blob: a0f5a9c712f126f3ca7f9c3e5cbd3fd0313f059c [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700491 if !*useGDB {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
David Benjamin3ed59772016-03-08 12:50:21 -0500495 }
496 return t.Conn.Read(b)
497}
498
499func (t *timeoutConn) Write(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700500 if !*useGDB {
501 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
502 return 0, err
503 }
David Benjamin3ed59772016-03-08 12:50:21 -0500504 }
505 return t.Conn.Write(b)
506}
507
David Benjamin0fde2eb2017-06-30 19:11:22 -0400508func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400509 if !test.noSessionCache {
510 if config.ClientSessionCache == nil {
511 config.ClientSessionCache = NewLRUClientSessionCache(1)
512 }
513 if config.ServerSessionCache == nil {
514 config.ServerSessionCache = NewLRUServerSessionCache(1)
515 }
516 }
517 if test.testType == clientTest {
518 if len(config.Certificates) == 0 {
519 config.Certificates = []Certificate{rsaCertificate}
520 }
521 } else {
522 // Supply a ServerName to ensure a constant session cache key,
523 // rather than falling back to net.Conn.RemoteAddr.
524 if len(config.ServerName) == 0 {
525 config.ServerName = "test"
526 }
527 }
528 if *fuzzer {
529 config.Bugs.NullAllCiphers = true
530 }
David Benjamin01a90572016-09-22 00:11:43 -0400531 if *deterministic {
532 config.Time = func() time.Time { return time.Unix(1234, 1234) }
533 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400534 if test.tls13Variant != 0 {
535 config.TLS13Variant = test.tls13Variant
536 }
David Benjamine54af062016-08-08 19:21:18 -0400537
David Benjamin01784b42016-06-07 18:00:52 -0400538 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500539
David Benjamin6fd297b2014-08-11 18:43:38 -0400540 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500541 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
542 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500543 }
544
David Benjamin9867b7d2016-03-01 23:25:48 -0500545 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500546 local, peer := "client", "server"
547 if test.testType == clientTest {
548 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500549 }
David Benjaminebda9b32015-11-02 15:33:18 -0500550 connDebug := &recordingConn{
551 Conn: conn,
552 isDatagram: test.protocol == dtls,
553 local: local,
554 peer: peer,
555 }
556 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 if *flagDebug {
558 defer connDebug.WriteTo(os.Stdout)
559 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400560 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500561 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400562 path := transcriptPrefix + strconv.Itoa(num)
563 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500564 }()
565 }
David Benjaminebda9b32015-11-02 15:33:18 -0500566
567 if config.Bugs.PacketAdaptor != nil {
568 config.Bugs.PacketAdaptor.debug = connDebug
569 }
570 }
571
572 if test.replayWrites {
573 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400574 }
575
David Benjamin3ed59772016-03-08 12:50:21 -0500576 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500577 if test.damageFirstWrite {
578 connDamage = newDamageAdaptor(conn)
579 conn = connDamage
580 }
581
David Benjamin6fd297b2014-08-11 18:43:38 -0400582 if test.sendPrefix != "" {
583 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
584 return err
585 }
David Benjamin98e882e2014-08-08 13:24:34 -0400586 }
587
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400589 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSServer(conn, config)
592 } else {
593 tlsConn = Server(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 } else {
596 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400597 if test.protocol == dtls {
598 tlsConn = DTLSClient(conn, config)
599 } else {
600 tlsConn = Client(conn, config)
601 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400602 }
David Benjamin30789da2015-08-29 22:56:45 -0400603 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400604
Adam Langley95c29f32014-06-20 12:00:00 -0700605 if err := tlsConn.Handshake(); err != nil {
606 return err
607 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700608
David Benjamin01fe8202014-09-24 15:21:44 -0400609 // TODO(davidben): move all per-connection expectations into a dedicated
610 // expectations struct that can be specified separately for the two
611 // legs.
612 expectedVersion := test.expectedVersion
613 if isResume && test.expectedResumeVersion != 0 {
614 expectedVersion = test.expectedResumeVersion
615 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700616 connState := tlsConn.ConnectionState()
617 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400618 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400619 }
620
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700621 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400622 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
623 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700624 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
625 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
626 }
David Benjamin90da8c82015-04-20 14:57:57 -0400627
David Benjamina08e49d2014-08-24 01:46:07 -0400628 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700629 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400630 if channelID == nil {
631 return fmt.Errorf("no channel ID negotiated")
632 }
633 if channelID.Curve != channelIDKey.Curve ||
634 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
635 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
636 return fmt.Errorf("incorrect channel ID")
637 }
David Benjamin634f4752017-07-01 11:08:41 -0400638 } else if connState.ChannelID != nil {
639 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400640 }
641
David Benjaminae2888f2014-09-06 12:58:58 -0400642 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700643 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400644 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
645 }
646 }
647
David Benjaminc7ce9772015-10-09 19:32:41 -0400648 if test.expectNoNextProto {
649 if actual := connState.NegotiatedProtocol; actual != "" {
650 return fmt.Errorf("got unexpected next proto %s", actual)
651 }
652 }
653
David Benjaminfc7b0862014-09-06 13:21:53 -0400654 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700655 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400656 return fmt.Errorf("next proto type mismatch")
657 }
658 }
659
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700660 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500661 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
662 }
663
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100664 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300665 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100666 }
667
Paul Lietar4fac72e2015-09-09 13:44:55 +0100668 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
669 return fmt.Errorf("SCT list mismatch")
670 }
671
Nick Harper60edffd2016-06-21 15:19:24 -0700672 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
673 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400674 }
675
Steven Valdez5440fe02016-07-18 12:40:30 -0400676 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
677 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
678 }
679
David Benjamin2c516452016-11-15 10:16:54 +0900680 if test.expectPeerCertificate != nil {
681 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
682 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
683 }
684 for i, cert := range connState.PeerCertificates {
685 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
686 return fmt.Errorf("peer certificate %d did not match", i+1)
687 }
688 }
689 }
690
David Benjaminc565ebb2015-04-03 04:06:36 -0400691 if test.exportKeyingMaterial > 0 {
692 actual := make([]byte, test.exportKeyingMaterial)
693 if _, err := io.ReadFull(tlsConn, actual); err != nil {
694 return err
695 }
696 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
697 if err != nil {
698 return err
699 }
700 if !bytes.Equal(actual, expected) {
701 return fmt.Errorf("keying material mismatch")
702 }
703 }
704
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700705 if test.testTLSUnique {
706 var peersValue [12]byte
707 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
708 return err
709 }
710 expected := tlsConn.ConnectionState().TLSUnique
711 if !bytes.Equal(peersValue[:], expected) {
712 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
713 }
714 }
715
David Benjamin47921102016-07-28 11:29:18 -0400716 if test.sendHalfHelloRequest {
717 tlsConn.SendHalfHelloRequest()
718 }
719
Steven Valdeze831a812017-03-09 14:56:07 -0500720 shimPrefix := test.shimPrefix
721 if isResume {
722 shimPrefix = test.resumeShimPrefix
723 }
724 if test.shimWritesFirst || test.readWithUnfinishedWrite {
725 shimPrefix = "hello"
726 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400727 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400728 // If readWithUnfinishedWrite is set, the shim prefix will be
729 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500730 if shimPrefix != "" && !test.readWithUnfinishedWrite {
731 var buf = make([]byte, len(shimPrefix))
732 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400733 if err != nil {
734 return err
735 }
Steven Valdeze831a812017-03-09 14:56:07 -0500736 if string(buf) != shimPrefix {
737 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400738 }
Steven Valdeze831a812017-03-09 14:56:07 -0500739 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400740 }
741
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 if test.renegotiateCiphers != nil {
743 config.CipherSuites = test.renegotiateCiphers
744 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400745 for i := 0; i < test.renegotiate; i++ {
746 if err := tlsConn.Renegotiate(); err != nil {
747 return err
748 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700749 }
750 } else if test.renegotiateCiphers != nil {
751 panic("renegotiateCiphers without renegotiate")
752 }
753
David Benjamin5fa3eba2015-01-22 16:35:40 -0500754 if test.damageFirstWrite {
755 connDamage.setDamage(true)
756 tlsConn.Write([]byte("DAMAGED WRITE"))
757 connDamage.setDamage(false)
758 }
759
David Benjamin8e6db492015-07-25 18:29:23 -0400760 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700761 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400762 if test.protocol == dtls {
763 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
764 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700765 // Read until EOF.
766 _, err := io.Copy(ioutil.Discard, tlsConn)
767 return err
768 }
David Benjamin4417d052015-04-05 04:17:25 -0400769 if messageLen == 0 {
770 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700771 }
Adam Langley95c29f32014-06-20 12:00:00 -0700772
David Benjamin8e6db492015-07-25 18:29:23 -0400773 messageCount := test.messageCount
774 if messageCount == 0 {
775 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400776 }
777
David Benjamin8e6db492015-07-25 18:29:23 -0400778 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400779 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400780 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400781 }
782
David Benjamin8e6db492015-07-25 18:29:23 -0400783 for i := 0; i < test.sendEmptyRecords; i++ {
784 tlsConn.Write(nil)
785 }
786
787 for i := 0; i < test.sendWarningAlerts; i++ {
788 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
789 }
790
David Benjamin24e58862017-06-14 18:45:29 -0400791 if test.sendBogusAlertType {
792 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
793 }
794
David Benjaminbbba9392017-04-06 12:54:12 -0400795 testMessage := make([]byte, messageLen)
796 for i := range testMessage {
797 testMessage[i] = 0x42 ^ byte(j)
798 }
799 tlsConn.Write(testMessage)
800
801 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500802 if shimPrefix != "" {
803 var buf = make([]byte, len(shimPrefix))
804 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400805 if err != nil {
806 return err
807 }
Steven Valdeze831a812017-03-09 14:56:07 -0500808 if string(buf) != shimPrefix {
809 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400810 }
Steven Valdeze831a812017-03-09 14:56:07 -0500811 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400812 }
813
David Benjamin4f75aaf2015-09-01 16:53:10 -0400814 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400815 // The shim will not respond.
816 continue
817 }
818
David Benjaminbbba9392017-04-06 12:54:12 -0400819 // Process the KeyUpdate ACK. However many KeyUpdates the runner
820 // sends, the shim should respond only once.
821 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
822 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
823 return err
824 }
825 }
826
David Benjamin8e6db492015-07-25 18:29:23 -0400827 buf := make([]byte, len(testMessage))
828 if test.protocol == dtls {
829 bufTmp := make([]byte, len(buf)+1)
830 n, err := tlsConn.Read(bufTmp)
831 if err != nil {
832 return err
833 }
834 if n != len(buf) {
835 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
836 }
837 copy(buf, bufTmp)
838 } else {
839 _, err := io.ReadFull(tlsConn, buf)
840 if err != nil {
841 return err
842 }
843 }
844
845 for i, v := range buf {
846 if v != testMessage[i]^0xff {
847 return fmt.Errorf("bad reply contents at byte %d", i)
848 }
Adam Langley95c29f32014-06-20 12:00:00 -0700849 }
850 }
851
852 return nil
853}
854
David Benjamin325b5c32014-07-01 19:40:31 -0400855func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400856 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700857 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400858 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700859 }
David Benjamin325b5c32014-07-01 19:40:31 -0400860 valgrindArgs = append(valgrindArgs, path)
861 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamin325b5c32014-07-01 19:40:31 -0400866func gdbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "gdb", "--args"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700870
David Benjamin325b5c32014-07-01 19:40:31 -0400871 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700872}
873
David Benjamind16bf342015-12-18 00:53:12 -0500874func lldbOf(path string, args ...string) *exec.Cmd {
875 xtermArgs := []string{"-e", "lldb", "--"}
876 xtermArgs = append(xtermArgs, path)
877 xtermArgs = append(xtermArgs, args...)
878
879 return exec.Command("xterm", xtermArgs...)
880}
881
EKR842ae6c2016-07-27 09:22:05 +0200882var (
883 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
884 errUnimplemented = errors.New("child process does not implement needed flags")
885)
Adam Langley69a01602014-11-17 17:26:55 -0800886
David Benjamin87c8a642015-02-21 01:54:29 -0500887// accept accepts a connection from listener, unless waitChan signals a process
888// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400889func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500890 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400891 conn net.Conn
892 err error
893 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500894 }
895 connChan := make(chan connOrError, 1)
896 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400897 startTime := time.Now()
Adam Langley182b5732017-07-28 11:00:23 -0700898 if !*useGDB {
899 listener.SetDeadline(time.Now().Add(*idleTimeout))
900 }
David Benjamin87c8a642015-02-21 01:54:29 -0500901 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400902 endTime := time.Now()
903 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500904 close(connChan)
905 }()
906 select {
907 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400908 if result.err != nil {
909 // TODO(davidben): Remove this logging when
910 // https://crbug.com/boringssl/199 is resolved.
911 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
912 }
David Benjamin87c8a642015-02-21 01:54:29 -0500913 return result.conn, result.err
914 case childErr := <-waitChan:
915 waitChan <- childErr
916 return nil, fmt.Errorf("child exited early: %s", childErr)
917 }
918}
919
EKRf71d7ed2016-08-06 13:25:12 -0700920func translateExpectedError(errorStr string) string {
921 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
922 return translated
923 }
924
925 if *looseErrors {
926 return ""
927 }
928
929 return errorStr
930}
931
Adam Langley7c803a62015-06-15 15:35:05 -0700932func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400933 // Help debugging panics on the Go side.
934 defer func() {
935 if r := recover(); r != nil {
936 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
937 panic(r)
938 }
939 }()
940
Adam Langley38311732014-10-16 19:04:35 -0700941 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
942 panic("Error expected without shouldFail in " + test.name)
943 }
944
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700945 if test.expectResumeRejected && !test.resumeSession {
946 panic("expectResumeRejected without resumeSession in " + test.name)
947 }
948
Adam Langley33b1d4f2016-12-07 15:03:45 -0800949 for _, ver := range tlsVersions {
950 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
951 continue
952 }
953
David Benjamina5022392017-07-10 17:40:39 -0400954 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
955 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
Adam Langley33b1d4f2016-12-07 15:03:45 -0800956 }
957
David Benjamina5022392017-07-10 17:40:39 -0400958 if ver.tls13Variant != 0 {
959 var foundFlag bool
960 for _, flag := range test.flags {
961 if flag == "-tls13-variant" {
962 foundFlag = true
963 break
964 }
965 }
966 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
967 panic(fmt.Sprintf("The name of test %q suggests that uses an experimental TLS 1.3 variant, but neither the shim nor the runner configures it", test.name))
968 }
969 }
970
Adam Langley33b1d4f2016-12-07 15:03:45 -0800971 }
972
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700973 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
974 if err != nil {
975 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
976 }
David Benjamin87c8a642015-02-21 01:54:29 -0500977 if err != nil {
978 panic(err)
979 }
980 defer func() {
981 if listener != nil {
982 listener.Close()
983 }
984 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700985
David Benjamin87c8a642015-02-21 01:54:29 -0500986 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400987 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400988 flags = append(flags, "-server")
989
David Benjamin025b3d32014-07-01 19:53:04 -0400990 flags = append(flags, "-key-file")
991 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700992 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400993 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700994 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400995 }
996
997 flags = append(flags, "-cert-file")
998 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700999 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001000 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001001 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001002 }
1003 }
David Benjamin5a593af2014-08-11 19:51:50 -04001004
David Benjamin6fd297b2014-08-11 18:43:38 -04001005 if test.protocol == dtls {
1006 flags = append(flags, "-dtls")
1007 }
1008
David Benjamin46662482016-08-17 00:51:00 -04001009 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001010 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001011 resumeCount++
1012 if test.resumeRenewedSession {
1013 resumeCount++
1014 }
1015 }
1016
1017 if resumeCount > 0 {
1018 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001019 }
1020
David Benjamine58c4f52014-08-24 03:47:07 -04001021 if test.shimWritesFirst {
1022 flags = append(flags, "-shim-writes-first")
1023 }
1024
David Benjaminbbba9392017-04-06 12:54:12 -04001025 if test.readWithUnfinishedWrite {
1026 flags = append(flags, "-read-with-unfinished-write")
1027 }
1028
David Benjamin30789da2015-08-29 22:56:45 -04001029 if test.shimShutsDown {
1030 flags = append(flags, "-shim-shuts-down")
1031 }
1032
David Benjaminc565ebb2015-04-03 04:06:36 -04001033 if test.exportKeyingMaterial > 0 {
1034 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1035 flags = append(flags, "-export-label", test.exportLabel)
1036 flags = append(flags, "-export-context", test.exportContext)
1037 if test.useExportContext {
1038 flags = append(flags, "-use-export-context")
1039 }
1040 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001041 if test.expectResumeRejected {
1042 flags = append(flags, "-expect-session-miss")
1043 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001044
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001045 if test.testTLSUnique {
1046 flags = append(flags, "-tls-unique")
1047 }
1048
David Benjamina5022392017-07-10 17:40:39 -04001049 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001050 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1051 }
1052
David Benjamin0fde2eb2017-06-30 19:11:22 -04001053 var transcriptPrefix string
1054 if len(*transcriptDir) != 0 {
1055 protocol := "tls"
1056 if test.protocol == dtls {
1057 protocol = "dtls"
1058 }
1059
1060 side := "client"
1061 if test.testType == serverTest {
1062 side = "server"
1063 }
1064
1065 dir := filepath.Join(*transcriptDir, protocol, side)
1066 if err := os.MkdirAll(dir, 0755); err != nil {
1067 return err
1068 }
1069 transcriptPrefix = filepath.Join(dir, test.name+"-")
1070 flags = append(flags, "-write-settings", transcriptPrefix)
1071 }
1072
David Benjamin025b3d32014-07-01 19:53:04 -04001073 flags = append(flags, test.flags...)
1074
1075 var shim *exec.Cmd
1076 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001077 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001078 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001079 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001080 } else if *useLLDB {
1081 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001082 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001083 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001084 }
David Benjamin025b3d32014-07-01 19:53:04 -04001085 shim.Stdin = os.Stdin
1086 var stdoutBuf, stderrBuf bytes.Buffer
1087 shim.Stdout = &stdoutBuf
1088 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001089 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001090 shim.Env = os.Environ()
1091 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001092 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001093 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001094 }
1095 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1096 }
David Benjamin025b3d32014-07-01 19:53:04 -04001097
1098 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001099 panic(err)
1100 }
David Benjamin87c8a642015-02-21 01:54:29 -05001101 waitChan := make(chan error, 1)
1102 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001103
1104 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001105
David Benjamin7a4aaa42016-09-20 17:58:14 -04001106 if *deterministic {
1107 config.Rand = &deterministicRand{}
1108 }
1109
David Benjamin87c8a642015-02-21 01:54:29 -05001110 conn, err := acceptOrWait(listener, waitChan)
1111 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001112 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001113 conn.Close()
1114 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001115
David Benjamin46662482016-08-17 00:51:00 -04001116 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001117 var resumeConfig Config
1118 if test.resumeConfig != nil {
1119 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001120 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001121 resumeConfig.SessionTicketKey = config.SessionTicketKey
1122 resumeConfig.ClientSessionCache = config.ClientSessionCache
1123 resumeConfig.ServerSessionCache = config.ServerSessionCache
1124 }
David Benjamin2e045a92016-06-08 13:09:56 -04001125 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001126 } else {
1127 resumeConfig = config
1128 }
David Benjamin87c8a642015-02-21 01:54:29 -05001129 var connResume net.Conn
1130 connResume, err = acceptOrWait(listener, waitChan)
1131 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001132 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001133 connResume.Close()
1134 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001135 }
1136
David Benjamin87c8a642015-02-21 01:54:29 -05001137 // Close the listener now. This is to avoid hangs should the shim try to
1138 // open more connections than expected.
1139 listener.Close()
1140 listener = nil
1141
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001142 var shimKilledLock sync.Mutex
1143 var shimKilled bool
1144 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1145 shimKilledLock.Lock()
1146 shimKilled = true
1147 shimKilledLock.Unlock()
1148 shim.Process.Kill()
1149 })
David Benjamin87c8a642015-02-21 01:54:29 -05001150 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001151 waitTimeout.Stop()
1152 shimKilledLock.Lock()
1153 if shimKilled && err == nil {
1154 err = errors.New("timeout waiting for the shim to exit.")
1155 }
1156 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001157 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001158 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001159 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1160 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001161 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001162 case 89:
1163 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001164 case 99:
1165 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001166 }
1167 }
Adam Langley95c29f32014-06-20 12:00:00 -07001168
David Benjamin9bea3492016-03-02 10:59:16 -05001169 // Account for Windows line endings.
1170 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1171 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001172
1173 // Separate the errors from the shim and those from tools like
1174 // AddressSanitizer.
1175 var extraStderr string
1176 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1177 stderr = stderrParts[0]
1178 extraStderr = stderrParts[1]
1179 }
1180
Adam Langley95c29f32014-06-20 12:00:00 -07001181 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001182 expectedError := translateExpectedError(test.expectedError)
1183 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001184
Adam Langleyac61fa32014-06-23 12:03:11 -07001185 localError := "none"
1186 if err != nil {
1187 localError = err.Error()
1188 }
1189 if len(test.expectedLocalError) != 0 {
1190 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1191 }
Adam Langley95c29f32014-06-20 12:00:00 -07001192
1193 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001194 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001195 if childErr != nil {
1196 childError = childErr.Error()
1197 }
1198
1199 var msg string
1200 switch {
1201 case failed && !test.shouldFail:
1202 msg = "unexpected failure"
1203 case !failed && test.shouldFail:
1204 msg = "unexpected success"
1205 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001206 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001207 default:
1208 panic("internal error")
1209 }
1210
David Benjamin9aafb642016-09-20 19:36:53 -04001211 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001212 }
1213
David Benjamind2ba8892016-09-20 19:41:04 -04001214 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001215 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001216 }
1217
David Benjamind2ba8892016-09-20 19:41:04 -04001218 if *useValgrind && isValgrindError {
1219 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1220 }
1221
Adam Langley95c29f32014-06-20 12:00:00 -07001222 return nil
1223}
1224
David Benjaminaa012042016-12-10 13:33:05 -05001225type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001226 name string
1227 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001228 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001229 // excludeFlag is the legacy shim flag to disable the version.
1230 excludeFlag string
1231 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001232 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1233 versionDTLS uint16
1234 // versionWire, if non-zero, is the wire representation of the
1235 // version. Otherwise the wire version is the protocol version or
1236 // versionDTLS.
1237 versionWire uint16
1238 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001239}
1240
1241func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001242 // The shim uses the protocol version in its public API, but uses the
1243 // DTLS-specific version if it exists.
1244 if protocol == dtls && vers.versionDTLS != 0 {
1245 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001246 }
Steven Valdez520e1222017-06-13 12:45:25 -04001247 return strconv.Itoa(int(vers.version))
1248}
1249
1250func (vers tlsVersion) wire(protocol protocol) uint16 {
1251 if protocol == dtls && vers.versionDTLS != 0 {
1252 return vers.versionDTLS
1253 }
1254 if vers.versionWire != 0 {
1255 return vers.versionWire
1256 }
1257 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001258}
1259
1260var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001261 {
1262 name: "SSL3",
1263 version: VersionSSL30,
1264 excludeFlag: "-no-ssl3",
1265 },
1266 {
1267 name: "TLS1",
1268 version: VersionTLS10,
1269 excludeFlag: "-no-tls1",
1270 hasDTLS: true,
1271 versionDTLS: VersionDTLS10,
1272 },
1273 {
1274 name: "TLS11",
1275 version: VersionTLS11,
1276 excludeFlag: "-no-tls11",
1277 },
1278 {
1279 name: "TLS12",
1280 version: VersionTLS12,
1281 excludeFlag: "-no-tls12",
1282 hasDTLS: true,
1283 versionDTLS: VersionDTLS12,
1284 },
1285 {
1286 name: "TLS13",
1287 version: VersionTLS13,
1288 excludeFlag: "-no-tls13",
1289 versionWire: tls13DraftVersion,
1290 tls13Variant: TLS13Default,
1291 },
1292 {
1293 name: "TLS13Experiment",
1294 version: VersionTLS13,
1295 excludeFlag: "-no-tls13",
1296 versionWire: tls13ExperimentVersion,
1297 tls13Variant: TLS13Experiment,
1298 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001299 {
1300 name: "TLS13RecordTypeExperiment",
1301 version: VersionTLS13,
1302 excludeFlag: "-no-tls13",
1303 versionWire: tls13RecordTypeExperimentVersion,
1304 tls13Variant: TLS13RecordTypeExperiment,
1305 },
Steven Valdez520e1222017-06-13 12:45:25 -04001306}
1307
1308func allVersions(protocol protocol) []tlsVersion {
1309 if protocol == tls {
1310 return tlsVersions
1311 }
1312
1313 var ret []tlsVersion
1314 for _, vers := range tlsVersions {
1315 if vers.hasDTLS {
1316 ret = append(ret, vers)
1317 }
1318 }
1319 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001320}
1321
David Benjaminaa012042016-12-10 13:33:05 -05001322type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001323 name string
1324 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001325}
1326
1327var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001328 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001329 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001330 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001332 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001333 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001334 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001335 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1336 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001337 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1338 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001339 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001340 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001341 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001342 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001343 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001344 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001345 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001346 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001347 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001348 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001349 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1350 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001351 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1352 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001353 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001354 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1355 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1356 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001357 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001358}
1359
David Benjamin8b8c0062014-11-23 02:47:52 -05001360func hasComponent(suiteName, component string) bool {
1361 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1362}
1363
David Benjaminf7768e42014-08-31 02:06:47 -04001364func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001365 return hasComponent(suiteName, "GCM") ||
1366 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001367 hasComponent(suiteName, "SHA384") ||
1368 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001369}
1370
Nick Harper1fd39d82016-06-14 18:14:35 -07001371func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001372 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001373}
1374
David Benjamin8b8c0062014-11-23 02:47:52 -05001375func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001376 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001377}
1378
Adam Langleya7997f12015-05-14 17:38:50 -07001379func bigFromHex(hex string) *big.Int {
1380 ret, ok := new(big.Int).SetString(hex, 16)
1381 if !ok {
1382 panic("failed to parse hex number 0x" + hex)
1383 }
1384 return ret
1385}
1386
Adam Langley7c803a62015-06-15 15:35:05 -07001387func addBasicTests() {
1388 basicTests := []testCase{
1389 {
Adam Langley7c803a62015-06-15 15:35:05 -07001390 name: "NoFallbackSCSV",
1391 config: Config{
1392 Bugs: ProtocolBugs{
1393 FailIfNotFallbackSCSV: true,
1394 },
1395 },
1396 shouldFail: true,
1397 expectedLocalError: "no fallback SCSV found",
1398 },
1399 {
1400 name: "SendFallbackSCSV",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 FailIfNotFallbackSCSV: true,
1404 },
1405 },
1406 flags: []string{"-fallback-scsv"},
1407 },
1408 {
1409 name: "ClientCertificateTypes",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 ClientAuth: RequestClientCert,
1413 ClientCertificateTypes: []byte{
1414 CertTypeDSSSign,
1415 CertTypeRSASign,
1416 CertTypeECDSASign,
1417 },
1418 },
1419 flags: []string{
1420 "-expect-certificate-types",
1421 base64.StdEncoding.EncodeToString([]byte{
1422 CertTypeDSSSign,
1423 CertTypeRSASign,
1424 CertTypeECDSASign,
1425 }),
1426 },
1427 },
1428 {
Adam Langley7c803a62015-06-15 15:35:05 -07001429 name: "UnauthenticatedECDH",
1430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001431 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001432 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1433 Bugs: ProtocolBugs{
1434 UnauthenticatedECDH: true,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":UNEXPECTED_MESSAGE:",
1439 },
1440 {
1441 name: "SkipCertificateStatus",
1442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001443 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Bugs: ProtocolBugs{
1446 SkipCertificateStatus: true,
1447 },
1448 },
1449 flags: []string{
1450 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001451 // This test involves an optional message. Test the message callback
1452 // trace to ensure we do not miss or double-report any.
1453 "-expect-msg-callback",
1454 `write hs 1
1455read hs 2
1456read hs 11
1457read hs 12
1458read hs 14
1459write hs 16
1460write ccs
1461write hs 20
1462read hs 4
1463read ccs
1464read hs 20
1465read alert 1 0
1466`,
1467 },
1468 },
1469 {
1470 protocol: dtls,
1471 name: "SkipCertificateStatus-DTLS",
1472 config: Config{
1473 MaxVersion: VersionTLS12,
1474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1475 Bugs: ProtocolBugs{
1476 SkipCertificateStatus: true,
1477 },
1478 },
1479 flags: []string{
1480 "-enable-ocsp-stapling",
1481 // This test involves an optional message. Test the message callback
1482 // trace to ensure we do not miss or double-report any.
1483 "-expect-msg-callback",
1484 `write hs 1
1485read hs 3
1486write hs 1
1487read hs 2
1488read hs 11
1489read hs 12
1490read hs 14
1491write hs 16
1492write ccs
1493write hs 20
1494read hs 4
1495read ccs
1496read hs 20
1497read alert 1 0
1498`,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 },
1500 },
1501 {
1502 name: "SkipServerKeyExchange",
1503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001504 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1506 Bugs: ProtocolBugs{
1507 SkipServerKeyExchange: true,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_MESSAGE:",
1512 },
1513 {
Adam Langley7c803a62015-06-15 15:35:05 -07001514 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001515 name: "ServerSkipCertificateVerify",
1516 config: Config{
1517 MaxVersion: VersionTLS12,
1518 Certificates: []Certificate{rsaChainCertificate},
1519 Bugs: ProtocolBugs{
1520 SkipCertificateVerify: true,
1521 },
1522 },
1523 expectPeerCertificate: &rsaChainCertificate,
1524 flags: []string{
1525 "-require-any-client-certificate",
1526 },
1527 shouldFail: true,
1528 expectedError: ":UNEXPECTED_RECORD:",
1529 expectedLocalError: "remote error: unexpected message",
1530 },
1531 {
1532 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 name: "Alert",
1534 config: Config{
1535 Bugs: ProtocolBugs{
1536 SendSpuriousAlert: alertRecordOverflow,
1537 },
1538 },
1539 shouldFail: true,
1540 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1541 },
1542 {
1543 protocol: dtls,
1544 testType: serverTest,
1545 name: "Alert-DTLS",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 SendSpuriousAlert: alertRecordOverflow,
1549 },
1550 },
1551 shouldFail: true,
1552 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1553 },
1554 {
1555 testType: serverTest,
1556 name: "FragmentAlert",
1557 config: Config{
1558 Bugs: ProtocolBugs{
1559 FragmentAlert: true,
1560 SendSpuriousAlert: alertRecordOverflow,
1561 },
1562 },
1563 shouldFail: true,
1564 expectedError: ":BAD_ALERT:",
1565 },
1566 {
1567 protocol: dtls,
1568 testType: serverTest,
1569 name: "FragmentAlert-DTLS",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 FragmentAlert: true,
1573 SendSpuriousAlert: alertRecordOverflow,
1574 },
1575 },
1576 shouldFail: true,
1577 expectedError: ":BAD_ALERT:",
1578 },
1579 {
1580 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001581 name: "DoubleAlert",
1582 config: Config{
1583 Bugs: ProtocolBugs{
1584 DoubleAlert: true,
1585 SendSpuriousAlert: alertRecordOverflow,
1586 },
1587 },
1588 shouldFail: true,
1589 expectedError: ":BAD_ALERT:",
1590 },
1591 {
1592 protocol: dtls,
1593 testType: serverTest,
1594 name: "DoubleAlert-DTLS",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 DoubleAlert: true,
1598 SendSpuriousAlert: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":BAD_ALERT:",
1603 },
1604 {
Adam Langley7c803a62015-06-15 15:35:05 -07001605 name: "SkipNewSessionTicket",
1606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001607 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001608 Bugs: ProtocolBugs{
1609 SkipNewSessionTicket: true,
1610 },
1611 },
1612 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001613 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001614 },
1615 {
1616 testType: serverTest,
1617 name: "FallbackSCSV",
1618 config: Config{
1619 MaxVersion: VersionTLS11,
1620 Bugs: ProtocolBugs{
1621 SendFallbackSCSV: true,
1622 },
1623 },
David Benjamin56cadc32016-12-16 19:54:11 -05001624 shouldFail: true,
1625 expectedError: ":INAPPROPRIATE_FALLBACK:",
1626 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001627 },
1628 {
1629 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001630 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001631 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001632 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 Bugs: ProtocolBugs{
1634 SendFallbackSCSV: true,
1635 },
1636 },
1637 },
1638 {
1639 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001640 name: "FallbackSCSV-VersionMatch-TLS12",
1641 config: Config{
1642 MaxVersion: VersionTLS12,
1643 Bugs: ProtocolBugs{
1644 SendFallbackSCSV: true,
1645 },
1646 },
1647 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1648 },
1649 {
1650 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001651 name: "FragmentedClientVersion",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 MaxHandshakeRecordLength: 1,
1655 FragmentClientVersion: true,
1656 },
1657 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001658 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001659 },
1660 {
Adam Langley7c803a62015-06-15 15:35:05 -07001661 testType: serverTest,
1662 name: "HttpGET",
1663 sendPrefix: "GET / HTTP/1.0\n",
1664 shouldFail: true,
1665 expectedError: ":HTTP_REQUEST:",
1666 },
1667 {
1668 testType: serverTest,
1669 name: "HttpPOST",
1670 sendPrefix: "POST / HTTP/1.0\n",
1671 shouldFail: true,
1672 expectedError: ":HTTP_REQUEST:",
1673 },
1674 {
1675 testType: serverTest,
1676 name: "HttpHEAD",
1677 sendPrefix: "HEAD / HTTP/1.0\n",
1678 shouldFail: true,
1679 expectedError: ":HTTP_REQUEST:",
1680 },
1681 {
1682 testType: serverTest,
1683 name: "HttpPUT",
1684 sendPrefix: "PUT / HTTP/1.0\n",
1685 shouldFail: true,
1686 expectedError: ":HTTP_REQUEST:",
1687 },
1688 {
1689 testType: serverTest,
1690 name: "HttpCONNECT",
1691 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1692 shouldFail: true,
1693 expectedError: ":HTTPS_PROXY_REQUEST:",
1694 },
1695 {
1696 testType: serverTest,
1697 name: "Garbage",
1698 sendPrefix: "blah",
1699 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001700 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
Adam Langley7c803a62015-06-15 15:35:05 -07001703 name: "RSAEphemeralKey",
1704 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001705 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001706 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1707 Bugs: ProtocolBugs{
1708 RSAEphemeralKey: true,
1709 },
1710 },
1711 shouldFail: true,
1712 expectedError: ":UNEXPECTED_MESSAGE:",
1713 },
1714 {
1715 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001716 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001717 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001718 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001719 },
1720 {
1721 protocol: dtls,
1722 name: "DisableEverything-DTLS",
1723 flags: []string{"-no-tls12", "-no-tls1"},
1724 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001725 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001726 },
1727 {
Adam Langley7c803a62015-06-15 15:35:05 -07001728 protocol: dtls,
1729 testType: serverTest,
1730 name: "MTU",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxPacketLength: 256,
1734 },
1735 },
1736 flags: []string{"-mtu", "256"},
1737 },
1738 {
1739 protocol: dtls,
1740 testType: serverTest,
1741 name: "MTUExceeded",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 MaxPacketLength: 255,
1745 },
1746 },
1747 flags: []string{"-mtu", "256"},
1748 shouldFail: true,
1749 expectedLocalError: "dtls: exceeded maximum packet length",
1750 },
1751 {
Adam Langley7c803a62015-06-15 15:35:05 -07001752 name: "EmptyCertificateList",
1753 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001754 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001755 Bugs: ProtocolBugs{
1756 EmptyCertificateList: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DECODE_ERROR:",
1761 },
1762 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001763 name: "EmptyCertificateList-TLS13",
1764 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001765 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001766 Bugs: ProtocolBugs{
1767 EmptyCertificateList: true,
1768 },
1769 },
1770 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001771 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001772 },
1773 {
Adam Langley7c803a62015-06-15 15:35:05 -07001774 name: "TLSFatalBadPackets",
1775 damageFirstWrite: true,
1776 shouldFail: true,
1777 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1778 },
1779 {
1780 protocol: dtls,
1781 name: "DTLSIgnoreBadPackets",
1782 damageFirstWrite: true,
1783 },
1784 {
1785 protocol: dtls,
1786 name: "DTLSIgnoreBadPackets-Async",
1787 damageFirstWrite: true,
1788 flags: []string{"-async"},
1789 },
1790 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001791 name: "AppDataBeforeHandshake",
1792 config: Config{
1793 Bugs: ProtocolBugs{
1794 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1795 },
1796 },
1797 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001798 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001799 },
1800 {
1801 name: "AppDataBeforeHandshake-Empty",
1802 config: Config{
1803 Bugs: ProtocolBugs{
1804 AppDataBeforeHandshake: []byte{},
1805 },
1806 },
1807 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001808 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001809 },
1810 {
1811 protocol: dtls,
1812 name: "AppDataBeforeHandshake-DTLS",
1813 config: Config{
1814 Bugs: ProtocolBugs{
1815 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1816 },
1817 },
1818 shouldFail: true,
1819 expectedError: ":UNEXPECTED_RECORD:",
1820 },
1821 {
1822 protocol: dtls,
1823 name: "AppDataBeforeHandshake-DTLS-Empty",
1824 config: Config{
1825 Bugs: ProtocolBugs{
1826 AppDataBeforeHandshake: []byte{},
1827 },
1828 },
1829 shouldFail: true,
1830 expectedError: ":UNEXPECTED_RECORD:",
1831 },
1832 {
Adam Langley7c803a62015-06-15 15:35:05 -07001833 name: "AppDataAfterChangeCipherSpec",
1834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 Bugs: ProtocolBugs{
1837 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1838 },
1839 },
1840 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001841 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001842 },
1843 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001844 name: "AppDataAfterChangeCipherSpec-Empty",
1845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001846 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001847 Bugs: ProtocolBugs{
1848 AppDataAfterChangeCipherSpec: []byte{},
1849 },
1850 },
1851 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001852 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001853 },
1854 {
Adam Langley7c803a62015-06-15 15:35:05 -07001855 protocol: dtls,
1856 name: "AppDataAfterChangeCipherSpec-DTLS",
1857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001858 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001859 Bugs: ProtocolBugs{
1860 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1861 },
1862 },
1863 // BoringSSL's DTLS implementation will drop the out-of-order
1864 // application data.
1865 },
1866 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001867 protocol: dtls,
1868 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001870 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001871 Bugs: ProtocolBugs{
1872 AppDataAfterChangeCipherSpec: []byte{},
1873 },
1874 },
1875 // BoringSSL's DTLS implementation will drop the out-of-order
1876 // application data.
1877 },
1878 {
Adam Langley7c803a62015-06-15 15:35:05 -07001879 name: "AlertAfterChangeCipherSpec",
1880 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001881 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001882 Bugs: ProtocolBugs{
1883 AlertAfterChangeCipherSpec: alertRecordOverflow,
1884 },
1885 },
1886 shouldFail: true,
1887 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1888 },
1889 {
1890 protocol: dtls,
1891 name: "AlertAfterChangeCipherSpec-DTLS",
1892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001893 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001894 Bugs: ProtocolBugs{
1895 AlertAfterChangeCipherSpec: alertRecordOverflow,
1896 },
1897 },
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1900 },
1901 {
1902 protocol: dtls,
1903 name: "ReorderHandshakeFragments-Small-DTLS",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 ReorderHandshakeFragments: true,
1907 // Small enough that every handshake message is
1908 // fragmented.
1909 MaxHandshakeRecordLength: 2,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "ReorderHandshakeFragments-Large-DTLS",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 ReorderHandshakeFragments: true,
1919 // Large enough that no handshake message is
1920 // fragmented.
1921 MaxHandshakeRecordLength: 2048,
1922 },
1923 },
1924 },
1925 {
1926 protocol: dtls,
1927 name: "MixCompleteMessageWithFragments-DTLS",
1928 config: Config{
1929 Bugs: ProtocolBugs{
1930 ReorderHandshakeFragments: true,
1931 MixCompleteMessageWithFragments: true,
1932 MaxHandshakeRecordLength: 2,
1933 },
1934 },
1935 },
1936 {
1937 name: "SendInvalidRecordType",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendInvalidRecordType: true,
1941 },
1942 },
1943 shouldFail: true,
1944 expectedError: ":UNEXPECTED_RECORD:",
1945 },
1946 {
1947 protocol: dtls,
1948 name: "SendInvalidRecordType-DTLS",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 SendInvalidRecordType: true,
1952 },
1953 },
1954 shouldFail: true,
1955 expectedError: ":UNEXPECTED_RECORD:",
1956 },
1957 {
1958 name: "FalseStart-SkipServerSecondLeg",
1959 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001960 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1962 NextProtos: []string{"foo"},
1963 Bugs: ProtocolBugs{
1964 SkipNewSessionTicket: true,
1965 SkipChangeCipherSpec: true,
1966 SkipFinished: true,
1967 ExpectFalseStart: true,
1968 },
1969 },
1970 flags: []string{
1971 "-false-start",
1972 "-handshake-never-done",
1973 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001974 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001975 },
1976 shimWritesFirst: true,
1977 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001978 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001979 },
1980 {
1981 name: "FalseStart-SkipServerSecondLeg-Implicit",
1982 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001983 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1985 NextProtos: []string{"foo"},
1986 Bugs: ProtocolBugs{
1987 SkipNewSessionTicket: true,
1988 SkipChangeCipherSpec: true,
1989 SkipFinished: true,
1990 },
1991 },
1992 flags: []string{
1993 "-implicit-handshake",
1994 "-false-start",
1995 "-handshake-never-done",
1996 "-advertise-alpn", "\x03foo",
1997 },
1998 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001999 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002000 },
2001 {
2002 testType: serverTest,
2003 name: "FailEarlyCallback",
2004 flags: []string{"-fail-early-callback"},
2005 shouldFail: true,
2006 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002007 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002008 },
2009 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002010 name: "FailCertCallback-Client-TLS12",
2011 config: Config{
2012 MaxVersion: VersionTLS12,
2013 ClientAuth: RequestClientCert,
2014 },
2015 flags: []string{"-fail-cert-callback"},
2016 shouldFail: true,
2017 expectedError: ":CERT_CB_ERROR:",
2018 expectedLocalError: "remote error: internal error",
2019 },
2020 {
2021 testType: serverTest,
2022 name: "FailCertCallback-Server-TLS12",
2023 config: Config{
2024 MaxVersion: VersionTLS12,
2025 },
2026 flags: []string{"-fail-cert-callback"},
2027 shouldFail: true,
2028 expectedError: ":CERT_CB_ERROR:",
2029 expectedLocalError: "remote error: internal error",
2030 },
2031 {
2032 name: "FailCertCallback-Client-TLS13",
2033 config: Config{
2034 MaxVersion: VersionTLS13,
2035 ClientAuth: RequestClientCert,
2036 },
2037 flags: []string{"-fail-cert-callback"},
2038 shouldFail: true,
2039 expectedError: ":CERT_CB_ERROR:",
2040 expectedLocalError: "remote error: internal error",
2041 },
2042 {
2043 testType: serverTest,
2044 name: "FailCertCallback-Server-TLS13",
2045 config: Config{
2046 MaxVersion: VersionTLS13,
2047 },
2048 flags: []string{"-fail-cert-callback"},
2049 shouldFail: true,
2050 expectedError: ":CERT_CB_ERROR:",
2051 expectedLocalError: "remote error: internal error",
2052 },
2053 {
Adam Langley7c803a62015-06-15 15:35:05 -07002054 protocol: dtls,
2055 name: "FragmentMessageTypeMismatch-DTLS",
2056 config: Config{
2057 Bugs: ProtocolBugs{
2058 MaxHandshakeRecordLength: 2,
2059 FragmentMessageTypeMismatch: true,
2060 },
2061 },
2062 shouldFail: true,
2063 expectedError: ":FRAGMENT_MISMATCH:",
2064 },
2065 {
2066 protocol: dtls,
2067 name: "FragmentMessageLengthMismatch-DTLS",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 MaxHandshakeRecordLength: 2,
2071 FragmentMessageLengthMismatch: true,
2072 },
2073 },
2074 shouldFail: true,
2075 expectedError: ":FRAGMENT_MISMATCH:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "SplitFragments-Header-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SplitFragments: 2,
2083 },
2084 },
2085 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002086 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002087 },
2088 {
2089 protocol: dtls,
2090 name: "SplitFragments-Boundary-DTLS",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SplitFragments: dtlsRecordHeaderLen,
2094 },
2095 },
2096 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002097 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002098 },
2099 {
2100 protocol: dtls,
2101 name: "SplitFragments-Body-DTLS",
2102 config: Config{
2103 Bugs: ProtocolBugs{
2104 SplitFragments: dtlsRecordHeaderLen + 1,
2105 },
2106 },
2107 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002108 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002109 },
2110 {
2111 protocol: dtls,
2112 name: "SendEmptyFragments-DTLS",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendEmptyFragments: true,
2116 },
2117 },
2118 },
2119 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002120 name: "BadFinished-Client",
2121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002123 Bugs: ProtocolBugs{
2124 BadFinished: true,
2125 },
2126 },
2127 shouldFail: true,
2128 expectedError: ":DIGEST_CHECK_FAILED:",
2129 },
2130 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002131 name: "BadFinished-Client-TLS13",
2132 config: Config{
2133 MaxVersion: VersionTLS13,
2134 Bugs: ProtocolBugs{
2135 BadFinished: true,
2136 },
2137 },
2138 shouldFail: true,
2139 expectedError: ":DIGEST_CHECK_FAILED:",
2140 },
2141 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002142 testType: serverTest,
2143 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002145 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002146 Bugs: ProtocolBugs{
2147 BadFinished: true,
2148 },
2149 },
2150 shouldFail: true,
2151 expectedError: ":DIGEST_CHECK_FAILED:",
2152 },
2153 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002154 testType: serverTest,
2155 name: "BadFinished-Server-TLS13",
2156 config: Config{
2157 MaxVersion: VersionTLS13,
2158 Bugs: ProtocolBugs{
2159 BadFinished: true,
2160 },
2161 },
2162 shouldFail: true,
2163 expectedError: ":DIGEST_CHECK_FAILED:",
2164 },
2165 {
Adam Langley7c803a62015-06-15 15:35:05 -07002166 name: "FalseStart-BadFinished",
2167 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002168 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2170 NextProtos: []string{"foo"},
2171 Bugs: ProtocolBugs{
2172 BadFinished: true,
2173 ExpectFalseStart: true,
2174 },
2175 },
2176 flags: []string{
2177 "-false-start",
2178 "-handshake-never-done",
2179 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002180 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002181 },
2182 shimWritesFirst: true,
2183 shouldFail: true,
2184 expectedError: ":DIGEST_CHECK_FAILED:",
2185 },
2186 {
2187 name: "NoFalseStart-NoALPN",
2188 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2191 Bugs: ProtocolBugs{
2192 ExpectFalseStart: true,
2193 AlertBeforeFalseStartTest: alertAccessDenied,
2194 },
2195 },
2196 flags: []string{
2197 "-false-start",
2198 },
2199 shimWritesFirst: true,
2200 shouldFail: true,
2201 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2202 expectedLocalError: "tls: peer did not false start: EOF",
2203 },
2204 {
2205 name: "NoFalseStart-NoAEAD",
2206 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002207 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002208 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2209 NextProtos: []string{"foo"},
2210 Bugs: ProtocolBugs{
2211 ExpectFalseStart: true,
2212 AlertBeforeFalseStartTest: alertAccessDenied,
2213 },
2214 },
2215 flags: []string{
2216 "-false-start",
2217 "-advertise-alpn", "\x03foo",
2218 },
2219 shimWritesFirst: true,
2220 shouldFail: true,
2221 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2222 expectedLocalError: "tls: peer did not false start: EOF",
2223 },
2224 {
2225 name: "NoFalseStart-RSA",
2226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002227 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002228 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2229 NextProtos: []string{"foo"},
2230 Bugs: ProtocolBugs{
2231 ExpectFalseStart: true,
2232 AlertBeforeFalseStartTest: alertAccessDenied,
2233 },
2234 },
2235 flags: []string{
2236 "-false-start",
2237 "-advertise-alpn", "\x03foo",
2238 },
2239 shimWritesFirst: true,
2240 shouldFail: true,
2241 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2242 expectedLocalError: "tls: peer did not false start: EOF",
2243 },
2244 {
Adam Langley7c803a62015-06-15 15:35:05 -07002245 protocol: dtls,
2246 name: "SendSplitAlert-Sync",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendSplitAlert: true,
2250 },
2251 },
2252 },
2253 {
2254 protocol: dtls,
2255 name: "SendSplitAlert-Async",
2256 config: Config{
2257 Bugs: ProtocolBugs{
2258 SendSplitAlert: true,
2259 },
2260 },
2261 flags: []string{"-async"},
2262 },
2263 {
2264 protocol: dtls,
2265 name: "PackDTLSHandshake",
2266 config: Config{
2267 Bugs: ProtocolBugs{
2268 MaxHandshakeRecordLength: 2,
2269 PackHandshakeFragments: 20,
2270 PackHandshakeRecords: 200,
2271 },
2272 },
2273 },
2274 {
Adam Langley7c803a62015-06-15 15:35:05 -07002275 name: "SendEmptyRecords-Pass",
2276 sendEmptyRecords: 32,
2277 },
2278 {
2279 name: "SendEmptyRecords",
2280 sendEmptyRecords: 33,
2281 shouldFail: true,
2282 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2283 },
2284 {
2285 name: "SendEmptyRecords-Async",
2286 sendEmptyRecords: 33,
2287 flags: []string{"-async"},
2288 shouldFail: true,
2289 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2290 },
2291 {
David Benjamine8e84b92016-08-03 15:39:47 -04002292 name: "SendWarningAlerts-Pass",
2293 config: Config{
2294 MaxVersion: VersionTLS12,
2295 },
Adam Langley7c803a62015-06-15 15:35:05 -07002296 sendWarningAlerts: 4,
2297 },
2298 {
David Benjamine8e84b92016-08-03 15:39:47 -04002299 protocol: dtls,
2300 name: "SendWarningAlerts-DTLS-Pass",
2301 config: Config{
2302 MaxVersion: VersionTLS12,
2303 },
Adam Langley7c803a62015-06-15 15:35:05 -07002304 sendWarningAlerts: 4,
2305 },
2306 {
David Benjamine8e84b92016-08-03 15:39:47 -04002307 name: "SendWarningAlerts-TLS13",
2308 config: Config{
2309 MaxVersion: VersionTLS13,
2310 },
2311 sendWarningAlerts: 4,
2312 shouldFail: true,
2313 expectedError: ":BAD_ALERT:",
2314 expectedLocalError: "remote error: error decoding message",
2315 },
2316 {
2317 name: "SendWarningAlerts",
2318 config: Config{
2319 MaxVersion: VersionTLS12,
2320 },
Adam Langley7c803a62015-06-15 15:35:05 -07002321 sendWarningAlerts: 5,
2322 shouldFail: true,
2323 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2324 },
2325 {
David Benjamine8e84b92016-08-03 15:39:47 -04002326 name: "SendWarningAlerts-Async",
2327 config: Config{
2328 MaxVersion: VersionTLS12,
2329 },
Adam Langley7c803a62015-06-15 15:35:05 -07002330 sendWarningAlerts: 5,
2331 flags: []string{"-async"},
2332 shouldFail: true,
2333 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2334 },
David Benjaminba4594a2015-06-18 18:36:15 -04002335 {
David Benjamin24e58862017-06-14 18:45:29 -04002336 name: "SendBogusAlertType",
2337 sendBogusAlertType: true,
2338 shouldFail: true,
2339 expectedError: ":UNKNOWN_ALERT_TYPE:",
2340 expectedLocalError: "remote error: illegal parameter",
2341 },
2342 {
2343 protocol: dtls,
2344 name: "SendBogusAlertType-DTLS",
2345 sendBogusAlertType: true,
2346 shouldFail: true,
2347 expectedError: ":UNKNOWN_ALERT_TYPE:",
2348 expectedLocalError: "remote error: illegal parameter",
2349 },
2350 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002351 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002352 config: Config{
2353 MaxVersion: VersionTLS13,
2354 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002355 sendKeyUpdates: 33,
2356 keyUpdateRequest: keyUpdateNotRequested,
2357 shouldFail: true,
2358 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002359 },
2360 {
David Benjaminba4594a2015-06-18 18:36:15 -04002361 name: "EmptySessionID",
2362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002363 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002364 SessionTicketsDisabled: true,
2365 },
2366 noSessionCache: true,
2367 flags: []string{"-expect-no-session"},
2368 },
David Benjamin30789da2015-08-29 22:56:45 -04002369 {
2370 name: "Unclean-Shutdown",
2371 config: Config{
2372 Bugs: ProtocolBugs{
2373 NoCloseNotify: true,
2374 ExpectCloseNotify: true,
2375 },
2376 },
2377 shimShutsDown: true,
2378 flags: []string{"-check-close-notify"},
2379 shouldFail: true,
2380 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2381 },
2382 {
2383 name: "Unclean-Shutdown-Ignored",
2384 config: Config{
2385 Bugs: ProtocolBugs{
2386 NoCloseNotify: true,
2387 },
2388 },
2389 shimShutsDown: true,
2390 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002391 {
David Benjaminfa214e42016-05-10 17:03:10 -04002392 name: "Unclean-Shutdown-Alert",
2393 config: Config{
2394 Bugs: ProtocolBugs{
2395 SendAlertOnShutdown: alertDecompressionFailure,
2396 ExpectCloseNotify: true,
2397 },
2398 },
2399 shimShutsDown: true,
2400 flags: []string{"-check-close-notify"},
2401 shouldFail: true,
2402 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2403 },
2404 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002405 name: "LargePlaintext",
2406 config: Config{
2407 Bugs: ProtocolBugs{
2408 SendLargeRecords: true,
2409 },
2410 },
2411 messageLen: maxPlaintext + 1,
2412 shouldFail: true,
2413 expectedError: ":DATA_LENGTH_TOO_LONG:",
2414 },
2415 {
2416 protocol: dtls,
2417 name: "LargePlaintext-DTLS",
2418 config: Config{
2419 Bugs: ProtocolBugs{
2420 SendLargeRecords: true,
2421 },
2422 },
2423 messageLen: maxPlaintext + 1,
2424 shouldFail: true,
2425 expectedError: ":DATA_LENGTH_TOO_LONG:",
2426 },
2427 {
2428 name: "LargeCiphertext",
2429 config: Config{
2430 Bugs: ProtocolBugs{
2431 SendLargeRecords: true,
2432 },
2433 },
2434 messageLen: maxPlaintext * 2,
2435 shouldFail: true,
2436 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2437 },
2438 {
2439 protocol: dtls,
2440 name: "LargeCiphertext-DTLS",
2441 config: Config{
2442 Bugs: ProtocolBugs{
2443 SendLargeRecords: true,
2444 },
2445 },
2446 messageLen: maxPlaintext * 2,
2447 // Unlike the other four cases, DTLS drops records which
2448 // are invalid before authentication, so the connection
2449 // does not fail.
2450 expectMessageDropped: true,
2451 },
David Benjamindd6fed92015-10-23 17:41:12 -04002452 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002453 name: "BadHelloRequest-1",
2454 renegotiate: 1,
2455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002456 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002457 Bugs: ProtocolBugs{
2458 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2459 },
2460 },
2461 flags: []string{
2462 "-renegotiate-freely",
2463 "-expect-total-renegotiations", "1",
2464 },
2465 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002466 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002467 },
2468 {
2469 name: "BadHelloRequest-2",
2470 renegotiate: 1,
2471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002472 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002473 Bugs: ProtocolBugs{
2474 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2475 },
2476 },
2477 flags: []string{
2478 "-renegotiate-freely",
2479 "-expect-total-renegotiations", "1",
2480 },
2481 shouldFail: true,
2482 expectedError: ":BAD_HELLO_REQUEST:",
2483 },
David Benjaminef1b0092015-11-21 14:05:44 -05002484 {
2485 testType: serverTest,
2486 name: "SupportTicketsWithSessionID",
2487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002488 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002489 SessionTicketsDisabled: true,
2490 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002491 resumeConfig: &Config{
2492 MaxVersion: VersionTLS12,
2493 },
David Benjaminef1b0092015-11-21 14:05:44 -05002494 resumeSession: true,
2495 },
David Benjamin02edcd02016-07-27 17:40:37 -04002496 {
2497 protocol: dtls,
2498 name: "DTLS-SendExtraFinished",
2499 config: Config{
2500 Bugs: ProtocolBugs{
2501 SendExtraFinished: true,
2502 },
2503 },
2504 shouldFail: true,
2505 expectedError: ":UNEXPECTED_RECORD:",
2506 },
2507 {
2508 protocol: dtls,
2509 name: "DTLS-SendExtraFinished-Reordered",
2510 config: Config{
2511 Bugs: ProtocolBugs{
2512 MaxHandshakeRecordLength: 2,
2513 ReorderHandshakeFragments: true,
2514 SendExtraFinished: true,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNEXPECTED_RECORD:",
2519 },
David Benjamine97fb482016-07-29 09:23:07 -04002520 {
2521 testType: serverTest,
2522 name: "V2ClientHello-EmptyRecordPrefix",
2523 config: Config{
2524 // Choose a cipher suite that does not involve
2525 // elliptic curves, so no extensions are
2526 // involved.
2527 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002528 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002529 Bugs: ProtocolBugs{
2530 SendV2ClientHello: true,
2531 },
2532 },
2533 sendPrefix: string([]byte{
2534 byte(recordTypeHandshake),
2535 3, 1, // version
2536 0, 0, // length
2537 }),
2538 // A no-op empty record may not be sent before V2ClientHello.
2539 shouldFail: true,
2540 expectedError: ":WRONG_VERSION_NUMBER:",
2541 },
2542 {
2543 testType: serverTest,
2544 name: "V2ClientHello-WarningAlertPrefix",
2545 config: Config{
2546 // Choose a cipher suite that does not involve
2547 // elliptic curves, so no extensions are
2548 // involved.
2549 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002550 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002551 Bugs: ProtocolBugs{
2552 SendV2ClientHello: true,
2553 },
2554 },
2555 sendPrefix: string([]byte{
2556 byte(recordTypeAlert),
2557 3, 1, // version
2558 0, 2, // length
2559 alertLevelWarning, byte(alertDecompressionFailure),
2560 }),
2561 // A no-op warning alert may not be sent before V2ClientHello.
2562 shouldFail: true,
2563 expectedError: ":WRONG_VERSION_NUMBER:",
2564 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002565 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002566 name: "KeyUpdate-Client",
2567 config: Config{
2568 MaxVersion: VersionTLS13,
2569 },
2570 sendKeyUpdates: 1,
2571 keyUpdateRequest: keyUpdateNotRequested,
2572 },
2573 {
2574 testType: serverTest,
2575 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002576 config: Config{
2577 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002578 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002579 sendKeyUpdates: 1,
2580 keyUpdateRequest: keyUpdateNotRequested,
2581 },
2582 {
2583 name: "KeyUpdate-InvalidRequestMode",
2584 config: Config{
2585 MaxVersion: VersionTLS13,
2586 },
2587 sendKeyUpdates: 1,
2588 keyUpdateRequest: 42,
2589 shouldFail: true,
2590 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002591 },
David Benjaminabe94e32016-09-04 14:18:58 -04002592 {
David Benjaminbbba9392017-04-06 12:54:12 -04002593 // Test that KeyUpdates are acknowledged properly.
2594 name: "KeyUpdate-RequestACK",
2595 config: Config{
2596 MaxVersion: VersionTLS13,
2597 Bugs: ProtocolBugs{
2598 RejectUnsolicitedKeyUpdate: true,
2599 },
2600 },
2601 // Test the shim receiving many KeyUpdates in a row.
2602 sendKeyUpdates: 5,
2603 messageCount: 5,
2604 keyUpdateRequest: keyUpdateRequested,
2605 },
2606 {
2607 // Test that KeyUpdates are acknowledged properly if the
2608 // peer's KeyUpdate is discovered while a write is
2609 // pending.
2610 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2611 config: Config{
2612 MaxVersion: VersionTLS13,
2613 Bugs: ProtocolBugs{
2614 RejectUnsolicitedKeyUpdate: true,
2615 },
2616 },
2617 // Test the shim receiving many KeyUpdates in a row.
2618 sendKeyUpdates: 5,
2619 messageCount: 5,
2620 keyUpdateRequest: keyUpdateRequested,
2621 readWithUnfinishedWrite: true,
2622 flags: []string{"-async"},
2623 },
2624 {
David Benjaminabe94e32016-09-04 14:18:58 -04002625 name: "SendSNIWarningAlert",
2626 config: Config{
2627 MaxVersion: VersionTLS12,
2628 Bugs: ProtocolBugs{
2629 SendSNIWarningAlert: true,
2630 },
2631 },
2632 },
David Benjaminc241d792016-09-09 10:34:20 -04002633 {
2634 testType: serverTest,
2635 name: "ExtraCompressionMethods-TLS12",
2636 config: Config{
2637 MaxVersion: VersionTLS12,
2638 Bugs: ProtocolBugs{
2639 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2640 },
2641 },
2642 },
2643 {
2644 testType: serverTest,
2645 name: "ExtraCompressionMethods-TLS13",
2646 config: Config{
2647 MaxVersion: VersionTLS13,
2648 Bugs: ProtocolBugs{
2649 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2650 },
2651 },
2652 shouldFail: true,
2653 expectedError: ":INVALID_COMPRESSION_LIST:",
2654 expectedLocalError: "remote error: illegal parameter",
2655 },
2656 {
2657 testType: serverTest,
2658 name: "NoNullCompression-TLS12",
2659 config: Config{
2660 MaxVersion: VersionTLS12,
2661 Bugs: ProtocolBugs{
2662 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2663 },
2664 },
2665 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002666 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002667 expectedLocalError: "remote error: illegal parameter",
2668 },
2669 {
2670 testType: serverTest,
2671 name: "NoNullCompression-TLS13",
2672 config: Config{
2673 MaxVersion: VersionTLS13,
2674 Bugs: ProtocolBugs{
2675 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2676 },
2677 },
2678 shouldFail: true,
2679 expectedError: ":INVALID_COMPRESSION_LIST:",
2680 expectedLocalError: "remote error: illegal parameter",
2681 },
David Benjamin413e79e2017-07-01 10:11:53 -04002682 // Test that the client rejects invalid compression methods
2683 // from the server.
2684 {
2685 testType: clientTest,
2686 name: "InvalidCompressionMethod",
2687 config: Config{
2688 MaxVersion: VersionTLS12,
2689 Bugs: ProtocolBugs{
2690 SendCompressionMethod: 1,
2691 },
2692 },
2693 shouldFail: true,
2694 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2695 expectedLocalError: "remote error: illegal parameter",
2696 },
David Benjamin65ac9972016-09-02 21:35:25 -04002697 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002698 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002699 config: Config{
2700 MaxVersion: VersionTLS12,
2701 Bugs: ProtocolBugs{
2702 ExpectGREASE: true,
2703 },
2704 },
2705 flags: []string{"-enable-grease"},
2706 },
2707 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002708 name: "GREASE-Client-TLS13",
2709 config: Config{
2710 MaxVersion: VersionTLS13,
2711 Bugs: ProtocolBugs{
2712 ExpectGREASE: true,
2713 },
2714 },
2715 flags: []string{"-enable-grease"},
2716 },
2717 {
2718 testType: serverTest,
2719 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002720 config: Config{
2721 MaxVersion: VersionTLS13,
2722 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002723 // TLS 1.3 servers are expected to
2724 // always enable GREASE. TLS 1.3 is new,
2725 // so there is no existing ecosystem to
2726 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002727 ExpectGREASE: true,
2728 },
2729 },
David Benjamin65ac9972016-09-02 21:35:25 -04002730 },
David Benjamine3fbb362017-01-06 16:19:28 -05002731 {
2732 // Test the server so there is a large certificate as
2733 // well as application data.
2734 testType: serverTest,
2735 name: "MaxSendFragment",
2736 config: Config{
2737 Bugs: ProtocolBugs{
2738 MaxReceivePlaintext: 512,
2739 },
2740 },
2741 messageLen: 1024,
2742 flags: []string{
2743 "-max-send-fragment", "512",
2744 "-read-size", "1024",
2745 },
2746 },
2747 {
2748 // Test the server so there is a large certificate as
2749 // well as application data.
2750 testType: serverTest,
2751 name: "MaxSendFragment-TooLarge",
2752 config: Config{
2753 Bugs: ProtocolBugs{
2754 // Ensure that some of the records are
2755 // 512.
2756 MaxReceivePlaintext: 511,
2757 },
2758 },
2759 messageLen: 1024,
2760 flags: []string{
2761 "-max-send-fragment", "512",
2762 "-read-size", "1024",
2763 },
2764 shouldFail: true,
2765 expectedLocalError: "local error: record overflow",
2766 },
Adam Langley7c803a62015-06-15 15:35:05 -07002767 }
Adam Langley7c803a62015-06-15 15:35:05 -07002768 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002769
2770 // Test that very large messages can be received.
2771 cert := rsaCertificate
2772 for i := 0; i < 50; i++ {
2773 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2774 }
2775 testCases = append(testCases, testCase{
2776 name: "LargeMessage",
2777 config: Config{
2778 Certificates: []Certificate{cert},
2779 },
2780 })
2781 testCases = append(testCases, testCase{
2782 protocol: dtls,
2783 name: "LargeMessage-DTLS",
2784 config: Config{
2785 Certificates: []Certificate{cert},
2786 },
2787 })
2788
2789 // They are rejected if the maximum certificate chain length is capped.
2790 testCases = append(testCases, testCase{
2791 name: "LargeMessage-Reject",
2792 config: Config{
2793 Certificates: []Certificate{cert},
2794 },
2795 flags: []string{"-max-cert-list", "16384"},
2796 shouldFail: true,
2797 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2798 })
2799 testCases = append(testCases, testCase{
2800 protocol: dtls,
2801 name: "LargeMessage-Reject-DTLS",
2802 config: Config{
2803 Certificates: []Certificate{cert},
2804 },
2805 flags: []string{"-max-cert-list", "16384"},
2806 shouldFail: true,
2807 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2808 })
Adam Langley7c803a62015-06-15 15:35:05 -07002809}
2810
David Benjaminaa012042016-12-10 13:33:05 -05002811func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2812 const psk = "12345"
2813 const pskIdentity = "luggage combo"
2814
2815 var prefix string
2816 if protocol == dtls {
2817 if !ver.hasDTLS {
2818 return
2819 }
2820 prefix = "D"
2821 }
2822
2823 var cert Certificate
2824 var certFile string
2825 var keyFile string
2826 if hasComponent(suite.name, "ECDSA") {
2827 cert = ecdsaP256Certificate
2828 certFile = ecdsaP256CertificateFile
2829 keyFile = ecdsaP256KeyFile
2830 } else {
2831 cert = rsaCertificate
2832 certFile = rsaCertificateFile
2833 keyFile = rsaKeyFile
2834 }
2835
2836 var flags []string
2837 if hasComponent(suite.name, "PSK") {
2838 flags = append(flags,
2839 "-psk", psk,
2840 "-psk-identity", pskIdentity)
2841 }
2842 if hasComponent(suite.name, "NULL") {
2843 // NULL ciphers must be explicitly enabled.
2844 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2845 }
David Benjaminaa012042016-12-10 13:33:05 -05002846
2847 var shouldServerFail, shouldClientFail bool
2848 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2849 // BoringSSL clients accept ECDHE on SSLv3, but
2850 // a BoringSSL server will never select it
2851 // because the extension is missing.
2852 shouldServerFail = true
2853 }
2854 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2855 shouldClientFail = true
2856 shouldServerFail = true
2857 }
2858 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2859 shouldClientFail = true
2860 shouldServerFail = true
2861 }
2862 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2863 shouldClientFail = true
2864 shouldServerFail = true
2865 }
2866 if !isDTLSCipher(suite.name) && protocol == dtls {
2867 shouldClientFail = true
2868 shouldServerFail = true
2869 }
2870
2871 var sendCipherSuite uint16
2872 var expectedServerError, expectedClientError string
2873 serverCipherSuites := []uint16{suite.id}
2874 if shouldServerFail {
2875 expectedServerError = ":NO_SHARED_CIPHER:"
2876 }
2877 if shouldClientFail {
2878 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2879 // Configure the server to select ciphers as normal but
2880 // select an incompatible cipher in ServerHello.
2881 serverCipherSuites = nil
2882 sendCipherSuite = suite.id
2883 }
2884
David Benjamincdb6fe92017-02-07 16:06:48 -05002885 // For cipher suites and versions where exporters are defined, verify
2886 // that they interoperate.
2887 var exportKeyingMaterial int
2888 if ver.version > VersionSSL30 {
2889 exportKeyingMaterial = 1024
2890 }
2891
David Benjaminaa012042016-12-10 13:33:05 -05002892 testCases = append(testCases, testCase{
2893 testType: serverTest,
2894 protocol: protocol,
2895 name: prefix + ver.name + "-" + suite.name + "-server",
2896 config: Config{
2897 MinVersion: ver.version,
2898 MaxVersion: ver.version,
2899 CipherSuites: []uint16{suite.id},
2900 Certificates: []Certificate{cert},
2901 PreSharedKey: []byte(psk),
2902 PreSharedKeyIdentity: pskIdentity,
2903 Bugs: ProtocolBugs{
2904 AdvertiseAllConfiguredCiphers: true,
2905 },
2906 },
David Benjamina5022392017-07-10 17:40:39 -04002907 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002908 certFile: certFile,
2909 keyFile: keyFile,
2910 flags: flags,
2911 resumeSession: true,
2912 shouldFail: shouldServerFail,
2913 expectedError: expectedServerError,
2914 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002915 })
2916
2917 testCases = append(testCases, testCase{
2918 testType: clientTest,
2919 protocol: protocol,
2920 name: prefix + ver.name + "-" + suite.name + "-client",
2921 config: Config{
2922 MinVersion: ver.version,
2923 MaxVersion: ver.version,
2924 CipherSuites: serverCipherSuites,
2925 Certificates: []Certificate{cert},
2926 PreSharedKey: []byte(psk),
2927 PreSharedKeyIdentity: pskIdentity,
2928 Bugs: ProtocolBugs{
2929 IgnorePeerCipherPreferences: shouldClientFail,
2930 SendCipherSuite: sendCipherSuite,
2931 },
2932 },
David Benjamina5022392017-07-10 17:40:39 -04002933 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002934 flags: flags,
2935 resumeSession: true,
2936 shouldFail: shouldClientFail,
2937 expectedError: expectedClientError,
2938 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002939 })
2940
David Benjamin6f600d62016-12-21 16:06:54 -05002941 if shouldClientFail {
2942 return
2943 }
2944
2945 // Ensure the maximum record size is accepted.
2946 testCases = append(testCases, testCase{
2947 protocol: protocol,
2948 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2949 config: Config{
2950 MinVersion: ver.version,
2951 MaxVersion: ver.version,
2952 CipherSuites: []uint16{suite.id},
2953 Certificates: []Certificate{cert},
2954 PreSharedKey: []byte(psk),
2955 PreSharedKeyIdentity: pskIdentity,
2956 },
David Benjamina5022392017-07-10 17:40:39 -04002957 tls13Variant: ver.tls13Variant,
2958 flags: flags,
2959 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002960 })
2961
2962 // Test bad records for all ciphers. Bad records are fatal in TLS
2963 // and ignored in DTLS.
2964 var shouldFail bool
2965 var expectedError string
2966 if protocol == tls {
2967 shouldFail = true
2968 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2969 }
2970
2971 testCases = append(testCases, testCase{
2972 protocol: protocol,
2973 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2974 config: Config{
2975 MinVersion: ver.version,
2976 MaxVersion: ver.version,
2977 CipherSuites: []uint16{suite.id},
2978 Certificates: []Certificate{cert},
2979 PreSharedKey: []byte(psk),
2980 PreSharedKeyIdentity: pskIdentity,
2981 },
David Benjamina5022392017-07-10 17:40:39 -04002982 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002983 flags: flags,
2984 damageFirstWrite: true,
2985 messageLen: maxPlaintext,
2986 shouldFail: shouldFail,
2987 expectedError: expectedError,
2988 })
David Benjaminaa012042016-12-10 13:33:05 -05002989}
2990
Adam Langley95c29f32014-06-20 12:00:00 -07002991func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002992 const bogusCipher = 0xfe00
2993
Adam Langley95c29f32014-06-20 12:00:00 -07002994 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002995 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002996 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002997 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002998 }
David Benjamin2c99d282015-09-01 10:23:00 -04002999 }
Adam Langley95c29f32014-06-20 12:00:00 -07003000 }
Adam Langleya7997f12015-05-14 17:38:50 -07003001
3002 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003003 name: "NoSharedCipher",
3004 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003005 MaxVersion: VersionTLS12,
3006 CipherSuites: []uint16{},
3007 },
3008 shouldFail: true,
3009 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3010 })
3011
3012 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003013 name: "NoSharedCipher-TLS13",
3014 config: Config{
3015 MaxVersion: VersionTLS13,
3016 CipherSuites: []uint16{},
3017 },
3018 shouldFail: true,
3019 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3020 })
3021
3022 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003023 name: "UnsupportedCipherSuite",
3024 config: Config{
3025 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003026 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 Bugs: ProtocolBugs{
3028 IgnorePeerCipherPreferences: true,
3029 },
3030 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003031 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003032 shouldFail: true,
3033 expectedError: ":WRONG_CIPHER_RETURNED:",
3034 })
3035
3036 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003037 name: "ServerHelloBogusCipher",
3038 config: Config{
3039 MaxVersion: VersionTLS12,
3040 Bugs: ProtocolBugs{
3041 SendCipherSuite: bogusCipher,
3042 },
3043 },
3044 shouldFail: true,
3045 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3046 })
3047 testCases = append(testCases, testCase{
3048 name: "ServerHelloBogusCipher-TLS13",
3049 config: Config{
3050 MaxVersion: VersionTLS13,
3051 Bugs: ProtocolBugs{
3052 SendCipherSuite: bogusCipher,
3053 },
3054 },
3055 shouldFail: true,
3056 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3057 })
3058
David Benjamin241ae832016-01-15 03:04:54 -05003059 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003060 testCases = append(testCases, testCase{
3061 testType: serverTest,
3062 name: "UnknownCipher",
3063 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003064 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003065 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003066 Bugs: ProtocolBugs{
3067 AdvertiseAllConfiguredCiphers: true,
3068 },
3069 },
3070 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003071
3072 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003073 testCases = append(testCases, testCase{
3074 testType: serverTest,
3075 name: "UnknownCipher-TLS13",
3076 config: Config{
3077 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003078 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003079 Bugs: ProtocolBugs{
3080 AdvertiseAllConfiguredCiphers: true,
3081 },
David Benjamin241ae832016-01-15 03:04:54 -05003082 },
3083 })
3084
David Benjamin78679342016-09-16 19:42:05 -04003085 // Test empty ECDHE_PSK identity hints work as expected.
3086 testCases = append(testCases, testCase{
3087 name: "EmptyECDHEPSKHint",
3088 config: Config{
3089 MaxVersion: VersionTLS12,
3090 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3091 PreSharedKey: []byte("secret"),
3092 },
3093 flags: []string{"-psk", "secret"},
3094 })
3095
3096 // Test empty PSK identity hints work as expected, even if an explicit
3097 // ServerKeyExchange is sent.
3098 testCases = append(testCases, testCase{
3099 name: "ExplicitEmptyPSKHint",
3100 config: Config{
3101 MaxVersion: VersionTLS12,
3102 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3103 PreSharedKey: []byte("secret"),
3104 Bugs: ProtocolBugs{
3105 AlwaysSendPreSharedKeyIdentityHint: true,
3106 },
3107 },
3108 flags: []string{"-psk", "secret"},
3109 })
David Benjamin69522112017-03-28 15:38:29 -05003110
3111 // Test that clients enforce that the server-sent certificate and cipher
3112 // suite match in TLS 1.2.
3113 testCases = append(testCases, testCase{
3114 name: "CertificateCipherMismatch-RSA",
3115 config: Config{
3116 MaxVersion: VersionTLS12,
3117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3118 Certificates: []Certificate{rsaCertificate},
3119 Bugs: ProtocolBugs{
3120 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3121 },
3122 },
3123 shouldFail: true,
3124 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3125 })
3126 testCases = append(testCases, testCase{
3127 name: "CertificateCipherMismatch-ECDSA",
3128 config: Config{
3129 MaxVersion: VersionTLS12,
3130 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3131 Certificates: []Certificate{ecdsaP256Certificate},
3132 Bugs: ProtocolBugs{
3133 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3134 },
3135 },
3136 shouldFail: true,
3137 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3138 })
3139 testCases = append(testCases, testCase{
3140 name: "CertificateCipherMismatch-Ed25519",
3141 config: Config{
3142 MaxVersion: VersionTLS12,
3143 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3144 Certificates: []Certificate{ed25519Certificate},
3145 Bugs: ProtocolBugs{
3146 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 },
3149 shouldFail: true,
3150 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3151 })
3152
3153 // Test that servers decline to select a cipher suite which is
3154 // inconsistent with their configured certificate.
3155 testCases = append(testCases, testCase{
3156 testType: serverTest,
3157 name: "ServerCipherFilter-RSA",
3158 config: Config{
3159 MaxVersion: VersionTLS12,
3160 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3161 },
3162 flags: []string{
3163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3165 },
3166 shouldFail: true,
3167 expectedError: ":NO_SHARED_CIPHER:",
3168 })
3169 testCases = append(testCases, testCase{
3170 testType: serverTest,
3171 name: "ServerCipherFilter-ECDSA",
3172 config: Config{
3173 MaxVersion: VersionTLS12,
3174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3175 },
3176 flags: []string{
3177 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3178 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3179 },
3180 shouldFail: true,
3181 expectedError: ":NO_SHARED_CIPHER:",
3182 })
3183 testCases = append(testCases, testCase{
3184 testType: serverTest,
3185 name: "ServerCipherFilter-Ed25519",
3186 config: Config{
3187 MaxVersion: VersionTLS12,
3188 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3189 },
3190 flags: []string{
3191 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3192 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3193 },
3194 shouldFail: true,
3195 expectedError: ":NO_SHARED_CIPHER:",
3196 })
David Benjamin364af782017-07-01 10:35:27 -04003197
3198 // Test cipher suite negotiation works as expected. Configure a
3199 // complicated cipher suite configuration.
3200 const negotiationTestCiphers = "" +
3201 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3202 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3203 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3204 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3205 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3206 negotiationTests := []struct {
3207 ciphers []uint16
3208 expected uint16
3209 }{
3210 // Server preferences are honored, including when
3211 // equipreference groups are involved.
3212 {
3213 []uint16{
3214 TLS_RSA_WITH_AES_256_GCM_SHA384,
3215 TLS_RSA_WITH_AES_128_CBC_SHA,
3216 TLS_RSA_WITH_AES_128_GCM_SHA256,
3217 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3218 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3219 },
3220 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3221 },
3222 {
3223 []uint16{
3224 TLS_RSA_WITH_AES_256_GCM_SHA384,
3225 TLS_RSA_WITH_AES_128_CBC_SHA,
3226 TLS_RSA_WITH_AES_128_GCM_SHA256,
3227 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3228 },
3229 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3230 },
3231 {
3232 []uint16{
3233 TLS_RSA_WITH_AES_256_GCM_SHA384,
3234 TLS_RSA_WITH_AES_128_CBC_SHA,
3235 TLS_RSA_WITH_AES_128_GCM_SHA256,
3236 },
3237 TLS_RSA_WITH_AES_128_GCM_SHA256,
3238 },
3239 {
3240 []uint16{
3241 TLS_RSA_WITH_AES_256_GCM_SHA384,
3242 TLS_RSA_WITH_AES_128_CBC_SHA,
3243 },
3244 TLS_RSA_WITH_AES_128_CBC_SHA,
3245 },
3246 // Equipreference groups use the client preference.
3247 {
3248 []uint16{
3249 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3250 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3251 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3252 },
3253 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3254 },
3255 {
3256 []uint16{
3257 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3258 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3259 },
3260 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3261 },
3262 {
3263 []uint16{
3264 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3265 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3266 },
3267 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3268 },
3269 {
3270 []uint16{
3271 TLS_RSA_WITH_AES_256_GCM_SHA384,
3272 TLS_RSA_WITH_AES_256_CBC_SHA,
3273 },
3274 TLS_RSA_WITH_AES_256_GCM_SHA384,
3275 },
3276 {
3277 []uint16{
3278 TLS_RSA_WITH_AES_256_CBC_SHA,
3279 TLS_RSA_WITH_AES_256_GCM_SHA384,
3280 },
3281 TLS_RSA_WITH_AES_256_CBC_SHA,
3282 },
3283 // If there are two equipreference groups, the preferred one
3284 // takes precedence.
3285 {
3286 []uint16{
3287 TLS_RSA_WITH_AES_256_GCM_SHA384,
3288 TLS_RSA_WITH_AES_256_CBC_SHA,
3289 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3290 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3291 },
3292 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3293 },
3294 }
3295 for i, t := range negotiationTests {
3296 testCases = append(testCases, testCase{
3297 testType: serverTest,
3298 name: "CipherNegotiation-" + strconv.Itoa(i),
3299 config: Config{
3300 MaxVersion: VersionTLS12,
3301 CipherSuites: t.ciphers,
3302 },
3303 flags: []string{"-cipher", negotiationTestCiphers},
3304 expectedCipher: t.expected,
3305 })
3306 }
Adam Langley95c29f32014-06-20 12:00:00 -07003307}
3308
3309func addBadECDSASignatureTests() {
3310 for badR := BadValue(1); badR < NumBadValues; badR++ {
3311 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003312 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003313 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3314 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003315 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003316 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003317 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003318 Bugs: ProtocolBugs{
3319 BadECDSAR: badR,
3320 BadECDSAS: badS,
3321 },
3322 },
3323 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003324 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003325 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003326 testCases = append(testCases, testCase{
3327 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3328 config: Config{
3329 MaxVersion: VersionTLS13,
3330 Certificates: []Certificate{ecdsaP256Certificate},
3331 Bugs: ProtocolBugs{
3332 BadECDSAR: badR,
3333 BadECDSAS: badS,
3334 },
3335 },
3336 shouldFail: true,
3337 expectedError: ":BAD_SIGNATURE:",
3338 })
Adam Langley95c29f32014-06-20 12:00:00 -07003339 }
3340 }
3341}
3342
Adam Langley80842bd2014-06-20 12:00:00 -07003343func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003344 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003345 name: "MaxCBCPadding",
3346 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003347 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003348 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3349 Bugs: ProtocolBugs{
3350 MaxPadding: true,
3351 },
3352 },
3353 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3354 })
David Benjamin025b3d32014-07-01 19:53:04 -04003355 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003356 name: "BadCBCPadding",
3357 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003358 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003359 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3360 Bugs: ProtocolBugs{
3361 PaddingFirstByteBad: true,
3362 },
3363 },
3364 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003365 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003366 })
3367 // OpenSSL previously had an issue where the first byte of padding in
3368 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003369 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003370 name: "BadCBCPadding255",
3371 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003372 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3374 Bugs: ProtocolBugs{
3375 MaxPadding: true,
3376 PaddingFirstByteBadIf255: true,
3377 },
3378 },
3379 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3380 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003381 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003382 })
3383}
3384
Kenny Root7fdeaf12014-08-05 15:23:37 -07003385func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003386 var cbcCiphers = []struct {
3387 name string
3388 cipher uint16
3389 }{
3390 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3391 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3392 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3393 }
3394 for _, t := range cbcCiphers {
3395 testCases = append(testCases, testCase{
3396 name: "CBCRecordSplitting-" + t.name,
3397 config: Config{
3398 MaxVersion: VersionTLS10,
3399 MinVersion: VersionTLS10,
3400 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003401 Bugs: ProtocolBugs{
3402 ExpectRecordSplitting: true,
3403 },
David Benjamina1ce8562017-07-01 11:46:57 -04003404 },
3405 messageLen: -1, // read until EOF
3406 resumeSession: true,
3407 flags: []string{
3408 "-async",
3409 "-write-different-record-sizes",
3410 "-cbc-record-splitting",
3411 },
3412 })
3413 testCases = append(testCases, testCase{
3414 name: "CBCRecordSplittingPartialWrite-" + t.name,
3415 config: Config{
3416 MaxVersion: VersionTLS10,
3417 MinVersion: VersionTLS10,
3418 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003419 Bugs: ProtocolBugs{
3420 ExpectRecordSplitting: true,
3421 },
David Benjamina1ce8562017-07-01 11:46:57 -04003422 },
3423 messageLen: -1, // read until EOF
3424 flags: []string{
3425 "-async",
3426 "-write-different-record-sizes",
3427 "-cbc-record-splitting",
3428 "-partial-write",
3429 },
3430 })
3431 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003432}
3433
David Benjamin636293b2014-07-08 17:59:18 -04003434func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003435 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003436 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003437 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3438 cert, err := x509.ParseCertificate(cert.Certificate[0])
3439 if err != nil {
3440 panic(err)
3441 }
3442 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003443 }
Adam Langley2ff79332017-02-28 13:45:39 -08003444 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003445
David Benjamin636293b2014-07-08 17:59:18 -04003446 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003447 testCases = append(testCases, testCase{
3448 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003449 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003450 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003451 MinVersion: ver.version,
3452 MaxVersion: ver.version,
3453 ClientAuth: RequireAnyClientCert,
3454 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003455 },
David Benjamina5022392017-07-10 17:40:39 -04003456 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003457 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003458 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3459 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003460 },
3461 })
3462 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003463 testType: serverTest,
3464 name: ver.name + "-Server-ClientAuth-RSA",
3465 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003466 MinVersion: ver.version,
3467 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003468 Certificates: []Certificate{rsaCertificate},
3469 },
David Benjamina5022392017-07-10 17:40:39 -04003470 tls13Variant: ver.tls13Variant,
3471 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003472 })
David Benjamine098ec22014-08-27 23:13:20 -04003473 if ver.version != VersionSSL30 {
3474 testCases = append(testCases, testCase{
3475 testType: serverTest,
3476 name: ver.name + "-Server-ClientAuth-ECDSA",
3477 config: Config{
3478 MinVersion: ver.version,
3479 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003480 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003481 },
David Benjamina5022392017-07-10 17:40:39 -04003482 tls13Variant: ver.tls13Variant,
3483 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003484 })
3485 testCases = append(testCases, testCase{
3486 testType: clientTest,
3487 name: ver.name + "-Client-ClientAuth-ECDSA",
3488 config: Config{
3489 MinVersion: ver.version,
3490 MaxVersion: ver.version,
3491 ClientAuth: RequireAnyClientCert,
3492 ClientCAs: certPool,
3493 },
David Benjamina5022392017-07-10 17:40:39 -04003494 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003495 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003496 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3497 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003498 },
3499 })
3500 }
Adam Langley37646832016-08-01 16:16:46 -07003501
3502 testCases = append(testCases, testCase{
3503 name: "NoClientCertificate-" + ver.name,
3504 config: Config{
3505 MinVersion: ver.version,
3506 MaxVersion: ver.version,
3507 ClientAuth: RequireAnyClientCert,
3508 },
David Benjamina5022392017-07-10 17:40:39 -04003509 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003510 shouldFail: true,
3511 expectedLocalError: "client didn't provide a certificate",
3512 })
3513
3514 testCases = append(testCases, testCase{
3515 // Even if not configured to expect a certificate, OpenSSL will
3516 // return X509_V_OK as the verify_result.
3517 testType: serverTest,
3518 name: "NoClientCertificateRequested-Server-" + ver.name,
3519 config: Config{
3520 MinVersion: ver.version,
3521 MaxVersion: ver.version,
3522 },
David Benjamina5022392017-07-10 17:40:39 -04003523 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003524 flags: []string{
3525 "-expect-verify-result",
3526 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003527 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003528 })
3529
3530 testCases = append(testCases, testCase{
3531 // If a client certificate is not provided, OpenSSL will still
3532 // return X509_V_OK as the verify_result.
3533 testType: serverTest,
3534 name: "NoClientCertificate-Server-" + ver.name,
3535 config: Config{
3536 MinVersion: ver.version,
3537 MaxVersion: ver.version,
3538 },
David Benjamina5022392017-07-10 17:40:39 -04003539 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003540 flags: []string{
3541 "-expect-verify-result",
3542 "-verify-peer",
3543 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003544 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003545 })
3546
David Benjamin1db9e1b2016-10-07 20:51:43 -04003547 certificateRequired := "remote error: certificate required"
3548 if ver.version < VersionTLS13 {
3549 // Prior to TLS 1.3, the generic handshake_failure alert
3550 // was used.
3551 certificateRequired = "remote error: handshake failure"
3552 }
Adam Langley37646832016-08-01 16:16:46 -07003553 testCases = append(testCases, testCase{
3554 testType: serverTest,
3555 name: "RequireAnyClientCertificate-" + ver.name,
3556 config: Config{
3557 MinVersion: ver.version,
3558 MaxVersion: ver.version,
3559 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003560 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003561 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003562 shouldFail: true,
3563 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3564 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003565 })
3566
3567 if ver.version != VersionSSL30 {
3568 testCases = append(testCases, testCase{
3569 testType: serverTest,
3570 name: "SkipClientCertificate-" + ver.name,
3571 config: Config{
3572 MinVersion: ver.version,
3573 MaxVersion: ver.version,
3574 Bugs: ProtocolBugs{
3575 SkipClientCertificate: true,
3576 },
3577 },
3578 // Setting SSL_VERIFY_PEER allows anonymous clients.
3579 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003580 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003581 shouldFail: true,
3582 expectedError: ":UNEXPECTED_MESSAGE:",
3583 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003584
3585 testCases = append(testCases, testCase{
3586 testType: serverTest,
3587 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3588 config: Config{
3589 MinVersion: ver.version,
3590 MaxVersion: ver.version,
3591 },
3592 flags: []string{
3593 "-enable-channel-id",
3594 "-verify-peer-if-no-obc",
3595 },
David Benjamina5022392017-07-10 17:40:39 -04003596 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003597 shouldFail: true,
3598 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3599 expectedLocalError: certificateRequired,
3600 })
3601
3602 testCases = append(testCases, testCase{
3603 testType: serverTest,
3604 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3605 config: Config{
3606 MinVersion: ver.version,
3607 MaxVersion: ver.version,
3608 ChannelID: channelIDKey,
3609 },
3610 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003611 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003612 flags: []string{
3613 "-enable-channel-id",
3614 "-verify-peer-if-no-obc",
3615 },
3616 })
Adam Langley37646832016-08-01 16:16:46 -07003617 }
Adam Langley2ff79332017-02-28 13:45:39 -08003618
3619 testCases = append(testCases, testCase{
3620 testType: serverTest,
3621 name: ver.name + "-Server-CertReq-CA-List",
3622 config: Config{
3623 MinVersion: ver.version,
3624 MaxVersion: ver.version,
3625 Certificates: []Certificate{rsaCertificate},
3626 Bugs: ProtocolBugs{
3627 ExpectCertificateReqNames: caNames,
3628 },
3629 },
David Benjamina5022392017-07-10 17:40:39 -04003630 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003631 flags: []string{
3632 "-require-any-client-certificate",
3633 "-use-client-ca-list", encodeDERValues(caNames),
3634 },
3635 })
3636
3637 testCases = append(testCases, testCase{
3638 testType: clientTest,
3639 name: ver.name + "-Client-CertReq-CA-List",
3640 config: Config{
3641 MinVersion: ver.version,
3642 MaxVersion: ver.version,
3643 Certificates: []Certificate{rsaCertificate},
3644 ClientAuth: RequireAnyClientCert,
3645 ClientCAs: certPool,
3646 },
David Benjamina5022392017-07-10 17:40:39 -04003647 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003648 flags: []string{
3649 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3650 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3651 "-expect-client-ca-list", encodeDERValues(caNames),
3652 },
3653 })
David Benjamin636293b2014-07-08 17:59:18 -04003654 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003655
David Benjaminc032dfa2016-05-12 14:54:57 -04003656 // Client auth is only legal in certificate-based ciphers.
3657 testCases = append(testCases, testCase{
3658 testType: clientTest,
3659 name: "ClientAuth-PSK",
3660 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003661 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003662 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3663 PreSharedKey: []byte("secret"),
3664 ClientAuth: RequireAnyClientCert,
3665 },
3666 flags: []string{
3667 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3668 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3669 "-psk", "secret",
3670 },
3671 shouldFail: true,
3672 expectedError: ":UNEXPECTED_MESSAGE:",
3673 })
3674 testCases = append(testCases, testCase{
3675 testType: clientTest,
3676 name: "ClientAuth-ECDHE_PSK",
3677 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003678 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003679 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3680 PreSharedKey: []byte("secret"),
3681 ClientAuth: RequireAnyClientCert,
3682 },
3683 flags: []string{
3684 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3685 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3686 "-psk", "secret",
3687 },
3688 shouldFail: true,
3689 expectedError: ":UNEXPECTED_MESSAGE:",
3690 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003691
3692 // Regression test for a bug where the client CA list, if explicitly
3693 // set to NULL, was mis-encoded.
3694 testCases = append(testCases, testCase{
3695 testType: serverTest,
3696 name: "Null-Client-CA-List",
3697 config: Config{
3698 MaxVersion: VersionTLS12,
3699 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003700 Bugs: ProtocolBugs{
3701 ExpectCertificateReqNames: [][]byte{},
3702 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003703 },
3704 flags: []string{
3705 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003706 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003707 },
3708 })
David Benjamin636293b2014-07-08 17:59:18 -04003709}
3710
Adam Langley75712922014-10-10 16:23:43 -07003711func addExtendedMasterSecretTests() {
3712 const expectEMSFlag = "-expect-extended-master-secret"
3713
3714 for _, with := range []bool{false, true} {
3715 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003716 if with {
3717 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003718 }
3719
3720 for _, isClient := range []bool{false, true} {
3721 suffix := "-Server"
3722 testType := serverTest
3723 if isClient {
3724 suffix = "-Client"
3725 testType = clientTest
3726 }
3727
3728 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003729 // In TLS 1.3, the extension is irrelevant and
3730 // always reports as enabled.
3731 var flags []string
3732 if with || ver.version >= VersionTLS13 {
3733 flags = []string{expectEMSFlag}
3734 }
3735
Adam Langley75712922014-10-10 16:23:43 -07003736 test := testCase{
3737 testType: testType,
3738 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3739 config: Config{
3740 MinVersion: ver.version,
3741 MaxVersion: ver.version,
3742 Bugs: ProtocolBugs{
3743 NoExtendedMasterSecret: !with,
3744 RequireExtendedMasterSecret: with,
3745 },
3746 },
David Benjamina5022392017-07-10 17:40:39 -04003747 tls13Variant: ver.tls13Variant,
3748 flags: flags,
3749 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003750 }
3751 if test.shouldFail {
3752 test.expectedLocalError = "extended master secret required but not supported by peer"
3753 }
3754 testCases = append(testCases, test)
3755 }
3756 }
3757 }
3758
Adam Langleyba5934b2015-06-02 10:50:35 -07003759 for _, isClient := range []bool{false, true} {
3760 for _, supportedInFirstConnection := range []bool{false, true} {
3761 for _, supportedInResumeConnection := range []bool{false, true} {
3762 boolToWord := func(b bool) string {
3763 if b {
3764 return "Yes"
3765 }
3766 return "No"
3767 }
3768 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3769 if isClient {
3770 suffix += "Client"
3771 } else {
3772 suffix += "Server"
3773 }
3774
3775 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003776 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003777 Bugs: ProtocolBugs{
3778 RequireExtendedMasterSecret: true,
3779 },
3780 }
3781
3782 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003784 Bugs: ProtocolBugs{
3785 NoExtendedMasterSecret: true,
3786 },
3787 }
3788
3789 test := testCase{
3790 name: "ExtendedMasterSecret-" + suffix,
3791 resumeSession: true,
3792 }
3793
3794 if !isClient {
3795 test.testType = serverTest
3796 }
3797
3798 if supportedInFirstConnection {
3799 test.config = supportedConfig
3800 } else {
3801 test.config = noSupportConfig
3802 }
3803
3804 if supportedInResumeConnection {
3805 test.resumeConfig = &supportedConfig
3806 } else {
3807 test.resumeConfig = &noSupportConfig
3808 }
3809
3810 switch suffix {
3811 case "YesToYes-Client", "YesToYes-Server":
3812 // When a session is resumed, it should
3813 // still be aware that its master
3814 // secret was generated via EMS and
3815 // thus it's safe to use tls-unique.
3816 test.flags = []string{expectEMSFlag}
3817 case "NoToYes-Server":
3818 // If an original connection did not
3819 // contain EMS, but a resumption
3820 // handshake does, then a server should
3821 // not resume the session.
3822 test.expectResumeRejected = true
3823 case "YesToNo-Server":
3824 // Resuming an EMS session without the
3825 // EMS extension should cause the
3826 // server to abort the connection.
3827 test.shouldFail = true
3828 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3829 case "NoToYes-Client":
3830 // A client should abort a connection
3831 // where the server resumed a non-EMS
3832 // session but echoed the EMS
3833 // extension.
3834 test.shouldFail = true
3835 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3836 case "YesToNo-Client":
3837 // A client should abort a connection
3838 // where the server didn't echo EMS
3839 // when the session used it.
3840 test.shouldFail = true
3841 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3842 }
3843
3844 testCases = append(testCases, test)
3845 }
3846 }
3847 }
David Benjamin163c9562016-08-29 23:14:17 -04003848
3849 // Switching EMS on renegotiation is forbidden.
3850 testCases = append(testCases, testCase{
3851 name: "ExtendedMasterSecret-Renego-NoEMS",
3852 config: Config{
3853 MaxVersion: VersionTLS12,
3854 Bugs: ProtocolBugs{
3855 NoExtendedMasterSecret: true,
3856 NoExtendedMasterSecretOnRenegotiation: true,
3857 },
3858 },
3859 renegotiate: 1,
3860 flags: []string{
3861 "-renegotiate-freely",
3862 "-expect-total-renegotiations", "1",
3863 },
3864 })
3865
3866 testCases = append(testCases, testCase{
3867 name: "ExtendedMasterSecret-Renego-Upgrade",
3868 config: Config{
3869 MaxVersion: VersionTLS12,
3870 Bugs: ProtocolBugs{
3871 NoExtendedMasterSecret: true,
3872 },
3873 },
3874 renegotiate: 1,
3875 flags: []string{
3876 "-renegotiate-freely",
3877 "-expect-total-renegotiations", "1",
3878 },
3879 shouldFail: true,
3880 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3881 })
3882
3883 testCases = append(testCases, testCase{
3884 name: "ExtendedMasterSecret-Renego-Downgrade",
3885 config: Config{
3886 MaxVersion: VersionTLS12,
3887 Bugs: ProtocolBugs{
3888 NoExtendedMasterSecretOnRenegotiation: true,
3889 },
3890 },
3891 renegotiate: 1,
3892 flags: []string{
3893 "-renegotiate-freely",
3894 "-expect-total-renegotiations", "1",
3895 },
3896 shouldFail: true,
3897 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3898 })
Adam Langley75712922014-10-10 16:23:43 -07003899}
3900
David Benjamin582ba042016-07-07 12:33:25 -07003901type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003902 protocol protocol
3903 async bool
3904 splitHandshake bool
3905 packHandshakeFlight bool
3906 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003907}
3908
David Benjamin43ec06f2014-08-05 02:28:57 -04003909// Adds tests that try to cover the range of the handshake state machine, under
3910// various conditions. Some of these are redundant with other tests, but they
3911// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003912func addAllStateMachineCoverageTests() {
3913 for _, async := range []bool{false, true} {
3914 for _, protocol := range []protocol{tls, dtls} {
3915 addStateMachineCoverageTests(stateMachineTestConfig{
3916 protocol: protocol,
3917 async: async,
3918 })
3919 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003920 protocol: protocol,
3921 async: async,
3922 implicitHandshake: true,
3923 })
3924 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003925 protocol: protocol,
3926 async: async,
3927 splitHandshake: true,
3928 })
3929 if protocol == tls {
3930 addStateMachineCoverageTests(stateMachineTestConfig{
3931 protocol: protocol,
3932 async: async,
3933 packHandshakeFlight: true,
3934 })
3935 }
3936 }
3937 }
3938}
3939
3940func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003941 var tests []testCase
3942
3943 // Basic handshake, with resumption. Client and server,
3944 // session ID and session ticket.
3945 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 name: "Basic-Client",
3947 config: Config{
3948 MaxVersion: VersionTLS12,
3949 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003951 // Ensure session tickets are used, not session IDs.
3952 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 })
3954 tests = append(tests, testCase{
3955 name: "Basic-Client-RenewTicket",
3956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003957 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003958 Bugs: ProtocolBugs{
3959 RenewTicketOnResume: true,
3960 },
3961 },
David Benjamin46662482016-08-17 00:51:00 -04003962 flags: []string{"-expect-ticket-renewal"},
3963 resumeSession: true,
3964 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003965 })
3966 tests = append(tests, testCase{
3967 name: "Basic-Client-NoTicket",
3968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 SessionTicketsDisabled: true,
3971 },
3972 resumeSession: true,
3973 })
3974 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003975 testType: serverTest,
3976 name: "Basic-Server",
3977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003978 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003979 Bugs: ProtocolBugs{
3980 RequireSessionTickets: true,
3981 },
3982 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003983 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003984 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003985 })
3986 tests = append(tests, testCase{
3987 testType: serverTest,
3988 name: "Basic-Server-NoTickets",
3989 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003990 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003991 SessionTicketsDisabled: true,
3992 },
3993 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003994 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003995 })
3996 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003997 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003998 name: "Basic-Server-EarlyCallback",
3999 config: Config{
4000 MaxVersion: VersionTLS12,
4001 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004002 flags: []string{"-use-early-callback"},
4003 resumeSession: true,
4004 })
4005
Steven Valdez143e8b32016-07-11 13:19:03 -04004006 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004007 if config.protocol == tls {
4008 tests = append(tests, testCase{
4009 name: "TLS13-1RTT-Client",
4010 config: Config{
4011 MaxVersion: VersionTLS13,
4012 MinVersion: VersionTLS13,
4013 },
David Benjamin46662482016-08-17 00:51:00 -04004014 resumeSession: true,
4015 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004016 })
4017
4018 tests = append(tests, testCase{
4019 testType: serverTest,
4020 name: "TLS13-1RTT-Server",
4021 config: Config{
4022 MaxVersion: VersionTLS13,
4023 MinVersion: VersionTLS13,
4024 },
David Benjamin46662482016-08-17 00:51:00 -04004025 resumeSession: true,
4026 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004027 // TLS 1.3 uses tickets, so the session should not be
4028 // cached statefully.
4029 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004030 })
4031
4032 tests = append(tests, testCase{
4033 name: "TLS13-HelloRetryRequest-Client",
4034 config: Config{
4035 MaxVersion: VersionTLS13,
4036 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004037 // P-384 requires a HelloRetryRequest against BoringSSL's default
4038 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004039 CurvePreferences: []CurveID{CurveP384},
4040 Bugs: ProtocolBugs{
4041 ExpectMissingKeyShare: true,
4042 },
4043 },
4044 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4045 resumeSession: true,
4046 })
4047
4048 tests = append(tests, testCase{
4049 testType: serverTest,
4050 name: "TLS13-HelloRetryRequest-Server",
4051 config: Config{
4052 MaxVersion: VersionTLS13,
4053 MinVersion: VersionTLS13,
4054 // Require a HelloRetryRequest for every curve.
4055 DefaultCurves: []CurveID{},
4056 },
4057 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4058 resumeSession: true,
4059 })
Steven Valdez2d850622017-01-11 11:34:52 -05004060
Steven Valdez2d850622017-01-11 11:34:52 -05004061 tests = append(tests, testCase{
4062 testType: clientTest,
4063 name: "TLS13-EarlyData-Client",
4064 config: Config{
4065 MaxVersion: VersionTLS13,
4066 MinVersion: VersionTLS13,
4067 MaxEarlyDataSize: 16384,
4068 },
Steven Valdeze831a812017-03-09 14:56:07 -05004069 resumeConfig: &Config{
4070 MaxVersion: VersionTLS13,
4071 MinVersion: VersionTLS13,
4072 MaxEarlyDataSize: 16384,
4073 Bugs: ProtocolBugs{
4074 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4075 },
4076 },
Steven Valdez2d850622017-01-11 11:34:52 -05004077 resumeSession: true,
4078 flags: []string{
4079 "-enable-early-data",
4080 "-expect-early-data-info",
4081 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004082 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004083 },
4084 })
4085
4086 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004087 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004088 name: "TLS13Experiment-EarlyData-Client",
4089 config: Config{
4090 MaxVersion: VersionTLS13,
4091 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004092 MaxEarlyDataSize: 16384,
4093 },
4094 resumeConfig: &Config{
4095 MaxVersion: VersionTLS13,
4096 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004097 MaxEarlyDataSize: 16384,
4098 Bugs: ProtocolBugs{
4099 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4100 },
4101 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004102 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004103 resumeSession: true,
4104 flags: []string{
4105 "-enable-early-data",
4106 "-expect-early-data-info",
4107 "-expect-accept-early-data",
4108 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004109 },
4110 })
4111
4112 tests = append(tests, testCase{
4113 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004114 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4115 config: Config{
4116 MaxVersion: VersionTLS13,
4117 MinVersion: VersionTLS13,
4118 TLS13Variant: TLS13RecordTypeExperiment,
4119 MaxEarlyDataSize: 16384,
4120 },
4121 resumeConfig: &Config{
4122 MaxVersion: VersionTLS13,
4123 MinVersion: VersionTLS13,
4124 TLS13Variant: TLS13RecordTypeExperiment,
4125 MaxEarlyDataSize: 16384,
4126 Bugs: ProtocolBugs{
4127 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4128 },
4129 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004130 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004131 resumeSession: true,
4132 flags: []string{
4133 "-enable-early-data",
4134 "-expect-early-data-info",
4135 "-expect-accept-early-data",
4136 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004137 },
4138 })
4139
4140 tests = append(tests, testCase{
4141 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004142 name: "TLS13-EarlyData-TooMuchData-Client",
4143 config: Config{
4144 MaxVersion: VersionTLS13,
4145 MinVersion: VersionTLS13,
4146 MaxEarlyDataSize: 2,
4147 },
4148 resumeConfig: &Config{
4149 MaxVersion: VersionTLS13,
4150 MinVersion: VersionTLS13,
4151 MaxEarlyDataSize: 2,
4152 Bugs: ProtocolBugs{
4153 ExpectEarlyData: [][]byte{{'h', 'e'}},
4154 },
4155 },
4156 resumeShimPrefix: "llo",
4157 resumeSession: true,
4158 flags: []string{
4159 "-enable-early-data",
4160 "-expect-early-data-info",
4161 "-expect-accept-early-data",
4162 "-on-resume-shim-writes-first",
4163 },
4164 })
4165
4166 // Unfinished writes can only be tested when operations are async. EarlyData
4167 // can't be tested as part of an ImplicitHandshake in this case since
4168 // otherwise the early data will be sent as normal data.
4169 if config.async && !config.implicitHandshake {
4170 tests = append(tests, testCase{
4171 testType: clientTest,
4172 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4173 config: Config{
4174 MaxVersion: VersionTLS13,
4175 MinVersion: VersionTLS13,
4176 MaxEarlyDataSize: 16384,
4177 },
4178 resumeConfig: &Config{
4179 MaxVersion: VersionTLS13,
4180 MinVersion: VersionTLS13,
4181 MaxEarlyDataSize: 16384,
4182 Bugs: ProtocolBugs{
4183 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4184 },
4185 },
4186 resumeSession: true,
4187 flags: []string{
4188 "-enable-early-data",
4189 "-expect-early-data-info",
4190 "-expect-accept-early-data",
4191 "-on-resume-read-with-unfinished-write",
4192 "-on-resume-shim-writes-first",
4193 },
4194 })
4195
4196 // Rejected unfinished writes are discarded (from the
4197 // perspective of the calling application) on 0-RTT
4198 // reject.
4199 tests = append(tests, testCase{
4200 testType: clientTest,
4201 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4202 config: Config{
4203 MaxVersion: VersionTLS13,
4204 MinVersion: VersionTLS13,
4205 MaxEarlyDataSize: 16384,
4206 },
4207 resumeConfig: &Config{
4208 MaxVersion: VersionTLS13,
4209 MinVersion: VersionTLS13,
4210 MaxEarlyDataSize: 16384,
4211 Bugs: ProtocolBugs{
4212 AlwaysRejectEarlyData: true,
4213 },
4214 },
4215 resumeSession: true,
4216 flags: []string{
4217 "-enable-early-data",
4218 "-expect-early-data-info",
4219 "-expect-reject-early-data",
4220 "-on-resume-read-with-unfinished-write",
4221 "-on-resume-shim-writes-first",
4222 },
4223 })
4224 }
4225
4226 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004227 testType: serverTest,
4228 name: "TLS13-EarlyData-Server",
4229 config: Config{
4230 MaxVersion: VersionTLS13,
4231 MinVersion: VersionTLS13,
4232 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004233 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004234 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004235 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004236 },
4237 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004238 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004239 resumeSession: true,
4240 flags: []string{
4241 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004242 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004243 },
4244 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004245
4246 tests = append(tests, testCase{
4247 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004248 name: "TLS13Experiment-EarlyData-Server",
4249 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004250 MaxVersion: VersionTLS13,
4251 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004252 Bugs: ProtocolBugs{
4253 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4254 ExpectEarlyDataAccepted: true,
4255 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4256 },
4257 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004258 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004259 messageCount: 2,
4260 resumeSession: true,
4261 flags: []string{
4262 "-enable-early-data",
4263 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004264 },
4265 })
4266
4267 tests = append(tests, testCase{
4268 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004269 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4270 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004271 MaxVersion: VersionTLS13,
4272 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004273 Bugs: ProtocolBugs{
4274 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4275 ExpectEarlyDataAccepted: true,
4276 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4277 },
4278 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004279 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004280 messageCount: 2,
4281 resumeSession: true,
4282 flags: []string{
4283 "-enable-early-data",
4284 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004285 },
4286 })
4287
4288 tests = append(tests, testCase{
4289 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004290 name: "TLS13-MaxEarlyData-Server",
4291 config: Config{
4292 MaxVersion: VersionTLS13,
4293 MinVersion: VersionTLS13,
4294 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004295 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004296 ExpectEarlyDataAccepted: true,
4297 },
4298 },
4299 messageCount: 2,
4300 resumeSession: true,
4301 flags: []string{
4302 "-enable-early-data",
4303 "-expect-accept-early-data",
4304 },
4305 shouldFail: true,
4306 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4307 })
David Benjamine73c7f42016-08-17 00:29:33 -04004308 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004309
David Benjamin760b1dd2015-05-15 23:33:48 -04004310 // TLS client auth.
4311 tests = append(tests, testCase{
4312 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004313 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004315 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004316 ClientAuth: RequestClientCert,
4317 },
4318 })
4319 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004320 testType: serverTest,
4321 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 config: Config{
4323 MaxVersion: VersionTLS12,
4324 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004325 // Setting SSL_VERIFY_PEER allows anonymous clients.
4326 flags: []string{"-verify-peer"},
4327 })
David Benjamin582ba042016-07-07 12:33:25 -07004328 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004329 tests = append(tests, testCase{
4330 testType: clientTest,
4331 name: "ClientAuth-NoCertificate-Client-SSL3",
4332 config: Config{
4333 MaxVersion: VersionSSL30,
4334 ClientAuth: RequestClientCert,
4335 },
4336 })
4337 tests = append(tests, testCase{
4338 testType: serverTest,
4339 name: "ClientAuth-NoCertificate-Server-SSL3",
4340 config: Config{
4341 MaxVersion: VersionSSL30,
4342 },
4343 // Setting SSL_VERIFY_PEER allows anonymous clients.
4344 flags: []string{"-verify-peer"},
4345 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004346 tests = append(tests, testCase{
4347 testType: clientTest,
4348 name: "ClientAuth-NoCertificate-Client-TLS13",
4349 config: Config{
4350 MaxVersion: VersionTLS13,
4351 ClientAuth: RequestClientCert,
4352 },
4353 })
4354 tests = append(tests, testCase{
4355 testType: serverTest,
4356 name: "ClientAuth-NoCertificate-Server-TLS13",
4357 config: Config{
4358 MaxVersion: VersionTLS13,
4359 },
4360 // Setting SSL_VERIFY_PEER allows anonymous clients.
4361 flags: []string{"-verify-peer"},
4362 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004363 }
4364 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004365 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004366 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004368 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004369 ClientAuth: RequireAnyClientCert,
4370 },
4371 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004372 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4373 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004374 },
4375 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004376 tests = append(tests, testCase{
4377 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004378 name: "ClientAuth-RSA-Client-TLS13",
4379 config: Config{
4380 MaxVersion: VersionTLS13,
4381 ClientAuth: RequireAnyClientCert,
4382 },
4383 flags: []string{
4384 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4385 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4386 },
4387 })
4388 tests = append(tests, testCase{
4389 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004390 name: "ClientAuth-ECDSA-Client",
4391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004392 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004393 ClientAuth: RequireAnyClientCert,
4394 },
4395 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004396 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4397 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004398 },
4399 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004400 tests = append(tests, testCase{
4401 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004402 name: "ClientAuth-ECDSA-Client-TLS13",
4403 config: Config{
4404 MaxVersion: VersionTLS13,
4405 ClientAuth: RequireAnyClientCert,
4406 },
4407 flags: []string{
4408 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4409 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4410 },
4411 })
4412 tests = append(tests, testCase{
4413 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004414 name: "ClientAuth-NoCertificate-OldCallback",
4415 config: Config{
4416 MaxVersion: VersionTLS12,
4417 ClientAuth: RequestClientCert,
4418 },
4419 flags: []string{"-use-old-client-cert-callback"},
4420 })
4421 tests = append(tests, testCase{
4422 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004423 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4424 config: Config{
4425 MaxVersion: VersionTLS13,
4426 ClientAuth: RequestClientCert,
4427 },
4428 flags: []string{"-use-old-client-cert-callback"},
4429 })
4430 tests = append(tests, testCase{
4431 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004432 name: "ClientAuth-OldCallback",
4433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004434 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004435 ClientAuth: RequireAnyClientCert,
4436 },
4437 flags: []string{
4438 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4439 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4440 "-use-old-client-cert-callback",
4441 },
4442 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004443 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004444 testType: clientTest,
4445 name: "ClientAuth-OldCallback-TLS13",
4446 config: Config{
4447 MaxVersion: VersionTLS13,
4448 ClientAuth: RequireAnyClientCert,
4449 },
4450 flags: []string{
4451 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4452 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4453 "-use-old-client-cert-callback",
4454 },
4455 })
4456 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004457 testType: serverTest,
4458 name: "ClientAuth-Server",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 Certificates: []Certificate{rsaCertificate},
4462 },
4463 flags: []string{"-require-any-client-certificate"},
4464 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004465 tests = append(tests, testCase{
4466 testType: serverTest,
4467 name: "ClientAuth-Server-TLS13",
4468 config: Config{
4469 MaxVersion: VersionTLS13,
4470 Certificates: []Certificate{rsaCertificate},
4471 },
4472 flags: []string{"-require-any-client-certificate"},
4473 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004474
David Benjamin4c3ddf72016-06-29 18:13:53 -04004475 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004476 tests = append(tests, testCase{
4477 testType: serverTest,
4478 name: "Basic-Server-RSA",
4479 config: Config{
4480 MaxVersion: VersionTLS12,
4481 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4482 },
4483 flags: []string{
4484 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4485 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4486 },
4487 })
4488 tests = append(tests, testCase{
4489 testType: serverTest,
4490 name: "Basic-Server-ECDHE-RSA",
4491 config: Config{
4492 MaxVersion: VersionTLS12,
4493 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4494 },
4495 flags: []string{
4496 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4497 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4498 },
4499 })
4500 tests = append(tests, testCase{
4501 testType: serverTest,
4502 name: "Basic-Server-ECDHE-ECDSA",
4503 config: Config{
4504 MaxVersion: VersionTLS12,
4505 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4506 },
4507 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004508 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4509 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004510 },
4511 })
David Benjamin69522112017-03-28 15:38:29 -05004512 tests = append(tests, testCase{
4513 testType: serverTest,
4514 name: "Basic-Server-Ed25519",
4515 config: Config{
4516 MaxVersion: VersionTLS12,
4517 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4518 },
4519 flags: []string{
4520 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4521 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4522 "-enable-ed25519",
4523 },
4524 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004525
David Benjamin760b1dd2015-05-15 23:33:48 -04004526 // No session ticket support; server doesn't send NewSessionTicket.
4527 tests = append(tests, testCase{
4528 name: "SessionTicketsDisabled-Client",
4529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004530 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004531 SessionTicketsDisabled: true,
4532 },
4533 })
4534 tests = append(tests, testCase{
4535 testType: serverTest,
4536 name: "SessionTicketsDisabled-Server",
4537 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004538 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004539 SessionTicketsDisabled: true,
4540 },
4541 })
4542
4543 // Skip ServerKeyExchange in PSK key exchange if there's no
4544 // identity hint.
4545 tests = append(tests, testCase{
4546 name: "EmptyPSKHint-Client",
4547 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004548 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004549 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4550 PreSharedKey: []byte("secret"),
4551 },
4552 flags: []string{"-psk", "secret"},
4553 })
4554 tests = append(tests, testCase{
4555 testType: serverTest,
4556 name: "EmptyPSKHint-Server",
4557 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004558 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004559 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4560 PreSharedKey: []byte("secret"),
4561 },
4562 flags: []string{"-psk", "secret"},
4563 })
4564
David Benjamin4c3ddf72016-06-29 18:13:53 -04004565 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004566 tests = append(tests, testCase{
4567 testType: clientTest,
4568 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004569 config: Config{
4570 MaxVersion: VersionTLS12,
4571 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004572 flags: []string{
4573 "-enable-ocsp-stapling",
4574 "-expect-ocsp-response",
4575 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004576 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004577 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004578 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004579 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004580 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004581 testType: serverTest,
4582 name: "OCSPStapling-Server",
4583 config: Config{
4584 MaxVersion: VersionTLS12,
4585 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004586 expectedOCSPResponse: testOCSPResponse,
4587 flags: []string{
4588 "-ocsp-response",
4589 base64.StdEncoding.EncodeToString(testOCSPResponse),
4590 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004591 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004592 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004593 tests = append(tests, testCase{
4594 testType: clientTest,
4595 name: "OCSPStapling-Client-TLS13",
4596 config: Config{
4597 MaxVersion: VersionTLS13,
4598 },
4599 flags: []string{
4600 "-enable-ocsp-stapling",
4601 "-expect-ocsp-response",
4602 base64.StdEncoding.EncodeToString(testOCSPResponse),
4603 "-verify-peer",
4604 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004605 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004606 })
4607 tests = append(tests, testCase{
4608 testType: serverTest,
4609 name: "OCSPStapling-Server-TLS13",
4610 config: Config{
4611 MaxVersion: VersionTLS13,
4612 },
4613 expectedOCSPResponse: testOCSPResponse,
4614 flags: []string{
4615 "-ocsp-response",
4616 base64.StdEncoding.EncodeToString(testOCSPResponse),
4617 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004618 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004619 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004620
David Benjamin4c3ddf72016-06-29 18:13:53 -04004621 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004622 for _, vers := range tlsVersions {
4623 if config.protocol == dtls && !vers.hasDTLS {
4624 continue
4625 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004626 for _, useCustomCallback := range []bool{false, true} {
4627 for _, testType := range []testType{clientTest, serverTest} {
4628 suffix := "-Client"
4629 if testType == serverTest {
4630 suffix = "-Server"
4631 }
4632 suffix += "-" + vers.name
4633 if useCustomCallback {
4634 suffix += "-CustomCallback"
4635 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004636
David Benjamin3a1dd462017-07-11 16:13:10 -04004637 flags := []string{"-verify-peer"}
4638 if testType == serverTest {
4639 flags = append(flags, "-require-any-client-certificate")
4640 }
4641 if useCustomCallback {
4642 flags = append(flags, "-use-custom-verify-callback")
4643 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004644
David Benjamin3a1dd462017-07-11 16:13:10 -04004645 tests = append(tests, testCase{
4646 testType: testType,
4647 name: "CertificateVerificationSucceed" + suffix,
4648 config: Config{
4649 MaxVersion: vers.version,
4650 Certificates: []Certificate{rsaCertificate},
4651 },
4652 tls13Variant: vers.tls13Variant,
4653 flags: append([]string{"-expect-verify-result"}, flags...),
4654 resumeSession: true,
4655 })
4656 tests = append(tests, testCase{
4657 testType: testType,
4658 name: "CertificateVerificationFail" + suffix,
4659 config: Config{
4660 MaxVersion: vers.version,
4661 Certificates: []Certificate{rsaCertificate},
4662 },
4663 tls13Variant: vers.tls13Variant,
4664 flags: append([]string{"-verify-fail"}, flags...),
4665 shouldFail: true,
4666 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4667 })
4668 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004669 }
4670
4671 // By default, the client is in a soft fail mode where the peer
4672 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004673 tests = append(tests, testCase{
4674 testType: clientTest,
4675 name: "CertificateVerificationSoftFail-" + vers.name,
4676 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004677 MaxVersion: vers.version,
4678 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004679 },
David Benjamina5022392017-07-10 17:40:39 -04004680 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004681 flags: []string{
4682 "-verify-fail",
4683 "-expect-verify-result",
4684 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004685 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004686 })
4687 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004688
David Benjamin1d4f4c02016-07-26 18:03:08 -04004689 tests = append(tests, testCase{
4690 name: "ShimSendAlert",
4691 flags: []string{"-send-alert"},
4692 shimWritesFirst: true,
4693 shouldFail: true,
4694 expectedLocalError: "remote error: decompression failure",
4695 })
4696
David Benjamin582ba042016-07-07 12:33:25 -07004697 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004698 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004699 name: "Renegotiate-Client",
4700 config: Config{
4701 MaxVersion: VersionTLS12,
4702 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004703 renegotiate: 1,
4704 flags: []string{
4705 "-renegotiate-freely",
4706 "-expect-total-renegotiations", "1",
4707 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004709
David Benjamin47921102016-07-28 11:29:18 -04004710 tests = append(tests, testCase{
4711 name: "SendHalfHelloRequest",
4712 config: Config{
4713 MaxVersion: VersionTLS12,
4714 Bugs: ProtocolBugs{
4715 PackHelloRequestWithFinished: config.packHandshakeFlight,
4716 },
4717 },
4718 sendHalfHelloRequest: true,
4719 flags: []string{"-renegotiate-ignore"},
4720 shouldFail: true,
4721 expectedError: ":UNEXPECTED_RECORD:",
4722 })
4723
David Benjamin760b1dd2015-05-15 23:33:48 -04004724 // NPN on client and server; results in post-handshake message.
4725 tests = append(tests, testCase{
4726 name: "NPN-Client",
4727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004728 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004729 NextProtos: []string{"foo"},
4730 },
4731 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004732 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004733 expectedNextProto: "foo",
4734 expectedNextProtoType: npn,
4735 })
4736 tests = append(tests, testCase{
4737 testType: serverTest,
4738 name: "NPN-Server",
4739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004740 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004741 NextProtos: []string{"bar"},
4742 },
4743 flags: []string{
4744 "-advertise-npn", "\x03foo\x03bar\x03baz",
4745 "-expect-next-proto", "bar",
4746 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004747 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004748 expectedNextProto: "bar",
4749 expectedNextProtoType: npn,
4750 })
4751
4752 // TODO(davidben): Add tests for when False Start doesn't trigger.
4753
4754 // Client does False Start and negotiates NPN.
4755 tests = append(tests, testCase{
4756 name: "FalseStart",
4757 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004758 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004759 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4760 NextProtos: []string{"foo"},
4761 Bugs: ProtocolBugs{
4762 ExpectFalseStart: true,
4763 },
4764 },
4765 flags: []string{
4766 "-false-start",
4767 "-select-next-proto", "foo",
4768 },
4769 shimWritesFirst: true,
4770 resumeSession: true,
4771 })
4772
4773 // Client does False Start and negotiates ALPN.
4774 tests = append(tests, testCase{
4775 name: "FalseStart-ALPN",
4776 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004777 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4779 NextProtos: []string{"foo"},
4780 Bugs: ProtocolBugs{
4781 ExpectFalseStart: true,
4782 },
4783 },
4784 flags: []string{
4785 "-false-start",
4786 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004787 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004788 },
4789 shimWritesFirst: true,
4790 resumeSession: true,
4791 })
4792
David Benjamin760b1dd2015-05-15 23:33:48 -04004793 // False Start without session tickets.
4794 tests = append(tests, testCase{
4795 name: "FalseStart-SessionTicketsDisabled",
4796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004797 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4799 NextProtos: []string{"foo"},
4800 SessionTicketsDisabled: true,
4801 Bugs: ProtocolBugs{
4802 ExpectFalseStart: true,
4803 },
4804 },
4805 flags: []string{
4806 "-false-start",
4807 "-select-next-proto", "foo",
4808 },
4809 shimWritesFirst: true,
4810 })
4811
4812 // Server parses a V2ClientHello.
4813 tests = append(tests, testCase{
4814 testType: serverTest,
4815 name: "SendV2ClientHello",
4816 config: Config{
4817 // Choose a cipher suite that does not involve
4818 // elliptic curves, so no extensions are
4819 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004820 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004821 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004822 Bugs: ProtocolBugs{
4823 SendV2ClientHello: true,
4824 },
4825 },
David Benjamin78b8b992017-08-01 18:38:41 -04004826 flags: []string{
4827 "-expect-msg-callback",
4828 `read v2clienthello
4829write hs 2
4830write hs 11
4831write hs 14
4832read hs 16
4833read ccs
4834read hs 20
4835write ccs
4836write hs 20
4837read alert 1 0
4838`,
4839 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004840 })
4841
Nick Harper60a85cb2016-09-23 16:25:11 -07004842 // Test Channel ID
4843 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004844 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004845 continue
4846 }
4847 // Client sends a Channel ID.
4848 tests = append(tests, testCase{
4849 name: "ChannelID-Client-" + ver.name,
4850 config: Config{
4851 MaxVersion: ver.version,
4852 RequestChannelID: true,
4853 },
David Benjamina5022392017-07-10 17:40:39 -04004854 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004855 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4856 resumeSession: true,
4857 expectChannelID: true,
4858 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004859
Nick Harper60a85cb2016-09-23 16:25:11 -07004860 // Server accepts a Channel ID.
4861 tests = append(tests, testCase{
4862 testType: serverTest,
4863 name: "ChannelID-Server-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 ChannelID: channelIDKey,
4867 },
David Benjamina5022392017-07-10 17:40:39 -04004868 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004869 flags: []string{
4870 "-expect-channel-id",
4871 base64.StdEncoding.EncodeToString(channelIDBytes),
4872 },
4873 resumeSession: true,
4874 expectChannelID: true,
4875 })
4876
4877 tests = append(tests, testCase{
4878 testType: serverTest,
4879 name: "InvalidChannelIDSignature-" + ver.name,
4880 config: Config{
4881 MaxVersion: ver.version,
4882 ChannelID: channelIDKey,
4883 Bugs: ProtocolBugs{
4884 InvalidChannelIDSignature: true,
4885 },
4886 },
David Benjamina5022392017-07-10 17:40:39 -04004887 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004888 flags: []string{"-enable-channel-id"},
4889 shouldFail: true,
4890 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4891 })
David Benjamin634f4752017-07-01 11:08:41 -04004892
4893 if ver.version < VersionTLS13 {
4894 // Channel ID requires ECDHE ciphers.
4895 tests = append(tests, testCase{
4896 testType: serverTest,
4897 name: "ChannelID-NoECDHE-" + ver.name,
4898 config: Config{
4899 MaxVersion: ver.version,
4900 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4901 ChannelID: channelIDKey,
4902 },
4903 expectChannelID: false,
4904 flags: []string{"-enable-channel-id"},
4905 })
4906
4907 // Sanity-check setting expectChannelID false works.
4908 tests = append(tests, testCase{
4909 testType: serverTest,
4910 name: "ChannelID-ECDHE-" + ver.name,
4911 config: Config{
4912 MaxVersion: ver.version,
4913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4914 ChannelID: channelIDKey,
4915 },
4916 expectChannelID: false,
4917 flags: []string{"-enable-channel-id"},
4918 shouldFail: true,
4919 expectedLocalError: "channel ID unexpectedly negotiated",
4920 })
4921 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004922 }
David Benjamin30789da2015-08-29 22:56:45 -04004923
David Benjaminf8fcdf32016-06-08 15:56:13 -04004924 // Channel ID and NPN at the same time, to ensure their relative
4925 // ordering is correct.
4926 tests = append(tests, testCase{
4927 name: "ChannelID-NPN-Client",
4928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004929 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004930 RequestChannelID: true,
4931 NextProtos: []string{"foo"},
4932 },
4933 flags: []string{
4934 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4935 "-select-next-proto", "foo",
4936 },
4937 resumeSession: true,
4938 expectChannelID: true,
4939 expectedNextProto: "foo",
4940 expectedNextProtoType: npn,
4941 })
4942 tests = append(tests, testCase{
4943 testType: serverTest,
4944 name: "ChannelID-NPN-Server",
4945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004946 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004947 ChannelID: channelIDKey,
4948 NextProtos: []string{"bar"},
4949 },
4950 flags: []string{
4951 "-expect-channel-id",
4952 base64.StdEncoding.EncodeToString(channelIDBytes),
4953 "-advertise-npn", "\x03foo\x03bar\x03baz",
4954 "-expect-next-proto", "bar",
4955 },
4956 resumeSession: true,
4957 expectChannelID: true,
4958 expectedNextProto: "bar",
4959 expectedNextProtoType: npn,
4960 })
4961
David Benjamin30789da2015-08-29 22:56:45 -04004962 // Bidirectional shutdown with the runner initiating.
4963 tests = append(tests, testCase{
4964 name: "Shutdown-Runner",
4965 config: Config{
4966 Bugs: ProtocolBugs{
4967 ExpectCloseNotify: true,
4968 },
4969 },
4970 flags: []string{"-check-close-notify"},
4971 })
4972
David Benjamine3843d42017-03-25 18:00:56 -05004973 if !config.implicitHandshake {
4974 // Bidirectional shutdown with the shim initiating. The runner,
4975 // in the meantime, sends garbage before the close_notify which
4976 // the shim must ignore. This test is disabled under implicit
4977 // handshake tests because the shim never reads or writes.
4978 tests = append(tests, testCase{
4979 name: "Shutdown-Shim",
4980 config: Config{
4981 MaxVersion: VersionTLS12,
4982 Bugs: ProtocolBugs{
4983 ExpectCloseNotify: true,
4984 },
David Benjamin30789da2015-08-29 22:56:45 -04004985 },
David Benjamine3843d42017-03-25 18:00:56 -05004986 shimShutsDown: true,
4987 sendEmptyRecords: 1,
4988 sendWarningAlerts: 1,
4989 flags: []string{"-check-close-notify"},
4990 })
4991 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004992 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004993 // TODO(davidben): DTLS 1.3 will want a similar thing for
4994 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004995 tests = append(tests, testCase{
4996 name: "SkipHelloVerifyRequest",
4997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004998 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004999 Bugs: ProtocolBugs{
5000 SkipHelloVerifyRequest: true,
5001 },
5002 },
5003 })
5004 }
5005
David Benjamin760b1dd2015-05-15 23:33:48 -04005006 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07005007 test.protocol = config.protocol
5008 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005009 test.name += "-DTLS"
5010 }
David Benjamin582ba042016-07-07 12:33:25 -07005011 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05005012 test.name += "-Async"
5013 test.flags = append(test.flags, "-async")
5014 } else {
5015 test.name += "-Sync"
5016 }
David Benjamin582ba042016-07-07 12:33:25 -07005017 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005018 test.name += "-SplitHandshakeRecords"
5019 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005020 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005021 test.config.Bugs.MaxPacketLength = 256
5022 test.flags = append(test.flags, "-mtu", "256")
5023 }
5024 }
David Benjamin582ba042016-07-07 12:33:25 -07005025 if config.packHandshakeFlight {
5026 test.name += "-PackHandshakeFlight"
5027 test.config.Bugs.PackHandshakeFlight = true
5028 }
David Benjamine3843d42017-03-25 18:00:56 -05005029 if config.implicitHandshake {
5030 test.name += "-ImplicitHandshake"
5031 test.flags = append(test.flags, "-implicit-handshake")
5032 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005033 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005034 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005035}
5036
Adam Langley524e7172015-02-20 16:04:00 -08005037func addDDoSCallbackTests() {
5038 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005039 for _, resume := range []bool{false, true} {
5040 suffix := "Resume"
5041 if resume {
5042 suffix = "No" + suffix
5043 }
5044
5045 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005046 testType: serverTest,
5047 name: "Server-DDoS-OK-" + suffix,
5048 config: Config{
5049 MaxVersion: VersionTLS12,
5050 },
Adam Langley524e7172015-02-20 16:04:00 -08005051 flags: []string{"-install-ddos-callback"},
5052 resumeSession: resume,
5053 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005054 testCases = append(testCases, testCase{
5055 testType: serverTest,
5056 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5057 config: Config{
5058 MaxVersion: VersionTLS13,
5059 },
5060 flags: []string{"-install-ddos-callback"},
5061 resumeSession: resume,
5062 })
Adam Langley524e7172015-02-20 16:04:00 -08005063
5064 failFlag := "-fail-ddos-callback"
5065 if resume {
5066 failFlag = "-fail-second-ddos-callback"
5067 }
5068 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005069 testType: serverTest,
5070 name: "Server-DDoS-Reject-" + suffix,
5071 config: Config{
5072 MaxVersion: VersionTLS12,
5073 },
David Benjamin2c66e072016-09-16 15:58:00 -04005074 flags: []string{"-install-ddos-callback", failFlag},
5075 resumeSession: resume,
5076 shouldFail: true,
5077 expectedError: ":CONNECTION_REJECTED:",
5078 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005079 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5083 config: Config{
5084 MaxVersion: VersionTLS13,
5085 },
David Benjamin2c66e072016-09-16 15:58:00 -04005086 flags: []string{"-install-ddos-callback", failFlag},
5087 resumeSession: resume,
5088 shouldFail: true,
5089 expectedError: ":CONNECTION_REJECTED:",
5090 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005091 })
Adam Langley524e7172015-02-20 16:04:00 -08005092 }
5093}
5094
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005095func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005096 for _, protocol := range []protocol{tls, dtls} {
5097 for _, shimVers := range allVersions(protocol) {
5098 // Assemble flags to disable all newer versions on the shim.
5099 var flags []string
5100 for _, vers := range allVersions(protocol) {
5101 if vers.version > shimVers.version {
5102 flags = append(flags, vers.excludeFlag)
5103 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005104 }
Steven Valdez520e1222017-06-13 12:45:25 -04005105
5106 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5107
5108 if shimVers.tls13Variant != 0 {
5109 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5110 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5111 }
5112
5113 // Test configuring the runner's maximum version.
5114 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005115 expectedVersion := shimVers.version
5116 if runnerVers.version < shimVers.version {
5117 expectedVersion = runnerVers.version
5118 }
Steven Valdez520e1222017-06-13 12:45:25 -04005119 // When running and shim have different TLS 1.3 variants enabled,
5120 // shim clients are expected to fall back to TLS 1.2, while shim
5121 // servers support both variants when enabled when the experiment is
5122 // enabled.
5123 expectedServerVersion := expectedVersion
5124 expectedClientVersion := expectedVersion
5125 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5126 expectedClientVersion = VersionTLS12
5127 expectedServerVersion = VersionTLS12
5128 if shimVers.tls13Variant != TLS13Default {
5129 expectedServerVersion = VersionTLS13
5130 }
5131 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005132
David Benjamin8b8c0062014-11-23 02:47:52 -05005133 suffix := shimVers.name + "-" + runnerVers.name
5134 if protocol == dtls {
5135 suffix += "-DTLS"
5136 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005137
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005138 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005139 clientVers := shimVers.version
5140 if clientVers > VersionTLS10 {
5141 clientVers = VersionTLS10
5142 }
Steven Valdez520e1222017-06-13 12:45:25 -04005143 clientVers = recordVersionToWire(clientVers, protocol)
5144 serverVers := expectedServerVersion
5145 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005146 serverVers = VersionTLS10
5147 }
Steven Valdez520e1222017-06-13 12:45:25 -04005148 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005149
David Benjamin8b8c0062014-11-23 02:47:52 -05005150 testCases = append(testCases, testCase{
5151 protocol: protocol,
5152 testType: clientTest,
5153 name: "VersionNegotiation-Client-" + suffix,
5154 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005155 MaxVersion: runnerVers.version,
5156 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005157 Bugs: ProtocolBugs{
5158 ExpectInitialRecordVersion: clientVers,
5159 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005160 },
5161 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005162 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005163 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005164 testCases = append(testCases, testCase{
5165 protocol: protocol,
5166 testType: clientTest,
5167 name: "VersionNegotiation-Client2-" + suffix,
5168 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005169 MaxVersion: runnerVers.version,
5170 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005171 Bugs: ProtocolBugs{
5172 ExpectInitialRecordVersion: clientVers,
5173 },
5174 },
Steven Valdez520e1222017-06-13 12:45:25 -04005175 flags: flags2,
5176 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005177 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005178
5179 testCases = append(testCases, testCase{
5180 protocol: protocol,
5181 testType: serverTest,
5182 name: "VersionNegotiation-Server-" + suffix,
5183 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005184 MaxVersion: runnerVers.version,
5185 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005186 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005187 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005188 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005189 },
5190 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005191 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005192 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005193 testCases = append(testCases, testCase{
5194 protocol: protocol,
5195 testType: serverTest,
5196 name: "VersionNegotiation-Server2-" + suffix,
5197 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005198 MaxVersion: runnerVers.version,
5199 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005200 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005201 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005202 },
5203 },
Steven Valdez520e1222017-06-13 12:45:25 -04005204 flags: flags2,
5205 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005206 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005207 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005208 }
5209 }
David Benjamin95c69562016-06-29 18:15:03 -04005210
Steven Valdezfdd10992016-09-15 16:27:05 -04005211 // Test the version extension at all versions.
5212 for _, vers := range tlsVersions {
5213 protocols := []protocol{tls}
5214 if vers.hasDTLS {
5215 protocols = append(protocols, dtls)
5216 }
5217 for _, protocol := range protocols {
5218 suffix := vers.name
5219 if protocol == dtls {
5220 suffix += "-DTLS"
5221 }
5222
Steven Valdezfdd10992016-09-15 16:27:05 -04005223 testCases = append(testCases, testCase{
5224 protocol: protocol,
5225 testType: serverTest,
5226 name: "VersionNegotiationExtension-" + suffix,
5227 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005228 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005230 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005231 },
5232 },
5233 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005234 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005235 })
5236 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005237 }
5238
5239 // If all versions are unknown, negotiation fails.
5240 testCases = append(testCases, testCase{
5241 testType: serverTest,
5242 name: "NoSupportedVersions",
5243 config: Config{
5244 Bugs: ProtocolBugs{
5245 SendSupportedVersions: []uint16{0x1111},
5246 },
5247 },
5248 shouldFail: true,
5249 expectedError: ":UNSUPPORTED_PROTOCOL:",
5250 })
5251 testCases = append(testCases, testCase{
5252 protocol: dtls,
5253 testType: serverTest,
5254 name: "NoSupportedVersions-DTLS",
5255 config: Config{
5256 Bugs: ProtocolBugs{
5257 SendSupportedVersions: []uint16{0x1111},
5258 },
5259 },
5260 shouldFail: true,
5261 expectedError: ":UNSUPPORTED_PROTOCOL:",
5262 })
5263
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "ClientHelloVersionTooHigh",
5267 config: Config{
5268 MaxVersion: VersionTLS13,
5269 Bugs: ProtocolBugs{
5270 SendClientVersion: 0x0304,
5271 OmitSupportedVersions: true,
5272 },
5273 },
5274 expectedVersion: VersionTLS12,
5275 })
5276
5277 testCases = append(testCases, testCase{
5278 testType: serverTest,
5279 name: "ConflictingVersionNegotiation",
5280 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005281 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005282 SendClientVersion: VersionTLS12,
5283 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005284 },
5285 },
David Benjaminad75a662016-09-30 15:42:59 -04005286 // The extension takes precedence over the ClientHello version.
5287 expectedVersion: VersionTLS11,
5288 })
5289
5290 testCases = append(testCases, testCase{
5291 testType: serverTest,
5292 name: "ConflictingVersionNegotiation-2",
5293 config: Config{
5294 Bugs: ProtocolBugs{
5295 SendClientVersion: VersionTLS11,
5296 SendSupportedVersions: []uint16{VersionTLS12},
5297 },
5298 },
5299 // The extension takes precedence over the ClientHello version.
5300 expectedVersion: VersionTLS12,
5301 })
5302
5303 testCases = append(testCases, testCase{
5304 testType: serverTest,
5305 name: "RejectFinalTLS13",
5306 config: Config{
5307 Bugs: ProtocolBugs{
5308 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5309 },
5310 },
5311 // We currently implement a draft TLS 1.3 version. Ensure that
5312 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005313 expectedVersion: VersionTLS12,
5314 })
5315
Steven Valdez038da9b2017-07-10 12:57:25 -04005316 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5317 // the ServerHello.
5318 testCases = append(testCases, testCase{
5319 testType: clientTest,
5320 name: "SupportedVersionSelection-TLS12",
5321 config: Config{
5322 MaxVersion: VersionTLS12,
5323 Bugs: ProtocolBugs{
5324 SendServerSupportedExtensionVersion: VersionTLS12,
5325 },
5326 },
5327 shouldFail: true,
5328 expectedError: ":UNEXPECTED_EXTENSION:",
5329 })
5330
5331 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5332 // supported_versions extension in the ServerHello.
5333 testCases = append(testCases, testCase{
5334 testType: clientTest,
5335 name: "SupportedVersionSelection-TLS13",
5336 config: Config{
5337 MaxVersion: VersionTLS13,
5338 Bugs: ProtocolBugs{
5339 SendServerSupportedExtensionVersion: tls13DraftVersion,
5340 },
5341 },
5342 shouldFail: true,
5343 expectedError: ":UNEXPECTED_EXTENSION:",
5344 })
5345
Brian Smithf85d3232016-10-28 10:34:06 -10005346 // Test that the maximum version is selected regardless of the
5347 // client-sent order.
5348 testCases = append(testCases, testCase{
5349 testType: serverTest,
5350 name: "IgnoreClientVersionOrder",
5351 config: Config{
5352 Bugs: ProtocolBugs{
5353 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5354 },
5355 },
5356 expectedVersion: VersionTLS13,
5357 })
5358
David Benjamin95c69562016-06-29 18:15:03 -04005359 // Test for version tolerance.
5360 testCases = append(testCases, testCase{
5361 testType: serverTest,
5362 name: "MinorVersionTolerance",
5363 config: Config{
5364 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005365 SendClientVersion: 0x03ff,
5366 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005367 },
5368 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005369 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005370 })
5371 testCases = append(testCases, testCase{
5372 testType: serverTest,
5373 name: "MajorVersionTolerance",
5374 config: Config{
5375 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005376 SendClientVersion: 0x0400,
5377 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005378 },
5379 },
David Benjaminad75a662016-09-30 15:42:59 -04005380 // TLS 1.3 must be negotiated with the supported_versions
5381 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005382 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005383 })
David Benjaminad75a662016-09-30 15:42:59 -04005384 testCases = append(testCases, testCase{
5385 testType: serverTest,
5386 name: "VersionTolerance-TLS13",
5387 config: Config{
5388 Bugs: ProtocolBugs{
5389 // Although TLS 1.3 does not use
5390 // ClientHello.version, it still tolerates high
5391 // values there.
5392 SendClientVersion: 0x0400,
5393 },
5394 },
5395 expectedVersion: VersionTLS13,
5396 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005397
David Benjamin95c69562016-06-29 18:15:03 -04005398 testCases = append(testCases, testCase{
5399 protocol: dtls,
5400 testType: serverTest,
5401 name: "MinorVersionTolerance-DTLS",
5402 config: Config{
5403 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005404 SendClientVersion: 0xfe00,
5405 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005406 },
5407 },
5408 expectedVersion: VersionTLS12,
5409 })
5410 testCases = append(testCases, testCase{
5411 protocol: dtls,
5412 testType: serverTest,
5413 name: "MajorVersionTolerance-DTLS",
5414 config: Config{
5415 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005416 SendClientVersion: 0xfdff,
5417 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005418 },
5419 },
5420 expectedVersion: VersionTLS12,
5421 })
5422
5423 // Test that versions below 3.0 are rejected.
5424 testCases = append(testCases, testCase{
5425 testType: serverTest,
5426 name: "VersionTooLow",
5427 config: Config{
5428 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005429 SendClientVersion: 0x0200,
5430 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":UNSUPPORTED_PROTOCOL:",
5435 })
5436 testCases = append(testCases, testCase{
5437 protocol: dtls,
5438 testType: serverTest,
5439 name: "VersionTooLow-DTLS",
5440 config: Config{
5441 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005442 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":UNSUPPORTED_PROTOCOL:",
5447 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005448
David Benjamin2dc02042016-09-19 19:57:37 -04005449 testCases = append(testCases, testCase{
5450 name: "ServerBogusVersion",
5451 config: Config{
5452 Bugs: ProtocolBugs{
5453 SendServerHelloVersion: 0x1234,
5454 },
5455 },
5456 shouldFail: true,
5457 expectedError: ":UNSUPPORTED_PROTOCOL:",
5458 })
5459
David Benjamin1f61f0d2016-07-10 12:20:35 -04005460 // Test TLS 1.3's downgrade signal.
5461 testCases = append(testCases, testCase{
5462 name: "Downgrade-TLS12-Client",
5463 config: Config{
5464 Bugs: ProtocolBugs{
5465 NegotiateVersion: VersionTLS12,
5466 },
5467 },
David Benjamin592b5322016-09-30 15:15:01 -04005468 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005469 // TODO(davidben): This test should fail once TLS 1.3 is final
5470 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005471 })
5472 testCases = append(testCases, testCase{
5473 testType: serverTest,
5474 name: "Downgrade-TLS12-Server",
5475 config: Config{
5476 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005477 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005478 },
5479 },
David Benjamin592b5322016-09-30 15:15:01 -04005480 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005481 // TODO(davidben): This test should fail once TLS 1.3 is final
5482 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005483 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005484}
5485
David Benjaminaccb4542014-12-12 23:44:33 -05005486func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005487 for _, protocol := range []protocol{tls, dtls} {
5488 for _, shimVers := range allVersions(protocol) {
5489 // Assemble flags to disable all older versions on the shim.
5490 var flags []string
5491 for _, vers := range allVersions(protocol) {
5492 if vers.version < shimVers.version {
5493 flags = append(flags, vers.excludeFlag)
5494 }
David Benjaminaccb4542014-12-12 23:44:33 -05005495 }
Steven Valdez520e1222017-06-13 12:45:25 -04005496
5497 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5498
5499 if shimVers.tls13Variant != 0 {
5500 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5501 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5502 }
5503
5504 for _, runnerVers := range allVersions(protocol) {
5505 // Different TLS 1.3 variants are incompatible with each other and don't
5506 // produce consistent minimum versions.
5507 //
5508 // TODO(davidben): Fold these tests (the main value is in the
5509 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5510 // on intended shim behavior, not the shim + runner combination.
5511 if shimVers.tls13Variant != runnerVers.tls13Variant {
5512 continue
5513 }
5514
David Benjaminaccb4542014-12-12 23:44:33 -05005515 suffix := shimVers.name + "-" + runnerVers.name
5516 if protocol == dtls {
5517 suffix += "-DTLS"
5518 }
David Benjaminaccb4542014-12-12 23:44:33 -05005519
David Benjaminaccb4542014-12-12 23:44:33 -05005520 var expectedVersion uint16
5521 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005522 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005523 if runnerVers.version >= shimVers.version {
5524 expectedVersion = runnerVers.version
5525 } else {
5526 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005527 expectedError = ":UNSUPPORTED_PROTOCOL:"
5528 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005529 }
5530
5531 testCases = append(testCases, testCase{
5532 protocol: protocol,
5533 testType: clientTest,
5534 name: "MinimumVersion-Client-" + suffix,
5535 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005536 MaxVersion: runnerVers.version,
5537 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005538 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005539 // Ensure the server does not decline to
5540 // select a version (versions extension) or
5541 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005542 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005543 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005544 },
David Benjaminaccb4542014-12-12 23:44:33 -05005545 },
David Benjamin87909c02014-12-13 01:55:01 -05005546 flags: flags,
5547 expectedVersion: expectedVersion,
5548 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005549 expectedError: expectedError,
5550 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005551 })
5552 testCases = append(testCases, testCase{
5553 protocol: protocol,
5554 testType: clientTest,
5555 name: "MinimumVersion-Client2-" + suffix,
5556 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005557 MaxVersion: runnerVers.version,
5558 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005559 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005560 // Ensure the server does not decline to
5561 // select a version (versions extension) or
5562 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005563 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005564 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005565 },
David Benjaminaccb4542014-12-12 23:44:33 -05005566 },
Steven Valdez520e1222017-06-13 12:45:25 -04005567 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005568 expectedVersion: expectedVersion,
5569 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005570 expectedError: expectedError,
5571 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005572 })
5573
5574 testCases = append(testCases, testCase{
5575 protocol: protocol,
5576 testType: serverTest,
5577 name: "MinimumVersion-Server-" + suffix,
5578 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005579 MaxVersion: runnerVers.version,
5580 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005581 },
David Benjamin87909c02014-12-13 01:55:01 -05005582 flags: flags,
5583 expectedVersion: expectedVersion,
5584 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005585 expectedError: expectedError,
5586 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005587 })
5588 testCases = append(testCases, testCase{
5589 protocol: protocol,
5590 testType: serverTest,
5591 name: "MinimumVersion-Server2-" + suffix,
5592 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005593 MaxVersion: runnerVers.version,
5594 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005595 },
Steven Valdez520e1222017-06-13 12:45:25 -04005596 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005597 expectedVersion: expectedVersion,
5598 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005599 expectedError: expectedError,
5600 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005601 })
5602 }
5603 }
5604 }
5605}
5606
David Benjamine78bfde2014-09-06 12:45:15 -04005607func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005608 // TODO(davidben): Extensions, where applicable, all move their server
5609 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5610 // tests for both. Also test interaction with 0-RTT when implemented.
5611
David Benjamin97d17d92016-07-14 16:12:00 -04005612 // Repeat extensions tests all versions except SSL 3.0.
5613 for _, ver := range tlsVersions {
5614 if ver.version == VersionSSL30 {
5615 continue
5616 }
5617
David Benjamin97d17d92016-07-14 16:12:00 -04005618 // Test that duplicate extensions are rejected.
5619 testCases = append(testCases, testCase{
5620 testType: clientTest,
5621 name: "DuplicateExtensionClient-" + ver.name,
5622 config: Config{
5623 MaxVersion: ver.version,
5624 Bugs: ProtocolBugs{
5625 DuplicateExtension: true,
5626 },
David Benjamine78bfde2014-09-06 12:45:15 -04005627 },
David Benjamina5022392017-07-10 17:40:39 -04005628 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005629 shouldFail: true,
5630 expectedLocalError: "remote error: error decoding message",
5631 })
5632 testCases = append(testCases, testCase{
5633 testType: serverTest,
5634 name: "DuplicateExtensionServer-" + ver.name,
5635 config: Config{
5636 MaxVersion: ver.version,
5637 Bugs: ProtocolBugs{
5638 DuplicateExtension: true,
5639 },
David Benjamine78bfde2014-09-06 12:45:15 -04005640 },
David Benjamina5022392017-07-10 17:40:39 -04005641 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005642 shouldFail: true,
5643 expectedLocalError: "remote error: error decoding message",
5644 })
5645
5646 // Test SNI.
5647 testCases = append(testCases, testCase{
5648 testType: clientTest,
5649 name: "ServerNameExtensionClient-" + ver.name,
5650 config: Config{
5651 MaxVersion: ver.version,
5652 Bugs: ProtocolBugs{
5653 ExpectServerName: "example.com",
5654 },
David Benjamine78bfde2014-09-06 12:45:15 -04005655 },
David Benjamina5022392017-07-10 17:40:39 -04005656 tls13Variant: ver.tls13Variant,
5657 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005658 })
5659 testCases = append(testCases, testCase{
5660 testType: clientTest,
5661 name: "ServerNameExtensionClientMismatch-" + ver.name,
5662 config: Config{
5663 MaxVersion: ver.version,
5664 Bugs: ProtocolBugs{
5665 ExpectServerName: "mismatch.com",
5666 },
David Benjamine78bfde2014-09-06 12:45:15 -04005667 },
David Benjamin97d17d92016-07-14 16:12:00 -04005668 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005669 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005670 shouldFail: true,
5671 expectedLocalError: "tls: unexpected server name",
5672 })
5673 testCases = append(testCases, testCase{
5674 testType: clientTest,
5675 name: "ServerNameExtensionClientMissing-" + ver.name,
5676 config: Config{
5677 MaxVersion: ver.version,
5678 Bugs: ProtocolBugs{
5679 ExpectServerName: "missing.com",
5680 },
David Benjamine78bfde2014-09-06 12:45:15 -04005681 },
David Benjamina5022392017-07-10 17:40:39 -04005682 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005683 shouldFail: true,
5684 expectedLocalError: "tls: unexpected server name",
5685 })
5686 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005687 testType: clientTest,
5688 name: "TolerateServerNameAck-" + ver.name,
5689 config: Config{
5690 MaxVersion: ver.version,
5691 Bugs: ProtocolBugs{
5692 SendServerNameAck: true,
5693 },
5694 },
David Benjamina5022392017-07-10 17:40:39 -04005695 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005696 flags: []string{"-host-name", "example.com"},
5697 resumeSession: true,
5698 })
5699 testCases = append(testCases, testCase{
5700 testType: clientTest,
5701 name: "UnsolicitedServerNameAck-" + ver.name,
5702 config: Config{
5703 MaxVersion: ver.version,
5704 Bugs: ProtocolBugs{
5705 SendServerNameAck: true,
5706 },
5707 },
David Benjamina5022392017-07-10 17:40:39 -04005708 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005709 shouldFail: true,
5710 expectedError: ":UNEXPECTED_EXTENSION:",
5711 expectedLocalError: "remote error: unsupported extension",
5712 })
5713 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005714 testType: serverTest,
5715 name: "ServerNameExtensionServer-" + ver.name,
5716 config: Config{
5717 MaxVersion: ver.version,
5718 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005719 },
David Benjamina5022392017-07-10 17:40:39 -04005720 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005721 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005722 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005723 })
5724
5725 // Test ALPN.
5726 testCases = append(testCases, testCase{
5727 testType: clientTest,
5728 name: "ALPNClient-" + ver.name,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 NextProtos: []string{"foo"},
5732 },
5733 flags: []string{
5734 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5735 "-expect-alpn", "foo",
5736 },
David Benjamina5022392017-07-10 17:40:39 -04005737 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005738 expectedNextProto: "foo",
5739 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005740 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005741 })
5742 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005743 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005744 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005745 config: Config{
5746 MaxVersion: ver.version,
5747 Bugs: ProtocolBugs{
5748 SendALPN: "baz",
5749 },
5750 },
5751 flags: []string{
5752 "-advertise-alpn", "\x03foo\x03bar",
5753 },
David Benjamina5022392017-07-10 17:40:39 -04005754 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005755 shouldFail: true,
5756 expectedError: ":INVALID_ALPN_PROTOCOL:",
5757 expectedLocalError: "remote error: illegal parameter",
5758 })
5759 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005760 testType: clientTest,
5761 name: "ALPNClient-AllowUnknown-" + ver.name,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 Bugs: ProtocolBugs{
5765 SendALPN: "baz",
5766 },
5767 },
5768 flags: []string{
5769 "-advertise-alpn", "\x03foo\x03bar",
5770 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005771 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005772 },
David Benjamina5022392017-07-10 17:40:39 -04005773 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005774 })
5775 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005776 testType: serverTest,
5777 name: "ALPNServer-" + ver.name,
5778 config: Config{
5779 MaxVersion: ver.version,
5780 NextProtos: []string{"foo", "bar", "baz"},
5781 },
5782 flags: []string{
5783 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5784 "-select-alpn", "foo",
5785 },
David Benjamina5022392017-07-10 17:40:39 -04005786 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005787 expectedNextProto: "foo",
5788 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005789 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005790 })
5791 testCases = append(testCases, testCase{
5792 testType: serverTest,
5793 name: "ALPNServer-Decline-" + ver.name,
5794 config: Config{
5795 MaxVersion: ver.version,
5796 NextProtos: []string{"foo", "bar", "baz"},
5797 },
5798 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005799 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005800 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005801 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005802 })
5803
David Benjamin25fe85b2016-08-09 20:00:32 -04005804 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5805 // called once.
5806 testCases = append(testCases, testCase{
5807 testType: serverTest,
5808 name: "ALPNServer-Async-" + ver.name,
5809 config: Config{
5810 MaxVersion: ver.version,
5811 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005812 // Prior to TLS 1.3, exercise the asynchronous session callback.
5813 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005814 },
5815 flags: []string{
5816 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5817 "-select-alpn", "foo",
5818 "-async",
5819 },
David Benjamina5022392017-07-10 17:40:39 -04005820 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005821 expectedNextProto: "foo",
5822 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005823 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005824 })
5825
David Benjamin97d17d92016-07-14 16:12:00 -04005826 var emptyString string
5827 testCases = append(testCases, testCase{
5828 testType: clientTest,
5829 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5830 config: Config{
5831 MaxVersion: ver.version,
5832 NextProtos: []string{""},
5833 Bugs: ProtocolBugs{
5834 // A server returning an empty ALPN protocol
5835 // should be rejected.
5836 ALPNProtocol: &emptyString,
5837 },
5838 },
5839 flags: []string{
5840 "-advertise-alpn", "\x03foo",
5841 },
David Benjamina5022392017-07-10 17:40:39 -04005842 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005843 shouldFail: true,
5844 expectedError: ":PARSE_TLSEXT:",
5845 })
5846 testCases = append(testCases, testCase{
5847 testType: serverTest,
5848 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5849 config: Config{
5850 MaxVersion: ver.version,
5851 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005852 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005853 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005854 },
David Benjamin97d17d92016-07-14 16:12:00 -04005855 flags: []string{
5856 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005857 },
David Benjamina5022392017-07-10 17:40:39 -04005858 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005859 shouldFail: true,
5860 expectedError: ":PARSE_TLSEXT:",
5861 })
5862
5863 // Test NPN and the interaction with ALPN.
5864 if ver.version < VersionTLS13 {
5865 // Test that the server prefers ALPN over NPN.
5866 testCases = append(testCases, testCase{
5867 testType: serverTest,
5868 name: "ALPNServer-Preferred-" + ver.name,
5869 config: Config{
5870 MaxVersion: ver.version,
5871 NextProtos: []string{"foo", "bar", "baz"},
5872 },
5873 flags: []string{
5874 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5875 "-select-alpn", "foo",
5876 "-advertise-npn", "\x03foo\x03bar\x03baz",
5877 },
David Benjamina5022392017-07-10 17:40:39 -04005878 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005879 expectedNextProto: "foo",
5880 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005881 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005882 })
5883 testCases = append(testCases, testCase{
5884 testType: serverTest,
5885 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5886 config: Config{
5887 MaxVersion: ver.version,
5888 NextProtos: []string{"foo", "bar", "baz"},
5889 Bugs: ProtocolBugs{
5890 SwapNPNAndALPN: true,
5891 },
5892 },
5893 flags: []string{
5894 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5895 "-select-alpn", "foo",
5896 "-advertise-npn", "\x03foo\x03bar\x03baz",
5897 },
David Benjamina5022392017-07-10 17:40:39 -04005898 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005899 expectedNextProto: "foo",
5900 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005901 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005902 })
5903
5904 // Test that negotiating both NPN and ALPN is forbidden.
5905 testCases = append(testCases, testCase{
5906 name: "NegotiateALPNAndNPN-" + ver.name,
5907 config: Config{
5908 MaxVersion: ver.version,
5909 NextProtos: []string{"foo", "bar", "baz"},
5910 Bugs: ProtocolBugs{
5911 NegotiateALPNAndNPN: true,
5912 },
5913 },
5914 flags: []string{
5915 "-advertise-alpn", "\x03foo",
5916 "-select-next-proto", "foo",
5917 },
David Benjamina5022392017-07-10 17:40:39 -04005918 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005919 shouldFail: true,
5920 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5921 })
5922 testCases = append(testCases, testCase{
5923 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5924 config: Config{
5925 MaxVersion: ver.version,
5926 NextProtos: []string{"foo", "bar", "baz"},
5927 Bugs: ProtocolBugs{
5928 NegotiateALPNAndNPN: true,
5929 SwapNPNAndALPN: true,
5930 },
5931 },
5932 flags: []string{
5933 "-advertise-alpn", "\x03foo",
5934 "-select-next-proto", "foo",
5935 },
David Benjamina5022392017-07-10 17:40:39 -04005936 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005937 shouldFail: true,
5938 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5939 })
David Benjamin97d17d92016-07-14 16:12:00 -04005940 }
5941
5942 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005943
5944 // Resume with a corrupt ticket.
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
5947 name: "CorruptTicket-" + ver.name,
5948 config: Config{
5949 MaxVersion: ver.version,
5950 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005951 FilterTicket: func(in []byte) ([]byte, error) {
5952 in[len(in)-1] ^= 1
5953 return in, nil
5954 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005955 },
5956 },
David Benjamina5022392017-07-10 17:40:39 -04005957 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005958 resumeSession: true,
5959 expectResumeRejected: true,
5960 })
5961 // Test the ticket callback, with and without renewal.
5962 testCases = append(testCases, testCase{
5963 testType: serverTest,
5964 name: "TicketCallback-" + ver.name,
5965 config: Config{
5966 MaxVersion: ver.version,
5967 },
David Benjamina5022392017-07-10 17:40:39 -04005968 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005969 resumeSession: true,
5970 flags: []string{"-use-ticket-callback"},
5971 })
5972 testCases = append(testCases, testCase{
5973 testType: serverTest,
5974 name: "TicketCallback-Renew-" + ver.name,
5975 config: Config{
5976 MaxVersion: ver.version,
5977 Bugs: ProtocolBugs{
5978 ExpectNewTicket: true,
5979 },
5980 },
David Benjamina5022392017-07-10 17:40:39 -04005981 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005982 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5983 resumeSession: true,
5984 })
5985
5986 // Test that the ticket callback is only called once when everything before
5987 // it in the ClientHello is asynchronous. This corrupts the ticket so
5988 // certificate selection callbacks run.
5989 testCases = append(testCases, testCase{
5990 testType: serverTest,
5991 name: "TicketCallback-SingleCall-" + ver.name,
5992 config: Config{
5993 MaxVersion: ver.version,
5994 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005995 FilterTicket: func(in []byte) ([]byte, error) {
5996 in[len(in)-1] ^= 1
5997 return in, nil
5998 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005999 },
6000 },
David Benjamina5022392017-07-10 17:40:39 -04006001 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006002 resumeSession: true,
6003 expectResumeRejected: true,
6004 flags: []string{
6005 "-use-ticket-callback",
6006 "-async",
6007 },
6008 })
6009
David Benjamind4c349b2017-02-09 14:07:17 -05006010 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04006011 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04006012 testCases = append(testCases, testCase{
6013 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05006014 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04006015 config: Config{
6016 MaxVersion: ver.version,
6017 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006018 EmptyTicketSessionID: true,
6019 },
6020 },
6021 resumeSession: true,
6022 })
6023 testCases = append(testCases, testCase{
6024 testType: serverTest,
6025 name: "TicketSessionIDLength-16-" + ver.name,
6026 config: Config{
6027 MaxVersion: ver.version,
6028 Bugs: ProtocolBugs{
6029 TicketSessionIDLength: 16,
6030 },
6031 },
6032 resumeSession: true,
6033 })
6034 testCases = append(testCases, testCase{
6035 testType: serverTest,
6036 name: "TicketSessionIDLength-32-" + ver.name,
6037 config: Config{
6038 MaxVersion: ver.version,
6039 Bugs: ProtocolBugs{
6040 TicketSessionIDLength: 32,
6041 },
6042 },
6043 resumeSession: true,
6044 })
6045 testCases = append(testCases, testCase{
6046 testType: serverTest,
6047 name: "TicketSessionIDLength-33-" + ver.name,
6048 config: Config{
6049 MaxVersion: ver.version,
6050 Bugs: ProtocolBugs{
6051 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006052 },
6053 },
6054 resumeSession: true,
6055 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006056 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006057 expectedError: ":DECODE_ERROR:",
6058 })
6059 }
6060
6061 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6062 // are ignored.
6063 if ver.hasDTLS {
6064 testCases = append(testCases, testCase{
6065 protocol: dtls,
6066 name: "SRTP-Client-" + ver.name,
6067 config: Config{
6068 MaxVersion: ver.version,
6069 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6070 },
6071 flags: []string{
6072 "-srtp-profiles",
6073 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6074 },
6075 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6076 })
6077 testCases = append(testCases, testCase{
6078 protocol: dtls,
6079 testType: serverTest,
6080 name: "SRTP-Server-" + ver.name,
6081 config: Config{
6082 MaxVersion: ver.version,
6083 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6084 },
6085 flags: []string{
6086 "-srtp-profiles",
6087 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6088 },
6089 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6090 })
6091 // Test that the MKI is ignored.
6092 testCases = append(testCases, testCase{
6093 protocol: dtls,
6094 testType: serverTest,
6095 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6096 config: Config{
6097 MaxVersion: ver.version,
6098 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6099 Bugs: ProtocolBugs{
6100 SRTPMasterKeyIdentifer: "bogus",
6101 },
6102 },
6103 flags: []string{
6104 "-srtp-profiles",
6105 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6106 },
6107 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6108 })
6109 // Test that SRTP isn't negotiated on the server if there were
6110 // no matching profiles.
6111 testCases = append(testCases, testCase{
6112 protocol: dtls,
6113 testType: serverTest,
6114 name: "SRTP-Server-NoMatch-" + ver.name,
6115 config: Config{
6116 MaxVersion: ver.version,
6117 SRTPProtectionProfiles: []uint16{100, 101, 102},
6118 },
6119 flags: []string{
6120 "-srtp-profiles",
6121 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6122 },
6123 expectedSRTPProtectionProfile: 0,
6124 })
6125 // Test that the server returning an invalid SRTP profile is
6126 // flagged as an error by the client.
6127 testCases = append(testCases, testCase{
6128 protocol: dtls,
6129 name: "SRTP-Client-NoMatch-" + ver.name,
6130 config: Config{
6131 MaxVersion: ver.version,
6132 Bugs: ProtocolBugs{
6133 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6134 },
6135 },
6136 flags: []string{
6137 "-srtp-profiles",
6138 "SRTP_AES128_CM_SHA1_80",
6139 },
6140 shouldFail: true,
6141 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6142 })
6143 }
6144
6145 // Test SCT list.
6146 testCases = append(testCases, testCase{
6147 name: "SignedCertificateTimestampList-Client-" + ver.name,
6148 testType: clientTest,
6149 config: Config{
6150 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006151 },
David Benjamin97d17d92016-07-14 16:12:00 -04006152 flags: []string{
6153 "-enable-signed-cert-timestamps",
6154 "-expect-signed-cert-timestamps",
6155 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006156 },
David Benjamina5022392017-07-10 17:40:39 -04006157 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006158 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006159 })
David Benjamindaa88502016-10-04 16:32:16 -04006160
Adam Langleycfa08c32016-11-17 13:21:27 -08006161 var differentSCTList []byte
6162 differentSCTList = append(differentSCTList, testSCTList...)
6163 differentSCTList[len(differentSCTList)-1] ^= 1
6164
David Benjamindaa88502016-10-04 16:32:16 -04006165 // The SCT extension did not specify that it must only be sent on resumption as it
6166 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006167 testCases = append(testCases, testCase{
6168 name: "SendSCTListOnResume-" + ver.name,
6169 config: Config{
6170 MaxVersion: ver.version,
6171 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006172 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006173 },
David Benjamind98452d2015-06-16 14:16:23 -04006174 },
David Benjamin97d17d92016-07-14 16:12:00 -04006175 flags: []string{
6176 "-enable-signed-cert-timestamps",
6177 "-expect-signed-cert-timestamps",
6178 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006179 },
David Benjamina5022392017-07-10 17:40:39 -04006180 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006181 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006182 })
David Benjamindaa88502016-10-04 16:32:16 -04006183
David Benjamin97d17d92016-07-14 16:12:00 -04006184 testCases = append(testCases, testCase{
6185 name: "SignedCertificateTimestampList-Server-" + ver.name,
6186 testType: serverTest,
6187 config: Config{
6188 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006189 },
David Benjamin97d17d92016-07-14 16:12:00 -04006190 flags: []string{
6191 "-signed-cert-timestamps",
6192 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006193 },
David Benjamina5022392017-07-10 17:40:39 -04006194 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006195 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006196 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006197 })
David Benjamin53210cb2016-11-16 09:01:48 +09006198
Adam Langleycfa08c32016-11-17 13:21:27 -08006199 emptySCTListCert := *testCerts[0].cert
6200 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6201
6202 // Test empty SCT list.
6203 testCases = append(testCases, testCase{
6204 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6205 testType: clientTest,
6206 config: Config{
6207 MaxVersion: ver.version,
6208 Certificates: []Certificate{emptySCTListCert},
6209 },
6210 flags: []string{
6211 "-enable-signed-cert-timestamps",
6212 },
David Benjamina5022392017-07-10 17:40:39 -04006213 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006214 shouldFail: true,
6215 expectedError: ":ERROR_PARSING_EXTENSION:",
6216 })
6217
6218 emptySCTCert := *testCerts[0].cert
6219 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6220
6221 // Test empty SCT in non-empty list.
6222 testCases = append(testCases, testCase{
6223 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6224 testType: clientTest,
6225 config: Config{
6226 MaxVersion: ver.version,
6227 Certificates: []Certificate{emptySCTCert},
6228 },
6229 flags: []string{
6230 "-enable-signed-cert-timestamps",
6231 },
David Benjamina5022392017-07-10 17:40:39 -04006232 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006233 shouldFail: true,
6234 expectedError: ":ERROR_PARSING_EXTENSION:",
6235 })
6236
David Benjamin53210cb2016-11-16 09:01:48 +09006237 // Test that certificate-related extensions are not sent unsolicited.
6238 testCases = append(testCases, testCase{
6239 testType: serverTest,
6240 name: "UnsolicitedCertificateExtensions-" + ver.name,
6241 config: Config{
6242 MaxVersion: ver.version,
6243 Bugs: ProtocolBugs{
6244 NoOCSPStapling: true,
6245 NoSignedCertificateTimestamps: true,
6246 },
6247 },
David Benjamina5022392017-07-10 17:40:39 -04006248 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006249 flags: []string{
6250 "-ocsp-response",
6251 base64.StdEncoding.EncodeToString(testOCSPResponse),
6252 "-signed-cert-timestamps",
6253 base64.StdEncoding.EncodeToString(testSCTList),
6254 },
6255 })
David Benjamin97d17d92016-07-14 16:12:00 -04006256 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006257
Paul Lietar4fac72e2015-09-09 13:44:55 +01006258 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006259 testType: clientTest,
6260 name: "ClientHelloPadding",
6261 config: Config{
6262 Bugs: ProtocolBugs{
6263 RequireClientHelloSize: 512,
6264 },
6265 },
6266 // This hostname just needs to be long enough to push the
6267 // ClientHello into F5's danger zone between 256 and 511 bytes
6268 // long.
6269 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6270 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006271
6272 // Extensions should not function in SSL 3.0.
6273 testCases = append(testCases, testCase{
6274 testType: serverTest,
6275 name: "SSLv3Extensions-NoALPN",
6276 config: Config{
6277 MaxVersion: VersionSSL30,
6278 NextProtos: []string{"foo", "bar", "baz"},
6279 },
6280 flags: []string{
6281 "-select-alpn", "foo",
6282 },
6283 expectNoNextProto: true,
6284 })
6285
6286 // Test session tickets separately as they follow a different codepath.
6287 testCases = append(testCases, testCase{
6288 testType: serverTest,
6289 name: "SSLv3Extensions-NoTickets",
6290 config: Config{
6291 MaxVersion: VersionSSL30,
6292 Bugs: ProtocolBugs{
6293 // Historically, session tickets in SSL 3.0
6294 // failed in different ways depending on whether
6295 // the client supported renegotiation_info.
6296 NoRenegotiationInfo: true,
6297 },
6298 },
6299 resumeSession: true,
6300 })
6301 testCases = append(testCases, testCase{
6302 testType: serverTest,
6303 name: "SSLv3Extensions-NoTickets2",
6304 config: Config{
6305 MaxVersion: VersionSSL30,
6306 },
6307 resumeSession: true,
6308 })
6309
6310 // But SSL 3.0 does send and process renegotiation_info.
6311 testCases = append(testCases, testCase{
6312 testType: serverTest,
6313 name: "SSLv3Extensions-RenegotiationInfo",
6314 config: Config{
6315 MaxVersion: VersionSSL30,
6316 Bugs: ProtocolBugs{
6317 RequireRenegotiationInfo: true,
6318 },
6319 },
David Benjamind2610042017-01-03 10:49:28 -05006320 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006321 })
6322 testCases = append(testCases, testCase{
6323 testType: serverTest,
6324 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6325 config: Config{
6326 MaxVersion: VersionSSL30,
6327 Bugs: ProtocolBugs{
6328 NoRenegotiationInfo: true,
6329 SendRenegotiationSCSV: true,
6330 RequireRenegotiationInfo: true,
6331 },
6332 },
David Benjamind2610042017-01-03 10:49:28 -05006333 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006334 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006335
6336 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6337 // in ServerHello.
6338 testCases = append(testCases, testCase{
6339 name: "NPN-Forbidden-TLS13",
6340 config: Config{
6341 MaxVersion: VersionTLS13,
6342 NextProtos: []string{"foo"},
6343 Bugs: ProtocolBugs{
6344 NegotiateNPNAtAllVersions: true,
6345 },
6346 },
6347 flags: []string{"-select-next-proto", "foo"},
6348 shouldFail: true,
6349 expectedError: ":ERROR_PARSING_EXTENSION:",
6350 })
6351 testCases = append(testCases, testCase{
6352 name: "EMS-Forbidden-TLS13",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 Bugs: ProtocolBugs{
6356 NegotiateEMSAtAllVersions: true,
6357 },
6358 },
6359 shouldFail: true,
6360 expectedError: ":ERROR_PARSING_EXTENSION:",
6361 })
6362 testCases = append(testCases, testCase{
6363 name: "RenegotiationInfo-Forbidden-TLS13",
6364 config: Config{
6365 MaxVersion: VersionTLS13,
6366 Bugs: ProtocolBugs{
6367 NegotiateRenegotiationInfoAtAllVersions: true,
6368 },
6369 },
6370 shouldFail: true,
6371 expectedError: ":ERROR_PARSING_EXTENSION:",
6372 })
6373 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006374 name: "Ticket-Forbidden-TLS13",
6375 config: Config{
6376 MaxVersion: VersionTLS12,
6377 },
6378 resumeConfig: &Config{
6379 MaxVersion: VersionTLS13,
6380 Bugs: ProtocolBugs{
6381 AdvertiseTicketExtension: true,
6382 },
6383 },
6384 resumeSession: true,
6385 shouldFail: true,
6386 expectedError: ":ERROR_PARSING_EXTENSION:",
6387 })
6388
6389 // Test that illegal extensions in TLS 1.3 are declined by the server if
6390 // offered in ClientHello. The runner's server will fail if this occurs,
6391 // so we exercise the offering path. (EMS and Renegotiation Info are
6392 // implicit in every test.)
6393 testCases = append(testCases, testCase{
6394 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006395 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006396 config: Config{
6397 MaxVersion: VersionTLS13,
6398 NextProtos: []string{"bar"},
6399 },
6400 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6401 })
David Benjamin196df5b2016-09-21 16:23:27 -04006402
David Benjamindaa88502016-10-04 16:32:16 -04006403 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6404 // tolerated.
6405 testCases = append(testCases, testCase{
6406 name: "SendOCSPResponseOnResume-TLS12",
6407 config: Config{
6408 MaxVersion: VersionTLS12,
6409 Bugs: ProtocolBugs{
6410 SendOCSPResponseOnResume: []byte("bogus"),
6411 },
6412 },
6413 flags: []string{
6414 "-enable-ocsp-stapling",
6415 "-expect-ocsp-response",
6416 base64.StdEncoding.EncodeToString(testOCSPResponse),
6417 },
6418 resumeSession: true,
6419 })
6420
David Benjamindaa88502016-10-04 16:32:16 -04006421 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006422 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006423 config: Config{
6424 MaxVersion: VersionTLS13,
6425 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006426 SendExtensionOnCertificate: testOCSPExtension,
6427 },
6428 },
6429 shouldFail: true,
6430 expectedError: ":UNEXPECTED_EXTENSION:",
6431 })
6432
6433 testCases = append(testCases, testCase{
6434 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6435 config: Config{
6436 MaxVersion: VersionTLS13,
6437 Bugs: ProtocolBugs{
6438 SendExtensionOnCertificate: testSCTExtension,
6439 },
6440 },
6441 shouldFail: true,
6442 expectedError: ":UNEXPECTED_EXTENSION:",
6443 })
6444
6445 // Test that extensions on client certificates are never accepted.
6446 testCases = append(testCases, testCase{
6447 name: "SendExtensionOnClientCertificate-TLS13",
6448 testType: serverTest,
6449 config: Config{
6450 MaxVersion: VersionTLS13,
6451 Certificates: []Certificate{rsaCertificate},
6452 Bugs: ProtocolBugs{
6453 SendExtensionOnCertificate: testOCSPExtension,
6454 },
6455 },
6456 flags: []string{
6457 "-enable-ocsp-stapling",
6458 "-require-any-client-certificate",
6459 },
6460 shouldFail: true,
6461 expectedError: ":UNEXPECTED_EXTENSION:",
6462 })
6463
6464 testCases = append(testCases, testCase{
6465 name: "SendUnknownExtensionOnCertificate-TLS13",
6466 config: Config{
6467 MaxVersion: VersionTLS13,
6468 Bugs: ProtocolBugs{
6469 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6470 },
6471 },
6472 shouldFail: true,
6473 expectedError: ":UNEXPECTED_EXTENSION:",
6474 })
6475
Adam Langleycfa08c32016-11-17 13:21:27 -08006476 var differentSCTList []byte
6477 differentSCTList = append(differentSCTList, testSCTList...)
6478 differentSCTList[len(differentSCTList)-1] ^= 1
6479
Steven Valdeza833c352016-11-01 13:39:36 -04006480 // Test that extensions on intermediates are allowed but ignored.
6481 testCases = append(testCases, testCase{
6482 name: "IgnoreExtensionsOnIntermediates-TLS13",
6483 config: Config{
6484 MaxVersion: VersionTLS13,
6485 Certificates: []Certificate{rsaChainCertificate},
6486 Bugs: ProtocolBugs{
6487 // Send different values on the intermediate. This tests
6488 // the intermediate's extensions do not override the
6489 // leaf's.
6490 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006491 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006492 },
6493 },
6494 flags: []string{
6495 "-enable-ocsp-stapling",
6496 "-expect-ocsp-response",
6497 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006498 "-enable-signed-cert-timestamps",
6499 "-expect-signed-cert-timestamps",
6500 base64.StdEncoding.EncodeToString(testSCTList),
6501 },
6502 resumeSession: true,
6503 })
6504
6505 // Test that extensions are not sent on intermediates when configured
6506 // only for a leaf.
6507 testCases = append(testCases, testCase{
6508 testType: serverTest,
6509 name: "SendNoExtensionsOnIntermediate-TLS13",
6510 config: Config{
6511 MaxVersion: VersionTLS13,
6512 Bugs: ProtocolBugs{
6513 ExpectNoExtensionsOnIntermediate: true,
6514 },
6515 },
6516 flags: []string{
6517 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6518 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6519 "-ocsp-response",
6520 base64.StdEncoding.EncodeToString(testOCSPResponse),
6521 "-signed-cert-timestamps",
6522 base64.StdEncoding.EncodeToString(testSCTList),
6523 },
6524 })
6525
6526 // Test that extensions are not sent on client certificates.
6527 testCases = append(testCases, testCase{
6528 name: "SendNoClientCertificateExtensions-TLS13",
6529 config: Config{
6530 MaxVersion: VersionTLS13,
6531 ClientAuth: RequireAnyClientCert,
6532 },
6533 flags: []string{
6534 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6535 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6536 "-ocsp-response",
6537 base64.StdEncoding.EncodeToString(testOCSPResponse),
6538 "-signed-cert-timestamps",
6539 base64.StdEncoding.EncodeToString(testSCTList),
6540 },
6541 })
6542
6543 testCases = append(testCases, testCase{
6544 name: "SendDuplicateExtensionsOnCerts-TLS13",
6545 config: Config{
6546 MaxVersion: VersionTLS13,
6547 Bugs: ProtocolBugs{
6548 SendDuplicateCertExtensions: true,
6549 },
6550 },
6551 flags: []string{
6552 "-enable-ocsp-stapling",
6553 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006554 },
6555 resumeSession: true,
6556 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006557 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006558 })
Adam Langley9b885c52016-11-18 14:21:03 -08006559
6560 testCases = append(testCases, testCase{
6561 name: "SignedCertificateTimestampListInvalid-Server",
6562 testType: serverTest,
6563 flags: []string{
6564 "-signed-cert-timestamps",
6565 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6566 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006567 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006568 expectedError: ":INVALID_SCT_LIST:",
6569 })
David Benjamine78bfde2014-09-06 12:45:15 -04006570}
6571
David Benjamin01fe8202014-09-24 15:21:44 -04006572func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006573 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006574 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006575 // SSL 3.0 does not have tickets and TLS 1.3 does not
6576 // have session IDs, so skip their cross-resumption
6577 // tests.
6578 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6579 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6580 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006581 }
6582
David Benjamin8b8c0062014-11-23 02:47:52 -05006583 protocols := []protocol{tls}
6584 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6585 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006586 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006587 for _, protocol := range protocols {
6588 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6589 if protocol == dtls {
6590 suffix += "-DTLS"
6591 }
6592
Steven Valdez520e1222017-06-13 12:45:25 -04006593 // We can't resume across TLS 1.3 variants and error out earlier in the
6594 // session resumption.
6595 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6596 continue
6597 }
6598
David Benjaminece3de92015-03-16 18:02:20 -04006599 if sessionVers.version == resumeVers.version {
6600 testCases = append(testCases, testCase{
6601 protocol: protocol,
6602 name: "Resume-Client" + suffix,
6603 resumeSession: true,
6604 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: sessionVers.version,
6606 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006607 Bugs: ProtocolBugs{
6608 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6609 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6610 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006611 },
David Benjaminece3de92015-03-16 18:02:20 -04006612 expectedVersion: sessionVers.version,
6613 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006614 flags: []string{
6615 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6616 },
David Benjaminece3de92015-03-16 18:02:20 -04006617 })
6618 } else {
David Benjamin405da482016-08-08 17:25:07 -04006619 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6620
6621 // Offering a TLS 1.3 session sends an empty session ID, so
6622 // there is no way to convince a non-lookahead client the
6623 // session was resumed. It will appear to the client that a
6624 // stray ChangeCipherSpec was sent.
6625 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6626 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006627 }
6628
David Benjaminece3de92015-03-16 18:02:20 -04006629 testCases = append(testCases, testCase{
6630 protocol: protocol,
6631 name: "Resume-Client-Mismatch" + suffix,
6632 resumeSession: true,
6633 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006634 MaxVersion: sessionVers.version,
6635 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006636 },
David Benjaminece3de92015-03-16 18:02:20 -04006637 expectedVersion: sessionVers.version,
6638 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006639 MaxVersion: resumeVers.version,
6640 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006641 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006642 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006643 },
6644 },
6645 expectedResumeVersion: resumeVers.version,
6646 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006647 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006648 flags: []string{
6649 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6650 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6651 },
David Benjaminece3de92015-03-16 18:02:20 -04006652 })
6653 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006654
6655 testCases = append(testCases, testCase{
6656 protocol: protocol,
6657 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006658 resumeSession: true,
6659 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006660 MaxVersion: sessionVers.version,
6661 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006662 },
6663 expectedVersion: sessionVers.version,
6664 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006665 MaxVersion: resumeVers.version,
6666 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006667 },
6668 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006669 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006670 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006671 flags: []string{
6672 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6673 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6674 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006675 })
6676
David Benjamin8b8c0062014-11-23 02:47:52 -05006677 testCases = append(testCases, testCase{
6678 protocol: protocol,
6679 testType: serverTest,
6680 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006681 resumeSession: true,
6682 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006683 MaxVersion: sessionVers.version,
6684 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006685 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006686 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006687 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006688 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006689 MaxVersion: resumeVers.version,
6690 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006691 Bugs: ProtocolBugs{
6692 SendBothTickets: true,
6693 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006694 },
6695 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006696 flags: []string{
6697 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6698 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6699 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006700 })
6701 }
David Benjamin01fe8202014-09-24 15:21:44 -04006702 }
6703 }
David Benjaminece3de92015-03-16 18:02:20 -04006704
David Benjamin4199b0d2016-11-01 13:58:25 -04006705 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006706 testCases = append(testCases, testCase{
6707 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006708 name: "ShimTicketRewritable",
6709 resumeSession: true,
6710 config: Config{
6711 MaxVersion: VersionTLS12,
6712 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6713 Bugs: ProtocolBugs{
6714 FilterTicket: func(in []byte) ([]byte, error) {
6715 in, err := SetShimTicketVersion(in, VersionTLS12)
6716 if err != nil {
6717 return nil, err
6718 }
6719 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6720 },
6721 },
6722 },
6723 flags: []string{
6724 "-ticket-key",
6725 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6726 },
6727 })
6728
6729 // Resumptions are declined if the version does not match.
6730 testCases = append(testCases, testCase{
6731 testType: serverTest,
6732 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006733 resumeSession: true,
6734 config: Config{
6735 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006736 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006737 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006738 FilterTicket: func(in []byte) ([]byte, error) {
6739 return SetShimTicketVersion(in, VersionTLS13)
6740 },
6741 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006742 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006743 flags: []string{
6744 "-ticket-key",
6745 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6746 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006747 expectResumeRejected: true,
6748 })
6749
6750 testCases = append(testCases, testCase{
6751 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006752 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006753 resumeSession: true,
6754 config: Config{
6755 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006756 Bugs: ProtocolBugs{
6757 FilterTicket: func(in []byte) ([]byte, error) {
6758 return SetShimTicketVersion(in, VersionTLS12)
6759 },
6760 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006761 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006762 flags: []string{
6763 "-ticket-key",
6764 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6765 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006766 expectResumeRejected: true,
6767 })
6768
David Benjamin4199b0d2016-11-01 13:58:25 -04006769 // Resumptions are declined if the cipher is invalid or disabled.
6770 testCases = append(testCases, testCase{
6771 testType: serverTest,
6772 name: "Resume-Server-DeclineBadCipher",
6773 resumeSession: true,
6774 config: Config{
6775 MaxVersion: VersionTLS12,
6776 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006777 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006778 FilterTicket: func(in []byte) ([]byte, error) {
6779 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6780 },
6781 },
6782 },
6783 flags: []string{
6784 "-ticket-key",
6785 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6786 },
6787 expectResumeRejected: true,
6788 })
6789
6790 testCases = append(testCases, testCase{
6791 testType: serverTest,
6792 name: "Resume-Server-DeclineBadCipher-2",
6793 resumeSession: true,
6794 config: Config{
6795 MaxVersion: VersionTLS12,
6796 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006797 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006798 FilterTicket: func(in []byte) ([]byte, error) {
6799 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6800 },
6801 },
6802 },
6803 flags: []string{
6804 "-cipher", "AES128",
6805 "-ticket-key",
6806 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6807 },
6808 expectResumeRejected: true,
6809 })
6810
David Benjaminf01f42a2016-11-16 19:05:33 +09006811 // Sessions are not resumed if they do not use the preferred cipher.
6812 testCases = append(testCases, testCase{
6813 testType: serverTest,
6814 name: "Resume-Server-CipherNotPreferred",
6815 resumeSession: true,
6816 config: Config{
6817 MaxVersion: VersionTLS12,
6818 Bugs: ProtocolBugs{
6819 ExpectNewTicket: true,
6820 FilterTicket: func(in []byte) ([]byte, error) {
6821 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6822 },
6823 },
6824 },
6825 flags: []string{
6826 "-ticket-key",
6827 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6828 },
6829 shouldFail: false,
6830 expectResumeRejected: true,
6831 })
6832
6833 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6834 // PRF hashes match, but BoringSSL will always decline such resumptions.
6835 testCases = append(testCases, testCase{
6836 testType: serverTest,
6837 name: "Resume-Server-CipherNotPreferred-TLS13",
6838 resumeSession: true,
6839 config: Config{
6840 MaxVersion: VersionTLS13,
6841 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6842 Bugs: ProtocolBugs{
6843 FilterTicket: func(in []byte) ([]byte, error) {
6844 // If the client (runner) offers ChaCha20-Poly1305 first, the
6845 // server (shim) always prefers it. Switch it to AES-GCM.
6846 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6847 },
6848 },
6849 },
6850 flags: []string{
6851 "-ticket-key",
6852 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6853 },
6854 shouldFail: false,
6855 expectResumeRejected: true,
6856 })
6857
6858 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006859 testCases = append(testCases, testCase{
6860 testType: serverTest,
6861 name: "Resume-Server-DeclineBadCipher-TLS13",
6862 resumeSession: true,
6863 config: Config{
6864 MaxVersion: VersionTLS13,
6865 Bugs: ProtocolBugs{
6866 FilterTicket: func(in []byte) ([]byte, error) {
6867 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6868 },
6869 },
6870 },
6871 flags: []string{
6872 "-ticket-key",
6873 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6874 },
6875 expectResumeRejected: true,
6876 })
6877
David Benjaminf01f42a2016-11-16 19:05:33 +09006878 // If the client does not offer the cipher from the session, decline to
6879 // resume. Clients are forbidden from doing this, but BoringSSL selects
6880 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006881 testCases = append(testCases, testCase{
6882 testType: serverTest,
6883 name: "Resume-Server-UnofferedCipher",
6884 resumeSession: true,
6885 config: Config{
6886 MaxVersion: VersionTLS12,
6887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6888 },
6889 resumeConfig: &Config{
6890 MaxVersion: VersionTLS12,
6891 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6892 Bugs: ProtocolBugs{
6893 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6894 },
6895 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006896 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006897 })
6898
David Benjaminf01f42a2016-11-16 19:05:33 +09006899 // In TLS 1.3, clients may advertise a cipher list which does not
6900 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006901 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6902 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: "Resume-Server-UnofferedCipher-TLS13",
6906 resumeSession: true,
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6910 },
6911 resumeConfig: &Config{
6912 MaxVersion: VersionTLS13,
6913 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6914 Bugs: ProtocolBugs{
6915 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6916 },
6917 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006918 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006919 })
6920
David Benjamin4199b0d2016-11-01 13:58:25 -04006921 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006922 testCases = append(testCases, testCase{
6923 name: "Resume-Client-CipherMismatch",
6924 resumeSession: true,
6925 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006926 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006927 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6928 },
6929 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006930 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006931 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6932 Bugs: ProtocolBugs{
6933 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6934 },
6935 },
6936 shouldFail: true,
6937 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6938 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006939
David Benjamine1cc35e2016-11-16 16:25:58 +09006940 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6941 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006942 testCases = append(testCases, testCase{
6943 name: "Resume-Client-CipherMismatch-TLS13",
6944 resumeSession: true,
6945 config: Config{
6946 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006947 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006948 },
6949 resumeConfig: &Config{
6950 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006951 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6952 },
6953 })
6954
6955 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6956 testCases = append(testCases, testCase{
6957 name: "Resume-Client-PRFMismatch-TLS13",
6958 resumeSession: true,
6959 config: Config{
6960 MaxVersion: VersionTLS13,
6961 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6962 },
6963 resumeConfig: &Config{
6964 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006965 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006966 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006967 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006968 },
6969 },
6970 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006971 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006972 })
Steven Valdeza833c352016-11-01 13:39:36 -04006973
6974 testCases = append(testCases, testCase{
6975 testType: serverTest,
6976 name: "Resume-Server-BinderWrongLength",
6977 resumeSession: true,
6978 config: Config{
6979 MaxVersion: VersionTLS13,
6980 Bugs: ProtocolBugs{
6981 SendShortPSKBinder: true,
6982 },
6983 },
6984 shouldFail: true,
6985 expectedLocalError: "remote error: error decrypting message",
6986 expectedError: ":DIGEST_CHECK_FAILED:",
6987 })
6988
6989 testCases = append(testCases, testCase{
6990 testType: serverTest,
6991 name: "Resume-Server-NoPSKBinder",
6992 resumeSession: true,
6993 config: Config{
6994 MaxVersion: VersionTLS13,
6995 Bugs: ProtocolBugs{
6996 SendNoPSKBinder: true,
6997 },
6998 },
6999 shouldFail: true,
7000 expectedLocalError: "remote error: error decoding message",
7001 expectedError: ":DECODE_ERROR:",
7002 })
7003
7004 testCases = append(testCases, testCase{
7005 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05007006 name: "Resume-Server-ExtraPSKBinder",
7007 resumeSession: true,
7008 config: Config{
7009 MaxVersion: VersionTLS13,
7010 Bugs: ProtocolBugs{
7011 SendExtraPSKBinder: true,
7012 },
7013 },
7014 shouldFail: true,
7015 expectedLocalError: "remote error: illegal parameter",
7016 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7017 })
7018
7019 testCases = append(testCases, testCase{
7020 testType: serverTest,
7021 name: "Resume-Server-ExtraIdentityNoBinder",
7022 resumeSession: true,
7023 config: Config{
7024 MaxVersion: VersionTLS13,
7025 Bugs: ProtocolBugs{
7026 ExtraPSKIdentity: true,
7027 },
7028 },
7029 shouldFail: true,
7030 expectedLocalError: "remote error: illegal parameter",
7031 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7032 })
7033
7034 testCases = append(testCases, testCase{
7035 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007036 name: "Resume-Server-InvalidPSKBinder",
7037 resumeSession: true,
7038 config: Config{
7039 MaxVersion: VersionTLS13,
7040 Bugs: ProtocolBugs{
7041 SendInvalidPSKBinder: true,
7042 },
7043 },
7044 shouldFail: true,
7045 expectedLocalError: "remote error: error decrypting message",
7046 expectedError: ":DIGEST_CHECK_FAILED:",
7047 })
7048
7049 testCases = append(testCases, testCase{
7050 testType: serverTest,
7051 name: "Resume-Server-PSKBinderFirstExtension",
7052 resumeSession: true,
7053 config: Config{
7054 MaxVersion: VersionTLS13,
7055 Bugs: ProtocolBugs{
7056 PSKBinderFirst: true,
7057 },
7058 },
7059 shouldFail: true,
7060 expectedLocalError: "remote error: illegal parameter",
7061 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7062 })
David Benjamin01fe8202014-09-24 15:21:44 -04007063}
7064
Adam Langley2ae77d22014-10-28 17:29:33 -07007065func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007066 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007067 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007068 testType: serverTest,
7069 name: "Renegotiate-Server-Forbidden",
7070 config: Config{
7071 MaxVersion: VersionTLS12,
7072 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007073 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007074 shouldFail: true,
7075 expectedError: ":NO_RENEGOTIATION:",
7076 expectedLocalError: "remote error: no renegotiation",
7077 })
Adam Langley5021b222015-06-12 18:27:58 -07007078 // The server shouldn't echo the renegotiation extension unless
7079 // requested by the client.
7080 testCases = append(testCases, testCase{
7081 testType: serverTest,
7082 name: "Renegotiate-Server-NoExt",
7083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007084 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007085 Bugs: ProtocolBugs{
7086 NoRenegotiationInfo: true,
7087 RequireRenegotiationInfo: true,
7088 },
7089 },
7090 shouldFail: true,
7091 expectedLocalError: "renegotiation extension missing",
7092 })
7093 // The renegotiation SCSV should be sufficient for the server to echo
7094 // the extension.
7095 testCases = append(testCases, testCase{
7096 testType: serverTest,
7097 name: "Renegotiate-Server-NoExt-SCSV",
7098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007099 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007100 Bugs: ProtocolBugs{
7101 NoRenegotiationInfo: true,
7102 SendRenegotiationSCSV: true,
7103 RequireRenegotiationInfo: true,
7104 },
7105 },
7106 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007107 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007108 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007110 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007111 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007112 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007113 },
7114 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007115 renegotiate: 1,
7116 flags: []string{
7117 "-renegotiate-freely",
7118 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007119 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007120 },
David Benjamincdea40c2015-03-19 14:09:43 -04007121 })
7122 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007123 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007124 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007126 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 Bugs: ProtocolBugs{
7128 EmptyRenegotiationInfo: true,
7129 },
7130 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007131 flags: []string{"-renegotiate-freely"},
7132 shouldFail: true,
7133 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007134 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007135 })
7136 testCases = append(testCases, testCase{
7137 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007138 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007140 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007141 Bugs: ProtocolBugs{
7142 BadRenegotiationInfo: true,
7143 },
7144 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007145 flags: []string{"-renegotiate-freely"},
7146 shouldFail: true,
7147 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007148 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007149 })
7150 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007151 name: "Renegotiate-Client-BadExt2",
7152 renegotiate: 1,
7153 config: Config{
7154 MaxVersion: VersionTLS12,
7155 Bugs: ProtocolBugs{
7156 BadRenegotiationInfoEnd: true,
7157 },
7158 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007159 flags: []string{"-renegotiate-freely"},
7160 shouldFail: true,
7161 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007162 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007163 })
7164 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007165 name: "Renegotiate-Client-Downgrade",
7166 renegotiate: 1,
7167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007168 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007169 Bugs: ProtocolBugs{
7170 NoRenegotiationInfoAfterInitial: true,
7171 },
7172 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007173 flags: []string{"-renegotiate-freely"},
7174 shouldFail: true,
7175 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007176 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007177 })
7178 testCases = append(testCases, testCase{
7179 name: "Renegotiate-Client-Upgrade",
7180 renegotiate: 1,
7181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007182 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007183 Bugs: ProtocolBugs{
7184 NoRenegotiationInfoInInitial: true,
7185 },
7186 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007187 flags: []string{"-renegotiate-freely"},
7188 shouldFail: true,
7189 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007190 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007191 })
7192 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007193 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007194 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007197 Bugs: ProtocolBugs{
7198 NoRenegotiationInfo: true,
7199 },
7200 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007201 flags: []string{
7202 "-renegotiate-freely",
7203 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007204 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007205 },
David Benjamincff0b902015-05-15 23:09:47 -04007206 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007207
7208 // Test that the server may switch ciphers on renegotiation without
7209 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007210 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007211 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007212 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007213 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007214 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007215 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007216 },
7217 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007218 flags: []string{
7219 "-renegotiate-freely",
7220 "-expect-total-renegotiations", "1",
7221 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007222 })
7223 testCases = append(testCases, testCase{
7224 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007225 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007227 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007228 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7229 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007230 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007231 flags: []string{
7232 "-renegotiate-freely",
7233 "-expect-total-renegotiations", "1",
7234 },
David Benjaminb16346b2015-04-08 19:16:58 -04007235 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007236
7237 // Test that the server may not switch versions on renegotiation.
7238 testCases = append(testCases, testCase{
7239 name: "Renegotiate-Client-SwitchVersion",
7240 config: Config{
7241 MaxVersion: VersionTLS12,
7242 // Pick a cipher which exists at both versions.
7243 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7244 Bugs: ProtocolBugs{
7245 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007246 // Avoid failing early at the record layer.
7247 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007248 },
7249 },
7250 renegotiate: 1,
7251 flags: []string{
7252 "-renegotiate-freely",
7253 "-expect-total-renegotiations", "1",
7254 },
7255 shouldFail: true,
7256 expectedError: ":WRONG_SSL_VERSION:",
7257 })
7258
David Benjaminb16346b2015-04-08 19:16:58 -04007259 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007260 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007261 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007262 config: Config{
7263 MaxVersion: VersionTLS10,
7264 Bugs: ProtocolBugs{
7265 RequireSameRenegoClientVersion: true,
7266 },
7267 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007268 flags: []string{
7269 "-renegotiate-freely",
7270 "-expect-total-renegotiations", "1",
7271 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007272 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007273 testCases = append(testCases, testCase{
7274 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007275 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007276 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007277 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007278 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7279 NextProtos: []string{"foo"},
7280 },
7281 flags: []string{
7282 "-false-start",
7283 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007284 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007285 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007286 },
7287 shimWritesFirst: true,
7288 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007289
7290 // Client-side renegotiation controls.
7291 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007292 name: "Renegotiate-Client-Forbidden-1",
7293 config: Config{
7294 MaxVersion: VersionTLS12,
7295 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007296 renegotiate: 1,
7297 shouldFail: true,
7298 expectedError: ":NO_RENEGOTIATION:",
7299 expectedLocalError: "remote error: no renegotiation",
7300 })
7301 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007302 name: "Renegotiate-Client-Once-1",
7303 config: Config{
7304 MaxVersion: VersionTLS12,
7305 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007306 renegotiate: 1,
7307 flags: []string{
7308 "-renegotiate-once",
7309 "-expect-total-renegotiations", "1",
7310 },
7311 })
7312 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007313 name: "Renegotiate-Client-Freely-1",
7314 config: Config{
7315 MaxVersion: VersionTLS12,
7316 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007317 renegotiate: 1,
7318 flags: []string{
7319 "-renegotiate-freely",
7320 "-expect-total-renegotiations", "1",
7321 },
7322 })
7323 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007324 name: "Renegotiate-Client-Once-2",
7325 config: Config{
7326 MaxVersion: VersionTLS12,
7327 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007328 renegotiate: 2,
7329 flags: []string{"-renegotiate-once"},
7330 shouldFail: true,
7331 expectedError: ":NO_RENEGOTIATION:",
7332 expectedLocalError: "remote error: no renegotiation",
7333 })
7334 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007335 name: "Renegotiate-Client-Freely-2",
7336 config: Config{
7337 MaxVersion: VersionTLS12,
7338 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007339 renegotiate: 2,
7340 flags: []string{
7341 "-renegotiate-freely",
7342 "-expect-total-renegotiations", "2",
7343 },
7344 })
Adam Langley27a0d082015-11-03 13:34:10 -08007345 testCases = append(testCases, testCase{
7346 name: "Renegotiate-Client-NoIgnore",
7347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007349 Bugs: ProtocolBugs{
7350 SendHelloRequestBeforeEveryAppDataRecord: true,
7351 },
7352 },
7353 shouldFail: true,
7354 expectedError: ":NO_RENEGOTIATION:",
7355 })
7356 testCases = append(testCases, testCase{
7357 name: "Renegotiate-Client-Ignore",
7358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007359 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007360 Bugs: ProtocolBugs{
7361 SendHelloRequestBeforeEveryAppDataRecord: true,
7362 },
7363 },
7364 flags: []string{
7365 "-renegotiate-ignore",
7366 "-expect-total-renegotiations", "0",
7367 },
7368 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007369
David Benjamin34941c02016-10-08 11:45:31 -04007370 // Renegotiation is not allowed at SSL 3.0.
7371 testCases = append(testCases, testCase{
7372 name: "Renegotiate-Client-SSL3",
7373 config: Config{
7374 MaxVersion: VersionSSL30,
7375 },
7376 renegotiate: 1,
7377 flags: []string{
7378 "-renegotiate-freely",
7379 "-expect-total-renegotiations", "1",
7380 },
7381 shouldFail: true,
7382 expectedError: ":NO_RENEGOTIATION:",
7383 expectedLocalError: "remote error: no renegotiation",
7384 })
7385
David Benjamina1eaba12017-01-01 23:19:22 -05007386 // Renegotiation is not allowed when there is an unfinished write.
7387 testCases = append(testCases, testCase{
7388 name: "Renegotiate-Client-UnfinishedWrite",
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 },
David Benjaminbbba9392017-04-06 12:54:12 -04007392 renegotiate: 1,
7393 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007394 flags: []string{
7395 "-async",
7396 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007397 },
7398 shouldFail: true,
7399 expectedError: ":NO_RENEGOTIATION:",
7400 // We do not successfully send the no_renegotiation alert in
7401 // this case. https://crbug.com/boringssl/130
7402 })
7403
David Benjamin07ab5d42017-02-09 20:11:41 -05007404 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007405 testCases = append(testCases, testCase{
7406 name: "StrayHelloRequest",
7407 config: Config{
7408 MaxVersion: VersionTLS12,
7409 Bugs: ProtocolBugs{
7410 SendHelloRequestBeforeEveryHandshakeMessage: true,
7411 },
7412 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007415 })
7416 testCases = append(testCases, testCase{
7417 name: "StrayHelloRequest-Packed",
7418 config: Config{
7419 MaxVersion: VersionTLS12,
7420 Bugs: ProtocolBugs{
7421 PackHandshakeFlight: true,
7422 SendHelloRequestBeforeEveryHandshakeMessage: true,
7423 },
7424 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007425 shouldFail: true,
7426 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007427 })
7428
David Benjamin12d2c482016-07-24 10:56:51 -04007429 // Test renegotiation works if HelloRequest and server Finished come in
7430 // the same record.
7431 testCases = append(testCases, testCase{
7432 name: "Renegotiate-Client-Packed",
7433 config: Config{
7434 MaxVersion: VersionTLS12,
7435 Bugs: ProtocolBugs{
7436 PackHandshakeFlight: true,
7437 PackHelloRequestWithFinished: true,
7438 },
7439 },
7440 renegotiate: 1,
7441 flags: []string{
7442 "-renegotiate-freely",
7443 "-expect-total-renegotiations", "1",
7444 },
7445 })
7446
David Benjamin397c8e62016-07-08 14:14:36 -07007447 // Renegotiation is forbidden in TLS 1.3.
7448 testCases = append(testCases, testCase{
7449 name: "Renegotiate-Client-TLS13",
7450 config: Config{
7451 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007452 Bugs: ProtocolBugs{
7453 SendHelloRequestBeforeEveryAppDataRecord: true,
7454 },
David Benjamin397c8e62016-07-08 14:14:36 -07007455 },
David Benjamin397c8e62016-07-08 14:14:36 -07007456 flags: []string{
7457 "-renegotiate-freely",
7458 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007459 shouldFail: true,
7460 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007461 })
7462
7463 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7464 testCases = append(testCases, testCase{
7465 name: "StrayHelloRequest-TLS13",
7466 config: Config{
7467 MaxVersion: VersionTLS13,
7468 Bugs: ProtocolBugs{
7469 SendHelloRequestBeforeEveryHandshakeMessage: true,
7470 },
7471 },
7472 shouldFail: true,
7473 expectedError: ":UNEXPECTED_MESSAGE:",
7474 })
David Benjamind2610042017-01-03 10:49:28 -05007475
7476 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7477 // always reads as supporting it, regardless of whether it was
7478 // negotiated.
7479 testCases = append(testCases, testCase{
7480 name: "AlwaysReportRenegotiationInfo-TLS13",
7481 config: Config{
7482 MaxVersion: VersionTLS13,
7483 Bugs: ProtocolBugs{
7484 NoRenegotiationInfo: true,
7485 },
7486 },
7487 flags: []string{
7488 "-expect-secure-renegotiation",
7489 },
7490 })
David Benjamina58baaf2017-02-28 20:54:28 -05007491
7492 // Certificates may not change on renegotiation.
7493 testCases = append(testCases, testCase{
7494 name: "Renegotiation-CertificateChange",
7495 config: Config{
7496 MaxVersion: VersionTLS12,
7497 Certificates: []Certificate{rsaCertificate},
7498 Bugs: ProtocolBugs{
7499 RenegotiationCertificate: &rsaChainCertificate,
7500 },
7501 },
7502 renegotiate: 1,
7503 flags: []string{"-renegotiate-freely"},
7504 shouldFail: true,
7505 expectedError: ":SERVER_CERT_CHANGED:",
7506 })
7507 testCases = append(testCases, testCase{
7508 name: "Renegotiation-CertificateChange-2",
7509 config: Config{
7510 MaxVersion: VersionTLS12,
7511 Certificates: []Certificate{rsaCertificate},
7512 Bugs: ProtocolBugs{
7513 RenegotiationCertificate: &rsa1024Certificate,
7514 },
7515 },
7516 renegotiate: 1,
7517 flags: []string{"-renegotiate-freely"},
7518 shouldFail: true,
7519 expectedError: ":SERVER_CERT_CHANGED:",
7520 })
David Benjaminbbf42462017-03-14 21:27:10 -04007521
7522 // We do not negotiate ALPN after the initial handshake. This is
7523 // error-prone and only risks bugs in consumers.
7524 testCases = append(testCases, testCase{
7525 testType: clientTest,
7526 name: "Renegotiation-ForbidALPN",
7527 config: Config{
7528 MaxVersion: VersionTLS12,
7529 Bugs: ProtocolBugs{
7530 // Forcibly negotiate ALPN on both initial and
7531 // renegotiation handshakes. The test stack will
7532 // internally check the client does not offer
7533 // it.
7534 SendALPN: "foo",
7535 },
7536 },
7537 flags: []string{
7538 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7539 "-expect-alpn", "foo",
7540 "-renegotiate-freely",
7541 },
7542 renegotiate: 1,
7543 shouldFail: true,
7544 expectedError: ":UNEXPECTED_EXTENSION:",
7545 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007546}
7547
David Benjamin5e961c12014-11-07 01:48:35 -05007548func addDTLSReplayTests() {
7549 // Test that sequence number replays are detected.
7550 testCases = append(testCases, testCase{
7551 protocol: dtls,
7552 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007553 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007554 replayWrites: true,
7555 })
7556
David Benjamin8e6db492015-07-25 18:29:23 -04007557 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007558 // than the retransmit window.
7559 testCases = append(testCases, testCase{
7560 protocol: dtls,
7561 name: "DTLS-Replay-LargeGaps",
7562 config: Config{
7563 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007564 SequenceNumberMapping: func(in uint64) uint64 {
7565 return in * 127
7566 },
David Benjamin5e961c12014-11-07 01:48:35 -05007567 },
7568 },
David Benjamin8e6db492015-07-25 18:29:23 -04007569 messageCount: 200,
7570 replayWrites: true,
7571 })
7572
7573 // Test the incoming sequence number changing non-monotonically.
7574 testCases = append(testCases, testCase{
7575 protocol: dtls,
7576 name: "DTLS-Replay-NonMonotonic",
7577 config: Config{
7578 Bugs: ProtocolBugs{
7579 SequenceNumberMapping: func(in uint64) uint64 {
7580 return in ^ 31
7581 },
7582 },
7583 },
7584 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007585 replayWrites: true,
7586 })
7587}
7588
Nick Harper60edffd2016-06-21 15:19:24 -07007589var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007590 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007591 id signatureAlgorithm
7592 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007593}{
Nick Harper60edffd2016-06-21 15:19:24 -07007594 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7595 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7596 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7597 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007598 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007599 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7600 // hash function doesn't have to match the curve and so the same
7601 // signature algorithm works with P-224.
7602 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007603 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7604 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7605 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007606 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7607 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7608 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007609 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007610 // Tests for key types prior to TLS 1.2.
7611 {"RSA", 0, testCertRSA},
7612 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007613}
7614
Nick Harper60edffd2016-06-21 15:19:24 -07007615const fakeSigAlg1 signatureAlgorithm = 0x2a01
7616const fakeSigAlg2 signatureAlgorithm = 0xff01
7617
7618func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007619 // Not all ciphers involve a signature. Advertise a list which gives all
7620 // versions a signing cipher.
7621 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007622 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007623 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7624 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7625 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7626 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007627 }
David Benjamin5208fd42016-07-13 21:43:25 -04007628
David Benjaminca3d5452016-07-14 12:51:01 -04007629 var allAlgorithms []signatureAlgorithm
7630 for _, alg := range testSignatureAlgorithms {
7631 if alg.id != 0 {
7632 allAlgorithms = append(allAlgorithms, alg.id)
7633 }
7634 }
7635
Nick Harper60edffd2016-06-21 15:19:24 -07007636 // Make sure each signature algorithm works. Include some fake values in
7637 // the list and ensure they're ignored.
7638 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007639 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007640 if (ver.version < VersionTLS12) != (alg.id == 0) {
7641 continue
7642 }
7643
7644 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7645 // or remove it in C.
7646 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007647 continue
7648 }
Nick Harper60edffd2016-06-21 15:19:24 -07007649
David Benjamin3ef76972016-10-17 17:59:54 -04007650 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007651 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007652 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007653 shouldSignFail = true
7654 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007655 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007656 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007657 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7658 shouldSignFail = true
7659 shouldVerifyFail = true
7660 }
7661 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7662 // the curve has to match the hash size.
7663 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007664 shouldSignFail = true
7665 shouldVerifyFail = true
7666 }
7667
7668 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7669 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7670 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007671 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007672
7673 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007674 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007675 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007676 }
7677 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007678 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007679 }
David Benjamin000800a2014-11-14 01:43:59 -05007680
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007682
David Benjamin7a41d372016-07-09 11:21:54 -07007683 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007684 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007685 config: Config{
7686 MaxVersion: ver.version,
7687 ClientAuth: RequireAnyClientCert,
7688 VerifySignatureAlgorithms: []signatureAlgorithm{
7689 fakeSigAlg1,
7690 alg.id,
7691 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007692 },
David Benjamin7a41d372016-07-09 11:21:54 -07007693 },
7694 flags: []string{
7695 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7696 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7697 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007698 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007699 },
David Benjamina5022392017-07-10 17:40:39 -04007700 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007701 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007702 expectedError: signError,
7703 expectedPeerSignatureAlgorithm: alg.id,
7704 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007705
David Benjamin7a41d372016-07-09 11:21:54 -07007706 testCases = append(testCases, testCase{
7707 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007708 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007709 config: Config{
7710 MaxVersion: ver.version,
7711 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7712 SignSignatureAlgorithms: []signatureAlgorithm{
7713 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007714 },
David Benjamin7a41d372016-07-09 11:21:54 -07007715 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007716 SkipECDSACurveCheck: shouldVerifyFail,
7717 IgnoreSignatureVersionChecks: shouldVerifyFail,
7718 // Some signature algorithms may not be advertised.
7719 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007720 },
David Benjamin7a41d372016-07-09 11:21:54 -07007721 },
David Benjamina5022392017-07-10 17:40:39 -04007722 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007723 flags: []string{
7724 "-require-any-client-certificate",
7725 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7726 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007727 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007728 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007729 // Resume the session to assert the peer signature
7730 // algorithm is reported on both handshakes.
7731 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007732 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007733 expectedError: verifyError,
7734 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007735
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007736 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007737 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007738 testCases = append(testCases, testCase{
7739 testType: serverTest,
7740 name: "ServerAuth-Sign" + suffix,
7741 config: Config{
7742 MaxVersion: ver.version,
7743 CipherSuites: signingCiphers,
7744 VerifySignatureAlgorithms: []signatureAlgorithm{
7745 fakeSigAlg1,
7746 alg.id,
7747 fakeSigAlg2,
7748 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007749 },
David Benjamina5022392017-07-10 17:40:39 -04007750 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007751 flags: []string{
7752 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7753 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7754 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007755 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007756 },
7757 shouldFail: shouldSignFail,
7758 expectedError: signError,
7759 expectedPeerSignatureAlgorithm: alg.id,
7760 })
7761 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007762
7763 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007764 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007765 config: Config{
7766 MaxVersion: ver.version,
7767 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007768 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007769 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007770 alg.id,
7771 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007772 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007773 SkipECDSACurveCheck: shouldVerifyFail,
7774 IgnoreSignatureVersionChecks: shouldVerifyFail,
7775 // Some signature algorithms may not be advertised.
7776 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007777 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007778 },
David Benjamina5022392017-07-10 17:40:39 -04007779 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007780 flags: []string{
7781 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7782 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007783 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007784 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007785 // Resume the session to assert the peer signature
7786 // algorithm is reported on both handshakes.
7787 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007788 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007789 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007790 })
David Benjamin5208fd42016-07-13 21:43:25 -04007791
David Benjamin3ef76972016-10-17 17:59:54 -04007792 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007793 testCases = append(testCases, testCase{
7794 testType: serverTest,
7795 name: "ClientAuth-InvalidSignature" + suffix,
7796 config: Config{
7797 MaxVersion: ver.version,
7798 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7799 SignSignatureAlgorithms: []signatureAlgorithm{
7800 alg.id,
7801 },
7802 Bugs: ProtocolBugs{
7803 InvalidSignature: true,
7804 },
7805 },
David Benjamina5022392017-07-10 17:40:39 -04007806 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007807 flags: []string{
7808 "-require-any-client-certificate",
7809 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007810 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007811 },
7812 shouldFail: true,
7813 expectedError: ":BAD_SIGNATURE:",
7814 })
7815
7816 testCases = append(testCases, testCase{
7817 name: "ServerAuth-InvalidSignature" + suffix,
7818 config: Config{
7819 MaxVersion: ver.version,
7820 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7821 CipherSuites: signingCiphers,
7822 SignSignatureAlgorithms: []signatureAlgorithm{
7823 alg.id,
7824 },
7825 Bugs: ProtocolBugs{
7826 InvalidSignature: true,
7827 },
7828 },
David Benjamina5022392017-07-10 17:40:39 -04007829 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007830 flags: []string{
7831 "-enable-all-curves",
7832 "-enable-ed25519",
7833 },
David Benjamin5208fd42016-07-13 21:43:25 -04007834 shouldFail: true,
7835 expectedError: ":BAD_SIGNATURE:",
7836 })
7837 }
David Benjaminca3d5452016-07-14 12:51:01 -04007838
David Benjamin3ef76972016-10-17 17:59:54 -04007839 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007840 testCases = append(testCases, testCase{
7841 name: "ClientAuth-Sign-Negotiate" + suffix,
7842 config: Config{
7843 MaxVersion: ver.version,
7844 ClientAuth: RequireAnyClientCert,
7845 VerifySignatureAlgorithms: allAlgorithms,
7846 },
David Benjamina5022392017-07-10 17:40:39 -04007847 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007848 flags: []string{
7849 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7850 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7851 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007852 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007853 "-signing-prefs", strconv.Itoa(int(alg.id)),
7854 },
7855 expectedPeerSignatureAlgorithm: alg.id,
7856 })
7857
7858 testCases = append(testCases, testCase{
7859 testType: serverTest,
7860 name: "ServerAuth-Sign-Negotiate" + suffix,
7861 config: Config{
7862 MaxVersion: ver.version,
7863 CipherSuites: signingCiphers,
7864 VerifySignatureAlgorithms: allAlgorithms,
7865 },
David Benjamina5022392017-07-10 17:40:39 -04007866 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007867 flags: []string{
7868 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7869 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7870 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007871 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007872 "-signing-prefs", strconv.Itoa(int(alg.id)),
7873 },
7874 expectedPeerSignatureAlgorithm: alg.id,
7875 })
7876 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007877 }
David Benjamin000800a2014-11-14 01:43:59 -05007878 }
7879
Nick Harper60edffd2016-06-21 15:19:24 -07007880 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007881 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007882 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007883 config: Config{
7884 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007885 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007886 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007887 signatureECDSAWithP521AndSHA512,
7888 signatureRSAPKCS1WithSHA384,
7889 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007890 },
7891 },
7892 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007893 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7894 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007895 },
Nick Harper60edffd2016-06-21 15:19:24 -07007896 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007897 })
7898
7899 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007900 name: "ClientAuth-SignatureType-TLS13",
7901 config: Config{
7902 ClientAuth: RequireAnyClientCert,
7903 MaxVersion: VersionTLS13,
7904 VerifySignatureAlgorithms: []signatureAlgorithm{
7905 signatureECDSAWithP521AndSHA512,
7906 signatureRSAPKCS1WithSHA384,
7907 signatureRSAPSSWithSHA384,
7908 signatureECDSAWithSHA1,
7909 },
7910 },
7911 flags: []string{
7912 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7913 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7914 },
7915 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7916 })
7917
7918 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007919 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007920 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007922 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007923 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007924 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007925 signatureECDSAWithP521AndSHA512,
7926 signatureRSAPKCS1WithSHA384,
7927 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007928 },
7929 },
Nick Harper60edffd2016-06-21 15:19:24 -07007930 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007931 })
7932
Steven Valdez143e8b32016-07-11 13:19:03 -04007933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "ServerAuth-SignatureType-TLS13",
7936 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007937 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007938 VerifySignatureAlgorithms: []signatureAlgorithm{
7939 signatureECDSAWithP521AndSHA512,
7940 signatureRSAPKCS1WithSHA384,
7941 signatureRSAPSSWithSHA384,
7942 signatureECDSAWithSHA1,
7943 },
7944 },
7945 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7946 })
7947
David Benjamina95e9f32016-07-08 16:28:04 -07007948 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007949 testCases = append(testCases, testCase{
7950 testType: serverTest,
7951 name: "Verify-ClientAuth-SignatureType",
7952 config: Config{
7953 MaxVersion: VersionTLS12,
7954 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007955 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007956 signatureRSAPKCS1WithSHA256,
7957 },
7958 Bugs: ProtocolBugs{
7959 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7960 },
7961 },
7962 flags: []string{
7963 "-require-any-client-certificate",
7964 },
7965 shouldFail: true,
7966 expectedError: ":WRONG_SIGNATURE_TYPE:",
7967 })
7968
7969 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007970 testType: serverTest,
7971 name: "Verify-ClientAuth-SignatureType-TLS13",
7972 config: Config{
7973 MaxVersion: VersionTLS13,
7974 Certificates: []Certificate{rsaCertificate},
7975 SignSignatureAlgorithms: []signatureAlgorithm{
7976 signatureRSAPSSWithSHA256,
7977 },
7978 Bugs: ProtocolBugs{
7979 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7980 },
7981 },
7982 flags: []string{
7983 "-require-any-client-certificate",
7984 },
7985 shouldFail: true,
7986 expectedError: ":WRONG_SIGNATURE_TYPE:",
7987 })
7988
7989 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007990 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007991 config: Config{
7992 MaxVersion: VersionTLS12,
7993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007994 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007995 signatureRSAPKCS1WithSHA256,
7996 },
7997 Bugs: ProtocolBugs{
7998 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7999 },
8000 },
8001 shouldFail: true,
8002 expectedError: ":WRONG_SIGNATURE_TYPE:",
8003 })
8004
Steven Valdez143e8b32016-07-11 13:19:03 -04008005 testCases = append(testCases, testCase{
8006 name: "Verify-ServerAuth-SignatureType-TLS13",
8007 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008008 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008009 SignSignatureAlgorithms: []signatureAlgorithm{
8010 signatureRSAPSSWithSHA256,
8011 },
8012 Bugs: ProtocolBugs{
8013 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8014 },
8015 },
8016 shouldFail: true,
8017 expectedError: ":WRONG_SIGNATURE_TYPE:",
8018 })
8019
David Benjamin51dd7d62016-07-08 16:07:01 -07008020 // Test that, if the list is missing, the peer falls back to SHA-1 in
8021 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008022 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008023 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008025 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008026 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008027 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008028 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008029 },
8030 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008031 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008032 },
8033 },
8034 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008035 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8036 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008037 },
8038 })
8039
8040 testCases = append(testCases, testCase{
8041 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008042 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008043 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008044 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008045 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008046 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008047 },
8048 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008049 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008050 },
8051 },
David Benjaminee32bea2016-08-17 13:36:44 -04008052 flags: []string{
8053 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8054 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8055 },
8056 })
8057
8058 testCases = append(testCases, testCase{
8059 name: "ClientAuth-SHA1-Fallback-ECDSA",
8060 config: Config{
8061 MaxVersion: VersionTLS12,
8062 ClientAuth: RequireAnyClientCert,
8063 VerifySignatureAlgorithms: []signatureAlgorithm{
8064 signatureECDSAWithSHA1,
8065 },
8066 Bugs: ProtocolBugs{
8067 NoSignatureAlgorithms: true,
8068 },
8069 },
8070 flags: []string{
8071 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8072 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8073 },
8074 })
8075
8076 testCases = append(testCases, testCase{
8077 testType: serverTest,
8078 name: "ServerAuth-SHA1-Fallback-ECDSA",
8079 config: Config{
8080 MaxVersion: VersionTLS12,
8081 VerifySignatureAlgorithms: []signatureAlgorithm{
8082 signatureECDSAWithSHA1,
8083 },
8084 Bugs: ProtocolBugs{
8085 NoSignatureAlgorithms: true,
8086 },
8087 },
8088 flags: []string{
8089 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8090 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8091 },
David Benjamin000800a2014-11-14 01:43:59 -05008092 })
David Benjamin72dc7832015-03-16 17:49:43 -04008093
David Benjamin51dd7d62016-07-08 16:07:01 -07008094 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008095 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008096 config: Config{
8097 MaxVersion: VersionTLS13,
8098 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008099 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008100 signatureRSAPKCS1WithSHA1,
8101 },
8102 Bugs: ProtocolBugs{
8103 NoSignatureAlgorithms: true,
8104 },
8105 },
8106 flags: []string{
8107 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8108 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8109 },
David Benjamin48901652016-08-01 12:12:47 -04008110 shouldFail: true,
8111 // An empty CertificateRequest signature algorithm list is a
8112 // syntax error in TLS 1.3.
8113 expectedError: ":DECODE_ERROR:",
8114 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008115 })
8116
8117 testCases = append(testCases, testCase{
8118 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008119 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008120 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008121 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008122 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008123 signatureRSAPKCS1WithSHA1,
8124 },
8125 Bugs: ProtocolBugs{
8126 NoSignatureAlgorithms: true,
8127 },
8128 },
8129 shouldFail: true,
8130 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8131 })
8132
David Benjaminb62d2872016-07-18 14:55:02 +02008133 // Test that hash preferences are enforced. BoringSSL does not implement
8134 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008135 testCases = append(testCases, testCase{
8136 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008137 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008139 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008140 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008141 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008142 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008143 },
8144 Bugs: ProtocolBugs{
8145 IgnorePeerSignatureAlgorithmPreferences: true,
8146 },
8147 },
8148 flags: []string{"-require-any-client-certificate"},
8149 shouldFail: true,
8150 expectedError: ":WRONG_SIGNATURE_TYPE:",
8151 })
8152
8153 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008154 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008156 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008158 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008159 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008160 },
8161 Bugs: ProtocolBugs{
8162 IgnorePeerSignatureAlgorithmPreferences: true,
8163 },
8164 },
8165 shouldFail: true,
8166 expectedError: ":WRONG_SIGNATURE_TYPE:",
8167 })
David Benjaminb62d2872016-07-18 14:55:02 +02008168 testCases = append(testCases, testCase{
8169 testType: serverTest,
8170 name: "ClientAuth-Enforced-TLS13",
8171 config: Config{
8172 MaxVersion: VersionTLS13,
8173 Certificates: []Certificate{rsaCertificate},
8174 SignSignatureAlgorithms: []signatureAlgorithm{
8175 signatureRSAPKCS1WithMD5,
8176 },
8177 Bugs: ProtocolBugs{
8178 IgnorePeerSignatureAlgorithmPreferences: true,
8179 IgnoreSignatureVersionChecks: true,
8180 },
8181 },
8182 flags: []string{"-require-any-client-certificate"},
8183 shouldFail: true,
8184 expectedError: ":WRONG_SIGNATURE_TYPE:",
8185 })
8186
8187 testCases = append(testCases, testCase{
8188 name: "ServerAuth-Enforced-TLS13",
8189 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008190 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008191 SignSignatureAlgorithms: []signatureAlgorithm{
8192 signatureRSAPKCS1WithMD5,
8193 },
8194 Bugs: ProtocolBugs{
8195 IgnorePeerSignatureAlgorithmPreferences: true,
8196 IgnoreSignatureVersionChecks: true,
8197 },
8198 },
8199 shouldFail: true,
8200 expectedError: ":WRONG_SIGNATURE_TYPE:",
8201 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008202
8203 // Test that the agreed upon digest respects the client preferences and
8204 // the server digests.
8205 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008206 name: "NoCommonAlgorithms-Digests",
8207 config: Config{
8208 MaxVersion: VersionTLS12,
8209 ClientAuth: RequireAnyClientCert,
8210 VerifySignatureAlgorithms: []signatureAlgorithm{
8211 signatureRSAPKCS1WithSHA512,
8212 signatureRSAPKCS1WithSHA1,
8213 },
8214 },
8215 flags: []string{
8216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8218 "-digest-prefs", "SHA256",
8219 },
8220 shouldFail: true,
8221 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8222 })
8223 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008224 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008226 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008227 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008228 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008229 signatureRSAPKCS1WithSHA512,
8230 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008231 },
8232 },
8233 flags: []string{
8234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008236 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008237 },
David Benjaminca3d5452016-07-14 12:51:01 -04008238 shouldFail: true,
8239 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8240 })
8241 testCases = append(testCases, testCase{
8242 name: "NoCommonAlgorithms-TLS13",
8243 config: Config{
8244 MaxVersion: VersionTLS13,
8245 ClientAuth: RequireAnyClientCert,
8246 VerifySignatureAlgorithms: []signatureAlgorithm{
8247 signatureRSAPSSWithSHA512,
8248 signatureRSAPSSWithSHA384,
8249 },
8250 },
8251 flags: []string{
8252 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8253 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8254 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8255 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008256 shouldFail: true,
8257 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008258 })
8259 testCases = append(testCases, testCase{
8260 name: "Agree-Digest-SHA256",
8261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008262 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008263 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008264 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008265 signatureRSAPKCS1WithSHA1,
8266 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008267 },
8268 },
8269 flags: []string{
8270 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8271 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008272 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008273 },
Nick Harper60edffd2016-06-21 15:19:24 -07008274 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008275 })
8276 testCases = append(testCases, testCase{
8277 name: "Agree-Digest-SHA1",
8278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008279 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008280 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008281 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008282 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008283 },
8284 },
8285 flags: []string{
8286 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8287 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008288 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008289 },
Nick Harper60edffd2016-06-21 15:19:24 -07008290 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008291 })
8292 testCases = append(testCases, testCase{
8293 name: "Agree-Digest-Default",
8294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008295 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008296 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008297 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008298 signatureRSAPKCS1WithSHA256,
8299 signatureECDSAWithP256AndSHA256,
8300 signatureRSAPKCS1WithSHA1,
8301 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008302 },
8303 },
8304 flags: []string{
8305 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8306 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8307 },
Nick Harper60edffd2016-06-21 15:19:24 -07008308 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008309 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008310
David Benjaminca3d5452016-07-14 12:51:01 -04008311 // Test that the signing preference list may include extra algorithms
8312 // without negotiation problems.
8313 testCases = append(testCases, testCase{
8314 testType: serverTest,
8315 name: "FilterExtraAlgorithms",
8316 config: Config{
8317 MaxVersion: VersionTLS12,
8318 VerifySignatureAlgorithms: []signatureAlgorithm{
8319 signatureRSAPKCS1WithSHA256,
8320 },
8321 },
8322 flags: []string{
8323 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8324 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8325 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8326 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8327 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8328 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8329 },
8330 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8331 })
8332
David Benjamin4c3ddf72016-06-29 18:13:53 -04008333 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8334 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008335 testCases = append(testCases, testCase{
8336 name: "CheckLeafCurve",
8337 config: Config{
8338 MaxVersion: VersionTLS12,
8339 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008340 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008341 },
8342 flags: []string{"-p384-only"},
8343 shouldFail: true,
8344 expectedError: ":BAD_ECC_CERT:",
8345 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008346
8347 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8348 testCases = append(testCases, testCase{
8349 name: "CheckLeafCurve-TLS13",
8350 config: Config{
8351 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008352 Certificates: []Certificate{ecdsaP256Certificate},
8353 },
8354 flags: []string{"-p384-only"},
8355 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008356
8357 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8358 testCases = append(testCases, testCase{
8359 name: "ECDSACurveMismatch-Verify-TLS12",
8360 config: Config{
8361 MaxVersion: VersionTLS12,
8362 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8363 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008364 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008365 signatureECDSAWithP384AndSHA384,
8366 },
8367 },
8368 })
8369
8370 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8371 testCases = append(testCases, testCase{
8372 name: "ECDSACurveMismatch-Verify-TLS13",
8373 config: Config{
8374 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008375 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008376 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008377 signatureECDSAWithP384AndSHA384,
8378 },
8379 Bugs: ProtocolBugs{
8380 SkipECDSACurveCheck: true,
8381 },
8382 },
8383 shouldFail: true,
8384 expectedError: ":WRONG_SIGNATURE_TYPE:",
8385 })
8386
8387 // Signature algorithm selection in TLS 1.3 should take the curve into
8388 // account.
8389 testCases = append(testCases, testCase{
8390 testType: serverTest,
8391 name: "ECDSACurveMismatch-Sign-TLS13",
8392 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008393 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008394 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008395 signatureECDSAWithP384AndSHA384,
8396 signatureECDSAWithP256AndSHA256,
8397 },
8398 },
8399 flags: []string{
8400 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8401 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8402 },
8403 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8404 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008405
8406 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8407 // server does not attempt to sign in that case.
8408 testCases = append(testCases, testCase{
8409 testType: serverTest,
8410 name: "RSA-PSS-Large",
8411 config: Config{
8412 MaxVersion: VersionTLS13,
8413 VerifySignatureAlgorithms: []signatureAlgorithm{
8414 signatureRSAPSSWithSHA512,
8415 },
8416 },
8417 flags: []string{
8418 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8419 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8420 },
8421 shouldFail: true,
8422 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8423 })
David Benjamin57e929f2016-08-30 00:30:38 -04008424
8425 // Test that RSA-PSS is enabled by default for TLS 1.2.
8426 testCases = append(testCases, testCase{
8427 testType: clientTest,
8428 name: "RSA-PSS-Default-Verify",
8429 config: Config{
8430 MaxVersion: VersionTLS12,
8431 SignSignatureAlgorithms: []signatureAlgorithm{
8432 signatureRSAPSSWithSHA256,
8433 },
8434 },
8435 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8436 })
8437
8438 testCases = append(testCases, testCase{
8439 testType: serverTest,
8440 name: "RSA-PSS-Default-Sign",
8441 config: Config{
8442 MaxVersion: VersionTLS12,
8443 VerifySignatureAlgorithms: []signatureAlgorithm{
8444 signatureRSAPSSWithSHA256,
8445 },
8446 },
8447 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8448 })
David Benjamin69522112017-03-28 15:38:29 -05008449
8450 // TLS 1.1 and below has no way to advertise support for or negotiate
8451 // Ed25519's signature algorithm.
8452 testCases = append(testCases, testCase{
8453 testType: clientTest,
8454 name: "NoEd25519-TLS11-ServerAuth-Verify",
8455 config: Config{
8456 MaxVersion: VersionTLS11,
8457 Certificates: []Certificate{ed25519Certificate},
8458 Bugs: ProtocolBugs{
8459 // Sign with Ed25519 even though it is TLS 1.1.
8460 UseLegacySigningAlgorithm: signatureEd25519,
8461 },
8462 },
8463 flags: []string{"-enable-ed25519"},
8464 shouldFail: true,
8465 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8466 })
8467 testCases = append(testCases, testCase{
8468 testType: serverTest,
8469 name: "NoEd25519-TLS11-ServerAuth-Sign",
8470 config: Config{
8471 MaxVersion: VersionTLS11,
8472 },
8473 flags: []string{
8474 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8475 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8476 },
8477 shouldFail: true,
8478 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8479 })
8480 testCases = append(testCases, testCase{
8481 testType: serverTest,
8482 name: "NoEd25519-TLS11-ClientAuth-Verify",
8483 config: Config{
8484 MaxVersion: VersionTLS11,
8485 Certificates: []Certificate{ed25519Certificate},
8486 Bugs: ProtocolBugs{
8487 // Sign with Ed25519 even though it is TLS 1.1.
8488 UseLegacySigningAlgorithm: signatureEd25519,
8489 },
8490 },
8491 flags: []string{
8492 "-enable-ed25519",
8493 "-require-any-client-certificate",
8494 },
8495 shouldFail: true,
8496 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8497 })
8498 testCases = append(testCases, testCase{
8499 testType: clientTest,
8500 name: "NoEd25519-TLS11-ClientAuth-Sign",
8501 config: Config{
8502 MaxVersion: VersionTLS11,
8503 ClientAuth: RequireAnyClientCert,
8504 },
8505 flags: []string{
8506 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8507 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8508 },
8509 shouldFail: true,
8510 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8511 })
8512
8513 // Test Ed25519 is not advertised by default.
8514 testCases = append(testCases, testCase{
8515 testType: clientTest,
8516 name: "Ed25519DefaultDisable-NoAdvertise",
8517 config: Config{
8518 Certificates: []Certificate{ed25519Certificate},
8519 },
8520 shouldFail: true,
8521 expectedLocalError: "tls: no common signature algorithms",
8522 })
8523
8524 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8525 // preferences.
8526 testCases = append(testCases, testCase{
8527 testType: clientTest,
8528 name: "Ed25519DefaultDisable-NoAccept",
8529 config: Config{
8530 Certificates: []Certificate{ed25519Certificate},
8531 Bugs: ProtocolBugs{
8532 IgnorePeerSignatureAlgorithmPreferences: true,
8533 },
8534 },
8535 shouldFail: true,
8536 expectedLocalError: "remote error: illegal parameter",
8537 expectedError: ":WRONG_SIGNATURE_TYPE:",
8538 })
David Benjamin71c21b42017-04-14 17:05:40 -04008539
8540 // Test that configuring verify preferences changes what the client
8541 // advertises.
8542 testCases = append(testCases, testCase{
8543 name: "VerifyPreferences-Advertised",
8544 config: Config{
8545 Certificates: []Certificate{rsaCertificate},
8546 SignSignatureAlgorithms: []signatureAlgorithm{
8547 signatureRSAPSSWithSHA256,
8548 signatureRSAPSSWithSHA384,
8549 signatureRSAPSSWithSHA512,
8550 },
8551 },
8552 flags: []string{
8553 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8554 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8555 },
8556 })
8557
8558 // Test that the client advertises a set which the runner can find
8559 // nothing in common with.
8560 testCases = append(testCases, testCase{
8561 name: "VerifyPreferences-NoCommonAlgorithms",
8562 config: Config{
8563 Certificates: []Certificate{rsaCertificate},
8564 SignSignatureAlgorithms: []signatureAlgorithm{
8565 signatureRSAPSSWithSHA256,
8566 signatureRSAPSSWithSHA512,
8567 },
8568 },
8569 flags: []string{
8570 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8571 },
8572 shouldFail: true,
8573 expectedLocalError: "tls: no common signature algorithms",
8574 })
8575
8576 // Test that the client enforces its preferences when configured.
8577 testCases = append(testCases, testCase{
8578 name: "VerifyPreferences-Enforced",
8579 config: Config{
8580 Certificates: []Certificate{rsaCertificate},
8581 SignSignatureAlgorithms: []signatureAlgorithm{
8582 signatureRSAPSSWithSHA256,
8583 signatureRSAPSSWithSHA512,
8584 },
8585 Bugs: ProtocolBugs{
8586 IgnorePeerSignatureAlgorithmPreferences: true,
8587 },
8588 },
8589 flags: []string{
8590 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8591 },
8592 shouldFail: true,
8593 expectedLocalError: "remote error: illegal parameter",
8594 expectedError: ":WRONG_SIGNATURE_TYPE:",
8595 })
8596
8597 // Test that explicitly configuring Ed25519 is as good as changing the
8598 // boolean toggle.
8599 testCases = append(testCases, testCase{
8600 name: "VerifyPreferences-Ed25519",
8601 config: Config{
8602 Certificates: []Certificate{ed25519Certificate},
8603 },
8604 flags: []string{
8605 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8606 },
8607 })
David Benjamin000800a2014-11-14 01:43:59 -05008608}
8609
David Benjamin83f90402015-01-27 01:09:43 -05008610// timeouts is the retransmit schedule for BoringSSL. It doubles and
8611// caps at 60 seconds. On the 13th timeout, it gives up.
8612var timeouts = []time.Duration{
8613 1 * time.Second,
8614 2 * time.Second,
8615 4 * time.Second,
8616 8 * time.Second,
8617 16 * time.Second,
8618 32 * time.Second,
8619 60 * time.Second,
8620 60 * time.Second,
8621 60 * time.Second,
8622 60 * time.Second,
8623 60 * time.Second,
8624 60 * time.Second,
8625 60 * time.Second,
8626}
8627
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008628// shortTimeouts is an alternate set of timeouts which would occur if the
8629// initial timeout duration was set to 250ms.
8630var shortTimeouts = []time.Duration{
8631 250 * time.Millisecond,
8632 500 * time.Millisecond,
8633 1 * time.Second,
8634 2 * time.Second,
8635 4 * time.Second,
8636 8 * time.Second,
8637 16 * time.Second,
8638 32 * time.Second,
8639 60 * time.Second,
8640 60 * time.Second,
8641 60 * time.Second,
8642 60 * time.Second,
8643 60 * time.Second,
8644}
8645
David Benjamin83f90402015-01-27 01:09:43 -05008646func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008647 // These tests work by coordinating some behavior on both the shim and
8648 // the runner.
8649 //
8650 // TimeoutSchedule configures the runner to send a series of timeout
8651 // opcodes to the shim (see packetAdaptor) immediately before reading
8652 // each peer handshake flight N. The timeout opcode both simulates a
8653 // timeout in the shim and acts as a synchronization point to help the
8654 // runner bracket each handshake flight.
8655 //
8656 // We assume the shim does not read from the channel eagerly. It must
8657 // first wait until it has sent flight N and is ready to receive
8658 // handshake flight N+1. At this point, it will process the timeout
8659 // opcode. It must then immediately respond with a timeout ACK and act
8660 // as if the shim was idle for the specified amount of time.
8661 //
8662 // The runner then drops all packets received before the ACK and
8663 // continues waiting for flight N. This ordering results in one attempt
8664 // at sending flight N to be dropped. For the test to complete, the
8665 // shim must send flight N again, testing that the shim implements DTLS
8666 // retransmit on a timeout.
8667
Steven Valdez143e8b32016-07-11 13:19:03 -04008668 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008669 // likely be more epochs to cross and the final message's retransmit may
8670 // be more complex.
8671
David Benjamin11c82892017-02-23 20:40:31 -05008672 // Test that this is indeed the timeout schedule. Stress all
8673 // four patterns of handshake.
8674 for i := 1; i < len(timeouts); i++ {
8675 number := strconv.Itoa(i)
8676 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008677 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008678 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008679 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008680 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008681 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008682 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008683 },
8684 },
8685 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008686 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008687 })
David Benjamin11c82892017-02-23 20:40:31 -05008688 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008689 protocol: dtls,
8690 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008691 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008693 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008694 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008695 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008696 },
8697 },
8698 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008699 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008700 })
8701 }
David Benjamin11c82892017-02-23 20:40:31 -05008702
8703 // Test that exceeding the timeout schedule hits a read
8704 // timeout.
8705 testCases = append(testCases, testCase{
8706 protocol: dtls,
8707 name: "DTLS-Retransmit-Timeout",
8708 config: Config{
8709 MaxVersion: VersionTLS12,
8710 Bugs: ProtocolBugs{
8711 TimeoutSchedule: timeouts,
8712 },
8713 },
8714 resumeSession: true,
8715 flags: []string{"-async"},
8716 shouldFail: true,
8717 expectedError: ":READ_TIMEOUT_EXPIRED:",
8718 })
8719
8720 // Test that timeout handling has a fudge factor, due to API
8721 // problems.
8722 testCases = append(testCases, testCase{
8723 protocol: dtls,
8724 name: "DTLS-Retransmit-Fudge",
8725 config: Config{
8726 MaxVersion: VersionTLS12,
8727 Bugs: ProtocolBugs{
8728 TimeoutSchedule: []time.Duration{
8729 timeouts[0] - 10*time.Millisecond,
8730 },
8731 },
8732 },
8733 resumeSession: true,
8734 flags: []string{"-async"},
8735 })
8736
8737 // Test that the final Finished retransmitting isn't
8738 // duplicated if the peer badly fragments everything.
8739 testCases = append(testCases, testCase{
8740 testType: serverTest,
8741 protocol: dtls,
8742 name: "DTLS-Retransmit-Fragmented",
8743 config: Config{
8744 MaxVersion: VersionTLS12,
8745 Bugs: ProtocolBugs{
8746 TimeoutSchedule: []time.Duration{timeouts[0]},
8747 MaxHandshakeRecordLength: 2,
8748 },
8749 },
8750 flags: []string{"-async"},
8751 })
8752
8753 // Test the timeout schedule when a shorter initial timeout duration is set.
8754 testCases = append(testCases, testCase{
8755 protocol: dtls,
8756 name: "DTLS-Retransmit-Short-Client",
8757 config: Config{
8758 MaxVersion: VersionTLS12,
8759 Bugs: ProtocolBugs{
8760 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8761 },
8762 },
8763 resumeSession: true,
8764 flags: []string{
8765 "-async",
8766 "-initial-timeout-duration-ms", "250",
8767 },
8768 })
8769 testCases = append(testCases, testCase{
8770 protocol: dtls,
8771 testType: serverTest,
8772 name: "DTLS-Retransmit-Short-Server",
8773 config: Config{
8774 MaxVersion: VersionTLS12,
8775 Bugs: ProtocolBugs{
8776 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8777 },
8778 },
8779 resumeSession: true,
8780 flags: []string{
8781 "-async",
8782 "-initial-timeout-duration-ms", "250",
8783 },
8784 })
David Benjamin302b8182017-08-22 14:47:22 -07008785
8786 // If the shim sends the last Finished (server full or client resume
8787 // handshakes), it must retransmit that Finished when it sees a
8788 // post-handshake penultimate Finished from the runner. The above tests
8789 // cover this. Conversely, if the shim sends the penultimate Finished
8790 // (client full or server resume), test that it does not retransmit.
8791 testCases = append(testCases, testCase{
8792 protocol: dtls,
8793 testType: clientTest,
8794 name: "DTLS-StrayRetransmitFinished-ClientFull",
8795 config: Config{
8796 MaxVersion: VersionTLS12,
8797 Bugs: ProtocolBugs{
8798 RetransmitFinished: true,
8799 },
8800 },
8801 })
8802 testCases = append(testCases, testCase{
8803 protocol: dtls,
8804 testType: serverTest,
8805 name: "DTLS-StrayRetransmitFinished-ServerResume",
8806 config: Config{
8807 MaxVersion: VersionTLS12,
8808 },
8809 resumeConfig: &Config{
8810 MaxVersion: VersionTLS12,
8811 Bugs: ProtocolBugs{
8812 RetransmitFinished: true,
8813 },
8814 },
8815 resumeSession: true,
8816 })
David Benjamin83f90402015-01-27 01:09:43 -05008817}
8818
David Benjaminc565ebb2015-04-03 04:06:36 -04008819func addExportKeyingMaterialTests() {
8820 for _, vers := range tlsVersions {
8821 if vers.version == VersionSSL30 {
8822 continue
8823 }
8824 testCases = append(testCases, testCase{
8825 name: "ExportKeyingMaterial-" + vers.name,
8826 config: Config{
8827 MaxVersion: vers.version,
8828 },
David Benjamina5022392017-07-10 17:40:39 -04008829 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008830 exportKeyingMaterial: 1024,
8831 exportLabel: "label",
8832 exportContext: "context",
8833 useExportContext: true,
8834 })
8835 testCases = append(testCases, testCase{
8836 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8837 config: Config{
8838 MaxVersion: vers.version,
8839 },
David Benjamina5022392017-07-10 17:40:39 -04008840 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008841 exportKeyingMaterial: 1024,
8842 })
8843 testCases = append(testCases, testCase{
8844 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8845 config: Config{
8846 MaxVersion: vers.version,
8847 },
David Benjamina5022392017-07-10 17:40:39 -04008848 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008849 exportKeyingMaterial: 1024,
8850 useExportContext: true,
8851 })
8852 testCases = append(testCases, testCase{
8853 name: "ExportKeyingMaterial-Small-" + vers.name,
8854 config: Config{
8855 MaxVersion: vers.version,
8856 },
David Benjamina5022392017-07-10 17:40:39 -04008857 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008858 exportKeyingMaterial: 1,
8859 exportLabel: "label",
8860 exportContext: "context",
8861 useExportContext: true,
8862 })
8863 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008864
David Benjaminc565ebb2015-04-03 04:06:36 -04008865 testCases = append(testCases, testCase{
8866 name: "ExportKeyingMaterial-SSL3",
8867 config: Config{
8868 MaxVersion: VersionSSL30,
8869 },
8870 exportKeyingMaterial: 1024,
8871 exportLabel: "label",
8872 exportContext: "context",
8873 useExportContext: true,
8874 shouldFail: true,
8875 expectedError: "failed to export keying material",
8876 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008877
8878 // Exporters work during a False Start.
8879 testCases = append(testCases, testCase{
8880 name: "ExportKeyingMaterial-FalseStart",
8881 config: Config{
8882 MaxVersion: VersionTLS12,
8883 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8884 NextProtos: []string{"foo"},
8885 Bugs: ProtocolBugs{
8886 ExpectFalseStart: true,
8887 },
8888 },
8889 flags: []string{
8890 "-false-start",
8891 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008892 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008893 },
8894 shimWritesFirst: true,
8895 exportKeyingMaterial: 1024,
8896 exportLabel: "label",
8897 exportContext: "context",
8898 useExportContext: true,
8899 })
8900
8901 // Exporters do not work in the middle of a renegotiation. Test this by
8902 // triggering the exporter after every SSL_read call and configuring the
8903 // shim to run asynchronously.
8904 testCases = append(testCases, testCase{
8905 name: "ExportKeyingMaterial-Renegotiate",
8906 config: Config{
8907 MaxVersion: VersionTLS12,
8908 },
8909 renegotiate: 1,
8910 flags: []string{
8911 "-async",
8912 "-use-exporter-between-reads",
8913 "-renegotiate-freely",
8914 "-expect-total-renegotiations", "1",
8915 },
8916 shouldFail: true,
8917 expectedError: "failed to export keying material",
8918 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008919}
8920
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008921func addTLSUniqueTests() {
8922 for _, isClient := range []bool{false, true} {
8923 for _, isResumption := range []bool{false, true} {
8924 for _, hasEMS := range []bool{false, true} {
8925 var suffix string
8926 if isResumption {
8927 suffix = "Resume-"
8928 } else {
8929 suffix = "Full-"
8930 }
8931
8932 if hasEMS {
8933 suffix += "EMS-"
8934 } else {
8935 suffix += "NoEMS-"
8936 }
8937
8938 if isClient {
8939 suffix += "Client"
8940 } else {
8941 suffix += "Server"
8942 }
8943
8944 test := testCase{
8945 name: "TLSUnique-" + suffix,
8946 testTLSUnique: true,
8947 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008948 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008949 Bugs: ProtocolBugs{
8950 NoExtendedMasterSecret: !hasEMS,
8951 },
8952 },
8953 }
8954
8955 if isResumption {
8956 test.resumeSession = true
8957 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008958 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008959 Bugs: ProtocolBugs{
8960 NoExtendedMasterSecret: !hasEMS,
8961 },
8962 }
8963 }
8964
8965 if isResumption && !hasEMS {
8966 test.shouldFail = true
8967 test.expectedError = "failed to get tls-unique"
8968 }
8969
8970 testCases = append(testCases, test)
8971 }
8972 }
8973 }
8974}
8975
Adam Langley09505632015-07-30 18:10:13 -07008976func addCustomExtensionTests() {
8977 expectedContents := "custom extension"
8978 emptyString := ""
8979
8980 for _, isClient := range []bool{false, true} {
8981 suffix := "Server"
8982 flag := "-enable-server-custom-extension"
8983 testType := serverTest
8984 if isClient {
8985 suffix = "Client"
8986 flag = "-enable-client-custom-extension"
8987 testType = clientTest
8988 }
8989
8990 testCases = append(testCases, testCase{
8991 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008992 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008994 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008995 Bugs: ProtocolBugs{
8996 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008997 ExpectedCustomExtension: &expectedContents,
8998 },
8999 },
9000 flags: []string{flag},
9001 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009002 testCases = append(testCases, testCase{
9003 testType: testType,
9004 name: "CustomExtensions-" + suffix + "-TLS13",
9005 config: Config{
9006 MaxVersion: VersionTLS13,
9007 Bugs: ProtocolBugs{
9008 CustomExtension: expectedContents,
9009 ExpectedCustomExtension: &expectedContents,
9010 },
9011 },
9012 flags: []string{flag},
9013 })
Adam Langley09505632015-07-30 18:10:13 -07009014
9015 // If the parse callback fails, the handshake should also fail.
9016 testCases = append(testCases, testCase{
9017 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009018 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009019 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009020 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009021 Bugs: ProtocolBugs{
9022 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07009023 ExpectedCustomExtension: &expectedContents,
9024 },
9025 },
David Benjamin399e7c92015-07-30 23:01:27 -04009026 flags: []string{flag},
9027 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009028 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9029 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009030 testCases = append(testCases, testCase{
9031 testType: testType,
9032 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9033 config: Config{
9034 MaxVersion: VersionTLS13,
9035 Bugs: ProtocolBugs{
9036 CustomExtension: expectedContents + "foo",
9037 ExpectedCustomExtension: &expectedContents,
9038 },
9039 },
9040 flags: []string{flag},
9041 shouldFail: true,
9042 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9043 })
Adam Langley09505632015-07-30 18:10:13 -07009044
9045 // If the add callback fails, the handshake should also fail.
9046 testCases = append(testCases, testCase{
9047 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009048 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009050 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009051 Bugs: ProtocolBugs{
9052 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009053 ExpectedCustomExtension: &expectedContents,
9054 },
9055 },
David Benjamin399e7c92015-07-30 23:01:27 -04009056 flags: []string{flag, "-custom-extension-fail-add"},
9057 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009058 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9059 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009060 testCases = append(testCases, testCase{
9061 testType: testType,
9062 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9063 config: Config{
9064 MaxVersion: VersionTLS13,
9065 Bugs: ProtocolBugs{
9066 CustomExtension: expectedContents,
9067 ExpectedCustomExtension: &expectedContents,
9068 },
9069 },
9070 flags: []string{flag, "-custom-extension-fail-add"},
9071 shouldFail: true,
9072 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9073 })
Adam Langley09505632015-07-30 18:10:13 -07009074
9075 // If the add callback returns zero, no extension should be
9076 // added.
9077 skipCustomExtension := expectedContents
9078 if isClient {
9079 // For the case where the client skips sending the
9080 // custom extension, the server must not “echo” it.
9081 skipCustomExtension = ""
9082 }
9083 testCases = append(testCases, testCase{
9084 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009085 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009087 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009088 Bugs: ProtocolBugs{
9089 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009090 ExpectedCustomExtension: &emptyString,
9091 },
9092 },
9093 flags: []string{flag, "-custom-extension-skip"},
9094 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009095 testCases = append(testCases, testCase{
9096 testType: testType,
9097 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9098 config: Config{
9099 MaxVersion: VersionTLS13,
9100 Bugs: ProtocolBugs{
9101 CustomExtension: skipCustomExtension,
9102 ExpectedCustomExtension: &emptyString,
9103 },
9104 },
9105 flags: []string{flag, "-custom-extension-skip"},
9106 })
Adam Langley09505632015-07-30 18:10:13 -07009107 }
9108
Steven Valdezf4ecc842017-08-10 14:02:56 -04009109 // If the client sends both early data and custom extension, the handshake
9110 // should succeed as long as both the extensions aren't returned by the
9111 // server.
9112 testCases = append(testCases, testCase{
9113 testType: clientTest,
9114 name: "CustomExtensions-Client-EarlyData-None",
9115 config: Config{
9116 MaxVersion: VersionTLS13,
9117 MaxEarlyDataSize: 16384,
9118 Bugs: ProtocolBugs{
9119 ExpectedCustomExtension: &expectedContents,
9120 AlwaysRejectEarlyData: true,
9121 },
9122 },
9123 resumeSession: true,
9124 flags: []string{
9125 "-enable-client-custom-extension",
9126 "-enable-early-data",
9127 "-expect-early-data-info",
9128 "-expect-reject-early-data",
9129 },
9130 })
9131
9132 testCases = append(testCases, testCase{
9133 testType: clientTest,
9134 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9135 config: Config{
9136 MaxVersion: VersionTLS13,
9137 MaxEarlyDataSize: 16384,
9138 Bugs: ProtocolBugs{
9139 ExpectedCustomExtension: &expectedContents,
9140 },
9141 },
9142 resumeSession: true,
9143 flags: []string{
9144 "-enable-client-custom-extension",
9145 "-enable-early-data",
9146 "-expect-early-data-info",
9147 "-expect-accept-early-data",
9148 },
9149 })
9150
9151 testCases = append(testCases, testCase{
9152 testType: clientTest,
9153 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9154 config: Config{
9155 MaxVersion: VersionTLS13,
9156 MaxEarlyDataSize: 16384,
9157 Bugs: ProtocolBugs{
9158 AlwaysRejectEarlyData: true,
9159 CustomExtension: expectedContents,
9160 ExpectedCustomExtension: &expectedContents,
9161 },
9162 },
9163 resumeSession: true,
9164 flags: []string{
9165 "-enable-client-custom-extension",
9166 "-enable-early-data",
9167 "-expect-early-data-info",
9168 "-expect-reject-early-data",
9169 },
9170 })
9171
9172 testCases = append(testCases, testCase{
9173 testType: clientTest,
9174 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9175 config: Config{
9176 MaxVersion: VersionTLS13,
9177 MaxEarlyDataSize: 16384,
9178 Bugs: ProtocolBugs{
9179 CustomExtension: expectedContents,
9180 ExpectedCustomExtension: &expectedContents,
9181 },
9182 },
9183 resumeConfig: &Config{
9184 MaxVersion: VersionTLS13,
9185 MaxEarlyDataSize: 16384,
9186 Bugs: ProtocolBugs{
9187 CustomExtension: expectedContents,
9188 ExpectedCustomExtension: &expectedContents,
9189 SendEarlyDataExtension: true,
9190 },
9191 },
9192 resumeSession: true,
9193 shouldFail: true,
9194 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9195 flags: []string{
9196 "-enable-client-custom-extension",
9197 "-enable-early-data",
9198 "-expect-early-data-info",
9199 },
9200 })
9201
9202 // If the server receives both early data and custom extension, only the
9203 // custom extension should be accepted.
9204 testCases = append(testCases, testCase{
9205 testType: serverTest,
9206 name: "CustomExtensions-Server-EarlyDataAccepted",
9207 config: Config{
9208 MaxVersion: VersionTLS13,
9209 MaxEarlyDataSize: 16384,
9210 Bugs: ProtocolBugs{
9211 CustomExtension: expectedContents,
9212 ExpectedCustomExtension: &expectedContents,
9213 ExpectEarlyDataAccepted: false,
9214 },
9215 },
9216 resumeSession: true,
9217 flags: []string{
9218 "-enable-server-custom-extension",
9219 "-enable-early-data",
9220 "-expect-early-data-info",
9221 },
9222 })
9223
Adam Langley09505632015-07-30 18:10:13 -07009224 // The custom extension add callback should not be called if the client
9225 // doesn't send the extension.
9226 testCases = append(testCases, testCase{
9227 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009228 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009229 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009230 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009231 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009232 ExpectedCustomExtension: &emptyString,
9233 },
9234 },
9235 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9236 })
Adam Langley2deb9842015-08-07 11:15:37 -07009237
Steven Valdez143e8b32016-07-11 13:19:03 -04009238 testCases = append(testCases, testCase{
9239 testType: serverTest,
9240 name: "CustomExtensions-NotCalled-Server-TLS13",
9241 config: Config{
9242 MaxVersion: VersionTLS13,
9243 Bugs: ProtocolBugs{
9244 ExpectedCustomExtension: &emptyString,
9245 },
9246 },
9247 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9248 })
9249
Adam Langley2deb9842015-08-07 11:15:37 -07009250 // Test an unknown extension from the server.
9251 testCases = append(testCases, testCase{
9252 testType: clientTest,
9253 name: "UnknownExtension-Client",
9254 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009255 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009256 Bugs: ProtocolBugs{
9257 CustomExtension: expectedContents,
9258 },
9259 },
David Benjamin0c40a962016-08-01 12:05:50 -04009260 shouldFail: true,
9261 expectedError: ":UNEXPECTED_EXTENSION:",
9262 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009263 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009264 testCases = append(testCases, testCase{
9265 testType: clientTest,
9266 name: "UnknownExtension-Client-TLS13",
9267 config: Config{
9268 MaxVersion: VersionTLS13,
9269 Bugs: ProtocolBugs{
9270 CustomExtension: expectedContents,
9271 },
9272 },
David Benjamin0c40a962016-08-01 12:05:50 -04009273 shouldFail: true,
9274 expectedError: ":UNEXPECTED_EXTENSION:",
9275 expectedLocalError: "remote error: unsupported extension",
9276 })
David Benjamin490469f2016-10-05 22:44:38 -04009277 testCases = append(testCases, testCase{
9278 testType: clientTest,
9279 name: "UnknownUnencryptedExtension-Client-TLS13",
9280 config: Config{
9281 MaxVersion: VersionTLS13,
9282 Bugs: ProtocolBugs{
9283 CustomUnencryptedExtension: expectedContents,
9284 },
9285 },
9286 shouldFail: true,
9287 expectedError: ":UNEXPECTED_EXTENSION:",
9288 // The shim must send an alert, but alerts at this point do not
9289 // get successfully decrypted by the runner.
9290 expectedLocalError: "local error: bad record MAC",
9291 })
9292 testCases = append(testCases, testCase{
9293 testType: clientTest,
9294 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9295 config: Config{
9296 MaxVersion: VersionTLS13,
9297 Bugs: ProtocolBugs{
9298 SendUnencryptedALPN: "foo",
9299 },
9300 },
9301 flags: []string{
9302 "-advertise-alpn", "\x03foo\x03bar",
9303 },
9304 shouldFail: true,
9305 expectedError: ":UNEXPECTED_EXTENSION:",
9306 // The shim must send an alert, but alerts at this point do not
9307 // get successfully decrypted by the runner.
9308 expectedLocalError: "local error: bad record MAC",
9309 })
David Benjamin0c40a962016-08-01 12:05:50 -04009310
9311 // Test a known but unoffered extension from the server.
9312 testCases = append(testCases, testCase{
9313 testType: clientTest,
9314 name: "UnofferedExtension-Client",
9315 config: Config{
9316 MaxVersion: VersionTLS12,
9317 Bugs: ProtocolBugs{
9318 SendALPN: "alpn",
9319 },
9320 },
9321 shouldFail: true,
9322 expectedError: ":UNEXPECTED_EXTENSION:",
9323 expectedLocalError: "remote error: unsupported extension",
9324 })
9325 testCases = append(testCases, testCase{
9326 testType: clientTest,
9327 name: "UnofferedExtension-Client-TLS13",
9328 config: Config{
9329 MaxVersion: VersionTLS13,
9330 Bugs: ProtocolBugs{
9331 SendALPN: "alpn",
9332 },
9333 },
9334 shouldFail: true,
9335 expectedError: ":UNEXPECTED_EXTENSION:",
9336 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009337 })
Adam Langley09505632015-07-30 18:10:13 -07009338}
9339
David Benjaminb36a3952015-12-01 18:53:13 -05009340func addRSAClientKeyExchangeTests() {
9341 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9342 testCases = append(testCases, testCase{
9343 testType: serverTest,
9344 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9345 config: Config{
9346 // Ensure the ClientHello version and final
9347 // version are different, to detect if the
9348 // server uses the wrong one.
9349 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009350 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009351 Bugs: ProtocolBugs{
9352 BadRSAClientKeyExchange: bad,
9353 },
9354 },
9355 shouldFail: true,
9356 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9357 })
9358 }
David Benjamine63d9d72016-09-19 18:27:34 -04009359
9360 // The server must compare whatever was in ClientHello.version for the
9361 // RSA premaster.
9362 testCases = append(testCases, testCase{
9363 testType: serverTest,
9364 name: "SendClientVersion-RSA",
9365 config: Config{
9366 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9367 Bugs: ProtocolBugs{
9368 SendClientVersion: 0x1234,
9369 },
9370 },
9371 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9372 })
David Benjaminb36a3952015-12-01 18:53:13 -05009373}
9374
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009375var testCurves = []struct {
9376 name string
9377 id CurveID
9378}{
Adam Langley764ab982017-03-10 18:01:30 -08009379 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009380 {"P-256", CurveP256},
9381 {"P-384", CurveP384},
9382 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009383 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009384}
9385
Steven Valdez5440fe02016-07-18 12:40:30 -04009386const bogusCurve = 0x1234
9387
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009388func addCurveTests() {
9389 for _, curve := range testCurves {
9390 testCases = append(testCases, testCase{
9391 name: "CurveTest-Client-" + curve.name,
9392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009393 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009394 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9395 CurvePreferences: []CurveID{curve.id},
9396 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009397 flags: []string{
9398 "-enable-all-curves",
9399 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9400 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009401 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009402 })
9403 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009404 name: "CurveTest-Client-" + curve.name + "-TLS13",
9405 config: Config{
9406 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009407 CurvePreferences: []CurveID{curve.id},
9408 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009409 flags: []string{
9410 "-enable-all-curves",
9411 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9412 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009413 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009414 })
9415 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009416 testType: serverTest,
9417 name: "CurveTest-Server-" + curve.name,
9418 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009419 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009420 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9421 CurvePreferences: []CurveID{curve.id},
9422 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009423 flags: []string{
9424 "-enable-all-curves",
9425 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9426 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009427 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009428 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009429 testCases = append(testCases, testCase{
9430 testType: serverTest,
9431 name: "CurveTest-Server-" + curve.name + "-TLS13",
9432 config: Config{
9433 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009434 CurvePreferences: []CurveID{curve.id},
9435 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009436 flags: []string{
9437 "-enable-all-curves",
9438 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9439 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009440 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009441 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009442 }
David Benjamin241ae832016-01-15 03:04:54 -05009443
9444 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009445 testCases = append(testCases, testCase{
9446 testType: serverTest,
9447 name: "UnknownCurve",
9448 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009449 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9451 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9452 },
9453 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009454
Steven Valdez803c77a2016-09-06 14:13:43 -04009455 // The server must be tolerant to bogus curves.
9456 testCases = append(testCases, testCase{
9457 testType: serverTest,
9458 name: "UnknownCurve-TLS13",
9459 config: Config{
9460 MaxVersion: VersionTLS13,
9461 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9462 },
9463 })
9464
David Benjamin4c3ddf72016-06-29 18:13:53 -04009465 // The server must not consider ECDHE ciphers when there are no
9466 // supported curves.
9467 testCases = append(testCases, testCase{
9468 testType: serverTest,
9469 name: "NoSupportedCurves",
9470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009471 MaxVersion: VersionTLS12,
9472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9473 Bugs: ProtocolBugs{
9474 NoSupportedCurves: true,
9475 },
9476 },
9477 shouldFail: true,
9478 expectedError: ":NO_SHARED_CIPHER:",
9479 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009480 testCases = append(testCases, testCase{
9481 testType: serverTest,
9482 name: "NoSupportedCurves-TLS13",
9483 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009484 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009485 Bugs: ProtocolBugs{
9486 NoSupportedCurves: true,
9487 },
9488 },
9489 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009490 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009491 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009492
9493 // The server must fall back to another cipher when there are no
9494 // supported curves.
9495 testCases = append(testCases, testCase{
9496 testType: serverTest,
9497 name: "NoCommonCurves",
9498 config: Config{
9499 MaxVersion: VersionTLS12,
9500 CipherSuites: []uint16{
9501 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009502 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009503 },
9504 CurvePreferences: []CurveID{CurveP224},
9505 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009506 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009507 })
9508
9509 // The client must reject bogus curves and disabled curves.
9510 testCases = append(testCases, testCase{
9511 name: "BadECDHECurve",
9512 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009513 MaxVersion: VersionTLS12,
9514 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9515 Bugs: ProtocolBugs{
9516 SendCurve: bogusCurve,
9517 },
9518 },
9519 shouldFail: true,
9520 expectedError: ":WRONG_CURVE:",
9521 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009522 testCases = append(testCases, testCase{
9523 name: "BadECDHECurve-TLS13",
9524 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009525 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009526 Bugs: ProtocolBugs{
9527 SendCurve: bogusCurve,
9528 },
9529 },
9530 shouldFail: true,
9531 expectedError: ":WRONG_CURVE:",
9532 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009533
9534 testCases = append(testCases, testCase{
9535 name: "UnsupportedCurve",
9536 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009537 MaxVersion: VersionTLS12,
9538 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9539 CurvePreferences: []CurveID{CurveP256},
9540 Bugs: ProtocolBugs{
9541 IgnorePeerCurvePreferences: true,
9542 },
9543 },
9544 flags: []string{"-p384-only"},
9545 shouldFail: true,
9546 expectedError: ":WRONG_CURVE:",
9547 })
9548
David Benjamin4f921572016-07-17 14:20:10 +02009549 testCases = append(testCases, testCase{
9550 // TODO(davidben): Add a TLS 1.3 version where
9551 // HelloRetryRequest requests an unsupported curve.
9552 name: "UnsupportedCurve-ServerHello-TLS13",
9553 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009554 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009555 CurvePreferences: []CurveID{CurveP384},
9556 Bugs: ProtocolBugs{
9557 SendCurve: CurveP256,
9558 },
9559 },
9560 flags: []string{"-p384-only"},
9561 shouldFail: true,
9562 expectedError: ":WRONG_CURVE:",
9563 })
9564
David Benjamin4c3ddf72016-06-29 18:13:53 -04009565 // Test invalid curve points.
9566 testCases = append(testCases, testCase{
9567 name: "InvalidECDHPoint-Client",
9568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009569 MaxVersion: VersionTLS12,
9570 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9571 CurvePreferences: []CurveID{CurveP256},
9572 Bugs: ProtocolBugs{
9573 InvalidECDHPoint: true,
9574 },
9575 },
9576 shouldFail: true,
9577 expectedError: ":INVALID_ENCODING:",
9578 })
9579 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009580 name: "InvalidECDHPoint-Client-TLS13",
9581 config: Config{
9582 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009583 CurvePreferences: []CurveID{CurveP256},
9584 Bugs: ProtocolBugs{
9585 InvalidECDHPoint: true,
9586 },
9587 },
9588 shouldFail: true,
9589 expectedError: ":INVALID_ENCODING:",
9590 })
9591 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009592 testType: serverTest,
9593 name: "InvalidECDHPoint-Server",
9594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009595 MaxVersion: VersionTLS12,
9596 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9597 CurvePreferences: []CurveID{CurveP256},
9598 Bugs: ProtocolBugs{
9599 InvalidECDHPoint: true,
9600 },
9601 },
9602 shouldFail: true,
9603 expectedError: ":INVALID_ENCODING:",
9604 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009605 testCases = append(testCases, testCase{
9606 testType: serverTest,
9607 name: "InvalidECDHPoint-Server-TLS13",
9608 config: Config{
9609 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009610 CurvePreferences: []CurveID{CurveP256},
9611 Bugs: ProtocolBugs{
9612 InvalidECDHPoint: true,
9613 },
9614 },
9615 shouldFail: true,
9616 expectedError: ":INVALID_ENCODING:",
9617 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009618
9619 // The previous curve ID should be reported on TLS 1.2 resumption.
9620 testCases = append(testCases, testCase{
9621 name: "CurveID-Resume-Client",
9622 config: Config{
9623 MaxVersion: VersionTLS12,
9624 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9625 CurvePreferences: []CurveID{CurveX25519},
9626 },
9627 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9628 resumeSession: true,
9629 })
9630 testCases = append(testCases, testCase{
9631 testType: serverTest,
9632 name: "CurveID-Resume-Server",
9633 config: Config{
9634 MaxVersion: VersionTLS12,
9635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9636 CurvePreferences: []CurveID{CurveX25519},
9637 },
9638 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9639 resumeSession: true,
9640 })
9641
9642 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9643 // one should be reported.
9644 testCases = append(testCases, testCase{
9645 name: "CurveID-Resume-Client-TLS13",
9646 config: Config{
9647 MaxVersion: VersionTLS13,
9648 CurvePreferences: []CurveID{CurveX25519},
9649 },
9650 resumeConfig: &Config{
9651 MaxVersion: VersionTLS13,
9652 CurvePreferences: []CurveID{CurveP256},
9653 },
9654 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009655 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9656 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009657 },
9658 resumeSession: true,
9659 })
9660 testCases = append(testCases, testCase{
9661 testType: serverTest,
9662 name: "CurveID-Resume-Server-TLS13",
9663 config: Config{
9664 MaxVersion: VersionTLS13,
9665 CurvePreferences: []CurveID{CurveX25519},
9666 },
9667 resumeConfig: &Config{
9668 MaxVersion: VersionTLS13,
9669 CurvePreferences: []CurveID{CurveP256},
9670 },
9671 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009672 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9673 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009674 },
9675 resumeSession: true,
9676 })
David Benjamina81967b2016-12-22 09:16:57 -05009677
9678 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9679 testCases = append(testCases, testCase{
9680 name: "PointFormat-ServerHello-TLS12",
9681 config: Config{
9682 MaxVersion: VersionTLS12,
9683 Bugs: ProtocolBugs{
9684 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9685 },
9686 },
9687 })
9688 testCases = append(testCases, testCase{
9689 name: "PointFormat-EncryptedExtensions-TLS13",
9690 config: Config{
9691 MaxVersion: VersionTLS13,
9692 Bugs: ProtocolBugs{
9693 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9694 },
9695 },
9696 shouldFail: true,
9697 expectedError: ":ERROR_PARSING_EXTENSION:",
9698 })
9699
9700 // Test that we tolerate unknown point formats, as long as
9701 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9702 // check they are still functional.
9703 testCases = append(testCases, testCase{
9704 name: "PointFormat-Client-Tolerance",
9705 config: Config{
9706 MaxVersion: VersionTLS12,
9707 Bugs: ProtocolBugs{
9708 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9709 },
9710 },
9711 })
9712 testCases = append(testCases, testCase{
9713 testType: serverTest,
9714 name: "PointFormat-Server-Tolerance",
9715 config: Config{
9716 MaxVersion: VersionTLS12,
9717 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9718 Bugs: ProtocolBugs{
9719 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9720 },
9721 },
9722 })
9723
9724 // Test TLS 1.2 does not require the point format extension to be
9725 // present.
9726 testCases = append(testCases, testCase{
9727 name: "PointFormat-Client-Missing",
9728 config: Config{
9729 MaxVersion: VersionTLS12,
9730 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9731 Bugs: ProtocolBugs{
9732 SendSupportedPointFormats: []byte{},
9733 },
9734 },
9735 })
9736 testCases = append(testCases, testCase{
9737 testType: serverTest,
9738 name: "PointFormat-Server-Missing",
9739 config: Config{
9740 MaxVersion: VersionTLS12,
9741 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9742 Bugs: ProtocolBugs{
9743 SendSupportedPointFormats: []byte{},
9744 },
9745 },
9746 })
9747
9748 // If the point format extension is present, uncompressed points must be
9749 // offered. BoringSSL requires this whether or not ECDHE is used.
9750 testCases = append(testCases, testCase{
9751 name: "PointFormat-Client-MissingUncompressed",
9752 config: Config{
9753 MaxVersion: VersionTLS12,
9754 Bugs: ProtocolBugs{
9755 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9756 },
9757 },
9758 shouldFail: true,
9759 expectedError: ":ERROR_PARSING_EXTENSION:",
9760 })
9761 testCases = append(testCases, testCase{
9762 testType: serverTest,
9763 name: "PointFormat-Server-MissingUncompressed",
9764 config: Config{
9765 MaxVersion: VersionTLS12,
9766 Bugs: ProtocolBugs{
9767 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9768 },
9769 },
9770 shouldFail: true,
9771 expectedError: ":ERROR_PARSING_EXTENSION:",
9772 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009773}
9774
David Benjaminc9ae27c2016-06-24 22:56:37 -04009775func addTLS13RecordTests() {
9776 testCases = append(testCases, testCase{
9777 name: "TLS13-RecordPadding",
9778 config: Config{
9779 MaxVersion: VersionTLS13,
9780 MinVersion: VersionTLS13,
9781 Bugs: ProtocolBugs{
9782 RecordPadding: 10,
9783 },
9784 },
9785 })
9786
9787 testCases = append(testCases, testCase{
9788 name: "TLS13-EmptyRecords",
9789 config: Config{
9790 MaxVersion: VersionTLS13,
9791 MinVersion: VersionTLS13,
9792 Bugs: ProtocolBugs{
9793 OmitRecordContents: true,
9794 },
9795 },
9796 shouldFail: true,
9797 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9798 })
9799
9800 testCases = append(testCases, testCase{
9801 name: "TLS13-OnlyPadding",
9802 config: Config{
9803 MaxVersion: VersionTLS13,
9804 MinVersion: VersionTLS13,
9805 Bugs: ProtocolBugs{
9806 OmitRecordContents: true,
9807 RecordPadding: 10,
9808 },
9809 },
9810 shouldFail: true,
9811 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9812 })
9813
9814 testCases = append(testCases, testCase{
9815 name: "TLS13-WrongOuterRecord",
9816 config: Config{
9817 MaxVersion: VersionTLS13,
9818 MinVersion: VersionTLS13,
9819 Bugs: ProtocolBugs{
9820 OuterRecordType: recordTypeHandshake,
9821 },
9822 },
9823 shouldFail: true,
9824 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9825 })
9826}
9827
Steven Valdez5b986082016-09-01 12:29:49 -04009828func addSessionTicketTests() {
9829 testCases = append(testCases, testCase{
9830 // In TLS 1.2 and below, empty NewSessionTicket messages
9831 // mean the server changed its mind on sending a ticket.
9832 name: "SendEmptySessionTicket",
9833 config: Config{
9834 MaxVersion: VersionTLS12,
9835 Bugs: ProtocolBugs{
9836 SendEmptySessionTicket: true,
9837 },
9838 },
9839 flags: []string{"-expect-no-session"},
9840 })
9841
9842 // Test that the server ignores unknown PSK modes.
9843 testCases = append(testCases, testCase{
9844 testType: serverTest,
9845 name: "TLS13-SendUnknownModeSessionTicket-Server",
9846 config: Config{
9847 MaxVersion: VersionTLS13,
9848 Bugs: ProtocolBugs{
9849 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009850 },
9851 },
9852 resumeSession: true,
9853 expectedResumeVersion: VersionTLS13,
9854 })
9855
Steven Valdeza833c352016-11-01 13:39:36 -04009856 // Test that the server does not send session tickets with no matching key exchange mode.
9857 testCases = append(testCases, testCase{
9858 testType: serverTest,
9859 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9860 config: Config{
9861 MaxVersion: VersionTLS13,
9862 Bugs: ProtocolBugs{
9863 SendPSKKeyExchangeModes: []byte{0x1a},
9864 ExpectNoNewSessionTicket: true,
9865 },
9866 },
9867 })
9868
9869 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009870 testCases = append(testCases, testCase{
9871 testType: serverTest,
9872 name: "TLS13-SendBadKEModeSessionTicket-Server",
9873 config: Config{
9874 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009875 },
9876 resumeConfig: &Config{
9877 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009878 Bugs: ProtocolBugs{
9879 SendPSKKeyExchangeModes: []byte{0x1a},
9880 },
9881 },
9882 resumeSession: true,
9883 expectResumeRejected: true,
9884 })
9885
Steven Valdeza833c352016-11-01 13:39:36 -04009886 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009887 testCases = append(testCases, testCase{
9888 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009889 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009890 config: Config{
9891 MaxVersion: VersionTLS13,
9892 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009893 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009894 },
9895 },
Steven Valdeza833c352016-11-01 13:39:36 -04009896 resumeSession: true,
9897 flags: []string{
9898 "-resumption-delay", "10",
9899 },
Steven Valdez5b986082016-09-01 12:29:49 -04009900 })
9901
Steven Valdeza833c352016-11-01 13:39:36 -04009902 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009903 testCases = append(testCases, testCase{
9904 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009905 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009906 config: Config{
9907 MaxVersion: VersionTLS13,
9908 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009909 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009910 },
9911 },
Steven Valdeza833c352016-11-01 13:39:36 -04009912 resumeSession: true,
9913 shouldFail: true,
9914 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009915 })
9916
David Benjamin35ac5b72017-03-03 15:05:56 -05009917 // Test that the server's ticket age skew reporting works.
9918 testCases = append(testCases, testCase{
9919 testType: serverTest,
9920 name: "TLS13-TicketAgeSkew-Forward",
9921 config: Config{
9922 MaxVersion: VersionTLS13,
9923 Bugs: ProtocolBugs{
9924 SendTicketAge: 15 * time.Second,
9925 },
9926 },
David Benjamin065d7332017-03-26 10:51:43 -05009927 resumeSession: true,
9928 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009929 flags: []string{
9930 "-resumption-delay", "10",
9931 "-expect-ticket-age-skew", "5",
9932 },
9933 })
9934 testCases = append(testCases, testCase{
9935 testType: serverTest,
9936 name: "TLS13-TicketAgeSkew-Backward",
9937 config: Config{
9938 MaxVersion: VersionTLS13,
9939 Bugs: ProtocolBugs{
9940 SendTicketAge: 5 * time.Second,
9941 },
9942 },
David Benjamin065d7332017-03-26 10:51:43 -05009943 resumeSession: true,
9944 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009945 flags: []string{
9946 "-resumption-delay", "10",
9947 "-expect-ticket-age-skew", "-5",
9948 },
9949 })
9950
Steven Valdez08b65f42016-12-07 15:29:45 -05009951 testCases = append(testCases, testCase{
9952 testType: clientTest,
9953 name: "TLS13-SendTicketEarlyDataInfo",
9954 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009955 MaxVersion: VersionTLS13,
9956 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009957 },
9958 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009959 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009960 "-expect-early-data-info",
9961 },
9962 })
9963
David Benjamin9b160662017-01-25 19:53:43 -05009964 // Test that 0-RTT tickets are ignored in clients unless opted in.
9965 testCases = append(testCases, testCase{
9966 testType: clientTest,
9967 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9968 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009969 MaxVersion: VersionTLS13,
9970 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009971 },
9972 })
9973
Steven Valdez08b65f42016-12-07 15:29:45 -05009974 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009975 testType: clientTest,
9976 name: "TLS13-DuplicateTicketEarlyDataInfo",
9977 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009978 MaxVersion: VersionTLS13,
9979 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009980 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009981 DuplicateTicketEarlyDataInfo: true,
9982 },
9983 },
9984 shouldFail: true,
9985 expectedError: ":DUPLICATE_EXTENSION:",
9986 expectedLocalError: "remote error: illegal parameter",
9987 })
9988
9989 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009990 testType: serverTest,
9991 name: "TLS13-ExpectTicketEarlyDataInfo",
9992 config: Config{
9993 MaxVersion: VersionTLS13,
9994 Bugs: ProtocolBugs{
9995 ExpectTicketEarlyDataInfo: true,
9996 },
9997 },
9998 flags: []string{
9999 "-enable-early-data",
10000 },
10001 })
David Benjamin17b30832017-01-28 14:00:32 -050010002
10003 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
10004 // is honored.
10005 testCases = append(testCases, testCase{
10006 testType: clientTest,
10007 name: "TLS13-HonorServerSessionTicketLifetime",
10008 config: Config{
10009 MaxVersion: VersionTLS13,
10010 Bugs: ProtocolBugs{
10011 SendTicketLifetime: 20 * time.Second,
10012 },
10013 },
10014 flags: []string{
10015 "-resumption-delay", "19",
10016 },
10017 resumeSession: true,
10018 })
10019 testCases = append(testCases, testCase{
10020 testType: clientTest,
10021 name: "TLS13-HonorServerSessionTicketLifetime-2",
10022 config: Config{
10023 MaxVersion: VersionTLS13,
10024 Bugs: ProtocolBugs{
10025 SendTicketLifetime: 20 * time.Second,
10026 // The client should not offer the expired session.
10027 ExpectNoTLS13PSK: true,
10028 },
10029 },
10030 flags: []string{
10031 "-resumption-delay", "21",
10032 },
David Benjamin023d4192017-02-06 13:49:07 -050010033 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -050010034 expectResumeRejected: true,
10035 })
Steven Valdez5b986082016-09-01 12:29:49 -040010036}
10037
David Benjamin82261be2016-07-07 14:32:50 -070010038func addChangeCipherSpecTests() {
10039 // Test missing ChangeCipherSpecs.
10040 testCases = append(testCases, testCase{
10041 name: "SkipChangeCipherSpec-Client",
10042 config: Config{
10043 MaxVersion: VersionTLS12,
10044 Bugs: ProtocolBugs{
10045 SkipChangeCipherSpec: true,
10046 },
10047 },
10048 shouldFail: true,
10049 expectedError: ":UNEXPECTED_RECORD:",
10050 })
10051 testCases = append(testCases, testCase{
10052 testType: serverTest,
10053 name: "SkipChangeCipherSpec-Server",
10054 config: Config{
10055 MaxVersion: VersionTLS12,
10056 Bugs: ProtocolBugs{
10057 SkipChangeCipherSpec: true,
10058 },
10059 },
10060 shouldFail: true,
10061 expectedError: ":UNEXPECTED_RECORD:",
10062 })
10063 testCases = append(testCases, testCase{
10064 testType: serverTest,
10065 name: "SkipChangeCipherSpec-Server-NPN",
10066 config: Config{
10067 MaxVersion: VersionTLS12,
10068 NextProtos: []string{"bar"},
10069 Bugs: ProtocolBugs{
10070 SkipChangeCipherSpec: true,
10071 },
10072 },
10073 flags: []string{
10074 "-advertise-npn", "\x03foo\x03bar\x03baz",
10075 },
10076 shouldFail: true,
10077 expectedError: ":UNEXPECTED_RECORD:",
10078 })
10079
10080 // Test synchronization between the handshake and ChangeCipherSpec.
10081 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10082 // rejected. Test both with and without handshake packing to handle both
10083 // when the partial post-CCS message is in its own record and when it is
10084 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010085 for _, packed := range []bool{false, true} {
10086 var suffix string
10087 if packed {
10088 suffix = "-Packed"
10089 }
10090
10091 testCases = append(testCases, testCase{
10092 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10093 config: Config{
10094 MaxVersion: VersionTLS12,
10095 Bugs: ProtocolBugs{
10096 FragmentAcrossChangeCipherSpec: true,
10097 PackHandshakeFlight: packed,
10098 },
10099 },
10100 shouldFail: true,
10101 expectedError: ":UNEXPECTED_RECORD:",
10102 })
10103 testCases = append(testCases, testCase{
10104 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10105 config: Config{
10106 MaxVersion: VersionTLS12,
10107 },
10108 resumeSession: true,
10109 resumeConfig: &Config{
10110 MaxVersion: VersionTLS12,
10111 Bugs: ProtocolBugs{
10112 FragmentAcrossChangeCipherSpec: true,
10113 PackHandshakeFlight: packed,
10114 },
10115 },
10116 shouldFail: true,
10117 expectedError: ":UNEXPECTED_RECORD:",
10118 })
10119 testCases = append(testCases, testCase{
10120 testType: serverTest,
10121 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10122 config: Config{
10123 MaxVersion: VersionTLS12,
10124 Bugs: ProtocolBugs{
10125 FragmentAcrossChangeCipherSpec: true,
10126 PackHandshakeFlight: packed,
10127 },
10128 },
10129 shouldFail: true,
10130 expectedError: ":UNEXPECTED_RECORD:",
10131 })
10132 testCases = append(testCases, testCase{
10133 testType: serverTest,
10134 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10135 config: Config{
10136 MaxVersion: VersionTLS12,
10137 },
10138 resumeSession: true,
10139 resumeConfig: &Config{
10140 MaxVersion: VersionTLS12,
10141 Bugs: ProtocolBugs{
10142 FragmentAcrossChangeCipherSpec: true,
10143 PackHandshakeFlight: packed,
10144 },
10145 },
10146 shouldFail: true,
10147 expectedError: ":UNEXPECTED_RECORD:",
10148 })
10149 testCases = append(testCases, testCase{
10150 testType: serverTest,
10151 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10152 config: Config{
10153 MaxVersion: VersionTLS12,
10154 NextProtos: []string{"bar"},
10155 Bugs: ProtocolBugs{
10156 FragmentAcrossChangeCipherSpec: true,
10157 PackHandshakeFlight: packed,
10158 },
10159 },
10160 flags: []string{
10161 "-advertise-npn", "\x03foo\x03bar\x03baz",
10162 },
10163 shouldFail: true,
10164 expectedError: ":UNEXPECTED_RECORD:",
10165 })
10166 }
10167
David Benjamin61672812016-07-14 23:10:43 -040010168 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10169 // messages in the handshake queue. Do this by testing the server
10170 // reading the client Finished, reversing the flight so Finished comes
10171 // first.
10172 testCases = append(testCases, testCase{
10173 protocol: dtls,
10174 testType: serverTest,
10175 name: "SendUnencryptedFinished-DTLS",
10176 config: Config{
10177 MaxVersion: VersionTLS12,
10178 Bugs: ProtocolBugs{
10179 SendUnencryptedFinished: true,
10180 ReverseHandshakeFragments: true,
10181 },
10182 },
10183 shouldFail: true,
10184 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10185 })
10186
Steven Valdez143e8b32016-07-11 13:19:03 -040010187 // Test synchronization between encryption changes and the handshake in
10188 // TLS 1.3, where ChangeCipherSpec is implicit.
10189 testCases = append(testCases, testCase{
10190 name: "PartialEncryptedExtensionsWithServerHello",
10191 config: Config{
10192 MaxVersion: VersionTLS13,
10193 Bugs: ProtocolBugs{
10194 PartialEncryptedExtensionsWithServerHello: true,
10195 },
10196 },
10197 shouldFail: true,
10198 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10199 })
10200 testCases = append(testCases, testCase{
10201 testType: serverTest,
10202 name: "PartialClientFinishedWithClientHello",
10203 config: Config{
10204 MaxVersion: VersionTLS13,
10205 Bugs: ProtocolBugs{
10206 PartialClientFinishedWithClientHello: true,
10207 },
10208 },
10209 shouldFail: true,
10210 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10211 })
10212
David Benjamin82261be2016-07-07 14:32:50 -070010213 // Test that early ChangeCipherSpecs are handled correctly.
10214 testCases = append(testCases, testCase{
10215 testType: serverTest,
10216 name: "EarlyChangeCipherSpec-server-1",
10217 config: Config{
10218 MaxVersion: VersionTLS12,
10219 Bugs: ProtocolBugs{
10220 EarlyChangeCipherSpec: 1,
10221 },
10222 },
10223 shouldFail: true,
10224 expectedError: ":UNEXPECTED_RECORD:",
10225 })
10226 testCases = append(testCases, testCase{
10227 testType: serverTest,
10228 name: "EarlyChangeCipherSpec-server-2",
10229 config: Config{
10230 MaxVersion: VersionTLS12,
10231 Bugs: ProtocolBugs{
10232 EarlyChangeCipherSpec: 2,
10233 },
10234 },
10235 shouldFail: true,
10236 expectedError: ":UNEXPECTED_RECORD:",
10237 })
10238 testCases = append(testCases, testCase{
10239 protocol: dtls,
10240 name: "StrayChangeCipherSpec",
10241 config: Config{
10242 // TODO(davidben): Once DTLS 1.3 exists, test
10243 // that stray ChangeCipherSpec messages are
10244 // rejected.
10245 MaxVersion: VersionTLS12,
10246 Bugs: ProtocolBugs{
10247 StrayChangeCipherSpec: true,
10248 },
10249 },
10250 })
10251
David Benjaminb0c761e2017-06-25 22:42:55 -040010252 // Test that reordered ChangeCipherSpecs are tolerated.
10253 testCases = append(testCases, testCase{
10254 protocol: dtls,
10255 name: "ReorderChangeCipherSpec-DTLS-Client",
10256 config: Config{
10257 MaxVersion: VersionTLS12,
10258 Bugs: ProtocolBugs{
10259 ReorderChangeCipherSpec: true,
10260 },
10261 },
10262 resumeSession: true,
10263 })
10264 testCases = append(testCases, testCase{
10265 testType: serverTest,
10266 protocol: dtls,
10267 name: "ReorderChangeCipherSpec-DTLS-Server",
10268 config: Config{
10269 MaxVersion: VersionTLS12,
10270 Bugs: ProtocolBugs{
10271 ReorderChangeCipherSpec: true,
10272 },
10273 },
10274 resumeSession: true,
10275 })
10276
David Benjamin82261be2016-07-07 14:32:50 -070010277 // Test that the contents of ChangeCipherSpec are checked.
10278 testCases = append(testCases, testCase{
10279 name: "BadChangeCipherSpec-1",
10280 config: Config{
10281 MaxVersion: VersionTLS12,
10282 Bugs: ProtocolBugs{
10283 BadChangeCipherSpec: []byte{2},
10284 },
10285 },
10286 shouldFail: true,
10287 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10288 })
10289 testCases = append(testCases, testCase{
10290 name: "BadChangeCipherSpec-2",
10291 config: Config{
10292 MaxVersion: VersionTLS12,
10293 Bugs: ProtocolBugs{
10294 BadChangeCipherSpec: []byte{1, 1},
10295 },
10296 },
10297 shouldFail: true,
10298 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10299 })
10300 testCases = append(testCases, testCase{
10301 protocol: dtls,
10302 name: "BadChangeCipherSpec-DTLS-1",
10303 config: Config{
10304 MaxVersion: VersionTLS12,
10305 Bugs: ProtocolBugs{
10306 BadChangeCipherSpec: []byte{2},
10307 },
10308 },
10309 shouldFail: true,
10310 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10311 })
10312 testCases = append(testCases, testCase{
10313 protocol: dtls,
10314 name: "BadChangeCipherSpec-DTLS-2",
10315 config: Config{
10316 MaxVersion: VersionTLS12,
10317 Bugs: ProtocolBugs{
10318 BadChangeCipherSpec: []byte{1, 1},
10319 },
10320 },
10321 shouldFail: true,
10322 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10323 })
10324}
10325
David Benjamincd2c8062016-09-09 11:28:16 -040010326type perMessageTest struct {
10327 messageType uint8
10328 test testCase
10329}
10330
10331// makePerMessageTests returns a series of test templates which cover each
10332// message in the TLS handshake. These may be used with bugs like
10333// WrongMessageType to fully test a per-message bug.
10334func makePerMessageTests() []perMessageTest {
10335 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010336 for _, protocol := range []protocol{tls, dtls} {
10337 var suffix string
10338 if protocol == dtls {
10339 suffix = "-DTLS"
10340 }
10341
David Benjamincd2c8062016-09-09 11:28:16 -040010342 ret = append(ret, perMessageTest{
10343 messageType: typeClientHello,
10344 test: testCase{
10345 protocol: protocol,
10346 testType: serverTest,
10347 name: "ClientHello" + suffix,
10348 config: Config{
10349 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010350 },
10351 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010352 })
10353
10354 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010355 ret = append(ret, perMessageTest{
10356 messageType: typeHelloVerifyRequest,
10357 test: testCase{
10358 protocol: protocol,
10359 name: "HelloVerifyRequest" + suffix,
10360 config: Config{
10361 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010362 },
10363 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010364 })
10365 }
10366
David Benjamincd2c8062016-09-09 11:28:16 -040010367 ret = append(ret, perMessageTest{
10368 messageType: typeServerHello,
10369 test: testCase{
10370 protocol: protocol,
10371 name: "ServerHello" + suffix,
10372 config: Config{
10373 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010374 },
10375 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010376 })
10377
David Benjamincd2c8062016-09-09 11:28:16 -040010378 ret = append(ret, perMessageTest{
10379 messageType: typeCertificate,
10380 test: testCase{
10381 protocol: protocol,
10382 name: "ServerCertificate" + suffix,
10383 config: Config{
10384 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010385 },
10386 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010387 })
10388
David Benjamincd2c8062016-09-09 11:28:16 -040010389 ret = append(ret, perMessageTest{
10390 messageType: typeCertificateStatus,
10391 test: testCase{
10392 protocol: protocol,
10393 name: "CertificateStatus" + suffix,
10394 config: Config{
10395 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010396 },
David Benjamincd2c8062016-09-09 11:28:16 -040010397 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010398 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010399 })
10400
David Benjamincd2c8062016-09-09 11:28:16 -040010401 ret = append(ret, perMessageTest{
10402 messageType: typeServerKeyExchange,
10403 test: testCase{
10404 protocol: protocol,
10405 name: "ServerKeyExchange" + suffix,
10406 config: Config{
10407 MaxVersion: VersionTLS12,
10408 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010409 },
10410 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010411 })
10412
David Benjamincd2c8062016-09-09 11:28:16 -040010413 ret = append(ret, perMessageTest{
10414 messageType: typeCertificateRequest,
10415 test: testCase{
10416 protocol: protocol,
10417 name: "CertificateRequest" + suffix,
10418 config: Config{
10419 MaxVersion: VersionTLS12,
10420 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010421 },
10422 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010423 })
10424
David Benjamincd2c8062016-09-09 11:28:16 -040010425 ret = append(ret, perMessageTest{
10426 messageType: typeServerHelloDone,
10427 test: testCase{
10428 protocol: protocol,
10429 name: "ServerHelloDone" + suffix,
10430 config: Config{
10431 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010432 },
10433 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010434 })
10435
David Benjamincd2c8062016-09-09 11:28:16 -040010436 ret = append(ret, perMessageTest{
10437 messageType: typeCertificate,
10438 test: testCase{
10439 testType: serverTest,
10440 protocol: protocol,
10441 name: "ClientCertificate" + suffix,
10442 config: Config{
10443 Certificates: []Certificate{rsaCertificate},
10444 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010445 },
David Benjamincd2c8062016-09-09 11:28:16 -040010446 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010447 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010448 })
10449
David Benjamincd2c8062016-09-09 11:28:16 -040010450 ret = append(ret, perMessageTest{
10451 messageType: typeCertificateVerify,
10452 test: testCase{
10453 testType: serverTest,
10454 protocol: protocol,
10455 name: "CertificateVerify" + suffix,
10456 config: Config{
10457 Certificates: []Certificate{rsaCertificate},
10458 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010459 },
David Benjamincd2c8062016-09-09 11:28:16 -040010460 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010461 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010462 })
10463
David Benjamincd2c8062016-09-09 11:28:16 -040010464 ret = append(ret, perMessageTest{
10465 messageType: typeClientKeyExchange,
10466 test: testCase{
10467 testType: serverTest,
10468 protocol: protocol,
10469 name: "ClientKeyExchange" + suffix,
10470 config: Config{
10471 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010472 },
10473 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010474 })
10475
10476 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010477 ret = append(ret, perMessageTest{
10478 messageType: typeNextProtocol,
10479 test: testCase{
10480 testType: serverTest,
10481 protocol: protocol,
10482 name: "NextProtocol" + suffix,
10483 config: Config{
10484 MaxVersion: VersionTLS12,
10485 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010486 },
David Benjamincd2c8062016-09-09 11:28:16 -040010487 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010488 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010489 })
10490
David Benjamincd2c8062016-09-09 11:28:16 -040010491 ret = append(ret, perMessageTest{
10492 messageType: typeChannelID,
10493 test: testCase{
10494 testType: serverTest,
10495 protocol: protocol,
10496 name: "ChannelID" + suffix,
10497 config: Config{
10498 MaxVersion: VersionTLS12,
10499 ChannelID: channelIDKey,
10500 },
10501 flags: []string{
10502 "-expect-channel-id",
10503 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010504 },
10505 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010506 })
10507 }
10508
David Benjamincd2c8062016-09-09 11:28:16 -040010509 ret = append(ret, perMessageTest{
10510 messageType: typeFinished,
10511 test: testCase{
10512 testType: serverTest,
10513 protocol: protocol,
10514 name: "ClientFinished" + suffix,
10515 config: Config{
10516 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010517 },
10518 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010519 })
10520
David Benjamincd2c8062016-09-09 11:28:16 -040010521 ret = append(ret, perMessageTest{
10522 messageType: typeNewSessionTicket,
10523 test: testCase{
10524 protocol: protocol,
10525 name: "NewSessionTicket" + suffix,
10526 config: Config{
10527 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010528 },
10529 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010530 })
10531
David Benjamincd2c8062016-09-09 11:28:16 -040010532 ret = append(ret, perMessageTest{
10533 messageType: typeFinished,
10534 test: testCase{
10535 protocol: protocol,
10536 name: "ServerFinished" + suffix,
10537 config: Config{
10538 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010539 },
10540 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010541 })
10542
10543 }
David Benjamincd2c8062016-09-09 11:28:16 -040010544
10545 ret = append(ret, perMessageTest{
10546 messageType: typeClientHello,
10547 test: testCase{
10548 testType: serverTest,
10549 name: "TLS13-ClientHello",
10550 config: Config{
10551 MaxVersion: VersionTLS13,
10552 },
10553 },
10554 })
10555
10556 ret = append(ret, perMessageTest{
10557 messageType: typeServerHello,
10558 test: testCase{
10559 name: "TLS13-ServerHello",
10560 config: Config{
10561 MaxVersion: VersionTLS13,
10562 },
10563 },
10564 })
10565
10566 ret = append(ret, perMessageTest{
10567 messageType: typeEncryptedExtensions,
10568 test: testCase{
10569 name: "TLS13-EncryptedExtensions",
10570 config: Config{
10571 MaxVersion: VersionTLS13,
10572 },
10573 },
10574 })
10575
10576 ret = append(ret, perMessageTest{
10577 messageType: typeCertificateRequest,
10578 test: testCase{
10579 name: "TLS13-CertificateRequest",
10580 config: Config{
10581 MaxVersion: VersionTLS13,
10582 ClientAuth: RequireAnyClientCert,
10583 },
10584 },
10585 })
10586
10587 ret = append(ret, perMessageTest{
10588 messageType: typeCertificate,
10589 test: testCase{
10590 name: "TLS13-ServerCertificate",
10591 config: Config{
10592 MaxVersion: VersionTLS13,
10593 },
10594 },
10595 })
10596
10597 ret = append(ret, perMessageTest{
10598 messageType: typeCertificateVerify,
10599 test: testCase{
10600 name: "TLS13-ServerCertificateVerify",
10601 config: Config{
10602 MaxVersion: VersionTLS13,
10603 },
10604 },
10605 })
10606
10607 ret = append(ret, perMessageTest{
10608 messageType: typeFinished,
10609 test: testCase{
10610 name: "TLS13-ServerFinished",
10611 config: Config{
10612 MaxVersion: VersionTLS13,
10613 },
10614 },
10615 })
10616
10617 ret = append(ret, perMessageTest{
10618 messageType: typeCertificate,
10619 test: testCase{
10620 testType: serverTest,
10621 name: "TLS13-ClientCertificate",
10622 config: Config{
10623 Certificates: []Certificate{rsaCertificate},
10624 MaxVersion: VersionTLS13,
10625 },
10626 flags: []string{"-require-any-client-certificate"},
10627 },
10628 })
10629
10630 ret = append(ret, perMessageTest{
10631 messageType: typeCertificateVerify,
10632 test: testCase{
10633 testType: serverTest,
10634 name: "TLS13-ClientCertificateVerify",
10635 config: Config{
10636 Certificates: []Certificate{rsaCertificate},
10637 MaxVersion: VersionTLS13,
10638 },
10639 flags: []string{"-require-any-client-certificate"},
10640 },
10641 })
10642
10643 ret = append(ret, perMessageTest{
10644 messageType: typeFinished,
10645 test: testCase{
10646 testType: serverTest,
10647 name: "TLS13-ClientFinished",
10648 config: Config{
10649 MaxVersion: VersionTLS13,
10650 },
10651 },
10652 })
10653
10654 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010655}
10656
David Benjamincd2c8062016-09-09 11:28:16 -040010657func addWrongMessageTypeTests() {
10658 for _, t := range makePerMessageTests() {
10659 t.test.name = "WrongMessageType-" + t.test.name
10660 t.test.config.Bugs.SendWrongMessageType = t.messageType
10661 t.test.shouldFail = true
10662 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10663 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010664
David Benjamincd2c8062016-09-09 11:28:16 -040010665 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10666 // In TLS 1.3, a bad ServerHello means the client sends
10667 // an unencrypted alert while the server expects
10668 // encryption, so the alert is not readable by runner.
10669 t.test.expectedLocalError = "local error: bad record MAC"
10670 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010671
David Benjamincd2c8062016-09-09 11:28:16 -040010672 testCases = append(testCases, t.test)
10673 }
David Benjaminebacdee2017-04-08 11:00:45 -040010674
10675 // The processing order for TLS 1.3 version negotiation is such that one
10676 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10677 // TLS 1.2. Test that we do not do this.
10678 testCases = append(testCases, testCase{
10679 name: "SendServerHelloAsHelloRetryRequest",
10680 config: Config{
10681 MaxVersion: VersionTLS12,
10682 Bugs: ProtocolBugs{
10683 SendServerHelloAsHelloRetryRequest: true,
10684 },
10685 },
10686 shouldFail: true,
10687 expectedError: ":UNEXPECTED_MESSAGE:",
10688 expectedLocalError: "remote error: unexpected message",
10689 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010690}
10691
David Benjamin639846e2016-09-09 11:41:18 -040010692func addTrailingMessageDataTests() {
10693 for _, t := range makePerMessageTests() {
10694 t.test.name = "TrailingMessageData-" + t.test.name
10695 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10696 t.test.shouldFail = true
10697 t.test.expectedError = ":DECODE_ERROR:"
10698 t.test.expectedLocalError = "remote error: error decoding message"
10699
10700 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10701 // In TLS 1.3, a bad ServerHello means the client sends
10702 // an unencrypted alert while the server expects
10703 // encryption, so the alert is not readable by runner.
10704 t.test.expectedLocalError = "local error: bad record MAC"
10705 }
10706
10707 if t.messageType == typeFinished {
10708 // Bad Finished messages read as the verify data having
10709 // the wrong length.
10710 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10711 t.test.expectedLocalError = "remote error: error decrypting message"
10712 }
10713
10714 testCases = append(testCases, t.test)
10715 }
10716}
10717
Steven Valdez143e8b32016-07-11 13:19:03 -040010718func addTLS13HandshakeTests() {
10719 testCases = append(testCases, testCase{
10720 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010721 name: "NegotiatePSKResumption-TLS13",
10722 config: Config{
10723 MaxVersion: VersionTLS13,
10724 Bugs: ProtocolBugs{
10725 NegotiatePSKResumption: true,
10726 },
10727 },
10728 resumeSession: true,
10729 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010730 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010731 })
10732
10733 testCases = append(testCases, testCase{
10734 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010735 name: "MissingKeyShare-Client",
10736 config: Config{
10737 MaxVersion: VersionTLS13,
10738 Bugs: ProtocolBugs{
10739 MissingKeyShare: true,
10740 },
10741 },
10742 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010743 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010744 })
10745
10746 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010747 testType: serverTest,
10748 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010749 config: Config{
10750 MaxVersion: VersionTLS13,
10751 Bugs: ProtocolBugs{
10752 MissingKeyShare: true,
10753 },
10754 },
10755 shouldFail: true,
10756 expectedError: ":MISSING_KEY_SHARE:",
10757 })
10758
10759 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010760 testType: serverTest,
10761 name: "DuplicateKeyShares",
10762 config: Config{
10763 MaxVersion: VersionTLS13,
10764 Bugs: ProtocolBugs{
10765 DuplicateKeyShares: true,
10766 },
10767 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010768 shouldFail: true,
10769 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010770 })
10771
10772 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010773 testType: serverTest,
10774 name: "SkipEarlyData",
10775 config: Config{
10776 MaxVersion: VersionTLS13,
10777 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010778 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010779 },
10780 },
10781 })
10782
10783 testCases = append(testCases, testCase{
10784 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010785 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010786 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010787 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010788 Bugs: ProtocolBugs{
10789 SendFakeEarlyDataLength: 4,
10790 },
10791 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010792 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010793 })
10794
10795 testCases = append(testCases, testCase{
10796 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010797 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10798 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010799 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010800 Bugs: ProtocolBugs{
10801 SendFakeEarlyDataLength: 4,
10802 },
10803 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010804 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010805 })
10806
10807 testCases = append(testCases, testCase{
10808 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010809 name: "SkipEarlyData-OmitEarlyDataExtension",
10810 config: Config{
10811 MaxVersion: VersionTLS13,
10812 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010813 SendFakeEarlyDataLength: 4,
10814 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010815 },
10816 },
10817 shouldFail: true,
10818 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10819 })
10820
10821 testCases = append(testCases, testCase{
10822 testType: serverTest,
10823 name: "SkipEarlyData-TooMuchData",
10824 config: Config{
10825 MaxVersion: VersionTLS13,
10826 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010827 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010828 },
10829 },
10830 shouldFail: true,
10831 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10832 })
10833
10834 testCases = append(testCases, testCase{
10835 testType: serverTest,
10836 name: "SkipEarlyData-Interleaved",
10837 config: Config{
10838 MaxVersion: VersionTLS13,
10839 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010840 SendFakeEarlyDataLength: 4,
10841 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010842 },
10843 },
10844 shouldFail: true,
10845 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10846 })
10847
10848 testCases = append(testCases, testCase{
10849 testType: serverTest,
10850 name: "SkipEarlyData-EarlyDataInTLS12",
10851 config: Config{
10852 MaxVersion: VersionTLS13,
10853 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010854 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010855 },
10856 },
10857 shouldFail: true,
10858 expectedError: ":UNEXPECTED_RECORD:",
10859 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10860 })
10861
10862 testCases = append(testCases, testCase{
10863 testType: serverTest,
10864 name: "SkipEarlyData-HRR",
10865 config: Config{
10866 MaxVersion: VersionTLS13,
10867 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010868 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010869 },
10870 DefaultCurves: []CurveID{},
10871 },
10872 })
10873
10874 testCases = append(testCases, testCase{
10875 testType: serverTest,
10876 name: "SkipEarlyData-HRR-Interleaved",
10877 config: Config{
10878 MaxVersion: VersionTLS13,
10879 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010880 SendFakeEarlyDataLength: 4,
10881 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010882 },
10883 DefaultCurves: []CurveID{},
10884 },
10885 shouldFail: true,
10886 expectedError: ":UNEXPECTED_RECORD:",
10887 })
10888
10889 testCases = append(testCases, testCase{
10890 testType: serverTest,
10891 name: "SkipEarlyData-HRR-TooMuchData",
10892 config: Config{
10893 MaxVersion: VersionTLS13,
10894 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010895 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010896 },
10897 DefaultCurves: []CurveID{},
10898 },
10899 shouldFail: true,
10900 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10901 })
10902
10903 // Test that skipping early data looking for cleartext correctly
10904 // processes an alert record.
10905 testCases = append(testCases, testCase{
10906 testType: serverTest,
10907 name: "SkipEarlyData-HRR-FatalAlert",
10908 config: Config{
10909 MaxVersion: VersionTLS13,
10910 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010911 SendEarlyAlert: true,
10912 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010913 },
10914 DefaultCurves: []CurveID{},
10915 },
10916 shouldFail: true,
10917 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10918 })
10919
10920 testCases = append(testCases, testCase{
10921 testType: serverTest,
10922 name: "SkipEarlyData-SecondClientHelloEarlyData",
10923 config: Config{
10924 MaxVersion: VersionTLS13,
10925 Bugs: ProtocolBugs{
10926 SendEarlyDataOnSecondClientHello: true,
10927 },
10928 DefaultCurves: []CurveID{},
10929 },
10930 shouldFail: true,
10931 expectedLocalError: "remote error: bad record MAC",
10932 })
10933
10934 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010935 testType: clientTest,
10936 name: "EmptyEncryptedExtensions",
10937 config: Config{
10938 MaxVersion: VersionTLS13,
10939 Bugs: ProtocolBugs{
10940 EmptyEncryptedExtensions: true,
10941 },
10942 },
10943 shouldFail: true,
10944 expectedLocalError: "remote error: error decoding message",
10945 })
10946
10947 testCases = append(testCases, testCase{
10948 testType: clientTest,
10949 name: "EncryptedExtensionsWithKeyShare",
10950 config: Config{
10951 MaxVersion: VersionTLS13,
10952 Bugs: ProtocolBugs{
10953 EncryptedExtensionsWithKeyShare: true,
10954 },
10955 },
10956 shouldFail: true,
10957 expectedLocalError: "remote error: unsupported extension",
10958 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010959
10960 testCases = append(testCases, testCase{
10961 testType: serverTest,
10962 name: "SendHelloRetryRequest",
10963 config: Config{
10964 MaxVersion: VersionTLS13,
10965 // Require a HelloRetryRequest for every curve.
10966 DefaultCurves: []CurveID{},
10967 },
10968 expectedCurveID: CurveX25519,
10969 })
10970
10971 testCases = append(testCases, testCase{
10972 testType: serverTest,
10973 name: "SendHelloRetryRequest-2",
10974 config: Config{
10975 MaxVersion: VersionTLS13,
10976 DefaultCurves: []CurveID{CurveP384},
10977 },
10978 // Although the ClientHello did not predict our preferred curve,
10979 // we always select it whether it is predicted or not.
10980 expectedCurveID: CurveX25519,
10981 })
10982
10983 testCases = append(testCases, testCase{
10984 name: "UnknownCurve-HelloRetryRequest",
10985 config: Config{
10986 MaxVersion: VersionTLS13,
10987 // P-384 requires HelloRetryRequest in BoringSSL.
10988 CurvePreferences: []CurveID{CurveP384},
10989 Bugs: ProtocolBugs{
10990 SendHelloRetryRequestCurve: bogusCurve,
10991 },
10992 },
10993 shouldFail: true,
10994 expectedError: ":WRONG_CURVE:",
10995 })
10996
10997 testCases = append(testCases, testCase{
10998 name: "DisabledCurve-HelloRetryRequest",
10999 config: Config{
11000 MaxVersion: VersionTLS13,
11001 CurvePreferences: []CurveID{CurveP256},
11002 Bugs: ProtocolBugs{
11003 IgnorePeerCurvePreferences: true,
11004 },
11005 },
11006 flags: []string{"-p384-only"},
11007 shouldFail: true,
11008 expectedError: ":WRONG_CURVE:",
11009 })
11010
11011 testCases = append(testCases, testCase{
11012 name: "UnnecessaryHelloRetryRequest",
11013 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011014 MaxVersion: VersionTLS13,
11015 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011016 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011017 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011018 },
11019 },
11020 shouldFail: true,
11021 expectedError: ":WRONG_CURVE:",
11022 })
11023
11024 testCases = append(testCases, testCase{
11025 name: "SecondHelloRetryRequest",
11026 config: Config{
11027 MaxVersion: VersionTLS13,
11028 // P-384 requires HelloRetryRequest in BoringSSL.
11029 CurvePreferences: []CurveID{CurveP384},
11030 Bugs: ProtocolBugs{
11031 SecondHelloRetryRequest: true,
11032 },
11033 },
11034 shouldFail: true,
11035 expectedError: ":UNEXPECTED_MESSAGE:",
11036 })
11037
11038 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011039 name: "HelloRetryRequest-Empty",
11040 config: Config{
11041 MaxVersion: VersionTLS13,
11042 Bugs: ProtocolBugs{
11043 AlwaysSendHelloRetryRequest: true,
11044 },
11045 },
11046 shouldFail: true,
11047 expectedError: ":DECODE_ERROR:",
11048 })
11049
11050 testCases = append(testCases, testCase{
11051 name: "HelloRetryRequest-DuplicateCurve",
11052 config: Config{
11053 MaxVersion: VersionTLS13,
11054 // P-384 requires a HelloRetryRequest against BoringSSL's default
11055 // configuration. Assert this ExpectMissingKeyShare.
11056 CurvePreferences: []CurveID{CurveP384},
11057 Bugs: ProtocolBugs{
11058 ExpectMissingKeyShare: true,
11059 DuplicateHelloRetryRequestExtensions: true,
11060 },
11061 },
11062 shouldFail: true,
11063 expectedError: ":DUPLICATE_EXTENSION:",
11064 expectedLocalError: "remote error: illegal parameter",
11065 })
11066
11067 testCases = append(testCases, testCase{
11068 name: "HelloRetryRequest-Cookie",
11069 config: Config{
11070 MaxVersion: VersionTLS13,
11071 Bugs: ProtocolBugs{
11072 SendHelloRetryRequestCookie: []byte("cookie"),
11073 },
11074 },
11075 })
11076
11077 testCases = append(testCases, testCase{
11078 name: "HelloRetryRequest-DuplicateCookie",
11079 config: Config{
11080 MaxVersion: VersionTLS13,
11081 Bugs: ProtocolBugs{
11082 SendHelloRetryRequestCookie: []byte("cookie"),
11083 DuplicateHelloRetryRequestExtensions: true,
11084 },
11085 },
11086 shouldFail: true,
11087 expectedError: ":DUPLICATE_EXTENSION:",
11088 expectedLocalError: "remote error: illegal parameter",
11089 })
11090
11091 testCases = append(testCases, testCase{
11092 name: "HelloRetryRequest-EmptyCookie",
11093 config: Config{
11094 MaxVersion: VersionTLS13,
11095 Bugs: ProtocolBugs{
11096 SendHelloRetryRequestCookie: []byte{},
11097 },
11098 },
11099 shouldFail: true,
11100 expectedError: ":DECODE_ERROR:",
11101 })
11102
11103 testCases = append(testCases, testCase{
11104 name: "HelloRetryRequest-Cookie-Curve",
11105 config: Config{
11106 MaxVersion: VersionTLS13,
11107 // P-384 requires HelloRetryRequest in BoringSSL.
11108 CurvePreferences: []CurveID{CurveP384},
11109 Bugs: ProtocolBugs{
11110 SendHelloRetryRequestCookie: []byte("cookie"),
11111 ExpectMissingKeyShare: true,
11112 },
11113 },
11114 })
11115
11116 testCases = append(testCases, testCase{
11117 name: "HelloRetryRequest-Unknown",
11118 config: Config{
11119 MaxVersion: VersionTLS13,
11120 Bugs: ProtocolBugs{
11121 CustomHelloRetryRequestExtension: "extension",
11122 },
11123 },
11124 shouldFail: true,
11125 expectedError: ":UNEXPECTED_EXTENSION:",
11126 expectedLocalError: "remote error: unsupported extension",
11127 })
11128
11129 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011130 testType: serverTest,
11131 name: "SecondClientHelloMissingKeyShare",
11132 config: Config{
11133 MaxVersion: VersionTLS13,
11134 DefaultCurves: []CurveID{},
11135 Bugs: ProtocolBugs{
11136 SecondClientHelloMissingKeyShare: true,
11137 },
11138 },
11139 shouldFail: true,
11140 expectedError: ":MISSING_KEY_SHARE:",
11141 })
11142
11143 testCases = append(testCases, testCase{
11144 testType: serverTest,
11145 name: "SecondClientHelloWrongCurve",
11146 config: Config{
11147 MaxVersion: VersionTLS13,
11148 DefaultCurves: []CurveID{},
11149 Bugs: ProtocolBugs{
11150 MisinterpretHelloRetryRequestCurve: CurveP521,
11151 },
11152 },
11153 shouldFail: true,
11154 expectedError: ":WRONG_CURVE:",
11155 })
11156
11157 testCases = append(testCases, testCase{
11158 name: "HelloRetryRequestVersionMismatch",
11159 config: Config{
11160 MaxVersion: VersionTLS13,
11161 // P-384 requires HelloRetryRequest in BoringSSL.
11162 CurvePreferences: []CurveID{CurveP384},
11163 Bugs: ProtocolBugs{
11164 SendServerHelloVersion: 0x0305,
11165 },
11166 },
11167 shouldFail: true,
11168 expectedError: ":WRONG_VERSION_NUMBER:",
11169 })
11170
11171 testCases = append(testCases, testCase{
11172 name: "HelloRetryRequestCurveMismatch",
11173 config: Config{
11174 MaxVersion: VersionTLS13,
11175 // P-384 requires HelloRetryRequest in BoringSSL.
11176 CurvePreferences: []CurveID{CurveP384},
11177 Bugs: ProtocolBugs{
11178 // Send P-384 (correct) in the HelloRetryRequest.
11179 SendHelloRetryRequestCurve: CurveP384,
11180 // But send P-256 in the ServerHello.
11181 SendCurve: CurveP256,
11182 },
11183 },
11184 shouldFail: true,
11185 expectedError: ":WRONG_CURVE:",
11186 })
11187
11188 // Test the server selecting a curve that requires a HelloRetryRequest
11189 // without sending it.
11190 testCases = append(testCases, testCase{
11191 name: "SkipHelloRetryRequest",
11192 config: Config{
11193 MaxVersion: VersionTLS13,
11194 // P-384 requires HelloRetryRequest in BoringSSL.
11195 CurvePreferences: []CurveID{CurveP384},
11196 Bugs: ProtocolBugs{
11197 SkipHelloRetryRequest: true,
11198 },
11199 },
11200 shouldFail: true,
11201 expectedError: ":WRONG_CURVE:",
11202 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011203
11204 testCases = append(testCases, testCase{
11205 name: "TLS13-RequestContextInHandshake",
11206 config: Config{
11207 MaxVersion: VersionTLS13,
11208 MinVersion: VersionTLS13,
11209 ClientAuth: RequireAnyClientCert,
11210 Bugs: ProtocolBugs{
11211 SendRequestContext: []byte("request context"),
11212 },
11213 },
11214 flags: []string{
11215 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11216 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11217 },
11218 shouldFail: true,
11219 expectedError: ":DECODE_ERROR:",
11220 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011221
11222 testCases = append(testCases, testCase{
11223 testType: serverTest,
11224 name: "TLS13-TrailingKeyShareData",
11225 config: Config{
11226 MaxVersion: VersionTLS13,
11227 Bugs: ProtocolBugs{
11228 TrailingKeyShareData: true,
11229 },
11230 },
11231 shouldFail: true,
11232 expectedError: ":DECODE_ERROR:",
11233 })
David Benjamin7f78df42016-10-05 22:33:19 -040011234
11235 testCases = append(testCases, testCase{
11236 name: "TLS13-AlwaysSelectPSKIdentity",
11237 config: Config{
11238 MaxVersion: VersionTLS13,
11239 Bugs: ProtocolBugs{
11240 AlwaysSelectPSKIdentity: true,
11241 },
11242 },
11243 shouldFail: true,
11244 expectedError: ":UNEXPECTED_EXTENSION:",
11245 })
11246
11247 testCases = append(testCases, testCase{
11248 name: "TLS13-InvalidPSKIdentity",
11249 config: Config{
11250 MaxVersion: VersionTLS13,
11251 Bugs: ProtocolBugs{
11252 SelectPSKIdentityOnResume: 1,
11253 },
11254 },
11255 resumeSession: true,
11256 shouldFail: true,
11257 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11258 })
David Benjamin1286bee2016-10-07 15:25:06 -040011259
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011260 testCases = append(testCases, testCase{
11261 testType: serverTest,
11262 name: "TLS13-ExtraPSKIdentity",
11263 config: Config{
11264 MaxVersion: VersionTLS13,
11265 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011266 ExtraPSKIdentity: true,
11267 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011268 },
11269 },
11270 resumeSession: true,
11271 })
11272
David Benjamin1286bee2016-10-07 15:25:06 -040011273 // Test that unknown NewSessionTicket extensions are tolerated.
11274 testCases = append(testCases, testCase{
11275 name: "TLS13-CustomTicketExtension",
11276 config: Config{
11277 MaxVersion: VersionTLS13,
11278 Bugs: ProtocolBugs{
11279 CustomTicketExtension: "1234",
11280 },
11281 },
11282 })
Steven Valdez2d850622017-01-11 11:34:52 -050011283
Steven Valdez0e4a4482017-07-17 11:12:34 -040011284 for _, noSessionID := range []bool{false, true} {
11285 prefix := "TLS13Experiment"
11286 variant := TLS13Experiment
11287 if noSessionID {
11288 prefix = "TLS13NoSessionIDExperiment"
11289 variant = TLS13NoSessionIDExperiment
11290 }
11291
11292 // Test that enabling a TLS 1.3 variant does not interfere with
11293 // TLS 1.2 session ID resumption.
11294 testCases = append(testCases, testCase{
11295 testType: clientTest,
11296 name: prefix + "-ResumeTLS12SessionID",
11297 config: Config{
11298 MaxVersion: VersionTLS12,
11299 SessionTicketsDisabled: true,
11300 },
11301 resumeSession: true,
11302 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11303 })
11304
11305 // Test that the server correctly echoes back session IDs of
11306 // various lengths.
11307 testCases = append(testCases, testCase{
11308 testType: serverTest,
11309 name: prefix + "-EmptySessionID",
11310 config: Config{
11311 MaxVersion: VersionTLS13,
11312 Bugs: ProtocolBugs{
11313 SendClientHelloSessionID: []byte{},
11314 },
11315 },
11316 tls13Variant: variant,
11317 })
11318
11319 testCases = append(testCases, testCase{
11320 testType: serverTest,
11321 name: prefix + "-ShortSessionID",
11322 config: Config{
11323 MaxVersion: VersionTLS13,
11324 Bugs: ProtocolBugs{
11325 SendClientHelloSessionID: make([]byte, 16),
11326 },
11327 },
11328 tls13Variant: variant,
11329 })
11330
11331 testCases = append(testCases, testCase{
11332 testType: serverTest,
11333 name: prefix + "-FullSessionID",
11334 config: Config{
11335 MaxVersion: VersionTLS13,
11336 Bugs: ProtocolBugs{
11337 SendClientHelloSessionID: make([]byte, 32),
11338 },
11339 },
11340 tls13Variant: variant,
11341 })
11342 }
11343
11344 // Test that the client sends a fake session ID in TLS13Experiment.
11345 testCases = append(testCases, testCase{
11346 testType: clientTest,
11347 name: "TLS13Experiment-RequireSessionID",
11348 config: Config{
11349 MaxVersion: VersionTLS13,
11350 Bugs: ProtocolBugs{
11351 ExpectClientHelloSessionID: true,
11352 },
11353 },
11354 tls13Variant: TLS13Experiment,
11355 })
11356
11357 // Test that the client does not send a fake session ID in
11358 // TLS13NoSessionIDExperiment.
11359 testCases = append(testCases, testCase{
11360 testType: clientTest,
11361 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11362 config: Config{
11363 MaxVersion: VersionTLS13,
11364 Bugs: ProtocolBugs{
11365 ExpectEmptyClientHelloSessionID: true,
11366 },
11367 },
11368 tls13Variant: TLS13NoSessionIDExperiment,
11369 })
11370
Steven Valdez2d850622017-01-11 11:34:52 -050011371 testCases = append(testCases, testCase{
11372 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011373 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011374 config: Config{
11375 MaxVersion: VersionTLS13,
11376 MaxEarlyDataSize: 16384,
11377 },
11378 resumeConfig: &Config{
11379 MaxVersion: VersionTLS13,
11380 MaxEarlyDataSize: 16384,
11381 Bugs: ProtocolBugs{
11382 AlwaysRejectEarlyData: true,
11383 },
11384 },
11385 resumeSession: true,
11386 flags: []string{
11387 "-enable-early-data",
11388 "-expect-early-data-info",
11389 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011390 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011391 },
11392 })
11393
11394 testCases = append(testCases, testCase{
11395 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011396 name: "TLS13Experiment-EarlyData-Reject-Client",
11397 config: Config{
11398 MaxVersion: VersionTLS13,
11399 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011400 },
11401 resumeConfig: &Config{
11402 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011403 MaxEarlyDataSize: 16384,
11404 Bugs: ProtocolBugs{
11405 AlwaysRejectEarlyData: true,
11406 },
11407 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011408 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011409 resumeSession: true,
11410 flags: []string{
11411 "-enable-early-data",
11412 "-expect-early-data-info",
11413 "-expect-reject-early-data",
11414 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011415 },
11416 })
11417
11418 testCases = append(testCases, testCase{
11419 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011420 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11421 config: Config{
11422 MaxVersion: VersionTLS13,
11423 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011424 },
11425 resumeConfig: &Config{
11426 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011427 MaxEarlyDataSize: 16384,
11428 Bugs: ProtocolBugs{
11429 AlwaysRejectEarlyData: true,
11430 },
11431 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011432 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011433 resumeSession: true,
11434 flags: []string{
11435 "-enable-early-data",
11436 "-expect-early-data-info",
11437 "-expect-reject-early-data",
11438 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011439 },
11440 })
11441
11442 testCases = append(testCases, testCase{
11443 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011444 name: "TLS13-EarlyData-RejectTicket-Client",
11445 config: Config{
11446 MaxVersion: VersionTLS13,
11447 MaxEarlyDataSize: 16384,
11448 Certificates: []Certificate{rsaCertificate},
11449 },
11450 resumeConfig: &Config{
11451 MaxVersion: VersionTLS13,
11452 MaxEarlyDataSize: 16384,
11453 Certificates: []Certificate{ecdsaP256Certificate},
11454 SessionTicketsDisabled: true,
11455 },
11456 resumeSession: true,
11457 expectResumeRejected: true,
11458 flags: []string{
11459 "-enable-early-data",
11460 "-expect-early-data-info",
11461 "-expect-reject-early-data",
11462 "-on-resume-shim-writes-first",
11463 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11464 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11465 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11466 // Session tickets are disabled, so the runner will not send a ticket.
11467 "-on-retry-expect-no-session",
11468 },
11469 })
11470
11471 testCases = append(testCases, testCase{
11472 testType: clientTest,
11473 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011474 config: Config{
11475 MaxVersion: VersionTLS13,
11476 MaxEarlyDataSize: 16384,
11477 },
11478 resumeConfig: &Config{
11479 MaxVersion: VersionTLS13,
11480 MaxEarlyDataSize: 16384,
11481 Bugs: ProtocolBugs{
11482 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11483 },
11484 },
11485 resumeSession: true,
11486 flags: []string{
11487 "-enable-early-data",
11488 "-expect-early-data-info",
11489 "-expect-reject-early-data",
11490 },
11491 })
11492
11493 // The client must check the server does not send the early_data
11494 // extension while rejecting the session.
11495 testCases = append(testCases, testCase{
11496 testType: clientTest,
11497 name: "TLS13-EarlyDataWithoutResume-Client",
11498 config: Config{
11499 MaxVersion: VersionTLS13,
11500 MaxEarlyDataSize: 16384,
11501 },
11502 resumeConfig: &Config{
11503 MaxVersion: VersionTLS13,
11504 SessionTicketsDisabled: true,
11505 Bugs: ProtocolBugs{
11506 SendEarlyDataExtension: true,
11507 },
11508 },
11509 resumeSession: true,
11510 flags: []string{
11511 "-enable-early-data",
11512 "-expect-early-data-info",
11513 },
11514 shouldFail: true,
11515 expectedError: ":UNEXPECTED_EXTENSION:",
11516 })
11517
11518 // The client must fail with a dedicated error code if the server
11519 // responds with TLS 1.2 when offering 0-RTT.
11520 testCases = append(testCases, testCase{
11521 testType: clientTest,
11522 name: "TLS13-EarlyDataVersionDowngrade-Client",
11523 config: Config{
11524 MaxVersion: VersionTLS13,
11525 MaxEarlyDataSize: 16384,
11526 },
11527 resumeConfig: &Config{
11528 MaxVersion: VersionTLS12,
11529 },
11530 resumeSession: true,
11531 flags: []string{
11532 "-enable-early-data",
11533 "-expect-early-data-info",
11534 },
11535 shouldFail: true,
11536 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11537 })
11538
11539 // Test that the client rejects an (unsolicited) early_data extension if
11540 // the server sent an HRR.
11541 testCases = append(testCases, testCase{
11542 testType: clientTest,
11543 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11544 config: Config{
11545 MaxVersion: VersionTLS13,
11546 MaxEarlyDataSize: 16384,
11547 },
11548 resumeConfig: &Config{
11549 MaxVersion: VersionTLS13,
11550 MaxEarlyDataSize: 16384,
11551 Bugs: ProtocolBugs{
11552 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11553 SendEarlyDataExtension: true,
11554 },
11555 },
11556 resumeSession: true,
11557 flags: []string{
11558 "-enable-early-data",
11559 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011560 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011561 },
11562 shouldFail: true,
11563 expectedError: ":UNEXPECTED_EXTENSION:",
11564 })
11565
11566 fooString := "foo"
11567 barString := "bar"
11568
11569 // Test that the client reports the correct ALPN after a 0-RTT reject
11570 // that changed it.
11571 testCases = append(testCases, testCase{
11572 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011573 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011574 config: Config{
11575 MaxVersion: VersionTLS13,
11576 MaxEarlyDataSize: 16384,
11577 Bugs: ProtocolBugs{
11578 ALPNProtocol: &fooString,
11579 },
11580 },
11581 resumeConfig: &Config{
11582 MaxVersion: VersionTLS13,
11583 MaxEarlyDataSize: 16384,
11584 Bugs: ProtocolBugs{
11585 ALPNProtocol: &barString,
11586 },
11587 },
11588 resumeSession: true,
11589 flags: []string{
11590 "-advertise-alpn", "\x03foo\x03bar",
11591 "-enable-early-data",
11592 "-expect-early-data-info",
11593 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011594 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011595 "-on-resume-expect-alpn", "foo",
11596 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011597 },
11598 })
11599
11600 // Test that the client reports the correct ALPN after a 0-RTT reject if
11601 // ALPN was omitted from the first connection.
11602 testCases = append(testCases, testCase{
11603 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011604 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011605 config: Config{
11606 MaxVersion: VersionTLS13,
11607 MaxEarlyDataSize: 16384,
11608 },
11609 resumeConfig: &Config{
11610 MaxVersion: VersionTLS13,
11611 MaxEarlyDataSize: 16384,
11612 NextProtos: []string{"foo"},
11613 },
11614 resumeSession: true,
11615 flags: []string{
11616 "-advertise-alpn", "\x03foo\x03bar",
11617 "-enable-early-data",
11618 "-expect-early-data-info",
11619 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011620 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011621 "-on-resume-expect-alpn", "",
11622 "-on-retry-expect-alpn", "foo",
11623 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011624 },
11625 })
11626
11627 // Test that the client reports the correct ALPN after a 0-RTT reject if
11628 // ALPN was omitted from the second connection.
11629 testCases = append(testCases, testCase{
11630 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011631 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011632 config: Config{
11633 MaxVersion: VersionTLS13,
11634 MaxEarlyDataSize: 16384,
11635 NextProtos: []string{"foo"},
11636 },
11637 resumeConfig: &Config{
11638 MaxVersion: VersionTLS13,
11639 MaxEarlyDataSize: 16384,
11640 },
11641 resumeSession: true,
11642 flags: []string{
11643 "-advertise-alpn", "\x03foo\x03bar",
11644 "-enable-early-data",
11645 "-expect-early-data-info",
11646 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011647 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011648 "-on-resume-expect-alpn", "foo",
11649 "-on-retry-expect-alpn", "",
11650 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011651 },
11652 })
11653
11654 // Test that the client enforces ALPN match on 0-RTT accept.
11655 testCases = append(testCases, testCase{
11656 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011657 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011658 config: Config{
11659 MaxVersion: VersionTLS13,
11660 MaxEarlyDataSize: 16384,
11661 Bugs: ProtocolBugs{
11662 ALPNProtocol: &fooString,
11663 },
11664 },
11665 resumeConfig: &Config{
11666 MaxVersion: VersionTLS13,
11667 MaxEarlyDataSize: 16384,
11668 Bugs: ProtocolBugs{
11669 AlwaysAcceptEarlyData: true,
11670 ALPNProtocol: &barString,
11671 },
11672 },
11673 resumeSession: true,
11674 flags: []string{
11675 "-advertise-alpn", "\x03foo\x03bar",
11676 "-enable-early-data",
11677 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011678 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011679 "-on-resume-expect-alpn", "foo",
11680 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011681 },
11682 shouldFail: true,
11683 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11684 })
11685
11686 // Test that the server correctly rejects 0-RTT when the previous
11687 // session did not allow early data on resumption.
11688 testCases = append(testCases, testCase{
11689 testType: serverTest,
11690 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11691 config: Config{
11692 MaxVersion: VersionTLS13,
11693 },
11694 resumeConfig: &Config{
11695 MaxVersion: VersionTLS13,
11696 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011697 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011698 ExpectEarlyDataAccepted: false,
11699 },
11700 },
11701 resumeSession: true,
11702 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011703 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011704 "-expect-reject-early-data",
11705 },
11706 })
11707
11708 // Test that we reject early data where ALPN is omitted from the first
11709 // connection.
11710 testCases = append(testCases, testCase{
11711 testType: serverTest,
11712 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11713 config: Config{
11714 MaxVersion: VersionTLS13,
11715 NextProtos: []string{},
11716 },
11717 resumeConfig: &Config{
11718 MaxVersion: VersionTLS13,
11719 NextProtos: []string{"foo"},
11720 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011721 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011722 ExpectEarlyDataAccepted: false,
11723 },
11724 },
11725 resumeSession: true,
11726 flags: []string{
11727 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011728 "-on-initial-select-alpn", "",
11729 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011730 },
11731 })
11732
11733 // Test that we reject early data where ALPN is omitted from the second
11734 // connection.
11735 testCases = append(testCases, testCase{
11736 testType: serverTest,
11737 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11738 config: Config{
11739 MaxVersion: VersionTLS13,
11740 NextProtos: []string{"foo"},
11741 },
11742 resumeConfig: &Config{
11743 MaxVersion: VersionTLS13,
11744 NextProtos: []string{},
11745 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011746 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011747 ExpectEarlyDataAccepted: false,
11748 },
11749 },
11750 resumeSession: true,
11751 flags: []string{
11752 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011753 "-on-initial-select-alpn", "foo",
11754 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011755 },
11756 })
11757
11758 // Test that we reject early data with mismatched ALPN.
11759 testCases = append(testCases, testCase{
11760 testType: serverTest,
11761 name: "TLS13-EarlyData-ALPNMismatch-Server",
11762 config: Config{
11763 MaxVersion: VersionTLS13,
11764 NextProtos: []string{"foo"},
11765 },
11766 resumeConfig: &Config{
11767 MaxVersion: VersionTLS13,
11768 NextProtos: []string{"bar"},
11769 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011770 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011771 ExpectEarlyDataAccepted: false,
11772 },
11773 },
11774 resumeSession: true,
11775 flags: []string{
11776 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011777 "-on-initial-select-alpn", "foo",
11778 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011779 },
11780 })
11781
David Benjamin6bb507b2017-03-29 16:35:57 -050011782 // Test that the client offering 0-RTT and Channel ID forbids the server
11783 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011784 testCases = append(testCases, testCase{
11785 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011786 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011787 config: Config{
11788 MaxVersion: VersionTLS13,
11789 MaxEarlyDataSize: 16384,
11790 RequestChannelID: true,
11791 },
11792 resumeSession: true,
11793 expectChannelID: true,
11794 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011795 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011796 flags: []string{
11797 "-enable-early-data",
11798 "-expect-early-data-info",
11799 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11800 },
11801 })
11802
David Benjamin6bb507b2017-03-29 16:35:57 -050011803 // Test that the client offering Channel ID and 0-RTT allows the server
11804 // to decline 0-RTT.
11805 testCases = append(testCases, testCase{
11806 testType: clientTest,
11807 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11808 config: Config{
11809 MaxVersion: VersionTLS13,
11810 MaxEarlyDataSize: 16384,
11811 RequestChannelID: true,
11812 Bugs: ProtocolBugs{
11813 AlwaysRejectEarlyData: true,
11814 },
11815 },
11816 resumeSession: true,
11817 expectChannelID: true,
11818 flags: []string{
11819 "-enable-early-data",
11820 "-expect-early-data-info",
11821 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11822 "-expect-reject-early-data",
11823 },
11824 })
11825
11826 // Test that the client offering Channel ID and 0-RTT allows the server
11827 // to decline Channel ID.
11828 testCases = append(testCases, testCase{
11829 testType: clientTest,
11830 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11831 config: Config{
11832 MaxVersion: VersionTLS13,
11833 MaxEarlyDataSize: 16384,
11834 },
11835 resumeSession: true,
11836 flags: []string{
11837 "-enable-early-data",
11838 "-expect-early-data-info",
11839 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11840 "-expect-accept-early-data",
11841 },
11842 })
11843
11844 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11845 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011846 testCases = append(testCases, testCase{
11847 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011848 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011849 config: Config{
11850 MaxVersion: VersionTLS13,
11851 ChannelID: channelIDKey,
11852 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011853 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011854 ExpectEarlyDataAccepted: false,
11855 },
11856 },
11857 resumeSession: true,
11858 expectChannelID: true,
11859 flags: []string{
11860 "-enable-early-data",
11861 "-expect-reject-early-data",
11862 "-expect-channel-id",
11863 base64.StdEncoding.EncodeToString(channelIDBytes),
11864 },
11865 })
11866
David Benjamin6bb507b2017-03-29 16:35:57 -050011867 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11868 // if not offered Channel ID.
11869 testCases = append(testCases, testCase{
11870 testType: serverTest,
11871 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11872 config: Config{
11873 MaxVersion: VersionTLS13,
11874 Bugs: ProtocolBugs{
11875 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11876 ExpectEarlyDataAccepted: true,
11877 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11878 },
11879 },
11880 resumeSession: true,
11881 expectChannelID: false,
11882 flags: []string{
11883 "-enable-early-data",
11884 "-expect-accept-early-data",
11885 "-enable-channel-id",
11886 },
11887 })
11888
David Benjamin32c89272017-03-26 13:54:21 -050011889 // Test that the server rejects 0-RTT streams without end_of_early_data.
11890 // The subsequent records should fail to decrypt.
11891 testCases = append(testCases, testCase{
11892 testType: serverTest,
11893 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11894 config: Config{
11895 MaxVersion: VersionTLS13,
11896 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011897 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011898 ExpectEarlyDataAccepted: true,
11899 SkipEndOfEarlyData: true,
11900 },
11901 },
11902 resumeSession: true,
11903 flags: []string{"-enable-early-data"},
11904 shouldFail: true,
11905 expectedLocalError: "remote error: bad record MAC",
11906 expectedError: ":BAD_DECRYPT:",
11907 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011908
11909 testCases = append(testCases, testCase{
11910 testType: serverTest,
11911 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11912 config: Config{
11913 MaxVersion: VersionTLS13,
11914 },
11915 resumeConfig: &Config{
11916 MaxVersion: VersionTLS13,
11917 Bugs: ProtocolBugs{
11918 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11919 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011920 ExpectEarlyDataAccepted: true,
11921 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011922 },
11923 resumeSession: true,
11924 shouldFail: true,
11925 expectedError: ":UNEXPECTED_RECORD:",
11926 expectedLocalError: "remote error: unexpected message",
11927 flags: []string{
11928 "-enable-early-data",
11929 },
11930 })
David Benjamind9cbb532017-07-07 13:17:19 -040011931
11932 // Test that the client reports TLS 1.3 as the version while sending
11933 // early data.
11934 testCases = append(testCases, testCase{
11935 testType: clientTest,
11936 name: "TLS13-EarlyData-Client-VersionAPI",
11937 config: Config{
11938 MaxVersion: VersionTLS13,
11939 MaxEarlyDataSize: 16384,
11940 },
11941 resumeSession: true,
11942 flags: []string{
11943 "-enable-early-data",
11944 "-expect-early-data-info",
11945 "-expect-accept-early-data",
11946 "-expect-version", strconv.Itoa(VersionTLS13),
11947 },
11948 })
David Benjamin4a37de02017-08-08 20:15:40 -040011949
11950 // Test that client and server both notice handshake errors after data
11951 // has started flowing.
11952 testCases = append(testCases, testCase{
11953 testType: clientTest,
11954 name: "TLS13-EarlyData-Client-BadFinished",
11955 config: Config{
11956 MaxVersion: VersionTLS13,
11957 MaxEarlyDataSize: 16384,
11958 },
11959 resumeConfig: &Config{
11960 MaxVersion: VersionTLS13,
11961 MaxEarlyDataSize: 16384,
11962 Bugs: ProtocolBugs{
11963 BadFinished: true,
11964 },
11965 },
11966 resumeSession: true,
11967 flags: []string{
11968 "-enable-early-data",
11969 "-expect-early-data-info",
11970 "-expect-accept-early-data",
11971 },
11972 shouldFail: true,
11973 expectedError: ":DIGEST_CHECK_FAILED:",
11974 expectedLocalError: "remote error: error decrypting message",
11975 })
11976 testCases = append(testCases, testCase{
11977 testType: serverTest,
11978 name: "TLS13-EarlyData-Server-BadFinished",
11979 config: Config{
11980 MaxVersion: VersionTLS13,
11981 MaxEarlyDataSize: 16384,
11982 },
11983 resumeConfig: &Config{
11984 MaxVersion: VersionTLS13,
11985 MaxEarlyDataSize: 16384,
11986 Bugs: ProtocolBugs{
11987 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11988 ExpectEarlyDataAccepted: true,
11989 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11990 BadFinished: true,
11991 },
11992 },
11993 resumeSession: true,
11994 flags: []string{
11995 "-enable-early-data",
11996 "-expect-accept-early-data",
11997 },
11998 shouldFail: true,
11999 expectedError: ":DIGEST_CHECK_FAILED:",
12000 expectedLocalError: "remote error: error decrypting message",
12001 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020012002 testCases = append(testCases, testCase{
12003 testType: serverTest,
12004 name: "TLS13-ServerSkipCertificateVerify",
12005 config: Config{
12006 MinVersion: VersionTLS13,
12007 MaxVersion: VersionTLS13,
12008 Certificates: []Certificate{rsaChainCertificate},
12009 Bugs: ProtocolBugs{
12010 SkipCertificateVerify: true,
12011 },
12012 },
12013 expectPeerCertificate: &rsaChainCertificate,
12014 flags: []string{
12015 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12016 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12017 "-require-any-client-certificate",
12018 },
12019 shouldFail: true,
12020 expectedError: ":UNEXPECTED_MESSAGE:",
12021 expectedLocalError: "remote error: unexpected message",
12022 })
12023 testCases = append(testCases, testCase{
12024 testType: clientTest,
12025 name: "TLS13-ClientSkipCertificateVerify",
12026 config: Config{
12027 MinVersion: VersionTLS13,
12028 MaxVersion: VersionTLS13,
12029 Certificates: []Certificate{rsaChainCertificate},
12030 Bugs: ProtocolBugs{
12031 SkipCertificateVerify: true,
12032 },
12033 },
12034 expectPeerCertificate: &rsaChainCertificate,
12035 flags: []string{
12036 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12037 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12038 },
12039 shouldFail: true,
12040 expectedError: ":UNEXPECTED_MESSAGE:",
12041 expectedLocalError: "remote error: unexpected message",
12042 })
Steven Valdez143e8b32016-07-11 13:19:03 -040012043}
12044
David Benjaminabbbee12016-10-31 19:20:42 -040012045func addTLS13CipherPreferenceTests() {
12046 // Test that client preference is honored if the shim has AES hardware
12047 // and ChaCha20-Poly1305 is preferred otherwise.
12048 testCases = append(testCases, testCase{
12049 testType: serverTest,
12050 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
12051 config: Config{
12052 MaxVersion: VersionTLS13,
12053 CipherSuites: []uint16{
12054 TLS_CHACHA20_POLY1305_SHA256,
12055 TLS_AES_128_GCM_SHA256,
12056 },
12057 },
12058 flags: []string{
12059 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12060 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12061 },
12062 })
12063
12064 testCases = append(testCases, testCase{
12065 testType: serverTest,
12066 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
12067 config: Config{
12068 MaxVersion: VersionTLS13,
12069 CipherSuites: []uint16{
12070 TLS_AES_128_GCM_SHA256,
12071 TLS_CHACHA20_POLY1305_SHA256,
12072 },
12073 },
12074 flags: []string{
12075 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12076 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12077 },
12078 })
12079
12080 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
12081 // whether it has AES hardware.
12082 testCases = append(testCases, testCase{
12083 name: "TLS13-CipherPreference-Client",
12084 config: Config{
12085 MaxVersion: VersionTLS13,
12086 // Use the client cipher order. (This is the default but
12087 // is listed to be explicit.)
12088 PreferServerCipherSuites: false,
12089 },
12090 flags: []string{
12091 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12092 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12093 },
12094 })
12095}
12096
David Benjaminf3fbade2016-09-19 13:08:16 -040012097func addPeekTests() {
12098 // Test SSL_peek works, including on empty records.
12099 testCases = append(testCases, testCase{
12100 name: "Peek-Basic",
12101 sendEmptyRecords: 1,
12102 flags: []string{"-peek-then-read"},
12103 })
12104
12105 // Test SSL_peek can drive the initial handshake.
12106 testCases = append(testCases, testCase{
12107 name: "Peek-ImplicitHandshake",
12108 flags: []string{
12109 "-peek-then-read",
12110 "-implicit-handshake",
12111 },
12112 })
12113
12114 // Test SSL_peek can discover and drive a renegotiation.
12115 testCases = append(testCases, testCase{
12116 name: "Peek-Renegotiate",
12117 config: Config{
12118 MaxVersion: VersionTLS12,
12119 },
12120 renegotiate: 1,
12121 flags: []string{
12122 "-peek-then-read",
12123 "-renegotiate-freely",
12124 "-expect-total-renegotiations", "1",
12125 },
12126 })
12127
12128 // Test SSL_peek can discover a close_notify.
12129 testCases = append(testCases, testCase{
12130 name: "Peek-Shutdown",
12131 config: Config{
12132 Bugs: ProtocolBugs{
12133 ExpectCloseNotify: true,
12134 },
12135 },
12136 flags: []string{
12137 "-peek-then-read",
12138 "-check-close-notify",
12139 },
12140 })
12141
12142 // Test SSL_peek can discover an alert.
12143 testCases = append(testCases, testCase{
12144 name: "Peek-Alert",
12145 config: Config{
12146 Bugs: ProtocolBugs{
12147 SendSpuriousAlert: alertRecordOverflow,
12148 },
12149 },
12150 flags: []string{"-peek-then-read"},
12151 shouldFail: true,
12152 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12153 })
12154
12155 // Test SSL_peek can handle KeyUpdate.
12156 testCases = append(testCases, testCase{
12157 name: "Peek-KeyUpdate",
12158 config: Config{
12159 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012160 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012161 sendKeyUpdates: 1,
12162 keyUpdateRequest: keyUpdateNotRequested,
12163 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012164 })
12165}
12166
David Benjamine6f22212016-11-08 14:28:24 -050012167func addRecordVersionTests() {
12168 for _, ver := range tlsVersions {
12169 // Test that the record version is enforced.
12170 testCases = append(testCases, testCase{
12171 name: "CheckRecordVersion-" + ver.name,
12172 config: Config{
12173 MinVersion: ver.version,
12174 MaxVersion: ver.version,
12175 Bugs: ProtocolBugs{
12176 SendRecordVersion: 0x03ff,
12177 },
12178 },
David Benjamina5022392017-07-10 17:40:39 -040012179 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012180 shouldFail: true,
12181 expectedError: ":WRONG_VERSION_NUMBER:",
12182 })
12183
12184 // Test that the ClientHello may use any record version, for
12185 // compatibility reasons.
12186 testCases = append(testCases, testCase{
12187 testType: serverTest,
12188 name: "LooseInitialRecordVersion-" + ver.name,
12189 config: Config{
12190 MinVersion: ver.version,
12191 MaxVersion: ver.version,
12192 Bugs: ProtocolBugs{
12193 SendInitialRecordVersion: 0x03ff,
12194 },
12195 },
David Benjamina5022392017-07-10 17:40:39 -040012196 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012197 })
12198
12199 // Test that garbage ClientHello record versions are rejected.
12200 testCases = append(testCases, testCase{
12201 testType: serverTest,
12202 name: "GarbageInitialRecordVersion-" + ver.name,
12203 config: Config{
12204 MinVersion: ver.version,
12205 MaxVersion: ver.version,
12206 Bugs: ProtocolBugs{
12207 SendInitialRecordVersion: 0xffff,
12208 },
12209 },
David Benjamina5022392017-07-10 17:40:39 -040012210 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012211 shouldFail: true,
12212 expectedError: ":WRONG_VERSION_NUMBER:",
12213 })
12214 }
12215}
12216
David Benjamin2c516452016-11-15 10:16:54 +090012217func addCertificateTests() {
12218 // Test that a certificate chain with intermediate may be sent and
12219 // received as both client and server.
12220 for _, ver := range tlsVersions {
12221 testCases = append(testCases, testCase{
12222 testType: clientTest,
12223 name: "SendReceiveIntermediate-Client-" + ver.name,
12224 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012225 MinVersion: ver.version,
12226 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012227 Certificates: []Certificate{rsaChainCertificate},
12228 ClientAuth: RequireAnyClientCert,
12229 },
David Benjamina5022392017-07-10 17:40:39 -040012230 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012231 expectPeerCertificate: &rsaChainCertificate,
12232 flags: []string{
12233 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12234 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12235 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12236 },
12237 })
12238
12239 testCases = append(testCases, testCase{
12240 testType: serverTest,
12241 name: "SendReceiveIntermediate-Server-" + ver.name,
12242 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012243 MinVersion: ver.version,
12244 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012245 Certificates: []Certificate{rsaChainCertificate},
12246 },
David Benjamina5022392017-07-10 17:40:39 -040012247 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012248 expectPeerCertificate: &rsaChainCertificate,
12249 flags: []string{
12250 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12251 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12252 "-require-any-client-certificate",
12253 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12254 },
12255 })
12256 }
12257}
12258
David Benjaminbbaf3672016-11-17 10:53:09 +090012259func addRetainOnlySHA256ClientCertTests() {
12260 for _, ver := range tlsVersions {
12261 // Test that enabling
12262 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12263 // actually requesting a client certificate is a no-op.
12264 testCases = append(testCases, testCase{
12265 testType: serverTest,
12266 name: "RetainOnlySHA256-NoCert-" + ver.name,
12267 config: Config{
12268 MinVersion: ver.version,
12269 MaxVersion: ver.version,
12270 },
David Benjamina5022392017-07-10 17:40:39 -040012271 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012272 flags: []string{
12273 "-retain-only-sha256-client-cert-initial",
12274 "-retain-only-sha256-client-cert-resume",
12275 },
12276 resumeSession: true,
12277 })
12278
12279 // Test that when retaining only a SHA-256 certificate is
12280 // enabled, the hash appears as expected.
12281 testCases = append(testCases, testCase{
12282 testType: serverTest,
12283 name: "RetainOnlySHA256-Cert-" + ver.name,
12284 config: Config{
12285 MinVersion: ver.version,
12286 MaxVersion: ver.version,
12287 Certificates: []Certificate{rsaCertificate},
12288 },
David Benjamina5022392017-07-10 17:40:39 -040012289 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012290 flags: []string{
12291 "-verify-peer",
12292 "-retain-only-sha256-client-cert-initial",
12293 "-retain-only-sha256-client-cert-resume",
12294 "-expect-sha256-client-cert-initial",
12295 "-expect-sha256-client-cert-resume",
12296 },
12297 resumeSession: true,
12298 })
12299
12300 // Test that when the config changes from on to off, a
12301 // resumption is rejected because the server now wants the full
12302 // certificate chain.
12303 testCases = append(testCases, testCase{
12304 testType: serverTest,
12305 name: "RetainOnlySHA256-OnOff-" + ver.name,
12306 config: Config{
12307 MinVersion: ver.version,
12308 MaxVersion: ver.version,
12309 Certificates: []Certificate{rsaCertificate},
12310 },
David Benjamina5022392017-07-10 17:40:39 -040012311 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012312 flags: []string{
12313 "-verify-peer",
12314 "-retain-only-sha256-client-cert-initial",
12315 "-expect-sha256-client-cert-initial",
12316 },
12317 resumeSession: true,
12318 expectResumeRejected: true,
12319 })
12320
12321 // Test that when the config changes from off to on, a
12322 // resumption is rejected because the server now wants just the
12323 // hash.
12324 testCases = append(testCases, testCase{
12325 testType: serverTest,
12326 name: "RetainOnlySHA256-OffOn-" + ver.name,
12327 config: Config{
12328 MinVersion: ver.version,
12329 MaxVersion: ver.version,
12330 Certificates: []Certificate{rsaCertificate},
12331 },
David Benjamina5022392017-07-10 17:40:39 -040012332 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012333 flags: []string{
12334 "-verify-peer",
12335 "-retain-only-sha256-client-cert-resume",
12336 "-expect-sha256-client-cert-resume",
12337 },
12338 resumeSession: true,
12339 expectResumeRejected: true,
12340 })
12341 }
12342}
12343
Adam Langleya4b91982016-12-12 12:05:53 -080012344func addECDSAKeyUsageTests() {
12345 p256 := elliptic.P256()
12346 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12347 if err != nil {
12348 panic(err)
12349 }
12350
12351 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12352 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12353 if err != nil {
12354 panic(err)
12355 }
12356
12357 template := x509.Certificate{
12358 SerialNumber: serialNumber,
12359 Subject: pkix.Name{
12360 Organization: []string{"Acme Co"},
12361 },
12362 NotBefore: time.Now(),
12363 NotAfter: time.Now(),
12364
12365 // An ECC certificate with only the keyAgreement key usgae may
12366 // be used with ECDH, but not ECDSA.
12367 KeyUsage: x509.KeyUsageKeyAgreement,
12368 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12369 BasicConstraintsValid: true,
12370 }
12371
12372 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12373 if err != nil {
12374 panic(err)
12375 }
12376
12377 cert := Certificate{
12378 Certificate: [][]byte{derBytes},
12379 PrivateKey: priv,
12380 }
12381
12382 for _, ver := range tlsVersions {
12383 if ver.version < VersionTLS12 {
12384 continue
12385 }
12386
12387 testCases = append(testCases, testCase{
12388 testType: clientTest,
12389 name: "ECDSAKeyUsage-" + ver.name,
12390 config: Config{
12391 MinVersion: ver.version,
12392 MaxVersion: ver.version,
12393 Certificates: []Certificate{cert},
12394 },
David Benjamina5022392017-07-10 17:40:39 -040012395 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012396 shouldFail: true,
12397 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12398 })
12399 }
12400}
12401
David Benjamin8c26d752017-03-26 15:13:51 -050012402func addExtraHandshakeTests() {
12403 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12404 // to ensure there is no transport I/O.
12405 testCases = append(testCases, testCase{
12406 testType: clientTest,
12407 name: "ExtraHandshake-Client-TLS12",
12408 config: Config{
12409 MinVersion: VersionTLS12,
12410 MaxVersion: VersionTLS12,
12411 },
12412 flags: []string{
12413 "-async",
12414 "-no-op-extra-handshake",
12415 },
12416 })
12417 testCases = append(testCases, testCase{
12418 testType: serverTest,
12419 name: "ExtraHandshake-Server-TLS12",
12420 config: Config{
12421 MinVersion: VersionTLS12,
12422 MaxVersion: VersionTLS12,
12423 },
12424 flags: []string{
12425 "-async",
12426 "-no-op-extra-handshake",
12427 },
12428 })
12429 testCases = append(testCases, testCase{
12430 testType: clientTest,
12431 name: "ExtraHandshake-Client-TLS13",
12432 config: Config{
12433 MinVersion: VersionTLS13,
12434 MaxVersion: VersionTLS13,
12435 },
12436 flags: []string{
12437 "-async",
12438 "-no-op-extra-handshake",
12439 },
12440 })
12441 testCases = append(testCases, testCase{
12442 testType: serverTest,
12443 name: "ExtraHandshake-Server-TLS13",
12444 config: Config{
12445 MinVersion: VersionTLS13,
12446 MaxVersion: VersionTLS13,
12447 },
12448 flags: []string{
12449 "-async",
12450 "-no-op-extra-handshake",
12451 },
12452 })
12453
12454 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12455 testCases = append(testCases, testCase{
12456 testType: serverTest,
12457 name: "ExtraHandshake-Server-EarlyData-TLS13",
12458 config: Config{
12459 MaxVersion: VersionTLS13,
12460 MinVersion: VersionTLS13,
12461 Bugs: ProtocolBugs{
12462 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12463 ExpectEarlyDataAccepted: true,
12464 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12465 },
12466 },
12467 messageCount: 2,
12468 resumeSession: true,
12469 flags: []string{
12470 "-async",
12471 "-enable-early-data",
12472 "-expect-accept-early-data",
12473 "-no-op-extra-handshake",
12474 },
12475 })
12476
12477 // An extra SSL_do_handshake drives the handshake to completion in False
12478 // Start. We test this by handshaking twice and asserting the False
12479 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12480 // how the test works.
12481 testCases = append(testCases, testCase{
12482 testType: clientTest,
12483 name: "ExtraHandshake-FalseStart",
12484 config: Config{
12485 MaxVersion: VersionTLS12,
12486 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12487 NextProtos: []string{"foo"},
12488 Bugs: ProtocolBugs{
12489 ExpectFalseStart: true,
12490 AlertBeforeFalseStartTest: alertAccessDenied,
12491 },
12492 },
12493 flags: []string{
12494 "-handshake-twice",
12495 "-false-start",
12496 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012497 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012498 },
12499 shimWritesFirst: true,
12500 shouldFail: true,
12501 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12502 expectedLocalError: "tls: peer did not false start: EOF",
12503 })
12504}
12505
David Benjaminb853f312017-07-14 18:40:34 -040012506// Test that omitted and empty extensions blocks are tolerated.
12507func addOmitExtensionsTests() {
12508 for _, ver := range tlsVersions {
12509 if ver.version > VersionTLS12 {
12510 continue
12511 }
12512
12513 testCases = append(testCases, testCase{
12514 testType: serverTest,
12515 name: "OmitExtensions-ClientHello-" + ver.name,
12516 config: Config{
12517 MinVersion: ver.version,
12518 MaxVersion: ver.version,
12519 SessionTicketsDisabled: true,
12520 Bugs: ProtocolBugs{
12521 OmitExtensions: true,
12522 },
12523 },
12524 })
12525
12526 testCases = append(testCases, testCase{
12527 testType: serverTest,
12528 name: "EmptyExtensions-ClientHello-" + ver.name,
12529 config: Config{
12530 MinVersion: ver.version,
12531 MaxVersion: ver.version,
12532 SessionTicketsDisabled: true,
12533 Bugs: ProtocolBugs{
12534 EmptyExtensions: true,
12535 },
12536 },
12537 })
12538
12539 testCases = append(testCases, testCase{
12540 testType: clientTest,
12541 name: "OmitExtensions-ServerHello-" + ver.name,
12542 config: Config{
12543 MinVersion: ver.version,
12544 MaxVersion: ver.version,
12545 SessionTicketsDisabled: true,
12546 Bugs: ProtocolBugs{
12547 OmitExtensions: true,
12548 // Disable all ServerHello extensions so
12549 // OmitExtensions works.
12550 NoExtendedMasterSecret: true,
12551 NoRenegotiationInfo: true,
12552 },
12553 },
12554 })
12555
12556 testCases = append(testCases, testCase{
12557 testType: clientTest,
12558 name: "EmptyExtensions-ServerHello-" + ver.name,
12559 config: Config{
12560 MinVersion: ver.version,
12561 MaxVersion: ver.version,
12562 SessionTicketsDisabled: true,
12563 Bugs: ProtocolBugs{
12564 EmptyExtensions: true,
12565 // Disable all ServerHello extensions so
12566 // EmptyExtensions works.
12567 NoExtendedMasterSecret: true,
12568 NoRenegotiationInfo: true,
12569 },
12570 },
12571 })
12572 }
12573}
12574
Adam Langley7c803a62015-06-15 15:35:05 -070012575func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012576 defer wg.Done()
12577
12578 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012579 var err error
12580
David Benjaminba28dfc2016-11-15 17:47:21 +090012581 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012582 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12583 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012584 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012585 if err != nil {
12586 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12587 }
12588 break
12589 }
12590 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012591 } else if *repeatUntilFailure {
12592 for err == nil {
12593 statusChan <- statusMsg{test: test, started: true}
12594 err = runTest(test, shimPath, -1)
12595 }
12596 } else {
12597 statusChan <- statusMsg{test: test, started: true}
12598 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012599 }
Adam Langley95c29f32014-06-20 12:00:00 -070012600 statusChan <- statusMsg{test: test, err: err}
12601 }
12602}
12603
12604type statusMsg struct {
12605 test *testCase
12606 started bool
12607 err error
12608}
12609
David Benjamin5f237bc2015-02-11 17:14:15 -050012610func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012611 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012612
David Benjamin5f237bc2015-02-11 17:14:15 -050012613 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012614 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012615 if !*pipe {
12616 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012617 var erase string
12618 for i := 0; i < lineLen; i++ {
12619 erase += "\b \b"
12620 }
12621 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012622 }
12623
Adam Langley95c29f32014-06-20 12:00:00 -070012624 if msg.started {
12625 started++
12626 } else {
12627 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012628
12629 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012630 if msg.err == errUnimplemented {
12631 if *pipe {
12632 // Print each test instead of a status line.
12633 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12634 }
12635 unimplemented++
12636 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12637 } else {
12638 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12639 failed++
12640 testOutput.addResult(msg.test.name, "FAIL")
12641 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012642 } else {
12643 if *pipe {
12644 // Print each test instead of a status line.
12645 fmt.Printf("PASSED (%s)\n", msg.test.name)
12646 }
12647 testOutput.addResult(msg.test.name, "PASS")
12648 }
Adam Langley95c29f32014-06-20 12:00:00 -070012649 }
12650
David Benjamin5f237bc2015-02-11 17:14:15 -050012651 if !*pipe {
12652 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012653 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012654 lineLen = len(line)
12655 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012656 }
Adam Langley95c29f32014-06-20 12:00:00 -070012657 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012658
12659 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012660}
12661
12662func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012663 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012664 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012665 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012666
Adam Langley7c803a62015-06-15 15:35:05 -070012667 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012668 addCipherSuiteTests()
12669 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012670 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012671 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012672 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012673 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012674 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012675 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012676 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012677 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012678 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012679 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012680 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012681 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012682 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012683 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012684 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012685 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012686 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012687 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012688 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012689 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012690 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012691 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012692 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012693 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012694 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012695 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012696 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012697 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012698 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012699 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012700 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012701 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012702 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012703
12704 var wg sync.WaitGroup
12705
Adam Langley7c803a62015-06-15 15:35:05 -070012706 statusChan := make(chan statusMsg, *numWorkers)
12707 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012708 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012709
EKRf71d7ed2016-08-06 13:25:12 -070012710 if len(*shimConfigFile) != 0 {
12711 encoded, err := ioutil.ReadFile(*shimConfigFile)
12712 if err != nil {
12713 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12714 os.Exit(1)
12715 }
12716
12717 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12718 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12719 os.Exit(1)
12720 }
12721 }
12722
David Benjamin025b3d32014-07-01 19:53:04 -040012723 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012724
Adam Langley7c803a62015-06-15 15:35:05 -070012725 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012726 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012727 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012728 }
12729
David Benjamin270f0a72016-03-17 14:41:36 -040012730 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012731 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012732 matched := true
12733 if len(*testToRun) != 0 {
12734 var err error
12735 matched, err = filepath.Match(*testToRun, testCases[i].name)
12736 if err != nil {
12737 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12738 os.Exit(1)
12739 }
12740 }
12741
EKRf71d7ed2016-08-06 13:25:12 -070012742 if !*includeDisabled {
12743 for pattern := range shimConfig.DisabledTests {
12744 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12745 if err != nil {
12746 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12747 os.Exit(1)
12748 }
12749
12750 if isDisabled {
12751 matched = false
12752 break
12753 }
12754 }
12755 }
12756
David Benjamin17e12922016-07-28 18:04:43 -040012757 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012758 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012759 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012760
12761 // Only run one test if repeating until failure.
12762 if *repeatUntilFailure {
12763 break
12764 }
Adam Langley95c29f32014-06-20 12:00:00 -070012765 }
12766 }
David Benjamin17e12922016-07-28 18:04:43 -040012767
David Benjamin270f0a72016-03-17 14:41:36 -040012768 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012769 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012770 os.Exit(1)
12771 }
Adam Langley95c29f32014-06-20 12:00:00 -070012772
12773 close(testChan)
12774 wg.Wait()
12775 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012776 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012777
12778 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012779
12780 if *jsonOutput != "" {
12781 if err := testOutput.writeTo(*jsonOutput); err != nil {
12782 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12783 }
12784 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012785
EKR842ae6c2016-07-27 09:22:05 +020012786 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12787 os.Exit(1)
12788 }
12789
12790 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012791 os.Exit(1)
12792 }
Adam Langley95c29f32014-06-20 12:00:00 -070012793}