blob: 8ced44d43026762f2b56683b523e26618da64c9c [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 Benjamin3a1dd462017-07-11 16:13:10 -04004556 for _, useCustomCallback := range []bool{false, true} {
4557 for _, testType := range []testType{clientTest, serverTest} {
4558 suffix := "-Client"
4559 if testType == serverTest {
4560 suffix = "-Server"
4561 }
4562 suffix += "-" + vers.name
4563 if useCustomCallback {
4564 suffix += "-CustomCallback"
4565 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004566
David Benjamin3a1dd462017-07-11 16:13:10 -04004567 flags := []string{"-verify-peer"}
4568 if testType == serverTest {
4569 flags = append(flags, "-require-any-client-certificate")
4570 }
4571 if useCustomCallback {
4572 flags = append(flags, "-use-custom-verify-callback")
4573 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004574
David Benjamin3a1dd462017-07-11 16:13:10 -04004575 tests = append(tests, testCase{
4576 testType: testType,
4577 name: "CertificateVerificationSucceed" + suffix,
4578 config: Config{
4579 MaxVersion: vers.version,
4580 Certificates: []Certificate{rsaCertificate},
4581 },
4582 tls13Variant: vers.tls13Variant,
4583 flags: append([]string{"-expect-verify-result"}, flags...),
4584 resumeSession: true,
4585 })
4586 tests = append(tests, testCase{
4587 testType: testType,
4588 name: "CertificateVerificationFail" + suffix,
4589 config: Config{
4590 MaxVersion: vers.version,
4591 Certificates: []Certificate{rsaCertificate},
4592 },
4593 tls13Variant: vers.tls13Variant,
4594 flags: append([]string{"-verify-fail"}, flags...),
4595 shouldFail: true,
4596 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4597 })
4598 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004599 }
4600
4601 // By default, the client is in a soft fail mode where the peer
4602 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004603 tests = append(tests, testCase{
4604 testType: clientTest,
4605 name: "CertificateVerificationSoftFail-" + vers.name,
4606 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004607 MaxVersion: vers.version,
4608 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004609 },
David Benjamina5022392017-07-10 17:40:39 -04004610 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004611 flags: []string{
4612 "-verify-fail",
4613 "-expect-verify-result",
4614 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004615 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004616 })
4617 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004618
David Benjamin1d4f4c02016-07-26 18:03:08 -04004619 tests = append(tests, testCase{
4620 name: "ShimSendAlert",
4621 flags: []string{"-send-alert"},
4622 shimWritesFirst: true,
4623 shouldFail: true,
4624 expectedLocalError: "remote error: decompression failure",
4625 })
4626
David Benjamin582ba042016-07-07 12:33:25 -07004627 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004628 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004629 name: "Renegotiate-Client",
4630 config: Config{
4631 MaxVersion: VersionTLS12,
4632 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004633 renegotiate: 1,
4634 flags: []string{
4635 "-renegotiate-freely",
4636 "-expect-total-renegotiations", "1",
4637 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004638 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004639
David Benjamin47921102016-07-28 11:29:18 -04004640 tests = append(tests, testCase{
4641 name: "SendHalfHelloRequest",
4642 config: Config{
4643 MaxVersion: VersionTLS12,
4644 Bugs: ProtocolBugs{
4645 PackHelloRequestWithFinished: config.packHandshakeFlight,
4646 },
4647 },
4648 sendHalfHelloRequest: true,
4649 flags: []string{"-renegotiate-ignore"},
4650 shouldFail: true,
4651 expectedError: ":UNEXPECTED_RECORD:",
4652 })
4653
David Benjamin760b1dd2015-05-15 23:33:48 -04004654 // NPN on client and server; results in post-handshake message.
4655 tests = append(tests, testCase{
4656 name: "NPN-Client",
4657 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004658 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004659 NextProtos: []string{"foo"},
4660 },
4661 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004662 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004663 expectedNextProto: "foo",
4664 expectedNextProtoType: npn,
4665 })
4666 tests = append(tests, testCase{
4667 testType: serverTest,
4668 name: "NPN-Server",
4669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004670 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004671 NextProtos: []string{"bar"},
4672 },
4673 flags: []string{
4674 "-advertise-npn", "\x03foo\x03bar\x03baz",
4675 "-expect-next-proto", "bar",
4676 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004677 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004678 expectedNextProto: "bar",
4679 expectedNextProtoType: npn,
4680 })
4681
4682 // TODO(davidben): Add tests for when False Start doesn't trigger.
4683
4684 // Client does False Start and negotiates NPN.
4685 tests = append(tests, testCase{
4686 name: "FalseStart",
4687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4690 NextProtos: []string{"foo"},
4691 Bugs: ProtocolBugs{
4692 ExpectFalseStart: true,
4693 },
4694 },
4695 flags: []string{
4696 "-false-start",
4697 "-select-next-proto", "foo",
4698 },
4699 shimWritesFirst: true,
4700 resumeSession: true,
4701 })
4702
4703 // Client does False Start and negotiates ALPN.
4704 tests = append(tests, testCase{
4705 name: "FalseStart-ALPN",
4706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004707 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4709 NextProtos: []string{"foo"},
4710 Bugs: ProtocolBugs{
4711 ExpectFalseStart: true,
4712 },
4713 },
4714 flags: []string{
4715 "-false-start",
4716 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004717 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004718 },
4719 shimWritesFirst: true,
4720 resumeSession: true,
4721 })
4722
David Benjamin760b1dd2015-05-15 23:33:48 -04004723 // False Start without session tickets.
4724 tests = append(tests, testCase{
4725 name: "FalseStart-SessionTicketsDisabled",
4726 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4729 NextProtos: []string{"foo"},
4730 SessionTicketsDisabled: true,
4731 Bugs: ProtocolBugs{
4732 ExpectFalseStart: true,
4733 },
4734 },
4735 flags: []string{
4736 "-false-start",
4737 "-select-next-proto", "foo",
4738 },
4739 shimWritesFirst: true,
4740 })
4741
4742 // Server parses a V2ClientHello.
4743 tests = append(tests, testCase{
4744 testType: serverTest,
4745 name: "SendV2ClientHello",
4746 config: Config{
4747 // Choose a cipher suite that does not involve
4748 // elliptic curves, so no extensions are
4749 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004750 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004751 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004752 Bugs: ProtocolBugs{
4753 SendV2ClientHello: true,
4754 },
4755 },
4756 })
4757
Nick Harper60a85cb2016-09-23 16:25:11 -07004758 // Test Channel ID
4759 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004760 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004761 continue
4762 }
4763 // Client sends a Channel ID.
4764 tests = append(tests, testCase{
4765 name: "ChannelID-Client-" + ver.name,
4766 config: Config{
4767 MaxVersion: ver.version,
4768 RequestChannelID: true,
4769 },
David Benjamina5022392017-07-10 17:40:39 -04004770 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004771 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4772 resumeSession: true,
4773 expectChannelID: true,
4774 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004775
Nick Harper60a85cb2016-09-23 16:25:11 -07004776 // Server accepts a Channel ID.
4777 tests = append(tests, testCase{
4778 testType: serverTest,
4779 name: "ChannelID-Server-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 ChannelID: channelIDKey,
4783 },
David Benjamina5022392017-07-10 17:40:39 -04004784 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004785 flags: []string{
4786 "-expect-channel-id",
4787 base64.StdEncoding.EncodeToString(channelIDBytes),
4788 },
4789 resumeSession: true,
4790 expectChannelID: true,
4791 })
4792
4793 tests = append(tests, testCase{
4794 testType: serverTest,
4795 name: "InvalidChannelIDSignature-" + ver.name,
4796 config: Config{
4797 MaxVersion: ver.version,
4798 ChannelID: channelIDKey,
4799 Bugs: ProtocolBugs{
4800 InvalidChannelIDSignature: true,
4801 },
4802 },
David Benjamina5022392017-07-10 17:40:39 -04004803 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004804 flags: []string{"-enable-channel-id"},
4805 shouldFail: true,
4806 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4807 })
David Benjamin634f4752017-07-01 11:08:41 -04004808
4809 if ver.version < VersionTLS13 {
4810 // Channel ID requires ECDHE ciphers.
4811 tests = append(tests, testCase{
4812 testType: serverTest,
4813 name: "ChannelID-NoECDHE-" + ver.name,
4814 config: Config{
4815 MaxVersion: ver.version,
4816 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4817 ChannelID: channelIDKey,
4818 },
4819 expectChannelID: false,
4820 flags: []string{"-enable-channel-id"},
4821 })
4822
4823 // Sanity-check setting expectChannelID false works.
4824 tests = append(tests, testCase{
4825 testType: serverTest,
4826 name: "ChannelID-ECDHE-" + ver.name,
4827 config: Config{
4828 MaxVersion: ver.version,
4829 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4830 ChannelID: channelIDKey,
4831 },
4832 expectChannelID: false,
4833 flags: []string{"-enable-channel-id"},
4834 shouldFail: true,
4835 expectedLocalError: "channel ID unexpectedly negotiated",
4836 })
4837 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004838 }
David Benjamin30789da2015-08-29 22:56:45 -04004839
David Benjaminf8fcdf32016-06-08 15:56:13 -04004840 // Channel ID and NPN at the same time, to ensure their relative
4841 // ordering is correct.
4842 tests = append(tests, testCase{
4843 name: "ChannelID-NPN-Client",
4844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004845 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004846 RequestChannelID: true,
4847 NextProtos: []string{"foo"},
4848 },
4849 flags: []string{
4850 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4851 "-select-next-proto", "foo",
4852 },
4853 resumeSession: true,
4854 expectChannelID: true,
4855 expectedNextProto: "foo",
4856 expectedNextProtoType: npn,
4857 })
4858 tests = append(tests, testCase{
4859 testType: serverTest,
4860 name: "ChannelID-NPN-Server",
4861 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004862 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004863 ChannelID: channelIDKey,
4864 NextProtos: []string{"bar"},
4865 },
4866 flags: []string{
4867 "-expect-channel-id",
4868 base64.StdEncoding.EncodeToString(channelIDBytes),
4869 "-advertise-npn", "\x03foo\x03bar\x03baz",
4870 "-expect-next-proto", "bar",
4871 },
4872 resumeSession: true,
4873 expectChannelID: true,
4874 expectedNextProto: "bar",
4875 expectedNextProtoType: npn,
4876 })
4877
David Benjamin30789da2015-08-29 22:56:45 -04004878 // Bidirectional shutdown with the runner initiating.
4879 tests = append(tests, testCase{
4880 name: "Shutdown-Runner",
4881 config: Config{
4882 Bugs: ProtocolBugs{
4883 ExpectCloseNotify: true,
4884 },
4885 },
4886 flags: []string{"-check-close-notify"},
4887 })
4888
David Benjamine3843d42017-03-25 18:00:56 -05004889 if !config.implicitHandshake {
4890 // Bidirectional shutdown with the shim initiating. The runner,
4891 // in the meantime, sends garbage before the close_notify which
4892 // the shim must ignore. This test is disabled under implicit
4893 // handshake tests because the shim never reads or writes.
4894 tests = append(tests, testCase{
4895 name: "Shutdown-Shim",
4896 config: Config{
4897 MaxVersion: VersionTLS12,
4898 Bugs: ProtocolBugs{
4899 ExpectCloseNotify: true,
4900 },
David Benjamin30789da2015-08-29 22:56:45 -04004901 },
David Benjamine3843d42017-03-25 18:00:56 -05004902 shimShutsDown: true,
4903 sendEmptyRecords: 1,
4904 sendWarningAlerts: 1,
4905 flags: []string{"-check-close-notify"},
4906 })
4907 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004908 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004909 // TODO(davidben): DTLS 1.3 will want a similar thing for
4910 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004911 tests = append(tests, testCase{
4912 name: "SkipHelloVerifyRequest",
4913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004914 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004915 Bugs: ProtocolBugs{
4916 SkipHelloVerifyRequest: true,
4917 },
4918 },
4919 })
4920 }
4921
David Benjamin760b1dd2015-05-15 23:33:48 -04004922 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004923 test.protocol = config.protocol
4924 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004925 test.name += "-DTLS"
4926 }
David Benjamin582ba042016-07-07 12:33:25 -07004927 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004928 test.name += "-Async"
4929 test.flags = append(test.flags, "-async")
4930 } else {
4931 test.name += "-Sync"
4932 }
David Benjamin582ba042016-07-07 12:33:25 -07004933 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004934 test.name += "-SplitHandshakeRecords"
4935 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004936 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004937 test.config.Bugs.MaxPacketLength = 256
4938 test.flags = append(test.flags, "-mtu", "256")
4939 }
4940 }
David Benjamin582ba042016-07-07 12:33:25 -07004941 if config.packHandshakeFlight {
4942 test.name += "-PackHandshakeFlight"
4943 test.config.Bugs.PackHandshakeFlight = true
4944 }
David Benjamine3843d42017-03-25 18:00:56 -05004945 if config.implicitHandshake {
4946 test.name += "-ImplicitHandshake"
4947 test.flags = append(test.flags, "-implicit-handshake")
4948 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004949 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004950 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004951}
4952
Adam Langley524e7172015-02-20 16:04:00 -08004953func addDDoSCallbackTests() {
4954 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004955 for _, resume := range []bool{false, true} {
4956 suffix := "Resume"
4957 if resume {
4958 suffix = "No" + suffix
4959 }
4960
4961 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004962 testType: serverTest,
4963 name: "Server-DDoS-OK-" + suffix,
4964 config: Config{
4965 MaxVersion: VersionTLS12,
4966 },
Adam Langley524e7172015-02-20 16:04:00 -08004967 flags: []string{"-install-ddos-callback"},
4968 resumeSession: resume,
4969 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004970 testCases = append(testCases, testCase{
4971 testType: serverTest,
4972 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4973 config: Config{
4974 MaxVersion: VersionTLS13,
4975 },
4976 flags: []string{"-install-ddos-callback"},
4977 resumeSession: resume,
4978 })
Adam Langley524e7172015-02-20 16:04:00 -08004979
4980 failFlag := "-fail-ddos-callback"
4981 if resume {
4982 failFlag = "-fail-second-ddos-callback"
4983 }
4984 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004985 testType: serverTest,
4986 name: "Server-DDoS-Reject-" + suffix,
4987 config: Config{
4988 MaxVersion: VersionTLS12,
4989 },
David Benjamin2c66e072016-09-16 15:58:00 -04004990 flags: []string{"-install-ddos-callback", failFlag},
4991 resumeSession: resume,
4992 shouldFail: true,
4993 expectedError: ":CONNECTION_REJECTED:",
4994 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004995 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004996 testCases = append(testCases, testCase{
4997 testType: serverTest,
4998 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4999 config: Config{
5000 MaxVersion: VersionTLS13,
5001 },
David Benjamin2c66e072016-09-16 15:58:00 -04005002 flags: []string{"-install-ddos-callback", failFlag},
5003 resumeSession: resume,
5004 shouldFail: true,
5005 expectedError: ":CONNECTION_REJECTED:",
5006 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005007 })
Adam Langley524e7172015-02-20 16:04:00 -08005008 }
5009}
5010
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005011func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005012 for _, protocol := range []protocol{tls, dtls} {
5013 for _, shimVers := range allVersions(protocol) {
5014 // Assemble flags to disable all newer versions on the shim.
5015 var flags []string
5016 for _, vers := range allVersions(protocol) {
5017 if vers.version > shimVers.version {
5018 flags = append(flags, vers.excludeFlag)
5019 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005020 }
Steven Valdez520e1222017-06-13 12:45:25 -04005021
5022 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5023
5024 if shimVers.tls13Variant != 0 {
5025 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5026 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5027 }
5028
5029 // Test configuring the runner's maximum version.
5030 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005031 expectedVersion := shimVers.version
5032 if runnerVers.version < shimVers.version {
5033 expectedVersion = runnerVers.version
5034 }
Steven Valdez520e1222017-06-13 12:45:25 -04005035 // When running and shim have different TLS 1.3 variants enabled,
5036 // shim clients are expected to fall back to TLS 1.2, while shim
5037 // servers support both variants when enabled when the experiment is
5038 // enabled.
5039 expectedServerVersion := expectedVersion
5040 expectedClientVersion := expectedVersion
5041 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5042 expectedClientVersion = VersionTLS12
5043 expectedServerVersion = VersionTLS12
5044 if shimVers.tls13Variant != TLS13Default {
5045 expectedServerVersion = VersionTLS13
5046 }
5047 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005048
David Benjamin8b8c0062014-11-23 02:47:52 -05005049 suffix := shimVers.name + "-" + runnerVers.name
5050 if protocol == dtls {
5051 suffix += "-DTLS"
5052 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005053
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005054 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005055 clientVers := shimVers.version
5056 if clientVers > VersionTLS10 {
5057 clientVers = VersionTLS10
5058 }
Steven Valdez520e1222017-06-13 12:45:25 -04005059 clientVers = recordVersionToWire(clientVers, protocol)
5060 serverVers := expectedServerVersion
5061 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005062 serverVers = VersionTLS10
5063 }
Steven Valdez520e1222017-06-13 12:45:25 -04005064 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005065
David Benjamin8b8c0062014-11-23 02:47:52 -05005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 testType: clientTest,
5069 name: "VersionNegotiation-Client-" + suffix,
5070 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005071 MaxVersion: runnerVers.version,
5072 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005073 Bugs: ProtocolBugs{
5074 ExpectInitialRecordVersion: clientVers,
5075 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005076 },
5077 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005078 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005079 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005080 testCases = append(testCases, testCase{
5081 protocol: protocol,
5082 testType: clientTest,
5083 name: "VersionNegotiation-Client2-" + suffix,
5084 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005085 MaxVersion: runnerVers.version,
5086 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005087 Bugs: ProtocolBugs{
5088 ExpectInitialRecordVersion: clientVers,
5089 },
5090 },
Steven Valdez520e1222017-06-13 12:45:25 -04005091 flags: flags2,
5092 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005093 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005094
5095 testCases = append(testCases, testCase{
5096 protocol: protocol,
5097 testType: serverTest,
5098 name: "VersionNegotiation-Server-" + suffix,
5099 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005100 MaxVersion: runnerVers.version,
5101 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005102 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005103 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005105 },
5106 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005107 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005108 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005109 testCases = append(testCases, testCase{
5110 protocol: protocol,
5111 testType: serverTest,
5112 name: "VersionNegotiation-Server2-" + suffix,
5113 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005114 MaxVersion: runnerVers.version,
5115 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005116 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005117 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005118 },
5119 },
Steven Valdez520e1222017-06-13 12:45:25 -04005120 flags: flags2,
5121 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005122 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005123 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005124 }
5125 }
David Benjamin95c69562016-06-29 18:15:03 -04005126
Steven Valdezfdd10992016-09-15 16:27:05 -04005127 // Test the version extension at all versions.
5128 for _, vers := range tlsVersions {
5129 protocols := []protocol{tls}
5130 if vers.hasDTLS {
5131 protocols = append(protocols, dtls)
5132 }
5133 for _, protocol := range protocols {
5134 suffix := vers.name
5135 if protocol == dtls {
5136 suffix += "-DTLS"
5137 }
5138
Steven Valdezfdd10992016-09-15 16:27:05 -04005139 testCases = append(testCases, testCase{
5140 protocol: protocol,
5141 testType: serverTest,
5142 name: "VersionNegotiationExtension-" + suffix,
5143 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005144 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005145 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005146 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005147 },
5148 },
5149 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005150 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005151 })
5152 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005153 }
5154
5155 // If all versions are unknown, negotiation fails.
5156 testCases = append(testCases, testCase{
5157 testType: serverTest,
5158 name: "NoSupportedVersions",
5159 config: Config{
5160 Bugs: ProtocolBugs{
5161 SendSupportedVersions: []uint16{0x1111},
5162 },
5163 },
5164 shouldFail: true,
5165 expectedError: ":UNSUPPORTED_PROTOCOL:",
5166 })
5167 testCases = append(testCases, testCase{
5168 protocol: dtls,
5169 testType: serverTest,
5170 name: "NoSupportedVersions-DTLS",
5171 config: Config{
5172 Bugs: ProtocolBugs{
5173 SendSupportedVersions: []uint16{0x1111},
5174 },
5175 },
5176 shouldFail: true,
5177 expectedError: ":UNSUPPORTED_PROTOCOL:",
5178 })
5179
5180 testCases = append(testCases, testCase{
5181 testType: serverTest,
5182 name: "ClientHelloVersionTooHigh",
5183 config: Config{
5184 MaxVersion: VersionTLS13,
5185 Bugs: ProtocolBugs{
5186 SendClientVersion: 0x0304,
5187 OmitSupportedVersions: true,
5188 },
5189 },
5190 expectedVersion: VersionTLS12,
5191 })
5192
5193 testCases = append(testCases, testCase{
5194 testType: serverTest,
5195 name: "ConflictingVersionNegotiation",
5196 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005197 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005198 SendClientVersion: VersionTLS12,
5199 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005200 },
5201 },
David Benjaminad75a662016-09-30 15:42:59 -04005202 // The extension takes precedence over the ClientHello version.
5203 expectedVersion: VersionTLS11,
5204 })
5205
5206 testCases = append(testCases, testCase{
5207 testType: serverTest,
5208 name: "ConflictingVersionNegotiation-2",
5209 config: Config{
5210 Bugs: ProtocolBugs{
5211 SendClientVersion: VersionTLS11,
5212 SendSupportedVersions: []uint16{VersionTLS12},
5213 },
5214 },
5215 // The extension takes precedence over the ClientHello version.
5216 expectedVersion: VersionTLS12,
5217 })
5218
5219 testCases = append(testCases, testCase{
5220 testType: serverTest,
5221 name: "RejectFinalTLS13",
5222 config: Config{
5223 Bugs: ProtocolBugs{
5224 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5225 },
5226 },
5227 // We currently implement a draft TLS 1.3 version. Ensure that
5228 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 expectedVersion: VersionTLS12,
5230 })
5231
Steven Valdez038da9b2017-07-10 12:57:25 -04005232 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5233 // the ServerHello.
5234 testCases = append(testCases, testCase{
5235 testType: clientTest,
5236 name: "SupportedVersionSelection-TLS12",
5237 config: Config{
5238 MaxVersion: VersionTLS12,
5239 Bugs: ProtocolBugs{
5240 SendServerSupportedExtensionVersion: VersionTLS12,
5241 },
5242 },
5243 shouldFail: true,
5244 expectedError: ":UNEXPECTED_EXTENSION:",
5245 })
5246
5247 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5248 // supported_versions extension in the ServerHello.
5249 testCases = append(testCases, testCase{
5250 testType: clientTest,
5251 name: "SupportedVersionSelection-TLS13",
5252 config: Config{
5253 MaxVersion: VersionTLS13,
5254 Bugs: ProtocolBugs{
5255 SendServerSupportedExtensionVersion: tls13DraftVersion,
5256 },
5257 },
5258 shouldFail: true,
5259 expectedError: ":UNEXPECTED_EXTENSION:",
5260 })
5261
Brian Smithf85d3232016-10-28 10:34:06 -10005262 // Test that the maximum version is selected regardless of the
5263 // client-sent order.
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "IgnoreClientVersionOrder",
5267 config: Config{
5268 Bugs: ProtocolBugs{
5269 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5270 },
5271 },
5272 expectedVersion: VersionTLS13,
5273 })
5274
David Benjamin95c69562016-06-29 18:15:03 -04005275 // Test for version tolerance.
5276 testCases = append(testCases, testCase{
5277 testType: serverTest,
5278 name: "MinorVersionTolerance",
5279 config: Config{
5280 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005281 SendClientVersion: 0x03ff,
5282 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005283 },
5284 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005285 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005286 })
5287 testCases = append(testCases, testCase{
5288 testType: serverTest,
5289 name: "MajorVersionTolerance",
5290 config: Config{
5291 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005292 SendClientVersion: 0x0400,
5293 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005294 },
5295 },
David Benjaminad75a662016-09-30 15:42:59 -04005296 // TLS 1.3 must be negotiated with the supported_versions
5297 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005298 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005299 })
David Benjaminad75a662016-09-30 15:42:59 -04005300 testCases = append(testCases, testCase{
5301 testType: serverTest,
5302 name: "VersionTolerance-TLS13",
5303 config: Config{
5304 Bugs: ProtocolBugs{
5305 // Although TLS 1.3 does not use
5306 // ClientHello.version, it still tolerates high
5307 // values there.
5308 SendClientVersion: 0x0400,
5309 },
5310 },
5311 expectedVersion: VersionTLS13,
5312 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005313
David Benjamin95c69562016-06-29 18:15:03 -04005314 testCases = append(testCases, testCase{
5315 protocol: dtls,
5316 testType: serverTest,
5317 name: "MinorVersionTolerance-DTLS",
5318 config: Config{
5319 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005320 SendClientVersion: 0xfe00,
5321 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005322 },
5323 },
5324 expectedVersion: VersionTLS12,
5325 })
5326 testCases = append(testCases, testCase{
5327 protocol: dtls,
5328 testType: serverTest,
5329 name: "MajorVersionTolerance-DTLS",
5330 config: Config{
5331 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005332 SendClientVersion: 0xfdff,
5333 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005334 },
5335 },
5336 expectedVersion: VersionTLS12,
5337 })
5338
5339 // Test that versions below 3.0 are rejected.
5340 testCases = append(testCases, testCase{
5341 testType: serverTest,
5342 name: "VersionTooLow",
5343 config: Config{
5344 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005345 SendClientVersion: 0x0200,
5346 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005347 },
5348 },
5349 shouldFail: true,
5350 expectedError: ":UNSUPPORTED_PROTOCOL:",
5351 })
5352 testCases = append(testCases, testCase{
5353 protocol: dtls,
5354 testType: serverTest,
5355 name: "VersionTooLow-DTLS",
5356 config: Config{
5357 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005358 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005359 },
5360 },
5361 shouldFail: true,
5362 expectedError: ":UNSUPPORTED_PROTOCOL:",
5363 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005364
David Benjamin2dc02042016-09-19 19:57:37 -04005365 testCases = append(testCases, testCase{
5366 name: "ServerBogusVersion",
5367 config: Config{
5368 Bugs: ProtocolBugs{
5369 SendServerHelloVersion: 0x1234,
5370 },
5371 },
5372 shouldFail: true,
5373 expectedError: ":UNSUPPORTED_PROTOCOL:",
5374 })
5375
David Benjamin1f61f0d2016-07-10 12:20:35 -04005376 // Test TLS 1.3's downgrade signal.
5377 testCases = append(testCases, testCase{
5378 name: "Downgrade-TLS12-Client",
5379 config: Config{
5380 Bugs: ProtocolBugs{
5381 NegotiateVersion: VersionTLS12,
5382 },
5383 },
David Benjamin592b5322016-09-30 15:15:01 -04005384 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005385 // TODO(davidben): This test should fail once TLS 1.3 is final
5386 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005387 })
5388 testCases = append(testCases, testCase{
5389 testType: serverTest,
5390 name: "Downgrade-TLS12-Server",
5391 config: Config{
5392 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005393 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005394 },
5395 },
David Benjamin592b5322016-09-30 15:15:01 -04005396 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005397 // TODO(davidben): This test should fail once TLS 1.3 is final
5398 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005399 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005400}
5401
David Benjaminaccb4542014-12-12 23:44:33 -05005402func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005403 for _, protocol := range []protocol{tls, dtls} {
5404 for _, shimVers := range allVersions(protocol) {
5405 // Assemble flags to disable all older versions on the shim.
5406 var flags []string
5407 for _, vers := range allVersions(protocol) {
5408 if vers.version < shimVers.version {
5409 flags = append(flags, vers.excludeFlag)
5410 }
David Benjaminaccb4542014-12-12 23:44:33 -05005411 }
Steven Valdez520e1222017-06-13 12:45:25 -04005412
5413 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5414
5415 if shimVers.tls13Variant != 0 {
5416 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5417 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5418 }
5419
5420 for _, runnerVers := range allVersions(protocol) {
5421 // Different TLS 1.3 variants are incompatible with each other and don't
5422 // produce consistent minimum versions.
5423 //
5424 // TODO(davidben): Fold these tests (the main value is in the
5425 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5426 // on intended shim behavior, not the shim + runner combination.
5427 if shimVers.tls13Variant != runnerVers.tls13Variant {
5428 continue
5429 }
5430
David Benjaminaccb4542014-12-12 23:44:33 -05005431 suffix := shimVers.name + "-" + runnerVers.name
5432 if protocol == dtls {
5433 suffix += "-DTLS"
5434 }
David Benjaminaccb4542014-12-12 23:44:33 -05005435
David Benjaminaccb4542014-12-12 23:44:33 -05005436 var expectedVersion uint16
5437 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005438 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005439 if runnerVers.version >= shimVers.version {
5440 expectedVersion = runnerVers.version
5441 } else {
5442 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005443 expectedError = ":UNSUPPORTED_PROTOCOL:"
5444 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005445 }
5446
5447 testCases = append(testCases, testCase{
5448 protocol: protocol,
5449 testType: clientTest,
5450 name: "MinimumVersion-Client-" + suffix,
5451 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005452 MaxVersion: runnerVers.version,
5453 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005454 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005455 // Ensure the server does not decline to
5456 // select a version (versions extension) or
5457 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005458 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005459 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005460 },
David Benjaminaccb4542014-12-12 23:44:33 -05005461 },
David Benjamin87909c02014-12-13 01:55:01 -05005462 flags: flags,
5463 expectedVersion: expectedVersion,
5464 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005465 expectedError: expectedError,
5466 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005467 })
5468 testCases = append(testCases, testCase{
5469 protocol: protocol,
5470 testType: clientTest,
5471 name: "MinimumVersion-Client2-" + suffix,
5472 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005473 MaxVersion: runnerVers.version,
5474 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005475 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005476 // Ensure the server does not decline to
5477 // select a version (versions extension) or
5478 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005479 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005480 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005481 },
David Benjaminaccb4542014-12-12 23:44:33 -05005482 },
Steven Valdez520e1222017-06-13 12:45:25 -04005483 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005484 expectedVersion: expectedVersion,
5485 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005486 expectedError: expectedError,
5487 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005488 })
5489
5490 testCases = append(testCases, testCase{
5491 protocol: protocol,
5492 testType: serverTest,
5493 name: "MinimumVersion-Server-" + suffix,
5494 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005495 MaxVersion: runnerVers.version,
5496 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005497 },
David Benjamin87909c02014-12-13 01:55:01 -05005498 flags: flags,
5499 expectedVersion: expectedVersion,
5500 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005501 expectedError: expectedError,
5502 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005503 })
5504 testCases = append(testCases, testCase{
5505 protocol: protocol,
5506 testType: serverTest,
5507 name: "MinimumVersion-Server2-" + suffix,
5508 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005509 MaxVersion: runnerVers.version,
5510 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005511 },
Steven Valdez520e1222017-06-13 12:45:25 -04005512 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005513 expectedVersion: expectedVersion,
5514 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005515 expectedError: expectedError,
5516 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005517 })
5518 }
5519 }
5520 }
5521}
5522
David Benjamine78bfde2014-09-06 12:45:15 -04005523func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005524 // TODO(davidben): Extensions, where applicable, all move their server
5525 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5526 // tests for both. Also test interaction with 0-RTT when implemented.
5527
David Benjamin97d17d92016-07-14 16:12:00 -04005528 // Repeat extensions tests all versions except SSL 3.0.
5529 for _, ver := range tlsVersions {
5530 if ver.version == VersionSSL30 {
5531 continue
5532 }
5533
David Benjamin97d17d92016-07-14 16:12:00 -04005534 // Test that duplicate extensions are rejected.
5535 testCases = append(testCases, testCase{
5536 testType: clientTest,
5537 name: "DuplicateExtensionClient-" + ver.name,
5538 config: Config{
5539 MaxVersion: ver.version,
5540 Bugs: ProtocolBugs{
5541 DuplicateExtension: true,
5542 },
David Benjamine78bfde2014-09-06 12:45:15 -04005543 },
David Benjamina5022392017-07-10 17:40:39 -04005544 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005545 shouldFail: true,
5546 expectedLocalError: "remote error: error decoding message",
5547 })
5548 testCases = append(testCases, testCase{
5549 testType: serverTest,
5550 name: "DuplicateExtensionServer-" + ver.name,
5551 config: Config{
5552 MaxVersion: ver.version,
5553 Bugs: ProtocolBugs{
5554 DuplicateExtension: true,
5555 },
David Benjamine78bfde2014-09-06 12:45:15 -04005556 },
David Benjamina5022392017-07-10 17:40:39 -04005557 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005558 shouldFail: true,
5559 expectedLocalError: "remote error: error decoding message",
5560 })
5561
5562 // Test SNI.
5563 testCases = append(testCases, testCase{
5564 testType: clientTest,
5565 name: "ServerNameExtensionClient-" + ver.name,
5566 config: Config{
5567 MaxVersion: ver.version,
5568 Bugs: ProtocolBugs{
5569 ExpectServerName: "example.com",
5570 },
David Benjamine78bfde2014-09-06 12:45:15 -04005571 },
David Benjamina5022392017-07-10 17:40:39 -04005572 tls13Variant: ver.tls13Variant,
5573 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005574 })
5575 testCases = append(testCases, testCase{
5576 testType: clientTest,
5577 name: "ServerNameExtensionClientMismatch-" + ver.name,
5578 config: Config{
5579 MaxVersion: ver.version,
5580 Bugs: ProtocolBugs{
5581 ExpectServerName: "mismatch.com",
5582 },
David Benjamine78bfde2014-09-06 12:45:15 -04005583 },
David Benjamin97d17d92016-07-14 16:12:00 -04005584 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005585 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005586 shouldFail: true,
5587 expectedLocalError: "tls: unexpected server name",
5588 })
5589 testCases = append(testCases, testCase{
5590 testType: clientTest,
5591 name: "ServerNameExtensionClientMissing-" + ver.name,
5592 config: Config{
5593 MaxVersion: ver.version,
5594 Bugs: ProtocolBugs{
5595 ExpectServerName: "missing.com",
5596 },
David Benjamine78bfde2014-09-06 12:45:15 -04005597 },
David Benjamina5022392017-07-10 17:40:39 -04005598 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005599 shouldFail: true,
5600 expectedLocalError: "tls: unexpected server name",
5601 })
5602 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005603 testType: clientTest,
5604 name: "TolerateServerNameAck-" + ver.name,
5605 config: Config{
5606 MaxVersion: ver.version,
5607 Bugs: ProtocolBugs{
5608 SendServerNameAck: true,
5609 },
5610 },
David Benjamina5022392017-07-10 17:40:39 -04005611 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005612 flags: []string{"-host-name", "example.com"},
5613 resumeSession: true,
5614 })
5615 testCases = append(testCases, testCase{
5616 testType: clientTest,
5617 name: "UnsolicitedServerNameAck-" + ver.name,
5618 config: Config{
5619 MaxVersion: ver.version,
5620 Bugs: ProtocolBugs{
5621 SendServerNameAck: true,
5622 },
5623 },
David Benjamina5022392017-07-10 17:40:39 -04005624 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005625 shouldFail: true,
5626 expectedError: ":UNEXPECTED_EXTENSION:",
5627 expectedLocalError: "remote error: unsupported extension",
5628 })
5629 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005630 testType: serverTest,
5631 name: "ServerNameExtensionServer-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005635 },
David Benjamina5022392017-07-10 17:40:39 -04005636 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005637 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005638 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005639 })
5640
5641 // Test ALPN.
5642 testCases = append(testCases, testCase{
5643 testType: clientTest,
5644 name: "ALPNClient-" + ver.name,
5645 config: Config{
5646 MaxVersion: ver.version,
5647 NextProtos: []string{"foo"},
5648 },
5649 flags: []string{
5650 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5651 "-expect-alpn", "foo",
5652 },
David Benjamina5022392017-07-10 17:40:39 -04005653 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005654 expectedNextProto: "foo",
5655 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005656 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005657 })
5658 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005659 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005660 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005661 config: Config{
5662 MaxVersion: ver.version,
5663 Bugs: ProtocolBugs{
5664 SendALPN: "baz",
5665 },
5666 },
5667 flags: []string{
5668 "-advertise-alpn", "\x03foo\x03bar",
5669 },
David Benjamina5022392017-07-10 17:40:39 -04005670 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005671 shouldFail: true,
5672 expectedError: ":INVALID_ALPN_PROTOCOL:",
5673 expectedLocalError: "remote error: illegal parameter",
5674 })
5675 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005676 testType: clientTest,
5677 name: "ALPNClient-AllowUnknown-" + ver.name,
5678 config: Config{
5679 MaxVersion: ver.version,
5680 Bugs: ProtocolBugs{
5681 SendALPN: "baz",
5682 },
5683 },
5684 flags: []string{
5685 "-advertise-alpn", "\x03foo\x03bar",
5686 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005687 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005688 },
David Benjamina5022392017-07-10 17:40:39 -04005689 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005690 })
5691 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005692 testType: serverTest,
5693 name: "ALPNServer-" + ver.name,
5694 config: Config{
5695 MaxVersion: ver.version,
5696 NextProtos: []string{"foo", "bar", "baz"},
5697 },
5698 flags: []string{
5699 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5700 "-select-alpn", "foo",
5701 },
David Benjamina5022392017-07-10 17:40:39 -04005702 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005703 expectedNextProto: "foo",
5704 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005705 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005706 })
5707 testCases = append(testCases, testCase{
5708 testType: serverTest,
5709 name: "ALPNServer-Decline-" + ver.name,
5710 config: Config{
5711 MaxVersion: ver.version,
5712 NextProtos: []string{"foo", "bar", "baz"},
5713 },
5714 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005715 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005716 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005717 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005718 })
5719
David Benjamin25fe85b2016-08-09 20:00:32 -04005720 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5721 // called once.
5722 testCases = append(testCases, testCase{
5723 testType: serverTest,
5724 name: "ALPNServer-Async-" + ver.name,
5725 config: Config{
5726 MaxVersion: ver.version,
5727 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005728 // Prior to TLS 1.3, exercise the asynchronous session callback.
5729 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005730 },
5731 flags: []string{
5732 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5733 "-select-alpn", "foo",
5734 "-async",
5735 },
David Benjamina5022392017-07-10 17:40:39 -04005736 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005737 expectedNextProto: "foo",
5738 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005739 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005740 })
5741
David Benjamin97d17d92016-07-14 16:12:00 -04005742 var emptyString string
5743 testCases = append(testCases, testCase{
5744 testType: clientTest,
5745 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5746 config: Config{
5747 MaxVersion: ver.version,
5748 NextProtos: []string{""},
5749 Bugs: ProtocolBugs{
5750 // A server returning an empty ALPN protocol
5751 // should be rejected.
5752 ALPNProtocol: &emptyString,
5753 },
5754 },
5755 flags: []string{
5756 "-advertise-alpn", "\x03foo",
5757 },
David Benjamina5022392017-07-10 17:40:39 -04005758 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005759 shouldFail: true,
5760 expectedError: ":PARSE_TLSEXT:",
5761 })
5762 testCases = append(testCases, testCase{
5763 testType: serverTest,
5764 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5765 config: Config{
5766 MaxVersion: ver.version,
5767 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005768 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005769 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005770 },
David Benjamin97d17d92016-07-14 16:12:00 -04005771 flags: []string{
5772 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005773 },
David Benjamina5022392017-07-10 17:40:39 -04005774 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005775 shouldFail: true,
5776 expectedError: ":PARSE_TLSEXT:",
5777 })
5778
5779 // Test NPN and the interaction with ALPN.
5780 if ver.version < VersionTLS13 {
5781 // Test that the server prefers ALPN over NPN.
5782 testCases = append(testCases, testCase{
5783 testType: serverTest,
5784 name: "ALPNServer-Preferred-" + ver.name,
5785 config: Config{
5786 MaxVersion: ver.version,
5787 NextProtos: []string{"foo", "bar", "baz"},
5788 },
5789 flags: []string{
5790 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5791 "-select-alpn", "foo",
5792 "-advertise-npn", "\x03foo\x03bar\x03baz",
5793 },
David Benjamina5022392017-07-10 17:40:39 -04005794 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005795 expectedNextProto: "foo",
5796 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005797 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005798 })
5799 testCases = append(testCases, testCase{
5800 testType: serverTest,
5801 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5802 config: Config{
5803 MaxVersion: ver.version,
5804 NextProtos: []string{"foo", "bar", "baz"},
5805 Bugs: ProtocolBugs{
5806 SwapNPNAndALPN: true,
5807 },
5808 },
5809 flags: []string{
5810 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5811 "-select-alpn", "foo",
5812 "-advertise-npn", "\x03foo\x03bar\x03baz",
5813 },
David Benjamina5022392017-07-10 17:40:39 -04005814 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005815 expectedNextProto: "foo",
5816 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005817 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005818 })
5819
5820 // Test that negotiating both NPN and ALPN is forbidden.
5821 testCases = append(testCases, testCase{
5822 name: "NegotiateALPNAndNPN-" + ver.name,
5823 config: Config{
5824 MaxVersion: ver.version,
5825 NextProtos: []string{"foo", "bar", "baz"},
5826 Bugs: ProtocolBugs{
5827 NegotiateALPNAndNPN: true,
5828 },
5829 },
5830 flags: []string{
5831 "-advertise-alpn", "\x03foo",
5832 "-select-next-proto", "foo",
5833 },
David Benjamina5022392017-07-10 17:40:39 -04005834 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005835 shouldFail: true,
5836 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5837 })
5838 testCases = append(testCases, testCase{
5839 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5840 config: Config{
5841 MaxVersion: ver.version,
5842 NextProtos: []string{"foo", "bar", "baz"},
5843 Bugs: ProtocolBugs{
5844 NegotiateALPNAndNPN: true,
5845 SwapNPNAndALPN: true,
5846 },
5847 },
5848 flags: []string{
5849 "-advertise-alpn", "\x03foo",
5850 "-select-next-proto", "foo",
5851 },
David Benjamina5022392017-07-10 17:40:39 -04005852 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005853 shouldFail: true,
5854 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5855 })
David Benjamin97d17d92016-07-14 16:12:00 -04005856 }
5857
5858 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005859
5860 // Resume with a corrupt ticket.
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "CorruptTicket-" + ver.name,
5864 config: Config{
5865 MaxVersion: ver.version,
5866 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005867 FilterTicket: func(in []byte) ([]byte, error) {
5868 in[len(in)-1] ^= 1
5869 return in, nil
5870 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005871 },
5872 },
David Benjamina5022392017-07-10 17:40:39 -04005873 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005874 resumeSession: true,
5875 expectResumeRejected: true,
5876 })
5877 // Test the ticket callback, with and without renewal.
5878 testCases = append(testCases, testCase{
5879 testType: serverTest,
5880 name: "TicketCallback-" + ver.name,
5881 config: Config{
5882 MaxVersion: ver.version,
5883 },
David Benjamina5022392017-07-10 17:40:39 -04005884 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005885 resumeSession: true,
5886 flags: []string{"-use-ticket-callback"},
5887 })
5888 testCases = append(testCases, testCase{
5889 testType: serverTest,
5890 name: "TicketCallback-Renew-" + ver.name,
5891 config: Config{
5892 MaxVersion: ver.version,
5893 Bugs: ProtocolBugs{
5894 ExpectNewTicket: true,
5895 },
5896 },
David Benjamina5022392017-07-10 17:40:39 -04005897 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005898 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5899 resumeSession: true,
5900 })
5901
5902 // Test that the ticket callback is only called once when everything before
5903 // it in the ClientHello is asynchronous. This corrupts the ticket so
5904 // certificate selection callbacks run.
5905 testCases = append(testCases, testCase{
5906 testType: serverTest,
5907 name: "TicketCallback-SingleCall-" + ver.name,
5908 config: Config{
5909 MaxVersion: ver.version,
5910 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005911 FilterTicket: func(in []byte) ([]byte, error) {
5912 in[len(in)-1] ^= 1
5913 return in, nil
5914 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005915 },
5916 },
David Benjamina5022392017-07-10 17:40:39 -04005917 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005918 resumeSession: true,
5919 expectResumeRejected: true,
5920 flags: []string{
5921 "-use-ticket-callback",
5922 "-async",
5923 },
5924 })
5925
David Benjamind4c349b2017-02-09 14:07:17 -05005926 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005927 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005928 testCases = append(testCases, testCase{
5929 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005930 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005931 config: Config{
5932 MaxVersion: ver.version,
5933 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005934 EmptyTicketSessionID: true,
5935 },
5936 },
5937 resumeSession: true,
5938 })
5939 testCases = append(testCases, testCase{
5940 testType: serverTest,
5941 name: "TicketSessionIDLength-16-" + ver.name,
5942 config: Config{
5943 MaxVersion: ver.version,
5944 Bugs: ProtocolBugs{
5945 TicketSessionIDLength: 16,
5946 },
5947 },
5948 resumeSession: true,
5949 })
5950 testCases = append(testCases, testCase{
5951 testType: serverTest,
5952 name: "TicketSessionIDLength-32-" + ver.name,
5953 config: Config{
5954 MaxVersion: ver.version,
5955 Bugs: ProtocolBugs{
5956 TicketSessionIDLength: 32,
5957 },
5958 },
5959 resumeSession: true,
5960 })
5961 testCases = append(testCases, testCase{
5962 testType: serverTest,
5963 name: "TicketSessionIDLength-33-" + ver.name,
5964 config: Config{
5965 MaxVersion: ver.version,
5966 Bugs: ProtocolBugs{
5967 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005968 },
5969 },
5970 resumeSession: true,
5971 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005972 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005973 expectedError: ":DECODE_ERROR:",
5974 })
5975 }
5976
5977 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5978 // are ignored.
5979 if ver.hasDTLS {
5980 testCases = append(testCases, testCase{
5981 protocol: dtls,
5982 name: "SRTP-Client-" + ver.name,
5983 config: Config{
5984 MaxVersion: ver.version,
5985 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5986 },
5987 flags: []string{
5988 "-srtp-profiles",
5989 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5990 },
5991 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5992 })
5993 testCases = append(testCases, testCase{
5994 protocol: dtls,
5995 testType: serverTest,
5996 name: "SRTP-Server-" + ver.name,
5997 config: Config{
5998 MaxVersion: ver.version,
5999 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6000 },
6001 flags: []string{
6002 "-srtp-profiles",
6003 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6004 },
6005 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6006 })
6007 // Test that the MKI is ignored.
6008 testCases = append(testCases, testCase{
6009 protocol: dtls,
6010 testType: serverTest,
6011 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6012 config: Config{
6013 MaxVersion: ver.version,
6014 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6015 Bugs: ProtocolBugs{
6016 SRTPMasterKeyIdentifer: "bogus",
6017 },
6018 },
6019 flags: []string{
6020 "-srtp-profiles",
6021 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6022 },
6023 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6024 })
6025 // Test that SRTP isn't negotiated on the server if there were
6026 // no matching profiles.
6027 testCases = append(testCases, testCase{
6028 protocol: dtls,
6029 testType: serverTest,
6030 name: "SRTP-Server-NoMatch-" + ver.name,
6031 config: Config{
6032 MaxVersion: ver.version,
6033 SRTPProtectionProfiles: []uint16{100, 101, 102},
6034 },
6035 flags: []string{
6036 "-srtp-profiles",
6037 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6038 },
6039 expectedSRTPProtectionProfile: 0,
6040 })
6041 // Test that the server returning an invalid SRTP profile is
6042 // flagged as an error by the client.
6043 testCases = append(testCases, testCase{
6044 protocol: dtls,
6045 name: "SRTP-Client-NoMatch-" + ver.name,
6046 config: Config{
6047 MaxVersion: ver.version,
6048 Bugs: ProtocolBugs{
6049 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6050 },
6051 },
6052 flags: []string{
6053 "-srtp-profiles",
6054 "SRTP_AES128_CM_SHA1_80",
6055 },
6056 shouldFail: true,
6057 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6058 })
6059 }
6060
6061 // Test SCT list.
6062 testCases = append(testCases, testCase{
6063 name: "SignedCertificateTimestampList-Client-" + ver.name,
6064 testType: clientTest,
6065 config: Config{
6066 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006067 },
David Benjamin97d17d92016-07-14 16:12:00 -04006068 flags: []string{
6069 "-enable-signed-cert-timestamps",
6070 "-expect-signed-cert-timestamps",
6071 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006072 },
David Benjamina5022392017-07-10 17:40:39 -04006073 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006074 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006075 })
David Benjamindaa88502016-10-04 16:32:16 -04006076
Adam Langleycfa08c32016-11-17 13:21:27 -08006077 var differentSCTList []byte
6078 differentSCTList = append(differentSCTList, testSCTList...)
6079 differentSCTList[len(differentSCTList)-1] ^= 1
6080
David Benjamindaa88502016-10-04 16:32:16 -04006081 // The SCT extension did not specify that it must only be sent on resumption as it
6082 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006083 testCases = append(testCases, testCase{
6084 name: "SendSCTListOnResume-" + ver.name,
6085 config: Config{
6086 MaxVersion: ver.version,
6087 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006088 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006089 },
David Benjamind98452d2015-06-16 14:16:23 -04006090 },
David Benjamin97d17d92016-07-14 16:12:00 -04006091 flags: []string{
6092 "-enable-signed-cert-timestamps",
6093 "-expect-signed-cert-timestamps",
6094 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006095 },
David Benjamina5022392017-07-10 17:40:39 -04006096 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006097 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006098 })
David Benjamindaa88502016-10-04 16:32:16 -04006099
David Benjamin97d17d92016-07-14 16:12:00 -04006100 testCases = append(testCases, testCase{
6101 name: "SignedCertificateTimestampList-Server-" + ver.name,
6102 testType: serverTest,
6103 config: Config{
6104 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006105 },
David Benjamin97d17d92016-07-14 16:12:00 -04006106 flags: []string{
6107 "-signed-cert-timestamps",
6108 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006109 },
David Benjamina5022392017-07-10 17:40:39 -04006110 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006111 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006112 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006113 })
David Benjamin53210cb2016-11-16 09:01:48 +09006114
Adam Langleycfa08c32016-11-17 13:21:27 -08006115 emptySCTListCert := *testCerts[0].cert
6116 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6117
6118 // Test empty SCT list.
6119 testCases = append(testCases, testCase{
6120 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6121 testType: clientTest,
6122 config: Config{
6123 MaxVersion: ver.version,
6124 Certificates: []Certificate{emptySCTListCert},
6125 },
6126 flags: []string{
6127 "-enable-signed-cert-timestamps",
6128 },
David Benjamina5022392017-07-10 17:40:39 -04006129 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006130 shouldFail: true,
6131 expectedError: ":ERROR_PARSING_EXTENSION:",
6132 })
6133
6134 emptySCTCert := *testCerts[0].cert
6135 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6136
6137 // Test empty SCT in non-empty list.
6138 testCases = append(testCases, testCase{
6139 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6140 testType: clientTest,
6141 config: Config{
6142 MaxVersion: ver.version,
6143 Certificates: []Certificate{emptySCTCert},
6144 },
6145 flags: []string{
6146 "-enable-signed-cert-timestamps",
6147 },
David Benjamina5022392017-07-10 17:40:39 -04006148 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006149 shouldFail: true,
6150 expectedError: ":ERROR_PARSING_EXTENSION:",
6151 })
6152
David Benjamin53210cb2016-11-16 09:01:48 +09006153 // Test that certificate-related extensions are not sent unsolicited.
6154 testCases = append(testCases, testCase{
6155 testType: serverTest,
6156 name: "UnsolicitedCertificateExtensions-" + ver.name,
6157 config: Config{
6158 MaxVersion: ver.version,
6159 Bugs: ProtocolBugs{
6160 NoOCSPStapling: true,
6161 NoSignedCertificateTimestamps: true,
6162 },
6163 },
David Benjamina5022392017-07-10 17:40:39 -04006164 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006165 flags: []string{
6166 "-ocsp-response",
6167 base64.StdEncoding.EncodeToString(testOCSPResponse),
6168 "-signed-cert-timestamps",
6169 base64.StdEncoding.EncodeToString(testSCTList),
6170 },
6171 })
David Benjamin97d17d92016-07-14 16:12:00 -04006172 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006173
Paul Lietar4fac72e2015-09-09 13:44:55 +01006174 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006175 testType: clientTest,
6176 name: "ClientHelloPadding",
6177 config: Config{
6178 Bugs: ProtocolBugs{
6179 RequireClientHelloSize: 512,
6180 },
6181 },
6182 // This hostname just needs to be long enough to push the
6183 // ClientHello into F5's danger zone between 256 and 511 bytes
6184 // long.
6185 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6186 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006187
6188 // Extensions should not function in SSL 3.0.
6189 testCases = append(testCases, testCase{
6190 testType: serverTest,
6191 name: "SSLv3Extensions-NoALPN",
6192 config: Config{
6193 MaxVersion: VersionSSL30,
6194 NextProtos: []string{"foo", "bar", "baz"},
6195 },
6196 flags: []string{
6197 "-select-alpn", "foo",
6198 },
6199 expectNoNextProto: true,
6200 })
6201
6202 // Test session tickets separately as they follow a different codepath.
6203 testCases = append(testCases, testCase{
6204 testType: serverTest,
6205 name: "SSLv3Extensions-NoTickets",
6206 config: Config{
6207 MaxVersion: VersionSSL30,
6208 Bugs: ProtocolBugs{
6209 // Historically, session tickets in SSL 3.0
6210 // failed in different ways depending on whether
6211 // the client supported renegotiation_info.
6212 NoRenegotiationInfo: true,
6213 },
6214 },
6215 resumeSession: true,
6216 })
6217 testCases = append(testCases, testCase{
6218 testType: serverTest,
6219 name: "SSLv3Extensions-NoTickets2",
6220 config: Config{
6221 MaxVersion: VersionSSL30,
6222 },
6223 resumeSession: true,
6224 })
6225
6226 // But SSL 3.0 does send and process renegotiation_info.
6227 testCases = append(testCases, testCase{
6228 testType: serverTest,
6229 name: "SSLv3Extensions-RenegotiationInfo",
6230 config: Config{
6231 MaxVersion: VersionSSL30,
6232 Bugs: ProtocolBugs{
6233 RequireRenegotiationInfo: true,
6234 },
6235 },
David Benjamind2610042017-01-03 10:49:28 -05006236 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006237 })
6238 testCases = append(testCases, testCase{
6239 testType: serverTest,
6240 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6241 config: Config{
6242 MaxVersion: VersionSSL30,
6243 Bugs: ProtocolBugs{
6244 NoRenegotiationInfo: true,
6245 SendRenegotiationSCSV: true,
6246 RequireRenegotiationInfo: true,
6247 },
6248 },
David Benjamind2610042017-01-03 10:49:28 -05006249 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006250 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006251
6252 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6253 // in ServerHello.
6254 testCases = append(testCases, testCase{
6255 name: "NPN-Forbidden-TLS13",
6256 config: Config{
6257 MaxVersion: VersionTLS13,
6258 NextProtos: []string{"foo"},
6259 Bugs: ProtocolBugs{
6260 NegotiateNPNAtAllVersions: true,
6261 },
6262 },
6263 flags: []string{"-select-next-proto", "foo"},
6264 shouldFail: true,
6265 expectedError: ":ERROR_PARSING_EXTENSION:",
6266 })
6267 testCases = append(testCases, testCase{
6268 name: "EMS-Forbidden-TLS13",
6269 config: Config{
6270 MaxVersion: VersionTLS13,
6271 Bugs: ProtocolBugs{
6272 NegotiateEMSAtAllVersions: true,
6273 },
6274 },
6275 shouldFail: true,
6276 expectedError: ":ERROR_PARSING_EXTENSION:",
6277 })
6278 testCases = append(testCases, testCase{
6279 name: "RenegotiationInfo-Forbidden-TLS13",
6280 config: Config{
6281 MaxVersion: VersionTLS13,
6282 Bugs: ProtocolBugs{
6283 NegotiateRenegotiationInfoAtAllVersions: true,
6284 },
6285 },
6286 shouldFail: true,
6287 expectedError: ":ERROR_PARSING_EXTENSION:",
6288 })
6289 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006290 name: "Ticket-Forbidden-TLS13",
6291 config: Config{
6292 MaxVersion: VersionTLS12,
6293 },
6294 resumeConfig: &Config{
6295 MaxVersion: VersionTLS13,
6296 Bugs: ProtocolBugs{
6297 AdvertiseTicketExtension: true,
6298 },
6299 },
6300 resumeSession: true,
6301 shouldFail: true,
6302 expectedError: ":ERROR_PARSING_EXTENSION:",
6303 })
6304
6305 // Test that illegal extensions in TLS 1.3 are declined by the server if
6306 // offered in ClientHello. The runner's server will fail if this occurs,
6307 // so we exercise the offering path. (EMS and Renegotiation Info are
6308 // implicit in every test.)
6309 testCases = append(testCases, testCase{
6310 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006311 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006312 config: Config{
6313 MaxVersion: VersionTLS13,
6314 NextProtos: []string{"bar"},
6315 },
6316 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6317 })
David Benjamin196df5b2016-09-21 16:23:27 -04006318
David Benjamindaa88502016-10-04 16:32:16 -04006319 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6320 // tolerated.
6321 testCases = append(testCases, testCase{
6322 name: "SendOCSPResponseOnResume-TLS12",
6323 config: Config{
6324 MaxVersion: VersionTLS12,
6325 Bugs: ProtocolBugs{
6326 SendOCSPResponseOnResume: []byte("bogus"),
6327 },
6328 },
6329 flags: []string{
6330 "-enable-ocsp-stapling",
6331 "-expect-ocsp-response",
6332 base64.StdEncoding.EncodeToString(testOCSPResponse),
6333 },
6334 resumeSession: true,
6335 })
6336
David Benjamindaa88502016-10-04 16:32:16 -04006337 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006338 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006339 config: Config{
6340 MaxVersion: VersionTLS13,
6341 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006342 SendExtensionOnCertificate: testOCSPExtension,
6343 },
6344 },
6345 shouldFail: true,
6346 expectedError: ":UNEXPECTED_EXTENSION:",
6347 })
6348
6349 testCases = append(testCases, testCase{
6350 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6351 config: Config{
6352 MaxVersion: VersionTLS13,
6353 Bugs: ProtocolBugs{
6354 SendExtensionOnCertificate: testSCTExtension,
6355 },
6356 },
6357 shouldFail: true,
6358 expectedError: ":UNEXPECTED_EXTENSION:",
6359 })
6360
6361 // Test that extensions on client certificates are never accepted.
6362 testCases = append(testCases, testCase{
6363 name: "SendExtensionOnClientCertificate-TLS13",
6364 testType: serverTest,
6365 config: Config{
6366 MaxVersion: VersionTLS13,
6367 Certificates: []Certificate{rsaCertificate},
6368 Bugs: ProtocolBugs{
6369 SendExtensionOnCertificate: testOCSPExtension,
6370 },
6371 },
6372 flags: []string{
6373 "-enable-ocsp-stapling",
6374 "-require-any-client-certificate",
6375 },
6376 shouldFail: true,
6377 expectedError: ":UNEXPECTED_EXTENSION:",
6378 })
6379
6380 testCases = append(testCases, testCase{
6381 name: "SendUnknownExtensionOnCertificate-TLS13",
6382 config: Config{
6383 MaxVersion: VersionTLS13,
6384 Bugs: ProtocolBugs{
6385 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6386 },
6387 },
6388 shouldFail: true,
6389 expectedError: ":UNEXPECTED_EXTENSION:",
6390 })
6391
Adam Langleycfa08c32016-11-17 13:21:27 -08006392 var differentSCTList []byte
6393 differentSCTList = append(differentSCTList, testSCTList...)
6394 differentSCTList[len(differentSCTList)-1] ^= 1
6395
Steven Valdeza833c352016-11-01 13:39:36 -04006396 // Test that extensions on intermediates are allowed but ignored.
6397 testCases = append(testCases, testCase{
6398 name: "IgnoreExtensionsOnIntermediates-TLS13",
6399 config: Config{
6400 MaxVersion: VersionTLS13,
6401 Certificates: []Certificate{rsaChainCertificate},
6402 Bugs: ProtocolBugs{
6403 // Send different values on the intermediate. This tests
6404 // the intermediate's extensions do not override the
6405 // leaf's.
6406 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006407 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006408 },
6409 },
6410 flags: []string{
6411 "-enable-ocsp-stapling",
6412 "-expect-ocsp-response",
6413 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006414 "-enable-signed-cert-timestamps",
6415 "-expect-signed-cert-timestamps",
6416 base64.StdEncoding.EncodeToString(testSCTList),
6417 },
6418 resumeSession: true,
6419 })
6420
6421 // Test that extensions are not sent on intermediates when configured
6422 // only for a leaf.
6423 testCases = append(testCases, testCase{
6424 testType: serverTest,
6425 name: "SendNoExtensionsOnIntermediate-TLS13",
6426 config: Config{
6427 MaxVersion: VersionTLS13,
6428 Bugs: ProtocolBugs{
6429 ExpectNoExtensionsOnIntermediate: true,
6430 },
6431 },
6432 flags: []string{
6433 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6434 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6435 "-ocsp-response",
6436 base64.StdEncoding.EncodeToString(testOCSPResponse),
6437 "-signed-cert-timestamps",
6438 base64.StdEncoding.EncodeToString(testSCTList),
6439 },
6440 })
6441
6442 // Test that extensions are not sent on client certificates.
6443 testCases = append(testCases, testCase{
6444 name: "SendNoClientCertificateExtensions-TLS13",
6445 config: Config{
6446 MaxVersion: VersionTLS13,
6447 ClientAuth: RequireAnyClientCert,
6448 },
6449 flags: []string{
6450 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6451 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6452 "-ocsp-response",
6453 base64.StdEncoding.EncodeToString(testOCSPResponse),
6454 "-signed-cert-timestamps",
6455 base64.StdEncoding.EncodeToString(testSCTList),
6456 },
6457 })
6458
6459 testCases = append(testCases, testCase{
6460 name: "SendDuplicateExtensionsOnCerts-TLS13",
6461 config: Config{
6462 MaxVersion: VersionTLS13,
6463 Bugs: ProtocolBugs{
6464 SendDuplicateCertExtensions: true,
6465 },
6466 },
6467 flags: []string{
6468 "-enable-ocsp-stapling",
6469 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006470 },
6471 resumeSession: true,
6472 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006473 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006474 })
Adam Langley9b885c52016-11-18 14:21:03 -08006475
6476 testCases = append(testCases, testCase{
6477 name: "SignedCertificateTimestampListInvalid-Server",
6478 testType: serverTest,
6479 flags: []string{
6480 "-signed-cert-timestamps",
6481 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6482 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006483 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006484 expectedError: ":INVALID_SCT_LIST:",
6485 })
David Benjamine78bfde2014-09-06 12:45:15 -04006486}
6487
David Benjamin01fe8202014-09-24 15:21:44 -04006488func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006489 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006490 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006491 // SSL 3.0 does not have tickets and TLS 1.3 does not
6492 // have session IDs, so skip their cross-resumption
6493 // tests.
6494 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6495 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6496 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006497 }
6498
David Benjamin8b8c0062014-11-23 02:47:52 -05006499 protocols := []protocol{tls}
6500 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6501 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006502 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006503 for _, protocol := range protocols {
6504 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6505 if protocol == dtls {
6506 suffix += "-DTLS"
6507 }
6508
Steven Valdez520e1222017-06-13 12:45:25 -04006509 // We can't resume across TLS 1.3 variants and error out earlier in the
6510 // session resumption.
6511 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6512 continue
6513 }
6514
David Benjaminece3de92015-03-16 18:02:20 -04006515 if sessionVers.version == resumeVers.version {
6516 testCases = append(testCases, testCase{
6517 protocol: protocol,
6518 name: "Resume-Client" + suffix,
6519 resumeSession: true,
6520 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006521 MaxVersion: sessionVers.version,
6522 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006523 Bugs: ProtocolBugs{
6524 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6525 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6526 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006527 },
David Benjaminece3de92015-03-16 18:02:20 -04006528 expectedVersion: sessionVers.version,
6529 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006530 flags: []string{
6531 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6532 },
David Benjaminece3de92015-03-16 18:02:20 -04006533 })
6534 } else {
David Benjamin405da482016-08-08 17:25:07 -04006535 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6536
6537 // Offering a TLS 1.3 session sends an empty session ID, so
6538 // there is no way to convince a non-lookahead client the
6539 // session was resumed. It will appear to the client that a
6540 // stray ChangeCipherSpec was sent.
6541 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6542 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006543 }
6544
David Benjaminece3de92015-03-16 18:02:20 -04006545 testCases = append(testCases, testCase{
6546 protocol: protocol,
6547 name: "Resume-Client-Mismatch" + suffix,
6548 resumeSession: true,
6549 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006550 MaxVersion: sessionVers.version,
6551 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006552 },
David Benjaminece3de92015-03-16 18:02:20 -04006553 expectedVersion: sessionVers.version,
6554 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006555 MaxVersion: resumeVers.version,
6556 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006557 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006558 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006559 },
6560 },
6561 expectedResumeVersion: resumeVers.version,
6562 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006563 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006564 flags: []string{
6565 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6566 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6567 },
David Benjaminece3de92015-03-16 18:02:20 -04006568 })
6569 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006570
6571 testCases = append(testCases, testCase{
6572 protocol: protocol,
6573 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006574 resumeSession: true,
6575 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006576 MaxVersion: sessionVers.version,
6577 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006578 },
6579 expectedVersion: sessionVers.version,
6580 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006581 MaxVersion: resumeVers.version,
6582 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006583 },
6584 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006585 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006586 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006587 flags: []string{
6588 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6589 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6590 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006591 })
6592
David Benjamin8b8c0062014-11-23 02:47:52 -05006593 testCases = append(testCases, testCase{
6594 protocol: protocol,
6595 testType: serverTest,
6596 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006597 resumeSession: true,
6598 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006599 MaxVersion: sessionVers.version,
6600 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006601 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006602 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006603 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006604 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: resumeVers.version,
6606 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006607 Bugs: ProtocolBugs{
6608 SendBothTickets: true,
6609 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006610 },
6611 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006612 flags: []string{
6613 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6614 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6615 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006616 })
6617 }
David Benjamin01fe8202014-09-24 15:21:44 -04006618 }
6619 }
David Benjaminece3de92015-03-16 18:02:20 -04006620
David Benjamin4199b0d2016-11-01 13:58:25 -04006621 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006622 testCases = append(testCases, testCase{
6623 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006624 name: "ShimTicketRewritable",
6625 resumeSession: true,
6626 config: Config{
6627 MaxVersion: VersionTLS12,
6628 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6629 Bugs: ProtocolBugs{
6630 FilterTicket: func(in []byte) ([]byte, error) {
6631 in, err := SetShimTicketVersion(in, VersionTLS12)
6632 if err != nil {
6633 return nil, err
6634 }
6635 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6636 },
6637 },
6638 },
6639 flags: []string{
6640 "-ticket-key",
6641 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6642 },
6643 })
6644
6645 // Resumptions are declined if the version does not match.
6646 testCases = append(testCases, testCase{
6647 testType: serverTest,
6648 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006649 resumeSession: true,
6650 config: Config{
6651 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006652 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006653 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006654 FilterTicket: func(in []byte) ([]byte, error) {
6655 return SetShimTicketVersion(in, VersionTLS13)
6656 },
6657 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006658 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006659 flags: []string{
6660 "-ticket-key",
6661 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6662 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006663 expectResumeRejected: true,
6664 })
6665
6666 testCases = append(testCases, testCase{
6667 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006668 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006669 resumeSession: true,
6670 config: Config{
6671 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006672 Bugs: ProtocolBugs{
6673 FilterTicket: func(in []byte) ([]byte, error) {
6674 return SetShimTicketVersion(in, VersionTLS12)
6675 },
6676 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006677 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006678 flags: []string{
6679 "-ticket-key",
6680 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6681 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006682 expectResumeRejected: true,
6683 })
6684
David Benjamin4199b0d2016-11-01 13:58:25 -04006685 // Resumptions are declined if the cipher is invalid or disabled.
6686 testCases = append(testCases, testCase{
6687 testType: serverTest,
6688 name: "Resume-Server-DeclineBadCipher",
6689 resumeSession: true,
6690 config: Config{
6691 MaxVersion: VersionTLS12,
6692 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006693 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006694 FilterTicket: func(in []byte) ([]byte, error) {
6695 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6696 },
6697 },
6698 },
6699 flags: []string{
6700 "-ticket-key",
6701 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6702 },
6703 expectResumeRejected: true,
6704 })
6705
6706 testCases = append(testCases, testCase{
6707 testType: serverTest,
6708 name: "Resume-Server-DeclineBadCipher-2",
6709 resumeSession: true,
6710 config: Config{
6711 MaxVersion: VersionTLS12,
6712 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006713 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006714 FilterTicket: func(in []byte) ([]byte, error) {
6715 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6716 },
6717 },
6718 },
6719 flags: []string{
6720 "-cipher", "AES128",
6721 "-ticket-key",
6722 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6723 },
6724 expectResumeRejected: true,
6725 })
6726
David Benjaminf01f42a2016-11-16 19:05:33 +09006727 // Sessions are not resumed if they do not use the preferred cipher.
6728 testCases = append(testCases, testCase{
6729 testType: serverTest,
6730 name: "Resume-Server-CipherNotPreferred",
6731 resumeSession: true,
6732 config: Config{
6733 MaxVersion: VersionTLS12,
6734 Bugs: ProtocolBugs{
6735 ExpectNewTicket: true,
6736 FilterTicket: func(in []byte) ([]byte, error) {
6737 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6738 },
6739 },
6740 },
6741 flags: []string{
6742 "-ticket-key",
6743 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6744 },
6745 shouldFail: false,
6746 expectResumeRejected: true,
6747 })
6748
6749 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6750 // PRF hashes match, but BoringSSL will always decline such resumptions.
6751 testCases = append(testCases, testCase{
6752 testType: serverTest,
6753 name: "Resume-Server-CipherNotPreferred-TLS13",
6754 resumeSession: true,
6755 config: Config{
6756 MaxVersion: VersionTLS13,
6757 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6758 Bugs: ProtocolBugs{
6759 FilterTicket: func(in []byte) ([]byte, error) {
6760 // If the client (runner) offers ChaCha20-Poly1305 first, the
6761 // server (shim) always prefers it. Switch it to AES-GCM.
6762 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6763 },
6764 },
6765 },
6766 flags: []string{
6767 "-ticket-key",
6768 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6769 },
6770 shouldFail: false,
6771 expectResumeRejected: true,
6772 })
6773
6774 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006775 testCases = append(testCases, testCase{
6776 testType: serverTest,
6777 name: "Resume-Server-DeclineBadCipher-TLS13",
6778 resumeSession: true,
6779 config: Config{
6780 MaxVersion: VersionTLS13,
6781 Bugs: ProtocolBugs{
6782 FilterTicket: func(in []byte) ([]byte, error) {
6783 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6784 },
6785 },
6786 },
6787 flags: []string{
6788 "-ticket-key",
6789 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6790 },
6791 expectResumeRejected: true,
6792 })
6793
David Benjaminf01f42a2016-11-16 19:05:33 +09006794 // If the client does not offer the cipher from the session, decline to
6795 // resume. Clients are forbidden from doing this, but BoringSSL selects
6796 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006797 testCases = append(testCases, testCase{
6798 testType: serverTest,
6799 name: "Resume-Server-UnofferedCipher",
6800 resumeSession: true,
6801 config: Config{
6802 MaxVersion: VersionTLS12,
6803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6804 },
6805 resumeConfig: &Config{
6806 MaxVersion: VersionTLS12,
6807 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6808 Bugs: ProtocolBugs{
6809 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6810 },
6811 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006812 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006813 })
6814
David Benjaminf01f42a2016-11-16 19:05:33 +09006815 // In TLS 1.3, clients may advertise a cipher list which does not
6816 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006817 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6818 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "Resume-Server-UnofferedCipher-TLS13",
6822 resumeSession: true,
6823 config: Config{
6824 MaxVersion: VersionTLS13,
6825 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6826 },
6827 resumeConfig: &Config{
6828 MaxVersion: VersionTLS13,
6829 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6830 Bugs: ProtocolBugs{
6831 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6832 },
6833 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006834 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006835 })
6836
David Benjamin4199b0d2016-11-01 13:58:25 -04006837 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006838 testCases = append(testCases, testCase{
6839 name: "Resume-Client-CipherMismatch",
6840 resumeSession: true,
6841 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006842 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006843 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6844 },
6845 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006846 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006847 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6848 Bugs: ProtocolBugs{
6849 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6850 },
6851 },
6852 shouldFail: true,
6853 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6854 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006855
David Benjamine1cc35e2016-11-16 16:25:58 +09006856 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6857 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006858 testCases = append(testCases, testCase{
6859 name: "Resume-Client-CipherMismatch-TLS13",
6860 resumeSession: true,
6861 config: Config{
6862 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006863 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006864 },
6865 resumeConfig: &Config{
6866 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006867 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6868 },
6869 })
6870
6871 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6872 testCases = append(testCases, testCase{
6873 name: "Resume-Client-PRFMismatch-TLS13",
6874 resumeSession: true,
6875 config: Config{
6876 MaxVersion: VersionTLS13,
6877 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6878 },
6879 resumeConfig: &Config{
6880 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006881 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006882 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006883 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006884 },
6885 },
6886 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006887 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006888 })
Steven Valdeza833c352016-11-01 13:39:36 -04006889
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: "Resume-Server-BinderWrongLength",
6893 resumeSession: true,
6894 config: Config{
6895 MaxVersion: VersionTLS13,
6896 Bugs: ProtocolBugs{
6897 SendShortPSKBinder: true,
6898 },
6899 },
6900 shouldFail: true,
6901 expectedLocalError: "remote error: error decrypting message",
6902 expectedError: ":DIGEST_CHECK_FAILED:",
6903 })
6904
6905 testCases = append(testCases, testCase{
6906 testType: serverTest,
6907 name: "Resume-Server-NoPSKBinder",
6908 resumeSession: true,
6909 config: Config{
6910 MaxVersion: VersionTLS13,
6911 Bugs: ProtocolBugs{
6912 SendNoPSKBinder: true,
6913 },
6914 },
6915 shouldFail: true,
6916 expectedLocalError: "remote error: error decoding message",
6917 expectedError: ":DECODE_ERROR:",
6918 })
6919
6920 testCases = append(testCases, testCase{
6921 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006922 name: "Resume-Server-ExtraPSKBinder",
6923 resumeSession: true,
6924 config: Config{
6925 MaxVersion: VersionTLS13,
6926 Bugs: ProtocolBugs{
6927 SendExtraPSKBinder: true,
6928 },
6929 },
6930 shouldFail: true,
6931 expectedLocalError: "remote error: illegal parameter",
6932 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6933 })
6934
6935 testCases = append(testCases, testCase{
6936 testType: serverTest,
6937 name: "Resume-Server-ExtraIdentityNoBinder",
6938 resumeSession: true,
6939 config: Config{
6940 MaxVersion: VersionTLS13,
6941 Bugs: ProtocolBugs{
6942 ExtraPSKIdentity: true,
6943 },
6944 },
6945 shouldFail: true,
6946 expectedLocalError: "remote error: illegal parameter",
6947 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6948 })
6949
6950 testCases = append(testCases, testCase{
6951 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006952 name: "Resume-Server-InvalidPSKBinder",
6953 resumeSession: true,
6954 config: Config{
6955 MaxVersion: VersionTLS13,
6956 Bugs: ProtocolBugs{
6957 SendInvalidPSKBinder: true,
6958 },
6959 },
6960 shouldFail: true,
6961 expectedLocalError: "remote error: error decrypting message",
6962 expectedError: ":DIGEST_CHECK_FAILED:",
6963 })
6964
6965 testCases = append(testCases, testCase{
6966 testType: serverTest,
6967 name: "Resume-Server-PSKBinderFirstExtension",
6968 resumeSession: true,
6969 config: Config{
6970 MaxVersion: VersionTLS13,
6971 Bugs: ProtocolBugs{
6972 PSKBinderFirst: true,
6973 },
6974 },
6975 shouldFail: true,
6976 expectedLocalError: "remote error: illegal parameter",
6977 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6978 })
David Benjamin01fe8202014-09-24 15:21:44 -04006979}
6980
Adam Langley2ae77d22014-10-28 17:29:33 -07006981func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006982 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006983 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006984 testType: serverTest,
6985 name: "Renegotiate-Server-Forbidden",
6986 config: Config{
6987 MaxVersion: VersionTLS12,
6988 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006989 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006990 shouldFail: true,
6991 expectedError: ":NO_RENEGOTIATION:",
6992 expectedLocalError: "remote error: no renegotiation",
6993 })
Adam Langley5021b222015-06-12 18:27:58 -07006994 // The server shouldn't echo the renegotiation extension unless
6995 // requested by the client.
6996 testCases = append(testCases, testCase{
6997 testType: serverTest,
6998 name: "Renegotiate-Server-NoExt",
6999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007001 Bugs: ProtocolBugs{
7002 NoRenegotiationInfo: true,
7003 RequireRenegotiationInfo: true,
7004 },
7005 },
7006 shouldFail: true,
7007 expectedLocalError: "renegotiation extension missing",
7008 })
7009 // The renegotiation SCSV should be sufficient for the server to echo
7010 // the extension.
7011 testCases = append(testCases, testCase{
7012 testType: serverTest,
7013 name: "Renegotiate-Server-NoExt-SCSV",
7014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007015 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007016 Bugs: ProtocolBugs{
7017 NoRenegotiationInfo: true,
7018 SendRenegotiationSCSV: true,
7019 RequireRenegotiationInfo: true,
7020 },
7021 },
7022 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007023 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007024 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007026 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007027 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007028 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007029 },
7030 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007031 renegotiate: 1,
7032 flags: []string{
7033 "-renegotiate-freely",
7034 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007035 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007036 },
David Benjamincdea40c2015-03-19 14:09:43 -04007037 })
7038 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007039 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007040 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007042 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007043 Bugs: ProtocolBugs{
7044 EmptyRenegotiationInfo: true,
7045 },
7046 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007047 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007048 shouldFail: true,
7049 expectedError: ":RENEGOTIATION_MISMATCH:",
7050 })
7051 testCases = append(testCases, testCase{
7052 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007053 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007055 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007056 Bugs: ProtocolBugs{
7057 BadRenegotiationInfo: true,
7058 },
7059 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007060 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007061 shouldFail: true,
7062 expectedError: ":RENEGOTIATION_MISMATCH:",
7063 })
7064 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007065 name: "Renegotiate-Client-BadExt2",
7066 renegotiate: 1,
7067 config: Config{
7068 MaxVersion: VersionTLS12,
7069 Bugs: ProtocolBugs{
7070 BadRenegotiationInfoEnd: true,
7071 },
7072 },
7073 flags: []string{"-renegotiate-freely"},
7074 shouldFail: true,
7075 expectedError: ":RENEGOTIATION_MISMATCH:",
7076 })
7077 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007078 name: "Renegotiate-Client-Downgrade",
7079 renegotiate: 1,
7080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007081 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007082 Bugs: ProtocolBugs{
7083 NoRenegotiationInfoAfterInitial: true,
7084 },
7085 },
7086 flags: []string{"-renegotiate-freely"},
7087 shouldFail: true,
7088 expectedError: ":RENEGOTIATION_MISMATCH:",
7089 })
7090 testCases = append(testCases, testCase{
7091 name: "Renegotiate-Client-Upgrade",
7092 renegotiate: 1,
7093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007094 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007095 Bugs: ProtocolBugs{
7096 NoRenegotiationInfoInInitial: true,
7097 },
7098 },
7099 flags: []string{"-renegotiate-freely"},
7100 shouldFail: true,
7101 expectedError: ":RENEGOTIATION_MISMATCH:",
7102 })
7103 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007104 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007105 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007107 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007108 Bugs: ProtocolBugs{
7109 NoRenegotiationInfo: true,
7110 },
7111 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007112 flags: []string{
7113 "-renegotiate-freely",
7114 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007115 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007116 },
David Benjamincff0b902015-05-15 23:09:47 -04007117 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007118
7119 // Test that the server may switch ciphers on renegotiation without
7120 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007121 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007122 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007123 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007124 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007125 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007126 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 },
7128 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007129 flags: []string{
7130 "-renegotiate-freely",
7131 "-expect-total-renegotiations", "1",
7132 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007133 })
7134 testCases = append(testCases, testCase{
7135 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007136 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007137 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007138 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007139 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7140 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007141 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007142 flags: []string{
7143 "-renegotiate-freely",
7144 "-expect-total-renegotiations", "1",
7145 },
David Benjaminb16346b2015-04-08 19:16:58 -04007146 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007147
7148 // Test that the server may not switch versions on renegotiation.
7149 testCases = append(testCases, testCase{
7150 name: "Renegotiate-Client-SwitchVersion",
7151 config: Config{
7152 MaxVersion: VersionTLS12,
7153 // Pick a cipher which exists at both versions.
7154 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7155 Bugs: ProtocolBugs{
7156 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007157 // Avoid failing early at the record layer.
7158 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007159 },
7160 },
7161 renegotiate: 1,
7162 flags: []string{
7163 "-renegotiate-freely",
7164 "-expect-total-renegotiations", "1",
7165 },
7166 shouldFail: true,
7167 expectedError: ":WRONG_SSL_VERSION:",
7168 })
7169
David Benjaminb16346b2015-04-08 19:16:58 -04007170 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007171 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007172 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007173 config: Config{
7174 MaxVersion: VersionTLS10,
7175 Bugs: ProtocolBugs{
7176 RequireSameRenegoClientVersion: true,
7177 },
7178 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007179 flags: []string{
7180 "-renegotiate-freely",
7181 "-expect-total-renegotiations", "1",
7182 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007183 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007184 testCases = append(testCases, testCase{
7185 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007186 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007187 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007188 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007189 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7190 NextProtos: []string{"foo"},
7191 },
7192 flags: []string{
7193 "-false-start",
7194 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007195 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007196 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007197 },
7198 shimWritesFirst: true,
7199 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007200
7201 // Client-side renegotiation controls.
7202 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007203 name: "Renegotiate-Client-Forbidden-1",
7204 config: Config{
7205 MaxVersion: VersionTLS12,
7206 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007207 renegotiate: 1,
7208 shouldFail: true,
7209 expectedError: ":NO_RENEGOTIATION:",
7210 expectedLocalError: "remote error: no renegotiation",
7211 })
7212 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007213 name: "Renegotiate-Client-Once-1",
7214 config: Config{
7215 MaxVersion: VersionTLS12,
7216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007217 renegotiate: 1,
7218 flags: []string{
7219 "-renegotiate-once",
7220 "-expect-total-renegotiations", "1",
7221 },
7222 })
7223 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007224 name: "Renegotiate-Client-Freely-1",
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007228 renegotiate: 1,
7229 flags: []string{
7230 "-renegotiate-freely",
7231 "-expect-total-renegotiations", "1",
7232 },
7233 })
7234 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007235 name: "Renegotiate-Client-Once-2",
7236 config: Config{
7237 MaxVersion: VersionTLS12,
7238 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007239 renegotiate: 2,
7240 flags: []string{"-renegotiate-once"},
7241 shouldFail: true,
7242 expectedError: ":NO_RENEGOTIATION:",
7243 expectedLocalError: "remote error: no renegotiation",
7244 })
7245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007246 name: "Renegotiate-Client-Freely-2",
7247 config: Config{
7248 MaxVersion: VersionTLS12,
7249 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007250 renegotiate: 2,
7251 flags: []string{
7252 "-renegotiate-freely",
7253 "-expect-total-renegotiations", "2",
7254 },
7255 })
Adam Langley27a0d082015-11-03 13:34:10 -08007256 testCases = append(testCases, testCase{
7257 name: "Renegotiate-Client-NoIgnore",
7258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007259 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007260 Bugs: ProtocolBugs{
7261 SendHelloRequestBeforeEveryAppDataRecord: true,
7262 },
7263 },
7264 shouldFail: true,
7265 expectedError: ":NO_RENEGOTIATION:",
7266 })
7267 testCases = append(testCases, testCase{
7268 name: "Renegotiate-Client-Ignore",
7269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007270 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007271 Bugs: ProtocolBugs{
7272 SendHelloRequestBeforeEveryAppDataRecord: true,
7273 },
7274 },
7275 flags: []string{
7276 "-renegotiate-ignore",
7277 "-expect-total-renegotiations", "0",
7278 },
7279 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007280
David Benjamin34941c02016-10-08 11:45:31 -04007281 // Renegotiation is not allowed at SSL 3.0.
7282 testCases = append(testCases, testCase{
7283 name: "Renegotiate-Client-SSL3",
7284 config: Config{
7285 MaxVersion: VersionSSL30,
7286 },
7287 renegotiate: 1,
7288 flags: []string{
7289 "-renegotiate-freely",
7290 "-expect-total-renegotiations", "1",
7291 },
7292 shouldFail: true,
7293 expectedError: ":NO_RENEGOTIATION:",
7294 expectedLocalError: "remote error: no renegotiation",
7295 })
7296
David Benjamina1eaba12017-01-01 23:19:22 -05007297 // Renegotiation is not allowed when there is an unfinished write.
7298 testCases = append(testCases, testCase{
7299 name: "Renegotiate-Client-UnfinishedWrite",
7300 config: Config{
7301 MaxVersion: VersionTLS12,
7302 },
David Benjaminbbba9392017-04-06 12:54:12 -04007303 renegotiate: 1,
7304 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007305 flags: []string{
7306 "-async",
7307 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007308 },
7309 shouldFail: true,
7310 expectedError: ":NO_RENEGOTIATION:",
7311 // We do not successfully send the no_renegotiation alert in
7312 // this case. https://crbug.com/boringssl/130
7313 })
7314
David Benjamin07ab5d42017-02-09 20:11:41 -05007315 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007316 testCases = append(testCases, testCase{
7317 name: "StrayHelloRequest",
7318 config: Config{
7319 MaxVersion: VersionTLS12,
7320 Bugs: ProtocolBugs{
7321 SendHelloRequestBeforeEveryHandshakeMessage: true,
7322 },
7323 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007324 shouldFail: true,
7325 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007326 })
7327 testCases = append(testCases, testCase{
7328 name: "StrayHelloRequest-Packed",
7329 config: Config{
7330 MaxVersion: VersionTLS12,
7331 Bugs: ProtocolBugs{
7332 PackHandshakeFlight: true,
7333 SendHelloRequestBeforeEveryHandshakeMessage: true,
7334 },
7335 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007336 shouldFail: true,
7337 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007338 })
7339
David Benjamin12d2c482016-07-24 10:56:51 -04007340 // Test renegotiation works if HelloRequest and server Finished come in
7341 // the same record.
7342 testCases = append(testCases, testCase{
7343 name: "Renegotiate-Client-Packed",
7344 config: Config{
7345 MaxVersion: VersionTLS12,
7346 Bugs: ProtocolBugs{
7347 PackHandshakeFlight: true,
7348 PackHelloRequestWithFinished: true,
7349 },
7350 },
7351 renegotiate: 1,
7352 flags: []string{
7353 "-renegotiate-freely",
7354 "-expect-total-renegotiations", "1",
7355 },
7356 })
7357
David Benjamin397c8e62016-07-08 14:14:36 -07007358 // Renegotiation is forbidden in TLS 1.3.
7359 testCases = append(testCases, testCase{
7360 name: "Renegotiate-Client-TLS13",
7361 config: Config{
7362 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007363 Bugs: ProtocolBugs{
7364 SendHelloRequestBeforeEveryAppDataRecord: true,
7365 },
David Benjamin397c8e62016-07-08 14:14:36 -07007366 },
David Benjamin397c8e62016-07-08 14:14:36 -07007367 flags: []string{
7368 "-renegotiate-freely",
7369 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007370 shouldFail: true,
7371 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007372 })
7373
7374 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7375 testCases = append(testCases, testCase{
7376 name: "StrayHelloRequest-TLS13",
7377 config: Config{
7378 MaxVersion: VersionTLS13,
7379 Bugs: ProtocolBugs{
7380 SendHelloRequestBeforeEveryHandshakeMessage: true,
7381 },
7382 },
7383 shouldFail: true,
7384 expectedError: ":UNEXPECTED_MESSAGE:",
7385 })
David Benjamind2610042017-01-03 10:49:28 -05007386
7387 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7388 // always reads as supporting it, regardless of whether it was
7389 // negotiated.
7390 testCases = append(testCases, testCase{
7391 name: "AlwaysReportRenegotiationInfo-TLS13",
7392 config: Config{
7393 MaxVersion: VersionTLS13,
7394 Bugs: ProtocolBugs{
7395 NoRenegotiationInfo: true,
7396 },
7397 },
7398 flags: []string{
7399 "-expect-secure-renegotiation",
7400 },
7401 })
David Benjamina58baaf2017-02-28 20:54:28 -05007402
7403 // Certificates may not change on renegotiation.
7404 testCases = append(testCases, testCase{
7405 name: "Renegotiation-CertificateChange",
7406 config: Config{
7407 MaxVersion: VersionTLS12,
7408 Certificates: []Certificate{rsaCertificate},
7409 Bugs: ProtocolBugs{
7410 RenegotiationCertificate: &rsaChainCertificate,
7411 },
7412 },
7413 renegotiate: 1,
7414 flags: []string{"-renegotiate-freely"},
7415 shouldFail: true,
7416 expectedError: ":SERVER_CERT_CHANGED:",
7417 })
7418 testCases = append(testCases, testCase{
7419 name: "Renegotiation-CertificateChange-2",
7420 config: Config{
7421 MaxVersion: VersionTLS12,
7422 Certificates: []Certificate{rsaCertificate},
7423 Bugs: ProtocolBugs{
7424 RenegotiationCertificate: &rsa1024Certificate,
7425 },
7426 },
7427 renegotiate: 1,
7428 flags: []string{"-renegotiate-freely"},
7429 shouldFail: true,
7430 expectedError: ":SERVER_CERT_CHANGED:",
7431 })
David Benjaminbbf42462017-03-14 21:27:10 -04007432
7433 // We do not negotiate ALPN after the initial handshake. This is
7434 // error-prone and only risks bugs in consumers.
7435 testCases = append(testCases, testCase{
7436 testType: clientTest,
7437 name: "Renegotiation-ForbidALPN",
7438 config: Config{
7439 MaxVersion: VersionTLS12,
7440 Bugs: ProtocolBugs{
7441 // Forcibly negotiate ALPN on both initial and
7442 // renegotiation handshakes. The test stack will
7443 // internally check the client does not offer
7444 // it.
7445 SendALPN: "foo",
7446 },
7447 },
7448 flags: []string{
7449 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7450 "-expect-alpn", "foo",
7451 "-renegotiate-freely",
7452 },
7453 renegotiate: 1,
7454 shouldFail: true,
7455 expectedError: ":UNEXPECTED_EXTENSION:",
7456 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007457}
7458
David Benjamin5e961c12014-11-07 01:48:35 -05007459func addDTLSReplayTests() {
7460 // Test that sequence number replays are detected.
7461 testCases = append(testCases, testCase{
7462 protocol: dtls,
7463 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007464 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007465 replayWrites: true,
7466 })
7467
David Benjamin8e6db492015-07-25 18:29:23 -04007468 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007469 // than the retransmit window.
7470 testCases = append(testCases, testCase{
7471 protocol: dtls,
7472 name: "DTLS-Replay-LargeGaps",
7473 config: Config{
7474 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007475 SequenceNumberMapping: func(in uint64) uint64 {
7476 return in * 127
7477 },
David Benjamin5e961c12014-11-07 01:48:35 -05007478 },
7479 },
David Benjamin8e6db492015-07-25 18:29:23 -04007480 messageCount: 200,
7481 replayWrites: true,
7482 })
7483
7484 // Test the incoming sequence number changing non-monotonically.
7485 testCases = append(testCases, testCase{
7486 protocol: dtls,
7487 name: "DTLS-Replay-NonMonotonic",
7488 config: Config{
7489 Bugs: ProtocolBugs{
7490 SequenceNumberMapping: func(in uint64) uint64 {
7491 return in ^ 31
7492 },
7493 },
7494 },
7495 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007496 replayWrites: true,
7497 })
7498}
7499
Nick Harper60edffd2016-06-21 15:19:24 -07007500var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007501 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007502 id signatureAlgorithm
7503 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007504}{
Nick Harper60edffd2016-06-21 15:19:24 -07007505 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7506 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7507 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7508 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007509 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007510 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7511 // hash function doesn't have to match the curve and so the same
7512 // signature algorithm works with P-224.
7513 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007514 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7515 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7516 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007517 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7518 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7519 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007520 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007521 // Tests for key types prior to TLS 1.2.
7522 {"RSA", 0, testCertRSA},
7523 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007524}
7525
Nick Harper60edffd2016-06-21 15:19:24 -07007526const fakeSigAlg1 signatureAlgorithm = 0x2a01
7527const fakeSigAlg2 signatureAlgorithm = 0xff01
7528
7529func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007530 // Not all ciphers involve a signature. Advertise a list which gives all
7531 // versions a signing cipher.
7532 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007533 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007534 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7535 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7536 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7537 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007538 }
David Benjamin5208fd42016-07-13 21:43:25 -04007539
David Benjaminca3d5452016-07-14 12:51:01 -04007540 var allAlgorithms []signatureAlgorithm
7541 for _, alg := range testSignatureAlgorithms {
7542 if alg.id != 0 {
7543 allAlgorithms = append(allAlgorithms, alg.id)
7544 }
7545 }
7546
Nick Harper60edffd2016-06-21 15:19:24 -07007547 // Make sure each signature algorithm works. Include some fake values in
7548 // the list and ensure they're ignored.
7549 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007550 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007551 if (ver.version < VersionTLS12) != (alg.id == 0) {
7552 continue
7553 }
7554
7555 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7556 // or remove it in C.
7557 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007558 continue
7559 }
Nick Harper60edffd2016-06-21 15:19:24 -07007560
David Benjamin3ef76972016-10-17 17:59:54 -04007561 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007562 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007563 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007564 shouldSignFail = true
7565 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007566 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007567 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007568 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7569 shouldSignFail = true
7570 shouldVerifyFail = true
7571 }
7572 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7573 // the curve has to match the hash size.
7574 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007575 shouldSignFail = true
7576 shouldVerifyFail = true
7577 }
7578
7579 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7580 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7581 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007582 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007583
7584 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007585 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007586 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007587 }
7588 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007589 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007590 }
David Benjamin000800a2014-11-14 01:43:59 -05007591
David Benjamin1fb125c2016-07-08 18:52:12 -07007592 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007593
David Benjamin7a41d372016-07-09 11:21:54 -07007594 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007595 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007596 config: Config{
7597 MaxVersion: ver.version,
7598 ClientAuth: RequireAnyClientCert,
7599 VerifySignatureAlgorithms: []signatureAlgorithm{
7600 fakeSigAlg1,
7601 alg.id,
7602 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007603 },
David Benjamin7a41d372016-07-09 11:21:54 -07007604 },
7605 flags: []string{
7606 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7607 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7608 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007609 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007610 },
David Benjamina5022392017-07-10 17:40:39 -04007611 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007612 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007613 expectedError: signError,
7614 expectedPeerSignatureAlgorithm: alg.id,
7615 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007616
David Benjamin7a41d372016-07-09 11:21:54 -07007617 testCases = append(testCases, testCase{
7618 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007619 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007620 config: Config{
7621 MaxVersion: ver.version,
7622 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7623 SignSignatureAlgorithms: []signatureAlgorithm{
7624 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007625 },
David Benjamin7a41d372016-07-09 11:21:54 -07007626 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007627 SkipECDSACurveCheck: shouldVerifyFail,
7628 IgnoreSignatureVersionChecks: shouldVerifyFail,
7629 // Some signature algorithms may not be advertised.
7630 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007631 },
David Benjamin7a41d372016-07-09 11:21:54 -07007632 },
David Benjamina5022392017-07-10 17:40:39 -04007633 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007634 flags: []string{
7635 "-require-any-client-certificate",
7636 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7637 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007638 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007639 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007640 // Resume the session to assert the peer signature
7641 // algorithm is reported on both handshakes.
7642 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007643 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007644 expectedError: verifyError,
7645 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007646
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007647 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007648 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007649 testCases = append(testCases, testCase{
7650 testType: serverTest,
7651 name: "ServerAuth-Sign" + suffix,
7652 config: Config{
7653 MaxVersion: ver.version,
7654 CipherSuites: signingCiphers,
7655 VerifySignatureAlgorithms: []signatureAlgorithm{
7656 fakeSigAlg1,
7657 alg.id,
7658 fakeSigAlg2,
7659 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007660 },
David Benjamina5022392017-07-10 17:40:39 -04007661 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007662 flags: []string{
7663 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7664 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7665 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007666 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007667 },
7668 shouldFail: shouldSignFail,
7669 expectedError: signError,
7670 expectedPeerSignatureAlgorithm: alg.id,
7671 })
7672 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007673
7674 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007675 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007676 config: Config{
7677 MaxVersion: ver.version,
7678 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007679 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007680 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 alg.id,
7682 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007683 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007684 SkipECDSACurveCheck: shouldVerifyFail,
7685 IgnoreSignatureVersionChecks: shouldVerifyFail,
7686 // Some signature algorithms may not be advertised.
7687 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007688 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007689 },
David Benjamina5022392017-07-10 17:40:39 -04007690 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007691 flags: []string{
7692 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7693 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007694 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007695 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007696 // Resume the session to assert the peer signature
7697 // algorithm is reported on both handshakes.
7698 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007699 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007700 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007701 })
David Benjamin5208fd42016-07-13 21:43:25 -04007702
David Benjamin3ef76972016-10-17 17:59:54 -04007703 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007704 testCases = append(testCases, testCase{
7705 testType: serverTest,
7706 name: "ClientAuth-InvalidSignature" + suffix,
7707 config: Config{
7708 MaxVersion: ver.version,
7709 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7710 SignSignatureAlgorithms: []signatureAlgorithm{
7711 alg.id,
7712 },
7713 Bugs: ProtocolBugs{
7714 InvalidSignature: true,
7715 },
7716 },
David Benjamina5022392017-07-10 17:40:39 -04007717 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007718 flags: []string{
7719 "-require-any-client-certificate",
7720 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007721 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007722 },
7723 shouldFail: true,
7724 expectedError: ":BAD_SIGNATURE:",
7725 })
7726
7727 testCases = append(testCases, testCase{
7728 name: "ServerAuth-InvalidSignature" + suffix,
7729 config: Config{
7730 MaxVersion: ver.version,
7731 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7732 CipherSuites: signingCiphers,
7733 SignSignatureAlgorithms: []signatureAlgorithm{
7734 alg.id,
7735 },
7736 Bugs: ProtocolBugs{
7737 InvalidSignature: true,
7738 },
7739 },
David Benjamina5022392017-07-10 17:40:39 -04007740 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007741 flags: []string{
7742 "-enable-all-curves",
7743 "-enable-ed25519",
7744 },
David Benjamin5208fd42016-07-13 21:43:25 -04007745 shouldFail: true,
7746 expectedError: ":BAD_SIGNATURE:",
7747 })
7748 }
David Benjaminca3d5452016-07-14 12:51:01 -04007749
David Benjamin3ef76972016-10-17 17:59:54 -04007750 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007751 testCases = append(testCases, testCase{
7752 name: "ClientAuth-Sign-Negotiate" + suffix,
7753 config: Config{
7754 MaxVersion: ver.version,
7755 ClientAuth: RequireAnyClientCert,
7756 VerifySignatureAlgorithms: allAlgorithms,
7757 },
David Benjamina5022392017-07-10 17:40:39 -04007758 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007759 flags: []string{
7760 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7761 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7762 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007763 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007764 "-signing-prefs", strconv.Itoa(int(alg.id)),
7765 },
7766 expectedPeerSignatureAlgorithm: alg.id,
7767 })
7768
7769 testCases = append(testCases, testCase{
7770 testType: serverTest,
7771 name: "ServerAuth-Sign-Negotiate" + suffix,
7772 config: Config{
7773 MaxVersion: ver.version,
7774 CipherSuites: signingCiphers,
7775 VerifySignatureAlgorithms: allAlgorithms,
7776 },
David Benjamina5022392017-07-10 17:40:39 -04007777 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007778 flags: []string{
7779 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7780 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7781 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007782 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007783 "-signing-prefs", strconv.Itoa(int(alg.id)),
7784 },
7785 expectedPeerSignatureAlgorithm: alg.id,
7786 })
7787 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007788 }
David Benjamin000800a2014-11-14 01:43:59 -05007789 }
7790
Nick Harper60edffd2016-06-21 15:19:24 -07007791 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007792 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007793 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007794 config: Config{
7795 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007796 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007797 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007798 signatureECDSAWithP521AndSHA512,
7799 signatureRSAPKCS1WithSHA384,
7800 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007801 },
7802 },
7803 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007804 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7805 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007806 },
Nick Harper60edffd2016-06-21 15:19:24 -07007807 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007808 })
7809
7810 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007811 name: "ClientAuth-SignatureType-TLS13",
7812 config: Config{
7813 ClientAuth: RequireAnyClientCert,
7814 MaxVersion: VersionTLS13,
7815 VerifySignatureAlgorithms: []signatureAlgorithm{
7816 signatureECDSAWithP521AndSHA512,
7817 signatureRSAPKCS1WithSHA384,
7818 signatureRSAPSSWithSHA384,
7819 signatureECDSAWithSHA1,
7820 },
7821 },
7822 flags: []string{
7823 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7824 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7825 },
7826 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7827 })
7828
7829 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007830 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007831 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007832 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007833 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007834 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007835 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007836 signatureECDSAWithP521AndSHA512,
7837 signatureRSAPKCS1WithSHA384,
7838 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007839 },
7840 },
Nick Harper60edffd2016-06-21 15:19:24 -07007841 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007842 })
7843
Steven Valdez143e8b32016-07-11 13:19:03 -04007844 testCases = append(testCases, testCase{
7845 testType: serverTest,
7846 name: "ServerAuth-SignatureType-TLS13",
7847 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007848 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007849 VerifySignatureAlgorithms: []signatureAlgorithm{
7850 signatureECDSAWithP521AndSHA512,
7851 signatureRSAPKCS1WithSHA384,
7852 signatureRSAPSSWithSHA384,
7853 signatureECDSAWithSHA1,
7854 },
7855 },
7856 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7857 })
7858
David Benjamina95e9f32016-07-08 16:28:04 -07007859 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007860 testCases = append(testCases, testCase{
7861 testType: serverTest,
7862 name: "Verify-ClientAuth-SignatureType",
7863 config: Config{
7864 MaxVersion: VersionTLS12,
7865 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007866 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007867 signatureRSAPKCS1WithSHA256,
7868 },
7869 Bugs: ProtocolBugs{
7870 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7871 },
7872 },
7873 flags: []string{
7874 "-require-any-client-certificate",
7875 },
7876 shouldFail: true,
7877 expectedError: ":WRONG_SIGNATURE_TYPE:",
7878 })
7879
7880 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007881 testType: serverTest,
7882 name: "Verify-ClientAuth-SignatureType-TLS13",
7883 config: Config{
7884 MaxVersion: VersionTLS13,
7885 Certificates: []Certificate{rsaCertificate},
7886 SignSignatureAlgorithms: []signatureAlgorithm{
7887 signatureRSAPSSWithSHA256,
7888 },
7889 Bugs: ProtocolBugs{
7890 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7891 },
7892 },
7893 flags: []string{
7894 "-require-any-client-certificate",
7895 },
7896 shouldFail: true,
7897 expectedError: ":WRONG_SIGNATURE_TYPE:",
7898 })
7899
7900 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007901 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007902 config: Config{
7903 MaxVersion: VersionTLS12,
7904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007905 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007906 signatureRSAPKCS1WithSHA256,
7907 },
7908 Bugs: ProtocolBugs{
7909 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7910 },
7911 },
7912 shouldFail: true,
7913 expectedError: ":WRONG_SIGNATURE_TYPE:",
7914 })
7915
Steven Valdez143e8b32016-07-11 13:19:03 -04007916 testCases = append(testCases, testCase{
7917 name: "Verify-ServerAuth-SignatureType-TLS13",
7918 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007919 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007920 SignSignatureAlgorithms: []signatureAlgorithm{
7921 signatureRSAPSSWithSHA256,
7922 },
7923 Bugs: ProtocolBugs{
7924 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7925 },
7926 },
7927 shouldFail: true,
7928 expectedError: ":WRONG_SIGNATURE_TYPE:",
7929 })
7930
David Benjamin51dd7d62016-07-08 16:07:01 -07007931 // Test that, if the list is missing, the peer falls back to SHA-1 in
7932 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007933 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007934 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007936 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007937 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007938 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007939 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007940 },
7941 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007942 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007943 },
7944 },
7945 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007946 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7947 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007948 },
7949 })
7950
7951 testCases = append(testCases, testCase{
7952 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007953 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007954 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007955 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007956 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007957 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007958 },
7959 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007960 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007961 },
7962 },
David Benjaminee32bea2016-08-17 13:36:44 -04007963 flags: []string{
7964 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7965 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7966 },
7967 })
7968
7969 testCases = append(testCases, testCase{
7970 name: "ClientAuth-SHA1-Fallback-ECDSA",
7971 config: Config{
7972 MaxVersion: VersionTLS12,
7973 ClientAuth: RequireAnyClientCert,
7974 VerifySignatureAlgorithms: []signatureAlgorithm{
7975 signatureECDSAWithSHA1,
7976 },
7977 Bugs: ProtocolBugs{
7978 NoSignatureAlgorithms: true,
7979 },
7980 },
7981 flags: []string{
7982 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7983 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7984 },
7985 })
7986
7987 testCases = append(testCases, testCase{
7988 testType: serverTest,
7989 name: "ServerAuth-SHA1-Fallback-ECDSA",
7990 config: Config{
7991 MaxVersion: VersionTLS12,
7992 VerifySignatureAlgorithms: []signatureAlgorithm{
7993 signatureECDSAWithSHA1,
7994 },
7995 Bugs: ProtocolBugs{
7996 NoSignatureAlgorithms: true,
7997 },
7998 },
7999 flags: []string{
8000 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8001 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8002 },
David Benjamin000800a2014-11-14 01:43:59 -05008003 })
David Benjamin72dc7832015-03-16 17:49:43 -04008004
David Benjamin51dd7d62016-07-08 16:07:01 -07008005 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008006 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008007 config: Config{
8008 MaxVersion: VersionTLS13,
8009 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008010 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008011 signatureRSAPKCS1WithSHA1,
8012 },
8013 Bugs: ProtocolBugs{
8014 NoSignatureAlgorithms: true,
8015 },
8016 },
8017 flags: []string{
8018 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8019 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8020 },
David Benjamin48901652016-08-01 12:12:47 -04008021 shouldFail: true,
8022 // An empty CertificateRequest signature algorithm list is a
8023 // syntax error in TLS 1.3.
8024 expectedError: ":DECODE_ERROR:",
8025 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008026 })
8027
8028 testCases = append(testCases, testCase{
8029 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008030 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008031 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008032 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008033 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008034 signatureRSAPKCS1WithSHA1,
8035 },
8036 Bugs: ProtocolBugs{
8037 NoSignatureAlgorithms: true,
8038 },
8039 },
8040 shouldFail: true,
8041 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8042 })
8043
David Benjaminb62d2872016-07-18 14:55:02 +02008044 // Test that hash preferences are enforced. BoringSSL does not implement
8045 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008046 testCases = append(testCases, testCase{
8047 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008048 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008050 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008051 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008052 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008053 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008054 },
8055 Bugs: ProtocolBugs{
8056 IgnorePeerSignatureAlgorithmPreferences: true,
8057 },
8058 },
8059 flags: []string{"-require-any-client-certificate"},
8060 shouldFail: true,
8061 expectedError: ":WRONG_SIGNATURE_TYPE:",
8062 })
8063
8064 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008065 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008067 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008069 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008070 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008071 },
8072 Bugs: ProtocolBugs{
8073 IgnorePeerSignatureAlgorithmPreferences: true,
8074 },
8075 },
8076 shouldFail: true,
8077 expectedError: ":WRONG_SIGNATURE_TYPE:",
8078 })
David Benjaminb62d2872016-07-18 14:55:02 +02008079 testCases = append(testCases, testCase{
8080 testType: serverTest,
8081 name: "ClientAuth-Enforced-TLS13",
8082 config: Config{
8083 MaxVersion: VersionTLS13,
8084 Certificates: []Certificate{rsaCertificate},
8085 SignSignatureAlgorithms: []signatureAlgorithm{
8086 signatureRSAPKCS1WithMD5,
8087 },
8088 Bugs: ProtocolBugs{
8089 IgnorePeerSignatureAlgorithmPreferences: true,
8090 IgnoreSignatureVersionChecks: true,
8091 },
8092 },
8093 flags: []string{"-require-any-client-certificate"},
8094 shouldFail: true,
8095 expectedError: ":WRONG_SIGNATURE_TYPE:",
8096 })
8097
8098 testCases = append(testCases, testCase{
8099 name: "ServerAuth-Enforced-TLS13",
8100 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008101 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008102 SignSignatureAlgorithms: []signatureAlgorithm{
8103 signatureRSAPKCS1WithMD5,
8104 },
8105 Bugs: ProtocolBugs{
8106 IgnorePeerSignatureAlgorithmPreferences: true,
8107 IgnoreSignatureVersionChecks: true,
8108 },
8109 },
8110 shouldFail: true,
8111 expectedError: ":WRONG_SIGNATURE_TYPE:",
8112 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008113
8114 // Test that the agreed upon digest respects the client preferences and
8115 // the server digests.
8116 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008117 name: "NoCommonAlgorithms-Digests",
8118 config: Config{
8119 MaxVersion: VersionTLS12,
8120 ClientAuth: RequireAnyClientCert,
8121 VerifySignatureAlgorithms: []signatureAlgorithm{
8122 signatureRSAPKCS1WithSHA512,
8123 signatureRSAPKCS1WithSHA1,
8124 },
8125 },
8126 flags: []string{
8127 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8128 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8129 "-digest-prefs", "SHA256",
8130 },
8131 shouldFail: true,
8132 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8133 })
8134 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008135 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008137 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008138 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008139 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008140 signatureRSAPKCS1WithSHA512,
8141 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008142 },
8143 },
8144 flags: []string{
8145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008147 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008148 },
David Benjaminca3d5452016-07-14 12:51:01 -04008149 shouldFail: true,
8150 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8151 })
8152 testCases = append(testCases, testCase{
8153 name: "NoCommonAlgorithms-TLS13",
8154 config: Config{
8155 MaxVersion: VersionTLS13,
8156 ClientAuth: RequireAnyClientCert,
8157 VerifySignatureAlgorithms: []signatureAlgorithm{
8158 signatureRSAPSSWithSHA512,
8159 signatureRSAPSSWithSHA384,
8160 },
8161 },
8162 flags: []string{
8163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8165 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8166 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008167 shouldFail: true,
8168 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008169 })
8170 testCases = append(testCases, testCase{
8171 name: "Agree-Digest-SHA256",
8172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008173 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008174 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008175 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008176 signatureRSAPKCS1WithSHA1,
8177 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008178 },
8179 },
8180 flags: []string{
8181 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8182 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008183 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008184 },
Nick Harper60edffd2016-06-21 15:19:24 -07008185 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008186 })
8187 testCases = append(testCases, testCase{
8188 name: "Agree-Digest-SHA1",
8189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008190 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008191 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008192 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008193 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008194 },
8195 },
8196 flags: []string{
8197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008199 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008200 },
Nick Harper60edffd2016-06-21 15:19:24 -07008201 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008202 })
8203 testCases = append(testCases, testCase{
8204 name: "Agree-Digest-Default",
8205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008206 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008207 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008208 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008209 signatureRSAPKCS1WithSHA256,
8210 signatureECDSAWithP256AndSHA256,
8211 signatureRSAPKCS1WithSHA1,
8212 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008213 },
8214 },
8215 flags: []string{
8216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8218 },
Nick Harper60edffd2016-06-21 15:19:24 -07008219 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008220 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008221
David Benjaminca3d5452016-07-14 12:51:01 -04008222 // Test that the signing preference list may include extra algorithms
8223 // without negotiation problems.
8224 testCases = append(testCases, testCase{
8225 testType: serverTest,
8226 name: "FilterExtraAlgorithms",
8227 config: Config{
8228 MaxVersion: VersionTLS12,
8229 VerifySignatureAlgorithms: []signatureAlgorithm{
8230 signatureRSAPKCS1WithSHA256,
8231 },
8232 },
8233 flags: []string{
8234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8236 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8237 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8238 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8239 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8240 },
8241 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8242 })
8243
David Benjamin4c3ddf72016-06-29 18:13:53 -04008244 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8245 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008246 testCases = append(testCases, testCase{
8247 name: "CheckLeafCurve",
8248 config: Config{
8249 MaxVersion: VersionTLS12,
8250 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008251 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008252 },
8253 flags: []string{"-p384-only"},
8254 shouldFail: true,
8255 expectedError: ":BAD_ECC_CERT:",
8256 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008257
8258 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8259 testCases = append(testCases, testCase{
8260 name: "CheckLeafCurve-TLS13",
8261 config: Config{
8262 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008263 Certificates: []Certificate{ecdsaP256Certificate},
8264 },
8265 flags: []string{"-p384-only"},
8266 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008267
8268 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8269 testCases = append(testCases, testCase{
8270 name: "ECDSACurveMismatch-Verify-TLS12",
8271 config: Config{
8272 MaxVersion: VersionTLS12,
8273 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8274 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008275 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008276 signatureECDSAWithP384AndSHA384,
8277 },
8278 },
8279 })
8280
8281 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8282 testCases = append(testCases, testCase{
8283 name: "ECDSACurveMismatch-Verify-TLS13",
8284 config: Config{
8285 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008286 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008287 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008288 signatureECDSAWithP384AndSHA384,
8289 },
8290 Bugs: ProtocolBugs{
8291 SkipECDSACurveCheck: true,
8292 },
8293 },
8294 shouldFail: true,
8295 expectedError: ":WRONG_SIGNATURE_TYPE:",
8296 })
8297
8298 // Signature algorithm selection in TLS 1.3 should take the curve into
8299 // account.
8300 testCases = append(testCases, testCase{
8301 testType: serverTest,
8302 name: "ECDSACurveMismatch-Sign-TLS13",
8303 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008304 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008305 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008306 signatureECDSAWithP384AndSHA384,
8307 signatureECDSAWithP256AndSHA256,
8308 },
8309 },
8310 flags: []string{
8311 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8312 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8313 },
8314 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8315 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008316
8317 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8318 // server does not attempt to sign in that case.
8319 testCases = append(testCases, testCase{
8320 testType: serverTest,
8321 name: "RSA-PSS-Large",
8322 config: Config{
8323 MaxVersion: VersionTLS13,
8324 VerifySignatureAlgorithms: []signatureAlgorithm{
8325 signatureRSAPSSWithSHA512,
8326 },
8327 },
8328 flags: []string{
8329 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8330 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8331 },
8332 shouldFail: true,
8333 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8334 })
David Benjamin57e929f2016-08-30 00:30:38 -04008335
8336 // Test that RSA-PSS is enabled by default for TLS 1.2.
8337 testCases = append(testCases, testCase{
8338 testType: clientTest,
8339 name: "RSA-PSS-Default-Verify",
8340 config: Config{
8341 MaxVersion: VersionTLS12,
8342 SignSignatureAlgorithms: []signatureAlgorithm{
8343 signatureRSAPSSWithSHA256,
8344 },
8345 },
8346 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8347 })
8348
8349 testCases = append(testCases, testCase{
8350 testType: serverTest,
8351 name: "RSA-PSS-Default-Sign",
8352 config: Config{
8353 MaxVersion: VersionTLS12,
8354 VerifySignatureAlgorithms: []signatureAlgorithm{
8355 signatureRSAPSSWithSHA256,
8356 },
8357 },
8358 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8359 })
David Benjamin69522112017-03-28 15:38:29 -05008360
8361 // TLS 1.1 and below has no way to advertise support for or negotiate
8362 // Ed25519's signature algorithm.
8363 testCases = append(testCases, testCase{
8364 testType: clientTest,
8365 name: "NoEd25519-TLS11-ServerAuth-Verify",
8366 config: Config{
8367 MaxVersion: VersionTLS11,
8368 Certificates: []Certificate{ed25519Certificate},
8369 Bugs: ProtocolBugs{
8370 // Sign with Ed25519 even though it is TLS 1.1.
8371 UseLegacySigningAlgorithm: signatureEd25519,
8372 },
8373 },
8374 flags: []string{"-enable-ed25519"},
8375 shouldFail: true,
8376 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8377 })
8378 testCases = append(testCases, testCase{
8379 testType: serverTest,
8380 name: "NoEd25519-TLS11-ServerAuth-Sign",
8381 config: Config{
8382 MaxVersion: VersionTLS11,
8383 },
8384 flags: []string{
8385 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8386 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8387 },
8388 shouldFail: true,
8389 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8390 })
8391 testCases = append(testCases, testCase{
8392 testType: serverTest,
8393 name: "NoEd25519-TLS11-ClientAuth-Verify",
8394 config: Config{
8395 MaxVersion: VersionTLS11,
8396 Certificates: []Certificate{ed25519Certificate},
8397 Bugs: ProtocolBugs{
8398 // Sign with Ed25519 even though it is TLS 1.1.
8399 UseLegacySigningAlgorithm: signatureEd25519,
8400 },
8401 },
8402 flags: []string{
8403 "-enable-ed25519",
8404 "-require-any-client-certificate",
8405 },
8406 shouldFail: true,
8407 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8408 })
8409 testCases = append(testCases, testCase{
8410 testType: clientTest,
8411 name: "NoEd25519-TLS11-ClientAuth-Sign",
8412 config: Config{
8413 MaxVersion: VersionTLS11,
8414 ClientAuth: RequireAnyClientCert,
8415 },
8416 flags: []string{
8417 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8418 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8419 },
8420 shouldFail: true,
8421 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8422 })
8423
8424 // Test Ed25519 is not advertised by default.
8425 testCases = append(testCases, testCase{
8426 testType: clientTest,
8427 name: "Ed25519DefaultDisable-NoAdvertise",
8428 config: Config{
8429 Certificates: []Certificate{ed25519Certificate},
8430 },
8431 shouldFail: true,
8432 expectedLocalError: "tls: no common signature algorithms",
8433 })
8434
8435 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8436 // preferences.
8437 testCases = append(testCases, testCase{
8438 testType: clientTest,
8439 name: "Ed25519DefaultDisable-NoAccept",
8440 config: Config{
8441 Certificates: []Certificate{ed25519Certificate},
8442 Bugs: ProtocolBugs{
8443 IgnorePeerSignatureAlgorithmPreferences: true,
8444 },
8445 },
8446 shouldFail: true,
8447 expectedLocalError: "remote error: illegal parameter",
8448 expectedError: ":WRONG_SIGNATURE_TYPE:",
8449 })
David Benjamin71c21b42017-04-14 17:05:40 -04008450
8451 // Test that configuring verify preferences changes what the client
8452 // advertises.
8453 testCases = append(testCases, testCase{
8454 name: "VerifyPreferences-Advertised",
8455 config: Config{
8456 Certificates: []Certificate{rsaCertificate},
8457 SignSignatureAlgorithms: []signatureAlgorithm{
8458 signatureRSAPSSWithSHA256,
8459 signatureRSAPSSWithSHA384,
8460 signatureRSAPSSWithSHA512,
8461 },
8462 },
8463 flags: []string{
8464 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8465 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8466 },
8467 })
8468
8469 // Test that the client advertises a set which the runner can find
8470 // nothing in common with.
8471 testCases = append(testCases, testCase{
8472 name: "VerifyPreferences-NoCommonAlgorithms",
8473 config: Config{
8474 Certificates: []Certificate{rsaCertificate},
8475 SignSignatureAlgorithms: []signatureAlgorithm{
8476 signatureRSAPSSWithSHA256,
8477 signatureRSAPSSWithSHA512,
8478 },
8479 },
8480 flags: []string{
8481 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8482 },
8483 shouldFail: true,
8484 expectedLocalError: "tls: no common signature algorithms",
8485 })
8486
8487 // Test that the client enforces its preferences when configured.
8488 testCases = append(testCases, testCase{
8489 name: "VerifyPreferences-Enforced",
8490 config: Config{
8491 Certificates: []Certificate{rsaCertificate},
8492 SignSignatureAlgorithms: []signatureAlgorithm{
8493 signatureRSAPSSWithSHA256,
8494 signatureRSAPSSWithSHA512,
8495 },
8496 Bugs: ProtocolBugs{
8497 IgnorePeerSignatureAlgorithmPreferences: true,
8498 },
8499 },
8500 flags: []string{
8501 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8502 },
8503 shouldFail: true,
8504 expectedLocalError: "remote error: illegal parameter",
8505 expectedError: ":WRONG_SIGNATURE_TYPE:",
8506 })
8507
8508 // Test that explicitly configuring Ed25519 is as good as changing the
8509 // boolean toggle.
8510 testCases = append(testCases, testCase{
8511 name: "VerifyPreferences-Ed25519",
8512 config: Config{
8513 Certificates: []Certificate{ed25519Certificate},
8514 },
8515 flags: []string{
8516 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8517 },
8518 })
David Benjamin000800a2014-11-14 01:43:59 -05008519}
8520
David Benjamin83f90402015-01-27 01:09:43 -05008521// timeouts is the retransmit schedule for BoringSSL. It doubles and
8522// caps at 60 seconds. On the 13th timeout, it gives up.
8523var timeouts = []time.Duration{
8524 1 * time.Second,
8525 2 * time.Second,
8526 4 * time.Second,
8527 8 * time.Second,
8528 16 * time.Second,
8529 32 * time.Second,
8530 60 * time.Second,
8531 60 * time.Second,
8532 60 * time.Second,
8533 60 * time.Second,
8534 60 * time.Second,
8535 60 * time.Second,
8536 60 * time.Second,
8537}
8538
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008539// shortTimeouts is an alternate set of timeouts which would occur if the
8540// initial timeout duration was set to 250ms.
8541var shortTimeouts = []time.Duration{
8542 250 * time.Millisecond,
8543 500 * time.Millisecond,
8544 1 * time.Second,
8545 2 * time.Second,
8546 4 * time.Second,
8547 8 * time.Second,
8548 16 * time.Second,
8549 32 * time.Second,
8550 60 * time.Second,
8551 60 * time.Second,
8552 60 * time.Second,
8553 60 * time.Second,
8554 60 * time.Second,
8555}
8556
David Benjamin83f90402015-01-27 01:09:43 -05008557func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008558 // These tests work by coordinating some behavior on both the shim and
8559 // the runner.
8560 //
8561 // TimeoutSchedule configures the runner to send a series of timeout
8562 // opcodes to the shim (see packetAdaptor) immediately before reading
8563 // each peer handshake flight N. The timeout opcode both simulates a
8564 // timeout in the shim and acts as a synchronization point to help the
8565 // runner bracket each handshake flight.
8566 //
8567 // We assume the shim does not read from the channel eagerly. It must
8568 // first wait until it has sent flight N and is ready to receive
8569 // handshake flight N+1. At this point, it will process the timeout
8570 // opcode. It must then immediately respond with a timeout ACK and act
8571 // as if the shim was idle for the specified amount of time.
8572 //
8573 // The runner then drops all packets received before the ACK and
8574 // continues waiting for flight N. This ordering results in one attempt
8575 // at sending flight N to be dropped. For the test to complete, the
8576 // shim must send flight N again, testing that the shim implements DTLS
8577 // retransmit on a timeout.
8578
Steven Valdez143e8b32016-07-11 13:19:03 -04008579 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008580 // likely be more epochs to cross and the final message's retransmit may
8581 // be more complex.
8582
David Benjamin11c82892017-02-23 20:40:31 -05008583 // Test that this is indeed the timeout schedule. Stress all
8584 // four patterns of handshake.
8585 for i := 1; i < len(timeouts); i++ {
8586 number := strconv.Itoa(i)
8587 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008588 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008589 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008590 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008591 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008592 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008593 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008594 },
8595 },
8596 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008597 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008598 })
David Benjamin11c82892017-02-23 20:40:31 -05008599 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008600 protocol: dtls,
8601 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008602 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008604 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008605 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008606 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008607 },
8608 },
8609 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008610 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008611 })
8612 }
David Benjamin11c82892017-02-23 20:40:31 -05008613
8614 // Test that exceeding the timeout schedule hits a read
8615 // timeout.
8616 testCases = append(testCases, testCase{
8617 protocol: dtls,
8618 name: "DTLS-Retransmit-Timeout",
8619 config: Config{
8620 MaxVersion: VersionTLS12,
8621 Bugs: ProtocolBugs{
8622 TimeoutSchedule: timeouts,
8623 },
8624 },
8625 resumeSession: true,
8626 flags: []string{"-async"},
8627 shouldFail: true,
8628 expectedError: ":READ_TIMEOUT_EXPIRED:",
8629 })
8630
8631 // Test that timeout handling has a fudge factor, due to API
8632 // problems.
8633 testCases = append(testCases, testCase{
8634 protocol: dtls,
8635 name: "DTLS-Retransmit-Fudge",
8636 config: Config{
8637 MaxVersion: VersionTLS12,
8638 Bugs: ProtocolBugs{
8639 TimeoutSchedule: []time.Duration{
8640 timeouts[0] - 10*time.Millisecond,
8641 },
8642 },
8643 },
8644 resumeSession: true,
8645 flags: []string{"-async"},
8646 })
8647
8648 // Test that the final Finished retransmitting isn't
8649 // duplicated if the peer badly fragments everything.
8650 testCases = append(testCases, testCase{
8651 testType: serverTest,
8652 protocol: dtls,
8653 name: "DTLS-Retransmit-Fragmented",
8654 config: Config{
8655 MaxVersion: VersionTLS12,
8656 Bugs: ProtocolBugs{
8657 TimeoutSchedule: []time.Duration{timeouts[0]},
8658 MaxHandshakeRecordLength: 2,
8659 },
8660 },
8661 flags: []string{"-async"},
8662 })
8663
8664 // Test the timeout schedule when a shorter initial timeout duration is set.
8665 testCases = append(testCases, testCase{
8666 protocol: dtls,
8667 name: "DTLS-Retransmit-Short-Client",
8668 config: Config{
8669 MaxVersion: VersionTLS12,
8670 Bugs: ProtocolBugs{
8671 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8672 },
8673 },
8674 resumeSession: true,
8675 flags: []string{
8676 "-async",
8677 "-initial-timeout-duration-ms", "250",
8678 },
8679 })
8680 testCases = append(testCases, testCase{
8681 protocol: dtls,
8682 testType: serverTest,
8683 name: "DTLS-Retransmit-Short-Server",
8684 config: Config{
8685 MaxVersion: VersionTLS12,
8686 Bugs: ProtocolBugs{
8687 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8688 },
8689 },
8690 resumeSession: true,
8691 flags: []string{
8692 "-async",
8693 "-initial-timeout-duration-ms", "250",
8694 },
8695 })
David Benjamin83f90402015-01-27 01:09:43 -05008696}
8697
David Benjaminc565ebb2015-04-03 04:06:36 -04008698func addExportKeyingMaterialTests() {
8699 for _, vers := range tlsVersions {
8700 if vers.version == VersionSSL30 {
8701 continue
8702 }
8703 testCases = append(testCases, testCase{
8704 name: "ExportKeyingMaterial-" + vers.name,
8705 config: Config{
8706 MaxVersion: vers.version,
8707 },
David Benjamina5022392017-07-10 17:40:39 -04008708 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008709 exportKeyingMaterial: 1024,
8710 exportLabel: "label",
8711 exportContext: "context",
8712 useExportContext: true,
8713 })
8714 testCases = append(testCases, testCase{
8715 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8716 config: Config{
8717 MaxVersion: vers.version,
8718 },
David Benjamina5022392017-07-10 17:40:39 -04008719 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008720 exportKeyingMaterial: 1024,
8721 })
8722 testCases = append(testCases, testCase{
8723 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8724 config: Config{
8725 MaxVersion: vers.version,
8726 },
David Benjamina5022392017-07-10 17:40:39 -04008727 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008728 exportKeyingMaterial: 1024,
8729 useExportContext: true,
8730 })
8731 testCases = append(testCases, testCase{
8732 name: "ExportKeyingMaterial-Small-" + vers.name,
8733 config: Config{
8734 MaxVersion: vers.version,
8735 },
David Benjamina5022392017-07-10 17:40:39 -04008736 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008737 exportKeyingMaterial: 1,
8738 exportLabel: "label",
8739 exportContext: "context",
8740 useExportContext: true,
8741 })
8742 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008743
David Benjaminc565ebb2015-04-03 04:06:36 -04008744 testCases = append(testCases, testCase{
8745 name: "ExportKeyingMaterial-SSL3",
8746 config: Config{
8747 MaxVersion: VersionSSL30,
8748 },
8749 exportKeyingMaterial: 1024,
8750 exportLabel: "label",
8751 exportContext: "context",
8752 useExportContext: true,
8753 shouldFail: true,
8754 expectedError: "failed to export keying material",
8755 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008756
8757 // Exporters work during a False Start.
8758 testCases = append(testCases, testCase{
8759 name: "ExportKeyingMaterial-FalseStart",
8760 config: Config{
8761 MaxVersion: VersionTLS12,
8762 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8763 NextProtos: []string{"foo"},
8764 Bugs: ProtocolBugs{
8765 ExpectFalseStart: true,
8766 },
8767 },
8768 flags: []string{
8769 "-false-start",
8770 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008771 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008772 },
8773 shimWritesFirst: true,
8774 exportKeyingMaterial: 1024,
8775 exportLabel: "label",
8776 exportContext: "context",
8777 useExportContext: true,
8778 })
8779
8780 // Exporters do not work in the middle of a renegotiation. Test this by
8781 // triggering the exporter after every SSL_read call and configuring the
8782 // shim to run asynchronously.
8783 testCases = append(testCases, testCase{
8784 name: "ExportKeyingMaterial-Renegotiate",
8785 config: Config{
8786 MaxVersion: VersionTLS12,
8787 },
8788 renegotiate: 1,
8789 flags: []string{
8790 "-async",
8791 "-use-exporter-between-reads",
8792 "-renegotiate-freely",
8793 "-expect-total-renegotiations", "1",
8794 },
8795 shouldFail: true,
8796 expectedError: "failed to export keying material",
8797 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008798}
8799
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008800func addTLSUniqueTests() {
8801 for _, isClient := range []bool{false, true} {
8802 for _, isResumption := range []bool{false, true} {
8803 for _, hasEMS := range []bool{false, true} {
8804 var suffix string
8805 if isResumption {
8806 suffix = "Resume-"
8807 } else {
8808 suffix = "Full-"
8809 }
8810
8811 if hasEMS {
8812 suffix += "EMS-"
8813 } else {
8814 suffix += "NoEMS-"
8815 }
8816
8817 if isClient {
8818 suffix += "Client"
8819 } else {
8820 suffix += "Server"
8821 }
8822
8823 test := testCase{
8824 name: "TLSUnique-" + suffix,
8825 testTLSUnique: true,
8826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008827 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008828 Bugs: ProtocolBugs{
8829 NoExtendedMasterSecret: !hasEMS,
8830 },
8831 },
8832 }
8833
8834 if isResumption {
8835 test.resumeSession = true
8836 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008837 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008838 Bugs: ProtocolBugs{
8839 NoExtendedMasterSecret: !hasEMS,
8840 },
8841 }
8842 }
8843
8844 if isResumption && !hasEMS {
8845 test.shouldFail = true
8846 test.expectedError = "failed to get tls-unique"
8847 }
8848
8849 testCases = append(testCases, test)
8850 }
8851 }
8852 }
8853}
8854
Adam Langley09505632015-07-30 18:10:13 -07008855func addCustomExtensionTests() {
8856 expectedContents := "custom extension"
8857 emptyString := ""
8858
8859 for _, isClient := range []bool{false, true} {
8860 suffix := "Server"
8861 flag := "-enable-server-custom-extension"
8862 testType := serverTest
8863 if isClient {
8864 suffix = "Client"
8865 flag = "-enable-client-custom-extension"
8866 testType = clientTest
8867 }
8868
8869 testCases = append(testCases, testCase{
8870 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008871 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008873 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008874 Bugs: ProtocolBugs{
8875 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008876 ExpectedCustomExtension: &expectedContents,
8877 },
8878 },
8879 flags: []string{flag},
8880 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008881 testCases = append(testCases, testCase{
8882 testType: testType,
8883 name: "CustomExtensions-" + suffix + "-TLS13",
8884 config: Config{
8885 MaxVersion: VersionTLS13,
8886 Bugs: ProtocolBugs{
8887 CustomExtension: expectedContents,
8888 ExpectedCustomExtension: &expectedContents,
8889 },
8890 },
8891 flags: []string{flag},
8892 })
Adam Langley09505632015-07-30 18:10:13 -07008893
Steven Valdez2a070722017-03-25 20:54:16 -05008894 // 0-RTT is not currently supported with Custom Extensions.
8895 testCases = append(testCases, testCase{
8896 testType: testType,
8897 name: "CustomExtensions-" + suffix + "-EarlyData",
8898 config: Config{
8899 MaxVersion: VersionTLS13,
8900 Bugs: ProtocolBugs{
8901 CustomExtension: expectedContents,
8902 ExpectedCustomExtension: &expectedContents,
8903 },
8904 },
8905 shouldFail: true,
8906 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8907 flags: []string{flag, "-enable-early-data"},
8908 })
8909
Adam Langley09505632015-07-30 18:10:13 -07008910 // If the parse callback fails, the handshake should also fail.
8911 testCases = append(testCases, testCase{
8912 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008913 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008915 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008916 Bugs: ProtocolBugs{
8917 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008918 ExpectedCustomExtension: &expectedContents,
8919 },
8920 },
David Benjamin399e7c92015-07-30 23:01:27 -04008921 flags: []string{flag},
8922 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008923 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8924 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008925 testCases = append(testCases, testCase{
8926 testType: testType,
8927 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8928 config: Config{
8929 MaxVersion: VersionTLS13,
8930 Bugs: ProtocolBugs{
8931 CustomExtension: expectedContents + "foo",
8932 ExpectedCustomExtension: &expectedContents,
8933 },
8934 },
8935 flags: []string{flag},
8936 shouldFail: true,
8937 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8938 })
Adam Langley09505632015-07-30 18:10:13 -07008939
8940 // If the add callback fails, the handshake should also fail.
8941 testCases = append(testCases, testCase{
8942 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008943 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008945 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008946 Bugs: ProtocolBugs{
8947 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008948 ExpectedCustomExtension: &expectedContents,
8949 },
8950 },
David Benjamin399e7c92015-07-30 23:01:27 -04008951 flags: []string{flag, "-custom-extension-fail-add"},
8952 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008953 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8954 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008955 testCases = append(testCases, testCase{
8956 testType: testType,
8957 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8958 config: Config{
8959 MaxVersion: VersionTLS13,
8960 Bugs: ProtocolBugs{
8961 CustomExtension: expectedContents,
8962 ExpectedCustomExtension: &expectedContents,
8963 },
8964 },
8965 flags: []string{flag, "-custom-extension-fail-add"},
8966 shouldFail: true,
8967 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8968 })
Adam Langley09505632015-07-30 18:10:13 -07008969
8970 // If the add callback returns zero, no extension should be
8971 // added.
8972 skipCustomExtension := expectedContents
8973 if isClient {
8974 // For the case where the client skips sending the
8975 // custom extension, the server must not “echo” it.
8976 skipCustomExtension = ""
8977 }
8978 testCases = append(testCases, testCase{
8979 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008980 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008982 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008983 Bugs: ProtocolBugs{
8984 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008985 ExpectedCustomExtension: &emptyString,
8986 },
8987 },
8988 flags: []string{flag, "-custom-extension-skip"},
8989 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008990 testCases = append(testCases, testCase{
8991 testType: testType,
8992 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8993 config: Config{
8994 MaxVersion: VersionTLS13,
8995 Bugs: ProtocolBugs{
8996 CustomExtension: skipCustomExtension,
8997 ExpectedCustomExtension: &emptyString,
8998 },
8999 },
9000 flags: []string{flag, "-custom-extension-skip"},
9001 })
Adam Langley09505632015-07-30 18:10:13 -07009002 }
9003
9004 // The custom extension add callback should not be called if the client
9005 // doesn't send the extension.
9006 testCases = append(testCases, testCase{
9007 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009008 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009010 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009011 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009012 ExpectedCustomExtension: &emptyString,
9013 },
9014 },
9015 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9016 })
Adam Langley2deb9842015-08-07 11:15:37 -07009017
Steven Valdez143e8b32016-07-11 13:19:03 -04009018 testCases = append(testCases, testCase{
9019 testType: serverTest,
9020 name: "CustomExtensions-NotCalled-Server-TLS13",
9021 config: Config{
9022 MaxVersion: VersionTLS13,
9023 Bugs: ProtocolBugs{
9024 ExpectedCustomExtension: &emptyString,
9025 },
9026 },
9027 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9028 })
9029
Adam Langley2deb9842015-08-07 11:15:37 -07009030 // Test an unknown extension from the server.
9031 testCases = append(testCases, testCase{
9032 testType: clientTest,
9033 name: "UnknownExtension-Client",
9034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009035 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009036 Bugs: ProtocolBugs{
9037 CustomExtension: expectedContents,
9038 },
9039 },
David Benjamin0c40a962016-08-01 12:05:50 -04009040 shouldFail: true,
9041 expectedError: ":UNEXPECTED_EXTENSION:",
9042 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009043 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009044 testCases = append(testCases, testCase{
9045 testType: clientTest,
9046 name: "UnknownExtension-Client-TLS13",
9047 config: Config{
9048 MaxVersion: VersionTLS13,
9049 Bugs: ProtocolBugs{
9050 CustomExtension: expectedContents,
9051 },
9052 },
David Benjamin0c40a962016-08-01 12:05:50 -04009053 shouldFail: true,
9054 expectedError: ":UNEXPECTED_EXTENSION:",
9055 expectedLocalError: "remote error: unsupported extension",
9056 })
David Benjamin490469f2016-10-05 22:44:38 -04009057 testCases = append(testCases, testCase{
9058 testType: clientTest,
9059 name: "UnknownUnencryptedExtension-Client-TLS13",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 Bugs: ProtocolBugs{
9063 CustomUnencryptedExtension: expectedContents,
9064 },
9065 },
9066 shouldFail: true,
9067 expectedError: ":UNEXPECTED_EXTENSION:",
9068 // The shim must send an alert, but alerts at this point do not
9069 // get successfully decrypted by the runner.
9070 expectedLocalError: "local error: bad record MAC",
9071 })
9072 testCases = append(testCases, testCase{
9073 testType: clientTest,
9074 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 Bugs: ProtocolBugs{
9078 SendUnencryptedALPN: "foo",
9079 },
9080 },
9081 flags: []string{
9082 "-advertise-alpn", "\x03foo\x03bar",
9083 },
9084 shouldFail: true,
9085 expectedError: ":UNEXPECTED_EXTENSION:",
9086 // The shim must send an alert, but alerts at this point do not
9087 // get successfully decrypted by the runner.
9088 expectedLocalError: "local error: bad record MAC",
9089 })
David Benjamin0c40a962016-08-01 12:05:50 -04009090
9091 // Test a known but unoffered extension from the server.
9092 testCases = append(testCases, testCase{
9093 testType: clientTest,
9094 name: "UnofferedExtension-Client",
9095 config: Config{
9096 MaxVersion: VersionTLS12,
9097 Bugs: ProtocolBugs{
9098 SendALPN: "alpn",
9099 },
9100 },
9101 shouldFail: true,
9102 expectedError: ":UNEXPECTED_EXTENSION:",
9103 expectedLocalError: "remote error: unsupported extension",
9104 })
9105 testCases = append(testCases, testCase{
9106 testType: clientTest,
9107 name: "UnofferedExtension-Client-TLS13",
9108 config: Config{
9109 MaxVersion: VersionTLS13,
9110 Bugs: ProtocolBugs{
9111 SendALPN: "alpn",
9112 },
9113 },
9114 shouldFail: true,
9115 expectedError: ":UNEXPECTED_EXTENSION:",
9116 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009117 })
Adam Langley09505632015-07-30 18:10:13 -07009118}
9119
David Benjaminb36a3952015-12-01 18:53:13 -05009120func addRSAClientKeyExchangeTests() {
9121 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9122 testCases = append(testCases, testCase{
9123 testType: serverTest,
9124 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9125 config: Config{
9126 // Ensure the ClientHello version and final
9127 // version are different, to detect if the
9128 // server uses the wrong one.
9129 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009130 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009131 Bugs: ProtocolBugs{
9132 BadRSAClientKeyExchange: bad,
9133 },
9134 },
9135 shouldFail: true,
9136 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9137 })
9138 }
David Benjamine63d9d72016-09-19 18:27:34 -04009139
9140 // The server must compare whatever was in ClientHello.version for the
9141 // RSA premaster.
9142 testCases = append(testCases, testCase{
9143 testType: serverTest,
9144 name: "SendClientVersion-RSA",
9145 config: Config{
9146 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9147 Bugs: ProtocolBugs{
9148 SendClientVersion: 0x1234,
9149 },
9150 },
9151 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9152 })
David Benjaminb36a3952015-12-01 18:53:13 -05009153}
9154
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009155var testCurves = []struct {
9156 name string
9157 id CurveID
9158}{
Adam Langley764ab982017-03-10 18:01:30 -08009159 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009160 {"P-256", CurveP256},
9161 {"P-384", CurveP384},
9162 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009163 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009164}
9165
Steven Valdez5440fe02016-07-18 12:40:30 -04009166const bogusCurve = 0x1234
9167
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009168func addCurveTests() {
9169 for _, curve := range testCurves {
9170 testCases = append(testCases, testCase{
9171 name: "CurveTest-Client-" + curve.name,
9172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009173 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9175 CurvePreferences: []CurveID{curve.id},
9176 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009177 flags: []string{
9178 "-enable-all-curves",
9179 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9180 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009181 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009182 })
9183 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009184 name: "CurveTest-Client-" + curve.name + "-TLS13",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009187 CurvePreferences: []CurveID{curve.id},
9188 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009189 flags: []string{
9190 "-enable-all-curves",
9191 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9192 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009193 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009194 })
9195 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009196 testType: serverTest,
9197 name: "CurveTest-Server-" + curve.name,
9198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009199 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9201 CurvePreferences: []CurveID{curve.id},
9202 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009203 flags: []string{
9204 "-enable-all-curves",
9205 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9206 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009207 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009208 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009209 testCases = append(testCases, testCase{
9210 testType: serverTest,
9211 name: "CurveTest-Server-" + curve.name + "-TLS13",
9212 config: Config{
9213 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009214 CurvePreferences: []CurveID{curve.id},
9215 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009216 flags: []string{
9217 "-enable-all-curves",
9218 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9219 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009220 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009221 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009222 }
David Benjamin241ae832016-01-15 03:04:54 -05009223
9224 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009225 testCases = append(testCases, testCase{
9226 testType: serverTest,
9227 name: "UnknownCurve",
9228 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009229 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009230 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9231 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9232 },
9233 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009234
Steven Valdez803c77a2016-09-06 14:13:43 -04009235 // The server must be tolerant to bogus curves.
9236 testCases = append(testCases, testCase{
9237 testType: serverTest,
9238 name: "UnknownCurve-TLS13",
9239 config: Config{
9240 MaxVersion: VersionTLS13,
9241 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9242 },
9243 })
9244
David Benjamin4c3ddf72016-06-29 18:13:53 -04009245 // The server must not consider ECDHE ciphers when there are no
9246 // supported curves.
9247 testCases = append(testCases, testCase{
9248 testType: serverTest,
9249 name: "NoSupportedCurves",
9250 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009251 MaxVersion: VersionTLS12,
9252 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9253 Bugs: ProtocolBugs{
9254 NoSupportedCurves: true,
9255 },
9256 },
9257 shouldFail: true,
9258 expectedError: ":NO_SHARED_CIPHER:",
9259 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009260 testCases = append(testCases, testCase{
9261 testType: serverTest,
9262 name: "NoSupportedCurves-TLS13",
9263 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009264 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009265 Bugs: ProtocolBugs{
9266 NoSupportedCurves: true,
9267 },
9268 },
9269 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009270 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009271 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009272
9273 // The server must fall back to another cipher when there are no
9274 // supported curves.
9275 testCases = append(testCases, testCase{
9276 testType: serverTest,
9277 name: "NoCommonCurves",
9278 config: Config{
9279 MaxVersion: VersionTLS12,
9280 CipherSuites: []uint16{
9281 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009282 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009283 },
9284 CurvePreferences: []CurveID{CurveP224},
9285 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009286 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009287 })
9288
9289 // The client must reject bogus curves and disabled curves.
9290 testCases = append(testCases, testCase{
9291 name: "BadECDHECurve",
9292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009293 MaxVersion: VersionTLS12,
9294 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9295 Bugs: ProtocolBugs{
9296 SendCurve: bogusCurve,
9297 },
9298 },
9299 shouldFail: true,
9300 expectedError: ":WRONG_CURVE:",
9301 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009302 testCases = append(testCases, testCase{
9303 name: "BadECDHECurve-TLS13",
9304 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009305 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009306 Bugs: ProtocolBugs{
9307 SendCurve: bogusCurve,
9308 },
9309 },
9310 shouldFail: true,
9311 expectedError: ":WRONG_CURVE:",
9312 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009313
9314 testCases = append(testCases, testCase{
9315 name: "UnsupportedCurve",
9316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009317 MaxVersion: VersionTLS12,
9318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9319 CurvePreferences: []CurveID{CurveP256},
9320 Bugs: ProtocolBugs{
9321 IgnorePeerCurvePreferences: true,
9322 },
9323 },
9324 flags: []string{"-p384-only"},
9325 shouldFail: true,
9326 expectedError: ":WRONG_CURVE:",
9327 })
9328
David Benjamin4f921572016-07-17 14:20:10 +02009329 testCases = append(testCases, testCase{
9330 // TODO(davidben): Add a TLS 1.3 version where
9331 // HelloRetryRequest requests an unsupported curve.
9332 name: "UnsupportedCurve-ServerHello-TLS13",
9333 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009334 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009335 CurvePreferences: []CurveID{CurveP384},
9336 Bugs: ProtocolBugs{
9337 SendCurve: CurveP256,
9338 },
9339 },
9340 flags: []string{"-p384-only"},
9341 shouldFail: true,
9342 expectedError: ":WRONG_CURVE:",
9343 })
9344
David Benjamin4c3ddf72016-06-29 18:13:53 -04009345 // Test invalid curve points.
9346 testCases = append(testCases, testCase{
9347 name: "InvalidECDHPoint-Client",
9348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009349 MaxVersion: VersionTLS12,
9350 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9351 CurvePreferences: []CurveID{CurveP256},
9352 Bugs: ProtocolBugs{
9353 InvalidECDHPoint: true,
9354 },
9355 },
9356 shouldFail: true,
9357 expectedError: ":INVALID_ENCODING:",
9358 })
9359 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009360 name: "InvalidECDHPoint-Client-TLS13",
9361 config: Config{
9362 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009363 CurvePreferences: []CurveID{CurveP256},
9364 Bugs: ProtocolBugs{
9365 InvalidECDHPoint: true,
9366 },
9367 },
9368 shouldFail: true,
9369 expectedError: ":INVALID_ENCODING:",
9370 })
9371 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009372 testType: serverTest,
9373 name: "InvalidECDHPoint-Server",
9374 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009375 MaxVersion: VersionTLS12,
9376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9377 CurvePreferences: []CurveID{CurveP256},
9378 Bugs: ProtocolBugs{
9379 InvalidECDHPoint: true,
9380 },
9381 },
9382 shouldFail: true,
9383 expectedError: ":INVALID_ENCODING:",
9384 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009385 testCases = append(testCases, testCase{
9386 testType: serverTest,
9387 name: "InvalidECDHPoint-Server-TLS13",
9388 config: Config{
9389 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009390 CurvePreferences: []CurveID{CurveP256},
9391 Bugs: ProtocolBugs{
9392 InvalidECDHPoint: true,
9393 },
9394 },
9395 shouldFail: true,
9396 expectedError: ":INVALID_ENCODING:",
9397 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009398
9399 // The previous curve ID should be reported on TLS 1.2 resumption.
9400 testCases = append(testCases, testCase{
9401 name: "CurveID-Resume-Client",
9402 config: Config{
9403 MaxVersion: VersionTLS12,
9404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9405 CurvePreferences: []CurveID{CurveX25519},
9406 },
9407 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9408 resumeSession: true,
9409 })
9410 testCases = append(testCases, testCase{
9411 testType: serverTest,
9412 name: "CurveID-Resume-Server",
9413 config: Config{
9414 MaxVersion: VersionTLS12,
9415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9416 CurvePreferences: []CurveID{CurveX25519},
9417 },
9418 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9419 resumeSession: true,
9420 })
9421
9422 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9423 // one should be reported.
9424 testCases = append(testCases, testCase{
9425 name: "CurveID-Resume-Client-TLS13",
9426 config: Config{
9427 MaxVersion: VersionTLS13,
9428 CurvePreferences: []CurveID{CurveX25519},
9429 },
9430 resumeConfig: &Config{
9431 MaxVersion: VersionTLS13,
9432 CurvePreferences: []CurveID{CurveP256},
9433 },
9434 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009435 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9436 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009437 },
9438 resumeSession: true,
9439 })
9440 testCases = append(testCases, testCase{
9441 testType: serverTest,
9442 name: "CurveID-Resume-Server-TLS13",
9443 config: Config{
9444 MaxVersion: VersionTLS13,
9445 CurvePreferences: []CurveID{CurveX25519},
9446 },
9447 resumeConfig: &Config{
9448 MaxVersion: VersionTLS13,
9449 CurvePreferences: []CurveID{CurveP256},
9450 },
9451 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009452 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9453 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009454 },
9455 resumeSession: true,
9456 })
David Benjamina81967b2016-12-22 09:16:57 -05009457
9458 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9459 testCases = append(testCases, testCase{
9460 name: "PointFormat-ServerHello-TLS12",
9461 config: Config{
9462 MaxVersion: VersionTLS12,
9463 Bugs: ProtocolBugs{
9464 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9465 },
9466 },
9467 })
9468 testCases = append(testCases, testCase{
9469 name: "PointFormat-EncryptedExtensions-TLS13",
9470 config: Config{
9471 MaxVersion: VersionTLS13,
9472 Bugs: ProtocolBugs{
9473 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9474 },
9475 },
9476 shouldFail: true,
9477 expectedError: ":ERROR_PARSING_EXTENSION:",
9478 })
9479
9480 // Test that we tolerate unknown point formats, as long as
9481 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9482 // check they are still functional.
9483 testCases = append(testCases, testCase{
9484 name: "PointFormat-Client-Tolerance",
9485 config: Config{
9486 MaxVersion: VersionTLS12,
9487 Bugs: ProtocolBugs{
9488 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9489 },
9490 },
9491 })
9492 testCases = append(testCases, testCase{
9493 testType: serverTest,
9494 name: "PointFormat-Server-Tolerance",
9495 config: Config{
9496 MaxVersion: VersionTLS12,
9497 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9498 Bugs: ProtocolBugs{
9499 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9500 },
9501 },
9502 })
9503
9504 // Test TLS 1.2 does not require the point format extension to be
9505 // present.
9506 testCases = append(testCases, testCase{
9507 name: "PointFormat-Client-Missing",
9508 config: Config{
9509 MaxVersion: VersionTLS12,
9510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9511 Bugs: ProtocolBugs{
9512 SendSupportedPointFormats: []byte{},
9513 },
9514 },
9515 })
9516 testCases = append(testCases, testCase{
9517 testType: serverTest,
9518 name: "PointFormat-Server-Missing",
9519 config: Config{
9520 MaxVersion: VersionTLS12,
9521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9522 Bugs: ProtocolBugs{
9523 SendSupportedPointFormats: []byte{},
9524 },
9525 },
9526 })
9527
9528 // If the point format extension is present, uncompressed points must be
9529 // offered. BoringSSL requires this whether or not ECDHE is used.
9530 testCases = append(testCases, testCase{
9531 name: "PointFormat-Client-MissingUncompressed",
9532 config: Config{
9533 MaxVersion: VersionTLS12,
9534 Bugs: ProtocolBugs{
9535 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9536 },
9537 },
9538 shouldFail: true,
9539 expectedError: ":ERROR_PARSING_EXTENSION:",
9540 })
9541 testCases = append(testCases, testCase{
9542 testType: serverTest,
9543 name: "PointFormat-Server-MissingUncompressed",
9544 config: Config{
9545 MaxVersion: VersionTLS12,
9546 Bugs: ProtocolBugs{
9547 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9548 },
9549 },
9550 shouldFail: true,
9551 expectedError: ":ERROR_PARSING_EXTENSION:",
9552 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009553}
9554
David Benjaminc9ae27c2016-06-24 22:56:37 -04009555func addTLS13RecordTests() {
9556 testCases = append(testCases, testCase{
9557 name: "TLS13-RecordPadding",
9558 config: Config{
9559 MaxVersion: VersionTLS13,
9560 MinVersion: VersionTLS13,
9561 Bugs: ProtocolBugs{
9562 RecordPadding: 10,
9563 },
9564 },
9565 })
9566
9567 testCases = append(testCases, testCase{
9568 name: "TLS13-EmptyRecords",
9569 config: Config{
9570 MaxVersion: VersionTLS13,
9571 MinVersion: VersionTLS13,
9572 Bugs: ProtocolBugs{
9573 OmitRecordContents: true,
9574 },
9575 },
9576 shouldFail: true,
9577 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9578 })
9579
9580 testCases = append(testCases, testCase{
9581 name: "TLS13-OnlyPadding",
9582 config: Config{
9583 MaxVersion: VersionTLS13,
9584 MinVersion: VersionTLS13,
9585 Bugs: ProtocolBugs{
9586 OmitRecordContents: true,
9587 RecordPadding: 10,
9588 },
9589 },
9590 shouldFail: true,
9591 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9592 })
9593
9594 testCases = append(testCases, testCase{
9595 name: "TLS13-WrongOuterRecord",
9596 config: Config{
9597 MaxVersion: VersionTLS13,
9598 MinVersion: VersionTLS13,
9599 Bugs: ProtocolBugs{
9600 OuterRecordType: recordTypeHandshake,
9601 },
9602 },
9603 shouldFail: true,
9604 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9605 })
9606}
9607
Steven Valdez5b986082016-09-01 12:29:49 -04009608func addSessionTicketTests() {
9609 testCases = append(testCases, testCase{
9610 // In TLS 1.2 and below, empty NewSessionTicket messages
9611 // mean the server changed its mind on sending a ticket.
9612 name: "SendEmptySessionTicket",
9613 config: Config{
9614 MaxVersion: VersionTLS12,
9615 Bugs: ProtocolBugs{
9616 SendEmptySessionTicket: true,
9617 },
9618 },
9619 flags: []string{"-expect-no-session"},
9620 })
9621
9622 // Test that the server ignores unknown PSK modes.
9623 testCases = append(testCases, testCase{
9624 testType: serverTest,
9625 name: "TLS13-SendUnknownModeSessionTicket-Server",
9626 config: Config{
9627 MaxVersion: VersionTLS13,
9628 Bugs: ProtocolBugs{
9629 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009630 },
9631 },
9632 resumeSession: true,
9633 expectedResumeVersion: VersionTLS13,
9634 })
9635
Steven Valdeza833c352016-11-01 13:39:36 -04009636 // Test that the server does not send session tickets with no matching key exchange mode.
9637 testCases = append(testCases, testCase{
9638 testType: serverTest,
9639 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9640 config: Config{
9641 MaxVersion: VersionTLS13,
9642 Bugs: ProtocolBugs{
9643 SendPSKKeyExchangeModes: []byte{0x1a},
9644 ExpectNoNewSessionTicket: true,
9645 },
9646 },
9647 })
9648
9649 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009650 testCases = append(testCases, testCase{
9651 testType: serverTest,
9652 name: "TLS13-SendBadKEModeSessionTicket-Server",
9653 config: Config{
9654 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009655 },
9656 resumeConfig: &Config{
9657 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009658 Bugs: ProtocolBugs{
9659 SendPSKKeyExchangeModes: []byte{0x1a},
9660 },
9661 },
9662 resumeSession: true,
9663 expectResumeRejected: true,
9664 })
9665
Steven Valdeza833c352016-11-01 13:39:36 -04009666 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009667 testCases = append(testCases, testCase{
9668 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009669 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009670 config: Config{
9671 MaxVersion: VersionTLS13,
9672 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009673 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009674 },
9675 },
Steven Valdeza833c352016-11-01 13:39:36 -04009676 resumeSession: true,
9677 flags: []string{
9678 "-resumption-delay", "10",
9679 },
Steven Valdez5b986082016-09-01 12:29:49 -04009680 })
9681
Steven Valdeza833c352016-11-01 13:39:36 -04009682 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009683 testCases = append(testCases, testCase{
9684 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009685 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009686 config: Config{
9687 MaxVersion: VersionTLS13,
9688 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009689 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009690 },
9691 },
Steven Valdeza833c352016-11-01 13:39:36 -04009692 resumeSession: true,
9693 shouldFail: true,
9694 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009695 })
9696
David Benjamin35ac5b72017-03-03 15:05:56 -05009697 // Test that the server's ticket age skew reporting works.
9698 testCases = append(testCases, testCase{
9699 testType: serverTest,
9700 name: "TLS13-TicketAgeSkew-Forward",
9701 config: Config{
9702 MaxVersion: VersionTLS13,
9703 Bugs: ProtocolBugs{
9704 SendTicketAge: 15 * time.Second,
9705 },
9706 },
David Benjamin065d7332017-03-26 10:51:43 -05009707 resumeSession: true,
9708 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009709 flags: []string{
9710 "-resumption-delay", "10",
9711 "-expect-ticket-age-skew", "5",
9712 },
9713 })
9714 testCases = append(testCases, testCase{
9715 testType: serverTest,
9716 name: "TLS13-TicketAgeSkew-Backward",
9717 config: Config{
9718 MaxVersion: VersionTLS13,
9719 Bugs: ProtocolBugs{
9720 SendTicketAge: 5 * time.Second,
9721 },
9722 },
David Benjamin065d7332017-03-26 10:51:43 -05009723 resumeSession: true,
9724 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009725 flags: []string{
9726 "-resumption-delay", "10",
9727 "-expect-ticket-age-skew", "-5",
9728 },
9729 })
9730
Steven Valdez08b65f42016-12-07 15:29:45 -05009731 testCases = append(testCases, testCase{
9732 testType: clientTest,
9733 name: "TLS13-SendTicketEarlyDataInfo",
9734 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009735 MaxVersion: VersionTLS13,
9736 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009737 },
9738 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009739 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009740 "-expect-early-data-info",
9741 },
9742 })
9743
David Benjamin9b160662017-01-25 19:53:43 -05009744 // Test that 0-RTT tickets are ignored in clients unless opted in.
9745 testCases = append(testCases, testCase{
9746 testType: clientTest,
9747 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9748 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009749 MaxVersion: VersionTLS13,
9750 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009751 },
9752 })
9753
Steven Valdez08b65f42016-12-07 15:29:45 -05009754 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009755 testType: clientTest,
9756 name: "TLS13-DuplicateTicketEarlyDataInfo",
9757 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009758 MaxVersion: VersionTLS13,
9759 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009760 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009761 DuplicateTicketEarlyDataInfo: true,
9762 },
9763 },
9764 shouldFail: true,
9765 expectedError: ":DUPLICATE_EXTENSION:",
9766 expectedLocalError: "remote error: illegal parameter",
9767 })
9768
9769 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009770 testType: serverTest,
9771 name: "TLS13-ExpectTicketEarlyDataInfo",
9772 config: Config{
9773 MaxVersion: VersionTLS13,
9774 Bugs: ProtocolBugs{
9775 ExpectTicketEarlyDataInfo: true,
9776 },
9777 },
9778 flags: []string{
9779 "-enable-early-data",
9780 },
9781 })
David Benjamin17b30832017-01-28 14:00:32 -05009782
9783 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9784 // is honored.
9785 testCases = append(testCases, testCase{
9786 testType: clientTest,
9787 name: "TLS13-HonorServerSessionTicketLifetime",
9788 config: Config{
9789 MaxVersion: VersionTLS13,
9790 Bugs: ProtocolBugs{
9791 SendTicketLifetime: 20 * time.Second,
9792 },
9793 },
9794 flags: []string{
9795 "-resumption-delay", "19",
9796 },
9797 resumeSession: true,
9798 })
9799 testCases = append(testCases, testCase{
9800 testType: clientTest,
9801 name: "TLS13-HonorServerSessionTicketLifetime-2",
9802 config: Config{
9803 MaxVersion: VersionTLS13,
9804 Bugs: ProtocolBugs{
9805 SendTicketLifetime: 20 * time.Second,
9806 // The client should not offer the expired session.
9807 ExpectNoTLS13PSK: true,
9808 },
9809 },
9810 flags: []string{
9811 "-resumption-delay", "21",
9812 },
David Benjamin023d4192017-02-06 13:49:07 -05009813 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009814 expectResumeRejected: true,
9815 })
Steven Valdez5b986082016-09-01 12:29:49 -04009816}
9817
David Benjamin82261be2016-07-07 14:32:50 -07009818func addChangeCipherSpecTests() {
9819 // Test missing ChangeCipherSpecs.
9820 testCases = append(testCases, testCase{
9821 name: "SkipChangeCipherSpec-Client",
9822 config: Config{
9823 MaxVersion: VersionTLS12,
9824 Bugs: ProtocolBugs{
9825 SkipChangeCipherSpec: true,
9826 },
9827 },
9828 shouldFail: true,
9829 expectedError: ":UNEXPECTED_RECORD:",
9830 })
9831 testCases = append(testCases, testCase{
9832 testType: serverTest,
9833 name: "SkipChangeCipherSpec-Server",
9834 config: Config{
9835 MaxVersion: VersionTLS12,
9836 Bugs: ProtocolBugs{
9837 SkipChangeCipherSpec: true,
9838 },
9839 },
9840 shouldFail: true,
9841 expectedError: ":UNEXPECTED_RECORD:",
9842 })
9843 testCases = append(testCases, testCase{
9844 testType: serverTest,
9845 name: "SkipChangeCipherSpec-Server-NPN",
9846 config: Config{
9847 MaxVersion: VersionTLS12,
9848 NextProtos: []string{"bar"},
9849 Bugs: ProtocolBugs{
9850 SkipChangeCipherSpec: true,
9851 },
9852 },
9853 flags: []string{
9854 "-advertise-npn", "\x03foo\x03bar\x03baz",
9855 },
9856 shouldFail: true,
9857 expectedError: ":UNEXPECTED_RECORD:",
9858 })
9859
9860 // Test synchronization between the handshake and ChangeCipherSpec.
9861 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9862 // rejected. Test both with and without handshake packing to handle both
9863 // when the partial post-CCS message is in its own record and when it is
9864 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009865 for _, packed := range []bool{false, true} {
9866 var suffix string
9867 if packed {
9868 suffix = "-Packed"
9869 }
9870
9871 testCases = append(testCases, testCase{
9872 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9873 config: Config{
9874 MaxVersion: VersionTLS12,
9875 Bugs: ProtocolBugs{
9876 FragmentAcrossChangeCipherSpec: true,
9877 PackHandshakeFlight: packed,
9878 },
9879 },
9880 shouldFail: true,
9881 expectedError: ":UNEXPECTED_RECORD:",
9882 })
9883 testCases = append(testCases, testCase{
9884 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9885 config: Config{
9886 MaxVersion: VersionTLS12,
9887 },
9888 resumeSession: true,
9889 resumeConfig: &Config{
9890 MaxVersion: VersionTLS12,
9891 Bugs: ProtocolBugs{
9892 FragmentAcrossChangeCipherSpec: true,
9893 PackHandshakeFlight: packed,
9894 },
9895 },
9896 shouldFail: true,
9897 expectedError: ":UNEXPECTED_RECORD:",
9898 })
9899 testCases = append(testCases, testCase{
9900 testType: serverTest,
9901 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9902 config: Config{
9903 MaxVersion: VersionTLS12,
9904 Bugs: ProtocolBugs{
9905 FragmentAcrossChangeCipherSpec: true,
9906 PackHandshakeFlight: packed,
9907 },
9908 },
9909 shouldFail: true,
9910 expectedError: ":UNEXPECTED_RECORD:",
9911 })
9912 testCases = append(testCases, testCase{
9913 testType: serverTest,
9914 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9915 config: Config{
9916 MaxVersion: VersionTLS12,
9917 },
9918 resumeSession: true,
9919 resumeConfig: &Config{
9920 MaxVersion: VersionTLS12,
9921 Bugs: ProtocolBugs{
9922 FragmentAcrossChangeCipherSpec: true,
9923 PackHandshakeFlight: packed,
9924 },
9925 },
9926 shouldFail: true,
9927 expectedError: ":UNEXPECTED_RECORD:",
9928 })
9929 testCases = append(testCases, testCase{
9930 testType: serverTest,
9931 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9932 config: Config{
9933 MaxVersion: VersionTLS12,
9934 NextProtos: []string{"bar"},
9935 Bugs: ProtocolBugs{
9936 FragmentAcrossChangeCipherSpec: true,
9937 PackHandshakeFlight: packed,
9938 },
9939 },
9940 flags: []string{
9941 "-advertise-npn", "\x03foo\x03bar\x03baz",
9942 },
9943 shouldFail: true,
9944 expectedError: ":UNEXPECTED_RECORD:",
9945 })
9946 }
9947
David Benjamin61672812016-07-14 23:10:43 -04009948 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9949 // messages in the handshake queue. Do this by testing the server
9950 // reading the client Finished, reversing the flight so Finished comes
9951 // first.
9952 testCases = append(testCases, testCase{
9953 protocol: dtls,
9954 testType: serverTest,
9955 name: "SendUnencryptedFinished-DTLS",
9956 config: Config{
9957 MaxVersion: VersionTLS12,
9958 Bugs: ProtocolBugs{
9959 SendUnencryptedFinished: true,
9960 ReverseHandshakeFragments: true,
9961 },
9962 },
9963 shouldFail: true,
9964 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9965 })
9966
Steven Valdez143e8b32016-07-11 13:19:03 -04009967 // Test synchronization between encryption changes and the handshake in
9968 // TLS 1.3, where ChangeCipherSpec is implicit.
9969 testCases = append(testCases, testCase{
9970 name: "PartialEncryptedExtensionsWithServerHello",
9971 config: Config{
9972 MaxVersion: VersionTLS13,
9973 Bugs: ProtocolBugs{
9974 PartialEncryptedExtensionsWithServerHello: true,
9975 },
9976 },
9977 shouldFail: true,
9978 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9979 })
9980 testCases = append(testCases, testCase{
9981 testType: serverTest,
9982 name: "PartialClientFinishedWithClientHello",
9983 config: Config{
9984 MaxVersion: VersionTLS13,
9985 Bugs: ProtocolBugs{
9986 PartialClientFinishedWithClientHello: true,
9987 },
9988 },
9989 shouldFail: true,
9990 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9991 })
9992
David Benjamin82261be2016-07-07 14:32:50 -07009993 // Test that early ChangeCipherSpecs are handled correctly.
9994 testCases = append(testCases, testCase{
9995 testType: serverTest,
9996 name: "EarlyChangeCipherSpec-server-1",
9997 config: Config{
9998 MaxVersion: VersionTLS12,
9999 Bugs: ProtocolBugs{
10000 EarlyChangeCipherSpec: 1,
10001 },
10002 },
10003 shouldFail: true,
10004 expectedError: ":UNEXPECTED_RECORD:",
10005 })
10006 testCases = append(testCases, testCase{
10007 testType: serverTest,
10008 name: "EarlyChangeCipherSpec-server-2",
10009 config: Config{
10010 MaxVersion: VersionTLS12,
10011 Bugs: ProtocolBugs{
10012 EarlyChangeCipherSpec: 2,
10013 },
10014 },
10015 shouldFail: true,
10016 expectedError: ":UNEXPECTED_RECORD:",
10017 })
10018 testCases = append(testCases, testCase{
10019 protocol: dtls,
10020 name: "StrayChangeCipherSpec",
10021 config: Config{
10022 // TODO(davidben): Once DTLS 1.3 exists, test
10023 // that stray ChangeCipherSpec messages are
10024 // rejected.
10025 MaxVersion: VersionTLS12,
10026 Bugs: ProtocolBugs{
10027 StrayChangeCipherSpec: true,
10028 },
10029 },
10030 })
10031
10032 // Test that the contents of ChangeCipherSpec are checked.
10033 testCases = append(testCases, testCase{
10034 name: "BadChangeCipherSpec-1",
10035 config: Config{
10036 MaxVersion: VersionTLS12,
10037 Bugs: ProtocolBugs{
10038 BadChangeCipherSpec: []byte{2},
10039 },
10040 },
10041 shouldFail: true,
10042 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10043 })
10044 testCases = append(testCases, testCase{
10045 name: "BadChangeCipherSpec-2",
10046 config: Config{
10047 MaxVersion: VersionTLS12,
10048 Bugs: ProtocolBugs{
10049 BadChangeCipherSpec: []byte{1, 1},
10050 },
10051 },
10052 shouldFail: true,
10053 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10054 })
10055 testCases = append(testCases, testCase{
10056 protocol: dtls,
10057 name: "BadChangeCipherSpec-DTLS-1",
10058 config: Config{
10059 MaxVersion: VersionTLS12,
10060 Bugs: ProtocolBugs{
10061 BadChangeCipherSpec: []byte{2},
10062 },
10063 },
10064 shouldFail: true,
10065 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10066 })
10067 testCases = append(testCases, testCase{
10068 protocol: dtls,
10069 name: "BadChangeCipherSpec-DTLS-2",
10070 config: Config{
10071 MaxVersion: VersionTLS12,
10072 Bugs: ProtocolBugs{
10073 BadChangeCipherSpec: []byte{1, 1},
10074 },
10075 },
10076 shouldFail: true,
10077 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10078 })
10079}
10080
David Benjamincd2c8062016-09-09 11:28:16 -040010081type perMessageTest struct {
10082 messageType uint8
10083 test testCase
10084}
10085
10086// makePerMessageTests returns a series of test templates which cover each
10087// message in the TLS handshake. These may be used with bugs like
10088// WrongMessageType to fully test a per-message bug.
10089func makePerMessageTests() []perMessageTest {
10090 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010091 for _, protocol := range []protocol{tls, dtls} {
10092 var suffix string
10093 if protocol == dtls {
10094 suffix = "-DTLS"
10095 }
10096
David Benjamincd2c8062016-09-09 11:28:16 -040010097 ret = append(ret, perMessageTest{
10098 messageType: typeClientHello,
10099 test: testCase{
10100 protocol: protocol,
10101 testType: serverTest,
10102 name: "ClientHello" + suffix,
10103 config: Config{
10104 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010105 },
10106 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010107 })
10108
10109 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010110 ret = append(ret, perMessageTest{
10111 messageType: typeHelloVerifyRequest,
10112 test: testCase{
10113 protocol: protocol,
10114 name: "HelloVerifyRequest" + suffix,
10115 config: Config{
10116 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010117 },
10118 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010119 })
10120 }
10121
David Benjamincd2c8062016-09-09 11:28:16 -040010122 ret = append(ret, perMessageTest{
10123 messageType: typeServerHello,
10124 test: testCase{
10125 protocol: protocol,
10126 name: "ServerHello" + suffix,
10127 config: Config{
10128 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010129 },
10130 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010131 })
10132
David Benjamincd2c8062016-09-09 11:28:16 -040010133 ret = append(ret, perMessageTest{
10134 messageType: typeCertificate,
10135 test: testCase{
10136 protocol: protocol,
10137 name: "ServerCertificate" + suffix,
10138 config: Config{
10139 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010140 },
10141 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010142 })
10143
David Benjamincd2c8062016-09-09 11:28:16 -040010144 ret = append(ret, perMessageTest{
10145 messageType: typeCertificateStatus,
10146 test: testCase{
10147 protocol: protocol,
10148 name: "CertificateStatus" + suffix,
10149 config: Config{
10150 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010151 },
David Benjamincd2c8062016-09-09 11:28:16 -040010152 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010153 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010154 })
10155
David Benjamincd2c8062016-09-09 11:28:16 -040010156 ret = append(ret, perMessageTest{
10157 messageType: typeServerKeyExchange,
10158 test: testCase{
10159 protocol: protocol,
10160 name: "ServerKeyExchange" + suffix,
10161 config: Config{
10162 MaxVersion: VersionTLS12,
10163 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010164 },
10165 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010166 })
10167
David Benjamincd2c8062016-09-09 11:28:16 -040010168 ret = append(ret, perMessageTest{
10169 messageType: typeCertificateRequest,
10170 test: testCase{
10171 protocol: protocol,
10172 name: "CertificateRequest" + suffix,
10173 config: Config{
10174 MaxVersion: VersionTLS12,
10175 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010176 },
10177 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010178 })
10179
David Benjamincd2c8062016-09-09 11:28:16 -040010180 ret = append(ret, perMessageTest{
10181 messageType: typeServerHelloDone,
10182 test: testCase{
10183 protocol: protocol,
10184 name: "ServerHelloDone" + suffix,
10185 config: Config{
10186 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010187 },
10188 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010189 })
10190
David Benjamincd2c8062016-09-09 11:28:16 -040010191 ret = append(ret, perMessageTest{
10192 messageType: typeCertificate,
10193 test: testCase{
10194 testType: serverTest,
10195 protocol: protocol,
10196 name: "ClientCertificate" + suffix,
10197 config: Config{
10198 Certificates: []Certificate{rsaCertificate},
10199 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010200 },
David Benjamincd2c8062016-09-09 11:28:16 -040010201 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010202 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010203 })
10204
David Benjamincd2c8062016-09-09 11:28:16 -040010205 ret = append(ret, perMessageTest{
10206 messageType: typeCertificateVerify,
10207 test: testCase{
10208 testType: serverTest,
10209 protocol: protocol,
10210 name: "CertificateVerify" + suffix,
10211 config: Config{
10212 Certificates: []Certificate{rsaCertificate},
10213 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010214 },
David Benjamincd2c8062016-09-09 11:28:16 -040010215 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010216 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010217 })
10218
David Benjamincd2c8062016-09-09 11:28:16 -040010219 ret = append(ret, perMessageTest{
10220 messageType: typeClientKeyExchange,
10221 test: testCase{
10222 testType: serverTest,
10223 protocol: protocol,
10224 name: "ClientKeyExchange" + suffix,
10225 config: Config{
10226 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010227 },
10228 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010229 })
10230
10231 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010232 ret = append(ret, perMessageTest{
10233 messageType: typeNextProtocol,
10234 test: testCase{
10235 testType: serverTest,
10236 protocol: protocol,
10237 name: "NextProtocol" + suffix,
10238 config: Config{
10239 MaxVersion: VersionTLS12,
10240 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010241 },
David Benjamincd2c8062016-09-09 11:28:16 -040010242 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010243 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010244 })
10245
David Benjamincd2c8062016-09-09 11:28:16 -040010246 ret = append(ret, perMessageTest{
10247 messageType: typeChannelID,
10248 test: testCase{
10249 testType: serverTest,
10250 protocol: protocol,
10251 name: "ChannelID" + suffix,
10252 config: Config{
10253 MaxVersion: VersionTLS12,
10254 ChannelID: channelIDKey,
10255 },
10256 flags: []string{
10257 "-expect-channel-id",
10258 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010259 },
10260 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010261 })
10262 }
10263
David Benjamincd2c8062016-09-09 11:28:16 -040010264 ret = append(ret, perMessageTest{
10265 messageType: typeFinished,
10266 test: testCase{
10267 testType: serverTest,
10268 protocol: protocol,
10269 name: "ClientFinished" + suffix,
10270 config: Config{
10271 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010272 },
10273 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010274 })
10275
David Benjamincd2c8062016-09-09 11:28:16 -040010276 ret = append(ret, perMessageTest{
10277 messageType: typeNewSessionTicket,
10278 test: testCase{
10279 protocol: protocol,
10280 name: "NewSessionTicket" + suffix,
10281 config: Config{
10282 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010283 },
10284 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010285 })
10286
David Benjamincd2c8062016-09-09 11:28:16 -040010287 ret = append(ret, perMessageTest{
10288 messageType: typeFinished,
10289 test: testCase{
10290 protocol: protocol,
10291 name: "ServerFinished" + suffix,
10292 config: Config{
10293 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010294 },
10295 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010296 })
10297
10298 }
David Benjamincd2c8062016-09-09 11:28:16 -040010299
10300 ret = append(ret, perMessageTest{
10301 messageType: typeClientHello,
10302 test: testCase{
10303 testType: serverTest,
10304 name: "TLS13-ClientHello",
10305 config: Config{
10306 MaxVersion: VersionTLS13,
10307 },
10308 },
10309 })
10310
10311 ret = append(ret, perMessageTest{
10312 messageType: typeServerHello,
10313 test: testCase{
10314 name: "TLS13-ServerHello",
10315 config: Config{
10316 MaxVersion: VersionTLS13,
10317 },
10318 },
10319 })
10320
10321 ret = append(ret, perMessageTest{
10322 messageType: typeEncryptedExtensions,
10323 test: testCase{
10324 name: "TLS13-EncryptedExtensions",
10325 config: Config{
10326 MaxVersion: VersionTLS13,
10327 },
10328 },
10329 })
10330
10331 ret = append(ret, perMessageTest{
10332 messageType: typeCertificateRequest,
10333 test: testCase{
10334 name: "TLS13-CertificateRequest",
10335 config: Config{
10336 MaxVersion: VersionTLS13,
10337 ClientAuth: RequireAnyClientCert,
10338 },
10339 },
10340 })
10341
10342 ret = append(ret, perMessageTest{
10343 messageType: typeCertificate,
10344 test: testCase{
10345 name: "TLS13-ServerCertificate",
10346 config: Config{
10347 MaxVersion: VersionTLS13,
10348 },
10349 },
10350 })
10351
10352 ret = append(ret, perMessageTest{
10353 messageType: typeCertificateVerify,
10354 test: testCase{
10355 name: "TLS13-ServerCertificateVerify",
10356 config: Config{
10357 MaxVersion: VersionTLS13,
10358 },
10359 },
10360 })
10361
10362 ret = append(ret, perMessageTest{
10363 messageType: typeFinished,
10364 test: testCase{
10365 name: "TLS13-ServerFinished",
10366 config: Config{
10367 MaxVersion: VersionTLS13,
10368 },
10369 },
10370 })
10371
10372 ret = append(ret, perMessageTest{
10373 messageType: typeCertificate,
10374 test: testCase{
10375 testType: serverTest,
10376 name: "TLS13-ClientCertificate",
10377 config: Config{
10378 Certificates: []Certificate{rsaCertificate},
10379 MaxVersion: VersionTLS13,
10380 },
10381 flags: []string{"-require-any-client-certificate"},
10382 },
10383 })
10384
10385 ret = append(ret, perMessageTest{
10386 messageType: typeCertificateVerify,
10387 test: testCase{
10388 testType: serverTest,
10389 name: "TLS13-ClientCertificateVerify",
10390 config: Config{
10391 Certificates: []Certificate{rsaCertificate},
10392 MaxVersion: VersionTLS13,
10393 },
10394 flags: []string{"-require-any-client-certificate"},
10395 },
10396 })
10397
10398 ret = append(ret, perMessageTest{
10399 messageType: typeFinished,
10400 test: testCase{
10401 testType: serverTest,
10402 name: "TLS13-ClientFinished",
10403 config: Config{
10404 MaxVersion: VersionTLS13,
10405 },
10406 },
10407 })
10408
10409 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010410}
10411
David Benjamincd2c8062016-09-09 11:28:16 -040010412func addWrongMessageTypeTests() {
10413 for _, t := range makePerMessageTests() {
10414 t.test.name = "WrongMessageType-" + t.test.name
10415 t.test.config.Bugs.SendWrongMessageType = t.messageType
10416 t.test.shouldFail = true
10417 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10418 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010419
David Benjamincd2c8062016-09-09 11:28:16 -040010420 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10421 // In TLS 1.3, a bad ServerHello means the client sends
10422 // an unencrypted alert while the server expects
10423 // encryption, so the alert is not readable by runner.
10424 t.test.expectedLocalError = "local error: bad record MAC"
10425 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010426
David Benjamincd2c8062016-09-09 11:28:16 -040010427 testCases = append(testCases, t.test)
10428 }
David Benjaminebacdee2017-04-08 11:00:45 -040010429
10430 // The processing order for TLS 1.3 version negotiation is such that one
10431 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10432 // TLS 1.2. Test that we do not do this.
10433 testCases = append(testCases, testCase{
10434 name: "SendServerHelloAsHelloRetryRequest",
10435 config: Config{
10436 MaxVersion: VersionTLS12,
10437 Bugs: ProtocolBugs{
10438 SendServerHelloAsHelloRetryRequest: true,
10439 },
10440 },
10441 shouldFail: true,
10442 expectedError: ":UNEXPECTED_MESSAGE:",
10443 expectedLocalError: "remote error: unexpected message",
10444 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010445}
10446
David Benjamin639846e2016-09-09 11:41:18 -040010447func addTrailingMessageDataTests() {
10448 for _, t := range makePerMessageTests() {
10449 t.test.name = "TrailingMessageData-" + t.test.name
10450 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10451 t.test.shouldFail = true
10452 t.test.expectedError = ":DECODE_ERROR:"
10453 t.test.expectedLocalError = "remote error: error decoding message"
10454
10455 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10456 // In TLS 1.3, a bad ServerHello means the client sends
10457 // an unencrypted alert while the server expects
10458 // encryption, so the alert is not readable by runner.
10459 t.test.expectedLocalError = "local error: bad record MAC"
10460 }
10461
10462 if t.messageType == typeFinished {
10463 // Bad Finished messages read as the verify data having
10464 // the wrong length.
10465 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10466 t.test.expectedLocalError = "remote error: error decrypting message"
10467 }
10468
10469 testCases = append(testCases, t.test)
10470 }
10471}
10472
Steven Valdez143e8b32016-07-11 13:19:03 -040010473func addTLS13HandshakeTests() {
10474 testCases = append(testCases, testCase{
10475 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010476 name: "NegotiatePSKResumption-TLS13",
10477 config: Config{
10478 MaxVersion: VersionTLS13,
10479 Bugs: ProtocolBugs{
10480 NegotiatePSKResumption: true,
10481 },
10482 },
10483 resumeSession: true,
10484 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010485 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010486 })
10487
10488 testCases = append(testCases, testCase{
10489 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010490 name: "MissingKeyShare-Client",
10491 config: Config{
10492 MaxVersion: VersionTLS13,
10493 Bugs: ProtocolBugs{
10494 MissingKeyShare: true,
10495 },
10496 },
10497 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010498 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010499 })
10500
10501 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010502 testType: serverTest,
10503 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010504 config: Config{
10505 MaxVersion: VersionTLS13,
10506 Bugs: ProtocolBugs{
10507 MissingKeyShare: true,
10508 },
10509 },
10510 shouldFail: true,
10511 expectedError: ":MISSING_KEY_SHARE:",
10512 })
10513
10514 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010515 testType: serverTest,
10516 name: "DuplicateKeyShares",
10517 config: Config{
10518 MaxVersion: VersionTLS13,
10519 Bugs: ProtocolBugs{
10520 DuplicateKeyShares: true,
10521 },
10522 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010523 shouldFail: true,
10524 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010525 })
10526
10527 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010528 testType: serverTest,
10529 name: "SkipEarlyData",
10530 config: Config{
10531 MaxVersion: VersionTLS13,
10532 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010533 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010534 },
10535 },
10536 })
10537
10538 testCases = append(testCases, testCase{
10539 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010540 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010541 config: Config{
10542 MaxVersion: VersionTLS13,
10543 TLS13Variant: TLS13Experiment,
10544 Bugs: ProtocolBugs{
10545 SendFakeEarlyDataLength: 4,
10546 },
10547 },
10548 flags: []string{"-tls13-variant", "1"},
10549 })
10550
10551 testCases = append(testCases, testCase{
10552 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010553 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10554 config: Config{
10555 MaxVersion: VersionTLS13,
10556 TLS13Variant: TLS13RecordTypeExperiment,
10557 Bugs: ProtocolBugs{
10558 SendFakeEarlyDataLength: 4,
10559 },
10560 },
10561 flags: []string{"-tls13-variant", "2"},
10562 })
10563
10564 testCases = append(testCases, testCase{
10565 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010566 name: "SkipEarlyData-OmitEarlyDataExtension",
10567 config: Config{
10568 MaxVersion: VersionTLS13,
10569 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010570 SendFakeEarlyDataLength: 4,
10571 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010572 },
10573 },
10574 shouldFail: true,
10575 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10576 })
10577
10578 testCases = append(testCases, testCase{
10579 testType: serverTest,
10580 name: "SkipEarlyData-TooMuchData",
10581 config: Config{
10582 MaxVersion: VersionTLS13,
10583 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010584 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010585 },
10586 },
10587 shouldFail: true,
10588 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10589 })
10590
10591 testCases = append(testCases, testCase{
10592 testType: serverTest,
10593 name: "SkipEarlyData-Interleaved",
10594 config: Config{
10595 MaxVersion: VersionTLS13,
10596 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010597 SendFakeEarlyDataLength: 4,
10598 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010599 },
10600 },
10601 shouldFail: true,
10602 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10603 })
10604
10605 testCases = append(testCases, testCase{
10606 testType: serverTest,
10607 name: "SkipEarlyData-EarlyDataInTLS12",
10608 config: Config{
10609 MaxVersion: VersionTLS13,
10610 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010611 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010612 },
10613 },
10614 shouldFail: true,
10615 expectedError: ":UNEXPECTED_RECORD:",
10616 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10617 })
10618
10619 testCases = append(testCases, testCase{
10620 testType: serverTest,
10621 name: "SkipEarlyData-HRR",
10622 config: Config{
10623 MaxVersion: VersionTLS13,
10624 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010625 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010626 },
10627 DefaultCurves: []CurveID{},
10628 },
10629 })
10630
10631 testCases = append(testCases, testCase{
10632 testType: serverTest,
10633 name: "SkipEarlyData-HRR-Interleaved",
10634 config: Config{
10635 MaxVersion: VersionTLS13,
10636 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010637 SendFakeEarlyDataLength: 4,
10638 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010639 },
10640 DefaultCurves: []CurveID{},
10641 },
10642 shouldFail: true,
10643 expectedError: ":UNEXPECTED_RECORD:",
10644 })
10645
10646 testCases = append(testCases, testCase{
10647 testType: serverTest,
10648 name: "SkipEarlyData-HRR-TooMuchData",
10649 config: Config{
10650 MaxVersion: VersionTLS13,
10651 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010652 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010653 },
10654 DefaultCurves: []CurveID{},
10655 },
10656 shouldFail: true,
10657 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10658 })
10659
10660 // Test that skipping early data looking for cleartext correctly
10661 // processes an alert record.
10662 testCases = append(testCases, testCase{
10663 testType: serverTest,
10664 name: "SkipEarlyData-HRR-FatalAlert",
10665 config: Config{
10666 MaxVersion: VersionTLS13,
10667 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010668 SendEarlyAlert: true,
10669 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010670 },
10671 DefaultCurves: []CurveID{},
10672 },
10673 shouldFail: true,
10674 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10675 })
10676
10677 testCases = append(testCases, testCase{
10678 testType: serverTest,
10679 name: "SkipEarlyData-SecondClientHelloEarlyData",
10680 config: Config{
10681 MaxVersion: VersionTLS13,
10682 Bugs: ProtocolBugs{
10683 SendEarlyDataOnSecondClientHello: true,
10684 },
10685 DefaultCurves: []CurveID{},
10686 },
10687 shouldFail: true,
10688 expectedLocalError: "remote error: bad record MAC",
10689 })
10690
10691 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010692 testType: clientTest,
10693 name: "EmptyEncryptedExtensions",
10694 config: Config{
10695 MaxVersion: VersionTLS13,
10696 Bugs: ProtocolBugs{
10697 EmptyEncryptedExtensions: true,
10698 },
10699 },
10700 shouldFail: true,
10701 expectedLocalError: "remote error: error decoding message",
10702 })
10703
10704 testCases = append(testCases, testCase{
10705 testType: clientTest,
10706 name: "EncryptedExtensionsWithKeyShare",
10707 config: Config{
10708 MaxVersion: VersionTLS13,
10709 Bugs: ProtocolBugs{
10710 EncryptedExtensionsWithKeyShare: true,
10711 },
10712 },
10713 shouldFail: true,
10714 expectedLocalError: "remote error: unsupported extension",
10715 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010716
10717 testCases = append(testCases, testCase{
10718 testType: serverTest,
10719 name: "SendHelloRetryRequest",
10720 config: Config{
10721 MaxVersion: VersionTLS13,
10722 // Require a HelloRetryRequest for every curve.
10723 DefaultCurves: []CurveID{},
10724 },
10725 expectedCurveID: CurveX25519,
10726 })
10727
10728 testCases = append(testCases, testCase{
10729 testType: serverTest,
10730 name: "SendHelloRetryRequest-2",
10731 config: Config{
10732 MaxVersion: VersionTLS13,
10733 DefaultCurves: []CurveID{CurveP384},
10734 },
10735 // Although the ClientHello did not predict our preferred curve,
10736 // we always select it whether it is predicted or not.
10737 expectedCurveID: CurveX25519,
10738 })
10739
10740 testCases = append(testCases, testCase{
10741 name: "UnknownCurve-HelloRetryRequest",
10742 config: Config{
10743 MaxVersion: VersionTLS13,
10744 // P-384 requires HelloRetryRequest in BoringSSL.
10745 CurvePreferences: []CurveID{CurveP384},
10746 Bugs: ProtocolBugs{
10747 SendHelloRetryRequestCurve: bogusCurve,
10748 },
10749 },
10750 shouldFail: true,
10751 expectedError: ":WRONG_CURVE:",
10752 })
10753
10754 testCases = append(testCases, testCase{
10755 name: "DisabledCurve-HelloRetryRequest",
10756 config: Config{
10757 MaxVersion: VersionTLS13,
10758 CurvePreferences: []CurveID{CurveP256},
10759 Bugs: ProtocolBugs{
10760 IgnorePeerCurvePreferences: true,
10761 },
10762 },
10763 flags: []string{"-p384-only"},
10764 shouldFail: true,
10765 expectedError: ":WRONG_CURVE:",
10766 })
10767
10768 testCases = append(testCases, testCase{
10769 name: "UnnecessaryHelloRetryRequest",
10770 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010771 MaxVersion: VersionTLS13,
10772 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010773 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010774 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010775 },
10776 },
10777 shouldFail: true,
10778 expectedError: ":WRONG_CURVE:",
10779 })
10780
10781 testCases = append(testCases, testCase{
10782 name: "SecondHelloRetryRequest",
10783 config: Config{
10784 MaxVersion: VersionTLS13,
10785 // P-384 requires HelloRetryRequest in BoringSSL.
10786 CurvePreferences: []CurveID{CurveP384},
10787 Bugs: ProtocolBugs{
10788 SecondHelloRetryRequest: true,
10789 },
10790 },
10791 shouldFail: true,
10792 expectedError: ":UNEXPECTED_MESSAGE:",
10793 })
10794
10795 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010796 name: "HelloRetryRequest-Empty",
10797 config: Config{
10798 MaxVersion: VersionTLS13,
10799 Bugs: ProtocolBugs{
10800 AlwaysSendHelloRetryRequest: true,
10801 },
10802 },
10803 shouldFail: true,
10804 expectedError: ":DECODE_ERROR:",
10805 })
10806
10807 testCases = append(testCases, testCase{
10808 name: "HelloRetryRequest-DuplicateCurve",
10809 config: Config{
10810 MaxVersion: VersionTLS13,
10811 // P-384 requires a HelloRetryRequest against BoringSSL's default
10812 // configuration. Assert this ExpectMissingKeyShare.
10813 CurvePreferences: []CurveID{CurveP384},
10814 Bugs: ProtocolBugs{
10815 ExpectMissingKeyShare: true,
10816 DuplicateHelloRetryRequestExtensions: true,
10817 },
10818 },
10819 shouldFail: true,
10820 expectedError: ":DUPLICATE_EXTENSION:",
10821 expectedLocalError: "remote error: illegal parameter",
10822 })
10823
10824 testCases = append(testCases, testCase{
10825 name: "HelloRetryRequest-Cookie",
10826 config: Config{
10827 MaxVersion: VersionTLS13,
10828 Bugs: ProtocolBugs{
10829 SendHelloRetryRequestCookie: []byte("cookie"),
10830 },
10831 },
10832 })
10833
10834 testCases = append(testCases, testCase{
10835 name: "HelloRetryRequest-DuplicateCookie",
10836 config: Config{
10837 MaxVersion: VersionTLS13,
10838 Bugs: ProtocolBugs{
10839 SendHelloRetryRequestCookie: []byte("cookie"),
10840 DuplicateHelloRetryRequestExtensions: true,
10841 },
10842 },
10843 shouldFail: true,
10844 expectedError: ":DUPLICATE_EXTENSION:",
10845 expectedLocalError: "remote error: illegal parameter",
10846 })
10847
10848 testCases = append(testCases, testCase{
10849 name: "HelloRetryRequest-EmptyCookie",
10850 config: Config{
10851 MaxVersion: VersionTLS13,
10852 Bugs: ProtocolBugs{
10853 SendHelloRetryRequestCookie: []byte{},
10854 },
10855 },
10856 shouldFail: true,
10857 expectedError: ":DECODE_ERROR:",
10858 })
10859
10860 testCases = append(testCases, testCase{
10861 name: "HelloRetryRequest-Cookie-Curve",
10862 config: Config{
10863 MaxVersion: VersionTLS13,
10864 // P-384 requires HelloRetryRequest in BoringSSL.
10865 CurvePreferences: []CurveID{CurveP384},
10866 Bugs: ProtocolBugs{
10867 SendHelloRetryRequestCookie: []byte("cookie"),
10868 ExpectMissingKeyShare: true,
10869 },
10870 },
10871 })
10872
10873 testCases = append(testCases, testCase{
10874 name: "HelloRetryRequest-Unknown",
10875 config: Config{
10876 MaxVersion: VersionTLS13,
10877 Bugs: ProtocolBugs{
10878 CustomHelloRetryRequestExtension: "extension",
10879 },
10880 },
10881 shouldFail: true,
10882 expectedError: ":UNEXPECTED_EXTENSION:",
10883 expectedLocalError: "remote error: unsupported extension",
10884 })
10885
10886 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010887 testType: serverTest,
10888 name: "SecondClientHelloMissingKeyShare",
10889 config: Config{
10890 MaxVersion: VersionTLS13,
10891 DefaultCurves: []CurveID{},
10892 Bugs: ProtocolBugs{
10893 SecondClientHelloMissingKeyShare: true,
10894 },
10895 },
10896 shouldFail: true,
10897 expectedError: ":MISSING_KEY_SHARE:",
10898 })
10899
10900 testCases = append(testCases, testCase{
10901 testType: serverTest,
10902 name: "SecondClientHelloWrongCurve",
10903 config: Config{
10904 MaxVersion: VersionTLS13,
10905 DefaultCurves: []CurveID{},
10906 Bugs: ProtocolBugs{
10907 MisinterpretHelloRetryRequestCurve: CurveP521,
10908 },
10909 },
10910 shouldFail: true,
10911 expectedError: ":WRONG_CURVE:",
10912 })
10913
10914 testCases = append(testCases, testCase{
10915 name: "HelloRetryRequestVersionMismatch",
10916 config: Config{
10917 MaxVersion: VersionTLS13,
10918 // P-384 requires HelloRetryRequest in BoringSSL.
10919 CurvePreferences: []CurveID{CurveP384},
10920 Bugs: ProtocolBugs{
10921 SendServerHelloVersion: 0x0305,
10922 },
10923 },
10924 shouldFail: true,
10925 expectedError: ":WRONG_VERSION_NUMBER:",
10926 })
10927
10928 testCases = append(testCases, testCase{
10929 name: "HelloRetryRequestCurveMismatch",
10930 config: Config{
10931 MaxVersion: VersionTLS13,
10932 // P-384 requires HelloRetryRequest in BoringSSL.
10933 CurvePreferences: []CurveID{CurveP384},
10934 Bugs: ProtocolBugs{
10935 // Send P-384 (correct) in the HelloRetryRequest.
10936 SendHelloRetryRequestCurve: CurveP384,
10937 // But send P-256 in the ServerHello.
10938 SendCurve: CurveP256,
10939 },
10940 },
10941 shouldFail: true,
10942 expectedError: ":WRONG_CURVE:",
10943 })
10944
10945 // Test the server selecting a curve that requires a HelloRetryRequest
10946 // without sending it.
10947 testCases = append(testCases, testCase{
10948 name: "SkipHelloRetryRequest",
10949 config: Config{
10950 MaxVersion: VersionTLS13,
10951 // P-384 requires HelloRetryRequest in BoringSSL.
10952 CurvePreferences: []CurveID{CurveP384},
10953 Bugs: ProtocolBugs{
10954 SkipHelloRetryRequest: true,
10955 },
10956 },
10957 shouldFail: true,
10958 expectedError: ":WRONG_CURVE:",
10959 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010960
10961 testCases = append(testCases, testCase{
10962 name: "TLS13-RequestContextInHandshake",
10963 config: Config{
10964 MaxVersion: VersionTLS13,
10965 MinVersion: VersionTLS13,
10966 ClientAuth: RequireAnyClientCert,
10967 Bugs: ProtocolBugs{
10968 SendRequestContext: []byte("request context"),
10969 },
10970 },
10971 flags: []string{
10972 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10973 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10974 },
10975 shouldFail: true,
10976 expectedError: ":DECODE_ERROR:",
10977 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010978
10979 testCases = append(testCases, testCase{
10980 testType: serverTest,
10981 name: "TLS13-TrailingKeyShareData",
10982 config: Config{
10983 MaxVersion: VersionTLS13,
10984 Bugs: ProtocolBugs{
10985 TrailingKeyShareData: true,
10986 },
10987 },
10988 shouldFail: true,
10989 expectedError: ":DECODE_ERROR:",
10990 })
David Benjamin7f78df42016-10-05 22:33:19 -040010991
10992 testCases = append(testCases, testCase{
10993 name: "TLS13-AlwaysSelectPSKIdentity",
10994 config: Config{
10995 MaxVersion: VersionTLS13,
10996 Bugs: ProtocolBugs{
10997 AlwaysSelectPSKIdentity: true,
10998 },
10999 },
11000 shouldFail: true,
11001 expectedError: ":UNEXPECTED_EXTENSION:",
11002 })
11003
11004 testCases = append(testCases, testCase{
11005 name: "TLS13-InvalidPSKIdentity",
11006 config: Config{
11007 MaxVersion: VersionTLS13,
11008 Bugs: ProtocolBugs{
11009 SelectPSKIdentityOnResume: 1,
11010 },
11011 },
11012 resumeSession: true,
11013 shouldFail: true,
11014 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11015 })
David Benjamin1286bee2016-10-07 15:25:06 -040011016
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011017 testCases = append(testCases, testCase{
11018 testType: serverTest,
11019 name: "TLS13-ExtraPSKIdentity",
11020 config: Config{
11021 MaxVersion: VersionTLS13,
11022 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011023 ExtraPSKIdentity: true,
11024 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011025 },
11026 },
11027 resumeSession: true,
11028 })
11029
David Benjamin1286bee2016-10-07 15:25:06 -040011030 // Test that unknown NewSessionTicket extensions are tolerated.
11031 testCases = append(testCases, testCase{
11032 name: "TLS13-CustomTicketExtension",
11033 config: Config{
11034 MaxVersion: VersionTLS13,
11035 Bugs: ProtocolBugs{
11036 CustomTicketExtension: "1234",
11037 },
11038 },
11039 })
Steven Valdez2d850622017-01-11 11:34:52 -050011040
Steven Valdez2d850622017-01-11 11:34:52 -050011041 testCases = append(testCases, testCase{
11042 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011043 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011044 config: Config{
11045 MaxVersion: VersionTLS13,
11046 MaxEarlyDataSize: 16384,
11047 },
11048 resumeConfig: &Config{
11049 MaxVersion: VersionTLS13,
11050 MaxEarlyDataSize: 16384,
11051 Bugs: ProtocolBugs{
11052 AlwaysRejectEarlyData: true,
11053 },
11054 },
11055 resumeSession: true,
11056 flags: []string{
11057 "-enable-early-data",
11058 "-expect-early-data-info",
11059 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011060 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011061 },
11062 })
11063
11064 testCases = append(testCases, testCase{
11065 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011066 name: "TLS13Experiment-EarlyData-Reject-Client",
11067 config: Config{
11068 MaxVersion: VersionTLS13,
11069 MaxEarlyDataSize: 16384,
11070 TLS13Variant: TLS13Experiment,
11071 },
11072 resumeConfig: &Config{
11073 MaxVersion: VersionTLS13,
11074 TLS13Variant: TLS13Experiment,
11075 MaxEarlyDataSize: 16384,
11076 Bugs: ProtocolBugs{
11077 AlwaysRejectEarlyData: true,
11078 },
11079 },
11080 resumeSession: true,
11081 flags: []string{
11082 "-enable-early-data",
11083 "-expect-early-data-info",
11084 "-expect-reject-early-data",
11085 "-on-resume-shim-writes-first",
11086 "-tls13-variant", "1",
11087 },
11088 })
11089
11090 testCases = append(testCases, testCase{
11091 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011092 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11093 config: Config{
11094 MaxVersion: VersionTLS13,
11095 MaxEarlyDataSize: 16384,
11096 TLS13Variant: TLS13RecordTypeExperiment,
11097 },
11098 resumeConfig: &Config{
11099 MaxVersion: VersionTLS13,
11100 TLS13Variant: TLS13RecordTypeExperiment,
11101 MaxEarlyDataSize: 16384,
11102 Bugs: ProtocolBugs{
11103 AlwaysRejectEarlyData: true,
11104 },
11105 },
11106 resumeSession: true,
11107 flags: []string{
11108 "-enable-early-data",
11109 "-expect-early-data-info",
11110 "-expect-reject-early-data",
11111 "-on-resume-shim-writes-first",
11112 "-tls13-variant", "2",
11113 },
11114 })
11115
11116 testCases = append(testCases, testCase{
11117 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011118 name: "TLS13-EarlyData-RejectTicket-Client",
11119 config: Config{
11120 MaxVersion: VersionTLS13,
11121 MaxEarlyDataSize: 16384,
11122 Certificates: []Certificate{rsaCertificate},
11123 },
11124 resumeConfig: &Config{
11125 MaxVersion: VersionTLS13,
11126 MaxEarlyDataSize: 16384,
11127 Certificates: []Certificate{ecdsaP256Certificate},
11128 SessionTicketsDisabled: true,
11129 },
11130 resumeSession: true,
11131 expectResumeRejected: true,
11132 flags: []string{
11133 "-enable-early-data",
11134 "-expect-early-data-info",
11135 "-expect-reject-early-data",
11136 "-on-resume-shim-writes-first",
11137 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11138 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11139 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11140 // Session tickets are disabled, so the runner will not send a ticket.
11141 "-on-retry-expect-no-session",
11142 },
11143 })
11144
11145 testCases = append(testCases, testCase{
11146 testType: clientTest,
11147 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011148 config: Config{
11149 MaxVersion: VersionTLS13,
11150 MaxEarlyDataSize: 16384,
11151 },
11152 resumeConfig: &Config{
11153 MaxVersion: VersionTLS13,
11154 MaxEarlyDataSize: 16384,
11155 Bugs: ProtocolBugs{
11156 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11157 },
11158 },
11159 resumeSession: true,
11160 flags: []string{
11161 "-enable-early-data",
11162 "-expect-early-data-info",
11163 "-expect-reject-early-data",
11164 },
11165 })
11166
11167 // The client must check the server does not send the early_data
11168 // extension while rejecting the session.
11169 testCases = append(testCases, testCase{
11170 testType: clientTest,
11171 name: "TLS13-EarlyDataWithoutResume-Client",
11172 config: Config{
11173 MaxVersion: VersionTLS13,
11174 MaxEarlyDataSize: 16384,
11175 },
11176 resumeConfig: &Config{
11177 MaxVersion: VersionTLS13,
11178 SessionTicketsDisabled: true,
11179 Bugs: ProtocolBugs{
11180 SendEarlyDataExtension: true,
11181 },
11182 },
11183 resumeSession: true,
11184 flags: []string{
11185 "-enable-early-data",
11186 "-expect-early-data-info",
11187 },
11188 shouldFail: true,
11189 expectedError: ":UNEXPECTED_EXTENSION:",
11190 })
11191
11192 // The client must fail with a dedicated error code if the server
11193 // responds with TLS 1.2 when offering 0-RTT.
11194 testCases = append(testCases, testCase{
11195 testType: clientTest,
11196 name: "TLS13-EarlyDataVersionDowngrade-Client",
11197 config: Config{
11198 MaxVersion: VersionTLS13,
11199 MaxEarlyDataSize: 16384,
11200 },
11201 resumeConfig: &Config{
11202 MaxVersion: VersionTLS12,
11203 },
11204 resumeSession: true,
11205 flags: []string{
11206 "-enable-early-data",
11207 "-expect-early-data-info",
11208 },
11209 shouldFail: true,
11210 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11211 })
11212
11213 // Test that the client rejects an (unsolicited) early_data extension if
11214 // the server sent an HRR.
11215 testCases = append(testCases, testCase{
11216 testType: clientTest,
11217 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11218 config: Config{
11219 MaxVersion: VersionTLS13,
11220 MaxEarlyDataSize: 16384,
11221 },
11222 resumeConfig: &Config{
11223 MaxVersion: VersionTLS13,
11224 MaxEarlyDataSize: 16384,
11225 Bugs: ProtocolBugs{
11226 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11227 SendEarlyDataExtension: true,
11228 },
11229 },
11230 resumeSession: true,
11231 flags: []string{
11232 "-enable-early-data",
11233 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011234 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011235 },
11236 shouldFail: true,
11237 expectedError: ":UNEXPECTED_EXTENSION:",
11238 })
11239
11240 fooString := "foo"
11241 barString := "bar"
11242
11243 // Test that the client reports the correct ALPN after a 0-RTT reject
11244 // that changed it.
11245 testCases = append(testCases, testCase{
11246 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011247 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011248 config: Config{
11249 MaxVersion: VersionTLS13,
11250 MaxEarlyDataSize: 16384,
11251 Bugs: ProtocolBugs{
11252 ALPNProtocol: &fooString,
11253 },
11254 },
11255 resumeConfig: &Config{
11256 MaxVersion: VersionTLS13,
11257 MaxEarlyDataSize: 16384,
11258 Bugs: ProtocolBugs{
11259 ALPNProtocol: &barString,
11260 },
11261 },
11262 resumeSession: true,
11263 flags: []string{
11264 "-advertise-alpn", "\x03foo\x03bar",
11265 "-enable-early-data",
11266 "-expect-early-data-info",
11267 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011268 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011269 "-on-resume-expect-alpn", "foo",
11270 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011271 },
11272 })
11273
11274 // Test that the client reports the correct ALPN after a 0-RTT reject if
11275 // ALPN was omitted from the first connection.
11276 testCases = append(testCases, testCase{
11277 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011278 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011279 config: Config{
11280 MaxVersion: VersionTLS13,
11281 MaxEarlyDataSize: 16384,
11282 },
11283 resumeConfig: &Config{
11284 MaxVersion: VersionTLS13,
11285 MaxEarlyDataSize: 16384,
11286 NextProtos: []string{"foo"},
11287 },
11288 resumeSession: true,
11289 flags: []string{
11290 "-advertise-alpn", "\x03foo\x03bar",
11291 "-enable-early-data",
11292 "-expect-early-data-info",
11293 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011294 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011295 "-on-resume-expect-alpn", "",
11296 "-on-retry-expect-alpn", "foo",
11297 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011298 },
11299 })
11300
11301 // Test that the client reports the correct ALPN after a 0-RTT reject if
11302 // ALPN was omitted from the second connection.
11303 testCases = append(testCases, testCase{
11304 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011305 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011306 config: Config{
11307 MaxVersion: VersionTLS13,
11308 MaxEarlyDataSize: 16384,
11309 NextProtos: []string{"foo"},
11310 },
11311 resumeConfig: &Config{
11312 MaxVersion: VersionTLS13,
11313 MaxEarlyDataSize: 16384,
11314 },
11315 resumeSession: true,
11316 flags: []string{
11317 "-advertise-alpn", "\x03foo\x03bar",
11318 "-enable-early-data",
11319 "-expect-early-data-info",
11320 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011321 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011322 "-on-resume-expect-alpn", "foo",
11323 "-on-retry-expect-alpn", "",
11324 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011325 },
11326 })
11327
11328 // Test that the client enforces ALPN match on 0-RTT accept.
11329 testCases = append(testCases, testCase{
11330 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011331 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011332 config: Config{
11333 MaxVersion: VersionTLS13,
11334 MaxEarlyDataSize: 16384,
11335 Bugs: ProtocolBugs{
11336 ALPNProtocol: &fooString,
11337 },
11338 },
11339 resumeConfig: &Config{
11340 MaxVersion: VersionTLS13,
11341 MaxEarlyDataSize: 16384,
11342 Bugs: ProtocolBugs{
11343 AlwaysAcceptEarlyData: true,
11344 ALPNProtocol: &barString,
11345 },
11346 },
11347 resumeSession: true,
11348 flags: []string{
11349 "-advertise-alpn", "\x03foo\x03bar",
11350 "-enable-early-data",
11351 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011352 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011353 "-on-resume-expect-alpn", "foo",
11354 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011355 },
11356 shouldFail: true,
11357 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11358 })
11359
11360 // Test that the server correctly rejects 0-RTT when the previous
11361 // session did not allow early data on resumption.
11362 testCases = append(testCases, testCase{
11363 testType: serverTest,
11364 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11365 config: Config{
11366 MaxVersion: VersionTLS13,
11367 },
11368 resumeConfig: &Config{
11369 MaxVersion: VersionTLS13,
11370 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011371 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011372 ExpectEarlyDataAccepted: false,
11373 },
11374 },
11375 resumeSession: true,
11376 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011377 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011378 "-expect-reject-early-data",
11379 },
11380 })
11381
11382 // Test that we reject early data where ALPN is omitted from the first
11383 // connection.
11384 testCases = append(testCases, testCase{
11385 testType: serverTest,
11386 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11387 config: Config{
11388 MaxVersion: VersionTLS13,
11389 NextProtos: []string{},
11390 },
11391 resumeConfig: &Config{
11392 MaxVersion: VersionTLS13,
11393 NextProtos: []string{"foo"},
11394 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011395 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011396 ExpectEarlyDataAccepted: false,
11397 },
11398 },
11399 resumeSession: true,
11400 flags: []string{
11401 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011402 "-on-initial-select-alpn", "",
11403 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011404 },
11405 })
11406
11407 // Test that we reject early data where ALPN is omitted from the second
11408 // connection.
11409 testCases = append(testCases, testCase{
11410 testType: serverTest,
11411 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11412 config: Config{
11413 MaxVersion: VersionTLS13,
11414 NextProtos: []string{"foo"},
11415 },
11416 resumeConfig: &Config{
11417 MaxVersion: VersionTLS13,
11418 NextProtos: []string{},
11419 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011420 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011421 ExpectEarlyDataAccepted: false,
11422 },
11423 },
11424 resumeSession: true,
11425 flags: []string{
11426 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011427 "-on-initial-select-alpn", "foo",
11428 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011429 },
11430 })
11431
11432 // Test that we reject early data with mismatched ALPN.
11433 testCases = append(testCases, testCase{
11434 testType: serverTest,
11435 name: "TLS13-EarlyData-ALPNMismatch-Server",
11436 config: Config{
11437 MaxVersion: VersionTLS13,
11438 NextProtos: []string{"foo"},
11439 },
11440 resumeConfig: &Config{
11441 MaxVersion: VersionTLS13,
11442 NextProtos: []string{"bar"},
11443 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011444 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011445 ExpectEarlyDataAccepted: false,
11446 },
11447 },
11448 resumeSession: true,
11449 flags: []string{
11450 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011451 "-on-initial-select-alpn", "foo",
11452 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011453 },
11454 })
11455
David Benjamin6bb507b2017-03-29 16:35:57 -050011456 // Test that the client offering 0-RTT and Channel ID forbids the server
11457 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011458 testCases = append(testCases, testCase{
11459 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011460 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011461 config: Config{
11462 MaxVersion: VersionTLS13,
11463 MaxEarlyDataSize: 16384,
11464 RequestChannelID: true,
11465 },
11466 resumeSession: true,
11467 expectChannelID: true,
11468 shouldFail: true,
11469 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11470 flags: []string{
11471 "-enable-early-data",
11472 "-expect-early-data-info",
11473 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11474 },
11475 })
11476
David Benjamin6bb507b2017-03-29 16:35:57 -050011477 // Test that the client offering Channel ID and 0-RTT allows the server
11478 // to decline 0-RTT.
11479 testCases = append(testCases, testCase{
11480 testType: clientTest,
11481 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11482 config: Config{
11483 MaxVersion: VersionTLS13,
11484 MaxEarlyDataSize: 16384,
11485 RequestChannelID: true,
11486 Bugs: ProtocolBugs{
11487 AlwaysRejectEarlyData: true,
11488 },
11489 },
11490 resumeSession: true,
11491 expectChannelID: true,
11492 flags: []string{
11493 "-enable-early-data",
11494 "-expect-early-data-info",
11495 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11496 "-expect-reject-early-data",
11497 },
11498 })
11499
11500 // Test that the client offering Channel ID and 0-RTT allows the server
11501 // to decline Channel ID.
11502 testCases = append(testCases, testCase{
11503 testType: clientTest,
11504 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11505 config: Config{
11506 MaxVersion: VersionTLS13,
11507 MaxEarlyDataSize: 16384,
11508 },
11509 resumeSession: true,
11510 flags: []string{
11511 "-enable-early-data",
11512 "-expect-early-data-info",
11513 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11514 "-expect-accept-early-data",
11515 },
11516 })
11517
11518 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11519 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011520 testCases = append(testCases, testCase{
11521 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011522 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011523 config: Config{
11524 MaxVersion: VersionTLS13,
11525 ChannelID: channelIDKey,
11526 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011527 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011528 ExpectEarlyDataAccepted: false,
11529 },
11530 },
11531 resumeSession: true,
11532 expectChannelID: true,
11533 flags: []string{
11534 "-enable-early-data",
11535 "-expect-reject-early-data",
11536 "-expect-channel-id",
11537 base64.StdEncoding.EncodeToString(channelIDBytes),
11538 },
11539 })
11540
David Benjamin6bb507b2017-03-29 16:35:57 -050011541 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11542 // if not offered Channel ID.
11543 testCases = append(testCases, testCase{
11544 testType: serverTest,
11545 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11546 config: Config{
11547 MaxVersion: VersionTLS13,
11548 Bugs: ProtocolBugs{
11549 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11550 ExpectEarlyDataAccepted: true,
11551 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11552 },
11553 },
11554 resumeSession: true,
11555 expectChannelID: false,
11556 flags: []string{
11557 "-enable-early-data",
11558 "-expect-accept-early-data",
11559 "-enable-channel-id",
11560 },
11561 })
11562
David Benjamin32c89272017-03-26 13:54:21 -050011563 // Test that the server rejects 0-RTT streams without end_of_early_data.
11564 // The subsequent records should fail to decrypt.
11565 testCases = append(testCases, testCase{
11566 testType: serverTest,
11567 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11568 config: Config{
11569 MaxVersion: VersionTLS13,
11570 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011571 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011572 ExpectEarlyDataAccepted: true,
11573 SkipEndOfEarlyData: true,
11574 },
11575 },
11576 resumeSession: true,
11577 flags: []string{"-enable-early-data"},
11578 shouldFail: true,
11579 expectedLocalError: "remote error: bad record MAC",
11580 expectedError: ":BAD_DECRYPT:",
11581 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011582
11583 testCases = append(testCases, testCase{
11584 testType: serverTest,
11585 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11586 config: Config{
11587 MaxVersion: VersionTLS13,
11588 },
11589 resumeConfig: &Config{
11590 MaxVersion: VersionTLS13,
11591 Bugs: ProtocolBugs{
11592 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11593 SendStrayEarlyHandshake: true,
11594 ExpectEarlyDataAccepted: true},
11595 },
11596 resumeSession: true,
11597 shouldFail: true,
11598 expectedError: ":UNEXPECTED_RECORD:",
11599 expectedLocalError: "remote error: unexpected message",
11600 flags: []string{
11601 "-enable-early-data",
11602 },
11603 })
David Benjamind9cbb532017-07-07 13:17:19 -040011604
11605 // Test that the client reports TLS 1.3 as the version while sending
11606 // early data.
11607 testCases = append(testCases, testCase{
11608 testType: clientTest,
11609 name: "TLS13-EarlyData-Client-VersionAPI",
11610 config: Config{
11611 MaxVersion: VersionTLS13,
11612 MaxEarlyDataSize: 16384,
11613 },
11614 resumeSession: true,
11615 flags: []string{
11616 "-enable-early-data",
11617 "-expect-early-data-info",
11618 "-expect-accept-early-data",
11619 "-expect-version", strconv.Itoa(VersionTLS13),
11620 },
11621 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011622}
11623
David Benjaminabbbee12016-10-31 19:20:42 -040011624func addTLS13CipherPreferenceTests() {
11625 // Test that client preference is honored if the shim has AES hardware
11626 // and ChaCha20-Poly1305 is preferred otherwise.
11627 testCases = append(testCases, testCase{
11628 testType: serverTest,
11629 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11630 config: Config{
11631 MaxVersion: VersionTLS13,
11632 CipherSuites: []uint16{
11633 TLS_CHACHA20_POLY1305_SHA256,
11634 TLS_AES_128_GCM_SHA256,
11635 },
11636 },
11637 flags: []string{
11638 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11639 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11640 },
11641 })
11642
11643 testCases = append(testCases, testCase{
11644 testType: serverTest,
11645 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11646 config: Config{
11647 MaxVersion: VersionTLS13,
11648 CipherSuites: []uint16{
11649 TLS_AES_128_GCM_SHA256,
11650 TLS_CHACHA20_POLY1305_SHA256,
11651 },
11652 },
11653 flags: []string{
11654 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11655 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11656 },
11657 })
11658
11659 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11660 // whether it has AES hardware.
11661 testCases = append(testCases, testCase{
11662 name: "TLS13-CipherPreference-Client",
11663 config: Config{
11664 MaxVersion: VersionTLS13,
11665 // Use the client cipher order. (This is the default but
11666 // is listed to be explicit.)
11667 PreferServerCipherSuites: false,
11668 },
11669 flags: []string{
11670 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11671 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11672 },
11673 })
11674}
11675
David Benjaminf3fbade2016-09-19 13:08:16 -040011676func addPeekTests() {
11677 // Test SSL_peek works, including on empty records.
11678 testCases = append(testCases, testCase{
11679 name: "Peek-Basic",
11680 sendEmptyRecords: 1,
11681 flags: []string{"-peek-then-read"},
11682 })
11683
11684 // Test SSL_peek can drive the initial handshake.
11685 testCases = append(testCases, testCase{
11686 name: "Peek-ImplicitHandshake",
11687 flags: []string{
11688 "-peek-then-read",
11689 "-implicit-handshake",
11690 },
11691 })
11692
11693 // Test SSL_peek can discover and drive a renegotiation.
11694 testCases = append(testCases, testCase{
11695 name: "Peek-Renegotiate",
11696 config: Config{
11697 MaxVersion: VersionTLS12,
11698 },
11699 renegotiate: 1,
11700 flags: []string{
11701 "-peek-then-read",
11702 "-renegotiate-freely",
11703 "-expect-total-renegotiations", "1",
11704 },
11705 })
11706
11707 // Test SSL_peek can discover a close_notify.
11708 testCases = append(testCases, testCase{
11709 name: "Peek-Shutdown",
11710 config: Config{
11711 Bugs: ProtocolBugs{
11712 ExpectCloseNotify: true,
11713 },
11714 },
11715 flags: []string{
11716 "-peek-then-read",
11717 "-check-close-notify",
11718 },
11719 })
11720
11721 // Test SSL_peek can discover an alert.
11722 testCases = append(testCases, testCase{
11723 name: "Peek-Alert",
11724 config: Config{
11725 Bugs: ProtocolBugs{
11726 SendSpuriousAlert: alertRecordOverflow,
11727 },
11728 },
11729 flags: []string{"-peek-then-read"},
11730 shouldFail: true,
11731 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11732 })
11733
11734 // Test SSL_peek can handle KeyUpdate.
11735 testCases = append(testCases, testCase{
11736 name: "Peek-KeyUpdate",
11737 config: Config{
11738 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011739 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011740 sendKeyUpdates: 1,
11741 keyUpdateRequest: keyUpdateNotRequested,
11742 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011743 })
11744}
11745
David Benjamine6f22212016-11-08 14:28:24 -050011746func addRecordVersionTests() {
11747 for _, ver := range tlsVersions {
11748 // Test that the record version is enforced.
11749 testCases = append(testCases, testCase{
11750 name: "CheckRecordVersion-" + ver.name,
11751 config: Config{
11752 MinVersion: ver.version,
11753 MaxVersion: ver.version,
11754 Bugs: ProtocolBugs{
11755 SendRecordVersion: 0x03ff,
11756 },
11757 },
David Benjamina5022392017-07-10 17:40:39 -040011758 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011759 shouldFail: true,
11760 expectedError: ":WRONG_VERSION_NUMBER:",
11761 })
11762
11763 // Test that the ClientHello may use any record version, for
11764 // compatibility reasons.
11765 testCases = append(testCases, testCase{
11766 testType: serverTest,
11767 name: "LooseInitialRecordVersion-" + ver.name,
11768 config: Config{
11769 MinVersion: ver.version,
11770 MaxVersion: ver.version,
11771 Bugs: ProtocolBugs{
11772 SendInitialRecordVersion: 0x03ff,
11773 },
11774 },
David Benjamina5022392017-07-10 17:40:39 -040011775 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011776 })
11777
11778 // Test that garbage ClientHello record versions are rejected.
11779 testCases = append(testCases, testCase{
11780 testType: serverTest,
11781 name: "GarbageInitialRecordVersion-" + ver.name,
11782 config: Config{
11783 MinVersion: ver.version,
11784 MaxVersion: ver.version,
11785 Bugs: ProtocolBugs{
11786 SendInitialRecordVersion: 0xffff,
11787 },
11788 },
David Benjamina5022392017-07-10 17:40:39 -040011789 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011790 shouldFail: true,
11791 expectedError: ":WRONG_VERSION_NUMBER:",
11792 })
11793 }
11794}
11795
David Benjamin2c516452016-11-15 10:16:54 +090011796func addCertificateTests() {
11797 // Test that a certificate chain with intermediate may be sent and
11798 // received as both client and server.
11799 for _, ver := range tlsVersions {
11800 testCases = append(testCases, testCase{
11801 testType: clientTest,
11802 name: "SendReceiveIntermediate-Client-" + ver.name,
11803 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011804 MinVersion: ver.version,
11805 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011806 Certificates: []Certificate{rsaChainCertificate},
11807 ClientAuth: RequireAnyClientCert,
11808 },
David Benjamina5022392017-07-10 17:40:39 -040011809 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011810 expectPeerCertificate: &rsaChainCertificate,
11811 flags: []string{
11812 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11813 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11814 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11815 },
11816 })
11817
11818 testCases = append(testCases, testCase{
11819 testType: serverTest,
11820 name: "SendReceiveIntermediate-Server-" + ver.name,
11821 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011822 MinVersion: ver.version,
11823 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011824 Certificates: []Certificate{rsaChainCertificate},
11825 },
David Benjamina5022392017-07-10 17:40:39 -040011826 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011827 expectPeerCertificate: &rsaChainCertificate,
11828 flags: []string{
11829 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11830 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11831 "-require-any-client-certificate",
11832 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11833 },
11834 })
11835 }
11836}
11837
David Benjaminbbaf3672016-11-17 10:53:09 +090011838func addRetainOnlySHA256ClientCertTests() {
11839 for _, ver := range tlsVersions {
11840 // Test that enabling
11841 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11842 // actually requesting a client certificate is a no-op.
11843 testCases = append(testCases, testCase{
11844 testType: serverTest,
11845 name: "RetainOnlySHA256-NoCert-" + ver.name,
11846 config: Config{
11847 MinVersion: ver.version,
11848 MaxVersion: ver.version,
11849 },
David Benjamina5022392017-07-10 17:40:39 -040011850 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011851 flags: []string{
11852 "-retain-only-sha256-client-cert-initial",
11853 "-retain-only-sha256-client-cert-resume",
11854 },
11855 resumeSession: true,
11856 })
11857
11858 // Test that when retaining only a SHA-256 certificate is
11859 // enabled, the hash appears as expected.
11860 testCases = append(testCases, testCase{
11861 testType: serverTest,
11862 name: "RetainOnlySHA256-Cert-" + ver.name,
11863 config: Config{
11864 MinVersion: ver.version,
11865 MaxVersion: ver.version,
11866 Certificates: []Certificate{rsaCertificate},
11867 },
David Benjamina5022392017-07-10 17:40:39 -040011868 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011869 flags: []string{
11870 "-verify-peer",
11871 "-retain-only-sha256-client-cert-initial",
11872 "-retain-only-sha256-client-cert-resume",
11873 "-expect-sha256-client-cert-initial",
11874 "-expect-sha256-client-cert-resume",
11875 },
11876 resumeSession: true,
11877 })
11878
11879 // Test that when the config changes from on to off, a
11880 // resumption is rejected because the server now wants the full
11881 // certificate chain.
11882 testCases = append(testCases, testCase{
11883 testType: serverTest,
11884 name: "RetainOnlySHA256-OnOff-" + ver.name,
11885 config: Config{
11886 MinVersion: ver.version,
11887 MaxVersion: ver.version,
11888 Certificates: []Certificate{rsaCertificate},
11889 },
David Benjamina5022392017-07-10 17:40:39 -040011890 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011891 flags: []string{
11892 "-verify-peer",
11893 "-retain-only-sha256-client-cert-initial",
11894 "-expect-sha256-client-cert-initial",
11895 },
11896 resumeSession: true,
11897 expectResumeRejected: true,
11898 })
11899
11900 // Test that when the config changes from off to on, a
11901 // resumption is rejected because the server now wants just the
11902 // hash.
11903 testCases = append(testCases, testCase{
11904 testType: serverTest,
11905 name: "RetainOnlySHA256-OffOn-" + ver.name,
11906 config: Config{
11907 MinVersion: ver.version,
11908 MaxVersion: ver.version,
11909 Certificates: []Certificate{rsaCertificate},
11910 },
David Benjamina5022392017-07-10 17:40:39 -040011911 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011912 flags: []string{
11913 "-verify-peer",
11914 "-retain-only-sha256-client-cert-resume",
11915 "-expect-sha256-client-cert-resume",
11916 },
11917 resumeSession: true,
11918 expectResumeRejected: true,
11919 })
11920 }
11921}
11922
Adam Langleya4b91982016-12-12 12:05:53 -080011923func addECDSAKeyUsageTests() {
11924 p256 := elliptic.P256()
11925 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11926 if err != nil {
11927 panic(err)
11928 }
11929
11930 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11931 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11932 if err != nil {
11933 panic(err)
11934 }
11935
11936 template := x509.Certificate{
11937 SerialNumber: serialNumber,
11938 Subject: pkix.Name{
11939 Organization: []string{"Acme Co"},
11940 },
11941 NotBefore: time.Now(),
11942 NotAfter: time.Now(),
11943
11944 // An ECC certificate with only the keyAgreement key usgae may
11945 // be used with ECDH, but not ECDSA.
11946 KeyUsage: x509.KeyUsageKeyAgreement,
11947 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11948 BasicConstraintsValid: true,
11949 }
11950
11951 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11952 if err != nil {
11953 panic(err)
11954 }
11955
11956 cert := Certificate{
11957 Certificate: [][]byte{derBytes},
11958 PrivateKey: priv,
11959 }
11960
11961 for _, ver := range tlsVersions {
11962 if ver.version < VersionTLS12 {
11963 continue
11964 }
11965
11966 testCases = append(testCases, testCase{
11967 testType: clientTest,
11968 name: "ECDSAKeyUsage-" + ver.name,
11969 config: Config{
11970 MinVersion: ver.version,
11971 MaxVersion: ver.version,
11972 Certificates: []Certificate{cert},
11973 },
David Benjamina5022392017-07-10 17:40:39 -040011974 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080011975 shouldFail: true,
11976 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11977 })
11978 }
11979}
11980
David Benjamin8c26d752017-03-26 15:13:51 -050011981func addExtraHandshakeTests() {
11982 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11983 // to ensure there is no transport I/O.
11984 testCases = append(testCases, testCase{
11985 testType: clientTest,
11986 name: "ExtraHandshake-Client-TLS12",
11987 config: Config{
11988 MinVersion: VersionTLS12,
11989 MaxVersion: VersionTLS12,
11990 },
11991 flags: []string{
11992 "-async",
11993 "-no-op-extra-handshake",
11994 },
11995 })
11996 testCases = append(testCases, testCase{
11997 testType: serverTest,
11998 name: "ExtraHandshake-Server-TLS12",
11999 config: Config{
12000 MinVersion: VersionTLS12,
12001 MaxVersion: VersionTLS12,
12002 },
12003 flags: []string{
12004 "-async",
12005 "-no-op-extra-handshake",
12006 },
12007 })
12008 testCases = append(testCases, testCase{
12009 testType: clientTest,
12010 name: "ExtraHandshake-Client-TLS13",
12011 config: Config{
12012 MinVersion: VersionTLS13,
12013 MaxVersion: VersionTLS13,
12014 },
12015 flags: []string{
12016 "-async",
12017 "-no-op-extra-handshake",
12018 },
12019 })
12020 testCases = append(testCases, testCase{
12021 testType: serverTest,
12022 name: "ExtraHandshake-Server-TLS13",
12023 config: Config{
12024 MinVersion: VersionTLS13,
12025 MaxVersion: VersionTLS13,
12026 },
12027 flags: []string{
12028 "-async",
12029 "-no-op-extra-handshake",
12030 },
12031 })
12032
12033 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12034 testCases = append(testCases, testCase{
12035 testType: serverTest,
12036 name: "ExtraHandshake-Server-EarlyData-TLS13",
12037 config: Config{
12038 MaxVersion: VersionTLS13,
12039 MinVersion: VersionTLS13,
12040 Bugs: ProtocolBugs{
12041 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12042 ExpectEarlyDataAccepted: true,
12043 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12044 },
12045 },
12046 messageCount: 2,
12047 resumeSession: true,
12048 flags: []string{
12049 "-async",
12050 "-enable-early-data",
12051 "-expect-accept-early-data",
12052 "-no-op-extra-handshake",
12053 },
12054 })
12055
12056 // An extra SSL_do_handshake drives the handshake to completion in False
12057 // Start. We test this by handshaking twice and asserting the False
12058 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12059 // how the test works.
12060 testCases = append(testCases, testCase{
12061 testType: clientTest,
12062 name: "ExtraHandshake-FalseStart",
12063 config: Config{
12064 MaxVersion: VersionTLS12,
12065 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12066 NextProtos: []string{"foo"},
12067 Bugs: ProtocolBugs{
12068 ExpectFalseStart: true,
12069 AlertBeforeFalseStartTest: alertAccessDenied,
12070 },
12071 },
12072 flags: []string{
12073 "-handshake-twice",
12074 "-false-start",
12075 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012076 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012077 },
12078 shimWritesFirst: true,
12079 shouldFail: true,
12080 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12081 expectedLocalError: "tls: peer did not false start: EOF",
12082 })
12083}
12084
David Benjaminb853f312017-07-14 18:40:34 -040012085// Test that omitted and empty extensions blocks are tolerated.
12086func addOmitExtensionsTests() {
12087 for _, ver := range tlsVersions {
12088 if ver.version > VersionTLS12 {
12089 continue
12090 }
12091
12092 testCases = append(testCases, testCase{
12093 testType: serverTest,
12094 name: "OmitExtensions-ClientHello-" + ver.name,
12095 config: Config{
12096 MinVersion: ver.version,
12097 MaxVersion: ver.version,
12098 SessionTicketsDisabled: true,
12099 Bugs: ProtocolBugs{
12100 OmitExtensions: true,
12101 },
12102 },
12103 })
12104
12105 testCases = append(testCases, testCase{
12106 testType: serverTest,
12107 name: "EmptyExtensions-ClientHello-" + ver.name,
12108 config: Config{
12109 MinVersion: ver.version,
12110 MaxVersion: ver.version,
12111 SessionTicketsDisabled: true,
12112 Bugs: ProtocolBugs{
12113 EmptyExtensions: true,
12114 },
12115 },
12116 })
12117
12118 testCases = append(testCases, testCase{
12119 testType: clientTest,
12120 name: "OmitExtensions-ServerHello-" + ver.name,
12121 config: Config{
12122 MinVersion: ver.version,
12123 MaxVersion: ver.version,
12124 SessionTicketsDisabled: true,
12125 Bugs: ProtocolBugs{
12126 OmitExtensions: true,
12127 // Disable all ServerHello extensions so
12128 // OmitExtensions works.
12129 NoExtendedMasterSecret: true,
12130 NoRenegotiationInfo: true,
12131 },
12132 },
12133 })
12134
12135 testCases = append(testCases, testCase{
12136 testType: clientTest,
12137 name: "EmptyExtensions-ServerHello-" + ver.name,
12138 config: Config{
12139 MinVersion: ver.version,
12140 MaxVersion: ver.version,
12141 SessionTicketsDisabled: true,
12142 Bugs: ProtocolBugs{
12143 EmptyExtensions: true,
12144 // Disable all ServerHello extensions so
12145 // EmptyExtensions works.
12146 NoExtendedMasterSecret: true,
12147 NoRenegotiationInfo: true,
12148 },
12149 },
12150 })
12151 }
12152}
12153
Adam Langley7c803a62015-06-15 15:35:05 -070012154func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012155 defer wg.Done()
12156
12157 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012158 var err error
12159
David Benjaminba28dfc2016-11-15 17:47:21 +090012160 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012161 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12162 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012163 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012164 if err != nil {
12165 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12166 }
12167 break
12168 }
12169 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012170 } else if *repeatUntilFailure {
12171 for err == nil {
12172 statusChan <- statusMsg{test: test, started: true}
12173 err = runTest(test, shimPath, -1)
12174 }
12175 } else {
12176 statusChan <- statusMsg{test: test, started: true}
12177 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012178 }
Adam Langley95c29f32014-06-20 12:00:00 -070012179 statusChan <- statusMsg{test: test, err: err}
12180 }
12181}
12182
12183type statusMsg struct {
12184 test *testCase
12185 started bool
12186 err error
12187}
12188
David Benjamin5f237bc2015-02-11 17:14:15 -050012189func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012190 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012191
David Benjamin5f237bc2015-02-11 17:14:15 -050012192 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012193 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012194 if !*pipe {
12195 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012196 var erase string
12197 for i := 0; i < lineLen; i++ {
12198 erase += "\b \b"
12199 }
12200 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012201 }
12202
Adam Langley95c29f32014-06-20 12:00:00 -070012203 if msg.started {
12204 started++
12205 } else {
12206 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012207
12208 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012209 if msg.err == errUnimplemented {
12210 if *pipe {
12211 // Print each test instead of a status line.
12212 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12213 }
12214 unimplemented++
12215 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12216 } else {
12217 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12218 failed++
12219 testOutput.addResult(msg.test.name, "FAIL")
12220 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012221 } else {
12222 if *pipe {
12223 // Print each test instead of a status line.
12224 fmt.Printf("PASSED (%s)\n", msg.test.name)
12225 }
12226 testOutput.addResult(msg.test.name, "PASS")
12227 }
Adam Langley95c29f32014-06-20 12:00:00 -070012228 }
12229
David Benjamin5f237bc2015-02-11 17:14:15 -050012230 if !*pipe {
12231 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012232 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012233 lineLen = len(line)
12234 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012235 }
Adam Langley95c29f32014-06-20 12:00:00 -070012236 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012237
12238 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012239}
12240
12241func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012242 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012243 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012244 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012245
Adam Langley7c803a62015-06-15 15:35:05 -070012246 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012247 addCipherSuiteTests()
12248 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012249 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012250 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012251 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012252 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012253 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012254 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012255 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012256 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012257 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012258 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012259 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012260 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012261 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012262 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012263 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012264 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012265 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012266 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012267 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012268 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012269 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012270 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012271 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012272 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012273 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012274 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012275 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012276 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012277 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012278 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012279 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012280 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012281 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012282
12283 var wg sync.WaitGroup
12284
Adam Langley7c803a62015-06-15 15:35:05 -070012285 statusChan := make(chan statusMsg, *numWorkers)
12286 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012287 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012288
EKRf71d7ed2016-08-06 13:25:12 -070012289 if len(*shimConfigFile) != 0 {
12290 encoded, err := ioutil.ReadFile(*shimConfigFile)
12291 if err != nil {
12292 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12293 os.Exit(1)
12294 }
12295
12296 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12297 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12298 os.Exit(1)
12299 }
12300 }
12301
David Benjamin025b3d32014-07-01 19:53:04 -040012302 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012303
Adam Langley7c803a62015-06-15 15:35:05 -070012304 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012305 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012306 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012307 }
12308
David Benjamin270f0a72016-03-17 14:41:36 -040012309 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012310 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012311 matched := true
12312 if len(*testToRun) != 0 {
12313 var err error
12314 matched, err = filepath.Match(*testToRun, testCases[i].name)
12315 if err != nil {
12316 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12317 os.Exit(1)
12318 }
12319 }
12320
EKRf71d7ed2016-08-06 13:25:12 -070012321 if !*includeDisabled {
12322 for pattern := range shimConfig.DisabledTests {
12323 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12324 if err != nil {
12325 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12326 os.Exit(1)
12327 }
12328
12329 if isDisabled {
12330 matched = false
12331 break
12332 }
12333 }
12334 }
12335
David Benjamin17e12922016-07-28 18:04:43 -040012336 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012337 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012338 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012339
12340 // Only run one test if repeating until failure.
12341 if *repeatUntilFailure {
12342 break
12343 }
Adam Langley95c29f32014-06-20 12:00:00 -070012344 }
12345 }
David Benjamin17e12922016-07-28 18:04:43 -040012346
David Benjamin270f0a72016-03-17 14:41:36 -040012347 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012348 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012349 os.Exit(1)
12350 }
Adam Langley95c29f32014-06-20 12:00:00 -070012351
12352 close(testChan)
12353 wg.Wait()
12354 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012355 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012356
12357 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012358
12359 if *jsonOutput != "" {
12360 if err := testOutput.writeTo(*jsonOutput); err != nil {
12361 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12362 }
12363 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012364
EKR842ae6c2016-07-27 09:22:05 +020012365 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12366 os.Exit(1)
12367 }
12368
12369 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012370 os.Exit(1)
12371 }
Adam Langley95c29f32014-06-20 12:00:00 -070012372}