blob: 39a3765897f59f58297d18629a73649284c3fb50 [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 },
Steven Valdez520e1222017-06-13 12:45:25 -04001319}
1320
1321func allVersions(protocol protocol) []tlsVersion {
1322 if protocol == tls {
1323 return tlsVersions
1324 }
1325
1326 var ret []tlsVersion
1327 for _, vers := range tlsVersions {
1328 if vers.hasDTLS {
1329 ret = append(ret, vers)
1330 }
1331 }
1332 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001333}
1334
David Benjaminaa012042016-12-10 13:33:05 -05001335type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001336 name string
1337 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001338}
1339
1340var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001341 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001342 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001343 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001344 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001345 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001346 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001347 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001348 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1349 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001350 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1351 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001352 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001353 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001354 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001355 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001356 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001357 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001358 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001359 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001360 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001361 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001362 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1363 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001364 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1365 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001366 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001367 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1368 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1369 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001370 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001371}
1372
David Benjamin8b8c0062014-11-23 02:47:52 -05001373func hasComponent(suiteName, component string) bool {
1374 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1375}
1376
David Benjaminf7768e42014-08-31 02:06:47 -04001377func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001378 return hasComponent(suiteName, "GCM") ||
1379 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001380 hasComponent(suiteName, "SHA384") ||
1381 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001382}
1383
Nick Harper1fd39d82016-06-14 18:14:35 -07001384func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001385 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001386}
1387
David Benjamin8b8c0062014-11-23 02:47:52 -05001388func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001389 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001390}
1391
Adam Langleya7997f12015-05-14 17:38:50 -07001392func bigFromHex(hex string) *big.Int {
1393 ret, ok := new(big.Int).SetString(hex, 16)
1394 if !ok {
1395 panic("failed to parse hex number 0x" + hex)
1396 }
1397 return ret
1398}
1399
Adam Langley7c803a62015-06-15 15:35:05 -07001400func addBasicTests() {
1401 basicTests := []testCase{
1402 {
Adam Langley7c803a62015-06-15 15:35:05 -07001403 name: "NoFallbackSCSV",
1404 config: Config{
1405 Bugs: ProtocolBugs{
1406 FailIfNotFallbackSCSV: true,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedLocalError: "no fallback SCSV found",
1411 },
1412 {
1413 name: "SendFallbackSCSV",
1414 config: Config{
1415 Bugs: ProtocolBugs{
1416 FailIfNotFallbackSCSV: true,
1417 },
1418 },
1419 flags: []string{"-fallback-scsv"},
1420 },
1421 {
1422 name: "ClientCertificateTypes",
1423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001424 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001425 ClientAuth: RequestClientCert,
1426 ClientCertificateTypes: []byte{
1427 CertTypeDSSSign,
1428 CertTypeRSASign,
1429 CertTypeECDSASign,
1430 },
1431 },
1432 flags: []string{
1433 "-expect-certificate-types",
1434 base64.StdEncoding.EncodeToString([]byte{
1435 CertTypeDSSSign,
1436 CertTypeRSASign,
1437 CertTypeECDSASign,
1438 }),
1439 },
1440 },
1441 {
Adam Langley7c803a62015-06-15 15:35:05 -07001442 name: "UnauthenticatedECDH",
1443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001444 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001445 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1446 Bugs: ProtocolBugs{
1447 UnauthenticatedECDH: true,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":UNEXPECTED_MESSAGE:",
1452 },
1453 {
1454 name: "SkipCertificateStatus",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 SkipCertificateStatus: true,
1460 },
1461 },
1462 flags: []string{
1463 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001464 // This test involves an optional message. Test the message callback
1465 // trace to ensure we do not miss or double-report any.
1466 "-expect-msg-callback",
1467 `write hs 1
1468read hs 2
1469read hs 11
1470read hs 12
1471read hs 14
1472write hs 16
1473write ccs
1474write hs 20
1475read hs 4
1476read ccs
1477read hs 20
1478read alert 1 0
1479`,
1480 },
1481 },
1482 {
1483 protocol: dtls,
1484 name: "SkipCertificateStatus-DTLS",
1485 config: Config{
1486 MaxVersion: VersionTLS12,
1487 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1488 Bugs: ProtocolBugs{
1489 SkipCertificateStatus: true,
1490 },
1491 },
1492 flags: []string{
1493 "-enable-ocsp-stapling",
1494 // This test involves an optional message. Test the message callback
1495 // trace to ensure we do not miss or double-report any.
1496 "-expect-msg-callback",
1497 `write hs 1
1498read hs 3
1499write hs 1
1500read hs 2
1501read hs 11
1502read hs 12
1503read hs 14
1504write hs 16
1505write ccs
1506write hs 20
1507read hs 4
1508read ccs
1509read hs 20
1510read alert 1 0
1511`,
Adam Langley7c803a62015-06-15 15:35:05 -07001512 },
1513 },
1514 {
1515 name: "SkipServerKeyExchange",
1516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001517 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001518 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1519 Bugs: ProtocolBugs{
1520 SkipServerKeyExchange: true,
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":UNEXPECTED_MESSAGE:",
1525 },
1526 {
Adam Langley7c803a62015-06-15 15:35:05 -07001527 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001528 name: "ServerSkipCertificateVerify",
1529 config: Config{
1530 MaxVersion: VersionTLS12,
1531 Certificates: []Certificate{rsaChainCertificate},
1532 Bugs: ProtocolBugs{
1533 SkipCertificateVerify: true,
1534 },
1535 },
1536 expectPeerCertificate: &rsaChainCertificate,
1537 flags: []string{
1538 "-require-any-client-certificate",
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_RECORD:",
1542 expectedLocalError: "remote error: unexpected message",
1543 },
1544 {
1545 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001546 name: "Alert",
1547 config: Config{
1548 Bugs: ProtocolBugs{
1549 SendSpuriousAlert: alertRecordOverflow,
1550 },
1551 },
1552 shouldFail: true,
1553 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1554 },
1555 {
1556 protocol: dtls,
1557 testType: serverTest,
1558 name: "Alert-DTLS",
1559 config: Config{
1560 Bugs: ProtocolBugs{
1561 SendSpuriousAlert: alertRecordOverflow,
1562 },
1563 },
1564 shouldFail: true,
1565 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1566 },
1567 {
1568 testType: serverTest,
1569 name: "FragmentAlert",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 FragmentAlert: true,
1573 SendSpuriousAlert: alertRecordOverflow,
1574 },
1575 },
1576 shouldFail: true,
1577 expectedError: ":BAD_ALERT:",
1578 },
1579 {
1580 protocol: dtls,
1581 testType: serverTest,
1582 name: "FragmentAlert-DTLS",
1583 config: Config{
1584 Bugs: ProtocolBugs{
1585 FragmentAlert: true,
1586 SendSpuriousAlert: alertRecordOverflow,
1587 },
1588 },
1589 shouldFail: true,
1590 expectedError: ":BAD_ALERT:",
1591 },
1592 {
1593 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001594 name: "DoubleAlert",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 DoubleAlert: true,
1598 SendSpuriousAlert: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":BAD_ALERT:",
1603 },
1604 {
1605 protocol: dtls,
1606 testType: serverTest,
1607 name: "DoubleAlert-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 DoubleAlert: true,
1611 SendSpuriousAlert: alertRecordOverflow,
1612 },
1613 },
1614 shouldFail: true,
1615 expectedError: ":BAD_ALERT:",
1616 },
1617 {
Adam Langley7c803a62015-06-15 15:35:05 -07001618 name: "SkipNewSessionTicket",
1619 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001620 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001621 Bugs: ProtocolBugs{
1622 SkipNewSessionTicket: true,
1623 },
1624 },
1625 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001626 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001627 },
1628 {
1629 testType: serverTest,
1630 name: "FallbackSCSV",
1631 config: Config{
1632 MaxVersion: VersionTLS11,
1633 Bugs: ProtocolBugs{
1634 SendFallbackSCSV: true,
1635 },
1636 },
David Benjamin56cadc32016-12-16 19:54:11 -05001637 shouldFail: true,
1638 expectedError: ":INAPPROPRIATE_FALLBACK:",
1639 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001640 },
1641 {
1642 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001643 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001644 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001645 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001646 Bugs: ProtocolBugs{
1647 SendFallbackSCSV: true,
1648 },
1649 },
1650 },
1651 {
1652 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001653 name: "FallbackSCSV-VersionMatch-TLS12",
1654 config: Config{
1655 MaxVersion: VersionTLS12,
1656 Bugs: ProtocolBugs{
1657 SendFallbackSCSV: true,
1658 },
1659 },
1660 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1661 },
1662 {
1663 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001664 name: "FragmentedClientVersion",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 MaxHandshakeRecordLength: 1,
1668 FragmentClientVersion: true,
1669 },
1670 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001671 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001672 },
1673 {
Adam Langley7c803a62015-06-15 15:35:05 -07001674 testType: serverTest,
1675 name: "HttpGET",
1676 sendPrefix: "GET / HTTP/1.0\n",
1677 shouldFail: true,
1678 expectedError: ":HTTP_REQUEST:",
1679 },
1680 {
1681 testType: serverTest,
1682 name: "HttpPOST",
1683 sendPrefix: "POST / HTTP/1.0\n",
1684 shouldFail: true,
1685 expectedError: ":HTTP_REQUEST:",
1686 },
1687 {
1688 testType: serverTest,
1689 name: "HttpHEAD",
1690 sendPrefix: "HEAD / HTTP/1.0\n",
1691 shouldFail: true,
1692 expectedError: ":HTTP_REQUEST:",
1693 },
1694 {
1695 testType: serverTest,
1696 name: "HttpPUT",
1697 sendPrefix: "PUT / HTTP/1.0\n",
1698 shouldFail: true,
1699 expectedError: ":HTTP_REQUEST:",
1700 },
1701 {
1702 testType: serverTest,
1703 name: "HttpCONNECT",
1704 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1705 shouldFail: true,
1706 expectedError: ":HTTPS_PROXY_REQUEST:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "Garbage",
1711 sendPrefix: "blah",
1712 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001713 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001714 },
1715 {
Adam Langley7c803a62015-06-15 15:35:05 -07001716 name: "RSAEphemeralKey",
1717 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001718 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001719 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1720 Bugs: ProtocolBugs{
1721 RSAEphemeralKey: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":UNEXPECTED_MESSAGE:",
1726 },
1727 {
1728 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001729 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001730 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001731 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001732 },
1733 {
1734 protocol: dtls,
1735 name: "DisableEverything-DTLS",
1736 flags: []string{"-no-tls12", "-no-tls1"},
1737 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001738 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001739 },
1740 {
Adam Langley7c803a62015-06-15 15:35:05 -07001741 protocol: dtls,
1742 testType: serverTest,
1743 name: "MTU",
1744 config: Config{
1745 Bugs: ProtocolBugs{
1746 MaxPacketLength: 256,
1747 },
1748 },
1749 flags: []string{"-mtu", "256"},
1750 },
1751 {
1752 protocol: dtls,
1753 testType: serverTest,
1754 name: "MTUExceeded",
1755 config: Config{
1756 Bugs: ProtocolBugs{
1757 MaxPacketLength: 255,
1758 },
1759 },
1760 flags: []string{"-mtu", "256"},
1761 shouldFail: true,
1762 expectedLocalError: "dtls: exceeded maximum packet length",
1763 },
1764 {
Adam Langley7c803a62015-06-15 15:35:05 -07001765 name: "EmptyCertificateList",
1766 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001767 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001768 Bugs: ProtocolBugs{
1769 EmptyCertificateList: true,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":DECODE_ERROR:",
1774 },
1775 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001776 name: "EmptyCertificateList-TLS13",
1777 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001778 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001779 Bugs: ProtocolBugs{
1780 EmptyCertificateList: true,
1781 },
1782 },
1783 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001784 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001785 },
1786 {
Adam Langley7c803a62015-06-15 15:35:05 -07001787 name: "TLSFatalBadPackets",
1788 damageFirstWrite: true,
1789 shouldFail: true,
1790 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1791 },
1792 {
1793 protocol: dtls,
1794 name: "DTLSIgnoreBadPackets",
1795 damageFirstWrite: true,
1796 },
1797 {
1798 protocol: dtls,
1799 name: "DTLSIgnoreBadPackets-Async",
1800 damageFirstWrite: true,
1801 flags: []string{"-async"},
1802 },
1803 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001804 name: "AppDataBeforeHandshake",
1805 config: Config{
1806 Bugs: ProtocolBugs{
1807 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1808 },
1809 },
1810 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001811 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001812 },
1813 {
1814 name: "AppDataBeforeHandshake-Empty",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 AppDataBeforeHandshake: []byte{},
1818 },
1819 },
1820 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001821 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001822 },
1823 {
1824 protocol: dtls,
1825 name: "AppDataBeforeHandshake-DTLS",
1826 config: Config{
1827 Bugs: ProtocolBugs{
1828 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1829 },
1830 },
1831 shouldFail: true,
1832 expectedError: ":UNEXPECTED_RECORD:",
1833 },
1834 {
1835 protocol: dtls,
1836 name: "AppDataBeforeHandshake-DTLS-Empty",
1837 config: Config{
1838 Bugs: ProtocolBugs{
1839 AppDataBeforeHandshake: []byte{},
1840 },
1841 },
1842 shouldFail: true,
1843 expectedError: ":UNEXPECTED_RECORD:",
1844 },
1845 {
Adam Langley7c803a62015-06-15 15:35:05 -07001846 name: "AppDataAfterChangeCipherSpec",
1847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001848 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001849 Bugs: ProtocolBugs{
1850 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1851 },
1852 },
1853 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001854 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001855 },
1856 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001857 name: "AppDataAfterChangeCipherSpec-Empty",
1858 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001859 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001860 Bugs: ProtocolBugs{
1861 AppDataAfterChangeCipherSpec: []byte{},
1862 },
1863 },
1864 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001865 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001866 },
1867 {
Adam Langley7c803a62015-06-15 15:35:05 -07001868 protocol: dtls,
1869 name: "AppDataAfterChangeCipherSpec-DTLS",
1870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001871 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001872 Bugs: ProtocolBugs{
1873 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1874 },
1875 },
1876 // BoringSSL's DTLS implementation will drop the out-of-order
1877 // application data.
1878 },
1879 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001880 protocol: dtls,
1881 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001883 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001884 Bugs: ProtocolBugs{
1885 AppDataAfterChangeCipherSpec: []byte{},
1886 },
1887 },
1888 // BoringSSL's DTLS implementation will drop the out-of-order
1889 // application data.
1890 },
1891 {
Adam Langley7c803a62015-06-15 15:35:05 -07001892 name: "AlertAfterChangeCipherSpec",
1893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001894 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001895 Bugs: ProtocolBugs{
1896 AlertAfterChangeCipherSpec: alertRecordOverflow,
1897 },
1898 },
1899 shouldFail: true,
1900 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1901 },
1902 {
1903 protocol: dtls,
1904 name: "AlertAfterChangeCipherSpec-DTLS",
1905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001906 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001907 Bugs: ProtocolBugs{
1908 AlertAfterChangeCipherSpec: alertRecordOverflow,
1909 },
1910 },
1911 shouldFail: true,
1912 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1913 },
1914 {
1915 protocol: dtls,
1916 name: "ReorderHandshakeFragments-Small-DTLS",
1917 config: Config{
1918 Bugs: ProtocolBugs{
1919 ReorderHandshakeFragments: true,
1920 // Small enough that every handshake message is
1921 // fragmented.
1922 MaxHandshakeRecordLength: 2,
1923 },
1924 },
1925 },
1926 {
1927 protocol: dtls,
1928 name: "ReorderHandshakeFragments-Large-DTLS",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 ReorderHandshakeFragments: true,
1932 // Large enough that no handshake message is
1933 // fragmented.
1934 MaxHandshakeRecordLength: 2048,
1935 },
1936 },
1937 },
1938 {
1939 protocol: dtls,
1940 name: "MixCompleteMessageWithFragments-DTLS",
1941 config: Config{
1942 Bugs: ProtocolBugs{
1943 ReorderHandshakeFragments: true,
1944 MixCompleteMessageWithFragments: true,
1945 MaxHandshakeRecordLength: 2,
1946 },
1947 },
1948 },
1949 {
1950 name: "SendInvalidRecordType",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 SendInvalidRecordType: true,
1954 },
1955 },
1956 shouldFail: true,
1957 expectedError: ":UNEXPECTED_RECORD:",
1958 },
1959 {
1960 protocol: dtls,
1961 name: "SendInvalidRecordType-DTLS",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendInvalidRecordType: true,
1965 },
1966 },
1967 shouldFail: true,
1968 expectedError: ":UNEXPECTED_RECORD:",
1969 },
1970 {
1971 name: "FalseStart-SkipServerSecondLeg",
1972 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001973 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1975 NextProtos: []string{"foo"},
1976 Bugs: ProtocolBugs{
1977 SkipNewSessionTicket: true,
1978 SkipChangeCipherSpec: true,
1979 SkipFinished: true,
1980 ExpectFalseStart: true,
1981 },
1982 },
1983 flags: []string{
1984 "-false-start",
1985 "-handshake-never-done",
1986 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001987 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001988 },
1989 shimWritesFirst: true,
1990 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001991 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001992 },
1993 {
1994 name: "FalseStart-SkipServerSecondLeg-Implicit",
1995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001996 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001997 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1998 NextProtos: []string{"foo"},
1999 Bugs: ProtocolBugs{
2000 SkipNewSessionTicket: true,
2001 SkipChangeCipherSpec: true,
2002 SkipFinished: true,
2003 },
2004 },
2005 flags: []string{
2006 "-implicit-handshake",
2007 "-false-start",
2008 "-handshake-never-done",
2009 "-advertise-alpn", "\x03foo",
2010 },
2011 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04002012 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002013 },
2014 {
2015 testType: serverTest,
2016 name: "FailEarlyCallback",
2017 flags: []string{"-fail-early-callback"},
2018 shouldFail: true,
2019 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002020 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002021 },
2022 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002023 name: "FailCertCallback-Client-TLS12",
2024 config: Config{
2025 MaxVersion: VersionTLS12,
2026 ClientAuth: RequestClientCert,
2027 },
2028 flags: []string{"-fail-cert-callback"},
2029 shouldFail: true,
2030 expectedError: ":CERT_CB_ERROR:",
2031 expectedLocalError: "remote error: internal error",
2032 },
2033 {
2034 testType: serverTest,
2035 name: "FailCertCallback-Server-TLS12",
2036 config: Config{
2037 MaxVersion: VersionTLS12,
2038 },
2039 flags: []string{"-fail-cert-callback"},
2040 shouldFail: true,
2041 expectedError: ":CERT_CB_ERROR:",
2042 expectedLocalError: "remote error: internal error",
2043 },
2044 {
2045 name: "FailCertCallback-Client-TLS13",
2046 config: Config{
2047 MaxVersion: VersionTLS13,
2048 ClientAuth: RequestClientCert,
2049 },
2050 flags: []string{"-fail-cert-callback"},
2051 shouldFail: true,
2052 expectedError: ":CERT_CB_ERROR:",
2053 expectedLocalError: "remote error: internal error",
2054 },
2055 {
2056 testType: serverTest,
2057 name: "FailCertCallback-Server-TLS13",
2058 config: Config{
2059 MaxVersion: VersionTLS13,
2060 },
2061 flags: []string{"-fail-cert-callback"},
2062 shouldFail: true,
2063 expectedError: ":CERT_CB_ERROR:",
2064 expectedLocalError: "remote error: internal error",
2065 },
2066 {
Adam Langley7c803a62015-06-15 15:35:05 -07002067 protocol: dtls,
2068 name: "FragmentMessageTypeMismatch-DTLS",
2069 config: Config{
2070 Bugs: ProtocolBugs{
2071 MaxHandshakeRecordLength: 2,
2072 FragmentMessageTypeMismatch: true,
2073 },
2074 },
2075 shouldFail: true,
2076 expectedError: ":FRAGMENT_MISMATCH:",
2077 },
2078 {
2079 protocol: dtls,
2080 name: "FragmentMessageLengthMismatch-DTLS",
2081 config: Config{
2082 Bugs: ProtocolBugs{
2083 MaxHandshakeRecordLength: 2,
2084 FragmentMessageLengthMismatch: true,
2085 },
2086 },
2087 shouldFail: true,
2088 expectedError: ":FRAGMENT_MISMATCH:",
2089 },
2090 {
2091 protocol: dtls,
2092 name: "SplitFragments-Header-DTLS",
2093 config: Config{
2094 Bugs: ProtocolBugs{
2095 SplitFragments: 2,
2096 },
2097 },
2098 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002099 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002100 },
2101 {
2102 protocol: dtls,
2103 name: "SplitFragments-Boundary-DTLS",
2104 config: Config{
2105 Bugs: ProtocolBugs{
2106 SplitFragments: dtlsRecordHeaderLen,
2107 },
2108 },
2109 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002110 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002111 },
2112 {
2113 protocol: dtls,
2114 name: "SplitFragments-Body-DTLS",
2115 config: Config{
2116 Bugs: ProtocolBugs{
2117 SplitFragments: dtlsRecordHeaderLen + 1,
2118 },
2119 },
2120 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002121 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002122 },
2123 {
2124 protocol: dtls,
2125 name: "SendEmptyFragments-DTLS",
2126 config: Config{
2127 Bugs: ProtocolBugs{
2128 SendEmptyFragments: true,
2129 },
2130 },
2131 },
2132 {
David Benjamine51fb0f2017-09-07 11:51:46 -04002133 testType: serverTest,
2134 protocol: dtls,
2135 name: "SendEmptyFragments-Padded-DTLS",
2136 config: Config{
2137 Bugs: ProtocolBugs{
2138 // Test empty fragments for a message with a
2139 // nice power-of-two length.
2140 PadClientHello: 64,
2141 SendEmptyFragments: true,
2142 },
2143 },
2144 },
2145 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002146 name: "BadFinished-Client",
2147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002148 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002149 Bugs: ProtocolBugs{
2150 BadFinished: true,
2151 },
2152 },
2153 shouldFail: true,
2154 expectedError: ":DIGEST_CHECK_FAILED:",
2155 },
2156 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002157 name: "BadFinished-Client-TLS13",
2158 config: Config{
2159 MaxVersion: VersionTLS13,
2160 Bugs: ProtocolBugs{
2161 BadFinished: true,
2162 },
2163 },
2164 shouldFail: true,
2165 expectedError: ":DIGEST_CHECK_FAILED:",
2166 },
2167 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002168 testType: serverTest,
2169 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002171 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002172 Bugs: ProtocolBugs{
2173 BadFinished: true,
2174 },
2175 },
2176 shouldFail: true,
2177 expectedError: ":DIGEST_CHECK_FAILED:",
2178 },
2179 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002180 testType: serverTest,
2181 name: "BadFinished-Server-TLS13",
2182 config: Config{
2183 MaxVersion: VersionTLS13,
2184 Bugs: ProtocolBugs{
2185 BadFinished: true,
2186 },
2187 },
2188 shouldFail: true,
2189 expectedError: ":DIGEST_CHECK_FAILED:",
2190 },
2191 {
Adam Langley7c803a62015-06-15 15:35:05 -07002192 name: "FalseStart-BadFinished",
2193 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002194 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002195 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2196 NextProtos: []string{"foo"},
2197 Bugs: ProtocolBugs{
2198 BadFinished: true,
2199 ExpectFalseStart: true,
2200 },
2201 },
2202 flags: []string{
2203 "-false-start",
2204 "-handshake-never-done",
2205 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002206 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002207 },
2208 shimWritesFirst: true,
2209 shouldFail: true,
2210 expectedError: ":DIGEST_CHECK_FAILED:",
2211 },
2212 {
2213 name: "NoFalseStart-NoALPN",
2214 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002215 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002216 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2217 Bugs: ProtocolBugs{
2218 ExpectFalseStart: true,
2219 AlertBeforeFalseStartTest: alertAccessDenied,
2220 },
2221 },
2222 flags: []string{
2223 "-false-start",
2224 },
2225 shimWritesFirst: true,
2226 shouldFail: true,
2227 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2228 expectedLocalError: "tls: peer did not false start: EOF",
2229 },
2230 {
2231 name: "NoFalseStart-NoAEAD",
2232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002233 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002234 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2235 NextProtos: []string{"foo"},
2236 Bugs: ProtocolBugs{
2237 ExpectFalseStart: true,
2238 AlertBeforeFalseStartTest: alertAccessDenied,
2239 },
2240 },
2241 flags: []string{
2242 "-false-start",
2243 "-advertise-alpn", "\x03foo",
2244 },
2245 shimWritesFirst: true,
2246 shouldFail: true,
2247 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2248 expectedLocalError: "tls: peer did not false start: EOF",
2249 },
2250 {
2251 name: "NoFalseStart-RSA",
2252 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002253 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002254 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2255 NextProtos: []string{"foo"},
2256 Bugs: ProtocolBugs{
2257 ExpectFalseStart: true,
2258 AlertBeforeFalseStartTest: alertAccessDenied,
2259 },
2260 },
2261 flags: []string{
2262 "-false-start",
2263 "-advertise-alpn", "\x03foo",
2264 },
2265 shimWritesFirst: true,
2266 shouldFail: true,
2267 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2268 expectedLocalError: "tls: peer did not false start: EOF",
2269 },
2270 {
Adam Langley7c803a62015-06-15 15:35:05 -07002271 protocol: dtls,
2272 name: "SendSplitAlert-Sync",
2273 config: Config{
2274 Bugs: ProtocolBugs{
2275 SendSplitAlert: true,
2276 },
2277 },
2278 },
2279 {
2280 protocol: dtls,
2281 name: "SendSplitAlert-Async",
2282 config: Config{
2283 Bugs: ProtocolBugs{
2284 SendSplitAlert: true,
2285 },
2286 },
2287 flags: []string{"-async"},
2288 },
2289 {
2290 protocol: dtls,
2291 name: "PackDTLSHandshake",
2292 config: Config{
2293 Bugs: ProtocolBugs{
2294 MaxHandshakeRecordLength: 2,
2295 PackHandshakeFragments: 20,
2296 PackHandshakeRecords: 200,
2297 },
2298 },
2299 },
2300 {
Adam Langley7c803a62015-06-15 15:35:05 -07002301 name: "SendEmptyRecords-Pass",
2302 sendEmptyRecords: 32,
2303 },
2304 {
2305 name: "SendEmptyRecords",
2306 sendEmptyRecords: 33,
2307 shouldFail: true,
2308 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2309 },
2310 {
2311 name: "SendEmptyRecords-Async",
2312 sendEmptyRecords: 33,
2313 flags: []string{"-async"},
2314 shouldFail: true,
2315 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2316 },
2317 {
David Benjamine8e84b92016-08-03 15:39:47 -04002318 name: "SendWarningAlerts-Pass",
2319 config: Config{
2320 MaxVersion: VersionTLS12,
2321 },
Adam Langley7c803a62015-06-15 15:35:05 -07002322 sendWarningAlerts: 4,
2323 },
2324 {
David Benjamine8e84b92016-08-03 15:39:47 -04002325 protocol: dtls,
2326 name: "SendWarningAlerts-DTLS-Pass",
2327 config: Config{
2328 MaxVersion: VersionTLS12,
2329 },
Adam Langley7c803a62015-06-15 15:35:05 -07002330 sendWarningAlerts: 4,
2331 },
2332 {
David Benjamine8e84b92016-08-03 15:39:47 -04002333 name: "SendWarningAlerts-TLS13",
2334 config: Config{
2335 MaxVersion: VersionTLS13,
2336 },
2337 sendWarningAlerts: 4,
2338 shouldFail: true,
2339 expectedError: ":BAD_ALERT:",
2340 expectedLocalError: "remote error: error decoding message",
2341 },
2342 {
2343 name: "SendWarningAlerts",
2344 config: Config{
2345 MaxVersion: VersionTLS12,
2346 },
Adam Langley7c803a62015-06-15 15:35:05 -07002347 sendWarningAlerts: 5,
2348 shouldFail: true,
2349 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2350 },
2351 {
David Benjamine8e84b92016-08-03 15:39:47 -04002352 name: "SendWarningAlerts-Async",
2353 config: Config{
2354 MaxVersion: VersionTLS12,
2355 },
Adam Langley7c803a62015-06-15 15:35:05 -07002356 sendWarningAlerts: 5,
2357 flags: []string{"-async"},
2358 shouldFail: true,
2359 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2360 },
David Benjaminba4594a2015-06-18 18:36:15 -04002361 {
David Benjamin24e58862017-06-14 18:45:29 -04002362 name: "SendBogusAlertType",
2363 sendBogusAlertType: true,
2364 shouldFail: true,
2365 expectedError: ":UNKNOWN_ALERT_TYPE:",
2366 expectedLocalError: "remote error: illegal parameter",
2367 },
2368 {
2369 protocol: dtls,
2370 name: "SendBogusAlertType-DTLS",
2371 sendBogusAlertType: true,
2372 shouldFail: true,
2373 expectedError: ":UNKNOWN_ALERT_TYPE:",
2374 expectedLocalError: "remote error: illegal parameter",
2375 },
2376 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002377 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002378 config: Config{
2379 MaxVersion: VersionTLS13,
2380 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002381 sendKeyUpdates: 33,
2382 keyUpdateRequest: keyUpdateNotRequested,
2383 shouldFail: true,
2384 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002385 },
2386 {
David Benjaminba4594a2015-06-18 18:36:15 -04002387 name: "EmptySessionID",
2388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002389 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002390 SessionTicketsDisabled: true,
2391 },
2392 noSessionCache: true,
2393 flags: []string{"-expect-no-session"},
2394 },
David Benjamin30789da2015-08-29 22:56:45 -04002395 {
2396 name: "Unclean-Shutdown",
2397 config: Config{
2398 Bugs: ProtocolBugs{
2399 NoCloseNotify: true,
2400 ExpectCloseNotify: true,
2401 },
2402 },
2403 shimShutsDown: true,
2404 flags: []string{"-check-close-notify"},
2405 shouldFail: true,
2406 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2407 },
2408 {
2409 name: "Unclean-Shutdown-Ignored",
2410 config: Config{
2411 Bugs: ProtocolBugs{
2412 NoCloseNotify: true,
2413 },
2414 },
2415 shimShutsDown: true,
2416 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002417 {
David Benjaminfa214e42016-05-10 17:03:10 -04002418 name: "Unclean-Shutdown-Alert",
2419 config: Config{
2420 Bugs: ProtocolBugs{
2421 SendAlertOnShutdown: alertDecompressionFailure,
2422 ExpectCloseNotify: true,
2423 },
2424 },
2425 shimShutsDown: true,
2426 flags: []string{"-check-close-notify"},
2427 shouldFail: true,
2428 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2429 },
2430 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002431 name: "LargePlaintext",
2432 config: Config{
2433 Bugs: ProtocolBugs{
2434 SendLargeRecords: true,
2435 },
2436 },
2437 messageLen: maxPlaintext + 1,
2438 shouldFail: true,
2439 expectedError: ":DATA_LENGTH_TOO_LONG:",
2440 },
2441 {
2442 protocol: dtls,
2443 name: "LargePlaintext-DTLS",
2444 config: Config{
2445 Bugs: ProtocolBugs{
2446 SendLargeRecords: true,
2447 },
2448 },
2449 messageLen: maxPlaintext + 1,
2450 shouldFail: true,
2451 expectedError: ":DATA_LENGTH_TOO_LONG:",
2452 },
2453 {
2454 name: "LargeCiphertext",
2455 config: Config{
2456 Bugs: ProtocolBugs{
2457 SendLargeRecords: true,
2458 },
2459 },
2460 messageLen: maxPlaintext * 2,
2461 shouldFail: true,
2462 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2463 },
2464 {
2465 protocol: dtls,
2466 name: "LargeCiphertext-DTLS",
2467 config: Config{
2468 Bugs: ProtocolBugs{
2469 SendLargeRecords: true,
2470 },
2471 },
2472 messageLen: maxPlaintext * 2,
2473 // Unlike the other four cases, DTLS drops records which
2474 // are invalid before authentication, so the connection
2475 // does not fail.
2476 expectMessageDropped: true,
2477 },
David Benjamindd6fed92015-10-23 17:41:12 -04002478 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002479 name: "BadHelloRequest-1",
2480 renegotiate: 1,
2481 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002483 Bugs: ProtocolBugs{
2484 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2485 },
2486 },
2487 flags: []string{
2488 "-renegotiate-freely",
2489 "-expect-total-renegotiations", "1",
2490 },
2491 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002492 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002493 },
2494 {
2495 name: "BadHelloRequest-2",
2496 renegotiate: 1,
2497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002498 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002499 Bugs: ProtocolBugs{
2500 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2501 },
2502 },
2503 flags: []string{
2504 "-renegotiate-freely",
2505 "-expect-total-renegotiations", "1",
2506 },
2507 shouldFail: true,
2508 expectedError: ":BAD_HELLO_REQUEST:",
2509 },
David Benjaminef1b0092015-11-21 14:05:44 -05002510 {
2511 testType: serverTest,
2512 name: "SupportTicketsWithSessionID",
2513 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002514 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002515 SessionTicketsDisabled: true,
2516 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002517 resumeConfig: &Config{
2518 MaxVersion: VersionTLS12,
2519 },
David Benjaminef1b0092015-11-21 14:05:44 -05002520 resumeSession: true,
2521 },
David Benjamin02edcd02016-07-27 17:40:37 -04002522 {
2523 protocol: dtls,
2524 name: "DTLS-SendExtraFinished",
2525 config: Config{
2526 Bugs: ProtocolBugs{
2527 SendExtraFinished: true,
2528 },
2529 },
2530 shouldFail: true,
2531 expectedError: ":UNEXPECTED_RECORD:",
2532 },
2533 {
2534 protocol: dtls,
2535 name: "DTLS-SendExtraFinished-Reordered",
2536 config: Config{
2537 Bugs: ProtocolBugs{
2538 MaxHandshakeRecordLength: 2,
2539 ReorderHandshakeFragments: true,
2540 SendExtraFinished: true,
2541 },
2542 },
2543 shouldFail: true,
2544 expectedError: ":UNEXPECTED_RECORD:",
2545 },
David Benjamine97fb482016-07-29 09:23:07 -04002546 {
2547 testType: serverTest,
2548 name: "V2ClientHello-EmptyRecordPrefix",
2549 config: Config{
2550 // Choose a cipher suite that does not involve
2551 // elliptic curves, so no extensions are
2552 // involved.
2553 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002554 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002555 Bugs: ProtocolBugs{
2556 SendV2ClientHello: true,
2557 },
2558 },
2559 sendPrefix: string([]byte{
2560 byte(recordTypeHandshake),
2561 3, 1, // version
2562 0, 0, // length
2563 }),
2564 // A no-op empty record may not be sent before V2ClientHello.
2565 shouldFail: true,
2566 expectedError: ":WRONG_VERSION_NUMBER:",
2567 },
2568 {
2569 testType: serverTest,
2570 name: "V2ClientHello-WarningAlertPrefix",
2571 config: Config{
2572 // Choose a cipher suite that does not involve
2573 // elliptic curves, so no extensions are
2574 // involved.
2575 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002576 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002577 Bugs: ProtocolBugs{
2578 SendV2ClientHello: true,
2579 },
2580 },
2581 sendPrefix: string([]byte{
2582 byte(recordTypeAlert),
2583 3, 1, // version
2584 0, 2, // length
2585 alertLevelWarning, byte(alertDecompressionFailure),
2586 }),
2587 // A no-op warning alert may not be sent before V2ClientHello.
2588 shouldFail: true,
2589 expectedError: ":WRONG_VERSION_NUMBER:",
2590 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002591 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002592 name: "KeyUpdate-Client",
2593 config: Config{
2594 MaxVersion: VersionTLS13,
2595 },
2596 sendKeyUpdates: 1,
2597 keyUpdateRequest: keyUpdateNotRequested,
2598 },
2599 {
2600 testType: serverTest,
2601 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002602 config: Config{
2603 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002604 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002605 sendKeyUpdates: 1,
2606 keyUpdateRequest: keyUpdateNotRequested,
2607 },
2608 {
2609 name: "KeyUpdate-InvalidRequestMode",
2610 config: Config{
2611 MaxVersion: VersionTLS13,
2612 },
2613 sendKeyUpdates: 1,
2614 keyUpdateRequest: 42,
2615 shouldFail: true,
2616 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002617 },
David Benjaminabe94e32016-09-04 14:18:58 -04002618 {
David Benjaminbbba9392017-04-06 12:54:12 -04002619 // Test that KeyUpdates are acknowledged properly.
2620 name: "KeyUpdate-RequestACK",
2621 config: Config{
2622 MaxVersion: VersionTLS13,
2623 Bugs: ProtocolBugs{
2624 RejectUnsolicitedKeyUpdate: true,
2625 },
2626 },
2627 // Test the shim receiving many KeyUpdates in a row.
2628 sendKeyUpdates: 5,
2629 messageCount: 5,
2630 keyUpdateRequest: keyUpdateRequested,
2631 },
2632 {
2633 // Test that KeyUpdates are acknowledged properly if the
2634 // peer's KeyUpdate is discovered while a write is
2635 // pending.
2636 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2637 config: Config{
2638 MaxVersion: VersionTLS13,
2639 Bugs: ProtocolBugs{
2640 RejectUnsolicitedKeyUpdate: true,
2641 },
2642 },
2643 // Test the shim receiving many KeyUpdates in a row.
2644 sendKeyUpdates: 5,
2645 messageCount: 5,
2646 keyUpdateRequest: keyUpdateRequested,
2647 readWithUnfinishedWrite: true,
2648 flags: []string{"-async"},
2649 },
2650 {
David Benjaminabe94e32016-09-04 14:18:58 -04002651 name: "SendSNIWarningAlert",
2652 config: Config{
2653 MaxVersion: VersionTLS12,
2654 Bugs: ProtocolBugs{
2655 SendSNIWarningAlert: true,
2656 },
2657 },
2658 },
David Benjaminc241d792016-09-09 10:34:20 -04002659 {
2660 testType: serverTest,
2661 name: "ExtraCompressionMethods-TLS12",
2662 config: Config{
2663 MaxVersion: VersionTLS12,
2664 Bugs: ProtocolBugs{
2665 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2666 },
2667 },
2668 },
2669 {
2670 testType: serverTest,
2671 name: "ExtraCompressionMethods-TLS13",
2672 config: Config{
2673 MaxVersion: VersionTLS13,
2674 Bugs: ProtocolBugs{
2675 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2676 },
2677 },
2678 shouldFail: true,
2679 expectedError: ":INVALID_COMPRESSION_LIST:",
2680 expectedLocalError: "remote error: illegal parameter",
2681 },
2682 {
2683 testType: serverTest,
2684 name: "NoNullCompression-TLS12",
2685 config: Config{
2686 MaxVersion: VersionTLS12,
2687 Bugs: ProtocolBugs{
2688 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2689 },
2690 },
2691 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002692 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002693 expectedLocalError: "remote error: illegal parameter",
2694 },
2695 {
2696 testType: serverTest,
2697 name: "NoNullCompression-TLS13",
2698 config: Config{
2699 MaxVersion: VersionTLS13,
2700 Bugs: ProtocolBugs{
2701 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2702 },
2703 },
2704 shouldFail: true,
2705 expectedError: ":INVALID_COMPRESSION_LIST:",
2706 expectedLocalError: "remote error: illegal parameter",
2707 },
David Benjamin413e79e2017-07-01 10:11:53 -04002708 // Test that the client rejects invalid compression methods
2709 // from the server.
2710 {
2711 testType: clientTest,
2712 name: "InvalidCompressionMethod",
2713 config: Config{
2714 MaxVersion: VersionTLS12,
2715 Bugs: ProtocolBugs{
2716 SendCompressionMethod: 1,
2717 },
2718 },
2719 shouldFail: true,
2720 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2721 expectedLocalError: "remote error: illegal parameter",
2722 },
David Benjamin65ac9972016-09-02 21:35:25 -04002723 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002724 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002725 config: Config{
2726 MaxVersion: VersionTLS12,
2727 Bugs: ProtocolBugs{
2728 ExpectGREASE: true,
2729 },
2730 },
2731 flags: []string{"-enable-grease"},
2732 },
2733 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002734 name: "GREASE-Client-TLS13",
2735 config: Config{
2736 MaxVersion: VersionTLS13,
2737 Bugs: ProtocolBugs{
2738 ExpectGREASE: true,
2739 },
2740 },
2741 flags: []string{"-enable-grease"},
2742 },
2743 {
2744 testType: serverTest,
2745 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002746 config: Config{
2747 MaxVersion: VersionTLS13,
2748 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002749 // TLS 1.3 servers are expected to
2750 // always enable GREASE. TLS 1.3 is new,
2751 // so there is no existing ecosystem to
2752 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002753 ExpectGREASE: true,
2754 },
2755 },
David Benjamin65ac9972016-09-02 21:35:25 -04002756 },
David Benjamine3fbb362017-01-06 16:19:28 -05002757 {
2758 // Test the server so there is a large certificate as
2759 // well as application data.
2760 testType: serverTest,
2761 name: "MaxSendFragment",
2762 config: Config{
2763 Bugs: ProtocolBugs{
2764 MaxReceivePlaintext: 512,
2765 },
2766 },
2767 messageLen: 1024,
2768 flags: []string{
2769 "-max-send-fragment", "512",
2770 "-read-size", "1024",
2771 },
2772 },
2773 {
2774 // Test the server so there is a large certificate as
2775 // well as application data.
2776 testType: serverTest,
2777 name: "MaxSendFragment-TooLarge",
2778 config: Config{
2779 Bugs: ProtocolBugs{
2780 // Ensure that some of the records are
2781 // 512.
2782 MaxReceivePlaintext: 511,
2783 },
2784 },
2785 messageLen: 1024,
2786 flags: []string{
2787 "-max-send-fragment", "512",
2788 "-read-size", "1024",
2789 },
2790 shouldFail: true,
2791 expectedLocalError: "local error: record overflow",
2792 },
Adam Langley7c803a62015-06-15 15:35:05 -07002793 }
Adam Langley7c803a62015-06-15 15:35:05 -07002794 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002795
2796 // Test that very large messages can be received.
2797 cert := rsaCertificate
2798 for i := 0; i < 50; i++ {
2799 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2800 }
2801 testCases = append(testCases, testCase{
2802 name: "LargeMessage",
2803 config: Config{
2804 Certificates: []Certificate{cert},
2805 },
2806 })
2807 testCases = append(testCases, testCase{
2808 protocol: dtls,
2809 name: "LargeMessage-DTLS",
2810 config: Config{
2811 Certificates: []Certificate{cert},
2812 },
2813 })
2814
2815 // They are rejected if the maximum certificate chain length is capped.
2816 testCases = append(testCases, testCase{
2817 name: "LargeMessage-Reject",
2818 config: Config{
2819 Certificates: []Certificate{cert},
2820 },
2821 flags: []string{"-max-cert-list", "16384"},
2822 shouldFail: true,
2823 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2824 })
2825 testCases = append(testCases, testCase{
2826 protocol: dtls,
2827 name: "LargeMessage-Reject-DTLS",
2828 config: Config{
2829 Certificates: []Certificate{cert},
2830 },
2831 flags: []string{"-max-cert-list", "16384"},
2832 shouldFail: true,
2833 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2834 })
Adam Langley7c803a62015-06-15 15:35:05 -07002835}
2836
David Benjaminaa012042016-12-10 13:33:05 -05002837func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2838 const psk = "12345"
2839 const pskIdentity = "luggage combo"
2840
2841 var prefix string
2842 if protocol == dtls {
2843 if !ver.hasDTLS {
2844 return
2845 }
2846 prefix = "D"
2847 }
2848
2849 var cert Certificate
2850 var certFile string
2851 var keyFile string
2852 if hasComponent(suite.name, "ECDSA") {
2853 cert = ecdsaP256Certificate
2854 certFile = ecdsaP256CertificateFile
2855 keyFile = ecdsaP256KeyFile
2856 } else {
2857 cert = rsaCertificate
2858 certFile = rsaCertificateFile
2859 keyFile = rsaKeyFile
2860 }
2861
2862 var flags []string
2863 if hasComponent(suite.name, "PSK") {
2864 flags = append(flags,
2865 "-psk", psk,
2866 "-psk-identity", pskIdentity)
2867 }
2868 if hasComponent(suite.name, "NULL") {
2869 // NULL ciphers must be explicitly enabled.
2870 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2871 }
David Benjaminaa012042016-12-10 13:33:05 -05002872
2873 var shouldServerFail, shouldClientFail bool
2874 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2875 // BoringSSL clients accept ECDHE on SSLv3, but
2876 // a BoringSSL server will never select it
2877 // because the extension is missing.
2878 shouldServerFail = true
2879 }
2880 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2881 shouldClientFail = true
2882 shouldServerFail = true
2883 }
2884 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2885 shouldClientFail = true
2886 shouldServerFail = true
2887 }
2888 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2889 shouldClientFail = true
2890 shouldServerFail = true
2891 }
2892 if !isDTLSCipher(suite.name) && protocol == dtls {
2893 shouldClientFail = true
2894 shouldServerFail = true
2895 }
2896
2897 var sendCipherSuite uint16
2898 var expectedServerError, expectedClientError string
2899 serverCipherSuites := []uint16{suite.id}
2900 if shouldServerFail {
2901 expectedServerError = ":NO_SHARED_CIPHER:"
2902 }
2903 if shouldClientFail {
2904 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2905 // Configure the server to select ciphers as normal but
2906 // select an incompatible cipher in ServerHello.
2907 serverCipherSuites = nil
2908 sendCipherSuite = suite.id
2909 }
2910
David Benjamincdb6fe92017-02-07 16:06:48 -05002911 // For cipher suites and versions where exporters are defined, verify
2912 // that they interoperate.
2913 var exportKeyingMaterial int
2914 if ver.version > VersionSSL30 {
2915 exportKeyingMaterial = 1024
2916 }
2917
David Benjaminaa012042016-12-10 13:33:05 -05002918 testCases = append(testCases, testCase{
2919 testType: serverTest,
2920 protocol: protocol,
2921 name: prefix + ver.name + "-" + suite.name + "-server",
2922 config: Config{
2923 MinVersion: ver.version,
2924 MaxVersion: ver.version,
2925 CipherSuites: []uint16{suite.id},
2926 Certificates: []Certificate{cert},
2927 PreSharedKey: []byte(psk),
2928 PreSharedKeyIdentity: pskIdentity,
2929 Bugs: ProtocolBugs{
2930 AdvertiseAllConfiguredCiphers: true,
2931 },
2932 },
David Benjamina5022392017-07-10 17:40:39 -04002933 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002934 certFile: certFile,
2935 keyFile: keyFile,
2936 flags: flags,
2937 resumeSession: true,
2938 shouldFail: shouldServerFail,
2939 expectedError: expectedServerError,
2940 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002941 })
2942
2943 testCases = append(testCases, testCase{
2944 testType: clientTest,
2945 protocol: protocol,
2946 name: prefix + ver.name + "-" + suite.name + "-client",
2947 config: Config{
2948 MinVersion: ver.version,
2949 MaxVersion: ver.version,
2950 CipherSuites: serverCipherSuites,
2951 Certificates: []Certificate{cert},
2952 PreSharedKey: []byte(psk),
2953 PreSharedKeyIdentity: pskIdentity,
2954 Bugs: ProtocolBugs{
2955 IgnorePeerCipherPreferences: shouldClientFail,
2956 SendCipherSuite: sendCipherSuite,
2957 },
2958 },
David Benjamina5022392017-07-10 17:40:39 -04002959 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002960 flags: flags,
2961 resumeSession: true,
2962 shouldFail: shouldClientFail,
2963 expectedError: expectedClientError,
2964 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002965 })
2966
David Benjamin6f600d62016-12-21 16:06:54 -05002967 if shouldClientFail {
2968 return
2969 }
2970
2971 // Ensure the maximum record size is accepted.
2972 testCases = append(testCases, testCase{
2973 protocol: protocol,
2974 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2975 config: Config{
2976 MinVersion: ver.version,
2977 MaxVersion: ver.version,
2978 CipherSuites: []uint16{suite.id},
2979 Certificates: []Certificate{cert},
2980 PreSharedKey: []byte(psk),
2981 PreSharedKeyIdentity: pskIdentity,
2982 },
David Benjamina5022392017-07-10 17:40:39 -04002983 tls13Variant: ver.tls13Variant,
2984 flags: flags,
2985 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002986 })
2987
2988 // Test bad records for all ciphers. Bad records are fatal in TLS
2989 // and ignored in DTLS.
2990 var shouldFail bool
2991 var expectedError string
2992 if protocol == tls {
2993 shouldFail = true
2994 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2995 }
2996
2997 testCases = append(testCases, testCase{
2998 protocol: protocol,
2999 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
3000 config: Config{
3001 MinVersion: ver.version,
3002 MaxVersion: ver.version,
3003 CipherSuites: []uint16{suite.id},
3004 Certificates: []Certificate{cert},
3005 PreSharedKey: []byte(psk),
3006 PreSharedKeyIdentity: pskIdentity,
3007 },
David Benjamina5022392017-07-10 17:40:39 -04003008 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05003009 flags: flags,
3010 damageFirstWrite: true,
3011 messageLen: maxPlaintext,
3012 shouldFail: shouldFail,
3013 expectedError: expectedError,
3014 })
David Benjaminaa012042016-12-10 13:33:05 -05003015}
3016
Adam Langley95c29f32014-06-20 12:00:00 -07003017func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02003018 const bogusCipher = 0xfe00
3019
Adam Langley95c29f32014-06-20 12:00:00 -07003020 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07003021 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04003022 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05003023 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07003024 }
David Benjamin2c99d282015-09-01 10:23:00 -04003025 }
Adam Langley95c29f32014-06-20 12:00:00 -07003026 }
Adam Langleya7997f12015-05-14 17:38:50 -07003027
3028 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003029 name: "NoSharedCipher",
3030 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003031 MaxVersion: VersionTLS12,
3032 CipherSuites: []uint16{},
3033 },
3034 shouldFail: true,
3035 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3036 })
3037
3038 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003039 name: "NoSharedCipher-TLS13",
3040 config: Config{
3041 MaxVersion: VersionTLS13,
3042 CipherSuites: []uint16{},
3043 },
3044 shouldFail: true,
3045 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3046 })
3047
3048 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003049 name: "UnsupportedCipherSuite",
3050 config: Config{
3051 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003052 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003053 Bugs: ProtocolBugs{
3054 IgnorePeerCipherPreferences: true,
3055 },
3056 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003057 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003058 shouldFail: true,
3059 expectedError: ":WRONG_CIPHER_RETURNED:",
3060 })
3061
3062 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003063 name: "ServerHelloBogusCipher",
3064 config: Config{
3065 MaxVersion: VersionTLS12,
3066 Bugs: ProtocolBugs{
3067 SendCipherSuite: bogusCipher,
3068 },
3069 },
3070 shouldFail: true,
3071 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3072 })
3073 testCases = append(testCases, testCase{
3074 name: "ServerHelloBogusCipher-TLS13",
3075 config: Config{
3076 MaxVersion: VersionTLS13,
3077 Bugs: ProtocolBugs{
3078 SendCipherSuite: bogusCipher,
3079 },
3080 },
3081 shouldFail: true,
3082 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3083 })
3084
David Benjamin241ae832016-01-15 03:04:54 -05003085 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003086 testCases = append(testCases, testCase{
3087 testType: serverTest,
3088 name: "UnknownCipher",
3089 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003090 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003091 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003092 Bugs: ProtocolBugs{
3093 AdvertiseAllConfiguredCiphers: true,
3094 },
3095 },
3096 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003097
3098 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003099 testCases = append(testCases, testCase{
3100 testType: serverTest,
3101 name: "UnknownCipher-TLS13",
3102 config: Config{
3103 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003104 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003105 Bugs: ProtocolBugs{
3106 AdvertiseAllConfiguredCiphers: true,
3107 },
David Benjamin241ae832016-01-15 03:04:54 -05003108 },
3109 })
3110
David Benjamin78679342016-09-16 19:42:05 -04003111 // Test empty ECDHE_PSK identity hints work as expected.
3112 testCases = append(testCases, testCase{
3113 name: "EmptyECDHEPSKHint",
3114 config: Config{
3115 MaxVersion: VersionTLS12,
3116 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3117 PreSharedKey: []byte("secret"),
3118 },
3119 flags: []string{"-psk", "secret"},
3120 })
3121
3122 // Test empty PSK identity hints work as expected, even if an explicit
3123 // ServerKeyExchange is sent.
3124 testCases = append(testCases, testCase{
3125 name: "ExplicitEmptyPSKHint",
3126 config: Config{
3127 MaxVersion: VersionTLS12,
3128 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3129 PreSharedKey: []byte("secret"),
3130 Bugs: ProtocolBugs{
3131 AlwaysSendPreSharedKeyIdentityHint: true,
3132 },
3133 },
3134 flags: []string{"-psk", "secret"},
3135 })
David Benjamin69522112017-03-28 15:38:29 -05003136
3137 // Test that clients enforce that the server-sent certificate and cipher
3138 // suite match in TLS 1.2.
3139 testCases = append(testCases, testCase{
3140 name: "CertificateCipherMismatch-RSA",
3141 config: Config{
3142 MaxVersion: VersionTLS12,
3143 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3144 Certificates: []Certificate{rsaCertificate},
3145 Bugs: ProtocolBugs{
3146 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 },
3149 shouldFail: true,
3150 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3151 })
3152 testCases = append(testCases, testCase{
3153 name: "CertificateCipherMismatch-ECDSA",
3154 config: Config{
3155 MaxVersion: VersionTLS12,
3156 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3157 Certificates: []Certificate{ecdsaP256Certificate},
3158 Bugs: ProtocolBugs{
3159 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3160 },
3161 },
3162 shouldFail: true,
3163 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3164 })
3165 testCases = append(testCases, testCase{
3166 name: "CertificateCipherMismatch-Ed25519",
3167 config: Config{
3168 MaxVersion: VersionTLS12,
3169 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3170 Certificates: []Certificate{ed25519Certificate},
3171 Bugs: ProtocolBugs{
3172 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3173 },
3174 },
3175 shouldFail: true,
3176 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3177 })
3178
3179 // Test that servers decline to select a cipher suite which is
3180 // inconsistent with their configured certificate.
3181 testCases = append(testCases, testCase{
3182 testType: serverTest,
3183 name: "ServerCipherFilter-RSA",
3184 config: Config{
3185 MaxVersion: VersionTLS12,
3186 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3187 },
3188 flags: []string{
3189 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3190 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3191 },
3192 shouldFail: true,
3193 expectedError: ":NO_SHARED_CIPHER:",
3194 })
3195 testCases = append(testCases, testCase{
3196 testType: serverTest,
3197 name: "ServerCipherFilter-ECDSA",
3198 config: Config{
3199 MaxVersion: VersionTLS12,
3200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3201 },
3202 flags: []string{
3203 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3204 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3205 },
3206 shouldFail: true,
3207 expectedError: ":NO_SHARED_CIPHER:",
3208 })
3209 testCases = append(testCases, testCase{
3210 testType: serverTest,
3211 name: "ServerCipherFilter-Ed25519",
3212 config: Config{
3213 MaxVersion: VersionTLS12,
3214 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3215 },
3216 flags: []string{
3217 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3218 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3219 },
3220 shouldFail: true,
3221 expectedError: ":NO_SHARED_CIPHER:",
3222 })
David Benjamin364af782017-07-01 10:35:27 -04003223
3224 // Test cipher suite negotiation works as expected. Configure a
3225 // complicated cipher suite configuration.
3226 const negotiationTestCiphers = "" +
3227 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3228 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3229 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3230 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3231 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3232 negotiationTests := []struct {
3233 ciphers []uint16
3234 expected uint16
3235 }{
3236 // Server preferences are honored, including when
3237 // equipreference groups are involved.
3238 {
3239 []uint16{
3240 TLS_RSA_WITH_AES_256_GCM_SHA384,
3241 TLS_RSA_WITH_AES_128_CBC_SHA,
3242 TLS_RSA_WITH_AES_128_GCM_SHA256,
3243 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3244 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3245 },
3246 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3247 },
3248 {
3249 []uint16{
3250 TLS_RSA_WITH_AES_256_GCM_SHA384,
3251 TLS_RSA_WITH_AES_128_CBC_SHA,
3252 TLS_RSA_WITH_AES_128_GCM_SHA256,
3253 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3254 },
3255 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3256 },
3257 {
3258 []uint16{
3259 TLS_RSA_WITH_AES_256_GCM_SHA384,
3260 TLS_RSA_WITH_AES_128_CBC_SHA,
3261 TLS_RSA_WITH_AES_128_GCM_SHA256,
3262 },
3263 TLS_RSA_WITH_AES_128_GCM_SHA256,
3264 },
3265 {
3266 []uint16{
3267 TLS_RSA_WITH_AES_256_GCM_SHA384,
3268 TLS_RSA_WITH_AES_128_CBC_SHA,
3269 },
3270 TLS_RSA_WITH_AES_128_CBC_SHA,
3271 },
3272 // Equipreference groups use the client preference.
3273 {
3274 []uint16{
3275 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3276 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3277 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3278 },
3279 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3280 },
3281 {
3282 []uint16{
3283 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3284 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3285 },
3286 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3287 },
3288 {
3289 []uint16{
3290 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3291 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3292 },
3293 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3294 },
3295 {
3296 []uint16{
3297 TLS_RSA_WITH_AES_256_GCM_SHA384,
3298 TLS_RSA_WITH_AES_256_CBC_SHA,
3299 },
3300 TLS_RSA_WITH_AES_256_GCM_SHA384,
3301 },
3302 {
3303 []uint16{
3304 TLS_RSA_WITH_AES_256_CBC_SHA,
3305 TLS_RSA_WITH_AES_256_GCM_SHA384,
3306 },
3307 TLS_RSA_WITH_AES_256_CBC_SHA,
3308 },
3309 // If there are two equipreference groups, the preferred one
3310 // takes precedence.
3311 {
3312 []uint16{
3313 TLS_RSA_WITH_AES_256_GCM_SHA384,
3314 TLS_RSA_WITH_AES_256_CBC_SHA,
3315 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3316 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3317 },
3318 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3319 },
3320 }
3321 for i, t := range negotiationTests {
3322 testCases = append(testCases, testCase{
3323 testType: serverTest,
3324 name: "CipherNegotiation-" + strconv.Itoa(i),
3325 config: Config{
3326 MaxVersion: VersionTLS12,
3327 CipherSuites: t.ciphers,
3328 },
3329 flags: []string{"-cipher", negotiationTestCiphers},
3330 expectedCipher: t.expected,
3331 })
3332 }
Adam Langley95c29f32014-06-20 12:00:00 -07003333}
3334
3335func addBadECDSASignatureTests() {
3336 for badR := BadValue(1); badR < NumBadValues; badR++ {
3337 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003338 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003339 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3340 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003341 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003342 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003343 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003344 Bugs: ProtocolBugs{
3345 BadECDSAR: badR,
3346 BadECDSAS: badS,
3347 },
3348 },
3349 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003350 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003351 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003352 testCases = append(testCases, testCase{
3353 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3354 config: Config{
3355 MaxVersion: VersionTLS13,
3356 Certificates: []Certificate{ecdsaP256Certificate},
3357 Bugs: ProtocolBugs{
3358 BadECDSAR: badR,
3359 BadECDSAS: badS,
3360 },
3361 },
3362 shouldFail: true,
3363 expectedError: ":BAD_SIGNATURE:",
3364 })
Adam Langley95c29f32014-06-20 12:00:00 -07003365 }
3366 }
3367}
3368
Adam Langley80842bd2014-06-20 12:00:00 -07003369func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003370 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003371 name: "MaxCBCPadding",
3372 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003373 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3375 Bugs: ProtocolBugs{
3376 MaxPadding: true,
3377 },
3378 },
3379 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3380 })
David Benjamin025b3d32014-07-01 19:53:04 -04003381 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003382 name: "BadCBCPadding",
3383 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003384 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003385 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3386 Bugs: ProtocolBugs{
3387 PaddingFirstByteBad: true,
3388 },
3389 },
3390 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003391 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003392 })
3393 // OpenSSL previously had an issue where the first byte of padding in
3394 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003395 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003396 name: "BadCBCPadding255",
3397 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003398 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003399 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3400 Bugs: ProtocolBugs{
3401 MaxPadding: true,
3402 PaddingFirstByteBadIf255: true,
3403 },
3404 },
3405 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3406 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003407 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003408 })
3409}
3410
Kenny Root7fdeaf12014-08-05 15:23:37 -07003411func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003412 var cbcCiphers = []struct {
3413 name string
3414 cipher uint16
3415 }{
3416 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3417 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3418 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3419 }
3420 for _, t := range cbcCiphers {
3421 testCases = append(testCases, testCase{
3422 name: "CBCRecordSplitting-" + t.name,
3423 config: Config{
3424 MaxVersion: VersionTLS10,
3425 MinVersion: VersionTLS10,
3426 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003427 Bugs: ProtocolBugs{
3428 ExpectRecordSplitting: true,
3429 },
David Benjamina1ce8562017-07-01 11:46:57 -04003430 },
3431 messageLen: -1, // read until EOF
3432 resumeSession: true,
3433 flags: []string{
3434 "-async",
3435 "-write-different-record-sizes",
3436 "-cbc-record-splitting",
3437 },
3438 })
3439 testCases = append(testCases, testCase{
3440 name: "CBCRecordSplittingPartialWrite-" + t.name,
3441 config: Config{
3442 MaxVersion: VersionTLS10,
3443 MinVersion: VersionTLS10,
3444 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003445 Bugs: ProtocolBugs{
3446 ExpectRecordSplitting: true,
3447 },
David Benjamina1ce8562017-07-01 11:46:57 -04003448 },
3449 messageLen: -1, // read until EOF
3450 flags: []string{
3451 "-async",
3452 "-write-different-record-sizes",
3453 "-cbc-record-splitting",
3454 "-partial-write",
3455 },
3456 })
3457 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003458}
3459
David Benjamin636293b2014-07-08 17:59:18 -04003460func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003461 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003462 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003463 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3464 cert, err := x509.ParseCertificate(cert.Certificate[0])
3465 if err != nil {
3466 panic(err)
3467 }
3468 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003469 }
Adam Langley2ff79332017-02-28 13:45:39 -08003470 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003471
David Benjamin636293b2014-07-08 17:59:18 -04003472 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003473 testCases = append(testCases, testCase{
3474 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003475 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003476 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003477 MinVersion: ver.version,
3478 MaxVersion: ver.version,
3479 ClientAuth: RequireAnyClientCert,
3480 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003481 },
David Benjamina5022392017-07-10 17:40:39 -04003482 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003483 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003484 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3485 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003486 },
3487 })
3488 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003489 testType: serverTest,
3490 name: ver.name + "-Server-ClientAuth-RSA",
3491 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003492 MinVersion: ver.version,
3493 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003494 Certificates: []Certificate{rsaCertificate},
3495 },
David Benjamina5022392017-07-10 17:40:39 -04003496 tls13Variant: ver.tls13Variant,
3497 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003498 })
David Benjamine098ec22014-08-27 23:13:20 -04003499 if ver.version != VersionSSL30 {
3500 testCases = append(testCases, testCase{
3501 testType: serverTest,
3502 name: ver.name + "-Server-ClientAuth-ECDSA",
3503 config: Config{
3504 MinVersion: ver.version,
3505 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003506 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003507 },
David Benjamina5022392017-07-10 17:40:39 -04003508 tls13Variant: ver.tls13Variant,
3509 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003510 })
3511 testCases = append(testCases, testCase{
3512 testType: clientTest,
3513 name: ver.name + "-Client-ClientAuth-ECDSA",
3514 config: Config{
3515 MinVersion: ver.version,
3516 MaxVersion: ver.version,
3517 ClientAuth: RequireAnyClientCert,
3518 ClientCAs: certPool,
3519 },
David Benjamina5022392017-07-10 17:40:39 -04003520 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003521 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003522 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3523 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003524 },
3525 })
3526 }
Adam Langley37646832016-08-01 16:16:46 -07003527
3528 testCases = append(testCases, testCase{
3529 name: "NoClientCertificate-" + ver.name,
3530 config: Config{
3531 MinVersion: ver.version,
3532 MaxVersion: ver.version,
3533 ClientAuth: RequireAnyClientCert,
3534 },
David Benjamina5022392017-07-10 17:40:39 -04003535 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003536 shouldFail: true,
3537 expectedLocalError: "client didn't provide a certificate",
3538 })
3539
3540 testCases = append(testCases, testCase{
3541 // Even if not configured to expect a certificate, OpenSSL will
3542 // return X509_V_OK as the verify_result.
3543 testType: serverTest,
3544 name: "NoClientCertificateRequested-Server-" + ver.name,
3545 config: Config{
3546 MinVersion: ver.version,
3547 MaxVersion: ver.version,
3548 },
David Benjamina5022392017-07-10 17:40:39 -04003549 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003550 flags: []string{
3551 "-expect-verify-result",
3552 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003553 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003554 })
3555
3556 testCases = append(testCases, testCase{
3557 // If a client certificate is not provided, OpenSSL will still
3558 // return X509_V_OK as the verify_result.
3559 testType: serverTest,
3560 name: "NoClientCertificate-Server-" + ver.name,
3561 config: Config{
3562 MinVersion: ver.version,
3563 MaxVersion: ver.version,
3564 },
David Benjamina5022392017-07-10 17:40:39 -04003565 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003566 flags: []string{
3567 "-expect-verify-result",
3568 "-verify-peer",
3569 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003570 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003571 })
3572
David Benjamin1db9e1b2016-10-07 20:51:43 -04003573 certificateRequired := "remote error: certificate required"
3574 if ver.version < VersionTLS13 {
3575 // Prior to TLS 1.3, the generic handshake_failure alert
3576 // was used.
3577 certificateRequired = "remote error: handshake failure"
3578 }
Adam Langley37646832016-08-01 16:16:46 -07003579 testCases = append(testCases, testCase{
3580 testType: serverTest,
3581 name: "RequireAnyClientCertificate-" + ver.name,
3582 config: Config{
3583 MinVersion: ver.version,
3584 MaxVersion: ver.version,
3585 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003586 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003587 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003588 shouldFail: true,
3589 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3590 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003591 })
3592
3593 if ver.version != VersionSSL30 {
3594 testCases = append(testCases, testCase{
3595 testType: serverTest,
3596 name: "SkipClientCertificate-" + ver.name,
3597 config: Config{
3598 MinVersion: ver.version,
3599 MaxVersion: ver.version,
3600 Bugs: ProtocolBugs{
3601 SkipClientCertificate: true,
3602 },
3603 },
3604 // Setting SSL_VERIFY_PEER allows anonymous clients.
3605 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003606 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003607 shouldFail: true,
3608 expectedError: ":UNEXPECTED_MESSAGE:",
3609 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003610
3611 testCases = append(testCases, testCase{
3612 testType: serverTest,
3613 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3614 config: Config{
3615 MinVersion: ver.version,
3616 MaxVersion: ver.version,
3617 },
3618 flags: []string{
3619 "-enable-channel-id",
3620 "-verify-peer-if-no-obc",
3621 },
David Benjamina5022392017-07-10 17:40:39 -04003622 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003623 shouldFail: true,
3624 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3625 expectedLocalError: certificateRequired,
3626 })
3627
3628 testCases = append(testCases, testCase{
3629 testType: serverTest,
3630 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3631 config: Config{
3632 MinVersion: ver.version,
3633 MaxVersion: ver.version,
3634 ChannelID: channelIDKey,
3635 },
3636 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003637 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003638 flags: []string{
3639 "-enable-channel-id",
3640 "-verify-peer-if-no-obc",
3641 },
3642 })
Adam Langley37646832016-08-01 16:16:46 -07003643 }
Adam Langley2ff79332017-02-28 13:45:39 -08003644
3645 testCases = append(testCases, testCase{
3646 testType: serverTest,
3647 name: ver.name + "-Server-CertReq-CA-List",
3648 config: Config{
3649 MinVersion: ver.version,
3650 MaxVersion: ver.version,
3651 Certificates: []Certificate{rsaCertificate},
3652 Bugs: ProtocolBugs{
3653 ExpectCertificateReqNames: caNames,
3654 },
3655 },
David Benjamina5022392017-07-10 17:40:39 -04003656 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003657 flags: []string{
3658 "-require-any-client-certificate",
3659 "-use-client-ca-list", encodeDERValues(caNames),
3660 },
3661 })
3662
3663 testCases = append(testCases, testCase{
3664 testType: clientTest,
3665 name: ver.name + "-Client-CertReq-CA-List",
3666 config: Config{
3667 MinVersion: ver.version,
3668 MaxVersion: ver.version,
3669 Certificates: []Certificate{rsaCertificate},
3670 ClientAuth: RequireAnyClientCert,
3671 ClientCAs: certPool,
3672 },
David Benjamina5022392017-07-10 17:40:39 -04003673 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003674 flags: []string{
3675 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3676 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3677 "-expect-client-ca-list", encodeDERValues(caNames),
3678 },
3679 })
David Benjamin636293b2014-07-08 17:59:18 -04003680 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003681
David Benjaminc032dfa2016-05-12 14:54:57 -04003682 // Client auth is only legal in certificate-based ciphers.
3683 testCases = append(testCases, testCase{
3684 testType: clientTest,
3685 name: "ClientAuth-PSK",
3686 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003687 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003688 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3689 PreSharedKey: []byte("secret"),
3690 ClientAuth: RequireAnyClientCert,
3691 },
3692 flags: []string{
3693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3695 "-psk", "secret",
3696 },
3697 shouldFail: true,
3698 expectedError: ":UNEXPECTED_MESSAGE:",
3699 })
3700 testCases = append(testCases, testCase{
3701 testType: clientTest,
3702 name: "ClientAuth-ECDHE_PSK",
3703 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003704 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003705 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3706 PreSharedKey: []byte("secret"),
3707 ClientAuth: RequireAnyClientCert,
3708 },
3709 flags: []string{
3710 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3711 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3712 "-psk", "secret",
3713 },
3714 shouldFail: true,
3715 expectedError: ":UNEXPECTED_MESSAGE:",
3716 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003717
3718 // Regression test for a bug where the client CA list, if explicitly
3719 // set to NULL, was mis-encoded.
3720 testCases = append(testCases, testCase{
3721 testType: serverTest,
3722 name: "Null-Client-CA-List",
3723 config: Config{
3724 MaxVersion: VersionTLS12,
3725 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003726 Bugs: ProtocolBugs{
3727 ExpectCertificateReqNames: [][]byte{},
3728 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003729 },
3730 flags: []string{
3731 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003732 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003733 },
3734 })
David Benjamin636293b2014-07-08 17:59:18 -04003735}
3736
Adam Langley75712922014-10-10 16:23:43 -07003737func addExtendedMasterSecretTests() {
3738 const expectEMSFlag = "-expect-extended-master-secret"
3739
3740 for _, with := range []bool{false, true} {
3741 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003742 if with {
3743 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003744 }
3745
3746 for _, isClient := range []bool{false, true} {
3747 suffix := "-Server"
3748 testType := serverTest
3749 if isClient {
3750 suffix = "-Client"
3751 testType = clientTest
3752 }
3753
3754 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003755 // In TLS 1.3, the extension is irrelevant and
3756 // always reports as enabled.
3757 var flags []string
3758 if with || ver.version >= VersionTLS13 {
3759 flags = []string{expectEMSFlag}
3760 }
3761
Adam Langley75712922014-10-10 16:23:43 -07003762 test := testCase{
3763 testType: testType,
3764 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3765 config: Config{
3766 MinVersion: ver.version,
3767 MaxVersion: ver.version,
3768 Bugs: ProtocolBugs{
3769 NoExtendedMasterSecret: !with,
3770 RequireExtendedMasterSecret: with,
3771 },
3772 },
David Benjamina5022392017-07-10 17:40:39 -04003773 tls13Variant: ver.tls13Variant,
3774 flags: flags,
3775 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003776 }
3777 if test.shouldFail {
3778 test.expectedLocalError = "extended master secret required but not supported by peer"
3779 }
3780 testCases = append(testCases, test)
3781 }
3782 }
3783 }
3784
Adam Langleyba5934b2015-06-02 10:50:35 -07003785 for _, isClient := range []bool{false, true} {
3786 for _, supportedInFirstConnection := range []bool{false, true} {
3787 for _, supportedInResumeConnection := range []bool{false, true} {
3788 boolToWord := func(b bool) string {
3789 if b {
3790 return "Yes"
3791 }
3792 return "No"
3793 }
3794 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3795 if isClient {
3796 suffix += "Client"
3797 } else {
3798 suffix += "Server"
3799 }
3800
3801 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003802 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003803 Bugs: ProtocolBugs{
3804 RequireExtendedMasterSecret: true,
3805 },
3806 }
3807
3808 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003810 Bugs: ProtocolBugs{
3811 NoExtendedMasterSecret: true,
3812 },
3813 }
3814
3815 test := testCase{
3816 name: "ExtendedMasterSecret-" + suffix,
3817 resumeSession: true,
3818 }
3819
3820 if !isClient {
3821 test.testType = serverTest
3822 }
3823
3824 if supportedInFirstConnection {
3825 test.config = supportedConfig
3826 } else {
3827 test.config = noSupportConfig
3828 }
3829
3830 if supportedInResumeConnection {
3831 test.resumeConfig = &supportedConfig
3832 } else {
3833 test.resumeConfig = &noSupportConfig
3834 }
3835
3836 switch suffix {
3837 case "YesToYes-Client", "YesToYes-Server":
3838 // When a session is resumed, it should
3839 // still be aware that its master
3840 // secret was generated via EMS and
3841 // thus it's safe to use tls-unique.
3842 test.flags = []string{expectEMSFlag}
3843 case "NoToYes-Server":
3844 // If an original connection did not
3845 // contain EMS, but a resumption
3846 // handshake does, then a server should
3847 // not resume the session.
3848 test.expectResumeRejected = true
3849 case "YesToNo-Server":
3850 // Resuming an EMS session without the
3851 // EMS extension should cause the
3852 // server to abort the connection.
3853 test.shouldFail = true
3854 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3855 case "NoToYes-Client":
3856 // A client should abort a connection
3857 // where the server resumed a non-EMS
3858 // session but echoed the EMS
3859 // extension.
3860 test.shouldFail = true
3861 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3862 case "YesToNo-Client":
3863 // A client should abort a connection
3864 // where the server didn't echo EMS
3865 // when the session used it.
3866 test.shouldFail = true
3867 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3868 }
3869
3870 testCases = append(testCases, test)
3871 }
3872 }
3873 }
David Benjamin163c9562016-08-29 23:14:17 -04003874
3875 // Switching EMS on renegotiation is forbidden.
3876 testCases = append(testCases, testCase{
3877 name: "ExtendedMasterSecret-Renego-NoEMS",
3878 config: Config{
3879 MaxVersion: VersionTLS12,
3880 Bugs: ProtocolBugs{
3881 NoExtendedMasterSecret: true,
3882 NoExtendedMasterSecretOnRenegotiation: true,
3883 },
3884 },
3885 renegotiate: 1,
3886 flags: []string{
3887 "-renegotiate-freely",
3888 "-expect-total-renegotiations", "1",
3889 },
3890 })
3891
3892 testCases = append(testCases, testCase{
3893 name: "ExtendedMasterSecret-Renego-Upgrade",
3894 config: Config{
3895 MaxVersion: VersionTLS12,
3896 Bugs: ProtocolBugs{
3897 NoExtendedMasterSecret: true,
3898 },
3899 },
3900 renegotiate: 1,
3901 flags: []string{
3902 "-renegotiate-freely",
3903 "-expect-total-renegotiations", "1",
3904 },
3905 shouldFail: true,
3906 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3907 })
3908
3909 testCases = append(testCases, testCase{
3910 name: "ExtendedMasterSecret-Renego-Downgrade",
3911 config: Config{
3912 MaxVersion: VersionTLS12,
3913 Bugs: ProtocolBugs{
3914 NoExtendedMasterSecretOnRenegotiation: true,
3915 },
3916 },
3917 renegotiate: 1,
3918 flags: []string{
3919 "-renegotiate-freely",
3920 "-expect-total-renegotiations", "1",
3921 },
3922 shouldFail: true,
3923 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3924 })
Adam Langley75712922014-10-10 16:23:43 -07003925}
3926
David Benjamin582ba042016-07-07 12:33:25 -07003927type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003928 protocol protocol
3929 async bool
3930 splitHandshake bool
3931 packHandshakeFlight bool
3932 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003933}
3934
David Benjamin43ec06f2014-08-05 02:28:57 -04003935// Adds tests that try to cover the range of the handshake state machine, under
3936// various conditions. Some of these are redundant with other tests, but they
3937// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003938func addAllStateMachineCoverageTests() {
3939 for _, async := range []bool{false, true} {
3940 for _, protocol := range []protocol{tls, dtls} {
3941 addStateMachineCoverageTests(stateMachineTestConfig{
3942 protocol: protocol,
3943 async: async,
3944 })
3945 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003946 protocol: protocol,
3947 async: async,
3948 implicitHandshake: true,
3949 })
3950 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003951 protocol: protocol,
3952 async: async,
3953 splitHandshake: true,
3954 })
3955 if protocol == tls {
3956 addStateMachineCoverageTests(stateMachineTestConfig{
3957 protocol: protocol,
3958 async: async,
3959 packHandshakeFlight: true,
3960 })
3961 }
3962 }
3963 }
3964}
3965
3966func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003967 var tests []testCase
3968
3969 // Basic handshake, with resumption. Client and server,
3970 // session ID and session ticket.
3971 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 name: "Basic-Client",
3973 config: Config{
3974 MaxVersion: VersionTLS12,
3975 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003976 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003977 // Ensure session tickets are used, not session IDs.
3978 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003979 })
3980 tests = append(tests, testCase{
3981 name: "Basic-Client-RenewTicket",
3982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003983 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003984 Bugs: ProtocolBugs{
3985 RenewTicketOnResume: true,
3986 },
3987 },
David Benjamin46662482016-08-17 00:51:00 -04003988 flags: []string{"-expect-ticket-renewal"},
3989 resumeSession: true,
3990 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003991 })
3992 tests = append(tests, testCase{
3993 name: "Basic-Client-NoTicket",
3994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003995 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003996 SessionTicketsDisabled: true,
3997 },
3998 resumeSession: true,
3999 })
4000 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05004001 testType: serverTest,
4002 name: "Basic-Server",
4003 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004004 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05004005 Bugs: ProtocolBugs{
4006 RequireSessionTickets: true,
4007 },
4008 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004009 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004010 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004011 })
4012 tests = append(tests, testCase{
4013 testType: serverTest,
4014 name: "Basic-Server-NoTickets",
4015 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004016 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 SessionTicketsDisabled: true,
4018 },
4019 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004020 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004021 })
4022 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004023 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004024 name: "Basic-Server-EarlyCallback",
4025 config: Config{
4026 MaxVersion: VersionTLS12,
4027 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004028 flags: []string{"-use-early-callback"},
4029 resumeSession: true,
4030 })
4031
Steven Valdez143e8b32016-07-11 13:19:03 -04004032 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004033 if config.protocol == tls {
4034 tests = append(tests, testCase{
4035 name: "TLS13-1RTT-Client",
4036 config: Config{
4037 MaxVersion: VersionTLS13,
4038 MinVersion: VersionTLS13,
4039 },
David Benjamin46662482016-08-17 00:51:00 -04004040 resumeSession: true,
4041 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004042 })
4043
4044 tests = append(tests, testCase{
4045 testType: serverTest,
4046 name: "TLS13-1RTT-Server",
4047 config: Config{
4048 MaxVersion: VersionTLS13,
4049 MinVersion: VersionTLS13,
4050 },
David Benjamin46662482016-08-17 00:51:00 -04004051 resumeSession: true,
4052 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004053 // TLS 1.3 uses tickets, so the session should not be
4054 // cached statefully.
4055 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004056 })
4057
4058 tests = append(tests, testCase{
4059 name: "TLS13-HelloRetryRequest-Client",
4060 config: Config{
4061 MaxVersion: VersionTLS13,
4062 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004063 // P-384 requires a HelloRetryRequest against BoringSSL's default
4064 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004065 CurvePreferences: []CurveID{CurveP384},
4066 Bugs: ProtocolBugs{
4067 ExpectMissingKeyShare: true,
4068 },
4069 },
4070 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4071 resumeSession: true,
4072 })
4073
4074 tests = append(tests, testCase{
4075 testType: serverTest,
4076 name: "TLS13-HelloRetryRequest-Server",
4077 config: Config{
4078 MaxVersion: VersionTLS13,
4079 MinVersion: VersionTLS13,
4080 // Require a HelloRetryRequest for every curve.
4081 DefaultCurves: []CurveID{},
4082 },
4083 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4084 resumeSession: true,
4085 })
Steven Valdez2d850622017-01-11 11:34:52 -05004086
Steven Valdez2d850622017-01-11 11:34:52 -05004087 tests = append(tests, testCase{
4088 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004089 name: "TLS13-EarlyData-TooMuchData-Client",
4090 config: Config{
4091 MaxVersion: VersionTLS13,
4092 MinVersion: VersionTLS13,
4093 MaxEarlyDataSize: 2,
4094 },
4095 resumeConfig: &Config{
4096 MaxVersion: VersionTLS13,
4097 MinVersion: VersionTLS13,
4098 MaxEarlyDataSize: 2,
4099 Bugs: ProtocolBugs{
4100 ExpectEarlyData: [][]byte{{'h', 'e'}},
4101 },
4102 },
4103 resumeShimPrefix: "llo",
4104 resumeSession: true,
4105 flags: []string{
4106 "-enable-early-data",
4107 "-expect-early-data-info",
4108 "-expect-accept-early-data",
4109 "-on-resume-shim-writes-first",
4110 },
4111 })
4112
4113 // Unfinished writes can only be tested when operations are async. EarlyData
4114 // can't be tested as part of an ImplicitHandshake in this case since
4115 // otherwise the early data will be sent as normal data.
4116 if config.async && !config.implicitHandshake {
4117 tests = append(tests, testCase{
4118 testType: clientTest,
4119 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4120 config: Config{
4121 MaxVersion: VersionTLS13,
4122 MinVersion: VersionTLS13,
4123 MaxEarlyDataSize: 16384,
4124 },
4125 resumeConfig: &Config{
4126 MaxVersion: VersionTLS13,
4127 MinVersion: VersionTLS13,
4128 MaxEarlyDataSize: 16384,
4129 Bugs: ProtocolBugs{
4130 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4131 },
4132 },
4133 resumeSession: true,
4134 flags: []string{
4135 "-enable-early-data",
4136 "-expect-early-data-info",
4137 "-expect-accept-early-data",
4138 "-on-resume-read-with-unfinished-write",
4139 "-on-resume-shim-writes-first",
4140 },
4141 })
4142
4143 // Rejected unfinished writes are discarded (from the
4144 // perspective of the calling application) on 0-RTT
4145 // reject.
4146 tests = append(tests, testCase{
4147 testType: clientTest,
4148 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4149 config: Config{
4150 MaxVersion: VersionTLS13,
4151 MinVersion: VersionTLS13,
4152 MaxEarlyDataSize: 16384,
4153 },
4154 resumeConfig: &Config{
4155 MaxVersion: VersionTLS13,
4156 MinVersion: VersionTLS13,
4157 MaxEarlyDataSize: 16384,
4158 Bugs: ProtocolBugs{
4159 AlwaysRejectEarlyData: true,
4160 },
4161 },
4162 resumeSession: true,
4163 flags: []string{
4164 "-enable-early-data",
4165 "-expect-early-data-info",
4166 "-expect-reject-early-data",
4167 "-on-resume-read-with-unfinished-write",
4168 "-on-resume-shim-writes-first",
4169 },
4170 })
4171 }
4172
4173 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004174 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004175 name: "TLS13-MaxEarlyData-Server",
4176 config: Config{
4177 MaxVersion: VersionTLS13,
4178 MinVersion: VersionTLS13,
4179 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004180 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004181 ExpectEarlyDataAccepted: true,
4182 },
4183 },
4184 messageCount: 2,
4185 resumeSession: true,
4186 flags: []string{
4187 "-enable-early-data",
4188 "-expect-accept-early-data",
4189 },
4190 shouldFail: true,
4191 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4192 })
David Benjamine73c7f42016-08-17 00:29:33 -04004193 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004194
David Benjamin760b1dd2015-05-15 23:33:48 -04004195 // TLS client auth.
4196 tests = append(tests, testCase{
4197 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004198 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004199 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004200 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004201 ClientAuth: RequestClientCert,
4202 },
4203 })
4204 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004205 testType: serverTest,
4206 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004207 config: Config{
4208 MaxVersion: VersionTLS12,
4209 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004210 // Setting SSL_VERIFY_PEER allows anonymous clients.
4211 flags: []string{"-verify-peer"},
4212 })
David Benjamin582ba042016-07-07 12:33:25 -07004213 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004214 tests = append(tests, testCase{
4215 testType: clientTest,
4216 name: "ClientAuth-NoCertificate-Client-SSL3",
4217 config: Config{
4218 MaxVersion: VersionSSL30,
4219 ClientAuth: RequestClientCert,
4220 },
4221 })
4222 tests = append(tests, testCase{
4223 testType: serverTest,
4224 name: "ClientAuth-NoCertificate-Server-SSL3",
4225 config: Config{
4226 MaxVersion: VersionSSL30,
4227 },
4228 // Setting SSL_VERIFY_PEER allows anonymous clients.
4229 flags: []string{"-verify-peer"},
4230 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004231 tests = append(tests, testCase{
4232 testType: clientTest,
4233 name: "ClientAuth-NoCertificate-Client-TLS13",
4234 config: Config{
4235 MaxVersion: VersionTLS13,
4236 ClientAuth: RequestClientCert,
4237 },
4238 })
4239 tests = append(tests, testCase{
4240 testType: serverTest,
4241 name: "ClientAuth-NoCertificate-Server-TLS13",
4242 config: Config{
4243 MaxVersion: VersionTLS13,
4244 },
4245 // Setting SSL_VERIFY_PEER allows anonymous clients.
4246 flags: []string{"-verify-peer"},
4247 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004248 }
4249 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004250 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004251 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004253 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004254 ClientAuth: RequireAnyClientCert,
4255 },
4256 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004257 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4258 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004259 },
4260 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004261 tests = append(tests, testCase{
4262 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004263 name: "ClientAuth-RSA-Client-TLS13",
4264 config: Config{
4265 MaxVersion: VersionTLS13,
4266 ClientAuth: RequireAnyClientCert,
4267 },
4268 flags: []string{
4269 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4270 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4271 },
4272 })
4273 tests = append(tests, testCase{
4274 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004275 name: "ClientAuth-ECDSA-Client",
4276 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004277 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004278 ClientAuth: RequireAnyClientCert,
4279 },
4280 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004281 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4282 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004283 },
4284 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004285 tests = append(tests, testCase{
4286 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004287 name: "ClientAuth-ECDSA-Client-TLS13",
4288 config: Config{
4289 MaxVersion: VersionTLS13,
4290 ClientAuth: RequireAnyClientCert,
4291 },
4292 flags: []string{
4293 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4294 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4295 },
4296 })
4297 tests = append(tests, testCase{
4298 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004299 name: "ClientAuth-NoCertificate-OldCallback",
4300 config: Config{
4301 MaxVersion: VersionTLS12,
4302 ClientAuth: RequestClientCert,
4303 },
4304 flags: []string{"-use-old-client-cert-callback"},
4305 })
4306 tests = append(tests, testCase{
4307 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004308 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4309 config: Config{
4310 MaxVersion: VersionTLS13,
4311 ClientAuth: RequestClientCert,
4312 },
4313 flags: []string{"-use-old-client-cert-callback"},
4314 })
4315 tests = append(tests, testCase{
4316 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004317 name: "ClientAuth-OldCallback",
4318 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004319 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004320 ClientAuth: RequireAnyClientCert,
4321 },
4322 flags: []string{
4323 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4324 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4325 "-use-old-client-cert-callback",
4326 },
4327 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004328 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004329 testType: clientTest,
4330 name: "ClientAuth-OldCallback-TLS13",
4331 config: Config{
4332 MaxVersion: VersionTLS13,
4333 ClientAuth: RequireAnyClientCert,
4334 },
4335 flags: []string{
4336 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4337 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4338 "-use-old-client-cert-callback",
4339 },
4340 })
4341 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004342 testType: serverTest,
4343 name: "ClientAuth-Server",
4344 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004345 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004346 Certificates: []Certificate{rsaCertificate},
4347 },
4348 flags: []string{"-require-any-client-certificate"},
4349 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004350 tests = append(tests, testCase{
4351 testType: serverTest,
4352 name: "ClientAuth-Server-TLS13",
4353 config: Config{
4354 MaxVersion: VersionTLS13,
4355 Certificates: []Certificate{rsaCertificate},
4356 },
4357 flags: []string{"-require-any-client-certificate"},
4358 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004359
David Benjamin4c3ddf72016-06-29 18:13:53 -04004360 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004361 tests = append(tests, testCase{
4362 testType: serverTest,
4363 name: "Basic-Server-RSA",
4364 config: Config{
4365 MaxVersion: VersionTLS12,
4366 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4367 },
4368 flags: []string{
4369 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4370 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4371 },
4372 })
4373 tests = append(tests, testCase{
4374 testType: serverTest,
4375 name: "Basic-Server-ECDHE-RSA",
4376 config: Config{
4377 MaxVersion: VersionTLS12,
4378 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4379 },
4380 flags: []string{
4381 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4382 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4383 },
4384 })
4385 tests = append(tests, testCase{
4386 testType: serverTest,
4387 name: "Basic-Server-ECDHE-ECDSA",
4388 config: Config{
4389 MaxVersion: VersionTLS12,
4390 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4391 },
4392 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004393 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4394 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004395 },
4396 })
David Benjamin69522112017-03-28 15:38:29 -05004397 tests = append(tests, testCase{
4398 testType: serverTest,
4399 name: "Basic-Server-Ed25519",
4400 config: Config{
4401 MaxVersion: VersionTLS12,
4402 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4403 },
4404 flags: []string{
4405 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4406 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4407 "-enable-ed25519",
4408 },
4409 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004410
David Benjamin760b1dd2015-05-15 23:33:48 -04004411 // No session ticket support; server doesn't send NewSessionTicket.
4412 tests = append(tests, testCase{
4413 name: "SessionTicketsDisabled-Client",
4414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004415 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004416 SessionTicketsDisabled: true,
4417 },
4418 })
4419 tests = append(tests, testCase{
4420 testType: serverTest,
4421 name: "SessionTicketsDisabled-Server",
4422 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004423 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004424 SessionTicketsDisabled: true,
4425 },
4426 })
4427
4428 // Skip ServerKeyExchange in PSK key exchange if there's no
4429 // identity hint.
4430 tests = append(tests, testCase{
4431 name: "EmptyPSKHint-Client",
4432 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004433 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004434 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4435 PreSharedKey: []byte("secret"),
4436 },
4437 flags: []string{"-psk", "secret"},
4438 })
4439 tests = append(tests, testCase{
4440 testType: serverTest,
4441 name: "EmptyPSKHint-Server",
4442 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004443 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004444 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4445 PreSharedKey: []byte("secret"),
4446 },
4447 flags: []string{"-psk", "secret"},
4448 })
4449
David Benjamin4c3ddf72016-06-29 18:13:53 -04004450 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004451 tests = append(tests, testCase{
4452 testType: clientTest,
4453 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004454 config: Config{
4455 MaxVersion: VersionTLS12,
4456 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004457 flags: []string{
4458 "-enable-ocsp-stapling",
4459 "-expect-ocsp-response",
4460 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004461 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004462 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004463 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004464 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004465 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004466 testType: serverTest,
4467 name: "OCSPStapling-Server",
4468 config: Config{
4469 MaxVersion: VersionTLS12,
4470 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004471 expectedOCSPResponse: testOCSPResponse,
4472 flags: []string{
4473 "-ocsp-response",
4474 base64.StdEncoding.EncodeToString(testOCSPResponse),
4475 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004476 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004477 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004478 tests = append(tests, testCase{
4479 testType: clientTest,
4480 name: "OCSPStapling-Client-TLS13",
4481 config: Config{
4482 MaxVersion: VersionTLS13,
4483 },
4484 flags: []string{
4485 "-enable-ocsp-stapling",
4486 "-expect-ocsp-response",
4487 base64.StdEncoding.EncodeToString(testOCSPResponse),
4488 "-verify-peer",
4489 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004490 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004491 })
4492 tests = append(tests, testCase{
4493 testType: serverTest,
4494 name: "OCSPStapling-Server-TLS13",
4495 config: Config{
4496 MaxVersion: VersionTLS13,
4497 },
4498 expectedOCSPResponse: testOCSPResponse,
4499 flags: []string{
4500 "-ocsp-response",
4501 base64.StdEncoding.EncodeToString(testOCSPResponse),
4502 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004503 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004504 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004505
David Benjamin4c3ddf72016-06-29 18:13:53 -04004506 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004507 for _, vers := range tlsVersions {
4508 if config.protocol == dtls && !vers.hasDTLS {
4509 continue
4510 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004511 for _, useCustomCallback := range []bool{false, true} {
4512 for _, testType := range []testType{clientTest, serverTest} {
4513 suffix := "-Client"
4514 if testType == serverTest {
4515 suffix = "-Server"
4516 }
4517 suffix += "-" + vers.name
4518 if useCustomCallback {
4519 suffix += "-CustomCallback"
4520 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004521
David Benjamin3a1dd462017-07-11 16:13:10 -04004522 flags := []string{"-verify-peer"}
4523 if testType == serverTest {
4524 flags = append(flags, "-require-any-client-certificate")
4525 }
4526 if useCustomCallback {
4527 flags = append(flags, "-use-custom-verify-callback")
4528 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004529
David Benjamin3a1dd462017-07-11 16:13:10 -04004530 tests = append(tests, testCase{
4531 testType: testType,
4532 name: "CertificateVerificationSucceed" + suffix,
4533 config: Config{
4534 MaxVersion: vers.version,
4535 Certificates: []Certificate{rsaCertificate},
4536 },
4537 tls13Variant: vers.tls13Variant,
4538 flags: append([]string{"-expect-verify-result"}, flags...),
4539 resumeSession: true,
4540 })
4541 tests = append(tests, testCase{
4542 testType: testType,
4543 name: "CertificateVerificationFail" + suffix,
4544 config: Config{
4545 MaxVersion: vers.version,
4546 Certificates: []Certificate{rsaCertificate},
4547 },
4548 tls13Variant: vers.tls13Variant,
4549 flags: append([]string{"-verify-fail"}, flags...),
4550 shouldFail: true,
4551 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4552 })
4553 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004554 }
4555
4556 // By default, the client is in a soft fail mode where the peer
4557 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004558 tests = append(tests, testCase{
4559 testType: clientTest,
4560 name: "CertificateVerificationSoftFail-" + vers.name,
4561 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004562 MaxVersion: vers.version,
4563 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004564 },
David Benjamina5022392017-07-10 17:40:39 -04004565 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004566 flags: []string{
4567 "-verify-fail",
4568 "-expect-verify-result",
4569 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004570 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004571 })
4572 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004573
David Benjamin1d4f4c02016-07-26 18:03:08 -04004574 tests = append(tests, testCase{
4575 name: "ShimSendAlert",
4576 flags: []string{"-send-alert"},
4577 shimWritesFirst: true,
4578 shouldFail: true,
4579 expectedLocalError: "remote error: decompression failure",
4580 })
4581
David Benjamin582ba042016-07-07 12:33:25 -07004582 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004583 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004584 name: "Renegotiate-Client",
4585 config: Config{
4586 MaxVersion: VersionTLS12,
4587 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004588 renegotiate: 1,
4589 flags: []string{
4590 "-renegotiate-freely",
4591 "-expect-total-renegotiations", "1",
4592 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004593 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004594
David Benjamin47921102016-07-28 11:29:18 -04004595 tests = append(tests, testCase{
4596 name: "SendHalfHelloRequest",
4597 config: Config{
4598 MaxVersion: VersionTLS12,
4599 Bugs: ProtocolBugs{
4600 PackHelloRequestWithFinished: config.packHandshakeFlight,
4601 },
4602 },
4603 sendHalfHelloRequest: true,
4604 flags: []string{"-renegotiate-ignore"},
4605 shouldFail: true,
4606 expectedError: ":UNEXPECTED_RECORD:",
4607 })
4608
David Benjamin760b1dd2015-05-15 23:33:48 -04004609 // NPN on client and server; results in post-handshake message.
4610 tests = append(tests, testCase{
4611 name: "NPN-Client",
4612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004613 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004614 NextProtos: []string{"foo"},
4615 },
4616 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004617 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004618 expectedNextProto: "foo",
4619 expectedNextProtoType: npn,
4620 })
4621 tests = append(tests, testCase{
4622 testType: serverTest,
4623 name: "NPN-Server",
4624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004625 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004626 NextProtos: []string{"bar"},
4627 },
4628 flags: []string{
4629 "-advertise-npn", "\x03foo\x03bar\x03baz",
4630 "-expect-next-proto", "bar",
4631 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004632 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004633 expectedNextProto: "bar",
4634 expectedNextProtoType: npn,
4635 })
4636
4637 // TODO(davidben): Add tests for when False Start doesn't trigger.
4638
4639 // Client does False Start and negotiates NPN.
4640 tests = append(tests, testCase{
4641 name: "FalseStart",
4642 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004643 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004644 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4645 NextProtos: []string{"foo"},
4646 Bugs: ProtocolBugs{
4647 ExpectFalseStart: true,
4648 },
4649 },
4650 flags: []string{
4651 "-false-start",
4652 "-select-next-proto", "foo",
4653 },
4654 shimWritesFirst: true,
4655 resumeSession: true,
4656 })
4657
4658 // Client does False Start and negotiates ALPN.
4659 tests = append(tests, testCase{
4660 name: "FalseStart-ALPN",
4661 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004662 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004663 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4664 NextProtos: []string{"foo"},
4665 Bugs: ProtocolBugs{
4666 ExpectFalseStart: true,
4667 },
4668 },
4669 flags: []string{
4670 "-false-start",
4671 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004672 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004673 },
4674 shimWritesFirst: true,
4675 resumeSession: true,
4676 })
4677
David Benjamin760b1dd2015-05-15 23:33:48 -04004678 // False Start without session tickets.
4679 tests = append(tests, testCase{
4680 name: "FalseStart-SessionTicketsDisabled",
4681 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004682 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004683 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4684 NextProtos: []string{"foo"},
4685 SessionTicketsDisabled: true,
4686 Bugs: ProtocolBugs{
4687 ExpectFalseStart: true,
4688 },
4689 },
4690 flags: []string{
4691 "-false-start",
4692 "-select-next-proto", "foo",
4693 },
4694 shimWritesFirst: true,
4695 })
4696
4697 // Server parses a V2ClientHello.
4698 tests = append(tests, testCase{
4699 testType: serverTest,
4700 name: "SendV2ClientHello",
4701 config: Config{
4702 // Choose a cipher suite that does not involve
4703 // elliptic curves, so no extensions are
4704 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004705 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004706 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004707 Bugs: ProtocolBugs{
4708 SendV2ClientHello: true,
4709 },
4710 },
David Benjamin78b8b992017-08-01 18:38:41 -04004711 flags: []string{
4712 "-expect-msg-callback",
4713 `read v2clienthello
4714write hs 2
4715write hs 11
4716write hs 14
4717read hs 16
4718read ccs
4719read hs 20
4720write ccs
4721write hs 20
4722read alert 1 0
4723`,
4724 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004725 })
4726
Nick Harper60a85cb2016-09-23 16:25:11 -07004727 // Test Channel ID
4728 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004729 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004730 continue
4731 }
4732 // Client sends a Channel ID.
4733 tests = append(tests, testCase{
4734 name: "ChannelID-Client-" + ver.name,
4735 config: Config{
4736 MaxVersion: ver.version,
4737 RequestChannelID: true,
4738 },
David Benjamina5022392017-07-10 17:40:39 -04004739 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004740 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4741 resumeSession: true,
4742 expectChannelID: true,
4743 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004744
Nick Harper60a85cb2016-09-23 16:25:11 -07004745 // Server accepts a Channel ID.
4746 tests = append(tests, testCase{
4747 testType: serverTest,
4748 name: "ChannelID-Server-" + ver.name,
4749 config: Config{
4750 MaxVersion: ver.version,
4751 ChannelID: channelIDKey,
4752 },
David Benjamina5022392017-07-10 17:40:39 -04004753 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004754 flags: []string{
4755 "-expect-channel-id",
4756 base64.StdEncoding.EncodeToString(channelIDBytes),
4757 },
4758 resumeSession: true,
4759 expectChannelID: true,
4760 })
4761
4762 tests = append(tests, testCase{
4763 testType: serverTest,
4764 name: "InvalidChannelIDSignature-" + ver.name,
4765 config: Config{
4766 MaxVersion: ver.version,
4767 ChannelID: channelIDKey,
4768 Bugs: ProtocolBugs{
4769 InvalidChannelIDSignature: true,
4770 },
4771 },
David Benjamina5022392017-07-10 17:40:39 -04004772 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004773 flags: []string{"-enable-channel-id"},
4774 shouldFail: true,
4775 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4776 })
David Benjamin634f4752017-07-01 11:08:41 -04004777
4778 if ver.version < VersionTLS13 {
4779 // Channel ID requires ECDHE ciphers.
4780 tests = append(tests, testCase{
4781 testType: serverTest,
4782 name: "ChannelID-NoECDHE-" + ver.name,
4783 config: Config{
4784 MaxVersion: ver.version,
4785 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4786 ChannelID: channelIDKey,
4787 },
4788 expectChannelID: false,
4789 flags: []string{"-enable-channel-id"},
4790 })
4791
4792 // Sanity-check setting expectChannelID false works.
4793 tests = append(tests, testCase{
4794 testType: serverTest,
4795 name: "ChannelID-ECDHE-" + ver.name,
4796 config: Config{
4797 MaxVersion: ver.version,
4798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4799 ChannelID: channelIDKey,
4800 },
4801 expectChannelID: false,
4802 flags: []string{"-enable-channel-id"},
4803 shouldFail: true,
4804 expectedLocalError: "channel ID unexpectedly negotiated",
4805 })
4806 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004807 }
David Benjamin30789da2015-08-29 22:56:45 -04004808
David Benjaminf8fcdf32016-06-08 15:56:13 -04004809 // Channel ID and NPN at the same time, to ensure their relative
4810 // ordering is correct.
4811 tests = append(tests, testCase{
4812 name: "ChannelID-NPN-Client",
4813 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004814 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004815 RequestChannelID: true,
4816 NextProtos: []string{"foo"},
4817 },
4818 flags: []string{
4819 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4820 "-select-next-proto", "foo",
4821 },
4822 resumeSession: true,
4823 expectChannelID: true,
4824 expectedNextProto: "foo",
4825 expectedNextProtoType: npn,
4826 })
4827 tests = append(tests, testCase{
4828 testType: serverTest,
4829 name: "ChannelID-NPN-Server",
4830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004831 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004832 ChannelID: channelIDKey,
4833 NextProtos: []string{"bar"},
4834 },
4835 flags: []string{
4836 "-expect-channel-id",
4837 base64.StdEncoding.EncodeToString(channelIDBytes),
4838 "-advertise-npn", "\x03foo\x03bar\x03baz",
4839 "-expect-next-proto", "bar",
4840 },
4841 resumeSession: true,
4842 expectChannelID: true,
4843 expectedNextProto: "bar",
4844 expectedNextProtoType: npn,
4845 })
4846
David Benjamin30789da2015-08-29 22:56:45 -04004847 // Bidirectional shutdown with the runner initiating.
4848 tests = append(tests, testCase{
4849 name: "Shutdown-Runner",
4850 config: Config{
4851 Bugs: ProtocolBugs{
4852 ExpectCloseNotify: true,
4853 },
4854 },
4855 flags: []string{"-check-close-notify"},
4856 })
4857
David Benjamine3843d42017-03-25 18:00:56 -05004858 if !config.implicitHandshake {
4859 // Bidirectional shutdown with the shim initiating. The runner,
4860 // in the meantime, sends garbage before the close_notify which
4861 // the shim must ignore. This test is disabled under implicit
4862 // handshake tests because the shim never reads or writes.
4863 tests = append(tests, testCase{
4864 name: "Shutdown-Shim",
4865 config: Config{
4866 MaxVersion: VersionTLS12,
4867 Bugs: ProtocolBugs{
4868 ExpectCloseNotify: true,
4869 },
David Benjamin30789da2015-08-29 22:56:45 -04004870 },
David Benjamine3843d42017-03-25 18:00:56 -05004871 shimShutsDown: true,
4872 sendEmptyRecords: 1,
4873 sendWarningAlerts: 1,
4874 flags: []string{"-check-close-notify"},
4875 })
4876 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004877 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004878 // TODO(davidben): DTLS 1.3 will want a similar thing for
4879 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004880 tests = append(tests, testCase{
4881 name: "SkipHelloVerifyRequest",
4882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004883 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004884 Bugs: ProtocolBugs{
4885 SkipHelloVerifyRequest: true,
4886 },
4887 },
4888 })
4889 }
4890
David Benjamin760b1dd2015-05-15 23:33:48 -04004891 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004892 test.protocol = config.protocol
4893 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004894 test.name += "-DTLS"
4895 }
David Benjamin582ba042016-07-07 12:33:25 -07004896 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004897 test.name += "-Async"
4898 test.flags = append(test.flags, "-async")
4899 } else {
4900 test.name += "-Sync"
4901 }
David Benjamin582ba042016-07-07 12:33:25 -07004902 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004903 test.name += "-SplitHandshakeRecords"
4904 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004905 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004906 test.config.Bugs.MaxPacketLength = 256
4907 test.flags = append(test.flags, "-mtu", "256")
4908 }
4909 }
David Benjamin582ba042016-07-07 12:33:25 -07004910 if config.packHandshakeFlight {
4911 test.name += "-PackHandshakeFlight"
4912 test.config.Bugs.PackHandshakeFlight = true
4913 }
David Benjamine3843d42017-03-25 18:00:56 -05004914 if config.implicitHandshake {
4915 test.name += "-ImplicitHandshake"
4916 test.flags = append(test.flags, "-implicit-handshake")
4917 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004918 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004919 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004920}
4921
Adam Langley524e7172015-02-20 16:04:00 -08004922func addDDoSCallbackTests() {
4923 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004924 for _, resume := range []bool{false, true} {
4925 suffix := "Resume"
4926 if resume {
4927 suffix = "No" + suffix
4928 }
4929
4930 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004931 testType: serverTest,
4932 name: "Server-DDoS-OK-" + suffix,
4933 config: Config{
4934 MaxVersion: VersionTLS12,
4935 },
Adam Langley524e7172015-02-20 16:04:00 -08004936 flags: []string{"-install-ddos-callback"},
4937 resumeSession: resume,
4938 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004939 testCases = append(testCases, testCase{
4940 testType: serverTest,
4941 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4942 config: Config{
4943 MaxVersion: VersionTLS13,
4944 },
4945 flags: []string{"-install-ddos-callback"},
4946 resumeSession: resume,
4947 })
Adam Langley524e7172015-02-20 16:04:00 -08004948
4949 failFlag := "-fail-ddos-callback"
4950 if resume {
4951 failFlag = "-fail-second-ddos-callback"
4952 }
4953 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004954 testType: serverTest,
4955 name: "Server-DDoS-Reject-" + suffix,
4956 config: Config{
4957 MaxVersion: VersionTLS12,
4958 },
David Benjamin2c66e072016-09-16 15:58:00 -04004959 flags: []string{"-install-ddos-callback", failFlag},
4960 resumeSession: resume,
4961 shouldFail: true,
4962 expectedError: ":CONNECTION_REJECTED:",
4963 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004964 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004965 testCases = append(testCases, testCase{
4966 testType: serverTest,
4967 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4968 config: Config{
4969 MaxVersion: VersionTLS13,
4970 },
David Benjamin2c66e072016-09-16 15:58:00 -04004971 flags: []string{"-install-ddos-callback", failFlag},
4972 resumeSession: resume,
4973 shouldFail: true,
4974 expectedError: ":CONNECTION_REJECTED:",
4975 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004976 })
Adam Langley524e7172015-02-20 16:04:00 -08004977 }
4978}
4979
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004980func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04004981 for _, protocol := range []protocol{tls, dtls} {
4982 for _, shimVers := range allVersions(protocol) {
4983 // Assemble flags to disable all newer versions on the shim.
4984 var flags []string
4985 for _, vers := range allVersions(protocol) {
4986 if vers.version > shimVers.version {
4987 flags = append(flags, vers.excludeFlag)
4988 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004989 }
Steven Valdez520e1222017-06-13 12:45:25 -04004990
4991 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
4992
4993 if shimVers.tls13Variant != 0 {
4994 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
4995 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
4996 }
4997
4998 // Test configuring the runner's maximum version.
4999 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005000 expectedVersion := shimVers.version
5001 if runnerVers.version < shimVers.version {
5002 expectedVersion = runnerVers.version
5003 }
Steven Valdez520e1222017-06-13 12:45:25 -04005004 // When running and shim have different TLS 1.3 variants enabled,
5005 // shim clients are expected to fall back to TLS 1.2, while shim
5006 // servers support both variants when enabled when the experiment is
5007 // enabled.
5008 expectedServerVersion := expectedVersion
5009 expectedClientVersion := expectedVersion
5010 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5011 expectedClientVersion = VersionTLS12
5012 expectedServerVersion = VersionTLS12
5013 if shimVers.tls13Variant != TLS13Default {
5014 expectedServerVersion = VersionTLS13
5015 }
5016 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005017
David Benjamin8b8c0062014-11-23 02:47:52 -05005018 suffix := shimVers.name + "-" + runnerVers.name
5019 if protocol == dtls {
5020 suffix += "-DTLS"
5021 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005022
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005023 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005024 clientVers := shimVers.version
5025 if clientVers > VersionTLS10 {
5026 clientVers = VersionTLS10
5027 }
Steven Valdez520e1222017-06-13 12:45:25 -04005028 clientVers = recordVersionToWire(clientVers, protocol)
5029 serverVers := expectedServerVersion
5030 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005031 serverVers = VersionTLS10
Steven Valdezc7d4d212017-09-11 13:53:08 -04005032 if runnerVers.tls13Variant == TLS13Experiment2 || runnerVers.tls13Variant == TLS13Experiment3 {
Steven Valdez16821262017-09-08 17:03:42 -04005033 serverVers = VersionTLS12
5034 }
Nick Harper1fd39d82016-06-14 18:14:35 -07005035 }
Steven Valdez520e1222017-06-13 12:45:25 -04005036 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005037
David Benjamin8b8c0062014-11-23 02:47:52 -05005038 testCases = append(testCases, testCase{
5039 protocol: protocol,
5040 testType: clientTest,
5041 name: "VersionNegotiation-Client-" + suffix,
5042 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005043 MaxVersion: runnerVers.version,
5044 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005045 Bugs: ProtocolBugs{
5046 ExpectInitialRecordVersion: clientVers,
5047 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005048 },
5049 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005050 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005051 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005052 testCases = append(testCases, testCase{
5053 protocol: protocol,
5054 testType: clientTest,
5055 name: "VersionNegotiation-Client2-" + suffix,
5056 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005057 MaxVersion: runnerVers.version,
5058 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005059 Bugs: ProtocolBugs{
5060 ExpectInitialRecordVersion: clientVers,
5061 },
5062 },
Steven Valdez520e1222017-06-13 12:45:25 -04005063 flags: flags2,
5064 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005065 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005066
5067 testCases = append(testCases, testCase{
5068 protocol: protocol,
5069 testType: serverTest,
5070 name: "VersionNegotiation-Server-" + suffix,
5071 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005072 MaxVersion: runnerVers.version,
5073 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005074 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005075 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005076 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005077 },
5078 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005079 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005080 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005081 testCases = append(testCases, testCase{
5082 protocol: protocol,
5083 testType: serverTest,
5084 name: "VersionNegotiation-Server2-" + suffix,
5085 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005086 MaxVersion: runnerVers.version,
5087 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005088 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005089 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005090 },
5091 },
Steven Valdez520e1222017-06-13 12:45:25 -04005092 flags: flags2,
5093 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005094 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005095 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005096 }
5097 }
David Benjamin95c69562016-06-29 18:15:03 -04005098
Steven Valdezfdd10992016-09-15 16:27:05 -04005099 // Test the version extension at all versions.
5100 for _, vers := range tlsVersions {
5101 protocols := []protocol{tls}
5102 if vers.hasDTLS {
5103 protocols = append(protocols, dtls)
5104 }
5105 for _, protocol := range protocols {
5106 suffix := vers.name
5107 if protocol == dtls {
5108 suffix += "-DTLS"
5109 }
5110
Steven Valdezfdd10992016-09-15 16:27:05 -04005111 testCases = append(testCases, testCase{
5112 protocol: protocol,
5113 testType: serverTest,
5114 name: "VersionNegotiationExtension-" + suffix,
5115 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005116 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005117 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005118 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005119 },
5120 },
5121 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005122 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005123 })
5124 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005125 }
5126
5127 // If all versions are unknown, negotiation fails.
5128 testCases = append(testCases, testCase{
5129 testType: serverTest,
5130 name: "NoSupportedVersions",
5131 config: Config{
5132 Bugs: ProtocolBugs{
5133 SendSupportedVersions: []uint16{0x1111},
5134 },
5135 },
5136 shouldFail: true,
5137 expectedError: ":UNSUPPORTED_PROTOCOL:",
5138 })
5139 testCases = append(testCases, testCase{
5140 protocol: dtls,
5141 testType: serverTest,
5142 name: "NoSupportedVersions-DTLS",
5143 config: Config{
5144 Bugs: ProtocolBugs{
5145 SendSupportedVersions: []uint16{0x1111},
5146 },
5147 },
5148 shouldFail: true,
5149 expectedError: ":UNSUPPORTED_PROTOCOL:",
5150 })
5151
5152 testCases = append(testCases, testCase{
5153 testType: serverTest,
5154 name: "ClientHelloVersionTooHigh",
5155 config: Config{
5156 MaxVersion: VersionTLS13,
5157 Bugs: ProtocolBugs{
5158 SendClientVersion: 0x0304,
5159 OmitSupportedVersions: true,
5160 },
5161 },
5162 expectedVersion: VersionTLS12,
5163 })
5164
5165 testCases = append(testCases, testCase{
5166 testType: serverTest,
5167 name: "ConflictingVersionNegotiation",
5168 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005169 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005170 SendClientVersion: VersionTLS12,
5171 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005172 },
5173 },
David Benjaminad75a662016-09-30 15:42:59 -04005174 // The extension takes precedence over the ClientHello version.
5175 expectedVersion: VersionTLS11,
5176 })
5177
5178 testCases = append(testCases, testCase{
5179 testType: serverTest,
5180 name: "ConflictingVersionNegotiation-2",
5181 config: Config{
5182 Bugs: ProtocolBugs{
5183 SendClientVersion: VersionTLS11,
5184 SendSupportedVersions: []uint16{VersionTLS12},
5185 },
5186 },
5187 // The extension takes precedence over the ClientHello version.
5188 expectedVersion: VersionTLS12,
5189 })
5190
5191 testCases = append(testCases, testCase{
5192 testType: serverTest,
5193 name: "RejectFinalTLS13",
5194 config: Config{
5195 Bugs: ProtocolBugs{
5196 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5197 },
5198 },
5199 // We currently implement a draft TLS 1.3 version. Ensure that
5200 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005201 expectedVersion: VersionTLS12,
5202 })
5203
Steven Valdez038da9b2017-07-10 12:57:25 -04005204 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5205 // the ServerHello.
5206 testCases = append(testCases, testCase{
5207 testType: clientTest,
5208 name: "SupportedVersionSelection-TLS12",
5209 config: Config{
5210 MaxVersion: VersionTLS12,
5211 Bugs: ProtocolBugs{
5212 SendServerSupportedExtensionVersion: VersionTLS12,
5213 },
5214 },
5215 shouldFail: true,
5216 expectedError: ":UNEXPECTED_EXTENSION:",
5217 })
5218
5219 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5220 // supported_versions extension in the ServerHello.
5221 testCases = append(testCases, testCase{
5222 testType: clientTest,
5223 name: "SupportedVersionSelection-TLS13",
5224 config: Config{
5225 MaxVersion: VersionTLS13,
5226 Bugs: ProtocolBugs{
5227 SendServerSupportedExtensionVersion: tls13DraftVersion,
5228 },
5229 },
5230 shouldFail: true,
5231 expectedError: ":UNEXPECTED_EXTENSION:",
5232 })
5233
Brian Smithf85d3232016-10-28 10:34:06 -10005234 // Test that the maximum version is selected regardless of the
5235 // client-sent order.
5236 testCases = append(testCases, testCase{
5237 testType: serverTest,
5238 name: "IgnoreClientVersionOrder",
5239 config: Config{
5240 Bugs: ProtocolBugs{
5241 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5242 },
5243 },
5244 expectedVersion: VersionTLS13,
5245 })
5246
David Benjamin95c69562016-06-29 18:15:03 -04005247 // Test for version tolerance.
5248 testCases = append(testCases, testCase{
5249 testType: serverTest,
5250 name: "MinorVersionTolerance",
5251 config: Config{
5252 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005253 SendClientVersion: 0x03ff,
5254 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005255 },
5256 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005257 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005258 })
5259 testCases = append(testCases, testCase{
5260 testType: serverTest,
5261 name: "MajorVersionTolerance",
5262 config: Config{
5263 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005264 SendClientVersion: 0x0400,
5265 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005266 },
5267 },
David Benjaminad75a662016-09-30 15:42:59 -04005268 // TLS 1.3 must be negotiated with the supported_versions
5269 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005270 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005271 })
David Benjaminad75a662016-09-30 15:42:59 -04005272 testCases = append(testCases, testCase{
5273 testType: serverTest,
5274 name: "VersionTolerance-TLS13",
5275 config: Config{
5276 Bugs: ProtocolBugs{
5277 // Although TLS 1.3 does not use
5278 // ClientHello.version, it still tolerates high
5279 // values there.
5280 SendClientVersion: 0x0400,
5281 },
5282 },
5283 expectedVersion: VersionTLS13,
5284 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005285
David Benjamin95c69562016-06-29 18:15:03 -04005286 testCases = append(testCases, testCase{
5287 protocol: dtls,
5288 testType: serverTest,
5289 name: "MinorVersionTolerance-DTLS",
5290 config: Config{
5291 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005292 SendClientVersion: 0xfe00,
5293 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005294 },
5295 },
5296 expectedVersion: VersionTLS12,
5297 })
5298 testCases = append(testCases, testCase{
5299 protocol: dtls,
5300 testType: serverTest,
5301 name: "MajorVersionTolerance-DTLS",
5302 config: Config{
5303 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005304 SendClientVersion: 0xfdff,
5305 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005306 },
5307 },
5308 expectedVersion: VersionTLS12,
5309 })
5310
5311 // Test that versions below 3.0 are rejected.
5312 testCases = append(testCases, testCase{
5313 testType: serverTest,
5314 name: "VersionTooLow",
5315 config: Config{
5316 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005317 SendClientVersion: 0x0200,
5318 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005319 },
5320 },
5321 shouldFail: true,
5322 expectedError: ":UNSUPPORTED_PROTOCOL:",
5323 })
5324 testCases = append(testCases, testCase{
5325 protocol: dtls,
5326 testType: serverTest,
5327 name: "VersionTooLow-DTLS",
5328 config: Config{
5329 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005330 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005331 },
5332 },
5333 shouldFail: true,
5334 expectedError: ":UNSUPPORTED_PROTOCOL:",
5335 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005336
David Benjamin2dc02042016-09-19 19:57:37 -04005337 testCases = append(testCases, testCase{
5338 name: "ServerBogusVersion",
5339 config: Config{
5340 Bugs: ProtocolBugs{
5341 SendServerHelloVersion: 0x1234,
5342 },
5343 },
5344 shouldFail: true,
5345 expectedError: ":UNSUPPORTED_PROTOCOL:",
5346 })
5347
David Benjamin1f61f0d2016-07-10 12:20:35 -04005348 // Test TLS 1.3's downgrade signal.
5349 testCases = append(testCases, testCase{
5350 name: "Downgrade-TLS12-Client",
5351 config: Config{
5352 Bugs: ProtocolBugs{
5353 NegotiateVersion: VersionTLS12,
5354 },
5355 },
David Benjamin592b5322016-09-30 15:15:01 -04005356 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005357 // TODO(davidben): This test should fail once TLS 1.3 is final
5358 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005359 })
5360 testCases = append(testCases, testCase{
5361 testType: serverTest,
5362 name: "Downgrade-TLS12-Server",
5363 config: Config{
5364 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005365 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005366 },
5367 },
David Benjamin592b5322016-09-30 15:15:01 -04005368 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005369 // TODO(davidben): This test should fail once TLS 1.3 is final
5370 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005371 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005372}
5373
David Benjaminaccb4542014-12-12 23:44:33 -05005374func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005375 for _, protocol := range []protocol{tls, dtls} {
5376 for _, shimVers := range allVersions(protocol) {
5377 // Assemble flags to disable all older versions on the shim.
5378 var flags []string
5379 for _, vers := range allVersions(protocol) {
5380 if vers.version < shimVers.version {
5381 flags = append(flags, vers.excludeFlag)
5382 }
David Benjaminaccb4542014-12-12 23:44:33 -05005383 }
Steven Valdez520e1222017-06-13 12:45:25 -04005384
5385 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5386
5387 if shimVers.tls13Variant != 0 {
5388 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5389 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5390 }
5391
5392 for _, runnerVers := range allVersions(protocol) {
5393 // Different TLS 1.3 variants are incompatible with each other and don't
5394 // produce consistent minimum versions.
5395 //
5396 // TODO(davidben): Fold these tests (the main value is in the
5397 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5398 // on intended shim behavior, not the shim + runner combination.
5399 if shimVers.tls13Variant != runnerVers.tls13Variant {
5400 continue
5401 }
5402
David Benjaminaccb4542014-12-12 23:44:33 -05005403 suffix := shimVers.name + "-" + runnerVers.name
5404 if protocol == dtls {
5405 suffix += "-DTLS"
5406 }
David Benjaminaccb4542014-12-12 23:44:33 -05005407
David Benjaminaccb4542014-12-12 23:44:33 -05005408 var expectedVersion uint16
5409 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005410 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005411 if runnerVers.version >= shimVers.version {
5412 expectedVersion = runnerVers.version
5413 } else {
5414 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005415 expectedError = ":UNSUPPORTED_PROTOCOL:"
5416 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005417 }
5418
5419 testCases = append(testCases, testCase{
5420 protocol: protocol,
5421 testType: clientTest,
5422 name: "MinimumVersion-Client-" + suffix,
5423 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005424 MaxVersion: runnerVers.version,
5425 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005426 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005427 // Ensure the server does not decline to
5428 // select a version (versions extension) or
5429 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005430 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005431 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005432 },
David Benjaminaccb4542014-12-12 23:44:33 -05005433 },
David Benjamin87909c02014-12-13 01:55:01 -05005434 flags: flags,
5435 expectedVersion: expectedVersion,
5436 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005437 expectedError: expectedError,
5438 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005439 })
5440 testCases = append(testCases, testCase{
5441 protocol: protocol,
5442 testType: clientTest,
5443 name: "MinimumVersion-Client2-" + suffix,
5444 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005445 MaxVersion: runnerVers.version,
5446 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005447 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005448 // Ensure the server does not decline to
5449 // select a version (versions extension) or
5450 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005451 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005452 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005453 },
David Benjaminaccb4542014-12-12 23:44:33 -05005454 },
Steven Valdez520e1222017-06-13 12:45:25 -04005455 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005456 expectedVersion: expectedVersion,
5457 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005458 expectedError: expectedError,
5459 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005460 })
5461
5462 testCases = append(testCases, testCase{
5463 protocol: protocol,
5464 testType: serverTest,
5465 name: "MinimumVersion-Server-" + suffix,
5466 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005467 MaxVersion: runnerVers.version,
5468 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005469 },
David Benjamin87909c02014-12-13 01:55:01 -05005470 flags: flags,
5471 expectedVersion: expectedVersion,
5472 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005473 expectedError: expectedError,
5474 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005475 })
5476 testCases = append(testCases, testCase{
5477 protocol: protocol,
5478 testType: serverTest,
5479 name: "MinimumVersion-Server2-" + suffix,
5480 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005481 MaxVersion: runnerVers.version,
5482 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005483 },
Steven Valdez520e1222017-06-13 12:45:25 -04005484 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005485 expectedVersion: expectedVersion,
5486 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005487 expectedError: expectedError,
5488 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005489 })
5490 }
5491 }
5492 }
5493}
5494
David Benjamine78bfde2014-09-06 12:45:15 -04005495func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005496 // TODO(davidben): Extensions, where applicable, all move their server
5497 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5498 // tests for both. Also test interaction with 0-RTT when implemented.
5499
David Benjamin97d17d92016-07-14 16:12:00 -04005500 // Repeat extensions tests all versions except SSL 3.0.
5501 for _, ver := range tlsVersions {
5502 if ver.version == VersionSSL30 {
5503 continue
5504 }
5505
David Benjamin97d17d92016-07-14 16:12:00 -04005506 // Test that duplicate extensions are rejected.
5507 testCases = append(testCases, testCase{
5508 testType: clientTest,
5509 name: "DuplicateExtensionClient-" + ver.name,
5510 config: Config{
5511 MaxVersion: ver.version,
5512 Bugs: ProtocolBugs{
5513 DuplicateExtension: true,
5514 },
David Benjamine78bfde2014-09-06 12:45:15 -04005515 },
David Benjamina5022392017-07-10 17:40:39 -04005516 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005517 shouldFail: true,
5518 expectedLocalError: "remote error: error decoding message",
5519 })
5520 testCases = append(testCases, testCase{
5521 testType: serverTest,
5522 name: "DuplicateExtensionServer-" + ver.name,
5523 config: Config{
5524 MaxVersion: ver.version,
5525 Bugs: ProtocolBugs{
5526 DuplicateExtension: true,
5527 },
David Benjamine78bfde2014-09-06 12:45:15 -04005528 },
David Benjamina5022392017-07-10 17:40:39 -04005529 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005530 shouldFail: true,
5531 expectedLocalError: "remote error: error decoding message",
5532 })
5533
5534 // Test SNI.
5535 testCases = append(testCases, testCase{
5536 testType: clientTest,
5537 name: "ServerNameExtensionClient-" + ver.name,
5538 config: Config{
5539 MaxVersion: ver.version,
5540 Bugs: ProtocolBugs{
5541 ExpectServerName: "example.com",
5542 },
David Benjamine78bfde2014-09-06 12:45:15 -04005543 },
David Benjamina5022392017-07-10 17:40:39 -04005544 tls13Variant: ver.tls13Variant,
5545 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005546 })
5547 testCases = append(testCases, testCase{
5548 testType: clientTest,
5549 name: "ServerNameExtensionClientMismatch-" + ver.name,
5550 config: Config{
5551 MaxVersion: ver.version,
5552 Bugs: ProtocolBugs{
5553 ExpectServerName: "mismatch.com",
5554 },
David Benjamine78bfde2014-09-06 12:45:15 -04005555 },
David Benjamin97d17d92016-07-14 16:12:00 -04005556 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005557 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005558 shouldFail: true,
5559 expectedLocalError: "tls: unexpected server name",
5560 })
5561 testCases = append(testCases, testCase{
5562 testType: clientTest,
5563 name: "ServerNameExtensionClientMissing-" + ver.name,
5564 config: Config{
5565 MaxVersion: ver.version,
5566 Bugs: ProtocolBugs{
5567 ExpectServerName: "missing.com",
5568 },
David Benjamine78bfde2014-09-06 12:45:15 -04005569 },
David Benjamina5022392017-07-10 17:40:39 -04005570 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005571 shouldFail: true,
5572 expectedLocalError: "tls: unexpected server name",
5573 })
5574 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005575 testType: clientTest,
5576 name: "TolerateServerNameAck-" + ver.name,
5577 config: Config{
5578 MaxVersion: ver.version,
5579 Bugs: ProtocolBugs{
5580 SendServerNameAck: true,
5581 },
5582 },
David Benjamina5022392017-07-10 17:40:39 -04005583 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005584 flags: []string{"-host-name", "example.com"},
5585 resumeSession: true,
5586 })
5587 testCases = append(testCases, testCase{
5588 testType: clientTest,
5589 name: "UnsolicitedServerNameAck-" + ver.name,
5590 config: Config{
5591 MaxVersion: ver.version,
5592 Bugs: ProtocolBugs{
5593 SendServerNameAck: true,
5594 },
5595 },
David Benjamina5022392017-07-10 17:40:39 -04005596 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005597 shouldFail: true,
5598 expectedError: ":UNEXPECTED_EXTENSION:",
5599 expectedLocalError: "remote error: unsupported extension",
5600 })
5601 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005602 testType: serverTest,
5603 name: "ServerNameExtensionServer-" + ver.name,
5604 config: Config{
5605 MaxVersion: ver.version,
5606 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005607 },
David Benjamina5022392017-07-10 17:40:39 -04005608 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005609 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005610 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005611 })
5612
5613 // Test ALPN.
5614 testCases = append(testCases, testCase{
5615 testType: clientTest,
5616 name: "ALPNClient-" + ver.name,
5617 config: Config{
5618 MaxVersion: ver.version,
5619 NextProtos: []string{"foo"},
5620 },
5621 flags: []string{
5622 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5623 "-expect-alpn", "foo",
5624 },
David Benjamina5022392017-07-10 17:40:39 -04005625 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005626 expectedNextProto: "foo",
5627 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005628 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005629 })
5630 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005631 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005632 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005633 config: Config{
5634 MaxVersion: ver.version,
5635 Bugs: ProtocolBugs{
5636 SendALPN: "baz",
5637 },
5638 },
5639 flags: []string{
5640 "-advertise-alpn", "\x03foo\x03bar",
5641 },
David Benjamina5022392017-07-10 17:40:39 -04005642 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005643 shouldFail: true,
5644 expectedError: ":INVALID_ALPN_PROTOCOL:",
5645 expectedLocalError: "remote error: illegal parameter",
5646 })
5647 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005648 testType: clientTest,
5649 name: "ALPNClient-AllowUnknown-" + ver.name,
5650 config: Config{
5651 MaxVersion: ver.version,
5652 Bugs: ProtocolBugs{
5653 SendALPN: "baz",
5654 },
5655 },
5656 flags: []string{
5657 "-advertise-alpn", "\x03foo\x03bar",
5658 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005659 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005660 },
David Benjamina5022392017-07-10 17:40:39 -04005661 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005662 })
5663 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005664 testType: serverTest,
5665 name: "ALPNServer-" + ver.name,
5666 config: Config{
5667 MaxVersion: ver.version,
5668 NextProtos: []string{"foo", "bar", "baz"},
5669 },
5670 flags: []string{
5671 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5672 "-select-alpn", "foo",
5673 },
David Benjamina5022392017-07-10 17:40:39 -04005674 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005675 expectedNextProto: "foo",
5676 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005677 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005678 })
5679 testCases = append(testCases, testCase{
5680 testType: serverTest,
5681 name: "ALPNServer-Decline-" + ver.name,
5682 config: Config{
5683 MaxVersion: ver.version,
5684 NextProtos: []string{"foo", "bar", "baz"},
5685 },
5686 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005687 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005688 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005689 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005690 })
5691
David Benjamin25fe85b2016-08-09 20:00:32 -04005692 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5693 // called once.
5694 testCases = append(testCases, testCase{
5695 testType: serverTest,
5696 name: "ALPNServer-Async-" + ver.name,
5697 config: Config{
5698 MaxVersion: ver.version,
5699 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005700 // Prior to TLS 1.3, exercise the asynchronous session callback.
5701 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005702 },
5703 flags: []string{
5704 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5705 "-select-alpn", "foo",
5706 "-async",
5707 },
David Benjamina5022392017-07-10 17:40:39 -04005708 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005709 expectedNextProto: "foo",
5710 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005711 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005712 })
5713
David Benjamin97d17d92016-07-14 16:12:00 -04005714 var emptyString string
5715 testCases = append(testCases, testCase{
5716 testType: clientTest,
5717 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5718 config: Config{
5719 MaxVersion: ver.version,
5720 NextProtos: []string{""},
5721 Bugs: ProtocolBugs{
5722 // A server returning an empty ALPN protocol
5723 // should be rejected.
5724 ALPNProtocol: &emptyString,
5725 },
5726 },
5727 flags: []string{
5728 "-advertise-alpn", "\x03foo",
5729 },
David Benjamina5022392017-07-10 17:40:39 -04005730 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005731 shouldFail: true,
5732 expectedError: ":PARSE_TLSEXT:",
5733 })
5734 testCases = append(testCases, testCase{
5735 testType: serverTest,
5736 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5737 config: Config{
5738 MaxVersion: ver.version,
5739 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005740 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005741 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005742 },
David Benjamin97d17d92016-07-14 16:12:00 -04005743 flags: []string{
5744 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005745 },
David Benjamina5022392017-07-10 17:40:39 -04005746 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005747 shouldFail: true,
5748 expectedError: ":PARSE_TLSEXT:",
5749 })
5750
5751 // Test NPN and the interaction with ALPN.
5752 if ver.version < VersionTLS13 {
5753 // Test that the server prefers ALPN over NPN.
5754 testCases = append(testCases, testCase{
5755 testType: serverTest,
5756 name: "ALPNServer-Preferred-" + ver.name,
5757 config: Config{
5758 MaxVersion: ver.version,
5759 NextProtos: []string{"foo", "bar", "baz"},
5760 },
5761 flags: []string{
5762 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5763 "-select-alpn", "foo",
5764 "-advertise-npn", "\x03foo\x03bar\x03baz",
5765 },
David Benjamina5022392017-07-10 17:40:39 -04005766 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005767 expectedNextProto: "foo",
5768 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005769 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005770 })
5771 testCases = append(testCases, testCase{
5772 testType: serverTest,
5773 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5774 config: Config{
5775 MaxVersion: ver.version,
5776 NextProtos: []string{"foo", "bar", "baz"},
5777 Bugs: ProtocolBugs{
5778 SwapNPNAndALPN: true,
5779 },
5780 },
5781 flags: []string{
5782 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5783 "-select-alpn", "foo",
5784 "-advertise-npn", "\x03foo\x03bar\x03baz",
5785 },
David Benjamina5022392017-07-10 17:40:39 -04005786 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005787 expectedNextProto: "foo",
5788 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005789 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005790 })
5791
5792 // Test that negotiating both NPN and ALPN is forbidden.
5793 testCases = append(testCases, testCase{
5794 name: "NegotiateALPNAndNPN-" + ver.name,
5795 config: Config{
5796 MaxVersion: ver.version,
5797 NextProtos: []string{"foo", "bar", "baz"},
5798 Bugs: ProtocolBugs{
5799 NegotiateALPNAndNPN: true,
5800 },
5801 },
5802 flags: []string{
5803 "-advertise-alpn", "\x03foo",
5804 "-select-next-proto", "foo",
5805 },
David Benjamina5022392017-07-10 17:40:39 -04005806 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005807 shouldFail: true,
5808 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5809 })
5810 testCases = append(testCases, testCase{
5811 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5812 config: Config{
5813 MaxVersion: ver.version,
5814 NextProtos: []string{"foo", "bar", "baz"},
5815 Bugs: ProtocolBugs{
5816 NegotiateALPNAndNPN: true,
5817 SwapNPNAndALPN: true,
5818 },
5819 },
5820 flags: []string{
5821 "-advertise-alpn", "\x03foo",
5822 "-select-next-proto", "foo",
5823 },
David Benjamina5022392017-07-10 17:40:39 -04005824 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005825 shouldFail: true,
5826 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5827 })
David Benjamin97d17d92016-07-14 16:12:00 -04005828 }
5829
5830 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005831
5832 // Resume with a corrupt ticket.
5833 testCases = append(testCases, testCase{
5834 testType: serverTest,
5835 name: "CorruptTicket-" + ver.name,
5836 config: Config{
5837 MaxVersion: ver.version,
5838 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005839 FilterTicket: func(in []byte) ([]byte, error) {
5840 in[len(in)-1] ^= 1
5841 return in, nil
5842 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005843 },
5844 },
David Benjamina5022392017-07-10 17:40:39 -04005845 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005846 resumeSession: true,
5847 expectResumeRejected: true,
5848 })
5849 // Test the ticket callback, with and without renewal.
5850 testCases = append(testCases, testCase{
5851 testType: serverTest,
5852 name: "TicketCallback-" + ver.name,
5853 config: Config{
5854 MaxVersion: ver.version,
5855 },
David Benjamina5022392017-07-10 17:40:39 -04005856 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005857 resumeSession: true,
5858 flags: []string{"-use-ticket-callback"},
5859 })
5860 testCases = append(testCases, testCase{
5861 testType: serverTest,
5862 name: "TicketCallback-Renew-" + ver.name,
5863 config: Config{
5864 MaxVersion: ver.version,
5865 Bugs: ProtocolBugs{
5866 ExpectNewTicket: true,
5867 },
5868 },
David Benjamina5022392017-07-10 17:40:39 -04005869 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005870 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5871 resumeSession: true,
5872 })
5873
5874 // Test that the ticket callback is only called once when everything before
5875 // it in the ClientHello is asynchronous. This corrupts the ticket so
5876 // certificate selection callbacks run.
5877 testCases = append(testCases, testCase{
5878 testType: serverTest,
5879 name: "TicketCallback-SingleCall-" + ver.name,
5880 config: Config{
5881 MaxVersion: ver.version,
5882 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005883 FilterTicket: func(in []byte) ([]byte, error) {
5884 in[len(in)-1] ^= 1
5885 return in, nil
5886 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005887 },
5888 },
David Benjamina5022392017-07-10 17:40:39 -04005889 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005890 resumeSession: true,
5891 expectResumeRejected: true,
5892 flags: []string{
5893 "-use-ticket-callback",
5894 "-async",
5895 },
5896 })
5897
David Benjamind4c349b2017-02-09 14:07:17 -05005898 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005899 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005900 testCases = append(testCases, testCase{
5901 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005902 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005903 config: Config{
5904 MaxVersion: ver.version,
5905 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005906 EmptyTicketSessionID: true,
5907 },
5908 },
5909 resumeSession: true,
5910 })
5911 testCases = append(testCases, testCase{
5912 testType: serverTest,
5913 name: "TicketSessionIDLength-16-" + ver.name,
5914 config: Config{
5915 MaxVersion: ver.version,
5916 Bugs: ProtocolBugs{
5917 TicketSessionIDLength: 16,
5918 },
5919 },
5920 resumeSession: true,
5921 })
5922 testCases = append(testCases, testCase{
5923 testType: serverTest,
5924 name: "TicketSessionIDLength-32-" + ver.name,
5925 config: Config{
5926 MaxVersion: ver.version,
5927 Bugs: ProtocolBugs{
5928 TicketSessionIDLength: 32,
5929 },
5930 },
5931 resumeSession: true,
5932 })
5933 testCases = append(testCases, testCase{
5934 testType: serverTest,
5935 name: "TicketSessionIDLength-33-" + ver.name,
5936 config: Config{
5937 MaxVersion: ver.version,
5938 Bugs: ProtocolBugs{
5939 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005940 },
5941 },
5942 resumeSession: true,
5943 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005944 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005945 expectedError: ":DECODE_ERROR:",
5946 })
5947 }
5948
5949 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5950 // are ignored.
5951 if ver.hasDTLS {
5952 testCases = append(testCases, testCase{
5953 protocol: dtls,
5954 name: "SRTP-Client-" + ver.name,
5955 config: Config{
5956 MaxVersion: ver.version,
5957 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5958 },
5959 flags: []string{
5960 "-srtp-profiles",
5961 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5962 },
5963 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5964 })
5965 testCases = append(testCases, testCase{
5966 protocol: dtls,
5967 testType: serverTest,
5968 name: "SRTP-Server-" + ver.name,
5969 config: Config{
5970 MaxVersion: ver.version,
5971 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5972 },
5973 flags: []string{
5974 "-srtp-profiles",
5975 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5976 },
5977 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5978 })
5979 // Test that the MKI is ignored.
5980 testCases = append(testCases, testCase{
5981 protocol: dtls,
5982 testType: serverTest,
5983 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5984 config: Config{
5985 MaxVersion: ver.version,
5986 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5987 Bugs: ProtocolBugs{
5988 SRTPMasterKeyIdentifer: "bogus",
5989 },
5990 },
5991 flags: []string{
5992 "-srtp-profiles",
5993 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5994 },
5995 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5996 })
5997 // Test that SRTP isn't negotiated on the server if there were
5998 // no matching profiles.
5999 testCases = append(testCases, testCase{
6000 protocol: dtls,
6001 testType: serverTest,
6002 name: "SRTP-Server-NoMatch-" + ver.name,
6003 config: Config{
6004 MaxVersion: ver.version,
6005 SRTPProtectionProfiles: []uint16{100, 101, 102},
6006 },
6007 flags: []string{
6008 "-srtp-profiles",
6009 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6010 },
6011 expectedSRTPProtectionProfile: 0,
6012 })
6013 // Test that the server returning an invalid SRTP profile is
6014 // flagged as an error by the client.
6015 testCases = append(testCases, testCase{
6016 protocol: dtls,
6017 name: "SRTP-Client-NoMatch-" + ver.name,
6018 config: Config{
6019 MaxVersion: ver.version,
6020 Bugs: ProtocolBugs{
6021 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6022 },
6023 },
6024 flags: []string{
6025 "-srtp-profiles",
6026 "SRTP_AES128_CM_SHA1_80",
6027 },
6028 shouldFail: true,
6029 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6030 })
6031 }
6032
6033 // Test SCT list.
6034 testCases = append(testCases, testCase{
6035 name: "SignedCertificateTimestampList-Client-" + ver.name,
6036 testType: clientTest,
6037 config: Config{
6038 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006039 },
David Benjamin97d17d92016-07-14 16:12:00 -04006040 flags: []string{
6041 "-enable-signed-cert-timestamps",
6042 "-expect-signed-cert-timestamps",
6043 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006044 },
David Benjamina5022392017-07-10 17:40:39 -04006045 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006046 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006047 })
David Benjamindaa88502016-10-04 16:32:16 -04006048
Adam Langleycfa08c32016-11-17 13:21:27 -08006049 var differentSCTList []byte
6050 differentSCTList = append(differentSCTList, testSCTList...)
6051 differentSCTList[len(differentSCTList)-1] ^= 1
6052
David Benjamindaa88502016-10-04 16:32:16 -04006053 // The SCT extension did not specify that it must only be sent on resumption as it
6054 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006055 testCases = append(testCases, testCase{
6056 name: "SendSCTListOnResume-" + ver.name,
6057 config: Config{
6058 MaxVersion: ver.version,
6059 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006060 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006061 },
David Benjamind98452d2015-06-16 14:16:23 -04006062 },
David Benjamin97d17d92016-07-14 16:12:00 -04006063 flags: []string{
6064 "-enable-signed-cert-timestamps",
6065 "-expect-signed-cert-timestamps",
6066 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006067 },
David Benjamina5022392017-07-10 17:40:39 -04006068 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006069 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006070 })
David Benjamindaa88502016-10-04 16:32:16 -04006071
David Benjamin97d17d92016-07-14 16:12:00 -04006072 testCases = append(testCases, testCase{
6073 name: "SignedCertificateTimestampList-Server-" + ver.name,
6074 testType: serverTest,
6075 config: Config{
6076 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006077 },
David Benjamin97d17d92016-07-14 16:12:00 -04006078 flags: []string{
6079 "-signed-cert-timestamps",
6080 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006081 },
David Benjamina5022392017-07-10 17:40:39 -04006082 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006083 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006084 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006085 })
David Benjamin53210cb2016-11-16 09:01:48 +09006086
Adam Langleycfa08c32016-11-17 13:21:27 -08006087 emptySCTListCert := *testCerts[0].cert
6088 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6089
6090 // Test empty SCT list.
6091 testCases = append(testCases, testCase{
6092 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6093 testType: clientTest,
6094 config: Config{
6095 MaxVersion: ver.version,
6096 Certificates: []Certificate{emptySCTListCert},
6097 },
6098 flags: []string{
6099 "-enable-signed-cert-timestamps",
6100 },
David Benjamina5022392017-07-10 17:40:39 -04006101 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006102 shouldFail: true,
6103 expectedError: ":ERROR_PARSING_EXTENSION:",
6104 })
6105
6106 emptySCTCert := *testCerts[0].cert
6107 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6108
6109 // Test empty SCT in non-empty list.
6110 testCases = append(testCases, testCase{
6111 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6112 testType: clientTest,
6113 config: Config{
6114 MaxVersion: ver.version,
6115 Certificates: []Certificate{emptySCTCert},
6116 },
6117 flags: []string{
6118 "-enable-signed-cert-timestamps",
6119 },
David Benjamina5022392017-07-10 17:40:39 -04006120 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006121 shouldFail: true,
6122 expectedError: ":ERROR_PARSING_EXTENSION:",
6123 })
6124
David Benjamin53210cb2016-11-16 09:01:48 +09006125 // Test that certificate-related extensions are not sent unsolicited.
6126 testCases = append(testCases, testCase{
6127 testType: serverTest,
6128 name: "UnsolicitedCertificateExtensions-" + ver.name,
6129 config: Config{
6130 MaxVersion: ver.version,
6131 Bugs: ProtocolBugs{
6132 NoOCSPStapling: true,
6133 NoSignedCertificateTimestamps: true,
6134 },
6135 },
David Benjamina5022392017-07-10 17:40:39 -04006136 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006137 flags: []string{
6138 "-ocsp-response",
6139 base64.StdEncoding.EncodeToString(testOCSPResponse),
6140 "-signed-cert-timestamps",
6141 base64.StdEncoding.EncodeToString(testSCTList),
6142 },
6143 })
David Benjamin97d17d92016-07-14 16:12:00 -04006144 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006145
Paul Lietar4fac72e2015-09-09 13:44:55 +01006146 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006147 testType: clientTest,
6148 name: "ClientHelloPadding",
6149 config: Config{
6150 Bugs: ProtocolBugs{
6151 RequireClientHelloSize: 512,
6152 },
6153 },
6154 // This hostname just needs to be long enough to push the
6155 // ClientHello into F5's danger zone between 256 and 511 bytes
6156 // long.
6157 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6158 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006159
6160 // Extensions should not function in SSL 3.0.
6161 testCases = append(testCases, testCase{
6162 testType: serverTest,
6163 name: "SSLv3Extensions-NoALPN",
6164 config: Config{
6165 MaxVersion: VersionSSL30,
6166 NextProtos: []string{"foo", "bar", "baz"},
6167 },
6168 flags: []string{
6169 "-select-alpn", "foo",
6170 },
6171 expectNoNextProto: true,
6172 })
6173
6174 // Test session tickets separately as they follow a different codepath.
6175 testCases = append(testCases, testCase{
6176 testType: serverTest,
6177 name: "SSLv3Extensions-NoTickets",
6178 config: Config{
6179 MaxVersion: VersionSSL30,
6180 Bugs: ProtocolBugs{
6181 // Historically, session tickets in SSL 3.0
6182 // failed in different ways depending on whether
6183 // the client supported renegotiation_info.
6184 NoRenegotiationInfo: true,
6185 },
6186 },
6187 resumeSession: true,
6188 })
6189 testCases = append(testCases, testCase{
6190 testType: serverTest,
6191 name: "SSLv3Extensions-NoTickets2",
6192 config: Config{
6193 MaxVersion: VersionSSL30,
6194 },
6195 resumeSession: true,
6196 })
6197
6198 // But SSL 3.0 does send and process renegotiation_info.
6199 testCases = append(testCases, testCase{
6200 testType: serverTest,
6201 name: "SSLv3Extensions-RenegotiationInfo",
6202 config: Config{
6203 MaxVersion: VersionSSL30,
6204 Bugs: ProtocolBugs{
6205 RequireRenegotiationInfo: true,
6206 },
6207 },
David Benjamind2610042017-01-03 10:49:28 -05006208 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006209 })
6210 testCases = append(testCases, testCase{
6211 testType: serverTest,
6212 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6213 config: Config{
6214 MaxVersion: VersionSSL30,
6215 Bugs: ProtocolBugs{
6216 NoRenegotiationInfo: true,
6217 SendRenegotiationSCSV: true,
6218 RequireRenegotiationInfo: true,
6219 },
6220 },
David Benjamind2610042017-01-03 10:49:28 -05006221 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006222 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006223
6224 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6225 // in ServerHello.
6226 testCases = append(testCases, testCase{
6227 name: "NPN-Forbidden-TLS13",
6228 config: Config{
6229 MaxVersion: VersionTLS13,
6230 NextProtos: []string{"foo"},
6231 Bugs: ProtocolBugs{
6232 NegotiateNPNAtAllVersions: true,
6233 },
6234 },
6235 flags: []string{"-select-next-proto", "foo"},
6236 shouldFail: true,
6237 expectedError: ":ERROR_PARSING_EXTENSION:",
6238 })
6239 testCases = append(testCases, testCase{
6240 name: "EMS-Forbidden-TLS13",
6241 config: Config{
6242 MaxVersion: VersionTLS13,
6243 Bugs: ProtocolBugs{
6244 NegotiateEMSAtAllVersions: true,
6245 },
6246 },
6247 shouldFail: true,
6248 expectedError: ":ERROR_PARSING_EXTENSION:",
6249 })
6250 testCases = append(testCases, testCase{
6251 name: "RenegotiationInfo-Forbidden-TLS13",
6252 config: Config{
6253 MaxVersion: VersionTLS13,
6254 Bugs: ProtocolBugs{
6255 NegotiateRenegotiationInfoAtAllVersions: true,
6256 },
6257 },
6258 shouldFail: true,
6259 expectedError: ":ERROR_PARSING_EXTENSION:",
6260 })
6261 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006262 name: "Ticket-Forbidden-TLS13",
6263 config: Config{
6264 MaxVersion: VersionTLS12,
6265 },
6266 resumeConfig: &Config{
6267 MaxVersion: VersionTLS13,
6268 Bugs: ProtocolBugs{
6269 AdvertiseTicketExtension: true,
6270 },
6271 },
6272 resumeSession: true,
6273 shouldFail: true,
6274 expectedError: ":ERROR_PARSING_EXTENSION:",
6275 })
6276
6277 // Test that illegal extensions in TLS 1.3 are declined by the server if
6278 // offered in ClientHello. The runner's server will fail if this occurs,
6279 // so we exercise the offering path. (EMS and Renegotiation Info are
6280 // implicit in every test.)
6281 testCases = append(testCases, testCase{
6282 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006283 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006284 config: Config{
6285 MaxVersion: VersionTLS13,
6286 NextProtos: []string{"bar"},
6287 },
6288 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6289 })
David Benjamin196df5b2016-09-21 16:23:27 -04006290
David Benjamindaa88502016-10-04 16:32:16 -04006291 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6292 // tolerated.
6293 testCases = append(testCases, testCase{
6294 name: "SendOCSPResponseOnResume-TLS12",
6295 config: Config{
6296 MaxVersion: VersionTLS12,
6297 Bugs: ProtocolBugs{
6298 SendOCSPResponseOnResume: []byte("bogus"),
6299 },
6300 },
6301 flags: []string{
6302 "-enable-ocsp-stapling",
6303 "-expect-ocsp-response",
6304 base64.StdEncoding.EncodeToString(testOCSPResponse),
6305 },
6306 resumeSession: true,
6307 })
6308
David Benjamindaa88502016-10-04 16:32:16 -04006309 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006310 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006311 config: Config{
6312 MaxVersion: VersionTLS13,
6313 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006314 SendExtensionOnCertificate: testOCSPExtension,
6315 },
6316 },
6317 shouldFail: true,
6318 expectedError: ":UNEXPECTED_EXTENSION:",
6319 })
6320
6321 testCases = append(testCases, testCase{
6322 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6323 config: Config{
6324 MaxVersion: VersionTLS13,
6325 Bugs: ProtocolBugs{
6326 SendExtensionOnCertificate: testSCTExtension,
6327 },
6328 },
6329 shouldFail: true,
6330 expectedError: ":UNEXPECTED_EXTENSION:",
6331 })
6332
6333 // Test that extensions on client certificates are never accepted.
6334 testCases = append(testCases, testCase{
6335 name: "SendExtensionOnClientCertificate-TLS13",
6336 testType: serverTest,
6337 config: Config{
6338 MaxVersion: VersionTLS13,
6339 Certificates: []Certificate{rsaCertificate},
6340 Bugs: ProtocolBugs{
6341 SendExtensionOnCertificate: testOCSPExtension,
6342 },
6343 },
6344 flags: []string{
6345 "-enable-ocsp-stapling",
6346 "-require-any-client-certificate",
6347 },
6348 shouldFail: true,
6349 expectedError: ":UNEXPECTED_EXTENSION:",
6350 })
6351
6352 testCases = append(testCases, testCase{
6353 name: "SendUnknownExtensionOnCertificate-TLS13",
6354 config: Config{
6355 MaxVersion: VersionTLS13,
6356 Bugs: ProtocolBugs{
6357 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6358 },
6359 },
6360 shouldFail: true,
6361 expectedError: ":UNEXPECTED_EXTENSION:",
6362 })
6363
6364 // Test that extensions on intermediates are allowed but ignored.
6365 testCases = append(testCases, testCase{
6366 name: "IgnoreExtensionsOnIntermediates-TLS13",
6367 config: Config{
6368 MaxVersion: VersionTLS13,
6369 Certificates: []Certificate{rsaChainCertificate},
6370 Bugs: ProtocolBugs{
6371 // Send different values on the intermediate. This tests
6372 // the intermediate's extensions do not override the
6373 // leaf's.
David Benjamin5c4271f2017-08-23 22:09:41 -07006374 SendOCSPOnIntermediates: testOCSPResponse2,
6375 SendSCTOnIntermediates: testSCTList2,
David Benjamindaa88502016-10-04 16:32:16 -04006376 },
6377 },
6378 flags: []string{
6379 "-enable-ocsp-stapling",
6380 "-expect-ocsp-response",
6381 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006382 "-enable-signed-cert-timestamps",
6383 "-expect-signed-cert-timestamps",
6384 base64.StdEncoding.EncodeToString(testSCTList),
6385 },
6386 resumeSession: true,
6387 })
6388
6389 // Test that extensions are not sent on intermediates when configured
6390 // only for a leaf.
6391 testCases = append(testCases, testCase{
6392 testType: serverTest,
6393 name: "SendNoExtensionsOnIntermediate-TLS13",
6394 config: Config{
6395 MaxVersion: VersionTLS13,
6396 Bugs: ProtocolBugs{
6397 ExpectNoExtensionsOnIntermediate: true,
6398 },
6399 },
6400 flags: []string{
6401 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6402 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6403 "-ocsp-response",
6404 base64.StdEncoding.EncodeToString(testOCSPResponse),
6405 "-signed-cert-timestamps",
6406 base64.StdEncoding.EncodeToString(testSCTList),
6407 },
6408 })
6409
6410 // Test that extensions are not sent on client certificates.
6411 testCases = append(testCases, testCase{
6412 name: "SendNoClientCertificateExtensions-TLS13",
6413 config: Config{
6414 MaxVersion: VersionTLS13,
6415 ClientAuth: RequireAnyClientCert,
6416 },
6417 flags: []string{
6418 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6419 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6420 "-ocsp-response",
6421 base64.StdEncoding.EncodeToString(testOCSPResponse),
6422 "-signed-cert-timestamps",
6423 base64.StdEncoding.EncodeToString(testSCTList),
6424 },
6425 })
6426
6427 testCases = append(testCases, testCase{
6428 name: "SendDuplicateExtensionsOnCerts-TLS13",
6429 config: Config{
6430 MaxVersion: VersionTLS13,
6431 Bugs: ProtocolBugs{
6432 SendDuplicateCertExtensions: true,
6433 },
6434 },
6435 flags: []string{
6436 "-enable-ocsp-stapling",
6437 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006438 },
6439 resumeSession: true,
6440 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006441 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006442 })
Adam Langley9b885c52016-11-18 14:21:03 -08006443
6444 testCases = append(testCases, testCase{
6445 name: "SignedCertificateTimestampListInvalid-Server",
6446 testType: serverTest,
6447 flags: []string{
6448 "-signed-cert-timestamps",
6449 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6450 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006451 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006452 expectedError: ":INVALID_SCT_LIST:",
6453 })
David Benjamine78bfde2014-09-06 12:45:15 -04006454}
6455
David Benjamin01fe8202014-09-24 15:21:44 -04006456func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006457 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006458 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006459 // SSL 3.0 does not have tickets and TLS 1.3 does not
6460 // have session IDs, so skip their cross-resumption
6461 // tests.
6462 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6463 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6464 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006465 }
6466
David Benjamin8b8c0062014-11-23 02:47:52 -05006467 protocols := []protocol{tls}
6468 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6469 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006470 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006471 for _, protocol := range protocols {
6472 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6473 if protocol == dtls {
6474 suffix += "-DTLS"
6475 }
6476
Steven Valdez520e1222017-06-13 12:45:25 -04006477 // We can't resume across TLS 1.3 variants and error out earlier in the
6478 // session resumption.
6479 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6480 continue
6481 }
6482
David Benjaminece3de92015-03-16 18:02:20 -04006483 if sessionVers.version == resumeVers.version {
6484 testCases = append(testCases, testCase{
6485 protocol: protocol,
6486 name: "Resume-Client" + suffix,
6487 resumeSession: true,
6488 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006489 MaxVersion: sessionVers.version,
6490 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006491 Bugs: ProtocolBugs{
6492 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6493 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6494 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006495 },
David Benjaminece3de92015-03-16 18:02:20 -04006496 expectedVersion: sessionVers.version,
6497 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006498 flags: []string{
6499 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6500 },
David Benjaminece3de92015-03-16 18:02:20 -04006501 })
6502 } else {
David Benjamin405da482016-08-08 17:25:07 -04006503 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6504
6505 // Offering a TLS 1.3 session sends an empty session ID, so
6506 // there is no way to convince a non-lookahead client the
6507 // session was resumed. It will appear to the client that a
6508 // stray ChangeCipherSpec was sent.
6509 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6510 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006511 }
6512
David Benjaminece3de92015-03-16 18:02:20 -04006513 testCases = append(testCases, testCase{
6514 protocol: protocol,
6515 name: "Resume-Client-Mismatch" + suffix,
6516 resumeSession: true,
6517 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006518 MaxVersion: sessionVers.version,
6519 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006520 },
David Benjaminece3de92015-03-16 18:02:20 -04006521 expectedVersion: sessionVers.version,
6522 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006523 MaxVersion: resumeVers.version,
6524 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006525 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006526 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006527 },
6528 },
6529 expectedResumeVersion: resumeVers.version,
6530 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006531 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006532 flags: []string{
6533 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6534 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6535 },
David Benjaminece3de92015-03-16 18:02:20 -04006536 })
6537 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006538
6539 testCases = append(testCases, testCase{
6540 protocol: protocol,
6541 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006542 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 },
6547 expectedVersion: sessionVers.version,
6548 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006549 MaxVersion: resumeVers.version,
6550 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006551 },
6552 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006553 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006554 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006555 flags: []string{
6556 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6557 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6558 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006559 })
6560
David Benjamin8b8c0062014-11-23 02:47:52 -05006561 testCases = append(testCases, testCase{
6562 protocol: protocol,
6563 testType: serverTest,
6564 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006565 resumeSession: true,
6566 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006567 MaxVersion: sessionVers.version,
6568 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006569 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006570 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006571 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006572 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006573 MaxVersion: resumeVers.version,
6574 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006575 Bugs: ProtocolBugs{
6576 SendBothTickets: true,
6577 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006578 },
6579 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006580 flags: []string{
6581 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6582 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6583 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006584 })
6585 }
David Benjamin01fe8202014-09-24 15:21:44 -04006586 }
6587 }
David Benjaminece3de92015-03-16 18:02:20 -04006588
David Benjamin4199b0d2016-11-01 13:58:25 -04006589 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006590 testCases = append(testCases, testCase{
6591 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006592 name: "ShimTicketRewritable",
6593 resumeSession: true,
6594 config: Config{
6595 MaxVersion: VersionTLS12,
6596 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6597 Bugs: ProtocolBugs{
6598 FilterTicket: func(in []byte) ([]byte, error) {
6599 in, err := SetShimTicketVersion(in, VersionTLS12)
6600 if err != nil {
6601 return nil, err
6602 }
6603 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6604 },
6605 },
6606 },
6607 flags: []string{
6608 "-ticket-key",
6609 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6610 },
6611 })
6612
6613 // Resumptions are declined if the version does not match.
6614 testCases = append(testCases, testCase{
6615 testType: serverTest,
6616 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006617 resumeSession: true,
6618 config: Config{
6619 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006620 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006621 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006622 FilterTicket: func(in []byte) ([]byte, error) {
6623 return SetShimTicketVersion(in, VersionTLS13)
6624 },
6625 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006626 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006627 flags: []string{
6628 "-ticket-key",
6629 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6630 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006631 expectResumeRejected: true,
6632 })
6633
6634 testCases = append(testCases, testCase{
6635 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006636 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006637 resumeSession: true,
6638 config: Config{
6639 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006640 Bugs: ProtocolBugs{
6641 FilterTicket: func(in []byte) ([]byte, error) {
6642 return SetShimTicketVersion(in, VersionTLS12)
6643 },
6644 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006645 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006646 flags: []string{
6647 "-ticket-key",
6648 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6649 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006650 expectResumeRejected: true,
6651 })
6652
David Benjamin4199b0d2016-11-01 13:58:25 -04006653 // Resumptions are declined if the cipher is invalid or disabled.
6654 testCases = append(testCases, testCase{
6655 testType: serverTest,
6656 name: "Resume-Server-DeclineBadCipher",
6657 resumeSession: true,
6658 config: Config{
6659 MaxVersion: VersionTLS12,
6660 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006661 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006662 FilterTicket: func(in []byte) ([]byte, error) {
6663 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6664 },
6665 },
6666 },
6667 flags: []string{
6668 "-ticket-key",
6669 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6670 },
6671 expectResumeRejected: true,
6672 })
6673
6674 testCases = append(testCases, testCase{
6675 testType: serverTest,
6676 name: "Resume-Server-DeclineBadCipher-2",
6677 resumeSession: true,
6678 config: Config{
6679 MaxVersion: VersionTLS12,
6680 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006681 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006682 FilterTicket: func(in []byte) ([]byte, error) {
6683 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6684 },
6685 },
6686 },
6687 flags: []string{
6688 "-cipher", "AES128",
6689 "-ticket-key",
6690 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6691 },
6692 expectResumeRejected: true,
6693 })
6694
David Benjaminf01f42a2016-11-16 19:05:33 +09006695 // Sessions are not resumed if they do not use the preferred cipher.
6696 testCases = append(testCases, testCase{
6697 testType: serverTest,
6698 name: "Resume-Server-CipherNotPreferred",
6699 resumeSession: true,
6700 config: Config{
6701 MaxVersion: VersionTLS12,
6702 Bugs: ProtocolBugs{
6703 ExpectNewTicket: true,
6704 FilterTicket: func(in []byte) ([]byte, error) {
6705 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6706 },
6707 },
6708 },
6709 flags: []string{
6710 "-ticket-key",
6711 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6712 },
6713 shouldFail: false,
6714 expectResumeRejected: true,
6715 })
6716
6717 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6718 // PRF hashes match, but BoringSSL will always decline such resumptions.
6719 testCases = append(testCases, testCase{
6720 testType: serverTest,
6721 name: "Resume-Server-CipherNotPreferred-TLS13",
6722 resumeSession: true,
6723 config: Config{
6724 MaxVersion: VersionTLS13,
6725 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6726 Bugs: ProtocolBugs{
6727 FilterTicket: func(in []byte) ([]byte, error) {
6728 // If the client (runner) offers ChaCha20-Poly1305 first, the
6729 // server (shim) always prefers it. Switch it to AES-GCM.
6730 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6731 },
6732 },
6733 },
6734 flags: []string{
6735 "-ticket-key",
6736 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6737 },
6738 shouldFail: false,
6739 expectResumeRejected: true,
6740 })
6741
6742 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006743 testCases = append(testCases, testCase{
6744 testType: serverTest,
6745 name: "Resume-Server-DeclineBadCipher-TLS13",
6746 resumeSession: true,
6747 config: Config{
6748 MaxVersion: VersionTLS13,
6749 Bugs: ProtocolBugs{
6750 FilterTicket: func(in []byte) ([]byte, error) {
6751 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6752 },
6753 },
6754 },
6755 flags: []string{
6756 "-ticket-key",
6757 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6758 },
6759 expectResumeRejected: true,
6760 })
6761
David Benjaminf01f42a2016-11-16 19:05:33 +09006762 // If the client does not offer the cipher from the session, decline to
6763 // resume. Clients are forbidden from doing this, but BoringSSL selects
6764 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006765 testCases = append(testCases, testCase{
6766 testType: serverTest,
6767 name: "Resume-Server-UnofferedCipher",
6768 resumeSession: true,
6769 config: Config{
6770 MaxVersion: VersionTLS12,
6771 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6772 },
6773 resumeConfig: &Config{
6774 MaxVersion: VersionTLS12,
6775 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6776 Bugs: ProtocolBugs{
6777 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6778 },
6779 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006780 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006781 })
6782
David Benjaminf01f42a2016-11-16 19:05:33 +09006783 // In TLS 1.3, clients may advertise a cipher list which does not
6784 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006785 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6786 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006787 testCases = append(testCases, testCase{
6788 testType: serverTest,
6789 name: "Resume-Server-UnofferedCipher-TLS13",
6790 resumeSession: true,
6791 config: Config{
6792 MaxVersion: VersionTLS13,
6793 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6794 },
6795 resumeConfig: &Config{
6796 MaxVersion: VersionTLS13,
6797 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6798 Bugs: ProtocolBugs{
6799 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6800 },
6801 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006802 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006803 })
6804
David Benjamin4199b0d2016-11-01 13:58:25 -04006805 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006806 testCases = append(testCases, testCase{
6807 name: "Resume-Client-CipherMismatch",
6808 resumeSession: true,
6809 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006810 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006811 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6812 },
6813 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006814 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006815 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6816 Bugs: ProtocolBugs{
6817 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6818 },
6819 },
6820 shouldFail: true,
6821 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6822 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006823
David Benjamine1cc35e2016-11-16 16:25:58 +09006824 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6825 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006826 testCases = append(testCases, testCase{
6827 name: "Resume-Client-CipherMismatch-TLS13",
6828 resumeSession: true,
6829 config: Config{
6830 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006831 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006832 },
6833 resumeConfig: &Config{
6834 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006835 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6836 },
6837 })
6838
6839 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6840 testCases = append(testCases, testCase{
6841 name: "Resume-Client-PRFMismatch-TLS13",
6842 resumeSession: true,
6843 config: Config{
6844 MaxVersion: VersionTLS13,
6845 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6846 },
6847 resumeConfig: &Config{
6848 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006849 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006850 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006851 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006852 },
6853 },
6854 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006855 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006856 })
Steven Valdeza833c352016-11-01 13:39:36 -04006857
6858 testCases = append(testCases, testCase{
6859 testType: serverTest,
6860 name: "Resume-Server-BinderWrongLength",
6861 resumeSession: true,
6862 config: Config{
6863 MaxVersion: VersionTLS13,
6864 Bugs: ProtocolBugs{
6865 SendShortPSKBinder: true,
6866 },
6867 },
6868 shouldFail: true,
6869 expectedLocalError: "remote error: error decrypting message",
6870 expectedError: ":DIGEST_CHECK_FAILED:",
6871 })
6872
6873 testCases = append(testCases, testCase{
6874 testType: serverTest,
6875 name: "Resume-Server-NoPSKBinder",
6876 resumeSession: true,
6877 config: Config{
6878 MaxVersion: VersionTLS13,
6879 Bugs: ProtocolBugs{
6880 SendNoPSKBinder: true,
6881 },
6882 },
6883 shouldFail: true,
6884 expectedLocalError: "remote error: error decoding message",
6885 expectedError: ":DECODE_ERROR:",
6886 })
6887
6888 testCases = append(testCases, testCase{
6889 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006890 name: "Resume-Server-ExtraPSKBinder",
6891 resumeSession: true,
6892 config: Config{
6893 MaxVersion: VersionTLS13,
6894 Bugs: ProtocolBugs{
6895 SendExtraPSKBinder: true,
6896 },
6897 },
6898 shouldFail: true,
6899 expectedLocalError: "remote error: illegal parameter",
6900 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6901 })
6902
6903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: "Resume-Server-ExtraIdentityNoBinder",
6906 resumeSession: true,
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 Bugs: ProtocolBugs{
6910 ExtraPSKIdentity: true,
6911 },
6912 },
6913 shouldFail: true,
6914 expectedLocalError: "remote error: illegal parameter",
6915 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6916 })
6917
6918 testCases = append(testCases, testCase{
6919 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006920 name: "Resume-Server-InvalidPSKBinder",
6921 resumeSession: true,
6922 config: Config{
6923 MaxVersion: VersionTLS13,
6924 Bugs: ProtocolBugs{
6925 SendInvalidPSKBinder: true,
6926 },
6927 },
6928 shouldFail: true,
6929 expectedLocalError: "remote error: error decrypting message",
6930 expectedError: ":DIGEST_CHECK_FAILED:",
6931 })
6932
6933 testCases = append(testCases, testCase{
6934 testType: serverTest,
6935 name: "Resume-Server-PSKBinderFirstExtension",
6936 resumeSession: true,
6937 config: Config{
6938 MaxVersion: VersionTLS13,
6939 Bugs: ProtocolBugs{
6940 PSKBinderFirst: true,
6941 },
6942 },
6943 shouldFail: true,
6944 expectedLocalError: "remote error: illegal parameter",
6945 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6946 })
David Benjamin01fe8202014-09-24 15:21:44 -04006947}
6948
Adam Langley2ae77d22014-10-28 17:29:33 -07006949func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006950 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006951 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006952 testType: serverTest,
6953 name: "Renegotiate-Server-Forbidden",
6954 config: Config{
6955 MaxVersion: VersionTLS12,
6956 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006957 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006958 shouldFail: true,
6959 expectedError: ":NO_RENEGOTIATION:",
6960 expectedLocalError: "remote error: no renegotiation",
6961 })
Adam Langley5021b222015-06-12 18:27:58 -07006962 // The server shouldn't echo the renegotiation extension unless
6963 // requested by the client.
6964 testCases = append(testCases, testCase{
6965 testType: serverTest,
6966 name: "Renegotiate-Server-NoExt",
6967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006968 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006969 Bugs: ProtocolBugs{
6970 NoRenegotiationInfo: true,
6971 RequireRenegotiationInfo: true,
6972 },
6973 },
6974 shouldFail: true,
6975 expectedLocalError: "renegotiation extension missing",
6976 })
6977 // The renegotiation SCSV should be sufficient for the server to echo
6978 // the extension.
6979 testCases = append(testCases, testCase{
6980 testType: serverTest,
6981 name: "Renegotiate-Server-NoExt-SCSV",
6982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006983 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006984 Bugs: ProtocolBugs{
6985 NoRenegotiationInfo: true,
6986 SendRenegotiationSCSV: true,
6987 RequireRenegotiationInfo: true,
6988 },
6989 },
6990 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006991 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006992 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006994 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006995 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006996 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006997 },
6998 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006999 renegotiate: 1,
David Benjamind0beda02017-09-06 16:46:50 -04007000 // Test renegotiation after both an initial and resumption
7001 // handshake.
7002 resumeSession: true,
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007003 flags: []string{
7004 "-renegotiate-freely",
7005 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007006 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007007 },
David Benjamincdea40c2015-03-19 14:09:43 -04007008 })
7009 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007010 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007011 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007013 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007014 Bugs: ProtocolBugs{
7015 EmptyRenegotiationInfo: true,
7016 },
7017 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007018 flags: []string{"-renegotiate-freely"},
7019 shouldFail: true,
7020 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007021 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007022 })
7023 testCases = append(testCases, testCase{
7024 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007025 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007027 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007028 Bugs: ProtocolBugs{
7029 BadRenegotiationInfo: true,
7030 },
7031 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007032 flags: []string{"-renegotiate-freely"},
7033 shouldFail: true,
7034 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007035 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007036 })
7037 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007038 name: "Renegotiate-Client-BadExt2",
7039 renegotiate: 1,
7040 config: Config{
7041 MaxVersion: VersionTLS12,
7042 Bugs: ProtocolBugs{
7043 BadRenegotiationInfoEnd: true,
7044 },
7045 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007046 flags: []string{"-renegotiate-freely"},
7047 shouldFail: true,
7048 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007049 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007050 })
7051 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007052 name: "Renegotiate-Client-Downgrade",
7053 renegotiate: 1,
7054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007055 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007056 Bugs: ProtocolBugs{
7057 NoRenegotiationInfoAfterInitial: true,
7058 },
7059 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007060 flags: []string{"-renegotiate-freely"},
7061 shouldFail: true,
7062 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007063 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007064 })
7065 testCases = append(testCases, testCase{
7066 name: "Renegotiate-Client-Upgrade",
7067 renegotiate: 1,
7068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007069 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007070 Bugs: ProtocolBugs{
7071 NoRenegotiationInfoInInitial: true,
7072 },
7073 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007074 flags: []string{"-renegotiate-freely"},
7075 shouldFail: true,
7076 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007077 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007078 })
7079 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007080 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007081 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007083 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007084 Bugs: ProtocolBugs{
7085 NoRenegotiationInfo: true,
7086 },
7087 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007088 flags: []string{
7089 "-renegotiate-freely",
7090 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007091 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007092 },
David Benjamincff0b902015-05-15 23:09:47 -04007093 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007094
7095 // Test that the server may switch ciphers on renegotiation without
7096 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007097 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007098 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007099 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007100 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007101 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007102 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007103 },
7104 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007105 flags: []string{
7106 "-renegotiate-freely",
7107 "-expect-total-renegotiations", "1",
7108 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007109 })
7110 testCases = append(testCases, testCase{
7111 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007112 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007113 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007114 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007115 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7116 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007117 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007118 flags: []string{
7119 "-renegotiate-freely",
7120 "-expect-total-renegotiations", "1",
7121 },
David Benjaminb16346b2015-04-08 19:16:58 -04007122 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007123
7124 // Test that the server may not switch versions on renegotiation.
7125 testCases = append(testCases, testCase{
7126 name: "Renegotiate-Client-SwitchVersion",
7127 config: Config{
7128 MaxVersion: VersionTLS12,
7129 // Pick a cipher which exists at both versions.
7130 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7131 Bugs: ProtocolBugs{
7132 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007133 // Avoid failing early at the record layer.
7134 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007135 },
7136 },
7137 renegotiate: 1,
7138 flags: []string{
7139 "-renegotiate-freely",
7140 "-expect-total-renegotiations", "1",
7141 },
7142 shouldFail: true,
7143 expectedError: ":WRONG_SSL_VERSION:",
7144 })
7145
David Benjaminb16346b2015-04-08 19:16:58 -04007146 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007147 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007148 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007149 config: Config{
7150 MaxVersion: VersionTLS10,
7151 Bugs: ProtocolBugs{
7152 RequireSameRenegoClientVersion: true,
7153 },
7154 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007155 flags: []string{
7156 "-renegotiate-freely",
7157 "-expect-total-renegotiations", "1",
7158 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007159 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007160 testCases = append(testCases, testCase{
7161 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007162 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007163 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007164 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007165 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7166 NextProtos: []string{"foo"},
7167 },
7168 flags: []string{
7169 "-false-start",
7170 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007171 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007172 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007173 },
7174 shimWritesFirst: true,
7175 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007176
7177 // Client-side renegotiation controls.
7178 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007179 name: "Renegotiate-Client-Forbidden-1",
7180 config: Config{
7181 MaxVersion: VersionTLS12,
7182 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007183 renegotiate: 1,
7184 shouldFail: true,
7185 expectedError: ":NO_RENEGOTIATION:",
7186 expectedLocalError: "remote error: no renegotiation",
7187 })
7188 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007189 name: "Renegotiate-Client-Once-1",
7190 config: Config{
7191 MaxVersion: VersionTLS12,
7192 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007193 renegotiate: 1,
7194 flags: []string{
7195 "-renegotiate-once",
7196 "-expect-total-renegotiations", "1",
7197 },
7198 })
7199 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007200 name: "Renegotiate-Client-Freely-1",
7201 config: Config{
7202 MaxVersion: VersionTLS12,
7203 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007204 renegotiate: 1,
7205 flags: []string{
7206 "-renegotiate-freely",
7207 "-expect-total-renegotiations", "1",
7208 },
7209 })
7210 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007211 name: "Renegotiate-Client-Once-2",
7212 config: Config{
7213 MaxVersion: VersionTLS12,
7214 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007215 renegotiate: 2,
7216 flags: []string{"-renegotiate-once"},
7217 shouldFail: true,
7218 expectedError: ":NO_RENEGOTIATION:",
7219 expectedLocalError: "remote error: no renegotiation",
7220 })
7221 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007222 name: "Renegotiate-Client-Freely-2",
7223 config: Config{
7224 MaxVersion: VersionTLS12,
7225 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007226 renegotiate: 2,
7227 flags: []string{
7228 "-renegotiate-freely",
7229 "-expect-total-renegotiations", "2",
7230 },
7231 })
Adam Langley27a0d082015-11-03 13:34:10 -08007232 testCases = append(testCases, testCase{
7233 name: "Renegotiate-Client-NoIgnore",
7234 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007235 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007236 Bugs: ProtocolBugs{
7237 SendHelloRequestBeforeEveryAppDataRecord: true,
7238 },
7239 },
7240 shouldFail: true,
7241 expectedError: ":NO_RENEGOTIATION:",
7242 })
7243 testCases = append(testCases, testCase{
7244 name: "Renegotiate-Client-Ignore",
7245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007246 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007247 Bugs: ProtocolBugs{
7248 SendHelloRequestBeforeEveryAppDataRecord: true,
7249 },
7250 },
7251 flags: []string{
7252 "-renegotiate-ignore",
7253 "-expect-total-renegotiations", "0",
7254 },
7255 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007256
David Benjamin34941c02016-10-08 11:45:31 -04007257 // Renegotiation is not allowed at SSL 3.0.
7258 testCases = append(testCases, testCase{
7259 name: "Renegotiate-Client-SSL3",
7260 config: Config{
7261 MaxVersion: VersionSSL30,
7262 },
7263 renegotiate: 1,
7264 flags: []string{
7265 "-renegotiate-freely",
7266 "-expect-total-renegotiations", "1",
7267 },
7268 shouldFail: true,
7269 expectedError: ":NO_RENEGOTIATION:",
7270 expectedLocalError: "remote error: no renegotiation",
7271 })
7272
David Benjamina1eaba12017-01-01 23:19:22 -05007273 // Renegotiation is not allowed when there is an unfinished write.
7274 testCases = append(testCases, testCase{
7275 name: "Renegotiate-Client-UnfinishedWrite",
7276 config: Config{
7277 MaxVersion: VersionTLS12,
7278 },
David Benjaminbbba9392017-04-06 12:54:12 -04007279 renegotiate: 1,
7280 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007281 flags: []string{
7282 "-async",
7283 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007284 },
7285 shouldFail: true,
7286 expectedError: ":NO_RENEGOTIATION:",
7287 // We do not successfully send the no_renegotiation alert in
7288 // this case. https://crbug.com/boringssl/130
7289 })
7290
David Benjamin07ab5d42017-02-09 20:11:41 -05007291 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007292 testCases = append(testCases, testCase{
7293 name: "StrayHelloRequest",
7294 config: Config{
7295 MaxVersion: VersionTLS12,
7296 Bugs: ProtocolBugs{
7297 SendHelloRequestBeforeEveryHandshakeMessage: true,
7298 },
7299 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007300 shouldFail: true,
7301 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007302 })
7303 testCases = append(testCases, testCase{
7304 name: "StrayHelloRequest-Packed",
7305 config: Config{
7306 MaxVersion: VersionTLS12,
7307 Bugs: ProtocolBugs{
7308 PackHandshakeFlight: true,
7309 SendHelloRequestBeforeEveryHandshakeMessage: true,
7310 },
7311 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007312 shouldFail: true,
7313 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007314 })
7315
David Benjamin12d2c482016-07-24 10:56:51 -04007316 // Test renegotiation works if HelloRequest and server Finished come in
7317 // the same record.
7318 testCases = append(testCases, testCase{
7319 name: "Renegotiate-Client-Packed",
7320 config: Config{
7321 MaxVersion: VersionTLS12,
7322 Bugs: ProtocolBugs{
7323 PackHandshakeFlight: true,
7324 PackHelloRequestWithFinished: true,
7325 },
7326 },
7327 renegotiate: 1,
7328 flags: []string{
7329 "-renegotiate-freely",
7330 "-expect-total-renegotiations", "1",
7331 },
7332 })
7333
David Benjamin397c8e62016-07-08 14:14:36 -07007334 // Renegotiation is forbidden in TLS 1.3.
7335 testCases = append(testCases, testCase{
7336 name: "Renegotiate-Client-TLS13",
7337 config: Config{
7338 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007339 Bugs: ProtocolBugs{
7340 SendHelloRequestBeforeEveryAppDataRecord: true,
7341 },
David Benjamin397c8e62016-07-08 14:14:36 -07007342 },
David Benjamin397c8e62016-07-08 14:14:36 -07007343 flags: []string{
7344 "-renegotiate-freely",
7345 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007346 shouldFail: true,
7347 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007348 })
7349
7350 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7351 testCases = append(testCases, testCase{
7352 name: "StrayHelloRequest-TLS13",
7353 config: Config{
7354 MaxVersion: VersionTLS13,
7355 Bugs: ProtocolBugs{
7356 SendHelloRequestBeforeEveryHandshakeMessage: true,
7357 },
7358 },
7359 shouldFail: true,
7360 expectedError: ":UNEXPECTED_MESSAGE:",
7361 })
David Benjamind2610042017-01-03 10:49:28 -05007362
7363 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7364 // always reads as supporting it, regardless of whether it was
7365 // negotiated.
7366 testCases = append(testCases, testCase{
7367 name: "AlwaysReportRenegotiationInfo-TLS13",
7368 config: Config{
7369 MaxVersion: VersionTLS13,
7370 Bugs: ProtocolBugs{
7371 NoRenegotiationInfo: true,
7372 },
7373 },
7374 flags: []string{
7375 "-expect-secure-renegotiation",
7376 },
7377 })
David Benjamina58baaf2017-02-28 20:54:28 -05007378
7379 // Certificates may not change on renegotiation.
7380 testCases = append(testCases, testCase{
7381 name: "Renegotiation-CertificateChange",
7382 config: Config{
7383 MaxVersion: VersionTLS12,
7384 Certificates: []Certificate{rsaCertificate},
7385 Bugs: ProtocolBugs{
7386 RenegotiationCertificate: &rsaChainCertificate,
7387 },
7388 },
7389 renegotiate: 1,
7390 flags: []string{"-renegotiate-freely"},
7391 shouldFail: true,
7392 expectedError: ":SERVER_CERT_CHANGED:",
7393 })
7394 testCases = append(testCases, testCase{
7395 name: "Renegotiation-CertificateChange-2",
7396 config: Config{
7397 MaxVersion: VersionTLS12,
7398 Certificates: []Certificate{rsaCertificate},
7399 Bugs: ProtocolBugs{
7400 RenegotiationCertificate: &rsa1024Certificate,
7401 },
7402 },
7403 renegotiate: 1,
7404 flags: []string{"-renegotiate-freely"},
7405 shouldFail: true,
7406 expectedError: ":SERVER_CERT_CHANGED:",
7407 })
David Benjaminbbf42462017-03-14 21:27:10 -04007408
7409 // We do not negotiate ALPN after the initial handshake. This is
7410 // error-prone and only risks bugs in consumers.
7411 testCases = append(testCases, testCase{
7412 testType: clientTest,
7413 name: "Renegotiation-ForbidALPN",
7414 config: Config{
7415 MaxVersion: VersionTLS12,
7416 Bugs: ProtocolBugs{
7417 // Forcibly negotiate ALPN on both initial and
7418 // renegotiation handshakes. The test stack will
7419 // internally check the client does not offer
7420 // it.
7421 SendALPN: "foo",
7422 },
7423 },
7424 flags: []string{
7425 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7426 "-expect-alpn", "foo",
7427 "-renegotiate-freely",
7428 },
7429 renegotiate: 1,
7430 shouldFail: true,
7431 expectedError: ":UNEXPECTED_EXTENSION:",
7432 })
David Benjamin5c4271f2017-08-23 22:09:41 -07007433
7434 // The server may send different stapled OCSP responses or SCT lists on
7435 // renegotiation, but BoringSSL ignores this and reports the old values.
7436 // Also test that non-fatal verify results are preserved.
7437 testCases = append(testCases, testCase{
7438 testType: clientTest,
7439 name: "Renegotiation-ChangeAuthProperties",
7440 config: Config{
7441 MaxVersion: VersionTLS12,
7442 Bugs: ProtocolBugs{
7443 SendOCSPResponseOnRenegotiation: testOCSPResponse2,
7444 SendSCTListOnRenegotiation: testSCTList2,
7445 },
7446 },
7447 renegotiate: 1,
7448 flags: []string{
7449 "-renegotiate-freely",
7450 "-expect-total-renegotiations", "1",
7451 "-enable-ocsp-stapling",
7452 "-expect-ocsp-response",
7453 base64.StdEncoding.EncodeToString(testOCSPResponse),
7454 "-enable-signed-cert-timestamps",
7455 "-expect-signed-cert-timestamps",
7456 base64.StdEncoding.EncodeToString(testSCTList),
7457 "-verify-fail",
7458 "-expect-verify-result",
7459 },
7460 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007461}
7462
David Benjamin5e961c12014-11-07 01:48:35 -05007463func addDTLSReplayTests() {
7464 // Test that sequence number replays are detected.
7465 testCases = append(testCases, testCase{
7466 protocol: dtls,
7467 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007468 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007469 replayWrites: true,
7470 })
7471
David Benjamin8e6db492015-07-25 18:29:23 -04007472 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007473 // than the retransmit window.
7474 testCases = append(testCases, testCase{
7475 protocol: dtls,
7476 name: "DTLS-Replay-LargeGaps",
7477 config: Config{
7478 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007479 SequenceNumberMapping: func(in uint64) uint64 {
7480 return in * 127
7481 },
David Benjamin5e961c12014-11-07 01:48:35 -05007482 },
7483 },
David Benjamin8e6db492015-07-25 18:29:23 -04007484 messageCount: 200,
7485 replayWrites: true,
7486 })
7487
7488 // Test the incoming sequence number changing non-monotonically.
7489 testCases = append(testCases, testCase{
7490 protocol: dtls,
7491 name: "DTLS-Replay-NonMonotonic",
7492 config: Config{
7493 Bugs: ProtocolBugs{
7494 SequenceNumberMapping: func(in uint64) uint64 {
7495 return in ^ 31
7496 },
7497 },
7498 },
7499 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007500 replayWrites: true,
7501 })
7502}
7503
Nick Harper60edffd2016-06-21 15:19:24 -07007504var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007505 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007506 id signatureAlgorithm
7507 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007508}{
Nick Harper60edffd2016-06-21 15:19:24 -07007509 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7510 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7511 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7512 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007513 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007514 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7515 // hash function doesn't have to match the curve and so the same
7516 // signature algorithm works with P-224.
7517 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007518 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7519 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7520 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007521 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7522 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7523 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007524 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007525 // Tests for key types prior to TLS 1.2.
7526 {"RSA", 0, testCertRSA},
7527 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007528}
7529
Nick Harper60edffd2016-06-21 15:19:24 -07007530const fakeSigAlg1 signatureAlgorithm = 0x2a01
7531const fakeSigAlg2 signatureAlgorithm = 0xff01
7532
7533func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007534 // Not all ciphers involve a signature. Advertise a list which gives all
7535 // versions a signing cipher.
7536 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007537 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007538 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7539 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7540 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7541 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007542 }
David Benjamin5208fd42016-07-13 21:43:25 -04007543
David Benjaminca3d5452016-07-14 12:51:01 -04007544 var allAlgorithms []signatureAlgorithm
7545 for _, alg := range testSignatureAlgorithms {
7546 if alg.id != 0 {
7547 allAlgorithms = append(allAlgorithms, alg.id)
7548 }
7549 }
7550
Nick Harper60edffd2016-06-21 15:19:24 -07007551 // Make sure each signature algorithm works. Include some fake values in
7552 // the list and ensure they're ignored.
7553 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007554 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007555 if (ver.version < VersionTLS12) != (alg.id == 0) {
7556 continue
7557 }
7558
7559 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7560 // or remove it in C.
7561 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007562 continue
7563 }
Nick Harper60edffd2016-06-21 15:19:24 -07007564
David Benjamin3ef76972016-10-17 17:59:54 -04007565 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007566 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007567 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007568 shouldSignFail = true
7569 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007570 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007571 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007572 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7573 shouldSignFail = true
7574 shouldVerifyFail = true
7575 }
7576 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7577 // the curve has to match the hash size.
7578 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007579 shouldSignFail = true
7580 shouldVerifyFail = true
7581 }
7582
7583 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7584 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7585 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007586 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007587
7588 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007589 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007590 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007591 }
7592 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007593 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007594 }
David Benjamin000800a2014-11-14 01:43:59 -05007595
David Benjamin1fb125c2016-07-08 18:52:12 -07007596 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007597
David Benjamin7a41d372016-07-09 11:21:54 -07007598 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007599 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007600 config: Config{
7601 MaxVersion: ver.version,
7602 ClientAuth: RequireAnyClientCert,
7603 VerifySignatureAlgorithms: []signatureAlgorithm{
7604 fakeSigAlg1,
7605 alg.id,
7606 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007607 },
David Benjamin7a41d372016-07-09 11:21:54 -07007608 },
7609 flags: []string{
7610 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7611 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7612 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007613 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007614 },
David Benjamina5022392017-07-10 17:40:39 -04007615 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007616 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007617 expectedError: signError,
7618 expectedPeerSignatureAlgorithm: alg.id,
7619 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007620
David Benjamin7a41d372016-07-09 11:21:54 -07007621 testCases = append(testCases, testCase{
7622 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007623 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007624 config: Config{
7625 MaxVersion: ver.version,
7626 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7627 SignSignatureAlgorithms: []signatureAlgorithm{
7628 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007629 },
David Benjamin7a41d372016-07-09 11:21:54 -07007630 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007631 SkipECDSACurveCheck: shouldVerifyFail,
7632 IgnoreSignatureVersionChecks: shouldVerifyFail,
7633 // Some signature algorithms may not be advertised.
7634 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007635 },
David Benjamin7a41d372016-07-09 11:21:54 -07007636 },
David Benjamina5022392017-07-10 17:40:39 -04007637 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007638 flags: []string{
7639 "-require-any-client-certificate",
7640 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7641 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007642 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007643 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007644 // Resume the session to assert the peer signature
7645 // algorithm is reported on both handshakes.
7646 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007647 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007648 expectedError: verifyError,
7649 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007650
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007651 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007652 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007653 testCases = append(testCases, testCase{
7654 testType: serverTest,
7655 name: "ServerAuth-Sign" + suffix,
7656 config: Config{
7657 MaxVersion: ver.version,
7658 CipherSuites: signingCiphers,
7659 VerifySignatureAlgorithms: []signatureAlgorithm{
7660 fakeSigAlg1,
7661 alg.id,
7662 fakeSigAlg2,
7663 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007664 },
David Benjamina5022392017-07-10 17:40:39 -04007665 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007666 flags: []string{
7667 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7668 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7669 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007670 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007671 },
7672 shouldFail: shouldSignFail,
7673 expectedError: signError,
7674 expectedPeerSignatureAlgorithm: alg.id,
7675 })
7676 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007677
7678 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007679 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007680 config: Config{
7681 MaxVersion: ver.version,
7682 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007683 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007684 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007685 alg.id,
7686 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007687 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007688 SkipECDSACurveCheck: shouldVerifyFail,
7689 IgnoreSignatureVersionChecks: shouldVerifyFail,
7690 // Some signature algorithms may not be advertised.
7691 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007692 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007693 },
David Benjamina5022392017-07-10 17:40:39 -04007694 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007695 flags: []string{
7696 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7697 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007698 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007699 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007700 // Resume the session to assert the peer signature
7701 // algorithm is reported on both handshakes.
7702 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007703 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007704 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007705 })
David Benjamin5208fd42016-07-13 21:43:25 -04007706
David Benjamin3ef76972016-10-17 17:59:54 -04007707 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007708 testCases = append(testCases, testCase{
7709 testType: serverTest,
7710 name: "ClientAuth-InvalidSignature" + suffix,
7711 config: Config{
7712 MaxVersion: ver.version,
7713 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7714 SignSignatureAlgorithms: []signatureAlgorithm{
7715 alg.id,
7716 },
7717 Bugs: ProtocolBugs{
7718 InvalidSignature: true,
7719 },
7720 },
David Benjamina5022392017-07-10 17:40:39 -04007721 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007722 flags: []string{
7723 "-require-any-client-certificate",
7724 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007725 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007726 },
7727 shouldFail: true,
7728 expectedError: ":BAD_SIGNATURE:",
7729 })
7730
7731 testCases = append(testCases, testCase{
7732 name: "ServerAuth-InvalidSignature" + suffix,
7733 config: Config{
7734 MaxVersion: ver.version,
7735 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7736 CipherSuites: signingCiphers,
7737 SignSignatureAlgorithms: []signatureAlgorithm{
7738 alg.id,
7739 },
7740 Bugs: ProtocolBugs{
7741 InvalidSignature: true,
7742 },
7743 },
David Benjamina5022392017-07-10 17:40:39 -04007744 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007745 flags: []string{
7746 "-enable-all-curves",
7747 "-enable-ed25519",
7748 },
David Benjamin5208fd42016-07-13 21:43:25 -04007749 shouldFail: true,
7750 expectedError: ":BAD_SIGNATURE:",
7751 })
7752 }
David Benjaminca3d5452016-07-14 12:51:01 -04007753
David Benjamin3ef76972016-10-17 17:59:54 -04007754 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007755 testCases = append(testCases, testCase{
7756 name: "ClientAuth-Sign-Negotiate" + suffix,
7757 config: Config{
7758 MaxVersion: ver.version,
7759 ClientAuth: RequireAnyClientCert,
7760 VerifySignatureAlgorithms: allAlgorithms,
7761 },
David Benjamina5022392017-07-10 17:40:39 -04007762 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007763 flags: []string{
7764 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7765 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7766 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007767 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007768 "-signing-prefs", strconv.Itoa(int(alg.id)),
7769 },
7770 expectedPeerSignatureAlgorithm: alg.id,
7771 })
7772
7773 testCases = append(testCases, testCase{
7774 testType: serverTest,
7775 name: "ServerAuth-Sign-Negotiate" + suffix,
7776 config: Config{
7777 MaxVersion: ver.version,
7778 CipherSuites: signingCiphers,
7779 VerifySignatureAlgorithms: allAlgorithms,
7780 },
David Benjamina5022392017-07-10 17:40:39 -04007781 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007782 flags: []string{
7783 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7784 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7785 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007786 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007787 "-signing-prefs", strconv.Itoa(int(alg.id)),
7788 },
7789 expectedPeerSignatureAlgorithm: alg.id,
7790 })
7791 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007792 }
David Benjamin000800a2014-11-14 01:43:59 -05007793 }
7794
Nick Harper60edffd2016-06-21 15:19:24 -07007795 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007796 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007797 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007798 config: Config{
7799 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007800 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007801 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007802 signatureECDSAWithP521AndSHA512,
7803 signatureRSAPKCS1WithSHA384,
7804 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007805 },
7806 },
7807 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007808 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7809 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007810 },
Nick Harper60edffd2016-06-21 15:19:24 -07007811 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007812 })
7813
7814 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007815 name: "ClientAuth-SignatureType-TLS13",
7816 config: Config{
7817 ClientAuth: RequireAnyClientCert,
7818 MaxVersion: VersionTLS13,
7819 VerifySignatureAlgorithms: []signatureAlgorithm{
7820 signatureECDSAWithP521AndSHA512,
7821 signatureRSAPKCS1WithSHA384,
7822 signatureRSAPSSWithSHA384,
7823 signatureECDSAWithSHA1,
7824 },
7825 },
7826 flags: []string{
7827 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7828 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7829 },
7830 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7831 })
7832
7833 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007834 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007835 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007837 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007839 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007840 signatureECDSAWithP521AndSHA512,
7841 signatureRSAPKCS1WithSHA384,
7842 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007843 },
7844 },
Nick Harper60edffd2016-06-21 15:19:24 -07007845 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007846 })
7847
Steven Valdez143e8b32016-07-11 13:19:03 -04007848 testCases = append(testCases, testCase{
7849 testType: serverTest,
7850 name: "ServerAuth-SignatureType-TLS13",
7851 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007852 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007853 VerifySignatureAlgorithms: []signatureAlgorithm{
7854 signatureECDSAWithP521AndSHA512,
7855 signatureRSAPKCS1WithSHA384,
7856 signatureRSAPSSWithSHA384,
7857 signatureECDSAWithSHA1,
7858 },
7859 },
7860 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7861 })
7862
David Benjamina95e9f32016-07-08 16:28:04 -07007863 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007864 testCases = append(testCases, testCase{
7865 testType: serverTest,
7866 name: "Verify-ClientAuth-SignatureType",
7867 config: Config{
7868 MaxVersion: VersionTLS12,
7869 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007870 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007871 signatureRSAPKCS1WithSHA256,
7872 },
7873 Bugs: ProtocolBugs{
7874 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7875 },
7876 },
7877 flags: []string{
7878 "-require-any-client-certificate",
7879 },
7880 shouldFail: true,
7881 expectedError: ":WRONG_SIGNATURE_TYPE:",
7882 })
7883
7884 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007885 testType: serverTest,
7886 name: "Verify-ClientAuth-SignatureType-TLS13",
7887 config: Config{
7888 MaxVersion: VersionTLS13,
7889 Certificates: []Certificate{rsaCertificate},
7890 SignSignatureAlgorithms: []signatureAlgorithm{
7891 signatureRSAPSSWithSHA256,
7892 },
7893 Bugs: ProtocolBugs{
7894 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7895 },
7896 },
7897 flags: []string{
7898 "-require-any-client-certificate",
7899 },
7900 shouldFail: true,
7901 expectedError: ":WRONG_SIGNATURE_TYPE:",
7902 })
7903
7904 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007905 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007906 config: Config{
7907 MaxVersion: VersionTLS12,
7908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007909 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007910 signatureRSAPKCS1WithSHA256,
7911 },
7912 Bugs: ProtocolBugs{
7913 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7914 },
7915 },
7916 shouldFail: true,
7917 expectedError: ":WRONG_SIGNATURE_TYPE:",
7918 })
7919
Steven Valdez143e8b32016-07-11 13:19:03 -04007920 testCases = append(testCases, testCase{
7921 name: "Verify-ServerAuth-SignatureType-TLS13",
7922 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007923 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007924 SignSignatureAlgorithms: []signatureAlgorithm{
7925 signatureRSAPSSWithSHA256,
7926 },
7927 Bugs: ProtocolBugs{
7928 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7929 },
7930 },
7931 shouldFail: true,
7932 expectedError: ":WRONG_SIGNATURE_TYPE:",
7933 })
7934
David Benjamin51dd7d62016-07-08 16:07:01 -07007935 // Test that, if the list is missing, the peer falls back to SHA-1 in
7936 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007937 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007938 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007940 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007941 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007942 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007943 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007944 },
7945 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007946 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007947 },
7948 },
7949 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007950 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7951 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007952 },
7953 })
7954
7955 testCases = append(testCases, testCase{
7956 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007957 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007958 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007959 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007960 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007961 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007962 },
7963 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007964 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007965 },
7966 },
David Benjaminee32bea2016-08-17 13:36:44 -04007967 flags: []string{
7968 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7969 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7970 },
7971 })
7972
7973 testCases = append(testCases, testCase{
7974 name: "ClientAuth-SHA1-Fallback-ECDSA",
7975 config: Config{
7976 MaxVersion: VersionTLS12,
7977 ClientAuth: RequireAnyClientCert,
7978 VerifySignatureAlgorithms: []signatureAlgorithm{
7979 signatureECDSAWithSHA1,
7980 },
7981 Bugs: ProtocolBugs{
7982 NoSignatureAlgorithms: true,
7983 },
7984 },
7985 flags: []string{
7986 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7987 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7988 },
7989 })
7990
7991 testCases = append(testCases, testCase{
7992 testType: serverTest,
7993 name: "ServerAuth-SHA1-Fallback-ECDSA",
7994 config: Config{
7995 MaxVersion: VersionTLS12,
7996 VerifySignatureAlgorithms: []signatureAlgorithm{
7997 signatureECDSAWithSHA1,
7998 },
7999 Bugs: ProtocolBugs{
8000 NoSignatureAlgorithms: true,
8001 },
8002 },
8003 flags: []string{
8004 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8005 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8006 },
David Benjamin000800a2014-11-14 01:43:59 -05008007 })
David Benjamin72dc7832015-03-16 17:49:43 -04008008
David Benjamin51dd7d62016-07-08 16:07:01 -07008009 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008010 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008011 config: Config{
8012 MaxVersion: VersionTLS13,
8013 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008014 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008015 signatureRSAPKCS1WithSHA1,
8016 },
8017 Bugs: ProtocolBugs{
8018 NoSignatureAlgorithms: true,
8019 },
8020 },
8021 flags: []string{
8022 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8023 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8024 },
David Benjamin48901652016-08-01 12:12:47 -04008025 shouldFail: true,
8026 // An empty CertificateRequest signature algorithm list is a
8027 // syntax error in TLS 1.3.
8028 expectedError: ":DECODE_ERROR:",
8029 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008030 })
8031
8032 testCases = append(testCases, testCase{
8033 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008034 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008035 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008036 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008037 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008038 signatureRSAPKCS1WithSHA1,
8039 },
8040 Bugs: ProtocolBugs{
8041 NoSignatureAlgorithms: true,
8042 },
8043 },
8044 shouldFail: true,
8045 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8046 })
8047
David Benjaminb62d2872016-07-18 14:55:02 +02008048 // Test that hash preferences are enforced. BoringSSL does not implement
8049 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008050 testCases = append(testCases, testCase{
8051 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008052 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008053 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008054 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008055 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008056 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008057 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008058 },
8059 Bugs: ProtocolBugs{
8060 IgnorePeerSignatureAlgorithmPreferences: true,
8061 },
8062 },
8063 flags: []string{"-require-any-client-certificate"},
8064 shouldFail: true,
8065 expectedError: ":WRONG_SIGNATURE_TYPE:",
8066 })
8067
8068 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008069 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008071 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008072 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008073 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008074 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008075 },
8076 Bugs: ProtocolBugs{
8077 IgnorePeerSignatureAlgorithmPreferences: true,
8078 },
8079 },
8080 shouldFail: true,
8081 expectedError: ":WRONG_SIGNATURE_TYPE:",
8082 })
David Benjaminb62d2872016-07-18 14:55:02 +02008083 testCases = append(testCases, testCase{
8084 testType: serverTest,
8085 name: "ClientAuth-Enforced-TLS13",
8086 config: Config{
8087 MaxVersion: VersionTLS13,
8088 Certificates: []Certificate{rsaCertificate},
8089 SignSignatureAlgorithms: []signatureAlgorithm{
8090 signatureRSAPKCS1WithMD5,
8091 },
8092 Bugs: ProtocolBugs{
8093 IgnorePeerSignatureAlgorithmPreferences: true,
8094 IgnoreSignatureVersionChecks: true,
8095 },
8096 },
8097 flags: []string{"-require-any-client-certificate"},
8098 shouldFail: true,
8099 expectedError: ":WRONG_SIGNATURE_TYPE:",
8100 })
8101
8102 testCases = append(testCases, testCase{
8103 name: "ServerAuth-Enforced-TLS13",
8104 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008105 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008106 SignSignatureAlgorithms: []signatureAlgorithm{
8107 signatureRSAPKCS1WithMD5,
8108 },
8109 Bugs: ProtocolBugs{
8110 IgnorePeerSignatureAlgorithmPreferences: true,
8111 IgnoreSignatureVersionChecks: true,
8112 },
8113 },
8114 shouldFail: true,
8115 expectedError: ":WRONG_SIGNATURE_TYPE:",
8116 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008117
8118 // Test that the agreed upon digest respects the client preferences and
8119 // the server digests.
8120 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008121 name: "NoCommonAlgorithms-Digests",
8122 config: Config{
8123 MaxVersion: VersionTLS12,
8124 ClientAuth: RequireAnyClientCert,
8125 VerifySignatureAlgorithms: []signatureAlgorithm{
8126 signatureRSAPKCS1WithSHA512,
8127 signatureRSAPKCS1WithSHA1,
8128 },
8129 },
8130 flags: []string{
8131 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8132 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8133 "-digest-prefs", "SHA256",
8134 },
8135 shouldFail: true,
8136 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8137 })
8138 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008139 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008140 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008141 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008142 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008143 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008144 signatureRSAPKCS1WithSHA512,
8145 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008146 },
8147 },
8148 flags: []string{
8149 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8150 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008151 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008152 },
David Benjaminca3d5452016-07-14 12:51:01 -04008153 shouldFail: true,
8154 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8155 })
8156 testCases = append(testCases, testCase{
8157 name: "NoCommonAlgorithms-TLS13",
8158 config: Config{
8159 MaxVersion: VersionTLS13,
8160 ClientAuth: RequireAnyClientCert,
8161 VerifySignatureAlgorithms: []signatureAlgorithm{
8162 signatureRSAPSSWithSHA512,
8163 signatureRSAPSSWithSHA384,
8164 },
8165 },
8166 flags: []string{
8167 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8168 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8169 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8170 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008171 shouldFail: true,
8172 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008173 })
8174 testCases = append(testCases, testCase{
8175 name: "Agree-Digest-SHA256",
8176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008177 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008178 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008179 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008180 signatureRSAPKCS1WithSHA1,
8181 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008182 },
8183 },
8184 flags: []string{
8185 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8186 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008187 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008188 },
Nick Harper60edffd2016-06-21 15:19:24 -07008189 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008190 })
8191 testCases = append(testCases, testCase{
8192 name: "Agree-Digest-SHA1",
8193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008194 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008195 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008196 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008197 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008198 },
8199 },
8200 flags: []string{
8201 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8202 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008203 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008204 },
Nick Harper60edffd2016-06-21 15:19:24 -07008205 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008206 })
8207 testCases = append(testCases, testCase{
8208 name: "Agree-Digest-Default",
8209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008210 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008211 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008212 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008213 signatureRSAPKCS1WithSHA256,
8214 signatureECDSAWithP256AndSHA256,
8215 signatureRSAPKCS1WithSHA1,
8216 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008217 },
8218 },
8219 flags: []string{
8220 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8221 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8222 },
Nick Harper60edffd2016-06-21 15:19:24 -07008223 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008224 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008225
David Benjaminca3d5452016-07-14 12:51:01 -04008226 // Test that the signing preference list may include extra algorithms
8227 // without negotiation problems.
8228 testCases = append(testCases, testCase{
8229 testType: serverTest,
8230 name: "FilterExtraAlgorithms",
8231 config: Config{
8232 MaxVersion: VersionTLS12,
8233 VerifySignatureAlgorithms: []signatureAlgorithm{
8234 signatureRSAPKCS1WithSHA256,
8235 },
8236 },
8237 flags: []string{
8238 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8239 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8240 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8241 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8242 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8243 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8244 },
8245 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8246 })
8247
David Benjamin4c3ddf72016-06-29 18:13:53 -04008248 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8249 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008250 testCases = append(testCases, testCase{
8251 name: "CheckLeafCurve",
8252 config: Config{
8253 MaxVersion: VersionTLS12,
8254 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008255 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008256 },
8257 flags: []string{"-p384-only"},
8258 shouldFail: true,
8259 expectedError: ":BAD_ECC_CERT:",
8260 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008261
8262 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8263 testCases = append(testCases, testCase{
8264 name: "CheckLeafCurve-TLS13",
8265 config: Config{
8266 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008267 Certificates: []Certificate{ecdsaP256Certificate},
8268 },
8269 flags: []string{"-p384-only"},
8270 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008271
8272 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8273 testCases = append(testCases, testCase{
8274 name: "ECDSACurveMismatch-Verify-TLS12",
8275 config: Config{
8276 MaxVersion: VersionTLS12,
8277 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8278 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008279 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008280 signatureECDSAWithP384AndSHA384,
8281 },
8282 },
8283 })
8284
8285 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8286 testCases = append(testCases, testCase{
8287 name: "ECDSACurveMismatch-Verify-TLS13",
8288 config: Config{
8289 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008290 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008291 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008292 signatureECDSAWithP384AndSHA384,
8293 },
8294 Bugs: ProtocolBugs{
8295 SkipECDSACurveCheck: true,
8296 },
8297 },
8298 shouldFail: true,
8299 expectedError: ":WRONG_SIGNATURE_TYPE:",
8300 })
8301
8302 // Signature algorithm selection in TLS 1.3 should take the curve into
8303 // account.
8304 testCases = append(testCases, testCase{
8305 testType: serverTest,
8306 name: "ECDSACurveMismatch-Sign-TLS13",
8307 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008308 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008309 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008310 signatureECDSAWithP384AndSHA384,
8311 signatureECDSAWithP256AndSHA256,
8312 },
8313 },
8314 flags: []string{
8315 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8316 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8317 },
8318 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8319 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008320
8321 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8322 // server does not attempt to sign in that case.
8323 testCases = append(testCases, testCase{
8324 testType: serverTest,
8325 name: "RSA-PSS-Large",
8326 config: Config{
8327 MaxVersion: VersionTLS13,
8328 VerifySignatureAlgorithms: []signatureAlgorithm{
8329 signatureRSAPSSWithSHA512,
8330 },
8331 },
8332 flags: []string{
8333 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8334 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8335 },
8336 shouldFail: true,
8337 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8338 })
David Benjamin57e929f2016-08-30 00:30:38 -04008339
8340 // Test that RSA-PSS is enabled by default for TLS 1.2.
8341 testCases = append(testCases, testCase{
8342 testType: clientTest,
8343 name: "RSA-PSS-Default-Verify",
8344 config: Config{
8345 MaxVersion: VersionTLS12,
8346 SignSignatureAlgorithms: []signatureAlgorithm{
8347 signatureRSAPSSWithSHA256,
8348 },
8349 },
8350 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8351 })
8352
8353 testCases = append(testCases, testCase{
8354 testType: serverTest,
8355 name: "RSA-PSS-Default-Sign",
8356 config: Config{
8357 MaxVersion: VersionTLS12,
8358 VerifySignatureAlgorithms: []signatureAlgorithm{
8359 signatureRSAPSSWithSHA256,
8360 },
8361 },
8362 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8363 })
David Benjamin69522112017-03-28 15:38:29 -05008364
8365 // TLS 1.1 and below has no way to advertise support for or negotiate
8366 // Ed25519's signature algorithm.
8367 testCases = append(testCases, testCase{
8368 testType: clientTest,
8369 name: "NoEd25519-TLS11-ServerAuth-Verify",
8370 config: Config{
8371 MaxVersion: VersionTLS11,
8372 Certificates: []Certificate{ed25519Certificate},
8373 Bugs: ProtocolBugs{
8374 // Sign with Ed25519 even though it is TLS 1.1.
8375 UseLegacySigningAlgorithm: signatureEd25519,
8376 },
8377 },
8378 flags: []string{"-enable-ed25519"},
8379 shouldFail: true,
8380 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8381 })
8382 testCases = append(testCases, testCase{
8383 testType: serverTest,
8384 name: "NoEd25519-TLS11-ServerAuth-Sign",
8385 config: Config{
8386 MaxVersion: VersionTLS11,
8387 },
8388 flags: []string{
8389 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8390 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8391 },
8392 shouldFail: true,
8393 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8394 })
8395 testCases = append(testCases, testCase{
8396 testType: serverTest,
8397 name: "NoEd25519-TLS11-ClientAuth-Verify",
8398 config: Config{
8399 MaxVersion: VersionTLS11,
8400 Certificates: []Certificate{ed25519Certificate},
8401 Bugs: ProtocolBugs{
8402 // Sign with Ed25519 even though it is TLS 1.1.
8403 UseLegacySigningAlgorithm: signatureEd25519,
8404 },
8405 },
8406 flags: []string{
8407 "-enable-ed25519",
8408 "-require-any-client-certificate",
8409 },
8410 shouldFail: true,
8411 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8412 })
8413 testCases = append(testCases, testCase{
8414 testType: clientTest,
8415 name: "NoEd25519-TLS11-ClientAuth-Sign",
8416 config: Config{
8417 MaxVersion: VersionTLS11,
8418 ClientAuth: RequireAnyClientCert,
8419 },
8420 flags: []string{
8421 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8422 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8423 },
8424 shouldFail: true,
8425 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8426 })
8427
8428 // Test Ed25519 is not advertised by default.
8429 testCases = append(testCases, testCase{
8430 testType: clientTest,
8431 name: "Ed25519DefaultDisable-NoAdvertise",
8432 config: Config{
8433 Certificates: []Certificate{ed25519Certificate},
8434 },
8435 shouldFail: true,
8436 expectedLocalError: "tls: no common signature algorithms",
8437 })
8438
8439 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8440 // preferences.
8441 testCases = append(testCases, testCase{
8442 testType: clientTest,
8443 name: "Ed25519DefaultDisable-NoAccept",
8444 config: Config{
8445 Certificates: []Certificate{ed25519Certificate},
8446 Bugs: ProtocolBugs{
8447 IgnorePeerSignatureAlgorithmPreferences: true,
8448 },
8449 },
8450 shouldFail: true,
8451 expectedLocalError: "remote error: illegal parameter",
8452 expectedError: ":WRONG_SIGNATURE_TYPE:",
8453 })
David Benjamin71c21b42017-04-14 17:05:40 -04008454
8455 // Test that configuring verify preferences changes what the client
8456 // advertises.
8457 testCases = append(testCases, testCase{
8458 name: "VerifyPreferences-Advertised",
8459 config: Config{
8460 Certificates: []Certificate{rsaCertificate},
8461 SignSignatureAlgorithms: []signatureAlgorithm{
8462 signatureRSAPSSWithSHA256,
8463 signatureRSAPSSWithSHA384,
8464 signatureRSAPSSWithSHA512,
8465 },
8466 },
8467 flags: []string{
8468 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8469 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8470 },
8471 })
8472
8473 // Test that the client advertises a set which the runner can find
8474 // nothing in common with.
8475 testCases = append(testCases, testCase{
8476 name: "VerifyPreferences-NoCommonAlgorithms",
8477 config: Config{
8478 Certificates: []Certificate{rsaCertificate},
8479 SignSignatureAlgorithms: []signatureAlgorithm{
8480 signatureRSAPSSWithSHA256,
8481 signatureRSAPSSWithSHA512,
8482 },
8483 },
8484 flags: []string{
8485 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8486 },
8487 shouldFail: true,
8488 expectedLocalError: "tls: no common signature algorithms",
8489 })
8490
8491 // Test that the client enforces its preferences when configured.
8492 testCases = append(testCases, testCase{
8493 name: "VerifyPreferences-Enforced",
8494 config: Config{
8495 Certificates: []Certificate{rsaCertificate},
8496 SignSignatureAlgorithms: []signatureAlgorithm{
8497 signatureRSAPSSWithSHA256,
8498 signatureRSAPSSWithSHA512,
8499 },
8500 Bugs: ProtocolBugs{
8501 IgnorePeerSignatureAlgorithmPreferences: true,
8502 },
8503 },
8504 flags: []string{
8505 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8506 },
8507 shouldFail: true,
8508 expectedLocalError: "remote error: illegal parameter",
8509 expectedError: ":WRONG_SIGNATURE_TYPE:",
8510 })
8511
8512 // Test that explicitly configuring Ed25519 is as good as changing the
8513 // boolean toggle.
8514 testCases = append(testCases, testCase{
8515 name: "VerifyPreferences-Ed25519",
8516 config: Config{
8517 Certificates: []Certificate{ed25519Certificate},
8518 },
8519 flags: []string{
8520 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8521 },
8522 })
David Benjamin000800a2014-11-14 01:43:59 -05008523}
8524
David Benjamin83f90402015-01-27 01:09:43 -05008525// timeouts is the retransmit schedule for BoringSSL. It doubles and
8526// caps at 60 seconds. On the 13th timeout, it gives up.
8527var timeouts = []time.Duration{
8528 1 * time.Second,
8529 2 * time.Second,
8530 4 * time.Second,
8531 8 * time.Second,
8532 16 * time.Second,
8533 32 * time.Second,
8534 60 * time.Second,
8535 60 * time.Second,
8536 60 * time.Second,
8537 60 * time.Second,
8538 60 * time.Second,
8539 60 * time.Second,
8540 60 * time.Second,
8541}
8542
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008543// shortTimeouts is an alternate set of timeouts which would occur if the
8544// initial timeout duration was set to 250ms.
8545var shortTimeouts = []time.Duration{
8546 250 * time.Millisecond,
8547 500 * time.Millisecond,
8548 1 * time.Second,
8549 2 * time.Second,
8550 4 * time.Second,
8551 8 * time.Second,
8552 16 * time.Second,
8553 32 * time.Second,
8554 60 * time.Second,
8555 60 * time.Second,
8556 60 * time.Second,
8557 60 * time.Second,
8558 60 * time.Second,
8559}
8560
David Benjamin83f90402015-01-27 01:09:43 -05008561func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008562 // These tests work by coordinating some behavior on both the shim and
8563 // the runner.
8564 //
8565 // TimeoutSchedule configures the runner to send a series of timeout
8566 // opcodes to the shim (see packetAdaptor) immediately before reading
8567 // each peer handshake flight N. The timeout opcode both simulates a
8568 // timeout in the shim and acts as a synchronization point to help the
8569 // runner bracket each handshake flight.
8570 //
8571 // We assume the shim does not read from the channel eagerly. It must
8572 // first wait until it has sent flight N and is ready to receive
8573 // handshake flight N+1. At this point, it will process the timeout
8574 // opcode. It must then immediately respond with a timeout ACK and act
8575 // as if the shim was idle for the specified amount of time.
8576 //
8577 // The runner then drops all packets received before the ACK and
8578 // continues waiting for flight N. This ordering results in one attempt
8579 // at sending flight N to be dropped. For the test to complete, the
8580 // shim must send flight N again, testing that the shim implements DTLS
8581 // retransmit on a timeout.
8582
Steven Valdez143e8b32016-07-11 13:19:03 -04008583 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008584 // likely be more epochs to cross and the final message's retransmit may
8585 // be more complex.
8586
David Benjamin11c82892017-02-23 20:40:31 -05008587 // Test that this is indeed the timeout schedule. Stress all
8588 // four patterns of handshake.
8589 for i := 1; i < len(timeouts); i++ {
8590 number := strconv.Itoa(i)
8591 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008592 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008593 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008595 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008596 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008597 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008598 },
8599 },
8600 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008601 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008602 })
David Benjamin11c82892017-02-23 20:40:31 -05008603 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008604 protocol: dtls,
8605 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008606 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008607 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008608 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008609 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008610 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008611 },
8612 },
8613 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008614 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008615 })
8616 }
David Benjamin11c82892017-02-23 20:40:31 -05008617
8618 // Test that exceeding the timeout schedule hits a read
8619 // timeout.
8620 testCases = append(testCases, testCase{
8621 protocol: dtls,
8622 name: "DTLS-Retransmit-Timeout",
8623 config: Config{
8624 MaxVersion: VersionTLS12,
8625 Bugs: ProtocolBugs{
8626 TimeoutSchedule: timeouts,
8627 },
8628 },
8629 resumeSession: true,
8630 flags: []string{"-async"},
8631 shouldFail: true,
8632 expectedError: ":READ_TIMEOUT_EXPIRED:",
8633 })
8634
8635 // Test that timeout handling has a fudge factor, due to API
8636 // problems.
8637 testCases = append(testCases, testCase{
8638 protocol: dtls,
8639 name: "DTLS-Retransmit-Fudge",
8640 config: Config{
8641 MaxVersion: VersionTLS12,
8642 Bugs: ProtocolBugs{
8643 TimeoutSchedule: []time.Duration{
8644 timeouts[0] - 10*time.Millisecond,
8645 },
8646 },
8647 },
8648 resumeSession: true,
8649 flags: []string{"-async"},
8650 })
8651
8652 // Test that the final Finished retransmitting isn't
8653 // duplicated if the peer badly fragments everything.
8654 testCases = append(testCases, testCase{
8655 testType: serverTest,
8656 protocol: dtls,
8657 name: "DTLS-Retransmit-Fragmented",
8658 config: Config{
8659 MaxVersion: VersionTLS12,
8660 Bugs: ProtocolBugs{
8661 TimeoutSchedule: []time.Duration{timeouts[0]},
8662 MaxHandshakeRecordLength: 2,
8663 },
8664 },
8665 flags: []string{"-async"},
8666 })
8667
8668 // Test the timeout schedule when a shorter initial timeout duration is set.
8669 testCases = append(testCases, testCase{
8670 protocol: dtls,
8671 name: "DTLS-Retransmit-Short-Client",
8672 config: Config{
8673 MaxVersion: VersionTLS12,
8674 Bugs: ProtocolBugs{
8675 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8676 },
8677 },
8678 resumeSession: true,
8679 flags: []string{
8680 "-async",
8681 "-initial-timeout-duration-ms", "250",
8682 },
8683 })
8684 testCases = append(testCases, testCase{
8685 protocol: dtls,
8686 testType: serverTest,
8687 name: "DTLS-Retransmit-Short-Server",
8688 config: Config{
8689 MaxVersion: VersionTLS12,
8690 Bugs: ProtocolBugs{
8691 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8692 },
8693 },
8694 resumeSession: true,
8695 flags: []string{
8696 "-async",
8697 "-initial-timeout-duration-ms", "250",
8698 },
8699 })
David Benjamin302b8182017-08-22 14:47:22 -07008700
8701 // If the shim sends the last Finished (server full or client resume
8702 // handshakes), it must retransmit that Finished when it sees a
8703 // post-handshake penultimate Finished from the runner. The above tests
8704 // cover this. Conversely, if the shim sends the penultimate Finished
8705 // (client full or server resume), test that it does not retransmit.
8706 testCases = append(testCases, testCase{
8707 protocol: dtls,
8708 testType: clientTest,
8709 name: "DTLS-StrayRetransmitFinished-ClientFull",
8710 config: Config{
8711 MaxVersion: VersionTLS12,
8712 Bugs: ProtocolBugs{
8713 RetransmitFinished: true,
8714 },
8715 },
8716 })
8717 testCases = append(testCases, testCase{
8718 protocol: dtls,
8719 testType: serverTest,
8720 name: "DTLS-StrayRetransmitFinished-ServerResume",
8721 config: Config{
8722 MaxVersion: VersionTLS12,
8723 },
8724 resumeConfig: &Config{
8725 MaxVersion: VersionTLS12,
8726 Bugs: ProtocolBugs{
8727 RetransmitFinished: true,
8728 },
8729 },
8730 resumeSession: true,
8731 })
David Benjamin83f90402015-01-27 01:09:43 -05008732}
8733
David Benjaminc565ebb2015-04-03 04:06:36 -04008734func addExportKeyingMaterialTests() {
8735 for _, vers := range tlsVersions {
8736 if vers.version == VersionSSL30 {
8737 continue
8738 }
8739 testCases = append(testCases, testCase{
8740 name: "ExportKeyingMaterial-" + vers.name,
8741 config: Config{
8742 MaxVersion: vers.version,
8743 },
David Benjamina5022392017-07-10 17:40:39 -04008744 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008745 exportKeyingMaterial: 1024,
8746 exportLabel: "label",
8747 exportContext: "context",
8748 useExportContext: true,
8749 })
8750 testCases = append(testCases, testCase{
8751 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8752 config: Config{
8753 MaxVersion: vers.version,
8754 },
David Benjamina5022392017-07-10 17:40:39 -04008755 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008756 exportKeyingMaterial: 1024,
8757 })
8758 testCases = append(testCases, testCase{
8759 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8760 config: Config{
8761 MaxVersion: vers.version,
8762 },
David Benjamina5022392017-07-10 17:40:39 -04008763 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008764 exportKeyingMaterial: 1024,
8765 useExportContext: true,
8766 })
8767 testCases = append(testCases, testCase{
8768 name: "ExportKeyingMaterial-Small-" + vers.name,
8769 config: Config{
8770 MaxVersion: vers.version,
8771 },
David Benjamina5022392017-07-10 17:40:39 -04008772 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008773 exportKeyingMaterial: 1,
8774 exportLabel: "label",
8775 exportContext: "context",
8776 useExportContext: true,
8777 })
8778 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008779
David Benjaminc565ebb2015-04-03 04:06:36 -04008780 testCases = append(testCases, testCase{
8781 name: "ExportKeyingMaterial-SSL3",
8782 config: Config{
8783 MaxVersion: VersionSSL30,
8784 },
8785 exportKeyingMaterial: 1024,
8786 exportLabel: "label",
8787 exportContext: "context",
8788 useExportContext: true,
8789 shouldFail: true,
8790 expectedError: "failed to export keying material",
8791 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008792
8793 // Exporters work during a False Start.
8794 testCases = append(testCases, testCase{
8795 name: "ExportKeyingMaterial-FalseStart",
8796 config: Config{
8797 MaxVersion: VersionTLS12,
8798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8799 NextProtos: []string{"foo"},
8800 Bugs: ProtocolBugs{
8801 ExpectFalseStart: true,
8802 },
8803 },
8804 flags: []string{
8805 "-false-start",
8806 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008807 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008808 },
8809 shimWritesFirst: true,
8810 exportKeyingMaterial: 1024,
8811 exportLabel: "label",
8812 exportContext: "context",
8813 useExportContext: true,
8814 })
8815
8816 // Exporters do not work in the middle of a renegotiation. Test this by
8817 // triggering the exporter after every SSL_read call and configuring the
8818 // shim to run asynchronously.
8819 testCases = append(testCases, testCase{
8820 name: "ExportKeyingMaterial-Renegotiate",
8821 config: Config{
8822 MaxVersion: VersionTLS12,
8823 },
8824 renegotiate: 1,
8825 flags: []string{
8826 "-async",
8827 "-use-exporter-between-reads",
8828 "-renegotiate-freely",
8829 "-expect-total-renegotiations", "1",
8830 },
8831 shouldFail: true,
8832 expectedError: "failed to export keying material",
8833 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008834}
8835
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008836func addTLSUniqueTests() {
8837 for _, isClient := range []bool{false, true} {
8838 for _, isResumption := range []bool{false, true} {
8839 for _, hasEMS := range []bool{false, true} {
8840 var suffix string
8841 if isResumption {
8842 suffix = "Resume-"
8843 } else {
8844 suffix = "Full-"
8845 }
8846
8847 if hasEMS {
8848 suffix += "EMS-"
8849 } else {
8850 suffix += "NoEMS-"
8851 }
8852
8853 if isClient {
8854 suffix += "Client"
8855 } else {
8856 suffix += "Server"
8857 }
8858
8859 test := testCase{
8860 name: "TLSUnique-" + suffix,
8861 testTLSUnique: true,
8862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008863 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008864 Bugs: ProtocolBugs{
8865 NoExtendedMasterSecret: !hasEMS,
8866 },
8867 },
8868 }
8869
8870 if isResumption {
8871 test.resumeSession = true
8872 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008873 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008874 Bugs: ProtocolBugs{
8875 NoExtendedMasterSecret: !hasEMS,
8876 },
8877 }
8878 }
8879
8880 if isResumption && !hasEMS {
8881 test.shouldFail = true
8882 test.expectedError = "failed to get tls-unique"
8883 }
8884
8885 testCases = append(testCases, test)
8886 }
8887 }
8888 }
8889}
8890
Adam Langley09505632015-07-30 18:10:13 -07008891func addCustomExtensionTests() {
8892 expectedContents := "custom extension"
8893 emptyString := ""
8894
8895 for _, isClient := range []bool{false, true} {
8896 suffix := "Server"
8897 flag := "-enable-server-custom-extension"
8898 testType := serverTest
8899 if isClient {
8900 suffix = "Client"
8901 flag = "-enable-client-custom-extension"
8902 testType = clientTest
8903 }
8904
8905 testCases = append(testCases, testCase{
8906 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008907 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008908 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008909 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008910 Bugs: ProtocolBugs{
8911 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008912 ExpectedCustomExtension: &expectedContents,
8913 },
8914 },
8915 flags: []string{flag},
8916 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008917 testCases = append(testCases, testCase{
8918 testType: testType,
8919 name: "CustomExtensions-" + suffix + "-TLS13",
8920 config: Config{
8921 MaxVersion: VersionTLS13,
8922 Bugs: ProtocolBugs{
8923 CustomExtension: expectedContents,
8924 ExpectedCustomExtension: &expectedContents,
8925 },
8926 },
8927 flags: []string{flag},
8928 })
Adam Langley09505632015-07-30 18:10:13 -07008929
8930 // If the parse callback fails, the handshake should also fail.
8931 testCases = append(testCases, testCase{
8932 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008933 name: "CustomExtensions-ParseError-" + 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 + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008938 ExpectedCustomExtension: &expectedContents,
8939 },
8940 },
David Benjamin399e7c92015-07-30 23:01:27 -04008941 flags: []string{flag},
8942 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008943 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8944 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008945 testCases = append(testCases, testCase{
8946 testType: testType,
8947 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8948 config: Config{
8949 MaxVersion: VersionTLS13,
8950 Bugs: ProtocolBugs{
8951 CustomExtension: expectedContents + "foo",
8952 ExpectedCustomExtension: &expectedContents,
8953 },
8954 },
8955 flags: []string{flag},
8956 shouldFail: true,
8957 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8958 })
Adam Langley09505632015-07-30 18:10:13 -07008959
8960 // If the add callback fails, the handshake should also fail.
8961 testCases = append(testCases, testCase{
8962 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008963 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008965 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008966 Bugs: ProtocolBugs{
8967 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008968 ExpectedCustomExtension: &expectedContents,
8969 },
8970 },
David Benjamin399e7c92015-07-30 23:01:27 -04008971 flags: []string{flag, "-custom-extension-fail-add"},
8972 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008973 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8974 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008975 testCases = append(testCases, testCase{
8976 testType: testType,
8977 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8978 config: Config{
8979 MaxVersion: VersionTLS13,
8980 Bugs: ProtocolBugs{
8981 CustomExtension: expectedContents,
8982 ExpectedCustomExtension: &expectedContents,
8983 },
8984 },
8985 flags: []string{flag, "-custom-extension-fail-add"},
8986 shouldFail: true,
8987 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8988 })
Adam Langley09505632015-07-30 18:10:13 -07008989
8990 // If the add callback returns zero, no extension should be
8991 // added.
8992 skipCustomExtension := expectedContents
8993 if isClient {
8994 // For the case where the client skips sending the
8995 // custom extension, the server must not “echo” it.
8996 skipCustomExtension = ""
8997 }
8998 testCases = append(testCases, testCase{
8999 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009000 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009002 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009003 Bugs: ProtocolBugs{
9004 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009005 ExpectedCustomExtension: &emptyString,
9006 },
9007 },
9008 flags: []string{flag, "-custom-extension-skip"},
9009 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009010 testCases = append(testCases, testCase{
9011 testType: testType,
9012 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9013 config: Config{
9014 MaxVersion: VersionTLS13,
9015 Bugs: ProtocolBugs{
9016 CustomExtension: skipCustomExtension,
9017 ExpectedCustomExtension: &emptyString,
9018 },
9019 },
9020 flags: []string{flag, "-custom-extension-skip"},
9021 })
Adam Langley09505632015-07-30 18:10:13 -07009022 }
9023
Steven Valdezf4ecc842017-08-10 14:02:56 -04009024 // If the client sends both early data and custom extension, the handshake
9025 // should succeed as long as both the extensions aren't returned by the
9026 // server.
9027 testCases = append(testCases, testCase{
9028 testType: clientTest,
9029 name: "CustomExtensions-Client-EarlyData-None",
9030 config: Config{
9031 MaxVersion: VersionTLS13,
9032 MaxEarlyDataSize: 16384,
9033 Bugs: ProtocolBugs{
9034 ExpectedCustomExtension: &expectedContents,
9035 AlwaysRejectEarlyData: true,
9036 },
9037 },
9038 resumeSession: true,
9039 flags: []string{
9040 "-enable-client-custom-extension",
9041 "-enable-early-data",
9042 "-expect-early-data-info",
9043 "-expect-reject-early-data",
9044 },
9045 })
9046
9047 testCases = append(testCases, testCase{
9048 testType: clientTest,
9049 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9050 config: Config{
9051 MaxVersion: VersionTLS13,
9052 MaxEarlyDataSize: 16384,
9053 Bugs: ProtocolBugs{
9054 ExpectedCustomExtension: &expectedContents,
9055 },
9056 },
9057 resumeSession: true,
9058 flags: []string{
9059 "-enable-client-custom-extension",
9060 "-enable-early-data",
9061 "-expect-early-data-info",
9062 "-expect-accept-early-data",
9063 },
9064 })
9065
9066 testCases = append(testCases, testCase{
9067 testType: clientTest,
9068 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9069 config: Config{
9070 MaxVersion: VersionTLS13,
9071 MaxEarlyDataSize: 16384,
9072 Bugs: ProtocolBugs{
9073 AlwaysRejectEarlyData: true,
9074 CustomExtension: expectedContents,
9075 ExpectedCustomExtension: &expectedContents,
9076 },
9077 },
9078 resumeSession: true,
9079 flags: []string{
9080 "-enable-client-custom-extension",
9081 "-enable-early-data",
9082 "-expect-early-data-info",
9083 "-expect-reject-early-data",
9084 },
9085 })
9086
9087 testCases = append(testCases, testCase{
9088 testType: clientTest,
9089 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9090 config: Config{
9091 MaxVersion: VersionTLS13,
9092 MaxEarlyDataSize: 16384,
9093 Bugs: ProtocolBugs{
9094 CustomExtension: expectedContents,
9095 ExpectedCustomExtension: &expectedContents,
9096 },
9097 },
9098 resumeConfig: &Config{
9099 MaxVersion: VersionTLS13,
9100 MaxEarlyDataSize: 16384,
9101 Bugs: ProtocolBugs{
9102 CustomExtension: expectedContents,
9103 ExpectedCustomExtension: &expectedContents,
9104 SendEarlyDataExtension: true,
9105 },
9106 },
9107 resumeSession: true,
9108 shouldFail: true,
9109 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9110 flags: []string{
9111 "-enable-client-custom-extension",
9112 "-enable-early-data",
9113 "-expect-early-data-info",
9114 },
9115 })
9116
9117 // If the server receives both early data and custom extension, only the
9118 // custom extension should be accepted.
9119 testCases = append(testCases, testCase{
9120 testType: serverTest,
9121 name: "CustomExtensions-Server-EarlyDataAccepted",
9122 config: Config{
9123 MaxVersion: VersionTLS13,
9124 MaxEarlyDataSize: 16384,
9125 Bugs: ProtocolBugs{
9126 CustomExtension: expectedContents,
9127 ExpectedCustomExtension: &expectedContents,
9128 ExpectEarlyDataAccepted: false,
9129 },
9130 },
9131 resumeSession: true,
9132 flags: []string{
9133 "-enable-server-custom-extension",
9134 "-enable-early-data",
9135 "-expect-early-data-info",
9136 },
9137 })
9138
Adam Langley09505632015-07-30 18:10:13 -07009139 // The custom extension add callback should not be called if the client
9140 // doesn't send the extension.
9141 testCases = append(testCases, testCase{
9142 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009143 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009145 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009146 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009147 ExpectedCustomExtension: &emptyString,
9148 },
9149 },
9150 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9151 })
Adam Langley2deb9842015-08-07 11:15:37 -07009152
Steven Valdez143e8b32016-07-11 13:19:03 -04009153 testCases = append(testCases, testCase{
9154 testType: serverTest,
9155 name: "CustomExtensions-NotCalled-Server-TLS13",
9156 config: Config{
9157 MaxVersion: VersionTLS13,
9158 Bugs: ProtocolBugs{
9159 ExpectedCustomExtension: &emptyString,
9160 },
9161 },
9162 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9163 })
9164
Adam Langley2deb9842015-08-07 11:15:37 -07009165 // Test an unknown extension from the server.
9166 testCases = append(testCases, testCase{
9167 testType: clientTest,
9168 name: "UnknownExtension-Client",
9169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009170 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009171 Bugs: ProtocolBugs{
9172 CustomExtension: expectedContents,
9173 },
9174 },
David Benjamin0c40a962016-08-01 12:05:50 -04009175 shouldFail: true,
9176 expectedError: ":UNEXPECTED_EXTENSION:",
9177 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009178 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009179 testCases = append(testCases, testCase{
9180 testType: clientTest,
9181 name: "UnknownExtension-Client-TLS13",
9182 config: Config{
9183 MaxVersion: VersionTLS13,
9184 Bugs: ProtocolBugs{
9185 CustomExtension: expectedContents,
9186 },
9187 },
David Benjamin0c40a962016-08-01 12:05:50 -04009188 shouldFail: true,
9189 expectedError: ":UNEXPECTED_EXTENSION:",
9190 expectedLocalError: "remote error: unsupported extension",
9191 })
David Benjamin490469f2016-10-05 22:44:38 -04009192 testCases = append(testCases, testCase{
9193 testType: clientTest,
9194 name: "UnknownUnencryptedExtension-Client-TLS13",
9195 config: Config{
9196 MaxVersion: VersionTLS13,
9197 Bugs: ProtocolBugs{
9198 CustomUnencryptedExtension: expectedContents,
9199 },
9200 },
9201 shouldFail: true,
9202 expectedError: ":UNEXPECTED_EXTENSION:",
9203 // The shim must send an alert, but alerts at this point do not
9204 // get successfully decrypted by the runner.
9205 expectedLocalError: "local error: bad record MAC",
9206 })
9207 testCases = append(testCases, testCase{
9208 testType: clientTest,
9209 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9210 config: Config{
9211 MaxVersion: VersionTLS13,
9212 Bugs: ProtocolBugs{
9213 SendUnencryptedALPN: "foo",
9214 },
9215 },
9216 flags: []string{
9217 "-advertise-alpn", "\x03foo\x03bar",
9218 },
9219 shouldFail: true,
9220 expectedError: ":UNEXPECTED_EXTENSION:",
9221 // The shim must send an alert, but alerts at this point do not
9222 // get successfully decrypted by the runner.
9223 expectedLocalError: "local error: bad record MAC",
9224 })
David Benjamin0c40a962016-08-01 12:05:50 -04009225
9226 // Test a known but unoffered extension from the server.
9227 testCases = append(testCases, testCase{
9228 testType: clientTest,
9229 name: "UnofferedExtension-Client",
9230 config: Config{
9231 MaxVersion: VersionTLS12,
9232 Bugs: ProtocolBugs{
9233 SendALPN: "alpn",
9234 },
9235 },
9236 shouldFail: true,
9237 expectedError: ":UNEXPECTED_EXTENSION:",
9238 expectedLocalError: "remote error: unsupported extension",
9239 })
9240 testCases = append(testCases, testCase{
9241 testType: clientTest,
9242 name: "UnofferedExtension-Client-TLS13",
9243 config: Config{
9244 MaxVersion: VersionTLS13,
9245 Bugs: ProtocolBugs{
9246 SendALPN: "alpn",
9247 },
9248 },
9249 shouldFail: true,
9250 expectedError: ":UNEXPECTED_EXTENSION:",
9251 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009252 })
Adam Langley09505632015-07-30 18:10:13 -07009253}
9254
David Benjaminb36a3952015-12-01 18:53:13 -05009255func addRSAClientKeyExchangeTests() {
9256 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9257 testCases = append(testCases, testCase{
9258 testType: serverTest,
9259 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9260 config: Config{
9261 // Ensure the ClientHello version and final
9262 // version are different, to detect if the
9263 // server uses the wrong one.
9264 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009265 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009266 Bugs: ProtocolBugs{
9267 BadRSAClientKeyExchange: bad,
9268 },
9269 },
9270 shouldFail: true,
9271 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9272 })
9273 }
David Benjamine63d9d72016-09-19 18:27:34 -04009274
9275 // The server must compare whatever was in ClientHello.version for the
9276 // RSA premaster.
9277 testCases = append(testCases, testCase{
9278 testType: serverTest,
9279 name: "SendClientVersion-RSA",
9280 config: Config{
9281 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9282 Bugs: ProtocolBugs{
9283 SendClientVersion: 0x1234,
9284 },
9285 },
9286 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9287 })
David Benjaminb36a3952015-12-01 18:53:13 -05009288}
9289
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009290var testCurves = []struct {
9291 name string
9292 id CurveID
9293}{
Adam Langley764ab982017-03-10 18:01:30 -08009294 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009295 {"P-256", CurveP256},
9296 {"P-384", CurveP384},
9297 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009298 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009299}
9300
Steven Valdez5440fe02016-07-18 12:40:30 -04009301const bogusCurve = 0x1234
9302
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009303func addCurveTests() {
9304 for _, curve := range testCurves {
9305 testCases = append(testCases, testCase{
9306 name: "CurveTest-Client-" + curve.name,
9307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009308 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009309 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9310 CurvePreferences: []CurveID{curve.id},
9311 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009312 flags: []string{
9313 "-enable-all-curves",
9314 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9315 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009316 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009317 })
9318 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009319 name: "CurveTest-Client-" + curve.name + "-TLS13",
9320 config: Config{
9321 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009322 CurvePreferences: []CurveID{curve.id},
9323 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009324 flags: []string{
9325 "-enable-all-curves",
9326 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9327 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009328 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009329 })
9330 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009331 testType: serverTest,
9332 name: "CurveTest-Server-" + 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 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009344 testCases = append(testCases, testCase{
9345 testType: serverTest,
9346 name: "CurveTest-Server-" + curve.name + "-TLS13",
9347 config: Config{
9348 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009349 CurvePreferences: []CurveID{curve.id},
9350 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009351 flags: []string{
9352 "-enable-all-curves",
9353 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9354 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009355 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009356 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009357 }
David Benjamin241ae832016-01-15 03:04:54 -05009358
9359 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009360 testCases = append(testCases, testCase{
9361 testType: serverTest,
9362 name: "UnknownCurve",
9363 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009364 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009365 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9366 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9367 },
9368 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009369
Steven Valdez803c77a2016-09-06 14:13:43 -04009370 // The server must be tolerant to bogus curves.
9371 testCases = append(testCases, testCase{
9372 testType: serverTest,
9373 name: "UnknownCurve-TLS13",
9374 config: Config{
9375 MaxVersion: VersionTLS13,
9376 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9377 },
9378 })
9379
David Benjamin4c3ddf72016-06-29 18:13:53 -04009380 // The server must not consider ECDHE ciphers when there are no
9381 // supported curves.
9382 testCases = append(testCases, testCase{
9383 testType: serverTest,
9384 name: "NoSupportedCurves",
9385 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009386 MaxVersion: VersionTLS12,
9387 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9388 Bugs: ProtocolBugs{
9389 NoSupportedCurves: true,
9390 },
9391 },
9392 shouldFail: true,
9393 expectedError: ":NO_SHARED_CIPHER:",
9394 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009395 testCases = append(testCases, testCase{
9396 testType: serverTest,
9397 name: "NoSupportedCurves-TLS13",
9398 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009399 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009400 Bugs: ProtocolBugs{
9401 NoSupportedCurves: true,
9402 },
9403 },
9404 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009405 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009406 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009407
9408 // The server must fall back to another cipher when there are no
9409 // supported curves.
9410 testCases = append(testCases, testCase{
9411 testType: serverTest,
9412 name: "NoCommonCurves",
9413 config: Config{
9414 MaxVersion: VersionTLS12,
9415 CipherSuites: []uint16{
9416 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009417 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009418 },
9419 CurvePreferences: []CurveID{CurveP224},
9420 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009421 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009422 })
9423
9424 // The client must reject bogus curves and disabled curves.
9425 testCases = append(testCases, testCase{
9426 name: "BadECDHECurve",
9427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009428 MaxVersion: VersionTLS12,
9429 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9430 Bugs: ProtocolBugs{
9431 SendCurve: bogusCurve,
9432 },
9433 },
9434 shouldFail: true,
9435 expectedError: ":WRONG_CURVE:",
9436 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009437 testCases = append(testCases, testCase{
9438 name: "BadECDHECurve-TLS13",
9439 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009440 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009441 Bugs: ProtocolBugs{
9442 SendCurve: bogusCurve,
9443 },
9444 },
9445 shouldFail: true,
9446 expectedError: ":WRONG_CURVE:",
9447 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009448
9449 testCases = append(testCases, testCase{
9450 name: "UnsupportedCurve",
9451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009452 MaxVersion: VersionTLS12,
9453 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9454 CurvePreferences: []CurveID{CurveP256},
9455 Bugs: ProtocolBugs{
9456 IgnorePeerCurvePreferences: true,
9457 },
9458 },
9459 flags: []string{"-p384-only"},
9460 shouldFail: true,
9461 expectedError: ":WRONG_CURVE:",
9462 })
9463
David Benjamin4f921572016-07-17 14:20:10 +02009464 testCases = append(testCases, testCase{
9465 // TODO(davidben): Add a TLS 1.3 version where
9466 // HelloRetryRequest requests an unsupported curve.
9467 name: "UnsupportedCurve-ServerHello-TLS13",
9468 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009469 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009470 CurvePreferences: []CurveID{CurveP384},
9471 Bugs: ProtocolBugs{
9472 SendCurve: CurveP256,
9473 },
9474 },
9475 flags: []string{"-p384-only"},
9476 shouldFail: true,
9477 expectedError: ":WRONG_CURVE:",
9478 })
9479
David Benjamin4c3ddf72016-06-29 18:13:53 -04009480 // Test invalid curve points.
9481 testCases = append(testCases, testCase{
9482 name: "InvalidECDHPoint-Client",
9483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009484 MaxVersion: VersionTLS12,
9485 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9486 CurvePreferences: []CurveID{CurveP256},
9487 Bugs: ProtocolBugs{
9488 InvalidECDHPoint: true,
9489 },
9490 },
9491 shouldFail: true,
9492 expectedError: ":INVALID_ENCODING:",
9493 })
9494 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009495 name: "InvalidECDHPoint-Client-TLS13",
9496 config: Config{
9497 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009498 CurvePreferences: []CurveID{CurveP256},
9499 Bugs: ProtocolBugs{
9500 InvalidECDHPoint: true,
9501 },
9502 },
9503 shouldFail: true,
9504 expectedError: ":INVALID_ENCODING:",
9505 })
9506 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009507 testType: serverTest,
9508 name: "InvalidECDHPoint-Server",
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 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009520 testCases = append(testCases, testCase{
9521 testType: serverTest,
9522 name: "InvalidECDHPoint-Server-TLS13",
9523 config: Config{
9524 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009525 CurvePreferences: []CurveID{CurveP256},
9526 Bugs: ProtocolBugs{
9527 InvalidECDHPoint: true,
9528 },
9529 },
9530 shouldFail: true,
9531 expectedError: ":INVALID_ENCODING:",
9532 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009533
9534 // The previous curve ID should be reported on TLS 1.2 resumption.
9535 testCases = append(testCases, testCase{
9536 name: "CurveID-Resume-Client",
9537 config: Config{
9538 MaxVersion: VersionTLS12,
9539 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9540 CurvePreferences: []CurveID{CurveX25519},
9541 },
9542 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9543 resumeSession: true,
9544 })
9545 testCases = append(testCases, testCase{
9546 testType: serverTest,
9547 name: "CurveID-Resume-Server",
9548 config: Config{
9549 MaxVersion: VersionTLS12,
9550 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9551 CurvePreferences: []CurveID{CurveX25519},
9552 },
9553 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9554 resumeSession: true,
9555 })
9556
9557 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9558 // one should be reported.
9559 testCases = append(testCases, testCase{
9560 name: "CurveID-Resume-Client-TLS13",
9561 config: Config{
9562 MaxVersion: VersionTLS13,
9563 CurvePreferences: []CurveID{CurveX25519},
9564 },
9565 resumeConfig: &Config{
9566 MaxVersion: VersionTLS13,
9567 CurvePreferences: []CurveID{CurveP256},
9568 },
9569 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009570 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9571 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009572 },
9573 resumeSession: true,
9574 })
9575 testCases = append(testCases, testCase{
9576 testType: serverTest,
9577 name: "CurveID-Resume-Server-TLS13",
9578 config: Config{
9579 MaxVersion: VersionTLS13,
9580 CurvePreferences: []CurveID{CurveX25519},
9581 },
9582 resumeConfig: &Config{
9583 MaxVersion: VersionTLS13,
9584 CurvePreferences: []CurveID{CurveP256},
9585 },
9586 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009587 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9588 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009589 },
9590 resumeSession: true,
9591 })
David Benjamina81967b2016-12-22 09:16:57 -05009592
9593 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9594 testCases = append(testCases, testCase{
9595 name: "PointFormat-ServerHello-TLS12",
9596 config: Config{
9597 MaxVersion: VersionTLS12,
9598 Bugs: ProtocolBugs{
9599 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9600 },
9601 },
9602 })
9603 testCases = append(testCases, testCase{
9604 name: "PointFormat-EncryptedExtensions-TLS13",
9605 config: Config{
9606 MaxVersion: VersionTLS13,
9607 Bugs: ProtocolBugs{
9608 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9609 },
9610 },
9611 shouldFail: true,
9612 expectedError: ":ERROR_PARSING_EXTENSION:",
9613 })
9614
David Benjamin6c1f2b72017-10-04 17:01:22 -04009615 // Server-sent supported groups/curves are legal in TLS 1.3. They are
9616 // illegal in TLS 1.2, but some servers send them anyway, so we must
9617 // tolerate them.
9618 testCases = append(testCases, testCase{
9619 name: "SupportedCurves-ServerHello-TLS12",
9620 config: Config{
9621 MaxVersion: VersionTLS12,
9622 Bugs: ProtocolBugs{
9623 SendServerSupportedCurves: true,
9624 },
9625 },
9626 })
9627 testCases = append(testCases, testCase{
9628 name: "SupportedCurves-EncryptedExtensions-TLS13",
9629 config: Config{
9630 MaxVersion: VersionTLS13,
9631 Bugs: ProtocolBugs{
9632 SendServerSupportedCurves: true,
9633 },
9634 },
9635 })
9636
David Benjamina81967b2016-12-22 09:16:57 -05009637 // Test that we tolerate unknown point formats, as long as
9638 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9639 // check they are still functional.
9640 testCases = append(testCases, testCase{
9641 name: "PointFormat-Client-Tolerance",
9642 config: Config{
9643 MaxVersion: VersionTLS12,
9644 Bugs: ProtocolBugs{
9645 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9646 },
9647 },
9648 })
9649 testCases = append(testCases, testCase{
9650 testType: serverTest,
9651 name: "PointFormat-Server-Tolerance",
9652 config: Config{
9653 MaxVersion: VersionTLS12,
9654 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9655 Bugs: ProtocolBugs{
9656 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9657 },
9658 },
9659 })
9660
9661 // Test TLS 1.2 does not require the point format extension to be
9662 // present.
9663 testCases = append(testCases, testCase{
9664 name: "PointFormat-Client-Missing",
9665 config: Config{
9666 MaxVersion: VersionTLS12,
9667 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9668 Bugs: ProtocolBugs{
9669 SendSupportedPointFormats: []byte{},
9670 },
9671 },
9672 })
9673 testCases = append(testCases, testCase{
9674 testType: serverTest,
9675 name: "PointFormat-Server-Missing",
9676 config: Config{
9677 MaxVersion: VersionTLS12,
9678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9679 Bugs: ProtocolBugs{
9680 SendSupportedPointFormats: []byte{},
9681 },
9682 },
9683 })
9684
9685 // If the point format extension is present, uncompressed points must be
9686 // offered. BoringSSL requires this whether or not ECDHE is used.
9687 testCases = append(testCases, testCase{
9688 name: "PointFormat-Client-MissingUncompressed",
9689 config: Config{
9690 MaxVersion: VersionTLS12,
9691 Bugs: ProtocolBugs{
9692 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9693 },
9694 },
9695 shouldFail: true,
9696 expectedError: ":ERROR_PARSING_EXTENSION:",
9697 })
9698 testCases = append(testCases, testCase{
9699 testType: serverTest,
9700 name: "PointFormat-Server-MissingUncompressed",
9701 config: Config{
9702 MaxVersion: VersionTLS12,
9703 Bugs: ProtocolBugs{
9704 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9705 },
9706 },
9707 shouldFail: true,
9708 expectedError: ":ERROR_PARSING_EXTENSION:",
9709 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009710}
9711
David Benjaminc9ae27c2016-06-24 22:56:37 -04009712func addTLS13RecordTests() {
9713 testCases = append(testCases, testCase{
9714 name: "TLS13-RecordPadding",
9715 config: Config{
9716 MaxVersion: VersionTLS13,
9717 MinVersion: VersionTLS13,
9718 Bugs: ProtocolBugs{
9719 RecordPadding: 10,
9720 },
9721 },
9722 })
9723
9724 testCases = append(testCases, testCase{
9725 name: "TLS13-EmptyRecords",
9726 config: Config{
9727 MaxVersion: VersionTLS13,
9728 MinVersion: VersionTLS13,
9729 Bugs: ProtocolBugs{
9730 OmitRecordContents: true,
9731 },
9732 },
9733 shouldFail: true,
9734 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9735 })
9736
9737 testCases = append(testCases, testCase{
9738 name: "TLS13-OnlyPadding",
9739 config: Config{
9740 MaxVersion: VersionTLS13,
9741 MinVersion: VersionTLS13,
9742 Bugs: ProtocolBugs{
9743 OmitRecordContents: true,
9744 RecordPadding: 10,
9745 },
9746 },
9747 shouldFail: true,
9748 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9749 })
9750
9751 testCases = append(testCases, testCase{
9752 name: "TLS13-WrongOuterRecord",
9753 config: Config{
9754 MaxVersion: VersionTLS13,
9755 MinVersion: VersionTLS13,
9756 Bugs: ProtocolBugs{
9757 OuterRecordType: recordTypeHandshake,
9758 },
9759 },
9760 shouldFail: true,
9761 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9762 })
9763}
9764
Steven Valdez5b986082016-09-01 12:29:49 -04009765func addSessionTicketTests() {
9766 testCases = append(testCases, testCase{
9767 // In TLS 1.2 and below, empty NewSessionTicket messages
9768 // mean the server changed its mind on sending a ticket.
9769 name: "SendEmptySessionTicket",
9770 config: Config{
9771 MaxVersion: VersionTLS12,
9772 Bugs: ProtocolBugs{
9773 SendEmptySessionTicket: true,
9774 },
9775 },
9776 flags: []string{"-expect-no-session"},
9777 })
9778
9779 // Test that the server ignores unknown PSK modes.
9780 testCases = append(testCases, testCase{
9781 testType: serverTest,
9782 name: "TLS13-SendUnknownModeSessionTicket-Server",
9783 config: Config{
9784 MaxVersion: VersionTLS13,
9785 Bugs: ProtocolBugs{
9786 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009787 },
9788 },
9789 resumeSession: true,
9790 expectedResumeVersion: VersionTLS13,
9791 })
9792
Steven Valdeza833c352016-11-01 13:39:36 -04009793 // Test that the server does not send session tickets with no matching key exchange mode.
9794 testCases = append(testCases, testCase{
9795 testType: serverTest,
9796 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9797 config: Config{
9798 MaxVersion: VersionTLS13,
9799 Bugs: ProtocolBugs{
9800 SendPSKKeyExchangeModes: []byte{0x1a},
9801 ExpectNoNewSessionTicket: true,
9802 },
9803 },
9804 })
9805
9806 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009807 testCases = append(testCases, testCase{
9808 testType: serverTest,
9809 name: "TLS13-SendBadKEModeSessionTicket-Server",
9810 config: Config{
9811 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009812 },
9813 resumeConfig: &Config{
9814 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009815 Bugs: ProtocolBugs{
9816 SendPSKKeyExchangeModes: []byte{0x1a},
9817 },
9818 },
9819 resumeSession: true,
9820 expectResumeRejected: true,
9821 })
9822
Steven Valdeza833c352016-11-01 13:39:36 -04009823 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009824 testCases = append(testCases, testCase{
9825 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009826 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009827 config: Config{
9828 MaxVersion: VersionTLS13,
9829 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009830 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009831 },
9832 },
Steven Valdeza833c352016-11-01 13:39:36 -04009833 resumeSession: true,
9834 flags: []string{
9835 "-resumption-delay", "10",
9836 },
Steven Valdez5b986082016-09-01 12:29:49 -04009837 })
9838
Steven Valdeza833c352016-11-01 13:39:36 -04009839 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009840 testCases = append(testCases, testCase{
9841 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009842 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009843 config: Config{
9844 MaxVersion: VersionTLS13,
9845 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009846 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009847 },
9848 },
Steven Valdeza833c352016-11-01 13:39:36 -04009849 resumeSession: true,
9850 shouldFail: true,
9851 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009852 })
9853
David Benjamin35ac5b72017-03-03 15:05:56 -05009854 // Test that the server's ticket age skew reporting works.
9855 testCases = append(testCases, testCase{
9856 testType: serverTest,
9857 name: "TLS13-TicketAgeSkew-Forward",
9858 config: Config{
9859 MaxVersion: VersionTLS13,
9860 Bugs: ProtocolBugs{
9861 SendTicketAge: 15 * time.Second,
9862 },
9863 },
David Benjamin065d7332017-03-26 10:51:43 -05009864 resumeSession: true,
9865 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009866 flags: []string{
9867 "-resumption-delay", "10",
9868 "-expect-ticket-age-skew", "5",
9869 },
9870 })
9871 testCases = append(testCases, testCase{
9872 testType: serverTest,
9873 name: "TLS13-TicketAgeSkew-Backward",
9874 config: Config{
9875 MaxVersion: VersionTLS13,
9876 Bugs: ProtocolBugs{
9877 SendTicketAge: 5 * time.Second,
9878 },
9879 },
David Benjamin065d7332017-03-26 10:51:43 -05009880 resumeSession: true,
9881 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009882 flags: []string{
9883 "-resumption-delay", "10",
9884 "-expect-ticket-age-skew", "-5",
9885 },
9886 })
9887
Steven Valdez08b65f42016-12-07 15:29:45 -05009888 testCases = append(testCases, testCase{
9889 testType: clientTest,
9890 name: "TLS13-SendTicketEarlyDataInfo",
9891 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009892 MaxVersion: VersionTLS13,
9893 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009894 },
9895 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009896 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009897 "-expect-early-data-info",
9898 },
9899 })
9900
David Benjamin9b160662017-01-25 19:53:43 -05009901 // Test that 0-RTT tickets are ignored in clients unless opted in.
9902 testCases = append(testCases, testCase{
9903 testType: clientTest,
9904 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9905 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009906 MaxVersion: VersionTLS13,
9907 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009908 },
9909 })
9910
Steven Valdez08b65f42016-12-07 15:29:45 -05009911 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009912 testType: clientTest,
9913 name: "TLS13-DuplicateTicketEarlyDataInfo",
9914 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009915 MaxVersion: VersionTLS13,
9916 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009917 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009918 DuplicateTicketEarlyDataInfo: true,
9919 },
9920 },
9921 shouldFail: true,
9922 expectedError: ":DUPLICATE_EXTENSION:",
9923 expectedLocalError: "remote error: illegal parameter",
9924 })
9925
9926 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009927 testType: serverTest,
9928 name: "TLS13-ExpectTicketEarlyDataInfo",
9929 config: Config{
9930 MaxVersion: VersionTLS13,
9931 Bugs: ProtocolBugs{
9932 ExpectTicketEarlyDataInfo: true,
9933 },
9934 },
9935 flags: []string{
9936 "-enable-early-data",
9937 },
9938 })
David Benjamin17b30832017-01-28 14:00:32 -05009939
9940 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9941 // is honored.
9942 testCases = append(testCases, testCase{
9943 testType: clientTest,
9944 name: "TLS13-HonorServerSessionTicketLifetime",
9945 config: Config{
9946 MaxVersion: VersionTLS13,
9947 Bugs: ProtocolBugs{
9948 SendTicketLifetime: 20 * time.Second,
9949 },
9950 },
9951 flags: []string{
9952 "-resumption-delay", "19",
9953 },
9954 resumeSession: true,
9955 })
9956 testCases = append(testCases, testCase{
9957 testType: clientTest,
9958 name: "TLS13-HonorServerSessionTicketLifetime-2",
9959 config: Config{
9960 MaxVersion: VersionTLS13,
9961 Bugs: ProtocolBugs{
9962 SendTicketLifetime: 20 * time.Second,
9963 // The client should not offer the expired session.
9964 ExpectNoTLS13PSK: true,
9965 },
9966 },
9967 flags: []string{
9968 "-resumption-delay", "21",
9969 },
David Benjamin023d4192017-02-06 13:49:07 -05009970 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009971 expectResumeRejected: true,
9972 })
Steven Valdez5b986082016-09-01 12:29:49 -04009973}
9974
David Benjamin82261be2016-07-07 14:32:50 -07009975func addChangeCipherSpecTests() {
9976 // Test missing ChangeCipherSpecs.
9977 testCases = append(testCases, testCase{
9978 name: "SkipChangeCipherSpec-Client",
9979 config: Config{
9980 MaxVersion: VersionTLS12,
9981 Bugs: ProtocolBugs{
9982 SkipChangeCipherSpec: true,
9983 },
9984 },
9985 shouldFail: true,
9986 expectedError: ":UNEXPECTED_RECORD:",
9987 })
9988 testCases = append(testCases, testCase{
9989 testType: serverTest,
9990 name: "SkipChangeCipherSpec-Server",
9991 config: Config{
9992 MaxVersion: VersionTLS12,
9993 Bugs: ProtocolBugs{
9994 SkipChangeCipherSpec: true,
9995 },
9996 },
9997 shouldFail: true,
9998 expectedError: ":UNEXPECTED_RECORD:",
9999 })
10000 testCases = append(testCases, testCase{
10001 testType: serverTest,
10002 name: "SkipChangeCipherSpec-Server-NPN",
10003 config: Config{
10004 MaxVersion: VersionTLS12,
10005 NextProtos: []string{"bar"},
10006 Bugs: ProtocolBugs{
10007 SkipChangeCipherSpec: true,
10008 },
10009 },
10010 flags: []string{
10011 "-advertise-npn", "\x03foo\x03bar\x03baz",
10012 },
10013 shouldFail: true,
10014 expectedError: ":UNEXPECTED_RECORD:",
10015 })
10016
10017 // Test synchronization between the handshake and ChangeCipherSpec.
10018 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10019 // rejected. Test both with and without handshake packing to handle both
10020 // when the partial post-CCS message is in its own record and when it is
10021 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010022 for _, packed := range []bool{false, true} {
10023 var suffix string
10024 if packed {
10025 suffix = "-Packed"
10026 }
10027
10028 testCases = append(testCases, testCase{
10029 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10030 config: Config{
10031 MaxVersion: VersionTLS12,
10032 Bugs: ProtocolBugs{
10033 FragmentAcrossChangeCipherSpec: true,
10034 PackHandshakeFlight: packed,
10035 },
10036 },
10037 shouldFail: true,
10038 expectedError: ":UNEXPECTED_RECORD:",
10039 })
10040 testCases = append(testCases, testCase{
10041 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10042 config: Config{
10043 MaxVersion: VersionTLS12,
10044 },
10045 resumeSession: true,
10046 resumeConfig: &Config{
10047 MaxVersion: VersionTLS12,
10048 Bugs: ProtocolBugs{
10049 FragmentAcrossChangeCipherSpec: true,
10050 PackHandshakeFlight: packed,
10051 },
10052 },
10053 shouldFail: true,
10054 expectedError: ":UNEXPECTED_RECORD:",
10055 })
10056 testCases = append(testCases, testCase{
10057 testType: serverTest,
10058 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10059 config: Config{
10060 MaxVersion: VersionTLS12,
10061 Bugs: ProtocolBugs{
10062 FragmentAcrossChangeCipherSpec: true,
10063 PackHandshakeFlight: packed,
10064 },
10065 },
10066 shouldFail: true,
10067 expectedError: ":UNEXPECTED_RECORD:",
10068 })
10069 testCases = append(testCases, testCase{
10070 testType: serverTest,
10071 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10072 config: Config{
10073 MaxVersion: VersionTLS12,
10074 },
10075 resumeSession: true,
10076 resumeConfig: &Config{
10077 MaxVersion: VersionTLS12,
10078 Bugs: ProtocolBugs{
10079 FragmentAcrossChangeCipherSpec: true,
10080 PackHandshakeFlight: packed,
10081 },
10082 },
10083 shouldFail: true,
10084 expectedError: ":UNEXPECTED_RECORD:",
10085 })
10086 testCases = append(testCases, testCase{
10087 testType: serverTest,
10088 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10089 config: Config{
10090 MaxVersion: VersionTLS12,
10091 NextProtos: []string{"bar"},
10092 Bugs: ProtocolBugs{
10093 FragmentAcrossChangeCipherSpec: true,
10094 PackHandshakeFlight: packed,
10095 },
10096 },
10097 flags: []string{
10098 "-advertise-npn", "\x03foo\x03bar\x03baz",
10099 },
10100 shouldFail: true,
10101 expectedError: ":UNEXPECTED_RECORD:",
10102 })
10103 }
10104
David Benjamin61672812016-07-14 23:10:43 -040010105 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10106 // messages in the handshake queue. Do this by testing the server
10107 // reading the client Finished, reversing the flight so Finished comes
10108 // first.
10109 testCases = append(testCases, testCase{
10110 protocol: dtls,
10111 testType: serverTest,
10112 name: "SendUnencryptedFinished-DTLS",
10113 config: Config{
10114 MaxVersion: VersionTLS12,
10115 Bugs: ProtocolBugs{
10116 SendUnencryptedFinished: true,
10117 ReverseHandshakeFragments: true,
10118 },
10119 },
10120 shouldFail: true,
10121 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10122 })
10123
Steven Valdez143e8b32016-07-11 13:19:03 -040010124 // Test synchronization between encryption changes and the handshake in
10125 // TLS 1.3, where ChangeCipherSpec is implicit.
10126 testCases = append(testCases, testCase{
10127 name: "PartialEncryptedExtensionsWithServerHello",
10128 config: Config{
10129 MaxVersion: VersionTLS13,
10130 Bugs: ProtocolBugs{
10131 PartialEncryptedExtensionsWithServerHello: true,
10132 },
10133 },
10134 shouldFail: true,
10135 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10136 })
10137 testCases = append(testCases, testCase{
10138 testType: serverTest,
10139 name: "PartialClientFinishedWithClientHello",
10140 config: Config{
10141 MaxVersion: VersionTLS13,
10142 Bugs: ProtocolBugs{
10143 PartialClientFinishedWithClientHello: true,
10144 },
10145 },
10146 shouldFail: true,
10147 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10148 })
10149
David Benjamin82261be2016-07-07 14:32:50 -070010150 // Test that early ChangeCipherSpecs are handled correctly.
10151 testCases = append(testCases, testCase{
10152 testType: serverTest,
10153 name: "EarlyChangeCipherSpec-server-1",
10154 config: Config{
10155 MaxVersion: VersionTLS12,
10156 Bugs: ProtocolBugs{
10157 EarlyChangeCipherSpec: 1,
10158 },
10159 },
10160 shouldFail: true,
10161 expectedError: ":UNEXPECTED_RECORD:",
10162 })
10163 testCases = append(testCases, testCase{
10164 testType: serverTest,
10165 name: "EarlyChangeCipherSpec-server-2",
10166 config: Config{
10167 MaxVersion: VersionTLS12,
10168 Bugs: ProtocolBugs{
10169 EarlyChangeCipherSpec: 2,
10170 },
10171 },
10172 shouldFail: true,
10173 expectedError: ":UNEXPECTED_RECORD:",
10174 })
10175 testCases = append(testCases, testCase{
10176 protocol: dtls,
10177 name: "StrayChangeCipherSpec",
10178 config: Config{
10179 // TODO(davidben): Once DTLS 1.3 exists, test
10180 // that stray ChangeCipherSpec messages are
10181 // rejected.
10182 MaxVersion: VersionTLS12,
10183 Bugs: ProtocolBugs{
10184 StrayChangeCipherSpec: true,
10185 },
10186 },
10187 })
10188
David Benjaminb0c761e2017-06-25 22:42:55 -040010189 // Test that reordered ChangeCipherSpecs are tolerated.
10190 testCases = append(testCases, testCase{
10191 protocol: dtls,
10192 name: "ReorderChangeCipherSpec-DTLS-Client",
10193 config: Config{
10194 MaxVersion: VersionTLS12,
10195 Bugs: ProtocolBugs{
10196 ReorderChangeCipherSpec: true,
10197 },
10198 },
10199 resumeSession: true,
10200 })
10201 testCases = append(testCases, testCase{
10202 testType: serverTest,
10203 protocol: dtls,
10204 name: "ReorderChangeCipherSpec-DTLS-Server",
10205 config: Config{
10206 MaxVersion: VersionTLS12,
10207 Bugs: ProtocolBugs{
10208 ReorderChangeCipherSpec: true,
10209 },
10210 },
10211 resumeSession: true,
10212 })
10213
David Benjamin82261be2016-07-07 14:32:50 -070010214 // Test that the contents of ChangeCipherSpec are checked.
10215 testCases = append(testCases, testCase{
10216 name: "BadChangeCipherSpec-1",
10217 config: Config{
10218 MaxVersion: VersionTLS12,
10219 Bugs: ProtocolBugs{
10220 BadChangeCipherSpec: []byte{2},
10221 },
10222 },
10223 shouldFail: true,
10224 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10225 })
10226 testCases = append(testCases, testCase{
10227 name: "BadChangeCipherSpec-2",
10228 config: Config{
10229 MaxVersion: VersionTLS12,
10230 Bugs: ProtocolBugs{
10231 BadChangeCipherSpec: []byte{1, 1},
10232 },
10233 },
10234 shouldFail: true,
10235 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10236 })
10237 testCases = append(testCases, testCase{
10238 protocol: dtls,
10239 name: "BadChangeCipherSpec-DTLS-1",
10240 config: Config{
10241 MaxVersion: VersionTLS12,
10242 Bugs: ProtocolBugs{
10243 BadChangeCipherSpec: []byte{2},
10244 },
10245 },
10246 shouldFail: true,
10247 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10248 })
10249 testCases = append(testCases, testCase{
10250 protocol: dtls,
10251 name: "BadChangeCipherSpec-DTLS-2",
10252 config: Config{
10253 MaxVersion: VersionTLS12,
10254 Bugs: ProtocolBugs{
10255 BadChangeCipherSpec: []byte{1, 1},
10256 },
10257 },
10258 shouldFail: true,
10259 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10260 })
10261}
10262
David Benjamincd2c8062016-09-09 11:28:16 -040010263type perMessageTest struct {
10264 messageType uint8
10265 test testCase
10266}
10267
10268// makePerMessageTests returns a series of test templates which cover each
10269// message in the TLS handshake. These may be used with bugs like
10270// WrongMessageType to fully test a per-message bug.
10271func makePerMessageTests() []perMessageTest {
10272 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010273 for _, protocol := range []protocol{tls, dtls} {
10274 var suffix string
10275 if protocol == dtls {
10276 suffix = "-DTLS"
10277 }
10278
David Benjamincd2c8062016-09-09 11:28:16 -040010279 ret = append(ret, perMessageTest{
10280 messageType: typeClientHello,
10281 test: testCase{
10282 protocol: protocol,
10283 testType: serverTest,
10284 name: "ClientHello" + suffix,
10285 config: Config{
10286 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010287 },
10288 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010289 })
10290
10291 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010292 ret = append(ret, perMessageTest{
10293 messageType: typeHelloVerifyRequest,
10294 test: testCase{
10295 protocol: protocol,
10296 name: "HelloVerifyRequest" + suffix,
10297 config: Config{
10298 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010299 },
10300 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010301 })
10302 }
10303
David Benjamincd2c8062016-09-09 11:28:16 -040010304 ret = append(ret, perMessageTest{
10305 messageType: typeServerHello,
10306 test: testCase{
10307 protocol: protocol,
10308 name: "ServerHello" + suffix,
10309 config: Config{
10310 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010311 },
10312 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010313 })
10314
David Benjamincd2c8062016-09-09 11:28:16 -040010315 ret = append(ret, perMessageTest{
10316 messageType: typeCertificate,
10317 test: testCase{
10318 protocol: protocol,
10319 name: "ServerCertificate" + suffix,
10320 config: Config{
10321 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010322 },
10323 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010324 })
10325
David Benjamincd2c8062016-09-09 11:28:16 -040010326 ret = append(ret, perMessageTest{
10327 messageType: typeCertificateStatus,
10328 test: testCase{
10329 protocol: protocol,
10330 name: "CertificateStatus" + suffix,
10331 config: Config{
10332 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010333 },
David Benjamincd2c8062016-09-09 11:28:16 -040010334 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010335 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010336 })
10337
David Benjamincd2c8062016-09-09 11:28:16 -040010338 ret = append(ret, perMessageTest{
10339 messageType: typeServerKeyExchange,
10340 test: testCase{
10341 protocol: protocol,
10342 name: "ServerKeyExchange" + suffix,
10343 config: Config{
10344 MaxVersion: VersionTLS12,
10345 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010346 },
10347 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010348 })
10349
David Benjamincd2c8062016-09-09 11:28:16 -040010350 ret = append(ret, perMessageTest{
10351 messageType: typeCertificateRequest,
10352 test: testCase{
10353 protocol: protocol,
10354 name: "CertificateRequest" + suffix,
10355 config: Config{
10356 MaxVersion: VersionTLS12,
10357 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010358 },
10359 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010360 })
10361
David Benjamincd2c8062016-09-09 11:28:16 -040010362 ret = append(ret, perMessageTest{
10363 messageType: typeServerHelloDone,
10364 test: testCase{
10365 protocol: protocol,
10366 name: "ServerHelloDone" + suffix,
10367 config: Config{
10368 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010369 },
10370 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010371 })
10372
David Benjamincd2c8062016-09-09 11:28:16 -040010373 ret = append(ret, perMessageTest{
10374 messageType: typeCertificate,
10375 test: testCase{
10376 testType: serverTest,
10377 protocol: protocol,
10378 name: "ClientCertificate" + suffix,
10379 config: Config{
10380 Certificates: []Certificate{rsaCertificate},
10381 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010382 },
David Benjamincd2c8062016-09-09 11:28:16 -040010383 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010384 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010385 })
10386
David Benjamincd2c8062016-09-09 11:28:16 -040010387 ret = append(ret, perMessageTest{
10388 messageType: typeCertificateVerify,
10389 test: testCase{
10390 testType: serverTest,
10391 protocol: protocol,
10392 name: "CertificateVerify" + suffix,
10393 config: Config{
10394 Certificates: []Certificate{rsaCertificate},
10395 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010396 },
David Benjamincd2c8062016-09-09 11:28:16 -040010397 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010398 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010399 })
10400
David Benjamincd2c8062016-09-09 11:28:16 -040010401 ret = append(ret, perMessageTest{
10402 messageType: typeClientKeyExchange,
10403 test: testCase{
10404 testType: serverTest,
10405 protocol: protocol,
10406 name: "ClientKeyExchange" + suffix,
10407 config: Config{
10408 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010409 },
10410 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010411 })
10412
10413 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010414 ret = append(ret, perMessageTest{
10415 messageType: typeNextProtocol,
10416 test: testCase{
10417 testType: serverTest,
10418 protocol: protocol,
10419 name: "NextProtocol" + suffix,
10420 config: Config{
10421 MaxVersion: VersionTLS12,
10422 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010423 },
David Benjamincd2c8062016-09-09 11:28:16 -040010424 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010425 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010426 })
10427
David Benjamincd2c8062016-09-09 11:28:16 -040010428 ret = append(ret, perMessageTest{
10429 messageType: typeChannelID,
10430 test: testCase{
10431 testType: serverTest,
10432 protocol: protocol,
10433 name: "ChannelID" + suffix,
10434 config: Config{
10435 MaxVersion: VersionTLS12,
10436 ChannelID: channelIDKey,
10437 },
10438 flags: []string{
10439 "-expect-channel-id",
10440 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010441 },
10442 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010443 })
10444 }
10445
David Benjamincd2c8062016-09-09 11:28:16 -040010446 ret = append(ret, perMessageTest{
10447 messageType: typeFinished,
10448 test: testCase{
10449 testType: serverTest,
10450 protocol: protocol,
10451 name: "ClientFinished" + suffix,
10452 config: Config{
10453 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010454 },
10455 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010456 })
10457
David Benjamincd2c8062016-09-09 11:28:16 -040010458 ret = append(ret, perMessageTest{
10459 messageType: typeNewSessionTicket,
10460 test: testCase{
10461 protocol: protocol,
10462 name: "NewSessionTicket" + suffix,
10463 config: Config{
10464 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010465 },
10466 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010467 })
10468
David Benjamincd2c8062016-09-09 11:28:16 -040010469 ret = append(ret, perMessageTest{
10470 messageType: typeFinished,
10471 test: testCase{
10472 protocol: protocol,
10473 name: "ServerFinished" + suffix,
10474 config: Config{
10475 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010476 },
10477 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010478 })
10479
10480 }
David Benjamincd2c8062016-09-09 11:28:16 -040010481
10482 ret = append(ret, perMessageTest{
10483 messageType: typeClientHello,
10484 test: testCase{
10485 testType: serverTest,
10486 name: "TLS13-ClientHello",
10487 config: Config{
10488 MaxVersion: VersionTLS13,
10489 },
10490 },
10491 })
10492
10493 ret = append(ret, perMessageTest{
10494 messageType: typeServerHello,
10495 test: testCase{
10496 name: "TLS13-ServerHello",
10497 config: Config{
10498 MaxVersion: VersionTLS13,
10499 },
10500 },
10501 })
10502
10503 ret = append(ret, perMessageTest{
10504 messageType: typeEncryptedExtensions,
10505 test: testCase{
10506 name: "TLS13-EncryptedExtensions",
10507 config: Config{
10508 MaxVersion: VersionTLS13,
10509 },
10510 },
10511 })
10512
10513 ret = append(ret, perMessageTest{
10514 messageType: typeCertificateRequest,
10515 test: testCase{
10516 name: "TLS13-CertificateRequest",
10517 config: Config{
10518 MaxVersion: VersionTLS13,
10519 ClientAuth: RequireAnyClientCert,
10520 },
10521 },
10522 })
10523
10524 ret = append(ret, perMessageTest{
10525 messageType: typeCertificate,
10526 test: testCase{
10527 name: "TLS13-ServerCertificate",
10528 config: Config{
10529 MaxVersion: VersionTLS13,
10530 },
10531 },
10532 })
10533
10534 ret = append(ret, perMessageTest{
10535 messageType: typeCertificateVerify,
10536 test: testCase{
10537 name: "TLS13-ServerCertificateVerify",
10538 config: Config{
10539 MaxVersion: VersionTLS13,
10540 },
10541 },
10542 })
10543
10544 ret = append(ret, perMessageTest{
10545 messageType: typeFinished,
10546 test: testCase{
10547 name: "TLS13-ServerFinished",
10548 config: Config{
10549 MaxVersion: VersionTLS13,
10550 },
10551 },
10552 })
10553
10554 ret = append(ret, perMessageTest{
10555 messageType: typeCertificate,
10556 test: testCase{
10557 testType: serverTest,
10558 name: "TLS13-ClientCertificate",
10559 config: Config{
10560 Certificates: []Certificate{rsaCertificate},
10561 MaxVersion: VersionTLS13,
10562 },
10563 flags: []string{"-require-any-client-certificate"},
10564 },
10565 })
10566
10567 ret = append(ret, perMessageTest{
10568 messageType: typeCertificateVerify,
10569 test: testCase{
10570 testType: serverTest,
10571 name: "TLS13-ClientCertificateVerify",
10572 config: Config{
10573 Certificates: []Certificate{rsaCertificate},
10574 MaxVersion: VersionTLS13,
10575 },
10576 flags: []string{"-require-any-client-certificate"},
10577 },
10578 })
10579
10580 ret = append(ret, perMessageTest{
10581 messageType: typeFinished,
10582 test: testCase{
10583 testType: serverTest,
10584 name: "TLS13-ClientFinished",
10585 config: Config{
10586 MaxVersion: VersionTLS13,
10587 },
10588 },
10589 })
10590
10591 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010592}
10593
David Benjamincd2c8062016-09-09 11:28:16 -040010594func addWrongMessageTypeTests() {
10595 for _, t := range makePerMessageTests() {
10596 t.test.name = "WrongMessageType-" + t.test.name
10597 t.test.config.Bugs.SendWrongMessageType = t.messageType
10598 t.test.shouldFail = true
10599 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10600 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010601
David Benjamincd2c8062016-09-09 11:28:16 -040010602 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10603 // In TLS 1.3, a bad ServerHello means the client sends
10604 // an unencrypted alert while the server expects
10605 // encryption, so the alert is not readable by runner.
10606 t.test.expectedLocalError = "local error: bad record MAC"
10607 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010608
David Benjamincd2c8062016-09-09 11:28:16 -040010609 testCases = append(testCases, t.test)
10610 }
David Benjaminebacdee2017-04-08 11:00:45 -040010611
10612 // The processing order for TLS 1.3 version negotiation is such that one
10613 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10614 // TLS 1.2. Test that we do not do this.
10615 testCases = append(testCases, testCase{
10616 name: "SendServerHelloAsHelloRetryRequest",
10617 config: Config{
10618 MaxVersion: VersionTLS12,
10619 Bugs: ProtocolBugs{
10620 SendServerHelloAsHelloRetryRequest: true,
10621 },
10622 },
10623 shouldFail: true,
10624 expectedError: ":UNEXPECTED_MESSAGE:",
10625 expectedLocalError: "remote error: unexpected message",
10626 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010627}
10628
David Benjamin639846e2016-09-09 11:41:18 -040010629func addTrailingMessageDataTests() {
10630 for _, t := range makePerMessageTests() {
10631 t.test.name = "TrailingMessageData-" + t.test.name
10632 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10633 t.test.shouldFail = true
10634 t.test.expectedError = ":DECODE_ERROR:"
10635 t.test.expectedLocalError = "remote error: error decoding message"
10636
10637 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10638 // In TLS 1.3, a bad ServerHello means the client sends
10639 // an unencrypted alert while the server expects
10640 // encryption, so the alert is not readable by runner.
10641 t.test.expectedLocalError = "local error: bad record MAC"
10642 }
10643
10644 if t.messageType == typeFinished {
10645 // Bad Finished messages read as the verify data having
10646 // the wrong length.
10647 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10648 t.test.expectedLocalError = "remote error: error decrypting message"
10649 }
10650
10651 testCases = append(testCases, t.test)
10652 }
10653}
10654
Steven Valdez143e8b32016-07-11 13:19:03 -040010655func addTLS13HandshakeTests() {
10656 testCases = append(testCases, testCase{
10657 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010658 name: "NegotiatePSKResumption-TLS13",
10659 config: Config{
10660 MaxVersion: VersionTLS13,
10661 Bugs: ProtocolBugs{
10662 NegotiatePSKResumption: true,
10663 },
10664 },
10665 resumeSession: true,
10666 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010667 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010668 })
10669
10670 testCases = append(testCases, testCase{
10671 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010672 name: "MissingKeyShare-Client",
10673 config: Config{
10674 MaxVersion: VersionTLS13,
10675 Bugs: ProtocolBugs{
10676 MissingKeyShare: true,
10677 },
10678 },
10679 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010680 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010681 })
10682
10683 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010684 testType: serverTest,
10685 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010686 config: Config{
10687 MaxVersion: VersionTLS13,
10688 Bugs: ProtocolBugs{
10689 MissingKeyShare: true,
10690 },
10691 },
10692 shouldFail: true,
10693 expectedError: ":MISSING_KEY_SHARE:",
10694 })
10695
10696 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010697 testType: serverTest,
10698 name: "DuplicateKeyShares",
10699 config: Config{
10700 MaxVersion: VersionTLS13,
10701 Bugs: ProtocolBugs{
10702 DuplicateKeyShares: true,
10703 },
10704 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010705 shouldFail: true,
10706 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010707 })
10708
Steven Valdezc7d4d212017-09-11 13:53:08 -040010709 for _, version := range allVersions(tls) {
10710 if version.version != VersionTLS13 {
10711 continue
10712 }
10713 name := version.name
10714 variant := version.tls13Variant
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010715
Steven Valdezc7d4d212017-09-11 13:53:08 -040010716 testCases = append(testCases, testCase{
10717 testType: serverTest,
10718 name: "SkipEarlyData-" + name,
10719 config: Config{
10720 MaxVersion: VersionTLS13,
10721 Bugs: ProtocolBugs{
10722 SendFakeEarlyDataLength: 4,
10723 },
Steven Valdez520e1222017-06-13 12:45:25 -040010724 },
Steven Valdezc7d4d212017-09-11 13:53:08 -040010725 tls13Variant: variant,
10726 })
Steven Valdez520e1222017-06-13 12:45:25 -040010727
Steven Valdezc7d4d212017-09-11 13:53:08 -040010728 // Test that enabling a TLS 1.3 variant does not interfere with
10729 // TLS 1.2 session ID resumption.
10730 testCases = append(testCases, testCase{
10731 testType: clientTest,
10732 name: "ResumeTLS12SessionID-" + name,
10733 config: Config{
10734 MaxVersion: VersionTLS12,
10735 SessionTicketsDisabled: true,
Steven Valdezdbe01582017-07-14 10:39:28 -040010736 },
Steven Valdezc7d4d212017-09-11 13:53:08 -040010737 tls13Variant: variant,
10738 resumeSession: true,
10739 })
10740
10741 // Test that the server correctly echoes back session IDs of
10742 // various lengths.
10743 testCases = append(testCases, testCase{
10744 testType: serverTest,
10745 name: "EmptySessionID-" + name,
10746 config: Config{
10747 MaxVersion: VersionTLS13,
10748 Bugs: ProtocolBugs{
10749 SendClientHelloSessionID: []byte{},
10750 },
10751 },
10752 tls13Variant: variant,
10753 })
10754
10755 testCases = append(testCases, testCase{
10756 testType: serverTest,
10757 name: "ShortSessionID-" + name,
10758 config: Config{
10759 MaxVersion: VersionTLS13,
10760 Bugs: ProtocolBugs{
10761 SendClientHelloSessionID: make([]byte, 16),
10762 },
10763 },
10764 tls13Variant: variant,
10765 })
10766
10767 testCases = append(testCases, testCase{
10768 testType: serverTest,
10769 name: "FullSessionID-" + name,
10770 config: Config{
10771 MaxVersion: VersionTLS13,
10772 Bugs: ProtocolBugs{
10773 SendClientHelloSessionID: make([]byte, 32),
10774 },
10775 },
10776 tls13Variant: variant,
10777 })
10778
10779 hasSessionID := false
Steven Valdez4c7f5fa2017-10-02 15:53:57 -040010780 if variant != TLS13Default {
Steven Valdezc7d4d212017-09-11 13:53:08 -040010781 hasSessionID = true
10782 }
10783
10784 // Test that the client sends a fake session ID in the correct experiments.
10785 testCases = append(testCases, testCase{
10786 testType: clientTest,
10787 name: "TLS13SessionID-" + name,
10788 config: Config{
10789 MaxVersion: VersionTLS13,
10790 Bugs: ProtocolBugs{
Steven Valdez4c7f5fa2017-10-02 15:53:57 -040010791 ExpectClientHelloSessionID: hasSessionID,
Steven Valdezc7d4d212017-09-11 13:53:08 -040010792 },
10793 },
10794 tls13Variant: variant,
10795 })
10796
10797 testCases = append(testCases, testCase{
10798 testType: clientTest,
10799 name: "EarlyData-Client-" + name,
10800 config: Config{
10801 MaxVersion: VersionTLS13,
10802 MinVersion: VersionTLS13,
10803 MaxEarlyDataSize: 16384,
10804 },
10805 resumeConfig: &Config{
10806 MaxVersion: VersionTLS13,
10807 MinVersion: VersionTLS13,
10808 MaxEarlyDataSize: 16384,
10809 Bugs: ProtocolBugs{
10810 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
10811 },
10812 },
10813 tls13Variant: variant,
10814 resumeSession: true,
10815 flags: []string{
10816 "-enable-early-data",
10817 "-expect-early-data-info",
10818 "-expect-accept-early-data",
10819 "-on-resume-shim-writes-first",
10820 },
10821 })
10822
10823 testCases = append(testCases, testCase{
10824 testType: clientTest,
10825 name: "EarlyData-Reject-Client-" + name,
10826 config: Config{
10827 MaxVersion: VersionTLS13,
10828 MaxEarlyDataSize: 16384,
10829 },
10830 resumeConfig: &Config{
10831 MaxVersion: VersionTLS13,
10832 MaxEarlyDataSize: 16384,
10833 Bugs: ProtocolBugs{
10834 AlwaysRejectEarlyData: true,
10835 },
10836 },
10837 tls13Variant: variant,
10838 resumeSession: true,
10839 flags: []string{
10840 "-enable-early-data",
10841 "-expect-early-data-info",
10842 "-expect-reject-early-data",
10843 "-on-resume-shim-writes-first",
10844 },
10845 })
10846
10847 testCases = append(testCases, testCase{
10848 testType: serverTest,
10849 name: "EarlyData-Server-" + name,
10850 config: Config{
10851 MaxVersion: VersionTLS13,
10852 MinVersion: VersionTLS13,
10853 Bugs: ProtocolBugs{
10854 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10855 ExpectEarlyDataAccepted: true,
10856 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10857 },
10858 },
10859 tls13Variant: variant,
10860 messageCount: 2,
10861 resumeSession: true,
10862 flags: []string{
10863 "-enable-early-data",
10864 "-expect-accept-early-data",
10865 },
10866 })
10867
10868 }
Steven Valdezdbe01582017-07-14 10:39:28 -040010869
10870 testCases = append(testCases, testCase{
10871 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010872 name: "SkipEarlyData-OmitEarlyDataExtension",
10873 config: Config{
10874 MaxVersion: VersionTLS13,
10875 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010876 SendFakeEarlyDataLength: 4,
10877 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010878 },
10879 },
10880 shouldFail: true,
10881 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10882 })
10883
10884 testCases = append(testCases, testCase{
10885 testType: serverTest,
10886 name: "SkipEarlyData-TooMuchData",
10887 config: Config{
10888 MaxVersion: VersionTLS13,
10889 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010890 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010891 },
10892 },
10893 shouldFail: true,
10894 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10895 })
10896
10897 testCases = append(testCases, testCase{
10898 testType: serverTest,
10899 name: "SkipEarlyData-Interleaved",
10900 config: Config{
10901 MaxVersion: VersionTLS13,
10902 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010903 SendFakeEarlyDataLength: 4,
10904 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010905 },
10906 },
10907 shouldFail: true,
10908 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10909 })
10910
10911 testCases = append(testCases, testCase{
10912 testType: serverTest,
10913 name: "SkipEarlyData-EarlyDataInTLS12",
10914 config: Config{
10915 MaxVersion: VersionTLS13,
10916 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010917 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010918 },
10919 },
10920 shouldFail: true,
10921 expectedError: ":UNEXPECTED_RECORD:",
10922 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10923 })
10924
10925 testCases = append(testCases, testCase{
10926 testType: serverTest,
10927 name: "SkipEarlyData-HRR",
10928 config: Config{
10929 MaxVersion: VersionTLS13,
10930 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010931 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010932 },
10933 DefaultCurves: []CurveID{},
10934 },
10935 })
10936
10937 testCases = append(testCases, testCase{
10938 testType: serverTest,
10939 name: "SkipEarlyData-HRR-Interleaved",
10940 config: Config{
10941 MaxVersion: VersionTLS13,
10942 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010943 SendFakeEarlyDataLength: 4,
10944 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010945 },
10946 DefaultCurves: []CurveID{},
10947 },
10948 shouldFail: true,
10949 expectedError: ":UNEXPECTED_RECORD:",
10950 })
10951
10952 testCases = append(testCases, testCase{
10953 testType: serverTest,
10954 name: "SkipEarlyData-HRR-TooMuchData",
10955 config: Config{
10956 MaxVersion: VersionTLS13,
10957 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010958 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010959 },
10960 DefaultCurves: []CurveID{},
10961 },
10962 shouldFail: true,
10963 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10964 })
10965
10966 // Test that skipping early data looking for cleartext correctly
10967 // processes an alert record.
10968 testCases = append(testCases, testCase{
10969 testType: serverTest,
10970 name: "SkipEarlyData-HRR-FatalAlert",
10971 config: Config{
10972 MaxVersion: VersionTLS13,
10973 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010974 SendEarlyAlert: true,
10975 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010976 },
10977 DefaultCurves: []CurveID{},
10978 },
10979 shouldFail: true,
10980 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10981 })
10982
10983 testCases = append(testCases, testCase{
10984 testType: serverTest,
10985 name: "SkipEarlyData-SecondClientHelloEarlyData",
10986 config: Config{
10987 MaxVersion: VersionTLS13,
10988 Bugs: ProtocolBugs{
10989 SendEarlyDataOnSecondClientHello: true,
10990 },
10991 DefaultCurves: []CurveID{},
10992 },
10993 shouldFail: true,
10994 expectedLocalError: "remote error: bad record MAC",
10995 })
10996
10997 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010998 testType: clientTest,
10999 name: "EmptyEncryptedExtensions",
11000 config: Config{
11001 MaxVersion: VersionTLS13,
11002 Bugs: ProtocolBugs{
11003 EmptyEncryptedExtensions: true,
11004 },
11005 },
11006 shouldFail: true,
11007 expectedLocalError: "remote error: error decoding message",
11008 })
11009
11010 testCases = append(testCases, testCase{
11011 testType: clientTest,
11012 name: "EncryptedExtensionsWithKeyShare",
11013 config: Config{
11014 MaxVersion: VersionTLS13,
11015 Bugs: ProtocolBugs{
11016 EncryptedExtensionsWithKeyShare: true,
11017 },
11018 },
11019 shouldFail: true,
11020 expectedLocalError: "remote error: unsupported extension",
11021 })
Steven Valdez5440fe02016-07-18 12:40:30 -040011022
11023 testCases = append(testCases, testCase{
11024 testType: serverTest,
11025 name: "SendHelloRetryRequest",
11026 config: Config{
11027 MaxVersion: VersionTLS13,
11028 // Require a HelloRetryRequest for every curve.
11029 DefaultCurves: []CurveID{},
11030 },
11031 expectedCurveID: CurveX25519,
11032 })
11033
11034 testCases = append(testCases, testCase{
11035 testType: serverTest,
11036 name: "SendHelloRetryRequest-2",
11037 config: Config{
11038 MaxVersion: VersionTLS13,
11039 DefaultCurves: []CurveID{CurveP384},
11040 },
11041 // Although the ClientHello did not predict our preferred curve,
11042 // we always select it whether it is predicted or not.
11043 expectedCurveID: CurveX25519,
11044 })
11045
11046 testCases = append(testCases, testCase{
11047 name: "UnknownCurve-HelloRetryRequest",
11048 config: Config{
11049 MaxVersion: VersionTLS13,
11050 // P-384 requires HelloRetryRequest in BoringSSL.
11051 CurvePreferences: []CurveID{CurveP384},
11052 Bugs: ProtocolBugs{
11053 SendHelloRetryRequestCurve: bogusCurve,
11054 },
11055 },
11056 shouldFail: true,
11057 expectedError: ":WRONG_CURVE:",
11058 })
11059
11060 testCases = append(testCases, testCase{
11061 name: "DisabledCurve-HelloRetryRequest",
11062 config: Config{
11063 MaxVersion: VersionTLS13,
11064 CurvePreferences: []CurveID{CurveP256},
11065 Bugs: ProtocolBugs{
11066 IgnorePeerCurvePreferences: true,
11067 },
11068 },
11069 flags: []string{"-p384-only"},
11070 shouldFail: true,
11071 expectedError: ":WRONG_CURVE:",
11072 })
11073
11074 testCases = append(testCases, testCase{
11075 name: "UnnecessaryHelloRetryRequest",
11076 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011077 MaxVersion: VersionTLS13,
11078 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011079 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011080 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011081 },
11082 },
11083 shouldFail: true,
11084 expectedError: ":WRONG_CURVE:",
11085 })
11086
11087 testCases = append(testCases, testCase{
11088 name: "SecondHelloRetryRequest",
11089 config: Config{
11090 MaxVersion: VersionTLS13,
11091 // P-384 requires HelloRetryRequest in BoringSSL.
11092 CurvePreferences: []CurveID{CurveP384},
11093 Bugs: ProtocolBugs{
11094 SecondHelloRetryRequest: true,
11095 },
11096 },
11097 shouldFail: true,
11098 expectedError: ":UNEXPECTED_MESSAGE:",
11099 })
11100
11101 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011102 name: "HelloRetryRequest-Empty",
11103 config: Config{
11104 MaxVersion: VersionTLS13,
11105 Bugs: ProtocolBugs{
11106 AlwaysSendHelloRetryRequest: true,
11107 },
11108 },
11109 shouldFail: true,
11110 expectedError: ":DECODE_ERROR:",
11111 })
11112
11113 testCases = append(testCases, testCase{
11114 name: "HelloRetryRequest-DuplicateCurve",
11115 config: Config{
11116 MaxVersion: VersionTLS13,
11117 // P-384 requires a HelloRetryRequest against BoringSSL's default
11118 // configuration. Assert this ExpectMissingKeyShare.
11119 CurvePreferences: []CurveID{CurveP384},
11120 Bugs: ProtocolBugs{
11121 ExpectMissingKeyShare: true,
11122 DuplicateHelloRetryRequestExtensions: true,
11123 },
11124 },
11125 shouldFail: true,
11126 expectedError: ":DUPLICATE_EXTENSION:",
11127 expectedLocalError: "remote error: illegal parameter",
11128 })
11129
11130 testCases = append(testCases, testCase{
11131 name: "HelloRetryRequest-Cookie",
11132 config: Config{
11133 MaxVersion: VersionTLS13,
11134 Bugs: ProtocolBugs{
11135 SendHelloRetryRequestCookie: []byte("cookie"),
11136 },
11137 },
11138 })
11139
11140 testCases = append(testCases, testCase{
11141 name: "HelloRetryRequest-DuplicateCookie",
11142 config: Config{
11143 MaxVersion: VersionTLS13,
11144 Bugs: ProtocolBugs{
11145 SendHelloRetryRequestCookie: []byte("cookie"),
11146 DuplicateHelloRetryRequestExtensions: true,
11147 },
11148 },
11149 shouldFail: true,
11150 expectedError: ":DUPLICATE_EXTENSION:",
11151 expectedLocalError: "remote error: illegal parameter",
11152 })
11153
11154 testCases = append(testCases, testCase{
11155 name: "HelloRetryRequest-EmptyCookie",
11156 config: Config{
11157 MaxVersion: VersionTLS13,
11158 Bugs: ProtocolBugs{
11159 SendHelloRetryRequestCookie: []byte{},
11160 },
11161 },
11162 shouldFail: true,
11163 expectedError: ":DECODE_ERROR:",
11164 })
11165
11166 testCases = append(testCases, testCase{
11167 name: "HelloRetryRequest-Cookie-Curve",
11168 config: Config{
11169 MaxVersion: VersionTLS13,
11170 // P-384 requires HelloRetryRequest in BoringSSL.
11171 CurvePreferences: []CurveID{CurveP384},
11172 Bugs: ProtocolBugs{
11173 SendHelloRetryRequestCookie: []byte("cookie"),
11174 ExpectMissingKeyShare: true,
11175 },
11176 },
11177 })
11178
11179 testCases = append(testCases, testCase{
11180 name: "HelloRetryRequest-Unknown",
11181 config: Config{
11182 MaxVersion: VersionTLS13,
11183 Bugs: ProtocolBugs{
11184 CustomHelloRetryRequestExtension: "extension",
11185 },
11186 },
11187 shouldFail: true,
11188 expectedError: ":UNEXPECTED_EXTENSION:",
11189 expectedLocalError: "remote error: unsupported extension",
11190 })
11191
11192 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011193 testType: serverTest,
11194 name: "SecondClientHelloMissingKeyShare",
11195 config: Config{
11196 MaxVersion: VersionTLS13,
11197 DefaultCurves: []CurveID{},
11198 Bugs: ProtocolBugs{
11199 SecondClientHelloMissingKeyShare: true,
11200 },
11201 },
11202 shouldFail: true,
11203 expectedError: ":MISSING_KEY_SHARE:",
11204 })
11205
11206 testCases = append(testCases, testCase{
11207 testType: serverTest,
11208 name: "SecondClientHelloWrongCurve",
11209 config: Config{
11210 MaxVersion: VersionTLS13,
11211 DefaultCurves: []CurveID{},
11212 Bugs: ProtocolBugs{
11213 MisinterpretHelloRetryRequestCurve: CurveP521,
11214 },
11215 },
11216 shouldFail: true,
11217 expectedError: ":WRONG_CURVE:",
11218 })
11219
11220 testCases = append(testCases, testCase{
11221 name: "HelloRetryRequestVersionMismatch",
11222 config: Config{
11223 MaxVersion: VersionTLS13,
11224 // P-384 requires HelloRetryRequest in BoringSSL.
11225 CurvePreferences: []CurveID{CurveP384},
11226 Bugs: ProtocolBugs{
11227 SendServerHelloVersion: 0x0305,
11228 },
11229 },
11230 shouldFail: true,
11231 expectedError: ":WRONG_VERSION_NUMBER:",
11232 })
11233
11234 testCases = append(testCases, testCase{
11235 name: "HelloRetryRequestCurveMismatch",
11236 config: Config{
11237 MaxVersion: VersionTLS13,
11238 // P-384 requires HelloRetryRequest in BoringSSL.
11239 CurvePreferences: []CurveID{CurveP384},
11240 Bugs: ProtocolBugs{
11241 // Send P-384 (correct) in the HelloRetryRequest.
11242 SendHelloRetryRequestCurve: CurveP384,
11243 // But send P-256 in the ServerHello.
11244 SendCurve: CurveP256,
11245 },
11246 },
11247 shouldFail: true,
11248 expectedError: ":WRONG_CURVE:",
11249 })
11250
11251 // Test the server selecting a curve that requires a HelloRetryRequest
11252 // without sending it.
11253 testCases = append(testCases, testCase{
11254 name: "SkipHelloRetryRequest",
11255 config: Config{
11256 MaxVersion: VersionTLS13,
11257 // P-384 requires HelloRetryRequest in BoringSSL.
11258 CurvePreferences: []CurveID{CurveP384},
11259 Bugs: ProtocolBugs{
11260 SkipHelloRetryRequest: true,
11261 },
11262 },
11263 shouldFail: true,
11264 expectedError: ":WRONG_CURVE:",
11265 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011266
11267 testCases = append(testCases, testCase{
11268 name: "TLS13-RequestContextInHandshake",
11269 config: Config{
11270 MaxVersion: VersionTLS13,
11271 MinVersion: VersionTLS13,
11272 ClientAuth: RequireAnyClientCert,
11273 Bugs: ProtocolBugs{
11274 SendRequestContext: []byte("request context"),
11275 },
11276 },
11277 flags: []string{
11278 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11279 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11280 },
11281 shouldFail: true,
11282 expectedError: ":DECODE_ERROR:",
11283 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011284
11285 testCases = append(testCases, testCase{
11286 testType: serverTest,
11287 name: "TLS13-TrailingKeyShareData",
11288 config: Config{
11289 MaxVersion: VersionTLS13,
11290 Bugs: ProtocolBugs{
11291 TrailingKeyShareData: true,
11292 },
11293 },
11294 shouldFail: true,
11295 expectedError: ":DECODE_ERROR:",
11296 })
David Benjamin7f78df42016-10-05 22:33:19 -040011297
11298 testCases = append(testCases, testCase{
11299 name: "TLS13-AlwaysSelectPSKIdentity",
11300 config: Config{
11301 MaxVersion: VersionTLS13,
11302 Bugs: ProtocolBugs{
11303 AlwaysSelectPSKIdentity: true,
11304 },
11305 },
11306 shouldFail: true,
11307 expectedError: ":UNEXPECTED_EXTENSION:",
11308 })
11309
11310 testCases = append(testCases, testCase{
11311 name: "TLS13-InvalidPSKIdentity",
11312 config: Config{
11313 MaxVersion: VersionTLS13,
11314 Bugs: ProtocolBugs{
11315 SelectPSKIdentityOnResume: 1,
11316 },
11317 },
11318 resumeSession: true,
11319 shouldFail: true,
11320 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11321 })
David Benjamin1286bee2016-10-07 15:25:06 -040011322
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011323 testCases = append(testCases, testCase{
11324 testType: serverTest,
11325 name: "TLS13-ExtraPSKIdentity",
11326 config: Config{
11327 MaxVersion: VersionTLS13,
11328 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011329 ExtraPSKIdentity: true,
11330 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011331 },
11332 },
11333 resumeSession: true,
11334 })
11335
David Benjamin1286bee2016-10-07 15:25:06 -040011336 // Test that unknown NewSessionTicket extensions are tolerated.
11337 testCases = append(testCases, testCase{
11338 name: "TLS13-CustomTicketExtension",
11339 config: Config{
11340 MaxVersion: VersionTLS13,
11341 Bugs: ProtocolBugs{
11342 CustomTicketExtension: "1234",
11343 },
11344 },
11345 })
Steven Valdezdbe01582017-07-14 10:39:28 -040011346 testCases = append(testCases, testCase{
11347 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011348 name: "TLS13-EarlyData-RejectTicket-Client",
11349 config: Config{
11350 MaxVersion: VersionTLS13,
11351 MaxEarlyDataSize: 16384,
11352 Certificates: []Certificate{rsaCertificate},
11353 },
11354 resumeConfig: &Config{
11355 MaxVersion: VersionTLS13,
11356 MaxEarlyDataSize: 16384,
11357 Certificates: []Certificate{ecdsaP256Certificate},
11358 SessionTicketsDisabled: true,
11359 },
11360 resumeSession: true,
11361 expectResumeRejected: true,
11362 flags: []string{
11363 "-enable-early-data",
11364 "-expect-early-data-info",
11365 "-expect-reject-early-data",
11366 "-on-resume-shim-writes-first",
11367 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11368 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11369 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11370 // Session tickets are disabled, so the runner will not send a ticket.
11371 "-on-retry-expect-no-session",
11372 },
11373 })
11374
11375 testCases = append(testCases, testCase{
11376 testType: clientTest,
11377 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011378 config: Config{
11379 MaxVersion: VersionTLS13,
11380 MaxEarlyDataSize: 16384,
11381 },
11382 resumeConfig: &Config{
11383 MaxVersion: VersionTLS13,
11384 MaxEarlyDataSize: 16384,
11385 Bugs: ProtocolBugs{
11386 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11387 },
11388 },
11389 resumeSession: true,
11390 flags: []string{
11391 "-enable-early-data",
11392 "-expect-early-data-info",
11393 "-expect-reject-early-data",
11394 },
11395 })
11396
11397 // The client must check the server does not send the early_data
11398 // extension while rejecting the session.
11399 testCases = append(testCases, testCase{
11400 testType: clientTest,
11401 name: "TLS13-EarlyDataWithoutResume-Client",
11402 config: Config{
11403 MaxVersion: VersionTLS13,
11404 MaxEarlyDataSize: 16384,
11405 },
11406 resumeConfig: &Config{
11407 MaxVersion: VersionTLS13,
11408 SessionTicketsDisabled: true,
11409 Bugs: ProtocolBugs{
11410 SendEarlyDataExtension: true,
11411 },
11412 },
11413 resumeSession: true,
11414 flags: []string{
11415 "-enable-early-data",
11416 "-expect-early-data-info",
11417 },
11418 shouldFail: true,
11419 expectedError: ":UNEXPECTED_EXTENSION:",
11420 })
11421
11422 // The client must fail with a dedicated error code if the server
11423 // responds with TLS 1.2 when offering 0-RTT.
11424 testCases = append(testCases, testCase{
11425 testType: clientTest,
11426 name: "TLS13-EarlyDataVersionDowngrade-Client",
11427 config: Config{
11428 MaxVersion: VersionTLS13,
11429 MaxEarlyDataSize: 16384,
11430 },
11431 resumeConfig: &Config{
11432 MaxVersion: VersionTLS12,
11433 },
11434 resumeSession: true,
11435 flags: []string{
11436 "-enable-early-data",
11437 "-expect-early-data-info",
11438 },
11439 shouldFail: true,
11440 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11441 })
11442
11443 // Test that the client rejects an (unsolicited) early_data extension if
11444 // the server sent an HRR.
11445 testCases = append(testCases, testCase{
11446 testType: clientTest,
11447 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11448 config: Config{
11449 MaxVersion: VersionTLS13,
11450 MaxEarlyDataSize: 16384,
11451 },
11452 resumeConfig: &Config{
11453 MaxVersion: VersionTLS13,
11454 MaxEarlyDataSize: 16384,
11455 Bugs: ProtocolBugs{
11456 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11457 SendEarlyDataExtension: true,
11458 },
11459 },
11460 resumeSession: true,
11461 flags: []string{
11462 "-enable-early-data",
11463 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011464 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011465 },
11466 shouldFail: true,
11467 expectedError: ":UNEXPECTED_EXTENSION:",
11468 })
11469
11470 fooString := "foo"
11471 barString := "bar"
11472
11473 // Test that the client reports the correct ALPN after a 0-RTT reject
11474 // that changed it.
11475 testCases = append(testCases, testCase{
11476 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011477 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011478 config: Config{
11479 MaxVersion: VersionTLS13,
11480 MaxEarlyDataSize: 16384,
11481 Bugs: ProtocolBugs{
11482 ALPNProtocol: &fooString,
11483 },
11484 },
11485 resumeConfig: &Config{
11486 MaxVersion: VersionTLS13,
11487 MaxEarlyDataSize: 16384,
11488 Bugs: ProtocolBugs{
11489 ALPNProtocol: &barString,
11490 },
11491 },
11492 resumeSession: true,
11493 flags: []string{
11494 "-advertise-alpn", "\x03foo\x03bar",
11495 "-enable-early-data",
11496 "-expect-early-data-info",
11497 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011498 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011499 "-on-resume-expect-alpn", "foo",
11500 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011501 },
11502 })
11503
11504 // Test that the client reports the correct ALPN after a 0-RTT reject if
11505 // ALPN was omitted from the first connection.
11506 testCases = append(testCases, testCase{
11507 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011508 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011509 config: Config{
11510 MaxVersion: VersionTLS13,
11511 MaxEarlyDataSize: 16384,
11512 },
11513 resumeConfig: &Config{
11514 MaxVersion: VersionTLS13,
11515 MaxEarlyDataSize: 16384,
11516 NextProtos: []string{"foo"},
11517 },
11518 resumeSession: true,
11519 flags: []string{
11520 "-advertise-alpn", "\x03foo\x03bar",
11521 "-enable-early-data",
11522 "-expect-early-data-info",
11523 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011524 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011525 "-on-resume-expect-alpn", "",
11526 "-on-retry-expect-alpn", "foo",
11527 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011528 },
11529 })
11530
11531 // Test that the client reports the correct ALPN after a 0-RTT reject if
11532 // ALPN was omitted from the second connection.
11533 testCases = append(testCases, testCase{
11534 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011535 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011536 config: Config{
11537 MaxVersion: VersionTLS13,
11538 MaxEarlyDataSize: 16384,
11539 NextProtos: []string{"foo"},
11540 },
11541 resumeConfig: &Config{
11542 MaxVersion: VersionTLS13,
11543 MaxEarlyDataSize: 16384,
11544 },
11545 resumeSession: true,
11546 flags: []string{
11547 "-advertise-alpn", "\x03foo\x03bar",
11548 "-enable-early-data",
11549 "-expect-early-data-info",
11550 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011551 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011552 "-on-resume-expect-alpn", "foo",
11553 "-on-retry-expect-alpn", "",
11554 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011555 },
11556 })
11557
11558 // Test that the client enforces ALPN match on 0-RTT accept.
11559 testCases = append(testCases, testCase{
11560 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011561 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011562 config: Config{
11563 MaxVersion: VersionTLS13,
11564 MaxEarlyDataSize: 16384,
11565 Bugs: ProtocolBugs{
11566 ALPNProtocol: &fooString,
11567 },
11568 },
11569 resumeConfig: &Config{
11570 MaxVersion: VersionTLS13,
11571 MaxEarlyDataSize: 16384,
11572 Bugs: ProtocolBugs{
11573 AlwaysAcceptEarlyData: true,
11574 ALPNProtocol: &barString,
11575 },
11576 },
11577 resumeSession: true,
11578 flags: []string{
11579 "-advertise-alpn", "\x03foo\x03bar",
11580 "-enable-early-data",
11581 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011582 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011583 "-on-resume-expect-alpn", "foo",
11584 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011585 },
11586 shouldFail: true,
11587 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11588 })
11589
11590 // Test that the server correctly rejects 0-RTT when the previous
11591 // session did not allow early data on resumption.
11592 testCases = append(testCases, testCase{
11593 testType: serverTest,
11594 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11595 config: Config{
11596 MaxVersion: VersionTLS13,
11597 },
11598 resumeConfig: &Config{
11599 MaxVersion: VersionTLS13,
11600 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011601 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011602 ExpectEarlyDataAccepted: false,
11603 },
11604 },
11605 resumeSession: true,
11606 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011607 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011608 "-expect-reject-early-data",
11609 },
11610 })
11611
11612 // Test that we reject early data where ALPN is omitted from the first
11613 // connection.
11614 testCases = append(testCases, testCase{
11615 testType: serverTest,
11616 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11617 config: Config{
11618 MaxVersion: VersionTLS13,
11619 NextProtos: []string{},
11620 },
11621 resumeConfig: &Config{
11622 MaxVersion: VersionTLS13,
11623 NextProtos: []string{"foo"},
11624 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011625 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011626 ExpectEarlyDataAccepted: false,
11627 },
11628 },
11629 resumeSession: true,
11630 flags: []string{
11631 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011632 "-on-initial-select-alpn", "",
11633 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011634 },
11635 })
11636
11637 // Test that we reject early data where ALPN is omitted from the second
11638 // connection.
11639 testCases = append(testCases, testCase{
11640 testType: serverTest,
11641 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11642 config: Config{
11643 MaxVersion: VersionTLS13,
11644 NextProtos: []string{"foo"},
11645 },
11646 resumeConfig: &Config{
11647 MaxVersion: VersionTLS13,
11648 NextProtos: []string{},
11649 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011650 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011651 ExpectEarlyDataAccepted: false,
11652 },
11653 },
11654 resumeSession: true,
11655 flags: []string{
11656 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011657 "-on-initial-select-alpn", "foo",
11658 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011659 },
11660 })
11661
11662 // Test that we reject early data with mismatched ALPN.
11663 testCases = append(testCases, testCase{
11664 testType: serverTest,
11665 name: "TLS13-EarlyData-ALPNMismatch-Server",
11666 config: Config{
11667 MaxVersion: VersionTLS13,
11668 NextProtos: []string{"foo"},
11669 },
11670 resumeConfig: &Config{
11671 MaxVersion: VersionTLS13,
11672 NextProtos: []string{"bar"},
11673 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011674 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011675 ExpectEarlyDataAccepted: false,
11676 },
11677 },
11678 resumeSession: true,
11679 flags: []string{
11680 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011681 "-on-initial-select-alpn", "foo",
11682 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011683 },
11684 })
11685
David Benjamin6bb507b2017-03-29 16:35:57 -050011686 // Test that the client offering 0-RTT and Channel ID forbids the server
11687 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011688 testCases = append(testCases, testCase{
11689 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011690 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011691 config: Config{
11692 MaxVersion: VersionTLS13,
11693 MaxEarlyDataSize: 16384,
11694 RequestChannelID: true,
11695 },
11696 resumeSession: true,
11697 expectChannelID: true,
11698 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011699 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011700 flags: []string{
11701 "-enable-early-data",
11702 "-expect-early-data-info",
11703 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11704 },
11705 })
11706
David Benjamin6bb507b2017-03-29 16:35:57 -050011707 // Test that the client offering Channel ID and 0-RTT allows the server
11708 // to decline 0-RTT.
11709 testCases = append(testCases, testCase{
11710 testType: clientTest,
11711 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11712 config: Config{
11713 MaxVersion: VersionTLS13,
11714 MaxEarlyDataSize: 16384,
11715 RequestChannelID: true,
11716 Bugs: ProtocolBugs{
11717 AlwaysRejectEarlyData: true,
11718 },
11719 },
11720 resumeSession: true,
11721 expectChannelID: true,
11722 flags: []string{
11723 "-enable-early-data",
11724 "-expect-early-data-info",
11725 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11726 "-expect-reject-early-data",
11727 },
11728 })
11729
11730 // Test that the client offering Channel ID and 0-RTT allows the server
11731 // to decline Channel ID.
11732 testCases = append(testCases, testCase{
11733 testType: clientTest,
11734 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11735 config: Config{
11736 MaxVersion: VersionTLS13,
11737 MaxEarlyDataSize: 16384,
11738 },
11739 resumeSession: true,
11740 flags: []string{
11741 "-enable-early-data",
11742 "-expect-early-data-info",
11743 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11744 "-expect-accept-early-data",
11745 },
11746 })
11747
11748 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11749 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011750 testCases = append(testCases, testCase{
11751 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011752 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011753 config: Config{
11754 MaxVersion: VersionTLS13,
11755 ChannelID: channelIDKey,
11756 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011757 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011758 ExpectEarlyDataAccepted: false,
11759 },
11760 },
11761 resumeSession: true,
11762 expectChannelID: true,
11763 flags: []string{
11764 "-enable-early-data",
11765 "-expect-reject-early-data",
11766 "-expect-channel-id",
11767 base64.StdEncoding.EncodeToString(channelIDBytes),
11768 },
11769 })
11770
David Benjamin6bb507b2017-03-29 16:35:57 -050011771 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11772 // if not offered Channel ID.
11773 testCases = append(testCases, testCase{
11774 testType: serverTest,
11775 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11776 config: Config{
11777 MaxVersion: VersionTLS13,
11778 Bugs: ProtocolBugs{
11779 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11780 ExpectEarlyDataAccepted: true,
11781 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11782 },
11783 },
11784 resumeSession: true,
11785 expectChannelID: false,
11786 flags: []string{
11787 "-enable-early-data",
11788 "-expect-accept-early-data",
11789 "-enable-channel-id",
11790 },
11791 })
11792
David Benjamin32c89272017-03-26 13:54:21 -050011793 // Test that the server rejects 0-RTT streams without end_of_early_data.
11794 // The subsequent records should fail to decrypt.
11795 testCases = append(testCases, testCase{
11796 testType: serverTest,
11797 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11798 config: Config{
11799 MaxVersion: VersionTLS13,
11800 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011801 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011802 ExpectEarlyDataAccepted: true,
11803 SkipEndOfEarlyData: true,
11804 },
11805 },
11806 resumeSession: true,
11807 flags: []string{"-enable-early-data"},
11808 shouldFail: true,
11809 expectedLocalError: "remote error: bad record MAC",
11810 expectedError: ":BAD_DECRYPT:",
11811 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011812
11813 testCases = append(testCases, testCase{
11814 testType: serverTest,
11815 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11816 config: Config{
11817 MaxVersion: VersionTLS13,
11818 },
11819 resumeConfig: &Config{
11820 MaxVersion: VersionTLS13,
11821 Bugs: ProtocolBugs{
11822 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11823 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011824 ExpectEarlyDataAccepted: true,
11825 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011826 },
11827 resumeSession: true,
11828 shouldFail: true,
11829 expectedError: ":UNEXPECTED_RECORD:",
11830 expectedLocalError: "remote error: unexpected message",
11831 flags: []string{
11832 "-enable-early-data",
11833 },
11834 })
David Benjamind9cbb532017-07-07 13:17:19 -040011835
11836 // Test that the client reports TLS 1.3 as the version while sending
11837 // early data.
11838 testCases = append(testCases, testCase{
11839 testType: clientTest,
11840 name: "TLS13-EarlyData-Client-VersionAPI",
11841 config: Config{
11842 MaxVersion: VersionTLS13,
11843 MaxEarlyDataSize: 16384,
11844 },
11845 resumeSession: true,
11846 flags: []string{
11847 "-enable-early-data",
11848 "-expect-early-data-info",
11849 "-expect-accept-early-data",
11850 "-expect-version", strconv.Itoa(VersionTLS13),
11851 },
11852 })
David Benjamin4a37de02017-08-08 20:15:40 -040011853
11854 // Test that client and server both notice handshake errors after data
11855 // has started flowing.
11856 testCases = append(testCases, testCase{
11857 testType: clientTest,
11858 name: "TLS13-EarlyData-Client-BadFinished",
11859 config: Config{
11860 MaxVersion: VersionTLS13,
11861 MaxEarlyDataSize: 16384,
11862 },
11863 resumeConfig: &Config{
11864 MaxVersion: VersionTLS13,
11865 MaxEarlyDataSize: 16384,
11866 Bugs: ProtocolBugs{
11867 BadFinished: true,
11868 },
11869 },
11870 resumeSession: true,
11871 flags: []string{
11872 "-enable-early-data",
11873 "-expect-early-data-info",
11874 "-expect-accept-early-data",
11875 },
11876 shouldFail: true,
11877 expectedError: ":DIGEST_CHECK_FAILED:",
11878 expectedLocalError: "remote error: error decrypting message",
11879 })
11880 testCases = append(testCases, testCase{
11881 testType: serverTest,
11882 name: "TLS13-EarlyData-Server-BadFinished",
11883 config: Config{
11884 MaxVersion: VersionTLS13,
11885 MaxEarlyDataSize: 16384,
11886 },
11887 resumeConfig: &Config{
11888 MaxVersion: VersionTLS13,
11889 MaxEarlyDataSize: 16384,
11890 Bugs: ProtocolBugs{
11891 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11892 ExpectEarlyDataAccepted: true,
11893 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11894 BadFinished: true,
11895 },
11896 },
11897 resumeSession: true,
11898 flags: []string{
11899 "-enable-early-data",
11900 "-expect-accept-early-data",
11901 },
11902 shouldFail: true,
11903 expectedError: ":DIGEST_CHECK_FAILED:",
11904 expectedLocalError: "remote error: error decrypting message",
11905 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020011906 testCases = append(testCases, testCase{
11907 testType: serverTest,
11908 name: "TLS13-ServerSkipCertificateVerify",
11909 config: Config{
11910 MinVersion: VersionTLS13,
11911 MaxVersion: VersionTLS13,
11912 Certificates: []Certificate{rsaChainCertificate},
11913 Bugs: ProtocolBugs{
11914 SkipCertificateVerify: true,
11915 },
11916 },
11917 expectPeerCertificate: &rsaChainCertificate,
11918 flags: []string{
11919 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11920 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11921 "-require-any-client-certificate",
11922 },
11923 shouldFail: true,
11924 expectedError: ":UNEXPECTED_MESSAGE:",
11925 expectedLocalError: "remote error: unexpected message",
11926 })
11927 testCases = append(testCases, testCase{
11928 testType: clientTest,
11929 name: "TLS13-ClientSkipCertificateVerify",
11930 config: Config{
11931 MinVersion: VersionTLS13,
11932 MaxVersion: VersionTLS13,
11933 Certificates: []Certificate{rsaChainCertificate},
11934 Bugs: ProtocolBugs{
11935 SkipCertificateVerify: true,
11936 },
11937 },
11938 expectPeerCertificate: &rsaChainCertificate,
11939 flags: []string{
11940 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11941 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11942 },
11943 shouldFail: true,
11944 expectedError: ":UNEXPECTED_MESSAGE:",
11945 expectedLocalError: "remote error: unexpected message",
11946 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011947}
11948
David Benjaminabbbee12016-10-31 19:20:42 -040011949func addTLS13CipherPreferenceTests() {
11950 // Test that client preference is honored if the shim has AES hardware
11951 // and ChaCha20-Poly1305 is preferred otherwise.
11952 testCases = append(testCases, testCase{
11953 testType: serverTest,
11954 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11955 config: Config{
11956 MaxVersion: VersionTLS13,
11957 CipherSuites: []uint16{
11958 TLS_CHACHA20_POLY1305_SHA256,
11959 TLS_AES_128_GCM_SHA256,
11960 },
11961 },
11962 flags: []string{
11963 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11964 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11965 },
11966 })
11967
11968 testCases = append(testCases, testCase{
11969 testType: serverTest,
11970 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11971 config: Config{
11972 MaxVersion: VersionTLS13,
11973 CipherSuites: []uint16{
11974 TLS_AES_128_GCM_SHA256,
11975 TLS_CHACHA20_POLY1305_SHA256,
11976 },
11977 },
11978 flags: []string{
11979 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11980 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11981 },
11982 })
11983
11984 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11985 // whether it has AES hardware.
11986 testCases = append(testCases, testCase{
11987 name: "TLS13-CipherPreference-Client",
11988 config: Config{
11989 MaxVersion: VersionTLS13,
11990 // Use the client cipher order. (This is the default but
11991 // is listed to be explicit.)
11992 PreferServerCipherSuites: false,
11993 },
11994 flags: []string{
11995 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11996 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11997 },
11998 })
11999}
12000
David Benjaminf3fbade2016-09-19 13:08:16 -040012001func addPeekTests() {
12002 // Test SSL_peek works, including on empty records.
12003 testCases = append(testCases, testCase{
12004 name: "Peek-Basic",
12005 sendEmptyRecords: 1,
12006 flags: []string{"-peek-then-read"},
12007 })
12008
12009 // Test SSL_peek can drive the initial handshake.
12010 testCases = append(testCases, testCase{
12011 name: "Peek-ImplicitHandshake",
12012 flags: []string{
12013 "-peek-then-read",
12014 "-implicit-handshake",
12015 },
12016 })
12017
12018 // Test SSL_peek can discover and drive a renegotiation.
12019 testCases = append(testCases, testCase{
12020 name: "Peek-Renegotiate",
12021 config: Config{
12022 MaxVersion: VersionTLS12,
12023 },
12024 renegotiate: 1,
12025 flags: []string{
12026 "-peek-then-read",
12027 "-renegotiate-freely",
12028 "-expect-total-renegotiations", "1",
12029 },
12030 })
12031
12032 // Test SSL_peek can discover a close_notify.
12033 testCases = append(testCases, testCase{
12034 name: "Peek-Shutdown",
12035 config: Config{
12036 Bugs: ProtocolBugs{
12037 ExpectCloseNotify: true,
12038 },
12039 },
12040 flags: []string{
12041 "-peek-then-read",
12042 "-check-close-notify",
12043 },
12044 })
12045
12046 // Test SSL_peek can discover an alert.
12047 testCases = append(testCases, testCase{
12048 name: "Peek-Alert",
12049 config: Config{
12050 Bugs: ProtocolBugs{
12051 SendSpuriousAlert: alertRecordOverflow,
12052 },
12053 },
12054 flags: []string{"-peek-then-read"},
12055 shouldFail: true,
12056 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12057 })
12058
12059 // Test SSL_peek can handle KeyUpdate.
12060 testCases = append(testCases, testCase{
12061 name: "Peek-KeyUpdate",
12062 config: Config{
12063 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012064 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012065 sendKeyUpdates: 1,
12066 keyUpdateRequest: keyUpdateNotRequested,
12067 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012068 })
12069}
12070
David Benjamine6f22212016-11-08 14:28:24 -050012071func addRecordVersionTests() {
12072 for _, ver := range tlsVersions {
12073 // Test that the record version is enforced.
12074 testCases = append(testCases, testCase{
12075 name: "CheckRecordVersion-" + ver.name,
12076 config: Config{
12077 MinVersion: ver.version,
12078 MaxVersion: ver.version,
12079 Bugs: ProtocolBugs{
12080 SendRecordVersion: 0x03ff,
12081 },
12082 },
David Benjamina5022392017-07-10 17:40:39 -040012083 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012084 shouldFail: true,
12085 expectedError: ":WRONG_VERSION_NUMBER:",
12086 })
12087
12088 // Test that the ClientHello may use any record version, for
12089 // compatibility reasons.
12090 testCases = append(testCases, testCase{
12091 testType: serverTest,
12092 name: "LooseInitialRecordVersion-" + ver.name,
12093 config: Config{
12094 MinVersion: ver.version,
12095 MaxVersion: ver.version,
12096 Bugs: ProtocolBugs{
12097 SendInitialRecordVersion: 0x03ff,
12098 },
12099 },
David Benjamina5022392017-07-10 17:40:39 -040012100 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012101 })
12102
12103 // Test that garbage ClientHello record versions are rejected.
12104 testCases = append(testCases, testCase{
12105 testType: serverTest,
12106 name: "GarbageInitialRecordVersion-" + ver.name,
12107 config: Config{
12108 MinVersion: ver.version,
12109 MaxVersion: ver.version,
12110 Bugs: ProtocolBugs{
12111 SendInitialRecordVersion: 0xffff,
12112 },
12113 },
David Benjamina5022392017-07-10 17:40:39 -040012114 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012115 shouldFail: true,
12116 expectedError: ":WRONG_VERSION_NUMBER:",
12117 })
12118 }
12119}
12120
David Benjamin2c516452016-11-15 10:16:54 +090012121func addCertificateTests() {
David Benjamin2c516452016-11-15 10:16:54 +090012122 for _, ver := range tlsVersions {
David Benjamin3969fdf2017-08-29 15:50:58 -040012123 // Test that a certificate chain with intermediate may be sent
12124 // and received as both client and server.
David Benjamin2c516452016-11-15 10:16:54 +090012125 testCases = append(testCases, testCase{
12126 testType: clientTest,
12127 name: "SendReceiveIntermediate-Client-" + ver.name,
12128 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012129 MinVersion: ver.version,
12130 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012131 Certificates: []Certificate{rsaChainCertificate},
12132 ClientAuth: RequireAnyClientCert,
12133 },
David Benjamina5022392017-07-10 17:40:39 -040012134 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012135 expectPeerCertificate: &rsaChainCertificate,
12136 flags: []string{
12137 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12138 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12139 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12140 },
12141 })
12142
12143 testCases = append(testCases, testCase{
12144 testType: serverTest,
12145 name: "SendReceiveIntermediate-Server-" + ver.name,
12146 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012147 MinVersion: ver.version,
12148 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012149 Certificates: []Certificate{rsaChainCertificate},
12150 },
David Benjamina5022392017-07-10 17:40:39 -040012151 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012152 expectPeerCertificate: &rsaChainCertificate,
12153 flags: []string{
12154 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12155 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12156 "-require-any-client-certificate",
12157 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12158 },
12159 })
David Benjamin3969fdf2017-08-29 15:50:58 -040012160
12161 // Test that garbage leaf certificates are properly rejected.
12162 testCases = append(testCases, testCase{
12163 testType: clientTest,
12164 name: "GarbageCertificate-Client-" + ver.name,
12165 config: Config{
12166 MinVersion: ver.version,
12167 MaxVersion: ver.version,
12168 Certificates: []Certificate{garbageCertificate},
12169 },
12170 tls13Variant: ver.tls13Variant,
12171 shouldFail: true,
12172 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12173 expectedLocalError: "remote error: error decoding message",
12174 })
12175
12176 testCases = append(testCases, testCase{
12177 testType: serverTest,
12178 name: "GarbageCertificate-Server-" + ver.name,
12179 config: Config{
12180 MinVersion: ver.version,
12181 MaxVersion: ver.version,
12182 Certificates: []Certificate{garbageCertificate},
12183 },
12184 tls13Variant: ver.tls13Variant,
12185 flags: []string{"-require-any-client-certificate"},
12186 shouldFail: true,
12187 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12188 expectedLocalError: "remote error: error decoding message",
12189 })
David Benjamin2c516452016-11-15 10:16:54 +090012190 }
12191}
12192
David Benjaminbbaf3672016-11-17 10:53:09 +090012193func addRetainOnlySHA256ClientCertTests() {
12194 for _, ver := range tlsVersions {
12195 // Test that enabling
12196 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12197 // actually requesting a client certificate is a no-op.
12198 testCases = append(testCases, testCase{
12199 testType: serverTest,
12200 name: "RetainOnlySHA256-NoCert-" + ver.name,
12201 config: Config{
12202 MinVersion: ver.version,
12203 MaxVersion: ver.version,
12204 },
David Benjamina5022392017-07-10 17:40:39 -040012205 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012206 flags: []string{
David Benjaminf2165072017-08-23 23:01:37 -070012207 "-on-initial-retain-only-sha256-client-cert",
12208 "-on-resume-retain-only-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012209 },
12210 resumeSession: true,
12211 })
12212
12213 // Test that when retaining only a SHA-256 certificate is
12214 // enabled, the hash appears as expected.
12215 testCases = append(testCases, testCase{
12216 testType: serverTest,
12217 name: "RetainOnlySHA256-Cert-" + ver.name,
12218 config: Config{
12219 MinVersion: ver.version,
12220 MaxVersion: ver.version,
12221 Certificates: []Certificate{rsaCertificate},
12222 },
David Benjamina5022392017-07-10 17:40:39 -040012223 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012224 flags: []string{
12225 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012226 "-on-initial-retain-only-sha256-client-cert",
12227 "-on-resume-retain-only-sha256-client-cert",
12228 "-on-initial-expect-sha256-client-cert",
12229 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012230 },
12231 resumeSession: true,
12232 })
12233
12234 // Test that when the config changes from on to off, a
12235 // resumption is rejected because the server now wants the full
12236 // certificate chain.
12237 testCases = append(testCases, testCase{
12238 testType: serverTest,
12239 name: "RetainOnlySHA256-OnOff-" + ver.name,
12240 config: Config{
12241 MinVersion: ver.version,
12242 MaxVersion: ver.version,
12243 Certificates: []Certificate{rsaCertificate},
12244 },
David Benjamina5022392017-07-10 17:40:39 -040012245 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012246 flags: []string{
12247 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012248 "-on-initial-retain-only-sha256-client-cert",
12249 "-on-initial-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012250 },
12251 resumeSession: true,
12252 expectResumeRejected: true,
12253 })
12254
12255 // Test that when the config changes from off to on, a
12256 // resumption is rejected because the server now wants just the
12257 // hash.
12258 testCases = append(testCases, testCase{
12259 testType: serverTest,
12260 name: "RetainOnlySHA256-OffOn-" + ver.name,
12261 config: Config{
12262 MinVersion: ver.version,
12263 MaxVersion: ver.version,
12264 Certificates: []Certificate{rsaCertificate},
12265 },
David Benjamina5022392017-07-10 17:40:39 -040012266 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012267 flags: []string{
12268 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012269 "-on-resume-retain-only-sha256-client-cert",
12270 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012271 },
12272 resumeSession: true,
12273 expectResumeRejected: true,
12274 })
12275 }
12276}
12277
Adam Langleya4b91982016-12-12 12:05:53 -080012278func addECDSAKeyUsageTests() {
12279 p256 := elliptic.P256()
12280 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12281 if err != nil {
12282 panic(err)
12283 }
12284
12285 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12286 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12287 if err != nil {
12288 panic(err)
12289 }
12290
12291 template := x509.Certificate{
12292 SerialNumber: serialNumber,
12293 Subject: pkix.Name{
12294 Organization: []string{"Acme Co"},
12295 },
12296 NotBefore: time.Now(),
12297 NotAfter: time.Now(),
12298
12299 // An ECC certificate with only the keyAgreement key usgae may
12300 // be used with ECDH, but not ECDSA.
12301 KeyUsage: x509.KeyUsageKeyAgreement,
12302 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12303 BasicConstraintsValid: true,
12304 }
12305
12306 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12307 if err != nil {
12308 panic(err)
12309 }
12310
12311 cert := Certificate{
12312 Certificate: [][]byte{derBytes},
12313 PrivateKey: priv,
12314 }
12315
12316 for _, ver := range tlsVersions {
12317 if ver.version < VersionTLS12 {
12318 continue
12319 }
12320
12321 testCases = append(testCases, testCase{
12322 testType: clientTest,
12323 name: "ECDSAKeyUsage-" + ver.name,
12324 config: Config{
12325 MinVersion: ver.version,
12326 MaxVersion: ver.version,
12327 Certificates: []Certificate{cert},
12328 },
David Benjamina5022392017-07-10 17:40:39 -040012329 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012330 shouldFail: true,
12331 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12332 })
12333 }
12334}
12335
David Benjamin8c26d752017-03-26 15:13:51 -050012336func addExtraHandshakeTests() {
12337 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12338 // to ensure there is no transport I/O.
12339 testCases = append(testCases, testCase{
12340 testType: clientTest,
12341 name: "ExtraHandshake-Client-TLS12",
12342 config: Config{
12343 MinVersion: VersionTLS12,
12344 MaxVersion: VersionTLS12,
12345 },
12346 flags: []string{
12347 "-async",
12348 "-no-op-extra-handshake",
12349 },
12350 })
12351 testCases = append(testCases, testCase{
12352 testType: serverTest,
12353 name: "ExtraHandshake-Server-TLS12",
12354 config: Config{
12355 MinVersion: VersionTLS12,
12356 MaxVersion: VersionTLS12,
12357 },
12358 flags: []string{
12359 "-async",
12360 "-no-op-extra-handshake",
12361 },
12362 })
12363 testCases = append(testCases, testCase{
12364 testType: clientTest,
12365 name: "ExtraHandshake-Client-TLS13",
12366 config: Config{
12367 MinVersion: VersionTLS13,
12368 MaxVersion: VersionTLS13,
12369 },
12370 flags: []string{
12371 "-async",
12372 "-no-op-extra-handshake",
12373 },
12374 })
12375 testCases = append(testCases, testCase{
12376 testType: serverTest,
12377 name: "ExtraHandshake-Server-TLS13",
12378 config: Config{
12379 MinVersion: VersionTLS13,
12380 MaxVersion: VersionTLS13,
12381 },
12382 flags: []string{
12383 "-async",
12384 "-no-op-extra-handshake",
12385 },
12386 })
12387
12388 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12389 testCases = append(testCases, testCase{
12390 testType: serverTest,
12391 name: "ExtraHandshake-Server-EarlyData-TLS13",
12392 config: Config{
12393 MaxVersion: VersionTLS13,
12394 MinVersion: VersionTLS13,
12395 Bugs: ProtocolBugs{
12396 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12397 ExpectEarlyDataAccepted: true,
12398 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12399 },
12400 },
12401 messageCount: 2,
12402 resumeSession: true,
12403 flags: []string{
12404 "-async",
12405 "-enable-early-data",
12406 "-expect-accept-early-data",
12407 "-no-op-extra-handshake",
12408 },
12409 })
12410
12411 // An extra SSL_do_handshake drives the handshake to completion in False
12412 // Start. We test this by handshaking twice and asserting the False
12413 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12414 // how the test works.
12415 testCases = append(testCases, testCase{
12416 testType: clientTest,
12417 name: "ExtraHandshake-FalseStart",
12418 config: Config{
12419 MaxVersion: VersionTLS12,
12420 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12421 NextProtos: []string{"foo"},
12422 Bugs: ProtocolBugs{
12423 ExpectFalseStart: true,
12424 AlertBeforeFalseStartTest: alertAccessDenied,
12425 },
12426 },
12427 flags: []string{
12428 "-handshake-twice",
12429 "-false-start",
12430 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012431 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012432 },
12433 shimWritesFirst: true,
12434 shouldFail: true,
12435 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12436 expectedLocalError: "tls: peer did not false start: EOF",
12437 })
12438}
12439
David Benjaminb853f312017-07-14 18:40:34 -040012440// Test that omitted and empty extensions blocks are tolerated.
12441func addOmitExtensionsTests() {
David Benjamin0a471912017-08-31 00:19:57 -040012442 // Check the ExpectOmitExtensions setting works.
12443 testCases = append(testCases, testCase{
12444 testType: serverTest,
12445 name: "ExpectOmitExtensions",
12446 config: Config{
12447 MinVersion: VersionTLS12,
12448 MaxVersion: VersionTLS12,
12449 Bugs: ProtocolBugs{
12450 ExpectOmitExtensions: true,
12451 },
12452 },
12453 shouldFail: true,
12454 expectedLocalError: "tls: ServerHello did not omit extensions",
12455 })
12456
David Benjaminb853f312017-07-14 18:40:34 -040012457 for _, ver := range tlsVersions {
12458 if ver.version > VersionTLS12 {
12459 continue
12460 }
12461
12462 testCases = append(testCases, testCase{
12463 testType: serverTest,
12464 name: "OmitExtensions-ClientHello-" + ver.name,
12465 config: Config{
12466 MinVersion: ver.version,
12467 MaxVersion: ver.version,
12468 SessionTicketsDisabled: true,
12469 Bugs: ProtocolBugs{
12470 OmitExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012471 // With no client extensions, the ServerHello must not have
12472 // extensions. It should then omit the extensions field.
12473 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012474 },
12475 },
12476 })
12477
12478 testCases = append(testCases, testCase{
12479 testType: serverTest,
12480 name: "EmptyExtensions-ClientHello-" + ver.name,
12481 config: Config{
12482 MinVersion: ver.version,
12483 MaxVersion: ver.version,
12484 SessionTicketsDisabled: true,
12485 Bugs: ProtocolBugs{
12486 EmptyExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012487 // With no client extensions, the ServerHello must not have
12488 // extensions. It should then omit the extensions field.
12489 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012490 },
12491 },
12492 })
12493
12494 testCases = append(testCases, testCase{
12495 testType: clientTest,
12496 name: "OmitExtensions-ServerHello-" + ver.name,
12497 config: Config{
12498 MinVersion: ver.version,
12499 MaxVersion: ver.version,
12500 SessionTicketsDisabled: true,
12501 Bugs: ProtocolBugs{
12502 OmitExtensions: true,
12503 // Disable all ServerHello extensions so
12504 // OmitExtensions works.
12505 NoExtendedMasterSecret: true,
12506 NoRenegotiationInfo: true,
12507 },
12508 },
12509 })
12510
12511 testCases = append(testCases, testCase{
12512 testType: clientTest,
12513 name: "EmptyExtensions-ServerHello-" + ver.name,
12514 config: Config{
12515 MinVersion: ver.version,
12516 MaxVersion: ver.version,
12517 SessionTicketsDisabled: true,
12518 Bugs: ProtocolBugs{
12519 EmptyExtensions: true,
12520 // Disable all ServerHello extensions so
12521 // EmptyExtensions works.
12522 NoExtendedMasterSecret: true,
12523 NoRenegotiationInfo: true,
12524 },
12525 },
12526 })
12527 }
12528}
12529
Adam Langley7c803a62015-06-15 15:35:05 -070012530func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012531 defer wg.Done()
12532
12533 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012534 var err error
12535
David Benjaminba28dfc2016-11-15 17:47:21 +090012536 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012537 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12538 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012539 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012540 if err != nil {
12541 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12542 }
12543 break
12544 }
12545 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012546 } else if *repeatUntilFailure {
12547 for err == nil {
12548 statusChan <- statusMsg{test: test, started: true}
12549 err = runTest(test, shimPath, -1)
12550 }
12551 } else {
12552 statusChan <- statusMsg{test: test, started: true}
12553 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012554 }
Adam Langley95c29f32014-06-20 12:00:00 -070012555 statusChan <- statusMsg{test: test, err: err}
12556 }
12557}
12558
12559type statusMsg struct {
12560 test *testCase
12561 started bool
12562 err error
12563}
12564
David Benjamin5f237bc2015-02-11 17:14:15 -050012565func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012566 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012567
David Benjamin5f237bc2015-02-11 17:14:15 -050012568 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012569 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012570 if !*pipe {
12571 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012572 var erase string
12573 for i := 0; i < lineLen; i++ {
12574 erase += "\b \b"
12575 }
12576 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012577 }
12578
Adam Langley95c29f32014-06-20 12:00:00 -070012579 if msg.started {
12580 started++
12581 } else {
12582 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012583
12584 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012585 if msg.err == errUnimplemented {
12586 if *pipe {
12587 // Print each test instead of a status line.
12588 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12589 }
12590 unimplemented++
12591 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12592 } else {
12593 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12594 failed++
12595 testOutput.addResult(msg.test.name, "FAIL")
12596 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012597 } else {
12598 if *pipe {
12599 // Print each test instead of a status line.
12600 fmt.Printf("PASSED (%s)\n", msg.test.name)
12601 }
12602 testOutput.addResult(msg.test.name, "PASS")
12603 }
Adam Langley95c29f32014-06-20 12:00:00 -070012604 }
12605
David Benjamin5f237bc2015-02-11 17:14:15 -050012606 if !*pipe {
12607 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012608 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012609 lineLen = len(line)
12610 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012611 }
Adam Langley95c29f32014-06-20 12:00:00 -070012612 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012613
12614 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012615}
12616
12617func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012618 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012619 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012620 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012621
Adam Langley7c803a62015-06-15 15:35:05 -070012622 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012623 addCipherSuiteTests()
12624 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012625 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012626 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012627 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012628 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012629 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012630 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012631 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012632 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012633 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012634 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012635 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012636 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012637 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012638 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012639 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012640 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012641 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012642 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012643 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012644 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012645 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012646 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012647 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012648 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012649 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012650 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012651 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012652 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012653 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012654 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012655 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012656 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012657 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012658
12659 var wg sync.WaitGroup
12660
Adam Langley7c803a62015-06-15 15:35:05 -070012661 statusChan := make(chan statusMsg, *numWorkers)
12662 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012663 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012664
EKRf71d7ed2016-08-06 13:25:12 -070012665 if len(*shimConfigFile) != 0 {
12666 encoded, err := ioutil.ReadFile(*shimConfigFile)
12667 if err != nil {
12668 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12669 os.Exit(1)
12670 }
12671
12672 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12673 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12674 os.Exit(1)
12675 }
12676 }
12677
David Benjamin025b3d32014-07-01 19:53:04 -040012678 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012679
Adam Langley7c803a62015-06-15 15:35:05 -070012680 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012681 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012682 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012683 }
12684
David Benjamin270f0a72016-03-17 14:41:36 -040012685 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012686 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012687 matched := true
12688 if len(*testToRun) != 0 {
12689 var err error
12690 matched, err = filepath.Match(*testToRun, testCases[i].name)
12691 if err != nil {
12692 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12693 os.Exit(1)
12694 }
12695 }
12696
EKRf71d7ed2016-08-06 13:25:12 -070012697 if !*includeDisabled {
12698 for pattern := range shimConfig.DisabledTests {
12699 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12700 if err != nil {
12701 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12702 os.Exit(1)
12703 }
12704
12705 if isDisabled {
12706 matched = false
12707 break
12708 }
12709 }
12710 }
12711
David Benjamin17e12922016-07-28 18:04:43 -040012712 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012713 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012714 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012715
12716 // Only run one test if repeating until failure.
12717 if *repeatUntilFailure {
12718 break
12719 }
Adam Langley95c29f32014-06-20 12:00:00 -070012720 }
12721 }
David Benjamin17e12922016-07-28 18:04:43 -040012722
David Benjamin270f0a72016-03-17 14:41:36 -040012723 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012724 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012725 os.Exit(1)
12726 }
Adam Langley95c29f32014-06-20 12:00:00 -070012727
12728 close(testChan)
12729 wg.Wait()
12730 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012731 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012732
12733 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012734
12735 if *jsonOutput != "" {
12736 if err := testOutput.writeTo(*jsonOutput); err != nil {
12737 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12738 }
12739 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012740
EKR842ae6c2016-07-27 09:22:05 +020012741 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12742 os.Exit(1)
12743 }
12744
12745 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012746 os.Exit(1)
12747 }
Adam Langley95c29f32014-06-20 12:00:00 -070012748}