blob: 9898101f73fa08823f7a288843db55bb2d4f14c0 [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",
David Benjamin78b8b992017-08-01 18:38:41 -04001451 // This test involves an optional message. Test the message callback
1452 // trace to ensure we do not miss or double-report any.
1453 "-expect-msg-callback",
1454 `write hs 1
1455read hs 2
1456read hs 11
1457read hs 12
1458read hs 14
1459write hs 16
1460write ccs
1461write hs 20
1462read hs 4
1463read ccs
1464read hs 20
1465read alert 1 0
1466`,
1467 },
1468 },
1469 {
1470 protocol: dtls,
1471 name: "SkipCertificateStatus-DTLS",
1472 config: Config{
1473 MaxVersion: VersionTLS12,
1474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1475 Bugs: ProtocolBugs{
1476 SkipCertificateStatus: true,
1477 },
1478 },
1479 flags: []string{
1480 "-enable-ocsp-stapling",
1481 // This test involves an optional message. Test the message callback
1482 // trace to ensure we do not miss or double-report any.
1483 "-expect-msg-callback",
1484 `write hs 1
1485read hs 3
1486write hs 1
1487read hs 2
1488read hs 11
1489read hs 12
1490read hs 14
1491write hs 16
1492write ccs
1493write hs 20
1494read hs 4
1495read ccs
1496read hs 20
1497read alert 1 0
1498`,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 },
1500 },
1501 {
1502 name: "SkipServerKeyExchange",
1503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001504 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1506 Bugs: ProtocolBugs{
1507 SkipServerKeyExchange: true,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_MESSAGE:",
1512 },
1513 {
Adam Langley7c803a62015-06-15 15:35:05 -07001514 testType: serverTest,
1515 name: "Alert",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 SendSpuriousAlert: alertRecordOverflow,
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1523 },
1524 {
1525 protocol: dtls,
1526 testType: serverTest,
1527 name: "Alert-DTLS",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 SendSpuriousAlert: alertRecordOverflow,
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1535 },
1536 {
1537 testType: serverTest,
1538 name: "FragmentAlert",
1539 config: Config{
1540 Bugs: ProtocolBugs{
1541 FragmentAlert: true,
1542 SendSpuriousAlert: alertRecordOverflow,
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":BAD_ALERT:",
1547 },
1548 {
1549 protocol: dtls,
1550 testType: serverTest,
1551 name: "FragmentAlert-DTLS",
1552 config: Config{
1553 Bugs: ProtocolBugs{
1554 FragmentAlert: true,
1555 SendSpuriousAlert: alertRecordOverflow,
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":BAD_ALERT:",
1560 },
1561 {
1562 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001563 name: "DoubleAlert",
1564 config: Config{
1565 Bugs: ProtocolBugs{
1566 DoubleAlert: true,
1567 SendSpuriousAlert: alertRecordOverflow,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":BAD_ALERT:",
1572 },
1573 {
1574 protocol: dtls,
1575 testType: serverTest,
1576 name: "DoubleAlert-DTLS",
1577 config: Config{
1578 Bugs: ProtocolBugs{
1579 DoubleAlert: true,
1580 SendSpuriousAlert: alertRecordOverflow,
1581 },
1582 },
1583 shouldFail: true,
1584 expectedError: ":BAD_ALERT:",
1585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 name: "SkipNewSessionTicket",
1588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001589 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001590 Bugs: ProtocolBugs{
1591 SkipNewSessionTicket: true,
1592 },
1593 },
1594 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001595 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001596 },
1597 {
1598 testType: serverTest,
1599 name: "FallbackSCSV",
1600 config: Config{
1601 MaxVersion: VersionTLS11,
1602 Bugs: ProtocolBugs{
1603 SendFallbackSCSV: true,
1604 },
1605 },
David Benjamin56cadc32016-12-16 19:54:11 -05001606 shouldFail: true,
1607 expectedError: ":INAPPROPRIATE_FALLBACK:",
1608 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001609 },
1610 {
1611 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001612 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001613 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001614 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001615 Bugs: ProtocolBugs{
1616 SendFallbackSCSV: true,
1617 },
1618 },
1619 },
1620 {
1621 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001622 name: "FallbackSCSV-VersionMatch-TLS12",
1623 config: Config{
1624 MaxVersion: VersionTLS12,
1625 Bugs: ProtocolBugs{
1626 SendFallbackSCSV: true,
1627 },
1628 },
1629 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1630 },
1631 {
1632 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 name: "FragmentedClientVersion",
1634 config: Config{
1635 Bugs: ProtocolBugs{
1636 MaxHandshakeRecordLength: 1,
1637 FragmentClientVersion: true,
1638 },
1639 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001640 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001641 },
1642 {
Adam Langley7c803a62015-06-15 15:35:05 -07001643 testType: serverTest,
1644 name: "HttpGET",
1645 sendPrefix: "GET / HTTP/1.0\n",
1646 shouldFail: true,
1647 expectedError: ":HTTP_REQUEST:",
1648 },
1649 {
1650 testType: serverTest,
1651 name: "HttpPOST",
1652 sendPrefix: "POST / HTTP/1.0\n",
1653 shouldFail: true,
1654 expectedError: ":HTTP_REQUEST:",
1655 },
1656 {
1657 testType: serverTest,
1658 name: "HttpHEAD",
1659 sendPrefix: "HEAD / HTTP/1.0\n",
1660 shouldFail: true,
1661 expectedError: ":HTTP_REQUEST:",
1662 },
1663 {
1664 testType: serverTest,
1665 name: "HttpPUT",
1666 sendPrefix: "PUT / HTTP/1.0\n",
1667 shouldFail: true,
1668 expectedError: ":HTTP_REQUEST:",
1669 },
1670 {
1671 testType: serverTest,
1672 name: "HttpCONNECT",
1673 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1674 shouldFail: true,
1675 expectedError: ":HTTPS_PROXY_REQUEST:",
1676 },
1677 {
1678 testType: serverTest,
1679 name: "Garbage",
1680 sendPrefix: "blah",
1681 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001682 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001683 },
1684 {
Adam Langley7c803a62015-06-15 15:35:05 -07001685 name: "RSAEphemeralKey",
1686 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001687 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001688 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1689 Bugs: ProtocolBugs{
1690 RSAEphemeralKey: true,
1691 },
1692 },
1693 shouldFail: true,
1694 expectedError: ":UNEXPECTED_MESSAGE:",
1695 },
1696 {
1697 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001698 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001699 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001700 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
1703 protocol: dtls,
1704 name: "DisableEverything-DTLS",
1705 flags: []string{"-no-tls12", "-no-tls1"},
1706 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001707 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001708 },
1709 {
Adam Langley7c803a62015-06-15 15:35:05 -07001710 protocol: dtls,
1711 testType: serverTest,
1712 name: "MTU",
1713 config: Config{
1714 Bugs: ProtocolBugs{
1715 MaxPacketLength: 256,
1716 },
1717 },
1718 flags: []string{"-mtu", "256"},
1719 },
1720 {
1721 protocol: dtls,
1722 testType: serverTest,
1723 name: "MTUExceeded",
1724 config: Config{
1725 Bugs: ProtocolBugs{
1726 MaxPacketLength: 255,
1727 },
1728 },
1729 flags: []string{"-mtu", "256"},
1730 shouldFail: true,
1731 expectedLocalError: "dtls: exceeded maximum packet length",
1732 },
1733 {
Adam Langley7c803a62015-06-15 15:35:05 -07001734 name: "EmptyCertificateList",
1735 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001736 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001737 Bugs: ProtocolBugs{
1738 EmptyCertificateList: true,
1739 },
1740 },
1741 shouldFail: true,
1742 expectedError: ":DECODE_ERROR:",
1743 },
1744 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001745 name: "EmptyCertificateList-TLS13",
1746 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001747 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001748 Bugs: ProtocolBugs{
1749 EmptyCertificateList: true,
1750 },
1751 },
1752 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001753 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001754 },
1755 {
Adam Langley7c803a62015-06-15 15:35:05 -07001756 name: "TLSFatalBadPackets",
1757 damageFirstWrite: true,
1758 shouldFail: true,
1759 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1760 },
1761 {
1762 protocol: dtls,
1763 name: "DTLSIgnoreBadPackets",
1764 damageFirstWrite: true,
1765 },
1766 {
1767 protocol: dtls,
1768 name: "DTLSIgnoreBadPackets-Async",
1769 damageFirstWrite: true,
1770 flags: []string{"-async"},
1771 },
1772 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001773 name: "AppDataBeforeHandshake",
1774 config: Config{
1775 Bugs: ProtocolBugs{
1776 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1777 },
1778 },
1779 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001780 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001781 },
1782 {
1783 name: "AppDataBeforeHandshake-Empty",
1784 config: Config{
1785 Bugs: ProtocolBugs{
1786 AppDataBeforeHandshake: []byte{},
1787 },
1788 },
1789 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001790 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001791 },
1792 {
1793 protocol: dtls,
1794 name: "AppDataBeforeHandshake-DTLS",
1795 config: Config{
1796 Bugs: ProtocolBugs{
1797 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1798 },
1799 },
1800 shouldFail: true,
1801 expectedError: ":UNEXPECTED_RECORD:",
1802 },
1803 {
1804 protocol: dtls,
1805 name: "AppDataBeforeHandshake-DTLS-Empty",
1806 config: Config{
1807 Bugs: ProtocolBugs{
1808 AppDataBeforeHandshake: []byte{},
1809 },
1810 },
1811 shouldFail: true,
1812 expectedError: ":UNEXPECTED_RECORD:",
1813 },
1814 {
Adam Langley7c803a62015-06-15 15:35:05 -07001815 name: "AppDataAfterChangeCipherSpec",
1816 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001817 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001818 Bugs: ProtocolBugs{
1819 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1820 },
1821 },
1822 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001823 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001824 },
1825 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001826 name: "AppDataAfterChangeCipherSpec-Empty",
1827 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001828 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001829 Bugs: ProtocolBugs{
1830 AppDataAfterChangeCipherSpec: []byte{},
1831 },
1832 },
1833 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001834 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001835 },
1836 {
Adam Langley7c803a62015-06-15 15:35:05 -07001837 protocol: dtls,
1838 name: "AppDataAfterChangeCipherSpec-DTLS",
1839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001840 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001841 Bugs: ProtocolBugs{
1842 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1843 },
1844 },
1845 // BoringSSL's DTLS implementation will drop the out-of-order
1846 // application data.
1847 },
1848 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001849 protocol: dtls,
1850 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001852 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001853 Bugs: ProtocolBugs{
1854 AppDataAfterChangeCipherSpec: []byte{},
1855 },
1856 },
1857 // BoringSSL's DTLS implementation will drop the out-of-order
1858 // application data.
1859 },
1860 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 name: "AlertAfterChangeCipherSpec",
1862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001863 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001864 Bugs: ProtocolBugs{
1865 AlertAfterChangeCipherSpec: alertRecordOverflow,
1866 },
1867 },
1868 shouldFail: true,
1869 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1870 },
1871 {
1872 protocol: dtls,
1873 name: "AlertAfterChangeCipherSpec-DTLS",
1874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001875 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001876 Bugs: ProtocolBugs{
1877 AlertAfterChangeCipherSpec: alertRecordOverflow,
1878 },
1879 },
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1882 },
1883 {
1884 protocol: dtls,
1885 name: "ReorderHandshakeFragments-Small-DTLS",
1886 config: Config{
1887 Bugs: ProtocolBugs{
1888 ReorderHandshakeFragments: true,
1889 // Small enough that every handshake message is
1890 // fragmented.
1891 MaxHandshakeRecordLength: 2,
1892 },
1893 },
1894 },
1895 {
1896 protocol: dtls,
1897 name: "ReorderHandshakeFragments-Large-DTLS",
1898 config: Config{
1899 Bugs: ProtocolBugs{
1900 ReorderHandshakeFragments: true,
1901 // Large enough that no handshake message is
1902 // fragmented.
1903 MaxHandshakeRecordLength: 2048,
1904 },
1905 },
1906 },
1907 {
1908 protocol: dtls,
1909 name: "MixCompleteMessageWithFragments-DTLS",
1910 config: Config{
1911 Bugs: ProtocolBugs{
1912 ReorderHandshakeFragments: true,
1913 MixCompleteMessageWithFragments: true,
1914 MaxHandshakeRecordLength: 2,
1915 },
1916 },
1917 },
1918 {
1919 name: "SendInvalidRecordType",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 SendInvalidRecordType: true,
1923 },
1924 },
1925 shouldFail: true,
1926 expectedError: ":UNEXPECTED_RECORD:",
1927 },
1928 {
1929 protocol: dtls,
1930 name: "SendInvalidRecordType-DTLS",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SendInvalidRecordType: true,
1934 },
1935 },
1936 shouldFail: true,
1937 expectedError: ":UNEXPECTED_RECORD:",
1938 },
1939 {
1940 name: "FalseStart-SkipServerSecondLeg",
1941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001942 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1944 NextProtos: []string{"foo"},
1945 Bugs: ProtocolBugs{
1946 SkipNewSessionTicket: true,
1947 SkipChangeCipherSpec: true,
1948 SkipFinished: true,
1949 ExpectFalseStart: true,
1950 },
1951 },
1952 flags: []string{
1953 "-false-start",
1954 "-handshake-never-done",
1955 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001956 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001957 },
1958 shimWritesFirst: true,
1959 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001960 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001961 },
1962 {
1963 name: "FalseStart-SkipServerSecondLeg-Implicit",
1964 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001965 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1967 NextProtos: []string{"foo"},
1968 Bugs: ProtocolBugs{
1969 SkipNewSessionTicket: true,
1970 SkipChangeCipherSpec: true,
1971 SkipFinished: true,
1972 },
1973 },
1974 flags: []string{
1975 "-implicit-handshake",
1976 "-false-start",
1977 "-handshake-never-done",
1978 "-advertise-alpn", "\x03foo",
1979 },
1980 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001981 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001982 },
1983 {
1984 testType: serverTest,
1985 name: "FailEarlyCallback",
1986 flags: []string{"-fail-early-callback"},
1987 shouldFail: true,
1988 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001989 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001990 },
1991 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001992 name: "FailCertCallback-Client-TLS12",
1993 config: Config{
1994 MaxVersion: VersionTLS12,
1995 ClientAuth: RequestClientCert,
1996 },
1997 flags: []string{"-fail-cert-callback"},
1998 shouldFail: true,
1999 expectedError: ":CERT_CB_ERROR:",
2000 expectedLocalError: "remote error: internal error",
2001 },
2002 {
2003 testType: serverTest,
2004 name: "FailCertCallback-Server-TLS12",
2005 config: Config{
2006 MaxVersion: VersionTLS12,
2007 },
2008 flags: []string{"-fail-cert-callback"},
2009 shouldFail: true,
2010 expectedError: ":CERT_CB_ERROR:",
2011 expectedLocalError: "remote error: internal error",
2012 },
2013 {
2014 name: "FailCertCallback-Client-TLS13",
2015 config: Config{
2016 MaxVersion: VersionTLS13,
2017 ClientAuth: RequestClientCert,
2018 },
2019 flags: []string{"-fail-cert-callback"},
2020 shouldFail: true,
2021 expectedError: ":CERT_CB_ERROR:",
2022 expectedLocalError: "remote error: internal error",
2023 },
2024 {
2025 testType: serverTest,
2026 name: "FailCertCallback-Server-TLS13",
2027 config: Config{
2028 MaxVersion: VersionTLS13,
2029 },
2030 flags: []string{"-fail-cert-callback"},
2031 shouldFail: true,
2032 expectedError: ":CERT_CB_ERROR:",
2033 expectedLocalError: "remote error: internal error",
2034 },
2035 {
Adam Langley7c803a62015-06-15 15:35:05 -07002036 protocol: dtls,
2037 name: "FragmentMessageTypeMismatch-DTLS",
2038 config: Config{
2039 Bugs: ProtocolBugs{
2040 MaxHandshakeRecordLength: 2,
2041 FragmentMessageTypeMismatch: true,
2042 },
2043 },
2044 shouldFail: true,
2045 expectedError: ":FRAGMENT_MISMATCH:",
2046 },
2047 {
2048 protocol: dtls,
2049 name: "FragmentMessageLengthMismatch-DTLS",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 MaxHandshakeRecordLength: 2,
2053 FragmentMessageLengthMismatch: true,
2054 },
2055 },
2056 shouldFail: true,
2057 expectedError: ":FRAGMENT_MISMATCH:",
2058 },
2059 {
2060 protocol: dtls,
2061 name: "SplitFragments-Header-DTLS",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SplitFragments: 2,
2065 },
2066 },
2067 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002068 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002069 },
2070 {
2071 protocol: dtls,
2072 name: "SplitFragments-Boundary-DTLS",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SplitFragments: dtlsRecordHeaderLen,
2076 },
2077 },
2078 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002079 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002080 },
2081 {
2082 protocol: dtls,
2083 name: "SplitFragments-Body-DTLS",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SplitFragments: dtlsRecordHeaderLen + 1,
2087 },
2088 },
2089 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002090 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002091 },
2092 {
2093 protocol: dtls,
2094 name: "SendEmptyFragments-DTLS",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 SendEmptyFragments: true,
2098 },
2099 },
2100 },
2101 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002102 name: "BadFinished-Client",
2103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002104 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002105 Bugs: ProtocolBugs{
2106 BadFinished: true,
2107 },
2108 },
2109 shouldFail: true,
2110 expectedError: ":DIGEST_CHECK_FAILED:",
2111 },
2112 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002113 name: "BadFinished-Client-TLS13",
2114 config: Config{
2115 MaxVersion: VersionTLS13,
2116 Bugs: ProtocolBugs{
2117 BadFinished: true,
2118 },
2119 },
2120 shouldFail: true,
2121 expectedError: ":DIGEST_CHECK_FAILED:",
2122 },
2123 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002124 testType: serverTest,
2125 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002127 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002128 Bugs: ProtocolBugs{
2129 BadFinished: true,
2130 },
2131 },
2132 shouldFail: true,
2133 expectedError: ":DIGEST_CHECK_FAILED:",
2134 },
2135 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002136 testType: serverTest,
2137 name: "BadFinished-Server-TLS13",
2138 config: Config{
2139 MaxVersion: VersionTLS13,
2140 Bugs: ProtocolBugs{
2141 BadFinished: true,
2142 },
2143 },
2144 shouldFail: true,
2145 expectedError: ":DIGEST_CHECK_FAILED:",
2146 },
2147 {
Adam Langley7c803a62015-06-15 15:35:05 -07002148 name: "FalseStart-BadFinished",
2149 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002150 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002151 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2152 NextProtos: []string{"foo"},
2153 Bugs: ProtocolBugs{
2154 BadFinished: true,
2155 ExpectFalseStart: true,
2156 },
2157 },
2158 flags: []string{
2159 "-false-start",
2160 "-handshake-never-done",
2161 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002162 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002163 },
2164 shimWritesFirst: true,
2165 shouldFail: true,
2166 expectedError: ":DIGEST_CHECK_FAILED:",
2167 },
2168 {
2169 name: "NoFalseStart-NoALPN",
2170 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002171 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002172 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2173 Bugs: ProtocolBugs{
2174 ExpectFalseStart: true,
2175 AlertBeforeFalseStartTest: alertAccessDenied,
2176 },
2177 },
2178 flags: []string{
2179 "-false-start",
2180 },
2181 shimWritesFirst: true,
2182 shouldFail: true,
2183 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2184 expectedLocalError: "tls: peer did not false start: EOF",
2185 },
2186 {
2187 name: "NoFalseStart-NoAEAD",
2188 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2191 NextProtos: []string{"foo"},
2192 Bugs: ProtocolBugs{
2193 ExpectFalseStart: true,
2194 AlertBeforeFalseStartTest: alertAccessDenied,
2195 },
2196 },
2197 flags: []string{
2198 "-false-start",
2199 "-advertise-alpn", "\x03foo",
2200 },
2201 shimWritesFirst: true,
2202 shouldFail: true,
2203 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2204 expectedLocalError: "tls: peer did not false start: EOF",
2205 },
2206 {
2207 name: "NoFalseStart-RSA",
2208 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002209 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002210 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2211 NextProtos: []string{"foo"},
2212 Bugs: ProtocolBugs{
2213 ExpectFalseStart: true,
2214 AlertBeforeFalseStartTest: alertAccessDenied,
2215 },
2216 },
2217 flags: []string{
2218 "-false-start",
2219 "-advertise-alpn", "\x03foo",
2220 },
2221 shimWritesFirst: true,
2222 shouldFail: true,
2223 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2224 expectedLocalError: "tls: peer did not false start: EOF",
2225 },
2226 {
Adam Langley7c803a62015-06-15 15:35:05 -07002227 protocol: dtls,
2228 name: "SendSplitAlert-Sync",
2229 config: Config{
2230 Bugs: ProtocolBugs{
2231 SendSplitAlert: true,
2232 },
2233 },
2234 },
2235 {
2236 protocol: dtls,
2237 name: "SendSplitAlert-Async",
2238 config: Config{
2239 Bugs: ProtocolBugs{
2240 SendSplitAlert: true,
2241 },
2242 },
2243 flags: []string{"-async"},
2244 },
2245 {
2246 protocol: dtls,
2247 name: "PackDTLSHandshake",
2248 config: Config{
2249 Bugs: ProtocolBugs{
2250 MaxHandshakeRecordLength: 2,
2251 PackHandshakeFragments: 20,
2252 PackHandshakeRecords: 200,
2253 },
2254 },
2255 },
2256 {
Adam Langley7c803a62015-06-15 15:35:05 -07002257 name: "SendEmptyRecords-Pass",
2258 sendEmptyRecords: 32,
2259 },
2260 {
2261 name: "SendEmptyRecords",
2262 sendEmptyRecords: 33,
2263 shouldFail: true,
2264 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2265 },
2266 {
2267 name: "SendEmptyRecords-Async",
2268 sendEmptyRecords: 33,
2269 flags: []string{"-async"},
2270 shouldFail: true,
2271 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2272 },
2273 {
David Benjamine8e84b92016-08-03 15:39:47 -04002274 name: "SendWarningAlerts-Pass",
2275 config: Config{
2276 MaxVersion: VersionTLS12,
2277 },
Adam Langley7c803a62015-06-15 15:35:05 -07002278 sendWarningAlerts: 4,
2279 },
2280 {
David Benjamine8e84b92016-08-03 15:39:47 -04002281 protocol: dtls,
2282 name: "SendWarningAlerts-DTLS-Pass",
2283 config: Config{
2284 MaxVersion: VersionTLS12,
2285 },
Adam Langley7c803a62015-06-15 15:35:05 -07002286 sendWarningAlerts: 4,
2287 },
2288 {
David Benjamine8e84b92016-08-03 15:39:47 -04002289 name: "SendWarningAlerts-TLS13",
2290 config: Config{
2291 MaxVersion: VersionTLS13,
2292 },
2293 sendWarningAlerts: 4,
2294 shouldFail: true,
2295 expectedError: ":BAD_ALERT:",
2296 expectedLocalError: "remote error: error decoding message",
2297 },
2298 {
2299 name: "SendWarningAlerts",
2300 config: Config{
2301 MaxVersion: VersionTLS12,
2302 },
Adam Langley7c803a62015-06-15 15:35:05 -07002303 sendWarningAlerts: 5,
2304 shouldFail: true,
2305 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2306 },
2307 {
David Benjamine8e84b92016-08-03 15:39:47 -04002308 name: "SendWarningAlerts-Async",
2309 config: Config{
2310 MaxVersion: VersionTLS12,
2311 },
Adam Langley7c803a62015-06-15 15:35:05 -07002312 sendWarningAlerts: 5,
2313 flags: []string{"-async"},
2314 shouldFail: true,
2315 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2316 },
David Benjaminba4594a2015-06-18 18:36:15 -04002317 {
David Benjamin24e58862017-06-14 18:45:29 -04002318 name: "SendBogusAlertType",
2319 sendBogusAlertType: true,
2320 shouldFail: true,
2321 expectedError: ":UNKNOWN_ALERT_TYPE:",
2322 expectedLocalError: "remote error: illegal parameter",
2323 },
2324 {
2325 protocol: dtls,
2326 name: "SendBogusAlertType-DTLS",
2327 sendBogusAlertType: true,
2328 shouldFail: true,
2329 expectedError: ":UNKNOWN_ALERT_TYPE:",
2330 expectedLocalError: "remote error: illegal parameter",
2331 },
2332 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002333 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002334 config: Config{
2335 MaxVersion: VersionTLS13,
2336 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002337 sendKeyUpdates: 33,
2338 keyUpdateRequest: keyUpdateNotRequested,
2339 shouldFail: true,
2340 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002341 },
2342 {
David Benjaminba4594a2015-06-18 18:36:15 -04002343 name: "EmptySessionID",
2344 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002345 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002346 SessionTicketsDisabled: true,
2347 },
2348 noSessionCache: true,
2349 flags: []string{"-expect-no-session"},
2350 },
David Benjamin30789da2015-08-29 22:56:45 -04002351 {
2352 name: "Unclean-Shutdown",
2353 config: Config{
2354 Bugs: ProtocolBugs{
2355 NoCloseNotify: true,
2356 ExpectCloseNotify: true,
2357 },
2358 },
2359 shimShutsDown: true,
2360 flags: []string{"-check-close-notify"},
2361 shouldFail: true,
2362 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2363 },
2364 {
2365 name: "Unclean-Shutdown-Ignored",
2366 config: Config{
2367 Bugs: ProtocolBugs{
2368 NoCloseNotify: true,
2369 },
2370 },
2371 shimShutsDown: true,
2372 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002373 {
David Benjaminfa214e42016-05-10 17:03:10 -04002374 name: "Unclean-Shutdown-Alert",
2375 config: Config{
2376 Bugs: ProtocolBugs{
2377 SendAlertOnShutdown: alertDecompressionFailure,
2378 ExpectCloseNotify: true,
2379 },
2380 },
2381 shimShutsDown: true,
2382 flags: []string{"-check-close-notify"},
2383 shouldFail: true,
2384 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2385 },
2386 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002387 name: "LargePlaintext",
2388 config: Config{
2389 Bugs: ProtocolBugs{
2390 SendLargeRecords: true,
2391 },
2392 },
2393 messageLen: maxPlaintext + 1,
2394 shouldFail: true,
2395 expectedError: ":DATA_LENGTH_TOO_LONG:",
2396 },
2397 {
2398 protocol: dtls,
2399 name: "LargePlaintext-DTLS",
2400 config: Config{
2401 Bugs: ProtocolBugs{
2402 SendLargeRecords: true,
2403 },
2404 },
2405 messageLen: maxPlaintext + 1,
2406 shouldFail: true,
2407 expectedError: ":DATA_LENGTH_TOO_LONG:",
2408 },
2409 {
2410 name: "LargeCiphertext",
2411 config: Config{
2412 Bugs: ProtocolBugs{
2413 SendLargeRecords: true,
2414 },
2415 },
2416 messageLen: maxPlaintext * 2,
2417 shouldFail: true,
2418 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2419 },
2420 {
2421 protocol: dtls,
2422 name: "LargeCiphertext-DTLS",
2423 config: Config{
2424 Bugs: ProtocolBugs{
2425 SendLargeRecords: true,
2426 },
2427 },
2428 messageLen: maxPlaintext * 2,
2429 // Unlike the other four cases, DTLS drops records which
2430 // are invalid before authentication, so the connection
2431 // does not fail.
2432 expectMessageDropped: true,
2433 },
David Benjamindd6fed92015-10-23 17:41:12 -04002434 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002435 name: "BadHelloRequest-1",
2436 renegotiate: 1,
2437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002438 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002439 Bugs: ProtocolBugs{
2440 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2441 },
2442 },
2443 flags: []string{
2444 "-renegotiate-freely",
2445 "-expect-total-renegotiations", "1",
2446 },
2447 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002448 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002449 },
2450 {
2451 name: "BadHelloRequest-2",
2452 renegotiate: 1,
2453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002454 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002455 Bugs: ProtocolBugs{
2456 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2457 },
2458 },
2459 flags: []string{
2460 "-renegotiate-freely",
2461 "-expect-total-renegotiations", "1",
2462 },
2463 shouldFail: true,
2464 expectedError: ":BAD_HELLO_REQUEST:",
2465 },
David Benjaminef1b0092015-11-21 14:05:44 -05002466 {
2467 testType: serverTest,
2468 name: "SupportTicketsWithSessionID",
2469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002470 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002471 SessionTicketsDisabled: true,
2472 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002473 resumeConfig: &Config{
2474 MaxVersion: VersionTLS12,
2475 },
David Benjaminef1b0092015-11-21 14:05:44 -05002476 resumeSession: true,
2477 },
David Benjamin02edcd02016-07-27 17:40:37 -04002478 {
2479 protocol: dtls,
2480 name: "DTLS-SendExtraFinished",
2481 config: Config{
2482 Bugs: ProtocolBugs{
2483 SendExtraFinished: true,
2484 },
2485 },
2486 shouldFail: true,
2487 expectedError: ":UNEXPECTED_RECORD:",
2488 },
2489 {
2490 protocol: dtls,
2491 name: "DTLS-SendExtraFinished-Reordered",
2492 config: Config{
2493 Bugs: ProtocolBugs{
2494 MaxHandshakeRecordLength: 2,
2495 ReorderHandshakeFragments: true,
2496 SendExtraFinished: true,
2497 },
2498 },
2499 shouldFail: true,
2500 expectedError: ":UNEXPECTED_RECORD:",
2501 },
David Benjamine97fb482016-07-29 09:23:07 -04002502 {
2503 testType: serverTest,
2504 name: "V2ClientHello-EmptyRecordPrefix",
2505 config: Config{
2506 // Choose a cipher suite that does not involve
2507 // elliptic curves, so no extensions are
2508 // involved.
2509 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002510 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002511 Bugs: ProtocolBugs{
2512 SendV2ClientHello: true,
2513 },
2514 },
2515 sendPrefix: string([]byte{
2516 byte(recordTypeHandshake),
2517 3, 1, // version
2518 0, 0, // length
2519 }),
2520 // A no-op empty record may not be sent before V2ClientHello.
2521 shouldFail: true,
2522 expectedError: ":WRONG_VERSION_NUMBER:",
2523 },
2524 {
2525 testType: serverTest,
2526 name: "V2ClientHello-WarningAlertPrefix",
2527 config: Config{
2528 // Choose a cipher suite that does not involve
2529 // elliptic curves, so no extensions are
2530 // involved.
2531 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002532 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002533 Bugs: ProtocolBugs{
2534 SendV2ClientHello: true,
2535 },
2536 },
2537 sendPrefix: string([]byte{
2538 byte(recordTypeAlert),
2539 3, 1, // version
2540 0, 2, // length
2541 alertLevelWarning, byte(alertDecompressionFailure),
2542 }),
2543 // A no-op warning alert may not be sent before V2ClientHello.
2544 shouldFail: true,
2545 expectedError: ":WRONG_VERSION_NUMBER:",
2546 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002547 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002548 name: "KeyUpdate-Client",
2549 config: Config{
2550 MaxVersion: VersionTLS13,
2551 },
2552 sendKeyUpdates: 1,
2553 keyUpdateRequest: keyUpdateNotRequested,
2554 },
2555 {
2556 testType: serverTest,
2557 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002558 config: Config{
2559 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002560 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002561 sendKeyUpdates: 1,
2562 keyUpdateRequest: keyUpdateNotRequested,
2563 },
2564 {
2565 name: "KeyUpdate-InvalidRequestMode",
2566 config: Config{
2567 MaxVersion: VersionTLS13,
2568 },
2569 sendKeyUpdates: 1,
2570 keyUpdateRequest: 42,
2571 shouldFail: true,
2572 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002573 },
David Benjaminabe94e32016-09-04 14:18:58 -04002574 {
David Benjaminbbba9392017-04-06 12:54:12 -04002575 // Test that KeyUpdates are acknowledged properly.
2576 name: "KeyUpdate-RequestACK",
2577 config: Config{
2578 MaxVersion: VersionTLS13,
2579 Bugs: ProtocolBugs{
2580 RejectUnsolicitedKeyUpdate: true,
2581 },
2582 },
2583 // Test the shim receiving many KeyUpdates in a row.
2584 sendKeyUpdates: 5,
2585 messageCount: 5,
2586 keyUpdateRequest: keyUpdateRequested,
2587 },
2588 {
2589 // Test that KeyUpdates are acknowledged properly if the
2590 // peer's KeyUpdate is discovered while a write is
2591 // pending.
2592 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2593 config: Config{
2594 MaxVersion: VersionTLS13,
2595 Bugs: ProtocolBugs{
2596 RejectUnsolicitedKeyUpdate: true,
2597 },
2598 },
2599 // Test the shim receiving many KeyUpdates in a row.
2600 sendKeyUpdates: 5,
2601 messageCount: 5,
2602 keyUpdateRequest: keyUpdateRequested,
2603 readWithUnfinishedWrite: true,
2604 flags: []string{"-async"},
2605 },
2606 {
David Benjaminabe94e32016-09-04 14:18:58 -04002607 name: "SendSNIWarningAlert",
2608 config: Config{
2609 MaxVersion: VersionTLS12,
2610 Bugs: ProtocolBugs{
2611 SendSNIWarningAlert: true,
2612 },
2613 },
2614 },
David Benjaminc241d792016-09-09 10:34:20 -04002615 {
2616 testType: serverTest,
2617 name: "ExtraCompressionMethods-TLS12",
2618 config: Config{
2619 MaxVersion: VersionTLS12,
2620 Bugs: ProtocolBugs{
2621 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2622 },
2623 },
2624 },
2625 {
2626 testType: serverTest,
2627 name: "ExtraCompressionMethods-TLS13",
2628 config: Config{
2629 MaxVersion: VersionTLS13,
2630 Bugs: ProtocolBugs{
2631 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2632 },
2633 },
2634 shouldFail: true,
2635 expectedError: ":INVALID_COMPRESSION_LIST:",
2636 expectedLocalError: "remote error: illegal parameter",
2637 },
2638 {
2639 testType: serverTest,
2640 name: "NoNullCompression-TLS12",
2641 config: Config{
2642 MaxVersion: VersionTLS12,
2643 Bugs: ProtocolBugs{
2644 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2645 },
2646 },
2647 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002648 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002649 expectedLocalError: "remote error: illegal parameter",
2650 },
2651 {
2652 testType: serverTest,
2653 name: "NoNullCompression-TLS13",
2654 config: Config{
2655 MaxVersion: VersionTLS13,
2656 Bugs: ProtocolBugs{
2657 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2658 },
2659 },
2660 shouldFail: true,
2661 expectedError: ":INVALID_COMPRESSION_LIST:",
2662 expectedLocalError: "remote error: illegal parameter",
2663 },
David Benjamin413e79e2017-07-01 10:11:53 -04002664 // Test that the client rejects invalid compression methods
2665 // from the server.
2666 {
2667 testType: clientTest,
2668 name: "InvalidCompressionMethod",
2669 config: Config{
2670 MaxVersion: VersionTLS12,
2671 Bugs: ProtocolBugs{
2672 SendCompressionMethod: 1,
2673 },
2674 },
2675 shouldFail: true,
2676 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2677 expectedLocalError: "remote error: illegal parameter",
2678 },
David Benjamin65ac9972016-09-02 21:35:25 -04002679 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002680 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002681 config: Config{
2682 MaxVersion: VersionTLS12,
2683 Bugs: ProtocolBugs{
2684 ExpectGREASE: true,
2685 },
2686 },
2687 flags: []string{"-enable-grease"},
2688 },
2689 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002690 name: "GREASE-Client-TLS13",
2691 config: Config{
2692 MaxVersion: VersionTLS13,
2693 Bugs: ProtocolBugs{
2694 ExpectGREASE: true,
2695 },
2696 },
2697 flags: []string{"-enable-grease"},
2698 },
2699 {
2700 testType: serverTest,
2701 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002702 config: Config{
2703 MaxVersion: VersionTLS13,
2704 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002705 // TLS 1.3 servers are expected to
2706 // always enable GREASE. TLS 1.3 is new,
2707 // so there is no existing ecosystem to
2708 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002709 ExpectGREASE: true,
2710 },
2711 },
David Benjamin65ac9972016-09-02 21:35:25 -04002712 },
David Benjamine3fbb362017-01-06 16:19:28 -05002713 {
2714 // Test the server so there is a large certificate as
2715 // well as application data.
2716 testType: serverTest,
2717 name: "MaxSendFragment",
2718 config: Config{
2719 Bugs: ProtocolBugs{
2720 MaxReceivePlaintext: 512,
2721 },
2722 },
2723 messageLen: 1024,
2724 flags: []string{
2725 "-max-send-fragment", "512",
2726 "-read-size", "1024",
2727 },
2728 },
2729 {
2730 // Test the server so there is a large certificate as
2731 // well as application data.
2732 testType: serverTest,
2733 name: "MaxSendFragment-TooLarge",
2734 config: Config{
2735 Bugs: ProtocolBugs{
2736 // Ensure that some of the records are
2737 // 512.
2738 MaxReceivePlaintext: 511,
2739 },
2740 },
2741 messageLen: 1024,
2742 flags: []string{
2743 "-max-send-fragment", "512",
2744 "-read-size", "1024",
2745 },
2746 shouldFail: true,
2747 expectedLocalError: "local error: record overflow",
2748 },
Adam Langley7c803a62015-06-15 15:35:05 -07002749 }
Adam Langley7c803a62015-06-15 15:35:05 -07002750 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002751
2752 // Test that very large messages can be received.
2753 cert := rsaCertificate
2754 for i := 0; i < 50; i++ {
2755 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2756 }
2757 testCases = append(testCases, testCase{
2758 name: "LargeMessage",
2759 config: Config{
2760 Certificates: []Certificate{cert},
2761 },
2762 })
2763 testCases = append(testCases, testCase{
2764 protocol: dtls,
2765 name: "LargeMessage-DTLS",
2766 config: Config{
2767 Certificates: []Certificate{cert},
2768 },
2769 })
2770
2771 // They are rejected if the maximum certificate chain length is capped.
2772 testCases = append(testCases, testCase{
2773 name: "LargeMessage-Reject",
2774 config: Config{
2775 Certificates: []Certificate{cert},
2776 },
2777 flags: []string{"-max-cert-list", "16384"},
2778 shouldFail: true,
2779 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2780 })
2781 testCases = append(testCases, testCase{
2782 protocol: dtls,
2783 name: "LargeMessage-Reject-DTLS",
2784 config: Config{
2785 Certificates: []Certificate{cert},
2786 },
2787 flags: []string{"-max-cert-list", "16384"},
2788 shouldFail: true,
2789 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2790 })
Adam Langley7c803a62015-06-15 15:35:05 -07002791}
2792
David Benjaminaa012042016-12-10 13:33:05 -05002793func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2794 const psk = "12345"
2795 const pskIdentity = "luggage combo"
2796
2797 var prefix string
2798 if protocol == dtls {
2799 if !ver.hasDTLS {
2800 return
2801 }
2802 prefix = "D"
2803 }
2804
2805 var cert Certificate
2806 var certFile string
2807 var keyFile string
2808 if hasComponent(suite.name, "ECDSA") {
2809 cert = ecdsaP256Certificate
2810 certFile = ecdsaP256CertificateFile
2811 keyFile = ecdsaP256KeyFile
2812 } else {
2813 cert = rsaCertificate
2814 certFile = rsaCertificateFile
2815 keyFile = rsaKeyFile
2816 }
2817
2818 var flags []string
2819 if hasComponent(suite.name, "PSK") {
2820 flags = append(flags,
2821 "-psk", psk,
2822 "-psk-identity", pskIdentity)
2823 }
2824 if hasComponent(suite.name, "NULL") {
2825 // NULL ciphers must be explicitly enabled.
2826 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2827 }
David Benjaminaa012042016-12-10 13:33:05 -05002828
2829 var shouldServerFail, shouldClientFail bool
2830 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2831 // BoringSSL clients accept ECDHE on SSLv3, but
2832 // a BoringSSL server will never select it
2833 // because the extension is missing.
2834 shouldServerFail = true
2835 }
2836 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2837 shouldClientFail = true
2838 shouldServerFail = true
2839 }
2840 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2841 shouldClientFail = true
2842 shouldServerFail = true
2843 }
2844 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2845 shouldClientFail = true
2846 shouldServerFail = true
2847 }
2848 if !isDTLSCipher(suite.name) && protocol == dtls {
2849 shouldClientFail = true
2850 shouldServerFail = true
2851 }
2852
2853 var sendCipherSuite uint16
2854 var expectedServerError, expectedClientError string
2855 serverCipherSuites := []uint16{suite.id}
2856 if shouldServerFail {
2857 expectedServerError = ":NO_SHARED_CIPHER:"
2858 }
2859 if shouldClientFail {
2860 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2861 // Configure the server to select ciphers as normal but
2862 // select an incompatible cipher in ServerHello.
2863 serverCipherSuites = nil
2864 sendCipherSuite = suite.id
2865 }
2866
David Benjamincdb6fe92017-02-07 16:06:48 -05002867 // For cipher suites and versions where exporters are defined, verify
2868 // that they interoperate.
2869 var exportKeyingMaterial int
2870 if ver.version > VersionSSL30 {
2871 exportKeyingMaterial = 1024
2872 }
2873
David Benjaminaa012042016-12-10 13:33:05 -05002874 testCases = append(testCases, testCase{
2875 testType: serverTest,
2876 protocol: protocol,
2877 name: prefix + ver.name + "-" + suite.name + "-server",
2878 config: Config{
2879 MinVersion: ver.version,
2880 MaxVersion: ver.version,
2881 CipherSuites: []uint16{suite.id},
2882 Certificates: []Certificate{cert},
2883 PreSharedKey: []byte(psk),
2884 PreSharedKeyIdentity: pskIdentity,
2885 Bugs: ProtocolBugs{
2886 AdvertiseAllConfiguredCiphers: true,
2887 },
2888 },
David Benjamina5022392017-07-10 17:40:39 -04002889 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002890 certFile: certFile,
2891 keyFile: keyFile,
2892 flags: flags,
2893 resumeSession: true,
2894 shouldFail: shouldServerFail,
2895 expectedError: expectedServerError,
2896 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002897 })
2898
2899 testCases = append(testCases, testCase{
2900 testType: clientTest,
2901 protocol: protocol,
2902 name: prefix + ver.name + "-" + suite.name + "-client",
2903 config: Config{
2904 MinVersion: ver.version,
2905 MaxVersion: ver.version,
2906 CipherSuites: serverCipherSuites,
2907 Certificates: []Certificate{cert},
2908 PreSharedKey: []byte(psk),
2909 PreSharedKeyIdentity: pskIdentity,
2910 Bugs: ProtocolBugs{
2911 IgnorePeerCipherPreferences: shouldClientFail,
2912 SendCipherSuite: sendCipherSuite,
2913 },
2914 },
David Benjamina5022392017-07-10 17:40:39 -04002915 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002916 flags: flags,
2917 resumeSession: true,
2918 shouldFail: shouldClientFail,
2919 expectedError: expectedClientError,
2920 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002921 })
2922
David Benjamin6f600d62016-12-21 16:06:54 -05002923 if shouldClientFail {
2924 return
2925 }
2926
2927 // Ensure the maximum record size is accepted.
2928 testCases = append(testCases, testCase{
2929 protocol: protocol,
2930 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2931 config: Config{
2932 MinVersion: ver.version,
2933 MaxVersion: ver.version,
2934 CipherSuites: []uint16{suite.id},
2935 Certificates: []Certificate{cert},
2936 PreSharedKey: []byte(psk),
2937 PreSharedKeyIdentity: pskIdentity,
2938 },
David Benjamina5022392017-07-10 17:40:39 -04002939 tls13Variant: ver.tls13Variant,
2940 flags: flags,
2941 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002942 })
2943
2944 // Test bad records for all ciphers. Bad records are fatal in TLS
2945 // and ignored in DTLS.
2946 var shouldFail bool
2947 var expectedError string
2948 if protocol == tls {
2949 shouldFail = true
2950 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2951 }
2952
2953 testCases = append(testCases, testCase{
2954 protocol: protocol,
2955 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2956 config: Config{
2957 MinVersion: ver.version,
2958 MaxVersion: ver.version,
2959 CipherSuites: []uint16{suite.id},
2960 Certificates: []Certificate{cert},
2961 PreSharedKey: []byte(psk),
2962 PreSharedKeyIdentity: pskIdentity,
2963 },
David Benjamina5022392017-07-10 17:40:39 -04002964 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002965 flags: flags,
2966 damageFirstWrite: true,
2967 messageLen: maxPlaintext,
2968 shouldFail: shouldFail,
2969 expectedError: expectedError,
2970 })
David Benjaminaa012042016-12-10 13:33:05 -05002971}
2972
Adam Langley95c29f32014-06-20 12:00:00 -07002973func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002974 const bogusCipher = 0xfe00
2975
Adam Langley95c29f32014-06-20 12:00:00 -07002976 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002977 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002978 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002979 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002980 }
David Benjamin2c99d282015-09-01 10:23:00 -04002981 }
Adam Langley95c29f32014-06-20 12:00:00 -07002982 }
Adam Langleya7997f12015-05-14 17:38:50 -07002983
2984 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002985 name: "NoSharedCipher",
2986 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002987 MaxVersion: VersionTLS12,
2988 CipherSuites: []uint16{},
2989 },
2990 shouldFail: true,
2991 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2992 })
2993
2994 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002995 name: "NoSharedCipher-TLS13",
2996 config: Config{
2997 MaxVersion: VersionTLS13,
2998 CipherSuites: []uint16{},
2999 },
3000 shouldFail: true,
3001 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3002 })
3003
3004 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003005 name: "UnsupportedCipherSuite",
3006 config: Config{
3007 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003008 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003009 Bugs: ProtocolBugs{
3010 IgnorePeerCipherPreferences: true,
3011 },
3012 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003013 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003014 shouldFail: true,
3015 expectedError: ":WRONG_CIPHER_RETURNED:",
3016 })
3017
3018 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003019 name: "ServerHelloBogusCipher",
3020 config: Config{
3021 MaxVersion: VersionTLS12,
3022 Bugs: ProtocolBugs{
3023 SendCipherSuite: bogusCipher,
3024 },
3025 },
3026 shouldFail: true,
3027 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3028 })
3029 testCases = append(testCases, testCase{
3030 name: "ServerHelloBogusCipher-TLS13",
3031 config: Config{
3032 MaxVersion: VersionTLS13,
3033 Bugs: ProtocolBugs{
3034 SendCipherSuite: bogusCipher,
3035 },
3036 },
3037 shouldFail: true,
3038 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3039 })
3040
David Benjamin241ae832016-01-15 03:04:54 -05003041 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003042 testCases = append(testCases, testCase{
3043 testType: serverTest,
3044 name: "UnknownCipher",
3045 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003046 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003047 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003048 Bugs: ProtocolBugs{
3049 AdvertiseAllConfiguredCiphers: true,
3050 },
3051 },
3052 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003053
3054 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003055 testCases = append(testCases, testCase{
3056 testType: serverTest,
3057 name: "UnknownCipher-TLS13",
3058 config: Config{
3059 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003060 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003061 Bugs: ProtocolBugs{
3062 AdvertiseAllConfiguredCiphers: true,
3063 },
David Benjamin241ae832016-01-15 03:04:54 -05003064 },
3065 })
3066
David Benjamin78679342016-09-16 19:42:05 -04003067 // Test empty ECDHE_PSK identity hints work as expected.
3068 testCases = append(testCases, testCase{
3069 name: "EmptyECDHEPSKHint",
3070 config: Config{
3071 MaxVersion: VersionTLS12,
3072 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3073 PreSharedKey: []byte("secret"),
3074 },
3075 flags: []string{"-psk", "secret"},
3076 })
3077
3078 // Test empty PSK identity hints work as expected, even if an explicit
3079 // ServerKeyExchange is sent.
3080 testCases = append(testCases, testCase{
3081 name: "ExplicitEmptyPSKHint",
3082 config: Config{
3083 MaxVersion: VersionTLS12,
3084 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3085 PreSharedKey: []byte("secret"),
3086 Bugs: ProtocolBugs{
3087 AlwaysSendPreSharedKeyIdentityHint: true,
3088 },
3089 },
3090 flags: []string{"-psk", "secret"},
3091 })
David Benjamin69522112017-03-28 15:38:29 -05003092
3093 // Test that clients enforce that the server-sent certificate and cipher
3094 // suite match in TLS 1.2.
3095 testCases = append(testCases, testCase{
3096 name: "CertificateCipherMismatch-RSA",
3097 config: Config{
3098 MaxVersion: VersionTLS12,
3099 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3100 Certificates: []Certificate{rsaCertificate},
3101 Bugs: ProtocolBugs{
3102 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3103 },
3104 },
3105 shouldFail: true,
3106 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3107 })
3108 testCases = append(testCases, testCase{
3109 name: "CertificateCipherMismatch-ECDSA",
3110 config: Config{
3111 MaxVersion: VersionTLS12,
3112 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3113 Certificates: []Certificate{ecdsaP256Certificate},
3114 Bugs: ProtocolBugs{
3115 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3116 },
3117 },
3118 shouldFail: true,
3119 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3120 })
3121 testCases = append(testCases, testCase{
3122 name: "CertificateCipherMismatch-Ed25519",
3123 config: Config{
3124 MaxVersion: VersionTLS12,
3125 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3126 Certificates: []Certificate{ed25519Certificate},
3127 Bugs: ProtocolBugs{
3128 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3129 },
3130 },
3131 shouldFail: true,
3132 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3133 })
3134
3135 // Test that servers decline to select a cipher suite which is
3136 // inconsistent with their configured certificate.
3137 testCases = append(testCases, testCase{
3138 testType: serverTest,
3139 name: "ServerCipherFilter-RSA",
3140 config: Config{
3141 MaxVersion: VersionTLS12,
3142 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3143 },
3144 flags: []string{
3145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3147 },
3148 shouldFail: true,
3149 expectedError: ":NO_SHARED_CIPHER:",
3150 })
3151 testCases = append(testCases, testCase{
3152 testType: serverTest,
3153 name: "ServerCipherFilter-ECDSA",
3154 config: Config{
3155 MaxVersion: VersionTLS12,
3156 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3157 },
3158 flags: []string{
3159 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3160 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3161 },
3162 shouldFail: true,
3163 expectedError: ":NO_SHARED_CIPHER:",
3164 })
3165 testCases = append(testCases, testCase{
3166 testType: serverTest,
3167 name: "ServerCipherFilter-Ed25519",
3168 config: Config{
3169 MaxVersion: VersionTLS12,
3170 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3171 },
3172 flags: []string{
3173 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3174 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3175 },
3176 shouldFail: true,
3177 expectedError: ":NO_SHARED_CIPHER:",
3178 })
David Benjamin364af782017-07-01 10:35:27 -04003179
3180 // Test cipher suite negotiation works as expected. Configure a
3181 // complicated cipher suite configuration.
3182 const negotiationTestCiphers = "" +
3183 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3184 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3185 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3186 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3187 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3188 negotiationTests := []struct {
3189 ciphers []uint16
3190 expected uint16
3191 }{
3192 // Server preferences are honored, including when
3193 // equipreference groups are involved.
3194 {
3195 []uint16{
3196 TLS_RSA_WITH_AES_256_GCM_SHA384,
3197 TLS_RSA_WITH_AES_128_CBC_SHA,
3198 TLS_RSA_WITH_AES_128_GCM_SHA256,
3199 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3200 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3201 },
3202 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3203 },
3204 {
3205 []uint16{
3206 TLS_RSA_WITH_AES_256_GCM_SHA384,
3207 TLS_RSA_WITH_AES_128_CBC_SHA,
3208 TLS_RSA_WITH_AES_128_GCM_SHA256,
3209 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3210 },
3211 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3212 },
3213 {
3214 []uint16{
3215 TLS_RSA_WITH_AES_256_GCM_SHA384,
3216 TLS_RSA_WITH_AES_128_CBC_SHA,
3217 TLS_RSA_WITH_AES_128_GCM_SHA256,
3218 },
3219 TLS_RSA_WITH_AES_128_GCM_SHA256,
3220 },
3221 {
3222 []uint16{
3223 TLS_RSA_WITH_AES_256_GCM_SHA384,
3224 TLS_RSA_WITH_AES_128_CBC_SHA,
3225 },
3226 TLS_RSA_WITH_AES_128_CBC_SHA,
3227 },
3228 // Equipreference groups use the client preference.
3229 {
3230 []uint16{
3231 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3232 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3233 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3234 },
3235 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3236 },
3237 {
3238 []uint16{
3239 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3240 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3241 },
3242 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3243 },
3244 {
3245 []uint16{
3246 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3247 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3248 },
3249 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3250 },
3251 {
3252 []uint16{
3253 TLS_RSA_WITH_AES_256_GCM_SHA384,
3254 TLS_RSA_WITH_AES_256_CBC_SHA,
3255 },
3256 TLS_RSA_WITH_AES_256_GCM_SHA384,
3257 },
3258 {
3259 []uint16{
3260 TLS_RSA_WITH_AES_256_CBC_SHA,
3261 TLS_RSA_WITH_AES_256_GCM_SHA384,
3262 },
3263 TLS_RSA_WITH_AES_256_CBC_SHA,
3264 },
3265 // If there are two equipreference groups, the preferred one
3266 // takes precedence.
3267 {
3268 []uint16{
3269 TLS_RSA_WITH_AES_256_GCM_SHA384,
3270 TLS_RSA_WITH_AES_256_CBC_SHA,
3271 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3272 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3273 },
3274 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3275 },
3276 }
3277 for i, t := range negotiationTests {
3278 testCases = append(testCases, testCase{
3279 testType: serverTest,
3280 name: "CipherNegotiation-" + strconv.Itoa(i),
3281 config: Config{
3282 MaxVersion: VersionTLS12,
3283 CipherSuites: t.ciphers,
3284 },
3285 flags: []string{"-cipher", negotiationTestCiphers},
3286 expectedCipher: t.expected,
3287 })
3288 }
Adam Langley95c29f32014-06-20 12:00:00 -07003289}
3290
3291func addBadECDSASignatureTests() {
3292 for badR := BadValue(1); badR < NumBadValues; badR++ {
3293 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003294 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003295 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3296 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003297 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003298 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003299 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003300 Bugs: ProtocolBugs{
3301 BadECDSAR: badR,
3302 BadECDSAS: badS,
3303 },
3304 },
3305 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003306 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003307 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003308 testCases = append(testCases, testCase{
3309 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3310 config: Config{
3311 MaxVersion: VersionTLS13,
3312 Certificates: []Certificate{ecdsaP256Certificate},
3313 Bugs: ProtocolBugs{
3314 BadECDSAR: badR,
3315 BadECDSAS: badS,
3316 },
3317 },
3318 shouldFail: true,
3319 expectedError: ":BAD_SIGNATURE:",
3320 })
Adam Langley95c29f32014-06-20 12:00:00 -07003321 }
3322 }
3323}
3324
Adam Langley80842bd2014-06-20 12:00:00 -07003325func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003326 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003327 name: "MaxCBCPadding",
3328 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003329 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003330 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3331 Bugs: ProtocolBugs{
3332 MaxPadding: true,
3333 },
3334 },
3335 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3336 })
David Benjamin025b3d32014-07-01 19:53:04 -04003337 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003338 name: "BadCBCPadding",
3339 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003340 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3342 Bugs: ProtocolBugs{
3343 PaddingFirstByteBad: true,
3344 },
3345 },
3346 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003347 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003348 })
3349 // OpenSSL previously had an issue where the first byte of padding in
3350 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003351 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003352 name: "BadCBCPadding255",
3353 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003354 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3356 Bugs: ProtocolBugs{
3357 MaxPadding: true,
3358 PaddingFirstByteBadIf255: true,
3359 },
3360 },
3361 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3362 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003363 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003364 })
3365}
3366
Kenny Root7fdeaf12014-08-05 15:23:37 -07003367func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003368 var cbcCiphers = []struct {
3369 name string
3370 cipher uint16
3371 }{
3372 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3373 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3374 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3375 }
3376 for _, t := range cbcCiphers {
3377 testCases = append(testCases, testCase{
3378 name: "CBCRecordSplitting-" + t.name,
3379 config: Config{
3380 MaxVersion: VersionTLS10,
3381 MinVersion: VersionTLS10,
3382 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003383 Bugs: ProtocolBugs{
3384 ExpectRecordSplitting: true,
3385 },
David Benjamina1ce8562017-07-01 11:46:57 -04003386 },
3387 messageLen: -1, // read until EOF
3388 resumeSession: true,
3389 flags: []string{
3390 "-async",
3391 "-write-different-record-sizes",
3392 "-cbc-record-splitting",
3393 },
3394 })
3395 testCases = append(testCases, testCase{
3396 name: "CBCRecordSplittingPartialWrite-" + t.name,
3397 config: Config{
3398 MaxVersion: VersionTLS10,
3399 MinVersion: VersionTLS10,
3400 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003401 Bugs: ProtocolBugs{
3402 ExpectRecordSplitting: true,
3403 },
David Benjamina1ce8562017-07-01 11:46:57 -04003404 },
3405 messageLen: -1, // read until EOF
3406 flags: []string{
3407 "-async",
3408 "-write-different-record-sizes",
3409 "-cbc-record-splitting",
3410 "-partial-write",
3411 },
3412 })
3413 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003414}
3415
David Benjamin636293b2014-07-08 17:59:18 -04003416func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003417 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003418 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003419 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3420 cert, err := x509.ParseCertificate(cert.Certificate[0])
3421 if err != nil {
3422 panic(err)
3423 }
3424 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003425 }
Adam Langley2ff79332017-02-28 13:45:39 -08003426 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003427
David Benjamin636293b2014-07-08 17:59:18 -04003428 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003429 testCases = append(testCases, testCase{
3430 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003431 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003432 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003433 MinVersion: ver.version,
3434 MaxVersion: ver.version,
3435 ClientAuth: RequireAnyClientCert,
3436 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003437 },
David Benjamina5022392017-07-10 17:40:39 -04003438 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003439 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003440 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3441 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003442 },
3443 })
3444 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003445 testType: serverTest,
3446 name: ver.name + "-Server-ClientAuth-RSA",
3447 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003448 MinVersion: ver.version,
3449 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003450 Certificates: []Certificate{rsaCertificate},
3451 },
David Benjamina5022392017-07-10 17:40:39 -04003452 tls13Variant: ver.tls13Variant,
3453 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003454 })
David Benjamine098ec22014-08-27 23:13:20 -04003455 if ver.version != VersionSSL30 {
3456 testCases = append(testCases, testCase{
3457 testType: serverTest,
3458 name: ver.name + "-Server-ClientAuth-ECDSA",
3459 config: Config{
3460 MinVersion: ver.version,
3461 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003462 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003463 },
David Benjamina5022392017-07-10 17:40:39 -04003464 tls13Variant: ver.tls13Variant,
3465 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003466 })
3467 testCases = append(testCases, testCase{
3468 testType: clientTest,
3469 name: ver.name + "-Client-ClientAuth-ECDSA",
3470 config: Config{
3471 MinVersion: ver.version,
3472 MaxVersion: ver.version,
3473 ClientAuth: RequireAnyClientCert,
3474 ClientCAs: certPool,
3475 },
David Benjamina5022392017-07-10 17:40:39 -04003476 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003477 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003478 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3479 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003480 },
3481 })
3482 }
Adam Langley37646832016-08-01 16:16:46 -07003483
3484 testCases = append(testCases, testCase{
3485 name: "NoClientCertificate-" + ver.name,
3486 config: Config{
3487 MinVersion: ver.version,
3488 MaxVersion: ver.version,
3489 ClientAuth: RequireAnyClientCert,
3490 },
David Benjamina5022392017-07-10 17:40:39 -04003491 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003492 shouldFail: true,
3493 expectedLocalError: "client didn't provide a certificate",
3494 })
3495
3496 testCases = append(testCases, testCase{
3497 // Even if not configured to expect a certificate, OpenSSL will
3498 // return X509_V_OK as the verify_result.
3499 testType: serverTest,
3500 name: "NoClientCertificateRequested-Server-" + ver.name,
3501 config: Config{
3502 MinVersion: ver.version,
3503 MaxVersion: ver.version,
3504 },
David Benjamina5022392017-07-10 17:40:39 -04003505 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003506 flags: []string{
3507 "-expect-verify-result",
3508 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003509 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003510 })
3511
3512 testCases = append(testCases, testCase{
3513 // If a client certificate is not provided, OpenSSL will still
3514 // return X509_V_OK as the verify_result.
3515 testType: serverTest,
3516 name: "NoClientCertificate-Server-" + ver.name,
3517 config: Config{
3518 MinVersion: ver.version,
3519 MaxVersion: ver.version,
3520 },
David Benjamina5022392017-07-10 17:40:39 -04003521 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003522 flags: []string{
3523 "-expect-verify-result",
3524 "-verify-peer",
3525 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003526 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003527 })
3528
David Benjamin1db9e1b2016-10-07 20:51:43 -04003529 certificateRequired := "remote error: certificate required"
3530 if ver.version < VersionTLS13 {
3531 // Prior to TLS 1.3, the generic handshake_failure alert
3532 // was used.
3533 certificateRequired = "remote error: handshake failure"
3534 }
Adam Langley37646832016-08-01 16:16:46 -07003535 testCases = append(testCases, testCase{
3536 testType: serverTest,
3537 name: "RequireAnyClientCertificate-" + ver.name,
3538 config: Config{
3539 MinVersion: ver.version,
3540 MaxVersion: ver.version,
3541 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003542 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003543 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003544 shouldFail: true,
3545 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3546 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003547 })
3548
3549 if ver.version != VersionSSL30 {
3550 testCases = append(testCases, testCase{
3551 testType: serverTest,
3552 name: "SkipClientCertificate-" + ver.name,
3553 config: Config{
3554 MinVersion: ver.version,
3555 MaxVersion: ver.version,
3556 Bugs: ProtocolBugs{
3557 SkipClientCertificate: true,
3558 },
3559 },
3560 // Setting SSL_VERIFY_PEER allows anonymous clients.
3561 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003562 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003563 shouldFail: true,
3564 expectedError: ":UNEXPECTED_MESSAGE:",
3565 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003566
3567 testCases = append(testCases, testCase{
3568 testType: serverTest,
3569 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3570 config: Config{
3571 MinVersion: ver.version,
3572 MaxVersion: ver.version,
3573 },
3574 flags: []string{
3575 "-enable-channel-id",
3576 "-verify-peer-if-no-obc",
3577 },
David Benjamina5022392017-07-10 17:40:39 -04003578 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003579 shouldFail: true,
3580 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3581 expectedLocalError: certificateRequired,
3582 })
3583
3584 testCases = append(testCases, testCase{
3585 testType: serverTest,
3586 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3587 config: Config{
3588 MinVersion: ver.version,
3589 MaxVersion: ver.version,
3590 ChannelID: channelIDKey,
3591 },
3592 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003593 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003594 flags: []string{
3595 "-enable-channel-id",
3596 "-verify-peer-if-no-obc",
3597 },
3598 })
Adam Langley37646832016-08-01 16:16:46 -07003599 }
Adam Langley2ff79332017-02-28 13:45:39 -08003600
3601 testCases = append(testCases, testCase{
3602 testType: serverTest,
3603 name: ver.name + "-Server-CertReq-CA-List",
3604 config: Config{
3605 MinVersion: ver.version,
3606 MaxVersion: ver.version,
3607 Certificates: []Certificate{rsaCertificate},
3608 Bugs: ProtocolBugs{
3609 ExpectCertificateReqNames: caNames,
3610 },
3611 },
David Benjamina5022392017-07-10 17:40:39 -04003612 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003613 flags: []string{
3614 "-require-any-client-certificate",
3615 "-use-client-ca-list", encodeDERValues(caNames),
3616 },
3617 })
3618
3619 testCases = append(testCases, testCase{
3620 testType: clientTest,
3621 name: ver.name + "-Client-CertReq-CA-List",
3622 config: Config{
3623 MinVersion: ver.version,
3624 MaxVersion: ver.version,
3625 Certificates: []Certificate{rsaCertificate},
3626 ClientAuth: RequireAnyClientCert,
3627 ClientCAs: certPool,
3628 },
David Benjamina5022392017-07-10 17:40:39 -04003629 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003630 flags: []string{
3631 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3632 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3633 "-expect-client-ca-list", encodeDERValues(caNames),
3634 },
3635 })
David Benjamin636293b2014-07-08 17:59:18 -04003636 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003637
David Benjaminc032dfa2016-05-12 14:54:57 -04003638 // Client auth is only legal in certificate-based ciphers.
3639 testCases = append(testCases, testCase{
3640 testType: clientTest,
3641 name: "ClientAuth-PSK",
3642 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003643 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003644 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3645 PreSharedKey: []byte("secret"),
3646 ClientAuth: RequireAnyClientCert,
3647 },
3648 flags: []string{
3649 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3650 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3651 "-psk", "secret",
3652 },
3653 shouldFail: true,
3654 expectedError: ":UNEXPECTED_MESSAGE:",
3655 })
3656 testCases = append(testCases, testCase{
3657 testType: clientTest,
3658 name: "ClientAuth-ECDHE_PSK",
3659 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003660 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003661 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3662 PreSharedKey: []byte("secret"),
3663 ClientAuth: RequireAnyClientCert,
3664 },
3665 flags: []string{
3666 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3667 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3668 "-psk", "secret",
3669 },
3670 shouldFail: true,
3671 expectedError: ":UNEXPECTED_MESSAGE:",
3672 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003673
3674 // Regression test for a bug where the client CA list, if explicitly
3675 // set to NULL, was mis-encoded.
3676 testCases = append(testCases, testCase{
3677 testType: serverTest,
3678 name: "Null-Client-CA-List",
3679 config: Config{
3680 MaxVersion: VersionTLS12,
3681 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003682 Bugs: ProtocolBugs{
3683 ExpectCertificateReqNames: [][]byte{},
3684 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003685 },
3686 flags: []string{
3687 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003688 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003689 },
3690 })
David Benjamin636293b2014-07-08 17:59:18 -04003691}
3692
Adam Langley75712922014-10-10 16:23:43 -07003693func addExtendedMasterSecretTests() {
3694 const expectEMSFlag = "-expect-extended-master-secret"
3695
3696 for _, with := range []bool{false, true} {
3697 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003698 if with {
3699 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003700 }
3701
3702 for _, isClient := range []bool{false, true} {
3703 suffix := "-Server"
3704 testType := serverTest
3705 if isClient {
3706 suffix = "-Client"
3707 testType = clientTest
3708 }
3709
3710 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003711 // In TLS 1.3, the extension is irrelevant and
3712 // always reports as enabled.
3713 var flags []string
3714 if with || ver.version >= VersionTLS13 {
3715 flags = []string{expectEMSFlag}
3716 }
3717
Adam Langley75712922014-10-10 16:23:43 -07003718 test := testCase{
3719 testType: testType,
3720 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3721 config: Config{
3722 MinVersion: ver.version,
3723 MaxVersion: ver.version,
3724 Bugs: ProtocolBugs{
3725 NoExtendedMasterSecret: !with,
3726 RequireExtendedMasterSecret: with,
3727 },
3728 },
David Benjamina5022392017-07-10 17:40:39 -04003729 tls13Variant: ver.tls13Variant,
3730 flags: flags,
3731 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003732 }
3733 if test.shouldFail {
3734 test.expectedLocalError = "extended master secret required but not supported by peer"
3735 }
3736 testCases = append(testCases, test)
3737 }
3738 }
3739 }
3740
Adam Langleyba5934b2015-06-02 10:50:35 -07003741 for _, isClient := range []bool{false, true} {
3742 for _, supportedInFirstConnection := range []bool{false, true} {
3743 for _, supportedInResumeConnection := range []bool{false, true} {
3744 boolToWord := func(b bool) string {
3745 if b {
3746 return "Yes"
3747 }
3748 return "No"
3749 }
3750 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3751 if isClient {
3752 suffix += "Client"
3753 } else {
3754 suffix += "Server"
3755 }
3756
3757 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003758 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003759 Bugs: ProtocolBugs{
3760 RequireExtendedMasterSecret: true,
3761 },
3762 }
3763
3764 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003766 Bugs: ProtocolBugs{
3767 NoExtendedMasterSecret: true,
3768 },
3769 }
3770
3771 test := testCase{
3772 name: "ExtendedMasterSecret-" + suffix,
3773 resumeSession: true,
3774 }
3775
3776 if !isClient {
3777 test.testType = serverTest
3778 }
3779
3780 if supportedInFirstConnection {
3781 test.config = supportedConfig
3782 } else {
3783 test.config = noSupportConfig
3784 }
3785
3786 if supportedInResumeConnection {
3787 test.resumeConfig = &supportedConfig
3788 } else {
3789 test.resumeConfig = &noSupportConfig
3790 }
3791
3792 switch suffix {
3793 case "YesToYes-Client", "YesToYes-Server":
3794 // When a session is resumed, it should
3795 // still be aware that its master
3796 // secret was generated via EMS and
3797 // thus it's safe to use tls-unique.
3798 test.flags = []string{expectEMSFlag}
3799 case "NoToYes-Server":
3800 // If an original connection did not
3801 // contain EMS, but a resumption
3802 // handshake does, then a server should
3803 // not resume the session.
3804 test.expectResumeRejected = true
3805 case "YesToNo-Server":
3806 // Resuming an EMS session without the
3807 // EMS extension should cause the
3808 // server to abort the connection.
3809 test.shouldFail = true
3810 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3811 case "NoToYes-Client":
3812 // A client should abort a connection
3813 // where the server resumed a non-EMS
3814 // session but echoed the EMS
3815 // extension.
3816 test.shouldFail = true
3817 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3818 case "YesToNo-Client":
3819 // A client should abort a connection
3820 // where the server didn't echo EMS
3821 // when the session used it.
3822 test.shouldFail = true
3823 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3824 }
3825
3826 testCases = append(testCases, test)
3827 }
3828 }
3829 }
David Benjamin163c9562016-08-29 23:14:17 -04003830
3831 // Switching EMS on renegotiation is forbidden.
3832 testCases = append(testCases, testCase{
3833 name: "ExtendedMasterSecret-Renego-NoEMS",
3834 config: Config{
3835 MaxVersion: VersionTLS12,
3836 Bugs: ProtocolBugs{
3837 NoExtendedMasterSecret: true,
3838 NoExtendedMasterSecretOnRenegotiation: true,
3839 },
3840 },
3841 renegotiate: 1,
3842 flags: []string{
3843 "-renegotiate-freely",
3844 "-expect-total-renegotiations", "1",
3845 },
3846 })
3847
3848 testCases = append(testCases, testCase{
3849 name: "ExtendedMasterSecret-Renego-Upgrade",
3850 config: Config{
3851 MaxVersion: VersionTLS12,
3852 Bugs: ProtocolBugs{
3853 NoExtendedMasterSecret: true,
3854 },
3855 },
3856 renegotiate: 1,
3857 flags: []string{
3858 "-renegotiate-freely",
3859 "-expect-total-renegotiations", "1",
3860 },
3861 shouldFail: true,
3862 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3863 })
3864
3865 testCases = append(testCases, testCase{
3866 name: "ExtendedMasterSecret-Renego-Downgrade",
3867 config: Config{
3868 MaxVersion: VersionTLS12,
3869 Bugs: ProtocolBugs{
3870 NoExtendedMasterSecretOnRenegotiation: true,
3871 },
3872 },
3873 renegotiate: 1,
3874 flags: []string{
3875 "-renegotiate-freely",
3876 "-expect-total-renegotiations", "1",
3877 },
3878 shouldFail: true,
3879 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3880 })
Adam Langley75712922014-10-10 16:23:43 -07003881}
3882
David Benjamin582ba042016-07-07 12:33:25 -07003883type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003884 protocol protocol
3885 async bool
3886 splitHandshake bool
3887 packHandshakeFlight bool
3888 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003889}
3890
David Benjamin43ec06f2014-08-05 02:28:57 -04003891// Adds tests that try to cover the range of the handshake state machine, under
3892// various conditions. Some of these are redundant with other tests, but they
3893// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003894func addAllStateMachineCoverageTests() {
3895 for _, async := range []bool{false, true} {
3896 for _, protocol := range []protocol{tls, dtls} {
3897 addStateMachineCoverageTests(stateMachineTestConfig{
3898 protocol: protocol,
3899 async: async,
3900 })
3901 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003902 protocol: protocol,
3903 async: async,
3904 implicitHandshake: true,
3905 })
3906 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003907 protocol: protocol,
3908 async: async,
3909 splitHandshake: true,
3910 })
3911 if protocol == tls {
3912 addStateMachineCoverageTests(stateMachineTestConfig{
3913 protocol: protocol,
3914 async: async,
3915 packHandshakeFlight: true,
3916 })
3917 }
3918 }
3919 }
3920}
3921
3922func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003923 var tests []testCase
3924
3925 // Basic handshake, with resumption. Client and server,
3926 // session ID and session ticket.
3927 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003928 name: "Basic-Client",
3929 config: Config{
3930 MaxVersion: VersionTLS12,
3931 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003932 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003933 // Ensure session tickets are used, not session IDs.
3934 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003935 })
3936 tests = append(tests, testCase{
3937 name: "Basic-Client-RenewTicket",
3938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003939 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003940 Bugs: ProtocolBugs{
3941 RenewTicketOnResume: true,
3942 },
3943 },
David Benjamin46662482016-08-17 00:51:00 -04003944 flags: []string{"-expect-ticket-renewal"},
3945 resumeSession: true,
3946 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003947 })
3948 tests = append(tests, testCase{
3949 name: "Basic-Client-NoTicket",
3950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003951 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003952 SessionTicketsDisabled: true,
3953 },
3954 resumeSession: true,
3955 })
3956 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003957 testType: serverTest,
3958 name: "Basic-Server",
3959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003960 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003961 Bugs: ProtocolBugs{
3962 RequireSessionTickets: true,
3963 },
3964 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003965 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003966 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003967 })
3968 tests = append(tests, testCase{
3969 testType: serverTest,
3970 name: "Basic-Server-NoTickets",
3971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003973 SessionTicketsDisabled: true,
3974 },
3975 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003976 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 })
3978 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003980 name: "Basic-Server-EarlyCallback",
3981 config: Config{
3982 MaxVersion: VersionTLS12,
3983 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003984 flags: []string{"-use-early-callback"},
3985 resumeSession: true,
3986 })
3987
Steven Valdez143e8b32016-07-11 13:19:03 -04003988 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003989 if config.protocol == tls {
3990 tests = append(tests, testCase{
3991 name: "TLS13-1RTT-Client",
3992 config: Config{
3993 MaxVersion: VersionTLS13,
3994 MinVersion: VersionTLS13,
3995 },
David Benjamin46662482016-08-17 00:51:00 -04003996 resumeSession: true,
3997 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003998 })
3999
4000 tests = append(tests, testCase{
4001 testType: serverTest,
4002 name: "TLS13-1RTT-Server",
4003 config: Config{
4004 MaxVersion: VersionTLS13,
4005 MinVersion: VersionTLS13,
4006 },
David Benjamin46662482016-08-17 00:51:00 -04004007 resumeSession: true,
4008 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004009 // TLS 1.3 uses tickets, so the session should not be
4010 // cached statefully.
4011 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004012 })
4013
4014 tests = append(tests, testCase{
4015 name: "TLS13-HelloRetryRequest-Client",
4016 config: Config{
4017 MaxVersion: VersionTLS13,
4018 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004019 // P-384 requires a HelloRetryRequest against BoringSSL's default
4020 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004021 CurvePreferences: []CurveID{CurveP384},
4022 Bugs: ProtocolBugs{
4023 ExpectMissingKeyShare: true,
4024 },
4025 },
4026 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4027 resumeSession: true,
4028 })
4029
4030 tests = append(tests, testCase{
4031 testType: serverTest,
4032 name: "TLS13-HelloRetryRequest-Server",
4033 config: Config{
4034 MaxVersion: VersionTLS13,
4035 MinVersion: VersionTLS13,
4036 // Require a HelloRetryRequest for every curve.
4037 DefaultCurves: []CurveID{},
4038 },
4039 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4040 resumeSession: true,
4041 })
Steven Valdez2d850622017-01-11 11:34:52 -05004042
Steven Valdez2d850622017-01-11 11:34:52 -05004043 tests = append(tests, testCase{
4044 testType: clientTest,
4045 name: "TLS13-EarlyData-Client",
4046 config: Config{
4047 MaxVersion: VersionTLS13,
4048 MinVersion: VersionTLS13,
4049 MaxEarlyDataSize: 16384,
4050 },
Steven Valdeze831a812017-03-09 14:56:07 -05004051 resumeConfig: &Config{
4052 MaxVersion: VersionTLS13,
4053 MinVersion: VersionTLS13,
4054 MaxEarlyDataSize: 16384,
4055 Bugs: ProtocolBugs{
4056 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4057 },
4058 },
Steven Valdez2d850622017-01-11 11:34:52 -05004059 resumeSession: true,
4060 flags: []string{
4061 "-enable-early-data",
4062 "-expect-early-data-info",
4063 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004064 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004065 },
4066 })
4067
4068 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004069 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004070 name: "TLS13Experiment-EarlyData-Client",
4071 config: Config{
4072 MaxVersion: VersionTLS13,
4073 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004074 MaxEarlyDataSize: 16384,
4075 },
4076 resumeConfig: &Config{
4077 MaxVersion: VersionTLS13,
4078 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004079 MaxEarlyDataSize: 16384,
4080 Bugs: ProtocolBugs{
4081 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4082 },
4083 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004084 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004085 resumeSession: true,
4086 flags: []string{
4087 "-enable-early-data",
4088 "-expect-early-data-info",
4089 "-expect-accept-early-data",
4090 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004091 },
4092 })
4093
4094 tests = append(tests, testCase{
4095 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004096 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4097 config: Config{
4098 MaxVersion: VersionTLS13,
4099 MinVersion: VersionTLS13,
4100 TLS13Variant: TLS13RecordTypeExperiment,
4101 MaxEarlyDataSize: 16384,
4102 },
4103 resumeConfig: &Config{
4104 MaxVersion: VersionTLS13,
4105 MinVersion: VersionTLS13,
4106 TLS13Variant: TLS13RecordTypeExperiment,
4107 MaxEarlyDataSize: 16384,
4108 Bugs: ProtocolBugs{
4109 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4110 },
4111 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004112 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004113 resumeSession: true,
4114 flags: []string{
4115 "-enable-early-data",
4116 "-expect-early-data-info",
4117 "-expect-accept-early-data",
4118 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004119 },
4120 })
4121
4122 tests = append(tests, testCase{
4123 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004124 name: "TLS13-EarlyData-TooMuchData-Client",
4125 config: Config{
4126 MaxVersion: VersionTLS13,
4127 MinVersion: VersionTLS13,
4128 MaxEarlyDataSize: 2,
4129 },
4130 resumeConfig: &Config{
4131 MaxVersion: VersionTLS13,
4132 MinVersion: VersionTLS13,
4133 MaxEarlyDataSize: 2,
4134 Bugs: ProtocolBugs{
4135 ExpectEarlyData: [][]byte{{'h', 'e'}},
4136 },
4137 },
4138 resumeShimPrefix: "llo",
4139 resumeSession: true,
4140 flags: []string{
4141 "-enable-early-data",
4142 "-expect-early-data-info",
4143 "-expect-accept-early-data",
4144 "-on-resume-shim-writes-first",
4145 },
4146 })
4147
4148 // Unfinished writes can only be tested when operations are async. EarlyData
4149 // can't be tested as part of an ImplicitHandshake in this case since
4150 // otherwise the early data will be sent as normal data.
4151 if config.async && !config.implicitHandshake {
4152 tests = append(tests, testCase{
4153 testType: clientTest,
4154 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4155 config: Config{
4156 MaxVersion: VersionTLS13,
4157 MinVersion: VersionTLS13,
4158 MaxEarlyDataSize: 16384,
4159 },
4160 resumeConfig: &Config{
4161 MaxVersion: VersionTLS13,
4162 MinVersion: VersionTLS13,
4163 MaxEarlyDataSize: 16384,
4164 Bugs: ProtocolBugs{
4165 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4166 },
4167 },
4168 resumeSession: true,
4169 flags: []string{
4170 "-enable-early-data",
4171 "-expect-early-data-info",
4172 "-expect-accept-early-data",
4173 "-on-resume-read-with-unfinished-write",
4174 "-on-resume-shim-writes-first",
4175 },
4176 })
4177
4178 // Rejected unfinished writes are discarded (from the
4179 // perspective of the calling application) on 0-RTT
4180 // reject.
4181 tests = append(tests, testCase{
4182 testType: clientTest,
4183 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4184 config: Config{
4185 MaxVersion: VersionTLS13,
4186 MinVersion: VersionTLS13,
4187 MaxEarlyDataSize: 16384,
4188 },
4189 resumeConfig: &Config{
4190 MaxVersion: VersionTLS13,
4191 MinVersion: VersionTLS13,
4192 MaxEarlyDataSize: 16384,
4193 Bugs: ProtocolBugs{
4194 AlwaysRejectEarlyData: true,
4195 },
4196 },
4197 resumeSession: true,
4198 flags: []string{
4199 "-enable-early-data",
4200 "-expect-early-data-info",
4201 "-expect-reject-early-data",
4202 "-on-resume-read-with-unfinished-write",
4203 "-on-resume-shim-writes-first",
4204 },
4205 })
4206 }
4207
4208 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004209 testType: serverTest,
4210 name: "TLS13-EarlyData-Server",
4211 config: Config{
4212 MaxVersion: VersionTLS13,
4213 MinVersion: VersionTLS13,
4214 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004215 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004216 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004217 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004218 },
4219 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004220 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004221 resumeSession: true,
4222 flags: []string{
4223 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004224 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004225 },
4226 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004227
4228 tests = append(tests, testCase{
4229 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004230 name: "TLS13Experiment-EarlyData-Server",
4231 config: Config{
4232 MaxVersion: VersionTLS13,
4233 MinVersion: VersionTLS13,
4234 TLS13Variant: TLS13Experiment,
4235 Bugs: ProtocolBugs{
4236 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4237 ExpectEarlyDataAccepted: true,
4238 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4239 },
4240 },
4241 messageCount: 2,
4242 resumeSession: true,
4243 flags: []string{
4244 "-enable-early-data",
4245 "-expect-accept-early-data",
4246 "-tls13-variant", "1",
4247 },
4248 })
4249
4250 tests = append(tests, testCase{
4251 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004252 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4253 config: Config{
4254 MaxVersion: VersionTLS13,
4255 MinVersion: VersionTLS13,
4256 TLS13Variant: TLS13RecordTypeExperiment,
4257 Bugs: ProtocolBugs{
4258 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4259 ExpectEarlyDataAccepted: true,
4260 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4261 },
4262 },
4263 messageCount: 2,
4264 resumeSession: true,
4265 flags: []string{
4266 "-enable-early-data",
4267 "-expect-accept-early-data",
4268 "-tls13-variant", "2",
4269 },
4270 })
4271
4272 tests = append(tests, testCase{
4273 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004274 name: "TLS13-MaxEarlyData-Server",
4275 config: Config{
4276 MaxVersion: VersionTLS13,
4277 MinVersion: VersionTLS13,
4278 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004279 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004280 ExpectEarlyDataAccepted: true,
4281 },
4282 },
4283 messageCount: 2,
4284 resumeSession: true,
4285 flags: []string{
4286 "-enable-early-data",
4287 "-expect-accept-early-data",
4288 },
4289 shouldFail: true,
4290 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4291 })
David Benjamine73c7f42016-08-17 00:29:33 -04004292 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004293
David Benjamin760b1dd2015-05-15 23:33:48 -04004294 // TLS client auth.
4295 tests = append(tests, testCase{
4296 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004297 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004298 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004299 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004300 ClientAuth: RequestClientCert,
4301 },
4302 })
4303 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004304 testType: serverTest,
4305 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004306 config: Config{
4307 MaxVersion: VersionTLS12,
4308 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004309 // Setting SSL_VERIFY_PEER allows anonymous clients.
4310 flags: []string{"-verify-peer"},
4311 })
David Benjamin582ba042016-07-07 12:33:25 -07004312 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004313 tests = append(tests, testCase{
4314 testType: clientTest,
4315 name: "ClientAuth-NoCertificate-Client-SSL3",
4316 config: Config{
4317 MaxVersion: VersionSSL30,
4318 ClientAuth: RequestClientCert,
4319 },
4320 })
4321 tests = append(tests, testCase{
4322 testType: serverTest,
4323 name: "ClientAuth-NoCertificate-Server-SSL3",
4324 config: Config{
4325 MaxVersion: VersionSSL30,
4326 },
4327 // Setting SSL_VERIFY_PEER allows anonymous clients.
4328 flags: []string{"-verify-peer"},
4329 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004330 tests = append(tests, testCase{
4331 testType: clientTest,
4332 name: "ClientAuth-NoCertificate-Client-TLS13",
4333 config: Config{
4334 MaxVersion: VersionTLS13,
4335 ClientAuth: RequestClientCert,
4336 },
4337 })
4338 tests = append(tests, testCase{
4339 testType: serverTest,
4340 name: "ClientAuth-NoCertificate-Server-TLS13",
4341 config: Config{
4342 MaxVersion: VersionTLS13,
4343 },
4344 // Setting SSL_VERIFY_PEER allows anonymous clients.
4345 flags: []string{"-verify-peer"},
4346 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004347 }
4348 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004349 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004350 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004351 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004352 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004353 ClientAuth: RequireAnyClientCert,
4354 },
4355 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004356 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4357 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004358 },
4359 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004360 tests = append(tests, testCase{
4361 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004362 name: "ClientAuth-RSA-Client-TLS13",
4363 config: Config{
4364 MaxVersion: VersionTLS13,
4365 ClientAuth: RequireAnyClientCert,
4366 },
4367 flags: []string{
4368 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4369 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4370 },
4371 })
4372 tests = append(tests, testCase{
4373 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004374 name: "ClientAuth-ECDSA-Client",
4375 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004376 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004377 ClientAuth: RequireAnyClientCert,
4378 },
4379 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004380 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4381 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004382 },
4383 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004384 tests = append(tests, testCase{
4385 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004386 name: "ClientAuth-ECDSA-Client-TLS13",
4387 config: Config{
4388 MaxVersion: VersionTLS13,
4389 ClientAuth: RequireAnyClientCert,
4390 },
4391 flags: []string{
4392 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4393 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4394 },
4395 })
4396 tests = append(tests, testCase{
4397 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004398 name: "ClientAuth-NoCertificate-OldCallback",
4399 config: Config{
4400 MaxVersion: VersionTLS12,
4401 ClientAuth: RequestClientCert,
4402 },
4403 flags: []string{"-use-old-client-cert-callback"},
4404 })
4405 tests = append(tests, testCase{
4406 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004407 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4408 config: Config{
4409 MaxVersion: VersionTLS13,
4410 ClientAuth: RequestClientCert,
4411 },
4412 flags: []string{"-use-old-client-cert-callback"},
4413 })
4414 tests = append(tests, testCase{
4415 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004416 name: "ClientAuth-OldCallback",
4417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004418 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004419 ClientAuth: RequireAnyClientCert,
4420 },
4421 flags: []string{
4422 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4423 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4424 "-use-old-client-cert-callback",
4425 },
4426 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004427 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004428 testType: clientTest,
4429 name: "ClientAuth-OldCallback-TLS13",
4430 config: Config{
4431 MaxVersion: VersionTLS13,
4432 ClientAuth: RequireAnyClientCert,
4433 },
4434 flags: []string{
4435 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4436 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4437 "-use-old-client-cert-callback",
4438 },
4439 })
4440 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004441 testType: serverTest,
4442 name: "ClientAuth-Server",
4443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004444 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004445 Certificates: []Certificate{rsaCertificate},
4446 },
4447 flags: []string{"-require-any-client-certificate"},
4448 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004449 tests = append(tests, testCase{
4450 testType: serverTest,
4451 name: "ClientAuth-Server-TLS13",
4452 config: Config{
4453 MaxVersion: VersionTLS13,
4454 Certificates: []Certificate{rsaCertificate},
4455 },
4456 flags: []string{"-require-any-client-certificate"},
4457 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004458
David Benjamin4c3ddf72016-06-29 18:13:53 -04004459 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 tests = append(tests, testCase{
4461 testType: serverTest,
4462 name: "Basic-Server-RSA",
4463 config: Config{
4464 MaxVersion: VersionTLS12,
4465 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4466 },
4467 flags: []string{
4468 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4469 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4470 },
4471 })
4472 tests = append(tests, testCase{
4473 testType: serverTest,
4474 name: "Basic-Server-ECDHE-RSA",
4475 config: Config{
4476 MaxVersion: VersionTLS12,
4477 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4478 },
4479 flags: []string{
4480 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4481 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4482 },
4483 })
4484 tests = append(tests, testCase{
4485 testType: serverTest,
4486 name: "Basic-Server-ECDHE-ECDSA",
4487 config: Config{
4488 MaxVersion: VersionTLS12,
4489 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4490 },
4491 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004492 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4493 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004494 },
4495 })
David Benjamin69522112017-03-28 15:38:29 -05004496 tests = append(tests, testCase{
4497 testType: serverTest,
4498 name: "Basic-Server-Ed25519",
4499 config: Config{
4500 MaxVersion: VersionTLS12,
4501 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4502 },
4503 flags: []string{
4504 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4505 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4506 "-enable-ed25519",
4507 },
4508 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004509
David Benjamin760b1dd2015-05-15 23:33:48 -04004510 // No session ticket support; server doesn't send NewSessionTicket.
4511 tests = append(tests, testCase{
4512 name: "SessionTicketsDisabled-Client",
4513 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004514 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004515 SessionTicketsDisabled: true,
4516 },
4517 })
4518 tests = append(tests, testCase{
4519 testType: serverTest,
4520 name: "SessionTicketsDisabled-Server",
4521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004522 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004523 SessionTicketsDisabled: true,
4524 },
4525 })
4526
4527 // Skip ServerKeyExchange in PSK key exchange if there's no
4528 // identity hint.
4529 tests = append(tests, testCase{
4530 name: "EmptyPSKHint-Client",
4531 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004532 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004533 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4534 PreSharedKey: []byte("secret"),
4535 },
4536 flags: []string{"-psk", "secret"},
4537 })
4538 tests = append(tests, testCase{
4539 testType: serverTest,
4540 name: "EmptyPSKHint-Server",
4541 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004542 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004543 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4544 PreSharedKey: []byte("secret"),
4545 },
4546 flags: []string{"-psk", "secret"},
4547 })
4548
David Benjamin4c3ddf72016-06-29 18:13:53 -04004549 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004550 tests = append(tests, testCase{
4551 testType: clientTest,
4552 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004553 config: Config{
4554 MaxVersion: VersionTLS12,
4555 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004556 flags: []string{
4557 "-enable-ocsp-stapling",
4558 "-expect-ocsp-response",
4559 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004560 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004561 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004562 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004563 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004564 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004565 testType: serverTest,
4566 name: "OCSPStapling-Server",
4567 config: Config{
4568 MaxVersion: VersionTLS12,
4569 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004570 expectedOCSPResponse: testOCSPResponse,
4571 flags: []string{
4572 "-ocsp-response",
4573 base64.StdEncoding.EncodeToString(testOCSPResponse),
4574 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004575 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004576 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004577 tests = append(tests, testCase{
4578 testType: clientTest,
4579 name: "OCSPStapling-Client-TLS13",
4580 config: Config{
4581 MaxVersion: VersionTLS13,
4582 },
4583 flags: []string{
4584 "-enable-ocsp-stapling",
4585 "-expect-ocsp-response",
4586 base64.StdEncoding.EncodeToString(testOCSPResponse),
4587 "-verify-peer",
4588 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004589 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004590 })
4591 tests = append(tests, testCase{
4592 testType: serverTest,
4593 name: "OCSPStapling-Server-TLS13",
4594 config: Config{
4595 MaxVersion: VersionTLS13,
4596 },
4597 expectedOCSPResponse: testOCSPResponse,
4598 flags: []string{
4599 "-ocsp-response",
4600 base64.StdEncoding.EncodeToString(testOCSPResponse),
4601 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004602 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004603 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004604
David Benjamin4c3ddf72016-06-29 18:13:53 -04004605 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004606 for _, vers := range tlsVersions {
4607 if config.protocol == dtls && !vers.hasDTLS {
4608 continue
4609 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004610 for _, useCustomCallback := range []bool{false, true} {
4611 for _, testType := range []testType{clientTest, serverTest} {
4612 suffix := "-Client"
4613 if testType == serverTest {
4614 suffix = "-Server"
4615 }
4616 suffix += "-" + vers.name
4617 if useCustomCallback {
4618 suffix += "-CustomCallback"
4619 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004620
David Benjamin3a1dd462017-07-11 16:13:10 -04004621 flags := []string{"-verify-peer"}
4622 if testType == serverTest {
4623 flags = append(flags, "-require-any-client-certificate")
4624 }
4625 if useCustomCallback {
4626 flags = append(flags, "-use-custom-verify-callback")
4627 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004628
David Benjamin3a1dd462017-07-11 16:13:10 -04004629 tests = append(tests, testCase{
4630 testType: testType,
4631 name: "CertificateVerificationSucceed" + suffix,
4632 config: Config{
4633 MaxVersion: vers.version,
4634 Certificates: []Certificate{rsaCertificate},
4635 },
4636 tls13Variant: vers.tls13Variant,
4637 flags: append([]string{"-expect-verify-result"}, flags...),
4638 resumeSession: true,
4639 })
4640 tests = append(tests, testCase{
4641 testType: testType,
4642 name: "CertificateVerificationFail" + suffix,
4643 config: Config{
4644 MaxVersion: vers.version,
4645 Certificates: []Certificate{rsaCertificate},
4646 },
4647 tls13Variant: vers.tls13Variant,
4648 flags: append([]string{"-verify-fail"}, flags...),
4649 shouldFail: true,
4650 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4651 })
4652 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004653 }
4654
4655 // By default, the client is in a soft fail mode where the peer
4656 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004657 tests = append(tests, testCase{
4658 testType: clientTest,
4659 name: "CertificateVerificationSoftFail-" + vers.name,
4660 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004661 MaxVersion: vers.version,
4662 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004663 },
David Benjamina5022392017-07-10 17:40:39 -04004664 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004665 flags: []string{
4666 "-verify-fail",
4667 "-expect-verify-result",
4668 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004669 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004670 })
4671 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004672
David Benjamin1d4f4c02016-07-26 18:03:08 -04004673 tests = append(tests, testCase{
4674 name: "ShimSendAlert",
4675 flags: []string{"-send-alert"},
4676 shimWritesFirst: true,
4677 shouldFail: true,
4678 expectedLocalError: "remote error: decompression failure",
4679 })
4680
David Benjamin582ba042016-07-07 12:33:25 -07004681 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004682 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004683 name: "Renegotiate-Client",
4684 config: Config{
4685 MaxVersion: VersionTLS12,
4686 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004687 renegotiate: 1,
4688 flags: []string{
4689 "-renegotiate-freely",
4690 "-expect-total-renegotiations", "1",
4691 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004692 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004693
David Benjamin47921102016-07-28 11:29:18 -04004694 tests = append(tests, testCase{
4695 name: "SendHalfHelloRequest",
4696 config: Config{
4697 MaxVersion: VersionTLS12,
4698 Bugs: ProtocolBugs{
4699 PackHelloRequestWithFinished: config.packHandshakeFlight,
4700 },
4701 },
4702 sendHalfHelloRequest: true,
4703 flags: []string{"-renegotiate-ignore"},
4704 shouldFail: true,
4705 expectedError: ":UNEXPECTED_RECORD:",
4706 })
4707
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 // NPN on client and server; results in post-handshake message.
4709 tests = append(tests, testCase{
4710 name: "NPN-Client",
4711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004712 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004713 NextProtos: []string{"foo"},
4714 },
4715 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004716 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004717 expectedNextProto: "foo",
4718 expectedNextProtoType: npn,
4719 })
4720 tests = append(tests, testCase{
4721 testType: serverTest,
4722 name: "NPN-Server",
4723 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004724 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004725 NextProtos: []string{"bar"},
4726 },
4727 flags: []string{
4728 "-advertise-npn", "\x03foo\x03bar\x03baz",
4729 "-expect-next-proto", "bar",
4730 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004731 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004732 expectedNextProto: "bar",
4733 expectedNextProtoType: npn,
4734 })
4735
4736 // TODO(davidben): Add tests for when False Start doesn't trigger.
4737
4738 // Client does False Start and negotiates NPN.
4739 tests = append(tests, testCase{
4740 name: "FalseStart",
4741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004742 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4744 NextProtos: []string{"foo"},
4745 Bugs: ProtocolBugs{
4746 ExpectFalseStart: true,
4747 },
4748 },
4749 flags: []string{
4750 "-false-start",
4751 "-select-next-proto", "foo",
4752 },
4753 shimWritesFirst: true,
4754 resumeSession: true,
4755 })
4756
4757 // Client does False Start and negotiates ALPN.
4758 tests = append(tests, testCase{
4759 name: "FalseStart-ALPN",
4760 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004761 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004762 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4763 NextProtos: []string{"foo"},
4764 Bugs: ProtocolBugs{
4765 ExpectFalseStart: true,
4766 },
4767 },
4768 flags: []string{
4769 "-false-start",
4770 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004771 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004772 },
4773 shimWritesFirst: true,
4774 resumeSession: true,
4775 })
4776
David Benjamin760b1dd2015-05-15 23:33:48 -04004777 // False Start without session tickets.
4778 tests = append(tests, testCase{
4779 name: "FalseStart-SessionTicketsDisabled",
4780 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004781 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004782 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4783 NextProtos: []string{"foo"},
4784 SessionTicketsDisabled: true,
4785 Bugs: ProtocolBugs{
4786 ExpectFalseStart: true,
4787 },
4788 },
4789 flags: []string{
4790 "-false-start",
4791 "-select-next-proto", "foo",
4792 },
4793 shimWritesFirst: true,
4794 })
4795
4796 // Server parses a V2ClientHello.
4797 tests = append(tests, testCase{
4798 testType: serverTest,
4799 name: "SendV2ClientHello",
4800 config: Config{
4801 // Choose a cipher suite that does not involve
4802 // elliptic curves, so no extensions are
4803 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004804 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004805 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004806 Bugs: ProtocolBugs{
4807 SendV2ClientHello: true,
4808 },
4809 },
David Benjamin78b8b992017-08-01 18:38:41 -04004810 flags: []string{
4811 "-expect-msg-callback",
4812 `read v2clienthello
4813write hs 2
4814write hs 11
4815write hs 14
4816read hs 16
4817read ccs
4818read hs 20
4819write ccs
4820write hs 20
4821read alert 1 0
4822`,
4823 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004824 })
4825
Nick Harper60a85cb2016-09-23 16:25:11 -07004826 // Test Channel ID
4827 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004828 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004829 continue
4830 }
4831 // Client sends a Channel ID.
4832 tests = append(tests, testCase{
4833 name: "ChannelID-Client-" + ver.name,
4834 config: Config{
4835 MaxVersion: ver.version,
4836 RequestChannelID: true,
4837 },
David Benjamina5022392017-07-10 17:40:39 -04004838 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004839 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4840 resumeSession: true,
4841 expectChannelID: true,
4842 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004843
Nick Harper60a85cb2016-09-23 16:25:11 -07004844 // Server accepts a Channel ID.
4845 tests = append(tests, testCase{
4846 testType: serverTest,
4847 name: "ChannelID-Server-" + ver.name,
4848 config: Config{
4849 MaxVersion: ver.version,
4850 ChannelID: channelIDKey,
4851 },
David Benjamina5022392017-07-10 17:40:39 -04004852 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004853 flags: []string{
4854 "-expect-channel-id",
4855 base64.StdEncoding.EncodeToString(channelIDBytes),
4856 },
4857 resumeSession: true,
4858 expectChannelID: true,
4859 })
4860
4861 tests = append(tests, testCase{
4862 testType: serverTest,
4863 name: "InvalidChannelIDSignature-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 ChannelID: channelIDKey,
4867 Bugs: ProtocolBugs{
4868 InvalidChannelIDSignature: true,
4869 },
4870 },
David Benjamina5022392017-07-10 17:40:39 -04004871 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004872 flags: []string{"-enable-channel-id"},
4873 shouldFail: true,
4874 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4875 })
David Benjamin634f4752017-07-01 11:08:41 -04004876
4877 if ver.version < VersionTLS13 {
4878 // Channel ID requires ECDHE ciphers.
4879 tests = append(tests, testCase{
4880 testType: serverTest,
4881 name: "ChannelID-NoECDHE-" + ver.name,
4882 config: Config{
4883 MaxVersion: ver.version,
4884 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4885 ChannelID: channelIDKey,
4886 },
4887 expectChannelID: false,
4888 flags: []string{"-enable-channel-id"},
4889 })
4890
4891 // Sanity-check setting expectChannelID false works.
4892 tests = append(tests, testCase{
4893 testType: serverTest,
4894 name: "ChannelID-ECDHE-" + ver.name,
4895 config: Config{
4896 MaxVersion: ver.version,
4897 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4898 ChannelID: channelIDKey,
4899 },
4900 expectChannelID: false,
4901 flags: []string{"-enable-channel-id"},
4902 shouldFail: true,
4903 expectedLocalError: "channel ID unexpectedly negotiated",
4904 })
4905 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004906 }
David Benjamin30789da2015-08-29 22:56:45 -04004907
David Benjaminf8fcdf32016-06-08 15:56:13 -04004908 // Channel ID and NPN at the same time, to ensure their relative
4909 // ordering is correct.
4910 tests = append(tests, testCase{
4911 name: "ChannelID-NPN-Client",
4912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004913 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004914 RequestChannelID: true,
4915 NextProtos: []string{"foo"},
4916 },
4917 flags: []string{
4918 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4919 "-select-next-proto", "foo",
4920 },
4921 resumeSession: true,
4922 expectChannelID: true,
4923 expectedNextProto: "foo",
4924 expectedNextProtoType: npn,
4925 })
4926 tests = append(tests, testCase{
4927 testType: serverTest,
4928 name: "ChannelID-NPN-Server",
4929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004930 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004931 ChannelID: channelIDKey,
4932 NextProtos: []string{"bar"},
4933 },
4934 flags: []string{
4935 "-expect-channel-id",
4936 base64.StdEncoding.EncodeToString(channelIDBytes),
4937 "-advertise-npn", "\x03foo\x03bar\x03baz",
4938 "-expect-next-proto", "bar",
4939 },
4940 resumeSession: true,
4941 expectChannelID: true,
4942 expectedNextProto: "bar",
4943 expectedNextProtoType: npn,
4944 })
4945
David Benjamin30789da2015-08-29 22:56:45 -04004946 // Bidirectional shutdown with the runner initiating.
4947 tests = append(tests, testCase{
4948 name: "Shutdown-Runner",
4949 config: Config{
4950 Bugs: ProtocolBugs{
4951 ExpectCloseNotify: true,
4952 },
4953 },
4954 flags: []string{"-check-close-notify"},
4955 })
4956
David Benjamine3843d42017-03-25 18:00:56 -05004957 if !config.implicitHandshake {
4958 // Bidirectional shutdown with the shim initiating. The runner,
4959 // in the meantime, sends garbage before the close_notify which
4960 // the shim must ignore. This test is disabled under implicit
4961 // handshake tests because the shim never reads or writes.
4962 tests = append(tests, testCase{
4963 name: "Shutdown-Shim",
4964 config: Config{
4965 MaxVersion: VersionTLS12,
4966 Bugs: ProtocolBugs{
4967 ExpectCloseNotify: true,
4968 },
David Benjamin30789da2015-08-29 22:56:45 -04004969 },
David Benjamine3843d42017-03-25 18:00:56 -05004970 shimShutsDown: true,
4971 sendEmptyRecords: 1,
4972 sendWarningAlerts: 1,
4973 flags: []string{"-check-close-notify"},
4974 })
4975 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004976 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004977 // TODO(davidben): DTLS 1.3 will want a similar thing for
4978 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004979 tests = append(tests, testCase{
4980 name: "SkipHelloVerifyRequest",
4981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004982 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004983 Bugs: ProtocolBugs{
4984 SkipHelloVerifyRequest: true,
4985 },
4986 },
4987 })
4988 }
4989
David Benjamin760b1dd2015-05-15 23:33:48 -04004990 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004991 test.protocol = config.protocol
4992 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004993 test.name += "-DTLS"
4994 }
David Benjamin582ba042016-07-07 12:33:25 -07004995 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004996 test.name += "-Async"
4997 test.flags = append(test.flags, "-async")
4998 } else {
4999 test.name += "-Sync"
5000 }
David Benjamin582ba042016-07-07 12:33:25 -07005001 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005002 test.name += "-SplitHandshakeRecords"
5003 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005004 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005005 test.config.Bugs.MaxPacketLength = 256
5006 test.flags = append(test.flags, "-mtu", "256")
5007 }
5008 }
David Benjamin582ba042016-07-07 12:33:25 -07005009 if config.packHandshakeFlight {
5010 test.name += "-PackHandshakeFlight"
5011 test.config.Bugs.PackHandshakeFlight = true
5012 }
David Benjamine3843d42017-03-25 18:00:56 -05005013 if config.implicitHandshake {
5014 test.name += "-ImplicitHandshake"
5015 test.flags = append(test.flags, "-implicit-handshake")
5016 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005017 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005018 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005019}
5020
Adam Langley524e7172015-02-20 16:04:00 -08005021func addDDoSCallbackTests() {
5022 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005023 for _, resume := range []bool{false, true} {
5024 suffix := "Resume"
5025 if resume {
5026 suffix = "No" + suffix
5027 }
5028
5029 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005030 testType: serverTest,
5031 name: "Server-DDoS-OK-" + suffix,
5032 config: Config{
5033 MaxVersion: VersionTLS12,
5034 },
Adam Langley524e7172015-02-20 16:04:00 -08005035 flags: []string{"-install-ddos-callback"},
5036 resumeSession: resume,
5037 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005038 testCases = append(testCases, testCase{
5039 testType: serverTest,
5040 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5041 config: Config{
5042 MaxVersion: VersionTLS13,
5043 },
5044 flags: []string{"-install-ddos-callback"},
5045 resumeSession: resume,
5046 })
Adam Langley524e7172015-02-20 16:04:00 -08005047
5048 failFlag := "-fail-ddos-callback"
5049 if resume {
5050 failFlag = "-fail-second-ddos-callback"
5051 }
5052 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005053 testType: serverTest,
5054 name: "Server-DDoS-Reject-" + suffix,
5055 config: Config{
5056 MaxVersion: VersionTLS12,
5057 },
David Benjamin2c66e072016-09-16 15:58:00 -04005058 flags: []string{"-install-ddos-callback", failFlag},
5059 resumeSession: resume,
5060 shouldFail: true,
5061 expectedError: ":CONNECTION_REJECTED:",
5062 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005063 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005064 testCases = append(testCases, testCase{
5065 testType: serverTest,
5066 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5067 config: Config{
5068 MaxVersion: VersionTLS13,
5069 },
David Benjamin2c66e072016-09-16 15:58:00 -04005070 flags: []string{"-install-ddos-callback", failFlag},
5071 resumeSession: resume,
5072 shouldFail: true,
5073 expectedError: ":CONNECTION_REJECTED:",
5074 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005075 })
Adam Langley524e7172015-02-20 16:04:00 -08005076 }
5077}
5078
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005079func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005080 for _, protocol := range []protocol{tls, dtls} {
5081 for _, shimVers := range allVersions(protocol) {
5082 // Assemble flags to disable all newer versions on the shim.
5083 var flags []string
5084 for _, vers := range allVersions(protocol) {
5085 if vers.version > shimVers.version {
5086 flags = append(flags, vers.excludeFlag)
5087 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005088 }
Steven Valdez520e1222017-06-13 12:45:25 -04005089
5090 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5091
5092 if shimVers.tls13Variant != 0 {
5093 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5094 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5095 }
5096
5097 // Test configuring the runner's maximum version.
5098 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005099 expectedVersion := shimVers.version
5100 if runnerVers.version < shimVers.version {
5101 expectedVersion = runnerVers.version
5102 }
Steven Valdez520e1222017-06-13 12:45:25 -04005103 // When running and shim have different TLS 1.3 variants enabled,
5104 // shim clients are expected to fall back to TLS 1.2, while shim
5105 // servers support both variants when enabled when the experiment is
5106 // enabled.
5107 expectedServerVersion := expectedVersion
5108 expectedClientVersion := expectedVersion
5109 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5110 expectedClientVersion = VersionTLS12
5111 expectedServerVersion = VersionTLS12
5112 if shimVers.tls13Variant != TLS13Default {
5113 expectedServerVersion = VersionTLS13
5114 }
5115 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005116
David Benjamin8b8c0062014-11-23 02:47:52 -05005117 suffix := shimVers.name + "-" + runnerVers.name
5118 if protocol == dtls {
5119 suffix += "-DTLS"
5120 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005121
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005122 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005123 clientVers := shimVers.version
5124 if clientVers > VersionTLS10 {
5125 clientVers = VersionTLS10
5126 }
Steven Valdez520e1222017-06-13 12:45:25 -04005127 clientVers = recordVersionToWire(clientVers, protocol)
5128 serverVers := expectedServerVersion
5129 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005130 serverVers = VersionTLS10
5131 }
Steven Valdez520e1222017-06-13 12:45:25 -04005132 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005133
David Benjamin8b8c0062014-11-23 02:47:52 -05005134 testCases = append(testCases, testCase{
5135 protocol: protocol,
5136 testType: clientTest,
5137 name: "VersionNegotiation-Client-" + suffix,
5138 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005139 MaxVersion: runnerVers.version,
5140 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005141 Bugs: ProtocolBugs{
5142 ExpectInitialRecordVersion: clientVers,
5143 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005144 },
5145 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005146 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005147 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005148 testCases = append(testCases, testCase{
5149 protocol: protocol,
5150 testType: clientTest,
5151 name: "VersionNegotiation-Client2-" + suffix,
5152 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005153 MaxVersion: runnerVers.version,
5154 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005155 Bugs: ProtocolBugs{
5156 ExpectInitialRecordVersion: clientVers,
5157 },
5158 },
Steven Valdez520e1222017-06-13 12:45:25 -04005159 flags: flags2,
5160 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005161 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005162
5163 testCases = append(testCases, testCase{
5164 protocol: protocol,
5165 testType: serverTest,
5166 name: "VersionNegotiation-Server-" + suffix,
5167 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005168 MaxVersion: runnerVers.version,
5169 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005170 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005171 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005172 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005173 },
5174 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005175 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005176 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005177 testCases = append(testCases, testCase{
5178 protocol: protocol,
5179 testType: serverTest,
5180 name: "VersionNegotiation-Server2-" + suffix,
5181 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005182 MaxVersion: runnerVers.version,
5183 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005184 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005185 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005186 },
5187 },
Steven Valdez520e1222017-06-13 12:45:25 -04005188 flags: flags2,
5189 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005190 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005191 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005192 }
5193 }
David Benjamin95c69562016-06-29 18:15:03 -04005194
Steven Valdezfdd10992016-09-15 16:27:05 -04005195 // Test the version extension at all versions.
5196 for _, vers := range tlsVersions {
5197 protocols := []protocol{tls}
5198 if vers.hasDTLS {
5199 protocols = append(protocols, dtls)
5200 }
5201 for _, protocol := range protocols {
5202 suffix := vers.name
5203 if protocol == dtls {
5204 suffix += "-DTLS"
5205 }
5206
Steven Valdezfdd10992016-09-15 16:27:05 -04005207 testCases = append(testCases, testCase{
5208 protocol: protocol,
5209 testType: serverTest,
5210 name: "VersionNegotiationExtension-" + suffix,
5211 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005212 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005213 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005214 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005215 },
5216 },
5217 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005218 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005219 })
5220 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005221 }
5222
5223 // If all versions are unknown, negotiation fails.
5224 testCases = append(testCases, testCase{
5225 testType: serverTest,
5226 name: "NoSupportedVersions",
5227 config: Config{
5228 Bugs: ProtocolBugs{
5229 SendSupportedVersions: []uint16{0x1111},
5230 },
5231 },
5232 shouldFail: true,
5233 expectedError: ":UNSUPPORTED_PROTOCOL:",
5234 })
5235 testCases = append(testCases, testCase{
5236 protocol: dtls,
5237 testType: serverTest,
5238 name: "NoSupportedVersions-DTLS",
5239 config: Config{
5240 Bugs: ProtocolBugs{
5241 SendSupportedVersions: []uint16{0x1111},
5242 },
5243 },
5244 shouldFail: true,
5245 expectedError: ":UNSUPPORTED_PROTOCOL:",
5246 })
5247
5248 testCases = append(testCases, testCase{
5249 testType: serverTest,
5250 name: "ClientHelloVersionTooHigh",
5251 config: Config{
5252 MaxVersion: VersionTLS13,
5253 Bugs: ProtocolBugs{
5254 SendClientVersion: 0x0304,
5255 OmitSupportedVersions: true,
5256 },
5257 },
5258 expectedVersion: VersionTLS12,
5259 })
5260
5261 testCases = append(testCases, testCase{
5262 testType: serverTest,
5263 name: "ConflictingVersionNegotiation",
5264 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005265 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005266 SendClientVersion: VersionTLS12,
5267 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005268 },
5269 },
David Benjaminad75a662016-09-30 15:42:59 -04005270 // The extension takes precedence over the ClientHello version.
5271 expectedVersion: VersionTLS11,
5272 })
5273
5274 testCases = append(testCases, testCase{
5275 testType: serverTest,
5276 name: "ConflictingVersionNegotiation-2",
5277 config: Config{
5278 Bugs: ProtocolBugs{
5279 SendClientVersion: VersionTLS11,
5280 SendSupportedVersions: []uint16{VersionTLS12},
5281 },
5282 },
5283 // The extension takes precedence over the ClientHello version.
5284 expectedVersion: VersionTLS12,
5285 })
5286
5287 testCases = append(testCases, testCase{
5288 testType: serverTest,
5289 name: "RejectFinalTLS13",
5290 config: Config{
5291 Bugs: ProtocolBugs{
5292 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5293 },
5294 },
5295 // We currently implement a draft TLS 1.3 version. Ensure that
5296 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005297 expectedVersion: VersionTLS12,
5298 })
5299
Steven Valdez038da9b2017-07-10 12:57:25 -04005300 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5301 // the ServerHello.
5302 testCases = append(testCases, testCase{
5303 testType: clientTest,
5304 name: "SupportedVersionSelection-TLS12",
5305 config: Config{
5306 MaxVersion: VersionTLS12,
5307 Bugs: ProtocolBugs{
5308 SendServerSupportedExtensionVersion: VersionTLS12,
5309 },
5310 },
5311 shouldFail: true,
5312 expectedError: ":UNEXPECTED_EXTENSION:",
5313 })
5314
5315 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5316 // supported_versions extension in the ServerHello.
5317 testCases = append(testCases, testCase{
5318 testType: clientTest,
5319 name: "SupportedVersionSelection-TLS13",
5320 config: Config{
5321 MaxVersion: VersionTLS13,
5322 Bugs: ProtocolBugs{
5323 SendServerSupportedExtensionVersion: tls13DraftVersion,
5324 },
5325 },
5326 shouldFail: true,
5327 expectedError: ":UNEXPECTED_EXTENSION:",
5328 })
5329
Brian Smithf85d3232016-10-28 10:34:06 -10005330 // Test that the maximum version is selected regardless of the
5331 // client-sent order.
5332 testCases = append(testCases, testCase{
5333 testType: serverTest,
5334 name: "IgnoreClientVersionOrder",
5335 config: Config{
5336 Bugs: ProtocolBugs{
5337 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5338 },
5339 },
5340 expectedVersion: VersionTLS13,
5341 })
5342
David Benjamin95c69562016-06-29 18:15:03 -04005343 // Test for version tolerance.
5344 testCases = append(testCases, testCase{
5345 testType: serverTest,
5346 name: "MinorVersionTolerance",
5347 config: Config{
5348 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005349 SendClientVersion: 0x03ff,
5350 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005351 },
5352 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005353 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005354 })
5355 testCases = append(testCases, testCase{
5356 testType: serverTest,
5357 name: "MajorVersionTolerance",
5358 config: Config{
5359 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005360 SendClientVersion: 0x0400,
5361 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005362 },
5363 },
David Benjaminad75a662016-09-30 15:42:59 -04005364 // TLS 1.3 must be negotiated with the supported_versions
5365 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005366 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005367 })
David Benjaminad75a662016-09-30 15:42:59 -04005368 testCases = append(testCases, testCase{
5369 testType: serverTest,
5370 name: "VersionTolerance-TLS13",
5371 config: Config{
5372 Bugs: ProtocolBugs{
5373 // Although TLS 1.3 does not use
5374 // ClientHello.version, it still tolerates high
5375 // values there.
5376 SendClientVersion: 0x0400,
5377 },
5378 },
5379 expectedVersion: VersionTLS13,
5380 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005381
David Benjamin95c69562016-06-29 18:15:03 -04005382 testCases = append(testCases, testCase{
5383 protocol: dtls,
5384 testType: serverTest,
5385 name: "MinorVersionTolerance-DTLS",
5386 config: Config{
5387 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005388 SendClientVersion: 0xfe00,
5389 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005390 },
5391 },
5392 expectedVersion: VersionTLS12,
5393 })
5394 testCases = append(testCases, testCase{
5395 protocol: dtls,
5396 testType: serverTest,
5397 name: "MajorVersionTolerance-DTLS",
5398 config: Config{
5399 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005400 SendClientVersion: 0xfdff,
5401 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005402 },
5403 },
5404 expectedVersion: VersionTLS12,
5405 })
5406
5407 // Test that versions below 3.0 are rejected.
5408 testCases = append(testCases, testCase{
5409 testType: serverTest,
5410 name: "VersionTooLow",
5411 config: Config{
5412 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005413 SendClientVersion: 0x0200,
5414 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005415 },
5416 },
5417 shouldFail: true,
5418 expectedError: ":UNSUPPORTED_PROTOCOL:",
5419 })
5420 testCases = append(testCases, testCase{
5421 protocol: dtls,
5422 testType: serverTest,
5423 name: "VersionTooLow-DTLS",
5424 config: Config{
5425 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005426 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005427 },
5428 },
5429 shouldFail: true,
5430 expectedError: ":UNSUPPORTED_PROTOCOL:",
5431 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005432
David Benjamin2dc02042016-09-19 19:57:37 -04005433 testCases = append(testCases, testCase{
5434 name: "ServerBogusVersion",
5435 config: Config{
5436 Bugs: ProtocolBugs{
5437 SendServerHelloVersion: 0x1234,
5438 },
5439 },
5440 shouldFail: true,
5441 expectedError: ":UNSUPPORTED_PROTOCOL:",
5442 })
5443
David Benjamin1f61f0d2016-07-10 12:20:35 -04005444 // Test TLS 1.3's downgrade signal.
5445 testCases = append(testCases, testCase{
5446 name: "Downgrade-TLS12-Client",
5447 config: Config{
5448 Bugs: ProtocolBugs{
5449 NegotiateVersion: VersionTLS12,
5450 },
5451 },
David Benjamin592b5322016-09-30 15:15:01 -04005452 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005453 // TODO(davidben): This test should fail once TLS 1.3 is final
5454 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005455 })
5456 testCases = append(testCases, testCase{
5457 testType: serverTest,
5458 name: "Downgrade-TLS12-Server",
5459 config: Config{
5460 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005461 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005462 },
5463 },
David Benjamin592b5322016-09-30 15:15:01 -04005464 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005465 // TODO(davidben): This test should fail once TLS 1.3 is final
5466 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005467 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005468}
5469
David Benjaminaccb4542014-12-12 23:44:33 -05005470func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005471 for _, protocol := range []protocol{tls, dtls} {
5472 for _, shimVers := range allVersions(protocol) {
5473 // Assemble flags to disable all older versions on the shim.
5474 var flags []string
5475 for _, vers := range allVersions(protocol) {
5476 if vers.version < shimVers.version {
5477 flags = append(flags, vers.excludeFlag)
5478 }
David Benjaminaccb4542014-12-12 23:44:33 -05005479 }
Steven Valdez520e1222017-06-13 12:45:25 -04005480
5481 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5482
5483 if shimVers.tls13Variant != 0 {
5484 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5485 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5486 }
5487
5488 for _, runnerVers := range allVersions(protocol) {
5489 // Different TLS 1.3 variants are incompatible with each other and don't
5490 // produce consistent minimum versions.
5491 //
5492 // TODO(davidben): Fold these tests (the main value is in the
5493 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5494 // on intended shim behavior, not the shim + runner combination.
5495 if shimVers.tls13Variant != runnerVers.tls13Variant {
5496 continue
5497 }
5498
David Benjaminaccb4542014-12-12 23:44:33 -05005499 suffix := shimVers.name + "-" + runnerVers.name
5500 if protocol == dtls {
5501 suffix += "-DTLS"
5502 }
David Benjaminaccb4542014-12-12 23:44:33 -05005503
David Benjaminaccb4542014-12-12 23:44:33 -05005504 var expectedVersion uint16
5505 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005506 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005507 if runnerVers.version >= shimVers.version {
5508 expectedVersion = runnerVers.version
5509 } else {
5510 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005511 expectedError = ":UNSUPPORTED_PROTOCOL:"
5512 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005513 }
5514
5515 testCases = append(testCases, testCase{
5516 protocol: protocol,
5517 testType: clientTest,
5518 name: "MinimumVersion-Client-" + suffix,
5519 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005520 MaxVersion: runnerVers.version,
5521 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005522 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005523 // Ensure the server does not decline to
5524 // select a version (versions extension) or
5525 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005526 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005527 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005528 },
David Benjaminaccb4542014-12-12 23:44:33 -05005529 },
David Benjamin87909c02014-12-13 01:55:01 -05005530 flags: flags,
5531 expectedVersion: expectedVersion,
5532 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005533 expectedError: expectedError,
5534 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005535 })
5536 testCases = append(testCases, testCase{
5537 protocol: protocol,
5538 testType: clientTest,
5539 name: "MinimumVersion-Client2-" + suffix,
5540 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005541 MaxVersion: runnerVers.version,
5542 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005543 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005544 // Ensure the server does not decline to
5545 // select a version (versions extension) or
5546 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005547 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005548 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005549 },
David Benjaminaccb4542014-12-12 23:44:33 -05005550 },
Steven Valdez520e1222017-06-13 12:45:25 -04005551 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005552 expectedVersion: expectedVersion,
5553 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005554 expectedError: expectedError,
5555 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005556 })
5557
5558 testCases = append(testCases, testCase{
5559 protocol: protocol,
5560 testType: serverTest,
5561 name: "MinimumVersion-Server-" + suffix,
5562 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005563 MaxVersion: runnerVers.version,
5564 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005565 },
David Benjamin87909c02014-12-13 01:55:01 -05005566 flags: flags,
5567 expectedVersion: expectedVersion,
5568 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005569 expectedError: expectedError,
5570 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005571 })
5572 testCases = append(testCases, testCase{
5573 protocol: protocol,
5574 testType: serverTest,
5575 name: "MinimumVersion-Server2-" + suffix,
5576 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005577 MaxVersion: runnerVers.version,
5578 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005579 },
Steven Valdez520e1222017-06-13 12:45:25 -04005580 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005581 expectedVersion: expectedVersion,
5582 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005583 expectedError: expectedError,
5584 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005585 })
5586 }
5587 }
5588 }
5589}
5590
David Benjamine78bfde2014-09-06 12:45:15 -04005591func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005592 // TODO(davidben): Extensions, where applicable, all move their server
5593 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5594 // tests for both. Also test interaction with 0-RTT when implemented.
5595
David Benjamin97d17d92016-07-14 16:12:00 -04005596 // Repeat extensions tests all versions except SSL 3.0.
5597 for _, ver := range tlsVersions {
5598 if ver.version == VersionSSL30 {
5599 continue
5600 }
5601
David Benjamin97d17d92016-07-14 16:12:00 -04005602 // Test that duplicate extensions are rejected.
5603 testCases = append(testCases, testCase{
5604 testType: clientTest,
5605 name: "DuplicateExtensionClient-" + ver.name,
5606 config: Config{
5607 MaxVersion: ver.version,
5608 Bugs: ProtocolBugs{
5609 DuplicateExtension: true,
5610 },
David Benjamine78bfde2014-09-06 12:45:15 -04005611 },
David Benjamina5022392017-07-10 17:40:39 -04005612 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005613 shouldFail: true,
5614 expectedLocalError: "remote error: error decoding message",
5615 })
5616 testCases = append(testCases, testCase{
5617 testType: serverTest,
5618 name: "DuplicateExtensionServer-" + ver.name,
5619 config: Config{
5620 MaxVersion: ver.version,
5621 Bugs: ProtocolBugs{
5622 DuplicateExtension: true,
5623 },
David Benjamine78bfde2014-09-06 12:45:15 -04005624 },
David Benjamina5022392017-07-10 17:40:39 -04005625 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005626 shouldFail: true,
5627 expectedLocalError: "remote error: error decoding message",
5628 })
5629
5630 // Test SNI.
5631 testCases = append(testCases, testCase{
5632 testType: clientTest,
5633 name: "ServerNameExtensionClient-" + ver.name,
5634 config: Config{
5635 MaxVersion: ver.version,
5636 Bugs: ProtocolBugs{
5637 ExpectServerName: "example.com",
5638 },
David Benjamine78bfde2014-09-06 12:45:15 -04005639 },
David Benjamina5022392017-07-10 17:40:39 -04005640 tls13Variant: ver.tls13Variant,
5641 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005642 })
5643 testCases = append(testCases, testCase{
5644 testType: clientTest,
5645 name: "ServerNameExtensionClientMismatch-" + ver.name,
5646 config: Config{
5647 MaxVersion: ver.version,
5648 Bugs: ProtocolBugs{
5649 ExpectServerName: "mismatch.com",
5650 },
David Benjamine78bfde2014-09-06 12:45:15 -04005651 },
David Benjamin97d17d92016-07-14 16:12:00 -04005652 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005653 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005654 shouldFail: true,
5655 expectedLocalError: "tls: unexpected server name",
5656 })
5657 testCases = append(testCases, testCase{
5658 testType: clientTest,
5659 name: "ServerNameExtensionClientMissing-" + ver.name,
5660 config: Config{
5661 MaxVersion: ver.version,
5662 Bugs: ProtocolBugs{
5663 ExpectServerName: "missing.com",
5664 },
David Benjamine78bfde2014-09-06 12:45:15 -04005665 },
David Benjamina5022392017-07-10 17:40:39 -04005666 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005667 shouldFail: true,
5668 expectedLocalError: "tls: unexpected server name",
5669 })
5670 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005671 testType: clientTest,
5672 name: "TolerateServerNameAck-" + ver.name,
5673 config: Config{
5674 MaxVersion: ver.version,
5675 Bugs: ProtocolBugs{
5676 SendServerNameAck: true,
5677 },
5678 },
David Benjamina5022392017-07-10 17:40:39 -04005679 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005680 flags: []string{"-host-name", "example.com"},
5681 resumeSession: true,
5682 })
5683 testCases = append(testCases, testCase{
5684 testType: clientTest,
5685 name: "UnsolicitedServerNameAck-" + ver.name,
5686 config: Config{
5687 MaxVersion: ver.version,
5688 Bugs: ProtocolBugs{
5689 SendServerNameAck: true,
5690 },
5691 },
David Benjamina5022392017-07-10 17:40:39 -04005692 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005693 shouldFail: true,
5694 expectedError: ":UNEXPECTED_EXTENSION:",
5695 expectedLocalError: "remote error: unsupported extension",
5696 })
5697 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005698 testType: serverTest,
5699 name: "ServerNameExtensionServer-" + ver.name,
5700 config: Config{
5701 MaxVersion: ver.version,
5702 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005703 },
David Benjamina5022392017-07-10 17:40:39 -04005704 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005705 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005706 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005707 })
5708
5709 // Test ALPN.
5710 testCases = append(testCases, testCase{
5711 testType: clientTest,
5712 name: "ALPNClient-" + ver.name,
5713 config: Config{
5714 MaxVersion: ver.version,
5715 NextProtos: []string{"foo"},
5716 },
5717 flags: []string{
5718 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5719 "-expect-alpn", "foo",
5720 },
David Benjamina5022392017-07-10 17:40:39 -04005721 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005722 expectedNextProto: "foo",
5723 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005724 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005725 })
5726 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005727 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005728 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005729 config: Config{
5730 MaxVersion: ver.version,
5731 Bugs: ProtocolBugs{
5732 SendALPN: "baz",
5733 },
5734 },
5735 flags: []string{
5736 "-advertise-alpn", "\x03foo\x03bar",
5737 },
David Benjamina5022392017-07-10 17:40:39 -04005738 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005739 shouldFail: true,
5740 expectedError: ":INVALID_ALPN_PROTOCOL:",
5741 expectedLocalError: "remote error: illegal parameter",
5742 })
5743 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005744 testType: clientTest,
5745 name: "ALPNClient-AllowUnknown-" + ver.name,
5746 config: Config{
5747 MaxVersion: ver.version,
5748 Bugs: ProtocolBugs{
5749 SendALPN: "baz",
5750 },
5751 },
5752 flags: []string{
5753 "-advertise-alpn", "\x03foo\x03bar",
5754 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005755 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005756 },
David Benjamina5022392017-07-10 17:40:39 -04005757 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005758 })
5759 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005760 testType: serverTest,
5761 name: "ALPNServer-" + ver.name,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 NextProtos: []string{"foo", "bar", "baz"},
5765 },
5766 flags: []string{
5767 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5768 "-select-alpn", "foo",
5769 },
David Benjamina5022392017-07-10 17:40:39 -04005770 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005771 expectedNextProto: "foo",
5772 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005773 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005774 })
5775 testCases = append(testCases, testCase{
5776 testType: serverTest,
5777 name: "ALPNServer-Decline-" + ver.name,
5778 config: Config{
5779 MaxVersion: ver.version,
5780 NextProtos: []string{"foo", "bar", "baz"},
5781 },
5782 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005783 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005784 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005785 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005786 })
5787
David Benjamin25fe85b2016-08-09 20:00:32 -04005788 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5789 // called once.
5790 testCases = append(testCases, testCase{
5791 testType: serverTest,
5792 name: "ALPNServer-Async-" + ver.name,
5793 config: Config{
5794 MaxVersion: ver.version,
5795 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005796 // Prior to TLS 1.3, exercise the asynchronous session callback.
5797 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005798 },
5799 flags: []string{
5800 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5801 "-select-alpn", "foo",
5802 "-async",
5803 },
David Benjamina5022392017-07-10 17:40:39 -04005804 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005805 expectedNextProto: "foo",
5806 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005807 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005808 })
5809
David Benjamin97d17d92016-07-14 16:12:00 -04005810 var emptyString string
5811 testCases = append(testCases, testCase{
5812 testType: clientTest,
5813 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5814 config: Config{
5815 MaxVersion: ver.version,
5816 NextProtos: []string{""},
5817 Bugs: ProtocolBugs{
5818 // A server returning an empty ALPN protocol
5819 // should be rejected.
5820 ALPNProtocol: &emptyString,
5821 },
5822 },
5823 flags: []string{
5824 "-advertise-alpn", "\x03foo",
5825 },
David Benjamina5022392017-07-10 17:40:39 -04005826 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005827 shouldFail: true,
5828 expectedError: ":PARSE_TLSEXT:",
5829 })
5830 testCases = append(testCases, testCase{
5831 testType: serverTest,
5832 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5833 config: Config{
5834 MaxVersion: ver.version,
5835 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005836 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005837 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005838 },
David Benjamin97d17d92016-07-14 16:12:00 -04005839 flags: []string{
5840 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005841 },
David Benjamina5022392017-07-10 17:40:39 -04005842 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005843 shouldFail: true,
5844 expectedError: ":PARSE_TLSEXT:",
5845 })
5846
5847 // Test NPN and the interaction with ALPN.
5848 if ver.version < VersionTLS13 {
5849 // Test that the server prefers ALPN over NPN.
5850 testCases = append(testCases, testCase{
5851 testType: serverTest,
5852 name: "ALPNServer-Preferred-" + ver.name,
5853 config: Config{
5854 MaxVersion: ver.version,
5855 NextProtos: []string{"foo", "bar", "baz"},
5856 },
5857 flags: []string{
5858 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5859 "-select-alpn", "foo",
5860 "-advertise-npn", "\x03foo\x03bar\x03baz",
5861 },
David Benjamina5022392017-07-10 17:40:39 -04005862 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005863 expectedNextProto: "foo",
5864 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005865 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005866 })
5867 testCases = append(testCases, testCase{
5868 testType: serverTest,
5869 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5870 config: Config{
5871 MaxVersion: ver.version,
5872 NextProtos: []string{"foo", "bar", "baz"},
5873 Bugs: ProtocolBugs{
5874 SwapNPNAndALPN: true,
5875 },
5876 },
5877 flags: []string{
5878 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5879 "-select-alpn", "foo",
5880 "-advertise-npn", "\x03foo\x03bar\x03baz",
5881 },
David Benjamina5022392017-07-10 17:40:39 -04005882 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005883 expectedNextProto: "foo",
5884 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005885 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005886 })
5887
5888 // Test that negotiating both NPN and ALPN is forbidden.
5889 testCases = append(testCases, testCase{
5890 name: "NegotiateALPNAndNPN-" + ver.name,
5891 config: Config{
5892 MaxVersion: ver.version,
5893 NextProtos: []string{"foo", "bar", "baz"},
5894 Bugs: ProtocolBugs{
5895 NegotiateALPNAndNPN: true,
5896 },
5897 },
5898 flags: []string{
5899 "-advertise-alpn", "\x03foo",
5900 "-select-next-proto", "foo",
5901 },
David Benjamina5022392017-07-10 17:40:39 -04005902 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005903 shouldFail: true,
5904 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5905 })
5906 testCases = append(testCases, testCase{
5907 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5908 config: Config{
5909 MaxVersion: ver.version,
5910 NextProtos: []string{"foo", "bar", "baz"},
5911 Bugs: ProtocolBugs{
5912 NegotiateALPNAndNPN: true,
5913 SwapNPNAndALPN: true,
5914 },
5915 },
5916 flags: []string{
5917 "-advertise-alpn", "\x03foo",
5918 "-select-next-proto", "foo",
5919 },
David Benjamina5022392017-07-10 17:40:39 -04005920 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005921 shouldFail: true,
5922 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5923 })
David Benjamin97d17d92016-07-14 16:12:00 -04005924 }
5925
5926 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005927
5928 // Resume with a corrupt ticket.
5929 testCases = append(testCases, testCase{
5930 testType: serverTest,
5931 name: "CorruptTicket-" + ver.name,
5932 config: Config{
5933 MaxVersion: ver.version,
5934 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005935 FilterTicket: func(in []byte) ([]byte, error) {
5936 in[len(in)-1] ^= 1
5937 return in, nil
5938 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005939 },
5940 },
David Benjamina5022392017-07-10 17:40:39 -04005941 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005942 resumeSession: true,
5943 expectResumeRejected: true,
5944 })
5945 // Test the ticket callback, with and without renewal.
5946 testCases = append(testCases, testCase{
5947 testType: serverTest,
5948 name: "TicketCallback-" + ver.name,
5949 config: Config{
5950 MaxVersion: ver.version,
5951 },
David Benjamina5022392017-07-10 17:40:39 -04005952 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005953 resumeSession: true,
5954 flags: []string{"-use-ticket-callback"},
5955 })
5956 testCases = append(testCases, testCase{
5957 testType: serverTest,
5958 name: "TicketCallback-Renew-" + ver.name,
5959 config: Config{
5960 MaxVersion: ver.version,
5961 Bugs: ProtocolBugs{
5962 ExpectNewTicket: true,
5963 },
5964 },
David Benjamina5022392017-07-10 17:40:39 -04005965 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005966 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5967 resumeSession: true,
5968 })
5969
5970 // Test that the ticket callback is only called once when everything before
5971 // it in the ClientHello is asynchronous. This corrupts the ticket so
5972 // certificate selection callbacks run.
5973 testCases = append(testCases, testCase{
5974 testType: serverTest,
5975 name: "TicketCallback-SingleCall-" + ver.name,
5976 config: Config{
5977 MaxVersion: ver.version,
5978 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005979 FilterTicket: func(in []byte) ([]byte, error) {
5980 in[len(in)-1] ^= 1
5981 return in, nil
5982 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005983 },
5984 },
David Benjamina5022392017-07-10 17:40:39 -04005985 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005986 resumeSession: true,
5987 expectResumeRejected: true,
5988 flags: []string{
5989 "-use-ticket-callback",
5990 "-async",
5991 },
5992 })
5993
David Benjamind4c349b2017-02-09 14:07:17 -05005994 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005995 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005996 testCases = append(testCases, testCase{
5997 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005998 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005999 config: Config{
6000 MaxVersion: ver.version,
6001 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006002 EmptyTicketSessionID: true,
6003 },
6004 },
6005 resumeSession: true,
6006 })
6007 testCases = append(testCases, testCase{
6008 testType: serverTest,
6009 name: "TicketSessionIDLength-16-" + ver.name,
6010 config: Config{
6011 MaxVersion: ver.version,
6012 Bugs: ProtocolBugs{
6013 TicketSessionIDLength: 16,
6014 },
6015 },
6016 resumeSession: true,
6017 })
6018 testCases = append(testCases, testCase{
6019 testType: serverTest,
6020 name: "TicketSessionIDLength-32-" + ver.name,
6021 config: Config{
6022 MaxVersion: ver.version,
6023 Bugs: ProtocolBugs{
6024 TicketSessionIDLength: 32,
6025 },
6026 },
6027 resumeSession: true,
6028 })
6029 testCases = append(testCases, testCase{
6030 testType: serverTest,
6031 name: "TicketSessionIDLength-33-" + ver.name,
6032 config: Config{
6033 MaxVersion: ver.version,
6034 Bugs: ProtocolBugs{
6035 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006036 },
6037 },
6038 resumeSession: true,
6039 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006040 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006041 expectedError: ":DECODE_ERROR:",
6042 })
6043 }
6044
6045 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6046 // are ignored.
6047 if ver.hasDTLS {
6048 testCases = append(testCases, testCase{
6049 protocol: dtls,
6050 name: "SRTP-Client-" + ver.name,
6051 config: Config{
6052 MaxVersion: ver.version,
6053 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6054 },
6055 flags: []string{
6056 "-srtp-profiles",
6057 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6058 },
6059 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6060 })
6061 testCases = append(testCases, testCase{
6062 protocol: dtls,
6063 testType: serverTest,
6064 name: "SRTP-Server-" + ver.name,
6065 config: Config{
6066 MaxVersion: ver.version,
6067 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6068 },
6069 flags: []string{
6070 "-srtp-profiles",
6071 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6072 },
6073 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6074 })
6075 // Test that the MKI is ignored.
6076 testCases = append(testCases, testCase{
6077 protocol: dtls,
6078 testType: serverTest,
6079 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6080 config: Config{
6081 MaxVersion: ver.version,
6082 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6083 Bugs: ProtocolBugs{
6084 SRTPMasterKeyIdentifer: "bogus",
6085 },
6086 },
6087 flags: []string{
6088 "-srtp-profiles",
6089 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6090 },
6091 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6092 })
6093 // Test that SRTP isn't negotiated on the server if there were
6094 // no matching profiles.
6095 testCases = append(testCases, testCase{
6096 protocol: dtls,
6097 testType: serverTest,
6098 name: "SRTP-Server-NoMatch-" + ver.name,
6099 config: Config{
6100 MaxVersion: ver.version,
6101 SRTPProtectionProfiles: []uint16{100, 101, 102},
6102 },
6103 flags: []string{
6104 "-srtp-profiles",
6105 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6106 },
6107 expectedSRTPProtectionProfile: 0,
6108 })
6109 // Test that the server returning an invalid SRTP profile is
6110 // flagged as an error by the client.
6111 testCases = append(testCases, testCase{
6112 protocol: dtls,
6113 name: "SRTP-Client-NoMatch-" + ver.name,
6114 config: Config{
6115 MaxVersion: ver.version,
6116 Bugs: ProtocolBugs{
6117 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6118 },
6119 },
6120 flags: []string{
6121 "-srtp-profiles",
6122 "SRTP_AES128_CM_SHA1_80",
6123 },
6124 shouldFail: true,
6125 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6126 })
6127 }
6128
6129 // Test SCT list.
6130 testCases = append(testCases, testCase{
6131 name: "SignedCertificateTimestampList-Client-" + ver.name,
6132 testType: clientTest,
6133 config: Config{
6134 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006135 },
David Benjamin97d17d92016-07-14 16:12:00 -04006136 flags: []string{
6137 "-enable-signed-cert-timestamps",
6138 "-expect-signed-cert-timestamps",
6139 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006140 },
David Benjamina5022392017-07-10 17:40:39 -04006141 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006142 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006143 })
David Benjamindaa88502016-10-04 16:32:16 -04006144
Adam Langleycfa08c32016-11-17 13:21:27 -08006145 var differentSCTList []byte
6146 differentSCTList = append(differentSCTList, testSCTList...)
6147 differentSCTList[len(differentSCTList)-1] ^= 1
6148
David Benjamindaa88502016-10-04 16:32:16 -04006149 // The SCT extension did not specify that it must only be sent on resumption as it
6150 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006151 testCases = append(testCases, testCase{
6152 name: "SendSCTListOnResume-" + ver.name,
6153 config: Config{
6154 MaxVersion: ver.version,
6155 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006156 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006157 },
David Benjamind98452d2015-06-16 14:16:23 -04006158 },
David Benjamin97d17d92016-07-14 16:12:00 -04006159 flags: []string{
6160 "-enable-signed-cert-timestamps",
6161 "-expect-signed-cert-timestamps",
6162 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006163 },
David Benjamina5022392017-07-10 17:40:39 -04006164 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006165 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006166 })
David Benjamindaa88502016-10-04 16:32:16 -04006167
David Benjamin97d17d92016-07-14 16:12:00 -04006168 testCases = append(testCases, testCase{
6169 name: "SignedCertificateTimestampList-Server-" + ver.name,
6170 testType: serverTest,
6171 config: Config{
6172 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006173 },
David Benjamin97d17d92016-07-14 16:12:00 -04006174 flags: []string{
6175 "-signed-cert-timestamps",
6176 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006177 },
David Benjamina5022392017-07-10 17:40:39 -04006178 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006179 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006180 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006181 })
David Benjamin53210cb2016-11-16 09:01:48 +09006182
Adam Langleycfa08c32016-11-17 13:21:27 -08006183 emptySCTListCert := *testCerts[0].cert
6184 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6185
6186 // Test empty SCT list.
6187 testCases = append(testCases, testCase{
6188 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6189 testType: clientTest,
6190 config: Config{
6191 MaxVersion: ver.version,
6192 Certificates: []Certificate{emptySCTListCert},
6193 },
6194 flags: []string{
6195 "-enable-signed-cert-timestamps",
6196 },
David Benjamina5022392017-07-10 17:40:39 -04006197 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006198 shouldFail: true,
6199 expectedError: ":ERROR_PARSING_EXTENSION:",
6200 })
6201
6202 emptySCTCert := *testCerts[0].cert
6203 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6204
6205 // Test empty SCT in non-empty list.
6206 testCases = append(testCases, testCase{
6207 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6208 testType: clientTest,
6209 config: Config{
6210 MaxVersion: ver.version,
6211 Certificates: []Certificate{emptySCTCert},
6212 },
6213 flags: []string{
6214 "-enable-signed-cert-timestamps",
6215 },
David Benjamina5022392017-07-10 17:40:39 -04006216 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006217 shouldFail: true,
6218 expectedError: ":ERROR_PARSING_EXTENSION:",
6219 })
6220
David Benjamin53210cb2016-11-16 09:01:48 +09006221 // Test that certificate-related extensions are not sent unsolicited.
6222 testCases = append(testCases, testCase{
6223 testType: serverTest,
6224 name: "UnsolicitedCertificateExtensions-" + ver.name,
6225 config: Config{
6226 MaxVersion: ver.version,
6227 Bugs: ProtocolBugs{
6228 NoOCSPStapling: true,
6229 NoSignedCertificateTimestamps: true,
6230 },
6231 },
David Benjamina5022392017-07-10 17:40:39 -04006232 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006233 flags: []string{
6234 "-ocsp-response",
6235 base64.StdEncoding.EncodeToString(testOCSPResponse),
6236 "-signed-cert-timestamps",
6237 base64.StdEncoding.EncodeToString(testSCTList),
6238 },
6239 })
David Benjamin97d17d92016-07-14 16:12:00 -04006240 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006241
Paul Lietar4fac72e2015-09-09 13:44:55 +01006242 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006243 testType: clientTest,
6244 name: "ClientHelloPadding",
6245 config: Config{
6246 Bugs: ProtocolBugs{
6247 RequireClientHelloSize: 512,
6248 },
6249 },
6250 // This hostname just needs to be long enough to push the
6251 // ClientHello into F5's danger zone between 256 and 511 bytes
6252 // long.
6253 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6254 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006255
6256 // Extensions should not function in SSL 3.0.
6257 testCases = append(testCases, testCase{
6258 testType: serverTest,
6259 name: "SSLv3Extensions-NoALPN",
6260 config: Config{
6261 MaxVersion: VersionSSL30,
6262 NextProtos: []string{"foo", "bar", "baz"},
6263 },
6264 flags: []string{
6265 "-select-alpn", "foo",
6266 },
6267 expectNoNextProto: true,
6268 })
6269
6270 // Test session tickets separately as they follow a different codepath.
6271 testCases = append(testCases, testCase{
6272 testType: serverTest,
6273 name: "SSLv3Extensions-NoTickets",
6274 config: Config{
6275 MaxVersion: VersionSSL30,
6276 Bugs: ProtocolBugs{
6277 // Historically, session tickets in SSL 3.0
6278 // failed in different ways depending on whether
6279 // the client supported renegotiation_info.
6280 NoRenegotiationInfo: true,
6281 },
6282 },
6283 resumeSession: true,
6284 })
6285 testCases = append(testCases, testCase{
6286 testType: serverTest,
6287 name: "SSLv3Extensions-NoTickets2",
6288 config: Config{
6289 MaxVersion: VersionSSL30,
6290 },
6291 resumeSession: true,
6292 })
6293
6294 // But SSL 3.0 does send and process renegotiation_info.
6295 testCases = append(testCases, testCase{
6296 testType: serverTest,
6297 name: "SSLv3Extensions-RenegotiationInfo",
6298 config: Config{
6299 MaxVersion: VersionSSL30,
6300 Bugs: ProtocolBugs{
6301 RequireRenegotiationInfo: true,
6302 },
6303 },
David Benjamind2610042017-01-03 10:49:28 -05006304 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006305 })
6306 testCases = append(testCases, testCase{
6307 testType: serverTest,
6308 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6309 config: Config{
6310 MaxVersion: VersionSSL30,
6311 Bugs: ProtocolBugs{
6312 NoRenegotiationInfo: true,
6313 SendRenegotiationSCSV: true,
6314 RequireRenegotiationInfo: true,
6315 },
6316 },
David Benjamind2610042017-01-03 10:49:28 -05006317 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006318 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006319
6320 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6321 // in ServerHello.
6322 testCases = append(testCases, testCase{
6323 name: "NPN-Forbidden-TLS13",
6324 config: Config{
6325 MaxVersion: VersionTLS13,
6326 NextProtos: []string{"foo"},
6327 Bugs: ProtocolBugs{
6328 NegotiateNPNAtAllVersions: true,
6329 },
6330 },
6331 flags: []string{"-select-next-proto", "foo"},
6332 shouldFail: true,
6333 expectedError: ":ERROR_PARSING_EXTENSION:",
6334 })
6335 testCases = append(testCases, testCase{
6336 name: "EMS-Forbidden-TLS13",
6337 config: Config{
6338 MaxVersion: VersionTLS13,
6339 Bugs: ProtocolBugs{
6340 NegotiateEMSAtAllVersions: true,
6341 },
6342 },
6343 shouldFail: true,
6344 expectedError: ":ERROR_PARSING_EXTENSION:",
6345 })
6346 testCases = append(testCases, testCase{
6347 name: "RenegotiationInfo-Forbidden-TLS13",
6348 config: Config{
6349 MaxVersion: VersionTLS13,
6350 Bugs: ProtocolBugs{
6351 NegotiateRenegotiationInfoAtAllVersions: true,
6352 },
6353 },
6354 shouldFail: true,
6355 expectedError: ":ERROR_PARSING_EXTENSION:",
6356 })
6357 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006358 name: "Ticket-Forbidden-TLS13",
6359 config: Config{
6360 MaxVersion: VersionTLS12,
6361 },
6362 resumeConfig: &Config{
6363 MaxVersion: VersionTLS13,
6364 Bugs: ProtocolBugs{
6365 AdvertiseTicketExtension: true,
6366 },
6367 },
6368 resumeSession: true,
6369 shouldFail: true,
6370 expectedError: ":ERROR_PARSING_EXTENSION:",
6371 })
6372
6373 // Test that illegal extensions in TLS 1.3 are declined by the server if
6374 // offered in ClientHello. The runner's server will fail if this occurs,
6375 // so we exercise the offering path. (EMS and Renegotiation Info are
6376 // implicit in every test.)
6377 testCases = append(testCases, testCase{
6378 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006379 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006380 config: Config{
6381 MaxVersion: VersionTLS13,
6382 NextProtos: []string{"bar"},
6383 },
6384 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6385 })
David Benjamin196df5b2016-09-21 16:23:27 -04006386
David Benjamindaa88502016-10-04 16:32:16 -04006387 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6388 // tolerated.
6389 testCases = append(testCases, testCase{
6390 name: "SendOCSPResponseOnResume-TLS12",
6391 config: Config{
6392 MaxVersion: VersionTLS12,
6393 Bugs: ProtocolBugs{
6394 SendOCSPResponseOnResume: []byte("bogus"),
6395 },
6396 },
6397 flags: []string{
6398 "-enable-ocsp-stapling",
6399 "-expect-ocsp-response",
6400 base64.StdEncoding.EncodeToString(testOCSPResponse),
6401 },
6402 resumeSession: true,
6403 })
6404
David Benjamindaa88502016-10-04 16:32:16 -04006405 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006406 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006407 config: Config{
6408 MaxVersion: VersionTLS13,
6409 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006410 SendExtensionOnCertificate: testOCSPExtension,
6411 },
6412 },
6413 shouldFail: true,
6414 expectedError: ":UNEXPECTED_EXTENSION:",
6415 })
6416
6417 testCases = append(testCases, testCase{
6418 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6419 config: Config{
6420 MaxVersion: VersionTLS13,
6421 Bugs: ProtocolBugs{
6422 SendExtensionOnCertificate: testSCTExtension,
6423 },
6424 },
6425 shouldFail: true,
6426 expectedError: ":UNEXPECTED_EXTENSION:",
6427 })
6428
6429 // Test that extensions on client certificates are never accepted.
6430 testCases = append(testCases, testCase{
6431 name: "SendExtensionOnClientCertificate-TLS13",
6432 testType: serverTest,
6433 config: Config{
6434 MaxVersion: VersionTLS13,
6435 Certificates: []Certificate{rsaCertificate},
6436 Bugs: ProtocolBugs{
6437 SendExtensionOnCertificate: testOCSPExtension,
6438 },
6439 },
6440 flags: []string{
6441 "-enable-ocsp-stapling",
6442 "-require-any-client-certificate",
6443 },
6444 shouldFail: true,
6445 expectedError: ":UNEXPECTED_EXTENSION:",
6446 })
6447
6448 testCases = append(testCases, testCase{
6449 name: "SendUnknownExtensionOnCertificate-TLS13",
6450 config: Config{
6451 MaxVersion: VersionTLS13,
6452 Bugs: ProtocolBugs{
6453 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6454 },
6455 },
6456 shouldFail: true,
6457 expectedError: ":UNEXPECTED_EXTENSION:",
6458 })
6459
Adam Langleycfa08c32016-11-17 13:21:27 -08006460 var differentSCTList []byte
6461 differentSCTList = append(differentSCTList, testSCTList...)
6462 differentSCTList[len(differentSCTList)-1] ^= 1
6463
Steven Valdeza833c352016-11-01 13:39:36 -04006464 // Test that extensions on intermediates are allowed but ignored.
6465 testCases = append(testCases, testCase{
6466 name: "IgnoreExtensionsOnIntermediates-TLS13",
6467 config: Config{
6468 MaxVersion: VersionTLS13,
6469 Certificates: []Certificate{rsaChainCertificate},
6470 Bugs: ProtocolBugs{
6471 // Send different values on the intermediate. This tests
6472 // the intermediate's extensions do not override the
6473 // leaf's.
6474 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006475 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006476 },
6477 },
6478 flags: []string{
6479 "-enable-ocsp-stapling",
6480 "-expect-ocsp-response",
6481 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006482 "-enable-signed-cert-timestamps",
6483 "-expect-signed-cert-timestamps",
6484 base64.StdEncoding.EncodeToString(testSCTList),
6485 },
6486 resumeSession: true,
6487 })
6488
6489 // Test that extensions are not sent on intermediates when configured
6490 // only for a leaf.
6491 testCases = append(testCases, testCase{
6492 testType: serverTest,
6493 name: "SendNoExtensionsOnIntermediate-TLS13",
6494 config: Config{
6495 MaxVersion: VersionTLS13,
6496 Bugs: ProtocolBugs{
6497 ExpectNoExtensionsOnIntermediate: true,
6498 },
6499 },
6500 flags: []string{
6501 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6502 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6503 "-ocsp-response",
6504 base64.StdEncoding.EncodeToString(testOCSPResponse),
6505 "-signed-cert-timestamps",
6506 base64.StdEncoding.EncodeToString(testSCTList),
6507 },
6508 })
6509
6510 // Test that extensions are not sent on client certificates.
6511 testCases = append(testCases, testCase{
6512 name: "SendNoClientCertificateExtensions-TLS13",
6513 config: Config{
6514 MaxVersion: VersionTLS13,
6515 ClientAuth: RequireAnyClientCert,
6516 },
6517 flags: []string{
6518 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6519 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6520 "-ocsp-response",
6521 base64.StdEncoding.EncodeToString(testOCSPResponse),
6522 "-signed-cert-timestamps",
6523 base64.StdEncoding.EncodeToString(testSCTList),
6524 },
6525 })
6526
6527 testCases = append(testCases, testCase{
6528 name: "SendDuplicateExtensionsOnCerts-TLS13",
6529 config: Config{
6530 MaxVersion: VersionTLS13,
6531 Bugs: ProtocolBugs{
6532 SendDuplicateCertExtensions: true,
6533 },
6534 },
6535 flags: []string{
6536 "-enable-ocsp-stapling",
6537 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006538 },
6539 resumeSession: true,
6540 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006541 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006542 })
Adam Langley9b885c52016-11-18 14:21:03 -08006543
6544 testCases = append(testCases, testCase{
6545 name: "SignedCertificateTimestampListInvalid-Server",
6546 testType: serverTest,
6547 flags: []string{
6548 "-signed-cert-timestamps",
6549 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6550 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006551 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006552 expectedError: ":INVALID_SCT_LIST:",
6553 })
David Benjamine78bfde2014-09-06 12:45:15 -04006554}
6555
David Benjamin01fe8202014-09-24 15:21:44 -04006556func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006557 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006558 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006559 // SSL 3.0 does not have tickets and TLS 1.3 does not
6560 // have session IDs, so skip their cross-resumption
6561 // tests.
6562 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6563 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6564 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006565 }
6566
David Benjamin8b8c0062014-11-23 02:47:52 -05006567 protocols := []protocol{tls}
6568 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6569 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006570 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006571 for _, protocol := range protocols {
6572 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6573 if protocol == dtls {
6574 suffix += "-DTLS"
6575 }
6576
Steven Valdez520e1222017-06-13 12:45:25 -04006577 // We can't resume across TLS 1.3 variants and error out earlier in the
6578 // session resumption.
6579 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6580 continue
6581 }
6582
David Benjaminece3de92015-03-16 18:02:20 -04006583 if sessionVers.version == resumeVers.version {
6584 testCases = append(testCases, testCase{
6585 protocol: protocol,
6586 name: "Resume-Client" + suffix,
6587 resumeSession: true,
6588 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006589 MaxVersion: sessionVers.version,
6590 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006591 Bugs: ProtocolBugs{
6592 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6593 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6594 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006595 },
David Benjaminece3de92015-03-16 18:02:20 -04006596 expectedVersion: sessionVers.version,
6597 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006598 flags: []string{
6599 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6600 },
David Benjaminece3de92015-03-16 18:02:20 -04006601 })
6602 } else {
David Benjamin405da482016-08-08 17:25:07 -04006603 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6604
6605 // Offering a TLS 1.3 session sends an empty session ID, so
6606 // there is no way to convince a non-lookahead client the
6607 // session was resumed. It will appear to the client that a
6608 // stray ChangeCipherSpec was sent.
6609 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6610 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006611 }
6612
David Benjaminece3de92015-03-16 18:02:20 -04006613 testCases = append(testCases, testCase{
6614 protocol: protocol,
6615 name: "Resume-Client-Mismatch" + suffix,
6616 resumeSession: true,
6617 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006618 MaxVersion: sessionVers.version,
6619 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006620 },
David Benjaminece3de92015-03-16 18:02:20 -04006621 expectedVersion: sessionVers.version,
6622 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006623 MaxVersion: resumeVers.version,
6624 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006625 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006626 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006627 },
6628 },
6629 expectedResumeVersion: resumeVers.version,
6630 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006631 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006632 flags: []string{
6633 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6634 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6635 },
David Benjaminece3de92015-03-16 18:02:20 -04006636 })
6637 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006638
6639 testCases = append(testCases, testCase{
6640 protocol: protocol,
6641 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006642 resumeSession: true,
6643 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006644 MaxVersion: sessionVers.version,
6645 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006646 },
6647 expectedVersion: sessionVers.version,
6648 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006649 MaxVersion: resumeVers.version,
6650 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006651 },
6652 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006653 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006654 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006655 flags: []string{
6656 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6657 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6658 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006659 })
6660
David Benjamin8b8c0062014-11-23 02:47:52 -05006661 testCases = append(testCases, testCase{
6662 protocol: protocol,
6663 testType: serverTest,
6664 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006665 resumeSession: true,
6666 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006667 MaxVersion: sessionVers.version,
6668 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006669 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006670 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006671 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006672 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006673 MaxVersion: resumeVers.version,
6674 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006675 Bugs: ProtocolBugs{
6676 SendBothTickets: true,
6677 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006678 },
6679 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006680 flags: []string{
6681 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6682 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6683 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006684 })
6685 }
David Benjamin01fe8202014-09-24 15:21:44 -04006686 }
6687 }
David Benjaminece3de92015-03-16 18:02:20 -04006688
David Benjamin4199b0d2016-11-01 13:58:25 -04006689 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006690 testCases = append(testCases, testCase{
6691 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006692 name: "ShimTicketRewritable",
6693 resumeSession: true,
6694 config: Config{
6695 MaxVersion: VersionTLS12,
6696 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6697 Bugs: ProtocolBugs{
6698 FilterTicket: func(in []byte) ([]byte, error) {
6699 in, err := SetShimTicketVersion(in, VersionTLS12)
6700 if err != nil {
6701 return nil, err
6702 }
6703 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6704 },
6705 },
6706 },
6707 flags: []string{
6708 "-ticket-key",
6709 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6710 },
6711 })
6712
6713 // Resumptions are declined if the version does not match.
6714 testCases = append(testCases, testCase{
6715 testType: serverTest,
6716 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006717 resumeSession: true,
6718 config: Config{
6719 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006720 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006721 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006722 FilterTicket: func(in []byte) ([]byte, error) {
6723 return SetShimTicketVersion(in, VersionTLS13)
6724 },
6725 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006726 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006727 flags: []string{
6728 "-ticket-key",
6729 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6730 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006731 expectResumeRejected: true,
6732 })
6733
6734 testCases = append(testCases, testCase{
6735 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006736 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006737 resumeSession: true,
6738 config: Config{
6739 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006740 Bugs: ProtocolBugs{
6741 FilterTicket: func(in []byte) ([]byte, error) {
6742 return SetShimTicketVersion(in, VersionTLS12)
6743 },
6744 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006745 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006746 flags: []string{
6747 "-ticket-key",
6748 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6749 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006750 expectResumeRejected: true,
6751 })
6752
David Benjamin4199b0d2016-11-01 13:58:25 -04006753 // Resumptions are declined if the cipher is invalid or disabled.
6754 testCases = append(testCases, testCase{
6755 testType: serverTest,
6756 name: "Resume-Server-DeclineBadCipher",
6757 resumeSession: true,
6758 config: Config{
6759 MaxVersion: VersionTLS12,
6760 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006761 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006762 FilterTicket: func(in []byte) ([]byte, error) {
6763 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6764 },
6765 },
6766 },
6767 flags: []string{
6768 "-ticket-key",
6769 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6770 },
6771 expectResumeRejected: true,
6772 })
6773
6774 testCases = append(testCases, testCase{
6775 testType: serverTest,
6776 name: "Resume-Server-DeclineBadCipher-2",
6777 resumeSession: true,
6778 config: Config{
6779 MaxVersion: VersionTLS12,
6780 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006781 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006782 FilterTicket: func(in []byte) ([]byte, error) {
6783 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6784 },
6785 },
6786 },
6787 flags: []string{
6788 "-cipher", "AES128",
6789 "-ticket-key",
6790 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6791 },
6792 expectResumeRejected: true,
6793 })
6794
David Benjaminf01f42a2016-11-16 19:05:33 +09006795 // Sessions are not resumed if they do not use the preferred cipher.
6796 testCases = append(testCases, testCase{
6797 testType: serverTest,
6798 name: "Resume-Server-CipherNotPreferred",
6799 resumeSession: true,
6800 config: Config{
6801 MaxVersion: VersionTLS12,
6802 Bugs: ProtocolBugs{
6803 ExpectNewTicket: true,
6804 FilterTicket: func(in []byte) ([]byte, error) {
6805 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6806 },
6807 },
6808 },
6809 flags: []string{
6810 "-ticket-key",
6811 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6812 },
6813 shouldFail: false,
6814 expectResumeRejected: true,
6815 })
6816
6817 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6818 // PRF hashes match, but BoringSSL will always decline such resumptions.
6819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "Resume-Server-CipherNotPreferred-TLS13",
6822 resumeSession: true,
6823 config: Config{
6824 MaxVersion: VersionTLS13,
6825 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6826 Bugs: ProtocolBugs{
6827 FilterTicket: func(in []byte) ([]byte, error) {
6828 // If the client (runner) offers ChaCha20-Poly1305 first, the
6829 // server (shim) always prefers it. Switch it to AES-GCM.
6830 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6831 },
6832 },
6833 },
6834 flags: []string{
6835 "-ticket-key",
6836 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6837 },
6838 shouldFail: false,
6839 expectResumeRejected: true,
6840 })
6841
6842 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006843 testCases = append(testCases, testCase{
6844 testType: serverTest,
6845 name: "Resume-Server-DeclineBadCipher-TLS13",
6846 resumeSession: true,
6847 config: Config{
6848 MaxVersion: VersionTLS13,
6849 Bugs: ProtocolBugs{
6850 FilterTicket: func(in []byte) ([]byte, error) {
6851 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6852 },
6853 },
6854 },
6855 flags: []string{
6856 "-ticket-key",
6857 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6858 },
6859 expectResumeRejected: true,
6860 })
6861
David Benjaminf01f42a2016-11-16 19:05:33 +09006862 // If the client does not offer the cipher from the session, decline to
6863 // resume. Clients are forbidden from doing this, but BoringSSL selects
6864 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006865 testCases = append(testCases, testCase{
6866 testType: serverTest,
6867 name: "Resume-Server-UnofferedCipher",
6868 resumeSession: true,
6869 config: Config{
6870 MaxVersion: VersionTLS12,
6871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6872 },
6873 resumeConfig: &Config{
6874 MaxVersion: VersionTLS12,
6875 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6876 Bugs: ProtocolBugs{
6877 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6878 },
6879 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006880 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006881 })
6882
David Benjaminf01f42a2016-11-16 19:05:33 +09006883 // In TLS 1.3, clients may advertise a cipher list which does not
6884 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006885 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6886 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006887 testCases = append(testCases, testCase{
6888 testType: serverTest,
6889 name: "Resume-Server-UnofferedCipher-TLS13",
6890 resumeSession: true,
6891 config: Config{
6892 MaxVersion: VersionTLS13,
6893 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6894 },
6895 resumeConfig: &Config{
6896 MaxVersion: VersionTLS13,
6897 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6898 Bugs: ProtocolBugs{
6899 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6900 },
6901 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006902 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006903 })
6904
David Benjamin4199b0d2016-11-01 13:58:25 -04006905 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006906 testCases = append(testCases, testCase{
6907 name: "Resume-Client-CipherMismatch",
6908 resumeSession: true,
6909 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006910 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006911 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6912 },
6913 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006914 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006915 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6916 Bugs: ProtocolBugs{
6917 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6918 },
6919 },
6920 shouldFail: true,
6921 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6922 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006923
David Benjamine1cc35e2016-11-16 16:25:58 +09006924 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6925 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006926 testCases = append(testCases, testCase{
6927 name: "Resume-Client-CipherMismatch-TLS13",
6928 resumeSession: true,
6929 config: Config{
6930 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006931 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006932 },
6933 resumeConfig: &Config{
6934 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006935 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6936 },
6937 })
6938
6939 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6940 testCases = append(testCases, testCase{
6941 name: "Resume-Client-PRFMismatch-TLS13",
6942 resumeSession: true,
6943 config: Config{
6944 MaxVersion: VersionTLS13,
6945 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6946 },
6947 resumeConfig: &Config{
6948 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006949 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006950 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006951 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006952 },
6953 },
6954 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006955 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006956 })
Steven Valdeza833c352016-11-01 13:39:36 -04006957
6958 testCases = append(testCases, testCase{
6959 testType: serverTest,
6960 name: "Resume-Server-BinderWrongLength",
6961 resumeSession: true,
6962 config: Config{
6963 MaxVersion: VersionTLS13,
6964 Bugs: ProtocolBugs{
6965 SendShortPSKBinder: true,
6966 },
6967 },
6968 shouldFail: true,
6969 expectedLocalError: "remote error: error decrypting message",
6970 expectedError: ":DIGEST_CHECK_FAILED:",
6971 })
6972
6973 testCases = append(testCases, testCase{
6974 testType: serverTest,
6975 name: "Resume-Server-NoPSKBinder",
6976 resumeSession: true,
6977 config: Config{
6978 MaxVersion: VersionTLS13,
6979 Bugs: ProtocolBugs{
6980 SendNoPSKBinder: true,
6981 },
6982 },
6983 shouldFail: true,
6984 expectedLocalError: "remote error: error decoding message",
6985 expectedError: ":DECODE_ERROR:",
6986 })
6987
6988 testCases = append(testCases, testCase{
6989 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006990 name: "Resume-Server-ExtraPSKBinder",
6991 resumeSession: true,
6992 config: Config{
6993 MaxVersion: VersionTLS13,
6994 Bugs: ProtocolBugs{
6995 SendExtraPSKBinder: true,
6996 },
6997 },
6998 shouldFail: true,
6999 expectedLocalError: "remote error: illegal parameter",
7000 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7001 })
7002
7003 testCases = append(testCases, testCase{
7004 testType: serverTest,
7005 name: "Resume-Server-ExtraIdentityNoBinder",
7006 resumeSession: true,
7007 config: Config{
7008 MaxVersion: VersionTLS13,
7009 Bugs: ProtocolBugs{
7010 ExtraPSKIdentity: true,
7011 },
7012 },
7013 shouldFail: true,
7014 expectedLocalError: "remote error: illegal parameter",
7015 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7016 })
7017
7018 testCases = append(testCases, testCase{
7019 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007020 name: "Resume-Server-InvalidPSKBinder",
7021 resumeSession: true,
7022 config: Config{
7023 MaxVersion: VersionTLS13,
7024 Bugs: ProtocolBugs{
7025 SendInvalidPSKBinder: true,
7026 },
7027 },
7028 shouldFail: true,
7029 expectedLocalError: "remote error: error decrypting message",
7030 expectedError: ":DIGEST_CHECK_FAILED:",
7031 })
7032
7033 testCases = append(testCases, testCase{
7034 testType: serverTest,
7035 name: "Resume-Server-PSKBinderFirstExtension",
7036 resumeSession: true,
7037 config: Config{
7038 MaxVersion: VersionTLS13,
7039 Bugs: ProtocolBugs{
7040 PSKBinderFirst: true,
7041 },
7042 },
7043 shouldFail: true,
7044 expectedLocalError: "remote error: illegal parameter",
7045 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7046 })
David Benjamin01fe8202014-09-24 15:21:44 -04007047}
7048
Adam Langley2ae77d22014-10-28 17:29:33 -07007049func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007050 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007051 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007052 testType: serverTest,
7053 name: "Renegotiate-Server-Forbidden",
7054 config: Config{
7055 MaxVersion: VersionTLS12,
7056 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007057 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007058 shouldFail: true,
7059 expectedError: ":NO_RENEGOTIATION:",
7060 expectedLocalError: "remote error: no renegotiation",
7061 })
Adam Langley5021b222015-06-12 18:27:58 -07007062 // The server shouldn't echo the renegotiation extension unless
7063 // requested by the client.
7064 testCases = append(testCases, testCase{
7065 testType: serverTest,
7066 name: "Renegotiate-Server-NoExt",
7067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007068 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007069 Bugs: ProtocolBugs{
7070 NoRenegotiationInfo: true,
7071 RequireRenegotiationInfo: true,
7072 },
7073 },
7074 shouldFail: true,
7075 expectedLocalError: "renegotiation extension missing",
7076 })
7077 // The renegotiation SCSV should be sufficient for the server to echo
7078 // the extension.
7079 testCases = append(testCases, testCase{
7080 testType: serverTest,
7081 name: "Renegotiate-Server-NoExt-SCSV",
7082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007083 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007084 Bugs: ProtocolBugs{
7085 NoRenegotiationInfo: true,
7086 SendRenegotiationSCSV: true,
7087 RequireRenegotiationInfo: true,
7088 },
7089 },
7090 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007091 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007092 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007094 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007095 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007096 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007097 },
7098 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007099 renegotiate: 1,
7100 flags: []string{
7101 "-renegotiate-freely",
7102 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007103 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007104 },
David Benjamincdea40c2015-03-19 14:09:43 -04007105 })
7106 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007107 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007108 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007110 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007111 Bugs: ProtocolBugs{
7112 EmptyRenegotiationInfo: true,
7113 },
7114 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007115 flags: []string{"-renegotiate-freely"},
7116 shouldFail: true,
7117 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007118 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007119 })
7120 testCases = append(testCases, testCase{
7121 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007122 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007123 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007124 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007125 Bugs: ProtocolBugs{
7126 BadRenegotiationInfo: true,
7127 },
7128 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007129 flags: []string{"-renegotiate-freely"},
7130 shouldFail: true,
7131 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007132 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007133 })
7134 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007135 name: "Renegotiate-Client-BadExt2",
7136 renegotiate: 1,
7137 config: Config{
7138 MaxVersion: VersionTLS12,
7139 Bugs: ProtocolBugs{
7140 BadRenegotiationInfoEnd: true,
7141 },
7142 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007143 flags: []string{"-renegotiate-freely"},
7144 shouldFail: true,
7145 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007146 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007147 })
7148 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007149 name: "Renegotiate-Client-Downgrade",
7150 renegotiate: 1,
7151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007152 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007153 Bugs: ProtocolBugs{
7154 NoRenegotiationInfoAfterInitial: true,
7155 },
7156 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007157 flags: []string{"-renegotiate-freely"},
7158 shouldFail: true,
7159 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007160 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007161 })
7162 testCases = append(testCases, testCase{
7163 name: "Renegotiate-Client-Upgrade",
7164 renegotiate: 1,
7165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007166 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007167 Bugs: ProtocolBugs{
7168 NoRenegotiationInfoInInitial: true,
7169 },
7170 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007171 flags: []string{"-renegotiate-freely"},
7172 shouldFail: true,
7173 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007174 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007175 })
7176 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007177 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007178 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007179 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007180 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007181 Bugs: ProtocolBugs{
7182 NoRenegotiationInfo: true,
7183 },
7184 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007185 flags: []string{
7186 "-renegotiate-freely",
7187 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007188 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007189 },
David Benjamincff0b902015-05-15 23:09:47 -04007190 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007191
7192 // Test that the server may switch ciphers on renegotiation without
7193 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007194 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007195 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007196 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007197 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007198 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007199 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007200 },
7201 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007202 flags: []string{
7203 "-renegotiate-freely",
7204 "-expect-total-renegotiations", "1",
7205 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007206 })
7207 testCases = append(testCases, testCase{
7208 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007209 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007210 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007211 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007212 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7213 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007214 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007215 flags: []string{
7216 "-renegotiate-freely",
7217 "-expect-total-renegotiations", "1",
7218 },
David Benjaminb16346b2015-04-08 19:16:58 -04007219 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007220
7221 // Test that the server may not switch versions on renegotiation.
7222 testCases = append(testCases, testCase{
7223 name: "Renegotiate-Client-SwitchVersion",
7224 config: Config{
7225 MaxVersion: VersionTLS12,
7226 // Pick a cipher which exists at both versions.
7227 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7228 Bugs: ProtocolBugs{
7229 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007230 // Avoid failing early at the record layer.
7231 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007232 },
7233 },
7234 renegotiate: 1,
7235 flags: []string{
7236 "-renegotiate-freely",
7237 "-expect-total-renegotiations", "1",
7238 },
7239 shouldFail: true,
7240 expectedError: ":WRONG_SSL_VERSION:",
7241 })
7242
David Benjaminb16346b2015-04-08 19:16:58 -04007243 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007244 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007245 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007246 config: Config{
7247 MaxVersion: VersionTLS10,
7248 Bugs: ProtocolBugs{
7249 RequireSameRenegoClientVersion: true,
7250 },
7251 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007252 flags: []string{
7253 "-renegotiate-freely",
7254 "-expect-total-renegotiations", "1",
7255 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007256 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007257 testCases = append(testCases, testCase{
7258 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007259 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007260 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007261 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007262 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7263 NextProtos: []string{"foo"},
7264 },
7265 flags: []string{
7266 "-false-start",
7267 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007268 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007269 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007270 },
7271 shimWritesFirst: true,
7272 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007273
7274 // Client-side renegotiation controls.
7275 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007276 name: "Renegotiate-Client-Forbidden-1",
7277 config: Config{
7278 MaxVersion: VersionTLS12,
7279 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007280 renegotiate: 1,
7281 shouldFail: true,
7282 expectedError: ":NO_RENEGOTIATION:",
7283 expectedLocalError: "remote error: no renegotiation",
7284 })
7285 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007286 name: "Renegotiate-Client-Once-1",
7287 config: Config{
7288 MaxVersion: VersionTLS12,
7289 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007290 renegotiate: 1,
7291 flags: []string{
7292 "-renegotiate-once",
7293 "-expect-total-renegotiations", "1",
7294 },
7295 })
7296 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007297 name: "Renegotiate-Client-Freely-1",
7298 config: Config{
7299 MaxVersion: VersionTLS12,
7300 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007301 renegotiate: 1,
7302 flags: []string{
7303 "-renegotiate-freely",
7304 "-expect-total-renegotiations", "1",
7305 },
7306 })
7307 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007308 name: "Renegotiate-Client-Once-2",
7309 config: Config{
7310 MaxVersion: VersionTLS12,
7311 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007312 renegotiate: 2,
7313 flags: []string{"-renegotiate-once"},
7314 shouldFail: true,
7315 expectedError: ":NO_RENEGOTIATION:",
7316 expectedLocalError: "remote error: no renegotiation",
7317 })
7318 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007319 name: "Renegotiate-Client-Freely-2",
7320 config: Config{
7321 MaxVersion: VersionTLS12,
7322 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007323 renegotiate: 2,
7324 flags: []string{
7325 "-renegotiate-freely",
7326 "-expect-total-renegotiations", "2",
7327 },
7328 })
Adam Langley27a0d082015-11-03 13:34:10 -08007329 testCases = append(testCases, testCase{
7330 name: "Renegotiate-Client-NoIgnore",
7331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007332 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007333 Bugs: ProtocolBugs{
7334 SendHelloRequestBeforeEveryAppDataRecord: true,
7335 },
7336 },
7337 shouldFail: true,
7338 expectedError: ":NO_RENEGOTIATION:",
7339 })
7340 testCases = append(testCases, testCase{
7341 name: "Renegotiate-Client-Ignore",
7342 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007343 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007344 Bugs: ProtocolBugs{
7345 SendHelloRequestBeforeEveryAppDataRecord: true,
7346 },
7347 },
7348 flags: []string{
7349 "-renegotiate-ignore",
7350 "-expect-total-renegotiations", "0",
7351 },
7352 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007353
David Benjamin34941c02016-10-08 11:45:31 -04007354 // Renegotiation is not allowed at SSL 3.0.
7355 testCases = append(testCases, testCase{
7356 name: "Renegotiate-Client-SSL3",
7357 config: Config{
7358 MaxVersion: VersionSSL30,
7359 },
7360 renegotiate: 1,
7361 flags: []string{
7362 "-renegotiate-freely",
7363 "-expect-total-renegotiations", "1",
7364 },
7365 shouldFail: true,
7366 expectedError: ":NO_RENEGOTIATION:",
7367 expectedLocalError: "remote error: no renegotiation",
7368 })
7369
David Benjamina1eaba12017-01-01 23:19:22 -05007370 // Renegotiation is not allowed when there is an unfinished write.
7371 testCases = append(testCases, testCase{
7372 name: "Renegotiate-Client-UnfinishedWrite",
7373 config: Config{
7374 MaxVersion: VersionTLS12,
7375 },
David Benjaminbbba9392017-04-06 12:54:12 -04007376 renegotiate: 1,
7377 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007378 flags: []string{
7379 "-async",
7380 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007381 },
7382 shouldFail: true,
7383 expectedError: ":NO_RENEGOTIATION:",
7384 // We do not successfully send the no_renegotiation alert in
7385 // this case. https://crbug.com/boringssl/130
7386 })
7387
David Benjamin07ab5d42017-02-09 20:11:41 -05007388 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007389 testCases = append(testCases, testCase{
7390 name: "StrayHelloRequest",
7391 config: Config{
7392 MaxVersion: VersionTLS12,
7393 Bugs: ProtocolBugs{
7394 SendHelloRequestBeforeEveryHandshakeMessage: true,
7395 },
7396 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007397 shouldFail: true,
7398 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007399 })
7400 testCases = append(testCases, testCase{
7401 name: "StrayHelloRequest-Packed",
7402 config: Config{
7403 MaxVersion: VersionTLS12,
7404 Bugs: ProtocolBugs{
7405 PackHandshakeFlight: true,
7406 SendHelloRequestBeforeEveryHandshakeMessage: true,
7407 },
7408 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007409 shouldFail: true,
7410 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007411 })
7412
David Benjamin12d2c482016-07-24 10:56:51 -04007413 // Test renegotiation works if HelloRequest and server Finished come in
7414 // the same record.
7415 testCases = append(testCases, testCase{
7416 name: "Renegotiate-Client-Packed",
7417 config: Config{
7418 MaxVersion: VersionTLS12,
7419 Bugs: ProtocolBugs{
7420 PackHandshakeFlight: true,
7421 PackHelloRequestWithFinished: true,
7422 },
7423 },
7424 renegotiate: 1,
7425 flags: []string{
7426 "-renegotiate-freely",
7427 "-expect-total-renegotiations", "1",
7428 },
7429 })
7430
David Benjamin397c8e62016-07-08 14:14:36 -07007431 // Renegotiation is forbidden in TLS 1.3.
7432 testCases = append(testCases, testCase{
7433 name: "Renegotiate-Client-TLS13",
7434 config: Config{
7435 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007436 Bugs: ProtocolBugs{
7437 SendHelloRequestBeforeEveryAppDataRecord: true,
7438 },
David Benjamin397c8e62016-07-08 14:14:36 -07007439 },
David Benjamin397c8e62016-07-08 14:14:36 -07007440 flags: []string{
7441 "-renegotiate-freely",
7442 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007443 shouldFail: true,
7444 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007445 })
7446
7447 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7448 testCases = append(testCases, testCase{
7449 name: "StrayHelloRequest-TLS13",
7450 config: Config{
7451 MaxVersion: VersionTLS13,
7452 Bugs: ProtocolBugs{
7453 SendHelloRequestBeforeEveryHandshakeMessage: true,
7454 },
7455 },
7456 shouldFail: true,
7457 expectedError: ":UNEXPECTED_MESSAGE:",
7458 })
David Benjamind2610042017-01-03 10:49:28 -05007459
7460 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7461 // always reads as supporting it, regardless of whether it was
7462 // negotiated.
7463 testCases = append(testCases, testCase{
7464 name: "AlwaysReportRenegotiationInfo-TLS13",
7465 config: Config{
7466 MaxVersion: VersionTLS13,
7467 Bugs: ProtocolBugs{
7468 NoRenegotiationInfo: true,
7469 },
7470 },
7471 flags: []string{
7472 "-expect-secure-renegotiation",
7473 },
7474 })
David Benjamina58baaf2017-02-28 20:54:28 -05007475
7476 // Certificates may not change on renegotiation.
7477 testCases = append(testCases, testCase{
7478 name: "Renegotiation-CertificateChange",
7479 config: Config{
7480 MaxVersion: VersionTLS12,
7481 Certificates: []Certificate{rsaCertificate},
7482 Bugs: ProtocolBugs{
7483 RenegotiationCertificate: &rsaChainCertificate,
7484 },
7485 },
7486 renegotiate: 1,
7487 flags: []string{"-renegotiate-freely"},
7488 shouldFail: true,
7489 expectedError: ":SERVER_CERT_CHANGED:",
7490 })
7491 testCases = append(testCases, testCase{
7492 name: "Renegotiation-CertificateChange-2",
7493 config: Config{
7494 MaxVersion: VersionTLS12,
7495 Certificates: []Certificate{rsaCertificate},
7496 Bugs: ProtocolBugs{
7497 RenegotiationCertificate: &rsa1024Certificate,
7498 },
7499 },
7500 renegotiate: 1,
7501 flags: []string{"-renegotiate-freely"},
7502 shouldFail: true,
7503 expectedError: ":SERVER_CERT_CHANGED:",
7504 })
David Benjaminbbf42462017-03-14 21:27:10 -04007505
7506 // We do not negotiate ALPN after the initial handshake. This is
7507 // error-prone and only risks bugs in consumers.
7508 testCases = append(testCases, testCase{
7509 testType: clientTest,
7510 name: "Renegotiation-ForbidALPN",
7511 config: Config{
7512 MaxVersion: VersionTLS12,
7513 Bugs: ProtocolBugs{
7514 // Forcibly negotiate ALPN on both initial and
7515 // renegotiation handshakes. The test stack will
7516 // internally check the client does not offer
7517 // it.
7518 SendALPN: "foo",
7519 },
7520 },
7521 flags: []string{
7522 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7523 "-expect-alpn", "foo",
7524 "-renegotiate-freely",
7525 },
7526 renegotiate: 1,
7527 shouldFail: true,
7528 expectedError: ":UNEXPECTED_EXTENSION:",
7529 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007530}
7531
David Benjamin5e961c12014-11-07 01:48:35 -05007532func addDTLSReplayTests() {
7533 // Test that sequence number replays are detected.
7534 testCases = append(testCases, testCase{
7535 protocol: dtls,
7536 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007537 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007538 replayWrites: true,
7539 })
7540
David Benjamin8e6db492015-07-25 18:29:23 -04007541 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007542 // than the retransmit window.
7543 testCases = append(testCases, testCase{
7544 protocol: dtls,
7545 name: "DTLS-Replay-LargeGaps",
7546 config: Config{
7547 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007548 SequenceNumberMapping: func(in uint64) uint64 {
7549 return in * 127
7550 },
David Benjamin5e961c12014-11-07 01:48:35 -05007551 },
7552 },
David Benjamin8e6db492015-07-25 18:29:23 -04007553 messageCount: 200,
7554 replayWrites: true,
7555 })
7556
7557 // Test the incoming sequence number changing non-monotonically.
7558 testCases = append(testCases, testCase{
7559 protocol: dtls,
7560 name: "DTLS-Replay-NonMonotonic",
7561 config: Config{
7562 Bugs: ProtocolBugs{
7563 SequenceNumberMapping: func(in uint64) uint64 {
7564 return in ^ 31
7565 },
7566 },
7567 },
7568 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007569 replayWrites: true,
7570 })
7571}
7572
Nick Harper60edffd2016-06-21 15:19:24 -07007573var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007574 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007575 id signatureAlgorithm
7576 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007577}{
Nick Harper60edffd2016-06-21 15:19:24 -07007578 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7579 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7580 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7581 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007582 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007583 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7584 // hash function doesn't have to match the curve and so the same
7585 // signature algorithm works with P-224.
7586 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007587 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7588 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7589 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007590 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7591 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7592 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007593 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007594 // Tests for key types prior to TLS 1.2.
7595 {"RSA", 0, testCertRSA},
7596 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007597}
7598
Nick Harper60edffd2016-06-21 15:19:24 -07007599const fakeSigAlg1 signatureAlgorithm = 0x2a01
7600const fakeSigAlg2 signatureAlgorithm = 0xff01
7601
7602func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007603 // Not all ciphers involve a signature. Advertise a list which gives all
7604 // versions a signing cipher.
7605 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007606 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007607 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7608 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7609 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7610 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007611 }
David Benjamin5208fd42016-07-13 21:43:25 -04007612
David Benjaminca3d5452016-07-14 12:51:01 -04007613 var allAlgorithms []signatureAlgorithm
7614 for _, alg := range testSignatureAlgorithms {
7615 if alg.id != 0 {
7616 allAlgorithms = append(allAlgorithms, alg.id)
7617 }
7618 }
7619
Nick Harper60edffd2016-06-21 15:19:24 -07007620 // Make sure each signature algorithm works. Include some fake values in
7621 // the list and ensure they're ignored.
7622 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007623 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007624 if (ver.version < VersionTLS12) != (alg.id == 0) {
7625 continue
7626 }
7627
7628 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7629 // or remove it in C.
7630 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007631 continue
7632 }
Nick Harper60edffd2016-06-21 15:19:24 -07007633
David Benjamin3ef76972016-10-17 17:59:54 -04007634 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007635 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007636 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007637 shouldSignFail = true
7638 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007639 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007640 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007641 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7642 shouldSignFail = true
7643 shouldVerifyFail = true
7644 }
7645 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7646 // the curve has to match the hash size.
7647 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007648 shouldSignFail = true
7649 shouldVerifyFail = true
7650 }
7651
7652 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7653 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7654 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007655 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007656
7657 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007658 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007659 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007660 }
7661 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007662 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007663 }
David Benjamin000800a2014-11-14 01:43:59 -05007664
David Benjamin1fb125c2016-07-08 18:52:12 -07007665 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007666
David Benjamin7a41d372016-07-09 11:21:54 -07007667 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007668 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007669 config: Config{
7670 MaxVersion: ver.version,
7671 ClientAuth: RequireAnyClientCert,
7672 VerifySignatureAlgorithms: []signatureAlgorithm{
7673 fakeSigAlg1,
7674 alg.id,
7675 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007676 },
David Benjamin7a41d372016-07-09 11:21:54 -07007677 },
7678 flags: []string{
7679 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7680 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7681 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007682 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007683 },
David Benjamina5022392017-07-10 17:40:39 -04007684 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007685 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007686 expectedError: signError,
7687 expectedPeerSignatureAlgorithm: alg.id,
7688 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007689
David Benjamin7a41d372016-07-09 11:21:54 -07007690 testCases = append(testCases, testCase{
7691 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007692 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007693 config: Config{
7694 MaxVersion: ver.version,
7695 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7696 SignSignatureAlgorithms: []signatureAlgorithm{
7697 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007698 },
David Benjamin7a41d372016-07-09 11:21:54 -07007699 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007700 SkipECDSACurveCheck: shouldVerifyFail,
7701 IgnoreSignatureVersionChecks: shouldVerifyFail,
7702 // Some signature algorithms may not be advertised.
7703 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007704 },
David Benjamin7a41d372016-07-09 11:21:54 -07007705 },
David Benjamina5022392017-07-10 17:40:39 -04007706 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007707 flags: []string{
7708 "-require-any-client-certificate",
7709 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7710 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007711 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007712 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007713 // Resume the session to assert the peer signature
7714 // algorithm is reported on both handshakes.
7715 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007716 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007717 expectedError: verifyError,
7718 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007719
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007720 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007721 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007722 testCases = append(testCases, testCase{
7723 testType: serverTest,
7724 name: "ServerAuth-Sign" + suffix,
7725 config: Config{
7726 MaxVersion: ver.version,
7727 CipherSuites: signingCiphers,
7728 VerifySignatureAlgorithms: []signatureAlgorithm{
7729 fakeSigAlg1,
7730 alg.id,
7731 fakeSigAlg2,
7732 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007733 },
David Benjamina5022392017-07-10 17:40:39 -04007734 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007735 flags: []string{
7736 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7737 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7738 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007739 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007740 },
7741 shouldFail: shouldSignFail,
7742 expectedError: signError,
7743 expectedPeerSignatureAlgorithm: alg.id,
7744 })
7745 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007746
7747 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007748 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007749 config: Config{
7750 MaxVersion: ver.version,
7751 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007752 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007753 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007754 alg.id,
7755 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007756 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007757 SkipECDSACurveCheck: shouldVerifyFail,
7758 IgnoreSignatureVersionChecks: shouldVerifyFail,
7759 // Some signature algorithms may not be advertised.
7760 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007761 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007762 },
David Benjamina5022392017-07-10 17:40:39 -04007763 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007764 flags: []string{
7765 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7766 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007767 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007768 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007769 // Resume the session to assert the peer signature
7770 // algorithm is reported on both handshakes.
7771 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007772 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007773 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007774 })
David Benjamin5208fd42016-07-13 21:43:25 -04007775
David Benjamin3ef76972016-10-17 17:59:54 -04007776 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007777 testCases = append(testCases, testCase{
7778 testType: serverTest,
7779 name: "ClientAuth-InvalidSignature" + suffix,
7780 config: Config{
7781 MaxVersion: ver.version,
7782 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7783 SignSignatureAlgorithms: []signatureAlgorithm{
7784 alg.id,
7785 },
7786 Bugs: ProtocolBugs{
7787 InvalidSignature: true,
7788 },
7789 },
David Benjamina5022392017-07-10 17:40:39 -04007790 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007791 flags: []string{
7792 "-require-any-client-certificate",
7793 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007794 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007795 },
7796 shouldFail: true,
7797 expectedError: ":BAD_SIGNATURE:",
7798 })
7799
7800 testCases = append(testCases, testCase{
7801 name: "ServerAuth-InvalidSignature" + suffix,
7802 config: Config{
7803 MaxVersion: ver.version,
7804 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7805 CipherSuites: signingCiphers,
7806 SignSignatureAlgorithms: []signatureAlgorithm{
7807 alg.id,
7808 },
7809 Bugs: ProtocolBugs{
7810 InvalidSignature: true,
7811 },
7812 },
David Benjamina5022392017-07-10 17:40:39 -04007813 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007814 flags: []string{
7815 "-enable-all-curves",
7816 "-enable-ed25519",
7817 },
David Benjamin5208fd42016-07-13 21:43:25 -04007818 shouldFail: true,
7819 expectedError: ":BAD_SIGNATURE:",
7820 })
7821 }
David Benjaminca3d5452016-07-14 12:51:01 -04007822
David Benjamin3ef76972016-10-17 17:59:54 -04007823 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007824 testCases = append(testCases, testCase{
7825 name: "ClientAuth-Sign-Negotiate" + suffix,
7826 config: Config{
7827 MaxVersion: ver.version,
7828 ClientAuth: RequireAnyClientCert,
7829 VerifySignatureAlgorithms: allAlgorithms,
7830 },
David Benjamina5022392017-07-10 17:40:39 -04007831 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007832 flags: []string{
7833 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7834 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7835 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007836 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007837 "-signing-prefs", strconv.Itoa(int(alg.id)),
7838 },
7839 expectedPeerSignatureAlgorithm: alg.id,
7840 })
7841
7842 testCases = append(testCases, testCase{
7843 testType: serverTest,
7844 name: "ServerAuth-Sign-Negotiate" + suffix,
7845 config: Config{
7846 MaxVersion: ver.version,
7847 CipherSuites: signingCiphers,
7848 VerifySignatureAlgorithms: allAlgorithms,
7849 },
David Benjamina5022392017-07-10 17:40:39 -04007850 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007851 flags: []string{
7852 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7853 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7854 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007855 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007856 "-signing-prefs", strconv.Itoa(int(alg.id)),
7857 },
7858 expectedPeerSignatureAlgorithm: alg.id,
7859 })
7860 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007861 }
David Benjamin000800a2014-11-14 01:43:59 -05007862 }
7863
Nick Harper60edffd2016-06-21 15:19:24 -07007864 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007865 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007866 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007867 config: Config{
7868 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007869 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007870 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007871 signatureECDSAWithP521AndSHA512,
7872 signatureRSAPKCS1WithSHA384,
7873 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007874 },
7875 },
7876 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007877 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7878 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007879 },
Nick Harper60edffd2016-06-21 15:19:24 -07007880 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007881 })
7882
7883 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007884 name: "ClientAuth-SignatureType-TLS13",
7885 config: Config{
7886 ClientAuth: RequireAnyClientCert,
7887 MaxVersion: VersionTLS13,
7888 VerifySignatureAlgorithms: []signatureAlgorithm{
7889 signatureECDSAWithP521AndSHA512,
7890 signatureRSAPKCS1WithSHA384,
7891 signatureRSAPSSWithSHA384,
7892 signatureECDSAWithSHA1,
7893 },
7894 },
7895 flags: []string{
7896 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7897 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7898 },
7899 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7900 })
7901
7902 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007903 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007904 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007906 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007907 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007908 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007909 signatureECDSAWithP521AndSHA512,
7910 signatureRSAPKCS1WithSHA384,
7911 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007912 },
7913 },
Nick Harper60edffd2016-06-21 15:19:24 -07007914 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007915 })
7916
Steven Valdez143e8b32016-07-11 13:19:03 -04007917 testCases = append(testCases, testCase{
7918 testType: serverTest,
7919 name: "ServerAuth-SignatureType-TLS13",
7920 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007921 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007922 VerifySignatureAlgorithms: []signatureAlgorithm{
7923 signatureECDSAWithP521AndSHA512,
7924 signatureRSAPKCS1WithSHA384,
7925 signatureRSAPSSWithSHA384,
7926 signatureECDSAWithSHA1,
7927 },
7928 },
7929 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7930 })
7931
David Benjamina95e9f32016-07-08 16:28:04 -07007932 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "Verify-ClientAuth-SignatureType",
7936 config: Config{
7937 MaxVersion: VersionTLS12,
7938 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007939 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007940 signatureRSAPKCS1WithSHA256,
7941 },
7942 Bugs: ProtocolBugs{
7943 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7944 },
7945 },
7946 flags: []string{
7947 "-require-any-client-certificate",
7948 },
7949 shouldFail: true,
7950 expectedError: ":WRONG_SIGNATURE_TYPE:",
7951 })
7952
7953 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007954 testType: serverTest,
7955 name: "Verify-ClientAuth-SignatureType-TLS13",
7956 config: Config{
7957 MaxVersion: VersionTLS13,
7958 Certificates: []Certificate{rsaCertificate},
7959 SignSignatureAlgorithms: []signatureAlgorithm{
7960 signatureRSAPSSWithSHA256,
7961 },
7962 Bugs: ProtocolBugs{
7963 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7964 },
7965 },
7966 flags: []string{
7967 "-require-any-client-certificate",
7968 },
7969 shouldFail: true,
7970 expectedError: ":WRONG_SIGNATURE_TYPE:",
7971 })
7972
7973 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007974 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007975 config: Config{
7976 MaxVersion: VersionTLS12,
7977 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007978 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007979 signatureRSAPKCS1WithSHA256,
7980 },
7981 Bugs: ProtocolBugs{
7982 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7983 },
7984 },
7985 shouldFail: true,
7986 expectedError: ":WRONG_SIGNATURE_TYPE:",
7987 })
7988
Steven Valdez143e8b32016-07-11 13:19:03 -04007989 testCases = append(testCases, testCase{
7990 name: "Verify-ServerAuth-SignatureType-TLS13",
7991 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007992 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007993 SignSignatureAlgorithms: []signatureAlgorithm{
7994 signatureRSAPSSWithSHA256,
7995 },
7996 Bugs: ProtocolBugs{
7997 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7998 },
7999 },
8000 shouldFail: true,
8001 expectedError: ":WRONG_SIGNATURE_TYPE:",
8002 })
8003
David Benjamin51dd7d62016-07-08 16:07:01 -07008004 // Test that, if the list is missing, the peer falls back to SHA-1 in
8005 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008006 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008007 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008009 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008010 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008011 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008012 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008013 },
8014 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008015 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008016 },
8017 },
8018 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008019 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8020 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008021 },
8022 })
8023
8024 testCases = append(testCases, testCase{
8025 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008026 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008027 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008028 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008029 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008030 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008031 },
8032 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008033 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008034 },
8035 },
David Benjaminee32bea2016-08-17 13:36:44 -04008036 flags: []string{
8037 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8038 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8039 },
8040 })
8041
8042 testCases = append(testCases, testCase{
8043 name: "ClientAuth-SHA1-Fallback-ECDSA",
8044 config: Config{
8045 MaxVersion: VersionTLS12,
8046 ClientAuth: RequireAnyClientCert,
8047 VerifySignatureAlgorithms: []signatureAlgorithm{
8048 signatureECDSAWithSHA1,
8049 },
8050 Bugs: ProtocolBugs{
8051 NoSignatureAlgorithms: true,
8052 },
8053 },
8054 flags: []string{
8055 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8056 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8057 },
8058 })
8059
8060 testCases = append(testCases, testCase{
8061 testType: serverTest,
8062 name: "ServerAuth-SHA1-Fallback-ECDSA",
8063 config: Config{
8064 MaxVersion: VersionTLS12,
8065 VerifySignatureAlgorithms: []signatureAlgorithm{
8066 signatureECDSAWithSHA1,
8067 },
8068 Bugs: ProtocolBugs{
8069 NoSignatureAlgorithms: true,
8070 },
8071 },
8072 flags: []string{
8073 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8074 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8075 },
David Benjamin000800a2014-11-14 01:43:59 -05008076 })
David Benjamin72dc7832015-03-16 17:49:43 -04008077
David Benjamin51dd7d62016-07-08 16:07:01 -07008078 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008079 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008080 config: Config{
8081 MaxVersion: VersionTLS13,
8082 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008083 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008084 signatureRSAPKCS1WithSHA1,
8085 },
8086 Bugs: ProtocolBugs{
8087 NoSignatureAlgorithms: true,
8088 },
8089 },
8090 flags: []string{
8091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8093 },
David Benjamin48901652016-08-01 12:12:47 -04008094 shouldFail: true,
8095 // An empty CertificateRequest signature algorithm list is a
8096 // syntax error in TLS 1.3.
8097 expectedError: ":DECODE_ERROR:",
8098 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008099 })
8100
8101 testCases = append(testCases, testCase{
8102 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008103 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008104 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008105 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008106 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008107 signatureRSAPKCS1WithSHA1,
8108 },
8109 Bugs: ProtocolBugs{
8110 NoSignatureAlgorithms: true,
8111 },
8112 },
8113 shouldFail: true,
8114 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8115 })
8116
David Benjaminb62d2872016-07-18 14:55:02 +02008117 // Test that hash preferences are enforced. BoringSSL does not implement
8118 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008119 testCases = append(testCases, testCase{
8120 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008121 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008123 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008124 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008125 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008126 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008127 },
8128 Bugs: ProtocolBugs{
8129 IgnorePeerSignatureAlgorithmPreferences: true,
8130 },
8131 },
8132 flags: []string{"-require-any-client-certificate"},
8133 shouldFail: true,
8134 expectedError: ":WRONG_SIGNATURE_TYPE:",
8135 })
8136
8137 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008138 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008140 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008141 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008142 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008143 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008144 },
8145 Bugs: ProtocolBugs{
8146 IgnorePeerSignatureAlgorithmPreferences: true,
8147 },
8148 },
8149 shouldFail: true,
8150 expectedError: ":WRONG_SIGNATURE_TYPE:",
8151 })
David Benjaminb62d2872016-07-18 14:55:02 +02008152 testCases = append(testCases, testCase{
8153 testType: serverTest,
8154 name: "ClientAuth-Enforced-TLS13",
8155 config: Config{
8156 MaxVersion: VersionTLS13,
8157 Certificates: []Certificate{rsaCertificate},
8158 SignSignatureAlgorithms: []signatureAlgorithm{
8159 signatureRSAPKCS1WithMD5,
8160 },
8161 Bugs: ProtocolBugs{
8162 IgnorePeerSignatureAlgorithmPreferences: true,
8163 IgnoreSignatureVersionChecks: true,
8164 },
8165 },
8166 flags: []string{"-require-any-client-certificate"},
8167 shouldFail: true,
8168 expectedError: ":WRONG_SIGNATURE_TYPE:",
8169 })
8170
8171 testCases = append(testCases, testCase{
8172 name: "ServerAuth-Enforced-TLS13",
8173 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008174 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008175 SignSignatureAlgorithms: []signatureAlgorithm{
8176 signatureRSAPKCS1WithMD5,
8177 },
8178 Bugs: ProtocolBugs{
8179 IgnorePeerSignatureAlgorithmPreferences: true,
8180 IgnoreSignatureVersionChecks: true,
8181 },
8182 },
8183 shouldFail: true,
8184 expectedError: ":WRONG_SIGNATURE_TYPE:",
8185 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008186
8187 // Test that the agreed upon digest respects the client preferences and
8188 // the server digests.
8189 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008190 name: "NoCommonAlgorithms-Digests",
8191 config: Config{
8192 MaxVersion: VersionTLS12,
8193 ClientAuth: RequireAnyClientCert,
8194 VerifySignatureAlgorithms: []signatureAlgorithm{
8195 signatureRSAPKCS1WithSHA512,
8196 signatureRSAPKCS1WithSHA1,
8197 },
8198 },
8199 flags: []string{
8200 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8201 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8202 "-digest-prefs", "SHA256",
8203 },
8204 shouldFail: true,
8205 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8206 })
8207 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008208 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008210 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008211 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008212 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008213 signatureRSAPKCS1WithSHA512,
8214 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008215 },
8216 },
8217 flags: []string{
8218 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8219 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008220 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008221 },
David Benjaminca3d5452016-07-14 12:51:01 -04008222 shouldFail: true,
8223 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8224 })
8225 testCases = append(testCases, testCase{
8226 name: "NoCommonAlgorithms-TLS13",
8227 config: Config{
8228 MaxVersion: VersionTLS13,
8229 ClientAuth: RequireAnyClientCert,
8230 VerifySignatureAlgorithms: []signatureAlgorithm{
8231 signatureRSAPSSWithSHA512,
8232 signatureRSAPSSWithSHA384,
8233 },
8234 },
8235 flags: []string{
8236 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8237 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8238 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8239 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008240 shouldFail: true,
8241 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008242 })
8243 testCases = append(testCases, testCase{
8244 name: "Agree-Digest-SHA256",
8245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008246 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008247 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008248 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008249 signatureRSAPKCS1WithSHA1,
8250 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008251 },
8252 },
8253 flags: []string{
8254 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8255 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008256 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008257 },
Nick Harper60edffd2016-06-21 15:19:24 -07008258 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008259 })
8260 testCases = append(testCases, testCase{
8261 name: "Agree-Digest-SHA1",
8262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008263 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008264 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008265 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008266 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008267 },
8268 },
8269 flags: []string{
8270 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8271 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008272 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008273 },
Nick Harper60edffd2016-06-21 15:19:24 -07008274 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008275 })
8276 testCases = append(testCases, testCase{
8277 name: "Agree-Digest-Default",
8278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008279 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008280 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008281 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008282 signatureRSAPKCS1WithSHA256,
8283 signatureECDSAWithP256AndSHA256,
8284 signatureRSAPKCS1WithSHA1,
8285 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008286 },
8287 },
8288 flags: []string{
8289 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8290 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8291 },
Nick Harper60edffd2016-06-21 15:19:24 -07008292 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008293 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008294
David Benjaminca3d5452016-07-14 12:51:01 -04008295 // Test that the signing preference list may include extra algorithms
8296 // without negotiation problems.
8297 testCases = append(testCases, testCase{
8298 testType: serverTest,
8299 name: "FilterExtraAlgorithms",
8300 config: Config{
8301 MaxVersion: VersionTLS12,
8302 VerifySignatureAlgorithms: []signatureAlgorithm{
8303 signatureRSAPKCS1WithSHA256,
8304 },
8305 },
8306 flags: []string{
8307 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8308 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8309 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8310 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8311 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8312 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8313 },
8314 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8315 })
8316
David Benjamin4c3ddf72016-06-29 18:13:53 -04008317 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8318 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008319 testCases = append(testCases, testCase{
8320 name: "CheckLeafCurve",
8321 config: Config{
8322 MaxVersion: VersionTLS12,
8323 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008324 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008325 },
8326 flags: []string{"-p384-only"},
8327 shouldFail: true,
8328 expectedError: ":BAD_ECC_CERT:",
8329 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008330
8331 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8332 testCases = append(testCases, testCase{
8333 name: "CheckLeafCurve-TLS13",
8334 config: Config{
8335 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008336 Certificates: []Certificate{ecdsaP256Certificate},
8337 },
8338 flags: []string{"-p384-only"},
8339 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008340
8341 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8342 testCases = append(testCases, testCase{
8343 name: "ECDSACurveMismatch-Verify-TLS12",
8344 config: Config{
8345 MaxVersion: VersionTLS12,
8346 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8347 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008348 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008349 signatureECDSAWithP384AndSHA384,
8350 },
8351 },
8352 })
8353
8354 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8355 testCases = append(testCases, testCase{
8356 name: "ECDSACurveMismatch-Verify-TLS13",
8357 config: Config{
8358 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008359 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008360 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008361 signatureECDSAWithP384AndSHA384,
8362 },
8363 Bugs: ProtocolBugs{
8364 SkipECDSACurveCheck: true,
8365 },
8366 },
8367 shouldFail: true,
8368 expectedError: ":WRONG_SIGNATURE_TYPE:",
8369 })
8370
8371 // Signature algorithm selection in TLS 1.3 should take the curve into
8372 // account.
8373 testCases = append(testCases, testCase{
8374 testType: serverTest,
8375 name: "ECDSACurveMismatch-Sign-TLS13",
8376 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008377 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008378 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008379 signatureECDSAWithP384AndSHA384,
8380 signatureECDSAWithP256AndSHA256,
8381 },
8382 },
8383 flags: []string{
8384 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8385 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8386 },
8387 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8388 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008389
8390 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8391 // server does not attempt to sign in that case.
8392 testCases = append(testCases, testCase{
8393 testType: serverTest,
8394 name: "RSA-PSS-Large",
8395 config: Config{
8396 MaxVersion: VersionTLS13,
8397 VerifySignatureAlgorithms: []signatureAlgorithm{
8398 signatureRSAPSSWithSHA512,
8399 },
8400 },
8401 flags: []string{
8402 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8403 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8404 },
8405 shouldFail: true,
8406 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8407 })
David Benjamin57e929f2016-08-30 00:30:38 -04008408
8409 // Test that RSA-PSS is enabled by default for TLS 1.2.
8410 testCases = append(testCases, testCase{
8411 testType: clientTest,
8412 name: "RSA-PSS-Default-Verify",
8413 config: Config{
8414 MaxVersion: VersionTLS12,
8415 SignSignatureAlgorithms: []signatureAlgorithm{
8416 signatureRSAPSSWithSHA256,
8417 },
8418 },
8419 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8420 })
8421
8422 testCases = append(testCases, testCase{
8423 testType: serverTest,
8424 name: "RSA-PSS-Default-Sign",
8425 config: Config{
8426 MaxVersion: VersionTLS12,
8427 VerifySignatureAlgorithms: []signatureAlgorithm{
8428 signatureRSAPSSWithSHA256,
8429 },
8430 },
8431 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8432 })
David Benjamin69522112017-03-28 15:38:29 -05008433
8434 // TLS 1.1 and below has no way to advertise support for or negotiate
8435 // Ed25519's signature algorithm.
8436 testCases = append(testCases, testCase{
8437 testType: clientTest,
8438 name: "NoEd25519-TLS11-ServerAuth-Verify",
8439 config: Config{
8440 MaxVersion: VersionTLS11,
8441 Certificates: []Certificate{ed25519Certificate},
8442 Bugs: ProtocolBugs{
8443 // Sign with Ed25519 even though it is TLS 1.1.
8444 UseLegacySigningAlgorithm: signatureEd25519,
8445 },
8446 },
8447 flags: []string{"-enable-ed25519"},
8448 shouldFail: true,
8449 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8450 })
8451 testCases = append(testCases, testCase{
8452 testType: serverTest,
8453 name: "NoEd25519-TLS11-ServerAuth-Sign",
8454 config: Config{
8455 MaxVersion: VersionTLS11,
8456 },
8457 flags: []string{
8458 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8459 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8460 },
8461 shouldFail: true,
8462 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8463 })
8464 testCases = append(testCases, testCase{
8465 testType: serverTest,
8466 name: "NoEd25519-TLS11-ClientAuth-Verify",
8467 config: Config{
8468 MaxVersion: VersionTLS11,
8469 Certificates: []Certificate{ed25519Certificate},
8470 Bugs: ProtocolBugs{
8471 // Sign with Ed25519 even though it is TLS 1.1.
8472 UseLegacySigningAlgorithm: signatureEd25519,
8473 },
8474 },
8475 flags: []string{
8476 "-enable-ed25519",
8477 "-require-any-client-certificate",
8478 },
8479 shouldFail: true,
8480 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8481 })
8482 testCases = append(testCases, testCase{
8483 testType: clientTest,
8484 name: "NoEd25519-TLS11-ClientAuth-Sign",
8485 config: Config{
8486 MaxVersion: VersionTLS11,
8487 ClientAuth: RequireAnyClientCert,
8488 },
8489 flags: []string{
8490 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8491 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8492 },
8493 shouldFail: true,
8494 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8495 })
8496
8497 // Test Ed25519 is not advertised by default.
8498 testCases = append(testCases, testCase{
8499 testType: clientTest,
8500 name: "Ed25519DefaultDisable-NoAdvertise",
8501 config: Config{
8502 Certificates: []Certificate{ed25519Certificate},
8503 },
8504 shouldFail: true,
8505 expectedLocalError: "tls: no common signature algorithms",
8506 })
8507
8508 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8509 // preferences.
8510 testCases = append(testCases, testCase{
8511 testType: clientTest,
8512 name: "Ed25519DefaultDisable-NoAccept",
8513 config: Config{
8514 Certificates: []Certificate{ed25519Certificate},
8515 Bugs: ProtocolBugs{
8516 IgnorePeerSignatureAlgorithmPreferences: true,
8517 },
8518 },
8519 shouldFail: true,
8520 expectedLocalError: "remote error: illegal parameter",
8521 expectedError: ":WRONG_SIGNATURE_TYPE:",
8522 })
David Benjamin71c21b42017-04-14 17:05:40 -04008523
8524 // Test that configuring verify preferences changes what the client
8525 // advertises.
8526 testCases = append(testCases, testCase{
8527 name: "VerifyPreferences-Advertised",
8528 config: Config{
8529 Certificates: []Certificate{rsaCertificate},
8530 SignSignatureAlgorithms: []signatureAlgorithm{
8531 signatureRSAPSSWithSHA256,
8532 signatureRSAPSSWithSHA384,
8533 signatureRSAPSSWithSHA512,
8534 },
8535 },
8536 flags: []string{
8537 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8538 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8539 },
8540 })
8541
8542 // Test that the client advertises a set which the runner can find
8543 // nothing in common with.
8544 testCases = append(testCases, testCase{
8545 name: "VerifyPreferences-NoCommonAlgorithms",
8546 config: Config{
8547 Certificates: []Certificate{rsaCertificate},
8548 SignSignatureAlgorithms: []signatureAlgorithm{
8549 signatureRSAPSSWithSHA256,
8550 signatureRSAPSSWithSHA512,
8551 },
8552 },
8553 flags: []string{
8554 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8555 },
8556 shouldFail: true,
8557 expectedLocalError: "tls: no common signature algorithms",
8558 })
8559
8560 // Test that the client enforces its preferences when configured.
8561 testCases = append(testCases, testCase{
8562 name: "VerifyPreferences-Enforced",
8563 config: Config{
8564 Certificates: []Certificate{rsaCertificate},
8565 SignSignatureAlgorithms: []signatureAlgorithm{
8566 signatureRSAPSSWithSHA256,
8567 signatureRSAPSSWithSHA512,
8568 },
8569 Bugs: ProtocolBugs{
8570 IgnorePeerSignatureAlgorithmPreferences: true,
8571 },
8572 },
8573 flags: []string{
8574 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8575 },
8576 shouldFail: true,
8577 expectedLocalError: "remote error: illegal parameter",
8578 expectedError: ":WRONG_SIGNATURE_TYPE:",
8579 })
8580
8581 // Test that explicitly configuring Ed25519 is as good as changing the
8582 // boolean toggle.
8583 testCases = append(testCases, testCase{
8584 name: "VerifyPreferences-Ed25519",
8585 config: Config{
8586 Certificates: []Certificate{ed25519Certificate},
8587 },
8588 flags: []string{
8589 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8590 },
8591 })
David Benjamin000800a2014-11-14 01:43:59 -05008592}
8593
David Benjamin83f90402015-01-27 01:09:43 -05008594// timeouts is the retransmit schedule for BoringSSL. It doubles and
8595// caps at 60 seconds. On the 13th timeout, it gives up.
8596var timeouts = []time.Duration{
8597 1 * time.Second,
8598 2 * time.Second,
8599 4 * time.Second,
8600 8 * time.Second,
8601 16 * time.Second,
8602 32 * time.Second,
8603 60 * time.Second,
8604 60 * time.Second,
8605 60 * time.Second,
8606 60 * time.Second,
8607 60 * time.Second,
8608 60 * time.Second,
8609 60 * time.Second,
8610}
8611
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008612// shortTimeouts is an alternate set of timeouts which would occur if the
8613// initial timeout duration was set to 250ms.
8614var shortTimeouts = []time.Duration{
8615 250 * time.Millisecond,
8616 500 * time.Millisecond,
8617 1 * time.Second,
8618 2 * time.Second,
8619 4 * time.Second,
8620 8 * time.Second,
8621 16 * time.Second,
8622 32 * time.Second,
8623 60 * time.Second,
8624 60 * time.Second,
8625 60 * time.Second,
8626 60 * time.Second,
8627 60 * time.Second,
8628}
8629
David Benjamin83f90402015-01-27 01:09:43 -05008630func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008631 // These tests work by coordinating some behavior on both the shim and
8632 // the runner.
8633 //
8634 // TimeoutSchedule configures the runner to send a series of timeout
8635 // opcodes to the shim (see packetAdaptor) immediately before reading
8636 // each peer handshake flight N. The timeout opcode both simulates a
8637 // timeout in the shim and acts as a synchronization point to help the
8638 // runner bracket each handshake flight.
8639 //
8640 // We assume the shim does not read from the channel eagerly. It must
8641 // first wait until it has sent flight N and is ready to receive
8642 // handshake flight N+1. At this point, it will process the timeout
8643 // opcode. It must then immediately respond with a timeout ACK and act
8644 // as if the shim was idle for the specified amount of time.
8645 //
8646 // The runner then drops all packets received before the ACK and
8647 // continues waiting for flight N. This ordering results in one attempt
8648 // at sending flight N to be dropped. For the test to complete, the
8649 // shim must send flight N again, testing that the shim implements DTLS
8650 // retransmit on a timeout.
8651
Steven Valdez143e8b32016-07-11 13:19:03 -04008652 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008653 // likely be more epochs to cross and the final message's retransmit may
8654 // be more complex.
8655
David Benjamin11c82892017-02-23 20:40:31 -05008656 // Test that this is indeed the timeout schedule. Stress all
8657 // four patterns of handshake.
8658 for i := 1; i < len(timeouts); i++ {
8659 number := strconv.Itoa(i)
8660 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008661 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008662 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008664 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008665 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008666 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008667 },
8668 },
8669 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008670 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008671 })
David Benjamin11c82892017-02-23 20:40:31 -05008672 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008673 protocol: dtls,
8674 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008675 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008677 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008678 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008679 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008680 },
8681 },
8682 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008683 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008684 })
8685 }
David Benjamin11c82892017-02-23 20:40:31 -05008686
8687 // Test that exceeding the timeout schedule hits a read
8688 // timeout.
8689 testCases = append(testCases, testCase{
8690 protocol: dtls,
8691 name: "DTLS-Retransmit-Timeout",
8692 config: Config{
8693 MaxVersion: VersionTLS12,
8694 Bugs: ProtocolBugs{
8695 TimeoutSchedule: timeouts,
8696 },
8697 },
8698 resumeSession: true,
8699 flags: []string{"-async"},
8700 shouldFail: true,
8701 expectedError: ":READ_TIMEOUT_EXPIRED:",
8702 })
8703
8704 // Test that timeout handling has a fudge factor, due to API
8705 // problems.
8706 testCases = append(testCases, testCase{
8707 protocol: dtls,
8708 name: "DTLS-Retransmit-Fudge",
8709 config: Config{
8710 MaxVersion: VersionTLS12,
8711 Bugs: ProtocolBugs{
8712 TimeoutSchedule: []time.Duration{
8713 timeouts[0] - 10*time.Millisecond,
8714 },
8715 },
8716 },
8717 resumeSession: true,
8718 flags: []string{"-async"},
8719 })
8720
8721 // Test that the final Finished retransmitting isn't
8722 // duplicated if the peer badly fragments everything.
8723 testCases = append(testCases, testCase{
8724 testType: serverTest,
8725 protocol: dtls,
8726 name: "DTLS-Retransmit-Fragmented",
8727 config: Config{
8728 MaxVersion: VersionTLS12,
8729 Bugs: ProtocolBugs{
8730 TimeoutSchedule: []time.Duration{timeouts[0]},
8731 MaxHandshakeRecordLength: 2,
8732 },
8733 },
8734 flags: []string{"-async"},
8735 })
8736
8737 // Test the timeout schedule when a shorter initial timeout duration is set.
8738 testCases = append(testCases, testCase{
8739 protocol: dtls,
8740 name: "DTLS-Retransmit-Short-Client",
8741 config: Config{
8742 MaxVersion: VersionTLS12,
8743 Bugs: ProtocolBugs{
8744 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8745 },
8746 },
8747 resumeSession: true,
8748 flags: []string{
8749 "-async",
8750 "-initial-timeout-duration-ms", "250",
8751 },
8752 })
8753 testCases = append(testCases, testCase{
8754 protocol: dtls,
8755 testType: serverTest,
8756 name: "DTLS-Retransmit-Short-Server",
8757 config: Config{
8758 MaxVersion: VersionTLS12,
8759 Bugs: ProtocolBugs{
8760 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8761 },
8762 },
8763 resumeSession: true,
8764 flags: []string{
8765 "-async",
8766 "-initial-timeout-duration-ms", "250",
8767 },
8768 })
David Benjamin83f90402015-01-27 01:09:43 -05008769}
8770
David Benjaminc565ebb2015-04-03 04:06:36 -04008771func addExportKeyingMaterialTests() {
8772 for _, vers := range tlsVersions {
8773 if vers.version == VersionSSL30 {
8774 continue
8775 }
8776 testCases = append(testCases, testCase{
8777 name: "ExportKeyingMaterial-" + vers.name,
8778 config: Config{
8779 MaxVersion: vers.version,
8780 },
David Benjamina5022392017-07-10 17:40:39 -04008781 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008782 exportKeyingMaterial: 1024,
8783 exportLabel: "label",
8784 exportContext: "context",
8785 useExportContext: true,
8786 })
8787 testCases = append(testCases, testCase{
8788 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8789 config: Config{
8790 MaxVersion: vers.version,
8791 },
David Benjamina5022392017-07-10 17:40:39 -04008792 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008793 exportKeyingMaterial: 1024,
8794 })
8795 testCases = append(testCases, testCase{
8796 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8797 config: Config{
8798 MaxVersion: vers.version,
8799 },
David Benjamina5022392017-07-10 17:40:39 -04008800 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008801 exportKeyingMaterial: 1024,
8802 useExportContext: true,
8803 })
8804 testCases = append(testCases, testCase{
8805 name: "ExportKeyingMaterial-Small-" + vers.name,
8806 config: Config{
8807 MaxVersion: vers.version,
8808 },
David Benjamina5022392017-07-10 17:40:39 -04008809 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008810 exportKeyingMaterial: 1,
8811 exportLabel: "label",
8812 exportContext: "context",
8813 useExportContext: true,
8814 })
8815 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008816
David Benjaminc565ebb2015-04-03 04:06:36 -04008817 testCases = append(testCases, testCase{
8818 name: "ExportKeyingMaterial-SSL3",
8819 config: Config{
8820 MaxVersion: VersionSSL30,
8821 },
8822 exportKeyingMaterial: 1024,
8823 exportLabel: "label",
8824 exportContext: "context",
8825 useExportContext: true,
8826 shouldFail: true,
8827 expectedError: "failed to export keying material",
8828 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008829
8830 // Exporters work during a False Start.
8831 testCases = append(testCases, testCase{
8832 name: "ExportKeyingMaterial-FalseStart",
8833 config: Config{
8834 MaxVersion: VersionTLS12,
8835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8836 NextProtos: []string{"foo"},
8837 Bugs: ProtocolBugs{
8838 ExpectFalseStart: true,
8839 },
8840 },
8841 flags: []string{
8842 "-false-start",
8843 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008844 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008845 },
8846 shimWritesFirst: true,
8847 exportKeyingMaterial: 1024,
8848 exportLabel: "label",
8849 exportContext: "context",
8850 useExportContext: true,
8851 })
8852
8853 // Exporters do not work in the middle of a renegotiation. Test this by
8854 // triggering the exporter after every SSL_read call and configuring the
8855 // shim to run asynchronously.
8856 testCases = append(testCases, testCase{
8857 name: "ExportKeyingMaterial-Renegotiate",
8858 config: Config{
8859 MaxVersion: VersionTLS12,
8860 },
8861 renegotiate: 1,
8862 flags: []string{
8863 "-async",
8864 "-use-exporter-between-reads",
8865 "-renegotiate-freely",
8866 "-expect-total-renegotiations", "1",
8867 },
8868 shouldFail: true,
8869 expectedError: "failed to export keying material",
8870 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008871}
8872
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008873func addTLSUniqueTests() {
8874 for _, isClient := range []bool{false, true} {
8875 for _, isResumption := range []bool{false, true} {
8876 for _, hasEMS := range []bool{false, true} {
8877 var suffix string
8878 if isResumption {
8879 suffix = "Resume-"
8880 } else {
8881 suffix = "Full-"
8882 }
8883
8884 if hasEMS {
8885 suffix += "EMS-"
8886 } else {
8887 suffix += "NoEMS-"
8888 }
8889
8890 if isClient {
8891 suffix += "Client"
8892 } else {
8893 suffix += "Server"
8894 }
8895
8896 test := testCase{
8897 name: "TLSUnique-" + suffix,
8898 testTLSUnique: true,
8899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008900 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008901 Bugs: ProtocolBugs{
8902 NoExtendedMasterSecret: !hasEMS,
8903 },
8904 },
8905 }
8906
8907 if isResumption {
8908 test.resumeSession = true
8909 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008910 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008911 Bugs: ProtocolBugs{
8912 NoExtendedMasterSecret: !hasEMS,
8913 },
8914 }
8915 }
8916
8917 if isResumption && !hasEMS {
8918 test.shouldFail = true
8919 test.expectedError = "failed to get tls-unique"
8920 }
8921
8922 testCases = append(testCases, test)
8923 }
8924 }
8925 }
8926}
8927
Adam Langley09505632015-07-30 18:10:13 -07008928func addCustomExtensionTests() {
8929 expectedContents := "custom extension"
8930 emptyString := ""
8931
8932 for _, isClient := range []bool{false, true} {
8933 suffix := "Server"
8934 flag := "-enable-server-custom-extension"
8935 testType := serverTest
8936 if isClient {
8937 suffix = "Client"
8938 flag = "-enable-client-custom-extension"
8939 testType = clientTest
8940 }
8941
8942 testCases = append(testCases, testCase{
8943 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008944 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008946 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008947 Bugs: ProtocolBugs{
8948 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008949 ExpectedCustomExtension: &expectedContents,
8950 },
8951 },
8952 flags: []string{flag},
8953 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008954 testCases = append(testCases, testCase{
8955 testType: testType,
8956 name: "CustomExtensions-" + suffix + "-TLS13",
8957 config: Config{
8958 MaxVersion: VersionTLS13,
8959 Bugs: ProtocolBugs{
8960 CustomExtension: expectedContents,
8961 ExpectedCustomExtension: &expectedContents,
8962 },
8963 },
8964 flags: []string{flag},
8965 })
Adam Langley09505632015-07-30 18:10:13 -07008966
Steven Valdez2a070722017-03-25 20:54:16 -05008967 // 0-RTT is not currently supported with Custom Extensions.
8968 testCases = append(testCases, testCase{
8969 testType: testType,
8970 name: "CustomExtensions-" + suffix + "-EarlyData",
8971 config: Config{
8972 MaxVersion: VersionTLS13,
8973 Bugs: ProtocolBugs{
8974 CustomExtension: expectedContents,
8975 ExpectedCustomExtension: &expectedContents,
8976 },
8977 },
8978 shouldFail: true,
8979 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8980 flags: []string{flag, "-enable-early-data"},
8981 })
8982
Adam Langley09505632015-07-30 18:10:13 -07008983 // If the parse callback fails, the handshake should also fail.
8984 testCases = append(testCases, testCase{
8985 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008986 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008987 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008988 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008989 Bugs: ProtocolBugs{
8990 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008991 ExpectedCustomExtension: &expectedContents,
8992 },
8993 },
David Benjamin399e7c92015-07-30 23:01:27 -04008994 flags: []string{flag},
8995 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008996 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8997 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008998 testCases = append(testCases, testCase{
8999 testType: testType,
9000 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9001 config: Config{
9002 MaxVersion: VersionTLS13,
9003 Bugs: ProtocolBugs{
9004 CustomExtension: expectedContents + "foo",
9005 ExpectedCustomExtension: &expectedContents,
9006 },
9007 },
9008 flags: []string{flag},
9009 shouldFail: true,
9010 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9011 })
Adam Langley09505632015-07-30 18:10:13 -07009012
9013 // If the add callback fails, the handshake should also fail.
9014 testCases = append(testCases, testCase{
9015 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009016 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009017 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009018 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009019 Bugs: ProtocolBugs{
9020 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009021 ExpectedCustomExtension: &expectedContents,
9022 },
9023 },
David Benjamin399e7c92015-07-30 23:01:27 -04009024 flags: []string{flag, "-custom-extension-fail-add"},
9025 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009026 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9027 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009028 testCases = append(testCases, testCase{
9029 testType: testType,
9030 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9031 config: Config{
9032 MaxVersion: VersionTLS13,
9033 Bugs: ProtocolBugs{
9034 CustomExtension: expectedContents,
9035 ExpectedCustomExtension: &expectedContents,
9036 },
9037 },
9038 flags: []string{flag, "-custom-extension-fail-add"},
9039 shouldFail: true,
9040 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9041 })
Adam Langley09505632015-07-30 18:10:13 -07009042
9043 // If the add callback returns zero, no extension should be
9044 // added.
9045 skipCustomExtension := expectedContents
9046 if isClient {
9047 // For the case where the client skips sending the
9048 // custom extension, the server must not “echo” it.
9049 skipCustomExtension = ""
9050 }
9051 testCases = append(testCases, testCase{
9052 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009053 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009055 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009056 Bugs: ProtocolBugs{
9057 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009058 ExpectedCustomExtension: &emptyString,
9059 },
9060 },
9061 flags: []string{flag, "-custom-extension-skip"},
9062 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009063 testCases = append(testCases, testCase{
9064 testType: testType,
9065 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9066 config: Config{
9067 MaxVersion: VersionTLS13,
9068 Bugs: ProtocolBugs{
9069 CustomExtension: skipCustomExtension,
9070 ExpectedCustomExtension: &emptyString,
9071 },
9072 },
9073 flags: []string{flag, "-custom-extension-skip"},
9074 })
Adam Langley09505632015-07-30 18:10:13 -07009075 }
9076
9077 // The custom extension add callback should not be called if the client
9078 // doesn't send the extension.
9079 testCases = append(testCases, testCase{
9080 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009081 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009083 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009084 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009085 ExpectedCustomExtension: &emptyString,
9086 },
9087 },
9088 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9089 })
Adam Langley2deb9842015-08-07 11:15:37 -07009090
Steven Valdez143e8b32016-07-11 13:19:03 -04009091 testCases = append(testCases, testCase{
9092 testType: serverTest,
9093 name: "CustomExtensions-NotCalled-Server-TLS13",
9094 config: Config{
9095 MaxVersion: VersionTLS13,
9096 Bugs: ProtocolBugs{
9097 ExpectedCustomExtension: &emptyString,
9098 },
9099 },
9100 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9101 })
9102
Adam Langley2deb9842015-08-07 11:15:37 -07009103 // Test an unknown extension from the server.
9104 testCases = append(testCases, testCase{
9105 testType: clientTest,
9106 name: "UnknownExtension-Client",
9107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009108 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009109 Bugs: ProtocolBugs{
9110 CustomExtension: expectedContents,
9111 },
9112 },
David Benjamin0c40a962016-08-01 12:05:50 -04009113 shouldFail: true,
9114 expectedError: ":UNEXPECTED_EXTENSION:",
9115 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009116 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009117 testCases = append(testCases, testCase{
9118 testType: clientTest,
9119 name: "UnknownExtension-Client-TLS13",
9120 config: Config{
9121 MaxVersion: VersionTLS13,
9122 Bugs: ProtocolBugs{
9123 CustomExtension: expectedContents,
9124 },
9125 },
David Benjamin0c40a962016-08-01 12:05:50 -04009126 shouldFail: true,
9127 expectedError: ":UNEXPECTED_EXTENSION:",
9128 expectedLocalError: "remote error: unsupported extension",
9129 })
David Benjamin490469f2016-10-05 22:44:38 -04009130 testCases = append(testCases, testCase{
9131 testType: clientTest,
9132 name: "UnknownUnencryptedExtension-Client-TLS13",
9133 config: Config{
9134 MaxVersion: VersionTLS13,
9135 Bugs: ProtocolBugs{
9136 CustomUnencryptedExtension: expectedContents,
9137 },
9138 },
9139 shouldFail: true,
9140 expectedError: ":UNEXPECTED_EXTENSION:",
9141 // The shim must send an alert, but alerts at this point do not
9142 // get successfully decrypted by the runner.
9143 expectedLocalError: "local error: bad record MAC",
9144 })
9145 testCases = append(testCases, testCase{
9146 testType: clientTest,
9147 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9148 config: Config{
9149 MaxVersion: VersionTLS13,
9150 Bugs: ProtocolBugs{
9151 SendUnencryptedALPN: "foo",
9152 },
9153 },
9154 flags: []string{
9155 "-advertise-alpn", "\x03foo\x03bar",
9156 },
9157 shouldFail: true,
9158 expectedError: ":UNEXPECTED_EXTENSION:",
9159 // The shim must send an alert, but alerts at this point do not
9160 // get successfully decrypted by the runner.
9161 expectedLocalError: "local error: bad record MAC",
9162 })
David Benjamin0c40a962016-08-01 12:05:50 -04009163
9164 // Test a known but unoffered extension from the server.
9165 testCases = append(testCases, testCase{
9166 testType: clientTest,
9167 name: "UnofferedExtension-Client",
9168 config: Config{
9169 MaxVersion: VersionTLS12,
9170 Bugs: ProtocolBugs{
9171 SendALPN: "alpn",
9172 },
9173 },
9174 shouldFail: true,
9175 expectedError: ":UNEXPECTED_EXTENSION:",
9176 expectedLocalError: "remote error: unsupported extension",
9177 })
9178 testCases = append(testCases, testCase{
9179 testType: clientTest,
9180 name: "UnofferedExtension-Client-TLS13",
9181 config: Config{
9182 MaxVersion: VersionTLS13,
9183 Bugs: ProtocolBugs{
9184 SendALPN: "alpn",
9185 },
9186 },
9187 shouldFail: true,
9188 expectedError: ":UNEXPECTED_EXTENSION:",
9189 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009190 })
Adam Langley09505632015-07-30 18:10:13 -07009191}
9192
David Benjaminb36a3952015-12-01 18:53:13 -05009193func addRSAClientKeyExchangeTests() {
9194 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9195 testCases = append(testCases, testCase{
9196 testType: serverTest,
9197 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9198 config: Config{
9199 // Ensure the ClientHello version and final
9200 // version are different, to detect if the
9201 // server uses the wrong one.
9202 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009203 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009204 Bugs: ProtocolBugs{
9205 BadRSAClientKeyExchange: bad,
9206 },
9207 },
9208 shouldFail: true,
9209 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9210 })
9211 }
David Benjamine63d9d72016-09-19 18:27:34 -04009212
9213 // The server must compare whatever was in ClientHello.version for the
9214 // RSA premaster.
9215 testCases = append(testCases, testCase{
9216 testType: serverTest,
9217 name: "SendClientVersion-RSA",
9218 config: Config{
9219 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9220 Bugs: ProtocolBugs{
9221 SendClientVersion: 0x1234,
9222 },
9223 },
9224 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9225 })
David Benjaminb36a3952015-12-01 18:53:13 -05009226}
9227
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009228var testCurves = []struct {
9229 name string
9230 id CurveID
9231}{
Adam Langley764ab982017-03-10 18:01:30 -08009232 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009233 {"P-256", CurveP256},
9234 {"P-384", CurveP384},
9235 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009236 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009237}
9238
Steven Valdez5440fe02016-07-18 12:40:30 -04009239const bogusCurve = 0x1234
9240
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009241func addCurveTests() {
9242 for _, curve := range testCurves {
9243 testCases = append(testCases, testCase{
9244 name: "CurveTest-Client-" + curve.name,
9245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009246 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009247 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9248 CurvePreferences: []CurveID{curve.id},
9249 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009250 flags: []string{
9251 "-enable-all-curves",
9252 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9253 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009254 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009255 })
9256 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009257 name: "CurveTest-Client-" + curve.name + "-TLS13",
9258 config: Config{
9259 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009260 CurvePreferences: []CurveID{curve.id},
9261 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009262 flags: []string{
9263 "-enable-all-curves",
9264 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9265 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009266 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009267 })
9268 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009269 testType: serverTest,
9270 name: "CurveTest-Server-" + curve.name,
9271 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009272 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009273 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9274 CurvePreferences: []CurveID{curve.id},
9275 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009276 flags: []string{
9277 "-enable-all-curves",
9278 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9279 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009280 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009281 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009282 testCases = append(testCases, testCase{
9283 testType: serverTest,
9284 name: "CurveTest-Server-" + curve.name + "-TLS13",
9285 config: Config{
9286 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009287 CurvePreferences: []CurveID{curve.id},
9288 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009289 flags: []string{
9290 "-enable-all-curves",
9291 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9292 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009293 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009294 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009295 }
David Benjamin241ae832016-01-15 03:04:54 -05009296
9297 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009298 testCases = append(testCases, testCase{
9299 testType: serverTest,
9300 name: "UnknownCurve",
9301 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009302 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009303 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9304 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9305 },
9306 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009307
Steven Valdez803c77a2016-09-06 14:13:43 -04009308 // The server must be tolerant to bogus curves.
9309 testCases = append(testCases, testCase{
9310 testType: serverTest,
9311 name: "UnknownCurve-TLS13",
9312 config: Config{
9313 MaxVersion: VersionTLS13,
9314 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9315 },
9316 })
9317
David Benjamin4c3ddf72016-06-29 18:13:53 -04009318 // The server must not consider ECDHE ciphers when there are no
9319 // supported curves.
9320 testCases = append(testCases, testCase{
9321 testType: serverTest,
9322 name: "NoSupportedCurves",
9323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009324 MaxVersion: VersionTLS12,
9325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9326 Bugs: ProtocolBugs{
9327 NoSupportedCurves: true,
9328 },
9329 },
9330 shouldFail: true,
9331 expectedError: ":NO_SHARED_CIPHER:",
9332 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009333 testCases = append(testCases, testCase{
9334 testType: serverTest,
9335 name: "NoSupportedCurves-TLS13",
9336 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009337 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009338 Bugs: ProtocolBugs{
9339 NoSupportedCurves: true,
9340 },
9341 },
9342 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009343 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009344 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009345
9346 // The server must fall back to another cipher when there are no
9347 // supported curves.
9348 testCases = append(testCases, testCase{
9349 testType: serverTest,
9350 name: "NoCommonCurves",
9351 config: Config{
9352 MaxVersion: VersionTLS12,
9353 CipherSuites: []uint16{
9354 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009355 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009356 },
9357 CurvePreferences: []CurveID{CurveP224},
9358 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009359 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009360 })
9361
9362 // The client must reject bogus curves and disabled curves.
9363 testCases = append(testCases, testCase{
9364 name: "BadECDHECurve",
9365 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009366 MaxVersion: VersionTLS12,
9367 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9368 Bugs: ProtocolBugs{
9369 SendCurve: bogusCurve,
9370 },
9371 },
9372 shouldFail: true,
9373 expectedError: ":WRONG_CURVE:",
9374 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009375 testCases = append(testCases, testCase{
9376 name: "BadECDHECurve-TLS13",
9377 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009378 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009379 Bugs: ProtocolBugs{
9380 SendCurve: bogusCurve,
9381 },
9382 },
9383 shouldFail: true,
9384 expectedError: ":WRONG_CURVE:",
9385 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009386
9387 testCases = append(testCases, testCase{
9388 name: "UnsupportedCurve",
9389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009390 MaxVersion: VersionTLS12,
9391 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9392 CurvePreferences: []CurveID{CurveP256},
9393 Bugs: ProtocolBugs{
9394 IgnorePeerCurvePreferences: true,
9395 },
9396 },
9397 flags: []string{"-p384-only"},
9398 shouldFail: true,
9399 expectedError: ":WRONG_CURVE:",
9400 })
9401
David Benjamin4f921572016-07-17 14:20:10 +02009402 testCases = append(testCases, testCase{
9403 // TODO(davidben): Add a TLS 1.3 version where
9404 // HelloRetryRequest requests an unsupported curve.
9405 name: "UnsupportedCurve-ServerHello-TLS13",
9406 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009407 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009408 CurvePreferences: []CurveID{CurveP384},
9409 Bugs: ProtocolBugs{
9410 SendCurve: CurveP256,
9411 },
9412 },
9413 flags: []string{"-p384-only"},
9414 shouldFail: true,
9415 expectedError: ":WRONG_CURVE:",
9416 })
9417
David Benjamin4c3ddf72016-06-29 18:13:53 -04009418 // Test invalid curve points.
9419 testCases = append(testCases, testCase{
9420 name: "InvalidECDHPoint-Client",
9421 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009422 MaxVersion: VersionTLS12,
9423 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9424 CurvePreferences: []CurveID{CurveP256},
9425 Bugs: ProtocolBugs{
9426 InvalidECDHPoint: true,
9427 },
9428 },
9429 shouldFail: true,
9430 expectedError: ":INVALID_ENCODING:",
9431 })
9432 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009433 name: "InvalidECDHPoint-Client-TLS13",
9434 config: Config{
9435 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009436 CurvePreferences: []CurveID{CurveP256},
9437 Bugs: ProtocolBugs{
9438 InvalidECDHPoint: true,
9439 },
9440 },
9441 shouldFail: true,
9442 expectedError: ":INVALID_ENCODING:",
9443 })
9444 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009445 testType: serverTest,
9446 name: "InvalidECDHPoint-Server",
9447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009448 MaxVersion: VersionTLS12,
9449 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9450 CurvePreferences: []CurveID{CurveP256},
9451 Bugs: ProtocolBugs{
9452 InvalidECDHPoint: true,
9453 },
9454 },
9455 shouldFail: true,
9456 expectedError: ":INVALID_ENCODING:",
9457 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009458 testCases = append(testCases, testCase{
9459 testType: serverTest,
9460 name: "InvalidECDHPoint-Server-TLS13",
9461 config: Config{
9462 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009463 CurvePreferences: []CurveID{CurveP256},
9464 Bugs: ProtocolBugs{
9465 InvalidECDHPoint: true,
9466 },
9467 },
9468 shouldFail: true,
9469 expectedError: ":INVALID_ENCODING:",
9470 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009471
9472 // The previous curve ID should be reported on TLS 1.2 resumption.
9473 testCases = append(testCases, testCase{
9474 name: "CurveID-Resume-Client",
9475 config: Config{
9476 MaxVersion: VersionTLS12,
9477 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9478 CurvePreferences: []CurveID{CurveX25519},
9479 },
9480 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9481 resumeSession: true,
9482 })
9483 testCases = append(testCases, testCase{
9484 testType: serverTest,
9485 name: "CurveID-Resume-Server",
9486 config: Config{
9487 MaxVersion: VersionTLS12,
9488 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9489 CurvePreferences: []CurveID{CurveX25519},
9490 },
9491 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9492 resumeSession: true,
9493 })
9494
9495 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9496 // one should be reported.
9497 testCases = append(testCases, testCase{
9498 name: "CurveID-Resume-Client-TLS13",
9499 config: Config{
9500 MaxVersion: VersionTLS13,
9501 CurvePreferences: []CurveID{CurveX25519},
9502 },
9503 resumeConfig: &Config{
9504 MaxVersion: VersionTLS13,
9505 CurvePreferences: []CurveID{CurveP256},
9506 },
9507 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009508 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9509 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009510 },
9511 resumeSession: true,
9512 })
9513 testCases = append(testCases, testCase{
9514 testType: serverTest,
9515 name: "CurveID-Resume-Server-TLS13",
9516 config: Config{
9517 MaxVersion: VersionTLS13,
9518 CurvePreferences: []CurveID{CurveX25519},
9519 },
9520 resumeConfig: &Config{
9521 MaxVersion: VersionTLS13,
9522 CurvePreferences: []CurveID{CurveP256},
9523 },
9524 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009525 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9526 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009527 },
9528 resumeSession: true,
9529 })
David Benjamina81967b2016-12-22 09:16:57 -05009530
9531 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9532 testCases = append(testCases, testCase{
9533 name: "PointFormat-ServerHello-TLS12",
9534 config: Config{
9535 MaxVersion: VersionTLS12,
9536 Bugs: ProtocolBugs{
9537 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9538 },
9539 },
9540 })
9541 testCases = append(testCases, testCase{
9542 name: "PointFormat-EncryptedExtensions-TLS13",
9543 config: Config{
9544 MaxVersion: VersionTLS13,
9545 Bugs: ProtocolBugs{
9546 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9547 },
9548 },
9549 shouldFail: true,
9550 expectedError: ":ERROR_PARSING_EXTENSION:",
9551 })
9552
9553 // Test that we tolerate unknown point formats, as long as
9554 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9555 // check they are still functional.
9556 testCases = append(testCases, testCase{
9557 name: "PointFormat-Client-Tolerance",
9558 config: Config{
9559 MaxVersion: VersionTLS12,
9560 Bugs: ProtocolBugs{
9561 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9562 },
9563 },
9564 })
9565 testCases = append(testCases, testCase{
9566 testType: serverTest,
9567 name: "PointFormat-Server-Tolerance",
9568 config: Config{
9569 MaxVersion: VersionTLS12,
9570 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9571 Bugs: ProtocolBugs{
9572 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9573 },
9574 },
9575 })
9576
9577 // Test TLS 1.2 does not require the point format extension to be
9578 // present.
9579 testCases = append(testCases, testCase{
9580 name: "PointFormat-Client-Missing",
9581 config: Config{
9582 MaxVersion: VersionTLS12,
9583 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9584 Bugs: ProtocolBugs{
9585 SendSupportedPointFormats: []byte{},
9586 },
9587 },
9588 })
9589 testCases = append(testCases, testCase{
9590 testType: serverTest,
9591 name: "PointFormat-Server-Missing",
9592 config: Config{
9593 MaxVersion: VersionTLS12,
9594 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9595 Bugs: ProtocolBugs{
9596 SendSupportedPointFormats: []byte{},
9597 },
9598 },
9599 })
9600
9601 // If the point format extension is present, uncompressed points must be
9602 // offered. BoringSSL requires this whether or not ECDHE is used.
9603 testCases = append(testCases, testCase{
9604 name: "PointFormat-Client-MissingUncompressed",
9605 config: Config{
9606 MaxVersion: VersionTLS12,
9607 Bugs: ProtocolBugs{
9608 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9609 },
9610 },
9611 shouldFail: true,
9612 expectedError: ":ERROR_PARSING_EXTENSION:",
9613 })
9614 testCases = append(testCases, testCase{
9615 testType: serverTest,
9616 name: "PointFormat-Server-MissingUncompressed",
9617 config: Config{
9618 MaxVersion: VersionTLS12,
9619 Bugs: ProtocolBugs{
9620 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9621 },
9622 },
9623 shouldFail: true,
9624 expectedError: ":ERROR_PARSING_EXTENSION:",
9625 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009626}
9627
David Benjaminc9ae27c2016-06-24 22:56:37 -04009628func addTLS13RecordTests() {
9629 testCases = append(testCases, testCase{
9630 name: "TLS13-RecordPadding",
9631 config: Config{
9632 MaxVersion: VersionTLS13,
9633 MinVersion: VersionTLS13,
9634 Bugs: ProtocolBugs{
9635 RecordPadding: 10,
9636 },
9637 },
9638 })
9639
9640 testCases = append(testCases, testCase{
9641 name: "TLS13-EmptyRecords",
9642 config: Config{
9643 MaxVersion: VersionTLS13,
9644 MinVersion: VersionTLS13,
9645 Bugs: ProtocolBugs{
9646 OmitRecordContents: true,
9647 },
9648 },
9649 shouldFail: true,
9650 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9651 })
9652
9653 testCases = append(testCases, testCase{
9654 name: "TLS13-OnlyPadding",
9655 config: Config{
9656 MaxVersion: VersionTLS13,
9657 MinVersion: VersionTLS13,
9658 Bugs: ProtocolBugs{
9659 OmitRecordContents: true,
9660 RecordPadding: 10,
9661 },
9662 },
9663 shouldFail: true,
9664 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9665 })
9666
9667 testCases = append(testCases, testCase{
9668 name: "TLS13-WrongOuterRecord",
9669 config: Config{
9670 MaxVersion: VersionTLS13,
9671 MinVersion: VersionTLS13,
9672 Bugs: ProtocolBugs{
9673 OuterRecordType: recordTypeHandshake,
9674 },
9675 },
9676 shouldFail: true,
9677 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9678 })
9679}
9680
Steven Valdez5b986082016-09-01 12:29:49 -04009681func addSessionTicketTests() {
9682 testCases = append(testCases, testCase{
9683 // In TLS 1.2 and below, empty NewSessionTicket messages
9684 // mean the server changed its mind on sending a ticket.
9685 name: "SendEmptySessionTicket",
9686 config: Config{
9687 MaxVersion: VersionTLS12,
9688 Bugs: ProtocolBugs{
9689 SendEmptySessionTicket: true,
9690 },
9691 },
9692 flags: []string{"-expect-no-session"},
9693 })
9694
9695 // Test that the server ignores unknown PSK modes.
9696 testCases = append(testCases, testCase{
9697 testType: serverTest,
9698 name: "TLS13-SendUnknownModeSessionTicket-Server",
9699 config: Config{
9700 MaxVersion: VersionTLS13,
9701 Bugs: ProtocolBugs{
9702 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009703 },
9704 },
9705 resumeSession: true,
9706 expectedResumeVersion: VersionTLS13,
9707 })
9708
Steven Valdeza833c352016-11-01 13:39:36 -04009709 // Test that the server does not send session tickets with no matching key exchange mode.
9710 testCases = append(testCases, testCase{
9711 testType: serverTest,
9712 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9713 config: Config{
9714 MaxVersion: VersionTLS13,
9715 Bugs: ProtocolBugs{
9716 SendPSKKeyExchangeModes: []byte{0x1a},
9717 ExpectNoNewSessionTicket: true,
9718 },
9719 },
9720 })
9721
9722 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009723 testCases = append(testCases, testCase{
9724 testType: serverTest,
9725 name: "TLS13-SendBadKEModeSessionTicket-Server",
9726 config: Config{
9727 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009728 },
9729 resumeConfig: &Config{
9730 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009731 Bugs: ProtocolBugs{
9732 SendPSKKeyExchangeModes: []byte{0x1a},
9733 },
9734 },
9735 resumeSession: true,
9736 expectResumeRejected: true,
9737 })
9738
Steven Valdeza833c352016-11-01 13:39:36 -04009739 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009740 testCases = append(testCases, testCase{
9741 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009742 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009743 config: Config{
9744 MaxVersion: VersionTLS13,
9745 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009746 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009747 },
9748 },
Steven Valdeza833c352016-11-01 13:39:36 -04009749 resumeSession: true,
9750 flags: []string{
9751 "-resumption-delay", "10",
9752 },
Steven Valdez5b986082016-09-01 12:29:49 -04009753 })
9754
Steven Valdeza833c352016-11-01 13:39:36 -04009755 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009756 testCases = append(testCases, testCase{
9757 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009758 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009759 config: Config{
9760 MaxVersion: VersionTLS13,
9761 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009762 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009763 },
9764 },
Steven Valdeza833c352016-11-01 13:39:36 -04009765 resumeSession: true,
9766 shouldFail: true,
9767 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009768 })
9769
David Benjamin35ac5b72017-03-03 15:05:56 -05009770 // Test that the server's ticket age skew reporting works.
9771 testCases = append(testCases, testCase{
9772 testType: serverTest,
9773 name: "TLS13-TicketAgeSkew-Forward",
9774 config: Config{
9775 MaxVersion: VersionTLS13,
9776 Bugs: ProtocolBugs{
9777 SendTicketAge: 15 * time.Second,
9778 },
9779 },
David Benjamin065d7332017-03-26 10:51:43 -05009780 resumeSession: true,
9781 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009782 flags: []string{
9783 "-resumption-delay", "10",
9784 "-expect-ticket-age-skew", "5",
9785 },
9786 })
9787 testCases = append(testCases, testCase{
9788 testType: serverTest,
9789 name: "TLS13-TicketAgeSkew-Backward",
9790 config: Config{
9791 MaxVersion: VersionTLS13,
9792 Bugs: ProtocolBugs{
9793 SendTicketAge: 5 * time.Second,
9794 },
9795 },
David Benjamin065d7332017-03-26 10:51:43 -05009796 resumeSession: true,
9797 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009798 flags: []string{
9799 "-resumption-delay", "10",
9800 "-expect-ticket-age-skew", "-5",
9801 },
9802 })
9803
Steven Valdez08b65f42016-12-07 15:29:45 -05009804 testCases = append(testCases, testCase{
9805 testType: clientTest,
9806 name: "TLS13-SendTicketEarlyDataInfo",
9807 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009808 MaxVersion: VersionTLS13,
9809 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009810 },
9811 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009812 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009813 "-expect-early-data-info",
9814 },
9815 })
9816
David Benjamin9b160662017-01-25 19:53:43 -05009817 // Test that 0-RTT tickets are ignored in clients unless opted in.
9818 testCases = append(testCases, testCase{
9819 testType: clientTest,
9820 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9821 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009822 MaxVersion: VersionTLS13,
9823 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009824 },
9825 })
9826
Steven Valdez08b65f42016-12-07 15:29:45 -05009827 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009828 testType: clientTest,
9829 name: "TLS13-DuplicateTicketEarlyDataInfo",
9830 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009831 MaxVersion: VersionTLS13,
9832 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009833 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009834 DuplicateTicketEarlyDataInfo: true,
9835 },
9836 },
9837 shouldFail: true,
9838 expectedError: ":DUPLICATE_EXTENSION:",
9839 expectedLocalError: "remote error: illegal parameter",
9840 })
9841
9842 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009843 testType: serverTest,
9844 name: "TLS13-ExpectTicketEarlyDataInfo",
9845 config: Config{
9846 MaxVersion: VersionTLS13,
9847 Bugs: ProtocolBugs{
9848 ExpectTicketEarlyDataInfo: true,
9849 },
9850 },
9851 flags: []string{
9852 "-enable-early-data",
9853 },
9854 })
David Benjamin17b30832017-01-28 14:00:32 -05009855
9856 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9857 // is honored.
9858 testCases = append(testCases, testCase{
9859 testType: clientTest,
9860 name: "TLS13-HonorServerSessionTicketLifetime",
9861 config: Config{
9862 MaxVersion: VersionTLS13,
9863 Bugs: ProtocolBugs{
9864 SendTicketLifetime: 20 * time.Second,
9865 },
9866 },
9867 flags: []string{
9868 "-resumption-delay", "19",
9869 },
9870 resumeSession: true,
9871 })
9872 testCases = append(testCases, testCase{
9873 testType: clientTest,
9874 name: "TLS13-HonorServerSessionTicketLifetime-2",
9875 config: Config{
9876 MaxVersion: VersionTLS13,
9877 Bugs: ProtocolBugs{
9878 SendTicketLifetime: 20 * time.Second,
9879 // The client should not offer the expired session.
9880 ExpectNoTLS13PSK: true,
9881 },
9882 },
9883 flags: []string{
9884 "-resumption-delay", "21",
9885 },
David Benjamin023d4192017-02-06 13:49:07 -05009886 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009887 expectResumeRejected: true,
9888 })
Steven Valdez5b986082016-09-01 12:29:49 -04009889}
9890
David Benjamin82261be2016-07-07 14:32:50 -07009891func addChangeCipherSpecTests() {
9892 // Test missing ChangeCipherSpecs.
9893 testCases = append(testCases, testCase{
9894 name: "SkipChangeCipherSpec-Client",
9895 config: Config{
9896 MaxVersion: VersionTLS12,
9897 Bugs: ProtocolBugs{
9898 SkipChangeCipherSpec: true,
9899 },
9900 },
9901 shouldFail: true,
9902 expectedError: ":UNEXPECTED_RECORD:",
9903 })
9904 testCases = append(testCases, testCase{
9905 testType: serverTest,
9906 name: "SkipChangeCipherSpec-Server",
9907 config: Config{
9908 MaxVersion: VersionTLS12,
9909 Bugs: ProtocolBugs{
9910 SkipChangeCipherSpec: true,
9911 },
9912 },
9913 shouldFail: true,
9914 expectedError: ":UNEXPECTED_RECORD:",
9915 })
9916 testCases = append(testCases, testCase{
9917 testType: serverTest,
9918 name: "SkipChangeCipherSpec-Server-NPN",
9919 config: Config{
9920 MaxVersion: VersionTLS12,
9921 NextProtos: []string{"bar"},
9922 Bugs: ProtocolBugs{
9923 SkipChangeCipherSpec: true,
9924 },
9925 },
9926 flags: []string{
9927 "-advertise-npn", "\x03foo\x03bar\x03baz",
9928 },
9929 shouldFail: true,
9930 expectedError: ":UNEXPECTED_RECORD:",
9931 })
9932
9933 // Test synchronization between the handshake and ChangeCipherSpec.
9934 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9935 // rejected. Test both with and without handshake packing to handle both
9936 // when the partial post-CCS message is in its own record and when it is
9937 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009938 for _, packed := range []bool{false, true} {
9939 var suffix string
9940 if packed {
9941 suffix = "-Packed"
9942 }
9943
9944 testCases = append(testCases, testCase{
9945 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9946 config: Config{
9947 MaxVersion: VersionTLS12,
9948 Bugs: ProtocolBugs{
9949 FragmentAcrossChangeCipherSpec: true,
9950 PackHandshakeFlight: packed,
9951 },
9952 },
9953 shouldFail: true,
9954 expectedError: ":UNEXPECTED_RECORD:",
9955 })
9956 testCases = append(testCases, testCase{
9957 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9958 config: Config{
9959 MaxVersion: VersionTLS12,
9960 },
9961 resumeSession: true,
9962 resumeConfig: &Config{
9963 MaxVersion: VersionTLS12,
9964 Bugs: ProtocolBugs{
9965 FragmentAcrossChangeCipherSpec: true,
9966 PackHandshakeFlight: packed,
9967 },
9968 },
9969 shouldFail: true,
9970 expectedError: ":UNEXPECTED_RECORD:",
9971 })
9972 testCases = append(testCases, testCase{
9973 testType: serverTest,
9974 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9975 config: Config{
9976 MaxVersion: VersionTLS12,
9977 Bugs: ProtocolBugs{
9978 FragmentAcrossChangeCipherSpec: true,
9979 PackHandshakeFlight: packed,
9980 },
9981 },
9982 shouldFail: true,
9983 expectedError: ":UNEXPECTED_RECORD:",
9984 })
9985 testCases = append(testCases, testCase{
9986 testType: serverTest,
9987 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9988 config: Config{
9989 MaxVersion: VersionTLS12,
9990 },
9991 resumeSession: true,
9992 resumeConfig: &Config{
9993 MaxVersion: VersionTLS12,
9994 Bugs: ProtocolBugs{
9995 FragmentAcrossChangeCipherSpec: true,
9996 PackHandshakeFlight: packed,
9997 },
9998 },
9999 shouldFail: true,
10000 expectedError: ":UNEXPECTED_RECORD:",
10001 })
10002 testCases = append(testCases, testCase{
10003 testType: serverTest,
10004 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10005 config: Config{
10006 MaxVersion: VersionTLS12,
10007 NextProtos: []string{"bar"},
10008 Bugs: ProtocolBugs{
10009 FragmentAcrossChangeCipherSpec: true,
10010 PackHandshakeFlight: packed,
10011 },
10012 },
10013 flags: []string{
10014 "-advertise-npn", "\x03foo\x03bar\x03baz",
10015 },
10016 shouldFail: true,
10017 expectedError: ":UNEXPECTED_RECORD:",
10018 })
10019 }
10020
David Benjamin61672812016-07-14 23:10:43 -040010021 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10022 // messages in the handshake queue. Do this by testing the server
10023 // reading the client Finished, reversing the flight so Finished comes
10024 // first.
10025 testCases = append(testCases, testCase{
10026 protocol: dtls,
10027 testType: serverTest,
10028 name: "SendUnencryptedFinished-DTLS",
10029 config: Config{
10030 MaxVersion: VersionTLS12,
10031 Bugs: ProtocolBugs{
10032 SendUnencryptedFinished: true,
10033 ReverseHandshakeFragments: true,
10034 },
10035 },
10036 shouldFail: true,
10037 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10038 })
10039
Steven Valdez143e8b32016-07-11 13:19:03 -040010040 // Test synchronization between encryption changes and the handshake in
10041 // TLS 1.3, where ChangeCipherSpec is implicit.
10042 testCases = append(testCases, testCase{
10043 name: "PartialEncryptedExtensionsWithServerHello",
10044 config: Config{
10045 MaxVersion: VersionTLS13,
10046 Bugs: ProtocolBugs{
10047 PartialEncryptedExtensionsWithServerHello: true,
10048 },
10049 },
10050 shouldFail: true,
10051 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10052 })
10053 testCases = append(testCases, testCase{
10054 testType: serverTest,
10055 name: "PartialClientFinishedWithClientHello",
10056 config: Config{
10057 MaxVersion: VersionTLS13,
10058 Bugs: ProtocolBugs{
10059 PartialClientFinishedWithClientHello: true,
10060 },
10061 },
10062 shouldFail: true,
10063 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10064 })
10065
David Benjamin82261be2016-07-07 14:32:50 -070010066 // Test that early ChangeCipherSpecs are handled correctly.
10067 testCases = append(testCases, testCase{
10068 testType: serverTest,
10069 name: "EarlyChangeCipherSpec-server-1",
10070 config: Config{
10071 MaxVersion: VersionTLS12,
10072 Bugs: ProtocolBugs{
10073 EarlyChangeCipherSpec: 1,
10074 },
10075 },
10076 shouldFail: true,
10077 expectedError: ":UNEXPECTED_RECORD:",
10078 })
10079 testCases = append(testCases, testCase{
10080 testType: serverTest,
10081 name: "EarlyChangeCipherSpec-server-2",
10082 config: Config{
10083 MaxVersion: VersionTLS12,
10084 Bugs: ProtocolBugs{
10085 EarlyChangeCipherSpec: 2,
10086 },
10087 },
10088 shouldFail: true,
10089 expectedError: ":UNEXPECTED_RECORD:",
10090 })
10091 testCases = append(testCases, testCase{
10092 protocol: dtls,
10093 name: "StrayChangeCipherSpec",
10094 config: Config{
10095 // TODO(davidben): Once DTLS 1.3 exists, test
10096 // that stray ChangeCipherSpec messages are
10097 // rejected.
10098 MaxVersion: VersionTLS12,
10099 Bugs: ProtocolBugs{
10100 StrayChangeCipherSpec: true,
10101 },
10102 },
10103 })
10104
David Benjaminb0c761e2017-06-25 22:42:55 -040010105 // Test that reordered ChangeCipherSpecs are tolerated.
10106 testCases = append(testCases, testCase{
10107 protocol: dtls,
10108 name: "ReorderChangeCipherSpec-DTLS-Client",
10109 config: Config{
10110 MaxVersion: VersionTLS12,
10111 Bugs: ProtocolBugs{
10112 ReorderChangeCipherSpec: true,
10113 },
10114 },
10115 resumeSession: true,
10116 })
10117 testCases = append(testCases, testCase{
10118 testType: serverTest,
10119 protocol: dtls,
10120 name: "ReorderChangeCipherSpec-DTLS-Server",
10121 config: Config{
10122 MaxVersion: VersionTLS12,
10123 Bugs: ProtocolBugs{
10124 ReorderChangeCipherSpec: true,
10125 },
10126 },
10127 resumeSession: true,
10128 })
10129
David Benjamin82261be2016-07-07 14:32:50 -070010130 // Test that the contents of ChangeCipherSpec are checked.
10131 testCases = append(testCases, testCase{
10132 name: "BadChangeCipherSpec-1",
10133 config: Config{
10134 MaxVersion: VersionTLS12,
10135 Bugs: ProtocolBugs{
10136 BadChangeCipherSpec: []byte{2},
10137 },
10138 },
10139 shouldFail: true,
10140 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10141 })
10142 testCases = append(testCases, testCase{
10143 name: "BadChangeCipherSpec-2",
10144 config: Config{
10145 MaxVersion: VersionTLS12,
10146 Bugs: ProtocolBugs{
10147 BadChangeCipherSpec: []byte{1, 1},
10148 },
10149 },
10150 shouldFail: true,
10151 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10152 })
10153 testCases = append(testCases, testCase{
10154 protocol: dtls,
10155 name: "BadChangeCipherSpec-DTLS-1",
10156 config: Config{
10157 MaxVersion: VersionTLS12,
10158 Bugs: ProtocolBugs{
10159 BadChangeCipherSpec: []byte{2},
10160 },
10161 },
10162 shouldFail: true,
10163 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10164 })
10165 testCases = append(testCases, testCase{
10166 protocol: dtls,
10167 name: "BadChangeCipherSpec-DTLS-2",
10168 config: Config{
10169 MaxVersion: VersionTLS12,
10170 Bugs: ProtocolBugs{
10171 BadChangeCipherSpec: []byte{1, 1},
10172 },
10173 },
10174 shouldFail: true,
10175 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10176 })
10177}
10178
David Benjamincd2c8062016-09-09 11:28:16 -040010179type perMessageTest struct {
10180 messageType uint8
10181 test testCase
10182}
10183
10184// makePerMessageTests returns a series of test templates which cover each
10185// message in the TLS handshake. These may be used with bugs like
10186// WrongMessageType to fully test a per-message bug.
10187func makePerMessageTests() []perMessageTest {
10188 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010189 for _, protocol := range []protocol{tls, dtls} {
10190 var suffix string
10191 if protocol == dtls {
10192 suffix = "-DTLS"
10193 }
10194
David Benjamincd2c8062016-09-09 11:28:16 -040010195 ret = append(ret, perMessageTest{
10196 messageType: typeClientHello,
10197 test: testCase{
10198 protocol: protocol,
10199 testType: serverTest,
10200 name: "ClientHello" + suffix,
10201 config: Config{
10202 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010203 },
10204 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010205 })
10206
10207 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010208 ret = append(ret, perMessageTest{
10209 messageType: typeHelloVerifyRequest,
10210 test: testCase{
10211 protocol: protocol,
10212 name: "HelloVerifyRequest" + suffix,
10213 config: Config{
10214 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010215 },
10216 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010217 })
10218 }
10219
David Benjamincd2c8062016-09-09 11:28:16 -040010220 ret = append(ret, perMessageTest{
10221 messageType: typeServerHello,
10222 test: testCase{
10223 protocol: protocol,
10224 name: "ServerHello" + suffix,
10225 config: Config{
10226 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010227 },
10228 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010229 })
10230
David Benjamincd2c8062016-09-09 11:28:16 -040010231 ret = append(ret, perMessageTest{
10232 messageType: typeCertificate,
10233 test: testCase{
10234 protocol: protocol,
10235 name: "ServerCertificate" + suffix,
10236 config: Config{
10237 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010238 },
10239 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010240 })
10241
David Benjamincd2c8062016-09-09 11:28:16 -040010242 ret = append(ret, perMessageTest{
10243 messageType: typeCertificateStatus,
10244 test: testCase{
10245 protocol: protocol,
10246 name: "CertificateStatus" + suffix,
10247 config: Config{
10248 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010249 },
David Benjamincd2c8062016-09-09 11:28:16 -040010250 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010251 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010252 })
10253
David Benjamincd2c8062016-09-09 11:28:16 -040010254 ret = append(ret, perMessageTest{
10255 messageType: typeServerKeyExchange,
10256 test: testCase{
10257 protocol: protocol,
10258 name: "ServerKeyExchange" + suffix,
10259 config: Config{
10260 MaxVersion: VersionTLS12,
10261 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010262 },
10263 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010264 })
10265
David Benjamincd2c8062016-09-09 11:28:16 -040010266 ret = append(ret, perMessageTest{
10267 messageType: typeCertificateRequest,
10268 test: testCase{
10269 protocol: protocol,
10270 name: "CertificateRequest" + suffix,
10271 config: Config{
10272 MaxVersion: VersionTLS12,
10273 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010274 },
10275 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010276 })
10277
David Benjamincd2c8062016-09-09 11:28:16 -040010278 ret = append(ret, perMessageTest{
10279 messageType: typeServerHelloDone,
10280 test: testCase{
10281 protocol: protocol,
10282 name: "ServerHelloDone" + suffix,
10283 config: Config{
10284 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010285 },
10286 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010287 })
10288
David Benjamincd2c8062016-09-09 11:28:16 -040010289 ret = append(ret, perMessageTest{
10290 messageType: typeCertificate,
10291 test: testCase{
10292 testType: serverTest,
10293 protocol: protocol,
10294 name: "ClientCertificate" + suffix,
10295 config: Config{
10296 Certificates: []Certificate{rsaCertificate},
10297 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010298 },
David Benjamincd2c8062016-09-09 11:28:16 -040010299 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010300 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010301 })
10302
David Benjamincd2c8062016-09-09 11:28:16 -040010303 ret = append(ret, perMessageTest{
10304 messageType: typeCertificateVerify,
10305 test: testCase{
10306 testType: serverTest,
10307 protocol: protocol,
10308 name: "CertificateVerify" + suffix,
10309 config: Config{
10310 Certificates: []Certificate{rsaCertificate},
10311 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010312 },
David Benjamincd2c8062016-09-09 11:28:16 -040010313 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010314 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010315 })
10316
David Benjamincd2c8062016-09-09 11:28:16 -040010317 ret = append(ret, perMessageTest{
10318 messageType: typeClientKeyExchange,
10319 test: testCase{
10320 testType: serverTest,
10321 protocol: protocol,
10322 name: "ClientKeyExchange" + suffix,
10323 config: Config{
10324 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010325 },
10326 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010327 })
10328
10329 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010330 ret = append(ret, perMessageTest{
10331 messageType: typeNextProtocol,
10332 test: testCase{
10333 testType: serverTest,
10334 protocol: protocol,
10335 name: "NextProtocol" + suffix,
10336 config: Config{
10337 MaxVersion: VersionTLS12,
10338 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010339 },
David Benjamincd2c8062016-09-09 11:28:16 -040010340 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010341 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010342 })
10343
David Benjamincd2c8062016-09-09 11:28:16 -040010344 ret = append(ret, perMessageTest{
10345 messageType: typeChannelID,
10346 test: testCase{
10347 testType: serverTest,
10348 protocol: protocol,
10349 name: "ChannelID" + suffix,
10350 config: Config{
10351 MaxVersion: VersionTLS12,
10352 ChannelID: channelIDKey,
10353 },
10354 flags: []string{
10355 "-expect-channel-id",
10356 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010357 },
10358 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010359 })
10360 }
10361
David Benjamincd2c8062016-09-09 11:28:16 -040010362 ret = append(ret, perMessageTest{
10363 messageType: typeFinished,
10364 test: testCase{
10365 testType: serverTest,
10366 protocol: protocol,
10367 name: "ClientFinished" + suffix,
10368 config: Config{
10369 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010370 },
10371 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010372 })
10373
David Benjamincd2c8062016-09-09 11:28:16 -040010374 ret = append(ret, perMessageTest{
10375 messageType: typeNewSessionTicket,
10376 test: testCase{
10377 protocol: protocol,
10378 name: "NewSessionTicket" + suffix,
10379 config: Config{
10380 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010381 },
10382 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010383 })
10384
David Benjamincd2c8062016-09-09 11:28:16 -040010385 ret = append(ret, perMessageTest{
10386 messageType: typeFinished,
10387 test: testCase{
10388 protocol: protocol,
10389 name: "ServerFinished" + suffix,
10390 config: Config{
10391 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010392 },
10393 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010394 })
10395
10396 }
David Benjamincd2c8062016-09-09 11:28:16 -040010397
10398 ret = append(ret, perMessageTest{
10399 messageType: typeClientHello,
10400 test: testCase{
10401 testType: serverTest,
10402 name: "TLS13-ClientHello",
10403 config: Config{
10404 MaxVersion: VersionTLS13,
10405 },
10406 },
10407 })
10408
10409 ret = append(ret, perMessageTest{
10410 messageType: typeServerHello,
10411 test: testCase{
10412 name: "TLS13-ServerHello",
10413 config: Config{
10414 MaxVersion: VersionTLS13,
10415 },
10416 },
10417 })
10418
10419 ret = append(ret, perMessageTest{
10420 messageType: typeEncryptedExtensions,
10421 test: testCase{
10422 name: "TLS13-EncryptedExtensions",
10423 config: Config{
10424 MaxVersion: VersionTLS13,
10425 },
10426 },
10427 })
10428
10429 ret = append(ret, perMessageTest{
10430 messageType: typeCertificateRequest,
10431 test: testCase{
10432 name: "TLS13-CertificateRequest",
10433 config: Config{
10434 MaxVersion: VersionTLS13,
10435 ClientAuth: RequireAnyClientCert,
10436 },
10437 },
10438 })
10439
10440 ret = append(ret, perMessageTest{
10441 messageType: typeCertificate,
10442 test: testCase{
10443 name: "TLS13-ServerCertificate",
10444 config: Config{
10445 MaxVersion: VersionTLS13,
10446 },
10447 },
10448 })
10449
10450 ret = append(ret, perMessageTest{
10451 messageType: typeCertificateVerify,
10452 test: testCase{
10453 name: "TLS13-ServerCertificateVerify",
10454 config: Config{
10455 MaxVersion: VersionTLS13,
10456 },
10457 },
10458 })
10459
10460 ret = append(ret, perMessageTest{
10461 messageType: typeFinished,
10462 test: testCase{
10463 name: "TLS13-ServerFinished",
10464 config: Config{
10465 MaxVersion: VersionTLS13,
10466 },
10467 },
10468 })
10469
10470 ret = append(ret, perMessageTest{
10471 messageType: typeCertificate,
10472 test: testCase{
10473 testType: serverTest,
10474 name: "TLS13-ClientCertificate",
10475 config: Config{
10476 Certificates: []Certificate{rsaCertificate},
10477 MaxVersion: VersionTLS13,
10478 },
10479 flags: []string{"-require-any-client-certificate"},
10480 },
10481 })
10482
10483 ret = append(ret, perMessageTest{
10484 messageType: typeCertificateVerify,
10485 test: testCase{
10486 testType: serverTest,
10487 name: "TLS13-ClientCertificateVerify",
10488 config: Config{
10489 Certificates: []Certificate{rsaCertificate},
10490 MaxVersion: VersionTLS13,
10491 },
10492 flags: []string{"-require-any-client-certificate"},
10493 },
10494 })
10495
10496 ret = append(ret, perMessageTest{
10497 messageType: typeFinished,
10498 test: testCase{
10499 testType: serverTest,
10500 name: "TLS13-ClientFinished",
10501 config: Config{
10502 MaxVersion: VersionTLS13,
10503 },
10504 },
10505 })
10506
10507 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010508}
10509
David Benjamincd2c8062016-09-09 11:28:16 -040010510func addWrongMessageTypeTests() {
10511 for _, t := range makePerMessageTests() {
10512 t.test.name = "WrongMessageType-" + t.test.name
10513 t.test.config.Bugs.SendWrongMessageType = t.messageType
10514 t.test.shouldFail = true
10515 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10516 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010517
David Benjamincd2c8062016-09-09 11:28:16 -040010518 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10519 // In TLS 1.3, a bad ServerHello means the client sends
10520 // an unencrypted alert while the server expects
10521 // encryption, so the alert is not readable by runner.
10522 t.test.expectedLocalError = "local error: bad record MAC"
10523 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010524
David Benjamincd2c8062016-09-09 11:28:16 -040010525 testCases = append(testCases, t.test)
10526 }
David Benjaminebacdee2017-04-08 11:00:45 -040010527
10528 // The processing order for TLS 1.3 version negotiation is such that one
10529 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10530 // TLS 1.2. Test that we do not do this.
10531 testCases = append(testCases, testCase{
10532 name: "SendServerHelloAsHelloRetryRequest",
10533 config: Config{
10534 MaxVersion: VersionTLS12,
10535 Bugs: ProtocolBugs{
10536 SendServerHelloAsHelloRetryRequest: true,
10537 },
10538 },
10539 shouldFail: true,
10540 expectedError: ":UNEXPECTED_MESSAGE:",
10541 expectedLocalError: "remote error: unexpected message",
10542 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010543}
10544
David Benjamin639846e2016-09-09 11:41:18 -040010545func addTrailingMessageDataTests() {
10546 for _, t := range makePerMessageTests() {
10547 t.test.name = "TrailingMessageData-" + t.test.name
10548 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10549 t.test.shouldFail = true
10550 t.test.expectedError = ":DECODE_ERROR:"
10551 t.test.expectedLocalError = "remote error: error decoding message"
10552
10553 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10554 // In TLS 1.3, a bad ServerHello means the client sends
10555 // an unencrypted alert while the server expects
10556 // encryption, so the alert is not readable by runner.
10557 t.test.expectedLocalError = "local error: bad record MAC"
10558 }
10559
10560 if t.messageType == typeFinished {
10561 // Bad Finished messages read as the verify data having
10562 // the wrong length.
10563 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10564 t.test.expectedLocalError = "remote error: error decrypting message"
10565 }
10566
10567 testCases = append(testCases, t.test)
10568 }
10569}
10570
Steven Valdez143e8b32016-07-11 13:19:03 -040010571func addTLS13HandshakeTests() {
10572 testCases = append(testCases, testCase{
10573 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010574 name: "NegotiatePSKResumption-TLS13",
10575 config: Config{
10576 MaxVersion: VersionTLS13,
10577 Bugs: ProtocolBugs{
10578 NegotiatePSKResumption: true,
10579 },
10580 },
10581 resumeSession: true,
10582 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010583 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010584 })
10585
10586 testCases = append(testCases, testCase{
10587 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010588 name: "MissingKeyShare-Client",
10589 config: Config{
10590 MaxVersion: VersionTLS13,
10591 Bugs: ProtocolBugs{
10592 MissingKeyShare: true,
10593 },
10594 },
10595 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010596 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010597 })
10598
10599 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010600 testType: serverTest,
10601 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010602 config: Config{
10603 MaxVersion: VersionTLS13,
10604 Bugs: ProtocolBugs{
10605 MissingKeyShare: true,
10606 },
10607 },
10608 shouldFail: true,
10609 expectedError: ":MISSING_KEY_SHARE:",
10610 })
10611
10612 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010613 testType: serverTest,
10614 name: "DuplicateKeyShares",
10615 config: Config{
10616 MaxVersion: VersionTLS13,
10617 Bugs: ProtocolBugs{
10618 DuplicateKeyShares: true,
10619 },
10620 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010621 shouldFail: true,
10622 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010623 })
10624
10625 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010626 testType: serverTest,
10627 name: "SkipEarlyData",
10628 config: Config{
10629 MaxVersion: VersionTLS13,
10630 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010631 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010632 },
10633 },
10634 })
10635
10636 testCases = append(testCases, testCase{
10637 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010638 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010639 config: Config{
10640 MaxVersion: VersionTLS13,
10641 TLS13Variant: TLS13Experiment,
10642 Bugs: ProtocolBugs{
10643 SendFakeEarlyDataLength: 4,
10644 },
10645 },
10646 flags: []string{"-tls13-variant", "1"},
10647 })
10648
10649 testCases = append(testCases, testCase{
10650 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010651 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10652 config: Config{
10653 MaxVersion: VersionTLS13,
10654 TLS13Variant: TLS13RecordTypeExperiment,
10655 Bugs: ProtocolBugs{
10656 SendFakeEarlyDataLength: 4,
10657 },
10658 },
10659 flags: []string{"-tls13-variant", "2"},
10660 })
10661
10662 testCases = append(testCases, testCase{
10663 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010664 name: "SkipEarlyData-OmitEarlyDataExtension",
10665 config: Config{
10666 MaxVersion: VersionTLS13,
10667 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010668 SendFakeEarlyDataLength: 4,
10669 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010670 },
10671 },
10672 shouldFail: true,
10673 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10674 })
10675
10676 testCases = append(testCases, testCase{
10677 testType: serverTest,
10678 name: "SkipEarlyData-TooMuchData",
10679 config: Config{
10680 MaxVersion: VersionTLS13,
10681 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010682 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010683 },
10684 },
10685 shouldFail: true,
10686 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10687 })
10688
10689 testCases = append(testCases, testCase{
10690 testType: serverTest,
10691 name: "SkipEarlyData-Interleaved",
10692 config: Config{
10693 MaxVersion: VersionTLS13,
10694 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010695 SendFakeEarlyDataLength: 4,
10696 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010697 },
10698 },
10699 shouldFail: true,
10700 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10701 })
10702
10703 testCases = append(testCases, testCase{
10704 testType: serverTest,
10705 name: "SkipEarlyData-EarlyDataInTLS12",
10706 config: Config{
10707 MaxVersion: VersionTLS13,
10708 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010709 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010710 },
10711 },
10712 shouldFail: true,
10713 expectedError: ":UNEXPECTED_RECORD:",
10714 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10715 })
10716
10717 testCases = append(testCases, testCase{
10718 testType: serverTest,
10719 name: "SkipEarlyData-HRR",
10720 config: Config{
10721 MaxVersion: VersionTLS13,
10722 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010723 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010724 },
10725 DefaultCurves: []CurveID{},
10726 },
10727 })
10728
10729 testCases = append(testCases, testCase{
10730 testType: serverTest,
10731 name: "SkipEarlyData-HRR-Interleaved",
10732 config: Config{
10733 MaxVersion: VersionTLS13,
10734 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010735 SendFakeEarlyDataLength: 4,
10736 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010737 },
10738 DefaultCurves: []CurveID{},
10739 },
10740 shouldFail: true,
10741 expectedError: ":UNEXPECTED_RECORD:",
10742 })
10743
10744 testCases = append(testCases, testCase{
10745 testType: serverTest,
10746 name: "SkipEarlyData-HRR-TooMuchData",
10747 config: Config{
10748 MaxVersion: VersionTLS13,
10749 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010750 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010751 },
10752 DefaultCurves: []CurveID{},
10753 },
10754 shouldFail: true,
10755 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10756 })
10757
10758 // Test that skipping early data looking for cleartext correctly
10759 // processes an alert record.
10760 testCases = append(testCases, testCase{
10761 testType: serverTest,
10762 name: "SkipEarlyData-HRR-FatalAlert",
10763 config: Config{
10764 MaxVersion: VersionTLS13,
10765 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010766 SendEarlyAlert: true,
10767 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010768 },
10769 DefaultCurves: []CurveID{},
10770 },
10771 shouldFail: true,
10772 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10773 })
10774
10775 testCases = append(testCases, testCase{
10776 testType: serverTest,
10777 name: "SkipEarlyData-SecondClientHelloEarlyData",
10778 config: Config{
10779 MaxVersion: VersionTLS13,
10780 Bugs: ProtocolBugs{
10781 SendEarlyDataOnSecondClientHello: true,
10782 },
10783 DefaultCurves: []CurveID{},
10784 },
10785 shouldFail: true,
10786 expectedLocalError: "remote error: bad record MAC",
10787 })
10788
10789 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010790 testType: clientTest,
10791 name: "EmptyEncryptedExtensions",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 Bugs: ProtocolBugs{
10795 EmptyEncryptedExtensions: true,
10796 },
10797 },
10798 shouldFail: true,
10799 expectedLocalError: "remote error: error decoding message",
10800 })
10801
10802 testCases = append(testCases, testCase{
10803 testType: clientTest,
10804 name: "EncryptedExtensionsWithKeyShare",
10805 config: Config{
10806 MaxVersion: VersionTLS13,
10807 Bugs: ProtocolBugs{
10808 EncryptedExtensionsWithKeyShare: true,
10809 },
10810 },
10811 shouldFail: true,
10812 expectedLocalError: "remote error: unsupported extension",
10813 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010814
10815 testCases = append(testCases, testCase{
10816 testType: serverTest,
10817 name: "SendHelloRetryRequest",
10818 config: Config{
10819 MaxVersion: VersionTLS13,
10820 // Require a HelloRetryRequest for every curve.
10821 DefaultCurves: []CurveID{},
10822 },
10823 expectedCurveID: CurveX25519,
10824 })
10825
10826 testCases = append(testCases, testCase{
10827 testType: serverTest,
10828 name: "SendHelloRetryRequest-2",
10829 config: Config{
10830 MaxVersion: VersionTLS13,
10831 DefaultCurves: []CurveID{CurveP384},
10832 },
10833 // Although the ClientHello did not predict our preferred curve,
10834 // we always select it whether it is predicted or not.
10835 expectedCurveID: CurveX25519,
10836 })
10837
10838 testCases = append(testCases, testCase{
10839 name: "UnknownCurve-HelloRetryRequest",
10840 config: Config{
10841 MaxVersion: VersionTLS13,
10842 // P-384 requires HelloRetryRequest in BoringSSL.
10843 CurvePreferences: []CurveID{CurveP384},
10844 Bugs: ProtocolBugs{
10845 SendHelloRetryRequestCurve: bogusCurve,
10846 },
10847 },
10848 shouldFail: true,
10849 expectedError: ":WRONG_CURVE:",
10850 })
10851
10852 testCases = append(testCases, testCase{
10853 name: "DisabledCurve-HelloRetryRequest",
10854 config: Config{
10855 MaxVersion: VersionTLS13,
10856 CurvePreferences: []CurveID{CurveP256},
10857 Bugs: ProtocolBugs{
10858 IgnorePeerCurvePreferences: true,
10859 },
10860 },
10861 flags: []string{"-p384-only"},
10862 shouldFail: true,
10863 expectedError: ":WRONG_CURVE:",
10864 })
10865
10866 testCases = append(testCases, testCase{
10867 name: "UnnecessaryHelloRetryRequest",
10868 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010869 MaxVersion: VersionTLS13,
10870 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010871 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010872 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010873 },
10874 },
10875 shouldFail: true,
10876 expectedError: ":WRONG_CURVE:",
10877 })
10878
10879 testCases = append(testCases, testCase{
10880 name: "SecondHelloRetryRequest",
10881 config: Config{
10882 MaxVersion: VersionTLS13,
10883 // P-384 requires HelloRetryRequest in BoringSSL.
10884 CurvePreferences: []CurveID{CurveP384},
10885 Bugs: ProtocolBugs{
10886 SecondHelloRetryRequest: true,
10887 },
10888 },
10889 shouldFail: true,
10890 expectedError: ":UNEXPECTED_MESSAGE:",
10891 })
10892
10893 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010894 name: "HelloRetryRequest-Empty",
10895 config: Config{
10896 MaxVersion: VersionTLS13,
10897 Bugs: ProtocolBugs{
10898 AlwaysSendHelloRetryRequest: true,
10899 },
10900 },
10901 shouldFail: true,
10902 expectedError: ":DECODE_ERROR:",
10903 })
10904
10905 testCases = append(testCases, testCase{
10906 name: "HelloRetryRequest-DuplicateCurve",
10907 config: Config{
10908 MaxVersion: VersionTLS13,
10909 // P-384 requires a HelloRetryRequest against BoringSSL's default
10910 // configuration. Assert this ExpectMissingKeyShare.
10911 CurvePreferences: []CurveID{CurveP384},
10912 Bugs: ProtocolBugs{
10913 ExpectMissingKeyShare: true,
10914 DuplicateHelloRetryRequestExtensions: true,
10915 },
10916 },
10917 shouldFail: true,
10918 expectedError: ":DUPLICATE_EXTENSION:",
10919 expectedLocalError: "remote error: illegal parameter",
10920 })
10921
10922 testCases = append(testCases, testCase{
10923 name: "HelloRetryRequest-Cookie",
10924 config: Config{
10925 MaxVersion: VersionTLS13,
10926 Bugs: ProtocolBugs{
10927 SendHelloRetryRequestCookie: []byte("cookie"),
10928 },
10929 },
10930 })
10931
10932 testCases = append(testCases, testCase{
10933 name: "HelloRetryRequest-DuplicateCookie",
10934 config: Config{
10935 MaxVersion: VersionTLS13,
10936 Bugs: ProtocolBugs{
10937 SendHelloRetryRequestCookie: []byte("cookie"),
10938 DuplicateHelloRetryRequestExtensions: true,
10939 },
10940 },
10941 shouldFail: true,
10942 expectedError: ":DUPLICATE_EXTENSION:",
10943 expectedLocalError: "remote error: illegal parameter",
10944 })
10945
10946 testCases = append(testCases, testCase{
10947 name: "HelloRetryRequest-EmptyCookie",
10948 config: Config{
10949 MaxVersion: VersionTLS13,
10950 Bugs: ProtocolBugs{
10951 SendHelloRetryRequestCookie: []byte{},
10952 },
10953 },
10954 shouldFail: true,
10955 expectedError: ":DECODE_ERROR:",
10956 })
10957
10958 testCases = append(testCases, testCase{
10959 name: "HelloRetryRequest-Cookie-Curve",
10960 config: Config{
10961 MaxVersion: VersionTLS13,
10962 // P-384 requires HelloRetryRequest in BoringSSL.
10963 CurvePreferences: []CurveID{CurveP384},
10964 Bugs: ProtocolBugs{
10965 SendHelloRetryRequestCookie: []byte("cookie"),
10966 ExpectMissingKeyShare: true,
10967 },
10968 },
10969 })
10970
10971 testCases = append(testCases, testCase{
10972 name: "HelloRetryRequest-Unknown",
10973 config: Config{
10974 MaxVersion: VersionTLS13,
10975 Bugs: ProtocolBugs{
10976 CustomHelloRetryRequestExtension: "extension",
10977 },
10978 },
10979 shouldFail: true,
10980 expectedError: ":UNEXPECTED_EXTENSION:",
10981 expectedLocalError: "remote error: unsupported extension",
10982 })
10983
10984 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010985 testType: serverTest,
10986 name: "SecondClientHelloMissingKeyShare",
10987 config: Config{
10988 MaxVersion: VersionTLS13,
10989 DefaultCurves: []CurveID{},
10990 Bugs: ProtocolBugs{
10991 SecondClientHelloMissingKeyShare: true,
10992 },
10993 },
10994 shouldFail: true,
10995 expectedError: ":MISSING_KEY_SHARE:",
10996 })
10997
10998 testCases = append(testCases, testCase{
10999 testType: serverTest,
11000 name: "SecondClientHelloWrongCurve",
11001 config: Config{
11002 MaxVersion: VersionTLS13,
11003 DefaultCurves: []CurveID{},
11004 Bugs: ProtocolBugs{
11005 MisinterpretHelloRetryRequestCurve: CurveP521,
11006 },
11007 },
11008 shouldFail: true,
11009 expectedError: ":WRONG_CURVE:",
11010 })
11011
11012 testCases = append(testCases, testCase{
11013 name: "HelloRetryRequestVersionMismatch",
11014 config: Config{
11015 MaxVersion: VersionTLS13,
11016 // P-384 requires HelloRetryRequest in BoringSSL.
11017 CurvePreferences: []CurveID{CurveP384},
11018 Bugs: ProtocolBugs{
11019 SendServerHelloVersion: 0x0305,
11020 },
11021 },
11022 shouldFail: true,
11023 expectedError: ":WRONG_VERSION_NUMBER:",
11024 })
11025
11026 testCases = append(testCases, testCase{
11027 name: "HelloRetryRequestCurveMismatch",
11028 config: Config{
11029 MaxVersion: VersionTLS13,
11030 // P-384 requires HelloRetryRequest in BoringSSL.
11031 CurvePreferences: []CurveID{CurveP384},
11032 Bugs: ProtocolBugs{
11033 // Send P-384 (correct) in the HelloRetryRequest.
11034 SendHelloRetryRequestCurve: CurveP384,
11035 // But send P-256 in the ServerHello.
11036 SendCurve: CurveP256,
11037 },
11038 },
11039 shouldFail: true,
11040 expectedError: ":WRONG_CURVE:",
11041 })
11042
11043 // Test the server selecting a curve that requires a HelloRetryRequest
11044 // without sending it.
11045 testCases = append(testCases, testCase{
11046 name: "SkipHelloRetryRequest",
11047 config: Config{
11048 MaxVersion: VersionTLS13,
11049 // P-384 requires HelloRetryRequest in BoringSSL.
11050 CurvePreferences: []CurveID{CurveP384},
11051 Bugs: ProtocolBugs{
11052 SkipHelloRetryRequest: true,
11053 },
11054 },
11055 shouldFail: true,
11056 expectedError: ":WRONG_CURVE:",
11057 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011058
11059 testCases = append(testCases, testCase{
11060 name: "TLS13-RequestContextInHandshake",
11061 config: Config{
11062 MaxVersion: VersionTLS13,
11063 MinVersion: VersionTLS13,
11064 ClientAuth: RequireAnyClientCert,
11065 Bugs: ProtocolBugs{
11066 SendRequestContext: []byte("request context"),
11067 },
11068 },
11069 flags: []string{
11070 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11071 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11072 },
11073 shouldFail: true,
11074 expectedError: ":DECODE_ERROR:",
11075 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011076
11077 testCases = append(testCases, testCase{
11078 testType: serverTest,
11079 name: "TLS13-TrailingKeyShareData",
11080 config: Config{
11081 MaxVersion: VersionTLS13,
11082 Bugs: ProtocolBugs{
11083 TrailingKeyShareData: true,
11084 },
11085 },
11086 shouldFail: true,
11087 expectedError: ":DECODE_ERROR:",
11088 })
David Benjamin7f78df42016-10-05 22:33:19 -040011089
11090 testCases = append(testCases, testCase{
11091 name: "TLS13-AlwaysSelectPSKIdentity",
11092 config: Config{
11093 MaxVersion: VersionTLS13,
11094 Bugs: ProtocolBugs{
11095 AlwaysSelectPSKIdentity: true,
11096 },
11097 },
11098 shouldFail: true,
11099 expectedError: ":UNEXPECTED_EXTENSION:",
11100 })
11101
11102 testCases = append(testCases, testCase{
11103 name: "TLS13-InvalidPSKIdentity",
11104 config: Config{
11105 MaxVersion: VersionTLS13,
11106 Bugs: ProtocolBugs{
11107 SelectPSKIdentityOnResume: 1,
11108 },
11109 },
11110 resumeSession: true,
11111 shouldFail: true,
11112 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11113 })
David Benjamin1286bee2016-10-07 15:25:06 -040011114
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011115 testCases = append(testCases, testCase{
11116 testType: serverTest,
11117 name: "TLS13-ExtraPSKIdentity",
11118 config: Config{
11119 MaxVersion: VersionTLS13,
11120 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011121 ExtraPSKIdentity: true,
11122 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011123 },
11124 },
11125 resumeSession: true,
11126 })
11127
David Benjamin1286bee2016-10-07 15:25:06 -040011128 // Test that unknown NewSessionTicket extensions are tolerated.
11129 testCases = append(testCases, testCase{
11130 name: "TLS13-CustomTicketExtension",
11131 config: Config{
11132 MaxVersion: VersionTLS13,
11133 Bugs: ProtocolBugs{
11134 CustomTicketExtension: "1234",
11135 },
11136 },
11137 })
Steven Valdez2d850622017-01-11 11:34:52 -050011138
Steven Valdez0e4a4482017-07-17 11:12:34 -040011139 for _, noSessionID := range []bool{false, true} {
11140 prefix := "TLS13Experiment"
11141 variant := TLS13Experiment
11142 if noSessionID {
11143 prefix = "TLS13NoSessionIDExperiment"
11144 variant = TLS13NoSessionIDExperiment
11145 }
11146
11147 // Test that enabling a TLS 1.3 variant does not interfere with
11148 // TLS 1.2 session ID resumption.
11149 testCases = append(testCases, testCase{
11150 testType: clientTest,
11151 name: prefix + "-ResumeTLS12SessionID",
11152 config: Config{
11153 MaxVersion: VersionTLS12,
11154 SessionTicketsDisabled: true,
11155 },
11156 resumeSession: true,
11157 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11158 })
11159
11160 // Test that the server correctly echoes back session IDs of
11161 // various lengths.
11162 testCases = append(testCases, testCase{
11163 testType: serverTest,
11164 name: prefix + "-EmptySessionID",
11165 config: Config{
11166 MaxVersion: VersionTLS13,
11167 Bugs: ProtocolBugs{
11168 SendClientHelloSessionID: []byte{},
11169 },
11170 },
11171 tls13Variant: variant,
11172 })
11173
11174 testCases = append(testCases, testCase{
11175 testType: serverTest,
11176 name: prefix + "-ShortSessionID",
11177 config: Config{
11178 MaxVersion: VersionTLS13,
11179 Bugs: ProtocolBugs{
11180 SendClientHelloSessionID: make([]byte, 16),
11181 },
11182 },
11183 tls13Variant: variant,
11184 })
11185
11186 testCases = append(testCases, testCase{
11187 testType: serverTest,
11188 name: prefix + "-FullSessionID",
11189 config: Config{
11190 MaxVersion: VersionTLS13,
11191 Bugs: ProtocolBugs{
11192 SendClientHelloSessionID: make([]byte, 32),
11193 },
11194 },
11195 tls13Variant: variant,
11196 })
11197 }
11198
11199 // Test that the client sends a fake session ID in TLS13Experiment.
11200 testCases = append(testCases, testCase{
11201 testType: clientTest,
11202 name: "TLS13Experiment-RequireSessionID",
11203 config: Config{
11204 MaxVersion: VersionTLS13,
11205 Bugs: ProtocolBugs{
11206 ExpectClientHelloSessionID: true,
11207 },
11208 },
11209 tls13Variant: TLS13Experiment,
11210 })
11211
11212 // Test that the client does not send a fake session ID in
11213 // TLS13NoSessionIDExperiment.
11214 testCases = append(testCases, testCase{
11215 testType: clientTest,
11216 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11217 config: Config{
11218 MaxVersion: VersionTLS13,
11219 Bugs: ProtocolBugs{
11220 ExpectEmptyClientHelloSessionID: true,
11221 },
11222 },
11223 tls13Variant: TLS13NoSessionIDExperiment,
11224 })
11225
Steven Valdez2d850622017-01-11 11:34:52 -050011226 testCases = append(testCases, testCase{
11227 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011228 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011229 config: Config{
11230 MaxVersion: VersionTLS13,
11231 MaxEarlyDataSize: 16384,
11232 },
11233 resumeConfig: &Config{
11234 MaxVersion: VersionTLS13,
11235 MaxEarlyDataSize: 16384,
11236 Bugs: ProtocolBugs{
11237 AlwaysRejectEarlyData: true,
11238 },
11239 },
11240 resumeSession: true,
11241 flags: []string{
11242 "-enable-early-data",
11243 "-expect-early-data-info",
11244 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011245 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011246 },
11247 })
11248
11249 testCases = append(testCases, testCase{
11250 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011251 name: "TLS13Experiment-EarlyData-Reject-Client",
11252 config: Config{
11253 MaxVersion: VersionTLS13,
11254 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011255 },
11256 resumeConfig: &Config{
11257 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011258 MaxEarlyDataSize: 16384,
11259 Bugs: ProtocolBugs{
11260 AlwaysRejectEarlyData: true,
11261 },
11262 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011263 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011264 resumeSession: true,
11265 flags: []string{
11266 "-enable-early-data",
11267 "-expect-early-data-info",
11268 "-expect-reject-early-data",
11269 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011270 },
11271 })
11272
11273 testCases = append(testCases, testCase{
11274 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011275 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11276 config: Config{
11277 MaxVersion: VersionTLS13,
11278 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011279 },
11280 resumeConfig: &Config{
11281 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011282 MaxEarlyDataSize: 16384,
11283 Bugs: ProtocolBugs{
11284 AlwaysRejectEarlyData: true,
11285 },
11286 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011287 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011288 resumeSession: true,
11289 flags: []string{
11290 "-enable-early-data",
11291 "-expect-early-data-info",
11292 "-expect-reject-early-data",
11293 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011294 },
11295 })
11296
11297 testCases = append(testCases, testCase{
11298 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011299 name: "TLS13-EarlyData-RejectTicket-Client",
11300 config: Config{
11301 MaxVersion: VersionTLS13,
11302 MaxEarlyDataSize: 16384,
11303 Certificates: []Certificate{rsaCertificate},
11304 },
11305 resumeConfig: &Config{
11306 MaxVersion: VersionTLS13,
11307 MaxEarlyDataSize: 16384,
11308 Certificates: []Certificate{ecdsaP256Certificate},
11309 SessionTicketsDisabled: true,
11310 },
11311 resumeSession: true,
11312 expectResumeRejected: true,
11313 flags: []string{
11314 "-enable-early-data",
11315 "-expect-early-data-info",
11316 "-expect-reject-early-data",
11317 "-on-resume-shim-writes-first",
11318 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11319 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11320 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11321 // Session tickets are disabled, so the runner will not send a ticket.
11322 "-on-retry-expect-no-session",
11323 },
11324 })
11325
11326 testCases = append(testCases, testCase{
11327 testType: clientTest,
11328 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011329 config: Config{
11330 MaxVersion: VersionTLS13,
11331 MaxEarlyDataSize: 16384,
11332 },
11333 resumeConfig: &Config{
11334 MaxVersion: VersionTLS13,
11335 MaxEarlyDataSize: 16384,
11336 Bugs: ProtocolBugs{
11337 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11338 },
11339 },
11340 resumeSession: true,
11341 flags: []string{
11342 "-enable-early-data",
11343 "-expect-early-data-info",
11344 "-expect-reject-early-data",
11345 },
11346 })
11347
11348 // The client must check the server does not send the early_data
11349 // extension while rejecting the session.
11350 testCases = append(testCases, testCase{
11351 testType: clientTest,
11352 name: "TLS13-EarlyDataWithoutResume-Client",
11353 config: Config{
11354 MaxVersion: VersionTLS13,
11355 MaxEarlyDataSize: 16384,
11356 },
11357 resumeConfig: &Config{
11358 MaxVersion: VersionTLS13,
11359 SessionTicketsDisabled: true,
11360 Bugs: ProtocolBugs{
11361 SendEarlyDataExtension: true,
11362 },
11363 },
11364 resumeSession: true,
11365 flags: []string{
11366 "-enable-early-data",
11367 "-expect-early-data-info",
11368 },
11369 shouldFail: true,
11370 expectedError: ":UNEXPECTED_EXTENSION:",
11371 })
11372
11373 // The client must fail with a dedicated error code if the server
11374 // responds with TLS 1.2 when offering 0-RTT.
11375 testCases = append(testCases, testCase{
11376 testType: clientTest,
11377 name: "TLS13-EarlyDataVersionDowngrade-Client",
11378 config: Config{
11379 MaxVersion: VersionTLS13,
11380 MaxEarlyDataSize: 16384,
11381 },
11382 resumeConfig: &Config{
11383 MaxVersion: VersionTLS12,
11384 },
11385 resumeSession: true,
11386 flags: []string{
11387 "-enable-early-data",
11388 "-expect-early-data-info",
11389 },
11390 shouldFail: true,
11391 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11392 })
11393
11394 // Test that the client rejects an (unsolicited) early_data extension if
11395 // the server sent an HRR.
11396 testCases = append(testCases, testCase{
11397 testType: clientTest,
11398 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11399 config: Config{
11400 MaxVersion: VersionTLS13,
11401 MaxEarlyDataSize: 16384,
11402 },
11403 resumeConfig: &Config{
11404 MaxVersion: VersionTLS13,
11405 MaxEarlyDataSize: 16384,
11406 Bugs: ProtocolBugs{
11407 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11408 SendEarlyDataExtension: true,
11409 },
11410 },
11411 resumeSession: true,
11412 flags: []string{
11413 "-enable-early-data",
11414 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011415 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011416 },
11417 shouldFail: true,
11418 expectedError: ":UNEXPECTED_EXTENSION:",
11419 })
11420
11421 fooString := "foo"
11422 barString := "bar"
11423
11424 // Test that the client reports the correct ALPN after a 0-RTT reject
11425 // that changed it.
11426 testCases = append(testCases, testCase{
11427 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011428 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011429 config: Config{
11430 MaxVersion: VersionTLS13,
11431 MaxEarlyDataSize: 16384,
11432 Bugs: ProtocolBugs{
11433 ALPNProtocol: &fooString,
11434 },
11435 },
11436 resumeConfig: &Config{
11437 MaxVersion: VersionTLS13,
11438 MaxEarlyDataSize: 16384,
11439 Bugs: ProtocolBugs{
11440 ALPNProtocol: &barString,
11441 },
11442 },
11443 resumeSession: true,
11444 flags: []string{
11445 "-advertise-alpn", "\x03foo\x03bar",
11446 "-enable-early-data",
11447 "-expect-early-data-info",
11448 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011449 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011450 "-on-resume-expect-alpn", "foo",
11451 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011452 },
11453 })
11454
11455 // Test that the client reports the correct ALPN after a 0-RTT reject if
11456 // ALPN was omitted from the first connection.
11457 testCases = append(testCases, testCase{
11458 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011459 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011460 config: Config{
11461 MaxVersion: VersionTLS13,
11462 MaxEarlyDataSize: 16384,
11463 },
11464 resumeConfig: &Config{
11465 MaxVersion: VersionTLS13,
11466 MaxEarlyDataSize: 16384,
11467 NextProtos: []string{"foo"},
11468 },
11469 resumeSession: true,
11470 flags: []string{
11471 "-advertise-alpn", "\x03foo\x03bar",
11472 "-enable-early-data",
11473 "-expect-early-data-info",
11474 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011475 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011476 "-on-resume-expect-alpn", "",
11477 "-on-retry-expect-alpn", "foo",
11478 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011479 },
11480 })
11481
11482 // Test that the client reports the correct ALPN after a 0-RTT reject if
11483 // ALPN was omitted from the second connection.
11484 testCases = append(testCases, testCase{
11485 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011486 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011487 config: Config{
11488 MaxVersion: VersionTLS13,
11489 MaxEarlyDataSize: 16384,
11490 NextProtos: []string{"foo"},
11491 },
11492 resumeConfig: &Config{
11493 MaxVersion: VersionTLS13,
11494 MaxEarlyDataSize: 16384,
11495 },
11496 resumeSession: true,
11497 flags: []string{
11498 "-advertise-alpn", "\x03foo\x03bar",
11499 "-enable-early-data",
11500 "-expect-early-data-info",
11501 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011502 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011503 "-on-resume-expect-alpn", "foo",
11504 "-on-retry-expect-alpn", "",
11505 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011506 },
11507 })
11508
11509 // Test that the client enforces ALPN match on 0-RTT accept.
11510 testCases = append(testCases, testCase{
11511 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011512 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011513 config: Config{
11514 MaxVersion: VersionTLS13,
11515 MaxEarlyDataSize: 16384,
11516 Bugs: ProtocolBugs{
11517 ALPNProtocol: &fooString,
11518 },
11519 },
11520 resumeConfig: &Config{
11521 MaxVersion: VersionTLS13,
11522 MaxEarlyDataSize: 16384,
11523 Bugs: ProtocolBugs{
11524 AlwaysAcceptEarlyData: true,
11525 ALPNProtocol: &barString,
11526 },
11527 },
11528 resumeSession: true,
11529 flags: []string{
11530 "-advertise-alpn", "\x03foo\x03bar",
11531 "-enable-early-data",
11532 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011533 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011534 "-on-resume-expect-alpn", "foo",
11535 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011536 },
11537 shouldFail: true,
11538 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11539 })
11540
11541 // Test that the server correctly rejects 0-RTT when the previous
11542 // session did not allow early data on resumption.
11543 testCases = append(testCases, testCase{
11544 testType: serverTest,
11545 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11546 config: Config{
11547 MaxVersion: VersionTLS13,
11548 },
11549 resumeConfig: &Config{
11550 MaxVersion: VersionTLS13,
11551 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011552 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011553 ExpectEarlyDataAccepted: false,
11554 },
11555 },
11556 resumeSession: true,
11557 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011558 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011559 "-expect-reject-early-data",
11560 },
11561 })
11562
11563 // Test that we reject early data where ALPN is omitted from the first
11564 // connection.
11565 testCases = append(testCases, testCase{
11566 testType: serverTest,
11567 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11568 config: Config{
11569 MaxVersion: VersionTLS13,
11570 NextProtos: []string{},
11571 },
11572 resumeConfig: &Config{
11573 MaxVersion: VersionTLS13,
11574 NextProtos: []string{"foo"},
11575 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011576 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011577 ExpectEarlyDataAccepted: false,
11578 },
11579 },
11580 resumeSession: true,
11581 flags: []string{
11582 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011583 "-on-initial-select-alpn", "",
11584 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011585 },
11586 })
11587
11588 // Test that we reject early data where ALPN is omitted from the second
11589 // connection.
11590 testCases = append(testCases, testCase{
11591 testType: serverTest,
11592 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11593 config: Config{
11594 MaxVersion: VersionTLS13,
11595 NextProtos: []string{"foo"},
11596 },
11597 resumeConfig: &Config{
11598 MaxVersion: VersionTLS13,
11599 NextProtos: []string{},
11600 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011601 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011602 ExpectEarlyDataAccepted: false,
11603 },
11604 },
11605 resumeSession: true,
11606 flags: []string{
11607 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011608 "-on-initial-select-alpn", "foo",
11609 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011610 },
11611 })
11612
11613 // Test that we reject early data with mismatched ALPN.
11614 testCases = append(testCases, testCase{
11615 testType: serverTest,
11616 name: "TLS13-EarlyData-ALPNMismatch-Server",
11617 config: Config{
11618 MaxVersion: VersionTLS13,
11619 NextProtos: []string{"foo"},
11620 },
11621 resumeConfig: &Config{
11622 MaxVersion: VersionTLS13,
11623 NextProtos: []string{"bar"},
11624 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011625 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011626 ExpectEarlyDataAccepted: false,
11627 },
11628 },
11629 resumeSession: true,
11630 flags: []string{
11631 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011632 "-on-initial-select-alpn", "foo",
11633 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011634 },
11635 })
11636
David Benjamin6bb507b2017-03-29 16:35:57 -050011637 // Test that the client offering 0-RTT and Channel ID forbids the server
11638 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011639 testCases = append(testCases, testCase{
11640 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011641 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011642 config: Config{
11643 MaxVersion: VersionTLS13,
11644 MaxEarlyDataSize: 16384,
11645 RequestChannelID: true,
11646 },
11647 resumeSession: true,
11648 expectChannelID: true,
11649 shouldFail: true,
11650 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11651 flags: []string{
11652 "-enable-early-data",
11653 "-expect-early-data-info",
11654 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11655 },
11656 })
11657
David Benjamin6bb507b2017-03-29 16:35:57 -050011658 // Test that the client offering Channel ID and 0-RTT allows the server
11659 // to decline 0-RTT.
11660 testCases = append(testCases, testCase{
11661 testType: clientTest,
11662 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11663 config: Config{
11664 MaxVersion: VersionTLS13,
11665 MaxEarlyDataSize: 16384,
11666 RequestChannelID: true,
11667 Bugs: ProtocolBugs{
11668 AlwaysRejectEarlyData: true,
11669 },
11670 },
11671 resumeSession: true,
11672 expectChannelID: true,
11673 flags: []string{
11674 "-enable-early-data",
11675 "-expect-early-data-info",
11676 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11677 "-expect-reject-early-data",
11678 },
11679 })
11680
11681 // Test that the client offering Channel ID and 0-RTT allows the server
11682 // to decline Channel ID.
11683 testCases = append(testCases, testCase{
11684 testType: clientTest,
11685 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11686 config: Config{
11687 MaxVersion: VersionTLS13,
11688 MaxEarlyDataSize: 16384,
11689 },
11690 resumeSession: true,
11691 flags: []string{
11692 "-enable-early-data",
11693 "-expect-early-data-info",
11694 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11695 "-expect-accept-early-data",
11696 },
11697 })
11698
11699 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11700 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011701 testCases = append(testCases, testCase{
11702 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011703 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011704 config: Config{
11705 MaxVersion: VersionTLS13,
11706 ChannelID: channelIDKey,
11707 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011708 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011709 ExpectEarlyDataAccepted: false,
11710 },
11711 },
11712 resumeSession: true,
11713 expectChannelID: true,
11714 flags: []string{
11715 "-enable-early-data",
11716 "-expect-reject-early-data",
11717 "-expect-channel-id",
11718 base64.StdEncoding.EncodeToString(channelIDBytes),
11719 },
11720 })
11721
David Benjamin6bb507b2017-03-29 16:35:57 -050011722 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11723 // if not offered Channel ID.
11724 testCases = append(testCases, testCase{
11725 testType: serverTest,
11726 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11727 config: Config{
11728 MaxVersion: VersionTLS13,
11729 Bugs: ProtocolBugs{
11730 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11731 ExpectEarlyDataAccepted: true,
11732 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11733 },
11734 },
11735 resumeSession: true,
11736 expectChannelID: false,
11737 flags: []string{
11738 "-enable-early-data",
11739 "-expect-accept-early-data",
11740 "-enable-channel-id",
11741 },
11742 })
11743
David Benjamin32c89272017-03-26 13:54:21 -050011744 // Test that the server rejects 0-RTT streams without end_of_early_data.
11745 // The subsequent records should fail to decrypt.
11746 testCases = append(testCases, testCase{
11747 testType: serverTest,
11748 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11749 config: Config{
11750 MaxVersion: VersionTLS13,
11751 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011752 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011753 ExpectEarlyDataAccepted: true,
11754 SkipEndOfEarlyData: true,
11755 },
11756 },
11757 resumeSession: true,
11758 flags: []string{"-enable-early-data"},
11759 shouldFail: true,
11760 expectedLocalError: "remote error: bad record MAC",
11761 expectedError: ":BAD_DECRYPT:",
11762 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011763
11764 testCases = append(testCases, testCase{
11765 testType: serverTest,
11766 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11767 config: Config{
11768 MaxVersion: VersionTLS13,
11769 },
11770 resumeConfig: &Config{
11771 MaxVersion: VersionTLS13,
11772 Bugs: ProtocolBugs{
11773 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11774 SendStrayEarlyHandshake: true,
11775 ExpectEarlyDataAccepted: true},
11776 },
11777 resumeSession: true,
11778 shouldFail: true,
11779 expectedError: ":UNEXPECTED_RECORD:",
11780 expectedLocalError: "remote error: unexpected message",
11781 flags: []string{
11782 "-enable-early-data",
11783 },
11784 })
David Benjamind9cbb532017-07-07 13:17:19 -040011785
11786 // Test that the client reports TLS 1.3 as the version while sending
11787 // early data.
11788 testCases = append(testCases, testCase{
11789 testType: clientTest,
11790 name: "TLS13-EarlyData-Client-VersionAPI",
11791 config: Config{
11792 MaxVersion: VersionTLS13,
11793 MaxEarlyDataSize: 16384,
11794 },
11795 resumeSession: true,
11796 flags: []string{
11797 "-enable-early-data",
11798 "-expect-early-data-info",
11799 "-expect-accept-early-data",
11800 "-expect-version", strconv.Itoa(VersionTLS13),
11801 },
11802 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011803}
11804
David Benjaminabbbee12016-10-31 19:20:42 -040011805func addTLS13CipherPreferenceTests() {
11806 // Test that client preference is honored if the shim has AES hardware
11807 // and ChaCha20-Poly1305 is preferred otherwise.
11808 testCases = append(testCases, testCase{
11809 testType: serverTest,
11810 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11811 config: Config{
11812 MaxVersion: VersionTLS13,
11813 CipherSuites: []uint16{
11814 TLS_CHACHA20_POLY1305_SHA256,
11815 TLS_AES_128_GCM_SHA256,
11816 },
11817 },
11818 flags: []string{
11819 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11820 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11821 },
11822 })
11823
11824 testCases = append(testCases, testCase{
11825 testType: serverTest,
11826 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11827 config: Config{
11828 MaxVersion: VersionTLS13,
11829 CipherSuites: []uint16{
11830 TLS_AES_128_GCM_SHA256,
11831 TLS_CHACHA20_POLY1305_SHA256,
11832 },
11833 },
11834 flags: []string{
11835 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11836 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11837 },
11838 })
11839
11840 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11841 // whether it has AES hardware.
11842 testCases = append(testCases, testCase{
11843 name: "TLS13-CipherPreference-Client",
11844 config: Config{
11845 MaxVersion: VersionTLS13,
11846 // Use the client cipher order. (This is the default but
11847 // is listed to be explicit.)
11848 PreferServerCipherSuites: false,
11849 },
11850 flags: []string{
11851 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11852 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11853 },
11854 })
11855}
11856
David Benjaminf3fbade2016-09-19 13:08:16 -040011857func addPeekTests() {
11858 // Test SSL_peek works, including on empty records.
11859 testCases = append(testCases, testCase{
11860 name: "Peek-Basic",
11861 sendEmptyRecords: 1,
11862 flags: []string{"-peek-then-read"},
11863 })
11864
11865 // Test SSL_peek can drive the initial handshake.
11866 testCases = append(testCases, testCase{
11867 name: "Peek-ImplicitHandshake",
11868 flags: []string{
11869 "-peek-then-read",
11870 "-implicit-handshake",
11871 },
11872 })
11873
11874 // Test SSL_peek can discover and drive a renegotiation.
11875 testCases = append(testCases, testCase{
11876 name: "Peek-Renegotiate",
11877 config: Config{
11878 MaxVersion: VersionTLS12,
11879 },
11880 renegotiate: 1,
11881 flags: []string{
11882 "-peek-then-read",
11883 "-renegotiate-freely",
11884 "-expect-total-renegotiations", "1",
11885 },
11886 })
11887
11888 // Test SSL_peek can discover a close_notify.
11889 testCases = append(testCases, testCase{
11890 name: "Peek-Shutdown",
11891 config: Config{
11892 Bugs: ProtocolBugs{
11893 ExpectCloseNotify: true,
11894 },
11895 },
11896 flags: []string{
11897 "-peek-then-read",
11898 "-check-close-notify",
11899 },
11900 })
11901
11902 // Test SSL_peek can discover an alert.
11903 testCases = append(testCases, testCase{
11904 name: "Peek-Alert",
11905 config: Config{
11906 Bugs: ProtocolBugs{
11907 SendSpuriousAlert: alertRecordOverflow,
11908 },
11909 },
11910 flags: []string{"-peek-then-read"},
11911 shouldFail: true,
11912 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11913 })
11914
11915 // Test SSL_peek can handle KeyUpdate.
11916 testCases = append(testCases, testCase{
11917 name: "Peek-KeyUpdate",
11918 config: Config{
11919 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011920 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011921 sendKeyUpdates: 1,
11922 keyUpdateRequest: keyUpdateNotRequested,
11923 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011924 })
11925}
11926
David Benjamine6f22212016-11-08 14:28:24 -050011927func addRecordVersionTests() {
11928 for _, ver := range tlsVersions {
11929 // Test that the record version is enforced.
11930 testCases = append(testCases, testCase{
11931 name: "CheckRecordVersion-" + ver.name,
11932 config: Config{
11933 MinVersion: ver.version,
11934 MaxVersion: ver.version,
11935 Bugs: ProtocolBugs{
11936 SendRecordVersion: 0x03ff,
11937 },
11938 },
David Benjamina5022392017-07-10 17:40:39 -040011939 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011940 shouldFail: true,
11941 expectedError: ":WRONG_VERSION_NUMBER:",
11942 })
11943
11944 // Test that the ClientHello may use any record version, for
11945 // compatibility reasons.
11946 testCases = append(testCases, testCase{
11947 testType: serverTest,
11948 name: "LooseInitialRecordVersion-" + ver.name,
11949 config: Config{
11950 MinVersion: ver.version,
11951 MaxVersion: ver.version,
11952 Bugs: ProtocolBugs{
11953 SendInitialRecordVersion: 0x03ff,
11954 },
11955 },
David Benjamina5022392017-07-10 17:40:39 -040011956 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011957 })
11958
11959 // Test that garbage ClientHello record versions are rejected.
11960 testCases = append(testCases, testCase{
11961 testType: serverTest,
11962 name: "GarbageInitialRecordVersion-" + ver.name,
11963 config: Config{
11964 MinVersion: ver.version,
11965 MaxVersion: ver.version,
11966 Bugs: ProtocolBugs{
11967 SendInitialRecordVersion: 0xffff,
11968 },
11969 },
David Benjamina5022392017-07-10 17:40:39 -040011970 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011971 shouldFail: true,
11972 expectedError: ":WRONG_VERSION_NUMBER:",
11973 })
11974 }
11975}
11976
David Benjamin2c516452016-11-15 10:16:54 +090011977func addCertificateTests() {
11978 // Test that a certificate chain with intermediate may be sent and
11979 // received as both client and server.
11980 for _, ver := range tlsVersions {
11981 testCases = append(testCases, testCase{
11982 testType: clientTest,
11983 name: "SendReceiveIntermediate-Client-" + ver.name,
11984 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011985 MinVersion: ver.version,
11986 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011987 Certificates: []Certificate{rsaChainCertificate},
11988 ClientAuth: RequireAnyClientCert,
11989 },
David Benjamina5022392017-07-10 17:40:39 -040011990 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011991 expectPeerCertificate: &rsaChainCertificate,
11992 flags: []string{
11993 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11994 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11995 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11996 },
11997 })
11998
11999 testCases = append(testCases, testCase{
12000 testType: serverTest,
12001 name: "SendReceiveIntermediate-Server-" + ver.name,
12002 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012003 MinVersion: ver.version,
12004 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012005 Certificates: []Certificate{rsaChainCertificate},
12006 },
David Benjamina5022392017-07-10 17:40:39 -040012007 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012008 expectPeerCertificate: &rsaChainCertificate,
12009 flags: []string{
12010 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12011 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12012 "-require-any-client-certificate",
12013 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12014 },
12015 })
12016 }
12017}
12018
David Benjaminbbaf3672016-11-17 10:53:09 +090012019func addRetainOnlySHA256ClientCertTests() {
12020 for _, ver := range tlsVersions {
12021 // Test that enabling
12022 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12023 // actually requesting a client certificate is a no-op.
12024 testCases = append(testCases, testCase{
12025 testType: serverTest,
12026 name: "RetainOnlySHA256-NoCert-" + ver.name,
12027 config: Config{
12028 MinVersion: ver.version,
12029 MaxVersion: ver.version,
12030 },
David Benjamina5022392017-07-10 17:40:39 -040012031 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012032 flags: []string{
12033 "-retain-only-sha256-client-cert-initial",
12034 "-retain-only-sha256-client-cert-resume",
12035 },
12036 resumeSession: true,
12037 })
12038
12039 // Test that when retaining only a SHA-256 certificate is
12040 // enabled, the hash appears as expected.
12041 testCases = append(testCases, testCase{
12042 testType: serverTest,
12043 name: "RetainOnlySHA256-Cert-" + ver.name,
12044 config: Config{
12045 MinVersion: ver.version,
12046 MaxVersion: ver.version,
12047 Certificates: []Certificate{rsaCertificate},
12048 },
David Benjamina5022392017-07-10 17:40:39 -040012049 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012050 flags: []string{
12051 "-verify-peer",
12052 "-retain-only-sha256-client-cert-initial",
12053 "-retain-only-sha256-client-cert-resume",
12054 "-expect-sha256-client-cert-initial",
12055 "-expect-sha256-client-cert-resume",
12056 },
12057 resumeSession: true,
12058 })
12059
12060 // Test that when the config changes from on to off, a
12061 // resumption is rejected because the server now wants the full
12062 // certificate chain.
12063 testCases = append(testCases, testCase{
12064 testType: serverTest,
12065 name: "RetainOnlySHA256-OnOff-" + ver.name,
12066 config: Config{
12067 MinVersion: ver.version,
12068 MaxVersion: ver.version,
12069 Certificates: []Certificate{rsaCertificate},
12070 },
David Benjamina5022392017-07-10 17:40:39 -040012071 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012072 flags: []string{
12073 "-verify-peer",
12074 "-retain-only-sha256-client-cert-initial",
12075 "-expect-sha256-client-cert-initial",
12076 },
12077 resumeSession: true,
12078 expectResumeRejected: true,
12079 })
12080
12081 // Test that when the config changes from off to on, a
12082 // resumption is rejected because the server now wants just the
12083 // hash.
12084 testCases = append(testCases, testCase{
12085 testType: serverTest,
12086 name: "RetainOnlySHA256-OffOn-" + ver.name,
12087 config: Config{
12088 MinVersion: ver.version,
12089 MaxVersion: ver.version,
12090 Certificates: []Certificate{rsaCertificate},
12091 },
David Benjamina5022392017-07-10 17:40:39 -040012092 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012093 flags: []string{
12094 "-verify-peer",
12095 "-retain-only-sha256-client-cert-resume",
12096 "-expect-sha256-client-cert-resume",
12097 },
12098 resumeSession: true,
12099 expectResumeRejected: true,
12100 })
12101 }
12102}
12103
Adam Langleya4b91982016-12-12 12:05:53 -080012104func addECDSAKeyUsageTests() {
12105 p256 := elliptic.P256()
12106 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12107 if err != nil {
12108 panic(err)
12109 }
12110
12111 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12112 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12113 if err != nil {
12114 panic(err)
12115 }
12116
12117 template := x509.Certificate{
12118 SerialNumber: serialNumber,
12119 Subject: pkix.Name{
12120 Organization: []string{"Acme Co"},
12121 },
12122 NotBefore: time.Now(),
12123 NotAfter: time.Now(),
12124
12125 // An ECC certificate with only the keyAgreement key usgae may
12126 // be used with ECDH, but not ECDSA.
12127 KeyUsage: x509.KeyUsageKeyAgreement,
12128 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12129 BasicConstraintsValid: true,
12130 }
12131
12132 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12133 if err != nil {
12134 panic(err)
12135 }
12136
12137 cert := Certificate{
12138 Certificate: [][]byte{derBytes},
12139 PrivateKey: priv,
12140 }
12141
12142 for _, ver := range tlsVersions {
12143 if ver.version < VersionTLS12 {
12144 continue
12145 }
12146
12147 testCases = append(testCases, testCase{
12148 testType: clientTest,
12149 name: "ECDSAKeyUsage-" + ver.name,
12150 config: Config{
12151 MinVersion: ver.version,
12152 MaxVersion: ver.version,
12153 Certificates: []Certificate{cert},
12154 },
David Benjamina5022392017-07-10 17:40:39 -040012155 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012156 shouldFail: true,
12157 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12158 })
12159 }
12160}
12161
David Benjamin8c26d752017-03-26 15:13:51 -050012162func addExtraHandshakeTests() {
12163 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12164 // to ensure there is no transport I/O.
12165 testCases = append(testCases, testCase{
12166 testType: clientTest,
12167 name: "ExtraHandshake-Client-TLS12",
12168 config: Config{
12169 MinVersion: VersionTLS12,
12170 MaxVersion: VersionTLS12,
12171 },
12172 flags: []string{
12173 "-async",
12174 "-no-op-extra-handshake",
12175 },
12176 })
12177 testCases = append(testCases, testCase{
12178 testType: serverTest,
12179 name: "ExtraHandshake-Server-TLS12",
12180 config: Config{
12181 MinVersion: VersionTLS12,
12182 MaxVersion: VersionTLS12,
12183 },
12184 flags: []string{
12185 "-async",
12186 "-no-op-extra-handshake",
12187 },
12188 })
12189 testCases = append(testCases, testCase{
12190 testType: clientTest,
12191 name: "ExtraHandshake-Client-TLS13",
12192 config: Config{
12193 MinVersion: VersionTLS13,
12194 MaxVersion: VersionTLS13,
12195 },
12196 flags: []string{
12197 "-async",
12198 "-no-op-extra-handshake",
12199 },
12200 })
12201 testCases = append(testCases, testCase{
12202 testType: serverTest,
12203 name: "ExtraHandshake-Server-TLS13",
12204 config: Config{
12205 MinVersion: VersionTLS13,
12206 MaxVersion: VersionTLS13,
12207 },
12208 flags: []string{
12209 "-async",
12210 "-no-op-extra-handshake",
12211 },
12212 })
12213
12214 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12215 testCases = append(testCases, testCase{
12216 testType: serverTest,
12217 name: "ExtraHandshake-Server-EarlyData-TLS13",
12218 config: Config{
12219 MaxVersion: VersionTLS13,
12220 MinVersion: VersionTLS13,
12221 Bugs: ProtocolBugs{
12222 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12223 ExpectEarlyDataAccepted: true,
12224 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12225 },
12226 },
12227 messageCount: 2,
12228 resumeSession: true,
12229 flags: []string{
12230 "-async",
12231 "-enable-early-data",
12232 "-expect-accept-early-data",
12233 "-no-op-extra-handshake",
12234 },
12235 })
12236
12237 // An extra SSL_do_handshake drives the handshake to completion in False
12238 // Start. We test this by handshaking twice and asserting the False
12239 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12240 // how the test works.
12241 testCases = append(testCases, testCase{
12242 testType: clientTest,
12243 name: "ExtraHandshake-FalseStart",
12244 config: Config{
12245 MaxVersion: VersionTLS12,
12246 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12247 NextProtos: []string{"foo"},
12248 Bugs: ProtocolBugs{
12249 ExpectFalseStart: true,
12250 AlertBeforeFalseStartTest: alertAccessDenied,
12251 },
12252 },
12253 flags: []string{
12254 "-handshake-twice",
12255 "-false-start",
12256 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012257 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012258 },
12259 shimWritesFirst: true,
12260 shouldFail: true,
12261 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12262 expectedLocalError: "tls: peer did not false start: EOF",
12263 })
12264}
12265
David Benjaminb853f312017-07-14 18:40:34 -040012266// Test that omitted and empty extensions blocks are tolerated.
12267func addOmitExtensionsTests() {
12268 for _, ver := range tlsVersions {
12269 if ver.version > VersionTLS12 {
12270 continue
12271 }
12272
12273 testCases = append(testCases, testCase{
12274 testType: serverTest,
12275 name: "OmitExtensions-ClientHello-" + ver.name,
12276 config: Config{
12277 MinVersion: ver.version,
12278 MaxVersion: ver.version,
12279 SessionTicketsDisabled: true,
12280 Bugs: ProtocolBugs{
12281 OmitExtensions: true,
12282 },
12283 },
12284 })
12285
12286 testCases = append(testCases, testCase{
12287 testType: serverTest,
12288 name: "EmptyExtensions-ClientHello-" + ver.name,
12289 config: Config{
12290 MinVersion: ver.version,
12291 MaxVersion: ver.version,
12292 SessionTicketsDisabled: true,
12293 Bugs: ProtocolBugs{
12294 EmptyExtensions: true,
12295 },
12296 },
12297 })
12298
12299 testCases = append(testCases, testCase{
12300 testType: clientTest,
12301 name: "OmitExtensions-ServerHello-" + ver.name,
12302 config: Config{
12303 MinVersion: ver.version,
12304 MaxVersion: ver.version,
12305 SessionTicketsDisabled: true,
12306 Bugs: ProtocolBugs{
12307 OmitExtensions: true,
12308 // Disable all ServerHello extensions so
12309 // OmitExtensions works.
12310 NoExtendedMasterSecret: true,
12311 NoRenegotiationInfo: true,
12312 },
12313 },
12314 })
12315
12316 testCases = append(testCases, testCase{
12317 testType: clientTest,
12318 name: "EmptyExtensions-ServerHello-" + ver.name,
12319 config: Config{
12320 MinVersion: ver.version,
12321 MaxVersion: ver.version,
12322 SessionTicketsDisabled: true,
12323 Bugs: ProtocolBugs{
12324 EmptyExtensions: true,
12325 // Disable all ServerHello extensions so
12326 // EmptyExtensions works.
12327 NoExtendedMasterSecret: true,
12328 NoRenegotiationInfo: true,
12329 },
12330 },
12331 })
12332 }
12333}
12334
Adam Langley7c803a62015-06-15 15:35:05 -070012335func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012336 defer wg.Done()
12337
12338 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012339 var err error
12340
David Benjaminba28dfc2016-11-15 17:47:21 +090012341 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012342 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12343 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012344 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012345 if err != nil {
12346 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12347 }
12348 break
12349 }
12350 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012351 } else if *repeatUntilFailure {
12352 for err == nil {
12353 statusChan <- statusMsg{test: test, started: true}
12354 err = runTest(test, shimPath, -1)
12355 }
12356 } else {
12357 statusChan <- statusMsg{test: test, started: true}
12358 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012359 }
Adam Langley95c29f32014-06-20 12:00:00 -070012360 statusChan <- statusMsg{test: test, err: err}
12361 }
12362}
12363
12364type statusMsg struct {
12365 test *testCase
12366 started bool
12367 err error
12368}
12369
David Benjamin5f237bc2015-02-11 17:14:15 -050012370func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012371 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012372
David Benjamin5f237bc2015-02-11 17:14:15 -050012373 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012374 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012375 if !*pipe {
12376 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012377 var erase string
12378 for i := 0; i < lineLen; i++ {
12379 erase += "\b \b"
12380 }
12381 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012382 }
12383
Adam Langley95c29f32014-06-20 12:00:00 -070012384 if msg.started {
12385 started++
12386 } else {
12387 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012388
12389 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012390 if msg.err == errUnimplemented {
12391 if *pipe {
12392 // Print each test instead of a status line.
12393 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12394 }
12395 unimplemented++
12396 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12397 } else {
12398 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12399 failed++
12400 testOutput.addResult(msg.test.name, "FAIL")
12401 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012402 } else {
12403 if *pipe {
12404 // Print each test instead of a status line.
12405 fmt.Printf("PASSED (%s)\n", msg.test.name)
12406 }
12407 testOutput.addResult(msg.test.name, "PASS")
12408 }
Adam Langley95c29f32014-06-20 12:00:00 -070012409 }
12410
David Benjamin5f237bc2015-02-11 17:14:15 -050012411 if !*pipe {
12412 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012413 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012414 lineLen = len(line)
12415 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012416 }
Adam Langley95c29f32014-06-20 12:00:00 -070012417 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012418
12419 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012420}
12421
12422func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012423 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012424 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012425 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012426
Adam Langley7c803a62015-06-15 15:35:05 -070012427 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012428 addCipherSuiteTests()
12429 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012430 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012431 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012432 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012433 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012434 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012435 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012436 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012437 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012438 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012439 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012440 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012441 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012442 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012443 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012444 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012445 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012446 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012447 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012448 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012449 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012450 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012451 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012452 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012453 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012454 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012455 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012456 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012457 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012458 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012459 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012460 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012461 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012462 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012463
12464 var wg sync.WaitGroup
12465
Adam Langley7c803a62015-06-15 15:35:05 -070012466 statusChan := make(chan statusMsg, *numWorkers)
12467 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012468 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012469
EKRf71d7ed2016-08-06 13:25:12 -070012470 if len(*shimConfigFile) != 0 {
12471 encoded, err := ioutil.ReadFile(*shimConfigFile)
12472 if err != nil {
12473 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12474 os.Exit(1)
12475 }
12476
12477 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12478 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12479 os.Exit(1)
12480 }
12481 }
12482
David Benjamin025b3d32014-07-01 19:53:04 -040012483 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012484
Adam Langley7c803a62015-06-15 15:35:05 -070012485 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012486 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012487 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012488 }
12489
David Benjamin270f0a72016-03-17 14:41:36 -040012490 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012491 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012492 matched := true
12493 if len(*testToRun) != 0 {
12494 var err error
12495 matched, err = filepath.Match(*testToRun, testCases[i].name)
12496 if err != nil {
12497 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12498 os.Exit(1)
12499 }
12500 }
12501
EKRf71d7ed2016-08-06 13:25:12 -070012502 if !*includeDisabled {
12503 for pattern := range shimConfig.DisabledTests {
12504 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12505 if err != nil {
12506 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12507 os.Exit(1)
12508 }
12509
12510 if isDisabled {
12511 matched = false
12512 break
12513 }
12514 }
12515 }
12516
David Benjamin17e12922016-07-28 18:04:43 -040012517 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012518 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012519 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012520
12521 // Only run one test if repeating until failure.
12522 if *repeatUntilFailure {
12523 break
12524 }
Adam Langley95c29f32014-06-20 12:00:00 -070012525 }
12526 }
David Benjamin17e12922016-07-28 18:04:43 -040012527
David Benjamin270f0a72016-03-17 14:41:36 -040012528 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012529 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012530 os.Exit(1)
12531 }
Adam Langley95c29f32014-06-20 12:00:00 -070012532
12533 close(testChan)
12534 wg.Wait()
12535 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012536 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012537
12538 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012539
12540 if *jsonOutput != "" {
12541 if err := testOutput.writeTo(*jsonOutput); err != nil {
12542 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12543 }
12544 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012545
EKR842ae6c2016-07-27 09:22:05 +020012546 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12547 os.Exit(1)
12548 }
12549
12550 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012551 os.Exit(1)
12552 }
Adam Langley95c29f32014-06-20 12:00:00 -070012553}