blob: 86f5f715d63baa46e1251acf6d4daefdac47acb6 [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) {
491 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
492 return 0, err
493 }
494 return t.Conn.Read(b)
495}
496
497func (t *timeoutConn) Write(b []byte) (int, error) {
498 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
499 return 0, err
500 }
501 return t.Conn.Write(b)
502}
503
David Benjamin0fde2eb2017-06-30 19:11:22 -0400504func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400505 if !test.noSessionCache {
506 if config.ClientSessionCache == nil {
507 config.ClientSessionCache = NewLRUClientSessionCache(1)
508 }
509 if config.ServerSessionCache == nil {
510 config.ServerSessionCache = NewLRUServerSessionCache(1)
511 }
512 }
513 if test.testType == clientTest {
514 if len(config.Certificates) == 0 {
515 config.Certificates = []Certificate{rsaCertificate}
516 }
517 } else {
518 // Supply a ServerName to ensure a constant session cache key,
519 // rather than falling back to net.Conn.RemoteAddr.
520 if len(config.ServerName) == 0 {
521 config.ServerName = "test"
522 }
523 }
524 if *fuzzer {
525 config.Bugs.NullAllCiphers = true
526 }
David Benjamin01a90572016-09-22 00:11:43 -0400527 if *deterministic {
528 config.Time = func() time.Time { return time.Unix(1234, 1234) }
529 }
David Benjamine54af062016-08-08 19:21:18 -0400530
David Benjamin01784b42016-06-07 18:00:52 -0400531 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500532
David Benjamin6fd297b2014-08-11 18:43:38 -0400533 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500534 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
535 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500536 }
537
David Benjamin9867b7d2016-03-01 23:25:48 -0500538 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500539 local, peer := "client", "server"
540 if test.testType == clientTest {
541 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500542 }
David Benjaminebda9b32015-11-02 15:33:18 -0500543 connDebug := &recordingConn{
544 Conn: conn,
545 isDatagram: test.protocol == dtls,
546 local: local,
547 peer: peer,
548 }
549 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500550 if *flagDebug {
551 defer connDebug.WriteTo(os.Stdout)
552 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400553 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500554 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400555 path := transcriptPrefix + strconv.Itoa(num)
556 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 }()
558 }
David Benjaminebda9b32015-11-02 15:33:18 -0500559
560 if config.Bugs.PacketAdaptor != nil {
561 config.Bugs.PacketAdaptor.debug = connDebug
562 }
563 }
564
565 if test.replayWrites {
566 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400567 }
568
David Benjamin3ed59772016-03-08 12:50:21 -0500569 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500570 if test.damageFirstWrite {
571 connDamage = newDamageAdaptor(conn)
572 conn = connDamage
573 }
574
David Benjamin6fd297b2014-08-11 18:43:38 -0400575 if test.sendPrefix != "" {
576 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
577 return err
578 }
David Benjamin98e882e2014-08-08 13:24:34 -0400579 }
580
David Benjamin1d5c83e2014-07-22 19:20:02 -0400581 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400582 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400583 if test.protocol == dtls {
584 tlsConn = DTLSServer(conn, config)
585 } else {
586 tlsConn = Server(conn, config)
587 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 } else {
589 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSClient(conn, config)
592 } else {
593 tlsConn = Client(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 }
David Benjamin30789da2015-08-29 22:56:45 -0400596 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400597
Adam Langley95c29f32014-06-20 12:00:00 -0700598 if err := tlsConn.Handshake(); err != nil {
599 return err
600 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700601
David Benjamin01fe8202014-09-24 15:21:44 -0400602 // TODO(davidben): move all per-connection expectations into a dedicated
603 // expectations struct that can be specified separately for the two
604 // legs.
605 expectedVersion := test.expectedVersion
606 if isResume && test.expectedResumeVersion != 0 {
607 expectedVersion = test.expectedResumeVersion
608 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700609 connState := tlsConn.ConnectionState()
610 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400611 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400612 }
613
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700614 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400615 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
616 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700617 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
618 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
619 }
David Benjamin90da8c82015-04-20 14:57:57 -0400620
David Benjamina08e49d2014-08-24 01:46:07 -0400621 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700622 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400623 if channelID == nil {
624 return fmt.Errorf("no channel ID negotiated")
625 }
626 if channelID.Curve != channelIDKey.Curve ||
627 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
628 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
629 return fmt.Errorf("incorrect channel ID")
630 }
David Benjamin634f4752017-07-01 11:08:41 -0400631 } else if connState.ChannelID != nil {
632 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400633 }
634
David Benjaminae2888f2014-09-06 12:58:58 -0400635 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700636 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400637 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
638 }
639 }
640
David Benjaminc7ce9772015-10-09 19:32:41 -0400641 if test.expectNoNextProto {
642 if actual := connState.NegotiatedProtocol; actual != "" {
643 return fmt.Errorf("got unexpected next proto %s", actual)
644 }
645 }
646
David Benjaminfc7b0862014-09-06 13:21:53 -0400647 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700648 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400649 return fmt.Errorf("next proto type mismatch")
650 }
651 }
652
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700653 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500654 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
655 }
656
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100657 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300658 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100659 }
660
Paul Lietar4fac72e2015-09-09 13:44:55 +0100661 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
662 return fmt.Errorf("SCT list mismatch")
663 }
664
Nick Harper60edffd2016-06-21 15:19:24 -0700665 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
666 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400667 }
668
Steven Valdez5440fe02016-07-18 12:40:30 -0400669 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
670 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
671 }
672
David Benjamin2c516452016-11-15 10:16:54 +0900673 if test.expectPeerCertificate != nil {
674 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
675 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
676 }
677 for i, cert := range connState.PeerCertificates {
678 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
679 return fmt.Errorf("peer certificate %d did not match", i+1)
680 }
681 }
682 }
683
David Benjaminc565ebb2015-04-03 04:06:36 -0400684 if test.exportKeyingMaterial > 0 {
685 actual := make([]byte, test.exportKeyingMaterial)
686 if _, err := io.ReadFull(tlsConn, actual); err != nil {
687 return err
688 }
689 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
690 if err != nil {
691 return err
692 }
693 if !bytes.Equal(actual, expected) {
694 return fmt.Errorf("keying material mismatch")
695 }
696 }
697
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700698 if test.testTLSUnique {
699 var peersValue [12]byte
700 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
701 return err
702 }
703 expected := tlsConn.ConnectionState().TLSUnique
704 if !bytes.Equal(peersValue[:], expected) {
705 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
706 }
707 }
708
David Benjamin47921102016-07-28 11:29:18 -0400709 if test.sendHalfHelloRequest {
710 tlsConn.SendHalfHelloRequest()
711 }
712
Steven Valdeze831a812017-03-09 14:56:07 -0500713 shimPrefix := test.shimPrefix
714 if isResume {
715 shimPrefix = test.resumeShimPrefix
716 }
717 if test.shimWritesFirst || test.readWithUnfinishedWrite {
718 shimPrefix = "hello"
719 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400720 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400721 // If readWithUnfinishedWrite is set, the shim prefix will be
722 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500723 if shimPrefix != "" && !test.readWithUnfinishedWrite {
724 var buf = make([]byte, len(shimPrefix))
725 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400726 if err != nil {
727 return err
728 }
Steven Valdeze831a812017-03-09 14:56:07 -0500729 if string(buf) != shimPrefix {
730 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400731 }
Steven Valdeze831a812017-03-09 14:56:07 -0500732 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400733 }
734
Adam Langleycf2d4f42014-10-28 19:06:14 -0700735 if test.renegotiateCiphers != nil {
736 config.CipherSuites = test.renegotiateCiphers
737 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400738 for i := 0; i < test.renegotiate; i++ {
739 if err := tlsConn.Renegotiate(); err != nil {
740 return err
741 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 }
743 } else if test.renegotiateCiphers != nil {
744 panic("renegotiateCiphers without renegotiate")
745 }
746
David Benjamin5fa3eba2015-01-22 16:35:40 -0500747 if test.damageFirstWrite {
748 connDamage.setDamage(true)
749 tlsConn.Write([]byte("DAMAGED WRITE"))
750 connDamage.setDamage(false)
751 }
752
David Benjamin8e6db492015-07-25 18:29:23 -0400753 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700754 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400755 if test.protocol == dtls {
756 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
757 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700758 // Read until EOF.
759 _, err := io.Copy(ioutil.Discard, tlsConn)
760 return err
761 }
David Benjamin4417d052015-04-05 04:17:25 -0400762 if messageLen == 0 {
763 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700764 }
Adam Langley95c29f32014-06-20 12:00:00 -0700765
David Benjamin8e6db492015-07-25 18:29:23 -0400766 messageCount := test.messageCount
767 if messageCount == 0 {
768 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400769 }
770
David Benjamin8e6db492015-07-25 18:29:23 -0400771 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400772 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400773 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400774 }
775
David Benjamin8e6db492015-07-25 18:29:23 -0400776 for i := 0; i < test.sendEmptyRecords; i++ {
777 tlsConn.Write(nil)
778 }
779
780 for i := 0; i < test.sendWarningAlerts; i++ {
781 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
782 }
783
David Benjamin24e58862017-06-14 18:45:29 -0400784 if test.sendBogusAlertType {
785 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
786 }
787
David Benjaminbbba9392017-04-06 12:54:12 -0400788 testMessage := make([]byte, messageLen)
789 for i := range testMessage {
790 testMessage[i] = 0x42 ^ byte(j)
791 }
792 tlsConn.Write(testMessage)
793
794 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500795 if shimPrefix != "" {
796 var buf = make([]byte, len(shimPrefix))
797 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400798 if err != nil {
799 return err
800 }
Steven Valdeze831a812017-03-09 14:56:07 -0500801 if string(buf) != shimPrefix {
802 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400803 }
Steven Valdeze831a812017-03-09 14:56:07 -0500804 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400805 }
806
David Benjamin4f75aaf2015-09-01 16:53:10 -0400807 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400808 // The shim will not respond.
809 continue
810 }
811
David Benjaminbbba9392017-04-06 12:54:12 -0400812 // Process the KeyUpdate ACK. However many KeyUpdates the runner
813 // sends, the shim should respond only once.
814 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
815 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
816 return err
817 }
818 }
819
David Benjamin8e6db492015-07-25 18:29:23 -0400820 buf := make([]byte, len(testMessage))
821 if test.protocol == dtls {
822 bufTmp := make([]byte, len(buf)+1)
823 n, err := tlsConn.Read(bufTmp)
824 if err != nil {
825 return err
826 }
827 if n != len(buf) {
828 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
829 }
830 copy(buf, bufTmp)
831 } else {
832 _, err := io.ReadFull(tlsConn, buf)
833 if err != nil {
834 return err
835 }
836 }
837
838 for i, v := range buf {
839 if v != testMessage[i]^0xff {
840 return fmt.Errorf("bad reply contents at byte %d", i)
841 }
Adam Langley95c29f32014-06-20 12:00:00 -0700842 }
843 }
844
845 return nil
846}
847
David Benjamin325b5c32014-07-01 19:40:31 -0400848func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400849 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700850 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400851 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700852 }
David Benjamin325b5c32014-07-01 19:40:31 -0400853 valgrindArgs = append(valgrindArgs, path)
854 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700855
David Benjamin325b5c32014-07-01 19:40:31 -0400856 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700857}
858
David Benjamin325b5c32014-07-01 19:40:31 -0400859func gdbOf(path string, args ...string) *exec.Cmd {
860 xtermArgs := []string{"-e", "gdb", "--args"}
861 xtermArgs = append(xtermArgs, path)
862 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700863
David Benjamin325b5c32014-07-01 19:40:31 -0400864 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700865}
866
David Benjamind16bf342015-12-18 00:53:12 -0500867func lldbOf(path string, args ...string) *exec.Cmd {
868 xtermArgs := []string{"-e", "lldb", "--"}
869 xtermArgs = append(xtermArgs, path)
870 xtermArgs = append(xtermArgs, args...)
871
872 return exec.Command("xterm", xtermArgs...)
873}
874
EKR842ae6c2016-07-27 09:22:05 +0200875var (
876 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
877 errUnimplemented = errors.New("child process does not implement needed flags")
878)
Adam Langley69a01602014-11-17 17:26:55 -0800879
David Benjamin87c8a642015-02-21 01:54:29 -0500880// accept accepts a connection from listener, unless waitChan signals a process
881// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400882func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500883 type connOrError struct {
884 conn net.Conn
885 err error
886 }
887 connChan := make(chan connOrError, 1)
888 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400889 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500890 conn, err := listener.Accept()
891 connChan <- connOrError{conn, err}
892 close(connChan)
893 }()
894 select {
895 case result := <-connChan:
896 return result.conn, result.err
897 case childErr := <-waitChan:
898 waitChan <- childErr
899 return nil, fmt.Errorf("child exited early: %s", childErr)
900 }
901}
902
EKRf71d7ed2016-08-06 13:25:12 -0700903func translateExpectedError(errorStr string) string {
904 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
905 return translated
906 }
907
908 if *looseErrors {
909 return ""
910 }
911
912 return errorStr
913}
914
Adam Langley7c803a62015-06-15 15:35:05 -0700915func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400916 // Help debugging panics on the Go side.
917 defer func() {
918 if r := recover(); r != nil {
919 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
920 panic(r)
921 }
922 }()
923
Adam Langley38311732014-10-16 19:04:35 -0700924 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
925 panic("Error expected without shouldFail in " + test.name)
926 }
927
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700928 if test.expectResumeRejected && !test.resumeSession {
929 panic("expectResumeRejected without resumeSession in " + test.name)
930 }
931
Adam Langley33b1d4f2016-12-07 15:03:45 -0800932 for _, ver := range tlsVersions {
933 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
934 continue
935 }
936
David Benjamina5022392017-07-10 17:40:39 -0400937 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
938 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 -0800939 }
940
David Benjamina5022392017-07-10 17:40:39 -0400941 if ver.tls13Variant != 0 {
942 var foundFlag bool
943 for _, flag := range test.flags {
944 if flag == "-tls13-variant" {
945 foundFlag = true
946 break
947 }
948 }
949 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
950 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))
951 }
952 }
953
Adam Langley33b1d4f2016-12-07 15:03:45 -0800954 }
955
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700956 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
957 if err != nil {
958 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
959 }
David Benjamin87c8a642015-02-21 01:54:29 -0500960 if err != nil {
961 panic(err)
962 }
963 defer func() {
964 if listener != nil {
965 listener.Close()
966 }
967 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700968
David Benjamin87c8a642015-02-21 01:54:29 -0500969 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400970 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400971 flags = append(flags, "-server")
972
David Benjamin025b3d32014-07-01 19:53:04 -0400973 flags = append(flags, "-key-file")
974 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700975 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400976 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700977 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400978 }
979
980 flags = append(flags, "-cert-file")
981 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700982 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400983 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700984 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400985 }
986 }
David Benjamin5a593af2014-08-11 19:51:50 -0400987
David Benjamin6fd297b2014-08-11 18:43:38 -0400988 if test.protocol == dtls {
989 flags = append(flags, "-dtls")
990 }
991
David Benjamin46662482016-08-17 00:51:00 -0400992 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400993 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400994 resumeCount++
995 if test.resumeRenewedSession {
996 resumeCount++
997 }
998 }
999
1000 if resumeCount > 0 {
1001 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001002 }
1003
David Benjamine58c4f52014-08-24 03:47:07 -04001004 if test.shimWritesFirst {
1005 flags = append(flags, "-shim-writes-first")
1006 }
1007
David Benjaminbbba9392017-04-06 12:54:12 -04001008 if test.readWithUnfinishedWrite {
1009 flags = append(flags, "-read-with-unfinished-write")
1010 }
1011
David Benjamin30789da2015-08-29 22:56:45 -04001012 if test.shimShutsDown {
1013 flags = append(flags, "-shim-shuts-down")
1014 }
1015
David Benjaminc565ebb2015-04-03 04:06:36 -04001016 if test.exportKeyingMaterial > 0 {
1017 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1018 flags = append(flags, "-export-label", test.exportLabel)
1019 flags = append(flags, "-export-context", test.exportContext)
1020 if test.useExportContext {
1021 flags = append(flags, "-use-export-context")
1022 }
1023 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001024 if test.expectResumeRejected {
1025 flags = append(flags, "-expect-session-miss")
1026 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001027
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001028 if test.testTLSUnique {
1029 flags = append(flags, "-tls-unique")
1030 }
1031
David Benjamina5022392017-07-10 17:40:39 -04001032 if test.tls13Variant != 0 {
1033 test.config.TLS13Variant = test.tls13Variant
1034 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1035 }
1036
David Benjamin0fde2eb2017-06-30 19:11:22 -04001037 var transcriptPrefix string
1038 if len(*transcriptDir) != 0 {
1039 protocol := "tls"
1040 if test.protocol == dtls {
1041 protocol = "dtls"
1042 }
1043
1044 side := "client"
1045 if test.testType == serverTest {
1046 side = "server"
1047 }
1048
1049 dir := filepath.Join(*transcriptDir, protocol, side)
1050 if err := os.MkdirAll(dir, 0755); err != nil {
1051 return err
1052 }
1053 transcriptPrefix = filepath.Join(dir, test.name+"-")
1054 flags = append(flags, "-write-settings", transcriptPrefix)
1055 }
1056
David Benjamin025b3d32014-07-01 19:53:04 -04001057 flags = append(flags, test.flags...)
1058
1059 var shim *exec.Cmd
1060 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001061 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001062 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001063 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001064 } else if *useLLDB {
1065 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001066 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001067 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001068 }
David Benjamin025b3d32014-07-01 19:53:04 -04001069 shim.Stdin = os.Stdin
1070 var stdoutBuf, stderrBuf bytes.Buffer
1071 shim.Stdout = &stdoutBuf
1072 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001073 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001074 shim.Env = os.Environ()
1075 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001076 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001077 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001078 }
1079 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1080 }
David Benjamin025b3d32014-07-01 19:53:04 -04001081
1082 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001083 panic(err)
1084 }
David Benjamin87c8a642015-02-21 01:54:29 -05001085 waitChan := make(chan error, 1)
1086 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001087
1088 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001089
David Benjamin7a4aaa42016-09-20 17:58:14 -04001090 if *deterministic {
1091 config.Rand = &deterministicRand{}
1092 }
1093
David Benjamin87c8a642015-02-21 01:54:29 -05001094 conn, err := acceptOrWait(listener, waitChan)
1095 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001096 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001097 conn.Close()
1098 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001099
David Benjamin46662482016-08-17 00:51:00 -04001100 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001101 var resumeConfig Config
1102 if test.resumeConfig != nil {
1103 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001104 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001105 resumeConfig.SessionTicketKey = config.SessionTicketKey
1106 resumeConfig.ClientSessionCache = config.ClientSessionCache
1107 resumeConfig.ServerSessionCache = config.ServerSessionCache
1108 }
David Benjamin2e045a92016-06-08 13:09:56 -04001109 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001110 } else {
1111 resumeConfig = config
1112 }
David Benjamin87c8a642015-02-21 01:54:29 -05001113 var connResume net.Conn
1114 connResume, err = acceptOrWait(listener, waitChan)
1115 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001116 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001117 connResume.Close()
1118 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001119 }
1120
David Benjamin87c8a642015-02-21 01:54:29 -05001121 // Close the listener now. This is to avoid hangs should the shim try to
1122 // open more connections than expected.
1123 listener.Close()
1124 listener = nil
1125
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001126 var shimKilledLock sync.Mutex
1127 var shimKilled bool
1128 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1129 shimKilledLock.Lock()
1130 shimKilled = true
1131 shimKilledLock.Unlock()
1132 shim.Process.Kill()
1133 })
David Benjamin87c8a642015-02-21 01:54:29 -05001134 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001135 waitTimeout.Stop()
1136 shimKilledLock.Lock()
1137 if shimKilled && err == nil {
1138 err = errors.New("timeout waiting for the shim to exit.")
1139 }
1140 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001141 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001142 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001143 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1144 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001145 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001146 case 89:
1147 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001148 case 99:
1149 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001150 }
1151 }
Adam Langley95c29f32014-06-20 12:00:00 -07001152
David Benjamin9bea3492016-03-02 10:59:16 -05001153 // Account for Windows line endings.
1154 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1155 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001156
1157 // Separate the errors from the shim and those from tools like
1158 // AddressSanitizer.
1159 var extraStderr string
1160 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1161 stderr = stderrParts[0]
1162 extraStderr = stderrParts[1]
1163 }
1164
Adam Langley95c29f32014-06-20 12:00:00 -07001165 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001166 expectedError := translateExpectedError(test.expectedError)
1167 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001168
Adam Langleyac61fa32014-06-23 12:03:11 -07001169 localError := "none"
1170 if err != nil {
1171 localError = err.Error()
1172 }
1173 if len(test.expectedLocalError) != 0 {
1174 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1175 }
Adam Langley95c29f32014-06-20 12:00:00 -07001176
1177 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001178 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001179 if childErr != nil {
1180 childError = childErr.Error()
1181 }
1182
1183 var msg string
1184 switch {
1185 case failed && !test.shouldFail:
1186 msg = "unexpected failure"
1187 case !failed && test.shouldFail:
1188 msg = "unexpected success"
1189 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001190 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001191 default:
1192 panic("internal error")
1193 }
1194
David Benjamin9aafb642016-09-20 19:36:53 -04001195 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 -07001196 }
1197
David Benjamind2ba8892016-09-20 19:41:04 -04001198 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001199 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001200 }
1201
David Benjamind2ba8892016-09-20 19:41:04 -04001202 if *useValgrind && isValgrindError {
1203 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1204 }
1205
Adam Langley95c29f32014-06-20 12:00:00 -07001206 return nil
1207}
1208
David Benjaminaa012042016-12-10 13:33:05 -05001209type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001210 name string
1211 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001212 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001213 // excludeFlag is the legacy shim flag to disable the version.
1214 excludeFlag string
1215 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001216 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1217 versionDTLS uint16
1218 // versionWire, if non-zero, is the wire representation of the
1219 // version. Otherwise the wire version is the protocol version or
1220 // versionDTLS.
1221 versionWire uint16
1222 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001223}
1224
1225func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001226 // The shim uses the protocol version in its public API, but uses the
1227 // DTLS-specific version if it exists.
1228 if protocol == dtls && vers.versionDTLS != 0 {
1229 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001230 }
Steven Valdez520e1222017-06-13 12:45:25 -04001231 return strconv.Itoa(int(vers.version))
1232}
1233
1234func (vers tlsVersion) wire(protocol protocol) uint16 {
1235 if protocol == dtls && vers.versionDTLS != 0 {
1236 return vers.versionDTLS
1237 }
1238 if vers.versionWire != 0 {
1239 return vers.versionWire
1240 }
1241 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001242}
1243
1244var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001245 {
1246 name: "SSL3",
1247 version: VersionSSL30,
1248 excludeFlag: "-no-ssl3",
1249 },
1250 {
1251 name: "TLS1",
1252 version: VersionTLS10,
1253 excludeFlag: "-no-tls1",
1254 hasDTLS: true,
1255 versionDTLS: VersionDTLS10,
1256 },
1257 {
1258 name: "TLS11",
1259 version: VersionTLS11,
1260 excludeFlag: "-no-tls11",
1261 },
1262 {
1263 name: "TLS12",
1264 version: VersionTLS12,
1265 excludeFlag: "-no-tls12",
1266 hasDTLS: true,
1267 versionDTLS: VersionDTLS12,
1268 },
1269 {
1270 name: "TLS13",
1271 version: VersionTLS13,
1272 excludeFlag: "-no-tls13",
1273 versionWire: tls13DraftVersion,
1274 tls13Variant: TLS13Default,
1275 },
1276 {
1277 name: "TLS13Experiment",
1278 version: VersionTLS13,
1279 excludeFlag: "-no-tls13",
1280 versionWire: tls13ExperimentVersion,
1281 tls13Variant: TLS13Experiment,
1282 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001283 {
1284 name: "TLS13RecordTypeExperiment",
1285 version: VersionTLS13,
1286 excludeFlag: "-no-tls13",
1287 versionWire: tls13RecordTypeExperimentVersion,
1288 tls13Variant: TLS13RecordTypeExperiment,
1289 },
Steven Valdez520e1222017-06-13 12:45:25 -04001290}
1291
1292func allVersions(protocol protocol) []tlsVersion {
1293 if protocol == tls {
1294 return tlsVersions
1295 }
1296
1297 var ret []tlsVersion
1298 for _, vers := range tlsVersions {
1299 if vers.hasDTLS {
1300 ret = append(ret, vers)
1301 }
1302 }
1303 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001304}
1305
David Benjaminaa012042016-12-10 13:33:05 -05001306type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001307 name string
1308 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001309}
1310
1311var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001312 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001313 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001314 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001315 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001316 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001317 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001318 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001319 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1320 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001321 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1322 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001323 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001324 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001325 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001326 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001327 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001328 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001329 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001330 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001332 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001333 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1334 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001335 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1336 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001337 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001338 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1339 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1340 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001341 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001342}
1343
David Benjamin8b8c0062014-11-23 02:47:52 -05001344func hasComponent(suiteName, component string) bool {
1345 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1346}
1347
David Benjaminf7768e42014-08-31 02:06:47 -04001348func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001349 return hasComponent(suiteName, "GCM") ||
1350 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001351 hasComponent(suiteName, "SHA384") ||
1352 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001353}
1354
Nick Harper1fd39d82016-06-14 18:14:35 -07001355func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001356 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001357}
1358
David Benjamin8b8c0062014-11-23 02:47:52 -05001359func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001360 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001361}
1362
Adam Langleya7997f12015-05-14 17:38:50 -07001363func bigFromHex(hex string) *big.Int {
1364 ret, ok := new(big.Int).SetString(hex, 16)
1365 if !ok {
1366 panic("failed to parse hex number 0x" + hex)
1367 }
1368 return ret
1369}
1370
Adam Langley7c803a62015-06-15 15:35:05 -07001371func addBasicTests() {
1372 basicTests := []testCase{
1373 {
Adam Langley7c803a62015-06-15 15:35:05 -07001374 name: "NoFallbackSCSV",
1375 config: Config{
1376 Bugs: ProtocolBugs{
1377 FailIfNotFallbackSCSV: true,
1378 },
1379 },
1380 shouldFail: true,
1381 expectedLocalError: "no fallback SCSV found",
1382 },
1383 {
1384 name: "SendFallbackSCSV",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 FailIfNotFallbackSCSV: true,
1388 },
1389 },
1390 flags: []string{"-fallback-scsv"},
1391 },
1392 {
1393 name: "ClientCertificateTypes",
1394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001395 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001396 ClientAuth: RequestClientCert,
1397 ClientCertificateTypes: []byte{
1398 CertTypeDSSSign,
1399 CertTypeRSASign,
1400 CertTypeECDSASign,
1401 },
1402 },
1403 flags: []string{
1404 "-expect-certificate-types",
1405 base64.StdEncoding.EncodeToString([]byte{
1406 CertTypeDSSSign,
1407 CertTypeRSASign,
1408 CertTypeECDSASign,
1409 }),
1410 },
1411 },
1412 {
Adam Langley7c803a62015-06-15 15:35:05 -07001413 name: "UnauthenticatedECDH",
1414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001415 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1417 Bugs: ProtocolBugs{
1418 UnauthenticatedECDH: true,
1419 },
1420 },
1421 shouldFail: true,
1422 expectedError: ":UNEXPECTED_MESSAGE:",
1423 },
1424 {
1425 name: "SkipCertificateStatus",
1426 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001427 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001428 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1429 Bugs: ProtocolBugs{
1430 SkipCertificateStatus: true,
1431 },
1432 },
1433 flags: []string{
1434 "-enable-ocsp-stapling",
1435 },
1436 },
1437 {
1438 name: "SkipServerKeyExchange",
1439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001440 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001441 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1442 Bugs: ProtocolBugs{
1443 SkipServerKeyExchange: true,
1444 },
1445 },
1446 shouldFail: true,
1447 expectedError: ":UNEXPECTED_MESSAGE:",
1448 },
1449 {
Adam Langley7c803a62015-06-15 15:35:05 -07001450 testType: serverTest,
1451 name: "Alert",
1452 config: Config{
1453 Bugs: ProtocolBugs{
1454 SendSpuriousAlert: alertRecordOverflow,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1459 },
1460 {
1461 protocol: dtls,
1462 testType: serverTest,
1463 name: "Alert-DTLS",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 SendSpuriousAlert: alertRecordOverflow,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1471 },
1472 {
1473 testType: serverTest,
1474 name: "FragmentAlert",
1475 config: Config{
1476 Bugs: ProtocolBugs{
1477 FragmentAlert: true,
1478 SendSpuriousAlert: alertRecordOverflow,
1479 },
1480 },
1481 shouldFail: true,
1482 expectedError: ":BAD_ALERT:",
1483 },
1484 {
1485 protocol: dtls,
1486 testType: serverTest,
1487 name: "FragmentAlert-DTLS",
1488 config: Config{
1489 Bugs: ProtocolBugs{
1490 FragmentAlert: true,
1491 SendSpuriousAlert: alertRecordOverflow,
1492 },
1493 },
1494 shouldFail: true,
1495 expectedError: ":BAD_ALERT:",
1496 },
1497 {
1498 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001499 name: "DoubleAlert",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 DoubleAlert: true,
1503 SendSpuriousAlert: alertRecordOverflow,
1504 },
1505 },
1506 shouldFail: true,
1507 expectedError: ":BAD_ALERT:",
1508 },
1509 {
1510 protocol: dtls,
1511 testType: serverTest,
1512 name: "DoubleAlert-DTLS",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 DoubleAlert: true,
1516 SendSpuriousAlert: alertRecordOverflow,
1517 },
1518 },
1519 shouldFail: true,
1520 expectedError: ":BAD_ALERT:",
1521 },
1522 {
Adam Langley7c803a62015-06-15 15:35:05 -07001523 name: "SkipNewSessionTicket",
1524 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001525 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001526 Bugs: ProtocolBugs{
1527 SkipNewSessionTicket: true,
1528 },
1529 },
1530 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001531 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001532 },
1533 {
1534 testType: serverTest,
1535 name: "FallbackSCSV",
1536 config: Config{
1537 MaxVersion: VersionTLS11,
1538 Bugs: ProtocolBugs{
1539 SendFallbackSCSV: true,
1540 },
1541 },
David Benjamin56cadc32016-12-16 19:54:11 -05001542 shouldFail: true,
1543 expectedError: ":INAPPROPRIATE_FALLBACK:",
1544 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001545 },
1546 {
1547 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001548 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001549 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001550 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001551 Bugs: ProtocolBugs{
1552 SendFallbackSCSV: true,
1553 },
1554 },
1555 },
1556 {
1557 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001558 name: "FallbackSCSV-VersionMatch-TLS12",
1559 config: Config{
1560 MaxVersion: VersionTLS12,
1561 Bugs: ProtocolBugs{
1562 SendFallbackSCSV: true,
1563 },
1564 },
1565 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1566 },
1567 {
1568 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001569 name: "FragmentedClientVersion",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 MaxHandshakeRecordLength: 1,
1573 FragmentClientVersion: true,
1574 },
1575 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001576 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001577 },
1578 {
Adam Langley7c803a62015-06-15 15:35:05 -07001579 testType: serverTest,
1580 name: "HttpGET",
1581 sendPrefix: "GET / HTTP/1.0\n",
1582 shouldFail: true,
1583 expectedError: ":HTTP_REQUEST:",
1584 },
1585 {
1586 testType: serverTest,
1587 name: "HttpPOST",
1588 sendPrefix: "POST / HTTP/1.0\n",
1589 shouldFail: true,
1590 expectedError: ":HTTP_REQUEST:",
1591 },
1592 {
1593 testType: serverTest,
1594 name: "HttpHEAD",
1595 sendPrefix: "HEAD / HTTP/1.0\n",
1596 shouldFail: true,
1597 expectedError: ":HTTP_REQUEST:",
1598 },
1599 {
1600 testType: serverTest,
1601 name: "HttpPUT",
1602 sendPrefix: "PUT / HTTP/1.0\n",
1603 shouldFail: true,
1604 expectedError: ":HTTP_REQUEST:",
1605 },
1606 {
1607 testType: serverTest,
1608 name: "HttpCONNECT",
1609 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1610 shouldFail: true,
1611 expectedError: ":HTTPS_PROXY_REQUEST:",
1612 },
1613 {
1614 testType: serverTest,
1615 name: "Garbage",
1616 sendPrefix: "blah",
1617 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001618 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001619 },
1620 {
Adam Langley7c803a62015-06-15 15:35:05 -07001621 name: "RSAEphemeralKey",
1622 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001623 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001624 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1625 Bugs: ProtocolBugs{
1626 RSAEphemeralKey: true,
1627 },
1628 },
1629 shouldFail: true,
1630 expectedError: ":UNEXPECTED_MESSAGE:",
1631 },
1632 {
1633 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001634 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001635 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001636 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001637 },
1638 {
1639 protocol: dtls,
1640 name: "DisableEverything-DTLS",
1641 flags: []string{"-no-tls12", "-no-tls1"},
1642 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001643 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001644 },
1645 {
Adam Langley7c803a62015-06-15 15:35:05 -07001646 protocol: dtls,
1647 testType: serverTest,
1648 name: "MTU",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 MaxPacketLength: 256,
1652 },
1653 },
1654 flags: []string{"-mtu", "256"},
1655 },
1656 {
1657 protocol: dtls,
1658 testType: serverTest,
1659 name: "MTUExceeded",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 MaxPacketLength: 255,
1663 },
1664 },
1665 flags: []string{"-mtu", "256"},
1666 shouldFail: true,
1667 expectedLocalError: "dtls: exceeded maximum packet length",
1668 },
1669 {
Adam Langley7c803a62015-06-15 15:35:05 -07001670 name: "EmptyCertificateList",
1671 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001672 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001673 Bugs: ProtocolBugs{
1674 EmptyCertificateList: true,
1675 },
1676 },
1677 shouldFail: true,
1678 expectedError: ":DECODE_ERROR:",
1679 },
1680 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001681 name: "EmptyCertificateList-TLS13",
1682 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001683 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001684 Bugs: ProtocolBugs{
1685 EmptyCertificateList: true,
1686 },
1687 },
1688 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001689 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001690 },
1691 {
Adam Langley7c803a62015-06-15 15:35:05 -07001692 name: "TLSFatalBadPackets",
1693 damageFirstWrite: true,
1694 shouldFail: true,
1695 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1696 },
1697 {
1698 protocol: dtls,
1699 name: "DTLSIgnoreBadPackets",
1700 damageFirstWrite: true,
1701 },
1702 {
1703 protocol: dtls,
1704 name: "DTLSIgnoreBadPackets-Async",
1705 damageFirstWrite: true,
1706 flags: []string{"-async"},
1707 },
1708 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001709 name: "AppDataBeforeHandshake",
1710 config: Config{
1711 Bugs: ProtocolBugs{
1712 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1713 },
1714 },
1715 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001716 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001717 },
1718 {
1719 name: "AppDataBeforeHandshake-Empty",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 AppDataBeforeHandshake: []byte{},
1723 },
1724 },
1725 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001726 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001727 },
1728 {
1729 protocol: dtls,
1730 name: "AppDataBeforeHandshake-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1734 },
1735 },
1736 shouldFail: true,
1737 expectedError: ":UNEXPECTED_RECORD:",
1738 },
1739 {
1740 protocol: dtls,
1741 name: "AppDataBeforeHandshake-DTLS-Empty",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 AppDataBeforeHandshake: []byte{},
1745 },
1746 },
1747 shouldFail: true,
1748 expectedError: ":UNEXPECTED_RECORD:",
1749 },
1750 {
Adam Langley7c803a62015-06-15 15:35:05 -07001751 name: "AppDataAfterChangeCipherSpec",
1752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001753 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001754 Bugs: ProtocolBugs{
1755 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1756 },
1757 },
1758 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001759 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001760 },
1761 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001762 name: "AppDataAfterChangeCipherSpec-Empty",
1763 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001764 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001765 Bugs: ProtocolBugs{
1766 AppDataAfterChangeCipherSpec: []byte{},
1767 },
1768 },
1769 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001770 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001771 },
1772 {
Adam Langley7c803a62015-06-15 15:35:05 -07001773 protocol: dtls,
1774 name: "AppDataAfterChangeCipherSpec-DTLS",
1775 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001776 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001777 Bugs: ProtocolBugs{
1778 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1779 },
1780 },
1781 // BoringSSL's DTLS implementation will drop the out-of-order
1782 // application data.
1783 },
1784 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001785 protocol: dtls,
1786 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001788 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001789 Bugs: ProtocolBugs{
1790 AppDataAfterChangeCipherSpec: []byte{},
1791 },
1792 },
1793 // BoringSSL's DTLS implementation will drop the out-of-order
1794 // application data.
1795 },
1796 {
Adam Langley7c803a62015-06-15 15:35:05 -07001797 name: "AlertAfterChangeCipherSpec",
1798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001799 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001800 Bugs: ProtocolBugs{
1801 AlertAfterChangeCipherSpec: alertRecordOverflow,
1802 },
1803 },
1804 shouldFail: true,
1805 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1806 },
1807 {
1808 protocol: dtls,
1809 name: "AlertAfterChangeCipherSpec-DTLS",
1810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001811 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001812 Bugs: ProtocolBugs{
1813 AlertAfterChangeCipherSpec: alertRecordOverflow,
1814 },
1815 },
1816 shouldFail: true,
1817 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1818 },
1819 {
1820 protocol: dtls,
1821 name: "ReorderHandshakeFragments-Small-DTLS",
1822 config: Config{
1823 Bugs: ProtocolBugs{
1824 ReorderHandshakeFragments: true,
1825 // Small enough that every handshake message is
1826 // fragmented.
1827 MaxHandshakeRecordLength: 2,
1828 },
1829 },
1830 },
1831 {
1832 protocol: dtls,
1833 name: "ReorderHandshakeFragments-Large-DTLS",
1834 config: Config{
1835 Bugs: ProtocolBugs{
1836 ReorderHandshakeFragments: true,
1837 // Large enough that no handshake message is
1838 // fragmented.
1839 MaxHandshakeRecordLength: 2048,
1840 },
1841 },
1842 },
1843 {
1844 protocol: dtls,
1845 name: "MixCompleteMessageWithFragments-DTLS",
1846 config: Config{
1847 Bugs: ProtocolBugs{
1848 ReorderHandshakeFragments: true,
1849 MixCompleteMessageWithFragments: true,
1850 MaxHandshakeRecordLength: 2,
1851 },
1852 },
1853 },
1854 {
1855 name: "SendInvalidRecordType",
1856 config: Config{
1857 Bugs: ProtocolBugs{
1858 SendInvalidRecordType: true,
1859 },
1860 },
1861 shouldFail: true,
1862 expectedError: ":UNEXPECTED_RECORD:",
1863 },
1864 {
1865 protocol: dtls,
1866 name: "SendInvalidRecordType-DTLS",
1867 config: Config{
1868 Bugs: ProtocolBugs{
1869 SendInvalidRecordType: true,
1870 },
1871 },
1872 shouldFail: true,
1873 expectedError: ":UNEXPECTED_RECORD:",
1874 },
1875 {
1876 name: "FalseStart-SkipServerSecondLeg",
1877 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001878 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001879 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1880 NextProtos: []string{"foo"},
1881 Bugs: ProtocolBugs{
1882 SkipNewSessionTicket: true,
1883 SkipChangeCipherSpec: true,
1884 SkipFinished: true,
1885 ExpectFalseStart: true,
1886 },
1887 },
1888 flags: []string{
1889 "-false-start",
1890 "-handshake-never-done",
1891 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001892 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001893 },
1894 shimWritesFirst: true,
1895 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001896 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001897 },
1898 {
1899 name: "FalseStart-SkipServerSecondLeg-Implicit",
1900 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001901 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001902 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1903 NextProtos: []string{"foo"},
1904 Bugs: ProtocolBugs{
1905 SkipNewSessionTicket: true,
1906 SkipChangeCipherSpec: true,
1907 SkipFinished: true,
1908 },
1909 },
1910 flags: []string{
1911 "-implicit-handshake",
1912 "-false-start",
1913 "-handshake-never-done",
1914 "-advertise-alpn", "\x03foo",
1915 },
1916 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001917 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001918 },
1919 {
1920 testType: serverTest,
1921 name: "FailEarlyCallback",
1922 flags: []string{"-fail-early-callback"},
1923 shouldFail: true,
1924 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001925 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001926 },
1927 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001928 name: "FailCertCallback-Client-TLS12",
1929 config: Config{
1930 MaxVersion: VersionTLS12,
1931 ClientAuth: RequestClientCert,
1932 },
1933 flags: []string{"-fail-cert-callback"},
1934 shouldFail: true,
1935 expectedError: ":CERT_CB_ERROR:",
1936 expectedLocalError: "remote error: internal error",
1937 },
1938 {
1939 testType: serverTest,
1940 name: "FailCertCallback-Server-TLS12",
1941 config: Config{
1942 MaxVersion: VersionTLS12,
1943 },
1944 flags: []string{"-fail-cert-callback"},
1945 shouldFail: true,
1946 expectedError: ":CERT_CB_ERROR:",
1947 expectedLocalError: "remote error: internal error",
1948 },
1949 {
1950 name: "FailCertCallback-Client-TLS13",
1951 config: Config{
1952 MaxVersion: VersionTLS13,
1953 ClientAuth: RequestClientCert,
1954 },
1955 flags: []string{"-fail-cert-callback"},
1956 shouldFail: true,
1957 expectedError: ":CERT_CB_ERROR:",
1958 expectedLocalError: "remote error: internal error",
1959 },
1960 {
1961 testType: serverTest,
1962 name: "FailCertCallback-Server-TLS13",
1963 config: Config{
1964 MaxVersion: VersionTLS13,
1965 },
1966 flags: []string{"-fail-cert-callback"},
1967 shouldFail: true,
1968 expectedError: ":CERT_CB_ERROR:",
1969 expectedLocalError: "remote error: internal error",
1970 },
1971 {
Adam Langley7c803a62015-06-15 15:35:05 -07001972 protocol: dtls,
1973 name: "FragmentMessageTypeMismatch-DTLS",
1974 config: Config{
1975 Bugs: ProtocolBugs{
1976 MaxHandshakeRecordLength: 2,
1977 FragmentMessageTypeMismatch: true,
1978 },
1979 },
1980 shouldFail: true,
1981 expectedError: ":FRAGMENT_MISMATCH:",
1982 },
1983 {
1984 protocol: dtls,
1985 name: "FragmentMessageLengthMismatch-DTLS",
1986 config: Config{
1987 Bugs: ProtocolBugs{
1988 MaxHandshakeRecordLength: 2,
1989 FragmentMessageLengthMismatch: true,
1990 },
1991 },
1992 shouldFail: true,
1993 expectedError: ":FRAGMENT_MISMATCH:",
1994 },
1995 {
1996 protocol: dtls,
1997 name: "SplitFragments-Header-DTLS",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SplitFragments: 2,
2001 },
2002 },
2003 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002004 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002005 },
2006 {
2007 protocol: dtls,
2008 name: "SplitFragments-Boundary-DTLS",
2009 config: Config{
2010 Bugs: ProtocolBugs{
2011 SplitFragments: dtlsRecordHeaderLen,
2012 },
2013 },
2014 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002015 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002016 },
2017 {
2018 protocol: dtls,
2019 name: "SplitFragments-Body-DTLS",
2020 config: Config{
2021 Bugs: ProtocolBugs{
2022 SplitFragments: dtlsRecordHeaderLen + 1,
2023 },
2024 },
2025 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002026 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002027 },
2028 {
2029 protocol: dtls,
2030 name: "SendEmptyFragments-DTLS",
2031 config: Config{
2032 Bugs: ProtocolBugs{
2033 SendEmptyFragments: true,
2034 },
2035 },
2036 },
2037 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002038 name: "BadFinished-Client",
2039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002040 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002041 Bugs: ProtocolBugs{
2042 BadFinished: true,
2043 },
2044 },
2045 shouldFail: true,
2046 expectedError: ":DIGEST_CHECK_FAILED:",
2047 },
2048 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002049 name: "BadFinished-Client-TLS13",
2050 config: Config{
2051 MaxVersion: VersionTLS13,
2052 Bugs: ProtocolBugs{
2053 BadFinished: true,
2054 },
2055 },
2056 shouldFail: true,
2057 expectedError: ":DIGEST_CHECK_FAILED:",
2058 },
2059 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002060 testType: serverTest,
2061 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002063 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002064 Bugs: ProtocolBugs{
2065 BadFinished: true,
2066 },
2067 },
2068 shouldFail: true,
2069 expectedError: ":DIGEST_CHECK_FAILED:",
2070 },
2071 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002072 testType: serverTest,
2073 name: "BadFinished-Server-TLS13",
2074 config: Config{
2075 MaxVersion: VersionTLS13,
2076 Bugs: ProtocolBugs{
2077 BadFinished: true,
2078 },
2079 },
2080 shouldFail: true,
2081 expectedError: ":DIGEST_CHECK_FAILED:",
2082 },
2083 {
Adam Langley7c803a62015-06-15 15:35:05 -07002084 name: "FalseStart-BadFinished",
2085 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002086 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002087 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2088 NextProtos: []string{"foo"},
2089 Bugs: ProtocolBugs{
2090 BadFinished: true,
2091 ExpectFalseStart: true,
2092 },
2093 },
2094 flags: []string{
2095 "-false-start",
2096 "-handshake-never-done",
2097 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002098 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002099 },
2100 shimWritesFirst: true,
2101 shouldFail: true,
2102 expectedError: ":DIGEST_CHECK_FAILED:",
2103 },
2104 {
2105 name: "NoFalseStart-NoALPN",
2106 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002107 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002108 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2109 Bugs: ProtocolBugs{
2110 ExpectFalseStart: true,
2111 AlertBeforeFalseStartTest: alertAccessDenied,
2112 },
2113 },
2114 flags: []string{
2115 "-false-start",
2116 },
2117 shimWritesFirst: true,
2118 shouldFail: true,
2119 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2120 expectedLocalError: "tls: peer did not false start: EOF",
2121 },
2122 {
2123 name: "NoFalseStart-NoAEAD",
2124 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002125 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002126 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2127 NextProtos: []string{"foo"},
2128 Bugs: ProtocolBugs{
2129 ExpectFalseStart: true,
2130 AlertBeforeFalseStartTest: alertAccessDenied,
2131 },
2132 },
2133 flags: []string{
2134 "-false-start",
2135 "-advertise-alpn", "\x03foo",
2136 },
2137 shimWritesFirst: true,
2138 shouldFail: true,
2139 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2140 expectedLocalError: "tls: peer did not false start: EOF",
2141 },
2142 {
2143 name: "NoFalseStart-RSA",
2144 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002145 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002146 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2147 NextProtos: []string{"foo"},
2148 Bugs: ProtocolBugs{
2149 ExpectFalseStart: true,
2150 AlertBeforeFalseStartTest: alertAccessDenied,
2151 },
2152 },
2153 flags: []string{
2154 "-false-start",
2155 "-advertise-alpn", "\x03foo",
2156 },
2157 shimWritesFirst: true,
2158 shouldFail: true,
2159 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2160 expectedLocalError: "tls: peer did not false start: EOF",
2161 },
2162 {
Adam Langley7c803a62015-06-15 15:35:05 -07002163 protocol: dtls,
2164 name: "SendSplitAlert-Sync",
2165 config: Config{
2166 Bugs: ProtocolBugs{
2167 SendSplitAlert: true,
2168 },
2169 },
2170 },
2171 {
2172 protocol: dtls,
2173 name: "SendSplitAlert-Async",
2174 config: Config{
2175 Bugs: ProtocolBugs{
2176 SendSplitAlert: true,
2177 },
2178 },
2179 flags: []string{"-async"},
2180 },
2181 {
2182 protocol: dtls,
2183 name: "PackDTLSHandshake",
2184 config: Config{
2185 Bugs: ProtocolBugs{
2186 MaxHandshakeRecordLength: 2,
2187 PackHandshakeFragments: 20,
2188 PackHandshakeRecords: 200,
2189 },
2190 },
2191 },
2192 {
Adam Langley7c803a62015-06-15 15:35:05 -07002193 name: "SendEmptyRecords-Pass",
2194 sendEmptyRecords: 32,
2195 },
2196 {
2197 name: "SendEmptyRecords",
2198 sendEmptyRecords: 33,
2199 shouldFail: true,
2200 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2201 },
2202 {
2203 name: "SendEmptyRecords-Async",
2204 sendEmptyRecords: 33,
2205 flags: []string{"-async"},
2206 shouldFail: true,
2207 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2208 },
2209 {
David Benjamine8e84b92016-08-03 15:39:47 -04002210 name: "SendWarningAlerts-Pass",
2211 config: Config{
2212 MaxVersion: VersionTLS12,
2213 },
Adam Langley7c803a62015-06-15 15:35:05 -07002214 sendWarningAlerts: 4,
2215 },
2216 {
David Benjamine8e84b92016-08-03 15:39:47 -04002217 protocol: dtls,
2218 name: "SendWarningAlerts-DTLS-Pass",
2219 config: Config{
2220 MaxVersion: VersionTLS12,
2221 },
Adam Langley7c803a62015-06-15 15:35:05 -07002222 sendWarningAlerts: 4,
2223 },
2224 {
David Benjamine8e84b92016-08-03 15:39:47 -04002225 name: "SendWarningAlerts-TLS13",
2226 config: Config{
2227 MaxVersion: VersionTLS13,
2228 },
2229 sendWarningAlerts: 4,
2230 shouldFail: true,
2231 expectedError: ":BAD_ALERT:",
2232 expectedLocalError: "remote error: error decoding message",
2233 },
2234 {
2235 name: "SendWarningAlerts",
2236 config: Config{
2237 MaxVersion: VersionTLS12,
2238 },
Adam Langley7c803a62015-06-15 15:35:05 -07002239 sendWarningAlerts: 5,
2240 shouldFail: true,
2241 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2242 },
2243 {
David Benjamine8e84b92016-08-03 15:39:47 -04002244 name: "SendWarningAlerts-Async",
2245 config: Config{
2246 MaxVersion: VersionTLS12,
2247 },
Adam Langley7c803a62015-06-15 15:35:05 -07002248 sendWarningAlerts: 5,
2249 flags: []string{"-async"},
2250 shouldFail: true,
2251 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2252 },
David Benjaminba4594a2015-06-18 18:36:15 -04002253 {
David Benjamin24e58862017-06-14 18:45:29 -04002254 name: "SendBogusAlertType",
2255 sendBogusAlertType: true,
2256 shouldFail: true,
2257 expectedError: ":UNKNOWN_ALERT_TYPE:",
2258 expectedLocalError: "remote error: illegal parameter",
2259 },
2260 {
2261 protocol: dtls,
2262 name: "SendBogusAlertType-DTLS",
2263 sendBogusAlertType: true,
2264 shouldFail: true,
2265 expectedError: ":UNKNOWN_ALERT_TYPE:",
2266 expectedLocalError: "remote error: illegal parameter",
2267 },
2268 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002269 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002270 config: Config{
2271 MaxVersion: VersionTLS13,
2272 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002273 sendKeyUpdates: 33,
2274 keyUpdateRequest: keyUpdateNotRequested,
2275 shouldFail: true,
2276 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002277 },
2278 {
David Benjaminba4594a2015-06-18 18:36:15 -04002279 name: "EmptySessionID",
2280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002281 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002282 SessionTicketsDisabled: true,
2283 },
2284 noSessionCache: true,
2285 flags: []string{"-expect-no-session"},
2286 },
David Benjamin30789da2015-08-29 22:56:45 -04002287 {
2288 name: "Unclean-Shutdown",
2289 config: Config{
2290 Bugs: ProtocolBugs{
2291 NoCloseNotify: true,
2292 ExpectCloseNotify: true,
2293 },
2294 },
2295 shimShutsDown: true,
2296 flags: []string{"-check-close-notify"},
2297 shouldFail: true,
2298 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2299 },
2300 {
2301 name: "Unclean-Shutdown-Ignored",
2302 config: Config{
2303 Bugs: ProtocolBugs{
2304 NoCloseNotify: true,
2305 },
2306 },
2307 shimShutsDown: true,
2308 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002309 {
David Benjaminfa214e42016-05-10 17:03:10 -04002310 name: "Unclean-Shutdown-Alert",
2311 config: Config{
2312 Bugs: ProtocolBugs{
2313 SendAlertOnShutdown: alertDecompressionFailure,
2314 ExpectCloseNotify: true,
2315 },
2316 },
2317 shimShutsDown: true,
2318 flags: []string{"-check-close-notify"},
2319 shouldFail: true,
2320 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2321 },
2322 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002323 name: "LargePlaintext",
2324 config: Config{
2325 Bugs: ProtocolBugs{
2326 SendLargeRecords: true,
2327 },
2328 },
2329 messageLen: maxPlaintext + 1,
2330 shouldFail: true,
2331 expectedError: ":DATA_LENGTH_TOO_LONG:",
2332 },
2333 {
2334 protocol: dtls,
2335 name: "LargePlaintext-DTLS",
2336 config: Config{
2337 Bugs: ProtocolBugs{
2338 SendLargeRecords: true,
2339 },
2340 },
2341 messageLen: maxPlaintext + 1,
2342 shouldFail: true,
2343 expectedError: ":DATA_LENGTH_TOO_LONG:",
2344 },
2345 {
2346 name: "LargeCiphertext",
2347 config: Config{
2348 Bugs: ProtocolBugs{
2349 SendLargeRecords: true,
2350 },
2351 },
2352 messageLen: maxPlaintext * 2,
2353 shouldFail: true,
2354 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2355 },
2356 {
2357 protocol: dtls,
2358 name: "LargeCiphertext-DTLS",
2359 config: Config{
2360 Bugs: ProtocolBugs{
2361 SendLargeRecords: true,
2362 },
2363 },
2364 messageLen: maxPlaintext * 2,
2365 // Unlike the other four cases, DTLS drops records which
2366 // are invalid before authentication, so the connection
2367 // does not fail.
2368 expectMessageDropped: true,
2369 },
David Benjamindd6fed92015-10-23 17:41:12 -04002370 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002371 name: "BadHelloRequest-1",
2372 renegotiate: 1,
2373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002374 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002375 Bugs: ProtocolBugs{
2376 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2377 },
2378 },
2379 flags: []string{
2380 "-renegotiate-freely",
2381 "-expect-total-renegotiations", "1",
2382 },
2383 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002384 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002385 },
2386 {
2387 name: "BadHelloRequest-2",
2388 renegotiate: 1,
2389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002390 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002391 Bugs: ProtocolBugs{
2392 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2393 },
2394 },
2395 flags: []string{
2396 "-renegotiate-freely",
2397 "-expect-total-renegotiations", "1",
2398 },
2399 shouldFail: true,
2400 expectedError: ":BAD_HELLO_REQUEST:",
2401 },
David Benjaminef1b0092015-11-21 14:05:44 -05002402 {
2403 testType: serverTest,
2404 name: "SupportTicketsWithSessionID",
2405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002406 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002407 SessionTicketsDisabled: true,
2408 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002409 resumeConfig: &Config{
2410 MaxVersion: VersionTLS12,
2411 },
David Benjaminef1b0092015-11-21 14:05:44 -05002412 resumeSession: true,
2413 },
David Benjamin02edcd02016-07-27 17:40:37 -04002414 {
2415 protocol: dtls,
2416 name: "DTLS-SendExtraFinished",
2417 config: Config{
2418 Bugs: ProtocolBugs{
2419 SendExtraFinished: true,
2420 },
2421 },
2422 shouldFail: true,
2423 expectedError: ":UNEXPECTED_RECORD:",
2424 },
2425 {
2426 protocol: dtls,
2427 name: "DTLS-SendExtraFinished-Reordered",
2428 config: Config{
2429 Bugs: ProtocolBugs{
2430 MaxHandshakeRecordLength: 2,
2431 ReorderHandshakeFragments: true,
2432 SendExtraFinished: true,
2433 },
2434 },
2435 shouldFail: true,
2436 expectedError: ":UNEXPECTED_RECORD:",
2437 },
David Benjamine97fb482016-07-29 09:23:07 -04002438 {
2439 testType: serverTest,
2440 name: "V2ClientHello-EmptyRecordPrefix",
2441 config: Config{
2442 // Choose a cipher suite that does not involve
2443 // elliptic curves, so no extensions are
2444 // involved.
2445 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002446 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002447 Bugs: ProtocolBugs{
2448 SendV2ClientHello: true,
2449 },
2450 },
2451 sendPrefix: string([]byte{
2452 byte(recordTypeHandshake),
2453 3, 1, // version
2454 0, 0, // length
2455 }),
2456 // A no-op empty record may not be sent before V2ClientHello.
2457 shouldFail: true,
2458 expectedError: ":WRONG_VERSION_NUMBER:",
2459 },
2460 {
2461 testType: serverTest,
2462 name: "V2ClientHello-WarningAlertPrefix",
2463 config: Config{
2464 // Choose a cipher suite that does not involve
2465 // elliptic curves, so no extensions are
2466 // involved.
2467 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002468 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002469 Bugs: ProtocolBugs{
2470 SendV2ClientHello: true,
2471 },
2472 },
2473 sendPrefix: string([]byte{
2474 byte(recordTypeAlert),
2475 3, 1, // version
2476 0, 2, // length
2477 alertLevelWarning, byte(alertDecompressionFailure),
2478 }),
2479 // A no-op warning alert may not be sent before V2ClientHello.
2480 shouldFail: true,
2481 expectedError: ":WRONG_VERSION_NUMBER:",
2482 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002483 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002484 name: "KeyUpdate-Client",
2485 config: Config{
2486 MaxVersion: VersionTLS13,
2487 },
2488 sendKeyUpdates: 1,
2489 keyUpdateRequest: keyUpdateNotRequested,
2490 },
2491 {
2492 testType: serverTest,
2493 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002494 config: Config{
2495 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002496 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002497 sendKeyUpdates: 1,
2498 keyUpdateRequest: keyUpdateNotRequested,
2499 },
2500 {
2501 name: "KeyUpdate-InvalidRequestMode",
2502 config: Config{
2503 MaxVersion: VersionTLS13,
2504 },
2505 sendKeyUpdates: 1,
2506 keyUpdateRequest: 42,
2507 shouldFail: true,
2508 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002509 },
David Benjaminabe94e32016-09-04 14:18:58 -04002510 {
David Benjaminbbba9392017-04-06 12:54:12 -04002511 // Test that KeyUpdates are acknowledged properly.
2512 name: "KeyUpdate-RequestACK",
2513 config: Config{
2514 MaxVersion: VersionTLS13,
2515 Bugs: ProtocolBugs{
2516 RejectUnsolicitedKeyUpdate: true,
2517 },
2518 },
2519 // Test the shim receiving many KeyUpdates in a row.
2520 sendKeyUpdates: 5,
2521 messageCount: 5,
2522 keyUpdateRequest: keyUpdateRequested,
2523 },
2524 {
2525 // Test that KeyUpdates are acknowledged properly if the
2526 // peer's KeyUpdate is discovered while a write is
2527 // pending.
2528 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2529 config: Config{
2530 MaxVersion: VersionTLS13,
2531 Bugs: ProtocolBugs{
2532 RejectUnsolicitedKeyUpdate: true,
2533 },
2534 },
2535 // Test the shim receiving many KeyUpdates in a row.
2536 sendKeyUpdates: 5,
2537 messageCount: 5,
2538 keyUpdateRequest: keyUpdateRequested,
2539 readWithUnfinishedWrite: true,
2540 flags: []string{"-async"},
2541 },
2542 {
David Benjaminabe94e32016-09-04 14:18:58 -04002543 name: "SendSNIWarningAlert",
2544 config: Config{
2545 MaxVersion: VersionTLS12,
2546 Bugs: ProtocolBugs{
2547 SendSNIWarningAlert: true,
2548 },
2549 },
2550 },
David Benjaminc241d792016-09-09 10:34:20 -04002551 {
2552 testType: serverTest,
2553 name: "ExtraCompressionMethods-TLS12",
2554 config: Config{
2555 MaxVersion: VersionTLS12,
2556 Bugs: ProtocolBugs{
2557 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2558 },
2559 },
2560 },
2561 {
2562 testType: serverTest,
2563 name: "ExtraCompressionMethods-TLS13",
2564 config: Config{
2565 MaxVersion: VersionTLS13,
2566 Bugs: ProtocolBugs{
2567 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2568 },
2569 },
2570 shouldFail: true,
2571 expectedError: ":INVALID_COMPRESSION_LIST:",
2572 expectedLocalError: "remote error: illegal parameter",
2573 },
2574 {
2575 testType: serverTest,
2576 name: "NoNullCompression-TLS12",
2577 config: Config{
2578 MaxVersion: VersionTLS12,
2579 Bugs: ProtocolBugs{
2580 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2581 },
2582 },
2583 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002584 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002585 expectedLocalError: "remote error: illegal parameter",
2586 },
2587 {
2588 testType: serverTest,
2589 name: "NoNullCompression-TLS13",
2590 config: Config{
2591 MaxVersion: VersionTLS13,
2592 Bugs: ProtocolBugs{
2593 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2594 },
2595 },
2596 shouldFail: true,
2597 expectedError: ":INVALID_COMPRESSION_LIST:",
2598 expectedLocalError: "remote error: illegal parameter",
2599 },
David Benjamin413e79e2017-07-01 10:11:53 -04002600 // Test that the client rejects invalid compression methods
2601 // from the server.
2602 {
2603 testType: clientTest,
2604 name: "InvalidCompressionMethod",
2605 config: Config{
2606 MaxVersion: VersionTLS12,
2607 Bugs: ProtocolBugs{
2608 SendCompressionMethod: 1,
2609 },
2610 },
2611 shouldFail: true,
2612 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2613 expectedLocalError: "remote error: illegal parameter",
2614 },
David Benjamin65ac9972016-09-02 21:35:25 -04002615 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002616 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002617 config: Config{
2618 MaxVersion: VersionTLS12,
2619 Bugs: ProtocolBugs{
2620 ExpectGREASE: true,
2621 },
2622 },
2623 flags: []string{"-enable-grease"},
2624 },
2625 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002626 name: "GREASE-Client-TLS13",
2627 config: Config{
2628 MaxVersion: VersionTLS13,
2629 Bugs: ProtocolBugs{
2630 ExpectGREASE: true,
2631 },
2632 },
2633 flags: []string{"-enable-grease"},
2634 },
2635 {
2636 testType: serverTest,
2637 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002638 config: Config{
2639 MaxVersion: VersionTLS13,
2640 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002641 // TLS 1.3 servers are expected to
2642 // always enable GREASE. TLS 1.3 is new,
2643 // so there is no existing ecosystem to
2644 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002645 ExpectGREASE: true,
2646 },
2647 },
David Benjamin65ac9972016-09-02 21:35:25 -04002648 },
David Benjamine3fbb362017-01-06 16:19:28 -05002649 {
2650 // Test the server so there is a large certificate as
2651 // well as application data.
2652 testType: serverTest,
2653 name: "MaxSendFragment",
2654 config: Config{
2655 Bugs: ProtocolBugs{
2656 MaxReceivePlaintext: 512,
2657 },
2658 },
2659 messageLen: 1024,
2660 flags: []string{
2661 "-max-send-fragment", "512",
2662 "-read-size", "1024",
2663 },
2664 },
2665 {
2666 // Test the server so there is a large certificate as
2667 // well as application data.
2668 testType: serverTest,
2669 name: "MaxSendFragment-TooLarge",
2670 config: Config{
2671 Bugs: ProtocolBugs{
2672 // Ensure that some of the records are
2673 // 512.
2674 MaxReceivePlaintext: 511,
2675 },
2676 },
2677 messageLen: 1024,
2678 flags: []string{
2679 "-max-send-fragment", "512",
2680 "-read-size", "1024",
2681 },
2682 shouldFail: true,
2683 expectedLocalError: "local error: record overflow",
2684 },
Adam Langley7c803a62015-06-15 15:35:05 -07002685 }
Adam Langley7c803a62015-06-15 15:35:05 -07002686 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002687
2688 // Test that very large messages can be received.
2689 cert := rsaCertificate
2690 for i := 0; i < 50; i++ {
2691 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2692 }
2693 testCases = append(testCases, testCase{
2694 name: "LargeMessage",
2695 config: Config{
2696 Certificates: []Certificate{cert},
2697 },
2698 })
2699 testCases = append(testCases, testCase{
2700 protocol: dtls,
2701 name: "LargeMessage-DTLS",
2702 config: Config{
2703 Certificates: []Certificate{cert},
2704 },
2705 })
2706
2707 // They are rejected if the maximum certificate chain length is capped.
2708 testCases = append(testCases, testCase{
2709 name: "LargeMessage-Reject",
2710 config: Config{
2711 Certificates: []Certificate{cert},
2712 },
2713 flags: []string{"-max-cert-list", "16384"},
2714 shouldFail: true,
2715 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2716 })
2717 testCases = append(testCases, testCase{
2718 protocol: dtls,
2719 name: "LargeMessage-Reject-DTLS",
2720 config: Config{
2721 Certificates: []Certificate{cert},
2722 },
2723 flags: []string{"-max-cert-list", "16384"},
2724 shouldFail: true,
2725 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2726 })
Adam Langley7c803a62015-06-15 15:35:05 -07002727}
2728
David Benjaminaa012042016-12-10 13:33:05 -05002729func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2730 const psk = "12345"
2731 const pskIdentity = "luggage combo"
2732
2733 var prefix string
2734 if protocol == dtls {
2735 if !ver.hasDTLS {
2736 return
2737 }
2738 prefix = "D"
2739 }
2740
2741 var cert Certificate
2742 var certFile string
2743 var keyFile string
2744 if hasComponent(suite.name, "ECDSA") {
2745 cert = ecdsaP256Certificate
2746 certFile = ecdsaP256CertificateFile
2747 keyFile = ecdsaP256KeyFile
2748 } else {
2749 cert = rsaCertificate
2750 certFile = rsaCertificateFile
2751 keyFile = rsaKeyFile
2752 }
2753
2754 var flags []string
2755 if hasComponent(suite.name, "PSK") {
2756 flags = append(flags,
2757 "-psk", psk,
2758 "-psk-identity", pskIdentity)
2759 }
2760 if hasComponent(suite.name, "NULL") {
2761 // NULL ciphers must be explicitly enabled.
2762 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2763 }
David Benjaminaa012042016-12-10 13:33:05 -05002764
2765 var shouldServerFail, shouldClientFail bool
2766 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2767 // BoringSSL clients accept ECDHE on SSLv3, but
2768 // a BoringSSL server will never select it
2769 // because the extension is missing.
2770 shouldServerFail = true
2771 }
2772 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2773 shouldClientFail = true
2774 shouldServerFail = true
2775 }
2776 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2777 shouldClientFail = true
2778 shouldServerFail = true
2779 }
2780 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2781 shouldClientFail = true
2782 shouldServerFail = true
2783 }
2784 if !isDTLSCipher(suite.name) && protocol == dtls {
2785 shouldClientFail = true
2786 shouldServerFail = true
2787 }
2788
2789 var sendCipherSuite uint16
2790 var expectedServerError, expectedClientError string
2791 serverCipherSuites := []uint16{suite.id}
2792 if shouldServerFail {
2793 expectedServerError = ":NO_SHARED_CIPHER:"
2794 }
2795 if shouldClientFail {
2796 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2797 // Configure the server to select ciphers as normal but
2798 // select an incompatible cipher in ServerHello.
2799 serverCipherSuites = nil
2800 sendCipherSuite = suite.id
2801 }
2802
David Benjamincdb6fe92017-02-07 16:06:48 -05002803 // For cipher suites and versions where exporters are defined, verify
2804 // that they interoperate.
2805 var exportKeyingMaterial int
2806 if ver.version > VersionSSL30 {
2807 exportKeyingMaterial = 1024
2808 }
2809
David Benjaminaa012042016-12-10 13:33:05 -05002810 testCases = append(testCases, testCase{
2811 testType: serverTest,
2812 protocol: protocol,
2813 name: prefix + ver.name + "-" + suite.name + "-server",
2814 config: Config{
2815 MinVersion: ver.version,
2816 MaxVersion: ver.version,
2817 CipherSuites: []uint16{suite.id},
2818 Certificates: []Certificate{cert},
2819 PreSharedKey: []byte(psk),
2820 PreSharedKeyIdentity: pskIdentity,
2821 Bugs: ProtocolBugs{
2822 AdvertiseAllConfiguredCiphers: true,
2823 },
2824 },
David Benjamina5022392017-07-10 17:40:39 -04002825 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002826 certFile: certFile,
2827 keyFile: keyFile,
2828 flags: flags,
2829 resumeSession: true,
2830 shouldFail: shouldServerFail,
2831 expectedError: expectedServerError,
2832 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002833 })
2834
2835 testCases = append(testCases, testCase{
2836 testType: clientTest,
2837 protocol: protocol,
2838 name: prefix + ver.name + "-" + suite.name + "-client",
2839 config: Config{
2840 MinVersion: ver.version,
2841 MaxVersion: ver.version,
2842 CipherSuites: serverCipherSuites,
2843 Certificates: []Certificate{cert},
2844 PreSharedKey: []byte(psk),
2845 PreSharedKeyIdentity: pskIdentity,
2846 Bugs: ProtocolBugs{
2847 IgnorePeerCipherPreferences: shouldClientFail,
2848 SendCipherSuite: sendCipherSuite,
2849 },
2850 },
David Benjamina5022392017-07-10 17:40:39 -04002851 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002852 flags: flags,
2853 resumeSession: true,
2854 shouldFail: shouldClientFail,
2855 expectedError: expectedClientError,
2856 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002857 })
2858
David Benjamin6f600d62016-12-21 16:06:54 -05002859 if shouldClientFail {
2860 return
2861 }
2862
2863 // Ensure the maximum record size is accepted.
2864 testCases = append(testCases, testCase{
2865 protocol: protocol,
2866 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2867 config: Config{
2868 MinVersion: ver.version,
2869 MaxVersion: ver.version,
2870 CipherSuites: []uint16{suite.id},
2871 Certificates: []Certificate{cert},
2872 PreSharedKey: []byte(psk),
2873 PreSharedKeyIdentity: pskIdentity,
2874 },
David Benjamina5022392017-07-10 17:40:39 -04002875 tls13Variant: ver.tls13Variant,
2876 flags: flags,
2877 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002878 })
2879
2880 // Test bad records for all ciphers. Bad records are fatal in TLS
2881 // and ignored in DTLS.
2882 var shouldFail bool
2883 var expectedError string
2884 if protocol == tls {
2885 shouldFail = true
2886 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2887 }
2888
2889 testCases = append(testCases, testCase{
2890 protocol: protocol,
2891 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2892 config: Config{
2893 MinVersion: ver.version,
2894 MaxVersion: ver.version,
2895 CipherSuites: []uint16{suite.id},
2896 Certificates: []Certificate{cert},
2897 PreSharedKey: []byte(psk),
2898 PreSharedKeyIdentity: pskIdentity,
2899 },
David Benjamina5022392017-07-10 17:40:39 -04002900 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002901 flags: flags,
2902 damageFirstWrite: true,
2903 messageLen: maxPlaintext,
2904 shouldFail: shouldFail,
2905 expectedError: expectedError,
2906 })
David Benjaminaa012042016-12-10 13:33:05 -05002907}
2908
Adam Langley95c29f32014-06-20 12:00:00 -07002909func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002910 const bogusCipher = 0xfe00
2911
Adam Langley95c29f32014-06-20 12:00:00 -07002912 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002913 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002914 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002915 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002916 }
David Benjamin2c99d282015-09-01 10:23:00 -04002917 }
Adam Langley95c29f32014-06-20 12:00:00 -07002918 }
Adam Langleya7997f12015-05-14 17:38:50 -07002919
2920 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002921 name: "NoSharedCipher",
2922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002923 MaxVersion: VersionTLS12,
2924 CipherSuites: []uint16{},
2925 },
2926 shouldFail: true,
2927 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2928 })
2929
2930 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002931 name: "NoSharedCipher-TLS13",
2932 config: Config{
2933 MaxVersion: VersionTLS13,
2934 CipherSuites: []uint16{},
2935 },
2936 shouldFail: true,
2937 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2938 })
2939
2940 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002941 name: "UnsupportedCipherSuite",
2942 config: Config{
2943 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002944 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002945 Bugs: ProtocolBugs{
2946 IgnorePeerCipherPreferences: true,
2947 },
2948 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002949 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002950 shouldFail: true,
2951 expectedError: ":WRONG_CIPHER_RETURNED:",
2952 })
2953
2954 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002955 name: "ServerHelloBogusCipher",
2956 config: Config{
2957 MaxVersion: VersionTLS12,
2958 Bugs: ProtocolBugs{
2959 SendCipherSuite: bogusCipher,
2960 },
2961 },
2962 shouldFail: true,
2963 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2964 })
2965 testCases = append(testCases, testCase{
2966 name: "ServerHelloBogusCipher-TLS13",
2967 config: Config{
2968 MaxVersion: VersionTLS13,
2969 Bugs: ProtocolBugs{
2970 SendCipherSuite: bogusCipher,
2971 },
2972 },
2973 shouldFail: true,
2974 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2975 })
2976
David Benjamin241ae832016-01-15 03:04:54 -05002977 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002978 testCases = append(testCases, testCase{
2979 testType: serverTest,
2980 name: "UnknownCipher",
2981 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002982 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002983 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002984 Bugs: ProtocolBugs{
2985 AdvertiseAllConfiguredCiphers: true,
2986 },
2987 },
2988 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002989
2990 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002991 testCases = append(testCases, testCase{
2992 testType: serverTest,
2993 name: "UnknownCipher-TLS13",
2994 config: Config{
2995 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002996 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002997 Bugs: ProtocolBugs{
2998 AdvertiseAllConfiguredCiphers: true,
2999 },
David Benjamin241ae832016-01-15 03:04:54 -05003000 },
3001 })
3002
David Benjamin78679342016-09-16 19:42:05 -04003003 // Test empty ECDHE_PSK identity hints work as expected.
3004 testCases = append(testCases, testCase{
3005 name: "EmptyECDHEPSKHint",
3006 config: Config{
3007 MaxVersion: VersionTLS12,
3008 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3009 PreSharedKey: []byte("secret"),
3010 },
3011 flags: []string{"-psk", "secret"},
3012 })
3013
3014 // Test empty PSK identity hints work as expected, even if an explicit
3015 // ServerKeyExchange is sent.
3016 testCases = append(testCases, testCase{
3017 name: "ExplicitEmptyPSKHint",
3018 config: Config{
3019 MaxVersion: VersionTLS12,
3020 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3021 PreSharedKey: []byte("secret"),
3022 Bugs: ProtocolBugs{
3023 AlwaysSendPreSharedKeyIdentityHint: true,
3024 },
3025 },
3026 flags: []string{"-psk", "secret"},
3027 })
David Benjamin69522112017-03-28 15:38:29 -05003028
3029 // Test that clients enforce that the server-sent certificate and cipher
3030 // suite match in TLS 1.2.
3031 testCases = append(testCases, testCase{
3032 name: "CertificateCipherMismatch-RSA",
3033 config: Config{
3034 MaxVersion: VersionTLS12,
3035 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3036 Certificates: []Certificate{rsaCertificate},
3037 Bugs: ProtocolBugs{
3038 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3039 },
3040 },
3041 shouldFail: true,
3042 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3043 })
3044 testCases = append(testCases, testCase{
3045 name: "CertificateCipherMismatch-ECDSA",
3046 config: Config{
3047 MaxVersion: VersionTLS12,
3048 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3049 Certificates: []Certificate{ecdsaP256Certificate},
3050 Bugs: ProtocolBugs{
3051 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3052 },
3053 },
3054 shouldFail: true,
3055 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3056 })
3057 testCases = append(testCases, testCase{
3058 name: "CertificateCipherMismatch-Ed25519",
3059 config: Config{
3060 MaxVersion: VersionTLS12,
3061 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3062 Certificates: []Certificate{ed25519Certificate},
3063 Bugs: ProtocolBugs{
3064 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3065 },
3066 },
3067 shouldFail: true,
3068 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3069 })
3070
3071 // Test that servers decline to select a cipher suite which is
3072 // inconsistent with their configured certificate.
3073 testCases = append(testCases, testCase{
3074 testType: serverTest,
3075 name: "ServerCipherFilter-RSA",
3076 config: Config{
3077 MaxVersion: VersionTLS12,
3078 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3079 },
3080 flags: []string{
3081 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3082 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3083 },
3084 shouldFail: true,
3085 expectedError: ":NO_SHARED_CIPHER:",
3086 })
3087 testCases = append(testCases, testCase{
3088 testType: serverTest,
3089 name: "ServerCipherFilter-ECDSA",
3090 config: Config{
3091 MaxVersion: VersionTLS12,
3092 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3093 },
3094 flags: []string{
3095 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3096 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3097 },
3098 shouldFail: true,
3099 expectedError: ":NO_SHARED_CIPHER:",
3100 })
3101 testCases = append(testCases, testCase{
3102 testType: serverTest,
3103 name: "ServerCipherFilter-Ed25519",
3104 config: Config{
3105 MaxVersion: VersionTLS12,
3106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3107 },
3108 flags: []string{
3109 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3110 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3111 },
3112 shouldFail: true,
3113 expectedError: ":NO_SHARED_CIPHER:",
3114 })
David Benjamin364af782017-07-01 10:35:27 -04003115
3116 // Test cipher suite negotiation works as expected. Configure a
3117 // complicated cipher suite configuration.
3118 const negotiationTestCiphers = "" +
3119 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3120 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3121 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3122 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3123 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3124 negotiationTests := []struct {
3125 ciphers []uint16
3126 expected uint16
3127 }{
3128 // Server preferences are honored, including when
3129 // equipreference groups are involved.
3130 {
3131 []uint16{
3132 TLS_RSA_WITH_AES_256_GCM_SHA384,
3133 TLS_RSA_WITH_AES_128_CBC_SHA,
3134 TLS_RSA_WITH_AES_128_GCM_SHA256,
3135 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3136 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3137 },
3138 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3139 },
3140 {
3141 []uint16{
3142 TLS_RSA_WITH_AES_256_GCM_SHA384,
3143 TLS_RSA_WITH_AES_128_CBC_SHA,
3144 TLS_RSA_WITH_AES_128_GCM_SHA256,
3145 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3146 },
3147 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3148 },
3149 {
3150 []uint16{
3151 TLS_RSA_WITH_AES_256_GCM_SHA384,
3152 TLS_RSA_WITH_AES_128_CBC_SHA,
3153 TLS_RSA_WITH_AES_128_GCM_SHA256,
3154 },
3155 TLS_RSA_WITH_AES_128_GCM_SHA256,
3156 },
3157 {
3158 []uint16{
3159 TLS_RSA_WITH_AES_256_GCM_SHA384,
3160 TLS_RSA_WITH_AES_128_CBC_SHA,
3161 },
3162 TLS_RSA_WITH_AES_128_CBC_SHA,
3163 },
3164 // Equipreference groups use the client preference.
3165 {
3166 []uint16{
3167 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3168 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3169 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3170 },
3171 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3172 },
3173 {
3174 []uint16{
3175 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3176 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3177 },
3178 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3179 },
3180 {
3181 []uint16{
3182 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3183 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3184 },
3185 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3186 },
3187 {
3188 []uint16{
3189 TLS_RSA_WITH_AES_256_GCM_SHA384,
3190 TLS_RSA_WITH_AES_256_CBC_SHA,
3191 },
3192 TLS_RSA_WITH_AES_256_GCM_SHA384,
3193 },
3194 {
3195 []uint16{
3196 TLS_RSA_WITH_AES_256_CBC_SHA,
3197 TLS_RSA_WITH_AES_256_GCM_SHA384,
3198 },
3199 TLS_RSA_WITH_AES_256_CBC_SHA,
3200 },
3201 // If there are two equipreference groups, the preferred one
3202 // takes precedence.
3203 {
3204 []uint16{
3205 TLS_RSA_WITH_AES_256_GCM_SHA384,
3206 TLS_RSA_WITH_AES_256_CBC_SHA,
3207 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3208 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3209 },
3210 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3211 },
3212 }
3213 for i, t := range negotiationTests {
3214 testCases = append(testCases, testCase{
3215 testType: serverTest,
3216 name: "CipherNegotiation-" + strconv.Itoa(i),
3217 config: Config{
3218 MaxVersion: VersionTLS12,
3219 CipherSuites: t.ciphers,
3220 },
3221 flags: []string{"-cipher", negotiationTestCiphers},
3222 expectedCipher: t.expected,
3223 })
3224 }
Adam Langley95c29f32014-06-20 12:00:00 -07003225}
3226
3227func addBadECDSASignatureTests() {
3228 for badR := BadValue(1); badR < NumBadValues; badR++ {
3229 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003230 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003231 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3232 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003233 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003234 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003235 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003236 Bugs: ProtocolBugs{
3237 BadECDSAR: badR,
3238 BadECDSAS: badS,
3239 },
3240 },
3241 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003242 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003243 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003244 testCases = append(testCases, testCase{
3245 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3246 config: Config{
3247 MaxVersion: VersionTLS13,
3248 Certificates: []Certificate{ecdsaP256Certificate},
3249 Bugs: ProtocolBugs{
3250 BadECDSAR: badR,
3251 BadECDSAS: badS,
3252 },
3253 },
3254 shouldFail: true,
3255 expectedError: ":BAD_SIGNATURE:",
3256 })
Adam Langley95c29f32014-06-20 12:00:00 -07003257 }
3258 }
3259}
3260
Adam Langley80842bd2014-06-20 12:00:00 -07003261func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003262 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003263 name: "MaxCBCPadding",
3264 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003265 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003266 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3267 Bugs: ProtocolBugs{
3268 MaxPadding: true,
3269 },
3270 },
3271 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3272 })
David Benjamin025b3d32014-07-01 19:53:04 -04003273 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003274 name: "BadCBCPadding",
3275 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003276 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003277 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3278 Bugs: ProtocolBugs{
3279 PaddingFirstByteBad: true,
3280 },
3281 },
3282 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003283 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003284 })
3285 // OpenSSL previously had an issue where the first byte of padding in
3286 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003287 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003288 name: "BadCBCPadding255",
3289 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003290 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003291 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3292 Bugs: ProtocolBugs{
3293 MaxPadding: true,
3294 PaddingFirstByteBadIf255: true,
3295 },
3296 },
3297 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3298 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003299 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003300 })
3301}
3302
Kenny Root7fdeaf12014-08-05 15:23:37 -07003303func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003304 var cbcCiphers = []struct {
3305 name string
3306 cipher uint16
3307 }{
3308 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3309 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3310 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3311 }
3312 for _, t := range cbcCiphers {
3313 testCases = append(testCases, testCase{
3314 name: "CBCRecordSplitting-" + t.name,
3315 config: Config{
3316 MaxVersion: VersionTLS10,
3317 MinVersion: VersionTLS10,
3318 CipherSuites: []uint16{t.cipher},
3319 },
3320 messageLen: -1, // read until EOF
3321 resumeSession: true,
3322 flags: []string{
3323 "-async",
3324 "-write-different-record-sizes",
3325 "-cbc-record-splitting",
3326 },
3327 })
3328 testCases = append(testCases, testCase{
3329 name: "CBCRecordSplittingPartialWrite-" + t.name,
3330 config: Config{
3331 MaxVersion: VersionTLS10,
3332 MinVersion: VersionTLS10,
3333 CipherSuites: []uint16{t.cipher},
3334 },
3335 messageLen: -1, // read until EOF
3336 flags: []string{
3337 "-async",
3338 "-write-different-record-sizes",
3339 "-cbc-record-splitting",
3340 "-partial-write",
3341 },
3342 })
3343 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003344}
3345
David Benjamin636293b2014-07-08 17:59:18 -04003346func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003347 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003348 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003349 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3350 cert, err := x509.ParseCertificate(cert.Certificate[0])
3351 if err != nil {
3352 panic(err)
3353 }
3354 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003355 }
Adam Langley2ff79332017-02-28 13:45:39 -08003356 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003357
David Benjamin636293b2014-07-08 17:59:18 -04003358 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003359 testCases = append(testCases, testCase{
3360 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003361 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003362 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003363 MinVersion: ver.version,
3364 MaxVersion: ver.version,
3365 ClientAuth: RequireAnyClientCert,
3366 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003367 },
David Benjamina5022392017-07-10 17:40:39 -04003368 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003369 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003370 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3371 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003372 },
3373 })
3374 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003375 testType: serverTest,
3376 name: ver.name + "-Server-ClientAuth-RSA",
3377 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003378 MinVersion: ver.version,
3379 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003380 Certificates: []Certificate{rsaCertificate},
3381 },
David Benjamina5022392017-07-10 17:40:39 -04003382 tls13Variant: ver.tls13Variant,
3383 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003384 })
David Benjamine098ec22014-08-27 23:13:20 -04003385 if ver.version != VersionSSL30 {
3386 testCases = append(testCases, testCase{
3387 testType: serverTest,
3388 name: ver.name + "-Server-ClientAuth-ECDSA",
3389 config: Config{
3390 MinVersion: ver.version,
3391 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003392 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003393 },
David Benjamina5022392017-07-10 17:40:39 -04003394 tls13Variant: ver.tls13Variant,
3395 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003396 })
3397 testCases = append(testCases, testCase{
3398 testType: clientTest,
3399 name: ver.name + "-Client-ClientAuth-ECDSA",
3400 config: Config{
3401 MinVersion: ver.version,
3402 MaxVersion: ver.version,
3403 ClientAuth: RequireAnyClientCert,
3404 ClientCAs: certPool,
3405 },
David Benjamina5022392017-07-10 17:40:39 -04003406 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003407 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003408 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3409 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003410 },
3411 })
3412 }
Adam Langley37646832016-08-01 16:16:46 -07003413
3414 testCases = append(testCases, testCase{
3415 name: "NoClientCertificate-" + ver.name,
3416 config: Config{
3417 MinVersion: ver.version,
3418 MaxVersion: ver.version,
3419 ClientAuth: RequireAnyClientCert,
3420 },
David Benjamina5022392017-07-10 17:40:39 -04003421 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003422 shouldFail: true,
3423 expectedLocalError: "client didn't provide a certificate",
3424 })
3425
3426 testCases = append(testCases, testCase{
3427 // Even if not configured to expect a certificate, OpenSSL will
3428 // return X509_V_OK as the verify_result.
3429 testType: serverTest,
3430 name: "NoClientCertificateRequested-Server-" + ver.name,
3431 config: Config{
3432 MinVersion: ver.version,
3433 MaxVersion: ver.version,
3434 },
David Benjamina5022392017-07-10 17:40:39 -04003435 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003436 flags: []string{
3437 "-expect-verify-result",
3438 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003439 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003440 })
3441
3442 testCases = append(testCases, testCase{
3443 // If a client certificate is not provided, OpenSSL will still
3444 // return X509_V_OK as the verify_result.
3445 testType: serverTest,
3446 name: "NoClientCertificate-Server-" + ver.name,
3447 config: Config{
3448 MinVersion: ver.version,
3449 MaxVersion: ver.version,
3450 },
David Benjamina5022392017-07-10 17:40:39 -04003451 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003452 flags: []string{
3453 "-expect-verify-result",
3454 "-verify-peer",
3455 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003456 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003457 })
3458
David Benjamin1db9e1b2016-10-07 20:51:43 -04003459 certificateRequired := "remote error: certificate required"
3460 if ver.version < VersionTLS13 {
3461 // Prior to TLS 1.3, the generic handshake_failure alert
3462 // was used.
3463 certificateRequired = "remote error: handshake failure"
3464 }
Adam Langley37646832016-08-01 16:16:46 -07003465 testCases = append(testCases, testCase{
3466 testType: serverTest,
3467 name: "RequireAnyClientCertificate-" + ver.name,
3468 config: Config{
3469 MinVersion: ver.version,
3470 MaxVersion: ver.version,
3471 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003472 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003473 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003474 shouldFail: true,
3475 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3476 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003477 })
3478
3479 if ver.version != VersionSSL30 {
3480 testCases = append(testCases, testCase{
3481 testType: serverTest,
3482 name: "SkipClientCertificate-" + ver.name,
3483 config: Config{
3484 MinVersion: ver.version,
3485 MaxVersion: ver.version,
3486 Bugs: ProtocolBugs{
3487 SkipClientCertificate: true,
3488 },
3489 },
3490 // Setting SSL_VERIFY_PEER allows anonymous clients.
3491 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003492 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003493 shouldFail: true,
3494 expectedError: ":UNEXPECTED_MESSAGE:",
3495 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003496
3497 testCases = append(testCases, testCase{
3498 testType: serverTest,
3499 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3500 config: Config{
3501 MinVersion: ver.version,
3502 MaxVersion: ver.version,
3503 },
3504 flags: []string{
3505 "-enable-channel-id",
3506 "-verify-peer-if-no-obc",
3507 },
David Benjamina5022392017-07-10 17:40:39 -04003508 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003509 shouldFail: true,
3510 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3511 expectedLocalError: certificateRequired,
3512 })
3513
3514 testCases = append(testCases, testCase{
3515 testType: serverTest,
3516 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3517 config: Config{
3518 MinVersion: ver.version,
3519 MaxVersion: ver.version,
3520 ChannelID: channelIDKey,
3521 },
3522 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003523 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003524 flags: []string{
3525 "-enable-channel-id",
3526 "-verify-peer-if-no-obc",
3527 },
3528 })
Adam Langley37646832016-08-01 16:16:46 -07003529 }
Adam Langley2ff79332017-02-28 13:45:39 -08003530
3531 testCases = append(testCases, testCase{
3532 testType: serverTest,
3533 name: ver.name + "-Server-CertReq-CA-List",
3534 config: Config{
3535 MinVersion: ver.version,
3536 MaxVersion: ver.version,
3537 Certificates: []Certificate{rsaCertificate},
3538 Bugs: ProtocolBugs{
3539 ExpectCertificateReqNames: caNames,
3540 },
3541 },
David Benjamina5022392017-07-10 17:40:39 -04003542 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003543 flags: []string{
3544 "-require-any-client-certificate",
3545 "-use-client-ca-list", encodeDERValues(caNames),
3546 },
3547 })
3548
3549 testCases = append(testCases, testCase{
3550 testType: clientTest,
3551 name: ver.name + "-Client-CertReq-CA-List",
3552 config: Config{
3553 MinVersion: ver.version,
3554 MaxVersion: ver.version,
3555 Certificates: []Certificate{rsaCertificate},
3556 ClientAuth: RequireAnyClientCert,
3557 ClientCAs: certPool,
3558 },
David Benjamina5022392017-07-10 17:40:39 -04003559 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003560 flags: []string{
3561 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3562 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3563 "-expect-client-ca-list", encodeDERValues(caNames),
3564 },
3565 })
David Benjamin636293b2014-07-08 17:59:18 -04003566 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003567
David Benjaminc032dfa2016-05-12 14:54:57 -04003568 // Client auth is only legal in certificate-based ciphers.
3569 testCases = append(testCases, testCase{
3570 testType: clientTest,
3571 name: "ClientAuth-PSK",
3572 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003573 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003574 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3575 PreSharedKey: []byte("secret"),
3576 ClientAuth: RequireAnyClientCert,
3577 },
3578 flags: []string{
3579 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3580 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3581 "-psk", "secret",
3582 },
3583 shouldFail: true,
3584 expectedError: ":UNEXPECTED_MESSAGE:",
3585 })
3586 testCases = append(testCases, testCase{
3587 testType: clientTest,
3588 name: "ClientAuth-ECDHE_PSK",
3589 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003590 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003591 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3592 PreSharedKey: []byte("secret"),
3593 ClientAuth: RequireAnyClientCert,
3594 },
3595 flags: []string{
3596 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3597 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3598 "-psk", "secret",
3599 },
3600 shouldFail: true,
3601 expectedError: ":UNEXPECTED_MESSAGE:",
3602 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003603
3604 // Regression test for a bug where the client CA list, if explicitly
3605 // set to NULL, was mis-encoded.
3606 testCases = append(testCases, testCase{
3607 testType: serverTest,
3608 name: "Null-Client-CA-List",
3609 config: Config{
3610 MaxVersion: VersionTLS12,
3611 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003612 Bugs: ProtocolBugs{
3613 ExpectCertificateReqNames: [][]byte{},
3614 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003615 },
3616 flags: []string{
3617 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003618 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003619 },
3620 })
David Benjamin636293b2014-07-08 17:59:18 -04003621}
3622
Adam Langley75712922014-10-10 16:23:43 -07003623func addExtendedMasterSecretTests() {
3624 const expectEMSFlag = "-expect-extended-master-secret"
3625
3626 for _, with := range []bool{false, true} {
3627 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003628 if with {
3629 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003630 }
3631
3632 for _, isClient := range []bool{false, true} {
3633 suffix := "-Server"
3634 testType := serverTest
3635 if isClient {
3636 suffix = "-Client"
3637 testType = clientTest
3638 }
3639
3640 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003641 // In TLS 1.3, the extension is irrelevant and
3642 // always reports as enabled.
3643 var flags []string
3644 if with || ver.version >= VersionTLS13 {
3645 flags = []string{expectEMSFlag}
3646 }
3647
Adam Langley75712922014-10-10 16:23:43 -07003648 test := testCase{
3649 testType: testType,
3650 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3651 config: Config{
3652 MinVersion: ver.version,
3653 MaxVersion: ver.version,
3654 Bugs: ProtocolBugs{
3655 NoExtendedMasterSecret: !with,
3656 RequireExtendedMasterSecret: with,
3657 },
3658 },
David Benjamina5022392017-07-10 17:40:39 -04003659 tls13Variant: ver.tls13Variant,
3660 flags: flags,
3661 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003662 }
3663 if test.shouldFail {
3664 test.expectedLocalError = "extended master secret required but not supported by peer"
3665 }
3666 testCases = append(testCases, test)
3667 }
3668 }
3669 }
3670
Adam Langleyba5934b2015-06-02 10:50:35 -07003671 for _, isClient := range []bool{false, true} {
3672 for _, supportedInFirstConnection := range []bool{false, true} {
3673 for _, supportedInResumeConnection := range []bool{false, true} {
3674 boolToWord := func(b bool) string {
3675 if b {
3676 return "Yes"
3677 }
3678 return "No"
3679 }
3680 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3681 if isClient {
3682 suffix += "Client"
3683 } else {
3684 suffix += "Server"
3685 }
3686
3687 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003688 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003689 Bugs: ProtocolBugs{
3690 RequireExtendedMasterSecret: true,
3691 },
3692 }
3693
3694 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003695 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003696 Bugs: ProtocolBugs{
3697 NoExtendedMasterSecret: true,
3698 },
3699 }
3700
3701 test := testCase{
3702 name: "ExtendedMasterSecret-" + suffix,
3703 resumeSession: true,
3704 }
3705
3706 if !isClient {
3707 test.testType = serverTest
3708 }
3709
3710 if supportedInFirstConnection {
3711 test.config = supportedConfig
3712 } else {
3713 test.config = noSupportConfig
3714 }
3715
3716 if supportedInResumeConnection {
3717 test.resumeConfig = &supportedConfig
3718 } else {
3719 test.resumeConfig = &noSupportConfig
3720 }
3721
3722 switch suffix {
3723 case "YesToYes-Client", "YesToYes-Server":
3724 // When a session is resumed, it should
3725 // still be aware that its master
3726 // secret was generated via EMS and
3727 // thus it's safe to use tls-unique.
3728 test.flags = []string{expectEMSFlag}
3729 case "NoToYes-Server":
3730 // If an original connection did not
3731 // contain EMS, but a resumption
3732 // handshake does, then a server should
3733 // not resume the session.
3734 test.expectResumeRejected = true
3735 case "YesToNo-Server":
3736 // Resuming an EMS session without the
3737 // EMS extension should cause the
3738 // server to abort the connection.
3739 test.shouldFail = true
3740 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3741 case "NoToYes-Client":
3742 // A client should abort a connection
3743 // where the server resumed a non-EMS
3744 // session but echoed the EMS
3745 // extension.
3746 test.shouldFail = true
3747 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3748 case "YesToNo-Client":
3749 // A client should abort a connection
3750 // where the server didn't echo EMS
3751 // when the session used it.
3752 test.shouldFail = true
3753 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3754 }
3755
3756 testCases = append(testCases, test)
3757 }
3758 }
3759 }
David Benjamin163c9562016-08-29 23:14:17 -04003760
3761 // Switching EMS on renegotiation is forbidden.
3762 testCases = append(testCases, testCase{
3763 name: "ExtendedMasterSecret-Renego-NoEMS",
3764 config: Config{
3765 MaxVersion: VersionTLS12,
3766 Bugs: ProtocolBugs{
3767 NoExtendedMasterSecret: true,
3768 NoExtendedMasterSecretOnRenegotiation: true,
3769 },
3770 },
3771 renegotiate: 1,
3772 flags: []string{
3773 "-renegotiate-freely",
3774 "-expect-total-renegotiations", "1",
3775 },
3776 })
3777
3778 testCases = append(testCases, testCase{
3779 name: "ExtendedMasterSecret-Renego-Upgrade",
3780 config: Config{
3781 MaxVersion: VersionTLS12,
3782 Bugs: ProtocolBugs{
3783 NoExtendedMasterSecret: true,
3784 },
3785 },
3786 renegotiate: 1,
3787 flags: []string{
3788 "-renegotiate-freely",
3789 "-expect-total-renegotiations", "1",
3790 },
3791 shouldFail: true,
3792 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3793 })
3794
3795 testCases = append(testCases, testCase{
3796 name: "ExtendedMasterSecret-Renego-Downgrade",
3797 config: Config{
3798 MaxVersion: VersionTLS12,
3799 Bugs: ProtocolBugs{
3800 NoExtendedMasterSecretOnRenegotiation: true,
3801 },
3802 },
3803 renegotiate: 1,
3804 flags: []string{
3805 "-renegotiate-freely",
3806 "-expect-total-renegotiations", "1",
3807 },
3808 shouldFail: true,
3809 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3810 })
Adam Langley75712922014-10-10 16:23:43 -07003811}
3812
David Benjamin582ba042016-07-07 12:33:25 -07003813type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003814 protocol protocol
3815 async bool
3816 splitHandshake bool
3817 packHandshakeFlight bool
3818 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003819}
3820
David Benjamin43ec06f2014-08-05 02:28:57 -04003821// Adds tests that try to cover the range of the handshake state machine, under
3822// various conditions. Some of these are redundant with other tests, but they
3823// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003824func addAllStateMachineCoverageTests() {
3825 for _, async := range []bool{false, true} {
3826 for _, protocol := range []protocol{tls, dtls} {
3827 addStateMachineCoverageTests(stateMachineTestConfig{
3828 protocol: protocol,
3829 async: async,
3830 })
3831 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003832 protocol: protocol,
3833 async: async,
3834 implicitHandshake: true,
3835 })
3836 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003837 protocol: protocol,
3838 async: async,
3839 splitHandshake: true,
3840 })
3841 if protocol == tls {
3842 addStateMachineCoverageTests(stateMachineTestConfig{
3843 protocol: protocol,
3844 async: async,
3845 packHandshakeFlight: true,
3846 })
3847 }
3848 }
3849 }
3850}
3851
3852func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003853 var tests []testCase
3854
3855 // Basic handshake, with resumption. Client and server,
3856 // session ID and session ticket.
3857 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003858 name: "Basic-Client",
3859 config: Config{
3860 MaxVersion: VersionTLS12,
3861 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003862 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003863 // Ensure session tickets are used, not session IDs.
3864 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003865 })
3866 tests = append(tests, testCase{
3867 name: "Basic-Client-RenewTicket",
3868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003869 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003870 Bugs: ProtocolBugs{
3871 RenewTicketOnResume: true,
3872 },
3873 },
David Benjamin46662482016-08-17 00:51:00 -04003874 flags: []string{"-expect-ticket-renewal"},
3875 resumeSession: true,
3876 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003877 })
3878 tests = append(tests, testCase{
3879 name: "Basic-Client-NoTicket",
3880 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003881 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003882 SessionTicketsDisabled: true,
3883 },
3884 resumeSession: true,
3885 })
3886 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003887 testType: serverTest,
3888 name: "Basic-Server",
3889 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003890 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003891 Bugs: ProtocolBugs{
3892 RequireSessionTickets: true,
3893 },
3894 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003895 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003896 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003897 })
3898 tests = append(tests, testCase{
3899 testType: serverTest,
3900 name: "Basic-Server-NoTickets",
3901 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003902 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003903 SessionTicketsDisabled: true,
3904 },
3905 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003906 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003907 })
3908 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003909 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003910 name: "Basic-Server-EarlyCallback",
3911 config: Config{
3912 MaxVersion: VersionTLS12,
3913 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003914 flags: []string{"-use-early-callback"},
3915 resumeSession: true,
3916 })
3917
Steven Valdez143e8b32016-07-11 13:19:03 -04003918 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003919 if config.protocol == tls {
3920 tests = append(tests, testCase{
3921 name: "TLS13-1RTT-Client",
3922 config: Config{
3923 MaxVersion: VersionTLS13,
3924 MinVersion: VersionTLS13,
3925 },
David Benjamin46662482016-08-17 00:51:00 -04003926 resumeSession: true,
3927 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003928 })
3929
3930 tests = append(tests, testCase{
3931 testType: serverTest,
3932 name: "TLS13-1RTT-Server",
3933 config: Config{
3934 MaxVersion: VersionTLS13,
3935 MinVersion: VersionTLS13,
3936 },
David Benjamin46662482016-08-17 00:51:00 -04003937 resumeSession: true,
3938 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003939 // TLS 1.3 uses tickets, so the session should not be
3940 // cached statefully.
3941 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003942 })
3943
3944 tests = append(tests, testCase{
3945 name: "TLS13-HelloRetryRequest-Client",
3946 config: Config{
3947 MaxVersion: VersionTLS13,
3948 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003949 // P-384 requires a HelloRetryRequest against BoringSSL's default
3950 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003951 CurvePreferences: []CurveID{CurveP384},
3952 Bugs: ProtocolBugs{
3953 ExpectMissingKeyShare: true,
3954 },
3955 },
3956 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3957 resumeSession: true,
3958 })
3959
3960 tests = append(tests, testCase{
3961 testType: serverTest,
3962 name: "TLS13-HelloRetryRequest-Server",
3963 config: Config{
3964 MaxVersion: VersionTLS13,
3965 MinVersion: VersionTLS13,
3966 // Require a HelloRetryRequest for every curve.
3967 DefaultCurves: []CurveID{},
3968 },
3969 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3970 resumeSession: true,
3971 })
Steven Valdez2d850622017-01-11 11:34:52 -05003972
Steven Valdez2d850622017-01-11 11:34:52 -05003973 tests = append(tests, testCase{
3974 testType: clientTest,
3975 name: "TLS13-EarlyData-Client",
3976 config: Config{
3977 MaxVersion: VersionTLS13,
3978 MinVersion: VersionTLS13,
3979 MaxEarlyDataSize: 16384,
3980 },
Steven Valdeze831a812017-03-09 14:56:07 -05003981 resumeConfig: &Config{
3982 MaxVersion: VersionTLS13,
3983 MinVersion: VersionTLS13,
3984 MaxEarlyDataSize: 16384,
3985 Bugs: ProtocolBugs{
3986 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3987 },
3988 },
Steven Valdez2d850622017-01-11 11:34:52 -05003989 resumeSession: true,
3990 flags: []string{
3991 "-enable-early-data",
3992 "-expect-early-data-info",
3993 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003994 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003995 },
3996 })
3997
3998 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003999 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004000 name: "TLS13Experiment-EarlyData-Client",
4001 config: Config{
4002 MaxVersion: VersionTLS13,
4003 MinVersion: VersionTLS13,
4004 TLS13Variant: TLS13Experiment,
4005 MaxEarlyDataSize: 16384,
4006 },
4007 resumeConfig: &Config{
4008 MaxVersion: VersionTLS13,
4009 MinVersion: VersionTLS13,
4010 TLS13Variant: TLS13Experiment,
4011 MaxEarlyDataSize: 16384,
4012 Bugs: ProtocolBugs{
4013 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4014 },
4015 },
4016 resumeSession: true,
4017 flags: []string{
4018 "-enable-early-data",
4019 "-expect-early-data-info",
4020 "-expect-accept-early-data",
4021 "-on-resume-shim-writes-first",
4022 "-tls13-variant", "1",
4023 },
4024 })
4025
4026 tests = append(tests, testCase{
4027 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004028 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4029 config: Config{
4030 MaxVersion: VersionTLS13,
4031 MinVersion: VersionTLS13,
4032 TLS13Variant: TLS13RecordTypeExperiment,
4033 MaxEarlyDataSize: 16384,
4034 },
4035 resumeConfig: &Config{
4036 MaxVersion: VersionTLS13,
4037 MinVersion: VersionTLS13,
4038 TLS13Variant: TLS13RecordTypeExperiment,
4039 MaxEarlyDataSize: 16384,
4040 Bugs: ProtocolBugs{
4041 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4042 },
4043 },
4044 resumeSession: true,
4045 flags: []string{
4046 "-enable-early-data",
4047 "-expect-early-data-info",
4048 "-expect-accept-early-data",
4049 "-on-resume-shim-writes-first",
4050 "-tls13-variant", "2",
4051 },
4052 })
4053
4054 tests = append(tests, testCase{
4055 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004056 name: "TLS13-EarlyData-TooMuchData-Client",
4057 config: Config{
4058 MaxVersion: VersionTLS13,
4059 MinVersion: VersionTLS13,
4060 MaxEarlyDataSize: 2,
4061 },
4062 resumeConfig: &Config{
4063 MaxVersion: VersionTLS13,
4064 MinVersion: VersionTLS13,
4065 MaxEarlyDataSize: 2,
4066 Bugs: ProtocolBugs{
4067 ExpectEarlyData: [][]byte{{'h', 'e'}},
4068 },
4069 },
4070 resumeShimPrefix: "llo",
4071 resumeSession: true,
4072 flags: []string{
4073 "-enable-early-data",
4074 "-expect-early-data-info",
4075 "-expect-accept-early-data",
4076 "-on-resume-shim-writes-first",
4077 },
4078 })
4079
4080 // Unfinished writes can only be tested when operations are async. EarlyData
4081 // can't be tested as part of an ImplicitHandshake in this case since
4082 // otherwise the early data will be sent as normal data.
4083 if config.async && !config.implicitHandshake {
4084 tests = append(tests, testCase{
4085 testType: clientTest,
4086 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4087 config: Config{
4088 MaxVersion: VersionTLS13,
4089 MinVersion: VersionTLS13,
4090 MaxEarlyDataSize: 16384,
4091 },
4092 resumeConfig: &Config{
4093 MaxVersion: VersionTLS13,
4094 MinVersion: VersionTLS13,
4095 MaxEarlyDataSize: 16384,
4096 Bugs: ProtocolBugs{
4097 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4098 },
4099 },
4100 resumeSession: true,
4101 flags: []string{
4102 "-enable-early-data",
4103 "-expect-early-data-info",
4104 "-expect-accept-early-data",
4105 "-on-resume-read-with-unfinished-write",
4106 "-on-resume-shim-writes-first",
4107 },
4108 })
4109
4110 // Rejected unfinished writes are discarded (from the
4111 // perspective of the calling application) on 0-RTT
4112 // reject.
4113 tests = append(tests, testCase{
4114 testType: clientTest,
4115 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4116 config: Config{
4117 MaxVersion: VersionTLS13,
4118 MinVersion: VersionTLS13,
4119 MaxEarlyDataSize: 16384,
4120 },
4121 resumeConfig: &Config{
4122 MaxVersion: VersionTLS13,
4123 MinVersion: VersionTLS13,
4124 MaxEarlyDataSize: 16384,
4125 Bugs: ProtocolBugs{
4126 AlwaysRejectEarlyData: true,
4127 },
4128 },
4129 resumeSession: true,
4130 flags: []string{
4131 "-enable-early-data",
4132 "-expect-early-data-info",
4133 "-expect-reject-early-data",
4134 "-on-resume-read-with-unfinished-write",
4135 "-on-resume-shim-writes-first",
4136 },
4137 })
4138 }
4139
4140 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004141 testType: serverTest,
4142 name: "TLS13-EarlyData-Server",
4143 config: Config{
4144 MaxVersion: VersionTLS13,
4145 MinVersion: VersionTLS13,
4146 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004147 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004148 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004149 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004150 },
4151 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004152 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004153 resumeSession: true,
4154 flags: []string{
4155 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004156 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004157 },
4158 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004159
4160 tests = append(tests, testCase{
4161 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004162 name: "TLS13Experiment-EarlyData-Server",
4163 config: Config{
4164 MaxVersion: VersionTLS13,
4165 MinVersion: VersionTLS13,
4166 TLS13Variant: TLS13Experiment,
4167 Bugs: ProtocolBugs{
4168 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4169 ExpectEarlyDataAccepted: true,
4170 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4171 },
4172 },
4173 messageCount: 2,
4174 resumeSession: true,
4175 flags: []string{
4176 "-enable-early-data",
4177 "-expect-accept-early-data",
4178 "-tls13-variant", "1",
4179 },
4180 })
4181
4182 tests = append(tests, testCase{
4183 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004184 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4185 config: Config{
4186 MaxVersion: VersionTLS13,
4187 MinVersion: VersionTLS13,
4188 TLS13Variant: TLS13RecordTypeExperiment,
4189 Bugs: ProtocolBugs{
4190 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4191 ExpectEarlyDataAccepted: true,
4192 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4193 },
4194 },
4195 messageCount: 2,
4196 resumeSession: true,
4197 flags: []string{
4198 "-enable-early-data",
4199 "-expect-accept-early-data",
4200 "-tls13-variant", "2",
4201 },
4202 })
4203
4204 tests = append(tests, testCase{
4205 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004206 name: "TLS13-MaxEarlyData-Server",
4207 config: Config{
4208 MaxVersion: VersionTLS13,
4209 MinVersion: VersionTLS13,
4210 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004211 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004212 ExpectEarlyDataAccepted: true,
4213 },
4214 },
4215 messageCount: 2,
4216 resumeSession: true,
4217 flags: []string{
4218 "-enable-early-data",
4219 "-expect-accept-early-data",
4220 },
4221 shouldFail: true,
4222 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4223 })
David Benjamine73c7f42016-08-17 00:29:33 -04004224 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004225
David Benjamin760b1dd2015-05-15 23:33:48 -04004226 // TLS client auth.
4227 tests = append(tests, testCase{
4228 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004229 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004230 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004231 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004232 ClientAuth: RequestClientCert,
4233 },
4234 })
4235 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004236 testType: serverTest,
4237 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004238 config: Config{
4239 MaxVersion: VersionTLS12,
4240 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004241 // Setting SSL_VERIFY_PEER allows anonymous clients.
4242 flags: []string{"-verify-peer"},
4243 })
David Benjamin582ba042016-07-07 12:33:25 -07004244 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004245 tests = append(tests, testCase{
4246 testType: clientTest,
4247 name: "ClientAuth-NoCertificate-Client-SSL3",
4248 config: Config{
4249 MaxVersion: VersionSSL30,
4250 ClientAuth: RequestClientCert,
4251 },
4252 })
4253 tests = append(tests, testCase{
4254 testType: serverTest,
4255 name: "ClientAuth-NoCertificate-Server-SSL3",
4256 config: Config{
4257 MaxVersion: VersionSSL30,
4258 },
4259 // Setting SSL_VERIFY_PEER allows anonymous clients.
4260 flags: []string{"-verify-peer"},
4261 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004262 tests = append(tests, testCase{
4263 testType: clientTest,
4264 name: "ClientAuth-NoCertificate-Client-TLS13",
4265 config: Config{
4266 MaxVersion: VersionTLS13,
4267 ClientAuth: RequestClientCert,
4268 },
4269 })
4270 tests = append(tests, testCase{
4271 testType: serverTest,
4272 name: "ClientAuth-NoCertificate-Server-TLS13",
4273 config: Config{
4274 MaxVersion: VersionTLS13,
4275 },
4276 // Setting SSL_VERIFY_PEER allows anonymous clients.
4277 flags: []string{"-verify-peer"},
4278 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004279 }
4280 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004281 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004282 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004283 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004284 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004285 ClientAuth: RequireAnyClientCert,
4286 },
4287 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004288 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4289 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004290 },
4291 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004292 tests = append(tests, testCase{
4293 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004294 name: "ClientAuth-RSA-Client-TLS13",
4295 config: Config{
4296 MaxVersion: VersionTLS13,
4297 ClientAuth: RequireAnyClientCert,
4298 },
4299 flags: []string{
4300 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4301 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4302 },
4303 })
4304 tests = append(tests, testCase{
4305 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004306 name: "ClientAuth-ECDSA-Client",
4307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004308 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004309 ClientAuth: RequireAnyClientCert,
4310 },
4311 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004312 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4313 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004314 },
4315 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004316 tests = append(tests, testCase{
4317 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004318 name: "ClientAuth-ECDSA-Client-TLS13",
4319 config: Config{
4320 MaxVersion: VersionTLS13,
4321 ClientAuth: RequireAnyClientCert,
4322 },
4323 flags: []string{
4324 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4325 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4326 },
4327 })
4328 tests = append(tests, testCase{
4329 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004330 name: "ClientAuth-NoCertificate-OldCallback",
4331 config: Config{
4332 MaxVersion: VersionTLS12,
4333 ClientAuth: RequestClientCert,
4334 },
4335 flags: []string{"-use-old-client-cert-callback"},
4336 })
4337 tests = append(tests, testCase{
4338 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004339 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4340 config: Config{
4341 MaxVersion: VersionTLS13,
4342 ClientAuth: RequestClientCert,
4343 },
4344 flags: []string{"-use-old-client-cert-callback"},
4345 })
4346 tests = append(tests, testCase{
4347 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004348 name: "ClientAuth-OldCallback",
4349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004350 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004351 ClientAuth: RequireAnyClientCert,
4352 },
4353 flags: []string{
4354 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4355 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4356 "-use-old-client-cert-callback",
4357 },
4358 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004359 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004360 testType: clientTest,
4361 name: "ClientAuth-OldCallback-TLS13",
4362 config: Config{
4363 MaxVersion: VersionTLS13,
4364 ClientAuth: RequireAnyClientCert,
4365 },
4366 flags: []string{
4367 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4368 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4369 "-use-old-client-cert-callback",
4370 },
4371 })
4372 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004373 testType: serverTest,
4374 name: "ClientAuth-Server",
4375 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004376 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004377 Certificates: []Certificate{rsaCertificate},
4378 },
4379 flags: []string{"-require-any-client-certificate"},
4380 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004381 tests = append(tests, testCase{
4382 testType: serverTest,
4383 name: "ClientAuth-Server-TLS13",
4384 config: Config{
4385 MaxVersion: VersionTLS13,
4386 Certificates: []Certificate{rsaCertificate},
4387 },
4388 flags: []string{"-require-any-client-certificate"},
4389 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004390
David Benjamin4c3ddf72016-06-29 18:13:53 -04004391 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004392 tests = append(tests, testCase{
4393 testType: serverTest,
4394 name: "Basic-Server-RSA",
4395 config: Config{
4396 MaxVersion: VersionTLS12,
4397 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4398 },
4399 flags: []string{
4400 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4401 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4402 },
4403 })
4404 tests = append(tests, testCase{
4405 testType: serverTest,
4406 name: "Basic-Server-ECDHE-RSA",
4407 config: Config{
4408 MaxVersion: VersionTLS12,
4409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4410 },
4411 flags: []string{
4412 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4413 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4414 },
4415 })
4416 tests = append(tests, testCase{
4417 testType: serverTest,
4418 name: "Basic-Server-ECDHE-ECDSA",
4419 config: Config{
4420 MaxVersion: VersionTLS12,
4421 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4422 },
4423 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004424 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4425 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004426 },
4427 })
David Benjamin69522112017-03-28 15:38:29 -05004428 tests = append(tests, testCase{
4429 testType: serverTest,
4430 name: "Basic-Server-Ed25519",
4431 config: Config{
4432 MaxVersion: VersionTLS12,
4433 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4434 },
4435 flags: []string{
4436 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4437 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4438 "-enable-ed25519",
4439 },
4440 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004441
David Benjamin760b1dd2015-05-15 23:33:48 -04004442 // No session ticket support; server doesn't send NewSessionTicket.
4443 tests = append(tests, testCase{
4444 name: "SessionTicketsDisabled-Client",
4445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004446 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004447 SessionTicketsDisabled: true,
4448 },
4449 })
4450 tests = append(tests, testCase{
4451 testType: serverTest,
4452 name: "SessionTicketsDisabled-Server",
4453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004454 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004455 SessionTicketsDisabled: true,
4456 },
4457 })
4458
4459 // Skip ServerKeyExchange in PSK key exchange if there's no
4460 // identity hint.
4461 tests = append(tests, testCase{
4462 name: "EmptyPSKHint-Client",
4463 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004464 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004465 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4466 PreSharedKey: []byte("secret"),
4467 },
4468 flags: []string{"-psk", "secret"},
4469 })
4470 tests = append(tests, testCase{
4471 testType: serverTest,
4472 name: "EmptyPSKHint-Server",
4473 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004474 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004475 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4476 PreSharedKey: []byte("secret"),
4477 },
4478 flags: []string{"-psk", "secret"},
4479 })
4480
David Benjamin4c3ddf72016-06-29 18:13:53 -04004481 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004482 tests = append(tests, testCase{
4483 testType: clientTest,
4484 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004485 config: Config{
4486 MaxVersion: VersionTLS12,
4487 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004488 flags: []string{
4489 "-enable-ocsp-stapling",
4490 "-expect-ocsp-response",
4491 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004492 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004493 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004494 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004495 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004496 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004497 testType: serverTest,
4498 name: "OCSPStapling-Server",
4499 config: Config{
4500 MaxVersion: VersionTLS12,
4501 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004502 expectedOCSPResponse: testOCSPResponse,
4503 flags: []string{
4504 "-ocsp-response",
4505 base64.StdEncoding.EncodeToString(testOCSPResponse),
4506 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004507 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004508 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004509 tests = append(tests, testCase{
4510 testType: clientTest,
4511 name: "OCSPStapling-Client-TLS13",
4512 config: Config{
4513 MaxVersion: VersionTLS13,
4514 },
4515 flags: []string{
4516 "-enable-ocsp-stapling",
4517 "-expect-ocsp-response",
4518 base64.StdEncoding.EncodeToString(testOCSPResponse),
4519 "-verify-peer",
4520 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004521 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004522 })
4523 tests = append(tests, testCase{
4524 testType: serverTest,
4525 name: "OCSPStapling-Server-TLS13",
4526 config: Config{
4527 MaxVersion: VersionTLS13,
4528 },
4529 expectedOCSPResponse: testOCSPResponse,
4530 flags: []string{
4531 "-ocsp-response",
4532 base64.StdEncoding.EncodeToString(testOCSPResponse),
4533 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004534 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004535 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004536
David Benjamin4c3ddf72016-06-29 18:13:53 -04004537 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004538 for _, vers := range tlsVersions {
4539 if config.protocol == dtls && !vers.hasDTLS {
4540 continue
4541 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004542 for _, testType := range []testType{clientTest, serverTest} {
4543 suffix := "-Client"
4544 if testType == serverTest {
4545 suffix = "-Server"
4546 }
4547 suffix += "-" + vers.name
4548
4549 flag := "-verify-peer"
4550 if testType == serverTest {
4551 flag = "-require-any-client-certificate"
4552 }
4553
4554 tests = append(tests, testCase{
4555 testType: testType,
4556 name: "CertificateVerificationSucceed" + suffix,
4557 config: Config{
4558 MaxVersion: vers.version,
4559 Certificates: []Certificate{rsaCertificate},
4560 },
David Benjamina5022392017-07-10 17:40:39 -04004561 tls13Variant: vers.tls13Variant,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004562 flags: []string{
4563 flag,
4564 "-expect-verify-result",
4565 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004566 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004567 })
4568 tests = append(tests, testCase{
4569 testType: testType,
4570 name: "CertificateVerificationFail" + suffix,
4571 config: Config{
4572 MaxVersion: vers.version,
4573 Certificates: []Certificate{rsaCertificate},
4574 },
David Benjamina5022392017-07-10 17:40:39 -04004575 tls13Variant: vers.tls13Variant,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004576 flags: []string{
4577 flag,
4578 "-verify-fail",
4579 },
4580 shouldFail: true,
4581 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4582 })
4583 }
4584
4585 // By default, the client is in a soft fail mode where the peer
4586 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004587 tests = append(tests, testCase{
4588 testType: clientTest,
4589 name: "CertificateVerificationSoftFail-" + vers.name,
4590 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004591 MaxVersion: vers.version,
4592 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004593 },
David Benjamina5022392017-07-10 17:40:39 -04004594 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004595 flags: []string{
4596 "-verify-fail",
4597 "-expect-verify-result",
4598 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004599 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004600 })
4601 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004602
David Benjamin1d4f4c02016-07-26 18:03:08 -04004603 tests = append(tests, testCase{
4604 name: "ShimSendAlert",
4605 flags: []string{"-send-alert"},
4606 shimWritesFirst: true,
4607 shouldFail: true,
4608 expectedLocalError: "remote error: decompression failure",
4609 })
4610
David Benjamin582ba042016-07-07 12:33:25 -07004611 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004612 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004613 name: "Renegotiate-Client",
4614 config: Config{
4615 MaxVersion: VersionTLS12,
4616 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004617 renegotiate: 1,
4618 flags: []string{
4619 "-renegotiate-freely",
4620 "-expect-total-renegotiations", "1",
4621 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004622 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004623
David Benjamin47921102016-07-28 11:29:18 -04004624 tests = append(tests, testCase{
4625 name: "SendHalfHelloRequest",
4626 config: Config{
4627 MaxVersion: VersionTLS12,
4628 Bugs: ProtocolBugs{
4629 PackHelloRequestWithFinished: config.packHandshakeFlight,
4630 },
4631 },
4632 sendHalfHelloRequest: true,
4633 flags: []string{"-renegotiate-ignore"},
4634 shouldFail: true,
4635 expectedError: ":UNEXPECTED_RECORD:",
4636 })
4637
David Benjamin760b1dd2015-05-15 23:33:48 -04004638 // NPN on client and server; results in post-handshake message.
4639 tests = append(tests, testCase{
4640 name: "NPN-Client",
4641 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004642 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004643 NextProtos: []string{"foo"},
4644 },
4645 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004646 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004647 expectedNextProto: "foo",
4648 expectedNextProtoType: npn,
4649 })
4650 tests = append(tests, testCase{
4651 testType: serverTest,
4652 name: "NPN-Server",
4653 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004654 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004655 NextProtos: []string{"bar"},
4656 },
4657 flags: []string{
4658 "-advertise-npn", "\x03foo\x03bar\x03baz",
4659 "-expect-next-proto", "bar",
4660 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004661 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004662 expectedNextProto: "bar",
4663 expectedNextProtoType: npn,
4664 })
4665
4666 // TODO(davidben): Add tests for when False Start doesn't trigger.
4667
4668 // Client does False Start and negotiates NPN.
4669 tests = append(tests, testCase{
4670 name: "FalseStart",
4671 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004672 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004673 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4674 NextProtos: []string{"foo"},
4675 Bugs: ProtocolBugs{
4676 ExpectFalseStart: true,
4677 },
4678 },
4679 flags: []string{
4680 "-false-start",
4681 "-select-next-proto", "foo",
4682 },
4683 shimWritesFirst: true,
4684 resumeSession: true,
4685 })
4686
4687 // Client does False Start and negotiates ALPN.
4688 tests = append(tests, testCase{
4689 name: "FalseStart-ALPN",
4690 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004691 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4693 NextProtos: []string{"foo"},
4694 Bugs: ProtocolBugs{
4695 ExpectFalseStart: true,
4696 },
4697 },
4698 flags: []string{
4699 "-false-start",
4700 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004701 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004702 },
4703 shimWritesFirst: true,
4704 resumeSession: true,
4705 })
4706
David Benjamin760b1dd2015-05-15 23:33:48 -04004707 // False Start without session tickets.
4708 tests = append(tests, testCase{
4709 name: "FalseStart-SessionTicketsDisabled",
4710 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004711 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004712 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4713 NextProtos: []string{"foo"},
4714 SessionTicketsDisabled: true,
4715 Bugs: ProtocolBugs{
4716 ExpectFalseStart: true,
4717 },
4718 },
4719 flags: []string{
4720 "-false-start",
4721 "-select-next-proto", "foo",
4722 },
4723 shimWritesFirst: true,
4724 })
4725
4726 // Server parses a V2ClientHello.
4727 tests = append(tests, testCase{
4728 testType: serverTest,
4729 name: "SendV2ClientHello",
4730 config: Config{
4731 // Choose a cipher suite that does not involve
4732 // elliptic curves, so no extensions are
4733 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004734 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004735 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004736 Bugs: ProtocolBugs{
4737 SendV2ClientHello: true,
4738 },
4739 },
4740 })
4741
Nick Harper60a85cb2016-09-23 16:25:11 -07004742 // Test Channel ID
4743 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004744 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004745 continue
4746 }
4747 // Client sends a Channel ID.
4748 tests = append(tests, testCase{
4749 name: "ChannelID-Client-" + ver.name,
4750 config: Config{
4751 MaxVersion: ver.version,
4752 RequestChannelID: true,
4753 },
David Benjamina5022392017-07-10 17:40:39 -04004754 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004755 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4756 resumeSession: true,
4757 expectChannelID: true,
4758 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004759
Nick Harper60a85cb2016-09-23 16:25:11 -07004760 // Server accepts a Channel ID.
4761 tests = append(tests, testCase{
4762 testType: serverTest,
4763 name: "ChannelID-Server-" + ver.name,
4764 config: Config{
4765 MaxVersion: ver.version,
4766 ChannelID: channelIDKey,
4767 },
David Benjamina5022392017-07-10 17:40:39 -04004768 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004769 flags: []string{
4770 "-expect-channel-id",
4771 base64.StdEncoding.EncodeToString(channelIDBytes),
4772 },
4773 resumeSession: true,
4774 expectChannelID: true,
4775 })
4776
4777 tests = append(tests, testCase{
4778 testType: serverTest,
4779 name: "InvalidChannelIDSignature-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 ChannelID: channelIDKey,
4783 Bugs: ProtocolBugs{
4784 InvalidChannelIDSignature: true,
4785 },
4786 },
David Benjamina5022392017-07-10 17:40:39 -04004787 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004788 flags: []string{"-enable-channel-id"},
4789 shouldFail: true,
4790 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4791 })
David Benjamin634f4752017-07-01 11:08:41 -04004792
4793 if ver.version < VersionTLS13 {
4794 // Channel ID requires ECDHE ciphers.
4795 tests = append(tests, testCase{
4796 testType: serverTest,
4797 name: "ChannelID-NoECDHE-" + ver.name,
4798 config: Config{
4799 MaxVersion: ver.version,
4800 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4801 ChannelID: channelIDKey,
4802 },
4803 expectChannelID: false,
4804 flags: []string{"-enable-channel-id"},
4805 })
4806
4807 // Sanity-check setting expectChannelID false works.
4808 tests = append(tests, testCase{
4809 testType: serverTest,
4810 name: "ChannelID-ECDHE-" + ver.name,
4811 config: Config{
4812 MaxVersion: ver.version,
4813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4814 ChannelID: channelIDKey,
4815 },
4816 expectChannelID: false,
4817 flags: []string{"-enable-channel-id"},
4818 shouldFail: true,
4819 expectedLocalError: "channel ID unexpectedly negotiated",
4820 })
4821 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004822 }
David Benjamin30789da2015-08-29 22:56:45 -04004823
David Benjaminf8fcdf32016-06-08 15:56:13 -04004824 // Channel ID and NPN at the same time, to ensure their relative
4825 // ordering is correct.
4826 tests = append(tests, testCase{
4827 name: "ChannelID-NPN-Client",
4828 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004829 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004830 RequestChannelID: true,
4831 NextProtos: []string{"foo"},
4832 },
4833 flags: []string{
4834 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4835 "-select-next-proto", "foo",
4836 },
4837 resumeSession: true,
4838 expectChannelID: true,
4839 expectedNextProto: "foo",
4840 expectedNextProtoType: npn,
4841 })
4842 tests = append(tests, testCase{
4843 testType: serverTest,
4844 name: "ChannelID-NPN-Server",
4845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004846 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004847 ChannelID: channelIDKey,
4848 NextProtos: []string{"bar"},
4849 },
4850 flags: []string{
4851 "-expect-channel-id",
4852 base64.StdEncoding.EncodeToString(channelIDBytes),
4853 "-advertise-npn", "\x03foo\x03bar\x03baz",
4854 "-expect-next-proto", "bar",
4855 },
4856 resumeSession: true,
4857 expectChannelID: true,
4858 expectedNextProto: "bar",
4859 expectedNextProtoType: npn,
4860 })
4861
David Benjamin30789da2015-08-29 22:56:45 -04004862 // Bidirectional shutdown with the runner initiating.
4863 tests = append(tests, testCase{
4864 name: "Shutdown-Runner",
4865 config: Config{
4866 Bugs: ProtocolBugs{
4867 ExpectCloseNotify: true,
4868 },
4869 },
4870 flags: []string{"-check-close-notify"},
4871 })
4872
David Benjamine3843d42017-03-25 18:00:56 -05004873 if !config.implicitHandshake {
4874 // Bidirectional shutdown with the shim initiating. The runner,
4875 // in the meantime, sends garbage before the close_notify which
4876 // the shim must ignore. This test is disabled under implicit
4877 // handshake tests because the shim never reads or writes.
4878 tests = append(tests, testCase{
4879 name: "Shutdown-Shim",
4880 config: Config{
4881 MaxVersion: VersionTLS12,
4882 Bugs: ProtocolBugs{
4883 ExpectCloseNotify: true,
4884 },
David Benjamin30789da2015-08-29 22:56:45 -04004885 },
David Benjamine3843d42017-03-25 18:00:56 -05004886 shimShutsDown: true,
4887 sendEmptyRecords: 1,
4888 sendWarningAlerts: 1,
4889 flags: []string{"-check-close-notify"},
4890 })
4891 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004892 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004893 // TODO(davidben): DTLS 1.3 will want a similar thing for
4894 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004895 tests = append(tests, testCase{
4896 name: "SkipHelloVerifyRequest",
4897 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004898 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004899 Bugs: ProtocolBugs{
4900 SkipHelloVerifyRequest: true,
4901 },
4902 },
4903 })
4904 }
4905
David Benjamin760b1dd2015-05-15 23:33:48 -04004906 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004907 test.protocol = config.protocol
4908 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004909 test.name += "-DTLS"
4910 }
David Benjamin582ba042016-07-07 12:33:25 -07004911 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004912 test.name += "-Async"
4913 test.flags = append(test.flags, "-async")
4914 } else {
4915 test.name += "-Sync"
4916 }
David Benjamin582ba042016-07-07 12:33:25 -07004917 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004918 test.name += "-SplitHandshakeRecords"
4919 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004920 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004921 test.config.Bugs.MaxPacketLength = 256
4922 test.flags = append(test.flags, "-mtu", "256")
4923 }
4924 }
David Benjamin582ba042016-07-07 12:33:25 -07004925 if config.packHandshakeFlight {
4926 test.name += "-PackHandshakeFlight"
4927 test.config.Bugs.PackHandshakeFlight = true
4928 }
David Benjamine3843d42017-03-25 18:00:56 -05004929 if config.implicitHandshake {
4930 test.name += "-ImplicitHandshake"
4931 test.flags = append(test.flags, "-implicit-handshake")
4932 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004933 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004934 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004935}
4936
Adam Langley524e7172015-02-20 16:04:00 -08004937func addDDoSCallbackTests() {
4938 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004939 for _, resume := range []bool{false, true} {
4940 suffix := "Resume"
4941 if resume {
4942 suffix = "No" + suffix
4943 }
4944
4945 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004946 testType: serverTest,
4947 name: "Server-DDoS-OK-" + suffix,
4948 config: Config{
4949 MaxVersion: VersionTLS12,
4950 },
Adam Langley524e7172015-02-20 16:04:00 -08004951 flags: []string{"-install-ddos-callback"},
4952 resumeSession: resume,
4953 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004954 testCases = append(testCases, testCase{
4955 testType: serverTest,
4956 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4957 config: Config{
4958 MaxVersion: VersionTLS13,
4959 },
4960 flags: []string{"-install-ddos-callback"},
4961 resumeSession: resume,
4962 })
Adam Langley524e7172015-02-20 16:04:00 -08004963
4964 failFlag := "-fail-ddos-callback"
4965 if resume {
4966 failFlag = "-fail-second-ddos-callback"
4967 }
4968 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004969 testType: serverTest,
4970 name: "Server-DDoS-Reject-" + suffix,
4971 config: Config{
4972 MaxVersion: VersionTLS12,
4973 },
David Benjamin2c66e072016-09-16 15:58:00 -04004974 flags: []string{"-install-ddos-callback", failFlag},
4975 resumeSession: resume,
4976 shouldFail: true,
4977 expectedError: ":CONNECTION_REJECTED:",
4978 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004979 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004980 testCases = append(testCases, testCase{
4981 testType: serverTest,
4982 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4983 config: Config{
4984 MaxVersion: VersionTLS13,
4985 },
David Benjamin2c66e072016-09-16 15:58:00 -04004986 flags: []string{"-install-ddos-callback", failFlag},
4987 resumeSession: resume,
4988 shouldFail: true,
4989 expectedError: ":CONNECTION_REJECTED:",
4990 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004991 })
Adam Langley524e7172015-02-20 16:04:00 -08004992 }
4993}
4994
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004995func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04004996 for _, protocol := range []protocol{tls, dtls} {
4997 for _, shimVers := range allVersions(protocol) {
4998 // Assemble flags to disable all newer versions on the shim.
4999 var flags []string
5000 for _, vers := range allVersions(protocol) {
5001 if vers.version > shimVers.version {
5002 flags = append(flags, vers.excludeFlag)
5003 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005004 }
Steven Valdez520e1222017-06-13 12:45:25 -04005005
5006 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5007
5008 if shimVers.tls13Variant != 0 {
5009 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5010 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5011 }
5012
5013 // Test configuring the runner's maximum version.
5014 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005015 expectedVersion := shimVers.version
5016 if runnerVers.version < shimVers.version {
5017 expectedVersion = runnerVers.version
5018 }
Steven Valdez520e1222017-06-13 12:45:25 -04005019 // When running and shim have different TLS 1.3 variants enabled,
5020 // shim clients are expected to fall back to TLS 1.2, while shim
5021 // servers support both variants when enabled when the experiment is
5022 // enabled.
5023 expectedServerVersion := expectedVersion
5024 expectedClientVersion := expectedVersion
5025 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5026 expectedClientVersion = VersionTLS12
5027 expectedServerVersion = VersionTLS12
5028 if shimVers.tls13Variant != TLS13Default {
5029 expectedServerVersion = VersionTLS13
5030 }
5031 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005032
David Benjamin8b8c0062014-11-23 02:47:52 -05005033 suffix := shimVers.name + "-" + runnerVers.name
5034 if protocol == dtls {
5035 suffix += "-DTLS"
5036 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005037
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005038 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005039 clientVers := shimVers.version
5040 if clientVers > VersionTLS10 {
5041 clientVers = VersionTLS10
5042 }
Steven Valdez520e1222017-06-13 12:45:25 -04005043 clientVers = recordVersionToWire(clientVers, protocol)
5044 serverVers := expectedServerVersion
5045 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005046 serverVers = VersionTLS10
5047 }
Steven Valdez520e1222017-06-13 12:45:25 -04005048 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005049
David Benjamin8b8c0062014-11-23 02:47:52 -05005050 testCases = append(testCases, testCase{
5051 protocol: protocol,
5052 testType: clientTest,
5053 name: "VersionNegotiation-Client-" + suffix,
5054 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005055 MaxVersion: runnerVers.version,
5056 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005057 Bugs: ProtocolBugs{
5058 ExpectInitialRecordVersion: clientVers,
5059 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005060 },
5061 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005062 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005063 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005064 testCases = append(testCases, testCase{
5065 protocol: protocol,
5066 testType: clientTest,
5067 name: "VersionNegotiation-Client2-" + suffix,
5068 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005069 MaxVersion: runnerVers.version,
5070 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005071 Bugs: ProtocolBugs{
5072 ExpectInitialRecordVersion: clientVers,
5073 },
5074 },
Steven Valdez520e1222017-06-13 12:45:25 -04005075 flags: flags2,
5076 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005077 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005078
5079 testCases = append(testCases, testCase{
5080 protocol: protocol,
5081 testType: serverTest,
5082 name: "VersionNegotiation-Server-" + suffix,
5083 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005084 MaxVersion: runnerVers.version,
5085 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005086 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005087 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005088 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005089 },
5090 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005091 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005092 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005093 testCases = append(testCases, testCase{
5094 protocol: protocol,
5095 testType: serverTest,
5096 name: "VersionNegotiation-Server2-" + suffix,
5097 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005098 MaxVersion: runnerVers.version,
5099 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005100 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005101 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005102 },
5103 },
Steven Valdez520e1222017-06-13 12:45:25 -04005104 flags: flags2,
5105 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005106 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005107 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005108 }
5109 }
David Benjamin95c69562016-06-29 18:15:03 -04005110
Steven Valdezfdd10992016-09-15 16:27:05 -04005111 // Test the version extension at all versions.
5112 for _, vers := range tlsVersions {
5113 protocols := []protocol{tls}
5114 if vers.hasDTLS {
5115 protocols = append(protocols, dtls)
5116 }
5117 for _, protocol := range protocols {
5118 suffix := vers.name
5119 if protocol == dtls {
5120 suffix += "-DTLS"
5121 }
5122
Steven Valdezfdd10992016-09-15 16:27:05 -04005123 testCases = append(testCases, testCase{
5124 protocol: protocol,
5125 testType: serverTest,
5126 name: "VersionNegotiationExtension-" + suffix,
5127 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005128 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005129 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005130 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005131 },
5132 },
5133 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005134 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005135 })
5136 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005137 }
5138
5139 // If all versions are unknown, negotiation fails.
5140 testCases = append(testCases, testCase{
5141 testType: serverTest,
5142 name: "NoSupportedVersions",
5143 config: Config{
5144 Bugs: ProtocolBugs{
5145 SendSupportedVersions: []uint16{0x1111},
5146 },
5147 },
5148 shouldFail: true,
5149 expectedError: ":UNSUPPORTED_PROTOCOL:",
5150 })
5151 testCases = append(testCases, testCase{
5152 protocol: dtls,
5153 testType: serverTest,
5154 name: "NoSupportedVersions-DTLS",
5155 config: Config{
5156 Bugs: ProtocolBugs{
5157 SendSupportedVersions: []uint16{0x1111},
5158 },
5159 },
5160 shouldFail: true,
5161 expectedError: ":UNSUPPORTED_PROTOCOL:",
5162 })
5163
5164 testCases = append(testCases, testCase{
5165 testType: serverTest,
5166 name: "ClientHelloVersionTooHigh",
5167 config: Config{
5168 MaxVersion: VersionTLS13,
5169 Bugs: ProtocolBugs{
5170 SendClientVersion: 0x0304,
5171 OmitSupportedVersions: true,
5172 },
5173 },
5174 expectedVersion: VersionTLS12,
5175 })
5176
5177 testCases = append(testCases, testCase{
5178 testType: serverTest,
5179 name: "ConflictingVersionNegotiation",
5180 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005181 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005182 SendClientVersion: VersionTLS12,
5183 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005184 },
5185 },
David Benjaminad75a662016-09-30 15:42:59 -04005186 // The extension takes precedence over the ClientHello version.
5187 expectedVersion: VersionTLS11,
5188 })
5189
5190 testCases = append(testCases, testCase{
5191 testType: serverTest,
5192 name: "ConflictingVersionNegotiation-2",
5193 config: Config{
5194 Bugs: ProtocolBugs{
5195 SendClientVersion: VersionTLS11,
5196 SendSupportedVersions: []uint16{VersionTLS12},
5197 },
5198 },
5199 // The extension takes precedence over the ClientHello version.
5200 expectedVersion: VersionTLS12,
5201 })
5202
5203 testCases = append(testCases, testCase{
5204 testType: serverTest,
5205 name: "RejectFinalTLS13",
5206 config: Config{
5207 Bugs: ProtocolBugs{
5208 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5209 },
5210 },
5211 // We currently implement a draft TLS 1.3 version. Ensure that
5212 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005213 expectedVersion: VersionTLS12,
5214 })
5215
Steven Valdez038da9b2017-07-10 12:57:25 -04005216 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5217 // the ServerHello.
5218 testCases = append(testCases, testCase{
5219 testType: clientTest,
5220 name: "SupportedVersionSelection-TLS12",
5221 config: Config{
5222 MaxVersion: VersionTLS12,
5223 Bugs: ProtocolBugs{
5224 SendServerSupportedExtensionVersion: VersionTLS12,
5225 },
5226 },
5227 shouldFail: true,
5228 expectedError: ":UNEXPECTED_EXTENSION:",
5229 })
5230
5231 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5232 // supported_versions extension in the ServerHello.
5233 testCases = append(testCases, testCase{
5234 testType: clientTest,
5235 name: "SupportedVersionSelection-TLS13",
5236 config: Config{
5237 MaxVersion: VersionTLS13,
5238 Bugs: ProtocolBugs{
5239 SendServerSupportedExtensionVersion: tls13DraftVersion,
5240 },
5241 },
5242 shouldFail: true,
5243 expectedError: ":UNEXPECTED_EXTENSION:",
5244 })
5245
Brian Smithf85d3232016-10-28 10:34:06 -10005246 // Test that the maximum version is selected regardless of the
5247 // client-sent order.
5248 testCases = append(testCases, testCase{
5249 testType: serverTest,
5250 name: "IgnoreClientVersionOrder",
5251 config: Config{
5252 Bugs: ProtocolBugs{
5253 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5254 },
5255 },
5256 expectedVersion: VersionTLS13,
5257 })
5258
David Benjamin95c69562016-06-29 18:15:03 -04005259 // Test for version tolerance.
5260 testCases = append(testCases, testCase{
5261 testType: serverTest,
5262 name: "MinorVersionTolerance",
5263 config: Config{
5264 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005265 SendClientVersion: 0x03ff,
5266 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005267 },
5268 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005269 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005270 })
5271 testCases = append(testCases, testCase{
5272 testType: serverTest,
5273 name: "MajorVersionTolerance",
5274 config: Config{
5275 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005276 SendClientVersion: 0x0400,
5277 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005278 },
5279 },
David Benjaminad75a662016-09-30 15:42:59 -04005280 // TLS 1.3 must be negotiated with the supported_versions
5281 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005282 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005283 })
David Benjaminad75a662016-09-30 15:42:59 -04005284 testCases = append(testCases, testCase{
5285 testType: serverTest,
5286 name: "VersionTolerance-TLS13",
5287 config: Config{
5288 Bugs: ProtocolBugs{
5289 // Although TLS 1.3 does not use
5290 // ClientHello.version, it still tolerates high
5291 // values there.
5292 SendClientVersion: 0x0400,
5293 },
5294 },
5295 expectedVersion: VersionTLS13,
5296 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005297
David Benjamin95c69562016-06-29 18:15:03 -04005298 testCases = append(testCases, testCase{
5299 protocol: dtls,
5300 testType: serverTest,
5301 name: "MinorVersionTolerance-DTLS",
5302 config: Config{
5303 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005304 SendClientVersion: 0xfe00,
5305 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005306 },
5307 },
5308 expectedVersion: VersionTLS12,
5309 })
5310 testCases = append(testCases, testCase{
5311 protocol: dtls,
5312 testType: serverTest,
5313 name: "MajorVersionTolerance-DTLS",
5314 config: Config{
5315 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005316 SendClientVersion: 0xfdff,
5317 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005318 },
5319 },
5320 expectedVersion: VersionTLS12,
5321 })
5322
5323 // Test that versions below 3.0 are rejected.
5324 testCases = append(testCases, testCase{
5325 testType: serverTest,
5326 name: "VersionTooLow",
5327 config: Config{
5328 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005329 SendClientVersion: 0x0200,
5330 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005331 },
5332 },
5333 shouldFail: true,
5334 expectedError: ":UNSUPPORTED_PROTOCOL:",
5335 })
5336 testCases = append(testCases, testCase{
5337 protocol: dtls,
5338 testType: serverTest,
5339 name: "VersionTooLow-DTLS",
5340 config: Config{
5341 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005342 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005343 },
5344 },
5345 shouldFail: true,
5346 expectedError: ":UNSUPPORTED_PROTOCOL:",
5347 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005348
David Benjamin2dc02042016-09-19 19:57:37 -04005349 testCases = append(testCases, testCase{
5350 name: "ServerBogusVersion",
5351 config: Config{
5352 Bugs: ProtocolBugs{
5353 SendServerHelloVersion: 0x1234,
5354 },
5355 },
5356 shouldFail: true,
5357 expectedError: ":UNSUPPORTED_PROTOCOL:",
5358 })
5359
David Benjamin1f61f0d2016-07-10 12:20:35 -04005360 // Test TLS 1.3's downgrade signal.
5361 testCases = append(testCases, testCase{
5362 name: "Downgrade-TLS12-Client",
5363 config: Config{
5364 Bugs: ProtocolBugs{
5365 NegotiateVersion: VersionTLS12,
5366 },
5367 },
David Benjamin592b5322016-09-30 15:15:01 -04005368 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005369 // TODO(davidben): This test should fail once TLS 1.3 is final
5370 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005371 })
5372 testCases = append(testCases, testCase{
5373 testType: serverTest,
5374 name: "Downgrade-TLS12-Server",
5375 config: Config{
5376 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005377 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005378 },
5379 },
David Benjamin592b5322016-09-30 15:15:01 -04005380 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005381 // TODO(davidben): This test should fail once TLS 1.3 is final
5382 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005383 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005384}
5385
David Benjaminaccb4542014-12-12 23:44:33 -05005386func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005387 for _, protocol := range []protocol{tls, dtls} {
5388 for _, shimVers := range allVersions(protocol) {
5389 // Assemble flags to disable all older versions on the shim.
5390 var flags []string
5391 for _, vers := range allVersions(protocol) {
5392 if vers.version < shimVers.version {
5393 flags = append(flags, vers.excludeFlag)
5394 }
David Benjaminaccb4542014-12-12 23:44:33 -05005395 }
Steven Valdez520e1222017-06-13 12:45:25 -04005396
5397 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5398
5399 if shimVers.tls13Variant != 0 {
5400 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5401 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5402 }
5403
5404 for _, runnerVers := range allVersions(protocol) {
5405 // Different TLS 1.3 variants are incompatible with each other and don't
5406 // produce consistent minimum versions.
5407 //
5408 // TODO(davidben): Fold these tests (the main value is in the
5409 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5410 // on intended shim behavior, not the shim + runner combination.
5411 if shimVers.tls13Variant != runnerVers.tls13Variant {
5412 continue
5413 }
5414
David Benjaminaccb4542014-12-12 23:44:33 -05005415 suffix := shimVers.name + "-" + runnerVers.name
5416 if protocol == dtls {
5417 suffix += "-DTLS"
5418 }
David Benjaminaccb4542014-12-12 23:44:33 -05005419
David Benjaminaccb4542014-12-12 23:44:33 -05005420 var expectedVersion uint16
5421 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005422 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005423 if runnerVers.version >= shimVers.version {
5424 expectedVersion = runnerVers.version
5425 } else {
5426 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005427 expectedError = ":UNSUPPORTED_PROTOCOL:"
5428 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005429 }
5430
5431 testCases = append(testCases, testCase{
5432 protocol: protocol,
5433 testType: clientTest,
5434 name: "MinimumVersion-Client-" + suffix,
5435 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005436 MaxVersion: runnerVers.version,
5437 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005438 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005439 // Ensure the server does not decline to
5440 // select a version (versions extension) or
5441 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005442 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005443 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005444 },
David Benjaminaccb4542014-12-12 23:44:33 -05005445 },
David Benjamin87909c02014-12-13 01:55:01 -05005446 flags: flags,
5447 expectedVersion: expectedVersion,
5448 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005449 expectedError: expectedError,
5450 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005451 })
5452 testCases = append(testCases, testCase{
5453 protocol: protocol,
5454 testType: clientTest,
5455 name: "MinimumVersion-Client2-" + suffix,
5456 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005457 MaxVersion: runnerVers.version,
5458 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005459 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005460 // Ensure the server does not decline to
5461 // select a version (versions extension) or
5462 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005463 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005464 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005465 },
David Benjaminaccb4542014-12-12 23:44:33 -05005466 },
Steven Valdez520e1222017-06-13 12:45:25 -04005467 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005468 expectedVersion: expectedVersion,
5469 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005470 expectedError: expectedError,
5471 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005472 })
5473
5474 testCases = append(testCases, testCase{
5475 protocol: protocol,
5476 testType: serverTest,
5477 name: "MinimumVersion-Server-" + suffix,
5478 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005479 MaxVersion: runnerVers.version,
5480 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005481 },
David Benjamin87909c02014-12-13 01:55:01 -05005482 flags: flags,
5483 expectedVersion: expectedVersion,
5484 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005485 expectedError: expectedError,
5486 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005487 })
5488 testCases = append(testCases, testCase{
5489 protocol: protocol,
5490 testType: serverTest,
5491 name: "MinimumVersion-Server2-" + suffix,
5492 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005493 MaxVersion: runnerVers.version,
5494 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005495 },
Steven Valdez520e1222017-06-13 12:45:25 -04005496 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005497 expectedVersion: expectedVersion,
5498 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005499 expectedError: expectedError,
5500 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005501 })
5502 }
5503 }
5504 }
5505}
5506
David Benjamine78bfde2014-09-06 12:45:15 -04005507func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005508 // TODO(davidben): Extensions, where applicable, all move their server
5509 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5510 // tests for both. Also test interaction with 0-RTT when implemented.
5511
David Benjamin97d17d92016-07-14 16:12:00 -04005512 // Repeat extensions tests all versions except SSL 3.0.
5513 for _, ver := range tlsVersions {
5514 if ver.version == VersionSSL30 {
5515 continue
5516 }
5517
David Benjamin97d17d92016-07-14 16:12:00 -04005518 // Test that duplicate extensions are rejected.
5519 testCases = append(testCases, testCase{
5520 testType: clientTest,
5521 name: "DuplicateExtensionClient-" + ver.name,
5522 config: Config{
5523 MaxVersion: ver.version,
5524 Bugs: ProtocolBugs{
5525 DuplicateExtension: true,
5526 },
David Benjamine78bfde2014-09-06 12:45:15 -04005527 },
David Benjamina5022392017-07-10 17:40:39 -04005528 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005529 shouldFail: true,
5530 expectedLocalError: "remote error: error decoding message",
5531 })
5532 testCases = append(testCases, testCase{
5533 testType: serverTest,
5534 name: "DuplicateExtensionServer-" + ver.name,
5535 config: Config{
5536 MaxVersion: ver.version,
5537 Bugs: ProtocolBugs{
5538 DuplicateExtension: true,
5539 },
David Benjamine78bfde2014-09-06 12:45:15 -04005540 },
David Benjamina5022392017-07-10 17:40:39 -04005541 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005542 shouldFail: true,
5543 expectedLocalError: "remote error: error decoding message",
5544 })
5545
5546 // Test SNI.
5547 testCases = append(testCases, testCase{
5548 testType: clientTest,
5549 name: "ServerNameExtensionClient-" + ver.name,
5550 config: Config{
5551 MaxVersion: ver.version,
5552 Bugs: ProtocolBugs{
5553 ExpectServerName: "example.com",
5554 },
David Benjamine78bfde2014-09-06 12:45:15 -04005555 },
David Benjamina5022392017-07-10 17:40:39 -04005556 tls13Variant: ver.tls13Variant,
5557 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005558 })
5559 testCases = append(testCases, testCase{
5560 testType: clientTest,
5561 name: "ServerNameExtensionClientMismatch-" + ver.name,
5562 config: Config{
5563 MaxVersion: ver.version,
5564 Bugs: ProtocolBugs{
5565 ExpectServerName: "mismatch.com",
5566 },
David Benjamine78bfde2014-09-06 12:45:15 -04005567 },
David Benjamin97d17d92016-07-14 16:12:00 -04005568 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005569 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005570 shouldFail: true,
5571 expectedLocalError: "tls: unexpected server name",
5572 })
5573 testCases = append(testCases, testCase{
5574 testType: clientTest,
5575 name: "ServerNameExtensionClientMissing-" + ver.name,
5576 config: Config{
5577 MaxVersion: ver.version,
5578 Bugs: ProtocolBugs{
5579 ExpectServerName: "missing.com",
5580 },
David Benjamine78bfde2014-09-06 12:45:15 -04005581 },
David Benjamina5022392017-07-10 17:40:39 -04005582 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005583 shouldFail: true,
5584 expectedLocalError: "tls: unexpected server name",
5585 })
5586 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005587 testType: clientTest,
5588 name: "TolerateServerNameAck-" + ver.name,
5589 config: Config{
5590 MaxVersion: ver.version,
5591 Bugs: ProtocolBugs{
5592 SendServerNameAck: true,
5593 },
5594 },
David Benjamina5022392017-07-10 17:40:39 -04005595 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005596 flags: []string{"-host-name", "example.com"},
5597 resumeSession: true,
5598 })
5599 testCases = append(testCases, testCase{
5600 testType: clientTest,
5601 name: "UnsolicitedServerNameAck-" + ver.name,
5602 config: Config{
5603 MaxVersion: ver.version,
5604 Bugs: ProtocolBugs{
5605 SendServerNameAck: true,
5606 },
5607 },
David Benjamina5022392017-07-10 17:40:39 -04005608 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005609 shouldFail: true,
5610 expectedError: ":UNEXPECTED_EXTENSION:",
5611 expectedLocalError: "remote error: unsupported extension",
5612 })
5613 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005614 testType: serverTest,
5615 name: "ServerNameExtensionServer-" + ver.name,
5616 config: Config{
5617 MaxVersion: ver.version,
5618 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005619 },
David Benjamina5022392017-07-10 17:40:39 -04005620 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005621 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005622 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005623 })
5624
5625 // Test ALPN.
5626 testCases = append(testCases, testCase{
5627 testType: clientTest,
5628 name: "ALPNClient-" + ver.name,
5629 config: Config{
5630 MaxVersion: ver.version,
5631 NextProtos: []string{"foo"},
5632 },
5633 flags: []string{
5634 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5635 "-expect-alpn", "foo",
5636 },
David Benjamina5022392017-07-10 17:40:39 -04005637 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005638 expectedNextProto: "foo",
5639 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005640 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005641 })
5642 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005643 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005644 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005645 config: Config{
5646 MaxVersion: ver.version,
5647 Bugs: ProtocolBugs{
5648 SendALPN: "baz",
5649 },
5650 },
5651 flags: []string{
5652 "-advertise-alpn", "\x03foo\x03bar",
5653 },
David Benjamina5022392017-07-10 17:40:39 -04005654 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005655 shouldFail: true,
5656 expectedError: ":INVALID_ALPN_PROTOCOL:",
5657 expectedLocalError: "remote error: illegal parameter",
5658 })
5659 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005660 testType: clientTest,
5661 name: "ALPNClient-AllowUnknown-" + ver.name,
5662 config: Config{
5663 MaxVersion: ver.version,
5664 Bugs: ProtocolBugs{
5665 SendALPN: "baz",
5666 },
5667 },
5668 flags: []string{
5669 "-advertise-alpn", "\x03foo\x03bar",
5670 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005671 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005672 },
David Benjamina5022392017-07-10 17:40:39 -04005673 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005674 })
5675 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005676 testType: serverTest,
5677 name: "ALPNServer-" + ver.name,
5678 config: Config{
5679 MaxVersion: ver.version,
5680 NextProtos: []string{"foo", "bar", "baz"},
5681 },
5682 flags: []string{
5683 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5684 "-select-alpn", "foo",
5685 },
David Benjamina5022392017-07-10 17:40:39 -04005686 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005687 expectedNextProto: "foo",
5688 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005689 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005690 })
5691 testCases = append(testCases, testCase{
5692 testType: serverTest,
5693 name: "ALPNServer-Decline-" + ver.name,
5694 config: Config{
5695 MaxVersion: ver.version,
5696 NextProtos: []string{"foo", "bar", "baz"},
5697 },
5698 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005699 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005700 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005701 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005702 })
5703
David Benjamin25fe85b2016-08-09 20:00:32 -04005704 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5705 // called once.
5706 testCases = append(testCases, testCase{
5707 testType: serverTest,
5708 name: "ALPNServer-Async-" + ver.name,
5709 config: Config{
5710 MaxVersion: ver.version,
5711 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005712 // Prior to TLS 1.3, exercise the asynchronous session callback.
5713 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005714 },
5715 flags: []string{
5716 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5717 "-select-alpn", "foo",
5718 "-async",
5719 },
David Benjamina5022392017-07-10 17:40:39 -04005720 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005721 expectedNextProto: "foo",
5722 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005723 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005724 })
5725
David Benjamin97d17d92016-07-14 16:12:00 -04005726 var emptyString string
5727 testCases = append(testCases, testCase{
5728 testType: clientTest,
5729 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5730 config: Config{
5731 MaxVersion: ver.version,
5732 NextProtos: []string{""},
5733 Bugs: ProtocolBugs{
5734 // A server returning an empty ALPN protocol
5735 // should be rejected.
5736 ALPNProtocol: &emptyString,
5737 },
5738 },
5739 flags: []string{
5740 "-advertise-alpn", "\x03foo",
5741 },
David Benjamina5022392017-07-10 17:40:39 -04005742 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005743 shouldFail: true,
5744 expectedError: ":PARSE_TLSEXT:",
5745 })
5746 testCases = append(testCases, testCase{
5747 testType: serverTest,
5748 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5749 config: Config{
5750 MaxVersion: ver.version,
5751 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005752 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005753 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005754 },
David Benjamin97d17d92016-07-14 16:12:00 -04005755 flags: []string{
5756 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005757 },
David Benjamina5022392017-07-10 17:40:39 -04005758 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005759 shouldFail: true,
5760 expectedError: ":PARSE_TLSEXT:",
5761 })
5762
5763 // Test NPN and the interaction with ALPN.
5764 if ver.version < VersionTLS13 {
5765 // Test that the server prefers ALPN over NPN.
5766 testCases = append(testCases, testCase{
5767 testType: serverTest,
5768 name: "ALPNServer-Preferred-" + ver.name,
5769 config: Config{
5770 MaxVersion: ver.version,
5771 NextProtos: []string{"foo", "bar", "baz"},
5772 },
5773 flags: []string{
5774 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5775 "-select-alpn", "foo",
5776 "-advertise-npn", "\x03foo\x03bar\x03baz",
5777 },
David Benjamina5022392017-07-10 17:40:39 -04005778 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005779 expectedNextProto: "foo",
5780 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005781 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005782 })
5783 testCases = append(testCases, testCase{
5784 testType: serverTest,
5785 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5786 config: Config{
5787 MaxVersion: ver.version,
5788 NextProtos: []string{"foo", "bar", "baz"},
5789 Bugs: ProtocolBugs{
5790 SwapNPNAndALPN: true,
5791 },
5792 },
5793 flags: []string{
5794 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5795 "-select-alpn", "foo",
5796 "-advertise-npn", "\x03foo\x03bar\x03baz",
5797 },
David Benjamina5022392017-07-10 17:40:39 -04005798 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005799 expectedNextProto: "foo",
5800 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005801 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005802 })
5803
5804 // Test that negotiating both NPN and ALPN is forbidden.
5805 testCases = append(testCases, testCase{
5806 name: "NegotiateALPNAndNPN-" + ver.name,
5807 config: Config{
5808 MaxVersion: ver.version,
5809 NextProtos: []string{"foo", "bar", "baz"},
5810 Bugs: ProtocolBugs{
5811 NegotiateALPNAndNPN: true,
5812 },
5813 },
5814 flags: []string{
5815 "-advertise-alpn", "\x03foo",
5816 "-select-next-proto", "foo",
5817 },
David Benjamina5022392017-07-10 17:40:39 -04005818 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005819 shouldFail: true,
5820 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5821 })
5822 testCases = append(testCases, testCase{
5823 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5824 config: Config{
5825 MaxVersion: ver.version,
5826 NextProtos: []string{"foo", "bar", "baz"},
5827 Bugs: ProtocolBugs{
5828 NegotiateALPNAndNPN: true,
5829 SwapNPNAndALPN: true,
5830 },
5831 },
5832 flags: []string{
5833 "-advertise-alpn", "\x03foo",
5834 "-select-next-proto", "foo",
5835 },
David Benjamina5022392017-07-10 17:40:39 -04005836 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005837 shouldFail: true,
5838 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5839 })
David Benjamin97d17d92016-07-14 16:12:00 -04005840 }
5841
5842 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005843
5844 // Resume with a corrupt ticket.
5845 testCases = append(testCases, testCase{
5846 testType: serverTest,
5847 name: "CorruptTicket-" + ver.name,
5848 config: Config{
5849 MaxVersion: ver.version,
5850 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005851 FilterTicket: func(in []byte) ([]byte, error) {
5852 in[len(in)-1] ^= 1
5853 return in, nil
5854 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005855 },
5856 },
David Benjamina5022392017-07-10 17:40:39 -04005857 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005858 resumeSession: true,
5859 expectResumeRejected: true,
5860 })
5861 // Test the ticket callback, with and without renewal.
5862 testCases = append(testCases, testCase{
5863 testType: serverTest,
5864 name: "TicketCallback-" + ver.name,
5865 config: Config{
5866 MaxVersion: ver.version,
5867 },
David Benjamina5022392017-07-10 17:40:39 -04005868 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005869 resumeSession: true,
5870 flags: []string{"-use-ticket-callback"},
5871 })
5872 testCases = append(testCases, testCase{
5873 testType: serverTest,
5874 name: "TicketCallback-Renew-" + ver.name,
5875 config: Config{
5876 MaxVersion: ver.version,
5877 Bugs: ProtocolBugs{
5878 ExpectNewTicket: true,
5879 },
5880 },
David Benjamina5022392017-07-10 17:40:39 -04005881 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005882 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5883 resumeSession: true,
5884 })
5885
5886 // Test that the ticket callback is only called once when everything before
5887 // it in the ClientHello is asynchronous. This corrupts the ticket so
5888 // certificate selection callbacks run.
5889 testCases = append(testCases, testCase{
5890 testType: serverTest,
5891 name: "TicketCallback-SingleCall-" + ver.name,
5892 config: Config{
5893 MaxVersion: ver.version,
5894 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005895 FilterTicket: func(in []byte) ([]byte, error) {
5896 in[len(in)-1] ^= 1
5897 return in, nil
5898 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005899 },
5900 },
David Benjamina5022392017-07-10 17:40:39 -04005901 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005902 resumeSession: true,
5903 expectResumeRejected: true,
5904 flags: []string{
5905 "-use-ticket-callback",
5906 "-async",
5907 },
5908 })
5909
David Benjamind4c349b2017-02-09 14:07:17 -05005910 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005911 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005912 testCases = append(testCases, testCase{
5913 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005914 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005915 config: Config{
5916 MaxVersion: ver.version,
5917 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005918 EmptyTicketSessionID: true,
5919 },
5920 },
5921 resumeSession: true,
5922 })
5923 testCases = append(testCases, testCase{
5924 testType: serverTest,
5925 name: "TicketSessionIDLength-16-" + ver.name,
5926 config: Config{
5927 MaxVersion: ver.version,
5928 Bugs: ProtocolBugs{
5929 TicketSessionIDLength: 16,
5930 },
5931 },
5932 resumeSession: true,
5933 })
5934 testCases = append(testCases, testCase{
5935 testType: serverTest,
5936 name: "TicketSessionIDLength-32-" + ver.name,
5937 config: Config{
5938 MaxVersion: ver.version,
5939 Bugs: ProtocolBugs{
5940 TicketSessionIDLength: 32,
5941 },
5942 },
5943 resumeSession: true,
5944 })
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
5947 name: "TicketSessionIDLength-33-" + ver.name,
5948 config: Config{
5949 MaxVersion: ver.version,
5950 Bugs: ProtocolBugs{
5951 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005952 },
5953 },
5954 resumeSession: true,
5955 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005956 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005957 expectedError: ":DECODE_ERROR:",
5958 })
5959 }
5960
5961 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5962 // are ignored.
5963 if ver.hasDTLS {
5964 testCases = append(testCases, testCase{
5965 protocol: dtls,
5966 name: "SRTP-Client-" + ver.name,
5967 config: Config{
5968 MaxVersion: ver.version,
5969 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5970 },
5971 flags: []string{
5972 "-srtp-profiles",
5973 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5974 },
5975 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5976 })
5977 testCases = append(testCases, testCase{
5978 protocol: dtls,
5979 testType: serverTest,
5980 name: "SRTP-Server-" + ver.name,
5981 config: Config{
5982 MaxVersion: ver.version,
5983 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5984 },
5985 flags: []string{
5986 "-srtp-profiles",
5987 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5988 },
5989 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5990 })
5991 // Test that the MKI is ignored.
5992 testCases = append(testCases, testCase{
5993 protocol: dtls,
5994 testType: serverTest,
5995 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5996 config: Config{
5997 MaxVersion: ver.version,
5998 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5999 Bugs: ProtocolBugs{
6000 SRTPMasterKeyIdentifer: "bogus",
6001 },
6002 },
6003 flags: []string{
6004 "-srtp-profiles",
6005 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6006 },
6007 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6008 })
6009 // Test that SRTP isn't negotiated on the server if there were
6010 // no matching profiles.
6011 testCases = append(testCases, testCase{
6012 protocol: dtls,
6013 testType: serverTest,
6014 name: "SRTP-Server-NoMatch-" + ver.name,
6015 config: Config{
6016 MaxVersion: ver.version,
6017 SRTPProtectionProfiles: []uint16{100, 101, 102},
6018 },
6019 flags: []string{
6020 "-srtp-profiles",
6021 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6022 },
6023 expectedSRTPProtectionProfile: 0,
6024 })
6025 // Test that the server returning an invalid SRTP profile is
6026 // flagged as an error by the client.
6027 testCases = append(testCases, testCase{
6028 protocol: dtls,
6029 name: "SRTP-Client-NoMatch-" + ver.name,
6030 config: Config{
6031 MaxVersion: ver.version,
6032 Bugs: ProtocolBugs{
6033 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6034 },
6035 },
6036 flags: []string{
6037 "-srtp-profiles",
6038 "SRTP_AES128_CM_SHA1_80",
6039 },
6040 shouldFail: true,
6041 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6042 })
6043 }
6044
6045 // Test SCT list.
6046 testCases = append(testCases, testCase{
6047 name: "SignedCertificateTimestampList-Client-" + ver.name,
6048 testType: clientTest,
6049 config: Config{
6050 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006051 },
David Benjamin97d17d92016-07-14 16:12:00 -04006052 flags: []string{
6053 "-enable-signed-cert-timestamps",
6054 "-expect-signed-cert-timestamps",
6055 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006056 },
David Benjamina5022392017-07-10 17:40:39 -04006057 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006058 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006059 })
David Benjamindaa88502016-10-04 16:32:16 -04006060
Adam Langleycfa08c32016-11-17 13:21:27 -08006061 var differentSCTList []byte
6062 differentSCTList = append(differentSCTList, testSCTList...)
6063 differentSCTList[len(differentSCTList)-1] ^= 1
6064
David Benjamindaa88502016-10-04 16:32:16 -04006065 // The SCT extension did not specify that it must only be sent on resumption as it
6066 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006067 testCases = append(testCases, testCase{
6068 name: "SendSCTListOnResume-" + ver.name,
6069 config: Config{
6070 MaxVersion: ver.version,
6071 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006072 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006073 },
David Benjamind98452d2015-06-16 14:16:23 -04006074 },
David Benjamin97d17d92016-07-14 16:12:00 -04006075 flags: []string{
6076 "-enable-signed-cert-timestamps",
6077 "-expect-signed-cert-timestamps",
6078 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006079 },
David Benjamina5022392017-07-10 17:40:39 -04006080 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006081 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006082 })
David Benjamindaa88502016-10-04 16:32:16 -04006083
David Benjamin97d17d92016-07-14 16:12:00 -04006084 testCases = append(testCases, testCase{
6085 name: "SignedCertificateTimestampList-Server-" + ver.name,
6086 testType: serverTest,
6087 config: Config{
6088 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006089 },
David Benjamin97d17d92016-07-14 16:12:00 -04006090 flags: []string{
6091 "-signed-cert-timestamps",
6092 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006093 },
David Benjamina5022392017-07-10 17:40:39 -04006094 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006095 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006096 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006097 })
David Benjamin53210cb2016-11-16 09:01:48 +09006098
Adam Langleycfa08c32016-11-17 13:21:27 -08006099 emptySCTListCert := *testCerts[0].cert
6100 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6101
6102 // Test empty SCT list.
6103 testCases = append(testCases, testCase{
6104 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6105 testType: clientTest,
6106 config: Config{
6107 MaxVersion: ver.version,
6108 Certificates: []Certificate{emptySCTListCert},
6109 },
6110 flags: []string{
6111 "-enable-signed-cert-timestamps",
6112 },
David Benjamina5022392017-07-10 17:40:39 -04006113 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006114 shouldFail: true,
6115 expectedError: ":ERROR_PARSING_EXTENSION:",
6116 })
6117
6118 emptySCTCert := *testCerts[0].cert
6119 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6120
6121 // Test empty SCT in non-empty list.
6122 testCases = append(testCases, testCase{
6123 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6124 testType: clientTest,
6125 config: Config{
6126 MaxVersion: ver.version,
6127 Certificates: []Certificate{emptySCTCert},
6128 },
6129 flags: []string{
6130 "-enable-signed-cert-timestamps",
6131 },
David Benjamina5022392017-07-10 17:40:39 -04006132 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006133 shouldFail: true,
6134 expectedError: ":ERROR_PARSING_EXTENSION:",
6135 })
6136
David Benjamin53210cb2016-11-16 09:01:48 +09006137 // Test that certificate-related extensions are not sent unsolicited.
6138 testCases = append(testCases, testCase{
6139 testType: serverTest,
6140 name: "UnsolicitedCertificateExtensions-" + ver.name,
6141 config: Config{
6142 MaxVersion: ver.version,
6143 Bugs: ProtocolBugs{
6144 NoOCSPStapling: true,
6145 NoSignedCertificateTimestamps: true,
6146 },
6147 },
David Benjamina5022392017-07-10 17:40:39 -04006148 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006149 flags: []string{
6150 "-ocsp-response",
6151 base64.StdEncoding.EncodeToString(testOCSPResponse),
6152 "-signed-cert-timestamps",
6153 base64.StdEncoding.EncodeToString(testSCTList),
6154 },
6155 })
David Benjamin97d17d92016-07-14 16:12:00 -04006156 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006157
Paul Lietar4fac72e2015-09-09 13:44:55 +01006158 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006159 testType: clientTest,
6160 name: "ClientHelloPadding",
6161 config: Config{
6162 Bugs: ProtocolBugs{
6163 RequireClientHelloSize: 512,
6164 },
6165 },
6166 // This hostname just needs to be long enough to push the
6167 // ClientHello into F5's danger zone between 256 and 511 bytes
6168 // long.
6169 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6170 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006171
6172 // Extensions should not function in SSL 3.0.
6173 testCases = append(testCases, testCase{
6174 testType: serverTest,
6175 name: "SSLv3Extensions-NoALPN",
6176 config: Config{
6177 MaxVersion: VersionSSL30,
6178 NextProtos: []string{"foo", "bar", "baz"},
6179 },
6180 flags: []string{
6181 "-select-alpn", "foo",
6182 },
6183 expectNoNextProto: true,
6184 })
6185
6186 // Test session tickets separately as they follow a different codepath.
6187 testCases = append(testCases, testCase{
6188 testType: serverTest,
6189 name: "SSLv3Extensions-NoTickets",
6190 config: Config{
6191 MaxVersion: VersionSSL30,
6192 Bugs: ProtocolBugs{
6193 // Historically, session tickets in SSL 3.0
6194 // failed in different ways depending on whether
6195 // the client supported renegotiation_info.
6196 NoRenegotiationInfo: true,
6197 },
6198 },
6199 resumeSession: true,
6200 })
6201 testCases = append(testCases, testCase{
6202 testType: serverTest,
6203 name: "SSLv3Extensions-NoTickets2",
6204 config: Config{
6205 MaxVersion: VersionSSL30,
6206 },
6207 resumeSession: true,
6208 })
6209
6210 // But SSL 3.0 does send and process renegotiation_info.
6211 testCases = append(testCases, testCase{
6212 testType: serverTest,
6213 name: "SSLv3Extensions-RenegotiationInfo",
6214 config: Config{
6215 MaxVersion: VersionSSL30,
6216 Bugs: ProtocolBugs{
6217 RequireRenegotiationInfo: true,
6218 },
6219 },
David Benjamind2610042017-01-03 10:49:28 -05006220 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006221 })
6222 testCases = append(testCases, testCase{
6223 testType: serverTest,
6224 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6225 config: Config{
6226 MaxVersion: VersionSSL30,
6227 Bugs: ProtocolBugs{
6228 NoRenegotiationInfo: true,
6229 SendRenegotiationSCSV: true,
6230 RequireRenegotiationInfo: true,
6231 },
6232 },
David Benjamind2610042017-01-03 10:49:28 -05006233 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006234 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006235
6236 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6237 // in ServerHello.
6238 testCases = append(testCases, testCase{
6239 name: "NPN-Forbidden-TLS13",
6240 config: Config{
6241 MaxVersion: VersionTLS13,
6242 NextProtos: []string{"foo"},
6243 Bugs: ProtocolBugs{
6244 NegotiateNPNAtAllVersions: true,
6245 },
6246 },
6247 flags: []string{"-select-next-proto", "foo"},
6248 shouldFail: true,
6249 expectedError: ":ERROR_PARSING_EXTENSION:",
6250 })
6251 testCases = append(testCases, testCase{
6252 name: "EMS-Forbidden-TLS13",
6253 config: Config{
6254 MaxVersion: VersionTLS13,
6255 Bugs: ProtocolBugs{
6256 NegotiateEMSAtAllVersions: true,
6257 },
6258 },
6259 shouldFail: true,
6260 expectedError: ":ERROR_PARSING_EXTENSION:",
6261 })
6262 testCases = append(testCases, testCase{
6263 name: "RenegotiationInfo-Forbidden-TLS13",
6264 config: Config{
6265 MaxVersion: VersionTLS13,
6266 Bugs: ProtocolBugs{
6267 NegotiateRenegotiationInfoAtAllVersions: true,
6268 },
6269 },
6270 shouldFail: true,
6271 expectedError: ":ERROR_PARSING_EXTENSION:",
6272 })
6273 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006274 name: "Ticket-Forbidden-TLS13",
6275 config: Config{
6276 MaxVersion: VersionTLS12,
6277 },
6278 resumeConfig: &Config{
6279 MaxVersion: VersionTLS13,
6280 Bugs: ProtocolBugs{
6281 AdvertiseTicketExtension: true,
6282 },
6283 },
6284 resumeSession: true,
6285 shouldFail: true,
6286 expectedError: ":ERROR_PARSING_EXTENSION:",
6287 })
6288
6289 // Test that illegal extensions in TLS 1.3 are declined by the server if
6290 // offered in ClientHello. The runner's server will fail if this occurs,
6291 // so we exercise the offering path. (EMS and Renegotiation Info are
6292 // implicit in every test.)
6293 testCases = append(testCases, testCase{
6294 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006295 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006296 config: Config{
6297 MaxVersion: VersionTLS13,
6298 NextProtos: []string{"bar"},
6299 },
6300 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6301 })
David Benjamin196df5b2016-09-21 16:23:27 -04006302
David Benjamindaa88502016-10-04 16:32:16 -04006303 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6304 // tolerated.
6305 testCases = append(testCases, testCase{
6306 name: "SendOCSPResponseOnResume-TLS12",
6307 config: Config{
6308 MaxVersion: VersionTLS12,
6309 Bugs: ProtocolBugs{
6310 SendOCSPResponseOnResume: []byte("bogus"),
6311 },
6312 },
6313 flags: []string{
6314 "-enable-ocsp-stapling",
6315 "-expect-ocsp-response",
6316 base64.StdEncoding.EncodeToString(testOCSPResponse),
6317 },
6318 resumeSession: true,
6319 })
6320
David Benjamindaa88502016-10-04 16:32:16 -04006321 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006322 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006323 config: Config{
6324 MaxVersion: VersionTLS13,
6325 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006326 SendExtensionOnCertificate: testOCSPExtension,
6327 },
6328 },
6329 shouldFail: true,
6330 expectedError: ":UNEXPECTED_EXTENSION:",
6331 })
6332
6333 testCases = append(testCases, testCase{
6334 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6335 config: Config{
6336 MaxVersion: VersionTLS13,
6337 Bugs: ProtocolBugs{
6338 SendExtensionOnCertificate: testSCTExtension,
6339 },
6340 },
6341 shouldFail: true,
6342 expectedError: ":UNEXPECTED_EXTENSION:",
6343 })
6344
6345 // Test that extensions on client certificates are never accepted.
6346 testCases = append(testCases, testCase{
6347 name: "SendExtensionOnClientCertificate-TLS13",
6348 testType: serverTest,
6349 config: Config{
6350 MaxVersion: VersionTLS13,
6351 Certificates: []Certificate{rsaCertificate},
6352 Bugs: ProtocolBugs{
6353 SendExtensionOnCertificate: testOCSPExtension,
6354 },
6355 },
6356 flags: []string{
6357 "-enable-ocsp-stapling",
6358 "-require-any-client-certificate",
6359 },
6360 shouldFail: true,
6361 expectedError: ":UNEXPECTED_EXTENSION:",
6362 })
6363
6364 testCases = append(testCases, testCase{
6365 name: "SendUnknownExtensionOnCertificate-TLS13",
6366 config: Config{
6367 MaxVersion: VersionTLS13,
6368 Bugs: ProtocolBugs{
6369 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6370 },
6371 },
6372 shouldFail: true,
6373 expectedError: ":UNEXPECTED_EXTENSION:",
6374 })
6375
Adam Langleycfa08c32016-11-17 13:21:27 -08006376 var differentSCTList []byte
6377 differentSCTList = append(differentSCTList, testSCTList...)
6378 differentSCTList[len(differentSCTList)-1] ^= 1
6379
Steven Valdeza833c352016-11-01 13:39:36 -04006380 // Test that extensions on intermediates are allowed but ignored.
6381 testCases = append(testCases, testCase{
6382 name: "IgnoreExtensionsOnIntermediates-TLS13",
6383 config: Config{
6384 MaxVersion: VersionTLS13,
6385 Certificates: []Certificate{rsaChainCertificate},
6386 Bugs: ProtocolBugs{
6387 // Send different values on the intermediate. This tests
6388 // the intermediate's extensions do not override the
6389 // leaf's.
6390 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006391 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006392 },
6393 },
6394 flags: []string{
6395 "-enable-ocsp-stapling",
6396 "-expect-ocsp-response",
6397 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006398 "-enable-signed-cert-timestamps",
6399 "-expect-signed-cert-timestamps",
6400 base64.StdEncoding.EncodeToString(testSCTList),
6401 },
6402 resumeSession: true,
6403 })
6404
6405 // Test that extensions are not sent on intermediates when configured
6406 // only for a leaf.
6407 testCases = append(testCases, testCase{
6408 testType: serverTest,
6409 name: "SendNoExtensionsOnIntermediate-TLS13",
6410 config: Config{
6411 MaxVersion: VersionTLS13,
6412 Bugs: ProtocolBugs{
6413 ExpectNoExtensionsOnIntermediate: true,
6414 },
6415 },
6416 flags: []string{
6417 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6418 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6419 "-ocsp-response",
6420 base64.StdEncoding.EncodeToString(testOCSPResponse),
6421 "-signed-cert-timestamps",
6422 base64.StdEncoding.EncodeToString(testSCTList),
6423 },
6424 })
6425
6426 // Test that extensions are not sent on client certificates.
6427 testCases = append(testCases, testCase{
6428 name: "SendNoClientCertificateExtensions-TLS13",
6429 config: Config{
6430 MaxVersion: VersionTLS13,
6431 ClientAuth: RequireAnyClientCert,
6432 },
6433 flags: []string{
6434 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6435 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6436 "-ocsp-response",
6437 base64.StdEncoding.EncodeToString(testOCSPResponse),
6438 "-signed-cert-timestamps",
6439 base64.StdEncoding.EncodeToString(testSCTList),
6440 },
6441 })
6442
6443 testCases = append(testCases, testCase{
6444 name: "SendDuplicateExtensionsOnCerts-TLS13",
6445 config: Config{
6446 MaxVersion: VersionTLS13,
6447 Bugs: ProtocolBugs{
6448 SendDuplicateCertExtensions: true,
6449 },
6450 },
6451 flags: []string{
6452 "-enable-ocsp-stapling",
6453 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006454 },
6455 resumeSession: true,
6456 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006457 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006458 })
Adam Langley9b885c52016-11-18 14:21:03 -08006459
6460 testCases = append(testCases, testCase{
6461 name: "SignedCertificateTimestampListInvalid-Server",
6462 testType: serverTest,
6463 flags: []string{
6464 "-signed-cert-timestamps",
6465 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6466 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006467 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006468 expectedError: ":INVALID_SCT_LIST:",
6469 })
David Benjamine78bfde2014-09-06 12:45:15 -04006470}
6471
David Benjamin01fe8202014-09-24 15:21:44 -04006472func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006473 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006474 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006475 // SSL 3.0 does not have tickets and TLS 1.3 does not
6476 // have session IDs, so skip their cross-resumption
6477 // tests.
6478 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6479 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6480 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006481 }
6482
David Benjamin8b8c0062014-11-23 02:47:52 -05006483 protocols := []protocol{tls}
6484 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6485 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006486 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006487 for _, protocol := range protocols {
6488 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6489 if protocol == dtls {
6490 suffix += "-DTLS"
6491 }
6492
Steven Valdez520e1222017-06-13 12:45:25 -04006493 // We can't resume across TLS 1.3 variants and error out earlier in the
6494 // session resumption.
6495 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6496 continue
6497 }
6498
David Benjaminece3de92015-03-16 18:02:20 -04006499 if sessionVers.version == resumeVers.version {
6500 testCases = append(testCases, testCase{
6501 protocol: protocol,
6502 name: "Resume-Client" + suffix,
6503 resumeSession: true,
6504 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006505 MaxVersion: sessionVers.version,
6506 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006507 Bugs: ProtocolBugs{
6508 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6509 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6510 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006511 },
David Benjaminece3de92015-03-16 18:02:20 -04006512 expectedVersion: sessionVers.version,
6513 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006514 flags: []string{
6515 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6516 },
David Benjaminece3de92015-03-16 18:02:20 -04006517 })
6518 } else {
David Benjamin405da482016-08-08 17:25:07 -04006519 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6520
6521 // Offering a TLS 1.3 session sends an empty session ID, so
6522 // there is no way to convince a non-lookahead client the
6523 // session was resumed. It will appear to the client that a
6524 // stray ChangeCipherSpec was sent.
6525 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6526 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006527 }
6528
David Benjaminece3de92015-03-16 18:02:20 -04006529 testCases = append(testCases, testCase{
6530 protocol: protocol,
6531 name: "Resume-Client-Mismatch" + suffix,
6532 resumeSession: true,
6533 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006534 MaxVersion: sessionVers.version,
6535 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006536 },
David Benjaminece3de92015-03-16 18:02:20 -04006537 expectedVersion: sessionVers.version,
6538 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006539 MaxVersion: resumeVers.version,
6540 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006541 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006542 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006543 },
6544 },
6545 expectedResumeVersion: resumeVers.version,
6546 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006547 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006548 flags: []string{
6549 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6550 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6551 },
David Benjaminece3de92015-03-16 18:02:20 -04006552 })
6553 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006554
6555 testCases = append(testCases, testCase{
6556 protocol: protocol,
6557 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006558 resumeSession: true,
6559 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006560 MaxVersion: sessionVers.version,
6561 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006562 },
6563 expectedVersion: sessionVers.version,
6564 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006565 MaxVersion: resumeVers.version,
6566 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006567 },
6568 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006569 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006570 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006571 flags: []string{
6572 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6573 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6574 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006575 })
6576
David Benjamin8b8c0062014-11-23 02:47:52 -05006577 testCases = append(testCases, testCase{
6578 protocol: protocol,
6579 testType: serverTest,
6580 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006581 resumeSession: true,
6582 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006583 MaxVersion: sessionVers.version,
6584 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006585 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006586 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006587 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006588 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006589 MaxVersion: resumeVers.version,
6590 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006591 Bugs: ProtocolBugs{
6592 SendBothTickets: true,
6593 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006594 },
6595 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006596 flags: []string{
6597 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6598 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6599 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006600 })
6601 }
David Benjamin01fe8202014-09-24 15:21:44 -04006602 }
6603 }
David Benjaminece3de92015-03-16 18:02:20 -04006604
David Benjamin4199b0d2016-11-01 13:58:25 -04006605 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006606 testCases = append(testCases, testCase{
6607 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006608 name: "ShimTicketRewritable",
6609 resumeSession: true,
6610 config: Config{
6611 MaxVersion: VersionTLS12,
6612 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6613 Bugs: ProtocolBugs{
6614 FilterTicket: func(in []byte) ([]byte, error) {
6615 in, err := SetShimTicketVersion(in, VersionTLS12)
6616 if err != nil {
6617 return nil, err
6618 }
6619 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6620 },
6621 },
6622 },
6623 flags: []string{
6624 "-ticket-key",
6625 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6626 },
6627 })
6628
6629 // Resumptions are declined if the version does not match.
6630 testCases = append(testCases, testCase{
6631 testType: serverTest,
6632 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006633 resumeSession: true,
6634 config: Config{
6635 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006636 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006637 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006638 FilterTicket: func(in []byte) ([]byte, error) {
6639 return SetShimTicketVersion(in, VersionTLS13)
6640 },
6641 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006642 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006643 flags: []string{
6644 "-ticket-key",
6645 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6646 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006647 expectResumeRejected: true,
6648 })
6649
6650 testCases = append(testCases, testCase{
6651 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006652 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006653 resumeSession: true,
6654 config: Config{
6655 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006656 Bugs: ProtocolBugs{
6657 FilterTicket: func(in []byte) ([]byte, error) {
6658 return SetShimTicketVersion(in, VersionTLS12)
6659 },
6660 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006661 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006662 flags: []string{
6663 "-ticket-key",
6664 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6665 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006666 expectResumeRejected: true,
6667 })
6668
David Benjamin4199b0d2016-11-01 13:58:25 -04006669 // Resumptions are declined if the cipher is invalid or disabled.
6670 testCases = append(testCases, testCase{
6671 testType: serverTest,
6672 name: "Resume-Server-DeclineBadCipher",
6673 resumeSession: true,
6674 config: Config{
6675 MaxVersion: VersionTLS12,
6676 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006677 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006678 FilterTicket: func(in []byte) ([]byte, error) {
6679 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6680 },
6681 },
6682 },
6683 flags: []string{
6684 "-ticket-key",
6685 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6686 },
6687 expectResumeRejected: true,
6688 })
6689
6690 testCases = append(testCases, testCase{
6691 testType: serverTest,
6692 name: "Resume-Server-DeclineBadCipher-2",
6693 resumeSession: true,
6694 config: Config{
6695 MaxVersion: VersionTLS12,
6696 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006697 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006698 FilterTicket: func(in []byte) ([]byte, error) {
6699 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6700 },
6701 },
6702 },
6703 flags: []string{
6704 "-cipher", "AES128",
6705 "-ticket-key",
6706 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6707 },
6708 expectResumeRejected: true,
6709 })
6710
David Benjaminf01f42a2016-11-16 19:05:33 +09006711 // Sessions are not resumed if they do not use the preferred cipher.
6712 testCases = append(testCases, testCase{
6713 testType: serverTest,
6714 name: "Resume-Server-CipherNotPreferred",
6715 resumeSession: true,
6716 config: Config{
6717 MaxVersion: VersionTLS12,
6718 Bugs: ProtocolBugs{
6719 ExpectNewTicket: true,
6720 FilterTicket: func(in []byte) ([]byte, error) {
6721 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6722 },
6723 },
6724 },
6725 flags: []string{
6726 "-ticket-key",
6727 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6728 },
6729 shouldFail: false,
6730 expectResumeRejected: true,
6731 })
6732
6733 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6734 // PRF hashes match, but BoringSSL will always decline such resumptions.
6735 testCases = append(testCases, testCase{
6736 testType: serverTest,
6737 name: "Resume-Server-CipherNotPreferred-TLS13",
6738 resumeSession: true,
6739 config: Config{
6740 MaxVersion: VersionTLS13,
6741 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6742 Bugs: ProtocolBugs{
6743 FilterTicket: func(in []byte) ([]byte, error) {
6744 // If the client (runner) offers ChaCha20-Poly1305 first, the
6745 // server (shim) always prefers it. Switch it to AES-GCM.
6746 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6747 },
6748 },
6749 },
6750 flags: []string{
6751 "-ticket-key",
6752 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6753 },
6754 shouldFail: false,
6755 expectResumeRejected: true,
6756 })
6757
6758 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006759 testCases = append(testCases, testCase{
6760 testType: serverTest,
6761 name: "Resume-Server-DeclineBadCipher-TLS13",
6762 resumeSession: true,
6763 config: Config{
6764 MaxVersion: VersionTLS13,
6765 Bugs: ProtocolBugs{
6766 FilterTicket: func(in []byte) ([]byte, error) {
6767 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6768 },
6769 },
6770 },
6771 flags: []string{
6772 "-ticket-key",
6773 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6774 },
6775 expectResumeRejected: true,
6776 })
6777
David Benjaminf01f42a2016-11-16 19:05:33 +09006778 // If the client does not offer the cipher from the session, decline to
6779 // resume. Clients are forbidden from doing this, but BoringSSL selects
6780 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006781 testCases = append(testCases, testCase{
6782 testType: serverTest,
6783 name: "Resume-Server-UnofferedCipher",
6784 resumeSession: true,
6785 config: Config{
6786 MaxVersion: VersionTLS12,
6787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6788 },
6789 resumeConfig: &Config{
6790 MaxVersion: VersionTLS12,
6791 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6792 Bugs: ProtocolBugs{
6793 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6794 },
6795 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006796 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006797 })
6798
David Benjaminf01f42a2016-11-16 19:05:33 +09006799 // In TLS 1.3, clients may advertise a cipher list which does not
6800 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006801 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6802 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006803 testCases = append(testCases, testCase{
6804 testType: serverTest,
6805 name: "Resume-Server-UnofferedCipher-TLS13",
6806 resumeSession: true,
6807 config: Config{
6808 MaxVersion: VersionTLS13,
6809 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6810 },
6811 resumeConfig: &Config{
6812 MaxVersion: VersionTLS13,
6813 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6814 Bugs: ProtocolBugs{
6815 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6816 },
6817 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006818 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006819 })
6820
David Benjamin4199b0d2016-11-01 13:58:25 -04006821 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006822 testCases = append(testCases, testCase{
6823 name: "Resume-Client-CipherMismatch",
6824 resumeSession: true,
6825 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006826 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006827 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6828 },
6829 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006830 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006831 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6832 Bugs: ProtocolBugs{
6833 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6834 },
6835 },
6836 shouldFail: true,
6837 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6838 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006839
David Benjamine1cc35e2016-11-16 16:25:58 +09006840 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6841 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006842 testCases = append(testCases, testCase{
6843 name: "Resume-Client-CipherMismatch-TLS13",
6844 resumeSession: true,
6845 config: Config{
6846 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006847 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006848 },
6849 resumeConfig: &Config{
6850 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006851 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6852 },
6853 })
6854
6855 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6856 testCases = append(testCases, testCase{
6857 name: "Resume-Client-PRFMismatch-TLS13",
6858 resumeSession: true,
6859 config: Config{
6860 MaxVersion: VersionTLS13,
6861 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6862 },
6863 resumeConfig: &Config{
6864 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006865 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006866 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006867 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006868 },
6869 },
6870 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006871 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006872 })
Steven Valdeza833c352016-11-01 13:39:36 -04006873
6874 testCases = append(testCases, testCase{
6875 testType: serverTest,
6876 name: "Resume-Server-BinderWrongLength",
6877 resumeSession: true,
6878 config: Config{
6879 MaxVersion: VersionTLS13,
6880 Bugs: ProtocolBugs{
6881 SendShortPSKBinder: true,
6882 },
6883 },
6884 shouldFail: true,
6885 expectedLocalError: "remote error: error decrypting message",
6886 expectedError: ":DIGEST_CHECK_FAILED:",
6887 })
6888
6889 testCases = append(testCases, testCase{
6890 testType: serverTest,
6891 name: "Resume-Server-NoPSKBinder",
6892 resumeSession: true,
6893 config: Config{
6894 MaxVersion: VersionTLS13,
6895 Bugs: ProtocolBugs{
6896 SendNoPSKBinder: true,
6897 },
6898 },
6899 shouldFail: true,
6900 expectedLocalError: "remote error: error decoding message",
6901 expectedError: ":DECODE_ERROR:",
6902 })
6903
6904 testCases = append(testCases, testCase{
6905 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006906 name: "Resume-Server-ExtraPSKBinder",
6907 resumeSession: true,
6908 config: Config{
6909 MaxVersion: VersionTLS13,
6910 Bugs: ProtocolBugs{
6911 SendExtraPSKBinder: true,
6912 },
6913 },
6914 shouldFail: true,
6915 expectedLocalError: "remote error: illegal parameter",
6916 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6917 })
6918
6919 testCases = append(testCases, testCase{
6920 testType: serverTest,
6921 name: "Resume-Server-ExtraIdentityNoBinder",
6922 resumeSession: true,
6923 config: Config{
6924 MaxVersion: VersionTLS13,
6925 Bugs: ProtocolBugs{
6926 ExtraPSKIdentity: true,
6927 },
6928 },
6929 shouldFail: true,
6930 expectedLocalError: "remote error: illegal parameter",
6931 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6932 })
6933
6934 testCases = append(testCases, testCase{
6935 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006936 name: "Resume-Server-InvalidPSKBinder",
6937 resumeSession: true,
6938 config: Config{
6939 MaxVersion: VersionTLS13,
6940 Bugs: ProtocolBugs{
6941 SendInvalidPSKBinder: true,
6942 },
6943 },
6944 shouldFail: true,
6945 expectedLocalError: "remote error: error decrypting message",
6946 expectedError: ":DIGEST_CHECK_FAILED:",
6947 })
6948
6949 testCases = append(testCases, testCase{
6950 testType: serverTest,
6951 name: "Resume-Server-PSKBinderFirstExtension",
6952 resumeSession: true,
6953 config: Config{
6954 MaxVersion: VersionTLS13,
6955 Bugs: ProtocolBugs{
6956 PSKBinderFirst: true,
6957 },
6958 },
6959 shouldFail: true,
6960 expectedLocalError: "remote error: illegal parameter",
6961 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6962 })
David Benjamin01fe8202014-09-24 15:21:44 -04006963}
6964
Adam Langley2ae77d22014-10-28 17:29:33 -07006965func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006966 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006967 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006968 testType: serverTest,
6969 name: "Renegotiate-Server-Forbidden",
6970 config: Config{
6971 MaxVersion: VersionTLS12,
6972 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006973 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006974 shouldFail: true,
6975 expectedError: ":NO_RENEGOTIATION:",
6976 expectedLocalError: "remote error: no renegotiation",
6977 })
Adam Langley5021b222015-06-12 18:27:58 -07006978 // The server shouldn't echo the renegotiation extension unless
6979 // requested by the client.
6980 testCases = append(testCases, testCase{
6981 testType: serverTest,
6982 name: "Renegotiate-Server-NoExt",
6983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006984 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006985 Bugs: ProtocolBugs{
6986 NoRenegotiationInfo: true,
6987 RequireRenegotiationInfo: true,
6988 },
6989 },
6990 shouldFail: true,
6991 expectedLocalError: "renegotiation extension missing",
6992 })
6993 // The renegotiation SCSV should be sufficient for the server to echo
6994 // the extension.
6995 testCases = append(testCases, testCase{
6996 testType: serverTest,
6997 name: "Renegotiate-Server-NoExt-SCSV",
6998 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006999 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007000 Bugs: ProtocolBugs{
7001 NoRenegotiationInfo: true,
7002 SendRenegotiationSCSV: true,
7003 RequireRenegotiationInfo: true,
7004 },
7005 },
7006 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007007 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007008 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007010 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007011 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007012 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007013 },
7014 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007015 renegotiate: 1,
7016 flags: []string{
7017 "-renegotiate-freely",
7018 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007019 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007020 },
David Benjamincdea40c2015-03-19 14:09:43 -04007021 })
7022 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007023 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007024 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007026 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007027 Bugs: ProtocolBugs{
7028 EmptyRenegotiationInfo: true,
7029 },
7030 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007031 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007032 shouldFail: true,
7033 expectedError: ":RENEGOTIATION_MISMATCH:",
7034 })
7035 testCases = append(testCases, testCase{
7036 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007037 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007039 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007040 Bugs: ProtocolBugs{
7041 BadRenegotiationInfo: true,
7042 },
7043 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007044 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007045 shouldFail: true,
7046 expectedError: ":RENEGOTIATION_MISMATCH:",
7047 })
7048 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007049 name: "Renegotiate-Client-BadExt2",
7050 renegotiate: 1,
7051 config: Config{
7052 MaxVersion: VersionTLS12,
7053 Bugs: ProtocolBugs{
7054 BadRenegotiationInfoEnd: true,
7055 },
7056 },
7057 flags: []string{"-renegotiate-freely"},
7058 shouldFail: true,
7059 expectedError: ":RENEGOTIATION_MISMATCH:",
7060 })
7061 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007062 name: "Renegotiate-Client-Downgrade",
7063 renegotiate: 1,
7064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007065 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007066 Bugs: ProtocolBugs{
7067 NoRenegotiationInfoAfterInitial: true,
7068 },
7069 },
7070 flags: []string{"-renegotiate-freely"},
7071 shouldFail: true,
7072 expectedError: ":RENEGOTIATION_MISMATCH:",
7073 })
7074 testCases = append(testCases, testCase{
7075 name: "Renegotiate-Client-Upgrade",
7076 renegotiate: 1,
7077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007078 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007079 Bugs: ProtocolBugs{
7080 NoRenegotiationInfoInInitial: true,
7081 },
7082 },
7083 flags: []string{"-renegotiate-freely"},
7084 shouldFail: true,
7085 expectedError: ":RENEGOTIATION_MISMATCH:",
7086 })
7087 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007088 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007089 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007091 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007092 Bugs: ProtocolBugs{
7093 NoRenegotiationInfo: true,
7094 },
7095 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007096 flags: []string{
7097 "-renegotiate-freely",
7098 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007099 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007100 },
David Benjamincff0b902015-05-15 23:09:47 -04007101 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007102
7103 // Test that the server may switch ciphers on renegotiation without
7104 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007105 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007106 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007107 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007108 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007109 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007110 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007111 },
7112 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007113 flags: []string{
7114 "-renegotiate-freely",
7115 "-expect-total-renegotiations", "1",
7116 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007117 })
7118 testCases = append(testCases, testCase{
7119 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007120 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007121 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007122 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007123 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7124 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007125 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007126 flags: []string{
7127 "-renegotiate-freely",
7128 "-expect-total-renegotiations", "1",
7129 },
David Benjaminb16346b2015-04-08 19:16:58 -04007130 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007131
7132 // Test that the server may not switch versions on renegotiation.
7133 testCases = append(testCases, testCase{
7134 name: "Renegotiate-Client-SwitchVersion",
7135 config: Config{
7136 MaxVersion: VersionTLS12,
7137 // Pick a cipher which exists at both versions.
7138 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7139 Bugs: ProtocolBugs{
7140 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007141 // Avoid failing early at the record layer.
7142 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007143 },
7144 },
7145 renegotiate: 1,
7146 flags: []string{
7147 "-renegotiate-freely",
7148 "-expect-total-renegotiations", "1",
7149 },
7150 shouldFail: true,
7151 expectedError: ":WRONG_SSL_VERSION:",
7152 })
7153
David Benjaminb16346b2015-04-08 19:16:58 -04007154 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007155 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007156 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007157 config: Config{
7158 MaxVersion: VersionTLS10,
7159 Bugs: ProtocolBugs{
7160 RequireSameRenegoClientVersion: true,
7161 },
7162 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007163 flags: []string{
7164 "-renegotiate-freely",
7165 "-expect-total-renegotiations", "1",
7166 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007167 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007168 testCases = append(testCases, testCase{
7169 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007170 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007171 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007172 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7174 NextProtos: []string{"foo"},
7175 },
7176 flags: []string{
7177 "-false-start",
7178 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007179 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007180 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007181 },
7182 shimWritesFirst: true,
7183 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007184
7185 // Client-side renegotiation controls.
7186 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007187 name: "Renegotiate-Client-Forbidden-1",
7188 config: Config{
7189 MaxVersion: VersionTLS12,
7190 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007191 renegotiate: 1,
7192 shouldFail: true,
7193 expectedError: ":NO_RENEGOTIATION:",
7194 expectedLocalError: "remote error: no renegotiation",
7195 })
7196 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007197 name: "Renegotiate-Client-Once-1",
7198 config: Config{
7199 MaxVersion: VersionTLS12,
7200 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007201 renegotiate: 1,
7202 flags: []string{
7203 "-renegotiate-once",
7204 "-expect-total-renegotiations", "1",
7205 },
7206 })
7207 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007208 name: "Renegotiate-Client-Freely-1",
7209 config: Config{
7210 MaxVersion: VersionTLS12,
7211 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007212 renegotiate: 1,
7213 flags: []string{
7214 "-renegotiate-freely",
7215 "-expect-total-renegotiations", "1",
7216 },
7217 })
7218 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007219 name: "Renegotiate-Client-Once-2",
7220 config: Config{
7221 MaxVersion: VersionTLS12,
7222 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007223 renegotiate: 2,
7224 flags: []string{"-renegotiate-once"},
7225 shouldFail: true,
7226 expectedError: ":NO_RENEGOTIATION:",
7227 expectedLocalError: "remote error: no renegotiation",
7228 })
7229 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007230 name: "Renegotiate-Client-Freely-2",
7231 config: Config{
7232 MaxVersion: VersionTLS12,
7233 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007234 renegotiate: 2,
7235 flags: []string{
7236 "-renegotiate-freely",
7237 "-expect-total-renegotiations", "2",
7238 },
7239 })
Adam Langley27a0d082015-11-03 13:34:10 -08007240 testCases = append(testCases, testCase{
7241 name: "Renegotiate-Client-NoIgnore",
7242 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007243 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007244 Bugs: ProtocolBugs{
7245 SendHelloRequestBeforeEveryAppDataRecord: true,
7246 },
7247 },
7248 shouldFail: true,
7249 expectedError: ":NO_RENEGOTIATION:",
7250 })
7251 testCases = append(testCases, testCase{
7252 name: "Renegotiate-Client-Ignore",
7253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007254 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007255 Bugs: ProtocolBugs{
7256 SendHelloRequestBeforeEveryAppDataRecord: true,
7257 },
7258 },
7259 flags: []string{
7260 "-renegotiate-ignore",
7261 "-expect-total-renegotiations", "0",
7262 },
7263 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007264
David Benjamin34941c02016-10-08 11:45:31 -04007265 // Renegotiation is not allowed at SSL 3.0.
7266 testCases = append(testCases, testCase{
7267 name: "Renegotiate-Client-SSL3",
7268 config: Config{
7269 MaxVersion: VersionSSL30,
7270 },
7271 renegotiate: 1,
7272 flags: []string{
7273 "-renegotiate-freely",
7274 "-expect-total-renegotiations", "1",
7275 },
7276 shouldFail: true,
7277 expectedError: ":NO_RENEGOTIATION:",
7278 expectedLocalError: "remote error: no renegotiation",
7279 })
7280
David Benjamina1eaba12017-01-01 23:19:22 -05007281 // Renegotiation is not allowed when there is an unfinished write.
7282 testCases = append(testCases, testCase{
7283 name: "Renegotiate-Client-UnfinishedWrite",
7284 config: Config{
7285 MaxVersion: VersionTLS12,
7286 },
David Benjaminbbba9392017-04-06 12:54:12 -04007287 renegotiate: 1,
7288 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007289 flags: []string{
7290 "-async",
7291 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007292 },
7293 shouldFail: true,
7294 expectedError: ":NO_RENEGOTIATION:",
7295 // We do not successfully send the no_renegotiation alert in
7296 // this case. https://crbug.com/boringssl/130
7297 })
7298
David Benjamin07ab5d42017-02-09 20:11:41 -05007299 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007300 testCases = append(testCases, testCase{
7301 name: "StrayHelloRequest",
7302 config: Config{
7303 MaxVersion: VersionTLS12,
7304 Bugs: ProtocolBugs{
7305 SendHelloRequestBeforeEveryHandshakeMessage: true,
7306 },
7307 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007308 shouldFail: true,
7309 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007310 })
7311 testCases = append(testCases, testCase{
7312 name: "StrayHelloRequest-Packed",
7313 config: Config{
7314 MaxVersion: VersionTLS12,
7315 Bugs: ProtocolBugs{
7316 PackHandshakeFlight: true,
7317 SendHelloRequestBeforeEveryHandshakeMessage: true,
7318 },
7319 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007320 shouldFail: true,
7321 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007322 })
7323
David Benjamin12d2c482016-07-24 10:56:51 -04007324 // Test renegotiation works if HelloRequest and server Finished come in
7325 // the same record.
7326 testCases = append(testCases, testCase{
7327 name: "Renegotiate-Client-Packed",
7328 config: Config{
7329 MaxVersion: VersionTLS12,
7330 Bugs: ProtocolBugs{
7331 PackHandshakeFlight: true,
7332 PackHelloRequestWithFinished: true,
7333 },
7334 },
7335 renegotiate: 1,
7336 flags: []string{
7337 "-renegotiate-freely",
7338 "-expect-total-renegotiations", "1",
7339 },
7340 })
7341
David Benjamin397c8e62016-07-08 14:14:36 -07007342 // Renegotiation is forbidden in TLS 1.3.
7343 testCases = append(testCases, testCase{
7344 name: "Renegotiate-Client-TLS13",
7345 config: Config{
7346 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007347 Bugs: ProtocolBugs{
7348 SendHelloRequestBeforeEveryAppDataRecord: true,
7349 },
David Benjamin397c8e62016-07-08 14:14:36 -07007350 },
David Benjamin397c8e62016-07-08 14:14:36 -07007351 flags: []string{
7352 "-renegotiate-freely",
7353 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007354 shouldFail: true,
7355 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007356 })
7357
7358 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7359 testCases = append(testCases, testCase{
7360 name: "StrayHelloRequest-TLS13",
7361 config: Config{
7362 MaxVersion: VersionTLS13,
7363 Bugs: ProtocolBugs{
7364 SendHelloRequestBeforeEveryHandshakeMessage: true,
7365 },
7366 },
7367 shouldFail: true,
7368 expectedError: ":UNEXPECTED_MESSAGE:",
7369 })
David Benjamind2610042017-01-03 10:49:28 -05007370
7371 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7372 // always reads as supporting it, regardless of whether it was
7373 // negotiated.
7374 testCases = append(testCases, testCase{
7375 name: "AlwaysReportRenegotiationInfo-TLS13",
7376 config: Config{
7377 MaxVersion: VersionTLS13,
7378 Bugs: ProtocolBugs{
7379 NoRenegotiationInfo: true,
7380 },
7381 },
7382 flags: []string{
7383 "-expect-secure-renegotiation",
7384 },
7385 })
David Benjamina58baaf2017-02-28 20:54:28 -05007386
7387 // Certificates may not change on renegotiation.
7388 testCases = append(testCases, testCase{
7389 name: "Renegotiation-CertificateChange",
7390 config: Config{
7391 MaxVersion: VersionTLS12,
7392 Certificates: []Certificate{rsaCertificate},
7393 Bugs: ProtocolBugs{
7394 RenegotiationCertificate: &rsaChainCertificate,
7395 },
7396 },
7397 renegotiate: 1,
7398 flags: []string{"-renegotiate-freely"},
7399 shouldFail: true,
7400 expectedError: ":SERVER_CERT_CHANGED:",
7401 })
7402 testCases = append(testCases, testCase{
7403 name: "Renegotiation-CertificateChange-2",
7404 config: Config{
7405 MaxVersion: VersionTLS12,
7406 Certificates: []Certificate{rsaCertificate},
7407 Bugs: ProtocolBugs{
7408 RenegotiationCertificate: &rsa1024Certificate,
7409 },
7410 },
7411 renegotiate: 1,
7412 flags: []string{"-renegotiate-freely"},
7413 shouldFail: true,
7414 expectedError: ":SERVER_CERT_CHANGED:",
7415 })
David Benjaminbbf42462017-03-14 21:27:10 -04007416
7417 // We do not negotiate ALPN after the initial handshake. This is
7418 // error-prone and only risks bugs in consumers.
7419 testCases = append(testCases, testCase{
7420 testType: clientTest,
7421 name: "Renegotiation-ForbidALPN",
7422 config: Config{
7423 MaxVersion: VersionTLS12,
7424 Bugs: ProtocolBugs{
7425 // Forcibly negotiate ALPN on both initial and
7426 // renegotiation handshakes. The test stack will
7427 // internally check the client does not offer
7428 // it.
7429 SendALPN: "foo",
7430 },
7431 },
7432 flags: []string{
7433 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7434 "-expect-alpn", "foo",
7435 "-renegotiate-freely",
7436 },
7437 renegotiate: 1,
7438 shouldFail: true,
7439 expectedError: ":UNEXPECTED_EXTENSION:",
7440 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007441}
7442
David Benjamin5e961c12014-11-07 01:48:35 -05007443func addDTLSReplayTests() {
7444 // Test that sequence number replays are detected.
7445 testCases = append(testCases, testCase{
7446 protocol: dtls,
7447 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007448 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007449 replayWrites: true,
7450 })
7451
David Benjamin8e6db492015-07-25 18:29:23 -04007452 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007453 // than the retransmit window.
7454 testCases = append(testCases, testCase{
7455 protocol: dtls,
7456 name: "DTLS-Replay-LargeGaps",
7457 config: Config{
7458 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007459 SequenceNumberMapping: func(in uint64) uint64 {
7460 return in * 127
7461 },
David Benjamin5e961c12014-11-07 01:48:35 -05007462 },
7463 },
David Benjamin8e6db492015-07-25 18:29:23 -04007464 messageCount: 200,
7465 replayWrites: true,
7466 })
7467
7468 // Test the incoming sequence number changing non-monotonically.
7469 testCases = append(testCases, testCase{
7470 protocol: dtls,
7471 name: "DTLS-Replay-NonMonotonic",
7472 config: Config{
7473 Bugs: ProtocolBugs{
7474 SequenceNumberMapping: func(in uint64) uint64 {
7475 return in ^ 31
7476 },
7477 },
7478 },
7479 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007480 replayWrites: true,
7481 })
7482}
7483
Nick Harper60edffd2016-06-21 15:19:24 -07007484var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007485 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007486 id signatureAlgorithm
7487 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007488}{
Nick Harper60edffd2016-06-21 15:19:24 -07007489 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7490 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7491 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7492 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007493 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007494 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7495 // hash function doesn't have to match the curve and so the same
7496 // signature algorithm works with P-224.
7497 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007498 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7499 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7500 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007501 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7502 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7503 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007504 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007505 // Tests for key types prior to TLS 1.2.
7506 {"RSA", 0, testCertRSA},
7507 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007508}
7509
Nick Harper60edffd2016-06-21 15:19:24 -07007510const fakeSigAlg1 signatureAlgorithm = 0x2a01
7511const fakeSigAlg2 signatureAlgorithm = 0xff01
7512
7513func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007514 // Not all ciphers involve a signature. Advertise a list which gives all
7515 // versions a signing cipher.
7516 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007517 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007518 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7519 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7520 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7521 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007522 }
David Benjamin5208fd42016-07-13 21:43:25 -04007523
David Benjaminca3d5452016-07-14 12:51:01 -04007524 var allAlgorithms []signatureAlgorithm
7525 for _, alg := range testSignatureAlgorithms {
7526 if alg.id != 0 {
7527 allAlgorithms = append(allAlgorithms, alg.id)
7528 }
7529 }
7530
Nick Harper60edffd2016-06-21 15:19:24 -07007531 // Make sure each signature algorithm works. Include some fake values in
7532 // the list and ensure they're ignored.
7533 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007534 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007535 if (ver.version < VersionTLS12) != (alg.id == 0) {
7536 continue
7537 }
7538
7539 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7540 // or remove it in C.
7541 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007542 continue
7543 }
Nick Harper60edffd2016-06-21 15:19:24 -07007544
David Benjamin3ef76972016-10-17 17:59:54 -04007545 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007546 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007547 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007548 shouldSignFail = true
7549 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007550 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007551 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007552 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7553 shouldSignFail = true
7554 shouldVerifyFail = true
7555 }
7556 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7557 // the curve has to match the hash size.
7558 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007559 shouldSignFail = true
7560 shouldVerifyFail = true
7561 }
7562
7563 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7564 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7565 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007566 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007567
7568 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007569 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007570 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007571 }
7572 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007573 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007574 }
David Benjamin000800a2014-11-14 01:43:59 -05007575
David Benjamin1fb125c2016-07-08 18:52:12 -07007576 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007577
David Benjamin7a41d372016-07-09 11:21:54 -07007578 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007579 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007580 config: Config{
7581 MaxVersion: ver.version,
7582 ClientAuth: RequireAnyClientCert,
7583 VerifySignatureAlgorithms: []signatureAlgorithm{
7584 fakeSigAlg1,
7585 alg.id,
7586 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007587 },
David Benjamin7a41d372016-07-09 11:21:54 -07007588 },
7589 flags: []string{
7590 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7591 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7592 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007593 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007594 },
David Benjamina5022392017-07-10 17:40:39 -04007595 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007596 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007597 expectedError: signError,
7598 expectedPeerSignatureAlgorithm: alg.id,
7599 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007600
David Benjamin7a41d372016-07-09 11:21:54 -07007601 testCases = append(testCases, testCase{
7602 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007603 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007604 config: Config{
7605 MaxVersion: ver.version,
7606 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7607 SignSignatureAlgorithms: []signatureAlgorithm{
7608 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007609 },
David Benjamin7a41d372016-07-09 11:21:54 -07007610 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007611 SkipECDSACurveCheck: shouldVerifyFail,
7612 IgnoreSignatureVersionChecks: shouldVerifyFail,
7613 // Some signature algorithms may not be advertised.
7614 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007615 },
David Benjamin7a41d372016-07-09 11:21:54 -07007616 },
David Benjamina5022392017-07-10 17:40:39 -04007617 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007618 flags: []string{
7619 "-require-any-client-certificate",
7620 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7621 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007622 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007623 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007624 // Resume the session to assert the peer signature
7625 // algorithm is reported on both handshakes.
7626 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007627 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007628 expectedError: verifyError,
7629 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007630
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007631 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007632 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007633 testCases = append(testCases, testCase{
7634 testType: serverTest,
7635 name: "ServerAuth-Sign" + suffix,
7636 config: Config{
7637 MaxVersion: ver.version,
7638 CipherSuites: signingCiphers,
7639 VerifySignatureAlgorithms: []signatureAlgorithm{
7640 fakeSigAlg1,
7641 alg.id,
7642 fakeSigAlg2,
7643 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007644 },
David Benjamina5022392017-07-10 17:40:39 -04007645 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007646 flags: []string{
7647 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7648 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7649 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007650 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007651 },
7652 shouldFail: shouldSignFail,
7653 expectedError: signError,
7654 expectedPeerSignatureAlgorithm: alg.id,
7655 })
7656 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007657
7658 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007659 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007660 config: Config{
7661 MaxVersion: ver.version,
7662 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007663 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007664 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007665 alg.id,
7666 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007667 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007668 SkipECDSACurveCheck: shouldVerifyFail,
7669 IgnoreSignatureVersionChecks: shouldVerifyFail,
7670 // Some signature algorithms may not be advertised.
7671 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007672 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007673 },
David Benjamina5022392017-07-10 17:40:39 -04007674 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007675 flags: []string{
7676 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7677 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007678 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007679 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007680 // Resume the session to assert the peer signature
7681 // algorithm is reported on both handshakes.
7682 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007683 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007684 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007685 })
David Benjamin5208fd42016-07-13 21:43:25 -04007686
David Benjamin3ef76972016-10-17 17:59:54 -04007687 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007688 testCases = append(testCases, testCase{
7689 testType: serverTest,
7690 name: "ClientAuth-InvalidSignature" + suffix,
7691 config: Config{
7692 MaxVersion: ver.version,
7693 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7694 SignSignatureAlgorithms: []signatureAlgorithm{
7695 alg.id,
7696 },
7697 Bugs: ProtocolBugs{
7698 InvalidSignature: true,
7699 },
7700 },
David Benjamina5022392017-07-10 17:40:39 -04007701 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007702 flags: []string{
7703 "-require-any-client-certificate",
7704 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007705 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007706 },
7707 shouldFail: true,
7708 expectedError: ":BAD_SIGNATURE:",
7709 })
7710
7711 testCases = append(testCases, testCase{
7712 name: "ServerAuth-InvalidSignature" + suffix,
7713 config: Config{
7714 MaxVersion: ver.version,
7715 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7716 CipherSuites: signingCiphers,
7717 SignSignatureAlgorithms: []signatureAlgorithm{
7718 alg.id,
7719 },
7720 Bugs: ProtocolBugs{
7721 InvalidSignature: true,
7722 },
7723 },
David Benjamina5022392017-07-10 17:40:39 -04007724 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007725 flags: []string{
7726 "-enable-all-curves",
7727 "-enable-ed25519",
7728 },
David Benjamin5208fd42016-07-13 21:43:25 -04007729 shouldFail: true,
7730 expectedError: ":BAD_SIGNATURE:",
7731 })
7732 }
David Benjaminca3d5452016-07-14 12:51:01 -04007733
David Benjamin3ef76972016-10-17 17:59:54 -04007734 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007735 testCases = append(testCases, testCase{
7736 name: "ClientAuth-Sign-Negotiate" + suffix,
7737 config: Config{
7738 MaxVersion: ver.version,
7739 ClientAuth: RequireAnyClientCert,
7740 VerifySignatureAlgorithms: allAlgorithms,
7741 },
David Benjamina5022392017-07-10 17:40:39 -04007742 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007743 flags: []string{
7744 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7745 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7746 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007747 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007748 "-signing-prefs", strconv.Itoa(int(alg.id)),
7749 },
7750 expectedPeerSignatureAlgorithm: alg.id,
7751 })
7752
7753 testCases = append(testCases, testCase{
7754 testType: serverTest,
7755 name: "ServerAuth-Sign-Negotiate" + suffix,
7756 config: Config{
7757 MaxVersion: ver.version,
7758 CipherSuites: signingCiphers,
7759 VerifySignatureAlgorithms: allAlgorithms,
7760 },
David Benjamina5022392017-07-10 17:40:39 -04007761 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007762 flags: []string{
7763 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7764 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7765 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007766 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007767 "-signing-prefs", strconv.Itoa(int(alg.id)),
7768 },
7769 expectedPeerSignatureAlgorithm: alg.id,
7770 })
7771 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007772 }
David Benjamin000800a2014-11-14 01:43:59 -05007773 }
7774
Nick Harper60edffd2016-06-21 15:19:24 -07007775 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007776 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007777 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007778 config: Config{
7779 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007780 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007781 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007782 signatureECDSAWithP521AndSHA512,
7783 signatureRSAPKCS1WithSHA384,
7784 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007785 },
7786 },
7787 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007788 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7789 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007790 },
Nick Harper60edffd2016-06-21 15:19:24 -07007791 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007792 })
7793
7794 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007795 name: "ClientAuth-SignatureType-TLS13",
7796 config: Config{
7797 ClientAuth: RequireAnyClientCert,
7798 MaxVersion: VersionTLS13,
7799 VerifySignatureAlgorithms: []signatureAlgorithm{
7800 signatureECDSAWithP521AndSHA512,
7801 signatureRSAPKCS1WithSHA384,
7802 signatureRSAPSSWithSHA384,
7803 signatureECDSAWithSHA1,
7804 },
7805 },
7806 flags: []string{
7807 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7808 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7809 },
7810 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7811 })
7812
7813 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007814 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007815 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007816 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007817 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007819 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007820 signatureECDSAWithP521AndSHA512,
7821 signatureRSAPKCS1WithSHA384,
7822 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007823 },
7824 },
Nick Harper60edffd2016-06-21 15:19:24 -07007825 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007826 })
7827
Steven Valdez143e8b32016-07-11 13:19:03 -04007828 testCases = append(testCases, testCase{
7829 testType: serverTest,
7830 name: "ServerAuth-SignatureType-TLS13",
7831 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007832 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007833 VerifySignatureAlgorithms: []signatureAlgorithm{
7834 signatureECDSAWithP521AndSHA512,
7835 signatureRSAPKCS1WithSHA384,
7836 signatureRSAPSSWithSHA384,
7837 signatureECDSAWithSHA1,
7838 },
7839 },
7840 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7841 })
7842
David Benjamina95e9f32016-07-08 16:28:04 -07007843 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007844 testCases = append(testCases, testCase{
7845 testType: serverTest,
7846 name: "Verify-ClientAuth-SignatureType",
7847 config: Config{
7848 MaxVersion: VersionTLS12,
7849 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007850 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007851 signatureRSAPKCS1WithSHA256,
7852 },
7853 Bugs: ProtocolBugs{
7854 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7855 },
7856 },
7857 flags: []string{
7858 "-require-any-client-certificate",
7859 },
7860 shouldFail: true,
7861 expectedError: ":WRONG_SIGNATURE_TYPE:",
7862 })
7863
7864 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007865 testType: serverTest,
7866 name: "Verify-ClientAuth-SignatureType-TLS13",
7867 config: Config{
7868 MaxVersion: VersionTLS13,
7869 Certificates: []Certificate{rsaCertificate},
7870 SignSignatureAlgorithms: []signatureAlgorithm{
7871 signatureRSAPSSWithSHA256,
7872 },
7873 Bugs: ProtocolBugs{
7874 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7875 },
7876 },
7877 flags: []string{
7878 "-require-any-client-certificate",
7879 },
7880 shouldFail: true,
7881 expectedError: ":WRONG_SIGNATURE_TYPE:",
7882 })
7883
7884 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007885 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007886 config: Config{
7887 MaxVersion: VersionTLS12,
7888 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007889 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007890 signatureRSAPKCS1WithSHA256,
7891 },
7892 Bugs: ProtocolBugs{
7893 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7894 },
7895 },
7896 shouldFail: true,
7897 expectedError: ":WRONG_SIGNATURE_TYPE:",
7898 })
7899
Steven Valdez143e8b32016-07-11 13:19:03 -04007900 testCases = append(testCases, testCase{
7901 name: "Verify-ServerAuth-SignatureType-TLS13",
7902 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007903 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007904 SignSignatureAlgorithms: []signatureAlgorithm{
7905 signatureRSAPSSWithSHA256,
7906 },
7907 Bugs: ProtocolBugs{
7908 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7909 },
7910 },
7911 shouldFail: true,
7912 expectedError: ":WRONG_SIGNATURE_TYPE:",
7913 })
7914
David Benjamin51dd7d62016-07-08 16:07:01 -07007915 // Test that, if the list is missing, the peer falls back to SHA-1 in
7916 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007917 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007918 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007920 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007921 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007922 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007923 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007924 },
7925 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007926 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007927 },
7928 },
7929 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007930 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7931 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007932 },
7933 })
7934
7935 testCases = append(testCases, testCase{
7936 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007937 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007938 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007939 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007940 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007941 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007942 },
7943 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007944 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007945 },
7946 },
David Benjaminee32bea2016-08-17 13:36:44 -04007947 flags: []string{
7948 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7949 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7950 },
7951 })
7952
7953 testCases = append(testCases, testCase{
7954 name: "ClientAuth-SHA1-Fallback-ECDSA",
7955 config: Config{
7956 MaxVersion: VersionTLS12,
7957 ClientAuth: RequireAnyClientCert,
7958 VerifySignatureAlgorithms: []signatureAlgorithm{
7959 signatureECDSAWithSHA1,
7960 },
7961 Bugs: ProtocolBugs{
7962 NoSignatureAlgorithms: true,
7963 },
7964 },
7965 flags: []string{
7966 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7967 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7968 },
7969 })
7970
7971 testCases = append(testCases, testCase{
7972 testType: serverTest,
7973 name: "ServerAuth-SHA1-Fallback-ECDSA",
7974 config: Config{
7975 MaxVersion: VersionTLS12,
7976 VerifySignatureAlgorithms: []signatureAlgorithm{
7977 signatureECDSAWithSHA1,
7978 },
7979 Bugs: ProtocolBugs{
7980 NoSignatureAlgorithms: true,
7981 },
7982 },
7983 flags: []string{
7984 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7985 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7986 },
David Benjamin000800a2014-11-14 01:43:59 -05007987 })
David Benjamin72dc7832015-03-16 17:49:43 -04007988
David Benjamin51dd7d62016-07-08 16:07:01 -07007989 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007990 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007991 config: Config{
7992 MaxVersion: VersionTLS13,
7993 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007994 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007995 signatureRSAPKCS1WithSHA1,
7996 },
7997 Bugs: ProtocolBugs{
7998 NoSignatureAlgorithms: true,
7999 },
8000 },
8001 flags: []string{
8002 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8003 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8004 },
David Benjamin48901652016-08-01 12:12:47 -04008005 shouldFail: true,
8006 // An empty CertificateRequest signature algorithm list is a
8007 // syntax error in TLS 1.3.
8008 expectedError: ":DECODE_ERROR:",
8009 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008010 })
8011
8012 testCases = append(testCases, testCase{
8013 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008014 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008015 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008016 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008017 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008018 signatureRSAPKCS1WithSHA1,
8019 },
8020 Bugs: ProtocolBugs{
8021 NoSignatureAlgorithms: true,
8022 },
8023 },
8024 shouldFail: true,
8025 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8026 })
8027
David Benjaminb62d2872016-07-18 14:55:02 +02008028 // Test that hash preferences are enforced. BoringSSL does not implement
8029 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008030 testCases = append(testCases, testCase{
8031 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008032 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008034 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008035 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008036 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008037 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008038 },
8039 Bugs: ProtocolBugs{
8040 IgnorePeerSignatureAlgorithmPreferences: true,
8041 },
8042 },
8043 flags: []string{"-require-any-client-certificate"},
8044 shouldFail: true,
8045 expectedError: ":WRONG_SIGNATURE_TYPE:",
8046 })
8047
8048 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008049 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008050 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008051 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008052 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008053 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008054 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008055 },
8056 Bugs: ProtocolBugs{
8057 IgnorePeerSignatureAlgorithmPreferences: true,
8058 },
8059 },
8060 shouldFail: true,
8061 expectedError: ":WRONG_SIGNATURE_TYPE:",
8062 })
David Benjaminb62d2872016-07-18 14:55:02 +02008063 testCases = append(testCases, testCase{
8064 testType: serverTest,
8065 name: "ClientAuth-Enforced-TLS13",
8066 config: Config{
8067 MaxVersion: VersionTLS13,
8068 Certificates: []Certificate{rsaCertificate},
8069 SignSignatureAlgorithms: []signatureAlgorithm{
8070 signatureRSAPKCS1WithMD5,
8071 },
8072 Bugs: ProtocolBugs{
8073 IgnorePeerSignatureAlgorithmPreferences: true,
8074 IgnoreSignatureVersionChecks: true,
8075 },
8076 },
8077 flags: []string{"-require-any-client-certificate"},
8078 shouldFail: true,
8079 expectedError: ":WRONG_SIGNATURE_TYPE:",
8080 })
8081
8082 testCases = append(testCases, testCase{
8083 name: "ServerAuth-Enforced-TLS13",
8084 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008085 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008086 SignSignatureAlgorithms: []signatureAlgorithm{
8087 signatureRSAPKCS1WithMD5,
8088 },
8089 Bugs: ProtocolBugs{
8090 IgnorePeerSignatureAlgorithmPreferences: true,
8091 IgnoreSignatureVersionChecks: true,
8092 },
8093 },
8094 shouldFail: true,
8095 expectedError: ":WRONG_SIGNATURE_TYPE:",
8096 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008097
8098 // Test that the agreed upon digest respects the client preferences and
8099 // the server digests.
8100 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008101 name: "NoCommonAlgorithms-Digests",
8102 config: Config{
8103 MaxVersion: VersionTLS12,
8104 ClientAuth: RequireAnyClientCert,
8105 VerifySignatureAlgorithms: []signatureAlgorithm{
8106 signatureRSAPKCS1WithSHA512,
8107 signatureRSAPKCS1WithSHA1,
8108 },
8109 },
8110 flags: []string{
8111 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8112 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8113 "-digest-prefs", "SHA256",
8114 },
8115 shouldFail: true,
8116 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8117 })
8118 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008119 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008121 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008122 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008123 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008124 signatureRSAPKCS1WithSHA512,
8125 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008126 },
8127 },
8128 flags: []string{
8129 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8130 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008131 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008132 },
David Benjaminca3d5452016-07-14 12:51:01 -04008133 shouldFail: true,
8134 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8135 })
8136 testCases = append(testCases, testCase{
8137 name: "NoCommonAlgorithms-TLS13",
8138 config: Config{
8139 MaxVersion: VersionTLS13,
8140 ClientAuth: RequireAnyClientCert,
8141 VerifySignatureAlgorithms: []signatureAlgorithm{
8142 signatureRSAPSSWithSHA512,
8143 signatureRSAPSSWithSHA384,
8144 },
8145 },
8146 flags: []string{
8147 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8148 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8149 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8150 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008151 shouldFail: true,
8152 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008153 })
8154 testCases = append(testCases, testCase{
8155 name: "Agree-Digest-SHA256",
8156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008157 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008158 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008159 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008160 signatureRSAPKCS1WithSHA1,
8161 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008162 },
8163 },
8164 flags: []string{
8165 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8166 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008167 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008168 },
Nick Harper60edffd2016-06-21 15:19:24 -07008169 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008170 })
8171 testCases = append(testCases, testCase{
8172 name: "Agree-Digest-SHA1",
8173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008174 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008175 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008176 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008177 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008178 },
8179 },
8180 flags: []string{
8181 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8182 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008183 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008184 },
Nick Harper60edffd2016-06-21 15:19:24 -07008185 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008186 })
8187 testCases = append(testCases, testCase{
8188 name: "Agree-Digest-Default",
8189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008190 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008191 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008192 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008193 signatureRSAPKCS1WithSHA256,
8194 signatureECDSAWithP256AndSHA256,
8195 signatureRSAPKCS1WithSHA1,
8196 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008197 },
8198 },
8199 flags: []string{
8200 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8201 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8202 },
Nick Harper60edffd2016-06-21 15:19:24 -07008203 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008204 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008205
David Benjaminca3d5452016-07-14 12:51:01 -04008206 // Test that the signing preference list may include extra algorithms
8207 // without negotiation problems.
8208 testCases = append(testCases, testCase{
8209 testType: serverTest,
8210 name: "FilterExtraAlgorithms",
8211 config: Config{
8212 MaxVersion: VersionTLS12,
8213 VerifySignatureAlgorithms: []signatureAlgorithm{
8214 signatureRSAPKCS1WithSHA256,
8215 },
8216 },
8217 flags: []string{
8218 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8219 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8220 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8221 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8222 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8223 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8224 },
8225 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8226 })
8227
David Benjamin4c3ddf72016-06-29 18:13:53 -04008228 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8229 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008230 testCases = append(testCases, testCase{
8231 name: "CheckLeafCurve",
8232 config: Config{
8233 MaxVersion: VersionTLS12,
8234 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008235 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008236 },
8237 flags: []string{"-p384-only"},
8238 shouldFail: true,
8239 expectedError: ":BAD_ECC_CERT:",
8240 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008241
8242 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8243 testCases = append(testCases, testCase{
8244 name: "CheckLeafCurve-TLS13",
8245 config: Config{
8246 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008247 Certificates: []Certificate{ecdsaP256Certificate},
8248 },
8249 flags: []string{"-p384-only"},
8250 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008251
8252 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8253 testCases = append(testCases, testCase{
8254 name: "ECDSACurveMismatch-Verify-TLS12",
8255 config: Config{
8256 MaxVersion: VersionTLS12,
8257 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8258 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008259 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008260 signatureECDSAWithP384AndSHA384,
8261 },
8262 },
8263 })
8264
8265 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8266 testCases = append(testCases, testCase{
8267 name: "ECDSACurveMismatch-Verify-TLS13",
8268 config: Config{
8269 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008270 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008271 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008272 signatureECDSAWithP384AndSHA384,
8273 },
8274 Bugs: ProtocolBugs{
8275 SkipECDSACurveCheck: true,
8276 },
8277 },
8278 shouldFail: true,
8279 expectedError: ":WRONG_SIGNATURE_TYPE:",
8280 })
8281
8282 // Signature algorithm selection in TLS 1.3 should take the curve into
8283 // account.
8284 testCases = append(testCases, testCase{
8285 testType: serverTest,
8286 name: "ECDSACurveMismatch-Sign-TLS13",
8287 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008288 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008289 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008290 signatureECDSAWithP384AndSHA384,
8291 signatureECDSAWithP256AndSHA256,
8292 },
8293 },
8294 flags: []string{
8295 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8296 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8297 },
8298 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8299 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008300
8301 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8302 // server does not attempt to sign in that case.
8303 testCases = append(testCases, testCase{
8304 testType: serverTest,
8305 name: "RSA-PSS-Large",
8306 config: Config{
8307 MaxVersion: VersionTLS13,
8308 VerifySignatureAlgorithms: []signatureAlgorithm{
8309 signatureRSAPSSWithSHA512,
8310 },
8311 },
8312 flags: []string{
8313 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8314 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8315 },
8316 shouldFail: true,
8317 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8318 })
David Benjamin57e929f2016-08-30 00:30:38 -04008319
8320 // Test that RSA-PSS is enabled by default for TLS 1.2.
8321 testCases = append(testCases, testCase{
8322 testType: clientTest,
8323 name: "RSA-PSS-Default-Verify",
8324 config: Config{
8325 MaxVersion: VersionTLS12,
8326 SignSignatureAlgorithms: []signatureAlgorithm{
8327 signatureRSAPSSWithSHA256,
8328 },
8329 },
8330 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8331 })
8332
8333 testCases = append(testCases, testCase{
8334 testType: serverTest,
8335 name: "RSA-PSS-Default-Sign",
8336 config: Config{
8337 MaxVersion: VersionTLS12,
8338 VerifySignatureAlgorithms: []signatureAlgorithm{
8339 signatureRSAPSSWithSHA256,
8340 },
8341 },
8342 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8343 })
David Benjamin69522112017-03-28 15:38:29 -05008344
8345 // TLS 1.1 and below has no way to advertise support for or negotiate
8346 // Ed25519's signature algorithm.
8347 testCases = append(testCases, testCase{
8348 testType: clientTest,
8349 name: "NoEd25519-TLS11-ServerAuth-Verify",
8350 config: Config{
8351 MaxVersion: VersionTLS11,
8352 Certificates: []Certificate{ed25519Certificate},
8353 Bugs: ProtocolBugs{
8354 // Sign with Ed25519 even though it is TLS 1.1.
8355 UseLegacySigningAlgorithm: signatureEd25519,
8356 },
8357 },
8358 flags: []string{"-enable-ed25519"},
8359 shouldFail: true,
8360 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8361 })
8362 testCases = append(testCases, testCase{
8363 testType: serverTest,
8364 name: "NoEd25519-TLS11-ServerAuth-Sign",
8365 config: Config{
8366 MaxVersion: VersionTLS11,
8367 },
8368 flags: []string{
8369 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8370 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8371 },
8372 shouldFail: true,
8373 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8374 })
8375 testCases = append(testCases, testCase{
8376 testType: serverTest,
8377 name: "NoEd25519-TLS11-ClientAuth-Verify",
8378 config: Config{
8379 MaxVersion: VersionTLS11,
8380 Certificates: []Certificate{ed25519Certificate},
8381 Bugs: ProtocolBugs{
8382 // Sign with Ed25519 even though it is TLS 1.1.
8383 UseLegacySigningAlgorithm: signatureEd25519,
8384 },
8385 },
8386 flags: []string{
8387 "-enable-ed25519",
8388 "-require-any-client-certificate",
8389 },
8390 shouldFail: true,
8391 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8392 })
8393 testCases = append(testCases, testCase{
8394 testType: clientTest,
8395 name: "NoEd25519-TLS11-ClientAuth-Sign",
8396 config: Config{
8397 MaxVersion: VersionTLS11,
8398 ClientAuth: RequireAnyClientCert,
8399 },
8400 flags: []string{
8401 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8402 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8403 },
8404 shouldFail: true,
8405 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8406 })
8407
8408 // Test Ed25519 is not advertised by default.
8409 testCases = append(testCases, testCase{
8410 testType: clientTest,
8411 name: "Ed25519DefaultDisable-NoAdvertise",
8412 config: Config{
8413 Certificates: []Certificate{ed25519Certificate},
8414 },
8415 shouldFail: true,
8416 expectedLocalError: "tls: no common signature algorithms",
8417 })
8418
8419 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8420 // preferences.
8421 testCases = append(testCases, testCase{
8422 testType: clientTest,
8423 name: "Ed25519DefaultDisable-NoAccept",
8424 config: Config{
8425 Certificates: []Certificate{ed25519Certificate},
8426 Bugs: ProtocolBugs{
8427 IgnorePeerSignatureAlgorithmPreferences: true,
8428 },
8429 },
8430 shouldFail: true,
8431 expectedLocalError: "remote error: illegal parameter",
8432 expectedError: ":WRONG_SIGNATURE_TYPE:",
8433 })
David Benjamin71c21b42017-04-14 17:05:40 -04008434
8435 // Test that configuring verify preferences changes what the client
8436 // advertises.
8437 testCases = append(testCases, testCase{
8438 name: "VerifyPreferences-Advertised",
8439 config: Config{
8440 Certificates: []Certificate{rsaCertificate},
8441 SignSignatureAlgorithms: []signatureAlgorithm{
8442 signatureRSAPSSWithSHA256,
8443 signatureRSAPSSWithSHA384,
8444 signatureRSAPSSWithSHA512,
8445 },
8446 },
8447 flags: []string{
8448 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8449 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8450 },
8451 })
8452
8453 // Test that the client advertises a set which the runner can find
8454 // nothing in common with.
8455 testCases = append(testCases, testCase{
8456 name: "VerifyPreferences-NoCommonAlgorithms",
8457 config: Config{
8458 Certificates: []Certificate{rsaCertificate},
8459 SignSignatureAlgorithms: []signatureAlgorithm{
8460 signatureRSAPSSWithSHA256,
8461 signatureRSAPSSWithSHA512,
8462 },
8463 },
8464 flags: []string{
8465 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8466 },
8467 shouldFail: true,
8468 expectedLocalError: "tls: no common signature algorithms",
8469 })
8470
8471 // Test that the client enforces its preferences when configured.
8472 testCases = append(testCases, testCase{
8473 name: "VerifyPreferences-Enforced",
8474 config: Config{
8475 Certificates: []Certificate{rsaCertificate},
8476 SignSignatureAlgorithms: []signatureAlgorithm{
8477 signatureRSAPSSWithSHA256,
8478 signatureRSAPSSWithSHA512,
8479 },
8480 Bugs: ProtocolBugs{
8481 IgnorePeerSignatureAlgorithmPreferences: true,
8482 },
8483 },
8484 flags: []string{
8485 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8486 },
8487 shouldFail: true,
8488 expectedLocalError: "remote error: illegal parameter",
8489 expectedError: ":WRONG_SIGNATURE_TYPE:",
8490 })
8491
8492 // Test that explicitly configuring Ed25519 is as good as changing the
8493 // boolean toggle.
8494 testCases = append(testCases, testCase{
8495 name: "VerifyPreferences-Ed25519",
8496 config: Config{
8497 Certificates: []Certificate{ed25519Certificate},
8498 },
8499 flags: []string{
8500 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8501 },
8502 })
David Benjamin000800a2014-11-14 01:43:59 -05008503}
8504
David Benjamin83f90402015-01-27 01:09:43 -05008505// timeouts is the retransmit schedule for BoringSSL. It doubles and
8506// caps at 60 seconds. On the 13th timeout, it gives up.
8507var timeouts = []time.Duration{
8508 1 * time.Second,
8509 2 * time.Second,
8510 4 * time.Second,
8511 8 * time.Second,
8512 16 * time.Second,
8513 32 * time.Second,
8514 60 * time.Second,
8515 60 * time.Second,
8516 60 * time.Second,
8517 60 * time.Second,
8518 60 * time.Second,
8519 60 * time.Second,
8520 60 * time.Second,
8521}
8522
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008523// shortTimeouts is an alternate set of timeouts which would occur if the
8524// initial timeout duration was set to 250ms.
8525var shortTimeouts = []time.Duration{
8526 250 * time.Millisecond,
8527 500 * time.Millisecond,
8528 1 * time.Second,
8529 2 * time.Second,
8530 4 * time.Second,
8531 8 * time.Second,
8532 16 * time.Second,
8533 32 * time.Second,
8534 60 * time.Second,
8535 60 * time.Second,
8536 60 * time.Second,
8537 60 * time.Second,
8538 60 * time.Second,
8539}
8540
David Benjamin83f90402015-01-27 01:09:43 -05008541func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008542 // These tests work by coordinating some behavior on both the shim and
8543 // the runner.
8544 //
8545 // TimeoutSchedule configures the runner to send a series of timeout
8546 // opcodes to the shim (see packetAdaptor) immediately before reading
8547 // each peer handshake flight N. The timeout opcode both simulates a
8548 // timeout in the shim and acts as a synchronization point to help the
8549 // runner bracket each handshake flight.
8550 //
8551 // We assume the shim does not read from the channel eagerly. It must
8552 // first wait until it has sent flight N and is ready to receive
8553 // handshake flight N+1. At this point, it will process the timeout
8554 // opcode. It must then immediately respond with a timeout ACK and act
8555 // as if the shim was idle for the specified amount of time.
8556 //
8557 // The runner then drops all packets received before the ACK and
8558 // continues waiting for flight N. This ordering results in one attempt
8559 // at sending flight N to be dropped. For the test to complete, the
8560 // shim must send flight N again, testing that the shim implements DTLS
8561 // retransmit on a timeout.
8562
Steven Valdez143e8b32016-07-11 13:19:03 -04008563 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008564 // likely be more epochs to cross and the final message's retransmit may
8565 // be more complex.
8566
David Benjamin11c82892017-02-23 20:40:31 -05008567 // Test that this is indeed the timeout schedule. Stress all
8568 // four patterns of handshake.
8569 for i := 1; i < len(timeouts); i++ {
8570 number := strconv.Itoa(i)
8571 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008572 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008573 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008575 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008576 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008577 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008578 },
8579 },
8580 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008581 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008582 })
David Benjamin11c82892017-02-23 20:40:31 -05008583 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008584 protocol: dtls,
8585 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008586 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008588 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008589 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008590 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008591 },
8592 },
8593 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008594 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008595 })
8596 }
David Benjamin11c82892017-02-23 20:40:31 -05008597
8598 // Test that exceeding the timeout schedule hits a read
8599 // timeout.
8600 testCases = append(testCases, testCase{
8601 protocol: dtls,
8602 name: "DTLS-Retransmit-Timeout",
8603 config: Config{
8604 MaxVersion: VersionTLS12,
8605 Bugs: ProtocolBugs{
8606 TimeoutSchedule: timeouts,
8607 },
8608 },
8609 resumeSession: true,
8610 flags: []string{"-async"},
8611 shouldFail: true,
8612 expectedError: ":READ_TIMEOUT_EXPIRED:",
8613 })
8614
8615 // Test that timeout handling has a fudge factor, due to API
8616 // problems.
8617 testCases = append(testCases, testCase{
8618 protocol: dtls,
8619 name: "DTLS-Retransmit-Fudge",
8620 config: Config{
8621 MaxVersion: VersionTLS12,
8622 Bugs: ProtocolBugs{
8623 TimeoutSchedule: []time.Duration{
8624 timeouts[0] - 10*time.Millisecond,
8625 },
8626 },
8627 },
8628 resumeSession: true,
8629 flags: []string{"-async"},
8630 })
8631
8632 // Test that the final Finished retransmitting isn't
8633 // duplicated if the peer badly fragments everything.
8634 testCases = append(testCases, testCase{
8635 testType: serverTest,
8636 protocol: dtls,
8637 name: "DTLS-Retransmit-Fragmented",
8638 config: Config{
8639 MaxVersion: VersionTLS12,
8640 Bugs: ProtocolBugs{
8641 TimeoutSchedule: []time.Duration{timeouts[0]},
8642 MaxHandshakeRecordLength: 2,
8643 },
8644 },
8645 flags: []string{"-async"},
8646 })
8647
8648 // Test the timeout schedule when a shorter initial timeout duration is set.
8649 testCases = append(testCases, testCase{
8650 protocol: dtls,
8651 name: "DTLS-Retransmit-Short-Client",
8652 config: Config{
8653 MaxVersion: VersionTLS12,
8654 Bugs: ProtocolBugs{
8655 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8656 },
8657 },
8658 resumeSession: true,
8659 flags: []string{
8660 "-async",
8661 "-initial-timeout-duration-ms", "250",
8662 },
8663 })
8664 testCases = append(testCases, testCase{
8665 protocol: dtls,
8666 testType: serverTest,
8667 name: "DTLS-Retransmit-Short-Server",
8668 config: Config{
8669 MaxVersion: VersionTLS12,
8670 Bugs: ProtocolBugs{
8671 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8672 },
8673 },
8674 resumeSession: true,
8675 flags: []string{
8676 "-async",
8677 "-initial-timeout-duration-ms", "250",
8678 },
8679 })
David Benjamin83f90402015-01-27 01:09:43 -05008680}
8681
David Benjaminc565ebb2015-04-03 04:06:36 -04008682func addExportKeyingMaterialTests() {
8683 for _, vers := range tlsVersions {
8684 if vers.version == VersionSSL30 {
8685 continue
8686 }
8687 testCases = append(testCases, testCase{
8688 name: "ExportKeyingMaterial-" + vers.name,
8689 config: Config{
8690 MaxVersion: vers.version,
8691 },
David Benjamina5022392017-07-10 17:40:39 -04008692 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008693 exportKeyingMaterial: 1024,
8694 exportLabel: "label",
8695 exportContext: "context",
8696 useExportContext: true,
8697 })
8698 testCases = append(testCases, testCase{
8699 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8700 config: Config{
8701 MaxVersion: vers.version,
8702 },
David Benjamina5022392017-07-10 17:40:39 -04008703 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008704 exportKeyingMaterial: 1024,
8705 })
8706 testCases = append(testCases, testCase{
8707 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8708 config: Config{
8709 MaxVersion: vers.version,
8710 },
David Benjamina5022392017-07-10 17:40:39 -04008711 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008712 exportKeyingMaterial: 1024,
8713 useExportContext: true,
8714 })
8715 testCases = append(testCases, testCase{
8716 name: "ExportKeyingMaterial-Small-" + vers.name,
8717 config: Config{
8718 MaxVersion: vers.version,
8719 },
David Benjamina5022392017-07-10 17:40:39 -04008720 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008721 exportKeyingMaterial: 1,
8722 exportLabel: "label",
8723 exportContext: "context",
8724 useExportContext: true,
8725 })
8726 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008727
David Benjaminc565ebb2015-04-03 04:06:36 -04008728 testCases = append(testCases, testCase{
8729 name: "ExportKeyingMaterial-SSL3",
8730 config: Config{
8731 MaxVersion: VersionSSL30,
8732 },
8733 exportKeyingMaterial: 1024,
8734 exportLabel: "label",
8735 exportContext: "context",
8736 useExportContext: true,
8737 shouldFail: true,
8738 expectedError: "failed to export keying material",
8739 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008740
8741 // Exporters work during a False Start.
8742 testCases = append(testCases, testCase{
8743 name: "ExportKeyingMaterial-FalseStart",
8744 config: Config{
8745 MaxVersion: VersionTLS12,
8746 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8747 NextProtos: []string{"foo"},
8748 Bugs: ProtocolBugs{
8749 ExpectFalseStart: true,
8750 },
8751 },
8752 flags: []string{
8753 "-false-start",
8754 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008755 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008756 },
8757 shimWritesFirst: true,
8758 exportKeyingMaterial: 1024,
8759 exportLabel: "label",
8760 exportContext: "context",
8761 useExportContext: true,
8762 })
8763
8764 // Exporters do not work in the middle of a renegotiation. Test this by
8765 // triggering the exporter after every SSL_read call and configuring the
8766 // shim to run asynchronously.
8767 testCases = append(testCases, testCase{
8768 name: "ExportKeyingMaterial-Renegotiate",
8769 config: Config{
8770 MaxVersion: VersionTLS12,
8771 },
8772 renegotiate: 1,
8773 flags: []string{
8774 "-async",
8775 "-use-exporter-between-reads",
8776 "-renegotiate-freely",
8777 "-expect-total-renegotiations", "1",
8778 },
8779 shouldFail: true,
8780 expectedError: "failed to export keying material",
8781 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008782}
8783
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008784func addTLSUniqueTests() {
8785 for _, isClient := range []bool{false, true} {
8786 for _, isResumption := range []bool{false, true} {
8787 for _, hasEMS := range []bool{false, true} {
8788 var suffix string
8789 if isResumption {
8790 suffix = "Resume-"
8791 } else {
8792 suffix = "Full-"
8793 }
8794
8795 if hasEMS {
8796 suffix += "EMS-"
8797 } else {
8798 suffix += "NoEMS-"
8799 }
8800
8801 if isClient {
8802 suffix += "Client"
8803 } else {
8804 suffix += "Server"
8805 }
8806
8807 test := testCase{
8808 name: "TLSUnique-" + suffix,
8809 testTLSUnique: true,
8810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008811 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008812 Bugs: ProtocolBugs{
8813 NoExtendedMasterSecret: !hasEMS,
8814 },
8815 },
8816 }
8817
8818 if isResumption {
8819 test.resumeSession = true
8820 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008821 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008822 Bugs: ProtocolBugs{
8823 NoExtendedMasterSecret: !hasEMS,
8824 },
8825 }
8826 }
8827
8828 if isResumption && !hasEMS {
8829 test.shouldFail = true
8830 test.expectedError = "failed to get tls-unique"
8831 }
8832
8833 testCases = append(testCases, test)
8834 }
8835 }
8836 }
8837}
8838
Adam Langley09505632015-07-30 18:10:13 -07008839func addCustomExtensionTests() {
8840 expectedContents := "custom extension"
8841 emptyString := ""
8842
8843 for _, isClient := range []bool{false, true} {
8844 suffix := "Server"
8845 flag := "-enable-server-custom-extension"
8846 testType := serverTest
8847 if isClient {
8848 suffix = "Client"
8849 flag = "-enable-client-custom-extension"
8850 testType = clientTest
8851 }
8852
8853 testCases = append(testCases, testCase{
8854 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008855 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008856 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008857 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008858 Bugs: ProtocolBugs{
8859 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008860 ExpectedCustomExtension: &expectedContents,
8861 },
8862 },
8863 flags: []string{flag},
8864 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008865 testCases = append(testCases, testCase{
8866 testType: testType,
8867 name: "CustomExtensions-" + suffix + "-TLS13",
8868 config: Config{
8869 MaxVersion: VersionTLS13,
8870 Bugs: ProtocolBugs{
8871 CustomExtension: expectedContents,
8872 ExpectedCustomExtension: &expectedContents,
8873 },
8874 },
8875 flags: []string{flag},
8876 })
Adam Langley09505632015-07-30 18:10:13 -07008877
Steven Valdez2a070722017-03-25 20:54:16 -05008878 // 0-RTT is not currently supported with Custom Extensions.
8879 testCases = append(testCases, testCase{
8880 testType: testType,
8881 name: "CustomExtensions-" + suffix + "-EarlyData",
8882 config: Config{
8883 MaxVersion: VersionTLS13,
8884 Bugs: ProtocolBugs{
8885 CustomExtension: expectedContents,
8886 ExpectedCustomExtension: &expectedContents,
8887 },
8888 },
8889 shouldFail: true,
8890 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8891 flags: []string{flag, "-enable-early-data"},
8892 })
8893
Adam Langley09505632015-07-30 18:10:13 -07008894 // If the parse callback fails, the handshake should also fail.
8895 testCases = append(testCases, testCase{
8896 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008897 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008899 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008900 Bugs: ProtocolBugs{
8901 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008902 ExpectedCustomExtension: &expectedContents,
8903 },
8904 },
David Benjamin399e7c92015-07-30 23:01:27 -04008905 flags: []string{flag},
8906 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008907 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8908 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008909 testCases = append(testCases, testCase{
8910 testType: testType,
8911 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8912 config: Config{
8913 MaxVersion: VersionTLS13,
8914 Bugs: ProtocolBugs{
8915 CustomExtension: expectedContents + "foo",
8916 ExpectedCustomExtension: &expectedContents,
8917 },
8918 },
8919 flags: []string{flag},
8920 shouldFail: true,
8921 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8922 })
Adam Langley09505632015-07-30 18:10:13 -07008923
8924 // If the add callback fails, the handshake should also fail.
8925 testCases = append(testCases, testCase{
8926 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008927 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008929 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008930 Bugs: ProtocolBugs{
8931 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008932 ExpectedCustomExtension: &expectedContents,
8933 },
8934 },
David Benjamin399e7c92015-07-30 23:01:27 -04008935 flags: []string{flag, "-custom-extension-fail-add"},
8936 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008937 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8938 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008939 testCases = append(testCases, testCase{
8940 testType: testType,
8941 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8942 config: Config{
8943 MaxVersion: VersionTLS13,
8944 Bugs: ProtocolBugs{
8945 CustomExtension: expectedContents,
8946 ExpectedCustomExtension: &expectedContents,
8947 },
8948 },
8949 flags: []string{flag, "-custom-extension-fail-add"},
8950 shouldFail: true,
8951 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8952 })
Adam Langley09505632015-07-30 18:10:13 -07008953
8954 // If the add callback returns zero, no extension should be
8955 // added.
8956 skipCustomExtension := expectedContents
8957 if isClient {
8958 // For the case where the client skips sending the
8959 // custom extension, the server must not “echo” it.
8960 skipCustomExtension = ""
8961 }
8962 testCases = append(testCases, testCase{
8963 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008964 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008966 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008967 Bugs: ProtocolBugs{
8968 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008969 ExpectedCustomExtension: &emptyString,
8970 },
8971 },
8972 flags: []string{flag, "-custom-extension-skip"},
8973 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008974 testCases = append(testCases, testCase{
8975 testType: testType,
8976 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8977 config: Config{
8978 MaxVersion: VersionTLS13,
8979 Bugs: ProtocolBugs{
8980 CustomExtension: skipCustomExtension,
8981 ExpectedCustomExtension: &emptyString,
8982 },
8983 },
8984 flags: []string{flag, "-custom-extension-skip"},
8985 })
Adam Langley09505632015-07-30 18:10:13 -07008986 }
8987
8988 // The custom extension add callback should not be called if the client
8989 // doesn't send the extension.
8990 testCases = append(testCases, testCase{
8991 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008992 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008994 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008995 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008996 ExpectedCustomExtension: &emptyString,
8997 },
8998 },
8999 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9000 })
Adam Langley2deb9842015-08-07 11:15:37 -07009001
Steven Valdez143e8b32016-07-11 13:19:03 -04009002 testCases = append(testCases, testCase{
9003 testType: serverTest,
9004 name: "CustomExtensions-NotCalled-Server-TLS13",
9005 config: Config{
9006 MaxVersion: VersionTLS13,
9007 Bugs: ProtocolBugs{
9008 ExpectedCustomExtension: &emptyString,
9009 },
9010 },
9011 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9012 })
9013
Adam Langley2deb9842015-08-07 11:15:37 -07009014 // Test an unknown extension from the server.
9015 testCases = append(testCases, testCase{
9016 testType: clientTest,
9017 name: "UnknownExtension-Client",
9018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009019 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009020 Bugs: ProtocolBugs{
9021 CustomExtension: expectedContents,
9022 },
9023 },
David Benjamin0c40a962016-08-01 12:05:50 -04009024 shouldFail: true,
9025 expectedError: ":UNEXPECTED_EXTENSION:",
9026 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009027 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009028 testCases = append(testCases, testCase{
9029 testType: clientTest,
9030 name: "UnknownExtension-Client-TLS13",
9031 config: Config{
9032 MaxVersion: VersionTLS13,
9033 Bugs: ProtocolBugs{
9034 CustomExtension: expectedContents,
9035 },
9036 },
David Benjamin0c40a962016-08-01 12:05:50 -04009037 shouldFail: true,
9038 expectedError: ":UNEXPECTED_EXTENSION:",
9039 expectedLocalError: "remote error: unsupported extension",
9040 })
David Benjamin490469f2016-10-05 22:44:38 -04009041 testCases = append(testCases, testCase{
9042 testType: clientTest,
9043 name: "UnknownUnencryptedExtension-Client-TLS13",
9044 config: Config{
9045 MaxVersion: VersionTLS13,
9046 Bugs: ProtocolBugs{
9047 CustomUnencryptedExtension: expectedContents,
9048 },
9049 },
9050 shouldFail: true,
9051 expectedError: ":UNEXPECTED_EXTENSION:",
9052 // The shim must send an alert, but alerts at this point do not
9053 // get successfully decrypted by the runner.
9054 expectedLocalError: "local error: bad record MAC",
9055 })
9056 testCases = append(testCases, testCase{
9057 testType: clientTest,
9058 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9059 config: Config{
9060 MaxVersion: VersionTLS13,
9061 Bugs: ProtocolBugs{
9062 SendUnencryptedALPN: "foo",
9063 },
9064 },
9065 flags: []string{
9066 "-advertise-alpn", "\x03foo\x03bar",
9067 },
9068 shouldFail: true,
9069 expectedError: ":UNEXPECTED_EXTENSION:",
9070 // The shim must send an alert, but alerts at this point do not
9071 // get successfully decrypted by the runner.
9072 expectedLocalError: "local error: bad record MAC",
9073 })
David Benjamin0c40a962016-08-01 12:05:50 -04009074
9075 // Test a known but unoffered extension from the server.
9076 testCases = append(testCases, testCase{
9077 testType: clientTest,
9078 name: "UnofferedExtension-Client",
9079 config: Config{
9080 MaxVersion: VersionTLS12,
9081 Bugs: ProtocolBugs{
9082 SendALPN: "alpn",
9083 },
9084 },
9085 shouldFail: true,
9086 expectedError: ":UNEXPECTED_EXTENSION:",
9087 expectedLocalError: "remote error: unsupported extension",
9088 })
9089 testCases = append(testCases, testCase{
9090 testType: clientTest,
9091 name: "UnofferedExtension-Client-TLS13",
9092 config: Config{
9093 MaxVersion: VersionTLS13,
9094 Bugs: ProtocolBugs{
9095 SendALPN: "alpn",
9096 },
9097 },
9098 shouldFail: true,
9099 expectedError: ":UNEXPECTED_EXTENSION:",
9100 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009101 })
Adam Langley09505632015-07-30 18:10:13 -07009102}
9103
David Benjaminb36a3952015-12-01 18:53:13 -05009104func addRSAClientKeyExchangeTests() {
9105 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9106 testCases = append(testCases, testCase{
9107 testType: serverTest,
9108 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9109 config: Config{
9110 // Ensure the ClientHello version and final
9111 // version are different, to detect if the
9112 // server uses the wrong one.
9113 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009114 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009115 Bugs: ProtocolBugs{
9116 BadRSAClientKeyExchange: bad,
9117 },
9118 },
9119 shouldFail: true,
9120 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9121 })
9122 }
David Benjamine63d9d72016-09-19 18:27:34 -04009123
9124 // The server must compare whatever was in ClientHello.version for the
9125 // RSA premaster.
9126 testCases = append(testCases, testCase{
9127 testType: serverTest,
9128 name: "SendClientVersion-RSA",
9129 config: Config{
9130 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9131 Bugs: ProtocolBugs{
9132 SendClientVersion: 0x1234,
9133 },
9134 },
9135 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9136 })
David Benjaminb36a3952015-12-01 18:53:13 -05009137}
9138
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009139var testCurves = []struct {
9140 name string
9141 id CurveID
9142}{
Adam Langley764ab982017-03-10 18:01:30 -08009143 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009144 {"P-256", CurveP256},
9145 {"P-384", CurveP384},
9146 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009147 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009148}
9149
Steven Valdez5440fe02016-07-18 12:40:30 -04009150const bogusCurve = 0x1234
9151
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009152func addCurveTests() {
9153 for _, curve := range testCurves {
9154 testCases = append(testCases, testCase{
9155 name: "CurveTest-Client-" + curve.name,
9156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009157 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009158 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9159 CurvePreferences: []CurveID{curve.id},
9160 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009161 flags: []string{
9162 "-enable-all-curves",
9163 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9164 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009165 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009166 })
9167 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009168 name: "CurveTest-Client-" + curve.name + "-TLS13",
9169 config: Config{
9170 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009171 CurvePreferences: []CurveID{curve.id},
9172 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009173 flags: []string{
9174 "-enable-all-curves",
9175 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9176 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009177 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009178 })
9179 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009180 testType: serverTest,
9181 name: "CurveTest-Server-" + curve.name,
9182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009183 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9185 CurvePreferences: []CurveID{curve.id},
9186 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009187 flags: []string{
9188 "-enable-all-curves",
9189 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9190 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009191 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009192 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009193 testCases = append(testCases, testCase{
9194 testType: serverTest,
9195 name: "CurveTest-Server-" + curve.name + "-TLS13",
9196 config: Config{
9197 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009198 CurvePreferences: []CurveID{curve.id},
9199 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009200 flags: []string{
9201 "-enable-all-curves",
9202 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9203 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009204 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009205 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009206 }
David Benjamin241ae832016-01-15 03:04:54 -05009207
9208 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009209 testCases = append(testCases, testCase{
9210 testType: serverTest,
9211 name: "UnknownCurve",
9212 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009213 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009214 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9215 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9216 },
9217 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009218
Steven Valdez803c77a2016-09-06 14:13:43 -04009219 // The server must be tolerant to bogus curves.
9220 testCases = append(testCases, testCase{
9221 testType: serverTest,
9222 name: "UnknownCurve-TLS13",
9223 config: Config{
9224 MaxVersion: VersionTLS13,
9225 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9226 },
9227 })
9228
David Benjamin4c3ddf72016-06-29 18:13:53 -04009229 // The server must not consider ECDHE ciphers when there are no
9230 // supported curves.
9231 testCases = append(testCases, testCase{
9232 testType: serverTest,
9233 name: "NoSupportedCurves",
9234 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009235 MaxVersion: VersionTLS12,
9236 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9237 Bugs: ProtocolBugs{
9238 NoSupportedCurves: true,
9239 },
9240 },
9241 shouldFail: true,
9242 expectedError: ":NO_SHARED_CIPHER:",
9243 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009244 testCases = append(testCases, testCase{
9245 testType: serverTest,
9246 name: "NoSupportedCurves-TLS13",
9247 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009248 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009249 Bugs: ProtocolBugs{
9250 NoSupportedCurves: true,
9251 },
9252 },
9253 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009254 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009255 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009256
9257 // The server must fall back to another cipher when there are no
9258 // supported curves.
9259 testCases = append(testCases, testCase{
9260 testType: serverTest,
9261 name: "NoCommonCurves",
9262 config: Config{
9263 MaxVersion: VersionTLS12,
9264 CipherSuites: []uint16{
9265 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009266 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009267 },
9268 CurvePreferences: []CurveID{CurveP224},
9269 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009270 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009271 })
9272
9273 // The client must reject bogus curves and disabled curves.
9274 testCases = append(testCases, testCase{
9275 name: "BadECDHECurve",
9276 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009277 MaxVersion: VersionTLS12,
9278 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9279 Bugs: ProtocolBugs{
9280 SendCurve: bogusCurve,
9281 },
9282 },
9283 shouldFail: true,
9284 expectedError: ":WRONG_CURVE:",
9285 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009286 testCases = append(testCases, testCase{
9287 name: "BadECDHECurve-TLS13",
9288 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009289 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009290 Bugs: ProtocolBugs{
9291 SendCurve: bogusCurve,
9292 },
9293 },
9294 shouldFail: true,
9295 expectedError: ":WRONG_CURVE:",
9296 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009297
9298 testCases = append(testCases, testCase{
9299 name: "UnsupportedCurve",
9300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009301 MaxVersion: VersionTLS12,
9302 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9303 CurvePreferences: []CurveID{CurveP256},
9304 Bugs: ProtocolBugs{
9305 IgnorePeerCurvePreferences: true,
9306 },
9307 },
9308 flags: []string{"-p384-only"},
9309 shouldFail: true,
9310 expectedError: ":WRONG_CURVE:",
9311 })
9312
David Benjamin4f921572016-07-17 14:20:10 +02009313 testCases = append(testCases, testCase{
9314 // TODO(davidben): Add a TLS 1.3 version where
9315 // HelloRetryRequest requests an unsupported curve.
9316 name: "UnsupportedCurve-ServerHello-TLS13",
9317 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009318 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009319 CurvePreferences: []CurveID{CurveP384},
9320 Bugs: ProtocolBugs{
9321 SendCurve: CurveP256,
9322 },
9323 },
9324 flags: []string{"-p384-only"},
9325 shouldFail: true,
9326 expectedError: ":WRONG_CURVE:",
9327 })
9328
David Benjamin4c3ddf72016-06-29 18:13:53 -04009329 // Test invalid curve points.
9330 testCases = append(testCases, testCase{
9331 name: "InvalidECDHPoint-Client",
9332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009333 MaxVersion: VersionTLS12,
9334 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9335 CurvePreferences: []CurveID{CurveP256},
9336 Bugs: ProtocolBugs{
9337 InvalidECDHPoint: true,
9338 },
9339 },
9340 shouldFail: true,
9341 expectedError: ":INVALID_ENCODING:",
9342 })
9343 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009344 name: "InvalidECDHPoint-Client-TLS13",
9345 config: Config{
9346 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009347 CurvePreferences: []CurveID{CurveP256},
9348 Bugs: ProtocolBugs{
9349 InvalidECDHPoint: true,
9350 },
9351 },
9352 shouldFail: true,
9353 expectedError: ":INVALID_ENCODING:",
9354 })
9355 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009356 testType: serverTest,
9357 name: "InvalidECDHPoint-Server",
9358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009359 MaxVersion: VersionTLS12,
9360 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9361 CurvePreferences: []CurveID{CurveP256},
9362 Bugs: ProtocolBugs{
9363 InvalidECDHPoint: true,
9364 },
9365 },
9366 shouldFail: true,
9367 expectedError: ":INVALID_ENCODING:",
9368 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009369 testCases = append(testCases, testCase{
9370 testType: serverTest,
9371 name: "InvalidECDHPoint-Server-TLS13",
9372 config: Config{
9373 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009374 CurvePreferences: []CurveID{CurveP256},
9375 Bugs: ProtocolBugs{
9376 InvalidECDHPoint: true,
9377 },
9378 },
9379 shouldFail: true,
9380 expectedError: ":INVALID_ENCODING:",
9381 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009382
9383 // The previous curve ID should be reported on TLS 1.2 resumption.
9384 testCases = append(testCases, testCase{
9385 name: "CurveID-Resume-Client",
9386 config: Config{
9387 MaxVersion: VersionTLS12,
9388 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9389 CurvePreferences: []CurveID{CurveX25519},
9390 },
9391 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9392 resumeSession: true,
9393 })
9394 testCases = append(testCases, testCase{
9395 testType: serverTest,
9396 name: "CurveID-Resume-Server",
9397 config: Config{
9398 MaxVersion: VersionTLS12,
9399 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9400 CurvePreferences: []CurveID{CurveX25519},
9401 },
9402 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9403 resumeSession: true,
9404 })
9405
9406 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9407 // one should be reported.
9408 testCases = append(testCases, testCase{
9409 name: "CurveID-Resume-Client-TLS13",
9410 config: Config{
9411 MaxVersion: VersionTLS13,
9412 CurvePreferences: []CurveID{CurveX25519},
9413 },
9414 resumeConfig: &Config{
9415 MaxVersion: VersionTLS13,
9416 CurvePreferences: []CurveID{CurveP256},
9417 },
9418 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009419 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9420 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009421 },
9422 resumeSession: true,
9423 })
9424 testCases = append(testCases, testCase{
9425 testType: serverTest,
9426 name: "CurveID-Resume-Server-TLS13",
9427 config: Config{
9428 MaxVersion: VersionTLS13,
9429 CurvePreferences: []CurveID{CurveX25519},
9430 },
9431 resumeConfig: &Config{
9432 MaxVersion: VersionTLS13,
9433 CurvePreferences: []CurveID{CurveP256},
9434 },
9435 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009436 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9437 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009438 },
9439 resumeSession: true,
9440 })
David Benjamina81967b2016-12-22 09:16:57 -05009441
9442 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9443 testCases = append(testCases, testCase{
9444 name: "PointFormat-ServerHello-TLS12",
9445 config: Config{
9446 MaxVersion: VersionTLS12,
9447 Bugs: ProtocolBugs{
9448 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9449 },
9450 },
9451 })
9452 testCases = append(testCases, testCase{
9453 name: "PointFormat-EncryptedExtensions-TLS13",
9454 config: Config{
9455 MaxVersion: VersionTLS13,
9456 Bugs: ProtocolBugs{
9457 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9458 },
9459 },
9460 shouldFail: true,
9461 expectedError: ":ERROR_PARSING_EXTENSION:",
9462 })
9463
9464 // Test that we tolerate unknown point formats, as long as
9465 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9466 // check they are still functional.
9467 testCases = append(testCases, testCase{
9468 name: "PointFormat-Client-Tolerance",
9469 config: Config{
9470 MaxVersion: VersionTLS12,
9471 Bugs: ProtocolBugs{
9472 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9473 },
9474 },
9475 })
9476 testCases = append(testCases, testCase{
9477 testType: serverTest,
9478 name: "PointFormat-Server-Tolerance",
9479 config: Config{
9480 MaxVersion: VersionTLS12,
9481 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9482 Bugs: ProtocolBugs{
9483 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9484 },
9485 },
9486 })
9487
9488 // Test TLS 1.2 does not require the point format extension to be
9489 // present.
9490 testCases = append(testCases, testCase{
9491 name: "PointFormat-Client-Missing",
9492 config: Config{
9493 MaxVersion: VersionTLS12,
9494 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9495 Bugs: ProtocolBugs{
9496 SendSupportedPointFormats: []byte{},
9497 },
9498 },
9499 })
9500 testCases = append(testCases, testCase{
9501 testType: serverTest,
9502 name: "PointFormat-Server-Missing",
9503 config: Config{
9504 MaxVersion: VersionTLS12,
9505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9506 Bugs: ProtocolBugs{
9507 SendSupportedPointFormats: []byte{},
9508 },
9509 },
9510 })
9511
9512 // If the point format extension is present, uncompressed points must be
9513 // offered. BoringSSL requires this whether or not ECDHE is used.
9514 testCases = append(testCases, testCase{
9515 name: "PointFormat-Client-MissingUncompressed",
9516 config: Config{
9517 MaxVersion: VersionTLS12,
9518 Bugs: ProtocolBugs{
9519 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9520 },
9521 },
9522 shouldFail: true,
9523 expectedError: ":ERROR_PARSING_EXTENSION:",
9524 })
9525 testCases = append(testCases, testCase{
9526 testType: serverTest,
9527 name: "PointFormat-Server-MissingUncompressed",
9528 config: Config{
9529 MaxVersion: VersionTLS12,
9530 Bugs: ProtocolBugs{
9531 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9532 },
9533 },
9534 shouldFail: true,
9535 expectedError: ":ERROR_PARSING_EXTENSION:",
9536 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009537}
9538
David Benjaminc9ae27c2016-06-24 22:56:37 -04009539func addTLS13RecordTests() {
9540 testCases = append(testCases, testCase{
9541 name: "TLS13-RecordPadding",
9542 config: Config{
9543 MaxVersion: VersionTLS13,
9544 MinVersion: VersionTLS13,
9545 Bugs: ProtocolBugs{
9546 RecordPadding: 10,
9547 },
9548 },
9549 })
9550
9551 testCases = append(testCases, testCase{
9552 name: "TLS13-EmptyRecords",
9553 config: Config{
9554 MaxVersion: VersionTLS13,
9555 MinVersion: VersionTLS13,
9556 Bugs: ProtocolBugs{
9557 OmitRecordContents: true,
9558 },
9559 },
9560 shouldFail: true,
9561 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9562 })
9563
9564 testCases = append(testCases, testCase{
9565 name: "TLS13-OnlyPadding",
9566 config: Config{
9567 MaxVersion: VersionTLS13,
9568 MinVersion: VersionTLS13,
9569 Bugs: ProtocolBugs{
9570 OmitRecordContents: true,
9571 RecordPadding: 10,
9572 },
9573 },
9574 shouldFail: true,
9575 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9576 })
9577
9578 testCases = append(testCases, testCase{
9579 name: "TLS13-WrongOuterRecord",
9580 config: Config{
9581 MaxVersion: VersionTLS13,
9582 MinVersion: VersionTLS13,
9583 Bugs: ProtocolBugs{
9584 OuterRecordType: recordTypeHandshake,
9585 },
9586 },
9587 shouldFail: true,
9588 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9589 })
9590}
9591
Steven Valdez5b986082016-09-01 12:29:49 -04009592func addSessionTicketTests() {
9593 testCases = append(testCases, testCase{
9594 // In TLS 1.2 and below, empty NewSessionTicket messages
9595 // mean the server changed its mind on sending a ticket.
9596 name: "SendEmptySessionTicket",
9597 config: Config{
9598 MaxVersion: VersionTLS12,
9599 Bugs: ProtocolBugs{
9600 SendEmptySessionTicket: true,
9601 },
9602 },
9603 flags: []string{"-expect-no-session"},
9604 })
9605
9606 // Test that the server ignores unknown PSK modes.
9607 testCases = append(testCases, testCase{
9608 testType: serverTest,
9609 name: "TLS13-SendUnknownModeSessionTicket-Server",
9610 config: Config{
9611 MaxVersion: VersionTLS13,
9612 Bugs: ProtocolBugs{
9613 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009614 },
9615 },
9616 resumeSession: true,
9617 expectedResumeVersion: VersionTLS13,
9618 })
9619
Steven Valdeza833c352016-11-01 13:39:36 -04009620 // Test that the server does not send session tickets with no matching key exchange mode.
9621 testCases = append(testCases, testCase{
9622 testType: serverTest,
9623 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9624 config: Config{
9625 MaxVersion: VersionTLS13,
9626 Bugs: ProtocolBugs{
9627 SendPSKKeyExchangeModes: []byte{0x1a},
9628 ExpectNoNewSessionTicket: true,
9629 },
9630 },
9631 })
9632
9633 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009634 testCases = append(testCases, testCase{
9635 testType: serverTest,
9636 name: "TLS13-SendBadKEModeSessionTicket-Server",
9637 config: Config{
9638 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009639 },
9640 resumeConfig: &Config{
9641 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009642 Bugs: ProtocolBugs{
9643 SendPSKKeyExchangeModes: []byte{0x1a},
9644 },
9645 },
9646 resumeSession: true,
9647 expectResumeRejected: true,
9648 })
9649
Steven Valdeza833c352016-11-01 13:39:36 -04009650 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009651 testCases = append(testCases, testCase{
9652 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009653 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009654 config: Config{
9655 MaxVersion: VersionTLS13,
9656 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009657 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009658 },
9659 },
Steven Valdeza833c352016-11-01 13:39:36 -04009660 resumeSession: true,
9661 flags: []string{
9662 "-resumption-delay", "10",
9663 },
Steven Valdez5b986082016-09-01 12:29:49 -04009664 })
9665
Steven Valdeza833c352016-11-01 13:39:36 -04009666 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009667 testCases = append(testCases, testCase{
9668 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009669 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009670 config: Config{
9671 MaxVersion: VersionTLS13,
9672 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009673 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009674 },
9675 },
Steven Valdeza833c352016-11-01 13:39:36 -04009676 resumeSession: true,
9677 shouldFail: true,
9678 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009679 })
9680
David Benjamin35ac5b72017-03-03 15:05:56 -05009681 // Test that the server's ticket age skew reporting works.
9682 testCases = append(testCases, testCase{
9683 testType: serverTest,
9684 name: "TLS13-TicketAgeSkew-Forward",
9685 config: Config{
9686 MaxVersion: VersionTLS13,
9687 Bugs: ProtocolBugs{
9688 SendTicketAge: 15 * time.Second,
9689 },
9690 },
David Benjamin065d7332017-03-26 10:51:43 -05009691 resumeSession: true,
9692 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009693 flags: []string{
9694 "-resumption-delay", "10",
9695 "-expect-ticket-age-skew", "5",
9696 },
9697 })
9698 testCases = append(testCases, testCase{
9699 testType: serverTest,
9700 name: "TLS13-TicketAgeSkew-Backward",
9701 config: Config{
9702 MaxVersion: VersionTLS13,
9703 Bugs: ProtocolBugs{
9704 SendTicketAge: 5 * time.Second,
9705 },
9706 },
David Benjamin065d7332017-03-26 10:51:43 -05009707 resumeSession: true,
9708 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009709 flags: []string{
9710 "-resumption-delay", "10",
9711 "-expect-ticket-age-skew", "-5",
9712 },
9713 })
9714
Steven Valdez08b65f42016-12-07 15:29:45 -05009715 testCases = append(testCases, testCase{
9716 testType: clientTest,
9717 name: "TLS13-SendTicketEarlyDataInfo",
9718 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009719 MaxVersion: VersionTLS13,
9720 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009721 },
9722 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009723 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009724 "-expect-early-data-info",
9725 },
9726 })
9727
David Benjamin9b160662017-01-25 19:53:43 -05009728 // Test that 0-RTT tickets are ignored in clients unless opted in.
9729 testCases = append(testCases, testCase{
9730 testType: clientTest,
9731 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9732 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009733 MaxVersion: VersionTLS13,
9734 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009735 },
9736 })
9737
Steven Valdez08b65f42016-12-07 15:29:45 -05009738 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009739 testType: clientTest,
9740 name: "TLS13-DuplicateTicketEarlyDataInfo",
9741 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009742 MaxVersion: VersionTLS13,
9743 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009744 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009745 DuplicateTicketEarlyDataInfo: true,
9746 },
9747 },
9748 shouldFail: true,
9749 expectedError: ":DUPLICATE_EXTENSION:",
9750 expectedLocalError: "remote error: illegal parameter",
9751 })
9752
9753 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009754 testType: serverTest,
9755 name: "TLS13-ExpectTicketEarlyDataInfo",
9756 config: Config{
9757 MaxVersion: VersionTLS13,
9758 Bugs: ProtocolBugs{
9759 ExpectTicketEarlyDataInfo: true,
9760 },
9761 },
9762 flags: []string{
9763 "-enable-early-data",
9764 },
9765 })
David Benjamin17b30832017-01-28 14:00:32 -05009766
9767 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9768 // is honored.
9769 testCases = append(testCases, testCase{
9770 testType: clientTest,
9771 name: "TLS13-HonorServerSessionTicketLifetime",
9772 config: Config{
9773 MaxVersion: VersionTLS13,
9774 Bugs: ProtocolBugs{
9775 SendTicketLifetime: 20 * time.Second,
9776 },
9777 },
9778 flags: []string{
9779 "-resumption-delay", "19",
9780 },
9781 resumeSession: true,
9782 })
9783 testCases = append(testCases, testCase{
9784 testType: clientTest,
9785 name: "TLS13-HonorServerSessionTicketLifetime-2",
9786 config: Config{
9787 MaxVersion: VersionTLS13,
9788 Bugs: ProtocolBugs{
9789 SendTicketLifetime: 20 * time.Second,
9790 // The client should not offer the expired session.
9791 ExpectNoTLS13PSK: true,
9792 },
9793 },
9794 flags: []string{
9795 "-resumption-delay", "21",
9796 },
David Benjamin023d4192017-02-06 13:49:07 -05009797 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009798 expectResumeRejected: true,
9799 })
Steven Valdez5b986082016-09-01 12:29:49 -04009800}
9801
David Benjamin82261be2016-07-07 14:32:50 -07009802func addChangeCipherSpecTests() {
9803 // Test missing ChangeCipherSpecs.
9804 testCases = append(testCases, testCase{
9805 name: "SkipChangeCipherSpec-Client",
9806 config: Config{
9807 MaxVersion: VersionTLS12,
9808 Bugs: ProtocolBugs{
9809 SkipChangeCipherSpec: true,
9810 },
9811 },
9812 shouldFail: true,
9813 expectedError: ":UNEXPECTED_RECORD:",
9814 })
9815 testCases = append(testCases, testCase{
9816 testType: serverTest,
9817 name: "SkipChangeCipherSpec-Server",
9818 config: Config{
9819 MaxVersion: VersionTLS12,
9820 Bugs: ProtocolBugs{
9821 SkipChangeCipherSpec: true,
9822 },
9823 },
9824 shouldFail: true,
9825 expectedError: ":UNEXPECTED_RECORD:",
9826 })
9827 testCases = append(testCases, testCase{
9828 testType: serverTest,
9829 name: "SkipChangeCipherSpec-Server-NPN",
9830 config: Config{
9831 MaxVersion: VersionTLS12,
9832 NextProtos: []string{"bar"},
9833 Bugs: ProtocolBugs{
9834 SkipChangeCipherSpec: true,
9835 },
9836 },
9837 flags: []string{
9838 "-advertise-npn", "\x03foo\x03bar\x03baz",
9839 },
9840 shouldFail: true,
9841 expectedError: ":UNEXPECTED_RECORD:",
9842 })
9843
9844 // Test synchronization between the handshake and ChangeCipherSpec.
9845 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9846 // rejected. Test both with and without handshake packing to handle both
9847 // when the partial post-CCS message is in its own record and when it is
9848 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009849 for _, packed := range []bool{false, true} {
9850 var suffix string
9851 if packed {
9852 suffix = "-Packed"
9853 }
9854
9855 testCases = append(testCases, testCase{
9856 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9857 config: Config{
9858 MaxVersion: VersionTLS12,
9859 Bugs: ProtocolBugs{
9860 FragmentAcrossChangeCipherSpec: true,
9861 PackHandshakeFlight: packed,
9862 },
9863 },
9864 shouldFail: true,
9865 expectedError: ":UNEXPECTED_RECORD:",
9866 })
9867 testCases = append(testCases, testCase{
9868 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9869 config: Config{
9870 MaxVersion: VersionTLS12,
9871 },
9872 resumeSession: true,
9873 resumeConfig: &Config{
9874 MaxVersion: VersionTLS12,
9875 Bugs: ProtocolBugs{
9876 FragmentAcrossChangeCipherSpec: true,
9877 PackHandshakeFlight: packed,
9878 },
9879 },
9880 shouldFail: true,
9881 expectedError: ":UNEXPECTED_RECORD:",
9882 })
9883 testCases = append(testCases, testCase{
9884 testType: serverTest,
9885 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9886 config: Config{
9887 MaxVersion: VersionTLS12,
9888 Bugs: ProtocolBugs{
9889 FragmentAcrossChangeCipherSpec: true,
9890 PackHandshakeFlight: packed,
9891 },
9892 },
9893 shouldFail: true,
9894 expectedError: ":UNEXPECTED_RECORD:",
9895 })
9896 testCases = append(testCases, testCase{
9897 testType: serverTest,
9898 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9899 config: Config{
9900 MaxVersion: VersionTLS12,
9901 },
9902 resumeSession: true,
9903 resumeConfig: &Config{
9904 MaxVersion: VersionTLS12,
9905 Bugs: ProtocolBugs{
9906 FragmentAcrossChangeCipherSpec: true,
9907 PackHandshakeFlight: packed,
9908 },
9909 },
9910 shouldFail: true,
9911 expectedError: ":UNEXPECTED_RECORD:",
9912 })
9913 testCases = append(testCases, testCase{
9914 testType: serverTest,
9915 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9916 config: Config{
9917 MaxVersion: VersionTLS12,
9918 NextProtos: []string{"bar"},
9919 Bugs: ProtocolBugs{
9920 FragmentAcrossChangeCipherSpec: true,
9921 PackHandshakeFlight: packed,
9922 },
9923 },
9924 flags: []string{
9925 "-advertise-npn", "\x03foo\x03bar\x03baz",
9926 },
9927 shouldFail: true,
9928 expectedError: ":UNEXPECTED_RECORD:",
9929 })
9930 }
9931
David Benjamin61672812016-07-14 23:10:43 -04009932 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9933 // messages in the handshake queue. Do this by testing the server
9934 // reading the client Finished, reversing the flight so Finished comes
9935 // first.
9936 testCases = append(testCases, testCase{
9937 protocol: dtls,
9938 testType: serverTest,
9939 name: "SendUnencryptedFinished-DTLS",
9940 config: Config{
9941 MaxVersion: VersionTLS12,
9942 Bugs: ProtocolBugs{
9943 SendUnencryptedFinished: true,
9944 ReverseHandshakeFragments: true,
9945 },
9946 },
9947 shouldFail: true,
9948 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9949 })
9950
Steven Valdez143e8b32016-07-11 13:19:03 -04009951 // Test synchronization between encryption changes and the handshake in
9952 // TLS 1.3, where ChangeCipherSpec is implicit.
9953 testCases = append(testCases, testCase{
9954 name: "PartialEncryptedExtensionsWithServerHello",
9955 config: Config{
9956 MaxVersion: VersionTLS13,
9957 Bugs: ProtocolBugs{
9958 PartialEncryptedExtensionsWithServerHello: true,
9959 },
9960 },
9961 shouldFail: true,
9962 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9963 })
9964 testCases = append(testCases, testCase{
9965 testType: serverTest,
9966 name: "PartialClientFinishedWithClientHello",
9967 config: Config{
9968 MaxVersion: VersionTLS13,
9969 Bugs: ProtocolBugs{
9970 PartialClientFinishedWithClientHello: true,
9971 },
9972 },
9973 shouldFail: true,
9974 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9975 })
9976
David Benjamin82261be2016-07-07 14:32:50 -07009977 // Test that early ChangeCipherSpecs are handled correctly.
9978 testCases = append(testCases, testCase{
9979 testType: serverTest,
9980 name: "EarlyChangeCipherSpec-server-1",
9981 config: Config{
9982 MaxVersion: VersionTLS12,
9983 Bugs: ProtocolBugs{
9984 EarlyChangeCipherSpec: 1,
9985 },
9986 },
9987 shouldFail: true,
9988 expectedError: ":UNEXPECTED_RECORD:",
9989 })
9990 testCases = append(testCases, testCase{
9991 testType: serverTest,
9992 name: "EarlyChangeCipherSpec-server-2",
9993 config: Config{
9994 MaxVersion: VersionTLS12,
9995 Bugs: ProtocolBugs{
9996 EarlyChangeCipherSpec: 2,
9997 },
9998 },
9999 shouldFail: true,
10000 expectedError: ":UNEXPECTED_RECORD:",
10001 })
10002 testCases = append(testCases, testCase{
10003 protocol: dtls,
10004 name: "StrayChangeCipherSpec",
10005 config: Config{
10006 // TODO(davidben): Once DTLS 1.3 exists, test
10007 // that stray ChangeCipherSpec messages are
10008 // rejected.
10009 MaxVersion: VersionTLS12,
10010 Bugs: ProtocolBugs{
10011 StrayChangeCipherSpec: true,
10012 },
10013 },
10014 })
10015
10016 // Test that the contents of ChangeCipherSpec are checked.
10017 testCases = append(testCases, testCase{
10018 name: "BadChangeCipherSpec-1",
10019 config: Config{
10020 MaxVersion: VersionTLS12,
10021 Bugs: ProtocolBugs{
10022 BadChangeCipherSpec: []byte{2},
10023 },
10024 },
10025 shouldFail: true,
10026 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10027 })
10028 testCases = append(testCases, testCase{
10029 name: "BadChangeCipherSpec-2",
10030 config: Config{
10031 MaxVersion: VersionTLS12,
10032 Bugs: ProtocolBugs{
10033 BadChangeCipherSpec: []byte{1, 1},
10034 },
10035 },
10036 shouldFail: true,
10037 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10038 })
10039 testCases = append(testCases, testCase{
10040 protocol: dtls,
10041 name: "BadChangeCipherSpec-DTLS-1",
10042 config: Config{
10043 MaxVersion: VersionTLS12,
10044 Bugs: ProtocolBugs{
10045 BadChangeCipherSpec: []byte{2},
10046 },
10047 },
10048 shouldFail: true,
10049 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10050 })
10051 testCases = append(testCases, testCase{
10052 protocol: dtls,
10053 name: "BadChangeCipherSpec-DTLS-2",
10054 config: Config{
10055 MaxVersion: VersionTLS12,
10056 Bugs: ProtocolBugs{
10057 BadChangeCipherSpec: []byte{1, 1},
10058 },
10059 },
10060 shouldFail: true,
10061 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10062 })
10063}
10064
David Benjamincd2c8062016-09-09 11:28:16 -040010065type perMessageTest struct {
10066 messageType uint8
10067 test testCase
10068}
10069
10070// makePerMessageTests returns a series of test templates which cover each
10071// message in the TLS handshake. These may be used with bugs like
10072// WrongMessageType to fully test a per-message bug.
10073func makePerMessageTests() []perMessageTest {
10074 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010075 for _, protocol := range []protocol{tls, dtls} {
10076 var suffix string
10077 if protocol == dtls {
10078 suffix = "-DTLS"
10079 }
10080
David Benjamincd2c8062016-09-09 11:28:16 -040010081 ret = append(ret, perMessageTest{
10082 messageType: typeClientHello,
10083 test: testCase{
10084 protocol: protocol,
10085 testType: serverTest,
10086 name: "ClientHello" + suffix,
10087 config: Config{
10088 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010089 },
10090 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010091 })
10092
10093 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010094 ret = append(ret, perMessageTest{
10095 messageType: typeHelloVerifyRequest,
10096 test: testCase{
10097 protocol: protocol,
10098 name: "HelloVerifyRequest" + suffix,
10099 config: Config{
10100 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010101 },
10102 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010103 })
10104 }
10105
David Benjamincd2c8062016-09-09 11:28:16 -040010106 ret = append(ret, perMessageTest{
10107 messageType: typeServerHello,
10108 test: testCase{
10109 protocol: protocol,
10110 name: "ServerHello" + suffix,
10111 config: Config{
10112 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010113 },
10114 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010115 })
10116
David Benjamincd2c8062016-09-09 11:28:16 -040010117 ret = append(ret, perMessageTest{
10118 messageType: typeCertificate,
10119 test: testCase{
10120 protocol: protocol,
10121 name: "ServerCertificate" + suffix,
10122 config: Config{
10123 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010124 },
10125 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010126 })
10127
David Benjamincd2c8062016-09-09 11:28:16 -040010128 ret = append(ret, perMessageTest{
10129 messageType: typeCertificateStatus,
10130 test: testCase{
10131 protocol: protocol,
10132 name: "CertificateStatus" + suffix,
10133 config: Config{
10134 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010135 },
David Benjamincd2c8062016-09-09 11:28:16 -040010136 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010137 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010138 })
10139
David Benjamincd2c8062016-09-09 11:28:16 -040010140 ret = append(ret, perMessageTest{
10141 messageType: typeServerKeyExchange,
10142 test: testCase{
10143 protocol: protocol,
10144 name: "ServerKeyExchange" + suffix,
10145 config: Config{
10146 MaxVersion: VersionTLS12,
10147 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010148 },
10149 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010150 })
10151
David Benjamincd2c8062016-09-09 11:28:16 -040010152 ret = append(ret, perMessageTest{
10153 messageType: typeCertificateRequest,
10154 test: testCase{
10155 protocol: protocol,
10156 name: "CertificateRequest" + suffix,
10157 config: Config{
10158 MaxVersion: VersionTLS12,
10159 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010160 },
10161 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010162 })
10163
David Benjamincd2c8062016-09-09 11:28:16 -040010164 ret = append(ret, perMessageTest{
10165 messageType: typeServerHelloDone,
10166 test: testCase{
10167 protocol: protocol,
10168 name: "ServerHelloDone" + suffix,
10169 config: Config{
10170 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010171 },
10172 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010173 })
10174
David Benjamincd2c8062016-09-09 11:28:16 -040010175 ret = append(ret, perMessageTest{
10176 messageType: typeCertificate,
10177 test: testCase{
10178 testType: serverTest,
10179 protocol: protocol,
10180 name: "ClientCertificate" + suffix,
10181 config: Config{
10182 Certificates: []Certificate{rsaCertificate},
10183 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010184 },
David Benjamincd2c8062016-09-09 11:28:16 -040010185 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010186 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010187 })
10188
David Benjamincd2c8062016-09-09 11:28:16 -040010189 ret = append(ret, perMessageTest{
10190 messageType: typeCertificateVerify,
10191 test: testCase{
10192 testType: serverTest,
10193 protocol: protocol,
10194 name: "CertificateVerify" + suffix,
10195 config: Config{
10196 Certificates: []Certificate{rsaCertificate},
10197 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010198 },
David Benjamincd2c8062016-09-09 11:28:16 -040010199 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010200 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010201 })
10202
David Benjamincd2c8062016-09-09 11:28:16 -040010203 ret = append(ret, perMessageTest{
10204 messageType: typeClientKeyExchange,
10205 test: testCase{
10206 testType: serverTest,
10207 protocol: protocol,
10208 name: "ClientKeyExchange" + suffix,
10209 config: Config{
10210 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010211 },
10212 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010213 })
10214
10215 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010216 ret = append(ret, perMessageTest{
10217 messageType: typeNextProtocol,
10218 test: testCase{
10219 testType: serverTest,
10220 protocol: protocol,
10221 name: "NextProtocol" + suffix,
10222 config: Config{
10223 MaxVersion: VersionTLS12,
10224 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010225 },
David Benjamincd2c8062016-09-09 11:28:16 -040010226 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010227 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010228 })
10229
David Benjamincd2c8062016-09-09 11:28:16 -040010230 ret = append(ret, perMessageTest{
10231 messageType: typeChannelID,
10232 test: testCase{
10233 testType: serverTest,
10234 protocol: protocol,
10235 name: "ChannelID" + suffix,
10236 config: Config{
10237 MaxVersion: VersionTLS12,
10238 ChannelID: channelIDKey,
10239 },
10240 flags: []string{
10241 "-expect-channel-id",
10242 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010243 },
10244 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010245 })
10246 }
10247
David Benjamincd2c8062016-09-09 11:28:16 -040010248 ret = append(ret, perMessageTest{
10249 messageType: typeFinished,
10250 test: testCase{
10251 testType: serverTest,
10252 protocol: protocol,
10253 name: "ClientFinished" + suffix,
10254 config: Config{
10255 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010256 },
10257 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010258 })
10259
David Benjamincd2c8062016-09-09 11:28:16 -040010260 ret = append(ret, perMessageTest{
10261 messageType: typeNewSessionTicket,
10262 test: testCase{
10263 protocol: protocol,
10264 name: "NewSessionTicket" + suffix,
10265 config: Config{
10266 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010267 },
10268 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010269 })
10270
David Benjamincd2c8062016-09-09 11:28:16 -040010271 ret = append(ret, perMessageTest{
10272 messageType: typeFinished,
10273 test: testCase{
10274 protocol: protocol,
10275 name: "ServerFinished" + suffix,
10276 config: Config{
10277 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010278 },
10279 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010280 })
10281
10282 }
David Benjamincd2c8062016-09-09 11:28:16 -040010283
10284 ret = append(ret, perMessageTest{
10285 messageType: typeClientHello,
10286 test: testCase{
10287 testType: serverTest,
10288 name: "TLS13-ClientHello",
10289 config: Config{
10290 MaxVersion: VersionTLS13,
10291 },
10292 },
10293 })
10294
10295 ret = append(ret, perMessageTest{
10296 messageType: typeServerHello,
10297 test: testCase{
10298 name: "TLS13-ServerHello",
10299 config: Config{
10300 MaxVersion: VersionTLS13,
10301 },
10302 },
10303 })
10304
10305 ret = append(ret, perMessageTest{
10306 messageType: typeEncryptedExtensions,
10307 test: testCase{
10308 name: "TLS13-EncryptedExtensions",
10309 config: Config{
10310 MaxVersion: VersionTLS13,
10311 },
10312 },
10313 })
10314
10315 ret = append(ret, perMessageTest{
10316 messageType: typeCertificateRequest,
10317 test: testCase{
10318 name: "TLS13-CertificateRequest",
10319 config: Config{
10320 MaxVersion: VersionTLS13,
10321 ClientAuth: RequireAnyClientCert,
10322 },
10323 },
10324 })
10325
10326 ret = append(ret, perMessageTest{
10327 messageType: typeCertificate,
10328 test: testCase{
10329 name: "TLS13-ServerCertificate",
10330 config: Config{
10331 MaxVersion: VersionTLS13,
10332 },
10333 },
10334 })
10335
10336 ret = append(ret, perMessageTest{
10337 messageType: typeCertificateVerify,
10338 test: testCase{
10339 name: "TLS13-ServerCertificateVerify",
10340 config: Config{
10341 MaxVersion: VersionTLS13,
10342 },
10343 },
10344 })
10345
10346 ret = append(ret, perMessageTest{
10347 messageType: typeFinished,
10348 test: testCase{
10349 name: "TLS13-ServerFinished",
10350 config: Config{
10351 MaxVersion: VersionTLS13,
10352 },
10353 },
10354 })
10355
10356 ret = append(ret, perMessageTest{
10357 messageType: typeCertificate,
10358 test: testCase{
10359 testType: serverTest,
10360 name: "TLS13-ClientCertificate",
10361 config: Config{
10362 Certificates: []Certificate{rsaCertificate},
10363 MaxVersion: VersionTLS13,
10364 },
10365 flags: []string{"-require-any-client-certificate"},
10366 },
10367 })
10368
10369 ret = append(ret, perMessageTest{
10370 messageType: typeCertificateVerify,
10371 test: testCase{
10372 testType: serverTest,
10373 name: "TLS13-ClientCertificateVerify",
10374 config: Config{
10375 Certificates: []Certificate{rsaCertificate},
10376 MaxVersion: VersionTLS13,
10377 },
10378 flags: []string{"-require-any-client-certificate"},
10379 },
10380 })
10381
10382 ret = append(ret, perMessageTest{
10383 messageType: typeFinished,
10384 test: testCase{
10385 testType: serverTest,
10386 name: "TLS13-ClientFinished",
10387 config: Config{
10388 MaxVersion: VersionTLS13,
10389 },
10390 },
10391 })
10392
10393 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010394}
10395
David Benjamincd2c8062016-09-09 11:28:16 -040010396func addWrongMessageTypeTests() {
10397 for _, t := range makePerMessageTests() {
10398 t.test.name = "WrongMessageType-" + t.test.name
10399 t.test.config.Bugs.SendWrongMessageType = t.messageType
10400 t.test.shouldFail = true
10401 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10402 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010403
David Benjamincd2c8062016-09-09 11:28:16 -040010404 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10405 // In TLS 1.3, a bad ServerHello means the client sends
10406 // an unencrypted alert while the server expects
10407 // encryption, so the alert is not readable by runner.
10408 t.test.expectedLocalError = "local error: bad record MAC"
10409 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010410
David Benjamincd2c8062016-09-09 11:28:16 -040010411 testCases = append(testCases, t.test)
10412 }
David Benjaminebacdee2017-04-08 11:00:45 -040010413
10414 // The processing order for TLS 1.3 version negotiation is such that one
10415 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10416 // TLS 1.2. Test that we do not do this.
10417 testCases = append(testCases, testCase{
10418 name: "SendServerHelloAsHelloRetryRequest",
10419 config: Config{
10420 MaxVersion: VersionTLS12,
10421 Bugs: ProtocolBugs{
10422 SendServerHelloAsHelloRetryRequest: true,
10423 },
10424 },
10425 shouldFail: true,
10426 expectedError: ":UNEXPECTED_MESSAGE:",
10427 expectedLocalError: "remote error: unexpected message",
10428 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010429}
10430
David Benjamin639846e2016-09-09 11:41:18 -040010431func addTrailingMessageDataTests() {
10432 for _, t := range makePerMessageTests() {
10433 t.test.name = "TrailingMessageData-" + t.test.name
10434 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10435 t.test.shouldFail = true
10436 t.test.expectedError = ":DECODE_ERROR:"
10437 t.test.expectedLocalError = "remote error: error decoding message"
10438
10439 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10440 // In TLS 1.3, a bad ServerHello means the client sends
10441 // an unencrypted alert while the server expects
10442 // encryption, so the alert is not readable by runner.
10443 t.test.expectedLocalError = "local error: bad record MAC"
10444 }
10445
10446 if t.messageType == typeFinished {
10447 // Bad Finished messages read as the verify data having
10448 // the wrong length.
10449 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10450 t.test.expectedLocalError = "remote error: error decrypting message"
10451 }
10452
10453 testCases = append(testCases, t.test)
10454 }
10455}
10456
Steven Valdez143e8b32016-07-11 13:19:03 -040010457func addTLS13HandshakeTests() {
10458 testCases = append(testCases, testCase{
10459 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010460 name: "NegotiatePSKResumption-TLS13",
10461 config: Config{
10462 MaxVersion: VersionTLS13,
10463 Bugs: ProtocolBugs{
10464 NegotiatePSKResumption: true,
10465 },
10466 },
10467 resumeSession: true,
10468 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010469 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010470 })
10471
10472 testCases = append(testCases, testCase{
10473 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010474 name: "MissingKeyShare-Client",
10475 config: Config{
10476 MaxVersion: VersionTLS13,
10477 Bugs: ProtocolBugs{
10478 MissingKeyShare: true,
10479 },
10480 },
10481 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010482 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010483 })
10484
10485 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010486 testType: serverTest,
10487 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010488 config: Config{
10489 MaxVersion: VersionTLS13,
10490 Bugs: ProtocolBugs{
10491 MissingKeyShare: true,
10492 },
10493 },
10494 shouldFail: true,
10495 expectedError: ":MISSING_KEY_SHARE:",
10496 })
10497
10498 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010499 testType: serverTest,
10500 name: "DuplicateKeyShares",
10501 config: Config{
10502 MaxVersion: VersionTLS13,
10503 Bugs: ProtocolBugs{
10504 DuplicateKeyShares: true,
10505 },
10506 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010507 shouldFail: true,
10508 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010509 })
10510
10511 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010512 testType: serverTest,
10513 name: "SkipEarlyData",
10514 config: Config{
10515 MaxVersion: VersionTLS13,
10516 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010517 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010518 },
10519 },
10520 })
10521
10522 testCases = append(testCases, testCase{
10523 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010524 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010525 config: Config{
10526 MaxVersion: VersionTLS13,
10527 TLS13Variant: TLS13Experiment,
10528 Bugs: ProtocolBugs{
10529 SendFakeEarlyDataLength: 4,
10530 },
10531 },
10532 flags: []string{"-tls13-variant", "1"},
10533 })
10534
10535 testCases = append(testCases, testCase{
10536 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010537 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10538 config: Config{
10539 MaxVersion: VersionTLS13,
10540 TLS13Variant: TLS13RecordTypeExperiment,
10541 Bugs: ProtocolBugs{
10542 SendFakeEarlyDataLength: 4,
10543 },
10544 },
10545 flags: []string{"-tls13-variant", "2"},
10546 })
10547
10548 testCases = append(testCases, testCase{
10549 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010550 name: "SkipEarlyData-OmitEarlyDataExtension",
10551 config: Config{
10552 MaxVersion: VersionTLS13,
10553 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010554 SendFakeEarlyDataLength: 4,
10555 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010556 },
10557 },
10558 shouldFail: true,
10559 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10560 })
10561
10562 testCases = append(testCases, testCase{
10563 testType: serverTest,
10564 name: "SkipEarlyData-TooMuchData",
10565 config: Config{
10566 MaxVersion: VersionTLS13,
10567 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010568 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010569 },
10570 },
10571 shouldFail: true,
10572 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10573 })
10574
10575 testCases = append(testCases, testCase{
10576 testType: serverTest,
10577 name: "SkipEarlyData-Interleaved",
10578 config: Config{
10579 MaxVersion: VersionTLS13,
10580 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010581 SendFakeEarlyDataLength: 4,
10582 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010583 },
10584 },
10585 shouldFail: true,
10586 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10587 })
10588
10589 testCases = append(testCases, testCase{
10590 testType: serverTest,
10591 name: "SkipEarlyData-EarlyDataInTLS12",
10592 config: Config{
10593 MaxVersion: VersionTLS13,
10594 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010595 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010596 },
10597 },
10598 shouldFail: true,
10599 expectedError: ":UNEXPECTED_RECORD:",
10600 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10601 })
10602
10603 testCases = append(testCases, testCase{
10604 testType: serverTest,
10605 name: "SkipEarlyData-HRR",
10606 config: Config{
10607 MaxVersion: VersionTLS13,
10608 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010609 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010610 },
10611 DefaultCurves: []CurveID{},
10612 },
10613 })
10614
10615 testCases = append(testCases, testCase{
10616 testType: serverTest,
10617 name: "SkipEarlyData-HRR-Interleaved",
10618 config: Config{
10619 MaxVersion: VersionTLS13,
10620 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010621 SendFakeEarlyDataLength: 4,
10622 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010623 },
10624 DefaultCurves: []CurveID{},
10625 },
10626 shouldFail: true,
10627 expectedError: ":UNEXPECTED_RECORD:",
10628 })
10629
10630 testCases = append(testCases, testCase{
10631 testType: serverTest,
10632 name: "SkipEarlyData-HRR-TooMuchData",
10633 config: Config{
10634 MaxVersion: VersionTLS13,
10635 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010636 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010637 },
10638 DefaultCurves: []CurveID{},
10639 },
10640 shouldFail: true,
10641 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10642 })
10643
10644 // Test that skipping early data looking for cleartext correctly
10645 // processes an alert record.
10646 testCases = append(testCases, testCase{
10647 testType: serverTest,
10648 name: "SkipEarlyData-HRR-FatalAlert",
10649 config: Config{
10650 MaxVersion: VersionTLS13,
10651 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010652 SendEarlyAlert: true,
10653 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010654 },
10655 DefaultCurves: []CurveID{},
10656 },
10657 shouldFail: true,
10658 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10659 })
10660
10661 testCases = append(testCases, testCase{
10662 testType: serverTest,
10663 name: "SkipEarlyData-SecondClientHelloEarlyData",
10664 config: Config{
10665 MaxVersion: VersionTLS13,
10666 Bugs: ProtocolBugs{
10667 SendEarlyDataOnSecondClientHello: true,
10668 },
10669 DefaultCurves: []CurveID{},
10670 },
10671 shouldFail: true,
10672 expectedLocalError: "remote error: bad record MAC",
10673 })
10674
10675 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010676 testType: clientTest,
10677 name: "EmptyEncryptedExtensions",
10678 config: Config{
10679 MaxVersion: VersionTLS13,
10680 Bugs: ProtocolBugs{
10681 EmptyEncryptedExtensions: true,
10682 },
10683 },
10684 shouldFail: true,
10685 expectedLocalError: "remote error: error decoding message",
10686 })
10687
10688 testCases = append(testCases, testCase{
10689 testType: clientTest,
10690 name: "EncryptedExtensionsWithKeyShare",
10691 config: Config{
10692 MaxVersion: VersionTLS13,
10693 Bugs: ProtocolBugs{
10694 EncryptedExtensionsWithKeyShare: true,
10695 },
10696 },
10697 shouldFail: true,
10698 expectedLocalError: "remote error: unsupported extension",
10699 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010700
10701 testCases = append(testCases, testCase{
10702 testType: serverTest,
10703 name: "SendHelloRetryRequest",
10704 config: Config{
10705 MaxVersion: VersionTLS13,
10706 // Require a HelloRetryRequest for every curve.
10707 DefaultCurves: []CurveID{},
10708 },
10709 expectedCurveID: CurveX25519,
10710 })
10711
10712 testCases = append(testCases, testCase{
10713 testType: serverTest,
10714 name: "SendHelloRetryRequest-2",
10715 config: Config{
10716 MaxVersion: VersionTLS13,
10717 DefaultCurves: []CurveID{CurveP384},
10718 },
10719 // Although the ClientHello did not predict our preferred curve,
10720 // we always select it whether it is predicted or not.
10721 expectedCurveID: CurveX25519,
10722 })
10723
10724 testCases = append(testCases, testCase{
10725 name: "UnknownCurve-HelloRetryRequest",
10726 config: Config{
10727 MaxVersion: VersionTLS13,
10728 // P-384 requires HelloRetryRequest in BoringSSL.
10729 CurvePreferences: []CurveID{CurveP384},
10730 Bugs: ProtocolBugs{
10731 SendHelloRetryRequestCurve: bogusCurve,
10732 },
10733 },
10734 shouldFail: true,
10735 expectedError: ":WRONG_CURVE:",
10736 })
10737
10738 testCases = append(testCases, testCase{
10739 name: "DisabledCurve-HelloRetryRequest",
10740 config: Config{
10741 MaxVersion: VersionTLS13,
10742 CurvePreferences: []CurveID{CurveP256},
10743 Bugs: ProtocolBugs{
10744 IgnorePeerCurvePreferences: true,
10745 },
10746 },
10747 flags: []string{"-p384-only"},
10748 shouldFail: true,
10749 expectedError: ":WRONG_CURVE:",
10750 })
10751
10752 testCases = append(testCases, testCase{
10753 name: "UnnecessaryHelloRetryRequest",
10754 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010755 MaxVersion: VersionTLS13,
10756 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010757 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010758 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010759 },
10760 },
10761 shouldFail: true,
10762 expectedError: ":WRONG_CURVE:",
10763 })
10764
10765 testCases = append(testCases, testCase{
10766 name: "SecondHelloRetryRequest",
10767 config: Config{
10768 MaxVersion: VersionTLS13,
10769 // P-384 requires HelloRetryRequest in BoringSSL.
10770 CurvePreferences: []CurveID{CurveP384},
10771 Bugs: ProtocolBugs{
10772 SecondHelloRetryRequest: true,
10773 },
10774 },
10775 shouldFail: true,
10776 expectedError: ":UNEXPECTED_MESSAGE:",
10777 })
10778
10779 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010780 name: "HelloRetryRequest-Empty",
10781 config: Config{
10782 MaxVersion: VersionTLS13,
10783 Bugs: ProtocolBugs{
10784 AlwaysSendHelloRetryRequest: true,
10785 },
10786 },
10787 shouldFail: true,
10788 expectedError: ":DECODE_ERROR:",
10789 })
10790
10791 testCases = append(testCases, testCase{
10792 name: "HelloRetryRequest-DuplicateCurve",
10793 config: Config{
10794 MaxVersion: VersionTLS13,
10795 // P-384 requires a HelloRetryRequest against BoringSSL's default
10796 // configuration. Assert this ExpectMissingKeyShare.
10797 CurvePreferences: []CurveID{CurveP384},
10798 Bugs: ProtocolBugs{
10799 ExpectMissingKeyShare: true,
10800 DuplicateHelloRetryRequestExtensions: true,
10801 },
10802 },
10803 shouldFail: true,
10804 expectedError: ":DUPLICATE_EXTENSION:",
10805 expectedLocalError: "remote error: illegal parameter",
10806 })
10807
10808 testCases = append(testCases, testCase{
10809 name: "HelloRetryRequest-Cookie",
10810 config: Config{
10811 MaxVersion: VersionTLS13,
10812 Bugs: ProtocolBugs{
10813 SendHelloRetryRequestCookie: []byte("cookie"),
10814 },
10815 },
10816 })
10817
10818 testCases = append(testCases, testCase{
10819 name: "HelloRetryRequest-DuplicateCookie",
10820 config: Config{
10821 MaxVersion: VersionTLS13,
10822 Bugs: ProtocolBugs{
10823 SendHelloRetryRequestCookie: []byte("cookie"),
10824 DuplicateHelloRetryRequestExtensions: true,
10825 },
10826 },
10827 shouldFail: true,
10828 expectedError: ":DUPLICATE_EXTENSION:",
10829 expectedLocalError: "remote error: illegal parameter",
10830 })
10831
10832 testCases = append(testCases, testCase{
10833 name: "HelloRetryRequest-EmptyCookie",
10834 config: Config{
10835 MaxVersion: VersionTLS13,
10836 Bugs: ProtocolBugs{
10837 SendHelloRetryRequestCookie: []byte{},
10838 },
10839 },
10840 shouldFail: true,
10841 expectedError: ":DECODE_ERROR:",
10842 })
10843
10844 testCases = append(testCases, testCase{
10845 name: "HelloRetryRequest-Cookie-Curve",
10846 config: Config{
10847 MaxVersion: VersionTLS13,
10848 // P-384 requires HelloRetryRequest in BoringSSL.
10849 CurvePreferences: []CurveID{CurveP384},
10850 Bugs: ProtocolBugs{
10851 SendHelloRetryRequestCookie: []byte("cookie"),
10852 ExpectMissingKeyShare: true,
10853 },
10854 },
10855 })
10856
10857 testCases = append(testCases, testCase{
10858 name: "HelloRetryRequest-Unknown",
10859 config: Config{
10860 MaxVersion: VersionTLS13,
10861 Bugs: ProtocolBugs{
10862 CustomHelloRetryRequestExtension: "extension",
10863 },
10864 },
10865 shouldFail: true,
10866 expectedError: ":UNEXPECTED_EXTENSION:",
10867 expectedLocalError: "remote error: unsupported extension",
10868 })
10869
10870 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010871 testType: serverTest,
10872 name: "SecondClientHelloMissingKeyShare",
10873 config: Config{
10874 MaxVersion: VersionTLS13,
10875 DefaultCurves: []CurveID{},
10876 Bugs: ProtocolBugs{
10877 SecondClientHelloMissingKeyShare: true,
10878 },
10879 },
10880 shouldFail: true,
10881 expectedError: ":MISSING_KEY_SHARE:",
10882 })
10883
10884 testCases = append(testCases, testCase{
10885 testType: serverTest,
10886 name: "SecondClientHelloWrongCurve",
10887 config: Config{
10888 MaxVersion: VersionTLS13,
10889 DefaultCurves: []CurveID{},
10890 Bugs: ProtocolBugs{
10891 MisinterpretHelloRetryRequestCurve: CurveP521,
10892 },
10893 },
10894 shouldFail: true,
10895 expectedError: ":WRONG_CURVE:",
10896 })
10897
10898 testCases = append(testCases, testCase{
10899 name: "HelloRetryRequestVersionMismatch",
10900 config: Config{
10901 MaxVersion: VersionTLS13,
10902 // P-384 requires HelloRetryRequest in BoringSSL.
10903 CurvePreferences: []CurveID{CurveP384},
10904 Bugs: ProtocolBugs{
10905 SendServerHelloVersion: 0x0305,
10906 },
10907 },
10908 shouldFail: true,
10909 expectedError: ":WRONG_VERSION_NUMBER:",
10910 })
10911
10912 testCases = append(testCases, testCase{
10913 name: "HelloRetryRequestCurveMismatch",
10914 config: Config{
10915 MaxVersion: VersionTLS13,
10916 // P-384 requires HelloRetryRequest in BoringSSL.
10917 CurvePreferences: []CurveID{CurveP384},
10918 Bugs: ProtocolBugs{
10919 // Send P-384 (correct) in the HelloRetryRequest.
10920 SendHelloRetryRequestCurve: CurveP384,
10921 // But send P-256 in the ServerHello.
10922 SendCurve: CurveP256,
10923 },
10924 },
10925 shouldFail: true,
10926 expectedError: ":WRONG_CURVE:",
10927 })
10928
10929 // Test the server selecting a curve that requires a HelloRetryRequest
10930 // without sending it.
10931 testCases = append(testCases, testCase{
10932 name: "SkipHelloRetryRequest",
10933 config: Config{
10934 MaxVersion: VersionTLS13,
10935 // P-384 requires HelloRetryRequest in BoringSSL.
10936 CurvePreferences: []CurveID{CurveP384},
10937 Bugs: ProtocolBugs{
10938 SkipHelloRetryRequest: true,
10939 },
10940 },
10941 shouldFail: true,
10942 expectedError: ":WRONG_CURVE:",
10943 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010944
10945 testCases = append(testCases, testCase{
10946 name: "TLS13-RequestContextInHandshake",
10947 config: Config{
10948 MaxVersion: VersionTLS13,
10949 MinVersion: VersionTLS13,
10950 ClientAuth: RequireAnyClientCert,
10951 Bugs: ProtocolBugs{
10952 SendRequestContext: []byte("request context"),
10953 },
10954 },
10955 flags: []string{
10956 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10957 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10958 },
10959 shouldFail: true,
10960 expectedError: ":DECODE_ERROR:",
10961 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010962
10963 testCases = append(testCases, testCase{
10964 testType: serverTest,
10965 name: "TLS13-TrailingKeyShareData",
10966 config: Config{
10967 MaxVersion: VersionTLS13,
10968 Bugs: ProtocolBugs{
10969 TrailingKeyShareData: true,
10970 },
10971 },
10972 shouldFail: true,
10973 expectedError: ":DECODE_ERROR:",
10974 })
David Benjamin7f78df42016-10-05 22:33:19 -040010975
10976 testCases = append(testCases, testCase{
10977 name: "TLS13-AlwaysSelectPSKIdentity",
10978 config: Config{
10979 MaxVersion: VersionTLS13,
10980 Bugs: ProtocolBugs{
10981 AlwaysSelectPSKIdentity: true,
10982 },
10983 },
10984 shouldFail: true,
10985 expectedError: ":UNEXPECTED_EXTENSION:",
10986 })
10987
10988 testCases = append(testCases, testCase{
10989 name: "TLS13-InvalidPSKIdentity",
10990 config: Config{
10991 MaxVersion: VersionTLS13,
10992 Bugs: ProtocolBugs{
10993 SelectPSKIdentityOnResume: 1,
10994 },
10995 },
10996 resumeSession: true,
10997 shouldFail: true,
10998 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10999 })
David Benjamin1286bee2016-10-07 15:25:06 -040011000
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011001 testCases = append(testCases, testCase{
11002 testType: serverTest,
11003 name: "TLS13-ExtraPSKIdentity",
11004 config: Config{
11005 MaxVersion: VersionTLS13,
11006 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011007 ExtraPSKIdentity: true,
11008 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011009 },
11010 },
11011 resumeSession: true,
11012 })
11013
David Benjamin1286bee2016-10-07 15:25:06 -040011014 // Test that unknown NewSessionTicket extensions are tolerated.
11015 testCases = append(testCases, testCase{
11016 name: "TLS13-CustomTicketExtension",
11017 config: Config{
11018 MaxVersion: VersionTLS13,
11019 Bugs: ProtocolBugs{
11020 CustomTicketExtension: "1234",
11021 },
11022 },
11023 })
Steven Valdez2d850622017-01-11 11:34:52 -050011024
Steven Valdez2d850622017-01-11 11:34:52 -050011025 testCases = append(testCases, testCase{
11026 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011027 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011028 config: Config{
11029 MaxVersion: VersionTLS13,
11030 MaxEarlyDataSize: 16384,
11031 },
11032 resumeConfig: &Config{
11033 MaxVersion: VersionTLS13,
11034 MaxEarlyDataSize: 16384,
11035 Bugs: ProtocolBugs{
11036 AlwaysRejectEarlyData: true,
11037 },
11038 },
11039 resumeSession: true,
11040 flags: []string{
11041 "-enable-early-data",
11042 "-expect-early-data-info",
11043 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011044 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011045 },
11046 })
11047
11048 testCases = append(testCases, testCase{
11049 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011050 name: "TLS13Experiment-EarlyData-Reject-Client",
11051 config: Config{
11052 MaxVersion: VersionTLS13,
11053 MaxEarlyDataSize: 16384,
11054 TLS13Variant: TLS13Experiment,
11055 },
11056 resumeConfig: &Config{
11057 MaxVersion: VersionTLS13,
11058 TLS13Variant: TLS13Experiment,
11059 MaxEarlyDataSize: 16384,
11060 Bugs: ProtocolBugs{
11061 AlwaysRejectEarlyData: true,
11062 },
11063 },
11064 resumeSession: true,
11065 flags: []string{
11066 "-enable-early-data",
11067 "-expect-early-data-info",
11068 "-expect-reject-early-data",
11069 "-on-resume-shim-writes-first",
11070 "-tls13-variant", "1",
11071 },
11072 })
11073
11074 testCases = append(testCases, testCase{
11075 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011076 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11077 config: Config{
11078 MaxVersion: VersionTLS13,
11079 MaxEarlyDataSize: 16384,
11080 TLS13Variant: TLS13RecordTypeExperiment,
11081 },
11082 resumeConfig: &Config{
11083 MaxVersion: VersionTLS13,
11084 TLS13Variant: TLS13RecordTypeExperiment,
11085 MaxEarlyDataSize: 16384,
11086 Bugs: ProtocolBugs{
11087 AlwaysRejectEarlyData: true,
11088 },
11089 },
11090 resumeSession: true,
11091 flags: []string{
11092 "-enable-early-data",
11093 "-expect-early-data-info",
11094 "-expect-reject-early-data",
11095 "-on-resume-shim-writes-first",
11096 "-tls13-variant", "2",
11097 },
11098 })
11099
11100 testCases = append(testCases, testCase{
11101 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011102 name: "TLS13-EarlyData-RejectTicket-Client",
11103 config: Config{
11104 MaxVersion: VersionTLS13,
11105 MaxEarlyDataSize: 16384,
11106 Certificates: []Certificate{rsaCertificate},
11107 },
11108 resumeConfig: &Config{
11109 MaxVersion: VersionTLS13,
11110 MaxEarlyDataSize: 16384,
11111 Certificates: []Certificate{ecdsaP256Certificate},
11112 SessionTicketsDisabled: true,
11113 },
11114 resumeSession: true,
11115 expectResumeRejected: true,
11116 flags: []string{
11117 "-enable-early-data",
11118 "-expect-early-data-info",
11119 "-expect-reject-early-data",
11120 "-on-resume-shim-writes-first",
11121 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11122 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11123 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11124 // Session tickets are disabled, so the runner will not send a ticket.
11125 "-on-retry-expect-no-session",
11126 },
11127 })
11128
11129 testCases = append(testCases, testCase{
11130 testType: clientTest,
11131 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011132 config: Config{
11133 MaxVersion: VersionTLS13,
11134 MaxEarlyDataSize: 16384,
11135 },
11136 resumeConfig: &Config{
11137 MaxVersion: VersionTLS13,
11138 MaxEarlyDataSize: 16384,
11139 Bugs: ProtocolBugs{
11140 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11141 },
11142 },
11143 resumeSession: true,
11144 flags: []string{
11145 "-enable-early-data",
11146 "-expect-early-data-info",
11147 "-expect-reject-early-data",
11148 },
11149 })
11150
11151 // The client must check the server does not send the early_data
11152 // extension while rejecting the session.
11153 testCases = append(testCases, testCase{
11154 testType: clientTest,
11155 name: "TLS13-EarlyDataWithoutResume-Client",
11156 config: Config{
11157 MaxVersion: VersionTLS13,
11158 MaxEarlyDataSize: 16384,
11159 },
11160 resumeConfig: &Config{
11161 MaxVersion: VersionTLS13,
11162 SessionTicketsDisabled: true,
11163 Bugs: ProtocolBugs{
11164 SendEarlyDataExtension: true,
11165 },
11166 },
11167 resumeSession: true,
11168 flags: []string{
11169 "-enable-early-data",
11170 "-expect-early-data-info",
11171 },
11172 shouldFail: true,
11173 expectedError: ":UNEXPECTED_EXTENSION:",
11174 })
11175
11176 // The client must fail with a dedicated error code if the server
11177 // responds with TLS 1.2 when offering 0-RTT.
11178 testCases = append(testCases, testCase{
11179 testType: clientTest,
11180 name: "TLS13-EarlyDataVersionDowngrade-Client",
11181 config: Config{
11182 MaxVersion: VersionTLS13,
11183 MaxEarlyDataSize: 16384,
11184 },
11185 resumeConfig: &Config{
11186 MaxVersion: VersionTLS12,
11187 },
11188 resumeSession: true,
11189 flags: []string{
11190 "-enable-early-data",
11191 "-expect-early-data-info",
11192 },
11193 shouldFail: true,
11194 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11195 })
11196
11197 // Test that the client rejects an (unsolicited) early_data extension if
11198 // the server sent an HRR.
11199 testCases = append(testCases, testCase{
11200 testType: clientTest,
11201 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11202 config: Config{
11203 MaxVersion: VersionTLS13,
11204 MaxEarlyDataSize: 16384,
11205 },
11206 resumeConfig: &Config{
11207 MaxVersion: VersionTLS13,
11208 MaxEarlyDataSize: 16384,
11209 Bugs: ProtocolBugs{
11210 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11211 SendEarlyDataExtension: true,
11212 },
11213 },
11214 resumeSession: true,
11215 flags: []string{
11216 "-enable-early-data",
11217 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011218 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011219 },
11220 shouldFail: true,
11221 expectedError: ":UNEXPECTED_EXTENSION:",
11222 })
11223
11224 fooString := "foo"
11225 barString := "bar"
11226
11227 // Test that the client reports the correct ALPN after a 0-RTT reject
11228 // that changed it.
11229 testCases = append(testCases, testCase{
11230 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011231 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011232 config: Config{
11233 MaxVersion: VersionTLS13,
11234 MaxEarlyDataSize: 16384,
11235 Bugs: ProtocolBugs{
11236 ALPNProtocol: &fooString,
11237 },
11238 },
11239 resumeConfig: &Config{
11240 MaxVersion: VersionTLS13,
11241 MaxEarlyDataSize: 16384,
11242 Bugs: ProtocolBugs{
11243 ALPNProtocol: &barString,
11244 },
11245 },
11246 resumeSession: true,
11247 flags: []string{
11248 "-advertise-alpn", "\x03foo\x03bar",
11249 "-enable-early-data",
11250 "-expect-early-data-info",
11251 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011252 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011253 "-on-resume-expect-alpn", "foo",
11254 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011255 },
11256 })
11257
11258 // Test that the client reports the correct ALPN after a 0-RTT reject if
11259 // ALPN was omitted from the first connection.
11260 testCases = append(testCases, testCase{
11261 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011262 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011263 config: Config{
11264 MaxVersion: VersionTLS13,
11265 MaxEarlyDataSize: 16384,
11266 },
11267 resumeConfig: &Config{
11268 MaxVersion: VersionTLS13,
11269 MaxEarlyDataSize: 16384,
11270 NextProtos: []string{"foo"},
11271 },
11272 resumeSession: true,
11273 flags: []string{
11274 "-advertise-alpn", "\x03foo\x03bar",
11275 "-enable-early-data",
11276 "-expect-early-data-info",
11277 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011278 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011279 "-on-resume-expect-alpn", "",
11280 "-on-retry-expect-alpn", "foo",
11281 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011282 },
11283 })
11284
11285 // Test that the client reports the correct ALPN after a 0-RTT reject if
11286 // ALPN was omitted from the second connection.
11287 testCases = append(testCases, testCase{
11288 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011289 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011290 config: Config{
11291 MaxVersion: VersionTLS13,
11292 MaxEarlyDataSize: 16384,
11293 NextProtos: []string{"foo"},
11294 },
11295 resumeConfig: &Config{
11296 MaxVersion: VersionTLS13,
11297 MaxEarlyDataSize: 16384,
11298 },
11299 resumeSession: true,
11300 flags: []string{
11301 "-advertise-alpn", "\x03foo\x03bar",
11302 "-enable-early-data",
11303 "-expect-early-data-info",
11304 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011305 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011306 "-on-resume-expect-alpn", "foo",
11307 "-on-retry-expect-alpn", "",
11308 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011309 },
11310 })
11311
11312 // Test that the client enforces ALPN match on 0-RTT accept.
11313 testCases = append(testCases, testCase{
11314 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011315 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011316 config: Config{
11317 MaxVersion: VersionTLS13,
11318 MaxEarlyDataSize: 16384,
11319 Bugs: ProtocolBugs{
11320 ALPNProtocol: &fooString,
11321 },
11322 },
11323 resumeConfig: &Config{
11324 MaxVersion: VersionTLS13,
11325 MaxEarlyDataSize: 16384,
11326 Bugs: ProtocolBugs{
11327 AlwaysAcceptEarlyData: true,
11328 ALPNProtocol: &barString,
11329 },
11330 },
11331 resumeSession: true,
11332 flags: []string{
11333 "-advertise-alpn", "\x03foo\x03bar",
11334 "-enable-early-data",
11335 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011336 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011337 "-on-resume-expect-alpn", "foo",
11338 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011339 },
11340 shouldFail: true,
11341 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11342 })
11343
11344 // Test that the server correctly rejects 0-RTT when the previous
11345 // session did not allow early data on resumption.
11346 testCases = append(testCases, testCase{
11347 testType: serverTest,
11348 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11349 config: Config{
11350 MaxVersion: VersionTLS13,
11351 },
11352 resumeConfig: &Config{
11353 MaxVersion: VersionTLS13,
11354 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011355 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011356 ExpectEarlyDataAccepted: false,
11357 },
11358 },
11359 resumeSession: true,
11360 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011361 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011362 "-expect-reject-early-data",
11363 },
11364 })
11365
11366 // Test that we reject early data where ALPN is omitted from the first
11367 // connection.
11368 testCases = append(testCases, testCase{
11369 testType: serverTest,
11370 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11371 config: Config{
11372 MaxVersion: VersionTLS13,
11373 NextProtos: []string{},
11374 },
11375 resumeConfig: &Config{
11376 MaxVersion: VersionTLS13,
11377 NextProtos: []string{"foo"},
11378 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011379 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011380 ExpectEarlyDataAccepted: false,
11381 },
11382 },
11383 resumeSession: true,
11384 flags: []string{
11385 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011386 "-on-initial-select-alpn", "",
11387 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011388 },
11389 })
11390
11391 // Test that we reject early data where ALPN is omitted from the second
11392 // connection.
11393 testCases = append(testCases, testCase{
11394 testType: serverTest,
11395 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11396 config: Config{
11397 MaxVersion: VersionTLS13,
11398 NextProtos: []string{"foo"},
11399 },
11400 resumeConfig: &Config{
11401 MaxVersion: VersionTLS13,
11402 NextProtos: []string{},
11403 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011404 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011405 ExpectEarlyDataAccepted: false,
11406 },
11407 },
11408 resumeSession: true,
11409 flags: []string{
11410 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011411 "-on-initial-select-alpn", "foo",
11412 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011413 },
11414 })
11415
11416 // Test that we reject early data with mismatched ALPN.
11417 testCases = append(testCases, testCase{
11418 testType: serverTest,
11419 name: "TLS13-EarlyData-ALPNMismatch-Server",
11420 config: Config{
11421 MaxVersion: VersionTLS13,
11422 NextProtos: []string{"foo"},
11423 },
11424 resumeConfig: &Config{
11425 MaxVersion: VersionTLS13,
11426 NextProtos: []string{"bar"},
11427 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011428 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011429 ExpectEarlyDataAccepted: false,
11430 },
11431 },
11432 resumeSession: true,
11433 flags: []string{
11434 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011435 "-on-initial-select-alpn", "foo",
11436 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011437 },
11438 })
11439
David Benjamin6bb507b2017-03-29 16:35:57 -050011440 // Test that the client offering 0-RTT and Channel ID forbids the server
11441 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011442 testCases = append(testCases, testCase{
11443 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011444 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011445 config: Config{
11446 MaxVersion: VersionTLS13,
11447 MaxEarlyDataSize: 16384,
11448 RequestChannelID: true,
11449 },
11450 resumeSession: true,
11451 expectChannelID: true,
11452 shouldFail: true,
11453 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11454 flags: []string{
11455 "-enable-early-data",
11456 "-expect-early-data-info",
11457 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11458 },
11459 })
11460
David Benjamin6bb507b2017-03-29 16:35:57 -050011461 // Test that the client offering Channel ID and 0-RTT allows the server
11462 // to decline 0-RTT.
11463 testCases = append(testCases, testCase{
11464 testType: clientTest,
11465 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11466 config: Config{
11467 MaxVersion: VersionTLS13,
11468 MaxEarlyDataSize: 16384,
11469 RequestChannelID: true,
11470 Bugs: ProtocolBugs{
11471 AlwaysRejectEarlyData: true,
11472 },
11473 },
11474 resumeSession: true,
11475 expectChannelID: true,
11476 flags: []string{
11477 "-enable-early-data",
11478 "-expect-early-data-info",
11479 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11480 "-expect-reject-early-data",
11481 },
11482 })
11483
11484 // Test that the client offering Channel ID and 0-RTT allows the server
11485 // to decline Channel ID.
11486 testCases = append(testCases, testCase{
11487 testType: clientTest,
11488 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11489 config: Config{
11490 MaxVersion: VersionTLS13,
11491 MaxEarlyDataSize: 16384,
11492 },
11493 resumeSession: true,
11494 flags: []string{
11495 "-enable-early-data",
11496 "-expect-early-data-info",
11497 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11498 "-expect-accept-early-data",
11499 },
11500 })
11501
11502 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11503 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011504 testCases = append(testCases, testCase{
11505 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011506 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011507 config: Config{
11508 MaxVersion: VersionTLS13,
11509 ChannelID: channelIDKey,
11510 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011511 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011512 ExpectEarlyDataAccepted: false,
11513 },
11514 },
11515 resumeSession: true,
11516 expectChannelID: true,
11517 flags: []string{
11518 "-enable-early-data",
11519 "-expect-reject-early-data",
11520 "-expect-channel-id",
11521 base64.StdEncoding.EncodeToString(channelIDBytes),
11522 },
11523 })
11524
David Benjamin6bb507b2017-03-29 16:35:57 -050011525 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11526 // if not offered Channel ID.
11527 testCases = append(testCases, testCase{
11528 testType: serverTest,
11529 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11530 config: Config{
11531 MaxVersion: VersionTLS13,
11532 Bugs: ProtocolBugs{
11533 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11534 ExpectEarlyDataAccepted: true,
11535 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11536 },
11537 },
11538 resumeSession: true,
11539 expectChannelID: false,
11540 flags: []string{
11541 "-enable-early-data",
11542 "-expect-accept-early-data",
11543 "-enable-channel-id",
11544 },
11545 })
11546
David Benjamin32c89272017-03-26 13:54:21 -050011547 // Test that the server rejects 0-RTT streams without end_of_early_data.
11548 // The subsequent records should fail to decrypt.
11549 testCases = append(testCases, testCase{
11550 testType: serverTest,
11551 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11552 config: Config{
11553 MaxVersion: VersionTLS13,
11554 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011555 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011556 ExpectEarlyDataAccepted: true,
11557 SkipEndOfEarlyData: true,
11558 },
11559 },
11560 resumeSession: true,
11561 flags: []string{"-enable-early-data"},
11562 shouldFail: true,
11563 expectedLocalError: "remote error: bad record MAC",
11564 expectedError: ":BAD_DECRYPT:",
11565 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011566
11567 testCases = append(testCases, testCase{
11568 testType: serverTest,
11569 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11570 config: Config{
11571 MaxVersion: VersionTLS13,
11572 },
11573 resumeConfig: &Config{
11574 MaxVersion: VersionTLS13,
11575 Bugs: ProtocolBugs{
11576 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11577 SendStrayEarlyHandshake: true,
11578 ExpectEarlyDataAccepted: true},
11579 },
11580 resumeSession: true,
11581 shouldFail: true,
11582 expectedError: ":UNEXPECTED_RECORD:",
11583 expectedLocalError: "remote error: unexpected message",
11584 flags: []string{
11585 "-enable-early-data",
11586 },
11587 })
David Benjamind9cbb532017-07-07 13:17:19 -040011588
11589 // Test that the client reports TLS 1.3 as the version while sending
11590 // early data.
11591 testCases = append(testCases, testCase{
11592 testType: clientTest,
11593 name: "TLS13-EarlyData-Client-VersionAPI",
11594 config: Config{
11595 MaxVersion: VersionTLS13,
11596 MaxEarlyDataSize: 16384,
11597 },
11598 resumeSession: true,
11599 flags: []string{
11600 "-enable-early-data",
11601 "-expect-early-data-info",
11602 "-expect-accept-early-data",
11603 "-expect-version", strconv.Itoa(VersionTLS13),
11604 },
11605 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011606}
11607
David Benjaminabbbee12016-10-31 19:20:42 -040011608func addTLS13CipherPreferenceTests() {
11609 // Test that client preference is honored if the shim has AES hardware
11610 // and ChaCha20-Poly1305 is preferred otherwise.
11611 testCases = append(testCases, testCase{
11612 testType: serverTest,
11613 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11614 config: Config{
11615 MaxVersion: VersionTLS13,
11616 CipherSuites: []uint16{
11617 TLS_CHACHA20_POLY1305_SHA256,
11618 TLS_AES_128_GCM_SHA256,
11619 },
11620 },
11621 flags: []string{
11622 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11623 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11624 },
11625 })
11626
11627 testCases = append(testCases, testCase{
11628 testType: serverTest,
11629 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11630 config: Config{
11631 MaxVersion: VersionTLS13,
11632 CipherSuites: []uint16{
11633 TLS_AES_128_GCM_SHA256,
11634 TLS_CHACHA20_POLY1305_SHA256,
11635 },
11636 },
11637 flags: []string{
11638 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11639 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11640 },
11641 })
11642
11643 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11644 // whether it has AES hardware.
11645 testCases = append(testCases, testCase{
11646 name: "TLS13-CipherPreference-Client",
11647 config: Config{
11648 MaxVersion: VersionTLS13,
11649 // Use the client cipher order. (This is the default but
11650 // is listed to be explicit.)
11651 PreferServerCipherSuites: false,
11652 },
11653 flags: []string{
11654 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11655 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11656 },
11657 })
11658}
11659
David Benjaminf3fbade2016-09-19 13:08:16 -040011660func addPeekTests() {
11661 // Test SSL_peek works, including on empty records.
11662 testCases = append(testCases, testCase{
11663 name: "Peek-Basic",
11664 sendEmptyRecords: 1,
11665 flags: []string{"-peek-then-read"},
11666 })
11667
11668 // Test SSL_peek can drive the initial handshake.
11669 testCases = append(testCases, testCase{
11670 name: "Peek-ImplicitHandshake",
11671 flags: []string{
11672 "-peek-then-read",
11673 "-implicit-handshake",
11674 },
11675 })
11676
11677 // Test SSL_peek can discover and drive a renegotiation.
11678 testCases = append(testCases, testCase{
11679 name: "Peek-Renegotiate",
11680 config: Config{
11681 MaxVersion: VersionTLS12,
11682 },
11683 renegotiate: 1,
11684 flags: []string{
11685 "-peek-then-read",
11686 "-renegotiate-freely",
11687 "-expect-total-renegotiations", "1",
11688 },
11689 })
11690
11691 // Test SSL_peek can discover a close_notify.
11692 testCases = append(testCases, testCase{
11693 name: "Peek-Shutdown",
11694 config: Config{
11695 Bugs: ProtocolBugs{
11696 ExpectCloseNotify: true,
11697 },
11698 },
11699 flags: []string{
11700 "-peek-then-read",
11701 "-check-close-notify",
11702 },
11703 })
11704
11705 // Test SSL_peek can discover an alert.
11706 testCases = append(testCases, testCase{
11707 name: "Peek-Alert",
11708 config: Config{
11709 Bugs: ProtocolBugs{
11710 SendSpuriousAlert: alertRecordOverflow,
11711 },
11712 },
11713 flags: []string{"-peek-then-read"},
11714 shouldFail: true,
11715 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11716 })
11717
11718 // Test SSL_peek can handle KeyUpdate.
11719 testCases = append(testCases, testCase{
11720 name: "Peek-KeyUpdate",
11721 config: Config{
11722 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011723 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011724 sendKeyUpdates: 1,
11725 keyUpdateRequest: keyUpdateNotRequested,
11726 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011727 })
11728}
11729
David Benjamine6f22212016-11-08 14:28:24 -050011730func addRecordVersionTests() {
11731 for _, ver := range tlsVersions {
11732 // Test that the record version is enforced.
11733 testCases = append(testCases, testCase{
11734 name: "CheckRecordVersion-" + ver.name,
11735 config: Config{
11736 MinVersion: ver.version,
11737 MaxVersion: ver.version,
11738 Bugs: ProtocolBugs{
11739 SendRecordVersion: 0x03ff,
11740 },
11741 },
David Benjamina5022392017-07-10 17:40:39 -040011742 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011743 shouldFail: true,
11744 expectedError: ":WRONG_VERSION_NUMBER:",
11745 })
11746
11747 // Test that the ClientHello may use any record version, for
11748 // compatibility reasons.
11749 testCases = append(testCases, testCase{
11750 testType: serverTest,
11751 name: "LooseInitialRecordVersion-" + ver.name,
11752 config: Config{
11753 MinVersion: ver.version,
11754 MaxVersion: ver.version,
11755 Bugs: ProtocolBugs{
11756 SendInitialRecordVersion: 0x03ff,
11757 },
11758 },
David Benjamina5022392017-07-10 17:40:39 -040011759 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011760 })
11761
11762 // Test that garbage ClientHello record versions are rejected.
11763 testCases = append(testCases, testCase{
11764 testType: serverTest,
11765 name: "GarbageInitialRecordVersion-" + ver.name,
11766 config: Config{
11767 MinVersion: ver.version,
11768 MaxVersion: ver.version,
11769 Bugs: ProtocolBugs{
11770 SendInitialRecordVersion: 0xffff,
11771 },
11772 },
David Benjamina5022392017-07-10 17:40:39 -040011773 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011774 shouldFail: true,
11775 expectedError: ":WRONG_VERSION_NUMBER:",
11776 })
11777 }
11778}
11779
David Benjamin2c516452016-11-15 10:16:54 +090011780func addCertificateTests() {
11781 // Test that a certificate chain with intermediate may be sent and
11782 // received as both client and server.
11783 for _, ver := range tlsVersions {
11784 testCases = append(testCases, testCase{
11785 testType: clientTest,
11786 name: "SendReceiveIntermediate-Client-" + ver.name,
11787 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011788 MinVersion: ver.version,
11789 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011790 Certificates: []Certificate{rsaChainCertificate},
11791 ClientAuth: RequireAnyClientCert,
11792 },
David Benjamina5022392017-07-10 17:40:39 -040011793 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011794 expectPeerCertificate: &rsaChainCertificate,
11795 flags: []string{
11796 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11797 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11798 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11799 },
11800 })
11801
11802 testCases = append(testCases, testCase{
11803 testType: serverTest,
11804 name: "SendReceiveIntermediate-Server-" + ver.name,
11805 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011806 MinVersion: ver.version,
11807 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011808 Certificates: []Certificate{rsaChainCertificate},
11809 },
David Benjamina5022392017-07-10 17:40:39 -040011810 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011811 expectPeerCertificate: &rsaChainCertificate,
11812 flags: []string{
11813 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11814 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11815 "-require-any-client-certificate",
11816 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11817 },
11818 })
11819 }
11820}
11821
David Benjaminbbaf3672016-11-17 10:53:09 +090011822func addRetainOnlySHA256ClientCertTests() {
11823 for _, ver := range tlsVersions {
11824 // Test that enabling
11825 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11826 // actually requesting a client certificate is a no-op.
11827 testCases = append(testCases, testCase{
11828 testType: serverTest,
11829 name: "RetainOnlySHA256-NoCert-" + ver.name,
11830 config: Config{
11831 MinVersion: ver.version,
11832 MaxVersion: ver.version,
11833 },
David Benjamina5022392017-07-10 17:40:39 -040011834 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011835 flags: []string{
11836 "-retain-only-sha256-client-cert-initial",
11837 "-retain-only-sha256-client-cert-resume",
11838 },
11839 resumeSession: true,
11840 })
11841
11842 // Test that when retaining only a SHA-256 certificate is
11843 // enabled, the hash appears as expected.
11844 testCases = append(testCases, testCase{
11845 testType: serverTest,
11846 name: "RetainOnlySHA256-Cert-" + ver.name,
11847 config: Config{
11848 MinVersion: ver.version,
11849 MaxVersion: ver.version,
11850 Certificates: []Certificate{rsaCertificate},
11851 },
David Benjamina5022392017-07-10 17:40:39 -040011852 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011853 flags: []string{
11854 "-verify-peer",
11855 "-retain-only-sha256-client-cert-initial",
11856 "-retain-only-sha256-client-cert-resume",
11857 "-expect-sha256-client-cert-initial",
11858 "-expect-sha256-client-cert-resume",
11859 },
11860 resumeSession: true,
11861 })
11862
11863 // Test that when the config changes from on to off, a
11864 // resumption is rejected because the server now wants the full
11865 // certificate chain.
11866 testCases = append(testCases, testCase{
11867 testType: serverTest,
11868 name: "RetainOnlySHA256-OnOff-" + ver.name,
11869 config: Config{
11870 MinVersion: ver.version,
11871 MaxVersion: ver.version,
11872 Certificates: []Certificate{rsaCertificate},
11873 },
David Benjamina5022392017-07-10 17:40:39 -040011874 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011875 flags: []string{
11876 "-verify-peer",
11877 "-retain-only-sha256-client-cert-initial",
11878 "-expect-sha256-client-cert-initial",
11879 },
11880 resumeSession: true,
11881 expectResumeRejected: true,
11882 })
11883
11884 // Test that when the config changes from off to on, a
11885 // resumption is rejected because the server now wants just the
11886 // hash.
11887 testCases = append(testCases, testCase{
11888 testType: serverTest,
11889 name: "RetainOnlySHA256-OffOn-" + ver.name,
11890 config: Config{
11891 MinVersion: ver.version,
11892 MaxVersion: ver.version,
11893 Certificates: []Certificate{rsaCertificate},
11894 },
David Benjamina5022392017-07-10 17:40:39 -040011895 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011896 flags: []string{
11897 "-verify-peer",
11898 "-retain-only-sha256-client-cert-resume",
11899 "-expect-sha256-client-cert-resume",
11900 },
11901 resumeSession: true,
11902 expectResumeRejected: true,
11903 })
11904 }
11905}
11906
Adam Langleya4b91982016-12-12 12:05:53 -080011907func addECDSAKeyUsageTests() {
11908 p256 := elliptic.P256()
11909 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11910 if err != nil {
11911 panic(err)
11912 }
11913
11914 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11915 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11916 if err != nil {
11917 panic(err)
11918 }
11919
11920 template := x509.Certificate{
11921 SerialNumber: serialNumber,
11922 Subject: pkix.Name{
11923 Organization: []string{"Acme Co"},
11924 },
11925 NotBefore: time.Now(),
11926 NotAfter: time.Now(),
11927
11928 // An ECC certificate with only the keyAgreement key usgae may
11929 // be used with ECDH, but not ECDSA.
11930 KeyUsage: x509.KeyUsageKeyAgreement,
11931 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11932 BasicConstraintsValid: true,
11933 }
11934
11935 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11936 if err != nil {
11937 panic(err)
11938 }
11939
11940 cert := Certificate{
11941 Certificate: [][]byte{derBytes},
11942 PrivateKey: priv,
11943 }
11944
11945 for _, ver := range tlsVersions {
11946 if ver.version < VersionTLS12 {
11947 continue
11948 }
11949
11950 testCases = append(testCases, testCase{
11951 testType: clientTest,
11952 name: "ECDSAKeyUsage-" + ver.name,
11953 config: Config{
11954 MinVersion: ver.version,
11955 MaxVersion: ver.version,
11956 Certificates: []Certificate{cert},
11957 },
David Benjamina5022392017-07-10 17:40:39 -040011958 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080011959 shouldFail: true,
11960 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11961 })
11962 }
11963}
11964
David Benjamin8c26d752017-03-26 15:13:51 -050011965func addExtraHandshakeTests() {
11966 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11967 // to ensure there is no transport I/O.
11968 testCases = append(testCases, testCase{
11969 testType: clientTest,
11970 name: "ExtraHandshake-Client-TLS12",
11971 config: Config{
11972 MinVersion: VersionTLS12,
11973 MaxVersion: VersionTLS12,
11974 },
11975 flags: []string{
11976 "-async",
11977 "-no-op-extra-handshake",
11978 },
11979 })
11980 testCases = append(testCases, testCase{
11981 testType: serverTest,
11982 name: "ExtraHandshake-Server-TLS12",
11983 config: Config{
11984 MinVersion: VersionTLS12,
11985 MaxVersion: VersionTLS12,
11986 },
11987 flags: []string{
11988 "-async",
11989 "-no-op-extra-handshake",
11990 },
11991 })
11992 testCases = append(testCases, testCase{
11993 testType: clientTest,
11994 name: "ExtraHandshake-Client-TLS13",
11995 config: Config{
11996 MinVersion: VersionTLS13,
11997 MaxVersion: VersionTLS13,
11998 },
11999 flags: []string{
12000 "-async",
12001 "-no-op-extra-handshake",
12002 },
12003 })
12004 testCases = append(testCases, testCase{
12005 testType: serverTest,
12006 name: "ExtraHandshake-Server-TLS13",
12007 config: Config{
12008 MinVersion: VersionTLS13,
12009 MaxVersion: VersionTLS13,
12010 },
12011 flags: []string{
12012 "-async",
12013 "-no-op-extra-handshake",
12014 },
12015 })
12016
12017 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12018 testCases = append(testCases, testCase{
12019 testType: serverTest,
12020 name: "ExtraHandshake-Server-EarlyData-TLS13",
12021 config: Config{
12022 MaxVersion: VersionTLS13,
12023 MinVersion: VersionTLS13,
12024 Bugs: ProtocolBugs{
12025 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12026 ExpectEarlyDataAccepted: true,
12027 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12028 },
12029 },
12030 messageCount: 2,
12031 resumeSession: true,
12032 flags: []string{
12033 "-async",
12034 "-enable-early-data",
12035 "-expect-accept-early-data",
12036 "-no-op-extra-handshake",
12037 },
12038 })
12039
12040 // An extra SSL_do_handshake drives the handshake to completion in False
12041 // Start. We test this by handshaking twice and asserting the False
12042 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12043 // how the test works.
12044 testCases = append(testCases, testCase{
12045 testType: clientTest,
12046 name: "ExtraHandshake-FalseStart",
12047 config: Config{
12048 MaxVersion: VersionTLS12,
12049 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12050 NextProtos: []string{"foo"},
12051 Bugs: ProtocolBugs{
12052 ExpectFalseStart: true,
12053 AlertBeforeFalseStartTest: alertAccessDenied,
12054 },
12055 },
12056 flags: []string{
12057 "-handshake-twice",
12058 "-false-start",
12059 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012060 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012061 },
12062 shimWritesFirst: true,
12063 shouldFail: true,
12064 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12065 expectedLocalError: "tls: peer did not false start: EOF",
12066 })
12067}
12068
Adam Langley7c803a62015-06-15 15:35:05 -070012069func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012070 defer wg.Done()
12071
12072 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012073 var err error
12074
David Benjaminba28dfc2016-11-15 17:47:21 +090012075 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012076 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12077 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012078 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012079 if err != nil {
12080 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12081 }
12082 break
12083 }
12084 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012085 } else if *repeatUntilFailure {
12086 for err == nil {
12087 statusChan <- statusMsg{test: test, started: true}
12088 err = runTest(test, shimPath, -1)
12089 }
12090 } else {
12091 statusChan <- statusMsg{test: test, started: true}
12092 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012093 }
Adam Langley95c29f32014-06-20 12:00:00 -070012094 statusChan <- statusMsg{test: test, err: err}
12095 }
12096}
12097
12098type statusMsg struct {
12099 test *testCase
12100 started bool
12101 err error
12102}
12103
David Benjamin5f237bc2015-02-11 17:14:15 -050012104func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012105 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012106
David Benjamin5f237bc2015-02-11 17:14:15 -050012107 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012108 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012109 if !*pipe {
12110 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012111 var erase string
12112 for i := 0; i < lineLen; i++ {
12113 erase += "\b \b"
12114 }
12115 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012116 }
12117
Adam Langley95c29f32014-06-20 12:00:00 -070012118 if msg.started {
12119 started++
12120 } else {
12121 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012122
12123 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012124 if msg.err == errUnimplemented {
12125 if *pipe {
12126 // Print each test instead of a status line.
12127 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12128 }
12129 unimplemented++
12130 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12131 } else {
12132 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12133 failed++
12134 testOutput.addResult(msg.test.name, "FAIL")
12135 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012136 } else {
12137 if *pipe {
12138 // Print each test instead of a status line.
12139 fmt.Printf("PASSED (%s)\n", msg.test.name)
12140 }
12141 testOutput.addResult(msg.test.name, "PASS")
12142 }
Adam Langley95c29f32014-06-20 12:00:00 -070012143 }
12144
David Benjamin5f237bc2015-02-11 17:14:15 -050012145 if !*pipe {
12146 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012147 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012148 lineLen = len(line)
12149 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012150 }
Adam Langley95c29f32014-06-20 12:00:00 -070012151 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012152
12153 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012154}
12155
12156func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012157 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012158 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012159 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012160
Adam Langley7c803a62015-06-15 15:35:05 -070012161 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012162 addCipherSuiteTests()
12163 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012164 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012165 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012166 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012167 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012168 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012169 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012170 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012171 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012172 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012173 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012174 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012175 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012176 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012177 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012178 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012179 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012180 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012181 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012182 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012183 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012184 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012185 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012186 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012187 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012188 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012189 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012190 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012191 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012192 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012193 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012194 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012195 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012196
12197 var wg sync.WaitGroup
12198
Adam Langley7c803a62015-06-15 15:35:05 -070012199 statusChan := make(chan statusMsg, *numWorkers)
12200 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012201 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012202
EKRf71d7ed2016-08-06 13:25:12 -070012203 if len(*shimConfigFile) != 0 {
12204 encoded, err := ioutil.ReadFile(*shimConfigFile)
12205 if err != nil {
12206 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12207 os.Exit(1)
12208 }
12209
12210 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12211 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12212 os.Exit(1)
12213 }
12214 }
12215
David Benjamin025b3d32014-07-01 19:53:04 -040012216 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012217
Adam Langley7c803a62015-06-15 15:35:05 -070012218 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012219 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012220 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012221 }
12222
David Benjamin270f0a72016-03-17 14:41:36 -040012223 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012224 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012225 matched := true
12226 if len(*testToRun) != 0 {
12227 var err error
12228 matched, err = filepath.Match(*testToRun, testCases[i].name)
12229 if err != nil {
12230 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12231 os.Exit(1)
12232 }
12233 }
12234
EKRf71d7ed2016-08-06 13:25:12 -070012235 if !*includeDisabled {
12236 for pattern := range shimConfig.DisabledTests {
12237 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12238 if err != nil {
12239 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12240 os.Exit(1)
12241 }
12242
12243 if isDisabled {
12244 matched = false
12245 break
12246 }
12247 }
12248 }
12249
David Benjamin17e12922016-07-28 18:04:43 -040012250 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012251 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012252 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012253
12254 // Only run one test if repeating until failure.
12255 if *repeatUntilFailure {
12256 break
12257 }
Adam Langley95c29f32014-06-20 12:00:00 -070012258 }
12259 }
David Benjamin17e12922016-07-28 18:04:43 -040012260
David Benjamin270f0a72016-03-17 14:41:36 -040012261 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012262 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012263 os.Exit(1)
12264 }
Adam Langley95c29f32014-06-20 12:00:00 -070012265
12266 close(testChan)
12267 wg.Wait()
12268 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012269 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012270
12271 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012272
12273 if *jsonOutput != "" {
12274 if err := testOutput.writeTo(*jsonOutput); err != nil {
12275 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12276 }
12277 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012278
EKR842ae6c2016-07-27 09:22:05 +020012279 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12280 os.Exit(1)
12281 }
12282
12283 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012284 os.Exit(1)
12285 }
Adam Langley95c29f32014-06-20 12:00:00 -070012286}