blob: 5918e6b35cbd01296856c9dd3ddff5add55f1587 [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 Benjamin861f28a2017-10-06 13:10:45 -04001148 var childErr error
1149 if *useGDB {
1150 childErr = <-waitChan
1151 } else {
1152 var shimKilledLock sync.Mutex
1153 var shimKilled bool
1154 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1155 shimKilledLock.Lock()
1156 shimKilled = true
1157 shimKilledLock.Unlock()
1158 shim.Process.Kill()
1159 })
1160 childErr = <-waitChan
1161 waitTimeout.Stop()
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001162 shimKilledLock.Lock()
David Benjamin861f28a2017-10-06 13:10:45 -04001163 if shimKilled && err == nil {
1164 err = errors.New("timeout waiting for the shim to exit.")
1165 }
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001166 shimKilledLock.Unlock()
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001167 }
David Benjamin861f28a2017-10-06 13:10:45 -04001168
David Benjamind2ba8892016-09-20 19:41:04 -04001169 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001170 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001171 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1172 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001173 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001174 case 89:
1175 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001176 case 99:
1177 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001178 }
1179 }
Adam Langley95c29f32014-06-20 12:00:00 -07001180
David Benjamin9bea3492016-03-02 10:59:16 -05001181 // Account for Windows line endings.
1182 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1183 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001184
1185 // Separate the errors from the shim and those from tools like
1186 // AddressSanitizer.
1187 var extraStderr string
1188 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1189 stderr = stderrParts[0]
1190 extraStderr = stderrParts[1]
1191 }
1192
Adam Langley95c29f32014-06-20 12:00:00 -07001193 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001194 expectedError := translateExpectedError(test.expectedError)
1195 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001196
Adam Langleyac61fa32014-06-23 12:03:11 -07001197 localError := "none"
1198 if err != nil {
1199 localError = err.Error()
1200 }
1201 if len(test.expectedLocalError) != 0 {
1202 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1203 }
Adam Langley95c29f32014-06-20 12:00:00 -07001204
1205 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001206 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001207 if childErr != nil {
1208 childError = childErr.Error()
1209 }
1210
1211 var msg string
1212 switch {
1213 case failed && !test.shouldFail:
1214 msg = "unexpected failure"
1215 case !failed && test.shouldFail:
1216 msg = "unexpected success"
1217 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001218 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001219 default:
1220 panic("internal error")
1221 }
1222
David Benjamin9aafb642016-09-20 19:36:53 -04001223 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 -07001224 }
1225
David Benjamind2ba8892016-09-20 19:41:04 -04001226 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001227 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001228 }
1229
David Benjamind2ba8892016-09-20 19:41:04 -04001230 if *useValgrind && isValgrindError {
1231 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1232 }
1233
Adam Langley95c29f32014-06-20 12:00:00 -07001234 return nil
1235}
1236
David Benjaminaa012042016-12-10 13:33:05 -05001237type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001238 name string
1239 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001240 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001241 // excludeFlag is the legacy shim flag to disable the version.
1242 excludeFlag string
1243 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001244 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1245 versionDTLS uint16
1246 // versionWire, if non-zero, is the wire representation of the
1247 // version. Otherwise the wire version is the protocol version or
1248 // versionDTLS.
1249 versionWire uint16
1250 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001251}
1252
1253func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001254 // The shim uses the protocol version in its public API, but uses the
1255 // DTLS-specific version if it exists.
1256 if protocol == dtls && vers.versionDTLS != 0 {
1257 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001258 }
Steven Valdez520e1222017-06-13 12:45:25 -04001259 return strconv.Itoa(int(vers.version))
1260}
1261
1262func (vers tlsVersion) wire(protocol protocol) uint16 {
1263 if protocol == dtls && vers.versionDTLS != 0 {
1264 return vers.versionDTLS
1265 }
1266 if vers.versionWire != 0 {
1267 return vers.versionWire
1268 }
1269 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001270}
1271
1272var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001273 {
1274 name: "SSL3",
1275 version: VersionSSL30,
1276 excludeFlag: "-no-ssl3",
1277 },
1278 {
1279 name: "TLS1",
1280 version: VersionTLS10,
1281 excludeFlag: "-no-tls1",
1282 hasDTLS: true,
1283 versionDTLS: VersionDTLS10,
1284 },
1285 {
1286 name: "TLS11",
1287 version: VersionTLS11,
1288 excludeFlag: "-no-tls11",
1289 },
1290 {
1291 name: "TLS12",
1292 version: VersionTLS12,
1293 excludeFlag: "-no-tls12",
1294 hasDTLS: true,
1295 versionDTLS: VersionDTLS12,
1296 },
1297 {
1298 name: "TLS13",
1299 version: VersionTLS13,
1300 excludeFlag: "-no-tls13",
1301 versionWire: tls13DraftVersion,
1302 tls13Variant: TLS13Default,
1303 },
1304 {
1305 name: "TLS13Experiment",
1306 version: VersionTLS13,
1307 excludeFlag: "-no-tls13",
1308 versionWire: tls13ExperimentVersion,
1309 tls13Variant: TLS13Experiment,
1310 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001311 {
Steven Valdez16821262017-09-08 17:03:42 -04001312 name: "TLS13Experiment2",
1313 version: VersionTLS13,
1314 excludeFlag: "-no-tls13",
1315 versionWire: tls13Experiment2Version,
1316 tls13Variant: TLS13Experiment2,
1317 },
1318 {
Steven Valdezc7d4d212017-09-11 13:53:08 -04001319 name: "TLS13Experiment3",
1320 version: VersionTLS13,
1321 excludeFlag: "-no-tls13",
1322 versionWire: tls13Experiment3Version,
1323 tls13Variant: TLS13Experiment3,
1324 },
Steven Valdez520e1222017-06-13 12:45:25 -04001325}
1326
1327func allVersions(protocol protocol) []tlsVersion {
1328 if protocol == tls {
1329 return tlsVersions
1330 }
1331
1332 var ret []tlsVersion
1333 for _, vers := range tlsVersions {
1334 if vers.hasDTLS {
1335 ret = append(ret, vers)
1336 }
1337 }
1338 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001339}
1340
David Benjaminaa012042016-12-10 13:33:05 -05001341type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001342 name string
1343 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001344}
1345
1346var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001347 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001348 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001349 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001350 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001351 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001352 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001353 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001354 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1355 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001356 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1357 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001358 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001359 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001360 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001361 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001362 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001363 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001364 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001365 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001366 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001367 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001368 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1369 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001370 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1371 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001372 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001373 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1374 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1375 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001376 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001377}
1378
David Benjamin8b8c0062014-11-23 02:47:52 -05001379func hasComponent(suiteName, component string) bool {
1380 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1381}
1382
David Benjaminf7768e42014-08-31 02:06:47 -04001383func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001384 return hasComponent(suiteName, "GCM") ||
1385 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001386 hasComponent(suiteName, "SHA384") ||
1387 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001388}
1389
Nick Harper1fd39d82016-06-14 18:14:35 -07001390func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001391 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001392}
1393
David Benjamin8b8c0062014-11-23 02:47:52 -05001394func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001395 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001396}
1397
Adam Langleya7997f12015-05-14 17:38:50 -07001398func bigFromHex(hex string) *big.Int {
1399 ret, ok := new(big.Int).SetString(hex, 16)
1400 if !ok {
1401 panic("failed to parse hex number 0x" + hex)
1402 }
1403 return ret
1404}
1405
Adam Langley7c803a62015-06-15 15:35:05 -07001406func addBasicTests() {
1407 basicTests := []testCase{
1408 {
Adam Langley7c803a62015-06-15 15:35:05 -07001409 name: "NoFallbackSCSV",
1410 config: Config{
1411 Bugs: ProtocolBugs{
1412 FailIfNotFallbackSCSV: true,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedLocalError: "no fallback SCSV found",
1417 },
1418 {
1419 name: "SendFallbackSCSV",
1420 config: Config{
1421 Bugs: ProtocolBugs{
1422 FailIfNotFallbackSCSV: true,
1423 },
1424 },
1425 flags: []string{"-fallback-scsv"},
1426 },
1427 {
1428 name: "ClientCertificateTypes",
1429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001430 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001431 ClientAuth: RequestClientCert,
1432 ClientCertificateTypes: []byte{
1433 CertTypeDSSSign,
1434 CertTypeRSASign,
1435 CertTypeECDSASign,
1436 },
1437 },
1438 flags: []string{
1439 "-expect-certificate-types",
1440 base64.StdEncoding.EncodeToString([]byte{
1441 CertTypeDSSSign,
1442 CertTypeRSASign,
1443 CertTypeECDSASign,
1444 }),
1445 },
1446 },
1447 {
Adam Langley7c803a62015-06-15 15:35:05 -07001448 name: "UnauthenticatedECDH",
1449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001450 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Bugs: ProtocolBugs{
1453 UnauthenticatedECDH: true,
1454 },
1455 },
1456 shouldFail: true,
1457 expectedError: ":UNEXPECTED_MESSAGE:",
1458 },
1459 {
1460 name: "SkipCertificateStatus",
1461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001462 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001463 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1464 Bugs: ProtocolBugs{
1465 SkipCertificateStatus: true,
1466 },
1467 },
1468 flags: []string{
1469 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001470 // This test involves an optional message. Test the message callback
1471 // trace to ensure we do not miss or double-report any.
1472 "-expect-msg-callback",
1473 `write hs 1
1474read hs 2
1475read hs 11
1476read hs 12
1477read hs 14
1478write hs 16
1479write ccs
1480write hs 20
1481read hs 4
1482read ccs
1483read hs 20
1484read alert 1 0
1485`,
1486 },
1487 },
1488 {
1489 protocol: dtls,
1490 name: "SkipCertificateStatus-DTLS",
1491 config: Config{
1492 MaxVersion: VersionTLS12,
1493 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1494 Bugs: ProtocolBugs{
1495 SkipCertificateStatus: true,
1496 },
1497 },
1498 flags: []string{
1499 "-enable-ocsp-stapling",
1500 // This test involves an optional message. Test the message callback
1501 // trace to ensure we do not miss or double-report any.
1502 "-expect-msg-callback",
1503 `write hs 1
1504read hs 3
1505write hs 1
1506read hs 2
1507read hs 11
1508read hs 12
1509read hs 14
1510write hs 16
1511write ccs
1512write hs 20
1513read hs 4
1514read ccs
1515read hs 20
1516read alert 1 0
1517`,
Adam Langley7c803a62015-06-15 15:35:05 -07001518 },
1519 },
1520 {
1521 name: "SkipServerKeyExchange",
1522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001523 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1525 Bugs: ProtocolBugs{
1526 SkipServerKeyExchange: true,
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_MESSAGE:",
1531 },
1532 {
Adam Langley7c803a62015-06-15 15:35:05 -07001533 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001534 name: "ServerSkipCertificateVerify",
1535 config: Config{
1536 MaxVersion: VersionTLS12,
1537 Certificates: []Certificate{rsaChainCertificate},
1538 Bugs: ProtocolBugs{
1539 SkipCertificateVerify: true,
1540 },
1541 },
1542 expectPeerCertificate: &rsaChainCertificate,
1543 flags: []string{
1544 "-require-any-client-certificate",
1545 },
1546 shouldFail: true,
1547 expectedError: ":UNEXPECTED_RECORD:",
1548 expectedLocalError: "remote error: unexpected message",
1549 },
1550 {
1551 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001552 name: "Alert",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 SendSpuriousAlert: alertRecordOverflow,
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1560 },
1561 {
1562 protocol: dtls,
1563 testType: serverTest,
1564 name: "Alert-DTLS",
1565 config: Config{
1566 Bugs: ProtocolBugs{
1567 SendSpuriousAlert: alertRecordOverflow,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1572 },
1573 {
1574 testType: serverTest,
1575 name: "FragmentAlert",
1576 config: Config{
1577 Bugs: ProtocolBugs{
1578 FragmentAlert: true,
1579 SendSpuriousAlert: alertRecordOverflow,
1580 },
1581 },
1582 shouldFail: true,
1583 expectedError: ":BAD_ALERT:",
1584 },
1585 {
1586 protocol: dtls,
1587 testType: serverTest,
1588 name: "FragmentAlert-DTLS",
1589 config: Config{
1590 Bugs: ProtocolBugs{
1591 FragmentAlert: true,
1592 SendSpuriousAlert: alertRecordOverflow,
1593 },
1594 },
1595 shouldFail: true,
1596 expectedError: ":BAD_ALERT:",
1597 },
1598 {
1599 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001600 name: "DoubleAlert",
1601 config: Config{
1602 Bugs: ProtocolBugs{
1603 DoubleAlert: true,
1604 SendSpuriousAlert: alertRecordOverflow,
1605 },
1606 },
1607 shouldFail: true,
1608 expectedError: ":BAD_ALERT:",
1609 },
1610 {
1611 protocol: dtls,
1612 testType: serverTest,
1613 name: "DoubleAlert-DTLS",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 DoubleAlert: true,
1617 SendSpuriousAlert: alertRecordOverflow,
1618 },
1619 },
1620 shouldFail: true,
1621 expectedError: ":BAD_ALERT:",
1622 },
1623 {
Adam Langley7c803a62015-06-15 15:35:05 -07001624 name: "SkipNewSessionTicket",
1625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001626 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001627 Bugs: ProtocolBugs{
1628 SkipNewSessionTicket: true,
1629 },
1630 },
1631 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001632 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001633 },
1634 {
1635 testType: serverTest,
1636 name: "FallbackSCSV",
1637 config: Config{
1638 MaxVersion: VersionTLS11,
1639 Bugs: ProtocolBugs{
1640 SendFallbackSCSV: true,
1641 },
1642 },
David Benjamin56cadc32016-12-16 19:54:11 -05001643 shouldFail: true,
1644 expectedError: ":INAPPROPRIATE_FALLBACK:",
1645 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001646 },
1647 {
1648 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001649 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001650 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001651 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001652 Bugs: ProtocolBugs{
1653 SendFallbackSCSV: true,
1654 },
1655 },
1656 },
1657 {
1658 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001659 name: "FallbackSCSV-VersionMatch-TLS12",
1660 config: Config{
1661 MaxVersion: VersionTLS12,
1662 Bugs: ProtocolBugs{
1663 SendFallbackSCSV: true,
1664 },
1665 },
1666 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1667 },
1668 {
1669 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001670 name: "FragmentedClientVersion",
1671 config: Config{
1672 Bugs: ProtocolBugs{
1673 MaxHandshakeRecordLength: 1,
1674 FragmentClientVersion: true,
1675 },
1676 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001677 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001678 },
1679 {
Adam Langley7c803a62015-06-15 15:35:05 -07001680 testType: serverTest,
1681 name: "HttpGET",
1682 sendPrefix: "GET / HTTP/1.0\n",
1683 shouldFail: true,
1684 expectedError: ":HTTP_REQUEST:",
1685 },
1686 {
1687 testType: serverTest,
1688 name: "HttpPOST",
1689 sendPrefix: "POST / HTTP/1.0\n",
1690 shouldFail: true,
1691 expectedError: ":HTTP_REQUEST:",
1692 },
1693 {
1694 testType: serverTest,
1695 name: "HttpHEAD",
1696 sendPrefix: "HEAD / HTTP/1.0\n",
1697 shouldFail: true,
1698 expectedError: ":HTTP_REQUEST:",
1699 },
1700 {
1701 testType: serverTest,
1702 name: "HttpPUT",
1703 sendPrefix: "PUT / HTTP/1.0\n",
1704 shouldFail: true,
1705 expectedError: ":HTTP_REQUEST:",
1706 },
1707 {
1708 testType: serverTest,
1709 name: "HttpCONNECT",
1710 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1711 shouldFail: true,
1712 expectedError: ":HTTPS_PROXY_REQUEST:",
1713 },
1714 {
1715 testType: serverTest,
1716 name: "Garbage",
1717 sendPrefix: "blah",
1718 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001719 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001720 },
1721 {
Adam Langley7c803a62015-06-15 15:35:05 -07001722 name: "RSAEphemeralKey",
1723 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001724 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001725 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1726 Bugs: ProtocolBugs{
1727 RSAEphemeralKey: true,
1728 },
1729 },
1730 shouldFail: true,
1731 expectedError: ":UNEXPECTED_MESSAGE:",
1732 },
1733 {
1734 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001735 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001736 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001737 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001738 },
1739 {
1740 protocol: dtls,
1741 name: "DisableEverything-DTLS",
1742 flags: []string{"-no-tls12", "-no-tls1"},
1743 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001744 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001745 },
1746 {
Adam Langley7c803a62015-06-15 15:35:05 -07001747 protocol: dtls,
1748 testType: serverTest,
1749 name: "MTU",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 MaxPacketLength: 256,
1753 },
1754 },
1755 flags: []string{"-mtu", "256"},
1756 },
1757 {
1758 protocol: dtls,
1759 testType: serverTest,
1760 name: "MTUExceeded",
1761 config: Config{
1762 Bugs: ProtocolBugs{
1763 MaxPacketLength: 255,
1764 },
1765 },
1766 flags: []string{"-mtu", "256"},
1767 shouldFail: true,
1768 expectedLocalError: "dtls: exceeded maximum packet length",
1769 },
1770 {
Adam Langley7c803a62015-06-15 15:35:05 -07001771 name: "EmptyCertificateList",
1772 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001773 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001774 Bugs: ProtocolBugs{
1775 EmptyCertificateList: true,
1776 },
1777 },
1778 shouldFail: true,
1779 expectedError: ":DECODE_ERROR:",
1780 },
1781 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001782 name: "EmptyCertificateList-TLS13",
1783 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001784 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001785 Bugs: ProtocolBugs{
1786 EmptyCertificateList: true,
1787 },
1788 },
1789 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001790 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001791 },
1792 {
Adam Langley7c803a62015-06-15 15:35:05 -07001793 name: "TLSFatalBadPackets",
1794 damageFirstWrite: true,
1795 shouldFail: true,
1796 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1797 },
1798 {
1799 protocol: dtls,
1800 name: "DTLSIgnoreBadPackets",
1801 damageFirstWrite: true,
1802 },
1803 {
1804 protocol: dtls,
1805 name: "DTLSIgnoreBadPackets-Async",
1806 damageFirstWrite: true,
1807 flags: []string{"-async"},
1808 },
1809 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001810 name: "AppDataBeforeHandshake",
1811 config: Config{
1812 Bugs: ProtocolBugs{
1813 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1814 },
1815 },
1816 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001817 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001818 },
1819 {
1820 name: "AppDataBeforeHandshake-Empty",
1821 config: Config{
1822 Bugs: ProtocolBugs{
1823 AppDataBeforeHandshake: []byte{},
1824 },
1825 },
1826 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001827 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001828 },
1829 {
1830 protocol: dtls,
1831 name: "AppDataBeforeHandshake-DTLS",
1832 config: Config{
1833 Bugs: ProtocolBugs{
1834 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1835 },
1836 },
1837 shouldFail: true,
1838 expectedError: ":UNEXPECTED_RECORD:",
1839 },
1840 {
1841 protocol: dtls,
1842 name: "AppDataBeforeHandshake-DTLS-Empty",
1843 config: Config{
1844 Bugs: ProtocolBugs{
1845 AppDataBeforeHandshake: []byte{},
1846 },
1847 },
1848 shouldFail: true,
1849 expectedError: ":UNEXPECTED_RECORD:",
1850 },
1851 {
Adam Langley7c803a62015-06-15 15:35:05 -07001852 name: "AppDataAfterChangeCipherSpec",
1853 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001854 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001855 Bugs: ProtocolBugs{
1856 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1857 },
1858 },
1859 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001860 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001861 },
1862 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001863 name: "AppDataAfterChangeCipherSpec-Empty",
1864 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001865 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001866 Bugs: ProtocolBugs{
1867 AppDataAfterChangeCipherSpec: []byte{},
1868 },
1869 },
1870 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001871 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001872 },
1873 {
Adam Langley7c803a62015-06-15 15:35:05 -07001874 protocol: dtls,
1875 name: "AppDataAfterChangeCipherSpec-DTLS",
1876 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001877 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001878 Bugs: ProtocolBugs{
1879 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1880 },
1881 },
1882 // BoringSSL's DTLS implementation will drop the out-of-order
1883 // application data.
1884 },
1885 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001886 protocol: dtls,
1887 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001889 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001890 Bugs: ProtocolBugs{
1891 AppDataAfterChangeCipherSpec: []byte{},
1892 },
1893 },
1894 // BoringSSL's DTLS implementation will drop the out-of-order
1895 // application data.
1896 },
1897 {
Adam Langley7c803a62015-06-15 15:35:05 -07001898 name: "AlertAfterChangeCipherSpec",
1899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001900 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001901 Bugs: ProtocolBugs{
1902 AlertAfterChangeCipherSpec: alertRecordOverflow,
1903 },
1904 },
1905 shouldFail: true,
1906 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1907 },
1908 {
1909 protocol: dtls,
1910 name: "AlertAfterChangeCipherSpec-DTLS",
1911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001912 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001913 Bugs: ProtocolBugs{
1914 AlertAfterChangeCipherSpec: alertRecordOverflow,
1915 },
1916 },
1917 shouldFail: true,
1918 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1919 },
1920 {
1921 protocol: dtls,
1922 name: "ReorderHandshakeFragments-Small-DTLS",
1923 config: Config{
1924 Bugs: ProtocolBugs{
1925 ReorderHandshakeFragments: true,
1926 // Small enough that every handshake message is
1927 // fragmented.
1928 MaxHandshakeRecordLength: 2,
1929 },
1930 },
1931 },
1932 {
1933 protocol: dtls,
1934 name: "ReorderHandshakeFragments-Large-DTLS",
1935 config: Config{
1936 Bugs: ProtocolBugs{
1937 ReorderHandshakeFragments: true,
1938 // Large enough that no handshake message is
1939 // fragmented.
1940 MaxHandshakeRecordLength: 2048,
1941 },
1942 },
1943 },
1944 {
1945 protocol: dtls,
1946 name: "MixCompleteMessageWithFragments-DTLS",
1947 config: Config{
1948 Bugs: ProtocolBugs{
1949 ReorderHandshakeFragments: true,
1950 MixCompleteMessageWithFragments: true,
1951 MaxHandshakeRecordLength: 2,
1952 },
1953 },
1954 },
1955 {
1956 name: "SendInvalidRecordType",
1957 config: Config{
1958 Bugs: ProtocolBugs{
1959 SendInvalidRecordType: true,
1960 },
1961 },
1962 shouldFail: true,
1963 expectedError: ":UNEXPECTED_RECORD:",
1964 },
1965 {
1966 protocol: dtls,
1967 name: "SendInvalidRecordType-DTLS",
1968 config: Config{
1969 Bugs: ProtocolBugs{
1970 SendInvalidRecordType: true,
1971 },
1972 },
1973 shouldFail: true,
1974 expectedError: ":UNEXPECTED_RECORD:",
1975 },
1976 {
1977 name: "FalseStart-SkipServerSecondLeg",
1978 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001979 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001980 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1981 NextProtos: []string{"foo"},
1982 Bugs: ProtocolBugs{
1983 SkipNewSessionTicket: true,
1984 SkipChangeCipherSpec: true,
1985 SkipFinished: true,
1986 ExpectFalseStart: true,
1987 },
1988 },
1989 flags: []string{
1990 "-false-start",
1991 "-handshake-never-done",
1992 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001993 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001994 },
1995 shimWritesFirst: true,
1996 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001997 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001998 },
1999 {
2000 name: "FalseStart-SkipServerSecondLeg-Implicit",
2001 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002002 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2004 NextProtos: []string{"foo"},
2005 Bugs: ProtocolBugs{
2006 SkipNewSessionTicket: true,
2007 SkipChangeCipherSpec: true,
2008 SkipFinished: true,
2009 },
2010 },
2011 flags: []string{
2012 "-implicit-handshake",
2013 "-false-start",
2014 "-handshake-never-done",
2015 "-advertise-alpn", "\x03foo",
2016 },
2017 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04002018 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002019 },
2020 {
2021 testType: serverTest,
2022 name: "FailEarlyCallback",
2023 flags: []string{"-fail-early-callback"},
2024 shouldFail: true,
2025 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002026 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002027 },
2028 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002029 name: "FailCertCallback-Client-TLS12",
2030 config: Config{
2031 MaxVersion: VersionTLS12,
2032 ClientAuth: RequestClientCert,
2033 },
2034 flags: []string{"-fail-cert-callback"},
2035 shouldFail: true,
2036 expectedError: ":CERT_CB_ERROR:",
2037 expectedLocalError: "remote error: internal error",
2038 },
2039 {
2040 testType: serverTest,
2041 name: "FailCertCallback-Server-TLS12",
2042 config: Config{
2043 MaxVersion: VersionTLS12,
2044 },
2045 flags: []string{"-fail-cert-callback"},
2046 shouldFail: true,
2047 expectedError: ":CERT_CB_ERROR:",
2048 expectedLocalError: "remote error: internal error",
2049 },
2050 {
2051 name: "FailCertCallback-Client-TLS13",
2052 config: Config{
2053 MaxVersion: VersionTLS13,
2054 ClientAuth: RequestClientCert,
2055 },
2056 flags: []string{"-fail-cert-callback"},
2057 shouldFail: true,
2058 expectedError: ":CERT_CB_ERROR:",
2059 expectedLocalError: "remote error: internal error",
2060 },
2061 {
2062 testType: serverTest,
2063 name: "FailCertCallback-Server-TLS13",
2064 config: Config{
2065 MaxVersion: VersionTLS13,
2066 },
2067 flags: []string{"-fail-cert-callback"},
2068 shouldFail: true,
2069 expectedError: ":CERT_CB_ERROR:",
2070 expectedLocalError: "remote error: internal error",
2071 },
2072 {
Adam Langley7c803a62015-06-15 15:35:05 -07002073 protocol: dtls,
2074 name: "FragmentMessageTypeMismatch-DTLS",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 MaxHandshakeRecordLength: 2,
2078 FragmentMessageTypeMismatch: true,
2079 },
2080 },
2081 shouldFail: true,
2082 expectedError: ":FRAGMENT_MISMATCH:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "FragmentMessageLengthMismatch-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 MaxHandshakeRecordLength: 2,
2090 FragmentMessageLengthMismatch: true,
2091 },
2092 },
2093 shouldFail: true,
2094 expectedError: ":FRAGMENT_MISMATCH:",
2095 },
2096 {
2097 protocol: dtls,
2098 name: "SplitFragments-Header-DTLS",
2099 config: Config{
2100 Bugs: ProtocolBugs{
2101 SplitFragments: 2,
2102 },
2103 },
2104 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002105 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002106 },
2107 {
2108 protocol: dtls,
2109 name: "SplitFragments-Boundary-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SplitFragments: dtlsRecordHeaderLen,
2113 },
2114 },
2115 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002116 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002117 },
2118 {
2119 protocol: dtls,
2120 name: "SplitFragments-Body-DTLS",
2121 config: Config{
2122 Bugs: ProtocolBugs{
2123 SplitFragments: dtlsRecordHeaderLen + 1,
2124 },
2125 },
2126 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002127 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002128 },
2129 {
2130 protocol: dtls,
2131 name: "SendEmptyFragments-DTLS",
2132 config: Config{
2133 Bugs: ProtocolBugs{
2134 SendEmptyFragments: true,
2135 },
2136 },
2137 },
2138 {
David Benjamine51fb0f2017-09-07 11:51:46 -04002139 testType: serverTest,
2140 protocol: dtls,
2141 name: "SendEmptyFragments-Padded-DTLS",
2142 config: Config{
2143 Bugs: ProtocolBugs{
2144 // Test empty fragments for a message with a
2145 // nice power-of-two length.
2146 PadClientHello: 64,
2147 SendEmptyFragments: true,
2148 },
2149 },
2150 },
2151 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002152 name: "BadFinished-Client",
2153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002154 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002155 Bugs: ProtocolBugs{
2156 BadFinished: true,
2157 },
2158 },
2159 shouldFail: true,
2160 expectedError: ":DIGEST_CHECK_FAILED:",
2161 },
2162 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002163 name: "BadFinished-Client-TLS13",
2164 config: Config{
2165 MaxVersion: VersionTLS13,
2166 Bugs: ProtocolBugs{
2167 BadFinished: true,
2168 },
2169 },
2170 shouldFail: true,
2171 expectedError: ":DIGEST_CHECK_FAILED:",
2172 },
2173 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002174 testType: serverTest,
2175 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002177 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002178 Bugs: ProtocolBugs{
2179 BadFinished: true,
2180 },
2181 },
2182 shouldFail: true,
2183 expectedError: ":DIGEST_CHECK_FAILED:",
2184 },
2185 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002186 testType: serverTest,
2187 name: "BadFinished-Server-TLS13",
2188 config: Config{
2189 MaxVersion: VersionTLS13,
2190 Bugs: ProtocolBugs{
2191 BadFinished: true,
2192 },
2193 },
2194 shouldFail: true,
2195 expectedError: ":DIGEST_CHECK_FAILED:",
2196 },
2197 {
Adam Langley7c803a62015-06-15 15:35:05 -07002198 name: "FalseStart-BadFinished",
2199 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002200 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002201 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2202 NextProtos: []string{"foo"},
2203 Bugs: ProtocolBugs{
2204 BadFinished: true,
2205 ExpectFalseStart: true,
2206 },
2207 },
2208 flags: []string{
2209 "-false-start",
2210 "-handshake-never-done",
2211 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002212 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002213 },
2214 shimWritesFirst: true,
2215 shouldFail: true,
2216 expectedError: ":DIGEST_CHECK_FAILED:",
2217 },
2218 {
2219 name: "NoFalseStart-NoALPN",
2220 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002221 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002222 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2223 Bugs: ProtocolBugs{
2224 ExpectFalseStart: true,
2225 AlertBeforeFalseStartTest: alertAccessDenied,
2226 },
2227 },
2228 flags: []string{
2229 "-false-start",
2230 },
2231 shimWritesFirst: true,
2232 shouldFail: true,
2233 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2234 expectedLocalError: "tls: peer did not false start: EOF",
2235 },
2236 {
2237 name: "NoFalseStart-NoAEAD",
2238 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002239 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002240 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2241 NextProtos: []string{"foo"},
2242 Bugs: ProtocolBugs{
2243 ExpectFalseStart: true,
2244 AlertBeforeFalseStartTest: alertAccessDenied,
2245 },
2246 },
2247 flags: []string{
2248 "-false-start",
2249 "-advertise-alpn", "\x03foo",
2250 },
2251 shimWritesFirst: true,
2252 shouldFail: true,
2253 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2254 expectedLocalError: "tls: peer did not false start: EOF",
2255 },
2256 {
2257 name: "NoFalseStart-RSA",
2258 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002260 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2261 NextProtos: []string{"foo"},
2262 Bugs: ProtocolBugs{
2263 ExpectFalseStart: true,
2264 AlertBeforeFalseStartTest: alertAccessDenied,
2265 },
2266 },
2267 flags: []string{
2268 "-false-start",
2269 "-advertise-alpn", "\x03foo",
2270 },
2271 shimWritesFirst: true,
2272 shouldFail: true,
2273 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2274 expectedLocalError: "tls: peer did not false start: EOF",
2275 },
2276 {
Adam Langley7c803a62015-06-15 15:35:05 -07002277 protocol: dtls,
2278 name: "SendSplitAlert-Sync",
2279 config: Config{
2280 Bugs: ProtocolBugs{
2281 SendSplitAlert: true,
2282 },
2283 },
2284 },
2285 {
2286 protocol: dtls,
2287 name: "SendSplitAlert-Async",
2288 config: Config{
2289 Bugs: ProtocolBugs{
2290 SendSplitAlert: true,
2291 },
2292 },
2293 flags: []string{"-async"},
2294 },
2295 {
2296 protocol: dtls,
2297 name: "PackDTLSHandshake",
2298 config: Config{
2299 Bugs: ProtocolBugs{
2300 MaxHandshakeRecordLength: 2,
2301 PackHandshakeFragments: 20,
2302 PackHandshakeRecords: 200,
2303 },
2304 },
2305 },
2306 {
Adam Langley7c803a62015-06-15 15:35:05 -07002307 name: "SendEmptyRecords-Pass",
2308 sendEmptyRecords: 32,
2309 },
2310 {
2311 name: "SendEmptyRecords",
2312 sendEmptyRecords: 33,
2313 shouldFail: true,
2314 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2315 },
2316 {
2317 name: "SendEmptyRecords-Async",
2318 sendEmptyRecords: 33,
2319 flags: []string{"-async"},
2320 shouldFail: true,
2321 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2322 },
2323 {
David Benjamine8e84b92016-08-03 15:39:47 -04002324 name: "SendWarningAlerts-Pass",
2325 config: Config{
2326 MaxVersion: VersionTLS12,
2327 },
Adam Langley7c803a62015-06-15 15:35:05 -07002328 sendWarningAlerts: 4,
2329 },
2330 {
David Benjamine8e84b92016-08-03 15:39:47 -04002331 protocol: dtls,
2332 name: "SendWarningAlerts-DTLS-Pass",
2333 config: Config{
2334 MaxVersion: VersionTLS12,
2335 },
Adam Langley7c803a62015-06-15 15:35:05 -07002336 sendWarningAlerts: 4,
2337 },
2338 {
David Benjamine8e84b92016-08-03 15:39:47 -04002339 name: "SendWarningAlerts-TLS13",
2340 config: Config{
2341 MaxVersion: VersionTLS13,
2342 },
2343 sendWarningAlerts: 4,
2344 shouldFail: true,
2345 expectedError: ":BAD_ALERT:",
2346 expectedLocalError: "remote error: error decoding message",
2347 },
2348 {
2349 name: "SendWarningAlerts",
2350 config: Config{
2351 MaxVersion: VersionTLS12,
2352 },
Adam Langley7c803a62015-06-15 15:35:05 -07002353 sendWarningAlerts: 5,
2354 shouldFail: true,
2355 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2356 },
2357 {
David Benjamine8e84b92016-08-03 15:39:47 -04002358 name: "SendWarningAlerts-Async",
2359 config: Config{
2360 MaxVersion: VersionTLS12,
2361 },
Adam Langley7c803a62015-06-15 15:35:05 -07002362 sendWarningAlerts: 5,
2363 flags: []string{"-async"},
2364 shouldFail: true,
2365 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2366 },
David Benjaminba4594a2015-06-18 18:36:15 -04002367 {
David Benjamin24e58862017-06-14 18:45:29 -04002368 name: "SendBogusAlertType",
2369 sendBogusAlertType: true,
2370 shouldFail: true,
2371 expectedError: ":UNKNOWN_ALERT_TYPE:",
2372 expectedLocalError: "remote error: illegal parameter",
2373 },
2374 {
2375 protocol: dtls,
2376 name: "SendBogusAlertType-DTLS",
2377 sendBogusAlertType: true,
2378 shouldFail: true,
2379 expectedError: ":UNKNOWN_ALERT_TYPE:",
2380 expectedLocalError: "remote error: illegal parameter",
2381 },
2382 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002383 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002384 config: Config{
2385 MaxVersion: VersionTLS13,
2386 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002387 sendKeyUpdates: 33,
2388 keyUpdateRequest: keyUpdateNotRequested,
2389 shouldFail: true,
2390 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002391 },
2392 {
David Benjaminba4594a2015-06-18 18:36:15 -04002393 name: "EmptySessionID",
2394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002395 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002396 SessionTicketsDisabled: true,
2397 },
2398 noSessionCache: true,
2399 flags: []string{"-expect-no-session"},
2400 },
David Benjamin30789da2015-08-29 22:56:45 -04002401 {
2402 name: "Unclean-Shutdown",
2403 config: Config{
2404 Bugs: ProtocolBugs{
2405 NoCloseNotify: true,
2406 ExpectCloseNotify: true,
2407 },
2408 },
2409 shimShutsDown: true,
2410 flags: []string{"-check-close-notify"},
2411 shouldFail: true,
2412 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2413 },
2414 {
2415 name: "Unclean-Shutdown-Ignored",
2416 config: Config{
2417 Bugs: ProtocolBugs{
2418 NoCloseNotify: true,
2419 },
2420 },
2421 shimShutsDown: true,
2422 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002423 {
David Benjaminfa214e42016-05-10 17:03:10 -04002424 name: "Unclean-Shutdown-Alert",
2425 config: Config{
2426 Bugs: ProtocolBugs{
2427 SendAlertOnShutdown: alertDecompressionFailure,
2428 ExpectCloseNotify: true,
2429 },
2430 },
2431 shimShutsDown: true,
2432 flags: []string{"-check-close-notify"},
2433 shouldFail: true,
2434 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2435 },
2436 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002437 name: "LargePlaintext",
2438 config: Config{
2439 Bugs: ProtocolBugs{
2440 SendLargeRecords: true,
2441 },
2442 },
2443 messageLen: maxPlaintext + 1,
2444 shouldFail: true,
2445 expectedError: ":DATA_LENGTH_TOO_LONG:",
2446 },
2447 {
2448 protocol: dtls,
2449 name: "LargePlaintext-DTLS",
2450 config: Config{
2451 Bugs: ProtocolBugs{
2452 SendLargeRecords: true,
2453 },
2454 },
2455 messageLen: maxPlaintext + 1,
2456 shouldFail: true,
2457 expectedError: ":DATA_LENGTH_TOO_LONG:",
2458 },
2459 {
2460 name: "LargeCiphertext",
2461 config: Config{
2462 Bugs: ProtocolBugs{
2463 SendLargeRecords: true,
2464 },
2465 },
2466 messageLen: maxPlaintext * 2,
2467 shouldFail: true,
2468 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2469 },
2470 {
2471 protocol: dtls,
2472 name: "LargeCiphertext-DTLS",
2473 config: Config{
2474 Bugs: ProtocolBugs{
2475 SendLargeRecords: true,
2476 },
2477 },
2478 messageLen: maxPlaintext * 2,
2479 // Unlike the other four cases, DTLS drops records which
2480 // are invalid before authentication, so the connection
2481 // does not fail.
2482 expectMessageDropped: true,
2483 },
David Benjamindd6fed92015-10-23 17:41:12 -04002484 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002485 name: "BadHelloRequest-1",
2486 renegotiate: 1,
2487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002488 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002489 Bugs: ProtocolBugs{
2490 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2491 },
2492 },
2493 flags: []string{
2494 "-renegotiate-freely",
2495 "-expect-total-renegotiations", "1",
2496 },
2497 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002498 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002499 },
2500 {
2501 name: "BadHelloRequest-2",
2502 renegotiate: 1,
2503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002504 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002505 Bugs: ProtocolBugs{
2506 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2507 },
2508 },
2509 flags: []string{
2510 "-renegotiate-freely",
2511 "-expect-total-renegotiations", "1",
2512 },
2513 shouldFail: true,
2514 expectedError: ":BAD_HELLO_REQUEST:",
2515 },
David Benjaminef1b0092015-11-21 14:05:44 -05002516 {
2517 testType: serverTest,
2518 name: "SupportTicketsWithSessionID",
2519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002520 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002521 SessionTicketsDisabled: true,
2522 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002523 resumeConfig: &Config{
2524 MaxVersion: VersionTLS12,
2525 },
David Benjaminef1b0092015-11-21 14:05:44 -05002526 resumeSession: true,
2527 },
David Benjamin02edcd02016-07-27 17:40:37 -04002528 {
2529 protocol: dtls,
2530 name: "DTLS-SendExtraFinished",
2531 config: Config{
2532 Bugs: ProtocolBugs{
2533 SendExtraFinished: true,
2534 },
2535 },
2536 shouldFail: true,
2537 expectedError: ":UNEXPECTED_RECORD:",
2538 },
2539 {
2540 protocol: dtls,
2541 name: "DTLS-SendExtraFinished-Reordered",
2542 config: Config{
2543 Bugs: ProtocolBugs{
2544 MaxHandshakeRecordLength: 2,
2545 ReorderHandshakeFragments: true,
2546 SendExtraFinished: true,
2547 },
2548 },
2549 shouldFail: true,
2550 expectedError: ":UNEXPECTED_RECORD:",
2551 },
David Benjamine97fb482016-07-29 09:23:07 -04002552 {
2553 testType: serverTest,
2554 name: "V2ClientHello-EmptyRecordPrefix",
2555 config: Config{
2556 // Choose a cipher suite that does not involve
2557 // elliptic curves, so no extensions are
2558 // involved.
2559 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002560 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002561 Bugs: ProtocolBugs{
2562 SendV2ClientHello: true,
2563 },
2564 },
2565 sendPrefix: string([]byte{
2566 byte(recordTypeHandshake),
2567 3, 1, // version
2568 0, 0, // length
2569 }),
2570 // A no-op empty record may not be sent before V2ClientHello.
2571 shouldFail: true,
2572 expectedError: ":WRONG_VERSION_NUMBER:",
2573 },
2574 {
2575 testType: serverTest,
2576 name: "V2ClientHello-WarningAlertPrefix",
2577 config: Config{
2578 // Choose a cipher suite that does not involve
2579 // elliptic curves, so no extensions are
2580 // involved.
2581 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002582 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002583 Bugs: ProtocolBugs{
2584 SendV2ClientHello: true,
2585 },
2586 },
2587 sendPrefix: string([]byte{
2588 byte(recordTypeAlert),
2589 3, 1, // version
2590 0, 2, // length
2591 alertLevelWarning, byte(alertDecompressionFailure),
2592 }),
2593 // A no-op warning alert may not be sent before V2ClientHello.
2594 shouldFail: true,
2595 expectedError: ":WRONG_VERSION_NUMBER:",
2596 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002597 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002598 name: "KeyUpdate-Client",
2599 config: Config{
2600 MaxVersion: VersionTLS13,
2601 },
2602 sendKeyUpdates: 1,
2603 keyUpdateRequest: keyUpdateNotRequested,
2604 },
2605 {
2606 testType: serverTest,
2607 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002608 config: Config{
2609 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002610 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002611 sendKeyUpdates: 1,
2612 keyUpdateRequest: keyUpdateNotRequested,
2613 },
2614 {
2615 name: "KeyUpdate-InvalidRequestMode",
2616 config: Config{
2617 MaxVersion: VersionTLS13,
2618 },
2619 sendKeyUpdates: 1,
2620 keyUpdateRequest: 42,
2621 shouldFail: true,
2622 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002623 },
David Benjaminabe94e32016-09-04 14:18:58 -04002624 {
David Benjaminbbba9392017-04-06 12:54:12 -04002625 // Test that KeyUpdates are acknowledged properly.
2626 name: "KeyUpdate-RequestACK",
2627 config: Config{
2628 MaxVersion: VersionTLS13,
2629 Bugs: ProtocolBugs{
2630 RejectUnsolicitedKeyUpdate: true,
2631 },
2632 },
2633 // Test the shim receiving many KeyUpdates in a row.
2634 sendKeyUpdates: 5,
2635 messageCount: 5,
2636 keyUpdateRequest: keyUpdateRequested,
2637 },
2638 {
2639 // Test that KeyUpdates are acknowledged properly if the
2640 // peer's KeyUpdate is discovered while a write is
2641 // pending.
2642 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2643 config: Config{
2644 MaxVersion: VersionTLS13,
2645 Bugs: ProtocolBugs{
2646 RejectUnsolicitedKeyUpdate: true,
2647 },
2648 },
2649 // Test the shim receiving many KeyUpdates in a row.
2650 sendKeyUpdates: 5,
2651 messageCount: 5,
2652 keyUpdateRequest: keyUpdateRequested,
2653 readWithUnfinishedWrite: true,
2654 flags: []string{"-async"},
2655 },
2656 {
David Benjaminabe94e32016-09-04 14:18:58 -04002657 name: "SendSNIWarningAlert",
2658 config: Config{
2659 MaxVersion: VersionTLS12,
2660 Bugs: ProtocolBugs{
2661 SendSNIWarningAlert: true,
2662 },
2663 },
2664 },
David Benjaminc241d792016-09-09 10:34:20 -04002665 {
2666 testType: serverTest,
2667 name: "ExtraCompressionMethods-TLS12",
2668 config: Config{
2669 MaxVersion: VersionTLS12,
2670 Bugs: ProtocolBugs{
2671 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2672 },
2673 },
2674 },
2675 {
2676 testType: serverTest,
2677 name: "ExtraCompressionMethods-TLS13",
2678 config: Config{
2679 MaxVersion: VersionTLS13,
2680 Bugs: ProtocolBugs{
2681 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2682 },
2683 },
2684 shouldFail: true,
2685 expectedError: ":INVALID_COMPRESSION_LIST:",
2686 expectedLocalError: "remote error: illegal parameter",
2687 },
2688 {
2689 testType: serverTest,
2690 name: "NoNullCompression-TLS12",
2691 config: Config{
2692 MaxVersion: VersionTLS12,
2693 Bugs: ProtocolBugs{
2694 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2695 },
2696 },
2697 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002698 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002699 expectedLocalError: "remote error: illegal parameter",
2700 },
2701 {
2702 testType: serverTest,
2703 name: "NoNullCompression-TLS13",
2704 config: Config{
2705 MaxVersion: VersionTLS13,
2706 Bugs: ProtocolBugs{
2707 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2708 },
2709 },
2710 shouldFail: true,
2711 expectedError: ":INVALID_COMPRESSION_LIST:",
2712 expectedLocalError: "remote error: illegal parameter",
2713 },
David Benjamin413e79e2017-07-01 10:11:53 -04002714 // Test that the client rejects invalid compression methods
2715 // from the server.
2716 {
2717 testType: clientTest,
2718 name: "InvalidCompressionMethod",
2719 config: Config{
2720 MaxVersion: VersionTLS12,
2721 Bugs: ProtocolBugs{
2722 SendCompressionMethod: 1,
2723 },
2724 },
2725 shouldFail: true,
2726 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2727 expectedLocalError: "remote error: illegal parameter",
2728 },
David Benjamin65ac9972016-09-02 21:35:25 -04002729 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002730 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002731 config: Config{
2732 MaxVersion: VersionTLS12,
2733 Bugs: ProtocolBugs{
2734 ExpectGREASE: true,
2735 },
2736 },
2737 flags: []string{"-enable-grease"},
2738 },
2739 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002740 name: "GREASE-Client-TLS13",
2741 config: Config{
2742 MaxVersion: VersionTLS13,
2743 Bugs: ProtocolBugs{
2744 ExpectGREASE: true,
2745 },
2746 },
2747 flags: []string{"-enable-grease"},
2748 },
2749 {
2750 testType: serverTest,
2751 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002752 config: Config{
2753 MaxVersion: VersionTLS13,
2754 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002755 // TLS 1.3 servers are expected to
2756 // always enable GREASE. TLS 1.3 is new,
2757 // so there is no existing ecosystem to
2758 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002759 ExpectGREASE: true,
2760 },
2761 },
David Benjamin65ac9972016-09-02 21:35:25 -04002762 },
David Benjamine3fbb362017-01-06 16:19:28 -05002763 {
2764 // Test the server so there is a large certificate as
2765 // well as application data.
2766 testType: serverTest,
2767 name: "MaxSendFragment",
2768 config: Config{
2769 Bugs: ProtocolBugs{
2770 MaxReceivePlaintext: 512,
2771 },
2772 },
2773 messageLen: 1024,
2774 flags: []string{
2775 "-max-send-fragment", "512",
2776 "-read-size", "1024",
2777 },
2778 },
2779 {
2780 // Test the server so there is a large certificate as
2781 // well as application data.
2782 testType: serverTest,
2783 name: "MaxSendFragment-TooLarge",
2784 config: Config{
2785 Bugs: ProtocolBugs{
2786 // Ensure that some of the records are
2787 // 512.
2788 MaxReceivePlaintext: 511,
2789 },
2790 },
2791 messageLen: 1024,
2792 flags: []string{
2793 "-max-send-fragment", "512",
2794 "-read-size", "1024",
2795 },
2796 shouldFail: true,
2797 expectedLocalError: "local error: record overflow",
2798 },
Adam Langley7c803a62015-06-15 15:35:05 -07002799 }
Adam Langley7c803a62015-06-15 15:35:05 -07002800 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002801
2802 // Test that very large messages can be received.
2803 cert := rsaCertificate
2804 for i := 0; i < 50; i++ {
2805 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2806 }
2807 testCases = append(testCases, testCase{
2808 name: "LargeMessage",
2809 config: Config{
2810 Certificates: []Certificate{cert},
2811 },
2812 })
2813 testCases = append(testCases, testCase{
2814 protocol: dtls,
2815 name: "LargeMessage-DTLS",
2816 config: Config{
2817 Certificates: []Certificate{cert},
2818 },
2819 })
2820
2821 // They are rejected if the maximum certificate chain length is capped.
2822 testCases = append(testCases, testCase{
2823 name: "LargeMessage-Reject",
2824 config: Config{
2825 Certificates: []Certificate{cert},
2826 },
2827 flags: []string{"-max-cert-list", "16384"},
2828 shouldFail: true,
2829 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2830 })
2831 testCases = append(testCases, testCase{
2832 protocol: dtls,
2833 name: "LargeMessage-Reject-DTLS",
2834 config: Config{
2835 Certificates: []Certificate{cert},
2836 },
2837 flags: []string{"-max-cert-list", "16384"},
2838 shouldFail: true,
2839 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2840 })
Adam Langley7c803a62015-06-15 15:35:05 -07002841}
2842
David Benjaminaa012042016-12-10 13:33:05 -05002843func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2844 const psk = "12345"
2845 const pskIdentity = "luggage combo"
2846
2847 var prefix string
2848 if protocol == dtls {
2849 if !ver.hasDTLS {
2850 return
2851 }
2852 prefix = "D"
2853 }
2854
2855 var cert Certificate
2856 var certFile string
2857 var keyFile string
2858 if hasComponent(suite.name, "ECDSA") {
2859 cert = ecdsaP256Certificate
2860 certFile = ecdsaP256CertificateFile
2861 keyFile = ecdsaP256KeyFile
2862 } else {
2863 cert = rsaCertificate
2864 certFile = rsaCertificateFile
2865 keyFile = rsaKeyFile
2866 }
2867
2868 var flags []string
2869 if hasComponent(suite.name, "PSK") {
2870 flags = append(flags,
2871 "-psk", psk,
2872 "-psk-identity", pskIdentity)
2873 }
2874 if hasComponent(suite.name, "NULL") {
2875 // NULL ciphers must be explicitly enabled.
2876 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2877 }
David Benjaminaa012042016-12-10 13:33:05 -05002878
2879 var shouldServerFail, shouldClientFail bool
2880 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2881 // BoringSSL clients accept ECDHE on SSLv3, but
2882 // a BoringSSL server will never select it
2883 // because the extension is missing.
2884 shouldServerFail = true
2885 }
2886 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2887 shouldClientFail = true
2888 shouldServerFail = true
2889 }
2890 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2891 shouldClientFail = true
2892 shouldServerFail = true
2893 }
2894 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2895 shouldClientFail = true
2896 shouldServerFail = true
2897 }
2898 if !isDTLSCipher(suite.name) && protocol == dtls {
2899 shouldClientFail = true
2900 shouldServerFail = true
2901 }
2902
2903 var sendCipherSuite uint16
2904 var expectedServerError, expectedClientError string
2905 serverCipherSuites := []uint16{suite.id}
2906 if shouldServerFail {
2907 expectedServerError = ":NO_SHARED_CIPHER:"
2908 }
2909 if shouldClientFail {
2910 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2911 // Configure the server to select ciphers as normal but
2912 // select an incompatible cipher in ServerHello.
2913 serverCipherSuites = nil
2914 sendCipherSuite = suite.id
2915 }
2916
David Benjamincdb6fe92017-02-07 16:06:48 -05002917 // For cipher suites and versions where exporters are defined, verify
2918 // that they interoperate.
2919 var exportKeyingMaterial int
2920 if ver.version > VersionSSL30 {
2921 exportKeyingMaterial = 1024
2922 }
2923
David Benjaminaa012042016-12-10 13:33:05 -05002924 testCases = append(testCases, testCase{
2925 testType: serverTest,
2926 protocol: protocol,
2927 name: prefix + ver.name + "-" + suite.name + "-server",
2928 config: Config{
2929 MinVersion: ver.version,
2930 MaxVersion: ver.version,
2931 CipherSuites: []uint16{suite.id},
2932 Certificates: []Certificate{cert},
2933 PreSharedKey: []byte(psk),
2934 PreSharedKeyIdentity: pskIdentity,
2935 Bugs: ProtocolBugs{
2936 AdvertiseAllConfiguredCiphers: true,
2937 },
2938 },
David Benjamina5022392017-07-10 17:40:39 -04002939 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002940 certFile: certFile,
2941 keyFile: keyFile,
2942 flags: flags,
2943 resumeSession: true,
2944 shouldFail: shouldServerFail,
2945 expectedError: expectedServerError,
2946 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002947 })
2948
2949 testCases = append(testCases, testCase{
2950 testType: clientTest,
2951 protocol: protocol,
2952 name: prefix + ver.name + "-" + suite.name + "-client",
2953 config: Config{
2954 MinVersion: ver.version,
2955 MaxVersion: ver.version,
2956 CipherSuites: serverCipherSuites,
2957 Certificates: []Certificate{cert},
2958 PreSharedKey: []byte(psk),
2959 PreSharedKeyIdentity: pskIdentity,
2960 Bugs: ProtocolBugs{
2961 IgnorePeerCipherPreferences: shouldClientFail,
2962 SendCipherSuite: sendCipherSuite,
2963 },
2964 },
David Benjamina5022392017-07-10 17:40:39 -04002965 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002966 flags: flags,
2967 resumeSession: true,
2968 shouldFail: shouldClientFail,
2969 expectedError: expectedClientError,
2970 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002971 })
2972
David Benjamin6f600d62016-12-21 16:06:54 -05002973 if shouldClientFail {
2974 return
2975 }
2976
2977 // Ensure the maximum record size is accepted.
2978 testCases = append(testCases, testCase{
2979 protocol: protocol,
2980 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2981 config: Config{
2982 MinVersion: ver.version,
2983 MaxVersion: ver.version,
2984 CipherSuites: []uint16{suite.id},
2985 Certificates: []Certificate{cert},
2986 PreSharedKey: []byte(psk),
2987 PreSharedKeyIdentity: pskIdentity,
2988 },
David Benjamina5022392017-07-10 17:40:39 -04002989 tls13Variant: ver.tls13Variant,
2990 flags: flags,
2991 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002992 })
2993
2994 // Test bad records for all ciphers. Bad records are fatal in TLS
2995 // and ignored in DTLS.
2996 var shouldFail bool
2997 var expectedError string
2998 if protocol == tls {
2999 shouldFail = true
3000 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
3001 }
3002
3003 testCases = append(testCases, testCase{
3004 protocol: protocol,
3005 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
3006 config: Config{
3007 MinVersion: ver.version,
3008 MaxVersion: ver.version,
3009 CipherSuites: []uint16{suite.id},
3010 Certificates: []Certificate{cert},
3011 PreSharedKey: []byte(psk),
3012 PreSharedKeyIdentity: pskIdentity,
3013 },
David Benjamina5022392017-07-10 17:40:39 -04003014 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05003015 flags: flags,
3016 damageFirstWrite: true,
3017 messageLen: maxPlaintext,
3018 shouldFail: shouldFail,
3019 expectedError: expectedError,
3020 })
David Benjaminaa012042016-12-10 13:33:05 -05003021}
3022
Adam Langley95c29f32014-06-20 12:00:00 -07003023func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02003024 const bogusCipher = 0xfe00
3025
Adam Langley95c29f32014-06-20 12:00:00 -07003026 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07003027 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04003028 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05003029 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07003030 }
David Benjamin2c99d282015-09-01 10:23:00 -04003031 }
Adam Langley95c29f32014-06-20 12:00:00 -07003032 }
Adam Langleya7997f12015-05-14 17:38:50 -07003033
3034 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003035 name: "NoSharedCipher",
3036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003037 MaxVersion: VersionTLS12,
3038 CipherSuites: []uint16{},
3039 },
3040 shouldFail: true,
3041 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3042 })
3043
3044 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003045 name: "NoSharedCipher-TLS13",
3046 config: Config{
3047 MaxVersion: VersionTLS13,
3048 CipherSuites: []uint16{},
3049 },
3050 shouldFail: true,
3051 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3052 })
3053
3054 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003055 name: "UnsupportedCipherSuite",
3056 config: Config{
3057 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003058 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003059 Bugs: ProtocolBugs{
3060 IgnorePeerCipherPreferences: true,
3061 },
3062 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003063 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003064 shouldFail: true,
3065 expectedError: ":WRONG_CIPHER_RETURNED:",
3066 })
3067
3068 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003069 name: "ServerHelloBogusCipher",
3070 config: Config{
3071 MaxVersion: VersionTLS12,
3072 Bugs: ProtocolBugs{
3073 SendCipherSuite: bogusCipher,
3074 },
3075 },
3076 shouldFail: true,
3077 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3078 })
3079 testCases = append(testCases, testCase{
3080 name: "ServerHelloBogusCipher-TLS13",
3081 config: Config{
3082 MaxVersion: VersionTLS13,
3083 Bugs: ProtocolBugs{
3084 SendCipherSuite: bogusCipher,
3085 },
3086 },
3087 shouldFail: true,
3088 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3089 })
3090
David Benjamin241ae832016-01-15 03:04:54 -05003091 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003092 testCases = append(testCases, testCase{
3093 testType: serverTest,
3094 name: "UnknownCipher",
3095 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003096 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003097 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003098 Bugs: ProtocolBugs{
3099 AdvertiseAllConfiguredCiphers: true,
3100 },
3101 },
3102 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003103
3104 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003105 testCases = append(testCases, testCase{
3106 testType: serverTest,
3107 name: "UnknownCipher-TLS13",
3108 config: Config{
3109 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003110 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003111 Bugs: ProtocolBugs{
3112 AdvertiseAllConfiguredCiphers: true,
3113 },
David Benjamin241ae832016-01-15 03:04:54 -05003114 },
3115 })
3116
David Benjamin78679342016-09-16 19:42:05 -04003117 // Test empty ECDHE_PSK identity hints work as expected.
3118 testCases = append(testCases, testCase{
3119 name: "EmptyECDHEPSKHint",
3120 config: Config{
3121 MaxVersion: VersionTLS12,
3122 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3123 PreSharedKey: []byte("secret"),
3124 },
3125 flags: []string{"-psk", "secret"},
3126 })
3127
3128 // Test empty PSK identity hints work as expected, even if an explicit
3129 // ServerKeyExchange is sent.
3130 testCases = append(testCases, testCase{
3131 name: "ExplicitEmptyPSKHint",
3132 config: Config{
3133 MaxVersion: VersionTLS12,
3134 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3135 PreSharedKey: []byte("secret"),
3136 Bugs: ProtocolBugs{
3137 AlwaysSendPreSharedKeyIdentityHint: true,
3138 },
3139 },
3140 flags: []string{"-psk", "secret"},
3141 })
David Benjamin69522112017-03-28 15:38:29 -05003142
3143 // Test that clients enforce that the server-sent certificate and cipher
3144 // suite match in TLS 1.2.
3145 testCases = append(testCases, testCase{
3146 name: "CertificateCipherMismatch-RSA",
3147 config: Config{
3148 MaxVersion: VersionTLS12,
3149 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3150 Certificates: []Certificate{rsaCertificate},
3151 Bugs: ProtocolBugs{
3152 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3153 },
3154 },
3155 shouldFail: true,
3156 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3157 })
3158 testCases = append(testCases, testCase{
3159 name: "CertificateCipherMismatch-ECDSA",
3160 config: Config{
3161 MaxVersion: VersionTLS12,
3162 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3163 Certificates: []Certificate{ecdsaP256Certificate},
3164 Bugs: ProtocolBugs{
3165 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3166 },
3167 },
3168 shouldFail: true,
3169 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3170 })
3171 testCases = append(testCases, testCase{
3172 name: "CertificateCipherMismatch-Ed25519",
3173 config: Config{
3174 MaxVersion: VersionTLS12,
3175 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3176 Certificates: []Certificate{ed25519Certificate},
3177 Bugs: ProtocolBugs{
3178 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3179 },
3180 },
3181 shouldFail: true,
3182 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3183 })
3184
3185 // Test that servers decline to select a cipher suite which is
3186 // inconsistent with their configured certificate.
3187 testCases = append(testCases, testCase{
3188 testType: serverTest,
3189 name: "ServerCipherFilter-RSA",
3190 config: Config{
3191 MaxVersion: VersionTLS12,
3192 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3193 },
3194 flags: []string{
3195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3197 },
3198 shouldFail: true,
3199 expectedError: ":NO_SHARED_CIPHER:",
3200 })
3201 testCases = append(testCases, testCase{
3202 testType: serverTest,
3203 name: "ServerCipherFilter-ECDSA",
3204 config: Config{
3205 MaxVersion: VersionTLS12,
3206 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3207 },
3208 flags: []string{
3209 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3210 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3211 },
3212 shouldFail: true,
3213 expectedError: ":NO_SHARED_CIPHER:",
3214 })
3215 testCases = append(testCases, testCase{
3216 testType: serverTest,
3217 name: "ServerCipherFilter-Ed25519",
3218 config: Config{
3219 MaxVersion: VersionTLS12,
3220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3221 },
3222 flags: []string{
3223 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3224 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3225 },
3226 shouldFail: true,
3227 expectedError: ":NO_SHARED_CIPHER:",
3228 })
David Benjamin364af782017-07-01 10:35:27 -04003229
3230 // Test cipher suite negotiation works as expected. Configure a
3231 // complicated cipher suite configuration.
3232 const negotiationTestCiphers = "" +
3233 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3234 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3235 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3236 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3237 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3238 negotiationTests := []struct {
3239 ciphers []uint16
3240 expected uint16
3241 }{
3242 // Server preferences are honored, including when
3243 // equipreference groups are involved.
3244 {
3245 []uint16{
3246 TLS_RSA_WITH_AES_256_GCM_SHA384,
3247 TLS_RSA_WITH_AES_128_CBC_SHA,
3248 TLS_RSA_WITH_AES_128_GCM_SHA256,
3249 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3250 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3251 },
3252 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3253 },
3254 {
3255 []uint16{
3256 TLS_RSA_WITH_AES_256_GCM_SHA384,
3257 TLS_RSA_WITH_AES_128_CBC_SHA,
3258 TLS_RSA_WITH_AES_128_GCM_SHA256,
3259 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3260 },
3261 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3262 },
3263 {
3264 []uint16{
3265 TLS_RSA_WITH_AES_256_GCM_SHA384,
3266 TLS_RSA_WITH_AES_128_CBC_SHA,
3267 TLS_RSA_WITH_AES_128_GCM_SHA256,
3268 },
3269 TLS_RSA_WITH_AES_128_GCM_SHA256,
3270 },
3271 {
3272 []uint16{
3273 TLS_RSA_WITH_AES_256_GCM_SHA384,
3274 TLS_RSA_WITH_AES_128_CBC_SHA,
3275 },
3276 TLS_RSA_WITH_AES_128_CBC_SHA,
3277 },
3278 // Equipreference groups use the client preference.
3279 {
3280 []uint16{
3281 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3282 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3283 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3284 },
3285 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3286 },
3287 {
3288 []uint16{
3289 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3290 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3291 },
3292 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3293 },
3294 {
3295 []uint16{
3296 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3297 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3298 },
3299 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3300 },
3301 {
3302 []uint16{
3303 TLS_RSA_WITH_AES_256_GCM_SHA384,
3304 TLS_RSA_WITH_AES_256_CBC_SHA,
3305 },
3306 TLS_RSA_WITH_AES_256_GCM_SHA384,
3307 },
3308 {
3309 []uint16{
3310 TLS_RSA_WITH_AES_256_CBC_SHA,
3311 TLS_RSA_WITH_AES_256_GCM_SHA384,
3312 },
3313 TLS_RSA_WITH_AES_256_CBC_SHA,
3314 },
3315 // If there are two equipreference groups, the preferred one
3316 // takes precedence.
3317 {
3318 []uint16{
3319 TLS_RSA_WITH_AES_256_GCM_SHA384,
3320 TLS_RSA_WITH_AES_256_CBC_SHA,
3321 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3322 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3323 },
3324 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3325 },
3326 }
3327 for i, t := range negotiationTests {
3328 testCases = append(testCases, testCase{
3329 testType: serverTest,
3330 name: "CipherNegotiation-" + strconv.Itoa(i),
3331 config: Config{
3332 MaxVersion: VersionTLS12,
3333 CipherSuites: t.ciphers,
3334 },
3335 flags: []string{"-cipher", negotiationTestCiphers},
3336 expectedCipher: t.expected,
3337 })
3338 }
Adam Langley95c29f32014-06-20 12:00:00 -07003339}
3340
3341func addBadECDSASignatureTests() {
3342 for badR := BadValue(1); badR < NumBadValues; badR++ {
3343 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003344 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003345 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3346 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003347 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003348 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003349 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003350 Bugs: ProtocolBugs{
3351 BadECDSAR: badR,
3352 BadECDSAS: badS,
3353 },
3354 },
3355 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003356 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003357 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003358 testCases = append(testCases, testCase{
3359 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3360 config: Config{
3361 MaxVersion: VersionTLS13,
3362 Certificates: []Certificate{ecdsaP256Certificate},
3363 Bugs: ProtocolBugs{
3364 BadECDSAR: badR,
3365 BadECDSAS: badS,
3366 },
3367 },
3368 shouldFail: true,
3369 expectedError: ":BAD_SIGNATURE:",
3370 })
Adam Langley95c29f32014-06-20 12:00:00 -07003371 }
3372 }
3373}
3374
Adam Langley80842bd2014-06-20 12:00:00 -07003375func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003376 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003377 name: "MaxCBCPadding",
3378 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003379 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003380 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3381 Bugs: ProtocolBugs{
3382 MaxPadding: true,
3383 },
3384 },
3385 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3386 })
David Benjamin025b3d32014-07-01 19:53:04 -04003387 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003388 name: "BadCBCPadding",
3389 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003390 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003391 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3392 Bugs: ProtocolBugs{
3393 PaddingFirstByteBad: true,
3394 },
3395 },
3396 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003397 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003398 })
3399 // OpenSSL previously had an issue where the first byte of padding in
3400 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003401 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003402 name: "BadCBCPadding255",
3403 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003404 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003405 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3406 Bugs: ProtocolBugs{
3407 MaxPadding: true,
3408 PaddingFirstByteBadIf255: true,
3409 },
3410 },
3411 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3412 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003413 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003414 })
3415}
3416
Kenny Root7fdeaf12014-08-05 15:23:37 -07003417func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003418 var cbcCiphers = []struct {
3419 name string
3420 cipher uint16
3421 }{
3422 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3423 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3424 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3425 }
3426 for _, t := range cbcCiphers {
3427 testCases = append(testCases, testCase{
3428 name: "CBCRecordSplitting-" + t.name,
3429 config: Config{
3430 MaxVersion: VersionTLS10,
3431 MinVersion: VersionTLS10,
3432 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003433 Bugs: ProtocolBugs{
3434 ExpectRecordSplitting: true,
3435 },
David Benjamina1ce8562017-07-01 11:46:57 -04003436 },
3437 messageLen: -1, // read until EOF
3438 resumeSession: true,
3439 flags: []string{
3440 "-async",
3441 "-write-different-record-sizes",
3442 "-cbc-record-splitting",
3443 },
3444 })
3445 testCases = append(testCases, testCase{
3446 name: "CBCRecordSplittingPartialWrite-" + t.name,
3447 config: Config{
3448 MaxVersion: VersionTLS10,
3449 MinVersion: VersionTLS10,
3450 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003451 Bugs: ProtocolBugs{
3452 ExpectRecordSplitting: true,
3453 },
David Benjamina1ce8562017-07-01 11:46:57 -04003454 },
3455 messageLen: -1, // read until EOF
3456 flags: []string{
3457 "-async",
3458 "-write-different-record-sizes",
3459 "-cbc-record-splitting",
3460 "-partial-write",
3461 },
3462 })
3463 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003464}
3465
David Benjamin636293b2014-07-08 17:59:18 -04003466func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003467 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003468 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003469 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3470 cert, err := x509.ParseCertificate(cert.Certificate[0])
3471 if err != nil {
3472 panic(err)
3473 }
3474 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003475 }
Adam Langley2ff79332017-02-28 13:45:39 -08003476 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003477
David Benjamin636293b2014-07-08 17:59:18 -04003478 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003479 testCases = append(testCases, testCase{
3480 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003481 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003482 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003483 MinVersion: ver.version,
3484 MaxVersion: ver.version,
3485 ClientAuth: RequireAnyClientCert,
3486 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003487 },
David Benjamina5022392017-07-10 17:40:39 -04003488 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003489 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003490 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3491 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003492 },
3493 })
3494 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003495 testType: serverTest,
3496 name: ver.name + "-Server-ClientAuth-RSA",
3497 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003498 MinVersion: ver.version,
3499 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003500 Certificates: []Certificate{rsaCertificate},
3501 },
David Benjamina5022392017-07-10 17:40:39 -04003502 tls13Variant: ver.tls13Variant,
3503 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003504 })
David Benjamine098ec22014-08-27 23:13:20 -04003505 if ver.version != VersionSSL30 {
3506 testCases = append(testCases, testCase{
3507 testType: serverTest,
3508 name: ver.name + "-Server-ClientAuth-ECDSA",
3509 config: Config{
3510 MinVersion: ver.version,
3511 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003512 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003513 },
David Benjamina5022392017-07-10 17:40:39 -04003514 tls13Variant: ver.tls13Variant,
3515 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003516 })
3517 testCases = append(testCases, testCase{
3518 testType: clientTest,
3519 name: ver.name + "-Client-ClientAuth-ECDSA",
3520 config: Config{
3521 MinVersion: ver.version,
3522 MaxVersion: ver.version,
3523 ClientAuth: RequireAnyClientCert,
3524 ClientCAs: certPool,
3525 },
David Benjamina5022392017-07-10 17:40:39 -04003526 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003527 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003528 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3529 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003530 },
3531 })
3532 }
Adam Langley37646832016-08-01 16:16:46 -07003533
3534 testCases = append(testCases, testCase{
3535 name: "NoClientCertificate-" + ver.name,
3536 config: Config{
3537 MinVersion: ver.version,
3538 MaxVersion: ver.version,
3539 ClientAuth: RequireAnyClientCert,
3540 },
David Benjamina5022392017-07-10 17:40:39 -04003541 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003542 shouldFail: true,
3543 expectedLocalError: "client didn't provide a certificate",
3544 })
3545
3546 testCases = append(testCases, testCase{
3547 // Even if not configured to expect a certificate, OpenSSL will
3548 // return X509_V_OK as the verify_result.
3549 testType: serverTest,
3550 name: "NoClientCertificateRequested-Server-" + ver.name,
3551 config: Config{
3552 MinVersion: ver.version,
3553 MaxVersion: ver.version,
3554 },
David Benjamina5022392017-07-10 17:40:39 -04003555 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003556 flags: []string{
3557 "-expect-verify-result",
3558 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003559 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003560 })
3561
3562 testCases = append(testCases, testCase{
3563 // If a client certificate is not provided, OpenSSL will still
3564 // return X509_V_OK as the verify_result.
3565 testType: serverTest,
3566 name: "NoClientCertificate-Server-" + ver.name,
3567 config: Config{
3568 MinVersion: ver.version,
3569 MaxVersion: ver.version,
3570 },
David Benjamina5022392017-07-10 17:40:39 -04003571 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003572 flags: []string{
3573 "-expect-verify-result",
3574 "-verify-peer",
3575 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003576 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003577 })
3578
David Benjamin1db9e1b2016-10-07 20:51:43 -04003579 certificateRequired := "remote error: certificate required"
3580 if ver.version < VersionTLS13 {
3581 // Prior to TLS 1.3, the generic handshake_failure alert
3582 // was used.
3583 certificateRequired = "remote error: handshake failure"
3584 }
Adam Langley37646832016-08-01 16:16:46 -07003585 testCases = append(testCases, testCase{
3586 testType: serverTest,
3587 name: "RequireAnyClientCertificate-" + ver.name,
3588 config: Config{
3589 MinVersion: ver.version,
3590 MaxVersion: ver.version,
3591 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003592 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003593 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003594 shouldFail: true,
3595 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3596 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003597 })
3598
3599 if ver.version != VersionSSL30 {
3600 testCases = append(testCases, testCase{
3601 testType: serverTest,
3602 name: "SkipClientCertificate-" + ver.name,
3603 config: Config{
3604 MinVersion: ver.version,
3605 MaxVersion: ver.version,
3606 Bugs: ProtocolBugs{
3607 SkipClientCertificate: true,
3608 },
3609 },
3610 // Setting SSL_VERIFY_PEER allows anonymous clients.
3611 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003612 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003613 shouldFail: true,
3614 expectedError: ":UNEXPECTED_MESSAGE:",
3615 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003616
3617 testCases = append(testCases, testCase{
3618 testType: serverTest,
3619 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3620 config: Config{
3621 MinVersion: ver.version,
3622 MaxVersion: ver.version,
3623 },
3624 flags: []string{
3625 "-enable-channel-id",
3626 "-verify-peer-if-no-obc",
3627 },
David Benjamina5022392017-07-10 17:40:39 -04003628 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003629 shouldFail: true,
3630 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3631 expectedLocalError: certificateRequired,
3632 })
3633
3634 testCases = append(testCases, testCase{
3635 testType: serverTest,
3636 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3637 config: Config{
3638 MinVersion: ver.version,
3639 MaxVersion: ver.version,
3640 ChannelID: channelIDKey,
3641 },
3642 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003643 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003644 flags: []string{
3645 "-enable-channel-id",
3646 "-verify-peer-if-no-obc",
3647 },
3648 })
Adam Langley37646832016-08-01 16:16:46 -07003649 }
Adam Langley2ff79332017-02-28 13:45:39 -08003650
3651 testCases = append(testCases, testCase{
3652 testType: serverTest,
3653 name: ver.name + "-Server-CertReq-CA-List",
3654 config: Config{
3655 MinVersion: ver.version,
3656 MaxVersion: ver.version,
3657 Certificates: []Certificate{rsaCertificate},
3658 Bugs: ProtocolBugs{
3659 ExpectCertificateReqNames: caNames,
3660 },
3661 },
David Benjamina5022392017-07-10 17:40:39 -04003662 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003663 flags: []string{
3664 "-require-any-client-certificate",
3665 "-use-client-ca-list", encodeDERValues(caNames),
3666 },
3667 })
3668
3669 testCases = append(testCases, testCase{
3670 testType: clientTest,
3671 name: ver.name + "-Client-CertReq-CA-List",
3672 config: Config{
3673 MinVersion: ver.version,
3674 MaxVersion: ver.version,
3675 Certificates: []Certificate{rsaCertificate},
3676 ClientAuth: RequireAnyClientCert,
3677 ClientCAs: certPool,
3678 },
David Benjamina5022392017-07-10 17:40:39 -04003679 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003680 flags: []string{
3681 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3682 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3683 "-expect-client-ca-list", encodeDERValues(caNames),
3684 },
3685 })
David Benjamin636293b2014-07-08 17:59:18 -04003686 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003687
David Benjaminc032dfa2016-05-12 14:54:57 -04003688 // Client auth is only legal in certificate-based ciphers.
3689 testCases = append(testCases, testCase{
3690 testType: clientTest,
3691 name: "ClientAuth-PSK",
3692 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003693 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003694 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3695 PreSharedKey: []byte("secret"),
3696 ClientAuth: RequireAnyClientCert,
3697 },
3698 flags: []string{
3699 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3700 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3701 "-psk", "secret",
3702 },
3703 shouldFail: true,
3704 expectedError: ":UNEXPECTED_MESSAGE:",
3705 })
3706 testCases = append(testCases, testCase{
3707 testType: clientTest,
3708 name: "ClientAuth-ECDHE_PSK",
3709 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003710 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003711 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3712 PreSharedKey: []byte("secret"),
3713 ClientAuth: RequireAnyClientCert,
3714 },
3715 flags: []string{
3716 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3717 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3718 "-psk", "secret",
3719 },
3720 shouldFail: true,
3721 expectedError: ":UNEXPECTED_MESSAGE:",
3722 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003723
3724 // Regression test for a bug where the client CA list, if explicitly
3725 // set to NULL, was mis-encoded.
3726 testCases = append(testCases, testCase{
3727 testType: serverTest,
3728 name: "Null-Client-CA-List",
3729 config: Config{
3730 MaxVersion: VersionTLS12,
3731 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003732 Bugs: ProtocolBugs{
3733 ExpectCertificateReqNames: [][]byte{},
3734 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003735 },
3736 flags: []string{
3737 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003738 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003739 },
3740 })
David Benjamin636293b2014-07-08 17:59:18 -04003741}
3742
Adam Langley75712922014-10-10 16:23:43 -07003743func addExtendedMasterSecretTests() {
3744 const expectEMSFlag = "-expect-extended-master-secret"
3745
3746 for _, with := range []bool{false, true} {
3747 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003748 if with {
3749 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003750 }
3751
3752 for _, isClient := range []bool{false, true} {
3753 suffix := "-Server"
3754 testType := serverTest
3755 if isClient {
3756 suffix = "-Client"
3757 testType = clientTest
3758 }
3759
3760 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003761 // In TLS 1.3, the extension is irrelevant and
3762 // always reports as enabled.
3763 var flags []string
3764 if with || ver.version >= VersionTLS13 {
3765 flags = []string{expectEMSFlag}
3766 }
3767
Adam Langley75712922014-10-10 16:23:43 -07003768 test := testCase{
3769 testType: testType,
3770 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3771 config: Config{
3772 MinVersion: ver.version,
3773 MaxVersion: ver.version,
3774 Bugs: ProtocolBugs{
3775 NoExtendedMasterSecret: !with,
3776 RequireExtendedMasterSecret: with,
3777 },
3778 },
David Benjamina5022392017-07-10 17:40:39 -04003779 tls13Variant: ver.tls13Variant,
3780 flags: flags,
3781 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003782 }
3783 if test.shouldFail {
3784 test.expectedLocalError = "extended master secret required but not supported by peer"
3785 }
3786 testCases = append(testCases, test)
3787 }
3788 }
3789 }
3790
Adam Langleyba5934b2015-06-02 10:50:35 -07003791 for _, isClient := range []bool{false, true} {
3792 for _, supportedInFirstConnection := range []bool{false, true} {
3793 for _, supportedInResumeConnection := range []bool{false, true} {
3794 boolToWord := func(b bool) string {
3795 if b {
3796 return "Yes"
3797 }
3798 return "No"
3799 }
3800 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3801 if isClient {
3802 suffix += "Client"
3803 } else {
3804 suffix += "Server"
3805 }
3806
3807 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003808 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003809 Bugs: ProtocolBugs{
3810 RequireExtendedMasterSecret: true,
3811 },
3812 }
3813
3814 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003815 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003816 Bugs: ProtocolBugs{
3817 NoExtendedMasterSecret: true,
3818 },
3819 }
3820
3821 test := testCase{
3822 name: "ExtendedMasterSecret-" + suffix,
3823 resumeSession: true,
3824 }
3825
3826 if !isClient {
3827 test.testType = serverTest
3828 }
3829
3830 if supportedInFirstConnection {
3831 test.config = supportedConfig
3832 } else {
3833 test.config = noSupportConfig
3834 }
3835
3836 if supportedInResumeConnection {
3837 test.resumeConfig = &supportedConfig
3838 } else {
3839 test.resumeConfig = &noSupportConfig
3840 }
3841
3842 switch suffix {
3843 case "YesToYes-Client", "YesToYes-Server":
3844 // When a session is resumed, it should
3845 // still be aware that its master
3846 // secret was generated via EMS and
3847 // thus it's safe to use tls-unique.
3848 test.flags = []string{expectEMSFlag}
3849 case "NoToYes-Server":
3850 // If an original connection did not
3851 // contain EMS, but a resumption
3852 // handshake does, then a server should
3853 // not resume the session.
3854 test.expectResumeRejected = true
3855 case "YesToNo-Server":
3856 // Resuming an EMS session without the
3857 // EMS extension should cause the
3858 // server to abort the connection.
3859 test.shouldFail = true
3860 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3861 case "NoToYes-Client":
3862 // A client should abort a connection
3863 // where the server resumed a non-EMS
3864 // session but echoed the EMS
3865 // extension.
3866 test.shouldFail = true
3867 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3868 case "YesToNo-Client":
3869 // A client should abort a connection
3870 // where the server didn't echo EMS
3871 // when the session used it.
3872 test.shouldFail = true
3873 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3874 }
3875
3876 testCases = append(testCases, test)
3877 }
3878 }
3879 }
David Benjamin163c9562016-08-29 23:14:17 -04003880
3881 // Switching EMS on renegotiation is forbidden.
3882 testCases = append(testCases, testCase{
3883 name: "ExtendedMasterSecret-Renego-NoEMS",
3884 config: Config{
3885 MaxVersion: VersionTLS12,
3886 Bugs: ProtocolBugs{
3887 NoExtendedMasterSecret: true,
3888 NoExtendedMasterSecretOnRenegotiation: true,
3889 },
3890 },
3891 renegotiate: 1,
3892 flags: []string{
3893 "-renegotiate-freely",
3894 "-expect-total-renegotiations", "1",
3895 },
3896 })
3897
3898 testCases = append(testCases, testCase{
3899 name: "ExtendedMasterSecret-Renego-Upgrade",
3900 config: Config{
3901 MaxVersion: VersionTLS12,
3902 Bugs: ProtocolBugs{
3903 NoExtendedMasterSecret: true,
3904 },
3905 },
3906 renegotiate: 1,
3907 flags: []string{
3908 "-renegotiate-freely",
3909 "-expect-total-renegotiations", "1",
3910 },
3911 shouldFail: true,
3912 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3913 })
3914
3915 testCases = append(testCases, testCase{
3916 name: "ExtendedMasterSecret-Renego-Downgrade",
3917 config: Config{
3918 MaxVersion: VersionTLS12,
3919 Bugs: ProtocolBugs{
3920 NoExtendedMasterSecretOnRenegotiation: true,
3921 },
3922 },
3923 renegotiate: 1,
3924 flags: []string{
3925 "-renegotiate-freely",
3926 "-expect-total-renegotiations", "1",
3927 },
3928 shouldFail: true,
3929 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3930 })
Adam Langley75712922014-10-10 16:23:43 -07003931}
3932
David Benjamin582ba042016-07-07 12:33:25 -07003933type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003934 protocol protocol
3935 async bool
3936 splitHandshake bool
3937 packHandshakeFlight bool
3938 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003939}
3940
David Benjamin43ec06f2014-08-05 02:28:57 -04003941// Adds tests that try to cover the range of the handshake state machine, under
3942// various conditions. Some of these are redundant with other tests, but they
3943// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003944func addAllStateMachineCoverageTests() {
3945 for _, async := range []bool{false, true} {
3946 for _, protocol := range []protocol{tls, dtls} {
3947 addStateMachineCoverageTests(stateMachineTestConfig{
3948 protocol: protocol,
3949 async: async,
3950 })
3951 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003952 protocol: protocol,
3953 async: async,
3954 implicitHandshake: true,
3955 })
3956 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003957 protocol: protocol,
3958 async: async,
3959 splitHandshake: true,
3960 })
3961 if protocol == tls {
3962 addStateMachineCoverageTests(stateMachineTestConfig{
3963 protocol: protocol,
3964 async: async,
3965 packHandshakeFlight: true,
3966 })
3967 }
3968 }
3969 }
3970}
3971
3972func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003973 var tests []testCase
3974
3975 // Basic handshake, with resumption. Client and server,
3976 // session ID and session ticket.
3977 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003978 name: "Basic-Client",
3979 config: Config{
3980 MaxVersion: VersionTLS12,
3981 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003982 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003983 // Ensure session tickets are used, not session IDs.
3984 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003985 })
3986 tests = append(tests, testCase{
3987 name: "Basic-Client-RenewTicket",
3988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003989 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003990 Bugs: ProtocolBugs{
3991 RenewTicketOnResume: true,
3992 },
3993 },
David Benjamin46662482016-08-17 00:51:00 -04003994 flags: []string{"-expect-ticket-renewal"},
3995 resumeSession: true,
3996 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003997 })
3998 tests = append(tests, testCase{
3999 name: "Basic-Client-NoTicket",
4000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004001 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004002 SessionTicketsDisabled: true,
4003 },
4004 resumeSession: true,
4005 })
4006 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05004007 testType: serverTest,
4008 name: "Basic-Server",
4009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004010 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05004011 Bugs: ProtocolBugs{
4012 RequireSessionTickets: true,
4013 },
4014 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004015 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004016 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 })
4018 tests = append(tests, testCase{
4019 testType: serverTest,
4020 name: "Basic-Server-NoTickets",
4021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004022 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004023 SessionTicketsDisabled: true,
4024 },
4025 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004026 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004027 })
4028 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004029 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 name: "Basic-Server-EarlyCallback",
4031 config: Config{
4032 MaxVersion: VersionTLS12,
4033 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004034 flags: []string{"-use-early-callback"},
4035 resumeSession: true,
4036 })
4037
Steven Valdez143e8b32016-07-11 13:19:03 -04004038 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004039 if config.protocol == tls {
4040 tests = append(tests, testCase{
4041 name: "TLS13-1RTT-Client",
4042 config: Config{
4043 MaxVersion: VersionTLS13,
4044 MinVersion: VersionTLS13,
4045 },
David Benjamin46662482016-08-17 00:51:00 -04004046 resumeSession: true,
4047 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004048 })
4049
4050 tests = append(tests, testCase{
4051 testType: serverTest,
4052 name: "TLS13-1RTT-Server",
4053 config: Config{
4054 MaxVersion: VersionTLS13,
4055 MinVersion: VersionTLS13,
4056 },
David Benjamin46662482016-08-17 00:51:00 -04004057 resumeSession: true,
4058 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004059 // TLS 1.3 uses tickets, so the session should not be
4060 // cached statefully.
4061 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004062 })
4063
4064 tests = append(tests, testCase{
4065 name: "TLS13-HelloRetryRequest-Client",
4066 config: Config{
4067 MaxVersion: VersionTLS13,
4068 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004069 // P-384 requires a HelloRetryRequest against BoringSSL's default
4070 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004071 CurvePreferences: []CurveID{CurveP384},
4072 Bugs: ProtocolBugs{
4073 ExpectMissingKeyShare: true,
4074 },
4075 },
4076 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4077 resumeSession: true,
4078 })
4079
4080 tests = append(tests, testCase{
4081 testType: serverTest,
4082 name: "TLS13-HelloRetryRequest-Server",
4083 config: Config{
4084 MaxVersion: VersionTLS13,
4085 MinVersion: VersionTLS13,
4086 // Require a HelloRetryRequest for every curve.
4087 DefaultCurves: []CurveID{},
4088 },
4089 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4090 resumeSession: true,
4091 })
Steven Valdez2d850622017-01-11 11:34:52 -05004092
Steven Valdez2d850622017-01-11 11:34:52 -05004093 tests = append(tests, testCase{
4094 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004095 name: "TLS13-EarlyData-TooMuchData-Client",
4096 config: Config{
4097 MaxVersion: VersionTLS13,
4098 MinVersion: VersionTLS13,
4099 MaxEarlyDataSize: 2,
4100 },
4101 resumeConfig: &Config{
4102 MaxVersion: VersionTLS13,
4103 MinVersion: VersionTLS13,
4104 MaxEarlyDataSize: 2,
4105 Bugs: ProtocolBugs{
4106 ExpectEarlyData: [][]byte{{'h', 'e'}},
4107 },
4108 },
4109 resumeShimPrefix: "llo",
4110 resumeSession: true,
4111 flags: []string{
4112 "-enable-early-data",
4113 "-expect-early-data-info",
4114 "-expect-accept-early-data",
4115 "-on-resume-shim-writes-first",
4116 },
4117 })
4118
4119 // Unfinished writes can only be tested when operations are async. EarlyData
4120 // can't be tested as part of an ImplicitHandshake in this case since
4121 // otherwise the early data will be sent as normal data.
4122 if config.async && !config.implicitHandshake {
4123 tests = append(tests, testCase{
4124 testType: clientTest,
4125 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4126 config: Config{
4127 MaxVersion: VersionTLS13,
4128 MinVersion: VersionTLS13,
4129 MaxEarlyDataSize: 16384,
4130 },
4131 resumeConfig: &Config{
4132 MaxVersion: VersionTLS13,
4133 MinVersion: VersionTLS13,
4134 MaxEarlyDataSize: 16384,
4135 Bugs: ProtocolBugs{
4136 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4137 },
4138 },
4139 resumeSession: true,
4140 flags: []string{
4141 "-enable-early-data",
4142 "-expect-early-data-info",
4143 "-expect-accept-early-data",
4144 "-on-resume-read-with-unfinished-write",
4145 "-on-resume-shim-writes-first",
4146 },
4147 })
4148
4149 // Rejected unfinished writes are discarded (from the
4150 // perspective of the calling application) on 0-RTT
4151 // reject.
4152 tests = append(tests, testCase{
4153 testType: clientTest,
4154 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4155 config: Config{
4156 MaxVersion: VersionTLS13,
4157 MinVersion: VersionTLS13,
4158 MaxEarlyDataSize: 16384,
4159 },
4160 resumeConfig: &Config{
4161 MaxVersion: VersionTLS13,
4162 MinVersion: VersionTLS13,
4163 MaxEarlyDataSize: 16384,
4164 Bugs: ProtocolBugs{
4165 AlwaysRejectEarlyData: true,
4166 },
4167 },
4168 resumeSession: true,
4169 flags: []string{
4170 "-enable-early-data",
4171 "-expect-early-data-info",
4172 "-expect-reject-early-data",
4173 "-on-resume-read-with-unfinished-write",
4174 "-on-resume-shim-writes-first",
4175 },
4176 })
4177 }
4178
4179 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004180 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004181 name: "TLS13-MaxEarlyData-Server",
4182 config: Config{
4183 MaxVersion: VersionTLS13,
4184 MinVersion: VersionTLS13,
4185 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004186 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004187 ExpectEarlyDataAccepted: true,
4188 },
4189 },
4190 messageCount: 2,
4191 resumeSession: true,
4192 flags: []string{
4193 "-enable-early-data",
4194 "-expect-accept-early-data",
4195 },
4196 shouldFail: true,
4197 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4198 })
David Benjamine73c7f42016-08-17 00:29:33 -04004199 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004200
David Benjamin760b1dd2015-05-15 23:33:48 -04004201 // TLS client auth.
4202 tests = append(tests, testCase{
4203 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004204 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004206 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004207 ClientAuth: RequestClientCert,
4208 },
4209 })
4210 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004211 testType: serverTest,
4212 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004213 config: Config{
4214 MaxVersion: VersionTLS12,
4215 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004216 // Setting SSL_VERIFY_PEER allows anonymous clients.
4217 flags: []string{"-verify-peer"},
4218 })
David Benjamin582ba042016-07-07 12:33:25 -07004219 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004220 tests = append(tests, testCase{
4221 testType: clientTest,
4222 name: "ClientAuth-NoCertificate-Client-SSL3",
4223 config: Config{
4224 MaxVersion: VersionSSL30,
4225 ClientAuth: RequestClientCert,
4226 },
4227 })
4228 tests = append(tests, testCase{
4229 testType: serverTest,
4230 name: "ClientAuth-NoCertificate-Server-SSL3",
4231 config: Config{
4232 MaxVersion: VersionSSL30,
4233 },
4234 // Setting SSL_VERIFY_PEER allows anonymous clients.
4235 flags: []string{"-verify-peer"},
4236 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004237 tests = append(tests, testCase{
4238 testType: clientTest,
4239 name: "ClientAuth-NoCertificate-Client-TLS13",
4240 config: Config{
4241 MaxVersion: VersionTLS13,
4242 ClientAuth: RequestClientCert,
4243 },
4244 })
4245 tests = append(tests, testCase{
4246 testType: serverTest,
4247 name: "ClientAuth-NoCertificate-Server-TLS13",
4248 config: Config{
4249 MaxVersion: VersionTLS13,
4250 },
4251 // Setting SSL_VERIFY_PEER allows anonymous clients.
4252 flags: []string{"-verify-peer"},
4253 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004254 }
4255 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004256 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004257 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004259 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004260 ClientAuth: RequireAnyClientCert,
4261 },
4262 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004263 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4264 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004265 },
4266 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004267 tests = append(tests, testCase{
4268 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004269 name: "ClientAuth-RSA-Client-TLS13",
4270 config: Config{
4271 MaxVersion: VersionTLS13,
4272 ClientAuth: RequireAnyClientCert,
4273 },
4274 flags: []string{
4275 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4276 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4277 },
4278 })
4279 tests = append(tests, testCase{
4280 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004281 name: "ClientAuth-ECDSA-Client",
4282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004283 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004284 ClientAuth: RequireAnyClientCert,
4285 },
4286 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004287 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4288 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004289 },
4290 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004291 tests = append(tests, testCase{
4292 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004293 name: "ClientAuth-ECDSA-Client-TLS13",
4294 config: Config{
4295 MaxVersion: VersionTLS13,
4296 ClientAuth: RequireAnyClientCert,
4297 },
4298 flags: []string{
4299 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4300 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4301 },
4302 })
4303 tests = append(tests, testCase{
4304 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004305 name: "ClientAuth-NoCertificate-OldCallback",
4306 config: Config{
4307 MaxVersion: VersionTLS12,
4308 ClientAuth: RequestClientCert,
4309 },
4310 flags: []string{"-use-old-client-cert-callback"},
4311 })
4312 tests = append(tests, testCase{
4313 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004314 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4315 config: Config{
4316 MaxVersion: VersionTLS13,
4317 ClientAuth: RequestClientCert,
4318 },
4319 flags: []string{"-use-old-client-cert-callback"},
4320 })
4321 tests = append(tests, testCase{
4322 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004323 name: "ClientAuth-OldCallback",
4324 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004325 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004326 ClientAuth: RequireAnyClientCert,
4327 },
4328 flags: []string{
4329 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4330 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4331 "-use-old-client-cert-callback",
4332 },
4333 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004334 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004335 testType: clientTest,
4336 name: "ClientAuth-OldCallback-TLS13",
4337 config: Config{
4338 MaxVersion: VersionTLS13,
4339 ClientAuth: RequireAnyClientCert,
4340 },
4341 flags: []string{
4342 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4343 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4344 "-use-old-client-cert-callback",
4345 },
4346 })
4347 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004348 testType: serverTest,
4349 name: "ClientAuth-Server",
4350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004351 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004352 Certificates: []Certificate{rsaCertificate},
4353 },
4354 flags: []string{"-require-any-client-certificate"},
4355 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004356 tests = append(tests, testCase{
4357 testType: serverTest,
4358 name: "ClientAuth-Server-TLS13",
4359 config: Config{
4360 MaxVersion: VersionTLS13,
4361 Certificates: []Certificate{rsaCertificate},
4362 },
4363 flags: []string{"-require-any-client-certificate"},
4364 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004365
David Benjamin4c3ddf72016-06-29 18:13:53 -04004366 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004367 tests = append(tests, testCase{
4368 testType: serverTest,
4369 name: "Basic-Server-RSA",
4370 config: Config{
4371 MaxVersion: VersionTLS12,
4372 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4373 },
4374 flags: []string{
4375 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4376 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4377 },
4378 })
4379 tests = append(tests, testCase{
4380 testType: serverTest,
4381 name: "Basic-Server-ECDHE-RSA",
4382 config: Config{
4383 MaxVersion: VersionTLS12,
4384 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4385 },
4386 flags: []string{
4387 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4388 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4389 },
4390 })
4391 tests = append(tests, testCase{
4392 testType: serverTest,
4393 name: "Basic-Server-ECDHE-ECDSA",
4394 config: Config{
4395 MaxVersion: VersionTLS12,
4396 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4397 },
4398 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004399 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4400 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004401 },
4402 })
David Benjamin69522112017-03-28 15:38:29 -05004403 tests = append(tests, testCase{
4404 testType: serverTest,
4405 name: "Basic-Server-Ed25519",
4406 config: Config{
4407 MaxVersion: VersionTLS12,
4408 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4409 },
4410 flags: []string{
4411 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4412 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4413 "-enable-ed25519",
4414 },
4415 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004416
David Benjamin760b1dd2015-05-15 23:33:48 -04004417 // No session ticket support; server doesn't send NewSessionTicket.
4418 tests = append(tests, testCase{
4419 name: "SessionTicketsDisabled-Client",
4420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004421 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004422 SessionTicketsDisabled: true,
4423 },
4424 })
4425 tests = append(tests, testCase{
4426 testType: serverTest,
4427 name: "SessionTicketsDisabled-Server",
4428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004429 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004430 SessionTicketsDisabled: true,
4431 },
4432 })
4433
4434 // Skip ServerKeyExchange in PSK key exchange if there's no
4435 // identity hint.
4436 tests = append(tests, testCase{
4437 name: "EmptyPSKHint-Client",
4438 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004439 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004440 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4441 PreSharedKey: []byte("secret"),
4442 },
4443 flags: []string{"-psk", "secret"},
4444 })
4445 tests = append(tests, testCase{
4446 testType: serverTest,
4447 name: "EmptyPSKHint-Server",
4448 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004449 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004450 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4451 PreSharedKey: []byte("secret"),
4452 },
4453 flags: []string{"-psk", "secret"},
4454 })
4455
David Benjamin4c3ddf72016-06-29 18:13:53 -04004456 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004457 tests = append(tests, testCase{
4458 testType: clientTest,
4459 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 config: Config{
4461 MaxVersion: VersionTLS12,
4462 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004463 flags: []string{
4464 "-enable-ocsp-stapling",
4465 "-expect-ocsp-response",
4466 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004467 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004468 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004469 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004470 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004471 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004472 testType: serverTest,
4473 name: "OCSPStapling-Server",
4474 config: Config{
4475 MaxVersion: VersionTLS12,
4476 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004477 expectedOCSPResponse: testOCSPResponse,
4478 flags: []string{
4479 "-ocsp-response",
4480 base64.StdEncoding.EncodeToString(testOCSPResponse),
4481 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004482 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004483 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004484 tests = append(tests, testCase{
4485 testType: clientTest,
4486 name: "OCSPStapling-Client-TLS13",
4487 config: Config{
4488 MaxVersion: VersionTLS13,
4489 },
4490 flags: []string{
4491 "-enable-ocsp-stapling",
4492 "-expect-ocsp-response",
4493 base64.StdEncoding.EncodeToString(testOCSPResponse),
4494 "-verify-peer",
4495 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004496 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004497 })
4498 tests = append(tests, testCase{
4499 testType: serverTest,
4500 name: "OCSPStapling-Server-TLS13",
4501 config: Config{
4502 MaxVersion: VersionTLS13,
4503 },
4504 expectedOCSPResponse: testOCSPResponse,
4505 flags: []string{
4506 "-ocsp-response",
4507 base64.StdEncoding.EncodeToString(testOCSPResponse),
4508 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004509 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004510 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004511
David Benjamin4c3ddf72016-06-29 18:13:53 -04004512 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004513 for _, vers := range tlsVersions {
4514 if config.protocol == dtls && !vers.hasDTLS {
4515 continue
4516 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004517 for _, useCustomCallback := range []bool{false, true} {
4518 for _, testType := range []testType{clientTest, serverTest} {
4519 suffix := "-Client"
4520 if testType == serverTest {
4521 suffix = "-Server"
4522 }
4523 suffix += "-" + vers.name
4524 if useCustomCallback {
4525 suffix += "-CustomCallback"
4526 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004527
David Benjamin3a1dd462017-07-11 16:13:10 -04004528 flags := []string{"-verify-peer"}
4529 if testType == serverTest {
4530 flags = append(flags, "-require-any-client-certificate")
4531 }
4532 if useCustomCallback {
4533 flags = append(flags, "-use-custom-verify-callback")
4534 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004535
David Benjamin3a1dd462017-07-11 16:13:10 -04004536 tests = append(tests, testCase{
4537 testType: testType,
4538 name: "CertificateVerificationSucceed" + suffix,
4539 config: Config{
4540 MaxVersion: vers.version,
4541 Certificates: []Certificate{rsaCertificate},
4542 },
4543 tls13Variant: vers.tls13Variant,
4544 flags: append([]string{"-expect-verify-result"}, flags...),
4545 resumeSession: true,
4546 })
4547 tests = append(tests, testCase{
4548 testType: testType,
4549 name: "CertificateVerificationFail" + suffix,
4550 config: Config{
4551 MaxVersion: vers.version,
4552 Certificates: []Certificate{rsaCertificate},
4553 },
4554 tls13Variant: vers.tls13Variant,
4555 flags: append([]string{"-verify-fail"}, flags...),
4556 shouldFail: true,
4557 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4558 })
4559 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004560 }
4561
4562 // By default, the client is in a soft fail mode where the peer
4563 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004564 tests = append(tests, testCase{
4565 testType: clientTest,
4566 name: "CertificateVerificationSoftFail-" + vers.name,
4567 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004568 MaxVersion: vers.version,
4569 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004570 },
David Benjamina5022392017-07-10 17:40:39 -04004571 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004572 flags: []string{
4573 "-verify-fail",
4574 "-expect-verify-result",
4575 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004576 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004577 })
4578 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004579
David Benjamin1d4f4c02016-07-26 18:03:08 -04004580 tests = append(tests, testCase{
4581 name: "ShimSendAlert",
4582 flags: []string{"-send-alert"},
4583 shimWritesFirst: true,
4584 shouldFail: true,
4585 expectedLocalError: "remote error: decompression failure",
4586 })
4587
David Benjamin582ba042016-07-07 12:33:25 -07004588 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004589 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004590 name: "Renegotiate-Client",
4591 config: Config{
4592 MaxVersion: VersionTLS12,
4593 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004594 renegotiate: 1,
4595 flags: []string{
4596 "-renegotiate-freely",
4597 "-expect-total-renegotiations", "1",
4598 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004599 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004600
David Benjamin47921102016-07-28 11:29:18 -04004601 tests = append(tests, testCase{
4602 name: "SendHalfHelloRequest",
4603 config: Config{
4604 MaxVersion: VersionTLS12,
4605 Bugs: ProtocolBugs{
4606 PackHelloRequestWithFinished: config.packHandshakeFlight,
4607 },
4608 },
4609 sendHalfHelloRequest: true,
4610 flags: []string{"-renegotiate-ignore"},
4611 shouldFail: true,
4612 expectedError: ":UNEXPECTED_RECORD:",
4613 })
4614
David Benjamin760b1dd2015-05-15 23:33:48 -04004615 // NPN on client and server; results in post-handshake message.
4616 tests = append(tests, testCase{
4617 name: "NPN-Client",
4618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004619 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004620 NextProtos: []string{"foo"},
4621 },
4622 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004623 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004624 expectedNextProto: "foo",
4625 expectedNextProtoType: npn,
4626 })
4627 tests = append(tests, testCase{
4628 testType: serverTest,
4629 name: "NPN-Server",
4630 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004631 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004632 NextProtos: []string{"bar"},
4633 },
4634 flags: []string{
4635 "-advertise-npn", "\x03foo\x03bar\x03baz",
4636 "-expect-next-proto", "bar",
4637 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004638 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004639 expectedNextProto: "bar",
4640 expectedNextProtoType: npn,
4641 })
4642
4643 // TODO(davidben): Add tests for when False Start doesn't trigger.
4644
4645 // Client does False Start and negotiates NPN.
4646 tests = append(tests, testCase{
4647 name: "FalseStart",
4648 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004649 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004650 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4651 NextProtos: []string{"foo"},
4652 Bugs: ProtocolBugs{
4653 ExpectFalseStart: true,
4654 },
4655 },
4656 flags: []string{
4657 "-false-start",
4658 "-select-next-proto", "foo",
4659 },
4660 shimWritesFirst: true,
4661 resumeSession: true,
4662 })
4663
4664 // Client does False Start and negotiates ALPN.
4665 tests = append(tests, testCase{
4666 name: "FalseStart-ALPN",
4667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004668 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4670 NextProtos: []string{"foo"},
4671 Bugs: ProtocolBugs{
4672 ExpectFalseStart: true,
4673 },
4674 },
4675 flags: []string{
4676 "-false-start",
4677 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004678 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004679 },
4680 shimWritesFirst: true,
4681 resumeSession: true,
4682 })
4683
David Benjamin760b1dd2015-05-15 23:33:48 -04004684 // False Start without session tickets.
4685 tests = append(tests, testCase{
4686 name: "FalseStart-SessionTicketsDisabled",
4687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4690 NextProtos: []string{"foo"},
4691 SessionTicketsDisabled: true,
4692 Bugs: ProtocolBugs{
4693 ExpectFalseStart: true,
4694 },
4695 },
4696 flags: []string{
4697 "-false-start",
4698 "-select-next-proto", "foo",
4699 },
4700 shimWritesFirst: true,
4701 })
4702
4703 // Server parses a V2ClientHello.
4704 tests = append(tests, testCase{
4705 testType: serverTest,
4706 name: "SendV2ClientHello",
4707 config: Config{
4708 // Choose a cipher suite that does not involve
4709 // elliptic curves, so no extensions are
4710 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004711 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004712 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004713 Bugs: ProtocolBugs{
4714 SendV2ClientHello: true,
4715 },
4716 },
David Benjamin78b8b992017-08-01 18:38:41 -04004717 flags: []string{
4718 "-expect-msg-callback",
4719 `read v2clienthello
4720write hs 2
4721write hs 11
4722write hs 14
4723read hs 16
4724read ccs
4725read hs 20
4726write ccs
4727write hs 20
4728read alert 1 0
4729`,
4730 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004731 })
4732
Nick Harper60a85cb2016-09-23 16:25:11 -07004733 // Test Channel ID
4734 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004735 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004736 continue
4737 }
4738 // Client sends a Channel ID.
4739 tests = append(tests, testCase{
4740 name: "ChannelID-Client-" + ver.name,
4741 config: Config{
4742 MaxVersion: ver.version,
4743 RequestChannelID: true,
4744 },
David Benjamina5022392017-07-10 17:40:39 -04004745 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004746 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4747 resumeSession: true,
4748 expectChannelID: true,
4749 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004750
Nick Harper60a85cb2016-09-23 16:25:11 -07004751 // Server accepts a Channel ID.
4752 tests = append(tests, testCase{
4753 testType: serverTest,
4754 name: "ChannelID-Server-" + ver.name,
4755 config: Config{
4756 MaxVersion: ver.version,
4757 ChannelID: channelIDKey,
4758 },
David Benjamina5022392017-07-10 17:40:39 -04004759 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004760 flags: []string{
4761 "-expect-channel-id",
4762 base64.StdEncoding.EncodeToString(channelIDBytes),
4763 },
4764 resumeSession: true,
4765 expectChannelID: true,
4766 })
4767
4768 tests = append(tests, testCase{
4769 testType: serverTest,
4770 name: "InvalidChannelIDSignature-" + ver.name,
4771 config: Config{
4772 MaxVersion: ver.version,
4773 ChannelID: channelIDKey,
4774 Bugs: ProtocolBugs{
4775 InvalidChannelIDSignature: true,
4776 },
4777 },
David Benjamina5022392017-07-10 17:40:39 -04004778 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004779 flags: []string{"-enable-channel-id"},
4780 shouldFail: true,
4781 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4782 })
David Benjamin634f4752017-07-01 11:08:41 -04004783
4784 if ver.version < VersionTLS13 {
4785 // Channel ID requires ECDHE ciphers.
4786 tests = append(tests, testCase{
4787 testType: serverTest,
4788 name: "ChannelID-NoECDHE-" + ver.name,
4789 config: Config{
4790 MaxVersion: ver.version,
4791 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4792 ChannelID: channelIDKey,
4793 },
4794 expectChannelID: false,
4795 flags: []string{"-enable-channel-id"},
4796 })
4797
4798 // Sanity-check setting expectChannelID false works.
4799 tests = append(tests, testCase{
4800 testType: serverTest,
4801 name: "ChannelID-ECDHE-" + ver.name,
4802 config: Config{
4803 MaxVersion: ver.version,
4804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4805 ChannelID: channelIDKey,
4806 },
4807 expectChannelID: false,
4808 flags: []string{"-enable-channel-id"},
4809 shouldFail: true,
4810 expectedLocalError: "channel ID unexpectedly negotiated",
4811 })
4812 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004813 }
David Benjamin30789da2015-08-29 22:56:45 -04004814
David Benjaminf8fcdf32016-06-08 15:56:13 -04004815 // Channel ID and NPN at the same time, to ensure their relative
4816 // ordering is correct.
4817 tests = append(tests, testCase{
4818 name: "ChannelID-NPN-Client",
4819 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004820 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004821 RequestChannelID: true,
4822 NextProtos: []string{"foo"},
4823 },
4824 flags: []string{
4825 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4826 "-select-next-proto", "foo",
4827 },
4828 resumeSession: true,
4829 expectChannelID: true,
4830 expectedNextProto: "foo",
4831 expectedNextProtoType: npn,
4832 })
4833 tests = append(tests, testCase{
4834 testType: serverTest,
4835 name: "ChannelID-NPN-Server",
4836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004837 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004838 ChannelID: channelIDKey,
4839 NextProtos: []string{"bar"},
4840 },
4841 flags: []string{
4842 "-expect-channel-id",
4843 base64.StdEncoding.EncodeToString(channelIDBytes),
4844 "-advertise-npn", "\x03foo\x03bar\x03baz",
4845 "-expect-next-proto", "bar",
4846 },
4847 resumeSession: true,
4848 expectChannelID: true,
4849 expectedNextProto: "bar",
4850 expectedNextProtoType: npn,
4851 })
4852
David Benjamin30789da2015-08-29 22:56:45 -04004853 // Bidirectional shutdown with the runner initiating.
4854 tests = append(tests, testCase{
4855 name: "Shutdown-Runner",
4856 config: Config{
4857 Bugs: ProtocolBugs{
4858 ExpectCloseNotify: true,
4859 },
4860 },
4861 flags: []string{"-check-close-notify"},
4862 })
4863
David Benjamine3843d42017-03-25 18:00:56 -05004864 if !config.implicitHandshake {
4865 // Bidirectional shutdown with the shim initiating. The runner,
4866 // in the meantime, sends garbage before the close_notify which
4867 // the shim must ignore. This test is disabled under implicit
4868 // handshake tests because the shim never reads or writes.
4869 tests = append(tests, testCase{
4870 name: "Shutdown-Shim",
4871 config: Config{
4872 MaxVersion: VersionTLS12,
4873 Bugs: ProtocolBugs{
4874 ExpectCloseNotify: true,
4875 },
David Benjamin30789da2015-08-29 22:56:45 -04004876 },
David Benjamine3843d42017-03-25 18:00:56 -05004877 shimShutsDown: true,
4878 sendEmptyRecords: 1,
4879 sendWarningAlerts: 1,
4880 flags: []string{"-check-close-notify"},
4881 })
4882 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004883 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004884 // TODO(davidben): DTLS 1.3 will want a similar thing for
4885 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004886 tests = append(tests, testCase{
4887 name: "SkipHelloVerifyRequest",
4888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004889 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004890 Bugs: ProtocolBugs{
4891 SkipHelloVerifyRequest: true,
4892 },
4893 },
4894 })
4895 }
4896
David Benjamin760b1dd2015-05-15 23:33:48 -04004897 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004898 test.protocol = config.protocol
4899 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004900 test.name += "-DTLS"
4901 }
David Benjamin582ba042016-07-07 12:33:25 -07004902 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004903 test.name += "-Async"
4904 test.flags = append(test.flags, "-async")
4905 } else {
4906 test.name += "-Sync"
4907 }
David Benjamin582ba042016-07-07 12:33:25 -07004908 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004909 test.name += "-SplitHandshakeRecords"
4910 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004911 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004912 test.config.Bugs.MaxPacketLength = 256
4913 test.flags = append(test.flags, "-mtu", "256")
4914 }
4915 }
David Benjamin582ba042016-07-07 12:33:25 -07004916 if config.packHandshakeFlight {
4917 test.name += "-PackHandshakeFlight"
4918 test.config.Bugs.PackHandshakeFlight = true
4919 }
David Benjamine3843d42017-03-25 18:00:56 -05004920 if config.implicitHandshake {
4921 test.name += "-ImplicitHandshake"
4922 test.flags = append(test.flags, "-implicit-handshake")
4923 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004924 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004925 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004926}
4927
Adam Langley524e7172015-02-20 16:04:00 -08004928func addDDoSCallbackTests() {
4929 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004930 for _, resume := range []bool{false, true} {
4931 suffix := "Resume"
4932 if resume {
4933 suffix = "No" + suffix
4934 }
4935
4936 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004937 testType: serverTest,
4938 name: "Server-DDoS-OK-" + suffix,
4939 config: Config{
4940 MaxVersion: VersionTLS12,
4941 },
Adam Langley524e7172015-02-20 16:04:00 -08004942 flags: []string{"-install-ddos-callback"},
4943 resumeSession: resume,
4944 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004945 testCases = append(testCases, testCase{
4946 testType: serverTest,
4947 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4948 config: Config{
4949 MaxVersion: VersionTLS13,
4950 },
4951 flags: []string{"-install-ddos-callback"},
4952 resumeSession: resume,
4953 })
Adam Langley524e7172015-02-20 16:04:00 -08004954
4955 failFlag := "-fail-ddos-callback"
4956 if resume {
4957 failFlag = "-fail-second-ddos-callback"
4958 }
4959 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004960 testType: serverTest,
4961 name: "Server-DDoS-Reject-" + suffix,
4962 config: Config{
4963 MaxVersion: VersionTLS12,
4964 },
David Benjamin2c66e072016-09-16 15:58:00 -04004965 flags: []string{"-install-ddos-callback", failFlag},
4966 resumeSession: resume,
4967 shouldFail: true,
4968 expectedError: ":CONNECTION_REJECTED:",
4969 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004970 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004971 testCases = append(testCases, testCase{
4972 testType: serverTest,
4973 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4974 config: Config{
4975 MaxVersion: VersionTLS13,
4976 },
David Benjamin2c66e072016-09-16 15:58:00 -04004977 flags: []string{"-install-ddos-callback", failFlag},
4978 resumeSession: resume,
4979 shouldFail: true,
4980 expectedError: ":CONNECTION_REJECTED:",
4981 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004982 })
Adam Langley524e7172015-02-20 16:04:00 -08004983 }
4984}
4985
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004986func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04004987 for _, protocol := range []protocol{tls, dtls} {
4988 for _, shimVers := range allVersions(protocol) {
4989 // Assemble flags to disable all newer versions on the shim.
4990 var flags []string
4991 for _, vers := range allVersions(protocol) {
4992 if vers.version > shimVers.version {
4993 flags = append(flags, vers.excludeFlag)
4994 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004995 }
Steven Valdez520e1222017-06-13 12:45:25 -04004996
4997 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
4998
4999 if shimVers.tls13Variant != 0 {
5000 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5001 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5002 }
5003
5004 // Test configuring the runner's maximum version.
5005 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005006 expectedVersion := shimVers.version
5007 if runnerVers.version < shimVers.version {
5008 expectedVersion = runnerVers.version
5009 }
Steven Valdez520e1222017-06-13 12:45:25 -04005010 // When running and shim have different TLS 1.3 variants enabled,
5011 // shim clients are expected to fall back to TLS 1.2, while shim
5012 // servers support both variants when enabled when the experiment is
5013 // enabled.
5014 expectedServerVersion := expectedVersion
5015 expectedClientVersion := expectedVersion
5016 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5017 expectedClientVersion = VersionTLS12
5018 expectedServerVersion = VersionTLS12
5019 if shimVers.tls13Variant != TLS13Default {
5020 expectedServerVersion = VersionTLS13
5021 }
5022 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005023
David Benjamin8b8c0062014-11-23 02:47:52 -05005024 suffix := shimVers.name + "-" + runnerVers.name
5025 if protocol == dtls {
5026 suffix += "-DTLS"
5027 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005028
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005029 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005030 clientVers := shimVers.version
5031 if clientVers > VersionTLS10 {
5032 clientVers = VersionTLS10
5033 }
Steven Valdez520e1222017-06-13 12:45:25 -04005034 clientVers = recordVersionToWire(clientVers, protocol)
5035 serverVers := expectedServerVersion
5036 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005037 serverVers = VersionTLS10
Steven Valdezc7d4d212017-09-11 13:53:08 -04005038 if runnerVers.tls13Variant == TLS13Experiment2 || runnerVers.tls13Variant == TLS13Experiment3 {
Steven Valdez16821262017-09-08 17:03:42 -04005039 serverVers = VersionTLS12
5040 }
Nick Harper1fd39d82016-06-14 18:14:35 -07005041 }
Steven Valdez520e1222017-06-13 12:45:25 -04005042 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005043
David Benjamin8b8c0062014-11-23 02:47:52 -05005044 testCases = append(testCases, testCase{
5045 protocol: protocol,
5046 testType: clientTest,
5047 name: "VersionNegotiation-Client-" + suffix,
5048 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005049 MaxVersion: runnerVers.version,
5050 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005051 Bugs: ProtocolBugs{
5052 ExpectInitialRecordVersion: clientVers,
5053 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005054 },
5055 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005056 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005057 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005058 testCases = append(testCases, testCase{
5059 protocol: protocol,
5060 testType: clientTest,
5061 name: "VersionNegotiation-Client2-" + suffix,
5062 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005063 MaxVersion: runnerVers.version,
5064 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005065 Bugs: ProtocolBugs{
5066 ExpectInitialRecordVersion: clientVers,
5067 },
5068 },
Steven Valdez520e1222017-06-13 12:45:25 -04005069 flags: flags2,
5070 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005071 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005072
5073 testCases = append(testCases, testCase{
5074 protocol: protocol,
5075 testType: serverTest,
5076 name: "VersionNegotiation-Server-" + suffix,
5077 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005078 MaxVersion: runnerVers.version,
5079 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005080 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005081 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005082 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005083 },
5084 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005085 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005086 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005087 testCases = append(testCases, testCase{
5088 protocol: protocol,
5089 testType: serverTest,
5090 name: "VersionNegotiation-Server2-" + suffix,
5091 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005092 MaxVersion: runnerVers.version,
5093 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005094 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005095 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005096 },
5097 },
Steven Valdez520e1222017-06-13 12:45:25 -04005098 flags: flags2,
5099 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005100 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005101 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005102 }
5103 }
David Benjamin95c69562016-06-29 18:15:03 -04005104
Steven Valdezfdd10992016-09-15 16:27:05 -04005105 // Test the version extension at all versions.
5106 for _, vers := range tlsVersions {
5107 protocols := []protocol{tls}
5108 if vers.hasDTLS {
5109 protocols = append(protocols, dtls)
5110 }
5111 for _, protocol := range protocols {
5112 suffix := vers.name
5113 if protocol == dtls {
5114 suffix += "-DTLS"
5115 }
5116
Steven Valdezfdd10992016-09-15 16:27:05 -04005117 testCases = append(testCases, testCase{
5118 protocol: protocol,
5119 testType: serverTest,
5120 name: "VersionNegotiationExtension-" + suffix,
5121 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005122 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005123 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005124 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005125 },
5126 },
5127 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005128 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005129 })
5130 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005131 }
5132
5133 // If all versions are unknown, negotiation fails.
5134 testCases = append(testCases, testCase{
5135 testType: serverTest,
5136 name: "NoSupportedVersions",
5137 config: Config{
5138 Bugs: ProtocolBugs{
5139 SendSupportedVersions: []uint16{0x1111},
5140 },
5141 },
5142 shouldFail: true,
5143 expectedError: ":UNSUPPORTED_PROTOCOL:",
5144 })
5145 testCases = append(testCases, testCase{
5146 protocol: dtls,
5147 testType: serverTest,
5148 name: "NoSupportedVersions-DTLS",
5149 config: Config{
5150 Bugs: ProtocolBugs{
5151 SendSupportedVersions: []uint16{0x1111},
5152 },
5153 },
5154 shouldFail: true,
5155 expectedError: ":UNSUPPORTED_PROTOCOL:",
5156 })
5157
5158 testCases = append(testCases, testCase{
5159 testType: serverTest,
5160 name: "ClientHelloVersionTooHigh",
5161 config: Config{
5162 MaxVersion: VersionTLS13,
5163 Bugs: ProtocolBugs{
5164 SendClientVersion: 0x0304,
5165 OmitSupportedVersions: true,
5166 },
5167 },
5168 expectedVersion: VersionTLS12,
5169 })
5170
5171 testCases = append(testCases, testCase{
5172 testType: serverTest,
5173 name: "ConflictingVersionNegotiation",
5174 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005175 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005176 SendClientVersion: VersionTLS12,
5177 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005178 },
5179 },
David Benjaminad75a662016-09-30 15:42:59 -04005180 // The extension takes precedence over the ClientHello version.
5181 expectedVersion: VersionTLS11,
5182 })
5183
5184 testCases = append(testCases, testCase{
5185 testType: serverTest,
5186 name: "ConflictingVersionNegotiation-2",
5187 config: Config{
5188 Bugs: ProtocolBugs{
5189 SendClientVersion: VersionTLS11,
5190 SendSupportedVersions: []uint16{VersionTLS12},
5191 },
5192 },
5193 // The extension takes precedence over the ClientHello version.
5194 expectedVersion: VersionTLS12,
5195 })
5196
5197 testCases = append(testCases, testCase{
5198 testType: serverTest,
5199 name: "RejectFinalTLS13",
5200 config: Config{
5201 Bugs: ProtocolBugs{
5202 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5203 },
5204 },
5205 // We currently implement a draft TLS 1.3 version. Ensure that
5206 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005207 expectedVersion: VersionTLS12,
5208 })
5209
Steven Valdez038da9b2017-07-10 12:57:25 -04005210 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5211 // the ServerHello.
5212 testCases = append(testCases, testCase{
5213 testType: clientTest,
5214 name: "SupportedVersionSelection-TLS12",
5215 config: Config{
5216 MaxVersion: VersionTLS12,
5217 Bugs: ProtocolBugs{
5218 SendServerSupportedExtensionVersion: VersionTLS12,
5219 },
5220 },
5221 shouldFail: true,
5222 expectedError: ":UNEXPECTED_EXTENSION:",
5223 })
5224
5225 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5226 // supported_versions extension in the ServerHello.
5227 testCases = append(testCases, testCase{
5228 testType: clientTest,
5229 name: "SupportedVersionSelection-TLS13",
5230 config: Config{
5231 MaxVersion: VersionTLS13,
5232 Bugs: ProtocolBugs{
5233 SendServerSupportedExtensionVersion: tls13DraftVersion,
5234 },
5235 },
5236 shouldFail: true,
5237 expectedError: ":UNEXPECTED_EXTENSION:",
5238 })
5239
Brian Smithf85d3232016-10-28 10:34:06 -10005240 // Test that the maximum version is selected regardless of the
5241 // client-sent order.
5242 testCases = append(testCases, testCase{
5243 testType: serverTest,
5244 name: "IgnoreClientVersionOrder",
5245 config: Config{
5246 Bugs: ProtocolBugs{
5247 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5248 },
5249 },
5250 expectedVersion: VersionTLS13,
5251 })
5252
David Benjamin95c69562016-06-29 18:15:03 -04005253 // Test for version tolerance.
5254 testCases = append(testCases, testCase{
5255 testType: serverTest,
5256 name: "MinorVersionTolerance",
5257 config: Config{
5258 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005259 SendClientVersion: 0x03ff,
5260 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005261 },
5262 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005263 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005264 })
5265 testCases = append(testCases, testCase{
5266 testType: serverTest,
5267 name: "MajorVersionTolerance",
5268 config: Config{
5269 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005270 SendClientVersion: 0x0400,
5271 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005272 },
5273 },
David Benjaminad75a662016-09-30 15:42:59 -04005274 // TLS 1.3 must be negotiated with the supported_versions
5275 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005276 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005277 })
David Benjaminad75a662016-09-30 15:42:59 -04005278 testCases = append(testCases, testCase{
5279 testType: serverTest,
5280 name: "VersionTolerance-TLS13",
5281 config: Config{
5282 Bugs: ProtocolBugs{
5283 // Although TLS 1.3 does not use
5284 // ClientHello.version, it still tolerates high
5285 // values there.
5286 SendClientVersion: 0x0400,
5287 },
5288 },
5289 expectedVersion: VersionTLS13,
5290 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005291
David Benjamin95c69562016-06-29 18:15:03 -04005292 testCases = append(testCases, testCase{
5293 protocol: dtls,
5294 testType: serverTest,
5295 name: "MinorVersionTolerance-DTLS",
5296 config: Config{
5297 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005298 SendClientVersion: 0xfe00,
5299 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005300 },
5301 },
5302 expectedVersion: VersionTLS12,
5303 })
5304 testCases = append(testCases, testCase{
5305 protocol: dtls,
5306 testType: serverTest,
5307 name: "MajorVersionTolerance-DTLS",
5308 config: Config{
5309 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005310 SendClientVersion: 0xfdff,
5311 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005312 },
5313 },
5314 expectedVersion: VersionTLS12,
5315 })
5316
5317 // Test that versions below 3.0 are rejected.
5318 testCases = append(testCases, testCase{
5319 testType: serverTest,
5320 name: "VersionTooLow",
5321 config: Config{
5322 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005323 SendClientVersion: 0x0200,
5324 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005325 },
5326 },
5327 shouldFail: true,
5328 expectedError: ":UNSUPPORTED_PROTOCOL:",
5329 })
5330 testCases = append(testCases, testCase{
5331 protocol: dtls,
5332 testType: serverTest,
5333 name: "VersionTooLow-DTLS",
5334 config: Config{
5335 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005336 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005337 },
5338 },
5339 shouldFail: true,
5340 expectedError: ":UNSUPPORTED_PROTOCOL:",
5341 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005342
David Benjamin2dc02042016-09-19 19:57:37 -04005343 testCases = append(testCases, testCase{
5344 name: "ServerBogusVersion",
5345 config: Config{
5346 Bugs: ProtocolBugs{
5347 SendServerHelloVersion: 0x1234,
5348 },
5349 },
5350 shouldFail: true,
5351 expectedError: ":UNSUPPORTED_PROTOCOL:",
5352 })
5353
David Benjamin1f61f0d2016-07-10 12:20:35 -04005354 // Test TLS 1.3's downgrade signal.
5355 testCases = append(testCases, testCase{
5356 name: "Downgrade-TLS12-Client",
5357 config: Config{
5358 Bugs: ProtocolBugs{
5359 NegotiateVersion: VersionTLS12,
5360 },
5361 },
David Benjamin592b5322016-09-30 15:15:01 -04005362 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005363 // TODO(davidben): This test should fail once TLS 1.3 is final
5364 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005365 })
5366 testCases = append(testCases, testCase{
5367 testType: serverTest,
5368 name: "Downgrade-TLS12-Server",
5369 config: Config{
5370 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005371 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005372 },
5373 },
David Benjamin592b5322016-09-30 15:15:01 -04005374 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005375 // TODO(davidben): This test should fail once TLS 1.3 is final
5376 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005377 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005378}
5379
David Benjaminaccb4542014-12-12 23:44:33 -05005380func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005381 for _, protocol := range []protocol{tls, dtls} {
5382 for _, shimVers := range allVersions(protocol) {
5383 // Assemble flags to disable all older versions on the shim.
5384 var flags []string
5385 for _, vers := range allVersions(protocol) {
5386 if vers.version < shimVers.version {
5387 flags = append(flags, vers.excludeFlag)
5388 }
David Benjaminaccb4542014-12-12 23:44:33 -05005389 }
Steven Valdez520e1222017-06-13 12:45:25 -04005390
5391 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5392
5393 if shimVers.tls13Variant != 0 {
5394 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5395 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5396 }
5397
5398 for _, runnerVers := range allVersions(protocol) {
5399 // Different TLS 1.3 variants are incompatible with each other and don't
5400 // produce consistent minimum versions.
5401 //
5402 // TODO(davidben): Fold these tests (the main value is in the
5403 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5404 // on intended shim behavior, not the shim + runner combination.
5405 if shimVers.tls13Variant != runnerVers.tls13Variant {
5406 continue
5407 }
5408
David Benjaminaccb4542014-12-12 23:44:33 -05005409 suffix := shimVers.name + "-" + runnerVers.name
5410 if protocol == dtls {
5411 suffix += "-DTLS"
5412 }
David Benjaminaccb4542014-12-12 23:44:33 -05005413
David Benjaminaccb4542014-12-12 23:44:33 -05005414 var expectedVersion uint16
5415 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005416 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005417 if runnerVers.version >= shimVers.version {
5418 expectedVersion = runnerVers.version
5419 } else {
5420 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005421 expectedError = ":UNSUPPORTED_PROTOCOL:"
5422 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005423 }
5424
5425 testCases = append(testCases, testCase{
5426 protocol: protocol,
5427 testType: clientTest,
5428 name: "MinimumVersion-Client-" + suffix,
5429 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005430 MaxVersion: runnerVers.version,
5431 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005432 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005433 // Ensure the server does not decline to
5434 // select a version (versions extension) or
5435 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005436 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005437 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005438 },
David Benjaminaccb4542014-12-12 23:44:33 -05005439 },
David Benjamin87909c02014-12-13 01:55:01 -05005440 flags: flags,
5441 expectedVersion: expectedVersion,
5442 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005443 expectedError: expectedError,
5444 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005445 })
5446 testCases = append(testCases, testCase{
5447 protocol: protocol,
5448 testType: clientTest,
5449 name: "MinimumVersion-Client2-" + suffix,
5450 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005451 MaxVersion: runnerVers.version,
5452 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005453 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005454 // Ensure the server does not decline to
5455 // select a version (versions extension) or
5456 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005457 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005458 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005459 },
David Benjaminaccb4542014-12-12 23:44:33 -05005460 },
Steven Valdez520e1222017-06-13 12:45:25 -04005461 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005462 expectedVersion: expectedVersion,
5463 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005464 expectedError: expectedError,
5465 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005466 })
5467
5468 testCases = append(testCases, testCase{
5469 protocol: protocol,
5470 testType: serverTest,
5471 name: "MinimumVersion-Server-" + suffix,
5472 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005473 MaxVersion: runnerVers.version,
5474 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005475 },
David Benjamin87909c02014-12-13 01:55:01 -05005476 flags: flags,
5477 expectedVersion: expectedVersion,
5478 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005479 expectedError: expectedError,
5480 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005481 })
5482 testCases = append(testCases, testCase{
5483 protocol: protocol,
5484 testType: serverTest,
5485 name: "MinimumVersion-Server2-" + suffix,
5486 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005487 MaxVersion: runnerVers.version,
5488 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005489 },
Steven Valdez520e1222017-06-13 12:45:25 -04005490 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005491 expectedVersion: expectedVersion,
5492 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005493 expectedError: expectedError,
5494 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005495 })
5496 }
5497 }
5498 }
5499}
5500
David Benjamine78bfde2014-09-06 12:45:15 -04005501func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005502 // TODO(davidben): Extensions, where applicable, all move their server
5503 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5504 // tests for both. Also test interaction with 0-RTT when implemented.
5505
David Benjamin97d17d92016-07-14 16:12:00 -04005506 // Repeat extensions tests all versions except SSL 3.0.
5507 for _, ver := range tlsVersions {
5508 if ver.version == VersionSSL30 {
5509 continue
5510 }
5511
David Benjamin97d17d92016-07-14 16:12:00 -04005512 // Test that duplicate extensions are rejected.
5513 testCases = append(testCases, testCase{
5514 testType: clientTest,
5515 name: "DuplicateExtensionClient-" + ver.name,
5516 config: Config{
5517 MaxVersion: ver.version,
5518 Bugs: ProtocolBugs{
5519 DuplicateExtension: true,
5520 },
David Benjamine78bfde2014-09-06 12:45:15 -04005521 },
David Benjamina5022392017-07-10 17:40:39 -04005522 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005523 shouldFail: true,
5524 expectedLocalError: "remote error: error decoding message",
5525 })
5526 testCases = append(testCases, testCase{
5527 testType: serverTest,
5528 name: "DuplicateExtensionServer-" + ver.name,
5529 config: Config{
5530 MaxVersion: ver.version,
5531 Bugs: ProtocolBugs{
5532 DuplicateExtension: true,
5533 },
David Benjamine78bfde2014-09-06 12:45:15 -04005534 },
David Benjamina5022392017-07-10 17:40:39 -04005535 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005536 shouldFail: true,
5537 expectedLocalError: "remote error: error decoding message",
5538 })
5539
5540 // Test SNI.
5541 testCases = append(testCases, testCase{
5542 testType: clientTest,
5543 name: "ServerNameExtensionClient-" + ver.name,
5544 config: Config{
5545 MaxVersion: ver.version,
5546 Bugs: ProtocolBugs{
5547 ExpectServerName: "example.com",
5548 },
David Benjamine78bfde2014-09-06 12:45:15 -04005549 },
David Benjamina5022392017-07-10 17:40:39 -04005550 tls13Variant: ver.tls13Variant,
5551 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005552 })
5553 testCases = append(testCases, testCase{
5554 testType: clientTest,
5555 name: "ServerNameExtensionClientMismatch-" + ver.name,
5556 config: Config{
5557 MaxVersion: ver.version,
5558 Bugs: ProtocolBugs{
5559 ExpectServerName: "mismatch.com",
5560 },
David Benjamine78bfde2014-09-06 12:45:15 -04005561 },
David Benjamin97d17d92016-07-14 16:12:00 -04005562 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005563 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005564 shouldFail: true,
5565 expectedLocalError: "tls: unexpected server name",
5566 })
5567 testCases = append(testCases, testCase{
5568 testType: clientTest,
5569 name: "ServerNameExtensionClientMissing-" + ver.name,
5570 config: Config{
5571 MaxVersion: ver.version,
5572 Bugs: ProtocolBugs{
5573 ExpectServerName: "missing.com",
5574 },
David Benjamine78bfde2014-09-06 12:45:15 -04005575 },
David Benjamina5022392017-07-10 17:40:39 -04005576 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005577 shouldFail: true,
5578 expectedLocalError: "tls: unexpected server name",
5579 })
5580 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005581 testType: clientTest,
5582 name: "TolerateServerNameAck-" + ver.name,
5583 config: Config{
5584 MaxVersion: ver.version,
5585 Bugs: ProtocolBugs{
5586 SendServerNameAck: true,
5587 },
5588 },
David Benjamina5022392017-07-10 17:40:39 -04005589 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005590 flags: []string{"-host-name", "example.com"},
5591 resumeSession: true,
5592 })
5593 testCases = append(testCases, testCase{
5594 testType: clientTest,
5595 name: "UnsolicitedServerNameAck-" + ver.name,
5596 config: Config{
5597 MaxVersion: ver.version,
5598 Bugs: ProtocolBugs{
5599 SendServerNameAck: true,
5600 },
5601 },
David Benjamina5022392017-07-10 17:40:39 -04005602 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005603 shouldFail: true,
5604 expectedError: ":UNEXPECTED_EXTENSION:",
5605 expectedLocalError: "remote error: unsupported extension",
5606 })
5607 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005608 testType: serverTest,
5609 name: "ServerNameExtensionServer-" + ver.name,
5610 config: Config{
5611 MaxVersion: ver.version,
5612 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005613 },
David Benjamina5022392017-07-10 17:40:39 -04005614 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005615 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005616 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005617 })
5618
5619 // Test ALPN.
5620 testCases = append(testCases, testCase{
5621 testType: clientTest,
5622 name: "ALPNClient-" + ver.name,
5623 config: Config{
5624 MaxVersion: ver.version,
5625 NextProtos: []string{"foo"},
5626 },
5627 flags: []string{
5628 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5629 "-expect-alpn", "foo",
5630 },
David Benjamina5022392017-07-10 17:40:39 -04005631 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005632 expectedNextProto: "foo",
5633 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005634 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005635 })
5636 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005637 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005638 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005639 config: Config{
5640 MaxVersion: ver.version,
5641 Bugs: ProtocolBugs{
5642 SendALPN: "baz",
5643 },
5644 },
5645 flags: []string{
5646 "-advertise-alpn", "\x03foo\x03bar",
5647 },
David Benjamina5022392017-07-10 17:40:39 -04005648 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005649 shouldFail: true,
5650 expectedError: ":INVALID_ALPN_PROTOCOL:",
5651 expectedLocalError: "remote error: illegal parameter",
5652 })
5653 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005654 testType: clientTest,
5655 name: "ALPNClient-AllowUnknown-" + ver.name,
5656 config: Config{
5657 MaxVersion: ver.version,
5658 Bugs: ProtocolBugs{
5659 SendALPN: "baz",
5660 },
5661 },
5662 flags: []string{
5663 "-advertise-alpn", "\x03foo\x03bar",
5664 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005665 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005666 },
David Benjamina5022392017-07-10 17:40:39 -04005667 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005668 })
5669 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005670 testType: serverTest,
5671 name: "ALPNServer-" + ver.name,
5672 config: Config{
5673 MaxVersion: ver.version,
5674 NextProtos: []string{"foo", "bar", "baz"},
5675 },
5676 flags: []string{
5677 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5678 "-select-alpn", "foo",
5679 },
David Benjamina5022392017-07-10 17:40:39 -04005680 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005681 expectedNextProto: "foo",
5682 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005683 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005684 })
5685 testCases = append(testCases, testCase{
5686 testType: serverTest,
5687 name: "ALPNServer-Decline-" + ver.name,
5688 config: Config{
5689 MaxVersion: ver.version,
5690 NextProtos: []string{"foo", "bar", "baz"},
5691 },
5692 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005693 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005694 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005695 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005696 })
5697
David Benjamin25fe85b2016-08-09 20:00:32 -04005698 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5699 // called once.
5700 testCases = append(testCases, testCase{
5701 testType: serverTest,
5702 name: "ALPNServer-Async-" + ver.name,
5703 config: Config{
5704 MaxVersion: ver.version,
5705 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005706 // Prior to TLS 1.3, exercise the asynchronous session callback.
5707 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005708 },
5709 flags: []string{
5710 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5711 "-select-alpn", "foo",
5712 "-async",
5713 },
David Benjamina5022392017-07-10 17:40:39 -04005714 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005715 expectedNextProto: "foo",
5716 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005717 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005718 })
5719
David Benjamin97d17d92016-07-14 16:12:00 -04005720 var emptyString string
5721 testCases = append(testCases, testCase{
5722 testType: clientTest,
5723 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5724 config: Config{
5725 MaxVersion: ver.version,
5726 NextProtos: []string{""},
5727 Bugs: ProtocolBugs{
5728 // A server returning an empty ALPN protocol
5729 // should be rejected.
5730 ALPNProtocol: &emptyString,
5731 },
5732 },
5733 flags: []string{
5734 "-advertise-alpn", "\x03foo",
5735 },
David Benjamina5022392017-07-10 17:40:39 -04005736 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005737 shouldFail: true,
5738 expectedError: ":PARSE_TLSEXT:",
5739 })
5740 testCases = append(testCases, testCase{
5741 testType: serverTest,
5742 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5743 config: Config{
5744 MaxVersion: ver.version,
5745 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005746 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005747 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005748 },
David Benjamin97d17d92016-07-14 16:12:00 -04005749 flags: []string{
5750 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005751 },
David Benjamina5022392017-07-10 17:40:39 -04005752 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005753 shouldFail: true,
5754 expectedError: ":PARSE_TLSEXT:",
5755 })
5756
5757 // Test NPN and the interaction with ALPN.
5758 if ver.version < VersionTLS13 {
5759 // Test that the server prefers ALPN over NPN.
5760 testCases = append(testCases, testCase{
5761 testType: serverTest,
5762 name: "ALPNServer-Preferred-" + ver.name,
5763 config: Config{
5764 MaxVersion: ver.version,
5765 NextProtos: []string{"foo", "bar", "baz"},
5766 },
5767 flags: []string{
5768 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5769 "-select-alpn", "foo",
5770 "-advertise-npn", "\x03foo\x03bar\x03baz",
5771 },
David Benjamina5022392017-07-10 17:40:39 -04005772 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005773 expectedNextProto: "foo",
5774 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005775 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005776 })
5777 testCases = append(testCases, testCase{
5778 testType: serverTest,
5779 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5780 config: Config{
5781 MaxVersion: ver.version,
5782 NextProtos: []string{"foo", "bar", "baz"},
5783 Bugs: ProtocolBugs{
5784 SwapNPNAndALPN: true,
5785 },
5786 },
5787 flags: []string{
5788 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5789 "-select-alpn", "foo",
5790 "-advertise-npn", "\x03foo\x03bar\x03baz",
5791 },
David Benjamina5022392017-07-10 17:40:39 -04005792 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005793 expectedNextProto: "foo",
5794 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005795 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005796 })
5797
5798 // Test that negotiating both NPN and ALPN is forbidden.
5799 testCases = append(testCases, testCase{
5800 name: "NegotiateALPNAndNPN-" + ver.name,
5801 config: Config{
5802 MaxVersion: ver.version,
5803 NextProtos: []string{"foo", "bar", "baz"},
5804 Bugs: ProtocolBugs{
5805 NegotiateALPNAndNPN: true,
5806 },
5807 },
5808 flags: []string{
5809 "-advertise-alpn", "\x03foo",
5810 "-select-next-proto", "foo",
5811 },
David Benjamina5022392017-07-10 17:40:39 -04005812 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005813 shouldFail: true,
5814 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5815 })
5816 testCases = append(testCases, testCase{
5817 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5818 config: Config{
5819 MaxVersion: ver.version,
5820 NextProtos: []string{"foo", "bar", "baz"},
5821 Bugs: ProtocolBugs{
5822 NegotiateALPNAndNPN: true,
5823 SwapNPNAndALPN: true,
5824 },
5825 },
5826 flags: []string{
5827 "-advertise-alpn", "\x03foo",
5828 "-select-next-proto", "foo",
5829 },
David Benjamina5022392017-07-10 17:40:39 -04005830 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005831 shouldFail: true,
5832 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5833 })
David Benjamin97d17d92016-07-14 16:12:00 -04005834 }
5835
5836 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005837
5838 // Resume with a corrupt ticket.
5839 testCases = append(testCases, testCase{
5840 testType: serverTest,
5841 name: "CorruptTicket-" + ver.name,
5842 config: Config{
5843 MaxVersion: ver.version,
5844 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005845 FilterTicket: func(in []byte) ([]byte, error) {
5846 in[len(in)-1] ^= 1
5847 return in, nil
5848 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005849 },
5850 },
David Benjamina5022392017-07-10 17:40:39 -04005851 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005852 resumeSession: true,
5853 expectResumeRejected: true,
5854 })
5855 // Test the ticket callback, with and without renewal.
5856 testCases = append(testCases, testCase{
5857 testType: serverTest,
5858 name: "TicketCallback-" + ver.name,
5859 config: Config{
5860 MaxVersion: ver.version,
5861 },
David Benjamina5022392017-07-10 17:40:39 -04005862 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005863 resumeSession: true,
5864 flags: []string{"-use-ticket-callback"},
5865 })
5866 testCases = append(testCases, testCase{
5867 testType: serverTest,
5868 name: "TicketCallback-Renew-" + ver.name,
5869 config: Config{
5870 MaxVersion: ver.version,
5871 Bugs: ProtocolBugs{
5872 ExpectNewTicket: true,
5873 },
5874 },
David Benjamina5022392017-07-10 17:40:39 -04005875 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005876 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5877 resumeSession: true,
5878 })
5879
5880 // Test that the ticket callback is only called once when everything before
5881 // it in the ClientHello is asynchronous. This corrupts the ticket so
5882 // certificate selection callbacks run.
5883 testCases = append(testCases, testCase{
5884 testType: serverTest,
5885 name: "TicketCallback-SingleCall-" + ver.name,
5886 config: Config{
5887 MaxVersion: ver.version,
5888 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005889 FilterTicket: func(in []byte) ([]byte, error) {
5890 in[len(in)-1] ^= 1
5891 return in, nil
5892 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005893 },
5894 },
David Benjamina5022392017-07-10 17:40:39 -04005895 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005896 resumeSession: true,
5897 expectResumeRejected: true,
5898 flags: []string{
5899 "-use-ticket-callback",
5900 "-async",
5901 },
5902 })
5903
David Benjamind4c349b2017-02-09 14:07:17 -05005904 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005905 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005906 testCases = append(testCases, testCase{
5907 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005908 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005909 config: Config{
5910 MaxVersion: ver.version,
5911 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005912 EmptyTicketSessionID: true,
5913 },
5914 },
5915 resumeSession: true,
5916 })
5917 testCases = append(testCases, testCase{
5918 testType: serverTest,
5919 name: "TicketSessionIDLength-16-" + ver.name,
5920 config: Config{
5921 MaxVersion: ver.version,
5922 Bugs: ProtocolBugs{
5923 TicketSessionIDLength: 16,
5924 },
5925 },
5926 resumeSession: true,
5927 })
5928 testCases = append(testCases, testCase{
5929 testType: serverTest,
5930 name: "TicketSessionIDLength-32-" + ver.name,
5931 config: Config{
5932 MaxVersion: ver.version,
5933 Bugs: ProtocolBugs{
5934 TicketSessionIDLength: 32,
5935 },
5936 },
5937 resumeSession: true,
5938 })
5939 testCases = append(testCases, testCase{
5940 testType: serverTest,
5941 name: "TicketSessionIDLength-33-" + ver.name,
5942 config: Config{
5943 MaxVersion: ver.version,
5944 Bugs: ProtocolBugs{
5945 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005946 },
5947 },
5948 resumeSession: true,
5949 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005950 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005951 expectedError: ":DECODE_ERROR:",
5952 })
5953 }
5954
5955 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5956 // are ignored.
5957 if ver.hasDTLS {
5958 testCases = append(testCases, testCase{
5959 protocol: dtls,
5960 name: "SRTP-Client-" + ver.name,
5961 config: Config{
5962 MaxVersion: ver.version,
5963 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5964 },
5965 flags: []string{
5966 "-srtp-profiles",
5967 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5968 },
5969 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5970 })
5971 testCases = append(testCases, testCase{
5972 protocol: dtls,
5973 testType: serverTest,
5974 name: "SRTP-Server-" + ver.name,
5975 config: Config{
5976 MaxVersion: ver.version,
5977 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5978 },
5979 flags: []string{
5980 "-srtp-profiles",
5981 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5982 },
5983 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5984 })
5985 // Test that the MKI is ignored.
5986 testCases = append(testCases, testCase{
5987 protocol: dtls,
5988 testType: serverTest,
5989 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5990 config: Config{
5991 MaxVersion: ver.version,
5992 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5993 Bugs: ProtocolBugs{
5994 SRTPMasterKeyIdentifer: "bogus",
5995 },
5996 },
5997 flags: []string{
5998 "-srtp-profiles",
5999 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6000 },
6001 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6002 })
6003 // Test that SRTP isn't negotiated on the server if there were
6004 // no matching profiles.
6005 testCases = append(testCases, testCase{
6006 protocol: dtls,
6007 testType: serverTest,
6008 name: "SRTP-Server-NoMatch-" + ver.name,
6009 config: Config{
6010 MaxVersion: ver.version,
6011 SRTPProtectionProfiles: []uint16{100, 101, 102},
6012 },
6013 flags: []string{
6014 "-srtp-profiles",
6015 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6016 },
6017 expectedSRTPProtectionProfile: 0,
6018 })
6019 // Test that the server returning an invalid SRTP profile is
6020 // flagged as an error by the client.
6021 testCases = append(testCases, testCase{
6022 protocol: dtls,
6023 name: "SRTP-Client-NoMatch-" + ver.name,
6024 config: Config{
6025 MaxVersion: ver.version,
6026 Bugs: ProtocolBugs{
6027 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6028 },
6029 },
6030 flags: []string{
6031 "-srtp-profiles",
6032 "SRTP_AES128_CM_SHA1_80",
6033 },
6034 shouldFail: true,
6035 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6036 })
6037 }
6038
6039 // Test SCT list.
6040 testCases = append(testCases, testCase{
6041 name: "SignedCertificateTimestampList-Client-" + ver.name,
6042 testType: clientTest,
6043 config: Config{
6044 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006045 },
David Benjamin97d17d92016-07-14 16:12:00 -04006046 flags: []string{
6047 "-enable-signed-cert-timestamps",
6048 "-expect-signed-cert-timestamps",
6049 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006050 },
David Benjamina5022392017-07-10 17:40:39 -04006051 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006052 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006053 })
David Benjamindaa88502016-10-04 16:32:16 -04006054
Adam Langleycfa08c32016-11-17 13:21:27 -08006055 var differentSCTList []byte
6056 differentSCTList = append(differentSCTList, testSCTList...)
6057 differentSCTList[len(differentSCTList)-1] ^= 1
6058
David Benjamindaa88502016-10-04 16:32:16 -04006059 // The SCT extension did not specify that it must only be sent on resumption as it
6060 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006061 testCases = append(testCases, testCase{
6062 name: "SendSCTListOnResume-" + ver.name,
6063 config: Config{
6064 MaxVersion: ver.version,
6065 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006066 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006067 },
David Benjamind98452d2015-06-16 14:16:23 -04006068 },
David Benjamin97d17d92016-07-14 16:12:00 -04006069 flags: []string{
6070 "-enable-signed-cert-timestamps",
6071 "-expect-signed-cert-timestamps",
6072 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006073 },
David Benjamina5022392017-07-10 17:40:39 -04006074 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006075 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006076 })
David Benjamindaa88502016-10-04 16:32:16 -04006077
David Benjamin97d17d92016-07-14 16:12:00 -04006078 testCases = append(testCases, testCase{
6079 name: "SignedCertificateTimestampList-Server-" + ver.name,
6080 testType: serverTest,
6081 config: Config{
6082 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006083 },
David Benjamin97d17d92016-07-14 16:12:00 -04006084 flags: []string{
6085 "-signed-cert-timestamps",
6086 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006087 },
David Benjamina5022392017-07-10 17:40:39 -04006088 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006089 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006090 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006091 })
David Benjamin53210cb2016-11-16 09:01:48 +09006092
Adam Langleycfa08c32016-11-17 13:21:27 -08006093 emptySCTListCert := *testCerts[0].cert
6094 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6095
6096 // Test empty SCT list.
6097 testCases = append(testCases, testCase{
6098 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6099 testType: clientTest,
6100 config: Config{
6101 MaxVersion: ver.version,
6102 Certificates: []Certificate{emptySCTListCert},
6103 },
6104 flags: []string{
6105 "-enable-signed-cert-timestamps",
6106 },
David Benjamina5022392017-07-10 17:40:39 -04006107 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006108 shouldFail: true,
6109 expectedError: ":ERROR_PARSING_EXTENSION:",
6110 })
6111
6112 emptySCTCert := *testCerts[0].cert
6113 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6114
6115 // Test empty SCT in non-empty list.
6116 testCases = append(testCases, testCase{
6117 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6118 testType: clientTest,
6119 config: Config{
6120 MaxVersion: ver.version,
6121 Certificates: []Certificate{emptySCTCert},
6122 },
6123 flags: []string{
6124 "-enable-signed-cert-timestamps",
6125 },
David Benjamina5022392017-07-10 17:40:39 -04006126 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006127 shouldFail: true,
6128 expectedError: ":ERROR_PARSING_EXTENSION:",
6129 })
6130
David Benjamin53210cb2016-11-16 09:01:48 +09006131 // Test that certificate-related extensions are not sent unsolicited.
6132 testCases = append(testCases, testCase{
6133 testType: serverTest,
6134 name: "UnsolicitedCertificateExtensions-" + ver.name,
6135 config: Config{
6136 MaxVersion: ver.version,
6137 Bugs: ProtocolBugs{
6138 NoOCSPStapling: true,
6139 NoSignedCertificateTimestamps: true,
6140 },
6141 },
David Benjamina5022392017-07-10 17:40:39 -04006142 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006143 flags: []string{
6144 "-ocsp-response",
6145 base64.StdEncoding.EncodeToString(testOCSPResponse),
6146 "-signed-cert-timestamps",
6147 base64.StdEncoding.EncodeToString(testSCTList),
6148 },
6149 })
David Benjamin97d17d92016-07-14 16:12:00 -04006150 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006151
Paul Lietar4fac72e2015-09-09 13:44:55 +01006152 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006153 testType: clientTest,
6154 name: "ClientHelloPadding",
6155 config: Config{
6156 Bugs: ProtocolBugs{
6157 RequireClientHelloSize: 512,
6158 },
6159 },
6160 // This hostname just needs to be long enough to push the
6161 // ClientHello into F5's danger zone between 256 and 511 bytes
6162 // long.
6163 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6164 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006165
6166 // Extensions should not function in SSL 3.0.
6167 testCases = append(testCases, testCase{
6168 testType: serverTest,
6169 name: "SSLv3Extensions-NoALPN",
6170 config: Config{
6171 MaxVersion: VersionSSL30,
6172 NextProtos: []string{"foo", "bar", "baz"},
6173 },
6174 flags: []string{
6175 "-select-alpn", "foo",
6176 },
6177 expectNoNextProto: true,
6178 })
6179
6180 // Test session tickets separately as they follow a different codepath.
6181 testCases = append(testCases, testCase{
6182 testType: serverTest,
6183 name: "SSLv3Extensions-NoTickets",
6184 config: Config{
6185 MaxVersion: VersionSSL30,
6186 Bugs: ProtocolBugs{
6187 // Historically, session tickets in SSL 3.0
6188 // failed in different ways depending on whether
6189 // the client supported renegotiation_info.
6190 NoRenegotiationInfo: true,
6191 },
6192 },
6193 resumeSession: true,
6194 })
6195 testCases = append(testCases, testCase{
6196 testType: serverTest,
6197 name: "SSLv3Extensions-NoTickets2",
6198 config: Config{
6199 MaxVersion: VersionSSL30,
6200 },
6201 resumeSession: true,
6202 })
6203
6204 // But SSL 3.0 does send and process renegotiation_info.
6205 testCases = append(testCases, testCase{
6206 testType: serverTest,
6207 name: "SSLv3Extensions-RenegotiationInfo",
6208 config: Config{
6209 MaxVersion: VersionSSL30,
6210 Bugs: ProtocolBugs{
6211 RequireRenegotiationInfo: true,
6212 },
6213 },
David Benjamind2610042017-01-03 10:49:28 -05006214 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006215 })
6216 testCases = append(testCases, testCase{
6217 testType: serverTest,
6218 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6219 config: Config{
6220 MaxVersion: VersionSSL30,
6221 Bugs: ProtocolBugs{
6222 NoRenegotiationInfo: true,
6223 SendRenegotiationSCSV: true,
6224 RequireRenegotiationInfo: true,
6225 },
6226 },
David Benjamind2610042017-01-03 10:49:28 -05006227 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006228 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006229
6230 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6231 // in ServerHello.
6232 testCases = append(testCases, testCase{
6233 name: "NPN-Forbidden-TLS13",
6234 config: Config{
6235 MaxVersion: VersionTLS13,
6236 NextProtos: []string{"foo"},
6237 Bugs: ProtocolBugs{
6238 NegotiateNPNAtAllVersions: true,
6239 },
6240 },
6241 flags: []string{"-select-next-proto", "foo"},
6242 shouldFail: true,
6243 expectedError: ":ERROR_PARSING_EXTENSION:",
6244 })
6245 testCases = append(testCases, testCase{
6246 name: "EMS-Forbidden-TLS13",
6247 config: Config{
6248 MaxVersion: VersionTLS13,
6249 Bugs: ProtocolBugs{
6250 NegotiateEMSAtAllVersions: true,
6251 },
6252 },
6253 shouldFail: true,
6254 expectedError: ":ERROR_PARSING_EXTENSION:",
6255 })
6256 testCases = append(testCases, testCase{
6257 name: "RenegotiationInfo-Forbidden-TLS13",
6258 config: Config{
6259 MaxVersion: VersionTLS13,
6260 Bugs: ProtocolBugs{
6261 NegotiateRenegotiationInfoAtAllVersions: true,
6262 },
6263 },
6264 shouldFail: true,
6265 expectedError: ":ERROR_PARSING_EXTENSION:",
6266 })
6267 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006268 name: "Ticket-Forbidden-TLS13",
6269 config: Config{
6270 MaxVersion: VersionTLS12,
6271 },
6272 resumeConfig: &Config{
6273 MaxVersion: VersionTLS13,
6274 Bugs: ProtocolBugs{
6275 AdvertiseTicketExtension: true,
6276 },
6277 },
6278 resumeSession: true,
6279 shouldFail: true,
6280 expectedError: ":ERROR_PARSING_EXTENSION:",
6281 })
6282
6283 // Test that illegal extensions in TLS 1.3 are declined by the server if
6284 // offered in ClientHello. The runner's server will fail if this occurs,
6285 // so we exercise the offering path. (EMS and Renegotiation Info are
6286 // implicit in every test.)
6287 testCases = append(testCases, testCase{
6288 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006289 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006290 config: Config{
6291 MaxVersion: VersionTLS13,
6292 NextProtos: []string{"bar"},
6293 },
6294 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6295 })
David Benjamin196df5b2016-09-21 16:23:27 -04006296
David Benjamindaa88502016-10-04 16:32:16 -04006297 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6298 // tolerated.
6299 testCases = append(testCases, testCase{
6300 name: "SendOCSPResponseOnResume-TLS12",
6301 config: Config{
6302 MaxVersion: VersionTLS12,
6303 Bugs: ProtocolBugs{
6304 SendOCSPResponseOnResume: []byte("bogus"),
6305 },
6306 },
6307 flags: []string{
6308 "-enable-ocsp-stapling",
6309 "-expect-ocsp-response",
6310 base64.StdEncoding.EncodeToString(testOCSPResponse),
6311 },
6312 resumeSession: true,
6313 })
6314
David Benjamindaa88502016-10-04 16:32:16 -04006315 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006316 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006317 config: Config{
6318 MaxVersion: VersionTLS13,
6319 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006320 SendExtensionOnCertificate: testOCSPExtension,
6321 },
6322 },
6323 shouldFail: true,
6324 expectedError: ":UNEXPECTED_EXTENSION:",
6325 })
6326
6327 testCases = append(testCases, testCase{
6328 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6329 config: Config{
6330 MaxVersion: VersionTLS13,
6331 Bugs: ProtocolBugs{
6332 SendExtensionOnCertificate: testSCTExtension,
6333 },
6334 },
6335 shouldFail: true,
6336 expectedError: ":UNEXPECTED_EXTENSION:",
6337 })
6338
6339 // Test that extensions on client certificates are never accepted.
6340 testCases = append(testCases, testCase{
6341 name: "SendExtensionOnClientCertificate-TLS13",
6342 testType: serverTest,
6343 config: Config{
6344 MaxVersion: VersionTLS13,
6345 Certificates: []Certificate{rsaCertificate},
6346 Bugs: ProtocolBugs{
6347 SendExtensionOnCertificate: testOCSPExtension,
6348 },
6349 },
6350 flags: []string{
6351 "-enable-ocsp-stapling",
6352 "-require-any-client-certificate",
6353 },
6354 shouldFail: true,
6355 expectedError: ":UNEXPECTED_EXTENSION:",
6356 })
6357
6358 testCases = append(testCases, testCase{
6359 name: "SendUnknownExtensionOnCertificate-TLS13",
6360 config: Config{
6361 MaxVersion: VersionTLS13,
6362 Bugs: ProtocolBugs{
6363 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6364 },
6365 },
6366 shouldFail: true,
6367 expectedError: ":UNEXPECTED_EXTENSION:",
6368 })
6369
6370 // Test that extensions on intermediates are allowed but ignored.
6371 testCases = append(testCases, testCase{
6372 name: "IgnoreExtensionsOnIntermediates-TLS13",
6373 config: Config{
6374 MaxVersion: VersionTLS13,
6375 Certificates: []Certificate{rsaChainCertificate},
6376 Bugs: ProtocolBugs{
6377 // Send different values on the intermediate. This tests
6378 // the intermediate's extensions do not override the
6379 // leaf's.
David Benjamin5c4271f2017-08-23 22:09:41 -07006380 SendOCSPOnIntermediates: testOCSPResponse2,
6381 SendSCTOnIntermediates: testSCTList2,
David Benjamindaa88502016-10-04 16:32:16 -04006382 },
6383 },
6384 flags: []string{
6385 "-enable-ocsp-stapling",
6386 "-expect-ocsp-response",
6387 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006388 "-enable-signed-cert-timestamps",
6389 "-expect-signed-cert-timestamps",
6390 base64.StdEncoding.EncodeToString(testSCTList),
6391 },
6392 resumeSession: true,
6393 })
6394
6395 // Test that extensions are not sent on intermediates when configured
6396 // only for a leaf.
6397 testCases = append(testCases, testCase{
6398 testType: serverTest,
6399 name: "SendNoExtensionsOnIntermediate-TLS13",
6400 config: Config{
6401 MaxVersion: VersionTLS13,
6402 Bugs: ProtocolBugs{
6403 ExpectNoExtensionsOnIntermediate: true,
6404 },
6405 },
6406 flags: []string{
6407 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6408 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6409 "-ocsp-response",
6410 base64.StdEncoding.EncodeToString(testOCSPResponse),
6411 "-signed-cert-timestamps",
6412 base64.StdEncoding.EncodeToString(testSCTList),
6413 },
6414 })
6415
6416 // Test that extensions are not sent on client certificates.
6417 testCases = append(testCases, testCase{
6418 name: "SendNoClientCertificateExtensions-TLS13",
6419 config: Config{
6420 MaxVersion: VersionTLS13,
6421 ClientAuth: RequireAnyClientCert,
6422 },
6423 flags: []string{
6424 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6425 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6426 "-ocsp-response",
6427 base64.StdEncoding.EncodeToString(testOCSPResponse),
6428 "-signed-cert-timestamps",
6429 base64.StdEncoding.EncodeToString(testSCTList),
6430 },
6431 })
6432
6433 testCases = append(testCases, testCase{
6434 name: "SendDuplicateExtensionsOnCerts-TLS13",
6435 config: Config{
6436 MaxVersion: VersionTLS13,
6437 Bugs: ProtocolBugs{
6438 SendDuplicateCertExtensions: true,
6439 },
6440 },
6441 flags: []string{
6442 "-enable-ocsp-stapling",
6443 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006444 },
6445 resumeSession: true,
6446 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006447 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006448 })
Adam Langley9b885c52016-11-18 14:21:03 -08006449
6450 testCases = append(testCases, testCase{
6451 name: "SignedCertificateTimestampListInvalid-Server",
6452 testType: serverTest,
6453 flags: []string{
6454 "-signed-cert-timestamps",
6455 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6456 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006457 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006458 expectedError: ":INVALID_SCT_LIST:",
6459 })
David Benjamine78bfde2014-09-06 12:45:15 -04006460}
6461
David Benjamin01fe8202014-09-24 15:21:44 -04006462func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006463 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006464 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006465 // SSL 3.0 does not have tickets and TLS 1.3 does not
6466 // have session IDs, so skip their cross-resumption
6467 // tests.
6468 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6469 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6470 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006471 }
6472
David Benjamin8b8c0062014-11-23 02:47:52 -05006473 protocols := []protocol{tls}
6474 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6475 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006476 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006477 for _, protocol := range protocols {
6478 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6479 if protocol == dtls {
6480 suffix += "-DTLS"
6481 }
6482
Steven Valdez520e1222017-06-13 12:45:25 -04006483 // We can't resume across TLS 1.3 variants and error out earlier in the
6484 // session resumption.
6485 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6486 continue
6487 }
6488
David Benjaminece3de92015-03-16 18:02:20 -04006489 if sessionVers.version == resumeVers.version {
6490 testCases = append(testCases, testCase{
6491 protocol: protocol,
6492 name: "Resume-Client" + suffix,
6493 resumeSession: true,
6494 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006495 MaxVersion: sessionVers.version,
6496 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006497 Bugs: ProtocolBugs{
6498 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6499 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6500 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006501 },
David Benjaminece3de92015-03-16 18:02:20 -04006502 expectedVersion: sessionVers.version,
6503 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006504 flags: []string{
6505 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6506 },
David Benjaminece3de92015-03-16 18:02:20 -04006507 })
6508 } else {
David Benjamin405da482016-08-08 17:25:07 -04006509 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6510
6511 // Offering a TLS 1.3 session sends an empty session ID, so
6512 // there is no way to convince a non-lookahead client the
6513 // session was resumed. It will appear to the client that a
6514 // stray ChangeCipherSpec was sent.
6515 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6516 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006517 }
6518
David Benjaminece3de92015-03-16 18:02:20 -04006519 testCases = append(testCases, testCase{
6520 protocol: protocol,
6521 name: "Resume-Client-Mismatch" + suffix,
6522 resumeSession: true,
6523 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006524 MaxVersion: sessionVers.version,
6525 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006526 },
David Benjaminece3de92015-03-16 18:02:20 -04006527 expectedVersion: sessionVers.version,
6528 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006529 MaxVersion: resumeVers.version,
6530 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006531 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006532 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006533 },
6534 },
6535 expectedResumeVersion: resumeVers.version,
6536 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006537 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006538 flags: []string{
6539 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6540 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6541 },
David Benjaminece3de92015-03-16 18:02:20 -04006542 })
6543 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006544
6545 testCases = append(testCases, testCase{
6546 protocol: protocol,
6547 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006548 resumeSession: true,
6549 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006550 MaxVersion: sessionVers.version,
6551 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006552 },
6553 expectedVersion: sessionVers.version,
6554 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006555 MaxVersion: resumeVers.version,
6556 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006557 },
6558 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006559 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006560 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006561 flags: []string{
6562 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6563 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6564 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006565 })
6566
David Benjamin8b8c0062014-11-23 02:47:52 -05006567 testCases = append(testCases, testCase{
6568 protocol: protocol,
6569 testType: serverTest,
6570 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006571 resumeSession: true,
6572 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006573 MaxVersion: sessionVers.version,
6574 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006575 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006576 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006577 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006578 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006579 MaxVersion: resumeVers.version,
6580 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006581 Bugs: ProtocolBugs{
6582 SendBothTickets: true,
6583 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006584 },
6585 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006586 flags: []string{
6587 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6588 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6589 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006590 })
6591 }
David Benjamin01fe8202014-09-24 15:21:44 -04006592 }
6593 }
David Benjaminece3de92015-03-16 18:02:20 -04006594
David Benjamin4199b0d2016-11-01 13:58:25 -04006595 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006596 testCases = append(testCases, testCase{
6597 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006598 name: "ShimTicketRewritable",
6599 resumeSession: true,
6600 config: Config{
6601 MaxVersion: VersionTLS12,
6602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6603 Bugs: ProtocolBugs{
6604 FilterTicket: func(in []byte) ([]byte, error) {
6605 in, err := SetShimTicketVersion(in, VersionTLS12)
6606 if err != nil {
6607 return nil, err
6608 }
6609 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6610 },
6611 },
6612 },
6613 flags: []string{
6614 "-ticket-key",
6615 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6616 },
6617 })
6618
6619 // Resumptions are declined if the version does not match.
6620 testCases = append(testCases, testCase{
6621 testType: serverTest,
6622 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006623 resumeSession: true,
6624 config: Config{
6625 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006626 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006627 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006628 FilterTicket: func(in []byte) ([]byte, error) {
6629 return SetShimTicketVersion(in, VersionTLS13)
6630 },
6631 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006632 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006633 flags: []string{
6634 "-ticket-key",
6635 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6636 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006637 expectResumeRejected: true,
6638 })
6639
6640 testCases = append(testCases, testCase{
6641 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006642 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006643 resumeSession: true,
6644 config: Config{
6645 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006646 Bugs: ProtocolBugs{
6647 FilterTicket: func(in []byte) ([]byte, error) {
6648 return SetShimTicketVersion(in, VersionTLS12)
6649 },
6650 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006651 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006652 flags: []string{
6653 "-ticket-key",
6654 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6655 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006656 expectResumeRejected: true,
6657 })
6658
David Benjamin4199b0d2016-11-01 13:58:25 -04006659 // Resumptions are declined if the cipher is invalid or disabled.
6660 testCases = append(testCases, testCase{
6661 testType: serverTest,
6662 name: "Resume-Server-DeclineBadCipher",
6663 resumeSession: true,
6664 config: Config{
6665 MaxVersion: VersionTLS12,
6666 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006667 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006668 FilterTicket: func(in []byte) ([]byte, error) {
6669 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6670 },
6671 },
6672 },
6673 flags: []string{
6674 "-ticket-key",
6675 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6676 },
6677 expectResumeRejected: true,
6678 })
6679
6680 testCases = append(testCases, testCase{
6681 testType: serverTest,
6682 name: "Resume-Server-DeclineBadCipher-2",
6683 resumeSession: true,
6684 config: Config{
6685 MaxVersion: VersionTLS12,
6686 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006687 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006688 FilterTicket: func(in []byte) ([]byte, error) {
6689 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6690 },
6691 },
6692 },
6693 flags: []string{
6694 "-cipher", "AES128",
6695 "-ticket-key",
6696 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6697 },
6698 expectResumeRejected: true,
6699 })
6700
David Benjaminf01f42a2016-11-16 19:05:33 +09006701 // Sessions are not resumed if they do not use the preferred cipher.
6702 testCases = append(testCases, testCase{
6703 testType: serverTest,
6704 name: "Resume-Server-CipherNotPreferred",
6705 resumeSession: true,
6706 config: Config{
6707 MaxVersion: VersionTLS12,
6708 Bugs: ProtocolBugs{
6709 ExpectNewTicket: true,
6710 FilterTicket: func(in []byte) ([]byte, error) {
6711 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6712 },
6713 },
6714 },
6715 flags: []string{
6716 "-ticket-key",
6717 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6718 },
6719 shouldFail: false,
6720 expectResumeRejected: true,
6721 })
6722
6723 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6724 // PRF hashes match, but BoringSSL will always decline such resumptions.
6725 testCases = append(testCases, testCase{
6726 testType: serverTest,
6727 name: "Resume-Server-CipherNotPreferred-TLS13",
6728 resumeSession: true,
6729 config: Config{
6730 MaxVersion: VersionTLS13,
6731 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6732 Bugs: ProtocolBugs{
6733 FilterTicket: func(in []byte) ([]byte, error) {
6734 // If the client (runner) offers ChaCha20-Poly1305 first, the
6735 // server (shim) always prefers it. Switch it to AES-GCM.
6736 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6737 },
6738 },
6739 },
6740 flags: []string{
6741 "-ticket-key",
6742 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6743 },
6744 shouldFail: false,
6745 expectResumeRejected: true,
6746 })
6747
6748 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006749 testCases = append(testCases, testCase{
6750 testType: serverTest,
6751 name: "Resume-Server-DeclineBadCipher-TLS13",
6752 resumeSession: true,
6753 config: Config{
6754 MaxVersion: VersionTLS13,
6755 Bugs: ProtocolBugs{
6756 FilterTicket: func(in []byte) ([]byte, error) {
6757 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6758 },
6759 },
6760 },
6761 flags: []string{
6762 "-ticket-key",
6763 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6764 },
6765 expectResumeRejected: true,
6766 })
6767
David Benjaminf01f42a2016-11-16 19:05:33 +09006768 // If the client does not offer the cipher from the session, decline to
6769 // resume. Clients are forbidden from doing this, but BoringSSL selects
6770 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006771 testCases = append(testCases, testCase{
6772 testType: serverTest,
6773 name: "Resume-Server-UnofferedCipher",
6774 resumeSession: true,
6775 config: Config{
6776 MaxVersion: VersionTLS12,
6777 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6778 },
6779 resumeConfig: &Config{
6780 MaxVersion: VersionTLS12,
6781 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6782 Bugs: ProtocolBugs{
6783 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6784 },
6785 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006786 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006787 })
6788
David Benjaminf01f42a2016-11-16 19:05:33 +09006789 // In TLS 1.3, clients may advertise a cipher list which does not
6790 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006791 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6792 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006793 testCases = append(testCases, testCase{
6794 testType: serverTest,
6795 name: "Resume-Server-UnofferedCipher-TLS13",
6796 resumeSession: true,
6797 config: Config{
6798 MaxVersion: VersionTLS13,
6799 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6800 },
6801 resumeConfig: &Config{
6802 MaxVersion: VersionTLS13,
6803 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6804 Bugs: ProtocolBugs{
6805 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6806 },
6807 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006808 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006809 })
6810
David Benjamin4199b0d2016-11-01 13:58:25 -04006811 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006812 testCases = append(testCases, testCase{
6813 name: "Resume-Client-CipherMismatch",
6814 resumeSession: true,
6815 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006816 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006817 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6818 },
6819 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006820 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006821 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6822 Bugs: ProtocolBugs{
6823 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6824 },
6825 },
6826 shouldFail: true,
6827 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6828 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006829
David Benjamine1cc35e2016-11-16 16:25:58 +09006830 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6831 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006832 testCases = append(testCases, testCase{
6833 name: "Resume-Client-CipherMismatch-TLS13",
6834 resumeSession: true,
6835 config: Config{
6836 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006837 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006838 },
6839 resumeConfig: &Config{
6840 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006841 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6842 },
6843 })
6844
6845 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6846 testCases = append(testCases, testCase{
6847 name: "Resume-Client-PRFMismatch-TLS13",
6848 resumeSession: true,
6849 config: Config{
6850 MaxVersion: VersionTLS13,
6851 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6852 },
6853 resumeConfig: &Config{
6854 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006855 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006856 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006857 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006858 },
6859 },
6860 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006861 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006862 })
Steven Valdeza833c352016-11-01 13:39:36 -04006863
6864 testCases = append(testCases, testCase{
6865 testType: serverTest,
6866 name: "Resume-Server-BinderWrongLength",
6867 resumeSession: true,
6868 config: Config{
6869 MaxVersion: VersionTLS13,
6870 Bugs: ProtocolBugs{
6871 SendShortPSKBinder: true,
6872 },
6873 },
6874 shouldFail: true,
6875 expectedLocalError: "remote error: error decrypting message",
6876 expectedError: ":DIGEST_CHECK_FAILED:",
6877 })
6878
6879 testCases = append(testCases, testCase{
6880 testType: serverTest,
6881 name: "Resume-Server-NoPSKBinder",
6882 resumeSession: true,
6883 config: Config{
6884 MaxVersion: VersionTLS13,
6885 Bugs: ProtocolBugs{
6886 SendNoPSKBinder: true,
6887 },
6888 },
6889 shouldFail: true,
6890 expectedLocalError: "remote error: error decoding message",
6891 expectedError: ":DECODE_ERROR:",
6892 })
6893
6894 testCases = append(testCases, testCase{
6895 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006896 name: "Resume-Server-ExtraPSKBinder",
6897 resumeSession: true,
6898 config: Config{
6899 MaxVersion: VersionTLS13,
6900 Bugs: ProtocolBugs{
6901 SendExtraPSKBinder: true,
6902 },
6903 },
6904 shouldFail: true,
6905 expectedLocalError: "remote error: illegal parameter",
6906 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6907 })
6908
6909 testCases = append(testCases, testCase{
6910 testType: serverTest,
6911 name: "Resume-Server-ExtraIdentityNoBinder",
6912 resumeSession: true,
6913 config: Config{
6914 MaxVersion: VersionTLS13,
6915 Bugs: ProtocolBugs{
6916 ExtraPSKIdentity: true,
6917 },
6918 },
6919 shouldFail: true,
6920 expectedLocalError: "remote error: illegal parameter",
6921 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6922 })
6923
6924 testCases = append(testCases, testCase{
6925 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006926 name: "Resume-Server-InvalidPSKBinder",
6927 resumeSession: true,
6928 config: Config{
6929 MaxVersion: VersionTLS13,
6930 Bugs: ProtocolBugs{
6931 SendInvalidPSKBinder: true,
6932 },
6933 },
6934 shouldFail: true,
6935 expectedLocalError: "remote error: error decrypting message",
6936 expectedError: ":DIGEST_CHECK_FAILED:",
6937 })
6938
6939 testCases = append(testCases, testCase{
6940 testType: serverTest,
6941 name: "Resume-Server-PSKBinderFirstExtension",
6942 resumeSession: true,
6943 config: Config{
6944 MaxVersion: VersionTLS13,
6945 Bugs: ProtocolBugs{
6946 PSKBinderFirst: true,
6947 },
6948 },
6949 shouldFail: true,
6950 expectedLocalError: "remote error: illegal parameter",
6951 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6952 })
David Benjamin01fe8202014-09-24 15:21:44 -04006953}
6954
Adam Langley2ae77d22014-10-28 17:29:33 -07006955func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006956 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006957 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006958 testType: serverTest,
6959 name: "Renegotiate-Server-Forbidden",
6960 config: Config{
6961 MaxVersion: VersionTLS12,
6962 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006963 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006964 shouldFail: true,
6965 expectedError: ":NO_RENEGOTIATION:",
6966 expectedLocalError: "remote error: no renegotiation",
6967 })
Adam Langley5021b222015-06-12 18:27:58 -07006968 // The server shouldn't echo the renegotiation extension unless
6969 // requested by the client.
6970 testCases = append(testCases, testCase{
6971 testType: serverTest,
6972 name: "Renegotiate-Server-NoExt",
6973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006974 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006975 Bugs: ProtocolBugs{
6976 NoRenegotiationInfo: true,
6977 RequireRenegotiationInfo: true,
6978 },
6979 },
6980 shouldFail: true,
6981 expectedLocalError: "renegotiation extension missing",
6982 })
6983 // The renegotiation SCSV should be sufficient for the server to echo
6984 // the extension.
6985 testCases = append(testCases, testCase{
6986 testType: serverTest,
6987 name: "Renegotiate-Server-NoExt-SCSV",
6988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006989 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006990 Bugs: ProtocolBugs{
6991 NoRenegotiationInfo: true,
6992 SendRenegotiationSCSV: true,
6993 RequireRenegotiationInfo: true,
6994 },
6995 },
6996 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006997 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006998 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007001 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007002 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007003 },
7004 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007005 renegotiate: 1,
David Benjamind0beda02017-09-06 16:46:50 -04007006 // Test renegotiation after both an initial and resumption
7007 // handshake.
7008 resumeSession: true,
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007009 flags: []string{
7010 "-renegotiate-freely",
7011 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007012 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007013 },
David Benjamincdea40c2015-03-19 14:09:43 -04007014 })
7015 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007016 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007017 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007019 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007020 Bugs: ProtocolBugs{
7021 EmptyRenegotiationInfo: true,
7022 },
7023 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007024 flags: []string{"-renegotiate-freely"},
7025 shouldFail: true,
7026 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007027 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007028 })
7029 testCases = append(testCases, testCase{
7030 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007031 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007032 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007033 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007034 Bugs: ProtocolBugs{
7035 BadRenegotiationInfo: true,
7036 },
7037 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007038 flags: []string{"-renegotiate-freely"},
7039 shouldFail: true,
7040 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007041 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007042 })
7043 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007044 name: "Renegotiate-Client-BadExt2",
7045 renegotiate: 1,
7046 config: Config{
7047 MaxVersion: VersionTLS12,
7048 Bugs: ProtocolBugs{
7049 BadRenegotiationInfoEnd: true,
7050 },
7051 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007052 flags: []string{"-renegotiate-freely"},
7053 shouldFail: true,
7054 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007055 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007056 })
7057 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007058 name: "Renegotiate-Client-Downgrade",
7059 renegotiate: 1,
7060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007061 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007062 Bugs: ProtocolBugs{
7063 NoRenegotiationInfoAfterInitial: true,
7064 },
7065 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007066 flags: []string{"-renegotiate-freely"},
7067 shouldFail: true,
7068 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007069 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007070 })
7071 testCases = append(testCases, testCase{
7072 name: "Renegotiate-Client-Upgrade",
7073 renegotiate: 1,
7074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007075 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007076 Bugs: ProtocolBugs{
7077 NoRenegotiationInfoInInitial: true,
7078 },
7079 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007080 flags: []string{"-renegotiate-freely"},
7081 shouldFail: true,
7082 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007083 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007084 })
7085 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007086 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007087 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007089 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007090 Bugs: ProtocolBugs{
7091 NoRenegotiationInfo: true,
7092 },
7093 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007094 flags: []string{
7095 "-renegotiate-freely",
7096 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007097 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007098 },
David Benjamincff0b902015-05-15 23:09:47 -04007099 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007100
7101 // Test that the server may switch ciphers on renegotiation without
7102 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007103 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007104 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007105 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007106 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007107 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007108 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007109 },
7110 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007111 flags: []string{
7112 "-renegotiate-freely",
7113 "-expect-total-renegotiations", "1",
7114 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007115 })
7116 testCases = append(testCases, testCase{
7117 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007118 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007119 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007120 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007121 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7122 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007123 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007124 flags: []string{
7125 "-renegotiate-freely",
7126 "-expect-total-renegotiations", "1",
7127 },
David Benjaminb16346b2015-04-08 19:16:58 -04007128 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007129
7130 // Test that the server may not switch versions on renegotiation.
7131 testCases = append(testCases, testCase{
7132 name: "Renegotiate-Client-SwitchVersion",
7133 config: Config{
7134 MaxVersion: VersionTLS12,
7135 // Pick a cipher which exists at both versions.
7136 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7137 Bugs: ProtocolBugs{
7138 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007139 // Avoid failing early at the record layer.
7140 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007141 },
7142 },
7143 renegotiate: 1,
7144 flags: []string{
7145 "-renegotiate-freely",
7146 "-expect-total-renegotiations", "1",
7147 },
7148 shouldFail: true,
7149 expectedError: ":WRONG_SSL_VERSION:",
7150 })
7151
David Benjaminb16346b2015-04-08 19:16:58 -04007152 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007153 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007154 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007155 config: Config{
7156 MaxVersion: VersionTLS10,
7157 Bugs: ProtocolBugs{
7158 RequireSameRenegoClientVersion: true,
7159 },
7160 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007161 flags: []string{
7162 "-renegotiate-freely",
7163 "-expect-total-renegotiations", "1",
7164 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007165 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007166 testCases = append(testCases, testCase{
7167 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007168 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007169 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007170 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007171 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7172 NextProtos: []string{"foo"},
7173 },
7174 flags: []string{
7175 "-false-start",
7176 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007177 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007178 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007179 },
7180 shimWritesFirst: true,
7181 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007182
7183 // Client-side renegotiation controls.
7184 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007185 name: "Renegotiate-Client-Forbidden-1",
7186 config: Config{
7187 MaxVersion: VersionTLS12,
7188 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007189 renegotiate: 1,
7190 shouldFail: true,
7191 expectedError: ":NO_RENEGOTIATION:",
7192 expectedLocalError: "remote error: no renegotiation",
7193 })
7194 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007195 name: "Renegotiate-Client-Once-1",
7196 config: Config{
7197 MaxVersion: VersionTLS12,
7198 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007199 renegotiate: 1,
7200 flags: []string{
7201 "-renegotiate-once",
7202 "-expect-total-renegotiations", "1",
7203 },
7204 })
7205 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007206 name: "Renegotiate-Client-Freely-1",
7207 config: Config{
7208 MaxVersion: VersionTLS12,
7209 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007210 renegotiate: 1,
7211 flags: []string{
7212 "-renegotiate-freely",
7213 "-expect-total-renegotiations", "1",
7214 },
7215 })
7216 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007217 name: "Renegotiate-Client-Once-2",
7218 config: Config{
7219 MaxVersion: VersionTLS12,
7220 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007221 renegotiate: 2,
7222 flags: []string{"-renegotiate-once"},
7223 shouldFail: true,
7224 expectedError: ":NO_RENEGOTIATION:",
7225 expectedLocalError: "remote error: no renegotiation",
7226 })
7227 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007228 name: "Renegotiate-Client-Freely-2",
7229 config: Config{
7230 MaxVersion: VersionTLS12,
7231 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007232 renegotiate: 2,
7233 flags: []string{
7234 "-renegotiate-freely",
7235 "-expect-total-renegotiations", "2",
7236 },
7237 })
Adam Langley27a0d082015-11-03 13:34:10 -08007238 testCases = append(testCases, testCase{
7239 name: "Renegotiate-Client-NoIgnore",
7240 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007241 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007242 Bugs: ProtocolBugs{
7243 SendHelloRequestBeforeEveryAppDataRecord: true,
7244 },
7245 },
7246 shouldFail: true,
7247 expectedError: ":NO_RENEGOTIATION:",
7248 })
7249 testCases = append(testCases, testCase{
7250 name: "Renegotiate-Client-Ignore",
7251 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007252 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007253 Bugs: ProtocolBugs{
7254 SendHelloRequestBeforeEveryAppDataRecord: true,
7255 },
7256 },
7257 flags: []string{
7258 "-renegotiate-ignore",
7259 "-expect-total-renegotiations", "0",
7260 },
7261 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007262
David Benjamin34941c02016-10-08 11:45:31 -04007263 // Renegotiation is not allowed at SSL 3.0.
7264 testCases = append(testCases, testCase{
7265 name: "Renegotiate-Client-SSL3",
7266 config: Config{
7267 MaxVersion: VersionSSL30,
7268 },
7269 renegotiate: 1,
7270 flags: []string{
7271 "-renegotiate-freely",
7272 "-expect-total-renegotiations", "1",
7273 },
7274 shouldFail: true,
7275 expectedError: ":NO_RENEGOTIATION:",
7276 expectedLocalError: "remote error: no renegotiation",
7277 })
7278
David Benjamina1eaba12017-01-01 23:19:22 -05007279 // Renegotiation is not allowed when there is an unfinished write.
7280 testCases = append(testCases, testCase{
7281 name: "Renegotiate-Client-UnfinishedWrite",
7282 config: Config{
7283 MaxVersion: VersionTLS12,
7284 },
David Benjaminbbba9392017-04-06 12:54:12 -04007285 renegotiate: 1,
7286 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007287 flags: []string{
7288 "-async",
7289 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007290 },
7291 shouldFail: true,
7292 expectedError: ":NO_RENEGOTIATION:",
7293 // We do not successfully send the no_renegotiation alert in
7294 // this case. https://crbug.com/boringssl/130
7295 })
7296
David Benjamin07ab5d42017-02-09 20:11:41 -05007297 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007298 testCases = append(testCases, testCase{
7299 name: "StrayHelloRequest",
7300 config: Config{
7301 MaxVersion: VersionTLS12,
7302 Bugs: ProtocolBugs{
7303 SendHelloRequestBeforeEveryHandshakeMessage: true,
7304 },
7305 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007306 shouldFail: true,
7307 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007308 })
7309 testCases = append(testCases, testCase{
7310 name: "StrayHelloRequest-Packed",
7311 config: Config{
7312 MaxVersion: VersionTLS12,
7313 Bugs: ProtocolBugs{
7314 PackHandshakeFlight: true,
7315 SendHelloRequestBeforeEveryHandshakeMessage: true,
7316 },
7317 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007318 shouldFail: true,
7319 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007320 })
7321
David Benjamin12d2c482016-07-24 10:56:51 -04007322 // Test renegotiation works if HelloRequest and server Finished come in
7323 // the same record.
7324 testCases = append(testCases, testCase{
7325 name: "Renegotiate-Client-Packed",
7326 config: Config{
7327 MaxVersion: VersionTLS12,
7328 Bugs: ProtocolBugs{
7329 PackHandshakeFlight: true,
7330 PackHelloRequestWithFinished: true,
7331 },
7332 },
7333 renegotiate: 1,
7334 flags: []string{
7335 "-renegotiate-freely",
7336 "-expect-total-renegotiations", "1",
7337 },
7338 })
7339
David Benjamin397c8e62016-07-08 14:14:36 -07007340 // Renegotiation is forbidden in TLS 1.3.
7341 testCases = append(testCases, testCase{
7342 name: "Renegotiate-Client-TLS13",
7343 config: Config{
7344 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007345 Bugs: ProtocolBugs{
7346 SendHelloRequestBeforeEveryAppDataRecord: true,
7347 },
David Benjamin397c8e62016-07-08 14:14:36 -07007348 },
David Benjamin397c8e62016-07-08 14:14:36 -07007349 flags: []string{
7350 "-renegotiate-freely",
7351 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007352 shouldFail: true,
7353 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007354 })
7355
7356 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7357 testCases = append(testCases, testCase{
7358 name: "StrayHelloRequest-TLS13",
7359 config: Config{
7360 MaxVersion: VersionTLS13,
7361 Bugs: ProtocolBugs{
7362 SendHelloRequestBeforeEveryHandshakeMessage: true,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":UNEXPECTED_MESSAGE:",
7367 })
David Benjamind2610042017-01-03 10:49:28 -05007368
7369 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7370 // always reads as supporting it, regardless of whether it was
7371 // negotiated.
7372 testCases = append(testCases, testCase{
7373 name: "AlwaysReportRenegotiationInfo-TLS13",
7374 config: Config{
7375 MaxVersion: VersionTLS13,
7376 Bugs: ProtocolBugs{
7377 NoRenegotiationInfo: true,
7378 },
7379 },
7380 flags: []string{
7381 "-expect-secure-renegotiation",
7382 },
7383 })
David Benjamina58baaf2017-02-28 20:54:28 -05007384
7385 // Certificates may not change on renegotiation.
7386 testCases = append(testCases, testCase{
7387 name: "Renegotiation-CertificateChange",
7388 config: Config{
7389 MaxVersion: VersionTLS12,
7390 Certificates: []Certificate{rsaCertificate},
7391 Bugs: ProtocolBugs{
7392 RenegotiationCertificate: &rsaChainCertificate,
7393 },
7394 },
7395 renegotiate: 1,
7396 flags: []string{"-renegotiate-freely"},
7397 shouldFail: true,
7398 expectedError: ":SERVER_CERT_CHANGED:",
7399 })
7400 testCases = append(testCases, testCase{
7401 name: "Renegotiation-CertificateChange-2",
7402 config: Config{
7403 MaxVersion: VersionTLS12,
7404 Certificates: []Certificate{rsaCertificate},
7405 Bugs: ProtocolBugs{
7406 RenegotiationCertificate: &rsa1024Certificate,
7407 },
7408 },
7409 renegotiate: 1,
7410 flags: []string{"-renegotiate-freely"},
7411 shouldFail: true,
7412 expectedError: ":SERVER_CERT_CHANGED:",
7413 })
David Benjaminbbf42462017-03-14 21:27:10 -04007414
7415 // We do not negotiate ALPN after the initial handshake. This is
7416 // error-prone and only risks bugs in consumers.
7417 testCases = append(testCases, testCase{
7418 testType: clientTest,
7419 name: "Renegotiation-ForbidALPN",
7420 config: Config{
7421 MaxVersion: VersionTLS12,
7422 Bugs: ProtocolBugs{
7423 // Forcibly negotiate ALPN on both initial and
7424 // renegotiation handshakes. The test stack will
7425 // internally check the client does not offer
7426 // it.
7427 SendALPN: "foo",
7428 },
7429 },
7430 flags: []string{
7431 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7432 "-expect-alpn", "foo",
7433 "-renegotiate-freely",
7434 },
7435 renegotiate: 1,
7436 shouldFail: true,
7437 expectedError: ":UNEXPECTED_EXTENSION:",
7438 })
David Benjamin5c4271f2017-08-23 22:09:41 -07007439
7440 // The server may send different stapled OCSP responses or SCT lists on
7441 // renegotiation, but BoringSSL ignores this and reports the old values.
7442 // Also test that non-fatal verify results are preserved.
7443 testCases = append(testCases, testCase{
7444 testType: clientTest,
7445 name: "Renegotiation-ChangeAuthProperties",
7446 config: Config{
7447 MaxVersion: VersionTLS12,
7448 Bugs: ProtocolBugs{
7449 SendOCSPResponseOnRenegotiation: testOCSPResponse2,
7450 SendSCTListOnRenegotiation: testSCTList2,
7451 },
7452 },
7453 renegotiate: 1,
7454 flags: []string{
7455 "-renegotiate-freely",
7456 "-expect-total-renegotiations", "1",
7457 "-enable-ocsp-stapling",
7458 "-expect-ocsp-response",
7459 base64.StdEncoding.EncodeToString(testOCSPResponse),
7460 "-enable-signed-cert-timestamps",
7461 "-expect-signed-cert-timestamps",
7462 base64.StdEncoding.EncodeToString(testSCTList),
7463 "-verify-fail",
7464 "-expect-verify-result",
7465 },
7466 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007467}
7468
David Benjamin5e961c12014-11-07 01:48:35 -05007469func addDTLSReplayTests() {
7470 // Test that sequence number replays are detected.
7471 testCases = append(testCases, testCase{
7472 protocol: dtls,
7473 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007474 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007475 replayWrites: true,
7476 })
7477
David Benjamin8e6db492015-07-25 18:29:23 -04007478 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007479 // than the retransmit window.
7480 testCases = append(testCases, testCase{
7481 protocol: dtls,
7482 name: "DTLS-Replay-LargeGaps",
7483 config: Config{
7484 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007485 SequenceNumberMapping: func(in uint64) uint64 {
7486 return in * 127
7487 },
David Benjamin5e961c12014-11-07 01:48:35 -05007488 },
7489 },
David Benjamin8e6db492015-07-25 18:29:23 -04007490 messageCount: 200,
7491 replayWrites: true,
7492 })
7493
7494 // Test the incoming sequence number changing non-monotonically.
7495 testCases = append(testCases, testCase{
7496 protocol: dtls,
7497 name: "DTLS-Replay-NonMonotonic",
7498 config: Config{
7499 Bugs: ProtocolBugs{
7500 SequenceNumberMapping: func(in uint64) uint64 {
7501 return in ^ 31
7502 },
7503 },
7504 },
7505 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007506 replayWrites: true,
7507 })
7508}
7509
Nick Harper60edffd2016-06-21 15:19:24 -07007510var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007511 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007512 id signatureAlgorithm
7513 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007514}{
Nick Harper60edffd2016-06-21 15:19:24 -07007515 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7516 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7517 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7518 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007519 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007520 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7521 // hash function doesn't have to match the curve and so the same
7522 // signature algorithm works with P-224.
7523 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007524 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7525 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7526 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007527 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7528 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7529 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007530 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007531 // Tests for key types prior to TLS 1.2.
7532 {"RSA", 0, testCertRSA},
7533 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007534}
7535
Nick Harper60edffd2016-06-21 15:19:24 -07007536const fakeSigAlg1 signatureAlgorithm = 0x2a01
7537const fakeSigAlg2 signatureAlgorithm = 0xff01
7538
7539func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007540 // Not all ciphers involve a signature. Advertise a list which gives all
7541 // versions a signing cipher.
7542 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007543 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007544 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7545 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7546 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7547 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007548 }
David Benjamin5208fd42016-07-13 21:43:25 -04007549
David Benjaminca3d5452016-07-14 12:51:01 -04007550 var allAlgorithms []signatureAlgorithm
7551 for _, alg := range testSignatureAlgorithms {
7552 if alg.id != 0 {
7553 allAlgorithms = append(allAlgorithms, alg.id)
7554 }
7555 }
7556
Nick Harper60edffd2016-06-21 15:19:24 -07007557 // Make sure each signature algorithm works. Include some fake values in
7558 // the list and ensure they're ignored.
7559 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007560 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007561 if (ver.version < VersionTLS12) != (alg.id == 0) {
7562 continue
7563 }
7564
7565 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7566 // or remove it in C.
7567 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007568 continue
7569 }
Nick Harper60edffd2016-06-21 15:19:24 -07007570
David Benjamin3ef76972016-10-17 17:59:54 -04007571 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007572 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007573 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007574 shouldSignFail = true
7575 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007576 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007577 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007578 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7579 shouldSignFail = true
7580 shouldVerifyFail = true
7581 }
7582 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7583 // the curve has to match the hash size.
7584 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007585 shouldSignFail = true
7586 shouldVerifyFail = true
7587 }
7588
7589 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7590 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7591 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007592 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007593
7594 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007595 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007596 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007597 }
7598 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007599 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007600 }
David Benjamin000800a2014-11-14 01:43:59 -05007601
David Benjamin1fb125c2016-07-08 18:52:12 -07007602 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007603
David Benjamin7a41d372016-07-09 11:21:54 -07007604 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007605 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007606 config: Config{
7607 MaxVersion: ver.version,
7608 ClientAuth: RequireAnyClientCert,
7609 VerifySignatureAlgorithms: []signatureAlgorithm{
7610 fakeSigAlg1,
7611 alg.id,
7612 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007613 },
David Benjamin7a41d372016-07-09 11:21:54 -07007614 },
7615 flags: []string{
7616 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7617 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7618 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007619 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007620 },
David Benjamina5022392017-07-10 17:40:39 -04007621 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007622 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007623 expectedError: signError,
7624 expectedPeerSignatureAlgorithm: alg.id,
7625 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007626
David Benjamin7a41d372016-07-09 11:21:54 -07007627 testCases = append(testCases, testCase{
7628 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007629 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007630 config: Config{
7631 MaxVersion: ver.version,
7632 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7633 SignSignatureAlgorithms: []signatureAlgorithm{
7634 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007635 },
David Benjamin7a41d372016-07-09 11:21:54 -07007636 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007637 SkipECDSACurveCheck: shouldVerifyFail,
7638 IgnoreSignatureVersionChecks: shouldVerifyFail,
7639 // Some signature algorithms may not be advertised.
7640 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007641 },
David Benjamin7a41d372016-07-09 11:21:54 -07007642 },
David Benjamina5022392017-07-10 17:40:39 -04007643 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007644 flags: []string{
7645 "-require-any-client-certificate",
7646 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7647 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007648 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007649 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007650 // Resume the session to assert the peer signature
7651 // algorithm is reported on both handshakes.
7652 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007653 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007654 expectedError: verifyError,
7655 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007656
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007657 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007658 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007659 testCases = append(testCases, testCase{
7660 testType: serverTest,
7661 name: "ServerAuth-Sign" + suffix,
7662 config: Config{
7663 MaxVersion: ver.version,
7664 CipherSuites: signingCiphers,
7665 VerifySignatureAlgorithms: []signatureAlgorithm{
7666 fakeSigAlg1,
7667 alg.id,
7668 fakeSigAlg2,
7669 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007670 },
David Benjamina5022392017-07-10 17:40:39 -04007671 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007672 flags: []string{
7673 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7674 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7675 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007676 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007677 },
7678 shouldFail: shouldSignFail,
7679 expectedError: signError,
7680 expectedPeerSignatureAlgorithm: alg.id,
7681 })
7682 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007683
7684 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007685 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007686 config: Config{
7687 MaxVersion: ver.version,
7688 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007689 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007690 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007691 alg.id,
7692 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007693 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007694 SkipECDSACurveCheck: shouldVerifyFail,
7695 IgnoreSignatureVersionChecks: shouldVerifyFail,
7696 // Some signature algorithms may not be advertised.
7697 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007698 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007699 },
David Benjamina5022392017-07-10 17:40:39 -04007700 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007701 flags: []string{
7702 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7703 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007704 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007705 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007706 // Resume the session to assert the peer signature
7707 // algorithm is reported on both handshakes.
7708 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007709 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007710 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007711 })
David Benjamin5208fd42016-07-13 21:43:25 -04007712
David Benjamin3ef76972016-10-17 17:59:54 -04007713 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007714 testCases = append(testCases, testCase{
7715 testType: serverTest,
7716 name: "ClientAuth-InvalidSignature" + suffix,
7717 config: Config{
7718 MaxVersion: ver.version,
7719 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7720 SignSignatureAlgorithms: []signatureAlgorithm{
7721 alg.id,
7722 },
7723 Bugs: ProtocolBugs{
7724 InvalidSignature: true,
7725 },
7726 },
David Benjamina5022392017-07-10 17:40:39 -04007727 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007728 flags: []string{
7729 "-require-any-client-certificate",
7730 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007731 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007732 },
7733 shouldFail: true,
7734 expectedError: ":BAD_SIGNATURE:",
7735 })
7736
7737 testCases = append(testCases, testCase{
7738 name: "ServerAuth-InvalidSignature" + suffix,
7739 config: Config{
7740 MaxVersion: ver.version,
7741 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7742 CipherSuites: signingCiphers,
7743 SignSignatureAlgorithms: []signatureAlgorithm{
7744 alg.id,
7745 },
7746 Bugs: ProtocolBugs{
7747 InvalidSignature: true,
7748 },
7749 },
David Benjamina5022392017-07-10 17:40:39 -04007750 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007751 flags: []string{
7752 "-enable-all-curves",
7753 "-enable-ed25519",
7754 },
David Benjamin5208fd42016-07-13 21:43:25 -04007755 shouldFail: true,
7756 expectedError: ":BAD_SIGNATURE:",
7757 })
7758 }
David Benjaminca3d5452016-07-14 12:51:01 -04007759
David Benjamin3ef76972016-10-17 17:59:54 -04007760 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007761 testCases = append(testCases, testCase{
7762 name: "ClientAuth-Sign-Negotiate" + suffix,
7763 config: Config{
7764 MaxVersion: ver.version,
7765 ClientAuth: RequireAnyClientCert,
7766 VerifySignatureAlgorithms: allAlgorithms,
7767 },
David Benjamina5022392017-07-10 17:40:39 -04007768 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007769 flags: []string{
7770 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7771 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7772 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007773 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007774 "-signing-prefs", strconv.Itoa(int(alg.id)),
7775 },
7776 expectedPeerSignatureAlgorithm: alg.id,
7777 })
7778
7779 testCases = append(testCases, testCase{
7780 testType: serverTest,
7781 name: "ServerAuth-Sign-Negotiate" + suffix,
7782 config: Config{
7783 MaxVersion: ver.version,
7784 CipherSuites: signingCiphers,
7785 VerifySignatureAlgorithms: allAlgorithms,
7786 },
David Benjamina5022392017-07-10 17:40:39 -04007787 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007788 flags: []string{
7789 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7790 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7791 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007792 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007793 "-signing-prefs", strconv.Itoa(int(alg.id)),
7794 },
7795 expectedPeerSignatureAlgorithm: alg.id,
7796 })
7797 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007798 }
David Benjamin000800a2014-11-14 01:43:59 -05007799 }
7800
Nick Harper60edffd2016-06-21 15:19:24 -07007801 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007802 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007803 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007804 config: Config{
7805 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007806 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007807 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007808 signatureECDSAWithP521AndSHA512,
7809 signatureRSAPKCS1WithSHA384,
7810 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007811 },
7812 },
7813 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007814 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7815 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007816 },
Nick Harper60edffd2016-06-21 15:19:24 -07007817 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007818 })
7819
7820 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007821 name: "ClientAuth-SignatureType-TLS13",
7822 config: Config{
7823 ClientAuth: RequireAnyClientCert,
7824 MaxVersion: VersionTLS13,
7825 VerifySignatureAlgorithms: []signatureAlgorithm{
7826 signatureECDSAWithP521AndSHA512,
7827 signatureRSAPKCS1WithSHA384,
7828 signatureRSAPSSWithSHA384,
7829 signatureECDSAWithSHA1,
7830 },
7831 },
7832 flags: []string{
7833 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7834 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7835 },
7836 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7837 })
7838
7839 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007840 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007841 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007843 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007844 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007845 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007846 signatureECDSAWithP521AndSHA512,
7847 signatureRSAPKCS1WithSHA384,
7848 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007849 },
7850 },
Nick Harper60edffd2016-06-21 15:19:24 -07007851 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007852 })
7853
Steven Valdez143e8b32016-07-11 13:19:03 -04007854 testCases = append(testCases, testCase{
7855 testType: serverTest,
7856 name: "ServerAuth-SignatureType-TLS13",
7857 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007858 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007859 VerifySignatureAlgorithms: []signatureAlgorithm{
7860 signatureECDSAWithP521AndSHA512,
7861 signatureRSAPKCS1WithSHA384,
7862 signatureRSAPSSWithSHA384,
7863 signatureECDSAWithSHA1,
7864 },
7865 },
7866 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7867 })
7868
David Benjamina95e9f32016-07-08 16:28:04 -07007869 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007870 testCases = append(testCases, testCase{
7871 testType: serverTest,
7872 name: "Verify-ClientAuth-SignatureType",
7873 config: Config{
7874 MaxVersion: VersionTLS12,
7875 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007876 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007877 signatureRSAPKCS1WithSHA256,
7878 },
7879 Bugs: ProtocolBugs{
7880 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7881 },
7882 },
7883 flags: []string{
7884 "-require-any-client-certificate",
7885 },
7886 shouldFail: true,
7887 expectedError: ":WRONG_SIGNATURE_TYPE:",
7888 })
7889
7890 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007891 testType: serverTest,
7892 name: "Verify-ClientAuth-SignatureType-TLS13",
7893 config: Config{
7894 MaxVersion: VersionTLS13,
7895 Certificates: []Certificate{rsaCertificate},
7896 SignSignatureAlgorithms: []signatureAlgorithm{
7897 signatureRSAPSSWithSHA256,
7898 },
7899 Bugs: ProtocolBugs{
7900 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7901 },
7902 },
7903 flags: []string{
7904 "-require-any-client-certificate",
7905 },
7906 shouldFail: true,
7907 expectedError: ":WRONG_SIGNATURE_TYPE:",
7908 })
7909
7910 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007911 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007912 config: Config{
7913 MaxVersion: VersionTLS12,
7914 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007915 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007916 signatureRSAPKCS1WithSHA256,
7917 },
7918 Bugs: ProtocolBugs{
7919 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7920 },
7921 },
7922 shouldFail: true,
7923 expectedError: ":WRONG_SIGNATURE_TYPE:",
7924 })
7925
Steven Valdez143e8b32016-07-11 13:19:03 -04007926 testCases = append(testCases, testCase{
7927 name: "Verify-ServerAuth-SignatureType-TLS13",
7928 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007929 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007930 SignSignatureAlgorithms: []signatureAlgorithm{
7931 signatureRSAPSSWithSHA256,
7932 },
7933 Bugs: ProtocolBugs{
7934 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7935 },
7936 },
7937 shouldFail: true,
7938 expectedError: ":WRONG_SIGNATURE_TYPE:",
7939 })
7940
David Benjamin51dd7d62016-07-08 16:07:01 -07007941 // Test that, if the list is missing, the peer falls back to SHA-1 in
7942 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007943 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007944 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007946 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007947 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007948 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007949 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007950 },
7951 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007952 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007953 },
7954 },
7955 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007956 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7957 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007958 },
7959 })
7960
7961 testCases = append(testCases, testCase{
7962 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007963 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007964 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007965 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007966 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007967 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007968 },
7969 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007970 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007971 },
7972 },
David Benjaminee32bea2016-08-17 13:36:44 -04007973 flags: []string{
7974 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7975 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7976 },
7977 })
7978
7979 testCases = append(testCases, testCase{
7980 name: "ClientAuth-SHA1-Fallback-ECDSA",
7981 config: Config{
7982 MaxVersion: VersionTLS12,
7983 ClientAuth: RequireAnyClientCert,
7984 VerifySignatureAlgorithms: []signatureAlgorithm{
7985 signatureECDSAWithSHA1,
7986 },
7987 Bugs: ProtocolBugs{
7988 NoSignatureAlgorithms: true,
7989 },
7990 },
7991 flags: []string{
7992 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7993 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7994 },
7995 })
7996
7997 testCases = append(testCases, testCase{
7998 testType: serverTest,
7999 name: "ServerAuth-SHA1-Fallback-ECDSA",
8000 config: Config{
8001 MaxVersion: VersionTLS12,
8002 VerifySignatureAlgorithms: []signatureAlgorithm{
8003 signatureECDSAWithSHA1,
8004 },
8005 Bugs: ProtocolBugs{
8006 NoSignatureAlgorithms: true,
8007 },
8008 },
8009 flags: []string{
8010 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8011 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8012 },
David Benjamin000800a2014-11-14 01:43:59 -05008013 })
David Benjamin72dc7832015-03-16 17:49:43 -04008014
David Benjamin51dd7d62016-07-08 16:07:01 -07008015 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008016 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008017 config: Config{
8018 MaxVersion: VersionTLS13,
8019 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008020 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008021 signatureRSAPKCS1WithSHA1,
8022 },
8023 Bugs: ProtocolBugs{
8024 NoSignatureAlgorithms: true,
8025 },
8026 },
8027 flags: []string{
8028 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8029 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8030 },
David Benjamin48901652016-08-01 12:12:47 -04008031 shouldFail: true,
8032 // An empty CertificateRequest signature algorithm list is a
8033 // syntax error in TLS 1.3.
8034 expectedError: ":DECODE_ERROR:",
8035 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008036 })
8037
8038 testCases = append(testCases, testCase{
8039 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008040 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008041 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008042 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008043 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008044 signatureRSAPKCS1WithSHA1,
8045 },
8046 Bugs: ProtocolBugs{
8047 NoSignatureAlgorithms: true,
8048 },
8049 },
8050 shouldFail: true,
8051 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8052 })
8053
David Benjaminb62d2872016-07-18 14:55:02 +02008054 // Test that hash preferences are enforced. BoringSSL does not implement
8055 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008056 testCases = append(testCases, testCase{
8057 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008058 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008060 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008061 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008062 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008063 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008064 },
8065 Bugs: ProtocolBugs{
8066 IgnorePeerSignatureAlgorithmPreferences: true,
8067 },
8068 },
8069 flags: []string{"-require-any-client-certificate"},
8070 shouldFail: true,
8071 expectedError: ":WRONG_SIGNATURE_TYPE:",
8072 })
8073
8074 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008075 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008077 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008079 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008080 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008081 },
8082 Bugs: ProtocolBugs{
8083 IgnorePeerSignatureAlgorithmPreferences: true,
8084 },
8085 },
8086 shouldFail: true,
8087 expectedError: ":WRONG_SIGNATURE_TYPE:",
8088 })
David Benjaminb62d2872016-07-18 14:55:02 +02008089 testCases = append(testCases, testCase{
8090 testType: serverTest,
8091 name: "ClientAuth-Enforced-TLS13",
8092 config: Config{
8093 MaxVersion: VersionTLS13,
8094 Certificates: []Certificate{rsaCertificate},
8095 SignSignatureAlgorithms: []signatureAlgorithm{
8096 signatureRSAPKCS1WithMD5,
8097 },
8098 Bugs: ProtocolBugs{
8099 IgnorePeerSignatureAlgorithmPreferences: true,
8100 IgnoreSignatureVersionChecks: true,
8101 },
8102 },
8103 flags: []string{"-require-any-client-certificate"},
8104 shouldFail: true,
8105 expectedError: ":WRONG_SIGNATURE_TYPE:",
8106 })
8107
8108 testCases = append(testCases, testCase{
8109 name: "ServerAuth-Enforced-TLS13",
8110 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008111 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008112 SignSignatureAlgorithms: []signatureAlgorithm{
8113 signatureRSAPKCS1WithMD5,
8114 },
8115 Bugs: ProtocolBugs{
8116 IgnorePeerSignatureAlgorithmPreferences: true,
8117 IgnoreSignatureVersionChecks: true,
8118 },
8119 },
8120 shouldFail: true,
8121 expectedError: ":WRONG_SIGNATURE_TYPE:",
8122 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008123
8124 // Test that the agreed upon digest respects the client preferences and
8125 // the server digests.
8126 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008127 name: "NoCommonAlgorithms-Digests",
8128 config: Config{
8129 MaxVersion: VersionTLS12,
8130 ClientAuth: RequireAnyClientCert,
8131 VerifySignatureAlgorithms: []signatureAlgorithm{
8132 signatureRSAPKCS1WithSHA512,
8133 signatureRSAPKCS1WithSHA1,
8134 },
8135 },
8136 flags: []string{
8137 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8138 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8139 "-digest-prefs", "SHA256",
8140 },
8141 shouldFail: true,
8142 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8143 })
8144 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008145 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008147 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008148 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008149 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008150 signatureRSAPKCS1WithSHA512,
8151 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008152 },
8153 },
8154 flags: []string{
8155 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8156 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008157 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008158 },
David Benjaminca3d5452016-07-14 12:51:01 -04008159 shouldFail: true,
8160 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8161 })
8162 testCases = append(testCases, testCase{
8163 name: "NoCommonAlgorithms-TLS13",
8164 config: Config{
8165 MaxVersion: VersionTLS13,
8166 ClientAuth: RequireAnyClientCert,
8167 VerifySignatureAlgorithms: []signatureAlgorithm{
8168 signatureRSAPSSWithSHA512,
8169 signatureRSAPSSWithSHA384,
8170 },
8171 },
8172 flags: []string{
8173 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8174 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8175 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8176 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008177 shouldFail: true,
8178 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008179 })
8180 testCases = append(testCases, testCase{
8181 name: "Agree-Digest-SHA256",
8182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008183 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008184 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008185 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008186 signatureRSAPKCS1WithSHA1,
8187 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008188 },
8189 },
8190 flags: []string{
8191 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8192 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008193 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008194 },
Nick Harper60edffd2016-06-21 15:19:24 -07008195 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008196 })
8197 testCases = append(testCases, testCase{
8198 name: "Agree-Digest-SHA1",
8199 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008200 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008201 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008202 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008203 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008204 },
8205 },
8206 flags: []string{
8207 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8208 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008209 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008210 },
Nick Harper60edffd2016-06-21 15:19:24 -07008211 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008212 })
8213 testCases = append(testCases, testCase{
8214 name: "Agree-Digest-Default",
8215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008216 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008217 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008218 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008219 signatureRSAPKCS1WithSHA256,
8220 signatureECDSAWithP256AndSHA256,
8221 signatureRSAPKCS1WithSHA1,
8222 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008223 },
8224 },
8225 flags: []string{
8226 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8227 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8228 },
Nick Harper60edffd2016-06-21 15:19:24 -07008229 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008230 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008231
David Benjaminca3d5452016-07-14 12:51:01 -04008232 // Test that the signing preference list may include extra algorithms
8233 // without negotiation problems.
8234 testCases = append(testCases, testCase{
8235 testType: serverTest,
8236 name: "FilterExtraAlgorithms",
8237 config: Config{
8238 MaxVersion: VersionTLS12,
8239 VerifySignatureAlgorithms: []signatureAlgorithm{
8240 signatureRSAPKCS1WithSHA256,
8241 },
8242 },
8243 flags: []string{
8244 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8245 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8246 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8247 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8248 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8249 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8250 },
8251 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8252 })
8253
David Benjamin4c3ddf72016-06-29 18:13:53 -04008254 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8255 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008256 testCases = append(testCases, testCase{
8257 name: "CheckLeafCurve",
8258 config: Config{
8259 MaxVersion: VersionTLS12,
8260 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008261 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008262 },
8263 flags: []string{"-p384-only"},
8264 shouldFail: true,
8265 expectedError: ":BAD_ECC_CERT:",
8266 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008267
8268 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8269 testCases = append(testCases, testCase{
8270 name: "CheckLeafCurve-TLS13",
8271 config: Config{
8272 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008273 Certificates: []Certificate{ecdsaP256Certificate},
8274 },
8275 flags: []string{"-p384-only"},
8276 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008277
8278 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8279 testCases = append(testCases, testCase{
8280 name: "ECDSACurveMismatch-Verify-TLS12",
8281 config: Config{
8282 MaxVersion: VersionTLS12,
8283 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8284 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008285 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008286 signatureECDSAWithP384AndSHA384,
8287 },
8288 },
8289 })
8290
8291 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8292 testCases = append(testCases, testCase{
8293 name: "ECDSACurveMismatch-Verify-TLS13",
8294 config: Config{
8295 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008296 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008297 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008298 signatureECDSAWithP384AndSHA384,
8299 },
8300 Bugs: ProtocolBugs{
8301 SkipECDSACurveCheck: true,
8302 },
8303 },
8304 shouldFail: true,
8305 expectedError: ":WRONG_SIGNATURE_TYPE:",
8306 })
8307
8308 // Signature algorithm selection in TLS 1.3 should take the curve into
8309 // account.
8310 testCases = append(testCases, testCase{
8311 testType: serverTest,
8312 name: "ECDSACurveMismatch-Sign-TLS13",
8313 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008314 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008315 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008316 signatureECDSAWithP384AndSHA384,
8317 signatureECDSAWithP256AndSHA256,
8318 },
8319 },
8320 flags: []string{
8321 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8322 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8323 },
8324 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8325 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008326
8327 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8328 // server does not attempt to sign in that case.
8329 testCases = append(testCases, testCase{
8330 testType: serverTest,
8331 name: "RSA-PSS-Large",
8332 config: Config{
8333 MaxVersion: VersionTLS13,
8334 VerifySignatureAlgorithms: []signatureAlgorithm{
8335 signatureRSAPSSWithSHA512,
8336 },
8337 },
8338 flags: []string{
8339 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8340 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8341 },
8342 shouldFail: true,
8343 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8344 })
David Benjamin57e929f2016-08-30 00:30:38 -04008345
8346 // Test that RSA-PSS is enabled by default for TLS 1.2.
8347 testCases = append(testCases, testCase{
8348 testType: clientTest,
8349 name: "RSA-PSS-Default-Verify",
8350 config: Config{
8351 MaxVersion: VersionTLS12,
8352 SignSignatureAlgorithms: []signatureAlgorithm{
8353 signatureRSAPSSWithSHA256,
8354 },
8355 },
8356 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8357 })
8358
8359 testCases = append(testCases, testCase{
8360 testType: serverTest,
8361 name: "RSA-PSS-Default-Sign",
8362 config: Config{
8363 MaxVersion: VersionTLS12,
8364 VerifySignatureAlgorithms: []signatureAlgorithm{
8365 signatureRSAPSSWithSHA256,
8366 },
8367 },
8368 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8369 })
David Benjamin69522112017-03-28 15:38:29 -05008370
8371 // TLS 1.1 and below has no way to advertise support for or negotiate
8372 // Ed25519's signature algorithm.
8373 testCases = append(testCases, testCase{
8374 testType: clientTest,
8375 name: "NoEd25519-TLS11-ServerAuth-Verify",
8376 config: Config{
8377 MaxVersion: VersionTLS11,
8378 Certificates: []Certificate{ed25519Certificate},
8379 Bugs: ProtocolBugs{
8380 // Sign with Ed25519 even though it is TLS 1.1.
8381 UseLegacySigningAlgorithm: signatureEd25519,
8382 },
8383 },
8384 flags: []string{"-enable-ed25519"},
8385 shouldFail: true,
8386 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8387 })
8388 testCases = append(testCases, testCase{
8389 testType: serverTest,
8390 name: "NoEd25519-TLS11-ServerAuth-Sign",
8391 config: Config{
8392 MaxVersion: VersionTLS11,
8393 },
8394 flags: []string{
8395 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8396 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8397 },
8398 shouldFail: true,
8399 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8400 })
8401 testCases = append(testCases, testCase{
8402 testType: serverTest,
8403 name: "NoEd25519-TLS11-ClientAuth-Verify",
8404 config: Config{
8405 MaxVersion: VersionTLS11,
8406 Certificates: []Certificate{ed25519Certificate},
8407 Bugs: ProtocolBugs{
8408 // Sign with Ed25519 even though it is TLS 1.1.
8409 UseLegacySigningAlgorithm: signatureEd25519,
8410 },
8411 },
8412 flags: []string{
8413 "-enable-ed25519",
8414 "-require-any-client-certificate",
8415 },
8416 shouldFail: true,
8417 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8418 })
8419 testCases = append(testCases, testCase{
8420 testType: clientTest,
8421 name: "NoEd25519-TLS11-ClientAuth-Sign",
8422 config: Config{
8423 MaxVersion: VersionTLS11,
8424 ClientAuth: RequireAnyClientCert,
8425 },
8426 flags: []string{
8427 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8428 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8429 },
8430 shouldFail: true,
8431 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8432 })
8433
8434 // Test Ed25519 is not advertised by default.
8435 testCases = append(testCases, testCase{
8436 testType: clientTest,
8437 name: "Ed25519DefaultDisable-NoAdvertise",
8438 config: Config{
8439 Certificates: []Certificate{ed25519Certificate},
8440 },
8441 shouldFail: true,
8442 expectedLocalError: "tls: no common signature algorithms",
8443 })
8444
8445 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8446 // preferences.
8447 testCases = append(testCases, testCase{
8448 testType: clientTest,
8449 name: "Ed25519DefaultDisable-NoAccept",
8450 config: Config{
8451 Certificates: []Certificate{ed25519Certificate},
8452 Bugs: ProtocolBugs{
8453 IgnorePeerSignatureAlgorithmPreferences: true,
8454 },
8455 },
8456 shouldFail: true,
8457 expectedLocalError: "remote error: illegal parameter",
8458 expectedError: ":WRONG_SIGNATURE_TYPE:",
8459 })
David Benjamin71c21b42017-04-14 17:05:40 -04008460
8461 // Test that configuring verify preferences changes what the client
8462 // advertises.
8463 testCases = append(testCases, testCase{
8464 name: "VerifyPreferences-Advertised",
8465 config: Config{
8466 Certificates: []Certificate{rsaCertificate},
8467 SignSignatureAlgorithms: []signatureAlgorithm{
8468 signatureRSAPSSWithSHA256,
8469 signatureRSAPSSWithSHA384,
8470 signatureRSAPSSWithSHA512,
8471 },
8472 },
8473 flags: []string{
8474 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8475 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8476 },
8477 })
8478
8479 // Test that the client advertises a set which the runner can find
8480 // nothing in common with.
8481 testCases = append(testCases, testCase{
8482 name: "VerifyPreferences-NoCommonAlgorithms",
8483 config: Config{
8484 Certificates: []Certificate{rsaCertificate},
8485 SignSignatureAlgorithms: []signatureAlgorithm{
8486 signatureRSAPSSWithSHA256,
8487 signatureRSAPSSWithSHA512,
8488 },
8489 },
8490 flags: []string{
8491 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8492 },
8493 shouldFail: true,
8494 expectedLocalError: "tls: no common signature algorithms",
8495 })
8496
8497 // Test that the client enforces its preferences when configured.
8498 testCases = append(testCases, testCase{
8499 name: "VerifyPreferences-Enforced",
8500 config: Config{
8501 Certificates: []Certificate{rsaCertificate},
8502 SignSignatureAlgorithms: []signatureAlgorithm{
8503 signatureRSAPSSWithSHA256,
8504 signatureRSAPSSWithSHA512,
8505 },
8506 Bugs: ProtocolBugs{
8507 IgnorePeerSignatureAlgorithmPreferences: true,
8508 },
8509 },
8510 flags: []string{
8511 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8512 },
8513 shouldFail: true,
8514 expectedLocalError: "remote error: illegal parameter",
8515 expectedError: ":WRONG_SIGNATURE_TYPE:",
8516 })
8517
8518 // Test that explicitly configuring Ed25519 is as good as changing the
8519 // boolean toggle.
8520 testCases = append(testCases, testCase{
8521 name: "VerifyPreferences-Ed25519",
8522 config: Config{
8523 Certificates: []Certificate{ed25519Certificate},
8524 },
8525 flags: []string{
8526 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8527 },
8528 })
David Benjamin000800a2014-11-14 01:43:59 -05008529}
8530
David Benjamin83f90402015-01-27 01:09:43 -05008531// timeouts is the retransmit schedule for BoringSSL. It doubles and
8532// caps at 60 seconds. On the 13th timeout, it gives up.
8533var timeouts = []time.Duration{
8534 1 * time.Second,
8535 2 * time.Second,
8536 4 * time.Second,
8537 8 * time.Second,
8538 16 * time.Second,
8539 32 * time.Second,
8540 60 * time.Second,
8541 60 * time.Second,
8542 60 * time.Second,
8543 60 * time.Second,
8544 60 * time.Second,
8545 60 * time.Second,
8546 60 * time.Second,
8547}
8548
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008549// shortTimeouts is an alternate set of timeouts which would occur if the
8550// initial timeout duration was set to 250ms.
8551var shortTimeouts = []time.Duration{
8552 250 * time.Millisecond,
8553 500 * time.Millisecond,
8554 1 * time.Second,
8555 2 * time.Second,
8556 4 * time.Second,
8557 8 * time.Second,
8558 16 * time.Second,
8559 32 * time.Second,
8560 60 * time.Second,
8561 60 * time.Second,
8562 60 * time.Second,
8563 60 * time.Second,
8564 60 * time.Second,
8565}
8566
David Benjamin83f90402015-01-27 01:09:43 -05008567func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008568 // These tests work by coordinating some behavior on both the shim and
8569 // the runner.
8570 //
8571 // TimeoutSchedule configures the runner to send a series of timeout
8572 // opcodes to the shim (see packetAdaptor) immediately before reading
8573 // each peer handshake flight N. The timeout opcode both simulates a
8574 // timeout in the shim and acts as a synchronization point to help the
8575 // runner bracket each handshake flight.
8576 //
8577 // We assume the shim does not read from the channel eagerly. It must
8578 // first wait until it has sent flight N and is ready to receive
8579 // handshake flight N+1. At this point, it will process the timeout
8580 // opcode. It must then immediately respond with a timeout ACK and act
8581 // as if the shim was idle for the specified amount of time.
8582 //
8583 // The runner then drops all packets received before the ACK and
8584 // continues waiting for flight N. This ordering results in one attempt
8585 // at sending flight N to be dropped. For the test to complete, the
8586 // shim must send flight N again, testing that the shim implements DTLS
8587 // retransmit on a timeout.
8588
Steven Valdez143e8b32016-07-11 13:19:03 -04008589 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008590 // likely be more epochs to cross and the final message's retransmit may
8591 // be more complex.
8592
David Benjamin11c82892017-02-23 20:40:31 -05008593 // Test that this is indeed the timeout schedule. Stress all
8594 // four patterns of handshake.
8595 for i := 1; i < len(timeouts); i++ {
8596 number := strconv.Itoa(i)
8597 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008598 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008599 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008601 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008602 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008603 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008604 },
8605 },
8606 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008607 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008608 })
David Benjamin11c82892017-02-23 20:40:31 -05008609 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008610 protocol: dtls,
8611 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008612 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008613 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008614 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008615 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008616 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008617 },
8618 },
8619 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008620 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008621 })
8622 }
David Benjamin11c82892017-02-23 20:40:31 -05008623
8624 // Test that exceeding the timeout schedule hits a read
8625 // timeout.
8626 testCases = append(testCases, testCase{
8627 protocol: dtls,
8628 name: "DTLS-Retransmit-Timeout",
8629 config: Config{
8630 MaxVersion: VersionTLS12,
8631 Bugs: ProtocolBugs{
8632 TimeoutSchedule: timeouts,
8633 },
8634 },
8635 resumeSession: true,
8636 flags: []string{"-async"},
8637 shouldFail: true,
8638 expectedError: ":READ_TIMEOUT_EXPIRED:",
8639 })
8640
8641 // Test that timeout handling has a fudge factor, due to API
8642 // problems.
8643 testCases = append(testCases, testCase{
8644 protocol: dtls,
8645 name: "DTLS-Retransmit-Fudge",
8646 config: Config{
8647 MaxVersion: VersionTLS12,
8648 Bugs: ProtocolBugs{
8649 TimeoutSchedule: []time.Duration{
8650 timeouts[0] - 10*time.Millisecond,
8651 },
8652 },
8653 },
8654 resumeSession: true,
8655 flags: []string{"-async"},
8656 })
8657
8658 // Test that the final Finished retransmitting isn't
8659 // duplicated if the peer badly fragments everything.
8660 testCases = append(testCases, testCase{
8661 testType: serverTest,
8662 protocol: dtls,
8663 name: "DTLS-Retransmit-Fragmented",
8664 config: Config{
8665 MaxVersion: VersionTLS12,
8666 Bugs: ProtocolBugs{
8667 TimeoutSchedule: []time.Duration{timeouts[0]},
8668 MaxHandshakeRecordLength: 2,
8669 },
8670 },
8671 flags: []string{"-async"},
8672 })
8673
8674 // Test the timeout schedule when a shorter initial timeout duration is set.
8675 testCases = append(testCases, testCase{
8676 protocol: dtls,
8677 name: "DTLS-Retransmit-Short-Client",
8678 config: Config{
8679 MaxVersion: VersionTLS12,
8680 Bugs: ProtocolBugs{
8681 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8682 },
8683 },
8684 resumeSession: true,
8685 flags: []string{
8686 "-async",
8687 "-initial-timeout-duration-ms", "250",
8688 },
8689 })
8690 testCases = append(testCases, testCase{
8691 protocol: dtls,
8692 testType: serverTest,
8693 name: "DTLS-Retransmit-Short-Server",
8694 config: Config{
8695 MaxVersion: VersionTLS12,
8696 Bugs: ProtocolBugs{
8697 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8698 },
8699 },
8700 resumeSession: true,
8701 flags: []string{
8702 "-async",
8703 "-initial-timeout-duration-ms", "250",
8704 },
8705 })
David Benjamin302b8182017-08-22 14:47:22 -07008706
8707 // If the shim sends the last Finished (server full or client resume
8708 // handshakes), it must retransmit that Finished when it sees a
8709 // post-handshake penultimate Finished from the runner. The above tests
8710 // cover this. Conversely, if the shim sends the penultimate Finished
8711 // (client full or server resume), test that it does not retransmit.
8712 testCases = append(testCases, testCase{
8713 protocol: dtls,
8714 testType: clientTest,
8715 name: "DTLS-StrayRetransmitFinished-ClientFull",
8716 config: Config{
8717 MaxVersion: VersionTLS12,
8718 Bugs: ProtocolBugs{
8719 RetransmitFinished: true,
8720 },
8721 },
8722 })
8723 testCases = append(testCases, testCase{
8724 protocol: dtls,
8725 testType: serverTest,
8726 name: "DTLS-StrayRetransmitFinished-ServerResume",
8727 config: Config{
8728 MaxVersion: VersionTLS12,
8729 },
8730 resumeConfig: &Config{
8731 MaxVersion: VersionTLS12,
8732 Bugs: ProtocolBugs{
8733 RetransmitFinished: true,
8734 },
8735 },
8736 resumeSession: true,
8737 })
David Benjamin83f90402015-01-27 01:09:43 -05008738}
8739
David Benjaminc565ebb2015-04-03 04:06:36 -04008740func addExportKeyingMaterialTests() {
8741 for _, vers := range tlsVersions {
8742 if vers.version == VersionSSL30 {
8743 continue
8744 }
8745 testCases = append(testCases, testCase{
8746 name: "ExportKeyingMaterial-" + vers.name,
8747 config: Config{
8748 MaxVersion: vers.version,
8749 },
David Benjamina5022392017-07-10 17:40:39 -04008750 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008751 exportKeyingMaterial: 1024,
8752 exportLabel: "label",
8753 exportContext: "context",
8754 useExportContext: true,
8755 })
8756 testCases = append(testCases, testCase{
8757 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8758 config: Config{
8759 MaxVersion: vers.version,
8760 },
David Benjamina5022392017-07-10 17:40:39 -04008761 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008762 exportKeyingMaterial: 1024,
8763 })
8764 testCases = append(testCases, testCase{
8765 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8766 config: Config{
8767 MaxVersion: vers.version,
8768 },
David Benjamina5022392017-07-10 17:40:39 -04008769 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008770 exportKeyingMaterial: 1024,
8771 useExportContext: true,
8772 })
8773 testCases = append(testCases, testCase{
8774 name: "ExportKeyingMaterial-Small-" + vers.name,
8775 config: Config{
8776 MaxVersion: vers.version,
8777 },
David Benjamina5022392017-07-10 17:40:39 -04008778 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008779 exportKeyingMaterial: 1,
8780 exportLabel: "label",
8781 exportContext: "context",
8782 useExportContext: true,
8783 })
8784 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008785
David Benjaminc565ebb2015-04-03 04:06:36 -04008786 testCases = append(testCases, testCase{
8787 name: "ExportKeyingMaterial-SSL3",
8788 config: Config{
8789 MaxVersion: VersionSSL30,
8790 },
8791 exportKeyingMaterial: 1024,
8792 exportLabel: "label",
8793 exportContext: "context",
8794 useExportContext: true,
8795 shouldFail: true,
8796 expectedError: "failed to export keying material",
8797 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008798
8799 // Exporters work during a False Start.
8800 testCases = append(testCases, testCase{
8801 name: "ExportKeyingMaterial-FalseStart",
8802 config: Config{
8803 MaxVersion: VersionTLS12,
8804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8805 NextProtos: []string{"foo"},
8806 Bugs: ProtocolBugs{
8807 ExpectFalseStart: true,
8808 },
8809 },
8810 flags: []string{
8811 "-false-start",
8812 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008813 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008814 },
8815 shimWritesFirst: true,
8816 exportKeyingMaterial: 1024,
8817 exportLabel: "label",
8818 exportContext: "context",
8819 useExportContext: true,
8820 })
8821
8822 // Exporters do not work in the middle of a renegotiation. Test this by
8823 // triggering the exporter after every SSL_read call and configuring the
8824 // shim to run asynchronously.
8825 testCases = append(testCases, testCase{
8826 name: "ExportKeyingMaterial-Renegotiate",
8827 config: Config{
8828 MaxVersion: VersionTLS12,
8829 },
8830 renegotiate: 1,
8831 flags: []string{
8832 "-async",
8833 "-use-exporter-between-reads",
8834 "-renegotiate-freely",
8835 "-expect-total-renegotiations", "1",
8836 },
8837 shouldFail: true,
8838 expectedError: "failed to export keying material",
8839 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008840}
8841
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008842func addTLSUniqueTests() {
8843 for _, isClient := range []bool{false, true} {
8844 for _, isResumption := range []bool{false, true} {
8845 for _, hasEMS := range []bool{false, true} {
8846 var suffix string
8847 if isResumption {
8848 suffix = "Resume-"
8849 } else {
8850 suffix = "Full-"
8851 }
8852
8853 if hasEMS {
8854 suffix += "EMS-"
8855 } else {
8856 suffix += "NoEMS-"
8857 }
8858
8859 if isClient {
8860 suffix += "Client"
8861 } else {
8862 suffix += "Server"
8863 }
8864
8865 test := testCase{
8866 name: "TLSUnique-" + suffix,
8867 testTLSUnique: true,
8868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008869 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008870 Bugs: ProtocolBugs{
8871 NoExtendedMasterSecret: !hasEMS,
8872 },
8873 },
8874 }
8875
8876 if isResumption {
8877 test.resumeSession = true
8878 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008879 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008880 Bugs: ProtocolBugs{
8881 NoExtendedMasterSecret: !hasEMS,
8882 },
8883 }
8884 }
8885
8886 if isResumption && !hasEMS {
8887 test.shouldFail = true
8888 test.expectedError = "failed to get tls-unique"
8889 }
8890
8891 testCases = append(testCases, test)
8892 }
8893 }
8894 }
8895}
8896
Adam Langley09505632015-07-30 18:10:13 -07008897func addCustomExtensionTests() {
8898 expectedContents := "custom extension"
8899 emptyString := ""
8900
8901 for _, isClient := range []bool{false, true} {
8902 suffix := "Server"
8903 flag := "-enable-server-custom-extension"
8904 testType := serverTest
8905 if isClient {
8906 suffix = "Client"
8907 flag = "-enable-client-custom-extension"
8908 testType = clientTest
8909 }
8910
8911 testCases = append(testCases, testCase{
8912 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008913 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008915 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008916 Bugs: ProtocolBugs{
8917 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008918 ExpectedCustomExtension: &expectedContents,
8919 },
8920 },
8921 flags: []string{flag},
8922 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008923 testCases = append(testCases, testCase{
8924 testType: testType,
8925 name: "CustomExtensions-" + suffix + "-TLS13",
8926 config: Config{
8927 MaxVersion: VersionTLS13,
8928 Bugs: ProtocolBugs{
8929 CustomExtension: expectedContents,
8930 ExpectedCustomExtension: &expectedContents,
8931 },
8932 },
8933 flags: []string{flag},
8934 })
Adam Langley09505632015-07-30 18:10:13 -07008935
8936 // If the parse callback fails, the handshake should also fail.
8937 testCases = append(testCases, testCase{
8938 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008939 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008941 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008942 Bugs: ProtocolBugs{
8943 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008944 ExpectedCustomExtension: &expectedContents,
8945 },
8946 },
David Benjamin399e7c92015-07-30 23:01:27 -04008947 flags: []string{flag},
8948 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008949 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8950 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008951 testCases = append(testCases, testCase{
8952 testType: testType,
8953 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8954 config: Config{
8955 MaxVersion: VersionTLS13,
8956 Bugs: ProtocolBugs{
8957 CustomExtension: expectedContents + "foo",
8958 ExpectedCustomExtension: &expectedContents,
8959 },
8960 },
8961 flags: []string{flag},
8962 shouldFail: true,
8963 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8964 })
Adam Langley09505632015-07-30 18:10:13 -07008965
8966 // If the add callback fails, the handshake should also fail.
8967 testCases = append(testCases, testCase{
8968 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008969 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008971 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008972 Bugs: ProtocolBugs{
8973 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008974 ExpectedCustomExtension: &expectedContents,
8975 },
8976 },
David Benjamin399e7c92015-07-30 23:01:27 -04008977 flags: []string{flag, "-custom-extension-fail-add"},
8978 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008979 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8980 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008981 testCases = append(testCases, testCase{
8982 testType: testType,
8983 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8984 config: Config{
8985 MaxVersion: VersionTLS13,
8986 Bugs: ProtocolBugs{
8987 CustomExtension: expectedContents,
8988 ExpectedCustomExtension: &expectedContents,
8989 },
8990 },
8991 flags: []string{flag, "-custom-extension-fail-add"},
8992 shouldFail: true,
8993 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8994 })
Adam Langley09505632015-07-30 18:10:13 -07008995
8996 // If the add callback returns zero, no extension should be
8997 // added.
8998 skipCustomExtension := expectedContents
8999 if isClient {
9000 // For the case where the client skips sending the
9001 // custom extension, the server must not “echo” it.
9002 skipCustomExtension = ""
9003 }
9004 testCases = append(testCases, testCase{
9005 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009006 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009007 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009008 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009009 Bugs: ProtocolBugs{
9010 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009011 ExpectedCustomExtension: &emptyString,
9012 },
9013 },
9014 flags: []string{flag, "-custom-extension-skip"},
9015 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009016 testCases = append(testCases, testCase{
9017 testType: testType,
9018 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9019 config: Config{
9020 MaxVersion: VersionTLS13,
9021 Bugs: ProtocolBugs{
9022 CustomExtension: skipCustomExtension,
9023 ExpectedCustomExtension: &emptyString,
9024 },
9025 },
9026 flags: []string{flag, "-custom-extension-skip"},
9027 })
Adam Langley09505632015-07-30 18:10:13 -07009028 }
9029
Steven Valdezf4ecc842017-08-10 14:02:56 -04009030 // If the client sends both early data and custom extension, the handshake
9031 // should succeed as long as both the extensions aren't returned by the
9032 // server.
9033 testCases = append(testCases, testCase{
9034 testType: clientTest,
9035 name: "CustomExtensions-Client-EarlyData-None",
9036 config: Config{
9037 MaxVersion: VersionTLS13,
9038 MaxEarlyDataSize: 16384,
9039 Bugs: ProtocolBugs{
9040 ExpectedCustomExtension: &expectedContents,
9041 AlwaysRejectEarlyData: true,
9042 },
9043 },
9044 resumeSession: true,
9045 flags: []string{
9046 "-enable-client-custom-extension",
9047 "-enable-early-data",
9048 "-expect-early-data-info",
9049 "-expect-reject-early-data",
9050 },
9051 })
9052
9053 testCases = append(testCases, testCase{
9054 testType: clientTest,
9055 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9056 config: Config{
9057 MaxVersion: VersionTLS13,
9058 MaxEarlyDataSize: 16384,
9059 Bugs: ProtocolBugs{
9060 ExpectedCustomExtension: &expectedContents,
9061 },
9062 },
9063 resumeSession: true,
9064 flags: []string{
9065 "-enable-client-custom-extension",
9066 "-enable-early-data",
9067 "-expect-early-data-info",
9068 "-expect-accept-early-data",
9069 },
9070 })
9071
9072 testCases = append(testCases, testCase{
9073 testType: clientTest,
9074 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 MaxEarlyDataSize: 16384,
9078 Bugs: ProtocolBugs{
9079 AlwaysRejectEarlyData: true,
9080 CustomExtension: expectedContents,
9081 ExpectedCustomExtension: &expectedContents,
9082 },
9083 },
9084 resumeSession: true,
9085 flags: []string{
9086 "-enable-client-custom-extension",
9087 "-enable-early-data",
9088 "-expect-early-data-info",
9089 "-expect-reject-early-data",
9090 },
9091 })
9092
9093 testCases = append(testCases, testCase{
9094 testType: clientTest,
9095 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9096 config: Config{
9097 MaxVersion: VersionTLS13,
9098 MaxEarlyDataSize: 16384,
9099 Bugs: ProtocolBugs{
9100 CustomExtension: expectedContents,
9101 ExpectedCustomExtension: &expectedContents,
9102 },
9103 },
9104 resumeConfig: &Config{
9105 MaxVersion: VersionTLS13,
9106 MaxEarlyDataSize: 16384,
9107 Bugs: ProtocolBugs{
9108 CustomExtension: expectedContents,
9109 ExpectedCustomExtension: &expectedContents,
9110 SendEarlyDataExtension: true,
9111 },
9112 },
9113 resumeSession: true,
9114 shouldFail: true,
9115 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9116 flags: []string{
9117 "-enable-client-custom-extension",
9118 "-enable-early-data",
9119 "-expect-early-data-info",
9120 },
9121 })
9122
9123 // If the server receives both early data and custom extension, only the
9124 // custom extension should be accepted.
9125 testCases = append(testCases, testCase{
9126 testType: serverTest,
9127 name: "CustomExtensions-Server-EarlyDataAccepted",
9128 config: Config{
9129 MaxVersion: VersionTLS13,
9130 MaxEarlyDataSize: 16384,
9131 Bugs: ProtocolBugs{
9132 CustomExtension: expectedContents,
9133 ExpectedCustomExtension: &expectedContents,
9134 ExpectEarlyDataAccepted: false,
9135 },
9136 },
9137 resumeSession: true,
9138 flags: []string{
9139 "-enable-server-custom-extension",
9140 "-enable-early-data",
9141 "-expect-early-data-info",
9142 },
9143 })
9144
Adam Langley09505632015-07-30 18:10:13 -07009145 // The custom extension add callback should not be called if the client
9146 // doesn't send the extension.
9147 testCases = append(testCases, testCase{
9148 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009149 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009151 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009152 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009153 ExpectedCustomExtension: &emptyString,
9154 },
9155 },
9156 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9157 })
Adam Langley2deb9842015-08-07 11:15:37 -07009158
Steven Valdez143e8b32016-07-11 13:19:03 -04009159 testCases = append(testCases, testCase{
9160 testType: serverTest,
9161 name: "CustomExtensions-NotCalled-Server-TLS13",
9162 config: Config{
9163 MaxVersion: VersionTLS13,
9164 Bugs: ProtocolBugs{
9165 ExpectedCustomExtension: &emptyString,
9166 },
9167 },
9168 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9169 })
9170
Adam Langley2deb9842015-08-07 11:15:37 -07009171 // Test an unknown extension from the server.
9172 testCases = append(testCases, testCase{
9173 testType: clientTest,
9174 name: "UnknownExtension-Client",
9175 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009176 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009177 Bugs: ProtocolBugs{
9178 CustomExtension: expectedContents,
9179 },
9180 },
David Benjamin0c40a962016-08-01 12:05:50 -04009181 shouldFail: true,
9182 expectedError: ":UNEXPECTED_EXTENSION:",
9183 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009184 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009185 testCases = append(testCases, testCase{
9186 testType: clientTest,
9187 name: "UnknownExtension-Client-TLS13",
9188 config: Config{
9189 MaxVersion: VersionTLS13,
9190 Bugs: ProtocolBugs{
9191 CustomExtension: expectedContents,
9192 },
9193 },
David Benjamin0c40a962016-08-01 12:05:50 -04009194 shouldFail: true,
9195 expectedError: ":UNEXPECTED_EXTENSION:",
9196 expectedLocalError: "remote error: unsupported extension",
9197 })
David Benjamin490469f2016-10-05 22:44:38 -04009198 testCases = append(testCases, testCase{
9199 testType: clientTest,
9200 name: "UnknownUnencryptedExtension-Client-TLS13",
9201 config: Config{
9202 MaxVersion: VersionTLS13,
9203 Bugs: ProtocolBugs{
9204 CustomUnencryptedExtension: expectedContents,
9205 },
9206 },
9207 shouldFail: true,
9208 expectedError: ":UNEXPECTED_EXTENSION:",
9209 // The shim must send an alert, but alerts at this point do not
9210 // get successfully decrypted by the runner.
9211 expectedLocalError: "local error: bad record MAC",
9212 })
9213 testCases = append(testCases, testCase{
9214 testType: clientTest,
9215 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9216 config: Config{
9217 MaxVersion: VersionTLS13,
9218 Bugs: ProtocolBugs{
9219 SendUnencryptedALPN: "foo",
9220 },
9221 },
9222 flags: []string{
9223 "-advertise-alpn", "\x03foo\x03bar",
9224 },
9225 shouldFail: true,
9226 expectedError: ":UNEXPECTED_EXTENSION:",
9227 // The shim must send an alert, but alerts at this point do not
9228 // get successfully decrypted by the runner.
9229 expectedLocalError: "local error: bad record MAC",
9230 })
David Benjamin0c40a962016-08-01 12:05:50 -04009231
9232 // Test a known but unoffered extension from the server.
9233 testCases = append(testCases, testCase{
9234 testType: clientTest,
9235 name: "UnofferedExtension-Client",
9236 config: Config{
9237 MaxVersion: VersionTLS12,
9238 Bugs: ProtocolBugs{
9239 SendALPN: "alpn",
9240 },
9241 },
9242 shouldFail: true,
9243 expectedError: ":UNEXPECTED_EXTENSION:",
9244 expectedLocalError: "remote error: unsupported extension",
9245 })
9246 testCases = append(testCases, testCase{
9247 testType: clientTest,
9248 name: "UnofferedExtension-Client-TLS13",
9249 config: Config{
9250 MaxVersion: VersionTLS13,
9251 Bugs: ProtocolBugs{
9252 SendALPN: "alpn",
9253 },
9254 },
9255 shouldFail: true,
9256 expectedError: ":UNEXPECTED_EXTENSION:",
9257 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009258 })
Adam Langley09505632015-07-30 18:10:13 -07009259}
9260
David Benjaminb36a3952015-12-01 18:53:13 -05009261func addRSAClientKeyExchangeTests() {
9262 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9263 testCases = append(testCases, testCase{
9264 testType: serverTest,
9265 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9266 config: Config{
9267 // Ensure the ClientHello version and final
9268 // version are different, to detect if the
9269 // server uses the wrong one.
9270 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009271 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009272 Bugs: ProtocolBugs{
9273 BadRSAClientKeyExchange: bad,
9274 },
9275 },
9276 shouldFail: true,
9277 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9278 })
9279 }
David Benjamine63d9d72016-09-19 18:27:34 -04009280
9281 // The server must compare whatever was in ClientHello.version for the
9282 // RSA premaster.
9283 testCases = append(testCases, testCase{
9284 testType: serverTest,
9285 name: "SendClientVersion-RSA",
9286 config: Config{
9287 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9288 Bugs: ProtocolBugs{
9289 SendClientVersion: 0x1234,
9290 },
9291 },
9292 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9293 })
David Benjaminb36a3952015-12-01 18:53:13 -05009294}
9295
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009296var testCurves = []struct {
9297 name string
9298 id CurveID
9299}{
Adam Langley764ab982017-03-10 18:01:30 -08009300 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009301 {"P-256", CurveP256},
9302 {"P-384", CurveP384},
9303 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009304 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009305}
9306
Steven Valdez5440fe02016-07-18 12:40:30 -04009307const bogusCurve = 0x1234
9308
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009309func addCurveTests() {
9310 for _, curve := range testCurves {
9311 testCases = append(testCases, testCase{
9312 name: "CurveTest-Client-" + curve.name,
9313 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009314 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009315 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9316 CurvePreferences: []CurveID{curve.id},
9317 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009318 flags: []string{
9319 "-enable-all-curves",
9320 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9321 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009322 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009323 })
9324 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009325 name: "CurveTest-Client-" + curve.name + "-TLS13",
9326 config: Config{
9327 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009328 CurvePreferences: []CurveID{curve.id},
9329 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009330 flags: []string{
9331 "-enable-all-curves",
9332 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9333 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009334 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009335 })
9336 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009337 testType: serverTest,
9338 name: "CurveTest-Server-" + curve.name,
9339 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009340 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9342 CurvePreferences: []CurveID{curve.id},
9343 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009344 flags: []string{
9345 "-enable-all-curves",
9346 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9347 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009348 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009349 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009350 testCases = append(testCases, testCase{
9351 testType: serverTest,
9352 name: "CurveTest-Server-" + curve.name + "-TLS13",
9353 config: Config{
9354 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009355 CurvePreferences: []CurveID{curve.id},
9356 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009357 flags: []string{
9358 "-enable-all-curves",
9359 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9360 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009361 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009362 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009363 }
David Benjamin241ae832016-01-15 03:04:54 -05009364
9365 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009366 testCases = append(testCases, testCase{
9367 testType: serverTest,
9368 name: "UnknownCurve",
9369 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009370 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009371 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9372 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9373 },
9374 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009375
Steven Valdez803c77a2016-09-06 14:13:43 -04009376 // The server must be tolerant to bogus curves.
9377 testCases = append(testCases, testCase{
9378 testType: serverTest,
9379 name: "UnknownCurve-TLS13",
9380 config: Config{
9381 MaxVersion: VersionTLS13,
9382 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9383 },
9384 })
9385
David Benjamin4c3ddf72016-06-29 18:13:53 -04009386 // The server must not consider ECDHE ciphers when there are no
9387 // supported curves.
9388 testCases = append(testCases, testCase{
9389 testType: serverTest,
9390 name: "NoSupportedCurves",
9391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009392 MaxVersion: VersionTLS12,
9393 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9394 Bugs: ProtocolBugs{
9395 NoSupportedCurves: true,
9396 },
9397 },
9398 shouldFail: true,
9399 expectedError: ":NO_SHARED_CIPHER:",
9400 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009401 testCases = append(testCases, testCase{
9402 testType: serverTest,
9403 name: "NoSupportedCurves-TLS13",
9404 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009405 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009406 Bugs: ProtocolBugs{
9407 NoSupportedCurves: true,
9408 },
9409 },
9410 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009411 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009412 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009413
9414 // The server must fall back to another cipher when there are no
9415 // supported curves.
9416 testCases = append(testCases, testCase{
9417 testType: serverTest,
9418 name: "NoCommonCurves",
9419 config: Config{
9420 MaxVersion: VersionTLS12,
9421 CipherSuites: []uint16{
9422 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009423 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009424 },
9425 CurvePreferences: []CurveID{CurveP224},
9426 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009427 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009428 })
9429
9430 // The client must reject bogus curves and disabled curves.
9431 testCases = append(testCases, testCase{
9432 name: "BadECDHECurve",
9433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009434 MaxVersion: VersionTLS12,
9435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9436 Bugs: ProtocolBugs{
9437 SendCurve: bogusCurve,
9438 },
9439 },
9440 shouldFail: true,
9441 expectedError: ":WRONG_CURVE:",
9442 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009443 testCases = append(testCases, testCase{
9444 name: "BadECDHECurve-TLS13",
9445 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009446 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009447 Bugs: ProtocolBugs{
9448 SendCurve: bogusCurve,
9449 },
9450 },
9451 shouldFail: true,
9452 expectedError: ":WRONG_CURVE:",
9453 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009454
9455 testCases = append(testCases, testCase{
9456 name: "UnsupportedCurve",
9457 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009458 MaxVersion: VersionTLS12,
9459 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9460 CurvePreferences: []CurveID{CurveP256},
9461 Bugs: ProtocolBugs{
9462 IgnorePeerCurvePreferences: true,
9463 },
9464 },
9465 flags: []string{"-p384-only"},
9466 shouldFail: true,
9467 expectedError: ":WRONG_CURVE:",
9468 })
9469
David Benjamin4f921572016-07-17 14:20:10 +02009470 testCases = append(testCases, testCase{
9471 // TODO(davidben): Add a TLS 1.3 version where
9472 // HelloRetryRequest requests an unsupported curve.
9473 name: "UnsupportedCurve-ServerHello-TLS13",
9474 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009475 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009476 CurvePreferences: []CurveID{CurveP384},
9477 Bugs: ProtocolBugs{
9478 SendCurve: CurveP256,
9479 },
9480 },
9481 flags: []string{"-p384-only"},
9482 shouldFail: true,
9483 expectedError: ":WRONG_CURVE:",
9484 })
9485
David Benjamin4c3ddf72016-06-29 18:13:53 -04009486 // Test invalid curve points.
9487 testCases = append(testCases, testCase{
9488 name: "InvalidECDHPoint-Client",
9489 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009490 MaxVersion: VersionTLS12,
9491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9492 CurvePreferences: []CurveID{CurveP256},
9493 Bugs: ProtocolBugs{
9494 InvalidECDHPoint: true,
9495 },
9496 },
9497 shouldFail: true,
9498 expectedError: ":INVALID_ENCODING:",
9499 })
9500 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009501 name: "InvalidECDHPoint-Client-TLS13",
9502 config: Config{
9503 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009504 CurvePreferences: []CurveID{CurveP256},
9505 Bugs: ProtocolBugs{
9506 InvalidECDHPoint: true,
9507 },
9508 },
9509 shouldFail: true,
9510 expectedError: ":INVALID_ENCODING:",
9511 })
9512 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009513 testType: serverTest,
9514 name: "InvalidECDHPoint-Server",
9515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009516 MaxVersion: VersionTLS12,
9517 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9518 CurvePreferences: []CurveID{CurveP256},
9519 Bugs: ProtocolBugs{
9520 InvalidECDHPoint: true,
9521 },
9522 },
9523 shouldFail: true,
9524 expectedError: ":INVALID_ENCODING:",
9525 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009526 testCases = append(testCases, testCase{
9527 testType: serverTest,
9528 name: "InvalidECDHPoint-Server-TLS13",
9529 config: Config{
9530 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009531 CurvePreferences: []CurveID{CurveP256},
9532 Bugs: ProtocolBugs{
9533 InvalidECDHPoint: true,
9534 },
9535 },
9536 shouldFail: true,
9537 expectedError: ":INVALID_ENCODING:",
9538 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009539
9540 // The previous curve ID should be reported on TLS 1.2 resumption.
9541 testCases = append(testCases, testCase{
9542 name: "CurveID-Resume-Client",
9543 config: Config{
9544 MaxVersion: VersionTLS12,
9545 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9546 CurvePreferences: []CurveID{CurveX25519},
9547 },
9548 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9549 resumeSession: true,
9550 })
9551 testCases = append(testCases, testCase{
9552 testType: serverTest,
9553 name: "CurveID-Resume-Server",
9554 config: Config{
9555 MaxVersion: VersionTLS12,
9556 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9557 CurvePreferences: []CurveID{CurveX25519},
9558 },
9559 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9560 resumeSession: true,
9561 })
9562
9563 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9564 // one should be reported.
9565 testCases = append(testCases, testCase{
9566 name: "CurveID-Resume-Client-TLS13",
9567 config: Config{
9568 MaxVersion: VersionTLS13,
9569 CurvePreferences: []CurveID{CurveX25519},
9570 },
9571 resumeConfig: &Config{
9572 MaxVersion: VersionTLS13,
9573 CurvePreferences: []CurveID{CurveP256},
9574 },
9575 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009576 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9577 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009578 },
9579 resumeSession: true,
9580 })
9581 testCases = append(testCases, testCase{
9582 testType: serverTest,
9583 name: "CurveID-Resume-Server-TLS13",
9584 config: Config{
9585 MaxVersion: VersionTLS13,
9586 CurvePreferences: []CurveID{CurveX25519},
9587 },
9588 resumeConfig: &Config{
9589 MaxVersion: VersionTLS13,
9590 CurvePreferences: []CurveID{CurveP256},
9591 },
9592 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009593 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9594 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009595 },
9596 resumeSession: true,
9597 })
David Benjamina81967b2016-12-22 09:16:57 -05009598
9599 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9600 testCases = append(testCases, testCase{
9601 name: "PointFormat-ServerHello-TLS12",
9602 config: Config{
9603 MaxVersion: VersionTLS12,
9604 Bugs: ProtocolBugs{
9605 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9606 },
9607 },
9608 })
9609 testCases = append(testCases, testCase{
9610 name: "PointFormat-EncryptedExtensions-TLS13",
9611 config: Config{
9612 MaxVersion: VersionTLS13,
9613 Bugs: ProtocolBugs{
9614 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9615 },
9616 },
9617 shouldFail: true,
9618 expectedError: ":ERROR_PARSING_EXTENSION:",
9619 })
9620
David Benjamin6c1f2b72017-10-04 17:01:22 -04009621 // Server-sent supported groups/curves are legal in TLS 1.3. They are
9622 // illegal in TLS 1.2, but some servers send them anyway, so we must
9623 // tolerate them.
9624 testCases = append(testCases, testCase{
9625 name: "SupportedCurves-ServerHello-TLS12",
9626 config: Config{
9627 MaxVersion: VersionTLS12,
9628 Bugs: ProtocolBugs{
9629 SendServerSupportedCurves: true,
9630 },
9631 },
9632 })
9633 testCases = append(testCases, testCase{
9634 name: "SupportedCurves-EncryptedExtensions-TLS13",
9635 config: Config{
9636 MaxVersion: VersionTLS13,
9637 Bugs: ProtocolBugs{
9638 SendServerSupportedCurves: true,
9639 },
9640 },
9641 })
9642
David Benjamina81967b2016-12-22 09:16:57 -05009643 // Test that we tolerate unknown point formats, as long as
9644 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9645 // check they are still functional.
9646 testCases = append(testCases, testCase{
9647 name: "PointFormat-Client-Tolerance",
9648 config: Config{
9649 MaxVersion: VersionTLS12,
9650 Bugs: ProtocolBugs{
9651 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9652 },
9653 },
9654 })
9655 testCases = append(testCases, testCase{
9656 testType: serverTest,
9657 name: "PointFormat-Server-Tolerance",
9658 config: Config{
9659 MaxVersion: VersionTLS12,
9660 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9661 Bugs: ProtocolBugs{
9662 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9663 },
9664 },
9665 })
9666
9667 // Test TLS 1.2 does not require the point format extension to be
9668 // present.
9669 testCases = append(testCases, testCase{
9670 name: "PointFormat-Client-Missing",
9671 config: Config{
9672 MaxVersion: VersionTLS12,
9673 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9674 Bugs: ProtocolBugs{
9675 SendSupportedPointFormats: []byte{},
9676 },
9677 },
9678 })
9679 testCases = append(testCases, testCase{
9680 testType: serverTest,
9681 name: "PointFormat-Server-Missing",
9682 config: Config{
9683 MaxVersion: VersionTLS12,
9684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9685 Bugs: ProtocolBugs{
9686 SendSupportedPointFormats: []byte{},
9687 },
9688 },
9689 })
9690
9691 // If the point format extension is present, uncompressed points must be
9692 // offered. BoringSSL requires this whether or not ECDHE is used.
9693 testCases = append(testCases, testCase{
9694 name: "PointFormat-Client-MissingUncompressed",
9695 config: Config{
9696 MaxVersion: VersionTLS12,
9697 Bugs: ProtocolBugs{
9698 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9699 },
9700 },
9701 shouldFail: true,
9702 expectedError: ":ERROR_PARSING_EXTENSION:",
9703 })
9704 testCases = append(testCases, testCase{
9705 testType: serverTest,
9706 name: "PointFormat-Server-MissingUncompressed",
9707 config: Config{
9708 MaxVersion: VersionTLS12,
9709 Bugs: ProtocolBugs{
9710 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9711 },
9712 },
9713 shouldFail: true,
9714 expectedError: ":ERROR_PARSING_EXTENSION:",
9715 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009716}
9717
David Benjaminc9ae27c2016-06-24 22:56:37 -04009718func addTLS13RecordTests() {
9719 testCases = append(testCases, testCase{
9720 name: "TLS13-RecordPadding",
9721 config: Config{
9722 MaxVersion: VersionTLS13,
9723 MinVersion: VersionTLS13,
9724 Bugs: ProtocolBugs{
9725 RecordPadding: 10,
9726 },
9727 },
9728 })
9729
9730 testCases = append(testCases, testCase{
9731 name: "TLS13-EmptyRecords",
9732 config: Config{
9733 MaxVersion: VersionTLS13,
9734 MinVersion: VersionTLS13,
9735 Bugs: ProtocolBugs{
9736 OmitRecordContents: true,
9737 },
9738 },
9739 shouldFail: true,
9740 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9741 })
9742
9743 testCases = append(testCases, testCase{
9744 name: "TLS13-OnlyPadding",
9745 config: Config{
9746 MaxVersion: VersionTLS13,
9747 MinVersion: VersionTLS13,
9748 Bugs: ProtocolBugs{
9749 OmitRecordContents: true,
9750 RecordPadding: 10,
9751 },
9752 },
9753 shouldFail: true,
9754 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9755 })
9756
9757 testCases = append(testCases, testCase{
9758 name: "TLS13-WrongOuterRecord",
9759 config: Config{
9760 MaxVersion: VersionTLS13,
9761 MinVersion: VersionTLS13,
9762 Bugs: ProtocolBugs{
9763 OuterRecordType: recordTypeHandshake,
9764 },
9765 },
9766 shouldFail: true,
9767 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9768 })
9769}
9770
Steven Valdez5b986082016-09-01 12:29:49 -04009771func addSessionTicketTests() {
9772 testCases = append(testCases, testCase{
9773 // In TLS 1.2 and below, empty NewSessionTicket messages
9774 // mean the server changed its mind on sending a ticket.
9775 name: "SendEmptySessionTicket",
9776 config: Config{
9777 MaxVersion: VersionTLS12,
9778 Bugs: ProtocolBugs{
9779 SendEmptySessionTicket: true,
9780 },
9781 },
9782 flags: []string{"-expect-no-session"},
9783 })
9784
9785 // Test that the server ignores unknown PSK modes.
9786 testCases = append(testCases, testCase{
9787 testType: serverTest,
9788 name: "TLS13-SendUnknownModeSessionTicket-Server",
9789 config: Config{
9790 MaxVersion: VersionTLS13,
9791 Bugs: ProtocolBugs{
9792 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009793 },
9794 },
9795 resumeSession: true,
9796 expectedResumeVersion: VersionTLS13,
9797 })
9798
Steven Valdeza833c352016-11-01 13:39:36 -04009799 // Test that the server does not send session tickets with no matching key exchange mode.
9800 testCases = append(testCases, testCase{
9801 testType: serverTest,
9802 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9803 config: Config{
9804 MaxVersion: VersionTLS13,
9805 Bugs: ProtocolBugs{
9806 SendPSKKeyExchangeModes: []byte{0x1a},
9807 ExpectNoNewSessionTicket: true,
9808 },
9809 },
9810 })
9811
9812 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009813 testCases = append(testCases, testCase{
9814 testType: serverTest,
9815 name: "TLS13-SendBadKEModeSessionTicket-Server",
9816 config: Config{
9817 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009818 },
9819 resumeConfig: &Config{
9820 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009821 Bugs: ProtocolBugs{
9822 SendPSKKeyExchangeModes: []byte{0x1a},
9823 },
9824 },
9825 resumeSession: true,
9826 expectResumeRejected: true,
9827 })
9828
Steven Valdeza833c352016-11-01 13:39:36 -04009829 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009830 testCases = append(testCases, testCase{
9831 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009832 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009833 config: Config{
9834 MaxVersion: VersionTLS13,
9835 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009836 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009837 },
9838 },
Steven Valdeza833c352016-11-01 13:39:36 -04009839 resumeSession: true,
9840 flags: []string{
9841 "-resumption-delay", "10",
9842 },
Steven Valdez5b986082016-09-01 12:29:49 -04009843 })
9844
Steven Valdeza833c352016-11-01 13:39:36 -04009845 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009846 testCases = append(testCases, testCase{
9847 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009848 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009849 config: Config{
9850 MaxVersion: VersionTLS13,
9851 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009852 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009853 },
9854 },
Steven Valdeza833c352016-11-01 13:39:36 -04009855 resumeSession: true,
9856 shouldFail: true,
9857 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009858 })
9859
David Benjamin35ac5b72017-03-03 15:05:56 -05009860 // Test that the server's ticket age skew reporting works.
9861 testCases = append(testCases, testCase{
9862 testType: serverTest,
9863 name: "TLS13-TicketAgeSkew-Forward",
9864 config: Config{
9865 MaxVersion: VersionTLS13,
9866 Bugs: ProtocolBugs{
9867 SendTicketAge: 15 * time.Second,
9868 },
9869 },
David Benjamin065d7332017-03-26 10:51:43 -05009870 resumeSession: true,
9871 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009872 flags: []string{
9873 "-resumption-delay", "10",
9874 "-expect-ticket-age-skew", "5",
9875 },
9876 })
9877 testCases = append(testCases, testCase{
9878 testType: serverTest,
9879 name: "TLS13-TicketAgeSkew-Backward",
9880 config: Config{
9881 MaxVersion: VersionTLS13,
9882 Bugs: ProtocolBugs{
9883 SendTicketAge: 5 * time.Second,
9884 },
9885 },
David Benjamin065d7332017-03-26 10:51:43 -05009886 resumeSession: true,
9887 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009888 flags: []string{
9889 "-resumption-delay", "10",
9890 "-expect-ticket-age-skew", "-5",
9891 },
9892 })
9893
Steven Valdez08b65f42016-12-07 15:29:45 -05009894 testCases = append(testCases, testCase{
9895 testType: clientTest,
9896 name: "TLS13-SendTicketEarlyDataInfo",
9897 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009898 MaxVersion: VersionTLS13,
9899 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009900 },
9901 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009902 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009903 "-expect-early-data-info",
9904 },
9905 })
9906
David Benjamin9b160662017-01-25 19:53:43 -05009907 // Test that 0-RTT tickets are ignored in clients unless opted in.
9908 testCases = append(testCases, testCase{
9909 testType: clientTest,
9910 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9911 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009912 MaxVersion: VersionTLS13,
9913 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009914 },
9915 })
9916
Steven Valdez08b65f42016-12-07 15:29:45 -05009917 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009918 testType: clientTest,
9919 name: "TLS13-DuplicateTicketEarlyDataInfo",
9920 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009921 MaxVersion: VersionTLS13,
9922 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009923 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009924 DuplicateTicketEarlyDataInfo: true,
9925 },
9926 },
9927 shouldFail: true,
9928 expectedError: ":DUPLICATE_EXTENSION:",
9929 expectedLocalError: "remote error: illegal parameter",
9930 })
9931
9932 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009933 testType: serverTest,
9934 name: "TLS13-ExpectTicketEarlyDataInfo",
9935 config: Config{
9936 MaxVersion: VersionTLS13,
9937 Bugs: ProtocolBugs{
9938 ExpectTicketEarlyDataInfo: true,
9939 },
9940 },
9941 flags: []string{
9942 "-enable-early-data",
9943 },
9944 })
David Benjamin17b30832017-01-28 14:00:32 -05009945
9946 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9947 // is honored.
9948 testCases = append(testCases, testCase{
9949 testType: clientTest,
9950 name: "TLS13-HonorServerSessionTicketLifetime",
9951 config: Config{
9952 MaxVersion: VersionTLS13,
9953 Bugs: ProtocolBugs{
9954 SendTicketLifetime: 20 * time.Second,
9955 },
9956 },
9957 flags: []string{
9958 "-resumption-delay", "19",
9959 },
9960 resumeSession: true,
9961 })
9962 testCases = append(testCases, testCase{
9963 testType: clientTest,
9964 name: "TLS13-HonorServerSessionTicketLifetime-2",
9965 config: Config{
9966 MaxVersion: VersionTLS13,
9967 Bugs: ProtocolBugs{
9968 SendTicketLifetime: 20 * time.Second,
9969 // The client should not offer the expired session.
9970 ExpectNoTLS13PSK: true,
9971 },
9972 },
9973 flags: []string{
9974 "-resumption-delay", "21",
9975 },
David Benjamin023d4192017-02-06 13:49:07 -05009976 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009977 expectResumeRejected: true,
9978 })
Steven Valdez5b986082016-09-01 12:29:49 -04009979}
9980
David Benjamin82261be2016-07-07 14:32:50 -07009981func addChangeCipherSpecTests() {
9982 // Test missing ChangeCipherSpecs.
9983 testCases = append(testCases, testCase{
9984 name: "SkipChangeCipherSpec-Client",
9985 config: Config{
9986 MaxVersion: VersionTLS12,
9987 Bugs: ProtocolBugs{
9988 SkipChangeCipherSpec: true,
9989 },
9990 },
9991 shouldFail: true,
9992 expectedError: ":UNEXPECTED_RECORD:",
9993 })
9994 testCases = append(testCases, testCase{
9995 testType: serverTest,
9996 name: "SkipChangeCipherSpec-Server",
9997 config: Config{
9998 MaxVersion: VersionTLS12,
9999 Bugs: ProtocolBugs{
10000 SkipChangeCipherSpec: true,
10001 },
10002 },
10003 shouldFail: true,
10004 expectedError: ":UNEXPECTED_RECORD:",
10005 })
10006 testCases = append(testCases, testCase{
10007 testType: serverTest,
10008 name: "SkipChangeCipherSpec-Server-NPN",
10009 config: Config{
10010 MaxVersion: VersionTLS12,
10011 NextProtos: []string{"bar"},
10012 Bugs: ProtocolBugs{
10013 SkipChangeCipherSpec: true,
10014 },
10015 },
10016 flags: []string{
10017 "-advertise-npn", "\x03foo\x03bar\x03baz",
10018 },
10019 shouldFail: true,
10020 expectedError: ":UNEXPECTED_RECORD:",
10021 })
10022
10023 // Test synchronization between the handshake and ChangeCipherSpec.
10024 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10025 // rejected. Test both with and without handshake packing to handle both
10026 // when the partial post-CCS message is in its own record and when it is
10027 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010028 for _, packed := range []bool{false, true} {
10029 var suffix string
10030 if packed {
10031 suffix = "-Packed"
10032 }
10033
10034 testCases = append(testCases, testCase{
10035 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10036 config: Config{
10037 MaxVersion: VersionTLS12,
10038 Bugs: ProtocolBugs{
10039 FragmentAcrossChangeCipherSpec: true,
10040 PackHandshakeFlight: packed,
10041 },
10042 },
10043 shouldFail: true,
10044 expectedError: ":UNEXPECTED_RECORD:",
10045 })
10046 testCases = append(testCases, testCase{
10047 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10048 config: Config{
10049 MaxVersion: VersionTLS12,
10050 },
10051 resumeSession: true,
10052 resumeConfig: &Config{
10053 MaxVersion: VersionTLS12,
10054 Bugs: ProtocolBugs{
10055 FragmentAcrossChangeCipherSpec: true,
10056 PackHandshakeFlight: packed,
10057 },
10058 },
10059 shouldFail: true,
10060 expectedError: ":UNEXPECTED_RECORD:",
10061 })
10062 testCases = append(testCases, testCase{
10063 testType: serverTest,
10064 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10065 config: Config{
10066 MaxVersion: VersionTLS12,
10067 Bugs: ProtocolBugs{
10068 FragmentAcrossChangeCipherSpec: true,
10069 PackHandshakeFlight: packed,
10070 },
10071 },
10072 shouldFail: true,
10073 expectedError: ":UNEXPECTED_RECORD:",
10074 })
10075 testCases = append(testCases, testCase{
10076 testType: serverTest,
10077 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10078 config: Config{
10079 MaxVersion: VersionTLS12,
10080 },
10081 resumeSession: true,
10082 resumeConfig: &Config{
10083 MaxVersion: VersionTLS12,
10084 Bugs: ProtocolBugs{
10085 FragmentAcrossChangeCipherSpec: true,
10086 PackHandshakeFlight: packed,
10087 },
10088 },
10089 shouldFail: true,
10090 expectedError: ":UNEXPECTED_RECORD:",
10091 })
10092 testCases = append(testCases, testCase{
10093 testType: serverTest,
10094 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10095 config: Config{
10096 MaxVersion: VersionTLS12,
10097 NextProtos: []string{"bar"},
10098 Bugs: ProtocolBugs{
10099 FragmentAcrossChangeCipherSpec: true,
10100 PackHandshakeFlight: packed,
10101 },
10102 },
10103 flags: []string{
10104 "-advertise-npn", "\x03foo\x03bar\x03baz",
10105 },
10106 shouldFail: true,
10107 expectedError: ":UNEXPECTED_RECORD:",
10108 })
10109 }
10110
David Benjamin61672812016-07-14 23:10:43 -040010111 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10112 // messages in the handshake queue. Do this by testing the server
10113 // reading the client Finished, reversing the flight so Finished comes
10114 // first.
10115 testCases = append(testCases, testCase{
10116 protocol: dtls,
10117 testType: serverTest,
10118 name: "SendUnencryptedFinished-DTLS",
10119 config: Config{
10120 MaxVersion: VersionTLS12,
10121 Bugs: ProtocolBugs{
10122 SendUnencryptedFinished: true,
10123 ReverseHandshakeFragments: true,
10124 },
10125 },
10126 shouldFail: true,
10127 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10128 })
10129
Steven Valdez143e8b32016-07-11 13:19:03 -040010130 // Test synchronization between encryption changes and the handshake in
10131 // TLS 1.3, where ChangeCipherSpec is implicit.
10132 testCases = append(testCases, testCase{
10133 name: "PartialEncryptedExtensionsWithServerHello",
10134 config: Config{
10135 MaxVersion: VersionTLS13,
10136 Bugs: ProtocolBugs{
10137 PartialEncryptedExtensionsWithServerHello: true,
10138 },
10139 },
10140 shouldFail: true,
10141 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10142 })
10143 testCases = append(testCases, testCase{
10144 testType: serverTest,
10145 name: "PartialClientFinishedWithClientHello",
10146 config: Config{
10147 MaxVersion: VersionTLS13,
10148 Bugs: ProtocolBugs{
10149 PartialClientFinishedWithClientHello: true,
10150 },
10151 },
10152 shouldFail: true,
10153 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10154 })
10155
David Benjamin82261be2016-07-07 14:32:50 -070010156 // Test that early ChangeCipherSpecs are handled correctly.
10157 testCases = append(testCases, testCase{
10158 testType: serverTest,
10159 name: "EarlyChangeCipherSpec-server-1",
10160 config: Config{
10161 MaxVersion: VersionTLS12,
10162 Bugs: ProtocolBugs{
10163 EarlyChangeCipherSpec: 1,
10164 },
10165 },
10166 shouldFail: true,
10167 expectedError: ":UNEXPECTED_RECORD:",
10168 })
10169 testCases = append(testCases, testCase{
10170 testType: serverTest,
10171 name: "EarlyChangeCipherSpec-server-2",
10172 config: Config{
10173 MaxVersion: VersionTLS12,
10174 Bugs: ProtocolBugs{
10175 EarlyChangeCipherSpec: 2,
10176 },
10177 },
10178 shouldFail: true,
10179 expectedError: ":UNEXPECTED_RECORD:",
10180 })
10181 testCases = append(testCases, testCase{
10182 protocol: dtls,
10183 name: "StrayChangeCipherSpec",
10184 config: Config{
10185 // TODO(davidben): Once DTLS 1.3 exists, test
10186 // that stray ChangeCipherSpec messages are
10187 // rejected.
10188 MaxVersion: VersionTLS12,
10189 Bugs: ProtocolBugs{
10190 StrayChangeCipherSpec: true,
10191 },
10192 },
10193 })
10194
David Benjaminb0c761e2017-06-25 22:42:55 -040010195 // Test that reordered ChangeCipherSpecs are tolerated.
10196 testCases = append(testCases, testCase{
10197 protocol: dtls,
10198 name: "ReorderChangeCipherSpec-DTLS-Client",
10199 config: Config{
10200 MaxVersion: VersionTLS12,
10201 Bugs: ProtocolBugs{
10202 ReorderChangeCipherSpec: true,
10203 },
10204 },
10205 resumeSession: true,
10206 })
10207 testCases = append(testCases, testCase{
10208 testType: serverTest,
10209 protocol: dtls,
10210 name: "ReorderChangeCipherSpec-DTLS-Server",
10211 config: Config{
10212 MaxVersion: VersionTLS12,
10213 Bugs: ProtocolBugs{
10214 ReorderChangeCipherSpec: true,
10215 },
10216 },
10217 resumeSession: true,
10218 })
10219
David Benjamin82261be2016-07-07 14:32:50 -070010220 // Test that the contents of ChangeCipherSpec are checked.
10221 testCases = append(testCases, testCase{
10222 name: "BadChangeCipherSpec-1",
10223 config: Config{
10224 MaxVersion: VersionTLS12,
10225 Bugs: ProtocolBugs{
10226 BadChangeCipherSpec: []byte{2},
10227 },
10228 },
10229 shouldFail: true,
10230 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10231 })
10232 testCases = append(testCases, testCase{
10233 name: "BadChangeCipherSpec-2",
10234 config: Config{
10235 MaxVersion: VersionTLS12,
10236 Bugs: ProtocolBugs{
10237 BadChangeCipherSpec: []byte{1, 1},
10238 },
10239 },
10240 shouldFail: true,
10241 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10242 })
10243 testCases = append(testCases, testCase{
10244 protocol: dtls,
10245 name: "BadChangeCipherSpec-DTLS-1",
10246 config: Config{
10247 MaxVersion: VersionTLS12,
10248 Bugs: ProtocolBugs{
10249 BadChangeCipherSpec: []byte{2},
10250 },
10251 },
10252 shouldFail: true,
10253 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10254 })
10255 testCases = append(testCases, testCase{
10256 protocol: dtls,
10257 name: "BadChangeCipherSpec-DTLS-2",
10258 config: Config{
10259 MaxVersion: VersionTLS12,
10260 Bugs: ProtocolBugs{
10261 BadChangeCipherSpec: []byte{1, 1},
10262 },
10263 },
10264 shouldFail: true,
10265 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10266 })
10267}
10268
David Benjamincd2c8062016-09-09 11:28:16 -040010269type perMessageTest struct {
10270 messageType uint8
10271 test testCase
10272}
10273
10274// makePerMessageTests returns a series of test templates which cover each
10275// message in the TLS handshake. These may be used with bugs like
10276// WrongMessageType to fully test a per-message bug.
10277func makePerMessageTests() []perMessageTest {
10278 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010279 for _, protocol := range []protocol{tls, dtls} {
10280 var suffix string
10281 if protocol == dtls {
10282 suffix = "-DTLS"
10283 }
10284
David Benjamincd2c8062016-09-09 11:28:16 -040010285 ret = append(ret, perMessageTest{
10286 messageType: typeClientHello,
10287 test: testCase{
10288 protocol: protocol,
10289 testType: serverTest,
10290 name: "ClientHello" + suffix,
10291 config: Config{
10292 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010293 },
10294 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010295 })
10296
10297 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010298 ret = append(ret, perMessageTest{
10299 messageType: typeHelloVerifyRequest,
10300 test: testCase{
10301 protocol: protocol,
10302 name: "HelloVerifyRequest" + suffix,
10303 config: Config{
10304 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010305 },
10306 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010307 })
10308 }
10309
David Benjamincd2c8062016-09-09 11:28:16 -040010310 ret = append(ret, perMessageTest{
10311 messageType: typeServerHello,
10312 test: testCase{
10313 protocol: protocol,
10314 name: "ServerHello" + suffix,
10315 config: Config{
10316 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010317 },
10318 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010319 })
10320
David Benjamincd2c8062016-09-09 11:28:16 -040010321 ret = append(ret, perMessageTest{
10322 messageType: typeCertificate,
10323 test: testCase{
10324 protocol: protocol,
10325 name: "ServerCertificate" + suffix,
10326 config: Config{
10327 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010328 },
10329 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010330 })
10331
David Benjamincd2c8062016-09-09 11:28:16 -040010332 ret = append(ret, perMessageTest{
10333 messageType: typeCertificateStatus,
10334 test: testCase{
10335 protocol: protocol,
10336 name: "CertificateStatus" + suffix,
10337 config: Config{
10338 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010339 },
David Benjamincd2c8062016-09-09 11:28:16 -040010340 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010341 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010342 })
10343
David Benjamincd2c8062016-09-09 11:28:16 -040010344 ret = append(ret, perMessageTest{
10345 messageType: typeServerKeyExchange,
10346 test: testCase{
10347 protocol: protocol,
10348 name: "ServerKeyExchange" + suffix,
10349 config: Config{
10350 MaxVersion: VersionTLS12,
10351 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010352 },
10353 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010354 })
10355
David Benjamincd2c8062016-09-09 11:28:16 -040010356 ret = append(ret, perMessageTest{
10357 messageType: typeCertificateRequest,
10358 test: testCase{
10359 protocol: protocol,
10360 name: "CertificateRequest" + suffix,
10361 config: Config{
10362 MaxVersion: VersionTLS12,
10363 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010364 },
10365 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010366 })
10367
David Benjamincd2c8062016-09-09 11:28:16 -040010368 ret = append(ret, perMessageTest{
10369 messageType: typeServerHelloDone,
10370 test: testCase{
10371 protocol: protocol,
10372 name: "ServerHelloDone" + suffix,
10373 config: Config{
10374 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010375 },
10376 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010377 })
10378
David Benjamincd2c8062016-09-09 11:28:16 -040010379 ret = append(ret, perMessageTest{
10380 messageType: typeCertificate,
10381 test: testCase{
10382 testType: serverTest,
10383 protocol: protocol,
10384 name: "ClientCertificate" + suffix,
10385 config: Config{
10386 Certificates: []Certificate{rsaCertificate},
10387 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010388 },
David Benjamincd2c8062016-09-09 11:28:16 -040010389 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010390 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010391 })
10392
David Benjamincd2c8062016-09-09 11:28:16 -040010393 ret = append(ret, perMessageTest{
10394 messageType: typeCertificateVerify,
10395 test: testCase{
10396 testType: serverTest,
10397 protocol: protocol,
10398 name: "CertificateVerify" + suffix,
10399 config: Config{
10400 Certificates: []Certificate{rsaCertificate},
10401 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010402 },
David Benjamincd2c8062016-09-09 11:28:16 -040010403 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010404 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010405 })
10406
David Benjamincd2c8062016-09-09 11:28:16 -040010407 ret = append(ret, perMessageTest{
10408 messageType: typeClientKeyExchange,
10409 test: testCase{
10410 testType: serverTest,
10411 protocol: protocol,
10412 name: "ClientKeyExchange" + suffix,
10413 config: Config{
10414 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010415 },
10416 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010417 })
10418
10419 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010420 ret = append(ret, perMessageTest{
10421 messageType: typeNextProtocol,
10422 test: testCase{
10423 testType: serverTest,
10424 protocol: protocol,
10425 name: "NextProtocol" + suffix,
10426 config: Config{
10427 MaxVersion: VersionTLS12,
10428 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010429 },
David Benjamincd2c8062016-09-09 11:28:16 -040010430 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010431 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010432 })
10433
David Benjamincd2c8062016-09-09 11:28:16 -040010434 ret = append(ret, perMessageTest{
10435 messageType: typeChannelID,
10436 test: testCase{
10437 testType: serverTest,
10438 protocol: protocol,
10439 name: "ChannelID" + suffix,
10440 config: Config{
10441 MaxVersion: VersionTLS12,
10442 ChannelID: channelIDKey,
10443 },
10444 flags: []string{
10445 "-expect-channel-id",
10446 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010447 },
10448 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010449 })
10450 }
10451
David Benjamincd2c8062016-09-09 11:28:16 -040010452 ret = append(ret, perMessageTest{
10453 messageType: typeFinished,
10454 test: testCase{
10455 testType: serverTest,
10456 protocol: protocol,
10457 name: "ClientFinished" + suffix,
10458 config: Config{
10459 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010460 },
10461 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010462 })
10463
David Benjamincd2c8062016-09-09 11:28:16 -040010464 ret = append(ret, perMessageTest{
10465 messageType: typeNewSessionTicket,
10466 test: testCase{
10467 protocol: protocol,
10468 name: "NewSessionTicket" + suffix,
10469 config: Config{
10470 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010471 },
10472 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010473 })
10474
David Benjamincd2c8062016-09-09 11:28:16 -040010475 ret = append(ret, perMessageTest{
10476 messageType: typeFinished,
10477 test: testCase{
10478 protocol: protocol,
10479 name: "ServerFinished" + suffix,
10480 config: Config{
10481 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010482 },
10483 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010484 })
10485
10486 }
David Benjamincd2c8062016-09-09 11:28:16 -040010487
10488 ret = append(ret, perMessageTest{
10489 messageType: typeClientHello,
10490 test: testCase{
10491 testType: serverTest,
10492 name: "TLS13-ClientHello",
10493 config: Config{
10494 MaxVersion: VersionTLS13,
10495 },
10496 },
10497 })
10498
10499 ret = append(ret, perMessageTest{
10500 messageType: typeServerHello,
10501 test: testCase{
10502 name: "TLS13-ServerHello",
10503 config: Config{
10504 MaxVersion: VersionTLS13,
10505 },
10506 },
10507 })
10508
10509 ret = append(ret, perMessageTest{
10510 messageType: typeEncryptedExtensions,
10511 test: testCase{
10512 name: "TLS13-EncryptedExtensions",
10513 config: Config{
10514 MaxVersion: VersionTLS13,
10515 },
10516 },
10517 })
10518
10519 ret = append(ret, perMessageTest{
10520 messageType: typeCertificateRequest,
10521 test: testCase{
10522 name: "TLS13-CertificateRequest",
10523 config: Config{
10524 MaxVersion: VersionTLS13,
10525 ClientAuth: RequireAnyClientCert,
10526 },
10527 },
10528 })
10529
10530 ret = append(ret, perMessageTest{
10531 messageType: typeCertificate,
10532 test: testCase{
10533 name: "TLS13-ServerCertificate",
10534 config: Config{
10535 MaxVersion: VersionTLS13,
10536 },
10537 },
10538 })
10539
10540 ret = append(ret, perMessageTest{
10541 messageType: typeCertificateVerify,
10542 test: testCase{
10543 name: "TLS13-ServerCertificateVerify",
10544 config: Config{
10545 MaxVersion: VersionTLS13,
10546 },
10547 },
10548 })
10549
10550 ret = append(ret, perMessageTest{
10551 messageType: typeFinished,
10552 test: testCase{
10553 name: "TLS13-ServerFinished",
10554 config: Config{
10555 MaxVersion: VersionTLS13,
10556 },
10557 },
10558 })
10559
10560 ret = append(ret, perMessageTest{
10561 messageType: typeCertificate,
10562 test: testCase{
10563 testType: serverTest,
10564 name: "TLS13-ClientCertificate",
10565 config: Config{
10566 Certificates: []Certificate{rsaCertificate},
10567 MaxVersion: VersionTLS13,
10568 },
10569 flags: []string{"-require-any-client-certificate"},
10570 },
10571 })
10572
10573 ret = append(ret, perMessageTest{
10574 messageType: typeCertificateVerify,
10575 test: testCase{
10576 testType: serverTest,
10577 name: "TLS13-ClientCertificateVerify",
10578 config: Config{
10579 Certificates: []Certificate{rsaCertificate},
10580 MaxVersion: VersionTLS13,
10581 },
10582 flags: []string{"-require-any-client-certificate"},
10583 },
10584 })
10585
10586 ret = append(ret, perMessageTest{
10587 messageType: typeFinished,
10588 test: testCase{
10589 testType: serverTest,
10590 name: "TLS13-ClientFinished",
10591 config: Config{
10592 MaxVersion: VersionTLS13,
10593 },
10594 },
10595 })
10596
10597 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010598}
10599
David Benjamincd2c8062016-09-09 11:28:16 -040010600func addWrongMessageTypeTests() {
10601 for _, t := range makePerMessageTests() {
10602 t.test.name = "WrongMessageType-" + t.test.name
10603 t.test.config.Bugs.SendWrongMessageType = t.messageType
10604 t.test.shouldFail = true
10605 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10606 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010607
David Benjamincd2c8062016-09-09 11:28:16 -040010608 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10609 // In TLS 1.3, a bad ServerHello means the client sends
10610 // an unencrypted alert while the server expects
10611 // encryption, so the alert is not readable by runner.
10612 t.test.expectedLocalError = "local error: bad record MAC"
10613 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010614
David Benjamincd2c8062016-09-09 11:28:16 -040010615 testCases = append(testCases, t.test)
10616 }
David Benjaminebacdee2017-04-08 11:00:45 -040010617
10618 // The processing order for TLS 1.3 version negotiation is such that one
10619 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10620 // TLS 1.2. Test that we do not do this.
10621 testCases = append(testCases, testCase{
10622 name: "SendServerHelloAsHelloRetryRequest",
10623 config: Config{
10624 MaxVersion: VersionTLS12,
10625 Bugs: ProtocolBugs{
10626 SendServerHelloAsHelloRetryRequest: true,
10627 },
10628 },
10629 shouldFail: true,
10630 expectedError: ":UNEXPECTED_MESSAGE:",
10631 expectedLocalError: "remote error: unexpected message",
10632 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010633}
10634
David Benjamin639846e2016-09-09 11:41:18 -040010635func addTrailingMessageDataTests() {
10636 for _, t := range makePerMessageTests() {
10637 t.test.name = "TrailingMessageData-" + t.test.name
10638 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10639 t.test.shouldFail = true
10640 t.test.expectedError = ":DECODE_ERROR:"
10641 t.test.expectedLocalError = "remote error: error decoding message"
10642
10643 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10644 // In TLS 1.3, a bad ServerHello means the client sends
10645 // an unencrypted alert while the server expects
10646 // encryption, so the alert is not readable by runner.
10647 t.test.expectedLocalError = "local error: bad record MAC"
10648 }
10649
10650 if t.messageType == typeFinished {
10651 // Bad Finished messages read as the verify data having
10652 // the wrong length.
10653 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10654 t.test.expectedLocalError = "remote error: error decrypting message"
10655 }
10656
10657 testCases = append(testCases, t.test)
10658 }
10659}
10660
Steven Valdez143e8b32016-07-11 13:19:03 -040010661func addTLS13HandshakeTests() {
10662 testCases = append(testCases, testCase{
10663 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010664 name: "NegotiatePSKResumption-TLS13",
10665 config: Config{
10666 MaxVersion: VersionTLS13,
10667 Bugs: ProtocolBugs{
10668 NegotiatePSKResumption: true,
10669 },
10670 },
10671 resumeSession: true,
10672 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010673 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010674 })
10675
10676 testCases = append(testCases, testCase{
10677 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010678 name: "MissingKeyShare-Client",
10679 config: Config{
10680 MaxVersion: VersionTLS13,
10681 Bugs: ProtocolBugs{
10682 MissingKeyShare: true,
10683 },
10684 },
10685 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010686 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010687 })
10688
10689 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010690 testType: serverTest,
10691 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010692 config: Config{
10693 MaxVersion: VersionTLS13,
10694 Bugs: ProtocolBugs{
10695 MissingKeyShare: true,
10696 },
10697 },
10698 shouldFail: true,
10699 expectedError: ":MISSING_KEY_SHARE:",
10700 })
10701
10702 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010703 testType: serverTest,
10704 name: "DuplicateKeyShares",
10705 config: Config{
10706 MaxVersion: VersionTLS13,
10707 Bugs: ProtocolBugs{
10708 DuplicateKeyShares: true,
10709 },
10710 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010711 shouldFail: true,
10712 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010713 })
10714
Steven Valdezc7d4d212017-09-11 13:53:08 -040010715 for _, version := range allVersions(tls) {
10716 if version.version != VersionTLS13 {
10717 continue
10718 }
10719 name := version.name
10720 variant := version.tls13Variant
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010721
Steven Valdezc7d4d212017-09-11 13:53:08 -040010722 testCases = append(testCases, testCase{
10723 testType: serverTest,
10724 name: "SkipEarlyData-" + name,
10725 config: Config{
10726 MaxVersion: VersionTLS13,
10727 Bugs: ProtocolBugs{
10728 SendFakeEarlyDataLength: 4,
10729 },
Steven Valdez520e1222017-06-13 12:45:25 -040010730 },
Steven Valdezc7d4d212017-09-11 13:53:08 -040010731 tls13Variant: variant,
10732 })
Steven Valdez520e1222017-06-13 12:45:25 -040010733
Steven Valdezc7d4d212017-09-11 13:53:08 -040010734 // Test that enabling a TLS 1.3 variant does not interfere with
10735 // TLS 1.2 session ID resumption.
10736 testCases = append(testCases, testCase{
10737 testType: clientTest,
10738 name: "ResumeTLS12SessionID-" + name,
10739 config: Config{
10740 MaxVersion: VersionTLS12,
10741 SessionTicketsDisabled: true,
Steven Valdezdbe01582017-07-14 10:39:28 -040010742 },
Steven Valdezc7d4d212017-09-11 13:53:08 -040010743 tls13Variant: variant,
10744 resumeSession: true,
10745 })
10746
10747 // Test that the server correctly echoes back session IDs of
10748 // various lengths.
10749 testCases = append(testCases, testCase{
10750 testType: serverTest,
10751 name: "EmptySessionID-" + name,
10752 config: Config{
10753 MaxVersion: VersionTLS13,
10754 Bugs: ProtocolBugs{
10755 SendClientHelloSessionID: []byte{},
10756 },
10757 },
10758 tls13Variant: variant,
10759 })
10760
10761 testCases = append(testCases, testCase{
10762 testType: serverTest,
10763 name: "ShortSessionID-" + name,
10764 config: Config{
10765 MaxVersion: VersionTLS13,
10766 Bugs: ProtocolBugs{
10767 SendClientHelloSessionID: make([]byte, 16),
10768 },
10769 },
10770 tls13Variant: variant,
10771 })
10772
10773 testCases = append(testCases, testCase{
10774 testType: serverTest,
10775 name: "FullSessionID-" + name,
10776 config: Config{
10777 MaxVersion: VersionTLS13,
10778 Bugs: ProtocolBugs{
10779 SendClientHelloSessionID: make([]byte, 32),
10780 },
10781 },
10782 tls13Variant: variant,
10783 })
10784
10785 hasSessionID := false
Steven Valdez4c7f5fa2017-10-02 15:53:57 -040010786 if variant != TLS13Default {
Steven Valdezc7d4d212017-09-11 13:53:08 -040010787 hasSessionID = true
10788 }
10789
10790 // Test that the client sends a fake session ID in the correct experiments.
10791 testCases = append(testCases, testCase{
10792 testType: clientTest,
10793 name: "TLS13SessionID-" + name,
10794 config: Config{
10795 MaxVersion: VersionTLS13,
10796 Bugs: ProtocolBugs{
Steven Valdez4c7f5fa2017-10-02 15:53:57 -040010797 ExpectClientHelloSessionID: hasSessionID,
Steven Valdezc7d4d212017-09-11 13:53:08 -040010798 },
10799 },
10800 tls13Variant: variant,
10801 })
10802
10803 testCases = append(testCases, testCase{
10804 testType: clientTest,
10805 name: "EarlyData-Client-" + name,
10806 config: Config{
10807 MaxVersion: VersionTLS13,
10808 MinVersion: VersionTLS13,
10809 MaxEarlyDataSize: 16384,
10810 },
10811 resumeConfig: &Config{
10812 MaxVersion: VersionTLS13,
10813 MinVersion: VersionTLS13,
10814 MaxEarlyDataSize: 16384,
10815 Bugs: ProtocolBugs{
10816 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
10817 },
10818 },
10819 tls13Variant: variant,
10820 resumeSession: true,
10821 flags: []string{
10822 "-enable-early-data",
10823 "-expect-early-data-info",
10824 "-expect-accept-early-data",
10825 "-on-resume-shim-writes-first",
10826 },
10827 })
10828
10829 testCases = append(testCases, testCase{
10830 testType: clientTest,
10831 name: "EarlyData-Reject-Client-" + name,
10832 config: Config{
10833 MaxVersion: VersionTLS13,
10834 MaxEarlyDataSize: 16384,
10835 },
10836 resumeConfig: &Config{
10837 MaxVersion: VersionTLS13,
10838 MaxEarlyDataSize: 16384,
10839 Bugs: ProtocolBugs{
10840 AlwaysRejectEarlyData: true,
10841 },
10842 },
10843 tls13Variant: variant,
10844 resumeSession: true,
10845 flags: []string{
10846 "-enable-early-data",
10847 "-expect-early-data-info",
10848 "-expect-reject-early-data",
10849 "-on-resume-shim-writes-first",
10850 },
10851 })
10852
10853 testCases = append(testCases, testCase{
10854 testType: serverTest,
10855 name: "EarlyData-Server-" + name,
10856 config: Config{
10857 MaxVersion: VersionTLS13,
10858 MinVersion: VersionTLS13,
10859 Bugs: ProtocolBugs{
10860 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10861 ExpectEarlyDataAccepted: true,
10862 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10863 },
10864 },
10865 tls13Variant: variant,
10866 messageCount: 2,
10867 resumeSession: true,
10868 flags: []string{
10869 "-enable-early-data",
10870 "-expect-accept-early-data",
10871 },
10872 })
10873
10874 }
Steven Valdezdbe01582017-07-14 10:39:28 -040010875
10876 testCases = append(testCases, testCase{
10877 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010878 name: "SkipEarlyData-OmitEarlyDataExtension",
10879 config: Config{
10880 MaxVersion: VersionTLS13,
10881 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010882 SendFakeEarlyDataLength: 4,
10883 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010884 },
10885 },
10886 shouldFail: true,
10887 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10888 })
10889
10890 testCases = append(testCases, testCase{
10891 testType: serverTest,
10892 name: "SkipEarlyData-TooMuchData",
10893 config: Config{
10894 MaxVersion: VersionTLS13,
10895 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010896 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010897 },
10898 },
10899 shouldFail: true,
10900 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10901 })
10902
10903 testCases = append(testCases, testCase{
10904 testType: serverTest,
10905 name: "SkipEarlyData-Interleaved",
10906 config: Config{
10907 MaxVersion: VersionTLS13,
10908 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010909 SendFakeEarlyDataLength: 4,
10910 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010911 },
10912 },
10913 shouldFail: true,
10914 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10915 })
10916
10917 testCases = append(testCases, testCase{
10918 testType: serverTest,
10919 name: "SkipEarlyData-EarlyDataInTLS12",
10920 config: Config{
10921 MaxVersion: VersionTLS13,
10922 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010923 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010924 },
10925 },
10926 shouldFail: true,
10927 expectedError: ":UNEXPECTED_RECORD:",
10928 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10929 })
10930
10931 testCases = append(testCases, testCase{
10932 testType: serverTest,
10933 name: "SkipEarlyData-HRR",
10934 config: Config{
10935 MaxVersion: VersionTLS13,
10936 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010937 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010938 },
10939 DefaultCurves: []CurveID{},
10940 },
10941 })
10942
10943 testCases = append(testCases, testCase{
10944 testType: serverTest,
10945 name: "SkipEarlyData-HRR-Interleaved",
10946 config: Config{
10947 MaxVersion: VersionTLS13,
10948 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010949 SendFakeEarlyDataLength: 4,
10950 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010951 },
10952 DefaultCurves: []CurveID{},
10953 },
10954 shouldFail: true,
10955 expectedError: ":UNEXPECTED_RECORD:",
10956 })
10957
10958 testCases = append(testCases, testCase{
10959 testType: serverTest,
10960 name: "SkipEarlyData-HRR-TooMuchData",
10961 config: Config{
10962 MaxVersion: VersionTLS13,
10963 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010964 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010965 },
10966 DefaultCurves: []CurveID{},
10967 },
10968 shouldFail: true,
10969 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10970 })
10971
10972 // Test that skipping early data looking for cleartext correctly
10973 // processes an alert record.
10974 testCases = append(testCases, testCase{
10975 testType: serverTest,
10976 name: "SkipEarlyData-HRR-FatalAlert",
10977 config: Config{
10978 MaxVersion: VersionTLS13,
10979 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010980 SendEarlyAlert: true,
10981 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010982 },
10983 DefaultCurves: []CurveID{},
10984 },
10985 shouldFail: true,
10986 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10987 })
10988
10989 testCases = append(testCases, testCase{
10990 testType: serverTest,
10991 name: "SkipEarlyData-SecondClientHelloEarlyData",
10992 config: Config{
10993 MaxVersion: VersionTLS13,
10994 Bugs: ProtocolBugs{
10995 SendEarlyDataOnSecondClientHello: true,
10996 },
10997 DefaultCurves: []CurveID{},
10998 },
10999 shouldFail: true,
11000 expectedLocalError: "remote error: bad record MAC",
11001 })
11002
11003 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040011004 testType: clientTest,
11005 name: "EmptyEncryptedExtensions",
11006 config: Config{
11007 MaxVersion: VersionTLS13,
11008 Bugs: ProtocolBugs{
11009 EmptyEncryptedExtensions: true,
11010 },
11011 },
11012 shouldFail: true,
11013 expectedLocalError: "remote error: error decoding message",
11014 })
11015
11016 testCases = append(testCases, testCase{
11017 testType: clientTest,
11018 name: "EncryptedExtensionsWithKeyShare",
11019 config: Config{
11020 MaxVersion: VersionTLS13,
11021 Bugs: ProtocolBugs{
11022 EncryptedExtensionsWithKeyShare: true,
11023 },
11024 },
11025 shouldFail: true,
11026 expectedLocalError: "remote error: unsupported extension",
11027 })
Steven Valdez5440fe02016-07-18 12:40:30 -040011028
11029 testCases = append(testCases, testCase{
11030 testType: serverTest,
11031 name: "SendHelloRetryRequest",
11032 config: Config{
11033 MaxVersion: VersionTLS13,
11034 // Require a HelloRetryRequest for every curve.
11035 DefaultCurves: []CurveID{},
11036 },
11037 expectedCurveID: CurveX25519,
11038 })
11039
11040 testCases = append(testCases, testCase{
11041 testType: serverTest,
11042 name: "SendHelloRetryRequest-2",
11043 config: Config{
11044 MaxVersion: VersionTLS13,
11045 DefaultCurves: []CurveID{CurveP384},
11046 },
11047 // Although the ClientHello did not predict our preferred curve,
11048 // we always select it whether it is predicted or not.
11049 expectedCurveID: CurveX25519,
11050 })
11051
11052 testCases = append(testCases, testCase{
11053 name: "UnknownCurve-HelloRetryRequest",
11054 config: Config{
11055 MaxVersion: VersionTLS13,
11056 // P-384 requires HelloRetryRequest in BoringSSL.
11057 CurvePreferences: []CurveID{CurveP384},
11058 Bugs: ProtocolBugs{
11059 SendHelloRetryRequestCurve: bogusCurve,
11060 },
11061 },
11062 shouldFail: true,
11063 expectedError: ":WRONG_CURVE:",
11064 })
11065
11066 testCases = append(testCases, testCase{
11067 name: "DisabledCurve-HelloRetryRequest",
11068 config: Config{
11069 MaxVersion: VersionTLS13,
11070 CurvePreferences: []CurveID{CurveP256},
11071 Bugs: ProtocolBugs{
11072 IgnorePeerCurvePreferences: true,
11073 },
11074 },
11075 flags: []string{"-p384-only"},
11076 shouldFail: true,
11077 expectedError: ":WRONG_CURVE:",
11078 })
11079
11080 testCases = append(testCases, testCase{
11081 name: "UnnecessaryHelloRetryRequest",
11082 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011083 MaxVersion: VersionTLS13,
11084 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011085 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011086 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011087 },
11088 },
11089 shouldFail: true,
11090 expectedError: ":WRONG_CURVE:",
11091 })
11092
11093 testCases = append(testCases, testCase{
11094 name: "SecondHelloRetryRequest",
11095 config: Config{
11096 MaxVersion: VersionTLS13,
11097 // P-384 requires HelloRetryRequest in BoringSSL.
11098 CurvePreferences: []CurveID{CurveP384},
11099 Bugs: ProtocolBugs{
11100 SecondHelloRetryRequest: true,
11101 },
11102 },
11103 shouldFail: true,
11104 expectedError: ":UNEXPECTED_MESSAGE:",
11105 })
11106
11107 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011108 name: "HelloRetryRequest-Empty",
11109 config: Config{
11110 MaxVersion: VersionTLS13,
11111 Bugs: ProtocolBugs{
11112 AlwaysSendHelloRetryRequest: true,
11113 },
11114 },
11115 shouldFail: true,
11116 expectedError: ":DECODE_ERROR:",
11117 })
11118
11119 testCases = append(testCases, testCase{
11120 name: "HelloRetryRequest-DuplicateCurve",
11121 config: Config{
11122 MaxVersion: VersionTLS13,
11123 // P-384 requires a HelloRetryRequest against BoringSSL's default
11124 // configuration. Assert this ExpectMissingKeyShare.
11125 CurvePreferences: []CurveID{CurveP384},
11126 Bugs: ProtocolBugs{
11127 ExpectMissingKeyShare: true,
11128 DuplicateHelloRetryRequestExtensions: true,
11129 },
11130 },
11131 shouldFail: true,
11132 expectedError: ":DUPLICATE_EXTENSION:",
11133 expectedLocalError: "remote error: illegal parameter",
11134 })
11135
11136 testCases = append(testCases, testCase{
11137 name: "HelloRetryRequest-Cookie",
11138 config: Config{
11139 MaxVersion: VersionTLS13,
11140 Bugs: ProtocolBugs{
11141 SendHelloRetryRequestCookie: []byte("cookie"),
11142 },
11143 },
11144 })
11145
11146 testCases = append(testCases, testCase{
11147 name: "HelloRetryRequest-DuplicateCookie",
11148 config: Config{
11149 MaxVersion: VersionTLS13,
11150 Bugs: ProtocolBugs{
11151 SendHelloRetryRequestCookie: []byte("cookie"),
11152 DuplicateHelloRetryRequestExtensions: true,
11153 },
11154 },
11155 shouldFail: true,
11156 expectedError: ":DUPLICATE_EXTENSION:",
11157 expectedLocalError: "remote error: illegal parameter",
11158 })
11159
11160 testCases = append(testCases, testCase{
11161 name: "HelloRetryRequest-EmptyCookie",
11162 config: Config{
11163 MaxVersion: VersionTLS13,
11164 Bugs: ProtocolBugs{
11165 SendHelloRetryRequestCookie: []byte{},
11166 },
11167 },
11168 shouldFail: true,
11169 expectedError: ":DECODE_ERROR:",
11170 })
11171
11172 testCases = append(testCases, testCase{
11173 name: "HelloRetryRequest-Cookie-Curve",
11174 config: Config{
11175 MaxVersion: VersionTLS13,
11176 // P-384 requires HelloRetryRequest in BoringSSL.
11177 CurvePreferences: []CurveID{CurveP384},
11178 Bugs: ProtocolBugs{
11179 SendHelloRetryRequestCookie: []byte("cookie"),
11180 ExpectMissingKeyShare: true,
11181 },
11182 },
11183 })
11184
11185 testCases = append(testCases, testCase{
11186 name: "HelloRetryRequest-Unknown",
11187 config: Config{
11188 MaxVersion: VersionTLS13,
11189 Bugs: ProtocolBugs{
11190 CustomHelloRetryRequestExtension: "extension",
11191 },
11192 },
11193 shouldFail: true,
11194 expectedError: ":UNEXPECTED_EXTENSION:",
11195 expectedLocalError: "remote error: unsupported extension",
11196 })
11197
11198 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011199 testType: serverTest,
11200 name: "SecondClientHelloMissingKeyShare",
11201 config: Config{
11202 MaxVersion: VersionTLS13,
11203 DefaultCurves: []CurveID{},
11204 Bugs: ProtocolBugs{
11205 SecondClientHelloMissingKeyShare: true,
11206 },
11207 },
11208 shouldFail: true,
11209 expectedError: ":MISSING_KEY_SHARE:",
11210 })
11211
11212 testCases = append(testCases, testCase{
11213 testType: serverTest,
11214 name: "SecondClientHelloWrongCurve",
11215 config: Config{
11216 MaxVersion: VersionTLS13,
11217 DefaultCurves: []CurveID{},
11218 Bugs: ProtocolBugs{
11219 MisinterpretHelloRetryRequestCurve: CurveP521,
11220 },
11221 },
11222 shouldFail: true,
11223 expectedError: ":WRONG_CURVE:",
11224 })
11225
11226 testCases = append(testCases, testCase{
11227 name: "HelloRetryRequestVersionMismatch",
11228 config: Config{
11229 MaxVersion: VersionTLS13,
11230 // P-384 requires HelloRetryRequest in BoringSSL.
11231 CurvePreferences: []CurveID{CurveP384},
11232 Bugs: ProtocolBugs{
11233 SendServerHelloVersion: 0x0305,
11234 },
11235 },
11236 shouldFail: true,
11237 expectedError: ":WRONG_VERSION_NUMBER:",
11238 })
11239
11240 testCases = append(testCases, testCase{
11241 name: "HelloRetryRequestCurveMismatch",
11242 config: Config{
11243 MaxVersion: VersionTLS13,
11244 // P-384 requires HelloRetryRequest in BoringSSL.
11245 CurvePreferences: []CurveID{CurveP384},
11246 Bugs: ProtocolBugs{
11247 // Send P-384 (correct) in the HelloRetryRequest.
11248 SendHelloRetryRequestCurve: CurveP384,
11249 // But send P-256 in the ServerHello.
11250 SendCurve: CurveP256,
11251 },
11252 },
11253 shouldFail: true,
11254 expectedError: ":WRONG_CURVE:",
11255 })
11256
11257 // Test the server selecting a curve that requires a HelloRetryRequest
11258 // without sending it.
11259 testCases = append(testCases, testCase{
11260 name: "SkipHelloRetryRequest",
11261 config: Config{
11262 MaxVersion: VersionTLS13,
11263 // P-384 requires HelloRetryRequest in BoringSSL.
11264 CurvePreferences: []CurveID{CurveP384},
11265 Bugs: ProtocolBugs{
11266 SkipHelloRetryRequest: true,
11267 },
11268 },
11269 shouldFail: true,
11270 expectedError: ":WRONG_CURVE:",
11271 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011272
11273 testCases = append(testCases, testCase{
11274 name: "TLS13-RequestContextInHandshake",
11275 config: Config{
11276 MaxVersion: VersionTLS13,
11277 MinVersion: VersionTLS13,
11278 ClientAuth: RequireAnyClientCert,
11279 Bugs: ProtocolBugs{
11280 SendRequestContext: []byte("request context"),
11281 },
11282 },
11283 flags: []string{
11284 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11285 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11286 },
11287 shouldFail: true,
11288 expectedError: ":DECODE_ERROR:",
11289 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011290
11291 testCases = append(testCases, testCase{
11292 testType: serverTest,
11293 name: "TLS13-TrailingKeyShareData",
11294 config: Config{
11295 MaxVersion: VersionTLS13,
11296 Bugs: ProtocolBugs{
11297 TrailingKeyShareData: true,
11298 },
11299 },
11300 shouldFail: true,
11301 expectedError: ":DECODE_ERROR:",
11302 })
David Benjamin7f78df42016-10-05 22:33:19 -040011303
11304 testCases = append(testCases, testCase{
11305 name: "TLS13-AlwaysSelectPSKIdentity",
11306 config: Config{
11307 MaxVersion: VersionTLS13,
11308 Bugs: ProtocolBugs{
11309 AlwaysSelectPSKIdentity: true,
11310 },
11311 },
11312 shouldFail: true,
11313 expectedError: ":UNEXPECTED_EXTENSION:",
11314 })
11315
11316 testCases = append(testCases, testCase{
11317 name: "TLS13-InvalidPSKIdentity",
11318 config: Config{
11319 MaxVersion: VersionTLS13,
11320 Bugs: ProtocolBugs{
11321 SelectPSKIdentityOnResume: 1,
11322 },
11323 },
11324 resumeSession: true,
11325 shouldFail: true,
11326 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11327 })
David Benjamin1286bee2016-10-07 15:25:06 -040011328
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011329 testCases = append(testCases, testCase{
11330 testType: serverTest,
11331 name: "TLS13-ExtraPSKIdentity",
11332 config: Config{
11333 MaxVersion: VersionTLS13,
11334 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011335 ExtraPSKIdentity: true,
11336 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011337 },
11338 },
11339 resumeSession: true,
11340 })
11341
David Benjamin1286bee2016-10-07 15:25:06 -040011342 // Test that unknown NewSessionTicket extensions are tolerated.
11343 testCases = append(testCases, testCase{
11344 name: "TLS13-CustomTicketExtension",
11345 config: Config{
11346 MaxVersion: VersionTLS13,
11347 Bugs: ProtocolBugs{
11348 CustomTicketExtension: "1234",
11349 },
11350 },
11351 })
Steven Valdezdbe01582017-07-14 10:39:28 -040011352 testCases = append(testCases, testCase{
11353 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011354 name: "TLS13-EarlyData-RejectTicket-Client",
11355 config: Config{
11356 MaxVersion: VersionTLS13,
11357 MaxEarlyDataSize: 16384,
11358 Certificates: []Certificate{rsaCertificate},
11359 },
11360 resumeConfig: &Config{
11361 MaxVersion: VersionTLS13,
11362 MaxEarlyDataSize: 16384,
11363 Certificates: []Certificate{ecdsaP256Certificate},
11364 SessionTicketsDisabled: true,
11365 },
11366 resumeSession: true,
11367 expectResumeRejected: true,
11368 flags: []string{
11369 "-enable-early-data",
11370 "-expect-early-data-info",
11371 "-expect-reject-early-data",
11372 "-on-resume-shim-writes-first",
11373 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11374 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11375 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11376 // Session tickets are disabled, so the runner will not send a ticket.
11377 "-on-retry-expect-no-session",
11378 },
11379 })
11380
11381 testCases = append(testCases, testCase{
11382 testType: clientTest,
11383 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011384 config: Config{
11385 MaxVersion: VersionTLS13,
11386 MaxEarlyDataSize: 16384,
11387 },
11388 resumeConfig: &Config{
11389 MaxVersion: VersionTLS13,
11390 MaxEarlyDataSize: 16384,
11391 Bugs: ProtocolBugs{
11392 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11393 },
11394 },
11395 resumeSession: true,
11396 flags: []string{
11397 "-enable-early-data",
11398 "-expect-early-data-info",
11399 "-expect-reject-early-data",
11400 },
11401 })
11402
11403 // The client must check the server does not send the early_data
11404 // extension while rejecting the session.
11405 testCases = append(testCases, testCase{
11406 testType: clientTest,
11407 name: "TLS13-EarlyDataWithoutResume-Client",
11408 config: Config{
11409 MaxVersion: VersionTLS13,
11410 MaxEarlyDataSize: 16384,
11411 },
11412 resumeConfig: &Config{
11413 MaxVersion: VersionTLS13,
11414 SessionTicketsDisabled: true,
11415 Bugs: ProtocolBugs{
11416 SendEarlyDataExtension: true,
11417 },
11418 },
11419 resumeSession: true,
11420 flags: []string{
11421 "-enable-early-data",
11422 "-expect-early-data-info",
11423 },
11424 shouldFail: true,
11425 expectedError: ":UNEXPECTED_EXTENSION:",
11426 })
11427
11428 // The client must fail with a dedicated error code if the server
11429 // responds with TLS 1.2 when offering 0-RTT.
11430 testCases = append(testCases, testCase{
11431 testType: clientTest,
11432 name: "TLS13-EarlyDataVersionDowngrade-Client",
11433 config: Config{
11434 MaxVersion: VersionTLS13,
11435 MaxEarlyDataSize: 16384,
11436 },
11437 resumeConfig: &Config{
11438 MaxVersion: VersionTLS12,
11439 },
11440 resumeSession: true,
11441 flags: []string{
11442 "-enable-early-data",
11443 "-expect-early-data-info",
11444 },
11445 shouldFail: true,
11446 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11447 })
11448
11449 // Test that the client rejects an (unsolicited) early_data extension if
11450 // the server sent an HRR.
11451 testCases = append(testCases, testCase{
11452 testType: clientTest,
11453 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11454 config: Config{
11455 MaxVersion: VersionTLS13,
11456 MaxEarlyDataSize: 16384,
11457 },
11458 resumeConfig: &Config{
11459 MaxVersion: VersionTLS13,
11460 MaxEarlyDataSize: 16384,
11461 Bugs: ProtocolBugs{
11462 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11463 SendEarlyDataExtension: true,
11464 },
11465 },
11466 resumeSession: true,
11467 flags: []string{
11468 "-enable-early-data",
11469 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011470 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011471 },
11472 shouldFail: true,
11473 expectedError: ":UNEXPECTED_EXTENSION:",
11474 })
11475
11476 fooString := "foo"
11477 barString := "bar"
11478
11479 // Test that the client reports the correct ALPN after a 0-RTT reject
11480 // that changed it.
11481 testCases = append(testCases, testCase{
11482 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011483 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011484 config: Config{
11485 MaxVersion: VersionTLS13,
11486 MaxEarlyDataSize: 16384,
11487 Bugs: ProtocolBugs{
11488 ALPNProtocol: &fooString,
11489 },
11490 },
11491 resumeConfig: &Config{
11492 MaxVersion: VersionTLS13,
11493 MaxEarlyDataSize: 16384,
11494 Bugs: ProtocolBugs{
11495 ALPNProtocol: &barString,
11496 },
11497 },
11498 resumeSession: true,
11499 flags: []string{
11500 "-advertise-alpn", "\x03foo\x03bar",
11501 "-enable-early-data",
11502 "-expect-early-data-info",
11503 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011504 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011505 "-on-resume-expect-alpn", "foo",
11506 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011507 },
11508 })
11509
11510 // Test that the client reports the correct ALPN after a 0-RTT reject if
11511 // ALPN was omitted from the first connection.
11512 testCases = append(testCases, testCase{
11513 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011514 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011515 config: Config{
11516 MaxVersion: VersionTLS13,
11517 MaxEarlyDataSize: 16384,
11518 },
11519 resumeConfig: &Config{
11520 MaxVersion: VersionTLS13,
11521 MaxEarlyDataSize: 16384,
11522 NextProtos: []string{"foo"},
11523 },
11524 resumeSession: true,
11525 flags: []string{
11526 "-advertise-alpn", "\x03foo\x03bar",
11527 "-enable-early-data",
11528 "-expect-early-data-info",
11529 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011530 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011531 "-on-resume-expect-alpn", "",
11532 "-on-retry-expect-alpn", "foo",
11533 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011534 },
11535 })
11536
11537 // Test that the client reports the correct ALPN after a 0-RTT reject if
11538 // ALPN was omitted from the second connection.
11539 testCases = append(testCases, testCase{
11540 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011541 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011542 config: Config{
11543 MaxVersion: VersionTLS13,
11544 MaxEarlyDataSize: 16384,
11545 NextProtos: []string{"foo"},
11546 },
11547 resumeConfig: &Config{
11548 MaxVersion: VersionTLS13,
11549 MaxEarlyDataSize: 16384,
11550 },
11551 resumeSession: true,
11552 flags: []string{
11553 "-advertise-alpn", "\x03foo\x03bar",
11554 "-enable-early-data",
11555 "-expect-early-data-info",
11556 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011557 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011558 "-on-resume-expect-alpn", "foo",
11559 "-on-retry-expect-alpn", "",
11560 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011561 },
11562 })
11563
11564 // Test that the client enforces ALPN match on 0-RTT accept.
11565 testCases = append(testCases, testCase{
11566 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011567 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011568 config: Config{
11569 MaxVersion: VersionTLS13,
11570 MaxEarlyDataSize: 16384,
11571 Bugs: ProtocolBugs{
11572 ALPNProtocol: &fooString,
11573 },
11574 },
11575 resumeConfig: &Config{
11576 MaxVersion: VersionTLS13,
11577 MaxEarlyDataSize: 16384,
11578 Bugs: ProtocolBugs{
11579 AlwaysAcceptEarlyData: true,
11580 ALPNProtocol: &barString,
11581 },
11582 },
11583 resumeSession: true,
11584 flags: []string{
11585 "-advertise-alpn", "\x03foo\x03bar",
11586 "-enable-early-data",
11587 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011588 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011589 "-on-resume-expect-alpn", "foo",
11590 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011591 },
11592 shouldFail: true,
11593 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11594 })
11595
11596 // Test that the server correctly rejects 0-RTT when the previous
11597 // session did not allow early data on resumption.
11598 testCases = append(testCases, testCase{
11599 testType: serverTest,
11600 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11601 config: Config{
11602 MaxVersion: VersionTLS13,
11603 },
11604 resumeConfig: &Config{
11605 MaxVersion: VersionTLS13,
11606 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011607 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011608 ExpectEarlyDataAccepted: false,
11609 },
11610 },
11611 resumeSession: true,
11612 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011613 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011614 "-expect-reject-early-data",
11615 },
11616 })
11617
11618 // Test that we reject early data where ALPN is omitted from the first
11619 // connection.
11620 testCases = append(testCases, testCase{
11621 testType: serverTest,
11622 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11623 config: Config{
11624 MaxVersion: VersionTLS13,
11625 NextProtos: []string{},
11626 },
11627 resumeConfig: &Config{
11628 MaxVersion: VersionTLS13,
11629 NextProtos: []string{"foo"},
11630 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011631 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011632 ExpectEarlyDataAccepted: false,
11633 },
11634 },
11635 resumeSession: true,
11636 flags: []string{
11637 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011638 "-on-initial-select-alpn", "",
11639 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011640 },
11641 })
11642
11643 // Test that we reject early data where ALPN is omitted from the second
11644 // connection.
11645 testCases = append(testCases, testCase{
11646 testType: serverTest,
11647 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11648 config: Config{
11649 MaxVersion: VersionTLS13,
11650 NextProtos: []string{"foo"},
11651 },
11652 resumeConfig: &Config{
11653 MaxVersion: VersionTLS13,
11654 NextProtos: []string{},
11655 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011656 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011657 ExpectEarlyDataAccepted: false,
11658 },
11659 },
11660 resumeSession: true,
11661 flags: []string{
11662 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011663 "-on-initial-select-alpn", "foo",
11664 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011665 },
11666 })
11667
11668 // Test that we reject early data with mismatched ALPN.
11669 testCases = append(testCases, testCase{
11670 testType: serverTest,
11671 name: "TLS13-EarlyData-ALPNMismatch-Server",
11672 config: Config{
11673 MaxVersion: VersionTLS13,
11674 NextProtos: []string{"foo"},
11675 },
11676 resumeConfig: &Config{
11677 MaxVersion: VersionTLS13,
11678 NextProtos: []string{"bar"},
11679 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011680 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011681 ExpectEarlyDataAccepted: false,
11682 },
11683 },
11684 resumeSession: true,
11685 flags: []string{
11686 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011687 "-on-initial-select-alpn", "foo",
11688 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011689 },
11690 })
11691
David Benjamin6bb507b2017-03-29 16:35:57 -050011692 // Test that the client offering 0-RTT and Channel ID forbids the server
11693 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011694 testCases = append(testCases, testCase{
11695 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011696 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011697 config: Config{
11698 MaxVersion: VersionTLS13,
11699 MaxEarlyDataSize: 16384,
11700 RequestChannelID: true,
11701 },
11702 resumeSession: true,
11703 expectChannelID: true,
11704 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011705 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011706 flags: []string{
11707 "-enable-early-data",
11708 "-expect-early-data-info",
11709 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11710 },
11711 })
11712
David Benjamin6bb507b2017-03-29 16:35:57 -050011713 // Test that the client offering Channel ID and 0-RTT allows the server
11714 // to decline 0-RTT.
11715 testCases = append(testCases, testCase{
11716 testType: clientTest,
11717 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11718 config: Config{
11719 MaxVersion: VersionTLS13,
11720 MaxEarlyDataSize: 16384,
11721 RequestChannelID: true,
11722 Bugs: ProtocolBugs{
11723 AlwaysRejectEarlyData: true,
11724 },
11725 },
11726 resumeSession: true,
11727 expectChannelID: true,
11728 flags: []string{
11729 "-enable-early-data",
11730 "-expect-early-data-info",
11731 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11732 "-expect-reject-early-data",
11733 },
11734 })
11735
11736 // Test that the client offering Channel ID and 0-RTT allows the server
11737 // to decline Channel ID.
11738 testCases = append(testCases, testCase{
11739 testType: clientTest,
11740 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11741 config: Config{
11742 MaxVersion: VersionTLS13,
11743 MaxEarlyDataSize: 16384,
11744 },
11745 resumeSession: true,
11746 flags: []string{
11747 "-enable-early-data",
11748 "-expect-early-data-info",
11749 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11750 "-expect-accept-early-data",
11751 },
11752 })
11753
11754 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11755 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011756 testCases = append(testCases, testCase{
11757 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011758 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011759 config: Config{
11760 MaxVersion: VersionTLS13,
11761 ChannelID: channelIDKey,
11762 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011763 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011764 ExpectEarlyDataAccepted: false,
11765 },
11766 },
11767 resumeSession: true,
11768 expectChannelID: true,
11769 flags: []string{
11770 "-enable-early-data",
11771 "-expect-reject-early-data",
11772 "-expect-channel-id",
11773 base64.StdEncoding.EncodeToString(channelIDBytes),
11774 },
11775 })
11776
David Benjamin6bb507b2017-03-29 16:35:57 -050011777 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11778 // if not offered Channel ID.
11779 testCases = append(testCases, testCase{
11780 testType: serverTest,
11781 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11782 config: Config{
11783 MaxVersion: VersionTLS13,
11784 Bugs: ProtocolBugs{
11785 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11786 ExpectEarlyDataAccepted: true,
11787 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11788 },
11789 },
11790 resumeSession: true,
11791 expectChannelID: false,
11792 flags: []string{
11793 "-enable-early-data",
11794 "-expect-accept-early-data",
11795 "-enable-channel-id",
11796 },
11797 })
11798
David Benjamin32c89272017-03-26 13:54:21 -050011799 // Test that the server rejects 0-RTT streams without end_of_early_data.
11800 // The subsequent records should fail to decrypt.
11801 testCases = append(testCases, testCase{
11802 testType: serverTest,
11803 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11804 config: Config{
11805 MaxVersion: VersionTLS13,
11806 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011807 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011808 ExpectEarlyDataAccepted: true,
11809 SkipEndOfEarlyData: true,
11810 },
11811 },
11812 resumeSession: true,
11813 flags: []string{"-enable-early-data"},
11814 shouldFail: true,
11815 expectedLocalError: "remote error: bad record MAC",
11816 expectedError: ":BAD_DECRYPT:",
11817 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011818
11819 testCases = append(testCases, testCase{
11820 testType: serverTest,
11821 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11822 config: Config{
11823 MaxVersion: VersionTLS13,
11824 },
11825 resumeConfig: &Config{
11826 MaxVersion: VersionTLS13,
11827 Bugs: ProtocolBugs{
11828 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11829 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011830 ExpectEarlyDataAccepted: true,
11831 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011832 },
11833 resumeSession: true,
11834 shouldFail: true,
11835 expectedError: ":UNEXPECTED_RECORD:",
11836 expectedLocalError: "remote error: unexpected message",
11837 flags: []string{
11838 "-enable-early-data",
11839 },
11840 })
David Benjamind9cbb532017-07-07 13:17:19 -040011841
11842 // Test that the client reports TLS 1.3 as the version while sending
11843 // early data.
11844 testCases = append(testCases, testCase{
11845 testType: clientTest,
11846 name: "TLS13-EarlyData-Client-VersionAPI",
11847 config: Config{
11848 MaxVersion: VersionTLS13,
11849 MaxEarlyDataSize: 16384,
11850 },
11851 resumeSession: true,
11852 flags: []string{
11853 "-enable-early-data",
11854 "-expect-early-data-info",
11855 "-expect-accept-early-data",
11856 "-expect-version", strconv.Itoa(VersionTLS13),
11857 },
11858 })
David Benjamin4a37de02017-08-08 20:15:40 -040011859
11860 // Test that client and server both notice handshake errors after data
11861 // has started flowing.
11862 testCases = append(testCases, testCase{
11863 testType: clientTest,
11864 name: "TLS13-EarlyData-Client-BadFinished",
11865 config: Config{
11866 MaxVersion: VersionTLS13,
11867 MaxEarlyDataSize: 16384,
11868 },
11869 resumeConfig: &Config{
11870 MaxVersion: VersionTLS13,
11871 MaxEarlyDataSize: 16384,
11872 Bugs: ProtocolBugs{
11873 BadFinished: true,
11874 },
11875 },
11876 resumeSession: true,
11877 flags: []string{
11878 "-enable-early-data",
11879 "-expect-early-data-info",
11880 "-expect-accept-early-data",
11881 },
11882 shouldFail: true,
11883 expectedError: ":DIGEST_CHECK_FAILED:",
11884 expectedLocalError: "remote error: error decrypting message",
11885 })
11886 testCases = append(testCases, testCase{
11887 testType: serverTest,
11888 name: "TLS13-EarlyData-Server-BadFinished",
11889 config: Config{
11890 MaxVersion: VersionTLS13,
11891 MaxEarlyDataSize: 16384,
11892 },
11893 resumeConfig: &Config{
11894 MaxVersion: VersionTLS13,
11895 MaxEarlyDataSize: 16384,
11896 Bugs: ProtocolBugs{
11897 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11898 ExpectEarlyDataAccepted: true,
11899 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11900 BadFinished: true,
11901 },
11902 },
11903 resumeSession: true,
11904 flags: []string{
11905 "-enable-early-data",
11906 "-expect-accept-early-data",
11907 },
11908 shouldFail: true,
11909 expectedError: ":DIGEST_CHECK_FAILED:",
11910 expectedLocalError: "remote error: error decrypting message",
11911 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020011912 testCases = append(testCases, testCase{
11913 testType: serverTest,
11914 name: "TLS13-ServerSkipCertificateVerify",
11915 config: Config{
11916 MinVersion: VersionTLS13,
11917 MaxVersion: VersionTLS13,
11918 Certificates: []Certificate{rsaChainCertificate},
11919 Bugs: ProtocolBugs{
11920 SkipCertificateVerify: true,
11921 },
11922 },
11923 expectPeerCertificate: &rsaChainCertificate,
11924 flags: []string{
11925 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11926 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11927 "-require-any-client-certificate",
11928 },
11929 shouldFail: true,
11930 expectedError: ":UNEXPECTED_MESSAGE:",
11931 expectedLocalError: "remote error: unexpected message",
11932 })
11933 testCases = append(testCases, testCase{
11934 testType: clientTest,
11935 name: "TLS13-ClientSkipCertificateVerify",
11936 config: Config{
11937 MinVersion: VersionTLS13,
11938 MaxVersion: VersionTLS13,
11939 Certificates: []Certificate{rsaChainCertificate},
11940 Bugs: ProtocolBugs{
11941 SkipCertificateVerify: true,
11942 },
11943 },
11944 expectPeerCertificate: &rsaChainCertificate,
11945 flags: []string{
11946 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11947 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11948 },
11949 shouldFail: true,
11950 expectedError: ":UNEXPECTED_MESSAGE:",
11951 expectedLocalError: "remote error: unexpected message",
11952 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011953}
11954
David Benjaminabbbee12016-10-31 19:20:42 -040011955func addTLS13CipherPreferenceTests() {
11956 // Test that client preference is honored if the shim has AES hardware
11957 // and ChaCha20-Poly1305 is preferred otherwise.
11958 testCases = append(testCases, testCase{
11959 testType: serverTest,
11960 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11961 config: Config{
11962 MaxVersion: VersionTLS13,
11963 CipherSuites: []uint16{
11964 TLS_CHACHA20_POLY1305_SHA256,
11965 TLS_AES_128_GCM_SHA256,
11966 },
11967 },
11968 flags: []string{
11969 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11970 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11971 },
11972 })
11973
11974 testCases = append(testCases, testCase{
11975 testType: serverTest,
11976 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11977 config: Config{
11978 MaxVersion: VersionTLS13,
11979 CipherSuites: []uint16{
11980 TLS_AES_128_GCM_SHA256,
11981 TLS_CHACHA20_POLY1305_SHA256,
11982 },
11983 },
11984 flags: []string{
11985 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11986 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11987 },
11988 })
11989
11990 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11991 // whether it has AES hardware.
11992 testCases = append(testCases, testCase{
11993 name: "TLS13-CipherPreference-Client",
11994 config: Config{
11995 MaxVersion: VersionTLS13,
11996 // Use the client cipher order. (This is the default but
11997 // is listed to be explicit.)
11998 PreferServerCipherSuites: false,
11999 },
12000 flags: []string{
12001 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12002 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12003 },
12004 })
12005}
12006
David Benjaminf3fbade2016-09-19 13:08:16 -040012007func addPeekTests() {
12008 // Test SSL_peek works, including on empty records.
12009 testCases = append(testCases, testCase{
12010 name: "Peek-Basic",
12011 sendEmptyRecords: 1,
12012 flags: []string{"-peek-then-read"},
12013 })
12014
12015 // Test SSL_peek can drive the initial handshake.
12016 testCases = append(testCases, testCase{
12017 name: "Peek-ImplicitHandshake",
12018 flags: []string{
12019 "-peek-then-read",
12020 "-implicit-handshake",
12021 },
12022 })
12023
12024 // Test SSL_peek can discover and drive a renegotiation.
12025 testCases = append(testCases, testCase{
12026 name: "Peek-Renegotiate",
12027 config: Config{
12028 MaxVersion: VersionTLS12,
12029 },
12030 renegotiate: 1,
12031 flags: []string{
12032 "-peek-then-read",
12033 "-renegotiate-freely",
12034 "-expect-total-renegotiations", "1",
12035 },
12036 })
12037
12038 // Test SSL_peek can discover a close_notify.
12039 testCases = append(testCases, testCase{
12040 name: "Peek-Shutdown",
12041 config: Config{
12042 Bugs: ProtocolBugs{
12043 ExpectCloseNotify: true,
12044 },
12045 },
12046 flags: []string{
12047 "-peek-then-read",
12048 "-check-close-notify",
12049 },
12050 })
12051
12052 // Test SSL_peek can discover an alert.
12053 testCases = append(testCases, testCase{
12054 name: "Peek-Alert",
12055 config: Config{
12056 Bugs: ProtocolBugs{
12057 SendSpuriousAlert: alertRecordOverflow,
12058 },
12059 },
12060 flags: []string{"-peek-then-read"},
12061 shouldFail: true,
12062 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12063 })
12064
12065 // Test SSL_peek can handle KeyUpdate.
12066 testCases = append(testCases, testCase{
12067 name: "Peek-KeyUpdate",
12068 config: Config{
12069 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012070 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012071 sendKeyUpdates: 1,
12072 keyUpdateRequest: keyUpdateNotRequested,
12073 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012074 })
12075}
12076
David Benjamine6f22212016-11-08 14:28:24 -050012077func addRecordVersionTests() {
12078 for _, ver := range tlsVersions {
12079 // Test that the record version is enforced.
12080 testCases = append(testCases, testCase{
12081 name: "CheckRecordVersion-" + ver.name,
12082 config: Config{
12083 MinVersion: ver.version,
12084 MaxVersion: ver.version,
12085 Bugs: ProtocolBugs{
12086 SendRecordVersion: 0x03ff,
12087 },
12088 },
David Benjamina5022392017-07-10 17:40:39 -040012089 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012090 shouldFail: true,
12091 expectedError: ":WRONG_VERSION_NUMBER:",
12092 })
12093
12094 // Test that the ClientHello may use any record version, for
12095 // compatibility reasons.
12096 testCases = append(testCases, testCase{
12097 testType: serverTest,
12098 name: "LooseInitialRecordVersion-" + ver.name,
12099 config: Config{
12100 MinVersion: ver.version,
12101 MaxVersion: ver.version,
12102 Bugs: ProtocolBugs{
12103 SendInitialRecordVersion: 0x03ff,
12104 },
12105 },
David Benjamina5022392017-07-10 17:40:39 -040012106 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012107 })
12108
12109 // Test that garbage ClientHello record versions are rejected.
12110 testCases = append(testCases, testCase{
12111 testType: serverTest,
12112 name: "GarbageInitialRecordVersion-" + ver.name,
12113 config: Config{
12114 MinVersion: ver.version,
12115 MaxVersion: ver.version,
12116 Bugs: ProtocolBugs{
12117 SendInitialRecordVersion: 0xffff,
12118 },
12119 },
David Benjamina5022392017-07-10 17:40:39 -040012120 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012121 shouldFail: true,
12122 expectedError: ":WRONG_VERSION_NUMBER:",
12123 })
12124 }
12125}
12126
David Benjamin2c516452016-11-15 10:16:54 +090012127func addCertificateTests() {
David Benjamin2c516452016-11-15 10:16:54 +090012128 for _, ver := range tlsVersions {
David Benjamin3969fdf2017-08-29 15:50:58 -040012129 // Test that a certificate chain with intermediate may be sent
12130 // and received as both client and server.
David Benjamin2c516452016-11-15 10:16:54 +090012131 testCases = append(testCases, testCase{
12132 testType: clientTest,
12133 name: "SendReceiveIntermediate-Client-" + ver.name,
12134 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012135 MinVersion: ver.version,
12136 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012137 Certificates: []Certificate{rsaChainCertificate},
12138 ClientAuth: RequireAnyClientCert,
12139 },
David Benjamina5022392017-07-10 17:40:39 -040012140 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012141 expectPeerCertificate: &rsaChainCertificate,
12142 flags: []string{
12143 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12144 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12145 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12146 },
12147 })
12148
12149 testCases = append(testCases, testCase{
12150 testType: serverTest,
12151 name: "SendReceiveIntermediate-Server-" + ver.name,
12152 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012153 MinVersion: ver.version,
12154 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012155 Certificates: []Certificate{rsaChainCertificate},
12156 },
David Benjamina5022392017-07-10 17:40:39 -040012157 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012158 expectPeerCertificate: &rsaChainCertificate,
12159 flags: []string{
12160 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12161 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12162 "-require-any-client-certificate",
12163 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12164 },
12165 })
David Benjamin3969fdf2017-08-29 15:50:58 -040012166
12167 // Test that garbage leaf certificates are properly rejected.
12168 testCases = append(testCases, testCase{
12169 testType: clientTest,
12170 name: "GarbageCertificate-Client-" + ver.name,
12171 config: Config{
12172 MinVersion: ver.version,
12173 MaxVersion: ver.version,
12174 Certificates: []Certificate{garbageCertificate},
12175 },
12176 tls13Variant: ver.tls13Variant,
12177 shouldFail: true,
12178 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12179 expectedLocalError: "remote error: error decoding message",
12180 })
12181
12182 testCases = append(testCases, testCase{
12183 testType: serverTest,
12184 name: "GarbageCertificate-Server-" + ver.name,
12185 config: Config{
12186 MinVersion: ver.version,
12187 MaxVersion: ver.version,
12188 Certificates: []Certificate{garbageCertificate},
12189 },
12190 tls13Variant: ver.tls13Variant,
12191 flags: []string{"-require-any-client-certificate"},
12192 shouldFail: true,
12193 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12194 expectedLocalError: "remote error: error decoding message",
12195 })
David Benjamin2c516452016-11-15 10:16:54 +090012196 }
12197}
12198
David Benjaminbbaf3672016-11-17 10:53:09 +090012199func addRetainOnlySHA256ClientCertTests() {
12200 for _, ver := range tlsVersions {
12201 // Test that enabling
12202 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12203 // actually requesting a client certificate is a no-op.
12204 testCases = append(testCases, testCase{
12205 testType: serverTest,
12206 name: "RetainOnlySHA256-NoCert-" + ver.name,
12207 config: Config{
12208 MinVersion: ver.version,
12209 MaxVersion: ver.version,
12210 },
David Benjamina5022392017-07-10 17:40:39 -040012211 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012212 flags: []string{
David Benjaminf2165072017-08-23 23:01:37 -070012213 "-on-initial-retain-only-sha256-client-cert",
12214 "-on-resume-retain-only-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012215 },
12216 resumeSession: true,
12217 })
12218
12219 // Test that when retaining only a SHA-256 certificate is
12220 // enabled, the hash appears as expected.
12221 testCases = append(testCases, testCase{
12222 testType: serverTest,
12223 name: "RetainOnlySHA256-Cert-" + ver.name,
12224 config: Config{
12225 MinVersion: ver.version,
12226 MaxVersion: ver.version,
12227 Certificates: []Certificate{rsaCertificate},
12228 },
David Benjamina5022392017-07-10 17:40:39 -040012229 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012230 flags: []string{
12231 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012232 "-on-initial-retain-only-sha256-client-cert",
12233 "-on-resume-retain-only-sha256-client-cert",
12234 "-on-initial-expect-sha256-client-cert",
12235 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012236 },
12237 resumeSession: true,
12238 })
12239
12240 // Test that when the config changes from on to off, a
12241 // resumption is rejected because the server now wants the full
12242 // certificate chain.
12243 testCases = append(testCases, testCase{
12244 testType: serverTest,
12245 name: "RetainOnlySHA256-OnOff-" + ver.name,
12246 config: Config{
12247 MinVersion: ver.version,
12248 MaxVersion: ver.version,
12249 Certificates: []Certificate{rsaCertificate},
12250 },
David Benjamina5022392017-07-10 17:40:39 -040012251 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012252 flags: []string{
12253 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012254 "-on-initial-retain-only-sha256-client-cert",
12255 "-on-initial-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012256 },
12257 resumeSession: true,
12258 expectResumeRejected: true,
12259 })
12260
12261 // Test that when the config changes from off to on, a
12262 // resumption is rejected because the server now wants just the
12263 // hash.
12264 testCases = append(testCases, testCase{
12265 testType: serverTest,
12266 name: "RetainOnlySHA256-OffOn-" + ver.name,
12267 config: Config{
12268 MinVersion: ver.version,
12269 MaxVersion: ver.version,
12270 Certificates: []Certificate{rsaCertificate},
12271 },
David Benjamina5022392017-07-10 17:40:39 -040012272 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012273 flags: []string{
12274 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012275 "-on-resume-retain-only-sha256-client-cert",
12276 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012277 },
12278 resumeSession: true,
12279 expectResumeRejected: true,
12280 })
12281 }
12282}
12283
Adam Langleya4b91982016-12-12 12:05:53 -080012284func addECDSAKeyUsageTests() {
12285 p256 := elliptic.P256()
12286 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12287 if err != nil {
12288 panic(err)
12289 }
12290
12291 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12292 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12293 if err != nil {
12294 panic(err)
12295 }
12296
12297 template := x509.Certificate{
12298 SerialNumber: serialNumber,
12299 Subject: pkix.Name{
12300 Organization: []string{"Acme Co"},
12301 },
12302 NotBefore: time.Now(),
12303 NotAfter: time.Now(),
12304
12305 // An ECC certificate with only the keyAgreement key usgae may
12306 // be used with ECDH, but not ECDSA.
12307 KeyUsage: x509.KeyUsageKeyAgreement,
12308 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12309 BasicConstraintsValid: true,
12310 }
12311
12312 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12313 if err != nil {
12314 panic(err)
12315 }
12316
12317 cert := Certificate{
12318 Certificate: [][]byte{derBytes},
12319 PrivateKey: priv,
12320 }
12321
12322 for _, ver := range tlsVersions {
12323 if ver.version < VersionTLS12 {
12324 continue
12325 }
12326
12327 testCases = append(testCases, testCase{
12328 testType: clientTest,
12329 name: "ECDSAKeyUsage-" + ver.name,
12330 config: Config{
12331 MinVersion: ver.version,
12332 MaxVersion: ver.version,
12333 Certificates: []Certificate{cert},
12334 },
David Benjamina5022392017-07-10 17:40:39 -040012335 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012336 shouldFail: true,
12337 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12338 })
12339 }
12340}
12341
David Benjamin8c26d752017-03-26 15:13:51 -050012342func addExtraHandshakeTests() {
12343 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12344 // to ensure there is no transport I/O.
12345 testCases = append(testCases, testCase{
12346 testType: clientTest,
12347 name: "ExtraHandshake-Client-TLS12",
12348 config: Config{
12349 MinVersion: VersionTLS12,
12350 MaxVersion: VersionTLS12,
12351 },
12352 flags: []string{
12353 "-async",
12354 "-no-op-extra-handshake",
12355 },
12356 })
12357 testCases = append(testCases, testCase{
12358 testType: serverTest,
12359 name: "ExtraHandshake-Server-TLS12",
12360 config: Config{
12361 MinVersion: VersionTLS12,
12362 MaxVersion: VersionTLS12,
12363 },
12364 flags: []string{
12365 "-async",
12366 "-no-op-extra-handshake",
12367 },
12368 })
12369 testCases = append(testCases, testCase{
12370 testType: clientTest,
12371 name: "ExtraHandshake-Client-TLS13",
12372 config: Config{
12373 MinVersion: VersionTLS13,
12374 MaxVersion: VersionTLS13,
12375 },
12376 flags: []string{
12377 "-async",
12378 "-no-op-extra-handshake",
12379 },
12380 })
12381 testCases = append(testCases, testCase{
12382 testType: serverTest,
12383 name: "ExtraHandshake-Server-TLS13",
12384 config: Config{
12385 MinVersion: VersionTLS13,
12386 MaxVersion: VersionTLS13,
12387 },
12388 flags: []string{
12389 "-async",
12390 "-no-op-extra-handshake",
12391 },
12392 })
12393
12394 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12395 testCases = append(testCases, testCase{
12396 testType: serverTest,
12397 name: "ExtraHandshake-Server-EarlyData-TLS13",
12398 config: Config{
12399 MaxVersion: VersionTLS13,
12400 MinVersion: VersionTLS13,
12401 Bugs: ProtocolBugs{
12402 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12403 ExpectEarlyDataAccepted: true,
12404 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12405 },
12406 },
12407 messageCount: 2,
12408 resumeSession: true,
12409 flags: []string{
12410 "-async",
12411 "-enable-early-data",
12412 "-expect-accept-early-data",
12413 "-no-op-extra-handshake",
12414 },
12415 })
12416
12417 // An extra SSL_do_handshake drives the handshake to completion in False
12418 // Start. We test this by handshaking twice and asserting the False
12419 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12420 // how the test works.
12421 testCases = append(testCases, testCase{
12422 testType: clientTest,
12423 name: "ExtraHandshake-FalseStart",
12424 config: Config{
12425 MaxVersion: VersionTLS12,
12426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12427 NextProtos: []string{"foo"},
12428 Bugs: ProtocolBugs{
12429 ExpectFalseStart: true,
12430 AlertBeforeFalseStartTest: alertAccessDenied,
12431 },
12432 },
12433 flags: []string{
12434 "-handshake-twice",
12435 "-false-start",
12436 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012437 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012438 },
12439 shimWritesFirst: true,
12440 shouldFail: true,
12441 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12442 expectedLocalError: "tls: peer did not false start: EOF",
12443 })
12444}
12445
David Benjaminb853f312017-07-14 18:40:34 -040012446// Test that omitted and empty extensions blocks are tolerated.
12447func addOmitExtensionsTests() {
David Benjamin0a471912017-08-31 00:19:57 -040012448 // Check the ExpectOmitExtensions setting works.
12449 testCases = append(testCases, testCase{
12450 testType: serverTest,
12451 name: "ExpectOmitExtensions",
12452 config: Config{
12453 MinVersion: VersionTLS12,
12454 MaxVersion: VersionTLS12,
12455 Bugs: ProtocolBugs{
12456 ExpectOmitExtensions: true,
12457 },
12458 },
12459 shouldFail: true,
12460 expectedLocalError: "tls: ServerHello did not omit extensions",
12461 })
12462
David Benjaminb853f312017-07-14 18:40:34 -040012463 for _, ver := range tlsVersions {
12464 if ver.version > VersionTLS12 {
12465 continue
12466 }
12467
12468 testCases = append(testCases, testCase{
12469 testType: serverTest,
12470 name: "OmitExtensions-ClientHello-" + ver.name,
12471 config: Config{
12472 MinVersion: ver.version,
12473 MaxVersion: ver.version,
12474 SessionTicketsDisabled: true,
12475 Bugs: ProtocolBugs{
12476 OmitExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012477 // With no client extensions, the ServerHello must not have
12478 // extensions. It should then omit the extensions field.
12479 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012480 },
12481 },
12482 })
12483
12484 testCases = append(testCases, testCase{
12485 testType: serverTest,
12486 name: "EmptyExtensions-ClientHello-" + ver.name,
12487 config: Config{
12488 MinVersion: ver.version,
12489 MaxVersion: ver.version,
12490 SessionTicketsDisabled: true,
12491 Bugs: ProtocolBugs{
12492 EmptyExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012493 // With no client extensions, the ServerHello must not have
12494 // extensions. It should then omit the extensions field.
12495 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012496 },
12497 },
12498 })
12499
12500 testCases = append(testCases, testCase{
12501 testType: clientTest,
12502 name: "OmitExtensions-ServerHello-" + ver.name,
12503 config: Config{
12504 MinVersion: ver.version,
12505 MaxVersion: ver.version,
12506 SessionTicketsDisabled: true,
12507 Bugs: ProtocolBugs{
12508 OmitExtensions: true,
12509 // Disable all ServerHello extensions so
12510 // OmitExtensions works.
12511 NoExtendedMasterSecret: true,
12512 NoRenegotiationInfo: true,
12513 },
12514 },
12515 })
12516
12517 testCases = append(testCases, testCase{
12518 testType: clientTest,
12519 name: "EmptyExtensions-ServerHello-" + ver.name,
12520 config: Config{
12521 MinVersion: ver.version,
12522 MaxVersion: ver.version,
12523 SessionTicketsDisabled: true,
12524 Bugs: ProtocolBugs{
12525 EmptyExtensions: true,
12526 // Disable all ServerHello extensions so
12527 // EmptyExtensions works.
12528 NoExtendedMasterSecret: true,
12529 NoRenegotiationInfo: true,
12530 },
12531 },
12532 })
12533 }
12534}
12535
Adam Langley7c803a62015-06-15 15:35:05 -070012536func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012537 defer wg.Done()
12538
12539 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012540 var err error
12541
David Benjaminba28dfc2016-11-15 17:47:21 +090012542 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012543 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12544 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012545 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012546 if err != nil {
12547 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12548 }
12549 break
12550 }
12551 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012552 } else if *repeatUntilFailure {
12553 for err == nil {
12554 statusChan <- statusMsg{test: test, started: true}
12555 err = runTest(test, shimPath, -1)
12556 }
12557 } else {
12558 statusChan <- statusMsg{test: test, started: true}
12559 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012560 }
Adam Langley95c29f32014-06-20 12:00:00 -070012561 statusChan <- statusMsg{test: test, err: err}
12562 }
12563}
12564
12565type statusMsg struct {
12566 test *testCase
12567 started bool
12568 err error
12569}
12570
David Benjamin5f237bc2015-02-11 17:14:15 -050012571func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012572 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012573
David Benjamin5f237bc2015-02-11 17:14:15 -050012574 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012575 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012576 if !*pipe {
12577 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012578 var erase string
12579 for i := 0; i < lineLen; i++ {
12580 erase += "\b \b"
12581 }
12582 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012583 }
12584
Adam Langley95c29f32014-06-20 12:00:00 -070012585 if msg.started {
12586 started++
12587 } else {
12588 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012589
12590 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012591 if msg.err == errUnimplemented {
12592 if *pipe {
12593 // Print each test instead of a status line.
12594 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12595 }
12596 unimplemented++
12597 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12598 } else {
12599 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12600 failed++
12601 testOutput.addResult(msg.test.name, "FAIL")
12602 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012603 } else {
12604 if *pipe {
12605 // Print each test instead of a status line.
12606 fmt.Printf("PASSED (%s)\n", msg.test.name)
12607 }
12608 testOutput.addResult(msg.test.name, "PASS")
12609 }
Adam Langley95c29f32014-06-20 12:00:00 -070012610 }
12611
David Benjamin5f237bc2015-02-11 17:14:15 -050012612 if !*pipe {
12613 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012614 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012615 lineLen = len(line)
12616 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012617 }
Adam Langley95c29f32014-06-20 12:00:00 -070012618 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012619
12620 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012621}
12622
12623func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012624 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012625 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012626 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012627
Adam Langley7c803a62015-06-15 15:35:05 -070012628 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012629 addCipherSuiteTests()
12630 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012631 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012632 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012633 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012634 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012635 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012636 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012637 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012638 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012639 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012640 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012641 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012642 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012643 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012644 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012645 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012646 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012647 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012648 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012649 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012650 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012651 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012652 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012653 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012654 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012655 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012656 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012657 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012658 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012659 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012660 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012661 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012662 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012663 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012664
12665 var wg sync.WaitGroup
12666
Adam Langley7c803a62015-06-15 15:35:05 -070012667 statusChan := make(chan statusMsg, *numWorkers)
12668 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012669 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012670
EKRf71d7ed2016-08-06 13:25:12 -070012671 if len(*shimConfigFile) != 0 {
12672 encoded, err := ioutil.ReadFile(*shimConfigFile)
12673 if err != nil {
12674 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12675 os.Exit(1)
12676 }
12677
12678 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12679 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12680 os.Exit(1)
12681 }
12682 }
12683
David Benjamin025b3d32014-07-01 19:53:04 -040012684 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012685
Adam Langley7c803a62015-06-15 15:35:05 -070012686 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012687 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012688 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012689 }
12690
David Benjamin270f0a72016-03-17 14:41:36 -040012691 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012692 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012693 matched := true
12694 if len(*testToRun) != 0 {
12695 var err error
12696 matched, err = filepath.Match(*testToRun, testCases[i].name)
12697 if err != nil {
12698 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12699 os.Exit(1)
12700 }
12701 }
12702
EKRf71d7ed2016-08-06 13:25:12 -070012703 if !*includeDisabled {
12704 for pattern := range shimConfig.DisabledTests {
12705 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12706 if err != nil {
12707 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12708 os.Exit(1)
12709 }
12710
12711 if isDisabled {
12712 matched = false
12713 break
12714 }
12715 }
12716 }
12717
David Benjamin17e12922016-07-28 18:04:43 -040012718 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012719 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012720 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012721
12722 // Only run one test if repeating until failure.
12723 if *repeatUntilFailure {
12724 break
12725 }
Adam Langley95c29f32014-06-20 12:00:00 -070012726 }
12727 }
David Benjamin17e12922016-07-28 18:04:43 -040012728
David Benjamin270f0a72016-03-17 14:41:36 -040012729 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012730 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012731 os.Exit(1)
12732 }
Adam Langley95c29f32014-06-20 12:00:00 -070012733
12734 close(testChan)
12735 wg.Wait()
12736 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012737 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012738
12739 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012740
12741 if *jsonOutput != "" {
12742 if err := testOutput.writeTo(*jsonOutput); err != nil {
12743 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12744 }
12745 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012746
EKR842ae6c2016-07-27 09:22:05 +020012747 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12748 os.Exit(1)
12749 }
12750
12751 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012752 os.Exit(1)
12753 }
Adam Langley95c29f32014-06-20 12:00:00 -070012754}