blob: 13163863a4bb9d01d7ce4a00f3d29cfc5ba04ede [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 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400530 if test.tls13Variant != 0 {
531 config.TLS13Variant = test.tls13Variant
532 }
David Benjamine54af062016-08-08 19:21:18 -0400533
David Benjamin01784b42016-06-07 18:00:52 -0400534 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500535
David Benjamin6fd297b2014-08-11 18:43:38 -0400536 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500537 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
538 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500539 }
540
David Benjamin9867b7d2016-03-01 23:25:48 -0500541 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500542 local, peer := "client", "server"
543 if test.testType == clientTest {
544 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500545 }
David Benjaminebda9b32015-11-02 15:33:18 -0500546 connDebug := &recordingConn{
547 Conn: conn,
548 isDatagram: test.protocol == dtls,
549 local: local,
550 peer: peer,
551 }
552 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500553 if *flagDebug {
554 defer connDebug.WriteTo(os.Stdout)
555 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400558 path := transcriptPrefix + strconv.Itoa(num)
559 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500560 }()
561 }
David Benjaminebda9b32015-11-02 15:33:18 -0500562
563 if config.Bugs.PacketAdaptor != nil {
564 config.Bugs.PacketAdaptor.debug = connDebug
565 }
566 }
567
568 if test.replayWrites {
569 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400570 }
571
David Benjamin3ed59772016-03-08 12:50:21 -0500572 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500573 if test.damageFirstWrite {
574 connDamage = newDamageAdaptor(conn)
575 conn = connDamage
576 }
577
David Benjamin6fd297b2014-08-11 18:43:38 -0400578 if test.sendPrefix != "" {
579 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
580 return err
581 }
David Benjamin98e882e2014-08-08 13:24:34 -0400582 }
583
David Benjamin1d5c83e2014-07-22 19:20:02 -0400584 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400585 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400586 if test.protocol == dtls {
587 tlsConn = DTLSServer(conn, config)
588 } else {
589 tlsConn = Server(conn, config)
590 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400591 } else {
592 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400593 if test.protocol == dtls {
594 tlsConn = DTLSClient(conn, config)
595 } else {
596 tlsConn = Client(conn, config)
597 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598 }
David Benjamin30789da2015-08-29 22:56:45 -0400599 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400600
Adam Langley95c29f32014-06-20 12:00:00 -0700601 if err := tlsConn.Handshake(); err != nil {
602 return err
603 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700604
David Benjamin01fe8202014-09-24 15:21:44 -0400605 // TODO(davidben): move all per-connection expectations into a dedicated
606 // expectations struct that can be specified separately for the two
607 // legs.
608 expectedVersion := test.expectedVersion
609 if isResume && test.expectedResumeVersion != 0 {
610 expectedVersion = test.expectedResumeVersion
611 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700612 connState := tlsConn.ConnectionState()
613 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400614 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400615 }
616
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700617 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400618 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
619 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700620 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
621 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
622 }
David Benjamin90da8c82015-04-20 14:57:57 -0400623
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700625 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400626 if channelID == nil {
627 return fmt.Errorf("no channel ID negotiated")
628 }
629 if channelID.Curve != channelIDKey.Curve ||
630 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
631 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
632 return fmt.Errorf("incorrect channel ID")
633 }
David Benjamin634f4752017-07-01 11:08:41 -0400634 } else if connState.ChannelID != nil {
635 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400636 }
637
David Benjaminae2888f2014-09-06 12:58:58 -0400638 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700639 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400640 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
641 }
642 }
643
David Benjaminc7ce9772015-10-09 19:32:41 -0400644 if test.expectNoNextProto {
645 if actual := connState.NegotiatedProtocol; actual != "" {
646 return fmt.Errorf("got unexpected next proto %s", actual)
647 }
648 }
649
David Benjaminfc7b0862014-09-06 13:21:53 -0400650 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700651 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400652 return fmt.Errorf("next proto type mismatch")
653 }
654 }
655
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700656 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500657 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
658 }
659
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100660 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300661 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100662 }
663
Paul Lietar4fac72e2015-09-09 13:44:55 +0100664 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
665 return fmt.Errorf("SCT list mismatch")
666 }
667
Nick Harper60edffd2016-06-21 15:19:24 -0700668 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
669 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400670 }
671
Steven Valdez5440fe02016-07-18 12:40:30 -0400672 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
673 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
674 }
675
David Benjamin2c516452016-11-15 10:16:54 +0900676 if test.expectPeerCertificate != nil {
677 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
678 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
679 }
680 for i, cert := range connState.PeerCertificates {
681 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
682 return fmt.Errorf("peer certificate %d did not match", i+1)
683 }
684 }
685 }
686
David Benjaminc565ebb2015-04-03 04:06:36 -0400687 if test.exportKeyingMaterial > 0 {
688 actual := make([]byte, test.exportKeyingMaterial)
689 if _, err := io.ReadFull(tlsConn, actual); err != nil {
690 return err
691 }
692 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
693 if err != nil {
694 return err
695 }
696 if !bytes.Equal(actual, expected) {
697 return fmt.Errorf("keying material mismatch")
698 }
699 }
700
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700701 if test.testTLSUnique {
702 var peersValue [12]byte
703 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
704 return err
705 }
706 expected := tlsConn.ConnectionState().TLSUnique
707 if !bytes.Equal(peersValue[:], expected) {
708 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
709 }
710 }
711
David Benjamin47921102016-07-28 11:29:18 -0400712 if test.sendHalfHelloRequest {
713 tlsConn.SendHalfHelloRequest()
714 }
715
Steven Valdeze831a812017-03-09 14:56:07 -0500716 shimPrefix := test.shimPrefix
717 if isResume {
718 shimPrefix = test.resumeShimPrefix
719 }
720 if test.shimWritesFirst || test.readWithUnfinishedWrite {
721 shimPrefix = "hello"
722 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400723 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400724 // If readWithUnfinishedWrite is set, the shim prefix will be
725 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500726 if shimPrefix != "" && !test.readWithUnfinishedWrite {
727 var buf = make([]byte, len(shimPrefix))
728 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400729 if err != nil {
730 return err
731 }
Steven Valdeze831a812017-03-09 14:56:07 -0500732 if string(buf) != shimPrefix {
733 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400734 }
Steven Valdeze831a812017-03-09 14:56:07 -0500735 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400736 }
737
Adam Langleycf2d4f42014-10-28 19:06:14 -0700738 if test.renegotiateCiphers != nil {
739 config.CipherSuites = test.renegotiateCiphers
740 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400741 for i := 0; i < test.renegotiate; i++ {
742 if err := tlsConn.Renegotiate(); err != nil {
743 return err
744 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700745 }
746 } else if test.renegotiateCiphers != nil {
747 panic("renegotiateCiphers without renegotiate")
748 }
749
David Benjamin5fa3eba2015-01-22 16:35:40 -0500750 if test.damageFirstWrite {
751 connDamage.setDamage(true)
752 tlsConn.Write([]byte("DAMAGED WRITE"))
753 connDamage.setDamage(false)
754 }
755
David Benjamin8e6db492015-07-25 18:29:23 -0400756 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700757 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400758 if test.protocol == dtls {
759 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
760 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700761 // Read until EOF.
762 _, err := io.Copy(ioutil.Discard, tlsConn)
763 return err
764 }
David Benjamin4417d052015-04-05 04:17:25 -0400765 if messageLen == 0 {
766 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700767 }
Adam Langley95c29f32014-06-20 12:00:00 -0700768
David Benjamin8e6db492015-07-25 18:29:23 -0400769 messageCount := test.messageCount
770 if messageCount == 0 {
771 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400772 }
773
David Benjamin8e6db492015-07-25 18:29:23 -0400774 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400775 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400776 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400777 }
778
David Benjamin8e6db492015-07-25 18:29:23 -0400779 for i := 0; i < test.sendEmptyRecords; i++ {
780 tlsConn.Write(nil)
781 }
782
783 for i := 0; i < test.sendWarningAlerts; i++ {
784 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
785 }
786
David Benjamin24e58862017-06-14 18:45:29 -0400787 if test.sendBogusAlertType {
788 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
789 }
790
David Benjaminbbba9392017-04-06 12:54:12 -0400791 testMessage := make([]byte, messageLen)
792 for i := range testMessage {
793 testMessage[i] = 0x42 ^ byte(j)
794 }
795 tlsConn.Write(testMessage)
796
797 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500798 if shimPrefix != "" {
799 var buf = make([]byte, len(shimPrefix))
800 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400801 if err != nil {
802 return err
803 }
Steven Valdeze831a812017-03-09 14:56:07 -0500804 if string(buf) != shimPrefix {
805 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400806 }
Steven Valdeze831a812017-03-09 14:56:07 -0500807 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400808 }
809
David Benjamin4f75aaf2015-09-01 16:53:10 -0400810 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400811 // The shim will not respond.
812 continue
813 }
814
David Benjaminbbba9392017-04-06 12:54:12 -0400815 // Process the KeyUpdate ACK. However many KeyUpdates the runner
816 // sends, the shim should respond only once.
817 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
818 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
819 return err
820 }
821 }
822
David Benjamin8e6db492015-07-25 18:29:23 -0400823 buf := make([]byte, len(testMessage))
824 if test.protocol == dtls {
825 bufTmp := make([]byte, len(buf)+1)
826 n, err := tlsConn.Read(bufTmp)
827 if err != nil {
828 return err
829 }
830 if n != len(buf) {
831 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
832 }
833 copy(buf, bufTmp)
834 } else {
835 _, err := io.ReadFull(tlsConn, buf)
836 if err != nil {
837 return err
838 }
839 }
840
841 for i, v := range buf {
842 if v != testMessage[i]^0xff {
843 return fmt.Errorf("bad reply contents at byte %d", i)
844 }
Adam Langley95c29f32014-06-20 12:00:00 -0700845 }
846 }
847
848 return nil
849}
850
David Benjamin325b5c32014-07-01 19:40:31 -0400851func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400852 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700853 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400854 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700855 }
David Benjamin325b5c32014-07-01 19:40:31 -0400856 valgrindArgs = append(valgrindArgs, path)
857 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700858
David Benjamin325b5c32014-07-01 19:40:31 -0400859 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700860}
861
David Benjamin325b5c32014-07-01 19:40:31 -0400862func gdbOf(path string, args ...string) *exec.Cmd {
863 xtermArgs := []string{"-e", "gdb", "--args"}
864 xtermArgs = append(xtermArgs, path)
865 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700866
David Benjamin325b5c32014-07-01 19:40:31 -0400867 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700868}
869
David Benjamind16bf342015-12-18 00:53:12 -0500870func lldbOf(path string, args ...string) *exec.Cmd {
871 xtermArgs := []string{"-e", "lldb", "--"}
872 xtermArgs = append(xtermArgs, path)
873 xtermArgs = append(xtermArgs, args...)
874
875 return exec.Command("xterm", xtermArgs...)
876}
877
EKR842ae6c2016-07-27 09:22:05 +0200878var (
879 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
880 errUnimplemented = errors.New("child process does not implement needed flags")
881)
Adam Langley69a01602014-11-17 17:26:55 -0800882
David Benjamin87c8a642015-02-21 01:54:29 -0500883// accept accepts a connection from listener, unless waitChan signals a process
884// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400885func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500886 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400887 conn net.Conn
888 err error
889 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500890 }
891 connChan := make(chan connOrError, 1)
892 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400893 startTime := time.Now()
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400894 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500895 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400896 endTime := time.Now()
897 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500898 close(connChan)
899 }()
900 select {
901 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400902 if result.err != nil {
903 // TODO(davidben): Remove this logging when
904 // https://crbug.com/boringssl/199 is resolved.
905 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
906 }
David Benjamin87c8a642015-02-21 01:54:29 -0500907 return result.conn, result.err
908 case childErr := <-waitChan:
909 waitChan <- childErr
910 return nil, fmt.Errorf("child exited early: %s", childErr)
911 }
912}
913
EKRf71d7ed2016-08-06 13:25:12 -0700914func translateExpectedError(errorStr string) string {
915 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
916 return translated
917 }
918
919 if *looseErrors {
920 return ""
921 }
922
923 return errorStr
924}
925
Adam Langley7c803a62015-06-15 15:35:05 -0700926func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400927 // Help debugging panics on the Go side.
928 defer func() {
929 if r := recover(); r != nil {
930 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
931 panic(r)
932 }
933 }()
934
Adam Langley38311732014-10-16 19:04:35 -0700935 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
936 panic("Error expected without shouldFail in " + test.name)
937 }
938
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700939 if test.expectResumeRejected && !test.resumeSession {
940 panic("expectResumeRejected without resumeSession in " + test.name)
941 }
942
Adam Langley33b1d4f2016-12-07 15:03:45 -0800943 for _, ver := range tlsVersions {
944 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
945 continue
946 }
947
David Benjamina5022392017-07-10 17:40:39 -0400948 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
949 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 -0800950 }
951
David Benjamina5022392017-07-10 17:40:39 -0400952 if ver.tls13Variant != 0 {
953 var foundFlag bool
954 for _, flag := range test.flags {
955 if flag == "-tls13-variant" {
956 foundFlag = true
957 break
958 }
959 }
960 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
961 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))
962 }
963 }
964
Adam Langley33b1d4f2016-12-07 15:03:45 -0800965 }
966
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700967 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
968 if err != nil {
969 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
970 }
David Benjamin87c8a642015-02-21 01:54:29 -0500971 if err != nil {
972 panic(err)
973 }
974 defer func() {
975 if listener != nil {
976 listener.Close()
977 }
978 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700979
David Benjamin87c8a642015-02-21 01:54:29 -0500980 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400981 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400982 flags = append(flags, "-server")
983
David Benjamin025b3d32014-07-01 19:53:04 -0400984 flags = append(flags, "-key-file")
985 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700986 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400987 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700988 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400989 }
990
991 flags = append(flags, "-cert-file")
992 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700993 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400994 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700995 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400996 }
997 }
David Benjamin5a593af2014-08-11 19:51:50 -0400998
David Benjamin6fd297b2014-08-11 18:43:38 -0400999 if test.protocol == dtls {
1000 flags = append(flags, "-dtls")
1001 }
1002
David Benjamin46662482016-08-17 00:51:00 -04001003 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001004 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001005 resumeCount++
1006 if test.resumeRenewedSession {
1007 resumeCount++
1008 }
1009 }
1010
1011 if resumeCount > 0 {
1012 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001013 }
1014
David Benjamine58c4f52014-08-24 03:47:07 -04001015 if test.shimWritesFirst {
1016 flags = append(flags, "-shim-writes-first")
1017 }
1018
David Benjaminbbba9392017-04-06 12:54:12 -04001019 if test.readWithUnfinishedWrite {
1020 flags = append(flags, "-read-with-unfinished-write")
1021 }
1022
David Benjamin30789da2015-08-29 22:56:45 -04001023 if test.shimShutsDown {
1024 flags = append(flags, "-shim-shuts-down")
1025 }
1026
David Benjaminc565ebb2015-04-03 04:06:36 -04001027 if test.exportKeyingMaterial > 0 {
1028 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1029 flags = append(flags, "-export-label", test.exportLabel)
1030 flags = append(flags, "-export-context", test.exportContext)
1031 if test.useExportContext {
1032 flags = append(flags, "-use-export-context")
1033 }
1034 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001035 if test.expectResumeRejected {
1036 flags = append(flags, "-expect-session-miss")
1037 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001038
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001039 if test.testTLSUnique {
1040 flags = append(flags, "-tls-unique")
1041 }
1042
David Benjamina5022392017-07-10 17:40:39 -04001043 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001044 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1045 }
1046
David Benjamin0fde2eb2017-06-30 19:11:22 -04001047 var transcriptPrefix string
1048 if len(*transcriptDir) != 0 {
1049 protocol := "tls"
1050 if test.protocol == dtls {
1051 protocol = "dtls"
1052 }
1053
1054 side := "client"
1055 if test.testType == serverTest {
1056 side = "server"
1057 }
1058
1059 dir := filepath.Join(*transcriptDir, protocol, side)
1060 if err := os.MkdirAll(dir, 0755); err != nil {
1061 return err
1062 }
1063 transcriptPrefix = filepath.Join(dir, test.name+"-")
1064 flags = append(flags, "-write-settings", transcriptPrefix)
1065 }
1066
David Benjamin025b3d32014-07-01 19:53:04 -04001067 flags = append(flags, test.flags...)
1068
1069 var shim *exec.Cmd
1070 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001071 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001072 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001073 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001074 } else if *useLLDB {
1075 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001076 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001077 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001078 }
David Benjamin025b3d32014-07-01 19:53:04 -04001079 shim.Stdin = os.Stdin
1080 var stdoutBuf, stderrBuf bytes.Buffer
1081 shim.Stdout = &stdoutBuf
1082 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001083 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001084 shim.Env = os.Environ()
1085 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001086 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001087 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001088 }
1089 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1090 }
David Benjamin025b3d32014-07-01 19:53:04 -04001091
1092 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001093 panic(err)
1094 }
David Benjamin87c8a642015-02-21 01:54:29 -05001095 waitChan := make(chan error, 1)
1096 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001097
1098 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001099
David Benjamin7a4aaa42016-09-20 17:58:14 -04001100 if *deterministic {
1101 config.Rand = &deterministicRand{}
1102 }
1103
David Benjamin87c8a642015-02-21 01:54:29 -05001104 conn, err := acceptOrWait(listener, waitChan)
1105 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001106 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001107 conn.Close()
1108 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001109
David Benjamin46662482016-08-17 00:51:00 -04001110 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001111 var resumeConfig Config
1112 if test.resumeConfig != nil {
1113 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001114 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001115 resumeConfig.SessionTicketKey = config.SessionTicketKey
1116 resumeConfig.ClientSessionCache = config.ClientSessionCache
1117 resumeConfig.ServerSessionCache = config.ServerSessionCache
1118 }
David Benjamin2e045a92016-06-08 13:09:56 -04001119 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001120 } else {
1121 resumeConfig = config
1122 }
David Benjamin87c8a642015-02-21 01:54:29 -05001123 var connResume net.Conn
1124 connResume, err = acceptOrWait(listener, waitChan)
1125 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001126 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001127 connResume.Close()
1128 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001129 }
1130
David Benjamin87c8a642015-02-21 01:54:29 -05001131 // Close the listener now. This is to avoid hangs should the shim try to
1132 // open more connections than expected.
1133 listener.Close()
1134 listener = nil
1135
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001136 var shimKilledLock sync.Mutex
1137 var shimKilled bool
1138 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1139 shimKilledLock.Lock()
1140 shimKilled = true
1141 shimKilledLock.Unlock()
1142 shim.Process.Kill()
1143 })
David Benjamin87c8a642015-02-21 01:54:29 -05001144 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001145 waitTimeout.Stop()
1146 shimKilledLock.Lock()
1147 if shimKilled && err == nil {
1148 err = errors.New("timeout waiting for the shim to exit.")
1149 }
1150 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001151 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001152 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001153 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1154 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001155 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001156 case 89:
1157 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001158 case 99:
1159 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001160 }
1161 }
Adam Langley95c29f32014-06-20 12:00:00 -07001162
David Benjamin9bea3492016-03-02 10:59:16 -05001163 // Account for Windows line endings.
1164 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1165 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001166
1167 // Separate the errors from the shim and those from tools like
1168 // AddressSanitizer.
1169 var extraStderr string
1170 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1171 stderr = stderrParts[0]
1172 extraStderr = stderrParts[1]
1173 }
1174
Adam Langley95c29f32014-06-20 12:00:00 -07001175 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001176 expectedError := translateExpectedError(test.expectedError)
1177 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001178
Adam Langleyac61fa32014-06-23 12:03:11 -07001179 localError := "none"
1180 if err != nil {
1181 localError = err.Error()
1182 }
1183 if len(test.expectedLocalError) != 0 {
1184 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1185 }
Adam Langley95c29f32014-06-20 12:00:00 -07001186
1187 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001188 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001189 if childErr != nil {
1190 childError = childErr.Error()
1191 }
1192
1193 var msg string
1194 switch {
1195 case failed && !test.shouldFail:
1196 msg = "unexpected failure"
1197 case !failed && test.shouldFail:
1198 msg = "unexpected success"
1199 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001200 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001201 default:
1202 panic("internal error")
1203 }
1204
David Benjamin9aafb642016-09-20 19:36:53 -04001205 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 -07001206 }
1207
David Benjamind2ba8892016-09-20 19:41:04 -04001208 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001209 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001210 }
1211
David Benjamind2ba8892016-09-20 19:41:04 -04001212 if *useValgrind && isValgrindError {
1213 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1214 }
1215
Adam Langley95c29f32014-06-20 12:00:00 -07001216 return nil
1217}
1218
David Benjaminaa012042016-12-10 13:33:05 -05001219type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001220 name string
1221 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001222 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001223 // excludeFlag is the legacy shim flag to disable the version.
1224 excludeFlag string
1225 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001226 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1227 versionDTLS uint16
1228 // versionWire, if non-zero, is the wire representation of the
1229 // version. Otherwise the wire version is the protocol version or
1230 // versionDTLS.
1231 versionWire uint16
1232 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001233}
1234
1235func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001236 // The shim uses the protocol version in its public API, but uses the
1237 // DTLS-specific version if it exists.
1238 if protocol == dtls && vers.versionDTLS != 0 {
1239 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001240 }
Steven Valdez520e1222017-06-13 12:45:25 -04001241 return strconv.Itoa(int(vers.version))
1242}
1243
1244func (vers tlsVersion) wire(protocol protocol) uint16 {
1245 if protocol == dtls && vers.versionDTLS != 0 {
1246 return vers.versionDTLS
1247 }
1248 if vers.versionWire != 0 {
1249 return vers.versionWire
1250 }
1251 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001252}
1253
1254var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001255 {
1256 name: "SSL3",
1257 version: VersionSSL30,
1258 excludeFlag: "-no-ssl3",
1259 },
1260 {
1261 name: "TLS1",
1262 version: VersionTLS10,
1263 excludeFlag: "-no-tls1",
1264 hasDTLS: true,
1265 versionDTLS: VersionDTLS10,
1266 },
1267 {
1268 name: "TLS11",
1269 version: VersionTLS11,
1270 excludeFlag: "-no-tls11",
1271 },
1272 {
1273 name: "TLS12",
1274 version: VersionTLS12,
1275 excludeFlag: "-no-tls12",
1276 hasDTLS: true,
1277 versionDTLS: VersionDTLS12,
1278 },
1279 {
1280 name: "TLS13",
1281 version: VersionTLS13,
1282 excludeFlag: "-no-tls13",
1283 versionWire: tls13DraftVersion,
1284 tls13Variant: TLS13Default,
1285 },
1286 {
1287 name: "TLS13Experiment",
1288 version: VersionTLS13,
1289 excludeFlag: "-no-tls13",
1290 versionWire: tls13ExperimentVersion,
1291 tls13Variant: TLS13Experiment,
1292 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001293 {
1294 name: "TLS13RecordTypeExperiment",
1295 version: VersionTLS13,
1296 excludeFlag: "-no-tls13",
1297 versionWire: tls13RecordTypeExperimentVersion,
1298 tls13Variant: TLS13RecordTypeExperiment,
1299 },
Steven Valdez520e1222017-06-13 12:45:25 -04001300}
1301
1302func allVersions(protocol protocol) []tlsVersion {
1303 if protocol == tls {
1304 return tlsVersions
1305 }
1306
1307 var ret []tlsVersion
1308 for _, vers := range tlsVersions {
1309 if vers.hasDTLS {
1310 ret = append(ret, vers)
1311 }
1312 }
1313 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001314}
1315
David Benjaminaa012042016-12-10 13:33:05 -05001316type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001317 name string
1318 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001319}
1320
1321var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001322 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001323 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001324 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001325 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001326 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001327 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001328 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001329 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1330 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1332 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001333 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001334 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001335 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001336 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001337 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001338 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001339 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001340 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001341 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001342 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001343 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1344 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001345 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1346 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001347 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001348 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1349 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1350 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001351 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001352}
1353
David Benjamin8b8c0062014-11-23 02:47:52 -05001354func hasComponent(suiteName, component string) bool {
1355 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1356}
1357
David Benjaminf7768e42014-08-31 02:06:47 -04001358func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001359 return hasComponent(suiteName, "GCM") ||
1360 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001361 hasComponent(suiteName, "SHA384") ||
1362 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001363}
1364
Nick Harper1fd39d82016-06-14 18:14:35 -07001365func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001366 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001367}
1368
David Benjamin8b8c0062014-11-23 02:47:52 -05001369func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001370 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001371}
1372
Adam Langleya7997f12015-05-14 17:38:50 -07001373func bigFromHex(hex string) *big.Int {
1374 ret, ok := new(big.Int).SetString(hex, 16)
1375 if !ok {
1376 panic("failed to parse hex number 0x" + hex)
1377 }
1378 return ret
1379}
1380
Adam Langley7c803a62015-06-15 15:35:05 -07001381func addBasicTests() {
1382 basicTests := []testCase{
1383 {
Adam Langley7c803a62015-06-15 15:35:05 -07001384 name: "NoFallbackSCSV",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 FailIfNotFallbackSCSV: true,
1388 },
1389 },
1390 shouldFail: true,
1391 expectedLocalError: "no fallback SCSV found",
1392 },
1393 {
1394 name: "SendFallbackSCSV",
1395 config: Config{
1396 Bugs: ProtocolBugs{
1397 FailIfNotFallbackSCSV: true,
1398 },
1399 },
1400 flags: []string{"-fallback-scsv"},
1401 },
1402 {
1403 name: "ClientCertificateTypes",
1404 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001405 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001406 ClientAuth: RequestClientCert,
1407 ClientCertificateTypes: []byte{
1408 CertTypeDSSSign,
1409 CertTypeRSASign,
1410 CertTypeECDSASign,
1411 },
1412 },
1413 flags: []string{
1414 "-expect-certificate-types",
1415 base64.StdEncoding.EncodeToString([]byte{
1416 CertTypeDSSSign,
1417 CertTypeRSASign,
1418 CertTypeECDSASign,
1419 }),
1420 },
1421 },
1422 {
Adam Langley7c803a62015-06-15 15:35:05 -07001423 name: "UnauthenticatedECDH",
1424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001425 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1427 Bugs: ProtocolBugs{
1428 UnauthenticatedECDH: true,
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":UNEXPECTED_MESSAGE:",
1433 },
1434 {
1435 name: "SkipCertificateStatus",
1436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001437 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1439 Bugs: ProtocolBugs{
1440 SkipCertificateStatus: true,
1441 },
1442 },
1443 flags: []string{
1444 "-enable-ocsp-stapling",
1445 },
1446 },
1447 {
1448 name: "SkipServerKeyExchange",
1449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001450 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Bugs: ProtocolBugs{
1453 SkipServerKeyExchange: true,
1454 },
1455 },
1456 shouldFail: true,
1457 expectedError: ":UNEXPECTED_MESSAGE:",
1458 },
1459 {
Adam Langley7c803a62015-06-15 15:35:05 -07001460 testType: serverTest,
1461 name: "Alert",
1462 config: Config{
1463 Bugs: ProtocolBugs{
1464 SendSpuriousAlert: alertRecordOverflow,
1465 },
1466 },
1467 shouldFail: true,
1468 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1469 },
1470 {
1471 protocol: dtls,
1472 testType: serverTest,
1473 name: "Alert-DTLS",
1474 config: Config{
1475 Bugs: ProtocolBugs{
1476 SendSpuriousAlert: alertRecordOverflow,
1477 },
1478 },
1479 shouldFail: true,
1480 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1481 },
1482 {
1483 testType: serverTest,
1484 name: "FragmentAlert",
1485 config: Config{
1486 Bugs: ProtocolBugs{
1487 FragmentAlert: true,
1488 SendSpuriousAlert: alertRecordOverflow,
1489 },
1490 },
1491 shouldFail: true,
1492 expectedError: ":BAD_ALERT:",
1493 },
1494 {
1495 protocol: dtls,
1496 testType: serverTest,
1497 name: "FragmentAlert-DTLS",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 FragmentAlert: true,
1501 SendSpuriousAlert: alertRecordOverflow,
1502 },
1503 },
1504 shouldFail: true,
1505 expectedError: ":BAD_ALERT:",
1506 },
1507 {
1508 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001509 name: "DoubleAlert",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 DoubleAlert: true,
1513 SendSpuriousAlert: alertRecordOverflow,
1514 },
1515 },
1516 shouldFail: true,
1517 expectedError: ":BAD_ALERT:",
1518 },
1519 {
1520 protocol: dtls,
1521 testType: serverTest,
1522 name: "DoubleAlert-DTLS",
1523 config: Config{
1524 Bugs: ProtocolBugs{
1525 DoubleAlert: true,
1526 SendSpuriousAlert: alertRecordOverflow,
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":BAD_ALERT:",
1531 },
1532 {
Adam Langley7c803a62015-06-15 15:35:05 -07001533 name: "SkipNewSessionTicket",
1534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001535 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001536 Bugs: ProtocolBugs{
1537 SkipNewSessionTicket: true,
1538 },
1539 },
1540 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001541 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001542 },
1543 {
1544 testType: serverTest,
1545 name: "FallbackSCSV",
1546 config: Config{
1547 MaxVersion: VersionTLS11,
1548 Bugs: ProtocolBugs{
1549 SendFallbackSCSV: true,
1550 },
1551 },
David Benjamin56cadc32016-12-16 19:54:11 -05001552 shouldFail: true,
1553 expectedError: ":INAPPROPRIATE_FALLBACK:",
1554 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001555 },
1556 {
1557 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001558 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001559 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001560 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001561 Bugs: ProtocolBugs{
1562 SendFallbackSCSV: true,
1563 },
1564 },
1565 },
1566 {
1567 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001568 name: "FallbackSCSV-VersionMatch-TLS12",
1569 config: Config{
1570 MaxVersion: VersionTLS12,
1571 Bugs: ProtocolBugs{
1572 SendFallbackSCSV: true,
1573 },
1574 },
1575 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1576 },
1577 {
1578 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001579 name: "FragmentedClientVersion",
1580 config: Config{
1581 Bugs: ProtocolBugs{
1582 MaxHandshakeRecordLength: 1,
1583 FragmentClientVersion: true,
1584 },
1585 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001586 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001587 },
1588 {
Adam Langley7c803a62015-06-15 15:35:05 -07001589 testType: serverTest,
1590 name: "HttpGET",
1591 sendPrefix: "GET / HTTP/1.0\n",
1592 shouldFail: true,
1593 expectedError: ":HTTP_REQUEST:",
1594 },
1595 {
1596 testType: serverTest,
1597 name: "HttpPOST",
1598 sendPrefix: "POST / HTTP/1.0\n",
1599 shouldFail: true,
1600 expectedError: ":HTTP_REQUEST:",
1601 },
1602 {
1603 testType: serverTest,
1604 name: "HttpHEAD",
1605 sendPrefix: "HEAD / HTTP/1.0\n",
1606 shouldFail: true,
1607 expectedError: ":HTTP_REQUEST:",
1608 },
1609 {
1610 testType: serverTest,
1611 name: "HttpPUT",
1612 sendPrefix: "PUT / HTTP/1.0\n",
1613 shouldFail: true,
1614 expectedError: ":HTTP_REQUEST:",
1615 },
1616 {
1617 testType: serverTest,
1618 name: "HttpCONNECT",
1619 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1620 shouldFail: true,
1621 expectedError: ":HTTPS_PROXY_REQUEST:",
1622 },
1623 {
1624 testType: serverTest,
1625 name: "Garbage",
1626 sendPrefix: "blah",
1627 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001628 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001629 },
1630 {
Adam Langley7c803a62015-06-15 15:35:05 -07001631 name: "RSAEphemeralKey",
1632 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001633 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001634 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1635 Bugs: ProtocolBugs{
1636 RSAEphemeralKey: true,
1637 },
1638 },
1639 shouldFail: true,
1640 expectedError: ":UNEXPECTED_MESSAGE:",
1641 },
1642 {
1643 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001644 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001645 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001646 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001647 },
1648 {
1649 protocol: dtls,
1650 name: "DisableEverything-DTLS",
1651 flags: []string{"-no-tls12", "-no-tls1"},
1652 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001653 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001654 },
1655 {
Adam Langley7c803a62015-06-15 15:35:05 -07001656 protocol: dtls,
1657 testType: serverTest,
1658 name: "MTU",
1659 config: Config{
1660 Bugs: ProtocolBugs{
1661 MaxPacketLength: 256,
1662 },
1663 },
1664 flags: []string{"-mtu", "256"},
1665 },
1666 {
1667 protocol: dtls,
1668 testType: serverTest,
1669 name: "MTUExceeded",
1670 config: Config{
1671 Bugs: ProtocolBugs{
1672 MaxPacketLength: 255,
1673 },
1674 },
1675 flags: []string{"-mtu", "256"},
1676 shouldFail: true,
1677 expectedLocalError: "dtls: exceeded maximum packet length",
1678 },
1679 {
Adam Langley7c803a62015-06-15 15:35:05 -07001680 name: "EmptyCertificateList",
1681 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001682 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001683 Bugs: ProtocolBugs{
1684 EmptyCertificateList: true,
1685 },
1686 },
1687 shouldFail: true,
1688 expectedError: ":DECODE_ERROR:",
1689 },
1690 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001691 name: "EmptyCertificateList-TLS13",
1692 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001693 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001694 Bugs: ProtocolBugs{
1695 EmptyCertificateList: true,
1696 },
1697 },
1698 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001699 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001700 },
1701 {
Adam Langley7c803a62015-06-15 15:35:05 -07001702 name: "TLSFatalBadPackets",
1703 damageFirstWrite: true,
1704 shouldFail: true,
1705 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1706 },
1707 {
1708 protocol: dtls,
1709 name: "DTLSIgnoreBadPackets",
1710 damageFirstWrite: true,
1711 },
1712 {
1713 protocol: dtls,
1714 name: "DTLSIgnoreBadPackets-Async",
1715 damageFirstWrite: true,
1716 flags: []string{"-async"},
1717 },
1718 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001719 name: "AppDataBeforeHandshake",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
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 name: "AppDataBeforeHandshake-Empty",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 AppDataBeforeHandshake: []byte{},
1733 },
1734 },
1735 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001736 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001737 },
1738 {
1739 protocol: dtls,
1740 name: "AppDataBeforeHandshake-DTLS",
1741 config: Config{
1742 Bugs: ProtocolBugs{
1743 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1744 },
1745 },
1746 shouldFail: true,
1747 expectedError: ":UNEXPECTED_RECORD:",
1748 },
1749 {
1750 protocol: dtls,
1751 name: "AppDataBeforeHandshake-DTLS-Empty",
1752 config: Config{
1753 Bugs: ProtocolBugs{
1754 AppDataBeforeHandshake: []byte{},
1755 },
1756 },
1757 shouldFail: true,
1758 expectedError: ":UNEXPECTED_RECORD:",
1759 },
1760 {
Adam Langley7c803a62015-06-15 15:35:05 -07001761 name: "AppDataAfterChangeCipherSpec",
1762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001763 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001764 Bugs: ProtocolBugs{
1765 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1766 },
1767 },
1768 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001769 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001770 },
1771 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001772 name: "AppDataAfterChangeCipherSpec-Empty",
1773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001774 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001775 Bugs: ProtocolBugs{
1776 AppDataAfterChangeCipherSpec: []byte{},
1777 },
1778 },
1779 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001780 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001781 },
1782 {
Adam Langley7c803a62015-06-15 15:35:05 -07001783 protocol: dtls,
1784 name: "AppDataAfterChangeCipherSpec-DTLS",
1785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001786 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001787 Bugs: ProtocolBugs{
1788 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1789 },
1790 },
1791 // BoringSSL's DTLS implementation will drop the out-of-order
1792 // application data.
1793 },
1794 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001795 protocol: dtls,
1796 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001798 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001799 Bugs: ProtocolBugs{
1800 AppDataAfterChangeCipherSpec: []byte{},
1801 },
1802 },
1803 // BoringSSL's DTLS implementation will drop the out-of-order
1804 // application data.
1805 },
1806 {
Adam Langley7c803a62015-06-15 15:35:05 -07001807 name: "AlertAfterChangeCipherSpec",
1808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001809 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001810 Bugs: ProtocolBugs{
1811 AlertAfterChangeCipherSpec: alertRecordOverflow,
1812 },
1813 },
1814 shouldFail: true,
1815 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1816 },
1817 {
1818 protocol: dtls,
1819 name: "AlertAfterChangeCipherSpec-DTLS",
1820 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001821 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001822 Bugs: ProtocolBugs{
1823 AlertAfterChangeCipherSpec: alertRecordOverflow,
1824 },
1825 },
1826 shouldFail: true,
1827 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1828 },
1829 {
1830 protocol: dtls,
1831 name: "ReorderHandshakeFragments-Small-DTLS",
1832 config: Config{
1833 Bugs: ProtocolBugs{
1834 ReorderHandshakeFragments: true,
1835 // Small enough that every handshake message is
1836 // fragmented.
1837 MaxHandshakeRecordLength: 2,
1838 },
1839 },
1840 },
1841 {
1842 protocol: dtls,
1843 name: "ReorderHandshakeFragments-Large-DTLS",
1844 config: Config{
1845 Bugs: ProtocolBugs{
1846 ReorderHandshakeFragments: true,
1847 // Large enough that no handshake message is
1848 // fragmented.
1849 MaxHandshakeRecordLength: 2048,
1850 },
1851 },
1852 },
1853 {
1854 protocol: dtls,
1855 name: "MixCompleteMessageWithFragments-DTLS",
1856 config: Config{
1857 Bugs: ProtocolBugs{
1858 ReorderHandshakeFragments: true,
1859 MixCompleteMessageWithFragments: true,
1860 MaxHandshakeRecordLength: 2,
1861 },
1862 },
1863 },
1864 {
1865 name: "SendInvalidRecordType",
1866 config: Config{
1867 Bugs: ProtocolBugs{
1868 SendInvalidRecordType: true,
1869 },
1870 },
1871 shouldFail: true,
1872 expectedError: ":UNEXPECTED_RECORD:",
1873 },
1874 {
1875 protocol: dtls,
1876 name: "SendInvalidRecordType-DTLS",
1877 config: Config{
1878 Bugs: ProtocolBugs{
1879 SendInvalidRecordType: true,
1880 },
1881 },
1882 shouldFail: true,
1883 expectedError: ":UNEXPECTED_RECORD:",
1884 },
1885 {
1886 name: "FalseStart-SkipServerSecondLeg",
1887 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001888 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001889 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1890 NextProtos: []string{"foo"},
1891 Bugs: ProtocolBugs{
1892 SkipNewSessionTicket: true,
1893 SkipChangeCipherSpec: true,
1894 SkipFinished: true,
1895 ExpectFalseStart: true,
1896 },
1897 },
1898 flags: []string{
1899 "-false-start",
1900 "-handshake-never-done",
1901 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001902 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001906 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001907 },
1908 {
1909 name: "FalseStart-SkipServerSecondLeg-Implicit",
1910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001911 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1913 NextProtos: []string{"foo"},
1914 Bugs: ProtocolBugs{
1915 SkipNewSessionTicket: true,
1916 SkipChangeCipherSpec: true,
1917 SkipFinished: true,
1918 },
1919 },
1920 flags: []string{
1921 "-implicit-handshake",
1922 "-false-start",
1923 "-handshake-never-done",
1924 "-advertise-alpn", "\x03foo",
1925 },
1926 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001927 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001928 },
1929 {
1930 testType: serverTest,
1931 name: "FailEarlyCallback",
1932 flags: []string{"-fail-early-callback"},
1933 shouldFail: true,
1934 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001935 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001936 },
1937 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001938 name: "FailCertCallback-Client-TLS12",
1939 config: Config{
1940 MaxVersion: VersionTLS12,
1941 ClientAuth: RequestClientCert,
1942 },
1943 flags: []string{"-fail-cert-callback"},
1944 shouldFail: true,
1945 expectedError: ":CERT_CB_ERROR:",
1946 expectedLocalError: "remote error: internal error",
1947 },
1948 {
1949 testType: serverTest,
1950 name: "FailCertCallback-Server-TLS12",
1951 config: Config{
1952 MaxVersion: VersionTLS12,
1953 },
1954 flags: []string{"-fail-cert-callback"},
1955 shouldFail: true,
1956 expectedError: ":CERT_CB_ERROR:",
1957 expectedLocalError: "remote error: internal error",
1958 },
1959 {
1960 name: "FailCertCallback-Client-TLS13",
1961 config: Config{
1962 MaxVersion: VersionTLS13,
1963 ClientAuth: RequestClientCert,
1964 },
1965 flags: []string{"-fail-cert-callback"},
1966 shouldFail: true,
1967 expectedError: ":CERT_CB_ERROR:",
1968 expectedLocalError: "remote error: internal error",
1969 },
1970 {
1971 testType: serverTest,
1972 name: "FailCertCallback-Server-TLS13",
1973 config: Config{
1974 MaxVersion: VersionTLS13,
1975 },
1976 flags: []string{"-fail-cert-callback"},
1977 shouldFail: true,
1978 expectedError: ":CERT_CB_ERROR:",
1979 expectedLocalError: "remote error: internal error",
1980 },
1981 {
Adam Langley7c803a62015-06-15 15:35:05 -07001982 protocol: dtls,
1983 name: "FragmentMessageTypeMismatch-DTLS",
1984 config: Config{
1985 Bugs: ProtocolBugs{
1986 MaxHandshakeRecordLength: 2,
1987 FragmentMessageTypeMismatch: true,
1988 },
1989 },
1990 shouldFail: true,
1991 expectedError: ":FRAGMENT_MISMATCH:",
1992 },
1993 {
1994 protocol: dtls,
1995 name: "FragmentMessageLengthMismatch-DTLS",
1996 config: Config{
1997 Bugs: ProtocolBugs{
1998 MaxHandshakeRecordLength: 2,
1999 FragmentMessageLengthMismatch: true,
2000 },
2001 },
2002 shouldFail: true,
2003 expectedError: ":FRAGMENT_MISMATCH:",
2004 },
2005 {
2006 protocol: dtls,
2007 name: "SplitFragments-Header-DTLS",
2008 config: Config{
2009 Bugs: ProtocolBugs{
2010 SplitFragments: 2,
2011 },
2012 },
2013 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002014 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002015 },
2016 {
2017 protocol: dtls,
2018 name: "SplitFragments-Boundary-DTLS",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 SplitFragments: dtlsRecordHeaderLen,
2022 },
2023 },
2024 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002025 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002026 },
2027 {
2028 protocol: dtls,
2029 name: "SplitFragments-Body-DTLS",
2030 config: Config{
2031 Bugs: ProtocolBugs{
2032 SplitFragments: dtlsRecordHeaderLen + 1,
2033 },
2034 },
2035 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002036 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002037 },
2038 {
2039 protocol: dtls,
2040 name: "SendEmptyFragments-DTLS",
2041 config: Config{
2042 Bugs: ProtocolBugs{
2043 SendEmptyFragments: true,
2044 },
2045 },
2046 },
2047 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002048 name: "BadFinished-Client",
2049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002050 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002051 Bugs: ProtocolBugs{
2052 BadFinished: true,
2053 },
2054 },
2055 shouldFail: true,
2056 expectedError: ":DIGEST_CHECK_FAILED:",
2057 },
2058 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002059 name: "BadFinished-Client-TLS13",
2060 config: Config{
2061 MaxVersion: VersionTLS13,
2062 Bugs: ProtocolBugs{
2063 BadFinished: true,
2064 },
2065 },
2066 shouldFail: true,
2067 expectedError: ":DIGEST_CHECK_FAILED:",
2068 },
2069 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002070 testType: serverTest,
2071 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002073 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002074 Bugs: ProtocolBugs{
2075 BadFinished: true,
2076 },
2077 },
2078 shouldFail: true,
2079 expectedError: ":DIGEST_CHECK_FAILED:",
2080 },
2081 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002082 testType: serverTest,
2083 name: "BadFinished-Server-TLS13",
2084 config: Config{
2085 MaxVersion: VersionTLS13,
2086 Bugs: ProtocolBugs{
2087 BadFinished: true,
2088 },
2089 },
2090 shouldFail: true,
2091 expectedError: ":DIGEST_CHECK_FAILED:",
2092 },
2093 {
Adam Langley7c803a62015-06-15 15:35:05 -07002094 name: "FalseStart-BadFinished",
2095 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002096 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002097 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2098 NextProtos: []string{"foo"},
2099 Bugs: ProtocolBugs{
2100 BadFinished: true,
2101 ExpectFalseStart: true,
2102 },
2103 },
2104 flags: []string{
2105 "-false-start",
2106 "-handshake-never-done",
2107 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002108 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002109 },
2110 shimWritesFirst: true,
2111 shouldFail: true,
2112 expectedError: ":DIGEST_CHECK_FAILED:",
2113 },
2114 {
2115 name: "NoFalseStart-NoALPN",
2116 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002117 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002118 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2119 Bugs: ProtocolBugs{
2120 ExpectFalseStart: true,
2121 AlertBeforeFalseStartTest: alertAccessDenied,
2122 },
2123 },
2124 flags: []string{
2125 "-false-start",
2126 },
2127 shimWritesFirst: true,
2128 shouldFail: true,
2129 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2130 expectedLocalError: "tls: peer did not false start: EOF",
2131 },
2132 {
2133 name: "NoFalseStart-NoAEAD",
2134 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002135 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002136 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2137 NextProtos: []string{"foo"},
2138 Bugs: ProtocolBugs{
2139 ExpectFalseStart: true,
2140 AlertBeforeFalseStartTest: alertAccessDenied,
2141 },
2142 },
2143 flags: []string{
2144 "-false-start",
2145 "-advertise-alpn", "\x03foo",
2146 },
2147 shimWritesFirst: true,
2148 shouldFail: true,
2149 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2150 expectedLocalError: "tls: peer did not false start: EOF",
2151 },
2152 {
2153 name: "NoFalseStart-RSA",
2154 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002155 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002156 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2157 NextProtos: []string{"foo"},
2158 Bugs: ProtocolBugs{
2159 ExpectFalseStart: true,
2160 AlertBeforeFalseStartTest: alertAccessDenied,
2161 },
2162 },
2163 flags: []string{
2164 "-false-start",
2165 "-advertise-alpn", "\x03foo",
2166 },
2167 shimWritesFirst: true,
2168 shouldFail: true,
2169 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2170 expectedLocalError: "tls: peer did not false start: EOF",
2171 },
2172 {
Adam Langley7c803a62015-06-15 15:35:05 -07002173 protocol: dtls,
2174 name: "SendSplitAlert-Sync",
2175 config: Config{
2176 Bugs: ProtocolBugs{
2177 SendSplitAlert: true,
2178 },
2179 },
2180 },
2181 {
2182 protocol: dtls,
2183 name: "SendSplitAlert-Async",
2184 config: Config{
2185 Bugs: ProtocolBugs{
2186 SendSplitAlert: true,
2187 },
2188 },
2189 flags: []string{"-async"},
2190 },
2191 {
2192 protocol: dtls,
2193 name: "PackDTLSHandshake",
2194 config: Config{
2195 Bugs: ProtocolBugs{
2196 MaxHandshakeRecordLength: 2,
2197 PackHandshakeFragments: 20,
2198 PackHandshakeRecords: 200,
2199 },
2200 },
2201 },
2202 {
Adam Langley7c803a62015-06-15 15:35:05 -07002203 name: "SendEmptyRecords-Pass",
2204 sendEmptyRecords: 32,
2205 },
2206 {
2207 name: "SendEmptyRecords",
2208 sendEmptyRecords: 33,
2209 shouldFail: true,
2210 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2211 },
2212 {
2213 name: "SendEmptyRecords-Async",
2214 sendEmptyRecords: 33,
2215 flags: []string{"-async"},
2216 shouldFail: true,
2217 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2218 },
2219 {
David Benjamine8e84b92016-08-03 15:39:47 -04002220 name: "SendWarningAlerts-Pass",
2221 config: Config{
2222 MaxVersion: VersionTLS12,
2223 },
Adam Langley7c803a62015-06-15 15:35:05 -07002224 sendWarningAlerts: 4,
2225 },
2226 {
David Benjamine8e84b92016-08-03 15:39:47 -04002227 protocol: dtls,
2228 name: "SendWarningAlerts-DTLS-Pass",
2229 config: Config{
2230 MaxVersion: VersionTLS12,
2231 },
Adam Langley7c803a62015-06-15 15:35:05 -07002232 sendWarningAlerts: 4,
2233 },
2234 {
David Benjamine8e84b92016-08-03 15:39:47 -04002235 name: "SendWarningAlerts-TLS13",
2236 config: Config{
2237 MaxVersion: VersionTLS13,
2238 },
2239 sendWarningAlerts: 4,
2240 shouldFail: true,
2241 expectedError: ":BAD_ALERT:",
2242 expectedLocalError: "remote error: error decoding message",
2243 },
2244 {
2245 name: "SendWarningAlerts",
2246 config: Config{
2247 MaxVersion: VersionTLS12,
2248 },
Adam Langley7c803a62015-06-15 15:35:05 -07002249 sendWarningAlerts: 5,
2250 shouldFail: true,
2251 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2252 },
2253 {
David Benjamine8e84b92016-08-03 15:39:47 -04002254 name: "SendWarningAlerts-Async",
2255 config: Config{
2256 MaxVersion: VersionTLS12,
2257 },
Adam Langley7c803a62015-06-15 15:35:05 -07002258 sendWarningAlerts: 5,
2259 flags: []string{"-async"},
2260 shouldFail: true,
2261 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2262 },
David Benjaminba4594a2015-06-18 18:36:15 -04002263 {
David Benjamin24e58862017-06-14 18:45:29 -04002264 name: "SendBogusAlertType",
2265 sendBogusAlertType: true,
2266 shouldFail: true,
2267 expectedError: ":UNKNOWN_ALERT_TYPE:",
2268 expectedLocalError: "remote error: illegal parameter",
2269 },
2270 {
2271 protocol: dtls,
2272 name: "SendBogusAlertType-DTLS",
2273 sendBogusAlertType: true,
2274 shouldFail: true,
2275 expectedError: ":UNKNOWN_ALERT_TYPE:",
2276 expectedLocalError: "remote error: illegal parameter",
2277 },
2278 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002279 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002280 config: Config{
2281 MaxVersion: VersionTLS13,
2282 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002283 sendKeyUpdates: 33,
2284 keyUpdateRequest: keyUpdateNotRequested,
2285 shouldFail: true,
2286 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002287 },
2288 {
David Benjaminba4594a2015-06-18 18:36:15 -04002289 name: "EmptySessionID",
2290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002291 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002292 SessionTicketsDisabled: true,
2293 },
2294 noSessionCache: true,
2295 flags: []string{"-expect-no-session"},
2296 },
David Benjamin30789da2015-08-29 22:56:45 -04002297 {
2298 name: "Unclean-Shutdown",
2299 config: Config{
2300 Bugs: ProtocolBugs{
2301 NoCloseNotify: true,
2302 ExpectCloseNotify: true,
2303 },
2304 },
2305 shimShutsDown: true,
2306 flags: []string{"-check-close-notify"},
2307 shouldFail: true,
2308 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2309 },
2310 {
2311 name: "Unclean-Shutdown-Ignored",
2312 config: Config{
2313 Bugs: ProtocolBugs{
2314 NoCloseNotify: true,
2315 },
2316 },
2317 shimShutsDown: true,
2318 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002319 {
David Benjaminfa214e42016-05-10 17:03:10 -04002320 name: "Unclean-Shutdown-Alert",
2321 config: Config{
2322 Bugs: ProtocolBugs{
2323 SendAlertOnShutdown: alertDecompressionFailure,
2324 ExpectCloseNotify: true,
2325 },
2326 },
2327 shimShutsDown: true,
2328 flags: []string{"-check-close-notify"},
2329 shouldFail: true,
2330 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2331 },
2332 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002333 name: "LargePlaintext",
2334 config: Config{
2335 Bugs: ProtocolBugs{
2336 SendLargeRecords: true,
2337 },
2338 },
2339 messageLen: maxPlaintext + 1,
2340 shouldFail: true,
2341 expectedError: ":DATA_LENGTH_TOO_LONG:",
2342 },
2343 {
2344 protocol: dtls,
2345 name: "LargePlaintext-DTLS",
2346 config: Config{
2347 Bugs: ProtocolBugs{
2348 SendLargeRecords: true,
2349 },
2350 },
2351 messageLen: maxPlaintext + 1,
2352 shouldFail: true,
2353 expectedError: ":DATA_LENGTH_TOO_LONG:",
2354 },
2355 {
2356 name: "LargeCiphertext",
2357 config: Config{
2358 Bugs: ProtocolBugs{
2359 SendLargeRecords: true,
2360 },
2361 },
2362 messageLen: maxPlaintext * 2,
2363 shouldFail: true,
2364 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2365 },
2366 {
2367 protocol: dtls,
2368 name: "LargeCiphertext-DTLS",
2369 config: Config{
2370 Bugs: ProtocolBugs{
2371 SendLargeRecords: true,
2372 },
2373 },
2374 messageLen: maxPlaintext * 2,
2375 // Unlike the other four cases, DTLS drops records which
2376 // are invalid before authentication, so the connection
2377 // does not fail.
2378 expectMessageDropped: true,
2379 },
David Benjamindd6fed92015-10-23 17:41:12 -04002380 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002381 name: "BadHelloRequest-1",
2382 renegotiate: 1,
2383 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002384 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002385 Bugs: ProtocolBugs{
2386 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2387 },
2388 },
2389 flags: []string{
2390 "-renegotiate-freely",
2391 "-expect-total-renegotiations", "1",
2392 },
2393 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002394 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002395 },
2396 {
2397 name: "BadHelloRequest-2",
2398 renegotiate: 1,
2399 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002400 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002401 Bugs: ProtocolBugs{
2402 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2403 },
2404 },
2405 flags: []string{
2406 "-renegotiate-freely",
2407 "-expect-total-renegotiations", "1",
2408 },
2409 shouldFail: true,
2410 expectedError: ":BAD_HELLO_REQUEST:",
2411 },
David Benjaminef1b0092015-11-21 14:05:44 -05002412 {
2413 testType: serverTest,
2414 name: "SupportTicketsWithSessionID",
2415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002416 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002417 SessionTicketsDisabled: true,
2418 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002419 resumeConfig: &Config{
2420 MaxVersion: VersionTLS12,
2421 },
David Benjaminef1b0092015-11-21 14:05:44 -05002422 resumeSession: true,
2423 },
David Benjamin02edcd02016-07-27 17:40:37 -04002424 {
2425 protocol: dtls,
2426 name: "DTLS-SendExtraFinished",
2427 config: Config{
2428 Bugs: ProtocolBugs{
2429 SendExtraFinished: true,
2430 },
2431 },
2432 shouldFail: true,
2433 expectedError: ":UNEXPECTED_RECORD:",
2434 },
2435 {
2436 protocol: dtls,
2437 name: "DTLS-SendExtraFinished-Reordered",
2438 config: Config{
2439 Bugs: ProtocolBugs{
2440 MaxHandshakeRecordLength: 2,
2441 ReorderHandshakeFragments: true,
2442 SendExtraFinished: true,
2443 },
2444 },
2445 shouldFail: true,
2446 expectedError: ":UNEXPECTED_RECORD:",
2447 },
David Benjamine97fb482016-07-29 09:23:07 -04002448 {
2449 testType: serverTest,
2450 name: "V2ClientHello-EmptyRecordPrefix",
2451 config: Config{
2452 // Choose a cipher suite that does not involve
2453 // elliptic curves, so no extensions are
2454 // involved.
2455 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002456 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002457 Bugs: ProtocolBugs{
2458 SendV2ClientHello: true,
2459 },
2460 },
2461 sendPrefix: string([]byte{
2462 byte(recordTypeHandshake),
2463 3, 1, // version
2464 0, 0, // length
2465 }),
2466 // A no-op empty record may not be sent before V2ClientHello.
2467 shouldFail: true,
2468 expectedError: ":WRONG_VERSION_NUMBER:",
2469 },
2470 {
2471 testType: serverTest,
2472 name: "V2ClientHello-WarningAlertPrefix",
2473 config: Config{
2474 // Choose a cipher suite that does not involve
2475 // elliptic curves, so no extensions are
2476 // involved.
2477 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002478 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002479 Bugs: ProtocolBugs{
2480 SendV2ClientHello: true,
2481 },
2482 },
2483 sendPrefix: string([]byte{
2484 byte(recordTypeAlert),
2485 3, 1, // version
2486 0, 2, // length
2487 alertLevelWarning, byte(alertDecompressionFailure),
2488 }),
2489 // A no-op warning alert may not be sent before V2ClientHello.
2490 shouldFail: true,
2491 expectedError: ":WRONG_VERSION_NUMBER:",
2492 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002493 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002494 name: "KeyUpdate-Client",
2495 config: Config{
2496 MaxVersion: VersionTLS13,
2497 },
2498 sendKeyUpdates: 1,
2499 keyUpdateRequest: keyUpdateNotRequested,
2500 },
2501 {
2502 testType: serverTest,
2503 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002504 config: Config{
2505 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002506 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002507 sendKeyUpdates: 1,
2508 keyUpdateRequest: keyUpdateNotRequested,
2509 },
2510 {
2511 name: "KeyUpdate-InvalidRequestMode",
2512 config: Config{
2513 MaxVersion: VersionTLS13,
2514 },
2515 sendKeyUpdates: 1,
2516 keyUpdateRequest: 42,
2517 shouldFail: true,
2518 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002519 },
David Benjaminabe94e32016-09-04 14:18:58 -04002520 {
David Benjaminbbba9392017-04-06 12:54:12 -04002521 // Test that KeyUpdates are acknowledged properly.
2522 name: "KeyUpdate-RequestACK",
2523 config: Config{
2524 MaxVersion: VersionTLS13,
2525 Bugs: ProtocolBugs{
2526 RejectUnsolicitedKeyUpdate: true,
2527 },
2528 },
2529 // Test the shim receiving many KeyUpdates in a row.
2530 sendKeyUpdates: 5,
2531 messageCount: 5,
2532 keyUpdateRequest: keyUpdateRequested,
2533 },
2534 {
2535 // Test that KeyUpdates are acknowledged properly if the
2536 // peer's KeyUpdate is discovered while a write is
2537 // pending.
2538 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2539 config: Config{
2540 MaxVersion: VersionTLS13,
2541 Bugs: ProtocolBugs{
2542 RejectUnsolicitedKeyUpdate: true,
2543 },
2544 },
2545 // Test the shim receiving many KeyUpdates in a row.
2546 sendKeyUpdates: 5,
2547 messageCount: 5,
2548 keyUpdateRequest: keyUpdateRequested,
2549 readWithUnfinishedWrite: true,
2550 flags: []string{"-async"},
2551 },
2552 {
David Benjaminabe94e32016-09-04 14:18:58 -04002553 name: "SendSNIWarningAlert",
2554 config: Config{
2555 MaxVersion: VersionTLS12,
2556 Bugs: ProtocolBugs{
2557 SendSNIWarningAlert: true,
2558 },
2559 },
2560 },
David Benjaminc241d792016-09-09 10:34:20 -04002561 {
2562 testType: serverTest,
2563 name: "ExtraCompressionMethods-TLS12",
2564 config: Config{
2565 MaxVersion: VersionTLS12,
2566 Bugs: ProtocolBugs{
2567 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2568 },
2569 },
2570 },
2571 {
2572 testType: serverTest,
2573 name: "ExtraCompressionMethods-TLS13",
2574 config: Config{
2575 MaxVersion: VersionTLS13,
2576 Bugs: ProtocolBugs{
2577 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2578 },
2579 },
2580 shouldFail: true,
2581 expectedError: ":INVALID_COMPRESSION_LIST:",
2582 expectedLocalError: "remote error: illegal parameter",
2583 },
2584 {
2585 testType: serverTest,
2586 name: "NoNullCompression-TLS12",
2587 config: Config{
2588 MaxVersion: VersionTLS12,
2589 Bugs: ProtocolBugs{
2590 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2591 },
2592 },
2593 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002594 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002595 expectedLocalError: "remote error: illegal parameter",
2596 },
2597 {
2598 testType: serverTest,
2599 name: "NoNullCompression-TLS13",
2600 config: Config{
2601 MaxVersion: VersionTLS13,
2602 Bugs: ProtocolBugs{
2603 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2604 },
2605 },
2606 shouldFail: true,
2607 expectedError: ":INVALID_COMPRESSION_LIST:",
2608 expectedLocalError: "remote error: illegal parameter",
2609 },
David Benjamin413e79e2017-07-01 10:11:53 -04002610 // Test that the client rejects invalid compression methods
2611 // from the server.
2612 {
2613 testType: clientTest,
2614 name: "InvalidCompressionMethod",
2615 config: Config{
2616 MaxVersion: VersionTLS12,
2617 Bugs: ProtocolBugs{
2618 SendCompressionMethod: 1,
2619 },
2620 },
2621 shouldFail: true,
2622 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2623 expectedLocalError: "remote error: illegal parameter",
2624 },
David Benjamin65ac9972016-09-02 21:35:25 -04002625 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002626 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002627 config: Config{
2628 MaxVersion: VersionTLS12,
2629 Bugs: ProtocolBugs{
2630 ExpectGREASE: true,
2631 },
2632 },
2633 flags: []string{"-enable-grease"},
2634 },
2635 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002636 name: "GREASE-Client-TLS13",
2637 config: Config{
2638 MaxVersion: VersionTLS13,
2639 Bugs: ProtocolBugs{
2640 ExpectGREASE: true,
2641 },
2642 },
2643 flags: []string{"-enable-grease"},
2644 },
2645 {
2646 testType: serverTest,
2647 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002648 config: Config{
2649 MaxVersion: VersionTLS13,
2650 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002651 // TLS 1.3 servers are expected to
2652 // always enable GREASE. TLS 1.3 is new,
2653 // so there is no existing ecosystem to
2654 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002655 ExpectGREASE: true,
2656 },
2657 },
David Benjamin65ac9972016-09-02 21:35:25 -04002658 },
David Benjamine3fbb362017-01-06 16:19:28 -05002659 {
2660 // Test the server so there is a large certificate as
2661 // well as application data.
2662 testType: serverTest,
2663 name: "MaxSendFragment",
2664 config: Config{
2665 Bugs: ProtocolBugs{
2666 MaxReceivePlaintext: 512,
2667 },
2668 },
2669 messageLen: 1024,
2670 flags: []string{
2671 "-max-send-fragment", "512",
2672 "-read-size", "1024",
2673 },
2674 },
2675 {
2676 // Test the server so there is a large certificate as
2677 // well as application data.
2678 testType: serverTest,
2679 name: "MaxSendFragment-TooLarge",
2680 config: Config{
2681 Bugs: ProtocolBugs{
2682 // Ensure that some of the records are
2683 // 512.
2684 MaxReceivePlaintext: 511,
2685 },
2686 },
2687 messageLen: 1024,
2688 flags: []string{
2689 "-max-send-fragment", "512",
2690 "-read-size", "1024",
2691 },
2692 shouldFail: true,
2693 expectedLocalError: "local error: record overflow",
2694 },
Adam Langley7c803a62015-06-15 15:35:05 -07002695 }
Adam Langley7c803a62015-06-15 15:35:05 -07002696 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002697
2698 // Test that very large messages can be received.
2699 cert := rsaCertificate
2700 for i := 0; i < 50; i++ {
2701 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2702 }
2703 testCases = append(testCases, testCase{
2704 name: "LargeMessage",
2705 config: Config{
2706 Certificates: []Certificate{cert},
2707 },
2708 })
2709 testCases = append(testCases, testCase{
2710 protocol: dtls,
2711 name: "LargeMessage-DTLS",
2712 config: Config{
2713 Certificates: []Certificate{cert},
2714 },
2715 })
2716
2717 // They are rejected if the maximum certificate chain length is capped.
2718 testCases = append(testCases, testCase{
2719 name: "LargeMessage-Reject",
2720 config: Config{
2721 Certificates: []Certificate{cert},
2722 },
2723 flags: []string{"-max-cert-list", "16384"},
2724 shouldFail: true,
2725 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2726 })
2727 testCases = append(testCases, testCase{
2728 protocol: dtls,
2729 name: "LargeMessage-Reject-DTLS",
2730 config: Config{
2731 Certificates: []Certificate{cert},
2732 },
2733 flags: []string{"-max-cert-list", "16384"},
2734 shouldFail: true,
2735 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2736 })
Adam Langley7c803a62015-06-15 15:35:05 -07002737}
2738
David Benjaminaa012042016-12-10 13:33:05 -05002739func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2740 const psk = "12345"
2741 const pskIdentity = "luggage combo"
2742
2743 var prefix string
2744 if protocol == dtls {
2745 if !ver.hasDTLS {
2746 return
2747 }
2748 prefix = "D"
2749 }
2750
2751 var cert Certificate
2752 var certFile string
2753 var keyFile string
2754 if hasComponent(suite.name, "ECDSA") {
2755 cert = ecdsaP256Certificate
2756 certFile = ecdsaP256CertificateFile
2757 keyFile = ecdsaP256KeyFile
2758 } else {
2759 cert = rsaCertificate
2760 certFile = rsaCertificateFile
2761 keyFile = rsaKeyFile
2762 }
2763
2764 var flags []string
2765 if hasComponent(suite.name, "PSK") {
2766 flags = append(flags,
2767 "-psk", psk,
2768 "-psk-identity", pskIdentity)
2769 }
2770 if hasComponent(suite.name, "NULL") {
2771 // NULL ciphers must be explicitly enabled.
2772 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2773 }
David Benjaminaa012042016-12-10 13:33:05 -05002774
2775 var shouldServerFail, shouldClientFail bool
2776 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2777 // BoringSSL clients accept ECDHE on SSLv3, but
2778 // a BoringSSL server will never select it
2779 // because the extension is missing.
2780 shouldServerFail = true
2781 }
2782 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2783 shouldClientFail = true
2784 shouldServerFail = true
2785 }
2786 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2787 shouldClientFail = true
2788 shouldServerFail = true
2789 }
2790 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2791 shouldClientFail = true
2792 shouldServerFail = true
2793 }
2794 if !isDTLSCipher(suite.name) && protocol == dtls {
2795 shouldClientFail = true
2796 shouldServerFail = true
2797 }
2798
2799 var sendCipherSuite uint16
2800 var expectedServerError, expectedClientError string
2801 serverCipherSuites := []uint16{suite.id}
2802 if shouldServerFail {
2803 expectedServerError = ":NO_SHARED_CIPHER:"
2804 }
2805 if shouldClientFail {
2806 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2807 // Configure the server to select ciphers as normal but
2808 // select an incompatible cipher in ServerHello.
2809 serverCipherSuites = nil
2810 sendCipherSuite = suite.id
2811 }
2812
David Benjamincdb6fe92017-02-07 16:06:48 -05002813 // For cipher suites and versions where exporters are defined, verify
2814 // that they interoperate.
2815 var exportKeyingMaterial int
2816 if ver.version > VersionSSL30 {
2817 exportKeyingMaterial = 1024
2818 }
2819
David Benjaminaa012042016-12-10 13:33:05 -05002820 testCases = append(testCases, testCase{
2821 testType: serverTest,
2822 protocol: protocol,
2823 name: prefix + ver.name + "-" + suite.name + "-server",
2824 config: Config{
2825 MinVersion: ver.version,
2826 MaxVersion: ver.version,
2827 CipherSuites: []uint16{suite.id},
2828 Certificates: []Certificate{cert},
2829 PreSharedKey: []byte(psk),
2830 PreSharedKeyIdentity: pskIdentity,
2831 Bugs: ProtocolBugs{
2832 AdvertiseAllConfiguredCiphers: true,
2833 },
2834 },
David Benjamina5022392017-07-10 17:40:39 -04002835 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002836 certFile: certFile,
2837 keyFile: keyFile,
2838 flags: flags,
2839 resumeSession: true,
2840 shouldFail: shouldServerFail,
2841 expectedError: expectedServerError,
2842 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002843 })
2844
2845 testCases = append(testCases, testCase{
2846 testType: clientTest,
2847 protocol: protocol,
2848 name: prefix + ver.name + "-" + suite.name + "-client",
2849 config: Config{
2850 MinVersion: ver.version,
2851 MaxVersion: ver.version,
2852 CipherSuites: serverCipherSuites,
2853 Certificates: []Certificate{cert},
2854 PreSharedKey: []byte(psk),
2855 PreSharedKeyIdentity: pskIdentity,
2856 Bugs: ProtocolBugs{
2857 IgnorePeerCipherPreferences: shouldClientFail,
2858 SendCipherSuite: sendCipherSuite,
2859 },
2860 },
David Benjamina5022392017-07-10 17:40:39 -04002861 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002862 flags: flags,
2863 resumeSession: true,
2864 shouldFail: shouldClientFail,
2865 expectedError: expectedClientError,
2866 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002867 })
2868
David Benjamin6f600d62016-12-21 16:06:54 -05002869 if shouldClientFail {
2870 return
2871 }
2872
2873 // Ensure the maximum record size is accepted.
2874 testCases = append(testCases, testCase{
2875 protocol: protocol,
2876 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2877 config: Config{
2878 MinVersion: ver.version,
2879 MaxVersion: ver.version,
2880 CipherSuites: []uint16{suite.id},
2881 Certificates: []Certificate{cert},
2882 PreSharedKey: []byte(psk),
2883 PreSharedKeyIdentity: pskIdentity,
2884 },
David Benjamina5022392017-07-10 17:40:39 -04002885 tls13Variant: ver.tls13Variant,
2886 flags: flags,
2887 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002888 })
2889
2890 // Test bad records for all ciphers. Bad records are fatal in TLS
2891 // and ignored in DTLS.
2892 var shouldFail bool
2893 var expectedError string
2894 if protocol == tls {
2895 shouldFail = true
2896 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2897 }
2898
2899 testCases = append(testCases, testCase{
2900 protocol: protocol,
2901 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2902 config: Config{
2903 MinVersion: ver.version,
2904 MaxVersion: ver.version,
2905 CipherSuites: []uint16{suite.id},
2906 Certificates: []Certificate{cert},
2907 PreSharedKey: []byte(psk),
2908 PreSharedKeyIdentity: pskIdentity,
2909 },
David Benjamina5022392017-07-10 17:40:39 -04002910 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002911 flags: flags,
2912 damageFirstWrite: true,
2913 messageLen: maxPlaintext,
2914 shouldFail: shouldFail,
2915 expectedError: expectedError,
2916 })
David Benjaminaa012042016-12-10 13:33:05 -05002917}
2918
Adam Langley95c29f32014-06-20 12:00:00 -07002919func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002920 const bogusCipher = 0xfe00
2921
Adam Langley95c29f32014-06-20 12:00:00 -07002922 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002923 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002924 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002925 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002926 }
David Benjamin2c99d282015-09-01 10:23:00 -04002927 }
Adam Langley95c29f32014-06-20 12:00:00 -07002928 }
Adam Langleya7997f12015-05-14 17:38:50 -07002929
2930 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002931 name: "NoSharedCipher",
2932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002933 MaxVersion: VersionTLS12,
2934 CipherSuites: []uint16{},
2935 },
2936 shouldFail: true,
2937 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2938 })
2939
2940 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002941 name: "NoSharedCipher-TLS13",
2942 config: Config{
2943 MaxVersion: VersionTLS13,
2944 CipherSuites: []uint16{},
2945 },
2946 shouldFail: true,
2947 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2948 })
2949
2950 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002951 name: "UnsupportedCipherSuite",
2952 config: Config{
2953 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002954 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002955 Bugs: ProtocolBugs{
2956 IgnorePeerCipherPreferences: true,
2957 },
2958 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002959 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002960 shouldFail: true,
2961 expectedError: ":WRONG_CIPHER_RETURNED:",
2962 })
2963
2964 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002965 name: "ServerHelloBogusCipher",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 Bugs: ProtocolBugs{
2969 SendCipherSuite: bogusCipher,
2970 },
2971 },
2972 shouldFail: true,
2973 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2974 })
2975 testCases = append(testCases, testCase{
2976 name: "ServerHelloBogusCipher-TLS13",
2977 config: Config{
2978 MaxVersion: VersionTLS13,
2979 Bugs: ProtocolBugs{
2980 SendCipherSuite: bogusCipher,
2981 },
2982 },
2983 shouldFail: true,
2984 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2985 })
2986
David Benjamin241ae832016-01-15 03:04:54 -05002987 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002988 testCases = append(testCases, testCase{
2989 testType: serverTest,
2990 name: "UnknownCipher",
2991 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002992 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002993 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002994 Bugs: ProtocolBugs{
2995 AdvertiseAllConfiguredCiphers: true,
2996 },
2997 },
2998 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002999
3000 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003001 testCases = append(testCases, testCase{
3002 testType: serverTest,
3003 name: "UnknownCipher-TLS13",
3004 config: Config{
3005 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003006 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003007 Bugs: ProtocolBugs{
3008 AdvertiseAllConfiguredCiphers: true,
3009 },
David Benjamin241ae832016-01-15 03:04:54 -05003010 },
3011 })
3012
David Benjamin78679342016-09-16 19:42:05 -04003013 // Test empty ECDHE_PSK identity hints work as expected.
3014 testCases = append(testCases, testCase{
3015 name: "EmptyECDHEPSKHint",
3016 config: Config{
3017 MaxVersion: VersionTLS12,
3018 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3019 PreSharedKey: []byte("secret"),
3020 },
3021 flags: []string{"-psk", "secret"},
3022 })
3023
3024 // Test empty PSK identity hints work as expected, even if an explicit
3025 // ServerKeyExchange is sent.
3026 testCases = append(testCases, testCase{
3027 name: "ExplicitEmptyPSKHint",
3028 config: Config{
3029 MaxVersion: VersionTLS12,
3030 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3031 PreSharedKey: []byte("secret"),
3032 Bugs: ProtocolBugs{
3033 AlwaysSendPreSharedKeyIdentityHint: true,
3034 },
3035 },
3036 flags: []string{"-psk", "secret"},
3037 })
David Benjamin69522112017-03-28 15:38:29 -05003038
3039 // Test that clients enforce that the server-sent certificate and cipher
3040 // suite match in TLS 1.2.
3041 testCases = append(testCases, testCase{
3042 name: "CertificateCipherMismatch-RSA",
3043 config: Config{
3044 MaxVersion: VersionTLS12,
3045 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3046 Certificates: []Certificate{rsaCertificate},
3047 Bugs: ProtocolBugs{
3048 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3049 },
3050 },
3051 shouldFail: true,
3052 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3053 })
3054 testCases = append(testCases, testCase{
3055 name: "CertificateCipherMismatch-ECDSA",
3056 config: Config{
3057 MaxVersion: VersionTLS12,
3058 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3059 Certificates: []Certificate{ecdsaP256Certificate},
3060 Bugs: ProtocolBugs{
3061 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3062 },
3063 },
3064 shouldFail: true,
3065 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3066 })
3067 testCases = append(testCases, testCase{
3068 name: "CertificateCipherMismatch-Ed25519",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3072 Certificates: []Certificate{ed25519Certificate},
3073 Bugs: ProtocolBugs{
3074 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3075 },
3076 },
3077 shouldFail: true,
3078 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3079 })
3080
3081 // Test that servers decline to select a cipher suite which is
3082 // inconsistent with their configured certificate.
3083 testCases = append(testCases, testCase{
3084 testType: serverTest,
3085 name: "ServerCipherFilter-RSA",
3086 config: Config{
3087 MaxVersion: VersionTLS12,
3088 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3089 },
3090 flags: []string{
3091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3093 },
3094 shouldFail: true,
3095 expectedError: ":NO_SHARED_CIPHER:",
3096 })
3097 testCases = append(testCases, testCase{
3098 testType: serverTest,
3099 name: "ServerCipherFilter-ECDSA",
3100 config: Config{
3101 MaxVersion: VersionTLS12,
3102 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3103 },
3104 flags: []string{
3105 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3106 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3107 },
3108 shouldFail: true,
3109 expectedError: ":NO_SHARED_CIPHER:",
3110 })
3111 testCases = append(testCases, testCase{
3112 testType: serverTest,
3113 name: "ServerCipherFilter-Ed25519",
3114 config: Config{
3115 MaxVersion: VersionTLS12,
3116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3117 },
3118 flags: []string{
3119 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3120 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3121 },
3122 shouldFail: true,
3123 expectedError: ":NO_SHARED_CIPHER:",
3124 })
David Benjamin364af782017-07-01 10:35:27 -04003125
3126 // Test cipher suite negotiation works as expected. Configure a
3127 // complicated cipher suite configuration.
3128 const negotiationTestCiphers = "" +
3129 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3130 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3131 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3132 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3133 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3134 negotiationTests := []struct {
3135 ciphers []uint16
3136 expected uint16
3137 }{
3138 // Server preferences are honored, including when
3139 // equipreference groups are involved.
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 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3149 },
3150 {
3151 []uint16{
3152 TLS_RSA_WITH_AES_256_GCM_SHA384,
3153 TLS_RSA_WITH_AES_128_CBC_SHA,
3154 TLS_RSA_WITH_AES_128_GCM_SHA256,
3155 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3156 },
3157 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3158 },
3159 {
3160 []uint16{
3161 TLS_RSA_WITH_AES_256_GCM_SHA384,
3162 TLS_RSA_WITH_AES_128_CBC_SHA,
3163 TLS_RSA_WITH_AES_128_GCM_SHA256,
3164 },
3165 TLS_RSA_WITH_AES_128_GCM_SHA256,
3166 },
3167 {
3168 []uint16{
3169 TLS_RSA_WITH_AES_256_GCM_SHA384,
3170 TLS_RSA_WITH_AES_128_CBC_SHA,
3171 },
3172 TLS_RSA_WITH_AES_128_CBC_SHA,
3173 },
3174 // Equipreference groups use the client preference.
3175 {
3176 []uint16{
3177 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3178 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3179 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3180 },
3181 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3182 },
3183 {
3184 []uint16{
3185 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3186 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3187 },
3188 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3189 },
3190 {
3191 []uint16{
3192 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3193 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3194 },
3195 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3196 },
3197 {
3198 []uint16{
3199 TLS_RSA_WITH_AES_256_GCM_SHA384,
3200 TLS_RSA_WITH_AES_256_CBC_SHA,
3201 },
3202 TLS_RSA_WITH_AES_256_GCM_SHA384,
3203 },
3204 {
3205 []uint16{
3206 TLS_RSA_WITH_AES_256_CBC_SHA,
3207 TLS_RSA_WITH_AES_256_GCM_SHA384,
3208 },
3209 TLS_RSA_WITH_AES_256_CBC_SHA,
3210 },
3211 // If there are two equipreference groups, the preferred one
3212 // takes precedence.
3213 {
3214 []uint16{
3215 TLS_RSA_WITH_AES_256_GCM_SHA384,
3216 TLS_RSA_WITH_AES_256_CBC_SHA,
3217 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3218 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3219 },
3220 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3221 },
3222 }
3223 for i, t := range negotiationTests {
3224 testCases = append(testCases, testCase{
3225 testType: serverTest,
3226 name: "CipherNegotiation-" + strconv.Itoa(i),
3227 config: Config{
3228 MaxVersion: VersionTLS12,
3229 CipherSuites: t.ciphers,
3230 },
3231 flags: []string{"-cipher", negotiationTestCiphers},
3232 expectedCipher: t.expected,
3233 })
3234 }
Adam Langley95c29f32014-06-20 12:00:00 -07003235}
3236
3237func addBadECDSASignatureTests() {
3238 for badR := BadValue(1); badR < NumBadValues; badR++ {
3239 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003240 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003241 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3242 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003243 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003244 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003245 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003246 Bugs: ProtocolBugs{
3247 BadECDSAR: badR,
3248 BadECDSAS: badS,
3249 },
3250 },
3251 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003252 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003253 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003254 testCases = append(testCases, testCase{
3255 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3256 config: Config{
3257 MaxVersion: VersionTLS13,
3258 Certificates: []Certificate{ecdsaP256Certificate},
3259 Bugs: ProtocolBugs{
3260 BadECDSAR: badR,
3261 BadECDSAS: badS,
3262 },
3263 },
3264 shouldFail: true,
3265 expectedError: ":BAD_SIGNATURE:",
3266 })
Adam Langley95c29f32014-06-20 12:00:00 -07003267 }
3268 }
3269}
3270
Adam Langley80842bd2014-06-20 12:00:00 -07003271func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003272 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003273 name: "MaxCBCPadding",
3274 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003275 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003276 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3277 Bugs: ProtocolBugs{
3278 MaxPadding: true,
3279 },
3280 },
3281 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3282 })
David Benjamin025b3d32014-07-01 19:53:04 -04003283 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003284 name: "BadCBCPadding",
3285 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003286 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003287 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3288 Bugs: ProtocolBugs{
3289 PaddingFirstByteBad: true,
3290 },
3291 },
3292 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003293 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003294 })
3295 // OpenSSL previously had an issue where the first byte of padding in
3296 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003297 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003298 name: "BadCBCPadding255",
3299 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003300 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003301 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3302 Bugs: ProtocolBugs{
3303 MaxPadding: true,
3304 PaddingFirstByteBadIf255: true,
3305 },
3306 },
3307 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3308 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003309 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003310 })
3311}
3312
Kenny Root7fdeaf12014-08-05 15:23:37 -07003313func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003314 var cbcCiphers = []struct {
3315 name string
3316 cipher uint16
3317 }{
3318 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3319 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3320 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3321 }
3322 for _, t := range cbcCiphers {
3323 testCases = append(testCases, testCase{
3324 name: "CBCRecordSplitting-" + t.name,
3325 config: Config{
3326 MaxVersion: VersionTLS10,
3327 MinVersion: VersionTLS10,
3328 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003329 Bugs: ProtocolBugs{
3330 ExpectRecordSplitting: true,
3331 },
David Benjamina1ce8562017-07-01 11:46:57 -04003332 },
3333 messageLen: -1, // read until EOF
3334 resumeSession: true,
3335 flags: []string{
3336 "-async",
3337 "-write-different-record-sizes",
3338 "-cbc-record-splitting",
3339 },
3340 })
3341 testCases = append(testCases, testCase{
3342 name: "CBCRecordSplittingPartialWrite-" + t.name,
3343 config: Config{
3344 MaxVersion: VersionTLS10,
3345 MinVersion: VersionTLS10,
3346 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003347 Bugs: ProtocolBugs{
3348 ExpectRecordSplitting: true,
3349 },
David Benjamina1ce8562017-07-01 11:46:57 -04003350 },
3351 messageLen: -1, // read until EOF
3352 flags: []string{
3353 "-async",
3354 "-write-different-record-sizes",
3355 "-cbc-record-splitting",
3356 "-partial-write",
3357 },
3358 })
3359 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003360}
3361
David Benjamin636293b2014-07-08 17:59:18 -04003362func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003363 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003364 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003365 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3366 cert, err := x509.ParseCertificate(cert.Certificate[0])
3367 if err != nil {
3368 panic(err)
3369 }
3370 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003371 }
Adam Langley2ff79332017-02-28 13:45:39 -08003372 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003373
David Benjamin636293b2014-07-08 17:59:18 -04003374 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003375 testCases = append(testCases, testCase{
3376 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003377 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003378 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003379 MinVersion: ver.version,
3380 MaxVersion: ver.version,
3381 ClientAuth: RequireAnyClientCert,
3382 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003383 },
David Benjamina5022392017-07-10 17:40:39 -04003384 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003385 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003386 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3387 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003388 },
3389 })
3390 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003391 testType: serverTest,
3392 name: ver.name + "-Server-ClientAuth-RSA",
3393 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003394 MinVersion: ver.version,
3395 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003396 Certificates: []Certificate{rsaCertificate},
3397 },
David Benjamina5022392017-07-10 17:40:39 -04003398 tls13Variant: ver.tls13Variant,
3399 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003400 })
David Benjamine098ec22014-08-27 23:13:20 -04003401 if ver.version != VersionSSL30 {
3402 testCases = append(testCases, testCase{
3403 testType: serverTest,
3404 name: ver.name + "-Server-ClientAuth-ECDSA",
3405 config: Config{
3406 MinVersion: ver.version,
3407 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003408 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003409 },
David Benjamina5022392017-07-10 17:40:39 -04003410 tls13Variant: ver.tls13Variant,
3411 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003412 })
3413 testCases = append(testCases, testCase{
3414 testType: clientTest,
3415 name: ver.name + "-Client-ClientAuth-ECDSA",
3416 config: Config{
3417 MinVersion: ver.version,
3418 MaxVersion: ver.version,
3419 ClientAuth: RequireAnyClientCert,
3420 ClientCAs: certPool,
3421 },
David Benjamina5022392017-07-10 17:40:39 -04003422 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003423 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003424 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3425 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003426 },
3427 })
3428 }
Adam Langley37646832016-08-01 16:16:46 -07003429
3430 testCases = append(testCases, testCase{
3431 name: "NoClientCertificate-" + ver.name,
3432 config: Config{
3433 MinVersion: ver.version,
3434 MaxVersion: ver.version,
3435 ClientAuth: RequireAnyClientCert,
3436 },
David Benjamina5022392017-07-10 17:40:39 -04003437 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003438 shouldFail: true,
3439 expectedLocalError: "client didn't provide a certificate",
3440 })
3441
3442 testCases = append(testCases, testCase{
3443 // Even if not configured to expect a certificate, OpenSSL will
3444 // return X509_V_OK as the verify_result.
3445 testType: serverTest,
3446 name: "NoClientCertificateRequested-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 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003455 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003456 })
3457
3458 testCases = append(testCases, testCase{
3459 // If a client certificate is not provided, OpenSSL will still
3460 // return X509_V_OK as the verify_result.
3461 testType: serverTest,
3462 name: "NoClientCertificate-Server-" + ver.name,
3463 config: Config{
3464 MinVersion: ver.version,
3465 MaxVersion: ver.version,
3466 },
David Benjamina5022392017-07-10 17:40:39 -04003467 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003468 flags: []string{
3469 "-expect-verify-result",
3470 "-verify-peer",
3471 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003472 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003473 })
3474
David Benjamin1db9e1b2016-10-07 20:51:43 -04003475 certificateRequired := "remote error: certificate required"
3476 if ver.version < VersionTLS13 {
3477 // Prior to TLS 1.3, the generic handshake_failure alert
3478 // was used.
3479 certificateRequired = "remote error: handshake failure"
3480 }
Adam Langley37646832016-08-01 16:16:46 -07003481 testCases = append(testCases, testCase{
3482 testType: serverTest,
3483 name: "RequireAnyClientCertificate-" + ver.name,
3484 config: Config{
3485 MinVersion: ver.version,
3486 MaxVersion: ver.version,
3487 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003488 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003489 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003490 shouldFail: true,
3491 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3492 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003493 })
3494
3495 if ver.version != VersionSSL30 {
3496 testCases = append(testCases, testCase{
3497 testType: serverTest,
3498 name: "SkipClientCertificate-" + ver.name,
3499 config: Config{
3500 MinVersion: ver.version,
3501 MaxVersion: ver.version,
3502 Bugs: ProtocolBugs{
3503 SkipClientCertificate: true,
3504 },
3505 },
3506 // Setting SSL_VERIFY_PEER allows anonymous clients.
3507 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003508 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003509 shouldFail: true,
3510 expectedError: ":UNEXPECTED_MESSAGE:",
3511 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003512
3513 testCases = append(testCases, testCase{
3514 testType: serverTest,
3515 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3516 config: Config{
3517 MinVersion: ver.version,
3518 MaxVersion: ver.version,
3519 },
3520 flags: []string{
3521 "-enable-channel-id",
3522 "-verify-peer-if-no-obc",
3523 },
David Benjamina5022392017-07-10 17:40:39 -04003524 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003525 shouldFail: true,
3526 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3527 expectedLocalError: certificateRequired,
3528 })
3529
3530 testCases = append(testCases, testCase{
3531 testType: serverTest,
3532 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3533 config: Config{
3534 MinVersion: ver.version,
3535 MaxVersion: ver.version,
3536 ChannelID: channelIDKey,
3537 },
3538 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003539 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003540 flags: []string{
3541 "-enable-channel-id",
3542 "-verify-peer-if-no-obc",
3543 },
3544 })
Adam Langley37646832016-08-01 16:16:46 -07003545 }
Adam Langley2ff79332017-02-28 13:45:39 -08003546
3547 testCases = append(testCases, testCase{
3548 testType: serverTest,
3549 name: ver.name + "-Server-CertReq-CA-List",
3550 config: Config{
3551 MinVersion: ver.version,
3552 MaxVersion: ver.version,
3553 Certificates: []Certificate{rsaCertificate},
3554 Bugs: ProtocolBugs{
3555 ExpectCertificateReqNames: caNames,
3556 },
3557 },
David Benjamina5022392017-07-10 17:40:39 -04003558 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003559 flags: []string{
3560 "-require-any-client-certificate",
3561 "-use-client-ca-list", encodeDERValues(caNames),
3562 },
3563 })
3564
3565 testCases = append(testCases, testCase{
3566 testType: clientTest,
3567 name: ver.name + "-Client-CertReq-CA-List",
3568 config: Config{
3569 MinVersion: ver.version,
3570 MaxVersion: ver.version,
3571 Certificates: []Certificate{rsaCertificate},
3572 ClientAuth: RequireAnyClientCert,
3573 ClientCAs: certPool,
3574 },
David Benjamina5022392017-07-10 17:40:39 -04003575 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003576 flags: []string{
3577 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3578 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3579 "-expect-client-ca-list", encodeDERValues(caNames),
3580 },
3581 })
David Benjamin636293b2014-07-08 17:59:18 -04003582 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003583
David Benjaminc032dfa2016-05-12 14:54:57 -04003584 // Client auth is only legal in certificate-based ciphers.
3585 testCases = append(testCases, testCase{
3586 testType: clientTest,
3587 name: "ClientAuth-PSK",
3588 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003589 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003590 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3591 PreSharedKey: []byte("secret"),
3592 ClientAuth: RequireAnyClientCert,
3593 },
3594 flags: []string{
3595 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3596 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3597 "-psk", "secret",
3598 },
3599 shouldFail: true,
3600 expectedError: ":UNEXPECTED_MESSAGE:",
3601 })
3602 testCases = append(testCases, testCase{
3603 testType: clientTest,
3604 name: "ClientAuth-ECDHE_PSK",
3605 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003606 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003607 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3608 PreSharedKey: []byte("secret"),
3609 ClientAuth: RequireAnyClientCert,
3610 },
3611 flags: []string{
3612 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3613 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3614 "-psk", "secret",
3615 },
3616 shouldFail: true,
3617 expectedError: ":UNEXPECTED_MESSAGE:",
3618 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003619
3620 // Regression test for a bug where the client CA list, if explicitly
3621 // set to NULL, was mis-encoded.
3622 testCases = append(testCases, testCase{
3623 testType: serverTest,
3624 name: "Null-Client-CA-List",
3625 config: Config{
3626 MaxVersion: VersionTLS12,
3627 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003628 Bugs: ProtocolBugs{
3629 ExpectCertificateReqNames: [][]byte{},
3630 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003631 },
3632 flags: []string{
3633 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003634 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003635 },
3636 })
David Benjamin636293b2014-07-08 17:59:18 -04003637}
3638
Adam Langley75712922014-10-10 16:23:43 -07003639func addExtendedMasterSecretTests() {
3640 const expectEMSFlag = "-expect-extended-master-secret"
3641
3642 for _, with := range []bool{false, true} {
3643 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003644 if with {
3645 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003646 }
3647
3648 for _, isClient := range []bool{false, true} {
3649 suffix := "-Server"
3650 testType := serverTest
3651 if isClient {
3652 suffix = "-Client"
3653 testType = clientTest
3654 }
3655
3656 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003657 // In TLS 1.3, the extension is irrelevant and
3658 // always reports as enabled.
3659 var flags []string
3660 if with || ver.version >= VersionTLS13 {
3661 flags = []string{expectEMSFlag}
3662 }
3663
Adam Langley75712922014-10-10 16:23:43 -07003664 test := testCase{
3665 testType: testType,
3666 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3667 config: Config{
3668 MinVersion: ver.version,
3669 MaxVersion: ver.version,
3670 Bugs: ProtocolBugs{
3671 NoExtendedMasterSecret: !with,
3672 RequireExtendedMasterSecret: with,
3673 },
3674 },
David Benjamina5022392017-07-10 17:40:39 -04003675 tls13Variant: ver.tls13Variant,
3676 flags: flags,
3677 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003678 }
3679 if test.shouldFail {
3680 test.expectedLocalError = "extended master secret required but not supported by peer"
3681 }
3682 testCases = append(testCases, test)
3683 }
3684 }
3685 }
3686
Adam Langleyba5934b2015-06-02 10:50:35 -07003687 for _, isClient := range []bool{false, true} {
3688 for _, supportedInFirstConnection := range []bool{false, true} {
3689 for _, supportedInResumeConnection := range []bool{false, true} {
3690 boolToWord := func(b bool) string {
3691 if b {
3692 return "Yes"
3693 }
3694 return "No"
3695 }
3696 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3697 if isClient {
3698 suffix += "Client"
3699 } else {
3700 suffix += "Server"
3701 }
3702
3703 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003704 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003705 Bugs: ProtocolBugs{
3706 RequireExtendedMasterSecret: true,
3707 },
3708 }
3709
3710 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003711 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003712 Bugs: ProtocolBugs{
3713 NoExtendedMasterSecret: true,
3714 },
3715 }
3716
3717 test := testCase{
3718 name: "ExtendedMasterSecret-" + suffix,
3719 resumeSession: true,
3720 }
3721
3722 if !isClient {
3723 test.testType = serverTest
3724 }
3725
3726 if supportedInFirstConnection {
3727 test.config = supportedConfig
3728 } else {
3729 test.config = noSupportConfig
3730 }
3731
3732 if supportedInResumeConnection {
3733 test.resumeConfig = &supportedConfig
3734 } else {
3735 test.resumeConfig = &noSupportConfig
3736 }
3737
3738 switch suffix {
3739 case "YesToYes-Client", "YesToYes-Server":
3740 // When a session is resumed, it should
3741 // still be aware that its master
3742 // secret was generated via EMS and
3743 // thus it's safe to use tls-unique.
3744 test.flags = []string{expectEMSFlag}
3745 case "NoToYes-Server":
3746 // If an original connection did not
3747 // contain EMS, but a resumption
3748 // handshake does, then a server should
3749 // not resume the session.
3750 test.expectResumeRejected = true
3751 case "YesToNo-Server":
3752 // Resuming an EMS session without the
3753 // EMS extension should cause the
3754 // server to abort the connection.
3755 test.shouldFail = true
3756 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3757 case "NoToYes-Client":
3758 // A client should abort a connection
3759 // where the server resumed a non-EMS
3760 // session but echoed the EMS
3761 // extension.
3762 test.shouldFail = true
3763 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3764 case "YesToNo-Client":
3765 // A client should abort a connection
3766 // where the server didn't echo EMS
3767 // when the session used it.
3768 test.shouldFail = true
3769 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3770 }
3771
3772 testCases = append(testCases, test)
3773 }
3774 }
3775 }
David Benjamin163c9562016-08-29 23:14:17 -04003776
3777 // Switching EMS on renegotiation is forbidden.
3778 testCases = append(testCases, testCase{
3779 name: "ExtendedMasterSecret-Renego-NoEMS",
3780 config: Config{
3781 MaxVersion: VersionTLS12,
3782 Bugs: ProtocolBugs{
3783 NoExtendedMasterSecret: true,
3784 NoExtendedMasterSecretOnRenegotiation: true,
3785 },
3786 },
3787 renegotiate: 1,
3788 flags: []string{
3789 "-renegotiate-freely",
3790 "-expect-total-renegotiations", "1",
3791 },
3792 })
3793
3794 testCases = append(testCases, testCase{
3795 name: "ExtendedMasterSecret-Renego-Upgrade",
3796 config: Config{
3797 MaxVersion: VersionTLS12,
3798 Bugs: ProtocolBugs{
3799 NoExtendedMasterSecret: true,
3800 },
3801 },
3802 renegotiate: 1,
3803 flags: []string{
3804 "-renegotiate-freely",
3805 "-expect-total-renegotiations", "1",
3806 },
3807 shouldFail: true,
3808 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3809 })
3810
3811 testCases = append(testCases, testCase{
3812 name: "ExtendedMasterSecret-Renego-Downgrade",
3813 config: Config{
3814 MaxVersion: VersionTLS12,
3815 Bugs: ProtocolBugs{
3816 NoExtendedMasterSecretOnRenegotiation: true,
3817 },
3818 },
3819 renegotiate: 1,
3820 flags: []string{
3821 "-renegotiate-freely",
3822 "-expect-total-renegotiations", "1",
3823 },
3824 shouldFail: true,
3825 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3826 })
Adam Langley75712922014-10-10 16:23:43 -07003827}
3828
David Benjamin582ba042016-07-07 12:33:25 -07003829type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003830 protocol protocol
3831 async bool
3832 splitHandshake bool
3833 packHandshakeFlight bool
3834 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003835}
3836
David Benjamin43ec06f2014-08-05 02:28:57 -04003837// Adds tests that try to cover the range of the handshake state machine, under
3838// various conditions. Some of these are redundant with other tests, but they
3839// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003840func addAllStateMachineCoverageTests() {
3841 for _, async := range []bool{false, true} {
3842 for _, protocol := range []protocol{tls, dtls} {
3843 addStateMachineCoverageTests(stateMachineTestConfig{
3844 protocol: protocol,
3845 async: async,
3846 })
3847 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003848 protocol: protocol,
3849 async: async,
3850 implicitHandshake: true,
3851 })
3852 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003853 protocol: protocol,
3854 async: async,
3855 splitHandshake: true,
3856 })
3857 if protocol == tls {
3858 addStateMachineCoverageTests(stateMachineTestConfig{
3859 protocol: protocol,
3860 async: async,
3861 packHandshakeFlight: true,
3862 })
3863 }
3864 }
3865 }
3866}
3867
3868func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003869 var tests []testCase
3870
3871 // Basic handshake, with resumption. Client and server,
3872 // session ID and session ticket.
3873 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003874 name: "Basic-Client",
3875 config: Config{
3876 MaxVersion: VersionTLS12,
3877 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003878 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003879 // Ensure session tickets are used, not session IDs.
3880 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 })
3882 tests = append(tests, testCase{
3883 name: "Basic-Client-RenewTicket",
3884 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003885 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003886 Bugs: ProtocolBugs{
3887 RenewTicketOnResume: true,
3888 },
3889 },
David Benjamin46662482016-08-17 00:51:00 -04003890 flags: []string{"-expect-ticket-renewal"},
3891 resumeSession: true,
3892 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003893 })
3894 tests = append(tests, testCase{
3895 name: "Basic-Client-NoTicket",
3896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003897 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003898 SessionTicketsDisabled: true,
3899 },
3900 resumeSession: true,
3901 })
3902 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003903 testType: serverTest,
3904 name: "Basic-Server",
3905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003906 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003907 Bugs: ProtocolBugs{
3908 RequireSessionTickets: true,
3909 },
3910 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003911 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003912 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003913 })
3914 tests = append(tests, testCase{
3915 testType: serverTest,
3916 name: "Basic-Server-NoTickets",
3917 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003918 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003919 SessionTicketsDisabled: true,
3920 },
3921 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003922 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003923 })
3924 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003925 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003926 name: "Basic-Server-EarlyCallback",
3927 config: Config{
3928 MaxVersion: VersionTLS12,
3929 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003930 flags: []string{"-use-early-callback"},
3931 resumeSession: true,
3932 })
3933
Steven Valdez143e8b32016-07-11 13:19:03 -04003934 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003935 if config.protocol == tls {
3936 tests = append(tests, testCase{
3937 name: "TLS13-1RTT-Client",
3938 config: Config{
3939 MaxVersion: VersionTLS13,
3940 MinVersion: VersionTLS13,
3941 },
David Benjamin46662482016-08-17 00:51:00 -04003942 resumeSession: true,
3943 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003944 })
3945
3946 tests = append(tests, testCase{
3947 testType: serverTest,
3948 name: "TLS13-1RTT-Server",
3949 config: Config{
3950 MaxVersion: VersionTLS13,
3951 MinVersion: VersionTLS13,
3952 },
David Benjamin46662482016-08-17 00:51:00 -04003953 resumeSession: true,
3954 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003955 // TLS 1.3 uses tickets, so the session should not be
3956 // cached statefully.
3957 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003958 })
3959
3960 tests = append(tests, testCase{
3961 name: "TLS13-HelloRetryRequest-Client",
3962 config: Config{
3963 MaxVersion: VersionTLS13,
3964 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003965 // P-384 requires a HelloRetryRequest against BoringSSL's default
3966 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003967 CurvePreferences: []CurveID{CurveP384},
3968 Bugs: ProtocolBugs{
3969 ExpectMissingKeyShare: true,
3970 },
3971 },
3972 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3973 resumeSession: true,
3974 })
3975
3976 tests = append(tests, testCase{
3977 testType: serverTest,
3978 name: "TLS13-HelloRetryRequest-Server",
3979 config: Config{
3980 MaxVersion: VersionTLS13,
3981 MinVersion: VersionTLS13,
3982 // Require a HelloRetryRequest for every curve.
3983 DefaultCurves: []CurveID{},
3984 },
3985 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3986 resumeSession: true,
3987 })
Steven Valdez2d850622017-01-11 11:34:52 -05003988
Steven Valdez2d850622017-01-11 11:34:52 -05003989 tests = append(tests, testCase{
3990 testType: clientTest,
3991 name: "TLS13-EarlyData-Client",
3992 config: Config{
3993 MaxVersion: VersionTLS13,
3994 MinVersion: VersionTLS13,
3995 MaxEarlyDataSize: 16384,
3996 },
Steven Valdeze831a812017-03-09 14:56:07 -05003997 resumeConfig: &Config{
3998 MaxVersion: VersionTLS13,
3999 MinVersion: VersionTLS13,
4000 MaxEarlyDataSize: 16384,
4001 Bugs: ProtocolBugs{
4002 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4003 },
4004 },
Steven Valdez2d850622017-01-11 11:34:52 -05004005 resumeSession: true,
4006 flags: []string{
4007 "-enable-early-data",
4008 "-expect-early-data-info",
4009 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004010 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004011 },
4012 })
4013
4014 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004015 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004016 name: "TLS13Experiment-EarlyData-Client",
4017 config: Config{
4018 MaxVersion: VersionTLS13,
4019 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004020 MaxEarlyDataSize: 16384,
4021 },
4022 resumeConfig: &Config{
4023 MaxVersion: VersionTLS13,
4024 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004025 MaxEarlyDataSize: 16384,
4026 Bugs: ProtocolBugs{
4027 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4028 },
4029 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004030 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004031 resumeSession: true,
4032 flags: []string{
4033 "-enable-early-data",
4034 "-expect-early-data-info",
4035 "-expect-accept-early-data",
4036 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004037 },
4038 })
4039
4040 tests = append(tests, testCase{
4041 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004042 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4043 config: Config{
4044 MaxVersion: VersionTLS13,
4045 MinVersion: VersionTLS13,
4046 TLS13Variant: TLS13RecordTypeExperiment,
4047 MaxEarlyDataSize: 16384,
4048 },
4049 resumeConfig: &Config{
4050 MaxVersion: VersionTLS13,
4051 MinVersion: VersionTLS13,
4052 TLS13Variant: TLS13RecordTypeExperiment,
4053 MaxEarlyDataSize: 16384,
4054 Bugs: ProtocolBugs{
4055 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4056 },
4057 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004058 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004059 resumeSession: true,
4060 flags: []string{
4061 "-enable-early-data",
4062 "-expect-early-data-info",
4063 "-expect-accept-early-data",
4064 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004065 },
4066 })
4067
4068 tests = append(tests, testCase{
4069 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004070 name: "TLS13-EarlyData-TooMuchData-Client",
4071 config: Config{
4072 MaxVersion: VersionTLS13,
4073 MinVersion: VersionTLS13,
4074 MaxEarlyDataSize: 2,
4075 },
4076 resumeConfig: &Config{
4077 MaxVersion: VersionTLS13,
4078 MinVersion: VersionTLS13,
4079 MaxEarlyDataSize: 2,
4080 Bugs: ProtocolBugs{
4081 ExpectEarlyData: [][]byte{{'h', 'e'}},
4082 },
4083 },
4084 resumeShimPrefix: "llo",
4085 resumeSession: true,
4086 flags: []string{
4087 "-enable-early-data",
4088 "-expect-early-data-info",
4089 "-expect-accept-early-data",
4090 "-on-resume-shim-writes-first",
4091 },
4092 })
4093
4094 // Unfinished writes can only be tested when operations are async. EarlyData
4095 // can't be tested as part of an ImplicitHandshake in this case since
4096 // otherwise the early data will be sent as normal data.
4097 if config.async && !config.implicitHandshake {
4098 tests = append(tests, testCase{
4099 testType: clientTest,
4100 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4101 config: Config{
4102 MaxVersion: VersionTLS13,
4103 MinVersion: VersionTLS13,
4104 MaxEarlyDataSize: 16384,
4105 },
4106 resumeConfig: &Config{
4107 MaxVersion: VersionTLS13,
4108 MinVersion: VersionTLS13,
4109 MaxEarlyDataSize: 16384,
4110 Bugs: ProtocolBugs{
4111 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4112 },
4113 },
4114 resumeSession: true,
4115 flags: []string{
4116 "-enable-early-data",
4117 "-expect-early-data-info",
4118 "-expect-accept-early-data",
4119 "-on-resume-read-with-unfinished-write",
4120 "-on-resume-shim-writes-first",
4121 },
4122 })
4123
4124 // Rejected unfinished writes are discarded (from the
4125 // perspective of the calling application) on 0-RTT
4126 // reject.
4127 tests = append(tests, testCase{
4128 testType: clientTest,
4129 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4130 config: Config{
4131 MaxVersion: VersionTLS13,
4132 MinVersion: VersionTLS13,
4133 MaxEarlyDataSize: 16384,
4134 },
4135 resumeConfig: &Config{
4136 MaxVersion: VersionTLS13,
4137 MinVersion: VersionTLS13,
4138 MaxEarlyDataSize: 16384,
4139 Bugs: ProtocolBugs{
4140 AlwaysRejectEarlyData: true,
4141 },
4142 },
4143 resumeSession: true,
4144 flags: []string{
4145 "-enable-early-data",
4146 "-expect-early-data-info",
4147 "-expect-reject-early-data",
4148 "-on-resume-read-with-unfinished-write",
4149 "-on-resume-shim-writes-first",
4150 },
4151 })
4152 }
4153
4154 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004155 testType: serverTest,
4156 name: "TLS13-EarlyData-Server",
4157 config: Config{
4158 MaxVersion: VersionTLS13,
4159 MinVersion: VersionTLS13,
4160 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004161 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004162 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004163 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004164 },
4165 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004166 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004167 resumeSession: true,
4168 flags: []string{
4169 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004170 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004171 },
4172 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004173
4174 tests = append(tests, testCase{
4175 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004176 name: "TLS13Experiment-EarlyData-Server",
4177 config: Config{
4178 MaxVersion: VersionTLS13,
4179 MinVersion: VersionTLS13,
4180 TLS13Variant: TLS13Experiment,
4181 Bugs: ProtocolBugs{
4182 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4183 ExpectEarlyDataAccepted: true,
4184 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4185 },
4186 },
4187 messageCount: 2,
4188 resumeSession: true,
4189 flags: []string{
4190 "-enable-early-data",
4191 "-expect-accept-early-data",
4192 "-tls13-variant", "1",
4193 },
4194 })
4195
4196 tests = append(tests, testCase{
4197 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004198 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4199 config: Config{
4200 MaxVersion: VersionTLS13,
4201 MinVersion: VersionTLS13,
4202 TLS13Variant: TLS13RecordTypeExperiment,
4203 Bugs: ProtocolBugs{
4204 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4205 ExpectEarlyDataAccepted: true,
4206 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4207 },
4208 },
4209 messageCount: 2,
4210 resumeSession: true,
4211 flags: []string{
4212 "-enable-early-data",
4213 "-expect-accept-early-data",
4214 "-tls13-variant", "2",
4215 },
4216 })
4217
4218 tests = append(tests, testCase{
4219 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004220 name: "TLS13-MaxEarlyData-Server",
4221 config: Config{
4222 MaxVersion: VersionTLS13,
4223 MinVersion: VersionTLS13,
4224 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004225 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004226 ExpectEarlyDataAccepted: true,
4227 },
4228 },
4229 messageCount: 2,
4230 resumeSession: true,
4231 flags: []string{
4232 "-enable-early-data",
4233 "-expect-accept-early-data",
4234 },
4235 shouldFail: true,
4236 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4237 })
David Benjamine73c7f42016-08-17 00:29:33 -04004238 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004239
David Benjamin760b1dd2015-05-15 23:33:48 -04004240 // TLS client auth.
4241 tests = append(tests, testCase{
4242 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004243 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004244 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004245 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004246 ClientAuth: RequestClientCert,
4247 },
4248 })
4249 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004250 testType: serverTest,
4251 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004252 config: Config{
4253 MaxVersion: VersionTLS12,
4254 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004255 // Setting SSL_VERIFY_PEER allows anonymous clients.
4256 flags: []string{"-verify-peer"},
4257 })
David Benjamin582ba042016-07-07 12:33:25 -07004258 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004259 tests = append(tests, testCase{
4260 testType: clientTest,
4261 name: "ClientAuth-NoCertificate-Client-SSL3",
4262 config: Config{
4263 MaxVersion: VersionSSL30,
4264 ClientAuth: RequestClientCert,
4265 },
4266 })
4267 tests = append(tests, testCase{
4268 testType: serverTest,
4269 name: "ClientAuth-NoCertificate-Server-SSL3",
4270 config: Config{
4271 MaxVersion: VersionSSL30,
4272 },
4273 // Setting SSL_VERIFY_PEER allows anonymous clients.
4274 flags: []string{"-verify-peer"},
4275 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004276 tests = append(tests, testCase{
4277 testType: clientTest,
4278 name: "ClientAuth-NoCertificate-Client-TLS13",
4279 config: Config{
4280 MaxVersion: VersionTLS13,
4281 ClientAuth: RequestClientCert,
4282 },
4283 })
4284 tests = append(tests, testCase{
4285 testType: serverTest,
4286 name: "ClientAuth-NoCertificate-Server-TLS13",
4287 config: Config{
4288 MaxVersion: VersionTLS13,
4289 },
4290 // Setting SSL_VERIFY_PEER allows anonymous clients.
4291 flags: []string{"-verify-peer"},
4292 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004293 }
4294 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004295 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004296 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004297 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004298 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004299 ClientAuth: RequireAnyClientCert,
4300 },
4301 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004302 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4303 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004304 },
4305 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004306 tests = append(tests, testCase{
4307 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004308 name: "ClientAuth-RSA-Client-TLS13",
4309 config: Config{
4310 MaxVersion: VersionTLS13,
4311 ClientAuth: RequireAnyClientCert,
4312 },
4313 flags: []string{
4314 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4315 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4316 },
4317 })
4318 tests = append(tests, testCase{
4319 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004320 name: "ClientAuth-ECDSA-Client",
4321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004323 ClientAuth: RequireAnyClientCert,
4324 },
4325 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004326 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4327 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004328 },
4329 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004330 tests = append(tests, testCase{
4331 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004332 name: "ClientAuth-ECDSA-Client-TLS13",
4333 config: Config{
4334 MaxVersion: VersionTLS13,
4335 ClientAuth: RequireAnyClientCert,
4336 },
4337 flags: []string{
4338 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4339 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4340 },
4341 })
4342 tests = append(tests, testCase{
4343 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004344 name: "ClientAuth-NoCertificate-OldCallback",
4345 config: Config{
4346 MaxVersion: VersionTLS12,
4347 ClientAuth: RequestClientCert,
4348 },
4349 flags: []string{"-use-old-client-cert-callback"},
4350 })
4351 tests = append(tests, testCase{
4352 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004353 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4354 config: Config{
4355 MaxVersion: VersionTLS13,
4356 ClientAuth: RequestClientCert,
4357 },
4358 flags: []string{"-use-old-client-cert-callback"},
4359 })
4360 tests = append(tests, testCase{
4361 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004362 name: "ClientAuth-OldCallback",
4363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004364 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004365 ClientAuth: RequireAnyClientCert,
4366 },
4367 flags: []string{
4368 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4369 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4370 "-use-old-client-cert-callback",
4371 },
4372 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004373 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004374 testType: clientTest,
4375 name: "ClientAuth-OldCallback-TLS13",
4376 config: Config{
4377 MaxVersion: VersionTLS13,
4378 ClientAuth: RequireAnyClientCert,
4379 },
4380 flags: []string{
4381 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4382 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4383 "-use-old-client-cert-callback",
4384 },
4385 })
4386 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004387 testType: serverTest,
4388 name: "ClientAuth-Server",
4389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004390 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004391 Certificates: []Certificate{rsaCertificate},
4392 },
4393 flags: []string{"-require-any-client-certificate"},
4394 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004395 tests = append(tests, testCase{
4396 testType: serverTest,
4397 name: "ClientAuth-Server-TLS13",
4398 config: Config{
4399 MaxVersion: VersionTLS13,
4400 Certificates: []Certificate{rsaCertificate},
4401 },
4402 flags: []string{"-require-any-client-certificate"},
4403 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004404
David Benjamin4c3ddf72016-06-29 18:13:53 -04004405 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004406 tests = append(tests, testCase{
4407 testType: serverTest,
4408 name: "Basic-Server-RSA",
4409 config: Config{
4410 MaxVersion: VersionTLS12,
4411 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4412 },
4413 flags: []string{
4414 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4415 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4416 },
4417 })
4418 tests = append(tests, testCase{
4419 testType: serverTest,
4420 name: "Basic-Server-ECDHE-RSA",
4421 config: Config{
4422 MaxVersion: VersionTLS12,
4423 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4424 },
4425 flags: []string{
4426 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4427 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4428 },
4429 })
4430 tests = append(tests, testCase{
4431 testType: serverTest,
4432 name: "Basic-Server-ECDHE-ECDSA",
4433 config: Config{
4434 MaxVersion: VersionTLS12,
4435 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4436 },
4437 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004438 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4439 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004440 },
4441 })
David Benjamin69522112017-03-28 15:38:29 -05004442 tests = append(tests, testCase{
4443 testType: serverTest,
4444 name: "Basic-Server-Ed25519",
4445 config: Config{
4446 MaxVersion: VersionTLS12,
4447 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4448 },
4449 flags: []string{
4450 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4451 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4452 "-enable-ed25519",
4453 },
4454 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004455
David Benjamin760b1dd2015-05-15 23:33:48 -04004456 // No session ticket support; server doesn't send NewSessionTicket.
4457 tests = append(tests, testCase{
4458 name: "SessionTicketsDisabled-Client",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 SessionTicketsDisabled: true,
4462 },
4463 })
4464 tests = append(tests, testCase{
4465 testType: serverTest,
4466 name: "SessionTicketsDisabled-Server",
4467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004468 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004469 SessionTicketsDisabled: true,
4470 },
4471 })
4472
4473 // Skip ServerKeyExchange in PSK key exchange if there's no
4474 // identity hint.
4475 tests = append(tests, testCase{
4476 name: "EmptyPSKHint-Client",
4477 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004478 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004479 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4480 PreSharedKey: []byte("secret"),
4481 },
4482 flags: []string{"-psk", "secret"},
4483 })
4484 tests = append(tests, testCase{
4485 testType: serverTest,
4486 name: "EmptyPSKHint-Server",
4487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004488 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004489 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4490 PreSharedKey: []byte("secret"),
4491 },
4492 flags: []string{"-psk", "secret"},
4493 })
4494
David Benjamin4c3ddf72016-06-29 18:13:53 -04004495 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004496 tests = append(tests, testCase{
4497 testType: clientTest,
4498 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004499 config: Config{
4500 MaxVersion: VersionTLS12,
4501 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004502 flags: []string{
4503 "-enable-ocsp-stapling",
4504 "-expect-ocsp-response",
4505 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004506 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004507 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004508 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004509 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004510 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004511 testType: serverTest,
4512 name: "OCSPStapling-Server",
4513 config: Config{
4514 MaxVersion: VersionTLS12,
4515 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004516 expectedOCSPResponse: testOCSPResponse,
4517 flags: []string{
4518 "-ocsp-response",
4519 base64.StdEncoding.EncodeToString(testOCSPResponse),
4520 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004521 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004522 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004523 tests = append(tests, testCase{
4524 testType: clientTest,
4525 name: "OCSPStapling-Client-TLS13",
4526 config: Config{
4527 MaxVersion: VersionTLS13,
4528 },
4529 flags: []string{
4530 "-enable-ocsp-stapling",
4531 "-expect-ocsp-response",
4532 base64.StdEncoding.EncodeToString(testOCSPResponse),
4533 "-verify-peer",
4534 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004535 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004536 })
4537 tests = append(tests, testCase{
4538 testType: serverTest,
4539 name: "OCSPStapling-Server-TLS13",
4540 config: Config{
4541 MaxVersion: VersionTLS13,
4542 },
4543 expectedOCSPResponse: testOCSPResponse,
4544 flags: []string{
4545 "-ocsp-response",
4546 base64.StdEncoding.EncodeToString(testOCSPResponse),
4547 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004548 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004549 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004550
David Benjamin4c3ddf72016-06-29 18:13:53 -04004551 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004552 for _, vers := range tlsVersions {
4553 if config.protocol == dtls && !vers.hasDTLS {
4554 continue
4555 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004556 for _, useCustomCallback := range []bool{false, true} {
4557 for _, testType := range []testType{clientTest, serverTest} {
4558 suffix := "-Client"
4559 if testType == serverTest {
4560 suffix = "-Server"
4561 }
4562 suffix += "-" + vers.name
4563 if useCustomCallback {
4564 suffix += "-CustomCallback"
4565 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004566
David Benjamin3a1dd462017-07-11 16:13:10 -04004567 flags := []string{"-verify-peer"}
4568 if testType == serverTest {
4569 flags = append(flags, "-require-any-client-certificate")
4570 }
4571 if useCustomCallback {
4572 flags = append(flags, "-use-custom-verify-callback")
4573 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004574
David Benjamin3a1dd462017-07-11 16:13:10 -04004575 tests = append(tests, testCase{
4576 testType: testType,
4577 name: "CertificateVerificationSucceed" + suffix,
4578 config: Config{
4579 MaxVersion: vers.version,
4580 Certificates: []Certificate{rsaCertificate},
4581 },
4582 tls13Variant: vers.tls13Variant,
4583 flags: append([]string{"-expect-verify-result"}, flags...),
4584 resumeSession: true,
4585 })
4586 tests = append(tests, testCase{
4587 testType: testType,
4588 name: "CertificateVerificationFail" + suffix,
4589 config: Config{
4590 MaxVersion: vers.version,
4591 Certificates: []Certificate{rsaCertificate},
4592 },
4593 tls13Variant: vers.tls13Variant,
4594 flags: append([]string{"-verify-fail"}, flags...),
4595 shouldFail: true,
4596 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4597 })
4598 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004599 }
4600
4601 // By default, the client is in a soft fail mode where the peer
4602 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004603 tests = append(tests, testCase{
4604 testType: clientTest,
4605 name: "CertificateVerificationSoftFail-" + vers.name,
4606 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004607 MaxVersion: vers.version,
4608 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004609 },
David Benjamina5022392017-07-10 17:40:39 -04004610 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004611 flags: []string{
4612 "-verify-fail",
4613 "-expect-verify-result",
4614 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004615 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004616 })
4617 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004618
David Benjamin1d4f4c02016-07-26 18:03:08 -04004619 tests = append(tests, testCase{
4620 name: "ShimSendAlert",
4621 flags: []string{"-send-alert"},
4622 shimWritesFirst: true,
4623 shouldFail: true,
4624 expectedLocalError: "remote error: decompression failure",
4625 })
4626
David Benjamin582ba042016-07-07 12:33:25 -07004627 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004628 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004629 name: "Renegotiate-Client",
4630 config: Config{
4631 MaxVersion: VersionTLS12,
4632 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004633 renegotiate: 1,
4634 flags: []string{
4635 "-renegotiate-freely",
4636 "-expect-total-renegotiations", "1",
4637 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004638 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004639
David Benjamin47921102016-07-28 11:29:18 -04004640 tests = append(tests, testCase{
4641 name: "SendHalfHelloRequest",
4642 config: Config{
4643 MaxVersion: VersionTLS12,
4644 Bugs: ProtocolBugs{
4645 PackHelloRequestWithFinished: config.packHandshakeFlight,
4646 },
4647 },
4648 sendHalfHelloRequest: true,
4649 flags: []string{"-renegotiate-ignore"},
4650 shouldFail: true,
4651 expectedError: ":UNEXPECTED_RECORD:",
4652 })
4653
David Benjamin760b1dd2015-05-15 23:33:48 -04004654 // NPN on client and server; results in post-handshake message.
4655 tests = append(tests, testCase{
4656 name: "NPN-Client",
4657 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004658 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004659 NextProtos: []string{"foo"},
4660 },
4661 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004662 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004663 expectedNextProto: "foo",
4664 expectedNextProtoType: npn,
4665 })
4666 tests = append(tests, testCase{
4667 testType: serverTest,
4668 name: "NPN-Server",
4669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004670 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004671 NextProtos: []string{"bar"},
4672 },
4673 flags: []string{
4674 "-advertise-npn", "\x03foo\x03bar\x03baz",
4675 "-expect-next-proto", "bar",
4676 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004677 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004678 expectedNextProto: "bar",
4679 expectedNextProtoType: npn,
4680 })
4681
4682 // TODO(davidben): Add tests for when False Start doesn't trigger.
4683
4684 // Client does False Start and negotiates NPN.
4685 tests = append(tests, testCase{
4686 name: "FalseStart",
4687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4690 NextProtos: []string{"foo"},
4691 Bugs: ProtocolBugs{
4692 ExpectFalseStart: true,
4693 },
4694 },
4695 flags: []string{
4696 "-false-start",
4697 "-select-next-proto", "foo",
4698 },
4699 shimWritesFirst: true,
4700 resumeSession: true,
4701 })
4702
4703 // Client does False Start and negotiates ALPN.
4704 tests = append(tests, testCase{
4705 name: "FalseStart-ALPN",
4706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004707 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4709 NextProtos: []string{"foo"},
4710 Bugs: ProtocolBugs{
4711 ExpectFalseStart: true,
4712 },
4713 },
4714 flags: []string{
4715 "-false-start",
4716 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004717 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004718 },
4719 shimWritesFirst: true,
4720 resumeSession: true,
4721 })
4722
David Benjamin760b1dd2015-05-15 23:33:48 -04004723 // False Start without session tickets.
4724 tests = append(tests, testCase{
4725 name: "FalseStart-SessionTicketsDisabled",
4726 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4729 NextProtos: []string{"foo"},
4730 SessionTicketsDisabled: true,
4731 Bugs: ProtocolBugs{
4732 ExpectFalseStart: true,
4733 },
4734 },
4735 flags: []string{
4736 "-false-start",
4737 "-select-next-proto", "foo",
4738 },
4739 shimWritesFirst: true,
4740 })
4741
4742 // Server parses a V2ClientHello.
4743 tests = append(tests, testCase{
4744 testType: serverTest,
4745 name: "SendV2ClientHello",
4746 config: Config{
4747 // Choose a cipher suite that does not involve
4748 // elliptic curves, so no extensions are
4749 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004750 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004751 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004752 Bugs: ProtocolBugs{
4753 SendV2ClientHello: true,
4754 },
4755 },
4756 })
4757
Nick Harper60a85cb2016-09-23 16:25:11 -07004758 // Test Channel ID
4759 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004760 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004761 continue
4762 }
4763 // Client sends a Channel ID.
4764 tests = append(tests, testCase{
4765 name: "ChannelID-Client-" + ver.name,
4766 config: Config{
4767 MaxVersion: ver.version,
4768 RequestChannelID: true,
4769 },
David Benjamina5022392017-07-10 17:40:39 -04004770 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004771 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4772 resumeSession: true,
4773 expectChannelID: true,
4774 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004775
Nick Harper60a85cb2016-09-23 16:25:11 -07004776 // Server accepts a Channel ID.
4777 tests = append(tests, testCase{
4778 testType: serverTest,
4779 name: "ChannelID-Server-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 ChannelID: channelIDKey,
4783 },
David Benjamina5022392017-07-10 17:40:39 -04004784 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004785 flags: []string{
4786 "-expect-channel-id",
4787 base64.StdEncoding.EncodeToString(channelIDBytes),
4788 },
4789 resumeSession: true,
4790 expectChannelID: true,
4791 })
4792
4793 tests = append(tests, testCase{
4794 testType: serverTest,
4795 name: "InvalidChannelIDSignature-" + ver.name,
4796 config: Config{
4797 MaxVersion: ver.version,
4798 ChannelID: channelIDKey,
4799 Bugs: ProtocolBugs{
4800 InvalidChannelIDSignature: true,
4801 },
4802 },
David Benjamina5022392017-07-10 17:40:39 -04004803 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004804 flags: []string{"-enable-channel-id"},
4805 shouldFail: true,
4806 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4807 })
David Benjamin634f4752017-07-01 11:08:41 -04004808
4809 if ver.version < VersionTLS13 {
4810 // Channel ID requires ECDHE ciphers.
4811 tests = append(tests, testCase{
4812 testType: serverTest,
4813 name: "ChannelID-NoECDHE-" + ver.name,
4814 config: Config{
4815 MaxVersion: ver.version,
4816 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4817 ChannelID: channelIDKey,
4818 },
4819 expectChannelID: false,
4820 flags: []string{"-enable-channel-id"},
4821 })
4822
4823 // Sanity-check setting expectChannelID false works.
4824 tests = append(tests, testCase{
4825 testType: serverTest,
4826 name: "ChannelID-ECDHE-" + ver.name,
4827 config: Config{
4828 MaxVersion: ver.version,
4829 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4830 ChannelID: channelIDKey,
4831 },
4832 expectChannelID: false,
4833 flags: []string{"-enable-channel-id"},
4834 shouldFail: true,
4835 expectedLocalError: "channel ID unexpectedly negotiated",
4836 })
4837 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004838 }
David Benjamin30789da2015-08-29 22:56:45 -04004839
David Benjaminf8fcdf32016-06-08 15:56:13 -04004840 // Channel ID and NPN at the same time, to ensure their relative
4841 // ordering is correct.
4842 tests = append(tests, testCase{
4843 name: "ChannelID-NPN-Client",
4844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004845 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004846 RequestChannelID: true,
4847 NextProtos: []string{"foo"},
4848 },
4849 flags: []string{
4850 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4851 "-select-next-proto", "foo",
4852 },
4853 resumeSession: true,
4854 expectChannelID: true,
4855 expectedNextProto: "foo",
4856 expectedNextProtoType: npn,
4857 })
4858 tests = append(tests, testCase{
4859 testType: serverTest,
4860 name: "ChannelID-NPN-Server",
4861 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004862 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004863 ChannelID: channelIDKey,
4864 NextProtos: []string{"bar"},
4865 },
4866 flags: []string{
4867 "-expect-channel-id",
4868 base64.StdEncoding.EncodeToString(channelIDBytes),
4869 "-advertise-npn", "\x03foo\x03bar\x03baz",
4870 "-expect-next-proto", "bar",
4871 },
4872 resumeSession: true,
4873 expectChannelID: true,
4874 expectedNextProto: "bar",
4875 expectedNextProtoType: npn,
4876 })
4877
David Benjamin30789da2015-08-29 22:56:45 -04004878 // Bidirectional shutdown with the runner initiating.
4879 tests = append(tests, testCase{
4880 name: "Shutdown-Runner",
4881 config: Config{
4882 Bugs: ProtocolBugs{
4883 ExpectCloseNotify: true,
4884 },
4885 },
4886 flags: []string{"-check-close-notify"},
4887 })
4888
David Benjamine3843d42017-03-25 18:00:56 -05004889 if !config.implicitHandshake {
4890 // Bidirectional shutdown with the shim initiating. The runner,
4891 // in the meantime, sends garbage before the close_notify which
4892 // the shim must ignore. This test is disabled under implicit
4893 // handshake tests because the shim never reads or writes.
4894 tests = append(tests, testCase{
4895 name: "Shutdown-Shim",
4896 config: Config{
4897 MaxVersion: VersionTLS12,
4898 Bugs: ProtocolBugs{
4899 ExpectCloseNotify: true,
4900 },
David Benjamin30789da2015-08-29 22:56:45 -04004901 },
David Benjamine3843d42017-03-25 18:00:56 -05004902 shimShutsDown: true,
4903 sendEmptyRecords: 1,
4904 sendWarningAlerts: 1,
4905 flags: []string{"-check-close-notify"},
4906 })
4907 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004908 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004909 // TODO(davidben): DTLS 1.3 will want a similar thing for
4910 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004911 tests = append(tests, testCase{
4912 name: "SkipHelloVerifyRequest",
4913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004914 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004915 Bugs: ProtocolBugs{
4916 SkipHelloVerifyRequest: true,
4917 },
4918 },
4919 })
4920 }
4921
David Benjamin760b1dd2015-05-15 23:33:48 -04004922 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004923 test.protocol = config.protocol
4924 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004925 test.name += "-DTLS"
4926 }
David Benjamin582ba042016-07-07 12:33:25 -07004927 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004928 test.name += "-Async"
4929 test.flags = append(test.flags, "-async")
4930 } else {
4931 test.name += "-Sync"
4932 }
David Benjamin582ba042016-07-07 12:33:25 -07004933 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004934 test.name += "-SplitHandshakeRecords"
4935 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004936 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004937 test.config.Bugs.MaxPacketLength = 256
4938 test.flags = append(test.flags, "-mtu", "256")
4939 }
4940 }
David Benjamin582ba042016-07-07 12:33:25 -07004941 if config.packHandshakeFlight {
4942 test.name += "-PackHandshakeFlight"
4943 test.config.Bugs.PackHandshakeFlight = true
4944 }
David Benjamine3843d42017-03-25 18:00:56 -05004945 if config.implicitHandshake {
4946 test.name += "-ImplicitHandshake"
4947 test.flags = append(test.flags, "-implicit-handshake")
4948 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004949 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004950 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004951}
4952
Adam Langley524e7172015-02-20 16:04:00 -08004953func addDDoSCallbackTests() {
4954 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004955 for _, resume := range []bool{false, true} {
4956 suffix := "Resume"
4957 if resume {
4958 suffix = "No" + suffix
4959 }
4960
4961 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004962 testType: serverTest,
4963 name: "Server-DDoS-OK-" + suffix,
4964 config: Config{
4965 MaxVersion: VersionTLS12,
4966 },
Adam Langley524e7172015-02-20 16:04:00 -08004967 flags: []string{"-install-ddos-callback"},
4968 resumeSession: resume,
4969 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004970 testCases = append(testCases, testCase{
4971 testType: serverTest,
4972 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4973 config: Config{
4974 MaxVersion: VersionTLS13,
4975 },
4976 flags: []string{"-install-ddos-callback"},
4977 resumeSession: resume,
4978 })
Adam Langley524e7172015-02-20 16:04:00 -08004979
4980 failFlag := "-fail-ddos-callback"
4981 if resume {
4982 failFlag = "-fail-second-ddos-callback"
4983 }
4984 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004985 testType: serverTest,
4986 name: "Server-DDoS-Reject-" + suffix,
4987 config: Config{
4988 MaxVersion: VersionTLS12,
4989 },
David Benjamin2c66e072016-09-16 15:58:00 -04004990 flags: []string{"-install-ddos-callback", failFlag},
4991 resumeSession: resume,
4992 shouldFail: true,
4993 expectedError: ":CONNECTION_REJECTED:",
4994 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004995 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004996 testCases = append(testCases, testCase{
4997 testType: serverTest,
4998 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4999 config: Config{
5000 MaxVersion: VersionTLS13,
5001 },
David Benjamin2c66e072016-09-16 15:58:00 -04005002 flags: []string{"-install-ddos-callback", failFlag},
5003 resumeSession: resume,
5004 shouldFail: true,
5005 expectedError: ":CONNECTION_REJECTED:",
5006 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005007 })
Adam Langley524e7172015-02-20 16:04:00 -08005008 }
5009}
5010
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005011func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005012 for _, protocol := range []protocol{tls, dtls} {
5013 for _, shimVers := range allVersions(protocol) {
5014 // Assemble flags to disable all newer versions on the shim.
5015 var flags []string
5016 for _, vers := range allVersions(protocol) {
5017 if vers.version > shimVers.version {
5018 flags = append(flags, vers.excludeFlag)
5019 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005020 }
Steven Valdez520e1222017-06-13 12:45:25 -04005021
5022 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5023
5024 if shimVers.tls13Variant != 0 {
5025 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5026 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5027 }
5028
5029 // Test configuring the runner's maximum version.
5030 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005031 expectedVersion := shimVers.version
5032 if runnerVers.version < shimVers.version {
5033 expectedVersion = runnerVers.version
5034 }
Steven Valdez520e1222017-06-13 12:45:25 -04005035 // When running and shim have different TLS 1.3 variants enabled,
5036 // shim clients are expected to fall back to TLS 1.2, while shim
5037 // servers support both variants when enabled when the experiment is
5038 // enabled.
5039 expectedServerVersion := expectedVersion
5040 expectedClientVersion := expectedVersion
5041 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5042 expectedClientVersion = VersionTLS12
5043 expectedServerVersion = VersionTLS12
5044 if shimVers.tls13Variant != TLS13Default {
5045 expectedServerVersion = VersionTLS13
5046 }
5047 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005048
David Benjamin8b8c0062014-11-23 02:47:52 -05005049 suffix := shimVers.name + "-" + runnerVers.name
5050 if protocol == dtls {
5051 suffix += "-DTLS"
5052 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005053
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005054 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005055 clientVers := shimVers.version
5056 if clientVers > VersionTLS10 {
5057 clientVers = VersionTLS10
5058 }
Steven Valdez520e1222017-06-13 12:45:25 -04005059 clientVers = recordVersionToWire(clientVers, protocol)
5060 serverVers := expectedServerVersion
5061 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005062 serverVers = VersionTLS10
5063 }
Steven Valdez520e1222017-06-13 12:45:25 -04005064 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005065
David Benjamin8b8c0062014-11-23 02:47:52 -05005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 testType: clientTest,
5069 name: "VersionNegotiation-Client-" + suffix,
5070 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005071 MaxVersion: runnerVers.version,
5072 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005073 Bugs: ProtocolBugs{
5074 ExpectInitialRecordVersion: clientVers,
5075 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005076 },
5077 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005078 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005079 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005080 testCases = append(testCases, testCase{
5081 protocol: protocol,
5082 testType: clientTest,
5083 name: "VersionNegotiation-Client2-" + suffix,
5084 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005085 MaxVersion: runnerVers.version,
5086 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005087 Bugs: ProtocolBugs{
5088 ExpectInitialRecordVersion: clientVers,
5089 },
5090 },
Steven Valdez520e1222017-06-13 12:45:25 -04005091 flags: flags2,
5092 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005093 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005094
5095 testCases = append(testCases, testCase{
5096 protocol: protocol,
5097 testType: serverTest,
5098 name: "VersionNegotiation-Server-" + suffix,
5099 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005100 MaxVersion: runnerVers.version,
5101 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005102 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005103 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005105 },
5106 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005107 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005108 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005109 testCases = append(testCases, testCase{
5110 protocol: protocol,
5111 testType: serverTest,
5112 name: "VersionNegotiation-Server2-" + suffix,
5113 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005114 MaxVersion: runnerVers.version,
5115 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005116 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005117 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005118 },
5119 },
Steven Valdez520e1222017-06-13 12:45:25 -04005120 flags: flags2,
5121 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005122 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005123 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005124 }
5125 }
David Benjamin95c69562016-06-29 18:15:03 -04005126
Steven Valdezfdd10992016-09-15 16:27:05 -04005127 // Test the version extension at all versions.
5128 for _, vers := range tlsVersions {
5129 protocols := []protocol{tls}
5130 if vers.hasDTLS {
5131 protocols = append(protocols, dtls)
5132 }
5133 for _, protocol := range protocols {
5134 suffix := vers.name
5135 if protocol == dtls {
5136 suffix += "-DTLS"
5137 }
5138
Steven Valdezfdd10992016-09-15 16:27:05 -04005139 testCases = append(testCases, testCase{
5140 protocol: protocol,
5141 testType: serverTest,
5142 name: "VersionNegotiationExtension-" + suffix,
5143 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005144 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005145 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005146 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005147 },
5148 },
5149 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005150 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005151 })
5152 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005153 }
5154
5155 // If all versions are unknown, negotiation fails.
5156 testCases = append(testCases, testCase{
5157 testType: serverTest,
5158 name: "NoSupportedVersions",
5159 config: Config{
5160 Bugs: ProtocolBugs{
5161 SendSupportedVersions: []uint16{0x1111},
5162 },
5163 },
5164 shouldFail: true,
5165 expectedError: ":UNSUPPORTED_PROTOCOL:",
5166 })
5167 testCases = append(testCases, testCase{
5168 protocol: dtls,
5169 testType: serverTest,
5170 name: "NoSupportedVersions-DTLS",
5171 config: Config{
5172 Bugs: ProtocolBugs{
5173 SendSupportedVersions: []uint16{0x1111},
5174 },
5175 },
5176 shouldFail: true,
5177 expectedError: ":UNSUPPORTED_PROTOCOL:",
5178 })
5179
5180 testCases = append(testCases, testCase{
5181 testType: serverTest,
5182 name: "ClientHelloVersionTooHigh",
5183 config: Config{
5184 MaxVersion: VersionTLS13,
5185 Bugs: ProtocolBugs{
5186 SendClientVersion: 0x0304,
5187 OmitSupportedVersions: true,
5188 },
5189 },
5190 expectedVersion: VersionTLS12,
5191 })
5192
5193 testCases = append(testCases, testCase{
5194 testType: serverTest,
5195 name: "ConflictingVersionNegotiation",
5196 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005197 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005198 SendClientVersion: VersionTLS12,
5199 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005200 },
5201 },
David Benjaminad75a662016-09-30 15:42:59 -04005202 // The extension takes precedence over the ClientHello version.
5203 expectedVersion: VersionTLS11,
5204 })
5205
5206 testCases = append(testCases, testCase{
5207 testType: serverTest,
5208 name: "ConflictingVersionNegotiation-2",
5209 config: Config{
5210 Bugs: ProtocolBugs{
5211 SendClientVersion: VersionTLS11,
5212 SendSupportedVersions: []uint16{VersionTLS12},
5213 },
5214 },
5215 // The extension takes precedence over the ClientHello version.
5216 expectedVersion: VersionTLS12,
5217 })
5218
5219 testCases = append(testCases, testCase{
5220 testType: serverTest,
5221 name: "RejectFinalTLS13",
5222 config: Config{
5223 Bugs: ProtocolBugs{
5224 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5225 },
5226 },
5227 // We currently implement a draft TLS 1.3 version. Ensure that
5228 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 expectedVersion: VersionTLS12,
5230 })
5231
Steven Valdez038da9b2017-07-10 12:57:25 -04005232 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5233 // the ServerHello.
5234 testCases = append(testCases, testCase{
5235 testType: clientTest,
5236 name: "SupportedVersionSelection-TLS12",
5237 config: Config{
5238 MaxVersion: VersionTLS12,
5239 Bugs: ProtocolBugs{
5240 SendServerSupportedExtensionVersion: VersionTLS12,
5241 },
5242 },
5243 shouldFail: true,
5244 expectedError: ":UNEXPECTED_EXTENSION:",
5245 })
5246
5247 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5248 // supported_versions extension in the ServerHello.
5249 testCases = append(testCases, testCase{
5250 testType: clientTest,
5251 name: "SupportedVersionSelection-TLS13",
5252 config: Config{
5253 MaxVersion: VersionTLS13,
5254 Bugs: ProtocolBugs{
5255 SendServerSupportedExtensionVersion: tls13DraftVersion,
5256 },
5257 },
5258 shouldFail: true,
5259 expectedError: ":UNEXPECTED_EXTENSION:",
5260 })
5261
Brian Smithf85d3232016-10-28 10:34:06 -10005262 // Test that the maximum version is selected regardless of the
5263 // client-sent order.
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "IgnoreClientVersionOrder",
5267 config: Config{
5268 Bugs: ProtocolBugs{
5269 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5270 },
5271 },
5272 expectedVersion: VersionTLS13,
5273 })
5274
David Benjamin95c69562016-06-29 18:15:03 -04005275 // Test for version tolerance.
5276 testCases = append(testCases, testCase{
5277 testType: serverTest,
5278 name: "MinorVersionTolerance",
5279 config: Config{
5280 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005281 SendClientVersion: 0x03ff,
5282 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005283 },
5284 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005285 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005286 })
5287 testCases = append(testCases, testCase{
5288 testType: serverTest,
5289 name: "MajorVersionTolerance",
5290 config: Config{
5291 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005292 SendClientVersion: 0x0400,
5293 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005294 },
5295 },
David Benjaminad75a662016-09-30 15:42:59 -04005296 // TLS 1.3 must be negotiated with the supported_versions
5297 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005298 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005299 })
David Benjaminad75a662016-09-30 15:42:59 -04005300 testCases = append(testCases, testCase{
5301 testType: serverTest,
5302 name: "VersionTolerance-TLS13",
5303 config: Config{
5304 Bugs: ProtocolBugs{
5305 // Although TLS 1.3 does not use
5306 // ClientHello.version, it still tolerates high
5307 // values there.
5308 SendClientVersion: 0x0400,
5309 },
5310 },
5311 expectedVersion: VersionTLS13,
5312 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005313
David Benjamin95c69562016-06-29 18:15:03 -04005314 testCases = append(testCases, testCase{
5315 protocol: dtls,
5316 testType: serverTest,
5317 name: "MinorVersionTolerance-DTLS",
5318 config: Config{
5319 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005320 SendClientVersion: 0xfe00,
5321 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005322 },
5323 },
5324 expectedVersion: VersionTLS12,
5325 })
5326 testCases = append(testCases, testCase{
5327 protocol: dtls,
5328 testType: serverTest,
5329 name: "MajorVersionTolerance-DTLS",
5330 config: Config{
5331 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005332 SendClientVersion: 0xfdff,
5333 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005334 },
5335 },
5336 expectedVersion: VersionTLS12,
5337 })
5338
5339 // Test that versions below 3.0 are rejected.
5340 testCases = append(testCases, testCase{
5341 testType: serverTest,
5342 name: "VersionTooLow",
5343 config: Config{
5344 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005345 SendClientVersion: 0x0200,
5346 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005347 },
5348 },
5349 shouldFail: true,
5350 expectedError: ":UNSUPPORTED_PROTOCOL:",
5351 })
5352 testCases = append(testCases, testCase{
5353 protocol: dtls,
5354 testType: serverTest,
5355 name: "VersionTooLow-DTLS",
5356 config: Config{
5357 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005358 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005359 },
5360 },
5361 shouldFail: true,
5362 expectedError: ":UNSUPPORTED_PROTOCOL:",
5363 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005364
David Benjamin2dc02042016-09-19 19:57:37 -04005365 testCases = append(testCases, testCase{
5366 name: "ServerBogusVersion",
5367 config: Config{
5368 Bugs: ProtocolBugs{
5369 SendServerHelloVersion: 0x1234,
5370 },
5371 },
5372 shouldFail: true,
5373 expectedError: ":UNSUPPORTED_PROTOCOL:",
5374 })
5375
David Benjamin1f61f0d2016-07-10 12:20:35 -04005376 // Test TLS 1.3's downgrade signal.
5377 testCases = append(testCases, testCase{
5378 name: "Downgrade-TLS12-Client",
5379 config: Config{
5380 Bugs: ProtocolBugs{
5381 NegotiateVersion: VersionTLS12,
5382 },
5383 },
David Benjamin592b5322016-09-30 15:15:01 -04005384 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005385 // TODO(davidben): This test should fail once TLS 1.3 is final
5386 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005387 })
5388 testCases = append(testCases, testCase{
5389 testType: serverTest,
5390 name: "Downgrade-TLS12-Server",
5391 config: Config{
5392 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005393 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005394 },
5395 },
David Benjamin592b5322016-09-30 15:15:01 -04005396 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005397 // TODO(davidben): This test should fail once TLS 1.3 is final
5398 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005399 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005400}
5401
David Benjaminaccb4542014-12-12 23:44:33 -05005402func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005403 for _, protocol := range []protocol{tls, dtls} {
5404 for _, shimVers := range allVersions(protocol) {
5405 // Assemble flags to disable all older versions on the shim.
5406 var flags []string
5407 for _, vers := range allVersions(protocol) {
5408 if vers.version < shimVers.version {
5409 flags = append(flags, vers.excludeFlag)
5410 }
David Benjaminaccb4542014-12-12 23:44:33 -05005411 }
Steven Valdez520e1222017-06-13 12:45:25 -04005412
5413 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5414
5415 if shimVers.tls13Variant != 0 {
5416 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5417 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5418 }
5419
5420 for _, runnerVers := range allVersions(protocol) {
5421 // Different TLS 1.3 variants are incompatible with each other and don't
5422 // produce consistent minimum versions.
5423 //
5424 // TODO(davidben): Fold these tests (the main value is in the
5425 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5426 // on intended shim behavior, not the shim + runner combination.
5427 if shimVers.tls13Variant != runnerVers.tls13Variant {
5428 continue
5429 }
5430
David Benjaminaccb4542014-12-12 23:44:33 -05005431 suffix := shimVers.name + "-" + runnerVers.name
5432 if protocol == dtls {
5433 suffix += "-DTLS"
5434 }
David Benjaminaccb4542014-12-12 23:44:33 -05005435
David Benjaminaccb4542014-12-12 23:44:33 -05005436 var expectedVersion uint16
5437 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005438 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005439 if runnerVers.version >= shimVers.version {
5440 expectedVersion = runnerVers.version
5441 } else {
5442 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005443 expectedError = ":UNSUPPORTED_PROTOCOL:"
5444 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005445 }
5446
5447 testCases = append(testCases, testCase{
5448 protocol: protocol,
5449 testType: clientTest,
5450 name: "MinimumVersion-Client-" + suffix,
5451 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005452 MaxVersion: runnerVers.version,
5453 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005454 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005455 // Ensure the server does not decline to
5456 // select a version (versions extension) or
5457 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005458 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005459 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005460 },
David Benjaminaccb4542014-12-12 23:44:33 -05005461 },
David Benjamin87909c02014-12-13 01:55:01 -05005462 flags: flags,
5463 expectedVersion: expectedVersion,
5464 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005465 expectedError: expectedError,
5466 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005467 })
5468 testCases = append(testCases, testCase{
5469 protocol: protocol,
5470 testType: clientTest,
5471 name: "MinimumVersion-Client2-" + suffix,
5472 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005473 MaxVersion: runnerVers.version,
5474 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005475 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005476 // Ensure the server does not decline to
5477 // select a version (versions extension) or
5478 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005479 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005480 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005481 },
David Benjaminaccb4542014-12-12 23:44:33 -05005482 },
Steven Valdez520e1222017-06-13 12:45:25 -04005483 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005484 expectedVersion: expectedVersion,
5485 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005486 expectedError: expectedError,
5487 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005488 })
5489
5490 testCases = append(testCases, testCase{
5491 protocol: protocol,
5492 testType: serverTest,
5493 name: "MinimumVersion-Server-" + suffix,
5494 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005495 MaxVersion: runnerVers.version,
5496 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005497 },
David Benjamin87909c02014-12-13 01:55:01 -05005498 flags: flags,
5499 expectedVersion: expectedVersion,
5500 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005501 expectedError: expectedError,
5502 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005503 })
5504 testCases = append(testCases, testCase{
5505 protocol: protocol,
5506 testType: serverTest,
5507 name: "MinimumVersion-Server2-" + suffix,
5508 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005509 MaxVersion: runnerVers.version,
5510 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005511 },
Steven Valdez520e1222017-06-13 12:45:25 -04005512 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005513 expectedVersion: expectedVersion,
5514 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005515 expectedError: expectedError,
5516 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005517 })
5518 }
5519 }
5520 }
5521}
5522
David Benjamine78bfde2014-09-06 12:45:15 -04005523func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005524 // TODO(davidben): Extensions, where applicable, all move their server
5525 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5526 // tests for both. Also test interaction with 0-RTT when implemented.
5527
David Benjamin97d17d92016-07-14 16:12:00 -04005528 // Repeat extensions tests all versions except SSL 3.0.
5529 for _, ver := range tlsVersions {
5530 if ver.version == VersionSSL30 {
5531 continue
5532 }
5533
David Benjamin97d17d92016-07-14 16:12:00 -04005534 // Test that duplicate extensions are rejected.
5535 testCases = append(testCases, testCase{
5536 testType: clientTest,
5537 name: "DuplicateExtensionClient-" + ver.name,
5538 config: Config{
5539 MaxVersion: ver.version,
5540 Bugs: ProtocolBugs{
5541 DuplicateExtension: true,
5542 },
David Benjamine78bfde2014-09-06 12:45:15 -04005543 },
David Benjamina5022392017-07-10 17:40:39 -04005544 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005545 shouldFail: true,
5546 expectedLocalError: "remote error: error decoding message",
5547 })
5548 testCases = append(testCases, testCase{
5549 testType: serverTest,
5550 name: "DuplicateExtensionServer-" + ver.name,
5551 config: Config{
5552 MaxVersion: ver.version,
5553 Bugs: ProtocolBugs{
5554 DuplicateExtension: true,
5555 },
David Benjamine78bfde2014-09-06 12:45:15 -04005556 },
David Benjamina5022392017-07-10 17:40:39 -04005557 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005558 shouldFail: true,
5559 expectedLocalError: "remote error: error decoding message",
5560 })
5561
5562 // Test SNI.
5563 testCases = append(testCases, testCase{
5564 testType: clientTest,
5565 name: "ServerNameExtensionClient-" + ver.name,
5566 config: Config{
5567 MaxVersion: ver.version,
5568 Bugs: ProtocolBugs{
5569 ExpectServerName: "example.com",
5570 },
David Benjamine78bfde2014-09-06 12:45:15 -04005571 },
David Benjamina5022392017-07-10 17:40:39 -04005572 tls13Variant: ver.tls13Variant,
5573 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005574 })
5575 testCases = append(testCases, testCase{
5576 testType: clientTest,
5577 name: "ServerNameExtensionClientMismatch-" + ver.name,
5578 config: Config{
5579 MaxVersion: ver.version,
5580 Bugs: ProtocolBugs{
5581 ExpectServerName: "mismatch.com",
5582 },
David Benjamine78bfde2014-09-06 12:45:15 -04005583 },
David Benjamin97d17d92016-07-14 16:12:00 -04005584 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005585 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005586 shouldFail: true,
5587 expectedLocalError: "tls: unexpected server name",
5588 })
5589 testCases = append(testCases, testCase{
5590 testType: clientTest,
5591 name: "ServerNameExtensionClientMissing-" + ver.name,
5592 config: Config{
5593 MaxVersion: ver.version,
5594 Bugs: ProtocolBugs{
5595 ExpectServerName: "missing.com",
5596 },
David Benjamine78bfde2014-09-06 12:45:15 -04005597 },
David Benjamina5022392017-07-10 17:40:39 -04005598 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005599 shouldFail: true,
5600 expectedLocalError: "tls: unexpected server name",
5601 })
5602 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005603 testType: clientTest,
5604 name: "TolerateServerNameAck-" + ver.name,
5605 config: Config{
5606 MaxVersion: ver.version,
5607 Bugs: ProtocolBugs{
5608 SendServerNameAck: true,
5609 },
5610 },
David Benjamina5022392017-07-10 17:40:39 -04005611 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005612 flags: []string{"-host-name", "example.com"},
5613 resumeSession: true,
5614 })
5615 testCases = append(testCases, testCase{
5616 testType: clientTest,
5617 name: "UnsolicitedServerNameAck-" + ver.name,
5618 config: Config{
5619 MaxVersion: ver.version,
5620 Bugs: ProtocolBugs{
5621 SendServerNameAck: true,
5622 },
5623 },
David Benjamina5022392017-07-10 17:40:39 -04005624 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005625 shouldFail: true,
5626 expectedError: ":UNEXPECTED_EXTENSION:",
5627 expectedLocalError: "remote error: unsupported extension",
5628 })
5629 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005630 testType: serverTest,
5631 name: "ServerNameExtensionServer-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005635 },
David Benjamina5022392017-07-10 17:40:39 -04005636 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005637 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005638 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005639 })
5640
5641 // Test ALPN.
5642 testCases = append(testCases, testCase{
5643 testType: clientTest,
5644 name: "ALPNClient-" + ver.name,
5645 config: Config{
5646 MaxVersion: ver.version,
5647 NextProtos: []string{"foo"},
5648 },
5649 flags: []string{
5650 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5651 "-expect-alpn", "foo",
5652 },
David Benjamina5022392017-07-10 17:40:39 -04005653 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005654 expectedNextProto: "foo",
5655 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005656 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005657 })
5658 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005659 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005660 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005661 config: Config{
5662 MaxVersion: ver.version,
5663 Bugs: ProtocolBugs{
5664 SendALPN: "baz",
5665 },
5666 },
5667 flags: []string{
5668 "-advertise-alpn", "\x03foo\x03bar",
5669 },
David Benjamina5022392017-07-10 17:40:39 -04005670 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005671 shouldFail: true,
5672 expectedError: ":INVALID_ALPN_PROTOCOL:",
5673 expectedLocalError: "remote error: illegal parameter",
5674 })
5675 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005676 testType: clientTest,
5677 name: "ALPNClient-AllowUnknown-" + ver.name,
5678 config: Config{
5679 MaxVersion: ver.version,
5680 Bugs: ProtocolBugs{
5681 SendALPN: "baz",
5682 },
5683 },
5684 flags: []string{
5685 "-advertise-alpn", "\x03foo\x03bar",
5686 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005687 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005688 },
David Benjamina5022392017-07-10 17:40:39 -04005689 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005690 })
5691 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005692 testType: serverTest,
5693 name: "ALPNServer-" + ver.name,
5694 config: Config{
5695 MaxVersion: ver.version,
5696 NextProtos: []string{"foo", "bar", "baz"},
5697 },
5698 flags: []string{
5699 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5700 "-select-alpn", "foo",
5701 },
David Benjamina5022392017-07-10 17:40:39 -04005702 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005703 expectedNextProto: "foo",
5704 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005705 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005706 })
5707 testCases = append(testCases, testCase{
5708 testType: serverTest,
5709 name: "ALPNServer-Decline-" + ver.name,
5710 config: Config{
5711 MaxVersion: ver.version,
5712 NextProtos: []string{"foo", "bar", "baz"},
5713 },
5714 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005715 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005716 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005717 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005718 })
5719
David Benjamin25fe85b2016-08-09 20:00:32 -04005720 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5721 // called once.
5722 testCases = append(testCases, testCase{
5723 testType: serverTest,
5724 name: "ALPNServer-Async-" + ver.name,
5725 config: Config{
5726 MaxVersion: ver.version,
5727 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005728 // Prior to TLS 1.3, exercise the asynchronous session callback.
5729 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005730 },
5731 flags: []string{
5732 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5733 "-select-alpn", "foo",
5734 "-async",
5735 },
David Benjamina5022392017-07-10 17:40:39 -04005736 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005737 expectedNextProto: "foo",
5738 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005739 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005740 })
5741
David Benjamin97d17d92016-07-14 16:12:00 -04005742 var emptyString string
5743 testCases = append(testCases, testCase{
5744 testType: clientTest,
5745 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5746 config: Config{
5747 MaxVersion: ver.version,
5748 NextProtos: []string{""},
5749 Bugs: ProtocolBugs{
5750 // A server returning an empty ALPN protocol
5751 // should be rejected.
5752 ALPNProtocol: &emptyString,
5753 },
5754 },
5755 flags: []string{
5756 "-advertise-alpn", "\x03foo",
5757 },
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 testCases = append(testCases, testCase{
5763 testType: serverTest,
5764 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5765 config: Config{
5766 MaxVersion: ver.version,
5767 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005768 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005769 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005770 },
David Benjamin97d17d92016-07-14 16:12:00 -04005771 flags: []string{
5772 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005773 },
David Benjamina5022392017-07-10 17:40:39 -04005774 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005775 shouldFail: true,
5776 expectedError: ":PARSE_TLSEXT:",
5777 })
5778
5779 // Test NPN and the interaction with ALPN.
5780 if ver.version < VersionTLS13 {
5781 // Test that the server prefers ALPN over NPN.
5782 testCases = append(testCases, testCase{
5783 testType: serverTest,
5784 name: "ALPNServer-Preferred-" + ver.name,
5785 config: Config{
5786 MaxVersion: ver.version,
5787 NextProtos: []string{"foo", "bar", "baz"},
5788 },
5789 flags: []string{
5790 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5791 "-select-alpn", "foo",
5792 "-advertise-npn", "\x03foo\x03bar\x03baz",
5793 },
David Benjamina5022392017-07-10 17:40:39 -04005794 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005795 expectedNextProto: "foo",
5796 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005797 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005798 })
5799 testCases = append(testCases, testCase{
5800 testType: serverTest,
5801 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5802 config: Config{
5803 MaxVersion: ver.version,
5804 NextProtos: []string{"foo", "bar", "baz"},
5805 Bugs: ProtocolBugs{
5806 SwapNPNAndALPN: true,
5807 },
5808 },
5809 flags: []string{
5810 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5811 "-select-alpn", "foo",
5812 "-advertise-npn", "\x03foo\x03bar\x03baz",
5813 },
David Benjamina5022392017-07-10 17:40:39 -04005814 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005815 expectedNextProto: "foo",
5816 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005817 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005818 })
5819
5820 // Test that negotiating both NPN and ALPN is forbidden.
5821 testCases = append(testCases, testCase{
5822 name: "NegotiateALPNAndNPN-" + ver.name,
5823 config: Config{
5824 MaxVersion: ver.version,
5825 NextProtos: []string{"foo", "bar", "baz"},
5826 Bugs: ProtocolBugs{
5827 NegotiateALPNAndNPN: true,
5828 },
5829 },
5830 flags: []string{
5831 "-advertise-alpn", "\x03foo",
5832 "-select-next-proto", "foo",
5833 },
David Benjamina5022392017-07-10 17:40:39 -04005834 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005835 shouldFail: true,
5836 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5837 })
5838 testCases = append(testCases, testCase{
5839 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5840 config: Config{
5841 MaxVersion: ver.version,
5842 NextProtos: []string{"foo", "bar", "baz"},
5843 Bugs: ProtocolBugs{
5844 NegotiateALPNAndNPN: true,
5845 SwapNPNAndALPN: true,
5846 },
5847 },
5848 flags: []string{
5849 "-advertise-alpn", "\x03foo",
5850 "-select-next-proto", "foo",
5851 },
David Benjamina5022392017-07-10 17:40:39 -04005852 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005853 shouldFail: true,
5854 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5855 })
David Benjamin97d17d92016-07-14 16:12:00 -04005856 }
5857
5858 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005859
5860 // Resume with a corrupt ticket.
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "CorruptTicket-" + ver.name,
5864 config: Config{
5865 MaxVersion: ver.version,
5866 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005867 FilterTicket: func(in []byte) ([]byte, error) {
5868 in[len(in)-1] ^= 1
5869 return in, nil
5870 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005871 },
5872 },
David Benjamina5022392017-07-10 17:40:39 -04005873 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005874 resumeSession: true,
5875 expectResumeRejected: true,
5876 })
5877 // Test the ticket callback, with and without renewal.
5878 testCases = append(testCases, testCase{
5879 testType: serverTest,
5880 name: "TicketCallback-" + ver.name,
5881 config: Config{
5882 MaxVersion: ver.version,
5883 },
David Benjamina5022392017-07-10 17:40:39 -04005884 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005885 resumeSession: true,
5886 flags: []string{"-use-ticket-callback"},
5887 })
5888 testCases = append(testCases, testCase{
5889 testType: serverTest,
5890 name: "TicketCallback-Renew-" + ver.name,
5891 config: Config{
5892 MaxVersion: ver.version,
5893 Bugs: ProtocolBugs{
5894 ExpectNewTicket: true,
5895 },
5896 },
David Benjamina5022392017-07-10 17:40:39 -04005897 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005898 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5899 resumeSession: true,
5900 })
5901
5902 // Test that the ticket callback is only called once when everything before
5903 // it in the ClientHello is asynchronous. This corrupts the ticket so
5904 // certificate selection callbacks run.
5905 testCases = append(testCases, testCase{
5906 testType: serverTest,
5907 name: "TicketCallback-SingleCall-" + ver.name,
5908 config: Config{
5909 MaxVersion: ver.version,
5910 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005911 FilterTicket: func(in []byte) ([]byte, error) {
5912 in[len(in)-1] ^= 1
5913 return in, nil
5914 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005915 },
5916 },
David Benjamina5022392017-07-10 17:40:39 -04005917 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005918 resumeSession: true,
5919 expectResumeRejected: true,
5920 flags: []string{
5921 "-use-ticket-callback",
5922 "-async",
5923 },
5924 })
5925
David Benjamind4c349b2017-02-09 14:07:17 -05005926 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005927 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005928 testCases = append(testCases, testCase{
5929 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005930 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005931 config: Config{
5932 MaxVersion: ver.version,
5933 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005934 EmptyTicketSessionID: true,
5935 },
5936 },
5937 resumeSession: true,
5938 })
5939 testCases = append(testCases, testCase{
5940 testType: serverTest,
5941 name: "TicketSessionIDLength-16-" + ver.name,
5942 config: Config{
5943 MaxVersion: ver.version,
5944 Bugs: ProtocolBugs{
5945 TicketSessionIDLength: 16,
5946 },
5947 },
5948 resumeSession: true,
5949 })
5950 testCases = append(testCases, testCase{
5951 testType: serverTest,
5952 name: "TicketSessionIDLength-32-" + ver.name,
5953 config: Config{
5954 MaxVersion: ver.version,
5955 Bugs: ProtocolBugs{
5956 TicketSessionIDLength: 32,
5957 },
5958 },
5959 resumeSession: true,
5960 })
5961 testCases = append(testCases, testCase{
5962 testType: serverTest,
5963 name: "TicketSessionIDLength-33-" + ver.name,
5964 config: Config{
5965 MaxVersion: ver.version,
5966 Bugs: ProtocolBugs{
5967 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005968 },
5969 },
5970 resumeSession: true,
5971 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005972 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005973 expectedError: ":DECODE_ERROR:",
5974 })
5975 }
5976
5977 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5978 // are ignored.
5979 if ver.hasDTLS {
5980 testCases = append(testCases, testCase{
5981 protocol: dtls,
5982 name: "SRTP-Client-" + ver.name,
5983 config: Config{
5984 MaxVersion: ver.version,
5985 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5986 },
5987 flags: []string{
5988 "-srtp-profiles",
5989 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5990 },
5991 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5992 })
5993 testCases = append(testCases, testCase{
5994 protocol: dtls,
5995 testType: serverTest,
5996 name: "SRTP-Server-" + ver.name,
5997 config: Config{
5998 MaxVersion: ver.version,
5999 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6000 },
6001 flags: []string{
6002 "-srtp-profiles",
6003 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6004 },
6005 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6006 })
6007 // Test that the MKI is ignored.
6008 testCases = append(testCases, testCase{
6009 protocol: dtls,
6010 testType: serverTest,
6011 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6012 config: Config{
6013 MaxVersion: ver.version,
6014 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6015 Bugs: ProtocolBugs{
6016 SRTPMasterKeyIdentifer: "bogus",
6017 },
6018 },
6019 flags: []string{
6020 "-srtp-profiles",
6021 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6022 },
6023 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6024 })
6025 // Test that SRTP isn't negotiated on the server if there were
6026 // no matching profiles.
6027 testCases = append(testCases, testCase{
6028 protocol: dtls,
6029 testType: serverTest,
6030 name: "SRTP-Server-NoMatch-" + ver.name,
6031 config: Config{
6032 MaxVersion: ver.version,
6033 SRTPProtectionProfiles: []uint16{100, 101, 102},
6034 },
6035 flags: []string{
6036 "-srtp-profiles",
6037 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6038 },
6039 expectedSRTPProtectionProfile: 0,
6040 })
6041 // Test that the server returning an invalid SRTP profile is
6042 // flagged as an error by the client.
6043 testCases = append(testCases, testCase{
6044 protocol: dtls,
6045 name: "SRTP-Client-NoMatch-" + ver.name,
6046 config: Config{
6047 MaxVersion: ver.version,
6048 Bugs: ProtocolBugs{
6049 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6050 },
6051 },
6052 flags: []string{
6053 "-srtp-profiles",
6054 "SRTP_AES128_CM_SHA1_80",
6055 },
6056 shouldFail: true,
6057 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6058 })
6059 }
6060
6061 // Test SCT list.
6062 testCases = append(testCases, testCase{
6063 name: "SignedCertificateTimestampList-Client-" + ver.name,
6064 testType: clientTest,
6065 config: Config{
6066 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006067 },
David Benjamin97d17d92016-07-14 16:12:00 -04006068 flags: []string{
6069 "-enable-signed-cert-timestamps",
6070 "-expect-signed-cert-timestamps",
6071 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006072 },
David Benjamina5022392017-07-10 17:40:39 -04006073 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006074 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006075 })
David Benjamindaa88502016-10-04 16:32:16 -04006076
Adam Langleycfa08c32016-11-17 13:21:27 -08006077 var differentSCTList []byte
6078 differentSCTList = append(differentSCTList, testSCTList...)
6079 differentSCTList[len(differentSCTList)-1] ^= 1
6080
David Benjamindaa88502016-10-04 16:32:16 -04006081 // The SCT extension did not specify that it must only be sent on resumption as it
6082 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006083 testCases = append(testCases, testCase{
6084 name: "SendSCTListOnResume-" + ver.name,
6085 config: Config{
6086 MaxVersion: ver.version,
6087 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006088 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006089 },
David Benjamind98452d2015-06-16 14:16:23 -04006090 },
David Benjamin97d17d92016-07-14 16:12:00 -04006091 flags: []string{
6092 "-enable-signed-cert-timestamps",
6093 "-expect-signed-cert-timestamps",
6094 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006095 },
David Benjamina5022392017-07-10 17:40:39 -04006096 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006097 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006098 })
David Benjamindaa88502016-10-04 16:32:16 -04006099
David Benjamin97d17d92016-07-14 16:12:00 -04006100 testCases = append(testCases, testCase{
6101 name: "SignedCertificateTimestampList-Server-" + ver.name,
6102 testType: serverTest,
6103 config: Config{
6104 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006105 },
David Benjamin97d17d92016-07-14 16:12:00 -04006106 flags: []string{
6107 "-signed-cert-timestamps",
6108 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006109 },
David Benjamina5022392017-07-10 17:40:39 -04006110 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006111 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006112 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006113 })
David Benjamin53210cb2016-11-16 09:01:48 +09006114
Adam Langleycfa08c32016-11-17 13:21:27 -08006115 emptySCTListCert := *testCerts[0].cert
6116 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6117
6118 // Test empty SCT list.
6119 testCases = append(testCases, testCase{
6120 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6121 testType: clientTest,
6122 config: Config{
6123 MaxVersion: ver.version,
6124 Certificates: []Certificate{emptySCTListCert},
6125 },
6126 flags: []string{
6127 "-enable-signed-cert-timestamps",
6128 },
David Benjamina5022392017-07-10 17:40:39 -04006129 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006130 shouldFail: true,
6131 expectedError: ":ERROR_PARSING_EXTENSION:",
6132 })
6133
6134 emptySCTCert := *testCerts[0].cert
6135 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6136
6137 // Test empty SCT in non-empty list.
6138 testCases = append(testCases, testCase{
6139 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6140 testType: clientTest,
6141 config: Config{
6142 MaxVersion: ver.version,
6143 Certificates: []Certificate{emptySCTCert},
6144 },
6145 flags: []string{
6146 "-enable-signed-cert-timestamps",
6147 },
David Benjamina5022392017-07-10 17:40:39 -04006148 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006149 shouldFail: true,
6150 expectedError: ":ERROR_PARSING_EXTENSION:",
6151 })
6152
David Benjamin53210cb2016-11-16 09:01:48 +09006153 // Test that certificate-related extensions are not sent unsolicited.
6154 testCases = append(testCases, testCase{
6155 testType: serverTest,
6156 name: "UnsolicitedCertificateExtensions-" + ver.name,
6157 config: Config{
6158 MaxVersion: ver.version,
6159 Bugs: ProtocolBugs{
6160 NoOCSPStapling: true,
6161 NoSignedCertificateTimestamps: true,
6162 },
6163 },
David Benjamina5022392017-07-10 17:40:39 -04006164 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006165 flags: []string{
6166 "-ocsp-response",
6167 base64.StdEncoding.EncodeToString(testOCSPResponse),
6168 "-signed-cert-timestamps",
6169 base64.StdEncoding.EncodeToString(testSCTList),
6170 },
6171 })
David Benjamin97d17d92016-07-14 16:12:00 -04006172 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006173
Paul Lietar4fac72e2015-09-09 13:44:55 +01006174 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006175 testType: clientTest,
6176 name: "ClientHelloPadding",
6177 config: Config{
6178 Bugs: ProtocolBugs{
6179 RequireClientHelloSize: 512,
6180 },
6181 },
6182 // This hostname just needs to be long enough to push the
6183 // ClientHello into F5's danger zone between 256 and 511 bytes
6184 // long.
6185 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6186 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006187
6188 // Extensions should not function in SSL 3.0.
6189 testCases = append(testCases, testCase{
6190 testType: serverTest,
6191 name: "SSLv3Extensions-NoALPN",
6192 config: Config{
6193 MaxVersion: VersionSSL30,
6194 NextProtos: []string{"foo", "bar", "baz"},
6195 },
6196 flags: []string{
6197 "-select-alpn", "foo",
6198 },
6199 expectNoNextProto: true,
6200 })
6201
6202 // Test session tickets separately as they follow a different codepath.
6203 testCases = append(testCases, testCase{
6204 testType: serverTest,
6205 name: "SSLv3Extensions-NoTickets",
6206 config: Config{
6207 MaxVersion: VersionSSL30,
6208 Bugs: ProtocolBugs{
6209 // Historically, session tickets in SSL 3.0
6210 // failed in different ways depending on whether
6211 // the client supported renegotiation_info.
6212 NoRenegotiationInfo: true,
6213 },
6214 },
6215 resumeSession: true,
6216 })
6217 testCases = append(testCases, testCase{
6218 testType: serverTest,
6219 name: "SSLv3Extensions-NoTickets2",
6220 config: Config{
6221 MaxVersion: VersionSSL30,
6222 },
6223 resumeSession: true,
6224 })
6225
6226 // But SSL 3.0 does send and process renegotiation_info.
6227 testCases = append(testCases, testCase{
6228 testType: serverTest,
6229 name: "SSLv3Extensions-RenegotiationInfo",
6230 config: Config{
6231 MaxVersion: VersionSSL30,
6232 Bugs: ProtocolBugs{
6233 RequireRenegotiationInfo: true,
6234 },
6235 },
David Benjamind2610042017-01-03 10:49:28 -05006236 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006237 })
6238 testCases = append(testCases, testCase{
6239 testType: serverTest,
6240 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6241 config: Config{
6242 MaxVersion: VersionSSL30,
6243 Bugs: ProtocolBugs{
6244 NoRenegotiationInfo: true,
6245 SendRenegotiationSCSV: true,
6246 RequireRenegotiationInfo: true,
6247 },
6248 },
David Benjamind2610042017-01-03 10:49:28 -05006249 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006250 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006251
6252 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6253 // in ServerHello.
6254 testCases = append(testCases, testCase{
6255 name: "NPN-Forbidden-TLS13",
6256 config: Config{
6257 MaxVersion: VersionTLS13,
6258 NextProtos: []string{"foo"},
6259 Bugs: ProtocolBugs{
6260 NegotiateNPNAtAllVersions: true,
6261 },
6262 },
6263 flags: []string{"-select-next-proto", "foo"},
6264 shouldFail: true,
6265 expectedError: ":ERROR_PARSING_EXTENSION:",
6266 })
6267 testCases = append(testCases, testCase{
6268 name: "EMS-Forbidden-TLS13",
6269 config: Config{
6270 MaxVersion: VersionTLS13,
6271 Bugs: ProtocolBugs{
6272 NegotiateEMSAtAllVersions: true,
6273 },
6274 },
6275 shouldFail: true,
6276 expectedError: ":ERROR_PARSING_EXTENSION:",
6277 })
6278 testCases = append(testCases, testCase{
6279 name: "RenegotiationInfo-Forbidden-TLS13",
6280 config: Config{
6281 MaxVersion: VersionTLS13,
6282 Bugs: ProtocolBugs{
6283 NegotiateRenegotiationInfoAtAllVersions: true,
6284 },
6285 },
6286 shouldFail: true,
6287 expectedError: ":ERROR_PARSING_EXTENSION:",
6288 })
6289 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006290 name: "Ticket-Forbidden-TLS13",
6291 config: Config{
6292 MaxVersion: VersionTLS12,
6293 },
6294 resumeConfig: &Config{
6295 MaxVersion: VersionTLS13,
6296 Bugs: ProtocolBugs{
6297 AdvertiseTicketExtension: true,
6298 },
6299 },
6300 resumeSession: true,
6301 shouldFail: true,
6302 expectedError: ":ERROR_PARSING_EXTENSION:",
6303 })
6304
6305 // Test that illegal extensions in TLS 1.3 are declined by the server if
6306 // offered in ClientHello. The runner's server will fail if this occurs,
6307 // so we exercise the offering path. (EMS and Renegotiation Info are
6308 // implicit in every test.)
6309 testCases = append(testCases, testCase{
6310 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006311 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006312 config: Config{
6313 MaxVersion: VersionTLS13,
6314 NextProtos: []string{"bar"},
6315 },
6316 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6317 })
David Benjamin196df5b2016-09-21 16:23:27 -04006318
David Benjamindaa88502016-10-04 16:32:16 -04006319 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6320 // tolerated.
6321 testCases = append(testCases, testCase{
6322 name: "SendOCSPResponseOnResume-TLS12",
6323 config: Config{
6324 MaxVersion: VersionTLS12,
6325 Bugs: ProtocolBugs{
6326 SendOCSPResponseOnResume: []byte("bogus"),
6327 },
6328 },
6329 flags: []string{
6330 "-enable-ocsp-stapling",
6331 "-expect-ocsp-response",
6332 base64.StdEncoding.EncodeToString(testOCSPResponse),
6333 },
6334 resumeSession: true,
6335 })
6336
David Benjamindaa88502016-10-04 16:32:16 -04006337 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006338 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006339 config: Config{
6340 MaxVersion: VersionTLS13,
6341 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006342 SendExtensionOnCertificate: testOCSPExtension,
6343 },
6344 },
6345 shouldFail: true,
6346 expectedError: ":UNEXPECTED_EXTENSION:",
6347 })
6348
6349 testCases = append(testCases, testCase{
6350 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6351 config: Config{
6352 MaxVersion: VersionTLS13,
6353 Bugs: ProtocolBugs{
6354 SendExtensionOnCertificate: testSCTExtension,
6355 },
6356 },
6357 shouldFail: true,
6358 expectedError: ":UNEXPECTED_EXTENSION:",
6359 })
6360
6361 // Test that extensions on client certificates are never accepted.
6362 testCases = append(testCases, testCase{
6363 name: "SendExtensionOnClientCertificate-TLS13",
6364 testType: serverTest,
6365 config: Config{
6366 MaxVersion: VersionTLS13,
6367 Certificates: []Certificate{rsaCertificate},
6368 Bugs: ProtocolBugs{
6369 SendExtensionOnCertificate: testOCSPExtension,
6370 },
6371 },
6372 flags: []string{
6373 "-enable-ocsp-stapling",
6374 "-require-any-client-certificate",
6375 },
6376 shouldFail: true,
6377 expectedError: ":UNEXPECTED_EXTENSION:",
6378 })
6379
6380 testCases = append(testCases, testCase{
6381 name: "SendUnknownExtensionOnCertificate-TLS13",
6382 config: Config{
6383 MaxVersion: VersionTLS13,
6384 Bugs: ProtocolBugs{
6385 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6386 },
6387 },
6388 shouldFail: true,
6389 expectedError: ":UNEXPECTED_EXTENSION:",
6390 })
6391
Adam Langleycfa08c32016-11-17 13:21:27 -08006392 var differentSCTList []byte
6393 differentSCTList = append(differentSCTList, testSCTList...)
6394 differentSCTList[len(differentSCTList)-1] ^= 1
6395
Steven Valdeza833c352016-11-01 13:39:36 -04006396 // Test that extensions on intermediates are allowed but ignored.
6397 testCases = append(testCases, testCase{
6398 name: "IgnoreExtensionsOnIntermediates-TLS13",
6399 config: Config{
6400 MaxVersion: VersionTLS13,
6401 Certificates: []Certificate{rsaChainCertificate},
6402 Bugs: ProtocolBugs{
6403 // Send different values on the intermediate. This tests
6404 // the intermediate's extensions do not override the
6405 // leaf's.
6406 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006407 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006408 },
6409 },
6410 flags: []string{
6411 "-enable-ocsp-stapling",
6412 "-expect-ocsp-response",
6413 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006414 "-enable-signed-cert-timestamps",
6415 "-expect-signed-cert-timestamps",
6416 base64.StdEncoding.EncodeToString(testSCTList),
6417 },
6418 resumeSession: true,
6419 })
6420
6421 // Test that extensions are not sent on intermediates when configured
6422 // only for a leaf.
6423 testCases = append(testCases, testCase{
6424 testType: serverTest,
6425 name: "SendNoExtensionsOnIntermediate-TLS13",
6426 config: Config{
6427 MaxVersion: VersionTLS13,
6428 Bugs: ProtocolBugs{
6429 ExpectNoExtensionsOnIntermediate: true,
6430 },
6431 },
6432 flags: []string{
6433 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6434 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6435 "-ocsp-response",
6436 base64.StdEncoding.EncodeToString(testOCSPResponse),
6437 "-signed-cert-timestamps",
6438 base64.StdEncoding.EncodeToString(testSCTList),
6439 },
6440 })
6441
6442 // Test that extensions are not sent on client certificates.
6443 testCases = append(testCases, testCase{
6444 name: "SendNoClientCertificateExtensions-TLS13",
6445 config: Config{
6446 MaxVersion: VersionTLS13,
6447 ClientAuth: RequireAnyClientCert,
6448 },
6449 flags: []string{
6450 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6451 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6452 "-ocsp-response",
6453 base64.StdEncoding.EncodeToString(testOCSPResponse),
6454 "-signed-cert-timestamps",
6455 base64.StdEncoding.EncodeToString(testSCTList),
6456 },
6457 })
6458
6459 testCases = append(testCases, testCase{
6460 name: "SendDuplicateExtensionsOnCerts-TLS13",
6461 config: Config{
6462 MaxVersion: VersionTLS13,
6463 Bugs: ProtocolBugs{
6464 SendDuplicateCertExtensions: true,
6465 },
6466 },
6467 flags: []string{
6468 "-enable-ocsp-stapling",
6469 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006470 },
6471 resumeSession: true,
6472 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006473 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006474 })
Adam Langley9b885c52016-11-18 14:21:03 -08006475
6476 testCases = append(testCases, testCase{
6477 name: "SignedCertificateTimestampListInvalid-Server",
6478 testType: serverTest,
6479 flags: []string{
6480 "-signed-cert-timestamps",
6481 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6482 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006483 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006484 expectedError: ":INVALID_SCT_LIST:",
6485 })
David Benjamine78bfde2014-09-06 12:45:15 -04006486}
6487
David Benjamin01fe8202014-09-24 15:21:44 -04006488func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006489 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006490 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006491 // SSL 3.0 does not have tickets and TLS 1.3 does not
6492 // have session IDs, so skip their cross-resumption
6493 // tests.
6494 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6495 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6496 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006497 }
6498
David Benjamin8b8c0062014-11-23 02:47:52 -05006499 protocols := []protocol{tls}
6500 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6501 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006502 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006503 for _, protocol := range protocols {
6504 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6505 if protocol == dtls {
6506 suffix += "-DTLS"
6507 }
6508
Steven Valdez520e1222017-06-13 12:45:25 -04006509 // We can't resume across TLS 1.3 variants and error out earlier in the
6510 // session resumption.
6511 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6512 continue
6513 }
6514
David Benjaminece3de92015-03-16 18:02:20 -04006515 if sessionVers.version == resumeVers.version {
6516 testCases = append(testCases, testCase{
6517 protocol: protocol,
6518 name: "Resume-Client" + suffix,
6519 resumeSession: true,
6520 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006521 MaxVersion: sessionVers.version,
6522 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006523 Bugs: ProtocolBugs{
6524 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6525 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6526 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006527 },
David Benjaminece3de92015-03-16 18:02:20 -04006528 expectedVersion: sessionVers.version,
6529 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006530 flags: []string{
6531 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6532 },
David Benjaminece3de92015-03-16 18:02:20 -04006533 })
6534 } else {
David Benjamin405da482016-08-08 17:25:07 -04006535 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6536
6537 // Offering a TLS 1.3 session sends an empty session ID, so
6538 // there is no way to convince a non-lookahead client the
6539 // session was resumed. It will appear to the client that a
6540 // stray ChangeCipherSpec was sent.
6541 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6542 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006543 }
6544
David Benjaminece3de92015-03-16 18:02:20 -04006545 testCases = append(testCases, testCase{
6546 protocol: protocol,
6547 name: "Resume-Client-Mismatch" + suffix,
6548 resumeSession: true,
6549 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006550 MaxVersion: sessionVers.version,
6551 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006552 },
David Benjaminece3de92015-03-16 18:02:20 -04006553 expectedVersion: sessionVers.version,
6554 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006555 MaxVersion: resumeVers.version,
6556 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006557 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006558 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006559 },
6560 },
6561 expectedResumeVersion: resumeVers.version,
6562 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006563 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006564 flags: []string{
6565 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6566 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6567 },
David Benjaminece3de92015-03-16 18:02:20 -04006568 })
6569 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006570
6571 testCases = append(testCases, testCase{
6572 protocol: protocol,
6573 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006574 resumeSession: true,
6575 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006576 MaxVersion: sessionVers.version,
6577 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006578 },
6579 expectedVersion: sessionVers.version,
6580 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006581 MaxVersion: resumeVers.version,
6582 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006583 },
6584 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006585 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006586 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006587 flags: []string{
6588 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6589 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6590 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006591 })
6592
David Benjamin8b8c0062014-11-23 02:47:52 -05006593 testCases = append(testCases, testCase{
6594 protocol: protocol,
6595 testType: serverTest,
6596 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006597 resumeSession: true,
6598 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006599 MaxVersion: sessionVers.version,
6600 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006601 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006602 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006603 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006604 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: resumeVers.version,
6606 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006607 Bugs: ProtocolBugs{
6608 SendBothTickets: true,
6609 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006610 },
6611 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006612 flags: []string{
6613 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6614 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6615 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006616 })
6617 }
David Benjamin01fe8202014-09-24 15:21:44 -04006618 }
6619 }
David Benjaminece3de92015-03-16 18:02:20 -04006620
David Benjamin4199b0d2016-11-01 13:58:25 -04006621 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006622 testCases = append(testCases, testCase{
6623 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006624 name: "ShimTicketRewritable",
6625 resumeSession: true,
6626 config: Config{
6627 MaxVersion: VersionTLS12,
6628 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6629 Bugs: ProtocolBugs{
6630 FilterTicket: func(in []byte) ([]byte, error) {
6631 in, err := SetShimTicketVersion(in, VersionTLS12)
6632 if err != nil {
6633 return nil, err
6634 }
6635 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6636 },
6637 },
6638 },
6639 flags: []string{
6640 "-ticket-key",
6641 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6642 },
6643 })
6644
6645 // Resumptions are declined if the version does not match.
6646 testCases = append(testCases, testCase{
6647 testType: serverTest,
6648 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006649 resumeSession: true,
6650 config: Config{
6651 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006652 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006653 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006654 FilterTicket: func(in []byte) ([]byte, error) {
6655 return SetShimTicketVersion(in, VersionTLS13)
6656 },
6657 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006658 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006659 flags: []string{
6660 "-ticket-key",
6661 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6662 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006663 expectResumeRejected: true,
6664 })
6665
6666 testCases = append(testCases, testCase{
6667 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006668 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006669 resumeSession: true,
6670 config: Config{
6671 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006672 Bugs: ProtocolBugs{
6673 FilterTicket: func(in []byte) ([]byte, error) {
6674 return SetShimTicketVersion(in, VersionTLS12)
6675 },
6676 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006677 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006678 flags: []string{
6679 "-ticket-key",
6680 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6681 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006682 expectResumeRejected: true,
6683 })
6684
David Benjamin4199b0d2016-11-01 13:58:25 -04006685 // Resumptions are declined if the cipher is invalid or disabled.
6686 testCases = append(testCases, testCase{
6687 testType: serverTest,
6688 name: "Resume-Server-DeclineBadCipher",
6689 resumeSession: true,
6690 config: Config{
6691 MaxVersion: VersionTLS12,
6692 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006693 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006694 FilterTicket: func(in []byte) ([]byte, error) {
6695 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6696 },
6697 },
6698 },
6699 flags: []string{
6700 "-ticket-key",
6701 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6702 },
6703 expectResumeRejected: true,
6704 })
6705
6706 testCases = append(testCases, testCase{
6707 testType: serverTest,
6708 name: "Resume-Server-DeclineBadCipher-2",
6709 resumeSession: true,
6710 config: Config{
6711 MaxVersion: VersionTLS12,
6712 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006713 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006714 FilterTicket: func(in []byte) ([]byte, error) {
6715 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6716 },
6717 },
6718 },
6719 flags: []string{
6720 "-cipher", "AES128",
6721 "-ticket-key",
6722 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6723 },
6724 expectResumeRejected: true,
6725 })
6726
David Benjaminf01f42a2016-11-16 19:05:33 +09006727 // Sessions are not resumed if they do not use the preferred cipher.
6728 testCases = append(testCases, testCase{
6729 testType: serverTest,
6730 name: "Resume-Server-CipherNotPreferred",
6731 resumeSession: true,
6732 config: Config{
6733 MaxVersion: VersionTLS12,
6734 Bugs: ProtocolBugs{
6735 ExpectNewTicket: true,
6736 FilterTicket: func(in []byte) ([]byte, error) {
6737 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6738 },
6739 },
6740 },
6741 flags: []string{
6742 "-ticket-key",
6743 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6744 },
6745 shouldFail: false,
6746 expectResumeRejected: true,
6747 })
6748
6749 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6750 // PRF hashes match, but BoringSSL will always decline such resumptions.
6751 testCases = append(testCases, testCase{
6752 testType: serverTest,
6753 name: "Resume-Server-CipherNotPreferred-TLS13",
6754 resumeSession: true,
6755 config: Config{
6756 MaxVersion: VersionTLS13,
6757 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6758 Bugs: ProtocolBugs{
6759 FilterTicket: func(in []byte) ([]byte, error) {
6760 // If the client (runner) offers ChaCha20-Poly1305 first, the
6761 // server (shim) always prefers it. Switch it to AES-GCM.
6762 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6763 },
6764 },
6765 },
6766 flags: []string{
6767 "-ticket-key",
6768 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6769 },
6770 shouldFail: false,
6771 expectResumeRejected: true,
6772 })
6773
6774 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006775 testCases = append(testCases, testCase{
6776 testType: serverTest,
6777 name: "Resume-Server-DeclineBadCipher-TLS13",
6778 resumeSession: true,
6779 config: Config{
6780 MaxVersion: VersionTLS13,
6781 Bugs: ProtocolBugs{
6782 FilterTicket: func(in []byte) ([]byte, error) {
6783 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6784 },
6785 },
6786 },
6787 flags: []string{
6788 "-ticket-key",
6789 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6790 },
6791 expectResumeRejected: true,
6792 })
6793
David Benjaminf01f42a2016-11-16 19:05:33 +09006794 // If the client does not offer the cipher from the session, decline to
6795 // resume. Clients are forbidden from doing this, but BoringSSL selects
6796 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006797 testCases = append(testCases, testCase{
6798 testType: serverTest,
6799 name: "Resume-Server-UnofferedCipher",
6800 resumeSession: true,
6801 config: Config{
6802 MaxVersion: VersionTLS12,
6803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6804 },
6805 resumeConfig: &Config{
6806 MaxVersion: VersionTLS12,
6807 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6808 Bugs: ProtocolBugs{
6809 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6810 },
6811 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006812 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006813 })
6814
David Benjaminf01f42a2016-11-16 19:05:33 +09006815 // In TLS 1.3, clients may advertise a cipher list which does not
6816 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006817 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6818 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "Resume-Server-UnofferedCipher-TLS13",
6822 resumeSession: true,
6823 config: Config{
6824 MaxVersion: VersionTLS13,
6825 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6826 },
6827 resumeConfig: &Config{
6828 MaxVersion: VersionTLS13,
6829 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6830 Bugs: ProtocolBugs{
6831 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6832 },
6833 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006834 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006835 })
6836
David Benjamin4199b0d2016-11-01 13:58:25 -04006837 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006838 testCases = append(testCases, testCase{
6839 name: "Resume-Client-CipherMismatch",
6840 resumeSession: true,
6841 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006842 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006843 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6844 },
6845 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006846 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006847 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6848 Bugs: ProtocolBugs{
6849 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6850 },
6851 },
6852 shouldFail: true,
6853 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6854 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006855
David Benjamine1cc35e2016-11-16 16:25:58 +09006856 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6857 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006858 testCases = append(testCases, testCase{
6859 name: "Resume-Client-CipherMismatch-TLS13",
6860 resumeSession: true,
6861 config: Config{
6862 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006863 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006864 },
6865 resumeConfig: &Config{
6866 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006867 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6868 },
6869 })
6870
6871 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6872 testCases = append(testCases, testCase{
6873 name: "Resume-Client-PRFMismatch-TLS13",
6874 resumeSession: true,
6875 config: Config{
6876 MaxVersion: VersionTLS13,
6877 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6878 },
6879 resumeConfig: &Config{
6880 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006881 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006882 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006883 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006884 },
6885 },
6886 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006887 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006888 })
Steven Valdeza833c352016-11-01 13:39:36 -04006889
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: "Resume-Server-BinderWrongLength",
6893 resumeSession: true,
6894 config: Config{
6895 MaxVersion: VersionTLS13,
6896 Bugs: ProtocolBugs{
6897 SendShortPSKBinder: true,
6898 },
6899 },
6900 shouldFail: true,
6901 expectedLocalError: "remote error: error decrypting message",
6902 expectedError: ":DIGEST_CHECK_FAILED:",
6903 })
6904
6905 testCases = append(testCases, testCase{
6906 testType: serverTest,
6907 name: "Resume-Server-NoPSKBinder",
6908 resumeSession: true,
6909 config: Config{
6910 MaxVersion: VersionTLS13,
6911 Bugs: ProtocolBugs{
6912 SendNoPSKBinder: true,
6913 },
6914 },
6915 shouldFail: true,
6916 expectedLocalError: "remote error: error decoding message",
6917 expectedError: ":DECODE_ERROR:",
6918 })
6919
6920 testCases = append(testCases, testCase{
6921 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006922 name: "Resume-Server-ExtraPSKBinder",
6923 resumeSession: true,
6924 config: Config{
6925 MaxVersion: VersionTLS13,
6926 Bugs: ProtocolBugs{
6927 SendExtraPSKBinder: true,
6928 },
6929 },
6930 shouldFail: true,
6931 expectedLocalError: "remote error: illegal parameter",
6932 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6933 })
6934
6935 testCases = append(testCases, testCase{
6936 testType: serverTest,
6937 name: "Resume-Server-ExtraIdentityNoBinder",
6938 resumeSession: true,
6939 config: Config{
6940 MaxVersion: VersionTLS13,
6941 Bugs: ProtocolBugs{
6942 ExtraPSKIdentity: true,
6943 },
6944 },
6945 shouldFail: true,
6946 expectedLocalError: "remote error: illegal parameter",
6947 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6948 })
6949
6950 testCases = append(testCases, testCase{
6951 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006952 name: "Resume-Server-InvalidPSKBinder",
6953 resumeSession: true,
6954 config: Config{
6955 MaxVersion: VersionTLS13,
6956 Bugs: ProtocolBugs{
6957 SendInvalidPSKBinder: true,
6958 },
6959 },
6960 shouldFail: true,
6961 expectedLocalError: "remote error: error decrypting message",
6962 expectedError: ":DIGEST_CHECK_FAILED:",
6963 })
6964
6965 testCases = append(testCases, testCase{
6966 testType: serverTest,
6967 name: "Resume-Server-PSKBinderFirstExtension",
6968 resumeSession: true,
6969 config: Config{
6970 MaxVersion: VersionTLS13,
6971 Bugs: ProtocolBugs{
6972 PSKBinderFirst: true,
6973 },
6974 },
6975 shouldFail: true,
6976 expectedLocalError: "remote error: illegal parameter",
6977 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6978 })
David Benjamin01fe8202014-09-24 15:21:44 -04006979}
6980
Adam Langley2ae77d22014-10-28 17:29:33 -07006981func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006982 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006983 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006984 testType: serverTest,
6985 name: "Renegotiate-Server-Forbidden",
6986 config: Config{
6987 MaxVersion: VersionTLS12,
6988 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006989 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006990 shouldFail: true,
6991 expectedError: ":NO_RENEGOTIATION:",
6992 expectedLocalError: "remote error: no renegotiation",
6993 })
Adam Langley5021b222015-06-12 18:27:58 -07006994 // The server shouldn't echo the renegotiation extension unless
6995 // requested by the client.
6996 testCases = append(testCases, testCase{
6997 testType: serverTest,
6998 name: "Renegotiate-Server-NoExt",
6999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007001 Bugs: ProtocolBugs{
7002 NoRenegotiationInfo: true,
7003 RequireRenegotiationInfo: true,
7004 },
7005 },
7006 shouldFail: true,
7007 expectedLocalError: "renegotiation extension missing",
7008 })
7009 // The renegotiation SCSV should be sufficient for the server to echo
7010 // the extension.
7011 testCases = append(testCases, testCase{
7012 testType: serverTest,
7013 name: "Renegotiate-Server-NoExt-SCSV",
7014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007015 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007016 Bugs: ProtocolBugs{
7017 NoRenegotiationInfo: true,
7018 SendRenegotiationSCSV: true,
7019 RequireRenegotiationInfo: true,
7020 },
7021 },
7022 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007023 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007024 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007026 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007027 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007028 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007029 },
7030 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007031 renegotiate: 1,
7032 flags: []string{
7033 "-renegotiate-freely",
7034 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007035 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007036 },
David Benjamincdea40c2015-03-19 14:09:43 -04007037 })
7038 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007039 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007040 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007042 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007043 Bugs: ProtocolBugs{
7044 EmptyRenegotiationInfo: true,
7045 },
7046 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007047 flags: []string{"-renegotiate-freely"},
7048 shouldFail: true,
7049 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007050 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007051 })
7052 testCases = append(testCases, testCase{
7053 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007054 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007056 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007057 Bugs: ProtocolBugs{
7058 BadRenegotiationInfo: true,
7059 },
7060 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007061 flags: []string{"-renegotiate-freely"},
7062 shouldFail: true,
7063 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007064 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007065 })
7066 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007067 name: "Renegotiate-Client-BadExt2",
7068 renegotiate: 1,
7069 config: Config{
7070 MaxVersion: VersionTLS12,
7071 Bugs: ProtocolBugs{
7072 BadRenegotiationInfoEnd: true,
7073 },
7074 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007075 flags: []string{"-renegotiate-freely"},
7076 shouldFail: true,
7077 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007078 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007079 })
7080 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007081 name: "Renegotiate-Client-Downgrade",
7082 renegotiate: 1,
7083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007084 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007085 Bugs: ProtocolBugs{
7086 NoRenegotiationInfoAfterInitial: true,
7087 },
7088 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007089 flags: []string{"-renegotiate-freely"},
7090 shouldFail: true,
7091 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007092 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007093 })
7094 testCases = append(testCases, testCase{
7095 name: "Renegotiate-Client-Upgrade",
7096 renegotiate: 1,
7097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007098 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007099 Bugs: ProtocolBugs{
7100 NoRenegotiationInfoInInitial: true,
7101 },
7102 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007103 flags: []string{"-renegotiate-freely"},
7104 shouldFail: true,
7105 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007106 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007107 })
7108 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007109 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007110 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007112 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007113 Bugs: ProtocolBugs{
7114 NoRenegotiationInfo: true,
7115 },
7116 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007117 flags: []string{
7118 "-renegotiate-freely",
7119 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007120 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007121 },
David Benjamincff0b902015-05-15 23:09:47 -04007122 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007123
7124 // Test that the server may switch ciphers on renegotiation without
7125 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007126 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007128 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007129 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007130 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007131 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007132 },
7133 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007134 flags: []string{
7135 "-renegotiate-freely",
7136 "-expect-total-renegotiations", "1",
7137 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007138 })
7139 testCases = append(testCases, testCase{
7140 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007141 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007142 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007143 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007144 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7145 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007146 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007147 flags: []string{
7148 "-renegotiate-freely",
7149 "-expect-total-renegotiations", "1",
7150 },
David Benjaminb16346b2015-04-08 19:16:58 -04007151 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007152
7153 // Test that the server may not switch versions on renegotiation.
7154 testCases = append(testCases, testCase{
7155 name: "Renegotiate-Client-SwitchVersion",
7156 config: Config{
7157 MaxVersion: VersionTLS12,
7158 // Pick a cipher which exists at both versions.
7159 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7160 Bugs: ProtocolBugs{
7161 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007162 // Avoid failing early at the record layer.
7163 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007164 },
7165 },
7166 renegotiate: 1,
7167 flags: []string{
7168 "-renegotiate-freely",
7169 "-expect-total-renegotiations", "1",
7170 },
7171 shouldFail: true,
7172 expectedError: ":WRONG_SSL_VERSION:",
7173 })
7174
David Benjaminb16346b2015-04-08 19:16:58 -04007175 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007176 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007177 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007178 config: Config{
7179 MaxVersion: VersionTLS10,
7180 Bugs: ProtocolBugs{
7181 RequireSameRenegoClientVersion: true,
7182 },
7183 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007184 flags: []string{
7185 "-renegotiate-freely",
7186 "-expect-total-renegotiations", "1",
7187 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007188 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007189 testCases = append(testCases, testCase{
7190 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007191 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007192 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007193 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007194 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7195 NextProtos: []string{"foo"},
7196 },
7197 flags: []string{
7198 "-false-start",
7199 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007200 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007201 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007202 },
7203 shimWritesFirst: true,
7204 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007205
7206 // Client-side renegotiation controls.
7207 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007208 name: "Renegotiate-Client-Forbidden-1",
7209 config: Config{
7210 MaxVersion: VersionTLS12,
7211 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007212 renegotiate: 1,
7213 shouldFail: true,
7214 expectedError: ":NO_RENEGOTIATION:",
7215 expectedLocalError: "remote error: no renegotiation",
7216 })
7217 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007218 name: "Renegotiate-Client-Once-1",
7219 config: Config{
7220 MaxVersion: VersionTLS12,
7221 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007222 renegotiate: 1,
7223 flags: []string{
7224 "-renegotiate-once",
7225 "-expect-total-renegotiations", "1",
7226 },
7227 })
7228 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007229 name: "Renegotiate-Client-Freely-1",
7230 config: Config{
7231 MaxVersion: VersionTLS12,
7232 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007233 renegotiate: 1,
7234 flags: []string{
7235 "-renegotiate-freely",
7236 "-expect-total-renegotiations", "1",
7237 },
7238 })
7239 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007240 name: "Renegotiate-Client-Once-2",
7241 config: Config{
7242 MaxVersion: VersionTLS12,
7243 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007244 renegotiate: 2,
7245 flags: []string{"-renegotiate-once"},
7246 shouldFail: true,
7247 expectedError: ":NO_RENEGOTIATION:",
7248 expectedLocalError: "remote error: no renegotiation",
7249 })
7250 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007251 name: "Renegotiate-Client-Freely-2",
7252 config: Config{
7253 MaxVersion: VersionTLS12,
7254 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007255 renegotiate: 2,
7256 flags: []string{
7257 "-renegotiate-freely",
7258 "-expect-total-renegotiations", "2",
7259 },
7260 })
Adam Langley27a0d082015-11-03 13:34:10 -08007261 testCases = append(testCases, testCase{
7262 name: "Renegotiate-Client-NoIgnore",
7263 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007264 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007265 Bugs: ProtocolBugs{
7266 SendHelloRequestBeforeEveryAppDataRecord: true,
7267 },
7268 },
7269 shouldFail: true,
7270 expectedError: ":NO_RENEGOTIATION:",
7271 })
7272 testCases = append(testCases, testCase{
7273 name: "Renegotiate-Client-Ignore",
7274 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007275 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007276 Bugs: ProtocolBugs{
7277 SendHelloRequestBeforeEveryAppDataRecord: true,
7278 },
7279 },
7280 flags: []string{
7281 "-renegotiate-ignore",
7282 "-expect-total-renegotiations", "0",
7283 },
7284 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007285
David Benjamin34941c02016-10-08 11:45:31 -04007286 // Renegotiation is not allowed at SSL 3.0.
7287 testCases = append(testCases, testCase{
7288 name: "Renegotiate-Client-SSL3",
7289 config: Config{
7290 MaxVersion: VersionSSL30,
7291 },
7292 renegotiate: 1,
7293 flags: []string{
7294 "-renegotiate-freely",
7295 "-expect-total-renegotiations", "1",
7296 },
7297 shouldFail: true,
7298 expectedError: ":NO_RENEGOTIATION:",
7299 expectedLocalError: "remote error: no renegotiation",
7300 })
7301
David Benjamina1eaba12017-01-01 23:19:22 -05007302 // Renegotiation is not allowed when there is an unfinished write.
7303 testCases = append(testCases, testCase{
7304 name: "Renegotiate-Client-UnfinishedWrite",
7305 config: Config{
7306 MaxVersion: VersionTLS12,
7307 },
David Benjaminbbba9392017-04-06 12:54:12 -04007308 renegotiate: 1,
7309 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007310 flags: []string{
7311 "-async",
7312 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007313 },
7314 shouldFail: true,
7315 expectedError: ":NO_RENEGOTIATION:",
7316 // We do not successfully send the no_renegotiation alert in
7317 // this case. https://crbug.com/boringssl/130
7318 })
7319
David Benjamin07ab5d42017-02-09 20:11:41 -05007320 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007321 testCases = append(testCases, testCase{
7322 name: "StrayHelloRequest",
7323 config: Config{
7324 MaxVersion: VersionTLS12,
7325 Bugs: ProtocolBugs{
7326 SendHelloRequestBeforeEveryHandshakeMessage: true,
7327 },
7328 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007329 shouldFail: true,
7330 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007331 })
7332 testCases = append(testCases, testCase{
7333 name: "StrayHelloRequest-Packed",
7334 config: Config{
7335 MaxVersion: VersionTLS12,
7336 Bugs: ProtocolBugs{
7337 PackHandshakeFlight: true,
7338 SendHelloRequestBeforeEveryHandshakeMessage: true,
7339 },
7340 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007341 shouldFail: true,
7342 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007343 })
7344
David Benjamin12d2c482016-07-24 10:56:51 -04007345 // Test renegotiation works if HelloRequest and server Finished come in
7346 // the same record.
7347 testCases = append(testCases, testCase{
7348 name: "Renegotiate-Client-Packed",
7349 config: Config{
7350 MaxVersion: VersionTLS12,
7351 Bugs: ProtocolBugs{
7352 PackHandshakeFlight: true,
7353 PackHelloRequestWithFinished: true,
7354 },
7355 },
7356 renegotiate: 1,
7357 flags: []string{
7358 "-renegotiate-freely",
7359 "-expect-total-renegotiations", "1",
7360 },
7361 })
7362
David Benjamin397c8e62016-07-08 14:14:36 -07007363 // Renegotiation is forbidden in TLS 1.3.
7364 testCases = append(testCases, testCase{
7365 name: "Renegotiate-Client-TLS13",
7366 config: Config{
7367 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007368 Bugs: ProtocolBugs{
7369 SendHelloRequestBeforeEveryAppDataRecord: true,
7370 },
David Benjamin397c8e62016-07-08 14:14:36 -07007371 },
David Benjamin397c8e62016-07-08 14:14:36 -07007372 flags: []string{
7373 "-renegotiate-freely",
7374 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007375 shouldFail: true,
7376 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007377 })
7378
7379 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7380 testCases = append(testCases, testCase{
7381 name: "StrayHelloRequest-TLS13",
7382 config: Config{
7383 MaxVersion: VersionTLS13,
7384 Bugs: ProtocolBugs{
7385 SendHelloRequestBeforeEveryHandshakeMessage: true,
7386 },
7387 },
7388 shouldFail: true,
7389 expectedError: ":UNEXPECTED_MESSAGE:",
7390 })
David Benjamind2610042017-01-03 10:49:28 -05007391
7392 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7393 // always reads as supporting it, regardless of whether it was
7394 // negotiated.
7395 testCases = append(testCases, testCase{
7396 name: "AlwaysReportRenegotiationInfo-TLS13",
7397 config: Config{
7398 MaxVersion: VersionTLS13,
7399 Bugs: ProtocolBugs{
7400 NoRenegotiationInfo: true,
7401 },
7402 },
7403 flags: []string{
7404 "-expect-secure-renegotiation",
7405 },
7406 })
David Benjamina58baaf2017-02-28 20:54:28 -05007407
7408 // Certificates may not change on renegotiation.
7409 testCases = append(testCases, testCase{
7410 name: "Renegotiation-CertificateChange",
7411 config: Config{
7412 MaxVersion: VersionTLS12,
7413 Certificates: []Certificate{rsaCertificate},
7414 Bugs: ProtocolBugs{
7415 RenegotiationCertificate: &rsaChainCertificate,
7416 },
7417 },
7418 renegotiate: 1,
7419 flags: []string{"-renegotiate-freely"},
7420 shouldFail: true,
7421 expectedError: ":SERVER_CERT_CHANGED:",
7422 })
7423 testCases = append(testCases, testCase{
7424 name: "Renegotiation-CertificateChange-2",
7425 config: Config{
7426 MaxVersion: VersionTLS12,
7427 Certificates: []Certificate{rsaCertificate},
7428 Bugs: ProtocolBugs{
7429 RenegotiationCertificate: &rsa1024Certificate,
7430 },
7431 },
7432 renegotiate: 1,
7433 flags: []string{"-renegotiate-freely"},
7434 shouldFail: true,
7435 expectedError: ":SERVER_CERT_CHANGED:",
7436 })
David Benjaminbbf42462017-03-14 21:27:10 -04007437
7438 // We do not negotiate ALPN after the initial handshake. This is
7439 // error-prone and only risks bugs in consumers.
7440 testCases = append(testCases, testCase{
7441 testType: clientTest,
7442 name: "Renegotiation-ForbidALPN",
7443 config: Config{
7444 MaxVersion: VersionTLS12,
7445 Bugs: ProtocolBugs{
7446 // Forcibly negotiate ALPN on both initial and
7447 // renegotiation handshakes. The test stack will
7448 // internally check the client does not offer
7449 // it.
7450 SendALPN: "foo",
7451 },
7452 },
7453 flags: []string{
7454 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7455 "-expect-alpn", "foo",
7456 "-renegotiate-freely",
7457 },
7458 renegotiate: 1,
7459 shouldFail: true,
7460 expectedError: ":UNEXPECTED_EXTENSION:",
7461 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007462}
7463
David Benjamin5e961c12014-11-07 01:48:35 -05007464func addDTLSReplayTests() {
7465 // Test that sequence number replays are detected.
7466 testCases = append(testCases, testCase{
7467 protocol: dtls,
7468 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007469 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007470 replayWrites: true,
7471 })
7472
David Benjamin8e6db492015-07-25 18:29:23 -04007473 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007474 // than the retransmit window.
7475 testCases = append(testCases, testCase{
7476 protocol: dtls,
7477 name: "DTLS-Replay-LargeGaps",
7478 config: Config{
7479 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007480 SequenceNumberMapping: func(in uint64) uint64 {
7481 return in * 127
7482 },
David Benjamin5e961c12014-11-07 01:48:35 -05007483 },
7484 },
David Benjamin8e6db492015-07-25 18:29:23 -04007485 messageCount: 200,
7486 replayWrites: true,
7487 })
7488
7489 // Test the incoming sequence number changing non-monotonically.
7490 testCases = append(testCases, testCase{
7491 protocol: dtls,
7492 name: "DTLS-Replay-NonMonotonic",
7493 config: Config{
7494 Bugs: ProtocolBugs{
7495 SequenceNumberMapping: func(in uint64) uint64 {
7496 return in ^ 31
7497 },
7498 },
7499 },
7500 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007501 replayWrites: true,
7502 })
7503}
7504
Nick Harper60edffd2016-06-21 15:19:24 -07007505var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007506 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007507 id signatureAlgorithm
7508 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007509}{
Nick Harper60edffd2016-06-21 15:19:24 -07007510 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7511 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7512 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7513 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007514 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007515 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7516 // hash function doesn't have to match the curve and so the same
7517 // signature algorithm works with P-224.
7518 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007519 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7520 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7521 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007522 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7523 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7524 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007525 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007526 // Tests for key types prior to TLS 1.2.
7527 {"RSA", 0, testCertRSA},
7528 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007529}
7530
Nick Harper60edffd2016-06-21 15:19:24 -07007531const fakeSigAlg1 signatureAlgorithm = 0x2a01
7532const fakeSigAlg2 signatureAlgorithm = 0xff01
7533
7534func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007535 // Not all ciphers involve a signature. Advertise a list which gives all
7536 // versions a signing cipher.
7537 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007538 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007539 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7540 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7541 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7542 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007543 }
David Benjamin5208fd42016-07-13 21:43:25 -04007544
David Benjaminca3d5452016-07-14 12:51:01 -04007545 var allAlgorithms []signatureAlgorithm
7546 for _, alg := range testSignatureAlgorithms {
7547 if alg.id != 0 {
7548 allAlgorithms = append(allAlgorithms, alg.id)
7549 }
7550 }
7551
Nick Harper60edffd2016-06-21 15:19:24 -07007552 // Make sure each signature algorithm works. Include some fake values in
7553 // the list and ensure they're ignored.
7554 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007555 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007556 if (ver.version < VersionTLS12) != (alg.id == 0) {
7557 continue
7558 }
7559
7560 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7561 // or remove it in C.
7562 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007563 continue
7564 }
Nick Harper60edffd2016-06-21 15:19:24 -07007565
David Benjamin3ef76972016-10-17 17:59:54 -04007566 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007567 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007568 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007569 shouldSignFail = true
7570 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007571 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007572 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007573 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7574 shouldSignFail = true
7575 shouldVerifyFail = true
7576 }
7577 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7578 // the curve has to match the hash size.
7579 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007580 shouldSignFail = true
7581 shouldVerifyFail = true
7582 }
7583
7584 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7585 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7586 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007587 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007588
7589 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007590 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007591 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007592 }
7593 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007594 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007595 }
David Benjamin000800a2014-11-14 01:43:59 -05007596
David Benjamin1fb125c2016-07-08 18:52:12 -07007597 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007598
David Benjamin7a41d372016-07-09 11:21:54 -07007599 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007600 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007601 config: Config{
7602 MaxVersion: ver.version,
7603 ClientAuth: RequireAnyClientCert,
7604 VerifySignatureAlgorithms: []signatureAlgorithm{
7605 fakeSigAlg1,
7606 alg.id,
7607 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007608 },
David Benjamin7a41d372016-07-09 11:21:54 -07007609 },
7610 flags: []string{
7611 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7612 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7613 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007614 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007615 },
David Benjamina5022392017-07-10 17:40:39 -04007616 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007617 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007618 expectedError: signError,
7619 expectedPeerSignatureAlgorithm: alg.id,
7620 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007621
David Benjamin7a41d372016-07-09 11:21:54 -07007622 testCases = append(testCases, testCase{
7623 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007624 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007625 config: Config{
7626 MaxVersion: ver.version,
7627 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7628 SignSignatureAlgorithms: []signatureAlgorithm{
7629 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007630 },
David Benjamin7a41d372016-07-09 11:21:54 -07007631 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007632 SkipECDSACurveCheck: shouldVerifyFail,
7633 IgnoreSignatureVersionChecks: shouldVerifyFail,
7634 // Some signature algorithms may not be advertised.
7635 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007636 },
David Benjamin7a41d372016-07-09 11:21:54 -07007637 },
David Benjamina5022392017-07-10 17:40:39 -04007638 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007639 flags: []string{
7640 "-require-any-client-certificate",
7641 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7642 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007643 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007644 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007645 // Resume the session to assert the peer signature
7646 // algorithm is reported on both handshakes.
7647 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007648 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007649 expectedError: verifyError,
7650 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007651
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007652 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007653 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007654 testCases = append(testCases, testCase{
7655 testType: serverTest,
7656 name: "ServerAuth-Sign" + suffix,
7657 config: Config{
7658 MaxVersion: ver.version,
7659 CipherSuites: signingCiphers,
7660 VerifySignatureAlgorithms: []signatureAlgorithm{
7661 fakeSigAlg1,
7662 alg.id,
7663 fakeSigAlg2,
7664 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007665 },
David Benjamina5022392017-07-10 17:40:39 -04007666 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007667 flags: []string{
7668 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7669 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7670 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007671 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007672 },
7673 shouldFail: shouldSignFail,
7674 expectedError: signError,
7675 expectedPeerSignatureAlgorithm: alg.id,
7676 })
7677 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007678
7679 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007680 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 config: Config{
7682 MaxVersion: ver.version,
7683 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007684 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007685 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007686 alg.id,
7687 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007688 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007689 SkipECDSACurveCheck: shouldVerifyFail,
7690 IgnoreSignatureVersionChecks: shouldVerifyFail,
7691 // Some signature algorithms may not be advertised.
7692 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007693 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007694 },
David Benjamina5022392017-07-10 17:40:39 -04007695 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007696 flags: []string{
7697 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7698 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007699 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007700 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007701 // Resume the session to assert the peer signature
7702 // algorithm is reported on both handshakes.
7703 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007704 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007705 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007706 })
David Benjamin5208fd42016-07-13 21:43:25 -04007707
David Benjamin3ef76972016-10-17 17:59:54 -04007708 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007709 testCases = append(testCases, testCase{
7710 testType: serverTest,
7711 name: "ClientAuth-InvalidSignature" + suffix,
7712 config: Config{
7713 MaxVersion: ver.version,
7714 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7715 SignSignatureAlgorithms: []signatureAlgorithm{
7716 alg.id,
7717 },
7718 Bugs: ProtocolBugs{
7719 InvalidSignature: true,
7720 },
7721 },
David Benjamina5022392017-07-10 17:40:39 -04007722 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007723 flags: []string{
7724 "-require-any-client-certificate",
7725 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007726 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007727 },
7728 shouldFail: true,
7729 expectedError: ":BAD_SIGNATURE:",
7730 })
7731
7732 testCases = append(testCases, testCase{
7733 name: "ServerAuth-InvalidSignature" + suffix,
7734 config: Config{
7735 MaxVersion: ver.version,
7736 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7737 CipherSuites: signingCiphers,
7738 SignSignatureAlgorithms: []signatureAlgorithm{
7739 alg.id,
7740 },
7741 Bugs: ProtocolBugs{
7742 InvalidSignature: true,
7743 },
7744 },
David Benjamina5022392017-07-10 17:40:39 -04007745 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007746 flags: []string{
7747 "-enable-all-curves",
7748 "-enable-ed25519",
7749 },
David Benjamin5208fd42016-07-13 21:43:25 -04007750 shouldFail: true,
7751 expectedError: ":BAD_SIGNATURE:",
7752 })
7753 }
David Benjaminca3d5452016-07-14 12:51:01 -04007754
David Benjamin3ef76972016-10-17 17:59:54 -04007755 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007756 testCases = append(testCases, testCase{
7757 name: "ClientAuth-Sign-Negotiate" + suffix,
7758 config: Config{
7759 MaxVersion: ver.version,
7760 ClientAuth: RequireAnyClientCert,
7761 VerifySignatureAlgorithms: allAlgorithms,
7762 },
David Benjamina5022392017-07-10 17:40:39 -04007763 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007764 flags: []string{
7765 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7766 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7767 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007768 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007769 "-signing-prefs", strconv.Itoa(int(alg.id)),
7770 },
7771 expectedPeerSignatureAlgorithm: alg.id,
7772 })
7773
7774 testCases = append(testCases, testCase{
7775 testType: serverTest,
7776 name: "ServerAuth-Sign-Negotiate" + suffix,
7777 config: Config{
7778 MaxVersion: ver.version,
7779 CipherSuites: signingCiphers,
7780 VerifySignatureAlgorithms: allAlgorithms,
7781 },
David Benjamina5022392017-07-10 17:40:39 -04007782 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007783 flags: []string{
7784 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7785 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7786 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007787 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007788 "-signing-prefs", strconv.Itoa(int(alg.id)),
7789 },
7790 expectedPeerSignatureAlgorithm: alg.id,
7791 })
7792 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007793 }
David Benjamin000800a2014-11-14 01:43:59 -05007794 }
7795
Nick Harper60edffd2016-06-21 15:19:24 -07007796 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007797 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007798 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007799 config: Config{
7800 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007801 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007802 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007803 signatureECDSAWithP521AndSHA512,
7804 signatureRSAPKCS1WithSHA384,
7805 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007806 },
7807 },
7808 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007809 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7810 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007811 },
Nick Harper60edffd2016-06-21 15:19:24 -07007812 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007813 })
7814
7815 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007816 name: "ClientAuth-SignatureType-TLS13",
7817 config: Config{
7818 ClientAuth: RequireAnyClientCert,
7819 MaxVersion: VersionTLS13,
7820 VerifySignatureAlgorithms: []signatureAlgorithm{
7821 signatureECDSAWithP521AndSHA512,
7822 signatureRSAPKCS1WithSHA384,
7823 signatureRSAPSSWithSHA384,
7824 signatureECDSAWithSHA1,
7825 },
7826 },
7827 flags: []string{
7828 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7829 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7830 },
7831 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7832 })
7833
7834 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007835 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007836 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007838 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007839 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007840 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007841 signatureECDSAWithP521AndSHA512,
7842 signatureRSAPKCS1WithSHA384,
7843 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007844 },
7845 },
Nick Harper60edffd2016-06-21 15:19:24 -07007846 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007847 })
7848
Steven Valdez143e8b32016-07-11 13:19:03 -04007849 testCases = append(testCases, testCase{
7850 testType: serverTest,
7851 name: "ServerAuth-SignatureType-TLS13",
7852 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007853 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007854 VerifySignatureAlgorithms: []signatureAlgorithm{
7855 signatureECDSAWithP521AndSHA512,
7856 signatureRSAPKCS1WithSHA384,
7857 signatureRSAPSSWithSHA384,
7858 signatureECDSAWithSHA1,
7859 },
7860 },
7861 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7862 })
7863
David Benjamina95e9f32016-07-08 16:28:04 -07007864 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007865 testCases = append(testCases, testCase{
7866 testType: serverTest,
7867 name: "Verify-ClientAuth-SignatureType",
7868 config: Config{
7869 MaxVersion: VersionTLS12,
7870 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007871 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007872 signatureRSAPKCS1WithSHA256,
7873 },
7874 Bugs: ProtocolBugs{
7875 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7876 },
7877 },
7878 flags: []string{
7879 "-require-any-client-certificate",
7880 },
7881 shouldFail: true,
7882 expectedError: ":WRONG_SIGNATURE_TYPE:",
7883 })
7884
7885 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007886 testType: serverTest,
7887 name: "Verify-ClientAuth-SignatureType-TLS13",
7888 config: Config{
7889 MaxVersion: VersionTLS13,
7890 Certificates: []Certificate{rsaCertificate},
7891 SignSignatureAlgorithms: []signatureAlgorithm{
7892 signatureRSAPSSWithSHA256,
7893 },
7894 Bugs: ProtocolBugs{
7895 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7896 },
7897 },
7898 flags: []string{
7899 "-require-any-client-certificate",
7900 },
7901 shouldFail: true,
7902 expectedError: ":WRONG_SIGNATURE_TYPE:",
7903 })
7904
7905 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007906 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007907 config: Config{
7908 MaxVersion: VersionTLS12,
7909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007910 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007911 signatureRSAPKCS1WithSHA256,
7912 },
7913 Bugs: ProtocolBugs{
7914 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7915 },
7916 },
7917 shouldFail: true,
7918 expectedError: ":WRONG_SIGNATURE_TYPE:",
7919 })
7920
Steven Valdez143e8b32016-07-11 13:19:03 -04007921 testCases = append(testCases, testCase{
7922 name: "Verify-ServerAuth-SignatureType-TLS13",
7923 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007924 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007925 SignSignatureAlgorithms: []signatureAlgorithm{
7926 signatureRSAPSSWithSHA256,
7927 },
7928 Bugs: ProtocolBugs{
7929 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7930 },
7931 },
7932 shouldFail: true,
7933 expectedError: ":WRONG_SIGNATURE_TYPE:",
7934 })
7935
David Benjamin51dd7d62016-07-08 16:07:01 -07007936 // Test that, if the list is missing, the peer falls back to SHA-1 in
7937 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007938 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007939 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007941 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007942 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007943 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007944 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007945 },
7946 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007947 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007948 },
7949 },
7950 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007951 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7952 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007953 },
7954 })
7955
7956 testCases = append(testCases, testCase{
7957 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007958 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007959 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007960 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007961 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007962 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007963 },
7964 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007965 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007966 },
7967 },
David Benjaminee32bea2016-08-17 13:36:44 -04007968 flags: []string{
7969 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7970 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7971 },
7972 })
7973
7974 testCases = append(testCases, testCase{
7975 name: "ClientAuth-SHA1-Fallback-ECDSA",
7976 config: Config{
7977 MaxVersion: VersionTLS12,
7978 ClientAuth: RequireAnyClientCert,
7979 VerifySignatureAlgorithms: []signatureAlgorithm{
7980 signatureECDSAWithSHA1,
7981 },
7982 Bugs: ProtocolBugs{
7983 NoSignatureAlgorithms: true,
7984 },
7985 },
7986 flags: []string{
7987 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7988 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7989 },
7990 })
7991
7992 testCases = append(testCases, testCase{
7993 testType: serverTest,
7994 name: "ServerAuth-SHA1-Fallback-ECDSA",
7995 config: Config{
7996 MaxVersion: VersionTLS12,
7997 VerifySignatureAlgorithms: []signatureAlgorithm{
7998 signatureECDSAWithSHA1,
7999 },
8000 Bugs: ProtocolBugs{
8001 NoSignatureAlgorithms: true,
8002 },
8003 },
8004 flags: []string{
8005 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8006 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8007 },
David Benjamin000800a2014-11-14 01:43:59 -05008008 })
David Benjamin72dc7832015-03-16 17:49:43 -04008009
David Benjamin51dd7d62016-07-08 16:07:01 -07008010 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008011 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008012 config: Config{
8013 MaxVersion: VersionTLS13,
8014 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008015 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008016 signatureRSAPKCS1WithSHA1,
8017 },
8018 Bugs: ProtocolBugs{
8019 NoSignatureAlgorithms: true,
8020 },
8021 },
8022 flags: []string{
8023 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8024 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8025 },
David Benjamin48901652016-08-01 12:12:47 -04008026 shouldFail: true,
8027 // An empty CertificateRequest signature algorithm list is a
8028 // syntax error in TLS 1.3.
8029 expectedError: ":DECODE_ERROR:",
8030 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008031 })
8032
8033 testCases = append(testCases, testCase{
8034 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008035 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008036 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008037 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008038 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008039 signatureRSAPKCS1WithSHA1,
8040 },
8041 Bugs: ProtocolBugs{
8042 NoSignatureAlgorithms: true,
8043 },
8044 },
8045 shouldFail: true,
8046 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8047 })
8048
David Benjaminb62d2872016-07-18 14:55:02 +02008049 // Test that hash preferences are enforced. BoringSSL does not implement
8050 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008051 testCases = append(testCases, testCase{
8052 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008053 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008055 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008056 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008057 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008058 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008059 },
8060 Bugs: ProtocolBugs{
8061 IgnorePeerSignatureAlgorithmPreferences: true,
8062 },
8063 },
8064 flags: []string{"-require-any-client-certificate"},
8065 shouldFail: true,
8066 expectedError: ":WRONG_SIGNATURE_TYPE:",
8067 })
8068
8069 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008070 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008072 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008073 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008074 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008075 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008076 },
8077 Bugs: ProtocolBugs{
8078 IgnorePeerSignatureAlgorithmPreferences: true,
8079 },
8080 },
8081 shouldFail: true,
8082 expectedError: ":WRONG_SIGNATURE_TYPE:",
8083 })
David Benjaminb62d2872016-07-18 14:55:02 +02008084 testCases = append(testCases, testCase{
8085 testType: serverTest,
8086 name: "ClientAuth-Enforced-TLS13",
8087 config: Config{
8088 MaxVersion: VersionTLS13,
8089 Certificates: []Certificate{rsaCertificate},
8090 SignSignatureAlgorithms: []signatureAlgorithm{
8091 signatureRSAPKCS1WithMD5,
8092 },
8093 Bugs: ProtocolBugs{
8094 IgnorePeerSignatureAlgorithmPreferences: true,
8095 IgnoreSignatureVersionChecks: true,
8096 },
8097 },
8098 flags: []string{"-require-any-client-certificate"},
8099 shouldFail: true,
8100 expectedError: ":WRONG_SIGNATURE_TYPE:",
8101 })
8102
8103 testCases = append(testCases, testCase{
8104 name: "ServerAuth-Enforced-TLS13",
8105 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008106 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008107 SignSignatureAlgorithms: []signatureAlgorithm{
8108 signatureRSAPKCS1WithMD5,
8109 },
8110 Bugs: ProtocolBugs{
8111 IgnorePeerSignatureAlgorithmPreferences: true,
8112 IgnoreSignatureVersionChecks: true,
8113 },
8114 },
8115 shouldFail: true,
8116 expectedError: ":WRONG_SIGNATURE_TYPE:",
8117 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008118
8119 // Test that the agreed upon digest respects the client preferences and
8120 // the server digests.
8121 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008122 name: "NoCommonAlgorithms-Digests",
8123 config: Config{
8124 MaxVersion: VersionTLS12,
8125 ClientAuth: RequireAnyClientCert,
8126 VerifySignatureAlgorithms: []signatureAlgorithm{
8127 signatureRSAPKCS1WithSHA512,
8128 signatureRSAPKCS1WithSHA1,
8129 },
8130 },
8131 flags: []string{
8132 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8133 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8134 "-digest-prefs", "SHA256",
8135 },
8136 shouldFail: true,
8137 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8138 })
8139 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008140 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008142 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008143 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008144 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008145 signatureRSAPKCS1WithSHA512,
8146 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008147 },
8148 },
8149 flags: []string{
8150 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8151 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008152 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008153 },
David Benjaminca3d5452016-07-14 12:51:01 -04008154 shouldFail: true,
8155 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8156 })
8157 testCases = append(testCases, testCase{
8158 name: "NoCommonAlgorithms-TLS13",
8159 config: Config{
8160 MaxVersion: VersionTLS13,
8161 ClientAuth: RequireAnyClientCert,
8162 VerifySignatureAlgorithms: []signatureAlgorithm{
8163 signatureRSAPSSWithSHA512,
8164 signatureRSAPSSWithSHA384,
8165 },
8166 },
8167 flags: []string{
8168 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8169 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8170 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8171 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008172 shouldFail: true,
8173 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008174 })
8175 testCases = append(testCases, testCase{
8176 name: "Agree-Digest-SHA256",
8177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008178 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008179 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008180 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008181 signatureRSAPKCS1WithSHA1,
8182 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008183 },
8184 },
8185 flags: []string{
8186 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8187 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008188 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008189 },
Nick Harper60edffd2016-06-21 15:19:24 -07008190 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008191 })
8192 testCases = append(testCases, testCase{
8193 name: "Agree-Digest-SHA1",
8194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008195 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008196 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008197 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008198 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008199 },
8200 },
8201 flags: []string{
8202 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8203 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008204 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008205 },
Nick Harper60edffd2016-06-21 15:19:24 -07008206 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008207 })
8208 testCases = append(testCases, testCase{
8209 name: "Agree-Digest-Default",
8210 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008211 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008212 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008213 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008214 signatureRSAPKCS1WithSHA256,
8215 signatureECDSAWithP256AndSHA256,
8216 signatureRSAPKCS1WithSHA1,
8217 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008218 },
8219 },
8220 flags: []string{
8221 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8222 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8223 },
Nick Harper60edffd2016-06-21 15:19:24 -07008224 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008225 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008226
David Benjaminca3d5452016-07-14 12:51:01 -04008227 // Test that the signing preference list may include extra algorithms
8228 // without negotiation problems.
8229 testCases = append(testCases, testCase{
8230 testType: serverTest,
8231 name: "FilterExtraAlgorithms",
8232 config: Config{
8233 MaxVersion: VersionTLS12,
8234 VerifySignatureAlgorithms: []signatureAlgorithm{
8235 signatureRSAPKCS1WithSHA256,
8236 },
8237 },
8238 flags: []string{
8239 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8240 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8241 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8242 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8243 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8244 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8245 },
8246 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8247 })
8248
David Benjamin4c3ddf72016-06-29 18:13:53 -04008249 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8250 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008251 testCases = append(testCases, testCase{
8252 name: "CheckLeafCurve",
8253 config: Config{
8254 MaxVersion: VersionTLS12,
8255 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008256 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008257 },
8258 flags: []string{"-p384-only"},
8259 shouldFail: true,
8260 expectedError: ":BAD_ECC_CERT:",
8261 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008262
8263 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8264 testCases = append(testCases, testCase{
8265 name: "CheckLeafCurve-TLS13",
8266 config: Config{
8267 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008268 Certificates: []Certificate{ecdsaP256Certificate},
8269 },
8270 flags: []string{"-p384-only"},
8271 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008272
8273 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8274 testCases = append(testCases, testCase{
8275 name: "ECDSACurveMismatch-Verify-TLS12",
8276 config: Config{
8277 MaxVersion: VersionTLS12,
8278 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8279 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008280 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008281 signatureECDSAWithP384AndSHA384,
8282 },
8283 },
8284 })
8285
8286 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8287 testCases = append(testCases, testCase{
8288 name: "ECDSACurveMismatch-Verify-TLS13",
8289 config: Config{
8290 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008291 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008292 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008293 signatureECDSAWithP384AndSHA384,
8294 },
8295 Bugs: ProtocolBugs{
8296 SkipECDSACurveCheck: true,
8297 },
8298 },
8299 shouldFail: true,
8300 expectedError: ":WRONG_SIGNATURE_TYPE:",
8301 })
8302
8303 // Signature algorithm selection in TLS 1.3 should take the curve into
8304 // account.
8305 testCases = append(testCases, testCase{
8306 testType: serverTest,
8307 name: "ECDSACurveMismatch-Sign-TLS13",
8308 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008309 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008310 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008311 signatureECDSAWithP384AndSHA384,
8312 signatureECDSAWithP256AndSHA256,
8313 },
8314 },
8315 flags: []string{
8316 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8317 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8318 },
8319 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8320 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008321
8322 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8323 // server does not attempt to sign in that case.
8324 testCases = append(testCases, testCase{
8325 testType: serverTest,
8326 name: "RSA-PSS-Large",
8327 config: Config{
8328 MaxVersion: VersionTLS13,
8329 VerifySignatureAlgorithms: []signatureAlgorithm{
8330 signatureRSAPSSWithSHA512,
8331 },
8332 },
8333 flags: []string{
8334 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8335 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8336 },
8337 shouldFail: true,
8338 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8339 })
David Benjamin57e929f2016-08-30 00:30:38 -04008340
8341 // Test that RSA-PSS is enabled by default for TLS 1.2.
8342 testCases = append(testCases, testCase{
8343 testType: clientTest,
8344 name: "RSA-PSS-Default-Verify",
8345 config: Config{
8346 MaxVersion: VersionTLS12,
8347 SignSignatureAlgorithms: []signatureAlgorithm{
8348 signatureRSAPSSWithSHA256,
8349 },
8350 },
8351 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8352 })
8353
8354 testCases = append(testCases, testCase{
8355 testType: serverTest,
8356 name: "RSA-PSS-Default-Sign",
8357 config: Config{
8358 MaxVersion: VersionTLS12,
8359 VerifySignatureAlgorithms: []signatureAlgorithm{
8360 signatureRSAPSSWithSHA256,
8361 },
8362 },
8363 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8364 })
David Benjamin69522112017-03-28 15:38:29 -05008365
8366 // TLS 1.1 and below has no way to advertise support for or negotiate
8367 // Ed25519's signature algorithm.
8368 testCases = append(testCases, testCase{
8369 testType: clientTest,
8370 name: "NoEd25519-TLS11-ServerAuth-Verify",
8371 config: Config{
8372 MaxVersion: VersionTLS11,
8373 Certificates: []Certificate{ed25519Certificate},
8374 Bugs: ProtocolBugs{
8375 // Sign with Ed25519 even though it is TLS 1.1.
8376 UseLegacySigningAlgorithm: signatureEd25519,
8377 },
8378 },
8379 flags: []string{"-enable-ed25519"},
8380 shouldFail: true,
8381 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8382 })
8383 testCases = append(testCases, testCase{
8384 testType: serverTest,
8385 name: "NoEd25519-TLS11-ServerAuth-Sign",
8386 config: Config{
8387 MaxVersion: VersionTLS11,
8388 },
8389 flags: []string{
8390 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8391 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8392 },
8393 shouldFail: true,
8394 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8395 })
8396 testCases = append(testCases, testCase{
8397 testType: serverTest,
8398 name: "NoEd25519-TLS11-ClientAuth-Verify",
8399 config: Config{
8400 MaxVersion: VersionTLS11,
8401 Certificates: []Certificate{ed25519Certificate},
8402 Bugs: ProtocolBugs{
8403 // Sign with Ed25519 even though it is TLS 1.1.
8404 UseLegacySigningAlgorithm: signatureEd25519,
8405 },
8406 },
8407 flags: []string{
8408 "-enable-ed25519",
8409 "-require-any-client-certificate",
8410 },
8411 shouldFail: true,
8412 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8413 })
8414 testCases = append(testCases, testCase{
8415 testType: clientTest,
8416 name: "NoEd25519-TLS11-ClientAuth-Sign",
8417 config: Config{
8418 MaxVersion: VersionTLS11,
8419 ClientAuth: RequireAnyClientCert,
8420 },
8421 flags: []string{
8422 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8423 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8424 },
8425 shouldFail: true,
8426 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8427 })
8428
8429 // Test Ed25519 is not advertised by default.
8430 testCases = append(testCases, testCase{
8431 testType: clientTest,
8432 name: "Ed25519DefaultDisable-NoAdvertise",
8433 config: Config{
8434 Certificates: []Certificate{ed25519Certificate},
8435 },
8436 shouldFail: true,
8437 expectedLocalError: "tls: no common signature algorithms",
8438 })
8439
8440 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8441 // preferences.
8442 testCases = append(testCases, testCase{
8443 testType: clientTest,
8444 name: "Ed25519DefaultDisable-NoAccept",
8445 config: Config{
8446 Certificates: []Certificate{ed25519Certificate},
8447 Bugs: ProtocolBugs{
8448 IgnorePeerSignatureAlgorithmPreferences: true,
8449 },
8450 },
8451 shouldFail: true,
8452 expectedLocalError: "remote error: illegal parameter",
8453 expectedError: ":WRONG_SIGNATURE_TYPE:",
8454 })
David Benjamin71c21b42017-04-14 17:05:40 -04008455
8456 // Test that configuring verify preferences changes what the client
8457 // advertises.
8458 testCases = append(testCases, testCase{
8459 name: "VerifyPreferences-Advertised",
8460 config: Config{
8461 Certificates: []Certificate{rsaCertificate},
8462 SignSignatureAlgorithms: []signatureAlgorithm{
8463 signatureRSAPSSWithSHA256,
8464 signatureRSAPSSWithSHA384,
8465 signatureRSAPSSWithSHA512,
8466 },
8467 },
8468 flags: []string{
8469 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8470 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8471 },
8472 })
8473
8474 // Test that the client advertises a set which the runner can find
8475 // nothing in common with.
8476 testCases = append(testCases, testCase{
8477 name: "VerifyPreferences-NoCommonAlgorithms",
8478 config: Config{
8479 Certificates: []Certificate{rsaCertificate},
8480 SignSignatureAlgorithms: []signatureAlgorithm{
8481 signatureRSAPSSWithSHA256,
8482 signatureRSAPSSWithSHA512,
8483 },
8484 },
8485 flags: []string{
8486 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8487 },
8488 shouldFail: true,
8489 expectedLocalError: "tls: no common signature algorithms",
8490 })
8491
8492 // Test that the client enforces its preferences when configured.
8493 testCases = append(testCases, testCase{
8494 name: "VerifyPreferences-Enforced",
8495 config: Config{
8496 Certificates: []Certificate{rsaCertificate},
8497 SignSignatureAlgorithms: []signatureAlgorithm{
8498 signatureRSAPSSWithSHA256,
8499 signatureRSAPSSWithSHA512,
8500 },
8501 Bugs: ProtocolBugs{
8502 IgnorePeerSignatureAlgorithmPreferences: true,
8503 },
8504 },
8505 flags: []string{
8506 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8507 },
8508 shouldFail: true,
8509 expectedLocalError: "remote error: illegal parameter",
8510 expectedError: ":WRONG_SIGNATURE_TYPE:",
8511 })
8512
8513 // Test that explicitly configuring Ed25519 is as good as changing the
8514 // boolean toggle.
8515 testCases = append(testCases, testCase{
8516 name: "VerifyPreferences-Ed25519",
8517 config: Config{
8518 Certificates: []Certificate{ed25519Certificate},
8519 },
8520 flags: []string{
8521 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8522 },
8523 })
David Benjamin000800a2014-11-14 01:43:59 -05008524}
8525
David Benjamin83f90402015-01-27 01:09:43 -05008526// timeouts is the retransmit schedule for BoringSSL. It doubles and
8527// caps at 60 seconds. On the 13th timeout, it gives up.
8528var timeouts = []time.Duration{
8529 1 * time.Second,
8530 2 * time.Second,
8531 4 * time.Second,
8532 8 * time.Second,
8533 16 * time.Second,
8534 32 * time.Second,
8535 60 * time.Second,
8536 60 * time.Second,
8537 60 * time.Second,
8538 60 * time.Second,
8539 60 * time.Second,
8540 60 * time.Second,
8541 60 * time.Second,
8542}
8543
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008544// shortTimeouts is an alternate set of timeouts which would occur if the
8545// initial timeout duration was set to 250ms.
8546var shortTimeouts = []time.Duration{
8547 250 * time.Millisecond,
8548 500 * time.Millisecond,
8549 1 * time.Second,
8550 2 * time.Second,
8551 4 * time.Second,
8552 8 * time.Second,
8553 16 * time.Second,
8554 32 * time.Second,
8555 60 * time.Second,
8556 60 * time.Second,
8557 60 * time.Second,
8558 60 * time.Second,
8559 60 * time.Second,
8560}
8561
David Benjamin83f90402015-01-27 01:09:43 -05008562func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008563 // These tests work by coordinating some behavior on both the shim and
8564 // the runner.
8565 //
8566 // TimeoutSchedule configures the runner to send a series of timeout
8567 // opcodes to the shim (see packetAdaptor) immediately before reading
8568 // each peer handshake flight N. The timeout opcode both simulates a
8569 // timeout in the shim and acts as a synchronization point to help the
8570 // runner bracket each handshake flight.
8571 //
8572 // We assume the shim does not read from the channel eagerly. It must
8573 // first wait until it has sent flight N and is ready to receive
8574 // handshake flight N+1. At this point, it will process the timeout
8575 // opcode. It must then immediately respond with a timeout ACK and act
8576 // as if the shim was idle for the specified amount of time.
8577 //
8578 // The runner then drops all packets received before the ACK and
8579 // continues waiting for flight N. This ordering results in one attempt
8580 // at sending flight N to be dropped. For the test to complete, the
8581 // shim must send flight N again, testing that the shim implements DTLS
8582 // retransmit on a timeout.
8583
Steven Valdez143e8b32016-07-11 13:19:03 -04008584 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008585 // likely be more epochs to cross and the final message's retransmit may
8586 // be more complex.
8587
David Benjamin11c82892017-02-23 20:40:31 -05008588 // Test that this is indeed the timeout schedule. Stress all
8589 // four patterns of handshake.
8590 for i := 1; i < len(timeouts); i++ {
8591 number := strconv.Itoa(i)
8592 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008593 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008594 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008596 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008597 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008598 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008599 },
8600 },
8601 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008602 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008603 })
David Benjamin11c82892017-02-23 20:40:31 -05008604 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008605 protocol: dtls,
8606 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008607 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008608 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008609 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008610 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008611 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008612 },
8613 },
8614 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008615 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008616 })
8617 }
David Benjamin11c82892017-02-23 20:40:31 -05008618
8619 // Test that exceeding the timeout schedule hits a read
8620 // timeout.
8621 testCases = append(testCases, testCase{
8622 protocol: dtls,
8623 name: "DTLS-Retransmit-Timeout",
8624 config: Config{
8625 MaxVersion: VersionTLS12,
8626 Bugs: ProtocolBugs{
8627 TimeoutSchedule: timeouts,
8628 },
8629 },
8630 resumeSession: true,
8631 flags: []string{"-async"},
8632 shouldFail: true,
8633 expectedError: ":READ_TIMEOUT_EXPIRED:",
8634 })
8635
8636 // Test that timeout handling has a fudge factor, due to API
8637 // problems.
8638 testCases = append(testCases, testCase{
8639 protocol: dtls,
8640 name: "DTLS-Retransmit-Fudge",
8641 config: Config{
8642 MaxVersion: VersionTLS12,
8643 Bugs: ProtocolBugs{
8644 TimeoutSchedule: []time.Duration{
8645 timeouts[0] - 10*time.Millisecond,
8646 },
8647 },
8648 },
8649 resumeSession: true,
8650 flags: []string{"-async"},
8651 })
8652
8653 // Test that the final Finished retransmitting isn't
8654 // duplicated if the peer badly fragments everything.
8655 testCases = append(testCases, testCase{
8656 testType: serverTest,
8657 protocol: dtls,
8658 name: "DTLS-Retransmit-Fragmented",
8659 config: Config{
8660 MaxVersion: VersionTLS12,
8661 Bugs: ProtocolBugs{
8662 TimeoutSchedule: []time.Duration{timeouts[0]},
8663 MaxHandshakeRecordLength: 2,
8664 },
8665 },
8666 flags: []string{"-async"},
8667 })
8668
8669 // Test the timeout schedule when a shorter initial timeout duration is set.
8670 testCases = append(testCases, testCase{
8671 protocol: dtls,
8672 name: "DTLS-Retransmit-Short-Client",
8673 config: Config{
8674 MaxVersion: VersionTLS12,
8675 Bugs: ProtocolBugs{
8676 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8677 },
8678 },
8679 resumeSession: true,
8680 flags: []string{
8681 "-async",
8682 "-initial-timeout-duration-ms", "250",
8683 },
8684 })
8685 testCases = append(testCases, testCase{
8686 protocol: dtls,
8687 testType: serverTest,
8688 name: "DTLS-Retransmit-Short-Server",
8689 config: Config{
8690 MaxVersion: VersionTLS12,
8691 Bugs: ProtocolBugs{
8692 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8693 },
8694 },
8695 resumeSession: true,
8696 flags: []string{
8697 "-async",
8698 "-initial-timeout-duration-ms", "250",
8699 },
8700 })
David Benjamin83f90402015-01-27 01:09:43 -05008701}
8702
David Benjaminc565ebb2015-04-03 04:06:36 -04008703func addExportKeyingMaterialTests() {
8704 for _, vers := range tlsVersions {
8705 if vers.version == VersionSSL30 {
8706 continue
8707 }
8708 testCases = append(testCases, testCase{
8709 name: "ExportKeyingMaterial-" + vers.name,
8710 config: Config{
8711 MaxVersion: vers.version,
8712 },
David Benjamina5022392017-07-10 17:40:39 -04008713 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008714 exportKeyingMaterial: 1024,
8715 exportLabel: "label",
8716 exportContext: "context",
8717 useExportContext: true,
8718 })
8719 testCases = append(testCases, testCase{
8720 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8721 config: Config{
8722 MaxVersion: vers.version,
8723 },
David Benjamina5022392017-07-10 17:40:39 -04008724 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008725 exportKeyingMaterial: 1024,
8726 })
8727 testCases = append(testCases, testCase{
8728 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8729 config: Config{
8730 MaxVersion: vers.version,
8731 },
David Benjamina5022392017-07-10 17:40:39 -04008732 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008733 exportKeyingMaterial: 1024,
8734 useExportContext: true,
8735 })
8736 testCases = append(testCases, testCase{
8737 name: "ExportKeyingMaterial-Small-" + vers.name,
8738 config: Config{
8739 MaxVersion: vers.version,
8740 },
David Benjamina5022392017-07-10 17:40:39 -04008741 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008742 exportKeyingMaterial: 1,
8743 exportLabel: "label",
8744 exportContext: "context",
8745 useExportContext: true,
8746 })
8747 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008748
David Benjaminc565ebb2015-04-03 04:06:36 -04008749 testCases = append(testCases, testCase{
8750 name: "ExportKeyingMaterial-SSL3",
8751 config: Config{
8752 MaxVersion: VersionSSL30,
8753 },
8754 exportKeyingMaterial: 1024,
8755 exportLabel: "label",
8756 exportContext: "context",
8757 useExportContext: true,
8758 shouldFail: true,
8759 expectedError: "failed to export keying material",
8760 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008761
8762 // Exporters work during a False Start.
8763 testCases = append(testCases, testCase{
8764 name: "ExportKeyingMaterial-FalseStart",
8765 config: Config{
8766 MaxVersion: VersionTLS12,
8767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8768 NextProtos: []string{"foo"},
8769 Bugs: ProtocolBugs{
8770 ExpectFalseStart: true,
8771 },
8772 },
8773 flags: []string{
8774 "-false-start",
8775 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008776 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008777 },
8778 shimWritesFirst: true,
8779 exportKeyingMaterial: 1024,
8780 exportLabel: "label",
8781 exportContext: "context",
8782 useExportContext: true,
8783 })
8784
8785 // Exporters do not work in the middle of a renegotiation. Test this by
8786 // triggering the exporter after every SSL_read call and configuring the
8787 // shim to run asynchronously.
8788 testCases = append(testCases, testCase{
8789 name: "ExportKeyingMaterial-Renegotiate",
8790 config: Config{
8791 MaxVersion: VersionTLS12,
8792 },
8793 renegotiate: 1,
8794 flags: []string{
8795 "-async",
8796 "-use-exporter-between-reads",
8797 "-renegotiate-freely",
8798 "-expect-total-renegotiations", "1",
8799 },
8800 shouldFail: true,
8801 expectedError: "failed to export keying material",
8802 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008803}
8804
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008805func addTLSUniqueTests() {
8806 for _, isClient := range []bool{false, true} {
8807 for _, isResumption := range []bool{false, true} {
8808 for _, hasEMS := range []bool{false, true} {
8809 var suffix string
8810 if isResumption {
8811 suffix = "Resume-"
8812 } else {
8813 suffix = "Full-"
8814 }
8815
8816 if hasEMS {
8817 suffix += "EMS-"
8818 } else {
8819 suffix += "NoEMS-"
8820 }
8821
8822 if isClient {
8823 suffix += "Client"
8824 } else {
8825 suffix += "Server"
8826 }
8827
8828 test := testCase{
8829 name: "TLSUnique-" + suffix,
8830 testTLSUnique: true,
8831 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008832 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008833 Bugs: ProtocolBugs{
8834 NoExtendedMasterSecret: !hasEMS,
8835 },
8836 },
8837 }
8838
8839 if isResumption {
8840 test.resumeSession = true
8841 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008842 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008843 Bugs: ProtocolBugs{
8844 NoExtendedMasterSecret: !hasEMS,
8845 },
8846 }
8847 }
8848
8849 if isResumption && !hasEMS {
8850 test.shouldFail = true
8851 test.expectedError = "failed to get tls-unique"
8852 }
8853
8854 testCases = append(testCases, test)
8855 }
8856 }
8857 }
8858}
8859
Adam Langley09505632015-07-30 18:10:13 -07008860func addCustomExtensionTests() {
8861 expectedContents := "custom extension"
8862 emptyString := ""
8863
8864 for _, isClient := range []bool{false, true} {
8865 suffix := "Server"
8866 flag := "-enable-server-custom-extension"
8867 testType := serverTest
8868 if isClient {
8869 suffix = "Client"
8870 flag = "-enable-client-custom-extension"
8871 testType = clientTest
8872 }
8873
8874 testCases = append(testCases, testCase{
8875 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008876 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008877 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008878 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008879 Bugs: ProtocolBugs{
8880 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008881 ExpectedCustomExtension: &expectedContents,
8882 },
8883 },
8884 flags: []string{flag},
8885 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008886 testCases = append(testCases, testCase{
8887 testType: testType,
8888 name: "CustomExtensions-" + suffix + "-TLS13",
8889 config: Config{
8890 MaxVersion: VersionTLS13,
8891 Bugs: ProtocolBugs{
8892 CustomExtension: expectedContents,
8893 ExpectedCustomExtension: &expectedContents,
8894 },
8895 },
8896 flags: []string{flag},
8897 })
Adam Langley09505632015-07-30 18:10:13 -07008898
Steven Valdez2a070722017-03-25 20:54:16 -05008899 // 0-RTT is not currently supported with Custom Extensions.
8900 testCases = append(testCases, testCase{
8901 testType: testType,
8902 name: "CustomExtensions-" + suffix + "-EarlyData",
8903 config: Config{
8904 MaxVersion: VersionTLS13,
8905 Bugs: ProtocolBugs{
8906 CustomExtension: expectedContents,
8907 ExpectedCustomExtension: &expectedContents,
8908 },
8909 },
8910 shouldFail: true,
8911 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8912 flags: []string{flag, "-enable-early-data"},
8913 })
8914
Adam Langley09505632015-07-30 18:10:13 -07008915 // If the parse callback fails, the handshake should also fail.
8916 testCases = append(testCases, testCase{
8917 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008918 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008920 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008921 Bugs: ProtocolBugs{
8922 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008923 ExpectedCustomExtension: &expectedContents,
8924 },
8925 },
David Benjamin399e7c92015-07-30 23:01:27 -04008926 flags: []string{flag},
8927 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008928 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8929 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008930 testCases = append(testCases, testCase{
8931 testType: testType,
8932 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8933 config: Config{
8934 MaxVersion: VersionTLS13,
8935 Bugs: ProtocolBugs{
8936 CustomExtension: expectedContents + "foo",
8937 ExpectedCustomExtension: &expectedContents,
8938 },
8939 },
8940 flags: []string{flag},
8941 shouldFail: true,
8942 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8943 })
Adam Langley09505632015-07-30 18:10:13 -07008944
8945 // If the add callback fails, the handshake should also fail.
8946 testCases = append(testCases, testCase{
8947 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008948 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008950 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008951 Bugs: ProtocolBugs{
8952 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008953 ExpectedCustomExtension: &expectedContents,
8954 },
8955 },
David Benjamin399e7c92015-07-30 23:01:27 -04008956 flags: []string{flag, "-custom-extension-fail-add"},
8957 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008958 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8959 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008960 testCases = append(testCases, testCase{
8961 testType: testType,
8962 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8963 config: Config{
8964 MaxVersion: VersionTLS13,
8965 Bugs: ProtocolBugs{
8966 CustomExtension: expectedContents,
8967 ExpectedCustomExtension: &expectedContents,
8968 },
8969 },
8970 flags: []string{flag, "-custom-extension-fail-add"},
8971 shouldFail: true,
8972 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8973 })
Adam Langley09505632015-07-30 18:10:13 -07008974
8975 // If the add callback returns zero, no extension should be
8976 // added.
8977 skipCustomExtension := expectedContents
8978 if isClient {
8979 // For the case where the client skips sending the
8980 // custom extension, the server must not “echo” it.
8981 skipCustomExtension = ""
8982 }
8983 testCases = append(testCases, testCase{
8984 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008985 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008986 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008987 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008988 Bugs: ProtocolBugs{
8989 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008990 ExpectedCustomExtension: &emptyString,
8991 },
8992 },
8993 flags: []string{flag, "-custom-extension-skip"},
8994 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008995 testCases = append(testCases, testCase{
8996 testType: testType,
8997 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8998 config: Config{
8999 MaxVersion: VersionTLS13,
9000 Bugs: ProtocolBugs{
9001 CustomExtension: skipCustomExtension,
9002 ExpectedCustomExtension: &emptyString,
9003 },
9004 },
9005 flags: []string{flag, "-custom-extension-skip"},
9006 })
Adam Langley09505632015-07-30 18:10:13 -07009007 }
9008
9009 // The custom extension add callback should not be called if the client
9010 // doesn't send the extension.
9011 testCases = append(testCases, testCase{
9012 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009013 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009015 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009016 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009017 ExpectedCustomExtension: &emptyString,
9018 },
9019 },
9020 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9021 })
Adam Langley2deb9842015-08-07 11:15:37 -07009022
Steven Valdez143e8b32016-07-11 13:19:03 -04009023 testCases = append(testCases, testCase{
9024 testType: serverTest,
9025 name: "CustomExtensions-NotCalled-Server-TLS13",
9026 config: Config{
9027 MaxVersion: VersionTLS13,
9028 Bugs: ProtocolBugs{
9029 ExpectedCustomExtension: &emptyString,
9030 },
9031 },
9032 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9033 })
9034
Adam Langley2deb9842015-08-07 11:15:37 -07009035 // Test an unknown extension from the server.
9036 testCases = append(testCases, testCase{
9037 testType: clientTest,
9038 name: "UnknownExtension-Client",
9039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009040 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009041 Bugs: ProtocolBugs{
9042 CustomExtension: expectedContents,
9043 },
9044 },
David Benjamin0c40a962016-08-01 12:05:50 -04009045 shouldFail: true,
9046 expectedError: ":UNEXPECTED_EXTENSION:",
9047 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009048 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009049 testCases = append(testCases, testCase{
9050 testType: clientTest,
9051 name: "UnknownExtension-Client-TLS13",
9052 config: Config{
9053 MaxVersion: VersionTLS13,
9054 Bugs: ProtocolBugs{
9055 CustomExtension: expectedContents,
9056 },
9057 },
David Benjamin0c40a962016-08-01 12:05:50 -04009058 shouldFail: true,
9059 expectedError: ":UNEXPECTED_EXTENSION:",
9060 expectedLocalError: "remote error: unsupported extension",
9061 })
David Benjamin490469f2016-10-05 22:44:38 -04009062 testCases = append(testCases, testCase{
9063 testType: clientTest,
9064 name: "UnknownUnencryptedExtension-Client-TLS13",
9065 config: Config{
9066 MaxVersion: VersionTLS13,
9067 Bugs: ProtocolBugs{
9068 CustomUnencryptedExtension: expectedContents,
9069 },
9070 },
9071 shouldFail: true,
9072 expectedError: ":UNEXPECTED_EXTENSION:",
9073 // The shim must send an alert, but alerts at this point do not
9074 // get successfully decrypted by the runner.
9075 expectedLocalError: "local error: bad record MAC",
9076 })
9077 testCases = append(testCases, testCase{
9078 testType: clientTest,
9079 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9080 config: Config{
9081 MaxVersion: VersionTLS13,
9082 Bugs: ProtocolBugs{
9083 SendUnencryptedALPN: "foo",
9084 },
9085 },
9086 flags: []string{
9087 "-advertise-alpn", "\x03foo\x03bar",
9088 },
9089 shouldFail: true,
9090 expectedError: ":UNEXPECTED_EXTENSION:",
9091 // The shim must send an alert, but alerts at this point do not
9092 // get successfully decrypted by the runner.
9093 expectedLocalError: "local error: bad record MAC",
9094 })
David Benjamin0c40a962016-08-01 12:05:50 -04009095
9096 // Test a known but unoffered extension from the server.
9097 testCases = append(testCases, testCase{
9098 testType: clientTest,
9099 name: "UnofferedExtension-Client",
9100 config: Config{
9101 MaxVersion: VersionTLS12,
9102 Bugs: ProtocolBugs{
9103 SendALPN: "alpn",
9104 },
9105 },
9106 shouldFail: true,
9107 expectedError: ":UNEXPECTED_EXTENSION:",
9108 expectedLocalError: "remote error: unsupported extension",
9109 })
9110 testCases = append(testCases, testCase{
9111 testType: clientTest,
9112 name: "UnofferedExtension-Client-TLS13",
9113 config: Config{
9114 MaxVersion: VersionTLS13,
9115 Bugs: ProtocolBugs{
9116 SendALPN: "alpn",
9117 },
9118 },
9119 shouldFail: true,
9120 expectedError: ":UNEXPECTED_EXTENSION:",
9121 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009122 })
Adam Langley09505632015-07-30 18:10:13 -07009123}
9124
David Benjaminb36a3952015-12-01 18:53:13 -05009125func addRSAClientKeyExchangeTests() {
9126 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9127 testCases = append(testCases, testCase{
9128 testType: serverTest,
9129 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9130 config: Config{
9131 // Ensure the ClientHello version and final
9132 // version are different, to detect if the
9133 // server uses the wrong one.
9134 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009135 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009136 Bugs: ProtocolBugs{
9137 BadRSAClientKeyExchange: bad,
9138 },
9139 },
9140 shouldFail: true,
9141 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9142 })
9143 }
David Benjamine63d9d72016-09-19 18:27:34 -04009144
9145 // The server must compare whatever was in ClientHello.version for the
9146 // RSA premaster.
9147 testCases = append(testCases, testCase{
9148 testType: serverTest,
9149 name: "SendClientVersion-RSA",
9150 config: Config{
9151 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9152 Bugs: ProtocolBugs{
9153 SendClientVersion: 0x1234,
9154 },
9155 },
9156 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9157 })
David Benjaminb36a3952015-12-01 18:53:13 -05009158}
9159
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009160var testCurves = []struct {
9161 name string
9162 id CurveID
9163}{
Adam Langley764ab982017-03-10 18:01:30 -08009164 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009165 {"P-256", CurveP256},
9166 {"P-384", CurveP384},
9167 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009168 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009169}
9170
Steven Valdez5440fe02016-07-18 12:40:30 -04009171const bogusCurve = 0x1234
9172
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009173func addCurveTests() {
9174 for _, curve := range testCurves {
9175 testCases = append(testCases, testCase{
9176 name: "CurveTest-Client-" + curve.name,
9177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009178 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9180 CurvePreferences: []CurveID{curve.id},
9181 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009182 flags: []string{
9183 "-enable-all-curves",
9184 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9185 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009186 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009187 })
9188 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009189 name: "CurveTest-Client-" + curve.name + "-TLS13",
9190 config: Config{
9191 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009192 CurvePreferences: []CurveID{curve.id},
9193 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009194 flags: []string{
9195 "-enable-all-curves",
9196 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9197 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009198 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009199 })
9200 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009201 testType: serverTest,
9202 name: "CurveTest-Server-" + curve.name,
9203 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009204 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9206 CurvePreferences: []CurveID{curve.id},
9207 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009208 flags: []string{
9209 "-enable-all-curves",
9210 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9211 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009212 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009213 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009214 testCases = append(testCases, testCase{
9215 testType: serverTest,
9216 name: "CurveTest-Server-" + curve.name + "-TLS13",
9217 config: Config{
9218 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009219 CurvePreferences: []CurveID{curve.id},
9220 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009221 flags: []string{
9222 "-enable-all-curves",
9223 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9224 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009225 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009226 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009227 }
David Benjamin241ae832016-01-15 03:04:54 -05009228
9229 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009230 testCases = append(testCases, testCase{
9231 testType: serverTest,
9232 name: "UnknownCurve",
9233 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009234 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009235 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9236 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9237 },
9238 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009239
Steven Valdez803c77a2016-09-06 14:13:43 -04009240 // The server must be tolerant to bogus curves.
9241 testCases = append(testCases, testCase{
9242 testType: serverTest,
9243 name: "UnknownCurve-TLS13",
9244 config: Config{
9245 MaxVersion: VersionTLS13,
9246 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9247 },
9248 })
9249
David Benjamin4c3ddf72016-06-29 18:13:53 -04009250 // The server must not consider ECDHE ciphers when there are no
9251 // supported curves.
9252 testCases = append(testCases, testCase{
9253 testType: serverTest,
9254 name: "NoSupportedCurves",
9255 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009256 MaxVersion: VersionTLS12,
9257 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9258 Bugs: ProtocolBugs{
9259 NoSupportedCurves: true,
9260 },
9261 },
9262 shouldFail: true,
9263 expectedError: ":NO_SHARED_CIPHER:",
9264 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009265 testCases = append(testCases, testCase{
9266 testType: serverTest,
9267 name: "NoSupportedCurves-TLS13",
9268 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009269 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009270 Bugs: ProtocolBugs{
9271 NoSupportedCurves: true,
9272 },
9273 },
9274 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009275 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009276 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009277
9278 // The server must fall back to another cipher when there are no
9279 // supported curves.
9280 testCases = append(testCases, testCase{
9281 testType: serverTest,
9282 name: "NoCommonCurves",
9283 config: Config{
9284 MaxVersion: VersionTLS12,
9285 CipherSuites: []uint16{
9286 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009287 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009288 },
9289 CurvePreferences: []CurveID{CurveP224},
9290 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009291 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009292 })
9293
9294 // The client must reject bogus curves and disabled curves.
9295 testCases = append(testCases, testCase{
9296 name: "BadECDHECurve",
9297 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009298 MaxVersion: VersionTLS12,
9299 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9300 Bugs: ProtocolBugs{
9301 SendCurve: bogusCurve,
9302 },
9303 },
9304 shouldFail: true,
9305 expectedError: ":WRONG_CURVE:",
9306 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009307 testCases = append(testCases, testCase{
9308 name: "BadECDHECurve-TLS13",
9309 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009310 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009311 Bugs: ProtocolBugs{
9312 SendCurve: bogusCurve,
9313 },
9314 },
9315 shouldFail: true,
9316 expectedError: ":WRONG_CURVE:",
9317 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009318
9319 testCases = append(testCases, testCase{
9320 name: "UnsupportedCurve",
9321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009322 MaxVersion: VersionTLS12,
9323 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9324 CurvePreferences: []CurveID{CurveP256},
9325 Bugs: ProtocolBugs{
9326 IgnorePeerCurvePreferences: true,
9327 },
9328 },
9329 flags: []string{"-p384-only"},
9330 shouldFail: true,
9331 expectedError: ":WRONG_CURVE:",
9332 })
9333
David Benjamin4f921572016-07-17 14:20:10 +02009334 testCases = append(testCases, testCase{
9335 // TODO(davidben): Add a TLS 1.3 version where
9336 // HelloRetryRequest requests an unsupported curve.
9337 name: "UnsupportedCurve-ServerHello-TLS13",
9338 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009339 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009340 CurvePreferences: []CurveID{CurveP384},
9341 Bugs: ProtocolBugs{
9342 SendCurve: CurveP256,
9343 },
9344 },
9345 flags: []string{"-p384-only"},
9346 shouldFail: true,
9347 expectedError: ":WRONG_CURVE:",
9348 })
9349
David Benjamin4c3ddf72016-06-29 18:13:53 -04009350 // Test invalid curve points.
9351 testCases = append(testCases, testCase{
9352 name: "InvalidECDHPoint-Client",
9353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009354 MaxVersion: VersionTLS12,
9355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9356 CurvePreferences: []CurveID{CurveP256},
9357 Bugs: ProtocolBugs{
9358 InvalidECDHPoint: true,
9359 },
9360 },
9361 shouldFail: true,
9362 expectedError: ":INVALID_ENCODING:",
9363 })
9364 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009365 name: "InvalidECDHPoint-Client-TLS13",
9366 config: Config{
9367 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009368 CurvePreferences: []CurveID{CurveP256},
9369 Bugs: ProtocolBugs{
9370 InvalidECDHPoint: true,
9371 },
9372 },
9373 shouldFail: true,
9374 expectedError: ":INVALID_ENCODING:",
9375 })
9376 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009377 testType: serverTest,
9378 name: "InvalidECDHPoint-Server",
9379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009380 MaxVersion: VersionTLS12,
9381 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9382 CurvePreferences: []CurveID{CurveP256},
9383 Bugs: ProtocolBugs{
9384 InvalidECDHPoint: true,
9385 },
9386 },
9387 shouldFail: true,
9388 expectedError: ":INVALID_ENCODING:",
9389 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009390 testCases = append(testCases, testCase{
9391 testType: serverTest,
9392 name: "InvalidECDHPoint-Server-TLS13",
9393 config: Config{
9394 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009395 CurvePreferences: []CurveID{CurveP256},
9396 Bugs: ProtocolBugs{
9397 InvalidECDHPoint: true,
9398 },
9399 },
9400 shouldFail: true,
9401 expectedError: ":INVALID_ENCODING:",
9402 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009403
9404 // The previous curve ID should be reported on TLS 1.2 resumption.
9405 testCases = append(testCases, testCase{
9406 name: "CurveID-Resume-Client",
9407 config: Config{
9408 MaxVersion: VersionTLS12,
9409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9410 CurvePreferences: []CurveID{CurveX25519},
9411 },
9412 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9413 resumeSession: true,
9414 })
9415 testCases = append(testCases, testCase{
9416 testType: serverTest,
9417 name: "CurveID-Resume-Server",
9418 config: Config{
9419 MaxVersion: VersionTLS12,
9420 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9421 CurvePreferences: []CurveID{CurveX25519},
9422 },
9423 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9424 resumeSession: true,
9425 })
9426
9427 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9428 // one should be reported.
9429 testCases = append(testCases, testCase{
9430 name: "CurveID-Resume-Client-TLS13",
9431 config: Config{
9432 MaxVersion: VersionTLS13,
9433 CurvePreferences: []CurveID{CurveX25519},
9434 },
9435 resumeConfig: &Config{
9436 MaxVersion: VersionTLS13,
9437 CurvePreferences: []CurveID{CurveP256},
9438 },
9439 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009440 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9441 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009442 },
9443 resumeSession: true,
9444 })
9445 testCases = append(testCases, testCase{
9446 testType: serverTest,
9447 name: "CurveID-Resume-Server-TLS13",
9448 config: Config{
9449 MaxVersion: VersionTLS13,
9450 CurvePreferences: []CurveID{CurveX25519},
9451 },
9452 resumeConfig: &Config{
9453 MaxVersion: VersionTLS13,
9454 CurvePreferences: []CurveID{CurveP256},
9455 },
9456 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009457 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9458 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009459 },
9460 resumeSession: true,
9461 })
David Benjamina81967b2016-12-22 09:16:57 -05009462
9463 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9464 testCases = append(testCases, testCase{
9465 name: "PointFormat-ServerHello-TLS12",
9466 config: Config{
9467 MaxVersion: VersionTLS12,
9468 Bugs: ProtocolBugs{
9469 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9470 },
9471 },
9472 })
9473 testCases = append(testCases, testCase{
9474 name: "PointFormat-EncryptedExtensions-TLS13",
9475 config: Config{
9476 MaxVersion: VersionTLS13,
9477 Bugs: ProtocolBugs{
9478 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9479 },
9480 },
9481 shouldFail: true,
9482 expectedError: ":ERROR_PARSING_EXTENSION:",
9483 })
9484
9485 // Test that we tolerate unknown point formats, as long as
9486 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9487 // check they are still functional.
9488 testCases = append(testCases, testCase{
9489 name: "PointFormat-Client-Tolerance",
9490 config: Config{
9491 MaxVersion: VersionTLS12,
9492 Bugs: ProtocolBugs{
9493 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9494 },
9495 },
9496 })
9497 testCases = append(testCases, testCase{
9498 testType: serverTest,
9499 name: "PointFormat-Server-Tolerance",
9500 config: Config{
9501 MaxVersion: VersionTLS12,
9502 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9503 Bugs: ProtocolBugs{
9504 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9505 },
9506 },
9507 })
9508
9509 // Test TLS 1.2 does not require the point format extension to be
9510 // present.
9511 testCases = append(testCases, testCase{
9512 name: "PointFormat-Client-Missing",
9513 config: Config{
9514 MaxVersion: VersionTLS12,
9515 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9516 Bugs: ProtocolBugs{
9517 SendSupportedPointFormats: []byte{},
9518 },
9519 },
9520 })
9521 testCases = append(testCases, testCase{
9522 testType: serverTest,
9523 name: "PointFormat-Server-Missing",
9524 config: Config{
9525 MaxVersion: VersionTLS12,
9526 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9527 Bugs: ProtocolBugs{
9528 SendSupportedPointFormats: []byte{},
9529 },
9530 },
9531 })
9532
9533 // If the point format extension is present, uncompressed points must be
9534 // offered. BoringSSL requires this whether or not ECDHE is used.
9535 testCases = append(testCases, testCase{
9536 name: "PointFormat-Client-MissingUncompressed",
9537 config: Config{
9538 MaxVersion: VersionTLS12,
9539 Bugs: ProtocolBugs{
9540 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9541 },
9542 },
9543 shouldFail: true,
9544 expectedError: ":ERROR_PARSING_EXTENSION:",
9545 })
9546 testCases = append(testCases, testCase{
9547 testType: serverTest,
9548 name: "PointFormat-Server-MissingUncompressed",
9549 config: Config{
9550 MaxVersion: VersionTLS12,
9551 Bugs: ProtocolBugs{
9552 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9553 },
9554 },
9555 shouldFail: true,
9556 expectedError: ":ERROR_PARSING_EXTENSION:",
9557 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009558}
9559
David Benjaminc9ae27c2016-06-24 22:56:37 -04009560func addTLS13RecordTests() {
9561 testCases = append(testCases, testCase{
9562 name: "TLS13-RecordPadding",
9563 config: Config{
9564 MaxVersion: VersionTLS13,
9565 MinVersion: VersionTLS13,
9566 Bugs: ProtocolBugs{
9567 RecordPadding: 10,
9568 },
9569 },
9570 })
9571
9572 testCases = append(testCases, testCase{
9573 name: "TLS13-EmptyRecords",
9574 config: Config{
9575 MaxVersion: VersionTLS13,
9576 MinVersion: VersionTLS13,
9577 Bugs: ProtocolBugs{
9578 OmitRecordContents: true,
9579 },
9580 },
9581 shouldFail: true,
9582 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9583 })
9584
9585 testCases = append(testCases, testCase{
9586 name: "TLS13-OnlyPadding",
9587 config: Config{
9588 MaxVersion: VersionTLS13,
9589 MinVersion: VersionTLS13,
9590 Bugs: ProtocolBugs{
9591 OmitRecordContents: true,
9592 RecordPadding: 10,
9593 },
9594 },
9595 shouldFail: true,
9596 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9597 })
9598
9599 testCases = append(testCases, testCase{
9600 name: "TLS13-WrongOuterRecord",
9601 config: Config{
9602 MaxVersion: VersionTLS13,
9603 MinVersion: VersionTLS13,
9604 Bugs: ProtocolBugs{
9605 OuterRecordType: recordTypeHandshake,
9606 },
9607 },
9608 shouldFail: true,
9609 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9610 })
9611}
9612
Steven Valdez5b986082016-09-01 12:29:49 -04009613func addSessionTicketTests() {
9614 testCases = append(testCases, testCase{
9615 // In TLS 1.2 and below, empty NewSessionTicket messages
9616 // mean the server changed its mind on sending a ticket.
9617 name: "SendEmptySessionTicket",
9618 config: Config{
9619 MaxVersion: VersionTLS12,
9620 Bugs: ProtocolBugs{
9621 SendEmptySessionTicket: true,
9622 },
9623 },
9624 flags: []string{"-expect-no-session"},
9625 })
9626
9627 // Test that the server ignores unknown PSK modes.
9628 testCases = append(testCases, testCase{
9629 testType: serverTest,
9630 name: "TLS13-SendUnknownModeSessionTicket-Server",
9631 config: Config{
9632 MaxVersion: VersionTLS13,
9633 Bugs: ProtocolBugs{
9634 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009635 },
9636 },
9637 resumeSession: true,
9638 expectedResumeVersion: VersionTLS13,
9639 })
9640
Steven Valdeza833c352016-11-01 13:39:36 -04009641 // Test that the server does not send session tickets with no matching key exchange mode.
9642 testCases = append(testCases, testCase{
9643 testType: serverTest,
9644 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9645 config: Config{
9646 MaxVersion: VersionTLS13,
9647 Bugs: ProtocolBugs{
9648 SendPSKKeyExchangeModes: []byte{0x1a},
9649 ExpectNoNewSessionTicket: true,
9650 },
9651 },
9652 })
9653
9654 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009655 testCases = append(testCases, testCase{
9656 testType: serverTest,
9657 name: "TLS13-SendBadKEModeSessionTicket-Server",
9658 config: Config{
9659 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009660 },
9661 resumeConfig: &Config{
9662 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009663 Bugs: ProtocolBugs{
9664 SendPSKKeyExchangeModes: []byte{0x1a},
9665 },
9666 },
9667 resumeSession: true,
9668 expectResumeRejected: true,
9669 })
9670
Steven Valdeza833c352016-11-01 13:39:36 -04009671 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009672 testCases = append(testCases, testCase{
9673 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009674 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009675 config: Config{
9676 MaxVersion: VersionTLS13,
9677 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009678 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009679 },
9680 },
Steven Valdeza833c352016-11-01 13:39:36 -04009681 resumeSession: true,
9682 flags: []string{
9683 "-resumption-delay", "10",
9684 },
Steven Valdez5b986082016-09-01 12:29:49 -04009685 })
9686
Steven Valdeza833c352016-11-01 13:39:36 -04009687 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009688 testCases = append(testCases, testCase{
9689 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009690 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009691 config: Config{
9692 MaxVersion: VersionTLS13,
9693 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009694 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009695 },
9696 },
Steven Valdeza833c352016-11-01 13:39:36 -04009697 resumeSession: true,
9698 shouldFail: true,
9699 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009700 })
9701
David Benjamin35ac5b72017-03-03 15:05:56 -05009702 // Test that the server's ticket age skew reporting works.
9703 testCases = append(testCases, testCase{
9704 testType: serverTest,
9705 name: "TLS13-TicketAgeSkew-Forward",
9706 config: Config{
9707 MaxVersion: VersionTLS13,
9708 Bugs: ProtocolBugs{
9709 SendTicketAge: 15 * time.Second,
9710 },
9711 },
David Benjamin065d7332017-03-26 10:51:43 -05009712 resumeSession: true,
9713 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009714 flags: []string{
9715 "-resumption-delay", "10",
9716 "-expect-ticket-age-skew", "5",
9717 },
9718 })
9719 testCases = append(testCases, testCase{
9720 testType: serverTest,
9721 name: "TLS13-TicketAgeSkew-Backward",
9722 config: Config{
9723 MaxVersion: VersionTLS13,
9724 Bugs: ProtocolBugs{
9725 SendTicketAge: 5 * time.Second,
9726 },
9727 },
David Benjamin065d7332017-03-26 10:51:43 -05009728 resumeSession: true,
9729 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009730 flags: []string{
9731 "-resumption-delay", "10",
9732 "-expect-ticket-age-skew", "-5",
9733 },
9734 })
9735
Steven Valdez08b65f42016-12-07 15:29:45 -05009736 testCases = append(testCases, testCase{
9737 testType: clientTest,
9738 name: "TLS13-SendTicketEarlyDataInfo",
9739 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009740 MaxVersion: VersionTLS13,
9741 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009742 },
9743 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009744 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009745 "-expect-early-data-info",
9746 },
9747 })
9748
David Benjamin9b160662017-01-25 19:53:43 -05009749 // Test that 0-RTT tickets are ignored in clients unless opted in.
9750 testCases = append(testCases, testCase{
9751 testType: clientTest,
9752 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9753 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009754 MaxVersion: VersionTLS13,
9755 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009756 },
9757 })
9758
Steven Valdez08b65f42016-12-07 15:29:45 -05009759 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009760 testType: clientTest,
9761 name: "TLS13-DuplicateTicketEarlyDataInfo",
9762 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009763 MaxVersion: VersionTLS13,
9764 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009765 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009766 DuplicateTicketEarlyDataInfo: true,
9767 },
9768 },
9769 shouldFail: true,
9770 expectedError: ":DUPLICATE_EXTENSION:",
9771 expectedLocalError: "remote error: illegal parameter",
9772 })
9773
9774 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009775 testType: serverTest,
9776 name: "TLS13-ExpectTicketEarlyDataInfo",
9777 config: Config{
9778 MaxVersion: VersionTLS13,
9779 Bugs: ProtocolBugs{
9780 ExpectTicketEarlyDataInfo: true,
9781 },
9782 },
9783 flags: []string{
9784 "-enable-early-data",
9785 },
9786 })
David Benjamin17b30832017-01-28 14:00:32 -05009787
9788 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9789 // is honored.
9790 testCases = append(testCases, testCase{
9791 testType: clientTest,
9792 name: "TLS13-HonorServerSessionTicketLifetime",
9793 config: Config{
9794 MaxVersion: VersionTLS13,
9795 Bugs: ProtocolBugs{
9796 SendTicketLifetime: 20 * time.Second,
9797 },
9798 },
9799 flags: []string{
9800 "-resumption-delay", "19",
9801 },
9802 resumeSession: true,
9803 })
9804 testCases = append(testCases, testCase{
9805 testType: clientTest,
9806 name: "TLS13-HonorServerSessionTicketLifetime-2",
9807 config: Config{
9808 MaxVersion: VersionTLS13,
9809 Bugs: ProtocolBugs{
9810 SendTicketLifetime: 20 * time.Second,
9811 // The client should not offer the expired session.
9812 ExpectNoTLS13PSK: true,
9813 },
9814 },
9815 flags: []string{
9816 "-resumption-delay", "21",
9817 },
David Benjamin023d4192017-02-06 13:49:07 -05009818 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009819 expectResumeRejected: true,
9820 })
Steven Valdez5b986082016-09-01 12:29:49 -04009821}
9822
David Benjamin82261be2016-07-07 14:32:50 -07009823func addChangeCipherSpecTests() {
9824 // Test missing ChangeCipherSpecs.
9825 testCases = append(testCases, testCase{
9826 name: "SkipChangeCipherSpec-Client",
9827 config: Config{
9828 MaxVersion: VersionTLS12,
9829 Bugs: ProtocolBugs{
9830 SkipChangeCipherSpec: true,
9831 },
9832 },
9833 shouldFail: true,
9834 expectedError: ":UNEXPECTED_RECORD:",
9835 })
9836 testCases = append(testCases, testCase{
9837 testType: serverTest,
9838 name: "SkipChangeCipherSpec-Server",
9839 config: Config{
9840 MaxVersion: VersionTLS12,
9841 Bugs: ProtocolBugs{
9842 SkipChangeCipherSpec: true,
9843 },
9844 },
9845 shouldFail: true,
9846 expectedError: ":UNEXPECTED_RECORD:",
9847 })
9848 testCases = append(testCases, testCase{
9849 testType: serverTest,
9850 name: "SkipChangeCipherSpec-Server-NPN",
9851 config: Config{
9852 MaxVersion: VersionTLS12,
9853 NextProtos: []string{"bar"},
9854 Bugs: ProtocolBugs{
9855 SkipChangeCipherSpec: true,
9856 },
9857 },
9858 flags: []string{
9859 "-advertise-npn", "\x03foo\x03bar\x03baz",
9860 },
9861 shouldFail: true,
9862 expectedError: ":UNEXPECTED_RECORD:",
9863 })
9864
9865 // Test synchronization between the handshake and ChangeCipherSpec.
9866 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9867 // rejected. Test both with and without handshake packing to handle both
9868 // when the partial post-CCS message is in its own record and when it is
9869 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009870 for _, packed := range []bool{false, true} {
9871 var suffix string
9872 if packed {
9873 suffix = "-Packed"
9874 }
9875
9876 testCases = append(testCases, testCase{
9877 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9878 config: Config{
9879 MaxVersion: VersionTLS12,
9880 Bugs: ProtocolBugs{
9881 FragmentAcrossChangeCipherSpec: true,
9882 PackHandshakeFlight: packed,
9883 },
9884 },
9885 shouldFail: true,
9886 expectedError: ":UNEXPECTED_RECORD:",
9887 })
9888 testCases = append(testCases, testCase{
9889 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9890 config: Config{
9891 MaxVersion: VersionTLS12,
9892 },
9893 resumeSession: true,
9894 resumeConfig: &Config{
9895 MaxVersion: VersionTLS12,
9896 Bugs: ProtocolBugs{
9897 FragmentAcrossChangeCipherSpec: true,
9898 PackHandshakeFlight: packed,
9899 },
9900 },
9901 shouldFail: true,
9902 expectedError: ":UNEXPECTED_RECORD:",
9903 })
9904 testCases = append(testCases, testCase{
9905 testType: serverTest,
9906 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9907 config: Config{
9908 MaxVersion: VersionTLS12,
9909 Bugs: ProtocolBugs{
9910 FragmentAcrossChangeCipherSpec: true,
9911 PackHandshakeFlight: packed,
9912 },
9913 },
9914 shouldFail: true,
9915 expectedError: ":UNEXPECTED_RECORD:",
9916 })
9917 testCases = append(testCases, testCase{
9918 testType: serverTest,
9919 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9920 config: Config{
9921 MaxVersion: VersionTLS12,
9922 },
9923 resumeSession: true,
9924 resumeConfig: &Config{
9925 MaxVersion: VersionTLS12,
9926 Bugs: ProtocolBugs{
9927 FragmentAcrossChangeCipherSpec: true,
9928 PackHandshakeFlight: packed,
9929 },
9930 },
9931 shouldFail: true,
9932 expectedError: ":UNEXPECTED_RECORD:",
9933 })
9934 testCases = append(testCases, testCase{
9935 testType: serverTest,
9936 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9937 config: Config{
9938 MaxVersion: VersionTLS12,
9939 NextProtos: []string{"bar"},
9940 Bugs: ProtocolBugs{
9941 FragmentAcrossChangeCipherSpec: true,
9942 PackHandshakeFlight: packed,
9943 },
9944 },
9945 flags: []string{
9946 "-advertise-npn", "\x03foo\x03bar\x03baz",
9947 },
9948 shouldFail: true,
9949 expectedError: ":UNEXPECTED_RECORD:",
9950 })
9951 }
9952
David Benjamin61672812016-07-14 23:10:43 -04009953 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9954 // messages in the handshake queue. Do this by testing the server
9955 // reading the client Finished, reversing the flight so Finished comes
9956 // first.
9957 testCases = append(testCases, testCase{
9958 protocol: dtls,
9959 testType: serverTest,
9960 name: "SendUnencryptedFinished-DTLS",
9961 config: Config{
9962 MaxVersion: VersionTLS12,
9963 Bugs: ProtocolBugs{
9964 SendUnencryptedFinished: true,
9965 ReverseHandshakeFragments: true,
9966 },
9967 },
9968 shouldFail: true,
9969 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9970 })
9971
Steven Valdez143e8b32016-07-11 13:19:03 -04009972 // Test synchronization between encryption changes and the handshake in
9973 // TLS 1.3, where ChangeCipherSpec is implicit.
9974 testCases = append(testCases, testCase{
9975 name: "PartialEncryptedExtensionsWithServerHello",
9976 config: Config{
9977 MaxVersion: VersionTLS13,
9978 Bugs: ProtocolBugs{
9979 PartialEncryptedExtensionsWithServerHello: true,
9980 },
9981 },
9982 shouldFail: true,
9983 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9984 })
9985 testCases = append(testCases, testCase{
9986 testType: serverTest,
9987 name: "PartialClientFinishedWithClientHello",
9988 config: Config{
9989 MaxVersion: VersionTLS13,
9990 Bugs: ProtocolBugs{
9991 PartialClientFinishedWithClientHello: true,
9992 },
9993 },
9994 shouldFail: true,
9995 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9996 })
9997
David Benjamin82261be2016-07-07 14:32:50 -07009998 // Test that early ChangeCipherSpecs are handled correctly.
9999 testCases = append(testCases, testCase{
10000 testType: serverTest,
10001 name: "EarlyChangeCipherSpec-server-1",
10002 config: Config{
10003 MaxVersion: VersionTLS12,
10004 Bugs: ProtocolBugs{
10005 EarlyChangeCipherSpec: 1,
10006 },
10007 },
10008 shouldFail: true,
10009 expectedError: ":UNEXPECTED_RECORD:",
10010 })
10011 testCases = append(testCases, testCase{
10012 testType: serverTest,
10013 name: "EarlyChangeCipherSpec-server-2",
10014 config: Config{
10015 MaxVersion: VersionTLS12,
10016 Bugs: ProtocolBugs{
10017 EarlyChangeCipherSpec: 2,
10018 },
10019 },
10020 shouldFail: true,
10021 expectedError: ":UNEXPECTED_RECORD:",
10022 })
10023 testCases = append(testCases, testCase{
10024 protocol: dtls,
10025 name: "StrayChangeCipherSpec",
10026 config: Config{
10027 // TODO(davidben): Once DTLS 1.3 exists, test
10028 // that stray ChangeCipherSpec messages are
10029 // rejected.
10030 MaxVersion: VersionTLS12,
10031 Bugs: ProtocolBugs{
10032 StrayChangeCipherSpec: true,
10033 },
10034 },
10035 })
10036
10037 // Test that the contents of ChangeCipherSpec are checked.
10038 testCases = append(testCases, testCase{
10039 name: "BadChangeCipherSpec-1",
10040 config: Config{
10041 MaxVersion: VersionTLS12,
10042 Bugs: ProtocolBugs{
10043 BadChangeCipherSpec: []byte{2},
10044 },
10045 },
10046 shouldFail: true,
10047 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10048 })
10049 testCases = append(testCases, testCase{
10050 name: "BadChangeCipherSpec-2",
10051 config: Config{
10052 MaxVersion: VersionTLS12,
10053 Bugs: ProtocolBugs{
10054 BadChangeCipherSpec: []byte{1, 1},
10055 },
10056 },
10057 shouldFail: true,
10058 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10059 })
10060 testCases = append(testCases, testCase{
10061 protocol: dtls,
10062 name: "BadChangeCipherSpec-DTLS-1",
10063 config: Config{
10064 MaxVersion: VersionTLS12,
10065 Bugs: ProtocolBugs{
10066 BadChangeCipherSpec: []byte{2},
10067 },
10068 },
10069 shouldFail: true,
10070 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10071 })
10072 testCases = append(testCases, testCase{
10073 protocol: dtls,
10074 name: "BadChangeCipherSpec-DTLS-2",
10075 config: Config{
10076 MaxVersion: VersionTLS12,
10077 Bugs: ProtocolBugs{
10078 BadChangeCipherSpec: []byte{1, 1},
10079 },
10080 },
10081 shouldFail: true,
10082 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10083 })
10084}
10085
David Benjamincd2c8062016-09-09 11:28:16 -040010086type perMessageTest struct {
10087 messageType uint8
10088 test testCase
10089}
10090
10091// makePerMessageTests returns a series of test templates which cover each
10092// message in the TLS handshake. These may be used with bugs like
10093// WrongMessageType to fully test a per-message bug.
10094func makePerMessageTests() []perMessageTest {
10095 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010096 for _, protocol := range []protocol{tls, dtls} {
10097 var suffix string
10098 if protocol == dtls {
10099 suffix = "-DTLS"
10100 }
10101
David Benjamincd2c8062016-09-09 11:28:16 -040010102 ret = append(ret, perMessageTest{
10103 messageType: typeClientHello,
10104 test: testCase{
10105 protocol: protocol,
10106 testType: serverTest,
10107 name: "ClientHello" + suffix,
10108 config: Config{
10109 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010110 },
10111 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010112 })
10113
10114 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010115 ret = append(ret, perMessageTest{
10116 messageType: typeHelloVerifyRequest,
10117 test: testCase{
10118 protocol: protocol,
10119 name: "HelloVerifyRequest" + suffix,
10120 config: Config{
10121 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010122 },
10123 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010124 })
10125 }
10126
David Benjamincd2c8062016-09-09 11:28:16 -040010127 ret = append(ret, perMessageTest{
10128 messageType: typeServerHello,
10129 test: testCase{
10130 protocol: protocol,
10131 name: "ServerHello" + suffix,
10132 config: Config{
10133 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010134 },
10135 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010136 })
10137
David Benjamincd2c8062016-09-09 11:28:16 -040010138 ret = append(ret, perMessageTest{
10139 messageType: typeCertificate,
10140 test: testCase{
10141 protocol: protocol,
10142 name: "ServerCertificate" + suffix,
10143 config: Config{
10144 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010145 },
10146 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010147 })
10148
David Benjamincd2c8062016-09-09 11:28:16 -040010149 ret = append(ret, perMessageTest{
10150 messageType: typeCertificateStatus,
10151 test: testCase{
10152 protocol: protocol,
10153 name: "CertificateStatus" + suffix,
10154 config: Config{
10155 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010156 },
David Benjamincd2c8062016-09-09 11:28:16 -040010157 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010158 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010159 })
10160
David Benjamincd2c8062016-09-09 11:28:16 -040010161 ret = append(ret, perMessageTest{
10162 messageType: typeServerKeyExchange,
10163 test: testCase{
10164 protocol: protocol,
10165 name: "ServerKeyExchange" + suffix,
10166 config: Config{
10167 MaxVersion: VersionTLS12,
10168 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010169 },
10170 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010171 })
10172
David Benjamincd2c8062016-09-09 11:28:16 -040010173 ret = append(ret, perMessageTest{
10174 messageType: typeCertificateRequest,
10175 test: testCase{
10176 protocol: protocol,
10177 name: "CertificateRequest" + suffix,
10178 config: Config{
10179 MaxVersion: VersionTLS12,
10180 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010181 },
10182 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010183 })
10184
David Benjamincd2c8062016-09-09 11:28:16 -040010185 ret = append(ret, perMessageTest{
10186 messageType: typeServerHelloDone,
10187 test: testCase{
10188 protocol: protocol,
10189 name: "ServerHelloDone" + suffix,
10190 config: Config{
10191 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010192 },
10193 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010194 })
10195
David Benjamincd2c8062016-09-09 11:28:16 -040010196 ret = append(ret, perMessageTest{
10197 messageType: typeCertificate,
10198 test: testCase{
10199 testType: serverTest,
10200 protocol: protocol,
10201 name: "ClientCertificate" + suffix,
10202 config: Config{
10203 Certificates: []Certificate{rsaCertificate},
10204 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010205 },
David Benjamincd2c8062016-09-09 11:28:16 -040010206 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010207 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010208 })
10209
David Benjamincd2c8062016-09-09 11:28:16 -040010210 ret = append(ret, perMessageTest{
10211 messageType: typeCertificateVerify,
10212 test: testCase{
10213 testType: serverTest,
10214 protocol: protocol,
10215 name: "CertificateVerify" + suffix,
10216 config: Config{
10217 Certificates: []Certificate{rsaCertificate},
10218 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010219 },
David Benjamincd2c8062016-09-09 11:28:16 -040010220 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010221 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010222 })
10223
David Benjamincd2c8062016-09-09 11:28:16 -040010224 ret = append(ret, perMessageTest{
10225 messageType: typeClientKeyExchange,
10226 test: testCase{
10227 testType: serverTest,
10228 protocol: protocol,
10229 name: "ClientKeyExchange" + suffix,
10230 config: Config{
10231 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010232 },
10233 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010234 })
10235
10236 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010237 ret = append(ret, perMessageTest{
10238 messageType: typeNextProtocol,
10239 test: testCase{
10240 testType: serverTest,
10241 protocol: protocol,
10242 name: "NextProtocol" + suffix,
10243 config: Config{
10244 MaxVersion: VersionTLS12,
10245 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010246 },
David Benjamincd2c8062016-09-09 11:28:16 -040010247 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010248 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010249 })
10250
David Benjamincd2c8062016-09-09 11:28:16 -040010251 ret = append(ret, perMessageTest{
10252 messageType: typeChannelID,
10253 test: testCase{
10254 testType: serverTest,
10255 protocol: protocol,
10256 name: "ChannelID" + suffix,
10257 config: Config{
10258 MaxVersion: VersionTLS12,
10259 ChannelID: channelIDKey,
10260 },
10261 flags: []string{
10262 "-expect-channel-id",
10263 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010264 },
10265 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010266 })
10267 }
10268
David Benjamincd2c8062016-09-09 11:28:16 -040010269 ret = append(ret, perMessageTest{
10270 messageType: typeFinished,
10271 test: testCase{
10272 testType: serverTest,
10273 protocol: protocol,
10274 name: "ClientFinished" + suffix,
10275 config: Config{
10276 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010277 },
10278 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010279 })
10280
David Benjamincd2c8062016-09-09 11:28:16 -040010281 ret = append(ret, perMessageTest{
10282 messageType: typeNewSessionTicket,
10283 test: testCase{
10284 protocol: protocol,
10285 name: "NewSessionTicket" + suffix,
10286 config: Config{
10287 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010288 },
10289 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010290 })
10291
David Benjamincd2c8062016-09-09 11:28:16 -040010292 ret = append(ret, perMessageTest{
10293 messageType: typeFinished,
10294 test: testCase{
10295 protocol: protocol,
10296 name: "ServerFinished" + suffix,
10297 config: Config{
10298 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010299 },
10300 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010301 })
10302
10303 }
David Benjamincd2c8062016-09-09 11:28:16 -040010304
10305 ret = append(ret, perMessageTest{
10306 messageType: typeClientHello,
10307 test: testCase{
10308 testType: serverTest,
10309 name: "TLS13-ClientHello",
10310 config: Config{
10311 MaxVersion: VersionTLS13,
10312 },
10313 },
10314 })
10315
10316 ret = append(ret, perMessageTest{
10317 messageType: typeServerHello,
10318 test: testCase{
10319 name: "TLS13-ServerHello",
10320 config: Config{
10321 MaxVersion: VersionTLS13,
10322 },
10323 },
10324 })
10325
10326 ret = append(ret, perMessageTest{
10327 messageType: typeEncryptedExtensions,
10328 test: testCase{
10329 name: "TLS13-EncryptedExtensions",
10330 config: Config{
10331 MaxVersion: VersionTLS13,
10332 },
10333 },
10334 })
10335
10336 ret = append(ret, perMessageTest{
10337 messageType: typeCertificateRequest,
10338 test: testCase{
10339 name: "TLS13-CertificateRequest",
10340 config: Config{
10341 MaxVersion: VersionTLS13,
10342 ClientAuth: RequireAnyClientCert,
10343 },
10344 },
10345 })
10346
10347 ret = append(ret, perMessageTest{
10348 messageType: typeCertificate,
10349 test: testCase{
10350 name: "TLS13-ServerCertificate",
10351 config: Config{
10352 MaxVersion: VersionTLS13,
10353 },
10354 },
10355 })
10356
10357 ret = append(ret, perMessageTest{
10358 messageType: typeCertificateVerify,
10359 test: testCase{
10360 name: "TLS13-ServerCertificateVerify",
10361 config: Config{
10362 MaxVersion: VersionTLS13,
10363 },
10364 },
10365 })
10366
10367 ret = append(ret, perMessageTest{
10368 messageType: typeFinished,
10369 test: testCase{
10370 name: "TLS13-ServerFinished",
10371 config: Config{
10372 MaxVersion: VersionTLS13,
10373 },
10374 },
10375 })
10376
10377 ret = append(ret, perMessageTest{
10378 messageType: typeCertificate,
10379 test: testCase{
10380 testType: serverTest,
10381 name: "TLS13-ClientCertificate",
10382 config: Config{
10383 Certificates: []Certificate{rsaCertificate},
10384 MaxVersion: VersionTLS13,
10385 },
10386 flags: []string{"-require-any-client-certificate"},
10387 },
10388 })
10389
10390 ret = append(ret, perMessageTest{
10391 messageType: typeCertificateVerify,
10392 test: testCase{
10393 testType: serverTest,
10394 name: "TLS13-ClientCertificateVerify",
10395 config: Config{
10396 Certificates: []Certificate{rsaCertificate},
10397 MaxVersion: VersionTLS13,
10398 },
10399 flags: []string{"-require-any-client-certificate"},
10400 },
10401 })
10402
10403 ret = append(ret, perMessageTest{
10404 messageType: typeFinished,
10405 test: testCase{
10406 testType: serverTest,
10407 name: "TLS13-ClientFinished",
10408 config: Config{
10409 MaxVersion: VersionTLS13,
10410 },
10411 },
10412 })
10413
10414 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010415}
10416
David Benjamincd2c8062016-09-09 11:28:16 -040010417func addWrongMessageTypeTests() {
10418 for _, t := range makePerMessageTests() {
10419 t.test.name = "WrongMessageType-" + t.test.name
10420 t.test.config.Bugs.SendWrongMessageType = t.messageType
10421 t.test.shouldFail = true
10422 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10423 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010424
David Benjamincd2c8062016-09-09 11:28:16 -040010425 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10426 // In TLS 1.3, a bad ServerHello means the client sends
10427 // an unencrypted alert while the server expects
10428 // encryption, so the alert is not readable by runner.
10429 t.test.expectedLocalError = "local error: bad record MAC"
10430 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010431
David Benjamincd2c8062016-09-09 11:28:16 -040010432 testCases = append(testCases, t.test)
10433 }
David Benjaminebacdee2017-04-08 11:00:45 -040010434
10435 // The processing order for TLS 1.3 version negotiation is such that one
10436 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10437 // TLS 1.2. Test that we do not do this.
10438 testCases = append(testCases, testCase{
10439 name: "SendServerHelloAsHelloRetryRequest",
10440 config: Config{
10441 MaxVersion: VersionTLS12,
10442 Bugs: ProtocolBugs{
10443 SendServerHelloAsHelloRetryRequest: true,
10444 },
10445 },
10446 shouldFail: true,
10447 expectedError: ":UNEXPECTED_MESSAGE:",
10448 expectedLocalError: "remote error: unexpected message",
10449 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010450}
10451
David Benjamin639846e2016-09-09 11:41:18 -040010452func addTrailingMessageDataTests() {
10453 for _, t := range makePerMessageTests() {
10454 t.test.name = "TrailingMessageData-" + t.test.name
10455 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10456 t.test.shouldFail = true
10457 t.test.expectedError = ":DECODE_ERROR:"
10458 t.test.expectedLocalError = "remote error: error decoding message"
10459
10460 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10461 // In TLS 1.3, a bad ServerHello means the client sends
10462 // an unencrypted alert while the server expects
10463 // encryption, so the alert is not readable by runner.
10464 t.test.expectedLocalError = "local error: bad record MAC"
10465 }
10466
10467 if t.messageType == typeFinished {
10468 // Bad Finished messages read as the verify data having
10469 // the wrong length.
10470 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10471 t.test.expectedLocalError = "remote error: error decrypting message"
10472 }
10473
10474 testCases = append(testCases, t.test)
10475 }
10476}
10477
Steven Valdez143e8b32016-07-11 13:19:03 -040010478func addTLS13HandshakeTests() {
10479 testCases = append(testCases, testCase{
10480 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010481 name: "NegotiatePSKResumption-TLS13",
10482 config: Config{
10483 MaxVersion: VersionTLS13,
10484 Bugs: ProtocolBugs{
10485 NegotiatePSKResumption: true,
10486 },
10487 },
10488 resumeSession: true,
10489 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010490 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010491 })
10492
10493 testCases = append(testCases, testCase{
10494 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010495 name: "MissingKeyShare-Client",
10496 config: Config{
10497 MaxVersion: VersionTLS13,
10498 Bugs: ProtocolBugs{
10499 MissingKeyShare: true,
10500 },
10501 },
10502 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010503 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010504 })
10505
10506 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010507 testType: serverTest,
10508 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010509 config: Config{
10510 MaxVersion: VersionTLS13,
10511 Bugs: ProtocolBugs{
10512 MissingKeyShare: true,
10513 },
10514 },
10515 shouldFail: true,
10516 expectedError: ":MISSING_KEY_SHARE:",
10517 })
10518
10519 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010520 testType: serverTest,
10521 name: "DuplicateKeyShares",
10522 config: Config{
10523 MaxVersion: VersionTLS13,
10524 Bugs: ProtocolBugs{
10525 DuplicateKeyShares: true,
10526 },
10527 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010528 shouldFail: true,
10529 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010530 })
10531
10532 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010533 testType: serverTest,
10534 name: "SkipEarlyData",
10535 config: Config{
10536 MaxVersion: VersionTLS13,
10537 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010538 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010539 },
10540 },
10541 })
10542
10543 testCases = append(testCases, testCase{
10544 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010545 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010546 config: Config{
10547 MaxVersion: VersionTLS13,
10548 TLS13Variant: TLS13Experiment,
10549 Bugs: ProtocolBugs{
10550 SendFakeEarlyDataLength: 4,
10551 },
10552 },
10553 flags: []string{"-tls13-variant", "1"},
10554 })
10555
10556 testCases = append(testCases, testCase{
10557 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010558 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10559 config: Config{
10560 MaxVersion: VersionTLS13,
10561 TLS13Variant: TLS13RecordTypeExperiment,
10562 Bugs: ProtocolBugs{
10563 SendFakeEarlyDataLength: 4,
10564 },
10565 },
10566 flags: []string{"-tls13-variant", "2"},
10567 })
10568
10569 testCases = append(testCases, testCase{
10570 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010571 name: "SkipEarlyData-OmitEarlyDataExtension",
10572 config: Config{
10573 MaxVersion: VersionTLS13,
10574 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010575 SendFakeEarlyDataLength: 4,
10576 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010577 },
10578 },
10579 shouldFail: true,
10580 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10581 })
10582
10583 testCases = append(testCases, testCase{
10584 testType: serverTest,
10585 name: "SkipEarlyData-TooMuchData",
10586 config: Config{
10587 MaxVersion: VersionTLS13,
10588 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010589 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010590 },
10591 },
10592 shouldFail: true,
10593 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10594 })
10595
10596 testCases = append(testCases, testCase{
10597 testType: serverTest,
10598 name: "SkipEarlyData-Interleaved",
10599 config: Config{
10600 MaxVersion: VersionTLS13,
10601 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010602 SendFakeEarlyDataLength: 4,
10603 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010604 },
10605 },
10606 shouldFail: true,
10607 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10608 })
10609
10610 testCases = append(testCases, testCase{
10611 testType: serverTest,
10612 name: "SkipEarlyData-EarlyDataInTLS12",
10613 config: Config{
10614 MaxVersion: VersionTLS13,
10615 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010616 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010617 },
10618 },
10619 shouldFail: true,
10620 expectedError: ":UNEXPECTED_RECORD:",
10621 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10622 })
10623
10624 testCases = append(testCases, testCase{
10625 testType: serverTest,
10626 name: "SkipEarlyData-HRR",
10627 config: Config{
10628 MaxVersion: VersionTLS13,
10629 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010630 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010631 },
10632 DefaultCurves: []CurveID{},
10633 },
10634 })
10635
10636 testCases = append(testCases, testCase{
10637 testType: serverTest,
10638 name: "SkipEarlyData-HRR-Interleaved",
10639 config: Config{
10640 MaxVersion: VersionTLS13,
10641 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010642 SendFakeEarlyDataLength: 4,
10643 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010644 },
10645 DefaultCurves: []CurveID{},
10646 },
10647 shouldFail: true,
10648 expectedError: ":UNEXPECTED_RECORD:",
10649 })
10650
10651 testCases = append(testCases, testCase{
10652 testType: serverTest,
10653 name: "SkipEarlyData-HRR-TooMuchData",
10654 config: Config{
10655 MaxVersion: VersionTLS13,
10656 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010657 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010658 },
10659 DefaultCurves: []CurveID{},
10660 },
10661 shouldFail: true,
10662 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10663 })
10664
10665 // Test that skipping early data looking for cleartext correctly
10666 // processes an alert record.
10667 testCases = append(testCases, testCase{
10668 testType: serverTest,
10669 name: "SkipEarlyData-HRR-FatalAlert",
10670 config: Config{
10671 MaxVersion: VersionTLS13,
10672 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010673 SendEarlyAlert: true,
10674 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010675 },
10676 DefaultCurves: []CurveID{},
10677 },
10678 shouldFail: true,
10679 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10680 })
10681
10682 testCases = append(testCases, testCase{
10683 testType: serverTest,
10684 name: "SkipEarlyData-SecondClientHelloEarlyData",
10685 config: Config{
10686 MaxVersion: VersionTLS13,
10687 Bugs: ProtocolBugs{
10688 SendEarlyDataOnSecondClientHello: true,
10689 },
10690 DefaultCurves: []CurveID{},
10691 },
10692 shouldFail: true,
10693 expectedLocalError: "remote error: bad record MAC",
10694 })
10695
10696 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010697 testType: clientTest,
10698 name: "EmptyEncryptedExtensions",
10699 config: Config{
10700 MaxVersion: VersionTLS13,
10701 Bugs: ProtocolBugs{
10702 EmptyEncryptedExtensions: true,
10703 },
10704 },
10705 shouldFail: true,
10706 expectedLocalError: "remote error: error decoding message",
10707 })
10708
10709 testCases = append(testCases, testCase{
10710 testType: clientTest,
10711 name: "EncryptedExtensionsWithKeyShare",
10712 config: Config{
10713 MaxVersion: VersionTLS13,
10714 Bugs: ProtocolBugs{
10715 EncryptedExtensionsWithKeyShare: true,
10716 },
10717 },
10718 shouldFail: true,
10719 expectedLocalError: "remote error: unsupported extension",
10720 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010721
10722 testCases = append(testCases, testCase{
10723 testType: serverTest,
10724 name: "SendHelloRetryRequest",
10725 config: Config{
10726 MaxVersion: VersionTLS13,
10727 // Require a HelloRetryRequest for every curve.
10728 DefaultCurves: []CurveID{},
10729 },
10730 expectedCurveID: CurveX25519,
10731 })
10732
10733 testCases = append(testCases, testCase{
10734 testType: serverTest,
10735 name: "SendHelloRetryRequest-2",
10736 config: Config{
10737 MaxVersion: VersionTLS13,
10738 DefaultCurves: []CurveID{CurveP384},
10739 },
10740 // Although the ClientHello did not predict our preferred curve,
10741 // we always select it whether it is predicted or not.
10742 expectedCurveID: CurveX25519,
10743 })
10744
10745 testCases = append(testCases, testCase{
10746 name: "UnknownCurve-HelloRetryRequest",
10747 config: Config{
10748 MaxVersion: VersionTLS13,
10749 // P-384 requires HelloRetryRequest in BoringSSL.
10750 CurvePreferences: []CurveID{CurveP384},
10751 Bugs: ProtocolBugs{
10752 SendHelloRetryRequestCurve: bogusCurve,
10753 },
10754 },
10755 shouldFail: true,
10756 expectedError: ":WRONG_CURVE:",
10757 })
10758
10759 testCases = append(testCases, testCase{
10760 name: "DisabledCurve-HelloRetryRequest",
10761 config: Config{
10762 MaxVersion: VersionTLS13,
10763 CurvePreferences: []CurveID{CurveP256},
10764 Bugs: ProtocolBugs{
10765 IgnorePeerCurvePreferences: true,
10766 },
10767 },
10768 flags: []string{"-p384-only"},
10769 shouldFail: true,
10770 expectedError: ":WRONG_CURVE:",
10771 })
10772
10773 testCases = append(testCases, testCase{
10774 name: "UnnecessaryHelloRetryRequest",
10775 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010776 MaxVersion: VersionTLS13,
10777 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010778 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010779 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010780 },
10781 },
10782 shouldFail: true,
10783 expectedError: ":WRONG_CURVE:",
10784 })
10785
10786 testCases = append(testCases, testCase{
10787 name: "SecondHelloRetryRequest",
10788 config: Config{
10789 MaxVersion: VersionTLS13,
10790 // P-384 requires HelloRetryRequest in BoringSSL.
10791 CurvePreferences: []CurveID{CurveP384},
10792 Bugs: ProtocolBugs{
10793 SecondHelloRetryRequest: true,
10794 },
10795 },
10796 shouldFail: true,
10797 expectedError: ":UNEXPECTED_MESSAGE:",
10798 })
10799
10800 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010801 name: "HelloRetryRequest-Empty",
10802 config: Config{
10803 MaxVersion: VersionTLS13,
10804 Bugs: ProtocolBugs{
10805 AlwaysSendHelloRetryRequest: true,
10806 },
10807 },
10808 shouldFail: true,
10809 expectedError: ":DECODE_ERROR:",
10810 })
10811
10812 testCases = append(testCases, testCase{
10813 name: "HelloRetryRequest-DuplicateCurve",
10814 config: Config{
10815 MaxVersion: VersionTLS13,
10816 // P-384 requires a HelloRetryRequest against BoringSSL's default
10817 // configuration. Assert this ExpectMissingKeyShare.
10818 CurvePreferences: []CurveID{CurveP384},
10819 Bugs: ProtocolBugs{
10820 ExpectMissingKeyShare: true,
10821 DuplicateHelloRetryRequestExtensions: true,
10822 },
10823 },
10824 shouldFail: true,
10825 expectedError: ":DUPLICATE_EXTENSION:",
10826 expectedLocalError: "remote error: illegal parameter",
10827 })
10828
10829 testCases = append(testCases, testCase{
10830 name: "HelloRetryRequest-Cookie",
10831 config: Config{
10832 MaxVersion: VersionTLS13,
10833 Bugs: ProtocolBugs{
10834 SendHelloRetryRequestCookie: []byte("cookie"),
10835 },
10836 },
10837 })
10838
10839 testCases = append(testCases, testCase{
10840 name: "HelloRetryRequest-DuplicateCookie",
10841 config: Config{
10842 MaxVersion: VersionTLS13,
10843 Bugs: ProtocolBugs{
10844 SendHelloRetryRequestCookie: []byte("cookie"),
10845 DuplicateHelloRetryRequestExtensions: true,
10846 },
10847 },
10848 shouldFail: true,
10849 expectedError: ":DUPLICATE_EXTENSION:",
10850 expectedLocalError: "remote error: illegal parameter",
10851 })
10852
10853 testCases = append(testCases, testCase{
10854 name: "HelloRetryRequest-EmptyCookie",
10855 config: Config{
10856 MaxVersion: VersionTLS13,
10857 Bugs: ProtocolBugs{
10858 SendHelloRetryRequestCookie: []byte{},
10859 },
10860 },
10861 shouldFail: true,
10862 expectedError: ":DECODE_ERROR:",
10863 })
10864
10865 testCases = append(testCases, testCase{
10866 name: "HelloRetryRequest-Cookie-Curve",
10867 config: Config{
10868 MaxVersion: VersionTLS13,
10869 // P-384 requires HelloRetryRequest in BoringSSL.
10870 CurvePreferences: []CurveID{CurveP384},
10871 Bugs: ProtocolBugs{
10872 SendHelloRetryRequestCookie: []byte("cookie"),
10873 ExpectMissingKeyShare: true,
10874 },
10875 },
10876 })
10877
10878 testCases = append(testCases, testCase{
10879 name: "HelloRetryRequest-Unknown",
10880 config: Config{
10881 MaxVersion: VersionTLS13,
10882 Bugs: ProtocolBugs{
10883 CustomHelloRetryRequestExtension: "extension",
10884 },
10885 },
10886 shouldFail: true,
10887 expectedError: ":UNEXPECTED_EXTENSION:",
10888 expectedLocalError: "remote error: unsupported extension",
10889 })
10890
10891 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010892 testType: serverTest,
10893 name: "SecondClientHelloMissingKeyShare",
10894 config: Config{
10895 MaxVersion: VersionTLS13,
10896 DefaultCurves: []CurveID{},
10897 Bugs: ProtocolBugs{
10898 SecondClientHelloMissingKeyShare: true,
10899 },
10900 },
10901 shouldFail: true,
10902 expectedError: ":MISSING_KEY_SHARE:",
10903 })
10904
10905 testCases = append(testCases, testCase{
10906 testType: serverTest,
10907 name: "SecondClientHelloWrongCurve",
10908 config: Config{
10909 MaxVersion: VersionTLS13,
10910 DefaultCurves: []CurveID{},
10911 Bugs: ProtocolBugs{
10912 MisinterpretHelloRetryRequestCurve: CurveP521,
10913 },
10914 },
10915 shouldFail: true,
10916 expectedError: ":WRONG_CURVE:",
10917 })
10918
10919 testCases = append(testCases, testCase{
10920 name: "HelloRetryRequestVersionMismatch",
10921 config: Config{
10922 MaxVersion: VersionTLS13,
10923 // P-384 requires HelloRetryRequest in BoringSSL.
10924 CurvePreferences: []CurveID{CurveP384},
10925 Bugs: ProtocolBugs{
10926 SendServerHelloVersion: 0x0305,
10927 },
10928 },
10929 shouldFail: true,
10930 expectedError: ":WRONG_VERSION_NUMBER:",
10931 })
10932
10933 testCases = append(testCases, testCase{
10934 name: "HelloRetryRequestCurveMismatch",
10935 config: Config{
10936 MaxVersion: VersionTLS13,
10937 // P-384 requires HelloRetryRequest in BoringSSL.
10938 CurvePreferences: []CurveID{CurveP384},
10939 Bugs: ProtocolBugs{
10940 // Send P-384 (correct) in the HelloRetryRequest.
10941 SendHelloRetryRequestCurve: CurveP384,
10942 // But send P-256 in the ServerHello.
10943 SendCurve: CurveP256,
10944 },
10945 },
10946 shouldFail: true,
10947 expectedError: ":WRONG_CURVE:",
10948 })
10949
10950 // Test the server selecting a curve that requires a HelloRetryRequest
10951 // without sending it.
10952 testCases = append(testCases, testCase{
10953 name: "SkipHelloRetryRequest",
10954 config: Config{
10955 MaxVersion: VersionTLS13,
10956 // P-384 requires HelloRetryRequest in BoringSSL.
10957 CurvePreferences: []CurveID{CurveP384},
10958 Bugs: ProtocolBugs{
10959 SkipHelloRetryRequest: true,
10960 },
10961 },
10962 shouldFail: true,
10963 expectedError: ":WRONG_CURVE:",
10964 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010965
10966 testCases = append(testCases, testCase{
10967 name: "TLS13-RequestContextInHandshake",
10968 config: Config{
10969 MaxVersion: VersionTLS13,
10970 MinVersion: VersionTLS13,
10971 ClientAuth: RequireAnyClientCert,
10972 Bugs: ProtocolBugs{
10973 SendRequestContext: []byte("request context"),
10974 },
10975 },
10976 flags: []string{
10977 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10978 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10979 },
10980 shouldFail: true,
10981 expectedError: ":DECODE_ERROR:",
10982 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010983
10984 testCases = append(testCases, testCase{
10985 testType: serverTest,
10986 name: "TLS13-TrailingKeyShareData",
10987 config: Config{
10988 MaxVersion: VersionTLS13,
10989 Bugs: ProtocolBugs{
10990 TrailingKeyShareData: true,
10991 },
10992 },
10993 shouldFail: true,
10994 expectedError: ":DECODE_ERROR:",
10995 })
David Benjamin7f78df42016-10-05 22:33:19 -040010996
10997 testCases = append(testCases, testCase{
10998 name: "TLS13-AlwaysSelectPSKIdentity",
10999 config: Config{
11000 MaxVersion: VersionTLS13,
11001 Bugs: ProtocolBugs{
11002 AlwaysSelectPSKIdentity: true,
11003 },
11004 },
11005 shouldFail: true,
11006 expectedError: ":UNEXPECTED_EXTENSION:",
11007 })
11008
11009 testCases = append(testCases, testCase{
11010 name: "TLS13-InvalidPSKIdentity",
11011 config: Config{
11012 MaxVersion: VersionTLS13,
11013 Bugs: ProtocolBugs{
11014 SelectPSKIdentityOnResume: 1,
11015 },
11016 },
11017 resumeSession: true,
11018 shouldFail: true,
11019 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11020 })
David Benjamin1286bee2016-10-07 15:25:06 -040011021
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011022 testCases = append(testCases, testCase{
11023 testType: serverTest,
11024 name: "TLS13-ExtraPSKIdentity",
11025 config: Config{
11026 MaxVersion: VersionTLS13,
11027 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011028 ExtraPSKIdentity: true,
11029 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011030 },
11031 },
11032 resumeSession: true,
11033 })
11034
David Benjamin1286bee2016-10-07 15:25:06 -040011035 // Test that unknown NewSessionTicket extensions are tolerated.
11036 testCases = append(testCases, testCase{
11037 name: "TLS13-CustomTicketExtension",
11038 config: Config{
11039 MaxVersion: VersionTLS13,
11040 Bugs: ProtocolBugs{
11041 CustomTicketExtension: "1234",
11042 },
11043 },
11044 })
Steven Valdez2d850622017-01-11 11:34:52 -050011045
Steven Valdez0e4a4482017-07-17 11:12:34 -040011046 for _, noSessionID := range []bool{false, true} {
11047 prefix := "TLS13Experiment"
11048 variant := TLS13Experiment
11049 if noSessionID {
11050 prefix = "TLS13NoSessionIDExperiment"
11051 variant = TLS13NoSessionIDExperiment
11052 }
11053
11054 // Test that enabling a TLS 1.3 variant does not interfere with
11055 // TLS 1.2 session ID resumption.
11056 testCases = append(testCases, testCase{
11057 testType: clientTest,
11058 name: prefix + "-ResumeTLS12SessionID",
11059 config: Config{
11060 MaxVersion: VersionTLS12,
11061 SessionTicketsDisabled: true,
11062 },
11063 resumeSession: true,
11064 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11065 })
11066
11067 // Test that the server correctly echoes back session IDs of
11068 // various lengths.
11069 testCases = append(testCases, testCase{
11070 testType: serverTest,
11071 name: prefix + "-EmptySessionID",
11072 config: Config{
11073 MaxVersion: VersionTLS13,
11074 Bugs: ProtocolBugs{
11075 SendClientHelloSessionID: []byte{},
11076 },
11077 },
11078 tls13Variant: variant,
11079 })
11080
11081 testCases = append(testCases, testCase{
11082 testType: serverTest,
11083 name: prefix + "-ShortSessionID",
11084 config: Config{
11085 MaxVersion: VersionTLS13,
11086 Bugs: ProtocolBugs{
11087 SendClientHelloSessionID: make([]byte, 16),
11088 },
11089 },
11090 tls13Variant: variant,
11091 })
11092
11093 testCases = append(testCases, testCase{
11094 testType: serverTest,
11095 name: prefix + "-FullSessionID",
11096 config: Config{
11097 MaxVersion: VersionTLS13,
11098 Bugs: ProtocolBugs{
11099 SendClientHelloSessionID: make([]byte, 32),
11100 },
11101 },
11102 tls13Variant: variant,
11103 })
11104 }
11105
11106 // Test that the client sends a fake session ID in TLS13Experiment.
11107 testCases = append(testCases, testCase{
11108 testType: clientTest,
11109 name: "TLS13Experiment-RequireSessionID",
11110 config: Config{
11111 MaxVersion: VersionTLS13,
11112 Bugs: ProtocolBugs{
11113 ExpectClientHelloSessionID: true,
11114 },
11115 },
11116 tls13Variant: TLS13Experiment,
11117 })
11118
11119 // Test that the client does not send a fake session ID in
11120 // TLS13NoSessionIDExperiment.
11121 testCases = append(testCases, testCase{
11122 testType: clientTest,
11123 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11124 config: Config{
11125 MaxVersion: VersionTLS13,
11126 Bugs: ProtocolBugs{
11127 ExpectEmptyClientHelloSessionID: true,
11128 },
11129 },
11130 tls13Variant: TLS13NoSessionIDExperiment,
11131 })
11132
Steven Valdez2d850622017-01-11 11:34:52 -050011133 testCases = append(testCases, testCase{
11134 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011135 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011136 config: Config{
11137 MaxVersion: VersionTLS13,
11138 MaxEarlyDataSize: 16384,
11139 },
11140 resumeConfig: &Config{
11141 MaxVersion: VersionTLS13,
11142 MaxEarlyDataSize: 16384,
11143 Bugs: ProtocolBugs{
11144 AlwaysRejectEarlyData: true,
11145 },
11146 },
11147 resumeSession: true,
11148 flags: []string{
11149 "-enable-early-data",
11150 "-expect-early-data-info",
11151 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011152 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011153 },
11154 })
11155
11156 testCases = append(testCases, testCase{
11157 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011158 name: "TLS13Experiment-EarlyData-Reject-Client",
11159 config: Config{
11160 MaxVersion: VersionTLS13,
11161 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011162 },
11163 resumeConfig: &Config{
11164 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011165 MaxEarlyDataSize: 16384,
11166 Bugs: ProtocolBugs{
11167 AlwaysRejectEarlyData: true,
11168 },
11169 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011170 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011171 resumeSession: true,
11172 flags: []string{
11173 "-enable-early-data",
11174 "-expect-early-data-info",
11175 "-expect-reject-early-data",
11176 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011177 },
11178 })
11179
11180 testCases = append(testCases, testCase{
11181 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011182 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11183 config: Config{
11184 MaxVersion: VersionTLS13,
11185 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011186 },
11187 resumeConfig: &Config{
11188 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011189 MaxEarlyDataSize: 16384,
11190 Bugs: ProtocolBugs{
11191 AlwaysRejectEarlyData: true,
11192 },
11193 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011194 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011195 resumeSession: true,
11196 flags: []string{
11197 "-enable-early-data",
11198 "-expect-early-data-info",
11199 "-expect-reject-early-data",
11200 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011201 },
11202 })
11203
11204 testCases = append(testCases, testCase{
11205 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011206 name: "TLS13-EarlyData-RejectTicket-Client",
11207 config: Config{
11208 MaxVersion: VersionTLS13,
11209 MaxEarlyDataSize: 16384,
11210 Certificates: []Certificate{rsaCertificate},
11211 },
11212 resumeConfig: &Config{
11213 MaxVersion: VersionTLS13,
11214 MaxEarlyDataSize: 16384,
11215 Certificates: []Certificate{ecdsaP256Certificate},
11216 SessionTicketsDisabled: true,
11217 },
11218 resumeSession: true,
11219 expectResumeRejected: true,
11220 flags: []string{
11221 "-enable-early-data",
11222 "-expect-early-data-info",
11223 "-expect-reject-early-data",
11224 "-on-resume-shim-writes-first",
11225 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11226 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11227 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11228 // Session tickets are disabled, so the runner will not send a ticket.
11229 "-on-retry-expect-no-session",
11230 },
11231 })
11232
11233 testCases = append(testCases, testCase{
11234 testType: clientTest,
11235 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011236 config: Config{
11237 MaxVersion: VersionTLS13,
11238 MaxEarlyDataSize: 16384,
11239 },
11240 resumeConfig: &Config{
11241 MaxVersion: VersionTLS13,
11242 MaxEarlyDataSize: 16384,
11243 Bugs: ProtocolBugs{
11244 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11245 },
11246 },
11247 resumeSession: true,
11248 flags: []string{
11249 "-enable-early-data",
11250 "-expect-early-data-info",
11251 "-expect-reject-early-data",
11252 },
11253 })
11254
11255 // The client must check the server does not send the early_data
11256 // extension while rejecting the session.
11257 testCases = append(testCases, testCase{
11258 testType: clientTest,
11259 name: "TLS13-EarlyDataWithoutResume-Client",
11260 config: Config{
11261 MaxVersion: VersionTLS13,
11262 MaxEarlyDataSize: 16384,
11263 },
11264 resumeConfig: &Config{
11265 MaxVersion: VersionTLS13,
11266 SessionTicketsDisabled: true,
11267 Bugs: ProtocolBugs{
11268 SendEarlyDataExtension: true,
11269 },
11270 },
11271 resumeSession: true,
11272 flags: []string{
11273 "-enable-early-data",
11274 "-expect-early-data-info",
11275 },
11276 shouldFail: true,
11277 expectedError: ":UNEXPECTED_EXTENSION:",
11278 })
11279
11280 // The client must fail with a dedicated error code if the server
11281 // responds with TLS 1.2 when offering 0-RTT.
11282 testCases = append(testCases, testCase{
11283 testType: clientTest,
11284 name: "TLS13-EarlyDataVersionDowngrade-Client",
11285 config: Config{
11286 MaxVersion: VersionTLS13,
11287 MaxEarlyDataSize: 16384,
11288 },
11289 resumeConfig: &Config{
11290 MaxVersion: VersionTLS12,
11291 },
11292 resumeSession: true,
11293 flags: []string{
11294 "-enable-early-data",
11295 "-expect-early-data-info",
11296 },
11297 shouldFail: true,
11298 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11299 })
11300
11301 // Test that the client rejects an (unsolicited) early_data extension if
11302 // the server sent an HRR.
11303 testCases = append(testCases, testCase{
11304 testType: clientTest,
11305 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11306 config: Config{
11307 MaxVersion: VersionTLS13,
11308 MaxEarlyDataSize: 16384,
11309 },
11310 resumeConfig: &Config{
11311 MaxVersion: VersionTLS13,
11312 MaxEarlyDataSize: 16384,
11313 Bugs: ProtocolBugs{
11314 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11315 SendEarlyDataExtension: true,
11316 },
11317 },
11318 resumeSession: true,
11319 flags: []string{
11320 "-enable-early-data",
11321 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011322 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011323 },
11324 shouldFail: true,
11325 expectedError: ":UNEXPECTED_EXTENSION:",
11326 })
11327
11328 fooString := "foo"
11329 barString := "bar"
11330
11331 // Test that the client reports the correct ALPN after a 0-RTT reject
11332 // that changed it.
11333 testCases = append(testCases, testCase{
11334 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011335 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011336 config: Config{
11337 MaxVersion: VersionTLS13,
11338 MaxEarlyDataSize: 16384,
11339 Bugs: ProtocolBugs{
11340 ALPNProtocol: &fooString,
11341 },
11342 },
11343 resumeConfig: &Config{
11344 MaxVersion: VersionTLS13,
11345 MaxEarlyDataSize: 16384,
11346 Bugs: ProtocolBugs{
11347 ALPNProtocol: &barString,
11348 },
11349 },
11350 resumeSession: true,
11351 flags: []string{
11352 "-advertise-alpn", "\x03foo\x03bar",
11353 "-enable-early-data",
11354 "-expect-early-data-info",
11355 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011356 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011357 "-on-resume-expect-alpn", "foo",
11358 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011359 },
11360 })
11361
11362 // Test that the client reports the correct ALPN after a 0-RTT reject if
11363 // ALPN was omitted from the first connection.
11364 testCases = append(testCases, testCase{
11365 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011366 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011367 config: Config{
11368 MaxVersion: VersionTLS13,
11369 MaxEarlyDataSize: 16384,
11370 },
11371 resumeConfig: &Config{
11372 MaxVersion: VersionTLS13,
11373 MaxEarlyDataSize: 16384,
11374 NextProtos: []string{"foo"},
11375 },
11376 resumeSession: true,
11377 flags: []string{
11378 "-advertise-alpn", "\x03foo\x03bar",
11379 "-enable-early-data",
11380 "-expect-early-data-info",
11381 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011382 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011383 "-on-resume-expect-alpn", "",
11384 "-on-retry-expect-alpn", "foo",
11385 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011386 },
11387 })
11388
11389 // Test that the client reports the correct ALPN after a 0-RTT reject if
11390 // ALPN was omitted from the second connection.
11391 testCases = append(testCases, testCase{
11392 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011393 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011394 config: Config{
11395 MaxVersion: VersionTLS13,
11396 MaxEarlyDataSize: 16384,
11397 NextProtos: []string{"foo"},
11398 },
11399 resumeConfig: &Config{
11400 MaxVersion: VersionTLS13,
11401 MaxEarlyDataSize: 16384,
11402 },
11403 resumeSession: true,
11404 flags: []string{
11405 "-advertise-alpn", "\x03foo\x03bar",
11406 "-enable-early-data",
11407 "-expect-early-data-info",
11408 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011409 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011410 "-on-resume-expect-alpn", "foo",
11411 "-on-retry-expect-alpn", "",
11412 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011413 },
11414 })
11415
11416 // Test that the client enforces ALPN match on 0-RTT accept.
11417 testCases = append(testCases, testCase{
11418 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011419 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011420 config: Config{
11421 MaxVersion: VersionTLS13,
11422 MaxEarlyDataSize: 16384,
11423 Bugs: ProtocolBugs{
11424 ALPNProtocol: &fooString,
11425 },
11426 },
11427 resumeConfig: &Config{
11428 MaxVersion: VersionTLS13,
11429 MaxEarlyDataSize: 16384,
11430 Bugs: ProtocolBugs{
11431 AlwaysAcceptEarlyData: true,
11432 ALPNProtocol: &barString,
11433 },
11434 },
11435 resumeSession: true,
11436 flags: []string{
11437 "-advertise-alpn", "\x03foo\x03bar",
11438 "-enable-early-data",
11439 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011440 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011441 "-on-resume-expect-alpn", "foo",
11442 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011443 },
11444 shouldFail: true,
11445 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11446 })
11447
11448 // Test that the server correctly rejects 0-RTT when the previous
11449 // session did not allow early data on resumption.
11450 testCases = append(testCases, testCase{
11451 testType: serverTest,
11452 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11453 config: Config{
11454 MaxVersion: VersionTLS13,
11455 },
11456 resumeConfig: &Config{
11457 MaxVersion: VersionTLS13,
11458 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011459 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011460 ExpectEarlyDataAccepted: false,
11461 },
11462 },
11463 resumeSession: true,
11464 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011465 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011466 "-expect-reject-early-data",
11467 },
11468 })
11469
11470 // Test that we reject early data where ALPN is omitted from the first
11471 // connection.
11472 testCases = append(testCases, testCase{
11473 testType: serverTest,
11474 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11475 config: Config{
11476 MaxVersion: VersionTLS13,
11477 NextProtos: []string{},
11478 },
11479 resumeConfig: &Config{
11480 MaxVersion: VersionTLS13,
11481 NextProtos: []string{"foo"},
11482 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011483 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011484 ExpectEarlyDataAccepted: false,
11485 },
11486 },
11487 resumeSession: true,
11488 flags: []string{
11489 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011490 "-on-initial-select-alpn", "",
11491 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011492 },
11493 })
11494
11495 // Test that we reject early data where ALPN is omitted from the second
11496 // connection.
11497 testCases = append(testCases, testCase{
11498 testType: serverTest,
11499 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11500 config: Config{
11501 MaxVersion: VersionTLS13,
11502 NextProtos: []string{"foo"},
11503 },
11504 resumeConfig: &Config{
11505 MaxVersion: VersionTLS13,
11506 NextProtos: []string{},
11507 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011508 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011509 ExpectEarlyDataAccepted: false,
11510 },
11511 },
11512 resumeSession: true,
11513 flags: []string{
11514 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011515 "-on-initial-select-alpn", "foo",
11516 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011517 },
11518 })
11519
11520 // Test that we reject early data with mismatched ALPN.
11521 testCases = append(testCases, testCase{
11522 testType: serverTest,
11523 name: "TLS13-EarlyData-ALPNMismatch-Server",
11524 config: Config{
11525 MaxVersion: VersionTLS13,
11526 NextProtos: []string{"foo"},
11527 },
11528 resumeConfig: &Config{
11529 MaxVersion: VersionTLS13,
11530 NextProtos: []string{"bar"},
11531 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011532 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011533 ExpectEarlyDataAccepted: false,
11534 },
11535 },
11536 resumeSession: true,
11537 flags: []string{
11538 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011539 "-on-initial-select-alpn", "foo",
11540 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011541 },
11542 })
11543
David Benjamin6bb507b2017-03-29 16:35:57 -050011544 // Test that the client offering 0-RTT and Channel ID forbids the server
11545 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011546 testCases = append(testCases, testCase{
11547 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011548 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011549 config: Config{
11550 MaxVersion: VersionTLS13,
11551 MaxEarlyDataSize: 16384,
11552 RequestChannelID: true,
11553 },
11554 resumeSession: true,
11555 expectChannelID: true,
11556 shouldFail: true,
11557 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11558 flags: []string{
11559 "-enable-early-data",
11560 "-expect-early-data-info",
11561 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11562 },
11563 })
11564
David Benjamin6bb507b2017-03-29 16:35:57 -050011565 // Test that the client offering Channel ID and 0-RTT allows the server
11566 // to decline 0-RTT.
11567 testCases = append(testCases, testCase{
11568 testType: clientTest,
11569 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11570 config: Config{
11571 MaxVersion: VersionTLS13,
11572 MaxEarlyDataSize: 16384,
11573 RequestChannelID: true,
11574 Bugs: ProtocolBugs{
11575 AlwaysRejectEarlyData: true,
11576 },
11577 },
11578 resumeSession: true,
11579 expectChannelID: true,
11580 flags: []string{
11581 "-enable-early-data",
11582 "-expect-early-data-info",
11583 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11584 "-expect-reject-early-data",
11585 },
11586 })
11587
11588 // Test that the client offering Channel ID and 0-RTT allows the server
11589 // to decline Channel ID.
11590 testCases = append(testCases, testCase{
11591 testType: clientTest,
11592 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11593 config: Config{
11594 MaxVersion: VersionTLS13,
11595 MaxEarlyDataSize: 16384,
11596 },
11597 resumeSession: true,
11598 flags: []string{
11599 "-enable-early-data",
11600 "-expect-early-data-info",
11601 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11602 "-expect-accept-early-data",
11603 },
11604 })
11605
11606 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11607 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011608 testCases = append(testCases, testCase{
11609 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011610 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011611 config: Config{
11612 MaxVersion: VersionTLS13,
11613 ChannelID: channelIDKey,
11614 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011615 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011616 ExpectEarlyDataAccepted: false,
11617 },
11618 },
11619 resumeSession: true,
11620 expectChannelID: true,
11621 flags: []string{
11622 "-enable-early-data",
11623 "-expect-reject-early-data",
11624 "-expect-channel-id",
11625 base64.StdEncoding.EncodeToString(channelIDBytes),
11626 },
11627 })
11628
David Benjamin6bb507b2017-03-29 16:35:57 -050011629 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11630 // if not offered Channel ID.
11631 testCases = append(testCases, testCase{
11632 testType: serverTest,
11633 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11634 config: Config{
11635 MaxVersion: VersionTLS13,
11636 Bugs: ProtocolBugs{
11637 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11638 ExpectEarlyDataAccepted: true,
11639 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11640 },
11641 },
11642 resumeSession: true,
11643 expectChannelID: false,
11644 flags: []string{
11645 "-enable-early-data",
11646 "-expect-accept-early-data",
11647 "-enable-channel-id",
11648 },
11649 })
11650
David Benjamin32c89272017-03-26 13:54:21 -050011651 // Test that the server rejects 0-RTT streams without end_of_early_data.
11652 // The subsequent records should fail to decrypt.
11653 testCases = append(testCases, testCase{
11654 testType: serverTest,
11655 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11656 config: Config{
11657 MaxVersion: VersionTLS13,
11658 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011659 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011660 ExpectEarlyDataAccepted: true,
11661 SkipEndOfEarlyData: true,
11662 },
11663 },
11664 resumeSession: true,
11665 flags: []string{"-enable-early-data"},
11666 shouldFail: true,
11667 expectedLocalError: "remote error: bad record MAC",
11668 expectedError: ":BAD_DECRYPT:",
11669 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011670
11671 testCases = append(testCases, testCase{
11672 testType: serverTest,
11673 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11674 config: Config{
11675 MaxVersion: VersionTLS13,
11676 },
11677 resumeConfig: &Config{
11678 MaxVersion: VersionTLS13,
11679 Bugs: ProtocolBugs{
11680 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11681 SendStrayEarlyHandshake: true,
11682 ExpectEarlyDataAccepted: true},
11683 },
11684 resumeSession: true,
11685 shouldFail: true,
11686 expectedError: ":UNEXPECTED_RECORD:",
11687 expectedLocalError: "remote error: unexpected message",
11688 flags: []string{
11689 "-enable-early-data",
11690 },
11691 })
David Benjamind9cbb532017-07-07 13:17:19 -040011692
11693 // Test that the client reports TLS 1.3 as the version while sending
11694 // early data.
11695 testCases = append(testCases, testCase{
11696 testType: clientTest,
11697 name: "TLS13-EarlyData-Client-VersionAPI",
11698 config: Config{
11699 MaxVersion: VersionTLS13,
11700 MaxEarlyDataSize: 16384,
11701 },
11702 resumeSession: true,
11703 flags: []string{
11704 "-enable-early-data",
11705 "-expect-early-data-info",
11706 "-expect-accept-early-data",
11707 "-expect-version", strconv.Itoa(VersionTLS13),
11708 },
11709 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011710}
11711
David Benjaminabbbee12016-10-31 19:20:42 -040011712func addTLS13CipherPreferenceTests() {
11713 // Test that client preference is honored if the shim has AES hardware
11714 // and ChaCha20-Poly1305 is preferred otherwise.
11715 testCases = append(testCases, testCase{
11716 testType: serverTest,
11717 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11718 config: Config{
11719 MaxVersion: VersionTLS13,
11720 CipherSuites: []uint16{
11721 TLS_CHACHA20_POLY1305_SHA256,
11722 TLS_AES_128_GCM_SHA256,
11723 },
11724 },
11725 flags: []string{
11726 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11727 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11728 },
11729 })
11730
11731 testCases = append(testCases, testCase{
11732 testType: serverTest,
11733 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11734 config: Config{
11735 MaxVersion: VersionTLS13,
11736 CipherSuites: []uint16{
11737 TLS_AES_128_GCM_SHA256,
11738 TLS_CHACHA20_POLY1305_SHA256,
11739 },
11740 },
11741 flags: []string{
11742 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11743 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11744 },
11745 })
11746
11747 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11748 // whether it has AES hardware.
11749 testCases = append(testCases, testCase{
11750 name: "TLS13-CipherPreference-Client",
11751 config: Config{
11752 MaxVersion: VersionTLS13,
11753 // Use the client cipher order. (This is the default but
11754 // is listed to be explicit.)
11755 PreferServerCipherSuites: false,
11756 },
11757 flags: []string{
11758 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11759 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11760 },
11761 })
11762}
11763
David Benjaminf3fbade2016-09-19 13:08:16 -040011764func addPeekTests() {
11765 // Test SSL_peek works, including on empty records.
11766 testCases = append(testCases, testCase{
11767 name: "Peek-Basic",
11768 sendEmptyRecords: 1,
11769 flags: []string{"-peek-then-read"},
11770 })
11771
11772 // Test SSL_peek can drive the initial handshake.
11773 testCases = append(testCases, testCase{
11774 name: "Peek-ImplicitHandshake",
11775 flags: []string{
11776 "-peek-then-read",
11777 "-implicit-handshake",
11778 },
11779 })
11780
11781 // Test SSL_peek can discover and drive a renegotiation.
11782 testCases = append(testCases, testCase{
11783 name: "Peek-Renegotiate",
11784 config: Config{
11785 MaxVersion: VersionTLS12,
11786 },
11787 renegotiate: 1,
11788 flags: []string{
11789 "-peek-then-read",
11790 "-renegotiate-freely",
11791 "-expect-total-renegotiations", "1",
11792 },
11793 })
11794
11795 // Test SSL_peek can discover a close_notify.
11796 testCases = append(testCases, testCase{
11797 name: "Peek-Shutdown",
11798 config: Config{
11799 Bugs: ProtocolBugs{
11800 ExpectCloseNotify: true,
11801 },
11802 },
11803 flags: []string{
11804 "-peek-then-read",
11805 "-check-close-notify",
11806 },
11807 })
11808
11809 // Test SSL_peek can discover an alert.
11810 testCases = append(testCases, testCase{
11811 name: "Peek-Alert",
11812 config: Config{
11813 Bugs: ProtocolBugs{
11814 SendSpuriousAlert: alertRecordOverflow,
11815 },
11816 },
11817 flags: []string{"-peek-then-read"},
11818 shouldFail: true,
11819 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11820 })
11821
11822 // Test SSL_peek can handle KeyUpdate.
11823 testCases = append(testCases, testCase{
11824 name: "Peek-KeyUpdate",
11825 config: Config{
11826 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011827 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011828 sendKeyUpdates: 1,
11829 keyUpdateRequest: keyUpdateNotRequested,
11830 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011831 })
11832}
11833
David Benjamine6f22212016-11-08 14:28:24 -050011834func addRecordVersionTests() {
11835 for _, ver := range tlsVersions {
11836 // Test that the record version is enforced.
11837 testCases = append(testCases, testCase{
11838 name: "CheckRecordVersion-" + ver.name,
11839 config: Config{
11840 MinVersion: ver.version,
11841 MaxVersion: ver.version,
11842 Bugs: ProtocolBugs{
11843 SendRecordVersion: 0x03ff,
11844 },
11845 },
David Benjamina5022392017-07-10 17:40:39 -040011846 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011847 shouldFail: true,
11848 expectedError: ":WRONG_VERSION_NUMBER:",
11849 })
11850
11851 // Test that the ClientHello may use any record version, for
11852 // compatibility reasons.
11853 testCases = append(testCases, testCase{
11854 testType: serverTest,
11855 name: "LooseInitialRecordVersion-" + ver.name,
11856 config: Config{
11857 MinVersion: ver.version,
11858 MaxVersion: ver.version,
11859 Bugs: ProtocolBugs{
11860 SendInitialRecordVersion: 0x03ff,
11861 },
11862 },
David Benjamina5022392017-07-10 17:40:39 -040011863 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011864 })
11865
11866 // Test that garbage ClientHello record versions are rejected.
11867 testCases = append(testCases, testCase{
11868 testType: serverTest,
11869 name: "GarbageInitialRecordVersion-" + ver.name,
11870 config: Config{
11871 MinVersion: ver.version,
11872 MaxVersion: ver.version,
11873 Bugs: ProtocolBugs{
11874 SendInitialRecordVersion: 0xffff,
11875 },
11876 },
David Benjamina5022392017-07-10 17:40:39 -040011877 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011878 shouldFail: true,
11879 expectedError: ":WRONG_VERSION_NUMBER:",
11880 })
11881 }
11882}
11883
David Benjamin2c516452016-11-15 10:16:54 +090011884func addCertificateTests() {
11885 // Test that a certificate chain with intermediate may be sent and
11886 // received as both client and server.
11887 for _, ver := range tlsVersions {
11888 testCases = append(testCases, testCase{
11889 testType: clientTest,
11890 name: "SendReceiveIntermediate-Client-" + ver.name,
11891 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011892 MinVersion: ver.version,
11893 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011894 Certificates: []Certificate{rsaChainCertificate},
11895 ClientAuth: RequireAnyClientCert,
11896 },
David Benjamina5022392017-07-10 17:40:39 -040011897 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011898 expectPeerCertificate: &rsaChainCertificate,
11899 flags: []string{
11900 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11901 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11902 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11903 },
11904 })
11905
11906 testCases = append(testCases, testCase{
11907 testType: serverTest,
11908 name: "SendReceiveIntermediate-Server-" + ver.name,
11909 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011910 MinVersion: ver.version,
11911 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011912 Certificates: []Certificate{rsaChainCertificate},
11913 },
David Benjamina5022392017-07-10 17:40:39 -040011914 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011915 expectPeerCertificate: &rsaChainCertificate,
11916 flags: []string{
11917 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11918 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11919 "-require-any-client-certificate",
11920 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11921 },
11922 })
11923 }
11924}
11925
David Benjaminbbaf3672016-11-17 10:53:09 +090011926func addRetainOnlySHA256ClientCertTests() {
11927 for _, ver := range tlsVersions {
11928 // Test that enabling
11929 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11930 // actually requesting a client certificate is a no-op.
11931 testCases = append(testCases, testCase{
11932 testType: serverTest,
11933 name: "RetainOnlySHA256-NoCert-" + ver.name,
11934 config: Config{
11935 MinVersion: ver.version,
11936 MaxVersion: ver.version,
11937 },
David Benjamina5022392017-07-10 17:40:39 -040011938 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011939 flags: []string{
11940 "-retain-only-sha256-client-cert-initial",
11941 "-retain-only-sha256-client-cert-resume",
11942 },
11943 resumeSession: true,
11944 })
11945
11946 // Test that when retaining only a SHA-256 certificate is
11947 // enabled, the hash appears as expected.
11948 testCases = append(testCases, testCase{
11949 testType: serverTest,
11950 name: "RetainOnlySHA256-Cert-" + ver.name,
11951 config: Config{
11952 MinVersion: ver.version,
11953 MaxVersion: ver.version,
11954 Certificates: []Certificate{rsaCertificate},
11955 },
David Benjamina5022392017-07-10 17:40:39 -040011956 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011957 flags: []string{
11958 "-verify-peer",
11959 "-retain-only-sha256-client-cert-initial",
11960 "-retain-only-sha256-client-cert-resume",
11961 "-expect-sha256-client-cert-initial",
11962 "-expect-sha256-client-cert-resume",
11963 },
11964 resumeSession: true,
11965 })
11966
11967 // Test that when the config changes from on to off, a
11968 // resumption is rejected because the server now wants the full
11969 // certificate chain.
11970 testCases = append(testCases, testCase{
11971 testType: serverTest,
11972 name: "RetainOnlySHA256-OnOff-" + ver.name,
11973 config: Config{
11974 MinVersion: ver.version,
11975 MaxVersion: ver.version,
11976 Certificates: []Certificate{rsaCertificate},
11977 },
David Benjamina5022392017-07-10 17:40:39 -040011978 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011979 flags: []string{
11980 "-verify-peer",
11981 "-retain-only-sha256-client-cert-initial",
11982 "-expect-sha256-client-cert-initial",
11983 },
11984 resumeSession: true,
11985 expectResumeRejected: true,
11986 })
11987
11988 // Test that when the config changes from off to on, a
11989 // resumption is rejected because the server now wants just the
11990 // hash.
11991 testCases = append(testCases, testCase{
11992 testType: serverTest,
11993 name: "RetainOnlySHA256-OffOn-" + ver.name,
11994 config: Config{
11995 MinVersion: ver.version,
11996 MaxVersion: ver.version,
11997 Certificates: []Certificate{rsaCertificate},
11998 },
David Benjamina5022392017-07-10 17:40:39 -040011999 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012000 flags: []string{
12001 "-verify-peer",
12002 "-retain-only-sha256-client-cert-resume",
12003 "-expect-sha256-client-cert-resume",
12004 },
12005 resumeSession: true,
12006 expectResumeRejected: true,
12007 })
12008 }
12009}
12010
Adam Langleya4b91982016-12-12 12:05:53 -080012011func addECDSAKeyUsageTests() {
12012 p256 := elliptic.P256()
12013 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12014 if err != nil {
12015 panic(err)
12016 }
12017
12018 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12019 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12020 if err != nil {
12021 panic(err)
12022 }
12023
12024 template := x509.Certificate{
12025 SerialNumber: serialNumber,
12026 Subject: pkix.Name{
12027 Organization: []string{"Acme Co"},
12028 },
12029 NotBefore: time.Now(),
12030 NotAfter: time.Now(),
12031
12032 // An ECC certificate with only the keyAgreement key usgae may
12033 // be used with ECDH, but not ECDSA.
12034 KeyUsage: x509.KeyUsageKeyAgreement,
12035 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12036 BasicConstraintsValid: true,
12037 }
12038
12039 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12040 if err != nil {
12041 panic(err)
12042 }
12043
12044 cert := Certificate{
12045 Certificate: [][]byte{derBytes},
12046 PrivateKey: priv,
12047 }
12048
12049 for _, ver := range tlsVersions {
12050 if ver.version < VersionTLS12 {
12051 continue
12052 }
12053
12054 testCases = append(testCases, testCase{
12055 testType: clientTest,
12056 name: "ECDSAKeyUsage-" + ver.name,
12057 config: Config{
12058 MinVersion: ver.version,
12059 MaxVersion: ver.version,
12060 Certificates: []Certificate{cert},
12061 },
David Benjamina5022392017-07-10 17:40:39 -040012062 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012063 shouldFail: true,
12064 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12065 })
12066 }
12067}
12068
David Benjamin8c26d752017-03-26 15:13:51 -050012069func addExtraHandshakeTests() {
12070 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12071 // to ensure there is no transport I/O.
12072 testCases = append(testCases, testCase{
12073 testType: clientTest,
12074 name: "ExtraHandshake-Client-TLS12",
12075 config: Config{
12076 MinVersion: VersionTLS12,
12077 MaxVersion: VersionTLS12,
12078 },
12079 flags: []string{
12080 "-async",
12081 "-no-op-extra-handshake",
12082 },
12083 })
12084 testCases = append(testCases, testCase{
12085 testType: serverTest,
12086 name: "ExtraHandshake-Server-TLS12",
12087 config: Config{
12088 MinVersion: VersionTLS12,
12089 MaxVersion: VersionTLS12,
12090 },
12091 flags: []string{
12092 "-async",
12093 "-no-op-extra-handshake",
12094 },
12095 })
12096 testCases = append(testCases, testCase{
12097 testType: clientTest,
12098 name: "ExtraHandshake-Client-TLS13",
12099 config: Config{
12100 MinVersion: VersionTLS13,
12101 MaxVersion: VersionTLS13,
12102 },
12103 flags: []string{
12104 "-async",
12105 "-no-op-extra-handshake",
12106 },
12107 })
12108 testCases = append(testCases, testCase{
12109 testType: serverTest,
12110 name: "ExtraHandshake-Server-TLS13",
12111 config: Config{
12112 MinVersion: VersionTLS13,
12113 MaxVersion: VersionTLS13,
12114 },
12115 flags: []string{
12116 "-async",
12117 "-no-op-extra-handshake",
12118 },
12119 })
12120
12121 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12122 testCases = append(testCases, testCase{
12123 testType: serverTest,
12124 name: "ExtraHandshake-Server-EarlyData-TLS13",
12125 config: Config{
12126 MaxVersion: VersionTLS13,
12127 MinVersion: VersionTLS13,
12128 Bugs: ProtocolBugs{
12129 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12130 ExpectEarlyDataAccepted: true,
12131 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12132 },
12133 },
12134 messageCount: 2,
12135 resumeSession: true,
12136 flags: []string{
12137 "-async",
12138 "-enable-early-data",
12139 "-expect-accept-early-data",
12140 "-no-op-extra-handshake",
12141 },
12142 })
12143
12144 // An extra SSL_do_handshake drives the handshake to completion in False
12145 // Start. We test this by handshaking twice and asserting the False
12146 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12147 // how the test works.
12148 testCases = append(testCases, testCase{
12149 testType: clientTest,
12150 name: "ExtraHandshake-FalseStart",
12151 config: Config{
12152 MaxVersion: VersionTLS12,
12153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12154 NextProtos: []string{"foo"},
12155 Bugs: ProtocolBugs{
12156 ExpectFalseStart: true,
12157 AlertBeforeFalseStartTest: alertAccessDenied,
12158 },
12159 },
12160 flags: []string{
12161 "-handshake-twice",
12162 "-false-start",
12163 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012164 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012165 },
12166 shimWritesFirst: true,
12167 shouldFail: true,
12168 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12169 expectedLocalError: "tls: peer did not false start: EOF",
12170 })
12171}
12172
David Benjaminb853f312017-07-14 18:40:34 -040012173// Test that omitted and empty extensions blocks are tolerated.
12174func addOmitExtensionsTests() {
12175 for _, ver := range tlsVersions {
12176 if ver.version > VersionTLS12 {
12177 continue
12178 }
12179
12180 testCases = append(testCases, testCase{
12181 testType: serverTest,
12182 name: "OmitExtensions-ClientHello-" + ver.name,
12183 config: Config{
12184 MinVersion: ver.version,
12185 MaxVersion: ver.version,
12186 SessionTicketsDisabled: true,
12187 Bugs: ProtocolBugs{
12188 OmitExtensions: true,
12189 },
12190 },
12191 })
12192
12193 testCases = append(testCases, testCase{
12194 testType: serverTest,
12195 name: "EmptyExtensions-ClientHello-" + ver.name,
12196 config: Config{
12197 MinVersion: ver.version,
12198 MaxVersion: ver.version,
12199 SessionTicketsDisabled: true,
12200 Bugs: ProtocolBugs{
12201 EmptyExtensions: true,
12202 },
12203 },
12204 })
12205
12206 testCases = append(testCases, testCase{
12207 testType: clientTest,
12208 name: "OmitExtensions-ServerHello-" + ver.name,
12209 config: Config{
12210 MinVersion: ver.version,
12211 MaxVersion: ver.version,
12212 SessionTicketsDisabled: true,
12213 Bugs: ProtocolBugs{
12214 OmitExtensions: true,
12215 // Disable all ServerHello extensions so
12216 // OmitExtensions works.
12217 NoExtendedMasterSecret: true,
12218 NoRenegotiationInfo: true,
12219 },
12220 },
12221 })
12222
12223 testCases = append(testCases, testCase{
12224 testType: clientTest,
12225 name: "EmptyExtensions-ServerHello-" + ver.name,
12226 config: Config{
12227 MinVersion: ver.version,
12228 MaxVersion: ver.version,
12229 SessionTicketsDisabled: true,
12230 Bugs: ProtocolBugs{
12231 EmptyExtensions: true,
12232 // Disable all ServerHello extensions so
12233 // EmptyExtensions works.
12234 NoExtendedMasterSecret: true,
12235 NoRenegotiationInfo: true,
12236 },
12237 },
12238 })
12239 }
12240}
12241
Adam Langley7c803a62015-06-15 15:35:05 -070012242func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012243 defer wg.Done()
12244
12245 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012246 var err error
12247
David Benjaminba28dfc2016-11-15 17:47:21 +090012248 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012249 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12250 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012251 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012252 if err != nil {
12253 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12254 }
12255 break
12256 }
12257 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012258 } else if *repeatUntilFailure {
12259 for err == nil {
12260 statusChan <- statusMsg{test: test, started: true}
12261 err = runTest(test, shimPath, -1)
12262 }
12263 } else {
12264 statusChan <- statusMsg{test: test, started: true}
12265 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012266 }
Adam Langley95c29f32014-06-20 12:00:00 -070012267 statusChan <- statusMsg{test: test, err: err}
12268 }
12269}
12270
12271type statusMsg struct {
12272 test *testCase
12273 started bool
12274 err error
12275}
12276
David Benjamin5f237bc2015-02-11 17:14:15 -050012277func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012278 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012279
David Benjamin5f237bc2015-02-11 17:14:15 -050012280 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012281 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012282 if !*pipe {
12283 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012284 var erase string
12285 for i := 0; i < lineLen; i++ {
12286 erase += "\b \b"
12287 }
12288 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012289 }
12290
Adam Langley95c29f32014-06-20 12:00:00 -070012291 if msg.started {
12292 started++
12293 } else {
12294 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012295
12296 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012297 if msg.err == errUnimplemented {
12298 if *pipe {
12299 // Print each test instead of a status line.
12300 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12301 }
12302 unimplemented++
12303 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12304 } else {
12305 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12306 failed++
12307 testOutput.addResult(msg.test.name, "FAIL")
12308 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012309 } else {
12310 if *pipe {
12311 // Print each test instead of a status line.
12312 fmt.Printf("PASSED (%s)\n", msg.test.name)
12313 }
12314 testOutput.addResult(msg.test.name, "PASS")
12315 }
Adam Langley95c29f32014-06-20 12:00:00 -070012316 }
12317
David Benjamin5f237bc2015-02-11 17:14:15 -050012318 if !*pipe {
12319 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012320 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012321 lineLen = len(line)
12322 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012323 }
Adam Langley95c29f32014-06-20 12:00:00 -070012324 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012325
12326 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012327}
12328
12329func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012330 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012331 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012332 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012333
Adam Langley7c803a62015-06-15 15:35:05 -070012334 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012335 addCipherSuiteTests()
12336 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012337 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012338 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012339 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012340 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012341 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012342 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012343 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012344 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012345 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012346 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012347 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012348 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012349 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012350 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012351 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012352 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012353 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012354 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012355 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012356 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012357 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012358 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012359 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012360 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012361 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012362 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012363 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012364 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012365 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012366 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012367 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012368 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012369 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012370
12371 var wg sync.WaitGroup
12372
Adam Langley7c803a62015-06-15 15:35:05 -070012373 statusChan := make(chan statusMsg, *numWorkers)
12374 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012375 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012376
EKRf71d7ed2016-08-06 13:25:12 -070012377 if len(*shimConfigFile) != 0 {
12378 encoded, err := ioutil.ReadFile(*shimConfigFile)
12379 if err != nil {
12380 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12381 os.Exit(1)
12382 }
12383
12384 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12385 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12386 os.Exit(1)
12387 }
12388 }
12389
David Benjamin025b3d32014-07-01 19:53:04 -040012390 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012391
Adam Langley7c803a62015-06-15 15:35:05 -070012392 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012393 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012394 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012395 }
12396
David Benjamin270f0a72016-03-17 14:41:36 -040012397 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012398 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012399 matched := true
12400 if len(*testToRun) != 0 {
12401 var err error
12402 matched, err = filepath.Match(*testToRun, testCases[i].name)
12403 if err != nil {
12404 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12405 os.Exit(1)
12406 }
12407 }
12408
EKRf71d7ed2016-08-06 13:25:12 -070012409 if !*includeDisabled {
12410 for pattern := range shimConfig.DisabledTests {
12411 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12412 if err != nil {
12413 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12414 os.Exit(1)
12415 }
12416
12417 if isDisabled {
12418 matched = false
12419 break
12420 }
12421 }
12422 }
12423
David Benjamin17e12922016-07-28 18:04:43 -040012424 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012425 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012426 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012427
12428 // Only run one test if repeating until failure.
12429 if *repeatUntilFailure {
12430 break
12431 }
Adam Langley95c29f32014-06-20 12:00:00 -070012432 }
12433 }
David Benjamin17e12922016-07-28 18:04:43 -040012434
David Benjamin270f0a72016-03-17 14:41:36 -040012435 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012436 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012437 os.Exit(1)
12438 }
Adam Langley95c29f32014-06-20 12:00:00 -070012439
12440 close(testChan)
12441 wg.Wait()
12442 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012443 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012444
12445 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012446
12447 if *jsonOutput != "" {
12448 if err := testOutput.writeTo(*jsonOutput); err != nil {
12449 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12450 }
12451 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012452
EKR842ae6c2016-07-27 09:22:05 +020012453 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12454 os.Exit(1)
12455 }
12456
12457 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012458 os.Exit(1)
12459 }
Adam Langley95c29f32014-06-20 12:00:00 -070012460}