blob: 7e64fe5f9e8036f44ec71005e22153159a1f6658 [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,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001515 name: "ServerSkipCertificateVerify",
1516 config: Config{
1517 MaxVersion: VersionTLS12,
1518 Certificates: []Certificate{rsaChainCertificate},
1519 Bugs: ProtocolBugs{
1520 SkipCertificateVerify: true,
1521 },
1522 },
1523 expectPeerCertificate: &rsaChainCertificate,
1524 flags: []string{
1525 "-require-any-client-certificate",
1526 },
1527 shouldFail: true,
1528 expectedError: ":UNEXPECTED_RECORD:",
1529 expectedLocalError: "remote error: unexpected message",
1530 },
1531 {
1532 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 name: "Alert",
1534 config: Config{
1535 Bugs: ProtocolBugs{
1536 SendSpuriousAlert: alertRecordOverflow,
1537 },
1538 },
1539 shouldFail: true,
1540 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1541 },
1542 {
1543 protocol: dtls,
1544 testType: serverTest,
1545 name: "Alert-DTLS",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 SendSpuriousAlert: alertRecordOverflow,
1549 },
1550 },
1551 shouldFail: true,
1552 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1553 },
1554 {
1555 testType: serverTest,
1556 name: "FragmentAlert",
1557 config: Config{
1558 Bugs: ProtocolBugs{
1559 FragmentAlert: true,
1560 SendSpuriousAlert: alertRecordOverflow,
1561 },
1562 },
1563 shouldFail: true,
1564 expectedError: ":BAD_ALERT:",
1565 },
1566 {
1567 protocol: dtls,
1568 testType: serverTest,
1569 name: "FragmentAlert-DTLS",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 FragmentAlert: true,
1573 SendSpuriousAlert: alertRecordOverflow,
1574 },
1575 },
1576 shouldFail: true,
1577 expectedError: ":BAD_ALERT:",
1578 },
1579 {
1580 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001581 name: "DoubleAlert",
1582 config: Config{
1583 Bugs: ProtocolBugs{
1584 DoubleAlert: true,
1585 SendSpuriousAlert: alertRecordOverflow,
1586 },
1587 },
1588 shouldFail: true,
1589 expectedError: ":BAD_ALERT:",
1590 },
1591 {
1592 protocol: dtls,
1593 testType: serverTest,
1594 name: "DoubleAlert-DTLS",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 DoubleAlert: true,
1598 SendSpuriousAlert: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":BAD_ALERT:",
1603 },
1604 {
Adam Langley7c803a62015-06-15 15:35:05 -07001605 name: "SkipNewSessionTicket",
1606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001607 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001608 Bugs: ProtocolBugs{
1609 SkipNewSessionTicket: true,
1610 },
1611 },
1612 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001613 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001614 },
1615 {
1616 testType: serverTest,
1617 name: "FallbackSCSV",
1618 config: Config{
1619 MaxVersion: VersionTLS11,
1620 Bugs: ProtocolBugs{
1621 SendFallbackSCSV: true,
1622 },
1623 },
David Benjamin56cadc32016-12-16 19:54:11 -05001624 shouldFail: true,
1625 expectedError: ":INAPPROPRIATE_FALLBACK:",
1626 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001627 },
1628 {
1629 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001630 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001631 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001632 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 Bugs: ProtocolBugs{
1634 SendFallbackSCSV: true,
1635 },
1636 },
1637 },
1638 {
1639 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001640 name: "FallbackSCSV-VersionMatch-TLS12",
1641 config: Config{
1642 MaxVersion: VersionTLS12,
1643 Bugs: ProtocolBugs{
1644 SendFallbackSCSV: true,
1645 },
1646 },
1647 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1648 },
1649 {
1650 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001651 name: "FragmentedClientVersion",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 MaxHandshakeRecordLength: 1,
1655 FragmentClientVersion: true,
1656 },
1657 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001658 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001659 },
1660 {
Adam Langley7c803a62015-06-15 15:35:05 -07001661 testType: serverTest,
1662 name: "HttpGET",
1663 sendPrefix: "GET / HTTP/1.0\n",
1664 shouldFail: true,
1665 expectedError: ":HTTP_REQUEST:",
1666 },
1667 {
1668 testType: serverTest,
1669 name: "HttpPOST",
1670 sendPrefix: "POST / HTTP/1.0\n",
1671 shouldFail: true,
1672 expectedError: ":HTTP_REQUEST:",
1673 },
1674 {
1675 testType: serverTest,
1676 name: "HttpHEAD",
1677 sendPrefix: "HEAD / HTTP/1.0\n",
1678 shouldFail: true,
1679 expectedError: ":HTTP_REQUEST:",
1680 },
1681 {
1682 testType: serverTest,
1683 name: "HttpPUT",
1684 sendPrefix: "PUT / HTTP/1.0\n",
1685 shouldFail: true,
1686 expectedError: ":HTTP_REQUEST:",
1687 },
1688 {
1689 testType: serverTest,
1690 name: "HttpCONNECT",
1691 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1692 shouldFail: true,
1693 expectedError: ":HTTPS_PROXY_REQUEST:",
1694 },
1695 {
1696 testType: serverTest,
1697 name: "Garbage",
1698 sendPrefix: "blah",
1699 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001700 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
Adam Langley7c803a62015-06-15 15:35:05 -07001703 name: "RSAEphemeralKey",
1704 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001705 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001706 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1707 Bugs: ProtocolBugs{
1708 RSAEphemeralKey: true,
1709 },
1710 },
1711 shouldFail: true,
1712 expectedError: ":UNEXPECTED_MESSAGE:",
1713 },
1714 {
1715 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001716 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001717 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001718 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001719 },
1720 {
1721 protocol: dtls,
1722 name: "DisableEverything-DTLS",
1723 flags: []string{"-no-tls12", "-no-tls1"},
1724 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001725 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001726 },
1727 {
Adam Langley7c803a62015-06-15 15:35:05 -07001728 protocol: dtls,
1729 testType: serverTest,
1730 name: "MTU",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxPacketLength: 256,
1734 },
1735 },
1736 flags: []string{"-mtu", "256"},
1737 },
1738 {
1739 protocol: dtls,
1740 testType: serverTest,
1741 name: "MTUExceeded",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 MaxPacketLength: 255,
1745 },
1746 },
1747 flags: []string{"-mtu", "256"},
1748 shouldFail: true,
1749 expectedLocalError: "dtls: exceeded maximum packet length",
1750 },
1751 {
Adam Langley7c803a62015-06-15 15:35:05 -07001752 name: "EmptyCertificateList",
1753 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001754 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001755 Bugs: ProtocolBugs{
1756 EmptyCertificateList: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DECODE_ERROR:",
1761 },
1762 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001763 name: "EmptyCertificateList-TLS13",
1764 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001765 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001766 Bugs: ProtocolBugs{
1767 EmptyCertificateList: true,
1768 },
1769 },
1770 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001771 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001772 },
1773 {
Adam Langley7c803a62015-06-15 15:35:05 -07001774 name: "TLSFatalBadPackets",
1775 damageFirstWrite: true,
1776 shouldFail: true,
1777 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1778 },
1779 {
1780 protocol: dtls,
1781 name: "DTLSIgnoreBadPackets",
1782 damageFirstWrite: true,
1783 },
1784 {
1785 protocol: dtls,
1786 name: "DTLSIgnoreBadPackets-Async",
1787 damageFirstWrite: true,
1788 flags: []string{"-async"},
1789 },
1790 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001791 name: "AppDataBeforeHandshake",
1792 config: Config{
1793 Bugs: ProtocolBugs{
1794 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1795 },
1796 },
1797 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001798 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001799 },
1800 {
1801 name: "AppDataBeforeHandshake-Empty",
1802 config: Config{
1803 Bugs: ProtocolBugs{
1804 AppDataBeforeHandshake: []byte{},
1805 },
1806 },
1807 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001808 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001809 },
1810 {
1811 protocol: dtls,
1812 name: "AppDataBeforeHandshake-DTLS",
1813 config: Config{
1814 Bugs: ProtocolBugs{
1815 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1816 },
1817 },
1818 shouldFail: true,
1819 expectedError: ":UNEXPECTED_RECORD:",
1820 },
1821 {
1822 protocol: dtls,
1823 name: "AppDataBeforeHandshake-DTLS-Empty",
1824 config: Config{
1825 Bugs: ProtocolBugs{
1826 AppDataBeforeHandshake: []byte{},
1827 },
1828 },
1829 shouldFail: true,
1830 expectedError: ":UNEXPECTED_RECORD:",
1831 },
1832 {
Adam Langley7c803a62015-06-15 15:35:05 -07001833 name: "AppDataAfterChangeCipherSpec",
1834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 Bugs: ProtocolBugs{
1837 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1838 },
1839 },
1840 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001841 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001842 },
1843 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001844 name: "AppDataAfterChangeCipherSpec-Empty",
1845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001846 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001847 Bugs: ProtocolBugs{
1848 AppDataAfterChangeCipherSpec: []byte{},
1849 },
1850 },
1851 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001852 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001853 },
1854 {
Adam Langley7c803a62015-06-15 15:35:05 -07001855 protocol: dtls,
1856 name: "AppDataAfterChangeCipherSpec-DTLS",
1857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001858 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001859 Bugs: ProtocolBugs{
1860 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1861 },
1862 },
1863 // BoringSSL's DTLS implementation will drop the out-of-order
1864 // application data.
1865 },
1866 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001867 protocol: dtls,
1868 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001870 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001871 Bugs: ProtocolBugs{
1872 AppDataAfterChangeCipherSpec: []byte{},
1873 },
1874 },
1875 // BoringSSL's DTLS implementation will drop the out-of-order
1876 // application data.
1877 },
1878 {
Adam Langley7c803a62015-06-15 15:35:05 -07001879 name: "AlertAfterChangeCipherSpec",
1880 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001881 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001882 Bugs: ProtocolBugs{
1883 AlertAfterChangeCipherSpec: alertRecordOverflow,
1884 },
1885 },
1886 shouldFail: true,
1887 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1888 },
1889 {
1890 protocol: dtls,
1891 name: "AlertAfterChangeCipherSpec-DTLS",
1892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001893 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001894 Bugs: ProtocolBugs{
1895 AlertAfterChangeCipherSpec: alertRecordOverflow,
1896 },
1897 },
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1900 },
1901 {
1902 protocol: dtls,
1903 name: "ReorderHandshakeFragments-Small-DTLS",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 ReorderHandshakeFragments: true,
1907 // Small enough that every handshake message is
1908 // fragmented.
1909 MaxHandshakeRecordLength: 2,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "ReorderHandshakeFragments-Large-DTLS",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 ReorderHandshakeFragments: true,
1919 // Large enough that no handshake message is
1920 // fragmented.
1921 MaxHandshakeRecordLength: 2048,
1922 },
1923 },
1924 },
1925 {
1926 protocol: dtls,
1927 name: "MixCompleteMessageWithFragments-DTLS",
1928 config: Config{
1929 Bugs: ProtocolBugs{
1930 ReorderHandshakeFragments: true,
1931 MixCompleteMessageWithFragments: true,
1932 MaxHandshakeRecordLength: 2,
1933 },
1934 },
1935 },
1936 {
1937 name: "SendInvalidRecordType",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendInvalidRecordType: true,
1941 },
1942 },
1943 shouldFail: true,
1944 expectedError: ":UNEXPECTED_RECORD:",
1945 },
1946 {
1947 protocol: dtls,
1948 name: "SendInvalidRecordType-DTLS",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 SendInvalidRecordType: true,
1952 },
1953 },
1954 shouldFail: true,
1955 expectedError: ":UNEXPECTED_RECORD:",
1956 },
1957 {
1958 name: "FalseStart-SkipServerSecondLeg",
1959 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001960 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1962 NextProtos: []string{"foo"},
1963 Bugs: ProtocolBugs{
1964 SkipNewSessionTicket: true,
1965 SkipChangeCipherSpec: true,
1966 SkipFinished: true,
1967 ExpectFalseStart: true,
1968 },
1969 },
1970 flags: []string{
1971 "-false-start",
1972 "-handshake-never-done",
1973 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001974 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001975 },
1976 shimWritesFirst: true,
1977 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001978 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001979 },
1980 {
1981 name: "FalseStart-SkipServerSecondLeg-Implicit",
1982 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001983 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1985 NextProtos: []string{"foo"},
1986 Bugs: ProtocolBugs{
1987 SkipNewSessionTicket: true,
1988 SkipChangeCipherSpec: true,
1989 SkipFinished: true,
1990 },
1991 },
1992 flags: []string{
1993 "-implicit-handshake",
1994 "-false-start",
1995 "-handshake-never-done",
1996 "-advertise-alpn", "\x03foo",
1997 },
1998 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001999 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002000 },
2001 {
2002 testType: serverTest,
2003 name: "FailEarlyCallback",
2004 flags: []string{"-fail-early-callback"},
2005 shouldFail: true,
2006 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002007 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002008 },
2009 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002010 name: "FailCertCallback-Client-TLS12",
2011 config: Config{
2012 MaxVersion: VersionTLS12,
2013 ClientAuth: RequestClientCert,
2014 },
2015 flags: []string{"-fail-cert-callback"},
2016 shouldFail: true,
2017 expectedError: ":CERT_CB_ERROR:",
2018 expectedLocalError: "remote error: internal error",
2019 },
2020 {
2021 testType: serverTest,
2022 name: "FailCertCallback-Server-TLS12",
2023 config: Config{
2024 MaxVersion: VersionTLS12,
2025 },
2026 flags: []string{"-fail-cert-callback"},
2027 shouldFail: true,
2028 expectedError: ":CERT_CB_ERROR:",
2029 expectedLocalError: "remote error: internal error",
2030 },
2031 {
2032 name: "FailCertCallback-Client-TLS13",
2033 config: Config{
2034 MaxVersion: VersionTLS13,
2035 ClientAuth: RequestClientCert,
2036 },
2037 flags: []string{"-fail-cert-callback"},
2038 shouldFail: true,
2039 expectedError: ":CERT_CB_ERROR:",
2040 expectedLocalError: "remote error: internal error",
2041 },
2042 {
2043 testType: serverTest,
2044 name: "FailCertCallback-Server-TLS13",
2045 config: Config{
2046 MaxVersion: VersionTLS13,
2047 },
2048 flags: []string{"-fail-cert-callback"},
2049 shouldFail: true,
2050 expectedError: ":CERT_CB_ERROR:",
2051 expectedLocalError: "remote error: internal error",
2052 },
2053 {
Adam Langley7c803a62015-06-15 15:35:05 -07002054 protocol: dtls,
2055 name: "FragmentMessageTypeMismatch-DTLS",
2056 config: Config{
2057 Bugs: ProtocolBugs{
2058 MaxHandshakeRecordLength: 2,
2059 FragmentMessageTypeMismatch: true,
2060 },
2061 },
2062 shouldFail: true,
2063 expectedError: ":FRAGMENT_MISMATCH:",
2064 },
2065 {
2066 protocol: dtls,
2067 name: "FragmentMessageLengthMismatch-DTLS",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 MaxHandshakeRecordLength: 2,
2071 FragmentMessageLengthMismatch: true,
2072 },
2073 },
2074 shouldFail: true,
2075 expectedError: ":FRAGMENT_MISMATCH:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "SplitFragments-Header-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SplitFragments: 2,
2083 },
2084 },
2085 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002086 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002087 },
2088 {
2089 protocol: dtls,
2090 name: "SplitFragments-Boundary-DTLS",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SplitFragments: dtlsRecordHeaderLen,
2094 },
2095 },
2096 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002097 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002098 },
2099 {
2100 protocol: dtls,
2101 name: "SplitFragments-Body-DTLS",
2102 config: Config{
2103 Bugs: ProtocolBugs{
2104 SplitFragments: dtlsRecordHeaderLen + 1,
2105 },
2106 },
2107 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002108 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002109 },
2110 {
2111 protocol: dtls,
2112 name: "SendEmptyFragments-DTLS",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendEmptyFragments: true,
2116 },
2117 },
2118 },
2119 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002120 name: "BadFinished-Client",
2121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002123 Bugs: ProtocolBugs{
2124 BadFinished: true,
2125 },
2126 },
2127 shouldFail: true,
2128 expectedError: ":DIGEST_CHECK_FAILED:",
2129 },
2130 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002131 name: "BadFinished-Client-TLS13",
2132 config: Config{
2133 MaxVersion: VersionTLS13,
2134 Bugs: ProtocolBugs{
2135 BadFinished: true,
2136 },
2137 },
2138 shouldFail: true,
2139 expectedError: ":DIGEST_CHECK_FAILED:",
2140 },
2141 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002142 testType: serverTest,
2143 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002145 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002146 Bugs: ProtocolBugs{
2147 BadFinished: true,
2148 },
2149 },
2150 shouldFail: true,
2151 expectedError: ":DIGEST_CHECK_FAILED:",
2152 },
2153 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002154 testType: serverTest,
2155 name: "BadFinished-Server-TLS13",
2156 config: Config{
2157 MaxVersion: VersionTLS13,
2158 Bugs: ProtocolBugs{
2159 BadFinished: true,
2160 },
2161 },
2162 shouldFail: true,
2163 expectedError: ":DIGEST_CHECK_FAILED:",
2164 },
2165 {
Adam Langley7c803a62015-06-15 15:35:05 -07002166 name: "FalseStart-BadFinished",
2167 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002168 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2170 NextProtos: []string{"foo"},
2171 Bugs: ProtocolBugs{
2172 BadFinished: true,
2173 ExpectFalseStart: true,
2174 },
2175 },
2176 flags: []string{
2177 "-false-start",
2178 "-handshake-never-done",
2179 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002180 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002181 },
2182 shimWritesFirst: true,
2183 shouldFail: true,
2184 expectedError: ":DIGEST_CHECK_FAILED:",
2185 },
2186 {
2187 name: "NoFalseStart-NoALPN",
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_GCM_SHA256},
2191 Bugs: ProtocolBugs{
2192 ExpectFalseStart: true,
2193 AlertBeforeFalseStartTest: alertAccessDenied,
2194 },
2195 },
2196 flags: []string{
2197 "-false-start",
2198 },
2199 shimWritesFirst: true,
2200 shouldFail: true,
2201 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2202 expectedLocalError: "tls: peer did not false start: EOF",
2203 },
2204 {
2205 name: "NoFalseStart-NoAEAD",
2206 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002207 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002208 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2209 NextProtos: []string{"foo"},
2210 Bugs: ProtocolBugs{
2211 ExpectFalseStart: true,
2212 AlertBeforeFalseStartTest: alertAccessDenied,
2213 },
2214 },
2215 flags: []string{
2216 "-false-start",
2217 "-advertise-alpn", "\x03foo",
2218 },
2219 shimWritesFirst: true,
2220 shouldFail: true,
2221 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2222 expectedLocalError: "tls: peer did not false start: EOF",
2223 },
2224 {
2225 name: "NoFalseStart-RSA",
2226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002227 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002228 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2229 NextProtos: []string{"foo"},
2230 Bugs: ProtocolBugs{
2231 ExpectFalseStart: true,
2232 AlertBeforeFalseStartTest: alertAccessDenied,
2233 },
2234 },
2235 flags: []string{
2236 "-false-start",
2237 "-advertise-alpn", "\x03foo",
2238 },
2239 shimWritesFirst: true,
2240 shouldFail: true,
2241 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2242 expectedLocalError: "tls: peer did not false start: EOF",
2243 },
2244 {
Adam Langley7c803a62015-06-15 15:35:05 -07002245 protocol: dtls,
2246 name: "SendSplitAlert-Sync",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendSplitAlert: true,
2250 },
2251 },
2252 },
2253 {
2254 protocol: dtls,
2255 name: "SendSplitAlert-Async",
2256 config: Config{
2257 Bugs: ProtocolBugs{
2258 SendSplitAlert: true,
2259 },
2260 },
2261 flags: []string{"-async"},
2262 },
2263 {
2264 protocol: dtls,
2265 name: "PackDTLSHandshake",
2266 config: Config{
2267 Bugs: ProtocolBugs{
2268 MaxHandshakeRecordLength: 2,
2269 PackHandshakeFragments: 20,
2270 PackHandshakeRecords: 200,
2271 },
2272 },
2273 },
2274 {
Adam Langley7c803a62015-06-15 15:35:05 -07002275 name: "SendEmptyRecords-Pass",
2276 sendEmptyRecords: 32,
2277 },
2278 {
2279 name: "SendEmptyRecords",
2280 sendEmptyRecords: 33,
2281 shouldFail: true,
2282 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2283 },
2284 {
2285 name: "SendEmptyRecords-Async",
2286 sendEmptyRecords: 33,
2287 flags: []string{"-async"},
2288 shouldFail: true,
2289 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2290 },
2291 {
David Benjamine8e84b92016-08-03 15:39:47 -04002292 name: "SendWarningAlerts-Pass",
2293 config: Config{
2294 MaxVersion: VersionTLS12,
2295 },
Adam Langley7c803a62015-06-15 15:35:05 -07002296 sendWarningAlerts: 4,
2297 },
2298 {
David Benjamine8e84b92016-08-03 15:39:47 -04002299 protocol: dtls,
2300 name: "SendWarningAlerts-DTLS-Pass",
2301 config: Config{
2302 MaxVersion: VersionTLS12,
2303 },
Adam Langley7c803a62015-06-15 15:35:05 -07002304 sendWarningAlerts: 4,
2305 },
2306 {
David Benjamine8e84b92016-08-03 15:39:47 -04002307 name: "SendWarningAlerts-TLS13",
2308 config: Config{
2309 MaxVersion: VersionTLS13,
2310 },
2311 sendWarningAlerts: 4,
2312 shouldFail: true,
2313 expectedError: ":BAD_ALERT:",
2314 expectedLocalError: "remote error: error decoding message",
2315 },
2316 {
2317 name: "SendWarningAlerts",
2318 config: Config{
2319 MaxVersion: VersionTLS12,
2320 },
Adam Langley7c803a62015-06-15 15:35:05 -07002321 sendWarningAlerts: 5,
2322 shouldFail: true,
2323 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2324 },
2325 {
David Benjamine8e84b92016-08-03 15:39:47 -04002326 name: "SendWarningAlerts-Async",
2327 config: Config{
2328 MaxVersion: VersionTLS12,
2329 },
Adam Langley7c803a62015-06-15 15:35:05 -07002330 sendWarningAlerts: 5,
2331 flags: []string{"-async"},
2332 shouldFail: true,
2333 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2334 },
David Benjaminba4594a2015-06-18 18:36:15 -04002335 {
David Benjamin24e58862017-06-14 18:45:29 -04002336 name: "SendBogusAlertType",
2337 sendBogusAlertType: true,
2338 shouldFail: true,
2339 expectedError: ":UNKNOWN_ALERT_TYPE:",
2340 expectedLocalError: "remote error: illegal parameter",
2341 },
2342 {
2343 protocol: dtls,
2344 name: "SendBogusAlertType-DTLS",
2345 sendBogusAlertType: true,
2346 shouldFail: true,
2347 expectedError: ":UNKNOWN_ALERT_TYPE:",
2348 expectedLocalError: "remote error: illegal parameter",
2349 },
2350 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002351 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002352 config: Config{
2353 MaxVersion: VersionTLS13,
2354 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002355 sendKeyUpdates: 33,
2356 keyUpdateRequest: keyUpdateNotRequested,
2357 shouldFail: true,
2358 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002359 },
2360 {
David Benjaminba4594a2015-06-18 18:36:15 -04002361 name: "EmptySessionID",
2362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002363 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002364 SessionTicketsDisabled: true,
2365 },
2366 noSessionCache: true,
2367 flags: []string{"-expect-no-session"},
2368 },
David Benjamin30789da2015-08-29 22:56:45 -04002369 {
2370 name: "Unclean-Shutdown",
2371 config: Config{
2372 Bugs: ProtocolBugs{
2373 NoCloseNotify: true,
2374 ExpectCloseNotify: true,
2375 },
2376 },
2377 shimShutsDown: true,
2378 flags: []string{"-check-close-notify"},
2379 shouldFail: true,
2380 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2381 },
2382 {
2383 name: "Unclean-Shutdown-Ignored",
2384 config: Config{
2385 Bugs: ProtocolBugs{
2386 NoCloseNotify: true,
2387 },
2388 },
2389 shimShutsDown: true,
2390 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002391 {
David Benjaminfa214e42016-05-10 17:03:10 -04002392 name: "Unclean-Shutdown-Alert",
2393 config: Config{
2394 Bugs: ProtocolBugs{
2395 SendAlertOnShutdown: alertDecompressionFailure,
2396 ExpectCloseNotify: true,
2397 },
2398 },
2399 shimShutsDown: true,
2400 flags: []string{"-check-close-notify"},
2401 shouldFail: true,
2402 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2403 },
2404 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002405 name: "LargePlaintext",
2406 config: Config{
2407 Bugs: ProtocolBugs{
2408 SendLargeRecords: true,
2409 },
2410 },
2411 messageLen: maxPlaintext + 1,
2412 shouldFail: true,
2413 expectedError: ":DATA_LENGTH_TOO_LONG:",
2414 },
2415 {
2416 protocol: dtls,
2417 name: "LargePlaintext-DTLS",
2418 config: Config{
2419 Bugs: ProtocolBugs{
2420 SendLargeRecords: true,
2421 },
2422 },
2423 messageLen: maxPlaintext + 1,
2424 shouldFail: true,
2425 expectedError: ":DATA_LENGTH_TOO_LONG:",
2426 },
2427 {
2428 name: "LargeCiphertext",
2429 config: Config{
2430 Bugs: ProtocolBugs{
2431 SendLargeRecords: true,
2432 },
2433 },
2434 messageLen: maxPlaintext * 2,
2435 shouldFail: true,
2436 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2437 },
2438 {
2439 protocol: dtls,
2440 name: "LargeCiphertext-DTLS",
2441 config: Config{
2442 Bugs: ProtocolBugs{
2443 SendLargeRecords: true,
2444 },
2445 },
2446 messageLen: maxPlaintext * 2,
2447 // Unlike the other four cases, DTLS drops records which
2448 // are invalid before authentication, so the connection
2449 // does not fail.
2450 expectMessageDropped: true,
2451 },
David Benjamindd6fed92015-10-23 17:41:12 -04002452 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002453 name: "BadHelloRequest-1",
2454 renegotiate: 1,
2455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002456 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002457 Bugs: ProtocolBugs{
2458 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2459 },
2460 },
2461 flags: []string{
2462 "-renegotiate-freely",
2463 "-expect-total-renegotiations", "1",
2464 },
2465 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002466 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002467 },
2468 {
2469 name: "BadHelloRequest-2",
2470 renegotiate: 1,
2471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002472 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002473 Bugs: ProtocolBugs{
2474 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2475 },
2476 },
2477 flags: []string{
2478 "-renegotiate-freely",
2479 "-expect-total-renegotiations", "1",
2480 },
2481 shouldFail: true,
2482 expectedError: ":BAD_HELLO_REQUEST:",
2483 },
David Benjaminef1b0092015-11-21 14:05:44 -05002484 {
2485 testType: serverTest,
2486 name: "SupportTicketsWithSessionID",
2487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002488 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002489 SessionTicketsDisabled: true,
2490 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002491 resumeConfig: &Config{
2492 MaxVersion: VersionTLS12,
2493 },
David Benjaminef1b0092015-11-21 14:05:44 -05002494 resumeSession: true,
2495 },
David Benjamin02edcd02016-07-27 17:40:37 -04002496 {
2497 protocol: dtls,
2498 name: "DTLS-SendExtraFinished",
2499 config: Config{
2500 Bugs: ProtocolBugs{
2501 SendExtraFinished: true,
2502 },
2503 },
2504 shouldFail: true,
2505 expectedError: ":UNEXPECTED_RECORD:",
2506 },
2507 {
2508 protocol: dtls,
2509 name: "DTLS-SendExtraFinished-Reordered",
2510 config: Config{
2511 Bugs: ProtocolBugs{
2512 MaxHandshakeRecordLength: 2,
2513 ReorderHandshakeFragments: true,
2514 SendExtraFinished: true,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNEXPECTED_RECORD:",
2519 },
David Benjamine97fb482016-07-29 09:23:07 -04002520 {
2521 testType: serverTest,
2522 name: "V2ClientHello-EmptyRecordPrefix",
2523 config: Config{
2524 // Choose a cipher suite that does not involve
2525 // elliptic curves, so no extensions are
2526 // involved.
2527 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002528 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002529 Bugs: ProtocolBugs{
2530 SendV2ClientHello: true,
2531 },
2532 },
2533 sendPrefix: string([]byte{
2534 byte(recordTypeHandshake),
2535 3, 1, // version
2536 0, 0, // length
2537 }),
2538 // A no-op empty record may not be sent before V2ClientHello.
2539 shouldFail: true,
2540 expectedError: ":WRONG_VERSION_NUMBER:",
2541 },
2542 {
2543 testType: serverTest,
2544 name: "V2ClientHello-WarningAlertPrefix",
2545 config: Config{
2546 // Choose a cipher suite that does not involve
2547 // elliptic curves, so no extensions are
2548 // involved.
2549 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002550 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002551 Bugs: ProtocolBugs{
2552 SendV2ClientHello: true,
2553 },
2554 },
2555 sendPrefix: string([]byte{
2556 byte(recordTypeAlert),
2557 3, 1, // version
2558 0, 2, // length
2559 alertLevelWarning, byte(alertDecompressionFailure),
2560 }),
2561 // A no-op warning alert may not be sent before V2ClientHello.
2562 shouldFail: true,
2563 expectedError: ":WRONG_VERSION_NUMBER:",
2564 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002565 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002566 name: "KeyUpdate-Client",
2567 config: Config{
2568 MaxVersion: VersionTLS13,
2569 },
2570 sendKeyUpdates: 1,
2571 keyUpdateRequest: keyUpdateNotRequested,
2572 },
2573 {
2574 testType: serverTest,
2575 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002576 config: Config{
2577 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002578 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002579 sendKeyUpdates: 1,
2580 keyUpdateRequest: keyUpdateNotRequested,
2581 },
2582 {
2583 name: "KeyUpdate-InvalidRequestMode",
2584 config: Config{
2585 MaxVersion: VersionTLS13,
2586 },
2587 sendKeyUpdates: 1,
2588 keyUpdateRequest: 42,
2589 shouldFail: true,
2590 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002591 },
David Benjaminabe94e32016-09-04 14:18:58 -04002592 {
David Benjaminbbba9392017-04-06 12:54:12 -04002593 // Test that KeyUpdates are acknowledged properly.
2594 name: "KeyUpdate-RequestACK",
2595 config: Config{
2596 MaxVersion: VersionTLS13,
2597 Bugs: ProtocolBugs{
2598 RejectUnsolicitedKeyUpdate: true,
2599 },
2600 },
2601 // Test the shim receiving many KeyUpdates in a row.
2602 sendKeyUpdates: 5,
2603 messageCount: 5,
2604 keyUpdateRequest: keyUpdateRequested,
2605 },
2606 {
2607 // Test that KeyUpdates are acknowledged properly if the
2608 // peer's KeyUpdate is discovered while a write is
2609 // pending.
2610 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2611 config: Config{
2612 MaxVersion: VersionTLS13,
2613 Bugs: ProtocolBugs{
2614 RejectUnsolicitedKeyUpdate: true,
2615 },
2616 },
2617 // Test the shim receiving many KeyUpdates in a row.
2618 sendKeyUpdates: 5,
2619 messageCount: 5,
2620 keyUpdateRequest: keyUpdateRequested,
2621 readWithUnfinishedWrite: true,
2622 flags: []string{"-async"},
2623 },
2624 {
David Benjaminabe94e32016-09-04 14:18:58 -04002625 name: "SendSNIWarningAlert",
2626 config: Config{
2627 MaxVersion: VersionTLS12,
2628 Bugs: ProtocolBugs{
2629 SendSNIWarningAlert: true,
2630 },
2631 },
2632 },
David Benjaminc241d792016-09-09 10:34:20 -04002633 {
2634 testType: serverTest,
2635 name: "ExtraCompressionMethods-TLS12",
2636 config: Config{
2637 MaxVersion: VersionTLS12,
2638 Bugs: ProtocolBugs{
2639 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2640 },
2641 },
2642 },
2643 {
2644 testType: serverTest,
2645 name: "ExtraCompressionMethods-TLS13",
2646 config: Config{
2647 MaxVersion: VersionTLS13,
2648 Bugs: ProtocolBugs{
2649 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2650 },
2651 },
2652 shouldFail: true,
2653 expectedError: ":INVALID_COMPRESSION_LIST:",
2654 expectedLocalError: "remote error: illegal parameter",
2655 },
2656 {
2657 testType: serverTest,
2658 name: "NoNullCompression-TLS12",
2659 config: Config{
2660 MaxVersion: VersionTLS12,
2661 Bugs: ProtocolBugs{
2662 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2663 },
2664 },
2665 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002666 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002667 expectedLocalError: "remote error: illegal parameter",
2668 },
2669 {
2670 testType: serverTest,
2671 name: "NoNullCompression-TLS13",
2672 config: Config{
2673 MaxVersion: VersionTLS13,
2674 Bugs: ProtocolBugs{
2675 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2676 },
2677 },
2678 shouldFail: true,
2679 expectedError: ":INVALID_COMPRESSION_LIST:",
2680 expectedLocalError: "remote error: illegal parameter",
2681 },
David Benjamin413e79e2017-07-01 10:11:53 -04002682 // Test that the client rejects invalid compression methods
2683 // from the server.
2684 {
2685 testType: clientTest,
2686 name: "InvalidCompressionMethod",
2687 config: Config{
2688 MaxVersion: VersionTLS12,
2689 Bugs: ProtocolBugs{
2690 SendCompressionMethod: 1,
2691 },
2692 },
2693 shouldFail: true,
2694 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2695 expectedLocalError: "remote error: illegal parameter",
2696 },
David Benjamin65ac9972016-09-02 21:35:25 -04002697 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002698 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002699 config: Config{
2700 MaxVersion: VersionTLS12,
2701 Bugs: ProtocolBugs{
2702 ExpectGREASE: true,
2703 },
2704 },
2705 flags: []string{"-enable-grease"},
2706 },
2707 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002708 name: "GREASE-Client-TLS13",
2709 config: Config{
2710 MaxVersion: VersionTLS13,
2711 Bugs: ProtocolBugs{
2712 ExpectGREASE: true,
2713 },
2714 },
2715 flags: []string{"-enable-grease"},
2716 },
2717 {
2718 testType: serverTest,
2719 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002720 config: Config{
2721 MaxVersion: VersionTLS13,
2722 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002723 // TLS 1.3 servers are expected to
2724 // always enable GREASE. TLS 1.3 is new,
2725 // so there is no existing ecosystem to
2726 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002727 ExpectGREASE: true,
2728 },
2729 },
David Benjamin65ac9972016-09-02 21:35:25 -04002730 },
David Benjamine3fbb362017-01-06 16:19:28 -05002731 {
2732 // Test the server so there is a large certificate as
2733 // well as application data.
2734 testType: serverTest,
2735 name: "MaxSendFragment",
2736 config: Config{
2737 Bugs: ProtocolBugs{
2738 MaxReceivePlaintext: 512,
2739 },
2740 },
2741 messageLen: 1024,
2742 flags: []string{
2743 "-max-send-fragment", "512",
2744 "-read-size", "1024",
2745 },
2746 },
2747 {
2748 // Test the server so there is a large certificate as
2749 // well as application data.
2750 testType: serverTest,
2751 name: "MaxSendFragment-TooLarge",
2752 config: Config{
2753 Bugs: ProtocolBugs{
2754 // Ensure that some of the records are
2755 // 512.
2756 MaxReceivePlaintext: 511,
2757 },
2758 },
2759 messageLen: 1024,
2760 flags: []string{
2761 "-max-send-fragment", "512",
2762 "-read-size", "1024",
2763 },
2764 shouldFail: true,
2765 expectedLocalError: "local error: record overflow",
2766 },
Adam Langley7c803a62015-06-15 15:35:05 -07002767 }
Adam Langley7c803a62015-06-15 15:35:05 -07002768 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002769
2770 // Test that very large messages can be received.
2771 cert := rsaCertificate
2772 for i := 0; i < 50; i++ {
2773 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2774 }
2775 testCases = append(testCases, testCase{
2776 name: "LargeMessage",
2777 config: Config{
2778 Certificates: []Certificate{cert},
2779 },
2780 })
2781 testCases = append(testCases, testCase{
2782 protocol: dtls,
2783 name: "LargeMessage-DTLS",
2784 config: Config{
2785 Certificates: []Certificate{cert},
2786 },
2787 })
2788
2789 // They are rejected if the maximum certificate chain length is capped.
2790 testCases = append(testCases, testCase{
2791 name: "LargeMessage-Reject",
2792 config: Config{
2793 Certificates: []Certificate{cert},
2794 },
2795 flags: []string{"-max-cert-list", "16384"},
2796 shouldFail: true,
2797 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2798 })
2799 testCases = append(testCases, testCase{
2800 protocol: dtls,
2801 name: "LargeMessage-Reject-DTLS",
2802 config: Config{
2803 Certificates: []Certificate{cert},
2804 },
2805 flags: []string{"-max-cert-list", "16384"},
2806 shouldFail: true,
2807 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2808 })
Adam Langley7c803a62015-06-15 15:35:05 -07002809}
2810
David Benjaminaa012042016-12-10 13:33:05 -05002811func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2812 const psk = "12345"
2813 const pskIdentity = "luggage combo"
2814
2815 var prefix string
2816 if protocol == dtls {
2817 if !ver.hasDTLS {
2818 return
2819 }
2820 prefix = "D"
2821 }
2822
2823 var cert Certificate
2824 var certFile string
2825 var keyFile string
2826 if hasComponent(suite.name, "ECDSA") {
2827 cert = ecdsaP256Certificate
2828 certFile = ecdsaP256CertificateFile
2829 keyFile = ecdsaP256KeyFile
2830 } else {
2831 cert = rsaCertificate
2832 certFile = rsaCertificateFile
2833 keyFile = rsaKeyFile
2834 }
2835
2836 var flags []string
2837 if hasComponent(suite.name, "PSK") {
2838 flags = append(flags,
2839 "-psk", psk,
2840 "-psk-identity", pskIdentity)
2841 }
2842 if hasComponent(suite.name, "NULL") {
2843 // NULL ciphers must be explicitly enabled.
2844 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2845 }
David Benjaminaa012042016-12-10 13:33:05 -05002846
2847 var shouldServerFail, shouldClientFail bool
2848 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2849 // BoringSSL clients accept ECDHE on SSLv3, but
2850 // a BoringSSL server will never select it
2851 // because the extension is missing.
2852 shouldServerFail = true
2853 }
2854 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2855 shouldClientFail = true
2856 shouldServerFail = true
2857 }
2858 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2859 shouldClientFail = true
2860 shouldServerFail = true
2861 }
2862 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2863 shouldClientFail = true
2864 shouldServerFail = true
2865 }
2866 if !isDTLSCipher(suite.name) && protocol == dtls {
2867 shouldClientFail = true
2868 shouldServerFail = true
2869 }
2870
2871 var sendCipherSuite uint16
2872 var expectedServerError, expectedClientError string
2873 serverCipherSuites := []uint16{suite.id}
2874 if shouldServerFail {
2875 expectedServerError = ":NO_SHARED_CIPHER:"
2876 }
2877 if shouldClientFail {
2878 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2879 // Configure the server to select ciphers as normal but
2880 // select an incompatible cipher in ServerHello.
2881 serverCipherSuites = nil
2882 sendCipherSuite = suite.id
2883 }
2884
David Benjamincdb6fe92017-02-07 16:06:48 -05002885 // For cipher suites and versions where exporters are defined, verify
2886 // that they interoperate.
2887 var exportKeyingMaterial int
2888 if ver.version > VersionSSL30 {
2889 exportKeyingMaterial = 1024
2890 }
2891
David Benjaminaa012042016-12-10 13:33:05 -05002892 testCases = append(testCases, testCase{
2893 testType: serverTest,
2894 protocol: protocol,
2895 name: prefix + ver.name + "-" + suite.name + "-server",
2896 config: Config{
2897 MinVersion: ver.version,
2898 MaxVersion: ver.version,
2899 CipherSuites: []uint16{suite.id},
2900 Certificates: []Certificate{cert},
2901 PreSharedKey: []byte(psk),
2902 PreSharedKeyIdentity: pskIdentity,
2903 Bugs: ProtocolBugs{
2904 AdvertiseAllConfiguredCiphers: true,
2905 },
2906 },
David Benjamina5022392017-07-10 17:40:39 -04002907 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002908 certFile: certFile,
2909 keyFile: keyFile,
2910 flags: flags,
2911 resumeSession: true,
2912 shouldFail: shouldServerFail,
2913 expectedError: expectedServerError,
2914 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002915 })
2916
2917 testCases = append(testCases, testCase{
2918 testType: clientTest,
2919 protocol: protocol,
2920 name: prefix + ver.name + "-" + suite.name + "-client",
2921 config: Config{
2922 MinVersion: ver.version,
2923 MaxVersion: ver.version,
2924 CipherSuites: serverCipherSuites,
2925 Certificates: []Certificate{cert},
2926 PreSharedKey: []byte(psk),
2927 PreSharedKeyIdentity: pskIdentity,
2928 Bugs: ProtocolBugs{
2929 IgnorePeerCipherPreferences: shouldClientFail,
2930 SendCipherSuite: sendCipherSuite,
2931 },
2932 },
David Benjamina5022392017-07-10 17:40:39 -04002933 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002934 flags: flags,
2935 resumeSession: true,
2936 shouldFail: shouldClientFail,
2937 expectedError: expectedClientError,
2938 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002939 })
2940
David Benjamin6f600d62016-12-21 16:06:54 -05002941 if shouldClientFail {
2942 return
2943 }
2944
2945 // Ensure the maximum record size is accepted.
2946 testCases = append(testCases, testCase{
2947 protocol: protocol,
2948 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2949 config: Config{
2950 MinVersion: ver.version,
2951 MaxVersion: ver.version,
2952 CipherSuites: []uint16{suite.id},
2953 Certificates: []Certificate{cert},
2954 PreSharedKey: []byte(psk),
2955 PreSharedKeyIdentity: pskIdentity,
2956 },
David Benjamina5022392017-07-10 17:40:39 -04002957 tls13Variant: ver.tls13Variant,
2958 flags: flags,
2959 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002960 })
2961
2962 // Test bad records for all ciphers. Bad records are fatal in TLS
2963 // and ignored in DTLS.
2964 var shouldFail bool
2965 var expectedError string
2966 if protocol == tls {
2967 shouldFail = true
2968 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2969 }
2970
2971 testCases = append(testCases, testCase{
2972 protocol: protocol,
2973 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2974 config: Config{
2975 MinVersion: ver.version,
2976 MaxVersion: ver.version,
2977 CipherSuites: []uint16{suite.id},
2978 Certificates: []Certificate{cert},
2979 PreSharedKey: []byte(psk),
2980 PreSharedKeyIdentity: pskIdentity,
2981 },
David Benjamina5022392017-07-10 17:40:39 -04002982 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002983 flags: flags,
2984 damageFirstWrite: true,
2985 messageLen: maxPlaintext,
2986 shouldFail: shouldFail,
2987 expectedError: expectedError,
2988 })
David Benjaminaa012042016-12-10 13:33:05 -05002989}
2990
Adam Langley95c29f32014-06-20 12:00:00 -07002991func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002992 const bogusCipher = 0xfe00
2993
Adam Langley95c29f32014-06-20 12:00:00 -07002994 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002995 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002996 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002997 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002998 }
David Benjamin2c99d282015-09-01 10:23:00 -04002999 }
Adam Langley95c29f32014-06-20 12:00:00 -07003000 }
Adam Langleya7997f12015-05-14 17:38:50 -07003001
3002 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003003 name: "NoSharedCipher",
3004 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003005 MaxVersion: VersionTLS12,
3006 CipherSuites: []uint16{},
3007 },
3008 shouldFail: true,
3009 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3010 })
3011
3012 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003013 name: "NoSharedCipher-TLS13",
3014 config: Config{
3015 MaxVersion: VersionTLS13,
3016 CipherSuites: []uint16{},
3017 },
3018 shouldFail: true,
3019 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3020 })
3021
3022 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003023 name: "UnsupportedCipherSuite",
3024 config: Config{
3025 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003026 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 Bugs: ProtocolBugs{
3028 IgnorePeerCipherPreferences: true,
3029 },
3030 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003031 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003032 shouldFail: true,
3033 expectedError: ":WRONG_CIPHER_RETURNED:",
3034 })
3035
3036 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003037 name: "ServerHelloBogusCipher",
3038 config: Config{
3039 MaxVersion: VersionTLS12,
3040 Bugs: ProtocolBugs{
3041 SendCipherSuite: bogusCipher,
3042 },
3043 },
3044 shouldFail: true,
3045 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3046 })
3047 testCases = append(testCases, testCase{
3048 name: "ServerHelloBogusCipher-TLS13",
3049 config: Config{
3050 MaxVersion: VersionTLS13,
3051 Bugs: ProtocolBugs{
3052 SendCipherSuite: bogusCipher,
3053 },
3054 },
3055 shouldFail: true,
3056 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3057 })
3058
David Benjamin241ae832016-01-15 03:04:54 -05003059 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003060 testCases = append(testCases, testCase{
3061 testType: serverTest,
3062 name: "UnknownCipher",
3063 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003064 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003065 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003066 Bugs: ProtocolBugs{
3067 AdvertiseAllConfiguredCiphers: true,
3068 },
3069 },
3070 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003071
3072 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003073 testCases = append(testCases, testCase{
3074 testType: serverTest,
3075 name: "UnknownCipher-TLS13",
3076 config: Config{
3077 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003078 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003079 Bugs: ProtocolBugs{
3080 AdvertiseAllConfiguredCiphers: true,
3081 },
David Benjamin241ae832016-01-15 03:04:54 -05003082 },
3083 })
3084
David Benjamin78679342016-09-16 19:42:05 -04003085 // Test empty ECDHE_PSK identity hints work as expected.
3086 testCases = append(testCases, testCase{
3087 name: "EmptyECDHEPSKHint",
3088 config: Config{
3089 MaxVersion: VersionTLS12,
3090 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3091 PreSharedKey: []byte("secret"),
3092 },
3093 flags: []string{"-psk", "secret"},
3094 })
3095
3096 // Test empty PSK identity hints work as expected, even if an explicit
3097 // ServerKeyExchange is sent.
3098 testCases = append(testCases, testCase{
3099 name: "ExplicitEmptyPSKHint",
3100 config: Config{
3101 MaxVersion: VersionTLS12,
3102 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3103 PreSharedKey: []byte("secret"),
3104 Bugs: ProtocolBugs{
3105 AlwaysSendPreSharedKeyIdentityHint: true,
3106 },
3107 },
3108 flags: []string{"-psk", "secret"},
3109 })
David Benjamin69522112017-03-28 15:38:29 -05003110
3111 // Test that clients enforce that the server-sent certificate and cipher
3112 // suite match in TLS 1.2.
3113 testCases = append(testCases, testCase{
3114 name: "CertificateCipherMismatch-RSA",
3115 config: Config{
3116 MaxVersion: VersionTLS12,
3117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3118 Certificates: []Certificate{rsaCertificate},
3119 Bugs: ProtocolBugs{
3120 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3121 },
3122 },
3123 shouldFail: true,
3124 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3125 })
3126 testCases = append(testCases, testCase{
3127 name: "CertificateCipherMismatch-ECDSA",
3128 config: Config{
3129 MaxVersion: VersionTLS12,
3130 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3131 Certificates: []Certificate{ecdsaP256Certificate},
3132 Bugs: ProtocolBugs{
3133 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3134 },
3135 },
3136 shouldFail: true,
3137 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3138 })
3139 testCases = append(testCases, testCase{
3140 name: "CertificateCipherMismatch-Ed25519",
3141 config: Config{
3142 MaxVersion: VersionTLS12,
3143 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3144 Certificates: []Certificate{ed25519Certificate},
3145 Bugs: ProtocolBugs{
3146 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 },
3149 shouldFail: true,
3150 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3151 })
3152
3153 // Test that servers decline to select a cipher suite which is
3154 // inconsistent with their configured certificate.
3155 testCases = append(testCases, testCase{
3156 testType: serverTest,
3157 name: "ServerCipherFilter-RSA",
3158 config: Config{
3159 MaxVersion: VersionTLS12,
3160 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3161 },
3162 flags: []string{
3163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3165 },
3166 shouldFail: true,
3167 expectedError: ":NO_SHARED_CIPHER:",
3168 })
3169 testCases = append(testCases, testCase{
3170 testType: serverTest,
3171 name: "ServerCipherFilter-ECDSA",
3172 config: Config{
3173 MaxVersion: VersionTLS12,
3174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3175 },
3176 flags: []string{
3177 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3178 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3179 },
3180 shouldFail: true,
3181 expectedError: ":NO_SHARED_CIPHER:",
3182 })
3183 testCases = append(testCases, testCase{
3184 testType: serverTest,
3185 name: "ServerCipherFilter-Ed25519",
3186 config: Config{
3187 MaxVersion: VersionTLS12,
3188 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3189 },
3190 flags: []string{
3191 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3192 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3193 },
3194 shouldFail: true,
3195 expectedError: ":NO_SHARED_CIPHER:",
3196 })
David Benjamin364af782017-07-01 10:35:27 -04003197
3198 // Test cipher suite negotiation works as expected. Configure a
3199 // complicated cipher suite configuration.
3200 const negotiationTestCiphers = "" +
3201 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3202 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3203 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3204 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3205 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3206 negotiationTests := []struct {
3207 ciphers []uint16
3208 expected uint16
3209 }{
3210 // Server preferences are honored, including when
3211 // equipreference groups are involved.
3212 {
3213 []uint16{
3214 TLS_RSA_WITH_AES_256_GCM_SHA384,
3215 TLS_RSA_WITH_AES_128_CBC_SHA,
3216 TLS_RSA_WITH_AES_128_GCM_SHA256,
3217 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3218 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3219 },
3220 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3221 },
3222 {
3223 []uint16{
3224 TLS_RSA_WITH_AES_256_GCM_SHA384,
3225 TLS_RSA_WITH_AES_128_CBC_SHA,
3226 TLS_RSA_WITH_AES_128_GCM_SHA256,
3227 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3228 },
3229 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3230 },
3231 {
3232 []uint16{
3233 TLS_RSA_WITH_AES_256_GCM_SHA384,
3234 TLS_RSA_WITH_AES_128_CBC_SHA,
3235 TLS_RSA_WITH_AES_128_GCM_SHA256,
3236 },
3237 TLS_RSA_WITH_AES_128_GCM_SHA256,
3238 },
3239 {
3240 []uint16{
3241 TLS_RSA_WITH_AES_256_GCM_SHA384,
3242 TLS_RSA_WITH_AES_128_CBC_SHA,
3243 },
3244 TLS_RSA_WITH_AES_128_CBC_SHA,
3245 },
3246 // Equipreference groups use the client preference.
3247 {
3248 []uint16{
3249 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3250 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3251 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3252 },
3253 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3254 },
3255 {
3256 []uint16{
3257 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3258 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3259 },
3260 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3261 },
3262 {
3263 []uint16{
3264 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3265 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3266 },
3267 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3268 },
3269 {
3270 []uint16{
3271 TLS_RSA_WITH_AES_256_GCM_SHA384,
3272 TLS_RSA_WITH_AES_256_CBC_SHA,
3273 },
3274 TLS_RSA_WITH_AES_256_GCM_SHA384,
3275 },
3276 {
3277 []uint16{
3278 TLS_RSA_WITH_AES_256_CBC_SHA,
3279 TLS_RSA_WITH_AES_256_GCM_SHA384,
3280 },
3281 TLS_RSA_WITH_AES_256_CBC_SHA,
3282 },
3283 // If there are two equipreference groups, the preferred one
3284 // takes precedence.
3285 {
3286 []uint16{
3287 TLS_RSA_WITH_AES_256_GCM_SHA384,
3288 TLS_RSA_WITH_AES_256_CBC_SHA,
3289 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3290 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3291 },
3292 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3293 },
3294 }
3295 for i, t := range negotiationTests {
3296 testCases = append(testCases, testCase{
3297 testType: serverTest,
3298 name: "CipherNegotiation-" + strconv.Itoa(i),
3299 config: Config{
3300 MaxVersion: VersionTLS12,
3301 CipherSuites: t.ciphers,
3302 },
3303 flags: []string{"-cipher", negotiationTestCiphers},
3304 expectedCipher: t.expected,
3305 })
3306 }
Adam Langley95c29f32014-06-20 12:00:00 -07003307}
3308
3309func addBadECDSASignatureTests() {
3310 for badR := BadValue(1); badR < NumBadValues; badR++ {
3311 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003312 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003313 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3314 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003315 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003316 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003317 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003318 Bugs: ProtocolBugs{
3319 BadECDSAR: badR,
3320 BadECDSAS: badS,
3321 },
3322 },
3323 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003324 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003325 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003326 testCases = append(testCases, testCase{
3327 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3328 config: Config{
3329 MaxVersion: VersionTLS13,
3330 Certificates: []Certificate{ecdsaP256Certificate},
3331 Bugs: ProtocolBugs{
3332 BadECDSAR: badR,
3333 BadECDSAS: badS,
3334 },
3335 },
3336 shouldFail: true,
3337 expectedError: ":BAD_SIGNATURE:",
3338 })
Adam Langley95c29f32014-06-20 12:00:00 -07003339 }
3340 }
3341}
3342
Adam Langley80842bd2014-06-20 12:00:00 -07003343func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003344 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003345 name: "MaxCBCPadding",
3346 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003347 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003348 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3349 Bugs: ProtocolBugs{
3350 MaxPadding: true,
3351 },
3352 },
3353 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3354 })
David Benjamin025b3d32014-07-01 19:53:04 -04003355 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003356 name: "BadCBCPadding",
3357 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003358 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003359 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3360 Bugs: ProtocolBugs{
3361 PaddingFirstByteBad: true,
3362 },
3363 },
3364 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003365 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003366 })
3367 // OpenSSL previously had an issue where the first byte of padding in
3368 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003369 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003370 name: "BadCBCPadding255",
3371 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003372 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3374 Bugs: ProtocolBugs{
3375 MaxPadding: true,
3376 PaddingFirstByteBadIf255: true,
3377 },
3378 },
3379 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3380 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003381 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003382 })
3383}
3384
Kenny Root7fdeaf12014-08-05 15:23:37 -07003385func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003386 var cbcCiphers = []struct {
3387 name string
3388 cipher uint16
3389 }{
3390 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3391 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3392 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3393 }
3394 for _, t := range cbcCiphers {
3395 testCases = append(testCases, testCase{
3396 name: "CBCRecordSplitting-" + 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 resumeSession: true,
3407 flags: []string{
3408 "-async",
3409 "-write-different-record-sizes",
3410 "-cbc-record-splitting",
3411 },
3412 })
3413 testCases = append(testCases, testCase{
3414 name: "CBCRecordSplittingPartialWrite-" + t.name,
3415 config: Config{
3416 MaxVersion: VersionTLS10,
3417 MinVersion: VersionTLS10,
3418 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003419 Bugs: ProtocolBugs{
3420 ExpectRecordSplitting: true,
3421 },
David Benjamina1ce8562017-07-01 11:46:57 -04003422 },
3423 messageLen: -1, // read until EOF
3424 flags: []string{
3425 "-async",
3426 "-write-different-record-sizes",
3427 "-cbc-record-splitting",
3428 "-partial-write",
3429 },
3430 })
3431 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003432}
3433
David Benjamin636293b2014-07-08 17:59:18 -04003434func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003435 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003436 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003437 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3438 cert, err := x509.ParseCertificate(cert.Certificate[0])
3439 if err != nil {
3440 panic(err)
3441 }
3442 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003443 }
Adam Langley2ff79332017-02-28 13:45:39 -08003444 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003445
David Benjamin636293b2014-07-08 17:59:18 -04003446 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003447 testCases = append(testCases, testCase{
3448 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003449 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003450 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003451 MinVersion: ver.version,
3452 MaxVersion: ver.version,
3453 ClientAuth: RequireAnyClientCert,
3454 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003455 },
David Benjamina5022392017-07-10 17:40:39 -04003456 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003457 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003458 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3459 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003460 },
3461 })
3462 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003463 testType: serverTest,
3464 name: ver.name + "-Server-ClientAuth-RSA",
3465 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003466 MinVersion: ver.version,
3467 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003468 Certificates: []Certificate{rsaCertificate},
3469 },
David Benjamina5022392017-07-10 17:40:39 -04003470 tls13Variant: ver.tls13Variant,
3471 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003472 })
David Benjamine098ec22014-08-27 23:13:20 -04003473 if ver.version != VersionSSL30 {
3474 testCases = append(testCases, testCase{
3475 testType: serverTest,
3476 name: ver.name + "-Server-ClientAuth-ECDSA",
3477 config: Config{
3478 MinVersion: ver.version,
3479 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003480 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003481 },
David Benjamina5022392017-07-10 17:40:39 -04003482 tls13Variant: ver.tls13Variant,
3483 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003484 })
3485 testCases = append(testCases, testCase{
3486 testType: clientTest,
3487 name: ver.name + "-Client-ClientAuth-ECDSA",
3488 config: Config{
3489 MinVersion: ver.version,
3490 MaxVersion: ver.version,
3491 ClientAuth: RequireAnyClientCert,
3492 ClientCAs: certPool,
3493 },
David Benjamina5022392017-07-10 17:40:39 -04003494 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003495 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003496 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3497 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003498 },
3499 })
3500 }
Adam Langley37646832016-08-01 16:16:46 -07003501
3502 testCases = append(testCases, testCase{
3503 name: "NoClientCertificate-" + ver.name,
3504 config: Config{
3505 MinVersion: ver.version,
3506 MaxVersion: ver.version,
3507 ClientAuth: RequireAnyClientCert,
3508 },
David Benjamina5022392017-07-10 17:40:39 -04003509 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003510 shouldFail: true,
3511 expectedLocalError: "client didn't provide a certificate",
3512 })
3513
3514 testCases = append(testCases, testCase{
3515 // Even if not configured to expect a certificate, OpenSSL will
3516 // return X509_V_OK as the verify_result.
3517 testType: serverTest,
3518 name: "NoClientCertificateRequested-Server-" + ver.name,
3519 config: Config{
3520 MinVersion: ver.version,
3521 MaxVersion: ver.version,
3522 },
David Benjamina5022392017-07-10 17:40:39 -04003523 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003524 flags: []string{
3525 "-expect-verify-result",
3526 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003527 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003528 })
3529
3530 testCases = append(testCases, testCase{
3531 // If a client certificate is not provided, OpenSSL will still
3532 // return X509_V_OK as the verify_result.
3533 testType: serverTest,
3534 name: "NoClientCertificate-Server-" + ver.name,
3535 config: Config{
3536 MinVersion: ver.version,
3537 MaxVersion: ver.version,
3538 },
David Benjamina5022392017-07-10 17:40:39 -04003539 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003540 flags: []string{
3541 "-expect-verify-result",
3542 "-verify-peer",
3543 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003544 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003545 })
3546
David Benjamin1db9e1b2016-10-07 20:51:43 -04003547 certificateRequired := "remote error: certificate required"
3548 if ver.version < VersionTLS13 {
3549 // Prior to TLS 1.3, the generic handshake_failure alert
3550 // was used.
3551 certificateRequired = "remote error: handshake failure"
3552 }
Adam Langley37646832016-08-01 16:16:46 -07003553 testCases = append(testCases, testCase{
3554 testType: serverTest,
3555 name: "RequireAnyClientCertificate-" + ver.name,
3556 config: Config{
3557 MinVersion: ver.version,
3558 MaxVersion: ver.version,
3559 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003560 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003561 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003562 shouldFail: true,
3563 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3564 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003565 })
3566
3567 if ver.version != VersionSSL30 {
3568 testCases = append(testCases, testCase{
3569 testType: serverTest,
3570 name: "SkipClientCertificate-" + ver.name,
3571 config: Config{
3572 MinVersion: ver.version,
3573 MaxVersion: ver.version,
3574 Bugs: ProtocolBugs{
3575 SkipClientCertificate: true,
3576 },
3577 },
3578 // Setting SSL_VERIFY_PEER allows anonymous clients.
3579 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003580 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003581 shouldFail: true,
3582 expectedError: ":UNEXPECTED_MESSAGE:",
3583 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003584
3585 testCases = append(testCases, testCase{
3586 testType: serverTest,
3587 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3588 config: Config{
3589 MinVersion: ver.version,
3590 MaxVersion: ver.version,
3591 },
3592 flags: []string{
3593 "-enable-channel-id",
3594 "-verify-peer-if-no-obc",
3595 },
David Benjamina5022392017-07-10 17:40:39 -04003596 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003597 shouldFail: true,
3598 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3599 expectedLocalError: certificateRequired,
3600 })
3601
3602 testCases = append(testCases, testCase{
3603 testType: serverTest,
3604 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3605 config: Config{
3606 MinVersion: ver.version,
3607 MaxVersion: ver.version,
3608 ChannelID: channelIDKey,
3609 },
3610 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003611 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003612 flags: []string{
3613 "-enable-channel-id",
3614 "-verify-peer-if-no-obc",
3615 },
3616 })
Adam Langley37646832016-08-01 16:16:46 -07003617 }
Adam Langley2ff79332017-02-28 13:45:39 -08003618
3619 testCases = append(testCases, testCase{
3620 testType: serverTest,
3621 name: ver.name + "-Server-CertReq-CA-List",
3622 config: Config{
3623 MinVersion: ver.version,
3624 MaxVersion: ver.version,
3625 Certificates: []Certificate{rsaCertificate},
3626 Bugs: ProtocolBugs{
3627 ExpectCertificateReqNames: caNames,
3628 },
3629 },
David Benjamina5022392017-07-10 17:40:39 -04003630 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003631 flags: []string{
3632 "-require-any-client-certificate",
3633 "-use-client-ca-list", encodeDERValues(caNames),
3634 },
3635 })
3636
3637 testCases = append(testCases, testCase{
3638 testType: clientTest,
3639 name: ver.name + "-Client-CertReq-CA-List",
3640 config: Config{
3641 MinVersion: ver.version,
3642 MaxVersion: ver.version,
3643 Certificates: []Certificate{rsaCertificate},
3644 ClientAuth: RequireAnyClientCert,
3645 ClientCAs: certPool,
3646 },
David Benjamina5022392017-07-10 17:40:39 -04003647 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003648 flags: []string{
3649 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3650 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3651 "-expect-client-ca-list", encodeDERValues(caNames),
3652 },
3653 })
David Benjamin636293b2014-07-08 17:59:18 -04003654 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003655
David Benjaminc032dfa2016-05-12 14:54:57 -04003656 // Client auth is only legal in certificate-based ciphers.
3657 testCases = append(testCases, testCase{
3658 testType: clientTest,
3659 name: "ClientAuth-PSK",
3660 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003661 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003662 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3663 PreSharedKey: []byte("secret"),
3664 ClientAuth: RequireAnyClientCert,
3665 },
3666 flags: []string{
3667 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3668 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3669 "-psk", "secret",
3670 },
3671 shouldFail: true,
3672 expectedError: ":UNEXPECTED_MESSAGE:",
3673 })
3674 testCases = append(testCases, testCase{
3675 testType: clientTest,
3676 name: "ClientAuth-ECDHE_PSK",
3677 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003678 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003679 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3680 PreSharedKey: []byte("secret"),
3681 ClientAuth: RequireAnyClientCert,
3682 },
3683 flags: []string{
3684 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3685 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3686 "-psk", "secret",
3687 },
3688 shouldFail: true,
3689 expectedError: ":UNEXPECTED_MESSAGE:",
3690 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003691
3692 // Regression test for a bug where the client CA list, if explicitly
3693 // set to NULL, was mis-encoded.
3694 testCases = append(testCases, testCase{
3695 testType: serverTest,
3696 name: "Null-Client-CA-List",
3697 config: Config{
3698 MaxVersion: VersionTLS12,
3699 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003700 Bugs: ProtocolBugs{
3701 ExpectCertificateReqNames: [][]byte{},
3702 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003703 },
3704 flags: []string{
3705 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003706 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003707 },
3708 })
David Benjamin636293b2014-07-08 17:59:18 -04003709}
3710
Adam Langley75712922014-10-10 16:23:43 -07003711func addExtendedMasterSecretTests() {
3712 const expectEMSFlag = "-expect-extended-master-secret"
3713
3714 for _, with := range []bool{false, true} {
3715 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003716 if with {
3717 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003718 }
3719
3720 for _, isClient := range []bool{false, true} {
3721 suffix := "-Server"
3722 testType := serverTest
3723 if isClient {
3724 suffix = "-Client"
3725 testType = clientTest
3726 }
3727
3728 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003729 // In TLS 1.3, the extension is irrelevant and
3730 // always reports as enabled.
3731 var flags []string
3732 if with || ver.version >= VersionTLS13 {
3733 flags = []string{expectEMSFlag}
3734 }
3735
Adam Langley75712922014-10-10 16:23:43 -07003736 test := testCase{
3737 testType: testType,
3738 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3739 config: Config{
3740 MinVersion: ver.version,
3741 MaxVersion: ver.version,
3742 Bugs: ProtocolBugs{
3743 NoExtendedMasterSecret: !with,
3744 RequireExtendedMasterSecret: with,
3745 },
3746 },
David Benjamina5022392017-07-10 17:40:39 -04003747 tls13Variant: ver.tls13Variant,
3748 flags: flags,
3749 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003750 }
3751 if test.shouldFail {
3752 test.expectedLocalError = "extended master secret required but not supported by peer"
3753 }
3754 testCases = append(testCases, test)
3755 }
3756 }
3757 }
3758
Adam Langleyba5934b2015-06-02 10:50:35 -07003759 for _, isClient := range []bool{false, true} {
3760 for _, supportedInFirstConnection := range []bool{false, true} {
3761 for _, supportedInResumeConnection := range []bool{false, true} {
3762 boolToWord := func(b bool) string {
3763 if b {
3764 return "Yes"
3765 }
3766 return "No"
3767 }
3768 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3769 if isClient {
3770 suffix += "Client"
3771 } else {
3772 suffix += "Server"
3773 }
3774
3775 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003776 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003777 Bugs: ProtocolBugs{
3778 RequireExtendedMasterSecret: true,
3779 },
3780 }
3781
3782 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003784 Bugs: ProtocolBugs{
3785 NoExtendedMasterSecret: true,
3786 },
3787 }
3788
3789 test := testCase{
3790 name: "ExtendedMasterSecret-" + suffix,
3791 resumeSession: true,
3792 }
3793
3794 if !isClient {
3795 test.testType = serverTest
3796 }
3797
3798 if supportedInFirstConnection {
3799 test.config = supportedConfig
3800 } else {
3801 test.config = noSupportConfig
3802 }
3803
3804 if supportedInResumeConnection {
3805 test.resumeConfig = &supportedConfig
3806 } else {
3807 test.resumeConfig = &noSupportConfig
3808 }
3809
3810 switch suffix {
3811 case "YesToYes-Client", "YesToYes-Server":
3812 // When a session is resumed, it should
3813 // still be aware that its master
3814 // secret was generated via EMS and
3815 // thus it's safe to use tls-unique.
3816 test.flags = []string{expectEMSFlag}
3817 case "NoToYes-Server":
3818 // If an original connection did not
3819 // contain EMS, but a resumption
3820 // handshake does, then a server should
3821 // not resume the session.
3822 test.expectResumeRejected = true
3823 case "YesToNo-Server":
3824 // Resuming an EMS session without the
3825 // EMS extension should cause the
3826 // server to abort the connection.
3827 test.shouldFail = true
3828 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3829 case "NoToYes-Client":
3830 // A client should abort a connection
3831 // where the server resumed a non-EMS
3832 // session but echoed the EMS
3833 // extension.
3834 test.shouldFail = true
3835 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3836 case "YesToNo-Client":
3837 // A client should abort a connection
3838 // where the server didn't echo EMS
3839 // when the session used it.
3840 test.shouldFail = true
3841 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3842 }
3843
3844 testCases = append(testCases, test)
3845 }
3846 }
3847 }
David Benjamin163c9562016-08-29 23:14:17 -04003848
3849 // Switching EMS on renegotiation is forbidden.
3850 testCases = append(testCases, testCase{
3851 name: "ExtendedMasterSecret-Renego-NoEMS",
3852 config: Config{
3853 MaxVersion: VersionTLS12,
3854 Bugs: ProtocolBugs{
3855 NoExtendedMasterSecret: true,
3856 NoExtendedMasterSecretOnRenegotiation: true,
3857 },
3858 },
3859 renegotiate: 1,
3860 flags: []string{
3861 "-renegotiate-freely",
3862 "-expect-total-renegotiations", "1",
3863 },
3864 })
3865
3866 testCases = append(testCases, testCase{
3867 name: "ExtendedMasterSecret-Renego-Upgrade",
3868 config: Config{
3869 MaxVersion: VersionTLS12,
3870 Bugs: ProtocolBugs{
3871 NoExtendedMasterSecret: true,
3872 },
3873 },
3874 renegotiate: 1,
3875 flags: []string{
3876 "-renegotiate-freely",
3877 "-expect-total-renegotiations", "1",
3878 },
3879 shouldFail: true,
3880 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3881 })
3882
3883 testCases = append(testCases, testCase{
3884 name: "ExtendedMasterSecret-Renego-Downgrade",
3885 config: Config{
3886 MaxVersion: VersionTLS12,
3887 Bugs: ProtocolBugs{
3888 NoExtendedMasterSecretOnRenegotiation: true,
3889 },
3890 },
3891 renegotiate: 1,
3892 flags: []string{
3893 "-renegotiate-freely",
3894 "-expect-total-renegotiations", "1",
3895 },
3896 shouldFail: true,
3897 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3898 })
Adam Langley75712922014-10-10 16:23:43 -07003899}
3900
David Benjamin582ba042016-07-07 12:33:25 -07003901type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003902 protocol protocol
3903 async bool
3904 splitHandshake bool
3905 packHandshakeFlight bool
3906 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003907}
3908
David Benjamin43ec06f2014-08-05 02:28:57 -04003909// Adds tests that try to cover the range of the handshake state machine, under
3910// various conditions. Some of these are redundant with other tests, but they
3911// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003912func addAllStateMachineCoverageTests() {
3913 for _, async := range []bool{false, true} {
3914 for _, protocol := range []protocol{tls, dtls} {
3915 addStateMachineCoverageTests(stateMachineTestConfig{
3916 protocol: protocol,
3917 async: async,
3918 })
3919 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003920 protocol: protocol,
3921 async: async,
3922 implicitHandshake: true,
3923 })
3924 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003925 protocol: protocol,
3926 async: async,
3927 splitHandshake: true,
3928 })
3929 if protocol == tls {
3930 addStateMachineCoverageTests(stateMachineTestConfig{
3931 protocol: protocol,
3932 async: async,
3933 packHandshakeFlight: true,
3934 })
3935 }
3936 }
3937 }
3938}
3939
3940func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003941 var tests []testCase
3942
3943 // Basic handshake, with resumption. Client and server,
3944 // session ID and session ticket.
3945 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 name: "Basic-Client",
3947 config: Config{
3948 MaxVersion: VersionTLS12,
3949 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003951 // Ensure session tickets are used, not session IDs.
3952 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 })
3954 tests = append(tests, testCase{
3955 name: "Basic-Client-RenewTicket",
3956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003957 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003958 Bugs: ProtocolBugs{
3959 RenewTicketOnResume: true,
3960 },
3961 },
David Benjamin46662482016-08-17 00:51:00 -04003962 flags: []string{"-expect-ticket-renewal"},
3963 resumeSession: true,
3964 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003965 })
3966 tests = append(tests, testCase{
3967 name: "Basic-Client-NoTicket",
3968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 SessionTicketsDisabled: true,
3971 },
3972 resumeSession: true,
3973 })
3974 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003975 testType: serverTest,
3976 name: "Basic-Server",
3977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003978 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003979 Bugs: ProtocolBugs{
3980 RequireSessionTickets: true,
3981 },
3982 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003983 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003984 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003985 })
3986 tests = append(tests, testCase{
3987 testType: serverTest,
3988 name: "Basic-Server-NoTickets",
3989 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003990 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003991 SessionTicketsDisabled: true,
3992 },
3993 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003994 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003995 })
3996 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003997 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003998 name: "Basic-Server-EarlyCallback",
3999 config: Config{
4000 MaxVersion: VersionTLS12,
4001 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004002 flags: []string{"-use-early-callback"},
4003 resumeSession: true,
4004 })
4005
Steven Valdez143e8b32016-07-11 13:19:03 -04004006 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004007 if config.protocol == tls {
4008 tests = append(tests, testCase{
4009 name: "TLS13-1RTT-Client",
4010 config: Config{
4011 MaxVersion: VersionTLS13,
4012 MinVersion: VersionTLS13,
4013 },
David Benjamin46662482016-08-17 00:51:00 -04004014 resumeSession: true,
4015 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004016 })
4017
4018 tests = append(tests, testCase{
4019 testType: serverTest,
4020 name: "TLS13-1RTT-Server",
4021 config: Config{
4022 MaxVersion: VersionTLS13,
4023 MinVersion: VersionTLS13,
4024 },
David Benjamin46662482016-08-17 00:51:00 -04004025 resumeSession: true,
4026 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004027 // TLS 1.3 uses tickets, so the session should not be
4028 // cached statefully.
4029 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004030 })
4031
4032 tests = append(tests, testCase{
4033 name: "TLS13-HelloRetryRequest-Client",
4034 config: Config{
4035 MaxVersion: VersionTLS13,
4036 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004037 // P-384 requires a HelloRetryRequest against BoringSSL's default
4038 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004039 CurvePreferences: []CurveID{CurveP384},
4040 Bugs: ProtocolBugs{
4041 ExpectMissingKeyShare: true,
4042 },
4043 },
4044 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4045 resumeSession: true,
4046 })
4047
4048 tests = append(tests, testCase{
4049 testType: serverTest,
4050 name: "TLS13-HelloRetryRequest-Server",
4051 config: Config{
4052 MaxVersion: VersionTLS13,
4053 MinVersion: VersionTLS13,
4054 // Require a HelloRetryRequest for every curve.
4055 DefaultCurves: []CurveID{},
4056 },
4057 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4058 resumeSession: true,
4059 })
Steven Valdez2d850622017-01-11 11:34:52 -05004060
Steven Valdez2d850622017-01-11 11:34:52 -05004061 tests = append(tests, testCase{
4062 testType: clientTest,
4063 name: "TLS13-EarlyData-Client",
4064 config: Config{
4065 MaxVersion: VersionTLS13,
4066 MinVersion: VersionTLS13,
4067 MaxEarlyDataSize: 16384,
4068 },
Steven Valdeze831a812017-03-09 14:56:07 -05004069 resumeConfig: &Config{
4070 MaxVersion: VersionTLS13,
4071 MinVersion: VersionTLS13,
4072 MaxEarlyDataSize: 16384,
4073 Bugs: ProtocolBugs{
4074 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4075 },
4076 },
Steven Valdez2d850622017-01-11 11:34:52 -05004077 resumeSession: true,
4078 flags: []string{
4079 "-enable-early-data",
4080 "-expect-early-data-info",
4081 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004082 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004083 },
4084 })
4085
4086 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004087 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004088 name: "TLS13Experiment-EarlyData-Client",
4089 config: Config{
4090 MaxVersion: VersionTLS13,
4091 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004092 MaxEarlyDataSize: 16384,
4093 },
4094 resumeConfig: &Config{
4095 MaxVersion: VersionTLS13,
4096 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004097 MaxEarlyDataSize: 16384,
4098 Bugs: ProtocolBugs{
4099 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4100 },
4101 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004102 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004103 resumeSession: true,
4104 flags: []string{
4105 "-enable-early-data",
4106 "-expect-early-data-info",
4107 "-expect-accept-early-data",
4108 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004109 },
4110 })
4111
4112 tests = append(tests, testCase{
4113 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004114 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4115 config: Config{
4116 MaxVersion: VersionTLS13,
4117 MinVersion: VersionTLS13,
4118 TLS13Variant: TLS13RecordTypeExperiment,
4119 MaxEarlyDataSize: 16384,
4120 },
4121 resumeConfig: &Config{
4122 MaxVersion: VersionTLS13,
4123 MinVersion: VersionTLS13,
4124 TLS13Variant: TLS13RecordTypeExperiment,
4125 MaxEarlyDataSize: 16384,
4126 Bugs: ProtocolBugs{
4127 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4128 },
4129 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004130 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004131 resumeSession: true,
4132 flags: []string{
4133 "-enable-early-data",
4134 "-expect-early-data-info",
4135 "-expect-accept-early-data",
4136 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004137 },
4138 })
4139
4140 tests = append(tests, testCase{
4141 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004142 name: "TLS13-EarlyData-TooMuchData-Client",
4143 config: Config{
4144 MaxVersion: VersionTLS13,
4145 MinVersion: VersionTLS13,
4146 MaxEarlyDataSize: 2,
4147 },
4148 resumeConfig: &Config{
4149 MaxVersion: VersionTLS13,
4150 MinVersion: VersionTLS13,
4151 MaxEarlyDataSize: 2,
4152 Bugs: ProtocolBugs{
4153 ExpectEarlyData: [][]byte{{'h', 'e'}},
4154 },
4155 },
4156 resumeShimPrefix: "llo",
4157 resumeSession: true,
4158 flags: []string{
4159 "-enable-early-data",
4160 "-expect-early-data-info",
4161 "-expect-accept-early-data",
4162 "-on-resume-shim-writes-first",
4163 },
4164 })
4165
4166 // Unfinished writes can only be tested when operations are async. EarlyData
4167 // can't be tested as part of an ImplicitHandshake in this case since
4168 // otherwise the early data will be sent as normal data.
4169 if config.async && !config.implicitHandshake {
4170 tests = append(tests, testCase{
4171 testType: clientTest,
4172 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4173 config: Config{
4174 MaxVersion: VersionTLS13,
4175 MinVersion: VersionTLS13,
4176 MaxEarlyDataSize: 16384,
4177 },
4178 resumeConfig: &Config{
4179 MaxVersion: VersionTLS13,
4180 MinVersion: VersionTLS13,
4181 MaxEarlyDataSize: 16384,
4182 Bugs: ProtocolBugs{
4183 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4184 },
4185 },
4186 resumeSession: true,
4187 flags: []string{
4188 "-enable-early-data",
4189 "-expect-early-data-info",
4190 "-expect-accept-early-data",
4191 "-on-resume-read-with-unfinished-write",
4192 "-on-resume-shim-writes-first",
4193 },
4194 })
4195
4196 // Rejected unfinished writes are discarded (from the
4197 // perspective of the calling application) on 0-RTT
4198 // reject.
4199 tests = append(tests, testCase{
4200 testType: clientTest,
4201 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4202 config: Config{
4203 MaxVersion: VersionTLS13,
4204 MinVersion: VersionTLS13,
4205 MaxEarlyDataSize: 16384,
4206 },
4207 resumeConfig: &Config{
4208 MaxVersion: VersionTLS13,
4209 MinVersion: VersionTLS13,
4210 MaxEarlyDataSize: 16384,
4211 Bugs: ProtocolBugs{
4212 AlwaysRejectEarlyData: true,
4213 },
4214 },
4215 resumeSession: true,
4216 flags: []string{
4217 "-enable-early-data",
4218 "-expect-early-data-info",
4219 "-expect-reject-early-data",
4220 "-on-resume-read-with-unfinished-write",
4221 "-on-resume-shim-writes-first",
4222 },
4223 })
4224 }
4225
4226 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004227 testType: serverTest,
4228 name: "TLS13-EarlyData-Server",
4229 config: Config{
4230 MaxVersion: VersionTLS13,
4231 MinVersion: VersionTLS13,
4232 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004233 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004234 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004235 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004236 },
4237 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004238 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004239 resumeSession: true,
4240 flags: []string{
4241 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004242 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004243 },
4244 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004245
4246 tests = append(tests, testCase{
4247 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004248 name: "TLS13Experiment-EarlyData-Server",
4249 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004250 MaxVersion: VersionTLS13,
4251 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004252 Bugs: ProtocolBugs{
4253 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4254 ExpectEarlyDataAccepted: true,
4255 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4256 },
4257 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004258 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004259 messageCount: 2,
4260 resumeSession: true,
4261 flags: []string{
4262 "-enable-early-data",
4263 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004264 },
4265 })
4266
4267 tests = append(tests, testCase{
4268 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004269 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4270 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004271 MaxVersion: VersionTLS13,
4272 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004273 Bugs: ProtocolBugs{
4274 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4275 ExpectEarlyDataAccepted: true,
4276 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4277 },
4278 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004279 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004280 messageCount: 2,
4281 resumeSession: true,
4282 flags: []string{
4283 "-enable-early-data",
4284 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004285 },
4286 })
4287
4288 tests = append(tests, testCase{
4289 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004290 name: "TLS13-MaxEarlyData-Server",
4291 config: Config{
4292 MaxVersion: VersionTLS13,
4293 MinVersion: VersionTLS13,
4294 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004295 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004296 ExpectEarlyDataAccepted: true,
4297 },
4298 },
4299 messageCount: 2,
4300 resumeSession: true,
4301 flags: []string{
4302 "-enable-early-data",
4303 "-expect-accept-early-data",
4304 },
4305 shouldFail: true,
4306 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4307 })
David Benjamine73c7f42016-08-17 00:29:33 -04004308 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004309
David Benjamin760b1dd2015-05-15 23:33:48 -04004310 // TLS client auth.
4311 tests = append(tests, testCase{
4312 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004313 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004315 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004316 ClientAuth: RequestClientCert,
4317 },
4318 })
4319 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004320 testType: serverTest,
4321 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 config: Config{
4323 MaxVersion: VersionTLS12,
4324 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004325 // Setting SSL_VERIFY_PEER allows anonymous clients.
4326 flags: []string{"-verify-peer"},
4327 })
David Benjamin582ba042016-07-07 12:33:25 -07004328 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004329 tests = append(tests, testCase{
4330 testType: clientTest,
4331 name: "ClientAuth-NoCertificate-Client-SSL3",
4332 config: Config{
4333 MaxVersion: VersionSSL30,
4334 ClientAuth: RequestClientCert,
4335 },
4336 })
4337 tests = append(tests, testCase{
4338 testType: serverTest,
4339 name: "ClientAuth-NoCertificate-Server-SSL3",
4340 config: Config{
4341 MaxVersion: VersionSSL30,
4342 },
4343 // Setting SSL_VERIFY_PEER allows anonymous clients.
4344 flags: []string{"-verify-peer"},
4345 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004346 tests = append(tests, testCase{
4347 testType: clientTest,
4348 name: "ClientAuth-NoCertificate-Client-TLS13",
4349 config: Config{
4350 MaxVersion: VersionTLS13,
4351 ClientAuth: RequestClientCert,
4352 },
4353 })
4354 tests = append(tests, testCase{
4355 testType: serverTest,
4356 name: "ClientAuth-NoCertificate-Server-TLS13",
4357 config: Config{
4358 MaxVersion: VersionTLS13,
4359 },
4360 // Setting SSL_VERIFY_PEER allows anonymous clients.
4361 flags: []string{"-verify-peer"},
4362 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004363 }
4364 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004365 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004366 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004368 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004369 ClientAuth: RequireAnyClientCert,
4370 },
4371 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004372 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4373 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004374 },
4375 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004376 tests = append(tests, testCase{
4377 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004378 name: "ClientAuth-RSA-Client-TLS13",
4379 config: Config{
4380 MaxVersion: VersionTLS13,
4381 ClientAuth: RequireAnyClientCert,
4382 },
4383 flags: []string{
4384 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4385 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4386 },
4387 })
4388 tests = append(tests, testCase{
4389 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004390 name: "ClientAuth-ECDSA-Client",
4391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004392 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004393 ClientAuth: RequireAnyClientCert,
4394 },
4395 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004396 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4397 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004398 },
4399 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004400 tests = append(tests, testCase{
4401 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004402 name: "ClientAuth-ECDSA-Client-TLS13",
4403 config: Config{
4404 MaxVersion: VersionTLS13,
4405 ClientAuth: RequireAnyClientCert,
4406 },
4407 flags: []string{
4408 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4409 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4410 },
4411 })
4412 tests = append(tests, testCase{
4413 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004414 name: "ClientAuth-NoCertificate-OldCallback",
4415 config: Config{
4416 MaxVersion: VersionTLS12,
4417 ClientAuth: RequestClientCert,
4418 },
4419 flags: []string{"-use-old-client-cert-callback"},
4420 })
4421 tests = append(tests, testCase{
4422 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004423 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4424 config: Config{
4425 MaxVersion: VersionTLS13,
4426 ClientAuth: RequestClientCert,
4427 },
4428 flags: []string{"-use-old-client-cert-callback"},
4429 })
4430 tests = append(tests, testCase{
4431 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004432 name: "ClientAuth-OldCallback",
4433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004434 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004435 ClientAuth: RequireAnyClientCert,
4436 },
4437 flags: []string{
4438 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4439 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4440 "-use-old-client-cert-callback",
4441 },
4442 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004443 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004444 testType: clientTest,
4445 name: "ClientAuth-OldCallback-TLS13",
4446 config: Config{
4447 MaxVersion: VersionTLS13,
4448 ClientAuth: RequireAnyClientCert,
4449 },
4450 flags: []string{
4451 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4452 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4453 "-use-old-client-cert-callback",
4454 },
4455 })
4456 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004457 testType: serverTest,
4458 name: "ClientAuth-Server",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 Certificates: []Certificate{rsaCertificate},
4462 },
4463 flags: []string{"-require-any-client-certificate"},
4464 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004465 tests = append(tests, testCase{
4466 testType: serverTest,
4467 name: "ClientAuth-Server-TLS13",
4468 config: Config{
4469 MaxVersion: VersionTLS13,
4470 Certificates: []Certificate{rsaCertificate},
4471 },
4472 flags: []string{"-require-any-client-certificate"},
4473 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004474
David Benjamin4c3ddf72016-06-29 18:13:53 -04004475 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004476 tests = append(tests, testCase{
4477 testType: serverTest,
4478 name: "Basic-Server-RSA",
4479 config: Config{
4480 MaxVersion: VersionTLS12,
4481 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4482 },
4483 flags: []string{
4484 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4485 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4486 },
4487 })
4488 tests = append(tests, testCase{
4489 testType: serverTest,
4490 name: "Basic-Server-ECDHE-RSA",
4491 config: Config{
4492 MaxVersion: VersionTLS12,
4493 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4494 },
4495 flags: []string{
4496 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4497 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4498 },
4499 })
4500 tests = append(tests, testCase{
4501 testType: serverTest,
4502 name: "Basic-Server-ECDHE-ECDSA",
4503 config: Config{
4504 MaxVersion: VersionTLS12,
4505 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4506 },
4507 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004508 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4509 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004510 },
4511 })
David Benjamin69522112017-03-28 15:38:29 -05004512 tests = append(tests, testCase{
4513 testType: serverTest,
4514 name: "Basic-Server-Ed25519",
4515 config: Config{
4516 MaxVersion: VersionTLS12,
4517 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4518 },
4519 flags: []string{
4520 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4521 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4522 "-enable-ed25519",
4523 },
4524 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004525
David Benjamin760b1dd2015-05-15 23:33:48 -04004526 // No session ticket support; server doesn't send NewSessionTicket.
4527 tests = append(tests, testCase{
4528 name: "SessionTicketsDisabled-Client",
4529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004530 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004531 SessionTicketsDisabled: true,
4532 },
4533 })
4534 tests = append(tests, testCase{
4535 testType: serverTest,
4536 name: "SessionTicketsDisabled-Server",
4537 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004538 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004539 SessionTicketsDisabled: true,
4540 },
4541 })
4542
4543 // Skip ServerKeyExchange in PSK key exchange if there's no
4544 // identity hint.
4545 tests = append(tests, testCase{
4546 name: "EmptyPSKHint-Client",
4547 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004548 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004549 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4550 PreSharedKey: []byte("secret"),
4551 },
4552 flags: []string{"-psk", "secret"},
4553 })
4554 tests = append(tests, testCase{
4555 testType: serverTest,
4556 name: "EmptyPSKHint-Server",
4557 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004558 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004559 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4560 PreSharedKey: []byte("secret"),
4561 },
4562 flags: []string{"-psk", "secret"},
4563 })
4564
David Benjamin4c3ddf72016-06-29 18:13:53 -04004565 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004566 tests = append(tests, testCase{
4567 testType: clientTest,
4568 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004569 config: Config{
4570 MaxVersion: VersionTLS12,
4571 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004572 flags: []string{
4573 "-enable-ocsp-stapling",
4574 "-expect-ocsp-response",
4575 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004576 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004577 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004578 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004579 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004580 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004581 testType: serverTest,
4582 name: "OCSPStapling-Server",
4583 config: Config{
4584 MaxVersion: VersionTLS12,
4585 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004586 expectedOCSPResponse: testOCSPResponse,
4587 flags: []string{
4588 "-ocsp-response",
4589 base64.StdEncoding.EncodeToString(testOCSPResponse),
4590 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004591 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004592 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004593 tests = append(tests, testCase{
4594 testType: clientTest,
4595 name: "OCSPStapling-Client-TLS13",
4596 config: Config{
4597 MaxVersion: VersionTLS13,
4598 },
4599 flags: []string{
4600 "-enable-ocsp-stapling",
4601 "-expect-ocsp-response",
4602 base64.StdEncoding.EncodeToString(testOCSPResponse),
4603 "-verify-peer",
4604 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004605 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004606 })
4607 tests = append(tests, testCase{
4608 testType: serverTest,
4609 name: "OCSPStapling-Server-TLS13",
4610 config: Config{
4611 MaxVersion: VersionTLS13,
4612 },
4613 expectedOCSPResponse: testOCSPResponse,
4614 flags: []string{
4615 "-ocsp-response",
4616 base64.StdEncoding.EncodeToString(testOCSPResponse),
4617 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004618 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004619 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004620
David Benjamin4c3ddf72016-06-29 18:13:53 -04004621 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004622 for _, vers := range tlsVersions {
4623 if config.protocol == dtls && !vers.hasDTLS {
4624 continue
4625 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004626 for _, useCustomCallback := range []bool{false, true} {
4627 for _, testType := range []testType{clientTest, serverTest} {
4628 suffix := "-Client"
4629 if testType == serverTest {
4630 suffix = "-Server"
4631 }
4632 suffix += "-" + vers.name
4633 if useCustomCallback {
4634 suffix += "-CustomCallback"
4635 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004636
David Benjamin3a1dd462017-07-11 16:13:10 -04004637 flags := []string{"-verify-peer"}
4638 if testType == serverTest {
4639 flags = append(flags, "-require-any-client-certificate")
4640 }
4641 if useCustomCallback {
4642 flags = append(flags, "-use-custom-verify-callback")
4643 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004644
David Benjamin3a1dd462017-07-11 16:13:10 -04004645 tests = append(tests, testCase{
4646 testType: testType,
4647 name: "CertificateVerificationSucceed" + suffix,
4648 config: Config{
4649 MaxVersion: vers.version,
4650 Certificates: []Certificate{rsaCertificate},
4651 },
4652 tls13Variant: vers.tls13Variant,
4653 flags: append([]string{"-expect-verify-result"}, flags...),
4654 resumeSession: true,
4655 })
4656 tests = append(tests, testCase{
4657 testType: testType,
4658 name: "CertificateVerificationFail" + suffix,
4659 config: Config{
4660 MaxVersion: vers.version,
4661 Certificates: []Certificate{rsaCertificate},
4662 },
4663 tls13Variant: vers.tls13Variant,
4664 flags: append([]string{"-verify-fail"}, flags...),
4665 shouldFail: true,
4666 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4667 })
4668 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004669 }
4670
4671 // By default, the client is in a soft fail mode where the peer
4672 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004673 tests = append(tests, testCase{
4674 testType: clientTest,
4675 name: "CertificateVerificationSoftFail-" + vers.name,
4676 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004677 MaxVersion: vers.version,
4678 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004679 },
David Benjamina5022392017-07-10 17:40:39 -04004680 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004681 flags: []string{
4682 "-verify-fail",
4683 "-expect-verify-result",
4684 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004685 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004686 })
4687 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004688
David Benjamin1d4f4c02016-07-26 18:03:08 -04004689 tests = append(tests, testCase{
4690 name: "ShimSendAlert",
4691 flags: []string{"-send-alert"},
4692 shimWritesFirst: true,
4693 shouldFail: true,
4694 expectedLocalError: "remote error: decompression failure",
4695 })
4696
David Benjamin582ba042016-07-07 12:33:25 -07004697 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004698 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004699 name: "Renegotiate-Client",
4700 config: Config{
4701 MaxVersion: VersionTLS12,
4702 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004703 renegotiate: 1,
4704 flags: []string{
4705 "-renegotiate-freely",
4706 "-expect-total-renegotiations", "1",
4707 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004709
David Benjamin47921102016-07-28 11:29:18 -04004710 tests = append(tests, testCase{
4711 name: "SendHalfHelloRequest",
4712 config: Config{
4713 MaxVersion: VersionTLS12,
4714 Bugs: ProtocolBugs{
4715 PackHelloRequestWithFinished: config.packHandshakeFlight,
4716 },
4717 },
4718 sendHalfHelloRequest: true,
4719 flags: []string{"-renegotiate-ignore"},
4720 shouldFail: true,
4721 expectedError: ":UNEXPECTED_RECORD:",
4722 })
4723
David Benjamin760b1dd2015-05-15 23:33:48 -04004724 // NPN on client and server; results in post-handshake message.
4725 tests = append(tests, testCase{
4726 name: "NPN-Client",
4727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004728 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004729 NextProtos: []string{"foo"},
4730 },
4731 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004732 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004733 expectedNextProto: "foo",
4734 expectedNextProtoType: npn,
4735 })
4736 tests = append(tests, testCase{
4737 testType: serverTest,
4738 name: "NPN-Server",
4739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004740 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004741 NextProtos: []string{"bar"},
4742 },
4743 flags: []string{
4744 "-advertise-npn", "\x03foo\x03bar\x03baz",
4745 "-expect-next-proto", "bar",
4746 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004747 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004748 expectedNextProto: "bar",
4749 expectedNextProtoType: npn,
4750 })
4751
4752 // TODO(davidben): Add tests for when False Start doesn't trigger.
4753
4754 // Client does False Start and negotiates NPN.
4755 tests = append(tests, testCase{
4756 name: "FalseStart",
4757 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004758 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004759 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4760 NextProtos: []string{"foo"},
4761 Bugs: ProtocolBugs{
4762 ExpectFalseStart: true,
4763 },
4764 },
4765 flags: []string{
4766 "-false-start",
4767 "-select-next-proto", "foo",
4768 },
4769 shimWritesFirst: true,
4770 resumeSession: true,
4771 })
4772
4773 // Client does False Start and negotiates ALPN.
4774 tests = append(tests, testCase{
4775 name: "FalseStart-ALPN",
4776 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004777 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4779 NextProtos: []string{"foo"},
4780 Bugs: ProtocolBugs{
4781 ExpectFalseStart: true,
4782 },
4783 },
4784 flags: []string{
4785 "-false-start",
4786 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004787 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004788 },
4789 shimWritesFirst: true,
4790 resumeSession: true,
4791 })
4792
David Benjamin760b1dd2015-05-15 23:33:48 -04004793 // False Start without session tickets.
4794 tests = append(tests, testCase{
4795 name: "FalseStart-SessionTicketsDisabled",
4796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004797 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4799 NextProtos: []string{"foo"},
4800 SessionTicketsDisabled: true,
4801 Bugs: ProtocolBugs{
4802 ExpectFalseStart: true,
4803 },
4804 },
4805 flags: []string{
4806 "-false-start",
4807 "-select-next-proto", "foo",
4808 },
4809 shimWritesFirst: true,
4810 })
4811
4812 // Server parses a V2ClientHello.
4813 tests = append(tests, testCase{
4814 testType: serverTest,
4815 name: "SendV2ClientHello",
4816 config: Config{
4817 // Choose a cipher suite that does not involve
4818 // elliptic curves, so no extensions are
4819 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004820 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004821 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004822 Bugs: ProtocolBugs{
4823 SendV2ClientHello: true,
4824 },
4825 },
David Benjamin78b8b992017-08-01 18:38:41 -04004826 flags: []string{
4827 "-expect-msg-callback",
4828 `read v2clienthello
4829write hs 2
4830write hs 11
4831write hs 14
4832read hs 16
4833read ccs
4834read hs 20
4835write ccs
4836write hs 20
4837read alert 1 0
4838`,
4839 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004840 })
4841
Nick Harper60a85cb2016-09-23 16:25:11 -07004842 // Test Channel ID
4843 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004844 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004845 continue
4846 }
4847 // Client sends a Channel ID.
4848 tests = append(tests, testCase{
4849 name: "ChannelID-Client-" + ver.name,
4850 config: Config{
4851 MaxVersion: ver.version,
4852 RequestChannelID: true,
4853 },
David Benjamina5022392017-07-10 17:40:39 -04004854 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004855 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4856 resumeSession: true,
4857 expectChannelID: true,
4858 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004859
Nick Harper60a85cb2016-09-23 16:25:11 -07004860 // Server accepts a Channel ID.
4861 tests = append(tests, testCase{
4862 testType: serverTest,
4863 name: "ChannelID-Server-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 ChannelID: channelIDKey,
4867 },
David Benjamina5022392017-07-10 17:40:39 -04004868 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004869 flags: []string{
4870 "-expect-channel-id",
4871 base64.StdEncoding.EncodeToString(channelIDBytes),
4872 },
4873 resumeSession: true,
4874 expectChannelID: true,
4875 })
4876
4877 tests = append(tests, testCase{
4878 testType: serverTest,
4879 name: "InvalidChannelIDSignature-" + ver.name,
4880 config: Config{
4881 MaxVersion: ver.version,
4882 ChannelID: channelIDKey,
4883 Bugs: ProtocolBugs{
4884 InvalidChannelIDSignature: true,
4885 },
4886 },
David Benjamina5022392017-07-10 17:40:39 -04004887 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004888 flags: []string{"-enable-channel-id"},
4889 shouldFail: true,
4890 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4891 })
David Benjamin634f4752017-07-01 11:08:41 -04004892
4893 if ver.version < VersionTLS13 {
4894 // Channel ID requires ECDHE ciphers.
4895 tests = append(tests, testCase{
4896 testType: serverTest,
4897 name: "ChannelID-NoECDHE-" + ver.name,
4898 config: Config{
4899 MaxVersion: ver.version,
4900 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4901 ChannelID: channelIDKey,
4902 },
4903 expectChannelID: false,
4904 flags: []string{"-enable-channel-id"},
4905 })
4906
4907 // Sanity-check setting expectChannelID false works.
4908 tests = append(tests, testCase{
4909 testType: serverTest,
4910 name: "ChannelID-ECDHE-" + ver.name,
4911 config: Config{
4912 MaxVersion: ver.version,
4913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4914 ChannelID: channelIDKey,
4915 },
4916 expectChannelID: false,
4917 flags: []string{"-enable-channel-id"},
4918 shouldFail: true,
4919 expectedLocalError: "channel ID unexpectedly negotiated",
4920 })
4921 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004922 }
David Benjamin30789da2015-08-29 22:56:45 -04004923
David Benjaminf8fcdf32016-06-08 15:56:13 -04004924 // Channel ID and NPN at the same time, to ensure their relative
4925 // ordering is correct.
4926 tests = append(tests, testCase{
4927 name: "ChannelID-NPN-Client",
4928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004929 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004930 RequestChannelID: true,
4931 NextProtos: []string{"foo"},
4932 },
4933 flags: []string{
4934 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4935 "-select-next-proto", "foo",
4936 },
4937 resumeSession: true,
4938 expectChannelID: true,
4939 expectedNextProto: "foo",
4940 expectedNextProtoType: npn,
4941 })
4942 tests = append(tests, testCase{
4943 testType: serverTest,
4944 name: "ChannelID-NPN-Server",
4945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004946 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004947 ChannelID: channelIDKey,
4948 NextProtos: []string{"bar"},
4949 },
4950 flags: []string{
4951 "-expect-channel-id",
4952 base64.StdEncoding.EncodeToString(channelIDBytes),
4953 "-advertise-npn", "\x03foo\x03bar\x03baz",
4954 "-expect-next-proto", "bar",
4955 },
4956 resumeSession: true,
4957 expectChannelID: true,
4958 expectedNextProto: "bar",
4959 expectedNextProtoType: npn,
4960 })
4961
David Benjamin30789da2015-08-29 22:56:45 -04004962 // Bidirectional shutdown with the runner initiating.
4963 tests = append(tests, testCase{
4964 name: "Shutdown-Runner",
4965 config: Config{
4966 Bugs: ProtocolBugs{
4967 ExpectCloseNotify: true,
4968 },
4969 },
4970 flags: []string{"-check-close-notify"},
4971 })
4972
David Benjamine3843d42017-03-25 18:00:56 -05004973 if !config.implicitHandshake {
4974 // Bidirectional shutdown with the shim initiating. The runner,
4975 // in the meantime, sends garbage before the close_notify which
4976 // the shim must ignore. This test is disabled under implicit
4977 // handshake tests because the shim never reads or writes.
4978 tests = append(tests, testCase{
4979 name: "Shutdown-Shim",
4980 config: Config{
4981 MaxVersion: VersionTLS12,
4982 Bugs: ProtocolBugs{
4983 ExpectCloseNotify: true,
4984 },
David Benjamin30789da2015-08-29 22:56:45 -04004985 },
David Benjamine3843d42017-03-25 18:00:56 -05004986 shimShutsDown: true,
4987 sendEmptyRecords: 1,
4988 sendWarningAlerts: 1,
4989 flags: []string{"-check-close-notify"},
4990 })
4991 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004992 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004993 // TODO(davidben): DTLS 1.3 will want a similar thing for
4994 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004995 tests = append(tests, testCase{
4996 name: "SkipHelloVerifyRequest",
4997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004998 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004999 Bugs: ProtocolBugs{
5000 SkipHelloVerifyRequest: true,
5001 },
5002 },
5003 })
5004 }
5005
David Benjamin760b1dd2015-05-15 23:33:48 -04005006 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07005007 test.protocol = config.protocol
5008 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005009 test.name += "-DTLS"
5010 }
David Benjamin582ba042016-07-07 12:33:25 -07005011 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05005012 test.name += "-Async"
5013 test.flags = append(test.flags, "-async")
5014 } else {
5015 test.name += "-Sync"
5016 }
David Benjamin582ba042016-07-07 12:33:25 -07005017 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005018 test.name += "-SplitHandshakeRecords"
5019 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005020 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005021 test.config.Bugs.MaxPacketLength = 256
5022 test.flags = append(test.flags, "-mtu", "256")
5023 }
5024 }
David Benjamin582ba042016-07-07 12:33:25 -07005025 if config.packHandshakeFlight {
5026 test.name += "-PackHandshakeFlight"
5027 test.config.Bugs.PackHandshakeFlight = true
5028 }
David Benjamine3843d42017-03-25 18:00:56 -05005029 if config.implicitHandshake {
5030 test.name += "-ImplicitHandshake"
5031 test.flags = append(test.flags, "-implicit-handshake")
5032 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005033 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005034 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005035}
5036
Adam Langley524e7172015-02-20 16:04:00 -08005037func addDDoSCallbackTests() {
5038 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005039 for _, resume := range []bool{false, true} {
5040 suffix := "Resume"
5041 if resume {
5042 suffix = "No" + suffix
5043 }
5044
5045 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005046 testType: serverTest,
5047 name: "Server-DDoS-OK-" + suffix,
5048 config: Config{
5049 MaxVersion: VersionTLS12,
5050 },
Adam Langley524e7172015-02-20 16:04:00 -08005051 flags: []string{"-install-ddos-callback"},
5052 resumeSession: resume,
5053 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005054 testCases = append(testCases, testCase{
5055 testType: serverTest,
5056 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5057 config: Config{
5058 MaxVersion: VersionTLS13,
5059 },
5060 flags: []string{"-install-ddos-callback"},
5061 resumeSession: resume,
5062 })
Adam Langley524e7172015-02-20 16:04:00 -08005063
5064 failFlag := "-fail-ddos-callback"
5065 if resume {
5066 failFlag = "-fail-second-ddos-callback"
5067 }
5068 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005069 testType: serverTest,
5070 name: "Server-DDoS-Reject-" + suffix,
5071 config: Config{
5072 MaxVersion: VersionTLS12,
5073 },
David Benjamin2c66e072016-09-16 15:58:00 -04005074 flags: []string{"-install-ddos-callback", failFlag},
5075 resumeSession: resume,
5076 shouldFail: true,
5077 expectedError: ":CONNECTION_REJECTED:",
5078 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005079 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5083 config: Config{
5084 MaxVersion: VersionTLS13,
5085 },
David Benjamin2c66e072016-09-16 15:58:00 -04005086 flags: []string{"-install-ddos-callback", failFlag},
5087 resumeSession: resume,
5088 shouldFail: true,
5089 expectedError: ":CONNECTION_REJECTED:",
5090 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005091 })
Adam Langley524e7172015-02-20 16:04:00 -08005092 }
5093}
5094
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005095func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005096 for _, protocol := range []protocol{tls, dtls} {
5097 for _, shimVers := range allVersions(protocol) {
5098 // Assemble flags to disable all newer versions on the shim.
5099 var flags []string
5100 for _, vers := range allVersions(protocol) {
5101 if vers.version > shimVers.version {
5102 flags = append(flags, vers.excludeFlag)
5103 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005104 }
Steven Valdez520e1222017-06-13 12:45:25 -04005105
5106 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5107
5108 if shimVers.tls13Variant != 0 {
5109 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5110 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5111 }
5112
5113 // Test configuring the runner's maximum version.
5114 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005115 expectedVersion := shimVers.version
5116 if runnerVers.version < shimVers.version {
5117 expectedVersion = runnerVers.version
5118 }
Steven Valdez520e1222017-06-13 12:45:25 -04005119 // When running and shim have different TLS 1.3 variants enabled,
5120 // shim clients are expected to fall back to TLS 1.2, while shim
5121 // servers support both variants when enabled when the experiment is
5122 // enabled.
5123 expectedServerVersion := expectedVersion
5124 expectedClientVersion := expectedVersion
5125 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5126 expectedClientVersion = VersionTLS12
5127 expectedServerVersion = VersionTLS12
5128 if shimVers.tls13Variant != TLS13Default {
5129 expectedServerVersion = VersionTLS13
5130 }
5131 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005132
David Benjamin8b8c0062014-11-23 02:47:52 -05005133 suffix := shimVers.name + "-" + runnerVers.name
5134 if protocol == dtls {
5135 suffix += "-DTLS"
5136 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005137
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005138 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005139 clientVers := shimVers.version
5140 if clientVers > VersionTLS10 {
5141 clientVers = VersionTLS10
5142 }
Steven Valdez520e1222017-06-13 12:45:25 -04005143 clientVers = recordVersionToWire(clientVers, protocol)
5144 serverVers := expectedServerVersion
5145 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005146 serverVers = VersionTLS10
5147 }
Steven Valdez520e1222017-06-13 12:45:25 -04005148 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005149
David Benjamin8b8c0062014-11-23 02:47:52 -05005150 testCases = append(testCases, testCase{
5151 protocol: protocol,
5152 testType: clientTest,
5153 name: "VersionNegotiation-Client-" + suffix,
5154 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005155 MaxVersion: runnerVers.version,
5156 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005157 Bugs: ProtocolBugs{
5158 ExpectInitialRecordVersion: clientVers,
5159 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005160 },
5161 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005162 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005163 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005164 testCases = append(testCases, testCase{
5165 protocol: protocol,
5166 testType: clientTest,
5167 name: "VersionNegotiation-Client2-" + suffix,
5168 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005169 MaxVersion: runnerVers.version,
5170 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005171 Bugs: ProtocolBugs{
5172 ExpectInitialRecordVersion: clientVers,
5173 },
5174 },
Steven Valdez520e1222017-06-13 12:45:25 -04005175 flags: flags2,
5176 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005177 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005178
5179 testCases = append(testCases, testCase{
5180 protocol: protocol,
5181 testType: serverTest,
5182 name: "VersionNegotiation-Server-" + suffix,
5183 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005184 MaxVersion: runnerVers.version,
5185 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005186 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005187 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005188 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005189 },
5190 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005191 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005192 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005193 testCases = append(testCases, testCase{
5194 protocol: protocol,
5195 testType: serverTest,
5196 name: "VersionNegotiation-Server2-" + suffix,
5197 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005198 MaxVersion: runnerVers.version,
5199 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005200 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005201 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005202 },
5203 },
Steven Valdez520e1222017-06-13 12:45:25 -04005204 flags: flags2,
5205 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005206 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005207 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005208 }
5209 }
David Benjamin95c69562016-06-29 18:15:03 -04005210
Steven Valdezfdd10992016-09-15 16:27:05 -04005211 // Test the version extension at all versions.
5212 for _, vers := range tlsVersions {
5213 protocols := []protocol{tls}
5214 if vers.hasDTLS {
5215 protocols = append(protocols, dtls)
5216 }
5217 for _, protocol := range protocols {
5218 suffix := vers.name
5219 if protocol == dtls {
5220 suffix += "-DTLS"
5221 }
5222
Steven Valdezfdd10992016-09-15 16:27:05 -04005223 testCases = append(testCases, testCase{
5224 protocol: protocol,
5225 testType: serverTest,
5226 name: "VersionNegotiationExtension-" + suffix,
5227 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005228 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005230 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005231 },
5232 },
5233 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005234 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005235 })
5236 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005237 }
5238
5239 // If all versions are unknown, negotiation fails.
5240 testCases = append(testCases, testCase{
5241 testType: serverTest,
5242 name: "NoSupportedVersions",
5243 config: Config{
5244 Bugs: ProtocolBugs{
5245 SendSupportedVersions: []uint16{0x1111},
5246 },
5247 },
5248 shouldFail: true,
5249 expectedError: ":UNSUPPORTED_PROTOCOL:",
5250 })
5251 testCases = append(testCases, testCase{
5252 protocol: dtls,
5253 testType: serverTest,
5254 name: "NoSupportedVersions-DTLS",
5255 config: Config{
5256 Bugs: ProtocolBugs{
5257 SendSupportedVersions: []uint16{0x1111},
5258 },
5259 },
5260 shouldFail: true,
5261 expectedError: ":UNSUPPORTED_PROTOCOL:",
5262 })
5263
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "ClientHelloVersionTooHigh",
5267 config: Config{
5268 MaxVersion: VersionTLS13,
5269 Bugs: ProtocolBugs{
5270 SendClientVersion: 0x0304,
5271 OmitSupportedVersions: true,
5272 },
5273 },
5274 expectedVersion: VersionTLS12,
5275 })
5276
5277 testCases = append(testCases, testCase{
5278 testType: serverTest,
5279 name: "ConflictingVersionNegotiation",
5280 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005281 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005282 SendClientVersion: VersionTLS12,
5283 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005284 },
5285 },
David Benjaminad75a662016-09-30 15:42:59 -04005286 // The extension takes precedence over the ClientHello version.
5287 expectedVersion: VersionTLS11,
5288 })
5289
5290 testCases = append(testCases, testCase{
5291 testType: serverTest,
5292 name: "ConflictingVersionNegotiation-2",
5293 config: Config{
5294 Bugs: ProtocolBugs{
5295 SendClientVersion: VersionTLS11,
5296 SendSupportedVersions: []uint16{VersionTLS12},
5297 },
5298 },
5299 // The extension takes precedence over the ClientHello version.
5300 expectedVersion: VersionTLS12,
5301 })
5302
5303 testCases = append(testCases, testCase{
5304 testType: serverTest,
5305 name: "RejectFinalTLS13",
5306 config: Config{
5307 Bugs: ProtocolBugs{
5308 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5309 },
5310 },
5311 // We currently implement a draft TLS 1.3 version. Ensure that
5312 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005313 expectedVersion: VersionTLS12,
5314 })
5315
Steven Valdez038da9b2017-07-10 12:57:25 -04005316 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5317 // the ServerHello.
5318 testCases = append(testCases, testCase{
5319 testType: clientTest,
5320 name: "SupportedVersionSelection-TLS12",
5321 config: Config{
5322 MaxVersion: VersionTLS12,
5323 Bugs: ProtocolBugs{
5324 SendServerSupportedExtensionVersion: VersionTLS12,
5325 },
5326 },
5327 shouldFail: true,
5328 expectedError: ":UNEXPECTED_EXTENSION:",
5329 })
5330
5331 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5332 // supported_versions extension in the ServerHello.
5333 testCases = append(testCases, testCase{
5334 testType: clientTest,
5335 name: "SupportedVersionSelection-TLS13",
5336 config: Config{
5337 MaxVersion: VersionTLS13,
5338 Bugs: ProtocolBugs{
5339 SendServerSupportedExtensionVersion: tls13DraftVersion,
5340 },
5341 },
5342 shouldFail: true,
5343 expectedError: ":UNEXPECTED_EXTENSION:",
5344 })
5345
Brian Smithf85d3232016-10-28 10:34:06 -10005346 // Test that the maximum version is selected regardless of the
5347 // client-sent order.
5348 testCases = append(testCases, testCase{
5349 testType: serverTest,
5350 name: "IgnoreClientVersionOrder",
5351 config: Config{
5352 Bugs: ProtocolBugs{
5353 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5354 },
5355 },
5356 expectedVersion: VersionTLS13,
5357 })
5358
David Benjamin95c69562016-06-29 18:15:03 -04005359 // Test for version tolerance.
5360 testCases = append(testCases, testCase{
5361 testType: serverTest,
5362 name: "MinorVersionTolerance",
5363 config: Config{
5364 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005365 SendClientVersion: 0x03ff,
5366 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005367 },
5368 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005369 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005370 })
5371 testCases = append(testCases, testCase{
5372 testType: serverTest,
5373 name: "MajorVersionTolerance",
5374 config: Config{
5375 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005376 SendClientVersion: 0x0400,
5377 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005378 },
5379 },
David Benjaminad75a662016-09-30 15:42:59 -04005380 // TLS 1.3 must be negotiated with the supported_versions
5381 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005382 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005383 })
David Benjaminad75a662016-09-30 15:42:59 -04005384 testCases = append(testCases, testCase{
5385 testType: serverTest,
5386 name: "VersionTolerance-TLS13",
5387 config: Config{
5388 Bugs: ProtocolBugs{
5389 // Although TLS 1.3 does not use
5390 // ClientHello.version, it still tolerates high
5391 // values there.
5392 SendClientVersion: 0x0400,
5393 },
5394 },
5395 expectedVersion: VersionTLS13,
5396 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005397
David Benjamin95c69562016-06-29 18:15:03 -04005398 testCases = append(testCases, testCase{
5399 protocol: dtls,
5400 testType: serverTest,
5401 name: "MinorVersionTolerance-DTLS",
5402 config: Config{
5403 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005404 SendClientVersion: 0xfe00,
5405 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005406 },
5407 },
5408 expectedVersion: VersionTLS12,
5409 })
5410 testCases = append(testCases, testCase{
5411 protocol: dtls,
5412 testType: serverTest,
5413 name: "MajorVersionTolerance-DTLS",
5414 config: Config{
5415 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005416 SendClientVersion: 0xfdff,
5417 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005418 },
5419 },
5420 expectedVersion: VersionTLS12,
5421 })
5422
5423 // Test that versions below 3.0 are rejected.
5424 testCases = append(testCases, testCase{
5425 testType: serverTest,
5426 name: "VersionTooLow",
5427 config: Config{
5428 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005429 SendClientVersion: 0x0200,
5430 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":UNSUPPORTED_PROTOCOL:",
5435 })
5436 testCases = append(testCases, testCase{
5437 protocol: dtls,
5438 testType: serverTest,
5439 name: "VersionTooLow-DTLS",
5440 config: Config{
5441 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005442 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":UNSUPPORTED_PROTOCOL:",
5447 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005448
David Benjamin2dc02042016-09-19 19:57:37 -04005449 testCases = append(testCases, testCase{
5450 name: "ServerBogusVersion",
5451 config: Config{
5452 Bugs: ProtocolBugs{
5453 SendServerHelloVersion: 0x1234,
5454 },
5455 },
5456 shouldFail: true,
5457 expectedError: ":UNSUPPORTED_PROTOCOL:",
5458 })
5459
David Benjamin1f61f0d2016-07-10 12:20:35 -04005460 // Test TLS 1.3's downgrade signal.
5461 testCases = append(testCases, testCase{
5462 name: "Downgrade-TLS12-Client",
5463 config: Config{
5464 Bugs: ProtocolBugs{
5465 NegotiateVersion: VersionTLS12,
5466 },
5467 },
David Benjamin592b5322016-09-30 15:15:01 -04005468 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005469 // TODO(davidben): This test should fail once TLS 1.3 is final
5470 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005471 })
5472 testCases = append(testCases, testCase{
5473 testType: serverTest,
5474 name: "Downgrade-TLS12-Server",
5475 config: Config{
5476 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005477 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005478 },
5479 },
David Benjamin592b5322016-09-30 15:15:01 -04005480 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005481 // TODO(davidben): This test should fail once TLS 1.3 is final
5482 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005483 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005484}
5485
David Benjaminaccb4542014-12-12 23:44:33 -05005486func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005487 for _, protocol := range []protocol{tls, dtls} {
5488 for _, shimVers := range allVersions(protocol) {
5489 // Assemble flags to disable all older versions on the shim.
5490 var flags []string
5491 for _, vers := range allVersions(protocol) {
5492 if vers.version < shimVers.version {
5493 flags = append(flags, vers.excludeFlag)
5494 }
David Benjaminaccb4542014-12-12 23:44:33 -05005495 }
Steven Valdez520e1222017-06-13 12:45:25 -04005496
5497 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5498
5499 if shimVers.tls13Variant != 0 {
5500 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5501 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5502 }
5503
5504 for _, runnerVers := range allVersions(protocol) {
5505 // Different TLS 1.3 variants are incompatible with each other and don't
5506 // produce consistent minimum versions.
5507 //
5508 // TODO(davidben): Fold these tests (the main value is in the
5509 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5510 // on intended shim behavior, not the shim + runner combination.
5511 if shimVers.tls13Variant != runnerVers.tls13Variant {
5512 continue
5513 }
5514
David Benjaminaccb4542014-12-12 23:44:33 -05005515 suffix := shimVers.name + "-" + runnerVers.name
5516 if protocol == dtls {
5517 suffix += "-DTLS"
5518 }
David Benjaminaccb4542014-12-12 23:44:33 -05005519
David Benjaminaccb4542014-12-12 23:44:33 -05005520 var expectedVersion uint16
5521 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005522 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005523 if runnerVers.version >= shimVers.version {
5524 expectedVersion = runnerVers.version
5525 } else {
5526 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005527 expectedError = ":UNSUPPORTED_PROTOCOL:"
5528 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005529 }
5530
5531 testCases = append(testCases, testCase{
5532 protocol: protocol,
5533 testType: clientTest,
5534 name: "MinimumVersion-Client-" + suffix,
5535 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005536 MaxVersion: runnerVers.version,
5537 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005538 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005539 // Ensure the server does not decline to
5540 // select a version (versions extension) or
5541 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005542 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005543 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005544 },
David Benjaminaccb4542014-12-12 23:44:33 -05005545 },
David Benjamin87909c02014-12-13 01:55:01 -05005546 flags: flags,
5547 expectedVersion: expectedVersion,
5548 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005549 expectedError: expectedError,
5550 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005551 })
5552 testCases = append(testCases, testCase{
5553 protocol: protocol,
5554 testType: clientTest,
5555 name: "MinimumVersion-Client2-" + suffix,
5556 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005557 MaxVersion: runnerVers.version,
5558 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005559 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005560 // Ensure the server does not decline to
5561 // select a version (versions extension) or
5562 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005563 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005564 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005565 },
David Benjaminaccb4542014-12-12 23:44:33 -05005566 },
Steven Valdez520e1222017-06-13 12:45:25 -04005567 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005568 expectedVersion: expectedVersion,
5569 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005570 expectedError: expectedError,
5571 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005572 })
5573
5574 testCases = append(testCases, testCase{
5575 protocol: protocol,
5576 testType: serverTest,
5577 name: "MinimumVersion-Server-" + suffix,
5578 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005579 MaxVersion: runnerVers.version,
5580 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005581 },
David Benjamin87909c02014-12-13 01:55:01 -05005582 flags: flags,
5583 expectedVersion: expectedVersion,
5584 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005585 expectedError: expectedError,
5586 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005587 })
5588 testCases = append(testCases, testCase{
5589 protocol: protocol,
5590 testType: serverTest,
5591 name: "MinimumVersion-Server2-" + suffix,
5592 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005593 MaxVersion: runnerVers.version,
5594 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005595 },
Steven Valdez520e1222017-06-13 12:45:25 -04005596 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005597 expectedVersion: expectedVersion,
5598 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005599 expectedError: expectedError,
5600 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005601 })
5602 }
5603 }
5604 }
5605}
5606
David Benjamine78bfde2014-09-06 12:45:15 -04005607func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005608 // TODO(davidben): Extensions, where applicable, all move their server
5609 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5610 // tests for both. Also test interaction with 0-RTT when implemented.
5611
David Benjamin97d17d92016-07-14 16:12:00 -04005612 // Repeat extensions tests all versions except SSL 3.0.
5613 for _, ver := range tlsVersions {
5614 if ver.version == VersionSSL30 {
5615 continue
5616 }
5617
David Benjamin97d17d92016-07-14 16:12:00 -04005618 // Test that duplicate extensions are rejected.
5619 testCases = append(testCases, testCase{
5620 testType: clientTest,
5621 name: "DuplicateExtensionClient-" + ver.name,
5622 config: Config{
5623 MaxVersion: ver.version,
5624 Bugs: ProtocolBugs{
5625 DuplicateExtension: true,
5626 },
David Benjamine78bfde2014-09-06 12:45:15 -04005627 },
David Benjamina5022392017-07-10 17:40:39 -04005628 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005629 shouldFail: true,
5630 expectedLocalError: "remote error: error decoding message",
5631 })
5632 testCases = append(testCases, testCase{
5633 testType: serverTest,
5634 name: "DuplicateExtensionServer-" + ver.name,
5635 config: Config{
5636 MaxVersion: ver.version,
5637 Bugs: ProtocolBugs{
5638 DuplicateExtension: true,
5639 },
David Benjamine78bfde2014-09-06 12:45:15 -04005640 },
David Benjamina5022392017-07-10 17:40:39 -04005641 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005642 shouldFail: true,
5643 expectedLocalError: "remote error: error decoding message",
5644 })
5645
5646 // Test SNI.
5647 testCases = append(testCases, testCase{
5648 testType: clientTest,
5649 name: "ServerNameExtensionClient-" + ver.name,
5650 config: Config{
5651 MaxVersion: ver.version,
5652 Bugs: ProtocolBugs{
5653 ExpectServerName: "example.com",
5654 },
David Benjamine78bfde2014-09-06 12:45:15 -04005655 },
David Benjamina5022392017-07-10 17:40:39 -04005656 tls13Variant: ver.tls13Variant,
5657 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005658 })
5659 testCases = append(testCases, testCase{
5660 testType: clientTest,
5661 name: "ServerNameExtensionClientMismatch-" + ver.name,
5662 config: Config{
5663 MaxVersion: ver.version,
5664 Bugs: ProtocolBugs{
5665 ExpectServerName: "mismatch.com",
5666 },
David Benjamine78bfde2014-09-06 12:45:15 -04005667 },
David Benjamin97d17d92016-07-14 16:12:00 -04005668 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005669 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005670 shouldFail: true,
5671 expectedLocalError: "tls: unexpected server name",
5672 })
5673 testCases = append(testCases, testCase{
5674 testType: clientTest,
5675 name: "ServerNameExtensionClientMissing-" + ver.name,
5676 config: Config{
5677 MaxVersion: ver.version,
5678 Bugs: ProtocolBugs{
5679 ExpectServerName: "missing.com",
5680 },
David Benjamine78bfde2014-09-06 12:45:15 -04005681 },
David Benjamina5022392017-07-10 17:40:39 -04005682 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005683 shouldFail: true,
5684 expectedLocalError: "tls: unexpected server name",
5685 })
5686 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005687 testType: clientTest,
5688 name: "TolerateServerNameAck-" + ver.name,
5689 config: Config{
5690 MaxVersion: ver.version,
5691 Bugs: ProtocolBugs{
5692 SendServerNameAck: true,
5693 },
5694 },
David Benjamina5022392017-07-10 17:40:39 -04005695 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005696 flags: []string{"-host-name", "example.com"},
5697 resumeSession: true,
5698 })
5699 testCases = append(testCases, testCase{
5700 testType: clientTest,
5701 name: "UnsolicitedServerNameAck-" + ver.name,
5702 config: Config{
5703 MaxVersion: ver.version,
5704 Bugs: ProtocolBugs{
5705 SendServerNameAck: true,
5706 },
5707 },
David Benjamina5022392017-07-10 17:40:39 -04005708 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005709 shouldFail: true,
5710 expectedError: ":UNEXPECTED_EXTENSION:",
5711 expectedLocalError: "remote error: unsupported extension",
5712 })
5713 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005714 testType: serverTest,
5715 name: "ServerNameExtensionServer-" + ver.name,
5716 config: Config{
5717 MaxVersion: ver.version,
5718 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005719 },
David Benjamina5022392017-07-10 17:40:39 -04005720 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005721 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005722 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005723 })
5724
5725 // Test ALPN.
5726 testCases = append(testCases, testCase{
5727 testType: clientTest,
5728 name: "ALPNClient-" + ver.name,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 NextProtos: []string{"foo"},
5732 },
5733 flags: []string{
5734 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5735 "-expect-alpn", "foo",
5736 },
David Benjamina5022392017-07-10 17:40:39 -04005737 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005738 expectedNextProto: "foo",
5739 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005740 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005741 })
5742 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005743 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005744 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005745 config: Config{
5746 MaxVersion: ver.version,
5747 Bugs: ProtocolBugs{
5748 SendALPN: "baz",
5749 },
5750 },
5751 flags: []string{
5752 "-advertise-alpn", "\x03foo\x03bar",
5753 },
David Benjamina5022392017-07-10 17:40:39 -04005754 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005755 shouldFail: true,
5756 expectedError: ":INVALID_ALPN_PROTOCOL:",
5757 expectedLocalError: "remote error: illegal parameter",
5758 })
5759 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005760 testType: clientTest,
5761 name: "ALPNClient-AllowUnknown-" + ver.name,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 Bugs: ProtocolBugs{
5765 SendALPN: "baz",
5766 },
5767 },
5768 flags: []string{
5769 "-advertise-alpn", "\x03foo\x03bar",
5770 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005771 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005772 },
David Benjamina5022392017-07-10 17:40:39 -04005773 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005774 })
5775 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005776 testType: serverTest,
5777 name: "ALPNServer-" + ver.name,
5778 config: Config{
5779 MaxVersion: ver.version,
5780 NextProtos: []string{"foo", "bar", "baz"},
5781 },
5782 flags: []string{
5783 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5784 "-select-alpn", "foo",
5785 },
David Benjamina5022392017-07-10 17:40:39 -04005786 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005787 expectedNextProto: "foo",
5788 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005789 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005790 })
5791 testCases = append(testCases, testCase{
5792 testType: serverTest,
5793 name: "ALPNServer-Decline-" + ver.name,
5794 config: Config{
5795 MaxVersion: ver.version,
5796 NextProtos: []string{"foo", "bar", "baz"},
5797 },
5798 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005799 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005800 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005801 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005802 })
5803
David Benjamin25fe85b2016-08-09 20:00:32 -04005804 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5805 // called once.
5806 testCases = append(testCases, testCase{
5807 testType: serverTest,
5808 name: "ALPNServer-Async-" + ver.name,
5809 config: Config{
5810 MaxVersion: ver.version,
5811 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005812 // Prior to TLS 1.3, exercise the asynchronous session callback.
5813 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005814 },
5815 flags: []string{
5816 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5817 "-select-alpn", "foo",
5818 "-async",
5819 },
David Benjamina5022392017-07-10 17:40:39 -04005820 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005821 expectedNextProto: "foo",
5822 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005823 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005824 })
5825
David Benjamin97d17d92016-07-14 16:12:00 -04005826 var emptyString string
5827 testCases = append(testCases, testCase{
5828 testType: clientTest,
5829 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5830 config: Config{
5831 MaxVersion: ver.version,
5832 NextProtos: []string{""},
5833 Bugs: ProtocolBugs{
5834 // A server returning an empty ALPN protocol
5835 // should be rejected.
5836 ALPNProtocol: &emptyString,
5837 },
5838 },
5839 flags: []string{
5840 "-advertise-alpn", "\x03foo",
5841 },
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 testCases = append(testCases, testCase{
5847 testType: serverTest,
5848 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5849 config: Config{
5850 MaxVersion: ver.version,
5851 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005852 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005853 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005854 },
David Benjamin97d17d92016-07-14 16:12:00 -04005855 flags: []string{
5856 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005857 },
David Benjamina5022392017-07-10 17:40:39 -04005858 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005859 shouldFail: true,
5860 expectedError: ":PARSE_TLSEXT:",
5861 })
5862
5863 // Test NPN and the interaction with ALPN.
5864 if ver.version < VersionTLS13 {
5865 // Test that the server prefers ALPN over NPN.
5866 testCases = append(testCases, testCase{
5867 testType: serverTest,
5868 name: "ALPNServer-Preferred-" + ver.name,
5869 config: Config{
5870 MaxVersion: ver.version,
5871 NextProtos: []string{"foo", "bar", "baz"},
5872 },
5873 flags: []string{
5874 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5875 "-select-alpn", "foo",
5876 "-advertise-npn", "\x03foo\x03bar\x03baz",
5877 },
David Benjamina5022392017-07-10 17:40:39 -04005878 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005879 expectedNextProto: "foo",
5880 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005881 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005882 })
5883 testCases = append(testCases, testCase{
5884 testType: serverTest,
5885 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5886 config: Config{
5887 MaxVersion: ver.version,
5888 NextProtos: []string{"foo", "bar", "baz"},
5889 Bugs: ProtocolBugs{
5890 SwapNPNAndALPN: true,
5891 },
5892 },
5893 flags: []string{
5894 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5895 "-select-alpn", "foo",
5896 "-advertise-npn", "\x03foo\x03bar\x03baz",
5897 },
David Benjamina5022392017-07-10 17:40:39 -04005898 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005899 expectedNextProto: "foo",
5900 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005901 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005902 })
5903
5904 // Test that negotiating both NPN and ALPN is forbidden.
5905 testCases = append(testCases, testCase{
5906 name: "NegotiateALPNAndNPN-" + ver.name,
5907 config: Config{
5908 MaxVersion: ver.version,
5909 NextProtos: []string{"foo", "bar", "baz"},
5910 Bugs: ProtocolBugs{
5911 NegotiateALPNAndNPN: true,
5912 },
5913 },
5914 flags: []string{
5915 "-advertise-alpn", "\x03foo",
5916 "-select-next-proto", "foo",
5917 },
David Benjamina5022392017-07-10 17:40:39 -04005918 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005919 shouldFail: true,
5920 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5921 })
5922 testCases = append(testCases, testCase{
5923 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5924 config: Config{
5925 MaxVersion: ver.version,
5926 NextProtos: []string{"foo", "bar", "baz"},
5927 Bugs: ProtocolBugs{
5928 NegotiateALPNAndNPN: true,
5929 SwapNPNAndALPN: true,
5930 },
5931 },
5932 flags: []string{
5933 "-advertise-alpn", "\x03foo",
5934 "-select-next-proto", "foo",
5935 },
David Benjamina5022392017-07-10 17:40:39 -04005936 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005937 shouldFail: true,
5938 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5939 })
David Benjamin97d17d92016-07-14 16:12:00 -04005940 }
5941
5942 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005943
5944 // Resume with a corrupt ticket.
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
5947 name: "CorruptTicket-" + ver.name,
5948 config: Config{
5949 MaxVersion: ver.version,
5950 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005951 FilterTicket: func(in []byte) ([]byte, error) {
5952 in[len(in)-1] ^= 1
5953 return in, nil
5954 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005955 },
5956 },
David Benjamina5022392017-07-10 17:40:39 -04005957 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005958 resumeSession: true,
5959 expectResumeRejected: true,
5960 })
5961 // Test the ticket callback, with and without renewal.
5962 testCases = append(testCases, testCase{
5963 testType: serverTest,
5964 name: "TicketCallback-" + ver.name,
5965 config: Config{
5966 MaxVersion: ver.version,
5967 },
David Benjamina5022392017-07-10 17:40:39 -04005968 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005969 resumeSession: true,
5970 flags: []string{"-use-ticket-callback"},
5971 })
5972 testCases = append(testCases, testCase{
5973 testType: serverTest,
5974 name: "TicketCallback-Renew-" + ver.name,
5975 config: Config{
5976 MaxVersion: ver.version,
5977 Bugs: ProtocolBugs{
5978 ExpectNewTicket: true,
5979 },
5980 },
David Benjamina5022392017-07-10 17:40:39 -04005981 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005982 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5983 resumeSession: true,
5984 })
5985
5986 // Test that the ticket callback is only called once when everything before
5987 // it in the ClientHello is asynchronous. This corrupts the ticket so
5988 // certificate selection callbacks run.
5989 testCases = append(testCases, testCase{
5990 testType: serverTest,
5991 name: "TicketCallback-SingleCall-" + ver.name,
5992 config: Config{
5993 MaxVersion: ver.version,
5994 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005995 FilterTicket: func(in []byte) ([]byte, error) {
5996 in[len(in)-1] ^= 1
5997 return in, nil
5998 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005999 },
6000 },
David Benjamina5022392017-07-10 17:40:39 -04006001 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006002 resumeSession: true,
6003 expectResumeRejected: true,
6004 flags: []string{
6005 "-use-ticket-callback",
6006 "-async",
6007 },
6008 })
6009
David Benjamind4c349b2017-02-09 14:07:17 -05006010 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04006011 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04006012 testCases = append(testCases, testCase{
6013 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05006014 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04006015 config: Config{
6016 MaxVersion: ver.version,
6017 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006018 EmptyTicketSessionID: true,
6019 },
6020 },
6021 resumeSession: true,
6022 })
6023 testCases = append(testCases, testCase{
6024 testType: serverTest,
6025 name: "TicketSessionIDLength-16-" + ver.name,
6026 config: Config{
6027 MaxVersion: ver.version,
6028 Bugs: ProtocolBugs{
6029 TicketSessionIDLength: 16,
6030 },
6031 },
6032 resumeSession: true,
6033 })
6034 testCases = append(testCases, testCase{
6035 testType: serverTest,
6036 name: "TicketSessionIDLength-32-" + ver.name,
6037 config: Config{
6038 MaxVersion: ver.version,
6039 Bugs: ProtocolBugs{
6040 TicketSessionIDLength: 32,
6041 },
6042 },
6043 resumeSession: true,
6044 })
6045 testCases = append(testCases, testCase{
6046 testType: serverTest,
6047 name: "TicketSessionIDLength-33-" + ver.name,
6048 config: Config{
6049 MaxVersion: ver.version,
6050 Bugs: ProtocolBugs{
6051 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006052 },
6053 },
6054 resumeSession: true,
6055 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006056 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006057 expectedError: ":DECODE_ERROR:",
6058 })
6059 }
6060
6061 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6062 // are ignored.
6063 if ver.hasDTLS {
6064 testCases = append(testCases, testCase{
6065 protocol: dtls,
6066 name: "SRTP-Client-" + ver.name,
6067 config: Config{
6068 MaxVersion: ver.version,
6069 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6070 },
6071 flags: []string{
6072 "-srtp-profiles",
6073 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6074 },
6075 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6076 })
6077 testCases = append(testCases, testCase{
6078 protocol: dtls,
6079 testType: serverTest,
6080 name: "SRTP-Server-" + ver.name,
6081 config: Config{
6082 MaxVersion: ver.version,
6083 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6084 },
6085 flags: []string{
6086 "-srtp-profiles",
6087 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6088 },
6089 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6090 })
6091 // Test that the MKI is ignored.
6092 testCases = append(testCases, testCase{
6093 protocol: dtls,
6094 testType: serverTest,
6095 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6096 config: Config{
6097 MaxVersion: ver.version,
6098 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6099 Bugs: ProtocolBugs{
6100 SRTPMasterKeyIdentifer: "bogus",
6101 },
6102 },
6103 flags: []string{
6104 "-srtp-profiles",
6105 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6106 },
6107 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6108 })
6109 // Test that SRTP isn't negotiated on the server if there were
6110 // no matching profiles.
6111 testCases = append(testCases, testCase{
6112 protocol: dtls,
6113 testType: serverTest,
6114 name: "SRTP-Server-NoMatch-" + ver.name,
6115 config: Config{
6116 MaxVersion: ver.version,
6117 SRTPProtectionProfiles: []uint16{100, 101, 102},
6118 },
6119 flags: []string{
6120 "-srtp-profiles",
6121 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6122 },
6123 expectedSRTPProtectionProfile: 0,
6124 })
6125 // Test that the server returning an invalid SRTP profile is
6126 // flagged as an error by the client.
6127 testCases = append(testCases, testCase{
6128 protocol: dtls,
6129 name: "SRTP-Client-NoMatch-" + ver.name,
6130 config: Config{
6131 MaxVersion: ver.version,
6132 Bugs: ProtocolBugs{
6133 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6134 },
6135 },
6136 flags: []string{
6137 "-srtp-profiles",
6138 "SRTP_AES128_CM_SHA1_80",
6139 },
6140 shouldFail: true,
6141 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6142 })
6143 }
6144
6145 // Test SCT list.
6146 testCases = append(testCases, testCase{
6147 name: "SignedCertificateTimestampList-Client-" + ver.name,
6148 testType: clientTest,
6149 config: Config{
6150 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006151 },
David Benjamin97d17d92016-07-14 16:12:00 -04006152 flags: []string{
6153 "-enable-signed-cert-timestamps",
6154 "-expect-signed-cert-timestamps",
6155 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006156 },
David Benjamina5022392017-07-10 17:40:39 -04006157 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006158 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006159 })
David Benjamindaa88502016-10-04 16:32:16 -04006160
Adam Langleycfa08c32016-11-17 13:21:27 -08006161 var differentSCTList []byte
6162 differentSCTList = append(differentSCTList, testSCTList...)
6163 differentSCTList[len(differentSCTList)-1] ^= 1
6164
David Benjamindaa88502016-10-04 16:32:16 -04006165 // The SCT extension did not specify that it must only be sent on resumption as it
6166 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006167 testCases = append(testCases, testCase{
6168 name: "SendSCTListOnResume-" + ver.name,
6169 config: Config{
6170 MaxVersion: ver.version,
6171 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006172 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006173 },
David Benjamind98452d2015-06-16 14:16:23 -04006174 },
David Benjamin97d17d92016-07-14 16:12:00 -04006175 flags: []string{
6176 "-enable-signed-cert-timestamps",
6177 "-expect-signed-cert-timestamps",
6178 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006179 },
David Benjamina5022392017-07-10 17:40:39 -04006180 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006181 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006182 })
David Benjamindaa88502016-10-04 16:32:16 -04006183
David Benjamin97d17d92016-07-14 16:12:00 -04006184 testCases = append(testCases, testCase{
6185 name: "SignedCertificateTimestampList-Server-" + ver.name,
6186 testType: serverTest,
6187 config: Config{
6188 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006189 },
David Benjamin97d17d92016-07-14 16:12:00 -04006190 flags: []string{
6191 "-signed-cert-timestamps",
6192 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006193 },
David Benjamina5022392017-07-10 17:40:39 -04006194 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006195 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006196 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006197 })
David Benjamin53210cb2016-11-16 09:01:48 +09006198
Adam Langleycfa08c32016-11-17 13:21:27 -08006199 emptySCTListCert := *testCerts[0].cert
6200 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6201
6202 // Test empty SCT list.
6203 testCases = append(testCases, testCase{
6204 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6205 testType: clientTest,
6206 config: Config{
6207 MaxVersion: ver.version,
6208 Certificates: []Certificate{emptySCTListCert},
6209 },
6210 flags: []string{
6211 "-enable-signed-cert-timestamps",
6212 },
David Benjamina5022392017-07-10 17:40:39 -04006213 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006214 shouldFail: true,
6215 expectedError: ":ERROR_PARSING_EXTENSION:",
6216 })
6217
6218 emptySCTCert := *testCerts[0].cert
6219 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6220
6221 // Test empty SCT in non-empty list.
6222 testCases = append(testCases, testCase{
6223 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6224 testType: clientTest,
6225 config: Config{
6226 MaxVersion: ver.version,
6227 Certificates: []Certificate{emptySCTCert},
6228 },
6229 flags: []string{
6230 "-enable-signed-cert-timestamps",
6231 },
David Benjamina5022392017-07-10 17:40:39 -04006232 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006233 shouldFail: true,
6234 expectedError: ":ERROR_PARSING_EXTENSION:",
6235 })
6236
David Benjamin53210cb2016-11-16 09:01:48 +09006237 // Test that certificate-related extensions are not sent unsolicited.
6238 testCases = append(testCases, testCase{
6239 testType: serverTest,
6240 name: "UnsolicitedCertificateExtensions-" + ver.name,
6241 config: Config{
6242 MaxVersion: ver.version,
6243 Bugs: ProtocolBugs{
6244 NoOCSPStapling: true,
6245 NoSignedCertificateTimestamps: true,
6246 },
6247 },
David Benjamina5022392017-07-10 17:40:39 -04006248 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006249 flags: []string{
6250 "-ocsp-response",
6251 base64.StdEncoding.EncodeToString(testOCSPResponse),
6252 "-signed-cert-timestamps",
6253 base64.StdEncoding.EncodeToString(testSCTList),
6254 },
6255 })
David Benjamin97d17d92016-07-14 16:12:00 -04006256 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006257
Paul Lietar4fac72e2015-09-09 13:44:55 +01006258 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006259 testType: clientTest,
6260 name: "ClientHelloPadding",
6261 config: Config{
6262 Bugs: ProtocolBugs{
6263 RequireClientHelloSize: 512,
6264 },
6265 },
6266 // This hostname just needs to be long enough to push the
6267 // ClientHello into F5's danger zone between 256 and 511 bytes
6268 // long.
6269 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6270 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006271
6272 // Extensions should not function in SSL 3.0.
6273 testCases = append(testCases, testCase{
6274 testType: serverTest,
6275 name: "SSLv3Extensions-NoALPN",
6276 config: Config{
6277 MaxVersion: VersionSSL30,
6278 NextProtos: []string{"foo", "bar", "baz"},
6279 },
6280 flags: []string{
6281 "-select-alpn", "foo",
6282 },
6283 expectNoNextProto: true,
6284 })
6285
6286 // Test session tickets separately as they follow a different codepath.
6287 testCases = append(testCases, testCase{
6288 testType: serverTest,
6289 name: "SSLv3Extensions-NoTickets",
6290 config: Config{
6291 MaxVersion: VersionSSL30,
6292 Bugs: ProtocolBugs{
6293 // Historically, session tickets in SSL 3.0
6294 // failed in different ways depending on whether
6295 // the client supported renegotiation_info.
6296 NoRenegotiationInfo: true,
6297 },
6298 },
6299 resumeSession: true,
6300 })
6301 testCases = append(testCases, testCase{
6302 testType: serverTest,
6303 name: "SSLv3Extensions-NoTickets2",
6304 config: Config{
6305 MaxVersion: VersionSSL30,
6306 },
6307 resumeSession: true,
6308 })
6309
6310 // But SSL 3.0 does send and process renegotiation_info.
6311 testCases = append(testCases, testCase{
6312 testType: serverTest,
6313 name: "SSLv3Extensions-RenegotiationInfo",
6314 config: Config{
6315 MaxVersion: VersionSSL30,
6316 Bugs: ProtocolBugs{
6317 RequireRenegotiationInfo: true,
6318 },
6319 },
David Benjamind2610042017-01-03 10:49:28 -05006320 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006321 })
6322 testCases = append(testCases, testCase{
6323 testType: serverTest,
6324 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6325 config: Config{
6326 MaxVersion: VersionSSL30,
6327 Bugs: ProtocolBugs{
6328 NoRenegotiationInfo: true,
6329 SendRenegotiationSCSV: true,
6330 RequireRenegotiationInfo: true,
6331 },
6332 },
David Benjamind2610042017-01-03 10:49:28 -05006333 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006334 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006335
6336 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6337 // in ServerHello.
6338 testCases = append(testCases, testCase{
6339 name: "NPN-Forbidden-TLS13",
6340 config: Config{
6341 MaxVersion: VersionTLS13,
6342 NextProtos: []string{"foo"},
6343 Bugs: ProtocolBugs{
6344 NegotiateNPNAtAllVersions: true,
6345 },
6346 },
6347 flags: []string{"-select-next-proto", "foo"},
6348 shouldFail: true,
6349 expectedError: ":ERROR_PARSING_EXTENSION:",
6350 })
6351 testCases = append(testCases, testCase{
6352 name: "EMS-Forbidden-TLS13",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 Bugs: ProtocolBugs{
6356 NegotiateEMSAtAllVersions: true,
6357 },
6358 },
6359 shouldFail: true,
6360 expectedError: ":ERROR_PARSING_EXTENSION:",
6361 })
6362 testCases = append(testCases, testCase{
6363 name: "RenegotiationInfo-Forbidden-TLS13",
6364 config: Config{
6365 MaxVersion: VersionTLS13,
6366 Bugs: ProtocolBugs{
6367 NegotiateRenegotiationInfoAtAllVersions: true,
6368 },
6369 },
6370 shouldFail: true,
6371 expectedError: ":ERROR_PARSING_EXTENSION:",
6372 })
6373 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006374 name: "Ticket-Forbidden-TLS13",
6375 config: Config{
6376 MaxVersion: VersionTLS12,
6377 },
6378 resumeConfig: &Config{
6379 MaxVersion: VersionTLS13,
6380 Bugs: ProtocolBugs{
6381 AdvertiseTicketExtension: true,
6382 },
6383 },
6384 resumeSession: true,
6385 shouldFail: true,
6386 expectedError: ":ERROR_PARSING_EXTENSION:",
6387 })
6388
6389 // Test that illegal extensions in TLS 1.3 are declined by the server if
6390 // offered in ClientHello. The runner's server will fail if this occurs,
6391 // so we exercise the offering path. (EMS and Renegotiation Info are
6392 // implicit in every test.)
6393 testCases = append(testCases, testCase{
6394 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006395 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006396 config: Config{
6397 MaxVersion: VersionTLS13,
6398 NextProtos: []string{"bar"},
6399 },
6400 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6401 })
David Benjamin196df5b2016-09-21 16:23:27 -04006402
David Benjamindaa88502016-10-04 16:32:16 -04006403 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6404 // tolerated.
6405 testCases = append(testCases, testCase{
6406 name: "SendOCSPResponseOnResume-TLS12",
6407 config: Config{
6408 MaxVersion: VersionTLS12,
6409 Bugs: ProtocolBugs{
6410 SendOCSPResponseOnResume: []byte("bogus"),
6411 },
6412 },
6413 flags: []string{
6414 "-enable-ocsp-stapling",
6415 "-expect-ocsp-response",
6416 base64.StdEncoding.EncodeToString(testOCSPResponse),
6417 },
6418 resumeSession: true,
6419 })
6420
David Benjamindaa88502016-10-04 16:32:16 -04006421 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006422 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006423 config: Config{
6424 MaxVersion: VersionTLS13,
6425 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006426 SendExtensionOnCertificate: testOCSPExtension,
6427 },
6428 },
6429 shouldFail: true,
6430 expectedError: ":UNEXPECTED_EXTENSION:",
6431 })
6432
6433 testCases = append(testCases, testCase{
6434 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6435 config: Config{
6436 MaxVersion: VersionTLS13,
6437 Bugs: ProtocolBugs{
6438 SendExtensionOnCertificate: testSCTExtension,
6439 },
6440 },
6441 shouldFail: true,
6442 expectedError: ":UNEXPECTED_EXTENSION:",
6443 })
6444
6445 // Test that extensions on client certificates are never accepted.
6446 testCases = append(testCases, testCase{
6447 name: "SendExtensionOnClientCertificate-TLS13",
6448 testType: serverTest,
6449 config: Config{
6450 MaxVersion: VersionTLS13,
6451 Certificates: []Certificate{rsaCertificate},
6452 Bugs: ProtocolBugs{
6453 SendExtensionOnCertificate: testOCSPExtension,
6454 },
6455 },
6456 flags: []string{
6457 "-enable-ocsp-stapling",
6458 "-require-any-client-certificate",
6459 },
6460 shouldFail: true,
6461 expectedError: ":UNEXPECTED_EXTENSION:",
6462 })
6463
6464 testCases = append(testCases, testCase{
6465 name: "SendUnknownExtensionOnCertificate-TLS13",
6466 config: Config{
6467 MaxVersion: VersionTLS13,
6468 Bugs: ProtocolBugs{
6469 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6470 },
6471 },
6472 shouldFail: true,
6473 expectedError: ":UNEXPECTED_EXTENSION:",
6474 })
6475
Adam Langleycfa08c32016-11-17 13:21:27 -08006476 var differentSCTList []byte
6477 differentSCTList = append(differentSCTList, testSCTList...)
6478 differentSCTList[len(differentSCTList)-1] ^= 1
6479
Steven Valdeza833c352016-11-01 13:39:36 -04006480 // Test that extensions on intermediates are allowed but ignored.
6481 testCases = append(testCases, testCase{
6482 name: "IgnoreExtensionsOnIntermediates-TLS13",
6483 config: Config{
6484 MaxVersion: VersionTLS13,
6485 Certificates: []Certificate{rsaChainCertificate},
6486 Bugs: ProtocolBugs{
6487 // Send different values on the intermediate. This tests
6488 // the intermediate's extensions do not override the
6489 // leaf's.
6490 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006491 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006492 },
6493 },
6494 flags: []string{
6495 "-enable-ocsp-stapling",
6496 "-expect-ocsp-response",
6497 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006498 "-enable-signed-cert-timestamps",
6499 "-expect-signed-cert-timestamps",
6500 base64.StdEncoding.EncodeToString(testSCTList),
6501 },
6502 resumeSession: true,
6503 })
6504
6505 // Test that extensions are not sent on intermediates when configured
6506 // only for a leaf.
6507 testCases = append(testCases, testCase{
6508 testType: serverTest,
6509 name: "SendNoExtensionsOnIntermediate-TLS13",
6510 config: Config{
6511 MaxVersion: VersionTLS13,
6512 Bugs: ProtocolBugs{
6513 ExpectNoExtensionsOnIntermediate: true,
6514 },
6515 },
6516 flags: []string{
6517 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6518 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6519 "-ocsp-response",
6520 base64.StdEncoding.EncodeToString(testOCSPResponse),
6521 "-signed-cert-timestamps",
6522 base64.StdEncoding.EncodeToString(testSCTList),
6523 },
6524 })
6525
6526 // Test that extensions are not sent on client certificates.
6527 testCases = append(testCases, testCase{
6528 name: "SendNoClientCertificateExtensions-TLS13",
6529 config: Config{
6530 MaxVersion: VersionTLS13,
6531 ClientAuth: RequireAnyClientCert,
6532 },
6533 flags: []string{
6534 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6535 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6536 "-ocsp-response",
6537 base64.StdEncoding.EncodeToString(testOCSPResponse),
6538 "-signed-cert-timestamps",
6539 base64.StdEncoding.EncodeToString(testSCTList),
6540 },
6541 })
6542
6543 testCases = append(testCases, testCase{
6544 name: "SendDuplicateExtensionsOnCerts-TLS13",
6545 config: Config{
6546 MaxVersion: VersionTLS13,
6547 Bugs: ProtocolBugs{
6548 SendDuplicateCertExtensions: true,
6549 },
6550 },
6551 flags: []string{
6552 "-enable-ocsp-stapling",
6553 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006554 },
6555 resumeSession: true,
6556 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006557 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006558 })
Adam Langley9b885c52016-11-18 14:21:03 -08006559
6560 testCases = append(testCases, testCase{
6561 name: "SignedCertificateTimestampListInvalid-Server",
6562 testType: serverTest,
6563 flags: []string{
6564 "-signed-cert-timestamps",
6565 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6566 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006567 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006568 expectedError: ":INVALID_SCT_LIST:",
6569 })
David Benjamine78bfde2014-09-06 12:45:15 -04006570}
6571
David Benjamin01fe8202014-09-24 15:21:44 -04006572func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006573 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006574 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006575 // SSL 3.0 does not have tickets and TLS 1.3 does not
6576 // have session IDs, so skip their cross-resumption
6577 // tests.
6578 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6579 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6580 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006581 }
6582
David Benjamin8b8c0062014-11-23 02:47:52 -05006583 protocols := []protocol{tls}
6584 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6585 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006586 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006587 for _, protocol := range protocols {
6588 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6589 if protocol == dtls {
6590 suffix += "-DTLS"
6591 }
6592
Steven Valdez520e1222017-06-13 12:45:25 -04006593 // We can't resume across TLS 1.3 variants and error out earlier in the
6594 // session resumption.
6595 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6596 continue
6597 }
6598
David Benjaminece3de92015-03-16 18:02:20 -04006599 if sessionVers.version == resumeVers.version {
6600 testCases = append(testCases, testCase{
6601 protocol: protocol,
6602 name: "Resume-Client" + suffix,
6603 resumeSession: true,
6604 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: sessionVers.version,
6606 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006607 Bugs: ProtocolBugs{
6608 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6609 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6610 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006611 },
David Benjaminece3de92015-03-16 18:02:20 -04006612 expectedVersion: sessionVers.version,
6613 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006614 flags: []string{
6615 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6616 },
David Benjaminece3de92015-03-16 18:02:20 -04006617 })
6618 } else {
David Benjamin405da482016-08-08 17:25:07 -04006619 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6620
6621 // Offering a TLS 1.3 session sends an empty session ID, so
6622 // there is no way to convince a non-lookahead client the
6623 // session was resumed. It will appear to the client that a
6624 // stray ChangeCipherSpec was sent.
6625 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6626 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006627 }
6628
David Benjaminece3de92015-03-16 18:02:20 -04006629 testCases = append(testCases, testCase{
6630 protocol: protocol,
6631 name: "Resume-Client-Mismatch" + suffix,
6632 resumeSession: true,
6633 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006634 MaxVersion: sessionVers.version,
6635 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006636 },
David Benjaminece3de92015-03-16 18:02:20 -04006637 expectedVersion: sessionVers.version,
6638 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006639 MaxVersion: resumeVers.version,
6640 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006641 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006642 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006643 },
6644 },
6645 expectedResumeVersion: resumeVers.version,
6646 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006647 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006648 flags: []string{
6649 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6650 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6651 },
David Benjaminece3de92015-03-16 18:02:20 -04006652 })
6653 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006654
6655 testCases = append(testCases, testCase{
6656 protocol: protocol,
6657 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006658 resumeSession: true,
6659 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006660 MaxVersion: sessionVers.version,
6661 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006662 },
6663 expectedVersion: sessionVers.version,
6664 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006665 MaxVersion: resumeVers.version,
6666 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006667 },
6668 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006669 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006670 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006671 flags: []string{
6672 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6673 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6674 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006675 })
6676
David Benjamin8b8c0062014-11-23 02:47:52 -05006677 testCases = append(testCases, testCase{
6678 protocol: protocol,
6679 testType: serverTest,
6680 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006681 resumeSession: true,
6682 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006683 MaxVersion: sessionVers.version,
6684 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006685 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006686 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006687 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006688 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006689 MaxVersion: resumeVers.version,
6690 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006691 Bugs: ProtocolBugs{
6692 SendBothTickets: true,
6693 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006694 },
6695 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006696 flags: []string{
6697 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6698 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6699 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006700 })
6701 }
David Benjamin01fe8202014-09-24 15:21:44 -04006702 }
6703 }
David Benjaminece3de92015-03-16 18:02:20 -04006704
David Benjamin4199b0d2016-11-01 13:58:25 -04006705 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006706 testCases = append(testCases, testCase{
6707 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006708 name: "ShimTicketRewritable",
6709 resumeSession: true,
6710 config: Config{
6711 MaxVersion: VersionTLS12,
6712 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6713 Bugs: ProtocolBugs{
6714 FilterTicket: func(in []byte) ([]byte, error) {
6715 in, err := SetShimTicketVersion(in, VersionTLS12)
6716 if err != nil {
6717 return nil, err
6718 }
6719 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6720 },
6721 },
6722 },
6723 flags: []string{
6724 "-ticket-key",
6725 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6726 },
6727 })
6728
6729 // Resumptions are declined if the version does not match.
6730 testCases = append(testCases, testCase{
6731 testType: serverTest,
6732 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006733 resumeSession: true,
6734 config: Config{
6735 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006736 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006737 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006738 FilterTicket: func(in []byte) ([]byte, error) {
6739 return SetShimTicketVersion(in, VersionTLS13)
6740 },
6741 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006742 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006743 flags: []string{
6744 "-ticket-key",
6745 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6746 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006747 expectResumeRejected: true,
6748 })
6749
6750 testCases = append(testCases, testCase{
6751 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006752 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006753 resumeSession: true,
6754 config: Config{
6755 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006756 Bugs: ProtocolBugs{
6757 FilterTicket: func(in []byte) ([]byte, error) {
6758 return SetShimTicketVersion(in, VersionTLS12)
6759 },
6760 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006761 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006762 flags: []string{
6763 "-ticket-key",
6764 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6765 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006766 expectResumeRejected: true,
6767 })
6768
David Benjamin4199b0d2016-11-01 13:58:25 -04006769 // Resumptions are declined if the cipher is invalid or disabled.
6770 testCases = append(testCases, testCase{
6771 testType: serverTest,
6772 name: "Resume-Server-DeclineBadCipher",
6773 resumeSession: true,
6774 config: Config{
6775 MaxVersion: VersionTLS12,
6776 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006777 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006778 FilterTicket: func(in []byte) ([]byte, error) {
6779 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6780 },
6781 },
6782 },
6783 flags: []string{
6784 "-ticket-key",
6785 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6786 },
6787 expectResumeRejected: true,
6788 })
6789
6790 testCases = append(testCases, testCase{
6791 testType: serverTest,
6792 name: "Resume-Server-DeclineBadCipher-2",
6793 resumeSession: true,
6794 config: Config{
6795 MaxVersion: VersionTLS12,
6796 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006797 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006798 FilterTicket: func(in []byte) ([]byte, error) {
6799 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6800 },
6801 },
6802 },
6803 flags: []string{
6804 "-cipher", "AES128",
6805 "-ticket-key",
6806 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6807 },
6808 expectResumeRejected: true,
6809 })
6810
David Benjaminf01f42a2016-11-16 19:05:33 +09006811 // Sessions are not resumed if they do not use the preferred cipher.
6812 testCases = append(testCases, testCase{
6813 testType: serverTest,
6814 name: "Resume-Server-CipherNotPreferred",
6815 resumeSession: true,
6816 config: Config{
6817 MaxVersion: VersionTLS12,
6818 Bugs: ProtocolBugs{
6819 ExpectNewTicket: true,
6820 FilterTicket: func(in []byte) ([]byte, error) {
6821 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6822 },
6823 },
6824 },
6825 flags: []string{
6826 "-ticket-key",
6827 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6828 },
6829 shouldFail: false,
6830 expectResumeRejected: true,
6831 })
6832
6833 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6834 // PRF hashes match, but BoringSSL will always decline such resumptions.
6835 testCases = append(testCases, testCase{
6836 testType: serverTest,
6837 name: "Resume-Server-CipherNotPreferred-TLS13",
6838 resumeSession: true,
6839 config: Config{
6840 MaxVersion: VersionTLS13,
6841 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6842 Bugs: ProtocolBugs{
6843 FilterTicket: func(in []byte) ([]byte, error) {
6844 // If the client (runner) offers ChaCha20-Poly1305 first, the
6845 // server (shim) always prefers it. Switch it to AES-GCM.
6846 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6847 },
6848 },
6849 },
6850 flags: []string{
6851 "-ticket-key",
6852 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6853 },
6854 shouldFail: false,
6855 expectResumeRejected: true,
6856 })
6857
6858 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006859 testCases = append(testCases, testCase{
6860 testType: serverTest,
6861 name: "Resume-Server-DeclineBadCipher-TLS13",
6862 resumeSession: true,
6863 config: Config{
6864 MaxVersion: VersionTLS13,
6865 Bugs: ProtocolBugs{
6866 FilterTicket: func(in []byte) ([]byte, error) {
6867 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6868 },
6869 },
6870 },
6871 flags: []string{
6872 "-ticket-key",
6873 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6874 },
6875 expectResumeRejected: true,
6876 })
6877
David Benjaminf01f42a2016-11-16 19:05:33 +09006878 // If the client does not offer the cipher from the session, decline to
6879 // resume. Clients are forbidden from doing this, but BoringSSL selects
6880 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006881 testCases = append(testCases, testCase{
6882 testType: serverTest,
6883 name: "Resume-Server-UnofferedCipher",
6884 resumeSession: true,
6885 config: Config{
6886 MaxVersion: VersionTLS12,
6887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6888 },
6889 resumeConfig: &Config{
6890 MaxVersion: VersionTLS12,
6891 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6892 Bugs: ProtocolBugs{
6893 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6894 },
6895 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006896 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006897 })
6898
David Benjaminf01f42a2016-11-16 19:05:33 +09006899 // In TLS 1.3, clients may advertise a cipher list which does not
6900 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006901 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6902 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: "Resume-Server-UnofferedCipher-TLS13",
6906 resumeSession: true,
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6910 },
6911 resumeConfig: &Config{
6912 MaxVersion: VersionTLS13,
6913 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6914 Bugs: ProtocolBugs{
6915 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6916 },
6917 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006918 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006919 })
6920
David Benjamin4199b0d2016-11-01 13:58:25 -04006921 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006922 testCases = append(testCases, testCase{
6923 name: "Resume-Client-CipherMismatch",
6924 resumeSession: true,
6925 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006926 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006927 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6928 },
6929 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006930 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006931 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6932 Bugs: ProtocolBugs{
6933 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6934 },
6935 },
6936 shouldFail: true,
6937 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6938 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006939
David Benjamine1cc35e2016-11-16 16:25:58 +09006940 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6941 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006942 testCases = append(testCases, testCase{
6943 name: "Resume-Client-CipherMismatch-TLS13",
6944 resumeSession: true,
6945 config: Config{
6946 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006947 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006948 },
6949 resumeConfig: &Config{
6950 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006951 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6952 },
6953 })
6954
6955 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6956 testCases = append(testCases, testCase{
6957 name: "Resume-Client-PRFMismatch-TLS13",
6958 resumeSession: true,
6959 config: Config{
6960 MaxVersion: VersionTLS13,
6961 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6962 },
6963 resumeConfig: &Config{
6964 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006965 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006966 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006967 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006968 },
6969 },
6970 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006971 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006972 })
Steven Valdeza833c352016-11-01 13:39:36 -04006973
6974 testCases = append(testCases, testCase{
6975 testType: serverTest,
6976 name: "Resume-Server-BinderWrongLength",
6977 resumeSession: true,
6978 config: Config{
6979 MaxVersion: VersionTLS13,
6980 Bugs: ProtocolBugs{
6981 SendShortPSKBinder: true,
6982 },
6983 },
6984 shouldFail: true,
6985 expectedLocalError: "remote error: error decrypting message",
6986 expectedError: ":DIGEST_CHECK_FAILED:",
6987 })
6988
6989 testCases = append(testCases, testCase{
6990 testType: serverTest,
6991 name: "Resume-Server-NoPSKBinder",
6992 resumeSession: true,
6993 config: Config{
6994 MaxVersion: VersionTLS13,
6995 Bugs: ProtocolBugs{
6996 SendNoPSKBinder: true,
6997 },
6998 },
6999 shouldFail: true,
7000 expectedLocalError: "remote error: error decoding message",
7001 expectedError: ":DECODE_ERROR:",
7002 })
7003
7004 testCases = append(testCases, testCase{
7005 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05007006 name: "Resume-Server-ExtraPSKBinder",
7007 resumeSession: true,
7008 config: Config{
7009 MaxVersion: VersionTLS13,
7010 Bugs: ProtocolBugs{
7011 SendExtraPSKBinder: true,
7012 },
7013 },
7014 shouldFail: true,
7015 expectedLocalError: "remote error: illegal parameter",
7016 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7017 })
7018
7019 testCases = append(testCases, testCase{
7020 testType: serverTest,
7021 name: "Resume-Server-ExtraIdentityNoBinder",
7022 resumeSession: true,
7023 config: Config{
7024 MaxVersion: VersionTLS13,
7025 Bugs: ProtocolBugs{
7026 ExtraPSKIdentity: true,
7027 },
7028 },
7029 shouldFail: true,
7030 expectedLocalError: "remote error: illegal parameter",
7031 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7032 })
7033
7034 testCases = append(testCases, testCase{
7035 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007036 name: "Resume-Server-InvalidPSKBinder",
7037 resumeSession: true,
7038 config: Config{
7039 MaxVersion: VersionTLS13,
7040 Bugs: ProtocolBugs{
7041 SendInvalidPSKBinder: true,
7042 },
7043 },
7044 shouldFail: true,
7045 expectedLocalError: "remote error: error decrypting message",
7046 expectedError: ":DIGEST_CHECK_FAILED:",
7047 })
7048
7049 testCases = append(testCases, testCase{
7050 testType: serverTest,
7051 name: "Resume-Server-PSKBinderFirstExtension",
7052 resumeSession: true,
7053 config: Config{
7054 MaxVersion: VersionTLS13,
7055 Bugs: ProtocolBugs{
7056 PSKBinderFirst: true,
7057 },
7058 },
7059 shouldFail: true,
7060 expectedLocalError: "remote error: illegal parameter",
7061 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7062 })
David Benjamin01fe8202014-09-24 15:21:44 -04007063}
7064
Adam Langley2ae77d22014-10-28 17:29:33 -07007065func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007066 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007067 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007068 testType: serverTest,
7069 name: "Renegotiate-Server-Forbidden",
7070 config: Config{
7071 MaxVersion: VersionTLS12,
7072 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007073 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007074 shouldFail: true,
7075 expectedError: ":NO_RENEGOTIATION:",
7076 expectedLocalError: "remote error: no renegotiation",
7077 })
Adam Langley5021b222015-06-12 18:27:58 -07007078 // The server shouldn't echo the renegotiation extension unless
7079 // requested by the client.
7080 testCases = append(testCases, testCase{
7081 testType: serverTest,
7082 name: "Renegotiate-Server-NoExt",
7083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007084 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007085 Bugs: ProtocolBugs{
7086 NoRenegotiationInfo: true,
7087 RequireRenegotiationInfo: true,
7088 },
7089 },
7090 shouldFail: true,
7091 expectedLocalError: "renegotiation extension missing",
7092 })
7093 // The renegotiation SCSV should be sufficient for the server to echo
7094 // the extension.
7095 testCases = append(testCases, testCase{
7096 testType: serverTest,
7097 name: "Renegotiate-Server-NoExt-SCSV",
7098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007099 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007100 Bugs: ProtocolBugs{
7101 NoRenegotiationInfo: true,
7102 SendRenegotiationSCSV: true,
7103 RequireRenegotiationInfo: true,
7104 },
7105 },
7106 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007107 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007108 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007110 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007111 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007112 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007113 },
7114 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007115 renegotiate: 1,
7116 flags: []string{
7117 "-renegotiate-freely",
7118 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007119 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007120 },
David Benjamincdea40c2015-03-19 14:09:43 -04007121 })
7122 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007123 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007124 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007126 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 Bugs: ProtocolBugs{
7128 EmptyRenegotiationInfo: true,
7129 },
7130 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007131 flags: []string{"-renegotiate-freely"},
7132 shouldFail: true,
7133 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007134 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007135 })
7136 testCases = append(testCases, testCase{
7137 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007138 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007140 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007141 Bugs: ProtocolBugs{
7142 BadRenegotiationInfo: true,
7143 },
7144 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007145 flags: []string{"-renegotiate-freely"},
7146 shouldFail: true,
7147 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007148 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007149 })
7150 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007151 name: "Renegotiate-Client-BadExt2",
7152 renegotiate: 1,
7153 config: Config{
7154 MaxVersion: VersionTLS12,
7155 Bugs: ProtocolBugs{
7156 BadRenegotiationInfoEnd: true,
7157 },
7158 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007159 flags: []string{"-renegotiate-freely"},
7160 shouldFail: true,
7161 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007162 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007163 })
7164 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007165 name: "Renegotiate-Client-Downgrade",
7166 renegotiate: 1,
7167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007168 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007169 Bugs: ProtocolBugs{
7170 NoRenegotiationInfoAfterInitial: true,
7171 },
7172 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007173 flags: []string{"-renegotiate-freely"},
7174 shouldFail: true,
7175 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007176 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007177 })
7178 testCases = append(testCases, testCase{
7179 name: "Renegotiate-Client-Upgrade",
7180 renegotiate: 1,
7181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007182 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007183 Bugs: ProtocolBugs{
7184 NoRenegotiationInfoInInitial: true,
7185 },
7186 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007187 flags: []string{"-renegotiate-freely"},
7188 shouldFail: true,
7189 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007190 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007191 })
7192 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007193 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007194 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007197 Bugs: ProtocolBugs{
7198 NoRenegotiationInfo: true,
7199 },
7200 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007201 flags: []string{
7202 "-renegotiate-freely",
7203 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007204 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007205 },
David Benjamincff0b902015-05-15 23:09:47 -04007206 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007207
7208 // Test that the server may switch ciphers on renegotiation without
7209 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007210 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007211 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007212 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007213 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007214 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007215 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007216 },
7217 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007218 flags: []string{
7219 "-renegotiate-freely",
7220 "-expect-total-renegotiations", "1",
7221 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007222 })
7223 testCases = append(testCases, testCase{
7224 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007225 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007227 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007228 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7229 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007230 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007231 flags: []string{
7232 "-renegotiate-freely",
7233 "-expect-total-renegotiations", "1",
7234 },
David Benjaminb16346b2015-04-08 19:16:58 -04007235 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007236
7237 // Test that the server may not switch versions on renegotiation.
7238 testCases = append(testCases, testCase{
7239 name: "Renegotiate-Client-SwitchVersion",
7240 config: Config{
7241 MaxVersion: VersionTLS12,
7242 // Pick a cipher which exists at both versions.
7243 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7244 Bugs: ProtocolBugs{
7245 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007246 // Avoid failing early at the record layer.
7247 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007248 },
7249 },
7250 renegotiate: 1,
7251 flags: []string{
7252 "-renegotiate-freely",
7253 "-expect-total-renegotiations", "1",
7254 },
7255 shouldFail: true,
7256 expectedError: ":WRONG_SSL_VERSION:",
7257 })
7258
David Benjaminb16346b2015-04-08 19:16:58 -04007259 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007260 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007261 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007262 config: Config{
7263 MaxVersion: VersionTLS10,
7264 Bugs: ProtocolBugs{
7265 RequireSameRenegoClientVersion: true,
7266 },
7267 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007268 flags: []string{
7269 "-renegotiate-freely",
7270 "-expect-total-renegotiations", "1",
7271 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007272 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007273 testCases = append(testCases, testCase{
7274 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007275 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007276 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007277 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007278 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7279 NextProtos: []string{"foo"},
7280 },
7281 flags: []string{
7282 "-false-start",
7283 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007284 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007285 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007286 },
7287 shimWritesFirst: true,
7288 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007289
7290 // Client-side renegotiation controls.
7291 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007292 name: "Renegotiate-Client-Forbidden-1",
7293 config: Config{
7294 MaxVersion: VersionTLS12,
7295 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007296 renegotiate: 1,
7297 shouldFail: true,
7298 expectedError: ":NO_RENEGOTIATION:",
7299 expectedLocalError: "remote error: no renegotiation",
7300 })
7301 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007302 name: "Renegotiate-Client-Once-1",
7303 config: Config{
7304 MaxVersion: VersionTLS12,
7305 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007306 renegotiate: 1,
7307 flags: []string{
7308 "-renegotiate-once",
7309 "-expect-total-renegotiations", "1",
7310 },
7311 })
7312 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007313 name: "Renegotiate-Client-Freely-1",
7314 config: Config{
7315 MaxVersion: VersionTLS12,
7316 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007317 renegotiate: 1,
7318 flags: []string{
7319 "-renegotiate-freely",
7320 "-expect-total-renegotiations", "1",
7321 },
7322 })
7323 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007324 name: "Renegotiate-Client-Once-2",
7325 config: Config{
7326 MaxVersion: VersionTLS12,
7327 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007328 renegotiate: 2,
7329 flags: []string{"-renegotiate-once"},
7330 shouldFail: true,
7331 expectedError: ":NO_RENEGOTIATION:",
7332 expectedLocalError: "remote error: no renegotiation",
7333 })
7334 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007335 name: "Renegotiate-Client-Freely-2",
7336 config: Config{
7337 MaxVersion: VersionTLS12,
7338 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007339 renegotiate: 2,
7340 flags: []string{
7341 "-renegotiate-freely",
7342 "-expect-total-renegotiations", "2",
7343 },
7344 })
Adam Langley27a0d082015-11-03 13:34:10 -08007345 testCases = append(testCases, testCase{
7346 name: "Renegotiate-Client-NoIgnore",
7347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007349 Bugs: ProtocolBugs{
7350 SendHelloRequestBeforeEveryAppDataRecord: true,
7351 },
7352 },
7353 shouldFail: true,
7354 expectedError: ":NO_RENEGOTIATION:",
7355 })
7356 testCases = append(testCases, testCase{
7357 name: "Renegotiate-Client-Ignore",
7358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007359 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007360 Bugs: ProtocolBugs{
7361 SendHelloRequestBeforeEveryAppDataRecord: true,
7362 },
7363 },
7364 flags: []string{
7365 "-renegotiate-ignore",
7366 "-expect-total-renegotiations", "0",
7367 },
7368 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007369
David Benjamin34941c02016-10-08 11:45:31 -04007370 // Renegotiation is not allowed at SSL 3.0.
7371 testCases = append(testCases, testCase{
7372 name: "Renegotiate-Client-SSL3",
7373 config: Config{
7374 MaxVersion: VersionSSL30,
7375 },
7376 renegotiate: 1,
7377 flags: []string{
7378 "-renegotiate-freely",
7379 "-expect-total-renegotiations", "1",
7380 },
7381 shouldFail: true,
7382 expectedError: ":NO_RENEGOTIATION:",
7383 expectedLocalError: "remote error: no renegotiation",
7384 })
7385
David Benjamina1eaba12017-01-01 23:19:22 -05007386 // Renegotiation is not allowed when there is an unfinished write.
7387 testCases = append(testCases, testCase{
7388 name: "Renegotiate-Client-UnfinishedWrite",
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 },
David Benjaminbbba9392017-04-06 12:54:12 -04007392 renegotiate: 1,
7393 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007394 flags: []string{
7395 "-async",
7396 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007397 },
7398 shouldFail: true,
7399 expectedError: ":NO_RENEGOTIATION:",
7400 // We do not successfully send the no_renegotiation alert in
7401 // this case. https://crbug.com/boringssl/130
7402 })
7403
David Benjamin07ab5d42017-02-09 20:11:41 -05007404 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007405 testCases = append(testCases, testCase{
7406 name: "StrayHelloRequest",
7407 config: Config{
7408 MaxVersion: VersionTLS12,
7409 Bugs: ProtocolBugs{
7410 SendHelloRequestBeforeEveryHandshakeMessage: true,
7411 },
7412 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007415 })
7416 testCases = append(testCases, testCase{
7417 name: "StrayHelloRequest-Packed",
7418 config: Config{
7419 MaxVersion: VersionTLS12,
7420 Bugs: ProtocolBugs{
7421 PackHandshakeFlight: true,
7422 SendHelloRequestBeforeEveryHandshakeMessage: true,
7423 },
7424 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007425 shouldFail: true,
7426 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007427 })
7428
David Benjamin12d2c482016-07-24 10:56:51 -04007429 // Test renegotiation works if HelloRequest and server Finished come in
7430 // the same record.
7431 testCases = append(testCases, testCase{
7432 name: "Renegotiate-Client-Packed",
7433 config: Config{
7434 MaxVersion: VersionTLS12,
7435 Bugs: ProtocolBugs{
7436 PackHandshakeFlight: true,
7437 PackHelloRequestWithFinished: true,
7438 },
7439 },
7440 renegotiate: 1,
7441 flags: []string{
7442 "-renegotiate-freely",
7443 "-expect-total-renegotiations", "1",
7444 },
7445 })
7446
David Benjamin397c8e62016-07-08 14:14:36 -07007447 // Renegotiation is forbidden in TLS 1.3.
7448 testCases = append(testCases, testCase{
7449 name: "Renegotiate-Client-TLS13",
7450 config: Config{
7451 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007452 Bugs: ProtocolBugs{
7453 SendHelloRequestBeforeEveryAppDataRecord: true,
7454 },
David Benjamin397c8e62016-07-08 14:14:36 -07007455 },
David Benjamin397c8e62016-07-08 14:14:36 -07007456 flags: []string{
7457 "-renegotiate-freely",
7458 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007459 shouldFail: true,
7460 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007461 })
7462
7463 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7464 testCases = append(testCases, testCase{
7465 name: "StrayHelloRequest-TLS13",
7466 config: Config{
7467 MaxVersion: VersionTLS13,
7468 Bugs: ProtocolBugs{
7469 SendHelloRequestBeforeEveryHandshakeMessage: true,
7470 },
7471 },
7472 shouldFail: true,
7473 expectedError: ":UNEXPECTED_MESSAGE:",
7474 })
David Benjamind2610042017-01-03 10:49:28 -05007475
7476 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7477 // always reads as supporting it, regardless of whether it was
7478 // negotiated.
7479 testCases = append(testCases, testCase{
7480 name: "AlwaysReportRenegotiationInfo-TLS13",
7481 config: Config{
7482 MaxVersion: VersionTLS13,
7483 Bugs: ProtocolBugs{
7484 NoRenegotiationInfo: true,
7485 },
7486 },
7487 flags: []string{
7488 "-expect-secure-renegotiation",
7489 },
7490 })
David Benjamina58baaf2017-02-28 20:54:28 -05007491
7492 // Certificates may not change on renegotiation.
7493 testCases = append(testCases, testCase{
7494 name: "Renegotiation-CertificateChange",
7495 config: Config{
7496 MaxVersion: VersionTLS12,
7497 Certificates: []Certificate{rsaCertificate},
7498 Bugs: ProtocolBugs{
7499 RenegotiationCertificate: &rsaChainCertificate,
7500 },
7501 },
7502 renegotiate: 1,
7503 flags: []string{"-renegotiate-freely"},
7504 shouldFail: true,
7505 expectedError: ":SERVER_CERT_CHANGED:",
7506 })
7507 testCases = append(testCases, testCase{
7508 name: "Renegotiation-CertificateChange-2",
7509 config: Config{
7510 MaxVersion: VersionTLS12,
7511 Certificates: []Certificate{rsaCertificate},
7512 Bugs: ProtocolBugs{
7513 RenegotiationCertificate: &rsa1024Certificate,
7514 },
7515 },
7516 renegotiate: 1,
7517 flags: []string{"-renegotiate-freely"},
7518 shouldFail: true,
7519 expectedError: ":SERVER_CERT_CHANGED:",
7520 })
David Benjaminbbf42462017-03-14 21:27:10 -04007521
7522 // We do not negotiate ALPN after the initial handshake. This is
7523 // error-prone and only risks bugs in consumers.
7524 testCases = append(testCases, testCase{
7525 testType: clientTest,
7526 name: "Renegotiation-ForbidALPN",
7527 config: Config{
7528 MaxVersion: VersionTLS12,
7529 Bugs: ProtocolBugs{
7530 // Forcibly negotiate ALPN on both initial and
7531 // renegotiation handshakes. The test stack will
7532 // internally check the client does not offer
7533 // it.
7534 SendALPN: "foo",
7535 },
7536 },
7537 flags: []string{
7538 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7539 "-expect-alpn", "foo",
7540 "-renegotiate-freely",
7541 },
7542 renegotiate: 1,
7543 shouldFail: true,
7544 expectedError: ":UNEXPECTED_EXTENSION:",
7545 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007546}
7547
David Benjamin5e961c12014-11-07 01:48:35 -05007548func addDTLSReplayTests() {
7549 // Test that sequence number replays are detected.
7550 testCases = append(testCases, testCase{
7551 protocol: dtls,
7552 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007553 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007554 replayWrites: true,
7555 })
7556
David Benjamin8e6db492015-07-25 18:29:23 -04007557 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007558 // than the retransmit window.
7559 testCases = append(testCases, testCase{
7560 protocol: dtls,
7561 name: "DTLS-Replay-LargeGaps",
7562 config: Config{
7563 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007564 SequenceNumberMapping: func(in uint64) uint64 {
7565 return in * 127
7566 },
David Benjamin5e961c12014-11-07 01:48:35 -05007567 },
7568 },
David Benjamin8e6db492015-07-25 18:29:23 -04007569 messageCount: 200,
7570 replayWrites: true,
7571 })
7572
7573 // Test the incoming sequence number changing non-monotonically.
7574 testCases = append(testCases, testCase{
7575 protocol: dtls,
7576 name: "DTLS-Replay-NonMonotonic",
7577 config: Config{
7578 Bugs: ProtocolBugs{
7579 SequenceNumberMapping: func(in uint64) uint64 {
7580 return in ^ 31
7581 },
7582 },
7583 },
7584 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007585 replayWrites: true,
7586 })
7587}
7588
Nick Harper60edffd2016-06-21 15:19:24 -07007589var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007590 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007591 id signatureAlgorithm
7592 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007593}{
Nick Harper60edffd2016-06-21 15:19:24 -07007594 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7595 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7596 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7597 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007598 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007599 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7600 // hash function doesn't have to match the curve and so the same
7601 // signature algorithm works with P-224.
7602 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007603 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7604 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7605 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007606 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7607 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7608 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007609 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007610 // Tests for key types prior to TLS 1.2.
7611 {"RSA", 0, testCertRSA},
7612 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007613}
7614
Nick Harper60edffd2016-06-21 15:19:24 -07007615const fakeSigAlg1 signatureAlgorithm = 0x2a01
7616const fakeSigAlg2 signatureAlgorithm = 0xff01
7617
7618func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007619 // Not all ciphers involve a signature. Advertise a list which gives all
7620 // versions a signing cipher.
7621 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007622 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007623 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7624 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7625 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7626 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007627 }
David Benjamin5208fd42016-07-13 21:43:25 -04007628
David Benjaminca3d5452016-07-14 12:51:01 -04007629 var allAlgorithms []signatureAlgorithm
7630 for _, alg := range testSignatureAlgorithms {
7631 if alg.id != 0 {
7632 allAlgorithms = append(allAlgorithms, alg.id)
7633 }
7634 }
7635
Nick Harper60edffd2016-06-21 15:19:24 -07007636 // Make sure each signature algorithm works. Include some fake values in
7637 // the list and ensure they're ignored.
7638 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007639 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007640 if (ver.version < VersionTLS12) != (alg.id == 0) {
7641 continue
7642 }
7643
7644 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7645 // or remove it in C.
7646 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007647 continue
7648 }
Nick Harper60edffd2016-06-21 15:19:24 -07007649
David Benjamin3ef76972016-10-17 17:59:54 -04007650 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007651 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007652 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007653 shouldSignFail = true
7654 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007655 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007656 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007657 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7658 shouldSignFail = true
7659 shouldVerifyFail = true
7660 }
7661 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7662 // the curve has to match the hash size.
7663 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007664 shouldSignFail = true
7665 shouldVerifyFail = true
7666 }
7667
7668 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7669 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7670 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007671 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007672
7673 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007674 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007675 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007676 }
7677 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007678 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007679 }
David Benjamin000800a2014-11-14 01:43:59 -05007680
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007682
David Benjamin7a41d372016-07-09 11:21:54 -07007683 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007684 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007685 config: Config{
7686 MaxVersion: ver.version,
7687 ClientAuth: RequireAnyClientCert,
7688 VerifySignatureAlgorithms: []signatureAlgorithm{
7689 fakeSigAlg1,
7690 alg.id,
7691 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007692 },
David Benjamin7a41d372016-07-09 11:21:54 -07007693 },
7694 flags: []string{
7695 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7696 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7697 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007698 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007699 },
David Benjamina5022392017-07-10 17:40:39 -04007700 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007701 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007702 expectedError: signError,
7703 expectedPeerSignatureAlgorithm: alg.id,
7704 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007705
David Benjamin7a41d372016-07-09 11:21:54 -07007706 testCases = append(testCases, testCase{
7707 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007708 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007709 config: Config{
7710 MaxVersion: ver.version,
7711 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7712 SignSignatureAlgorithms: []signatureAlgorithm{
7713 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007714 },
David Benjamin7a41d372016-07-09 11:21:54 -07007715 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007716 SkipECDSACurveCheck: shouldVerifyFail,
7717 IgnoreSignatureVersionChecks: shouldVerifyFail,
7718 // Some signature algorithms may not be advertised.
7719 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007720 },
David Benjamin7a41d372016-07-09 11:21:54 -07007721 },
David Benjamina5022392017-07-10 17:40:39 -04007722 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007723 flags: []string{
7724 "-require-any-client-certificate",
7725 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7726 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007727 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007728 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007729 // Resume the session to assert the peer signature
7730 // algorithm is reported on both handshakes.
7731 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007732 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007733 expectedError: verifyError,
7734 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007735
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007736 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007737 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007738 testCases = append(testCases, testCase{
7739 testType: serverTest,
7740 name: "ServerAuth-Sign" + suffix,
7741 config: Config{
7742 MaxVersion: ver.version,
7743 CipherSuites: signingCiphers,
7744 VerifySignatureAlgorithms: []signatureAlgorithm{
7745 fakeSigAlg1,
7746 alg.id,
7747 fakeSigAlg2,
7748 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007749 },
David Benjamina5022392017-07-10 17:40:39 -04007750 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007751 flags: []string{
7752 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7753 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7754 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007755 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007756 },
7757 shouldFail: shouldSignFail,
7758 expectedError: signError,
7759 expectedPeerSignatureAlgorithm: alg.id,
7760 })
7761 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007762
7763 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007764 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007765 config: Config{
7766 MaxVersion: ver.version,
7767 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007768 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007769 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007770 alg.id,
7771 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007772 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007773 SkipECDSACurveCheck: shouldVerifyFail,
7774 IgnoreSignatureVersionChecks: shouldVerifyFail,
7775 // Some signature algorithms may not be advertised.
7776 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007777 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007778 },
David Benjamina5022392017-07-10 17:40:39 -04007779 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007780 flags: []string{
7781 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7782 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007783 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007784 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007785 // Resume the session to assert the peer signature
7786 // algorithm is reported on both handshakes.
7787 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007788 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007789 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007790 })
David Benjamin5208fd42016-07-13 21:43:25 -04007791
David Benjamin3ef76972016-10-17 17:59:54 -04007792 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007793 testCases = append(testCases, testCase{
7794 testType: serverTest,
7795 name: "ClientAuth-InvalidSignature" + suffix,
7796 config: Config{
7797 MaxVersion: ver.version,
7798 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7799 SignSignatureAlgorithms: []signatureAlgorithm{
7800 alg.id,
7801 },
7802 Bugs: ProtocolBugs{
7803 InvalidSignature: true,
7804 },
7805 },
David Benjamina5022392017-07-10 17:40:39 -04007806 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007807 flags: []string{
7808 "-require-any-client-certificate",
7809 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007810 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007811 },
7812 shouldFail: true,
7813 expectedError: ":BAD_SIGNATURE:",
7814 })
7815
7816 testCases = append(testCases, testCase{
7817 name: "ServerAuth-InvalidSignature" + suffix,
7818 config: Config{
7819 MaxVersion: ver.version,
7820 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7821 CipherSuites: signingCiphers,
7822 SignSignatureAlgorithms: []signatureAlgorithm{
7823 alg.id,
7824 },
7825 Bugs: ProtocolBugs{
7826 InvalidSignature: true,
7827 },
7828 },
David Benjamina5022392017-07-10 17:40:39 -04007829 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007830 flags: []string{
7831 "-enable-all-curves",
7832 "-enable-ed25519",
7833 },
David Benjamin5208fd42016-07-13 21:43:25 -04007834 shouldFail: true,
7835 expectedError: ":BAD_SIGNATURE:",
7836 })
7837 }
David Benjaminca3d5452016-07-14 12:51:01 -04007838
David Benjamin3ef76972016-10-17 17:59:54 -04007839 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007840 testCases = append(testCases, testCase{
7841 name: "ClientAuth-Sign-Negotiate" + suffix,
7842 config: Config{
7843 MaxVersion: ver.version,
7844 ClientAuth: RequireAnyClientCert,
7845 VerifySignatureAlgorithms: allAlgorithms,
7846 },
David Benjamina5022392017-07-10 17:40:39 -04007847 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007848 flags: []string{
7849 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7850 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7851 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007852 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007853 "-signing-prefs", strconv.Itoa(int(alg.id)),
7854 },
7855 expectedPeerSignatureAlgorithm: alg.id,
7856 })
7857
7858 testCases = append(testCases, testCase{
7859 testType: serverTest,
7860 name: "ServerAuth-Sign-Negotiate" + suffix,
7861 config: Config{
7862 MaxVersion: ver.version,
7863 CipherSuites: signingCiphers,
7864 VerifySignatureAlgorithms: allAlgorithms,
7865 },
David Benjamina5022392017-07-10 17:40:39 -04007866 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007867 flags: []string{
7868 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7869 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7870 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007871 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007872 "-signing-prefs", strconv.Itoa(int(alg.id)),
7873 },
7874 expectedPeerSignatureAlgorithm: alg.id,
7875 })
7876 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007877 }
David Benjamin000800a2014-11-14 01:43:59 -05007878 }
7879
Nick Harper60edffd2016-06-21 15:19:24 -07007880 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007881 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007882 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007883 config: Config{
7884 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007885 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007886 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007887 signatureECDSAWithP521AndSHA512,
7888 signatureRSAPKCS1WithSHA384,
7889 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007890 },
7891 },
7892 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007893 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7894 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007895 },
Nick Harper60edffd2016-06-21 15:19:24 -07007896 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007897 })
7898
7899 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007900 name: "ClientAuth-SignatureType-TLS13",
7901 config: Config{
7902 ClientAuth: RequireAnyClientCert,
7903 MaxVersion: VersionTLS13,
7904 VerifySignatureAlgorithms: []signatureAlgorithm{
7905 signatureECDSAWithP521AndSHA512,
7906 signatureRSAPKCS1WithSHA384,
7907 signatureRSAPSSWithSHA384,
7908 signatureECDSAWithSHA1,
7909 },
7910 },
7911 flags: []string{
7912 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7913 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7914 },
7915 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7916 })
7917
7918 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007919 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007920 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007922 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007923 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007924 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007925 signatureECDSAWithP521AndSHA512,
7926 signatureRSAPKCS1WithSHA384,
7927 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007928 },
7929 },
Nick Harper60edffd2016-06-21 15:19:24 -07007930 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007931 })
7932
Steven Valdez143e8b32016-07-11 13:19:03 -04007933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "ServerAuth-SignatureType-TLS13",
7936 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007937 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007938 VerifySignatureAlgorithms: []signatureAlgorithm{
7939 signatureECDSAWithP521AndSHA512,
7940 signatureRSAPKCS1WithSHA384,
7941 signatureRSAPSSWithSHA384,
7942 signatureECDSAWithSHA1,
7943 },
7944 },
7945 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7946 })
7947
David Benjamina95e9f32016-07-08 16:28:04 -07007948 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007949 testCases = append(testCases, testCase{
7950 testType: serverTest,
7951 name: "Verify-ClientAuth-SignatureType",
7952 config: Config{
7953 MaxVersion: VersionTLS12,
7954 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007955 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007956 signatureRSAPKCS1WithSHA256,
7957 },
7958 Bugs: ProtocolBugs{
7959 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7960 },
7961 },
7962 flags: []string{
7963 "-require-any-client-certificate",
7964 },
7965 shouldFail: true,
7966 expectedError: ":WRONG_SIGNATURE_TYPE:",
7967 })
7968
7969 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007970 testType: serverTest,
7971 name: "Verify-ClientAuth-SignatureType-TLS13",
7972 config: Config{
7973 MaxVersion: VersionTLS13,
7974 Certificates: []Certificate{rsaCertificate},
7975 SignSignatureAlgorithms: []signatureAlgorithm{
7976 signatureRSAPSSWithSHA256,
7977 },
7978 Bugs: ProtocolBugs{
7979 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7980 },
7981 },
7982 flags: []string{
7983 "-require-any-client-certificate",
7984 },
7985 shouldFail: true,
7986 expectedError: ":WRONG_SIGNATURE_TYPE:",
7987 })
7988
7989 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007990 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007991 config: Config{
7992 MaxVersion: VersionTLS12,
7993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007994 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007995 signatureRSAPKCS1WithSHA256,
7996 },
7997 Bugs: ProtocolBugs{
7998 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7999 },
8000 },
8001 shouldFail: true,
8002 expectedError: ":WRONG_SIGNATURE_TYPE:",
8003 })
8004
Steven Valdez143e8b32016-07-11 13:19:03 -04008005 testCases = append(testCases, testCase{
8006 name: "Verify-ServerAuth-SignatureType-TLS13",
8007 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008008 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008009 SignSignatureAlgorithms: []signatureAlgorithm{
8010 signatureRSAPSSWithSHA256,
8011 },
8012 Bugs: ProtocolBugs{
8013 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8014 },
8015 },
8016 shouldFail: true,
8017 expectedError: ":WRONG_SIGNATURE_TYPE:",
8018 })
8019
David Benjamin51dd7d62016-07-08 16:07:01 -07008020 // Test that, if the list is missing, the peer falls back to SHA-1 in
8021 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008022 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008023 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008025 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008026 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008027 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008028 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008029 },
8030 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008031 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008032 },
8033 },
8034 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008035 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8036 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008037 },
8038 })
8039
8040 testCases = append(testCases, testCase{
8041 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008042 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008043 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008044 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008045 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008046 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008047 },
8048 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008049 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008050 },
8051 },
David Benjaminee32bea2016-08-17 13:36:44 -04008052 flags: []string{
8053 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8054 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8055 },
8056 })
8057
8058 testCases = append(testCases, testCase{
8059 name: "ClientAuth-SHA1-Fallback-ECDSA",
8060 config: Config{
8061 MaxVersion: VersionTLS12,
8062 ClientAuth: RequireAnyClientCert,
8063 VerifySignatureAlgorithms: []signatureAlgorithm{
8064 signatureECDSAWithSHA1,
8065 },
8066 Bugs: ProtocolBugs{
8067 NoSignatureAlgorithms: true,
8068 },
8069 },
8070 flags: []string{
8071 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8072 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8073 },
8074 })
8075
8076 testCases = append(testCases, testCase{
8077 testType: serverTest,
8078 name: "ServerAuth-SHA1-Fallback-ECDSA",
8079 config: Config{
8080 MaxVersion: VersionTLS12,
8081 VerifySignatureAlgorithms: []signatureAlgorithm{
8082 signatureECDSAWithSHA1,
8083 },
8084 Bugs: ProtocolBugs{
8085 NoSignatureAlgorithms: true,
8086 },
8087 },
8088 flags: []string{
8089 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8090 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8091 },
David Benjamin000800a2014-11-14 01:43:59 -05008092 })
David Benjamin72dc7832015-03-16 17:49:43 -04008093
David Benjamin51dd7d62016-07-08 16:07:01 -07008094 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008095 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008096 config: Config{
8097 MaxVersion: VersionTLS13,
8098 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008099 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008100 signatureRSAPKCS1WithSHA1,
8101 },
8102 Bugs: ProtocolBugs{
8103 NoSignatureAlgorithms: true,
8104 },
8105 },
8106 flags: []string{
8107 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8108 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8109 },
David Benjamin48901652016-08-01 12:12:47 -04008110 shouldFail: true,
8111 // An empty CertificateRequest signature algorithm list is a
8112 // syntax error in TLS 1.3.
8113 expectedError: ":DECODE_ERROR:",
8114 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008115 })
8116
8117 testCases = append(testCases, testCase{
8118 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008119 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008120 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008121 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008122 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008123 signatureRSAPKCS1WithSHA1,
8124 },
8125 Bugs: ProtocolBugs{
8126 NoSignatureAlgorithms: true,
8127 },
8128 },
8129 shouldFail: true,
8130 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8131 })
8132
David Benjaminb62d2872016-07-18 14:55:02 +02008133 // Test that hash preferences are enforced. BoringSSL does not implement
8134 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008135 testCases = append(testCases, testCase{
8136 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008137 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008139 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008140 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008141 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008142 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008143 },
8144 Bugs: ProtocolBugs{
8145 IgnorePeerSignatureAlgorithmPreferences: true,
8146 },
8147 },
8148 flags: []string{"-require-any-client-certificate"},
8149 shouldFail: true,
8150 expectedError: ":WRONG_SIGNATURE_TYPE:",
8151 })
8152
8153 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008154 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008156 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008158 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008159 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008160 },
8161 Bugs: ProtocolBugs{
8162 IgnorePeerSignatureAlgorithmPreferences: true,
8163 },
8164 },
8165 shouldFail: true,
8166 expectedError: ":WRONG_SIGNATURE_TYPE:",
8167 })
David Benjaminb62d2872016-07-18 14:55:02 +02008168 testCases = append(testCases, testCase{
8169 testType: serverTest,
8170 name: "ClientAuth-Enforced-TLS13",
8171 config: Config{
8172 MaxVersion: VersionTLS13,
8173 Certificates: []Certificate{rsaCertificate},
8174 SignSignatureAlgorithms: []signatureAlgorithm{
8175 signatureRSAPKCS1WithMD5,
8176 },
8177 Bugs: ProtocolBugs{
8178 IgnorePeerSignatureAlgorithmPreferences: true,
8179 IgnoreSignatureVersionChecks: true,
8180 },
8181 },
8182 flags: []string{"-require-any-client-certificate"},
8183 shouldFail: true,
8184 expectedError: ":WRONG_SIGNATURE_TYPE:",
8185 })
8186
8187 testCases = append(testCases, testCase{
8188 name: "ServerAuth-Enforced-TLS13",
8189 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008190 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008191 SignSignatureAlgorithms: []signatureAlgorithm{
8192 signatureRSAPKCS1WithMD5,
8193 },
8194 Bugs: ProtocolBugs{
8195 IgnorePeerSignatureAlgorithmPreferences: true,
8196 IgnoreSignatureVersionChecks: true,
8197 },
8198 },
8199 shouldFail: true,
8200 expectedError: ":WRONG_SIGNATURE_TYPE:",
8201 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008202
8203 // Test that the agreed upon digest respects the client preferences and
8204 // the server digests.
8205 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008206 name: "NoCommonAlgorithms-Digests",
8207 config: Config{
8208 MaxVersion: VersionTLS12,
8209 ClientAuth: RequireAnyClientCert,
8210 VerifySignatureAlgorithms: []signatureAlgorithm{
8211 signatureRSAPKCS1WithSHA512,
8212 signatureRSAPKCS1WithSHA1,
8213 },
8214 },
8215 flags: []string{
8216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8218 "-digest-prefs", "SHA256",
8219 },
8220 shouldFail: true,
8221 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8222 })
8223 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008224 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008226 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008227 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008228 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008229 signatureRSAPKCS1WithSHA512,
8230 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008231 },
8232 },
8233 flags: []string{
8234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008236 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008237 },
David Benjaminca3d5452016-07-14 12:51:01 -04008238 shouldFail: true,
8239 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8240 })
8241 testCases = append(testCases, testCase{
8242 name: "NoCommonAlgorithms-TLS13",
8243 config: Config{
8244 MaxVersion: VersionTLS13,
8245 ClientAuth: RequireAnyClientCert,
8246 VerifySignatureAlgorithms: []signatureAlgorithm{
8247 signatureRSAPSSWithSHA512,
8248 signatureRSAPSSWithSHA384,
8249 },
8250 },
8251 flags: []string{
8252 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8253 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8254 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8255 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008256 shouldFail: true,
8257 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008258 })
8259 testCases = append(testCases, testCase{
8260 name: "Agree-Digest-SHA256",
8261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008262 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008263 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008264 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008265 signatureRSAPKCS1WithSHA1,
8266 signatureRSAPKCS1WithSHA256,
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", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008273 },
Nick Harper60edffd2016-06-21 15:19:24 -07008274 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008275 })
8276 testCases = append(testCases, testCase{
8277 name: "Agree-Digest-SHA1",
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 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008283 },
8284 },
8285 flags: []string{
8286 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8287 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008288 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008289 },
Nick Harper60edffd2016-06-21 15:19:24 -07008290 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008291 })
8292 testCases = append(testCases, testCase{
8293 name: "Agree-Digest-Default",
8294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008295 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008296 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008297 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008298 signatureRSAPKCS1WithSHA256,
8299 signatureECDSAWithP256AndSHA256,
8300 signatureRSAPKCS1WithSHA1,
8301 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008302 },
8303 },
8304 flags: []string{
8305 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8306 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8307 },
Nick Harper60edffd2016-06-21 15:19:24 -07008308 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008309 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008310
David Benjaminca3d5452016-07-14 12:51:01 -04008311 // Test that the signing preference list may include extra algorithms
8312 // without negotiation problems.
8313 testCases = append(testCases, testCase{
8314 testType: serverTest,
8315 name: "FilterExtraAlgorithms",
8316 config: Config{
8317 MaxVersion: VersionTLS12,
8318 VerifySignatureAlgorithms: []signatureAlgorithm{
8319 signatureRSAPKCS1WithSHA256,
8320 },
8321 },
8322 flags: []string{
8323 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8324 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8325 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8326 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8327 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8328 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8329 },
8330 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8331 })
8332
David Benjamin4c3ddf72016-06-29 18:13:53 -04008333 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8334 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008335 testCases = append(testCases, testCase{
8336 name: "CheckLeafCurve",
8337 config: Config{
8338 MaxVersion: VersionTLS12,
8339 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008340 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008341 },
8342 flags: []string{"-p384-only"},
8343 shouldFail: true,
8344 expectedError: ":BAD_ECC_CERT:",
8345 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008346
8347 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8348 testCases = append(testCases, testCase{
8349 name: "CheckLeafCurve-TLS13",
8350 config: Config{
8351 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008352 Certificates: []Certificate{ecdsaP256Certificate},
8353 },
8354 flags: []string{"-p384-only"},
8355 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008356
8357 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8358 testCases = append(testCases, testCase{
8359 name: "ECDSACurveMismatch-Verify-TLS12",
8360 config: Config{
8361 MaxVersion: VersionTLS12,
8362 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8363 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008364 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008365 signatureECDSAWithP384AndSHA384,
8366 },
8367 },
8368 })
8369
8370 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8371 testCases = append(testCases, testCase{
8372 name: "ECDSACurveMismatch-Verify-TLS13",
8373 config: Config{
8374 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008375 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008376 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008377 signatureECDSAWithP384AndSHA384,
8378 },
8379 Bugs: ProtocolBugs{
8380 SkipECDSACurveCheck: true,
8381 },
8382 },
8383 shouldFail: true,
8384 expectedError: ":WRONG_SIGNATURE_TYPE:",
8385 })
8386
8387 // Signature algorithm selection in TLS 1.3 should take the curve into
8388 // account.
8389 testCases = append(testCases, testCase{
8390 testType: serverTest,
8391 name: "ECDSACurveMismatch-Sign-TLS13",
8392 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008393 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008394 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008395 signatureECDSAWithP384AndSHA384,
8396 signatureECDSAWithP256AndSHA256,
8397 },
8398 },
8399 flags: []string{
8400 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8401 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8402 },
8403 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8404 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008405
8406 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8407 // server does not attempt to sign in that case.
8408 testCases = append(testCases, testCase{
8409 testType: serverTest,
8410 name: "RSA-PSS-Large",
8411 config: Config{
8412 MaxVersion: VersionTLS13,
8413 VerifySignatureAlgorithms: []signatureAlgorithm{
8414 signatureRSAPSSWithSHA512,
8415 },
8416 },
8417 flags: []string{
8418 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8419 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8420 },
8421 shouldFail: true,
8422 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8423 })
David Benjamin57e929f2016-08-30 00:30:38 -04008424
8425 // Test that RSA-PSS is enabled by default for TLS 1.2.
8426 testCases = append(testCases, testCase{
8427 testType: clientTest,
8428 name: "RSA-PSS-Default-Verify",
8429 config: Config{
8430 MaxVersion: VersionTLS12,
8431 SignSignatureAlgorithms: []signatureAlgorithm{
8432 signatureRSAPSSWithSHA256,
8433 },
8434 },
8435 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8436 })
8437
8438 testCases = append(testCases, testCase{
8439 testType: serverTest,
8440 name: "RSA-PSS-Default-Sign",
8441 config: Config{
8442 MaxVersion: VersionTLS12,
8443 VerifySignatureAlgorithms: []signatureAlgorithm{
8444 signatureRSAPSSWithSHA256,
8445 },
8446 },
8447 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8448 })
David Benjamin69522112017-03-28 15:38:29 -05008449
8450 // TLS 1.1 and below has no way to advertise support for or negotiate
8451 // Ed25519's signature algorithm.
8452 testCases = append(testCases, testCase{
8453 testType: clientTest,
8454 name: "NoEd25519-TLS11-ServerAuth-Verify",
8455 config: Config{
8456 MaxVersion: VersionTLS11,
8457 Certificates: []Certificate{ed25519Certificate},
8458 Bugs: ProtocolBugs{
8459 // Sign with Ed25519 even though it is TLS 1.1.
8460 UseLegacySigningAlgorithm: signatureEd25519,
8461 },
8462 },
8463 flags: []string{"-enable-ed25519"},
8464 shouldFail: true,
8465 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8466 })
8467 testCases = append(testCases, testCase{
8468 testType: serverTest,
8469 name: "NoEd25519-TLS11-ServerAuth-Sign",
8470 config: Config{
8471 MaxVersion: VersionTLS11,
8472 },
8473 flags: []string{
8474 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8475 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8476 },
8477 shouldFail: true,
8478 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8479 })
8480 testCases = append(testCases, testCase{
8481 testType: serverTest,
8482 name: "NoEd25519-TLS11-ClientAuth-Verify",
8483 config: Config{
8484 MaxVersion: VersionTLS11,
8485 Certificates: []Certificate{ed25519Certificate},
8486 Bugs: ProtocolBugs{
8487 // Sign with Ed25519 even though it is TLS 1.1.
8488 UseLegacySigningAlgorithm: signatureEd25519,
8489 },
8490 },
8491 flags: []string{
8492 "-enable-ed25519",
8493 "-require-any-client-certificate",
8494 },
8495 shouldFail: true,
8496 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8497 })
8498 testCases = append(testCases, testCase{
8499 testType: clientTest,
8500 name: "NoEd25519-TLS11-ClientAuth-Sign",
8501 config: Config{
8502 MaxVersion: VersionTLS11,
8503 ClientAuth: RequireAnyClientCert,
8504 },
8505 flags: []string{
8506 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8507 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8508 },
8509 shouldFail: true,
8510 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8511 })
8512
8513 // Test Ed25519 is not advertised by default.
8514 testCases = append(testCases, testCase{
8515 testType: clientTest,
8516 name: "Ed25519DefaultDisable-NoAdvertise",
8517 config: Config{
8518 Certificates: []Certificate{ed25519Certificate},
8519 },
8520 shouldFail: true,
8521 expectedLocalError: "tls: no common signature algorithms",
8522 })
8523
8524 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8525 // preferences.
8526 testCases = append(testCases, testCase{
8527 testType: clientTest,
8528 name: "Ed25519DefaultDisable-NoAccept",
8529 config: Config{
8530 Certificates: []Certificate{ed25519Certificate},
8531 Bugs: ProtocolBugs{
8532 IgnorePeerSignatureAlgorithmPreferences: true,
8533 },
8534 },
8535 shouldFail: true,
8536 expectedLocalError: "remote error: illegal parameter",
8537 expectedError: ":WRONG_SIGNATURE_TYPE:",
8538 })
David Benjamin71c21b42017-04-14 17:05:40 -04008539
8540 // Test that configuring verify preferences changes what the client
8541 // advertises.
8542 testCases = append(testCases, testCase{
8543 name: "VerifyPreferences-Advertised",
8544 config: Config{
8545 Certificates: []Certificate{rsaCertificate},
8546 SignSignatureAlgorithms: []signatureAlgorithm{
8547 signatureRSAPSSWithSHA256,
8548 signatureRSAPSSWithSHA384,
8549 signatureRSAPSSWithSHA512,
8550 },
8551 },
8552 flags: []string{
8553 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8554 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8555 },
8556 })
8557
8558 // Test that the client advertises a set which the runner can find
8559 // nothing in common with.
8560 testCases = append(testCases, testCase{
8561 name: "VerifyPreferences-NoCommonAlgorithms",
8562 config: Config{
8563 Certificates: []Certificate{rsaCertificate},
8564 SignSignatureAlgorithms: []signatureAlgorithm{
8565 signatureRSAPSSWithSHA256,
8566 signatureRSAPSSWithSHA512,
8567 },
8568 },
8569 flags: []string{
8570 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8571 },
8572 shouldFail: true,
8573 expectedLocalError: "tls: no common signature algorithms",
8574 })
8575
8576 // Test that the client enforces its preferences when configured.
8577 testCases = append(testCases, testCase{
8578 name: "VerifyPreferences-Enforced",
8579 config: Config{
8580 Certificates: []Certificate{rsaCertificate},
8581 SignSignatureAlgorithms: []signatureAlgorithm{
8582 signatureRSAPSSWithSHA256,
8583 signatureRSAPSSWithSHA512,
8584 },
8585 Bugs: ProtocolBugs{
8586 IgnorePeerSignatureAlgorithmPreferences: true,
8587 },
8588 },
8589 flags: []string{
8590 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8591 },
8592 shouldFail: true,
8593 expectedLocalError: "remote error: illegal parameter",
8594 expectedError: ":WRONG_SIGNATURE_TYPE:",
8595 })
8596
8597 // Test that explicitly configuring Ed25519 is as good as changing the
8598 // boolean toggle.
8599 testCases = append(testCases, testCase{
8600 name: "VerifyPreferences-Ed25519",
8601 config: Config{
8602 Certificates: []Certificate{ed25519Certificate},
8603 },
8604 flags: []string{
8605 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8606 },
8607 })
David Benjamin000800a2014-11-14 01:43:59 -05008608}
8609
David Benjamin83f90402015-01-27 01:09:43 -05008610// timeouts is the retransmit schedule for BoringSSL. It doubles and
8611// caps at 60 seconds. On the 13th timeout, it gives up.
8612var timeouts = []time.Duration{
8613 1 * time.Second,
8614 2 * time.Second,
8615 4 * time.Second,
8616 8 * time.Second,
8617 16 * time.Second,
8618 32 * time.Second,
8619 60 * time.Second,
8620 60 * time.Second,
8621 60 * time.Second,
8622 60 * time.Second,
8623 60 * time.Second,
8624 60 * time.Second,
8625 60 * time.Second,
8626}
8627
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008628// shortTimeouts is an alternate set of timeouts which would occur if the
8629// initial timeout duration was set to 250ms.
8630var shortTimeouts = []time.Duration{
8631 250 * time.Millisecond,
8632 500 * time.Millisecond,
8633 1 * time.Second,
8634 2 * time.Second,
8635 4 * time.Second,
8636 8 * time.Second,
8637 16 * time.Second,
8638 32 * time.Second,
8639 60 * time.Second,
8640 60 * time.Second,
8641 60 * time.Second,
8642 60 * time.Second,
8643 60 * time.Second,
8644}
8645
David Benjamin83f90402015-01-27 01:09:43 -05008646func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008647 // These tests work by coordinating some behavior on both the shim and
8648 // the runner.
8649 //
8650 // TimeoutSchedule configures the runner to send a series of timeout
8651 // opcodes to the shim (see packetAdaptor) immediately before reading
8652 // each peer handshake flight N. The timeout opcode both simulates a
8653 // timeout in the shim and acts as a synchronization point to help the
8654 // runner bracket each handshake flight.
8655 //
8656 // We assume the shim does not read from the channel eagerly. It must
8657 // first wait until it has sent flight N and is ready to receive
8658 // handshake flight N+1. At this point, it will process the timeout
8659 // opcode. It must then immediately respond with a timeout ACK and act
8660 // as if the shim was idle for the specified amount of time.
8661 //
8662 // The runner then drops all packets received before the ACK and
8663 // continues waiting for flight N. This ordering results in one attempt
8664 // at sending flight N to be dropped. For the test to complete, the
8665 // shim must send flight N again, testing that the shim implements DTLS
8666 // retransmit on a timeout.
8667
Steven Valdez143e8b32016-07-11 13:19:03 -04008668 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008669 // likely be more epochs to cross and the final message's retransmit may
8670 // be more complex.
8671
David Benjamin11c82892017-02-23 20:40:31 -05008672 // Test that this is indeed the timeout schedule. Stress all
8673 // four patterns of handshake.
8674 for i := 1; i < len(timeouts); i++ {
8675 number := strconv.Itoa(i)
8676 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008677 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008678 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008679 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008680 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008681 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008682 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008683 },
8684 },
8685 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008686 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008687 })
David Benjamin11c82892017-02-23 20:40:31 -05008688 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008689 protocol: dtls,
8690 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008691 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008693 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008694 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008695 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008696 },
8697 },
8698 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008699 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008700 })
8701 }
David Benjamin11c82892017-02-23 20:40:31 -05008702
8703 // Test that exceeding the timeout schedule hits a read
8704 // timeout.
8705 testCases = append(testCases, testCase{
8706 protocol: dtls,
8707 name: "DTLS-Retransmit-Timeout",
8708 config: Config{
8709 MaxVersion: VersionTLS12,
8710 Bugs: ProtocolBugs{
8711 TimeoutSchedule: timeouts,
8712 },
8713 },
8714 resumeSession: true,
8715 flags: []string{"-async"},
8716 shouldFail: true,
8717 expectedError: ":READ_TIMEOUT_EXPIRED:",
8718 })
8719
8720 // Test that timeout handling has a fudge factor, due to API
8721 // problems.
8722 testCases = append(testCases, testCase{
8723 protocol: dtls,
8724 name: "DTLS-Retransmit-Fudge",
8725 config: Config{
8726 MaxVersion: VersionTLS12,
8727 Bugs: ProtocolBugs{
8728 TimeoutSchedule: []time.Duration{
8729 timeouts[0] - 10*time.Millisecond,
8730 },
8731 },
8732 },
8733 resumeSession: true,
8734 flags: []string{"-async"},
8735 })
8736
8737 // Test that the final Finished retransmitting isn't
8738 // duplicated if the peer badly fragments everything.
8739 testCases = append(testCases, testCase{
8740 testType: serverTest,
8741 protocol: dtls,
8742 name: "DTLS-Retransmit-Fragmented",
8743 config: Config{
8744 MaxVersion: VersionTLS12,
8745 Bugs: ProtocolBugs{
8746 TimeoutSchedule: []time.Duration{timeouts[0]},
8747 MaxHandshakeRecordLength: 2,
8748 },
8749 },
8750 flags: []string{"-async"},
8751 })
8752
8753 // Test the timeout schedule when a shorter initial timeout duration is set.
8754 testCases = append(testCases, testCase{
8755 protocol: dtls,
8756 name: "DTLS-Retransmit-Short-Client",
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 })
8769 testCases = append(testCases, testCase{
8770 protocol: dtls,
8771 testType: serverTest,
8772 name: "DTLS-Retransmit-Short-Server",
8773 config: Config{
8774 MaxVersion: VersionTLS12,
8775 Bugs: ProtocolBugs{
8776 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8777 },
8778 },
8779 resumeSession: true,
8780 flags: []string{
8781 "-async",
8782 "-initial-timeout-duration-ms", "250",
8783 },
8784 })
David Benjamin83f90402015-01-27 01:09:43 -05008785}
8786
David Benjaminc565ebb2015-04-03 04:06:36 -04008787func addExportKeyingMaterialTests() {
8788 for _, vers := range tlsVersions {
8789 if vers.version == VersionSSL30 {
8790 continue
8791 }
8792 testCases = append(testCases, testCase{
8793 name: "ExportKeyingMaterial-" + vers.name,
8794 config: Config{
8795 MaxVersion: vers.version,
8796 },
David Benjamina5022392017-07-10 17:40:39 -04008797 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008798 exportKeyingMaterial: 1024,
8799 exportLabel: "label",
8800 exportContext: "context",
8801 useExportContext: true,
8802 })
8803 testCases = append(testCases, testCase{
8804 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8805 config: Config{
8806 MaxVersion: vers.version,
8807 },
David Benjamina5022392017-07-10 17:40:39 -04008808 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008809 exportKeyingMaterial: 1024,
8810 })
8811 testCases = append(testCases, testCase{
8812 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8813 config: Config{
8814 MaxVersion: vers.version,
8815 },
David Benjamina5022392017-07-10 17:40:39 -04008816 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008817 exportKeyingMaterial: 1024,
8818 useExportContext: true,
8819 })
8820 testCases = append(testCases, testCase{
8821 name: "ExportKeyingMaterial-Small-" + vers.name,
8822 config: Config{
8823 MaxVersion: vers.version,
8824 },
David Benjamina5022392017-07-10 17:40:39 -04008825 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008826 exportKeyingMaterial: 1,
8827 exportLabel: "label",
8828 exportContext: "context",
8829 useExportContext: true,
8830 })
8831 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008832
David Benjaminc565ebb2015-04-03 04:06:36 -04008833 testCases = append(testCases, testCase{
8834 name: "ExportKeyingMaterial-SSL3",
8835 config: Config{
8836 MaxVersion: VersionSSL30,
8837 },
8838 exportKeyingMaterial: 1024,
8839 exportLabel: "label",
8840 exportContext: "context",
8841 useExportContext: true,
8842 shouldFail: true,
8843 expectedError: "failed to export keying material",
8844 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008845
8846 // Exporters work during a False Start.
8847 testCases = append(testCases, testCase{
8848 name: "ExportKeyingMaterial-FalseStart",
8849 config: Config{
8850 MaxVersion: VersionTLS12,
8851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8852 NextProtos: []string{"foo"},
8853 Bugs: ProtocolBugs{
8854 ExpectFalseStart: true,
8855 },
8856 },
8857 flags: []string{
8858 "-false-start",
8859 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008860 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008861 },
8862 shimWritesFirst: true,
8863 exportKeyingMaterial: 1024,
8864 exportLabel: "label",
8865 exportContext: "context",
8866 useExportContext: true,
8867 })
8868
8869 // Exporters do not work in the middle of a renegotiation. Test this by
8870 // triggering the exporter after every SSL_read call and configuring the
8871 // shim to run asynchronously.
8872 testCases = append(testCases, testCase{
8873 name: "ExportKeyingMaterial-Renegotiate",
8874 config: Config{
8875 MaxVersion: VersionTLS12,
8876 },
8877 renegotiate: 1,
8878 flags: []string{
8879 "-async",
8880 "-use-exporter-between-reads",
8881 "-renegotiate-freely",
8882 "-expect-total-renegotiations", "1",
8883 },
8884 shouldFail: true,
8885 expectedError: "failed to export keying material",
8886 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008887}
8888
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008889func addTLSUniqueTests() {
8890 for _, isClient := range []bool{false, true} {
8891 for _, isResumption := range []bool{false, true} {
8892 for _, hasEMS := range []bool{false, true} {
8893 var suffix string
8894 if isResumption {
8895 suffix = "Resume-"
8896 } else {
8897 suffix = "Full-"
8898 }
8899
8900 if hasEMS {
8901 suffix += "EMS-"
8902 } else {
8903 suffix += "NoEMS-"
8904 }
8905
8906 if isClient {
8907 suffix += "Client"
8908 } else {
8909 suffix += "Server"
8910 }
8911
8912 test := testCase{
8913 name: "TLSUnique-" + suffix,
8914 testTLSUnique: true,
8915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008916 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008917 Bugs: ProtocolBugs{
8918 NoExtendedMasterSecret: !hasEMS,
8919 },
8920 },
8921 }
8922
8923 if isResumption {
8924 test.resumeSession = true
8925 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008926 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008927 Bugs: ProtocolBugs{
8928 NoExtendedMasterSecret: !hasEMS,
8929 },
8930 }
8931 }
8932
8933 if isResumption && !hasEMS {
8934 test.shouldFail = true
8935 test.expectedError = "failed to get tls-unique"
8936 }
8937
8938 testCases = append(testCases, test)
8939 }
8940 }
8941 }
8942}
8943
Adam Langley09505632015-07-30 18:10:13 -07008944func addCustomExtensionTests() {
8945 expectedContents := "custom extension"
8946 emptyString := ""
8947
8948 for _, isClient := range []bool{false, true} {
8949 suffix := "Server"
8950 flag := "-enable-server-custom-extension"
8951 testType := serverTest
8952 if isClient {
8953 suffix = "Client"
8954 flag = "-enable-client-custom-extension"
8955 testType = clientTest
8956 }
8957
8958 testCases = append(testCases, testCase{
8959 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008960 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008962 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008963 Bugs: ProtocolBugs{
8964 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008965 ExpectedCustomExtension: &expectedContents,
8966 },
8967 },
8968 flags: []string{flag},
8969 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008970 testCases = append(testCases, testCase{
8971 testType: testType,
8972 name: "CustomExtensions-" + suffix + "-TLS13",
8973 config: Config{
8974 MaxVersion: VersionTLS13,
8975 Bugs: ProtocolBugs{
8976 CustomExtension: expectedContents,
8977 ExpectedCustomExtension: &expectedContents,
8978 },
8979 },
8980 flags: []string{flag},
8981 })
Adam Langley09505632015-07-30 18:10:13 -07008982
Steven Valdez2a070722017-03-25 20:54:16 -05008983 // 0-RTT is not currently supported with Custom Extensions.
8984 testCases = append(testCases, testCase{
8985 testType: testType,
8986 name: "CustomExtensions-" + suffix + "-EarlyData",
8987 config: Config{
8988 MaxVersion: VersionTLS13,
8989 Bugs: ProtocolBugs{
8990 CustomExtension: expectedContents,
8991 ExpectedCustomExtension: &expectedContents,
8992 },
8993 },
8994 shouldFail: true,
8995 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8996 flags: []string{flag, "-enable-early-data"},
8997 })
8998
Adam Langley09505632015-07-30 18:10:13 -07008999 // If the parse callback fails, the handshake should also fail.
9000 testCases = append(testCases, testCase{
9001 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009002 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009003 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009004 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009005 Bugs: ProtocolBugs{
9006 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07009007 ExpectedCustomExtension: &expectedContents,
9008 },
9009 },
David Benjamin399e7c92015-07-30 23:01:27 -04009010 flags: []string{flag},
9011 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009012 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9013 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009014 testCases = append(testCases, testCase{
9015 testType: testType,
9016 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9017 config: Config{
9018 MaxVersion: VersionTLS13,
9019 Bugs: ProtocolBugs{
9020 CustomExtension: expectedContents + "foo",
9021 ExpectedCustomExtension: &expectedContents,
9022 },
9023 },
9024 flags: []string{flag},
9025 shouldFail: true,
9026 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9027 })
Adam Langley09505632015-07-30 18:10:13 -07009028
9029 // If the add callback fails, the handshake should also fail.
9030 testCases = append(testCases, testCase{
9031 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009032 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009034 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009035 Bugs: ProtocolBugs{
9036 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009037 ExpectedCustomExtension: &expectedContents,
9038 },
9039 },
David Benjamin399e7c92015-07-30 23:01:27 -04009040 flags: []string{flag, "-custom-extension-fail-add"},
9041 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009042 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9043 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009044 testCases = append(testCases, testCase{
9045 testType: testType,
9046 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9047 config: Config{
9048 MaxVersion: VersionTLS13,
9049 Bugs: ProtocolBugs{
9050 CustomExtension: expectedContents,
9051 ExpectedCustomExtension: &expectedContents,
9052 },
9053 },
9054 flags: []string{flag, "-custom-extension-fail-add"},
9055 shouldFail: true,
9056 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9057 })
Adam Langley09505632015-07-30 18:10:13 -07009058
9059 // If the add callback returns zero, no extension should be
9060 // added.
9061 skipCustomExtension := expectedContents
9062 if isClient {
9063 // For the case where the client skips sending the
9064 // custom extension, the server must not “echo” it.
9065 skipCustomExtension = ""
9066 }
9067 testCases = append(testCases, testCase{
9068 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009069 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009071 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009072 Bugs: ProtocolBugs{
9073 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009074 ExpectedCustomExtension: &emptyString,
9075 },
9076 },
9077 flags: []string{flag, "-custom-extension-skip"},
9078 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009079 testCases = append(testCases, testCase{
9080 testType: testType,
9081 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9082 config: Config{
9083 MaxVersion: VersionTLS13,
9084 Bugs: ProtocolBugs{
9085 CustomExtension: skipCustomExtension,
9086 ExpectedCustomExtension: &emptyString,
9087 },
9088 },
9089 flags: []string{flag, "-custom-extension-skip"},
9090 })
Adam Langley09505632015-07-30 18:10:13 -07009091 }
9092
9093 // The custom extension add callback should not be called if the client
9094 // doesn't send the extension.
9095 testCases = append(testCases, testCase{
9096 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009097 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009099 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009100 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009101 ExpectedCustomExtension: &emptyString,
9102 },
9103 },
9104 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9105 })
Adam Langley2deb9842015-08-07 11:15:37 -07009106
Steven Valdez143e8b32016-07-11 13:19:03 -04009107 testCases = append(testCases, testCase{
9108 testType: serverTest,
9109 name: "CustomExtensions-NotCalled-Server-TLS13",
9110 config: Config{
9111 MaxVersion: VersionTLS13,
9112 Bugs: ProtocolBugs{
9113 ExpectedCustomExtension: &emptyString,
9114 },
9115 },
9116 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9117 })
9118
Adam Langley2deb9842015-08-07 11:15:37 -07009119 // Test an unknown extension from the server.
9120 testCases = append(testCases, testCase{
9121 testType: clientTest,
9122 name: "UnknownExtension-Client",
9123 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009124 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009125 Bugs: ProtocolBugs{
9126 CustomExtension: expectedContents,
9127 },
9128 },
David Benjamin0c40a962016-08-01 12:05:50 -04009129 shouldFail: true,
9130 expectedError: ":UNEXPECTED_EXTENSION:",
9131 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009132 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009133 testCases = append(testCases, testCase{
9134 testType: clientTest,
9135 name: "UnknownExtension-Client-TLS13",
9136 config: Config{
9137 MaxVersion: VersionTLS13,
9138 Bugs: ProtocolBugs{
9139 CustomExtension: expectedContents,
9140 },
9141 },
David Benjamin0c40a962016-08-01 12:05:50 -04009142 shouldFail: true,
9143 expectedError: ":UNEXPECTED_EXTENSION:",
9144 expectedLocalError: "remote error: unsupported extension",
9145 })
David Benjamin490469f2016-10-05 22:44:38 -04009146 testCases = append(testCases, testCase{
9147 testType: clientTest,
9148 name: "UnknownUnencryptedExtension-Client-TLS13",
9149 config: Config{
9150 MaxVersion: VersionTLS13,
9151 Bugs: ProtocolBugs{
9152 CustomUnencryptedExtension: expectedContents,
9153 },
9154 },
9155 shouldFail: true,
9156 expectedError: ":UNEXPECTED_EXTENSION:",
9157 // The shim must send an alert, but alerts at this point do not
9158 // get successfully decrypted by the runner.
9159 expectedLocalError: "local error: bad record MAC",
9160 })
9161 testCases = append(testCases, testCase{
9162 testType: clientTest,
9163 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9164 config: Config{
9165 MaxVersion: VersionTLS13,
9166 Bugs: ProtocolBugs{
9167 SendUnencryptedALPN: "foo",
9168 },
9169 },
9170 flags: []string{
9171 "-advertise-alpn", "\x03foo\x03bar",
9172 },
9173 shouldFail: true,
9174 expectedError: ":UNEXPECTED_EXTENSION:",
9175 // The shim must send an alert, but alerts at this point do not
9176 // get successfully decrypted by the runner.
9177 expectedLocalError: "local error: bad record MAC",
9178 })
David Benjamin0c40a962016-08-01 12:05:50 -04009179
9180 // Test a known but unoffered extension from the server.
9181 testCases = append(testCases, testCase{
9182 testType: clientTest,
9183 name: "UnofferedExtension-Client",
9184 config: Config{
9185 MaxVersion: VersionTLS12,
9186 Bugs: ProtocolBugs{
9187 SendALPN: "alpn",
9188 },
9189 },
9190 shouldFail: true,
9191 expectedError: ":UNEXPECTED_EXTENSION:",
9192 expectedLocalError: "remote error: unsupported extension",
9193 })
9194 testCases = append(testCases, testCase{
9195 testType: clientTest,
9196 name: "UnofferedExtension-Client-TLS13",
9197 config: Config{
9198 MaxVersion: VersionTLS13,
9199 Bugs: ProtocolBugs{
9200 SendALPN: "alpn",
9201 },
9202 },
9203 shouldFail: true,
9204 expectedError: ":UNEXPECTED_EXTENSION:",
9205 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009206 })
Adam Langley09505632015-07-30 18:10:13 -07009207}
9208
David Benjaminb36a3952015-12-01 18:53:13 -05009209func addRSAClientKeyExchangeTests() {
9210 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9211 testCases = append(testCases, testCase{
9212 testType: serverTest,
9213 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9214 config: Config{
9215 // Ensure the ClientHello version and final
9216 // version are different, to detect if the
9217 // server uses the wrong one.
9218 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009219 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009220 Bugs: ProtocolBugs{
9221 BadRSAClientKeyExchange: bad,
9222 },
9223 },
9224 shouldFail: true,
9225 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9226 })
9227 }
David Benjamine63d9d72016-09-19 18:27:34 -04009228
9229 // The server must compare whatever was in ClientHello.version for the
9230 // RSA premaster.
9231 testCases = append(testCases, testCase{
9232 testType: serverTest,
9233 name: "SendClientVersion-RSA",
9234 config: Config{
9235 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9236 Bugs: ProtocolBugs{
9237 SendClientVersion: 0x1234,
9238 },
9239 },
9240 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9241 })
David Benjaminb36a3952015-12-01 18:53:13 -05009242}
9243
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009244var testCurves = []struct {
9245 name string
9246 id CurveID
9247}{
Adam Langley764ab982017-03-10 18:01:30 -08009248 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009249 {"P-256", CurveP256},
9250 {"P-384", CurveP384},
9251 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009252 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009253}
9254
Steven Valdez5440fe02016-07-18 12:40:30 -04009255const bogusCurve = 0x1234
9256
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009257func addCurveTests() {
9258 for _, curve := range testCurves {
9259 testCases = append(testCases, testCase{
9260 name: "CurveTest-Client-" + curve.name,
9261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009262 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009263 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9264 CurvePreferences: []CurveID{curve.id},
9265 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009266 flags: []string{
9267 "-enable-all-curves",
9268 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9269 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009270 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009271 })
9272 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009273 name: "CurveTest-Client-" + curve.name + "-TLS13",
9274 config: Config{
9275 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009276 CurvePreferences: []CurveID{curve.id},
9277 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009278 flags: []string{
9279 "-enable-all-curves",
9280 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9281 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009282 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009283 })
9284 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009285 testType: serverTest,
9286 name: "CurveTest-Server-" + curve.name,
9287 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009288 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9290 CurvePreferences: []CurveID{curve.id},
9291 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009292 flags: []string{
9293 "-enable-all-curves",
9294 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9295 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009296 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009297 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009298 testCases = append(testCases, testCase{
9299 testType: serverTest,
9300 name: "CurveTest-Server-" + curve.name + "-TLS13",
9301 config: Config{
9302 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009303 CurvePreferences: []CurveID{curve.id},
9304 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009305 flags: []string{
9306 "-enable-all-curves",
9307 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9308 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009309 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009310 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009311 }
David Benjamin241ae832016-01-15 03:04:54 -05009312
9313 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009314 testCases = append(testCases, testCase{
9315 testType: serverTest,
9316 name: "UnknownCurve",
9317 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009318 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009319 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9320 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9321 },
9322 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009323
Steven Valdez803c77a2016-09-06 14:13:43 -04009324 // The server must be tolerant to bogus curves.
9325 testCases = append(testCases, testCase{
9326 testType: serverTest,
9327 name: "UnknownCurve-TLS13",
9328 config: Config{
9329 MaxVersion: VersionTLS13,
9330 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9331 },
9332 })
9333
David Benjamin4c3ddf72016-06-29 18:13:53 -04009334 // The server must not consider ECDHE ciphers when there are no
9335 // supported curves.
9336 testCases = append(testCases, testCase{
9337 testType: serverTest,
9338 name: "NoSupportedCurves",
9339 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009340 MaxVersion: VersionTLS12,
9341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9342 Bugs: ProtocolBugs{
9343 NoSupportedCurves: true,
9344 },
9345 },
9346 shouldFail: true,
9347 expectedError: ":NO_SHARED_CIPHER:",
9348 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009349 testCases = append(testCases, testCase{
9350 testType: serverTest,
9351 name: "NoSupportedCurves-TLS13",
9352 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009353 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009354 Bugs: ProtocolBugs{
9355 NoSupportedCurves: true,
9356 },
9357 },
9358 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009359 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009360 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009361
9362 // The server must fall back to another cipher when there are no
9363 // supported curves.
9364 testCases = append(testCases, testCase{
9365 testType: serverTest,
9366 name: "NoCommonCurves",
9367 config: Config{
9368 MaxVersion: VersionTLS12,
9369 CipherSuites: []uint16{
9370 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009371 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009372 },
9373 CurvePreferences: []CurveID{CurveP224},
9374 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009375 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009376 })
9377
9378 // The client must reject bogus curves and disabled curves.
9379 testCases = append(testCases, testCase{
9380 name: "BadECDHECurve",
9381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009382 MaxVersion: VersionTLS12,
9383 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9384 Bugs: ProtocolBugs{
9385 SendCurve: bogusCurve,
9386 },
9387 },
9388 shouldFail: true,
9389 expectedError: ":WRONG_CURVE:",
9390 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009391 testCases = append(testCases, testCase{
9392 name: "BadECDHECurve-TLS13",
9393 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009394 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009395 Bugs: ProtocolBugs{
9396 SendCurve: bogusCurve,
9397 },
9398 },
9399 shouldFail: true,
9400 expectedError: ":WRONG_CURVE:",
9401 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009402
9403 testCases = append(testCases, testCase{
9404 name: "UnsupportedCurve",
9405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009406 MaxVersion: VersionTLS12,
9407 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9408 CurvePreferences: []CurveID{CurveP256},
9409 Bugs: ProtocolBugs{
9410 IgnorePeerCurvePreferences: true,
9411 },
9412 },
9413 flags: []string{"-p384-only"},
9414 shouldFail: true,
9415 expectedError: ":WRONG_CURVE:",
9416 })
9417
David Benjamin4f921572016-07-17 14:20:10 +02009418 testCases = append(testCases, testCase{
9419 // TODO(davidben): Add a TLS 1.3 version where
9420 // HelloRetryRequest requests an unsupported curve.
9421 name: "UnsupportedCurve-ServerHello-TLS13",
9422 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009423 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009424 CurvePreferences: []CurveID{CurveP384},
9425 Bugs: ProtocolBugs{
9426 SendCurve: CurveP256,
9427 },
9428 },
9429 flags: []string{"-p384-only"},
9430 shouldFail: true,
9431 expectedError: ":WRONG_CURVE:",
9432 })
9433
David Benjamin4c3ddf72016-06-29 18:13:53 -04009434 // Test invalid curve points.
9435 testCases = append(testCases, testCase{
9436 name: "InvalidECDHPoint-Client",
9437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009438 MaxVersion: VersionTLS12,
9439 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9440 CurvePreferences: []CurveID{CurveP256},
9441 Bugs: ProtocolBugs{
9442 InvalidECDHPoint: true,
9443 },
9444 },
9445 shouldFail: true,
9446 expectedError: ":INVALID_ENCODING:",
9447 })
9448 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009449 name: "InvalidECDHPoint-Client-TLS13",
9450 config: Config{
9451 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009452 CurvePreferences: []CurveID{CurveP256},
9453 Bugs: ProtocolBugs{
9454 InvalidECDHPoint: true,
9455 },
9456 },
9457 shouldFail: true,
9458 expectedError: ":INVALID_ENCODING:",
9459 })
9460 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009461 testType: serverTest,
9462 name: "InvalidECDHPoint-Server",
9463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009464 MaxVersion: VersionTLS12,
9465 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9466 CurvePreferences: []CurveID{CurveP256},
9467 Bugs: ProtocolBugs{
9468 InvalidECDHPoint: true,
9469 },
9470 },
9471 shouldFail: true,
9472 expectedError: ":INVALID_ENCODING:",
9473 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009474 testCases = append(testCases, testCase{
9475 testType: serverTest,
9476 name: "InvalidECDHPoint-Server-TLS13",
9477 config: Config{
9478 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009479 CurvePreferences: []CurveID{CurveP256},
9480 Bugs: ProtocolBugs{
9481 InvalidECDHPoint: true,
9482 },
9483 },
9484 shouldFail: true,
9485 expectedError: ":INVALID_ENCODING:",
9486 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009487
9488 // The previous curve ID should be reported on TLS 1.2 resumption.
9489 testCases = append(testCases, testCase{
9490 name: "CurveID-Resume-Client",
9491 config: Config{
9492 MaxVersion: VersionTLS12,
9493 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9494 CurvePreferences: []CurveID{CurveX25519},
9495 },
9496 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9497 resumeSession: true,
9498 })
9499 testCases = append(testCases, testCase{
9500 testType: serverTest,
9501 name: "CurveID-Resume-Server",
9502 config: Config{
9503 MaxVersion: VersionTLS12,
9504 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9505 CurvePreferences: []CurveID{CurveX25519},
9506 },
9507 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9508 resumeSession: true,
9509 })
9510
9511 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9512 // one should be reported.
9513 testCases = append(testCases, testCase{
9514 name: "CurveID-Resume-Client-TLS13",
9515 config: Config{
9516 MaxVersion: VersionTLS13,
9517 CurvePreferences: []CurveID{CurveX25519},
9518 },
9519 resumeConfig: &Config{
9520 MaxVersion: VersionTLS13,
9521 CurvePreferences: []CurveID{CurveP256},
9522 },
9523 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009524 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9525 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009526 },
9527 resumeSession: true,
9528 })
9529 testCases = append(testCases, testCase{
9530 testType: serverTest,
9531 name: "CurveID-Resume-Server-TLS13",
9532 config: Config{
9533 MaxVersion: VersionTLS13,
9534 CurvePreferences: []CurveID{CurveX25519},
9535 },
9536 resumeConfig: &Config{
9537 MaxVersion: VersionTLS13,
9538 CurvePreferences: []CurveID{CurveP256},
9539 },
9540 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009541 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9542 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009543 },
9544 resumeSession: true,
9545 })
David Benjamina81967b2016-12-22 09:16:57 -05009546
9547 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9548 testCases = append(testCases, testCase{
9549 name: "PointFormat-ServerHello-TLS12",
9550 config: Config{
9551 MaxVersion: VersionTLS12,
9552 Bugs: ProtocolBugs{
9553 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9554 },
9555 },
9556 })
9557 testCases = append(testCases, testCase{
9558 name: "PointFormat-EncryptedExtensions-TLS13",
9559 config: Config{
9560 MaxVersion: VersionTLS13,
9561 Bugs: ProtocolBugs{
9562 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9563 },
9564 },
9565 shouldFail: true,
9566 expectedError: ":ERROR_PARSING_EXTENSION:",
9567 })
9568
9569 // Test that we tolerate unknown point formats, as long as
9570 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9571 // check they are still functional.
9572 testCases = append(testCases, testCase{
9573 name: "PointFormat-Client-Tolerance",
9574 config: Config{
9575 MaxVersion: VersionTLS12,
9576 Bugs: ProtocolBugs{
9577 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9578 },
9579 },
9580 })
9581 testCases = append(testCases, testCase{
9582 testType: serverTest,
9583 name: "PointFormat-Server-Tolerance",
9584 config: Config{
9585 MaxVersion: VersionTLS12,
9586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9587 Bugs: ProtocolBugs{
9588 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9589 },
9590 },
9591 })
9592
9593 // Test TLS 1.2 does not require the point format extension to be
9594 // present.
9595 testCases = append(testCases, testCase{
9596 name: "PointFormat-Client-Missing",
9597 config: Config{
9598 MaxVersion: VersionTLS12,
9599 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9600 Bugs: ProtocolBugs{
9601 SendSupportedPointFormats: []byte{},
9602 },
9603 },
9604 })
9605 testCases = append(testCases, testCase{
9606 testType: serverTest,
9607 name: "PointFormat-Server-Missing",
9608 config: Config{
9609 MaxVersion: VersionTLS12,
9610 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9611 Bugs: ProtocolBugs{
9612 SendSupportedPointFormats: []byte{},
9613 },
9614 },
9615 })
9616
9617 // If the point format extension is present, uncompressed points must be
9618 // offered. BoringSSL requires this whether or not ECDHE is used.
9619 testCases = append(testCases, testCase{
9620 name: "PointFormat-Client-MissingUncompressed",
9621 config: Config{
9622 MaxVersion: VersionTLS12,
9623 Bugs: ProtocolBugs{
9624 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9625 },
9626 },
9627 shouldFail: true,
9628 expectedError: ":ERROR_PARSING_EXTENSION:",
9629 })
9630 testCases = append(testCases, testCase{
9631 testType: serverTest,
9632 name: "PointFormat-Server-MissingUncompressed",
9633 config: Config{
9634 MaxVersion: VersionTLS12,
9635 Bugs: ProtocolBugs{
9636 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9637 },
9638 },
9639 shouldFail: true,
9640 expectedError: ":ERROR_PARSING_EXTENSION:",
9641 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009642}
9643
David Benjaminc9ae27c2016-06-24 22:56:37 -04009644func addTLS13RecordTests() {
9645 testCases = append(testCases, testCase{
9646 name: "TLS13-RecordPadding",
9647 config: Config{
9648 MaxVersion: VersionTLS13,
9649 MinVersion: VersionTLS13,
9650 Bugs: ProtocolBugs{
9651 RecordPadding: 10,
9652 },
9653 },
9654 })
9655
9656 testCases = append(testCases, testCase{
9657 name: "TLS13-EmptyRecords",
9658 config: Config{
9659 MaxVersion: VersionTLS13,
9660 MinVersion: VersionTLS13,
9661 Bugs: ProtocolBugs{
9662 OmitRecordContents: true,
9663 },
9664 },
9665 shouldFail: true,
9666 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9667 })
9668
9669 testCases = append(testCases, testCase{
9670 name: "TLS13-OnlyPadding",
9671 config: Config{
9672 MaxVersion: VersionTLS13,
9673 MinVersion: VersionTLS13,
9674 Bugs: ProtocolBugs{
9675 OmitRecordContents: true,
9676 RecordPadding: 10,
9677 },
9678 },
9679 shouldFail: true,
9680 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9681 })
9682
9683 testCases = append(testCases, testCase{
9684 name: "TLS13-WrongOuterRecord",
9685 config: Config{
9686 MaxVersion: VersionTLS13,
9687 MinVersion: VersionTLS13,
9688 Bugs: ProtocolBugs{
9689 OuterRecordType: recordTypeHandshake,
9690 },
9691 },
9692 shouldFail: true,
9693 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9694 })
9695}
9696
Steven Valdez5b986082016-09-01 12:29:49 -04009697func addSessionTicketTests() {
9698 testCases = append(testCases, testCase{
9699 // In TLS 1.2 and below, empty NewSessionTicket messages
9700 // mean the server changed its mind on sending a ticket.
9701 name: "SendEmptySessionTicket",
9702 config: Config{
9703 MaxVersion: VersionTLS12,
9704 Bugs: ProtocolBugs{
9705 SendEmptySessionTicket: true,
9706 },
9707 },
9708 flags: []string{"-expect-no-session"},
9709 })
9710
9711 // Test that the server ignores unknown PSK modes.
9712 testCases = append(testCases, testCase{
9713 testType: serverTest,
9714 name: "TLS13-SendUnknownModeSessionTicket-Server",
9715 config: Config{
9716 MaxVersion: VersionTLS13,
9717 Bugs: ProtocolBugs{
9718 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009719 },
9720 },
9721 resumeSession: true,
9722 expectedResumeVersion: VersionTLS13,
9723 })
9724
Steven Valdeza833c352016-11-01 13:39:36 -04009725 // Test that the server does not send session tickets with no matching key exchange mode.
9726 testCases = append(testCases, testCase{
9727 testType: serverTest,
9728 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9729 config: Config{
9730 MaxVersion: VersionTLS13,
9731 Bugs: ProtocolBugs{
9732 SendPSKKeyExchangeModes: []byte{0x1a},
9733 ExpectNoNewSessionTicket: true,
9734 },
9735 },
9736 })
9737
9738 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009739 testCases = append(testCases, testCase{
9740 testType: serverTest,
9741 name: "TLS13-SendBadKEModeSessionTicket-Server",
9742 config: Config{
9743 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009744 },
9745 resumeConfig: &Config{
9746 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009747 Bugs: ProtocolBugs{
9748 SendPSKKeyExchangeModes: []byte{0x1a},
9749 },
9750 },
9751 resumeSession: true,
9752 expectResumeRejected: true,
9753 })
9754
Steven Valdeza833c352016-11-01 13:39:36 -04009755 // Test that the client ticket age is sent correctly.
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-TestValidTicketAge-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: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009763 },
9764 },
Steven Valdeza833c352016-11-01 13:39:36 -04009765 resumeSession: true,
9766 flags: []string{
9767 "-resumption-delay", "10",
9768 },
Steven Valdez5b986082016-09-01 12:29:49 -04009769 })
9770
Steven Valdeza833c352016-11-01 13:39:36 -04009771 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009772 testCases = append(testCases, testCase{
9773 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009774 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009775 config: Config{
9776 MaxVersion: VersionTLS13,
9777 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009778 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009779 },
9780 },
Steven Valdeza833c352016-11-01 13:39:36 -04009781 resumeSession: true,
9782 shouldFail: true,
9783 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009784 })
9785
David Benjamin35ac5b72017-03-03 15:05:56 -05009786 // Test that the server's ticket age skew reporting works.
9787 testCases = append(testCases, testCase{
9788 testType: serverTest,
9789 name: "TLS13-TicketAgeSkew-Forward",
9790 config: Config{
9791 MaxVersion: VersionTLS13,
9792 Bugs: ProtocolBugs{
9793 SendTicketAge: 15 * 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 testCases = append(testCases, testCase{
9804 testType: serverTest,
9805 name: "TLS13-TicketAgeSkew-Backward",
9806 config: Config{
9807 MaxVersion: VersionTLS13,
9808 Bugs: ProtocolBugs{
9809 SendTicketAge: 5 * time.Second,
9810 },
9811 },
David Benjamin065d7332017-03-26 10:51:43 -05009812 resumeSession: true,
9813 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009814 flags: []string{
9815 "-resumption-delay", "10",
9816 "-expect-ticket-age-skew", "-5",
9817 },
9818 })
9819
Steven Valdez08b65f42016-12-07 15:29:45 -05009820 testCases = append(testCases, testCase{
9821 testType: clientTest,
9822 name: "TLS13-SendTicketEarlyDataInfo",
9823 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009824 MaxVersion: VersionTLS13,
9825 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009826 },
9827 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009828 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009829 "-expect-early-data-info",
9830 },
9831 })
9832
David Benjamin9b160662017-01-25 19:53:43 -05009833 // Test that 0-RTT tickets are ignored in clients unless opted in.
9834 testCases = append(testCases, testCase{
9835 testType: clientTest,
9836 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9837 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009838 MaxVersion: VersionTLS13,
9839 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009840 },
9841 })
9842
Steven Valdez08b65f42016-12-07 15:29:45 -05009843 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009844 testType: clientTest,
9845 name: "TLS13-DuplicateTicketEarlyDataInfo",
9846 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009847 MaxVersion: VersionTLS13,
9848 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009849 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009850 DuplicateTicketEarlyDataInfo: true,
9851 },
9852 },
9853 shouldFail: true,
9854 expectedError: ":DUPLICATE_EXTENSION:",
9855 expectedLocalError: "remote error: illegal parameter",
9856 })
9857
9858 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009859 testType: serverTest,
9860 name: "TLS13-ExpectTicketEarlyDataInfo",
9861 config: Config{
9862 MaxVersion: VersionTLS13,
9863 Bugs: ProtocolBugs{
9864 ExpectTicketEarlyDataInfo: true,
9865 },
9866 },
9867 flags: []string{
9868 "-enable-early-data",
9869 },
9870 })
David Benjamin17b30832017-01-28 14:00:32 -05009871
9872 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9873 // is honored.
9874 testCases = append(testCases, testCase{
9875 testType: clientTest,
9876 name: "TLS13-HonorServerSessionTicketLifetime",
9877 config: Config{
9878 MaxVersion: VersionTLS13,
9879 Bugs: ProtocolBugs{
9880 SendTicketLifetime: 20 * time.Second,
9881 },
9882 },
9883 flags: []string{
9884 "-resumption-delay", "19",
9885 },
9886 resumeSession: true,
9887 })
9888 testCases = append(testCases, testCase{
9889 testType: clientTest,
9890 name: "TLS13-HonorServerSessionTicketLifetime-2",
9891 config: Config{
9892 MaxVersion: VersionTLS13,
9893 Bugs: ProtocolBugs{
9894 SendTicketLifetime: 20 * time.Second,
9895 // The client should not offer the expired session.
9896 ExpectNoTLS13PSK: true,
9897 },
9898 },
9899 flags: []string{
9900 "-resumption-delay", "21",
9901 },
David Benjamin023d4192017-02-06 13:49:07 -05009902 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009903 expectResumeRejected: true,
9904 })
Steven Valdez5b986082016-09-01 12:29:49 -04009905}
9906
David Benjamin82261be2016-07-07 14:32:50 -07009907func addChangeCipherSpecTests() {
9908 // Test missing ChangeCipherSpecs.
9909 testCases = append(testCases, testCase{
9910 name: "SkipChangeCipherSpec-Client",
9911 config: Config{
9912 MaxVersion: VersionTLS12,
9913 Bugs: ProtocolBugs{
9914 SkipChangeCipherSpec: true,
9915 },
9916 },
9917 shouldFail: true,
9918 expectedError: ":UNEXPECTED_RECORD:",
9919 })
9920 testCases = append(testCases, testCase{
9921 testType: serverTest,
9922 name: "SkipChangeCipherSpec-Server",
9923 config: Config{
9924 MaxVersion: VersionTLS12,
9925 Bugs: ProtocolBugs{
9926 SkipChangeCipherSpec: true,
9927 },
9928 },
9929 shouldFail: true,
9930 expectedError: ":UNEXPECTED_RECORD:",
9931 })
9932 testCases = append(testCases, testCase{
9933 testType: serverTest,
9934 name: "SkipChangeCipherSpec-Server-NPN",
9935 config: Config{
9936 MaxVersion: VersionTLS12,
9937 NextProtos: []string{"bar"},
9938 Bugs: ProtocolBugs{
9939 SkipChangeCipherSpec: true,
9940 },
9941 },
9942 flags: []string{
9943 "-advertise-npn", "\x03foo\x03bar\x03baz",
9944 },
9945 shouldFail: true,
9946 expectedError: ":UNEXPECTED_RECORD:",
9947 })
9948
9949 // Test synchronization between the handshake and ChangeCipherSpec.
9950 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9951 // rejected. Test both with and without handshake packing to handle both
9952 // when the partial post-CCS message is in its own record and when it is
9953 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009954 for _, packed := range []bool{false, true} {
9955 var suffix string
9956 if packed {
9957 suffix = "-Packed"
9958 }
9959
9960 testCases = append(testCases, testCase{
9961 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9962 config: 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 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9974 config: Config{
9975 MaxVersion: VersionTLS12,
9976 },
9977 resumeSession: true,
9978 resumeConfig: &Config{
9979 MaxVersion: VersionTLS12,
9980 Bugs: ProtocolBugs{
9981 FragmentAcrossChangeCipherSpec: true,
9982 PackHandshakeFlight: packed,
9983 },
9984 },
9985 shouldFail: true,
9986 expectedError: ":UNEXPECTED_RECORD:",
9987 })
9988 testCases = append(testCases, testCase{
9989 testType: serverTest,
9990 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9991 config: Config{
9992 MaxVersion: VersionTLS12,
9993 Bugs: ProtocolBugs{
9994 FragmentAcrossChangeCipherSpec: true,
9995 PackHandshakeFlight: packed,
9996 },
9997 },
9998 shouldFail: true,
9999 expectedError: ":UNEXPECTED_RECORD:",
10000 })
10001 testCases = append(testCases, testCase{
10002 testType: serverTest,
10003 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10004 config: Config{
10005 MaxVersion: VersionTLS12,
10006 },
10007 resumeSession: true,
10008 resumeConfig: &Config{
10009 MaxVersion: VersionTLS12,
10010 Bugs: ProtocolBugs{
10011 FragmentAcrossChangeCipherSpec: true,
10012 PackHandshakeFlight: packed,
10013 },
10014 },
10015 shouldFail: true,
10016 expectedError: ":UNEXPECTED_RECORD:",
10017 })
10018 testCases = append(testCases, testCase{
10019 testType: serverTest,
10020 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10021 config: Config{
10022 MaxVersion: VersionTLS12,
10023 NextProtos: []string{"bar"},
10024 Bugs: ProtocolBugs{
10025 FragmentAcrossChangeCipherSpec: true,
10026 PackHandshakeFlight: packed,
10027 },
10028 },
10029 flags: []string{
10030 "-advertise-npn", "\x03foo\x03bar\x03baz",
10031 },
10032 shouldFail: true,
10033 expectedError: ":UNEXPECTED_RECORD:",
10034 })
10035 }
10036
David Benjamin61672812016-07-14 23:10:43 -040010037 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10038 // messages in the handshake queue. Do this by testing the server
10039 // reading the client Finished, reversing the flight so Finished comes
10040 // first.
10041 testCases = append(testCases, testCase{
10042 protocol: dtls,
10043 testType: serverTest,
10044 name: "SendUnencryptedFinished-DTLS",
10045 config: Config{
10046 MaxVersion: VersionTLS12,
10047 Bugs: ProtocolBugs{
10048 SendUnencryptedFinished: true,
10049 ReverseHandshakeFragments: true,
10050 },
10051 },
10052 shouldFail: true,
10053 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10054 })
10055
Steven Valdez143e8b32016-07-11 13:19:03 -040010056 // Test synchronization between encryption changes and the handshake in
10057 // TLS 1.3, where ChangeCipherSpec is implicit.
10058 testCases = append(testCases, testCase{
10059 name: "PartialEncryptedExtensionsWithServerHello",
10060 config: Config{
10061 MaxVersion: VersionTLS13,
10062 Bugs: ProtocolBugs{
10063 PartialEncryptedExtensionsWithServerHello: true,
10064 },
10065 },
10066 shouldFail: true,
10067 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10068 })
10069 testCases = append(testCases, testCase{
10070 testType: serverTest,
10071 name: "PartialClientFinishedWithClientHello",
10072 config: Config{
10073 MaxVersion: VersionTLS13,
10074 Bugs: ProtocolBugs{
10075 PartialClientFinishedWithClientHello: true,
10076 },
10077 },
10078 shouldFail: true,
10079 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10080 })
10081
David Benjamin82261be2016-07-07 14:32:50 -070010082 // Test that early ChangeCipherSpecs are handled correctly.
10083 testCases = append(testCases, testCase{
10084 testType: serverTest,
10085 name: "EarlyChangeCipherSpec-server-1",
10086 config: Config{
10087 MaxVersion: VersionTLS12,
10088 Bugs: ProtocolBugs{
10089 EarlyChangeCipherSpec: 1,
10090 },
10091 },
10092 shouldFail: true,
10093 expectedError: ":UNEXPECTED_RECORD:",
10094 })
10095 testCases = append(testCases, testCase{
10096 testType: serverTest,
10097 name: "EarlyChangeCipherSpec-server-2",
10098 config: Config{
10099 MaxVersion: VersionTLS12,
10100 Bugs: ProtocolBugs{
10101 EarlyChangeCipherSpec: 2,
10102 },
10103 },
10104 shouldFail: true,
10105 expectedError: ":UNEXPECTED_RECORD:",
10106 })
10107 testCases = append(testCases, testCase{
10108 protocol: dtls,
10109 name: "StrayChangeCipherSpec",
10110 config: Config{
10111 // TODO(davidben): Once DTLS 1.3 exists, test
10112 // that stray ChangeCipherSpec messages are
10113 // rejected.
10114 MaxVersion: VersionTLS12,
10115 Bugs: ProtocolBugs{
10116 StrayChangeCipherSpec: true,
10117 },
10118 },
10119 })
10120
David Benjaminb0c761e2017-06-25 22:42:55 -040010121 // Test that reordered ChangeCipherSpecs are tolerated.
10122 testCases = append(testCases, testCase{
10123 protocol: dtls,
10124 name: "ReorderChangeCipherSpec-DTLS-Client",
10125 config: Config{
10126 MaxVersion: VersionTLS12,
10127 Bugs: ProtocolBugs{
10128 ReorderChangeCipherSpec: true,
10129 },
10130 },
10131 resumeSession: true,
10132 })
10133 testCases = append(testCases, testCase{
10134 testType: serverTest,
10135 protocol: dtls,
10136 name: "ReorderChangeCipherSpec-DTLS-Server",
10137 config: Config{
10138 MaxVersion: VersionTLS12,
10139 Bugs: ProtocolBugs{
10140 ReorderChangeCipherSpec: true,
10141 },
10142 },
10143 resumeSession: true,
10144 })
10145
David Benjamin82261be2016-07-07 14:32:50 -070010146 // Test that the contents of ChangeCipherSpec are checked.
10147 testCases = append(testCases, testCase{
10148 name: "BadChangeCipherSpec-1",
10149 config: Config{
10150 MaxVersion: VersionTLS12,
10151 Bugs: ProtocolBugs{
10152 BadChangeCipherSpec: []byte{2},
10153 },
10154 },
10155 shouldFail: true,
10156 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10157 })
10158 testCases = append(testCases, testCase{
10159 name: "BadChangeCipherSpec-2",
10160 config: Config{
10161 MaxVersion: VersionTLS12,
10162 Bugs: ProtocolBugs{
10163 BadChangeCipherSpec: []byte{1, 1},
10164 },
10165 },
10166 shouldFail: true,
10167 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10168 })
10169 testCases = append(testCases, testCase{
10170 protocol: dtls,
10171 name: "BadChangeCipherSpec-DTLS-1",
10172 config: Config{
10173 MaxVersion: VersionTLS12,
10174 Bugs: ProtocolBugs{
10175 BadChangeCipherSpec: []byte{2},
10176 },
10177 },
10178 shouldFail: true,
10179 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10180 })
10181 testCases = append(testCases, testCase{
10182 protocol: dtls,
10183 name: "BadChangeCipherSpec-DTLS-2",
10184 config: Config{
10185 MaxVersion: VersionTLS12,
10186 Bugs: ProtocolBugs{
10187 BadChangeCipherSpec: []byte{1, 1},
10188 },
10189 },
10190 shouldFail: true,
10191 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10192 })
10193}
10194
David Benjamincd2c8062016-09-09 11:28:16 -040010195type perMessageTest struct {
10196 messageType uint8
10197 test testCase
10198}
10199
10200// makePerMessageTests returns a series of test templates which cover each
10201// message in the TLS handshake. These may be used with bugs like
10202// WrongMessageType to fully test a per-message bug.
10203func makePerMessageTests() []perMessageTest {
10204 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010205 for _, protocol := range []protocol{tls, dtls} {
10206 var suffix string
10207 if protocol == dtls {
10208 suffix = "-DTLS"
10209 }
10210
David Benjamincd2c8062016-09-09 11:28:16 -040010211 ret = append(ret, perMessageTest{
10212 messageType: typeClientHello,
10213 test: testCase{
10214 protocol: protocol,
10215 testType: serverTest,
10216 name: "ClientHello" + suffix,
10217 config: Config{
10218 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010219 },
10220 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010221 })
10222
10223 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010224 ret = append(ret, perMessageTest{
10225 messageType: typeHelloVerifyRequest,
10226 test: testCase{
10227 protocol: protocol,
10228 name: "HelloVerifyRequest" + suffix,
10229 config: Config{
10230 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010231 },
10232 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010233 })
10234 }
10235
David Benjamincd2c8062016-09-09 11:28:16 -040010236 ret = append(ret, perMessageTest{
10237 messageType: typeServerHello,
10238 test: testCase{
10239 protocol: protocol,
10240 name: "ServerHello" + suffix,
10241 config: Config{
10242 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010243 },
10244 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010245 })
10246
David Benjamincd2c8062016-09-09 11:28:16 -040010247 ret = append(ret, perMessageTest{
10248 messageType: typeCertificate,
10249 test: testCase{
10250 protocol: protocol,
10251 name: "ServerCertificate" + suffix,
10252 config: Config{
10253 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010254 },
10255 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010256 })
10257
David Benjamincd2c8062016-09-09 11:28:16 -040010258 ret = append(ret, perMessageTest{
10259 messageType: typeCertificateStatus,
10260 test: testCase{
10261 protocol: protocol,
10262 name: "CertificateStatus" + suffix,
10263 config: Config{
10264 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010265 },
David Benjamincd2c8062016-09-09 11:28:16 -040010266 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010267 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010268 })
10269
David Benjamincd2c8062016-09-09 11:28:16 -040010270 ret = append(ret, perMessageTest{
10271 messageType: typeServerKeyExchange,
10272 test: testCase{
10273 protocol: protocol,
10274 name: "ServerKeyExchange" + suffix,
10275 config: Config{
10276 MaxVersion: VersionTLS12,
10277 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010278 },
10279 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010280 })
10281
David Benjamincd2c8062016-09-09 11:28:16 -040010282 ret = append(ret, perMessageTest{
10283 messageType: typeCertificateRequest,
10284 test: testCase{
10285 protocol: protocol,
10286 name: "CertificateRequest" + suffix,
10287 config: Config{
10288 MaxVersion: VersionTLS12,
10289 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010290 },
10291 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010292 })
10293
David Benjamincd2c8062016-09-09 11:28:16 -040010294 ret = append(ret, perMessageTest{
10295 messageType: typeServerHelloDone,
10296 test: testCase{
10297 protocol: protocol,
10298 name: "ServerHelloDone" + suffix,
10299 config: Config{
10300 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010301 },
10302 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010303 })
10304
David Benjamincd2c8062016-09-09 11:28:16 -040010305 ret = append(ret, perMessageTest{
10306 messageType: typeCertificate,
10307 test: testCase{
10308 testType: serverTest,
10309 protocol: protocol,
10310 name: "ClientCertificate" + suffix,
10311 config: Config{
10312 Certificates: []Certificate{rsaCertificate},
10313 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010314 },
David Benjamincd2c8062016-09-09 11:28:16 -040010315 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010316 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010317 })
10318
David Benjamincd2c8062016-09-09 11:28:16 -040010319 ret = append(ret, perMessageTest{
10320 messageType: typeCertificateVerify,
10321 test: testCase{
10322 testType: serverTest,
10323 protocol: protocol,
10324 name: "CertificateVerify" + suffix,
10325 config: Config{
10326 Certificates: []Certificate{rsaCertificate},
10327 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010328 },
David Benjamincd2c8062016-09-09 11:28:16 -040010329 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010330 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010331 })
10332
David Benjamincd2c8062016-09-09 11:28:16 -040010333 ret = append(ret, perMessageTest{
10334 messageType: typeClientKeyExchange,
10335 test: testCase{
10336 testType: serverTest,
10337 protocol: protocol,
10338 name: "ClientKeyExchange" + suffix,
10339 config: Config{
10340 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010341 },
10342 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010343 })
10344
10345 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010346 ret = append(ret, perMessageTest{
10347 messageType: typeNextProtocol,
10348 test: testCase{
10349 testType: serverTest,
10350 protocol: protocol,
10351 name: "NextProtocol" + suffix,
10352 config: Config{
10353 MaxVersion: VersionTLS12,
10354 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010355 },
David Benjamincd2c8062016-09-09 11:28:16 -040010356 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010357 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010358 })
10359
David Benjamincd2c8062016-09-09 11:28:16 -040010360 ret = append(ret, perMessageTest{
10361 messageType: typeChannelID,
10362 test: testCase{
10363 testType: serverTest,
10364 protocol: protocol,
10365 name: "ChannelID" + suffix,
10366 config: Config{
10367 MaxVersion: VersionTLS12,
10368 ChannelID: channelIDKey,
10369 },
10370 flags: []string{
10371 "-expect-channel-id",
10372 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010373 },
10374 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010375 })
10376 }
10377
David Benjamincd2c8062016-09-09 11:28:16 -040010378 ret = append(ret, perMessageTest{
10379 messageType: typeFinished,
10380 test: testCase{
10381 testType: serverTest,
10382 protocol: protocol,
10383 name: "ClientFinished" + suffix,
10384 config: Config{
10385 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010386 },
10387 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010388 })
10389
David Benjamincd2c8062016-09-09 11:28:16 -040010390 ret = append(ret, perMessageTest{
10391 messageType: typeNewSessionTicket,
10392 test: testCase{
10393 protocol: protocol,
10394 name: "NewSessionTicket" + suffix,
10395 config: Config{
10396 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010397 },
10398 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010399 })
10400
David Benjamincd2c8062016-09-09 11:28:16 -040010401 ret = append(ret, perMessageTest{
10402 messageType: typeFinished,
10403 test: testCase{
10404 protocol: protocol,
10405 name: "ServerFinished" + suffix,
10406 config: Config{
10407 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010408 },
10409 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010410 })
10411
10412 }
David Benjamincd2c8062016-09-09 11:28:16 -040010413
10414 ret = append(ret, perMessageTest{
10415 messageType: typeClientHello,
10416 test: testCase{
10417 testType: serverTest,
10418 name: "TLS13-ClientHello",
10419 config: Config{
10420 MaxVersion: VersionTLS13,
10421 },
10422 },
10423 })
10424
10425 ret = append(ret, perMessageTest{
10426 messageType: typeServerHello,
10427 test: testCase{
10428 name: "TLS13-ServerHello",
10429 config: Config{
10430 MaxVersion: VersionTLS13,
10431 },
10432 },
10433 })
10434
10435 ret = append(ret, perMessageTest{
10436 messageType: typeEncryptedExtensions,
10437 test: testCase{
10438 name: "TLS13-EncryptedExtensions",
10439 config: Config{
10440 MaxVersion: VersionTLS13,
10441 },
10442 },
10443 })
10444
10445 ret = append(ret, perMessageTest{
10446 messageType: typeCertificateRequest,
10447 test: testCase{
10448 name: "TLS13-CertificateRequest",
10449 config: Config{
10450 MaxVersion: VersionTLS13,
10451 ClientAuth: RequireAnyClientCert,
10452 },
10453 },
10454 })
10455
10456 ret = append(ret, perMessageTest{
10457 messageType: typeCertificate,
10458 test: testCase{
10459 name: "TLS13-ServerCertificate",
10460 config: Config{
10461 MaxVersion: VersionTLS13,
10462 },
10463 },
10464 })
10465
10466 ret = append(ret, perMessageTest{
10467 messageType: typeCertificateVerify,
10468 test: testCase{
10469 name: "TLS13-ServerCertificateVerify",
10470 config: Config{
10471 MaxVersion: VersionTLS13,
10472 },
10473 },
10474 })
10475
10476 ret = append(ret, perMessageTest{
10477 messageType: typeFinished,
10478 test: testCase{
10479 name: "TLS13-ServerFinished",
10480 config: Config{
10481 MaxVersion: VersionTLS13,
10482 },
10483 },
10484 })
10485
10486 ret = append(ret, perMessageTest{
10487 messageType: typeCertificate,
10488 test: testCase{
10489 testType: serverTest,
10490 name: "TLS13-ClientCertificate",
10491 config: Config{
10492 Certificates: []Certificate{rsaCertificate},
10493 MaxVersion: VersionTLS13,
10494 },
10495 flags: []string{"-require-any-client-certificate"},
10496 },
10497 })
10498
10499 ret = append(ret, perMessageTest{
10500 messageType: typeCertificateVerify,
10501 test: testCase{
10502 testType: serverTest,
10503 name: "TLS13-ClientCertificateVerify",
10504 config: Config{
10505 Certificates: []Certificate{rsaCertificate},
10506 MaxVersion: VersionTLS13,
10507 },
10508 flags: []string{"-require-any-client-certificate"},
10509 },
10510 })
10511
10512 ret = append(ret, perMessageTest{
10513 messageType: typeFinished,
10514 test: testCase{
10515 testType: serverTest,
10516 name: "TLS13-ClientFinished",
10517 config: Config{
10518 MaxVersion: VersionTLS13,
10519 },
10520 },
10521 })
10522
10523 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010524}
10525
David Benjamincd2c8062016-09-09 11:28:16 -040010526func addWrongMessageTypeTests() {
10527 for _, t := range makePerMessageTests() {
10528 t.test.name = "WrongMessageType-" + t.test.name
10529 t.test.config.Bugs.SendWrongMessageType = t.messageType
10530 t.test.shouldFail = true
10531 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10532 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010533
David Benjamincd2c8062016-09-09 11:28:16 -040010534 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10535 // In TLS 1.3, a bad ServerHello means the client sends
10536 // an unencrypted alert while the server expects
10537 // encryption, so the alert is not readable by runner.
10538 t.test.expectedLocalError = "local error: bad record MAC"
10539 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010540
David Benjamincd2c8062016-09-09 11:28:16 -040010541 testCases = append(testCases, t.test)
10542 }
David Benjaminebacdee2017-04-08 11:00:45 -040010543
10544 // The processing order for TLS 1.3 version negotiation is such that one
10545 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10546 // TLS 1.2. Test that we do not do this.
10547 testCases = append(testCases, testCase{
10548 name: "SendServerHelloAsHelloRetryRequest",
10549 config: Config{
10550 MaxVersion: VersionTLS12,
10551 Bugs: ProtocolBugs{
10552 SendServerHelloAsHelloRetryRequest: true,
10553 },
10554 },
10555 shouldFail: true,
10556 expectedError: ":UNEXPECTED_MESSAGE:",
10557 expectedLocalError: "remote error: unexpected message",
10558 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010559}
10560
David Benjamin639846e2016-09-09 11:41:18 -040010561func addTrailingMessageDataTests() {
10562 for _, t := range makePerMessageTests() {
10563 t.test.name = "TrailingMessageData-" + t.test.name
10564 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10565 t.test.shouldFail = true
10566 t.test.expectedError = ":DECODE_ERROR:"
10567 t.test.expectedLocalError = "remote error: error decoding message"
10568
10569 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10570 // In TLS 1.3, a bad ServerHello means the client sends
10571 // an unencrypted alert while the server expects
10572 // encryption, so the alert is not readable by runner.
10573 t.test.expectedLocalError = "local error: bad record MAC"
10574 }
10575
10576 if t.messageType == typeFinished {
10577 // Bad Finished messages read as the verify data having
10578 // the wrong length.
10579 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10580 t.test.expectedLocalError = "remote error: error decrypting message"
10581 }
10582
10583 testCases = append(testCases, t.test)
10584 }
10585}
10586
Steven Valdez143e8b32016-07-11 13:19:03 -040010587func addTLS13HandshakeTests() {
10588 testCases = append(testCases, testCase{
10589 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010590 name: "NegotiatePSKResumption-TLS13",
10591 config: Config{
10592 MaxVersion: VersionTLS13,
10593 Bugs: ProtocolBugs{
10594 NegotiatePSKResumption: true,
10595 },
10596 },
10597 resumeSession: true,
10598 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010599 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010600 })
10601
10602 testCases = append(testCases, testCase{
10603 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010604 name: "MissingKeyShare-Client",
10605 config: Config{
10606 MaxVersion: VersionTLS13,
10607 Bugs: ProtocolBugs{
10608 MissingKeyShare: true,
10609 },
10610 },
10611 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010612 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010613 })
10614
10615 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010616 testType: serverTest,
10617 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010618 config: Config{
10619 MaxVersion: VersionTLS13,
10620 Bugs: ProtocolBugs{
10621 MissingKeyShare: true,
10622 },
10623 },
10624 shouldFail: true,
10625 expectedError: ":MISSING_KEY_SHARE:",
10626 })
10627
10628 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010629 testType: serverTest,
10630 name: "DuplicateKeyShares",
10631 config: Config{
10632 MaxVersion: VersionTLS13,
10633 Bugs: ProtocolBugs{
10634 DuplicateKeyShares: true,
10635 },
10636 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010637 shouldFail: true,
10638 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010639 })
10640
10641 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010642 testType: serverTest,
10643 name: "SkipEarlyData",
10644 config: Config{
10645 MaxVersion: VersionTLS13,
10646 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010647 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010648 },
10649 },
10650 })
10651
10652 testCases = append(testCases, testCase{
10653 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010654 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010655 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010656 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010657 Bugs: ProtocolBugs{
10658 SendFakeEarlyDataLength: 4,
10659 },
10660 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010661 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010662 })
10663
10664 testCases = append(testCases, testCase{
10665 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010666 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10667 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010668 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010669 Bugs: ProtocolBugs{
10670 SendFakeEarlyDataLength: 4,
10671 },
10672 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010673 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010674 })
10675
10676 testCases = append(testCases, testCase{
10677 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010678 name: "SkipEarlyData-OmitEarlyDataExtension",
10679 config: Config{
10680 MaxVersion: VersionTLS13,
10681 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010682 SendFakeEarlyDataLength: 4,
10683 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010684 },
10685 },
10686 shouldFail: true,
10687 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10688 })
10689
10690 testCases = append(testCases, testCase{
10691 testType: serverTest,
10692 name: "SkipEarlyData-TooMuchData",
10693 config: Config{
10694 MaxVersion: VersionTLS13,
10695 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010696 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010697 },
10698 },
10699 shouldFail: true,
10700 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10701 })
10702
10703 testCases = append(testCases, testCase{
10704 testType: serverTest,
10705 name: "SkipEarlyData-Interleaved",
10706 config: Config{
10707 MaxVersion: VersionTLS13,
10708 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010709 SendFakeEarlyDataLength: 4,
10710 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010711 },
10712 },
10713 shouldFail: true,
10714 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10715 })
10716
10717 testCases = append(testCases, testCase{
10718 testType: serverTest,
10719 name: "SkipEarlyData-EarlyDataInTLS12",
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 },
10726 shouldFail: true,
10727 expectedError: ":UNEXPECTED_RECORD:",
10728 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10729 })
10730
10731 testCases = append(testCases, testCase{
10732 testType: serverTest,
10733 name: "SkipEarlyData-HRR",
10734 config: Config{
10735 MaxVersion: VersionTLS13,
10736 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010737 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010738 },
10739 DefaultCurves: []CurveID{},
10740 },
10741 })
10742
10743 testCases = append(testCases, testCase{
10744 testType: serverTest,
10745 name: "SkipEarlyData-HRR-Interleaved",
10746 config: Config{
10747 MaxVersion: VersionTLS13,
10748 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010749 SendFakeEarlyDataLength: 4,
10750 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010751 },
10752 DefaultCurves: []CurveID{},
10753 },
10754 shouldFail: true,
10755 expectedError: ":UNEXPECTED_RECORD:",
10756 })
10757
10758 testCases = append(testCases, testCase{
10759 testType: serverTest,
10760 name: "SkipEarlyData-HRR-TooMuchData",
10761 config: Config{
10762 MaxVersion: VersionTLS13,
10763 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010764 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010765 },
10766 DefaultCurves: []CurveID{},
10767 },
10768 shouldFail: true,
10769 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10770 })
10771
10772 // Test that skipping early data looking for cleartext correctly
10773 // processes an alert record.
10774 testCases = append(testCases, testCase{
10775 testType: serverTest,
10776 name: "SkipEarlyData-HRR-FatalAlert",
10777 config: Config{
10778 MaxVersion: VersionTLS13,
10779 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010780 SendEarlyAlert: true,
10781 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010782 },
10783 DefaultCurves: []CurveID{},
10784 },
10785 shouldFail: true,
10786 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10787 })
10788
10789 testCases = append(testCases, testCase{
10790 testType: serverTest,
10791 name: "SkipEarlyData-SecondClientHelloEarlyData",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 Bugs: ProtocolBugs{
10795 SendEarlyDataOnSecondClientHello: true,
10796 },
10797 DefaultCurves: []CurveID{},
10798 },
10799 shouldFail: true,
10800 expectedLocalError: "remote error: bad record MAC",
10801 })
10802
10803 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010804 testType: clientTest,
10805 name: "EmptyEncryptedExtensions",
10806 config: Config{
10807 MaxVersion: VersionTLS13,
10808 Bugs: ProtocolBugs{
10809 EmptyEncryptedExtensions: true,
10810 },
10811 },
10812 shouldFail: true,
10813 expectedLocalError: "remote error: error decoding message",
10814 })
10815
10816 testCases = append(testCases, testCase{
10817 testType: clientTest,
10818 name: "EncryptedExtensionsWithKeyShare",
10819 config: Config{
10820 MaxVersion: VersionTLS13,
10821 Bugs: ProtocolBugs{
10822 EncryptedExtensionsWithKeyShare: true,
10823 },
10824 },
10825 shouldFail: true,
10826 expectedLocalError: "remote error: unsupported extension",
10827 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010828
10829 testCases = append(testCases, testCase{
10830 testType: serverTest,
10831 name: "SendHelloRetryRequest",
10832 config: Config{
10833 MaxVersion: VersionTLS13,
10834 // Require a HelloRetryRequest for every curve.
10835 DefaultCurves: []CurveID{},
10836 },
10837 expectedCurveID: CurveX25519,
10838 })
10839
10840 testCases = append(testCases, testCase{
10841 testType: serverTest,
10842 name: "SendHelloRetryRequest-2",
10843 config: Config{
10844 MaxVersion: VersionTLS13,
10845 DefaultCurves: []CurveID{CurveP384},
10846 },
10847 // Although the ClientHello did not predict our preferred curve,
10848 // we always select it whether it is predicted or not.
10849 expectedCurveID: CurveX25519,
10850 })
10851
10852 testCases = append(testCases, testCase{
10853 name: "UnknownCurve-HelloRetryRequest",
10854 config: Config{
10855 MaxVersion: VersionTLS13,
10856 // P-384 requires HelloRetryRequest in BoringSSL.
10857 CurvePreferences: []CurveID{CurveP384},
10858 Bugs: ProtocolBugs{
10859 SendHelloRetryRequestCurve: bogusCurve,
10860 },
10861 },
10862 shouldFail: true,
10863 expectedError: ":WRONG_CURVE:",
10864 })
10865
10866 testCases = append(testCases, testCase{
10867 name: "DisabledCurve-HelloRetryRequest",
10868 config: Config{
10869 MaxVersion: VersionTLS13,
10870 CurvePreferences: []CurveID{CurveP256},
10871 Bugs: ProtocolBugs{
10872 IgnorePeerCurvePreferences: true,
10873 },
10874 },
10875 flags: []string{"-p384-only"},
10876 shouldFail: true,
10877 expectedError: ":WRONG_CURVE:",
10878 })
10879
10880 testCases = append(testCases, testCase{
10881 name: "UnnecessaryHelloRetryRequest",
10882 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010883 MaxVersion: VersionTLS13,
10884 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010885 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010886 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010887 },
10888 },
10889 shouldFail: true,
10890 expectedError: ":WRONG_CURVE:",
10891 })
10892
10893 testCases = append(testCases, testCase{
10894 name: "SecondHelloRetryRequest",
10895 config: Config{
10896 MaxVersion: VersionTLS13,
10897 // P-384 requires HelloRetryRequest in BoringSSL.
10898 CurvePreferences: []CurveID{CurveP384},
10899 Bugs: ProtocolBugs{
10900 SecondHelloRetryRequest: true,
10901 },
10902 },
10903 shouldFail: true,
10904 expectedError: ":UNEXPECTED_MESSAGE:",
10905 })
10906
10907 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010908 name: "HelloRetryRequest-Empty",
10909 config: Config{
10910 MaxVersion: VersionTLS13,
10911 Bugs: ProtocolBugs{
10912 AlwaysSendHelloRetryRequest: true,
10913 },
10914 },
10915 shouldFail: true,
10916 expectedError: ":DECODE_ERROR:",
10917 })
10918
10919 testCases = append(testCases, testCase{
10920 name: "HelloRetryRequest-DuplicateCurve",
10921 config: Config{
10922 MaxVersion: VersionTLS13,
10923 // P-384 requires a HelloRetryRequest against BoringSSL's default
10924 // configuration. Assert this ExpectMissingKeyShare.
10925 CurvePreferences: []CurveID{CurveP384},
10926 Bugs: ProtocolBugs{
10927 ExpectMissingKeyShare: true,
10928 DuplicateHelloRetryRequestExtensions: true,
10929 },
10930 },
10931 shouldFail: true,
10932 expectedError: ":DUPLICATE_EXTENSION:",
10933 expectedLocalError: "remote error: illegal parameter",
10934 })
10935
10936 testCases = append(testCases, testCase{
10937 name: "HelloRetryRequest-Cookie",
10938 config: Config{
10939 MaxVersion: VersionTLS13,
10940 Bugs: ProtocolBugs{
10941 SendHelloRetryRequestCookie: []byte("cookie"),
10942 },
10943 },
10944 })
10945
10946 testCases = append(testCases, testCase{
10947 name: "HelloRetryRequest-DuplicateCookie",
10948 config: Config{
10949 MaxVersion: VersionTLS13,
10950 Bugs: ProtocolBugs{
10951 SendHelloRetryRequestCookie: []byte("cookie"),
10952 DuplicateHelloRetryRequestExtensions: true,
10953 },
10954 },
10955 shouldFail: true,
10956 expectedError: ":DUPLICATE_EXTENSION:",
10957 expectedLocalError: "remote error: illegal parameter",
10958 })
10959
10960 testCases = append(testCases, testCase{
10961 name: "HelloRetryRequest-EmptyCookie",
10962 config: Config{
10963 MaxVersion: VersionTLS13,
10964 Bugs: ProtocolBugs{
10965 SendHelloRetryRequestCookie: []byte{},
10966 },
10967 },
10968 shouldFail: true,
10969 expectedError: ":DECODE_ERROR:",
10970 })
10971
10972 testCases = append(testCases, testCase{
10973 name: "HelloRetryRequest-Cookie-Curve",
10974 config: Config{
10975 MaxVersion: VersionTLS13,
10976 // P-384 requires HelloRetryRequest in BoringSSL.
10977 CurvePreferences: []CurveID{CurveP384},
10978 Bugs: ProtocolBugs{
10979 SendHelloRetryRequestCookie: []byte("cookie"),
10980 ExpectMissingKeyShare: true,
10981 },
10982 },
10983 })
10984
10985 testCases = append(testCases, testCase{
10986 name: "HelloRetryRequest-Unknown",
10987 config: Config{
10988 MaxVersion: VersionTLS13,
10989 Bugs: ProtocolBugs{
10990 CustomHelloRetryRequestExtension: "extension",
10991 },
10992 },
10993 shouldFail: true,
10994 expectedError: ":UNEXPECTED_EXTENSION:",
10995 expectedLocalError: "remote error: unsupported extension",
10996 })
10997
10998 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010999 testType: serverTest,
11000 name: "SecondClientHelloMissingKeyShare",
11001 config: Config{
11002 MaxVersion: VersionTLS13,
11003 DefaultCurves: []CurveID{},
11004 Bugs: ProtocolBugs{
11005 SecondClientHelloMissingKeyShare: true,
11006 },
11007 },
11008 shouldFail: true,
11009 expectedError: ":MISSING_KEY_SHARE:",
11010 })
11011
11012 testCases = append(testCases, testCase{
11013 testType: serverTest,
11014 name: "SecondClientHelloWrongCurve",
11015 config: Config{
11016 MaxVersion: VersionTLS13,
11017 DefaultCurves: []CurveID{},
11018 Bugs: ProtocolBugs{
11019 MisinterpretHelloRetryRequestCurve: CurveP521,
11020 },
11021 },
11022 shouldFail: true,
11023 expectedError: ":WRONG_CURVE:",
11024 })
11025
11026 testCases = append(testCases, testCase{
11027 name: "HelloRetryRequestVersionMismatch",
11028 config: Config{
11029 MaxVersion: VersionTLS13,
11030 // P-384 requires HelloRetryRequest in BoringSSL.
11031 CurvePreferences: []CurveID{CurveP384},
11032 Bugs: ProtocolBugs{
11033 SendServerHelloVersion: 0x0305,
11034 },
11035 },
11036 shouldFail: true,
11037 expectedError: ":WRONG_VERSION_NUMBER:",
11038 })
11039
11040 testCases = append(testCases, testCase{
11041 name: "HelloRetryRequestCurveMismatch",
11042 config: Config{
11043 MaxVersion: VersionTLS13,
11044 // P-384 requires HelloRetryRequest in BoringSSL.
11045 CurvePreferences: []CurveID{CurveP384},
11046 Bugs: ProtocolBugs{
11047 // Send P-384 (correct) in the HelloRetryRequest.
11048 SendHelloRetryRequestCurve: CurveP384,
11049 // But send P-256 in the ServerHello.
11050 SendCurve: CurveP256,
11051 },
11052 },
11053 shouldFail: true,
11054 expectedError: ":WRONG_CURVE:",
11055 })
11056
11057 // Test the server selecting a curve that requires a HelloRetryRequest
11058 // without sending it.
11059 testCases = append(testCases, testCase{
11060 name: "SkipHelloRetryRequest",
11061 config: Config{
11062 MaxVersion: VersionTLS13,
11063 // P-384 requires HelloRetryRequest in BoringSSL.
11064 CurvePreferences: []CurveID{CurveP384},
11065 Bugs: ProtocolBugs{
11066 SkipHelloRetryRequest: true,
11067 },
11068 },
11069 shouldFail: true,
11070 expectedError: ":WRONG_CURVE:",
11071 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011072
11073 testCases = append(testCases, testCase{
11074 name: "TLS13-RequestContextInHandshake",
11075 config: Config{
11076 MaxVersion: VersionTLS13,
11077 MinVersion: VersionTLS13,
11078 ClientAuth: RequireAnyClientCert,
11079 Bugs: ProtocolBugs{
11080 SendRequestContext: []byte("request context"),
11081 },
11082 },
11083 flags: []string{
11084 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11085 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11086 },
11087 shouldFail: true,
11088 expectedError: ":DECODE_ERROR:",
11089 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011090
11091 testCases = append(testCases, testCase{
11092 testType: serverTest,
11093 name: "TLS13-TrailingKeyShareData",
11094 config: Config{
11095 MaxVersion: VersionTLS13,
11096 Bugs: ProtocolBugs{
11097 TrailingKeyShareData: true,
11098 },
11099 },
11100 shouldFail: true,
11101 expectedError: ":DECODE_ERROR:",
11102 })
David Benjamin7f78df42016-10-05 22:33:19 -040011103
11104 testCases = append(testCases, testCase{
11105 name: "TLS13-AlwaysSelectPSKIdentity",
11106 config: Config{
11107 MaxVersion: VersionTLS13,
11108 Bugs: ProtocolBugs{
11109 AlwaysSelectPSKIdentity: true,
11110 },
11111 },
11112 shouldFail: true,
11113 expectedError: ":UNEXPECTED_EXTENSION:",
11114 })
11115
11116 testCases = append(testCases, testCase{
11117 name: "TLS13-InvalidPSKIdentity",
11118 config: Config{
11119 MaxVersion: VersionTLS13,
11120 Bugs: ProtocolBugs{
11121 SelectPSKIdentityOnResume: 1,
11122 },
11123 },
11124 resumeSession: true,
11125 shouldFail: true,
11126 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11127 })
David Benjamin1286bee2016-10-07 15:25:06 -040011128
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011129 testCases = append(testCases, testCase{
11130 testType: serverTest,
11131 name: "TLS13-ExtraPSKIdentity",
11132 config: Config{
11133 MaxVersion: VersionTLS13,
11134 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011135 ExtraPSKIdentity: true,
11136 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011137 },
11138 },
11139 resumeSession: true,
11140 })
11141
David Benjamin1286bee2016-10-07 15:25:06 -040011142 // Test that unknown NewSessionTicket extensions are tolerated.
11143 testCases = append(testCases, testCase{
11144 name: "TLS13-CustomTicketExtension",
11145 config: Config{
11146 MaxVersion: VersionTLS13,
11147 Bugs: ProtocolBugs{
11148 CustomTicketExtension: "1234",
11149 },
11150 },
11151 })
Steven Valdez2d850622017-01-11 11:34:52 -050011152
Steven Valdez0e4a4482017-07-17 11:12:34 -040011153 for _, noSessionID := range []bool{false, true} {
11154 prefix := "TLS13Experiment"
11155 variant := TLS13Experiment
11156 if noSessionID {
11157 prefix = "TLS13NoSessionIDExperiment"
11158 variant = TLS13NoSessionIDExperiment
11159 }
11160
11161 // Test that enabling a TLS 1.3 variant does not interfere with
11162 // TLS 1.2 session ID resumption.
11163 testCases = append(testCases, testCase{
11164 testType: clientTest,
11165 name: prefix + "-ResumeTLS12SessionID",
11166 config: Config{
11167 MaxVersion: VersionTLS12,
11168 SessionTicketsDisabled: true,
11169 },
11170 resumeSession: true,
11171 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11172 })
11173
11174 // Test that the server correctly echoes back session IDs of
11175 // various lengths.
11176 testCases = append(testCases, testCase{
11177 testType: serverTest,
11178 name: prefix + "-EmptySessionID",
11179 config: Config{
11180 MaxVersion: VersionTLS13,
11181 Bugs: ProtocolBugs{
11182 SendClientHelloSessionID: []byte{},
11183 },
11184 },
11185 tls13Variant: variant,
11186 })
11187
11188 testCases = append(testCases, testCase{
11189 testType: serverTest,
11190 name: prefix + "-ShortSessionID",
11191 config: Config{
11192 MaxVersion: VersionTLS13,
11193 Bugs: ProtocolBugs{
11194 SendClientHelloSessionID: make([]byte, 16),
11195 },
11196 },
11197 tls13Variant: variant,
11198 })
11199
11200 testCases = append(testCases, testCase{
11201 testType: serverTest,
11202 name: prefix + "-FullSessionID",
11203 config: Config{
11204 MaxVersion: VersionTLS13,
11205 Bugs: ProtocolBugs{
11206 SendClientHelloSessionID: make([]byte, 32),
11207 },
11208 },
11209 tls13Variant: variant,
11210 })
11211 }
11212
11213 // Test that the client sends a fake session ID in TLS13Experiment.
11214 testCases = append(testCases, testCase{
11215 testType: clientTest,
11216 name: "TLS13Experiment-RequireSessionID",
11217 config: Config{
11218 MaxVersion: VersionTLS13,
11219 Bugs: ProtocolBugs{
11220 ExpectClientHelloSessionID: true,
11221 },
11222 },
11223 tls13Variant: TLS13Experiment,
11224 })
11225
11226 // Test that the client does not send a fake session ID in
11227 // TLS13NoSessionIDExperiment.
11228 testCases = append(testCases, testCase{
11229 testType: clientTest,
11230 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11231 config: Config{
11232 MaxVersion: VersionTLS13,
11233 Bugs: ProtocolBugs{
11234 ExpectEmptyClientHelloSessionID: true,
11235 },
11236 },
11237 tls13Variant: TLS13NoSessionIDExperiment,
11238 })
11239
Steven Valdez2d850622017-01-11 11:34:52 -050011240 testCases = append(testCases, testCase{
11241 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011242 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011243 config: Config{
11244 MaxVersion: VersionTLS13,
11245 MaxEarlyDataSize: 16384,
11246 },
11247 resumeConfig: &Config{
11248 MaxVersion: VersionTLS13,
11249 MaxEarlyDataSize: 16384,
11250 Bugs: ProtocolBugs{
11251 AlwaysRejectEarlyData: true,
11252 },
11253 },
11254 resumeSession: true,
11255 flags: []string{
11256 "-enable-early-data",
11257 "-expect-early-data-info",
11258 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011259 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011260 },
11261 })
11262
11263 testCases = append(testCases, testCase{
11264 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011265 name: "TLS13Experiment-EarlyData-Reject-Client",
11266 config: Config{
11267 MaxVersion: VersionTLS13,
11268 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011269 },
11270 resumeConfig: &Config{
11271 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011272 MaxEarlyDataSize: 16384,
11273 Bugs: ProtocolBugs{
11274 AlwaysRejectEarlyData: true,
11275 },
11276 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011277 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011278 resumeSession: true,
11279 flags: []string{
11280 "-enable-early-data",
11281 "-expect-early-data-info",
11282 "-expect-reject-early-data",
11283 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011284 },
11285 })
11286
11287 testCases = append(testCases, testCase{
11288 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011289 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11290 config: Config{
11291 MaxVersion: VersionTLS13,
11292 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011293 },
11294 resumeConfig: &Config{
11295 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011296 MaxEarlyDataSize: 16384,
11297 Bugs: ProtocolBugs{
11298 AlwaysRejectEarlyData: true,
11299 },
11300 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011301 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011302 resumeSession: true,
11303 flags: []string{
11304 "-enable-early-data",
11305 "-expect-early-data-info",
11306 "-expect-reject-early-data",
11307 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011308 },
11309 })
11310
11311 testCases = append(testCases, testCase{
11312 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011313 name: "TLS13-EarlyData-RejectTicket-Client",
11314 config: Config{
11315 MaxVersion: VersionTLS13,
11316 MaxEarlyDataSize: 16384,
11317 Certificates: []Certificate{rsaCertificate},
11318 },
11319 resumeConfig: &Config{
11320 MaxVersion: VersionTLS13,
11321 MaxEarlyDataSize: 16384,
11322 Certificates: []Certificate{ecdsaP256Certificate},
11323 SessionTicketsDisabled: true,
11324 },
11325 resumeSession: true,
11326 expectResumeRejected: true,
11327 flags: []string{
11328 "-enable-early-data",
11329 "-expect-early-data-info",
11330 "-expect-reject-early-data",
11331 "-on-resume-shim-writes-first",
11332 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11333 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11334 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11335 // Session tickets are disabled, so the runner will not send a ticket.
11336 "-on-retry-expect-no-session",
11337 },
11338 })
11339
11340 testCases = append(testCases, testCase{
11341 testType: clientTest,
11342 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011343 config: Config{
11344 MaxVersion: VersionTLS13,
11345 MaxEarlyDataSize: 16384,
11346 },
11347 resumeConfig: &Config{
11348 MaxVersion: VersionTLS13,
11349 MaxEarlyDataSize: 16384,
11350 Bugs: ProtocolBugs{
11351 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11352 },
11353 },
11354 resumeSession: true,
11355 flags: []string{
11356 "-enable-early-data",
11357 "-expect-early-data-info",
11358 "-expect-reject-early-data",
11359 },
11360 })
11361
11362 // The client must check the server does not send the early_data
11363 // extension while rejecting the session.
11364 testCases = append(testCases, testCase{
11365 testType: clientTest,
11366 name: "TLS13-EarlyDataWithoutResume-Client",
11367 config: Config{
11368 MaxVersion: VersionTLS13,
11369 MaxEarlyDataSize: 16384,
11370 },
11371 resumeConfig: &Config{
11372 MaxVersion: VersionTLS13,
11373 SessionTicketsDisabled: true,
11374 Bugs: ProtocolBugs{
11375 SendEarlyDataExtension: true,
11376 },
11377 },
11378 resumeSession: true,
11379 flags: []string{
11380 "-enable-early-data",
11381 "-expect-early-data-info",
11382 },
11383 shouldFail: true,
11384 expectedError: ":UNEXPECTED_EXTENSION:",
11385 })
11386
11387 // The client must fail with a dedicated error code if the server
11388 // responds with TLS 1.2 when offering 0-RTT.
11389 testCases = append(testCases, testCase{
11390 testType: clientTest,
11391 name: "TLS13-EarlyDataVersionDowngrade-Client",
11392 config: Config{
11393 MaxVersion: VersionTLS13,
11394 MaxEarlyDataSize: 16384,
11395 },
11396 resumeConfig: &Config{
11397 MaxVersion: VersionTLS12,
11398 },
11399 resumeSession: true,
11400 flags: []string{
11401 "-enable-early-data",
11402 "-expect-early-data-info",
11403 },
11404 shouldFail: true,
11405 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11406 })
11407
11408 // Test that the client rejects an (unsolicited) early_data extension if
11409 // the server sent an HRR.
11410 testCases = append(testCases, testCase{
11411 testType: clientTest,
11412 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11413 config: Config{
11414 MaxVersion: VersionTLS13,
11415 MaxEarlyDataSize: 16384,
11416 },
11417 resumeConfig: &Config{
11418 MaxVersion: VersionTLS13,
11419 MaxEarlyDataSize: 16384,
11420 Bugs: ProtocolBugs{
11421 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11422 SendEarlyDataExtension: true,
11423 },
11424 },
11425 resumeSession: true,
11426 flags: []string{
11427 "-enable-early-data",
11428 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011429 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011430 },
11431 shouldFail: true,
11432 expectedError: ":UNEXPECTED_EXTENSION:",
11433 })
11434
11435 fooString := "foo"
11436 barString := "bar"
11437
11438 // Test that the client reports the correct ALPN after a 0-RTT reject
11439 // that changed it.
11440 testCases = append(testCases, testCase{
11441 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011442 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011443 config: Config{
11444 MaxVersion: VersionTLS13,
11445 MaxEarlyDataSize: 16384,
11446 Bugs: ProtocolBugs{
11447 ALPNProtocol: &fooString,
11448 },
11449 },
11450 resumeConfig: &Config{
11451 MaxVersion: VersionTLS13,
11452 MaxEarlyDataSize: 16384,
11453 Bugs: ProtocolBugs{
11454 ALPNProtocol: &barString,
11455 },
11456 },
11457 resumeSession: true,
11458 flags: []string{
11459 "-advertise-alpn", "\x03foo\x03bar",
11460 "-enable-early-data",
11461 "-expect-early-data-info",
11462 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011463 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011464 "-on-resume-expect-alpn", "foo",
11465 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011466 },
11467 })
11468
11469 // Test that the client reports the correct ALPN after a 0-RTT reject if
11470 // ALPN was omitted from the first connection.
11471 testCases = append(testCases, testCase{
11472 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011473 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011474 config: Config{
11475 MaxVersion: VersionTLS13,
11476 MaxEarlyDataSize: 16384,
11477 },
11478 resumeConfig: &Config{
11479 MaxVersion: VersionTLS13,
11480 MaxEarlyDataSize: 16384,
11481 NextProtos: []string{"foo"},
11482 },
11483 resumeSession: true,
11484 flags: []string{
11485 "-advertise-alpn", "\x03foo\x03bar",
11486 "-enable-early-data",
11487 "-expect-early-data-info",
11488 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011489 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011490 "-on-resume-expect-alpn", "",
11491 "-on-retry-expect-alpn", "foo",
11492 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011493 },
11494 })
11495
11496 // Test that the client reports the correct ALPN after a 0-RTT reject if
11497 // ALPN was omitted from the second connection.
11498 testCases = append(testCases, testCase{
11499 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011500 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011501 config: Config{
11502 MaxVersion: VersionTLS13,
11503 MaxEarlyDataSize: 16384,
11504 NextProtos: []string{"foo"},
11505 },
11506 resumeConfig: &Config{
11507 MaxVersion: VersionTLS13,
11508 MaxEarlyDataSize: 16384,
11509 },
11510 resumeSession: true,
11511 flags: []string{
11512 "-advertise-alpn", "\x03foo\x03bar",
11513 "-enable-early-data",
11514 "-expect-early-data-info",
11515 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011516 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011517 "-on-resume-expect-alpn", "foo",
11518 "-on-retry-expect-alpn", "",
11519 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011520 },
11521 })
11522
11523 // Test that the client enforces ALPN match on 0-RTT accept.
11524 testCases = append(testCases, testCase{
11525 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011526 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011527 config: Config{
11528 MaxVersion: VersionTLS13,
11529 MaxEarlyDataSize: 16384,
11530 Bugs: ProtocolBugs{
11531 ALPNProtocol: &fooString,
11532 },
11533 },
11534 resumeConfig: &Config{
11535 MaxVersion: VersionTLS13,
11536 MaxEarlyDataSize: 16384,
11537 Bugs: ProtocolBugs{
11538 AlwaysAcceptEarlyData: true,
11539 ALPNProtocol: &barString,
11540 },
11541 },
11542 resumeSession: true,
11543 flags: []string{
11544 "-advertise-alpn", "\x03foo\x03bar",
11545 "-enable-early-data",
11546 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011547 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011548 "-on-resume-expect-alpn", "foo",
11549 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011550 },
11551 shouldFail: true,
11552 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11553 })
11554
11555 // Test that the server correctly rejects 0-RTT when the previous
11556 // session did not allow early data on resumption.
11557 testCases = append(testCases, testCase{
11558 testType: serverTest,
11559 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11560 config: Config{
11561 MaxVersion: VersionTLS13,
11562 },
11563 resumeConfig: &Config{
11564 MaxVersion: VersionTLS13,
11565 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011566 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011567 ExpectEarlyDataAccepted: false,
11568 },
11569 },
11570 resumeSession: true,
11571 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011572 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011573 "-expect-reject-early-data",
11574 },
11575 })
11576
11577 // Test that we reject early data where ALPN is omitted from the first
11578 // connection.
11579 testCases = append(testCases, testCase{
11580 testType: serverTest,
11581 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11582 config: Config{
11583 MaxVersion: VersionTLS13,
11584 NextProtos: []string{},
11585 },
11586 resumeConfig: &Config{
11587 MaxVersion: VersionTLS13,
11588 NextProtos: []string{"foo"},
11589 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011590 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011591 ExpectEarlyDataAccepted: false,
11592 },
11593 },
11594 resumeSession: true,
11595 flags: []string{
11596 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011597 "-on-initial-select-alpn", "",
11598 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011599 },
11600 })
11601
11602 // Test that we reject early data where ALPN is omitted from the second
11603 // connection.
11604 testCases = append(testCases, testCase{
11605 testType: serverTest,
11606 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11607 config: Config{
11608 MaxVersion: VersionTLS13,
11609 NextProtos: []string{"foo"},
11610 },
11611 resumeConfig: &Config{
11612 MaxVersion: VersionTLS13,
11613 NextProtos: []string{},
11614 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011615 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011616 ExpectEarlyDataAccepted: false,
11617 },
11618 },
11619 resumeSession: true,
11620 flags: []string{
11621 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011622 "-on-initial-select-alpn", "foo",
11623 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011624 },
11625 })
11626
11627 // Test that we reject early data with mismatched ALPN.
11628 testCases = append(testCases, testCase{
11629 testType: serverTest,
11630 name: "TLS13-EarlyData-ALPNMismatch-Server",
11631 config: Config{
11632 MaxVersion: VersionTLS13,
11633 NextProtos: []string{"foo"},
11634 },
11635 resumeConfig: &Config{
11636 MaxVersion: VersionTLS13,
11637 NextProtos: []string{"bar"},
11638 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011639 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011640 ExpectEarlyDataAccepted: false,
11641 },
11642 },
11643 resumeSession: true,
11644 flags: []string{
11645 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011646 "-on-initial-select-alpn", "foo",
11647 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011648 },
11649 })
11650
David Benjamin6bb507b2017-03-29 16:35:57 -050011651 // Test that the client offering 0-RTT and Channel ID forbids the server
11652 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011653 testCases = append(testCases, testCase{
11654 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011655 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011656 config: Config{
11657 MaxVersion: VersionTLS13,
11658 MaxEarlyDataSize: 16384,
11659 RequestChannelID: true,
11660 },
11661 resumeSession: true,
11662 expectChannelID: true,
11663 shouldFail: true,
11664 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11665 flags: []string{
11666 "-enable-early-data",
11667 "-expect-early-data-info",
11668 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11669 },
11670 })
11671
David Benjamin6bb507b2017-03-29 16:35:57 -050011672 // Test that the client offering Channel ID and 0-RTT allows the server
11673 // to decline 0-RTT.
11674 testCases = append(testCases, testCase{
11675 testType: clientTest,
11676 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11677 config: Config{
11678 MaxVersion: VersionTLS13,
11679 MaxEarlyDataSize: 16384,
11680 RequestChannelID: true,
11681 Bugs: ProtocolBugs{
11682 AlwaysRejectEarlyData: true,
11683 },
11684 },
11685 resumeSession: true,
11686 expectChannelID: true,
11687 flags: []string{
11688 "-enable-early-data",
11689 "-expect-early-data-info",
11690 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11691 "-expect-reject-early-data",
11692 },
11693 })
11694
11695 // Test that the client offering Channel ID and 0-RTT allows the server
11696 // to decline Channel ID.
11697 testCases = append(testCases, testCase{
11698 testType: clientTest,
11699 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11700 config: Config{
11701 MaxVersion: VersionTLS13,
11702 MaxEarlyDataSize: 16384,
11703 },
11704 resumeSession: true,
11705 flags: []string{
11706 "-enable-early-data",
11707 "-expect-early-data-info",
11708 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11709 "-expect-accept-early-data",
11710 },
11711 })
11712
11713 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11714 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011715 testCases = append(testCases, testCase{
11716 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011717 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011718 config: Config{
11719 MaxVersion: VersionTLS13,
11720 ChannelID: channelIDKey,
11721 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011722 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011723 ExpectEarlyDataAccepted: false,
11724 },
11725 },
11726 resumeSession: true,
11727 expectChannelID: true,
11728 flags: []string{
11729 "-enable-early-data",
11730 "-expect-reject-early-data",
11731 "-expect-channel-id",
11732 base64.StdEncoding.EncodeToString(channelIDBytes),
11733 },
11734 })
11735
David Benjamin6bb507b2017-03-29 16:35:57 -050011736 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11737 // if not offered Channel ID.
11738 testCases = append(testCases, testCase{
11739 testType: serverTest,
11740 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11741 config: Config{
11742 MaxVersion: VersionTLS13,
11743 Bugs: ProtocolBugs{
11744 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11745 ExpectEarlyDataAccepted: true,
11746 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11747 },
11748 },
11749 resumeSession: true,
11750 expectChannelID: false,
11751 flags: []string{
11752 "-enable-early-data",
11753 "-expect-accept-early-data",
11754 "-enable-channel-id",
11755 },
11756 })
11757
David Benjamin32c89272017-03-26 13:54:21 -050011758 // Test that the server rejects 0-RTT streams without end_of_early_data.
11759 // The subsequent records should fail to decrypt.
11760 testCases = append(testCases, testCase{
11761 testType: serverTest,
11762 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11763 config: Config{
11764 MaxVersion: VersionTLS13,
11765 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011766 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011767 ExpectEarlyDataAccepted: true,
11768 SkipEndOfEarlyData: true,
11769 },
11770 },
11771 resumeSession: true,
11772 flags: []string{"-enable-early-data"},
11773 shouldFail: true,
11774 expectedLocalError: "remote error: bad record MAC",
11775 expectedError: ":BAD_DECRYPT:",
11776 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011777
11778 testCases = append(testCases, testCase{
11779 testType: serverTest,
11780 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11781 config: Config{
11782 MaxVersion: VersionTLS13,
11783 },
11784 resumeConfig: &Config{
11785 MaxVersion: VersionTLS13,
11786 Bugs: ProtocolBugs{
11787 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11788 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011789 ExpectEarlyDataAccepted: true,
11790 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011791 },
11792 resumeSession: true,
11793 shouldFail: true,
11794 expectedError: ":UNEXPECTED_RECORD:",
11795 expectedLocalError: "remote error: unexpected message",
11796 flags: []string{
11797 "-enable-early-data",
11798 },
11799 })
David Benjamind9cbb532017-07-07 13:17:19 -040011800
11801 // Test that the client reports TLS 1.3 as the version while sending
11802 // early data.
11803 testCases = append(testCases, testCase{
11804 testType: clientTest,
11805 name: "TLS13-EarlyData-Client-VersionAPI",
11806 config: Config{
11807 MaxVersion: VersionTLS13,
11808 MaxEarlyDataSize: 16384,
11809 },
11810 resumeSession: true,
11811 flags: []string{
11812 "-enable-early-data",
11813 "-expect-early-data-info",
11814 "-expect-accept-early-data",
11815 "-expect-version", strconv.Itoa(VersionTLS13),
11816 },
11817 })
David Benjamin4a37de02017-08-08 20:15:40 -040011818
11819 // Test that client and server both notice handshake errors after data
11820 // has started flowing.
11821 testCases = append(testCases, testCase{
11822 testType: clientTest,
11823 name: "TLS13-EarlyData-Client-BadFinished",
11824 config: Config{
11825 MaxVersion: VersionTLS13,
11826 MaxEarlyDataSize: 16384,
11827 },
11828 resumeConfig: &Config{
11829 MaxVersion: VersionTLS13,
11830 MaxEarlyDataSize: 16384,
11831 Bugs: ProtocolBugs{
11832 BadFinished: true,
11833 },
11834 },
11835 resumeSession: true,
11836 flags: []string{
11837 "-enable-early-data",
11838 "-expect-early-data-info",
11839 "-expect-accept-early-data",
11840 },
11841 shouldFail: true,
11842 expectedError: ":DIGEST_CHECK_FAILED:",
11843 expectedLocalError: "remote error: error decrypting message",
11844 })
11845 testCases = append(testCases, testCase{
11846 testType: serverTest,
11847 name: "TLS13-EarlyData-Server-BadFinished",
11848 config: Config{
11849 MaxVersion: VersionTLS13,
11850 MaxEarlyDataSize: 16384,
11851 },
11852 resumeConfig: &Config{
11853 MaxVersion: VersionTLS13,
11854 MaxEarlyDataSize: 16384,
11855 Bugs: ProtocolBugs{
11856 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11857 ExpectEarlyDataAccepted: true,
11858 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11859 BadFinished: true,
11860 },
11861 },
11862 resumeSession: true,
11863 flags: []string{
11864 "-enable-early-data",
11865 "-expect-accept-early-data",
11866 },
11867 shouldFail: true,
11868 expectedError: ":DIGEST_CHECK_FAILED:",
11869 expectedLocalError: "remote error: error decrypting message",
11870 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020011871 testCases = append(testCases, testCase{
11872 testType: serverTest,
11873 name: "TLS13-ServerSkipCertificateVerify",
11874 config: Config{
11875 MinVersion: VersionTLS13,
11876 MaxVersion: VersionTLS13,
11877 Certificates: []Certificate{rsaChainCertificate},
11878 Bugs: ProtocolBugs{
11879 SkipCertificateVerify: true,
11880 },
11881 },
11882 expectPeerCertificate: &rsaChainCertificate,
11883 flags: []string{
11884 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11885 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11886 "-require-any-client-certificate",
11887 },
11888 shouldFail: true,
11889 expectedError: ":UNEXPECTED_MESSAGE:",
11890 expectedLocalError: "remote error: unexpected message",
11891 })
11892 testCases = append(testCases, testCase{
11893 testType: clientTest,
11894 name: "TLS13-ClientSkipCertificateVerify",
11895 config: Config{
11896 MinVersion: VersionTLS13,
11897 MaxVersion: VersionTLS13,
11898 Certificates: []Certificate{rsaChainCertificate},
11899 Bugs: ProtocolBugs{
11900 SkipCertificateVerify: true,
11901 },
11902 },
11903 expectPeerCertificate: &rsaChainCertificate,
11904 flags: []string{
11905 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11906 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11907 },
11908 shouldFail: true,
11909 expectedError: ":UNEXPECTED_MESSAGE:",
11910 expectedLocalError: "remote error: unexpected message",
11911 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011912}
11913
David Benjaminabbbee12016-10-31 19:20:42 -040011914func addTLS13CipherPreferenceTests() {
11915 // Test that client preference is honored if the shim has AES hardware
11916 // and ChaCha20-Poly1305 is preferred otherwise.
11917 testCases = append(testCases, testCase{
11918 testType: serverTest,
11919 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11920 config: Config{
11921 MaxVersion: VersionTLS13,
11922 CipherSuites: []uint16{
11923 TLS_CHACHA20_POLY1305_SHA256,
11924 TLS_AES_128_GCM_SHA256,
11925 },
11926 },
11927 flags: []string{
11928 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11929 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11930 },
11931 })
11932
11933 testCases = append(testCases, testCase{
11934 testType: serverTest,
11935 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11936 config: Config{
11937 MaxVersion: VersionTLS13,
11938 CipherSuites: []uint16{
11939 TLS_AES_128_GCM_SHA256,
11940 TLS_CHACHA20_POLY1305_SHA256,
11941 },
11942 },
11943 flags: []string{
11944 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11945 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11946 },
11947 })
11948
11949 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11950 // whether it has AES hardware.
11951 testCases = append(testCases, testCase{
11952 name: "TLS13-CipherPreference-Client",
11953 config: Config{
11954 MaxVersion: VersionTLS13,
11955 // Use the client cipher order. (This is the default but
11956 // is listed to be explicit.)
11957 PreferServerCipherSuites: false,
11958 },
11959 flags: []string{
11960 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11961 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11962 },
11963 })
11964}
11965
David Benjaminf3fbade2016-09-19 13:08:16 -040011966func addPeekTests() {
11967 // Test SSL_peek works, including on empty records.
11968 testCases = append(testCases, testCase{
11969 name: "Peek-Basic",
11970 sendEmptyRecords: 1,
11971 flags: []string{"-peek-then-read"},
11972 })
11973
11974 // Test SSL_peek can drive the initial handshake.
11975 testCases = append(testCases, testCase{
11976 name: "Peek-ImplicitHandshake",
11977 flags: []string{
11978 "-peek-then-read",
11979 "-implicit-handshake",
11980 },
11981 })
11982
11983 // Test SSL_peek can discover and drive a renegotiation.
11984 testCases = append(testCases, testCase{
11985 name: "Peek-Renegotiate",
11986 config: Config{
11987 MaxVersion: VersionTLS12,
11988 },
11989 renegotiate: 1,
11990 flags: []string{
11991 "-peek-then-read",
11992 "-renegotiate-freely",
11993 "-expect-total-renegotiations", "1",
11994 },
11995 })
11996
11997 // Test SSL_peek can discover a close_notify.
11998 testCases = append(testCases, testCase{
11999 name: "Peek-Shutdown",
12000 config: Config{
12001 Bugs: ProtocolBugs{
12002 ExpectCloseNotify: true,
12003 },
12004 },
12005 flags: []string{
12006 "-peek-then-read",
12007 "-check-close-notify",
12008 },
12009 })
12010
12011 // Test SSL_peek can discover an alert.
12012 testCases = append(testCases, testCase{
12013 name: "Peek-Alert",
12014 config: Config{
12015 Bugs: ProtocolBugs{
12016 SendSpuriousAlert: alertRecordOverflow,
12017 },
12018 },
12019 flags: []string{"-peek-then-read"},
12020 shouldFail: true,
12021 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12022 })
12023
12024 // Test SSL_peek can handle KeyUpdate.
12025 testCases = append(testCases, testCase{
12026 name: "Peek-KeyUpdate",
12027 config: Config{
12028 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012029 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012030 sendKeyUpdates: 1,
12031 keyUpdateRequest: keyUpdateNotRequested,
12032 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012033 })
12034}
12035
David Benjamine6f22212016-11-08 14:28:24 -050012036func addRecordVersionTests() {
12037 for _, ver := range tlsVersions {
12038 // Test that the record version is enforced.
12039 testCases = append(testCases, testCase{
12040 name: "CheckRecordVersion-" + ver.name,
12041 config: Config{
12042 MinVersion: ver.version,
12043 MaxVersion: ver.version,
12044 Bugs: ProtocolBugs{
12045 SendRecordVersion: 0x03ff,
12046 },
12047 },
David Benjamina5022392017-07-10 17:40:39 -040012048 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012049 shouldFail: true,
12050 expectedError: ":WRONG_VERSION_NUMBER:",
12051 })
12052
12053 // Test that the ClientHello may use any record version, for
12054 // compatibility reasons.
12055 testCases = append(testCases, testCase{
12056 testType: serverTest,
12057 name: "LooseInitialRecordVersion-" + ver.name,
12058 config: Config{
12059 MinVersion: ver.version,
12060 MaxVersion: ver.version,
12061 Bugs: ProtocolBugs{
12062 SendInitialRecordVersion: 0x03ff,
12063 },
12064 },
David Benjamina5022392017-07-10 17:40:39 -040012065 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012066 })
12067
12068 // Test that garbage ClientHello record versions are rejected.
12069 testCases = append(testCases, testCase{
12070 testType: serverTest,
12071 name: "GarbageInitialRecordVersion-" + ver.name,
12072 config: Config{
12073 MinVersion: ver.version,
12074 MaxVersion: ver.version,
12075 Bugs: ProtocolBugs{
12076 SendInitialRecordVersion: 0xffff,
12077 },
12078 },
David Benjamina5022392017-07-10 17:40:39 -040012079 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012080 shouldFail: true,
12081 expectedError: ":WRONG_VERSION_NUMBER:",
12082 })
12083 }
12084}
12085
David Benjamin2c516452016-11-15 10:16:54 +090012086func addCertificateTests() {
12087 // Test that a certificate chain with intermediate may be sent and
12088 // received as both client and server.
12089 for _, ver := range tlsVersions {
12090 testCases = append(testCases, testCase{
12091 testType: clientTest,
12092 name: "SendReceiveIntermediate-Client-" + ver.name,
12093 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012094 MinVersion: ver.version,
12095 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012096 Certificates: []Certificate{rsaChainCertificate},
12097 ClientAuth: RequireAnyClientCert,
12098 },
David Benjamina5022392017-07-10 17:40:39 -040012099 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012100 expectPeerCertificate: &rsaChainCertificate,
12101 flags: []string{
12102 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12103 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12104 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12105 },
12106 })
12107
12108 testCases = append(testCases, testCase{
12109 testType: serverTest,
12110 name: "SendReceiveIntermediate-Server-" + ver.name,
12111 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012112 MinVersion: ver.version,
12113 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012114 Certificates: []Certificate{rsaChainCertificate},
12115 },
David Benjamina5022392017-07-10 17:40:39 -040012116 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012117 expectPeerCertificate: &rsaChainCertificate,
12118 flags: []string{
12119 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12120 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12121 "-require-any-client-certificate",
12122 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12123 },
12124 })
12125 }
12126}
12127
David Benjaminbbaf3672016-11-17 10:53:09 +090012128func addRetainOnlySHA256ClientCertTests() {
12129 for _, ver := range tlsVersions {
12130 // Test that enabling
12131 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12132 // actually requesting a client certificate is a no-op.
12133 testCases = append(testCases, testCase{
12134 testType: serverTest,
12135 name: "RetainOnlySHA256-NoCert-" + ver.name,
12136 config: Config{
12137 MinVersion: ver.version,
12138 MaxVersion: ver.version,
12139 },
David Benjamina5022392017-07-10 17:40:39 -040012140 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012141 flags: []string{
12142 "-retain-only-sha256-client-cert-initial",
12143 "-retain-only-sha256-client-cert-resume",
12144 },
12145 resumeSession: true,
12146 })
12147
12148 // Test that when retaining only a SHA-256 certificate is
12149 // enabled, the hash appears as expected.
12150 testCases = append(testCases, testCase{
12151 testType: serverTest,
12152 name: "RetainOnlySHA256-Cert-" + ver.name,
12153 config: Config{
12154 MinVersion: ver.version,
12155 MaxVersion: ver.version,
12156 Certificates: []Certificate{rsaCertificate},
12157 },
David Benjamina5022392017-07-10 17:40:39 -040012158 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012159 flags: []string{
12160 "-verify-peer",
12161 "-retain-only-sha256-client-cert-initial",
12162 "-retain-only-sha256-client-cert-resume",
12163 "-expect-sha256-client-cert-initial",
12164 "-expect-sha256-client-cert-resume",
12165 },
12166 resumeSession: true,
12167 })
12168
12169 // Test that when the config changes from on to off, a
12170 // resumption is rejected because the server now wants the full
12171 // certificate chain.
12172 testCases = append(testCases, testCase{
12173 testType: serverTest,
12174 name: "RetainOnlySHA256-OnOff-" + ver.name,
12175 config: Config{
12176 MinVersion: ver.version,
12177 MaxVersion: ver.version,
12178 Certificates: []Certificate{rsaCertificate},
12179 },
David Benjamina5022392017-07-10 17:40:39 -040012180 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012181 flags: []string{
12182 "-verify-peer",
12183 "-retain-only-sha256-client-cert-initial",
12184 "-expect-sha256-client-cert-initial",
12185 },
12186 resumeSession: true,
12187 expectResumeRejected: true,
12188 })
12189
12190 // Test that when the config changes from off to on, a
12191 // resumption is rejected because the server now wants just the
12192 // hash.
12193 testCases = append(testCases, testCase{
12194 testType: serverTest,
12195 name: "RetainOnlySHA256-OffOn-" + ver.name,
12196 config: Config{
12197 MinVersion: ver.version,
12198 MaxVersion: ver.version,
12199 Certificates: []Certificate{rsaCertificate},
12200 },
David Benjamina5022392017-07-10 17:40:39 -040012201 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012202 flags: []string{
12203 "-verify-peer",
12204 "-retain-only-sha256-client-cert-resume",
12205 "-expect-sha256-client-cert-resume",
12206 },
12207 resumeSession: true,
12208 expectResumeRejected: true,
12209 })
12210 }
12211}
12212
Adam Langleya4b91982016-12-12 12:05:53 -080012213func addECDSAKeyUsageTests() {
12214 p256 := elliptic.P256()
12215 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12216 if err != nil {
12217 panic(err)
12218 }
12219
12220 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12221 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12222 if err != nil {
12223 panic(err)
12224 }
12225
12226 template := x509.Certificate{
12227 SerialNumber: serialNumber,
12228 Subject: pkix.Name{
12229 Organization: []string{"Acme Co"},
12230 },
12231 NotBefore: time.Now(),
12232 NotAfter: time.Now(),
12233
12234 // An ECC certificate with only the keyAgreement key usgae may
12235 // be used with ECDH, but not ECDSA.
12236 KeyUsage: x509.KeyUsageKeyAgreement,
12237 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12238 BasicConstraintsValid: true,
12239 }
12240
12241 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12242 if err != nil {
12243 panic(err)
12244 }
12245
12246 cert := Certificate{
12247 Certificate: [][]byte{derBytes},
12248 PrivateKey: priv,
12249 }
12250
12251 for _, ver := range tlsVersions {
12252 if ver.version < VersionTLS12 {
12253 continue
12254 }
12255
12256 testCases = append(testCases, testCase{
12257 testType: clientTest,
12258 name: "ECDSAKeyUsage-" + ver.name,
12259 config: Config{
12260 MinVersion: ver.version,
12261 MaxVersion: ver.version,
12262 Certificates: []Certificate{cert},
12263 },
David Benjamina5022392017-07-10 17:40:39 -040012264 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012265 shouldFail: true,
12266 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12267 })
12268 }
12269}
12270
David Benjamin8c26d752017-03-26 15:13:51 -050012271func addExtraHandshakeTests() {
12272 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12273 // to ensure there is no transport I/O.
12274 testCases = append(testCases, testCase{
12275 testType: clientTest,
12276 name: "ExtraHandshake-Client-TLS12",
12277 config: Config{
12278 MinVersion: VersionTLS12,
12279 MaxVersion: VersionTLS12,
12280 },
12281 flags: []string{
12282 "-async",
12283 "-no-op-extra-handshake",
12284 },
12285 })
12286 testCases = append(testCases, testCase{
12287 testType: serverTest,
12288 name: "ExtraHandshake-Server-TLS12",
12289 config: Config{
12290 MinVersion: VersionTLS12,
12291 MaxVersion: VersionTLS12,
12292 },
12293 flags: []string{
12294 "-async",
12295 "-no-op-extra-handshake",
12296 },
12297 })
12298 testCases = append(testCases, testCase{
12299 testType: clientTest,
12300 name: "ExtraHandshake-Client-TLS13",
12301 config: Config{
12302 MinVersion: VersionTLS13,
12303 MaxVersion: VersionTLS13,
12304 },
12305 flags: []string{
12306 "-async",
12307 "-no-op-extra-handshake",
12308 },
12309 })
12310 testCases = append(testCases, testCase{
12311 testType: serverTest,
12312 name: "ExtraHandshake-Server-TLS13",
12313 config: Config{
12314 MinVersion: VersionTLS13,
12315 MaxVersion: VersionTLS13,
12316 },
12317 flags: []string{
12318 "-async",
12319 "-no-op-extra-handshake",
12320 },
12321 })
12322
12323 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12324 testCases = append(testCases, testCase{
12325 testType: serverTest,
12326 name: "ExtraHandshake-Server-EarlyData-TLS13",
12327 config: Config{
12328 MaxVersion: VersionTLS13,
12329 MinVersion: VersionTLS13,
12330 Bugs: ProtocolBugs{
12331 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12332 ExpectEarlyDataAccepted: true,
12333 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12334 },
12335 },
12336 messageCount: 2,
12337 resumeSession: true,
12338 flags: []string{
12339 "-async",
12340 "-enable-early-data",
12341 "-expect-accept-early-data",
12342 "-no-op-extra-handshake",
12343 },
12344 })
12345
12346 // An extra SSL_do_handshake drives the handshake to completion in False
12347 // Start. We test this by handshaking twice and asserting the False
12348 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12349 // how the test works.
12350 testCases = append(testCases, testCase{
12351 testType: clientTest,
12352 name: "ExtraHandshake-FalseStart",
12353 config: Config{
12354 MaxVersion: VersionTLS12,
12355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12356 NextProtos: []string{"foo"},
12357 Bugs: ProtocolBugs{
12358 ExpectFalseStart: true,
12359 AlertBeforeFalseStartTest: alertAccessDenied,
12360 },
12361 },
12362 flags: []string{
12363 "-handshake-twice",
12364 "-false-start",
12365 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012366 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012367 },
12368 shimWritesFirst: true,
12369 shouldFail: true,
12370 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12371 expectedLocalError: "tls: peer did not false start: EOF",
12372 })
12373}
12374
David Benjaminb853f312017-07-14 18:40:34 -040012375// Test that omitted and empty extensions blocks are tolerated.
12376func addOmitExtensionsTests() {
12377 for _, ver := range tlsVersions {
12378 if ver.version > VersionTLS12 {
12379 continue
12380 }
12381
12382 testCases = append(testCases, testCase{
12383 testType: serverTest,
12384 name: "OmitExtensions-ClientHello-" + ver.name,
12385 config: Config{
12386 MinVersion: ver.version,
12387 MaxVersion: ver.version,
12388 SessionTicketsDisabled: true,
12389 Bugs: ProtocolBugs{
12390 OmitExtensions: true,
12391 },
12392 },
12393 })
12394
12395 testCases = append(testCases, testCase{
12396 testType: serverTest,
12397 name: "EmptyExtensions-ClientHello-" + ver.name,
12398 config: Config{
12399 MinVersion: ver.version,
12400 MaxVersion: ver.version,
12401 SessionTicketsDisabled: true,
12402 Bugs: ProtocolBugs{
12403 EmptyExtensions: true,
12404 },
12405 },
12406 })
12407
12408 testCases = append(testCases, testCase{
12409 testType: clientTest,
12410 name: "OmitExtensions-ServerHello-" + ver.name,
12411 config: Config{
12412 MinVersion: ver.version,
12413 MaxVersion: ver.version,
12414 SessionTicketsDisabled: true,
12415 Bugs: ProtocolBugs{
12416 OmitExtensions: true,
12417 // Disable all ServerHello extensions so
12418 // OmitExtensions works.
12419 NoExtendedMasterSecret: true,
12420 NoRenegotiationInfo: true,
12421 },
12422 },
12423 })
12424
12425 testCases = append(testCases, testCase{
12426 testType: clientTest,
12427 name: "EmptyExtensions-ServerHello-" + ver.name,
12428 config: Config{
12429 MinVersion: ver.version,
12430 MaxVersion: ver.version,
12431 SessionTicketsDisabled: true,
12432 Bugs: ProtocolBugs{
12433 EmptyExtensions: true,
12434 // Disable all ServerHello extensions so
12435 // EmptyExtensions works.
12436 NoExtendedMasterSecret: true,
12437 NoRenegotiationInfo: true,
12438 },
12439 },
12440 })
12441 }
12442}
12443
Adam Langley7c803a62015-06-15 15:35:05 -070012444func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012445 defer wg.Done()
12446
12447 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012448 var err error
12449
David Benjaminba28dfc2016-11-15 17:47:21 +090012450 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012451 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12452 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012453 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012454 if err != nil {
12455 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12456 }
12457 break
12458 }
12459 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012460 } else if *repeatUntilFailure {
12461 for err == nil {
12462 statusChan <- statusMsg{test: test, started: true}
12463 err = runTest(test, shimPath, -1)
12464 }
12465 } else {
12466 statusChan <- statusMsg{test: test, started: true}
12467 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012468 }
Adam Langley95c29f32014-06-20 12:00:00 -070012469 statusChan <- statusMsg{test: test, err: err}
12470 }
12471}
12472
12473type statusMsg struct {
12474 test *testCase
12475 started bool
12476 err error
12477}
12478
David Benjamin5f237bc2015-02-11 17:14:15 -050012479func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012480 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012481
David Benjamin5f237bc2015-02-11 17:14:15 -050012482 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012483 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012484 if !*pipe {
12485 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012486 var erase string
12487 for i := 0; i < lineLen; i++ {
12488 erase += "\b \b"
12489 }
12490 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012491 }
12492
Adam Langley95c29f32014-06-20 12:00:00 -070012493 if msg.started {
12494 started++
12495 } else {
12496 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012497
12498 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012499 if msg.err == errUnimplemented {
12500 if *pipe {
12501 // Print each test instead of a status line.
12502 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12503 }
12504 unimplemented++
12505 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12506 } else {
12507 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12508 failed++
12509 testOutput.addResult(msg.test.name, "FAIL")
12510 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012511 } else {
12512 if *pipe {
12513 // Print each test instead of a status line.
12514 fmt.Printf("PASSED (%s)\n", msg.test.name)
12515 }
12516 testOutput.addResult(msg.test.name, "PASS")
12517 }
Adam Langley95c29f32014-06-20 12:00:00 -070012518 }
12519
David Benjamin5f237bc2015-02-11 17:14:15 -050012520 if !*pipe {
12521 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012522 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012523 lineLen = len(line)
12524 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012525 }
Adam Langley95c29f32014-06-20 12:00:00 -070012526 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012527
12528 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012529}
12530
12531func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012532 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012533 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012534 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012535
Adam Langley7c803a62015-06-15 15:35:05 -070012536 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012537 addCipherSuiteTests()
12538 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012539 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012540 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012541 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012542 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012543 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012544 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012545 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012546 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012547 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012548 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012549 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012550 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012551 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012552 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012553 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012554 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012555 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012556 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012557 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012558 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012559 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012560 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012561 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012562 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012563 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012564 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012565 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012566 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012567 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012568 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012569 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012570 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012571 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012572
12573 var wg sync.WaitGroup
12574
Adam Langley7c803a62015-06-15 15:35:05 -070012575 statusChan := make(chan statusMsg, *numWorkers)
12576 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012577 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012578
EKRf71d7ed2016-08-06 13:25:12 -070012579 if len(*shimConfigFile) != 0 {
12580 encoded, err := ioutil.ReadFile(*shimConfigFile)
12581 if err != nil {
12582 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12583 os.Exit(1)
12584 }
12585
12586 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12587 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12588 os.Exit(1)
12589 }
12590 }
12591
David Benjamin025b3d32014-07-01 19:53:04 -040012592 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012593
Adam Langley7c803a62015-06-15 15:35:05 -070012594 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012595 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012596 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012597 }
12598
David Benjamin270f0a72016-03-17 14:41:36 -040012599 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012600 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012601 matched := true
12602 if len(*testToRun) != 0 {
12603 var err error
12604 matched, err = filepath.Match(*testToRun, testCases[i].name)
12605 if err != nil {
12606 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12607 os.Exit(1)
12608 }
12609 }
12610
EKRf71d7ed2016-08-06 13:25:12 -070012611 if !*includeDisabled {
12612 for pattern := range shimConfig.DisabledTests {
12613 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12614 if err != nil {
12615 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12616 os.Exit(1)
12617 }
12618
12619 if isDisabled {
12620 matched = false
12621 break
12622 }
12623 }
12624 }
12625
David Benjamin17e12922016-07-28 18:04:43 -040012626 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012627 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012628 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012629
12630 // Only run one test if repeating until failure.
12631 if *repeatUntilFailure {
12632 break
12633 }
Adam Langley95c29f32014-06-20 12:00:00 -070012634 }
12635 }
David Benjamin17e12922016-07-28 18:04:43 -040012636
David Benjamin270f0a72016-03-17 14:41:36 -040012637 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012638 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012639 os.Exit(1)
12640 }
Adam Langley95c29f32014-06-20 12:00:00 -070012641
12642 close(testChan)
12643 wg.Wait()
12644 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012645 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012646
12647 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012648
12649 if *jsonOutput != "" {
12650 if err := testOutput.writeTo(*jsonOutput); err != nil {
12651 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12652 }
12653 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012654
EKR842ae6c2016-07-27 09:22:05 +020012655 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12656 os.Exit(1)
12657 }
12658
12659 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012660 os.Exit(1)
12661 }
Adam Langley95c29f32014-06-20 12:00:00 -070012662}