blob: e526576d3bca5cb9feca1e3d4df16c70391abad4 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
491 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
492 return 0, err
493 }
494 return t.Conn.Read(b)
495}
496
497func (t *timeoutConn) Write(b []byte) (int, error) {
498 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
499 return 0, err
500 }
501 return t.Conn.Write(b)
502}
503
David Benjamin0fde2eb2017-06-30 19:11:22 -0400504func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400505 if !test.noSessionCache {
506 if config.ClientSessionCache == nil {
507 config.ClientSessionCache = NewLRUClientSessionCache(1)
508 }
509 if config.ServerSessionCache == nil {
510 config.ServerSessionCache = NewLRUServerSessionCache(1)
511 }
512 }
513 if test.testType == clientTest {
514 if len(config.Certificates) == 0 {
515 config.Certificates = []Certificate{rsaCertificate}
516 }
517 } else {
518 // Supply a ServerName to ensure a constant session cache key,
519 // rather than falling back to net.Conn.RemoteAddr.
520 if len(config.ServerName) == 0 {
521 config.ServerName = "test"
522 }
523 }
524 if *fuzzer {
525 config.Bugs.NullAllCiphers = true
526 }
David Benjamin01a90572016-09-22 00:11:43 -0400527 if *deterministic {
528 config.Time = func() time.Time { return time.Unix(1234, 1234) }
529 }
David Benjamine54af062016-08-08 19:21:18 -0400530
David Benjamin01784b42016-06-07 18:00:52 -0400531 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500532
David Benjamin6fd297b2014-08-11 18:43:38 -0400533 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500534 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
535 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500536 }
537
David Benjamin9867b7d2016-03-01 23:25:48 -0500538 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500539 local, peer := "client", "server"
540 if test.testType == clientTest {
541 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500542 }
David Benjaminebda9b32015-11-02 15:33:18 -0500543 connDebug := &recordingConn{
544 Conn: conn,
545 isDatagram: test.protocol == dtls,
546 local: local,
547 peer: peer,
548 }
549 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500550 if *flagDebug {
551 defer connDebug.WriteTo(os.Stdout)
552 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400553 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500554 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400555 path := transcriptPrefix + strconv.Itoa(num)
556 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 }()
558 }
David Benjaminebda9b32015-11-02 15:33:18 -0500559
560 if config.Bugs.PacketAdaptor != nil {
561 config.Bugs.PacketAdaptor.debug = connDebug
562 }
563 }
564
565 if test.replayWrites {
566 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400567 }
568
David Benjamin3ed59772016-03-08 12:50:21 -0500569 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500570 if test.damageFirstWrite {
571 connDamage = newDamageAdaptor(conn)
572 conn = connDamage
573 }
574
David Benjamin6fd297b2014-08-11 18:43:38 -0400575 if test.sendPrefix != "" {
576 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
577 return err
578 }
David Benjamin98e882e2014-08-08 13:24:34 -0400579 }
580
David Benjamin1d5c83e2014-07-22 19:20:02 -0400581 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400582 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400583 if test.protocol == dtls {
584 tlsConn = DTLSServer(conn, config)
585 } else {
586 tlsConn = Server(conn, config)
587 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 } else {
589 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSClient(conn, config)
592 } else {
593 tlsConn = Client(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 }
David Benjamin30789da2015-08-29 22:56:45 -0400596 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400597
Adam Langley95c29f32014-06-20 12:00:00 -0700598 if err := tlsConn.Handshake(); err != nil {
599 return err
600 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700601
David Benjamin01fe8202014-09-24 15:21:44 -0400602 // TODO(davidben): move all per-connection expectations into a dedicated
603 // expectations struct that can be specified separately for the two
604 // legs.
605 expectedVersion := test.expectedVersion
606 if isResume && test.expectedResumeVersion != 0 {
607 expectedVersion = test.expectedResumeVersion
608 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700609 connState := tlsConn.ConnectionState()
610 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400611 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400612 }
613
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700614 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400615 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
616 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700617 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
618 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
619 }
David Benjamin90da8c82015-04-20 14:57:57 -0400620
David Benjamina08e49d2014-08-24 01:46:07 -0400621 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700622 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400623 if channelID == nil {
624 return fmt.Errorf("no channel ID negotiated")
625 }
626 if channelID.Curve != channelIDKey.Curve ||
627 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
628 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
629 return fmt.Errorf("incorrect channel ID")
630 }
David Benjamin634f4752017-07-01 11:08:41 -0400631 } else if connState.ChannelID != nil {
632 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400633 }
634
David Benjaminae2888f2014-09-06 12:58:58 -0400635 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700636 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400637 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
638 }
639 }
640
David Benjaminc7ce9772015-10-09 19:32:41 -0400641 if test.expectNoNextProto {
642 if actual := connState.NegotiatedProtocol; actual != "" {
643 return fmt.Errorf("got unexpected next proto %s", actual)
644 }
645 }
646
David Benjaminfc7b0862014-09-06 13:21:53 -0400647 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700648 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400649 return fmt.Errorf("next proto type mismatch")
650 }
651 }
652
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700653 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500654 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
655 }
656
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100657 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300658 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100659 }
660
Paul Lietar4fac72e2015-09-09 13:44:55 +0100661 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
662 return fmt.Errorf("SCT list mismatch")
663 }
664
Nick Harper60edffd2016-06-21 15:19:24 -0700665 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
666 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400667 }
668
Steven Valdez5440fe02016-07-18 12:40:30 -0400669 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
670 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
671 }
672
David Benjamin2c516452016-11-15 10:16:54 +0900673 if test.expectPeerCertificate != nil {
674 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
675 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
676 }
677 for i, cert := range connState.PeerCertificates {
678 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
679 return fmt.Errorf("peer certificate %d did not match", i+1)
680 }
681 }
682 }
683
David Benjaminc565ebb2015-04-03 04:06:36 -0400684 if test.exportKeyingMaterial > 0 {
685 actual := make([]byte, test.exportKeyingMaterial)
686 if _, err := io.ReadFull(tlsConn, actual); err != nil {
687 return err
688 }
689 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
690 if err != nil {
691 return err
692 }
693 if !bytes.Equal(actual, expected) {
694 return fmt.Errorf("keying material mismatch")
695 }
696 }
697
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700698 if test.testTLSUnique {
699 var peersValue [12]byte
700 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
701 return err
702 }
703 expected := tlsConn.ConnectionState().TLSUnique
704 if !bytes.Equal(peersValue[:], expected) {
705 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
706 }
707 }
708
David Benjamin47921102016-07-28 11:29:18 -0400709 if test.sendHalfHelloRequest {
710 tlsConn.SendHalfHelloRequest()
711 }
712
Steven Valdeze831a812017-03-09 14:56:07 -0500713 shimPrefix := test.shimPrefix
714 if isResume {
715 shimPrefix = test.resumeShimPrefix
716 }
717 if test.shimWritesFirst || test.readWithUnfinishedWrite {
718 shimPrefix = "hello"
719 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400720 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400721 // If readWithUnfinishedWrite is set, the shim prefix will be
722 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500723 if shimPrefix != "" && !test.readWithUnfinishedWrite {
724 var buf = make([]byte, len(shimPrefix))
725 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400726 if err != nil {
727 return err
728 }
Steven Valdeze831a812017-03-09 14:56:07 -0500729 if string(buf) != shimPrefix {
730 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400731 }
Steven Valdeze831a812017-03-09 14:56:07 -0500732 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400733 }
734
Adam Langleycf2d4f42014-10-28 19:06:14 -0700735 if test.renegotiateCiphers != nil {
736 config.CipherSuites = test.renegotiateCiphers
737 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400738 for i := 0; i < test.renegotiate; i++ {
739 if err := tlsConn.Renegotiate(); err != nil {
740 return err
741 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 }
743 } else if test.renegotiateCiphers != nil {
744 panic("renegotiateCiphers without renegotiate")
745 }
746
David Benjamin5fa3eba2015-01-22 16:35:40 -0500747 if test.damageFirstWrite {
748 connDamage.setDamage(true)
749 tlsConn.Write([]byte("DAMAGED WRITE"))
750 connDamage.setDamage(false)
751 }
752
David Benjamin8e6db492015-07-25 18:29:23 -0400753 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700754 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400755 if test.protocol == dtls {
756 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
757 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700758 // Read until EOF.
759 _, err := io.Copy(ioutil.Discard, tlsConn)
760 return err
761 }
David Benjamin4417d052015-04-05 04:17:25 -0400762 if messageLen == 0 {
763 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700764 }
Adam Langley95c29f32014-06-20 12:00:00 -0700765
David Benjamin8e6db492015-07-25 18:29:23 -0400766 messageCount := test.messageCount
767 if messageCount == 0 {
768 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400769 }
770
David Benjamin8e6db492015-07-25 18:29:23 -0400771 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400772 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400773 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400774 }
775
David Benjamin8e6db492015-07-25 18:29:23 -0400776 for i := 0; i < test.sendEmptyRecords; i++ {
777 tlsConn.Write(nil)
778 }
779
780 for i := 0; i < test.sendWarningAlerts; i++ {
781 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
782 }
783
David Benjamin24e58862017-06-14 18:45:29 -0400784 if test.sendBogusAlertType {
785 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
786 }
787
David Benjaminbbba9392017-04-06 12:54:12 -0400788 testMessage := make([]byte, messageLen)
789 for i := range testMessage {
790 testMessage[i] = 0x42 ^ byte(j)
791 }
792 tlsConn.Write(testMessage)
793
794 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500795 if shimPrefix != "" {
796 var buf = make([]byte, len(shimPrefix))
797 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400798 if err != nil {
799 return err
800 }
Steven Valdeze831a812017-03-09 14:56:07 -0500801 if string(buf) != shimPrefix {
802 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400803 }
Steven Valdeze831a812017-03-09 14:56:07 -0500804 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400805 }
806
David Benjamin4f75aaf2015-09-01 16:53:10 -0400807 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400808 // The shim will not respond.
809 continue
810 }
811
David Benjaminbbba9392017-04-06 12:54:12 -0400812 // Process the KeyUpdate ACK. However many KeyUpdates the runner
813 // sends, the shim should respond only once.
814 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
815 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
816 return err
817 }
818 }
819
David Benjamin8e6db492015-07-25 18:29:23 -0400820 buf := make([]byte, len(testMessage))
821 if test.protocol == dtls {
822 bufTmp := make([]byte, len(buf)+1)
823 n, err := tlsConn.Read(bufTmp)
824 if err != nil {
825 return err
826 }
827 if n != len(buf) {
828 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
829 }
830 copy(buf, bufTmp)
831 } else {
832 _, err := io.ReadFull(tlsConn, buf)
833 if err != nil {
834 return err
835 }
836 }
837
838 for i, v := range buf {
839 if v != testMessage[i]^0xff {
840 return fmt.Errorf("bad reply contents at byte %d", i)
841 }
Adam Langley95c29f32014-06-20 12:00:00 -0700842 }
843 }
844
845 return nil
846}
847
David Benjamin325b5c32014-07-01 19:40:31 -0400848func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400849 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700850 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400851 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700852 }
David Benjamin325b5c32014-07-01 19:40:31 -0400853 valgrindArgs = append(valgrindArgs, path)
854 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700855
David Benjamin325b5c32014-07-01 19:40:31 -0400856 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700857}
858
David Benjamin325b5c32014-07-01 19:40:31 -0400859func gdbOf(path string, args ...string) *exec.Cmd {
860 xtermArgs := []string{"-e", "gdb", "--args"}
861 xtermArgs = append(xtermArgs, path)
862 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700863
David Benjamin325b5c32014-07-01 19:40:31 -0400864 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700865}
866
David Benjamind16bf342015-12-18 00:53:12 -0500867func lldbOf(path string, args ...string) *exec.Cmd {
868 xtermArgs := []string{"-e", "lldb", "--"}
869 xtermArgs = append(xtermArgs, path)
870 xtermArgs = append(xtermArgs, args...)
871
872 return exec.Command("xterm", xtermArgs...)
873}
874
EKR842ae6c2016-07-27 09:22:05 +0200875var (
876 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
877 errUnimplemented = errors.New("child process does not implement needed flags")
878)
Adam Langley69a01602014-11-17 17:26:55 -0800879
David Benjamin87c8a642015-02-21 01:54:29 -0500880// accept accepts a connection from listener, unless waitChan signals a process
881// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400882func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500883 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400884 conn net.Conn
885 err error
886 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500887 }
888 connChan := make(chan connOrError, 1)
889 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400890 startTime := time.Now()
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400891 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500892 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400893 endTime := time.Now()
894 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500895 close(connChan)
896 }()
897 select {
898 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400899 if result.err != nil {
900 // TODO(davidben): Remove this logging when
901 // https://crbug.com/boringssl/199 is resolved.
902 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
903 }
David Benjamin87c8a642015-02-21 01:54:29 -0500904 return result.conn, result.err
905 case childErr := <-waitChan:
906 waitChan <- childErr
907 return nil, fmt.Errorf("child exited early: %s", childErr)
908 }
909}
910
EKRf71d7ed2016-08-06 13:25:12 -0700911func translateExpectedError(errorStr string) string {
912 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
913 return translated
914 }
915
916 if *looseErrors {
917 return ""
918 }
919
920 return errorStr
921}
922
Adam Langley7c803a62015-06-15 15:35:05 -0700923func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400924 // Help debugging panics on the Go side.
925 defer func() {
926 if r := recover(); r != nil {
927 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
928 panic(r)
929 }
930 }()
931
Adam Langley38311732014-10-16 19:04:35 -0700932 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
933 panic("Error expected without shouldFail in " + test.name)
934 }
935
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700936 if test.expectResumeRejected && !test.resumeSession {
937 panic("expectResumeRejected without resumeSession in " + test.name)
938 }
939
Adam Langley33b1d4f2016-12-07 15:03:45 -0800940 for _, ver := range tlsVersions {
941 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
942 continue
943 }
944
David Benjamina5022392017-07-10 17:40:39 -0400945 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
946 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 -0800947 }
948
David Benjamina5022392017-07-10 17:40:39 -0400949 if ver.tls13Variant != 0 {
950 var foundFlag bool
951 for _, flag := range test.flags {
952 if flag == "-tls13-variant" {
953 foundFlag = true
954 break
955 }
956 }
957 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
958 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))
959 }
960 }
961
Adam Langley33b1d4f2016-12-07 15:03:45 -0800962 }
963
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700964 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
965 if err != nil {
966 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
967 }
David Benjamin87c8a642015-02-21 01:54:29 -0500968 if err != nil {
969 panic(err)
970 }
971 defer func() {
972 if listener != nil {
973 listener.Close()
974 }
975 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700976
David Benjamin87c8a642015-02-21 01:54:29 -0500977 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400978 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400979 flags = append(flags, "-server")
980
David Benjamin025b3d32014-07-01 19:53:04 -0400981 flags = append(flags, "-key-file")
982 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700983 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400984 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700985 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400986 }
987
988 flags = append(flags, "-cert-file")
989 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700990 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400991 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700992 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400993 }
994 }
David Benjamin5a593af2014-08-11 19:51:50 -0400995
David Benjamin6fd297b2014-08-11 18:43:38 -0400996 if test.protocol == dtls {
997 flags = append(flags, "-dtls")
998 }
999
David Benjamin46662482016-08-17 00:51:00 -04001000 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001001 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001002 resumeCount++
1003 if test.resumeRenewedSession {
1004 resumeCount++
1005 }
1006 }
1007
1008 if resumeCount > 0 {
1009 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001010 }
1011
David Benjamine58c4f52014-08-24 03:47:07 -04001012 if test.shimWritesFirst {
1013 flags = append(flags, "-shim-writes-first")
1014 }
1015
David Benjaminbbba9392017-04-06 12:54:12 -04001016 if test.readWithUnfinishedWrite {
1017 flags = append(flags, "-read-with-unfinished-write")
1018 }
1019
David Benjamin30789da2015-08-29 22:56:45 -04001020 if test.shimShutsDown {
1021 flags = append(flags, "-shim-shuts-down")
1022 }
1023
David Benjaminc565ebb2015-04-03 04:06:36 -04001024 if test.exportKeyingMaterial > 0 {
1025 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1026 flags = append(flags, "-export-label", test.exportLabel)
1027 flags = append(flags, "-export-context", test.exportContext)
1028 if test.useExportContext {
1029 flags = append(flags, "-use-export-context")
1030 }
1031 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001032 if test.expectResumeRejected {
1033 flags = append(flags, "-expect-session-miss")
1034 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001035
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001036 if test.testTLSUnique {
1037 flags = append(flags, "-tls-unique")
1038 }
1039
David Benjamina5022392017-07-10 17:40:39 -04001040 if test.tls13Variant != 0 {
1041 test.config.TLS13Variant = test.tls13Variant
1042 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1043 }
1044
David Benjamin0fde2eb2017-06-30 19:11:22 -04001045 var transcriptPrefix string
1046 if len(*transcriptDir) != 0 {
1047 protocol := "tls"
1048 if test.protocol == dtls {
1049 protocol = "dtls"
1050 }
1051
1052 side := "client"
1053 if test.testType == serverTest {
1054 side = "server"
1055 }
1056
1057 dir := filepath.Join(*transcriptDir, protocol, side)
1058 if err := os.MkdirAll(dir, 0755); err != nil {
1059 return err
1060 }
1061 transcriptPrefix = filepath.Join(dir, test.name+"-")
1062 flags = append(flags, "-write-settings", transcriptPrefix)
1063 }
1064
David Benjamin025b3d32014-07-01 19:53:04 -04001065 flags = append(flags, test.flags...)
1066
1067 var shim *exec.Cmd
1068 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001069 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001070 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001071 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001072 } else if *useLLDB {
1073 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001074 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001075 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001076 }
David Benjamin025b3d32014-07-01 19:53:04 -04001077 shim.Stdin = os.Stdin
1078 var stdoutBuf, stderrBuf bytes.Buffer
1079 shim.Stdout = &stdoutBuf
1080 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001081 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001082 shim.Env = os.Environ()
1083 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001084 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001085 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001086 }
1087 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1088 }
David Benjamin025b3d32014-07-01 19:53:04 -04001089
1090 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001091 panic(err)
1092 }
David Benjamin87c8a642015-02-21 01:54:29 -05001093 waitChan := make(chan error, 1)
1094 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001095
1096 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001097
David Benjamin7a4aaa42016-09-20 17:58:14 -04001098 if *deterministic {
1099 config.Rand = &deterministicRand{}
1100 }
1101
David Benjamin87c8a642015-02-21 01:54:29 -05001102 conn, err := acceptOrWait(listener, waitChan)
1103 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001104 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001105 conn.Close()
1106 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001107
David Benjamin46662482016-08-17 00:51:00 -04001108 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001109 var resumeConfig Config
1110 if test.resumeConfig != nil {
1111 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001112 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001113 resumeConfig.SessionTicketKey = config.SessionTicketKey
1114 resumeConfig.ClientSessionCache = config.ClientSessionCache
1115 resumeConfig.ServerSessionCache = config.ServerSessionCache
1116 }
David Benjamin2e045a92016-06-08 13:09:56 -04001117 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001118 } else {
1119 resumeConfig = config
1120 }
David Benjamin87c8a642015-02-21 01:54:29 -05001121 var connResume net.Conn
1122 connResume, err = acceptOrWait(listener, waitChan)
1123 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001124 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001125 connResume.Close()
1126 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001127 }
1128
David Benjamin87c8a642015-02-21 01:54:29 -05001129 // Close the listener now. This is to avoid hangs should the shim try to
1130 // open more connections than expected.
1131 listener.Close()
1132 listener = nil
1133
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001134 var shimKilledLock sync.Mutex
1135 var shimKilled bool
1136 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1137 shimKilledLock.Lock()
1138 shimKilled = true
1139 shimKilledLock.Unlock()
1140 shim.Process.Kill()
1141 })
David Benjamin87c8a642015-02-21 01:54:29 -05001142 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001143 waitTimeout.Stop()
1144 shimKilledLock.Lock()
1145 if shimKilled && err == nil {
1146 err = errors.New("timeout waiting for the shim to exit.")
1147 }
1148 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001149 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001150 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001151 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1152 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001153 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001154 case 89:
1155 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001156 case 99:
1157 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001158 }
1159 }
Adam Langley95c29f32014-06-20 12:00:00 -07001160
David Benjamin9bea3492016-03-02 10:59:16 -05001161 // Account for Windows line endings.
1162 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1163 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001164
1165 // Separate the errors from the shim and those from tools like
1166 // AddressSanitizer.
1167 var extraStderr string
1168 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1169 stderr = stderrParts[0]
1170 extraStderr = stderrParts[1]
1171 }
1172
Adam Langley95c29f32014-06-20 12:00:00 -07001173 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001174 expectedError := translateExpectedError(test.expectedError)
1175 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001176
Adam Langleyac61fa32014-06-23 12:03:11 -07001177 localError := "none"
1178 if err != nil {
1179 localError = err.Error()
1180 }
1181 if len(test.expectedLocalError) != 0 {
1182 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1183 }
Adam Langley95c29f32014-06-20 12:00:00 -07001184
1185 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001186 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001187 if childErr != nil {
1188 childError = childErr.Error()
1189 }
1190
1191 var msg string
1192 switch {
1193 case failed && !test.shouldFail:
1194 msg = "unexpected failure"
1195 case !failed && test.shouldFail:
1196 msg = "unexpected success"
1197 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001198 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001199 default:
1200 panic("internal error")
1201 }
1202
David Benjamin9aafb642016-09-20 19:36:53 -04001203 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 -07001204 }
1205
David Benjamind2ba8892016-09-20 19:41:04 -04001206 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001207 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001208 }
1209
David Benjamind2ba8892016-09-20 19:41:04 -04001210 if *useValgrind && isValgrindError {
1211 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1212 }
1213
Adam Langley95c29f32014-06-20 12:00:00 -07001214 return nil
1215}
1216
David Benjaminaa012042016-12-10 13:33:05 -05001217type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001218 name string
1219 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001220 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001221 // excludeFlag is the legacy shim flag to disable the version.
1222 excludeFlag string
1223 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001224 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1225 versionDTLS uint16
1226 // versionWire, if non-zero, is the wire representation of the
1227 // version. Otherwise the wire version is the protocol version or
1228 // versionDTLS.
1229 versionWire uint16
1230 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001231}
1232
1233func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001234 // The shim uses the protocol version in its public API, but uses the
1235 // DTLS-specific version if it exists.
1236 if protocol == dtls && vers.versionDTLS != 0 {
1237 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001238 }
Steven Valdez520e1222017-06-13 12:45:25 -04001239 return strconv.Itoa(int(vers.version))
1240}
1241
1242func (vers tlsVersion) wire(protocol protocol) uint16 {
1243 if protocol == dtls && vers.versionDTLS != 0 {
1244 return vers.versionDTLS
1245 }
1246 if vers.versionWire != 0 {
1247 return vers.versionWire
1248 }
1249 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001250}
1251
1252var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001253 {
1254 name: "SSL3",
1255 version: VersionSSL30,
1256 excludeFlag: "-no-ssl3",
1257 },
1258 {
1259 name: "TLS1",
1260 version: VersionTLS10,
1261 excludeFlag: "-no-tls1",
1262 hasDTLS: true,
1263 versionDTLS: VersionDTLS10,
1264 },
1265 {
1266 name: "TLS11",
1267 version: VersionTLS11,
1268 excludeFlag: "-no-tls11",
1269 },
1270 {
1271 name: "TLS12",
1272 version: VersionTLS12,
1273 excludeFlag: "-no-tls12",
1274 hasDTLS: true,
1275 versionDTLS: VersionDTLS12,
1276 },
1277 {
1278 name: "TLS13",
1279 version: VersionTLS13,
1280 excludeFlag: "-no-tls13",
1281 versionWire: tls13DraftVersion,
1282 tls13Variant: TLS13Default,
1283 },
1284 {
1285 name: "TLS13Experiment",
1286 version: VersionTLS13,
1287 excludeFlag: "-no-tls13",
1288 versionWire: tls13ExperimentVersion,
1289 tls13Variant: TLS13Experiment,
1290 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001291 {
1292 name: "TLS13RecordTypeExperiment",
1293 version: VersionTLS13,
1294 excludeFlag: "-no-tls13",
1295 versionWire: tls13RecordTypeExperimentVersion,
1296 tls13Variant: TLS13RecordTypeExperiment,
1297 },
Steven Valdez520e1222017-06-13 12:45:25 -04001298}
1299
1300func allVersions(protocol protocol) []tlsVersion {
1301 if protocol == tls {
1302 return tlsVersions
1303 }
1304
1305 var ret []tlsVersion
1306 for _, vers := range tlsVersions {
1307 if vers.hasDTLS {
1308 ret = append(ret, vers)
1309 }
1310 }
1311 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001312}
1313
David Benjaminaa012042016-12-10 13:33:05 -05001314type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001315 name string
1316 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001317}
1318
1319var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001320 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001321 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001322 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001323 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001324 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001325 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001326 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001327 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1328 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001329 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1330 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001331 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001332 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001333 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001334 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001335 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001336 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001337 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001338 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001339 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001340 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001341 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1342 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001343 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1344 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001345 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001346 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1347 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1348 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001349 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001350}
1351
David Benjamin8b8c0062014-11-23 02:47:52 -05001352func hasComponent(suiteName, component string) bool {
1353 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1354}
1355
David Benjaminf7768e42014-08-31 02:06:47 -04001356func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001357 return hasComponent(suiteName, "GCM") ||
1358 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001359 hasComponent(suiteName, "SHA384") ||
1360 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001361}
1362
Nick Harper1fd39d82016-06-14 18:14:35 -07001363func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001364 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001365}
1366
David Benjamin8b8c0062014-11-23 02:47:52 -05001367func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001368 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001369}
1370
Adam Langleya7997f12015-05-14 17:38:50 -07001371func bigFromHex(hex string) *big.Int {
1372 ret, ok := new(big.Int).SetString(hex, 16)
1373 if !ok {
1374 panic("failed to parse hex number 0x" + hex)
1375 }
1376 return ret
1377}
1378
Adam Langley7c803a62015-06-15 15:35:05 -07001379func addBasicTests() {
1380 basicTests := []testCase{
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 name: "NoFallbackSCSV",
1383 config: Config{
1384 Bugs: ProtocolBugs{
1385 FailIfNotFallbackSCSV: true,
1386 },
1387 },
1388 shouldFail: true,
1389 expectedLocalError: "no fallback SCSV found",
1390 },
1391 {
1392 name: "SendFallbackSCSV",
1393 config: Config{
1394 Bugs: ProtocolBugs{
1395 FailIfNotFallbackSCSV: true,
1396 },
1397 },
1398 flags: []string{"-fallback-scsv"},
1399 },
1400 {
1401 name: "ClientCertificateTypes",
1402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001403 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001404 ClientAuth: RequestClientCert,
1405 ClientCertificateTypes: []byte{
1406 CertTypeDSSSign,
1407 CertTypeRSASign,
1408 CertTypeECDSASign,
1409 },
1410 },
1411 flags: []string{
1412 "-expect-certificate-types",
1413 base64.StdEncoding.EncodeToString([]byte{
1414 CertTypeDSSSign,
1415 CertTypeRSASign,
1416 CertTypeECDSASign,
1417 }),
1418 },
1419 },
1420 {
Adam Langley7c803a62015-06-15 15:35:05 -07001421 name: "UnauthenticatedECDH",
1422 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001423 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1425 Bugs: ProtocolBugs{
1426 UnauthenticatedECDH: true,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":UNEXPECTED_MESSAGE:",
1431 },
1432 {
1433 name: "SkipCertificateStatus",
1434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001435 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001436 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1437 Bugs: ProtocolBugs{
1438 SkipCertificateStatus: true,
1439 },
1440 },
1441 flags: []string{
1442 "-enable-ocsp-stapling",
1443 },
1444 },
1445 {
1446 name: "SkipServerKeyExchange",
1447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001448 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001449 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1450 Bugs: ProtocolBugs{
1451 SkipServerKeyExchange: true,
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":UNEXPECTED_MESSAGE:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 testType: serverTest,
1459 name: "Alert",
1460 config: Config{
1461 Bugs: ProtocolBugs{
1462 SendSpuriousAlert: alertRecordOverflow,
1463 },
1464 },
1465 shouldFail: true,
1466 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1467 },
1468 {
1469 protocol: dtls,
1470 testType: serverTest,
1471 name: "Alert-DTLS",
1472 config: Config{
1473 Bugs: ProtocolBugs{
1474 SendSpuriousAlert: alertRecordOverflow,
1475 },
1476 },
1477 shouldFail: true,
1478 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1479 },
1480 {
1481 testType: serverTest,
1482 name: "FragmentAlert",
1483 config: Config{
1484 Bugs: ProtocolBugs{
1485 FragmentAlert: true,
1486 SendSpuriousAlert: alertRecordOverflow,
1487 },
1488 },
1489 shouldFail: true,
1490 expectedError: ":BAD_ALERT:",
1491 },
1492 {
1493 protocol: dtls,
1494 testType: serverTest,
1495 name: "FragmentAlert-DTLS",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 FragmentAlert: true,
1499 SendSpuriousAlert: alertRecordOverflow,
1500 },
1501 },
1502 shouldFail: true,
1503 expectedError: ":BAD_ALERT:",
1504 },
1505 {
1506 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001507 name: "DoubleAlert",
1508 config: Config{
1509 Bugs: ProtocolBugs{
1510 DoubleAlert: true,
1511 SendSpuriousAlert: alertRecordOverflow,
1512 },
1513 },
1514 shouldFail: true,
1515 expectedError: ":BAD_ALERT:",
1516 },
1517 {
1518 protocol: dtls,
1519 testType: serverTest,
1520 name: "DoubleAlert-DTLS",
1521 config: Config{
1522 Bugs: ProtocolBugs{
1523 DoubleAlert: true,
1524 SendSpuriousAlert: alertRecordOverflow,
1525 },
1526 },
1527 shouldFail: true,
1528 expectedError: ":BAD_ALERT:",
1529 },
1530 {
Adam Langley7c803a62015-06-15 15:35:05 -07001531 name: "SkipNewSessionTicket",
1532 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001533 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001534 Bugs: ProtocolBugs{
1535 SkipNewSessionTicket: true,
1536 },
1537 },
1538 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001539 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001540 },
1541 {
1542 testType: serverTest,
1543 name: "FallbackSCSV",
1544 config: Config{
1545 MaxVersion: VersionTLS11,
1546 Bugs: ProtocolBugs{
1547 SendFallbackSCSV: true,
1548 },
1549 },
David Benjamin56cadc32016-12-16 19:54:11 -05001550 shouldFail: true,
1551 expectedError: ":INAPPROPRIATE_FALLBACK:",
1552 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001553 },
1554 {
1555 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001556 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001557 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001558 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001559 Bugs: ProtocolBugs{
1560 SendFallbackSCSV: true,
1561 },
1562 },
1563 },
1564 {
1565 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001566 name: "FallbackSCSV-VersionMatch-TLS12",
1567 config: Config{
1568 MaxVersion: VersionTLS12,
1569 Bugs: ProtocolBugs{
1570 SendFallbackSCSV: true,
1571 },
1572 },
1573 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1574 },
1575 {
1576 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001577 name: "FragmentedClientVersion",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 MaxHandshakeRecordLength: 1,
1581 FragmentClientVersion: true,
1582 },
1583 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001584 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 testType: serverTest,
1588 name: "HttpGET",
1589 sendPrefix: "GET / HTTP/1.0\n",
1590 shouldFail: true,
1591 expectedError: ":HTTP_REQUEST:",
1592 },
1593 {
1594 testType: serverTest,
1595 name: "HttpPOST",
1596 sendPrefix: "POST / HTTP/1.0\n",
1597 shouldFail: true,
1598 expectedError: ":HTTP_REQUEST:",
1599 },
1600 {
1601 testType: serverTest,
1602 name: "HttpHEAD",
1603 sendPrefix: "HEAD / HTTP/1.0\n",
1604 shouldFail: true,
1605 expectedError: ":HTTP_REQUEST:",
1606 },
1607 {
1608 testType: serverTest,
1609 name: "HttpPUT",
1610 sendPrefix: "PUT / HTTP/1.0\n",
1611 shouldFail: true,
1612 expectedError: ":HTTP_REQUEST:",
1613 },
1614 {
1615 testType: serverTest,
1616 name: "HttpCONNECT",
1617 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1618 shouldFail: true,
1619 expectedError: ":HTTPS_PROXY_REQUEST:",
1620 },
1621 {
1622 testType: serverTest,
1623 name: "Garbage",
1624 sendPrefix: "blah",
1625 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001626 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001627 },
1628 {
Adam Langley7c803a62015-06-15 15:35:05 -07001629 name: "RSAEphemeralKey",
1630 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001631 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001632 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1633 Bugs: ProtocolBugs{
1634 RSAEphemeralKey: true,
1635 },
1636 },
1637 shouldFail: true,
1638 expectedError: ":UNEXPECTED_MESSAGE:",
1639 },
1640 {
1641 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001642 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001643 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001644 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001645 },
1646 {
1647 protocol: dtls,
1648 name: "DisableEverything-DTLS",
1649 flags: []string{"-no-tls12", "-no-tls1"},
1650 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001651 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001652 },
1653 {
Adam Langley7c803a62015-06-15 15:35:05 -07001654 protocol: dtls,
1655 testType: serverTest,
1656 name: "MTU",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 MaxPacketLength: 256,
1660 },
1661 },
1662 flags: []string{"-mtu", "256"},
1663 },
1664 {
1665 protocol: dtls,
1666 testType: serverTest,
1667 name: "MTUExceeded",
1668 config: Config{
1669 Bugs: ProtocolBugs{
1670 MaxPacketLength: 255,
1671 },
1672 },
1673 flags: []string{"-mtu", "256"},
1674 shouldFail: true,
1675 expectedLocalError: "dtls: exceeded maximum packet length",
1676 },
1677 {
Adam Langley7c803a62015-06-15 15:35:05 -07001678 name: "EmptyCertificateList",
1679 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001680 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001681 Bugs: ProtocolBugs{
1682 EmptyCertificateList: true,
1683 },
1684 },
1685 shouldFail: true,
1686 expectedError: ":DECODE_ERROR:",
1687 },
1688 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001689 name: "EmptyCertificateList-TLS13",
1690 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001691 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001692 Bugs: ProtocolBugs{
1693 EmptyCertificateList: true,
1694 },
1695 },
1696 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001697 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001698 },
1699 {
Adam Langley7c803a62015-06-15 15:35:05 -07001700 name: "TLSFatalBadPackets",
1701 damageFirstWrite: true,
1702 shouldFail: true,
1703 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1704 },
1705 {
1706 protocol: dtls,
1707 name: "DTLSIgnoreBadPackets",
1708 damageFirstWrite: true,
1709 },
1710 {
1711 protocol: dtls,
1712 name: "DTLSIgnoreBadPackets-Async",
1713 damageFirstWrite: true,
1714 flags: []string{"-async"},
1715 },
1716 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001717 name: "AppDataBeforeHandshake",
1718 config: Config{
1719 Bugs: ProtocolBugs{
1720 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1721 },
1722 },
1723 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001724 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001725 },
1726 {
1727 name: "AppDataBeforeHandshake-Empty",
1728 config: Config{
1729 Bugs: ProtocolBugs{
1730 AppDataBeforeHandshake: []byte{},
1731 },
1732 },
1733 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001734 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001735 },
1736 {
1737 protocol: dtls,
1738 name: "AppDataBeforeHandshake-DTLS",
1739 config: Config{
1740 Bugs: ProtocolBugs{
1741 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1742 },
1743 },
1744 shouldFail: true,
1745 expectedError: ":UNEXPECTED_RECORD:",
1746 },
1747 {
1748 protocol: dtls,
1749 name: "AppDataBeforeHandshake-DTLS-Empty",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 AppDataBeforeHandshake: []byte{},
1753 },
1754 },
1755 shouldFail: true,
1756 expectedError: ":UNEXPECTED_RECORD:",
1757 },
1758 {
Adam Langley7c803a62015-06-15 15:35:05 -07001759 name: "AppDataAfterChangeCipherSpec",
1760 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001761 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001762 Bugs: ProtocolBugs{
1763 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1764 },
1765 },
1766 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001767 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001768 },
1769 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001770 name: "AppDataAfterChangeCipherSpec-Empty",
1771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001772 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001773 Bugs: ProtocolBugs{
1774 AppDataAfterChangeCipherSpec: []byte{},
1775 },
1776 },
1777 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001778 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001779 },
1780 {
Adam Langley7c803a62015-06-15 15:35:05 -07001781 protocol: dtls,
1782 name: "AppDataAfterChangeCipherSpec-DTLS",
1783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001784 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001785 Bugs: ProtocolBugs{
1786 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1787 },
1788 },
1789 // BoringSSL's DTLS implementation will drop the out-of-order
1790 // application data.
1791 },
1792 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001793 protocol: dtls,
1794 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1795 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001796 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001797 Bugs: ProtocolBugs{
1798 AppDataAfterChangeCipherSpec: []byte{},
1799 },
1800 },
1801 // BoringSSL's DTLS implementation will drop the out-of-order
1802 // application data.
1803 },
1804 {
Adam Langley7c803a62015-06-15 15:35:05 -07001805 name: "AlertAfterChangeCipherSpec",
1806 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001807 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001808 Bugs: ProtocolBugs{
1809 AlertAfterChangeCipherSpec: alertRecordOverflow,
1810 },
1811 },
1812 shouldFail: true,
1813 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1814 },
1815 {
1816 protocol: dtls,
1817 name: "AlertAfterChangeCipherSpec-DTLS",
1818 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001819 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001820 Bugs: ProtocolBugs{
1821 AlertAfterChangeCipherSpec: alertRecordOverflow,
1822 },
1823 },
1824 shouldFail: true,
1825 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1826 },
1827 {
1828 protocol: dtls,
1829 name: "ReorderHandshakeFragments-Small-DTLS",
1830 config: Config{
1831 Bugs: ProtocolBugs{
1832 ReorderHandshakeFragments: true,
1833 // Small enough that every handshake message is
1834 // fragmented.
1835 MaxHandshakeRecordLength: 2,
1836 },
1837 },
1838 },
1839 {
1840 protocol: dtls,
1841 name: "ReorderHandshakeFragments-Large-DTLS",
1842 config: Config{
1843 Bugs: ProtocolBugs{
1844 ReorderHandshakeFragments: true,
1845 // Large enough that no handshake message is
1846 // fragmented.
1847 MaxHandshakeRecordLength: 2048,
1848 },
1849 },
1850 },
1851 {
1852 protocol: dtls,
1853 name: "MixCompleteMessageWithFragments-DTLS",
1854 config: Config{
1855 Bugs: ProtocolBugs{
1856 ReorderHandshakeFragments: true,
1857 MixCompleteMessageWithFragments: true,
1858 MaxHandshakeRecordLength: 2,
1859 },
1860 },
1861 },
1862 {
1863 name: "SendInvalidRecordType",
1864 config: Config{
1865 Bugs: ProtocolBugs{
1866 SendInvalidRecordType: true,
1867 },
1868 },
1869 shouldFail: true,
1870 expectedError: ":UNEXPECTED_RECORD:",
1871 },
1872 {
1873 protocol: dtls,
1874 name: "SendInvalidRecordType-DTLS",
1875 config: Config{
1876 Bugs: ProtocolBugs{
1877 SendInvalidRecordType: true,
1878 },
1879 },
1880 shouldFail: true,
1881 expectedError: ":UNEXPECTED_RECORD:",
1882 },
1883 {
1884 name: "FalseStart-SkipServerSecondLeg",
1885 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001886 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1888 NextProtos: []string{"foo"},
1889 Bugs: ProtocolBugs{
1890 SkipNewSessionTicket: true,
1891 SkipChangeCipherSpec: true,
1892 SkipFinished: true,
1893 ExpectFalseStart: true,
1894 },
1895 },
1896 flags: []string{
1897 "-false-start",
1898 "-handshake-never-done",
1899 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001900 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001901 },
1902 shimWritesFirst: true,
1903 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001904 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001905 },
1906 {
1907 name: "FalseStart-SkipServerSecondLeg-Implicit",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 SkipNewSessionTicket: true,
1914 SkipChangeCipherSpec: true,
1915 SkipFinished: true,
1916 },
1917 },
1918 flags: []string{
1919 "-implicit-handshake",
1920 "-false-start",
1921 "-handshake-never-done",
1922 "-advertise-alpn", "\x03foo",
1923 },
1924 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001925 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001926 },
1927 {
1928 testType: serverTest,
1929 name: "FailEarlyCallback",
1930 flags: []string{"-fail-early-callback"},
1931 shouldFail: true,
1932 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001933 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001934 },
1935 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001936 name: "FailCertCallback-Client-TLS12",
1937 config: Config{
1938 MaxVersion: VersionTLS12,
1939 ClientAuth: RequestClientCert,
1940 },
1941 flags: []string{"-fail-cert-callback"},
1942 shouldFail: true,
1943 expectedError: ":CERT_CB_ERROR:",
1944 expectedLocalError: "remote error: internal error",
1945 },
1946 {
1947 testType: serverTest,
1948 name: "FailCertCallback-Server-TLS12",
1949 config: Config{
1950 MaxVersion: VersionTLS12,
1951 },
1952 flags: []string{"-fail-cert-callback"},
1953 shouldFail: true,
1954 expectedError: ":CERT_CB_ERROR:",
1955 expectedLocalError: "remote error: internal error",
1956 },
1957 {
1958 name: "FailCertCallback-Client-TLS13",
1959 config: Config{
1960 MaxVersion: VersionTLS13,
1961 ClientAuth: RequestClientCert,
1962 },
1963 flags: []string{"-fail-cert-callback"},
1964 shouldFail: true,
1965 expectedError: ":CERT_CB_ERROR:",
1966 expectedLocalError: "remote error: internal error",
1967 },
1968 {
1969 testType: serverTest,
1970 name: "FailCertCallback-Server-TLS13",
1971 config: Config{
1972 MaxVersion: VersionTLS13,
1973 },
1974 flags: []string{"-fail-cert-callback"},
1975 shouldFail: true,
1976 expectedError: ":CERT_CB_ERROR:",
1977 expectedLocalError: "remote error: internal error",
1978 },
1979 {
Adam Langley7c803a62015-06-15 15:35:05 -07001980 protocol: dtls,
1981 name: "FragmentMessageTypeMismatch-DTLS",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 MaxHandshakeRecordLength: 2,
1985 FragmentMessageTypeMismatch: true,
1986 },
1987 },
1988 shouldFail: true,
1989 expectedError: ":FRAGMENT_MISMATCH:",
1990 },
1991 {
1992 protocol: dtls,
1993 name: "FragmentMessageLengthMismatch-DTLS",
1994 config: Config{
1995 Bugs: ProtocolBugs{
1996 MaxHandshakeRecordLength: 2,
1997 FragmentMessageLengthMismatch: true,
1998 },
1999 },
2000 shouldFail: true,
2001 expectedError: ":FRAGMENT_MISMATCH:",
2002 },
2003 {
2004 protocol: dtls,
2005 name: "SplitFragments-Header-DTLS",
2006 config: Config{
2007 Bugs: ProtocolBugs{
2008 SplitFragments: 2,
2009 },
2010 },
2011 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002012 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002013 },
2014 {
2015 protocol: dtls,
2016 name: "SplitFragments-Boundary-DTLS",
2017 config: Config{
2018 Bugs: ProtocolBugs{
2019 SplitFragments: dtlsRecordHeaderLen,
2020 },
2021 },
2022 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002023 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002024 },
2025 {
2026 protocol: dtls,
2027 name: "SplitFragments-Body-DTLS",
2028 config: Config{
2029 Bugs: ProtocolBugs{
2030 SplitFragments: dtlsRecordHeaderLen + 1,
2031 },
2032 },
2033 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002034 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002035 },
2036 {
2037 protocol: dtls,
2038 name: "SendEmptyFragments-DTLS",
2039 config: Config{
2040 Bugs: ProtocolBugs{
2041 SendEmptyFragments: true,
2042 },
2043 },
2044 },
2045 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002046 name: "BadFinished-Client",
2047 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002048 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002049 Bugs: ProtocolBugs{
2050 BadFinished: true,
2051 },
2052 },
2053 shouldFail: true,
2054 expectedError: ":DIGEST_CHECK_FAILED:",
2055 },
2056 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002057 name: "BadFinished-Client-TLS13",
2058 config: Config{
2059 MaxVersion: VersionTLS13,
2060 Bugs: ProtocolBugs{
2061 BadFinished: true,
2062 },
2063 },
2064 shouldFail: true,
2065 expectedError: ":DIGEST_CHECK_FAILED:",
2066 },
2067 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002068 testType: serverTest,
2069 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002071 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002072 Bugs: ProtocolBugs{
2073 BadFinished: true,
2074 },
2075 },
2076 shouldFail: true,
2077 expectedError: ":DIGEST_CHECK_FAILED:",
2078 },
2079 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002080 testType: serverTest,
2081 name: "BadFinished-Server-TLS13",
2082 config: Config{
2083 MaxVersion: VersionTLS13,
2084 Bugs: ProtocolBugs{
2085 BadFinished: true,
2086 },
2087 },
2088 shouldFail: true,
2089 expectedError: ":DIGEST_CHECK_FAILED:",
2090 },
2091 {
Adam Langley7c803a62015-06-15 15:35:05 -07002092 name: "FalseStart-BadFinished",
2093 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002094 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002095 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2096 NextProtos: []string{"foo"},
2097 Bugs: ProtocolBugs{
2098 BadFinished: true,
2099 ExpectFalseStart: true,
2100 },
2101 },
2102 flags: []string{
2103 "-false-start",
2104 "-handshake-never-done",
2105 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002106 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002107 },
2108 shimWritesFirst: true,
2109 shouldFail: true,
2110 expectedError: ":DIGEST_CHECK_FAILED:",
2111 },
2112 {
2113 name: "NoFalseStart-NoALPN",
2114 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002115 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2117 Bugs: ProtocolBugs{
2118 ExpectFalseStart: true,
2119 AlertBeforeFalseStartTest: alertAccessDenied,
2120 },
2121 },
2122 flags: []string{
2123 "-false-start",
2124 },
2125 shimWritesFirst: true,
2126 shouldFail: true,
2127 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2128 expectedLocalError: "tls: peer did not false start: EOF",
2129 },
2130 {
2131 name: "NoFalseStart-NoAEAD",
2132 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002133 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002134 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2135 NextProtos: []string{"foo"},
2136 Bugs: ProtocolBugs{
2137 ExpectFalseStart: true,
2138 AlertBeforeFalseStartTest: alertAccessDenied,
2139 },
2140 },
2141 flags: []string{
2142 "-false-start",
2143 "-advertise-alpn", "\x03foo",
2144 },
2145 shimWritesFirst: true,
2146 shouldFail: true,
2147 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2148 expectedLocalError: "tls: peer did not false start: EOF",
2149 },
2150 {
2151 name: "NoFalseStart-RSA",
2152 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002153 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002154 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2155 NextProtos: []string{"foo"},
2156 Bugs: ProtocolBugs{
2157 ExpectFalseStart: true,
2158 AlertBeforeFalseStartTest: alertAccessDenied,
2159 },
2160 },
2161 flags: []string{
2162 "-false-start",
2163 "-advertise-alpn", "\x03foo",
2164 },
2165 shimWritesFirst: true,
2166 shouldFail: true,
2167 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2168 expectedLocalError: "tls: peer did not false start: EOF",
2169 },
2170 {
Adam Langley7c803a62015-06-15 15:35:05 -07002171 protocol: dtls,
2172 name: "SendSplitAlert-Sync",
2173 config: Config{
2174 Bugs: ProtocolBugs{
2175 SendSplitAlert: true,
2176 },
2177 },
2178 },
2179 {
2180 protocol: dtls,
2181 name: "SendSplitAlert-Async",
2182 config: Config{
2183 Bugs: ProtocolBugs{
2184 SendSplitAlert: true,
2185 },
2186 },
2187 flags: []string{"-async"},
2188 },
2189 {
2190 protocol: dtls,
2191 name: "PackDTLSHandshake",
2192 config: Config{
2193 Bugs: ProtocolBugs{
2194 MaxHandshakeRecordLength: 2,
2195 PackHandshakeFragments: 20,
2196 PackHandshakeRecords: 200,
2197 },
2198 },
2199 },
2200 {
Adam Langley7c803a62015-06-15 15:35:05 -07002201 name: "SendEmptyRecords-Pass",
2202 sendEmptyRecords: 32,
2203 },
2204 {
2205 name: "SendEmptyRecords",
2206 sendEmptyRecords: 33,
2207 shouldFail: true,
2208 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2209 },
2210 {
2211 name: "SendEmptyRecords-Async",
2212 sendEmptyRecords: 33,
2213 flags: []string{"-async"},
2214 shouldFail: true,
2215 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2216 },
2217 {
David Benjamine8e84b92016-08-03 15:39:47 -04002218 name: "SendWarningAlerts-Pass",
2219 config: Config{
2220 MaxVersion: VersionTLS12,
2221 },
Adam Langley7c803a62015-06-15 15:35:05 -07002222 sendWarningAlerts: 4,
2223 },
2224 {
David Benjamine8e84b92016-08-03 15:39:47 -04002225 protocol: dtls,
2226 name: "SendWarningAlerts-DTLS-Pass",
2227 config: Config{
2228 MaxVersion: VersionTLS12,
2229 },
Adam Langley7c803a62015-06-15 15:35:05 -07002230 sendWarningAlerts: 4,
2231 },
2232 {
David Benjamine8e84b92016-08-03 15:39:47 -04002233 name: "SendWarningAlerts-TLS13",
2234 config: Config{
2235 MaxVersion: VersionTLS13,
2236 },
2237 sendWarningAlerts: 4,
2238 shouldFail: true,
2239 expectedError: ":BAD_ALERT:",
2240 expectedLocalError: "remote error: error decoding message",
2241 },
2242 {
2243 name: "SendWarningAlerts",
2244 config: Config{
2245 MaxVersion: VersionTLS12,
2246 },
Adam Langley7c803a62015-06-15 15:35:05 -07002247 sendWarningAlerts: 5,
2248 shouldFail: true,
2249 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2250 },
2251 {
David Benjamine8e84b92016-08-03 15:39:47 -04002252 name: "SendWarningAlerts-Async",
2253 config: Config{
2254 MaxVersion: VersionTLS12,
2255 },
Adam Langley7c803a62015-06-15 15:35:05 -07002256 sendWarningAlerts: 5,
2257 flags: []string{"-async"},
2258 shouldFail: true,
2259 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2260 },
David Benjaminba4594a2015-06-18 18:36:15 -04002261 {
David Benjamin24e58862017-06-14 18:45:29 -04002262 name: "SendBogusAlertType",
2263 sendBogusAlertType: true,
2264 shouldFail: true,
2265 expectedError: ":UNKNOWN_ALERT_TYPE:",
2266 expectedLocalError: "remote error: illegal parameter",
2267 },
2268 {
2269 protocol: dtls,
2270 name: "SendBogusAlertType-DTLS",
2271 sendBogusAlertType: true,
2272 shouldFail: true,
2273 expectedError: ":UNKNOWN_ALERT_TYPE:",
2274 expectedLocalError: "remote error: illegal parameter",
2275 },
2276 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002277 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002278 config: Config{
2279 MaxVersion: VersionTLS13,
2280 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002281 sendKeyUpdates: 33,
2282 keyUpdateRequest: keyUpdateNotRequested,
2283 shouldFail: true,
2284 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002285 },
2286 {
David Benjaminba4594a2015-06-18 18:36:15 -04002287 name: "EmptySessionID",
2288 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002289 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002290 SessionTicketsDisabled: true,
2291 },
2292 noSessionCache: true,
2293 flags: []string{"-expect-no-session"},
2294 },
David Benjamin30789da2015-08-29 22:56:45 -04002295 {
2296 name: "Unclean-Shutdown",
2297 config: Config{
2298 Bugs: ProtocolBugs{
2299 NoCloseNotify: true,
2300 ExpectCloseNotify: true,
2301 },
2302 },
2303 shimShutsDown: true,
2304 flags: []string{"-check-close-notify"},
2305 shouldFail: true,
2306 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2307 },
2308 {
2309 name: "Unclean-Shutdown-Ignored",
2310 config: Config{
2311 Bugs: ProtocolBugs{
2312 NoCloseNotify: true,
2313 },
2314 },
2315 shimShutsDown: true,
2316 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002317 {
David Benjaminfa214e42016-05-10 17:03:10 -04002318 name: "Unclean-Shutdown-Alert",
2319 config: Config{
2320 Bugs: ProtocolBugs{
2321 SendAlertOnShutdown: alertDecompressionFailure,
2322 ExpectCloseNotify: true,
2323 },
2324 },
2325 shimShutsDown: true,
2326 flags: []string{"-check-close-notify"},
2327 shouldFail: true,
2328 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2329 },
2330 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002331 name: "LargePlaintext",
2332 config: Config{
2333 Bugs: ProtocolBugs{
2334 SendLargeRecords: true,
2335 },
2336 },
2337 messageLen: maxPlaintext + 1,
2338 shouldFail: true,
2339 expectedError: ":DATA_LENGTH_TOO_LONG:",
2340 },
2341 {
2342 protocol: dtls,
2343 name: "LargePlaintext-DTLS",
2344 config: Config{
2345 Bugs: ProtocolBugs{
2346 SendLargeRecords: true,
2347 },
2348 },
2349 messageLen: maxPlaintext + 1,
2350 shouldFail: true,
2351 expectedError: ":DATA_LENGTH_TOO_LONG:",
2352 },
2353 {
2354 name: "LargeCiphertext",
2355 config: Config{
2356 Bugs: ProtocolBugs{
2357 SendLargeRecords: true,
2358 },
2359 },
2360 messageLen: maxPlaintext * 2,
2361 shouldFail: true,
2362 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2363 },
2364 {
2365 protocol: dtls,
2366 name: "LargeCiphertext-DTLS",
2367 config: Config{
2368 Bugs: ProtocolBugs{
2369 SendLargeRecords: true,
2370 },
2371 },
2372 messageLen: maxPlaintext * 2,
2373 // Unlike the other four cases, DTLS drops records which
2374 // are invalid before authentication, so the connection
2375 // does not fail.
2376 expectMessageDropped: true,
2377 },
David Benjamindd6fed92015-10-23 17:41:12 -04002378 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002379 name: "BadHelloRequest-1",
2380 renegotiate: 1,
2381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002382 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002383 Bugs: ProtocolBugs{
2384 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2385 },
2386 },
2387 flags: []string{
2388 "-renegotiate-freely",
2389 "-expect-total-renegotiations", "1",
2390 },
2391 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002392 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002393 },
2394 {
2395 name: "BadHelloRequest-2",
2396 renegotiate: 1,
2397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002398 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002399 Bugs: ProtocolBugs{
2400 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2401 },
2402 },
2403 flags: []string{
2404 "-renegotiate-freely",
2405 "-expect-total-renegotiations", "1",
2406 },
2407 shouldFail: true,
2408 expectedError: ":BAD_HELLO_REQUEST:",
2409 },
David Benjaminef1b0092015-11-21 14:05:44 -05002410 {
2411 testType: serverTest,
2412 name: "SupportTicketsWithSessionID",
2413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002414 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002415 SessionTicketsDisabled: true,
2416 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002417 resumeConfig: &Config{
2418 MaxVersion: VersionTLS12,
2419 },
David Benjaminef1b0092015-11-21 14:05:44 -05002420 resumeSession: true,
2421 },
David Benjamin02edcd02016-07-27 17:40:37 -04002422 {
2423 protocol: dtls,
2424 name: "DTLS-SendExtraFinished",
2425 config: Config{
2426 Bugs: ProtocolBugs{
2427 SendExtraFinished: true,
2428 },
2429 },
2430 shouldFail: true,
2431 expectedError: ":UNEXPECTED_RECORD:",
2432 },
2433 {
2434 protocol: dtls,
2435 name: "DTLS-SendExtraFinished-Reordered",
2436 config: Config{
2437 Bugs: ProtocolBugs{
2438 MaxHandshakeRecordLength: 2,
2439 ReorderHandshakeFragments: true,
2440 SendExtraFinished: true,
2441 },
2442 },
2443 shouldFail: true,
2444 expectedError: ":UNEXPECTED_RECORD:",
2445 },
David Benjamine97fb482016-07-29 09:23:07 -04002446 {
2447 testType: serverTest,
2448 name: "V2ClientHello-EmptyRecordPrefix",
2449 config: Config{
2450 // Choose a cipher suite that does not involve
2451 // elliptic curves, so no extensions are
2452 // involved.
2453 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002454 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002455 Bugs: ProtocolBugs{
2456 SendV2ClientHello: true,
2457 },
2458 },
2459 sendPrefix: string([]byte{
2460 byte(recordTypeHandshake),
2461 3, 1, // version
2462 0, 0, // length
2463 }),
2464 // A no-op empty record may not be sent before V2ClientHello.
2465 shouldFail: true,
2466 expectedError: ":WRONG_VERSION_NUMBER:",
2467 },
2468 {
2469 testType: serverTest,
2470 name: "V2ClientHello-WarningAlertPrefix",
2471 config: Config{
2472 // Choose a cipher suite that does not involve
2473 // elliptic curves, so no extensions are
2474 // involved.
2475 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002476 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002477 Bugs: ProtocolBugs{
2478 SendV2ClientHello: true,
2479 },
2480 },
2481 sendPrefix: string([]byte{
2482 byte(recordTypeAlert),
2483 3, 1, // version
2484 0, 2, // length
2485 alertLevelWarning, byte(alertDecompressionFailure),
2486 }),
2487 // A no-op warning alert may not be sent before V2ClientHello.
2488 shouldFail: true,
2489 expectedError: ":WRONG_VERSION_NUMBER:",
2490 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002491 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002492 name: "KeyUpdate-Client",
2493 config: Config{
2494 MaxVersion: VersionTLS13,
2495 },
2496 sendKeyUpdates: 1,
2497 keyUpdateRequest: keyUpdateNotRequested,
2498 },
2499 {
2500 testType: serverTest,
2501 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002502 config: Config{
2503 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002504 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002505 sendKeyUpdates: 1,
2506 keyUpdateRequest: keyUpdateNotRequested,
2507 },
2508 {
2509 name: "KeyUpdate-InvalidRequestMode",
2510 config: Config{
2511 MaxVersion: VersionTLS13,
2512 },
2513 sendKeyUpdates: 1,
2514 keyUpdateRequest: 42,
2515 shouldFail: true,
2516 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002517 },
David Benjaminabe94e32016-09-04 14:18:58 -04002518 {
David Benjaminbbba9392017-04-06 12:54:12 -04002519 // Test that KeyUpdates are acknowledged properly.
2520 name: "KeyUpdate-RequestACK",
2521 config: Config{
2522 MaxVersion: VersionTLS13,
2523 Bugs: ProtocolBugs{
2524 RejectUnsolicitedKeyUpdate: true,
2525 },
2526 },
2527 // Test the shim receiving many KeyUpdates in a row.
2528 sendKeyUpdates: 5,
2529 messageCount: 5,
2530 keyUpdateRequest: keyUpdateRequested,
2531 },
2532 {
2533 // Test that KeyUpdates are acknowledged properly if the
2534 // peer's KeyUpdate is discovered while a write is
2535 // pending.
2536 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2537 config: Config{
2538 MaxVersion: VersionTLS13,
2539 Bugs: ProtocolBugs{
2540 RejectUnsolicitedKeyUpdate: true,
2541 },
2542 },
2543 // Test the shim receiving many KeyUpdates in a row.
2544 sendKeyUpdates: 5,
2545 messageCount: 5,
2546 keyUpdateRequest: keyUpdateRequested,
2547 readWithUnfinishedWrite: true,
2548 flags: []string{"-async"},
2549 },
2550 {
David Benjaminabe94e32016-09-04 14:18:58 -04002551 name: "SendSNIWarningAlert",
2552 config: Config{
2553 MaxVersion: VersionTLS12,
2554 Bugs: ProtocolBugs{
2555 SendSNIWarningAlert: true,
2556 },
2557 },
2558 },
David Benjaminc241d792016-09-09 10:34:20 -04002559 {
2560 testType: serverTest,
2561 name: "ExtraCompressionMethods-TLS12",
2562 config: Config{
2563 MaxVersion: VersionTLS12,
2564 Bugs: ProtocolBugs{
2565 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2566 },
2567 },
2568 },
2569 {
2570 testType: serverTest,
2571 name: "ExtraCompressionMethods-TLS13",
2572 config: Config{
2573 MaxVersion: VersionTLS13,
2574 Bugs: ProtocolBugs{
2575 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2576 },
2577 },
2578 shouldFail: true,
2579 expectedError: ":INVALID_COMPRESSION_LIST:",
2580 expectedLocalError: "remote error: illegal parameter",
2581 },
2582 {
2583 testType: serverTest,
2584 name: "NoNullCompression-TLS12",
2585 config: Config{
2586 MaxVersion: VersionTLS12,
2587 Bugs: ProtocolBugs{
2588 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2589 },
2590 },
2591 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002592 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002593 expectedLocalError: "remote error: illegal parameter",
2594 },
2595 {
2596 testType: serverTest,
2597 name: "NoNullCompression-TLS13",
2598 config: Config{
2599 MaxVersion: VersionTLS13,
2600 Bugs: ProtocolBugs{
2601 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2602 },
2603 },
2604 shouldFail: true,
2605 expectedError: ":INVALID_COMPRESSION_LIST:",
2606 expectedLocalError: "remote error: illegal parameter",
2607 },
David Benjamin413e79e2017-07-01 10:11:53 -04002608 // Test that the client rejects invalid compression methods
2609 // from the server.
2610 {
2611 testType: clientTest,
2612 name: "InvalidCompressionMethod",
2613 config: Config{
2614 MaxVersion: VersionTLS12,
2615 Bugs: ProtocolBugs{
2616 SendCompressionMethod: 1,
2617 },
2618 },
2619 shouldFail: true,
2620 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2621 expectedLocalError: "remote error: illegal parameter",
2622 },
David Benjamin65ac9972016-09-02 21:35:25 -04002623 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002624 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002625 config: Config{
2626 MaxVersion: VersionTLS12,
2627 Bugs: ProtocolBugs{
2628 ExpectGREASE: true,
2629 },
2630 },
2631 flags: []string{"-enable-grease"},
2632 },
2633 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002634 name: "GREASE-Client-TLS13",
2635 config: Config{
2636 MaxVersion: VersionTLS13,
2637 Bugs: ProtocolBugs{
2638 ExpectGREASE: true,
2639 },
2640 },
2641 flags: []string{"-enable-grease"},
2642 },
2643 {
2644 testType: serverTest,
2645 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002646 config: Config{
2647 MaxVersion: VersionTLS13,
2648 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002649 // TLS 1.3 servers are expected to
2650 // always enable GREASE. TLS 1.3 is new,
2651 // so there is no existing ecosystem to
2652 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002653 ExpectGREASE: true,
2654 },
2655 },
David Benjamin65ac9972016-09-02 21:35:25 -04002656 },
David Benjamine3fbb362017-01-06 16:19:28 -05002657 {
2658 // Test the server so there is a large certificate as
2659 // well as application data.
2660 testType: serverTest,
2661 name: "MaxSendFragment",
2662 config: Config{
2663 Bugs: ProtocolBugs{
2664 MaxReceivePlaintext: 512,
2665 },
2666 },
2667 messageLen: 1024,
2668 flags: []string{
2669 "-max-send-fragment", "512",
2670 "-read-size", "1024",
2671 },
2672 },
2673 {
2674 // Test the server so there is a large certificate as
2675 // well as application data.
2676 testType: serverTest,
2677 name: "MaxSendFragment-TooLarge",
2678 config: Config{
2679 Bugs: ProtocolBugs{
2680 // Ensure that some of the records are
2681 // 512.
2682 MaxReceivePlaintext: 511,
2683 },
2684 },
2685 messageLen: 1024,
2686 flags: []string{
2687 "-max-send-fragment", "512",
2688 "-read-size", "1024",
2689 },
2690 shouldFail: true,
2691 expectedLocalError: "local error: record overflow",
2692 },
Adam Langley7c803a62015-06-15 15:35:05 -07002693 }
Adam Langley7c803a62015-06-15 15:35:05 -07002694 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002695
2696 // Test that very large messages can be received.
2697 cert := rsaCertificate
2698 for i := 0; i < 50; i++ {
2699 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2700 }
2701 testCases = append(testCases, testCase{
2702 name: "LargeMessage",
2703 config: Config{
2704 Certificates: []Certificate{cert},
2705 },
2706 })
2707 testCases = append(testCases, testCase{
2708 protocol: dtls,
2709 name: "LargeMessage-DTLS",
2710 config: Config{
2711 Certificates: []Certificate{cert},
2712 },
2713 })
2714
2715 // They are rejected if the maximum certificate chain length is capped.
2716 testCases = append(testCases, testCase{
2717 name: "LargeMessage-Reject",
2718 config: Config{
2719 Certificates: []Certificate{cert},
2720 },
2721 flags: []string{"-max-cert-list", "16384"},
2722 shouldFail: true,
2723 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2724 })
2725 testCases = append(testCases, testCase{
2726 protocol: dtls,
2727 name: "LargeMessage-Reject-DTLS",
2728 config: Config{
2729 Certificates: []Certificate{cert},
2730 },
2731 flags: []string{"-max-cert-list", "16384"},
2732 shouldFail: true,
2733 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2734 })
Adam Langley7c803a62015-06-15 15:35:05 -07002735}
2736
David Benjaminaa012042016-12-10 13:33:05 -05002737func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2738 const psk = "12345"
2739 const pskIdentity = "luggage combo"
2740
2741 var prefix string
2742 if protocol == dtls {
2743 if !ver.hasDTLS {
2744 return
2745 }
2746 prefix = "D"
2747 }
2748
2749 var cert Certificate
2750 var certFile string
2751 var keyFile string
2752 if hasComponent(suite.name, "ECDSA") {
2753 cert = ecdsaP256Certificate
2754 certFile = ecdsaP256CertificateFile
2755 keyFile = ecdsaP256KeyFile
2756 } else {
2757 cert = rsaCertificate
2758 certFile = rsaCertificateFile
2759 keyFile = rsaKeyFile
2760 }
2761
2762 var flags []string
2763 if hasComponent(suite.name, "PSK") {
2764 flags = append(flags,
2765 "-psk", psk,
2766 "-psk-identity", pskIdentity)
2767 }
2768 if hasComponent(suite.name, "NULL") {
2769 // NULL ciphers must be explicitly enabled.
2770 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2771 }
David Benjaminaa012042016-12-10 13:33:05 -05002772
2773 var shouldServerFail, shouldClientFail bool
2774 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2775 // BoringSSL clients accept ECDHE on SSLv3, but
2776 // a BoringSSL server will never select it
2777 // because the extension is missing.
2778 shouldServerFail = true
2779 }
2780 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2781 shouldClientFail = true
2782 shouldServerFail = true
2783 }
2784 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2785 shouldClientFail = true
2786 shouldServerFail = true
2787 }
2788 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2789 shouldClientFail = true
2790 shouldServerFail = true
2791 }
2792 if !isDTLSCipher(suite.name) && protocol == dtls {
2793 shouldClientFail = true
2794 shouldServerFail = true
2795 }
2796
2797 var sendCipherSuite uint16
2798 var expectedServerError, expectedClientError string
2799 serverCipherSuites := []uint16{suite.id}
2800 if shouldServerFail {
2801 expectedServerError = ":NO_SHARED_CIPHER:"
2802 }
2803 if shouldClientFail {
2804 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2805 // Configure the server to select ciphers as normal but
2806 // select an incompatible cipher in ServerHello.
2807 serverCipherSuites = nil
2808 sendCipherSuite = suite.id
2809 }
2810
David Benjamincdb6fe92017-02-07 16:06:48 -05002811 // For cipher suites and versions where exporters are defined, verify
2812 // that they interoperate.
2813 var exportKeyingMaterial int
2814 if ver.version > VersionSSL30 {
2815 exportKeyingMaterial = 1024
2816 }
2817
David Benjaminaa012042016-12-10 13:33:05 -05002818 testCases = append(testCases, testCase{
2819 testType: serverTest,
2820 protocol: protocol,
2821 name: prefix + ver.name + "-" + suite.name + "-server",
2822 config: Config{
2823 MinVersion: ver.version,
2824 MaxVersion: ver.version,
2825 CipherSuites: []uint16{suite.id},
2826 Certificates: []Certificate{cert},
2827 PreSharedKey: []byte(psk),
2828 PreSharedKeyIdentity: pskIdentity,
2829 Bugs: ProtocolBugs{
2830 AdvertiseAllConfiguredCiphers: true,
2831 },
2832 },
David Benjamina5022392017-07-10 17:40:39 -04002833 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002834 certFile: certFile,
2835 keyFile: keyFile,
2836 flags: flags,
2837 resumeSession: true,
2838 shouldFail: shouldServerFail,
2839 expectedError: expectedServerError,
2840 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002841 })
2842
2843 testCases = append(testCases, testCase{
2844 testType: clientTest,
2845 protocol: protocol,
2846 name: prefix + ver.name + "-" + suite.name + "-client",
2847 config: Config{
2848 MinVersion: ver.version,
2849 MaxVersion: ver.version,
2850 CipherSuites: serverCipherSuites,
2851 Certificates: []Certificate{cert},
2852 PreSharedKey: []byte(psk),
2853 PreSharedKeyIdentity: pskIdentity,
2854 Bugs: ProtocolBugs{
2855 IgnorePeerCipherPreferences: shouldClientFail,
2856 SendCipherSuite: sendCipherSuite,
2857 },
2858 },
David Benjamina5022392017-07-10 17:40:39 -04002859 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002860 flags: flags,
2861 resumeSession: true,
2862 shouldFail: shouldClientFail,
2863 expectedError: expectedClientError,
2864 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002865 })
2866
David Benjamin6f600d62016-12-21 16:06:54 -05002867 if shouldClientFail {
2868 return
2869 }
2870
2871 // Ensure the maximum record size is accepted.
2872 testCases = append(testCases, testCase{
2873 protocol: protocol,
2874 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2875 config: Config{
2876 MinVersion: ver.version,
2877 MaxVersion: ver.version,
2878 CipherSuites: []uint16{suite.id},
2879 Certificates: []Certificate{cert},
2880 PreSharedKey: []byte(psk),
2881 PreSharedKeyIdentity: pskIdentity,
2882 },
David Benjamina5022392017-07-10 17:40:39 -04002883 tls13Variant: ver.tls13Variant,
2884 flags: flags,
2885 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002886 })
2887
2888 // Test bad records for all ciphers. Bad records are fatal in TLS
2889 // and ignored in DTLS.
2890 var shouldFail bool
2891 var expectedError string
2892 if protocol == tls {
2893 shouldFail = true
2894 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2895 }
2896
2897 testCases = append(testCases, testCase{
2898 protocol: protocol,
2899 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2900 config: Config{
2901 MinVersion: ver.version,
2902 MaxVersion: ver.version,
2903 CipherSuites: []uint16{suite.id},
2904 Certificates: []Certificate{cert},
2905 PreSharedKey: []byte(psk),
2906 PreSharedKeyIdentity: pskIdentity,
2907 },
David Benjamina5022392017-07-10 17:40:39 -04002908 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002909 flags: flags,
2910 damageFirstWrite: true,
2911 messageLen: maxPlaintext,
2912 shouldFail: shouldFail,
2913 expectedError: expectedError,
2914 })
David Benjaminaa012042016-12-10 13:33:05 -05002915}
2916
Adam Langley95c29f32014-06-20 12:00:00 -07002917func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002918 const bogusCipher = 0xfe00
2919
Adam Langley95c29f32014-06-20 12:00:00 -07002920 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002921 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002922 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002923 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002924 }
David Benjamin2c99d282015-09-01 10:23:00 -04002925 }
Adam Langley95c29f32014-06-20 12:00:00 -07002926 }
Adam Langleya7997f12015-05-14 17:38:50 -07002927
2928 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002929 name: "NoSharedCipher",
2930 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002931 MaxVersion: VersionTLS12,
2932 CipherSuites: []uint16{},
2933 },
2934 shouldFail: true,
2935 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2936 })
2937
2938 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002939 name: "NoSharedCipher-TLS13",
2940 config: Config{
2941 MaxVersion: VersionTLS13,
2942 CipherSuites: []uint16{},
2943 },
2944 shouldFail: true,
2945 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2946 })
2947
2948 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002949 name: "UnsupportedCipherSuite",
2950 config: Config{
2951 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002952 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002953 Bugs: ProtocolBugs{
2954 IgnorePeerCipherPreferences: true,
2955 },
2956 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002957 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002958 shouldFail: true,
2959 expectedError: ":WRONG_CIPHER_RETURNED:",
2960 })
2961
2962 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002963 name: "ServerHelloBogusCipher",
2964 config: Config{
2965 MaxVersion: VersionTLS12,
2966 Bugs: ProtocolBugs{
2967 SendCipherSuite: bogusCipher,
2968 },
2969 },
2970 shouldFail: true,
2971 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2972 })
2973 testCases = append(testCases, testCase{
2974 name: "ServerHelloBogusCipher-TLS13",
2975 config: Config{
2976 MaxVersion: VersionTLS13,
2977 Bugs: ProtocolBugs{
2978 SendCipherSuite: bogusCipher,
2979 },
2980 },
2981 shouldFail: true,
2982 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2983 })
2984
David Benjamin241ae832016-01-15 03:04:54 -05002985 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002986 testCases = append(testCases, testCase{
2987 testType: serverTest,
2988 name: "UnknownCipher",
2989 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002990 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002991 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002992 Bugs: ProtocolBugs{
2993 AdvertiseAllConfiguredCiphers: true,
2994 },
2995 },
2996 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002997
2998 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002999 testCases = append(testCases, testCase{
3000 testType: serverTest,
3001 name: "UnknownCipher-TLS13",
3002 config: Config{
3003 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003004 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003005 Bugs: ProtocolBugs{
3006 AdvertiseAllConfiguredCiphers: true,
3007 },
David Benjamin241ae832016-01-15 03:04:54 -05003008 },
3009 })
3010
David Benjamin78679342016-09-16 19:42:05 -04003011 // Test empty ECDHE_PSK identity hints work as expected.
3012 testCases = append(testCases, testCase{
3013 name: "EmptyECDHEPSKHint",
3014 config: Config{
3015 MaxVersion: VersionTLS12,
3016 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3017 PreSharedKey: []byte("secret"),
3018 },
3019 flags: []string{"-psk", "secret"},
3020 })
3021
3022 // Test empty PSK identity hints work as expected, even if an explicit
3023 // ServerKeyExchange is sent.
3024 testCases = append(testCases, testCase{
3025 name: "ExplicitEmptyPSKHint",
3026 config: Config{
3027 MaxVersion: VersionTLS12,
3028 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3029 PreSharedKey: []byte("secret"),
3030 Bugs: ProtocolBugs{
3031 AlwaysSendPreSharedKeyIdentityHint: true,
3032 },
3033 },
3034 flags: []string{"-psk", "secret"},
3035 })
David Benjamin69522112017-03-28 15:38:29 -05003036
3037 // Test that clients enforce that the server-sent certificate and cipher
3038 // suite match in TLS 1.2.
3039 testCases = append(testCases, testCase{
3040 name: "CertificateCipherMismatch-RSA",
3041 config: Config{
3042 MaxVersion: VersionTLS12,
3043 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3044 Certificates: []Certificate{rsaCertificate},
3045 Bugs: ProtocolBugs{
3046 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3047 },
3048 },
3049 shouldFail: true,
3050 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3051 })
3052 testCases = append(testCases, testCase{
3053 name: "CertificateCipherMismatch-ECDSA",
3054 config: Config{
3055 MaxVersion: VersionTLS12,
3056 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3057 Certificates: []Certificate{ecdsaP256Certificate},
3058 Bugs: ProtocolBugs{
3059 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3060 },
3061 },
3062 shouldFail: true,
3063 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3064 })
3065 testCases = append(testCases, testCase{
3066 name: "CertificateCipherMismatch-Ed25519",
3067 config: Config{
3068 MaxVersion: VersionTLS12,
3069 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3070 Certificates: []Certificate{ed25519Certificate},
3071 Bugs: ProtocolBugs{
3072 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3073 },
3074 },
3075 shouldFail: true,
3076 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3077 })
3078
3079 // Test that servers decline to select a cipher suite which is
3080 // inconsistent with their configured certificate.
3081 testCases = append(testCases, testCase{
3082 testType: serverTest,
3083 name: "ServerCipherFilter-RSA",
3084 config: Config{
3085 MaxVersion: VersionTLS12,
3086 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3087 },
3088 flags: []string{
3089 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3090 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3091 },
3092 shouldFail: true,
3093 expectedError: ":NO_SHARED_CIPHER:",
3094 })
3095 testCases = append(testCases, testCase{
3096 testType: serverTest,
3097 name: "ServerCipherFilter-ECDSA",
3098 config: Config{
3099 MaxVersion: VersionTLS12,
3100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3101 },
3102 flags: []string{
3103 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3104 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3105 },
3106 shouldFail: true,
3107 expectedError: ":NO_SHARED_CIPHER:",
3108 })
3109 testCases = append(testCases, testCase{
3110 testType: serverTest,
3111 name: "ServerCipherFilter-Ed25519",
3112 config: Config{
3113 MaxVersion: VersionTLS12,
3114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3115 },
3116 flags: []string{
3117 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3118 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3119 },
3120 shouldFail: true,
3121 expectedError: ":NO_SHARED_CIPHER:",
3122 })
David Benjamin364af782017-07-01 10:35:27 -04003123
3124 // Test cipher suite negotiation works as expected. Configure a
3125 // complicated cipher suite configuration.
3126 const negotiationTestCiphers = "" +
3127 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3128 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3129 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3130 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3131 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3132 negotiationTests := []struct {
3133 ciphers []uint16
3134 expected uint16
3135 }{
3136 // Server preferences are honored, including when
3137 // equipreference groups are involved.
3138 {
3139 []uint16{
3140 TLS_RSA_WITH_AES_256_GCM_SHA384,
3141 TLS_RSA_WITH_AES_128_CBC_SHA,
3142 TLS_RSA_WITH_AES_128_GCM_SHA256,
3143 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3144 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3145 },
3146 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 {
3149 []uint16{
3150 TLS_RSA_WITH_AES_256_GCM_SHA384,
3151 TLS_RSA_WITH_AES_128_CBC_SHA,
3152 TLS_RSA_WITH_AES_128_GCM_SHA256,
3153 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3154 },
3155 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3156 },
3157 {
3158 []uint16{
3159 TLS_RSA_WITH_AES_256_GCM_SHA384,
3160 TLS_RSA_WITH_AES_128_CBC_SHA,
3161 TLS_RSA_WITH_AES_128_GCM_SHA256,
3162 },
3163 TLS_RSA_WITH_AES_128_GCM_SHA256,
3164 },
3165 {
3166 []uint16{
3167 TLS_RSA_WITH_AES_256_GCM_SHA384,
3168 TLS_RSA_WITH_AES_128_CBC_SHA,
3169 },
3170 TLS_RSA_WITH_AES_128_CBC_SHA,
3171 },
3172 // Equipreference groups use the client preference.
3173 {
3174 []uint16{
3175 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3176 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3177 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3178 },
3179 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3180 },
3181 {
3182 []uint16{
3183 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3184 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3185 },
3186 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3187 },
3188 {
3189 []uint16{
3190 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3191 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3192 },
3193 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3194 },
3195 {
3196 []uint16{
3197 TLS_RSA_WITH_AES_256_GCM_SHA384,
3198 TLS_RSA_WITH_AES_256_CBC_SHA,
3199 },
3200 TLS_RSA_WITH_AES_256_GCM_SHA384,
3201 },
3202 {
3203 []uint16{
3204 TLS_RSA_WITH_AES_256_CBC_SHA,
3205 TLS_RSA_WITH_AES_256_GCM_SHA384,
3206 },
3207 TLS_RSA_WITH_AES_256_CBC_SHA,
3208 },
3209 // If there are two equipreference groups, the preferred one
3210 // takes precedence.
3211 {
3212 []uint16{
3213 TLS_RSA_WITH_AES_256_GCM_SHA384,
3214 TLS_RSA_WITH_AES_256_CBC_SHA,
3215 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3216 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3217 },
3218 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3219 },
3220 }
3221 for i, t := range negotiationTests {
3222 testCases = append(testCases, testCase{
3223 testType: serverTest,
3224 name: "CipherNegotiation-" + strconv.Itoa(i),
3225 config: Config{
3226 MaxVersion: VersionTLS12,
3227 CipherSuites: t.ciphers,
3228 },
3229 flags: []string{"-cipher", negotiationTestCiphers},
3230 expectedCipher: t.expected,
3231 })
3232 }
Adam Langley95c29f32014-06-20 12:00:00 -07003233}
3234
3235func addBadECDSASignatureTests() {
3236 for badR := BadValue(1); badR < NumBadValues; badR++ {
3237 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003238 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003239 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3240 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003241 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003242 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003243 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003244 Bugs: ProtocolBugs{
3245 BadECDSAR: badR,
3246 BadECDSAS: badS,
3247 },
3248 },
3249 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003250 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003251 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003252 testCases = append(testCases, testCase{
3253 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3254 config: Config{
3255 MaxVersion: VersionTLS13,
3256 Certificates: []Certificate{ecdsaP256Certificate},
3257 Bugs: ProtocolBugs{
3258 BadECDSAR: badR,
3259 BadECDSAS: badS,
3260 },
3261 },
3262 shouldFail: true,
3263 expectedError: ":BAD_SIGNATURE:",
3264 })
Adam Langley95c29f32014-06-20 12:00:00 -07003265 }
3266 }
3267}
3268
Adam Langley80842bd2014-06-20 12:00:00 -07003269func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003270 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003271 name: "MaxCBCPadding",
3272 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003273 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003274 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3275 Bugs: ProtocolBugs{
3276 MaxPadding: true,
3277 },
3278 },
3279 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3280 })
David Benjamin025b3d32014-07-01 19:53:04 -04003281 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003282 name: "BadCBCPadding",
3283 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003284 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3286 Bugs: ProtocolBugs{
3287 PaddingFirstByteBad: true,
3288 },
3289 },
3290 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003291 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003292 })
3293 // OpenSSL previously had an issue where the first byte of padding in
3294 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003295 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003296 name: "BadCBCPadding255",
3297 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003298 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003299 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3300 Bugs: ProtocolBugs{
3301 MaxPadding: true,
3302 PaddingFirstByteBadIf255: true,
3303 },
3304 },
3305 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3306 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003307 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003308 })
3309}
3310
Kenny Root7fdeaf12014-08-05 15:23:37 -07003311func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003312 var cbcCiphers = []struct {
3313 name string
3314 cipher uint16
3315 }{
3316 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3317 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3318 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3319 }
3320 for _, t := range cbcCiphers {
3321 testCases = append(testCases, testCase{
3322 name: "CBCRecordSplitting-" + t.name,
3323 config: Config{
3324 MaxVersion: VersionTLS10,
3325 MinVersion: VersionTLS10,
3326 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003327 Bugs: ProtocolBugs{
3328 ExpectRecordSplitting: true,
3329 },
David Benjamina1ce8562017-07-01 11:46:57 -04003330 },
3331 messageLen: -1, // read until EOF
3332 resumeSession: true,
3333 flags: []string{
3334 "-async",
3335 "-write-different-record-sizes",
3336 "-cbc-record-splitting",
3337 },
3338 })
3339 testCases = append(testCases, testCase{
3340 name: "CBCRecordSplittingPartialWrite-" + t.name,
3341 config: Config{
3342 MaxVersion: VersionTLS10,
3343 MinVersion: VersionTLS10,
3344 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003345 Bugs: ProtocolBugs{
3346 ExpectRecordSplitting: true,
3347 },
David Benjamina1ce8562017-07-01 11:46:57 -04003348 },
3349 messageLen: -1, // read until EOF
3350 flags: []string{
3351 "-async",
3352 "-write-different-record-sizes",
3353 "-cbc-record-splitting",
3354 "-partial-write",
3355 },
3356 })
3357 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003358}
3359
David Benjamin636293b2014-07-08 17:59:18 -04003360func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003361 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003362 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003363 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3364 cert, err := x509.ParseCertificate(cert.Certificate[0])
3365 if err != nil {
3366 panic(err)
3367 }
3368 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003369 }
Adam Langley2ff79332017-02-28 13:45:39 -08003370 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003371
David Benjamin636293b2014-07-08 17:59:18 -04003372 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003373 testCases = append(testCases, testCase{
3374 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003375 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003376 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003377 MinVersion: ver.version,
3378 MaxVersion: ver.version,
3379 ClientAuth: RequireAnyClientCert,
3380 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003381 },
David Benjamina5022392017-07-10 17:40:39 -04003382 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003383 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003384 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3385 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003386 },
3387 })
3388 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003389 testType: serverTest,
3390 name: ver.name + "-Server-ClientAuth-RSA",
3391 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003392 MinVersion: ver.version,
3393 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003394 Certificates: []Certificate{rsaCertificate},
3395 },
David Benjamina5022392017-07-10 17:40:39 -04003396 tls13Variant: ver.tls13Variant,
3397 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003398 })
David Benjamine098ec22014-08-27 23:13:20 -04003399 if ver.version != VersionSSL30 {
3400 testCases = append(testCases, testCase{
3401 testType: serverTest,
3402 name: ver.name + "-Server-ClientAuth-ECDSA",
3403 config: Config{
3404 MinVersion: ver.version,
3405 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003406 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003407 },
David Benjamina5022392017-07-10 17:40:39 -04003408 tls13Variant: ver.tls13Variant,
3409 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003410 })
3411 testCases = append(testCases, testCase{
3412 testType: clientTest,
3413 name: ver.name + "-Client-ClientAuth-ECDSA",
3414 config: Config{
3415 MinVersion: ver.version,
3416 MaxVersion: ver.version,
3417 ClientAuth: RequireAnyClientCert,
3418 ClientCAs: certPool,
3419 },
David Benjamina5022392017-07-10 17:40:39 -04003420 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003421 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003422 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3423 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003424 },
3425 })
3426 }
Adam Langley37646832016-08-01 16:16:46 -07003427
3428 testCases = append(testCases, testCase{
3429 name: "NoClientCertificate-" + ver.name,
3430 config: Config{
3431 MinVersion: ver.version,
3432 MaxVersion: ver.version,
3433 ClientAuth: RequireAnyClientCert,
3434 },
David Benjamina5022392017-07-10 17:40:39 -04003435 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003436 shouldFail: true,
3437 expectedLocalError: "client didn't provide a certificate",
3438 })
3439
3440 testCases = append(testCases, testCase{
3441 // Even if not configured to expect a certificate, OpenSSL will
3442 // return X509_V_OK as the verify_result.
3443 testType: serverTest,
3444 name: "NoClientCertificateRequested-Server-" + ver.name,
3445 config: Config{
3446 MinVersion: ver.version,
3447 MaxVersion: ver.version,
3448 },
David Benjamina5022392017-07-10 17:40:39 -04003449 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003450 flags: []string{
3451 "-expect-verify-result",
3452 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003453 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003454 })
3455
3456 testCases = append(testCases, testCase{
3457 // If a client certificate is not provided, OpenSSL will still
3458 // return X509_V_OK as the verify_result.
3459 testType: serverTest,
3460 name: "NoClientCertificate-Server-" + ver.name,
3461 config: Config{
3462 MinVersion: ver.version,
3463 MaxVersion: ver.version,
3464 },
David Benjamina5022392017-07-10 17:40:39 -04003465 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003466 flags: []string{
3467 "-expect-verify-result",
3468 "-verify-peer",
3469 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003470 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003471 })
3472
David Benjamin1db9e1b2016-10-07 20:51:43 -04003473 certificateRequired := "remote error: certificate required"
3474 if ver.version < VersionTLS13 {
3475 // Prior to TLS 1.3, the generic handshake_failure alert
3476 // was used.
3477 certificateRequired = "remote error: handshake failure"
3478 }
Adam Langley37646832016-08-01 16:16:46 -07003479 testCases = append(testCases, testCase{
3480 testType: serverTest,
3481 name: "RequireAnyClientCertificate-" + ver.name,
3482 config: Config{
3483 MinVersion: ver.version,
3484 MaxVersion: ver.version,
3485 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003486 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003487 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003488 shouldFail: true,
3489 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3490 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003491 })
3492
3493 if ver.version != VersionSSL30 {
3494 testCases = append(testCases, testCase{
3495 testType: serverTest,
3496 name: "SkipClientCertificate-" + ver.name,
3497 config: Config{
3498 MinVersion: ver.version,
3499 MaxVersion: ver.version,
3500 Bugs: ProtocolBugs{
3501 SkipClientCertificate: true,
3502 },
3503 },
3504 // Setting SSL_VERIFY_PEER allows anonymous clients.
3505 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003506 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003507 shouldFail: true,
3508 expectedError: ":UNEXPECTED_MESSAGE:",
3509 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003510
3511 testCases = append(testCases, testCase{
3512 testType: serverTest,
3513 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3514 config: Config{
3515 MinVersion: ver.version,
3516 MaxVersion: ver.version,
3517 },
3518 flags: []string{
3519 "-enable-channel-id",
3520 "-verify-peer-if-no-obc",
3521 },
David Benjamina5022392017-07-10 17:40:39 -04003522 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003523 shouldFail: true,
3524 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3525 expectedLocalError: certificateRequired,
3526 })
3527
3528 testCases = append(testCases, testCase{
3529 testType: serverTest,
3530 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3531 config: Config{
3532 MinVersion: ver.version,
3533 MaxVersion: ver.version,
3534 ChannelID: channelIDKey,
3535 },
3536 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003537 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003538 flags: []string{
3539 "-enable-channel-id",
3540 "-verify-peer-if-no-obc",
3541 },
3542 })
Adam Langley37646832016-08-01 16:16:46 -07003543 }
Adam Langley2ff79332017-02-28 13:45:39 -08003544
3545 testCases = append(testCases, testCase{
3546 testType: serverTest,
3547 name: ver.name + "-Server-CertReq-CA-List",
3548 config: Config{
3549 MinVersion: ver.version,
3550 MaxVersion: ver.version,
3551 Certificates: []Certificate{rsaCertificate},
3552 Bugs: ProtocolBugs{
3553 ExpectCertificateReqNames: caNames,
3554 },
3555 },
David Benjamina5022392017-07-10 17:40:39 -04003556 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003557 flags: []string{
3558 "-require-any-client-certificate",
3559 "-use-client-ca-list", encodeDERValues(caNames),
3560 },
3561 })
3562
3563 testCases = append(testCases, testCase{
3564 testType: clientTest,
3565 name: ver.name + "-Client-CertReq-CA-List",
3566 config: Config{
3567 MinVersion: ver.version,
3568 MaxVersion: ver.version,
3569 Certificates: []Certificate{rsaCertificate},
3570 ClientAuth: RequireAnyClientCert,
3571 ClientCAs: certPool,
3572 },
David Benjamina5022392017-07-10 17:40:39 -04003573 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003574 flags: []string{
3575 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3576 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3577 "-expect-client-ca-list", encodeDERValues(caNames),
3578 },
3579 })
David Benjamin636293b2014-07-08 17:59:18 -04003580 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003581
David Benjaminc032dfa2016-05-12 14:54:57 -04003582 // Client auth is only legal in certificate-based ciphers.
3583 testCases = append(testCases, testCase{
3584 testType: clientTest,
3585 name: "ClientAuth-PSK",
3586 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003587 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003588 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3589 PreSharedKey: []byte("secret"),
3590 ClientAuth: RequireAnyClientCert,
3591 },
3592 flags: []string{
3593 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3594 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3595 "-psk", "secret",
3596 },
3597 shouldFail: true,
3598 expectedError: ":UNEXPECTED_MESSAGE:",
3599 })
3600 testCases = append(testCases, testCase{
3601 testType: clientTest,
3602 name: "ClientAuth-ECDHE_PSK",
3603 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003604 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003605 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3606 PreSharedKey: []byte("secret"),
3607 ClientAuth: RequireAnyClientCert,
3608 },
3609 flags: []string{
3610 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3611 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3612 "-psk", "secret",
3613 },
3614 shouldFail: true,
3615 expectedError: ":UNEXPECTED_MESSAGE:",
3616 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003617
3618 // Regression test for a bug where the client CA list, if explicitly
3619 // set to NULL, was mis-encoded.
3620 testCases = append(testCases, testCase{
3621 testType: serverTest,
3622 name: "Null-Client-CA-List",
3623 config: Config{
3624 MaxVersion: VersionTLS12,
3625 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003626 Bugs: ProtocolBugs{
3627 ExpectCertificateReqNames: [][]byte{},
3628 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003629 },
3630 flags: []string{
3631 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003632 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003633 },
3634 })
David Benjamin636293b2014-07-08 17:59:18 -04003635}
3636
Adam Langley75712922014-10-10 16:23:43 -07003637func addExtendedMasterSecretTests() {
3638 const expectEMSFlag = "-expect-extended-master-secret"
3639
3640 for _, with := range []bool{false, true} {
3641 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003642 if with {
3643 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003644 }
3645
3646 for _, isClient := range []bool{false, true} {
3647 suffix := "-Server"
3648 testType := serverTest
3649 if isClient {
3650 suffix = "-Client"
3651 testType = clientTest
3652 }
3653
3654 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003655 // In TLS 1.3, the extension is irrelevant and
3656 // always reports as enabled.
3657 var flags []string
3658 if with || ver.version >= VersionTLS13 {
3659 flags = []string{expectEMSFlag}
3660 }
3661
Adam Langley75712922014-10-10 16:23:43 -07003662 test := testCase{
3663 testType: testType,
3664 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3665 config: Config{
3666 MinVersion: ver.version,
3667 MaxVersion: ver.version,
3668 Bugs: ProtocolBugs{
3669 NoExtendedMasterSecret: !with,
3670 RequireExtendedMasterSecret: with,
3671 },
3672 },
David Benjamina5022392017-07-10 17:40:39 -04003673 tls13Variant: ver.tls13Variant,
3674 flags: flags,
3675 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003676 }
3677 if test.shouldFail {
3678 test.expectedLocalError = "extended master secret required but not supported by peer"
3679 }
3680 testCases = append(testCases, test)
3681 }
3682 }
3683 }
3684
Adam Langleyba5934b2015-06-02 10:50:35 -07003685 for _, isClient := range []bool{false, true} {
3686 for _, supportedInFirstConnection := range []bool{false, true} {
3687 for _, supportedInResumeConnection := range []bool{false, true} {
3688 boolToWord := func(b bool) string {
3689 if b {
3690 return "Yes"
3691 }
3692 return "No"
3693 }
3694 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3695 if isClient {
3696 suffix += "Client"
3697 } else {
3698 suffix += "Server"
3699 }
3700
3701 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003702 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003703 Bugs: ProtocolBugs{
3704 RequireExtendedMasterSecret: true,
3705 },
3706 }
3707
3708 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003709 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003710 Bugs: ProtocolBugs{
3711 NoExtendedMasterSecret: true,
3712 },
3713 }
3714
3715 test := testCase{
3716 name: "ExtendedMasterSecret-" + suffix,
3717 resumeSession: true,
3718 }
3719
3720 if !isClient {
3721 test.testType = serverTest
3722 }
3723
3724 if supportedInFirstConnection {
3725 test.config = supportedConfig
3726 } else {
3727 test.config = noSupportConfig
3728 }
3729
3730 if supportedInResumeConnection {
3731 test.resumeConfig = &supportedConfig
3732 } else {
3733 test.resumeConfig = &noSupportConfig
3734 }
3735
3736 switch suffix {
3737 case "YesToYes-Client", "YesToYes-Server":
3738 // When a session is resumed, it should
3739 // still be aware that its master
3740 // secret was generated via EMS and
3741 // thus it's safe to use tls-unique.
3742 test.flags = []string{expectEMSFlag}
3743 case "NoToYes-Server":
3744 // If an original connection did not
3745 // contain EMS, but a resumption
3746 // handshake does, then a server should
3747 // not resume the session.
3748 test.expectResumeRejected = true
3749 case "YesToNo-Server":
3750 // Resuming an EMS session without the
3751 // EMS extension should cause the
3752 // server to abort the connection.
3753 test.shouldFail = true
3754 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3755 case "NoToYes-Client":
3756 // A client should abort a connection
3757 // where the server resumed a non-EMS
3758 // session but echoed the EMS
3759 // extension.
3760 test.shouldFail = true
3761 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3762 case "YesToNo-Client":
3763 // A client should abort a connection
3764 // where the server didn't echo EMS
3765 // when the session used it.
3766 test.shouldFail = true
3767 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3768 }
3769
3770 testCases = append(testCases, test)
3771 }
3772 }
3773 }
David Benjamin163c9562016-08-29 23:14:17 -04003774
3775 // Switching EMS on renegotiation is forbidden.
3776 testCases = append(testCases, testCase{
3777 name: "ExtendedMasterSecret-Renego-NoEMS",
3778 config: Config{
3779 MaxVersion: VersionTLS12,
3780 Bugs: ProtocolBugs{
3781 NoExtendedMasterSecret: true,
3782 NoExtendedMasterSecretOnRenegotiation: true,
3783 },
3784 },
3785 renegotiate: 1,
3786 flags: []string{
3787 "-renegotiate-freely",
3788 "-expect-total-renegotiations", "1",
3789 },
3790 })
3791
3792 testCases = append(testCases, testCase{
3793 name: "ExtendedMasterSecret-Renego-Upgrade",
3794 config: Config{
3795 MaxVersion: VersionTLS12,
3796 Bugs: ProtocolBugs{
3797 NoExtendedMasterSecret: true,
3798 },
3799 },
3800 renegotiate: 1,
3801 flags: []string{
3802 "-renegotiate-freely",
3803 "-expect-total-renegotiations", "1",
3804 },
3805 shouldFail: true,
3806 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3807 })
3808
3809 testCases = append(testCases, testCase{
3810 name: "ExtendedMasterSecret-Renego-Downgrade",
3811 config: Config{
3812 MaxVersion: VersionTLS12,
3813 Bugs: ProtocolBugs{
3814 NoExtendedMasterSecretOnRenegotiation: true,
3815 },
3816 },
3817 renegotiate: 1,
3818 flags: []string{
3819 "-renegotiate-freely",
3820 "-expect-total-renegotiations", "1",
3821 },
3822 shouldFail: true,
3823 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3824 })
Adam Langley75712922014-10-10 16:23:43 -07003825}
3826
David Benjamin582ba042016-07-07 12:33:25 -07003827type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003828 protocol protocol
3829 async bool
3830 splitHandshake bool
3831 packHandshakeFlight bool
3832 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003833}
3834
David Benjamin43ec06f2014-08-05 02:28:57 -04003835// Adds tests that try to cover the range of the handshake state machine, under
3836// various conditions. Some of these are redundant with other tests, but they
3837// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003838func addAllStateMachineCoverageTests() {
3839 for _, async := range []bool{false, true} {
3840 for _, protocol := range []protocol{tls, dtls} {
3841 addStateMachineCoverageTests(stateMachineTestConfig{
3842 protocol: protocol,
3843 async: async,
3844 })
3845 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003846 protocol: protocol,
3847 async: async,
3848 implicitHandshake: true,
3849 })
3850 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003851 protocol: protocol,
3852 async: async,
3853 splitHandshake: true,
3854 })
3855 if protocol == tls {
3856 addStateMachineCoverageTests(stateMachineTestConfig{
3857 protocol: protocol,
3858 async: async,
3859 packHandshakeFlight: true,
3860 })
3861 }
3862 }
3863 }
3864}
3865
3866func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003867 var tests []testCase
3868
3869 // Basic handshake, with resumption. Client and server,
3870 // session ID and session ticket.
3871 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003872 name: "Basic-Client",
3873 config: Config{
3874 MaxVersion: VersionTLS12,
3875 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003876 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003877 // Ensure session tickets are used, not session IDs.
3878 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003879 })
3880 tests = append(tests, testCase{
3881 name: "Basic-Client-RenewTicket",
3882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003884 Bugs: ProtocolBugs{
3885 RenewTicketOnResume: true,
3886 },
3887 },
David Benjamin46662482016-08-17 00:51:00 -04003888 flags: []string{"-expect-ticket-renewal"},
3889 resumeSession: true,
3890 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003891 })
3892 tests = append(tests, testCase{
3893 name: "Basic-Client-NoTicket",
3894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003895 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003896 SessionTicketsDisabled: true,
3897 },
3898 resumeSession: true,
3899 })
3900 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003901 testType: serverTest,
3902 name: "Basic-Server",
3903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003904 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003905 Bugs: ProtocolBugs{
3906 RequireSessionTickets: true,
3907 },
3908 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003909 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003910 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003911 })
3912 tests = append(tests, testCase{
3913 testType: serverTest,
3914 name: "Basic-Server-NoTickets",
3915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003916 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003917 SessionTicketsDisabled: true,
3918 },
3919 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003920 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003921 })
3922 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003923 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 name: "Basic-Server-EarlyCallback",
3925 config: Config{
3926 MaxVersion: VersionTLS12,
3927 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003928 flags: []string{"-use-early-callback"},
3929 resumeSession: true,
3930 })
3931
Steven Valdez143e8b32016-07-11 13:19:03 -04003932 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003933 if config.protocol == tls {
3934 tests = append(tests, testCase{
3935 name: "TLS13-1RTT-Client",
3936 config: Config{
3937 MaxVersion: VersionTLS13,
3938 MinVersion: VersionTLS13,
3939 },
David Benjamin46662482016-08-17 00:51:00 -04003940 resumeSession: true,
3941 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003942 })
3943
3944 tests = append(tests, testCase{
3945 testType: serverTest,
3946 name: "TLS13-1RTT-Server",
3947 config: Config{
3948 MaxVersion: VersionTLS13,
3949 MinVersion: VersionTLS13,
3950 },
David Benjamin46662482016-08-17 00:51:00 -04003951 resumeSession: true,
3952 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003953 // TLS 1.3 uses tickets, so the session should not be
3954 // cached statefully.
3955 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003956 })
3957
3958 tests = append(tests, testCase{
3959 name: "TLS13-HelloRetryRequest-Client",
3960 config: Config{
3961 MaxVersion: VersionTLS13,
3962 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003963 // P-384 requires a HelloRetryRequest against BoringSSL's default
3964 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003965 CurvePreferences: []CurveID{CurveP384},
3966 Bugs: ProtocolBugs{
3967 ExpectMissingKeyShare: true,
3968 },
3969 },
3970 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3971 resumeSession: true,
3972 })
3973
3974 tests = append(tests, testCase{
3975 testType: serverTest,
3976 name: "TLS13-HelloRetryRequest-Server",
3977 config: Config{
3978 MaxVersion: VersionTLS13,
3979 MinVersion: VersionTLS13,
3980 // Require a HelloRetryRequest for every curve.
3981 DefaultCurves: []CurveID{},
3982 },
3983 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3984 resumeSession: true,
3985 })
Steven Valdez2d850622017-01-11 11:34:52 -05003986
Steven Valdez2d850622017-01-11 11:34:52 -05003987 tests = append(tests, testCase{
3988 testType: clientTest,
3989 name: "TLS13-EarlyData-Client",
3990 config: Config{
3991 MaxVersion: VersionTLS13,
3992 MinVersion: VersionTLS13,
3993 MaxEarlyDataSize: 16384,
3994 },
Steven Valdeze831a812017-03-09 14:56:07 -05003995 resumeConfig: &Config{
3996 MaxVersion: VersionTLS13,
3997 MinVersion: VersionTLS13,
3998 MaxEarlyDataSize: 16384,
3999 Bugs: ProtocolBugs{
4000 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4001 },
4002 },
Steven Valdez2d850622017-01-11 11:34:52 -05004003 resumeSession: true,
4004 flags: []string{
4005 "-enable-early-data",
4006 "-expect-early-data-info",
4007 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004008 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004009 },
4010 })
4011
4012 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004013 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004014 name: "TLS13Experiment-EarlyData-Client",
4015 config: Config{
4016 MaxVersion: VersionTLS13,
4017 MinVersion: VersionTLS13,
4018 TLS13Variant: TLS13Experiment,
4019 MaxEarlyDataSize: 16384,
4020 },
4021 resumeConfig: &Config{
4022 MaxVersion: VersionTLS13,
4023 MinVersion: VersionTLS13,
4024 TLS13Variant: TLS13Experiment,
4025 MaxEarlyDataSize: 16384,
4026 Bugs: ProtocolBugs{
4027 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4028 },
4029 },
4030 resumeSession: true,
4031 flags: []string{
4032 "-enable-early-data",
4033 "-expect-early-data-info",
4034 "-expect-accept-early-data",
4035 "-on-resume-shim-writes-first",
4036 "-tls13-variant", "1",
4037 },
4038 })
4039
4040 tests = append(tests, testCase{
4041 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004042 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4043 config: Config{
4044 MaxVersion: VersionTLS13,
4045 MinVersion: VersionTLS13,
4046 TLS13Variant: TLS13RecordTypeExperiment,
4047 MaxEarlyDataSize: 16384,
4048 },
4049 resumeConfig: &Config{
4050 MaxVersion: VersionTLS13,
4051 MinVersion: VersionTLS13,
4052 TLS13Variant: TLS13RecordTypeExperiment,
4053 MaxEarlyDataSize: 16384,
4054 Bugs: ProtocolBugs{
4055 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4056 },
4057 },
4058 resumeSession: true,
4059 flags: []string{
4060 "-enable-early-data",
4061 "-expect-early-data-info",
4062 "-expect-accept-early-data",
4063 "-on-resume-shim-writes-first",
4064 "-tls13-variant", "2",
4065 },
4066 })
4067
4068 tests = append(tests, testCase{
4069 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004070 name: "TLS13-EarlyData-TooMuchData-Client",
4071 config: Config{
4072 MaxVersion: VersionTLS13,
4073 MinVersion: VersionTLS13,
4074 MaxEarlyDataSize: 2,
4075 },
4076 resumeConfig: &Config{
4077 MaxVersion: VersionTLS13,
4078 MinVersion: VersionTLS13,
4079 MaxEarlyDataSize: 2,
4080 Bugs: ProtocolBugs{
4081 ExpectEarlyData: [][]byte{{'h', 'e'}},
4082 },
4083 },
4084 resumeShimPrefix: "llo",
4085 resumeSession: true,
4086 flags: []string{
4087 "-enable-early-data",
4088 "-expect-early-data-info",
4089 "-expect-accept-early-data",
4090 "-on-resume-shim-writes-first",
4091 },
4092 })
4093
4094 // Unfinished writes can only be tested when operations are async. EarlyData
4095 // can't be tested as part of an ImplicitHandshake in this case since
4096 // otherwise the early data will be sent as normal data.
4097 if config.async && !config.implicitHandshake {
4098 tests = append(tests, testCase{
4099 testType: clientTest,
4100 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4101 config: Config{
4102 MaxVersion: VersionTLS13,
4103 MinVersion: VersionTLS13,
4104 MaxEarlyDataSize: 16384,
4105 },
4106 resumeConfig: &Config{
4107 MaxVersion: VersionTLS13,
4108 MinVersion: VersionTLS13,
4109 MaxEarlyDataSize: 16384,
4110 Bugs: ProtocolBugs{
4111 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4112 },
4113 },
4114 resumeSession: true,
4115 flags: []string{
4116 "-enable-early-data",
4117 "-expect-early-data-info",
4118 "-expect-accept-early-data",
4119 "-on-resume-read-with-unfinished-write",
4120 "-on-resume-shim-writes-first",
4121 },
4122 })
4123
4124 // Rejected unfinished writes are discarded (from the
4125 // perspective of the calling application) on 0-RTT
4126 // reject.
4127 tests = append(tests, testCase{
4128 testType: clientTest,
4129 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4130 config: Config{
4131 MaxVersion: VersionTLS13,
4132 MinVersion: VersionTLS13,
4133 MaxEarlyDataSize: 16384,
4134 },
4135 resumeConfig: &Config{
4136 MaxVersion: VersionTLS13,
4137 MinVersion: VersionTLS13,
4138 MaxEarlyDataSize: 16384,
4139 Bugs: ProtocolBugs{
4140 AlwaysRejectEarlyData: true,
4141 },
4142 },
4143 resumeSession: true,
4144 flags: []string{
4145 "-enable-early-data",
4146 "-expect-early-data-info",
4147 "-expect-reject-early-data",
4148 "-on-resume-read-with-unfinished-write",
4149 "-on-resume-shim-writes-first",
4150 },
4151 })
4152 }
4153
4154 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004155 testType: serverTest,
4156 name: "TLS13-EarlyData-Server",
4157 config: Config{
4158 MaxVersion: VersionTLS13,
4159 MinVersion: VersionTLS13,
4160 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004161 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004162 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004163 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004164 },
4165 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004166 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004167 resumeSession: true,
4168 flags: []string{
4169 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004170 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004171 },
4172 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004173
4174 tests = append(tests, testCase{
4175 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004176 name: "TLS13Experiment-EarlyData-Server",
4177 config: Config{
4178 MaxVersion: VersionTLS13,
4179 MinVersion: VersionTLS13,
4180 TLS13Variant: TLS13Experiment,
4181 Bugs: ProtocolBugs{
4182 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4183 ExpectEarlyDataAccepted: true,
4184 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4185 },
4186 },
4187 messageCount: 2,
4188 resumeSession: true,
4189 flags: []string{
4190 "-enable-early-data",
4191 "-expect-accept-early-data",
4192 "-tls13-variant", "1",
4193 },
4194 })
4195
4196 tests = append(tests, testCase{
4197 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004198 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4199 config: Config{
4200 MaxVersion: VersionTLS13,
4201 MinVersion: VersionTLS13,
4202 TLS13Variant: TLS13RecordTypeExperiment,
4203 Bugs: ProtocolBugs{
4204 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4205 ExpectEarlyDataAccepted: true,
4206 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4207 },
4208 },
4209 messageCount: 2,
4210 resumeSession: true,
4211 flags: []string{
4212 "-enable-early-data",
4213 "-expect-accept-early-data",
4214 "-tls13-variant", "2",
4215 },
4216 })
4217
4218 tests = append(tests, testCase{
4219 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004220 name: "TLS13-MaxEarlyData-Server",
4221 config: Config{
4222 MaxVersion: VersionTLS13,
4223 MinVersion: VersionTLS13,
4224 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004225 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004226 ExpectEarlyDataAccepted: true,
4227 },
4228 },
4229 messageCount: 2,
4230 resumeSession: true,
4231 flags: []string{
4232 "-enable-early-data",
4233 "-expect-accept-early-data",
4234 },
4235 shouldFail: true,
4236 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4237 })
David Benjamine73c7f42016-08-17 00:29:33 -04004238 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004239
David Benjamin760b1dd2015-05-15 23:33:48 -04004240 // TLS client auth.
4241 tests = append(tests, testCase{
4242 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004243 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004244 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004245 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004246 ClientAuth: RequestClientCert,
4247 },
4248 })
4249 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004250 testType: serverTest,
4251 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004252 config: Config{
4253 MaxVersion: VersionTLS12,
4254 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004255 // Setting SSL_VERIFY_PEER allows anonymous clients.
4256 flags: []string{"-verify-peer"},
4257 })
David Benjamin582ba042016-07-07 12:33:25 -07004258 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004259 tests = append(tests, testCase{
4260 testType: clientTest,
4261 name: "ClientAuth-NoCertificate-Client-SSL3",
4262 config: Config{
4263 MaxVersion: VersionSSL30,
4264 ClientAuth: RequestClientCert,
4265 },
4266 })
4267 tests = append(tests, testCase{
4268 testType: serverTest,
4269 name: "ClientAuth-NoCertificate-Server-SSL3",
4270 config: Config{
4271 MaxVersion: VersionSSL30,
4272 },
4273 // Setting SSL_VERIFY_PEER allows anonymous clients.
4274 flags: []string{"-verify-peer"},
4275 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004276 tests = append(tests, testCase{
4277 testType: clientTest,
4278 name: "ClientAuth-NoCertificate-Client-TLS13",
4279 config: Config{
4280 MaxVersion: VersionTLS13,
4281 ClientAuth: RequestClientCert,
4282 },
4283 })
4284 tests = append(tests, testCase{
4285 testType: serverTest,
4286 name: "ClientAuth-NoCertificate-Server-TLS13",
4287 config: Config{
4288 MaxVersion: VersionTLS13,
4289 },
4290 // Setting SSL_VERIFY_PEER allows anonymous clients.
4291 flags: []string{"-verify-peer"},
4292 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004293 }
4294 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004295 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004296 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004297 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004298 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004299 ClientAuth: RequireAnyClientCert,
4300 },
4301 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004302 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4303 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004304 },
4305 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004306 tests = append(tests, testCase{
4307 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004308 name: "ClientAuth-RSA-Client-TLS13",
4309 config: Config{
4310 MaxVersion: VersionTLS13,
4311 ClientAuth: RequireAnyClientCert,
4312 },
4313 flags: []string{
4314 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4315 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4316 },
4317 })
4318 tests = append(tests, testCase{
4319 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004320 name: "ClientAuth-ECDSA-Client",
4321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004323 ClientAuth: RequireAnyClientCert,
4324 },
4325 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004326 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4327 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004328 },
4329 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004330 tests = append(tests, testCase{
4331 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004332 name: "ClientAuth-ECDSA-Client-TLS13",
4333 config: Config{
4334 MaxVersion: VersionTLS13,
4335 ClientAuth: RequireAnyClientCert,
4336 },
4337 flags: []string{
4338 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4339 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4340 },
4341 })
4342 tests = append(tests, testCase{
4343 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004344 name: "ClientAuth-NoCertificate-OldCallback",
4345 config: Config{
4346 MaxVersion: VersionTLS12,
4347 ClientAuth: RequestClientCert,
4348 },
4349 flags: []string{"-use-old-client-cert-callback"},
4350 })
4351 tests = append(tests, testCase{
4352 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004353 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4354 config: Config{
4355 MaxVersion: VersionTLS13,
4356 ClientAuth: RequestClientCert,
4357 },
4358 flags: []string{"-use-old-client-cert-callback"},
4359 })
4360 tests = append(tests, testCase{
4361 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004362 name: "ClientAuth-OldCallback",
4363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004364 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004365 ClientAuth: RequireAnyClientCert,
4366 },
4367 flags: []string{
4368 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4369 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4370 "-use-old-client-cert-callback",
4371 },
4372 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004373 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004374 testType: clientTest,
4375 name: "ClientAuth-OldCallback-TLS13",
4376 config: Config{
4377 MaxVersion: VersionTLS13,
4378 ClientAuth: RequireAnyClientCert,
4379 },
4380 flags: []string{
4381 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4382 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4383 "-use-old-client-cert-callback",
4384 },
4385 })
4386 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004387 testType: serverTest,
4388 name: "ClientAuth-Server",
4389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004390 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004391 Certificates: []Certificate{rsaCertificate},
4392 },
4393 flags: []string{"-require-any-client-certificate"},
4394 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004395 tests = append(tests, testCase{
4396 testType: serverTest,
4397 name: "ClientAuth-Server-TLS13",
4398 config: Config{
4399 MaxVersion: VersionTLS13,
4400 Certificates: []Certificate{rsaCertificate},
4401 },
4402 flags: []string{"-require-any-client-certificate"},
4403 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004404
David Benjamin4c3ddf72016-06-29 18:13:53 -04004405 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004406 tests = append(tests, testCase{
4407 testType: serverTest,
4408 name: "Basic-Server-RSA",
4409 config: Config{
4410 MaxVersion: VersionTLS12,
4411 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4412 },
4413 flags: []string{
4414 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4415 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4416 },
4417 })
4418 tests = append(tests, testCase{
4419 testType: serverTest,
4420 name: "Basic-Server-ECDHE-RSA",
4421 config: Config{
4422 MaxVersion: VersionTLS12,
4423 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4424 },
4425 flags: []string{
4426 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4427 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4428 },
4429 })
4430 tests = append(tests, testCase{
4431 testType: serverTest,
4432 name: "Basic-Server-ECDHE-ECDSA",
4433 config: Config{
4434 MaxVersion: VersionTLS12,
4435 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4436 },
4437 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004438 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4439 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004440 },
4441 })
David Benjamin69522112017-03-28 15:38:29 -05004442 tests = append(tests, testCase{
4443 testType: serverTest,
4444 name: "Basic-Server-Ed25519",
4445 config: Config{
4446 MaxVersion: VersionTLS12,
4447 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4448 },
4449 flags: []string{
4450 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4451 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4452 "-enable-ed25519",
4453 },
4454 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004455
David Benjamin760b1dd2015-05-15 23:33:48 -04004456 // No session ticket support; server doesn't send NewSessionTicket.
4457 tests = append(tests, testCase{
4458 name: "SessionTicketsDisabled-Client",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 SessionTicketsDisabled: true,
4462 },
4463 })
4464 tests = append(tests, testCase{
4465 testType: serverTest,
4466 name: "SessionTicketsDisabled-Server",
4467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004468 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004469 SessionTicketsDisabled: true,
4470 },
4471 })
4472
4473 // Skip ServerKeyExchange in PSK key exchange if there's no
4474 // identity hint.
4475 tests = append(tests, testCase{
4476 name: "EmptyPSKHint-Client",
4477 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004478 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004479 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4480 PreSharedKey: []byte("secret"),
4481 },
4482 flags: []string{"-psk", "secret"},
4483 })
4484 tests = append(tests, testCase{
4485 testType: serverTest,
4486 name: "EmptyPSKHint-Server",
4487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004488 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004489 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4490 PreSharedKey: []byte("secret"),
4491 },
4492 flags: []string{"-psk", "secret"},
4493 })
4494
David Benjamin4c3ddf72016-06-29 18:13:53 -04004495 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004496 tests = append(tests, testCase{
4497 testType: clientTest,
4498 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004499 config: Config{
4500 MaxVersion: VersionTLS12,
4501 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004502 flags: []string{
4503 "-enable-ocsp-stapling",
4504 "-expect-ocsp-response",
4505 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004506 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004507 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004508 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004509 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004510 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004511 testType: serverTest,
4512 name: "OCSPStapling-Server",
4513 config: Config{
4514 MaxVersion: VersionTLS12,
4515 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004516 expectedOCSPResponse: testOCSPResponse,
4517 flags: []string{
4518 "-ocsp-response",
4519 base64.StdEncoding.EncodeToString(testOCSPResponse),
4520 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004521 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004522 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004523 tests = append(tests, testCase{
4524 testType: clientTest,
4525 name: "OCSPStapling-Client-TLS13",
4526 config: Config{
4527 MaxVersion: VersionTLS13,
4528 },
4529 flags: []string{
4530 "-enable-ocsp-stapling",
4531 "-expect-ocsp-response",
4532 base64.StdEncoding.EncodeToString(testOCSPResponse),
4533 "-verify-peer",
4534 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004535 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004536 })
4537 tests = append(tests, testCase{
4538 testType: serverTest,
4539 name: "OCSPStapling-Server-TLS13",
4540 config: Config{
4541 MaxVersion: VersionTLS13,
4542 },
4543 expectedOCSPResponse: testOCSPResponse,
4544 flags: []string{
4545 "-ocsp-response",
4546 base64.StdEncoding.EncodeToString(testOCSPResponse),
4547 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004548 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004549 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004550
David Benjamin4c3ddf72016-06-29 18:13:53 -04004551 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004552 for _, vers := range tlsVersions {
4553 if config.protocol == dtls && !vers.hasDTLS {
4554 continue
4555 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004556 for _, testType := range []testType{clientTest, serverTest} {
4557 suffix := "-Client"
4558 if testType == serverTest {
4559 suffix = "-Server"
4560 }
4561 suffix += "-" + vers.name
4562
4563 flag := "-verify-peer"
4564 if testType == serverTest {
4565 flag = "-require-any-client-certificate"
4566 }
4567
4568 tests = append(tests, testCase{
4569 testType: testType,
4570 name: "CertificateVerificationSucceed" + suffix,
4571 config: Config{
4572 MaxVersion: vers.version,
4573 Certificates: []Certificate{rsaCertificate},
4574 },
David Benjamina5022392017-07-10 17:40:39 -04004575 tls13Variant: vers.tls13Variant,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004576 flags: []string{
4577 flag,
4578 "-expect-verify-result",
4579 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004580 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004581 })
4582 tests = append(tests, testCase{
4583 testType: testType,
4584 name: "CertificateVerificationFail" + suffix,
4585 config: Config{
4586 MaxVersion: vers.version,
4587 Certificates: []Certificate{rsaCertificate},
4588 },
David Benjamina5022392017-07-10 17:40:39 -04004589 tls13Variant: vers.tls13Variant,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004590 flags: []string{
4591 flag,
4592 "-verify-fail",
4593 },
4594 shouldFail: true,
4595 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4596 })
4597 }
4598
4599 // By default, the client is in a soft fail mode where the peer
4600 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004601 tests = append(tests, testCase{
4602 testType: clientTest,
4603 name: "CertificateVerificationSoftFail-" + vers.name,
4604 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004605 MaxVersion: vers.version,
4606 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004607 },
David Benjamina5022392017-07-10 17:40:39 -04004608 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004609 flags: []string{
4610 "-verify-fail",
4611 "-expect-verify-result",
4612 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004613 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004614 })
4615 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004616
David Benjamin1d4f4c02016-07-26 18:03:08 -04004617 tests = append(tests, testCase{
4618 name: "ShimSendAlert",
4619 flags: []string{"-send-alert"},
4620 shimWritesFirst: true,
4621 shouldFail: true,
4622 expectedLocalError: "remote error: decompression failure",
4623 })
4624
David Benjamin582ba042016-07-07 12:33:25 -07004625 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004626 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004627 name: "Renegotiate-Client",
4628 config: Config{
4629 MaxVersion: VersionTLS12,
4630 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004631 renegotiate: 1,
4632 flags: []string{
4633 "-renegotiate-freely",
4634 "-expect-total-renegotiations", "1",
4635 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004636 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004637
David Benjamin47921102016-07-28 11:29:18 -04004638 tests = append(tests, testCase{
4639 name: "SendHalfHelloRequest",
4640 config: Config{
4641 MaxVersion: VersionTLS12,
4642 Bugs: ProtocolBugs{
4643 PackHelloRequestWithFinished: config.packHandshakeFlight,
4644 },
4645 },
4646 sendHalfHelloRequest: true,
4647 flags: []string{"-renegotiate-ignore"},
4648 shouldFail: true,
4649 expectedError: ":UNEXPECTED_RECORD:",
4650 })
4651
David Benjamin760b1dd2015-05-15 23:33:48 -04004652 // NPN on client and server; results in post-handshake message.
4653 tests = append(tests, testCase{
4654 name: "NPN-Client",
4655 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004656 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004657 NextProtos: []string{"foo"},
4658 },
4659 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004660 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004661 expectedNextProto: "foo",
4662 expectedNextProtoType: npn,
4663 })
4664 tests = append(tests, testCase{
4665 testType: serverTest,
4666 name: "NPN-Server",
4667 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004668 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004669 NextProtos: []string{"bar"},
4670 },
4671 flags: []string{
4672 "-advertise-npn", "\x03foo\x03bar\x03baz",
4673 "-expect-next-proto", "bar",
4674 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004675 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004676 expectedNextProto: "bar",
4677 expectedNextProtoType: npn,
4678 })
4679
4680 // TODO(davidben): Add tests for when False Start doesn't trigger.
4681
4682 // Client does False Start and negotiates NPN.
4683 tests = append(tests, testCase{
4684 name: "FalseStart",
4685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004686 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4688 NextProtos: []string{"foo"},
4689 Bugs: ProtocolBugs{
4690 ExpectFalseStart: true,
4691 },
4692 },
4693 flags: []string{
4694 "-false-start",
4695 "-select-next-proto", "foo",
4696 },
4697 shimWritesFirst: true,
4698 resumeSession: true,
4699 })
4700
4701 // Client does False Start and negotiates ALPN.
4702 tests = append(tests, testCase{
4703 name: "FalseStart-ALPN",
4704 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004705 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004706 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4707 NextProtos: []string{"foo"},
4708 Bugs: ProtocolBugs{
4709 ExpectFalseStart: true,
4710 },
4711 },
4712 flags: []string{
4713 "-false-start",
4714 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004715 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004716 },
4717 shimWritesFirst: true,
4718 resumeSession: true,
4719 })
4720
David Benjamin760b1dd2015-05-15 23:33:48 -04004721 // False Start without session tickets.
4722 tests = append(tests, testCase{
4723 name: "FalseStart-SessionTicketsDisabled",
4724 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004725 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004726 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4727 NextProtos: []string{"foo"},
4728 SessionTicketsDisabled: true,
4729 Bugs: ProtocolBugs{
4730 ExpectFalseStart: true,
4731 },
4732 },
4733 flags: []string{
4734 "-false-start",
4735 "-select-next-proto", "foo",
4736 },
4737 shimWritesFirst: true,
4738 })
4739
4740 // Server parses a V2ClientHello.
4741 tests = append(tests, testCase{
4742 testType: serverTest,
4743 name: "SendV2ClientHello",
4744 config: Config{
4745 // Choose a cipher suite that does not involve
4746 // elliptic curves, so no extensions are
4747 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004748 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004749 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004750 Bugs: ProtocolBugs{
4751 SendV2ClientHello: true,
4752 },
4753 },
4754 })
4755
Nick Harper60a85cb2016-09-23 16:25:11 -07004756 // Test Channel ID
4757 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004758 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004759 continue
4760 }
4761 // Client sends a Channel ID.
4762 tests = append(tests, testCase{
4763 name: "ChannelID-Client-" + ver.name,
4764 config: Config{
4765 MaxVersion: ver.version,
4766 RequestChannelID: true,
4767 },
David Benjamina5022392017-07-10 17:40:39 -04004768 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004769 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4770 resumeSession: true,
4771 expectChannelID: true,
4772 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004773
Nick Harper60a85cb2016-09-23 16:25:11 -07004774 // Server accepts a Channel ID.
4775 tests = append(tests, testCase{
4776 testType: serverTest,
4777 name: "ChannelID-Server-" + ver.name,
4778 config: Config{
4779 MaxVersion: ver.version,
4780 ChannelID: channelIDKey,
4781 },
David Benjamina5022392017-07-10 17:40:39 -04004782 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004783 flags: []string{
4784 "-expect-channel-id",
4785 base64.StdEncoding.EncodeToString(channelIDBytes),
4786 },
4787 resumeSession: true,
4788 expectChannelID: true,
4789 })
4790
4791 tests = append(tests, testCase{
4792 testType: serverTest,
4793 name: "InvalidChannelIDSignature-" + ver.name,
4794 config: Config{
4795 MaxVersion: ver.version,
4796 ChannelID: channelIDKey,
4797 Bugs: ProtocolBugs{
4798 InvalidChannelIDSignature: true,
4799 },
4800 },
David Benjamina5022392017-07-10 17:40:39 -04004801 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004802 flags: []string{"-enable-channel-id"},
4803 shouldFail: true,
4804 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4805 })
David Benjamin634f4752017-07-01 11:08:41 -04004806
4807 if ver.version < VersionTLS13 {
4808 // Channel ID requires ECDHE ciphers.
4809 tests = append(tests, testCase{
4810 testType: serverTest,
4811 name: "ChannelID-NoECDHE-" + ver.name,
4812 config: Config{
4813 MaxVersion: ver.version,
4814 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4815 ChannelID: channelIDKey,
4816 },
4817 expectChannelID: false,
4818 flags: []string{"-enable-channel-id"},
4819 })
4820
4821 // Sanity-check setting expectChannelID false works.
4822 tests = append(tests, testCase{
4823 testType: serverTest,
4824 name: "ChannelID-ECDHE-" + ver.name,
4825 config: Config{
4826 MaxVersion: ver.version,
4827 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4828 ChannelID: channelIDKey,
4829 },
4830 expectChannelID: false,
4831 flags: []string{"-enable-channel-id"},
4832 shouldFail: true,
4833 expectedLocalError: "channel ID unexpectedly negotiated",
4834 })
4835 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004836 }
David Benjamin30789da2015-08-29 22:56:45 -04004837
David Benjaminf8fcdf32016-06-08 15:56:13 -04004838 // Channel ID and NPN at the same time, to ensure their relative
4839 // ordering is correct.
4840 tests = append(tests, testCase{
4841 name: "ChannelID-NPN-Client",
4842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004843 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004844 RequestChannelID: true,
4845 NextProtos: []string{"foo"},
4846 },
4847 flags: []string{
4848 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4849 "-select-next-proto", "foo",
4850 },
4851 resumeSession: true,
4852 expectChannelID: true,
4853 expectedNextProto: "foo",
4854 expectedNextProtoType: npn,
4855 })
4856 tests = append(tests, testCase{
4857 testType: serverTest,
4858 name: "ChannelID-NPN-Server",
4859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004860 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004861 ChannelID: channelIDKey,
4862 NextProtos: []string{"bar"},
4863 },
4864 flags: []string{
4865 "-expect-channel-id",
4866 base64.StdEncoding.EncodeToString(channelIDBytes),
4867 "-advertise-npn", "\x03foo\x03bar\x03baz",
4868 "-expect-next-proto", "bar",
4869 },
4870 resumeSession: true,
4871 expectChannelID: true,
4872 expectedNextProto: "bar",
4873 expectedNextProtoType: npn,
4874 })
4875
David Benjamin30789da2015-08-29 22:56:45 -04004876 // Bidirectional shutdown with the runner initiating.
4877 tests = append(tests, testCase{
4878 name: "Shutdown-Runner",
4879 config: Config{
4880 Bugs: ProtocolBugs{
4881 ExpectCloseNotify: true,
4882 },
4883 },
4884 flags: []string{"-check-close-notify"},
4885 })
4886
David Benjamine3843d42017-03-25 18:00:56 -05004887 if !config.implicitHandshake {
4888 // Bidirectional shutdown with the shim initiating. The runner,
4889 // in the meantime, sends garbage before the close_notify which
4890 // the shim must ignore. This test is disabled under implicit
4891 // handshake tests because the shim never reads or writes.
4892 tests = append(tests, testCase{
4893 name: "Shutdown-Shim",
4894 config: Config{
4895 MaxVersion: VersionTLS12,
4896 Bugs: ProtocolBugs{
4897 ExpectCloseNotify: true,
4898 },
David Benjamin30789da2015-08-29 22:56:45 -04004899 },
David Benjamine3843d42017-03-25 18:00:56 -05004900 shimShutsDown: true,
4901 sendEmptyRecords: 1,
4902 sendWarningAlerts: 1,
4903 flags: []string{"-check-close-notify"},
4904 })
4905 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004906 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004907 // TODO(davidben): DTLS 1.3 will want a similar thing for
4908 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004909 tests = append(tests, testCase{
4910 name: "SkipHelloVerifyRequest",
4911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004912 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004913 Bugs: ProtocolBugs{
4914 SkipHelloVerifyRequest: true,
4915 },
4916 },
4917 })
4918 }
4919
David Benjamin760b1dd2015-05-15 23:33:48 -04004920 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004921 test.protocol = config.protocol
4922 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004923 test.name += "-DTLS"
4924 }
David Benjamin582ba042016-07-07 12:33:25 -07004925 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004926 test.name += "-Async"
4927 test.flags = append(test.flags, "-async")
4928 } else {
4929 test.name += "-Sync"
4930 }
David Benjamin582ba042016-07-07 12:33:25 -07004931 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004932 test.name += "-SplitHandshakeRecords"
4933 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004934 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004935 test.config.Bugs.MaxPacketLength = 256
4936 test.flags = append(test.flags, "-mtu", "256")
4937 }
4938 }
David Benjamin582ba042016-07-07 12:33:25 -07004939 if config.packHandshakeFlight {
4940 test.name += "-PackHandshakeFlight"
4941 test.config.Bugs.PackHandshakeFlight = true
4942 }
David Benjamine3843d42017-03-25 18:00:56 -05004943 if config.implicitHandshake {
4944 test.name += "-ImplicitHandshake"
4945 test.flags = append(test.flags, "-implicit-handshake")
4946 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004947 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004948 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004949}
4950
Adam Langley524e7172015-02-20 16:04:00 -08004951func addDDoSCallbackTests() {
4952 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004953 for _, resume := range []bool{false, true} {
4954 suffix := "Resume"
4955 if resume {
4956 suffix = "No" + suffix
4957 }
4958
4959 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004960 testType: serverTest,
4961 name: "Server-DDoS-OK-" + suffix,
4962 config: Config{
4963 MaxVersion: VersionTLS12,
4964 },
Adam Langley524e7172015-02-20 16:04:00 -08004965 flags: []string{"-install-ddos-callback"},
4966 resumeSession: resume,
4967 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004968 testCases = append(testCases, testCase{
4969 testType: serverTest,
4970 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4971 config: Config{
4972 MaxVersion: VersionTLS13,
4973 },
4974 flags: []string{"-install-ddos-callback"},
4975 resumeSession: resume,
4976 })
Adam Langley524e7172015-02-20 16:04:00 -08004977
4978 failFlag := "-fail-ddos-callback"
4979 if resume {
4980 failFlag = "-fail-second-ddos-callback"
4981 }
4982 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004983 testType: serverTest,
4984 name: "Server-DDoS-Reject-" + suffix,
4985 config: Config{
4986 MaxVersion: VersionTLS12,
4987 },
David Benjamin2c66e072016-09-16 15:58:00 -04004988 flags: []string{"-install-ddos-callback", failFlag},
4989 resumeSession: resume,
4990 shouldFail: true,
4991 expectedError: ":CONNECTION_REJECTED:",
4992 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004993 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004994 testCases = append(testCases, testCase{
4995 testType: serverTest,
4996 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4997 config: Config{
4998 MaxVersion: VersionTLS13,
4999 },
David Benjamin2c66e072016-09-16 15:58:00 -04005000 flags: []string{"-install-ddos-callback", failFlag},
5001 resumeSession: resume,
5002 shouldFail: true,
5003 expectedError: ":CONNECTION_REJECTED:",
5004 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005005 })
Adam Langley524e7172015-02-20 16:04:00 -08005006 }
5007}
5008
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005009func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005010 for _, protocol := range []protocol{tls, dtls} {
5011 for _, shimVers := range allVersions(protocol) {
5012 // Assemble flags to disable all newer versions on the shim.
5013 var flags []string
5014 for _, vers := range allVersions(protocol) {
5015 if vers.version > shimVers.version {
5016 flags = append(flags, vers.excludeFlag)
5017 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005018 }
Steven Valdez520e1222017-06-13 12:45:25 -04005019
5020 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5021
5022 if shimVers.tls13Variant != 0 {
5023 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5024 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5025 }
5026
5027 // Test configuring the runner's maximum version.
5028 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005029 expectedVersion := shimVers.version
5030 if runnerVers.version < shimVers.version {
5031 expectedVersion = runnerVers.version
5032 }
Steven Valdez520e1222017-06-13 12:45:25 -04005033 // When running and shim have different TLS 1.3 variants enabled,
5034 // shim clients are expected to fall back to TLS 1.2, while shim
5035 // servers support both variants when enabled when the experiment is
5036 // enabled.
5037 expectedServerVersion := expectedVersion
5038 expectedClientVersion := expectedVersion
5039 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5040 expectedClientVersion = VersionTLS12
5041 expectedServerVersion = VersionTLS12
5042 if shimVers.tls13Variant != TLS13Default {
5043 expectedServerVersion = VersionTLS13
5044 }
5045 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005046
David Benjamin8b8c0062014-11-23 02:47:52 -05005047 suffix := shimVers.name + "-" + runnerVers.name
5048 if protocol == dtls {
5049 suffix += "-DTLS"
5050 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005051
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005052 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005053 clientVers := shimVers.version
5054 if clientVers > VersionTLS10 {
5055 clientVers = VersionTLS10
5056 }
Steven Valdez520e1222017-06-13 12:45:25 -04005057 clientVers = recordVersionToWire(clientVers, protocol)
5058 serverVers := expectedServerVersion
5059 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005060 serverVers = VersionTLS10
5061 }
Steven Valdez520e1222017-06-13 12:45:25 -04005062 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005063
David Benjamin8b8c0062014-11-23 02:47:52 -05005064 testCases = append(testCases, testCase{
5065 protocol: protocol,
5066 testType: clientTest,
5067 name: "VersionNegotiation-Client-" + suffix,
5068 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005069 MaxVersion: runnerVers.version,
5070 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005071 Bugs: ProtocolBugs{
5072 ExpectInitialRecordVersion: clientVers,
5073 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005074 },
5075 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005076 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005077 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005078 testCases = append(testCases, testCase{
5079 protocol: protocol,
5080 testType: clientTest,
5081 name: "VersionNegotiation-Client2-" + suffix,
5082 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005083 MaxVersion: runnerVers.version,
5084 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005085 Bugs: ProtocolBugs{
5086 ExpectInitialRecordVersion: clientVers,
5087 },
5088 },
Steven Valdez520e1222017-06-13 12:45:25 -04005089 flags: flags2,
5090 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005091 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005092
5093 testCases = append(testCases, testCase{
5094 protocol: protocol,
5095 testType: serverTest,
5096 name: "VersionNegotiation-Server-" + suffix,
5097 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005098 MaxVersion: runnerVers.version,
5099 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005100 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005101 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005102 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005103 },
5104 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005105 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005106 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005107 testCases = append(testCases, testCase{
5108 protocol: protocol,
5109 testType: serverTest,
5110 name: "VersionNegotiation-Server2-" + suffix,
5111 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005112 MaxVersion: runnerVers.version,
5113 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005114 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005115 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005116 },
5117 },
Steven Valdez520e1222017-06-13 12:45:25 -04005118 flags: flags2,
5119 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005120 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005121 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005122 }
5123 }
David Benjamin95c69562016-06-29 18:15:03 -04005124
Steven Valdezfdd10992016-09-15 16:27:05 -04005125 // Test the version extension at all versions.
5126 for _, vers := range tlsVersions {
5127 protocols := []protocol{tls}
5128 if vers.hasDTLS {
5129 protocols = append(protocols, dtls)
5130 }
5131 for _, protocol := range protocols {
5132 suffix := vers.name
5133 if protocol == dtls {
5134 suffix += "-DTLS"
5135 }
5136
Steven Valdezfdd10992016-09-15 16:27:05 -04005137 testCases = append(testCases, testCase{
5138 protocol: protocol,
5139 testType: serverTest,
5140 name: "VersionNegotiationExtension-" + suffix,
5141 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005142 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005143 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005144 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005145 },
5146 },
5147 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005148 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005149 })
5150 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005151 }
5152
5153 // If all versions are unknown, negotiation fails.
5154 testCases = append(testCases, testCase{
5155 testType: serverTest,
5156 name: "NoSupportedVersions",
5157 config: Config{
5158 Bugs: ProtocolBugs{
5159 SendSupportedVersions: []uint16{0x1111},
5160 },
5161 },
5162 shouldFail: true,
5163 expectedError: ":UNSUPPORTED_PROTOCOL:",
5164 })
5165 testCases = append(testCases, testCase{
5166 protocol: dtls,
5167 testType: serverTest,
5168 name: "NoSupportedVersions-DTLS",
5169 config: Config{
5170 Bugs: ProtocolBugs{
5171 SendSupportedVersions: []uint16{0x1111},
5172 },
5173 },
5174 shouldFail: true,
5175 expectedError: ":UNSUPPORTED_PROTOCOL:",
5176 })
5177
5178 testCases = append(testCases, testCase{
5179 testType: serverTest,
5180 name: "ClientHelloVersionTooHigh",
5181 config: Config{
5182 MaxVersion: VersionTLS13,
5183 Bugs: ProtocolBugs{
5184 SendClientVersion: 0x0304,
5185 OmitSupportedVersions: true,
5186 },
5187 },
5188 expectedVersion: VersionTLS12,
5189 })
5190
5191 testCases = append(testCases, testCase{
5192 testType: serverTest,
5193 name: "ConflictingVersionNegotiation",
5194 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005195 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005196 SendClientVersion: VersionTLS12,
5197 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005198 },
5199 },
David Benjaminad75a662016-09-30 15:42:59 -04005200 // The extension takes precedence over the ClientHello version.
5201 expectedVersion: VersionTLS11,
5202 })
5203
5204 testCases = append(testCases, testCase{
5205 testType: serverTest,
5206 name: "ConflictingVersionNegotiation-2",
5207 config: Config{
5208 Bugs: ProtocolBugs{
5209 SendClientVersion: VersionTLS11,
5210 SendSupportedVersions: []uint16{VersionTLS12},
5211 },
5212 },
5213 // The extension takes precedence over the ClientHello version.
5214 expectedVersion: VersionTLS12,
5215 })
5216
5217 testCases = append(testCases, testCase{
5218 testType: serverTest,
5219 name: "RejectFinalTLS13",
5220 config: Config{
5221 Bugs: ProtocolBugs{
5222 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5223 },
5224 },
5225 // We currently implement a draft TLS 1.3 version. Ensure that
5226 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005227 expectedVersion: VersionTLS12,
5228 })
5229
Steven Valdez038da9b2017-07-10 12:57:25 -04005230 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5231 // the ServerHello.
5232 testCases = append(testCases, testCase{
5233 testType: clientTest,
5234 name: "SupportedVersionSelection-TLS12",
5235 config: Config{
5236 MaxVersion: VersionTLS12,
5237 Bugs: ProtocolBugs{
5238 SendServerSupportedExtensionVersion: VersionTLS12,
5239 },
5240 },
5241 shouldFail: true,
5242 expectedError: ":UNEXPECTED_EXTENSION:",
5243 })
5244
5245 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5246 // supported_versions extension in the ServerHello.
5247 testCases = append(testCases, testCase{
5248 testType: clientTest,
5249 name: "SupportedVersionSelection-TLS13",
5250 config: Config{
5251 MaxVersion: VersionTLS13,
5252 Bugs: ProtocolBugs{
5253 SendServerSupportedExtensionVersion: tls13DraftVersion,
5254 },
5255 },
5256 shouldFail: true,
5257 expectedError: ":UNEXPECTED_EXTENSION:",
5258 })
5259
Brian Smithf85d3232016-10-28 10:34:06 -10005260 // Test that the maximum version is selected regardless of the
5261 // client-sent order.
5262 testCases = append(testCases, testCase{
5263 testType: serverTest,
5264 name: "IgnoreClientVersionOrder",
5265 config: Config{
5266 Bugs: ProtocolBugs{
5267 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5268 },
5269 },
5270 expectedVersion: VersionTLS13,
5271 })
5272
David Benjamin95c69562016-06-29 18:15:03 -04005273 // Test for version tolerance.
5274 testCases = append(testCases, testCase{
5275 testType: serverTest,
5276 name: "MinorVersionTolerance",
5277 config: Config{
5278 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005279 SendClientVersion: 0x03ff,
5280 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005281 },
5282 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005283 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005284 })
5285 testCases = append(testCases, testCase{
5286 testType: serverTest,
5287 name: "MajorVersionTolerance",
5288 config: Config{
5289 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005290 SendClientVersion: 0x0400,
5291 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005292 },
5293 },
David Benjaminad75a662016-09-30 15:42:59 -04005294 // TLS 1.3 must be negotiated with the supported_versions
5295 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005296 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005297 })
David Benjaminad75a662016-09-30 15:42:59 -04005298 testCases = append(testCases, testCase{
5299 testType: serverTest,
5300 name: "VersionTolerance-TLS13",
5301 config: Config{
5302 Bugs: ProtocolBugs{
5303 // Although TLS 1.3 does not use
5304 // ClientHello.version, it still tolerates high
5305 // values there.
5306 SendClientVersion: 0x0400,
5307 },
5308 },
5309 expectedVersion: VersionTLS13,
5310 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005311
David Benjamin95c69562016-06-29 18:15:03 -04005312 testCases = append(testCases, testCase{
5313 protocol: dtls,
5314 testType: serverTest,
5315 name: "MinorVersionTolerance-DTLS",
5316 config: Config{
5317 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005318 SendClientVersion: 0xfe00,
5319 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005320 },
5321 },
5322 expectedVersion: VersionTLS12,
5323 })
5324 testCases = append(testCases, testCase{
5325 protocol: dtls,
5326 testType: serverTest,
5327 name: "MajorVersionTolerance-DTLS",
5328 config: Config{
5329 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005330 SendClientVersion: 0xfdff,
5331 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005332 },
5333 },
5334 expectedVersion: VersionTLS12,
5335 })
5336
5337 // Test that versions below 3.0 are rejected.
5338 testCases = append(testCases, testCase{
5339 testType: serverTest,
5340 name: "VersionTooLow",
5341 config: Config{
5342 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005343 SendClientVersion: 0x0200,
5344 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005345 },
5346 },
5347 shouldFail: true,
5348 expectedError: ":UNSUPPORTED_PROTOCOL:",
5349 })
5350 testCases = append(testCases, testCase{
5351 protocol: dtls,
5352 testType: serverTest,
5353 name: "VersionTooLow-DTLS",
5354 config: Config{
5355 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005356 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005357 },
5358 },
5359 shouldFail: true,
5360 expectedError: ":UNSUPPORTED_PROTOCOL:",
5361 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005362
David Benjamin2dc02042016-09-19 19:57:37 -04005363 testCases = append(testCases, testCase{
5364 name: "ServerBogusVersion",
5365 config: Config{
5366 Bugs: ProtocolBugs{
5367 SendServerHelloVersion: 0x1234,
5368 },
5369 },
5370 shouldFail: true,
5371 expectedError: ":UNSUPPORTED_PROTOCOL:",
5372 })
5373
David Benjamin1f61f0d2016-07-10 12:20:35 -04005374 // Test TLS 1.3's downgrade signal.
5375 testCases = append(testCases, testCase{
5376 name: "Downgrade-TLS12-Client",
5377 config: Config{
5378 Bugs: ProtocolBugs{
5379 NegotiateVersion: VersionTLS12,
5380 },
5381 },
David Benjamin592b5322016-09-30 15:15:01 -04005382 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005383 // TODO(davidben): This test should fail once TLS 1.3 is final
5384 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005385 })
5386 testCases = append(testCases, testCase{
5387 testType: serverTest,
5388 name: "Downgrade-TLS12-Server",
5389 config: Config{
5390 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005391 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005392 },
5393 },
David Benjamin592b5322016-09-30 15:15:01 -04005394 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005395 // TODO(davidben): This test should fail once TLS 1.3 is final
5396 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005397 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005398}
5399
David Benjaminaccb4542014-12-12 23:44:33 -05005400func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005401 for _, protocol := range []protocol{tls, dtls} {
5402 for _, shimVers := range allVersions(protocol) {
5403 // Assemble flags to disable all older versions on the shim.
5404 var flags []string
5405 for _, vers := range allVersions(protocol) {
5406 if vers.version < shimVers.version {
5407 flags = append(flags, vers.excludeFlag)
5408 }
David Benjaminaccb4542014-12-12 23:44:33 -05005409 }
Steven Valdez520e1222017-06-13 12:45:25 -04005410
5411 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5412
5413 if shimVers.tls13Variant != 0 {
5414 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5415 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5416 }
5417
5418 for _, runnerVers := range allVersions(protocol) {
5419 // Different TLS 1.3 variants are incompatible with each other and don't
5420 // produce consistent minimum versions.
5421 //
5422 // TODO(davidben): Fold these tests (the main value is in the
5423 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5424 // on intended shim behavior, not the shim + runner combination.
5425 if shimVers.tls13Variant != runnerVers.tls13Variant {
5426 continue
5427 }
5428
David Benjaminaccb4542014-12-12 23:44:33 -05005429 suffix := shimVers.name + "-" + runnerVers.name
5430 if protocol == dtls {
5431 suffix += "-DTLS"
5432 }
David Benjaminaccb4542014-12-12 23:44:33 -05005433
David Benjaminaccb4542014-12-12 23:44:33 -05005434 var expectedVersion uint16
5435 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005436 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005437 if runnerVers.version >= shimVers.version {
5438 expectedVersion = runnerVers.version
5439 } else {
5440 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005441 expectedError = ":UNSUPPORTED_PROTOCOL:"
5442 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005443 }
5444
5445 testCases = append(testCases, testCase{
5446 protocol: protocol,
5447 testType: clientTest,
5448 name: "MinimumVersion-Client-" + suffix,
5449 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005450 MaxVersion: runnerVers.version,
5451 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005452 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005453 // Ensure the server does not decline to
5454 // select a version (versions extension) or
5455 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005456 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005457 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005458 },
David Benjaminaccb4542014-12-12 23:44:33 -05005459 },
David Benjamin87909c02014-12-13 01:55:01 -05005460 flags: flags,
5461 expectedVersion: expectedVersion,
5462 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005463 expectedError: expectedError,
5464 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005465 })
5466 testCases = append(testCases, testCase{
5467 protocol: protocol,
5468 testType: clientTest,
5469 name: "MinimumVersion-Client2-" + suffix,
5470 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005471 MaxVersion: runnerVers.version,
5472 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005473 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005474 // Ensure the server does not decline to
5475 // select a version (versions extension) or
5476 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005477 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005478 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005479 },
David Benjaminaccb4542014-12-12 23:44:33 -05005480 },
Steven Valdez520e1222017-06-13 12:45:25 -04005481 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005482 expectedVersion: expectedVersion,
5483 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005484 expectedError: expectedError,
5485 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005486 })
5487
5488 testCases = append(testCases, testCase{
5489 protocol: protocol,
5490 testType: serverTest,
5491 name: "MinimumVersion-Server-" + suffix,
5492 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005493 MaxVersion: runnerVers.version,
5494 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005495 },
David Benjamin87909c02014-12-13 01:55:01 -05005496 flags: flags,
5497 expectedVersion: expectedVersion,
5498 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005499 expectedError: expectedError,
5500 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005501 })
5502 testCases = append(testCases, testCase{
5503 protocol: protocol,
5504 testType: serverTest,
5505 name: "MinimumVersion-Server2-" + suffix,
5506 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005507 MaxVersion: runnerVers.version,
5508 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005509 },
Steven Valdez520e1222017-06-13 12:45:25 -04005510 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005511 expectedVersion: expectedVersion,
5512 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005513 expectedError: expectedError,
5514 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005515 })
5516 }
5517 }
5518 }
5519}
5520
David Benjamine78bfde2014-09-06 12:45:15 -04005521func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005522 // TODO(davidben): Extensions, where applicable, all move their server
5523 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5524 // tests for both. Also test interaction with 0-RTT when implemented.
5525
David Benjamin97d17d92016-07-14 16:12:00 -04005526 // Repeat extensions tests all versions except SSL 3.0.
5527 for _, ver := range tlsVersions {
5528 if ver.version == VersionSSL30 {
5529 continue
5530 }
5531
David Benjamin97d17d92016-07-14 16:12:00 -04005532 // Test that duplicate extensions are rejected.
5533 testCases = append(testCases, testCase{
5534 testType: clientTest,
5535 name: "DuplicateExtensionClient-" + ver.name,
5536 config: Config{
5537 MaxVersion: ver.version,
5538 Bugs: ProtocolBugs{
5539 DuplicateExtension: true,
5540 },
David Benjamine78bfde2014-09-06 12:45:15 -04005541 },
David Benjamina5022392017-07-10 17:40:39 -04005542 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005543 shouldFail: true,
5544 expectedLocalError: "remote error: error decoding message",
5545 })
5546 testCases = append(testCases, testCase{
5547 testType: serverTest,
5548 name: "DuplicateExtensionServer-" + ver.name,
5549 config: Config{
5550 MaxVersion: ver.version,
5551 Bugs: ProtocolBugs{
5552 DuplicateExtension: true,
5553 },
David Benjamine78bfde2014-09-06 12:45:15 -04005554 },
David Benjamina5022392017-07-10 17:40:39 -04005555 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005556 shouldFail: true,
5557 expectedLocalError: "remote error: error decoding message",
5558 })
5559
5560 // Test SNI.
5561 testCases = append(testCases, testCase{
5562 testType: clientTest,
5563 name: "ServerNameExtensionClient-" + ver.name,
5564 config: Config{
5565 MaxVersion: ver.version,
5566 Bugs: ProtocolBugs{
5567 ExpectServerName: "example.com",
5568 },
David Benjamine78bfde2014-09-06 12:45:15 -04005569 },
David Benjamina5022392017-07-10 17:40:39 -04005570 tls13Variant: ver.tls13Variant,
5571 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005572 })
5573 testCases = append(testCases, testCase{
5574 testType: clientTest,
5575 name: "ServerNameExtensionClientMismatch-" + ver.name,
5576 config: Config{
5577 MaxVersion: ver.version,
5578 Bugs: ProtocolBugs{
5579 ExpectServerName: "mismatch.com",
5580 },
David Benjamine78bfde2014-09-06 12:45:15 -04005581 },
David Benjamin97d17d92016-07-14 16:12:00 -04005582 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005583 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005584 shouldFail: true,
5585 expectedLocalError: "tls: unexpected server name",
5586 })
5587 testCases = append(testCases, testCase{
5588 testType: clientTest,
5589 name: "ServerNameExtensionClientMissing-" + ver.name,
5590 config: Config{
5591 MaxVersion: ver.version,
5592 Bugs: ProtocolBugs{
5593 ExpectServerName: "missing.com",
5594 },
David Benjamine78bfde2014-09-06 12:45:15 -04005595 },
David Benjamina5022392017-07-10 17:40:39 -04005596 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005597 shouldFail: true,
5598 expectedLocalError: "tls: unexpected server name",
5599 })
5600 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005601 testType: clientTest,
5602 name: "TolerateServerNameAck-" + ver.name,
5603 config: Config{
5604 MaxVersion: ver.version,
5605 Bugs: ProtocolBugs{
5606 SendServerNameAck: true,
5607 },
5608 },
David Benjamina5022392017-07-10 17:40:39 -04005609 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005610 flags: []string{"-host-name", "example.com"},
5611 resumeSession: true,
5612 })
5613 testCases = append(testCases, testCase{
5614 testType: clientTest,
5615 name: "UnsolicitedServerNameAck-" + ver.name,
5616 config: Config{
5617 MaxVersion: ver.version,
5618 Bugs: ProtocolBugs{
5619 SendServerNameAck: true,
5620 },
5621 },
David Benjamina5022392017-07-10 17:40:39 -04005622 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005623 shouldFail: true,
5624 expectedError: ":UNEXPECTED_EXTENSION:",
5625 expectedLocalError: "remote error: unsupported extension",
5626 })
5627 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005628 testType: serverTest,
5629 name: "ServerNameExtensionServer-" + ver.name,
5630 config: Config{
5631 MaxVersion: ver.version,
5632 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005633 },
David Benjamina5022392017-07-10 17:40:39 -04005634 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005635 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005636 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005637 })
5638
5639 // Test ALPN.
5640 testCases = append(testCases, testCase{
5641 testType: clientTest,
5642 name: "ALPNClient-" + ver.name,
5643 config: Config{
5644 MaxVersion: ver.version,
5645 NextProtos: []string{"foo"},
5646 },
5647 flags: []string{
5648 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5649 "-expect-alpn", "foo",
5650 },
David Benjamina5022392017-07-10 17:40:39 -04005651 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005652 expectedNextProto: "foo",
5653 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005654 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005655 })
5656 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005657 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005658 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005659 config: Config{
5660 MaxVersion: ver.version,
5661 Bugs: ProtocolBugs{
5662 SendALPN: "baz",
5663 },
5664 },
5665 flags: []string{
5666 "-advertise-alpn", "\x03foo\x03bar",
5667 },
David Benjamina5022392017-07-10 17:40:39 -04005668 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005669 shouldFail: true,
5670 expectedError: ":INVALID_ALPN_PROTOCOL:",
5671 expectedLocalError: "remote error: illegal parameter",
5672 })
5673 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005674 testType: clientTest,
5675 name: "ALPNClient-AllowUnknown-" + ver.name,
5676 config: Config{
5677 MaxVersion: ver.version,
5678 Bugs: ProtocolBugs{
5679 SendALPN: "baz",
5680 },
5681 },
5682 flags: []string{
5683 "-advertise-alpn", "\x03foo\x03bar",
5684 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005685 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005686 },
David Benjamina5022392017-07-10 17:40:39 -04005687 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005688 })
5689 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005690 testType: serverTest,
5691 name: "ALPNServer-" + ver.name,
5692 config: Config{
5693 MaxVersion: ver.version,
5694 NextProtos: []string{"foo", "bar", "baz"},
5695 },
5696 flags: []string{
5697 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5698 "-select-alpn", "foo",
5699 },
David Benjamina5022392017-07-10 17:40:39 -04005700 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005701 expectedNextProto: "foo",
5702 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005703 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005704 })
5705 testCases = append(testCases, testCase{
5706 testType: serverTest,
5707 name: "ALPNServer-Decline-" + ver.name,
5708 config: Config{
5709 MaxVersion: ver.version,
5710 NextProtos: []string{"foo", "bar", "baz"},
5711 },
5712 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005713 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005714 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005715 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005716 })
5717
David Benjamin25fe85b2016-08-09 20:00:32 -04005718 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5719 // called once.
5720 testCases = append(testCases, testCase{
5721 testType: serverTest,
5722 name: "ALPNServer-Async-" + ver.name,
5723 config: Config{
5724 MaxVersion: ver.version,
5725 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005726 // Prior to TLS 1.3, exercise the asynchronous session callback.
5727 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005728 },
5729 flags: []string{
5730 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5731 "-select-alpn", "foo",
5732 "-async",
5733 },
David Benjamina5022392017-07-10 17:40:39 -04005734 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005735 expectedNextProto: "foo",
5736 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005737 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005738 })
5739
David Benjamin97d17d92016-07-14 16:12:00 -04005740 var emptyString string
5741 testCases = append(testCases, testCase{
5742 testType: clientTest,
5743 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5744 config: Config{
5745 MaxVersion: ver.version,
5746 NextProtos: []string{""},
5747 Bugs: ProtocolBugs{
5748 // A server returning an empty ALPN protocol
5749 // should be rejected.
5750 ALPNProtocol: &emptyString,
5751 },
5752 },
5753 flags: []string{
5754 "-advertise-alpn", "\x03foo",
5755 },
David Benjamina5022392017-07-10 17:40:39 -04005756 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005757 shouldFail: true,
5758 expectedError: ":PARSE_TLSEXT:",
5759 })
5760 testCases = append(testCases, testCase{
5761 testType: serverTest,
5762 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5763 config: Config{
5764 MaxVersion: ver.version,
5765 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005766 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005767 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005768 },
David Benjamin97d17d92016-07-14 16:12:00 -04005769 flags: []string{
5770 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005771 },
David Benjamina5022392017-07-10 17:40:39 -04005772 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005773 shouldFail: true,
5774 expectedError: ":PARSE_TLSEXT:",
5775 })
5776
5777 // Test NPN and the interaction with ALPN.
5778 if ver.version < VersionTLS13 {
5779 // Test that the server prefers ALPN over NPN.
5780 testCases = append(testCases, testCase{
5781 testType: serverTest,
5782 name: "ALPNServer-Preferred-" + ver.name,
5783 config: Config{
5784 MaxVersion: ver.version,
5785 NextProtos: []string{"foo", "bar", "baz"},
5786 },
5787 flags: []string{
5788 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5789 "-select-alpn", "foo",
5790 "-advertise-npn", "\x03foo\x03bar\x03baz",
5791 },
David Benjamina5022392017-07-10 17:40:39 -04005792 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005793 expectedNextProto: "foo",
5794 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005795 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005796 })
5797 testCases = append(testCases, testCase{
5798 testType: serverTest,
5799 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5800 config: Config{
5801 MaxVersion: ver.version,
5802 NextProtos: []string{"foo", "bar", "baz"},
5803 Bugs: ProtocolBugs{
5804 SwapNPNAndALPN: true,
5805 },
5806 },
5807 flags: []string{
5808 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5809 "-select-alpn", "foo",
5810 "-advertise-npn", "\x03foo\x03bar\x03baz",
5811 },
David Benjamina5022392017-07-10 17:40:39 -04005812 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005813 expectedNextProto: "foo",
5814 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005815 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005816 })
5817
5818 // Test that negotiating both NPN and ALPN is forbidden.
5819 testCases = append(testCases, testCase{
5820 name: "NegotiateALPNAndNPN-" + ver.name,
5821 config: Config{
5822 MaxVersion: ver.version,
5823 NextProtos: []string{"foo", "bar", "baz"},
5824 Bugs: ProtocolBugs{
5825 NegotiateALPNAndNPN: true,
5826 },
5827 },
5828 flags: []string{
5829 "-advertise-alpn", "\x03foo",
5830 "-select-next-proto", "foo",
5831 },
David Benjamina5022392017-07-10 17:40:39 -04005832 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005833 shouldFail: true,
5834 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5835 })
5836 testCases = append(testCases, testCase{
5837 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5838 config: Config{
5839 MaxVersion: ver.version,
5840 NextProtos: []string{"foo", "bar", "baz"},
5841 Bugs: ProtocolBugs{
5842 NegotiateALPNAndNPN: true,
5843 SwapNPNAndALPN: true,
5844 },
5845 },
5846 flags: []string{
5847 "-advertise-alpn", "\x03foo",
5848 "-select-next-proto", "foo",
5849 },
David Benjamina5022392017-07-10 17:40:39 -04005850 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005851 shouldFail: true,
5852 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5853 })
David Benjamin97d17d92016-07-14 16:12:00 -04005854 }
5855
5856 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005857
5858 // Resume with a corrupt ticket.
5859 testCases = append(testCases, testCase{
5860 testType: serverTest,
5861 name: "CorruptTicket-" + ver.name,
5862 config: Config{
5863 MaxVersion: ver.version,
5864 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005865 FilterTicket: func(in []byte) ([]byte, error) {
5866 in[len(in)-1] ^= 1
5867 return in, nil
5868 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005869 },
5870 },
David Benjamina5022392017-07-10 17:40:39 -04005871 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005872 resumeSession: true,
5873 expectResumeRejected: true,
5874 })
5875 // Test the ticket callback, with and without renewal.
5876 testCases = append(testCases, testCase{
5877 testType: serverTest,
5878 name: "TicketCallback-" + ver.name,
5879 config: Config{
5880 MaxVersion: ver.version,
5881 },
David Benjamina5022392017-07-10 17:40:39 -04005882 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005883 resumeSession: true,
5884 flags: []string{"-use-ticket-callback"},
5885 })
5886 testCases = append(testCases, testCase{
5887 testType: serverTest,
5888 name: "TicketCallback-Renew-" + ver.name,
5889 config: Config{
5890 MaxVersion: ver.version,
5891 Bugs: ProtocolBugs{
5892 ExpectNewTicket: true,
5893 },
5894 },
David Benjamina5022392017-07-10 17:40:39 -04005895 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005896 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5897 resumeSession: true,
5898 })
5899
5900 // Test that the ticket callback is only called once when everything before
5901 // it in the ClientHello is asynchronous. This corrupts the ticket so
5902 // certificate selection callbacks run.
5903 testCases = append(testCases, testCase{
5904 testType: serverTest,
5905 name: "TicketCallback-SingleCall-" + ver.name,
5906 config: Config{
5907 MaxVersion: ver.version,
5908 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005909 FilterTicket: func(in []byte) ([]byte, error) {
5910 in[len(in)-1] ^= 1
5911 return in, nil
5912 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005913 },
5914 },
David Benjamina5022392017-07-10 17:40:39 -04005915 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005916 resumeSession: true,
5917 expectResumeRejected: true,
5918 flags: []string{
5919 "-use-ticket-callback",
5920 "-async",
5921 },
5922 })
5923
David Benjamind4c349b2017-02-09 14:07:17 -05005924 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005925 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005926 testCases = append(testCases, testCase{
5927 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005928 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005929 config: Config{
5930 MaxVersion: ver.version,
5931 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005932 EmptyTicketSessionID: true,
5933 },
5934 },
5935 resumeSession: true,
5936 })
5937 testCases = append(testCases, testCase{
5938 testType: serverTest,
5939 name: "TicketSessionIDLength-16-" + ver.name,
5940 config: Config{
5941 MaxVersion: ver.version,
5942 Bugs: ProtocolBugs{
5943 TicketSessionIDLength: 16,
5944 },
5945 },
5946 resumeSession: true,
5947 })
5948 testCases = append(testCases, testCase{
5949 testType: serverTest,
5950 name: "TicketSessionIDLength-32-" + ver.name,
5951 config: Config{
5952 MaxVersion: ver.version,
5953 Bugs: ProtocolBugs{
5954 TicketSessionIDLength: 32,
5955 },
5956 },
5957 resumeSession: true,
5958 })
5959 testCases = append(testCases, testCase{
5960 testType: serverTest,
5961 name: "TicketSessionIDLength-33-" + ver.name,
5962 config: Config{
5963 MaxVersion: ver.version,
5964 Bugs: ProtocolBugs{
5965 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005966 },
5967 },
5968 resumeSession: true,
5969 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005970 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005971 expectedError: ":DECODE_ERROR:",
5972 })
5973 }
5974
5975 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5976 // are ignored.
5977 if ver.hasDTLS {
5978 testCases = append(testCases, testCase{
5979 protocol: dtls,
5980 name: "SRTP-Client-" + ver.name,
5981 config: Config{
5982 MaxVersion: ver.version,
5983 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5984 },
5985 flags: []string{
5986 "-srtp-profiles",
5987 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5988 },
5989 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5990 })
5991 testCases = append(testCases, testCase{
5992 protocol: dtls,
5993 testType: serverTest,
5994 name: "SRTP-Server-" + ver.name,
5995 config: Config{
5996 MaxVersion: ver.version,
5997 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5998 },
5999 flags: []string{
6000 "-srtp-profiles",
6001 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6002 },
6003 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6004 })
6005 // Test that the MKI is ignored.
6006 testCases = append(testCases, testCase{
6007 protocol: dtls,
6008 testType: serverTest,
6009 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6010 config: Config{
6011 MaxVersion: ver.version,
6012 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6013 Bugs: ProtocolBugs{
6014 SRTPMasterKeyIdentifer: "bogus",
6015 },
6016 },
6017 flags: []string{
6018 "-srtp-profiles",
6019 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6020 },
6021 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6022 })
6023 // Test that SRTP isn't negotiated on the server if there were
6024 // no matching profiles.
6025 testCases = append(testCases, testCase{
6026 protocol: dtls,
6027 testType: serverTest,
6028 name: "SRTP-Server-NoMatch-" + ver.name,
6029 config: Config{
6030 MaxVersion: ver.version,
6031 SRTPProtectionProfiles: []uint16{100, 101, 102},
6032 },
6033 flags: []string{
6034 "-srtp-profiles",
6035 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6036 },
6037 expectedSRTPProtectionProfile: 0,
6038 })
6039 // Test that the server returning an invalid SRTP profile is
6040 // flagged as an error by the client.
6041 testCases = append(testCases, testCase{
6042 protocol: dtls,
6043 name: "SRTP-Client-NoMatch-" + ver.name,
6044 config: Config{
6045 MaxVersion: ver.version,
6046 Bugs: ProtocolBugs{
6047 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6048 },
6049 },
6050 flags: []string{
6051 "-srtp-profiles",
6052 "SRTP_AES128_CM_SHA1_80",
6053 },
6054 shouldFail: true,
6055 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6056 })
6057 }
6058
6059 // Test SCT list.
6060 testCases = append(testCases, testCase{
6061 name: "SignedCertificateTimestampList-Client-" + ver.name,
6062 testType: clientTest,
6063 config: Config{
6064 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006065 },
David Benjamin97d17d92016-07-14 16:12:00 -04006066 flags: []string{
6067 "-enable-signed-cert-timestamps",
6068 "-expect-signed-cert-timestamps",
6069 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006070 },
David Benjamina5022392017-07-10 17:40:39 -04006071 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006072 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006073 })
David Benjamindaa88502016-10-04 16:32:16 -04006074
Adam Langleycfa08c32016-11-17 13:21:27 -08006075 var differentSCTList []byte
6076 differentSCTList = append(differentSCTList, testSCTList...)
6077 differentSCTList[len(differentSCTList)-1] ^= 1
6078
David Benjamindaa88502016-10-04 16:32:16 -04006079 // The SCT extension did not specify that it must only be sent on resumption as it
6080 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006081 testCases = append(testCases, testCase{
6082 name: "SendSCTListOnResume-" + ver.name,
6083 config: Config{
6084 MaxVersion: ver.version,
6085 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006086 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006087 },
David Benjamind98452d2015-06-16 14:16:23 -04006088 },
David Benjamin97d17d92016-07-14 16:12:00 -04006089 flags: []string{
6090 "-enable-signed-cert-timestamps",
6091 "-expect-signed-cert-timestamps",
6092 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006093 },
David Benjamina5022392017-07-10 17:40:39 -04006094 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006095 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006096 })
David Benjamindaa88502016-10-04 16:32:16 -04006097
David Benjamin97d17d92016-07-14 16:12:00 -04006098 testCases = append(testCases, testCase{
6099 name: "SignedCertificateTimestampList-Server-" + ver.name,
6100 testType: serverTest,
6101 config: Config{
6102 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006103 },
David Benjamin97d17d92016-07-14 16:12:00 -04006104 flags: []string{
6105 "-signed-cert-timestamps",
6106 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006107 },
David Benjamina5022392017-07-10 17:40:39 -04006108 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006109 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006110 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006111 })
David Benjamin53210cb2016-11-16 09:01:48 +09006112
Adam Langleycfa08c32016-11-17 13:21:27 -08006113 emptySCTListCert := *testCerts[0].cert
6114 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6115
6116 // Test empty SCT list.
6117 testCases = append(testCases, testCase{
6118 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6119 testType: clientTest,
6120 config: Config{
6121 MaxVersion: ver.version,
6122 Certificates: []Certificate{emptySCTListCert},
6123 },
6124 flags: []string{
6125 "-enable-signed-cert-timestamps",
6126 },
David Benjamina5022392017-07-10 17:40:39 -04006127 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006128 shouldFail: true,
6129 expectedError: ":ERROR_PARSING_EXTENSION:",
6130 })
6131
6132 emptySCTCert := *testCerts[0].cert
6133 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6134
6135 // Test empty SCT in non-empty list.
6136 testCases = append(testCases, testCase{
6137 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6138 testType: clientTest,
6139 config: Config{
6140 MaxVersion: ver.version,
6141 Certificates: []Certificate{emptySCTCert},
6142 },
6143 flags: []string{
6144 "-enable-signed-cert-timestamps",
6145 },
David Benjamina5022392017-07-10 17:40:39 -04006146 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006147 shouldFail: true,
6148 expectedError: ":ERROR_PARSING_EXTENSION:",
6149 })
6150
David Benjamin53210cb2016-11-16 09:01:48 +09006151 // Test that certificate-related extensions are not sent unsolicited.
6152 testCases = append(testCases, testCase{
6153 testType: serverTest,
6154 name: "UnsolicitedCertificateExtensions-" + ver.name,
6155 config: Config{
6156 MaxVersion: ver.version,
6157 Bugs: ProtocolBugs{
6158 NoOCSPStapling: true,
6159 NoSignedCertificateTimestamps: true,
6160 },
6161 },
David Benjamina5022392017-07-10 17:40:39 -04006162 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006163 flags: []string{
6164 "-ocsp-response",
6165 base64.StdEncoding.EncodeToString(testOCSPResponse),
6166 "-signed-cert-timestamps",
6167 base64.StdEncoding.EncodeToString(testSCTList),
6168 },
6169 })
David Benjamin97d17d92016-07-14 16:12:00 -04006170 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171
Paul Lietar4fac72e2015-09-09 13:44:55 +01006172 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006173 testType: clientTest,
6174 name: "ClientHelloPadding",
6175 config: Config{
6176 Bugs: ProtocolBugs{
6177 RequireClientHelloSize: 512,
6178 },
6179 },
6180 // This hostname just needs to be long enough to push the
6181 // ClientHello into F5's danger zone between 256 and 511 bytes
6182 // long.
6183 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6184 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006185
6186 // Extensions should not function in SSL 3.0.
6187 testCases = append(testCases, testCase{
6188 testType: serverTest,
6189 name: "SSLv3Extensions-NoALPN",
6190 config: Config{
6191 MaxVersion: VersionSSL30,
6192 NextProtos: []string{"foo", "bar", "baz"},
6193 },
6194 flags: []string{
6195 "-select-alpn", "foo",
6196 },
6197 expectNoNextProto: true,
6198 })
6199
6200 // Test session tickets separately as they follow a different codepath.
6201 testCases = append(testCases, testCase{
6202 testType: serverTest,
6203 name: "SSLv3Extensions-NoTickets",
6204 config: Config{
6205 MaxVersion: VersionSSL30,
6206 Bugs: ProtocolBugs{
6207 // Historically, session tickets in SSL 3.0
6208 // failed in different ways depending on whether
6209 // the client supported renegotiation_info.
6210 NoRenegotiationInfo: true,
6211 },
6212 },
6213 resumeSession: true,
6214 })
6215 testCases = append(testCases, testCase{
6216 testType: serverTest,
6217 name: "SSLv3Extensions-NoTickets2",
6218 config: Config{
6219 MaxVersion: VersionSSL30,
6220 },
6221 resumeSession: true,
6222 })
6223
6224 // But SSL 3.0 does send and process renegotiation_info.
6225 testCases = append(testCases, testCase{
6226 testType: serverTest,
6227 name: "SSLv3Extensions-RenegotiationInfo",
6228 config: Config{
6229 MaxVersion: VersionSSL30,
6230 Bugs: ProtocolBugs{
6231 RequireRenegotiationInfo: true,
6232 },
6233 },
David Benjamind2610042017-01-03 10:49:28 -05006234 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006235 })
6236 testCases = append(testCases, testCase{
6237 testType: serverTest,
6238 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6239 config: Config{
6240 MaxVersion: VersionSSL30,
6241 Bugs: ProtocolBugs{
6242 NoRenegotiationInfo: true,
6243 SendRenegotiationSCSV: true,
6244 RequireRenegotiationInfo: true,
6245 },
6246 },
David Benjamind2610042017-01-03 10:49:28 -05006247 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006248 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006249
6250 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6251 // in ServerHello.
6252 testCases = append(testCases, testCase{
6253 name: "NPN-Forbidden-TLS13",
6254 config: Config{
6255 MaxVersion: VersionTLS13,
6256 NextProtos: []string{"foo"},
6257 Bugs: ProtocolBugs{
6258 NegotiateNPNAtAllVersions: true,
6259 },
6260 },
6261 flags: []string{"-select-next-proto", "foo"},
6262 shouldFail: true,
6263 expectedError: ":ERROR_PARSING_EXTENSION:",
6264 })
6265 testCases = append(testCases, testCase{
6266 name: "EMS-Forbidden-TLS13",
6267 config: Config{
6268 MaxVersion: VersionTLS13,
6269 Bugs: ProtocolBugs{
6270 NegotiateEMSAtAllVersions: true,
6271 },
6272 },
6273 shouldFail: true,
6274 expectedError: ":ERROR_PARSING_EXTENSION:",
6275 })
6276 testCases = append(testCases, testCase{
6277 name: "RenegotiationInfo-Forbidden-TLS13",
6278 config: Config{
6279 MaxVersion: VersionTLS13,
6280 Bugs: ProtocolBugs{
6281 NegotiateRenegotiationInfoAtAllVersions: true,
6282 },
6283 },
6284 shouldFail: true,
6285 expectedError: ":ERROR_PARSING_EXTENSION:",
6286 })
6287 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006288 name: "Ticket-Forbidden-TLS13",
6289 config: Config{
6290 MaxVersion: VersionTLS12,
6291 },
6292 resumeConfig: &Config{
6293 MaxVersion: VersionTLS13,
6294 Bugs: ProtocolBugs{
6295 AdvertiseTicketExtension: true,
6296 },
6297 },
6298 resumeSession: true,
6299 shouldFail: true,
6300 expectedError: ":ERROR_PARSING_EXTENSION:",
6301 })
6302
6303 // Test that illegal extensions in TLS 1.3 are declined by the server if
6304 // offered in ClientHello. The runner's server will fail if this occurs,
6305 // so we exercise the offering path. (EMS and Renegotiation Info are
6306 // implicit in every test.)
6307 testCases = append(testCases, testCase{
6308 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006309 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006310 config: Config{
6311 MaxVersion: VersionTLS13,
6312 NextProtos: []string{"bar"},
6313 },
6314 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6315 })
David Benjamin196df5b2016-09-21 16:23:27 -04006316
David Benjamindaa88502016-10-04 16:32:16 -04006317 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6318 // tolerated.
6319 testCases = append(testCases, testCase{
6320 name: "SendOCSPResponseOnResume-TLS12",
6321 config: Config{
6322 MaxVersion: VersionTLS12,
6323 Bugs: ProtocolBugs{
6324 SendOCSPResponseOnResume: []byte("bogus"),
6325 },
6326 },
6327 flags: []string{
6328 "-enable-ocsp-stapling",
6329 "-expect-ocsp-response",
6330 base64.StdEncoding.EncodeToString(testOCSPResponse),
6331 },
6332 resumeSession: true,
6333 })
6334
David Benjamindaa88502016-10-04 16:32:16 -04006335 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006336 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006337 config: Config{
6338 MaxVersion: VersionTLS13,
6339 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006340 SendExtensionOnCertificate: testOCSPExtension,
6341 },
6342 },
6343 shouldFail: true,
6344 expectedError: ":UNEXPECTED_EXTENSION:",
6345 })
6346
6347 testCases = append(testCases, testCase{
6348 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6349 config: Config{
6350 MaxVersion: VersionTLS13,
6351 Bugs: ProtocolBugs{
6352 SendExtensionOnCertificate: testSCTExtension,
6353 },
6354 },
6355 shouldFail: true,
6356 expectedError: ":UNEXPECTED_EXTENSION:",
6357 })
6358
6359 // Test that extensions on client certificates are never accepted.
6360 testCases = append(testCases, testCase{
6361 name: "SendExtensionOnClientCertificate-TLS13",
6362 testType: serverTest,
6363 config: Config{
6364 MaxVersion: VersionTLS13,
6365 Certificates: []Certificate{rsaCertificate},
6366 Bugs: ProtocolBugs{
6367 SendExtensionOnCertificate: testOCSPExtension,
6368 },
6369 },
6370 flags: []string{
6371 "-enable-ocsp-stapling",
6372 "-require-any-client-certificate",
6373 },
6374 shouldFail: true,
6375 expectedError: ":UNEXPECTED_EXTENSION:",
6376 })
6377
6378 testCases = append(testCases, testCase{
6379 name: "SendUnknownExtensionOnCertificate-TLS13",
6380 config: Config{
6381 MaxVersion: VersionTLS13,
6382 Bugs: ProtocolBugs{
6383 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6384 },
6385 },
6386 shouldFail: true,
6387 expectedError: ":UNEXPECTED_EXTENSION:",
6388 })
6389
Adam Langleycfa08c32016-11-17 13:21:27 -08006390 var differentSCTList []byte
6391 differentSCTList = append(differentSCTList, testSCTList...)
6392 differentSCTList[len(differentSCTList)-1] ^= 1
6393
Steven Valdeza833c352016-11-01 13:39:36 -04006394 // Test that extensions on intermediates are allowed but ignored.
6395 testCases = append(testCases, testCase{
6396 name: "IgnoreExtensionsOnIntermediates-TLS13",
6397 config: Config{
6398 MaxVersion: VersionTLS13,
6399 Certificates: []Certificate{rsaChainCertificate},
6400 Bugs: ProtocolBugs{
6401 // Send different values on the intermediate. This tests
6402 // the intermediate's extensions do not override the
6403 // leaf's.
6404 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006405 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006406 },
6407 },
6408 flags: []string{
6409 "-enable-ocsp-stapling",
6410 "-expect-ocsp-response",
6411 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006412 "-enable-signed-cert-timestamps",
6413 "-expect-signed-cert-timestamps",
6414 base64.StdEncoding.EncodeToString(testSCTList),
6415 },
6416 resumeSession: true,
6417 })
6418
6419 // Test that extensions are not sent on intermediates when configured
6420 // only for a leaf.
6421 testCases = append(testCases, testCase{
6422 testType: serverTest,
6423 name: "SendNoExtensionsOnIntermediate-TLS13",
6424 config: Config{
6425 MaxVersion: VersionTLS13,
6426 Bugs: ProtocolBugs{
6427 ExpectNoExtensionsOnIntermediate: true,
6428 },
6429 },
6430 flags: []string{
6431 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6432 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6433 "-ocsp-response",
6434 base64.StdEncoding.EncodeToString(testOCSPResponse),
6435 "-signed-cert-timestamps",
6436 base64.StdEncoding.EncodeToString(testSCTList),
6437 },
6438 })
6439
6440 // Test that extensions are not sent on client certificates.
6441 testCases = append(testCases, testCase{
6442 name: "SendNoClientCertificateExtensions-TLS13",
6443 config: Config{
6444 MaxVersion: VersionTLS13,
6445 ClientAuth: RequireAnyClientCert,
6446 },
6447 flags: []string{
6448 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6449 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6450 "-ocsp-response",
6451 base64.StdEncoding.EncodeToString(testOCSPResponse),
6452 "-signed-cert-timestamps",
6453 base64.StdEncoding.EncodeToString(testSCTList),
6454 },
6455 })
6456
6457 testCases = append(testCases, testCase{
6458 name: "SendDuplicateExtensionsOnCerts-TLS13",
6459 config: Config{
6460 MaxVersion: VersionTLS13,
6461 Bugs: ProtocolBugs{
6462 SendDuplicateCertExtensions: true,
6463 },
6464 },
6465 flags: []string{
6466 "-enable-ocsp-stapling",
6467 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006468 },
6469 resumeSession: true,
6470 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006471 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006472 })
Adam Langley9b885c52016-11-18 14:21:03 -08006473
6474 testCases = append(testCases, testCase{
6475 name: "SignedCertificateTimestampListInvalid-Server",
6476 testType: serverTest,
6477 flags: []string{
6478 "-signed-cert-timestamps",
6479 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6480 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006481 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006482 expectedError: ":INVALID_SCT_LIST:",
6483 })
David Benjamine78bfde2014-09-06 12:45:15 -04006484}
6485
David Benjamin01fe8202014-09-24 15:21:44 -04006486func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006487 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006488 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006489 // SSL 3.0 does not have tickets and TLS 1.3 does not
6490 // have session IDs, so skip their cross-resumption
6491 // tests.
6492 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6493 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6494 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006495 }
6496
David Benjamin8b8c0062014-11-23 02:47:52 -05006497 protocols := []protocol{tls}
6498 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6499 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006500 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006501 for _, protocol := range protocols {
6502 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6503 if protocol == dtls {
6504 suffix += "-DTLS"
6505 }
6506
Steven Valdez520e1222017-06-13 12:45:25 -04006507 // We can't resume across TLS 1.3 variants and error out earlier in the
6508 // session resumption.
6509 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6510 continue
6511 }
6512
David Benjaminece3de92015-03-16 18:02:20 -04006513 if sessionVers.version == resumeVers.version {
6514 testCases = append(testCases, testCase{
6515 protocol: protocol,
6516 name: "Resume-Client" + suffix,
6517 resumeSession: true,
6518 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006519 MaxVersion: sessionVers.version,
6520 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006521 Bugs: ProtocolBugs{
6522 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6523 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6524 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006525 },
David Benjaminece3de92015-03-16 18:02:20 -04006526 expectedVersion: sessionVers.version,
6527 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006528 flags: []string{
6529 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6530 },
David Benjaminece3de92015-03-16 18:02:20 -04006531 })
6532 } else {
David Benjamin405da482016-08-08 17:25:07 -04006533 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6534
6535 // Offering a TLS 1.3 session sends an empty session ID, so
6536 // there is no way to convince a non-lookahead client the
6537 // session was resumed. It will appear to the client that a
6538 // stray ChangeCipherSpec was sent.
6539 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6540 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006541 }
6542
David Benjaminece3de92015-03-16 18:02:20 -04006543 testCases = append(testCases, testCase{
6544 protocol: protocol,
6545 name: "Resume-Client-Mismatch" + suffix,
6546 resumeSession: true,
6547 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006548 MaxVersion: sessionVers.version,
6549 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006550 },
David Benjaminece3de92015-03-16 18:02:20 -04006551 expectedVersion: sessionVers.version,
6552 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006553 MaxVersion: resumeVers.version,
6554 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006555 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006556 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006557 },
6558 },
6559 expectedResumeVersion: resumeVers.version,
6560 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006561 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006562 flags: []string{
6563 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6564 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6565 },
David Benjaminece3de92015-03-16 18:02:20 -04006566 })
6567 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006568
6569 testCases = append(testCases, testCase{
6570 protocol: protocol,
6571 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006572 resumeSession: true,
6573 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006574 MaxVersion: sessionVers.version,
6575 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006576 },
6577 expectedVersion: sessionVers.version,
6578 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006579 MaxVersion: resumeVers.version,
6580 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006581 },
6582 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006583 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006584 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006585 flags: []string{
6586 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6587 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6588 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006589 })
6590
David Benjamin8b8c0062014-11-23 02:47:52 -05006591 testCases = append(testCases, testCase{
6592 protocol: protocol,
6593 testType: serverTest,
6594 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006595 resumeSession: true,
6596 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006597 MaxVersion: sessionVers.version,
6598 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006599 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006600 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006601 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006602 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006603 MaxVersion: resumeVers.version,
6604 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006605 Bugs: ProtocolBugs{
6606 SendBothTickets: true,
6607 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006608 },
6609 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006610 flags: []string{
6611 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6612 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6613 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006614 })
6615 }
David Benjamin01fe8202014-09-24 15:21:44 -04006616 }
6617 }
David Benjaminece3de92015-03-16 18:02:20 -04006618
David Benjamin4199b0d2016-11-01 13:58:25 -04006619 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006620 testCases = append(testCases, testCase{
6621 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006622 name: "ShimTicketRewritable",
6623 resumeSession: true,
6624 config: Config{
6625 MaxVersion: VersionTLS12,
6626 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6627 Bugs: ProtocolBugs{
6628 FilterTicket: func(in []byte) ([]byte, error) {
6629 in, err := SetShimTicketVersion(in, VersionTLS12)
6630 if err != nil {
6631 return nil, err
6632 }
6633 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6634 },
6635 },
6636 },
6637 flags: []string{
6638 "-ticket-key",
6639 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6640 },
6641 })
6642
6643 // Resumptions are declined if the version does not match.
6644 testCases = append(testCases, testCase{
6645 testType: serverTest,
6646 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006647 resumeSession: true,
6648 config: Config{
6649 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006650 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006651 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006652 FilterTicket: func(in []byte) ([]byte, error) {
6653 return SetShimTicketVersion(in, VersionTLS13)
6654 },
6655 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006656 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006657 flags: []string{
6658 "-ticket-key",
6659 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6660 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006661 expectResumeRejected: true,
6662 })
6663
6664 testCases = append(testCases, testCase{
6665 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006666 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006667 resumeSession: true,
6668 config: Config{
6669 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006670 Bugs: ProtocolBugs{
6671 FilterTicket: func(in []byte) ([]byte, error) {
6672 return SetShimTicketVersion(in, VersionTLS12)
6673 },
6674 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006675 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006676 flags: []string{
6677 "-ticket-key",
6678 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6679 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006680 expectResumeRejected: true,
6681 })
6682
David Benjamin4199b0d2016-11-01 13:58:25 -04006683 // Resumptions are declined if the cipher is invalid or disabled.
6684 testCases = append(testCases, testCase{
6685 testType: serverTest,
6686 name: "Resume-Server-DeclineBadCipher",
6687 resumeSession: true,
6688 config: Config{
6689 MaxVersion: VersionTLS12,
6690 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006691 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006692 FilterTicket: func(in []byte) ([]byte, error) {
6693 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6694 },
6695 },
6696 },
6697 flags: []string{
6698 "-ticket-key",
6699 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6700 },
6701 expectResumeRejected: true,
6702 })
6703
6704 testCases = append(testCases, testCase{
6705 testType: serverTest,
6706 name: "Resume-Server-DeclineBadCipher-2",
6707 resumeSession: true,
6708 config: Config{
6709 MaxVersion: VersionTLS12,
6710 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006711 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006712 FilterTicket: func(in []byte) ([]byte, error) {
6713 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6714 },
6715 },
6716 },
6717 flags: []string{
6718 "-cipher", "AES128",
6719 "-ticket-key",
6720 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6721 },
6722 expectResumeRejected: true,
6723 })
6724
David Benjaminf01f42a2016-11-16 19:05:33 +09006725 // Sessions are not resumed if they do not use the preferred cipher.
6726 testCases = append(testCases, testCase{
6727 testType: serverTest,
6728 name: "Resume-Server-CipherNotPreferred",
6729 resumeSession: true,
6730 config: Config{
6731 MaxVersion: VersionTLS12,
6732 Bugs: ProtocolBugs{
6733 ExpectNewTicket: true,
6734 FilterTicket: func(in []byte) ([]byte, error) {
6735 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6736 },
6737 },
6738 },
6739 flags: []string{
6740 "-ticket-key",
6741 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6742 },
6743 shouldFail: false,
6744 expectResumeRejected: true,
6745 })
6746
6747 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6748 // PRF hashes match, but BoringSSL will always decline such resumptions.
6749 testCases = append(testCases, testCase{
6750 testType: serverTest,
6751 name: "Resume-Server-CipherNotPreferred-TLS13",
6752 resumeSession: true,
6753 config: Config{
6754 MaxVersion: VersionTLS13,
6755 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6756 Bugs: ProtocolBugs{
6757 FilterTicket: func(in []byte) ([]byte, error) {
6758 // If the client (runner) offers ChaCha20-Poly1305 first, the
6759 // server (shim) always prefers it. Switch it to AES-GCM.
6760 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6761 },
6762 },
6763 },
6764 flags: []string{
6765 "-ticket-key",
6766 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6767 },
6768 shouldFail: false,
6769 expectResumeRejected: true,
6770 })
6771
6772 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006773 testCases = append(testCases, testCase{
6774 testType: serverTest,
6775 name: "Resume-Server-DeclineBadCipher-TLS13",
6776 resumeSession: true,
6777 config: Config{
6778 MaxVersion: VersionTLS13,
6779 Bugs: ProtocolBugs{
6780 FilterTicket: func(in []byte) ([]byte, error) {
6781 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6782 },
6783 },
6784 },
6785 flags: []string{
6786 "-ticket-key",
6787 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6788 },
6789 expectResumeRejected: true,
6790 })
6791
David Benjaminf01f42a2016-11-16 19:05:33 +09006792 // If the client does not offer the cipher from the session, decline to
6793 // resume. Clients are forbidden from doing this, but BoringSSL selects
6794 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006795 testCases = append(testCases, testCase{
6796 testType: serverTest,
6797 name: "Resume-Server-UnofferedCipher",
6798 resumeSession: true,
6799 config: Config{
6800 MaxVersion: VersionTLS12,
6801 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6802 },
6803 resumeConfig: &Config{
6804 MaxVersion: VersionTLS12,
6805 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6806 Bugs: ProtocolBugs{
6807 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6808 },
6809 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006810 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006811 })
6812
David Benjaminf01f42a2016-11-16 19:05:33 +09006813 // In TLS 1.3, clients may advertise a cipher list which does not
6814 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006815 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6816 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006817 testCases = append(testCases, testCase{
6818 testType: serverTest,
6819 name: "Resume-Server-UnofferedCipher-TLS13",
6820 resumeSession: true,
6821 config: Config{
6822 MaxVersion: VersionTLS13,
6823 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6824 },
6825 resumeConfig: &Config{
6826 MaxVersion: VersionTLS13,
6827 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6828 Bugs: ProtocolBugs{
6829 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6830 },
6831 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006832 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006833 })
6834
David Benjamin4199b0d2016-11-01 13:58:25 -04006835 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006836 testCases = append(testCases, testCase{
6837 name: "Resume-Client-CipherMismatch",
6838 resumeSession: true,
6839 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006840 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006841 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6842 },
6843 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006844 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006845 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6846 Bugs: ProtocolBugs{
6847 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6848 },
6849 },
6850 shouldFail: true,
6851 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6852 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006853
David Benjamine1cc35e2016-11-16 16:25:58 +09006854 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6855 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006856 testCases = append(testCases, testCase{
6857 name: "Resume-Client-CipherMismatch-TLS13",
6858 resumeSession: true,
6859 config: Config{
6860 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006861 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006862 },
6863 resumeConfig: &Config{
6864 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006865 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6866 },
6867 })
6868
6869 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6870 testCases = append(testCases, testCase{
6871 name: "Resume-Client-PRFMismatch-TLS13",
6872 resumeSession: true,
6873 config: Config{
6874 MaxVersion: VersionTLS13,
6875 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6876 },
6877 resumeConfig: &Config{
6878 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006879 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006880 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006881 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006882 },
6883 },
6884 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006885 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006886 })
Steven Valdeza833c352016-11-01 13:39:36 -04006887
6888 testCases = append(testCases, testCase{
6889 testType: serverTest,
6890 name: "Resume-Server-BinderWrongLength",
6891 resumeSession: true,
6892 config: Config{
6893 MaxVersion: VersionTLS13,
6894 Bugs: ProtocolBugs{
6895 SendShortPSKBinder: true,
6896 },
6897 },
6898 shouldFail: true,
6899 expectedLocalError: "remote error: error decrypting message",
6900 expectedError: ":DIGEST_CHECK_FAILED:",
6901 })
6902
6903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: "Resume-Server-NoPSKBinder",
6906 resumeSession: true,
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 Bugs: ProtocolBugs{
6910 SendNoPSKBinder: true,
6911 },
6912 },
6913 shouldFail: true,
6914 expectedLocalError: "remote error: error decoding message",
6915 expectedError: ":DECODE_ERROR:",
6916 })
6917
6918 testCases = append(testCases, testCase{
6919 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006920 name: "Resume-Server-ExtraPSKBinder",
6921 resumeSession: true,
6922 config: Config{
6923 MaxVersion: VersionTLS13,
6924 Bugs: ProtocolBugs{
6925 SendExtraPSKBinder: true,
6926 },
6927 },
6928 shouldFail: true,
6929 expectedLocalError: "remote error: illegal parameter",
6930 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6931 })
6932
6933 testCases = append(testCases, testCase{
6934 testType: serverTest,
6935 name: "Resume-Server-ExtraIdentityNoBinder",
6936 resumeSession: true,
6937 config: Config{
6938 MaxVersion: VersionTLS13,
6939 Bugs: ProtocolBugs{
6940 ExtraPSKIdentity: true,
6941 },
6942 },
6943 shouldFail: true,
6944 expectedLocalError: "remote error: illegal parameter",
6945 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6946 })
6947
6948 testCases = append(testCases, testCase{
6949 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006950 name: "Resume-Server-InvalidPSKBinder",
6951 resumeSession: true,
6952 config: Config{
6953 MaxVersion: VersionTLS13,
6954 Bugs: ProtocolBugs{
6955 SendInvalidPSKBinder: true,
6956 },
6957 },
6958 shouldFail: true,
6959 expectedLocalError: "remote error: error decrypting message",
6960 expectedError: ":DIGEST_CHECK_FAILED:",
6961 })
6962
6963 testCases = append(testCases, testCase{
6964 testType: serverTest,
6965 name: "Resume-Server-PSKBinderFirstExtension",
6966 resumeSession: true,
6967 config: Config{
6968 MaxVersion: VersionTLS13,
6969 Bugs: ProtocolBugs{
6970 PSKBinderFirst: true,
6971 },
6972 },
6973 shouldFail: true,
6974 expectedLocalError: "remote error: illegal parameter",
6975 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6976 })
David Benjamin01fe8202014-09-24 15:21:44 -04006977}
6978
Adam Langley2ae77d22014-10-28 17:29:33 -07006979func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006980 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006981 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006982 testType: serverTest,
6983 name: "Renegotiate-Server-Forbidden",
6984 config: Config{
6985 MaxVersion: VersionTLS12,
6986 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006987 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006988 shouldFail: true,
6989 expectedError: ":NO_RENEGOTIATION:",
6990 expectedLocalError: "remote error: no renegotiation",
6991 })
Adam Langley5021b222015-06-12 18:27:58 -07006992 // The server shouldn't echo the renegotiation extension unless
6993 // requested by the client.
6994 testCases = append(testCases, testCase{
6995 testType: serverTest,
6996 name: "Renegotiate-Server-NoExt",
6997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006999 Bugs: ProtocolBugs{
7000 NoRenegotiationInfo: true,
7001 RequireRenegotiationInfo: true,
7002 },
7003 },
7004 shouldFail: true,
7005 expectedLocalError: "renegotiation extension missing",
7006 })
7007 // The renegotiation SCSV should be sufficient for the server to echo
7008 // the extension.
7009 testCases = append(testCases, testCase{
7010 testType: serverTest,
7011 name: "Renegotiate-Server-NoExt-SCSV",
7012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007013 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007014 Bugs: ProtocolBugs{
7015 NoRenegotiationInfo: true,
7016 SendRenegotiationSCSV: true,
7017 RequireRenegotiationInfo: true,
7018 },
7019 },
7020 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007021 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007022 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007024 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007025 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007026 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007027 },
7028 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007029 renegotiate: 1,
7030 flags: []string{
7031 "-renegotiate-freely",
7032 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007033 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007034 },
David Benjamincdea40c2015-03-19 14:09:43 -04007035 })
7036 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007037 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007038 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007040 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007041 Bugs: ProtocolBugs{
7042 EmptyRenegotiationInfo: true,
7043 },
7044 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007045 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007046 shouldFail: true,
7047 expectedError: ":RENEGOTIATION_MISMATCH:",
7048 })
7049 testCases = append(testCases, testCase{
7050 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007051 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007052 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007053 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007054 Bugs: ProtocolBugs{
7055 BadRenegotiationInfo: true,
7056 },
7057 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007058 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007059 shouldFail: true,
7060 expectedError: ":RENEGOTIATION_MISMATCH:",
7061 })
7062 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007063 name: "Renegotiate-Client-BadExt2",
7064 renegotiate: 1,
7065 config: Config{
7066 MaxVersion: VersionTLS12,
7067 Bugs: ProtocolBugs{
7068 BadRenegotiationInfoEnd: true,
7069 },
7070 },
7071 flags: []string{"-renegotiate-freely"},
7072 shouldFail: true,
7073 expectedError: ":RENEGOTIATION_MISMATCH:",
7074 })
7075 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007076 name: "Renegotiate-Client-Downgrade",
7077 renegotiate: 1,
7078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007079 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007080 Bugs: ProtocolBugs{
7081 NoRenegotiationInfoAfterInitial: true,
7082 },
7083 },
7084 flags: []string{"-renegotiate-freely"},
7085 shouldFail: true,
7086 expectedError: ":RENEGOTIATION_MISMATCH:",
7087 })
7088 testCases = append(testCases, testCase{
7089 name: "Renegotiate-Client-Upgrade",
7090 renegotiate: 1,
7091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007092 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007093 Bugs: ProtocolBugs{
7094 NoRenegotiationInfoInInitial: true,
7095 },
7096 },
7097 flags: []string{"-renegotiate-freely"},
7098 shouldFail: true,
7099 expectedError: ":RENEGOTIATION_MISMATCH:",
7100 })
7101 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007102 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007103 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007104 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007105 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007106 Bugs: ProtocolBugs{
7107 NoRenegotiationInfo: true,
7108 },
7109 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007110 flags: []string{
7111 "-renegotiate-freely",
7112 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007113 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007114 },
David Benjamincff0b902015-05-15 23:09:47 -04007115 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007116
7117 // Test that the server may switch ciphers on renegotiation without
7118 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007119 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007120 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007121 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007122 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007123 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007124 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007125 },
7126 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007127 flags: []string{
7128 "-renegotiate-freely",
7129 "-expect-total-renegotiations", "1",
7130 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007131 })
7132 testCases = append(testCases, testCase{
7133 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007134 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007135 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007136 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007137 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7138 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007139 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007140 flags: []string{
7141 "-renegotiate-freely",
7142 "-expect-total-renegotiations", "1",
7143 },
David Benjaminb16346b2015-04-08 19:16:58 -04007144 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007145
7146 // Test that the server may not switch versions on renegotiation.
7147 testCases = append(testCases, testCase{
7148 name: "Renegotiate-Client-SwitchVersion",
7149 config: Config{
7150 MaxVersion: VersionTLS12,
7151 // Pick a cipher which exists at both versions.
7152 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7153 Bugs: ProtocolBugs{
7154 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007155 // Avoid failing early at the record layer.
7156 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007157 },
7158 },
7159 renegotiate: 1,
7160 flags: []string{
7161 "-renegotiate-freely",
7162 "-expect-total-renegotiations", "1",
7163 },
7164 shouldFail: true,
7165 expectedError: ":WRONG_SSL_VERSION:",
7166 })
7167
David Benjaminb16346b2015-04-08 19:16:58 -04007168 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007169 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007170 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007171 config: Config{
7172 MaxVersion: VersionTLS10,
7173 Bugs: ProtocolBugs{
7174 RequireSameRenegoClientVersion: true,
7175 },
7176 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007177 flags: []string{
7178 "-renegotiate-freely",
7179 "-expect-total-renegotiations", "1",
7180 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007181 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007182 testCases = append(testCases, testCase{
7183 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007184 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007185 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007186 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007187 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7188 NextProtos: []string{"foo"},
7189 },
7190 flags: []string{
7191 "-false-start",
7192 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007193 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007194 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007195 },
7196 shimWritesFirst: true,
7197 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007198
7199 // Client-side renegotiation controls.
7200 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007201 name: "Renegotiate-Client-Forbidden-1",
7202 config: Config{
7203 MaxVersion: VersionTLS12,
7204 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007205 renegotiate: 1,
7206 shouldFail: true,
7207 expectedError: ":NO_RENEGOTIATION:",
7208 expectedLocalError: "remote error: no renegotiation",
7209 })
7210 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007211 name: "Renegotiate-Client-Once-1",
7212 config: Config{
7213 MaxVersion: VersionTLS12,
7214 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007215 renegotiate: 1,
7216 flags: []string{
7217 "-renegotiate-once",
7218 "-expect-total-renegotiations", "1",
7219 },
7220 })
7221 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007222 name: "Renegotiate-Client-Freely-1",
7223 config: Config{
7224 MaxVersion: VersionTLS12,
7225 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007226 renegotiate: 1,
7227 flags: []string{
7228 "-renegotiate-freely",
7229 "-expect-total-renegotiations", "1",
7230 },
7231 })
7232 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007233 name: "Renegotiate-Client-Once-2",
7234 config: Config{
7235 MaxVersion: VersionTLS12,
7236 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007237 renegotiate: 2,
7238 flags: []string{"-renegotiate-once"},
7239 shouldFail: true,
7240 expectedError: ":NO_RENEGOTIATION:",
7241 expectedLocalError: "remote error: no renegotiation",
7242 })
7243 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007244 name: "Renegotiate-Client-Freely-2",
7245 config: Config{
7246 MaxVersion: VersionTLS12,
7247 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007248 renegotiate: 2,
7249 flags: []string{
7250 "-renegotiate-freely",
7251 "-expect-total-renegotiations", "2",
7252 },
7253 })
Adam Langley27a0d082015-11-03 13:34:10 -08007254 testCases = append(testCases, testCase{
7255 name: "Renegotiate-Client-NoIgnore",
7256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007257 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007258 Bugs: ProtocolBugs{
7259 SendHelloRequestBeforeEveryAppDataRecord: true,
7260 },
7261 },
7262 shouldFail: true,
7263 expectedError: ":NO_RENEGOTIATION:",
7264 })
7265 testCases = append(testCases, testCase{
7266 name: "Renegotiate-Client-Ignore",
7267 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007268 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007269 Bugs: ProtocolBugs{
7270 SendHelloRequestBeforeEveryAppDataRecord: true,
7271 },
7272 },
7273 flags: []string{
7274 "-renegotiate-ignore",
7275 "-expect-total-renegotiations", "0",
7276 },
7277 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007278
David Benjamin34941c02016-10-08 11:45:31 -04007279 // Renegotiation is not allowed at SSL 3.0.
7280 testCases = append(testCases, testCase{
7281 name: "Renegotiate-Client-SSL3",
7282 config: Config{
7283 MaxVersion: VersionSSL30,
7284 },
7285 renegotiate: 1,
7286 flags: []string{
7287 "-renegotiate-freely",
7288 "-expect-total-renegotiations", "1",
7289 },
7290 shouldFail: true,
7291 expectedError: ":NO_RENEGOTIATION:",
7292 expectedLocalError: "remote error: no renegotiation",
7293 })
7294
David Benjamina1eaba12017-01-01 23:19:22 -05007295 // Renegotiation is not allowed when there is an unfinished write.
7296 testCases = append(testCases, testCase{
7297 name: "Renegotiate-Client-UnfinishedWrite",
7298 config: Config{
7299 MaxVersion: VersionTLS12,
7300 },
David Benjaminbbba9392017-04-06 12:54:12 -04007301 renegotiate: 1,
7302 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007303 flags: []string{
7304 "-async",
7305 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007306 },
7307 shouldFail: true,
7308 expectedError: ":NO_RENEGOTIATION:",
7309 // We do not successfully send the no_renegotiation alert in
7310 // this case. https://crbug.com/boringssl/130
7311 })
7312
David Benjamin07ab5d42017-02-09 20:11:41 -05007313 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007314 testCases = append(testCases, testCase{
7315 name: "StrayHelloRequest",
7316 config: Config{
7317 MaxVersion: VersionTLS12,
7318 Bugs: ProtocolBugs{
7319 SendHelloRequestBeforeEveryHandshakeMessage: true,
7320 },
7321 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007322 shouldFail: true,
7323 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007324 })
7325 testCases = append(testCases, testCase{
7326 name: "StrayHelloRequest-Packed",
7327 config: Config{
7328 MaxVersion: VersionTLS12,
7329 Bugs: ProtocolBugs{
7330 PackHandshakeFlight: true,
7331 SendHelloRequestBeforeEveryHandshakeMessage: true,
7332 },
7333 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007334 shouldFail: true,
7335 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007336 })
7337
David Benjamin12d2c482016-07-24 10:56:51 -04007338 // Test renegotiation works if HelloRequest and server Finished come in
7339 // the same record.
7340 testCases = append(testCases, testCase{
7341 name: "Renegotiate-Client-Packed",
7342 config: Config{
7343 MaxVersion: VersionTLS12,
7344 Bugs: ProtocolBugs{
7345 PackHandshakeFlight: true,
7346 PackHelloRequestWithFinished: true,
7347 },
7348 },
7349 renegotiate: 1,
7350 flags: []string{
7351 "-renegotiate-freely",
7352 "-expect-total-renegotiations", "1",
7353 },
7354 })
7355
David Benjamin397c8e62016-07-08 14:14:36 -07007356 // Renegotiation is forbidden in TLS 1.3.
7357 testCases = append(testCases, testCase{
7358 name: "Renegotiate-Client-TLS13",
7359 config: Config{
7360 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007361 Bugs: ProtocolBugs{
7362 SendHelloRequestBeforeEveryAppDataRecord: true,
7363 },
David Benjamin397c8e62016-07-08 14:14:36 -07007364 },
David Benjamin397c8e62016-07-08 14:14:36 -07007365 flags: []string{
7366 "-renegotiate-freely",
7367 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007368 shouldFail: true,
7369 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007370 })
7371
7372 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7373 testCases = append(testCases, testCase{
7374 name: "StrayHelloRequest-TLS13",
7375 config: Config{
7376 MaxVersion: VersionTLS13,
7377 Bugs: ProtocolBugs{
7378 SendHelloRequestBeforeEveryHandshakeMessage: true,
7379 },
7380 },
7381 shouldFail: true,
7382 expectedError: ":UNEXPECTED_MESSAGE:",
7383 })
David Benjamind2610042017-01-03 10:49:28 -05007384
7385 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7386 // always reads as supporting it, regardless of whether it was
7387 // negotiated.
7388 testCases = append(testCases, testCase{
7389 name: "AlwaysReportRenegotiationInfo-TLS13",
7390 config: Config{
7391 MaxVersion: VersionTLS13,
7392 Bugs: ProtocolBugs{
7393 NoRenegotiationInfo: true,
7394 },
7395 },
7396 flags: []string{
7397 "-expect-secure-renegotiation",
7398 },
7399 })
David Benjamina58baaf2017-02-28 20:54:28 -05007400
7401 // Certificates may not change on renegotiation.
7402 testCases = append(testCases, testCase{
7403 name: "Renegotiation-CertificateChange",
7404 config: Config{
7405 MaxVersion: VersionTLS12,
7406 Certificates: []Certificate{rsaCertificate},
7407 Bugs: ProtocolBugs{
7408 RenegotiationCertificate: &rsaChainCertificate,
7409 },
7410 },
7411 renegotiate: 1,
7412 flags: []string{"-renegotiate-freely"},
7413 shouldFail: true,
7414 expectedError: ":SERVER_CERT_CHANGED:",
7415 })
7416 testCases = append(testCases, testCase{
7417 name: "Renegotiation-CertificateChange-2",
7418 config: Config{
7419 MaxVersion: VersionTLS12,
7420 Certificates: []Certificate{rsaCertificate},
7421 Bugs: ProtocolBugs{
7422 RenegotiationCertificate: &rsa1024Certificate,
7423 },
7424 },
7425 renegotiate: 1,
7426 flags: []string{"-renegotiate-freely"},
7427 shouldFail: true,
7428 expectedError: ":SERVER_CERT_CHANGED:",
7429 })
David Benjaminbbf42462017-03-14 21:27:10 -04007430
7431 // We do not negotiate ALPN after the initial handshake. This is
7432 // error-prone and only risks bugs in consumers.
7433 testCases = append(testCases, testCase{
7434 testType: clientTest,
7435 name: "Renegotiation-ForbidALPN",
7436 config: Config{
7437 MaxVersion: VersionTLS12,
7438 Bugs: ProtocolBugs{
7439 // Forcibly negotiate ALPN on both initial and
7440 // renegotiation handshakes. The test stack will
7441 // internally check the client does not offer
7442 // it.
7443 SendALPN: "foo",
7444 },
7445 },
7446 flags: []string{
7447 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7448 "-expect-alpn", "foo",
7449 "-renegotiate-freely",
7450 },
7451 renegotiate: 1,
7452 shouldFail: true,
7453 expectedError: ":UNEXPECTED_EXTENSION:",
7454 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007455}
7456
David Benjamin5e961c12014-11-07 01:48:35 -05007457func addDTLSReplayTests() {
7458 // Test that sequence number replays are detected.
7459 testCases = append(testCases, testCase{
7460 protocol: dtls,
7461 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007462 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007463 replayWrites: true,
7464 })
7465
David Benjamin8e6db492015-07-25 18:29:23 -04007466 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007467 // than the retransmit window.
7468 testCases = append(testCases, testCase{
7469 protocol: dtls,
7470 name: "DTLS-Replay-LargeGaps",
7471 config: Config{
7472 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007473 SequenceNumberMapping: func(in uint64) uint64 {
7474 return in * 127
7475 },
David Benjamin5e961c12014-11-07 01:48:35 -05007476 },
7477 },
David Benjamin8e6db492015-07-25 18:29:23 -04007478 messageCount: 200,
7479 replayWrites: true,
7480 })
7481
7482 // Test the incoming sequence number changing non-monotonically.
7483 testCases = append(testCases, testCase{
7484 protocol: dtls,
7485 name: "DTLS-Replay-NonMonotonic",
7486 config: Config{
7487 Bugs: ProtocolBugs{
7488 SequenceNumberMapping: func(in uint64) uint64 {
7489 return in ^ 31
7490 },
7491 },
7492 },
7493 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007494 replayWrites: true,
7495 })
7496}
7497
Nick Harper60edffd2016-06-21 15:19:24 -07007498var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007499 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007500 id signatureAlgorithm
7501 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007502}{
Nick Harper60edffd2016-06-21 15:19:24 -07007503 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7504 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7505 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7506 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007507 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007508 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7509 // hash function doesn't have to match the curve and so the same
7510 // signature algorithm works with P-224.
7511 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007512 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7513 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7514 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007515 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7516 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7517 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007518 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007519 // Tests for key types prior to TLS 1.2.
7520 {"RSA", 0, testCertRSA},
7521 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007522}
7523
Nick Harper60edffd2016-06-21 15:19:24 -07007524const fakeSigAlg1 signatureAlgorithm = 0x2a01
7525const fakeSigAlg2 signatureAlgorithm = 0xff01
7526
7527func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007528 // Not all ciphers involve a signature. Advertise a list which gives all
7529 // versions a signing cipher.
7530 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007531 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007532 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7533 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7534 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7535 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007536 }
David Benjamin5208fd42016-07-13 21:43:25 -04007537
David Benjaminca3d5452016-07-14 12:51:01 -04007538 var allAlgorithms []signatureAlgorithm
7539 for _, alg := range testSignatureAlgorithms {
7540 if alg.id != 0 {
7541 allAlgorithms = append(allAlgorithms, alg.id)
7542 }
7543 }
7544
Nick Harper60edffd2016-06-21 15:19:24 -07007545 // Make sure each signature algorithm works. Include some fake values in
7546 // the list and ensure they're ignored.
7547 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007548 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007549 if (ver.version < VersionTLS12) != (alg.id == 0) {
7550 continue
7551 }
7552
7553 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7554 // or remove it in C.
7555 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007556 continue
7557 }
Nick Harper60edffd2016-06-21 15:19:24 -07007558
David Benjamin3ef76972016-10-17 17:59:54 -04007559 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007560 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007561 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007562 shouldSignFail = true
7563 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007564 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007565 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007566 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7567 shouldSignFail = true
7568 shouldVerifyFail = true
7569 }
7570 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7571 // the curve has to match the hash size.
7572 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007573 shouldSignFail = true
7574 shouldVerifyFail = true
7575 }
7576
7577 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7578 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7579 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007580 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007581
7582 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007583 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007584 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007585 }
7586 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007587 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007588 }
David Benjamin000800a2014-11-14 01:43:59 -05007589
David Benjamin1fb125c2016-07-08 18:52:12 -07007590 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007591
David Benjamin7a41d372016-07-09 11:21:54 -07007592 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007593 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007594 config: Config{
7595 MaxVersion: ver.version,
7596 ClientAuth: RequireAnyClientCert,
7597 VerifySignatureAlgorithms: []signatureAlgorithm{
7598 fakeSigAlg1,
7599 alg.id,
7600 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007601 },
David Benjamin7a41d372016-07-09 11:21:54 -07007602 },
7603 flags: []string{
7604 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7605 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7606 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007607 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007608 },
David Benjamina5022392017-07-10 17:40:39 -04007609 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007610 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007611 expectedError: signError,
7612 expectedPeerSignatureAlgorithm: alg.id,
7613 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007614
David Benjamin7a41d372016-07-09 11:21:54 -07007615 testCases = append(testCases, testCase{
7616 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007617 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007618 config: Config{
7619 MaxVersion: ver.version,
7620 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7621 SignSignatureAlgorithms: []signatureAlgorithm{
7622 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007623 },
David Benjamin7a41d372016-07-09 11:21:54 -07007624 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007625 SkipECDSACurveCheck: shouldVerifyFail,
7626 IgnoreSignatureVersionChecks: shouldVerifyFail,
7627 // Some signature algorithms may not be advertised.
7628 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007629 },
David Benjamin7a41d372016-07-09 11:21:54 -07007630 },
David Benjamina5022392017-07-10 17:40:39 -04007631 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007632 flags: []string{
7633 "-require-any-client-certificate",
7634 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7635 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007636 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007637 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007638 // Resume the session to assert the peer signature
7639 // algorithm is reported on both handshakes.
7640 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007641 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007642 expectedError: verifyError,
7643 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007644
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007645 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007646 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007647 testCases = append(testCases, testCase{
7648 testType: serverTest,
7649 name: "ServerAuth-Sign" + suffix,
7650 config: Config{
7651 MaxVersion: ver.version,
7652 CipherSuites: signingCiphers,
7653 VerifySignatureAlgorithms: []signatureAlgorithm{
7654 fakeSigAlg1,
7655 alg.id,
7656 fakeSigAlg2,
7657 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007658 },
David Benjamina5022392017-07-10 17:40:39 -04007659 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007660 flags: []string{
7661 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7662 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7663 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007664 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007665 },
7666 shouldFail: shouldSignFail,
7667 expectedError: signError,
7668 expectedPeerSignatureAlgorithm: alg.id,
7669 })
7670 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007671
7672 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007673 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007674 config: Config{
7675 MaxVersion: ver.version,
7676 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007677 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007678 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007679 alg.id,
7680 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007681 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007682 SkipECDSACurveCheck: shouldVerifyFail,
7683 IgnoreSignatureVersionChecks: shouldVerifyFail,
7684 // Some signature algorithms may not be advertised.
7685 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007686 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007687 },
David Benjamina5022392017-07-10 17:40:39 -04007688 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007689 flags: []string{
7690 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7691 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007692 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007693 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007694 // Resume the session to assert the peer signature
7695 // algorithm is reported on both handshakes.
7696 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007697 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007698 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007699 })
David Benjamin5208fd42016-07-13 21:43:25 -04007700
David Benjamin3ef76972016-10-17 17:59:54 -04007701 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007702 testCases = append(testCases, testCase{
7703 testType: serverTest,
7704 name: "ClientAuth-InvalidSignature" + suffix,
7705 config: Config{
7706 MaxVersion: ver.version,
7707 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7708 SignSignatureAlgorithms: []signatureAlgorithm{
7709 alg.id,
7710 },
7711 Bugs: ProtocolBugs{
7712 InvalidSignature: true,
7713 },
7714 },
David Benjamina5022392017-07-10 17:40:39 -04007715 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007716 flags: []string{
7717 "-require-any-client-certificate",
7718 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007719 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007720 },
7721 shouldFail: true,
7722 expectedError: ":BAD_SIGNATURE:",
7723 })
7724
7725 testCases = append(testCases, testCase{
7726 name: "ServerAuth-InvalidSignature" + suffix,
7727 config: Config{
7728 MaxVersion: ver.version,
7729 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7730 CipherSuites: signingCiphers,
7731 SignSignatureAlgorithms: []signatureAlgorithm{
7732 alg.id,
7733 },
7734 Bugs: ProtocolBugs{
7735 InvalidSignature: true,
7736 },
7737 },
David Benjamina5022392017-07-10 17:40:39 -04007738 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007739 flags: []string{
7740 "-enable-all-curves",
7741 "-enable-ed25519",
7742 },
David Benjamin5208fd42016-07-13 21:43:25 -04007743 shouldFail: true,
7744 expectedError: ":BAD_SIGNATURE:",
7745 })
7746 }
David Benjaminca3d5452016-07-14 12:51:01 -04007747
David Benjamin3ef76972016-10-17 17:59:54 -04007748 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007749 testCases = append(testCases, testCase{
7750 name: "ClientAuth-Sign-Negotiate" + suffix,
7751 config: Config{
7752 MaxVersion: ver.version,
7753 ClientAuth: RequireAnyClientCert,
7754 VerifySignatureAlgorithms: allAlgorithms,
7755 },
David Benjamina5022392017-07-10 17:40:39 -04007756 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007757 flags: []string{
7758 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7759 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7760 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007761 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007762 "-signing-prefs", strconv.Itoa(int(alg.id)),
7763 },
7764 expectedPeerSignatureAlgorithm: alg.id,
7765 })
7766
7767 testCases = append(testCases, testCase{
7768 testType: serverTest,
7769 name: "ServerAuth-Sign-Negotiate" + suffix,
7770 config: Config{
7771 MaxVersion: ver.version,
7772 CipherSuites: signingCiphers,
7773 VerifySignatureAlgorithms: allAlgorithms,
7774 },
David Benjamina5022392017-07-10 17:40:39 -04007775 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007776 flags: []string{
7777 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7778 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7779 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007780 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007781 "-signing-prefs", strconv.Itoa(int(alg.id)),
7782 },
7783 expectedPeerSignatureAlgorithm: alg.id,
7784 })
7785 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007786 }
David Benjamin000800a2014-11-14 01:43:59 -05007787 }
7788
Nick Harper60edffd2016-06-21 15:19:24 -07007789 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007790 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007791 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007792 config: Config{
7793 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007794 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007795 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007796 signatureECDSAWithP521AndSHA512,
7797 signatureRSAPKCS1WithSHA384,
7798 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007799 },
7800 },
7801 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007802 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7803 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007804 },
Nick Harper60edffd2016-06-21 15:19:24 -07007805 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007806 })
7807
7808 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007809 name: "ClientAuth-SignatureType-TLS13",
7810 config: Config{
7811 ClientAuth: RequireAnyClientCert,
7812 MaxVersion: VersionTLS13,
7813 VerifySignatureAlgorithms: []signatureAlgorithm{
7814 signatureECDSAWithP521AndSHA512,
7815 signatureRSAPKCS1WithSHA384,
7816 signatureRSAPSSWithSHA384,
7817 signatureECDSAWithSHA1,
7818 },
7819 },
7820 flags: []string{
7821 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7822 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7823 },
7824 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7825 })
7826
7827 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007828 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007829 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007831 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007833 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007834 signatureECDSAWithP521AndSHA512,
7835 signatureRSAPKCS1WithSHA384,
7836 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007837 },
7838 },
Nick Harper60edffd2016-06-21 15:19:24 -07007839 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007840 })
7841
Steven Valdez143e8b32016-07-11 13:19:03 -04007842 testCases = append(testCases, testCase{
7843 testType: serverTest,
7844 name: "ServerAuth-SignatureType-TLS13",
7845 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007846 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007847 VerifySignatureAlgorithms: []signatureAlgorithm{
7848 signatureECDSAWithP521AndSHA512,
7849 signatureRSAPKCS1WithSHA384,
7850 signatureRSAPSSWithSHA384,
7851 signatureECDSAWithSHA1,
7852 },
7853 },
7854 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7855 })
7856
David Benjamina95e9f32016-07-08 16:28:04 -07007857 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007858 testCases = append(testCases, testCase{
7859 testType: serverTest,
7860 name: "Verify-ClientAuth-SignatureType",
7861 config: Config{
7862 MaxVersion: VersionTLS12,
7863 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007864 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007865 signatureRSAPKCS1WithSHA256,
7866 },
7867 Bugs: ProtocolBugs{
7868 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7869 },
7870 },
7871 flags: []string{
7872 "-require-any-client-certificate",
7873 },
7874 shouldFail: true,
7875 expectedError: ":WRONG_SIGNATURE_TYPE:",
7876 })
7877
7878 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007879 testType: serverTest,
7880 name: "Verify-ClientAuth-SignatureType-TLS13",
7881 config: Config{
7882 MaxVersion: VersionTLS13,
7883 Certificates: []Certificate{rsaCertificate},
7884 SignSignatureAlgorithms: []signatureAlgorithm{
7885 signatureRSAPSSWithSHA256,
7886 },
7887 Bugs: ProtocolBugs{
7888 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7889 },
7890 },
7891 flags: []string{
7892 "-require-any-client-certificate",
7893 },
7894 shouldFail: true,
7895 expectedError: ":WRONG_SIGNATURE_TYPE:",
7896 })
7897
7898 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007899 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007900 config: Config{
7901 MaxVersion: VersionTLS12,
7902 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007903 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007904 signatureRSAPKCS1WithSHA256,
7905 },
7906 Bugs: ProtocolBugs{
7907 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7908 },
7909 },
7910 shouldFail: true,
7911 expectedError: ":WRONG_SIGNATURE_TYPE:",
7912 })
7913
Steven Valdez143e8b32016-07-11 13:19:03 -04007914 testCases = append(testCases, testCase{
7915 name: "Verify-ServerAuth-SignatureType-TLS13",
7916 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007917 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007918 SignSignatureAlgorithms: []signatureAlgorithm{
7919 signatureRSAPSSWithSHA256,
7920 },
7921 Bugs: ProtocolBugs{
7922 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7923 },
7924 },
7925 shouldFail: true,
7926 expectedError: ":WRONG_SIGNATURE_TYPE:",
7927 })
7928
David Benjamin51dd7d62016-07-08 16:07:01 -07007929 // Test that, if the list is missing, the peer falls back to SHA-1 in
7930 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007931 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007932 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007934 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007935 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007936 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007937 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007938 },
7939 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007940 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007941 },
7942 },
7943 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007944 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7945 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007946 },
7947 })
7948
7949 testCases = append(testCases, testCase{
7950 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007951 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007952 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007953 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007954 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007955 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007956 },
7957 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007958 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007959 },
7960 },
David Benjaminee32bea2016-08-17 13:36:44 -04007961 flags: []string{
7962 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7963 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7964 },
7965 })
7966
7967 testCases = append(testCases, testCase{
7968 name: "ClientAuth-SHA1-Fallback-ECDSA",
7969 config: Config{
7970 MaxVersion: VersionTLS12,
7971 ClientAuth: RequireAnyClientCert,
7972 VerifySignatureAlgorithms: []signatureAlgorithm{
7973 signatureECDSAWithSHA1,
7974 },
7975 Bugs: ProtocolBugs{
7976 NoSignatureAlgorithms: true,
7977 },
7978 },
7979 flags: []string{
7980 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7981 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7982 },
7983 })
7984
7985 testCases = append(testCases, testCase{
7986 testType: serverTest,
7987 name: "ServerAuth-SHA1-Fallback-ECDSA",
7988 config: Config{
7989 MaxVersion: VersionTLS12,
7990 VerifySignatureAlgorithms: []signatureAlgorithm{
7991 signatureECDSAWithSHA1,
7992 },
7993 Bugs: ProtocolBugs{
7994 NoSignatureAlgorithms: true,
7995 },
7996 },
7997 flags: []string{
7998 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7999 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8000 },
David Benjamin000800a2014-11-14 01:43:59 -05008001 })
David Benjamin72dc7832015-03-16 17:49:43 -04008002
David Benjamin51dd7d62016-07-08 16:07:01 -07008003 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008004 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008005 config: Config{
8006 MaxVersion: VersionTLS13,
8007 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008008 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008009 signatureRSAPKCS1WithSHA1,
8010 },
8011 Bugs: ProtocolBugs{
8012 NoSignatureAlgorithms: true,
8013 },
8014 },
8015 flags: []string{
8016 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8017 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8018 },
David Benjamin48901652016-08-01 12:12:47 -04008019 shouldFail: true,
8020 // An empty CertificateRequest signature algorithm list is a
8021 // syntax error in TLS 1.3.
8022 expectedError: ":DECODE_ERROR:",
8023 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008024 })
8025
8026 testCases = append(testCases, testCase{
8027 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008028 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008029 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008030 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008031 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008032 signatureRSAPKCS1WithSHA1,
8033 },
8034 Bugs: ProtocolBugs{
8035 NoSignatureAlgorithms: true,
8036 },
8037 },
8038 shouldFail: true,
8039 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8040 })
8041
David Benjaminb62d2872016-07-18 14:55:02 +02008042 // Test that hash preferences are enforced. BoringSSL does not implement
8043 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008044 testCases = append(testCases, testCase{
8045 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008046 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008047 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008048 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008049 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008050 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008051 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008052 },
8053 Bugs: ProtocolBugs{
8054 IgnorePeerSignatureAlgorithmPreferences: true,
8055 },
8056 },
8057 flags: []string{"-require-any-client-certificate"},
8058 shouldFail: true,
8059 expectedError: ":WRONG_SIGNATURE_TYPE:",
8060 })
8061
8062 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008063 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008065 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008066 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008067 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008068 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008069 },
8070 Bugs: ProtocolBugs{
8071 IgnorePeerSignatureAlgorithmPreferences: true,
8072 },
8073 },
8074 shouldFail: true,
8075 expectedError: ":WRONG_SIGNATURE_TYPE:",
8076 })
David Benjaminb62d2872016-07-18 14:55:02 +02008077 testCases = append(testCases, testCase{
8078 testType: serverTest,
8079 name: "ClientAuth-Enforced-TLS13",
8080 config: Config{
8081 MaxVersion: VersionTLS13,
8082 Certificates: []Certificate{rsaCertificate},
8083 SignSignatureAlgorithms: []signatureAlgorithm{
8084 signatureRSAPKCS1WithMD5,
8085 },
8086 Bugs: ProtocolBugs{
8087 IgnorePeerSignatureAlgorithmPreferences: true,
8088 IgnoreSignatureVersionChecks: true,
8089 },
8090 },
8091 flags: []string{"-require-any-client-certificate"},
8092 shouldFail: true,
8093 expectedError: ":WRONG_SIGNATURE_TYPE:",
8094 })
8095
8096 testCases = append(testCases, testCase{
8097 name: "ServerAuth-Enforced-TLS13",
8098 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008099 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008100 SignSignatureAlgorithms: []signatureAlgorithm{
8101 signatureRSAPKCS1WithMD5,
8102 },
8103 Bugs: ProtocolBugs{
8104 IgnorePeerSignatureAlgorithmPreferences: true,
8105 IgnoreSignatureVersionChecks: true,
8106 },
8107 },
8108 shouldFail: true,
8109 expectedError: ":WRONG_SIGNATURE_TYPE:",
8110 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008111
8112 // Test that the agreed upon digest respects the client preferences and
8113 // the server digests.
8114 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008115 name: "NoCommonAlgorithms-Digests",
8116 config: Config{
8117 MaxVersion: VersionTLS12,
8118 ClientAuth: RequireAnyClientCert,
8119 VerifySignatureAlgorithms: []signatureAlgorithm{
8120 signatureRSAPKCS1WithSHA512,
8121 signatureRSAPKCS1WithSHA1,
8122 },
8123 },
8124 flags: []string{
8125 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8126 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8127 "-digest-prefs", "SHA256",
8128 },
8129 shouldFail: true,
8130 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8131 })
8132 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008133 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008135 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008136 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008137 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008138 signatureRSAPKCS1WithSHA512,
8139 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008140 },
8141 },
8142 flags: []string{
8143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008145 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008146 },
David Benjaminca3d5452016-07-14 12:51:01 -04008147 shouldFail: true,
8148 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8149 })
8150 testCases = append(testCases, testCase{
8151 name: "NoCommonAlgorithms-TLS13",
8152 config: Config{
8153 MaxVersion: VersionTLS13,
8154 ClientAuth: RequireAnyClientCert,
8155 VerifySignatureAlgorithms: []signatureAlgorithm{
8156 signatureRSAPSSWithSHA512,
8157 signatureRSAPSSWithSHA384,
8158 },
8159 },
8160 flags: []string{
8161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8163 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8164 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008165 shouldFail: true,
8166 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008167 })
8168 testCases = append(testCases, testCase{
8169 name: "Agree-Digest-SHA256",
8170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008171 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008172 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008173 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008174 signatureRSAPKCS1WithSHA1,
8175 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008176 },
8177 },
8178 flags: []string{
8179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008181 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008182 },
Nick Harper60edffd2016-06-21 15:19:24 -07008183 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008184 })
8185 testCases = append(testCases, testCase{
8186 name: "Agree-Digest-SHA1",
8187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008188 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008189 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008190 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008191 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008192 },
8193 },
8194 flags: []string{
8195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008197 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008198 },
Nick Harper60edffd2016-06-21 15:19:24 -07008199 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008200 })
8201 testCases = append(testCases, testCase{
8202 name: "Agree-Digest-Default",
8203 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008204 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008205 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008206 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008207 signatureRSAPKCS1WithSHA256,
8208 signatureECDSAWithP256AndSHA256,
8209 signatureRSAPKCS1WithSHA1,
8210 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008211 },
8212 },
8213 flags: []string{
8214 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8215 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8216 },
Nick Harper60edffd2016-06-21 15:19:24 -07008217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008218 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008219
David Benjaminca3d5452016-07-14 12:51:01 -04008220 // Test that the signing preference list may include extra algorithms
8221 // without negotiation problems.
8222 testCases = append(testCases, testCase{
8223 testType: serverTest,
8224 name: "FilterExtraAlgorithms",
8225 config: Config{
8226 MaxVersion: VersionTLS12,
8227 VerifySignatureAlgorithms: []signatureAlgorithm{
8228 signatureRSAPKCS1WithSHA256,
8229 },
8230 },
8231 flags: []string{
8232 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8233 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8234 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8235 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8236 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8237 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8238 },
8239 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8240 })
8241
David Benjamin4c3ddf72016-06-29 18:13:53 -04008242 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8243 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008244 testCases = append(testCases, testCase{
8245 name: "CheckLeafCurve",
8246 config: Config{
8247 MaxVersion: VersionTLS12,
8248 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008249 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008250 },
8251 flags: []string{"-p384-only"},
8252 shouldFail: true,
8253 expectedError: ":BAD_ECC_CERT:",
8254 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008255
8256 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8257 testCases = append(testCases, testCase{
8258 name: "CheckLeafCurve-TLS13",
8259 config: Config{
8260 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008261 Certificates: []Certificate{ecdsaP256Certificate},
8262 },
8263 flags: []string{"-p384-only"},
8264 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008265
8266 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8267 testCases = append(testCases, testCase{
8268 name: "ECDSACurveMismatch-Verify-TLS12",
8269 config: Config{
8270 MaxVersion: VersionTLS12,
8271 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8272 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008273 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008274 signatureECDSAWithP384AndSHA384,
8275 },
8276 },
8277 })
8278
8279 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8280 testCases = append(testCases, testCase{
8281 name: "ECDSACurveMismatch-Verify-TLS13",
8282 config: Config{
8283 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008284 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008285 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008286 signatureECDSAWithP384AndSHA384,
8287 },
8288 Bugs: ProtocolBugs{
8289 SkipECDSACurveCheck: true,
8290 },
8291 },
8292 shouldFail: true,
8293 expectedError: ":WRONG_SIGNATURE_TYPE:",
8294 })
8295
8296 // Signature algorithm selection in TLS 1.3 should take the curve into
8297 // account.
8298 testCases = append(testCases, testCase{
8299 testType: serverTest,
8300 name: "ECDSACurveMismatch-Sign-TLS13",
8301 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008302 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008303 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008304 signatureECDSAWithP384AndSHA384,
8305 signatureECDSAWithP256AndSHA256,
8306 },
8307 },
8308 flags: []string{
8309 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8310 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8311 },
8312 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8313 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008314
8315 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8316 // server does not attempt to sign in that case.
8317 testCases = append(testCases, testCase{
8318 testType: serverTest,
8319 name: "RSA-PSS-Large",
8320 config: Config{
8321 MaxVersion: VersionTLS13,
8322 VerifySignatureAlgorithms: []signatureAlgorithm{
8323 signatureRSAPSSWithSHA512,
8324 },
8325 },
8326 flags: []string{
8327 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8328 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8329 },
8330 shouldFail: true,
8331 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8332 })
David Benjamin57e929f2016-08-30 00:30:38 -04008333
8334 // Test that RSA-PSS is enabled by default for TLS 1.2.
8335 testCases = append(testCases, testCase{
8336 testType: clientTest,
8337 name: "RSA-PSS-Default-Verify",
8338 config: Config{
8339 MaxVersion: VersionTLS12,
8340 SignSignatureAlgorithms: []signatureAlgorithm{
8341 signatureRSAPSSWithSHA256,
8342 },
8343 },
8344 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8345 })
8346
8347 testCases = append(testCases, testCase{
8348 testType: serverTest,
8349 name: "RSA-PSS-Default-Sign",
8350 config: Config{
8351 MaxVersion: VersionTLS12,
8352 VerifySignatureAlgorithms: []signatureAlgorithm{
8353 signatureRSAPSSWithSHA256,
8354 },
8355 },
8356 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8357 })
David Benjamin69522112017-03-28 15:38:29 -05008358
8359 // TLS 1.1 and below has no way to advertise support for or negotiate
8360 // Ed25519's signature algorithm.
8361 testCases = append(testCases, testCase{
8362 testType: clientTest,
8363 name: "NoEd25519-TLS11-ServerAuth-Verify",
8364 config: Config{
8365 MaxVersion: VersionTLS11,
8366 Certificates: []Certificate{ed25519Certificate},
8367 Bugs: ProtocolBugs{
8368 // Sign with Ed25519 even though it is TLS 1.1.
8369 UseLegacySigningAlgorithm: signatureEd25519,
8370 },
8371 },
8372 flags: []string{"-enable-ed25519"},
8373 shouldFail: true,
8374 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8375 })
8376 testCases = append(testCases, testCase{
8377 testType: serverTest,
8378 name: "NoEd25519-TLS11-ServerAuth-Sign",
8379 config: Config{
8380 MaxVersion: VersionTLS11,
8381 },
8382 flags: []string{
8383 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8384 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8385 },
8386 shouldFail: true,
8387 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8388 })
8389 testCases = append(testCases, testCase{
8390 testType: serverTest,
8391 name: "NoEd25519-TLS11-ClientAuth-Verify",
8392 config: Config{
8393 MaxVersion: VersionTLS11,
8394 Certificates: []Certificate{ed25519Certificate},
8395 Bugs: ProtocolBugs{
8396 // Sign with Ed25519 even though it is TLS 1.1.
8397 UseLegacySigningAlgorithm: signatureEd25519,
8398 },
8399 },
8400 flags: []string{
8401 "-enable-ed25519",
8402 "-require-any-client-certificate",
8403 },
8404 shouldFail: true,
8405 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8406 })
8407 testCases = append(testCases, testCase{
8408 testType: clientTest,
8409 name: "NoEd25519-TLS11-ClientAuth-Sign",
8410 config: Config{
8411 MaxVersion: VersionTLS11,
8412 ClientAuth: RequireAnyClientCert,
8413 },
8414 flags: []string{
8415 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8416 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8417 },
8418 shouldFail: true,
8419 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8420 })
8421
8422 // Test Ed25519 is not advertised by default.
8423 testCases = append(testCases, testCase{
8424 testType: clientTest,
8425 name: "Ed25519DefaultDisable-NoAdvertise",
8426 config: Config{
8427 Certificates: []Certificate{ed25519Certificate},
8428 },
8429 shouldFail: true,
8430 expectedLocalError: "tls: no common signature algorithms",
8431 })
8432
8433 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8434 // preferences.
8435 testCases = append(testCases, testCase{
8436 testType: clientTest,
8437 name: "Ed25519DefaultDisable-NoAccept",
8438 config: Config{
8439 Certificates: []Certificate{ed25519Certificate},
8440 Bugs: ProtocolBugs{
8441 IgnorePeerSignatureAlgorithmPreferences: true,
8442 },
8443 },
8444 shouldFail: true,
8445 expectedLocalError: "remote error: illegal parameter",
8446 expectedError: ":WRONG_SIGNATURE_TYPE:",
8447 })
David Benjamin71c21b42017-04-14 17:05:40 -04008448
8449 // Test that configuring verify preferences changes what the client
8450 // advertises.
8451 testCases = append(testCases, testCase{
8452 name: "VerifyPreferences-Advertised",
8453 config: Config{
8454 Certificates: []Certificate{rsaCertificate},
8455 SignSignatureAlgorithms: []signatureAlgorithm{
8456 signatureRSAPSSWithSHA256,
8457 signatureRSAPSSWithSHA384,
8458 signatureRSAPSSWithSHA512,
8459 },
8460 },
8461 flags: []string{
8462 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8463 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8464 },
8465 })
8466
8467 // Test that the client advertises a set which the runner can find
8468 // nothing in common with.
8469 testCases = append(testCases, testCase{
8470 name: "VerifyPreferences-NoCommonAlgorithms",
8471 config: Config{
8472 Certificates: []Certificate{rsaCertificate},
8473 SignSignatureAlgorithms: []signatureAlgorithm{
8474 signatureRSAPSSWithSHA256,
8475 signatureRSAPSSWithSHA512,
8476 },
8477 },
8478 flags: []string{
8479 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8480 },
8481 shouldFail: true,
8482 expectedLocalError: "tls: no common signature algorithms",
8483 })
8484
8485 // Test that the client enforces its preferences when configured.
8486 testCases = append(testCases, testCase{
8487 name: "VerifyPreferences-Enforced",
8488 config: Config{
8489 Certificates: []Certificate{rsaCertificate},
8490 SignSignatureAlgorithms: []signatureAlgorithm{
8491 signatureRSAPSSWithSHA256,
8492 signatureRSAPSSWithSHA512,
8493 },
8494 Bugs: ProtocolBugs{
8495 IgnorePeerSignatureAlgorithmPreferences: true,
8496 },
8497 },
8498 flags: []string{
8499 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8500 },
8501 shouldFail: true,
8502 expectedLocalError: "remote error: illegal parameter",
8503 expectedError: ":WRONG_SIGNATURE_TYPE:",
8504 })
8505
8506 // Test that explicitly configuring Ed25519 is as good as changing the
8507 // boolean toggle.
8508 testCases = append(testCases, testCase{
8509 name: "VerifyPreferences-Ed25519",
8510 config: Config{
8511 Certificates: []Certificate{ed25519Certificate},
8512 },
8513 flags: []string{
8514 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8515 },
8516 })
David Benjamin000800a2014-11-14 01:43:59 -05008517}
8518
David Benjamin83f90402015-01-27 01:09:43 -05008519// timeouts is the retransmit schedule for BoringSSL. It doubles and
8520// caps at 60 seconds. On the 13th timeout, it gives up.
8521var timeouts = []time.Duration{
8522 1 * time.Second,
8523 2 * time.Second,
8524 4 * time.Second,
8525 8 * time.Second,
8526 16 * time.Second,
8527 32 * time.Second,
8528 60 * time.Second,
8529 60 * time.Second,
8530 60 * time.Second,
8531 60 * time.Second,
8532 60 * time.Second,
8533 60 * time.Second,
8534 60 * time.Second,
8535}
8536
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008537// shortTimeouts is an alternate set of timeouts which would occur if the
8538// initial timeout duration was set to 250ms.
8539var shortTimeouts = []time.Duration{
8540 250 * time.Millisecond,
8541 500 * time.Millisecond,
8542 1 * time.Second,
8543 2 * time.Second,
8544 4 * time.Second,
8545 8 * time.Second,
8546 16 * time.Second,
8547 32 * time.Second,
8548 60 * time.Second,
8549 60 * time.Second,
8550 60 * time.Second,
8551 60 * time.Second,
8552 60 * time.Second,
8553}
8554
David Benjamin83f90402015-01-27 01:09:43 -05008555func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008556 // These tests work by coordinating some behavior on both the shim and
8557 // the runner.
8558 //
8559 // TimeoutSchedule configures the runner to send a series of timeout
8560 // opcodes to the shim (see packetAdaptor) immediately before reading
8561 // each peer handshake flight N. The timeout opcode both simulates a
8562 // timeout in the shim and acts as a synchronization point to help the
8563 // runner bracket each handshake flight.
8564 //
8565 // We assume the shim does not read from the channel eagerly. It must
8566 // first wait until it has sent flight N and is ready to receive
8567 // handshake flight N+1. At this point, it will process the timeout
8568 // opcode. It must then immediately respond with a timeout ACK and act
8569 // as if the shim was idle for the specified amount of time.
8570 //
8571 // The runner then drops all packets received before the ACK and
8572 // continues waiting for flight N. This ordering results in one attempt
8573 // at sending flight N to be dropped. For the test to complete, the
8574 // shim must send flight N again, testing that the shim implements DTLS
8575 // retransmit on a timeout.
8576
Steven Valdez143e8b32016-07-11 13:19:03 -04008577 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008578 // likely be more epochs to cross and the final message's retransmit may
8579 // be more complex.
8580
David Benjamin11c82892017-02-23 20:40:31 -05008581 // Test that this is indeed the timeout schedule. Stress all
8582 // four patterns of handshake.
8583 for i := 1; i < len(timeouts); i++ {
8584 number := strconv.Itoa(i)
8585 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008586 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008587 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008589 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008590 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008591 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008592 },
8593 },
8594 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008595 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008596 })
David Benjamin11c82892017-02-23 20:40:31 -05008597 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008598 protocol: dtls,
8599 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008600 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008601 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008602 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008603 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008604 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008605 },
8606 },
8607 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008608 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008609 })
8610 }
David Benjamin11c82892017-02-23 20:40:31 -05008611
8612 // Test that exceeding the timeout schedule hits a read
8613 // timeout.
8614 testCases = append(testCases, testCase{
8615 protocol: dtls,
8616 name: "DTLS-Retransmit-Timeout",
8617 config: Config{
8618 MaxVersion: VersionTLS12,
8619 Bugs: ProtocolBugs{
8620 TimeoutSchedule: timeouts,
8621 },
8622 },
8623 resumeSession: true,
8624 flags: []string{"-async"},
8625 shouldFail: true,
8626 expectedError: ":READ_TIMEOUT_EXPIRED:",
8627 })
8628
8629 // Test that timeout handling has a fudge factor, due to API
8630 // problems.
8631 testCases = append(testCases, testCase{
8632 protocol: dtls,
8633 name: "DTLS-Retransmit-Fudge",
8634 config: Config{
8635 MaxVersion: VersionTLS12,
8636 Bugs: ProtocolBugs{
8637 TimeoutSchedule: []time.Duration{
8638 timeouts[0] - 10*time.Millisecond,
8639 },
8640 },
8641 },
8642 resumeSession: true,
8643 flags: []string{"-async"},
8644 })
8645
8646 // Test that the final Finished retransmitting isn't
8647 // duplicated if the peer badly fragments everything.
8648 testCases = append(testCases, testCase{
8649 testType: serverTest,
8650 protocol: dtls,
8651 name: "DTLS-Retransmit-Fragmented",
8652 config: Config{
8653 MaxVersion: VersionTLS12,
8654 Bugs: ProtocolBugs{
8655 TimeoutSchedule: []time.Duration{timeouts[0]},
8656 MaxHandshakeRecordLength: 2,
8657 },
8658 },
8659 flags: []string{"-async"},
8660 })
8661
8662 // Test the timeout schedule when a shorter initial timeout duration is set.
8663 testCases = append(testCases, testCase{
8664 protocol: dtls,
8665 name: "DTLS-Retransmit-Short-Client",
8666 config: Config{
8667 MaxVersion: VersionTLS12,
8668 Bugs: ProtocolBugs{
8669 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8670 },
8671 },
8672 resumeSession: true,
8673 flags: []string{
8674 "-async",
8675 "-initial-timeout-duration-ms", "250",
8676 },
8677 })
8678 testCases = append(testCases, testCase{
8679 protocol: dtls,
8680 testType: serverTest,
8681 name: "DTLS-Retransmit-Short-Server",
8682 config: Config{
8683 MaxVersion: VersionTLS12,
8684 Bugs: ProtocolBugs{
8685 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8686 },
8687 },
8688 resumeSession: true,
8689 flags: []string{
8690 "-async",
8691 "-initial-timeout-duration-ms", "250",
8692 },
8693 })
David Benjamin83f90402015-01-27 01:09:43 -05008694}
8695
David Benjaminc565ebb2015-04-03 04:06:36 -04008696func addExportKeyingMaterialTests() {
8697 for _, vers := range tlsVersions {
8698 if vers.version == VersionSSL30 {
8699 continue
8700 }
8701 testCases = append(testCases, testCase{
8702 name: "ExportKeyingMaterial-" + vers.name,
8703 config: Config{
8704 MaxVersion: vers.version,
8705 },
David Benjamina5022392017-07-10 17:40:39 -04008706 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008707 exportKeyingMaterial: 1024,
8708 exportLabel: "label",
8709 exportContext: "context",
8710 useExportContext: true,
8711 })
8712 testCases = append(testCases, testCase{
8713 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8714 config: Config{
8715 MaxVersion: vers.version,
8716 },
David Benjamina5022392017-07-10 17:40:39 -04008717 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008718 exportKeyingMaterial: 1024,
8719 })
8720 testCases = append(testCases, testCase{
8721 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8722 config: Config{
8723 MaxVersion: vers.version,
8724 },
David Benjamina5022392017-07-10 17:40:39 -04008725 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008726 exportKeyingMaterial: 1024,
8727 useExportContext: true,
8728 })
8729 testCases = append(testCases, testCase{
8730 name: "ExportKeyingMaterial-Small-" + vers.name,
8731 config: Config{
8732 MaxVersion: vers.version,
8733 },
David Benjamina5022392017-07-10 17:40:39 -04008734 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008735 exportKeyingMaterial: 1,
8736 exportLabel: "label",
8737 exportContext: "context",
8738 useExportContext: true,
8739 })
8740 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008741
David Benjaminc565ebb2015-04-03 04:06:36 -04008742 testCases = append(testCases, testCase{
8743 name: "ExportKeyingMaterial-SSL3",
8744 config: Config{
8745 MaxVersion: VersionSSL30,
8746 },
8747 exportKeyingMaterial: 1024,
8748 exportLabel: "label",
8749 exportContext: "context",
8750 useExportContext: true,
8751 shouldFail: true,
8752 expectedError: "failed to export keying material",
8753 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008754
8755 // Exporters work during a False Start.
8756 testCases = append(testCases, testCase{
8757 name: "ExportKeyingMaterial-FalseStart",
8758 config: Config{
8759 MaxVersion: VersionTLS12,
8760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8761 NextProtos: []string{"foo"},
8762 Bugs: ProtocolBugs{
8763 ExpectFalseStart: true,
8764 },
8765 },
8766 flags: []string{
8767 "-false-start",
8768 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008769 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008770 },
8771 shimWritesFirst: true,
8772 exportKeyingMaterial: 1024,
8773 exportLabel: "label",
8774 exportContext: "context",
8775 useExportContext: true,
8776 })
8777
8778 // Exporters do not work in the middle of a renegotiation. Test this by
8779 // triggering the exporter after every SSL_read call and configuring the
8780 // shim to run asynchronously.
8781 testCases = append(testCases, testCase{
8782 name: "ExportKeyingMaterial-Renegotiate",
8783 config: Config{
8784 MaxVersion: VersionTLS12,
8785 },
8786 renegotiate: 1,
8787 flags: []string{
8788 "-async",
8789 "-use-exporter-between-reads",
8790 "-renegotiate-freely",
8791 "-expect-total-renegotiations", "1",
8792 },
8793 shouldFail: true,
8794 expectedError: "failed to export keying material",
8795 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008796}
8797
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008798func addTLSUniqueTests() {
8799 for _, isClient := range []bool{false, true} {
8800 for _, isResumption := range []bool{false, true} {
8801 for _, hasEMS := range []bool{false, true} {
8802 var suffix string
8803 if isResumption {
8804 suffix = "Resume-"
8805 } else {
8806 suffix = "Full-"
8807 }
8808
8809 if hasEMS {
8810 suffix += "EMS-"
8811 } else {
8812 suffix += "NoEMS-"
8813 }
8814
8815 if isClient {
8816 suffix += "Client"
8817 } else {
8818 suffix += "Server"
8819 }
8820
8821 test := testCase{
8822 name: "TLSUnique-" + suffix,
8823 testTLSUnique: true,
8824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008825 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008826 Bugs: ProtocolBugs{
8827 NoExtendedMasterSecret: !hasEMS,
8828 },
8829 },
8830 }
8831
8832 if isResumption {
8833 test.resumeSession = true
8834 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008835 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008836 Bugs: ProtocolBugs{
8837 NoExtendedMasterSecret: !hasEMS,
8838 },
8839 }
8840 }
8841
8842 if isResumption && !hasEMS {
8843 test.shouldFail = true
8844 test.expectedError = "failed to get tls-unique"
8845 }
8846
8847 testCases = append(testCases, test)
8848 }
8849 }
8850 }
8851}
8852
Adam Langley09505632015-07-30 18:10:13 -07008853func addCustomExtensionTests() {
8854 expectedContents := "custom extension"
8855 emptyString := ""
8856
8857 for _, isClient := range []bool{false, true} {
8858 suffix := "Server"
8859 flag := "-enable-server-custom-extension"
8860 testType := serverTest
8861 if isClient {
8862 suffix = "Client"
8863 flag = "-enable-client-custom-extension"
8864 testType = clientTest
8865 }
8866
8867 testCases = append(testCases, testCase{
8868 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008869 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008871 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008872 Bugs: ProtocolBugs{
8873 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008874 ExpectedCustomExtension: &expectedContents,
8875 },
8876 },
8877 flags: []string{flag},
8878 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008879 testCases = append(testCases, testCase{
8880 testType: testType,
8881 name: "CustomExtensions-" + suffix + "-TLS13",
8882 config: Config{
8883 MaxVersion: VersionTLS13,
8884 Bugs: ProtocolBugs{
8885 CustomExtension: expectedContents,
8886 ExpectedCustomExtension: &expectedContents,
8887 },
8888 },
8889 flags: []string{flag},
8890 })
Adam Langley09505632015-07-30 18:10:13 -07008891
Steven Valdez2a070722017-03-25 20:54:16 -05008892 // 0-RTT is not currently supported with Custom Extensions.
8893 testCases = append(testCases, testCase{
8894 testType: testType,
8895 name: "CustomExtensions-" + suffix + "-EarlyData",
8896 config: Config{
8897 MaxVersion: VersionTLS13,
8898 Bugs: ProtocolBugs{
8899 CustomExtension: expectedContents,
8900 ExpectedCustomExtension: &expectedContents,
8901 },
8902 },
8903 shouldFail: true,
8904 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8905 flags: []string{flag, "-enable-early-data"},
8906 })
8907
Adam Langley09505632015-07-30 18:10:13 -07008908 // If the parse callback fails, the handshake should also fail.
8909 testCases = append(testCases, testCase{
8910 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008911 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008913 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008914 Bugs: ProtocolBugs{
8915 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008916 ExpectedCustomExtension: &expectedContents,
8917 },
8918 },
David Benjamin399e7c92015-07-30 23:01:27 -04008919 flags: []string{flag},
8920 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008921 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8922 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008923 testCases = append(testCases, testCase{
8924 testType: testType,
8925 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8926 config: Config{
8927 MaxVersion: VersionTLS13,
8928 Bugs: ProtocolBugs{
8929 CustomExtension: expectedContents + "foo",
8930 ExpectedCustomExtension: &expectedContents,
8931 },
8932 },
8933 flags: []string{flag},
8934 shouldFail: true,
8935 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8936 })
Adam Langley09505632015-07-30 18:10:13 -07008937
8938 // If the add callback fails, the handshake should also fail.
8939 testCases = append(testCases, testCase{
8940 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008941 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008942 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008943 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008944 Bugs: ProtocolBugs{
8945 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008946 ExpectedCustomExtension: &expectedContents,
8947 },
8948 },
David Benjamin399e7c92015-07-30 23:01:27 -04008949 flags: []string{flag, "-custom-extension-fail-add"},
8950 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008951 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8952 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008953 testCases = append(testCases, testCase{
8954 testType: testType,
8955 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8956 config: Config{
8957 MaxVersion: VersionTLS13,
8958 Bugs: ProtocolBugs{
8959 CustomExtension: expectedContents,
8960 ExpectedCustomExtension: &expectedContents,
8961 },
8962 },
8963 flags: []string{flag, "-custom-extension-fail-add"},
8964 shouldFail: true,
8965 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8966 })
Adam Langley09505632015-07-30 18:10:13 -07008967
8968 // If the add callback returns zero, no extension should be
8969 // added.
8970 skipCustomExtension := expectedContents
8971 if isClient {
8972 // For the case where the client skips sending the
8973 // custom extension, the server must not “echo” it.
8974 skipCustomExtension = ""
8975 }
8976 testCases = append(testCases, testCase{
8977 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008978 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008980 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008981 Bugs: ProtocolBugs{
8982 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008983 ExpectedCustomExtension: &emptyString,
8984 },
8985 },
8986 flags: []string{flag, "-custom-extension-skip"},
8987 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008988 testCases = append(testCases, testCase{
8989 testType: testType,
8990 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8991 config: Config{
8992 MaxVersion: VersionTLS13,
8993 Bugs: ProtocolBugs{
8994 CustomExtension: skipCustomExtension,
8995 ExpectedCustomExtension: &emptyString,
8996 },
8997 },
8998 flags: []string{flag, "-custom-extension-skip"},
8999 })
Adam Langley09505632015-07-30 18:10:13 -07009000 }
9001
9002 // The custom extension add callback should not be called if the client
9003 // doesn't send the extension.
9004 testCases = append(testCases, testCase{
9005 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009006 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009007 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009008 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009009 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009010 ExpectedCustomExtension: &emptyString,
9011 },
9012 },
9013 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9014 })
Adam Langley2deb9842015-08-07 11:15:37 -07009015
Steven Valdez143e8b32016-07-11 13:19:03 -04009016 testCases = append(testCases, testCase{
9017 testType: serverTest,
9018 name: "CustomExtensions-NotCalled-Server-TLS13",
9019 config: Config{
9020 MaxVersion: VersionTLS13,
9021 Bugs: ProtocolBugs{
9022 ExpectedCustomExtension: &emptyString,
9023 },
9024 },
9025 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9026 })
9027
Adam Langley2deb9842015-08-07 11:15:37 -07009028 // Test an unknown extension from the server.
9029 testCases = append(testCases, testCase{
9030 testType: clientTest,
9031 name: "UnknownExtension-Client",
9032 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009033 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009034 Bugs: ProtocolBugs{
9035 CustomExtension: expectedContents,
9036 },
9037 },
David Benjamin0c40a962016-08-01 12:05:50 -04009038 shouldFail: true,
9039 expectedError: ":UNEXPECTED_EXTENSION:",
9040 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009041 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009042 testCases = append(testCases, testCase{
9043 testType: clientTest,
9044 name: "UnknownExtension-Client-TLS13",
9045 config: Config{
9046 MaxVersion: VersionTLS13,
9047 Bugs: ProtocolBugs{
9048 CustomExtension: expectedContents,
9049 },
9050 },
David Benjamin0c40a962016-08-01 12:05:50 -04009051 shouldFail: true,
9052 expectedError: ":UNEXPECTED_EXTENSION:",
9053 expectedLocalError: "remote error: unsupported extension",
9054 })
David Benjamin490469f2016-10-05 22:44:38 -04009055 testCases = append(testCases, testCase{
9056 testType: clientTest,
9057 name: "UnknownUnencryptedExtension-Client-TLS13",
9058 config: Config{
9059 MaxVersion: VersionTLS13,
9060 Bugs: ProtocolBugs{
9061 CustomUnencryptedExtension: expectedContents,
9062 },
9063 },
9064 shouldFail: true,
9065 expectedError: ":UNEXPECTED_EXTENSION:",
9066 // The shim must send an alert, but alerts at this point do not
9067 // get successfully decrypted by the runner.
9068 expectedLocalError: "local error: bad record MAC",
9069 })
9070 testCases = append(testCases, testCase{
9071 testType: clientTest,
9072 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9073 config: Config{
9074 MaxVersion: VersionTLS13,
9075 Bugs: ProtocolBugs{
9076 SendUnencryptedALPN: "foo",
9077 },
9078 },
9079 flags: []string{
9080 "-advertise-alpn", "\x03foo\x03bar",
9081 },
9082 shouldFail: true,
9083 expectedError: ":UNEXPECTED_EXTENSION:",
9084 // The shim must send an alert, but alerts at this point do not
9085 // get successfully decrypted by the runner.
9086 expectedLocalError: "local error: bad record MAC",
9087 })
David Benjamin0c40a962016-08-01 12:05:50 -04009088
9089 // Test a known but unoffered extension from the server.
9090 testCases = append(testCases, testCase{
9091 testType: clientTest,
9092 name: "UnofferedExtension-Client",
9093 config: Config{
9094 MaxVersion: VersionTLS12,
9095 Bugs: ProtocolBugs{
9096 SendALPN: "alpn",
9097 },
9098 },
9099 shouldFail: true,
9100 expectedError: ":UNEXPECTED_EXTENSION:",
9101 expectedLocalError: "remote error: unsupported extension",
9102 })
9103 testCases = append(testCases, testCase{
9104 testType: clientTest,
9105 name: "UnofferedExtension-Client-TLS13",
9106 config: Config{
9107 MaxVersion: VersionTLS13,
9108 Bugs: ProtocolBugs{
9109 SendALPN: "alpn",
9110 },
9111 },
9112 shouldFail: true,
9113 expectedError: ":UNEXPECTED_EXTENSION:",
9114 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009115 })
Adam Langley09505632015-07-30 18:10:13 -07009116}
9117
David Benjaminb36a3952015-12-01 18:53:13 -05009118func addRSAClientKeyExchangeTests() {
9119 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9120 testCases = append(testCases, testCase{
9121 testType: serverTest,
9122 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9123 config: Config{
9124 // Ensure the ClientHello version and final
9125 // version are different, to detect if the
9126 // server uses the wrong one.
9127 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009128 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009129 Bugs: ProtocolBugs{
9130 BadRSAClientKeyExchange: bad,
9131 },
9132 },
9133 shouldFail: true,
9134 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9135 })
9136 }
David Benjamine63d9d72016-09-19 18:27:34 -04009137
9138 // The server must compare whatever was in ClientHello.version for the
9139 // RSA premaster.
9140 testCases = append(testCases, testCase{
9141 testType: serverTest,
9142 name: "SendClientVersion-RSA",
9143 config: Config{
9144 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9145 Bugs: ProtocolBugs{
9146 SendClientVersion: 0x1234,
9147 },
9148 },
9149 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9150 })
David Benjaminb36a3952015-12-01 18:53:13 -05009151}
9152
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009153var testCurves = []struct {
9154 name string
9155 id CurveID
9156}{
Adam Langley764ab982017-03-10 18:01:30 -08009157 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009158 {"P-256", CurveP256},
9159 {"P-384", CurveP384},
9160 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009161 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009162}
9163
Steven Valdez5440fe02016-07-18 12:40:30 -04009164const bogusCurve = 0x1234
9165
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009166func addCurveTests() {
9167 for _, curve := range testCurves {
9168 testCases = append(testCases, testCase{
9169 name: "CurveTest-Client-" + curve.name,
9170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009171 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009172 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9173 CurvePreferences: []CurveID{curve.id},
9174 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009175 flags: []string{
9176 "-enable-all-curves",
9177 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9178 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009179 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009180 })
9181 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009182 name: "CurveTest-Client-" + curve.name + "-TLS13",
9183 config: Config{
9184 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009185 CurvePreferences: []CurveID{curve.id},
9186 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009187 flags: []string{
9188 "-enable-all-curves",
9189 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9190 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009191 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009192 })
9193 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009194 testType: serverTest,
9195 name: "CurveTest-Server-" + curve.name,
9196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009197 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9199 CurvePreferences: []CurveID{curve.id},
9200 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009201 flags: []string{
9202 "-enable-all-curves",
9203 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9204 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009205 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009206 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009207 testCases = append(testCases, testCase{
9208 testType: serverTest,
9209 name: "CurveTest-Server-" + curve.name + "-TLS13",
9210 config: Config{
9211 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009212 CurvePreferences: []CurveID{curve.id},
9213 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009214 flags: []string{
9215 "-enable-all-curves",
9216 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9217 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009218 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009219 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009220 }
David Benjamin241ae832016-01-15 03:04:54 -05009221
9222 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009223 testCases = append(testCases, testCase{
9224 testType: serverTest,
9225 name: "UnknownCurve",
9226 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009227 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009228 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9229 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9230 },
9231 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009232
Steven Valdez803c77a2016-09-06 14:13:43 -04009233 // The server must be tolerant to bogus curves.
9234 testCases = append(testCases, testCase{
9235 testType: serverTest,
9236 name: "UnknownCurve-TLS13",
9237 config: Config{
9238 MaxVersion: VersionTLS13,
9239 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9240 },
9241 })
9242
David Benjamin4c3ddf72016-06-29 18:13:53 -04009243 // The server must not consider ECDHE ciphers when there are no
9244 // supported curves.
9245 testCases = append(testCases, testCase{
9246 testType: serverTest,
9247 name: "NoSupportedCurves",
9248 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009249 MaxVersion: VersionTLS12,
9250 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9251 Bugs: ProtocolBugs{
9252 NoSupportedCurves: true,
9253 },
9254 },
9255 shouldFail: true,
9256 expectedError: ":NO_SHARED_CIPHER:",
9257 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009258 testCases = append(testCases, testCase{
9259 testType: serverTest,
9260 name: "NoSupportedCurves-TLS13",
9261 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009262 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009263 Bugs: ProtocolBugs{
9264 NoSupportedCurves: true,
9265 },
9266 },
9267 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009268 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009269 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009270
9271 // The server must fall back to another cipher when there are no
9272 // supported curves.
9273 testCases = append(testCases, testCase{
9274 testType: serverTest,
9275 name: "NoCommonCurves",
9276 config: Config{
9277 MaxVersion: VersionTLS12,
9278 CipherSuites: []uint16{
9279 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009280 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009281 },
9282 CurvePreferences: []CurveID{CurveP224},
9283 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009284 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009285 })
9286
9287 // The client must reject bogus curves and disabled curves.
9288 testCases = append(testCases, testCase{
9289 name: "BadECDHECurve",
9290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009291 MaxVersion: VersionTLS12,
9292 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9293 Bugs: ProtocolBugs{
9294 SendCurve: bogusCurve,
9295 },
9296 },
9297 shouldFail: true,
9298 expectedError: ":WRONG_CURVE:",
9299 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009300 testCases = append(testCases, testCase{
9301 name: "BadECDHECurve-TLS13",
9302 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009303 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009304 Bugs: ProtocolBugs{
9305 SendCurve: bogusCurve,
9306 },
9307 },
9308 shouldFail: true,
9309 expectedError: ":WRONG_CURVE:",
9310 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009311
9312 testCases = append(testCases, testCase{
9313 name: "UnsupportedCurve",
9314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009315 MaxVersion: VersionTLS12,
9316 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9317 CurvePreferences: []CurveID{CurveP256},
9318 Bugs: ProtocolBugs{
9319 IgnorePeerCurvePreferences: true,
9320 },
9321 },
9322 flags: []string{"-p384-only"},
9323 shouldFail: true,
9324 expectedError: ":WRONG_CURVE:",
9325 })
9326
David Benjamin4f921572016-07-17 14:20:10 +02009327 testCases = append(testCases, testCase{
9328 // TODO(davidben): Add a TLS 1.3 version where
9329 // HelloRetryRequest requests an unsupported curve.
9330 name: "UnsupportedCurve-ServerHello-TLS13",
9331 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009332 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009333 CurvePreferences: []CurveID{CurveP384},
9334 Bugs: ProtocolBugs{
9335 SendCurve: CurveP256,
9336 },
9337 },
9338 flags: []string{"-p384-only"},
9339 shouldFail: true,
9340 expectedError: ":WRONG_CURVE:",
9341 })
9342
David Benjamin4c3ddf72016-06-29 18:13:53 -04009343 // Test invalid curve points.
9344 testCases = append(testCases, testCase{
9345 name: "InvalidECDHPoint-Client",
9346 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009347 MaxVersion: VersionTLS12,
9348 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9349 CurvePreferences: []CurveID{CurveP256},
9350 Bugs: ProtocolBugs{
9351 InvalidECDHPoint: true,
9352 },
9353 },
9354 shouldFail: true,
9355 expectedError: ":INVALID_ENCODING:",
9356 })
9357 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009358 name: "InvalidECDHPoint-Client-TLS13",
9359 config: Config{
9360 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009361 CurvePreferences: []CurveID{CurveP256},
9362 Bugs: ProtocolBugs{
9363 InvalidECDHPoint: true,
9364 },
9365 },
9366 shouldFail: true,
9367 expectedError: ":INVALID_ENCODING:",
9368 })
9369 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009370 testType: serverTest,
9371 name: "InvalidECDHPoint-Server",
9372 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009373 MaxVersion: VersionTLS12,
9374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9375 CurvePreferences: []CurveID{CurveP256},
9376 Bugs: ProtocolBugs{
9377 InvalidECDHPoint: true,
9378 },
9379 },
9380 shouldFail: true,
9381 expectedError: ":INVALID_ENCODING:",
9382 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009383 testCases = append(testCases, testCase{
9384 testType: serverTest,
9385 name: "InvalidECDHPoint-Server-TLS13",
9386 config: Config{
9387 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009388 CurvePreferences: []CurveID{CurveP256},
9389 Bugs: ProtocolBugs{
9390 InvalidECDHPoint: true,
9391 },
9392 },
9393 shouldFail: true,
9394 expectedError: ":INVALID_ENCODING:",
9395 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009396
9397 // The previous curve ID should be reported on TLS 1.2 resumption.
9398 testCases = append(testCases, testCase{
9399 name: "CurveID-Resume-Client",
9400 config: Config{
9401 MaxVersion: VersionTLS12,
9402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9403 CurvePreferences: []CurveID{CurveX25519},
9404 },
9405 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9406 resumeSession: true,
9407 })
9408 testCases = append(testCases, testCase{
9409 testType: serverTest,
9410 name: "CurveID-Resume-Server",
9411 config: Config{
9412 MaxVersion: VersionTLS12,
9413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9414 CurvePreferences: []CurveID{CurveX25519},
9415 },
9416 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9417 resumeSession: true,
9418 })
9419
9420 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9421 // one should be reported.
9422 testCases = append(testCases, testCase{
9423 name: "CurveID-Resume-Client-TLS13",
9424 config: Config{
9425 MaxVersion: VersionTLS13,
9426 CurvePreferences: []CurveID{CurveX25519},
9427 },
9428 resumeConfig: &Config{
9429 MaxVersion: VersionTLS13,
9430 CurvePreferences: []CurveID{CurveP256},
9431 },
9432 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009433 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9434 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009435 },
9436 resumeSession: true,
9437 })
9438 testCases = append(testCases, testCase{
9439 testType: serverTest,
9440 name: "CurveID-Resume-Server-TLS13",
9441 config: Config{
9442 MaxVersion: VersionTLS13,
9443 CurvePreferences: []CurveID{CurveX25519},
9444 },
9445 resumeConfig: &Config{
9446 MaxVersion: VersionTLS13,
9447 CurvePreferences: []CurveID{CurveP256},
9448 },
9449 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009450 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9451 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009452 },
9453 resumeSession: true,
9454 })
David Benjamina81967b2016-12-22 09:16:57 -05009455
9456 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9457 testCases = append(testCases, testCase{
9458 name: "PointFormat-ServerHello-TLS12",
9459 config: Config{
9460 MaxVersion: VersionTLS12,
9461 Bugs: ProtocolBugs{
9462 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9463 },
9464 },
9465 })
9466 testCases = append(testCases, testCase{
9467 name: "PointFormat-EncryptedExtensions-TLS13",
9468 config: Config{
9469 MaxVersion: VersionTLS13,
9470 Bugs: ProtocolBugs{
9471 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9472 },
9473 },
9474 shouldFail: true,
9475 expectedError: ":ERROR_PARSING_EXTENSION:",
9476 })
9477
9478 // Test that we tolerate unknown point formats, as long as
9479 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9480 // check they are still functional.
9481 testCases = append(testCases, testCase{
9482 name: "PointFormat-Client-Tolerance",
9483 config: Config{
9484 MaxVersion: VersionTLS12,
9485 Bugs: ProtocolBugs{
9486 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9487 },
9488 },
9489 })
9490 testCases = append(testCases, testCase{
9491 testType: serverTest,
9492 name: "PointFormat-Server-Tolerance",
9493 config: Config{
9494 MaxVersion: VersionTLS12,
9495 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9496 Bugs: ProtocolBugs{
9497 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9498 },
9499 },
9500 })
9501
9502 // Test TLS 1.2 does not require the point format extension to be
9503 // present.
9504 testCases = append(testCases, testCase{
9505 name: "PointFormat-Client-Missing",
9506 config: Config{
9507 MaxVersion: VersionTLS12,
9508 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9509 Bugs: ProtocolBugs{
9510 SendSupportedPointFormats: []byte{},
9511 },
9512 },
9513 })
9514 testCases = append(testCases, testCase{
9515 testType: serverTest,
9516 name: "PointFormat-Server-Missing",
9517 config: Config{
9518 MaxVersion: VersionTLS12,
9519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9520 Bugs: ProtocolBugs{
9521 SendSupportedPointFormats: []byte{},
9522 },
9523 },
9524 })
9525
9526 // If the point format extension is present, uncompressed points must be
9527 // offered. BoringSSL requires this whether or not ECDHE is used.
9528 testCases = append(testCases, testCase{
9529 name: "PointFormat-Client-MissingUncompressed",
9530 config: Config{
9531 MaxVersion: VersionTLS12,
9532 Bugs: ProtocolBugs{
9533 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9534 },
9535 },
9536 shouldFail: true,
9537 expectedError: ":ERROR_PARSING_EXTENSION:",
9538 })
9539 testCases = append(testCases, testCase{
9540 testType: serverTest,
9541 name: "PointFormat-Server-MissingUncompressed",
9542 config: Config{
9543 MaxVersion: VersionTLS12,
9544 Bugs: ProtocolBugs{
9545 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9546 },
9547 },
9548 shouldFail: true,
9549 expectedError: ":ERROR_PARSING_EXTENSION:",
9550 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009551}
9552
David Benjaminc9ae27c2016-06-24 22:56:37 -04009553func addTLS13RecordTests() {
9554 testCases = append(testCases, testCase{
9555 name: "TLS13-RecordPadding",
9556 config: Config{
9557 MaxVersion: VersionTLS13,
9558 MinVersion: VersionTLS13,
9559 Bugs: ProtocolBugs{
9560 RecordPadding: 10,
9561 },
9562 },
9563 })
9564
9565 testCases = append(testCases, testCase{
9566 name: "TLS13-EmptyRecords",
9567 config: Config{
9568 MaxVersion: VersionTLS13,
9569 MinVersion: VersionTLS13,
9570 Bugs: ProtocolBugs{
9571 OmitRecordContents: true,
9572 },
9573 },
9574 shouldFail: true,
9575 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9576 })
9577
9578 testCases = append(testCases, testCase{
9579 name: "TLS13-OnlyPadding",
9580 config: Config{
9581 MaxVersion: VersionTLS13,
9582 MinVersion: VersionTLS13,
9583 Bugs: ProtocolBugs{
9584 OmitRecordContents: true,
9585 RecordPadding: 10,
9586 },
9587 },
9588 shouldFail: true,
9589 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9590 })
9591
9592 testCases = append(testCases, testCase{
9593 name: "TLS13-WrongOuterRecord",
9594 config: Config{
9595 MaxVersion: VersionTLS13,
9596 MinVersion: VersionTLS13,
9597 Bugs: ProtocolBugs{
9598 OuterRecordType: recordTypeHandshake,
9599 },
9600 },
9601 shouldFail: true,
9602 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9603 })
9604}
9605
Steven Valdez5b986082016-09-01 12:29:49 -04009606func addSessionTicketTests() {
9607 testCases = append(testCases, testCase{
9608 // In TLS 1.2 and below, empty NewSessionTicket messages
9609 // mean the server changed its mind on sending a ticket.
9610 name: "SendEmptySessionTicket",
9611 config: Config{
9612 MaxVersion: VersionTLS12,
9613 Bugs: ProtocolBugs{
9614 SendEmptySessionTicket: true,
9615 },
9616 },
9617 flags: []string{"-expect-no-session"},
9618 })
9619
9620 // Test that the server ignores unknown PSK modes.
9621 testCases = append(testCases, testCase{
9622 testType: serverTest,
9623 name: "TLS13-SendUnknownModeSessionTicket-Server",
9624 config: Config{
9625 MaxVersion: VersionTLS13,
9626 Bugs: ProtocolBugs{
9627 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009628 },
9629 },
9630 resumeSession: true,
9631 expectedResumeVersion: VersionTLS13,
9632 })
9633
Steven Valdeza833c352016-11-01 13:39:36 -04009634 // Test that the server does not send session tickets with no matching key exchange mode.
9635 testCases = append(testCases, testCase{
9636 testType: serverTest,
9637 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9638 config: Config{
9639 MaxVersion: VersionTLS13,
9640 Bugs: ProtocolBugs{
9641 SendPSKKeyExchangeModes: []byte{0x1a},
9642 ExpectNoNewSessionTicket: true,
9643 },
9644 },
9645 })
9646
9647 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009648 testCases = append(testCases, testCase{
9649 testType: serverTest,
9650 name: "TLS13-SendBadKEModeSessionTicket-Server",
9651 config: Config{
9652 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009653 },
9654 resumeConfig: &Config{
9655 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009656 Bugs: ProtocolBugs{
9657 SendPSKKeyExchangeModes: []byte{0x1a},
9658 },
9659 },
9660 resumeSession: true,
9661 expectResumeRejected: true,
9662 })
9663
Steven Valdeza833c352016-11-01 13:39:36 -04009664 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009665 testCases = append(testCases, testCase{
9666 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009667 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009668 config: Config{
9669 MaxVersion: VersionTLS13,
9670 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009671 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009672 },
9673 },
Steven Valdeza833c352016-11-01 13:39:36 -04009674 resumeSession: true,
9675 flags: []string{
9676 "-resumption-delay", "10",
9677 },
Steven Valdez5b986082016-09-01 12:29:49 -04009678 })
9679
Steven Valdeza833c352016-11-01 13:39:36 -04009680 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009681 testCases = append(testCases, testCase{
9682 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009683 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009684 config: Config{
9685 MaxVersion: VersionTLS13,
9686 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009687 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009688 },
9689 },
Steven Valdeza833c352016-11-01 13:39:36 -04009690 resumeSession: true,
9691 shouldFail: true,
9692 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009693 })
9694
David Benjamin35ac5b72017-03-03 15:05:56 -05009695 // Test that the server's ticket age skew reporting works.
9696 testCases = append(testCases, testCase{
9697 testType: serverTest,
9698 name: "TLS13-TicketAgeSkew-Forward",
9699 config: Config{
9700 MaxVersion: VersionTLS13,
9701 Bugs: ProtocolBugs{
9702 SendTicketAge: 15 * time.Second,
9703 },
9704 },
David Benjamin065d7332017-03-26 10:51:43 -05009705 resumeSession: true,
9706 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009707 flags: []string{
9708 "-resumption-delay", "10",
9709 "-expect-ticket-age-skew", "5",
9710 },
9711 })
9712 testCases = append(testCases, testCase{
9713 testType: serverTest,
9714 name: "TLS13-TicketAgeSkew-Backward",
9715 config: Config{
9716 MaxVersion: VersionTLS13,
9717 Bugs: ProtocolBugs{
9718 SendTicketAge: 5 * time.Second,
9719 },
9720 },
David Benjamin065d7332017-03-26 10:51:43 -05009721 resumeSession: true,
9722 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009723 flags: []string{
9724 "-resumption-delay", "10",
9725 "-expect-ticket-age-skew", "-5",
9726 },
9727 })
9728
Steven Valdez08b65f42016-12-07 15:29:45 -05009729 testCases = append(testCases, testCase{
9730 testType: clientTest,
9731 name: "TLS13-SendTicketEarlyDataInfo",
9732 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009733 MaxVersion: VersionTLS13,
9734 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009735 },
9736 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009737 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009738 "-expect-early-data-info",
9739 },
9740 })
9741
David Benjamin9b160662017-01-25 19:53:43 -05009742 // Test that 0-RTT tickets are ignored in clients unless opted in.
9743 testCases = append(testCases, testCase{
9744 testType: clientTest,
9745 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9746 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009747 MaxVersion: VersionTLS13,
9748 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009749 },
9750 })
9751
Steven Valdez08b65f42016-12-07 15:29:45 -05009752 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009753 testType: clientTest,
9754 name: "TLS13-DuplicateTicketEarlyDataInfo",
9755 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009756 MaxVersion: VersionTLS13,
9757 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009758 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009759 DuplicateTicketEarlyDataInfo: true,
9760 },
9761 },
9762 shouldFail: true,
9763 expectedError: ":DUPLICATE_EXTENSION:",
9764 expectedLocalError: "remote error: illegal parameter",
9765 })
9766
9767 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009768 testType: serverTest,
9769 name: "TLS13-ExpectTicketEarlyDataInfo",
9770 config: Config{
9771 MaxVersion: VersionTLS13,
9772 Bugs: ProtocolBugs{
9773 ExpectTicketEarlyDataInfo: true,
9774 },
9775 },
9776 flags: []string{
9777 "-enable-early-data",
9778 },
9779 })
David Benjamin17b30832017-01-28 14:00:32 -05009780
9781 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9782 // is honored.
9783 testCases = append(testCases, testCase{
9784 testType: clientTest,
9785 name: "TLS13-HonorServerSessionTicketLifetime",
9786 config: Config{
9787 MaxVersion: VersionTLS13,
9788 Bugs: ProtocolBugs{
9789 SendTicketLifetime: 20 * time.Second,
9790 },
9791 },
9792 flags: []string{
9793 "-resumption-delay", "19",
9794 },
9795 resumeSession: true,
9796 })
9797 testCases = append(testCases, testCase{
9798 testType: clientTest,
9799 name: "TLS13-HonorServerSessionTicketLifetime-2",
9800 config: Config{
9801 MaxVersion: VersionTLS13,
9802 Bugs: ProtocolBugs{
9803 SendTicketLifetime: 20 * time.Second,
9804 // The client should not offer the expired session.
9805 ExpectNoTLS13PSK: true,
9806 },
9807 },
9808 flags: []string{
9809 "-resumption-delay", "21",
9810 },
David Benjamin023d4192017-02-06 13:49:07 -05009811 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009812 expectResumeRejected: true,
9813 })
Steven Valdez5b986082016-09-01 12:29:49 -04009814}
9815
David Benjamin82261be2016-07-07 14:32:50 -07009816func addChangeCipherSpecTests() {
9817 // Test missing ChangeCipherSpecs.
9818 testCases = append(testCases, testCase{
9819 name: "SkipChangeCipherSpec-Client",
9820 config: Config{
9821 MaxVersion: VersionTLS12,
9822 Bugs: ProtocolBugs{
9823 SkipChangeCipherSpec: true,
9824 },
9825 },
9826 shouldFail: true,
9827 expectedError: ":UNEXPECTED_RECORD:",
9828 })
9829 testCases = append(testCases, testCase{
9830 testType: serverTest,
9831 name: "SkipChangeCipherSpec-Server",
9832 config: Config{
9833 MaxVersion: VersionTLS12,
9834 Bugs: ProtocolBugs{
9835 SkipChangeCipherSpec: true,
9836 },
9837 },
9838 shouldFail: true,
9839 expectedError: ":UNEXPECTED_RECORD:",
9840 })
9841 testCases = append(testCases, testCase{
9842 testType: serverTest,
9843 name: "SkipChangeCipherSpec-Server-NPN",
9844 config: Config{
9845 MaxVersion: VersionTLS12,
9846 NextProtos: []string{"bar"},
9847 Bugs: ProtocolBugs{
9848 SkipChangeCipherSpec: true,
9849 },
9850 },
9851 flags: []string{
9852 "-advertise-npn", "\x03foo\x03bar\x03baz",
9853 },
9854 shouldFail: true,
9855 expectedError: ":UNEXPECTED_RECORD:",
9856 })
9857
9858 // Test synchronization between the handshake and ChangeCipherSpec.
9859 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9860 // rejected. Test both with and without handshake packing to handle both
9861 // when the partial post-CCS message is in its own record and when it is
9862 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009863 for _, packed := range []bool{false, true} {
9864 var suffix string
9865 if packed {
9866 suffix = "-Packed"
9867 }
9868
9869 testCases = append(testCases, testCase{
9870 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9871 config: Config{
9872 MaxVersion: VersionTLS12,
9873 Bugs: ProtocolBugs{
9874 FragmentAcrossChangeCipherSpec: true,
9875 PackHandshakeFlight: packed,
9876 },
9877 },
9878 shouldFail: true,
9879 expectedError: ":UNEXPECTED_RECORD:",
9880 })
9881 testCases = append(testCases, testCase{
9882 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9883 config: Config{
9884 MaxVersion: VersionTLS12,
9885 },
9886 resumeSession: true,
9887 resumeConfig: &Config{
9888 MaxVersion: VersionTLS12,
9889 Bugs: ProtocolBugs{
9890 FragmentAcrossChangeCipherSpec: true,
9891 PackHandshakeFlight: packed,
9892 },
9893 },
9894 shouldFail: true,
9895 expectedError: ":UNEXPECTED_RECORD:",
9896 })
9897 testCases = append(testCases, testCase{
9898 testType: serverTest,
9899 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9900 config: Config{
9901 MaxVersion: VersionTLS12,
9902 Bugs: ProtocolBugs{
9903 FragmentAcrossChangeCipherSpec: true,
9904 PackHandshakeFlight: packed,
9905 },
9906 },
9907 shouldFail: true,
9908 expectedError: ":UNEXPECTED_RECORD:",
9909 })
9910 testCases = append(testCases, testCase{
9911 testType: serverTest,
9912 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9913 config: Config{
9914 MaxVersion: VersionTLS12,
9915 },
9916 resumeSession: true,
9917 resumeConfig: &Config{
9918 MaxVersion: VersionTLS12,
9919 Bugs: ProtocolBugs{
9920 FragmentAcrossChangeCipherSpec: true,
9921 PackHandshakeFlight: packed,
9922 },
9923 },
9924 shouldFail: true,
9925 expectedError: ":UNEXPECTED_RECORD:",
9926 })
9927 testCases = append(testCases, testCase{
9928 testType: serverTest,
9929 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9930 config: Config{
9931 MaxVersion: VersionTLS12,
9932 NextProtos: []string{"bar"},
9933 Bugs: ProtocolBugs{
9934 FragmentAcrossChangeCipherSpec: true,
9935 PackHandshakeFlight: packed,
9936 },
9937 },
9938 flags: []string{
9939 "-advertise-npn", "\x03foo\x03bar\x03baz",
9940 },
9941 shouldFail: true,
9942 expectedError: ":UNEXPECTED_RECORD:",
9943 })
9944 }
9945
David Benjamin61672812016-07-14 23:10:43 -04009946 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9947 // messages in the handshake queue. Do this by testing the server
9948 // reading the client Finished, reversing the flight so Finished comes
9949 // first.
9950 testCases = append(testCases, testCase{
9951 protocol: dtls,
9952 testType: serverTest,
9953 name: "SendUnencryptedFinished-DTLS",
9954 config: Config{
9955 MaxVersion: VersionTLS12,
9956 Bugs: ProtocolBugs{
9957 SendUnencryptedFinished: true,
9958 ReverseHandshakeFragments: true,
9959 },
9960 },
9961 shouldFail: true,
9962 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9963 })
9964
Steven Valdez143e8b32016-07-11 13:19:03 -04009965 // Test synchronization between encryption changes and the handshake in
9966 // TLS 1.3, where ChangeCipherSpec is implicit.
9967 testCases = append(testCases, testCase{
9968 name: "PartialEncryptedExtensionsWithServerHello",
9969 config: Config{
9970 MaxVersion: VersionTLS13,
9971 Bugs: ProtocolBugs{
9972 PartialEncryptedExtensionsWithServerHello: true,
9973 },
9974 },
9975 shouldFail: true,
9976 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9977 })
9978 testCases = append(testCases, testCase{
9979 testType: serverTest,
9980 name: "PartialClientFinishedWithClientHello",
9981 config: Config{
9982 MaxVersion: VersionTLS13,
9983 Bugs: ProtocolBugs{
9984 PartialClientFinishedWithClientHello: true,
9985 },
9986 },
9987 shouldFail: true,
9988 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9989 })
9990
David Benjamin82261be2016-07-07 14:32:50 -07009991 // Test that early ChangeCipherSpecs are handled correctly.
9992 testCases = append(testCases, testCase{
9993 testType: serverTest,
9994 name: "EarlyChangeCipherSpec-server-1",
9995 config: Config{
9996 MaxVersion: VersionTLS12,
9997 Bugs: ProtocolBugs{
9998 EarlyChangeCipherSpec: 1,
9999 },
10000 },
10001 shouldFail: true,
10002 expectedError: ":UNEXPECTED_RECORD:",
10003 })
10004 testCases = append(testCases, testCase{
10005 testType: serverTest,
10006 name: "EarlyChangeCipherSpec-server-2",
10007 config: Config{
10008 MaxVersion: VersionTLS12,
10009 Bugs: ProtocolBugs{
10010 EarlyChangeCipherSpec: 2,
10011 },
10012 },
10013 shouldFail: true,
10014 expectedError: ":UNEXPECTED_RECORD:",
10015 })
10016 testCases = append(testCases, testCase{
10017 protocol: dtls,
10018 name: "StrayChangeCipherSpec",
10019 config: Config{
10020 // TODO(davidben): Once DTLS 1.3 exists, test
10021 // that stray ChangeCipherSpec messages are
10022 // rejected.
10023 MaxVersion: VersionTLS12,
10024 Bugs: ProtocolBugs{
10025 StrayChangeCipherSpec: true,
10026 },
10027 },
10028 })
10029
10030 // Test that the contents of ChangeCipherSpec are checked.
10031 testCases = append(testCases, testCase{
10032 name: "BadChangeCipherSpec-1",
10033 config: Config{
10034 MaxVersion: VersionTLS12,
10035 Bugs: ProtocolBugs{
10036 BadChangeCipherSpec: []byte{2},
10037 },
10038 },
10039 shouldFail: true,
10040 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10041 })
10042 testCases = append(testCases, testCase{
10043 name: "BadChangeCipherSpec-2",
10044 config: Config{
10045 MaxVersion: VersionTLS12,
10046 Bugs: ProtocolBugs{
10047 BadChangeCipherSpec: []byte{1, 1},
10048 },
10049 },
10050 shouldFail: true,
10051 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10052 })
10053 testCases = append(testCases, testCase{
10054 protocol: dtls,
10055 name: "BadChangeCipherSpec-DTLS-1",
10056 config: Config{
10057 MaxVersion: VersionTLS12,
10058 Bugs: ProtocolBugs{
10059 BadChangeCipherSpec: []byte{2},
10060 },
10061 },
10062 shouldFail: true,
10063 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10064 })
10065 testCases = append(testCases, testCase{
10066 protocol: dtls,
10067 name: "BadChangeCipherSpec-DTLS-2",
10068 config: Config{
10069 MaxVersion: VersionTLS12,
10070 Bugs: ProtocolBugs{
10071 BadChangeCipherSpec: []byte{1, 1},
10072 },
10073 },
10074 shouldFail: true,
10075 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10076 })
10077}
10078
David Benjamincd2c8062016-09-09 11:28:16 -040010079type perMessageTest struct {
10080 messageType uint8
10081 test testCase
10082}
10083
10084// makePerMessageTests returns a series of test templates which cover each
10085// message in the TLS handshake. These may be used with bugs like
10086// WrongMessageType to fully test a per-message bug.
10087func makePerMessageTests() []perMessageTest {
10088 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010089 for _, protocol := range []protocol{tls, dtls} {
10090 var suffix string
10091 if protocol == dtls {
10092 suffix = "-DTLS"
10093 }
10094
David Benjamincd2c8062016-09-09 11:28:16 -040010095 ret = append(ret, perMessageTest{
10096 messageType: typeClientHello,
10097 test: testCase{
10098 protocol: protocol,
10099 testType: serverTest,
10100 name: "ClientHello" + suffix,
10101 config: Config{
10102 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010103 },
10104 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010105 })
10106
10107 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010108 ret = append(ret, perMessageTest{
10109 messageType: typeHelloVerifyRequest,
10110 test: testCase{
10111 protocol: protocol,
10112 name: "HelloVerifyRequest" + suffix,
10113 config: Config{
10114 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010115 },
10116 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010117 })
10118 }
10119
David Benjamincd2c8062016-09-09 11:28:16 -040010120 ret = append(ret, perMessageTest{
10121 messageType: typeServerHello,
10122 test: testCase{
10123 protocol: protocol,
10124 name: "ServerHello" + suffix,
10125 config: Config{
10126 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010127 },
10128 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010129 })
10130
David Benjamincd2c8062016-09-09 11:28:16 -040010131 ret = append(ret, perMessageTest{
10132 messageType: typeCertificate,
10133 test: testCase{
10134 protocol: protocol,
10135 name: "ServerCertificate" + suffix,
10136 config: Config{
10137 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010138 },
10139 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010140 })
10141
David Benjamincd2c8062016-09-09 11:28:16 -040010142 ret = append(ret, perMessageTest{
10143 messageType: typeCertificateStatus,
10144 test: testCase{
10145 protocol: protocol,
10146 name: "CertificateStatus" + suffix,
10147 config: Config{
10148 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010149 },
David Benjamincd2c8062016-09-09 11:28:16 -040010150 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010151 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010152 })
10153
David Benjamincd2c8062016-09-09 11:28:16 -040010154 ret = append(ret, perMessageTest{
10155 messageType: typeServerKeyExchange,
10156 test: testCase{
10157 protocol: protocol,
10158 name: "ServerKeyExchange" + suffix,
10159 config: Config{
10160 MaxVersion: VersionTLS12,
10161 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010162 },
10163 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010164 })
10165
David Benjamincd2c8062016-09-09 11:28:16 -040010166 ret = append(ret, perMessageTest{
10167 messageType: typeCertificateRequest,
10168 test: testCase{
10169 protocol: protocol,
10170 name: "CertificateRequest" + suffix,
10171 config: Config{
10172 MaxVersion: VersionTLS12,
10173 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010174 },
10175 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010176 })
10177
David Benjamincd2c8062016-09-09 11:28:16 -040010178 ret = append(ret, perMessageTest{
10179 messageType: typeServerHelloDone,
10180 test: testCase{
10181 protocol: protocol,
10182 name: "ServerHelloDone" + suffix,
10183 config: Config{
10184 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010185 },
10186 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010187 })
10188
David Benjamincd2c8062016-09-09 11:28:16 -040010189 ret = append(ret, perMessageTest{
10190 messageType: typeCertificate,
10191 test: testCase{
10192 testType: serverTest,
10193 protocol: protocol,
10194 name: "ClientCertificate" + suffix,
10195 config: Config{
10196 Certificates: []Certificate{rsaCertificate},
10197 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010198 },
David Benjamincd2c8062016-09-09 11:28:16 -040010199 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010200 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010201 })
10202
David Benjamincd2c8062016-09-09 11:28:16 -040010203 ret = append(ret, perMessageTest{
10204 messageType: typeCertificateVerify,
10205 test: testCase{
10206 testType: serverTest,
10207 protocol: protocol,
10208 name: "CertificateVerify" + suffix,
10209 config: Config{
10210 Certificates: []Certificate{rsaCertificate},
10211 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010212 },
David Benjamincd2c8062016-09-09 11:28:16 -040010213 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010214 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010215 })
10216
David Benjamincd2c8062016-09-09 11:28:16 -040010217 ret = append(ret, perMessageTest{
10218 messageType: typeClientKeyExchange,
10219 test: testCase{
10220 testType: serverTest,
10221 protocol: protocol,
10222 name: "ClientKeyExchange" + suffix,
10223 config: Config{
10224 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010225 },
10226 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010227 })
10228
10229 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010230 ret = append(ret, perMessageTest{
10231 messageType: typeNextProtocol,
10232 test: testCase{
10233 testType: serverTest,
10234 protocol: protocol,
10235 name: "NextProtocol" + suffix,
10236 config: Config{
10237 MaxVersion: VersionTLS12,
10238 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010239 },
David Benjamincd2c8062016-09-09 11:28:16 -040010240 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010241 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010242 })
10243
David Benjamincd2c8062016-09-09 11:28:16 -040010244 ret = append(ret, perMessageTest{
10245 messageType: typeChannelID,
10246 test: testCase{
10247 testType: serverTest,
10248 protocol: protocol,
10249 name: "ChannelID" + suffix,
10250 config: Config{
10251 MaxVersion: VersionTLS12,
10252 ChannelID: channelIDKey,
10253 },
10254 flags: []string{
10255 "-expect-channel-id",
10256 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010257 },
10258 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010259 })
10260 }
10261
David Benjamincd2c8062016-09-09 11:28:16 -040010262 ret = append(ret, perMessageTest{
10263 messageType: typeFinished,
10264 test: testCase{
10265 testType: serverTest,
10266 protocol: protocol,
10267 name: "ClientFinished" + suffix,
10268 config: Config{
10269 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010270 },
10271 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010272 })
10273
David Benjamincd2c8062016-09-09 11:28:16 -040010274 ret = append(ret, perMessageTest{
10275 messageType: typeNewSessionTicket,
10276 test: testCase{
10277 protocol: protocol,
10278 name: "NewSessionTicket" + suffix,
10279 config: Config{
10280 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010281 },
10282 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010283 })
10284
David Benjamincd2c8062016-09-09 11:28:16 -040010285 ret = append(ret, perMessageTest{
10286 messageType: typeFinished,
10287 test: testCase{
10288 protocol: protocol,
10289 name: "ServerFinished" + suffix,
10290 config: Config{
10291 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010292 },
10293 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010294 })
10295
10296 }
David Benjamincd2c8062016-09-09 11:28:16 -040010297
10298 ret = append(ret, perMessageTest{
10299 messageType: typeClientHello,
10300 test: testCase{
10301 testType: serverTest,
10302 name: "TLS13-ClientHello",
10303 config: Config{
10304 MaxVersion: VersionTLS13,
10305 },
10306 },
10307 })
10308
10309 ret = append(ret, perMessageTest{
10310 messageType: typeServerHello,
10311 test: testCase{
10312 name: "TLS13-ServerHello",
10313 config: Config{
10314 MaxVersion: VersionTLS13,
10315 },
10316 },
10317 })
10318
10319 ret = append(ret, perMessageTest{
10320 messageType: typeEncryptedExtensions,
10321 test: testCase{
10322 name: "TLS13-EncryptedExtensions",
10323 config: Config{
10324 MaxVersion: VersionTLS13,
10325 },
10326 },
10327 })
10328
10329 ret = append(ret, perMessageTest{
10330 messageType: typeCertificateRequest,
10331 test: testCase{
10332 name: "TLS13-CertificateRequest",
10333 config: Config{
10334 MaxVersion: VersionTLS13,
10335 ClientAuth: RequireAnyClientCert,
10336 },
10337 },
10338 })
10339
10340 ret = append(ret, perMessageTest{
10341 messageType: typeCertificate,
10342 test: testCase{
10343 name: "TLS13-ServerCertificate",
10344 config: Config{
10345 MaxVersion: VersionTLS13,
10346 },
10347 },
10348 })
10349
10350 ret = append(ret, perMessageTest{
10351 messageType: typeCertificateVerify,
10352 test: testCase{
10353 name: "TLS13-ServerCertificateVerify",
10354 config: Config{
10355 MaxVersion: VersionTLS13,
10356 },
10357 },
10358 })
10359
10360 ret = append(ret, perMessageTest{
10361 messageType: typeFinished,
10362 test: testCase{
10363 name: "TLS13-ServerFinished",
10364 config: Config{
10365 MaxVersion: VersionTLS13,
10366 },
10367 },
10368 })
10369
10370 ret = append(ret, perMessageTest{
10371 messageType: typeCertificate,
10372 test: testCase{
10373 testType: serverTest,
10374 name: "TLS13-ClientCertificate",
10375 config: Config{
10376 Certificates: []Certificate{rsaCertificate},
10377 MaxVersion: VersionTLS13,
10378 },
10379 flags: []string{"-require-any-client-certificate"},
10380 },
10381 })
10382
10383 ret = append(ret, perMessageTest{
10384 messageType: typeCertificateVerify,
10385 test: testCase{
10386 testType: serverTest,
10387 name: "TLS13-ClientCertificateVerify",
10388 config: Config{
10389 Certificates: []Certificate{rsaCertificate},
10390 MaxVersion: VersionTLS13,
10391 },
10392 flags: []string{"-require-any-client-certificate"},
10393 },
10394 })
10395
10396 ret = append(ret, perMessageTest{
10397 messageType: typeFinished,
10398 test: testCase{
10399 testType: serverTest,
10400 name: "TLS13-ClientFinished",
10401 config: Config{
10402 MaxVersion: VersionTLS13,
10403 },
10404 },
10405 })
10406
10407 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010408}
10409
David Benjamincd2c8062016-09-09 11:28:16 -040010410func addWrongMessageTypeTests() {
10411 for _, t := range makePerMessageTests() {
10412 t.test.name = "WrongMessageType-" + t.test.name
10413 t.test.config.Bugs.SendWrongMessageType = t.messageType
10414 t.test.shouldFail = true
10415 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10416 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010417
David Benjamincd2c8062016-09-09 11:28:16 -040010418 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10419 // In TLS 1.3, a bad ServerHello means the client sends
10420 // an unencrypted alert while the server expects
10421 // encryption, so the alert is not readable by runner.
10422 t.test.expectedLocalError = "local error: bad record MAC"
10423 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010424
David Benjamincd2c8062016-09-09 11:28:16 -040010425 testCases = append(testCases, t.test)
10426 }
David Benjaminebacdee2017-04-08 11:00:45 -040010427
10428 // The processing order for TLS 1.3 version negotiation is such that one
10429 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10430 // TLS 1.2. Test that we do not do this.
10431 testCases = append(testCases, testCase{
10432 name: "SendServerHelloAsHelloRetryRequest",
10433 config: Config{
10434 MaxVersion: VersionTLS12,
10435 Bugs: ProtocolBugs{
10436 SendServerHelloAsHelloRetryRequest: true,
10437 },
10438 },
10439 shouldFail: true,
10440 expectedError: ":UNEXPECTED_MESSAGE:",
10441 expectedLocalError: "remote error: unexpected message",
10442 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010443}
10444
David Benjamin639846e2016-09-09 11:41:18 -040010445func addTrailingMessageDataTests() {
10446 for _, t := range makePerMessageTests() {
10447 t.test.name = "TrailingMessageData-" + t.test.name
10448 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10449 t.test.shouldFail = true
10450 t.test.expectedError = ":DECODE_ERROR:"
10451 t.test.expectedLocalError = "remote error: error decoding message"
10452
10453 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10454 // In TLS 1.3, a bad ServerHello means the client sends
10455 // an unencrypted alert while the server expects
10456 // encryption, so the alert is not readable by runner.
10457 t.test.expectedLocalError = "local error: bad record MAC"
10458 }
10459
10460 if t.messageType == typeFinished {
10461 // Bad Finished messages read as the verify data having
10462 // the wrong length.
10463 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10464 t.test.expectedLocalError = "remote error: error decrypting message"
10465 }
10466
10467 testCases = append(testCases, t.test)
10468 }
10469}
10470
Steven Valdez143e8b32016-07-11 13:19:03 -040010471func addTLS13HandshakeTests() {
10472 testCases = append(testCases, testCase{
10473 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010474 name: "NegotiatePSKResumption-TLS13",
10475 config: Config{
10476 MaxVersion: VersionTLS13,
10477 Bugs: ProtocolBugs{
10478 NegotiatePSKResumption: true,
10479 },
10480 },
10481 resumeSession: true,
10482 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010483 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010484 })
10485
10486 testCases = append(testCases, testCase{
10487 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010488 name: "MissingKeyShare-Client",
10489 config: Config{
10490 MaxVersion: VersionTLS13,
10491 Bugs: ProtocolBugs{
10492 MissingKeyShare: true,
10493 },
10494 },
10495 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010496 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010497 })
10498
10499 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010500 testType: serverTest,
10501 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010502 config: Config{
10503 MaxVersion: VersionTLS13,
10504 Bugs: ProtocolBugs{
10505 MissingKeyShare: true,
10506 },
10507 },
10508 shouldFail: true,
10509 expectedError: ":MISSING_KEY_SHARE:",
10510 })
10511
10512 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010513 testType: serverTest,
10514 name: "DuplicateKeyShares",
10515 config: Config{
10516 MaxVersion: VersionTLS13,
10517 Bugs: ProtocolBugs{
10518 DuplicateKeyShares: true,
10519 },
10520 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010521 shouldFail: true,
10522 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010523 })
10524
10525 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010526 testType: serverTest,
10527 name: "SkipEarlyData",
10528 config: Config{
10529 MaxVersion: VersionTLS13,
10530 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010531 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010532 },
10533 },
10534 })
10535
10536 testCases = append(testCases, testCase{
10537 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010538 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010539 config: Config{
10540 MaxVersion: VersionTLS13,
10541 TLS13Variant: TLS13Experiment,
10542 Bugs: ProtocolBugs{
10543 SendFakeEarlyDataLength: 4,
10544 },
10545 },
10546 flags: []string{"-tls13-variant", "1"},
10547 })
10548
10549 testCases = append(testCases, testCase{
10550 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010551 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10552 config: Config{
10553 MaxVersion: VersionTLS13,
10554 TLS13Variant: TLS13RecordTypeExperiment,
10555 Bugs: ProtocolBugs{
10556 SendFakeEarlyDataLength: 4,
10557 },
10558 },
10559 flags: []string{"-tls13-variant", "2"},
10560 })
10561
10562 testCases = append(testCases, testCase{
10563 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010564 name: "SkipEarlyData-OmitEarlyDataExtension",
10565 config: Config{
10566 MaxVersion: VersionTLS13,
10567 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010568 SendFakeEarlyDataLength: 4,
10569 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010570 },
10571 },
10572 shouldFail: true,
10573 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10574 })
10575
10576 testCases = append(testCases, testCase{
10577 testType: serverTest,
10578 name: "SkipEarlyData-TooMuchData",
10579 config: Config{
10580 MaxVersion: VersionTLS13,
10581 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010582 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010583 },
10584 },
10585 shouldFail: true,
10586 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10587 })
10588
10589 testCases = append(testCases, testCase{
10590 testType: serverTest,
10591 name: "SkipEarlyData-Interleaved",
10592 config: Config{
10593 MaxVersion: VersionTLS13,
10594 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010595 SendFakeEarlyDataLength: 4,
10596 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010597 },
10598 },
10599 shouldFail: true,
10600 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10601 })
10602
10603 testCases = append(testCases, testCase{
10604 testType: serverTest,
10605 name: "SkipEarlyData-EarlyDataInTLS12",
10606 config: Config{
10607 MaxVersion: VersionTLS13,
10608 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010609 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010610 },
10611 },
10612 shouldFail: true,
10613 expectedError: ":UNEXPECTED_RECORD:",
10614 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10615 })
10616
10617 testCases = append(testCases, testCase{
10618 testType: serverTest,
10619 name: "SkipEarlyData-HRR",
10620 config: Config{
10621 MaxVersion: VersionTLS13,
10622 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010623 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010624 },
10625 DefaultCurves: []CurveID{},
10626 },
10627 })
10628
10629 testCases = append(testCases, testCase{
10630 testType: serverTest,
10631 name: "SkipEarlyData-HRR-Interleaved",
10632 config: Config{
10633 MaxVersion: VersionTLS13,
10634 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010635 SendFakeEarlyDataLength: 4,
10636 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010637 },
10638 DefaultCurves: []CurveID{},
10639 },
10640 shouldFail: true,
10641 expectedError: ":UNEXPECTED_RECORD:",
10642 })
10643
10644 testCases = append(testCases, testCase{
10645 testType: serverTest,
10646 name: "SkipEarlyData-HRR-TooMuchData",
10647 config: Config{
10648 MaxVersion: VersionTLS13,
10649 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010650 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010651 },
10652 DefaultCurves: []CurveID{},
10653 },
10654 shouldFail: true,
10655 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10656 })
10657
10658 // Test that skipping early data looking for cleartext correctly
10659 // processes an alert record.
10660 testCases = append(testCases, testCase{
10661 testType: serverTest,
10662 name: "SkipEarlyData-HRR-FatalAlert",
10663 config: Config{
10664 MaxVersion: VersionTLS13,
10665 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010666 SendEarlyAlert: true,
10667 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010668 },
10669 DefaultCurves: []CurveID{},
10670 },
10671 shouldFail: true,
10672 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10673 })
10674
10675 testCases = append(testCases, testCase{
10676 testType: serverTest,
10677 name: "SkipEarlyData-SecondClientHelloEarlyData",
10678 config: Config{
10679 MaxVersion: VersionTLS13,
10680 Bugs: ProtocolBugs{
10681 SendEarlyDataOnSecondClientHello: true,
10682 },
10683 DefaultCurves: []CurveID{},
10684 },
10685 shouldFail: true,
10686 expectedLocalError: "remote error: bad record MAC",
10687 })
10688
10689 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010690 testType: clientTest,
10691 name: "EmptyEncryptedExtensions",
10692 config: Config{
10693 MaxVersion: VersionTLS13,
10694 Bugs: ProtocolBugs{
10695 EmptyEncryptedExtensions: true,
10696 },
10697 },
10698 shouldFail: true,
10699 expectedLocalError: "remote error: error decoding message",
10700 })
10701
10702 testCases = append(testCases, testCase{
10703 testType: clientTest,
10704 name: "EncryptedExtensionsWithKeyShare",
10705 config: Config{
10706 MaxVersion: VersionTLS13,
10707 Bugs: ProtocolBugs{
10708 EncryptedExtensionsWithKeyShare: true,
10709 },
10710 },
10711 shouldFail: true,
10712 expectedLocalError: "remote error: unsupported extension",
10713 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010714
10715 testCases = append(testCases, testCase{
10716 testType: serverTest,
10717 name: "SendHelloRetryRequest",
10718 config: Config{
10719 MaxVersion: VersionTLS13,
10720 // Require a HelloRetryRequest for every curve.
10721 DefaultCurves: []CurveID{},
10722 },
10723 expectedCurveID: CurveX25519,
10724 })
10725
10726 testCases = append(testCases, testCase{
10727 testType: serverTest,
10728 name: "SendHelloRetryRequest-2",
10729 config: Config{
10730 MaxVersion: VersionTLS13,
10731 DefaultCurves: []CurveID{CurveP384},
10732 },
10733 // Although the ClientHello did not predict our preferred curve,
10734 // we always select it whether it is predicted or not.
10735 expectedCurveID: CurveX25519,
10736 })
10737
10738 testCases = append(testCases, testCase{
10739 name: "UnknownCurve-HelloRetryRequest",
10740 config: Config{
10741 MaxVersion: VersionTLS13,
10742 // P-384 requires HelloRetryRequest in BoringSSL.
10743 CurvePreferences: []CurveID{CurveP384},
10744 Bugs: ProtocolBugs{
10745 SendHelloRetryRequestCurve: bogusCurve,
10746 },
10747 },
10748 shouldFail: true,
10749 expectedError: ":WRONG_CURVE:",
10750 })
10751
10752 testCases = append(testCases, testCase{
10753 name: "DisabledCurve-HelloRetryRequest",
10754 config: Config{
10755 MaxVersion: VersionTLS13,
10756 CurvePreferences: []CurveID{CurveP256},
10757 Bugs: ProtocolBugs{
10758 IgnorePeerCurvePreferences: true,
10759 },
10760 },
10761 flags: []string{"-p384-only"},
10762 shouldFail: true,
10763 expectedError: ":WRONG_CURVE:",
10764 })
10765
10766 testCases = append(testCases, testCase{
10767 name: "UnnecessaryHelloRetryRequest",
10768 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010769 MaxVersion: VersionTLS13,
10770 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010771 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010772 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010773 },
10774 },
10775 shouldFail: true,
10776 expectedError: ":WRONG_CURVE:",
10777 })
10778
10779 testCases = append(testCases, testCase{
10780 name: "SecondHelloRetryRequest",
10781 config: Config{
10782 MaxVersion: VersionTLS13,
10783 // P-384 requires HelloRetryRequest in BoringSSL.
10784 CurvePreferences: []CurveID{CurveP384},
10785 Bugs: ProtocolBugs{
10786 SecondHelloRetryRequest: true,
10787 },
10788 },
10789 shouldFail: true,
10790 expectedError: ":UNEXPECTED_MESSAGE:",
10791 })
10792
10793 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010794 name: "HelloRetryRequest-Empty",
10795 config: Config{
10796 MaxVersion: VersionTLS13,
10797 Bugs: ProtocolBugs{
10798 AlwaysSendHelloRetryRequest: true,
10799 },
10800 },
10801 shouldFail: true,
10802 expectedError: ":DECODE_ERROR:",
10803 })
10804
10805 testCases = append(testCases, testCase{
10806 name: "HelloRetryRequest-DuplicateCurve",
10807 config: Config{
10808 MaxVersion: VersionTLS13,
10809 // P-384 requires a HelloRetryRequest against BoringSSL's default
10810 // configuration. Assert this ExpectMissingKeyShare.
10811 CurvePreferences: []CurveID{CurveP384},
10812 Bugs: ProtocolBugs{
10813 ExpectMissingKeyShare: true,
10814 DuplicateHelloRetryRequestExtensions: true,
10815 },
10816 },
10817 shouldFail: true,
10818 expectedError: ":DUPLICATE_EXTENSION:",
10819 expectedLocalError: "remote error: illegal parameter",
10820 })
10821
10822 testCases = append(testCases, testCase{
10823 name: "HelloRetryRequest-Cookie",
10824 config: Config{
10825 MaxVersion: VersionTLS13,
10826 Bugs: ProtocolBugs{
10827 SendHelloRetryRequestCookie: []byte("cookie"),
10828 },
10829 },
10830 })
10831
10832 testCases = append(testCases, testCase{
10833 name: "HelloRetryRequest-DuplicateCookie",
10834 config: Config{
10835 MaxVersion: VersionTLS13,
10836 Bugs: ProtocolBugs{
10837 SendHelloRetryRequestCookie: []byte("cookie"),
10838 DuplicateHelloRetryRequestExtensions: true,
10839 },
10840 },
10841 shouldFail: true,
10842 expectedError: ":DUPLICATE_EXTENSION:",
10843 expectedLocalError: "remote error: illegal parameter",
10844 })
10845
10846 testCases = append(testCases, testCase{
10847 name: "HelloRetryRequest-EmptyCookie",
10848 config: Config{
10849 MaxVersion: VersionTLS13,
10850 Bugs: ProtocolBugs{
10851 SendHelloRetryRequestCookie: []byte{},
10852 },
10853 },
10854 shouldFail: true,
10855 expectedError: ":DECODE_ERROR:",
10856 })
10857
10858 testCases = append(testCases, testCase{
10859 name: "HelloRetryRequest-Cookie-Curve",
10860 config: Config{
10861 MaxVersion: VersionTLS13,
10862 // P-384 requires HelloRetryRequest in BoringSSL.
10863 CurvePreferences: []CurveID{CurveP384},
10864 Bugs: ProtocolBugs{
10865 SendHelloRetryRequestCookie: []byte("cookie"),
10866 ExpectMissingKeyShare: true,
10867 },
10868 },
10869 })
10870
10871 testCases = append(testCases, testCase{
10872 name: "HelloRetryRequest-Unknown",
10873 config: Config{
10874 MaxVersion: VersionTLS13,
10875 Bugs: ProtocolBugs{
10876 CustomHelloRetryRequestExtension: "extension",
10877 },
10878 },
10879 shouldFail: true,
10880 expectedError: ":UNEXPECTED_EXTENSION:",
10881 expectedLocalError: "remote error: unsupported extension",
10882 })
10883
10884 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010885 testType: serverTest,
10886 name: "SecondClientHelloMissingKeyShare",
10887 config: Config{
10888 MaxVersion: VersionTLS13,
10889 DefaultCurves: []CurveID{},
10890 Bugs: ProtocolBugs{
10891 SecondClientHelloMissingKeyShare: true,
10892 },
10893 },
10894 shouldFail: true,
10895 expectedError: ":MISSING_KEY_SHARE:",
10896 })
10897
10898 testCases = append(testCases, testCase{
10899 testType: serverTest,
10900 name: "SecondClientHelloWrongCurve",
10901 config: Config{
10902 MaxVersion: VersionTLS13,
10903 DefaultCurves: []CurveID{},
10904 Bugs: ProtocolBugs{
10905 MisinterpretHelloRetryRequestCurve: CurveP521,
10906 },
10907 },
10908 shouldFail: true,
10909 expectedError: ":WRONG_CURVE:",
10910 })
10911
10912 testCases = append(testCases, testCase{
10913 name: "HelloRetryRequestVersionMismatch",
10914 config: Config{
10915 MaxVersion: VersionTLS13,
10916 // P-384 requires HelloRetryRequest in BoringSSL.
10917 CurvePreferences: []CurveID{CurveP384},
10918 Bugs: ProtocolBugs{
10919 SendServerHelloVersion: 0x0305,
10920 },
10921 },
10922 shouldFail: true,
10923 expectedError: ":WRONG_VERSION_NUMBER:",
10924 })
10925
10926 testCases = append(testCases, testCase{
10927 name: "HelloRetryRequestCurveMismatch",
10928 config: Config{
10929 MaxVersion: VersionTLS13,
10930 // P-384 requires HelloRetryRequest in BoringSSL.
10931 CurvePreferences: []CurveID{CurveP384},
10932 Bugs: ProtocolBugs{
10933 // Send P-384 (correct) in the HelloRetryRequest.
10934 SendHelloRetryRequestCurve: CurveP384,
10935 // But send P-256 in the ServerHello.
10936 SendCurve: CurveP256,
10937 },
10938 },
10939 shouldFail: true,
10940 expectedError: ":WRONG_CURVE:",
10941 })
10942
10943 // Test the server selecting a curve that requires a HelloRetryRequest
10944 // without sending it.
10945 testCases = append(testCases, testCase{
10946 name: "SkipHelloRetryRequest",
10947 config: Config{
10948 MaxVersion: VersionTLS13,
10949 // P-384 requires HelloRetryRequest in BoringSSL.
10950 CurvePreferences: []CurveID{CurveP384},
10951 Bugs: ProtocolBugs{
10952 SkipHelloRetryRequest: true,
10953 },
10954 },
10955 shouldFail: true,
10956 expectedError: ":WRONG_CURVE:",
10957 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010958
10959 testCases = append(testCases, testCase{
10960 name: "TLS13-RequestContextInHandshake",
10961 config: Config{
10962 MaxVersion: VersionTLS13,
10963 MinVersion: VersionTLS13,
10964 ClientAuth: RequireAnyClientCert,
10965 Bugs: ProtocolBugs{
10966 SendRequestContext: []byte("request context"),
10967 },
10968 },
10969 flags: []string{
10970 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10971 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10972 },
10973 shouldFail: true,
10974 expectedError: ":DECODE_ERROR:",
10975 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010976
10977 testCases = append(testCases, testCase{
10978 testType: serverTest,
10979 name: "TLS13-TrailingKeyShareData",
10980 config: Config{
10981 MaxVersion: VersionTLS13,
10982 Bugs: ProtocolBugs{
10983 TrailingKeyShareData: true,
10984 },
10985 },
10986 shouldFail: true,
10987 expectedError: ":DECODE_ERROR:",
10988 })
David Benjamin7f78df42016-10-05 22:33:19 -040010989
10990 testCases = append(testCases, testCase{
10991 name: "TLS13-AlwaysSelectPSKIdentity",
10992 config: Config{
10993 MaxVersion: VersionTLS13,
10994 Bugs: ProtocolBugs{
10995 AlwaysSelectPSKIdentity: true,
10996 },
10997 },
10998 shouldFail: true,
10999 expectedError: ":UNEXPECTED_EXTENSION:",
11000 })
11001
11002 testCases = append(testCases, testCase{
11003 name: "TLS13-InvalidPSKIdentity",
11004 config: Config{
11005 MaxVersion: VersionTLS13,
11006 Bugs: ProtocolBugs{
11007 SelectPSKIdentityOnResume: 1,
11008 },
11009 },
11010 resumeSession: true,
11011 shouldFail: true,
11012 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11013 })
David Benjamin1286bee2016-10-07 15:25:06 -040011014
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011015 testCases = append(testCases, testCase{
11016 testType: serverTest,
11017 name: "TLS13-ExtraPSKIdentity",
11018 config: Config{
11019 MaxVersion: VersionTLS13,
11020 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011021 ExtraPSKIdentity: true,
11022 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011023 },
11024 },
11025 resumeSession: true,
11026 })
11027
David Benjamin1286bee2016-10-07 15:25:06 -040011028 // Test that unknown NewSessionTicket extensions are tolerated.
11029 testCases = append(testCases, testCase{
11030 name: "TLS13-CustomTicketExtension",
11031 config: Config{
11032 MaxVersion: VersionTLS13,
11033 Bugs: ProtocolBugs{
11034 CustomTicketExtension: "1234",
11035 },
11036 },
11037 })
Steven Valdez2d850622017-01-11 11:34:52 -050011038
Steven Valdez2d850622017-01-11 11:34:52 -050011039 testCases = append(testCases, testCase{
11040 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011041 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011042 config: Config{
11043 MaxVersion: VersionTLS13,
11044 MaxEarlyDataSize: 16384,
11045 },
11046 resumeConfig: &Config{
11047 MaxVersion: VersionTLS13,
11048 MaxEarlyDataSize: 16384,
11049 Bugs: ProtocolBugs{
11050 AlwaysRejectEarlyData: true,
11051 },
11052 },
11053 resumeSession: true,
11054 flags: []string{
11055 "-enable-early-data",
11056 "-expect-early-data-info",
11057 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011058 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011059 },
11060 })
11061
11062 testCases = append(testCases, testCase{
11063 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011064 name: "TLS13Experiment-EarlyData-Reject-Client",
11065 config: Config{
11066 MaxVersion: VersionTLS13,
11067 MaxEarlyDataSize: 16384,
11068 TLS13Variant: TLS13Experiment,
11069 },
11070 resumeConfig: &Config{
11071 MaxVersion: VersionTLS13,
11072 TLS13Variant: TLS13Experiment,
11073 MaxEarlyDataSize: 16384,
11074 Bugs: ProtocolBugs{
11075 AlwaysRejectEarlyData: true,
11076 },
11077 },
11078 resumeSession: true,
11079 flags: []string{
11080 "-enable-early-data",
11081 "-expect-early-data-info",
11082 "-expect-reject-early-data",
11083 "-on-resume-shim-writes-first",
11084 "-tls13-variant", "1",
11085 },
11086 })
11087
11088 testCases = append(testCases, testCase{
11089 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011090 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11091 config: Config{
11092 MaxVersion: VersionTLS13,
11093 MaxEarlyDataSize: 16384,
11094 TLS13Variant: TLS13RecordTypeExperiment,
11095 },
11096 resumeConfig: &Config{
11097 MaxVersion: VersionTLS13,
11098 TLS13Variant: TLS13RecordTypeExperiment,
11099 MaxEarlyDataSize: 16384,
11100 Bugs: ProtocolBugs{
11101 AlwaysRejectEarlyData: true,
11102 },
11103 },
11104 resumeSession: true,
11105 flags: []string{
11106 "-enable-early-data",
11107 "-expect-early-data-info",
11108 "-expect-reject-early-data",
11109 "-on-resume-shim-writes-first",
11110 "-tls13-variant", "2",
11111 },
11112 })
11113
11114 testCases = append(testCases, testCase{
11115 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011116 name: "TLS13-EarlyData-RejectTicket-Client",
11117 config: Config{
11118 MaxVersion: VersionTLS13,
11119 MaxEarlyDataSize: 16384,
11120 Certificates: []Certificate{rsaCertificate},
11121 },
11122 resumeConfig: &Config{
11123 MaxVersion: VersionTLS13,
11124 MaxEarlyDataSize: 16384,
11125 Certificates: []Certificate{ecdsaP256Certificate},
11126 SessionTicketsDisabled: true,
11127 },
11128 resumeSession: true,
11129 expectResumeRejected: true,
11130 flags: []string{
11131 "-enable-early-data",
11132 "-expect-early-data-info",
11133 "-expect-reject-early-data",
11134 "-on-resume-shim-writes-first",
11135 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11136 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11137 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11138 // Session tickets are disabled, so the runner will not send a ticket.
11139 "-on-retry-expect-no-session",
11140 },
11141 })
11142
11143 testCases = append(testCases, testCase{
11144 testType: clientTest,
11145 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011146 config: Config{
11147 MaxVersion: VersionTLS13,
11148 MaxEarlyDataSize: 16384,
11149 },
11150 resumeConfig: &Config{
11151 MaxVersion: VersionTLS13,
11152 MaxEarlyDataSize: 16384,
11153 Bugs: ProtocolBugs{
11154 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11155 },
11156 },
11157 resumeSession: true,
11158 flags: []string{
11159 "-enable-early-data",
11160 "-expect-early-data-info",
11161 "-expect-reject-early-data",
11162 },
11163 })
11164
11165 // The client must check the server does not send the early_data
11166 // extension while rejecting the session.
11167 testCases = append(testCases, testCase{
11168 testType: clientTest,
11169 name: "TLS13-EarlyDataWithoutResume-Client",
11170 config: Config{
11171 MaxVersion: VersionTLS13,
11172 MaxEarlyDataSize: 16384,
11173 },
11174 resumeConfig: &Config{
11175 MaxVersion: VersionTLS13,
11176 SessionTicketsDisabled: true,
11177 Bugs: ProtocolBugs{
11178 SendEarlyDataExtension: true,
11179 },
11180 },
11181 resumeSession: true,
11182 flags: []string{
11183 "-enable-early-data",
11184 "-expect-early-data-info",
11185 },
11186 shouldFail: true,
11187 expectedError: ":UNEXPECTED_EXTENSION:",
11188 })
11189
11190 // The client must fail with a dedicated error code if the server
11191 // responds with TLS 1.2 when offering 0-RTT.
11192 testCases = append(testCases, testCase{
11193 testType: clientTest,
11194 name: "TLS13-EarlyDataVersionDowngrade-Client",
11195 config: Config{
11196 MaxVersion: VersionTLS13,
11197 MaxEarlyDataSize: 16384,
11198 },
11199 resumeConfig: &Config{
11200 MaxVersion: VersionTLS12,
11201 },
11202 resumeSession: true,
11203 flags: []string{
11204 "-enable-early-data",
11205 "-expect-early-data-info",
11206 },
11207 shouldFail: true,
11208 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11209 })
11210
11211 // Test that the client rejects an (unsolicited) early_data extension if
11212 // the server sent an HRR.
11213 testCases = append(testCases, testCase{
11214 testType: clientTest,
11215 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11216 config: Config{
11217 MaxVersion: VersionTLS13,
11218 MaxEarlyDataSize: 16384,
11219 },
11220 resumeConfig: &Config{
11221 MaxVersion: VersionTLS13,
11222 MaxEarlyDataSize: 16384,
11223 Bugs: ProtocolBugs{
11224 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11225 SendEarlyDataExtension: true,
11226 },
11227 },
11228 resumeSession: true,
11229 flags: []string{
11230 "-enable-early-data",
11231 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011232 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011233 },
11234 shouldFail: true,
11235 expectedError: ":UNEXPECTED_EXTENSION:",
11236 })
11237
11238 fooString := "foo"
11239 barString := "bar"
11240
11241 // Test that the client reports the correct ALPN after a 0-RTT reject
11242 // that changed it.
11243 testCases = append(testCases, testCase{
11244 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011245 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011246 config: Config{
11247 MaxVersion: VersionTLS13,
11248 MaxEarlyDataSize: 16384,
11249 Bugs: ProtocolBugs{
11250 ALPNProtocol: &fooString,
11251 },
11252 },
11253 resumeConfig: &Config{
11254 MaxVersion: VersionTLS13,
11255 MaxEarlyDataSize: 16384,
11256 Bugs: ProtocolBugs{
11257 ALPNProtocol: &barString,
11258 },
11259 },
11260 resumeSession: true,
11261 flags: []string{
11262 "-advertise-alpn", "\x03foo\x03bar",
11263 "-enable-early-data",
11264 "-expect-early-data-info",
11265 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011266 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011267 "-on-resume-expect-alpn", "foo",
11268 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011269 },
11270 })
11271
11272 // Test that the client reports the correct ALPN after a 0-RTT reject if
11273 // ALPN was omitted from the first connection.
11274 testCases = append(testCases, testCase{
11275 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011276 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011277 config: Config{
11278 MaxVersion: VersionTLS13,
11279 MaxEarlyDataSize: 16384,
11280 },
11281 resumeConfig: &Config{
11282 MaxVersion: VersionTLS13,
11283 MaxEarlyDataSize: 16384,
11284 NextProtos: []string{"foo"},
11285 },
11286 resumeSession: true,
11287 flags: []string{
11288 "-advertise-alpn", "\x03foo\x03bar",
11289 "-enable-early-data",
11290 "-expect-early-data-info",
11291 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011292 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011293 "-on-resume-expect-alpn", "",
11294 "-on-retry-expect-alpn", "foo",
11295 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011296 },
11297 })
11298
11299 // Test that the client reports the correct ALPN after a 0-RTT reject if
11300 // ALPN was omitted from the second connection.
11301 testCases = append(testCases, testCase{
11302 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011303 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011304 config: Config{
11305 MaxVersion: VersionTLS13,
11306 MaxEarlyDataSize: 16384,
11307 NextProtos: []string{"foo"},
11308 },
11309 resumeConfig: &Config{
11310 MaxVersion: VersionTLS13,
11311 MaxEarlyDataSize: 16384,
11312 },
11313 resumeSession: true,
11314 flags: []string{
11315 "-advertise-alpn", "\x03foo\x03bar",
11316 "-enable-early-data",
11317 "-expect-early-data-info",
11318 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011319 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011320 "-on-resume-expect-alpn", "foo",
11321 "-on-retry-expect-alpn", "",
11322 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011323 },
11324 })
11325
11326 // Test that the client enforces ALPN match on 0-RTT accept.
11327 testCases = append(testCases, testCase{
11328 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011329 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011330 config: Config{
11331 MaxVersion: VersionTLS13,
11332 MaxEarlyDataSize: 16384,
11333 Bugs: ProtocolBugs{
11334 ALPNProtocol: &fooString,
11335 },
11336 },
11337 resumeConfig: &Config{
11338 MaxVersion: VersionTLS13,
11339 MaxEarlyDataSize: 16384,
11340 Bugs: ProtocolBugs{
11341 AlwaysAcceptEarlyData: true,
11342 ALPNProtocol: &barString,
11343 },
11344 },
11345 resumeSession: true,
11346 flags: []string{
11347 "-advertise-alpn", "\x03foo\x03bar",
11348 "-enable-early-data",
11349 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011350 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011351 "-on-resume-expect-alpn", "foo",
11352 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011353 },
11354 shouldFail: true,
11355 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11356 })
11357
11358 // Test that the server correctly rejects 0-RTT when the previous
11359 // session did not allow early data on resumption.
11360 testCases = append(testCases, testCase{
11361 testType: serverTest,
11362 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11363 config: Config{
11364 MaxVersion: VersionTLS13,
11365 },
11366 resumeConfig: &Config{
11367 MaxVersion: VersionTLS13,
11368 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011369 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011370 ExpectEarlyDataAccepted: false,
11371 },
11372 },
11373 resumeSession: true,
11374 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011375 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011376 "-expect-reject-early-data",
11377 },
11378 })
11379
11380 // Test that we reject early data where ALPN is omitted from the first
11381 // connection.
11382 testCases = append(testCases, testCase{
11383 testType: serverTest,
11384 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11385 config: Config{
11386 MaxVersion: VersionTLS13,
11387 NextProtos: []string{},
11388 },
11389 resumeConfig: &Config{
11390 MaxVersion: VersionTLS13,
11391 NextProtos: []string{"foo"},
11392 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011393 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011394 ExpectEarlyDataAccepted: false,
11395 },
11396 },
11397 resumeSession: true,
11398 flags: []string{
11399 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011400 "-on-initial-select-alpn", "",
11401 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011402 },
11403 })
11404
11405 // Test that we reject early data where ALPN is omitted from the second
11406 // connection.
11407 testCases = append(testCases, testCase{
11408 testType: serverTest,
11409 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11410 config: Config{
11411 MaxVersion: VersionTLS13,
11412 NextProtos: []string{"foo"},
11413 },
11414 resumeConfig: &Config{
11415 MaxVersion: VersionTLS13,
11416 NextProtos: []string{},
11417 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011418 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011419 ExpectEarlyDataAccepted: false,
11420 },
11421 },
11422 resumeSession: true,
11423 flags: []string{
11424 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011425 "-on-initial-select-alpn", "foo",
11426 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011427 },
11428 })
11429
11430 // Test that we reject early data with mismatched ALPN.
11431 testCases = append(testCases, testCase{
11432 testType: serverTest,
11433 name: "TLS13-EarlyData-ALPNMismatch-Server",
11434 config: Config{
11435 MaxVersion: VersionTLS13,
11436 NextProtos: []string{"foo"},
11437 },
11438 resumeConfig: &Config{
11439 MaxVersion: VersionTLS13,
11440 NextProtos: []string{"bar"},
11441 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011442 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011443 ExpectEarlyDataAccepted: false,
11444 },
11445 },
11446 resumeSession: true,
11447 flags: []string{
11448 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011449 "-on-initial-select-alpn", "foo",
11450 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011451 },
11452 })
11453
David Benjamin6bb507b2017-03-29 16:35:57 -050011454 // Test that the client offering 0-RTT and Channel ID forbids the server
11455 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011456 testCases = append(testCases, testCase{
11457 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011458 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011459 config: Config{
11460 MaxVersion: VersionTLS13,
11461 MaxEarlyDataSize: 16384,
11462 RequestChannelID: true,
11463 },
11464 resumeSession: true,
11465 expectChannelID: true,
11466 shouldFail: true,
11467 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11468 flags: []string{
11469 "-enable-early-data",
11470 "-expect-early-data-info",
11471 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11472 },
11473 })
11474
David Benjamin6bb507b2017-03-29 16:35:57 -050011475 // Test that the client offering Channel ID and 0-RTT allows the server
11476 // to decline 0-RTT.
11477 testCases = append(testCases, testCase{
11478 testType: clientTest,
11479 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11480 config: Config{
11481 MaxVersion: VersionTLS13,
11482 MaxEarlyDataSize: 16384,
11483 RequestChannelID: true,
11484 Bugs: ProtocolBugs{
11485 AlwaysRejectEarlyData: true,
11486 },
11487 },
11488 resumeSession: true,
11489 expectChannelID: true,
11490 flags: []string{
11491 "-enable-early-data",
11492 "-expect-early-data-info",
11493 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11494 "-expect-reject-early-data",
11495 },
11496 })
11497
11498 // Test that the client offering Channel ID and 0-RTT allows the server
11499 // to decline Channel ID.
11500 testCases = append(testCases, testCase{
11501 testType: clientTest,
11502 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11503 config: Config{
11504 MaxVersion: VersionTLS13,
11505 MaxEarlyDataSize: 16384,
11506 },
11507 resumeSession: true,
11508 flags: []string{
11509 "-enable-early-data",
11510 "-expect-early-data-info",
11511 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11512 "-expect-accept-early-data",
11513 },
11514 })
11515
11516 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11517 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011518 testCases = append(testCases, testCase{
11519 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011520 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011521 config: Config{
11522 MaxVersion: VersionTLS13,
11523 ChannelID: channelIDKey,
11524 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011525 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011526 ExpectEarlyDataAccepted: false,
11527 },
11528 },
11529 resumeSession: true,
11530 expectChannelID: true,
11531 flags: []string{
11532 "-enable-early-data",
11533 "-expect-reject-early-data",
11534 "-expect-channel-id",
11535 base64.StdEncoding.EncodeToString(channelIDBytes),
11536 },
11537 })
11538
David Benjamin6bb507b2017-03-29 16:35:57 -050011539 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11540 // if not offered Channel ID.
11541 testCases = append(testCases, testCase{
11542 testType: serverTest,
11543 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11544 config: Config{
11545 MaxVersion: VersionTLS13,
11546 Bugs: ProtocolBugs{
11547 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11548 ExpectEarlyDataAccepted: true,
11549 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11550 },
11551 },
11552 resumeSession: true,
11553 expectChannelID: false,
11554 flags: []string{
11555 "-enable-early-data",
11556 "-expect-accept-early-data",
11557 "-enable-channel-id",
11558 },
11559 })
11560
David Benjamin32c89272017-03-26 13:54:21 -050011561 // Test that the server rejects 0-RTT streams without end_of_early_data.
11562 // The subsequent records should fail to decrypt.
11563 testCases = append(testCases, testCase{
11564 testType: serverTest,
11565 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11566 config: Config{
11567 MaxVersion: VersionTLS13,
11568 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011569 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011570 ExpectEarlyDataAccepted: true,
11571 SkipEndOfEarlyData: true,
11572 },
11573 },
11574 resumeSession: true,
11575 flags: []string{"-enable-early-data"},
11576 shouldFail: true,
11577 expectedLocalError: "remote error: bad record MAC",
11578 expectedError: ":BAD_DECRYPT:",
11579 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011580
11581 testCases = append(testCases, testCase{
11582 testType: serverTest,
11583 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11584 config: Config{
11585 MaxVersion: VersionTLS13,
11586 },
11587 resumeConfig: &Config{
11588 MaxVersion: VersionTLS13,
11589 Bugs: ProtocolBugs{
11590 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11591 SendStrayEarlyHandshake: true,
11592 ExpectEarlyDataAccepted: true},
11593 },
11594 resumeSession: true,
11595 shouldFail: true,
11596 expectedError: ":UNEXPECTED_RECORD:",
11597 expectedLocalError: "remote error: unexpected message",
11598 flags: []string{
11599 "-enable-early-data",
11600 },
11601 })
David Benjamind9cbb532017-07-07 13:17:19 -040011602
11603 // Test that the client reports TLS 1.3 as the version while sending
11604 // early data.
11605 testCases = append(testCases, testCase{
11606 testType: clientTest,
11607 name: "TLS13-EarlyData-Client-VersionAPI",
11608 config: Config{
11609 MaxVersion: VersionTLS13,
11610 MaxEarlyDataSize: 16384,
11611 },
11612 resumeSession: true,
11613 flags: []string{
11614 "-enable-early-data",
11615 "-expect-early-data-info",
11616 "-expect-accept-early-data",
11617 "-expect-version", strconv.Itoa(VersionTLS13),
11618 },
11619 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011620}
11621
David Benjaminabbbee12016-10-31 19:20:42 -040011622func addTLS13CipherPreferenceTests() {
11623 // Test that client preference is honored if the shim has AES hardware
11624 // and ChaCha20-Poly1305 is preferred otherwise.
11625 testCases = append(testCases, testCase{
11626 testType: serverTest,
11627 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11628 config: Config{
11629 MaxVersion: VersionTLS13,
11630 CipherSuites: []uint16{
11631 TLS_CHACHA20_POLY1305_SHA256,
11632 TLS_AES_128_GCM_SHA256,
11633 },
11634 },
11635 flags: []string{
11636 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11637 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11638 },
11639 })
11640
11641 testCases = append(testCases, testCase{
11642 testType: serverTest,
11643 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11644 config: Config{
11645 MaxVersion: VersionTLS13,
11646 CipherSuites: []uint16{
11647 TLS_AES_128_GCM_SHA256,
11648 TLS_CHACHA20_POLY1305_SHA256,
11649 },
11650 },
11651 flags: []string{
11652 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11653 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11654 },
11655 })
11656
11657 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11658 // whether it has AES hardware.
11659 testCases = append(testCases, testCase{
11660 name: "TLS13-CipherPreference-Client",
11661 config: Config{
11662 MaxVersion: VersionTLS13,
11663 // Use the client cipher order. (This is the default but
11664 // is listed to be explicit.)
11665 PreferServerCipherSuites: false,
11666 },
11667 flags: []string{
11668 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11669 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11670 },
11671 })
11672}
11673
David Benjaminf3fbade2016-09-19 13:08:16 -040011674func addPeekTests() {
11675 // Test SSL_peek works, including on empty records.
11676 testCases = append(testCases, testCase{
11677 name: "Peek-Basic",
11678 sendEmptyRecords: 1,
11679 flags: []string{"-peek-then-read"},
11680 })
11681
11682 // Test SSL_peek can drive the initial handshake.
11683 testCases = append(testCases, testCase{
11684 name: "Peek-ImplicitHandshake",
11685 flags: []string{
11686 "-peek-then-read",
11687 "-implicit-handshake",
11688 },
11689 })
11690
11691 // Test SSL_peek can discover and drive a renegotiation.
11692 testCases = append(testCases, testCase{
11693 name: "Peek-Renegotiate",
11694 config: Config{
11695 MaxVersion: VersionTLS12,
11696 },
11697 renegotiate: 1,
11698 flags: []string{
11699 "-peek-then-read",
11700 "-renegotiate-freely",
11701 "-expect-total-renegotiations", "1",
11702 },
11703 })
11704
11705 // Test SSL_peek can discover a close_notify.
11706 testCases = append(testCases, testCase{
11707 name: "Peek-Shutdown",
11708 config: Config{
11709 Bugs: ProtocolBugs{
11710 ExpectCloseNotify: true,
11711 },
11712 },
11713 flags: []string{
11714 "-peek-then-read",
11715 "-check-close-notify",
11716 },
11717 })
11718
11719 // Test SSL_peek can discover an alert.
11720 testCases = append(testCases, testCase{
11721 name: "Peek-Alert",
11722 config: Config{
11723 Bugs: ProtocolBugs{
11724 SendSpuriousAlert: alertRecordOverflow,
11725 },
11726 },
11727 flags: []string{"-peek-then-read"},
11728 shouldFail: true,
11729 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11730 })
11731
11732 // Test SSL_peek can handle KeyUpdate.
11733 testCases = append(testCases, testCase{
11734 name: "Peek-KeyUpdate",
11735 config: Config{
11736 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011737 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011738 sendKeyUpdates: 1,
11739 keyUpdateRequest: keyUpdateNotRequested,
11740 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011741 })
11742}
11743
David Benjamine6f22212016-11-08 14:28:24 -050011744func addRecordVersionTests() {
11745 for _, ver := range tlsVersions {
11746 // Test that the record version is enforced.
11747 testCases = append(testCases, testCase{
11748 name: "CheckRecordVersion-" + ver.name,
11749 config: Config{
11750 MinVersion: ver.version,
11751 MaxVersion: ver.version,
11752 Bugs: ProtocolBugs{
11753 SendRecordVersion: 0x03ff,
11754 },
11755 },
David Benjamina5022392017-07-10 17:40:39 -040011756 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011757 shouldFail: true,
11758 expectedError: ":WRONG_VERSION_NUMBER:",
11759 })
11760
11761 // Test that the ClientHello may use any record version, for
11762 // compatibility reasons.
11763 testCases = append(testCases, testCase{
11764 testType: serverTest,
11765 name: "LooseInitialRecordVersion-" + ver.name,
11766 config: Config{
11767 MinVersion: ver.version,
11768 MaxVersion: ver.version,
11769 Bugs: ProtocolBugs{
11770 SendInitialRecordVersion: 0x03ff,
11771 },
11772 },
David Benjamina5022392017-07-10 17:40:39 -040011773 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011774 })
11775
11776 // Test that garbage ClientHello record versions are rejected.
11777 testCases = append(testCases, testCase{
11778 testType: serverTest,
11779 name: "GarbageInitialRecordVersion-" + ver.name,
11780 config: Config{
11781 MinVersion: ver.version,
11782 MaxVersion: ver.version,
11783 Bugs: ProtocolBugs{
11784 SendInitialRecordVersion: 0xffff,
11785 },
11786 },
David Benjamina5022392017-07-10 17:40:39 -040011787 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011788 shouldFail: true,
11789 expectedError: ":WRONG_VERSION_NUMBER:",
11790 })
11791 }
11792}
11793
David Benjamin2c516452016-11-15 10:16:54 +090011794func addCertificateTests() {
11795 // Test that a certificate chain with intermediate may be sent and
11796 // received as both client and server.
11797 for _, ver := range tlsVersions {
11798 testCases = append(testCases, testCase{
11799 testType: clientTest,
11800 name: "SendReceiveIntermediate-Client-" + ver.name,
11801 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011802 MinVersion: ver.version,
11803 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011804 Certificates: []Certificate{rsaChainCertificate},
11805 ClientAuth: RequireAnyClientCert,
11806 },
David Benjamina5022392017-07-10 17:40:39 -040011807 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011808 expectPeerCertificate: &rsaChainCertificate,
11809 flags: []string{
11810 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11811 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11812 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11813 },
11814 })
11815
11816 testCases = append(testCases, testCase{
11817 testType: serverTest,
11818 name: "SendReceiveIntermediate-Server-" + ver.name,
11819 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011820 MinVersion: ver.version,
11821 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011822 Certificates: []Certificate{rsaChainCertificate},
11823 },
David Benjamina5022392017-07-10 17:40:39 -040011824 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011825 expectPeerCertificate: &rsaChainCertificate,
11826 flags: []string{
11827 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11828 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11829 "-require-any-client-certificate",
11830 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11831 },
11832 })
11833 }
11834}
11835
David Benjaminbbaf3672016-11-17 10:53:09 +090011836func addRetainOnlySHA256ClientCertTests() {
11837 for _, ver := range tlsVersions {
11838 // Test that enabling
11839 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11840 // actually requesting a client certificate is a no-op.
11841 testCases = append(testCases, testCase{
11842 testType: serverTest,
11843 name: "RetainOnlySHA256-NoCert-" + ver.name,
11844 config: Config{
11845 MinVersion: ver.version,
11846 MaxVersion: ver.version,
11847 },
David Benjamina5022392017-07-10 17:40:39 -040011848 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011849 flags: []string{
11850 "-retain-only-sha256-client-cert-initial",
11851 "-retain-only-sha256-client-cert-resume",
11852 },
11853 resumeSession: true,
11854 })
11855
11856 // Test that when retaining only a SHA-256 certificate is
11857 // enabled, the hash appears as expected.
11858 testCases = append(testCases, testCase{
11859 testType: serverTest,
11860 name: "RetainOnlySHA256-Cert-" + ver.name,
11861 config: Config{
11862 MinVersion: ver.version,
11863 MaxVersion: ver.version,
11864 Certificates: []Certificate{rsaCertificate},
11865 },
David Benjamina5022392017-07-10 17:40:39 -040011866 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011867 flags: []string{
11868 "-verify-peer",
11869 "-retain-only-sha256-client-cert-initial",
11870 "-retain-only-sha256-client-cert-resume",
11871 "-expect-sha256-client-cert-initial",
11872 "-expect-sha256-client-cert-resume",
11873 },
11874 resumeSession: true,
11875 })
11876
11877 // Test that when the config changes from on to off, a
11878 // resumption is rejected because the server now wants the full
11879 // certificate chain.
11880 testCases = append(testCases, testCase{
11881 testType: serverTest,
11882 name: "RetainOnlySHA256-OnOff-" + ver.name,
11883 config: Config{
11884 MinVersion: ver.version,
11885 MaxVersion: ver.version,
11886 Certificates: []Certificate{rsaCertificate},
11887 },
David Benjamina5022392017-07-10 17:40:39 -040011888 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011889 flags: []string{
11890 "-verify-peer",
11891 "-retain-only-sha256-client-cert-initial",
11892 "-expect-sha256-client-cert-initial",
11893 },
11894 resumeSession: true,
11895 expectResumeRejected: true,
11896 })
11897
11898 // Test that when the config changes from off to on, a
11899 // resumption is rejected because the server now wants just the
11900 // hash.
11901 testCases = append(testCases, testCase{
11902 testType: serverTest,
11903 name: "RetainOnlySHA256-OffOn-" + ver.name,
11904 config: Config{
11905 MinVersion: ver.version,
11906 MaxVersion: ver.version,
11907 Certificates: []Certificate{rsaCertificate},
11908 },
David Benjamina5022392017-07-10 17:40:39 -040011909 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011910 flags: []string{
11911 "-verify-peer",
11912 "-retain-only-sha256-client-cert-resume",
11913 "-expect-sha256-client-cert-resume",
11914 },
11915 resumeSession: true,
11916 expectResumeRejected: true,
11917 })
11918 }
11919}
11920
Adam Langleya4b91982016-12-12 12:05:53 -080011921func addECDSAKeyUsageTests() {
11922 p256 := elliptic.P256()
11923 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11924 if err != nil {
11925 panic(err)
11926 }
11927
11928 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11929 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11930 if err != nil {
11931 panic(err)
11932 }
11933
11934 template := x509.Certificate{
11935 SerialNumber: serialNumber,
11936 Subject: pkix.Name{
11937 Organization: []string{"Acme Co"},
11938 },
11939 NotBefore: time.Now(),
11940 NotAfter: time.Now(),
11941
11942 // An ECC certificate with only the keyAgreement key usgae may
11943 // be used with ECDH, but not ECDSA.
11944 KeyUsage: x509.KeyUsageKeyAgreement,
11945 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11946 BasicConstraintsValid: true,
11947 }
11948
11949 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11950 if err != nil {
11951 panic(err)
11952 }
11953
11954 cert := Certificate{
11955 Certificate: [][]byte{derBytes},
11956 PrivateKey: priv,
11957 }
11958
11959 for _, ver := range tlsVersions {
11960 if ver.version < VersionTLS12 {
11961 continue
11962 }
11963
11964 testCases = append(testCases, testCase{
11965 testType: clientTest,
11966 name: "ECDSAKeyUsage-" + ver.name,
11967 config: Config{
11968 MinVersion: ver.version,
11969 MaxVersion: ver.version,
11970 Certificates: []Certificate{cert},
11971 },
David Benjamina5022392017-07-10 17:40:39 -040011972 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080011973 shouldFail: true,
11974 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11975 })
11976 }
11977}
11978
David Benjamin8c26d752017-03-26 15:13:51 -050011979func addExtraHandshakeTests() {
11980 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11981 // to ensure there is no transport I/O.
11982 testCases = append(testCases, testCase{
11983 testType: clientTest,
11984 name: "ExtraHandshake-Client-TLS12",
11985 config: Config{
11986 MinVersion: VersionTLS12,
11987 MaxVersion: VersionTLS12,
11988 },
11989 flags: []string{
11990 "-async",
11991 "-no-op-extra-handshake",
11992 },
11993 })
11994 testCases = append(testCases, testCase{
11995 testType: serverTest,
11996 name: "ExtraHandshake-Server-TLS12",
11997 config: Config{
11998 MinVersion: VersionTLS12,
11999 MaxVersion: VersionTLS12,
12000 },
12001 flags: []string{
12002 "-async",
12003 "-no-op-extra-handshake",
12004 },
12005 })
12006 testCases = append(testCases, testCase{
12007 testType: clientTest,
12008 name: "ExtraHandshake-Client-TLS13",
12009 config: Config{
12010 MinVersion: VersionTLS13,
12011 MaxVersion: VersionTLS13,
12012 },
12013 flags: []string{
12014 "-async",
12015 "-no-op-extra-handshake",
12016 },
12017 })
12018 testCases = append(testCases, testCase{
12019 testType: serverTest,
12020 name: "ExtraHandshake-Server-TLS13",
12021 config: Config{
12022 MinVersion: VersionTLS13,
12023 MaxVersion: VersionTLS13,
12024 },
12025 flags: []string{
12026 "-async",
12027 "-no-op-extra-handshake",
12028 },
12029 })
12030
12031 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12032 testCases = append(testCases, testCase{
12033 testType: serverTest,
12034 name: "ExtraHandshake-Server-EarlyData-TLS13",
12035 config: Config{
12036 MaxVersion: VersionTLS13,
12037 MinVersion: VersionTLS13,
12038 Bugs: ProtocolBugs{
12039 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12040 ExpectEarlyDataAccepted: true,
12041 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12042 },
12043 },
12044 messageCount: 2,
12045 resumeSession: true,
12046 flags: []string{
12047 "-async",
12048 "-enable-early-data",
12049 "-expect-accept-early-data",
12050 "-no-op-extra-handshake",
12051 },
12052 })
12053
12054 // An extra SSL_do_handshake drives the handshake to completion in False
12055 // Start. We test this by handshaking twice and asserting the False
12056 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12057 // how the test works.
12058 testCases = append(testCases, testCase{
12059 testType: clientTest,
12060 name: "ExtraHandshake-FalseStart",
12061 config: Config{
12062 MaxVersion: VersionTLS12,
12063 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12064 NextProtos: []string{"foo"},
12065 Bugs: ProtocolBugs{
12066 ExpectFalseStart: true,
12067 AlertBeforeFalseStartTest: alertAccessDenied,
12068 },
12069 },
12070 flags: []string{
12071 "-handshake-twice",
12072 "-false-start",
12073 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012074 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012075 },
12076 shimWritesFirst: true,
12077 shouldFail: true,
12078 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12079 expectedLocalError: "tls: peer did not false start: EOF",
12080 })
12081}
12082
David Benjaminb853f312017-07-14 18:40:34 -040012083// Test that omitted and empty extensions blocks are tolerated.
12084func addOmitExtensionsTests() {
12085 for _, ver := range tlsVersions {
12086 if ver.version > VersionTLS12 {
12087 continue
12088 }
12089
12090 testCases = append(testCases, testCase{
12091 testType: serverTest,
12092 name: "OmitExtensions-ClientHello-" + ver.name,
12093 config: Config{
12094 MinVersion: ver.version,
12095 MaxVersion: ver.version,
12096 SessionTicketsDisabled: true,
12097 Bugs: ProtocolBugs{
12098 OmitExtensions: true,
12099 },
12100 },
12101 })
12102
12103 testCases = append(testCases, testCase{
12104 testType: serverTest,
12105 name: "EmptyExtensions-ClientHello-" + ver.name,
12106 config: Config{
12107 MinVersion: ver.version,
12108 MaxVersion: ver.version,
12109 SessionTicketsDisabled: true,
12110 Bugs: ProtocolBugs{
12111 EmptyExtensions: true,
12112 },
12113 },
12114 })
12115
12116 testCases = append(testCases, testCase{
12117 testType: clientTest,
12118 name: "OmitExtensions-ServerHello-" + ver.name,
12119 config: Config{
12120 MinVersion: ver.version,
12121 MaxVersion: ver.version,
12122 SessionTicketsDisabled: true,
12123 Bugs: ProtocolBugs{
12124 OmitExtensions: true,
12125 // Disable all ServerHello extensions so
12126 // OmitExtensions works.
12127 NoExtendedMasterSecret: true,
12128 NoRenegotiationInfo: true,
12129 },
12130 },
12131 })
12132
12133 testCases = append(testCases, testCase{
12134 testType: clientTest,
12135 name: "EmptyExtensions-ServerHello-" + ver.name,
12136 config: Config{
12137 MinVersion: ver.version,
12138 MaxVersion: ver.version,
12139 SessionTicketsDisabled: true,
12140 Bugs: ProtocolBugs{
12141 EmptyExtensions: true,
12142 // Disable all ServerHello extensions so
12143 // EmptyExtensions works.
12144 NoExtendedMasterSecret: true,
12145 NoRenegotiationInfo: true,
12146 },
12147 },
12148 })
12149 }
12150}
12151
Adam Langley7c803a62015-06-15 15:35:05 -070012152func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012153 defer wg.Done()
12154
12155 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012156 var err error
12157
David Benjaminba28dfc2016-11-15 17:47:21 +090012158 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012159 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12160 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012161 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012162 if err != nil {
12163 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12164 }
12165 break
12166 }
12167 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012168 } else if *repeatUntilFailure {
12169 for err == nil {
12170 statusChan <- statusMsg{test: test, started: true}
12171 err = runTest(test, shimPath, -1)
12172 }
12173 } else {
12174 statusChan <- statusMsg{test: test, started: true}
12175 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012176 }
Adam Langley95c29f32014-06-20 12:00:00 -070012177 statusChan <- statusMsg{test: test, err: err}
12178 }
12179}
12180
12181type statusMsg struct {
12182 test *testCase
12183 started bool
12184 err error
12185}
12186
David Benjamin5f237bc2015-02-11 17:14:15 -050012187func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012188 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012189
David Benjamin5f237bc2015-02-11 17:14:15 -050012190 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012191 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012192 if !*pipe {
12193 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012194 var erase string
12195 for i := 0; i < lineLen; i++ {
12196 erase += "\b \b"
12197 }
12198 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012199 }
12200
Adam Langley95c29f32014-06-20 12:00:00 -070012201 if msg.started {
12202 started++
12203 } else {
12204 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012205
12206 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012207 if msg.err == errUnimplemented {
12208 if *pipe {
12209 // Print each test instead of a status line.
12210 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12211 }
12212 unimplemented++
12213 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12214 } else {
12215 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12216 failed++
12217 testOutput.addResult(msg.test.name, "FAIL")
12218 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012219 } else {
12220 if *pipe {
12221 // Print each test instead of a status line.
12222 fmt.Printf("PASSED (%s)\n", msg.test.name)
12223 }
12224 testOutput.addResult(msg.test.name, "PASS")
12225 }
Adam Langley95c29f32014-06-20 12:00:00 -070012226 }
12227
David Benjamin5f237bc2015-02-11 17:14:15 -050012228 if !*pipe {
12229 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012230 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012231 lineLen = len(line)
12232 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012233 }
Adam Langley95c29f32014-06-20 12:00:00 -070012234 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012235
12236 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012237}
12238
12239func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012240 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012241 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012242 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012243
Adam Langley7c803a62015-06-15 15:35:05 -070012244 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012245 addCipherSuiteTests()
12246 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012247 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012248 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012249 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012250 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012251 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012252 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012253 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012254 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012255 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012256 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012257 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012258 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012259 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012260 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012261 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012262 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012263 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012264 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012265 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012266 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012267 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012268 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012269 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012270 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012271 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012272 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012273 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012274 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012275 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012276 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012277 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012278 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012279 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012280
12281 var wg sync.WaitGroup
12282
Adam Langley7c803a62015-06-15 15:35:05 -070012283 statusChan := make(chan statusMsg, *numWorkers)
12284 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012285 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012286
EKRf71d7ed2016-08-06 13:25:12 -070012287 if len(*shimConfigFile) != 0 {
12288 encoded, err := ioutil.ReadFile(*shimConfigFile)
12289 if err != nil {
12290 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12291 os.Exit(1)
12292 }
12293
12294 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12295 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12296 os.Exit(1)
12297 }
12298 }
12299
David Benjamin025b3d32014-07-01 19:53:04 -040012300 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012301
Adam Langley7c803a62015-06-15 15:35:05 -070012302 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012303 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012304 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012305 }
12306
David Benjamin270f0a72016-03-17 14:41:36 -040012307 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012308 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012309 matched := true
12310 if len(*testToRun) != 0 {
12311 var err error
12312 matched, err = filepath.Match(*testToRun, testCases[i].name)
12313 if err != nil {
12314 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12315 os.Exit(1)
12316 }
12317 }
12318
EKRf71d7ed2016-08-06 13:25:12 -070012319 if !*includeDisabled {
12320 for pattern := range shimConfig.DisabledTests {
12321 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12322 if err != nil {
12323 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12324 os.Exit(1)
12325 }
12326
12327 if isDisabled {
12328 matched = false
12329 break
12330 }
12331 }
12332 }
12333
David Benjamin17e12922016-07-28 18:04:43 -040012334 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012335 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012336 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012337
12338 // Only run one test if repeating until failure.
12339 if *repeatUntilFailure {
12340 break
12341 }
Adam Langley95c29f32014-06-20 12:00:00 -070012342 }
12343 }
David Benjamin17e12922016-07-28 18:04:43 -040012344
David Benjamin270f0a72016-03-17 14:41:36 -040012345 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012346 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012347 os.Exit(1)
12348 }
Adam Langley95c29f32014-06-20 12:00:00 -070012349
12350 close(testChan)
12351 wg.Wait()
12352 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012353 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012354
12355 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012356
12357 if *jsonOutput != "" {
12358 if err := testOutput.writeTo(*jsonOutput); err != nil {
12359 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12360 }
12361 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012362
EKR842ae6c2016-07-27 09:22:05 +020012363 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12364 os.Exit(1)
12365 }
12366
12367 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012368 os.Exit(1)
12369 }
Adam Langley95c29f32014-06-20 12:00:00 -070012370}