blob: d53c04129e1f7ce29d00b94b28b7d1ecdf892f76 [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 Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700491 if !*useGDB {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
David Benjamin3ed59772016-03-08 12:50:21 -0500495 }
496 return t.Conn.Read(b)
497}
498
499func (t *timeoutConn) Write(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700500 if !*useGDB {
501 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
502 return 0, err
503 }
David Benjamin3ed59772016-03-08 12:50:21 -0500504 }
505 return t.Conn.Write(b)
506}
507
David Benjamin0fde2eb2017-06-30 19:11:22 -0400508func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400509 if !test.noSessionCache {
510 if config.ClientSessionCache == nil {
511 config.ClientSessionCache = NewLRUClientSessionCache(1)
512 }
513 if config.ServerSessionCache == nil {
514 config.ServerSessionCache = NewLRUServerSessionCache(1)
515 }
516 }
517 if test.testType == clientTest {
518 if len(config.Certificates) == 0 {
519 config.Certificates = []Certificate{rsaCertificate}
520 }
521 } else {
522 // Supply a ServerName to ensure a constant session cache key,
523 // rather than falling back to net.Conn.RemoteAddr.
524 if len(config.ServerName) == 0 {
525 config.ServerName = "test"
526 }
527 }
528 if *fuzzer {
529 config.Bugs.NullAllCiphers = true
530 }
David Benjamin01a90572016-09-22 00:11:43 -0400531 if *deterministic {
532 config.Time = func() time.Time { return time.Unix(1234, 1234) }
533 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400534 if test.tls13Variant != 0 {
535 config.TLS13Variant = test.tls13Variant
536 }
David Benjamine54af062016-08-08 19:21:18 -0400537
David Benjamin01784b42016-06-07 18:00:52 -0400538 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500539
David Benjamin6fd297b2014-08-11 18:43:38 -0400540 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500541 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
542 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500543 }
544
David Benjamin9867b7d2016-03-01 23:25:48 -0500545 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500546 local, peer := "client", "server"
547 if test.testType == clientTest {
548 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500549 }
David Benjaminebda9b32015-11-02 15:33:18 -0500550 connDebug := &recordingConn{
551 Conn: conn,
552 isDatagram: test.protocol == dtls,
553 local: local,
554 peer: peer,
555 }
556 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 if *flagDebug {
558 defer connDebug.WriteTo(os.Stdout)
559 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400560 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500561 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400562 path := transcriptPrefix + strconv.Itoa(num)
563 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500564 }()
565 }
David Benjaminebda9b32015-11-02 15:33:18 -0500566
567 if config.Bugs.PacketAdaptor != nil {
568 config.Bugs.PacketAdaptor.debug = connDebug
569 }
570 }
571
572 if test.replayWrites {
573 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400574 }
575
David Benjamin3ed59772016-03-08 12:50:21 -0500576 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500577 if test.damageFirstWrite {
578 connDamage = newDamageAdaptor(conn)
579 conn = connDamage
580 }
581
David Benjamin6fd297b2014-08-11 18:43:38 -0400582 if test.sendPrefix != "" {
583 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
584 return err
585 }
David Benjamin98e882e2014-08-08 13:24:34 -0400586 }
587
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400589 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSServer(conn, config)
592 } else {
593 tlsConn = Server(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 } else {
596 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400597 if test.protocol == dtls {
598 tlsConn = DTLSClient(conn, config)
599 } else {
600 tlsConn = Client(conn, config)
601 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400602 }
David Benjamin30789da2015-08-29 22:56:45 -0400603 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400604
Adam Langley95c29f32014-06-20 12:00:00 -0700605 if err := tlsConn.Handshake(); err != nil {
606 return err
607 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700608
David Benjamin01fe8202014-09-24 15:21:44 -0400609 // TODO(davidben): move all per-connection expectations into a dedicated
610 // expectations struct that can be specified separately for the two
611 // legs.
612 expectedVersion := test.expectedVersion
613 if isResume && test.expectedResumeVersion != 0 {
614 expectedVersion = test.expectedResumeVersion
615 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700616 connState := tlsConn.ConnectionState()
617 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400618 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400619 }
620
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700621 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400622 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
623 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700624 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
625 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
626 }
David Benjamin90da8c82015-04-20 14:57:57 -0400627
David Benjamina08e49d2014-08-24 01:46:07 -0400628 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700629 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400630 if channelID == nil {
631 return fmt.Errorf("no channel ID negotiated")
632 }
633 if channelID.Curve != channelIDKey.Curve ||
634 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
635 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
636 return fmt.Errorf("incorrect channel ID")
637 }
David Benjamin634f4752017-07-01 11:08:41 -0400638 } else if connState.ChannelID != nil {
639 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400640 }
641
David Benjaminae2888f2014-09-06 12:58:58 -0400642 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700643 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400644 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
645 }
646 }
647
David Benjaminc7ce9772015-10-09 19:32:41 -0400648 if test.expectNoNextProto {
649 if actual := connState.NegotiatedProtocol; actual != "" {
650 return fmt.Errorf("got unexpected next proto %s", actual)
651 }
652 }
653
David Benjaminfc7b0862014-09-06 13:21:53 -0400654 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700655 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400656 return fmt.Errorf("next proto type mismatch")
657 }
658 }
659
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700660 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500661 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
662 }
663
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100664 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300665 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100666 }
667
Paul Lietar4fac72e2015-09-09 13:44:55 +0100668 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
669 return fmt.Errorf("SCT list mismatch")
670 }
671
Nick Harper60edffd2016-06-21 15:19:24 -0700672 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
673 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400674 }
675
Steven Valdez5440fe02016-07-18 12:40:30 -0400676 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
677 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
678 }
679
David Benjamin2c516452016-11-15 10:16:54 +0900680 if test.expectPeerCertificate != nil {
681 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
682 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
683 }
684 for i, cert := range connState.PeerCertificates {
685 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
686 return fmt.Errorf("peer certificate %d did not match", i+1)
687 }
688 }
689 }
690
David Benjaminc565ebb2015-04-03 04:06:36 -0400691 if test.exportKeyingMaterial > 0 {
692 actual := make([]byte, test.exportKeyingMaterial)
693 if _, err := io.ReadFull(tlsConn, actual); err != nil {
694 return err
695 }
696 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
697 if err != nil {
698 return err
699 }
700 if !bytes.Equal(actual, expected) {
701 return fmt.Errorf("keying material mismatch")
702 }
703 }
704
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700705 if test.testTLSUnique {
706 var peersValue [12]byte
707 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
708 return err
709 }
710 expected := tlsConn.ConnectionState().TLSUnique
711 if !bytes.Equal(peersValue[:], expected) {
712 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
713 }
714 }
715
David Benjamin47921102016-07-28 11:29:18 -0400716 if test.sendHalfHelloRequest {
717 tlsConn.SendHalfHelloRequest()
718 }
719
Steven Valdeze831a812017-03-09 14:56:07 -0500720 shimPrefix := test.shimPrefix
721 if isResume {
722 shimPrefix = test.resumeShimPrefix
723 }
724 if test.shimWritesFirst || test.readWithUnfinishedWrite {
725 shimPrefix = "hello"
726 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400727 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400728 // If readWithUnfinishedWrite is set, the shim prefix will be
729 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500730 if shimPrefix != "" && !test.readWithUnfinishedWrite {
731 var buf = make([]byte, len(shimPrefix))
732 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400733 if err != nil {
734 return err
735 }
Steven Valdeze831a812017-03-09 14:56:07 -0500736 if string(buf) != shimPrefix {
737 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400738 }
Steven Valdeze831a812017-03-09 14:56:07 -0500739 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400740 }
741
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 if test.renegotiateCiphers != nil {
743 config.CipherSuites = test.renegotiateCiphers
744 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400745 for i := 0; i < test.renegotiate; i++ {
746 if err := tlsConn.Renegotiate(); err != nil {
747 return err
748 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700749 }
750 } else if test.renegotiateCiphers != nil {
751 panic("renegotiateCiphers without renegotiate")
752 }
753
David Benjamin5fa3eba2015-01-22 16:35:40 -0500754 if test.damageFirstWrite {
755 connDamage.setDamage(true)
756 tlsConn.Write([]byte("DAMAGED WRITE"))
757 connDamage.setDamage(false)
758 }
759
David Benjamin8e6db492015-07-25 18:29:23 -0400760 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700761 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400762 if test.protocol == dtls {
763 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
764 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700765 // Read until EOF.
766 _, err := io.Copy(ioutil.Discard, tlsConn)
767 return err
768 }
David Benjamin4417d052015-04-05 04:17:25 -0400769 if messageLen == 0 {
770 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700771 }
Adam Langley95c29f32014-06-20 12:00:00 -0700772
David Benjamin8e6db492015-07-25 18:29:23 -0400773 messageCount := test.messageCount
774 if messageCount == 0 {
775 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400776 }
777
David Benjamin8e6db492015-07-25 18:29:23 -0400778 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400779 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400780 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400781 }
782
David Benjamin8e6db492015-07-25 18:29:23 -0400783 for i := 0; i < test.sendEmptyRecords; i++ {
784 tlsConn.Write(nil)
785 }
786
787 for i := 0; i < test.sendWarningAlerts; i++ {
788 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
789 }
790
David Benjamin24e58862017-06-14 18:45:29 -0400791 if test.sendBogusAlertType {
792 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
793 }
794
David Benjaminbbba9392017-04-06 12:54:12 -0400795 testMessage := make([]byte, messageLen)
796 for i := range testMessage {
797 testMessage[i] = 0x42 ^ byte(j)
798 }
799 tlsConn.Write(testMessage)
800
801 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500802 if shimPrefix != "" {
803 var buf = make([]byte, len(shimPrefix))
804 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400805 if err != nil {
806 return err
807 }
Steven Valdeze831a812017-03-09 14:56:07 -0500808 if string(buf) != shimPrefix {
809 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400810 }
Steven Valdeze831a812017-03-09 14:56:07 -0500811 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400812 }
813
David Benjamin4f75aaf2015-09-01 16:53:10 -0400814 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400815 // The shim will not respond.
816 continue
817 }
818
David Benjaminbbba9392017-04-06 12:54:12 -0400819 // Process the KeyUpdate ACK. However many KeyUpdates the runner
820 // sends, the shim should respond only once.
821 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
822 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
823 return err
824 }
825 }
826
David Benjamin8e6db492015-07-25 18:29:23 -0400827 buf := make([]byte, len(testMessage))
828 if test.protocol == dtls {
829 bufTmp := make([]byte, len(buf)+1)
830 n, err := tlsConn.Read(bufTmp)
831 if err != nil {
832 return err
833 }
834 if n != len(buf) {
835 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
836 }
837 copy(buf, bufTmp)
838 } else {
839 _, err := io.ReadFull(tlsConn, buf)
840 if err != nil {
841 return err
842 }
843 }
844
845 for i, v := range buf {
846 if v != testMessage[i]^0xff {
847 return fmt.Errorf("bad reply contents at byte %d", i)
848 }
Adam Langley95c29f32014-06-20 12:00:00 -0700849 }
850 }
851
852 return nil
853}
854
David Benjamin325b5c32014-07-01 19:40:31 -0400855func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400856 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700857 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400858 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700859 }
David Benjamin325b5c32014-07-01 19:40:31 -0400860 valgrindArgs = append(valgrindArgs, path)
861 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamin325b5c32014-07-01 19:40:31 -0400866func gdbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "gdb", "--args"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700870
David Benjamin325b5c32014-07-01 19:40:31 -0400871 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700872}
873
David Benjamind16bf342015-12-18 00:53:12 -0500874func lldbOf(path string, args ...string) *exec.Cmd {
875 xtermArgs := []string{"-e", "lldb", "--"}
876 xtermArgs = append(xtermArgs, path)
877 xtermArgs = append(xtermArgs, args...)
878
879 return exec.Command("xterm", xtermArgs...)
880}
881
EKR842ae6c2016-07-27 09:22:05 +0200882var (
883 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
884 errUnimplemented = errors.New("child process does not implement needed flags")
885)
Adam Langley69a01602014-11-17 17:26:55 -0800886
David Benjamin87c8a642015-02-21 01:54:29 -0500887// accept accepts a connection from listener, unless waitChan signals a process
888// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400889func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500890 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400891 conn net.Conn
892 err error
893 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500894 }
895 connChan := make(chan connOrError, 1)
896 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400897 startTime := time.Now()
Adam Langley182b5732017-07-28 11:00:23 -0700898 if !*useGDB {
899 listener.SetDeadline(time.Now().Add(*idleTimeout))
900 }
David Benjamin87c8a642015-02-21 01:54:29 -0500901 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400902 endTime := time.Now()
903 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500904 close(connChan)
905 }()
906 select {
907 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400908 if result.err != nil {
909 // TODO(davidben): Remove this logging when
910 // https://crbug.com/boringssl/199 is resolved.
911 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
912 }
David Benjamin87c8a642015-02-21 01:54:29 -0500913 return result.conn, result.err
914 case childErr := <-waitChan:
915 waitChan <- childErr
916 return nil, fmt.Errorf("child exited early: %s", childErr)
917 }
918}
919
EKRf71d7ed2016-08-06 13:25:12 -0700920func translateExpectedError(errorStr string) string {
921 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
922 return translated
923 }
924
925 if *looseErrors {
926 return ""
927 }
928
929 return errorStr
930}
931
Adam Langley7c803a62015-06-15 15:35:05 -0700932func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400933 // Help debugging panics on the Go side.
934 defer func() {
935 if r := recover(); r != nil {
936 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
937 panic(r)
938 }
939 }()
940
Adam Langley38311732014-10-16 19:04:35 -0700941 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
942 panic("Error expected without shouldFail in " + test.name)
943 }
944
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700945 if test.expectResumeRejected && !test.resumeSession {
946 panic("expectResumeRejected without resumeSession in " + test.name)
947 }
948
Adam Langley33b1d4f2016-12-07 15:03:45 -0800949 for _, ver := range tlsVersions {
950 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
951 continue
952 }
953
David Benjamina5022392017-07-10 17:40:39 -0400954 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
955 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 -0800956 }
957
David Benjamina5022392017-07-10 17:40:39 -0400958 if ver.tls13Variant != 0 {
959 var foundFlag bool
960 for _, flag := range test.flags {
961 if flag == "-tls13-variant" {
962 foundFlag = true
963 break
964 }
965 }
966 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
967 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))
968 }
969 }
970
Adam Langley33b1d4f2016-12-07 15:03:45 -0800971 }
972
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700973 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
974 if err != nil {
975 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
976 }
David Benjamin87c8a642015-02-21 01:54:29 -0500977 if err != nil {
978 panic(err)
979 }
980 defer func() {
981 if listener != nil {
982 listener.Close()
983 }
984 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700985
David Benjamin87c8a642015-02-21 01:54:29 -0500986 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400987 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400988 flags = append(flags, "-server")
989
David Benjamin025b3d32014-07-01 19:53:04 -0400990 flags = append(flags, "-key-file")
991 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700992 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400993 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700994 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400995 }
996
997 flags = append(flags, "-cert-file")
998 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700999 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001000 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001001 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001002 }
1003 }
David Benjamin5a593af2014-08-11 19:51:50 -04001004
David Benjamin6fd297b2014-08-11 18:43:38 -04001005 if test.protocol == dtls {
1006 flags = append(flags, "-dtls")
1007 }
1008
David Benjamin46662482016-08-17 00:51:00 -04001009 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001010 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001011 resumeCount++
1012 if test.resumeRenewedSession {
1013 resumeCount++
1014 }
1015 }
1016
1017 if resumeCount > 0 {
1018 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001019 }
1020
David Benjamine58c4f52014-08-24 03:47:07 -04001021 if test.shimWritesFirst {
1022 flags = append(flags, "-shim-writes-first")
1023 }
1024
David Benjaminbbba9392017-04-06 12:54:12 -04001025 if test.readWithUnfinishedWrite {
1026 flags = append(flags, "-read-with-unfinished-write")
1027 }
1028
David Benjamin30789da2015-08-29 22:56:45 -04001029 if test.shimShutsDown {
1030 flags = append(flags, "-shim-shuts-down")
1031 }
1032
David Benjaminc565ebb2015-04-03 04:06:36 -04001033 if test.exportKeyingMaterial > 0 {
1034 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1035 flags = append(flags, "-export-label", test.exportLabel)
1036 flags = append(flags, "-export-context", test.exportContext)
1037 if test.useExportContext {
1038 flags = append(flags, "-use-export-context")
1039 }
1040 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001041 if test.expectResumeRejected {
1042 flags = append(flags, "-expect-session-miss")
1043 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001044
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001045 if test.testTLSUnique {
1046 flags = append(flags, "-tls-unique")
1047 }
1048
David Benjamina5022392017-07-10 17:40:39 -04001049 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001050 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1051 }
1052
David Benjamin0fde2eb2017-06-30 19:11:22 -04001053 var transcriptPrefix string
1054 if len(*transcriptDir) != 0 {
1055 protocol := "tls"
1056 if test.protocol == dtls {
1057 protocol = "dtls"
1058 }
1059
1060 side := "client"
1061 if test.testType == serverTest {
1062 side = "server"
1063 }
1064
1065 dir := filepath.Join(*transcriptDir, protocol, side)
1066 if err := os.MkdirAll(dir, 0755); err != nil {
1067 return err
1068 }
1069 transcriptPrefix = filepath.Join(dir, test.name+"-")
1070 flags = append(flags, "-write-settings", transcriptPrefix)
1071 }
1072
David Benjamin025b3d32014-07-01 19:53:04 -04001073 flags = append(flags, test.flags...)
1074
1075 var shim *exec.Cmd
1076 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001077 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001078 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001079 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001080 } else if *useLLDB {
1081 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001082 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001083 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001084 }
David Benjamin025b3d32014-07-01 19:53:04 -04001085 shim.Stdin = os.Stdin
1086 var stdoutBuf, stderrBuf bytes.Buffer
1087 shim.Stdout = &stdoutBuf
1088 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001089 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001090 shim.Env = os.Environ()
1091 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001092 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001093 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001094 }
1095 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1096 }
David Benjamin025b3d32014-07-01 19:53:04 -04001097
1098 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001099 panic(err)
1100 }
David Benjamin87c8a642015-02-21 01:54:29 -05001101 waitChan := make(chan error, 1)
1102 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001103
1104 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001105
David Benjamin7a4aaa42016-09-20 17:58:14 -04001106 if *deterministic {
1107 config.Rand = &deterministicRand{}
1108 }
1109
David Benjamin87c8a642015-02-21 01:54:29 -05001110 conn, err := acceptOrWait(listener, waitChan)
1111 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001112 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001113 conn.Close()
1114 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001115
David Benjamin46662482016-08-17 00:51:00 -04001116 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001117 var resumeConfig Config
1118 if test.resumeConfig != nil {
1119 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001120 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001121 resumeConfig.SessionTicketKey = config.SessionTicketKey
1122 resumeConfig.ClientSessionCache = config.ClientSessionCache
1123 resumeConfig.ServerSessionCache = config.ServerSessionCache
1124 }
David Benjamin2e045a92016-06-08 13:09:56 -04001125 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001126 } else {
1127 resumeConfig = config
1128 }
David Benjamin87c8a642015-02-21 01:54:29 -05001129 var connResume net.Conn
1130 connResume, err = acceptOrWait(listener, waitChan)
1131 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001132 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001133 connResume.Close()
1134 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001135 }
1136
David Benjamin87c8a642015-02-21 01:54:29 -05001137 // Close the listener now. This is to avoid hangs should the shim try to
1138 // open more connections than expected.
1139 listener.Close()
1140 listener = nil
1141
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001142 var shimKilledLock sync.Mutex
1143 var shimKilled bool
1144 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1145 shimKilledLock.Lock()
1146 shimKilled = true
1147 shimKilledLock.Unlock()
1148 shim.Process.Kill()
1149 })
David Benjamin87c8a642015-02-21 01:54:29 -05001150 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001151 waitTimeout.Stop()
1152 shimKilledLock.Lock()
1153 if shimKilled && err == nil {
1154 err = errors.New("timeout waiting for the shim to exit.")
1155 }
1156 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001157 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001158 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001159 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1160 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001161 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001162 case 89:
1163 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001164 case 99:
1165 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001166 }
1167 }
Adam Langley95c29f32014-06-20 12:00:00 -07001168
David Benjamin9bea3492016-03-02 10:59:16 -05001169 // Account for Windows line endings.
1170 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1171 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001172
1173 // Separate the errors from the shim and those from tools like
1174 // AddressSanitizer.
1175 var extraStderr string
1176 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1177 stderr = stderrParts[0]
1178 extraStderr = stderrParts[1]
1179 }
1180
Adam Langley95c29f32014-06-20 12:00:00 -07001181 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001182 expectedError := translateExpectedError(test.expectedError)
1183 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001184
Adam Langleyac61fa32014-06-23 12:03:11 -07001185 localError := "none"
1186 if err != nil {
1187 localError = err.Error()
1188 }
1189 if len(test.expectedLocalError) != 0 {
1190 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1191 }
Adam Langley95c29f32014-06-20 12:00:00 -07001192
1193 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001194 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001195 if childErr != nil {
1196 childError = childErr.Error()
1197 }
1198
1199 var msg string
1200 switch {
1201 case failed && !test.shouldFail:
1202 msg = "unexpected failure"
1203 case !failed && test.shouldFail:
1204 msg = "unexpected success"
1205 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001206 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001207 default:
1208 panic("internal error")
1209 }
1210
David Benjamin9aafb642016-09-20 19:36:53 -04001211 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 -07001212 }
1213
David Benjamind2ba8892016-09-20 19:41:04 -04001214 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001215 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001216 }
1217
David Benjamind2ba8892016-09-20 19:41:04 -04001218 if *useValgrind && isValgrindError {
1219 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1220 }
1221
Adam Langley95c29f32014-06-20 12:00:00 -07001222 return nil
1223}
1224
David Benjaminaa012042016-12-10 13:33:05 -05001225type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001226 name string
1227 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001228 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001229 // excludeFlag is the legacy shim flag to disable the version.
1230 excludeFlag string
1231 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001232 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1233 versionDTLS uint16
1234 // versionWire, if non-zero, is the wire representation of the
1235 // version. Otherwise the wire version is the protocol version or
1236 // versionDTLS.
1237 versionWire uint16
1238 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001239}
1240
1241func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001242 // The shim uses the protocol version in its public API, but uses the
1243 // DTLS-specific version if it exists.
1244 if protocol == dtls && vers.versionDTLS != 0 {
1245 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001246 }
Steven Valdez520e1222017-06-13 12:45:25 -04001247 return strconv.Itoa(int(vers.version))
1248}
1249
1250func (vers tlsVersion) wire(protocol protocol) uint16 {
1251 if protocol == dtls && vers.versionDTLS != 0 {
1252 return vers.versionDTLS
1253 }
1254 if vers.versionWire != 0 {
1255 return vers.versionWire
1256 }
1257 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001258}
1259
1260var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001261 {
1262 name: "SSL3",
1263 version: VersionSSL30,
1264 excludeFlag: "-no-ssl3",
1265 },
1266 {
1267 name: "TLS1",
1268 version: VersionTLS10,
1269 excludeFlag: "-no-tls1",
1270 hasDTLS: true,
1271 versionDTLS: VersionDTLS10,
1272 },
1273 {
1274 name: "TLS11",
1275 version: VersionTLS11,
1276 excludeFlag: "-no-tls11",
1277 },
1278 {
1279 name: "TLS12",
1280 version: VersionTLS12,
1281 excludeFlag: "-no-tls12",
1282 hasDTLS: true,
1283 versionDTLS: VersionDTLS12,
1284 },
1285 {
1286 name: "TLS13",
1287 version: VersionTLS13,
1288 excludeFlag: "-no-tls13",
1289 versionWire: tls13DraftVersion,
1290 tls13Variant: TLS13Default,
1291 },
1292 {
1293 name: "TLS13Experiment",
1294 version: VersionTLS13,
1295 excludeFlag: "-no-tls13",
1296 versionWire: tls13ExperimentVersion,
1297 tls13Variant: TLS13Experiment,
1298 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001299 {
1300 name: "TLS13RecordTypeExperiment",
1301 version: VersionTLS13,
1302 excludeFlag: "-no-tls13",
1303 versionWire: tls13RecordTypeExperimentVersion,
1304 tls13Variant: TLS13RecordTypeExperiment,
1305 },
Steven Valdez520e1222017-06-13 12:45:25 -04001306}
1307
1308func allVersions(protocol protocol) []tlsVersion {
1309 if protocol == tls {
1310 return tlsVersions
1311 }
1312
1313 var ret []tlsVersion
1314 for _, vers := range tlsVersions {
1315 if vers.hasDTLS {
1316 ret = append(ret, vers)
1317 }
1318 }
1319 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001320}
1321
David Benjaminaa012042016-12-10 13:33:05 -05001322type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001323 name string
1324 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001325}
1326
1327var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001328 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001329 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001330 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001332 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001333 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001334 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001335 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1336 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001337 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1338 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001339 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001340 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001341 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001342 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001343 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001344 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001345 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001346 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001347 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001348 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001349 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1350 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001351 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1352 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001353 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001354 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1355 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1356 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001357 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001358}
1359
David Benjamin8b8c0062014-11-23 02:47:52 -05001360func hasComponent(suiteName, component string) bool {
1361 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1362}
1363
David Benjaminf7768e42014-08-31 02:06:47 -04001364func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001365 return hasComponent(suiteName, "GCM") ||
1366 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001367 hasComponent(suiteName, "SHA384") ||
1368 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001369}
1370
Nick Harper1fd39d82016-06-14 18:14:35 -07001371func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001372 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001373}
1374
David Benjamin8b8c0062014-11-23 02:47:52 -05001375func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001376 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001377}
1378
Adam Langleya7997f12015-05-14 17:38:50 -07001379func bigFromHex(hex string) *big.Int {
1380 ret, ok := new(big.Int).SetString(hex, 16)
1381 if !ok {
1382 panic("failed to parse hex number 0x" + hex)
1383 }
1384 return ret
1385}
1386
Adam Langley7c803a62015-06-15 15:35:05 -07001387func addBasicTests() {
1388 basicTests := []testCase{
1389 {
Adam Langley7c803a62015-06-15 15:35:05 -07001390 name: "NoFallbackSCSV",
1391 config: Config{
1392 Bugs: ProtocolBugs{
1393 FailIfNotFallbackSCSV: true,
1394 },
1395 },
1396 shouldFail: true,
1397 expectedLocalError: "no fallback SCSV found",
1398 },
1399 {
1400 name: "SendFallbackSCSV",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 FailIfNotFallbackSCSV: true,
1404 },
1405 },
1406 flags: []string{"-fallback-scsv"},
1407 },
1408 {
1409 name: "ClientCertificateTypes",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 ClientAuth: RequestClientCert,
1413 ClientCertificateTypes: []byte{
1414 CertTypeDSSSign,
1415 CertTypeRSASign,
1416 CertTypeECDSASign,
1417 },
1418 },
1419 flags: []string{
1420 "-expect-certificate-types",
1421 base64.StdEncoding.EncodeToString([]byte{
1422 CertTypeDSSSign,
1423 CertTypeRSASign,
1424 CertTypeECDSASign,
1425 }),
1426 },
1427 },
1428 {
Adam Langley7c803a62015-06-15 15:35:05 -07001429 name: "UnauthenticatedECDH",
1430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001431 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001432 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1433 Bugs: ProtocolBugs{
1434 UnauthenticatedECDH: true,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":UNEXPECTED_MESSAGE:",
1439 },
1440 {
1441 name: "SkipCertificateStatus",
1442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001443 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Bugs: ProtocolBugs{
1446 SkipCertificateStatus: true,
1447 },
1448 },
1449 flags: []string{
1450 "-enable-ocsp-stapling",
1451 },
1452 },
1453 {
1454 name: "SkipServerKeyExchange",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 SkipServerKeyExchange: true,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":UNEXPECTED_MESSAGE:",
1464 },
1465 {
Adam Langley7c803a62015-06-15 15:35:05 -07001466 testType: serverTest,
1467 name: "Alert",
1468 config: Config{
1469 Bugs: ProtocolBugs{
1470 SendSpuriousAlert: alertRecordOverflow,
1471 },
1472 },
1473 shouldFail: true,
1474 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1475 },
1476 {
1477 protocol: dtls,
1478 testType: serverTest,
1479 name: "Alert-DTLS",
1480 config: Config{
1481 Bugs: ProtocolBugs{
1482 SendSpuriousAlert: alertRecordOverflow,
1483 },
1484 },
1485 shouldFail: true,
1486 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1487 },
1488 {
1489 testType: serverTest,
1490 name: "FragmentAlert",
1491 config: Config{
1492 Bugs: ProtocolBugs{
1493 FragmentAlert: true,
1494 SendSpuriousAlert: alertRecordOverflow,
1495 },
1496 },
1497 shouldFail: true,
1498 expectedError: ":BAD_ALERT:",
1499 },
1500 {
1501 protocol: dtls,
1502 testType: serverTest,
1503 name: "FragmentAlert-DTLS",
1504 config: Config{
1505 Bugs: ProtocolBugs{
1506 FragmentAlert: true,
1507 SendSpuriousAlert: alertRecordOverflow,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":BAD_ALERT:",
1512 },
1513 {
1514 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001515 name: "DoubleAlert",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 DoubleAlert: true,
1519 SendSpuriousAlert: alertRecordOverflow,
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":BAD_ALERT:",
1524 },
1525 {
1526 protocol: dtls,
1527 testType: serverTest,
1528 name: "DoubleAlert-DTLS",
1529 config: Config{
1530 Bugs: ProtocolBugs{
1531 DoubleAlert: true,
1532 SendSpuriousAlert: alertRecordOverflow,
1533 },
1534 },
1535 shouldFail: true,
1536 expectedError: ":BAD_ALERT:",
1537 },
1538 {
Adam Langley7c803a62015-06-15 15:35:05 -07001539 name: "SkipNewSessionTicket",
1540 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001541 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001542 Bugs: ProtocolBugs{
1543 SkipNewSessionTicket: true,
1544 },
1545 },
1546 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001547 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001548 },
1549 {
1550 testType: serverTest,
1551 name: "FallbackSCSV",
1552 config: Config{
1553 MaxVersion: VersionTLS11,
1554 Bugs: ProtocolBugs{
1555 SendFallbackSCSV: true,
1556 },
1557 },
David Benjamin56cadc32016-12-16 19:54:11 -05001558 shouldFail: true,
1559 expectedError: ":INAPPROPRIATE_FALLBACK:",
1560 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001561 },
1562 {
1563 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001564 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001565 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001566 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001567 Bugs: ProtocolBugs{
1568 SendFallbackSCSV: true,
1569 },
1570 },
1571 },
1572 {
1573 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 name: "FallbackSCSV-VersionMatch-TLS12",
1575 config: Config{
1576 MaxVersion: VersionTLS12,
1577 Bugs: ProtocolBugs{
1578 SendFallbackSCSV: true,
1579 },
1580 },
1581 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1582 },
1583 {
1584 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001585 name: "FragmentedClientVersion",
1586 config: Config{
1587 Bugs: ProtocolBugs{
1588 MaxHandshakeRecordLength: 1,
1589 FragmentClientVersion: true,
1590 },
1591 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001592 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001593 },
1594 {
Adam Langley7c803a62015-06-15 15:35:05 -07001595 testType: serverTest,
1596 name: "HttpGET",
1597 sendPrefix: "GET / HTTP/1.0\n",
1598 shouldFail: true,
1599 expectedError: ":HTTP_REQUEST:",
1600 },
1601 {
1602 testType: serverTest,
1603 name: "HttpPOST",
1604 sendPrefix: "POST / HTTP/1.0\n",
1605 shouldFail: true,
1606 expectedError: ":HTTP_REQUEST:",
1607 },
1608 {
1609 testType: serverTest,
1610 name: "HttpHEAD",
1611 sendPrefix: "HEAD / HTTP/1.0\n",
1612 shouldFail: true,
1613 expectedError: ":HTTP_REQUEST:",
1614 },
1615 {
1616 testType: serverTest,
1617 name: "HttpPUT",
1618 sendPrefix: "PUT / HTTP/1.0\n",
1619 shouldFail: true,
1620 expectedError: ":HTTP_REQUEST:",
1621 },
1622 {
1623 testType: serverTest,
1624 name: "HttpCONNECT",
1625 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1626 shouldFail: true,
1627 expectedError: ":HTTPS_PROXY_REQUEST:",
1628 },
1629 {
1630 testType: serverTest,
1631 name: "Garbage",
1632 sendPrefix: "blah",
1633 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001634 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001635 },
1636 {
Adam Langley7c803a62015-06-15 15:35:05 -07001637 name: "RSAEphemeralKey",
1638 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001639 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001640 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1641 Bugs: ProtocolBugs{
1642 RSAEphemeralKey: true,
1643 },
1644 },
1645 shouldFail: true,
1646 expectedError: ":UNEXPECTED_MESSAGE:",
1647 },
1648 {
1649 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001650 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001651 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001652 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001653 },
1654 {
1655 protocol: dtls,
1656 name: "DisableEverything-DTLS",
1657 flags: []string{"-no-tls12", "-no-tls1"},
1658 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001659 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001660 },
1661 {
Adam Langley7c803a62015-06-15 15:35:05 -07001662 protocol: dtls,
1663 testType: serverTest,
1664 name: "MTU",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 MaxPacketLength: 256,
1668 },
1669 },
1670 flags: []string{"-mtu", "256"},
1671 },
1672 {
1673 protocol: dtls,
1674 testType: serverTest,
1675 name: "MTUExceeded",
1676 config: Config{
1677 Bugs: ProtocolBugs{
1678 MaxPacketLength: 255,
1679 },
1680 },
1681 flags: []string{"-mtu", "256"},
1682 shouldFail: true,
1683 expectedLocalError: "dtls: exceeded maximum packet length",
1684 },
1685 {
Adam Langley7c803a62015-06-15 15:35:05 -07001686 name: "EmptyCertificateList",
1687 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001688 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001689 Bugs: ProtocolBugs{
1690 EmptyCertificateList: true,
1691 },
1692 },
1693 shouldFail: true,
1694 expectedError: ":DECODE_ERROR:",
1695 },
1696 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001697 name: "EmptyCertificateList-TLS13",
1698 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001699 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001700 Bugs: ProtocolBugs{
1701 EmptyCertificateList: true,
1702 },
1703 },
1704 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001705 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001706 },
1707 {
Adam Langley7c803a62015-06-15 15:35:05 -07001708 name: "TLSFatalBadPackets",
1709 damageFirstWrite: true,
1710 shouldFail: true,
1711 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1712 },
1713 {
1714 protocol: dtls,
1715 name: "DTLSIgnoreBadPackets",
1716 damageFirstWrite: true,
1717 },
1718 {
1719 protocol: dtls,
1720 name: "DTLSIgnoreBadPackets-Async",
1721 damageFirstWrite: true,
1722 flags: []string{"-async"},
1723 },
1724 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001725 name: "AppDataBeforeHandshake",
1726 config: Config{
1727 Bugs: ProtocolBugs{
1728 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1729 },
1730 },
1731 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001732 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001733 },
1734 {
1735 name: "AppDataBeforeHandshake-Empty",
1736 config: Config{
1737 Bugs: ProtocolBugs{
1738 AppDataBeforeHandshake: []byte{},
1739 },
1740 },
1741 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001742 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001743 },
1744 {
1745 protocol: dtls,
1746 name: "AppDataBeforeHandshake-DTLS",
1747 config: Config{
1748 Bugs: ProtocolBugs{
1749 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1750 },
1751 },
1752 shouldFail: true,
1753 expectedError: ":UNEXPECTED_RECORD:",
1754 },
1755 {
1756 protocol: dtls,
1757 name: "AppDataBeforeHandshake-DTLS-Empty",
1758 config: Config{
1759 Bugs: ProtocolBugs{
1760 AppDataBeforeHandshake: []byte{},
1761 },
1762 },
1763 shouldFail: true,
1764 expectedError: ":UNEXPECTED_RECORD:",
1765 },
1766 {
Adam Langley7c803a62015-06-15 15:35:05 -07001767 name: "AppDataAfterChangeCipherSpec",
1768 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001769 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001770 Bugs: ProtocolBugs{
1771 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1772 },
1773 },
1774 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001775 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001776 },
1777 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001778 name: "AppDataAfterChangeCipherSpec-Empty",
1779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001780 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001781 Bugs: ProtocolBugs{
1782 AppDataAfterChangeCipherSpec: []byte{},
1783 },
1784 },
1785 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001786 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001787 },
1788 {
Adam Langley7c803a62015-06-15 15:35:05 -07001789 protocol: dtls,
1790 name: "AppDataAfterChangeCipherSpec-DTLS",
1791 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001792 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001793 Bugs: ProtocolBugs{
1794 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1795 },
1796 },
1797 // BoringSSL's DTLS implementation will drop the out-of-order
1798 // application data.
1799 },
1800 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001801 protocol: dtls,
1802 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001804 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001805 Bugs: ProtocolBugs{
1806 AppDataAfterChangeCipherSpec: []byte{},
1807 },
1808 },
1809 // BoringSSL's DTLS implementation will drop the out-of-order
1810 // application data.
1811 },
1812 {
Adam Langley7c803a62015-06-15 15:35:05 -07001813 name: "AlertAfterChangeCipherSpec",
1814 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001815 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001816 Bugs: ProtocolBugs{
1817 AlertAfterChangeCipherSpec: alertRecordOverflow,
1818 },
1819 },
1820 shouldFail: true,
1821 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1822 },
1823 {
1824 protocol: dtls,
1825 name: "AlertAfterChangeCipherSpec-DTLS",
1826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001827 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001828 Bugs: ProtocolBugs{
1829 AlertAfterChangeCipherSpec: alertRecordOverflow,
1830 },
1831 },
1832 shouldFail: true,
1833 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1834 },
1835 {
1836 protocol: dtls,
1837 name: "ReorderHandshakeFragments-Small-DTLS",
1838 config: Config{
1839 Bugs: ProtocolBugs{
1840 ReorderHandshakeFragments: true,
1841 // Small enough that every handshake message is
1842 // fragmented.
1843 MaxHandshakeRecordLength: 2,
1844 },
1845 },
1846 },
1847 {
1848 protocol: dtls,
1849 name: "ReorderHandshakeFragments-Large-DTLS",
1850 config: Config{
1851 Bugs: ProtocolBugs{
1852 ReorderHandshakeFragments: true,
1853 // Large enough that no handshake message is
1854 // fragmented.
1855 MaxHandshakeRecordLength: 2048,
1856 },
1857 },
1858 },
1859 {
1860 protocol: dtls,
1861 name: "MixCompleteMessageWithFragments-DTLS",
1862 config: Config{
1863 Bugs: ProtocolBugs{
1864 ReorderHandshakeFragments: true,
1865 MixCompleteMessageWithFragments: true,
1866 MaxHandshakeRecordLength: 2,
1867 },
1868 },
1869 },
1870 {
1871 name: "SendInvalidRecordType",
1872 config: Config{
1873 Bugs: ProtocolBugs{
1874 SendInvalidRecordType: true,
1875 },
1876 },
1877 shouldFail: true,
1878 expectedError: ":UNEXPECTED_RECORD:",
1879 },
1880 {
1881 protocol: dtls,
1882 name: "SendInvalidRecordType-DTLS",
1883 config: Config{
1884 Bugs: ProtocolBugs{
1885 SendInvalidRecordType: true,
1886 },
1887 },
1888 shouldFail: true,
1889 expectedError: ":UNEXPECTED_RECORD:",
1890 },
1891 {
1892 name: "FalseStart-SkipServerSecondLeg",
1893 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001894 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001895 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1896 NextProtos: []string{"foo"},
1897 Bugs: ProtocolBugs{
1898 SkipNewSessionTicket: true,
1899 SkipChangeCipherSpec: true,
1900 SkipFinished: true,
1901 ExpectFalseStart: true,
1902 },
1903 },
1904 flags: []string{
1905 "-false-start",
1906 "-handshake-never-done",
1907 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001908 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001909 },
1910 shimWritesFirst: true,
1911 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001912 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001913 },
1914 {
1915 name: "FalseStart-SkipServerSecondLeg-Implicit",
1916 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001917 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1919 NextProtos: []string{"foo"},
1920 Bugs: ProtocolBugs{
1921 SkipNewSessionTicket: true,
1922 SkipChangeCipherSpec: true,
1923 SkipFinished: true,
1924 },
1925 },
1926 flags: []string{
1927 "-implicit-handshake",
1928 "-false-start",
1929 "-handshake-never-done",
1930 "-advertise-alpn", "\x03foo",
1931 },
1932 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001933 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001934 },
1935 {
1936 testType: serverTest,
1937 name: "FailEarlyCallback",
1938 flags: []string{"-fail-early-callback"},
1939 shouldFail: true,
1940 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001941 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001942 },
1943 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001944 name: "FailCertCallback-Client-TLS12",
1945 config: Config{
1946 MaxVersion: VersionTLS12,
1947 ClientAuth: RequestClientCert,
1948 },
1949 flags: []string{"-fail-cert-callback"},
1950 shouldFail: true,
1951 expectedError: ":CERT_CB_ERROR:",
1952 expectedLocalError: "remote error: internal error",
1953 },
1954 {
1955 testType: serverTest,
1956 name: "FailCertCallback-Server-TLS12",
1957 config: Config{
1958 MaxVersion: VersionTLS12,
1959 },
1960 flags: []string{"-fail-cert-callback"},
1961 shouldFail: true,
1962 expectedError: ":CERT_CB_ERROR:",
1963 expectedLocalError: "remote error: internal error",
1964 },
1965 {
1966 name: "FailCertCallback-Client-TLS13",
1967 config: Config{
1968 MaxVersion: VersionTLS13,
1969 ClientAuth: RequestClientCert,
1970 },
1971 flags: []string{"-fail-cert-callback"},
1972 shouldFail: true,
1973 expectedError: ":CERT_CB_ERROR:",
1974 expectedLocalError: "remote error: internal error",
1975 },
1976 {
1977 testType: serverTest,
1978 name: "FailCertCallback-Server-TLS13",
1979 config: Config{
1980 MaxVersion: VersionTLS13,
1981 },
1982 flags: []string{"-fail-cert-callback"},
1983 shouldFail: true,
1984 expectedError: ":CERT_CB_ERROR:",
1985 expectedLocalError: "remote error: internal error",
1986 },
1987 {
Adam Langley7c803a62015-06-15 15:35:05 -07001988 protocol: dtls,
1989 name: "FragmentMessageTypeMismatch-DTLS",
1990 config: Config{
1991 Bugs: ProtocolBugs{
1992 MaxHandshakeRecordLength: 2,
1993 FragmentMessageTypeMismatch: true,
1994 },
1995 },
1996 shouldFail: true,
1997 expectedError: ":FRAGMENT_MISMATCH:",
1998 },
1999 {
2000 protocol: dtls,
2001 name: "FragmentMessageLengthMismatch-DTLS",
2002 config: Config{
2003 Bugs: ProtocolBugs{
2004 MaxHandshakeRecordLength: 2,
2005 FragmentMessageLengthMismatch: true,
2006 },
2007 },
2008 shouldFail: true,
2009 expectedError: ":FRAGMENT_MISMATCH:",
2010 },
2011 {
2012 protocol: dtls,
2013 name: "SplitFragments-Header-DTLS",
2014 config: Config{
2015 Bugs: ProtocolBugs{
2016 SplitFragments: 2,
2017 },
2018 },
2019 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002020 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002021 },
2022 {
2023 protocol: dtls,
2024 name: "SplitFragments-Boundary-DTLS",
2025 config: Config{
2026 Bugs: ProtocolBugs{
2027 SplitFragments: dtlsRecordHeaderLen,
2028 },
2029 },
2030 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002031 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002032 },
2033 {
2034 protocol: dtls,
2035 name: "SplitFragments-Body-DTLS",
2036 config: Config{
2037 Bugs: ProtocolBugs{
2038 SplitFragments: dtlsRecordHeaderLen + 1,
2039 },
2040 },
2041 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002042 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002043 },
2044 {
2045 protocol: dtls,
2046 name: "SendEmptyFragments-DTLS",
2047 config: Config{
2048 Bugs: ProtocolBugs{
2049 SendEmptyFragments: true,
2050 },
2051 },
2052 },
2053 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002054 name: "BadFinished-Client",
2055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002056 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002057 Bugs: ProtocolBugs{
2058 BadFinished: true,
2059 },
2060 },
2061 shouldFail: true,
2062 expectedError: ":DIGEST_CHECK_FAILED:",
2063 },
2064 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002065 name: "BadFinished-Client-TLS13",
2066 config: Config{
2067 MaxVersion: VersionTLS13,
2068 Bugs: ProtocolBugs{
2069 BadFinished: true,
2070 },
2071 },
2072 shouldFail: true,
2073 expectedError: ":DIGEST_CHECK_FAILED:",
2074 },
2075 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002076 testType: serverTest,
2077 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002079 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002080 Bugs: ProtocolBugs{
2081 BadFinished: true,
2082 },
2083 },
2084 shouldFail: true,
2085 expectedError: ":DIGEST_CHECK_FAILED:",
2086 },
2087 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002088 testType: serverTest,
2089 name: "BadFinished-Server-TLS13",
2090 config: Config{
2091 MaxVersion: VersionTLS13,
2092 Bugs: ProtocolBugs{
2093 BadFinished: true,
2094 },
2095 },
2096 shouldFail: true,
2097 expectedError: ":DIGEST_CHECK_FAILED:",
2098 },
2099 {
Adam Langley7c803a62015-06-15 15:35:05 -07002100 name: "FalseStart-BadFinished",
2101 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002102 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002103 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2104 NextProtos: []string{"foo"},
2105 Bugs: ProtocolBugs{
2106 BadFinished: true,
2107 ExpectFalseStart: true,
2108 },
2109 },
2110 flags: []string{
2111 "-false-start",
2112 "-handshake-never-done",
2113 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002114 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002115 },
2116 shimWritesFirst: true,
2117 shouldFail: true,
2118 expectedError: ":DIGEST_CHECK_FAILED:",
2119 },
2120 {
2121 name: "NoFalseStart-NoALPN",
2122 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002123 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002124 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2125 Bugs: ProtocolBugs{
2126 ExpectFalseStart: true,
2127 AlertBeforeFalseStartTest: alertAccessDenied,
2128 },
2129 },
2130 flags: []string{
2131 "-false-start",
2132 },
2133 shimWritesFirst: true,
2134 shouldFail: true,
2135 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2136 expectedLocalError: "tls: peer did not false start: EOF",
2137 },
2138 {
2139 name: "NoFalseStart-NoAEAD",
2140 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002141 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002142 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2143 NextProtos: []string{"foo"},
2144 Bugs: ProtocolBugs{
2145 ExpectFalseStart: true,
2146 AlertBeforeFalseStartTest: alertAccessDenied,
2147 },
2148 },
2149 flags: []string{
2150 "-false-start",
2151 "-advertise-alpn", "\x03foo",
2152 },
2153 shimWritesFirst: true,
2154 shouldFail: true,
2155 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2156 expectedLocalError: "tls: peer did not false start: EOF",
2157 },
2158 {
2159 name: "NoFalseStart-RSA",
2160 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002161 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002162 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2163 NextProtos: []string{"foo"},
2164 Bugs: ProtocolBugs{
2165 ExpectFalseStart: true,
2166 AlertBeforeFalseStartTest: alertAccessDenied,
2167 },
2168 },
2169 flags: []string{
2170 "-false-start",
2171 "-advertise-alpn", "\x03foo",
2172 },
2173 shimWritesFirst: true,
2174 shouldFail: true,
2175 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2176 expectedLocalError: "tls: peer did not false start: EOF",
2177 },
2178 {
Adam Langley7c803a62015-06-15 15:35:05 -07002179 protocol: dtls,
2180 name: "SendSplitAlert-Sync",
2181 config: Config{
2182 Bugs: ProtocolBugs{
2183 SendSplitAlert: true,
2184 },
2185 },
2186 },
2187 {
2188 protocol: dtls,
2189 name: "SendSplitAlert-Async",
2190 config: Config{
2191 Bugs: ProtocolBugs{
2192 SendSplitAlert: true,
2193 },
2194 },
2195 flags: []string{"-async"},
2196 },
2197 {
2198 protocol: dtls,
2199 name: "PackDTLSHandshake",
2200 config: Config{
2201 Bugs: ProtocolBugs{
2202 MaxHandshakeRecordLength: 2,
2203 PackHandshakeFragments: 20,
2204 PackHandshakeRecords: 200,
2205 },
2206 },
2207 },
2208 {
Adam Langley7c803a62015-06-15 15:35:05 -07002209 name: "SendEmptyRecords-Pass",
2210 sendEmptyRecords: 32,
2211 },
2212 {
2213 name: "SendEmptyRecords",
2214 sendEmptyRecords: 33,
2215 shouldFail: true,
2216 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2217 },
2218 {
2219 name: "SendEmptyRecords-Async",
2220 sendEmptyRecords: 33,
2221 flags: []string{"-async"},
2222 shouldFail: true,
2223 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2224 },
2225 {
David Benjamine8e84b92016-08-03 15:39:47 -04002226 name: "SendWarningAlerts-Pass",
2227 config: Config{
2228 MaxVersion: VersionTLS12,
2229 },
Adam Langley7c803a62015-06-15 15:35:05 -07002230 sendWarningAlerts: 4,
2231 },
2232 {
David Benjamine8e84b92016-08-03 15:39:47 -04002233 protocol: dtls,
2234 name: "SendWarningAlerts-DTLS-Pass",
2235 config: Config{
2236 MaxVersion: VersionTLS12,
2237 },
Adam Langley7c803a62015-06-15 15:35:05 -07002238 sendWarningAlerts: 4,
2239 },
2240 {
David Benjamine8e84b92016-08-03 15:39:47 -04002241 name: "SendWarningAlerts-TLS13",
2242 config: Config{
2243 MaxVersion: VersionTLS13,
2244 },
2245 sendWarningAlerts: 4,
2246 shouldFail: true,
2247 expectedError: ":BAD_ALERT:",
2248 expectedLocalError: "remote error: error decoding message",
2249 },
2250 {
2251 name: "SendWarningAlerts",
2252 config: Config{
2253 MaxVersion: VersionTLS12,
2254 },
Adam Langley7c803a62015-06-15 15:35:05 -07002255 sendWarningAlerts: 5,
2256 shouldFail: true,
2257 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2258 },
2259 {
David Benjamine8e84b92016-08-03 15:39:47 -04002260 name: "SendWarningAlerts-Async",
2261 config: Config{
2262 MaxVersion: VersionTLS12,
2263 },
Adam Langley7c803a62015-06-15 15:35:05 -07002264 sendWarningAlerts: 5,
2265 flags: []string{"-async"},
2266 shouldFail: true,
2267 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2268 },
David Benjaminba4594a2015-06-18 18:36:15 -04002269 {
David Benjamin24e58862017-06-14 18:45:29 -04002270 name: "SendBogusAlertType",
2271 sendBogusAlertType: true,
2272 shouldFail: true,
2273 expectedError: ":UNKNOWN_ALERT_TYPE:",
2274 expectedLocalError: "remote error: illegal parameter",
2275 },
2276 {
2277 protocol: dtls,
2278 name: "SendBogusAlertType-DTLS",
2279 sendBogusAlertType: true,
2280 shouldFail: true,
2281 expectedError: ":UNKNOWN_ALERT_TYPE:",
2282 expectedLocalError: "remote error: illegal parameter",
2283 },
2284 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002285 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002286 config: Config{
2287 MaxVersion: VersionTLS13,
2288 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002289 sendKeyUpdates: 33,
2290 keyUpdateRequest: keyUpdateNotRequested,
2291 shouldFail: true,
2292 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002293 },
2294 {
David Benjaminba4594a2015-06-18 18:36:15 -04002295 name: "EmptySessionID",
2296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002297 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002298 SessionTicketsDisabled: true,
2299 },
2300 noSessionCache: true,
2301 flags: []string{"-expect-no-session"},
2302 },
David Benjamin30789da2015-08-29 22:56:45 -04002303 {
2304 name: "Unclean-Shutdown",
2305 config: Config{
2306 Bugs: ProtocolBugs{
2307 NoCloseNotify: true,
2308 ExpectCloseNotify: true,
2309 },
2310 },
2311 shimShutsDown: true,
2312 flags: []string{"-check-close-notify"},
2313 shouldFail: true,
2314 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2315 },
2316 {
2317 name: "Unclean-Shutdown-Ignored",
2318 config: Config{
2319 Bugs: ProtocolBugs{
2320 NoCloseNotify: true,
2321 },
2322 },
2323 shimShutsDown: true,
2324 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002325 {
David Benjaminfa214e42016-05-10 17:03:10 -04002326 name: "Unclean-Shutdown-Alert",
2327 config: Config{
2328 Bugs: ProtocolBugs{
2329 SendAlertOnShutdown: alertDecompressionFailure,
2330 ExpectCloseNotify: true,
2331 },
2332 },
2333 shimShutsDown: true,
2334 flags: []string{"-check-close-notify"},
2335 shouldFail: true,
2336 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2337 },
2338 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002339 name: "LargePlaintext",
2340 config: Config{
2341 Bugs: ProtocolBugs{
2342 SendLargeRecords: true,
2343 },
2344 },
2345 messageLen: maxPlaintext + 1,
2346 shouldFail: true,
2347 expectedError: ":DATA_LENGTH_TOO_LONG:",
2348 },
2349 {
2350 protocol: dtls,
2351 name: "LargePlaintext-DTLS",
2352 config: Config{
2353 Bugs: ProtocolBugs{
2354 SendLargeRecords: true,
2355 },
2356 },
2357 messageLen: maxPlaintext + 1,
2358 shouldFail: true,
2359 expectedError: ":DATA_LENGTH_TOO_LONG:",
2360 },
2361 {
2362 name: "LargeCiphertext",
2363 config: Config{
2364 Bugs: ProtocolBugs{
2365 SendLargeRecords: true,
2366 },
2367 },
2368 messageLen: maxPlaintext * 2,
2369 shouldFail: true,
2370 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2371 },
2372 {
2373 protocol: dtls,
2374 name: "LargeCiphertext-DTLS",
2375 config: Config{
2376 Bugs: ProtocolBugs{
2377 SendLargeRecords: true,
2378 },
2379 },
2380 messageLen: maxPlaintext * 2,
2381 // Unlike the other four cases, DTLS drops records which
2382 // are invalid before authentication, so the connection
2383 // does not fail.
2384 expectMessageDropped: true,
2385 },
David Benjamindd6fed92015-10-23 17:41:12 -04002386 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002387 name: "BadHelloRequest-1",
2388 renegotiate: 1,
2389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002390 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002391 Bugs: ProtocolBugs{
2392 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2393 },
2394 },
2395 flags: []string{
2396 "-renegotiate-freely",
2397 "-expect-total-renegotiations", "1",
2398 },
2399 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002400 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002401 },
2402 {
2403 name: "BadHelloRequest-2",
2404 renegotiate: 1,
2405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002406 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002407 Bugs: ProtocolBugs{
2408 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2409 },
2410 },
2411 flags: []string{
2412 "-renegotiate-freely",
2413 "-expect-total-renegotiations", "1",
2414 },
2415 shouldFail: true,
2416 expectedError: ":BAD_HELLO_REQUEST:",
2417 },
David Benjaminef1b0092015-11-21 14:05:44 -05002418 {
2419 testType: serverTest,
2420 name: "SupportTicketsWithSessionID",
2421 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002422 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002423 SessionTicketsDisabled: true,
2424 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002425 resumeConfig: &Config{
2426 MaxVersion: VersionTLS12,
2427 },
David Benjaminef1b0092015-11-21 14:05:44 -05002428 resumeSession: true,
2429 },
David Benjamin02edcd02016-07-27 17:40:37 -04002430 {
2431 protocol: dtls,
2432 name: "DTLS-SendExtraFinished",
2433 config: Config{
2434 Bugs: ProtocolBugs{
2435 SendExtraFinished: true,
2436 },
2437 },
2438 shouldFail: true,
2439 expectedError: ":UNEXPECTED_RECORD:",
2440 },
2441 {
2442 protocol: dtls,
2443 name: "DTLS-SendExtraFinished-Reordered",
2444 config: Config{
2445 Bugs: ProtocolBugs{
2446 MaxHandshakeRecordLength: 2,
2447 ReorderHandshakeFragments: true,
2448 SendExtraFinished: true,
2449 },
2450 },
2451 shouldFail: true,
2452 expectedError: ":UNEXPECTED_RECORD:",
2453 },
David Benjamine97fb482016-07-29 09:23:07 -04002454 {
2455 testType: serverTest,
2456 name: "V2ClientHello-EmptyRecordPrefix",
2457 config: Config{
2458 // Choose a cipher suite that does not involve
2459 // elliptic curves, so no extensions are
2460 // involved.
2461 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002462 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002463 Bugs: ProtocolBugs{
2464 SendV2ClientHello: true,
2465 },
2466 },
2467 sendPrefix: string([]byte{
2468 byte(recordTypeHandshake),
2469 3, 1, // version
2470 0, 0, // length
2471 }),
2472 // A no-op empty record may not be sent before V2ClientHello.
2473 shouldFail: true,
2474 expectedError: ":WRONG_VERSION_NUMBER:",
2475 },
2476 {
2477 testType: serverTest,
2478 name: "V2ClientHello-WarningAlertPrefix",
2479 config: Config{
2480 // Choose a cipher suite that does not involve
2481 // elliptic curves, so no extensions are
2482 // involved.
2483 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002484 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002485 Bugs: ProtocolBugs{
2486 SendV2ClientHello: true,
2487 },
2488 },
2489 sendPrefix: string([]byte{
2490 byte(recordTypeAlert),
2491 3, 1, // version
2492 0, 2, // length
2493 alertLevelWarning, byte(alertDecompressionFailure),
2494 }),
2495 // A no-op warning alert may not be sent before V2ClientHello.
2496 shouldFail: true,
2497 expectedError: ":WRONG_VERSION_NUMBER:",
2498 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002499 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002500 name: "KeyUpdate-Client",
2501 config: Config{
2502 MaxVersion: VersionTLS13,
2503 },
2504 sendKeyUpdates: 1,
2505 keyUpdateRequest: keyUpdateNotRequested,
2506 },
2507 {
2508 testType: serverTest,
2509 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002510 config: Config{
2511 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002512 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002513 sendKeyUpdates: 1,
2514 keyUpdateRequest: keyUpdateNotRequested,
2515 },
2516 {
2517 name: "KeyUpdate-InvalidRequestMode",
2518 config: Config{
2519 MaxVersion: VersionTLS13,
2520 },
2521 sendKeyUpdates: 1,
2522 keyUpdateRequest: 42,
2523 shouldFail: true,
2524 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002525 },
David Benjaminabe94e32016-09-04 14:18:58 -04002526 {
David Benjaminbbba9392017-04-06 12:54:12 -04002527 // Test that KeyUpdates are acknowledged properly.
2528 name: "KeyUpdate-RequestACK",
2529 config: Config{
2530 MaxVersion: VersionTLS13,
2531 Bugs: ProtocolBugs{
2532 RejectUnsolicitedKeyUpdate: true,
2533 },
2534 },
2535 // Test the shim receiving many KeyUpdates in a row.
2536 sendKeyUpdates: 5,
2537 messageCount: 5,
2538 keyUpdateRequest: keyUpdateRequested,
2539 },
2540 {
2541 // Test that KeyUpdates are acknowledged properly if the
2542 // peer's KeyUpdate is discovered while a write is
2543 // pending.
2544 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2545 config: Config{
2546 MaxVersion: VersionTLS13,
2547 Bugs: ProtocolBugs{
2548 RejectUnsolicitedKeyUpdate: true,
2549 },
2550 },
2551 // Test the shim receiving many KeyUpdates in a row.
2552 sendKeyUpdates: 5,
2553 messageCount: 5,
2554 keyUpdateRequest: keyUpdateRequested,
2555 readWithUnfinishedWrite: true,
2556 flags: []string{"-async"},
2557 },
2558 {
David Benjaminabe94e32016-09-04 14:18:58 -04002559 name: "SendSNIWarningAlert",
2560 config: Config{
2561 MaxVersion: VersionTLS12,
2562 Bugs: ProtocolBugs{
2563 SendSNIWarningAlert: true,
2564 },
2565 },
2566 },
David Benjaminc241d792016-09-09 10:34:20 -04002567 {
2568 testType: serverTest,
2569 name: "ExtraCompressionMethods-TLS12",
2570 config: Config{
2571 MaxVersion: VersionTLS12,
2572 Bugs: ProtocolBugs{
2573 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2574 },
2575 },
2576 },
2577 {
2578 testType: serverTest,
2579 name: "ExtraCompressionMethods-TLS13",
2580 config: Config{
2581 MaxVersion: VersionTLS13,
2582 Bugs: ProtocolBugs{
2583 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2584 },
2585 },
2586 shouldFail: true,
2587 expectedError: ":INVALID_COMPRESSION_LIST:",
2588 expectedLocalError: "remote error: illegal parameter",
2589 },
2590 {
2591 testType: serverTest,
2592 name: "NoNullCompression-TLS12",
2593 config: Config{
2594 MaxVersion: VersionTLS12,
2595 Bugs: ProtocolBugs{
2596 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2597 },
2598 },
2599 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002600 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002601 expectedLocalError: "remote error: illegal parameter",
2602 },
2603 {
2604 testType: serverTest,
2605 name: "NoNullCompression-TLS13",
2606 config: Config{
2607 MaxVersion: VersionTLS13,
2608 Bugs: ProtocolBugs{
2609 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2610 },
2611 },
2612 shouldFail: true,
2613 expectedError: ":INVALID_COMPRESSION_LIST:",
2614 expectedLocalError: "remote error: illegal parameter",
2615 },
David Benjamin413e79e2017-07-01 10:11:53 -04002616 // Test that the client rejects invalid compression methods
2617 // from the server.
2618 {
2619 testType: clientTest,
2620 name: "InvalidCompressionMethod",
2621 config: Config{
2622 MaxVersion: VersionTLS12,
2623 Bugs: ProtocolBugs{
2624 SendCompressionMethod: 1,
2625 },
2626 },
2627 shouldFail: true,
2628 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2629 expectedLocalError: "remote error: illegal parameter",
2630 },
David Benjamin65ac9972016-09-02 21:35:25 -04002631 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002632 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002633 config: Config{
2634 MaxVersion: VersionTLS12,
2635 Bugs: ProtocolBugs{
2636 ExpectGREASE: true,
2637 },
2638 },
2639 flags: []string{"-enable-grease"},
2640 },
2641 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002642 name: "GREASE-Client-TLS13",
2643 config: Config{
2644 MaxVersion: VersionTLS13,
2645 Bugs: ProtocolBugs{
2646 ExpectGREASE: true,
2647 },
2648 },
2649 flags: []string{"-enable-grease"},
2650 },
2651 {
2652 testType: serverTest,
2653 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002654 config: Config{
2655 MaxVersion: VersionTLS13,
2656 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002657 // TLS 1.3 servers are expected to
2658 // always enable GREASE. TLS 1.3 is new,
2659 // so there is no existing ecosystem to
2660 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002661 ExpectGREASE: true,
2662 },
2663 },
David Benjamin65ac9972016-09-02 21:35:25 -04002664 },
David Benjamine3fbb362017-01-06 16:19:28 -05002665 {
2666 // Test the server so there is a large certificate as
2667 // well as application data.
2668 testType: serverTest,
2669 name: "MaxSendFragment",
2670 config: Config{
2671 Bugs: ProtocolBugs{
2672 MaxReceivePlaintext: 512,
2673 },
2674 },
2675 messageLen: 1024,
2676 flags: []string{
2677 "-max-send-fragment", "512",
2678 "-read-size", "1024",
2679 },
2680 },
2681 {
2682 // Test the server so there is a large certificate as
2683 // well as application data.
2684 testType: serverTest,
2685 name: "MaxSendFragment-TooLarge",
2686 config: Config{
2687 Bugs: ProtocolBugs{
2688 // Ensure that some of the records are
2689 // 512.
2690 MaxReceivePlaintext: 511,
2691 },
2692 },
2693 messageLen: 1024,
2694 flags: []string{
2695 "-max-send-fragment", "512",
2696 "-read-size", "1024",
2697 },
2698 shouldFail: true,
2699 expectedLocalError: "local error: record overflow",
2700 },
Adam Langley7c803a62015-06-15 15:35:05 -07002701 }
Adam Langley7c803a62015-06-15 15:35:05 -07002702 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002703
2704 // Test that very large messages can be received.
2705 cert := rsaCertificate
2706 for i := 0; i < 50; i++ {
2707 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2708 }
2709 testCases = append(testCases, testCase{
2710 name: "LargeMessage",
2711 config: Config{
2712 Certificates: []Certificate{cert},
2713 },
2714 })
2715 testCases = append(testCases, testCase{
2716 protocol: dtls,
2717 name: "LargeMessage-DTLS",
2718 config: Config{
2719 Certificates: []Certificate{cert},
2720 },
2721 })
2722
2723 // They are rejected if the maximum certificate chain length is capped.
2724 testCases = append(testCases, testCase{
2725 name: "LargeMessage-Reject",
2726 config: Config{
2727 Certificates: []Certificate{cert},
2728 },
2729 flags: []string{"-max-cert-list", "16384"},
2730 shouldFail: true,
2731 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2732 })
2733 testCases = append(testCases, testCase{
2734 protocol: dtls,
2735 name: "LargeMessage-Reject-DTLS",
2736 config: Config{
2737 Certificates: []Certificate{cert},
2738 },
2739 flags: []string{"-max-cert-list", "16384"},
2740 shouldFail: true,
2741 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2742 })
Adam Langley7c803a62015-06-15 15:35:05 -07002743}
2744
David Benjaminaa012042016-12-10 13:33:05 -05002745func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2746 const psk = "12345"
2747 const pskIdentity = "luggage combo"
2748
2749 var prefix string
2750 if protocol == dtls {
2751 if !ver.hasDTLS {
2752 return
2753 }
2754 prefix = "D"
2755 }
2756
2757 var cert Certificate
2758 var certFile string
2759 var keyFile string
2760 if hasComponent(suite.name, "ECDSA") {
2761 cert = ecdsaP256Certificate
2762 certFile = ecdsaP256CertificateFile
2763 keyFile = ecdsaP256KeyFile
2764 } else {
2765 cert = rsaCertificate
2766 certFile = rsaCertificateFile
2767 keyFile = rsaKeyFile
2768 }
2769
2770 var flags []string
2771 if hasComponent(suite.name, "PSK") {
2772 flags = append(flags,
2773 "-psk", psk,
2774 "-psk-identity", pskIdentity)
2775 }
2776 if hasComponent(suite.name, "NULL") {
2777 // NULL ciphers must be explicitly enabled.
2778 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2779 }
David Benjaminaa012042016-12-10 13:33:05 -05002780
2781 var shouldServerFail, shouldClientFail bool
2782 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2783 // BoringSSL clients accept ECDHE on SSLv3, but
2784 // a BoringSSL server will never select it
2785 // because the extension is missing.
2786 shouldServerFail = true
2787 }
2788 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2789 shouldClientFail = true
2790 shouldServerFail = true
2791 }
2792 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2793 shouldClientFail = true
2794 shouldServerFail = true
2795 }
2796 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2797 shouldClientFail = true
2798 shouldServerFail = true
2799 }
2800 if !isDTLSCipher(suite.name) && protocol == dtls {
2801 shouldClientFail = true
2802 shouldServerFail = true
2803 }
2804
2805 var sendCipherSuite uint16
2806 var expectedServerError, expectedClientError string
2807 serverCipherSuites := []uint16{suite.id}
2808 if shouldServerFail {
2809 expectedServerError = ":NO_SHARED_CIPHER:"
2810 }
2811 if shouldClientFail {
2812 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2813 // Configure the server to select ciphers as normal but
2814 // select an incompatible cipher in ServerHello.
2815 serverCipherSuites = nil
2816 sendCipherSuite = suite.id
2817 }
2818
David Benjamincdb6fe92017-02-07 16:06:48 -05002819 // For cipher suites and versions where exporters are defined, verify
2820 // that they interoperate.
2821 var exportKeyingMaterial int
2822 if ver.version > VersionSSL30 {
2823 exportKeyingMaterial = 1024
2824 }
2825
David Benjaminaa012042016-12-10 13:33:05 -05002826 testCases = append(testCases, testCase{
2827 testType: serverTest,
2828 protocol: protocol,
2829 name: prefix + ver.name + "-" + suite.name + "-server",
2830 config: Config{
2831 MinVersion: ver.version,
2832 MaxVersion: ver.version,
2833 CipherSuites: []uint16{suite.id},
2834 Certificates: []Certificate{cert},
2835 PreSharedKey: []byte(psk),
2836 PreSharedKeyIdentity: pskIdentity,
2837 Bugs: ProtocolBugs{
2838 AdvertiseAllConfiguredCiphers: true,
2839 },
2840 },
David Benjamina5022392017-07-10 17:40:39 -04002841 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002842 certFile: certFile,
2843 keyFile: keyFile,
2844 flags: flags,
2845 resumeSession: true,
2846 shouldFail: shouldServerFail,
2847 expectedError: expectedServerError,
2848 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002849 })
2850
2851 testCases = append(testCases, testCase{
2852 testType: clientTest,
2853 protocol: protocol,
2854 name: prefix + ver.name + "-" + suite.name + "-client",
2855 config: Config{
2856 MinVersion: ver.version,
2857 MaxVersion: ver.version,
2858 CipherSuites: serverCipherSuites,
2859 Certificates: []Certificate{cert},
2860 PreSharedKey: []byte(psk),
2861 PreSharedKeyIdentity: pskIdentity,
2862 Bugs: ProtocolBugs{
2863 IgnorePeerCipherPreferences: shouldClientFail,
2864 SendCipherSuite: sendCipherSuite,
2865 },
2866 },
David Benjamina5022392017-07-10 17:40:39 -04002867 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002868 flags: flags,
2869 resumeSession: true,
2870 shouldFail: shouldClientFail,
2871 expectedError: expectedClientError,
2872 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002873 })
2874
David Benjamin6f600d62016-12-21 16:06:54 -05002875 if shouldClientFail {
2876 return
2877 }
2878
2879 // Ensure the maximum record size is accepted.
2880 testCases = append(testCases, testCase{
2881 protocol: protocol,
2882 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 CipherSuites: []uint16{suite.id},
2887 Certificates: []Certificate{cert},
2888 PreSharedKey: []byte(psk),
2889 PreSharedKeyIdentity: pskIdentity,
2890 },
David Benjamina5022392017-07-10 17:40:39 -04002891 tls13Variant: ver.tls13Variant,
2892 flags: flags,
2893 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002894 })
2895
2896 // Test bad records for all ciphers. Bad records are fatal in TLS
2897 // and ignored in DTLS.
2898 var shouldFail bool
2899 var expectedError string
2900 if protocol == tls {
2901 shouldFail = true
2902 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2903 }
2904
2905 testCases = append(testCases, testCase{
2906 protocol: protocol,
2907 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2908 config: Config{
2909 MinVersion: ver.version,
2910 MaxVersion: ver.version,
2911 CipherSuites: []uint16{suite.id},
2912 Certificates: []Certificate{cert},
2913 PreSharedKey: []byte(psk),
2914 PreSharedKeyIdentity: pskIdentity,
2915 },
David Benjamina5022392017-07-10 17:40:39 -04002916 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002917 flags: flags,
2918 damageFirstWrite: true,
2919 messageLen: maxPlaintext,
2920 shouldFail: shouldFail,
2921 expectedError: expectedError,
2922 })
David Benjaminaa012042016-12-10 13:33:05 -05002923}
2924
Adam Langley95c29f32014-06-20 12:00:00 -07002925func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002926 const bogusCipher = 0xfe00
2927
Adam Langley95c29f32014-06-20 12:00:00 -07002928 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002929 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002930 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002931 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002932 }
David Benjamin2c99d282015-09-01 10:23:00 -04002933 }
Adam Langley95c29f32014-06-20 12:00:00 -07002934 }
Adam Langleya7997f12015-05-14 17:38:50 -07002935
2936 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002937 name: "NoSharedCipher",
2938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002939 MaxVersion: VersionTLS12,
2940 CipherSuites: []uint16{},
2941 },
2942 shouldFail: true,
2943 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2944 })
2945
2946 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002947 name: "NoSharedCipher-TLS13",
2948 config: Config{
2949 MaxVersion: VersionTLS13,
2950 CipherSuites: []uint16{},
2951 },
2952 shouldFail: true,
2953 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2954 })
2955
2956 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002957 name: "UnsupportedCipherSuite",
2958 config: Config{
2959 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002960 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002961 Bugs: ProtocolBugs{
2962 IgnorePeerCipherPreferences: true,
2963 },
2964 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002965 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002966 shouldFail: true,
2967 expectedError: ":WRONG_CIPHER_RETURNED:",
2968 })
2969
2970 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002971 name: "ServerHelloBogusCipher",
2972 config: Config{
2973 MaxVersion: VersionTLS12,
2974 Bugs: ProtocolBugs{
2975 SendCipherSuite: bogusCipher,
2976 },
2977 },
2978 shouldFail: true,
2979 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2980 })
2981 testCases = append(testCases, testCase{
2982 name: "ServerHelloBogusCipher-TLS13",
2983 config: Config{
2984 MaxVersion: VersionTLS13,
2985 Bugs: ProtocolBugs{
2986 SendCipherSuite: bogusCipher,
2987 },
2988 },
2989 shouldFail: true,
2990 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2991 })
2992
David Benjamin241ae832016-01-15 03:04:54 -05002993 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002994 testCases = append(testCases, testCase{
2995 testType: serverTest,
2996 name: "UnknownCipher",
2997 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002998 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002999 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003000 Bugs: ProtocolBugs{
3001 AdvertiseAllConfiguredCiphers: true,
3002 },
3003 },
3004 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003005
3006 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003007 testCases = append(testCases, testCase{
3008 testType: serverTest,
3009 name: "UnknownCipher-TLS13",
3010 config: Config{
3011 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003012 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003013 Bugs: ProtocolBugs{
3014 AdvertiseAllConfiguredCiphers: true,
3015 },
David Benjamin241ae832016-01-15 03:04:54 -05003016 },
3017 })
3018
David Benjamin78679342016-09-16 19:42:05 -04003019 // Test empty ECDHE_PSK identity hints work as expected.
3020 testCases = append(testCases, testCase{
3021 name: "EmptyECDHEPSKHint",
3022 config: Config{
3023 MaxVersion: VersionTLS12,
3024 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3025 PreSharedKey: []byte("secret"),
3026 },
3027 flags: []string{"-psk", "secret"},
3028 })
3029
3030 // Test empty PSK identity hints work as expected, even if an explicit
3031 // ServerKeyExchange is sent.
3032 testCases = append(testCases, testCase{
3033 name: "ExplicitEmptyPSKHint",
3034 config: Config{
3035 MaxVersion: VersionTLS12,
3036 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3037 PreSharedKey: []byte("secret"),
3038 Bugs: ProtocolBugs{
3039 AlwaysSendPreSharedKeyIdentityHint: true,
3040 },
3041 },
3042 flags: []string{"-psk", "secret"},
3043 })
David Benjamin69522112017-03-28 15:38:29 -05003044
3045 // Test that clients enforce that the server-sent certificate and cipher
3046 // suite match in TLS 1.2.
3047 testCases = append(testCases, testCase{
3048 name: "CertificateCipherMismatch-RSA",
3049 config: Config{
3050 MaxVersion: VersionTLS12,
3051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3052 Certificates: []Certificate{rsaCertificate},
3053 Bugs: ProtocolBugs{
3054 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3055 },
3056 },
3057 shouldFail: true,
3058 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3059 })
3060 testCases = append(testCases, testCase{
3061 name: "CertificateCipherMismatch-ECDSA",
3062 config: Config{
3063 MaxVersion: VersionTLS12,
3064 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3065 Certificates: []Certificate{ecdsaP256Certificate},
3066 Bugs: ProtocolBugs{
3067 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3068 },
3069 },
3070 shouldFail: true,
3071 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3072 })
3073 testCases = append(testCases, testCase{
3074 name: "CertificateCipherMismatch-Ed25519",
3075 config: Config{
3076 MaxVersion: VersionTLS12,
3077 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3078 Certificates: []Certificate{ed25519Certificate},
3079 Bugs: ProtocolBugs{
3080 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3081 },
3082 },
3083 shouldFail: true,
3084 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3085 })
3086
3087 // Test that servers decline to select a cipher suite which is
3088 // inconsistent with their configured certificate.
3089 testCases = append(testCases, testCase{
3090 testType: serverTest,
3091 name: "ServerCipherFilter-RSA",
3092 config: Config{
3093 MaxVersion: VersionTLS12,
3094 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3095 },
3096 flags: []string{
3097 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3098 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3099 },
3100 shouldFail: true,
3101 expectedError: ":NO_SHARED_CIPHER:",
3102 })
3103 testCases = append(testCases, testCase{
3104 testType: serverTest,
3105 name: "ServerCipherFilter-ECDSA",
3106 config: Config{
3107 MaxVersion: VersionTLS12,
3108 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3109 },
3110 flags: []string{
3111 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3112 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3113 },
3114 shouldFail: true,
3115 expectedError: ":NO_SHARED_CIPHER:",
3116 })
3117 testCases = append(testCases, testCase{
3118 testType: serverTest,
3119 name: "ServerCipherFilter-Ed25519",
3120 config: Config{
3121 MaxVersion: VersionTLS12,
3122 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3123 },
3124 flags: []string{
3125 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3126 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3127 },
3128 shouldFail: true,
3129 expectedError: ":NO_SHARED_CIPHER:",
3130 })
David Benjamin364af782017-07-01 10:35:27 -04003131
3132 // Test cipher suite negotiation works as expected. Configure a
3133 // complicated cipher suite configuration.
3134 const negotiationTestCiphers = "" +
3135 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3136 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3137 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3138 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3139 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3140 negotiationTests := []struct {
3141 ciphers []uint16
3142 expected uint16
3143 }{
3144 // Server preferences are honored, including when
3145 // equipreference groups are involved.
3146 {
3147 []uint16{
3148 TLS_RSA_WITH_AES_256_GCM_SHA384,
3149 TLS_RSA_WITH_AES_128_CBC_SHA,
3150 TLS_RSA_WITH_AES_128_GCM_SHA256,
3151 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3152 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3153 },
3154 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3155 },
3156 {
3157 []uint16{
3158 TLS_RSA_WITH_AES_256_GCM_SHA384,
3159 TLS_RSA_WITH_AES_128_CBC_SHA,
3160 TLS_RSA_WITH_AES_128_GCM_SHA256,
3161 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3162 },
3163 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3164 },
3165 {
3166 []uint16{
3167 TLS_RSA_WITH_AES_256_GCM_SHA384,
3168 TLS_RSA_WITH_AES_128_CBC_SHA,
3169 TLS_RSA_WITH_AES_128_GCM_SHA256,
3170 },
3171 TLS_RSA_WITH_AES_128_GCM_SHA256,
3172 },
3173 {
3174 []uint16{
3175 TLS_RSA_WITH_AES_256_GCM_SHA384,
3176 TLS_RSA_WITH_AES_128_CBC_SHA,
3177 },
3178 TLS_RSA_WITH_AES_128_CBC_SHA,
3179 },
3180 // Equipreference groups use the client preference.
3181 {
3182 []uint16{
3183 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3184 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3185 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3186 },
3187 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3188 },
3189 {
3190 []uint16{
3191 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3192 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3193 },
3194 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3195 },
3196 {
3197 []uint16{
3198 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3199 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3200 },
3201 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3202 },
3203 {
3204 []uint16{
3205 TLS_RSA_WITH_AES_256_GCM_SHA384,
3206 TLS_RSA_WITH_AES_256_CBC_SHA,
3207 },
3208 TLS_RSA_WITH_AES_256_GCM_SHA384,
3209 },
3210 {
3211 []uint16{
3212 TLS_RSA_WITH_AES_256_CBC_SHA,
3213 TLS_RSA_WITH_AES_256_GCM_SHA384,
3214 },
3215 TLS_RSA_WITH_AES_256_CBC_SHA,
3216 },
3217 // If there are two equipreference groups, the preferred one
3218 // takes precedence.
3219 {
3220 []uint16{
3221 TLS_RSA_WITH_AES_256_GCM_SHA384,
3222 TLS_RSA_WITH_AES_256_CBC_SHA,
3223 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3224 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3225 },
3226 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3227 },
3228 }
3229 for i, t := range negotiationTests {
3230 testCases = append(testCases, testCase{
3231 testType: serverTest,
3232 name: "CipherNegotiation-" + strconv.Itoa(i),
3233 config: Config{
3234 MaxVersion: VersionTLS12,
3235 CipherSuites: t.ciphers,
3236 },
3237 flags: []string{"-cipher", negotiationTestCiphers},
3238 expectedCipher: t.expected,
3239 })
3240 }
Adam Langley95c29f32014-06-20 12:00:00 -07003241}
3242
3243func addBadECDSASignatureTests() {
3244 for badR := BadValue(1); badR < NumBadValues; badR++ {
3245 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003246 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003247 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3248 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003249 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003250 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003251 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003252 Bugs: ProtocolBugs{
3253 BadECDSAR: badR,
3254 BadECDSAS: badS,
3255 },
3256 },
3257 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003258 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003259 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003260 testCases = append(testCases, testCase{
3261 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3262 config: Config{
3263 MaxVersion: VersionTLS13,
3264 Certificates: []Certificate{ecdsaP256Certificate},
3265 Bugs: ProtocolBugs{
3266 BadECDSAR: badR,
3267 BadECDSAS: badS,
3268 },
3269 },
3270 shouldFail: true,
3271 expectedError: ":BAD_SIGNATURE:",
3272 })
Adam Langley95c29f32014-06-20 12:00:00 -07003273 }
3274 }
3275}
3276
Adam Langley80842bd2014-06-20 12:00:00 -07003277func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003278 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003279 name: "MaxCBCPadding",
3280 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003281 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003282 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3283 Bugs: ProtocolBugs{
3284 MaxPadding: true,
3285 },
3286 },
3287 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3288 })
David Benjamin025b3d32014-07-01 19:53:04 -04003289 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003290 name: "BadCBCPadding",
3291 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003292 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003293 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3294 Bugs: ProtocolBugs{
3295 PaddingFirstByteBad: true,
3296 },
3297 },
3298 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003299 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003300 })
3301 // OpenSSL previously had an issue where the first byte of padding in
3302 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003303 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003304 name: "BadCBCPadding255",
3305 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003306 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003307 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3308 Bugs: ProtocolBugs{
3309 MaxPadding: true,
3310 PaddingFirstByteBadIf255: true,
3311 },
3312 },
3313 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3314 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003315 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003316 })
3317}
3318
Kenny Root7fdeaf12014-08-05 15:23:37 -07003319func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003320 var cbcCiphers = []struct {
3321 name string
3322 cipher uint16
3323 }{
3324 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3325 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3326 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3327 }
3328 for _, t := range cbcCiphers {
3329 testCases = append(testCases, testCase{
3330 name: "CBCRecordSplitting-" + t.name,
3331 config: Config{
3332 MaxVersion: VersionTLS10,
3333 MinVersion: VersionTLS10,
3334 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003335 Bugs: ProtocolBugs{
3336 ExpectRecordSplitting: true,
3337 },
David Benjamina1ce8562017-07-01 11:46:57 -04003338 },
3339 messageLen: -1, // read until EOF
3340 resumeSession: true,
3341 flags: []string{
3342 "-async",
3343 "-write-different-record-sizes",
3344 "-cbc-record-splitting",
3345 },
3346 })
3347 testCases = append(testCases, testCase{
3348 name: "CBCRecordSplittingPartialWrite-" + t.name,
3349 config: Config{
3350 MaxVersion: VersionTLS10,
3351 MinVersion: VersionTLS10,
3352 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003353 Bugs: ProtocolBugs{
3354 ExpectRecordSplitting: true,
3355 },
David Benjamina1ce8562017-07-01 11:46:57 -04003356 },
3357 messageLen: -1, // read until EOF
3358 flags: []string{
3359 "-async",
3360 "-write-different-record-sizes",
3361 "-cbc-record-splitting",
3362 "-partial-write",
3363 },
3364 })
3365 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003366}
3367
David Benjamin636293b2014-07-08 17:59:18 -04003368func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003369 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003370 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003371 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3372 cert, err := x509.ParseCertificate(cert.Certificate[0])
3373 if err != nil {
3374 panic(err)
3375 }
3376 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003377 }
Adam Langley2ff79332017-02-28 13:45:39 -08003378 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003379
David Benjamin636293b2014-07-08 17:59:18 -04003380 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003381 testCases = append(testCases, testCase{
3382 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003383 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003384 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003385 MinVersion: ver.version,
3386 MaxVersion: ver.version,
3387 ClientAuth: RequireAnyClientCert,
3388 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003389 },
David Benjamina5022392017-07-10 17:40:39 -04003390 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003391 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003392 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3393 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003394 },
3395 })
3396 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003397 testType: serverTest,
3398 name: ver.name + "-Server-ClientAuth-RSA",
3399 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003400 MinVersion: ver.version,
3401 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003402 Certificates: []Certificate{rsaCertificate},
3403 },
David Benjamina5022392017-07-10 17:40:39 -04003404 tls13Variant: ver.tls13Variant,
3405 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003406 })
David Benjamine098ec22014-08-27 23:13:20 -04003407 if ver.version != VersionSSL30 {
3408 testCases = append(testCases, testCase{
3409 testType: serverTest,
3410 name: ver.name + "-Server-ClientAuth-ECDSA",
3411 config: Config{
3412 MinVersion: ver.version,
3413 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003414 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003415 },
David Benjamina5022392017-07-10 17:40:39 -04003416 tls13Variant: ver.tls13Variant,
3417 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003418 })
3419 testCases = append(testCases, testCase{
3420 testType: clientTest,
3421 name: ver.name + "-Client-ClientAuth-ECDSA",
3422 config: Config{
3423 MinVersion: ver.version,
3424 MaxVersion: ver.version,
3425 ClientAuth: RequireAnyClientCert,
3426 ClientCAs: certPool,
3427 },
David Benjamina5022392017-07-10 17:40:39 -04003428 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003429 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003430 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3431 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003432 },
3433 })
3434 }
Adam Langley37646832016-08-01 16:16:46 -07003435
3436 testCases = append(testCases, testCase{
3437 name: "NoClientCertificate-" + ver.name,
3438 config: Config{
3439 MinVersion: ver.version,
3440 MaxVersion: ver.version,
3441 ClientAuth: RequireAnyClientCert,
3442 },
David Benjamina5022392017-07-10 17:40:39 -04003443 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003444 shouldFail: true,
3445 expectedLocalError: "client didn't provide a certificate",
3446 })
3447
3448 testCases = append(testCases, testCase{
3449 // Even if not configured to expect a certificate, OpenSSL will
3450 // return X509_V_OK as the verify_result.
3451 testType: serverTest,
3452 name: "NoClientCertificateRequested-Server-" + ver.name,
3453 config: Config{
3454 MinVersion: ver.version,
3455 MaxVersion: ver.version,
3456 },
David Benjamina5022392017-07-10 17:40:39 -04003457 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003458 flags: []string{
3459 "-expect-verify-result",
3460 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003461 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003462 })
3463
3464 testCases = append(testCases, testCase{
3465 // If a client certificate is not provided, OpenSSL will still
3466 // return X509_V_OK as the verify_result.
3467 testType: serverTest,
3468 name: "NoClientCertificate-Server-" + ver.name,
3469 config: Config{
3470 MinVersion: ver.version,
3471 MaxVersion: ver.version,
3472 },
David Benjamina5022392017-07-10 17:40:39 -04003473 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003474 flags: []string{
3475 "-expect-verify-result",
3476 "-verify-peer",
3477 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003478 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003479 })
3480
David Benjamin1db9e1b2016-10-07 20:51:43 -04003481 certificateRequired := "remote error: certificate required"
3482 if ver.version < VersionTLS13 {
3483 // Prior to TLS 1.3, the generic handshake_failure alert
3484 // was used.
3485 certificateRequired = "remote error: handshake failure"
3486 }
Adam Langley37646832016-08-01 16:16:46 -07003487 testCases = append(testCases, testCase{
3488 testType: serverTest,
3489 name: "RequireAnyClientCertificate-" + ver.name,
3490 config: Config{
3491 MinVersion: ver.version,
3492 MaxVersion: ver.version,
3493 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003494 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003495 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003496 shouldFail: true,
3497 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3498 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003499 })
3500
3501 if ver.version != VersionSSL30 {
3502 testCases = append(testCases, testCase{
3503 testType: serverTest,
3504 name: "SkipClientCertificate-" + ver.name,
3505 config: Config{
3506 MinVersion: ver.version,
3507 MaxVersion: ver.version,
3508 Bugs: ProtocolBugs{
3509 SkipClientCertificate: true,
3510 },
3511 },
3512 // Setting SSL_VERIFY_PEER allows anonymous clients.
3513 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003514 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003515 shouldFail: true,
3516 expectedError: ":UNEXPECTED_MESSAGE:",
3517 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003518
3519 testCases = append(testCases, testCase{
3520 testType: serverTest,
3521 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3522 config: Config{
3523 MinVersion: ver.version,
3524 MaxVersion: ver.version,
3525 },
3526 flags: []string{
3527 "-enable-channel-id",
3528 "-verify-peer-if-no-obc",
3529 },
David Benjamina5022392017-07-10 17:40:39 -04003530 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003531 shouldFail: true,
3532 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3533 expectedLocalError: certificateRequired,
3534 })
3535
3536 testCases = append(testCases, testCase{
3537 testType: serverTest,
3538 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3539 config: Config{
3540 MinVersion: ver.version,
3541 MaxVersion: ver.version,
3542 ChannelID: channelIDKey,
3543 },
3544 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003545 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003546 flags: []string{
3547 "-enable-channel-id",
3548 "-verify-peer-if-no-obc",
3549 },
3550 })
Adam Langley37646832016-08-01 16:16:46 -07003551 }
Adam Langley2ff79332017-02-28 13:45:39 -08003552
3553 testCases = append(testCases, testCase{
3554 testType: serverTest,
3555 name: ver.name + "-Server-CertReq-CA-List",
3556 config: Config{
3557 MinVersion: ver.version,
3558 MaxVersion: ver.version,
3559 Certificates: []Certificate{rsaCertificate},
3560 Bugs: ProtocolBugs{
3561 ExpectCertificateReqNames: caNames,
3562 },
3563 },
David Benjamina5022392017-07-10 17:40:39 -04003564 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003565 flags: []string{
3566 "-require-any-client-certificate",
3567 "-use-client-ca-list", encodeDERValues(caNames),
3568 },
3569 })
3570
3571 testCases = append(testCases, testCase{
3572 testType: clientTest,
3573 name: ver.name + "-Client-CertReq-CA-List",
3574 config: Config{
3575 MinVersion: ver.version,
3576 MaxVersion: ver.version,
3577 Certificates: []Certificate{rsaCertificate},
3578 ClientAuth: RequireAnyClientCert,
3579 ClientCAs: certPool,
3580 },
David Benjamina5022392017-07-10 17:40:39 -04003581 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003582 flags: []string{
3583 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3584 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3585 "-expect-client-ca-list", encodeDERValues(caNames),
3586 },
3587 })
David Benjamin636293b2014-07-08 17:59:18 -04003588 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003589
David Benjaminc032dfa2016-05-12 14:54:57 -04003590 // Client auth is only legal in certificate-based ciphers.
3591 testCases = append(testCases, testCase{
3592 testType: clientTest,
3593 name: "ClientAuth-PSK",
3594 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003595 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003596 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3597 PreSharedKey: []byte("secret"),
3598 ClientAuth: RequireAnyClientCert,
3599 },
3600 flags: []string{
3601 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3602 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3603 "-psk", "secret",
3604 },
3605 shouldFail: true,
3606 expectedError: ":UNEXPECTED_MESSAGE:",
3607 })
3608 testCases = append(testCases, testCase{
3609 testType: clientTest,
3610 name: "ClientAuth-ECDHE_PSK",
3611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003612 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003613 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3614 PreSharedKey: []byte("secret"),
3615 ClientAuth: RequireAnyClientCert,
3616 },
3617 flags: []string{
3618 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3619 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3620 "-psk", "secret",
3621 },
3622 shouldFail: true,
3623 expectedError: ":UNEXPECTED_MESSAGE:",
3624 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003625
3626 // Regression test for a bug where the client CA list, if explicitly
3627 // set to NULL, was mis-encoded.
3628 testCases = append(testCases, testCase{
3629 testType: serverTest,
3630 name: "Null-Client-CA-List",
3631 config: Config{
3632 MaxVersion: VersionTLS12,
3633 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003634 Bugs: ProtocolBugs{
3635 ExpectCertificateReqNames: [][]byte{},
3636 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003637 },
3638 flags: []string{
3639 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003640 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003641 },
3642 })
David Benjamin636293b2014-07-08 17:59:18 -04003643}
3644
Adam Langley75712922014-10-10 16:23:43 -07003645func addExtendedMasterSecretTests() {
3646 const expectEMSFlag = "-expect-extended-master-secret"
3647
3648 for _, with := range []bool{false, true} {
3649 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003650 if with {
3651 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003652 }
3653
3654 for _, isClient := range []bool{false, true} {
3655 suffix := "-Server"
3656 testType := serverTest
3657 if isClient {
3658 suffix = "-Client"
3659 testType = clientTest
3660 }
3661
3662 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003663 // In TLS 1.3, the extension is irrelevant and
3664 // always reports as enabled.
3665 var flags []string
3666 if with || ver.version >= VersionTLS13 {
3667 flags = []string{expectEMSFlag}
3668 }
3669
Adam Langley75712922014-10-10 16:23:43 -07003670 test := testCase{
3671 testType: testType,
3672 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3673 config: Config{
3674 MinVersion: ver.version,
3675 MaxVersion: ver.version,
3676 Bugs: ProtocolBugs{
3677 NoExtendedMasterSecret: !with,
3678 RequireExtendedMasterSecret: with,
3679 },
3680 },
David Benjamina5022392017-07-10 17:40:39 -04003681 tls13Variant: ver.tls13Variant,
3682 flags: flags,
3683 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003684 }
3685 if test.shouldFail {
3686 test.expectedLocalError = "extended master secret required but not supported by peer"
3687 }
3688 testCases = append(testCases, test)
3689 }
3690 }
3691 }
3692
Adam Langleyba5934b2015-06-02 10:50:35 -07003693 for _, isClient := range []bool{false, true} {
3694 for _, supportedInFirstConnection := range []bool{false, true} {
3695 for _, supportedInResumeConnection := range []bool{false, true} {
3696 boolToWord := func(b bool) string {
3697 if b {
3698 return "Yes"
3699 }
3700 return "No"
3701 }
3702 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3703 if isClient {
3704 suffix += "Client"
3705 } else {
3706 suffix += "Server"
3707 }
3708
3709 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003710 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003711 Bugs: ProtocolBugs{
3712 RequireExtendedMasterSecret: true,
3713 },
3714 }
3715
3716 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003718 Bugs: ProtocolBugs{
3719 NoExtendedMasterSecret: true,
3720 },
3721 }
3722
3723 test := testCase{
3724 name: "ExtendedMasterSecret-" + suffix,
3725 resumeSession: true,
3726 }
3727
3728 if !isClient {
3729 test.testType = serverTest
3730 }
3731
3732 if supportedInFirstConnection {
3733 test.config = supportedConfig
3734 } else {
3735 test.config = noSupportConfig
3736 }
3737
3738 if supportedInResumeConnection {
3739 test.resumeConfig = &supportedConfig
3740 } else {
3741 test.resumeConfig = &noSupportConfig
3742 }
3743
3744 switch suffix {
3745 case "YesToYes-Client", "YesToYes-Server":
3746 // When a session is resumed, it should
3747 // still be aware that its master
3748 // secret was generated via EMS and
3749 // thus it's safe to use tls-unique.
3750 test.flags = []string{expectEMSFlag}
3751 case "NoToYes-Server":
3752 // If an original connection did not
3753 // contain EMS, but a resumption
3754 // handshake does, then a server should
3755 // not resume the session.
3756 test.expectResumeRejected = true
3757 case "YesToNo-Server":
3758 // Resuming an EMS session without the
3759 // EMS extension should cause the
3760 // server to abort the connection.
3761 test.shouldFail = true
3762 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3763 case "NoToYes-Client":
3764 // A client should abort a connection
3765 // where the server resumed a non-EMS
3766 // session but echoed the EMS
3767 // extension.
3768 test.shouldFail = true
3769 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3770 case "YesToNo-Client":
3771 // A client should abort a connection
3772 // where the server didn't echo EMS
3773 // when the session used it.
3774 test.shouldFail = true
3775 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3776 }
3777
3778 testCases = append(testCases, test)
3779 }
3780 }
3781 }
David Benjamin163c9562016-08-29 23:14:17 -04003782
3783 // Switching EMS on renegotiation is forbidden.
3784 testCases = append(testCases, testCase{
3785 name: "ExtendedMasterSecret-Renego-NoEMS",
3786 config: Config{
3787 MaxVersion: VersionTLS12,
3788 Bugs: ProtocolBugs{
3789 NoExtendedMasterSecret: true,
3790 NoExtendedMasterSecretOnRenegotiation: true,
3791 },
3792 },
3793 renegotiate: 1,
3794 flags: []string{
3795 "-renegotiate-freely",
3796 "-expect-total-renegotiations", "1",
3797 },
3798 })
3799
3800 testCases = append(testCases, testCase{
3801 name: "ExtendedMasterSecret-Renego-Upgrade",
3802 config: Config{
3803 MaxVersion: VersionTLS12,
3804 Bugs: ProtocolBugs{
3805 NoExtendedMasterSecret: true,
3806 },
3807 },
3808 renegotiate: 1,
3809 flags: []string{
3810 "-renegotiate-freely",
3811 "-expect-total-renegotiations", "1",
3812 },
3813 shouldFail: true,
3814 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3815 })
3816
3817 testCases = append(testCases, testCase{
3818 name: "ExtendedMasterSecret-Renego-Downgrade",
3819 config: Config{
3820 MaxVersion: VersionTLS12,
3821 Bugs: ProtocolBugs{
3822 NoExtendedMasterSecretOnRenegotiation: true,
3823 },
3824 },
3825 renegotiate: 1,
3826 flags: []string{
3827 "-renegotiate-freely",
3828 "-expect-total-renegotiations", "1",
3829 },
3830 shouldFail: true,
3831 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3832 })
Adam Langley75712922014-10-10 16:23:43 -07003833}
3834
David Benjamin582ba042016-07-07 12:33:25 -07003835type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003836 protocol protocol
3837 async bool
3838 splitHandshake bool
3839 packHandshakeFlight bool
3840 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003841}
3842
David Benjamin43ec06f2014-08-05 02:28:57 -04003843// Adds tests that try to cover the range of the handshake state machine, under
3844// various conditions. Some of these are redundant with other tests, but they
3845// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003846func addAllStateMachineCoverageTests() {
3847 for _, async := range []bool{false, true} {
3848 for _, protocol := range []protocol{tls, dtls} {
3849 addStateMachineCoverageTests(stateMachineTestConfig{
3850 protocol: protocol,
3851 async: async,
3852 })
3853 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003854 protocol: protocol,
3855 async: async,
3856 implicitHandshake: true,
3857 })
3858 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003859 protocol: protocol,
3860 async: async,
3861 splitHandshake: true,
3862 })
3863 if protocol == tls {
3864 addStateMachineCoverageTests(stateMachineTestConfig{
3865 protocol: protocol,
3866 async: async,
3867 packHandshakeFlight: true,
3868 })
3869 }
3870 }
3871 }
3872}
3873
3874func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003875 var tests []testCase
3876
3877 // Basic handshake, with resumption. Client and server,
3878 // session ID and session ticket.
3879 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003880 name: "Basic-Client",
3881 config: Config{
3882 MaxVersion: VersionTLS12,
3883 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003884 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003885 // Ensure session tickets are used, not session IDs.
3886 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003887 })
3888 tests = append(tests, testCase{
3889 name: "Basic-Client-RenewTicket",
3890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 Bugs: ProtocolBugs{
3893 RenewTicketOnResume: true,
3894 },
3895 },
David Benjamin46662482016-08-17 00:51:00 -04003896 flags: []string{"-expect-ticket-renewal"},
3897 resumeSession: true,
3898 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003899 })
3900 tests = append(tests, testCase{
3901 name: "Basic-Client-NoTicket",
3902 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003903 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003904 SessionTicketsDisabled: true,
3905 },
3906 resumeSession: true,
3907 })
3908 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003909 testType: serverTest,
3910 name: "Basic-Server",
3911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003912 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003913 Bugs: ProtocolBugs{
3914 RequireSessionTickets: true,
3915 },
3916 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003917 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003918 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003919 })
3920 tests = append(tests, testCase{
3921 testType: serverTest,
3922 name: "Basic-Server-NoTickets",
3923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 SessionTicketsDisabled: true,
3926 },
3927 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003928 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003929 })
3930 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003931 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003932 name: "Basic-Server-EarlyCallback",
3933 config: Config{
3934 MaxVersion: VersionTLS12,
3935 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003936 flags: []string{"-use-early-callback"},
3937 resumeSession: true,
3938 })
3939
Steven Valdez143e8b32016-07-11 13:19:03 -04003940 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003941 if config.protocol == tls {
3942 tests = append(tests, testCase{
3943 name: "TLS13-1RTT-Client",
3944 config: Config{
3945 MaxVersion: VersionTLS13,
3946 MinVersion: VersionTLS13,
3947 },
David Benjamin46662482016-08-17 00:51:00 -04003948 resumeSession: true,
3949 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003950 })
3951
3952 tests = append(tests, testCase{
3953 testType: serverTest,
3954 name: "TLS13-1RTT-Server",
3955 config: Config{
3956 MaxVersion: VersionTLS13,
3957 MinVersion: VersionTLS13,
3958 },
David Benjamin46662482016-08-17 00:51:00 -04003959 resumeSession: true,
3960 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003961 // TLS 1.3 uses tickets, so the session should not be
3962 // cached statefully.
3963 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003964 })
3965
3966 tests = append(tests, testCase{
3967 name: "TLS13-HelloRetryRequest-Client",
3968 config: Config{
3969 MaxVersion: VersionTLS13,
3970 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003971 // P-384 requires a HelloRetryRequest against BoringSSL's default
3972 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003973 CurvePreferences: []CurveID{CurveP384},
3974 Bugs: ProtocolBugs{
3975 ExpectMissingKeyShare: true,
3976 },
3977 },
3978 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3979 resumeSession: true,
3980 })
3981
3982 tests = append(tests, testCase{
3983 testType: serverTest,
3984 name: "TLS13-HelloRetryRequest-Server",
3985 config: Config{
3986 MaxVersion: VersionTLS13,
3987 MinVersion: VersionTLS13,
3988 // Require a HelloRetryRequest for every curve.
3989 DefaultCurves: []CurveID{},
3990 },
3991 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3992 resumeSession: true,
3993 })
Steven Valdez2d850622017-01-11 11:34:52 -05003994
Steven Valdez2d850622017-01-11 11:34:52 -05003995 tests = append(tests, testCase{
3996 testType: clientTest,
3997 name: "TLS13-EarlyData-Client",
3998 config: Config{
3999 MaxVersion: VersionTLS13,
4000 MinVersion: VersionTLS13,
4001 MaxEarlyDataSize: 16384,
4002 },
Steven Valdeze831a812017-03-09 14:56:07 -05004003 resumeConfig: &Config{
4004 MaxVersion: VersionTLS13,
4005 MinVersion: VersionTLS13,
4006 MaxEarlyDataSize: 16384,
4007 Bugs: ProtocolBugs{
4008 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4009 },
4010 },
Steven Valdez2d850622017-01-11 11:34:52 -05004011 resumeSession: true,
4012 flags: []string{
4013 "-enable-early-data",
4014 "-expect-early-data-info",
4015 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004016 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004017 },
4018 })
4019
4020 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004021 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004022 name: "TLS13Experiment-EarlyData-Client",
4023 config: Config{
4024 MaxVersion: VersionTLS13,
4025 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004026 MaxEarlyDataSize: 16384,
4027 },
4028 resumeConfig: &Config{
4029 MaxVersion: VersionTLS13,
4030 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004031 MaxEarlyDataSize: 16384,
4032 Bugs: ProtocolBugs{
4033 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4034 },
4035 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004036 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004037 resumeSession: true,
4038 flags: []string{
4039 "-enable-early-data",
4040 "-expect-early-data-info",
4041 "-expect-accept-early-data",
4042 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004043 },
4044 })
4045
4046 tests = append(tests, testCase{
4047 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004048 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4049 config: Config{
4050 MaxVersion: VersionTLS13,
4051 MinVersion: VersionTLS13,
4052 TLS13Variant: TLS13RecordTypeExperiment,
4053 MaxEarlyDataSize: 16384,
4054 },
4055 resumeConfig: &Config{
4056 MaxVersion: VersionTLS13,
4057 MinVersion: VersionTLS13,
4058 TLS13Variant: TLS13RecordTypeExperiment,
4059 MaxEarlyDataSize: 16384,
4060 Bugs: ProtocolBugs{
4061 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4062 },
4063 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004064 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004065 resumeSession: true,
4066 flags: []string{
4067 "-enable-early-data",
4068 "-expect-early-data-info",
4069 "-expect-accept-early-data",
4070 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004071 },
4072 })
4073
4074 tests = append(tests, testCase{
4075 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004076 name: "TLS13-EarlyData-TooMuchData-Client",
4077 config: Config{
4078 MaxVersion: VersionTLS13,
4079 MinVersion: VersionTLS13,
4080 MaxEarlyDataSize: 2,
4081 },
4082 resumeConfig: &Config{
4083 MaxVersion: VersionTLS13,
4084 MinVersion: VersionTLS13,
4085 MaxEarlyDataSize: 2,
4086 Bugs: ProtocolBugs{
4087 ExpectEarlyData: [][]byte{{'h', 'e'}},
4088 },
4089 },
4090 resumeShimPrefix: "llo",
4091 resumeSession: true,
4092 flags: []string{
4093 "-enable-early-data",
4094 "-expect-early-data-info",
4095 "-expect-accept-early-data",
4096 "-on-resume-shim-writes-first",
4097 },
4098 })
4099
4100 // Unfinished writes can only be tested when operations are async. EarlyData
4101 // can't be tested as part of an ImplicitHandshake in this case since
4102 // otherwise the early data will be sent as normal data.
4103 if config.async && !config.implicitHandshake {
4104 tests = append(tests, testCase{
4105 testType: clientTest,
4106 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4107 config: Config{
4108 MaxVersion: VersionTLS13,
4109 MinVersion: VersionTLS13,
4110 MaxEarlyDataSize: 16384,
4111 },
4112 resumeConfig: &Config{
4113 MaxVersion: VersionTLS13,
4114 MinVersion: VersionTLS13,
4115 MaxEarlyDataSize: 16384,
4116 Bugs: ProtocolBugs{
4117 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4118 },
4119 },
4120 resumeSession: true,
4121 flags: []string{
4122 "-enable-early-data",
4123 "-expect-early-data-info",
4124 "-expect-accept-early-data",
4125 "-on-resume-read-with-unfinished-write",
4126 "-on-resume-shim-writes-first",
4127 },
4128 })
4129
4130 // Rejected unfinished writes are discarded (from the
4131 // perspective of the calling application) on 0-RTT
4132 // reject.
4133 tests = append(tests, testCase{
4134 testType: clientTest,
4135 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4136 config: Config{
4137 MaxVersion: VersionTLS13,
4138 MinVersion: VersionTLS13,
4139 MaxEarlyDataSize: 16384,
4140 },
4141 resumeConfig: &Config{
4142 MaxVersion: VersionTLS13,
4143 MinVersion: VersionTLS13,
4144 MaxEarlyDataSize: 16384,
4145 Bugs: ProtocolBugs{
4146 AlwaysRejectEarlyData: true,
4147 },
4148 },
4149 resumeSession: true,
4150 flags: []string{
4151 "-enable-early-data",
4152 "-expect-early-data-info",
4153 "-expect-reject-early-data",
4154 "-on-resume-read-with-unfinished-write",
4155 "-on-resume-shim-writes-first",
4156 },
4157 })
4158 }
4159
4160 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004161 testType: serverTest,
4162 name: "TLS13-EarlyData-Server",
4163 config: Config{
4164 MaxVersion: VersionTLS13,
4165 MinVersion: VersionTLS13,
4166 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004167 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004168 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004169 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004170 },
4171 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004172 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004173 resumeSession: true,
4174 flags: []string{
4175 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004176 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004177 },
4178 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004179
4180 tests = append(tests, testCase{
4181 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004182 name: "TLS13Experiment-EarlyData-Server",
4183 config: Config{
4184 MaxVersion: VersionTLS13,
4185 MinVersion: VersionTLS13,
4186 TLS13Variant: TLS13Experiment,
4187 Bugs: ProtocolBugs{
4188 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4189 ExpectEarlyDataAccepted: true,
4190 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4191 },
4192 },
4193 messageCount: 2,
4194 resumeSession: true,
4195 flags: []string{
4196 "-enable-early-data",
4197 "-expect-accept-early-data",
4198 "-tls13-variant", "1",
4199 },
4200 })
4201
4202 tests = append(tests, testCase{
4203 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004204 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4205 config: Config{
4206 MaxVersion: VersionTLS13,
4207 MinVersion: VersionTLS13,
4208 TLS13Variant: TLS13RecordTypeExperiment,
4209 Bugs: ProtocolBugs{
4210 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4211 ExpectEarlyDataAccepted: true,
4212 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4213 },
4214 },
4215 messageCount: 2,
4216 resumeSession: true,
4217 flags: []string{
4218 "-enable-early-data",
4219 "-expect-accept-early-data",
4220 "-tls13-variant", "2",
4221 },
4222 })
4223
4224 tests = append(tests, testCase{
4225 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004226 name: "TLS13-MaxEarlyData-Server",
4227 config: Config{
4228 MaxVersion: VersionTLS13,
4229 MinVersion: VersionTLS13,
4230 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004231 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004232 ExpectEarlyDataAccepted: true,
4233 },
4234 },
4235 messageCount: 2,
4236 resumeSession: true,
4237 flags: []string{
4238 "-enable-early-data",
4239 "-expect-accept-early-data",
4240 },
4241 shouldFail: true,
4242 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4243 })
David Benjamine73c7f42016-08-17 00:29:33 -04004244 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004245
David Benjamin760b1dd2015-05-15 23:33:48 -04004246 // TLS client auth.
4247 tests = append(tests, testCase{
4248 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004249 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004250 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004251 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004252 ClientAuth: RequestClientCert,
4253 },
4254 })
4255 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004256 testType: serverTest,
4257 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004258 config: Config{
4259 MaxVersion: VersionTLS12,
4260 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004261 // Setting SSL_VERIFY_PEER allows anonymous clients.
4262 flags: []string{"-verify-peer"},
4263 })
David Benjamin582ba042016-07-07 12:33:25 -07004264 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004265 tests = append(tests, testCase{
4266 testType: clientTest,
4267 name: "ClientAuth-NoCertificate-Client-SSL3",
4268 config: Config{
4269 MaxVersion: VersionSSL30,
4270 ClientAuth: RequestClientCert,
4271 },
4272 })
4273 tests = append(tests, testCase{
4274 testType: serverTest,
4275 name: "ClientAuth-NoCertificate-Server-SSL3",
4276 config: Config{
4277 MaxVersion: VersionSSL30,
4278 },
4279 // Setting SSL_VERIFY_PEER allows anonymous clients.
4280 flags: []string{"-verify-peer"},
4281 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004282 tests = append(tests, testCase{
4283 testType: clientTest,
4284 name: "ClientAuth-NoCertificate-Client-TLS13",
4285 config: Config{
4286 MaxVersion: VersionTLS13,
4287 ClientAuth: RequestClientCert,
4288 },
4289 })
4290 tests = append(tests, testCase{
4291 testType: serverTest,
4292 name: "ClientAuth-NoCertificate-Server-TLS13",
4293 config: Config{
4294 MaxVersion: VersionTLS13,
4295 },
4296 // Setting SSL_VERIFY_PEER allows anonymous clients.
4297 flags: []string{"-verify-peer"},
4298 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004299 }
4300 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004301 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004302 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004303 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004304 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004305 ClientAuth: RequireAnyClientCert,
4306 },
4307 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004308 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4309 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004310 },
4311 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004312 tests = append(tests, testCase{
4313 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004314 name: "ClientAuth-RSA-Client-TLS13",
4315 config: Config{
4316 MaxVersion: VersionTLS13,
4317 ClientAuth: RequireAnyClientCert,
4318 },
4319 flags: []string{
4320 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4321 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4322 },
4323 })
4324 tests = append(tests, testCase{
4325 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004326 name: "ClientAuth-ECDSA-Client",
4327 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004328 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004329 ClientAuth: RequireAnyClientCert,
4330 },
4331 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004332 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4333 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004334 },
4335 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004336 tests = append(tests, testCase{
4337 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004338 name: "ClientAuth-ECDSA-Client-TLS13",
4339 config: Config{
4340 MaxVersion: VersionTLS13,
4341 ClientAuth: RequireAnyClientCert,
4342 },
4343 flags: []string{
4344 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4345 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4346 },
4347 })
4348 tests = append(tests, testCase{
4349 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004350 name: "ClientAuth-NoCertificate-OldCallback",
4351 config: Config{
4352 MaxVersion: VersionTLS12,
4353 ClientAuth: RequestClientCert,
4354 },
4355 flags: []string{"-use-old-client-cert-callback"},
4356 })
4357 tests = append(tests, testCase{
4358 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004359 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4360 config: Config{
4361 MaxVersion: VersionTLS13,
4362 ClientAuth: RequestClientCert,
4363 },
4364 flags: []string{"-use-old-client-cert-callback"},
4365 })
4366 tests = append(tests, testCase{
4367 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004368 name: "ClientAuth-OldCallback",
4369 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004370 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004371 ClientAuth: RequireAnyClientCert,
4372 },
4373 flags: []string{
4374 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4375 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4376 "-use-old-client-cert-callback",
4377 },
4378 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004379 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004380 testType: clientTest,
4381 name: "ClientAuth-OldCallback-TLS13",
4382 config: Config{
4383 MaxVersion: VersionTLS13,
4384 ClientAuth: RequireAnyClientCert,
4385 },
4386 flags: []string{
4387 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4388 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4389 "-use-old-client-cert-callback",
4390 },
4391 })
4392 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004393 testType: serverTest,
4394 name: "ClientAuth-Server",
4395 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004396 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004397 Certificates: []Certificate{rsaCertificate},
4398 },
4399 flags: []string{"-require-any-client-certificate"},
4400 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004401 tests = append(tests, testCase{
4402 testType: serverTest,
4403 name: "ClientAuth-Server-TLS13",
4404 config: Config{
4405 MaxVersion: VersionTLS13,
4406 Certificates: []Certificate{rsaCertificate},
4407 },
4408 flags: []string{"-require-any-client-certificate"},
4409 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004410
David Benjamin4c3ddf72016-06-29 18:13:53 -04004411 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004412 tests = append(tests, testCase{
4413 testType: serverTest,
4414 name: "Basic-Server-RSA",
4415 config: Config{
4416 MaxVersion: VersionTLS12,
4417 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4418 },
4419 flags: []string{
4420 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4421 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4422 },
4423 })
4424 tests = append(tests, testCase{
4425 testType: serverTest,
4426 name: "Basic-Server-ECDHE-RSA",
4427 config: Config{
4428 MaxVersion: VersionTLS12,
4429 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4430 },
4431 flags: []string{
4432 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4433 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4434 },
4435 })
4436 tests = append(tests, testCase{
4437 testType: serverTest,
4438 name: "Basic-Server-ECDHE-ECDSA",
4439 config: Config{
4440 MaxVersion: VersionTLS12,
4441 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4442 },
4443 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004444 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4445 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004446 },
4447 })
David Benjamin69522112017-03-28 15:38:29 -05004448 tests = append(tests, testCase{
4449 testType: serverTest,
4450 name: "Basic-Server-Ed25519",
4451 config: Config{
4452 MaxVersion: VersionTLS12,
4453 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4454 },
4455 flags: []string{
4456 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4457 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4458 "-enable-ed25519",
4459 },
4460 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004461
David Benjamin760b1dd2015-05-15 23:33:48 -04004462 // No session ticket support; server doesn't send NewSessionTicket.
4463 tests = append(tests, testCase{
4464 name: "SessionTicketsDisabled-Client",
4465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004466 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004467 SessionTicketsDisabled: true,
4468 },
4469 })
4470 tests = append(tests, testCase{
4471 testType: serverTest,
4472 name: "SessionTicketsDisabled-Server",
4473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004474 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004475 SessionTicketsDisabled: true,
4476 },
4477 })
4478
4479 // Skip ServerKeyExchange in PSK key exchange if there's no
4480 // identity hint.
4481 tests = append(tests, testCase{
4482 name: "EmptyPSKHint-Client",
4483 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004484 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004485 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4486 PreSharedKey: []byte("secret"),
4487 },
4488 flags: []string{"-psk", "secret"},
4489 })
4490 tests = append(tests, testCase{
4491 testType: serverTest,
4492 name: "EmptyPSKHint-Server",
4493 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004494 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004495 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4496 PreSharedKey: []byte("secret"),
4497 },
4498 flags: []string{"-psk", "secret"},
4499 })
4500
David Benjamin4c3ddf72016-06-29 18:13:53 -04004501 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004502 tests = append(tests, testCase{
4503 testType: clientTest,
4504 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004505 config: Config{
4506 MaxVersion: VersionTLS12,
4507 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004508 flags: []string{
4509 "-enable-ocsp-stapling",
4510 "-expect-ocsp-response",
4511 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004512 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004513 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004514 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004515 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004516 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004517 testType: serverTest,
4518 name: "OCSPStapling-Server",
4519 config: Config{
4520 MaxVersion: VersionTLS12,
4521 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004522 expectedOCSPResponse: testOCSPResponse,
4523 flags: []string{
4524 "-ocsp-response",
4525 base64.StdEncoding.EncodeToString(testOCSPResponse),
4526 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004527 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004528 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004529 tests = append(tests, testCase{
4530 testType: clientTest,
4531 name: "OCSPStapling-Client-TLS13",
4532 config: Config{
4533 MaxVersion: VersionTLS13,
4534 },
4535 flags: []string{
4536 "-enable-ocsp-stapling",
4537 "-expect-ocsp-response",
4538 base64.StdEncoding.EncodeToString(testOCSPResponse),
4539 "-verify-peer",
4540 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004541 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004542 })
4543 tests = append(tests, testCase{
4544 testType: serverTest,
4545 name: "OCSPStapling-Server-TLS13",
4546 config: Config{
4547 MaxVersion: VersionTLS13,
4548 },
4549 expectedOCSPResponse: testOCSPResponse,
4550 flags: []string{
4551 "-ocsp-response",
4552 base64.StdEncoding.EncodeToString(testOCSPResponse),
4553 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004554 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004555 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004556
David Benjamin4c3ddf72016-06-29 18:13:53 -04004557 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004558 for _, vers := range tlsVersions {
4559 if config.protocol == dtls && !vers.hasDTLS {
4560 continue
4561 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004562 for _, useCustomCallback := range []bool{false, true} {
4563 for _, testType := range []testType{clientTest, serverTest} {
4564 suffix := "-Client"
4565 if testType == serverTest {
4566 suffix = "-Server"
4567 }
4568 suffix += "-" + vers.name
4569 if useCustomCallback {
4570 suffix += "-CustomCallback"
4571 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004572
David Benjamin3a1dd462017-07-11 16:13:10 -04004573 flags := []string{"-verify-peer"}
4574 if testType == serverTest {
4575 flags = append(flags, "-require-any-client-certificate")
4576 }
4577 if useCustomCallback {
4578 flags = append(flags, "-use-custom-verify-callback")
4579 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004580
David Benjamin3a1dd462017-07-11 16:13:10 -04004581 tests = append(tests, testCase{
4582 testType: testType,
4583 name: "CertificateVerificationSucceed" + suffix,
4584 config: Config{
4585 MaxVersion: vers.version,
4586 Certificates: []Certificate{rsaCertificate},
4587 },
4588 tls13Variant: vers.tls13Variant,
4589 flags: append([]string{"-expect-verify-result"}, flags...),
4590 resumeSession: true,
4591 })
4592 tests = append(tests, testCase{
4593 testType: testType,
4594 name: "CertificateVerificationFail" + suffix,
4595 config: Config{
4596 MaxVersion: vers.version,
4597 Certificates: []Certificate{rsaCertificate},
4598 },
4599 tls13Variant: vers.tls13Variant,
4600 flags: append([]string{"-verify-fail"}, flags...),
4601 shouldFail: true,
4602 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4603 })
4604 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004605 }
4606
4607 // By default, the client is in a soft fail mode where the peer
4608 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004609 tests = append(tests, testCase{
4610 testType: clientTest,
4611 name: "CertificateVerificationSoftFail-" + vers.name,
4612 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004613 MaxVersion: vers.version,
4614 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004615 },
David Benjamina5022392017-07-10 17:40:39 -04004616 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004617 flags: []string{
4618 "-verify-fail",
4619 "-expect-verify-result",
4620 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004621 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004622 })
4623 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004624
David Benjamin1d4f4c02016-07-26 18:03:08 -04004625 tests = append(tests, testCase{
4626 name: "ShimSendAlert",
4627 flags: []string{"-send-alert"},
4628 shimWritesFirst: true,
4629 shouldFail: true,
4630 expectedLocalError: "remote error: decompression failure",
4631 })
4632
David Benjamin582ba042016-07-07 12:33:25 -07004633 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004634 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004635 name: "Renegotiate-Client",
4636 config: Config{
4637 MaxVersion: VersionTLS12,
4638 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004639 renegotiate: 1,
4640 flags: []string{
4641 "-renegotiate-freely",
4642 "-expect-total-renegotiations", "1",
4643 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004644 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004645
David Benjamin47921102016-07-28 11:29:18 -04004646 tests = append(tests, testCase{
4647 name: "SendHalfHelloRequest",
4648 config: Config{
4649 MaxVersion: VersionTLS12,
4650 Bugs: ProtocolBugs{
4651 PackHelloRequestWithFinished: config.packHandshakeFlight,
4652 },
4653 },
4654 sendHalfHelloRequest: true,
4655 flags: []string{"-renegotiate-ignore"},
4656 shouldFail: true,
4657 expectedError: ":UNEXPECTED_RECORD:",
4658 })
4659
David Benjamin760b1dd2015-05-15 23:33:48 -04004660 // NPN on client and server; results in post-handshake message.
4661 tests = append(tests, testCase{
4662 name: "NPN-Client",
4663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004664 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004665 NextProtos: []string{"foo"},
4666 },
4667 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004668 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004669 expectedNextProto: "foo",
4670 expectedNextProtoType: npn,
4671 })
4672 tests = append(tests, testCase{
4673 testType: serverTest,
4674 name: "NPN-Server",
4675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004676 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004677 NextProtos: []string{"bar"},
4678 },
4679 flags: []string{
4680 "-advertise-npn", "\x03foo\x03bar\x03baz",
4681 "-expect-next-proto", "bar",
4682 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004683 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004684 expectedNextProto: "bar",
4685 expectedNextProtoType: npn,
4686 })
4687
4688 // TODO(davidben): Add tests for when False Start doesn't trigger.
4689
4690 // Client does False Start and negotiates NPN.
4691 tests = append(tests, testCase{
4692 name: "FalseStart",
4693 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004694 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4696 NextProtos: []string{"foo"},
4697 Bugs: ProtocolBugs{
4698 ExpectFalseStart: true,
4699 },
4700 },
4701 flags: []string{
4702 "-false-start",
4703 "-select-next-proto", "foo",
4704 },
4705 shimWritesFirst: true,
4706 resumeSession: true,
4707 })
4708
4709 // Client does False Start and negotiates ALPN.
4710 tests = append(tests, testCase{
4711 name: "FalseStart-ALPN",
4712 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004713 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004714 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4715 NextProtos: []string{"foo"},
4716 Bugs: ProtocolBugs{
4717 ExpectFalseStart: true,
4718 },
4719 },
4720 flags: []string{
4721 "-false-start",
4722 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004723 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004724 },
4725 shimWritesFirst: true,
4726 resumeSession: true,
4727 })
4728
David Benjamin760b1dd2015-05-15 23:33:48 -04004729 // False Start without session tickets.
4730 tests = append(tests, testCase{
4731 name: "FalseStart-SessionTicketsDisabled",
4732 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004733 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004734 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4735 NextProtos: []string{"foo"},
4736 SessionTicketsDisabled: true,
4737 Bugs: ProtocolBugs{
4738 ExpectFalseStart: true,
4739 },
4740 },
4741 flags: []string{
4742 "-false-start",
4743 "-select-next-proto", "foo",
4744 },
4745 shimWritesFirst: true,
4746 })
4747
4748 // Server parses a V2ClientHello.
4749 tests = append(tests, testCase{
4750 testType: serverTest,
4751 name: "SendV2ClientHello",
4752 config: Config{
4753 // Choose a cipher suite that does not involve
4754 // elliptic curves, so no extensions are
4755 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004756 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004757 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004758 Bugs: ProtocolBugs{
4759 SendV2ClientHello: true,
4760 },
4761 },
4762 })
4763
Nick Harper60a85cb2016-09-23 16:25:11 -07004764 // Test Channel ID
4765 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004766 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004767 continue
4768 }
4769 // Client sends a Channel ID.
4770 tests = append(tests, testCase{
4771 name: "ChannelID-Client-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 RequestChannelID: true,
4775 },
David Benjamina5022392017-07-10 17:40:39 -04004776 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004777 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4778 resumeSession: true,
4779 expectChannelID: true,
4780 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004781
Nick Harper60a85cb2016-09-23 16:25:11 -07004782 // Server accepts a Channel ID.
4783 tests = append(tests, testCase{
4784 testType: serverTest,
4785 name: "ChannelID-Server-" + ver.name,
4786 config: Config{
4787 MaxVersion: ver.version,
4788 ChannelID: channelIDKey,
4789 },
David Benjamina5022392017-07-10 17:40:39 -04004790 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004791 flags: []string{
4792 "-expect-channel-id",
4793 base64.StdEncoding.EncodeToString(channelIDBytes),
4794 },
4795 resumeSession: true,
4796 expectChannelID: true,
4797 })
4798
4799 tests = append(tests, testCase{
4800 testType: serverTest,
4801 name: "InvalidChannelIDSignature-" + ver.name,
4802 config: Config{
4803 MaxVersion: ver.version,
4804 ChannelID: channelIDKey,
4805 Bugs: ProtocolBugs{
4806 InvalidChannelIDSignature: true,
4807 },
4808 },
David Benjamina5022392017-07-10 17:40:39 -04004809 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004810 flags: []string{"-enable-channel-id"},
4811 shouldFail: true,
4812 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4813 })
David Benjamin634f4752017-07-01 11:08:41 -04004814
4815 if ver.version < VersionTLS13 {
4816 // Channel ID requires ECDHE ciphers.
4817 tests = append(tests, testCase{
4818 testType: serverTest,
4819 name: "ChannelID-NoECDHE-" + ver.name,
4820 config: Config{
4821 MaxVersion: ver.version,
4822 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4823 ChannelID: channelIDKey,
4824 },
4825 expectChannelID: false,
4826 flags: []string{"-enable-channel-id"},
4827 })
4828
4829 // Sanity-check setting expectChannelID false works.
4830 tests = append(tests, testCase{
4831 testType: serverTest,
4832 name: "ChannelID-ECDHE-" + ver.name,
4833 config: Config{
4834 MaxVersion: ver.version,
4835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4836 ChannelID: channelIDKey,
4837 },
4838 expectChannelID: false,
4839 flags: []string{"-enable-channel-id"},
4840 shouldFail: true,
4841 expectedLocalError: "channel ID unexpectedly negotiated",
4842 })
4843 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004844 }
David Benjamin30789da2015-08-29 22:56:45 -04004845
David Benjaminf8fcdf32016-06-08 15:56:13 -04004846 // Channel ID and NPN at the same time, to ensure their relative
4847 // ordering is correct.
4848 tests = append(tests, testCase{
4849 name: "ChannelID-NPN-Client",
4850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004851 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004852 RequestChannelID: true,
4853 NextProtos: []string{"foo"},
4854 },
4855 flags: []string{
4856 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4857 "-select-next-proto", "foo",
4858 },
4859 resumeSession: true,
4860 expectChannelID: true,
4861 expectedNextProto: "foo",
4862 expectedNextProtoType: npn,
4863 })
4864 tests = append(tests, testCase{
4865 testType: serverTest,
4866 name: "ChannelID-NPN-Server",
4867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004868 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004869 ChannelID: channelIDKey,
4870 NextProtos: []string{"bar"},
4871 },
4872 flags: []string{
4873 "-expect-channel-id",
4874 base64.StdEncoding.EncodeToString(channelIDBytes),
4875 "-advertise-npn", "\x03foo\x03bar\x03baz",
4876 "-expect-next-proto", "bar",
4877 },
4878 resumeSession: true,
4879 expectChannelID: true,
4880 expectedNextProto: "bar",
4881 expectedNextProtoType: npn,
4882 })
4883
David Benjamin30789da2015-08-29 22:56:45 -04004884 // Bidirectional shutdown with the runner initiating.
4885 tests = append(tests, testCase{
4886 name: "Shutdown-Runner",
4887 config: Config{
4888 Bugs: ProtocolBugs{
4889 ExpectCloseNotify: true,
4890 },
4891 },
4892 flags: []string{"-check-close-notify"},
4893 })
4894
David Benjamine3843d42017-03-25 18:00:56 -05004895 if !config.implicitHandshake {
4896 // Bidirectional shutdown with the shim initiating. The runner,
4897 // in the meantime, sends garbage before the close_notify which
4898 // the shim must ignore. This test is disabled under implicit
4899 // handshake tests because the shim never reads or writes.
4900 tests = append(tests, testCase{
4901 name: "Shutdown-Shim",
4902 config: Config{
4903 MaxVersion: VersionTLS12,
4904 Bugs: ProtocolBugs{
4905 ExpectCloseNotify: true,
4906 },
David Benjamin30789da2015-08-29 22:56:45 -04004907 },
David Benjamine3843d42017-03-25 18:00:56 -05004908 shimShutsDown: true,
4909 sendEmptyRecords: 1,
4910 sendWarningAlerts: 1,
4911 flags: []string{"-check-close-notify"},
4912 })
4913 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004914 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004915 // TODO(davidben): DTLS 1.3 will want a similar thing for
4916 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004917 tests = append(tests, testCase{
4918 name: "SkipHelloVerifyRequest",
4919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004920 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004921 Bugs: ProtocolBugs{
4922 SkipHelloVerifyRequest: true,
4923 },
4924 },
4925 })
4926 }
4927
David Benjamin760b1dd2015-05-15 23:33:48 -04004928 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004929 test.protocol = config.protocol
4930 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004931 test.name += "-DTLS"
4932 }
David Benjamin582ba042016-07-07 12:33:25 -07004933 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004934 test.name += "-Async"
4935 test.flags = append(test.flags, "-async")
4936 } else {
4937 test.name += "-Sync"
4938 }
David Benjamin582ba042016-07-07 12:33:25 -07004939 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004940 test.name += "-SplitHandshakeRecords"
4941 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004942 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004943 test.config.Bugs.MaxPacketLength = 256
4944 test.flags = append(test.flags, "-mtu", "256")
4945 }
4946 }
David Benjamin582ba042016-07-07 12:33:25 -07004947 if config.packHandshakeFlight {
4948 test.name += "-PackHandshakeFlight"
4949 test.config.Bugs.PackHandshakeFlight = true
4950 }
David Benjamine3843d42017-03-25 18:00:56 -05004951 if config.implicitHandshake {
4952 test.name += "-ImplicitHandshake"
4953 test.flags = append(test.flags, "-implicit-handshake")
4954 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004955 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004956 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004957}
4958
Adam Langley524e7172015-02-20 16:04:00 -08004959func addDDoSCallbackTests() {
4960 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004961 for _, resume := range []bool{false, true} {
4962 suffix := "Resume"
4963 if resume {
4964 suffix = "No" + suffix
4965 }
4966
4967 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004968 testType: serverTest,
4969 name: "Server-DDoS-OK-" + suffix,
4970 config: Config{
4971 MaxVersion: VersionTLS12,
4972 },
Adam Langley524e7172015-02-20 16:04:00 -08004973 flags: []string{"-install-ddos-callback"},
4974 resumeSession: resume,
4975 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004976 testCases = append(testCases, testCase{
4977 testType: serverTest,
4978 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4979 config: Config{
4980 MaxVersion: VersionTLS13,
4981 },
4982 flags: []string{"-install-ddos-callback"},
4983 resumeSession: resume,
4984 })
Adam Langley524e7172015-02-20 16:04:00 -08004985
4986 failFlag := "-fail-ddos-callback"
4987 if resume {
4988 failFlag = "-fail-second-ddos-callback"
4989 }
4990 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004991 testType: serverTest,
4992 name: "Server-DDoS-Reject-" + suffix,
4993 config: Config{
4994 MaxVersion: VersionTLS12,
4995 },
David Benjamin2c66e072016-09-16 15:58:00 -04004996 flags: []string{"-install-ddos-callback", failFlag},
4997 resumeSession: resume,
4998 shouldFail: true,
4999 expectedError: ":CONNECTION_REJECTED:",
5000 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005001 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005002 testCases = append(testCases, testCase{
5003 testType: serverTest,
5004 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5005 config: Config{
5006 MaxVersion: VersionTLS13,
5007 },
David Benjamin2c66e072016-09-16 15:58:00 -04005008 flags: []string{"-install-ddos-callback", failFlag},
5009 resumeSession: resume,
5010 shouldFail: true,
5011 expectedError: ":CONNECTION_REJECTED:",
5012 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005013 })
Adam Langley524e7172015-02-20 16:04:00 -08005014 }
5015}
5016
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005017func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005018 for _, protocol := range []protocol{tls, dtls} {
5019 for _, shimVers := range allVersions(protocol) {
5020 // Assemble flags to disable all newer versions on the shim.
5021 var flags []string
5022 for _, vers := range allVersions(protocol) {
5023 if vers.version > shimVers.version {
5024 flags = append(flags, vers.excludeFlag)
5025 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005026 }
Steven Valdez520e1222017-06-13 12:45:25 -04005027
5028 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5029
5030 if shimVers.tls13Variant != 0 {
5031 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5032 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5033 }
5034
5035 // Test configuring the runner's maximum version.
5036 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005037 expectedVersion := shimVers.version
5038 if runnerVers.version < shimVers.version {
5039 expectedVersion = runnerVers.version
5040 }
Steven Valdez520e1222017-06-13 12:45:25 -04005041 // When running and shim have different TLS 1.3 variants enabled,
5042 // shim clients are expected to fall back to TLS 1.2, while shim
5043 // servers support both variants when enabled when the experiment is
5044 // enabled.
5045 expectedServerVersion := expectedVersion
5046 expectedClientVersion := expectedVersion
5047 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5048 expectedClientVersion = VersionTLS12
5049 expectedServerVersion = VersionTLS12
5050 if shimVers.tls13Variant != TLS13Default {
5051 expectedServerVersion = VersionTLS13
5052 }
5053 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005054
David Benjamin8b8c0062014-11-23 02:47:52 -05005055 suffix := shimVers.name + "-" + runnerVers.name
5056 if protocol == dtls {
5057 suffix += "-DTLS"
5058 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005059
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005060 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005061 clientVers := shimVers.version
5062 if clientVers > VersionTLS10 {
5063 clientVers = VersionTLS10
5064 }
Steven Valdez520e1222017-06-13 12:45:25 -04005065 clientVers = recordVersionToWire(clientVers, protocol)
5066 serverVers := expectedServerVersion
5067 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005068 serverVers = VersionTLS10
5069 }
Steven Valdez520e1222017-06-13 12:45:25 -04005070 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005071
David Benjamin8b8c0062014-11-23 02:47:52 -05005072 testCases = append(testCases, testCase{
5073 protocol: protocol,
5074 testType: clientTest,
5075 name: "VersionNegotiation-Client-" + suffix,
5076 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005077 MaxVersion: runnerVers.version,
5078 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005079 Bugs: ProtocolBugs{
5080 ExpectInitialRecordVersion: clientVers,
5081 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005082 },
5083 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005084 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005085 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005086 testCases = append(testCases, testCase{
5087 protocol: protocol,
5088 testType: clientTest,
5089 name: "VersionNegotiation-Client2-" + suffix,
5090 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005091 MaxVersion: runnerVers.version,
5092 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005093 Bugs: ProtocolBugs{
5094 ExpectInitialRecordVersion: clientVers,
5095 },
5096 },
Steven Valdez520e1222017-06-13 12:45:25 -04005097 flags: flags2,
5098 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005099 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005100
5101 testCases = append(testCases, testCase{
5102 protocol: protocol,
5103 testType: serverTest,
5104 name: "VersionNegotiation-Server-" + suffix,
5105 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005106 MaxVersion: runnerVers.version,
5107 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005108 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005109 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005110 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005111 },
5112 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005113 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005114 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005115 testCases = append(testCases, testCase{
5116 protocol: protocol,
5117 testType: serverTest,
5118 name: "VersionNegotiation-Server2-" + suffix,
5119 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005120 MaxVersion: runnerVers.version,
5121 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005122 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005123 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005124 },
5125 },
Steven Valdez520e1222017-06-13 12:45:25 -04005126 flags: flags2,
5127 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005128 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005129 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005130 }
5131 }
David Benjamin95c69562016-06-29 18:15:03 -04005132
Steven Valdezfdd10992016-09-15 16:27:05 -04005133 // Test the version extension at all versions.
5134 for _, vers := range tlsVersions {
5135 protocols := []protocol{tls}
5136 if vers.hasDTLS {
5137 protocols = append(protocols, dtls)
5138 }
5139 for _, protocol := range protocols {
5140 suffix := vers.name
5141 if protocol == dtls {
5142 suffix += "-DTLS"
5143 }
5144
Steven Valdezfdd10992016-09-15 16:27:05 -04005145 testCases = append(testCases, testCase{
5146 protocol: protocol,
5147 testType: serverTest,
5148 name: "VersionNegotiationExtension-" + suffix,
5149 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005150 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005151 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005152 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005153 },
5154 },
5155 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005156 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005157 })
5158 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005159 }
5160
5161 // If all versions are unknown, negotiation fails.
5162 testCases = append(testCases, testCase{
5163 testType: serverTest,
5164 name: "NoSupportedVersions",
5165 config: Config{
5166 Bugs: ProtocolBugs{
5167 SendSupportedVersions: []uint16{0x1111},
5168 },
5169 },
5170 shouldFail: true,
5171 expectedError: ":UNSUPPORTED_PROTOCOL:",
5172 })
5173 testCases = append(testCases, testCase{
5174 protocol: dtls,
5175 testType: serverTest,
5176 name: "NoSupportedVersions-DTLS",
5177 config: Config{
5178 Bugs: ProtocolBugs{
5179 SendSupportedVersions: []uint16{0x1111},
5180 },
5181 },
5182 shouldFail: true,
5183 expectedError: ":UNSUPPORTED_PROTOCOL:",
5184 })
5185
5186 testCases = append(testCases, testCase{
5187 testType: serverTest,
5188 name: "ClientHelloVersionTooHigh",
5189 config: Config{
5190 MaxVersion: VersionTLS13,
5191 Bugs: ProtocolBugs{
5192 SendClientVersion: 0x0304,
5193 OmitSupportedVersions: true,
5194 },
5195 },
5196 expectedVersion: VersionTLS12,
5197 })
5198
5199 testCases = append(testCases, testCase{
5200 testType: serverTest,
5201 name: "ConflictingVersionNegotiation",
5202 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005203 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005204 SendClientVersion: VersionTLS12,
5205 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005206 },
5207 },
David Benjaminad75a662016-09-30 15:42:59 -04005208 // The extension takes precedence over the ClientHello version.
5209 expectedVersion: VersionTLS11,
5210 })
5211
5212 testCases = append(testCases, testCase{
5213 testType: serverTest,
5214 name: "ConflictingVersionNegotiation-2",
5215 config: Config{
5216 Bugs: ProtocolBugs{
5217 SendClientVersion: VersionTLS11,
5218 SendSupportedVersions: []uint16{VersionTLS12},
5219 },
5220 },
5221 // The extension takes precedence over the ClientHello version.
5222 expectedVersion: VersionTLS12,
5223 })
5224
5225 testCases = append(testCases, testCase{
5226 testType: serverTest,
5227 name: "RejectFinalTLS13",
5228 config: Config{
5229 Bugs: ProtocolBugs{
5230 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5231 },
5232 },
5233 // We currently implement a draft TLS 1.3 version. Ensure that
5234 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005235 expectedVersion: VersionTLS12,
5236 })
5237
Steven Valdez038da9b2017-07-10 12:57:25 -04005238 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5239 // the ServerHello.
5240 testCases = append(testCases, testCase{
5241 testType: clientTest,
5242 name: "SupportedVersionSelection-TLS12",
5243 config: Config{
5244 MaxVersion: VersionTLS12,
5245 Bugs: ProtocolBugs{
5246 SendServerSupportedExtensionVersion: VersionTLS12,
5247 },
5248 },
5249 shouldFail: true,
5250 expectedError: ":UNEXPECTED_EXTENSION:",
5251 })
5252
5253 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5254 // supported_versions extension in the ServerHello.
5255 testCases = append(testCases, testCase{
5256 testType: clientTest,
5257 name: "SupportedVersionSelection-TLS13",
5258 config: Config{
5259 MaxVersion: VersionTLS13,
5260 Bugs: ProtocolBugs{
5261 SendServerSupportedExtensionVersion: tls13DraftVersion,
5262 },
5263 },
5264 shouldFail: true,
5265 expectedError: ":UNEXPECTED_EXTENSION:",
5266 })
5267
Brian Smithf85d3232016-10-28 10:34:06 -10005268 // Test that the maximum version is selected regardless of the
5269 // client-sent order.
5270 testCases = append(testCases, testCase{
5271 testType: serverTest,
5272 name: "IgnoreClientVersionOrder",
5273 config: Config{
5274 Bugs: ProtocolBugs{
5275 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5276 },
5277 },
5278 expectedVersion: VersionTLS13,
5279 })
5280
David Benjamin95c69562016-06-29 18:15:03 -04005281 // Test for version tolerance.
5282 testCases = append(testCases, testCase{
5283 testType: serverTest,
5284 name: "MinorVersionTolerance",
5285 config: Config{
5286 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005287 SendClientVersion: 0x03ff,
5288 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005289 },
5290 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005291 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005292 })
5293 testCases = append(testCases, testCase{
5294 testType: serverTest,
5295 name: "MajorVersionTolerance",
5296 config: Config{
5297 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005298 SendClientVersion: 0x0400,
5299 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005300 },
5301 },
David Benjaminad75a662016-09-30 15:42:59 -04005302 // TLS 1.3 must be negotiated with the supported_versions
5303 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005304 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005305 })
David Benjaminad75a662016-09-30 15:42:59 -04005306 testCases = append(testCases, testCase{
5307 testType: serverTest,
5308 name: "VersionTolerance-TLS13",
5309 config: Config{
5310 Bugs: ProtocolBugs{
5311 // Although TLS 1.3 does not use
5312 // ClientHello.version, it still tolerates high
5313 // values there.
5314 SendClientVersion: 0x0400,
5315 },
5316 },
5317 expectedVersion: VersionTLS13,
5318 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005319
David Benjamin95c69562016-06-29 18:15:03 -04005320 testCases = append(testCases, testCase{
5321 protocol: dtls,
5322 testType: serverTest,
5323 name: "MinorVersionTolerance-DTLS",
5324 config: Config{
5325 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005326 SendClientVersion: 0xfe00,
5327 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005328 },
5329 },
5330 expectedVersion: VersionTLS12,
5331 })
5332 testCases = append(testCases, testCase{
5333 protocol: dtls,
5334 testType: serverTest,
5335 name: "MajorVersionTolerance-DTLS",
5336 config: Config{
5337 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005338 SendClientVersion: 0xfdff,
5339 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005340 },
5341 },
5342 expectedVersion: VersionTLS12,
5343 })
5344
5345 // Test that versions below 3.0 are rejected.
5346 testCases = append(testCases, testCase{
5347 testType: serverTest,
5348 name: "VersionTooLow",
5349 config: Config{
5350 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005351 SendClientVersion: 0x0200,
5352 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005353 },
5354 },
5355 shouldFail: true,
5356 expectedError: ":UNSUPPORTED_PROTOCOL:",
5357 })
5358 testCases = append(testCases, testCase{
5359 protocol: dtls,
5360 testType: serverTest,
5361 name: "VersionTooLow-DTLS",
5362 config: Config{
5363 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005364 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005365 },
5366 },
5367 shouldFail: true,
5368 expectedError: ":UNSUPPORTED_PROTOCOL:",
5369 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005370
David Benjamin2dc02042016-09-19 19:57:37 -04005371 testCases = append(testCases, testCase{
5372 name: "ServerBogusVersion",
5373 config: Config{
5374 Bugs: ProtocolBugs{
5375 SendServerHelloVersion: 0x1234,
5376 },
5377 },
5378 shouldFail: true,
5379 expectedError: ":UNSUPPORTED_PROTOCOL:",
5380 })
5381
David Benjamin1f61f0d2016-07-10 12:20:35 -04005382 // Test TLS 1.3's downgrade signal.
5383 testCases = append(testCases, testCase{
5384 name: "Downgrade-TLS12-Client",
5385 config: Config{
5386 Bugs: ProtocolBugs{
5387 NegotiateVersion: VersionTLS12,
5388 },
5389 },
David Benjamin592b5322016-09-30 15:15:01 -04005390 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005391 // TODO(davidben): This test should fail once TLS 1.3 is final
5392 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005393 })
5394 testCases = append(testCases, testCase{
5395 testType: serverTest,
5396 name: "Downgrade-TLS12-Server",
5397 config: Config{
5398 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005399 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005400 },
5401 },
David Benjamin592b5322016-09-30 15:15:01 -04005402 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005403 // TODO(davidben): This test should fail once TLS 1.3 is final
5404 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005405 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005406}
5407
David Benjaminaccb4542014-12-12 23:44:33 -05005408func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005409 for _, protocol := range []protocol{tls, dtls} {
5410 for _, shimVers := range allVersions(protocol) {
5411 // Assemble flags to disable all older versions on the shim.
5412 var flags []string
5413 for _, vers := range allVersions(protocol) {
5414 if vers.version < shimVers.version {
5415 flags = append(flags, vers.excludeFlag)
5416 }
David Benjaminaccb4542014-12-12 23:44:33 -05005417 }
Steven Valdez520e1222017-06-13 12:45:25 -04005418
5419 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5420
5421 if shimVers.tls13Variant != 0 {
5422 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5423 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5424 }
5425
5426 for _, runnerVers := range allVersions(protocol) {
5427 // Different TLS 1.3 variants are incompatible with each other and don't
5428 // produce consistent minimum versions.
5429 //
5430 // TODO(davidben): Fold these tests (the main value is in the
5431 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5432 // on intended shim behavior, not the shim + runner combination.
5433 if shimVers.tls13Variant != runnerVers.tls13Variant {
5434 continue
5435 }
5436
David Benjaminaccb4542014-12-12 23:44:33 -05005437 suffix := shimVers.name + "-" + runnerVers.name
5438 if protocol == dtls {
5439 suffix += "-DTLS"
5440 }
David Benjaminaccb4542014-12-12 23:44:33 -05005441
David Benjaminaccb4542014-12-12 23:44:33 -05005442 var expectedVersion uint16
5443 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005444 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005445 if runnerVers.version >= shimVers.version {
5446 expectedVersion = runnerVers.version
5447 } else {
5448 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005449 expectedError = ":UNSUPPORTED_PROTOCOL:"
5450 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005451 }
5452
5453 testCases = append(testCases, testCase{
5454 protocol: protocol,
5455 testType: clientTest,
5456 name: "MinimumVersion-Client-" + suffix,
5457 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005458 MaxVersion: runnerVers.version,
5459 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005460 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005461 // Ensure the server does not decline to
5462 // select a version (versions extension) or
5463 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005464 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005465 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005466 },
David Benjaminaccb4542014-12-12 23:44:33 -05005467 },
David Benjamin87909c02014-12-13 01:55:01 -05005468 flags: flags,
5469 expectedVersion: expectedVersion,
5470 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005471 expectedError: expectedError,
5472 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005473 })
5474 testCases = append(testCases, testCase{
5475 protocol: protocol,
5476 testType: clientTest,
5477 name: "MinimumVersion-Client2-" + suffix,
5478 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005479 MaxVersion: runnerVers.version,
5480 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005481 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005482 // Ensure the server does not decline to
5483 // select a version (versions extension) or
5484 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005485 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005486 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005487 },
David Benjaminaccb4542014-12-12 23:44:33 -05005488 },
Steven Valdez520e1222017-06-13 12:45:25 -04005489 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005490 expectedVersion: expectedVersion,
5491 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005492 expectedError: expectedError,
5493 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005494 })
5495
5496 testCases = append(testCases, testCase{
5497 protocol: protocol,
5498 testType: serverTest,
5499 name: "MinimumVersion-Server-" + suffix,
5500 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005501 MaxVersion: runnerVers.version,
5502 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005503 },
David Benjamin87909c02014-12-13 01:55:01 -05005504 flags: flags,
5505 expectedVersion: expectedVersion,
5506 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005507 expectedError: expectedError,
5508 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005509 })
5510 testCases = append(testCases, testCase{
5511 protocol: protocol,
5512 testType: serverTest,
5513 name: "MinimumVersion-Server2-" + suffix,
5514 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005515 MaxVersion: runnerVers.version,
5516 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005517 },
Steven Valdez520e1222017-06-13 12:45:25 -04005518 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005519 expectedVersion: expectedVersion,
5520 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005521 expectedError: expectedError,
5522 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005523 })
5524 }
5525 }
5526 }
5527}
5528
David Benjamine78bfde2014-09-06 12:45:15 -04005529func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005530 // TODO(davidben): Extensions, where applicable, all move their server
5531 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5532 // tests for both. Also test interaction with 0-RTT when implemented.
5533
David Benjamin97d17d92016-07-14 16:12:00 -04005534 // Repeat extensions tests all versions except SSL 3.0.
5535 for _, ver := range tlsVersions {
5536 if ver.version == VersionSSL30 {
5537 continue
5538 }
5539
David Benjamin97d17d92016-07-14 16:12:00 -04005540 // Test that duplicate extensions are rejected.
5541 testCases = append(testCases, testCase{
5542 testType: clientTest,
5543 name: "DuplicateExtensionClient-" + ver.name,
5544 config: Config{
5545 MaxVersion: ver.version,
5546 Bugs: ProtocolBugs{
5547 DuplicateExtension: true,
5548 },
David Benjamine78bfde2014-09-06 12:45:15 -04005549 },
David Benjamina5022392017-07-10 17:40:39 -04005550 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005551 shouldFail: true,
5552 expectedLocalError: "remote error: error decoding message",
5553 })
5554 testCases = append(testCases, testCase{
5555 testType: serverTest,
5556 name: "DuplicateExtensionServer-" + ver.name,
5557 config: Config{
5558 MaxVersion: ver.version,
5559 Bugs: ProtocolBugs{
5560 DuplicateExtension: true,
5561 },
David Benjamine78bfde2014-09-06 12:45:15 -04005562 },
David Benjamina5022392017-07-10 17:40:39 -04005563 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005564 shouldFail: true,
5565 expectedLocalError: "remote error: error decoding message",
5566 })
5567
5568 // Test SNI.
5569 testCases = append(testCases, testCase{
5570 testType: clientTest,
5571 name: "ServerNameExtensionClient-" + ver.name,
5572 config: Config{
5573 MaxVersion: ver.version,
5574 Bugs: ProtocolBugs{
5575 ExpectServerName: "example.com",
5576 },
David Benjamine78bfde2014-09-06 12:45:15 -04005577 },
David Benjamina5022392017-07-10 17:40:39 -04005578 tls13Variant: ver.tls13Variant,
5579 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005580 })
5581 testCases = append(testCases, testCase{
5582 testType: clientTest,
5583 name: "ServerNameExtensionClientMismatch-" + ver.name,
5584 config: Config{
5585 MaxVersion: ver.version,
5586 Bugs: ProtocolBugs{
5587 ExpectServerName: "mismatch.com",
5588 },
David Benjamine78bfde2014-09-06 12:45:15 -04005589 },
David Benjamin97d17d92016-07-14 16:12:00 -04005590 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005591 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005592 shouldFail: true,
5593 expectedLocalError: "tls: unexpected server name",
5594 })
5595 testCases = append(testCases, testCase{
5596 testType: clientTest,
5597 name: "ServerNameExtensionClientMissing-" + ver.name,
5598 config: Config{
5599 MaxVersion: ver.version,
5600 Bugs: ProtocolBugs{
5601 ExpectServerName: "missing.com",
5602 },
David Benjamine78bfde2014-09-06 12:45:15 -04005603 },
David Benjamina5022392017-07-10 17:40:39 -04005604 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005605 shouldFail: true,
5606 expectedLocalError: "tls: unexpected server name",
5607 })
5608 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005609 testType: clientTest,
5610 name: "TolerateServerNameAck-" + ver.name,
5611 config: Config{
5612 MaxVersion: ver.version,
5613 Bugs: ProtocolBugs{
5614 SendServerNameAck: true,
5615 },
5616 },
David Benjamina5022392017-07-10 17:40:39 -04005617 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005618 flags: []string{"-host-name", "example.com"},
5619 resumeSession: true,
5620 })
5621 testCases = append(testCases, testCase{
5622 testType: clientTest,
5623 name: "UnsolicitedServerNameAck-" + ver.name,
5624 config: Config{
5625 MaxVersion: ver.version,
5626 Bugs: ProtocolBugs{
5627 SendServerNameAck: true,
5628 },
5629 },
David Benjamina5022392017-07-10 17:40:39 -04005630 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005631 shouldFail: true,
5632 expectedError: ":UNEXPECTED_EXTENSION:",
5633 expectedLocalError: "remote error: unsupported extension",
5634 })
5635 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005636 testType: serverTest,
5637 name: "ServerNameExtensionServer-" + ver.name,
5638 config: Config{
5639 MaxVersion: ver.version,
5640 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005641 },
David Benjamina5022392017-07-10 17:40:39 -04005642 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005643 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005644 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005645 })
5646
5647 // Test ALPN.
5648 testCases = append(testCases, testCase{
5649 testType: clientTest,
5650 name: "ALPNClient-" + ver.name,
5651 config: Config{
5652 MaxVersion: ver.version,
5653 NextProtos: []string{"foo"},
5654 },
5655 flags: []string{
5656 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5657 "-expect-alpn", "foo",
5658 },
David Benjamina5022392017-07-10 17:40:39 -04005659 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005660 expectedNextProto: "foo",
5661 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005662 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005663 })
5664 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005665 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005666 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005667 config: Config{
5668 MaxVersion: ver.version,
5669 Bugs: ProtocolBugs{
5670 SendALPN: "baz",
5671 },
5672 },
5673 flags: []string{
5674 "-advertise-alpn", "\x03foo\x03bar",
5675 },
David Benjamina5022392017-07-10 17:40:39 -04005676 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005677 shouldFail: true,
5678 expectedError: ":INVALID_ALPN_PROTOCOL:",
5679 expectedLocalError: "remote error: illegal parameter",
5680 })
5681 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005682 testType: clientTest,
5683 name: "ALPNClient-AllowUnknown-" + ver.name,
5684 config: Config{
5685 MaxVersion: ver.version,
5686 Bugs: ProtocolBugs{
5687 SendALPN: "baz",
5688 },
5689 },
5690 flags: []string{
5691 "-advertise-alpn", "\x03foo\x03bar",
5692 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005693 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005694 },
David Benjamina5022392017-07-10 17:40:39 -04005695 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005696 })
5697 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005698 testType: serverTest,
5699 name: "ALPNServer-" + ver.name,
5700 config: Config{
5701 MaxVersion: ver.version,
5702 NextProtos: []string{"foo", "bar", "baz"},
5703 },
5704 flags: []string{
5705 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5706 "-select-alpn", "foo",
5707 },
David Benjamina5022392017-07-10 17:40:39 -04005708 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005709 expectedNextProto: "foo",
5710 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005711 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005712 })
5713 testCases = append(testCases, testCase{
5714 testType: serverTest,
5715 name: "ALPNServer-Decline-" + ver.name,
5716 config: Config{
5717 MaxVersion: ver.version,
5718 NextProtos: []string{"foo", "bar", "baz"},
5719 },
5720 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005721 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005722 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005723 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005724 })
5725
David Benjamin25fe85b2016-08-09 20:00:32 -04005726 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5727 // called once.
5728 testCases = append(testCases, testCase{
5729 testType: serverTest,
5730 name: "ALPNServer-Async-" + ver.name,
5731 config: Config{
5732 MaxVersion: ver.version,
5733 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005734 // Prior to TLS 1.3, exercise the asynchronous session callback.
5735 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005736 },
5737 flags: []string{
5738 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5739 "-select-alpn", "foo",
5740 "-async",
5741 },
David Benjamina5022392017-07-10 17:40:39 -04005742 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005743 expectedNextProto: "foo",
5744 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005745 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005746 })
5747
David Benjamin97d17d92016-07-14 16:12:00 -04005748 var emptyString string
5749 testCases = append(testCases, testCase{
5750 testType: clientTest,
5751 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5752 config: Config{
5753 MaxVersion: ver.version,
5754 NextProtos: []string{""},
5755 Bugs: ProtocolBugs{
5756 // A server returning an empty ALPN protocol
5757 // should be rejected.
5758 ALPNProtocol: &emptyString,
5759 },
5760 },
5761 flags: []string{
5762 "-advertise-alpn", "\x03foo",
5763 },
David Benjamina5022392017-07-10 17:40:39 -04005764 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005765 shouldFail: true,
5766 expectedError: ":PARSE_TLSEXT:",
5767 })
5768 testCases = append(testCases, testCase{
5769 testType: serverTest,
5770 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5771 config: Config{
5772 MaxVersion: ver.version,
5773 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005774 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005775 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005776 },
David Benjamin97d17d92016-07-14 16:12:00 -04005777 flags: []string{
5778 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005779 },
David Benjamina5022392017-07-10 17:40:39 -04005780 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005781 shouldFail: true,
5782 expectedError: ":PARSE_TLSEXT:",
5783 })
5784
5785 // Test NPN and the interaction with ALPN.
5786 if ver.version < VersionTLS13 {
5787 // Test that the server prefers ALPN over NPN.
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "ALPNServer-Preferred-" + ver.name,
5791 config: Config{
5792 MaxVersion: ver.version,
5793 NextProtos: []string{"foo", "bar", "baz"},
5794 },
5795 flags: []string{
5796 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5797 "-select-alpn", "foo",
5798 "-advertise-npn", "\x03foo\x03bar\x03baz",
5799 },
David Benjamina5022392017-07-10 17:40:39 -04005800 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005801 expectedNextProto: "foo",
5802 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005803 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005804 })
5805 testCases = append(testCases, testCase{
5806 testType: serverTest,
5807 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5808 config: Config{
5809 MaxVersion: ver.version,
5810 NextProtos: []string{"foo", "bar", "baz"},
5811 Bugs: ProtocolBugs{
5812 SwapNPNAndALPN: true,
5813 },
5814 },
5815 flags: []string{
5816 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5817 "-select-alpn", "foo",
5818 "-advertise-npn", "\x03foo\x03bar\x03baz",
5819 },
David Benjamina5022392017-07-10 17:40:39 -04005820 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005821 expectedNextProto: "foo",
5822 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005823 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005824 })
5825
5826 // Test that negotiating both NPN and ALPN is forbidden.
5827 testCases = append(testCases, testCase{
5828 name: "NegotiateALPNAndNPN-" + ver.name,
5829 config: Config{
5830 MaxVersion: ver.version,
5831 NextProtos: []string{"foo", "bar", "baz"},
5832 Bugs: ProtocolBugs{
5833 NegotiateALPNAndNPN: true,
5834 },
5835 },
5836 flags: []string{
5837 "-advertise-alpn", "\x03foo",
5838 "-select-next-proto", "foo",
5839 },
David Benjamina5022392017-07-10 17:40:39 -04005840 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005841 shouldFail: true,
5842 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5843 })
5844 testCases = append(testCases, testCase{
5845 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5846 config: Config{
5847 MaxVersion: ver.version,
5848 NextProtos: []string{"foo", "bar", "baz"},
5849 Bugs: ProtocolBugs{
5850 NegotiateALPNAndNPN: true,
5851 SwapNPNAndALPN: true,
5852 },
5853 },
5854 flags: []string{
5855 "-advertise-alpn", "\x03foo",
5856 "-select-next-proto", "foo",
5857 },
David Benjamina5022392017-07-10 17:40:39 -04005858 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005859 shouldFail: true,
5860 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5861 })
David Benjamin97d17d92016-07-14 16:12:00 -04005862 }
5863
5864 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005865
5866 // Resume with a corrupt ticket.
5867 testCases = append(testCases, testCase{
5868 testType: serverTest,
5869 name: "CorruptTicket-" + ver.name,
5870 config: Config{
5871 MaxVersion: ver.version,
5872 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005873 FilterTicket: func(in []byte) ([]byte, error) {
5874 in[len(in)-1] ^= 1
5875 return in, nil
5876 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005877 },
5878 },
David Benjamina5022392017-07-10 17:40:39 -04005879 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005880 resumeSession: true,
5881 expectResumeRejected: true,
5882 })
5883 // Test the ticket callback, with and without renewal.
5884 testCases = append(testCases, testCase{
5885 testType: serverTest,
5886 name: "TicketCallback-" + ver.name,
5887 config: Config{
5888 MaxVersion: ver.version,
5889 },
David Benjamina5022392017-07-10 17:40:39 -04005890 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005891 resumeSession: true,
5892 flags: []string{"-use-ticket-callback"},
5893 })
5894 testCases = append(testCases, testCase{
5895 testType: serverTest,
5896 name: "TicketCallback-Renew-" + ver.name,
5897 config: Config{
5898 MaxVersion: ver.version,
5899 Bugs: ProtocolBugs{
5900 ExpectNewTicket: true,
5901 },
5902 },
David Benjamina5022392017-07-10 17:40:39 -04005903 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005904 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5905 resumeSession: true,
5906 })
5907
5908 // Test that the ticket callback is only called once when everything before
5909 // it in the ClientHello is asynchronous. This corrupts the ticket so
5910 // certificate selection callbacks run.
5911 testCases = append(testCases, testCase{
5912 testType: serverTest,
5913 name: "TicketCallback-SingleCall-" + ver.name,
5914 config: Config{
5915 MaxVersion: ver.version,
5916 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005917 FilterTicket: func(in []byte) ([]byte, error) {
5918 in[len(in)-1] ^= 1
5919 return in, nil
5920 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005921 },
5922 },
David Benjamina5022392017-07-10 17:40:39 -04005923 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005924 resumeSession: true,
5925 expectResumeRejected: true,
5926 flags: []string{
5927 "-use-ticket-callback",
5928 "-async",
5929 },
5930 })
5931
David Benjamind4c349b2017-02-09 14:07:17 -05005932 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005933 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005934 testCases = append(testCases, testCase{
5935 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005936 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005937 config: Config{
5938 MaxVersion: ver.version,
5939 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005940 EmptyTicketSessionID: true,
5941 },
5942 },
5943 resumeSession: true,
5944 })
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
5947 name: "TicketSessionIDLength-16-" + ver.name,
5948 config: Config{
5949 MaxVersion: ver.version,
5950 Bugs: ProtocolBugs{
5951 TicketSessionIDLength: 16,
5952 },
5953 },
5954 resumeSession: true,
5955 })
5956 testCases = append(testCases, testCase{
5957 testType: serverTest,
5958 name: "TicketSessionIDLength-32-" + ver.name,
5959 config: Config{
5960 MaxVersion: ver.version,
5961 Bugs: ProtocolBugs{
5962 TicketSessionIDLength: 32,
5963 },
5964 },
5965 resumeSession: true,
5966 })
5967 testCases = append(testCases, testCase{
5968 testType: serverTest,
5969 name: "TicketSessionIDLength-33-" + ver.name,
5970 config: Config{
5971 MaxVersion: ver.version,
5972 Bugs: ProtocolBugs{
5973 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005974 },
5975 },
5976 resumeSession: true,
5977 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005978 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005979 expectedError: ":DECODE_ERROR:",
5980 })
5981 }
5982
5983 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5984 // are ignored.
5985 if ver.hasDTLS {
5986 testCases = append(testCases, testCase{
5987 protocol: dtls,
5988 name: "SRTP-Client-" + ver.name,
5989 config: Config{
5990 MaxVersion: ver.version,
5991 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5992 },
5993 flags: []string{
5994 "-srtp-profiles",
5995 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5996 },
5997 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5998 })
5999 testCases = append(testCases, testCase{
6000 protocol: dtls,
6001 testType: serverTest,
6002 name: "SRTP-Server-" + ver.name,
6003 config: Config{
6004 MaxVersion: ver.version,
6005 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6006 },
6007 flags: []string{
6008 "-srtp-profiles",
6009 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6010 },
6011 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6012 })
6013 // Test that the MKI is ignored.
6014 testCases = append(testCases, testCase{
6015 protocol: dtls,
6016 testType: serverTest,
6017 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6018 config: Config{
6019 MaxVersion: ver.version,
6020 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6021 Bugs: ProtocolBugs{
6022 SRTPMasterKeyIdentifer: "bogus",
6023 },
6024 },
6025 flags: []string{
6026 "-srtp-profiles",
6027 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6028 },
6029 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6030 })
6031 // Test that SRTP isn't negotiated on the server if there were
6032 // no matching profiles.
6033 testCases = append(testCases, testCase{
6034 protocol: dtls,
6035 testType: serverTest,
6036 name: "SRTP-Server-NoMatch-" + ver.name,
6037 config: Config{
6038 MaxVersion: ver.version,
6039 SRTPProtectionProfiles: []uint16{100, 101, 102},
6040 },
6041 flags: []string{
6042 "-srtp-profiles",
6043 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6044 },
6045 expectedSRTPProtectionProfile: 0,
6046 })
6047 // Test that the server returning an invalid SRTP profile is
6048 // flagged as an error by the client.
6049 testCases = append(testCases, testCase{
6050 protocol: dtls,
6051 name: "SRTP-Client-NoMatch-" + ver.name,
6052 config: Config{
6053 MaxVersion: ver.version,
6054 Bugs: ProtocolBugs{
6055 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6056 },
6057 },
6058 flags: []string{
6059 "-srtp-profiles",
6060 "SRTP_AES128_CM_SHA1_80",
6061 },
6062 shouldFail: true,
6063 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6064 })
6065 }
6066
6067 // Test SCT list.
6068 testCases = append(testCases, testCase{
6069 name: "SignedCertificateTimestampList-Client-" + ver.name,
6070 testType: clientTest,
6071 config: Config{
6072 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006073 },
David Benjamin97d17d92016-07-14 16:12:00 -04006074 flags: []string{
6075 "-enable-signed-cert-timestamps",
6076 "-expect-signed-cert-timestamps",
6077 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006078 },
David Benjamina5022392017-07-10 17:40:39 -04006079 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006080 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006081 })
David Benjamindaa88502016-10-04 16:32:16 -04006082
Adam Langleycfa08c32016-11-17 13:21:27 -08006083 var differentSCTList []byte
6084 differentSCTList = append(differentSCTList, testSCTList...)
6085 differentSCTList[len(differentSCTList)-1] ^= 1
6086
David Benjamindaa88502016-10-04 16:32:16 -04006087 // The SCT extension did not specify that it must only be sent on resumption as it
6088 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006089 testCases = append(testCases, testCase{
6090 name: "SendSCTListOnResume-" + ver.name,
6091 config: Config{
6092 MaxVersion: ver.version,
6093 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006094 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006095 },
David Benjamind98452d2015-06-16 14:16:23 -04006096 },
David Benjamin97d17d92016-07-14 16:12:00 -04006097 flags: []string{
6098 "-enable-signed-cert-timestamps",
6099 "-expect-signed-cert-timestamps",
6100 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006101 },
David Benjamina5022392017-07-10 17:40:39 -04006102 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006103 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006104 })
David Benjamindaa88502016-10-04 16:32:16 -04006105
David Benjamin97d17d92016-07-14 16:12:00 -04006106 testCases = append(testCases, testCase{
6107 name: "SignedCertificateTimestampList-Server-" + ver.name,
6108 testType: serverTest,
6109 config: Config{
6110 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006111 },
David Benjamin97d17d92016-07-14 16:12:00 -04006112 flags: []string{
6113 "-signed-cert-timestamps",
6114 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006115 },
David Benjamina5022392017-07-10 17:40:39 -04006116 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006117 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006118 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006119 })
David Benjamin53210cb2016-11-16 09:01:48 +09006120
Adam Langleycfa08c32016-11-17 13:21:27 -08006121 emptySCTListCert := *testCerts[0].cert
6122 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6123
6124 // Test empty SCT list.
6125 testCases = append(testCases, testCase{
6126 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6127 testType: clientTest,
6128 config: Config{
6129 MaxVersion: ver.version,
6130 Certificates: []Certificate{emptySCTListCert},
6131 },
6132 flags: []string{
6133 "-enable-signed-cert-timestamps",
6134 },
David Benjamina5022392017-07-10 17:40:39 -04006135 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006136 shouldFail: true,
6137 expectedError: ":ERROR_PARSING_EXTENSION:",
6138 })
6139
6140 emptySCTCert := *testCerts[0].cert
6141 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6142
6143 // Test empty SCT in non-empty list.
6144 testCases = append(testCases, testCase{
6145 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6146 testType: clientTest,
6147 config: Config{
6148 MaxVersion: ver.version,
6149 Certificates: []Certificate{emptySCTCert},
6150 },
6151 flags: []string{
6152 "-enable-signed-cert-timestamps",
6153 },
David Benjamina5022392017-07-10 17:40:39 -04006154 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006155 shouldFail: true,
6156 expectedError: ":ERROR_PARSING_EXTENSION:",
6157 })
6158
David Benjamin53210cb2016-11-16 09:01:48 +09006159 // Test that certificate-related extensions are not sent unsolicited.
6160 testCases = append(testCases, testCase{
6161 testType: serverTest,
6162 name: "UnsolicitedCertificateExtensions-" + ver.name,
6163 config: Config{
6164 MaxVersion: ver.version,
6165 Bugs: ProtocolBugs{
6166 NoOCSPStapling: true,
6167 NoSignedCertificateTimestamps: true,
6168 },
6169 },
David Benjamina5022392017-07-10 17:40:39 -04006170 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006171 flags: []string{
6172 "-ocsp-response",
6173 base64.StdEncoding.EncodeToString(testOCSPResponse),
6174 "-signed-cert-timestamps",
6175 base64.StdEncoding.EncodeToString(testSCTList),
6176 },
6177 })
David Benjamin97d17d92016-07-14 16:12:00 -04006178 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006179
Paul Lietar4fac72e2015-09-09 13:44:55 +01006180 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006181 testType: clientTest,
6182 name: "ClientHelloPadding",
6183 config: Config{
6184 Bugs: ProtocolBugs{
6185 RequireClientHelloSize: 512,
6186 },
6187 },
6188 // This hostname just needs to be long enough to push the
6189 // ClientHello into F5's danger zone between 256 and 511 bytes
6190 // long.
6191 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6192 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006193
6194 // Extensions should not function in SSL 3.0.
6195 testCases = append(testCases, testCase{
6196 testType: serverTest,
6197 name: "SSLv3Extensions-NoALPN",
6198 config: Config{
6199 MaxVersion: VersionSSL30,
6200 NextProtos: []string{"foo", "bar", "baz"},
6201 },
6202 flags: []string{
6203 "-select-alpn", "foo",
6204 },
6205 expectNoNextProto: true,
6206 })
6207
6208 // Test session tickets separately as they follow a different codepath.
6209 testCases = append(testCases, testCase{
6210 testType: serverTest,
6211 name: "SSLv3Extensions-NoTickets",
6212 config: Config{
6213 MaxVersion: VersionSSL30,
6214 Bugs: ProtocolBugs{
6215 // Historically, session tickets in SSL 3.0
6216 // failed in different ways depending on whether
6217 // the client supported renegotiation_info.
6218 NoRenegotiationInfo: true,
6219 },
6220 },
6221 resumeSession: true,
6222 })
6223 testCases = append(testCases, testCase{
6224 testType: serverTest,
6225 name: "SSLv3Extensions-NoTickets2",
6226 config: Config{
6227 MaxVersion: VersionSSL30,
6228 },
6229 resumeSession: true,
6230 })
6231
6232 // But SSL 3.0 does send and process renegotiation_info.
6233 testCases = append(testCases, testCase{
6234 testType: serverTest,
6235 name: "SSLv3Extensions-RenegotiationInfo",
6236 config: Config{
6237 MaxVersion: VersionSSL30,
6238 Bugs: ProtocolBugs{
6239 RequireRenegotiationInfo: true,
6240 },
6241 },
David Benjamind2610042017-01-03 10:49:28 -05006242 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006243 })
6244 testCases = append(testCases, testCase{
6245 testType: serverTest,
6246 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6247 config: Config{
6248 MaxVersion: VersionSSL30,
6249 Bugs: ProtocolBugs{
6250 NoRenegotiationInfo: true,
6251 SendRenegotiationSCSV: true,
6252 RequireRenegotiationInfo: true,
6253 },
6254 },
David Benjamind2610042017-01-03 10:49:28 -05006255 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006256 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006257
6258 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6259 // in ServerHello.
6260 testCases = append(testCases, testCase{
6261 name: "NPN-Forbidden-TLS13",
6262 config: Config{
6263 MaxVersion: VersionTLS13,
6264 NextProtos: []string{"foo"},
6265 Bugs: ProtocolBugs{
6266 NegotiateNPNAtAllVersions: true,
6267 },
6268 },
6269 flags: []string{"-select-next-proto", "foo"},
6270 shouldFail: true,
6271 expectedError: ":ERROR_PARSING_EXTENSION:",
6272 })
6273 testCases = append(testCases, testCase{
6274 name: "EMS-Forbidden-TLS13",
6275 config: Config{
6276 MaxVersion: VersionTLS13,
6277 Bugs: ProtocolBugs{
6278 NegotiateEMSAtAllVersions: true,
6279 },
6280 },
6281 shouldFail: true,
6282 expectedError: ":ERROR_PARSING_EXTENSION:",
6283 })
6284 testCases = append(testCases, testCase{
6285 name: "RenegotiationInfo-Forbidden-TLS13",
6286 config: Config{
6287 MaxVersion: VersionTLS13,
6288 Bugs: ProtocolBugs{
6289 NegotiateRenegotiationInfoAtAllVersions: true,
6290 },
6291 },
6292 shouldFail: true,
6293 expectedError: ":ERROR_PARSING_EXTENSION:",
6294 })
6295 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006296 name: "Ticket-Forbidden-TLS13",
6297 config: Config{
6298 MaxVersion: VersionTLS12,
6299 },
6300 resumeConfig: &Config{
6301 MaxVersion: VersionTLS13,
6302 Bugs: ProtocolBugs{
6303 AdvertiseTicketExtension: true,
6304 },
6305 },
6306 resumeSession: true,
6307 shouldFail: true,
6308 expectedError: ":ERROR_PARSING_EXTENSION:",
6309 })
6310
6311 // Test that illegal extensions in TLS 1.3 are declined by the server if
6312 // offered in ClientHello. The runner's server will fail if this occurs,
6313 // so we exercise the offering path. (EMS and Renegotiation Info are
6314 // implicit in every test.)
6315 testCases = append(testCases, testCase{
6316 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006317 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006318 config: Config{
6319 MaxVersion: VersionTLS13,
6320 NextProtos: []string{"bar"},
6321 },
6322 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6323 })
David Benjamin196df5b2016-09-21 16:23:27 -04006324
David Benjamindaa88502016-10-04 16:32:16 -04006325 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6326 // tolerated.
6327 testCases = append(testCases, testCase{
6328 name: "SendOCSPResponseOnResume-TLS12",
6329 config: Config{
6330 MaxVersion: VersionTLS12,
6331 Bugs: ProtocolBugs{
6332 SendOCSPResponseOnResume: []byte("bogus"),
6333 },
6334 },
6335 flags: []string{
6336 "-enable-ocsp-stapling",
6337 "-expect-ocsp-response",
6338 base64.StdEncoding.EncodeToString(testOCSPResponse),
6339 },
6340 resumeSession: true,
6341 })
6342
David Benjamindaa88502016-10-04 16:32:16 -04006343 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006344 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006345 config: Config{
6346 MaxVersion: VersionTLS13,
6347 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006348 SendExtensionOnCertificate: testOCSPExtension,
6349 },
6350 },
6351 shouldFail: true,
6352 expectedError: ":UNEXPECTED_EXTENSION:",
6353 })
6354
6355 testCases = append(testCases, testCase{
6356 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6357 config: Config{
6358 MaxVersion: VersionTLS13,
6359 Bugs: ProtocolBugs{
6360 SendExtensionOnCertificate: testSCTExtension,
6361 },
6362 },
6363 shouldFail: true,
6364 expectedError: ":UNEXPECTED_EXTENSION:",
6365 })
6366
6367 // Test that extensions on client certificates are never accepted.
6368 testCases = append(testCases, testCase{
6369 name: "SendExtensionOnClientCertificate-TLS13",
6370 testType: serverTest,
6371 config: Config{
6372 MaxVersion: VersionTLS13,
6373 Certificates: []Certificate{rsaCertificate},
6374 Bugs: ProtocolBugs{
6375 SendExtensionOnCertificate: testOCSPExtension,
6376 },
6377 },
6378 flags: []string{
6379 "-enable-ocsp-stapling",
6380 "-require-any-client-certificate",
6381 },
6382 shouldFail: true,
6383 expectedError: ":UNEXPECTED_EXTENSION:",
6384 })
6385
6386 testCases = append(testCases, testCase{
6387 name: "SendUnknownExtensionOnCertificate-TLS13",
6388 config: Config{
6389 MaxVersion: VersionTLS13,
6390 Bugs: ProtocolBugs{
6391 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6392 },
6393 },
6394 shouldFail: true,
6395 expectedError: ":UNEXPECTED_EXTENSION:",
6396 })
6397
Adam Langleycfa08c32016-11-17 13:21:27 -08006398 var differentSCTList []byte
6399 differentSCTList = append(differentSCTList, testSCTList...)
6400 differentSCTList[len(differentSCTList)-1] ^= 1
6401
Steven Valdeza833c352016-11-01 13:39:36 -04006402 // Test that extensions on intermediates are allowed but ignored.
6403 testCases = append(testCases, testCase{
6404 name: "IgnoreExtensionsOnIntermediates-TLS13",
6405 config: Config{
6406 MaxVersion: VersionTLS13,
6407 Certificates: []Certificate{rsaChainCertificate},
6408 Bugs: ProtocolBugs{
6409 // Send different values on the intermediate. This tests
6410 // the intermediate's extensions do not override the
6411 // leaf's.
6412 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006413 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006414 },
6415 },
6416 flags: []string{
6417 "-enable-ocsp-stapling",
6418 "-expect-ocsp-response",
6419 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006420 "-enable-signed-cert-timestamps",
6421 "-expect-signed-cert-timestamps",
6422 base64.StdEncoding.EncodeToString(testSCTList),
6423 },
6424 resumeSession: true,
6425 })
6426
6427 // Test that extensions are not sent on intermediates when configured
6428 // only for a leaf.
6429 testCases = append(testCases, testCase{
6430 testType: serverTest,
6431 name: "SendNoExtensionsOnIntermediate-TLS13",
6432 config: Config{
6433 MaxVersion: VersionTLS13,
6434 Bugs: ProtocolBugs{
6435 ExpectNoExtensionsOnIntermediate: true,
6436 },
6437 },
6438 flags: []string{
6439 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6440 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6441 "-ocsp-response",
6442 base64.StdEncoding.EncodeToString(testOCSPResponse),
6443 "-signed-cert-timestamps",
6444 base64.StdEncoding.EncodeToString(testSCTList),
6445 },
6446 })
6447
6448 // Test that extensions are not sent on client certificates.
6449 testCases = append(testCases, testCase{
6450 name: "SendNoClientCertificateExtensions-TLS13",
6451 config: Config{
6452 MaxVersion: VersionTLS13,
6453 ClientAuth: RequireAnyClientCert,
6454 },
6455 flags: []string{
6456 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6457 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6458 "-ocsp-response",
6459 base64.StdEncoding.EncodeToString(testOCSPResponse),
6460 "-signed-cert-timestamps",
6461 base64.StdEncoding.EncodeToString(testSCTList),
6462 },
6463 })
6464
6465 testCases = append(testCases, testCase{
6466 name: "SendDuplicateExtensionsOnCerts-TLS13",
6467 config: Config{
6468 MaxVersion: VersionTLS13,
6469 Bugs: ProtocolBugs{
6470 SendDuplicateCertExtensions: true,
6471 },
6472 },
6473 flags: []string{
6474 "-enable-ocsp-stapling",
6475 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006476 },
6477 resumeSession: true,
6478 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006479 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006480 })
Adam Langley9b885c52016-11-18 14:21:03 -08006481
6482 testCases = append(testCases, testCase{
6483 name: "SignedCertificateTimestampListInvalid-Server",
6484 testType: serverTest,
6485 flags: []string{
6486 "-signed-cert-timestamps",
6487 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6488 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006489 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006490 expectedError: ":INVALID_SCT_LIST:",
6491 })
David Benjamine78bfde2014-09-06 12:45:15 -04006492}
6493
David Benjamin01fe8202014-09-24 15:21:44 -04006494func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006495 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006496 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006497 // SSL 3.0 does not have tickets and TLS 1.3 does not
6498 // have session IDs, so skip their cross-resumption
6499 // tests.
6500 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6501 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6502 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006503 }
6504
David Benjamin8b8c0062014-11-23 02:47:52 -05006505 protocols := []protocol{tls}
6506 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6507 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006508 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006509 for _, protocol := range protocols {
6510 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6511 if protocol == dtls {
6512 suffix += "-DTLS"
6513 }
6514
Steven Valdez520e1222017-06-13 12:45:25 -04006515 // We can't resume across TLS 1.3 variants and error out earlier in the
6516 // session resumption.
6517 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6518 continue
6519 }
6520
David Benjaminece3de92015-03-16 18:02:20 -04006521 if sessionVers.version == resumeVers.version {
6522 testCases = append(testCases, testCase{
6523 protocol: protocol,
6524 name: "Resume-Client" + suffix,
6525 resumeSession: true,
6526 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006527 MaxVersion: sessionVers.version,
6528 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006529 Bugs: ProtocolBugs{
6530 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6531 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6532 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006533 },
David Benjaminece3de92015-03-16 18:02:20 -04006534 expectedVersion: sessionVers.version,
6535 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006536 flags: []string{
6537 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6538 },
David Benjaminece3de92015-03-16 18:02:20 -04006539 })
6540 } else {
David Benjamin405da482016-08-08 17:25:07 -04006541 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6542
6543 // Offering a TLS 1.3 session sends an empty session ID, so
6544 // there is no way to convince a non-lookahead client the
6545 // session was resumed. It will appear to the client that a
6546 // stray ChangeCipherSpec was sent.
6547 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6548 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006549 }
6550
David Benjaminece3de92015-03-16 18:02:20 -04006551 testCases = append(testCases, testCase{
6552 protocol: protocol,
6553 name: "Resume-Client-Mismatch" + suffix,
6554 resumeSession: true,
6555 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006556 MaxVersion: sessionVers.version,
6557 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006558 },
David Benjaminece3de92015-03-16 18:02:20 -04006559 expectedVersion: sessionVers.version,
6560 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006561 MaxVersion: resumeVers.version,
6562 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006563 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006564 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006565 },
6566 },
6567 expectedResumeVersion: resumeVers.version,
6568 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006569 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006570 flags: []string{
6571 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6572 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6573 },
David Benjaminece3de92015-03-16 18:02:20 -04006574 })
6575 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006576
6577 testCases = append(testCases, testCase{
6578 protocol: protocol,
6579 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006580 resumeSession: true,
6581 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006582 MaxVersion: sessionVers.version,
6583 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006584 },
6585 expectedVersion: sessionVers.version,
6586 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006587 MaxVersion: resumeVers.version,
6588 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006589 },
6590 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006591 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006592 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006593 flags: []string{
6594 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6595 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6596 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006597 })
6598
David Benjamin8b8c0062014-11-23 02:47:52 -05006599 testCases = append(testCases, testCase{
6600 protocol: protocol,
6601 testType: serverTest,
6602 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006603 resumeSession: true,
6604 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: sessionVers.version,
6606 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006607 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006608 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006609 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006610 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006611 MaxVersion: resumeVers.version,
6612 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006613 Bugs: ProtocolBugs{
6614 SendBothTickets: true,
6615 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006616 },
6617 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006618 flags: []string{
6619 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6620 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6621 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006622 })
6623 }
David Benjamin01fe8202014-09-24 15:21:44 -04006624 }
6625 }
David Benjaminece3de92015-03-16 18:02:20 -04006626
David Benjamin4199b0d2016-11-01 13:58:25 -04006627 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006628 testCases = append(testCases, testCase{
6629 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006630 name: "ShimTicketRewritable",
6631 resumeSession: true,
6632 config: Config{
6633 MaxVersion: VersionTLS12,
6634 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6635 Bugs: ProtocolBugs{
6636 FilterTicket: func(in []byte) ([]byte, error) {
6637 in, err := SetShimTicketVersion(in, VersionTLS12)
6638 if err != nil {
6639 return nil, err
6640 }
6641 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6642 },
6643 },
6644 },
6645 flags: []string{
6646 "-ticket-key",
6647 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6648 },
6649 })
6650
6651 // Resumptions are declined if the version does not match.
6652 testCases = append(testCases, testCase{
6653 testType: serverTest,
6654 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006655 resumeSession: true,
6656 config: Config{
6657 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006658 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006659 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006660 FilterTicket: func(in []byte) ([]byte, error) {
6661 return SetShimTicketVersion(in, VersionTLS13)
6662 },
6663 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006664 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006665 flags: []string{
6666 "-ticket-key",
6667 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6668 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006669 expectResumeRejected: true,
6670 })
6671
6672 testCases = append(testCases, testCase{
6673 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006674 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006675 resumeSession: true,
6676 config: Config{
6677 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006678 Bugs: ProtocolBugs{
6679 FilterTicket: func(in []byte) ([]byte, error) {
6680 return SetShimTicketVersion(in, VersionTLS12)
6681 },
6682 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006683 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006684 flags: []string{
6685 "-ticket-key",
6686 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6687 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006688 expectResumeRejected: true,
6689 })
6690
David Benjamin4199b0d2016-11-01 13:58:25 -04006691 // Resumptions are declined if the cipher is invalid or disabled.
6692 testCases = append(testCases, testCase{
6693 testType: serverTest,
6694 name: "Resume-Server-DeclineBadCipher",
6695 resumeSession: true,
6696 config: Config{
6697 MaxVersion: VersionTLS12,
6698 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006699 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006700 FilterTicket: func(in []byte) ([]byte, error) {
6701 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6702 },
6703 },
6704 },
6705 flags: []string{
6706 "-ticket-key",
6707 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6708 },
6709 expectResumeRejected: true,
6710 })
6711
6712 testCases = append(testCases, testCase{
6713 testType: serverTest,
6714 name: "Resume-Server-DeclineBadCipher-2",
6715 resumeSession: true,
6716 config: Config{
6717 MaxVersion: VersionTLS12,
6718 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006719 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006720 FilterTicket: func(in []byte) ([]byte, error) {
6721 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6722 },
6723 },
6724 },
6725 flags: []string{
6726 "-cipher", "AES128",
6727 "-ticket-key",
6728 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6729 },
6730 expectResumeRejected: true,
6731 })
6732
David Benjaminf01f42a2016-11-16 19:05:33 +09006733 // Sessions are not resumed if they do not use the preferred cipher.
6734 testCases = append(testCases, testCase{
6735 testType: serverTest,
6736 name: "Resume-Server-CipherNotPreferred",
6737 resumeSession: true,
6738 config: Config{
6739 MaxVersion: VersionTLS12,
6740 Bugs: ProtocolBugs{
6741 ExpectNewTicket: true,
6742 FilterTicket: func(in []byte) ([]byte, error) {
6743 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6744 },
6745 },
6746 },
6747 flags: []string{
6748 "-ticket-key",
6749 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6750 },
6751 shouldFail: false,
6752 expectResumeRejected: true,
6753 })
6754
6755 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6756 // PRF hashes match, but BoringSSL will always decline such resumptions.
6757 testCases = append(testCases, testCase{
6758 testType: serverTest,
6759 name: "Resume-Server-CipherNotPreferred-TLS13",
6760 resumeSession: true,
6761 config: Config{
6762 MaxVersion: VersionTLS13,
6763 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6764 Bugs: ProtocolBugs{
6765 FilterTicket: func(in []byte) ([]byte, error) {
6766 // If the client (runner) offers ChaCha20-Poly1305 first, the
6767 // server (shim) always prefers it. Switch it to AES-GCM.
6768 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6769 },
6770 },
6771 },
6772 flags: []string{
6773 "-ticket-key",
6774 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6775 },
6776 shouldFail: false,
6777 expectResumeRejected: true,
6778 })
6779
6780 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006781 testCases = append(testCases, testCase{
6782 testType: serverTest,
6783 name: "Resume-Server-DeclineBadCipher-TLS13",
6784 resumeSession: true,
6785 config: Config{
6786 MaxVersion: VersionTLS13,
6787 Bugs: ProtocolBugs{
6788 FilterTicket: func(in []byte) ([]byte, error) {
6789 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6790 },
6791 },
6792 },
6793 flags: []string{
6794 "-ticket-key",
6795 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6796 },
6797 expectResumeRejected: true,
6798 })
6799
David Benjaminf01f42a2016-11-16 19:05:33 +09006800 // If the client does not offer the cipher from the session, decline to
6801 // resume. Clients are forbidden from doing this, but BoringSSL selects
6802 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006803 testCases = append(testCases, testCase{
6804 testType: serverTest,
6805 name: "Resume-Server-UnofferedCipher",
6806 resumeSession: true,
6807 config: Config{
6808 MaxVersion: VersionTLS12,
6809 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6810 },
6811 resumeConfig: &Config{
6812 MaxVersion: VersionTLS12,
6813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6814 Bugs: ProtocolBugs{
6815 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6816 },
6817 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006818 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006819 })
6820
David Benjaminf01f42a2016-11-16 19:05:33 +09006821 // In TLS 1.3, clients may advertise a cipher list which does not
6822 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006823 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6824 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006825 testCases = append(testCases, testCase{
6826 testType: serverTest,
6827 name: "Resume-Server-UnofferedCipher-TLS13",
6828 resumeSession: true,
6829 config: Config{
6830 MaxVersion: VersionTLS13,
6831 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6832 },
6833 resumeConfig: &Config{
6834 MaxVersion: VersionTLS13,
6835 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6836 Bugs: ProtocolBugs{
6837 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6838 },
6839 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006840 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006841 })
6842
David Benjamin4199b0d2016-11-01 13:58:25 -04006843 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006844 testCases = append(testCases, testCase{
6845 name: "Resume-Client-CipherMismatch",
6846 resumeSession: true,
6847 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006848 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006849 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6850 },
6851 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006852 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006853 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6854 Bugs: ProtocolBugs{
6855 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6856 },
6857 },
6858 shouldFail: true,
6859 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6860 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006861
David Benjamine1cc35e2016-11-16 16:25:58 +09006862 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6863 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006864 testCases = append(testCases, testCase{
6865 name: "Resume-Client-CipherMismatch-TLS13",
6866 resumeSession: true,
6867 config: Config{
6868 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006869 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006870 },
6871 resumeConfig: &Config{
6872 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006873 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6874 },
6875 })
6876
6877 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6878 testCases = append(testCases, testCase{
6879 name: "Resume-Client-PRFMismatch-TLS13",
6880 resumeSession: true,
6881 config: Config{
6882 MaxVersion: VersionTLS13,
6883 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6884 },
6885 resumeConfig: &Config{
6886 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006887 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006888 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006889 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006890 },
6891 },
6892 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006893 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006894 })
Steven Valdeza833c352016-11-01 13:39:36 -04006895
6896 testCases = append(testCases, testCase{
6897 testType: serverTest,
6898 name: "Resume-Server-BinderWrongLength",
6899 resumeSession: true,
6900 config: Config{
6901 MaxVersion: VersionTLS13,
6902 Bugs: ProtocolBugs{
6903 SendShortPSKBinder: true,
6904 },
6905 },
6906 shouldFail: true,
6907 expectedLocalError: "remote error: error decrypting message",
6908 expectedError: ":DIGEST_CHECK_FAILED:",
6909 })
6910
6911 testCases = append(testCases, testCase{
6912 testType: serverTest,
6913 name: "Resume-Server-NoPSKBinder",
6914 resumeSession: true,
6915 config: Config{
6916 MaxVersion: VersionTLS13,
6917 Bugs: ProtocolBugs{
6918 SendNoPSKBinder: true,
6919 },
6920 },
6921 shouldFail: true,
6922 expectedLocalError: "remote error: error decoding message",
6923 expectedError: ":DECODE_ERROR:",
6924 })
6925
6926 testCases = append(testCases, testCase{
6927 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006928 name: "Resume-Server-ExtraPSKBinder",
6929 resumeSession: true,
6930 config: Config{
6931 MaxVersion: VersionTLS13,
6932 Bugs: ProtocolBugs{
6933 SendExtraPSKBinder: true,
6934 },
6935 },
6936 shouldFail: true,
6937 expectedLocalError: "remote error: illegal parameter",
6938 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6939 })
6940
6941 testCases = append(testCases, testCase{
6942 testType: serverTest,
6943 name: "Resume-Server-ExtraIdentityNoBinder",
6944 resumeSession: true,
6945 config: Config{
6946 MaxVersion: VersionTLS13,
6947 Bugs: ProtocolBugs{
6948 ExtraPSKIdentity: true,
6949 },
6950 },
6951 shouldFail: true,
6952 expectedLocalError: "remote error: illegal parameter",
6953 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6954 })
6955
6956 testCases = append(testCases, testCase{
6957 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006958 name: "Resume-Server-InvalidPSKBinder",
6959 resumeSession: true,
6960 config: Config{
6961 MaxVersion: VersionTLS13,
6962 Bugs: ProtocolBugs{
6963 SendInvalidPSKBinder: true,
6964 },
6965 },
6966 shouldFail: true,
6967 expectedLocalError: "remote error: error decrypting message",
6968 expectedError: ":DIGEST_CHECK_FAILED:",
6969 })
6970
6971 testCases = append(testCases, testCase{
6972 testType: serverTest,
6973 name: "Resume-Server-PSKBinderFirstExtension",
6974 resumeSession: true,
6975 config: Config{
6976 MaxVersion: VersionTLS13,
6977 Bugs: ProtocolBugs{
6978 PSKBinderFirst: true,
6979 },
6980 },
6981 shouldFail: true,
6982 expectedLocalError: "remote error: illegal parameter",
6983 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6984 })
David Benjamin01fe8202014-09-24 15:21:44 -04006985}
6986
Adam Langley2ae77d22014-10-28 17:29:33 -07006987func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006988 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006989 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006990 testType: serverTest,
6991 name: "Renegotiate-Server-Forbidden",
6992 config: Config{
6993 MaxVersion: VersionTLS12,
6994 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006995 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006996 shouldFail: true,
6997 expectedError: ":NO_RENEGOTIATION:",
6998 expectedLocalError: "remote error: no renegotiation",
6999 })
Adam Langley5021b222015-06-12 18:27:58 -07007000 // The server shouldn't echo the renegotiation extension unless
7001 // requested by the client.
7002 testCases = append(testCases, testCase{
7003 testType: serverTest,
7004 name: "Renegotiate-Server-NoExt",
7005 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007006 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007007 Bugs: ProtocolBugs{
7008 NoRenegotiationInfo: true,
7009 RequireRenegotiationInfo: true,
7010 },
7011 },
7012 shouldFail: true,
7013 expectedLocalError: "renegotiation extension missing",
7014 })
7015 // The renegotiation SCSV should be sufficient for the server to echo
7016 // the extension.
7017 testCases = append(testCases, testCase{
7018 testType: serverTest,
7019 name: "Renegotiate-Server-NoExt-SCSV",
7020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007021 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007022 Bugs: ProtocolBugs{
7023 NoRenegotiationInfo: true,
7024 SendRenegotiationSCSV: true,
7025 RequireRenegotiationInfo: true,
7026 },
7027 },
7028 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007029 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007030 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007032 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007033 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007034 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007035 },
7036 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007037 renegotiate: 1,
7038 flags: []string{
7039 "-renegotiate-freely",
7040 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007041 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007042 },
David Benjamincdea40c2015-03-19 14:09:43 -04007043 })
7044 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007045 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007046 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007047 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007048 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007049 Bugs: ProtocolBugs{
7050 EmptyRenegotiationInfo: true,
7051 },
7052 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007053 flags: []string{"-renegotiate-freely"},
7054 shouldFail: true,
7055 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007056 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007057 })
7058 testCases = append(testCases, testCase{
7059 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007060 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007062 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007063 Bugs: ProtocolBugs{
7064 BadRenegotiationInfo: true,
7065 },
7066 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007067 flags: []string{"-renegotiate-freely"},
7068 shouldFail: true,
7069 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007070 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007071 })
7072 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007073 name: "Renegotiate-Client-BadExt2",
7074 renegotiate: 1,
7075 config: Config{
7076 MaxVersion: VersionTLS12,
7077 Bugs: ProtocolBugs{
7078 BadRenegotiationInfoEnd: true,
7079 },
7080 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007081 flags: []string{"-renegotiate-freely"},
7082 shouldFail: true,
7083 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007084 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007085 })
7086 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007087 name: "Renegotiate-Client-Downgrade",
7088 renegotiate: 1,
7089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007090 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007091 Bugs: ProtocolBugs{
7092 NoRenegotiationInfoAfterInitial: true,
7093 },
7094 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007095 flags: []string{"-renegotiate-freely"},
7096 shouldFail: true,
7097 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007098 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007099 })
7100 testCases = append(testCases, testCase{
7101 name: "Renegotiate-Client-Upgrade",
7102 renegotiate: 1,
7103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007104 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007105 Bugs: ProtocolBugs{
7106 NoRenegotiationInfoInInitial: true,
7107 },
7108 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007109 flags: []string{"-renegotiate-freely"},
7110 shouldFail: true,
7111 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007112 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007113 })
7114 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007115 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007116 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007118 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007119 Bugs: ProtocolBugs{
7120 NoRenegotiationInfo: true,
7121 },
7122 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007123 flags: []string{
7124 "-renegotiate-freely",
7125 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007126 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007127 },
David Benjamincff0b902015-05-15 23:09:47 -04007128 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007129
7130 // Test that the server may switch ciphers on renegotiation without
7131 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007132 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007133 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007134 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007135 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007136 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007137 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007138 },
7139 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007140 flags: []string{
7141 "-renegotiate-freely",
7142 "-expect-total-renegotiations", "1",
7143 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007144 })
7145 testCases = append(testCases, testCase{
7146 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007147 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007148 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007149 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7151 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007152 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007153 flags: []string{
7154 "-renegotiate-freely",
7155 "-expect-total-renegotiations", "1",
7156 },
David Benjaminb16346b2015-04-08 19:16:58 -04007157 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007158
7159 // Test that the server may not switch versions on renegotiation.
7160 testCases = append(testCases, testCase{
7161 name: "Renegotiate-Client-SwitchVersion",
7162 config: Config{
7163 MaxVersion: VersionTLS12,
7164 // Pick a cipher which exists at both versions.
7165 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7166 Bugs: ProtocolBugs{
7167 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007168 // Avoid failing early at the record layer.
7169 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007170 },
7171 },
7172 renegotiate: 1,
7173 flags: []string{
7174 "-renegotiate-freely",
7175 "-expect-total-renegotiations", "1",
7176 },
7177 shouldFail: true,
7178 expectedError: ":WRONG_SSL_VERSION:",
7179 })
7180
David Benjaminb16346b2015-04-08 19:16:58 -04007181 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007182 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007183 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007184 config: Config{
7185 MaxVersion: VersionTLS10,
7186 Bugs: ProtocolBugs{
7187 RequireSameRenegoClientVersion: true,
7188 },
7189 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007190 flags: []string{
7191 "-renegotiate-freely",
7192 "-expect-total-renegotiations", "1",
7193 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007194 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007195 testCases = append(testCases, testCase{
7196 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007197 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007199 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7201 NextProtos: []string{"foo"},
7202 },
7203 flags: []string{
7204 "-false-start",
7205 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007206 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007207 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007208 },
7209 shimWritesFirst: true,
7210 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007211
7212 // Client-side renegotiation controls.
7213 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007214 name: "Renegotiate-Client-Forbidden-1",
7215 config: Config{
7216 MaxVersion: VersionTLS12,
7217 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007218 renegotiate: 1,
7219 shouldFail: true,
7220 expectedError: ":NO_RENEGOTIATION:",
7221 expectedLocalError: "remote error: no renegotiation",
7222 })
7223 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007224 name: "Renegotiate-Client-Once-1",
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007228 renegotiate: 1,
7229 flags: []string{
7230 "-renegotiate-once",
7231 "-expect-total-renegotiations", "1",
7232 },
7233 })
7234 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007235 name: "Renegotiate-Client-Freely-1",
7236 config: Config{
7237 MaxVersion: VersionTLS12,
7238 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007239 renegotiate: 1,
7240 flags: []string{
7241 "-renegotiate-freely",
7242 "-expect-total-renegotiations", "1",
7243 },
7244 })
7245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007246 name: "Renegotiate-Client-Once-2",
7247 config: Config{
7248 MaxVersion: VersionTLS12,
7249 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007250 renegotiate: 2,
7251 flags: []string{"-renegotiate-once"},
7252 shouldFail: true,
7253 expectedError: ":NO_RENEGOTIATION:",
7254 expectedLocalError: "remote error: no renegotiation",
7255 })
7256 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007257 name: "Renegotiate-Client-Freely-2",
7258 config: Config{
7259 MaxVersion: VersionTLS12,
7260 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007261 renegotiate: 2,
7262 flags: []string{
7263 "-renegotiate-freely",
7264 "-expect-total-renegotiations", "2",
7265 },
7266 })
Adam Langley27a0d082015-11-03 13:34:10 -08007267 testCases = append(testCases, testCase{
7268 name: "Renegotiate-Client-NoIgnore",
7269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007270 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007271 Bugs: ProtocolBugs{
7272 SendHelloRequestBeforeEveryAppDataRecord: true,
7273 },
7274 },
7275 shouldFail: true,
7276 expectedError: ":NO_RENEGOTIATION:",
7277 })
7278 testCases = append(testCases, testCase{
7279 name: "Renegotiate-Client-Ignore",
7280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007281 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007282 Bugs: ProtocolBugs{
7283 SendHelloRequestBeforeEveryAppDataRecord: true,
7284 },
7285 },
7286 flags: []string{
7287 "-renegotiate-ignore",
7288 "-expect-total-renegotiations", "0",
7289 },
7290 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007291
David Benjamin34941c02016-10-08 11:45:31 -04007292 // Renegotiation is not allowed at SSL 3.0.
7293 testCases = append(testCases, testCase{
7294 name: "Renegotiate-Client-SSL3",
7295 config: Config{
7296 MaxVersion: VersionSSL30,
7297 },
7298 renegotiate: 1,
7299 flags: []string{
7300 "-renegotiate-freely",
7301 "-expect-total-renegotiations", "1",
7302 },
7303 shouldFail: true,
7304 expectedError: ":NO_RENEGOTIATION:",
7305 expectedLocalError: "remote error: no renegotiation",
7306 })
7307
David Benjamina1eaba12017-01-01 23:19:22 -05007308 // Renegotiation is not allowed when there is an unfinished write.
7309 testCases = append(testCases, testCase{
7310 name: "Renegotiate-Client-UnfinishedWrite",
7311 config: Config{
7312 MaxVersion: VersionTLS12,
7313 },
David Benjaminbbba9392017-04-06 12:54:12 -04007314 renegotiate: 1,
7315 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007316 flags: []string{
7317 "-async",
7318 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007319 },
7320 shouldFail: true,
7321 expectedError: ":NO_RENEGOTIATION:",
7322 // We do not successfully send the no_renegotiation alert in
7323 // this case. https://crbug.com/boringssl/130
7324 })
7325
David Benjamin07ab5d42017-02-09 20:11:41 -05007326 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007327 testCases = append(testCases, testCase{
7328 name: "StrayHelloRequest",
7329 config: Config{
7330 MaxVersion: VersionTLS12,
7331 Bugs: ProtocolBugs{
7332 SendHelloRequestBeforeEveryHandshakeMessage: true,
7333 },
7334 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007335 shouldFail: true,
7336 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007337 })
7338 testCases = append(testCases, testCase{
7339 name: "StrayHelloRequest-Packed",
7340 config: Config{
7341 MaxVersion: VersionTLS12,
7342 Bugs: ProtocolBugs{
7343 PackHandshakeFlight: true,
7344 SendHelloRequestBeforeEveryHandshakeMessage: true,
7345 },
7346 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007347 shouldFail: true,
7348 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007349 })
7350
David Benjamin12d2c482016-07-24 10:56:51 -04007351 // Test renegotiation works if HelloRequest and server Finished come in
7352 // the same record.
7353 testCases = append(testCases, testCase{
7354 name: "Renegotiate-Client-Packed",
7355 config: Config{
7356 MaxVersion: VersionTLS12,
7357 Bugs: ProtocolBugs{
7358 PackHandshakeFlight: true,
7359 PackHelloRequestWithFinished: true,
7360 },
7361 },
7362 renegotiate: 1,
7363 flags: []string{
7364 "-renegotiate-freely",
7365 "-expect-total-renegotiations", "1",
7366 },
7367 })
7368
David Benjamin397c8e62016-07-08 14:14:36 -07007369 // Renegotiation is forbidden in TLS 1.3.
7370 testCases = append(testCases, testCase{
7371 name: "Renegotiate-Client-TLS13",
7372 config: Config{
7373 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007374 Bugs: ProtocolBugs{
7375 SendHelloRequestBeforeEveryAppDataRecord: true,
7376 },
David Benjamin397c8e62016-07-08 14:14:36 -07007377 },
David Benjamin397c8e62016-07-08 14:14:36 -07007378 flags: []string{
7379 "-renegotiate-freely",
7380 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007381 shouldFail: true,
7382 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007383 })
7384
7385 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7386 testCases = append(testCases, testCase{
7387 name: "StrayHelloRequest-TLS13",
7388 config: Config{
7389 MaxVersion: VersionTLS13,
7390 Bugs: ProtocolBugs{
7391 SendHelloRequestBeforeEveryHandshakeMessage: true,
7392 },
7393 },
7394 shouldFail: true,
7395 expectedError: ":UNEXPECTED_MESSAGE:",
7396 })
David Benjamind2610042017-01-03 10:49:28 -05007397
7398 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7399 // always reads as supporting it, regardless of whether it was
7400 // negotiated.
7401 testCases = append(testCases, testCase{
7402 name: "AlwaysReportRenegotiationInfo-TLS13",
7403 config: Config{
7404 MaxVersion: VersionTLS13,
7405 Bugs: ProtocolBugs{
7406 NoRenegotiationInfo: true,
7407 },
7408 },
7409 flags: []string{
7410 "-expect-secure-renegotiation",
7411 },
7412 })
David Benjamina58baaf2017-02-28 20:54:28 -05007413
7414 // Certificates may not change on renegotiation.
7415 testCases = append(testCases, testCase{
7416 name: "Renegotiation-CertificateChange",
7417 config: Config{
7418 MaxVersion: VersionTLS12,
7419 Certificates: []Certificate{rsaCertificate},
7420 Bugs: ProtocolBugs{
7421 RenegotiationCertificate: &rsaChainCertificate,
7422 },
7423 },
7424 renegotiate: 1,
7425 flags: []string{"-renegotiate-freely"},
7426 shouldFail: true,
7427 expectedError: ":SERVER_CERT_CHANGED:",
7428 })
7429 testCases = append(testCases, testCase{
7430 name: "Renegotiation-CertificateChange-2",
7431 config: Config{
7432 MaxVersion: VersionTLS12,
7433 Certificates: []Certificate{rsaCertificate},
7434 Bugs: ProtocolBugs{
7435 RenegotiationCertificate: &rsa1024Certificate,
7436 },
7437 },
7438 renegotiate: 1,
7439 flags: []string{"-renegotiate-freely"},
7440 shouldFail: true,
7441 expectedError: ":SERVER_CERT_CHANGED:",
7442 })
David Benjaminbbf42462017-03-14 21:27:10 -04007443
7444 // We do not negotiate ALPN after the initial handshake. This is
7445 // error-prone and only risks bugs in consumers.
7446 testCases = append(testCases, testCase{
7447 testType: clientTest,
7448 name: "Renegotiation-ForbidALPN",
7449 config: Config{
7450 MaxVersion: VersionTLS12,
7451 Bugs: ProtocolBugs{
7452 // Forcibly negotiate ALPN on both initial and
7453 // renegotiation handshakes. The test stack will
7454 // internally check the client does not offer
7455 // it.
7456 SendALPN: "foo",
7457 },
7458 },
7459 flags: []string{
7460 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7461 "-expect-alpn", "foo",
7462 "-renegotiate-freely",
7463 },
7464 renegotiate: 1,
7465 shouldFail: true,
7466 expectedError: ":UNEXPECTED_EXTENSION:",
7467 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007468}
7469
David Benjamin5e961c12014-11-07 01:48:35 -05007470func addDTLSReplayTests() {
7471 // Test that sequence number replays are detected.
7472 testCases = append(testCases, testCase{
7473 protocol: dtls,
7474 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007475 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007476 replayWrites: true,
7477 })
7478
David Benjamin8e6db492015-07-25 18:29:23 -04007479 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007480 // than the retransmit window.
7481 testCases = append(testCases, testCase{
7482 protocol: dtls,
7483 name: "DTLS-Replay-LargeGaps",
7484 config: Config{
7485 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007486 SequenceNumberMapping: func(in uint64) uint64 {
7487 return in * 127
7488 },
David Benjamin5e961c12014-11-07 01:48:35 -05007489 },
7490 },
David Benjamin8e6db492015-07-25 18:29:23 -04007491 messageCount: 200,
7492 replayWrites: true,
7493 })
7494
7495 // Test the incoming sequence number changing non-monotonically.
7496 testCases = append(testCases, testCase{
7497 protocol: dtls,
7498 name: "DTLS-Replay-NonMonotonic",
7499 config: Config{
7500 Bugs: ProtocolBugs{
7501 SequenceNumberMapping: func(in uint64) uint64 {
7502 return in ^ 31
7503 },
7504 },
7505 },
7506 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007507 replayWrites: true,
7508 })
7509}
7510
Nick Harper60edffd2016-06-21 15:19:24 -07007511var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007512 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007513 id signatureAlgorithm
7514 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007515}{
Nick Harper60edffd2016-06-21 15:19:24 -07007516 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7517 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7518 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7519 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007520 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007521 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7522 // hash function doesn't have to match the curve and so the same
7523 // signature algorithm works with P-224.
7524 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007525 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7526 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7527 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007528 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7529 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7530 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007531 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007532 // Tests for key types prior to TLS 1.2.
7533 {"RSA", 0, testCertRSA},
7534 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007535}
7536
Nick Harper60edffd2016-06-21 15:19:24 -07007537const fakeSigAlg1 signatureAlgorithm = 0x2a01
7538const fakeSigAlg2 signatureAlgorithm = 0xff01
7539
7540func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007541 // Not all ciphers involve a signature. Advertise a list which gives all
7542 // versions a signing cipher.
7543 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007544 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007545 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7546 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7547 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7548 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007549 }
David Benjamin5208fd42016-07-13 21:43:25 -04007550
David Benjaminca3d5452016-07-14 12:51:01 -04007551 var allAlgorithms []signatureAlgorithm
7552 for _, alg := range testSignatureAlgorithms {
7553 if alg.id != 0 {
7554 allAlgorithms = append(allAlgorithms, alg.id)
7555 }
7556 }
7557
Nick Harper60edffd2016-06-21 15:19:24 -07007558 // Make sure each signature algorithm works. Include some fake values in
7559 // the list and ensure they're ignored.
7560 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007561 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007562 if (ver.version < VersionTLS12) != (alg.id == 0) {
7563 continue
7564 }
7565
7566 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7567 // or remove it in C.
7568 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007569 continue
7570 }
Nick Harper60edffd2016-06-21 15:19:24 -07007571
David Benjamin3ef76972016-10-17 17:59:54 -04007572 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007573 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007574 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007575 shouldSignFail = true
7576 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007577 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007578 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007579 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7580 shouldSignFail = true
7581 shouldVerifyFail = true
7582 }
7583 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7584 // the curve has to match the hash size.
7585 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007586 shouldSignFail = true
7587 shouldVerifyFail = true
7588 }
7589
7590 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7591 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7592 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007593 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007594
7595 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007596 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007597 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007598 }
7599 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007600 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007601 }
David Benjamin000800a2014-11-14 01:43:59 -05007602
David Benjamin1fb125c2016-07-08 18:52:12 -07007603 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007604
David Benjamin7a41d372016-07-09 11:21:54 -07007605 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007606 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007607 config: Config{
7608 MaxVersion: ver.version,
7609 ClientAuth: RequireAnyClientCert,
7610 VerifySignatureAlgorithms: []signatureAlgorithm{
7611 fakeSigAlg1,
7612 alg.id,
7613 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007614 },
David Benjamin7a41d372016-07-09 11:21:54 -07007615 },
7616 flags: []string{
7617 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7618 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7619 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007620 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007621 },
David Benjamina5022392017-07-10 17:40:39 -04007622 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007623 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007624 expectedError: signError,
7625 expectedPeerSignatureAlgorithm: alg.id,
7626 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007627
David Benjamin7a41d372016-07-09 11:21:54 -07007628 testCases = append(testCases, testCase{
7629 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007630 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007631 config: Config{
7632 MaxVersion: ver.version,
7633 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7634 SignSignatureAlgorithms: []signatureAlgorithm{
7635 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007636 },
David Benjamin7a41d372016-07-09 11:21:54 -07007637 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007638 SkipECDSACurveCheck: shouldVerifyFail,
7639 IgnoreSignatureVersionChecks: shouldVerifyFail,
7640 // Some signature algorithms may not be advertised.
7641 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007642 },
David Benjamin7a41d372016-07-09 11:21:54 -07007643 },
David Benjamina5022392017-07-10 17:40:39 -04007644 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007645 flags: []string{
7646 "-require-any-client-certificate",
7647 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7648 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007649 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007650 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007651 // Resume the session to assert the peer signature
7652 // algorithm is reported on both handshakes.
7653 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007654 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007655 expectedError: verifyError,
7656 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007657
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007658 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007659 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007660 testCases = append(testCases, testCase{
7661 testType: serverTest,
7662 name: "ServerAuth-Sign" + suffix,
7663 config: Config{
7664 MaxVersion: ver.version,
7665 CipherSuites: signingCiphers,
7666 VerifySignatureAlgorithms: []signatureAlgorithm{
7667 fakeSigAlg1,
7668 alg.id,
7669 fakeSigAlg2,
7670 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007671 },
David Benjamina5022392017-07-10 17:40:39 -04007672 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007673 flags: []string{
7674 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7675 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7676 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007677 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007678 },
7679 shouldFail: shouldSignFail,
7680 expectedError: signError,
7681 expectedPeerSignatureAlgorithm: alg.id,
7682 })
7683 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007684
7685 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007686 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007687 config: Config{
7688 MaxVersion: ver.version,
7689 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007690 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007691 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007692 alg.id,
7693 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007694 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007695 SkipECDSACurveCheck: shouldVerifyFail,
7696 IgnoreSignatureVersionChecks: shouldVerifyFail,
7697 // Some signature algorithms may not be advertised.
7698 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007699 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007700 },
David Benjamina5022392017-07-10 17:40:39 -04007701 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007702 flags: []string{
7703 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7704 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007705 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007706 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007707 // Resume the session to assert the peer signature
7708 // algorithm is reported on both handshakes.
7709 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007710 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007711 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007712 })
David Benjamin5208fd42016-07-13 21:43:25 -04007713
David Benjamin3ef76972016-10-17 17:59:54 -04007714 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007715 testCases = append(testCases, testCase{
7716 testType: serverTest,
7717 name: "ClientAuth-InvalidSignature" + suffix,
7718 config: Config{
7719 MaxVersion: ver.version,
7720 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7721 SignSignatureAlgorithms: []signatureAlgorithm{
7722 alg.id,
7723 },
7724 Bugs: ProtocolBugs{
7725 InvalidSignature: true,
7726 },
7727 },
David Benjamina5022392017-07-10 17:40:39 -04007728 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007729 flags: []string{
7730 "-require-any-client-certificate",
7731 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007732 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007733 },
7734 shouldFail: true,
7735 expectedError: ":BAD_SIGNATURE:",
7736 })
7737
7738 testCases = append(testCases, testCase{
7739 name: "ServerAuth-InvalidSignature" + suffix,
7740 config: Config{
7741 MaxVersion: ver.version,
7742 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7743 CipherSuites: signingCiphers,
7744 SignSignatureAlgorithms: []signatureAlgorithm{
7745 alg.id,
7746 },
7747 Bugs: ProtocolBugs{
7748 InvalidSignature: true,
7749 },
7750 },
David Benjamina5022392017-07-10 17:40:39 -04007751 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007752 flags: []string{
7753 "-enable-all-curves",
7754 "-enable-ed25519",
7755 },
David Benjamin5208fd42016-07-13 21:43:25 -04007756 shouldFail: true,
7757 expectedError: ":BAD_SIGNATURE:",
7758 })
7759 }
David Benjaminca3d5452016-07-14 12:51:01 -04007760
David Benjamin3ef76972016-10-17 17:59:54 -04007761 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007762 testCases = append(testCases, testCase{
7763 name: "ClientAuth-Sign-Negotiate" + suffix,
7764 config: Config{
7765 MaxVersion: ver.version,
7766 ClientAuth: RequireAnyClientCert,
7767 VerifySignatureAlgorithms: allAlgorithms,
7768 },
David Benjamina5022392017-07-10 17:40:39 -04007769 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007770 flags: []string{
7771 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7772 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7773 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007774 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007775 "-signing-prefs", strconv.Itoa(int(alg.id)),
7776 },
7777 expectedPeerSignatureAlgorithm: alg.id,
7778 })
7779
7780 testCases = append(testCases, testCase{
7781 testType: serverTest,
7782 name: "ServerAuth-Sign-Negotiate" + suffix,
7783 config: Config{
7784 MaxVersion: ver.version,
7785 CipherSuites: signingCiphers,
7786 VerifySignatureAlgorithms: allAlgorithms,
7787 },
David Benjamina5022392017-07-10 17:40:39 -04007788 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007789 flags: []string{
7790 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7791 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7792 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007793 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007794 "-signing-prefs", strconv.Itoa(int(alg.id)),
7795 },
7796 expectedPeerSignatureAlgorithm: alg.id,
7797 })
7798 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007799 }
David Benjamin000800a2014-11-14 01:43:59 -05007800 }
7801
Nick Harper60edffd2016-06-21 15:19:24 -07007802 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007803 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007804 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007805 config: Config{
7806 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007807 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007808 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007809 signatureECDSAWithP521AndSHA512,
7810 signatureRSAPKCS1WithSHA384,
7811 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007812 },
7813 },
7814 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007815 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7816 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007817 },
Nick Harper60edffd2016-06-21 15:19:24 -07007818 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007819 })
7820
7821 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007822 name: "ClientAuth-SignatureType-TLS13",
7823 config: Config{
7824 ClientAuth: RequireAnyClientCert,
7825 MaxVersion: VersionTLS13,
7826 VerifySignatureAlgorithms: []signatureAlgorithm{
7827 signatureECDSAWithP521AndSHA512,
7828 signatureRSAPKCS1WithSHA384,
7829 signatureRSAPSSWithSHA384,
7830 signatureECDSAWithSHA1,
7831 },
7832 },
7833 flags: []string{
7834 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7835 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7836 },
7837 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7838 })
7839
7840 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007841 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007842 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007843 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007844 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007846 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007847 signatureECDSAWithP521AndSHA512,
7848 signatureRSAPKCS1WithSHA384,
7849 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007850 },
7851 },
Nick Harper60edffd2016-06-21 15:19:24 -07007852 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007853 })
7854
Steven Valdez143e8b32016-07-11 13:19:03 -04007855 testCases = append(testCases, testCase{
7856 testType: serverTest,
7857 name: "ServerAuth-SignatureType-TLS13",
7858 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007859 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007860 VerifySignatureAlgorithms: []signatureAlgorithm{
7861 signatureECDSAWithP521AndSHA512,
7862 signatureRSAPKCS1WithSHA384,
7863 signatureRSAPSSWithSHA384,
7864 signatureECDSAWithSHA1,
7865 },
7866 },
7867 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7868 })
7869
David Benjamina95e9f32016-07-08 16:28:04 -07007870 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007871 testCases = append(testCases, testCase{
7872 testType: serverTest,
7873 name: "Verify-ClientAuth-SignatureType",
7874 config: Config{
7875 MaxVersion: VersionTLS12,
7876 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007877 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007878 signatureRSAPKCS1WithSHA256,
7879 },
7880 Bugs: ProtocolBugs{
7881 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7882 },
7883 },
7884 flags: []string{
7885 "-require-any-client-certificate",
7886 },
7887 shouldFail: true,
7888 expectedError: ":WRONG_SIGNATURE_TYPE:",
7889 })
7890
7891 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007892 testType: serverTest,
7893 name: "Verify-ClientAuth-SignatureType-TLS13",
7894 config: Config{
7895 MaxVersion: VersionTLS13,
7896 Certificates: []Certificate{rsaCertificate},
7897 SignSignatureAlgorithms: []signatureAlgorithm{
7898 signatureRSAPSSWithSHA256,
7899 },
7900 Bugs: ProtocolBugs{
7901 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7902 },
7903 },
7904 flags: []string{
7905 "-require-any-client-certificate",
7906 },
7907 shouldFail: true,
7908 expectedError: ":WRONG_SIGNATURE_TYPE:",
7909 })
7910
7911 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007912 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007913 config: Config{
7914 MaxVersion: VersionTLS12,
7915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007916 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007917 signatureRSAPKCS1WithSHA256,
7918 },
7919 Bugs: ProtocolBugs{
7920 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7921 },
7922 },
7923 shouldFail: true,
7924 expectedError: ":WRONG_SIGNATURE_TYPE:",
7925 })
7926
Steven Valdez143e8b32016-07-11 13:19:03 -04007927 testCases = append(testCases, testCase{
7928 name: "Verify-ServerAuth-SignatureType-TLS13",
7929 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007930 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007931 SignSignatureAlgorithms: []signatureAlgorithm{
7932 signatureRSAPSSWithSHA256,
7933 },
7934 Bugs: ProtocolBugs{
7935 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7936 },
7937 },
7938 shouldFail: true,
7939 expectedError: ":WRONG_SIGNATURE_TYPE:",
7940 })
7941
David Benjamin51dd7d62016-07-08 16:07:01 -07007942 // Test that, if the list is missing, the peer falls back to SHA-1 in
7943 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007944 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007945 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007946 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007947 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007948 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007949 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007950 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007951 },
7952 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007953 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007954 },
7955 },
7956 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007957 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7958 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007959 },
7960 })
7961
7962 testCases = append(testCases, testCase{
7963 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007964 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007965 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007966 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007967 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007968 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007969 },
7970 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007971 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007972 },
7973 },
David Benjaminee32bea2016-08-17 13:36:44 -04007974 flags: []string{
7975 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7976 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7977 },
7978 })
7979
7980 testCases = append(testCases, testCase{
7981 name: "ClientAuth-SHA1-Fallback-ECDSA",
7982 config: Config{
7983 MaxVersion: VersionTLS12,
7984 ClientAuth: RequireAnyClientCert,
7985 VerifySignatureAlgorithms: []signatureAlgorithm{
7986 signatureECDSAWithSHA1,
7987 },
7988 Bugs: ProtocolBugs{
7989 NoSignatureAlgorithms: true,
7990 },
7991 },
7992 flags: []string{
7993 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7994 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7995 },
7996 })
7997
7998 testCases = append(testCases, testCase{
7999 testType: serverTest,
8000 name: "ServerAuth-SHA1-Fallback-ECDSA",
8001 config: Config{
8002 MaxVersion: VersionTLS12,
8003 VerifySignatureAlgorithms: []signatureAlgorithm{
8004 signatureECDSAWithSHA1,
8005 },
8006 Bugs: ProtocolBugs{
8007 NoSignatureAlgorithms: true,
8008 },
8009 },
8010 flags: []string{
8011 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8012 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8013 },
David Benjamin000800a2014-11-14 01:43:59 -05008014 })
David Benjamin72dc7832015-03-16 17:49:43 -04008015
David Benjamin51dd7d62016-07-08 16:07:01 -07008016 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008017 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008018 config: Config{
8019 MaxVersion: VersionTLS13,
8020 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008021 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008022 signatureRSAPKCS1WithSHA1,
8023 },
8024 Bugs: ProtocolBugs{
8025 NoSignatureAlgorithms: true,
8026 },
8027 },
8028 flags: []string{
8029 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8030 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8031 },
David Benjamin48901652016-08-01 12:12:47 -04008032 shouldFail: true,
8033 // An empty CertificateRequest signature algorithm list is a
8034 // syntax error in TLS 1.3.
8035 expectedError: ":DECODE_ERROR:",
8036 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008037 })
8038
8039 testCases = append(testCases, testCase{
8040 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008041 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008042 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008043 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008044 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008045 signatureRSAPKCS1WithSHA1,
8046 },
8047 Bugs: ProtocolBugs{
8048 NoSignatureAlgorithms: true,
8049 },
8050 },
8051 shouldFail: true,
8052 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8053 })
8054
David Benjaminb62d2872016-07-18 14:55:02 +02008055 // Test that hash preferences are enforced. BoringSSL does not implement
8056 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008057 testCases = append(testCases, testCase{
8058 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008059 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008061 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008062 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008063 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008064 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008065 },
8066 Bugs: ProtocolBugs{
8067 IgnorePeerSignatureAlgorithmPreferences: true,
8068 },
8069 },
8070 flags: []string{"-require-any-client-certificate"},
8071 shouldFail: true,
8072 expectedError: ":WRONG_SIGNATURE_TYPE:",
8073 })
8074
8075 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008076 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008078 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008079 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008080 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008081 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008082 },
8083 Bugs: ProtocolBugs{
8084 IgnorePeerSignatureAlgorithmPreferences: true,
8085 },
8086 },
8087 shouldFail: true,
8088 expectedError: ":WRONG_SIGNATURE_TYPE:",
8089 })
David Benjaminb62d2872016-07-18 14:55:02 +02008090 testCases = append(testCases, testCase{
8091 testType: serverTest,
8092 name: "ClientAuth-Enforced-TLS13",
8093 config: Config{
8094 MaxVersion: VersionTLS13,
8095 Certificates: []Certificate{rsaCertificate},
8096 SignSignatureAlgorithms: []signatureAlgorithm{
8097 signatureRSAPKCS1WithMD5,
8098 },
8099 Bugs: ProtocolBugs{
8100 IgnorePeerSignatureAlgorithmPreferences: true,
8101 IgnoreSignatureVersionChecks: true,
8102 },
8103 },
8104 flags: []string{"-require-any-client-certificate"},
8105 shouldFail: true,
8106 expectedError: ":WRONG_SIGNATURE_TYPE:",
8107 })
8108
8109 testCases = append(testCases, testCase{
8110 name: "ServerAuth-Enforced-TLS13",
8111 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008112 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008113 SignSignatureAlgorithms: []signatureAlgorithm{
8114 signatureRSAPKCS1WithMD5,
8115 },
8116 Bugs: ProtocolBugs{
8117 IgnorePeerSignatureAlgorithmPreferences: true,
8118 IgnoreSignatureVersionChecks: true,
8119 },
8120 },
8121 shouldFail: true,
8122 expectedError: ":WRONG_SIGNATURE_TYPE:",
8123 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008124
8125 // Test that the agreed upon digest respects the client preferences and
8126 // the server digests.
8127 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008128 name: "NoCommonAlgorithms-Digests",
8129 config: Config{
8130 MaxVersion: VersionTLS12,
8131 ClientAuth: RequireAnyClientCert,
8132 VerifySignatureAlgorithms: []signatureAlgorithm{
8133 signatureRSAPKCS1WithSHA512,
8134 signatureRSAPKCS1WithSHA1,
8135 },
8136 },
8137 flags: []string{
8138 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8139 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8140 "-digest-prefs", "SHA256",
8141 },
8142 shouldFail: true,
8143 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8144 })
8145 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008146 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008148 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008149 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008150 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008151 signatureRSAPKCS1WithSHA512,
8152 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008153 },
8154 },
8155 flags: []string{
8156 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8157 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008158 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008159 },
David Benjaminca3d5452016-07-14 12:51:01 -04008160 shouldFail: true,
8161 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8162 })
8163 testCases = append(testCases, testCase{
8164 name: "NoCommonAlgorithms-TLS13",
8165 config: Config{
8166 MaxVersion: VersionTLS13,
8167 ClientAuth: RequireAnyClientCert,
8168 VerifySignatureAlgorithms: []signatureAlgorithm{
8169 signatureRSAPSSWithSHA512,
8170 signatureRSAPSSWithSHA384,
8171 },
8172 },
8173 flags: []string{
8174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8176 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8177 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008178 shouldFail: true,
8179 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008180 })
8181 testCases = append(testCases, testCase{
8182 name: "Agree-Digest-SHA256",
8183 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008184 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008185 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008186 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008187 signatureRSAPKCS1WithSHA1,
8188 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008189 },
8190 },
8191 flags: []string{
8192 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8193 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008194 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008195 },
Nick Harper60edffd2016-06-21 15:19:24 -07008196 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008197 })
8198 testCases = append(testCases, testCase{
8199 name: "Agree-Digest-SHA1",
8200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008201 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008202 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008203 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008204 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008205 },
8206 },
8207 flags: []string{
8208 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8209 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008210 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008211 },
Nick Harper60edffd2016-06-21 15:19:24 -07008212 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008213 })
8214 testCases = append(testCases, testCase{
8215 name: "Agree-Digest-Default",
8216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008217 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008218 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008219 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008220 signatureRSAPKCS1WithSHA256,
8221 signatureECDSAWithP256AndSHA256,
8222 signatureRSAPKCS1WithSHA1,
8223 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008224 },
8225 },
8226 flags: []string{
8227 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8228 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8229 },
Nick Harper60edffd2016-06-21 15:19:24 -07008230 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008231 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008232
David Benjaminca3d5452016-07-14 12:51:01 -04008233 // Test that the signing preference list may include extra algorithms
8234 // without negotiation problems.
8235 testCases = append(testCases, testCase{
8236 testType: serverTest,
8237 name: "FilterExtraAlgorithms",
8238 config: Config{
8239 MaxVersion: VersionTLS12,
8240 VerifySignatureAlgorithms: []signatureAlgorithm{
8241 signatureRSAPKCS1WithSHA256,
8242 },
8243 },
8244 flags: []string{
8245 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8246 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8247 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8248 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8249 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8250 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8251 },
8252 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8253 })
8254
David Benjamin4c3ddf72016-06-29 18:13:53 -04008255 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8256 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008257 testCases = append(testCases, testCase{
8258 name: "CheckLeafCurve",
8259 config: Config{
8260 MaxVersion: VersionTLS12,
8261 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008262 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008263 },
8264 flags: []string{"-p384-only"},
8265 shouldFail: true,
8266 expectedError: ":BAD_ECC_CERT:",
8267 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008268
8269 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8270 testCases = append(testCases, testCase{
8271 name: "CheckLeafCurve-TLS13",
8272 config: Config{
8273 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008274 Certificates: []Certificate{ecdsaP256Certificate},
8275 },
8276 flags: []string{"-p384-only"},
8277 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008278
8279 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8280 testCases = append(testCases, testCase{
8281 name: "ECDSACurveMismatch-Verify-TLS12",
8282 config: Config{
8283 MaxVersion: VersionTLS12,
8284 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8285 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008286 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008287 signatureECDSAWithP384AndSHA384,
8288 },
8289 },
8290 })
8291
8292 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8293 testCases = append(testCases, testCase{
8294 name: "ECDSACurveMismatch-Verify-TLS13",
8295 config: Config{
8296 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008297 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008298 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008299 signatureECDSAWithP384AndSHA384,
8300 },
8301 Bugs: ProtocolBugs{
8302 SkipECDSACurveCheck: true,
8303 },
8304 },
8305 shouldFail: true,
8306 expectedError: ":WRONG_SIGNATURE_TYPE:",
8307 })
8308
8309 // Signature algorithm selection in TLS 1.3 should take the curve into
8310 // account.
8311 testCases = append(testCases, testCase{
8312 testType: serverTest,
8313 name: "ECDSACurveMismatch-Sign-TLS13",
8314 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008315 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008316 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008317 signatureECDSAWithP384AndSHA384,
8318 signatureECDSAWithP256AndSHA256,
8319 },
8320 },
8321 flags: []string{
8322 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8323 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8324 },
8325 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8326 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008327
8328 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8329 // server does not attempt to sign in that case.
8330 testCases = append(testCases, testCase{
8331 testType: serverTest,
8332 name: "RSA-PSS-Large",
8333 config: Config{
8334 MaxVersion: VersionTLS13,
8335 VerifySignatureAlgorithms: []signatureAlgorithm{
8336 signatureRSAPSSWithSHA512,
8337 },
8338 },
8339 flags: []string{
8340 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8341 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8342 },
8343 shouldFail: true,
8344 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8345 })
David Benjamin57e929f2016-08-30 00:30:38 -04008346
8347 // Test that RSA-PSS is enabled by default for TLS 1.2.
8348 testCases = append(testCases, testCase{
8349 testType: clientTest,
8350 name: "RSA-PSS-Default-Verify",
8351 config: Config{
8352 MaxVersion: VersionTLS12,
8353 SignSignatureAlgorithms: []signatureAlgorithm{
8354 signatureRSAPSSWithSHA256,
8355 },
8356 },
8357 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8358 })
8359
8360 testCases = append(testCases, testCase{
8361 testType: serverTest,
8362 name: "RSA-PSS-Default-Sign",
8363 config: Config{
8364 MaxVersion: VersionTLS12,
8365 VerifySignatureAlgorithms: []signatureAlgorithm{
8366 signatureRSAPSSWithSHA256,
8367 },
8368 },
8369 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8370 })
David Benjamin69522112017-03-28 15:38:29 -05008371
8372 // TLS 1.1 and below has no way to advertise support for or negotiate
8373 // Ed25519's signature algorithm.
8374 testCases = append(testCases, testCase{
8375 testType: clientTest,
8376 name: "NoEd25519-TLS11-ServerAuth-Verify",
8377 config: Config{
8378 MaxVersion: VersionTLS11,
8379 Certificates: []Certificate{ed25519Certificate},
8380 Bugs: ProtocolBugs{
8381 // Sign with Ed25519 even though it is TLS 1.1.
8382 UseLegacySigningAlgorithm: signatureEd25519,
8383 },
8384 },
8385 flags: []string{"-enable-ed25519"},
8386 shouldFail: true,
8387 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8388 })
8389 testCases = append(testCases, testCase{
8390 testType: serverTest,
8391 name: "NoEd25519-TLS11-ServerAuth-Sign",
8392 config: Config{
8393 MaxVersion: VersionTLS11,
8394 },
8395 flags: []string{
8396 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8397 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8398 },
8399 shouldFail: true,
8400 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8401 })
8402 testCases = append(testCases, testCase{
8403 testType: serverTest,
8404 name: "NoEd25519-TLS11-ClientAuth-Verify",
8405 config: Config{
8406 MaxVersion: VersionTLS11,
8407 Certificates: []Certificate{ed25519Certificate},
8408 Bugs: ProtocolBugs{
8409 // Sign with Ed25519 even though it is TLS 1.1.
8410 UseLegacySigningAlgorithm: signatureEd25519,
8411 },
8412 },
8413 flags: []string{
8414 "-enable-ed25519",
8415 "-require-any-client-certificate",
8416 },
8417 shouldFail: true,
8418 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8419 })
8420 testCases = append(testCases, testCase{
8421 testType: clientTest,
8422 name: "NoEd25519-TLS11-ClientAuth-Sign",
8423 config: Config{
8424 MaxVersion: VersionTLS11,
8425 ClientAuth: RequireAnyClientCert,
8426 },
8427 flags: []string{
8428 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8429 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8430 },
8431 shouldFail: true,
8432 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8433 })
8434
8435 // Test Ed25519 is not advertised by default.
8436 testCases = append(testCases, testCase{
8437 testType: clientTest,
8438 name: "Ed25519DefaultDisable-NoAdvertise",
8439 config: Config{
8440 Certificates: []Certificate{ed25519Certificate},
8441 },
8442 shouldFail: true,
8443 expectedLocalError: "tls: no common signature algorithms",
8444 })
8445
8446 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8447 // preferences.
8448 testCases = append(testCases, testCase{
8449 testType: clientTest,
8450 name: "Ed25519DefaultDisable-NoAccept",
8451 config: Config{
8452 Certificates: []Certificate{ed25519Certificate},
8453 Bugs: ProtocolBugs{
8454 IgnorePeerSignatureAlgorithmPreferences: true,
8455 },
8456 },
8457 shouldFail: true,
8458 expectedLocalError: "remote error: illegal parameter",
8459 expectedError: ":WRONG_SIGNATURE_TYPE:",
8460 })
David Benjamin71c21b42017-04-14 17:05:40 -04008461
8462 // Test that configuring verify preferences changes what the client
8463 // advertises.
8464 testCases = append(testCases, testCase{
8465 name: "VerifyPreferences-Advertised",
8466 config: Config{
8467 Certificates: []Certificate{rsaCertificate},
8468 SignSignatureAlgorithms: []signatureAlgorithm{
8469 signatureRSAPSSWithSHA256,
8470 signatureRSAPSSWithSHA384,
8471 signatureRSAPSSWithSHA512,
8472 },
8473 },
8474 flags: []string{
8475 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8476 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8477 },
8478 })
8479
8480 // Test that the client advertises a set which the runner can find
8481 // nothing in common with.
8482 testCases = append(testCases, testCase{
8483 name: "VerifyPreferences-NoCommonAlgorithms",
8484 config: Config{
8485 Certificates: []Certificate{rsaCertificate},
8486 SignSignatureAlgorithms: []signatureAlgorithm{
8487 signatureRSAPSSWithSHA256,
8488 signatureRSAPSSWithSHA512,
8489 },
8490 },
8491 flags: []string{
8492 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8493 },
8494 shouldFail: true,
8495 expectedLocalError: "tls: no common signature algorithms",
8496 })
8497
8498 // Test that the client enforces its preferences when configured.
8499 testCases = append(testCases, testCase{
8500 name: "VerifyPreferences-Enforced",
8501 config: Config{
8502 Certificates: []Certificate{rsaCertificate},
8503 SignSignatureAlgorithms: []signatureAlgorithm{
8504 signatureRSAPSSWithSHA256,
8505 signatureRSAPSSWithSHA512,
8506 },
8507 Bugs: ProtocolBugs{
8508 IgnorePeerSignatureAlgorithmPreferences: true,
8509 },
8510 },
8511 flags: []string{
8512 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8513 },
8514 shouldFail: true,
8515 expectedLocalError: "remote error: illegal parameter",
8516 expectedError: ":WRONG_SIGNATURE_TYPE:",
8517 })
8518
8519 // Test that explicitly configuring Ed25519 is as good as changing the
8520 // boolean toggle.
8521 testCases = append(testCases, testCase{
8522 name: "VerifyPreferences-Ed25519",
8523 config: Config{
8524 Certificates: []Certificate{ed25519Certificate},
8525 },
8526 flags: []string{
8527 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8528 },
8529 })
David Benjamin000800a2014-11-14 01:43:59 -05008530}
8531
David Benjamin83f90402015-01-27 01:09:43 -05008532// timeouts is the retransmit schedule for BoringSSL. It doubles and
8533// caps at 60 seconds. On the 13th timeout, it gives up.
8534var timeouts = []time.Duration{
8535 1 * time.Second,
8536 2 * time.Second,
8537 4 * time.Second,
8538 8 * time.Second,
8539 16 * time.Second,
8540 32 * 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 60 * time.Second,
8548}
8549
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008550// shortTimeouts is an alternate set of timeouts which would occur if the
8551// initial timeout duration was set to 250ms.
8552var shortTimeouts = []time.Duration{
8553 250 * time.Millisecond,
8554 500 * time.Millisecond,
8555 1 * time.Second,
8556 2 * time.Second,
8557 4 * time.Second,
8558 8 * time.Second,
8559 16 * time.Second,
8560 32 * time.Second,
8561 60 * time.Second,
8562 60 * time.Second,
8563 60 * time.Second,
8564 60 * time.Second,
8565 60 * time.Second,
8566}
8567
David Benjamin83f90402015-01-27 01:09:43 -05008568func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008569 // These tests work by coordinating some behavior on both the shim and
8570 // the runner.
8571 //
8572 // TimeoutSchedule configures the runner to send a series of timeout
8573 // opcodes to the shim (see packetAdaptor) immediately before reading
8574 // each peer handshake flight N. The timeout opcode both simulates a
8575 // timeout in the shim and acts as a synchronization point to help the
8576 // runner bracket each handshake flight.
8577 //
8578 // We assume the shim does not read from the channel eagerly. It must
8579 // first wait until it has sent flight N and is ready to receive
8580 // handshake flight N+1. At this point, it will process the timeout
8581 // opcode. It must then immediately respond with a timeout ACK and act
8582 // as if the shim was idle for the specified amount of time.
8583 //
8584 // The runner then drops all packets received before the ACK and
8585 // continues waiting for flight N. This ordering results in one attempt
8586 // at sending flight N to be dropped. For the test to complete, the
8587 // shim must send flight N again, testing that the shim implements DTLS
8588 // retransmit on a timeout.
8589
Steven Valdez143e8b32016-07-11 13:19:03 -04008590 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008591 // likely be more epochs to cross and the final message's retransmit may
8592 // be more complex.
8593
David Benjamin11c82892017-02-23 20:40:31 -05008594 // Test that this is indeed the timeout schedule. Stress all
8595 // four patterns of handshake.
8596 for i := 1; i < len(timeouts); i++ {
8597 number := strconv.Itoa(i)
8598 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008599 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008600 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008601 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008602 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008603 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008604 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008605 },
8606 },
8607 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008608 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008609 })
David Benjamin11c82892017-02-23 20:40:31 -05008610 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008611 protocol: dtls,
8612 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008613 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008614 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008615 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008616 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008617 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008618 },
8619 },
8620 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008621 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008622 })
8623 }
David Benjamin11c82892017-02-23 20:40:31 -05008624
8625 // Test that exceeding the timeout schedule hits a read
8626 // timeout.
8627 testCases = append(testCases, testCase{
8628 protocol: dtls,
8629 name: "DTLS-Retransmit-Timeout",
8630 config: Config{
8631 MaxVersion: VersionTLS12,
8632 Bugs: ProtocolBugs{
8633 TimeoutSchedule: timeouts,
8634 },
8635 },
8636 resumeSession: true,
8637 flags: []string{"-async"},
8638 shouldFail: true,
8639 expectedError: ":READ_TIMEOUT_EXPIRED:",
8640 })
8641
8642 // Test that timeout handling has a fudge factor, due to API
8643 // problems.
8644 testCases = append(testCases, testCase{
8645 protocol: dtls,
8646 name: "DTLS-Retransmit-Fudge",
8647 config: Config{
8648 MaxVersion: VersionTLS12,
8649 Bugs: ProtocolBugs{
8650 TimeoutSchedule: []time.Duration{
8651 timeouts[0] - 10*time.Millisecond,
8652 },
8653 },
8654 },
8655 resumeSession: true,
8656 flags: []string{"-async"},
8657 })
8658
8659 // Test that the final Finished retransmitting isn't
8660 // duplicated if the peer badly fragments everything.
8661 testCases = append(testCases, testCase{
8662 testType: serverTest,
8663 protocol: dtls,
8664 name: "DTLS-Retransmit-Fragmented",
8665 config: Config{
8666 MaxVersion: VersionTLS12,
8667 Bugs: ProtocolBugs{
8668 TimeoutSchedule: []time.Duration{timeouts[0]},
8669 MaxHandshakeRecordLength: 2,
8670 },
8671 },
8672 flags: []string{"-async"},
8673 })
8674
8675 // Test the timeout schedule when a shorter initial timeout duration is set.
8676 testCases = append(testCases, testCase{
8677 protocol: dtls,
8678 name: "DTLS-Retransmit-Short-Client",
8679 config: Config{
8680 MaxVersion: VersionTLS12,
8681 Bugs: ProtocolBugs{
8682 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8683 },
8684 },
8685 resumeSession: true,
8686 flags: []string{
8687 "-async",
8688 "-initial-timeout-duration-ms", "250",
8689 },
8690 })
8691 testCases = append(testCases, testCase{
8692 protocol: dtls,
8693 testType: serverTest,
8694 name: "DTLS-Retransmit-Short-Server",
8695 config: Config{
8696 MaxVersion: VersionTLS12,
8697 Bugs: ProtocolBugs{
8698 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8699 },
8700 },
8701 resumeSession: true,
8702 flags: []string{
8703 "-async",
8704 "-initial-timeout-duration-ms", "250",
8705 },
8706 })
David Benjamin83f90402015-01-27 01:09:43 -05008707}
8708
David Benjaminc565ebb2015-04-03 04:06:36 -04008709func addExportKeyingMaterialTests() {
8710 for _, vers := range tlsVersions {
8711 if vers.version == VersionSSL30 {
8712 continue
8713 }
8714 testCases = append(testCases, testCase{
8715 name: "ExportKeyingMaterial-" + vers.name,
8716 config: Config{
8717 MaxVersion: vers.version,
8718 },
David Benjamina5022392017-07-10 17:40:39 -04008719 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008720 exportKeyingMaterial: 1024,
8721 exportLabel: "label",
8722 exportContext: "context",
8723 useExportContext: true,
8724 })
8725 testCases = append(testCases, testCase{
8726 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8727 config: Config{
8728 MaxVersion: vers.version,
8729 },
David Benjamina5022392017-07-10 17:40:39 -04008730 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008731 exportKeyingMaterial: 1024,
8732 })
8733 testCases = append(testCases, testCase{
8734 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8735 config: Config{
8736 MaxVersion: vers.version,
8737 },
David Benjamina5022392017-07-10 17:40:39 -04008738 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008739 exportKeyingMaterial: 1024,
8740 useExportContext: true,
8741 })
8742 testCases = append(testCases, testCase{
8743 name: "ExportKeyingMaterial-Small-" + vers.name,
8744 config: Config{
8745 MaxVersion: vers.version,
8746 },
David Benjamina5022392017-07-10 17:40:39 -04008747 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008748 exportKeyingMaterial: 1,
8749 exportLabel: "label",
8750 exportContext: "context",
8751 useExportContext: true,
8752 })
8753 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008754
David Benjaminc565ebb2015-04-03 04:06:36 -04008755 testCases = append(testCases, testCase{
8756 name: "ExportKeyingMaterial-SSL3",
8757 config: Config{
8758 MaxVersion: VersionSSL30,
8759 },
8760 exportKeyingMaterial: 1024,
8761 exportLabel: "label",
8762 exportContext: "context",
8763 useExportContext: true,
8764 shouldFail: true,
8765 expectedError: "failed to export keying material",
8766 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008767
8768 // Exporters work during a False Start.
8769 testCases = append(testCases, testCase{
8770 name: "ExportKeyingMaterial-FalseStart",
8771 config: Config{
8772 MaxVersion: VersionTLS12,
8773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8774 NextProtos: []string{"foo"},
8775 Bugs: ProtocolBugs{
8776 ExpectFalseStart: true,
8777 },
8778 },
8779 flags: []string{
8780 "-false-start",
8781 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008782 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008783 },
8784 shimWritesFirst: true,
8785 exportKeyingMaterial: 1024,
8786 exportLabel: "label",
8787 exportContext: "context",
8788 useExportContext: true,
8789 })
8790
8791 // Exporters do not work in the middle of a renegotiation. Test this by
8792 // triggering the exporter after every SSL_read call and configuring the
8793 // shim to run asynchronously.
8794 testCases = append(testCases, testCase{
8795 name: "ExportKeyingMaterial-Renegotiate",
8796 config: Config{
8797 MaxVersion: VersionTLS12,
8798 },
8799 renegotiate: 1,
8800 flags: []string{
8801 "-async",
8802 "-use-exporter-between-reads",
8803 "-renegotiate-freely",
8804 "-expect-total-renegotiations", "1",
8805 },
8806 shouldFail: true,
8807 expectedError: "failed to export keying material",
8808 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008809}
8810
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008811func addTLSUniqueTests() {
8812 for _, isClient := range []bool{false, true} {
8813 for _, isResumption := range []bool{false, true} {
8814 for _, hasEMS := range []bool{false, true} {
8815 var suffix string
8816 if isResumption {
8817 suffix = "Resume-"
8818 } else {
8819 suffix = "Full-"
8820 }
8821
8822 if hasEMS {
8823 suffix += "EMS-"
8824 } else {
8825 suffix += "NoEMS-"
8826 }
8827
8828 if isClient {
8829 suffix += "Client"
8830 } else {
8831 suffix += "Server"
8832 }
8833
8834 test := testCase{
8835 name: "TLSUnique-" + suffix,
8836 testTLSUnique: true,
8837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008838 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008839 Bugs: ProtocolBugs{
8840 NoExtendedMasterSecret: !hasEMS,
8841 },
8842 },
8843 }
8844
8845 if isResumption {
8846 test.resumeSession = true
8847 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008848 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008849 Bugs: ProtocolBugs{
8850 NoExtendedMasterSecret: !hasEMS,
8851 },
8852 }
8853 }
8854
8855 if isResumption && !hasEMS {
8856 test.shouldFail = true
8857 test.expectedError = "failed to get tls-unique"
8858 }
8859
8860 testCases = append(testCases, test)
8861 }
8862 }
8863 }
8864}
8865
Adam Langley09505632015-07-30 18:10:13 -07008866func addCustomExtensionTests() {
8867 expectedContents := "custom extension"
8868 emptyString := ""
8869
8870 for _, isClient := range []bool{false, true} {
8871 suffix := "Server"
8872 flag := "-enable-server-custom-extension"
8873 testType := serverTest
8874 if isClient {
8875 suffix = "Client"
8876 flag = "-enable-client-custom-extension"
8877 testType = clientTest
8878 }
8879
8880 testCases = append(testCases, testCase{
8881 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008882 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008884 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008885 Bugs: ProtocolBugs{
8886 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008887 ExpectedCustomExtension: &expectedContents,
8888 },
8889 },
8890 flags: []string{flag},
8891 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008892 testCases = append(testCases, testCase{
8893 testType: testType,
8894 name: "CustomExtensions-" + suffix + "-TLS13",
8895 config: Config{
8896 MaxVersion: VersionTLS13,
8897 Bugs: ProtocolBugs{
8898 CustomExtension: expectedContents,
8899 ExpectedCustomExtension: &expectedContents,
8900 },
8901 },
8902 flags: []string{flag},
8903 })
Adam Langley09505632015-07-30 18:10:13 -07008904
Steven Valdez2a070722017-03-25 20:54:16 -05008905 // 0-RTT is not currently supported with Custom Extensions.
8906 testCases = append(testCases, testCase{
8907 testType: testType,
8908 name: "CustomExtensions-" + suffix + "-EarlyData",
8909 config: Config{
8910 MaxVersion: VersionTLS13,
8911 Bugs: ProtocolBugs{
8912 CustomExtension: expectedContents,
8913 ExpectedCustomExtension: &expectedContents,
8914 },
8915 },
8916 shouldFail: true,
8917 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8918 flags: []string{flag, "-enable-early-data"},
8919 })
8920
Adam Langley09505632015-07-30 18:10:13 -07008921 // If the parse callback fails, the handshake should also fail.
8922 testCases = append(testCases, testCase{
8923 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008924 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008925 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008926 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008927 Bugs: ProtocolBugs{
8928 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008929 ExpectedCustomExtension: &expectedContents,
8930 },
8931 },
David Benjamin399e7c92015-07-30 23:01:27 -04008932 flags: []string{flag},
8933 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008934 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8935 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008936 testCases = append(testCases, testCase{
8937 testType: testType,
8938 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8939 config: Config{
8940 MaxVersion: VersionTLS13,
8941 Bugs: ProtocolBugs{
8942 CustomExtension: expectedContents + "foo",
8943 ExpectedCustomExtension: &expectedContents,
8944 },
8945 },
8946 flags: []string{flag},
8947 shouldFail: true,
8948 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8949 })
Adam Langley09505632015-07-30 18:10:13 -07008950
8951 // If the add callback fails, the handshake should also fail.
8952 testCases = append(testCases, testCase{
8953 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008954 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008956 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008957 Bugs: ProtocolBugs{
8958 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008959 ExpectedCustomExtension: &expectedContents,
8960 },
8961 },
David Benjamin399e7c92015-07-30 23:01:27 -04008962 flags: []string{flag, "-custom-extension-fail-add"},
8963 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008964 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8965 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008966 testCases = append(testCases, testCase{
8967 testType: testType,
8968 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8969 config: Config{
8970 MaxVersion: VersionTLS13,
8971 Bugs: ProtocolBugs{
8972 CustomExtension: expectedContents,
8973 ExpectedCustomExtension: &expectedContents,
8974 },
8975 },
8976 flags: []string{flag, "-custom-extension-fail-add"},
8977 shouldFail: true,
8978 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8979 })
Adam Langley09505632015-07-30 18:10:13 -07008980
8981 // If the add callback returns zero, no extension should be
8982 // added.
8983 skipCustomExtension := expectedContents
8984 if isClient {
8985 // For the case where the client skips sending the
8986 // custom extension, the server must not “echo” it.
8987 skipCustomExtension = ""
8988 }
8989 testCases = append(testCases, testCase{
8990 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008991 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008992 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008993 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008994 Bugs: ProtocolBugs{
8995 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008996 ExpectedCustomExtension: &emptyString,
8997 },
8998 },
8999 flags: []string{flag, "-custom-extension-skip"},
9000 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009001 testCases = append(testCases, testCase{
9002 testType: testType,
9003 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9004 config: Config{
9005 MaxVersion: VersionTLS13,
9006 Bugs: ProtocolBugs{
9007 CustomExtension: skipCustomExtension,
9008 ExpectedCustomExtension: &emptyString,
9009 },
9010 },
9011 flags: []string{flag, "-custom-extension-skip"},
9012 })
Adam Langley09505632015-07-30 18:10:13 -07009013 }
9014
9015 // The custom extension add callback should not be called if the client
9016 // doesn't send the extension.
9017 testCases = append(testCases, testCase{
9018 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009019 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009021 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009022 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009023 ExpectedCustomExtension: &emptyString,
9024 },
9025 },
9026 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9027 })
Adam Langley2deb9842015-08-07 11:15:37 -07009028
Steven Valdez143e8b32016-07-11 13:19:03 -04009029 testCases = append(testCases, testCase{
9030 testType: serverTest,
9031 name: "CustomExtensions-NotCalled-Server-TLS13",
9032 config: Config{
9033 MaxVersion: VersionTLS13,
9034 Bugs: ProtocolBugs{
9035 ExpectedCustomExtension: &emptyString,
9036 },
9037 },
9038 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9039 })
9040
Adam Langley2deb9842015-08-07 11:15:37 -07009041 // Test an unknown extension from the server.
9042 testCases = append(testCases, testCase{
9043 testType: clientTest,
9044 name: "UnknownExtension-Client",
9045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009046 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009047 Bugs: ProtocolBugs{
9048 CustomExtension: expectedContents,
9049 },
9050 },
David Benjamin0c40a962016-08-01 12:05:50 -04009051 shouldFail: true,
9052 expectedError: ":UNEXPECTED_EXTENSION:",
9053 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009054 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009055 testCases = append(testCases, testCase{
9056 testType: clientTest,
9057 name: "UnknownExtension-Client-TLS13",
9058 config: Config{
9059 MaxVersion: VersionTLS13,
9060 Bugs: ProtocolBugs{
9061 CustomExtension: expectedContents,
9062 },
9063 },
David Benjamin0c40a962016-08-01 12:05:50 -04009064 shouldFail: true,
9065 expectedError: ":UNEXPECTED_EXTENSION:",
9066 expectedLocalError: "remote error: unsupported extension",
9067 })
David Benjamin490469f2016-10-05 22:44:38 -04009068 testCases = append(testCases, testCase{
9069 testType: clientTest,
9070 name: "UnknownUnencryptedExtension-Client-TLS13",
9071 config: Config{
9072 MaxVersion: VersionTLS13,
9073 Bugs: ProtocolBugs{
9074 CustomUnencryptedExtension: expectedContents,
9075 },
9076 },
9077 shouldFail: true,
9078 expectedError: ":UNEXPECTED_EXTENSION:",
9079 // The shim must send an alert, but alerts at this point do not
9080 // get successfully decrypted by the runner.
9081 expectedLocalError: "local error: bad record MAC",
9082 })
9083 testCases = append(testCases, testCase{
9084 testType: clientTest,
9085 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9086 config: Config{
9087 MaxVersion: VersionTLS13,
9088 Bugs: ProtocolBugs{
9089 SendUnencryptedALPN: "foo",
9090 },
9091 },
9092 flags: []string{
9093 "-advertise-alpn", "\x03foo\x03bar",
9094 },
9095 shouldFail: true,
9096 expectedError: ":UNEXPECTED_EXTENSION:",
9097 // The shim must send an alert, but alerts at this point do not
9098 // get successfully decrypted by the runner.
9099 expectedLocalError: "local error: bad record MAC",
9100 })
David Benjamin0c40a962016-08-01 12:05:50 -04009101
9102 // Test a known but unoffered extension from the server.
9103 testCases = append(testCases, testCase{
9104 testType: clientTest,
9105 name: "UnofferedExtension-Client",
9106 config: Config{
9107 MaxVersion: VersionTLS12,
9108 Bugs: ProtocolBugs{
9109 SendALPN: "alpn",
9110 },
9111 },
9112 shouldFail: true,
9113 expectedError: ":UNEXPECTED_EXTENSION:",
9114 expectedLocalError: "remote error: unsupported extension",
9115 })
9116 testCases = append(testCases, testCase{
9117 testType: clientTest,
9118 name: "UnofferedExtension-Client-TLS13",
9119 config: Config{
9120 MaxVersion: VersionTLS13,
9121 Bugs: ProtocolBugs{
9122 SendALPN: "alpn",
9123 },
9124 },
9125 shouldFail: true,
9126 expectedError: ":UNEXPECTED_EXTENSION:",
9127 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009128 })
Adam Langley09505632015-07-30 18:10:13 -07009129}
9130
David Benjaminb36a3952015-12-01 18:53:13 -05009131func addRSAClientKeyExchangeTests() {
9132 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9133 testCases = append(testCases, testCase{
9134 testType: serverTest,
9135 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9136 config: Config{
9137 // Ensure the ClientHello version and final
9138 // version are different, to detect if the
9139 // server uses the wrong one.
9140 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009141 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009142 Bugs: ProtocolBugs{
9143 BadRSAClientKeyExchange: bad,
9144 },
9145 },
9146 shouldFail: true,
9147 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9148 })
9149 }
David Benjamine63d9d72016-09-19 18:27:34 -04009150
9151 // The server must compare whatever was in ClientHello.version for the
9152 // RSA premaster.
9153 testCases = append(testCases, testCase{
9154 testType: serverTest,
9155 name: "SendClientVersion-RSA",
9156 config: Config{
9157 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9158 Bugs: ProtocolBugs{
9159 SendClientVersion: 0x1234,
9160 },
9161 },
9162 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9163 })
David Benjaminb36a3952015-12-01 18:53:13 -05009164}
9165
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009166var testCurves = []struct {
9167 name string
9168 id CurveID
9169}{
Adam Langley764ab982017-03-10 18:01:30 -08009170 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009171 {"P-256", CurveP256},
9172 {"P-384", CurveP384},
9173 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009174 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009175}
9176
Steven Valdez5440fe02016-07-18 12:40:30 -04009177const bogusCurve = 0x1234
9178
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009179func addCurveTests() {
9180 for _, curve := range testCurves {
9181 testCases = append(testCases, testCase{
9182 name: "CurveTest-Client-" + curve.name,
9183 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009184 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009185 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9186 CurvePreferences: []CurveID{curve.id},
9187 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009188 flags: []string{
9189 "-enable-all-curves",
9190 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9191 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009192 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009193 })
9194 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009195 name: "CurveTest-Client-" + curve.name + "-TLS13",
9196 config: Config{
9197 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009198 CurvePreferences: []CurveID{curve.id},
9199 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009200 flags: []string{
9201 "-enable-all-curves",
9202 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9203 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009204 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009205 })
9206 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009207 testType: serverTest,
9208 name: "CurveTest-Server-" + curve.name,
9209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009210 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009211 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9212 CurvePreferences: []CurveID{curve.id},
9213 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009214 flags: []string{
9215 "-enable-all-curves",
9216 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9217 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009218 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009219 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009220 testCases = append(testCases, testCase{
9221 testType: serverTest,
9222 name: "CurveTest-Server-" + curve.name + "-TLS13",
9223 config: Config{
9224 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009225 CurvePreferences: []CurveID{curve.id},
9226 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009227 flags: []string{
9228 "-enable-all-curves",
9229 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9230 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009231 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009232 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009233 }
David Benjamin241ae832016-01-15 03:04:54 -05009234
9235 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009236 testCases = append(testCases, testCase{
9237 testType: serverTest,
9238 name: "UnknownCurve",
9239 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009240 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009241 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9242 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9243 },
9244 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009245
Steven Valdez803c77a2016-09-06 14:13:43 -04009246 // The server must be tolerant to bogus curves.
9247 testCases = append(testCases, testCase{
9248 testType: serverTest,
9249 name: "UnknownCurve-TLS13",
9250 config: Config{
9251 MaxVersion: VersionTLS13,
9252 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9253 },
9254 })
9255
David Benjamin4c3ddf72016-06-29 18:13:53 -04009256 // The server must not consider ECDHE ciphers when there are no
9257 // supported curves.
9258 testCases = append(testCases, testCase{
9259 testType: serverTest,
9260 name: "NoSupportedCurves",
9261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009262 MaxVersion: VersionTLS12,
9263 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9264 Bugs: ProtocolBugs{
9265 NoSupportedCurves: true,
9266 },
9267 },
9268 shouldFail: true,
9269 expectedError: ":NO_SHARED_CIPHER:",
9270 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009271 testCases = append(testCases, testCase{
9272 testType: serverTest,
9273 name: "NoSupportedCurves-TLS13",
9274 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009275 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009276 Bugs: ProtocolBugs{
9277 NoSupportedCurves: true,
9278 },
9279 },
9280 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009281 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009282 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009283
9284 // The server must fall back to another cipher when there are no
9285 // supported curves.
9286 testCases = append(testCases, testCase{
9287 testType: serverTest,
9288 name: "NoCommonCurves",
9289 config: Config{
9290 MaxVersion: VersionTLS12,
9291 CipherSuites: []uint16{
9292 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009293 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009294 },
9295 CurvePreferences: []CurveID{CurveP224},
9296 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009297 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009298 })
9299
9300 // The client must reject bogus curves and disabled curves.
9301 testCases = append(testCases, testCase{
9302 name: "BadECDHECurve",
9303 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009304 MaxVersion: VersionTLS12,
9305 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9306 Bugs: ProtocolBugs{
9307 SendCurve: bogusCurve,
9308 },
9309 },
9310 shouldFail: true,
9311 expectedError: ":WRONG_CURVE:",
9312 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009313 testCases = append(testCases, testCase{
9314 name: "BadECDHECurve-TLS13",
9315 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009316 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009317 Bugs: ProtocolBugs{
9318 SendCurve: bogusCurve,
9319 },
9320 },
9321 shouldFail: true,
9322 expectedError: ":WRONG_CURVE:",
9323 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009324
9325 testCases = append(testCases, testCase{
9326 name: "UnsupportedCurve",
9327 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009328 MaxVersion: VersionTLS12,
9329 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9330 CurvePreferences: []CurveID{CurveP256},
9331 Bugs: ProtocolBugs{
9332 IgnorePeerCurvePreferences: true,
9333 },
9334 },
9335 flags: []string{"-p384-only"},
9336 shouldFail: true,
9337 expectedError: ":WRONG_CURVE:",
9338 })
9339
David Benjamin4f921572016-07-17 14:20:10 +02009340 testCases = append(testCases, testCase{
9341 // TODO(davidben): Add a TLS 1.3 version where
9342 // HelloRetryRequest requests an unsupported curve.
9343 name: "UnsupportedCurve-ServerHello-TLS13",
9344 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009345 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009346 CurvePreferences: []CurveID{CurveP384},
9347 Bugs: ProtocolBugs{
9348 SendCurve: CurveP256,
9349 },
9350 },
9351 flags: []string{"-p384-only"},
9352 shouldFail: true,
9353 expectedError: ":WRONG_CURVE:",
9354 })
9355
David Benjamin4c3ddf72016-06-29 18:13:53 -04009356 // Test invalid curve points.
9357 testCases = append(testCases, testCase{
9358 name: "InvalidECDHPoint-Client",
9359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009360 MaxVersion: VersionTLS12,
9361 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9362 CurvePreferences: []CurveID{CurveP256},
9363 Bugs: ProtocolBugs{
9364 InvalidECDHPoint: true,
9365 },
9366 },
9367 shouldFail: true,
9368 expectedError: ":INVALID_ENCODING:",
9369 })
9370 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009371 name: "InvalidECDHPoint-Client-TLS13",
9372 config: Config{
9373 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009374 CurvePreferences: []CurveID{CurveP256},
9375 Bugs: ProtocolBugs{
9376 InvalidECDHPoint: true,
9377 },
9378 },
9379 shouldFail: true,
9380 expectedError: ":INVALID_ENCODING:",
9381 })
9382 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009383 testType: serverTest,
9384 name: "InvalidECDHPoint-Server",
9385 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009386 MaxVersion: VersionTLS12,
9387 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9388 CurvePreferences: []CurveID{CurveP256},
9389 Bugs: ProtocolBugs{
9390 InvalidECDHPoint: true,
9391 },
9392 },
9393 shouldFail: true,
9394 expectedError: ":INVALID_ENCODING:",
9395 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009396 testCases = append(testCases, testCase{
9397 testType: serverTest,
9398 name: "InvalidECDHPoint-Server-TLS13",
9399 config: Config{
9400 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009401 CurvePreferences: []CurveID{CurveP256},
9402 Bugs: ProtocolBugs{
9403 InvalidECDHPoint: true,
9404 },
9405 },
9406 shouldFail: true,
9407 expectedError: ":INVALID_ENCODING:",
9408 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009409
9410 // The previous curve ID should be reported on TLS 1.2 resumption.
9411 testCases = append(testCases, testCase{
9412 name: "CurveID-Resume-Client",
9413 config: Config{
9414 MaxVersion: VersionTLS12,
9415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9416 CurvePreferences: []CurveID{CurveX25519},
9417 },
9418 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9419 resumeSession: true,
9420 })
9421 testCases = append(testCases, testCase{
9422 testType: serverTest,
9423 name: "CurveID-Resume-Server",
9424 config: Config{
9425 MaxVersion: VersionTLS12,
9426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9427 CurvePreferences: []CurveID{CurveX25519},
9428 },
9429 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9430 resumeSession: true,
9431 })
9432
9433 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9434 // one should be reported.
9435 testCases = append(testCases, testCase{
9436 name: "CurveID-Resume-Client-TLS13",
9437 config: Config{
9438 MaxVersion: VersionTLS13,
9439 CurvePreferences: []CurveID{CurveX25519},
9440 },
9441 resumeConfig: &Config{
9442 MaxVersion: VersionTLS13,
9443 CurvePreferences: []CurveID{CurveP256},
9444 },
9445 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009446 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9447 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009448 },
9449 resumeSession: true,
9450 })
9451 testCases = append(testCases, testCase{
9452 testType: serverTest,
9453 name: "CurveID-Resume-Server-TLS13",
9454 config: Config{
9455 MaxVersion: VersionTLS13,
9456 CurvePreferences: []CurveID{CurveX25519},
9457 },
9458 resumeConfig: &Config{
9459 MaxVersion: VersionTLS13,
9460 CurvePreferences: []CurveID{CurveP256},
9461 },
9462 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009463 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9464 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009465 },
9466 resumeSession: true,
9467 })
David Benjamina81967b2016-12-22 09:16:57 -05009468
9469 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9470 testCases = append(testCases, testCase{
9471 name: "PointFormat-ServerHello-TLS12",
9472 config: Config{
9473 MaxVersion: VersionTLS12,
9474 Bugs: ProtocolBugs{
9475 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9476 },
9477 },
9478 })
9479 testCases = append(testCases, testCase{
9480 name: "PointFormat-EncryptedExtensions-TLS13",
9481 config: Config{
9482 MaxVersion: VersionTLS13,
9483 Bugs: ProtocolBugs{
9484 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9485 },
9486 },
9487 shouldFail: true,
9488 expectedError: ":ERROR_PARSING_EXTENSION:",
9489 })
9490
9491 // Test that we tolerate unknown point formats, as long as
9492 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9493 // check they are still functional.
9494 testCases = append(testCases, testCase{
9495 name: "PointFormat-Client-Tolerance",
9496 config: Config{
9497 MaxVersion: VersionTLS12,
9498 Bugs: ProtocolBugs{
9499 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9500 },
9501 },
9502 })
9503 testCases = append(testCases, testCase{
9504 testType: serverTest,
9505 name: "PointFormat-Server-Tolerance",
9506 config: Config{
9507 MaxVersion: VersionTLS12,
9508 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9509 Bugs: ProtocolBugs{
9510 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9511 },
9512 },
9513 })
9514
9515 // Test TLS 1.2 does not require the point format extension to be
9516 // present.
9517 testCases = append(testCases, testCase{
9518 name: "PointFormat-Client-Missing",
9519 config: Config{
9520 MaxVersion: VersionTLS12,
9521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9522 Bugs: ProtocolBugs{
9523 SendSupportedPointFormats: []byte{},
9524 },
9525 },
9526 })
9527 testCases = append(testCases, testCase{
9528 testType: serverTest,
9529 name: "PointFormat-Server-Missing",
9530 config: Config{
9531 MaxVersion: VersionTLS12,
9532 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9533 Bugs: ProtocolBugs{
9534 SendSupportedPointFormats: []byte{},
9535 },
9536 },
9537 })
9538
9539 // If the point format extension is present, uncompressed points must be
9540 // offered. BoringSSL requires this whether or not ECDHE is used.
9541 testCases = append(testCases, testCase{
9542 name: "PointFormat-Client-MissingUncompressed",
9543 config: Config{
9544 MaxVersion: VersionTLS12,
9545 Bugs: ProtocolBugs{
9546 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9547 },
9548 },
9549 shouldFail: true,
9550 expectedError: ":ERROR_PARSING_EXTENSION:",
9551 })
9552 testCases = append(testCases, testCase{
9553 testType: serverTest,
9554 name: "PointFormat-Server-MissingUncompressed",
9555 config: Config{
9556 MaxVersion: VersionTLS12,
9557 Bugs: ProtocolBugs{
9558 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9559 },
9560 },
9561 shouldFail: true,
9562 expectedError: ":ERROR_PARSING_EXTENSION:",
9563 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009564}
9565
David Benjaminc9ae27c2016-06-24 22:56:37 -04009566func addTLS13RecordTests() {
9567 testCases = append(testCases, testCase{
9568 name: "TLS13-RecordPadding",
9569 config: Config{
9570 MaxVersion: VersionTLS13,
9571 MinVersion: VersionTLS13,
9572 Bugs: ProtocolBugs{
9573 RecordPadding: 10,
9574 },
9575 },
9576 })
9577
9578 testCases = append(testCases, testCase{
9579 name: "TLS13-EmptyRecords",
9580 config: Config{
9581 MaxVersion: VersionTLS13,
9582 MinVersion: VersionTLS13,
9583 Bugs: ProtocolBugs{
9584 OmitRecordContents: true,
9585 },
9586 },
9587 shouldFail: true,
9588 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9589 })
9590
9591 testCases = append(testCases, testCase{
9592 name: "TLS13-OnlyPadding",
9593 config: Config{
9594 MaxVersion: VersionTLS13,
9595 MinVersion: VersionTLS13,
9596 Bugs: ProtocolBugs{
9597 OmitRecordContents: true,
9598 RecordPadding: 10,
9599 },
9600 },
9601 shouldFail: true,
9602 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9603 })
9604
9605 testCases = append(testCases, testCase{
9606 name: "TLS13-WrongOuterRecord",
9607 config: Config{
9608 MaxVersion: VersionTLS13,
9609 MinVersion: VersionTLS13,
9610 Bugs: ProtocolBugs{
9611 OuterRecordType: recordTypeHandshake,
9612 },
9613 },
9614 shouldFail: true,
9615 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9616 })
9617}
9618
Steven Valdez5b986082016-09-01 12:29:49 -04009619func addSessionTicketTests() {
9620 testCases = append(testCases, testCase{
9621 // In TLS 1.2 and below, empty NewSessionTicket messages
9622 // mean the server changed its mind on sending a ticket.
9623 name: "SendEmptySessionTicket",
9624 config: Config{
9625 MaxVersion: VersionTLS12,
9626 Bugs: ProtocolBugs{
9627 SendEmptySessionTicket: true,
9628 },
9629 },
9630 flags: []string{"-expect-no-session"},
9631 })
9632
9633 // Test that the server ignores unknown PSK modes.
9634 testCases = append(testCases, testCase{
9635 testType: serverTest,
9636 name: "TLS13-SendUnknownModeSessionTicket-Server",
9637 config: Config{
9638 MaxVersion: VersionTLS13,
9639 Bugs: ProtocolBugs{
9640 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009641 },
9642 },
9643 resumeSession: true,
9644 expectedResumeVersion: VersionTLS13,
9645 })
9646
Steven Valdeza833c352016-11-01 13:39:36 -04009647 // Test that the server does not send session tickets with no matching key exchange mode.
9648 testCases = append(testCases, testCase{
9649 testType: serverTest,
9650 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9651 config: Config{
9652 MaxVersion: VersionTLS13,
9653 Bugs: ProtocolBugs{
9654 SendPSKKeyExchangeModes: []byte{0x1a},
9655 ExpectNoNewSessionTicket: true,
9656 },
9657 },
9658 })
9659
9660 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009661 testCases = append(testCases, testCase{
9662 testType: serverTest,
9663 name: "TLS13-SendBadKEModeSessionTicket-Server",
9664 config: Config{
9665 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009666 },
9667 resumeConfig: &Config{
9668 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009669 Bugs: ProtocolBugs{
9670 SendPSKKeyExchangeModes: []byte{0x1a},
9671 },
9672 },
9673 resumeSession: true,
9674 expectResumeRejected: true,
9675 })
9676
Steven Valdeza833c352016-11-01 13:39:36 -04009677 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009678 testCases = append(testCases, testCase{
9679 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009680 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009681 config: Config{
9682 MaxVersion: VersionTLS13,
9683 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009684 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009685 },
9686 },
Steven Valdeza833c352016-11-01 13:39:36 -04009687 resumeSession: true,
9688 flags: []string{
9689 "-resumption-delay", "10",
9690 },
Steven Valdez5b986082016-09-01 12:29:49 -04009691 })
9692
Steven Valdeza833c352016-11-01 13:39:36 -04009693 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009694 testCases = append(testCases, testCase{
9695 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009696 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009697 config: Config{
9698 MaxVersion: VersionTLS13,
9699 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009700 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009701 },
9702 },
Steven Valdeza833c352016-11-01 13:39:36 -04009703 resumeSession: true,
9704 shouldFail: true,
9705 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009706 })
9707
David Benjamin35ac5b72017-03-03 15:05:56 -05009708 // Test that the server's ticket age skew reporting works.
9709 testCases = append(testCases, testCase{
9710 testType: serverTest,
9711 name: "TLS13-TicketAgeSkew-Forward",
9712 config: Config{
9713 MaxVersion: VersionTLS13,
9714 Bugs: ProtocolBugs{
9715 SendTicketAge: 15 * time.Second,
9716 },
9717 },
David Benjamin065d7332017-03-26 10:51:43 -05009718 resumeSession: true,
9719 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009720 flags: []string{
9721 "-resumption-delay", "10",
9722 "-expect-ticket-age-skew", "5",
9723 },
9724 })
9725 testCases = append(testCases, testCase{
9726 testType: serverTest,
9727 name: "TLS13-TicketAgeSkew-Backward",
9728 config: Config{
9729 MaxVersion: VersionTLS13,
9730 Bugs: ProtocolBugs{
9731 SendTicketAge: 5 * time.Second,
9732 },
9733 },
David Benjamin065d7332017-03-26 10:51:43 -05009734 resumeSession: true,
9735 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009736 flags: []string{
9737 "-resumption-delay", "10",
9738 "-expect-ticket-age-skew", "-5",
9739 },
9740 })
9741
Steven Valdez08b65f42016-12-07 15:29:45 -05009742 testCases = append(testCases, testCase{
9743 testType: clientTest,
9744 name: "TLS13-SendTicketEarlyDataInfo",
9745 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009746 MaxVersion: VersionTLS13,
9747 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009748 },
9749 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009750 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009751 "-expect-early-data-info",
9752 },
9753 })
9754
David Benjamin9b160662017-01-25 19:53:43 -05009755 // Test that 0-RTT tickets are ignored in clients unless opted in.
9756 testCases = append(testCases, testCase{
9757 testType: clientTest,
9758 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9759 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009760 MaxVersion: VersionTLS13,
9761 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009762 },
9763 })
9764
Steven Valdez08b65f42016-12-07 15:29:45 -05009765 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009766 testType: clientTest,
9767 name: "TLS13-DuplicateTicketEarlyDataInfo",
9768 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009769 MaxVersion: VersionTLS13,
9770 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009771 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009772 DuplicateTicketEarlyDataInfo: true,
9773 },
9774 },
9775 shouldFail: true,
9776 expectedError: ":DUPLICATE_EXTENSION:",
9777 expectedLocalError: "remote error: illegal parameter",
9778 })
9779
9780 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009781 testType: serverTest,
9782 name: "TLS13-ExpectTicketEarlyDataInfo",
9783 config: Config{
9784 MaxVersion: VersionTLS13,
9785 Bugs: ProtocolBugs{
9786 ExpectTicketEarlyDataInfo: true,
9787 },
9788 },
9789 flags: []string{
9790 "-enable-early-data",
9791 },
9792 })
David Benjamin17b30832017-01-28 14:00:32 -05009793
9794 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9795 // is honored.
9796 testCases = append(testCases, testCase{
9797 testType: clientTest,
9798 name: "TLS13-HonorServerSessionTicketLifetime",
9799 config: Config{
9800 MaxVersion: VersionTLS13,
9801 Bugs: ProtocolBugs{
9802 SendTicketLifetime: 20 * time.Second,
9803 },
9804 },
9805 flags: []string{
9806 "-resumption-delay", "19",
9807 },
9808 resumeSession: true,
9809 })
9810 testCases = append(testCases, testCase{
9811 testType: clientTest,
9812 name: "TLS13-HonorServerSessionTicketLifetime-2",
9813 config: Config{
9814 MaxVersion: VersionTLS13,
9815 Bugs: ProtocolBugs{
9816 SendTicketLifetime: 20 * time.Second,
9817 // The client should not offer the expired session.
9818 ExpectNoTLS13PSK: true,
9819 },
9820 },
9821 flags: []string{
9822 "-resumption-delay", "21",
9823 },
David Benjamin023d4192017-02-06 13:49:07 -05009824 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009825 expectResumeRejected: true,
9826 })
Steven Valdez5b986082016-09-01 12:29:49 -04009827}
9828
David Benjamin82261be2016-07-07 14:32:50 -07009829func addChangeCipherSpecTests() {
9830 // Test missing ChangeCipherSpecs.
9831 testCases = append(testCases, testCase{
9832 name: "SkipChangeCipherSpec-Client",
9833 config: Config{
9834 MaxVersion: VersionTLS12,
9835 Bugs: ProtocolBugs{
9836 SkipChangeCipherSpec: true,
9837 },
9838 },
9839 shouldFail: true,
9840 expectedError: ":UNEXPECTED_RECORD:",
9841 })
9842 testCases = append(testCases, testCase{
9843 testType: serverTest,
9844 name: "SkipChangeCipherSpec-Server",
9845 config: Config{
9846 MaxVersion: VersionTLS12,
9847 Bugs: ProtocolBugs{
9848 SkipChangeCipherSpec: true,
9849 },
9850 },
9851 shouldFail: true,
9852 expectedError: ":UNEXPECTED_RECORD:",
9853 })
9854 testCases = append(testCases, testCase{
9855 testType: serverTest,
9856 name: "SkipChangeCipherSpec-Server-NPN",
9857 config: Config{
9858 MaxVersion: VersionTLS12,
9859 NextProtos: []string{"bar"},
9860 Bugs: ProtocolBugs{
9861 SkipChangeCipherSpec: true,
9862 },
9863 },
9864 flags: []string{
9865 "-advertise-npn", "\x03foo\x03bar\x03baz",
9866 },
9867 shouldFail: true,
9868 expectedError: ":UNEXPECTED_RECORD:",
9869 })
9870
9871 // Test synchronization between the handshake and ChangeCipherSpec.
9872 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9873 // rejected. Test both with and without handshake packing to handle both
9874 // when the partial post-CCS message is in its own record and when it is
9875 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009876 for _, packed := range []bool{false, true} {
9877 var suffix string
9878 if packed {
9879 suffix = "-Packed"
9880 }
9881
9882 testCases = append(testCases, testCase{
9883 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9884 config: Config{
9885 MaxVersion: VersionTLS12,
9886 Bugs: ProtocolBugs{
9887 FragmentAcrossChangeCipherSpec: true,
9888 PackHandshakeFlight: packed,
9889 },
9890 },
9891 shouldFail: true,
9892 expectedError: ":UNEXPECTED_RECORD:",
9893 })
9894 testCases = append(testCases, testCase{
9895 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9896 config: Config{
9897 MaxVersion: VersionTLS12,
9898 },
9899 resumeSession: true,
9900 resumeConfig: &Config{
9901 MaxVersion: VersionTLS12,
9902 Bugs: ProtocolBugs{
9903 FragmentAcrossChangeCipherSpec: true,
9904 PackHandshakeFlight: packed,
9905 },
9906 },
9907 shouldFail: true,
9908 expectedError: ":UNEXPECTED_RECORD:",
9909 })
9910 testCases = append(testCases, testCase{
9911 testType: serverTest,
9912 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9913 config: Config{
9914 MaxVersion: VersionTLS12,
9915 Bugs: ProtocolBugs{
9916 FragmentAcrossChangeCipherSpec: true,
9917 PackHandshakeFlight: packed,
9918 },
9919 },
9920 shouldFail: true,
9921 expectedError: ":UNEXPECTED_RECORD:",
9922 })
9923 testCases = append(testCases, testCase{
9924 testType: serverTest,
9925 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9926 config: Config{
9927 MaxVersion: VersionTLS12,
9928 },
9929 resumeSession: true,
9930 resumeConfig: &Config{
9931 MaxVersion: VersionTLS12,
9932 Bugs: ProtocolBugs{
9933 FragmentAcrossChangeCipherSpec: true,
9934 PackHandshakeFlight: packed,
9935 },
9936 },
9937 shouldFail: true,
9938 expectedError: ":UNEXPECTED_RECORD:",
9939 })
9940 testCases = append(testCases, testCase{
9941 testType: serverTest,
9942 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9943 config: Config{
9944 MaxVersion: VersionTLS12,
9945 NextProtos: []string{"bar"},
9946 Bugs: ProtocolBugs{
9947 FragmentAcrossChangeCipherSpec: true,
9948 PackHandshakeFlight: packed,
9949 },
9950 },
9951 flags: []string{
9952 "-advertise-npn", "\x03foo\x03bar\x03baz",
9953 },
9954 shouldFail: true,
9955 expectedError: ":UNEXPECTED_RECORD:",
9956 })
9957 }
9958
David Benjamin61672812016-07-14 23:10:43 -04009959 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9960 // messages in the handshake queue. Do this by testing the server
9961 // reading the client Finished, reversing the flight so Finished comes
9962 // first.
9963 testCases = append(testCases, testCase{
9964 protocol: dtls,
9965 testType: serverTest,
9966 name: "SendUnencryptedFinished-DTLS",
9967 config: Config{
9968 MaxVersion: VersionTLS12,
9969 Bugs: ProtocolBugs{
9970 SendUnencryptedFinished: true,
9971 ReverseHandshakeFragments: true,
9972 },
9973 },
9974 shouldFail: true,
9975 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9976 })
9977
Steven Valdez143e8b32016-07-11 13:19:03 -04009978 // Test synchronization between encryption changes and the handshake in
9979 // TLS 1.3, where ChangeCipherSpec is implicit.
9980 testCases = append(testCases, testCase{
9981 name: "PartialEncryptedExtensionsWithServerHello",
9982 config: Config{
9983 MaxVersion: VersionTLS13,
9984 Bugs: ProtocolBugs{
9985 PartialEncryptedExtensionsWithServerHello: true,
9986 },
9987 },
9988 shouldFail: true,
9989 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9990 })
9991 testCases = append(testCases, testCase{
9992 testType: serverTest,
9993 name: "PartialClientFinishedWithClientHello",
9994 config: Config{
9995 MaxVersion: VersionTLS13,
9996 Bugs: ProtocolBugs{
9997 PartialClientFinishedWithClientHello: true,
9998 },
9999 },
10000 shouldFail: true,
10001 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10002 })
10003
David Benjamin82261be2016-07-07 14:32:50 -070010004 // Test that early ChangeCipherSpecs are handled correctly.
10005 testCases = append(testCases, testCase{
10006 testType: serverTest,
10007 name: "EarlyChangeCipherSpec-server-1",
10008 config: Config{
10009 MaxVersion: VersionTLS12,
10010 Bugs: ProtocolBugs{
10011 EarlyChangeCipherSpec: 1,
10012 },
10013 },
10014 shouldFail: true,
10015 expectedError: ":UNEXPECTED_RECORD:",
10016 })
10017 testCases = append(testCases, testCase{
10018 testType: serverTest,
10019 name: "EarlyChangeCipherSpec-server-2",
10020 config: Config{
10021 MaxVersion: VersionTLS12,
10022 Bugs: ProtocolBugs{
10023 EarlyChangeCipherSpec: 2,
10024 },
10025 },
10026 shouldFail: true,
10027 expectedError: ":UNEXPECTED_RECORD:",
10028 })
10029 testCases = append(testCases, testCase{
10030 protocol: dtls,
10031 name: "StrayChangeCipherSpec",
10032 config: Config{
10033 // TODO(davidben): Once DTLS 1.3 exists, test
10034 // that stray ChangeCipherSpec messages are
10035 // rejected.
10036 MaxVersion: VersionTLS12,
10037 Bugs: ProtocolBugs{
10038 StrayChangeCipherSpec: true,
10039 },
10040 },
10041 })
10042
David Benjaminb0c761e2017-06-25 22:42:55 -040010043 // Test that reordered ChangeCipherSpecs are tolerated.
10044 testCases = append(testCases, testCase{
10045 protocol: dtls,
10046 name: "ReorderChangeCipherSpec-DTLS-Client",
10047 config: Config{
10048 MaxVersion: VersionTLS12,
10049 Bugs: ProtocolBugs{
10050 ReorderChangeCipherSpec: true,
10051 },
10052 },
10053 resumeSession: true,
10054 })
10055 testCases = append(testCases, testCase{
10056 testType: serverTest,
10057 protocol: dtls,
10058 name: "ReorderChangeCipherSpec-DTLS-Server",
10059 config: Config{
10060 MaxVersion: VersionTLS12,
10061 Bugs: ProtocolBugs{
10062 ReorderChangeCipherSpec: true,
10063 },
10064 },
10065 resumeSession: true,
10066 })
10067
David Benjamin82261be2016-07-07 14:32:50 -070010068 // Test that the contents of ChangeCipherSpec are checked.
10069 testCases = append(testCases, testCase{
10070 name: "BadChangeCipherSpec-1",
10071 config: Config{
10072 MaxVersion: VersionTLS12,
10073 Bugs: ProtocolBugs{
10074 BadChangeCipherSpec: []byte{2},
10075 },
10076 },
10077 shouldFail: true,
10078 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10079 })
10080 testCases = append(testCases, testCase{
10081 name: "BadChangeCipherSpec-2",
10082 config: Config{
10083 MaxVersion: VersionTLS12,
10084 Bugs: ProtocolBugs{
10085 BadChangeCipherSpec: []byte{1, 1},
10086 },
10087 },
10088 shouldFail: true,
10089 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10090 })
10091 testCases = append(testCases, testCase{
10092 protocol: dtls,
10093 name: "BadChangeCipherSpec-DTLS-1",
10094 config: Config{
10095 MaxVersion: VersionTLS12,
10096 Bugs: ProtocolBugs{
10097 BadChangeCipherSpec: []byte{2},
10098 },
10099 },
10100 shouldFail: true,
10101 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10102 })
10103 testCases = append(testCases, testCase{
10104 protocol: dtls,
10105 name: "BadChangeCipherSpec-DTLS-2",
10106 config: Config{
10107 MaxVersion: VersionTLS12,
10108 Bugs: ProtocolBugs{
10109 BadChangeCipherSpec: []byte{1, 1},
10110 },
10111 },
10112 shouldFail: true,
10113 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10114 })
10115}
10116
David Benjamincd2c8062016-09-09 11:28:16 -040010117type perMessageTest struct {
10118 messageType uint8
10119 test testCase
10120}
10121
10122// makePerMessageTests returns a series of test templates which cover each
10123// message in the TLS handshake. These may be used with bugs like
10124// WrongMessageType to fully test a per-message bug.
10125func makePerMessageTests() []perMessageTest {
10126 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010127 for _, protocol := range []protocol{tls, dtls} {
10128 var suffix string
10129 if protocol == dtls {
10130 suffix = "-DTLS"
10131 }
10132
David Benjamincd2c8062016-09-09 11:28:16 -040010133 ret = append(ret, perMessageTest{
10134 messageType: typeClientHello,
10135 test: testCase{
10136 protocol: protocol,
10137 testType: serverTest,
10138 name: "ClientHello" + suffix,
10139 config: Config{
10140 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010141 },
10142 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010143 })
10144
10145 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010146 ret = append(ret, perMessageTest{
10147 messageType: typeHelloVerifyRequest,
10148 test: testCase{
10149 protocol: protocol,
10150 name: "HelloVerifyRequest" + suffix,
10151 config: Config{
10152 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010153 },
10154 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010155 })
10156 }
10157
David Benjamincd2c8062016-09-09 11:28:16 -040010158 ret = append(ret, perMessageTest{
10159 messageType: typeServerHello,
10160 test: testCase{
10161 protocol: protocol,
10162 name: "ServerHello" + suffix,
10163 config: Config{
10164 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010165 },
10166 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010167 })
10168
David Benjamincd2c8062016-09-09 11:28:16 -040010169 ret = append(ret, perMessageTest{
10170 messageType: typeCertificate,
10171 test: testCase{
10172 protocol: protocol,
10173 name: "ServerCertificate" + suffix,
10174 config: Config{
10175 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010176 },
10177 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010178 })
10179
David Benjamincd2c8062016-09-09 11:28:16 -040010180 ret = append(ret, perMessageTest{
10181 messageType: typeCertificateStatus,
10182 test: testCase{
10183 protocol: protocol,
10184 name: "CertificateStatus" + suffix,
10185 config: Config{
10186 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010187 },
David Benjamincd2c8062016-09-09 11:28:16 -040010188 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010189 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010190 })
10191
David Benjamincd2c8062016-09-09 11:28:16 -040010192 ret = append(ret, perMessageTest{
10193 messageType: typeServerKeyExchange,
10194 test: testCase{
10195 protocol: protocol,
10196 name: "ServerKeyExchange" + suffix,
10197 config: Config{
10198 MaxVersion: VersionTLS12,
10199 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010200 },
10201 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010202 })
10203
David Benjamincd2c8062016-09-09 11:28:16 -040010204 ret = append(ret, perMessageTest{
10205 messageType: typeCertificateRequest,
10206 test: testCase{
10207 protocol: protocol,
10208 name: "CertificateRequest" + suffix,
10209 config: Config{
10210 MaxVersion: VersionTLS12,
10211 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010212 },
10213 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010214 })
10215
David Benjamincd2c8062016-09-09 11:28:16 -040010216 ret = append(ret, perMessageTest{
10217 messageType: typeServerHelloDone,
10218 test: testCase{
10219 protocol: protocol,
10220 name: "ServerHelloDone" + suffix,
10221 config: Config{
10222 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010223 },
10224 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010225 })
10226
David Benjamincd2c8062016-09-09 11:28:16 -040010227 ret = append(ret, perMessageTest{
10228 messageType: typeCertificate,
10229 test: testCase{
10230 testType: serverTest,
10231 protocol: protocol,
10232 name: "ClientCertificate" + suffix,
10233 config: Config{
10234 Certificates: []Certificate{rsaCertificate},
10235 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010236 },
David Benjamincd2c8062016-09-09 11:28:16 -040010237 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010238 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010239 })
10240
David Benjamincd2c8062016-09-09 11:28:16 -040010241 ret = append(ret, perMessageTest{
10242 messageType: typeCertificateVerify,
10243 test: testCase{
10244 testType: serverTest,
10245 protocol: protocol,
10246 name: "CertificateVerify" + suffix,
10247 config: Config{
10248 Certificates: []Certificate{rsaCertificate},
10249 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010250 },
David Benjamincd2c8062016-09-09 11:28:16 -040010251 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010252 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010253 })
10254
David Benjamincd2c8062016-09-09 11:28:16 -040010255 ret = append(ret, perMessageTest{
10256 messageType: typeClientKeyExchange,
10257 test: testCase{
10258 testType: serverTest,
10259 protocol: protocol,
10260 name: "ClientKeyExchange" + suffix,
10261 config: Config{
10262 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010263 },
10264 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010265 })
10266
10267 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010268 ret = append(ret, perMessageTest{
10269 messageType: typeNextProtocol,
10270 test: testCase{
10271 testType: serverTest,
10272 protocol: protocol,
10273 name: "NextProtocol" + suffix,
10274 config: Config{
10275 MaxVersion: VersionTLS12,
10276 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010277 },
David Benjamincd2c8062016-09-09 11:28:16 -040010278 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010279 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010280 })
10281
David Benjamincd2c8062016-09-09 11:28:16 -040010282 ret = append(ret, perMessageTest{
10283 messageType: typeChannelID,
10284 test: testCase{
10285 testType: serverTest,
10286 protocol: protocol,
10287 name: "ChannelID" + suffix,
10288 config: Config{
10289 MaxVersion: VersionTLS12,
10290 ChannelID: channelIDKey,
10291 },
10292 flags: []string{
10293 "-expect-channel-id",
10294 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010295 },
10296 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010297 })
10298 }
10299
David Benjamincd2c8062016-09-09 11:28:16 -040010300 ret = append(ret, perMessageTest{
10301 messageType: typeFinished,
10302 test: testCase{
10303 testType: serverTest,
10304 protocol: protocol,
10305 name: "ClientFinished" + suffix,
10306 config: Config{
10307 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010308 },
10309 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010310 })
10311
David Benjamincd2c8062016-09-09 11:28:16 -040010312 ret = append(ret, perMessageTest{
10313 messageType: typeNewSessionTicket,
10314 test: testCase{
10315 protocol: protocol,
10316 name: "NewSessionTicket" + suffix,
10317 config: Config{
10318 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010319 },
10320 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010321 })
10322
David Benjamincd2c8062016-09-09 11:28:16 -040010323 ret = append(ret, perMessageTest{
10324 messageType: typeFinished,
10325 test: testCase{
10326 protocol: protocol,
10327 name: "ServerFinished" + suffix,
10328 config: Config{
10329 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010330 },
10331 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010332 })
10333
10334 }
David Benjamincd2c8062016-09-09 11:28:16 -040010335
10336 ret = append(ret, perMessageTest{
10337 messageType: typeClientHello,
10338 test: testCase{
10339 testType: serverTest,
10340 name: "TLS13-ClientHello",
10341 config: Config{
10342 MaxVersion: VersionTLS13,
10343 },
10344 },
10345 })
10346
10347 ret = append(ret, perMessageTest{
10348 messageType: typeServerHello,
10349 test: testCase{
10350 name: "TLS13-ServerHello",
10351 config: Config{
10352 MaxVersion: VersionTLS13,
10353 },
10354 },
10355 })
10356
10357 ret = append(ret, perMessageTest{
10358 messageType: typeEncryptedExtensions,
10359 test: testCase{
10360 name: "TLS13-EncryptedExtensions",
10361 config: Config{
10362 MaxVersion: VersionTLS13,
10363 },
10364 },
10365 })
10366
10367 ret = append(ret, perMessageTest{
10368 messageType: typeCertificateRequest,
10369 test: testCase{
10370 name: "TLS13-CertificateRequest",
10371 config: Config{
10372 MaxVersion: VersionTLS13,
10373 ClientAuth: RequireAnyClientCert,
10374 },
10375 },
10376 })
10377
10378 ret = append(ret, perMessageTest{
10379 messageType: typeCertificate,
10380 test: testCase{
10381 name: "TLS13-ServerCertificate",
10382 config: Config{
10383 MaxVersion: VersionTLS13,
10384 },
10385 },
10386 })
10387
10388 ret = append(ret, perMessageTest{
10389 messageType: typeCertificateVerify,
10390 test: testCase{
10391 name: "TLS13-ServerCertificateVerify",
10392 config: Config{
10393 MaxVersion: VersionTLS13,
10394 },
10395 },
10396 })
10397
10398 ret = append(ret, perMessageTest{
10399 messageType: typeFinished,
10400 test: testCase{
10401 name: "TLS13-ServerFinished",
10402 config: Config{
10403 MaxVersion: VersionTLS13,
10404 },
10405 },
10406 })
10407
10408 ret = append(ret, perMessageTest{
10409 messageType: typeCertificate,
10410 test: testCase{
10411 testType: serverTest,
10412 name: "TLS13-ClientCertificate",
10413 config: Config{
10414 Certificates: []Certificate{rsaCertificate},
10415 MaxVersion: VersionTLS13,
10416 },
10417 flags: []string{"-require-any-client-certificate"},
10418 },
10419 })
10420
10421 ret = append(ret, perMessageTest{
10422 messageType: typeCertificateVerify,
10423 test: testCase{
10424 testType: serverTest,
10425 name: "TLS13-ClientCertificateVerify",
10426 config: Config{
10427 Certificates: []Certificate{rsaCertificate},
10428 MaxVersion: VersionTLS13,
10429 },
10430 flags: []string{"-require-any-client-certificate"},
10431 },
10432 })
10433
10434 ret = append(ret, perMessageTest{
10435 messageType: typeFinished,
10436 test: testCase{
10437 testType: serverTest,
10438 name: "TLS13-ClientFinished",
10439 config: Config{
10440 MaxVersion: VersionTLS13,
10441 },
10442 },
10443 })
10444
10445 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010446}
10447
David Benjamincd2c8062016-09-09 11:28:16 -040010448func addWrongMessageTypeTests() {
10449 for _, t := range makePerMessageTests() {
10450 t.test.name = "WrongMessageType-" + t.test.name
10451 t.test.config.Bugs.SendWrongMessageType = t.messageType
10452 t.test.shouldFail = true
10453 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10454 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010455
David Benjamincd2c8062016-09-09 11:28:16 -040010456 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10457 // In TLS 1.3, a bad ServerHello means the client sends
10458 // an unencrypted alert while the server expects
10459 // encryption, so the alert is not readable by runner.
10460 t.test.expectedLocalError = "local error: bad record MAC"
10461 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010462
David Benjamincd2c8062016-09-09 11:28:16 -040010463 testCases = append(testCases, t.test)
10464 }
David Benjaminebacdee2017-04-08 11:00:45 -040010465
10466 // The processing order for TLS 1.3 version negotiation is such that one
10467 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10468 // TLS 1.2. Test that we do not do this.
10469 testCases = append(testCases, testCase{
10470 name: "SendServerHelloAsHelloRetryRequest",
10471 config: Config{
10472 MaxVersion: VersionTLS12,
10473 Bugs: ProtocolBugs{
10474 SendServerHelloAsHelloRetryRequest: true,
10475 },
10476 },
10477 shouldFail: true,
10478 expectedError: ":UNEXPECTED_MESSAGE:",
10479 expectedLocalError: "remote error: unexpected message",
10480 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010481}
10482
David Benjamin639846e2016-09-09 11:41:18 -040010483func addTrailingMessageDataTests() {
10484 for _, t := range makePerMessageTests() {
10485 t.test.name = "TrailingMessageData-" + t.test.name
10486 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10487 t.test.shouldFail = true
10488 t.test.expectedError = ":DECODE_ERROR:"
10489 t.test.expectedLocalError = "remote error: error decoding message"
10490
10491 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10492 // In TLS 1.3, a bad ServerHello means the client sends
10493 // an unencrypted alert while the server expects
10494 // encryption, so the alert is not readable by runner.
10495 t.test.expectedLocalError = "local error: bad record MAC"
10496 }
10497
10498 if t.messageType == typeFinished {
10499 // Bad Finished messages read as the verify data having
10500 // the wrong length.
10501 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10502 t.test.expectedLocalError = "remote error: error decrypting message"
10503 }
10504
10505 testCases = append(testCases, t.test)
10506 }
10507}
10508
Steven Valdez143e8b32016-07-11 13:19:03 -040010509func addTLS13HandshakeTests() {
10510 testCases = append(testCases, testCase{
10511 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010512 name: "NegotiatePSKResumption-TLS13",
10513 config: Config{
10514 MaxVersion: VersionTLS13,
10515 Bugs: ProtocolBugs{
10516 NegotiatePSKResumption: true,
10517 },
10518 },
10519 resumeSession: true,
10520 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010521 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010522 })
10523
10524 testCases = append(testCases, testCase{
10525 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010526 name: "MissingKeyShare-Client",
10527 config: Config{
10528 MaxVersion: VersionTLS13,
10529 Bugs: ProtocolBugs{
10530 MissingKeyShare: true,
10531 },
10532 },
10533 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010534 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010535 })
10536
10537 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010538 testType: serverTest,
10539 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010540 config: Config{
10541 MaxVersion: VersionTLS13,
10542 Bugs: ProtocolBugs{
10543 MissingKeyShare: true,
10544 },
10545 },
10546 shouldFail: true,
10547 expectedError: ":MISSING_KEY_SHARE:",
10548 })
10549
10550 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010551 testType: serverTest,
10552 name: "DuplicateKeyShares",
10553 config: Config{
10554 MaxVersion: VersionTLS13,
10555 Bugs: ProtocolBugs{
10556 DuplicateKeyShares: true,
10557 },
10558 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010559 shouldFail: true,
10560 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010561 })
10562
10563 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010564 testType: serverTest,
10565 name: "SkipEarlyData",
10566 config: Config{
10567 MaxVersion: VersionTLS13,
10568 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010569 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010570 },
10571 },
10572 })
10573
10574 testCases = append(testCases, testCase{
10575 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010576 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010577 config: Config{
10578 MaxVersion: VersionTLS13,
10579 TLS13Variant: TLS13Experiment,
10580 Bugs: ProtocolBugs{
10581 SendFakeEarlyDataLength: 4,
10582 },
10583 },
10584 flags: []string{"-tls13-variant", "1"},
10585 })
10586
10587 testCases = append(testCases, testCase{
10588 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010589 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10590 config: Config{
10591 MaxVersion: VersionTLS13,
10592 TLS13Variant: TLS13RecordTypeExperiment,
10593 Bugs: ProtocolBugs{
10594 SendFakeEarlyDataLength: 4,
10595 },
10596 },
10597 flags: []string{"-tls13-variant", "2"},
10598 })
10599
10600 testCases = append(testCases, testCase{
10601 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010602 name: "SkipEarlyData-OmitEarlyDataExtension",
10603 config: Config{
10604 MaxVersion: VersionTLS13,
10605 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010606 SendFakeEarlyDataLength: 4,
10607 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010608 },
10609 },
10610 shouldFail: true,
10611 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10612 })
10613
10614 testCases = append(testCases, testCase{
10615 testType: serverTest,
10616 name: "SkipEarlyData-TooMuchData",
10617 config: Config{
10618 MaxVersion: VersionTLS13,
10619 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010620 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010621 },
10622 },
10623 shouldFail: true,
10624 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10625 })
10626
10627 testCases = append(testCases, testCase{
10628 testType: serverTest,
10629 name: "SkipEarlyData-Interleaved",
10630 config: Config{
10631 MaxVersion: VersionTLS13,
10632 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010633 SendFakeEarlyDataLength: 4,
10634 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010635 },
10636 },
10637 shouldFail: true,
10638 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10639 })
10640
10641 testCases = append(testCases, testCase{
10642 testType: serverTest,
10643 name: "SkipEarlyData-EarlyDataInTLS12",
10644 config: Config{
10645 MaxVersion: VersionTLS13,
10646 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010647 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010648 },
10649 },
10650 shouldFail: true,
10651 expectedError: ":UNEXPECTED_RECORD:",
10652 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10653 })
10654
10655 testCases = append(testCases, testCase{
10656 testType: serverTest,
10657 name: "SkipEarlyData-HRR",
10658 config: Config{
10659 MaxVersion: VersionTLS13,
10660 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010661 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010662 },
10663 DefaultCurves: []CurveID{},
10664 },
10665 })
10666
10667 testCases = append(testCases, testCase{
10668 testType: serverTest,
10669 name: "SkipEarlyData-HRR-Interleaved",
10670 config: Config{
10671 MaxVersion: VersionTLS13,
10672 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010673 SendFakeEarlyDataLength: 4,
10674 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010675 },
10676 DefaultCurves: []CurveID{},
10677 },
10678 shouldFail: true,
10679 expectedError: ":UNEXPECTED_RECORD:",
10680 })
10681
10682 testCases = append(testCases, testCase{
10683 testType: serverTest,
10684 name: "SkipEarlyData-HRR-TooMuchData",
10685 config: Config{
10686 MaxVersion: VersionTLS13,
10687 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010688 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010689 },
10690 DefaultCurves: []CurveID{},
10691 },
10692 shouldFail: true,
10693 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10694 })
10695
10696 // Test that skipping early data looking for cleartext correctly
10697 // processes an alert record.
10698 testCases = append(testCases, testCase{
10699 testType: serverTest,
10700 name: "SkipEarlyData-HRR-FatalAlert",
10701 config: Config{
10702 MaxVersion: VersionTLS13,
10703 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010704 SendEarlyAlert: true,
10705 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010706 },
10707 DefaultCurves: []CurveID{},
10708 },
10709 shouldFail: true,
10710 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10711 })
10712
10713 testCases = append(testCases, testCase{
10714 testType: serverTest,
10715 name: "SkipEarlyData-SecondClientHelloEarlyData",
10716 config: Config{
10717 MaxVersion: VersionTLS13,
10718 Bugs: ProtocolBugs{
10719 SendEarlyDataOnSecondClientHello: true,
10720 },
10721 DefaultCurves: []CurveID{},
10722 },
10723 shouldFail: true,
10724 expectedLocalError: "remote error: bad record MAC",
10725 })
10726
10727 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010728 testType: clientTest,
10729 name: "EmptyEncryptedExtensions",
10730 config: Config{
10731 MaxVersion: VersionTLS13,
10732 Bugs: ProtocolBugs{
10733 EmptyEncryptedExtensions: true,
10734 },
10735 },
10736 shouldFail: true,
10737 expectedLocalError: "remote error: error decoding message",
10738 })
10739
10740 testCases = append(testCases, testCase{
10741 testType: clientTest,
10742 name: "EncryptedExtensionsWithKeyShare",
10743 config: Config{
10744 MaxVersion: VersionTLS13,
10745 Bugs: ProtocolBugs{
10746 EncryptedExtensionsWithKeyShare: true,
10747 },
10748 },
10749 shouldFail: true,
10750 expectedLocalError: "remote error: unsupported extension",
10751 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010752
10753 testCases = append(testCases, testCase{
10754 testType: serverTest,
10755 name: "SendHelloRetryRequest",
10756 config: Config{
10757 MaxVersion: VersionTLS13,
10758 // Require a HelloRetryRequest for every curve.
10759 DefaultCurves: []CurveID{},
10760 },
10761 expectedCurveID: CurveX25519,
10762 })
10763
10764 testCases = append(testCases, testCase{
10765 testType: serverTest,
10766 name: "SendHelloRetryRequest-2",
10767 config: Config{
10768 MaxVersion: VersionTLS13,
10769 DefaultCurves: []CurveID{CurveP384},
10770 },
10771 // Although the ClientHello did not predict our preferred curve,
10772 // we always select it whether it is predicted or not.
10773 expectedCurveID: CurveX25519,
10774 })
10775
10776 testCases = append(testCases, testCase{
10777 name: "UnknownCurve-HelloRetryRequest",
10778 config: Config{
10779 MaxVersion: VersionTLS13,
10780 // P-384 requires HelloRetryRequest in BoringSSL.
10781 CurvePreferences: []CurveID{CurveP384},
10782 Bugs: ProtocolBugs{
10783 SendHelloRetryRequestCurve: bogusCurve,
10784 },
10785 },
10786 shouldFail: true,
10787 expectedError: ":WRONG_CURVE:",
10788 })
10789
10790 testCases = append(testCases, testCase{
10791 name: "DisabledCurve-HelloRetryRequest",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 CurvePreferences: []CurveID{CurveP256},
10795 Bugs: ProtocolBugs{
10796 IgnorePeerCurvePreferences: true,
10797 },
10798 },
10799 flags: []string{"-p384-only"},
10800 shouldFail: true,
10801 expectedError: ":WRONG_CURVE:",
10802 })
10803
10804 testCases = append(testCases, testCase{
10805 name: "UnnecessaryHelloRetryRequest",
10806 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010807 MaxVersion: VersionTLS13,
10808 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010809 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010810 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010811 },
10812 },
10813 shouldFail: true,
10814 expectedError: ":WRONG_CURVE:",
10815 })
10816
10817 testCases = append(testCases, testCase{
10818 name: "SecondHelloRetryRequest",
10819 config: Config{
10820 MaxVersion: VersionTLS13,
10821 // P-384 requires HelloRetryRequest in BoringSSL.
10822 CurvePreferences: []CurveID{CurveP384},
10823 Bugs: ProtocolBugs{
10824 SecondHelloRetryRequest: true,
10825 },
10826 },
10827 shouldFail: true,
10828 expectedError: ":UNEXPECTED_MESSAGE:",
10829 })
10830
10831 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010832 name: "HelloRetryRequest-Empty",
10833 config: Config{
10834 MaxVersion: VersionTLS13,
10835 Bugs: ProtocolBugs{
10836 AlwaysSendHelloRetryRequest: true,
10837 },
10838 },
10839 shouldFail: true,
10840 expectedError: ":DECODE_ERROR:",
10841 })
10842
10843 testCases = append(testCases, testCase{
10844 name: "HelloRetryRequest-DuplicateCurve",
10845 config: Config{
10846 MaxVersion: VersionTLS13,
10847 // P-384 requires a HelloRetryRequest against BoringSSL's default
10848 // configuration. Assert this ExpectMissingKeyShare.
10849 CurvePreferences: []CurveID{CurveP384},
10850 Bugs: ProtocolBugs{
10851 ExpectMissingKeyShare: true,
10852 DuplicateHelloRetryRequestExtensions: true,
10853 },
10854 },
10855 shouldFail: true,
10856 expectedError: ":DUPLICATE_EXTENSION:",
10857 expectedLocalError: "remote error: illegal parameter",
10858 })
10859
10860 testCases = append(testCases, testCase{
10861 name: "HelloRetryRequest-Cookie",
10862 config: Config{
10863 MaxVersion: VersionTLS13,
10864 Bugs: ProtocolBugs{
10865 SendHelloRetryRequestCookie: []byte("cookie"),
10866 },
10867 },
10868 })
10869
10870 testCases = append(testCases, testCase{
10871 name: "HelloRetryRequest-DuplicateCookie",
10872 config: Config{
10873 MaxVersion: VersionTLS13,
10874 Bugs: ProtocolBugs{
10875 SendHelloRetryRequestCookie: []byte("cookie"),
10876 DuplicateHelloRetryRequestExtensions: true,
10877 },
10878 },
10879 shouldFail: true,
10880 expectedError: ":DUPLICATE_EXTENSION:",
10881 expectedLocalError: "remote error: illegal parameter",
10882 })
10883
10884 testCases = append(testCases, testCase{
10885 name: "HelloRetryRequest-EmptyCookie",
10886 config: Config{
10887 MaxVersion: VersionTLS13,
10888 Bugs: ProtocolBugs{
10889 SendHelloRetryRequestCookie: []byte{},
10890 },
10891 },
10892 shouldFail: true,
10893 expectedError: ":DECODE_ERROR:",
10894 })
10895
10896 testCases = append(testCases, testCase{
10897 name: "HelloRetryRequest-Cookie-Curve",
10898 config: Config{
10899 MaxVersion: VersionTLS13,
10900 // P-384 requires HelloRetryRequest in BoringSSL.
10901 CurvePreferences: []CurveID{CurveP384},
10902 Bugs: ProtocolBugs{
10903 SendHelloRetryRequestCookie: []byte("cookie"),
10904 ExpectMissingKeyShare: true,
10905 },
10906 },
10907 })
10908
10909 testCases = append(testCases, testCase{
10910 name: "HelloRetryRequest-Unknown",
10911 config: Config{
10912 MaxVersion: VersionTLS13,
10913 Bugs: ProtocolBugs{
10914 CustomHelloRetryRequestExtension: "extension",
10915 },
10916 },
10917 shouldFail: true,
10918 expectedError: ":UNEXPECTED_EXTENSION:",
10919 expectedLocalError: "remote error: unsupported extension",
10920 })
10921
10922 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010923 testType: serverTest,
10924 name: "SecondClientHelloMissingKeyShare",
10925 config: Config{
10926 MaxVersion: VersionTLS13,
10927 DefaultCurves: []CurveID{},
10928 Bugs: ProtocolBugs{
10929 SecondClientHelloMissingKeyShare: true,
10930 },
10931 },
10932 shouldFail: true,
10933 expectedError: ":MISSING_KEY_SHARE:",
10934 })
10935
10936 testCases = append(testCases, testCase{
10937 testType: serverTest,
10938 name: "SecondClientHelloWrongCurve",
10939 config: Config{
10940 MaxVersion: VersionTLS13,
10941 DefaultCurves: []CurveID{},
10942 Bugs: ProtocolBugs{
10943 MisinterpretHelloRetryRequestCurve: CurveP521,
10944 },
10945 },
10946 shouldFail: true,
10947 expectedError: ":WRONG_CURVE:",
10948 })
10949
10950 testCases = append(testCases, testCase{
10951 name: "HelloRetryRequestVersionMismatch",
10952 config: Config{
10953 MaxVersion: VersionTLS13,
10954 // P-384 requires HelloRetryRequest in BoringSSL.
10955 CurvePreferences: []CurveID{CurveP384},
10956 Bugs: ProtocolBugs{
10957 SendServerHelloVersion: 0x0305,
10958 },
10959 },
10960 shouldFail: true,
10961 expectedError: ":WRONG_VERSION_NUMBER:",
10962 })
10963
10964 testCases = append(testCases, testCase{
10965 name: "HelloRetryRequestCurveMismatch",
10966 config: Config{
10967 MaxVersion: VersionTLS13,
10968 // P-384 requires HelloRetryRequest in BoringSSL.
10969 CurvePreferences: []CurveID{CurveP384},
10970 Bugs: ProtocolBugs{
10971 // Send P-384 (correct) in the HelloRetryRequest.
10972 SendHelloRetryRequestCurve: CurveP384,
10973 // But send P-256 in the ServerHello.
10974 SendCurve: CurveP256,
10975 },
10976 },
10977 shouldFail: true,
10978 expectedError: ":WRONG_CURVE:",
10979 })
10980
10981 // Test the server selecting a curve that requires a HelloRetryRequest
10982 // without sending it.
10983 testCases = append(testCases, testCase{
10984 name: "SkipHelloRetryRequest",
10985 config: Config{
10986 MaxVersion: VersionTLS13,
10987 // P-384 requires HelloRetryRequest in BoringSSL.
10988 CurvePreferences: []CurveID{CurveP384},
10989 Bugs: ProtocolBugs{
10990 SkipHelloRetryRequest: true,
10991 },
10992 },
10993 shouldFail: true,
10994 expectedError: ":WRONG_CURVE:",
10995 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010996
10997 testCases = append(testCases, testCase{
10998 name: "TLS13-RequestContextInHandshake",
10999 config: Config{
11000 MaxVersion: VersionTLS13,
11001 MinVersion: VersionTLS13,
11002 ClientAuth: RequireAnyClientCert,
11003 Bugs: ProtocolBugs{
11004 SendRequestContext: []byte("request context"),
11005 },
11006 },
11007 flags: []string{
11008 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11009 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11010 },
11011 shouldFail: true,
11012 expectedError: ":DECODE_ERROR:",
11013 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011014
11015 testCases = append(testCases, testCase{
11016 testType: serverTest,
11017 name: "TLS13-TrailingKeyShareData",
11018 config: Config{
11019 MaxVersion: VersionTLS13,
11020 Bugs: ProtocolBugs{
11021 TrailingKeyShareData: true,
11022 },
11023 },
11024 shouldFail: true,
11025 expectedError: ":DECODE_ERROR:",
11026 })
David Benjamin7f78df42016-10-05 22:33:19 -040011027
11028 testCases = append(testCases, testCase{
11029 name: "TLS13-AlwaysSelectPSKIdentity",
11030 config: Config{
11031 MaxVersion: VersionTLS13,
11032 Bugs: ProtocolBugs{
11033 AlwaysSelectPSKIdentity: true,
11034 },
11035 },
11036 shouldFail: true,
11037 expectedError: ":UNEXPECTED_EXTENSION:",
11038 })
11039
11040 testCases = append(testCases, testCase{
11041 name: "TLS13-InvalidPSKIdentity",
11042 config: Config{
11043 MaxVersion: VersionTLS13,
11044 Bugs: ProtocolBugs{
11045 SelectPSKIdentityOnResume: 1,
11046 },
11047 },
11048 resumeSession: true,
11049 shouldFail: true,
11050 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11051 })
David Benjamin1286bee2016-10-07 15:25:06 -040011052
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011053 testCases = append(testCases, testCase{
11054 testType: serverTest,
11055 name: "TLS13-ExtraPSKIdentity",
11056 config: Config{
11057 MaxVersion: VersionTLS13,
11058 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011059 ExtraPSKIdentity: true,
11060 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011061 },
11062 },
11063 resumeSession: true,
11064 })
11065
David Benjamin1286bee2016-10-07 15:25:06 -040011066 // Test that unknown NewSessionTicket extensions are tolerated.
11067 testCases = append(testCases, testCase{
11068 name: "TLS13-CustomTicketExtension",
11069 config: Config{
11070 MaxVersion: VersionTLS13,
11071 Bugs: ProtocolBugs{
11072 CustomTicketExtension: "1234",
11073 },
11074 },
11075 })
Steven Valdez2d850622017-01-11 11:34:52 -050011076
Steven Valdez0e4a4482017-07-17 11:12:34 -040011077 for _, noSessionID := range []bool{false, true} {
11078 prefix := "TLS13Experiment"
11079 variant := TLS13Experiment
11080 if noSessionID {
11081 prefix = "TLS13NoSessionIDExperiment"
11082 variant = TLS13NoSessionIDExperiment
11083 }
11084
11085 // Test that enabling a TLS 1.3 variant does not interfere with
11086 // TLS 1.2 session ID resumption.
11087 testCases = append(testCases, testCase{
11088 testType: clientTest,
11089 name: prefix + "-ResumeTLS12SessionID",
11090 config: Config{
11091 MaxVersion: VersionTLS12,
11092 SessionTicketsDisabled: true,
11093 },
11094 resumeSession: true,
11095 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11096 })
11097
11098 // Test that the server correctly echoes back session IDs of
11099 // various lengths.
11100 testCases = append(testCases, testCase{
11101 testType: serverTest,
11102 name: prefix + "-EmptySessionID",
11103 config: Config{
11104 MaxVersion: VersionTLS13,
11105 Bugs: ProtocolBugs{
11106 SendClientHelloSessionID: []byte{},
11107 },
11108 },
11109 tls13Variant: variant,
11110 })
11111
11112 testCases = append(testCases, testCase{
11113 testType: serverTest,
11114 name: prefix + "-ShortSessionID",
11115 config: Config{
11116 MaxVersion: VersionTLS13,
11117 Bugs: ProtocolBugs{
11118 SendClientHelloSessionID: make([]byte, 16),
11119 },
11120 },
11121 tls13Variant: variant,
11122 })
11123
11124 testCases = append(testCases, testCase{
11125 testType: serverTest,
11126 name: prefix + "-FullSessionID",
11127 config: Config{
11128 MaxVersion: VersionTLS13,
11129 Bugs: ProtocolBugs{
11130 SendClientHelloSessionID: make([]byte, 32),
11131 },
11132 },
11133 tls13Variant: variant,
11134 })
11135 }
11136
11137 // Test that the client sends a fake session ID in TLS13Experiment.
11138 testCases = append(testCases, testCase{
11139 testType: clientTest,
11140 name: "TLS13Experiment-RequireSessionID",
11141 config: Config{
11142 MaxVersion: VersionTLS13,
11143 Bugs: ProtocolBugs{
11144 ExpectClientHelloSessionID: true,
11145 },
11146 },
11147 tls13Variant: TLS13Experiment,
11148 })
11149
11150 // Test that the client does not send a fake session ID in
11151 // TLS13NoSessionIDExperiment.
11152 testCases = append(testCases, testCase{
11153 testType: clientTest,
11154 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11155 config: Config{
11156 MaxVersion: VersionTLS13,
11157 Bugs: ProtocolBugs{
11158 ExpectEmptyClientHelloSessionID: true,
11159 },
11160 },
11161 tls13Variant: TLS13NoSessionIDExperiment,
11162 })
11163
Steven Valdez2d850622017-01-11 11:34:52 -050011164 testCases = append(testCases, testCase{
11165 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011166 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011167 config: Config{
11168 MaxVersion: VersionTLS13,
11169 MaxEarlyDataSize: 16384,
11170 },
11171 resumeConfig: &Config{
11172 MaxVersion: VersionTLS13,
11173 MaxEarlyDataSize: 16384,
11174 Bugs: ProtocolBugs{
11175 AlwaysRejectEarlyData: true,
11176 },
11177 },
11178 resumeSession: true,
11179 flags: []string{
11180 "-enable-early-data",
11181 "-expect-early-data-info",
11182 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011183 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011184 },
11185 })
11186
11187 testCases = append(testCases, testCase{
11188 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011189 name: "TLS13Experiment-EarlyData-Reject-Client",
11190 config: Config{
11191 MaxVersion: VersionTLS13,
11192 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011193 },
11194 resumeConfig: &Config{
11195 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011196 MaxEarlyDataSize: 16384,
11197 Bugs: ProtocolBugs{
11198 AlwaysRejectEarlyData: true,
11199 },
11200 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011201 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011202 resumeSession: true,
11203 flags: []string{
11204 "-enable-early-data",
11205 "-expect-early-data-info",
11206 "-expect-reject-early-data",
11207 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011208 },
11209 })
11210
11211 testCases = append(testCases, testCase{
11212 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011213 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11214 config: Config{
11215 MaxVersion: VersionTLS13,
11216 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011217 },
11218 resumeConfig: &Config{
11219 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011220 MaxEarlyDataSize: 16384,
11221 Bugs: ProtocolBugs{
11222 AlwaysRejectEarlyData: true,
11223 },
11224 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011225 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011226 resumeSession: true,
11227 flags: []string{
11228 "-enable-early-data",
11229 "-expect-early-data-info",
11230 "-expect-reject-early-data",
11231 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011232 },
11233 })
11234
11235 testCases = append(testCases, testCase{
11236 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011237 name: "TLS13-EarlyData-RejectTicket-Client",
11238 config: Config{
11239 MaxVersion: VersionTLS13,
11240 MaxEarlyDataSize: 16384,
11241 Certificates: []Certificate{rsaCertificate},
11242 },
11243 resumeConfig: &Config{
11244 MaxVersion: VersionTLS13,
11245 MaxEarlyDataSize: 16384,
11246 Certificates: []Certificate{ecdsaP256Certificate},
11247 SessionTicketsDisabled: true,
11248 },
11249 resumeSession: true,
11250 expectResumeRejected: true,
11251 flags: []string{
11252 "-enable-early-data",
11253 "-expect-early-data-info",
11254 "-expect-reject-early-data",
11255 "-on-resume-shim-writes-first",
11256 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11257 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11258 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11259 // Session tickets are disabled, so the runner will not send a ticket.
11260 "-on-retry-expect-no-session",
11261 },
11262 })
11263
11264 testCases = append(testCases, testCase{
11265 testType: clientTest,
11266 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011267 config: Config{
11268 MaxVersion: VersionTLS13,
11269 MaxEarlyDataSize: 16384,
11270 },
11271 resumeConfig: &Config{
11272 MaxVersion: VersionTLS13,
11273 MaxEarlyDataSize: 16384,
11274 Bugs: ProtocolBugs{
11275 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11276 },
11277 },
11278 resumeSession: true,
11279 flags: []string{
11280 "-enable-early-data",
11281 "-expect-early-data-info",
11282 "-expect-reject-early-data",
11283 },
11284 })
11285
11286 // The client must check the server does not send the early_data
11287 // extension while rejecting the session.
11288 testCases = append(testCases, testCase{
11289 testType: clientTest,
11290 name: "TLS13-EarlyDataWithoutResume-Client",
11291 config: Config{
11292 MaxVersion: VersionTLS13,
11293 MaxEarlyDataSize: 16384,
11294 },
11295 resumeConfig: &Config{
11296 MaxVersion: VersionTLS13,
11297 SessionTicketsDisabled: true,
11298 Bugs: ProtocolBugs{
11299 SendEarlyDataExtension: true,
11300 },
11301 },
11302 resumeSession: true,
11303 flags: []string{
11304 "-enable-early-data",
11305 "-expect-early-data-info",
11306 },
11307 shouldFail: true,
11308 expectedError: ":UNEXPECTED_EXTENSION:",
11309 })
11310
11311 // The client must fail with a dedicated error code if the server
11312 // responds with TLS 1.2 when offering 0-RTT.
11313 testCases = append(testCases, testCase{
11314 testType: clientTest,
11315 name: "TLS13-EarlyDataVersionDowngrade-Client",
11316 config: Config{
11317 MaxVersion: VersionTLS13,
11318 MaxEarlyDataSize: 16384,
11319 },
11320 resumeConfig: &Config{
11321 MaxVersion: VersionTLS12,
11322 },
11323 resumeSession: true,
11324 flags: []string{
11325 "-enable-early-data",
11326 "-expect-early-data-info",
11327 },
11328 shouldFail: true,
11329 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11330 })
11331
11332 // Test that the client rejects an (unsolicited) early_data extension if
11333 // the server sent an HRR.
11334 testCases = append(testCases, testCase{
11335 testType: clientTest,
11336 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11337 config: Config{
11338 MaxVersion: VersionTLS13,
11339 MaxEarlyDataSize: 16384,
11340 },
11341 resumeConfig: &Config{
11342 MaxVersion: VersionTLS13,
11343 MaxEarlyDataSize: 16384,
11344 Bugs: ProtocolBugs{
11345 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11346 SendEarlyDataExtension: true,
11347 },
11348 },
11349 resumeSession: true,
11350 flags: []string{
11351 "-enable-early-data",
11352 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011353 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011354 },
11355 shouldFail: true,
11356 expectedError: ":UNEXPECTED_EXTENSION:",
11357 })
11358
11359 fooString := "foo"
11360 barString := "bar"
11361
11362 // Test that the client reports the correct ALPN after a 0-RTT reject
11363 // that changed it.
11364 testCases = append(testCases, testCase{
11365 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011366 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011367 config: Config{
11368 MaxVersion: VersionTLS13,
11369 MaxEarlyDataSize: 16384,
11370 Bugs: ProtocolBugs{
11371 ALPNProtocol: &fooString,
11372 },
11373 },
11374 resumeConfig: &Config{
11375 MaxVersion: VersionTLS13,
11376 MaxEarlyDataSize: 16384,
11377 Bugs: ProtocolBugs{
11378 ALPNProtocol: &barString,
11379 },
11380 },
11381 resumeSession: true,
11382 flags: []string{
11383 "-advertise-alpn", "\x03foo\x03bar",
11384 "-enable-early-data",
11385 "-expect-early-data-info",
11386 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011387 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011388 "-on-resume-expect-alpn", "foo",
11389 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011390 },
11391 })
11392
11393 // Test that the client reports the correct ALPN after a 0-RTT reject if
11394 // ALPN was omitted from the first connection.
11395 testCases = append(testCases, testCase{
11396 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011397 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011398 config: Config{
11399 MaxVersion: VersionTLS13,
11400 MaxEarlyDataSize: 16384,
11401 },
11402 resumeConfig: &Config{
11403 MaxVersion: VersionTLS13,
11404 MaxEarlyDataSize: 16384,
11405 NextProtos: []string{"foo"},
11406 },
11407 resumeSession: true,
11408 flags: []string{
11409 "-advertise-alpn", "\x03foo\x03bar",
11410 "-enable-early-data",
11411 "-expect-early-data-info",
11412 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011413 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011414 "-on-resume-expect-alpn", "",
11415 "-on-retry-expect-alpn", "foo",
11416 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011417 },
11418 })
11419
11420 // Test that the client reports the correct ALPN after a 0-RTT reject if
11421 // ALPN was omitted from the second connection.
11422 testCases = append(testCases, testCase{
11423 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011424 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011425 config: Config{
11426 MaxVersion: VersionTLS13,
11427 MaxEarlyDataSize: 16384,
11428 NextProtos: []string{"foo"},
11429 },
11430 resumeConfig: &Config{
11431 MaxVersion: VersionTLS13,
11432 MaxEarlyDataSize: 16384,
11433 },
11434 resumeSession: true,
11435 flags: []string{
11436 "-advertise-alpn", "\x03foo\x03bar",
11437 "-enable-early-data",
11438 "-expect-early-data-info",
11439 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011440 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011441 "-on-resume-expect-alpn", "foo",
11442 "-on-retry-expect-alpn", "",
11443 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011444 },
11445 })
11446
11447 // Test that the client enforces ALPN match on 0-RTT accept.
11448 testCases = append(testCases, testCase{
11449 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011450 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011451 config: Config{
11452 MaxVersion: VersionTLS13,
11453 MaxEarlyDataSize: 16384,
11454 Bugs: ProtocolBugs{
11455 ALPNProtocol: &fooString,
11456 },
11457 },
11458 resumeConfig: &Config{
11459 MaxVersion: VersionTLS13,
11460 MaxEarlyDataSize: 16384,
11461 Bugs: ProtocolBugs{
11462 AlwaysAcceptEarlyData: true,
11463 ALPNProtocol: &barString,
11464 },
11465 },
11466 resumeSession: true,
11467 flags: []string{
11468 "-advertise-alpn", "\x03foo\x03bar",
11469 "-enable-early-data",
11470 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011471 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011472 "-on-resume-expect-alpn", "foo",
11473 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011474 },
11475 shouldFail: true,
11476 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11477 })
11478
11479 // Test that the server correctly rejects 0-RTT when the previous
11480 // session did not allow early data on resumption.
11481 testCases = append(testCases, testCase{
11482 testType: serverTest,
11483 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11484 config: Config{
11485 MaxVersion: VersionTLS13,
11486 },
11487 resumeConfig: &Config{
11488 MaxVersion: VersionTLS13,
11489 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011490 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011491 ExpectEarlyDataAccepted: false,
11492 },
11493 },
11494 resumeSession: true,
11495 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011496 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011497 "-expect-reject-early-data",
11498 },
11499 })
11500
11501 // Test that we reject early data where ALPN is omitted from the first
11502 // connection.
11503 testCases = append(testCases, testCase{
11504 testType: serverTest,
11505 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11506 config: Config{
11507 MaxVersion: VersionTLS13,
11508 NextProtos: []string{},
11509 },
11510 resumeConfig: &Config{
11511 MaxVersion: VersionTLS13,
11512 NextProtos: []string{"foo"},
11513 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011514 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011515 ExpectEarlyDataAccepted: false,
11516 },
11517 },
11518 resumeSession: true,
11519 flags: []string{
11520 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011521 "-on-initial-select-alpn", "",
11522 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011523 },
11524 })
11525
11526 // Test that we reject early data where ALPN is omitted from the second
11527 // connection.
11528 testCases = append(testCases, testCase{
11529 testType: serverTest,
11530 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11531 config: Config{
11532 MaxVersion: VersionTLS13,
11533 NextProtos: []string{"foo"},
11534 },
11535 resumeConfig: &Config{
11536 MaxVersion: VersionTLS13,
11537 NextProtos: []string{},
11538 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011539 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011540 ExpectEarlyDataAccepted: false,
11541 },
11542 },
11543 resumeSession: true,
11544 flags: []string{
11545 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011546 "-on-initial-select-alpn", "foo",
11547 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011548 },
11549 })
11550
11551 // Test that we reject early data with mismatched ALPN.
11552 testCases = append(testCases, testCase{
11553 testType: serverTest,
11554 name: "TLS13-EarlyData-ALPNMismatch-Server",
11555 config: Config{
11556 MaxVersion: VersionTLS13,
11557 NextProtos: []string{"foo"},
11558 },
11559 resumeConfig: &Config{
11560 MaxVersion: VersionTLS13,
11561 NextProtos: []string{"bar"},
11562 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011563 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011564 ExpectEarlyDataAccepted: false,
11565 },
11566 },
11567 resumeSession: true,
11568 flags: []string{
11569 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011570 "-on-initial-select-alpn", "foo",
11571 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011572 },
11573 })
11574
David Benjamin6bb507b2017-03-29 16:35:57 -050011575 // Test that the client offering 0-RTT and Channel ID forbids the server
11576 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011577 testCases = append(testCases, testCase{
11578 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011579 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011580 config: Config{
11581 MaxVersion: VersionTLS13,
11582 MaxEarlyDataSize: 16384,
11583 RequestChannelID: true,
11584 },
11585 resumeSession: true,
11586 expectChannelID: true,
11587 shouldFail: true,
11588 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11589 flags: []string{
11590 "-enable-early-data",
11591 "-expect-early-data-info",
11592 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11593 },
11594 })
11595
David Benjamin6bb507b2017-03-29 16:35:57 -050011596 // Test that the client offering Channel ID and 0-RTT allows the server
11597 // to decline 0-RTT.
11598 testCases = append(testCases, testCase{
11599 testType: clientTest,
11600 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11601 config: Config{
11602 MaxVersion: VersionTLS13,
11603 MaxEarlyDataSize: 16384,
11604 RequestChannelID: true,
11605 Bugs: ProtocolBugs{
11606 AlwaysRejectEarlyData: true,
11607 },
11608 },
11609 resumeSession: true,
11610 expectChannelID: true,
11611 flags: []string{
11612 "-enable-early-data",
11613 "-expect-early-data-info",
11614 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11615 "-expect-reject-early-data",
11616 },
11617 })
11618
11619 // Test that the client offering Channel ID and 0-RTT allows the server
11620 // to decline Channel ID.
11621 testCases = append(testCases, testCase{
11622 testType: clientTest,
11623 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11624 config: Config{
11625 MaxVersion: VersionTLS13,
11626 MaxEarlyDataSize: 16384,
11627 },
11628 resumeSession: true,
11629 flags: []string{
11630 "-enable-early-data",
11631 "-expect-early-data-info",
11632 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11633 "-expect-accept-early-data",
11634 },
11635 })
11636
11637 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11638 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011639 testCases = append(testCases, testCase{
11640 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011641 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011642 config: Config{
11643 MaxVersion: VersionTLS13,
11644 ChannelID: channelIDKey,
11645 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011646 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011647 ExpectEarlyDataAccepted: false,
11648 },
11649 },
11650 resumeSession: true,
11651 expectChannelID: true,
11652 flags: []string{
11653 "-enable-early-data",
11654 "-expect-reject-early-data",
11655 "-expect-channel-id",
11656 base64.StdEncoding.EncodeToString(channelIDBytes),
11657 },
11658 })
11659
David Benjamin6bb507b2017-03-29 16:35:57 -050011660 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11661 // if not offered Channel ID.
11662 testCases = append(testCases, testCase{
11663 testType: serverTest,
11664 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11665 config: Config{
11666 MaxVersion: VersionTLS13,
11667 Bugs: ProtocolBugs{
11668 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11669 ExpectEarlyDataAccepted: true,
11670 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11671 },
11672 },
11673 resumeSession: true,
11674 expectChannelID: false,
11675 flags: []string{
11676 "-enable-early-data",
11677 "-expect-accept-early-data",
11678 "-enable-channel-id",
11679 },
11680 })
11681
David Benjamin32c89272017-03-26 13:54:21 -050011682 // Test that the server rejects 0-RTT streams without end_of_early_data.
11683 // The subsequent records should fail to decrypt.
11684 testCases = append(testCases, testCase{
11685 testType: serverTest,
11686 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11687 config: Config{
11688 MaxVersion: VersionTLS13,
11689 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011690 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011691 ExpectEarlyDataAccepted: true,
11692 SkipEndOfEarlyData: true,
11693 },
11694 },
11695 resumeSession: true,
11696 flags: []string{"-enable-early-data"},
11697 shouldFail: true,
11698 expectedLocalError: "remote error: bad record MAC",
11699 expectedError: ":BAD_DECRYPT:",
11700 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011701
11702 testCases = append(testCases, testCase{
11703 testType: serverTest,
11704 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11705 config: Config{
11706 MaxVersion: VersionTLS13,
11707 },
11708 resumeConfig: &Config{
11709 MaxVersion: VersionTLS13,
11710 Bugs: ProtocolBugs{
11711 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11712 SendStrayEarlyHandshake: true,
11713 ExpectEarlyDataAccepted: true},
11714 },
11715 resumeSession: true,
11716 shouldFail: true,
11717 expectedError: ":UNEXPECTED_RECORD:",
11718 expectedLocalError: "remote error: unexpected message",
11719 flags: []string{
11720 "-enable-early-data",
11721 },
11722 })
David Benjamind9cbb532017-07-07 13:17:19 -040011723
11724 // Test that the client reports TLS 1.3 as the version while sending
11725 // early data.
11726 testCases = append(testCases, testCase{
11727 testType: clientTest,
11728 name: "TLS13-EarlyData-Client-VersionAPI",
11729 config: Config{
11730 MaxVersion: VersionTLS13,
11731 MaxEarlyDataSize: 16384,
11732 },
11733 resumeSession: true,
11734 flags: []string{
11735 "-enable-early-data",
11736 "-expect-early-data-info",
11737 "-expect-accept-early-data",
11738 "-expect-version", strconv.Itoa(VersionTLS13),
11739 },
11740 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011741}
11742
David Benjaminabbbee12016-10-31 19:20:42 -040011743func addTLS13CipherPreferenceTests() {
11744 // Test that client preference is honored if the shim has AES hardware
11745 // and ChaCha20-Poly1305 is preferred otherwise.
11746 testCases = append(testCases, testCase{
11747 testType: serverTest,
11748 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11749 config: Config{
11750 MaxVersion: VersionTLS13,
11751 CipherSuites: []uint16{
11752 TLS_CHACHA20_POLY1305_SHA256,
11753 TLS_AES_128_GCM_SHA256,
11754 },
11755 },
11756 flags: []string{
11757 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11758 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11759 },
11760 })
11761
11762 testCases = append(testCases, testCase{
11763 testType: serverTest,
11764 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11765 config: Config{
11766 MaxVersion: VersionTLS13,
11767 CipherSuites: []uint16{
11768 TLS_AES_128_GCM_SHA256,
11769 TLS_CHACHA20_POLY1305_SHA256,
11770 },
11771 },
11772 flags: []string{
11773 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11774 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11775 },
11776 })
11777
11778 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11779 // whether it has AES hardware.
11780 testCases = append(testCases, testCase{
11781 name: "TLS13-CipherPreference-Client",
11782 config: Config{
11783 MaxVersion: VersionTLS13,
11784 // Use the client cipher order. (This is the default but
11785 // is listed to be explicit.)
11786 PreferServerCipherSuites: false,
11787 },
11788 flags: []string{
11789 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11790 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11791 },
11792 })
11793}
11794
David Benjaminf3fbade2016-09-19 13:08:16 -040011795func addPeekTests() {
11796 // Test SSL_peek works, including on empty records.
11797 testCases = append(testCases, testCase{
11798 name: "Peek-Basic",
11799 sendEmptyRecords: 1,
11800 flags: []string{"-peek-then-read"},
11801 })
11802
11803 // Test SSL_peek can drive the initial handshake.
11804 testCases = append(testCases, testCase{
11805 name: "Peek-ImplicitHandshake",
11806 flags: []string{
11807 "-peek-then-read",
11808 "-implicit-handshake",
11809 },
11810 })
11811
11812 // Test SSL_peek can discover and drive a renegotiation.
11813 testCases = append(testCases, testCase{
11814 name: "Peek-Renegotiate",
11815 config: Config{
11816 MaxVersion: VersionTLS12,
11817 },
11818 renegotiate: 1,
11819 flags: []string{
11820 "-peek-then-read",
11821 "-renegotiate-freely",
11822 "-expect-total-renegotiations", "1",
11823 },
11824 })
11825
11826 // Test SSL_peek can discover a close_notify.
11827 testCases = append(testCases, testCase{
11828 name: "Peek-Shutdown",
11829 config: Config{
11830 Bugs: ProtocolBugs{
11831 ExpectCloseNotify: true,
11832 },
11833 },
11834 flags: []string{
11835 "-peek-then-read",
11836 "-check-close-notify",
11837 },
11838 })
11839
11840 // Test SSL_peek can discover an alert.
11841 testCases = append(testCases, testCase{
11842 name: "Peek-Alert",
11843 config: Config{
11844 Bugs: ProtocolBugs{
11845 SendSpuriousAlert: alertRecordOverflow,
11846 },
11847 },
11848 flags: []string{"-peek-then-read"},
11849 shouldFail: true,
11850 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11851 })
11852
11853 // Test SSL_peek can handle KeyUpdate.
11854 testCases = append(testCases, testCase{
11855 name: "Peek-KeyUpdate",
11856 config: Config{
11857 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011858 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011859 sendKeyUpdates: 1,
11860 keyUpdateRequest: keyUpdateNotRequested,
11861 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011862 })
11863}
11864
David Benjamine6f22212016-11-08 14:28:24 -050011865func addRecordVersionTests() {
11866 for _, ver := range tlsVersions {
11867 // Test that the record version is enforced.
11868 testCases = append(testCases, testCase{
11869 name: "CheckRecordVersion-" + ver.name,
11870 config: Config{
11871 MinVersion: ver.version,
11872 MaxVersion: ver.version,
11873 Bugs: ProtocolBugs{
11874 SendRecordVersion: 0x03ff,
11875 },
11876 },
David Benjamina5022392017-07-10 17:40:39 -040011877 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011878 shouldFail: true,
11879 expectedError: ":WRONG_VERSION_NUMBER:",
11880 })
11881
11882 // Test that the ClientHello may use any record version, for
11883 // compatibility reasons.
11884 testCases = append(testCases, testCase{
11885 testType: serverTest,
11886 name: "LooseInitialRecordVersion-" + ver.name,
11887 config: Config{
11888 MinVersion: ver.version,
11889 MaxVersion: ver.version,
11890 Bugs: ProtocolBugs{
11891 SendInitialRecordVersion: 0x03ff,
11892 },
11893 },
David Benjamina5022392017-07-10 17:40:39 -040011894 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011895 })
11896
11897 // Test that garbage ClientHello record versions are rejected.
11898 testCases = append(testCases, testCase{
11899 testType: serverTest,
11900 name: "GarbageInitialRecordVersion-" + ver.name,
11901 config: Config{
11902 MinVersion: ver.version,
11903 MaxVersion: ver.version,
11904 Bugs: ProtocolBugs{
11905 SendInitialRecordVersion: 0xffff,
11906 },
11907 },
David Benjamina5022392017-07-10 17:40:39 -040011908 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011909 shouldFail: true,
11910 expectedError: ":WRONG_VERSION_NUMBER:",
11911 })
11912 }
11913}
11914
David Benjamin2c516452016-11-15 10:16:54 +090011915func addCertificateTests() {
11916 // Test that a certificate chain with intermediate may be sent and
11917 // received as both client and server.
11918 for _, ver := range tlsVersions {
11919 testCases = append(testCases, testCase{
11920 testType: clientTest,
11921 name: "SendReceiveIntermediate-Client-" + ver.name,
11922 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011923 MinVersion: ver.version,
11924 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011925 Certificates: []Certificate{rsaChainCertificate},
11926 ClientAuth: RequireAnyClientCert,
11927 },
David Benjamina5022392017-07-10 17:40:39 -040011928 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011929 expectPeerCertificate: &rsaChainCertificate,
11930 flags: []string{
11931 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11932 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11933 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11934 },
11935 })
11936
11937 testCases = append(testCases, testCase{
11938 testType: serverTest,
11939 name: "SendReceiveIntermediate-Server-" + ver.name,
11940 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011941 MinVersion: ver.version,
11942 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011943 Certificates: []Certificate{rsaChainCertificate},
11944 },
David Benjamina5022392017-07-10 17:40:39 -040011945 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011946 expectPeerCertificate: &rsaChainCertificate,
11947 flags: []string{
11948 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11949 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11950 "-require-any-client-certificate",
11951 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11952 },
11953 })
11954 }
11955}
11956
David Benjaminbbaf3672016-11-17 10:53:09 +090011957func addRetainOnlySHA256ClientCertTests() {
11958 for _, ver := range tlsVersions {
11959 // Test that enabling
11960 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11961 // actually requesting a client certificate is a no-op.
11962 testCases = append(testCases, testCase{
11963 testType: serverTest,
11964 name: "RetainOnlySHA256-NoCert-" + ver.name,
11965 config: Config{
11966 MinVersion: ver.version,
11967 MaxVersion: ver.version,
11968 },
David Benjamina5022392017-07-10 17:40:39 -040011969 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011970 flags: []string{
11971 "-retain-only-sha256-client-cert-initial",
11972 "-retain-only-sha256-client-cert-resume",
11973 },
11974 resumeSession: true,
11975 })
11976
11977 // Test that when retaining only a SHA-256 certificate is
11978 // enabled, the hash appears as expected.
11979 testCases = append(testCases, testCase{
11980 testType: serverTest,
11981 name: "RetainOnlySHA256-Cert-" + ver.name,
11982 config: Config{
11983 MinVersion: ver.version,
11984 MaxVersion: ver.version,
11985 Certificates: []Certificate{rsaCertificate},
11986 },
David Benjamina5022392017-07-10 17:40:39 -040011987 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011988 flags: []string{
11989 "-verify-peer",
11990 "-retain-only-sha256-client-cert-initial",
11991 "-retain-only-sha256-client-cert-resume",
11992 "-expect-sha256-client-cert-initial",
11993 "-expect-sha256-client-cert-resume",
11994 },
11995 resumeSession: true,
11996 })
11997
11998 // Test that when the config changes from on to off, a
11999 // resumption is rejected because the server now wants the full
12000 // certificate chain.
12001 testCases = append(testCases, testCase{
12002 testType: serverTest,
12003 name: "RetainOnlySHA256-OnOff-" + ver.name,
12004 config: Config{
12005 MinVersion: ver.version,
12006 MaxVersion: ver.version,
12007 Certificates: []Certificate{rsaCertificate},
12008 },
David Benjamina5022392017-07-10 17:40:39 -040012009 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012010 flags: []string{
12011 "-verify-peer",
12012 "-retain-only-sha256-client-cert-initial",
12013 "-expect-sha256-client-cert-initial",
12014 },
12015 resumeSession: true,
12016 expectResumeRejected: true,
12017 })
12018
12019 // Test that when the config changes from off to on, a
12020 // resumption is rejected because the server now wants just the
12021 // hash.
12022 testCases = append(testCases, testCase{
12023 testType: serverTest,
12024 name: "RetainOnlySHA256-OffOn-" + ver.name,
12025 config: Config{
12026 MinVersion: ver.version,
12027 MaxVersion: ver.version,
12028 Certificates: []Certificate{rsaCertificate},
12029 },
David Benjamina5022392017-07-10 17:40:39 -040012030 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012031 flags: []string{
12032 "-verify-peer",
12033 "-retain-only-sha256-client-cert-resume",
12034 "-expect-sha256-client-cert-resume",
12035 },
12036 resumeSession: true,
12037 expectResumeRejected: true,
12038 })
12039 }
12040}
12041
Adam Langleya4b91982016-12-12 12:05:53 -080012042func addECDSAKeyUsageTests() {
12043 p256 := elliptic.P256()
12044 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12045 if err != nil {
12046 panic(err)
12047 }
12048
12049 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12050 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12051 if err != nil {
12052 panic(err)
12053 }
12054
12055 template := x509.Certificate{
12056 SerialNumber: serialNumber,
12057 Subject: pkix.Name{
12058 Organization: []string{"Acme Co"},
12059 },
12060 NotBefore: time.Now(),
12061 NotAfter: time.Now(),
12062
12063 // An ECC certificate with only the keyAgreement key usgae may
12064 // be used with ECDH, but not ECDSA.
12065 KeyUsage: x509.KeyUsageKeyAgreement,
12066 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12067 BasicConstraintsValid: true,
12068 }
12069
12070 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12071 if err != nil {
12072 panic(err)
12073 }
12074
12075 cert := Certificate{
12076 Certificate: [][]byte{derBytes},
12077 PrivateKey: priv,
12078 }
12079
12080 for _, ver := range tlsVersions {
12081 if ver.version < VersionTLS12 {
12082 continue
12083 }
12084
12085 testCases = append(testCases, testCase{
12086 testType: clientTest,
12087 name: "ECDSAKeyUsage-" + ver.name,
12088 config: Config{
12089 MinVersion: ver.version,
12090 MaxVersion: ver.version,
12091 Certificates: []Certificate{cert},
12092 },
David Benjamina5022392017-07-10 17:40:39 -040012093 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012094 shouldFail: true,
12095 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12096 })
12097 }
12098}
12099
David Benjamin8c26d752017-03-26 15:13:51 -050012100func addExtraHandshakeTests() {
12101 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12102 // to ensure there is no transport I/O.
12103 testCases = append(testCases, testCase{
12104 testType: clientTest,
12105 name: "ExtraHandshake-Client-TLS12",
12106 config: Config{
12107 MinVersion: VersionTLS12,
12108 MaxVersion: VersionTLS12,
12109 },
12110 flags: []string{
12111 "-async",
12112 "-no-op-extra-handshake",
12113 },
12114 })
12115 testCases = append(testCases, testCase{
12116 testType: serverTest,
12117 name: "ExtraHandshake-Server-TLS12",
12118 config: Config{
12119 MinVersion: VersionTLS12,
12120 MaxVersion: VersionTLS12,
12121 },
12122 flags: []string{
12123 "-async",
12124 "-no-op-extra-handshake",
12125 },
12126 })
12127 testCases = append(testCases, testCase{
12128 testType: clientTest,
12129 name: "ExtraHandshake-Client-TLS13",
12130 config: Config{
12131 MinVersion: VersionTLS13,
12132 MaxVersion: VersionTLS13,
12133 },
12134 flags: []string{
12135 "-async",
12136 "-no-op-extra-handshake",
12137 },
12138 })
12139 testCases = append(testCases, testCase{
12140 testType: serverTest,
12141 name: "ExtraHandshake-Server-TLS13",
12142 config: Config{
12143 MinVersion: VersionTLS13,
12144 MaxVersion: VersionTLS13,
12145 },
12146 flags: []string{
12147 "-async",
12148 "-no-op-extra-handshake",
12149 },
12150 })
12151
12152 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12153 testCases = append(testCases, testCase{
12154 testType: serverTest,
12155 name: "ExtraHandshake-Server-EarlyData-TLS13",
12156 config: Config{
12157 MaxVersion: VersionTLS13,
12158 MinVersion: VersionTLS13,
12159 Bugs: ProtocolBugs{
12160 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12161 ExpectEarlyDataAccepted: true,
12162 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12163 },
12164 },
12165 messageCount: 2,
12166 resumeSession: true,
12167 flags: []string{
12168 "-async",
12169 "-enable-early-data",
12170 "-expect-accept-early-data",
12171 "-no-op-extra-handshake",
12172 },
12173 })
12174
12175 // An extra SSL_do_handshake drives the handshake to completion in False
12176 // Start. We test this by handshaking twice and asserting the False
12177 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12178 // how the test works.
12179 testCases = append(testCases, testCase{
12180 testType: clientTest,
12181 name: "ExtraHandshake-FalseStart",
12182 config: Config{
12183 MaxVersion: VersionTLS12,
12184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12185 NextProtos: []string{"foo"},
12186 Bugs: ProtocolBugs{
12187 ExpectFalseStart: true,
12188 AlertBeforeFalseStartTest: alertAccessDenied,
12189 },
12190 },
12191 flags: []string{
12192 "-handshake-twice",
12193 "-false-start",
12194 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012195 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012196 },
12197 shimWritesFirst: true,
12198 shouldFail: true,
12199 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12200 expectedLocalError: "tls: peer did not false start: EOF",
12201 })
12202}
12203
David Benjaminb853f312017-07-14 18:40:34 -040012204// Test that omitted and empty extensions blocks are tolerated.
12205func addOmitExtensionsTests() {
12206 for _, ver := range tlsVersions {
12207 if ver.version > VersionTLS12 {
12208 continue
12209 }
12210
12211 testCases = append(testCases, testCase{
12212 testType: serverTest,
12213 name: "OmitExtensions-ClientHello-" + ver.name,
12214 config: Config{
12215 MinVersion: ver.version,
12216 MaxVersion: ver.version,
12217 SessionTicketsDisabled: true,
12218 Bugs: ProtocolBugs{
12219 OmitExtensions: true,
12220 },
12221 },
12222 })
12223
12224 testCases = append(testCases, testCase{
12225 testType: serverTest,
12226 name: "EmptyExtensions-ClientHello-" + ver.name,
12227 config: Config{
12228 MinVersion: ver.version,
12229 MaxVersion: ver.version,
12230 SessionTicketsDisabled: true,
12231 Bugs: ProtocolBugs{
12232 EmptyExtensions: true,
12233 },
12234 },
12235 })
12236
12237 testCases = append(testCases, testCase{
12238 testType: clientTest,
12239 name: "OmitExtensions-ServerHello-" + ver.name,
12240 config: Config{
12241 MinVersion: ver.version,
12242 MaxVersion: ver.version,
12243 SessionTicketsDisabled: true,
12244 Bugs: ProtocolBugs{
12245 OmitExtensions: true,
12246 // Disable all ServerHello extensions so
12247 // OmitExtensions works.
12248 NoExtendedMasterSecret: true,
12249 NoRenegotiationInfo: true,
12250 },
12251 },
12252 })
12253
12254 testCases = append(testCases, testCase{
12255 testType: clientTest,
12256 name: "EmptyExtensions-ServerHello-" + ver.name,
12257 config: Config{
12258 MinVersion: ver.version,
12259 MaxVersion: ver.version,
12260 SessionTicketsDisabled: true,
12261 Bugs: ProtocolBugs{
12262 EmptyExtensions: true,
12263 // Disable all ServerHello extensions so
12264 // EmptyExtensions works.
12265 NoExtendedMasterSecret: true,
12266 NoRenegotiationInfo: true,
12267 },
12268 },
12269 })
12270 }
12271}
12272
Adam Langley7c803a62015-06-15 15:35:05 -070012273func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012274 defer wg.Done()
12275
12276 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012277 var err error
12278
David Benjaminba28dfc2016-11-15 17:47:21 +090012279 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012280 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12281 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012282 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012283 if err != nil {
12284 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12285 }
12286 break
12287 }
12288 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012289 } else if *repeatUntilFailure {
12290 for err == nil {
12291 statusChan <- statusMsg{test: test, started: true}
12292 err = runTest(test, shimPath, -1)
12293 }
12294 } else {
12295 statusChan <- statusMsg{test: test, started: true}
12296 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012297 }
Adam Langley95c29f32014-06-20 12:00:00 -070012298 statusChan <- statusMsg{test: test, err: err}
12299 }
12300}
12301
12302type statusMsg struct {
12303 test *testCase
12304 started bool
12305 err error
12306}
12307
David Benjamin5f237bc2015-02-11 17:14:15 -050012308func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012309 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012310
David Benjamin5f237bc2015-02-11 17:14:15 -050012311 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012312 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012313 if !*pipe {
12314 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012315 var erase string
12316 for i := 0; i < lineLen; i++ {
12317 erase += "\b \b"
12318 }
12319 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012320 }
12321
Adam Langley95c29f32014-06-20 12:00:00 -070012322 if msg.started {
12323 started++
12324 } else {
12325 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012326
12327 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012328 if msg.err == errUnimplemented {
12329 if *pipe {
12330 // Print each test instead of a status line.
12331 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12332 }
12333 unimplemented++
12334 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12335 } else {
12336 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12337 failed++
12338 testOutput.addResult(msg.test.name, "FAIL")
12339 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012340 } else {
12341 if *pipe {
12342 // Print each test instead of a status line.
12343 fmt.Printf("PASSED (%s)\n", msg.test.name)
12344 }
12345 testOutput.addResult(msg.test.name, "PASS")
12346 }
Adam Langley95c29f32014-06-20 12:00:00 -070012347 }
12348
David Benjamin5f237bc2015-02-11 17:14:15 -050012349 if !*pipe {
12350 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012351 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012352 lineLen = len(line)
12353 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012354 }
Adam Langley95c29f32014-06-20 12:00:00 -070012355 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012356
12357 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012358}
12359
12360func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012361 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012362 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012363 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012364
Adam Langley7c803a62015-06-15 15:35:05 -070012365 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012366 addCipherSuiteTests()
12367 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012368 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012369 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012370 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012371 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012372 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012373 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012374 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012375 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012376 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012377 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012378 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012379 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012380 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012381 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012382 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012383 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012384 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012385 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012386 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012387 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012388 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012389 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012390 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012391 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012392 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012393 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012394 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012395 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012396 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012397 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012398 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012399 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012400 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012401
12402 var wg sync.WaitGroup
12403
Adam Langley7c803a62015-06-15 15:35:05 -070012404 statusChan := make(chan statusMsg, *numWorkers)
12405 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012406 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012407
EKRf71d7ed2016-08-06 13:25:12 -070012408 if len(*shimConfigFile) != 0 {
12409 encoded, err := ioutil.ReadFile(*shimConfigFile)
12410 if err != nil {
12411 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12412 os.Exit(1)
12413 }
12414
12415 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12416 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12417 os.Exit(1)
12418 }
12419 }
12420
David Benjamin025b3d32014-07-01 19:53:04 -040012421 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012422
Adam Langley7c803a62015-06-15 15:35:05 -070012423 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012424 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012425 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012426 }
12427
David Benjamin270f0a72016-03-17 14:41:36 -040012428 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012429 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012430 matched := true
12431 if len(*testToRun) != 0 {
12432 var err error
12433 matched, err = filepath.Match(*testToRun, testCases[i].name)
12434 if err != nil {
12435 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12436 os.Exit(1)
12437 }
12438 }
12439
EKRf71d7ed2016-08-06 13:25:12 -070012440 if !*includeDisabled {
12441 for pattern := range shimConfig.DisabledTests {
12442 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12443 if err != nil {
12444 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12445 os.Exit(1)
12446 }
12447
12448 if isDisabled {
12449 matched = false
12450 break
12451 }
12452 }
12453 }
12454
David Benjamin17e12922016-07-28 18:04:43 -040012455 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012456 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012457 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012458
12459 // Only run one test if repeating until failure.
12460 if *repeatUntilFailure {
12461 break
12462 }
Adam Langley95c29f32014-06-20 12:00:00 -070012463 }
12464 }
David Benjamin17e12922016-07-28 18:04:43 -040012465
David Benjamin270f0a72016-03-17 14:41:36 -040012466 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012467 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012468 os.Exit(1)
12469 }
Adam Langley95c29f32014-06-20 12:00:00 -070012470
12471 close(testChan)
12472 wg.Wait()
12473 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012474 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012475
12476 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012477
12478 if *jsonOutput != "" {
12479 if err := testOutput.writeTo(*jsonOutput); err != nil {
12480 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12481 }
12482 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012483
EKR842ae6c2016-07-27 09:22:05 +020012484 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12485 os.Exit(1)
12486 }
12487
12488 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012489 os.Exit(1)
12490 }
Adam Langley95c29f32014-06-20 12:00:00 -070012491}