blob: 4d7d2b0e3bbc087a592c66808fe678767c7322cb [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700491 if !*useGDB {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
David Benjamin3ed59772016-03-08 12:50:21 -0500495 }
496 return t.Conn.Read(b)
497}
498
499func (t *timeoutConn) Write(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700500 if !*useGDB {
501 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
502 return 0, err
503 }
David Benjamin3ed59772016-03-08 12:50:21 -0500504 }
505 return t.Conn.Write(b)
506}
507
David Benjamin0fde2eb2017-06-30 19:11:22 -0400508func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400509 if !test.noSessionCache {
510 if config.ClientSessionCache == nil {
511 config.ClientSessionCache = NewLRUClientSessionCache(1)
512 }
513 if config.ServerSessionCache == nil {
514 config.ServerSessionCache = NewLRUServerSessionCache(1)
515 }
516 }
517 if test.testType == clientTest {
518 if len(config.Certificates) == 0 {
519 config.Certificates = []Certificate{rsaCertificate}
520 }
521 } else {
522 // Supply a ServerName to ensure a constant session cache key,
523 // rather than falling back to net.Conn.RemoteAddr.
524 if len(config.ServerName) == 0 {
525 config.ServerName = "test"
526 }
527 }
528 if *fuzzer {
529 config.Bugs.NullAllCiphers = true
530 }
David Benjamin01a90572016-09-22 00:11:43 -0400531 if *deterministic {
532 config.Time = func() time.Time { return time.Unix(1234, 1234) }
533 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400534 if test.tls13Variant != 0 {
535 config.TLS13Variant = test.tls13Variant
536 }
David Benjamine54af062016-08-08 19:21:18 -0400537
David Benjamin01784b42016-06-07 18:00:52 -0400538 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500539
David Benjamin6fd297b2014-08-11 18:43:38 -0400540 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500541 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
542 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500543 }
544
David Benjamin9867b7d2016-03-01 23:25:48 -0500545 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500546 local, peer := "client", "server"
547 if test.testType == clientTest {
548 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500549 }
David Benjaminebda9b32015-11-02 15:33:18 -0500550 connDebug := &recordingConn{
551 Conn: conn,
552 isDatagram: test.protocol == dtls,
553 local: local,
554 peer: peer,
555 }
556 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 if *flagDebug {
558 defer connDebug.WriteTo(os.Stdout)
559 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400560 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500561 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400562 path := transcriptPrefix + strconv.Itoa(num)
563 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500564 }()
565 }
David Benjaminebda9b32015-11-02 15:33:18 -0500566
567 if config.Bugs.PacketAdaptor != nil {
568 config.Bugs.PacketAdaptor.debug = connDebug
569 }
570 }
571
572 if test.replayWrites {
573 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400574 }
575
David Benjamin3ed59772016-03-08 12:50:21 -0500576 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500577 if test.damageFirstWrite {
578 connDamage = newDamageAdaptor(conn)
579 conn = connDamage
580 }
581
David Benjamin6fd297b2014-08-11 18:43:38 -0400582 if test.sendPrefix != "" {
583 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
584 return err
585 }
David Benjamin98e882e2014-08-08 13:24:34 -0400586 }
587
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400589 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSServer(conn, config)
592 } else {
593 tlsConn = Server(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 } else {
596 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400597 if test.protocol == dtls {
598 tlsConn = DTLSClient(conn, config)
599 } else {
600 tlsConn = Client(conn, config)
601 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400602 }
David Benjamin30789da2015-08-29 22:56:45 -0400603 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400604
Adam Langley95c29f32014-06-20 12:00:00 -0700605 if err := tlsConn.Handshake(); err != nil {
606 return err
607 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700608
David Benjamin01fe8202014-09-24 15:21:44 -0400609 // TODO(davidben): move all per-connection expectations into a dedicated
610 // expectations struct that can be specified separately for the two
611 // legs.
612 expectedVersion := test.expectedVersion
613 if isResume && test.expectedResumeVersion != 0 {
614 expectedVersion = test.expectedResumeVersion
615 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700616 connState := tlsConn.ConnectionState()
617 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400618 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400619 }
620
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700621 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400622 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
623 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700624 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
625 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
626 }
David Benjamin90da8c82015-04-20 14:57:57 -0400627
David Benjamina08e49d2014-08-24 01:46:07 -0400628 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700629 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400630 if channelID == nil {
631 return fmt.Errorf("no channel ID negotiated")
632 }
633 if channelID.Curve != channelIDKey.Curve ||
634 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
635 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
636 return fmt.Errorf("incorrect channel ID")
637 }
David Benjamin634f4752017-07-01 11:08:41 -0400638 } else if connState.ChannelID != nil {
639 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400640 }
641
David Benjaminae2888f2014-09-06 12:58:58 -0400642 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700643 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400644 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
645 }
646 }
647
David Benjaminc7ce9772015-10-09 19:32:41 -0400648 if test.expectNoNextProto {
649 if actual := connState.NegotiatedProtocol; actual != "" {
650 return fmt.Errorf("got unexpected next proto %s", actual)
651 }
652 }
653
David Benjaminfc7b0862014-09-06 13:21:53 -0400654 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700655 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400656 return fmt.Errorf("next proto type mismatch")
657 }
658 }
659
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700660 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500661 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
662 }
663
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100664 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300665 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100666 }
667
Paul Lietar4fac72e2015-09-09 13:44:55 +0100668 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
669 return fmt.Errorf("SCT list mismatch")
670 }
671
Nick Harper60edffd2016-06-21 15:19:24 -0700672 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
673 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400674 }
675
Steven Valdez5440fe02016-07-18 12:40:30 -0400676 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
677 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
678 }
679
David Benjamin2c516452016-11-15 10:16:54 +0900680 if test.expectPeerCertificate != nil {
681 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
682 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
683 }
684 for i, cert := range connState.PeerCertificates {
685 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
686 return fmt.Errorf("peer certificate %d did not match", i+1)
687 }
688 }
689 }
690
David Benjaminc565ebb2015-04-03 04:06:36 -0400691 if test.exportKeyingMaterial > 0 {
692 actual := make([]byte, test.exportKeyingMaterial)
693 if _, err := io.ReadFull(tlsConn, actual); err != nil {
694 return err
695 }
696 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
697 if err != nil {
698 return err
699 }
700 if !bytes.Equal(actual, expected) {
701 return fmt.Errorf("keying material mismatch")
702 }
703 }
704
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700705 if test.testTLSUnique {
706 var peersValue [12]byte
707 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
708 return err
709 }
710 expected := tlsConn.ConnectionState().TLSUnique
711 if !bytes.Equal(peersValue[:], expected) {
712 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
713 }
714 }
715
David Benjamin47921102016-07-28 11:29:18 -0400716 if test.sendHalfHelloRequest {
717 tlsConn.SendHalfHelloRequest()
718 }
719
Steven Valdeze831a812017-03-09 14:56:07 -0500720 shimPrefix := test.shimPrefix
721 if isResume {
722 shimPrefix = test.resumeShimPrefix
723 }
724 if test.shimWritesFirst || test.readWithUnfinishedWrite {
725 shimPrefix = "hello"
726 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400727 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400728 // If readWithUnfinishedWrite is set, the shim prefix will be
729 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500730 if shimPrefix != "" && !test.readWithUnfinishedWrite {
731 var buf = make([]byte, len(shimPrefix))
732 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400733 if err != nil {
734 return err
735 }
Steven Valdeze831a812017-03-09 14:56:07 -0500736 if string(buf) != shimPrefix {
737 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400738 }
Steven Valdeze831a812017-03-09 14:56:07 -0500739 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400740 }
741
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 if test.renegotiateCiphers != nil {
743 config.CipherSuites = test.renegotiateCiphers
744 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400745 for i := 0; i < test.renegotiate; i++ {
746 if err := tlsConn.Renegotiate(); err != nil {
747 return err
748 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700749 }
750 } else if test.renegotiateCiphers != nil {
751 panic("renegotiateCiphers without renegotiate")
752 }
753
David Benjamin5fa3eba2015-01-22 16:35:40 -0500754 if test.damageFirstWrite {
755 connDamage.setDamage(true)
756 tlsConn.Write([]byte("DAMAGED WRITE"))
757 connDamage.setDamage(false)
758 }
759
David Benjamin8e6db492015-07-25 18:29:23 -0400760 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700761 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400762 if test.protocol == dtls {
763 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
764 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700765 // Read until EOF.
766 _, err := io.Copy(ioutil.Discard, tlsConn)
767 return err
768 }
David Benjamin4417d052015-04-05 04:17:25 -0400769 if messageLen == 0 {
770 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700771 }
Adam Langley95c29f32014-06-20 12:00:00 -0700772
David Benjamin8e6db492015-07-25 18:29:23 -0400773 messageCount := test.messageCount
774 if messageCount == 0 {
775 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400776 }
777
David Benjamin8e6db492015-07-25 18:29:23 -0400778 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400779 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400780 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400781 }
782
David Benjamin8e6db492015-07-25 18:29:23 -0400783 for i := 0; i < test.sendEmptyRecords; i++ {
784 tlsConn.Write(nil)
785 }
786
787 for i := 0; i < test.sendWarningAlerts; i++ {
788 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
789 }
790
David Benjamin24e58862017-06-14 18:45:29 -0400791 if test.sendBogusAlertType {
792 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
793 }
794
David Benjaminbbba9392017-04-06 12:54:12 -0400795 testMessage := make([]byte, messageLen)
796 for i := range testMessage {
797 testMessage[i] = 0x42 ^ byte(j)
798 }
799 tlsConn.Write(testMessage)
800
801 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500802 if shimPrefix != "" {
803 var buf = make([]byte, len(shimPrefix))
804 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400805 if err != nil {
806 return err
807 }
Steven Valdeze831a812017-03-09 14:56:07 -0500808 if string(buf) != shimPrefix {
809 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400810 }
Steven Valdeze831a812017-03-09 14:56:07 -0500811 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400812 }
813
David Benjamin4f75aaf2015-09-01 16:53:10 -0400814 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400815 // The shim will not respond.
816 continue
817 }
818
David Benjaminbbba9392017-04-06 12:54:12 -0400819 // Process the KeyUpdate ACK. However many KeyUpdates the runner
820 // sends, the shim should respond only once.
821 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
822 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
823 return err
824 }
825 }
826
David Benjamin8e6db492015-07-25 18:29:23 -0400827 buf := make([]byte, len(testMessage))
828 if test.protocol == dtls {
829 bufTmp := make([]byte, len(buf)+1)
830 n, err := tlsConn.Read(bufTmp)
831 if err != nil {
832 return err
833 }
834 if n != len(buf) {
835 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
836 }
837 copy(buf, bufTmp)
838 } else {
839 _, err := io.ReadFull(tlsConn, buf)
840 if err != nil {
841 return err
842 }
843 }
844
845 for i, v := range buf {
846 if v != testMessage[i]^0xff {
847 return fmt.Errorf("bad reply contents at byte %d", i)
848 }
Adam Langley95c29f32014-06-20 12:00:00 -0700849 }
850 }
851
852 return nil
853}
854
David Benjamin325b5c32014-07-01 19:40:31 -0400855func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400856 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700857 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400858 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700859 }
David Benjamin325b5c32014-07-01 19:40:31 -0400860 valgrindArgs = append(valgrindArgs, path)
861 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamin325b5c32014-07-01 19:40:31 -0400866func gdbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "gdb", "--args"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700870
David Benjamin325b5c32014-07-01 19:40:31 -0400871 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700872}
873
David Benjamind16bf342015-12-18 00:53:12 -0500874func lldbOf(path string, args ...string) *exec.Cmd {
875 xtermArgs := []string{"-e", "lldb", "--"}
876 xtermArgs = append(xtermArgs, path)
877 xtermArgs = append(xtermArgs, args...)
878
879 return exec.Command("xterm", xtermArgs...)
880}
881
EKR842ae6c2016-07-27 09:22:05 +0200882var (
883 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
884 errUnimplemented = errors.New("child process does not implement needed flags")
885)
Adam Langley69a01602014-11-17 17:26:55 -0800886
David Benjamin87c8a642015-02-21 01:54:29 -0500887// accept accepts a connection from listener, unless waitChan signals a process
888// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400889func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500890 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400891 conn net.Conn
892 err error
893 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500894 }
895 connChan := make(chan connOrError, 1)
896 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400897 startTime := time.Now()
Adam Langley182b5732017-07-28 11:00:23 -0700898 if !*useGDB {
899 listener.SetDeadline(time.Now().Add(*idleTimeout))
900 }
David Benjamin87c8a642015-02-21 01:54:29 -0500901 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400902 endTime := time.Now()
903 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500904 close(connChan)
905 }()
906 select {
907 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400908 if result.err != nil {
909 // TODO(davidben): Remove this logging when
910 // https://crbug.com/boringssl/199 is resolved.
911 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
912 }
David Benjamin87c8a642015-02-21 01:54:29 -0500913 return result.conn, result.err
914 case childErr := <-waitChan:
915 waitChan <- childErr
916 return nil, fmt.Errorf("child exited early: %s", childErr)
917 }
918}
919
EKRf71d7ed2016-08-06 13:25:12 -0700920func translateExpectedError(errorStr string) string {
921 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
922 return translated
923 }
924
925 if *looseErrors {
926 return ""
927 }
928
929 return errorStr
930}
931
Adam Langley7c803a62015-06-15 15:35:05 -0700932func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400933 // Help debugging panics on the Go side.
934 defer func() {
935 if r := recover(); r != nil {
936 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
937 panic(r)
938 }
939 }()
940
Adam Langley38311732014-10-16 19:04:35 -0700941 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
942 panic("Error expected without shouldFail in " + test.name)
943 }
944
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700945 if test.expectResumeRejected && !test.resumeSession {
946 panic("expectResumeRejected without resumeSession in " + test.name)
947 }
948
Adam Langley33b1d4f2016-12-07 15:03:45 -0800949 for _, ver := range tlsVersions {
950 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
951 continue
952 }
953
David Benjamina5022392017-07-10 17:40:39 -0400954 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
955 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
Adam Langley33b1d4f2016-12-07 15:03:45 -0800956 }
957
David Benjamina5022392017-07-10 17:40:39 -0400958 if ver.tls13Variant != 0 {
959 var foundFlag bool
960 for _, flag := range test.flags {
961 if flag == "-tls13-variant" {
962 foundFlag = true
963 break
964 }
965 }
966 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
967 panic(fmt.Sprintf("The name of test %q suggests that uses an experimental TLS 1.3 variant, but neither the shim nor the runner configures it", test.name))
968 }
969 }
970
Adam Langley33b1d4f2016-12-07 15:03:45 -0800971 }
972
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700973 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
974 if err != nil {
975 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
976 }
David Benjamin87c8a642015-02-21 01:54:29 -0500977 if err != nil {
978 panic(err)
979 }
980 defer func() {
981 if listener != nil {
982 listener.Close()
983 }
984 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700985
David Benjamin87c8a642015-02-21 01:54:29 -0500986 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400987 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400988 flags = append(flags, "-server")
989
David Benjamin025b3d32014-07-01 19:53:04 -0400990 flags = append(flags, "-key-file")
991 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700992 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400993 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700994 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400995 }
996
997 flags = append(flags, "-cert-file")
998 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700999 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001000 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001001 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001002 }
1003 }
David Benjamin5a593af2014-08-11 19:51:50 -04001004
David Benjamin6fd297b2014-08-11 18:43:38 -04001005 if test.protocol == dtls {
1006 flags = append(flags, "-dtls")
1007 }
1008
David Benjamin46662482016-08-17 00:51:00 -04001009 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001010 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001011 resumeCount++
1012 if test.resumeRenewedSession {
1013 resumeCount++
1014 }
1015 }
1016
1017 if resumeCount > 0 {
1018 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001019 }
1020
David Benjamine58c4f52014-08-24 03:47:07 -04001021 if test.shimWritesFirst {
1022 flags = append(flags, "-shim-writes-first")
1023 }
1024
David Benjaminbbba9392017-04-06 12:54:12 -04001025 if test.readWithUnfinishedWrite {
1026 flags = append(flags, "-read-with-unfinished-write")
1027 }
1028
David Benjamin30789da2015-08-29 22:56:45 -04001029 if test.shimShutsDown {
1030 flags = append(flags, "-shim-shuts-down")
1031 }
1032
David Benjaminc565ebb2015-04-03 04:06:36 -04001033 if test.exportKeyingMaterial > 0 {
1034 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1035 flags = append(flags, "-export-label", test.exportLabel)
1036 flags = append(flags, "-export-context", test.exportContext)
1037 if test.useExportContext {
1038 flags = append(flags, "-use-export-context")
1039 }
1040 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001041 if test.expectResumeRejected {
1042 flags = append(flags, "-expect-session-miss")
1043 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001044
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001045 if test.testTLSUnique {
1046 flags = append(flags, "-tls-unique")
1047 }
1048
David Benjamina5022392017-07-10 17:40:39 -04001049 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001050 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1051 }
1052
David Benjamin0fde2eb2017-06-30 19:11:22 -04001053 var transcriptPrefix string
1054 if len(*transcriptDir) != 0 {
1055 protocol := "tls"
1056 if test.protocol == dtls {
1057 protocol = "dtls"
1058 }
1059
1060 side := "client"
1061 if test.testType == serverTest {
1062 side = "server"
1063 }
1064
1065 dir := filepath.Join(*transcriptDir, protocol, side)
1066 if err := os.MkdirAll(dir, 0755); err != nil {
1067 return err
1068 }
1069 transcriptPrefix = filepath.Join(dir, test.name+"-")
1070 flags = append(flags, "-write-settings", transcriptPrefix)
1071 }
1072
David Benjamin025b3d32014-07-01 19:53:04 -04001073 flags = append(flags, test.flags...)
1074
1075 var shim *exec.Cmd
1076 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001077 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001078 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001079 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001080 } else if *useLLDB {
1081 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001082 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001083 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001084 }
David Benjamin025b3d32014-07-01 19:53:04 -04001085 shim.Stdin = os.Stdin
1086 var stdoutBuf, stderrBuf bytes.Buffer
1087 shim.Stdout = &stdoutBuf
1088 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001089 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001090 shim.Env = os.Environ()
1091 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001092 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001093 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001094 }
1095 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1096 }
David Benjamin025b3d32014-07-01 19:53:04 -04001097
1098 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001099 panic(err)
1100 }
David Benjamin87c8a642015-02-21 01:54:29 -05001101 waitChan := make(chan error, 1)
1102 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001103
1104 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001105
David Benjamin7a4aaa42016-09-20 17:58:14 -04001106 if *deterministic {
1107 config.Rand = &deterministicRand{}
1108 }
1109
David Benjamin87c8a642015-02-21 01:54:29 -05001110 conn, err := acceptOrWait(listener, waitChan)
1111 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001112 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001113 conn.Close()
1114 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001115
David Benjamin46662482016-08-17 00:51:00 -04001116 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001117 var resumeConfig Config
1118 if test.resumeConfig != nil {
1119 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001120 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001121 resumeConfig.SessionTicketKey = config.SessionTicketKey
1122 resumeConfig.ClientSessionCache = config.ClientSessionCache
1123 resumeConfig.ServerSessionCache = config.ServerSessionCache
1124 }
David Benjamin2e045a92016-06-08 13:09:56 -04001125 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001126 } else {
1127 resumeConfig = config
1128 }
David Benjamin87c8a642015-02-21 01:54:29 -05001129 var connResume net.Conn
1130 connResume, err = acceptOrWait(listener, waitChan)
1131 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001132 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001133 connResume.Close()
1134 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001135 }
1136
David Benjamin87c8a642015-02-21 01:54:29 -05001137 // Close the listener now. This is to avoid hangs should the shim try to
1138 // open more connections than expected.
1139 listener.Close()
1140 listener = nil
1141
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001142 var shimKilledLock sync.Mutex
1143 var shimKilled bool
1144 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1145 shimKilledLock.Lock()
1146 shimKilled = true
1147 shimKilledLock.Unlock()
1148 shim.Process.Kill()
1149 })
David Benjamin87c8a642015-02-21 01:54:29 -05001150 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001151 waitTimeout.Stop()
1152 shimKilledLock.Lock()
1153 if shimKilled && err == nil {
1154 err = errors.New("timeout waiting for the shim to exit.")
1155 }
1156 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001157 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001158 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001159 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1160 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001161 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001162 case 89:
1163 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001164 case 99:
1165 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001166 }
1167 }
Adam Langley95c29f32014-06-20 12:00:00 -07001168
David Benjamin9bea3492016-03-02 10:59:16 -05001169 // Account for Windows line endings.
1170 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1171 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001172
1173 // Separate the errors from the shim and those from tools like
1174 // AddressSanitizer.
1175 var extraStderr string
1176 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1177 stderr = stderrParts[0]
1178 extraStderr = stderrParts[1]
1179 }
1180
Adam Langley95c29f32014-06-20 12:00:00 -07001181 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001182 expectedError := translateExpectedError(test.expectedError)
1183 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001184
Adam Langleyac61fa32014-06-23 12:03:11 -07001185 localError := "none"
1186 if err != nil {
1187 localError = err.Error()
1188 }
1189 if len(test.expectedLocalError) != 0 {
1190 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1191 }
Adam Langley95c29f32014-06-20 12:00:00 -07001192
1193 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001194 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001195 if childErr != nil {
1196 childError = childErr.Error()
1197 }
1198
1199 var msg string
1200 switch {
1201 case failed && !test.shouldFail:
1202 msg = "unexpected failure"
1203 case !failed && test.shouldFail:
1204 msg = "unexpected success"
1205 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001206 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001207 default:
1208 panic("internal error")
1209 }
1210
David Benjamin9aafb642016-09-20 19:36:53 -04001211 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001212 }
1213
David Benjamind2ba8892016-09-20 19:41:04 -04001214 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001215 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001216 }
1217
David Benjamind2ba8892016-09-20 19:41:04 -04001218 if *useValgrind && isValgrindError {
1219 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1220 }
1221
Adam Langley95c29f32014-06-20 12:00:00 -07001222 return nil
1223}
1224
David Benjaminaa012042016-12-10 13:33:05 -05001225type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001226 name string
1227 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001228 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001229 // excludeFlag is the legacy shim flag to disable the version.
1230 excludeFlag string
1231 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001232 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1233 versionDTLS uint16
1234 // versionWire, if non-zero, is the wire representation of the
1235 // version. Otherwise the wire version is the protocol version or
1236 // versionDTLS.
1237 versionWire uint16
1238 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001239}
1240
1241func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001242 // The shim uses the protocol version in its public API, but uses the
1243 // DTLS-specific version if it exists.
1244 if protocol == dtls && vers.versionDTLS != 0 {
1245 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001246 }
Steven Valdez520e1222017-06-13 12:45:25 -04001247 return strconv.Itoa(int(vers.version))
1248}
1249
1250func (vers tlsVersion) wire(protocol protocol) uint16 {
1251 if protocol == dtls && vers.versionDTLS != 0 {
1252 return vers.versionDTLS
1253 }
1254 if vers.versionWire != 0 {
1255 return vers.versionWire
1256 }
1257 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001258}
1259
1260var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001261 {
1262 name: "SSL3",
1263 version: VersionSSL30,
1264 excludeFlag: "-no-ssl3",
1265 },
1266 {
1267 name: "TLS1",
1268 version: VersionTLS10,
1269 excludeFlag: "-no-tls1",
1270 hasDTLS: true,
1271 versionDTLS: VersionDTLS10,
1272 },
1273 {
1274 name: "TLS11",
1275 version: VersionTLS11,
1276 excludeFlag: "-no-tls11",
1277 },
1278 {
1279 name: "TLS12",
1280 version: VersionTLS12,
1281 excludeFlag: "-no-tls12",
1282 hasDTLS: true,
1283 versionDTLS: VersionDTLS12,
1284 },
1285 {
1286 name: "TLS13",
1287 version: VersionTLS13,
1288 excludeFlag: "-no-tls13",
1289 versionWire: tls13DraftVersion,
1290 tls13Variant: TLS13Default,
1291 },
1292 {
1293 name: "TLS13Experiment",
1294 version: VersionTLS13,
1295 excludeFlag: "-no-tls13",
1296 versionWire: tls13ExperimentVersion,
1297 tls13Variant: TLS13Experiment,
1298 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001299 {
1300 name: "TLS13RecordTypeExperiment",
1301 version: VersionTLS13,
1302 excludeFlag: "-no-tls13",
1303 versionWire: tls13RecordTypeExperimentVersion,
1304 tls13Variant: TLS13RecordTypeExperiment,
1305 },
Steven Valdez520e1222017-06-13 12:45:25 -04001306}
1307
1308func allVersions(protocol protocol) []tlsVersion {
1309 if protocol == tls {
1310 return tlsVersions
1311 }
1312
1313 var ret []tlsVersion
1314 for _, vers := range tlsVersions {
1315 if vers.hasDTLS {
1316 ret = append(ret, vers)
1317 }
1318 }
1319 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001320}
1321
David Benjaminaa012042016-12-10 13:33:05 -05001322type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001323 name string
1324 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001325}
1326
1327var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001328 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001329 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001330 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001332 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001333 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001334 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001335 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1336 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001337 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1338 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001339 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001340 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001341 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001342 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001343 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001344 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001345 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001346 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001347 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001348 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001349 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1350 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001351 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1352 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001353 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001354 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1355 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1356 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001357 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001358}
1359
David Benjamin8b8c0062014-11-23 02:47:52 -05001360func hasComponent(suiteName, component string) bool {
1361 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1362}
1363
David Benjaminf7768e42014-08-31 02:06:47 -04001364func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001365 return hasComponent(suiteName, "GCM") ||
1366 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001367 hasComponent(suiteName, "SHA384") ||
1368 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001369}
1370
Nick Harper1fd39d82016-06-14 18:14:35 -07001371func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001372 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001373}
1374
David Benjamin8b8c0062014-11-23 02:47:52 -05001375func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001376 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001377}
1378
Adam Langleya7997f12015-05-14 17:38:50 -07001379func bigFromHex(hex string) *big.Int {
1380 ret, ok := new(big.Int).SetString(hex, 16)
1381 if !ok {
1382 panic("failed to parse hex number 0x" + hex)
1383 }
1384 return ret
1385}
1386
Adam Langley7c803a62015-06-15 15:35:05 -07001387func addBasicTests() {
1388 basicTests := []testCase{
1389 {
Adam Langley7c803a62015-06-15 15:35:05 -07001390 name: "NoFallbackSCSV",
1391 config: Config{
1392 Bugs: ProtocolBugs{
1393 FailIfNotFallbackSCSV: true,
1394 },
1395 },
1396 shouldFail: true,
1397 expectedLocalError: "no fallback SCSV found",
1398 },
1399 {
1400 name: "SendFallbackSCSV",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 FailIfNotFallbackSCSV: true,
1404 },
1405 },
1406 flags: []string{"-fallback-scsv"},
1407 },
1408 {
1409 name: "ClientCertificateTypes",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 ClientAuth: RequestClientCert,
1413 ClientCertificateTypes: []byte{
1414 CertTypeDSSSign,
1415 CertTypeRSASign,
1416 CertTypeECDSASign,
1417 },
1418 },
1419 flags: []string{
1420 "-expect-certificate-types",
1421 base64.StdEncoding.EncodeToString([]byte{
1422 CertTypeDSSSign,
1423 CertTypeRSASign,
1424 CertTypeECDSASign,
1425 }),
1426 },
1427 },
1428 {
Adam Langley7c803a62015-06-15 15:35:05 -07001429 name: "UnauthenticatedECDH",
1430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001431 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001432 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1433 Bugs: ProtocolBugs{
1434 UnauthenticatedECDH: true,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":UNEXPECTED_MESSAGE:",
1439 },
1440 {
1441 name: "SkipCertificateStatus",
1442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001443 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Bugs: ProtocolBugs{
1446 SkipCertificateStatus: true,
1447 },
1448 },
1449 flags: []string{
1450 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001451 // This test involves an optional message. Test the message callback
1452 // trace to ensure we do not miss or double-report any.
1453 "-expect-msg-callback",
1454 `write hs 1
1455read hs 2
1456read hs 11
1457read hs 12
1458read hs 14
1459write hs 16
1460write ccs
1461write hs 20
1462read hs 4
1463read ccs
1464read hs 20
1465read alert 1 0
1466`,
1467 },
1468 },
1469 {
1470 protocol: dtls,
1471 name: "SkipCertificateStatus-DTLS",
1472 config: Config{
1473 MaxVersion: VersionTLS12,
1474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1475 Bugs: ProtocolBugs{
1476 SkipCertificateStatus: true,
1477 },
1478 },
1479 flags: []string{
1480 "-enable-ocsp-stapling",
1481 // This test involves an optional message. Test the message callback
1482 // trace to ensure we do not miss or double-report any.
1483 "-expect-msg-callback",
1484 `write hs 1
1485read hs 3
1486write hs 1
1487read hs 2
1488read hs 11
1489read hs 12
1490read hs 14
1491write hs 16
1492write ccs
1493write hs 20
1494read hs 4
1495read ccs
1496read hs 20
1497read alert 1 0
1498`,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 },
1500 },
1501 {
1502 name: "SkipServerKeyExchange",
1503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001504 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1506 Bugs: ProtocolBugs{
1507 SkipServerKeyExchange: true,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_MESSAGE:",
1512 },
1513 {
Adam Langley7c803a62015-06-15 15:35:05 -07001514 testType: serverTest,
1515 name: "Alert",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 SendSpuriousAlert: alertRecordOverflow,
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1523 },
1524 {
1525 protocol: dtls,
1526 testType: serverTest,
1527 name: "Alert-DTLS",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 SendSpuriousAlert: alertRecordOverflow,
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1535 },
1536 {
1537 testType: serverTest,
1538 name: "FragmentAlert",
1539 config: Config{
1540 Bugs: ProtocolBugs{
1541 FragmentAlert: true,
1542 SendSpuriousAlert: alertRecordOverflow,
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":BAD_ALERT:",
1547 },
1548 {
1549 protocol: dtls,
1550 testType: serverTest,
1551 name: "FragmentAlert-DTLS",
1552 config: Config{
1553 Bugs: ProtocolBugs{
1554 FragmentAlert: true,
1555 SendSpuriousAlert: alertRecordOverflow,
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":BAD_ALERT:",
1560 },
1561 {
1562 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001563 name: "DoubleAlert",
1564 config: Config{
1565 Bugs: ProtocolBugs{
1566 DoubleAlert: true,
1567 SendSpuriousAlert: alertRecordOverflow,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":BAD_ALERT:",
1572 },
1573 {
1574 protocol: dtls,
1575 testType: serverTest,
1576 name: "DoubleAlert-DTLS",
1577 config: Config{
1578 Bugs: ProtocolBugs{
1579 DoubleAlert: true,
1580 SendSpuriousAlert: alertRecordOverflow,
1581 },
1582 },
1583 shouldFail: true,
1584 expectedError: ":BAD_ALERT:",
1585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 name: "SkipNewSessionTicket",
1588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001589 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001590 Bugs: ProtocolBugs{
1591 SkipNewSessionTicket: true,
1592 },
1593 },
1594 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001595 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001596 },
1597 {
1598 testType: serverTest,
1599 name: "FallbackSCSV",
1600 config: Config{
1601 MaxVersion: VersionTLS11,
1602 Bugs: ProtocolBugs{
1603 SendFallbackSCSV: true,
1604 },
1605 },
David Benjamin56cadc32016-12-16 19:54:11 -05001606 shouldFail: true,
1607 expectedError: ":INAPPROPRIATE_FALLBACK:",
1608 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001609 },
1610 {
1611 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001612 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001613 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001614 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001615 Bugs: ProtocolBugs{
1616 SendFallbackSCSV: true,
1617 },
1618 },
1619 },
1620 {
1621 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001622 name: "FallbackSCSV-VersionMatch-TLS12",
1623 config: Config{
1624 MaxVersion: VersionTLS12,
1625 Bugs: ProtocolBugs{
1626 SendFallbackSCSV: true,
1627 },
1628 },
1629 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1630 },
1631 {
1632 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 name: "FragmentedClientVersion",
1634 config: Config{
1635 Bugs: ProtocolBugs{
1636 MaxHandshakeRecordLength: 1,
1637 FragmentClientVersion: true,
1638 },
1639 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001640 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001641 },
1642 {
Adam Langley7c803a62015-06-15 15:35:05 -07001643 testType: serverTest,
1644 name: "HttpGET",
1645 sendPrefix: "GET / HTTP/1.0\n",
1646 shouldFail: true,
1647 expectedError: ":HTTP_REQUEST:",
1648 },
1649 {
1650 testType: serverTest,
1651 name: "HttpPOST",
1652 sendPrefix: "POST / HTTP/1.0\n",
1653 shouldFail: true,
1654 expectedError: ":HTTP_REQUEST:",
1655 },
1656 {
1657 testType: serverTest,
1658 name: "HttpHEAD",
1659 sendPrefix: "HEAD / HTTP/1.0\n",
1660 shouldFail: true,
1661 expectedError: ":HTTP_REQUEST:",
1662 },
1663 {
1664 testType: serverTest,
1665 name: "HttpPUT",
1666 sendPrefix: "PUT / HTTP/1.0\n",
1667 shouldFail: true,
1668 expectedError: ":HTTP_REQUEST:",
1669 },
1670 {
1671 testType: serverTest,
1672 name: "HttpCONNECT",
1673 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1674 shouldFail: true,
1675 expectedError: ":HTTPS_PROXY_REQUEST:",
1676 },
1677 {
1678 testType: serverTest,
1679 name: "Garbage",
1680 sendPrefix: "blah",
1681 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001682 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001683 },
1684 {
Adam Langley7c803a62015-06-15 15:35:05 -07001685 name: "RSAEphemeralKey",
1686 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001687 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001688 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1689 Bugs: ProtocolBugs{
1690 RSAEphemeralKey: true,
1691 },
1692 },
1693 shouldFail: true,
1694 expectedError: ":UNEXPECTED_MESSAGE:",
1695 },
1696 {
1697 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001698 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001699 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001700 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
1703 protocol: dtls,
1704 name: "DisableEverything-DTLS",
1705 flags: []string{"-no-tls12", "-no-tls1"},
1706 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001707 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001708 },
1709 {
Adam Langley7c803a62015-06-15 15:35:05 -07001710 protocol: dtls,
1711 testType: serverTest,
1712 name: "MTU",
1713 config: Config{
1714 Bugs: ProtocolBugs{
1715 MaxPacketLength: 256,
1716 },
1717 },
1718 flags: []string{"-mtu", "256"},
1719 },
1720 {
1721 protocol: dtls,
1722 testType: serverTest,
1723 name: "MTUExceeded",
1724 config: Config{
1725 Bugs: ProtocolBugs{
1726 MaxPacketLength: 255,
1727 },
1728 },
1729 flags: []string{"-mtu", "256"},
1730 shouldFail: true,
1731 expectedLocalError: "dtls: exceeded maximum packet length",
1732 },
1733 {
Adam Langley7c803a62015-06-15 15:35:05 -07001734 name: "EmptyCertificateList",
1735 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001736 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001737 Bugs: ProtocolBugs{
1738 EmptyCertificateList: true,
1739 },
1740 },
1741 shouldFail: true,
1742 expectedError: ":DECODE_ERROR:",
1743 },
1744 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001745 name: "EmptyCertificateList-TLS13",
1746 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001747 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001748 Bugs: ProtocolBugs{
1749 EmptyCertificateList: true,
1750 },
1751 },
1752 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001753 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001754 },
1755 {
Adam Langley7c803a62015-06-15 15:35:05 -07001756 name: "TLSFatalBadPackets",
1757 damageFirstWrite: true,
1758 shouldFail: true,
1759 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1760 },
1761 {
1762 protocol: dtls,
1763 name: "DTLSIgnoreBadPackets",
1764 damageFirstWrite: true,
1765 },
1766 {
1767 protocol: dtls,
1768 name: "DTLSIgnoreBadPackets-Async",
1769 damageFirstWrite: true,
1770 flags: []string{"-async"},
1771 },
1772 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001773 name: "AppDataBeforeHandshake",
1774 config: Config{
1775 Bugs: ProtocolBugs{
1776 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1777 },
1778 },
1779 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001780 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001781 },
1782 {
1783 name: "AppDataBeforeHandshake-Empty",
1784 config: Config{
1785 Bugs: ProtocolBugs{
1786 AppDataBeforeHandshake: []byte{},
1787 },
1788 },
1789 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001790 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001791 },
1792 {
1793 protocol: dtls,
1794 name: "AppDataBeforeHandshake-DTLS",
1795 config: Config{
1796 Bugs: ProtocolBugs{
1797 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1798 },
1799 },
1800 shouldFail: true,
1801 expectedError: ":UNEXPECTED_RECORD:",
1802 },
1803 {
1804 protocol: dtls,
1805 name: "AppDataBeforeHandshake-DTLS-Empty",
1806 config: Config{
1807 Bugs: ProtocolBugs{
1808 AppDataBeforeHandshake: []byte{},
1809 },
1810 },
1811 shouldFail: true,
1812 expectedError: ":UNEXPECTED_RECORD:",
1813 },
1814 {
Adam Langley7c803a62015-06-15 15:35:05 -07001815 name: "AppDataAfterChangeCipherSpec",
1816 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001817 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001818 Bugs: ProtocolBugs{
1819 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1820 },
1821 },
1822 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001823 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001824 },
1825 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001826 name: "AppDataAfterChangeCipherSpec-Empty",
1827 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001828 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001829 Bugs: ProtocolBugs{
1830 AppDataAfterChangeCipherSpec: []byte{},
1831 },
1832 },
1833 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001834 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001835 },
1836 {
Adam Langley7c803a62015-06-15 15:35:05 -07001837 protocol: dtls,
1838 name: "AppDataAfterChangeCipherSpec-DTLS",
1839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001840 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001841 Bugs: ProtocolBugs{
1842 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1843 },
1844 },
1845 // BoringSSL's DTLS implementation will drop the out-of-order
1846 // application data.
1847 },
1848 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001849 protocol: dtls,
1850 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001852 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001853 Bugs: ProtocolBugs{
1854 AppDataAfterChangeCipherSpec: []byte{},
1855 },
1856 },
1857 // BoringSSL's DTLS implementation will drop the out-of-order
1858 // application data.
1859 },
1860 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 name: "AlertAfterChangeCipherSpec",
1862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001863 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001864 Bugs: ProtocolBugs{
1865 AlertAfterChangeCipherSpec: alertRecordOverflow,
1866 },
1867 },
1868 shouldFail: true,
1869 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1870 },
1871 {
1872 protocol: dtls,
1873 name: "AlertAfterChangeCipherSpec-DTLS",
1874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001875 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001876 Bugs: ProtocolBugs{
1877 AlertAfterChangeCipherSpec: alertRecordOverflow,
1878 },
1879 },
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1882 },
1883 {
1884 protocol: dtls,
1885 name: "ReorderHandshakeFragments-Small-DTLS",
1886 config: Config{
1887 Bugs: ProtocolBugs{
1888 ReorderHandshakeFragments: true,
1889 // Small enough that every handshake message is
1890 // fragmented.
1891 MaxHandshakeRecordLength: 2,
1892 },
1893 },
1894 },
1895 {
1896 protocol: dtls,
1897 name: "ReorderHandshakeFragments-Large-DTLS",
1898 config: Config{
1899 Bugs: ProtocolBugs{
1900 ReorderHandshakeFragments: true,
1901 // Large enough that no handshake message is
1902 // fragmented.
1903 MaxHandshakeRecordLength: 2048,
1904 },
1905 },
1906 },
1907 {
1908 protocol: dtls,
1909 name: "MixCompleteMessageWithFragments-DTLS",
1910 config: Config{
1911 Bugs: ProtocolBugs{
1912 ReorderHandshakeFragments: true,
1913 MixCompleteMessageWithFragments: true,
1914 MaxHandshakeRecordLength: 2,
1915 },
1916 },
1917 },
1918 {
1919 name: "SendInvalidRecordType",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 SendInvalidRecordType: true,
1923 },
1924 },
1925 shouldFail: true,
1926 expectedError: ":UNEXPECTED_RECORD:",
1927 },
1928 {
1929 protocol: dtls,
1930 name: "SendInvalidRecordType-DTLS",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SendInvalidRecordType: true,
1934 },
1935 },
1936 shouldFail: true,
1937 expectedError: ":UNEXPECTED_RECORD:",
1938 },
1939 {
1940 name: "FalseStart-SkipServerSecondLeg",
1941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001942 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1944 NextProtos: []string{"foo"},
1945 Bugs: ProtocolBugs{
1946 SkipNewSessionTicket: true,
1947 SkipChangeCipherSpec: true,
1948 SkipFinished: true,
1949 ExpectFalseStart: true,
1950 },
1951 },
1952 flags: []string{
1953 "-false-start",
1954 "-handshake-never-done",
1955 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001956 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001957 },
1958 shimWritesFirst: true,
1959 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001960 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001961 },
1962 {
1963 name: "FalseStart-SkipServerSecondLeg-Implicit",
1964 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001965 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1967 NextProtos: []string{"foo"},
1968 Bugs: ProtocolBugs{
1969 SkipNewSessionTicket: true,
1970 SkipChangeCipherSpec: true,
1971 SkipFinished: true,
1972 },
1973 },
1974 flags: []string{
1975 "-implicit-handshake",
1976 "-false-start",
1977 "-handshake-never-done",
1978 "-advertise-alpn", "\x03foo",
1979 },
1980 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001981 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001982 },
1983 {
1984 testType: serverTest,
1985 name: "FailEarlyCallback",
1986 flags: []string{"-fail-early-callback"},
1987 shouldFail: true,
1988 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001989 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001990 },
1991 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001992 name: "FailCertCallback-Client-TLS12",
1993 config: Config{
1994 MaxVersion: VersionTLS12,
1995 ClientAuth: RequestClientCert,
1996 },
1997 flags: []string{"-fail-cert-callback"},
1998 shouldFail: true,
1999 expectedError: ":CERT_CB_ERROR:",
2000 expectedLocalError: "remote error: internal error",
2001 },
2002 {
2003 testType: serverTest,
2004 name: "FailCertCallback-Server-TLS12",
2005 config: Config{
2006 MaxVersion: VersionTLS12,
2007 },
2008 flags: []string{"-fail-cert-callback"},
2009 shouldFail: true,
2010 expectedError: ":CERT_CB_ERROR:",
2011 expectedLocalError: "remote error: internal error",
2012 },
2013 {
2014 name: "FailCertCallback-Client-TLS13",
2015 config: Config{
2016 MaxVersion: VersionTLS13,
2017 ClientAuth: RequestClientCert,
2018 },
2019 flags: []string{"-fail-cert-callback"},
2020 shouldFail: true,
2021 expectedError: ":CERT_CB_ERROR:",
2022 expectedLocalError: "remote error: internal error",
2023 },
2024 {
2025 testType: serverTest,
2026 name: "FailCertCallback-Server-TLS13",
2027 config: Config{
2028 MaxVersion: VersionTLS13,
2029 },
2030 flags: []string{"-fail-cert-callback"},
2031 shouldFail: true,
2032 expectedError: ":CERT_CB_ERROR:",
2033 expectedLocalError: "remote error: internal error",
2034 },
2035 {
Adam Langley7c803a62015-06-15 15:35:05 -07002036 protocol: dtls,
2037 name: "FragmentMessageTypeMismatch-DTLS",
2038 config: Config{
2039 Bugs: ProtocolBugs{
2040 MaxHandshakeRecordLength: 2,
2041 FragmentMessageTypeMismatch: true,
2042 },
2043 },
2044 shouldFail: true,
2045 expectedError: ":FRAGMENT_MISMATCH:",
2046 },
2047 {
2048 protocol: dtls,
2049 name: "FragmentMessageLengthMismatch-DTLS",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 MaxHandshakeRecordLength: 2,
2053 FragmentMessageLengthMismatch: true,
2054 },
2055 },
2056 shouldFail: true,
2057 expectedError: ":FRAGMENT_MISMATCH:",
2058 },
2059 {
2060 protocol: dtls,
2061 name: "SplitFragments-Header-DTLS",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SplitFragments: 2,
2065 },
2066 },
2067 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002068 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002069 },
2070 {
2071 protocol: dtls,
2072 name: "SplitFragments-Boundary-DTLS",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SplitFragments: dtlsRecordHeaderLen,
2076 },
2077 },
2078 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002079 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002080 },
2081 {
2082 protocol: dtls,
2083 name: "SplitFragments-Body-DTLS",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SplitFragments: dtlsRecordHeaderLen + 1,
2087 },
2088 },
2089 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002090 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002091 },
2092 {
2093 protocol: dtls,
2094 name: "SendEmptyFragments-DTLS",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 SendEmptyFragments: true,
2098 },
2099 },
2100 },
2101 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002102 name: "BadFinished-Client",
2103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002104 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002105 Bugs: ProtocolBugs{
2106 BadFinished: true,
2107 },
2108 },
2109 shouldFail: true,
2110 expectedError: ":DIGEST_CHECK_FAILED:",
2111 },
2112 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002113 name: "BadFinished-Client-TLS13",
2114 config: Config{
2115 MaxVersion: VersionTLS13,
2116 Bugs: ProtocolBugs{
2117 BadFinished: true,
2118 },
2119 },
2120 shouldFail: true,
2121 expectedError: ":DIGEST_CHECK_FAILED:",
2122 },
2123 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002124 testType: serverTest,
2125 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002127 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002128 Bugs: ProtocolBugs{
2129 BadFinished: true,
2130 },
2131 },
2132 shouldFail: true,
2133 expectedError: ":DIGEST_CHECK_FAILED:",
2134 },
2135 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002136 testType: serverTest,
2137 name: "BadFinished-Server-TLS13",
2138 config: Config{
2139 MaxVersion: VersionTLS13,
2140 Bugs: ProtocolBugs{
2141 BadFinished: true,
2142 },
2143 },
2144 shouldFail: true,
2145 expectedError: ":DIGEST_CHECK_FAILED:",
2146 },
2147 {
Adam Langley7c803a62015-06-15 15:35:05 -07002148 name: "FalseStart-BadFinished",
2149 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002150 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002151 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2152 NextProtos: []string{"foo"},
2153 Bugs: ProtocolBugs{
2154 BadFinished: true,
2155 ExpectFalseStart: true,
2156 },
2157 },
2158 flags: []string{
2159 "-false-start",
2160 "-handshake-never-done",
2161 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002162 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002163 },
2164 shimWritesFirst: true,
2165 shouldFail: true,
2166 expectedError: ":DIGEST_CHECK_FAILED:",
2167 },
2168 {
2169 name: "NoFalseStart-NoALPN",
2170 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002171 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002172 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2173 Bugs: ProtocolBugs{
2174 ExpectFalseStart: true,
2175 AlertBeforeFalseStartTest: alertAccessDenied,
2176 },
2177 },
2178 flags: []string{
2179 "-false-start",
2180 },
2181 shimWritesFirst: true,
2182 shouldFail: true,
2183 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2184 expectedLocalError: "tls: peer did not false start: EOF",
2185 },
2186 {
2187 name: "NoFalseStart-NoAEAD",
2188 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2191 NextProtos: []string{"foo"},
2192 Bugs: ProtocolBugs{
2193 ExpectFalseStart: true,
2194 AlertBeforeFalseStartTest: alertAccessDenied,
2195 },
2196 },
2197 flags: []string{
2198 "-false-start",
2199 "-advertise-alpn", "\x03foo",
2200 },
2201 shimWritesFirst: true,
2202 shouldFail: true,
2203 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2204 expectedLocalError: "tls: peer did not false start: EOF",
2205 },
2206 {
2207 name: "NoFalseStart-RSA",
2208 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002209 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002210 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2211 NextProtos: []string{"foo"},
2212 Bugs: ProtocolBugs{
2213 ExpectFalseStart: true,
2214 AlertBeforeFalseStartTest: alertAccessDenied,
2215 },
2216 },
2217 flags: []string{
2218 "-false-start",
2219 "-advertise-alpn", "\x03foo",
2220 },
2221 shimWritesFirst: true,
2222 shouldFail: true,
2223 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2224 expectedLocalError: "tls: peer did not false start: EOF",
2225 },
2226 {
Adam Langley7c803a62015-06-15 15:35:05 -07002227 protocol: dtls,
2228 name: "SendSplitAlert-Sync",
2229 config: Config{
2230 Bugs: ProtocolBugs{
2231 SendSplitAlert: true,
2232 },
2233 },
2234 },
2235 {
2236 protocol: dtls,
2237 name: "SendSplitAlert-Async",
2238 config: Config{
2239 Bugs: ProtocolBugs{
2240 SendSplitAlert: true,
2241 },
2242 },
2243 flags: []string{"-async"},
2244 },
2245 {
2246 protocol: dtls,
2247 name: "PackDTLSHandshake",
2248 config: Config{
2249 Bugs: ProtocolBugs{
2250 MaxHandshakeRecordLength: 2,
2251 PackHandshakeFragments: 20,
2252 PackHandshakeRecords: 200,
2253 },
2254 },
2255 },
2256 {
Adam Langley7c803a62015-06-15 15:35:05 -07002257 name: "SendEmptyRecords-Pass",
2258 sendEmptyRecords: 32,
2259 },
2260 {
2261 name: "SendEmptyRecords",
2262 sendEmptyRecords: 33,
2263 shouldFail: true,
2264 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2265 },
2266 {
2267 name: "SendEmptyRecords-Async",
2268 sendEmptyRecords: 33,
2269 flags: []string{"-async"},
2270 shouldFail: true,
2271 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2272 },
2273 {
David Benjamine8e84b92016-08-03 15:39:47 -04002274 name: "SendWarningAlerts-Pass",
2275 config: Config{
2276 MaxVersion: VersionTLS12,
2277 },
Adam Langley7c803a62015-06-15 15:35:05 -07002278 sendWarningAlerts: 4,
2279 },
2280 {
David Benjamine8e84b92016-08-03 15:39:47 -04002281 protocol: dtls,
2282 name: "SendWarningAlerts-DTLS-Pass",
2283 config: Config{
2284 MaxVersion: VersionTLS12,
2285 },
Adam Langley7c803a62015-06-15 15:35:05 -07002286 sendWarningAlerts: 4,
2287 },
2288 {
David Benjamine8e84b92016-08-03 15:39:47 -04002289 name: "SendWarningAlerts-TLS13",
2290 config: Config{
2291 MaxVersion: VersionTLS13,
2292 },
2293 sendWarningAlerts: 4,
2294 shouldFail: true,
2295 expectedError: ":BAD_ALERT:",
2296 expectedLocalError: "remote error: error decoding message",
2297 },
2298 {
2299 name: "SendWarningAlerts",
2300 config: Config{
2301 MaxVersion: VersionTLS12,
2302 },
Adam Langley7c803a62015-06-15 15:35:05 -07002303 sendWarningAlerts: 5,
2304 shouldFail: true,
2305 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2306 },
2307 {
David Benjamine8e84b92016-08-03 15:39:47 -04002308 name: "SendWarningAlerts-Async",
2309 config: Config{
2310 MaxVersion: VersionTLS12,
2311 },
Adam Langley7c803a62015-06-15 15:35:05 -07002312 sendWarningAlerts: 5,
2313 flags: []string{"-async"},
2314 shouldFail: true,
2315 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2316 },
David Benjaminba4594a2015-06-18 18:36:15 -04002317 {
David Benjamin24e58862017-06-14 18:45:29 -04002318 name: "SendBogusAlertType",
2319 sendBogusAlertType: true,
2320 shouldFail: true,
2321 expectedError: ":UNKNOWN_ALERT_TYPE:",
2322 expectedLocalError: "remote error: illegal parameter",
2323 },
2324 {
2325 protocol: dtls,
2326 name: "SendBogusAlertType-DTLS",
2327 sendBogusAlertType: true,
2328 shouldFail: true,
2329 expectedError: ":UNKNOWN_ALERT_TYPE:",
2330 expectedLocalError: "remote error: illegal parameter",
2331 },
2332 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002333 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002334 config: Config{
2335 MaxVersion: VersionTLS13,
2336 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002337 sendKeyUpdates: 33,
2338 keyUpdateRequest: keyUpdateNotRequested,
2339 shouldFail: true,
2340 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002341 },
2342 {
David Benjaminba4594a2015-06-18 18:36:15 -04002343 name: "EmptySessionID",
2344 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002345 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002346 SessionTicketsDisabled: true,
2347 },
2348 noSessionCache: true,
2349 flags: []string{"-expect-no-session"},
2350 },
David Benjamin30789da2015-08-29 22:56:45 -04002351 {
2352 name: "Unclean-Shutdown",
2353 config: Config{
2354 Bugs: ProtocolBugs{
2355 NoCloseNotify: true,
2356 ExpectCloseNotify: true,
2357 },
2358 },
2359 shimShutsDown: true,
2360 flags: []string{"-check-close-notify"},
2361 shouldFail: true,
2362 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2363 },
2364 {
2365 name: "Unclean-Shutdown-Ignored",
2366 config: Config{
2367 Bugs: ProtocolBugs{
2368 NoCloseNotify: true,
2369 },
2370 },
2371 shimShutsDown: true,
2372 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002373 {
David Benjaminfa214e42016-05-10 17:03:10 -04002374 name: "Unclean-Shutdown-Alert",
2375 config: Config{
2376 Bugs: ProtocolBugs{
2377 SendAlertOnShutdown: alertDecompressionFailure,
2378 ExpectCloseNotify: true,
2379 },
2380 },
2381 shimShutsDown: true,
2382 flags: []string{"-check-close-notify"},
2383 shouldFail: true,
2384 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2385 },
2386 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002387 name: "LargePlaintext",
2388 config: Config{
2389 Bugs: ProtocolBugs{
2390 SendLargeRecords: true,
2391 },
2392 },
2393 messageLen: maxPlaintext + 1,
2394 shouldFail: true,
2395 expectedError: ":DATA_LENGTH_TOO_LONG:",
2396 },
2397 {
2398 protocol: dtls,
2399 name: "LargePlaintext-DTLS",
2400 config: Config{
2401 Bugs: ProtocolBugs{
2402 SendLargeRecords: true,
2403 },
2404 },
2405 messageLen: maxPlaintext + 1,
2406 shouldFail: true,
2407 expectedError: ":DATA_LENGTH_TOO_LONG:",
2408 },
2409 {
2410 name: "LargeCiphertext",
2411 config: Config{
2412 Bugs: ProtocolBugs{
2413 SendLargeRecords: true,
2414 },
2415 },
2416 messageLen: maxPlaintext * 2,
2417 shouldFail: true,
2418 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2419 },
2420 {
2421 protocol: dtls,
2422 name: "LargeCiphertext-DTLS",
2423 config: Config{
2424 Bugs: ProtocolBugs{
2425 SendLargeRecords: true,
2426 },
2427 },
2428 messageLen: maxPlaintext * 2,
2429 // Unlike the other four cases, DTLS drops records which
2430 // are invalid before authentication, so the connection
2431 // does not fail.
2432 expectMessageDropped: true,
2433 },
David Benjamindd6fed92015-10-23 17:41:12 -04002434 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002435 name: "BadHelloRequest-1",
2436 renegotiate: 1,
2437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002438 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002439 Bugs: ProtocolBugs{
2440 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2441 },
2442 },
2443 flags: []string{
2444 "-renegotiate-freely",
2445 "-expect-total-renegotiations", "1",
2446 },
2447 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002448 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002449 },
2450 {
2451 name: "BadHelloRequest-2",
2452 renegotiate: 1,
2453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002454 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002455 Bugs: ProtocolBugs{
2456 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2457 },
2458 },
2459 flags: []string{
2460 "-renegotiate-freely",
2461 "-expect-total-renegotiations", "1",
2462 },
2463 shouldFail: true,
2464 expectedError: ":BAD_HELLO_REQUEST:",
2465 },
David Benjaminef1b0092015-11-21 14:05:44 -05002466 {
2467 testType: serverTest,
2468 name: "SupportTicketsWithSessionID",
2469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002470 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002471 SessionTicketsDisabled: true,
2472 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002473 resumeConfig: &Config{
2474 MaxVersion: VersionTLS12,
2475 },
David Benjaminef1b0092015-11-21 14:05:44 -05002476 resumeSession: true,
2477 },
David Benjamin02edcd02016-07-27 17:40:37 -04002478 {
2479 protocol: dtls,
2480 name: "DTLS-SendExtraFinished",
2481 config: Config{
2482 Bugs: ProtocolBugs{
2483 SendExtraFinished: true,
2484 },
2485 },
2486 shouldFail: true,
2487 expectedError: ":UNEXPECTED_RECORD:",
2488 },
2489 {
2490 protocol: dtls,
2491 name: "DTLS-SendExtraFinished-Reordered",
2492 config: Config{
2493 Bugs: ProtocolBugs{
2494 MaxHandshakeRecordLength: 2,
2495 ReorderHandshakeFragments: true,
2496 SendExtraFinished: true,
2497 },
2498 },
2499 shouldFail: true,
2500 expectedError: ":UNEXPECTED_RECORD:",
2501 },
David Benjamine97fb482016-07-29 09:23:07 -04002502 {
2503 testType: serverTest,
2504 name: "V2ClientHello-EmptyRecordPrefix",
2505 config: Config{
2506 // Choose a cipher suite that does not involve
2507 // elliptic curves, so no extensions are
2508 // involved.
2509 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002510 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002511 Bugs: ProtocolBugs{
2512 SendV2ClientHello: true,
2513 },
2514 },
2515 sendPrefix: string([]byte{
2516 byte(recordTypeHandshake),
2517 3, 1, // version
2518 0, 0, // length
2519 }),
2520 // A no-op empty record may not be sent before V2ClientHello.
2521 shouldFail: true,
2522 expectedError: ":WRONG_VERSION_NUMBER:",
2523 },
2524 {
2525 testType: serverTest,
2526 name: "V2ClientHello-WarningAlertPrefix",
2527 config: Config{
2528 // Choose a cipher suite that does not involve
2529 // elliptic curves, so no extensions are
2530 // involved.
2531 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002532 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002533 Bugs: ProtocolBugs{
2534 SendV2ClientHello: true,
2535 },
2536 },
2537 sendPrefix: string([]byte{
2538 byte(recordTypeAlert),
2539 3, 1, // version
2540 0, 2, // length
2541 alertLevelWarning, byte(alertDecompressionFailure),
2542 }),
2543 // A no-op warning alert may not be sent before V2ClientHello.
2544 shouldFail: true,
2545 expectedError: ":WRONG_VERSION_NUMBER:",
2546 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002547 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002548 name: "KeyUpdate-Client",
2549 config: Config{
2550 MaxVersion: VersionTLS13,
2551 },
2552 sendKeyUpdates: 1,
2553 keyUpdateRequest: keyUpdateNotRequested,
2554 },
2555 {
2556 testType: serverTest,
2557 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002558 config: Config{
2559 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002560 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002561 sendKeyUpdates: 1,
2562 keyUpdateRequest: keyUpdateNotRequested,
2563 },
2564 {
2565 name: "KeyUpdate-InvalidRequestMode",
2566 config: Config{
2567 MaxVersion: VersionTLS13,
2568 },
2569 sendKeyUpdates: 1,
2570 keyUpdateRequest: 42,
2571 shouldFail: true,
2572 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002573 },
David Benjaminabe94e32016-09-04 14:18:58 -04002574 {
David Benjaminbbba9392017-04-06 12:54:12 -04002575 // Test that KeyUpdates are acknowledged properly.
2576 name: "KeyUpdate-RequestACK",
2577 config: Config{
2578 MaxVersion: VersionTLS13,
2579 Bugs: ProtocolBugs{
2580 RejectUnsolicitedKeyUpdate: true,
2581 },
2582 },
2583 // Test the shim receiving many KeyUpdates in a row.
2584 sendKeyUpdates: 5,
2585 messageCount: 5,
2586 keyUpdateRequest: keyUpdateRequested,
2587 },
2588 {
2589 // Test that KeyUpdates are acknowledged properly if the
2590 // peer's KeyUpdate is discovered while a write is
2591 // pending.
2592 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2593 config: Config{
2594 MaxVersion: VersionTLS13,
2595 Bugs: ProtocolBugs{
2596 RejectUnsolicitedKeyUpdate: true,
2597 },
2598 },
2599 // Test the shim receiving many KeyUpdates in a row.
2600 sendKeyUpdates: 5,
2601 messageCount: 5,
2602 keyUpdateRequest: keyUpdateRequested,
2603 readWithUnfinishedWrite: true,
2604 flags: []string{"-async"},
2605 },
2606 {
David Benjaminabe94e32016-09-04 14:18:58 -04002607 name: "SendSNIWarningAlert",
2608 config: Config{
2609 MaxVersion: VersionTLS12,
2610 Bugs: ProtocolBugs{
2611 SendSNIWarningAlert: true,
2612 },
2613 },
2614 },
David Benjaminc241d792016-09-09 10:34:20 -04002615 {
2616 testType: serverTest,
2617 name: "ExtraCompressionMethods-TLS12",
2618 config: Config{
2619 MaxVersion: VersionTLS12,
2620 Bugs: ProtocolBugs{
2621 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2622 },
2623 },
2624 },
2625 {
2626 testType: serverTest,
2627 name: "ExtraCompressionMethods-TLS13",
2628 config: Config{
2629 MaxVersion: VersionTLS13,
2630 Bugs: ProtocolBugs{
2631 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2632 },
2633 },
2634 shouldFail: true,
2635 expectedError: ":INVALID_COMPRESSION_LIST:",
2636 expectedLocalError: "remote error: illegal parameter",
2637 },
2638 {
2639 testType: serverTest,
2640 name: "NoNullCompression-TLS12",
2641 config: Config{
2642 MaxVersion: VersionTLS12,
2643 Bugs: ProtocolBugs{
2644 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2645 },
2646 },
2647 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002648 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002649 expectedLocalError: "remote error: illegal parameter",
2650 },
2651 {
2652 testType: serverTest,
2653 name: "NoNullCompression-TLS13",
2654 config: Config{
2655 MaxVersion: VersionTLS13,
2656 Bugs: ProtocolBugs{
2657 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2658 },
2659 },
2660 shouldFail: true,
2661 expectedError: ":INVALID_COMPRESSION_LIST:",
2662 expectedLocalError: "remote error: illegal parameter",
2663 },
David Benjamin413e79e2017-07-01 10:11:53 -04002664 // Test that the client rejects invalid compression methods
2665 // from the server.
2666 {
2667 testType: clientTest,
2668 name: "InvalidCompressionMethod",
2669 config: Config{
2670 MaxVersion: VersionTLS12,
2671 Bugs: ProtocolBugs{
2672 SendCompressionMethod: 1,
2673 },
2674 },
2675 shouldFail: true,
2676 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2677 expectedLocalError: "remote error: illegal parameter",
2678 },
David Benjamin65ac9972016-09-02 21:35:25 -04002679 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002680 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002681 config: Config{
2682 MaxVersion: VersionTLS12,
2683 Bugs: ProtocolBugs{
2684 ExpectGREASE: true,
2685 },
2686 },
2687 flags: []string{"-enable-grease"},
2688 },
2689 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002690 name: "GREASE-Client-TLS13",
2691 config: Config{
2692 MaxVersion: VersionTLS13,
2693 Bugs: ProtocolBugs{
2694 ExpectGREASE: true,
2695 },
2696 },
2697 flags: []string{"-enable-grease"},
2698 },
2699 {
2700 testType: serverTest,
2701 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002702 config: Config{
2703 MaxVersion: VersionTLS13,
2704 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002705 // TLS 1.3 servers are expected to
2706 // always enable GREASE. TLS 1.3 is new,
2707 // so there is no existing ecosystem to
2708 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002709 ExpectGREASE: true,
2710 },
2711 },
David Benjamin65ac9972016-09-02 21:35:25 -04002712 },
David Benjamine3fbb362017-01-06 16:19:28 -05002713 {
2714 // Test the server so there is a large certificate as
2715 // well as application data.
2716 testType: serverTest,
2717 name: "MaxSendFragment",
2718 config: Config{
2719 Bugs: ProtocolBugs{
2720 MaxReceivePlaintext: 512,
2721 },
2722 },
2723 messageLen: 1024,
2724 flags: []string{
2725 "-max-send-fragment", "512",
2726 "-read-size", "1024",
2727 },
2728 },
2729 {
2730 // Test the server so there is a large certificate as
2731 // well as application data.
2732 testType: serverTest,
2733 name: "MaxSendFragment-TooLarge",
2734 config: Config{
2735 Bugs: ProtocolBugs{
2736 // Ensure that some of the records are
2737 // 512.
2738 MaxReceivePlaintext: 511,
2739 },
2740 },
2741 messageLen: 1024,
2742 flags: []string{
2743 "-max-send-fragment", "512",
2744 "-read-size", "1024",
2745 },
2746 shouldFail: true,
2747 expectedLocalError: "local error: record overflow",
2748 },
Adam Langley7c803a62015-06-15 15:35:05 -07002749 }
Adam Langley7c803a62015-06-15 15:35:05 -07002750 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002751
2752 // Test that very large messages can be received.
2753 cert := rsaCertificate
2754 for i := 0; i < 50; i++ {
2755 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2756 }
2757 testCases = append(testCases, testCase{
2758 name: "LargeMessage",
2759 config: Config{
2760 Certificates: []Certificate{cert},
2761 },
2762 })
2763 testCases = append(testCases, testCase{
2764 protocol: dtls,
2765 name: "LargeMessage-DTLS",
2766 config: Config{
2767 Certificates: []Certificate{cert},
2768 },
2769 })
2770
2771 // They are rejected if the maximum certificate chain length is capped.
2772 testCases = append(testCases, testCase{
2773 name: "LargeMessage-Reject",
2774 config: Config{
2775 Certificates: []Certificate{cert},
2776 },
2777 flags: []string{"-max-cert-list", "16384"},
2778 shouldFail: true,
2779 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2780 })
2781 testCases = append(testCases, testCase{
2782 protocol: dtls,
2783 name: "LargeMessage-Reject-DTLS",
2784 config: Config{
2785 Certificates: []Certificate{cert},
2786 },
2787 flags: []string{"-max-cert-list", "16384"},
2788 shouldFail: true,
2789 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2790 })
Adam Langley7c803a62015-06-15 15:35:05 -07002791}
2792
David Benjaminaa012042016-12-10 13:33:05 -05002793func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2794 const psk = "12345"
2795 const pskIdentity = "luggage combo"
2796
2797 var prefix string
2798 if protocol == dtls {
2799 if !ver.hasDTLS {
2800 return
2801 }
2802 prefix = "D"
2803 }
2804
2805 var cert Certificate
2806 var certFile string
2807 var keyFile string
2808 if hasComponent(suite.name, "ECDSA") {
2809 cert = ecdsaP256Certificate
2810 certFile = ecdsaP256CertificateFile
2811 keyFile = ecdsaP256KeyFile
2812 } else {
2813 cert = rsaCertificate
2814 certFile = rsaCertificateFile
2815 keyFile = rsaKeyFile
2816 }
2817
2818 var flags []string
2819 if hasComponent(suite.name, "PSK") {
2820 flags = append(flags,
2821 "-psk", psk,
2822 "-psk-identity", pskIdentity)
2823 }
2824 if hasComponent(suite.name, "NULL") {
2825 // NULL ciphers must be explicitly enabled.
2826 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2827 }
David Benjaminaa012042016-12-10 13:33:05 -05002828
2829 var shouldServerFail, shouldClientFail bool
2830 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2831 // BoringSSL clients accept ECDHE on SSLv3, but
2832 // a BoringSSL server will never select it
2833 // because the extension is missing.
2834 shouldServerFail = true
2835 }
2836 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2837 shouldClientFail = true
2838 shouldServerFail = true
2839 }
2840 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2841 shouldClientFail = true
2842 shouldServerFail = true
2843 }
2844 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2845 shouldClientFail = true
2846 shouldServerFail = true
2847 }
2848 if !isDTLSCipher(suite.name) && protocol == dtls {
2849 shouldClientFail = true
2850 shouldServerFail = true
2851 }
2852
2853 var sendCipherSuite uint16
2854 var expectedServerError, expectedClientError string
2855 serverCipherSuites := []uint16{suite.id}
2856 if shouldServerFail {
2857 expectedServerError = ":NO_SHARED_CIPHER:"
2858 }
2859 if shouldClientFail {
2860 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2861 // Configure the server to select ciphers as normal but
2862 // select an incompatible cipher in ServerHello.
2863 serverCipherSuites = nil
2864 sendCipherSuite = suite.id
2865 }
2866
David Benjamincdb6fe92017-02-07 16:06:48 -05002867 // For cipher suites and versions where exporters are defined, verify
2868 // that they interoperate.
2869 var exportKeyingMaterial int
2870 if ver.version > VersionSSL30 {
2871 exportKeyingMaterial = 1024
2872 }
2873
David Benjaminaa012042016-12-10 13:33:05 -05002874 testCases = append(testCases, testCase{
2875 testType: serverTest,
2876 protocol: protocol,
2877 name: prefix + ver.name + "-" + suite.name + "-server",
2878 config: Config{
2879 MinVersion: ver.version,
2880 MaxVersion: ver.version,
2881 CipherSuites: []uint16{suite.id},
2882 Certificates: []Certificate{cert},
2883 PreSharedKey: []byte(psk),
2884 PreSharedKeyIdentity: pskIdentity,
2885 Bugs: ProtocolBugs{
2886 AdvertiseAllConfiguredCiphers: true,
2887 },
2888 },
David Benjamina5022392017-07-10 17:40:39 -04002889 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002890 certFile: certFile,
2891 keyFile: keyFile,
2892 flags: flags,
2893 resumeSession: true,
2894 shouldFail: shouldServerFail,
2895 expectedError: expectedServerError,
2896 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002897 })
2898
2899 testCases = append(testCases, testCase{
2900 testType: clientTest,
2901 protocol: protocol,
2902 name: prefix + ver.name + "-" + suite.name + "-client",
2903 config: Config{
2904 MinVersion: ver.version,
2905 MaxVersion: ver.version,
2906 CipherSuites: serverCipherSuites,
2907 Certificates: []Certificate{cert},
2908 PreSharedKey: []byte(psk),
2909 PreSharedKeyIdentity: pskIdentity,
2910 Bugs: ProtocolBugs{
2911 IgnorePeerCipherPreferences: shouldClientFail,
2912 SendCipherSuite: sendCipherSuite,
2913 },
2914 },
David Benjamina5022392017-07-10 17:40:39 -04002915 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002916 flags: flags,
2917 resumeSession: true,
2918 shouldFail: shouldClientFail,
2919 expectedError: expectedClientError,
2920 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002921 })
2922
David Benjamin6f600d62016-12-21 16:06:54 -05002923 if shouldClientFail {
2924 return
2925 }
2926
2927 // Ensure the maximum record size is accepted.
2928 testCases = append(testCases, testCase{
2929 protocol: protocol,
2930 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2931 config: Config{
2932 MinVersion: ver.version,
2933 MaxVersion: ver.version,
2934 CipherSuites: []uint16{suite.id},
2935 Certificates: []Certificate{cert},
2936 PreSharedKey: []byte(psk),
2937 PreSharedKeyIdentity: pskIdentity,
2938 },
David Benjamina5022392017-07-10 17:40:39 -04002939 tls13Variant: ver.tls13Variant,
2940 flags: flags,
2941 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002942 })
2943
2944 // Test bad records for all ciphers. Bad records are fatal in TLS
2945 // and ignored in DTLS.
2946 var shouldFail bool
2947 var expectedError string
2948 if protocol == tls {
2949 shouldFail = true
2950 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2951 }
2952
2953 testCases = append(testCases, testCase{
2954 protocol: protocol,
2955 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2956 config: Config{
2957 MinVersion: ver.version,
2958 MaxVersion: ver.version,
2959 CipherSuites: []uint16{suite.id},
2960 Certificates: []Certificate{cert},
2961 PreSharedKey: []byte(psk),
2962 PreSharedKeyIdentity: pskIdentity,
2963 },
David Benjamina5022392017-07-10 17:40:39 -04002964 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002965 flags: flags,
2966 damageFirstWrite: true,
2967 messageLen: maxPlaintext,
2968 shouldFail: shouldFail,
2969 expectedError: expectedError,
2970 })
David Benjaminaa012042016-12-10 13:33:05 -05002971}
2972
Adam Langley95c29f32014-06-20 12:00:00 -07002973func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002974 const bogusCipher = 0xfe00
2975
Adam Langley95c29f32014-06-20 12:00:00 -07002976 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002977 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002978 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002979 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002980 }
David Benjamin2c99d282015-09-01 10:23:00 -04002981 }
Adam Langley95c29f32014-06-20 12:00:00 -07002982 }
Adam Langleya7997f12015-05-14 17:38:50 -07002983
2984 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002985 name: "NoSharedCipher",
2986 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002987 MaxVersion: VersionTLS12,
2988 CipherSuites: []uint16{},
2989 },
2990 shouldFail: true,
2991 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2992 })
2993
2994 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002995 name: "NoSharedCipher-TLS13",
2996 config: Config{
2997 MaxVersion: VersionTLS13,
2998 CipherSuites: []uint16{},
2999 },
3000 shouldFail: true,
3001 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3002 })
3003
3004 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003005 name: "UnsupportedCipherSuite",
3006 config: Config{
3007 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003008 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003009 Bugs: ProtocolBugs{
3010 IgnorePeerCipherPreferences: true,
3011 },
3012 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003013 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003014 shouldFail: true,
3015 expectedError: ":WRONG_CIPHER_RETURNED:",
3016 })
3017
3018 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003019 name: "ServerHelloBogusCipher",
3020 config: Config{
3021 MaxVersion: VersionTLS12,
3022 Bugs: ProtocolBugs{
3023 SendCipherSuite: bogusCipher,
3024 },
3025 },
3026 shouldFail: true,
3027 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3028 })
3029 testCases = append(testCases, testCase{
3030 name: "ServerHelloBogusCipher-TLS13",
3031 config: Config{
3032 MaxVersion: VersionTLS13,
3033 Bugs: ProtocolBugs{
3034 SendCipherSuite: bogusCipher,
3035 },
3036 },
3037 shouldFail: true,
3038 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3039 })
3040
David Benjamin241ae832016-01-15 03:04:54 -05003041 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003042 testCases = append(testCases, testCase{
3043 testType: serverTest,
3044 name: "UnknownCipher",
3045 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003046 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003047 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003048 Bugs: ProtocolBugs{
3049 AdvertiseAllConfiguredCiphers: true,
3050 },
3051 },
3052 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003053
3054 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003055 testCases = append(testCases, testCase{
3056 testType: serverTest,
3057 name: "UnknownCipher-TLS13",
3058 config: Config{
3059 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003060 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003061 Bugs: ProtocolBugs{
3062 AdvertiseAllConfiguredCiphers: true,
3063 },
David Benjamin241ae832016-01-15 03:04:54 -05003064 },
3065 })
3066
David Benjamin78679342016-09-16 19:42:05 -04003067 // Test empty ECDHE_PSK identity hints work as expected.
3068 testCases = append(testCases, testCase{
3069 name: "EmptyECDHEPSKHint",
3070 config: Config{
3071 MaxVersion: VersionTLS12,
3072 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3073 PreSharedKey: []byte("secret"),
3074 },
3075 flags: []string{"-psk", "secret"},
3076 })
3077
3078 // Test empty PSK identity hints work as expected, even if an explicit
3079 // ServerKeyExchange is sent.
3080 testCases = append(testCases, testCase{
3081 name: "ExplicitEmptyPSKHint",
3082 config: Config{
3083 MaxVersion: VersionTLS12,
3084 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3085 PreSharedKey: []byte("secret"),
3086 Bugs: ProtocolBugs{
3087 AlwaysSendPreSharedKeyIdentityHint: true,
3088 },
3089 },
3090 flags: []string{"-psk", "secret"},
3091 })
David Benjamin69522112017-03-28 15:38:29 -05003092
3093 // Test that clients enforce that the server-sent certificate and cipher
3094 // suite match in TLS 1.2.
3095 testCases = append(testCases, testCase{
3096 name: "CertificateCipherMismatch-RSA",
3097 config: Config{
3098 MaxVersion: VersionTLS12,
3099 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3100 Certificates: []Certificate{rsaCertificate},
3101 Bugs: ProtocolBugs{
3102 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3103 },
3104 },
3105 shouldFail: true,
3106 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3107 })
3108 testCases = append(testCases, testCase{
3109 name: "CertificateCipherMismatch-ECDSA",
3110 config: Config{
3111 MaxVersion: VersionTLS12,
3112 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3113 Certificates: []Certificate{ecdsaP256Certificate},
3114 Bugs: ProtocolBugs{
3115 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3116 },
3117 },
3118 shouldFail: true,
3119 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3120 })
3121 testCases = append(testCases, testCase{
3122 name: "CertificateCipherMismatch-Ed25519",
3123 config: Config{
3124 MaxVersion: VersionTLS12,
3125 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3126 Certificates: []Certificate{ed25519Certificate},
3127 Bugs: ProtocolBugs{
3128 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3129 },
3130 },
3131 shouldFail: true,
3132 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3133 })
3134
3135 // Test that servers decline to select a cipher suite which is
3136 // inconsistent with their configured certificate.
3137 testCases = append(testCases, testCase{
3138 testType: serverTest,
3139 name: "ServerCipherFilter-RSA",
3140 config: Config{
3141 MaxVersion: VersionTLS12,
3142 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3143 },
3144 flags: []string{
3145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3147 },
3148 shouldFail: true,
3149 expectedError: ":NO_SHARED_CIPHER:",
3150 })
3151 testCases = append(testCases, testCase{
3152 testType: serverTest,
3153 name: "ServerCipherFilter-ECDSA",
3154 config: Config{
3155 MaxVersion: VersionTLS12,
3156 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3157 },
3158 flags: []string{
3159 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3160 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3161 },
3162 shouldFail: true,
3163 expectedError: ":NO_SHARED_CIPHER:",
3164 })
3165 testCases = append(testCases, testCase{
3166 testType: serverTest,
3167 name: "ServerCipherFilter-Ed25519",
3168 config: Config{
3169 MaxVersion: VersionTLS12,
3170 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3171 },
3172 flags: []string{
3173 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3174 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3175 },
3176 shouldFail: true,
3177 expectedError: ":NO_SHARED_CIPHER:",
3178 })
David Benjamin364af782017-07-01 10:35:27 -04003179
3180 // Test cipher suite negotiation works as expected. Configure a
3181 // complicated cipher suite configuration.
3182 const negotiationTestCiphers = "" +
3183 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3184 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3185 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3186 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3187 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3188 negotiationTests := []struct {
3189 ciphers []uint16
3190 expected uint16
3191 }{
3192 // Server preferences are honored, including when
3193 // equipreference groups are involved.
3194 {
3195 []uint16{
3196 TLS_RSA_WITH_AES_256_GCM_SHA384,
3197 TLS_RSA_WITH_AES_128_CBC_SHA,
3198 TLS_RSA_WITH_AES_128_GCM_SHA256,
3199 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3200 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3201 },
3202 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3203 },
3204 {
3205 []uint16{
3206 TLS_RSA_WITH_AES_256_GCM_SHA384,
3207 TLS_RSA_WITH_AES_128_CBC_SHA,
3208 TLS_RSA_WITH_AES_128_GCM_SHA256,
3209 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3210 },
3211 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3212 },
3213 {
3214 []uint16{
3215 TLS_RSA_WITH_AES_256_GCM_SHA384,
3216 TLS_RSA_WITH_AES_128_CBC_SHA,
3217 TLS_RSA_WITH_AES_128_GCM_SHA256,
3218 },
3219 TLS_RSA_WITH_AES_128_GCM_SHA256,
3220 },
3221 {
3222 []uint16{
3223 TLS_RSA_WITH_AES_256_GCM_SHA384,
3224 TLS_RSA_WITH_AES_128_CBC_SHA,
3225 },
3226 TLS_RSA_WITH_AES_128_CBC_SHA,
3227 },
3228 // Equipreference groups use the client preference.
3229 {
3230 []uint16{
3231 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3232 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3233 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3234 },
3235 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3236 },
3237 {
3238 []uint16{
3239 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3240 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3241 },
3242 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3243 },
3244 {
3245 []uint16{
3246 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3247 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3248 },
3249 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3250 },
3251 {
3252 []uint16{
3253 TLS_RSA_WITH_AES_256_GCM_SHA384,
3254 TLS_RSA_WITH_AES_256_CBC_SHA,
3255 },
3256 TLS_RSA_WITH_AES_256_GCM_SHA384,
3257 },
3258 {
3259 []uint16{
3260 TLS_RSA_WITH_AES_256_CBC_SHA,
3261 TLS_RSA_WITH_AES_256_GCM_SHA384,
3262 },
3263 TLS_RSA_WITH_AES_256_CBC_SHA,
3264 },
3265 // If there are two equipreference groups, the preferred one
3266 // takes precedence.
3267 {
3268 []uint16{
3269 TLS_RSA_WITH_AES_256_GCM_SHA384,
3270 TLS_RSA_WITH_AES_256_CBC_SHA,
3271 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3272 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3273 },
3274 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3275 },
3276 }
3277 for i, t := range negotiationTests {
3278 testCases = append(testCases, testCase{
3279 testType: serverTest,
3280 name: "CipherNegotiation-" + strconv.Itoa(i),
3281 config: Config{
3282 MaxVersion: VersionTLS12,
3283 CipherSuites: t.ciphers,
3284 },
3285 flags: []string{"-cipher", negotiationTestCiphers},
3286 expectedCipher: t.expected,
3287 })
3288 }
Adam Langley95c29f32014-06-20 12:00:00 -07003289}
3290
3291func addBadECDSASignatureTests() {
3292 for badR := BadValue(1); badR < NumBadValues; badR++ {
3293 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003294 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003295 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3296 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003297 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003298 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003299 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003300 Bugs: ProtocolBugs{
3301 BadECDSAR: badR,
3302 BadECDSAS: badS,
3303 },
3304 },
3305 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003306 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003307 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003308 testCases = append(testCases, testCase{
3309 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3310 config: Config{
3311 MaxVersion: VersionTLS13,
3312 Certificates: []Certificate{ecdsaP256Certificate},
3313 Bugs: ProtocolBugs{
3314 BadECDSAR: badR,
3315 BadECDSAS: badS,
3316 },
3317 },
3318 shouldFail: true,
3319 expectedError: ":BAD_SIGNATURE:",
3320 })
Adam Langley95c29f32014-06-20 12:00:00 -07003321 }
3322 }
3323}
3324
Adam Langley80842bd2014-06-20 12:00:00 -07003325func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003326 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003327 name: "MaxCBCPadding",
3328 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003329 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003330 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3331 Bugs: ProtocolBugs{
3332 MaxPadding: true,
3333 },
3334 },
3335 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3336 })
David Benjamin025b3d32014-07-01 19:53:04 -04003337 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003338 name: "BadCBCPadding",
3339 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003340 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3342 Bugs: ProtocolBugs{
3343 PaddingFirstByteBad: true,
3344 },
3345 },
3346 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003347 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003348 })
3349 // OpenSSL previously had an issue where the first byte of padding in
3350 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003351 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003352 name: "BadCBCPadding255",
3353 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003354 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3356 Bugs: ProtocolBugs{
3357 MaxPadding: true,
3358 PaddingFirstByteBadIf255: true,
3359 },
3360 },
3361 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3362 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003363 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003364 })
3365}
3366
Kenny Root7fdeaf12014-08-05 15:23:37 -07003367func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003368 var cbcCiphers = []struct {
3369 name string
3370 cipher uint16
3371 }{
3372 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3373 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3374 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3375 }
3376 for _, t := range cbcCiphers {
3377 testCases = append(testCases, testCase{
3378 name: "CBCRecordSplitting-" + t.name,
3379 config: Config{
3380 MaxVersion: VersionTLS10,
3381 MinVersion: VersionTLS10,
3382 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003383 Bugs: ProtocolBugs{
3384 ExpectRecordSplitting: true,
3385 },
David Benjamina1ce8562017-07-01 11:46:57 -04003386 },
3387 messageLen: -1, // read until EOF
3388 resumeSession: true,
3389 flags: []string{
3390 "-async",
3391 "-write-different-record-sizes",
3392 "-cbc-record-splitting",
3393 },
3394 })
3395 testCases = append(testCases, testCase{
3396 name: "CBCRecordSplittingPartialWrite-" + t.name,
3397 config: Config{
3398 MaxVersion: VersionTLS10,
3399 MinVersion: VersionTLS10,
3400 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003401 Bugs: ProtocolBugs{
3402 ExpectRecordSplitting: true,
3403 },
David Benjamina1ce8562017-07-01 11:46:57 -04003404 },
3405 messageLen: -1, // read until EOF
3406 flags: []string{
3407 "-async",
3408 "-write-different-record-sizes",
3409 "-cbc-record-splitting",
3410 "-partial-write",
3411 },
3412 })
3413 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003414}
3415
David Benjamin636293b2014-07-08 17:59:18 -04003416func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003417 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003418 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003419 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3420 cert, err := x509.ParseCertificate(cert.Certificate[0])
3421 if err != nil {
3422 panic(err)
3423 }
3424 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003425 }
Adam Langley2ff79332017-02-28 13:45:39 -08003426 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003427
David Benjamin636293b2014-07-08 17:59:18 -04003428 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003429 testCases = append(testCases, testCase{
3430 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003431 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003432 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003433 MinVersion: ver.version,
3434 MaxVersion: ver.version,
3435 ClientAuth: RequireAnyClientCert,
3436 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003437 },
David Benjamina5022392017-07-10 17:40:39 -04003438 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003439 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003440 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3441 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003442 },
3443 })
3444 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003445 testType: serverTest,
3446 name: ver.name + "-Server-ClientAuth-RSA",
3447 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003448 MinVersion: ver.version,
3449 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003450 Certificates: []Certificate{rsaCertificate},
3451 },
David Benjamina5022392017-07-10 17:40:39 -04003452 tls13Variant: ver.tls13Variant,
3453 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003454 })
David Benjamine098ec22014-08-27 23:13:20 -04003455 if ver.version != VersionSSL30 {
3456 testCases = append(testCases, testCase{
3457 testType: serverTest,
3458 name: ver.name + "-Server-ClientAuth-ECDSA",
3459 config: Config{
3460 MinVersion: ver.version,
3461 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003462 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003463 },
David Benjamina5022392017-07-10 17:40:39 -04003464 tls13Variant: ver.tls13Variant,
3465 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003466 })
3467 testCases = append(testCases, testCase{
3468 testType: clientTest,
3469 name: ver.name + "-Client-ClientAuth-ECDSA",
3470 config: Config{
3471 MinVersion: ver.version,
3472 MaxVersion: ver.version,
3473 ClientAuth: RequireAnyClientCert,
3474 ClientCAs: certPool,
3475 },
David Benjamina5022392017-07-10 17:40:39 -04003476 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003477 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003478 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3479 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003480 },
3481 })
3482 }
Adam Langley37646832016-08-01 16:16:46 -07003483
3484 testCases = append(testCases, testCase{
3485 name: "NoClientCertificate-" + ver.name,
3486 config: Config{
3487 MinVersion: ver.version,
3488 MaxVersion: ver.version,
3489 ClientAuth: RequireAnyClientCert,
3490 },
David Benjamina5022392017-07-10 17:40:39 -04003491 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003492 shouldFail: true,
3493 expectedLocalError: "client didn't provide a certificate",
3494 })
3495
3496 testCases = append(testCases, testCase{
3497 // Even if not configured to expect a certificate, OpenSSL will
3498 // return X509_V_OK as the verify_result.
3499 testType: serverTest,
3500 name: "NoClientCertificateRequested-Server-" + ver.name,
3501 config: Config{
3502 MinVersion: ver.version,
3503 MaxVersion: ver.version,
3504 },
David Benjamina5022392017-07-10 17:40:39 -04003505 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003506 flags: []string{
3507 "-expect-verify-result",
3508 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003509 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003510 })
3511
3512 testCases = append(testCases, testCase{
3513 // If a client certificate is not provided, OpenSSL will still
3514 // return X509_V_OK as the verify_result.
3515 testType: serverTest,
3516 name: "NoClientCertificate-Server-" + ver.name,
3517 config: Config{
3518 MinVersion: ver.version,
3519 MaxVersion: ver.version,
3520 },
David Benjamina5022392017-07-10 17:40:39 -04003521 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003522 flags: []string{
3523 "-expect-verify-result",
3524 "-verify-peer",
3525 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003526 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003527 })
3528
David Benjamin1db9e1b2016-10-07 20:51:43 -04003529 certificateRequired := "remote error: certificate required"
3530 if ver.version < VersionTLS13 {
3531 // Prior to TLS 1.3, the generic handshake_failure alert
3532 // was used.
3533 certificateRequired = "remote error: handshake failure"
3534 }
Adam Langley37646832016-08-01 16:16:46 -07003535 testCases = append(testCases, testCase{
3536 testType: serverTest,
3537 name: "RequireAnyClientCertificate-" + ver.name,
3538 config: Config{
3539 MinVersion: ver.version,
3540 MaxVersion: ver.version,
3541 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003542 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003543 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003544 shouldFail: true,
3545 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3546 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003547 })
3548
3549 if ver.version != VersionSSL30 {
3550 testCases = append(testCases, testCase{
3551 testType: serverTest,
3552 name: "SkipClientCertificate-" + ver.name,
3553 config: Config{
3554 MinVersion: ver.version,
3555 MaxVersion: ver.version,
3556 Bugs: ProtocolBugs{
3557 SkipClientCertificate: true,
3558 },
3559 },
3560 // Setting SSL_VERIFY_PEER allows anonymous clients.
3561 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003562 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003563 shouldFail: true,
3564 expectedError: ":UNEXPECTED_MESSAGE:",
3565 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003566
3567 testCases = append(testCases, testCase{
3568 testType: serverTest,
3569 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3570 config: Config{
3571 MinVersion: ver.version,
3572 MaxVersion: ver.version,
3573 },
3574 flags: []string{
3575 "-enable-channel-id",
3576 "-verify-peer-if-no-obc",
3577 },
David Benjamina5022392017-07-10 17:40:39 -04003578 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003579 shouldFail: true,
3580 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3581 expectedLocalError: certificateRequired,
3582 })
3583
3584 testCases = append(testCases, testCase{
3585 testType: serverTest,
3586 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3587 config: Config{
3588 MinVersion: ver.version,
3589 MaxVersion: ver.version,
3590 ChannelID: channelIDKey,
3591 },
3592 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003593 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003594 flags: []string{
3595 "-enable-channel-id",
3596 "-verify-peer-if-no-obc",
3597 },
3598 })
Adam Langley37646832016-08-01 16:16:46 -07003599 }
Adam Langley2ff79332017-02-28 13:45:39 -08003600
3601 testCases = append(testCases, testCase{
3602 testType: serverTest,
3603 name: ver.name + "-Server-CertReq-CA-List",
3604 config: Config{
3605 MinVersion: ver.version,
3606 MaxVersion: ver.version,
3607 Certificates: []Certificate{rsaCertificate},
3608 Bugs: ProtocolBugs{
3609 ExpectCertificateReqNames: caNames,
3610 },
3611 },
David Benjamina5022392017-07-10 17:40:39 -04003612 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003613 flags: []string{
3614 "-require-any-client-certificate",
3615 "-use-client-ca-list", encodeDERValues(caNames),
3616 },
3617 })
3618
3619 testCases = append(testCases, testCase{
3620 testType: clientTest,
3621 name: ver.name + "-Client-CertReq-CA-List",
3622 config: Config{
3623 MinVersion: ver.version,
3624 MaxVersion: ver.version,
3625 Certificates: []Certificate{rsaCertificate},
3626 ClientAuth: RequireAnyClientCert,
3627 ClientCAs: certPool,
3628 },
David Benjamina5022392017-07-10 17:40:39 -04003629 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003630 flags: []string{
3631 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3632 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3633 "-expect-client-ca-list", encodeDERValues(caNames),
3634 },
3635 })
David Benjamin636293b2014-07-08 17:59:18 -04003636 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003637
David Benjaminc032dfa2016-05-12 14:54:57 -04003638 // Client auth is only legal in certificate-based ciphers.
3639 testCases = append(testCases, testCase{
3640 testType: clientTest,
3641 name: "ClientAuth-PSK",
3642 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003643 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003644 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3645 PreSharedKey: []byte("secret"),
3646 ClientAuth: RequireAnyClientCert,
3647 },
3648 flags: []string{
3649 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3650 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3651 "-psk", "secret",
3652 },
3653 shouldFail: true,
3654 expectedError: ":UNEXPECTED_MESSAGE:",
3655 })
3656 testCases = append(testCases, testCase{
3657 testType: clientTest,
3658 name: "ClientAuth-ECDHE_PSK",
3659 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003660 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003661 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3662 PreSharedKey: []byte("secret"),
3663 ClientAuth: RequireAnyClientCert,
3664 },
3665 flags: []string{
3666 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3667 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3668 "-psk", "secret",
3669 },
3670 shouldFail: true,
3671 expectedError: ":UNEXPECTED_MESSAGE:",
3672 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003673
3674 // Regression test for a bug where the client CA list, if explicitly
3675 // set to NULL, was mis-encoded.
3676 testCases = append(testCases, testCase{
3677 testType: serverTest,
3678 name: "Null-Client-CA-List",
3679 config: Config{
3680 MaxVersion: VersionTLS12,
3681 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003682 Bugs: ProtocolBugs{
3683 ExpectCertificateReqNames: [][]byte{},
3684 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003685 },
3686 flags: []string{
3687 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003688 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003689 },
3690 })
David Benjamin636293b2014-07-08 17:59:18 -04003691}
3692
Adam Langley75712922014-10-10 16:23:43 -07003693func addExtendedMasterSecretTests() {
3694 const expectEMSFlag = "-expect-extended-master-secret"
3695
3696 for _, with := range []bool{false, true} {
3697 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003698 if with {
3699 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003700 }
3701
3702 for _, isClient := range []bool{false, true} {
3703 suffix := "-Server"
3704 testType := serverTest
3705 if isClient {
3706 suffix = "-Client"
3707 testType = clientTest
3708 }
3709
3710 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003711 // In TLS 1.3, the extension is irrelevant and
3712 // always reports as enabled.
3713 var flags []string
3714 if with || ver.version >= VersionTLS13 {
3715 flags = []string{expectEMSFlag}
3716 }
3717
Adam Langley75712922014-10-10 16:23:43 -07003718 test := testCase{
3719 testType: testType,
3720 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3721 config: Config{
3722 MinVersion: ver.version,
3723 MaxVersion: ver.version,
3724 Bugs: ProtocolBugs{
3725 NoExtendedMasterSecret: !with,
3726 RequireExtendedMasterSecret: with,
3727 },
3728 },
David Benjamina5022392017-07-10 17:40:39 -04003729 tls13Variant: ver.tls13Variant,
3730 flags: flags,
3731 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003732 }
3733 if test.shouldFail {
3734 test.expectedLocalError = "extended master secret required but not supported by peer"
3735 }
3736 testCases = append(testCases, test)
3737 }
3738 }
3739 }
3740
Adam Langleyba5934b2015-06-02 10:50:35 -07003741 for _, isClient := range []bool{false, true} {
3742 for _, supportedInFirstConnection := range []bool{false, true} {
3743 for _, supportedInResumeConnection := range []bool{false, true} {
3744 boolToWord := func(b bool) string {
3745 if b {
3746 return "Yes"
3747 }
3748 return "No"
3749 }
3750 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3751 if isClient {
3752 suffix += "Client"
3753 } else {
3754 suffix += "Server"
3755 }
3756
3757 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003758 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003759 Bugs: ProtocolBugs{
3760 RequireExtendedMasterSecret: true,
3761 },
3762 }
3763
3764 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003766 Bugs: ProtocolBugs{
3767 NoExtendedMasterSecret: true,
3768 },
3769 }
3770
3771 test := testCase{
3772 name: "ExtendedMasterSecret-" + suffix,
3773 resumeSession: true,
3774 }
3775
3776 if !isClient {
3777 test.testType = serverTest
3778 }
3779
3780 if supportedInFirstConnection {
3781 test.config = supportedConfig
3782 } else {
3783 test.config = noSupportConfig
3784 }
3785
3786 if supportedInResumeConnection {
3787 test.resumeConfig = &supportedConfig
3788 } else {
3789 test.resumeConfig = &noSupportConfig
3790 }
3791
3792 switch suffix {
3793 case "YesToYes-Client", "YesToYes-Server":
3794 // When a session is resumed, it should
3795 // still be aware that its master
3796 // secret was generated via EMS and
3797 // thus it's safe to use tls-unique.
3798 test.flags = []string{expectEMSFlag}
3799 case "NoToYes-Server":
3800 // If an original connection did not
3801 // contain EMS, but a resumption
3802 // handshake does, then a server should
3803 // not resume the session.
3804 test.expectResumeRejected = true
3805 case "YesToNo-Server":
3806 // Resuming an EMS session without the
3807 // EMS extension should cause the
3808 // server to abort the connection.
3809 test.shouldFail = true
3810 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3811 case "NoToYes-Client":
3812 // A client should abort a connection
3813 // where the server resumed a non-EMS
3814 // session but echoed the EMS
3815 // extension.
3816 test.shouldFail = true
3817 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3818 case "YesToNo-Client":
3819 // A client should abort a connection
3820 // where the server didn't echo EMS
3821 // when the session used it.
3822 test.shouldFail = true
3823 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3824 }
3825
3826 testCases = append(testCases, test)
3827 }
3828 }
3829 }
David Benjamin163c9562016-08-29 23:14:17 -04003830
3831 // Switching EMS on renegotiation is forbidden.
3832 testCases = append(testCases, testCase{
3833 name: "ExtendedMasterSecret-Renego-NoEMS",
3834 config: Config{
3835 MaxVersion: VersionTLS12,
3836 Bugs: ProtocolBugs{
3837 NoExtendedMasterSecret: true,
3838 NoExtendedMasterSecretOnRenegotiation: true,
3839 },
3840 },
3841 renegotiate: 1,
3842 flags: []string{
3843 "-renegotiate-freely",
3844 "-expect-total-renegotiations", "1",
3845 },
3846 })
3847
3848 testCases = append(testCases, testCase{
3849 name: "ExtendedMasterSecret-Renego-Upgrade",
3850 config: Config{
3851 MaxVersion: VersionTLS12,
3852 Bugs: ProtocolBugs{
3853 NoExtendedMasterSecret: true,
3854 },
3855 },
3856 renegotiate: 1,
3857 flags: []string{
3858 "-renegotiate-freely",
3859 "-expect-total-renegotiations", "1",
3860 },
3861 shouldFail: true,
3862 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3863 })
3864
3865 testCases = append(testCases, testCase{
3866 name: "ExtendedMasterSecret-Renego-Downgrade",
3867 config: Config{
3868 MaxVersion: VersionTLS12,
3869 Bugs: ProtocolBugs{
3870 NoExtendedMasterSecretOnRenegotiation: true,
3871 },
3872 },
3873 renegotiate: 1,
3874 flags: []string{
3875 "-renegotiate-freely",
3876 "-expect-total-renegotiations", "1",
3877 },
3878 shouldFail: true,
3879 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3880 })
Adam Langley75712922014-10-10 16:23:43 -07003881}
3882
David Benjamin582ba042016-07-07 12:33:25 -07003883type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003884 protocol protocol
3885 async bool
3886 splitHandshake bool
3887 packHandshakeFlight bool
3888 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003889}
3890
David Benjamin43ec06f2014-08-05 02:28:57 -04003891// Adds tests that try to cover the range of the handshake state machine, under
3892// various conditions. Some of these are redundant with other tests, but they
3893// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003894func addAllStateMachineCoverageTests() {
3895 for _, async := range []bool{false, true} {
3896 for _, protocol := range []protocol{tls, dtls} {
3897 addStateMachineCoverageTests(stateMachineTestConfig{
3898 protocol: protocol,
3899 async: async,
3900 })
3901 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003902 protocol: protocol,
3903 async: async,
3904 implicitHandshake: true,
3905 })
3906 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003907 protocol: protocol,
3908 async: async,
3909 splitHandshake: true,
3910 })
3911 if protocol == tls {
3912 addStateMachineCoverageTests(stateMachineTestConfig{
3913 protocol: protocol,
3914 async: async,
3915 packHandshakeFlight: true,
3916 })
3917 }
3918 }
3919 }
3920}
3921
3922func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003923 var tests []testCase
3924
3925 // Basic handshake, with resumption. Client and server,
3926 // session ID and session ticket.
3927 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003928 name: "Basic-Client",
3929 config: Config{
3930 MaxVersion: VersionTLS12,
3931 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003932 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003933 // Ensure session tickets are used, not session IDs.
3934 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003935 })
3936 tests = append(tests, testCase{
3937 name: "Basic-Client-RenewTicket",
3938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003939 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003940 Bugs: ProtocolBugs{
3941 RenewTicketOnResume: true,
3942 },
3943 },
David Benjamin46662482016-08-17 00:51:00 -04003944 flags: []string{"-expect-ticket-renewal"},
3945 resumeSession: true,
3946 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003947 })
3948 tests = append(tests, testCase{
3949 name: "Basic-Client-NoTicket",
3950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003951 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003952 SessionTicketsDisabled: true,
3953 },
3954 resumeSession: true,
3955 })
3956 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003957 testType: serverTest,
3958 name: "Basic-Server",
3959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003960 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003961 Bugs: ProtocolBugs{
3962 RequireSessionTickets: true,
3963 },
3964 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003965 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003966 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003967 })
3968 tests = append(tests, testCase{
3969 testType: serverTest,
3970 name: "Basic-Server-NoTickets",
3971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003973 SessionTicketsDisabled: true,
3974 },
3975 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003976 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 })
3978 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003980 name: "Basic-Server-EarlyCallback",
3981 config: Config{
3982 MaxVersion: VersionTLS12,
3983 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003984 flags: []string{"-use-early-callback"},
3985 resumeSession: true,
3986 })
3987
Steven Valdez143e8b32016-07-11 13:19:03 -04003988 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003989 if config.protocol == tls {
3990 tests = append(tests, testCase{
3991 name: "TLS13-1RTT-Client",
3992 config: Config{
3993 MaxVersion: VersionTLS13,
3994 MinVersion: VersionTLS13,
3995 },
David Benjamin46662482016-08-17 00:51:00 -04003996 resumeSession: true,
3997 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003998 })
3999
4000 tests = append(tests, testCase{
4001 testType: serverTest,
4002 name: "TLS13-1RTT-Server",
4003 config: Config{
4004 MaxVersion: VersionTLS13,
4005 MinVersion: VersionTLS13,
4006 },
David Benjamin46662482016-08-17 00:51:00 -04004007 resumeSession: true,
4008 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004009 // TLS 1.3 uses tickets, so the session should not be
4010 // cached statefully.
4011 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004012 })
4013
4014 tests = append(tests, testCase{
4015 name: "TLS13-HelloRetryRequest-Client",
4016 config: Config{
4017 MaxVersion: VersionTLS13,
4018 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004019 // P-384 requires a HelloRetryRequest against BoringSSL's default
4020 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004021 CurvePreferences: []CurveID{CurveP384},
4022 Bugs: ProtocolBugs{
4023 ExpectMissingKeyShare: true,
4024 },
4025 },
4026 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4027 resumeSession: true,
4028 })
4029
4030 tests = append(tests, testCase{
4031 testType: serverTest,
4032 name: "TLS13-HelloRetryRequest-Server",
4033 config: Config{
4034 MaxVersion: VersionTLS13,
4035 MinVersion: VersionTLS13,
4036 // Require a HelloRetryRequest for every curve.
4037 DefaultCurves: []CurveID{},
4038 },
4039 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4040 resumeSession: true,
4041 })
Steven Valdez2d850622017-01-11 11:34:52 -05004042
Steven Valdez2d850622017-01-11 11:34:52 -05004043 tests = append(tests, testCase{
4044 testType: clientTest,
4045 name: "TLS13-EarlyData-Client",
4046 config: Config{
4047 MaxVersion: VersionTLS13,
4048 MinVersion: VersionTLS13,
4049 MaxEarlyDataSize: 16384,
4050 },
Steven Valdeze831a812017-03-09 14:56:07 -05004051 resumeConfig: &Config{
4052 MaxVersion: VersionTLS13,
4053 MinVersion: VersionTLS13,
4054 MaxEarlyDataSize: 16384,
4055 Bugs: ProtocolBugs{
4056 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4057 },
4058 },
Steven Valdez2d850622017-01-11 11:34:52 -05004059 resumeSession: true,
4060 flags: []string{
4061 "-enable-early-data",
4062 "-expect-early-data-info",
4063 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004064 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004065 },
4066 })
4067
4068 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004069 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004070 name: "TLS13Experiment-EarlyData-Client",
4071 config: Config{
4072 MaxVersion: VersionTLS13,
4073 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004074 MaxEarlyDataSize: 16384,
4075 },
4076 resumeConfig: &Config{
4077 MaxVersion: VersionTLS13,
4078 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004079 MaxEarlyDataSize: 16384,
4080 Bugs: ProtocolBugs{
4081 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4082 },
4083 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004084 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004085 resumeSession: true,
4086 flags: []string{
4087 "-enable-early-data",
4088 "-expect-early-data-info",
4089 "-expect-accept-early-data",
4090 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004091 },
4092 })
4093
4094 tests = append(tests, testCase{
4095 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004096 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4097 config: Config{
4098 MaxVersion: VersionTLS13,
4099 MinVersion: VersionTLS13,
4100 TLS13Variant: TLS13RecordTypeExperiment,
4101 MaxEarlyDataSize: 16384,
4102 },
4103 resumeConfig: &Config{
4104 MaxVersion: VersionTLS13,
4105 MinVersion: VersionTLS13,
4106 TLS13Variant: TLS13RecordTypeExperiment,
4107 MaxEarlyDataSize: 16384,
4108 Bugs: ProtocolBugs{
4109 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4110 },
4111 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004112 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004113 resumeSession: true,
4114 flags: []string{
4115 "-enable-early-data",
4116 "-expect-early-data-info",
4117 "-expect-accept-early-data",
4118 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004119 },
4120 })
4121
4122 tests = append(tests, testCase{
4123 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004124 name: "TLS13-EarlyData-TooMuchData-Client",
4125 config: Config{
4126 MaxVersion: VersionTLS13,
4127 MinVersion: VersionTLS13,
4128 MaxEarlyDataSize: 2,
4129 },
4130 resumeConfig: &Config{
4131 MaxVersion: VersionTLS13,
4132 MinVersion: VersionTLS13,
4133 MaxEarlyDataSize: 2,
4134 Bugs: ProtocolBugs{
4135 ExpectEarlyData: [][]byte{{'h', 'e'}},
4136 },
4137 },
4138 resumeShimPrefix: "llo",
4139 resumeSession: true,
4140 flags: []string{
4141 "-enable-early-data",
4142 "-expect-early-data-info",
4143 "-expect-accept-early-data",
4144 "-on-resume-shim-writes-first",
4145 },
4146 })
4147
4148 // Unfinished writes can only be tested when operations are async. EarlyData
4149 // can't be tested as part of an ImplicitHandshake in this case since
4150 // otherwise the early data will be sent as normal data.
4151 if config.async && !config.implicitHandshake {
4152 tests = append(tests, testCase{
4153 testType: clientTest,
4154 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4155 config: Config{
4156 MaxVersion: VersionTLS13,
4157 MinVersion: VersionTLS13,
4158 MaxEarlyDataSize: 16384,
4159 },
4160 resumeConfig: &Config{
4161 MaxVersion: VersionTLS13,
4162 MinVersion: VersionTLS13,
4163 MaxEarlyDataSize: 16384,
4164 Bugs: ProtocolBugs{
4165 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4166 },
4167 },
4168 resumeSession: true,
4169 flags: []string{
4170 "-enable-early-data",
4171 "-expect-early-data-info",
4172 "-expect-accept-early-data",
4173 "-on-resume-read-with-unfinished-write",
4174 "-on-resume-shim-writes-first",
4175 },
4176 })
4177
4178 // Rejected unfinished writes are discarded (from the
4179 // perspective of the calling application) on 0-RTT
4180 // reject.
4181 tests = append(tests, testCase{
4182 testType: clientTest,
4183 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4184 config: Config{
4185 MaxVersion: VersionTLS13,
4186 MinVersion: VersionTLS13,
4187 MaxEarlyDataSize: 16384,
4188 },
4189 resumeConfig: &Config{
4190 MaxVersion: VersionTLS13,
4191 MinVersion: VersionTLS13,
4192 MaxEarlyDataSize: 16384,
4193 Bugs: ProtocolBugs{
4194 AlwaysRejectEarlyData: true,
4195 },
4196 },
4197 resumeSession: true,
4198 flags: []string{
4199 "-enable-early-data",
4200 "-expect-early-data-info",
4201 "-expect-reject-early-data",
4202 "-on-resume-read-with-unfinished-write",
4203 "-on-resume-shim-writes-first",
4204 },
4205 })
4206 }
4207
4208 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004209 testType: serverTest,
4210 name: "TLS13-EarlyData-Server",
4211 config: Config{
4212 MaxVersion: VersionTLS13,
4213 MinVersion: VersionTLS13,
4214 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004215 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004216 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004217 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004218 },
4219 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004220 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004221 resumeSession: true,
4222 flags: []string{
4223 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004224 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004225 },
4226 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004227
4228 tests = append(tests, testCase{
4229 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004230 name: "TLS13Experiment-EarlyData-Server",
4231 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004232 MaxVersion: VersionTLS13,
4233 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004234 Bugs: ProtocolBugs{
4235 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4236 ExpectEarlyDataAccepted: true,
4237 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4238 },
4239 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004240 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004241 messageCount: 2,
4242 resumeSession: true,
4243 flags: []string{
4244 "-enable-early-data",
4245 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004246 },
4247 })
4248
4249 tests = append(tests, testCase{
4250 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004251 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4252 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004253 MaxVersion: VersionTLS13,
4254 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004255 Bugs: ProtocolBugs{
4256 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4257 ExpectEarlyDataAccepted: true,
4258 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4259 },
4260 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004261 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004262 messageCount: 2,
4263 resumeSession: true,
4264 flags: []string{
4265 "-enable-early-data",
4266 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004267 },
4268 })
4269
4270 tests = append(tests, testCase{
4271 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004272 name: "TLS13-MaxEarlyData-Server",
4273 config: Config{
4274 MaxVersion: VersionTLS13,
4275 MinVersion: VersionTLS13,
4276 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004277 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004278 ExpectEarlyDataAccepted: true,
4279 },
4280 },
4281 messageCount: 2,
4282 resumeSession: true,
4283 flags: []string{
4284 "-enable-early-data",
4285 "-expect-accept-early-data",
4286 },
4287 shouldFail: true,
4288 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4289 })
David Benjamine73c7f42016-08-17 00:29:33 -04004290 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004291
David Benjamin760b1dd2015-05-15 23:33:48 -04004292 // TLS client auth.
4293 tests = append(tests, testCase{
4294 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004295 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004297 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004298 ClientAuth: RequestClientCert,
4299 },
4300 })
4301 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004302 testType: serverTest,
4303 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004304 config: Config{
4305 MaxVersion: VersionTLS12,
4306 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004307 // Setting SSL_VERIFY_PEER allows anonymous clients.
4308 flags: []string{"-verify-peer"},
4309 })
David Benjamin582ba042016-07-07 12:33:25 -07004310 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004311 tests = append(tests, testCase{
4312 testType: clientTest,
4313 name: "ClientAuth-NoCertificate-Client-SSL3",
4314 config: Config{
4315 MaxVersion: VersionSSL30,
4316 ClientAuth: RequestClientCert,
4317 },
4318 })
4319 tests = append(tests, testCase{
4320 testType: serverTest,
4321 name: "ClientAuth-NoCertificate-Server-SSL3",
4322 config: Config{
4323 MaxVersion: VersionSSL30,
4324 },
4325 // Setting SSL_VERIFY_PEER allows anonymous clients.
4326 flags: []string{"-verify-peer"},
4327 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004328 tests = append(tests, testCase{
4329 testType: clientTest,
4330 name: "ClientAuth-NoCertificate-Client-TLS13",
4331 config: Config{
4332 MaxVersion: VersionTLS13,
4333 ClientAuth: RequestClientCert,
4334 },
4335 })
4336 tests = append(tests, testCase{
4337 testType: serverTest,
4338 name: "ClientAuth-NoCertificate-Server-TLS13",
4339 config: Config{
4340 MaxVersion: VersionTLS13,
4341 },
4342 // Setting SSL_VERIFY_PEER allows anonymous clients.
4343 flags: []string{"-verify-peer"},
4344 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004345 }
4346 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004347 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004348 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004350 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004351 ClientAuth: RequireAnyClientCert,
4352 },
4353 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004354 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4355 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004356 },
4357 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004358 tests = append(tests, testCase{
4359 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004360 name: "ClientAuth-RSA-Client-TLS13",
4361 config: Config{
4362 MaxVersion: VersionTLS13,
4363 ClientAuth: RequireAnyClientCert,
4364 },
4365 flags: []string{
4366 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4367 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4368 },
4369 })
4370 tests = append(tests, testCase{
4371 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004372 name: "ClientAuth-ECDSA-Client",
4373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004374 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004375 ClientAuth: RequireAnyClientCert,
4376 },
4377 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004378 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4379 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004380 },
4381 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004382 tests = append(tests, testCase{
4383 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004384 name: "ClientAuth-ECDSA-Client-TLS13",
4385 config: Config{
4386 MaxVersion: VersionTLS13,
4387 ClientAuth: RequireAnyClientCert,
4388 },
4389 flags: []string{
4390 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4391 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4392 },
4393 })
4394 tests = append(tests, testCase{
4395 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004396 name: "ClientAuth-NoCertificate-OldCallback",
4397 config: Config{
4398 MaxVersion: VersionTLS12,
4399 ClientAuth: RequestClientCert,
4400 },
4401 flags: []string{"-use-old-client-cert-callback"},
4402 })
4403 tests = append(tests, testCase{
4404 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004405 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4406 config: Config{
4407 MaxVersion: VersionTLS13,
4408 ClientAuth: RequestClientCert,
4409 },
4410 flags: []string{"-use-old-client-cert-callback"},
4411 })
4412 tests = append(tests, testCase{
4413 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004414 name: "ClientAuth-OldCallback",
4415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004416 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004417 ClientAuth: RequireAnyClientCert,
4418 },
4419 flags: []string{
4420 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4421 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4422 "-use-old-client-cert-callback",
4423 },
4424 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004425 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004426 testType: clientTest,
4427 name: "ClientAuth-OldCallback-TLS13",
4428 config: Config{
4429 MaxVersion: VersionTLS13,
4430 ClientAuth: RequireAnyClientCert,
4431 },
4432 flags: []string{
4433 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4434 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4435 "-use-old-client-cert-callback",
4436 },
4437 })
4438 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004439 testType: serverTest,
4440 name: "ClientAuth-Server",
4441 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004442 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004443 Certificates: []Certificate{rsaCertificate},
4444 },
4445 flags: []string{"-require-any-client-certificate"},
4446 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004447 tests = append(tests, testCase{
4448 testType: serverTest,
4449 name: "ClientAuth-Server-TLS13",
4450 config: Config{
4451 MaxVersion: VersionTLS13,
4452 Certificates: []Certificate{rsaCertificate},
4453 },
4454 flags: []string{"-require-any-client-certificate"},
4455 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004456
David Benjamin4c3ddf72016-06-29 18:13:53 -04004457 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004458 tests = append(tests, testCase{
4459 testType: serverTest,
4460 name: "Basic-Server-RSA",
4461 config: Config{
4462 MaxVersion: VersionTLS12,
4463 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4464 },
4465 flags: []string{
4466 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4467 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4468 },
4469 })
4470 tests = append(tests, testCase{
4471 testType: serverTest,
4472 name: "Basic-Server-ECDHE-RSA",
4473 config: Config{
4474 MaxVersion: VersionTLS12,
4475 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4476 },
4477 flags: []string{
4478 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4479 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4480 },
4481 })
4482 tests = append(tests, testCase{
4483 testType: serverTest,
4484 name: "Basic-Server-ECDHE-ECDSA",
4485 config: Config{
4486 MaxVersion: VersionTLS12,
4487 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4488 },
4489 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004490 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4491 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004492 },
4493 })
David Benjamin69522112017-03-28 15:38:29 -05004494 tests = append(tests, testCase{
4495 testType: serverTest,
4496 name: "Basic-Server-Ed25519",
4497 config: Config{
4498 MaxVersion: VersionTLS12,
4499 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4500 },
4501 flags: []string{
4502 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4503 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4504 "-enable-ed25519",
4505 },
4506 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004507
David Benjamin760b1dd2015-05-15 23:33:48 -04004508 // No session ticket support; server doesn't send NewSessionTicket.
4509 tests = append(tests, testCase{
4510 name: "SessionTicketsDisabled-Client",
4511 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004512 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004513 SessionTicketsDisabled: true,
4514 },
4515 })
4516 tests = append(tests, testCase{
4517 testType: serverTest,
4518 name: "SessionTicketsDisabled-Server",
4519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004520 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004521 SessionTicketsDisabled: true,
4522 },
4523 })
4524
4525 // Skip ServerKeyExchange in PSK key exchange if there's no
4526 // identity hint.
4527 tests = append(tests, testCase{
4528 name: "EmptyPSKHint-Client",
4529 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004530 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004531 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4532 PreSharedKey: []byte("secret"),
4533 },
4534 flags: []string{"-psk", "secret"},
4535 })
4536 tests = append(tests, testCase{
4537 testType: serverTest,
4538 name: "EmptyPSKHint-Server",
4539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004540 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004541 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4542 PreSharedKey: []byte("secret"),
4543 },
4544 flags: []string{"-psk", "secret"},
4545 })
4546
David Benjamin4c3ddf72016-06-29 18:13:53 -04004547 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004548 tests = append(tests, testCase{
4549 testType: clientTest,
4550 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004551 config: Config{
4552 MaxVersion: VersionTLS12,
4553 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004554 flags: []string{
4555 "-enable-ocsp-stapling",
4556 "-expect-ocsp-response",
4557 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004558 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004559 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004560 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004561 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004562 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004563 testType: serverTest,
4564 name: "OCSPStapling-Server",
4565 config: Config{
4566 MaxVersion: VersionTLS12,
4567 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004568 expectedOCSPResponse: testOCSPResponse,
4569 flags: []string{
4570 "-ocsp-response",
4571 base64.StdEncoding.EncodeToString(testOCSPResponse),
4572 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004573 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004574 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004575 tests = append(tests, testCase{
4576 testType: clientTest,
4577 name: "OCSPStapling-Client-TLS13",
4578 config: Config{
4579 MaxVersion: VersionTLS13,
4580 },
4581 flags: []string{
4582 "-enable-ocsp-stapling",
4583 "-expect-ocsp-response",
4584 base64.StdEncoding.EncodeToString(testOCSPResponse),
4585 "-verify-peer",
4586 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004587 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004588 })
4589 tests = append(tests, testCase{
4590 testType: serverTest,
4591 name: "OCSPStapling-Server-TLS13",
4592 config: Config{
4593 MaxVersion: VersionTLS13,
4594 },
4595 expectedOCSPResponse: testOCSPResponse,
4596 flags: []string{
4597 "-ocsp-response",
4598 base64.StdEncoding.EncodeToString(testOCSPResponse),
4599 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004600 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004601 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004602
David Benjamin4c3ddf72016-06-29 18:13:53 -04004603 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004604 for _, vers := range tlsVersions {
4605 if config.protocol == dtls && !vers.hasDTLS {
4606 continue
4607 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004608 for _, useCustomCallback := range []bool{false, true} {
4609 for _, testType := range []testType{clientTest, serverTest} {
4610 suffix := "-Client"
4611 if testType == serverTest {
4612 suffix = "-Server"
4613 }
4614 suffix += "-" + vers.name
4615 if useCustomCallback {
4616 suffix += "-CustomCallback"
4617 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004618
David Benjamin3a1dd462017-07-11 16:13:10 -04004619 flags := []string{"-verify-peer"}
4620 if testType == serverTest {
4621 flags = append(flags, "-require-any-client-certificate")
4622 }
4623 if useCustomCallback {
4624 flags = append(flags, "-use-custom-verify-callback")
4625 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004626
David Benjamin3a1dd462017-07-11 16:13:10 -04004627 tests = append(tests, testCase{
4628 testType: testType,
4629 name: "CertificateVerificationSucceed" + suffix,
4630 config: Config{
4631 MaxVersion: vers.version,
4632 Certificates: []Certificate{rsaCertificate},
4633 },
4634 tls13Variant: vers.tls13Variant,
4635 flags: append([]string{"-expect-verify-result"}, flags...),
4636 resumeSession: true,
4637 })
4638 tests = append(tests, testCase{
4639 testType: testType,
4640 name: "CertificateVerificationFail" + suffix,
4641 config: Config{
4642 MaxVersion: vers.version,
4643 Certificates: []Certificate{rsaCertificate},
4644 },
4645 tls13Variant: vers.tls13Variant,
4646 flags: append([]string{"-verify-fail"}, flags...),
4647 shouldFail: true,
4648 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4649 })
4650 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004651 }
4652
4653 // By default, the client is in a soft fail mode where the peer
4654 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004655 tests = append(tests, testCase{
4656 testType: clientTest,
4657 name: "CertificateVerificationSoftFail-" + vers.name,
4658 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004659 MaxVersion: vers.version,
4660 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004661 },
David Benjamina5022392017-07-10 17:40:39 -04004662 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004663 flags: []string{
4664 "-verify-fail",
4665 "-expect-verify-result",
4666 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004667 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004668 })
4669 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004670
David Benjamin1d4f4c02016-07-26 18:03:08 -04004671 tests = append(tests, testCase{
4672 name: "ShimSendAlert",
4673 flags: []string{"-send-alert"},
4674 shimWritesFirst: true,
4675 shouldFail: true,
4676 expectedLocalError: "remote error: decompression failure",
4677 })
4678
David Benjamin582ba042016-07-07 12:33:25 -07004679 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004680 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004681 name: "Renegotiate-Client",
4682 config: Config{
4683 MaxVersion: VersionTLS12,
4684 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004685 renegotiate: 1,
4686 flags: []string{
4687 "-renegotiate-freely",
4688 "-expect-total-renegotiations", "1",
4689 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004690 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004691
David Benjamin47921102016-07-28 11:29:18 -04004692 tests = append(tests, testCase{
4693 name: "SendHalfHelloRequest",
4694 config: Config{
4695 MaxVersion: VersionTLS12,
4696 Bugs: ProtocolBugs{
4697 PackHelloRequestWithFinished: config.packHandshakeFlight,
4698 },
4699 },
4700 sendHalfHelloRequest: true,
4701 flags: []string{"-renegotiate-ignore"},
4702 shouldFail: true,
4703 expectedError: ":UNEXPECTED_RECORD:",
4704 })
4705
David Benjamin760b1dd2015-05-15 23:33:48 -04004706 // NPN on client and server; results in post-handshake message.
4707 tests = append(tests, testCase{
4708 name: "NPN-Client",
4709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004710 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004711 NextProtos: []string{"foo"},
4712 },
4713 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004714 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004715 expectedNextProto: "foo",
4716 expectedNextProtoType: npn,
4717 })
4718 tests = append(tests, testCase{
4719 testType: serverTest,
4720 name: "NPN-Server",
4721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004722 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004723 NextProtos: []string{"bar"},
4724 },
4725 flags: []string{
4726 "-advertise-npn", "\x03foo\x03bar\x03baz",
4727 "-expect-next-proto", "bar",
4728 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004729 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004730 expectedNextProto: "bar",
4731 expectedNextProtoType: npn,
4732 })
4733
4734 // TODO(davidben): Add tests for when False Start doesn't trigger.
4735
4736 // Client does False Start and negotiates NPN.
4737 tests = append(tests, testCase{
4738 name: "FalseStart",
4739 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004740 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004741 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4742 NextProtos: []string{"foo"},
4743 Bugs: ProtocolBugs{
4744 ExpectFalseStart: true,
4745 },
4746 },
4747 flags: []string{
4748 "-false-start",
4749 "-select-next-proto", "foo",
4750 },
4751 shimWritesFirst: true,
4752 resumeSession: true,
4753 })
4754
4755 // Client does False Start and negotiates ALPN.
4756 tests = append(tests, testCase{
4757 name: "FalseStart-ALPN",
4758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004759 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4761 NextProtos: []string{"foo"},
4762 Bugs: ProtocolBugs{
4763 ExpectFalseStart: true,
4764 },
4765 },
4766 flags: []string{
4767 "-false-start",
4768 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004769 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004770 },
4771 shimWritesFirst: true,
4772 resumeSession: true,
4773 })
4774
David Benjamin760b1dd2015-05-15 23:33:48 -04004775 // False Start without session tickets.
4776 tests = append(tests, testCase{
4777 name: "FalseStart-SessionTicketsDisabled",
4778 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004779 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004780 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4781 NextProtos: []string{"foo"},
4782 SessionTicketsDisabled: true,
4783 Bugs: ProtocolBugs{
4784 ExpectFalseStart: true,
4785 },
4786 },
4787 flags: []string{
4788 "-false-start",
4789 "-select-next-proto", "foo",
4790 },
4791 shimWritesFirst: true,
4792 })
4793
4794 // Server parses a V2ClientHello.
4795 tests = append(tests, testCase{
4796 testType: serverTest,
4797 name: "SendV2ClientHello",
4798 config: Config{
4799 // Choose a cipher suite that does not involve
4800 // elliptic curves, so no extensions are
4801 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004802 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004803 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004804 Bugs: ProtocolBugs{
4805 SendV2ClientHello: true,
4806 },
4807 },
David Benjamin78b8b992017-08-01 18:38:41 -04004808 flags: []string{
4809 "-expect-msg-callback",
4810 `read v2clienthello
4811write hs 2
4812write hs 11
4813write hs 14
4814read hs 16
4815read ccs
4816read hs 20
4817write ccs
4818write hs 20
4819read alert 1 0
4820`,
4821 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004822 })
4823
Nick Harper60a85cb2016-09-23 16:25:11 -07004824 // Test Channel ID
4825 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004826 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004827 continue
4828 }
4829 // Client sends a Channel ID.
4830 tests = append(tests, testCase{
4831 name: "ChannelID-Client-" + ver.name,
4832 config: Config{
4833 MaxVersion: ver.version,
4834 RequestChannelID: true,
4835 },
David Benjamina5022392017-07-10 17:40:39 -04004836 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004837 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4838 resumeSession: true,
4839 expectChannelID: true,
4840 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004841
Nick Harper60a85cb2016-09-23 16:25:11 -07004842 // Server accepts a Channel ID.
4843 tests = append(tests, testCase{
4844 testType: serverTest,
4845 name: "ChannelID-Server-" + ver.name,
4846 config: Config{
4847 MaxVersion: ver.version,
4848 ChannelID: channelIDKey,
4849 },
David Benjamina5022392017-07-10 17:40:39 -04004850 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004851 flags: []string{
4852 "-expect-channel-id",
4853 base64.StdEncoding.EncodeToString(channelIDBytes),
4854 },
4855 resumeSession: true,
4856 expectChannelID: true,
4857 })
4858
4859 tests = append(tests, testCase{
4860 testType: serverTest,
4861 name: "InvalidChannelIDSignature-" + ver.name,
4862 config: Config{
4863 MaxVersion: ver.version,
4864 ChannelID: channelIDKey,
4865 Bugs: ProtocolBugs{
4866 InvalidChannelIDSignature: true,
4867 },
4868 },
David Benjamina5022392017-07-10 17:40:39 -04004869 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004870 flags: []string{"-enable-channel-id"},
4871 shouldFail: true,
4872 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4873 })
David Benjamin634f4752017-07-01 11:08:41 -04004874
4875 if ver.version < VersionTLS13 {
4876 // Channel ID requires ECDHE ciphers.
4877 tests = append(tests, testCase{
4878 testType: serverTest,
4879 name: "ChannelID-NoECDHE-" + ver.name,
4880 config: Config{
4881 MaxVersion: ver.version,
4882 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4883 ChannelID: channelIDKey,
4884 },
4885 expectChannelID: false,
4886 flags: []string{"-enable-channel-id"},
4887 })
4888
4889 // Sanity-check setting expectChannelID false works.
4890 tests = append(tests, testCase{
4891 testType: serverTest,
4892 name: "ChannelID-ECDHE-" + ver.name,
4893 config: Config{
4894 MaxVersion: ver.version,
4895 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4896 ChannelID: channelIDKey,
4897 },
4898 expectChannelID: false,
4899 flags: []string{"-enable-channel-id"},
4900 shouldFail: true,
4901 expectedLocalError: "channel ID unexpectedly negotiated",
4902 })
4903 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004904 }
David Benjamin30789da2015-08-29 22:56:45 -04004905
David Benjaminf8fcdf32016-06-08 15:56:13 -04004906 // Channel ID and NPN at the same time, to ensure their relative
4907 // ordering is correct.
4908 tests = append(tests, testCase{
4909 name: "ChannelID-NPN-Client",
4910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004911 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004912 RequestChannelID: true,
4913 NextProtos: []string{"foo"},
4914 },
4915 flags: []string{
4916 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4917 "-select-next-proto", "foo",
4918 },
4919 resumeSession: true,
4920 expectChannelID: true,
4921 expectedNextProto: "foo",
4922 expectedNextProtoType: npn,
4923 })
4924 tests = append(tests, testCase{
4925 testType: serverTest,
4926 name: "ChannelID-NPN-Server",
4927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004928 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004929 ChannelID: channelIDKey,
4930 NextProtos: []string{"bar"},
4931 },
4932 flags: []string{
4933 "-expect-channel-id",
4934 base64.StdEncoding.EncodeToString(channelIDBytes),
4935 "-advertise-npn", "\x03foo\x03bar\x03baz",
4936 "-expect-next-proto", "bar",
4937 },
4938 resumeSession: true,
4939 expectChannelID: true,
4940 expectedNextProto: "bar",
4941 expectedNextProtoType: npn,
4942 })
4943
David Benjamin30789da2015-08-29 22:56:45 -04004944 // Bidirectional shutdown with the runner initiating.
4945 tests = append(tests, testCase{
4946 name: "Shutdown-Runner",
4947 config: Config{
4948 Bugs: ProtocolBugs{
4949 ExpectCloseNotify: true,
4950 },
4951 },
4952 flags: []string{"-check-close-notify"},
4953 })
4954
David Benjamine3843d42017-03-25 18:00:56 -05004955 if !config.implicitHandshake {
4956 // Bidirectional shutdown with the shim initiating. The runner,
4957 // in the meantime, sends garbage before the close_notify which
4958 // the shim must ignore. This test is disabled under implicit
4959 // handshake tests because the shim never reads or writes.
4960 tests = append(tests, testCase{
4961 name: "Shutdown-Shim",
4962 config: Config{
4963 MaxVersion: VersionTLS12,
4964 Bugs: ProtocolBugs{
4965 ExpectCloseNotify: true,
4966 },
David Benjamin30789da2015-08-29 22:56:45 -04004967 },
David Benjamine3843d42017-03-25 18:00:56 -05004968 shimShutsDown: true,
4969 sendEmptyRecords: 1,
4970 sendWarningAlerts: 1,
4971 flags: []string{"-check-close-notify"},
4972 })
4973 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004974 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004975 // TODO(davidben): DTLS 1.3 will want a similar thing for
4976 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004977 tests = append(tests, testCase{
4978 name: "SkipHelloVerifyRequest",
4979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004980 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004981 Bugs: ProtocolBugs{
4982 SkipHelloVerifyRequest: true,
4983 },
4984 },
4985 })
4986 }
4987
David Benjamin760b1dd2015-05-15 23:33:48 -04004988 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004989 test.protocol = config.protocol
4990 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004991 test.name += "-DTLS"
4992 }
David Benjamin582ba042016-07-07 12:33:25 -07004993 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004994 test.name += "-Async"
4995 test.flags = append(test.flags, "-async")
4996 } else {
4997 test.name += "-Sync"
4998 }
David Benjamin582ba042016-07-07 12:33:25 -07004999 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005000 test.name += "-SplitHandshakeRecords"
5001 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005002 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005003 test.config.Bugs.MaxPacketLength = 256
5004 test.flags = append(test.flags, "-mtu", "256")
5005 }
5006 }
David Benjamin582ba042016-07-07 12:33:25 -07005007 if config.packHandshakeFlight {
5008 test.name += "-PackHandshakeFlight"
5009 test.config.Bugs.PackHandshakeFlight = true
5010 }
David Benjamine3843d42017-03-25 18:00:56 -05005011 if config.implicitHandshake {
5012 test.name += "-ImplicitHandshake"
5013 test.flags = append(test.flags, "-implicit-handshake")
5014 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005015 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005016 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005017}
5018
Adam Langley524e7172015-02-20 16:04:00 -08005019func addDDoSCallbackTests() {
5020 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005021 for _, resume := range []bool{false, true} {
5022 suffix := "Resume"
5023 if resume {
5024 suffix = "No" + suffix
5025 }
5026
5027 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005028 testType: serverTest,
5029 name: "Server-DDoS-OK-" + suffix,
5030 config: Config{
5031 MaxVersion: VersionTLS12,
5032 },
Adam Langley524e7172015-02-20 16:04:00 -08005033 flags: []string{"-install-ddos-callback"},
5034 resumeSession: resume,
5035 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5039 config: Config{
5040 MaxVersion: VersionTLS13,
5041 },
5042 flags: []string{"-install-ddos-callback"},
5043 resumeSession: resume,
5044 })
Adam Langley524e7172015-02-20 16:04:00 -08005045
5046 failFlag := "-fail-ddos-callback"
5047 if resume {
5048 failFlag = "-fail-second-ddos-callback"
5049 }
5050 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005051 testType: serverTest,
5052 name: "Server-DDoS-Reject-" + suffix,
5053 config: Config{
5054 MaxVersion: VersionTLS12,
5055 },
David Benjamin2c66e072016-09-16 15:58:00 -04005056 flags: []string{"-install-ddos-callback", failFlag},
5057 resumeSession: resume,
5058 shouldFail: true,
5059 expectedError: ":CONNECTION_REJECTED:",
5060 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005061 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005062 testCases = append(testCases, testCase{
5063 testType: serverTest,
5064 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5065 config: Config{
5066 MaxVersion: VersionTLS13,
5067 },
David Benjamin2c66e072016-09-16 15:58:00 -04005068 flags: []string{"-install-ddos-callback", failFlag},
5069 resumeSession: resume,
5070 shouldFail: true,
5071 expectedError: ":CONNECTION_REJECTED:",
5072 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005073 })
Adam Langley524e7172015-02-20 16:04:00 -08005074 }
5075}
5076
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005077func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005078 for _, protocol := range []protocol{tls, dtls} {
5079 for _, shimVers := range allVersions(protocol) {
5080 // Assemble flags to disable all newer versions on the shim.
5081 var flags []string
5082 for _, vers := range allVersions(protocol) {
5083 if vers.version > shimVers.version {
5084 flags = append(flags, vers.excludeFlag)
5085 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005086 }
Steven Valdez520e1222017-06-13 12:45:25 -04005087
5088 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5089
5090 if shimVers.tls13Variant != 0 {
5091 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5092 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5093 }
5094
5095 // Test configuring the runner's maximum version.
5096 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005097 expectedVersion := shimVers.version
5098 if runnerVers.version < shimVers.version {
5099 expectedVersion = runnerVers.version
5100 }
Steven Valdez520e1222017-06-13 12:45:25 -04005101 // When running and shim have different TLS 1.3 variants enabled,
5102 // shim clients are expected to fall back to TLS 1.2, while shim
5103 // servers support both variants when enabled when the experiment is
5104 // enabled.
5105 expectedServerVersion := expectedVersion
5106 expectedClientVersion := expectedVersion
5107 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5108 expectedClientVersion = VersionTLS12
5109 expectedServerVersion = VersionTLS12
5110 if shimVers.tls13Variant != TLS13Default {
5111 expectedServerVersion = VersionTLS13
5112 }
5113 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005114
David Benjamin8b8c0062014-11-23 02:47:52 -05005115 suffix := shimVers.name + "-" + runnerVers.name
5116 if protocol == dtls {
5117 suffix += "-DTLS"
5118 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005119
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005120 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005121 clientVers := shimVers.version
5122 if clientVers > VersionTLS10 {
5123 clientVers = VersionTLS10
5124 }
Steven Valdez520e1222017-06-13 12:45:25 -04005125 clientVers = recordVersionToWire(clientVers, protocol)
5126 serverVers := expectedServerVersion
5127 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005128 serverVers = VersionTLS10
5129 }
Steven Valdez520e1222017-06-13 12:45:25 -04005130 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005131
David Benjamin8b8c0062014-11-23 02:47:52 -05005132 testCases = append(testCases, testCase{
5133 protocol: protocol,
5134 testType: clientTest,
5135 name: "VersionNegotiation-Client-" + suffix,
5136 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005137 MaxVersion: runnerVers.version,
5138 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005139 Bugs: ProtocolBugs{
5140 ExpectInitialRecordVersion: clientVers,
5141 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005142 },
5143 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005144 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005145 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005146 testCases = append(testCases, testCase{
5147 protocol: protocol,
5148 testType: clientTest,
5149 name: "VersionNegotiation-Client2-" + suffix,
5150 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005151 MaxVersion: runnerVers.version,
5152 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005153 Bugs: ProtocolBugs{
5154 ExpectInitialRecordVersion: clientVers,
5155 },
5156 },
Steven Valdez520e1222017-06-13 12:45:25 -04005157 flags: flags2,
5158 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005159 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005160
5161 testCases = append(testCases, testCase{
5162 protocol: protocol,
5163 testType: serverTest,
5164 name: "VersionNegotiation-Server-" + suffix,
5165 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005166 MaxVersion: runnerVers.version,
5167 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005168 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005169 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005170 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005171 },
5172 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005173 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005174 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005175 testCases = append(testCases, testCase{
5176 protocol: protocol,
5177 testType: serverTest,
5178 name: "VersionNegotiation-Server2-" + suffix,
5179 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005180 MaxVersion: runnerVers.version,
5181 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005182 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005183 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005184 },
5185 },
Steven Valdez520e1222017-06-13 12:45:25 -04005186 flags: flags2,
5187 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005188 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005189 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005190 }
5191 }
David Benjamin95c69562016-06-29 18:15:03 -04005192
Steven Valdezfdd10992016-09-15 16:27:05 -04005193 // Test the version extension at all versions.
5194 for _, vers := range tlsVersions {
5195 protocols := []protocol{tls}
5196 if vers.hasDTLS {
5197 protocols = append(protocols, dtls)
5198 }
5199 for _, protocol := range protocols {
5200 suffix := vers.name
5201 if protocol == dtls {
5202 suffix += "-DTLS"
5203 }
5204
Steven Valdezfdd10992016-09-15 16:27:05 -04005205 testCases = append(testCases, testCase{
5206 protocol: protocol,
5207 testType: serverTest,
5208 name: "VersionNegotiationExtension-" + suffix,
5209 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005210 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005211 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005212 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005213 },
5214 },
5215 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005216 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005217 })
5218 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005219 }
5220
5221 // If all versions are unknown, negotiation fails.
5222 testCases = append(testCases, testCase{
5223 testType: serverTest,
5224 name: "NoSupportedVersions",
5225 config: Config{
5226 Bugs: ProtocolBugs{
5227 SendSupportedVersions: []uint16{0x1111},
5228 },
5229 },
5230 shouldFail: true,
5231 expectedError: ":UNSUPPORTED_PROTOCOL:",
5232 })
5233 testCases = append(testCases, testCase{
5234 protocol: dtls,
5235 testType: serverTest,
5236 name: "NoSupportedVersions-DTLS",
5237 config: Config{
5238 Bugs: ProtocolBugs{
5239 SendSupportedVersions: []uint16{0x1111},
5240 },
5241 },
5242 shouldFail: true,
5243 expectedError: ":UNSUPPORTED_PROTOCOL:",
5244 })
5245
5246 testCases = append(testCases, testCase{
5247 testType: serverTest,
5248 name: "ClientHelloVersionTooHigh",
5249 config: Config{
5250 MaxVersion: VersionTLS13,
5251 Bugs: ProtocolBugs{
5252 SendClientVersion: 0x0304,
5253 OmitSupportedVersions: true,
5254 },
5255 },
5256 expectedVersion: VersionTLS12,
5257 })
5258
5259 testCases = append(testCases, testCase{
5260 testType: serverTest,
5261 name: "ConflictingVersionNegotiation",
5262 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005263 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005264 SendClientVersion: VersionTLS12,
5265 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005266 },
5267 },
David Benjaminad75a662016-09-30 15:42:59 -04005268 // The extension takes precedence over the ClientHello version.
5269 expectedVersion: VersionTLS11,
5270 })
5271
5272 testCases = append(testCases, testCase{
5273 testType: serverTest,
5274 name: "ConflictingVersionNegotiation-2",
5275 config: Config{
5276 Bugs: ProtocolBugs{
5277 SendClientVersion: VersionTLS11,
5278 SendSupportedVersions: []uint16{VersionTLS12},
5279 },
5280 },
5281 // The extension takes precedence over the ClientHello version.
5282 expectedVersion: VersionTLS12,
5283 })
5284
5285 testCases = append(testCases, testCase{
5286 testType: serverTest,
5287 name: "RejectFinalTLS13",
5288 config: Config{
5289 Bugs: ProtocolBugs{
5290 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5291 },
5292 },
5293 // We currently implement a draft TLS 1.3 version. Ensure that
5294 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005295 expectedVersion: VersionTLS12,
5296 })
5297
Steven Valdez038da9b2017-07-10 12:57:25 -04005298 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5299 // the ServerHello.
5300 testCases = append(testCases, testCase{
5301 testType: clientTest,
5302 name: "SupportedVersionSelection-TLS12",
5303 config: Config{
5304 MaxVersion: VersionTLS12,
5305 Bugs: ProtocolBugs{
5306 SendServerSupportedExtensionVersion: VersionTLS12,
5307 },
5308 },
5309 shouldFail: true,
5310 expectedError: ":UNEXPECTED_EXTENSION:",
5311 })
5312
5313 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5314 // supported_versions extension in the ServerHello.
5315 testCases = append(testCases, testCase{
5316 testType: clientTest,
5317 name: "SupportedVersionSelection-TLS13",
5318 config: Config{
5319 MaxVersion: VersionTLS13,
5320 Bugs: ProtocolBugs{
5321 SendServerSupportedExtensionVersion: tls13DraftVersion,
5322 },
5323 },
5324 shouldFail: true,
5325 expectedError: ":UNEXPECTED_EXTENSION:",
5326 })
5327
Brian Smithf85d3232016-10-28 10:34:06 -10005328 // Test that the maximum version is selected regardless of the
5329 // client-sent order.
5330 testCases = append(testCases, testCase{
5331 testType: serverTest,
5332 name: "IgnoreClientVersionOrder",
5333 config: Config{
5334 Bugs: ProtocolBugs{
5335 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5336 },
5337 },
5338 expectedVersion: VersionTLS13,
5339 })
5340
David Benjamin95c69562016-06-29 18:15:03 -04005341 // Test for version tolerance.
5342 testCases = append(testCases, testCase{
5343 testType: serverTest,
5344 name: "MinorVersionTolerance",
5345 config: Config{
5346 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005347 SendClientVersion: 0x03ff,
5348 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005349 },
5350 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005351 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005352 })
5353 testCases = append(testCases, testCase{
5354 testType: serverTest,
5355 name: "MajorVersionTolerance",
5356 config: Config{
5357 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005358 SendClientVersion: 0x0400,
5359 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005360 },
5361 },
David Benjaminad75a662016-09-30 15:42:59 -04005362 // TLS 1.3 must be negotiated with the supported_versions
5363 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005364 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005365 })
David Benjaminad75a662016-09-30 15:42:59 -04005366 testCases = append(testCases, testCase{
5367 testType: serverTest,
5368 name: "VersionTolerance-TLS13",
5369 config: Config{
5370 Bugs: ProtocolBugs{
5371 // Although TLS 1.3 does not use
5372 // ClientHello.version, it still tolerates high
5373 // values there.
5374 SendClientVersion: 0x0400,
5375 },
5376 },
5377 expectedVersion: VersionTLS13,
5378 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005379
David Benjamin95c69562016-06-29 18:15:03 -04005380 testCases = append(testCases, testCase{
5381 protocol: dtls,
5382 testType: serverTest,
5383 name: "MinorVersionTolerance-DTLS",
5384 config: Config{
5385 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005386 SendClientVersion: 0xfe00,
5387 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005388 },
5389 },
5390 expectedVersion: VersionTLS12,
5391 })
5392 testCases = append(testCases, testCase{
5393 protocol: dtls,
5394 testType: serverTest,
5395 name: "MajorVersionTolerance-DTLS",
5396 config: Config{
5397 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005398 SendClientVersion: 0xfdff,
5399 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005400 },
5401 },
5402 expectedVersion: VersionTLS12,
5403 })
5404
5405 // Test that versions below 3.0 are rejected.
5406 testCases = append(testCases, testCase{
5407 testType: serverTest,
5408 name: "VersionTooLow",
5409 config: Config{
5410 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005411 SendClientVersion: 0x0200,
5412 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005413 },
5414 },
5415 shouldFail: true,
5416 expectedError: ":UNSUPPORTED_PROTOCOL:",
5417 })
5418 testCases = append(testCases, testCase{
5419 protocol: dtls,
5420 testType: serverTest,
5421 name: "VersionTooLow-DTLS",
5422 config: Config{
5423 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005424 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005425 },
5426 },
5427 shouldFail: true,
5428 expectedError: ":UNSUPPORTED_PROTOCOL:",
5429 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005430
David Benjamin2dc02042016-09-19 19:57:37 -04005431 testCases = append(testCases, testCase{
5432 name: "ServerBogusVersion",
5433 config: Config{
5434 Bugs: ProtocolBugs{
5435 SendServerHelloVersion: 0x1234,
5436 },
5437 },
5438 shouldFail: true,
5439 expectedError: ":UNSUPPORTED_PROTOCOL:",
5440 })
5441
David Benjamin1f61f0d2016-07-10 12:20:35 -04005442 // Test TLS 1.3's downgrade signal.
5443 testCases = append(testCases, testCase{
5444 name: "Downgrade-TLS12-Client",
5445 config: Config{
5446 Bugs: ProtocolBugs{
5447 NegotiateVersion: VersionTLS12,
5448 },
5449 },
David Benjamin592b5322016-09-30 15:15:01 -04005450 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005451 // TODO(davidben): This test should fail once TLS 1.3 is final
5452 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005453 })
5454 testCases = append(testCases, testCase{
5455 testType: serverTest,
5456 name: "Downgrade-TLS12-Server",
5457 config: Config{
5458 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005459 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005460 },
5461 },
David Benjamin592b5322016-09-30 15:15:01 -04005462 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005463 // TODO(davidben): This test should fail once TLS 1.3 is final
5464 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005465 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005466}
5467
David Benjaminaccb4542014-12-12 23:44:33 -05005468func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005469 for _, protocol := range []protocol{tls, dtls} {
5470 for _, shimVers := range allVersions(protocol) {
5471 // Assemble flags to disable all older versions on the shim.
5472 var flags []string
5473 for _, vers := range allVersions(protocol) {
5474 if vers.version < shimVers.version {
5475 flags = append(flags, vers.excludeFlag)
5476 }
David Benjaminaccb4542014-12-12 23:44:33 -05005477 }
Steven Valdez520e1222017-06-13 12:45:25 -04005478
5479 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5480
5481 if shimVers.tls13Variant != 0 {
5482 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5483 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5484 }
5485
5486 for _, runnerVers := range allVersions(protocol) {
5487 // Different TLS 1.3 variants are incompatible with each other and don't
5488 // produce consistent minimum versions.
5489 //
5490 // TODO(davidben): Fold these tests (the main value is in the
5491 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5492 // on intended shim behavior, not the shim + runner combination.
5493 if shimVers.tls13Variant != runnerVers.tls13Variant {
5494 continue
5495 }
5496
David Benjaminaccb4542014-12-12 23:44:33 -05005497 suffix := shimVers.name + "-" + runnerVers.name
5498 if protocol == dtls {
5499 suffix += "-DTLS"
5500 }
David Benjaminaccb4542014-12-12 23:44:33 -05005501
David Benjaminaccb4542014-12-12 23:44:33 -05005502 var expectedVersion uint16
5503 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005504 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005505 if runnerVers.version >= shimVers.version {
5506 expectedVersion = runnerVers.version
5507 } else {
5508 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005509 expectedError = ":UNSUPPORTED_PROTOCOL:"
5510 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005511 }
5512
5513 testCases = append(testCases, testCase{
5514 protocol: protocol,
5515 testType: clientTest,
5516 name: "MinimumVersion-Client-" + suffix,
5517 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005518 MaxVersion: runnerVers.version,
5519 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005520 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005521 // Ensure the server does not decline to
5522 // select a version (versions extension) or
5523 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005524 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005525 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005526 },
David Benjaminaccb4542014-12-12 23:44:33 -05005527 },
David Benjamin87909c02014-12-13 01:55:01 -05005528 flags: flags,
5529 expectedVersion: expectedVersion,
5530 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005531 expectedError: expectedError,
5532 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005533 })
5534 testCases = append(testCases, testCase{
5535 protocol: protocol,
5536 testType: clientTest,
5537 name: "MinimumVersion-Client2-" + suffix,
5538 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005539 MaxVersion: runnerVers.version,
5540 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005541 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005542 // Ensure the server does not decline to
5543 // select a version (versions extension) or
5544 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005545 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005546 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005547 },
David Benjaminaccb4542014-12-12 23:44:33 -05005548 },
Steven Valdez520e1222017-06-13 12:45:25 -04005549 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005550 expectedVersion: expectedVersion,
5551 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005552 expectedError: expectedError,
5553 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005554 })
5555
5556 testCases = append(testCases, testCase{
5557 protocol: protocol,
5558 testType: serverTest,
5559 name: "MinimumVersion-Server-" + suffix,
5560 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005561 MaxVersion: runnerVers.version,
5562 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005563 },
David Benjamin87909c02014-12-13 01:55:01 -05005564 flags: flags,
5565 expectedVersion: expectedVersion,
5566 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005567 expectedError: expectedError,
5568 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005569 })
5570 testCases = append(testCases, testCase{
5571 protocol: protocol,
5572 testType: serverTest,
5573 name: "MinimumVersion-Server2-" + suffix,
5574 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005575 MaxVersion: runnerVers.version,
5576 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005577 },
Steven Valdez520e1222017-06-13 12:45:25 -04005578 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005579 expectedVersion: expectedVersion,
5580 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005581 expectedError: expectedError,
5582 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005583 })
5584 }
5585 }
5586 }
5587}
5588
David Benjamine78bfde2014-09-06 12:45:15 -04005589func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005590 // TODO(davidben): Extensions, where applicable, all move their server
5591 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5592 // tests for both. Also test interaction with 0-RTT when implemented.
5593
David Benjamin97d17d92016-07-14 16:12:00 -04005594 // Repeat extensions tests all versions except SSL 3.0.
5595 for _, ver := range tlsVersions {
5596 if ver.version == VersionSSL30 {
5597 continue
5598 }
5599
David Benjamin97d17d92016-07-14 16:12:00 -04005600 // Test that duplicate extensions are rejected.
5601 testCases = append(testCases, testCase{
5602 testType: clientTest,
5603 name: "DuplicateExtensionClient-" + ver.name,
5604 config: Config{
5605 MaxVersion: ver.version,
5606 Bugs: ProtocolBugs{
5607 DuplicateExtension: true,
5608 },
David Benjamine78bfde2014-09-06 12:45:15 -04005609 },
David Benjamina5022392017-07-10 17:40:39 -04005610 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005611 shouldFail: true,
5612 expectedLocalError: "remote error: error decoding message",
5613 })
5614 testCases = append(testCases, testCase{
5615 testType: serverTest,
5616 name: "DuplicateExtensionServer-" + ver.name,
5617 config: Config{
5618 MaxVersion: ver.version,
5619 Bugs: ProtocolBugs{
5620 DuplicateExtension: true,
5621 },
David Benjamine78bfde2014-09-06 12:45:15 -04005622 },
David Benjamina5022392017-07-10 17:40:39 -04005623 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005624 shouldFail: true,
5625 expectedLocalError: "remote error: error decoding message",
5626 })
5627
5628 // Test SNI.
5629 testCases = append(testCases, testCase{
5630 testType: clientTest,
5631 name: "ServerNameExtensionClient-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 Bugs: ProtocolBugs{
5635 ExpectServerName: "example.com",
5636 },
David Benjamine78bfde2014-09-06 12:45:15 -04005637 },
David Benjamina5022392017-07-10 17:40:39 -04005638 tls13Variant: ver.tls13Variant,
5639 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005640 })
5641 testCases = append(testCases, testCase{
5642 testType: clientTest,
5643 name: "ServerNameExtensionClientMismatch-" + ver.name,
5644 config: Config{
5645 MaxVersion: ver.version,
5646 Bugs: ProtocolBugs{
5647 ExpectServerName: "mismatch.com",
5648 },
David Benjamine78bfde2014-09-06 12:45:15 -04005649 },
David Benjamin97d17d92016-07-14 16:12:00 -04005650 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005651 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005652 shouldFail: true,
5653 expectedLocalError: "tls: unexpected server name",
5654 })
5655 testCases = append(testCases, testCase{
5656 testType: clientTest,
5657 name: "ServerNameExtensionClientMissing-" + ver.name,
5658 config: Config{
5659 MaxVersion: ver.version,
5660 Bugs: ProtocolBugs{
5661 ExpectServerName: "missing.com",
5662 },
David Benjamine78bfde2014-09-06 12:45:15 -04005663 },
David Benjamina5022392017-07-10 17:40:39 -04005664 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005665 shouldFail: true,
5666 expectedLocalError: "tls: unexpected server name",
5667 })
5668 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005669 testType: clientTest,
5670 name: "TolerateServerNameAck-" + ver.name,
5671 config: Config{
5672 MaxVersion: ver.version,
5673 Bugs: ProtocolBugs{
5674 SendServerNameAck: true,
5675 },
5676 },
David Benjamina5022392017-07-10 17:40:39 -04005677 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005678 flags: []string{"-host-name", "example.com"},
5679 resumeSession: true,
5680 })
5681 testCases = append(testCases, testCase{
5682 testType: clientTest,
5683 name: "UnsolicitedServerNameAck-" + ver.name,
5684 config: Config{
5685 MaxVersion: ver.version,
5686 Bugs: ProtocolBugs{
5687 SendServerNameAck: true,
5688 },
5689 },
David Benjamina5022392017-07-10 17:40:39 -04005690 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005691 shouldFail: true,
5692 expectedError: ":UNEXPECTED_EXTENSION:",
5693 expectedLocalError: "remote error: unsupported extension",
5694 })
5695 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005696 testType: serverTest,
5697 name: "ServerNameExtensionServer-" + ver.name,
5698 config: Config{
5699 MaxVersion: ver.version,
5700 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005701 },
David Benjamina5022392017-07-10 17:40:39 -04005702 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005703 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005704 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005705 })
5706
5707 // Test ALPN.
5708 testCases = append(testCases, testCase{
5709 testType: clientTest,
5710 name: "ALPNClient-" + ver.name,
5711 config: Config{
5712 MaxVersion: ver.version,
5713 NextProtos: []string{"foo"},
5714 },
5715 flags: []string{
5716 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5717 "-expect-alpn", "foo",
5718 },
David Benjamina5022392017-07-10 17:40:39 -04005719 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005720 expectedNextProto: "foo",
5721 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005722 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005723 })
5724 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005725 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005726 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005727 config: Config{
5728 MaxVersion: ver.version,
5729 Bugs: ProtocolBugs{
5730 SendALPN: "baz",
5731 },
5732 },
5733 flags: []string{
5734 "-advertise-alpn", "\x03foo\x03bar",
5735 },
David Benjamina5022392017-07-10 17:40:39 -04005736 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005737 shouldFail: true,
5738 expectedError: ":INVALID_ALPN_PROTOCOL:",
5739 expectedLocalError: "remote error: illegal parameter",
5740 })
5741 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005742 testType: clientTest,
5743 name: "ALPNClient-AllowUnknown-" + ver.name,
5744 config: Config{
5745 MaxVersion: ver.version,
5746 Bugs: ProtocolBugs{
5747 SendALPN: "baz",
5748 },
5749 },
5750 flags: []string{
5751 "-advertise-alpn", "\x03foo\x03bar",
5752 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005753 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005754 },
David Benjamina5022392017-07-10 17:40:39 -04005755 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005756 })
5757 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005758 testType: serverTest,
5759 name: "ALPNServer-" + ver.name,
5760 config: Config{
5761 MaxVersion: ver.version,
5762 NextProtos: []string{"foo", "bar", "baz"},
5763 },
5764 flags: []string{
5765 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5766 "-select-alpn", "foo",
5767 },
David Benjamina5022392017-07-10 17:40:39 -04005768 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005769 expectedNextProto: "foo",
5770 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005771 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005772 })
5773 testCases = append(testCases, testCase{
5774 testType: serverTest,
5775 name: "ALPNServer-Decline-" + ver.name,
5776 config: Config{
5777 MaxVersion: ver.version,
5778 NextProtos: []string{"foo", "bar", "baz"},
5779 },
5780 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005781 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005782 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005783 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005784 })
5785
David Benjamin25fe85b2016-08-09 20:00:32 -04005786 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5787 // called once.
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "ALPNServer-Async-" + ver.name,
5791 config: Config{
5792 MaxVersion: ver.version,
5793 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005794 // Prior to TLS 1.3, exercise the asynchronous session callback.
5795 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005796 },
5797 flags: []string{
5798 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5799 "-select-alpn", "foo",
5800 "-async",
5801 },
David Benjamina5022392017-07-10 17:40:39 -04005802 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005803 expectedNextProto: "foo",
5804 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005805 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005806 })
5807
David Benjamin97d17d92016-07-14 16:12:00 -04005808 var emptyString string
5809 testCases = append(testCases, testCase{
5810 testType: clientTest,
5811 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5812 config: Config{
5813 MaxVersion: ver.version,
5814 NextProtos: []string{""},
5815 Bugs: ProtocolBugs{
5816 // A server returning an empty ALPN protocol
5817 // should be rejected.
5818 ALPNProtocol: &emptyString,
5819 },
5820 },
5821 flags: []string{
5822 "-advertise-alpn", "\x03foo",
5823 },
David Benjamina5022392017-07-10 17:40:39 -04005824 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005825 shouldFail: true,
5826 expectedError: ":PARSE_TLSEXT:",
5827 })
5828 testCases = append(testCases, testCase{
5829 testType: serverTest,
5830 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5831 config: Config{
5832 MaxVersion: ver.version,
5833 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005834 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005835 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005836 },
David Benjamin97d17d92016-07-14 16:12:00 -04005837 flags: []string{
5838 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005839 },
David Benjamina5022392017-07-10 17:40:39 -04005840 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005841 shouldFail: true,
5842 expectedError: ":PARSE_TLSEXT:",
5843 })
5844
5845 // Test NPN and the interaction with ALPN.
5846 if ver.version < VersionTLS13 {
5847 // Test that the server prefers ALPN over NPN.
5848 testCases = append(testCases, testCase{
5849 testType: serverTest,
5850 name: "ALPNServer-Preferred-" + ver.name,
5851 config: Config{
5852 MaxVersion: ver.version,
5853 NextProtos: []string{"foo", "bar", "baz"},
5854 },
5855 flags: []string{
5856 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5857 "-select-alpn", "foo",
5858 "-advertise-npn", "\x03foo\x03bar\x03baz",
5859 },
David Benjamina5022392017-07-10 17:40:39 -04005860 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005861 expectedNextProto: "foo",
5862 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005863 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005864 })
5865 testCases = append(testCases, testCase{
5866 testType: serverTest,
5867 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5868 config: Config{
5869 MaxVersion: ver.version,
5870 NextProtos: []string{"foo", "bar", "baz"},
5871 Bugs: ProtocolBugs{
5872 SwapNPNAndALPN: true,
5873 },
5874 },
5875 flags: []string{
5876 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5877 "-select-alpn", "foo",
5878 "-advertise-npn", "\x03foo\x03bar\x03baz",
5879 },
David Benjamina5022392017-07-10 17:40:39 -04005880 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005881 expectedNextProto: "foo",
5882 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005883 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005884 })
5885
5886 // Test that negotiating both NPN and ALPN is forbidden.
5887 testCases = append(testCases, testCase{
5888 name: "NegotiateALPNAndNPN-" + ver.name,
5889 config: Config{
5890 MaxVersion: ver.version,
5891 NextProtos: []string{"foo", "bar", "baz"},
5892 Bugs: ProtocolBugs{
5893 NegotiateALPNAndNPN: true,
5894 },
5895 },
5896 flags: []string{
5897 "-advertise-alpn", "\x03foo",
5898 "-select-next-proto", "foo",
5899 },
David Benjamina5022392017-07-10 17:40:39 -04005900 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005901 shouldFail: true,
5902 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5903 })
5904 testCases = append(testCases, testCase{
5905 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5906 config: Config{
5907 MaxVersion: ver.version,
5908 NextProtos: []string{"foo", "bar", "baz"},
5909 Bugs: ProtocolBugs{
5910 NegotiateALPNAndNPN: true,
5911 SwapNPNAndALPN: 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 })
David Benjamin97d17d92016-07-14 16:12:00 -04005922 }
5923
5924 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005925
5926 // Resume with a corrupt ticket.
5927 testCases = append(testCases, testCase{
5928 testType: serverTest,
5929 name: "CorruptTicket-" + ver.name,
5930 config: Config{
5931 MaxVersion: ver.version,
5932 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005933 FilterTicket: func(in []byte) ([]byte, error) {
5934 in[len(in)-1] ^= 1
5935 return in, nil
5936 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005937 },
5938 },
David Benjamina5022392017-07-10 17:40:39 -04005939 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005940 resumeSession: true,
5941 expectResumeRejected: true,
5942 })
5943 // Test the ticket callback, with and without renewal.
5944 testCases = append(testCases, testCase{
5945 testType: serverTest,
5946 name: "TicketCallback-" + ver.name,
5947 config: Config{
5948 MaxVersion: ver.version,
5949 },
David Benjamina5022392017-07-10 17:40:39 -04005950 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005951 resumeSession: true,
5952 flags: []string{"-use-ticket-callback"},
5953 })
5954 testCases = append(testCases, testCase{
5955 testType: serverTest,
5956 name: "TicketCallback-Renew-" + ver.name,
5957 config: Config{
5958 MaxVersion: ver.version,
5959 Bugs: ProtocolBugs{
5960 ExpectNewTicket: true,
5961 },
5962 },
David Benjamina5022392017-07-10 17:40:39 -04005963 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005964 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5965 resumeSession: true,
5966 })
5967
5968 // Test that the ticket callback is only called once when everything before
5969 // it in the ClientHello is asynchronous. This corrupts the ticket so
5970 // certificate selection callbacks run.
5971 testCases = append(testCases, testCase{
5972 testType: serverTest,
5973 name: "TicketCallback-SingleCall-" + ver.name,
5974 config: Config{
5975 MaxVersion: ver.version,
5976 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005977 FilterTicket: func(in []byte) ([]byte, error) {
5978 in[len(in)-1] ^= 1
5979 return in, nil
5980 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005981 },
5982 },
David Benjamina5022392017-07-10 17:40:39 -04005983 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005984 resumeSession: true,
5985 expectResumeRejected: true,
5986 flags: []string{
5987 "-use-ticket-callback",
5988 "-async",
5989 },
5990 })
5991
David Benjamind4c349b2017-02-09 14:07:17 -05005992 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005993 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005994 testCases = append(testCases, testCase{
5995 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005996 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005997 config: Config{
5998 MaxVersion: ver.version,
5999 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006000 EmptyTicketSessionID: true,
6001 },
6002 },
6003 resumeSession: true,
6004 })
6005 testCases = append(testCases, testCase{
6006 testType: serverTest,
6007 name: "TicketSessionIDLength-16-" + ver.name,
6008 config: Config{
6009 MaxVersion: ver.version,
6010 Bugs: ProtocolBugs{
6011 TicketSessionIDLength: 16,
6012 },
6013 },
6014 resumeSession: true,
6015 })
6016 testCases = append(testCases, testCase{
6017 testType: serverTest,
6018 name: "TicketSessionIDLength-32-" + ver.name,
6019 config: Config{
6020 MaxVersion: ver.version,
6021 Bugs: ProtocolBugs{
6022 TicketSessionIDLength: 32,
6023 },
6024 },
6025 resumeSession: true,
6026 })
6027 testCases = append(testCases, testCase{
6028 testType: serverTest,
6029 name: "TicketSessionIDLength-33-" + ver.name,
6030 config: Config{
6031 MaxVersion: ver.version,
6032 Bugs: ProtocolBugs{
6033 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006034 },
6035 },
6036 resumeSession: true,
6037 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006038 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006039 expectedError: ":DECODE_ERROR:",
6040 })
6041 }
6042
6043 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6044 // are ignored.
6045 if ver.hasDTLS {
6046 testCases = append(testCases, testCase{
6047 protocol: dtls,
6048 name: "SRTP-Client-" + ver.name,
6049 config: Config{
6050 MaxVersion: ver.version,
6051 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6052 },
6053 flags: []string{
6054 "-srtp-profiles",
6055 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6056 },
6057 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6058 })
6059 testCases = append(testCases, testCase{
6060 protocol: dtls,
6061 testType: serverTest,
6062 name: "SRTP-Server-" + ver.name,
6063 config: Config{
6064 MaxVersion: ver.version,
6065 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6066 },
6067 flags: []string{
6068 "-srtp-profiles",
6069 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6070 },
6071 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6072 })
6073 // Test that the MKI is ignored.
6074 testCases = append(testCases, testCase{
6075 protocol: dtls,
6076 testType: serverTest,
6077 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6078 config: Config{
6079 MaxVersion: ver.version,
6080 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6081 Bugs: ProtocolBugs{
6082 SRTPMasterKeyIdentifer: "bogus",
6083 },
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 SRTP isn't negotiated on the server if there were
6092 // no matching profiles.
6093 testCases = append(testCases, testCase{
6094 protocol: dtls,
6095 testType: serverTest,
6096 name: "SRTP-Server-NoMatch-" + ver.name,
6097 config: Config{
6098 MaxVersion: ver.version,
6099 SRTPProtectionProfiles: []uint16{100, 101, 102},
6100 },
6101 flags: []string{
6102 "-srtp-profiles",
6103 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6104 },
6105 expectedSRTPProtectionProfile: 0,
6106 })
6107 // Test that the server returning an invalid SRTP profile is
6108 // flagged as an error by the client.
6109 testCases = append(testCases, testCase{
6110 protocol: dtls,
6111 name: "SRTP-Client-NoMatch-" + ver.name,
6112 config: Config{
6113 MaxVersion: ver.version,
6114 Bugs: ProtocolBugs{
6115 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6116 },
6117 },
6118 flags: []string{
6119 "-srtp-profiles",
6120 "SRTP_AES128_CM_SHA1_80",
6121 },
6122 shouldFail: true,
6123 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6124 })
6125 }
6126
6127 // Test SCT list.
6128 testCases = append(testCases, testCase{
6129 name: "SignedCertificateTimestampList-Client-" + ver.name,
6130 testType: clientTest,
6131 config: Config{
6132 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006133 },
David Benjamin97d17d92016-07-14 16:12:00 -04006134 flags: []string{
6135 "-enable-signed-cert-timestamps",
6136 "-expect-signed-cert-timestamps",
6137 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006138 },
David Benjamina5022392017-07-10 17:40:39 -04006139 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006140 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006141 })
David Benjamindaa88502016-10-04 16:32:16 -04006142
Adam Langleycfa08c32016-11-17 13:21:27 -08006143 var differentSCTList []byte
6144 differentSCTList = append(differentSCTList, testSCTList...)
6145 differentSCTList[len(differentSCTList)-1] ^= 1
6146
David Benjamindaa88502016-10-04 16:32:16 -04006147 // The SCT extension did not specify that it must only be sent on resumption as it
6148 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006149 testCases = append(testCases, testCase{
6150 name: "SendSCTListOnResume-" + ver.name,
6151 config: Config{
6152 MaxVersion: ver.version,
6153 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006154 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006155 },
David Benjamind98452d2015-06-16 14:16:23 -04006156 },
David Benjamin97d17d92016-07-14 16:12:00 -04006157 flags: []string{
6158 "-enable-signed-cert-timestamps",
6159 "-expect-signed-cert-timestamps",
6160 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006161 },
David Benjamina5022392017-07-10 17:40:39 -04006162 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006163 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006164 })
David Benjamindaa88502016-10-04 16:32:16 -04006165
David Benjamin97d17d92016-07-14 16:12:00 -04006166 testCases = append(testCases, testCase{
6167 name: "SignedCertificateTimestampList-Server-" + ver.name,
6168 testType: serverTest,
6169 config: Config{
6170 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006171 },
David Benjamin97d17d92016-07-14 16:12:00 -04006172 flags: []string{
6173 "-signed-cert-timestamps",
6174 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006175 },
David Benjamina5022392017-07-10 17:40:39 -04006176 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006177 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006178 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006179 })
David Benjamin53210cb2016-11-16 09:01:48 +09006180
Adam Langleycfa08c32016-11-17 13:21:27 -08006181 emptySCTListCert := *testCerts[0].cert
6182 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6183
6184 // Test empty SCT list.
6185 testCases = append(testCases, testCase{
6186 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6187 testType: clientTest,
6188 config: Config{
6189 MaxVersion: ver.version,
6190 Certificates: []Certificate{emptySCTListCert},
6191 },
6192 flags: []string{
6193 "-enable-signed-cert-timestamps",
6194 },
David Benjamina5022392017-07-10 17:40:39 -04006195 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006196 shouldFail: true,
6197 expectedError: ":ERROR_PARSING_EXTENSION:",
6198 })
6199
6200 emptySCTCert := *testCerts[0].cert
6201 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6202
6203 // Test empty SCT in non-empty list.
6204 testCases = append(testCases, testCase{
6205 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6206 testType: clientTest,
6207 config: Config{
6208 MaxVersion: ver.version,
6209 Certificates: []Certificate{emptySCTCert},
6210 },
6211 flags: []string{
6212 "-enable-signed-cert-timestamps",
6213 },
David Benjamina5022392017-07-10 17:40:39 -04006214 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006215 shouldFail: true,
6216 expectedError: ":ERROR_PARSING_EXTENSION:",
6217 })
6218
David Benjamin53210cb2016-11-16 09:01:48 +09006219 // Test that certificate-related extensions are not sent unsolicited.
6220 testCases = append(testCases, testCase{
6221 testType: serverTest,
6222 name: "UnsolicitedCertificateExtensions-" + ver.name,
6223 config: Config{
6224 MaxVersion: ver.version,
6225 Bugs: ProtocolBugs{
6226 NoOCSPStapling: true,
6227 NoSignedCertificateTimestamps: true,
6228 },
6229 },
David Benjamina5022392017-07-10 17:40:39 -04006230 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006231 flags: []string{
6232 "-ocsp-response",
6233 base64.StdEncoding.EncodeToString(testOCSPResponse),
6234 "-signed-cert-timestamps",
6235 base64.StdEncoding.EncodeToString(testSCTList),
6236 },
6237 })
David Benjamin97d17d92016-07-14 16:12:00 -04006238 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006239
Paul Lietar4fac72e2015-09-09 13:44:55 +01006240 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006241 testType: clientTest,
6242 name: "ClientHelloPadding",
6243 config: Config{
6244 Bugs: ProtocolBugs{
6245 RequireClientHelloSize: 512,
6246 },
6247 },
6248 // This hostname just needs to be long enough to push the
6249 // ClientHello into F5's danger zone between 256 and 511 bytes
6250 // long.
6251 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6252 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006253
6254 // Extensions should not function in SSL 3.0.
6255 testCases = append(testCases, testCase{
6256 testType: serverTest,
6257 name: "SSLv3Extensions-NoALPN",
6258 config: Config{
6259 MaxVersion: VersionSSL30,
6260 NextProtos: []string{"foo", "bar", "baz"},
6261 },
6262 flags: []string{
6263 "-select-alpn", "foo",
6264 },
6265 expectNoNextProto: true,
6266 })
6267
6268 // Test session tickets separately as they follow a different codepath.
6269 testCases = append(testCases, testCase{
6270 testType: serverTest,
6271 name: "SSLv3Extensions-NoTickets",
6272 config: Config{
6273 MaxVersion: VersionSSL30,
6274 Bugs: ProtocolBugs{
6275 // Historically, session tickets in SSL 3.0
6276 // failed in different ways depending on whether
6277 // the client supported renegotiation_info.
6278 NoRenegotiationInfo: true,
6279 },
6280 },
6281 resumeSession: true,
6282 })
6283 testCases = append(testCases, testCase{
6284 testType: serverTest,
6285 name: "SSLv3Extensions-NoTickets2",
6286 config: Config{
6287 MaxVersion: VersionSSL30,
6288 },
6289 resumeSession: true,
6290 })
6291
6292 // But SSL 3.0 does send and process renegotiation_info.
6293 testCases = append(testCases, testCase{
6294 testType: serverTest,
6295 name: "SSLv3Extensions-RenegotiationInfo",
6296 config: Config{
6297 MaxVersion: VersionSSL30,
6298 Bugs: ProtocolBugs{
6299 RequireRenegotiationInfo: true,
6300 },
6301 },
David Benjamind2610042017-01-03 10:49:28 -05006302 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006303 })
6304 testCases = append(testCases, testCase{
6305 testType: serverTest,
6306 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6307 config: Config{
6308 MaxVersion: VersionSSL30,
6309 Bugs: ProtocolBugs{
6310 NoRenegotiationInfo: true,
6311 SendRenegotiationSCSV: true,
6312 RequireRenegotiationInfo: true,
6313 },
6314 },
David Benjamind2610042017-01-03 10:49:28 -05006315 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006316 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006317
6318 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6319 // in ServerHello.
6320 testCases = append(testCases, testCase{
6321 name: "NPN-Forbidden-TLS13",
6322 config: Config{
6323 MaxVersion: VersionTLS13,
6324 NextProtos: []string{"foo"},
6325 Bugs: ProtocolBugs{
6326 NegotiateNPNAtAllVersions: true,
6327 },
6328 },
6329 flags: []string{"-select-next-proto", "foo"},
6330 shouldFail: true,
6331 expectedError: ":ERROR_PARSING_EXTENSION:",
6332 })
6333 testCases = append(testCases, testCase{
6334 name: "EMS-Forbidden-TLS13",
6335 config: Config{
6336 MaxVersion: VersionTLS13,
6337 Bugs: ProtocolBugs{
6338 NegotiateEMSAtAllVersions: true,
6339 },
6340 },
6341 shouldFail: true,
6342 expectedError: ":ERROR_PARSING_EXTENSION:",
6343 })
6344 testCases = append(testCases, testCase{
6345 name: "RenegotiationInfo-Forbidden-TLS13",
6346 config: Config{
6347 MaxVersion: VersionTLS13,
6348 Bugs: ProtocolBugs{
6349 NegotiateRenegotiationInfoAtAllVersions: true,
6350 },
6351 },
6352 shouldFail: true,
6353 expectedError: ":ERROR_PARSING_EXTENSION:",
6354 })
6355 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006356 name: "Ticket-Forbidden-TLS13",
6357 config: Config{
6358 MaxVersion: VersionTLS12,
6359 },
6360 resumeConfig: &Config{
6361 MaxVersion: VersionTLS13,
6362 Bugs: ProtocolBugs{
6363 AdvertiseTicketExtension: true,
6364 },
6365 },
6366 resumeSession: true,
6367 shouldFail: true,
6368 expectedError: ":ERROR_PARSING_EXTENSION:",
6369 })
6370
6371 // Test that illegal extensions in TLS 1.3 are declined by the server if
6372 // offered in ClientHello. The runner's server will fail if this occurs,
6373 // so we exercise the offering path. (EMS and Renegotiation Info are
6374 // implicit in every test.)
6375 testCases = append(testCases, testCase{
6376 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006377 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006378 config: Config{
6379 MaxVersion: VersionTLS13,
6380 NextProtos: []string{"bar"},
6381 },
6382 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6383 })
David Benjamin196df5b2016-09-21 16:23:27 -04006384
David Benjamindaa88502016-10-04 16:32:16 -04006385 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6386 // tolerated.
6387 testCases = append(testCases, testCase{
6388 name: "SendOCSPResponseOnResume-TLS12",
6389 config: Config{
6390 MaxVersion: VersionTLS12,
6391 Bugs: ProtocolBugs{
6392 SendOCSPResponseOnResume: []byte("bogus"),
6393 },
6394 },
6395 flags: []string{
6396 "-enable-ocsp-stapling",
6397 "-expect-ocsp-response",
6398 base64.StdEncoding.EncodeToString(testOCSPResponse),
6399 },
6400 resumeSession: true,
6401 })
6402
David Benjamindaa88502016-10-04 16:32:16 -04006403 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006404 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006405 config: Config{
6406 MaxVersion: VersionTLS13,
6407 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006408 SendExtensionOnCertificate: testOCSPExtension,
6409 },
6410 },
6411 shouldFail: true,
6412 expectedError: ":UNEXPECTED_EXTENSION:",
6413 })
6414
6415 testCases = append(testCases, testCase{
6416 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6417 config: Config{
6418 MaxVersion: VersionTLS13,
6419 Bugs: ProtocolBugs{
6420 SendExtensionOnCertificate: testSCTExtension,
6421 },
6422 },
6423 shouldFail: true,
6424 expectedError: ":UNEXPECTED_EXTENSION:",
6425 })
6426
6427 // Test that extensions on client certificates are never accepted.
6428 testCases = append(testCases, testCase{
6429 name: "SendExtensionOnClientCertificate-TLS13",
6430 testType: serverTest,
6431 config: Config{
6432 MaxVersion: VersionTLS13,
6433 Certificates: []Certificate{rsaCertificate},
6434 Bugs: ProtocolBugs{
6435 SendExtensionOnCertificate: testOCSPExtension,
6436 },
6437 },
6438 flags: []string{
6439 "-enable-ocsp-stapling",
6440 "-require-any-client-certificate",
6441 },
6442 shouldFail: true,
6443 expectedError: ":UNEXPECTED_EXTENSION:",
6444 })
6445
6446 testCases = append(testCases, testCase{
6447 name: "SendUnknownExtensionOnCertificate-TLS13",
6448 config: Config{
6449 MaxVersion: VersionTLS13,
6450 Bugs: ProtocolBugs{
6451 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6452 },
6453 },
6454 shouldFail: true,
6455 expectedError: ":UNEXPECTED_EXTENSION:",
6456 })
6457
Adam Langleycfa08c32016-11-17 13:21:27 -08006458 var differentSCTList []byte
6459 differentSCTList = append(differentSCTList, testSCTList...)
6460 differentSCTList[len(differentSCTList)-1] ^= 1
6461
Steven Valdeza833c352016-11-01 13:39:36 -04006462 // Test that extensions on intermediates are allowed but ignored.
6463 testCases = append(testCases, testCase{
6464 name: "IgnoreExtensionsOnIntermediates-TLS13",
6465 config: Config{
6466 MaxVersion: VersionTLS13,
6467 Certificates: []Certificate{rsaChainCertificate},
6468 Bugs: ProtocolBugs{
6469 // Send different values on the intermediate. This tests
6470 // the intermediate's extensions do not override the
6471 // leaf's.
6472 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006473 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006474 },
6475 },
6476 flags: []string{
6477 "-enable-ocsp-stapling",
6478 "-expect-ocsp-response",
6479 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006480 "-enable-signed-cert-timestamps",
6481 "-expect-signed-cert-timestamps",
6482 base64.StdEncoding.EncodeToString(testSCTList),
6483 },
6484 resumeSession: true,
6485 })
6486
6487 // Test that extensions are not sent on intermediates when configured
6488 // only for a leaf.
6489 testCases = append(testCases, testCase{
6490 testType: serverTest,
6491 name: "SendNoExtensionsOnIntermediate-TLS13",
6492 config: Config{
6493 MaxVersion: VersionTLS13,
6494 Bugs: ProtocolBugs{
6495 ExpectNoExtensionsOnIntermediate: true,
6496 },
6497 },
6498 flags: []string{
6499 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6500 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6501 "-ocsp-response",
6502 base64.StdEncoding.EncodeToString(testOCSPResponse),
6503 "-signed-cert-timestamps",
6504 base64.StdEncoding.EncodeToString(testSCTList),
6505 },
6506 })
6507
6508 // Test that extensions are not sent on client certificates.
6509 testCases = append(testCases, testCase{
6510 name: "SendNoClientCertificateExtensions-TLS13",
6511 config: Config{
6512 MaxVersion: VersionTLS13,
6513 ClientAuth: RequireAnyClientCert,
6514 },
6515 flags: []string{
6516 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6517 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6518 "-ocsp-response",
6519 base64.StdEncoding.EncodeToString(testOCSPResponse),
6520 "-signed-cert-timestamps",
6521 base64.StdEncoding.EncodeToString(testSCTList),
6522 },
6523 })
6524
6525 testCases = append(testCases, testCase{
6526 name: "SendDuplicateExtensionsOnCerts-TLS13",
6527 config: Config{
6528 MaxVersion: VersionTLS13,
6529 Bugs: ProtocolBugs{
6530 SendDuplicateCertExtensions: true,
6531 },
6532 },
6533 flags: []string{
6534 "-enable-ocsp-stapling",
6535 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006536 },
6537 resumeSession: true,
6538 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006539 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006540 })
Adam Langley9b885c52016-11-18 14:21:03 -08006541
6542 testCases = append(testCases, testCase{
6543 name: "SignedCertificateTimestampListInvalid-Server",
6544 testType: serverTest,
6545 flags: []string{
6546 "-signed-cert-timestamps",
6547 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6548 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006549 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006550 expectedError: ":INVALID_SCT_LIST:",
6551 })
David Benjamine78bfde2014-09-06 12:45:15 -04006552}
6553
David Benjamin01fe8202014-09-24 15:21:44 -04006554func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006555 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006556 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006557 // SSL 3.0 does not have tickets and TLS 1.3 does not
6558 // have session IDs, so skip their cross-resumption
6559 // tests.
6560 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6561 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6562 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006563 }
6564
David Benjamin8b8c0062014-11-23 02:47:52 -05006565 protocols := []protocol{tls}
6566 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6567 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006568 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006569 for _, protocol := range protocols {
6570 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6571 if protocol == dtls {
6572 suffix += "-DTLS"
6573 }
6574
Steven Valdez520e1222017-06-13 12:45:25 -04006575 // We can't resume across TLS 1.3 variants and error out earlier in the
6576 // session resumption.
6577 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6578 continue
6579 }
6580
David Benjaminece3de92015-03-16 18:02:20 -04006581 if sessionVers.version == resumeVers.version {
6582 testCases = append(testCases, testCase{
6583 protocol: protocol,
6584 name: "Resume-Client" + suffix,
6585 resumeSession: true,
6586 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006587 MaxVersion: sessionVers.version,
6588 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006589 Bugs: ProtocolBugs{
6590 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6591 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6592 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006593 },
David Benjaminece3de92015-03-16 18:02:20 -04006594 expectedVersion: sessionVers.version,
6595 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006596 flags: []string{
6597 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6598 },
David Benjaminece3de92015-03-16 18:02:20 -04006599 })
6600 } else {
David Benjamin405da482016-08-08 17:25:07 -04006601 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6602
6603 // Offering a TLS 1.3 session sends an empty session ID, so
6604 // there is no way to convince a non-lookahead client the
6605 // session was resumed. It will appear to the client that a
6606 // stray ChangeCipherSpec was sent.
6607 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6608 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006609 }
6610
David Benjaminece3de92015-03-16 18:02:20 -04006611 testCases = append(testCases, testCase{
6612 protocol: protocol,
6613 name: "Resume-Client-Mismatch" + suffix,
6614 resumeSession: true,
6615 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006616 MaxVersion: sessionVers.version,
6617 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006618 },
David Benjaminece3de92015-03-16 18:02:20 -04006619 expectedVersion: sessionVers.version,
6620 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006621 MaxVersion: resumeVers.version,
6622 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006623 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006624 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006625 },
6626 },
6627 expectedResumeVersion: resumeVers.version,
6628 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006629 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006630 flags: []string{
6631 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6632 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6633 },
David Benjaminece3de92015-03-16 18:02:20 -04006634 })
6635 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006636
6637 testCases = append(testCases, testCase{
6638 protocol: protocol,
6639 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006640 resumeSession: true,
6641 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006642 MaxVersion: sessionVers.version,
6643 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006644 },
6645 expectedVersion: sessionVers.version,
6646 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006647 MaxVersion: resumeVers.version,
6648 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006649 },
6650 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006651 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006652 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006653 flags: []string{
6654 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6655 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6656 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006657 })
6658
David Benjamin8b8c0062014-11-23 02:47:52 -05006659 testCases = append(testCases, testCase{
6660 protocol: protocol,
6661 testType: serverTest,
6662 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006663 resumeSession: true,
6664 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006665 MaxVersion: sessionVers.version,
6666 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006667 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006668 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006669 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006670 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006671 MaxVersion: resumeVers.version,
6672 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006673 Bugs: ProtocolBugs{
6674 SendBothTickets: true,
6675 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006676 },
6677 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006678 flags: []string{
6679 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6680 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6681 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006682 })
6683 }
David Benjamin01fe8202014-09-24 15:21:44 -04006684 }
6685 }
David Benjaminece3de92015-03-16 18:02:20 -04006686
David Benjamin4199b0d2016-11-01 13:58:25 -04006687 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006688 testCases = append(testCases, testCase{
6689 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006690 name: "ShimTicketRewritable",
6691 resumeSession: true,
6692 config: Config{
6693 MaxVersion: VersionTLS12,
6694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6695 Bugs: ProtocolBugs{
6696 FilterTicket: func(in []byte) ([]byte, error) {
6697 in, err := SetShimTicketVersion(in, VersionTLS12)
6698 if err != nil {
6699 return nil, err
6700 }
6701 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6702 },
6703 },
6704 },
6705 flags: []string{
6706 "-ticket-key",
6707 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6708 },
6709 })
6710
6711 // Resumptions are declined if the version does not match.
6712 testCases = append(testCases, testCase{
6713 testType: serverTest,
6714 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006715 resumeSession: true,
6716 config: Config{
6717 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006718 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006719 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006720 FilterTicket: func(in []byte) ([]byte, error) {
6721 return SetShimTicketVersion(in, VersionTLS13)
6722 },
6723 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006724 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006725 flags: []string{
6726 "-ticket-key",
6727 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6728 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006729 expectResumeRejected: true,
6730 })
6731
6732 testCases = append(testCases, testCase{
6733 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006734 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006735 resumeSession: true,
6736 config: Config{
6737 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006738 Bugs: ProtocolBugs{
6739 FilterTicket: func(in []byte) ([]byte, error) {
6740 return SetShimTicketVersion(in, VersionTLS12)
6741 },
6742 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006743 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006744 flags: []string{
6745 "-ticket-key",
6746 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6747 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006748 expectResumeRejected: true,
6749 })
6750
David Benjamin4199b0d2016-11-01 13:58:25 -04006751 // Resumptions are declined if the cipher is invalid or disabled.
6752 testCases = append(testCases, testCase{
6753 testType: serverTest,
6754 name: "Resume-Server-DeclineBadCipher",
6755 resumeSession: true,
6756 config: Config{
6757 MaxVersion: VersionTLS12,
6758 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006759 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006760 FilterTicket: func(in []byte) ([]byte, error) {
6761 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6762 },
6763 },
6764 },
6765 flags: []string{
6766 "-ticket-key",
6767 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6768 },
6769 expectResumeRejected: true,
6770 })
6771
6772 testCases = append(testCases, testCase{
6773 testType: serverTest,
6774 name: "Resume-Server-DeclineBadCipher-2",
6775 resumeSession: true,
6776 config: Config{
6777 MaxVersion: VersionTLS12,
6778 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006779 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006780 FilterTicket: func(in []byte) ([]byte, error) {
6781 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6782 },
6783 },
6784 },
6785 flags: []string{
6786 "-cipher", "AES128",
6787 "-ticket-key",
6788 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6789 },
6790 expectResumeRejected: true,
6791 })
6792
David Benjaminf01f42a2016-11-16 19:05:33 +09006793 // Sessions are not resumed if they do not use the preferred cipher.
6794 testCases = append(testCases, testCase{
6795 testType: serverTest,
6796 name: "Resume-Server-CipherNotPreferred",
6797 resumeSession: true,
6798 config: Config{
6799 MaxVersion: VersionTLS12,
6800 Bugs: ProtocolBugs{
6801 ExpectNewTicket: true,
6802 FilterTicket: func(in []byte) ([]byte, error) {
6803 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6804 },
6805 },
6806 },
6807 flags: []string{
6808 "-ticket-key",
6809 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6810 },
6811 shouldFail: false,
6812 expectResumeRejected: true,
6813 })
6814
6815 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6816 // PRF hashes match, but BoringSSL will always decline such resumptions.
6817 testCases = append(testCases, testCase{
6818 testType: serverTest,
6819 name: "Resume-Server-CipherNotPreferred-TLS13",
6820 resumeSession: true,
6821 config: Config{
6822 MaxVersion: VersionTLS13,
6823 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6824 Bugs: ProtocolBugs{
6825 FilterTicket: func(in []byte) ([]byte, error) {
6826 // If the client (runner) offers ChaCha20-Poly1305 first, the
6827 // server (shim) always prefers it. Switch it to AES-GCM.
6828 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6829 },
6830 },
6831 },
6832 flags: []string{
6833 "-ticket-key",
6834 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6835 },
6836 shouldFail: false,
6837 expectResumeRejected: true,
6838 })
6839
6840 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006841 testCases = append(testCases, testCase{
6842 testType: serverTest,
6843 name: "Resume-Server-DeclineBadCipher-TLS13",
6844 resumeSession: true,
6845 config: Config{
6846 MaxVersion: VersionTLS13,
6847 Bugs: ProtocolBugs{
6848 FilterTicket: func(in []byte) ([]byte, error) {
6849 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6850 },
6851 },
6852 },
6853 flags: []string{
6854 "-ticket-key",
6855 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6856 },
6857 expectResumeRejected: true,
6858 })
6859
David Benjaminf01f42a2016-11-16 19:05:33 +09006860 // If the client does not offer the cipher from the session, decline to
6861 // resume. Clients are forbidden from doing this, but BoringSSL selects
6862 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006863 testCases = append(testCases, testCase{
6864 testType: serverTest,
6865 name: "Resume-Server-UnofferedCipher",
6866 resumeSession: true,
6867 config: Config{
6868 MaxVersion: VersionTLS12,
6869 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6870 },
6871 resumeConfig: &Config{
6872 MaxVersion: VersionTLS12,
6873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6874 Bugs: ProtocolBugs{
6875 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6876 },
6877 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006878 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006879 })
6880
David Benjaminf01f42a2016-11-16 19:05:33 +09006881 // In TLS 1.3, clients may advertise a cipher list which does not
6882 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006883 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6884 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006885 testCases = append(testCases, testCase{
6886 testType: serverTest,
6887 name: "Resume-Server-UnofferedCipher-TLS13",
6888 resumeSession: true,
6889 config: Config{
6890 MaxVersion: VersionTLS13,
6891 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6892 },
6893 resumeConfig: &Config{
6894 MaxVersion: VersionTLS13,
6895 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6896 Bugs: ProtocolBugs{
6897 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6898 },
6899 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006900 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006901 })
6902
David Benjamin4199b0d2016-11-01 13:58:25 -04006903 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006904 testCases = append(testCases, testCase{
6905 name: "Resume-Client-CipherMismatch",
6906 resumeSession: true,
6907 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006908 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006909 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6910 },
6911 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006912 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006913 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6914 Bugs: ProtocolBugs{
6915 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6916 },
6917 },
6918 shouldFail: true,
6919 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6920 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006921
David Benjamine1cc35e2016-11-16 16:25:58 +09006922 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6923 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006924 testCases = append(testCases, testCase{
6925 name: "Resume-Client-CipherMismatch-TLS13",
6926 resumeSession: true,
6927 config: Config{
6928 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006929 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006930 },
6931 resumeConfig: &Config{
6932 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006933 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6934 },
6935 })
6936
6937 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6938 testCases = append(testCases, testCase{
6939 name: "Resume-Client-PRFMismatch-TLS13",
6940 resumeSession: true,
6941 config: Config{
6942 MaxVersion: VersionTLS13,
6943 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6944 },
6945 resumeConfig: &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 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006949 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006950 },
6951 },
6952 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006953 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006954 })
Steven Valdeza833c352016-11-01 13:39:36 -04006955
6956 testCases = append(testCases, testCase{
6957 testType: serverTest,
6958 name: "Resume-Server-BinderWrongLength",
6959 resumeSession: true,
6960 config: Config{
6961 MaxVersion: VersionTLS13,
6962 Bugs: ProtocolBugs{
6963 SendShortPSKBinder: true,
6964 },
6965 },
6966 shouldFail: true,
6967 expectedLocalError: "remote error: error decrypting message",
6968 expectedError: ":DIGEST_CHECK_FAILED:",
6969 })
6970
6971 testCases = append(testCases, testCase{
6972 testType: serverTest,
6973 name: "Resume-Server-NoPSKBinder",
6974 resumeSession: true,
6975 config: Config{
6976 MaxVersion: VersionTLS13,
6977 Bugs: ProtocolBugs{
6978 SendNoPSKBinder: true,
6979 },
6980 },
6981 shouldFail: true,
6982 expectedLocalError: "remote error: error decoding message",
6983 expectedError: ":DECODE_ERROR:",
6984 })
6985
6986 testCases = append(testCases, testCase{
6987 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006988 name: "Resume-Server-ExtraPSKBinder",
6989 resumeSession: true,
6990 config: Config{
6991 MaxVersion: VersionTLS13,
6992 Bugs: ProtocolBugs{
6993 SendExtraPSKBinder: true,
6994 },
6995 },
6996 shouldFail: true,
6997 expectedLocalError: "remote error: illegal parameter",
6998 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6999 })
7000
7001 testCases = append(testCases, testCase{
7002 testType: serverTest,
7003 name: "Resume-Server-ExtraIdentityNoBinder",
7004 resumeSession: true,
7005 config: Config{
7006 MaxVersion: VersionTLS13,
7007 Bugs: ProtocolBugs{
7008 ExtraPSKIdentity: true,
7009 },
7010 },
7011 shouldFail: true,
7012 expectedLocalError: "remote error: illegal parameter",
7013 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7014 })
7015
7016 testCases = append(testCases, testCase{
7017 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007018 name: "Resume-Server-InvalidPSKBinder",
7019 resumeSession: true,
7020 config: Config{
7021 MaxVersion: VersionTLS13,
7022 Bugs: ProtocolBugs{
7023 SendInvalidPSKBinder: true,
7024 },
7025 },
7026 shouldFail: true,
7027 expectedLocalError: "remote error: error decrypting message",
7028 expectedError: ":DIGEST_CHECK_FAILED:",
7029 })
7030
7031 testCases = append(testCases, testCase{
7032 testType: serverTest,
7033 name: "Resume-Server-PSKBinderFirstExtension",
7034 resumeSession: true,
7035 config: Config{
7036 MaxVersion: VersionTLS13,
7037 Bugs: ProtocolBugs{
7038 PSKBinderFirst: true,
7039 },
7040 },
7041 shouldFail: true,
7042 expectedLocalError: "remote error: illegal parameter",
7043 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7044 })
David Benjamin01fe8202014-09-24 15:21:44 -04007045}
7046
Adam Langley2ae77d22014-10-28 17:29:33 -07007047func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007048 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007049 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007050 testType: serverTest,
7051 name: "Renegotiate-Server-Forbidden",
7052 config: Config{
7053 MaxVersion: VersionTLS12,
7054 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007055 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007056 shouldFail: true,
7057 expectedError: ":NO_RENEGOTIATION:",
7058 expectedLocalError: "remote error: no renegotiation",
7059 })
Adam Langley5021b222015-06-12 18:27:58 -07007060 // The server shouldn't echo the renegotiation extension unless
7061 // requested by the client.
7062 testCases = append(testCases, testCase{
7063 testType: serverTest,
7064 name: "Renegotiate-Server-NoExt",
7065 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007066 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007067 Bugs: ProtocolBugs{
7068 NoRenegotiationInfo: true,
7069 RequireRenegotiationInfo: true,
7070 },
7071 },
7072 shouldFail: true,
7073 expectedLocalError: "renegotiation extension missing",
7074 })
7075 // The renegotiation SCSV should be sufficient for the server to echo
7076 // the extension.
7077 testCases = append(testCases, testCase{
7078 testType: serverTest,
7079 name: "Renegotiate-Server-NoExt-SCSV",
7080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007081 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007082 Bugs: ProtocolBugs{
7083 NoRenegotiationInfo: true,
7084 SendRenegotiationSCSV: true,
7085 RequireRenegotiationInfo: true,
7086 },
7087 },
7088 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007089 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007090 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007092 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007093 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007094 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007095 },
7096 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007097 renegotiate: 1,
7098 flags: []string{
7099 "-renegotiate-freely",
7100 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007101 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007102 },
David Benjamincdea40c2015-03-19 14:09:43 -04007103 })
7104 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007105 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007106 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007108 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007109 Bugs: ProtocolBugs{
7110 EmptyRenegotiationInfo: true,
7111 },
7112 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007113 flags: []string{"-renegotiate-freely"},
7114 shouldFail: true,
7115 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007116 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007117 })
7118 testCases = append(testCases, testCase{
7119 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007120 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007122 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007123 Bugs: ProtocolBugs{
7124 BadRenegotiationInfo: true,
7125 },
7126 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007127 flags: []string{"-renegotiate-freely"},
7128 shouldFail: true,
7129 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007130 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007131 })
7132 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007133 name: "Renegotiate-Client-BadExt2",
7134 renegotiate: 1,
7135 config: Config{
7136 MaxVersion: VersionTLS12,
7137 Bugs: ProtocolBugs{
7138 BadRenegotiationInfoEnd: true,
7139 },
7140 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007141 flags: []string{"-renegotiate-freely"},
7142 shouldFail: true,
7143 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007144 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007145 })
7146 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007147 name: "Renegotiate-Client-Downgrade",
7148 renegotiate: 1,
7149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007150 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007151 Bugs: ProtocolBugs{
7152 NoRenegotiationInfoAfterInitial: true,
7153 },
7154 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007155 flags: []string{"-renegotiate-freely"},
7156 shouldFail: true,
7157 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007158 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007159 })
7160 testCases = append(testCases, testCase{
7161 name: "Renegotiate-Client-Upgrade",
7162 renegotiate: 1,
7163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007164 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007165 Bugs: ProtocolBugs{
7166 NoRenegotiationInfoInInitial: true,
7167 },
7168 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007169 flags: []string{"-renegotiate-freely"},
7170 shouldFail: true,
7171 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007172 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007173 })
7174 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007175 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007176 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007178 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007179 Bugs: ProtocolBugs{
7180 NoRenegotiationInfo: true,
7181 },
7182 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007183 flags: []string{
7184 "-renegotiate-freely",
7185 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007186 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007187 },
David Benjamincff0b902015-05-15 23:09:47 -04007188 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007189
7190 // Test that the server may switch ciphers on renegotiation without
7191 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007192 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007193 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007194 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007195 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007196 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007197 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007198 },
7199 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007200 flags: []string{
7201 "-renegotiate-freely",
7202 "-expect-total-renegotiations", "1",
7203 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007204 })
7205 testCases = append(testCases, testCase{
7206 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007207 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007208 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007209 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007210 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7211 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007212 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007213 flags: []string{
7214 "-renegotiate-freely",
7215 "-expect-total-renegotiations", "1",
7216 },
David Benjaminb16346b2015-04-08 19:16:58 -04007217 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007218
7219 // Test that the server may not switch versions on renegotiation.
7220 testCases = append(testCases, testCase{
7221 name: "Renegotiate-Client-SwitchVersion",
7222 config: Config{
7223 MaxVersion: VersionTLS12,
7224 // Pick a cipher which exists at both versions.
7225 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7226 Bugs: ProtocolBugs{
7227 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007228 // Avoid failing early at the record layer.
7229 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007230 },
7231 },
7232 renegotiate: 1,
7233 flags: []string{
7234 "-renegotiate-freely",
7235 "-expect-total-renegotiations", "1",
7236 },
7237 shouldFail: true,
7238 expectedError: ":WRONG_SSL_VERSION:",
7239 })
7240
David Benjaminb16346b2015-04-08 19:16:58 -04007241 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007242 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007243 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007244 config: Config{
7245 MaxVersion: VersionTLS10,
7246 Bugs: ProtocolBugs{
7247 RequireSameRenegoClientVersion: true,
7248 },
7249 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007250 flags: []string{
7251 "-renegotiate-freely",
7252 "-expect-total-renegotiations", "1",
7253 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007254 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007255 testCases = append(testCases, testCase{
7256 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007257 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007258 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007259 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007260 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7261 NextProtos: []string{"foo"},
7262 },
7263 flags: []string{
7264 "-false-start",
7265 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007266 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007267 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007268 },
7269 shimWritesFirst: true,
7270 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007271
7272 // Client-side renegotiation controls.
7273 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007274 name: "Renegotiate-Client-Forbidden-1",
7275 config: Config{
7276 MaxVersion: VersionTLS12,
7277 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007278 renegotiate: 1,
7279 shouldFail: true,
7280 expectedError: ":NO_RENEGOTIATION:",
7281 expectedLocalError: "remote error: no renegotiation",
7282 })
7283 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007284 name: "Renegotiate-Client-Once-1",
7285 config: Config{
7286 MaxVersion: VersionTLS12,
7287 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007288 renegotiate: 1,
7289 flags: []string{
7290 "-renegotiate-once",
7291 "-expect-total-renegotiations", "1",
7292 },
7293 })
7294 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007295 name: "Renegotiate-Client-Freely-1",
7296 config: Config{
7297 MaxVersion: VersionTLS12,
7298 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007299 renegotiate: 1,
7300 flags: []string{
7301 "-renegotiate-freely",
7302 "-expect-total-renegotiations", "1",
7303 },
7304 })
7305 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007306 name: "Renegotiate-Client-Once-2",
7307 config: Config{
7308 MaxVersion: VersionTLS12,
7309 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007310 renegotiate: 2,
7311 flags: []string{"-renegotiate-once"},
7312 shouldFail: true,
7313 expectedError: ":NO_RENEGOTIATION:",
7314 expectedLocalError: "remote error: no renegotiation",
7315 })
7316 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007317 name: "Renegotiate-Client-Freely-2",
7318 config: Config{
7319 MaxVersion: VersionTLS12,
7320 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007321 renegotiate: 2,
7322 flags: []string{
7323 "-renegotiate-freely",
7324 "-expect-total-renegotiations", "2",
7325 },
7326 })
Adam Langley27a0d082015-11-03 13:34:10 -08007327 testCases = append(testCases, testCase{
7328 name: "Renegotiate-Client-NoIgnore",
7329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007330 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007331 Bugs: ProtocolBugs{
7332 SendHelloRequestBeforeEveryAppDataRecord: true,
7333 },
7334 },
7335 shouldFail: true,
7336 expectedError: ":NO_RENEGOTIATION:",
7337 })
7338 testCases = append(testCases, testCase{
7339 name: "Renegotiate-Client-Ignore",
7340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007341 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007342 Bugs: ProtocolBugs{
7343 SendHelloRequestBeforeEveryAppDataRecord: true,
7344 },
7345 },
7346 flags: []string{
7347 "-renegotiate-ignore",
7348 "-expect-total-renegotiations", "0",
7349 },
7350 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007351
David Benjamin34941c02016-10-08 11:45:31 -04007352 // Renegotiation is not allowed at SSL 3.0.
7353 testCases = append(testCases, testCase{
7354 name: "Renegotiate-Client-SSL3",
7355 config: Config{
7356 MaxVersion: VersionSSL30,
7357 },
7358 renegotiate: 1,
7359 flags: []string{
7360 "-renegotiate-freely",
7361 "-expect-total-renegotiations", "1",
7362 },
7363 shouldFail: true,
7364 expectedError: ":NO_RENEGOTIATION:",
7365 expectedLocalError: "remote error: no renegotiation",
7366 })
7367
David Benjamina1eaba12017-01-01 23:19:22 -05007368 // Renegotiation is not allowed when there is an unfinished write.
7369 testCases = append(testCases, testCase{
7370 name: "Renegotiate-Client-UnfinishedWrite",
7371 config: Config{
7372 MaxVersion: VersionTLS12,
7373 },
David Benjaminbbba9392017-04-06 12:54:12 -04007374 renegotiate: 1,
7375 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007376 flags: []string{
7377 "-async",
7378 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007379 },
7380 shouldFail: true,
7381 expectedError: ":NO_RENEGOTIATION:",
7382 // We do not successfully send the no_renegotiation alert in
7383 // this case. https://crbug.com/boringssl/130
7384 })
7385
David Benjamin07ab5d42017-02-09 20:11:41 -05007386 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007387 testCases = append(testCases, testCase{
7388 name: "StrayHelloRequest",
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 Bugs: ProtocolBugs{
7392 SendHelloRequestBeforeEveryHandshakeMessage: true,
7393 },
7394 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007395 shouldFail: true,
7396 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007397 })
7398 testCases = append(testCases, testCase{
7399 name: "StrayHelloRequest-Packed",
7400 config: Config{
7401 MaxVersion: VersionTLS12,
7402 Bugs: ProtocolBugs{
7403 PackHandshakeFlight: true,
7404 SendHelloRequestBeforeEveryHandshakeMessage: true,
7405 },
7406 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007407 shouldFail: true,
7408 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007409 })
7410
David Benjamin12d2c482016-07-24 10:56:51 -04007411 // Test renegotiation works if HelloRequest and server Finished come in
7412 // the same record.
7413 testCases = append(testCases, testCase{
7414 name: "Renegotiate-Client-Packed",
7415 config: Config{
7416 MaxVersion: VersionTLS12,
7417 Bugs: ProtocolBugs{
7418 PackHandshakeFlight: true,
7419 PackHelloRequestWithFinished: true,
7420 },
7421 },
7422 renegotiate: 1,
7423 flags: []string{
7424 "-renegotiate-freely",
7425 "-expect-total-renegotiations", "1",
7426 },
7427 })
7428
David Benjamin397c8e62016-07-08 14:14:36 -07007429 // Renegotiation is forbidden in TLS 1.3.
7430 testCases = append(testCases, testCase{
7431 name: "Renegotiate-Client-TLS13",
7432 config: Config{
7433 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007434 Bugs: ProtocolBugs{
7435 SendHelloRequestBeforeEveryAppDataRecord: true,
7436 },
David Benjamin397c8e62016-07-08 14:14:36 -07007437 },
David Benjamin397c8e62016-07-08 14:14:36 -07007438 flags: []string{
7439 "-renegotiate-freely",
7440 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007441 shouldFail: true,
7442 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007443 })
7444
7445 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7446 testCases = append(testCases, testCase{
7447 name: "StrayHelloRequest-TLS13",
7448 config: Config{
7449 MaxVersion: VersionTLS13,
7450 Bugs: ProtocolBugs{
7451 SendHelloRequestBeforeEveryHandshakeMessage: true,
7452 },
7453 },
7454 shouldFail: true,
7455 expectedError: ":UNEXPECTED_MESSAGE:",
7456 })
David Benjamind2610042017-01-03 10:49:28 -05007457
7458 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7459 // always reads as supporting it, regardless of whether it was
7460 // negotiated.
7461 testCases = append(testCases, testCase{
7462 name: "AlwaysReportRenegotiationInfo-TLS13",
7463 config: Config{
7464 MaxVersion: VersionTLS13,
7465 Bugs: ProtocolBugs{
7466 NoRenegotiationInfo: true,
7467 },
7468 },
7469 flags: []string{
7470 "-expect-secure-renegotiation",
7471 },
7472 })
David Benjamina58baaf2017-02-28 20:54:28 -05007473
7474 // Certificates may not change on renegotiation.
7475 testCases = append(testCases, testCase{
7476 name: "Renegotiation-CertificateChange",
7477 config: Config{
7478 MaxVersion: VersionTLS12,
7479 Certificates: []Certificate{rsaCertificate},
7480 Bugs: ProtocolBugs{
7481 RenegotiationCertificate: &rsaChainCertificate,
7482 },
7483 },
7484 renegotiate: 1,
7485 flags: []string{"-renegotiate-freely"},
7486 shouldFail: true,
7487 expectedError: ":SERVER_CERT_CHANGED:",
7488 })
7489 testCases = append(testCases, testCase{
7490 name: "Renegotiation-CertificateChange-2",
7491 config: Config{
7492 MaxVersion: VersionTLS12,
7493 Certificates: []Certificate{rsaCertificate},
7494 Bugs: ProtocolBugs{
7495 RenegotiationCertificate: &rsa1024Certificate,
7496 },
7497 },
7498 renegotiate: 1,
7499 flags: []string{"-renegotiate-freely"},
7500 shouldFail: true,
7501 expectedError: ":SERVER_CERT_CHANGED:",
7502 })
David Benjaminbbf42462017-03-14 21:27:10 -04007503
7504 // We do not negotiate ALPN after the initial handshake. This is
7505 // error-prone and only risks bugs in consumers.
7506 testCases = append(testCases, testCase{
7507 testType: clientTest,
7508 name: "Renegotiation-ForbidALPN",
7509 config: Config{
7510 MaxVersion: VersionTLS12,
7511 Bugs: ProtocolBugs{
7512 // Forcibly negotiate ALPN on both initial and
7513 // renegotiation handshakes. The test stack will
7514 // internally check the client does not offer
7515 // it.
7516 SendALPN: "foo",
7517 },
7518 },
7519 flags: []string{
7520 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7521 "-expect-alpn", "foo",
7522 "-renegotiate-freely",
7523 },
7524 renegotiate: 1,
7525 shouldFail: true,
7526 expectedError: ":UNEXPECTED_EXTENSION:",
7527 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007528}
7529
David Benjamin5e961c12014-11-07 01:48:35 -05007530func addDTLSReplayTests() {
7531 // Test that sequence number replays are detected.
7532 testCases = append(testCases, testCase{
7533 protocol: dtls,
7534 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007535 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007536 replayWrites: true,
7537 })
7538
David Benjamin8e6db492015-07-25 18:29:23 -04007539 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007540 // than the retransmit window.
7541 testCases = append(testCases, testCase{
7542 protocol: dtls,
7543 name: "DTLS-Replay-LargeGaps",
7544 config: Config{
7545 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007546 SequenceNumberMapping: func(in uint64) uint64 {
7547 return in * 127
7548 },
David Benjamin5e961c12014-11-07 01:48:35 -05007549 },
7550 },
David Benjamin8e6db492015-07-25 18:29:23 -04007551 messageCount: 200,
7552 replayWrites: true,
7553 })
7554
7555 // Test the incoming sequence number changing non-monotonically.
7556 testCases = append(testCases, testCase{
7557 protocol: dtls,
7558 name: "DTLS-Replay-NonMonotonic",
7559 config: Config{
7560 Bugs: ProtocolBugs{
7561 SequenceNumberMapping: func(in uint64) uint64 {
7562 return in ^ 31
7563 },
7564 },
7565 },
7566 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007567 replayWrites: true,
7568 })
7569}
7570
Nick Harper60edffd2016-06-21 15:19:24 -07007571var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007572 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007573 id signatureAlgorithm
7574 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007575}{
Nick Harper60edffd2016-06-21 15:19:24 -07007576 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7577 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7578 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7579 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007580 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007581 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7582 // hash function doesn't have to match the curve and so the same
7583 // signature algorithm works with P-224.
7584 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007585 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7586 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7587 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007588 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7589 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7590 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007591 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007592 // Tests for key types prior to TLS 1.2.
7593 {"RSA", 0, testCertRSA},
7594 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007595}
7596
Nick Harper60edffd2016-06-21 15:19:24 -07007597const fakeSigAlg1 signatureAlgorithm = 0x2a01
7598const fakeSigAlg2 signatureAlgorithm = 0xff01
7599
7600func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007601 // Not all ciphers involve a signature. Advertise a list which gives all
7602 // versions a signing cipher.
7603 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007604 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007605 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7606 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7607 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7608 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007609 }
David Benjamin5208fd42016-07-13 21:43:25 -04007610
David Benjaminca3d5452016-07-14 12:51:01 -04007611 var allAlgorithms []signatureAlgorithm
7612 for _, alg := range testSignatureAlgorithms {
7613 if alg.id != 0 {
7614 allAlgorithms = append(allAlgorithms, alg.id)
7615 }
7616 }
7617
Nick Harper60edffd2016-06-21 15:19:24 -07007618 // Make sure each signature algorithm works. Include some fake values in
7619 // the list and ensure they're ignored.
7620 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007621 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007622 if (ver.version < VersionTLS12) != (alg.id == 0) {
7623 continue
7624 }
7625
7626 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7627 // or remove it in C.
7628 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007629 continue
7630 }
Nick Harper60edffd2016-06-21 15:19:24 -07007631
David Benjamin3ef76972016-10-17 17:59:54 -04007632 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007633 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007634 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007635 shouldSignFail = true
7636 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007637 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007638 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007639 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7640 shouldSignFail = true
7641 shouldVerifyFail = true
7642 }
7643 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7644 // the curve has to match the hash size.
7645 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007646 shouldSignFail = true
7647 shouldVerifyFail = true
7648 }
7649
7650 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7651 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7652 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007653 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007654
7655 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007656 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007657 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007658 }
7659 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007660 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007661 }
David Benjamin000800a2014-11-14 01:43:59 -05007662
David Benjamin1fb125c2016-07-08 18:52:12 -07007663 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007664
David Benjamin7a41d372016-07-09 11:21:54 -07007665 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007666 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007667 config: Config{
7668 MaxVersion: ver.version,
7669 ClientAuth: RequireAnyClientCert,
7670 VerifySignatureAlgorithms: []signatureAlgorithm{
7671 fakeSigAlg1,
7672 alg.id,
7673 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007674 },
David Benjamin7a41d372016-07-09 11:21:54 -07007675 },
7676 flags: []string{
7677 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7678 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7679 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007680 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007681 },
David Benjamina5022392017-07-10 17:40:39 -04007682 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007683 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007684 expectedError: signError,
7685 expectedPeerSignatureAlgorithm: alg.id,
7686 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007687
David Benjamin7a41d372016-07-09 11:21:54 -07007688 testCases = append(testCases, testCase{
7689 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007690 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007691 config: Config{
7692 MaxVersion: ver.version,
7693 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7694 SignSignatureAlgorithms: []signatureAlgorithm{
7695 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007696 },
David Benjamin7a41d372016-07-09 11:21:54 -07007697 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007698 SkipECDSACurveCheck: shouldVerifyFail,
7699 IgnoreSignatureVersionChecks: shouldVerifyFail,
7700 // Some signature algorithms may not be advertised.
7701 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007702 },
David Benjamin7a41d372016-07-09 11:21:54 -07007703 },
David Benjamina5022392017-07-10 17:40:39 -04007704 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007705 flags: []string{
7706 "-require-any-client-certificate",
7707 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7708 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007709 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007710 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007711 // Resume the session to assert the peer signature
7712 // algorithm is reported on both handshakes.
7713 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007714 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007715 expectedError: verifyError,
7716 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007717
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007718 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007719 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007720 testCases = append(testCases, testCase{
7721 testType: serverTest,
7722 name: "ServerAuth-Sign" + suffix,
7723 config: Config{
7724 MaxVersion: ver.version,
7725 CipherSuites: signingCiphers,
7726 VerifySignatureAlgorithms: []signatureAlgorithm{
7727 fakeSigAlg1,
7728 alg.id,
7729 fakeSigAlg2,
7730 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007731 },
David Benjamina5022392017-07-10 17:40:39 -04007732 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007733 flags: []string{
7734 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7735 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7736 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007737 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007738 },
7739 shouldFail: shouldSignFail,
7740 expectedError: signError,
7741 expectedPeerSignatureAlgorithm: alg.id,
7742 })
7743 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007744
7745 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007746 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007747 config: Config{
7748 MaxVersion: ver.version,
7749 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007750 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007751 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007752 alg.id,
7753 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007754 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007755 SkipECDSACurveCheck: shouldVerifyFail,
7756 IgnoreSignatureVersionChecks: shouldVerifyFail,
7757 // Some signature algorithms may not be advertised.
7758 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007759 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007760 },
David Benjamina5022392017-07-10 17:40:39 -04007761 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007762 flags: []string{
7763 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7764 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007765 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007766 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007767 // Resume the session to assert the peer signature
7768 // algorithm is reported on both handshakes.
7769 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007770 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007771 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007772 })
David Benjamin5208fd42016-07-13 21:43:25 -04007773
David Benjamin3ef76972016-10-17 17:59:54 -04007774 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007775 testCases = append(testCases, testCase{
7776 testType: serverTest,
7777 name: "ClientAuth-InvalidSignature" + suffix,
7778 config: Config{
7779 MaxVersion: ver.version,
7780 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7781 SignSignatureAlgorithms: []signatureAlgorithm{
7782 alg.id,
7783 },
7784 Bugs: ProtocolBugs{
7785 InvalidSignature: true,
7786 },
7787 },
David Benjamina5022392017-07-10 17:40:39 -04007788 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007789 flags: []string{
7790 "-require-any-client-certificate",
7791 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007792 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007793 },
7794 shouldFail: true,
7795 expectedError: ":BAD_SIGNATURE:",
7796 })
7797
7798 testCases = append(testCases, testCase{
7799 name: "ServerAuth-InvalidSignature" + suffix,
7800 config: Config{
7801 MaxVersion: ver.version,
7802 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7803 CipherSuites: signingCiphers,
7804 SignSignatureAlgorithms: []signatureAlgorithm{
7805 alg.id,
7806 },
7807 Bugs: ProtocolBugs{
7808 InvalidSignature: true,
7809 },
7810 },
David Benjamina5022392017-07-10 17:40:39 -04007811 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007812 flags: []string{
7813 "-enable-all-curves",
7814 "-enable-ed25519",
7815 },
David Benjamin5208fd42016-07-13 21:43:25 -04007816 shouldFail: true,
7817 expectedError: ":BAD_SIGNATURE:",
7818 })
7819 }
David Benjaminca3d5452016-07-14 12:51:01 -04007820
David Benjamin3ef76972016-10-17 17:59:54 -04007821 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007822 testCases = append(testCases, testCase{
7823 name: "ClientAuth-Sign-Negotiate" + suffix,
7824 config: Config{
7825 MaxVersion: ver.version,
7826 ClientAuth: RequireAnyClientCert,
7827 VerifySignatureAlgorithms: allAlgorithms,
7828 },
David Benjamina5022392017-07-10 17:40:39 -04007829 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007830 flags: []string{
7831 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7832 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7833 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007834 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007835 "-signing-prefs", strconv.Itoa(int(alg.id)),
7836 },
7837 expectedPeerSignatureAlgorithm: alg.id,
7838 })
7839
7840 testCases = append(testCases, testCase{
7841 testType: serverTest,
7842 name: "ServerAuth-Sign-Negotiate" + suffix,
7843 config: Config{
7844 MaxVersion: ver.version,
7845 CipherSuites: signingCiphers,
7846 VerifySignatureAlgorithms: allAlgorithms,
7847 },
David Benjamina5022392017-07-10 17:40:39 -04007848 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007849 flags: []string{
7850 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7851 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7852 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007853 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007854 "-signing-prefs", strconv.Itoa(int(alg.id)),
7855 },
7856 expectedPeerSignatureAlgorithm: alg.id,
7857 })
7858 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007859 }
David Benjamin000800a2014-11-14 01:43:59 -05007860 }
7861
Nick Harper60edffd2016-06-21 15:19:24 -07007862 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007863 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007864 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007865 config: Config{
7866 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007867 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007868 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007869 signatureECDSAWithP521AndSHA512,
7870 signatureRSAPKCS1WithSHA384,
7871 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007872 },
7873 },
7874 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007875 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7876 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007877 },
Nick Harper60edffd2016-06-21 15:19:24 -07007878 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007879 })
7880
7881 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007882 name: "ClientAuth-SignatureType-TLS13",
7883 config: Config{
7884 ClientAuth: RequireAnyClientCert,
7885 MaxVersion: VersionTLS13,
7886 VerifySignatureAlgorithms: []signatureAlgorithm{
7887 signatureECDSAWithP521AndSHA512,
7888 signatureRSAPKCS1WithSHA384,
7889 signatureRSAPSSWithSHA384,
7890 signatureECDSAWithSHA1,
7891 },
7892 },
7893 flags: []string{
7894 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7895 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7896 },
7897 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7898 })
7899
7900 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007901 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007902 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007904 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007905 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007906 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007907 signatureECDSAWithP521AndSHA512,
7908 signatureRSAPKCS1WithSHA384,
7909 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007910 },
7911 },
Nick Harper60edffd2016-06-21 15:19:24 -07007912 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007913 })
7914
Steven Valdez143e8b32016-07-11 13:19:03 -04007915 testCases = append(testCases, testCase{
7916 testType: serverTest,
7917 name: "ServerAuth-SignatureType-TLS13",
7918 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007919 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007920 VerifySignatureAlgorithms: []signatureAlgorithm{
7921 signatureECDSAWithP521AndSHA512,
7922 signatureRSAPKCS1WithSHA384,
7923 signatureRSAPSSWithSHA384,
7924 signatureECDSAWithSHA1,
7925 },
7926 },
7927 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7928 })
7929
David Benjamina95e9f32016-07-08 16:28:04 -07007930 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007931 testCases = append(testCases, testCase{
7932 testType: serverTest,
7933 name: "Verify-ClientAuth-SignatureType",
7934 config: Config{
7935 MaxVersion: VersionTLS12,
7936 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007937 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007938 signatureRSAPKCS1WithSHA256,
7939 },
7940 Bugs: ProtocolBugs{
7941 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7942 },
7943 },
7944 flags: []string{
7945 "-require-any-client-certificate",
7946 },
7947 shouldFail: true,
7948 expectedError: ":WRONG_SIGNATURE_TYPE:",
7949 })
7950
7951 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007952 testType: serverTest,
7953 name: "Verify-ClientAuth-SignatureType-TLS13",
7954 config: Config{
7955 MaxVersion: VersionTLS13,
7956 Certificates: []Certificate{rsaCertificate},
7957 SignSignatureAlgorithms: []signatureAlgorithm{
7958 signatureRSAPSSWithSHA256,
7959 },
7960 Bugs: ProtocolBugs{
7961 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7962 },
7963 },
7964 flags: []string{
7965 "-require-any-client-certificate",
7966 },
7967 shouldFail: true,
7968 expectedError: ":WRONG_SIGNATURE_TYPE:",
7969 })
7970
7971 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007972 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007973 config: Config{
7974 MaxVersion: VersionTLS12,
7975 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007976 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007977 signatureRSAPKCS1WithSHA256,
7978 },
7979 Bugs: ProtocolBugs{
7980 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7981 },
7982 },
7983 shouldFail: true,
7984 expectedError: ":WRONG_SIGNATURE_TYPE:",
7985 })
7986
Steven Valdez143e8b32016-07-11 13:19:03 -04007987 testCases = append(testCases, testCase{
7988 name: "Verify-ServerAuth-SignatureType-TLS13",
7989 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007990 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007991 SignSignatureAlgorithms: []signatureAlgorithm{
7992 signatureRSAPSSWithSHA256,
7993 },
7994 Bugs: ProtocolBugs{
7995 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7996 },
7997 },
7998 shouldFail: true,
7999 expectedError: ":WRONG_SIGNATURE_TYPE:",
8000 })
8001
David Benjamin51dd7d62016-07-08 16:07:01 -07008002 // Test that, if the list is missing, the peer falls back to SHA-1 in
8003 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008004 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008005 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008007 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008008 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008009 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008010 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008011 },
8012 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008013 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008014 },
8015 },
8016 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008017 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8018 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008019 },
8020 })
8021
8022 testCases = append(testCases, testCase{
8023 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008024 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008025 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008026 MaxVersion: VersionTLS12,
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 },
David Benjaminee32bea2016-08-17 13:36:44 -04008034 flags: []string{
8035 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8036 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8037 },
8038 })
8039
8040 testCases = append(testCases, testCase{
8041 name: "ClientAuth-SHA1-Fallback-ECDSA",
8042 config: Config{
8043 MaxVersion: VersionTLS12,
8044 ClientAuth: RequireAnyClientCert,
8045 VerifySignatureAlgorithms: []signatureAlgorithm{
8046 signatureECDSAWithSHA1,
8047 },
8048 Bugs: ProtocolBugs{
8049 NoSignatureAlgorithms: true,
8050 },
8051 },
8052 flags: []string{
8053 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8054 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8055 },
8056 })
8057
8058 testCases = append(testCases, testCase{
8059 testType: serverTest,
8060 name: "ServerAuth-SHA1-Fallback-ECDSA",
8061 config: Config{
8062 MaxVersion: VersionTLS12,
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 },
David Benjamin000800a2014-11-14 01:43:59 -05008074 })
David Benjamin72dc7832015-03-16 17:49:43 -04008075
David Benjamin51dd7d62016-07-08 16:07:01 -07008076 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008077 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008078 config: Config{
8079 MaxVersion: VersionTLS13,
8080 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008081 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008082 signatureRSAPKCS1WithSHA1,
8083 },
8084 Bugs: ProtocolBugs{
8085 NoSignatureAlgorithms: true,
8086 },
8087 },
8088 flags: []string{
8089 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8090 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8091 },
David Benjamin48901652016-08-01 12:12:47 -04008092 shouldFail: true,
8093 // An empty CertificateRequest signature algorithm list is a
8094 // syntax error in TLS 1.3.
8095 expectedError: ":DECODE_ERROR:",
8096 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008097 })
8098
8099 testCases = append(testCases, testCase{
8100 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008101 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008102 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008103 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008104 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008105 signatureRSAPKCS1WithSHA1,
8106 },
8107 Bugs: ProtocolBugs{
8108 NoSignatureAlgorithms: true,
8109 },
8110 },
8111 shouldFail: true,
8112 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8113 })
8114
David Benjaminb62d2872016-07-18 14:55:02 +02008115 // Test that hash preferences are enforced. BoringSSL does not implement
8116 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008117 testCases = append(testCases, testCase{
8118 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008119 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008121 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008122 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008123 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008124 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008125 },
8126 Bugs: ProtocolBugs{
8127 IgnorePeerSignatureAlgorithmPreferences: true,
8128 },
8129 },
8130 flags: []string{"-require-any-client-certificate"},
8131 shouldFail: true,
8132 expectedError: ":WRONG_SIGNATURE_TYPE:",
8133 })
8134
8135 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008136 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008138 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008139 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008140 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008141 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008142 },
8143 Bugs: ProtocolBugs{
8144 IgnorePeerSignatureAlgorithmPreferences: true,
8145 },
8146 },
8147 shouldFail: true,
8148 expectedError: ":WRONG_SIGNATURE_TYPE:",
8149 })
David Benjaminb62d2872016-07-18 14:55:02 +02008150 testCases = append(testCases, testCase{
8151 testType: serverTest,
8152 name: "ClientAuth-Enforced-TLS13",
8153 config: Config{
8154 MaxVersion: VersionTLS13,
8155 Certificates: []Certificate{rsaCertificate},
8156 SignSignatureAlgorithms: []signatureAlgorithm{
8157 signatureRSAPKCS1WithMD5,
8158 },
8159 Bugs: ProtocolBugs{
8160 IgnorePeerSignatureAlgorithmPreferences: true,
8161 IgnoreSignatureVersionChecks: true,
8162 },
8163 },
8164 flags: []string{"-require-any-client-certificate"},
8165 shouldFail: true,
8166 expectedError: ":WRONG_SIGNATURE_TYPE:",
8167 })
8168
8169 testCases = append(testCases, testCase{
8170 name: "ServerAuth-Enforced-TLS13",
8171 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008172 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008173 SignSignatureAlgorithms: []signatureAlgorithm{
8174 signatureRSAPKCS1WithMD5,
8175 },
8176 Bugs: ProtocolBugs{
8177 IgnorePeerSignatureAlgorithmPreferences: true,
8178 IgnoreSignatureVersionChecks: true,
8179 },
8180 },
8181 shouldFail: true,
8182 expectedError: ":WRONG_SIGNATURE_TYPE:",
8183 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008184
8185 // Test that the agreed upon digest respects the client preferences and
8186 // the server digests.
8187 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008188 name: "NoCommonAlgorithms-Digests",
8189 config: Config{
8190 MaxVersion: VersionTLS12,
8191 ClientAuth: RequireAnyClientCert,
8192 VerifySignatureAlgorithms: []signatureAlgorithm{
8193 signatureRSAPKCS1WithSHA512,
8194 signatureRSAPKCS1WithSHA1,
8195 },
8196 },
8197 flags: []string{
8198 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8199 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8200 "-digest-prefs", "SHA256",
8201 },
8202 shouldFail: true,
8203 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8204 })
8205 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008206 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008207 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008208 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008209 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008210 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008211 signatureRSAPKCS1WithSHA512,
8212 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008213 },
8214 },
8215 flags: []string{
8216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008218 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008219 },
David Benjaminca3d5452016-07-14 12:51:01 -04008220 shouldFail: true,
8221 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8222 })
8223 testCases = append(testCases, testCase{
8224 name: "NoCommonAlgorithms-TLS13",
8225 config: Config{
8226 MaxVersion: VersionTLS13,
8227 ClientAuth: RequireAnyClientCert,
8228 VerifySignatureAlgorithms: []signatureAlgorithm{
8229 signatureRSAPSSWithSHA512,
8230 signatureRSAPSSWithSHA384,
8231 },
8232 },
8233 flags: []string{
8234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8236 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8237 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008238 shouldFail: true,
8239 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008240 })
8241 testCases = append(testCases, testCase{
8242 name: "Agree-Digest-SHA256",
8243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008244 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008245 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008246 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008247 signatureRSAPKCS1WithSHA1,
8248 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008249 },
8250 },
8251 flags: []string{
8252 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8253 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008254 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008255 },
Nick Harper60edffd2016-06-21 15:19:24 -07008256 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008257 })
8258 testCases = append(testCases, testCase{
8259 name: "Agree-Digest-SHA1",
8260 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008261 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008262 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008263 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008264 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008265 },
8266 },
8267 flags: []string{
8268 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8269 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008270 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008271 },
Nick Harper60edffd2016-06-21 15:19:24 -07008272 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008273 })
8274 testCases = append(testCases, testCase{
8275 name: "Agree-Digest-Default",
8276 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008277 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008278 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008279 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008280 signatureRSAPKCS1WithSHA256,
8281 signatureECDSAWithP256AndSHA256,
8282 signatureRSAPKCS1WithSHA1,
8283 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008284 },
8285 },
8286 flags: []string{
8287 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8288 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8289 },
Nick Harper60edffd2016-06-21 15:19:24 -07008290 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008291 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008292
David Benjaminca3d5452016-07-14 12:51:01 -04008293 // Test that the signing preference list may include extra algorithms
8294 // without negotiation problems.
8295 testCases = append(testCases, testCase{
8296 testType: serverTest,
8297 name: "FilterExtraAlgorithms",
8298 config: Config{
8299 MaxVersion: VersionTLS12,
8300 VerifySignatureAlgorithms: []signatureAlgorithm{
8301 signatureRSAPKCS1WithSHA256,
8302 },
8303 },
8304 flags: []string{
8305 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8306 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8307 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8308 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8309 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8310 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8311 },
8312 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8313 })
8314
David Benjamin4c3ddf72016-06-29 18:13:53 -04008315 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8316 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008317 testCases = append(testCases, testCase{
8318 name: "CheckLeafCurve",
8319 config: Config{
8320 MaxVersion: VersionTLS12,
8321 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008322 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008323 },
8324 flags: []string{"-p384-only"},
8325 shouldFail: true,
8326 expectedError: ":BAD_ECC_CERT:",
8327 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008328
8329 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8330 testCases = append(testCases, testCase{
8331 name: "CheckLeafCurve-TLS13",
8332 config: Config{
8333 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008334 Certificates: []Certificate{ecdsaP256Certificate},
8335 },
8336 flags: []string{"-p384-only"},
8337 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008338
8339 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8340 testCases = append(testCases, testCase{
8341 name: "ECDSACurveMismatch-Verify-TLS12",
8342 config: Config{
8343 MaxVersion: VersionTLS12,
8344 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8345 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008346 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008347 signatureECDSAWithP384AndSHA384,
8348 },
8349 },
8350 })
8351
8352 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8353 testCases = append(testCases, testCase{
8354 name: "ECDSACurveMismatch-Verify-TLS13",
8355 config: Config{
8356 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008357 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008358 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008359 signatureECDSAWithP384AndSHA384,
8360 },
8361 Bugs: ProtocolBugs{
8362 SkipECDSACurveCheck: true,
8363 },
8364 },
8365 shouldFail: true,
8366 expectedError: ":WRONG_SIGNATURE_TYPE:",
8367 })
8368
8369 // Signature algorithm selection in TLS 1.3 should take the curve into
8370 // account.
8371 testCases = append(testCases, testCase{
8372 testType: serverTest,
8373 name: "ECDSACurveMismatch-Sign-TLS13",
8374 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008375 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008376 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008377 signatureECDSAWithP384AndSHA384,
8378 signatureECDSAWithP256AndSHA256,
8379 },
8380 },
8381 flags: []string{
8382 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8383 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8384 },
8385 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8386 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008387
8388 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8389 // server does not attempt to sign in that case.
8390 testCases = append(testCases, testCase{
8391 testType: serverTest,
8392 name: "RSA-PSS-Large",
8393 config: Config{
8394 MaxVersion: VersionTLS13,
8395 VerifySignatureAlgorithms: []signatureAlgorithm{
8396 signatureRSAPSSWithSHA512,
8397 },
8398 },
8399 flags: []string{
8400 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8401 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8402 },
8403 shouldFail: true,
8404 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8405 })
David Benjamin57e929f2016-08-30 00:30:38 -04008406
8407 // Test that RSA-PSS is enabled by default for TLS 1.2.
8408 testCases = append(testCases, testCase{
8409 testType: clientTest,
8410 name: "RSA-PSS-Default-Verify",
8411 config: Config{
8412 MaxVersion: VersionTLS12,
8413 SignSignatureAlgorithms: []signatureAlgorithm{
8414 signatureRSAPSSWithSHA256,
8415 },
8416 },
8417 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8418 })
8419
8420 testCases = append(testCases, testCase{
8421 testType: serverTest,
8422 name: "RSA-PSS-Default-Sign",
8423 config: Config{
8424 MaxVersion: VersionTLS12,
8425 VerifySignatureAlgorithms: []signatureAlgorithm{
8426 signatureRSAPSSWithSHA256,
8427 },
8428 },
8429 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8430 })
David Benjamin69522112017-03-28 15:38:29 -05008431
8432 // TLS 1.1 and below has no way to advertise support for or negotiate
8433 // Ed25519's signature algorithm.
8434 testCases = append(testCases, testCase{
8435 testType: clientTest,
8436 name: "NoEd25519-TLS11-ServerAuth-Verify",
8437 config: Config{
8438 MaxVersion: VersionTLS11,
8439 Certificates: []Certificate{ed25519Certificate},
8440 Bugs: ProtocolBugs{
8441 // Sign with Ed25519 even though it is TLS 1.1.
8442 UseLegacySigningAlgorithm: signatureEd25519,
8443 },
8444 },
8445 flags: []string{"-enable-ed25519"},
8446 shouldFail: true,
8447 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8448 })
8449 testCases = append(testCases, testCase{
8450 testType: serverTest,
8451 name: "NoEd25519-TLS11-ServerAuth-Sign",
8452 config: Config{
8453 MaxVersion: VersionTLS11,
8454 },
8455 flags: []string{
8456 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8457 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8458 },
8459 shouldFail: true,
8460 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8461 })
8462 testCases = append(testCases, testCase{
8463 testType: serverTest,
8464 name: "NoEd25519-TLS11-ClientAuth-Verify",
8465 config: Config{
8466 MaxVersion: VersionTLS11,
8467 Certificates: []Certificate{ed25519Certificate},
8468 Bugs: ProtocolBugs{
8469 // Sign with Ed25519 even though it is TLS 1.1.
8470 UseLegacySigningAlgorithm: signatureEd25519,
8471 },
8472 },
8473 flags: []string{
8474 "-enable-ed25519",
8475 "-require-any-client-certificate",
8476 },
8477 shouldFail: true,
8478 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8479 })
8480 testCases = append(testCases, testCase{
8481 testType: clientTest,
8482 name: "NoEd25519-TLS11-ClientAuth-Sign",
8483 config: Config{
8484 MaxVersion: VersionTLS11,
8485 ClientAuth: RequireAnyClientCert,
8486 },
8487 flags: []string{
8488 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8489 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8490 },
8491 shouldFail: true,
8492 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8493 })
8494
8495 // Test Ed25519 is not advertised by default.
8496 testCases = append(testCases, testCase{
8497 testType: clientTest,
8498 name: "Ed25519DefaultDisable-NoAdvertise",
8499 config: Config{
8500 Certificates: []Certificate{ed25519Certificate},
8501 },
8502 shouldFail: true,
8503 expectedLocalError: "tls: no common signature algorithms",
8504 })
8505
8506 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8507 // preferences.
8508 testCases = append(testCases, testCase{
8509 testType: clientTest,
8510 name: "Ed25519DefaultDisable-NoAccept",
8511 config: Config{
8512 Certificates: []Certificate{ed25519Certificate},
8513 Bugs: ProtocolBugs{
8514 IgnorePeerSignatureAlgorithmPreferences: true,
8515 },
8516 },
8517 shouldFail: true,
8518 expectedLocalError: "remote error: illegal parameter",
8519 expectedError: ":WRONG_SIGNATURE_TYPE:",
8520 })
David Benjamin71c21b42017-04-14 17:05:40 -04008521
8522 // Test that configuring verify preferences changes what the client
8523 // advertises.
8524 testCases = append(testCases, testCase{
8525 name: "VerifyPreferences-Advertised",
8526 config: Config{
8527 Certificates: []Certificate{rsaCertificate},
8528 SignSignatureAlgorithms: []signatureAlgorithm{
8529 signatureRSAPSSWithSHA256,
8530 signatureRSAPSSWithSHA384,
8531 signatureRSAPSSWithSHA512,
8532 },
8533 },
8534 flags: []string{
8535 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8536 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8537 },
8538 })
8539
8540 // Test that the client advertises a set which the runner can find
8541 // nothing in common with.
8542 testCases = append(testCases, testCase{
8543 name: "VerifyPreferences-NoCommonAlgorithms",
8544 config: Config{
8545 Certificates: []Certificate{rsaCertificate},
8546 SignSignatureAlgorithms: []signatureAlgorithm{
8547 signatureRSAPSSWithSHA256,
8548 signatureRSAPSSWithSHA512,
8549 },
8550 },
8551 flags: []string{
8552 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8553 },
8554 shouldFail: true,
8555 expectedLocalError: "tls: no common signature algorithms",
8556 })
8557
8558 // Test that the client enforces its preferences when configured.
8559 testCases = append(testCases, testCase{
8560 name: "VerifyPreferences-Enforced",
8561 config: Config{
8562 Certificates: []Certificate{rsaCertificate},
8563 SignSignatureAlgorithms: []signatureAlgorithm{
8564 signatureRSAPSSWithSHA256,
8565 signatureRSAPSSWithSHA512,
8566 },
8567 Bugs: ProtocolBugs{
8568 IgnorePeerSignatureAlgorithmPreferences: true,
8569 },
8570 },
8571 flags: []string{
8572 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8573 },
8574 shouldFail: true,
8575 expectedLocalError: "remote error: illegal parameter",
8576 expectedError: ":WRONG_SIGNATURE_TYPE:",
8577 })
8578
8579 // Test that explicitly configuring Ed25519 is as good as changing the
8580 // boolean toggle.
8581 testCases = append(testCases, testCase{
8582 name: "VerifyPreferences-Ed25519",
8583 config: Config{
8584 Certificates: []Certificate{ed25519Certificate},
8585 },
8586 flags: []string{
8587 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8588 },
8589 })
David Benjamin000800a2014-11-14 01:43:59 -05008590}
8591
David Benjamin83f90402015-01-27 01:09:43 -05008592// timeouts is the retransmit schedule for BoringSSL. It doubles and
8593// caps at 60 seconds. On the 13th timeout, it gives up.
8594var timeouts = []time.Duration{
8595 1 * time.Second,
8596 2 * time.Second,
8597 4 * time.Second,
8598 8 * time.Second,
8599 16 * time.Second,
8600 32 * time.Second,
8601 60 * time.Second,
8602 60 * time.Second,
8603 60 * time.Second,
8604 60 * time.Second,
8605 60 * time.Second,
8606 60 * time.Second,
8607 60 * time.Second,
8608}
8609
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008610// shortTimeouts is an alternate set of timeouts which would occur if the
8611// initial timeout duration was set to 250ms.
8612var shortTimeouts = []time.Duration{
8613 250 * time.Millisecond,
8614 500 * time.Millisecond,
8615 1 * time.Second,
8616 2 * time.Second,
8617 4 * time.Second,
8618 8 * time.Second,
8619 16 * time.Second,
8620 32 * time.Second,
8621 60 * time.Second,
8622 60 * time.Second,
8623 60 * time.Second,
8624 60 * time.Second,
8625 60 * time.Second,
8626}
8627
David Benjamin83f90402015-01-27 01:09:43 -05008628func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008629 // These tests work by coordinating some behavior on both the shim and
8630 // the runner.
8631 //
8632 // TimeoutSchedule configures the runner to send a series of timeout
8633 // opcodes to the shim (see packetAdaptor) immediately before reading
8634 // each peer handshake flight N. The timeout opcode both simulates a
8635 // timeout in the shim and acts as a synchronization point to help the
8636 // runner bracket each handshake flight.
8637 //
8638 // We assume the shim does not read from the channel eagerly. It must
8639 // first wait until it has sent flight N and is ready to receive
8640 // handshake flight N+1. At this point, it will process the timeout
8641 // opcode. It must then immediately respond with a timeout ACK and act
8642 // as if the shim was idle for the specified amount of time.
8643 //
8644 // The runner then drops all packets received before the ACK and
8645 // continues waiting for flight N. This ordering results in one attempt
8646 // at sending flight N to be dropped. For the test to complete, the
8647 // shim must send flight N again, testing that the shim implements DTLS
8648 // retransmit on a timeout.
8649
Steven Valdez143e8b32016-07-11 13:19:03 -04008650 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008651 // likely be more epochs to cross and the final message's retransmit may
8652 // be more complex.
8653
David Benjamin11c82892017-02-23 20:40:31 -05008654 // Test that this is indeed the timeout schedule. Stress all
8655 // four patterns of handshake.
8656 for i := 1; i < len(timeouts); i++ {
8657 number := strconv.Itoa(i)
8658 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008659 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008660 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008661 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008662 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008663 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008664 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008665 },
8666 },
8667 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008668 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008669 })
David Benjamin11c82892017-02-23 20:40:31 -05008670 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008671 protocol: dtls,
8672 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008673 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008675 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008676 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008677 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008678 },
8679 },
8680 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008681 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008682 })
8683 }
David Benjamin11c82892017-02-23 20:40:31 -05008684
8685 // Test that exceeding the timeout schedule hits a read
8686 // timeout.
8687 testCases = append(testCases, testCase{
8688 protocol: dtls,
8689 name: "DTLS-Retransmit-Timeout",
8690 config: Config{
8691 MaxVersion: VersionTLS12,
8692 Bugs: ProtocolBugs{
8693 TimeoutSchedule: timeouts,
8694 },
8695 },
8696 resumeSession: true,
8697 flags: []string{"-async"},
8698 shouldFail: true,
8699 expectedError: ":READ_TIMEOUT_EXPIRED:",
8700 })
8701
8702 // Test that timeout handling has a fudge factor, due to API
8703 // problems.
8704 testCases = append(testCases, testCase{
8705 protocol: dtls,
8706 name: "DTLS-Retransmit-Fudge",
8707 config: Config{
8708 MaxVersion: VersionTLS12,
8709 Bugs: ProtocolBugs{
8710 TimeoutSchedule: []time.Duration{
8711 timeouts[0] - 10*time.Millisecond,
8712 },
8713 },
8714 },
8715 resumeSession: true,
8716 flags: []string{"-async"},
8717 })
8718
8719 // Test that the final Finished retransmitting isn't
8720 // duplicated if the peer badly fragments everything.
8721 testCases = append(testCases, testCase{
8722 testType: serverTest,
8723 protocol: dtls,
8724 name: "DTLS-Retransmit-Fragmented",
8725 config: Config{
8726 MaxVersion: VersionTLS12,
8727 Bugs: ProtocolBugs{
8728 TimeoutSchedule: []time.Duration{timeouts[0]},
8729 MaxHandshakeRecordLength: 2,
8730 },
8731 },
8732 flags: []string{"-async"},
8733 })
8734
8735 // Test the timeout schedule when a shorter initial timeout duration is set.
8736 testCases = append(testCases, testCase{
8737 protocol: dtls,
8738 name: "DTLS-Retransmit-Short-Client",
8739 config: Config{
8740 MaxVersion: VersionTLS12,
8741 Bugs: ProtocolBugs{
8742 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8743 },
8744 },
8745 resumeSession: true,
8746 flags: []string{
8747 "-async",
8748 "-initial-timeout-duration-ms", "250",
8749 },
8750 })
8751 testCases = append(testCases, testCase{
8752 protocol: dtls,
8753 testType: serverTest,
8754 name: "DTLS-Retransmit-Short-Server",
8755 config: Config{
8756 MaxVersion: VersionTLS12,
8757 Bugs: ProtocolBugs{
8758 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8759 },
8760 },
8761 resumeSession: true,
8762 flags: []string{
8763 "-async",
8764 "-initial-timeout-duration-ms", "250",
8765 },
8766 })
David Benjamin83f90402015-01-27 01:09:43 -05008767}
8768
David Benjaminc565ebb2015-04-03 04:06:36 -04008769func addExportKeyingMaterialTests() {
8770 for _, vers := range tlsVersions {
8771 if vers.version == VersionSSL30 {
8772 continue
8773 }
8774 testCases = append(testCases, testCase{
8775 name: "ExportKeyingMaterial-" + vers.name,
8776 config: Config{
8777 MaxVersion: vers.version,
8778 },
David Benjamina5022392017-07-10 17:40:39 -04008779 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008780 exportKeyingMaterial: 1024,
8781 exportLabel: "label",
8782 exportContext: "context",
8783 useExportContext: true,
8784 })
8785 testCases = append(testCases, testCase{
8786 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8787 config: Config{
8788 MaxVersion: vers.version,
8789 },
David Benjamina5022392017-07-10 17:40:39 -04008790 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008791 exportKeyingMaterial: 1024,
8792 })
8793 testCases = append(testCases, testCase{
8794 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8795 config: Config{
8796 MaxVersion: vers.version,
8797 },
David Benjamina5022392017-07-10 17:40:39 -04008798 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008799 exportKeyingMaterial: 1024,
8800 useExportContext: true,
8801 })
8802 testCases = append(testCases, testCase{
8803 name: "ExportKeyingMaterial-Small-" + vers.name,
8804 config: Config{
8805 MaxVersion: vers.version,
8806 },
David Benjamina5022392017-07-10 17:40:39 -04008807 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008808 exportKeyingMaterial: 1,
8809 exportLabel: "label",
8810 exportContext: "context",
8811 useExportContext: true,
8812 })
8813 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008814
David Benjaminc565ebb2015-04-03 04:06:36 -04008815 testCases = append(testCases, testCase{
8816 name: "ExportKeyingMaterial-SSL3",
8817 config: Config{
8818 MaxVersion: VersionSSL30,
8819 },
8820 exportKeyingMaterial: 1024,
8821 exportLabel: "label",
8822 exportContext: "context",
8823 useExportContext: true,
8824 shouldFail: true,
8825 expectedError: "failed to export keying material",
8826 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008827
8828 // Exporters work during a False Start.
8829 testCases = append(testCases, testCase{
8830 name: "ExportKeyingMaterial-FalseStart",
8831 config: Config{
8832 MaxVersion: VersionTLS12,
8833 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8834 NextProtos: []string{"foo"},
8835 Bugs: ProtocolBugs{
8836 ExpectFalseStart: true,
8837 },
8838 },
8839 flags: []string{
8840 "-false-start",
8841 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008842 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008843 },
8844 shimWritesFirst: true,
8845 exportKeyingMaterial: 1024,
8846 exportLabel: "label",
8847 exportContext: "context",
8848 useExportContext: true,
8849 })
8850
8851 // Exporters do not work in the middle of a renegotiation. Test this by
8852 // triggering the exporter after every SSL_read call and configuring the
8853 // shim to run asynchronously.
8854 testCases = append(testCases, testCase{
8855 name: "ExportKeyingMaterial-Renegotiate",
8856 config: Config{
8857 MaxVersion: VersionTLS12,
8858 },
8859 renegotiate: 1,
8860 flags: []string{
8861 "-async",
8862 "-use-exporter-between-reads",
8863 "-renegotiate-freely",
8864 "-expect-total-renegotiations", "1",
8865 },
8866 shouldFail: true,
8867 expectedError: "failed to export keying material",
8868 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008869}
8870
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008871func addTLSUniqueTests() {
8872 for _, isClient := range []bool{false, true} {
8873 for _, isResumption := range []bool{false, true} {
8874 for _, hasEMS := range []bool{false, true} {
8875 var suffix string
8876 if isResumption {
8877 suffix = "Resume-"
8878 } else {
8879 suffix = "Full-"
8880 }
8881
8882 if hasEMS {
8883 suffix += "EMS-"
8884 } else {
8885 suffix += "NoEMS-"
8886 }
8887
8888 if isClient {
8889 suffix += "Client"
8890 } else {
8891 suffix += "Server"
8892 }
8893
8894 test := testCase{
8895 name: "TLSUnique-" + suffix,
8896 testTLSUnique: true,
8897 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008898 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008899 Bugs: ProtocolBugs{
8900 NoExtendedMasterSecret: !hasEMS,
8901 },
8902 },
8903 }
8904
8905 if isResumption {
8906 test.resumeSession = true
8907 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008908 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008909 Bugs: ProtocolBugs{
8910 NoExtendedMasterSecret: !hasEMS,
8911 },
8912 }
8913 }
8914
8915 if isResumption && !hasEMS {
8916 test.shouldFail = true
8917 test.expectedError = "failed to get tls-unique"
8918 }
8919
8920 testCases = append(testCases, test)
8921 }
8922 }
8923 }
8924}
8925
Adam Langley09505632015-07-30 18:10:13 -07008926func addCustomExtensionTests() {
8927 expectedContents := "custom extension"
8928 emptyString := ""
8929
8930 for _, isClient := range []bool{false, true} {
8931 suffix := "Server"
8932 flag := "-enable-server-custom-extension"
8933 testType := serverTest
8934 if isClient {
8935 suffix = "Client"
8936 flag = "-enable-client-custom-extension"
8937 testType = clientTest
8938 }
8939
8940 testCases = append(testCases, testCase{
8941 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008942 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008943 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008944 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008945 Bugs: ProtocolBugs{
8946 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008947 ExpectedCustomExtension: &expectedContents,
8948 },
8949 },
8950 flags: []string{flag},
8951 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008952 testCases = append(testCases, testCase{
8953 testType: testType,
8954 name: "CustomExtensions-" + suffix + "-TLS13",
8955 config: Config{
8956 MaxVersion: VersionTLS13,
8957 Bugs: ProtocolBugs{
8958 CustomExtension: expectedContents,
8959 ExpectedCustomExtension: &expectedContents,
8960 },
8961 },
8962 flags: []string{flag},
8963 })
Adam Langley09505632015-07-30 18:10:13 -07008964
Steven Valdez2a070722017-03-25 20:54:16 -05008965 // 0-RTT is not currently supported with Custom Extensions.
8966 testCases = append(testCases, testCase{
8967 testType: testType,
8968 name: "CustomExtensions-" + suffix + "-EarlyData",
8969 config: Config{
8970 MaxVersion: VersionTLS13,
8971 Bugs: ProtocolBugs{
8972 CustomExtension: expectedContents,
8973 ExpectedCustomExtension: &expectedContents,
8974 },
8975 },
8976 shouldFail: true,
8977 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8978 flags: []string{flag, "-enable-early-data"},
8979 })
8980
Adam Langley09505632015-07-30 18:10:13 -07008981 // If the parse callback fails, the handshake should also fail.
8982 testCases = append(testCases, testCase{
8983 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008984 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008985 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008986 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008987 Bugs: ProtocolBugs{
8988 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008989 ExpectedCustomExtension: &expectedContents,
8990 },
8991 },
David Benjamin399e7c92015-07-30 23:01:27 -04008992 flags: []string{flag},
8993 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008994 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8995 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008996 testCases = append(testCases, testCase{
8997 testType: testType,
8998 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8999 config: Config{
9000 MaxVersion: VersionTLS13,
9001 Bugs: ProtocolBugs{
9002 CustomExtension: expectedContents + "foo",
9003 ExpectedCustomExtension: &expectedContents,
9004 },
9005 },
9006 flags: []string{flag},
9007 shouldFail: true,
9008 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9009 })
Adam Langley09505632015-07-30 18:10:13 -07009010
9011 // If the add callback fails, the handshake should also fail.
9012 testCases = append(testCases, testCase{
9013 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009014 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009015 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009016 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009017 Bugs: ProtocolBugs{
9018 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009019 ExpectedCustomExtension: &expectedContents,
9020 },
9021 },
David Benjamin399e7c92015-07-30 23:01:27 -04009022 flags: []string{flag, "-custom-extension-fail-add"},
9023 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009024 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9025 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009026 testCases = append(testCases, testCase{
9027 testType: testType,
9028 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9029 config: Config{
9030 MaxVersion: VersionTLS13,
9031 Bugs: ProtocolBugs{
9032 CustomExtension: expectedContents,
9033 ExpectedCustomExtension: &expectedContents,
9034 },
9035 },
9036 flags: []string{flag, "-custom-extension-fail-add"},
9037 shouldFail: true,
9038 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9039 })
Adam Langley09505632015-07-30 18:10:13 -07009040
9041 // If the add callback returns zero, no extension should be
9042 // added.
9043 skipCustomExtension := expectedContents
9044 if isClient {
9045 // For the case where the client skips sending the
9046 // custom extension, the server must not “echo” it.
9047 skipCustomExtension = ""
9048 }
9049 testCases = append(testCases, testCase{
9050 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009051 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009052 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009053 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009054 Bugs: ProtocolBugs{
9055 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009056 ExpectedCustomExtension: &emptyString,
9057 },
9058 },
9059 flags: []string{flag, "-custom-extension-skip"},
9060 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009061 testCases = append(testCases, testCase{
9062 testType: testType,
9063 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9064 config: Config{
9065 MaxVersion: VersionTLS13,
9066 Bugs: ProtocolBugs{
9067 CustomExtension: skipCustomExtension,
9068 ExpectedCustomExtension: &emptyString,
9069 },
9070 },
9071 flags: []string{flag, "-custom-extension-skip"},
9072 })
Adam Langley09505632015-07-30 18:10:13 -07009073 }
9074
9075 // The custom extension add callback should not be called if the client
9076 // doesn't send the extension.
9077 testCases = append(testCases, testCase{
9078 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009079 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009081 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009082 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009083 ExpectedCustomExtension: &emptyString,
9084 },
9085 },
9086 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9087 })
Adam Langley2deb9842015-08-07 11:15:37 -07009088
Steven Valdez143e8b32016-07-11 13:19:03 -04009089 testCases = append(testCases, testCase{
9090 testType: serverTest,
9091 name: "CustomExtensions-NotCalled-Server-TLS13",
9092 config: Config{
9093 MaxVersion: VersionTLS13,
9094 Bugs: ProtocolBugs{
9095 ExpectedCustomExtension: &emptyString,
9096 },
9097 },
9098 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9099 })
9100
Adam Langley2deb9842015-08-07 11:15:37 -07009101 // Test an unknown extension from the server.
9102 testCases = append(testCases, testCase{
9103 testType: clientTest,
9104 name: "UnknownExtension-Client",
9105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009106 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009107 Bugs: ProtocolBugs{
9108 CustomExtension: expectedContents,
9109 },
9110 },
David Benjamin0c40a962016-08-01 12:05:50 -04009111 shouldFail: true,
9112 expectedError: ":UNEXPECTED_EXTENSION:",
9113 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009114 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009115 testCases = append(testCases, testCase{
9116 testType: clientTest,
9117 name: "UnknownExtension-Client-TLS13",
9118 config: Config{
9119 MaxVersion: VersionTLS13,
9120 Bugs: ProtocolBugs{
9121 CustomExtension: expectedContents,
9122 },
9123 },
David Benjamin0c40a962016-08-01 12:05:50 -04009124 shouldFail: true,
9125 expectedError: ":UNEXPECTED_EXTENSION:",
9126 expectedLocalError: "remote error: unsupported extension",
9127 })
David Benjamin490469f2016-10-05 22:44:38 -04009128 testCases = append(testCases, testCase{
9129 testType: clientTest,
9130 name: "UnknownUnencryptedExtension-Client-TLS13",
9131 config: Config{
9132 MaxVersion: VersionTLS13,
9133 Bugs: ProtocolBugs{
9134 CustomUnencryptedExtension: expectedContents,
9135 },
9136 },
9137 shouldFail: true,
9138 expectedError: ":UNEXPECTED_EXTENSION:",
9139 // The shim must send an alert, but alerts at this point do not
9140 // get successfully decrypted by the runner.
9141 expectedLocalError: "local error: bad record MAC",
9142 })
9143 testCases = append(testCases, testCase{
9144 testType: clientTest,
9145 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9146 config: Config{
9147 MaxVersion: VersionTLS13,
9148 Bugs: ProtocolBugs{
9149 SendUnencryptedALPN: "foo",
9150 },
9151 },
9152 flags: []string{
9153 "-advertise-alpn", "\x03foo\x03bar",
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 })
David Benjamin0c40a962016-08-01 12:05:50 -04009161
9162 // Test a known but unoffered extension from the server.
9163 testCases = append(testCases, testCase{
9164 testType: clientTest,
9165 name: "UnofferedExtension-Client",
9166 config: Config{
9167 MaxVersion: VersionTLS12,
9168 Bugs: ProtocolBugs{
9169 SendALPN: "alpn",
9170 },
9171 },
9172 shouldFail: true,
9173 expectedError: ":UNEXPECTED_EXTENSION:",
9174 expectedLocalError: "remote error: unsupported extension",
9175 })
9176 testCases = append(testCases, testCase{
9177 testType: clientTest,
9178 name: "UnofferedExtension-Client-TLS13",
9179 config: Config{
9180 MaxVersion: VersionTLS13,
9181 Bugs: ProtocolBugs{
9182 SendALPN: "alpn",
9183 },
9184 },
9185 shouldFail: true,
9186 expectedError: ":UNEXPECTED_EXTENSION:",
9187 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009188 })
Adam Langley09505632015-07-30 18:10:13 -07009189}
9190
David Benjaminb36a3952015-12-01 18:53:13 -05009191func addRSAClientKeyExchangeTests() {
9192 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9193 testCases = append(testCases, testCase{
9194 testType: serverTest,
9195 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9196 config: Config{
9197 // Ensure the ClientHello version and final
9198 // version are different, to detect if the
9199 // server uses the wrong one.
9200 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009201 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009202 Bugs: ProtocolBugs{
9203 BadRSAClientKeyExchange: bad,
9204 },
9205 },
9206 shouldFail: true,
9207 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9208 })
9209 }
David Benjamine63d9d72016-09-19 18:27:34 -04009210
9211 // The server must compare whatever was in ClientHello.version for the
9212 // RSA premaster.
9213 testCases = append(testCases, testCase{
9214 testType: serverTest,
9215 name: "SendClientVersion-RSA",
9216 config: Config{
9217 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9218 Bugs: ProtocolBugs{
9219 SendClientVersion: 0x1234,
9220 },
9221 },
9222 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9223 })
David Benjaminb36a3952015-12-01 18:53:13 -05009224}
9225
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009226var testCurves = []struct {
9227 name string
9228 id CurveID
9229}{
Adam Langley764ab982017-03-10 18:01:30 -08009230 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009231 {"P-256", CurveP256},
9232 {"P-384", CurveP384},
9233 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009234 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009235}
9236
Steven Valdez5440fe02016-07-18 12:40:30 -04009237const bogusCurve = 0x1234
9238
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009239func addCurveTests() {
9240 for _, curve := range testCurves {
9241 testCases = append(testCases, testCase{
9242 name: "CurveTest-Client-" + curve.name,
9243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009244 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009245 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9246 CurvePreferences: []CurveID{curve.id},
9247 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009248 flags: []string{
9249 "-enable-all-curves",
9250 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9251 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009252 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009253 })
9254 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009255 name: "CurveTest-Client-" + curve.name + "-TLS13",
9256 config: Config{
9257 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009258 CurvePreferences: []CurveID{curve.id},
9259 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009260 flags: []string{
9261 "-enable-all-curves",
9262 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9263 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009264 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009265 })
9266 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009267 testType: serverTest,
9268 name: "CurveTest-Server-" + curve.name,
9269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009270 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009271 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9272 CurvePreferences: []CurveID{curve.id},
9273 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009274 flags: []string{
9275 "-enable-all-curves",
9276 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9277 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009278 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009279 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009280 testCases = append(testCases, testCase{
9281 testType: serverTest,
9282 name: "CurveTest-Server-" + curve.name + "-TLS13",
9283 config: Config{
9284 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009285 CurvePreferences: []CurveID{curve.id},
9286 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009287 flags: []string{
9288 "-enable-all-curves",
9289 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9290 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009291 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009292 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009293 }
David Benjamin241ae832016-01-15 03:04:54 -05009294
9295 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009296 testCases = append(testCases, testCase{
9297 testType: serverTest,
9298 name: "UnknownCurve",
9299 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009300 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009301 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9302 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9303 },
9304 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009305
Steven Valdez803c77a2016-09-06 14:13:43 -04009306 // The server must be tolerant to bogus curves.
9307 testCases = append(testCases, testCase{
9308 testType: serverTest,
9309 name: "UnknownCurve-TLS13",
9310 config: Config{
9311 MaxVersion: VersionTLS13,
9312 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9313 },
9314 })
9315
David Benjamin4c3ddf72016-06-29 18:13:53 -04009316 // The server must not consider ECDHE ciphers when there are no
9317 // supported curves.
9318 testCases = append(testCases, testCase{
9319 testType: serverTest,
9320 name: "NoSupportedCurves",
9321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009322 MaxVersion: VersionTLS12,
9323 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9324 Bugs: ProtocolBugs{
9325 NoSupportedCurves: true,
9326 },
9327 },
9328 shouldFail: true,
9329 expectedError: ":NO_SHARED_CIPHER:",
9330 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009331 testCases = append(testCases, testCase{
9332 testType: serverTest,
9333 name: "NoSupportedCurves-TLS13",
9334 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009335 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009336 Bugs: ProtocolBugs{
9337 NoSupportedCurves: true,
9338 },
9339 },
9340 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009341 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009342 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009343
9344 // The server must fall back to another cipher when there are no
9345 // supported curves.
9346 testCases = append(testCases, testCase{
9347 testType: serverTest,
9348 name: "NoCommonCurves",
9349 config: Config{
9350 MaxVersion: VersionTLS12,
9351 CipherSuites: []uint16{
9352 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009353 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009354 },
9355 CurvePreferences: []CurveID{CurveP224},
9356 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009357 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009358 })
9359
9360 // The client must reject bogus curves and disabled curves.
9361 testCases = append(testCases, testCase{
9362 name: "BadECDHECurve",
9363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009364 MaxVersion: VersionTLS12,
9365 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9366 Bugs: ProtocolBugs{
9367 SendCurve: bogusCurve,
9368 },
9369 },
9370 shouldFail: true,
9371 expectedError: ":WRONG_CURVE:",
9372 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009373 testCases = append(testCases, testCase{
9374 name: "BadECDHECurve-TLS13",
9375 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009376 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009377 Bugs: ProtocolBugs{
9378 SendCurve: bogusCurve,
9379 },
9380 },
9381 shouldFail: true,
9382 expectedError: ":WRONG_CURVE:",
9383 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009384
9385 testCases = append(testCases, testCase{
9386 name: "UnsupportedCurve",
9387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009388 MaxVersion: VersionTLS12,
9389 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9390 CurvePreferences: []CurveID{CurveP256},
9391 Bugs: ProtocolBugs{
9392 IgnorePeerCurvePreferences: true,
9393 },
9394 },
9395 flags: []string{"-p384-only"},
9396 shouldFail: true,
9397 expectedError: ":WRONG_CURVE:",
9398 })
9399
David Benjamin4f921572016-07-17 14:20:10 +02009400 testCases = append(testCases, testCase{
9401 // TODO(davidben): Add a TLS 1.3 version where
9402 // HelloRetryRequest requests an unsupported curve.
9403 name: "UnsupportedCurve-ServerHello-TLS13",
9404 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009405 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009406 CurvePreferences: []CurveID{CurveP384},
9407 Bugs: ProtocolBugs{
9408 SendCurve: CurveP256,
9409 },
9410 },
9411 flags: []string{"-p384-only"},
9412 shouldFail: true,
9413 expectedError: ":WRONG_CURVE:",
9414 })
9415
David Benjamin4c3ddf72016-06-29 18:13:53 -04009416 // Test invalid curve points.
9417 testCases = append(testCases, testCase{
9418 name: "InvalidECDHPoint-Client",
9419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009420 MaxVersion: VersionTLS12,
9421 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9422 CurvePreferences: []CurveID{CurveP256},
9423 Bugs: ProtocolBugs{
9424 InvalidECDHPoint: true,
9425 },
9426 },
9427 shouldFail: true,
9428 expectedError: ":INVALID_ENCODING:",
9429 })
9430 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009431 name: "InvalidECDHPoint-Client-TLS13",
9432 config: Config{
9433 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009434 CurvePreferences: []CurveID{CurveP256},
9435 Bugs: ProtocolBugs{
9436 InvalidECDHPoint: true,
9437 },
9438 },
9439 shouldFail: true,
9440 expectedError: ":INVALID_ENCODING:",
9441 })
9442 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009443 testType: serverTest,
9444 name: "InvalidECDHPoint-Server",
9445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009446 MaxVersion: VersionTLS12,
9447 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9448 CurvePreferences: []CurveID{CurveP256},
9449 Bugs: ProtocolBugs{
9450 InvalidECDHPoint: true,
9451 },
9452 },
9453 shouldFail: true,
9454 expectedError: ":INVALID_ENCODING:",
9455 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009456 testCases = append(testCases, testCase{
9457 testType: serverTest,
9458 name: "InvalidECDHPoint-Server-TLS13",
9459 config: Config{
9460 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009461 CurvePreferences: []CurveID{CurveP256},
9462 Bugs: ProtocolBugs{
9463 InvalidECDHPoint: true,
9464 },
9465 },
9466 shouldFail: true,
9467 expectedError: ":INVALID_ENCODING:",
9468 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009469
9470 // The previous curve ID should be reported on TLS 1.2 resumption.
9471 testCases = append(testCases, testCase{
9472 name: "CurveID-Resume-Client",
9473 config: Config{
9474 MaxVersion: VersionTLS12,
9475 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9476 CurvePreferences: []CurveID{CurveX25519},
9477 },
9478 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9479 resumeSession: true,
9480 })
9481 testCases = append(testCases, testCase{
9482 testType: serverTest,
9483 name: "CurveID-Resume-Server",
9484 config: Config{
9485 MaxVersion: VersionTLS12,
9486 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9487 CurvePreferences: []CurveID{CurveX25519},
9488 },
9489 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9490 resumeSession: true,
9491 })
9492
9493 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9494 // one should be reported.
9495 testCases = append(testCases, testCase{
9496 name: "CurveID-Resume-Client-TLS13",
9497 config: Config{
9498 MaxVersion: VersionTLS13,
9499 CurvePreferences: []CurveID{CurveX25519},
9500 },
9501 resumeConfig: &Config{
9502 MaxVersion: VersionTLS13,
9503 CurvePreferences: []CurveID{CurveP256},
9504 },
9505 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009506 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9507 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009508 },
9509 resumeSession: true,
9510 })
9511 testCases = append(testCases, testCase{
9512 testType: serverTest,
9513 name: "CurveID-Resume-Server-TLS13",
9514 config: Config{
9515 MaxVersion: VersionTLS13,
9516 CurvePreferences: []CurveID{CurveX25519},
9517 },
9518 resumeConfig: &Config{
9519 MaxVersion: VersionTLS13,
9520 CurvePreferences: []CurveID{CurveP256},
9521 },
9522 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009523 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9524 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009525 },
9526 resumeSession: true,
9527 })
David Benjamina81967b2016-12-22 09:16:57 -05009528
9529 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9530 testCases = append(testCases, testCase{
9531 name: "PointFormat-ServerHello-TLS12",
9532 config: Config{
9533 MaxVersion: VersionTLS12,
9534 Bugs: ProtocolBugs{
9535 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9536 },
9537 },
9538 })
9539 testCases = append(testCases, testCase{
9540 name: "PointFormat-EncryptedExtensions-TLS13",
9541 config: Config{
9542 MaxVersion: VersionTLS13,
9543 Bugs: ProtocolBugs{
9544 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9545 },
9546 },
9547 shouldFail: true,
9548 expectedError: ":ERROR_PARSING_EXTENSION:",
9549 })
9550
9551 // Test that we tolerate unknown point formats, as long as
9552 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9553 // check they are still functional.
9554 testCases = append(testCases, testCase{
9555 name: "PointFormat-Client-Tolerance",
9556 config: Config{
9557 MaxVersion: VersionTLS12,
9558 Bugs: ProtocolBugs{
9559 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9560 },
9561 },
9562 })
9563 testCases = append(testCases, testCase{
9564 testType: serverTest,
9565 name: "PointFormat-Server-Tolerance",
9566 config: Config{
9567 MaxVersion: VersionTLS12,
9568 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9569 Bugs: ProtocolBugs{
9570 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9571 },
9572 },
9573 })
9574
9575 // Test TLS 1.2 does not require the point format extension to be
9576 // present.
9577 testCases = append(testCases, testCase{
9578 name: "PointFormat-Client-Missing",
9579 config: Config{
9580 MaxVersion: VersionTLS12,
9581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9582 Bugs: ProtocolBugs{
9583 SendSupportedPointFormats: []byte{},
9584 },
9585 },
9586 })
9587 testCases = append(testCases, testCase{
9588 testType: serverTest,
9589 name: "PointFormat-Server-Missing",
9590 config: Config{
9591 MaxVersion: VersionTLS12,
9592 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9593 Bugs: ProtocolBugs{
9594 SendSupportedPointFormats: []byte{},
9595 },
9596 },
9597 })
9598
9599 // If the point format extension is present, uncompressed points must be
9600 // offered. BoringSSL requires this whether or not ECDHE is used.
9601 testCases = append(testCases, testCase{
9602 name: "PointFormat-Client-MissingUncompressed",
9603 config: Config{
9604 MaxVersion: VersionTLS12,
9605 Bugs: ProtocolBugs{
9606 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9607 },
9608 },
9609 shouldFail: true,
9610 expectedError: ":ERROR_PARSING_EXTENSION:",
9611 })
9612 testCases = append(testCases, testCase{
9613 testType: serverTest,
9614 name: "PointFormat-Server-MissingUncompressed",
9615 config: Config{
9616 MaxVersion: VersionTLS12,
9617 Bugs: ProtocolBugs{
9618 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9619 },
9620 },
9621 shouldFail: true,
9622 expectedError: ":ERROR_PARSING_EXTENSION:",
9623 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009624}
9625
David Benjaminc9ae27c2016-06-24 22:56:37 -04009626func addTLS13RecordTests() {
9627 testCases = append(testCases, testCase{
9628 name: "TLS13-RecordPadding",
9629 config: Config{
9630 MaxVersion: VersionTLS13,
9631 MinVersion: VersionTLS13,
9632 Bugs: ProtocolBugs{
9633 RecordPadding: 10,
9634 },
9635 },
9636 })
9637
9638 testCases = append(testCases, testCase{
9639 name: "TLS13-EmptyRecords",
9640 config: Config{
9641 MaxVersion: VersionTLS13,
9642 MinVersion: VersionTLS13,
9643 Bugs: ProtocolBugs{
9644 OmitRecordContents: true,
9645 },
9646 },
9647 shouldFail: true,
9648 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9649 })
9650
9651 testCases = append(testCases, testCase{
9652 name: "TLS13-OnlyPadding",
9653 config: Config{
9654 MaxVersion: VersionTLS13,
9655 MinVersion: VersionTLS13,
9656 Bugs: ProtocolBugs{
9657 OmitRecordContents: true,
9658 RecordPadding: 10,
9659 },
9660 },
9661 shouldFail: true,
9662 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9663 })
9664
9665 testCases = append(testCases, testCase{
9666 name: "TLS13-WrongOuterRecord",
9667 config: Config{
9668 MaxVersion: VersionTLS13,
9669 MinVersion: VersionTLS13,
9670 Bugs: ProtocolBugs{
9671 OuterRecordType: recordTypeHandshake,
9672 },
9673 },
9674 shouldFail: true,
9675 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9676 })
9677}
9678
Steven Valdez5b986082016-09-01 12:29:49 -04009679func addSessionTicketTests() {
9680 testCases = append(testCases, testCase{
9681 // In TLS 1.2 and below, empty NewSessionTicket messages
9682 // mean the server changed its mind on sending a ticket.
9683 name: "SendEmptySessionTicket",
9684 config: Config{
9685 MaxVersion: VersionTLS12,
9686 Bugs: ProtocolBugs{
9687 SendEmptySessionTicket: true,
9688 },
9689 },
9690 flags: []string{"-expect-no-session"},
9691 })
9692
9693 // Test that the server ignores unknown PSK modes.
9694 testCases = append(testCases, testCase{
9695 testType: serverTest,
9696 name: "TLS13-SendUnknownModeSessionTicket-Server",
9697 config: Config{
9698 MaxVersion: VersionTLS13,
9699 Bugs: ProtocolBugs{
9700 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009701 },
9702 },
9703 resumeSession: true,
9704 expectedResumeVersion: VersionTLS13,
9705 })
9706
Steven Valdeza833c352016-11-01 13:39:36 -04009707 // Test that the server does not send session tickets with no matching key exchange mode.
9708 testCases = append(testCases, testCase{
9709 testType: serverTest,
9710 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9711 config: Config{
9712 MaxVersion: VersionTLS13,
9713 Bugs: ProtocolBugs{
9714 SendPSKKeyExchangeModes: []byte{0x1a},
9715 ExpectNoNewSessionTicket: true,
9716 },
9717 },
9718 })
9719
9720 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009721 testCases = append(testCases, testCase{
9722 testType: serverTest,
9723 name: "TLS13-SendBadKEModeSessionTicket-Server",
9724 config: Config{
9725 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009726 },
9727 resumeConfig: &Config{
9728 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009729 Bugs: ProtocolBugs{
9730 SendPSKKeyExchangeModes: []byte{0x1a},
9731 },
9732 },
9733 resumeSession: true,
9734 expectResumeRejected: true,
9735 })
9736
Steven Valdeza833c352016-11-01 13:39:36 -04009737 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009738 testCases = append(testCases, testCase{
9739 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009740 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009741 config: Config{
9742 MaxVersion: VersionTLS13,
9743 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009744 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009745 },
9746 },
Steven Valdeza833c352016-11-01 13:39:36 -04009747 resumeSession: true,
9748 flags: []string{
9749 "-resumption-delay", "10",
9750 },
Steven Valdez5b986082016-09-01 12:29:49 -04009751 })
9752
Steven Valdeza833c352016-11-01 13:39:36 -04009753 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009754 testCases = append(testCases, testCase{
9755 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009756 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009757 config: Config{
9758 MaxVersion: VersionTLS13,
9759 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009760 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009761 },
9762 },
Steven Valdeza833c352016-11-01 13:39:36 -04009763 resumeSession: true,
9764 shouldFail: true,
9765 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009766 })
9767
David Benjamin35ac5b72017-03-03 15:05:56 -05009768 // Test that the server's ticket age skew reporting works.
9769 testCases = append(testCases, testCase{
9770 testType: serverTest,
9771 name: "TLS13-TicketAgeSkew-Forward",
9772 config: Config{
9773 MaxVersion: VersionTLS13,
9774 Bugs: ProtocolBugs{
9775 SendTicketAge: 15 * time.Second,
9776 },
9777 },
David Benjamin065d7332017-03-26 10:51:43 -05009778 resumeSession: true,
9779 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009780 flags: []string{
9781 "-resumption-delay", "10",
9782 "-expect-ticket-age-skew", "5",
9783 },
9784 })
9785 testCases = append(testCases, testCase{
9786 testType: serverTest,
9787 name: "TLS13-TicketAgeSkew-Backward",
9788 config: Config{
9789 MaxVersion: VersionTLS13,
9790 Bugs: ProtocolBugs{
9791 SendTicketAge: 5 * time.Second,
9792 },
9793 },
David Benjamin065d7332017-03-26 10:51:43 -05009794 resumeSession: true,
9795 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009796 flags: []string{
9797 "-resumption-delay", "10",
9798 "-expect-ticket-age-skew", "-5",
9799 },
9800 })
9801
Steven Valdez08b65f42016-12-07 15:29:45 -05009802 testCases = append(testCases, testCase{
9803 testType: clientTest,
9804 name: "TLS13-SendTicketEarlyDataInfo",
9805 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009806 MaxVersion: VersionTLS13,
9807 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009808 },
9809 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009810 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009811 "-expect-early-data-info",
9812 },
9813 })
9814
David Benjamin9b160662017-01-25 19:53:43 -05009815 // Test that 0-RTT tickets are ignored in clients unless opted in.
9816 testCases = append(testCases, testCase{
9817 testType: clientTest,
9818 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9819 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009820 MaxVersion: VersionTLS13,
9821 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009822 },
9823 })
9824
Steven Valdez08b65f42016-12-07 15:29:45 -05009825 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009826 testType: clientTest,
9827 name: "TLS13-DuplicateTicketEarlyDataInfo",
9828 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009829 MaxVersion: VersionTLS13,
9830 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009831 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009832 DuplicateTicketEarlyDataInfo: true,
9833 },
9834 },
9835 shouldFail: true,
9836 expectedError: ":DUPLICATE_EXTENSION:",
9837 expectedLocalError: "remote error: illegal parameter",
9838 })
9839
9840 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009841 testType: serverTest,
9842 name: "TLS13-ExpectTicketEarlyDataInfo",
9843 config: Config{
9844 MaxVersion: VersionTLS13,
9845 Bugs: ProtocolBugs{
9846 ExpectTicketEarlyDataInfo: true,
9847 },
9848 },
9849 flags: []string{
9850 "-enable-early-data",
9851 },
9852 })
David Benjamin17b30832017-01-28 14:00:32 -05009853
9854 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9855 // is honored.
9856 testCases = append(testCases, testCase{
9857 testType: clientTest,
9858 name: "TLS13-HonorServerSessionTicketLifetime",
9859 config: Config{
9860 MaxVersion: VersionTLS13,
9861 Bugs: ProtocolBugs{
9862 SendTicketLifetime: 20 * time.Second,
9863 },
9864 },
9865 flags: []string{
9866 "-resumption-delay", "19",
9867 },
9868 resumeSession: true,
9869 })
9870 testCases = append(testCases, testCase{
9871 testType: clientTest,
9872 name: "TLS13-HonorServerSessionTicketLifetime-2",
9873 config: Config{
9874 MaxVersion: VersionTLS13,
9875 Bugs: ProtocolBugs{
9876 SendTicketLifetime: 20 * time.Second,
9877 // The client should not offer the expired session.
9878 ExpectNoTLS13PSK: true,
9879 },
9880 },
9881 flags: []string{
9882 "-resumption-delay", "21",
9883 },
David Benjamin023d4192017-02-06 13:49:07 -05009884 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009885 expectResumeRejected: true,
9886 })
Steven Valdez5b986082016-09-01 12:29:49 -04009887}
9888
David Benjamin82261be2016-07-07 14:32:50 -07009889func addChangeCipherSpecTests() {
9890 // Test missing ChangeCipherSpecs.
9891 testCases = append(testCases, testCase{
9892 name: "SkipChangeCipherSpec-Client",
9893 config: Config{
9894 MaxVersion: VersionTLS12,
9895 Bugs: ProtocolBugs{
9896 SkipChangeCipherSpec: true,
9897 },
9898 },
9899 shouldFail: true,
9900 expectedError: ":UNEXPECTED_RECORD:",
9901 })
9902 testCases = append(testCases, testCase{
9903 testType: serverTest,
9904 name: "SkipChangeCipherSpec-Server",
9905 config: Config{
9906 MaxVersion: VersionTLS12,
9907 Bugs: ProtocolBugs{
9908 SkipChangeCipherSpec: true,
9909 },
9910 },
9911 shouldFail: true,
9912 expectedError: ":UNEXPECTED_RECORD:",
9913 })
9914 testCases = append(testCases, testCase{
9915 testType: serverTest,
9916 name: "SkipChangeCipherSpec-Server-NPN",
9917 config: Config{
9918 MaxVersion: VersionTLS12,
9919 NextProtos: []string{"bar"},
9920 Bugs: ProtocolBugs{
9921 SkipChangeCipherSpec: true,
9922 },
9923 },
9924 flags: []string{
9925 "-advertise-npn", "\x03foo\x03bar\x03baz",
9926 },
9927 shouldFail: true,
9928 expectedError: ":UNEXPECTED_RECORD:",
9929 })
9930
9931 // Test synchronization between the handshake and ChangeCipherSpec.
9932 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9933 // rejected. Test both with and without handshake packing to handle both
9934 // when the partial post-CCS message is in its own record and when it is
9935 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009936 for _, packed := range []bool{false, true} {
9937 var suffix string
9938 if packed {
9939 suffix = "-Packed"
9940 }
9941
9942 testCases = append(testCases, testCase{
9943 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9944 config: Config{
9945 MaxVersion: VersionTLS12,
9946 Bugs: ProtocolBugs{
9947 FragmentAcrossChangeCipherSpec: true,
9948 PackHandshakeFlight: packed,
9949 },
9950 },
9951 shouldFail: true,
9952 expectedError: ":UNEXPECTED_RECORD:",
9953 })
9954 testCases = append(testCases, testCase{
9955 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9956 config: Config{
9957 MaxVersion: VersionTLS12,
9958 },
9959 resumeSession: true,
9960 resumeConfig: &Config{
9961 MaxVersion: VersionTLS12,
9962 Bugs: ProtocolBugs{
9963 FragmentAcrossChangeCipherSpec: true,
9964 PackHandshakeFlight: packed,
9965 },
9966 },
9967 shouldFail: true,
9968 expectedError: ":UNEXPECTED_RECORD:",
9969 })
9970 testCases = append(testCases, testCase{
9971 testType: serverTest,
9972 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9973 config: Config{
9974 MaxVersion: VersionTLS12,
9975 Bugs: ProtocolBugs{
9976 FragmentAcrossChangeCipherSpec: true,
9977 PackHandshakeFlight: packed,
9978 },
9979 },
9980 shouldFail: true,
9981 expectedError: ":UNEXPECTED_RECORD:",
9982 })
9983 testCases = append(testCases, testCase{
9984 testType: serverTest,
9985 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9986 config: Config{
9987 MaxVersion: VersionTLS12,
9988 },
9989 resumeSession: true,
9990 resumeConfig: &Config{
9991 MaxVersion: VersionTLS12,
9992 Bugs: ProtocolBugs{
9993 FragmentAcrossChangeCipherSpec: true,
9994 PackHandshakeFlight: packed,
9995 },
9996 },
9997 shouldFail: true,
9998 expectedError: ":UNEXPECTED_RECORD:",
9999 })
10000 testCases = append(testCases, testCase{
10001 testType: serverTest,
10002 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10003 config: Config{
10004 MaxVersion: VersionTLS12,
10005 NextProtos: []string{"bar"},
10006 Bugs: ProtocolBugs{
10007 FragmentAcrossChangeCipherSpec: true,
10008 PackHandshakeFlight: packed,
10009 },
10010 },
10011 flags: []string{
10012 "-advertise-npn", "\x03foo\x03bar\x03baz",
10013 },
10014 shouldFail: true,
10015 expectedError: ":UNEXPECTED_RECORD:",
10016 })
10017 }
10018
David Benjamin61672812016-07-14 23:10:43 -040010019 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10020 // messages in the handshake queue. Do this by testing the server
10021 // reading the client Finished, reversing the flight so Finished comes
10022 // first.
10023 testCases = append(testCases, testCase{
10024 protocol: dtls,
10025 testType: serverTest,
10026 name: "SendUnencryptedFinished-DTLS",
10027 config: Config{
10028 MaxVersion: VersionTLS12,
10029 Bugs: ProtocolBugs{
10030 SendUnencryptedFinished: true,
10031 ReverseHandshakeFragments: true,
10032 },
10033 },
10034 shouldFail: true,
10035 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10036 })
10037
Steven Valdez143e8b32016-07-11 13:19:03 -040010038 // Test synchronization between encryption changes and the handshake in
10039 // TLS 1.3, where ChangeCipherSpec is implicit.
10040 testCases = append(testCases, testCase{
10041 name: "PartialEncryptedExtensionsWithServerHello",
10042 config: Config{
10043 MaxVersion: VersionTLS13,
10044 Bugs: ProtocolBugs{
10045 PartialEncryptedExtensionsWithServerHello: true,
10046 },
10047 },
10048 shouldFail: true,
10049 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10050 })
10051 testCases = append(testCases, testCase{
10052 testType: serverTest,
10053 name: "PartialClientFinishedWithClientHello",
10054 config: Config{
10055 MaxVersion: VersionTLS13,
10056 Bugs: ProtocolBugs{
10057 PartialClientFinishedWithClientHello: true,
10058 },
10059 },
10060 shouldFail: true,
10061 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10062 })
10063
David Benjamin82261be2016-07-07 14:32:50 -070010064 // Test that early ChangeCipherSpecs are handled correctly.
10065 testCases = append(testCases, testCase{
10066 testType: serverTest,
10067 name: "EarlyChangeCipherSpec-server-1",
10068 config: Config{
10069 MaxVersion: VersionTLS12,
10070 Bugs: ProtocolBugs{
10071 EarlyChangeCipherSpec: 1,
10072 },
10073 },
10074 shouldFail: true,
10075 expectedError: ":UNEXPECTED_RECORD:",
10076 })
10077 testCases = append(testCases, testCase{
10078 testType: serverTest,
10079 name: "EarlyChangeCipherSpec-server-2",
10080 config: Config{
10081 MaxVersion: VersionTLS12,
10082 Bugs: ProtocolBugs{
10083 EarlyChangeCipherSpec: 2,
10084 },
10085 },
10086 shouldFail: true,
10087 expectedError: ":UNEXPECTED_RECORD:",
10088 })
10089 testCases = append(testCases, testCase{
10090 protocol: dtls,
10091 name: "StrayChangeCipherSpec",
10092 config: Config{
10093 // TODO(davidben): Once DTLS 1.3 exists, test
10094 // that stray ChangeCipherSpec messages are
10095 // rejected.
10096 MaxVersion: VersionTLS12,
10097 Bugs: ProtocolBugs{
10098 StrayChangeCipherSpec: true,
10099 },
10100 },
10101 })
10102
David Benjaminb0c761e2017-06-25 22:42:55 -040010103 // Test that reordered ChangeCipherSpecs are tolerated.
10104 testCases = append(testCases, testCase{
10105 protocol: dtls,
10106 name: "ReorderChangeCipherSpec-DTLS-Client",
10107 config: Config{
10108 MaxVersion: VersionTLS12,
10109 Bugs: ProtocolBugs{
10110 ReorderChangeCipherSpec: true,
10111 },
10112 },
10113 resumeSession: true,
10114 })
10115 testCases = append(testCases, testCase{
10116 testType: serverTest,
10117 protocol: dtls,
10118 name: "ReorderChangeCipherSpec-DTLS-Server",
10119 config: Config{
10120 MaxVersion: VersionTLS12,
10121 Bugs: ProtocolBugs{
10122 ReorderChangeCipherSpec: true,
10123 },
10124 },
10125 resumeSession: true,
10126 })
10127
David Benjamin82261be2016-07-07 14:32:50 -070010128 // Test that the contents of ChangeCipherSpec are checked.
10129 testCases = append(testCases, testCase{
10130 name: "BadChangeCipherSpec-1",
10131 config: Config{
10132 MaxVersion: VersionTLS12,
10133 Bugs: ProtocolBugs{
10134 BadChangeCipherSpec: []byte{2},
10135 },
10136 },
10137 shouldFail: true,
10138 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10139 })
10140 testCases = append(testCases, testCase{
10141 name: "BadChangeCipherSpec-2",
10142 config: Config{
10143 MaxVersion: VersionTLS12,
10144 Bugs: ProtocolBugs{
10145 BadChangeCipherSpec: []byte{1, 1},
10146 },
10147 },
10148 shouldFail: true,
10149 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10150 })
10151 testCases = append(testCases, testCase{
10152 protocol: dtls,
10153 name: "BadChangeCipherSpec-DTLS-1",
10154 config: Config{
10155 MaxVersion: VersionTLS12,
10156 Bugs: ProtocolBugs{
10157 BadChangeCipherSpec: []byte{2},
10158 },
10159 },
10160 shouldFail: true,
10161 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10162 })
10163 testCases = append(testCases, testCase{
10164 protocol: dtls,
10165 name: "BadChangeCipherSpec-DTLS-2",
10166 config: Config{
10167 MaxVersion: VersionTLS12,
10168 Bugs: ProtocolBugs{
10169 BadChangeCipherSpec: []byte{1, 1},
10170 },
10171 },
10172 shouldFail: true,
10173 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10174 })
10175}
10176
David Benjamincd2c8062016-09-09 11:28:16 -040010177type perMessageTest struct {
10178 messageType uint8
10179 test testCase
10180}
10181
10182// makePerMessageTests returns a series of test templates which cover each
10183// message in the TLS handshake. These may be used with bugs like
10184// WrongMessageType to fully test a per-message bug.
10185func makePerMessageTests() []perMessageTest {
10186 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010187 for _, protocol := range []protocol{tls, dtls} {
10188 var suffix string
10189 if protocol == dtls {
10190 suffix = "-DTLS"
10191 }
10192
David Benjamincd2c8062016-09-09 11:28:16 -040010193 ret = append(ret, perMessageTest{
10194 messageType: typeClientHello,
10195 test: testCase{
10196 protocol: protocol,
10197 testType: serverTest,
10198 name: "ClientHello" + suffix,
10199 config: Config{
10200 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010201 },
10202 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010203 })
10204
10205 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010206 ret = append(ret, perMessageTest{
10207 messageType: typeHelloVerifyRequest,
10208 test: testCase{
10209 protocol: protocol,
10210 name: "HelloVerifyRequest" + suffix,
10211 config: Config{
10212 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010213 },
10214 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010215 })
10216 }
10217
David Benjamincd2c8062016-09-09 11:28:16 -040010218 ret = append(ret, perMessageTest{
10219 messageType: typeServerHello,
10220 test: testCase{
10221 protocol: protocol,
10222 name: "ServerHello" + suffix,
10223 config: Config{
10224 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010225 },
10226 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010227 })
10228
David Benjamincd2c8062016-09-09 11:28:16 -040010229 ret = append(ret, perMessageTest{
10230 messageType: typeCertificate,
10231 test: testCase{
10232 protocol: protocol,
10233 name: "ServerCertificate" + suffix,
10234 config: Config{
10235 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010236 },
10237 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010238 })
10239
David Benjamincd2c8062016-09-09 11:28:16 -040010240 ret = append(ret, perMessageTest{
10241 messageType: typeCertificateStatus,
10242 test: testCase{
10243 protocol: protocol,
10244 name: "CertificateStatus" + suffix,
10245 config: Config{
10246 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010247 },
David Benjamincd2c8062016-09-09 11:28:16 -040010248 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010249 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010250 })
10251
David Benjamincd2c8062016-09-09 11:28:16 -040010252 ret = append(ret, perMessageTest{
10253 messageType: typeServerKeyExchange,
10254 test: testCase{
10255 protocol: protocol,
10256 name: "ServerKeyExchange" + suffix,
10257 config: Config{
10258 MaxVersion: VersionTLS12,
10259 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010260 },
10261 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010262 })
10263
David Benjamincd2c8062016-09-09 11:28:16 -040010264 ret = append(ret, perMessageTest{
10265 messageType: typeCertificateRequest,
10266 test: testCase{
10267 protocol: protocol,
10268 name: "CertificateRequest" + suffix,
10269 config: Config{
10270 MaxVersion: VersionTLS12,
10271 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010272 },
10273 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010274 })
10275
David Benjamincd2c8062016-09-09 11:28:16 -040010276 ret = append(ret, perMessageTest{
10277 messageType: typeServerHelloDone,
10278 test: testCase{
10279 protocol: protocol,
10280 name: "ServerHelloDone" + suffix,
10281 config: Config{
10282 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010283 },
10284 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010285 })
10286
David Benjamincd2c8062016-09-09 11:28:16 -040010287 ret = append(ret, perMessageTest{
10288 messageType: typeCertificate,
10289 test: testCase{
10290 testType: serverTest,
10291 protocol: protocol,
10292 name: "ClientCertificate" + suffix,
10293 config: Config{
10294 Certificates: []Certificate{rsaCertificate},
10295 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010296 },
David Benjamincd2c8062016-09-09 11:28:16 -040010297 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010298 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010299 })
10300
David Benjamincd2c8062016-09-09 11:28:16 -040010301 ret = append(ret, perMessageTest{
10302 messageType: typeCertificateVerify,
10303 test: testCase{
10304 testType: serverTest,
10305 protocol: protocol,
10306 name: "CertificateVerify" + suffix,
10307 config: Config{
10308 Certificates: []Certificate{rsaCertificate},
10309 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010310 },
David Benjamincd2c8062016-09-09 11:28:16 -040010311 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010312 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010313 })
10314
David Benjamincd2c8062016-09-09 11:28:16 -040010315 ret = append(ret, perMessageTest{
10316 messageType: typeClientKeyExchange,
10317 test: testCase{
10318 testType: serverTest,
10319 protocol: protocol,
10320 name: "ClientKeyExchange" + suffix,
10321 config: Config{
10322 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010323 },
10324 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010325 })
10326
10327 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010328 ret = append(ret, perMessageTest{
10329 messageType: typeNextProtocol,
10330 test: testCase{
10331 testType: serverTest,
10332 protocol: protocol,
10333 name: "NextProtocol" + suffix,
10334 config: Config{
10335 MaxVersion: VersionTLS12,
10336 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010337 },
David Benjamincd2c8062016-09-09 11:28:16 -040010338 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010339 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010340 })
10341
David Benjamincd2c8062016-09-09 11:28:16 -040010342 ret = append(ret, perMessageTest{
10343 messageType: typeChannelID,
10344 test: testCase{
10345 testType: serverTest,
10346 protocol: protocol,
10347 name: "ChannelID" + suffix,
10348 config: Config{
10349 MaxVersion: VersionTLS12,
10350 ChannelID: channelIDKey,
10351 },
10352 flags: []string{
10353 "-expect-channel-id",
10354 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010355 },
10356 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010357 })
10358 }
10359
David Benjamincd2c8062016-09-09 11:28:16 -040010360 ret = append(ret, perMessageTest{
10361 messageType: typeFinished,
10362 test: testCase{
10363 testType: serverTest,
10364 protocol: protocol,
10365 name: "ClientFinished" + suffix,
10366 config: Config{
10367 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010368 },
10369 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010370 })
10371
David Benjamincd2c8062016-09-09 11:28:16 -040010372 ret = append(ret, perMessageTest{
10373 messageType: typeNewSessionTicket,
10374 test: testCase{
10375 protocol: protocol,
10376 name: "NewSessionTicket" + suffix,
10377 config: Config{
10378 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010379 },
10380 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010381 })
10382
David Benjamincd2c8062016-09-09 11:28:16 -040010383 ret = append(ret, perMessageTest{
10384 messageType: typeFinished,
10385 test: testCase{
10386 protocol: protocol,
10387 name: "ServerFinished" + suffix,
10388 config: Config{
10389 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010390 },
10391 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010392 })
10393
10394 }
David Benjamincd2c8062016-09-09 11:28:16 -040010395
10396 ret = append(ret, perMessageTest{
10397 messageType: typeClientHello,
10398 test: testCase{
10399 testType: serverTest,
10400 name: "TLS13-ClientHello",
10401 config: Config{
10402 MaxVersion: VersionTLS13,
10403 },
10404 },
10405 })
10406
10407 ret = append(ret, perMessageTest{
10408 messageType: typeServerHello,
10409 test: testCase{
10410 name: "TLS13-ServerHello",
10411 config: Config{
10412 MaxVersion: VersionTLS13,
10413 },
10414 },
10415 })
10416
10417 ret = append(ret, perMessageTest{
10418 messageType: typeEncryptedExtensions,
10419 test: testCase{
10420 name: "TLS13-EncryptedExtensions",
10421 config: Config{
10422 MaxVersion: VersionTLS13,
10423 },
10424 },
10425 })
10426
10427 ret = append(ret, perMessageTest{
10428 messageType: typeCertificateRequest,
10429 test: testCase{
10430 name: "TLS13-CertificateRequest",
10431 config: Config{
10432 MaxVersion: VersionTLS13,
10433 ClientAuth: RequireAnyClientCert,
10434 },
10435 },
10436 })
10437
10438 ret = append(ret, perMessageTest{
10439 messageType: typeCertificate,
10440 test: testCase{
10441 name: "TLS13-ServerCertificate",
10442 config: Config{
10443 MaxVersion: VersionTLS13,
10444 },
10445 },
10446 })
10447
10448 ret = append(ret, perMessageTest{
10449 messageType: typeCertificateVerify,
10450 test: testCase{
10451 name: "TLS13-ServerCertificateVerify",
10452 config: Config{
10453 MaxVersion: VersionTLS13,
10454 },
10455 },
10456 })
10457
10458 ret = append(ret, perMessageTest{
10459 messageType: typeFinished,
10460 test: testCase{
10461 name: "TLS13-ServerFinished",
10462 config: Config{
10463 MaxVersion: VersionTLS13,
10464 },
10465 },
10466 })
10467
10468 ret = append(ret, perMessageTest{
10469 messageType: typeCertificate,
10470 test: testCase{
10471 testType: serverTest,
10472 name: "TLS13-ClientCertificate",
10473 config: Config{
10474 Certificates: []Certificate{rsaCertificate},
10475 MaxVersion: VersionTLS13,
10476 },
10477 flags: []string{"-require-any-client-certificate"},
10478 },
10479 })
10480
10481 ret = append(ret, perMessageTest{
10482 messageType: typeCertificateVerify,
10483 test: testCase{
10484 testType: serverTest,
10485 name: "TLS13-ClientCertificateVerify",
10486 config: Config{
10487 Certificates: []Certificate{rsaCertificate},
10488 MaxVersion: VersionTLS13,
10489 },
10490 flags: []string{"-require-any-client-certificate"},
10491 },
10492 })
10493
10494 ret = append(ret, perMessageTest{
10495 messageType: typeFinished,
10496 test: testCase{
10497 testType: serverTest,
10498 name: "TLS13-ClientFinished",
10499 config: Config{
10500 MaxVersion: VersionTLS13,
10501 },
10502 },
10503 })
10504
10505 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010506}
10507
David Benjamincd2c8062016-09-09 11:28:16 -040010508func addWrongMessageTypeTests() {
10509 for _, t := range makePerMessageTests() {
10510 t.test.name = "WrongMessageType-" + t.test.name
10511 t.test.config.Bugs.SendWrongMessageType = t.messageType
10512 t.test.shouldFail = true
10513 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10514 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010515
David Benjamincd2c8062016-09-09 11:28:16 -040010516 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10517 // In TLS 1.3, a bad ServerHello means the client sends
10518 // an unencrypted alert while the server expects
10519 // encryption, so the alert is not readable by runner.
10520 t.test.expectedLocalError = "local error: bad record MAC"
10521 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010522
David Benjamincd2c8062016-09-09 11:28:16 -040010523 testCases = append(testCases, t.test)
10524 }
David Benjaminebacdee2017-04-08 11:00:45 -040010525
10526 // The processing order for TLS 1.3 version negotiation is such that one
10527 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10528 // TLS 1.2. Test that we do not do this.
10529 testCases = append(testCases, testCase{
10530 name: "SendServerHelloAsHelloRetryRequest",
10531 config: Config{
10532 MaxVersion: VersionTLS12,
10533 Bugs: ProtocolBugs{
10534 SendServerHelloAsHelloRetryRequest: true,
10535 },
10536 },
10537 shouldFail: true,
10538 expectedError: ":UNEXPECTED_MESSAGE:",
10539 expectedLocalError: "remote error: unexpected message",
10540 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010541}
10542
David Benjamin639846e2016-09-09 11:41:18 -040010543func addTrailingMessageDataTests() {
10544 for _, t := range makePerMessageTests() {
10545 t.test.name = "TrailingMessageData-" + t.test.name
10546 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10547 t.test.shouldFail = true
10548 t.test.expectedError = ":DECODE_ERROR:"
10549 t.test.expectedLocalError = "remote error: error decoding message"
10550
10551 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10552 // In TLS 1.3, a bad ServerHello means the client sends
10553 // an unencrypted alert while the server expects
10554 // encryption, so the alert is not readable by runner.
10555 t.test.expectedLocalError = "local error: bad record MAC"
10556 }
10557
10558 if t.messageType == typeFinished {
10559 // Bad Finished messages read as the verify data having
10560 // the wrong length.
10561 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10562 t.test.expectedLocalError = "remote error: error decrypting message"
10563 }
10564
10565 testCases = append(testCases, t.test)
10566 }
10567}
10568
Steven Valdez143e8b32016-07-11 13:19:03 -040010569func addTLS13HandshakeTests() {
10570 testCases = append(testCases, testCase{
10571 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010572 name: "NegotiatePSKResumption-TLS13",
10573 config: Config{
10574 MaxVersion: VersionTLS13,
10575 Bugs: ProtocolBugs{
10576 NegotiatePSKResumption: true,
10577 },
10578 },
10579 resumeSession: true,
10580 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010581 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010582 })
10583
10584 testCases = append(testCases, testCase{
10585 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010586 name: "MissingKeyShare-Client",
10587 config: Config{
10588 MaxVersion: VersionTLS13,
10589 Bugs: ProtocolBugs{
10590 MissingKeyShare: true,
10591 },
10592 },
10593 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010594 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010595 })
10596
10597 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010598 testType: serverTest,
10599 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010600 config: Config{
10601 MaxVersion: VersionTLS13,
10602 Bugs: ProtocolBugs{
10603 MissingKeyShare: true,
10604 },
10605 },
10606 shouldFail: true,
10607 expectedError: ":MISSING_KEY_SHARE:",
10608 })
10609
10610 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010611 testType: serverTest,
10612 name: "DuplicateKeyShares",
10613 config: Config{
10614 MaxVersion: VersionTLS13,
10615 Bugs: ProtocolBugs{
10616 DuplicateKeyShares: true,
10617 },
10618 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010619 shouldFail: true,
10620 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010621 })
10622
10623 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010624 testType: serverTest,
10625 name: "SkipEarlyData",
10626 config: Config{
10627 MaxVersion: VersionTLS13,
10628 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010629 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010630 },
10631 },
10632 })
10633
10634 testCases = append(testCases, testCase{
10635 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010636 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010637 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010638 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010639 Bugs: ProtocolBugs{
10640 SendFakeEarlyDataLength: 4,
10641 },
10642 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010643 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010644 })
10645
10646 testCases = append(testCases, testCase{
10647 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010648 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10649 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010650 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010651 Bugs: ProtocolBugs{
10652 SendFakeEarlyDataLength: 4,
10653 },
10654 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010655 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010656 })
10657
10658 testCases = append(testCases, testCase{
10659 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010660 name: "SkipEarlyData-OmitEarlyDataExtension",
10661 config: Config{
10662 MaxVersion: VersionTLS13,
10663 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010664 SendFakeEarlyDataLength: 4,
10665 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010666 },
10667 },
10668 shouldFail: true,
10669 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10670 })
10671
10672 testCases = append(testCases, testCase{
10673 testType: serverTest,
10674 name: "SkipEarlyData-TooMuchData",
10675 config: Config{
10676 MaxVersion: VersionTLS13,
10677 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010678 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010679 },
10680 },
10681 shouldFail: true,
10682 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10683 })
10684
10685 testCases = append(testCases, testCase{
10686 testType: serverTest,
10687 name: "SkipEarlyData-Interleaved",
10688 config: Config{
10689 MaxVersion: VersionTLS13,
10690 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010691 SendFakeEarlyDataLength: 4,
10692 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010693 },
10694 },
10695 shouldFail: true,
10696 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10697 })
10698
10699 testCases = append(testCases, testCase{
10700 testType: serverTest,
10701 name: "SkipEarlyData-EarlyDataInTLS12",
10702 config: Config{
10703 MaxVersion: VersionTLS13,
10704 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010705 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010706 },
10707 },
10708 shouldFail: true,
10709 expectedError: ":UNEXPECTED_RECORD:",
10710 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10711 })
10712
10713 testCases = append(testCases, testCase{
10714 testType: serverTest,
10715 name: "SkipEarlyData-HRR",
10716 config: Config{
10717 MaxVersion: VersionTLS13,
10718 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010719 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010720 },
10721 DefaultCurves: []CurveID{},
10722 },
10723 })
10724
10725 testCases = append(testCases, testCase{
10726 testType: serverTest,
10727 name: "SkipEarlyData-HRR-Interleaved",
10728 config: Config{
10729 MaxVersion: VersionTLS13,
10730 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010731 SendFakeEarlyDataLength: 4,
10732 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010733 },
10734 DefaultCurves: []CurveID{},
10735 },
10736 shouldFail: true,
10737 expectedError: ":UNEXPECTED_RECORD:",
10738 })
10739
10740 testCases = append(testCases, testCase{
10741 testType: serverTest,
10742 name: "SkipEarlyData-HRR-TooMuchData",
10743 config: Config{
10744 MaxVersion: VersionTLS13,
10745 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010746 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010747 },
10748 DefaultCurves: []CurveID{},
10749 },
10750 shouldFail: true,
10751 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10752 })
10753
10754 // Test that skipping early data looking for cleartext correctly
10755 // processes an alert record.
10756 testCases = append(testCases, testCase{
10757 testType: serverTest,
10758 name: "SkipEarlyData-HRR-FatalAlert",
10759 config: Config{
10760 MaxVersion: VersionTLS13,
10761 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010762 SendEarlyAlert: true,
10763 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010764 },
10765 DefaultCurves: []CurveID{},
10766 },
10767 shouldFail: true,
10768 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10769 })
10770
10771 testCases = append(testCases, testCase{
10772 testType: serverTest,
10773 name: "SkipEarlyData-SecondClientHelloEarlyData",
10774 config: Config{
10775 MaxVersion: VersionTLS13,
10776 Bugs: ProtocolBugs{
10777 SendEarlyDataOnSecondClientHello: true,
10778 },
10779 DefaultCurves: []CurveID{},
10780 },
10781 shouldFail: true,
10782 expectedLocalError: "remote error: bad record MAC",
10783 })
10784
10785 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010786 testType: clientTest,
10787 name: "EmptyEncryptedExtensions",
10788 config: Config{
10789 MaxVersion: VersionTLS13,
10790 Bugs: ProtocolBugs{
10791 EmptyEncryptedExtensions: true,
10792 },
10793 },
10794 shouldFail: true,
10795 expectedLocalError: "remote error: error decoding message",
10796 })
10797
10798 testCases = append(testCases, testCase{
10799 testType: clientTest,
10800 name: "EncryptedExtensionsWithKeyShare",
10801 config: Config{
10802 MaxVersion: VersionTLS13,
10803 Bugs: ProtocolBugs{
10804 EncryptedExtensionsWithKeyShare: true,
10805 },
10806 },
10807 shouldFail: true,
10808 expectedLocalError: "remote error: unsupported extension",
10809 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010810
10811 testCases = append(testCases, testCase{
10812 testType: serverTest,
10813 name: "SendHelloRetryRequest",
10814 config: Config{
10815 MaxVersion: VersionTLS13,
10816 // Require a HelloRetryRequest for every curve.
10817 DefaultCurves: []CurveID{},
10818 },
10819 expectedCurveID: CurveX25519,
10820 })
10821
10822 testCases = append(testCases, testCase{
10823 testType: serverTest,
10824 name: "SendHelloRetryRequest-2",
10825 config: Config{
10826 MaxVersion: VersionTLS13,
10827 DefaultCurves: []CurveID{CurveP384},
10828 },
10829 // Although the ClientHello did not predict our preferred curve,
10830 // we always select it whether it is predicted or not.
10831 expectedCurveID: CurveX25519,
10832 })
10833
10834 testCases = append(testCases, testCase{
10835 name: "UnknownCurve-HelloRetryRequest",
10836 config: Config{
10837 MaxVersion: VersionTLS13,
10838 // P-384 requires HelloRetryRequest in BoringSSL.
10839 CurvePreferences: []CurveID{CurveP384},
10840 Bugs: ProtocolBugs{
10841 SendHelloRetryRequestCurve: bogusCurve,
10842 },
10843 },
10844 shouldFail: true,
10845 expectedError: ":WRONG_CURVE:",
10846 })
10847
10848 testCases = append(testCases, testCase{
10849 name: "DisabledCurve-HelloRetryRequest",
10850 config: Config{
10851 MaxVersion: VersionTLS13,
10852 CurvePreferences: []CurveID{CurveP256},
10853 Bugs: ProtocolBugs{
10854 IgnorePeerCurvePreferences: true,
10855 },
10856 },
10857 flags: []string{"-p384-only"},
10858 shouldFail: true,
10859 expectedError: ":WRONG_CURVE:",
10860 })
10861
10862 testCases = append(testCases, testCase{
10863 name: "UnnecessaryHelloRetryRequest",
10864 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010865 MaxVersion: VersionTLS13,
10866 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010867 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010868 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010869 },
10870 },
10871 shouldFail: true,
10872 expectedError: ":WRONG_CURVE:",
10873 })
10874
10875 testCases = append(testCases, testCase{
10876 name: "SecondHelloRetryRequest",
10877 config: Config{
10878 MaxVersion: VersionTLS13,
10879 // P-384 requires HelloRetryRequest in BoringSSL.
10880 CurvePreferences: []CurveID{CurveP384},
10881 Bugs: ProtocolBugs{
10882 SecondHelloRetryRequest: true,
10883 },
10884 },
10885 shouldFail: true,
10886 expectedError: ":UNEXPECTED_MESSAGE:",
10887 })
10888
10889 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010890 name: "HelloRetryRequest-Empty",
10891 config: Config{
10892 MaxVersion: VersionTLS13,
10893 Bugs: ProtocolBugs{
10894 AlwaysSendHelloRetryRequest: true,
10895 },
10896 },
10897 shouldFail: true,
10898 expectedError: ":DECODE_ERROR:",
10899 })
10900
10901 testCases = append(testCases, testCase{
10902 name: "HelloRetryRequest-DuplicateCurve",
10903 config: Config{
10904 MaxVersion: VersionTLS13,
10905 // P-384 requires a HelloRetryRequest against BoringSSL's default
10906 // configuration. Assert this ExpectMissingKeyShare.
10907 CurvePreferences: []CurveID{CurveP384},
10908 Bugs: ProtocolBugs{
10909 ExpectMissingKeyShare: true,
10910 DuplicateHelloRetryRequestExtensions: true,
10911 },
10912 },
10913 shouldFail: true,
10914 expectedError: ":DUPLICATE_EXTENSION:",
10915 expectedLocalError: "remote error: illegal parameter",
10916 })
10917
10918 testCases = append(testCases, testCase{
10919 name: "HelloRetryRequest-Cookie",
10920 config: Config{
10921 MaxVersion: VersionTLS13,
10922 Bugs: ProtocolBugs{
10923 SendHelloRetryRequestCookie: []byte("cookie"),
10924 },
10925 },
10926 })
10927
10928 testCases = append(testCases, testCase{
10929 name: "HelloRetryRequest-DuplicateCookie",
10930 config: Config{
10931 MaxVersion: VersionTLS13,
10932 Bugs: ProtocolBugs{
10933 SendHelloRetryRequestCookie: []byte("cookie"),
10934 DuplicateHelloRetryRequestExtensions: true,
10935 },
10936 },
10937 shouldFail: true,
10938 expectedError: ":DUPLICATE_EXTENSION:",
10939 expectedLocalError: "remote error: illegal parameter",
10940 })
10941
10942 testCases = append(testCases, testCase{
10943 name: "HelloRetryRequest-EmptyCookie",
10944 config: Config{
10945 MaxVersion: VersionTLS13,
10946 Bugs: ProtocolBugs{
10947 SendHelloRetryRequestCookie: []byte{},
10948 },
10949 },
10950 shouldFail: true,
10951 expectedError: ":DECODE_ERROR:",
10952 })
10953
10954 testCases = append(testCases, testCase{
10955 name: "HelloRetryRequest-Cookie-Curve",
10956 config: Config{
10957 MaxVersion: VersionTLS13,
10958 // P-384 requires HelloRetryRequest in BoringSSL.
10959 CurvePreferences: []CurveID{CurveP384},
10960 Bugs: ProtocolBugs{
10961 SendHelloRetryRequestCookie: []byte("cookie"),
10962 ExpectMissingKeyShare: true,
10963 },
10964 },
10965 })
10966
10967 testCases = append(testCases, testCase{
10968 name: "HelloRetryRequest-Unknown",
10969 config: Config{
10970 MaxVersion: VersionTLS13,
10971 Bugs: ProtocolBugs{
10972 CustomHelloRetryRequestExtension: "extension",
10973 },
10974 },
10975 shouldFail: true,
10976 expectedError: ":UNEXPECTED_EXTENSION:",
10977 expectedLocalError: "remote error: unsupported extension",
10978 })
10979
10980 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010981 testType: serverTest,
10982 name: "SecondClientHelloMissingKeyShare",
10983 config: Config{
10984 MaxVersion: VersionTLS13,
10985 DefaultCurves: []CurveID{},
10986 Bugs: ProtocolBugs{
10987 SecondClientHelloMissingKeyShare: true,
10988 },
10989 },
10990 shouldFail: true,
10991 expectedError: ":MISSING_KEY_SHARE:",
10992 })
10993
10994 testCases = append(testCases, testCase{
10995 testType: serverTest,
10996 name: "SecondClientHelloWrongCurve",
10997 config: Config{
10998 MaxVersion: VersionTLS13,
10999 DefaultCurves: []CurveID{},
11000 Bugs: ProtocolBugs{
11001 MisinterpretHelloRetryRequestCurve: CurveP521,
11002 },
11003 },
11004 shouldFail: true,
11005 expectedError: ":WRONG_CURVE:",
11006 })
11007
11008 testCases = append(testCases, testCase{
11009 name: "HelloRetryRequestVersionMismatch",
11010 config: Config{
11011 MaxVersion: VersionTLS13,
11012 // P-384 requires HelloRetryRequest in BoringSSL.
11013 CurvePreferences: []CurveID{CurveP384},
11014 Bugs: ProtocolBugs{
11015 SendServerHelloVersion: 0x0305,
11016 },
11017 },
11018 shouldFail: true,
11019 expectedError: ":WRONG_VERSION_NUMBER:",
11020 })
11021
11022 testCases = append(testCases, testCase{
11023 name: "HelloRetryRequestCurveMismatch",
11024 config: Config{
11025 MaxVersion: VersionTLS13,
11026 // P-384 requires HelloRetryRequest in BoringSSL.
11027 CurvePreferences: []CurveID{CurveP384},
11028 Bugs: ProtocolBugs{
11029 // Send P-384 (correct) in the HelloRetryRequest.
11030 SendHelloRetryRequestCurve: CurveP384,
11031 // But send P-256 in the ServerHello.
11032 SendCurve: CurveP256,
11033 },
11034 },
11035 shouldFail: true,
11036 expectedError: ":WRONG_CURVE:",
11037 })
11038
11039 // Test the server selecting a curve that requires a HelloRetryRequest
11040 // without sending it.
11041 testCases = append(testCases, testCase{
11042 name: "SkipHelloRetryRequest",
11043 config: Config{
11044 MaxVersion: VersionTLS13,
11045 // P-384 requires HelloRetryRequest in BoringSSL.
11046 CurvePreferences: []CurveID{CurveP384},
11047 Bugs: ProtocolBugs{
11048 SkipHelloRetryRequest: true,
11049 },
11050 },
11051 shouldFail: true,
11052 expectedError: ":WRONG_CURVE:",
11053 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011054
11055 testCases = append(testCases, testCase{
11056 name: "TLS13-RequestContextInHandshake",
11057 config: Config{
11058 MaxVersion: VersionTLS13,
11059 MinVersion: VersionTLS13,
11060 ClientAuth: RequireAnyClientCert,
11061 Bugs: ProtocolBugs{
11062 SendRequestContext: []byte("request context"),
11063 },
11064 },
11065 flags: []string{
11066 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11067 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11068 },
11069 shouldFail: true,
11070 expectedError: ":DECODE_ERROR:",
11071 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011072
11073 testCases = append(testCases, testCase{
11074 testType: serverTest,
11075 name: "TLS13-TrailingKeyShareData",
11076 config: Config{
11077 MaxVersion: VersionTLS13,
11078 Bugs: ProtocolBugs{
11079 TrailingKeyShareData: true,
11080 },
11081 },
11082 shouldFail: true,
11083 expectedError: ":DECODE_ERROR:",
11084 })
David Benjamin7f78df42016-10-05 22:33:19 -040011085
11086 testCases = append(testCases, testCase{
11087 name: "TLS13-AlwaysSelectPSKIdentity",
11088 config: Config{
11089 MaxVersion: VersionTLS13,
11090 Bugs: ProtocolBugs{
11091 AlwaysSelectPSKIdentity: true,
11092 },
11093 },
11094 shouldFail: true,
11095 expectedError: ":UNEXPECTED_EXTENSION:",
11096 })
11097
11098 testCases = append(testCases, testCase{
11099 name: "TLS13-InvalidPSKIdentity",
11100 config: Config{
11101 MaxVersion: VersionTLS13,
11102 Bugs: ProtocolBugs{
11103 SelectPSKIdentityOnResume: 1,
11104 },
11105 },
11106 resumeSession: true,
11107 shouldFail: true,
11108 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11109 })
David Benjamin1286bee2016-10-07 15:25:06 -040011110
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011111 testCases = append(testCases, testCase{
11112 testType: serverTest,
11113 name: "TLS13-ExtraPSKIdentity",
11114 config: Config{
11115 MaxVersion: VersionTLS13,
11116 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011117 ExtraPSKIdentity: true,
11118 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011119 },
11120 },
11121 resumeSession: true,
11122 })
11123
David Benjamin1286bee2016-10-07 15:25:06 -040011124 // Test that unknown NewSessionTicket extensions are tolerated.
11125 testCases = append(testCases, testCase{
11126 name: "TLS13-CustomTicketExtension",
11127 config: Config{
11128 MaxVersion: VersionTLS13,
11129 Bugs: ProtocolBugs{
11130 CustomTicketExtension: "1234",
11131 },
11132 },
11133 })
Steven Valdez2d850622017-01-11 11:34:52 -050011134
Steven Valdez0e4a4482017-07-17 11:12:34 -040011135 for _, noSessionID := range []bool{false, true} {
11136 prefix := "TLS13Experiment"
11137 variant := TLS13Experiment
11138 if noSessionID {
11139 prefix = "TLS13NoSessionIDExperiment"
11140 variant = TLS13NoSessionIDExperiment
11141 }
11142
11143 // Test that enabling a TLS 1.3 variant does not interfere with
11144 // TLS 1.2 session ID resumption.
11145 testCases = append(testCases, testCase{
11146 testType: clientTest,
11147 name: prefix + "-ResumeTLS12SessionID",
11148 config: Config{
11149 MaxVersion: VersionTLS12,
11150 SessionTicketsDisabled: true,
11151 },
11152 resumeSession: true,
11153 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11154 })
11155
11156 // Test that the server correctly echoes back session IDs of
11157 // various lengths.
11158 testCases = append(testCases, testCase{
11159 testType: serverTest,
11160 name: prefix + "-EmptySessionID",
11161 config: Config{
11162 MaxVersion: VersionTLS13,
11163 Bugs: ProtocolBugs{
11164 SendClientHelloSessionID: []byte{},
11165 },
11166 },
11167 tls13Variant: variant,
11168 })
11169
11170 testCases = append(testCases, testCase{
11171 testType: serverTest,
11172 name: prefix + "-ShortSessionID",
11173 config: Config{
11174 MaxVersion: VersionTLS13,
11175 Bugs: ProtocolBugs{
11176 SendClientHelloSessionID: make([]byte, 16),
11177 },
11178 },
11179 tls13Variant: variant,
11180 })
11181
11182 testCases = append(testCases, testCase{
11183 testType: serverTest,
11184 name: prefix + "-FullSessionID",
11185 config: Config{
11186 MaxVersion: VersionTLS13,
11187 Bugs: ProtocolBugs{
11188 SendClientHelloSessionID: make([]byte, 32),
11189 },
11190 },
11191 tls13Variant: variant,
11192 })
11193 }
11194
11195 // Test that the client sends a fake session ID in TLS13Experiment.
11196 testCases = append(testCases, testCase{
11197 testType: clientTest,
11198 name: "TLS13Experiment-RequireSessionID",
11199 config: Config{
11200 MaxVersion: VersionTLS13,
11201 Bugs: ProtocolBugs{
11202 ExpectClientHelloSessionID: true,
11203 },
11204 },
11205 tls13Variant: TLS13Experiment,
11206 })
11207
11208 // Test that the client does not send a fake session ID in
11209 // TLS13NoSessionIDExperiment.
11210 testCases = append(testCases, testCase{
11211 testType: clientTest,
11212 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11213 config: Config{
11214 MaxVersion: VersionTLS13,
11215 Bugs: ProtocolBugs{
11216 ExpectEmptyClientHelloSessionID: true,
11217 },
11218 },
11219 tls13Variant: TLS13NoSessionIDExperiment,
11220 })
11221
Steven Valdez2d850622017-01-11 11:34:52 -050011222 testCases = append(testCases, testCase{
11223 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011224 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011225 config: Config{
11226 MaxVersion: VersionTLS13,
11227 MaxEarlyDataSize: 16384,
11228 },
11229 resumeConfig: &Config{
11230 MaxVersion: VersionTLS13,
11231 MaxEarlyDataSize: 16384,
11232 Bugs: ProtocolBugs{
11233 AlwaysRejectEarlyData: true,
11234 },
11235 },
11236 resumeSession: true,
11237 flags: []string{
11238 "-enable-early-data",
11239 "-expect-early-data-info",
11240 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011241 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011242 },
11243 })
11244
11245 testCases = append(testCases, testCase{
11246 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011247 name: "TLS13Experiment-EarlyData-Reject-Client",
11248 config: Config{
11249 MaxVersion: VersionTLS13,
11250 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011251 },
11252 resumeConfig: &Config{
11253 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011254 MaxEarlyDataSize: 16384,
11255 Bugs: ProtocolBugs{
11256 AlwaysRejectEarlyData: true,
11257 },
11258 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011259 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011260 resumeSession: true,
11261 flags: []string{
11262 "-enable-early-data",
11263 "-expect-early-data-info",
11264 "-expect-reject-early-data",
11265 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011266 },
11267 })
11268
11269 testCases = append(testCases, testCase{
11270 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011271 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11272 config: Config{
11273 MaxVersion: VersionTLS13,
11274 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011275 },
11276 resumeConfig: &Config{
11277 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011278 MaxEarlyDataSize: 16384,
11279 Bugs: ProtocolBugs{
11280 AlwaysRejectEarlyData: true,
11281 },
11282 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011283 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011284 resumeSession: true,
11285 flags: []string{
11286 "-enable-early-data",
11287 "-expect-early-data-info",
11288 "-expect-reject-early-data",
11289 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011290 },
11291 })
11292
11293 testCases = append(testCases, testCase{
11294 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011295 name: "TLS13-EarlyData-RejectTicket-Client",
11296 config: Config{
11297 MaxVersion: VersionTLS13,
11298 MaxEarlyDataSize: 16384,
11299 Certificates: []Certificate{rsaCertificate},
11300 },
11301 resumeConfig: &Config{
11302 MaxVersion: VersionTLS13,
11303 MaxEarlyDataSize: 16384,
11304 Certificates: []Certificate{ecdsaP256Certificate},
11305 SessionTicketsDisabled: true,
11306 },
11307 resumeSession: true,
11308 expectResumeRejected: true,
11309 flags: []string{
11310 "-enable-early-data",
11311 "-expect-early-data-info",
11312 "-expect-reject-early-data",
11313 "-on-resume-shim-writes-first",
11314 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11315 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11316 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11317 // Session tickets are disabled, so the runner will not send a ticket.
11318 "-on-retry-expect-no-session",
11319 },
11320 })
11321
11322 testCases = append(testCases, testCase{
11323 testType: clientTest,
11324 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011325 config: Config{
11326 MaxVersion: VersionTLS13,
11327 MaxEarlyDataSize: 16384,
11328 },
11329 resumeConfig: &Config{
11330 MaxVersion: VersionTLS13,
11331 MaxEarlyDataSize: 16384,
11332 Bugs: ProtocolBugs{
11333 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11334 },
11335 },
11336 resumeSession: true,
11337 flags: []string{
11338 "-enable-early-data",
11339 "-expect-early-data-info",
11340 "-expect-reject-early-data",
11341 },
11342 })
11343
11344 // The client must check the server does not send the early_data
11345 // extension while rejecting the session.
11346 testCases = append(testCases, testCase{
11347 testType: clientTest,
11348 name: "TLS13-EarlyDataWithoutResume-Client",
11349 config: Config{
11350 MaxVersion: VersionTLS13,
11351 MaxEarlyDataSize: 16384,
11352 },
11353 resumeConfig: &Config{
11354 MaxVersion: VersionTLS13,
11355 SessionTicketsDisabled: true,
11356 Bugs: ProtocolBugs{
11357 SendEarlyDataExtension: true,
11358 },
11359 },
11360 resumeSession: true,
11361 flags: []string{
11362 "-enable-early-data",
11363 "-expect-early-data-info",
11364 },
11365 shouldFail: true,
11366 expectedError: ":UNEXPECTED_EXTENSION:",
11367 })
11368
11369 // The client must fail with a dedicated error code if the server
11370 // responds with TLS 1.2 when offering 0-RTT.
11371 testCases = append(testCases, testCase{
11372 testType: clientTest,
11373 name: "TLS13-EarlyDataVersionDowngrade-Client",
11374 config: Config{
11375 MaxVersion: VersionTLS13,
11376 MaxEarlyDataSize: 16384,
11377 },
11378 resumeConfig: &Config{
11379 MaxVersion: VersionTLS12,
11380 },
11381 resumeSession: true,
11382 flags: []string{
11383 "-enable-early-data",
11384 "-expect-early-data-info",
11385 },
11386 shouldFail: true,
11387 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11388 })
11389
11390 // Test that the client rejects an (unsolicited) early_data extension if
11391 // the server sent an HRR.
11392 testCases = append(testCases, testCase{
11393 testType: clientTest,
11394 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11395 config: Config{
11396 MaxVersion: VersionTLS13,
11397 MaxEarlyDataSize: 16384,
11398 },
11399 resumeConfig: &Config{
11400 MaxVersion: VersionTLS13,
11401 MaxEarlyDataSize: 16384,
11402 Bugs: ProtocolBugs{
11403 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11404 SendEarlyDataExtension: true,
11405 },
11406 },
11407 resumeSession: true,
11408 flags: []string{
11409 "-enable-early-data",
11410 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011411 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011412 },
11413 shouldFail: true,
11414 expectedError: ":UNEXPECTED_EXTENSION:",
11415 })
11416
11417 fooString := "foo"
11418 barString := "bar"
11419
11420 // Test that the client reports the correct ALPN after a 0-RTT reject
11421 // that changed it.
11422 testCases = append(testCases, testCase{
11423 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011424 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011425 config: Config{
11426 MaxVersion: VersionTLS13,
11427 MaxEarlyDataSize: 16384,
11428 Bugs: ProtocolBugs{
11429 ALPNProtocol: &fooString,
11430 },
11431 },
11432 resumeConfig: &Config{
11433 MaxVersion: VersionTLS13,
11434 MaxEarlyDataSize: 16384,
11435 Bugs: ProtocolBugs{
11436 ALPNProtocol: &barString,
11437 },
11438 },
11439 resumeSession: true,
11440 flags: []string{
11441 "-advertise-alpn", "\x03foo\x03bar",
11442 "-enable-early-data",
11443 "-expect-early-data-info",
11444 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011445 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011446 "-on-resume-expect-alpn", "foo",
11447 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011448 },
11449 })
11450
11451 // Test that the client reports the correct ALPN after a 0-RTT reject if
11452 // ALPN was omitted from the first connection.
11453 testCases = append(testCases, testCase{
11454 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011455 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011456 config: Config{
11457 MaxVersion: VersionTLS13,
11458 MaxEarlyDataSize: 16384,
11459 },
11460 resumeConfig: &Config{
11461 MaxVersion: VersionTLS13,
11462 MaxEarlyDataSize: 16384,
11463 NextProtos: []string{"foo"},
11464 },
11465 resumeSession: true,
11466 flags: []string{
11467 "-advertise-alpn", "\x03foo\x03bar",
11468 "-enable-early-data",
11469 "-expect-early-data-info",
11470 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011471 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011472 "-on-resume-expect-alpn", "",
11473 "-on-retry-expect-alpn", "foo",
11474 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011475 },
11476 })
11477
11478 // Test that the client reports the correct ALPN after a 0-RTT reject if
11479 // ALPN was omitted from the second connection.
11480 testCases = append(testCases, testCase{
11481 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011482 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011483 config: Config{
11484 MaxVersion: VersionTLS13,
11485 MaxEarlyDataSize: 16384,
11486 NextProtos: []string{"foo"},
11487 },
11488 resumeConfig: &Config{
11489 MaxVersion: VersionTLS13,
11490 MaxEarlyDataSize: 16384,
11491 },
11492 resumeSession: true,
11493 flags: []string{
11494 "-advertise-alpn", "\x03foo\x03bar",
11495 "-enable-early-data",
11496 "-expect-early-data-info",
11497 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011498 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011499 "-on-resume-expect-alpn", "foo",
11500 "-on-retry-expect-alpn", "",
11501 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011502 },
11503 })
11504
11505 // Test that the client enforces ALPN match on 0-RTT accept.
11506 testCases = append(testCases, testCase{
11507 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011508 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011509 config: Config{
11510 MaxVersion: VersionTLS13,
11511 MaxEarlyDataSize: 16384,
11512 Bugs: ProtocolBugs{
11513 ALPNProtocol: &fooString,
11514 },
11515 },
11516 resumeConfig: &Config{
11517 MaxVersion: VersionTLS13,
11518 MaxEarlyDataSize: 16384,
11519 Bugs: ProtocolBugs{
11520 AlwaysAcceptEarlyData: true,
11521 ALPNProtocol: &barString,
11522 },
11523 },
11524 resumeSession: true,
11525 flags: []string{
11526 "-advertise-alpn", "\x03foo\x03bar",
11527 "-enable-early-data",
11528 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011529 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011530 "-on-resume-expect-alpn", "foo",
11531 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011532 },
11533 shouldFail: true,
11534 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11535 })
11536
11537 // Test that the server correctly rejects 0-RTT when the previous
11538 // session did not allow early data on resumption.
11539 testCases = append(testCases, testCase{
11540 testType: serverTest,
11541 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11542 config: Config{
11543 MaxVersion: VersionTLS13,
11544 },
11545 resumeConfig: &Config{
11546 MaxVersion: VersionTLS13,
11547 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011548 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011549 ExpectEarlyDataAccepted: false,
11550 },
11551 },
11552 resumeSession: true,
11553 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011554 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011555 "-expect-reject-early-data",
11556 },
11557 })
11558
11559 // Test that we reject early data where ALPN is omitted from the first
11560 // connection.
11561 testCases = append(testCases, testCase{
11562 testType: serverTest,
11563 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11564 config: Config{
11565 MaxVersion: VersionTLS13,
11566 NextProtos: []string{},
11567 },
11568 resumeConfig: &Config{
11569 MaxVersion: VersionTLS13,
11570 NextProtos: []string{"foo"},
11571 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011572 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011573 ExpectEarlyDataAccepted: false,
11574 },
11575 },
11576 resumeSession: true,
11577 flags: []string{
11578 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011579 "-on-initial-select-alpn", "",
11580 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011581 },
11582 })
11583
11584 // Test that we reject early data where ALPN is omitted from the second
11585 // connection.
11586 testCases = append(testCases, testCase{
11587 testType: serverTest,
11588 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11589 config: Config{
11590 MaxVersion: VersionTLS13,
11591 NextProtos: []string{"foo"},
11592 },
11593 resumeConfig: &Config{
11594 MaxVersion: VersionTLS13,
11595 NextProtos: []string{},
11596 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011597 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011598 ExpectEarlyDataAccepted: false,
11599 },
11600 },
11601 resumeSession: true,
11602 flags: []string{
11603 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011604 "-on-initial-select-alpn", "foo",
11605 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011606 },
11607 })
11608
11609 // Test that we reject early data with mismatched ALPN.
11610 testCases = append(testCases, testCase{
11611 testType: serverTest,
11612 name: "TLS13-EarlyData-ALPNMismatch-Server",
11613 config: Config{
11614 MaxVersion: VersionTLS13,
11615 NextProtos: []string{"foo"},
11616 },
11617 resumeConfig: &Config{
11618 MaxVersion: VersionTLS13,
11619 NextProtos: []string{"bar"},
11620 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011621 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011622 ExpectEarlyDataAccepted: false,
11623 },
11624 },
11625 resumeSession: true,
11626 flags: []string{
11627 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011628 "-on-initial-select-alpn", "foo",
11629 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011630 },
11631 })
11632
David Benjamin6bb507b2017-03-29 16:35:57 -050011633 // Test that the client offering 0-RTT and Channel ID forbids the server
11634 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011635 testCases = append(testCases, testCase{
11636 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011637 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011638 config: Config{
11639 MaxVersion: VersionTLS13,
11640 MaxEarlyDataSize: 16384,
11641 RequestChannelID: true,
11642 },
11643 resumeSession: true,
11644 expectChannelID: true,
11645 shouldFail: true,
11646 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11647 flags: []string{
11648 "-enable-early-data",
11649 "-expect-early-data-info",
11650 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11651 },
11652 })
11653
David Benjamin6bb507b2017-03-29 16:35:57 -050011654 // Test that the client offering Channel ID and 0-RTT allows the server
11655 // to decline 0-RTT.
11656 testCases = append(testCases, testCase{
11657 testType: clientTest,
11658 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11659 config: Config{
11660 MaxVersion: VersionTLS13,
11661 MaxEarlyDataSize: 16384,
11662 RequestChannelID: true,
11663 Bugs: ProtocolBugs{
11664 AlwaysRejectEarlyData: true,
11665 },
11666 },
11667 resumeSession: true,
11668 expectChannelID: true,
11669 flags: []string{
11670 "-enable-early-data",
11671 "-expect-early-data-info",
11672 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11673 "-expect-reject-early-data",
11674 },
11675 })
11676
11677 // Test that the client offering Channel ID and 0-RTT allows the server
11678 // to decline Channel ID.
11679 testCases = append(testCases, testCase{
11680 testType: clientTest,
11681 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11682 config: Config{
11683 MaxVersion: VersionTLS13,
11684 MaxEarlyDataSize: 16384,
11685 },
11686 resumeSession: true,
11687 flags: []string{
11688 "-enable-early-data",
11689 "-expect-early-data-info",
11690 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11691 "-expect-accept-early-data",
11692 },
11693 })
11694
11695 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11696 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011697 testCases = append(testCases, testCase{
11698 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011699 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011700 config: Config{
11701 MaxVersion: VersionTLS13,
11702 ChannelID: channelIDKey,
11703 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011704 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011705 ExpectEarlyDataAccepted: false,
11706 },
11707 },
11708 resumeSession: true,
11709 expectChannelID: true,
11710 flags: []string{
11711 "-enable-early-data",
11712 "-expect-reject-early-data",
11713 "-expect-channel-id",
11714 base64.StdEncoding.EncodeToString(channelIDBytes),
11715 },
11716 })
11717
David Benjamin6bb507b2017-03-29 16:35:57 -050011718 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11719 // if not offered Channel ID.
11720 testCases = append(testCases, testCase{
11721 testType: serverTest,
11722 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11723 config: Config{
11724 MaxVersion: VersionTLS13,
11725 Bugs: ProtocolBugs{
11726 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11727 ExpectEarlyDataAccepted: true,
11728 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11729 },
11730 },
11731 resumeSession: true,
11732 expectChannelID: false,
11733 flags: []string{
11734 "-enable-early-data",
11735 "-expect-accept-early-data",
11736 "-enable-channel-id",
11737 },
11738 })
11739
David Benjamin32c89272017-03-26 13:54:21 -050011740 // Test that the server rejects 0-RTT streams without end_of_early_data.
11741 // The subsequent records should fail to decrypt.
11742 testCases = append(testCases, testCase{
11743 testType: serverTest,
11744 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11745 config: Config{
11746 MaxVersion: VersionTLS13,
11747 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011748 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011749 ExpectEarlyDataAccepted: true,
11750 SkipEndOfEarlyData: true,
11751 },
11752 },
11753 resumeSession: true,
11754 flags: []string{"-enable-early-data"},
11755 shouldFail: true,
11756 expectedLocalError: "remote error: bad record MAC",
11757 expectedError: ":BAD_DECRYPT:",
11758 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011759
11760 testCases = append(testCases, testCase{
11761 testType: serverTest,
11762 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11763 config: Config{
11764 MaxVersion: VersionTLS13,
11765 },
11766 resumeConfig: &Config{
11767 MaxVersion: VersionTLS13,
11768 Bugs: ProtocolBugs{
11769 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11770 SendStrayEarlyHandshake: true,
11771 ExpectEarlyDataAccepted: true},
11772 },
11773 resumeSession: true,
11774 shouldFail: true,
11775 expectedError: ":UNEXPECTED_RECORD:",
11776 expectedLocalError: "remote error: unexpected message",
11777 flags: []string{
11778 "-enable-early-data",
11779 },
11780 })
David Benjamind9cbb532017-07-07 13:17:19 -040011781
11782 // Test that the client reports TLS 1.3 as the version while sending
11783 // early data.
11784 testCases = append(testCases, testCase{
11785 testType: clientTest,
11786 name: "TLS13-EarlyData-Client-VersionAPI",
11787 config: Config{
11788 MaxVersion: VersionTLS13,
11789 MaxEarlyDataSize: 16384,
11790 },
11791 resumeSession: true,
11792 flags: []string{
11793 "-enable-early-data",
11794 "-expect-early-data-info",
11795 "-expect-accept-early-data",
11796 "-expect-version", strconv.Itoa(VersionTLS13),
11797 },
11798 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011799}
11800
David Benjaminabbbee12016-10-31 19:20:42 -040011801func addTLS13CipherPreferenceTests() {
11802 // Test that client preference is honored if the shim has AES hardware
11803 // and ChaCha20-Poly1305 is preferred otherwise.
11804 testCases = append(testCases, testCase{
11805 testType: serverTest,
11806 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11807 config: Config{
11808 MaxVersion: VersionTLS13,
11809 CipherSuites: []uint16{
11810 TLS_CHACHA20_POLY1305_SHA256,
11811 TLS_AES_128_GCM_SHA256,
11812 },
11813 },
11814 flags: []string{
11815 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11816 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11817 },
11818 })
11819
11820 testCases = append(testCases, testCase{
11821 testType: serverTest,
11822 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11823 config: Config{
11824 MaxVersion: VersionTLS13,
11825 CipherSuites: []uint16{
11826 TLS_AES_128_GCM_SHA256,
11827 TLS_CHACHA20_POLY1305_SHA256,
11828 },
11829 },
11830 flags: []string{
11831 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11832 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11833 },
11834 })
11835
11836 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11837 // whether it has AES hardware.
11838 testCases = append(testCases, testCase{
11839 name: "TLS13-CipherPreference-Client",
11840 config: Config{
11841 MaxVersion: VersionTLS13,
11842 // Use the client cipher order. (This is the default but
11843 // is listed to be explicit.)
11844 PreferServerCipherSuites: false,
11845 },
11846 flags: []string{
11847 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11848 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11849 },
11850 })
11851}
11852
David Benjaminf3fbade2016-09-19 13:08:16 -040011853func addPeekTests() {
11854 // Test SSL_peek works, including on empty records.
11855 testCases = append(testCases, testCase{
11856 name: "Peek-Basic",
11857 sendEmptyRecords: 1,
11858 flags: []string{"-peek-then-read"},
11859 })
11860
11861 // Test SSL_peek can drive the initial handshake.
11862 testCases = append(testCases, testCase{
11863 name: "Peek-ImplicitHandshake",
11864 flags: []string{
11865 "-peek-then-read",
11866 "-implicit-handshake",
11867 },
11868 })
11869
11870 // Test SSL_peek can discover and drive a renegotiation.
11871 testCases = append(testCases, testCase{
11872 name: "Peek-Renegotiate",
11873 config: Config{
11874 MaxVersion: VersionTLS12,
11875 },
11876 renegotiate: 1,
11877 flags: []string{
11878 "-peek-then-read",
11879 "-renegotiate-freely",
11880 "-expect-total-renegotiations", "1",
11881 },
11882 })
11883
11884 // Test SSL_peek can discover a close_notify.
11885 testCases = append(testCases, testCase{
11886 name: "Peek-Shutdown",
11887 config: Config{
11888 Bugs: ProtocolBugs{
11889 ExpectCloseNotify: true,
11890 },
11891 },
11892 flags: []string{
11893 "-peek-then-read",
11894 "-check-close-notify",
11895 },
11896 })
11897
11898 // Test SSL_peek can discover an alert.
11899 testCases = append(testCases, testCase{
11900 name: "Peek-Alert",
11901 config: Config{
11902 Bugs: ProtocolBugs{
11903 SendSpuriousAlert: alertRecordOverflow,
11904 },
11905 },
11906 flags: []string{"-peek-then-read"},
11907 shouldFail: true,
11908 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11909 })
11910
11911 // Test SSL_peek can handle KeyUpdate.
11912 testCases = append(testCases, testCase{
11913 name: "Peek-KeyUpdate",
11914 config: Config{
11915 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011916 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011917 sendKeyUpdates: 1,
11918 keyUpdateRequest: keyUpdateNotRequested,
11919 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011920 })
11921}
11922
David Benjamine6f22212016-11-08 14:28:24 -050011923func addRecordVersionTests() {
11924 for _, ver := range tlsVersions {
11925 // Test that the record version is enforced.
11926 testCases = append(testCases, testCase{
11927 name: "CheckRecordVersion-" + ver.name,
11928 config: Config{
11929 MinVersion: ver.version,
11930 MaxVersion: ver.version,
11931 Bugs: ProtocolBugs{
11932 SendRecordVersion: 0x03ff,
11933 },
11934 },
David Benjamina5022392017-07-10 17:40:39 -040011935 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011936 shouldFail: true,
11937 expectedError: ":WRONG_VERSION_NUMBER:",
11938 })
11939
11940 // Test that the ClientHello may use any record version, for
11941 // compatibility reasons.
11942 testCases = append(testCases, testCase{
11943 testType: serverTest,
11944 name: "LooseInitialRecordVersion-" + ver.name,
11945 config: Config{
11946 MinVersion: ver.version,
11947 MaxVersion: ver.version,
11948 Bugs: ProtocolBugs{
11949 SendInitialRecordVersion: 0x03ff,
11950 },
11951 },
David Benjamina5022392017-07-10 17:40:39 -040011952 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011953 })
11954
11955 // Test that garbage ClientHello record versions are rejected.
11956 testCases = append(testCases, testCase{
11957 testType: serverTest,
11958 name: "GarbageInitialRecordVersion-" + ver.name,
11959 config: Config{
11960 MinVersion: ver.version,
11961 MaxVersion: ver.version,
11962 Bugs: ProtocolBugs{
11963 SendInitialRecordVersion: 0xffff,
11964 },
11965 },
David Benjamina5022392017-07-10 17:40:39 -040011966 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011967 shouldFail: true,
11968 expectedError: ":WRONG_VERSION_NUMBER:",
11969 })
11970 }
11971}
11972
David Benjamin2c516452016-11-15 10:16:54 +090011973func addCertificateTests() {
11974 // Test that a certificate chain with intermediate may be sent and
11975 // received as both client and server.
11976 for _, ver := range tlsVersions {
11977 testCases = append(testCases, testCase{
11978 testType: clientTest,
11979 name: "SendReceiveIntermediate-Client-" + ver.name,
11980 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011981 MinVersion: ver.version,
11982 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011983 Certificates: []Certificate{rsaChainCertificate},
11984 ClientAuth: RequireAnyClientCert,
11985 },
David Benjamina5022392017-07-10 17:40:39 -040011986 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011987 expectPeerCertificate: &rsaChainCertificate,
11988 flags: []string{
11989 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11990 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11991 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11992 },
11993 })
11994
11995 testCases = append(testCases, testCase{
11996 testType: serverTest,
11997 name: "SendReceiveIntermediate-Server-" + ver.name,
11998 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011999 MinVersion: ver.version,
12000 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012001 Certificates: []Certificate{rsaChainCertificate},
12002 },
David Benjamina5022392017-07-10 17:40:39 -040012003 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012004 expectPeerCertificate: &rsaChainCertificate,
12005 flags: []string{
12006 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12007 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12008 "-require-any-client-certificate",
12009 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12010 },
12011 })
12012 }
12013}
12014
David Benjaminbbaf3672016-11-17 10:53:09 +090012015func addRetainOnlySHA256ClientCertTests() {
12016 for _, ver := range tlsVersions {
12017 // Test that enabling
12018 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12019 // actually requesting a client certificate is a no-op.
12020 testCases = append(testCases, testCase{
12021 testType: serverTest,
12022 name: "RetainOnlySHA256-NoCert-" + ver.name,
12023 config: Config{
12024 MinVersion: ver.version,
12025 MaxVersion: ver.version,
12026 },
David Benjamina5022392017-07-10 17:40:39 -040012027 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012028 flags: []string{
12029 "-retain-only-sha256-client-cert-initial",
12030 "-retain-only-sha256-client-cert-resume",
12031 },
12032 resumeSession: true,
12033 })
12034
12035 // Test that when retaining only a SHA-256 certificate is
12036 // enabled, the hash appears as expected.
12037 testCases = append(testCases, testCase{
12038 testType: serverTest,
12039 name: "RetainOnlySHA256-Cert-" + ver.name,
12040 config: Config{
12041 MinVersion: ver.version,
12042 MaxVersion: ver.version,
12043 Certificates: []Certificate{rsaCertificate},
12044 },
David Benjamina5022392017-07-10 17:40:39 -040012045 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012046 flags: []string{
12047 "-verify-peer",
12048 "-retain-only-sha256-client-cert-initial",
12049 "-retain-only-sha256-client-cert-resume",
12050 "-expect-sha256-client-cert-initial",
12051 "-expect-sha256-client-cert-resume",
12052 },
12053 resumeSession: true,
12054 })
12055
12056 // Test that when the config changes from on to off, a
12057 // resumption is rejected because the server now wants the full
12058 // certificate chain.
12059 testCases = append(testCases, testCase{
12060 testType: serverTest,
12061 name: "RetainOnlySHA256-OnOff-" + ver.name,
12062 config: Config{
12063 MinVersion: ver.version,
12064 MaxVersion: ver.version,
12065 Certificates: []Certificate{rsaCertificate},
12066 },
David Benjamina5022392017-07-10 17:40:39 -040012067 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012068 flags: []string{
12069 "-verify-peer",
12070 "-retain-only-sha256-client-cert-initial",
12071 "-expect-sha256-client-cert-initial",
12072 },
12073 resumeSession: true,
12074 expectResumeRejected: true,
12075 })
12076
12077 // Test that when the config changes from off to on, a
12078 // resumption is rejected because the server now wants just the
12079 // hash.
12080 testCases = append(testCases, testCase{
12081 testType: serverTest,
12082 name: "RetainOnlySHA256-OffOn-" + ver.name,
12083 config: Config{
12084 MinVersion: ver.version,
12085 MaxVersion: ver.version,
12086 Certificates: []Certificate{rsaCertificate},
12087 },
David Benjamina5022392017-07-10 17:40:39 -040012088 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012089 flags: []string{
12090 "-verify-peer",
12091 "-retain-only-sha256-client-cert-resume",
12092 "-expect-sha256-client-cert-resume",
12093 },
12094 resumeSession: true,
12095 expectResumeRejected: true,
12096 })
12097 }
12098}
12099
Adam Langleya4b91982016-12-12 12:05:53 -080012100func addECDSAKeyUsageTests() {
12101 p256 := elliptic.P256()
12102 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12103 if err != nil {
12104 panic(err)
12105 }
12106
12107 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12108 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12109 if err != nil {
12110 panic(err)
12111 }
12112
12113 template := x509.Certificate{
12114 SerialNumber: serialNumber,
12115 Subject: pkix.Name{
12116 Organization: []string{"Acme Co"},
12117 },
12118 NotBefore: time.Now(),
12119 NotAfter: time.Now(),
12120
12121 // An ECC certificate with only the keyAgreement key usgae may
12122 // be used with ECDH, but not ECDSA.
12123 KeyUsage: x509.KeyUsageKeyAgreement,
12124 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12125 BasicConstraintsValid: true,
12126 }
12127
12128 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12129 if err != nil {
12130 panic(err)
12131 }
12132
12133 cert := Certificate{
12134 Certificate: [][]byte{derBytes},
12135 PrivateKey: priv,
12136 }
12137
12138 for _, ver := range tlsVersions {
12139 if ver.version < VersionTLS12 {
12140 continue
12141 }
12142
12143 testCases = append(testCases, testCase{
12144 testType: clientTest,
12145 name: "ECDSAKeyUsage-" + ver.name,
12146 config: Config{
12147 MinVersion: ver.version,
12148 MaxVersion: ver.version,
12149 Certificates: []Certificate{cert},
12150 },
David Benjamina5022392017-07-10 17:40:39 -040012151 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012152 shouldFail: true,
12153 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12154 })
12155 }
12156}
12157
David Benjamin8c26d752017-03-26 15:13:51 -050012158func addExtraHandshakeTests() {
12159 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12160 // to ensure there is no transport I/O.
12161 testCases = append(testCases, testCase{
12162 testType: clientTest,
12163 name: "ExtraHandshake-Client-TLS12",
12164 config: Config{
12165 MinVersion: VersionTLS12,
12166 MaxVersion: VersionTLS12,
12167 },
12168 flags: []string{
12169 "-async",
12170 "-no-op-extra-handshake",
12171 },
12172 })
12173 testCases = append(testCases, testCase{
12174 testType: serverTest,
12175 name: "ExtraHandshake-Server-TLS12",
12176 config: Config{
12177 MinVersion: VersionTLS12,
12178 MaxVersion: VersionTLS12,
12179 },
12180 flags: []string{
12181 "-async",
12182 "-no-op-extra-handshake",
12183 },
12184 })
12185 testCases = append(testCases, testCase{
12186 testType: clientTest,
12187 name: "ExtraHandshake-Client-TLS13",
12188 config: Config{
12189 MinVersion: VersionTLS13,
12190 MaxVersion: VersionTLS13,
12191 },
12192 flags: []string{
12193 "-async",
12194 "-no-op-extra-handshake",
12195 },
12196 })
12197 testCases = append(testCases, testCase{
12198 testType: serverTest,
12199 name: "ExtraHandshake-Server-TLS13",
12200 config: Config{
12201 MinVersion: VersionTLS13,
12202 MaxVersion: VersionTLS13,
12203 },
12204 flags: []string{
12205 "-async",
12206 "-no-op-extra-handshake",
12207 },
12208 })
12209
12210 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12211 testCases = append(testCases, testCase{
12212 testType: serverTest,
12213 name: "ExtraHandshake-Server-EarlyData-TLS13",
12214 config: Config{
12215 MaxVersion: VersionTLS13,
12216 MinVersion: VersionTLS13,
12217 Bugs: ProtocolBugs{
12218 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12219 ExpectEarlyDataAccepted: true,
12220 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12221 },
12222 },
12223 messageCount: 2,
12224 resumeSession: true,
12225 flags: []string{
12226 "-async",
12227 "-enable-early-data",
12228 "-expect-accept-early-data",
12229 "-no-op-extra-handshake",
12230 },
12231 })
12232
12233 // An extra SSL_do_handshake drives the handshake to completion in False
12234 // Start. We test this by handshaking twice and asserting the False
12235 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12236 // how the test works.
12237 testCases = append(testCases, testCase{
12238 testType: clientTest,
12239 name: "ExtraHandshake-FalseStart",
12240 config: Config{
12241 MaxVersion: VersionTLS12,
12242 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12243 NextProtos: []string{"foo"},
12244 Bugs: ProtocolBugs{
12245 ExpectFalseStart: true,
12246 AlertBeforeFalseStartTest: alertAccessDenied,
12247 },
12248 },
12249 flags: []string{
12250 "-handshake-twice",
12251 "-false-start",
12252 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012253 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012254 },
12255 shimWritesFirst: true,
12256 shouldFail: true,
12257 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12258 expectedLocalError: "tls: peer did not false start: EOF",
12259 })
12260}
12261
David Benjaminb853f312017-07-14 18:40:34 -040012262// Test that omitted and empty extensions blocks are tolerated.
12263func addOmitExtensionsTests() {
12264 for _, ver := range tlsVersions {
12265 if ver.version > VersionTLS12 {
12266 continue
12267 }
12268
12269 testCases = append(testCases, testCase{
12270 testType: serverTest,
12271 name: "OmitExtensions-ClientHello-" + ver.name,
12272 config: Config{
12273 MinVersion: ver.version,
12274 MaxVersion: ver.version,
12275 SessionTicketsDisabled: true,
12276 Bugs: ProtocolBugs{
12277 OmitExtensions: true,
12278 },
12279 },
12280 })
12281
12282 testCases = append(testCases, testCase{
12283 testType: serverTest,
12284 name: "EmptyExtensions-ClientHello-" + ver.name,
12285 config: Config{
12286 MinVersion: ver.version,
12287 MaxVersion: ver.version,
12288 SessionTicketsDisabled: true,
12289 Bugs: ProtocolBugs{
12290 EmptyExtensions: true,
12291 },
12292 },
12293 })
12294
12295 testCases = append(testCases, testCase{
12296 testType: clientTest,
12297 name: "OmitExtensions-ServerHello-" + ver.name,
12298 config: Config{
12299 MinVersion: ver.version,
12300 MaxVersion: ver.version,
12301 SessionTicketsDisabled: true,
12302 Bugs: ProtocolBugs{
12303 OmitExtensions: true,
12304 // Disable all ServerHello extensions so
12305 // OmitExtensions works.
12306 NoExtendedMasterSecret: true,
12307 NoRenegotiationInfo: true,
12308 },
12309 },
12310 })
12311
12312 testCases = append(testCases, testCase{
12313 testType: clientTest,
12314 name: "EmptyExtensions-ServerHello-" + ver.name,
12315 config: Config{
12316 MinVersion: ver.version,
12317 MaxVersion: ver.version,
12318 SessionTicketsDisabled: true,
12319 Bugs: ProtocolBugs{
12320 EmptyExtensions: true,
12321 // Disable all ServerHello extensions so
12322 // EmptyExtensions works.
12323 NoExtendedMasterSecret: true,
12324 NoRenegotiationInfo: true,
12325 },
12326 },
12327 })
12328 }
12329}
12330
Adam Langley7c803a62015-06-15 15:35:05 -070012331func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012332 defer wg.Done()
12333
12334 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012335 var err error
12336
David Benjaminba28dfc2016-11-15 17:47:21 +090012337 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012338 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12339 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012340 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012341 if err != nil {
12342 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12343 }
12344 break
12345 }
12346 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012347 } else if *repeatUntilFailure {
12348 for err == nil {
12349 statusChan <- statusMsg{test: test, started: true}
12350 err = runTest(test, shimPath, -1)
12351 }
12352 } else {
12353 statusChan <- statusMsg{test: test, started: true}
12354 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012355 }
Adam Langley95c29f32014-06-20 12:00:00 -070012356 statusChan <- statusMsg{test: test, err: err}
12357 }
12358}
12359
12360type statusMsg struct {
12361 test *testCase
12362 started bool
12363 err error
12364}
12365
David Benjamin5f237bc2015-02-11 17:14:15 -050012366func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012367 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012368
David Benjamin5f237bc2015-02-11 17:14:15 -050012369 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012370 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012371 if !*pipe {
12372 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012373 var erase string
12374 for i := 0; i < lineLen; i++ {
12375 erase += "\b \b"
12376 }
12377 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012378 }
12379
Adam Langley95c29f32014-06-20 12:00:00 -070012380 if msg.started {
12381 started++
12382 } else {
12383 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012384
12385 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012386 if msg.err == errUnimplemented {
12387 if *pipe {
12388 // Print each test instead of a status line.
12389 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12390 }
12391 unimplemented++
12392 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12393 } else {
12394 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12395 failed++
12396 testOutput.addResult(msg.test.name, "FAIL")
12397 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012398 } else {
12399 if *pipe {
12400 // Print each test instead of a status line.
12401 fmt.Printf("PASSED (%s)\n", msg.test.name)
12402 }
12403 testOutput.addResult(msg.test.name, "PASS")
12404 }
Adam Langley95c29f32014-06-20 12:00:00 -070012405 }
12406
David Benjamin5f237bc2015-02-11 17:14:15 -050012407 if !*pipe {
12408 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012409 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012410 lineLen = len(line)
12411 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012412 }
Adam Langley95c29f32014-06-20 12:00:00 -070012413 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012414
12415 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012416}
12417
12418func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012419 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012420 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012421 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012422
Adam Langley7c803a62015-06-15 15:35:05 -070012423 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012424 addCipherSuiteTests()
12425 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012426 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012427 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012428 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012429 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012430 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012431 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012432 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012433 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012434 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012435 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012436 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012437 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012438 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012439 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012440 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012441 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012442 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012443 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012444 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012445 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012446 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012447 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012448 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012449 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012450 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012451 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012452 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012453 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012454 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012455 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012456 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012457 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012458 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012459
12460 var wg sync.WaitGroup
12461
Adam Langley7c803a62015-06-15 15:35:05 -070012462 statusChan := make(chan statusMsg, *numWorkers)
12463 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012464 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012465
EKRf71d7ed2016-08-06 13:25:12 -070012466 if len(*shimConfigFile) != 0 {
12467 encoded, err := ioutil.ReadFile(*shimConfigFile)
12468 if err != nil {
12469 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12470 os.Exit(1)
12471 }
12472
12473 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12474 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12475 os.Exit(1)
12476 }
12477 }
12478
David Benjamin025b3d32014-07-01 19:53:04 -040012479 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012480
Adam Langley7c803a62015-06-15 15:35:05 -070012481 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012482 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012483 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012484 }
12485
David Benjamin270f0a72016-03-17 14:41:36 -040012486 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012487 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012488 matched := true
12489 if len(*testToRun) != 0 {
12490 var err error
12491 matched, err = filepath.Match(*testToRun, testCases[i].name)
12492 if err != nil {
12493 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12494 os.Exit(1)
12495 }
12496 }
12497
EKRf71d7ed2016-08-06 13:25:12 -070012498 if !*includeDisabled {
12499 for pattern := range shimConfig.DisabledTests {
12500 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12501 if err != nil {
12502 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12503 os.Exit(1)
12504 }
12505
12506 if isDisabled {
12507 matched = false
12508 break
12509 }
12510 }
12511 }
12512
David Benjamin17e12922016-07-28 18:04:43 -040012513 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012514 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012515 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012516
12517 // Only run one test if repeating until failure.
12518 if *repeatUntilFailure {
12519 break
12520 }
Adam Langley95c29f32014-06-20 12:00:00 -070012521 }
12522 }
David Benjamin17e12922016-07-28 18:04:43 -040012523
David Benjamin270f0a72016-03-17 14:41:36 -040012524 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012525 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012526 os.Exit(1)
12527 }
Adam Langley95c29f32014-06-20 12:00:00 -070012528
12529 close(testChan)
12530 wg.Wait()
12531 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012532 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012533
12534 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012535
12536 if *jsonOutput != "" {
12537 if err := testOutput.writeTo(*jsonOutput); err != nil {
12538 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12539 }
12540 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012541
EKR842ae6c2016-07-27 09:22:05 +020012542 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12543 os.Exit(1)
12544 }
12545
12546 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012547 os.Exit(1)
12548 }
Adam Langley95c29f32014-06-20 12:00:00 -070012549}