blob: 2ae697cb97147c00ba266a5a1ad2ac393532bbaa [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700491 if !*useGDB {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
David Benjamin3ed59772016-03-08 12:50:21 -0500495 }
496 return t.Conn.Read(b)
497}
498
499func (t *timeoutConn) Write(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700500 if !*useGDB {
501 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
502 return 0, err
503 }
David Benjamin3ed59772016-03-08 12:50:21 -0500504 }
505 return t.Conn.Write(b)
506}
507
David Benjamin0fde2eb2017-06-30 19:11:22 -0400508func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400509 if !test.noSessionCache {
510 if config.ClientSessionCache == nil {
511 config.ClientSessionCache = NewLRUClientSessionCache(1)
512 }
513 if config.ServerSessionCache == nil {
514 config.ServerSessionCache = NewLRUServerSessionCache(1)
515 }
516 }
517 if test.testType == clientTest {
518 if len(config.Certificates) == 0 {
519 config.Certificates = []Certificate{rsaCertificate}
520 }
521 } else {
522 // Supply a ServerName to ensure a constant session cache key,
523 // rather than falling back to net.Conn.RemoteAddr.
524 if len(config.ServerName) == 0 {
525 config.ServerName = "test"
526 }
527 }
528 if *fuzzer {
529 config.Bugs.NullAllCiphers = true
530 }
David Benjamin01a90572016-09-22 00:11:43 -0400531 if *deterministic {
532 config.Time = func() time.Time { return time.Unix(1234, 1234) }
533 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400534 if test.tls13Variant != 0 {
535 config.TLS13Variant = test.tls13Variant
536 }
David Benjamine54af062016-08-08 19:21:18 -0400537
David Benjamin01784b42016-06-07 18:00:52 -0400538 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500539
David Benjamin6fd297b2014-08-11 18:43:38 -0400540 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500541 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
542 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500543 }
544
David Benjamin9867b7d2016-03-01 23:25:48 -0500545 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500546 local, peer := "client", "server"
547 if test.testType == clientTest {
548 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500549 }
David Benjaminebda9b32015-11-02 15:33:18 -0500550 connDebug := &recordingConn{
551 Conn: conn,
552 isDatagram: test.protocol == dtls,
553 local: local,
554 peer: peer,
555 }
556 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 if *flagDebug {
558 defer connDebug.WriteTo(os.Stdout)
559 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400560 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500561 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400562 path := transcriptPrefix + strconv.Itoa(num)
563 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500564 }()
565 }
David Benjaminebda9b32015-11-02 15:33:18 -0500566
567 if config.Bugs.PacketAdaptor != nil {
568 config.Bugs.PacketAdaptor.debug = connDebug
569 }
570 }
571
572 if test.replayWrites {
573 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400574 }
575
David Benjamin3ed59772016-03-08 12:50:21 -0500576 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500577 if test.damageFirstWrite {
578 connDamage = newDamageAdaptor(conn)
579 conn = connDamage
580 }
581
David Benjamin6fd297b2014-08-11 18:43:38 -0400582 if test.sendPrefix != "" {
583 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
584 return err
585 }
David Benjamin98e882e2014-08-08 13:24:34 -0400586 }
587
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400589 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSServer(conn, config)
592 } else {
593 tlsConn = Server(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 } else {
596 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400597 if test.protocol == dtls {
598 tlsConn = DTLSClient(conn, config)
599 } else {
600 tlsConn = Client(conn, config)
601 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400602 }
David Benjamin30789da2015-08-29 22:56:45 -0400603 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400604
Adam Langley95c29f32014-06-20 12:00:00 -0700605 if err := tlsConn.Handshake(); err != nil {
606 return err
607 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700608
David Benjamin01fe8202014-09-24 15:21:44 -0400609 // TODO(davidben): move all per-connection expectations into a dedicated
610 // expectations struct that can be specified separately for the two
611 // legs.
612 expectedVersion := test.expectedVersion
613 if isResume && test.expectedResumeVersion != 0 {
614 expectedVersion = test.expectedResumeVersion
615 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700616 connState := tlsConn.ConnectionState()
617 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400618 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400619 }
620
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700621 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400622 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
623 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700624 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
625 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
626 }
David Benjamin90da8c82015-04-20 14:57:57 -0400627
David Benjamina08e49d2014-08-24 01:46:07 -0400628 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700629 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400630 if channelID == nil {
631 return fmt.Errorf("no channel ID negotiated")
632 }
633 if channelID.Curve != channelIDKey.Curve ||
634 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
635 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
636 return fmt.Errorf("incorrect channel ID")
637 }
David Benjamin634f4752017-07-01 11:08:41 -0400638 } else if connState.ChannelID != nil {
639 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400640 }
641
David Benjaminae2888f2014-09-06 12:58:58 -0400642 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700643 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400644 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
645 }
646 }
647
David Benjaminc7ce9772015-10-09 19:32:41 -0400648 if test.expectNoNextProto {
649 if actual := connState.NegotiatedProtocol; actual != "" {
650 return fmt.Errorf("got unexpected next proto %s", actual)
651 }
652 }
653
David Benjaminfc7b0862014-09-06 13:21:53 -0400654 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700655 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400656 return fmt.Errorf("next proto type mismatch")
657 }
658 }
659
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700660 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500661 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
662 }
663
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100664 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300665 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100666 }
667
Paul Lietar4fac72e2015-09-09 13:44:55 +0100668 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
669 return fmt.Errorf("SCT list mismatch")
670 }
671
Nick Harper60edffd2016-06-21 15:19:24 -0700672 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
673 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400674 }
675
Steven Valdez5440fe02016-07-18 12:40:30 -0400676 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
677 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
678 }
679
David Benjamin2c516452016-11-15 10:16:54 +0900680 if test.expectPeerCertificate != nil {
681 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
682 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
683 }
684 for i, cert := range connState.PeerCertificates {
685 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
686 return fmt.Errorf("peer certificate %d did not match", i+1)
687 }
688 }
689 }
690
David Benjaminc565ebb2015-04-03 04:06:36 -0400691 if test.exportKeyingMaterial > 0 {
692 actual := make([]byte, test.exportKeyingMaterial)
693 if _, err := io.ReadFull(tlsConn, actual); err != nil {
694 return err
695 }
696 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
697 if err != nil {
698 return err
699 }
700 if !bytes.Equal(actual, expected) {
701 return fmt.Errorf("keying material mismatch")
702 }
703 }
704
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700705 if test.testTLSUnique {
706 var peersValue [12]byte
707 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
708 return err
709 }
710 expected := tlsConn.ConnectionState().TLSUnique
711 if !bytes.Equal(peersValue[:], expected) {
712 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
713 }
714 }
715
David Benjamin47921102016-07-28 11:29:18 -0400716 if test.sendHalfHelloRequest {
717 tlsConn.SendHalfHelloRequest()
718 }
719
Steven Valdeze831a812017-03-09 14:56:07 -0500720 shimPrefix := test.shimPrefix
721 if isResume {
722 shimPrefix = test.resumeShimPrefix
723 }
724 if test.shimWritesFirst || test.readWithUnfinishedWrite {
725 shimPrefix = "hello"
726 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400727 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400728 // If readWithUnfinishedWrite is set, the shim prefix will be
729 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500730 if shimPrefix != "" && !test.readWithUnfinishedWrite {
731 var buf = make([]byte, len(shimPrefix))
732 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400733 if err != nil {
734 return err
735 }
Steven Valdeze831a812017-03-09 14:56:07 -0500736 if string(buf) != shimPrefix {
737 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400738 }
Steven Valdeze831a812017-03-09 14:56:07 -0500739 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400740 }
741
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 if test.renegotiateCiphers != nil {
743 config.CipherSuites = test.renegotiateCiphers
744 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400745 for i := 0; i < test.renegotiate; i++ {
746 if err := tlsConn.Renegotiate(); err != nil {
747 return err
748 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700749 }
750 } else if test.renegotiateCiphers != nil {
751 panic("renegotiateCiphers without renegotiate")
752 }
753
David Benjamin5fa3eba2015-01-22 16:35:40 -0500754 if test.damageFirstWrite {
755 connDamage.setDamage(true)
756 tlsConn.Write([]byte("DAMAGED WRITE"))
757 connDamage.setDamage(false)
758 }
759
David Benjamin8e6db492015-07-25 18:29:23 -0400760 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700761 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400762 if test.protocol == dtls {
763 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
764 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700765 // Read until EOF.
766 _, err := io.Copy(ioutil.Discard, tlsConn)
767 return err
768 }
David Benjamin4417d052015-04-05 04:17:25 -0400769 if messageLen == 0 {
770 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700771 }
Adam Langley95c29f32014-06-20 12:00:00 -0700772
David Benjamin8e6db492015-07-25 18:29:23 -0400773 messageCount := test.messageCount
774 if messageCount == 0 {
775 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400776 }
777
David Benjamin8e6db492015-07-25 18:29:23 -0400778 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400779 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400780 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400781 }
782
David Benjamin8e6db492015-07-25 18:29:23 -0400783 for i := 0; i < test.sendEmptyRecords; i++ {
784 tlsConn.Write(nil)
785 }
786
787 for i := 0; i < test.sendWarningAlerts; i++ {
788 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
789 }
790
David Benjamin24e58862017-06-14 18:45:29 -0400791 if test.sendBogusAlertType {
792 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
793 }
794
David Benjaminbbba9392017-04-06 12:54:12 -0400795 testMessage := make([]byte, messageLen)
796 for i := range testMessage {
797 testMessage[i] = 0x42 ^ byte(j)
798 }
799 tlsConn.Write(testMessage)
800
801 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500802 if shimPrefix != "" {
803 var buf = make([]byte, len(shimPrefix))
804 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400805 if err != nil {
806 return err
807 }
Steven Valdeze831a812017-03-09 14:56:07 -0500808 if string(buf) != shimPrefix {
809 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400810 }
Steven Valdeze831a812017-03-09 14:56:07 -0500811 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400812 }
813
David Benjamin4f75aaf2015-09-01 16:53:10 -0400814 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400815 // The shim will not respond.
816 continue
817 }
818
David Benjaminbbba9392017-04-06 12:54:12 -0400819 // Process the KeyUpdate ACK. However many KeyUpdates the runner
820 // sends, the shim should respond only once.
821 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
822 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
823 return err
824 }
825 }
826
David Benjamin8e6db492015-07-25 18:29:23 -0400827 buf := make([]byte, len(testMessage))
828 if test.protocol == dtls {
829 bufTmp := make([]byte, len(buf)+1)
830 n, err := tlsConn.Read(bufTmp)
831 if err != nil {
832 return err
833 }
834 if n != len(buf) {
835 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
836 }
837 copy(buf, bufTmp)
838 } else {
839 _, err := io.ReadFull(tlsConn, buf)
840 if err != nil {
841 return err
842 }
843 }
844
845 for i, v := range buf {
846 if v != testMessage[i]^0xff {
847 return fmt.Errorf("bad reply contents at byte %d", i)
848 }
Adam Langley95c29f32014-06-20 12:00:00 -0700849 }
850 }
851
852 return nil
853}
854
David Benjamin325b5c32014-07-01 19:40:31 -0400855func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400856 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700857 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400858 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700859 }
David Benjamin325b5c32014-07-01 19:40:31 -0400860 valgrindArgs = append(valgrindArgs, path)
861 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamin325b5c32014-07-01 19:40:31 -0400866func gdbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "gdb", "--args"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700870
David Benjamin325b5c32014-07-01 19:40:31 -0400871 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700872}
873
David Benjamind16bf342015-12-18 00:53:12 -0500874func lldbOf(path string, args ...string) *exec.Cmd {
875 xtermArgs := []string{"-e", "lldb", "--"}
876 xtermArgs = append(xtermArgs, path)
877 xtermArgs = append(xtermArgs, args...)
878
879 return exec.Command("xterm", xtermArgs...)
880}
881
EKR842ae6c2016-07-27 09:22:05 +0200882var (
883 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
884 errUnimplemented = errors.New("child process does not implement needed flags")
885)
Adam Langley69a01602014-11-17 17:26:55 -0800886
David Benjamin87c8a642015-02-21 01:54:29 -0500887// accept accepts a connection from listener, unless waitChan signals a process
888// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400889func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500890 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400891 conn net.Conn
892 err error
893 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500894 }
895 connChan := make(chan connOrError, 1)
896 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400897 startTime := time.Now()
Adam Langley182b5732017-07-28 11:00:23 -0700898 if !*useGDB {
899 listener.SetDeadline(time.Now().Add(*idleTimeout))
900 }
David Benjamin87c8a642015-02-21 01:54:29 -0500901 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400902 endTime := time.Now()
903 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500904 close(connChan)
905 }()
906 select {
907 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400908 if result.err != nil {
909 // TODO(davidben): Remove this logging when
910 // https://crbug.com/boringssl/199 is resolved.
911 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
912 }
David Benjamin87c8a642015-02-21 01:54:29 -0500913 return result.conn, result.err
914 case childErr := <-waitChan:
915 waitChan <- childErr
916 return nil, fmt.Errorf("child exited early: %s", childErr)
917 }
918}
919
EKRf71d7ed2016-08-06 13:25:12 -0700920func translateExpectedError(errorStr string) string {
921 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
922 return translated
923 }
924
925 if *looseErrors {
926 return ""
927 }
928
929 return errorStr
930}
931
Adam Langley7c803a62015-06-15 15:35:05 -0700932func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400933 // Help debugging panics on the Go side.
934 defer func() {
935 if r := recover(); r != nil {
936 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
937 panic(r)
938 }
939 }()
940
Adam Langley38311732014-10-16 19:04:35 -0700941 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
942 panic("Error expected without shouldFail in " + test.name)
943 }
944
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700945 if test.expectResumeRejected && !test.resumeSession {
946 panic("expectResumeRejected without resumeSession in " + test.name)
947 }
948
Adam Langley33b1d4f2016-12-07 15:03:45 -0800949 for _, ver := range tlsVersions {
950 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
951 continue
952 }
953
David Benjamina5022392017-07-10 17:40:39 -0400954 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
955 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
Adam Langley33b1d4f2016-12-07 15:03:45 -0800956 }
957
David Benjamina5022392017-07-10 17:40:39 -0400958 if ver.tls13Variant != 0 {
959 var foundFlag bool
960 for _, flag := range test.flags {
961 if flag == "-tls13-variant" {
962 foundFlag = true
963 break
964 }
965 }
966 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
967 panic(fmt.Sprintf("The name of test %q suggests that uses an experimental TLS 1.3 variant, but neither the shim nor the runner configures it", test.name))
968 }
969 }
970
Adam Langley33b1d4f2016-12-07 15:03:45 -0800971 }
972
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700973 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
974 if err != nil {
975 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
976 }
David Benjamin87c8a642015-02-21 01:54:29 -0500977 if err != nil {
978 panic(err)
979 }
980 defer func() {
981 if listener != nil {
982 listener.Close()
983 }
984 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700985
David Benjamin87c8a642015-02-21 01:54:29 -0500986 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400987 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400988 flags = append(flags, "-server")
989
David Benjamin025b3d32014-07-01 19:53:04 -0400990 flags = append(flags, "-key-file")
991 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700992 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400993 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700994 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400995 }
996
997 flags = append(flags, "-cert-file")
998 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700999 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001000 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001001 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001002 }
1003 }
David Benjamin5a593af2014-08-11 19:51:50 -04001004
David Benjamin6fd297b2014-08-11 18:43:38 -04001005 if test.protocol == dtls {
1006 flags = append(flags, "-dtls")
1007 }
1008
David Benjamin46662482016-08-17 00:51:00 -04001009 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001010 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001011 resumeCount++
1012 if test.resumeRenewedSession {
1013 resumeCount++
1014 }
1015 }
1016
1017 if resumeCount > 0 {
1018 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001019 }
1020
David Benjamine58c4f52014-08-24 03:47:07 -04001021 if test.shimWritesFirst {
1022 flags = append(flags, "-shim-writes-first")
1023 }
1024
David Benjaminbbba9392017-04-06 12:54:12 -04001025 if test.readWithUnfinishedWrite {
1026 flags = append(flags, "-read-with-unfinished-write")
1027 }
1028
David Benjamin30789da2015-08-29 22:56:45 -04001029 if test.shimShutsDown {
1030 flags = append(flags, "-shim-shuts-down")
1031 }
1032
David Benjaminc565ebb2015-04-03 04:06:36 -04001033 if test.exportKeyingMaterial > 0 {
1034 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1035 flags = append(flags, "-export-label", test.exportLabel)
1036 flags = append(flags, "-export-context", test.exportContext)
1037 if test.useExportContext {
1038 flags = append(flags, "-use-export-context")
1039 }
1040 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001041 if test.expectResumeRejected {
1042 flags = append(flags, "-expect-session-miss")
1043 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001044
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001045 if test.testTLSUnique {
1046 flags = append(flags, "-tls-unique")
1047 }
1048
David Benjamina5022392017-07-10 17:40:39 -04001049 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001050 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1051 }
1052
David Benjamin0fde2eb2017-06-30 19:11:22 -04001053 var transcriptPrefix string
1054 if len(*transcriptDir) != 0 {
1055 protocol := "tls"
1056 if test.protocol == dtls {
1057 protocol = "dtls"
1058 }
1059
1060 side := "client"
1061 if test.testType == serverTest {
1062 side = "server"
1063 }
1064
1065 dir := filepath.Join(*transcriptDir, protocol, side)
1066 if err := os.MkdirAll(dir, 0755); err != nil {
1067 return err
1068 }
1069 transcriptPrefix = filepath.Join(dir, test.name+"-")
1070 flags = append(flags, "-write-settings", transcriptPrefix)
1071 }
1072
David Benjamin025b3d32014-07-01 19:53:04 -04001073 flags = append(flags, test.flags...)
1074
1075 var shim *exec.Cmd
1076 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001077 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001078 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001079 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001080 } else if *useLLDB {
1081 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001082 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001083 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001084 }
David Benjamin025b3d32014-07-01 19:53:04 -04001085 shim.Stdin = os.Stdin
1086 var stdoutBuf, stderrBuf bytes.Buffer
1087 shim.Stdout = &stdoutBuf
1088 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001089 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001090 shim.Env = os.Environ()
1091 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001092 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001093 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001094 }
1095 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1096 }
David Benjamin025b3d32014-07-01 19:53:04 -04001097
1098 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001099 panic(err)
1100 }
David Benjamin87c8a642015-02-21 01:54:29 -05001101 waitChan := make(chan error, 1)
1102 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001103
1104 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001105
David Benjamin7a4aaa42016-09-20 17:58:14 -04001106 if *deterministic {
1107 config.Rand = &deterministicRand{}
1108 }
1109
David Benjamin87c8a642015-02-21 01:54:29 -05001110 conn, err := acceptOrWait(listener, waitChan)
1111 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001112 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001113 conn.Close()
1114 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001115
David Benjamin46662482016-08-17 00:51:00 -04001116 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001117 var resumeConfig Config
1118 if test.resumeConfig != nil {
1119 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001120 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001121 resumeConfig.SessionTicketKey = config.SessionTicketKey
1122 resumeConfig.ClientSessionCache = config.ClientSessionCache
1123 resumeConfig.ServerSessionCache = config.ServerSessionCache
1124 }
David Benjamin2e045a92016-06-08 13:09:56 -04001125 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001126 } else {
1127 resumeConfig = config
1128 }
David Benjamin87c8a642015-02-21 01:54:29 -05001129 var connResume net.Conn
1130 connResume, err = acceptOrWait(listener, waitChan)
1131 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001132 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001133 connResume.Close()
1134 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001135 }
1136
David Benjamin87c8a642015-02-21 01:54:29 -05001137 // Close the listener now. This is to avoid hangs should the shim try to
1138 // open more connections than expected.
1139 listener.Close()
1140 listener = nil
1141
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001142 var shimKilledLock sync.Mutex
1143 var shimKilled bool
1144 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1145 shimKilledLock.Lock()
1146 shimKilled = true
1147 shimKilledLock.Unlock()
1148 shim.Process.Kill()
1149 })
David Benjamin87c8a642015-02-21 01:54:29 -05001150 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001151 waitTimeout.Stop()
1152 shimKilledLock.Lock()
1153 if shimKilled && err == nil {
1154 err = errors.New("timeout waiting for the shim to exit.")
1155 }
1156 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001157 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001158 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001159 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1160 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001161 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001162 case 89:
1163 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001164 case 99:
1165 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001166 }
1167 }
Adam Langley95c29f32014-06-20 12:00:00 -07001168
David Benjamin9bea3492016-03-02 10:59:16 -05001169 // Account for Windows line endings.
1170 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1171 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001172
1173 // Separate the errors from the shim and those from tools like
1174 // AddressSanitizer.
1175 var extraStderr string
1176 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1177 stderr = stderrParts[0]
1178 extraStderr = stderrParts[1]
1179 }
1180
Adam Langley95c29f32014-06-20 12:00:00 -07001181 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001182 expectedError := translateExpectedError(test.expectedError)
1183 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001184
Adam Langleyac61fa32014-06-23 12:03:11 -07001185 localError := "none"
1186 if err != nil {
1187 localError = err.Error()
1188 }
1189 if len(test.expectedLocalError) != 0 {
1190 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1191 }
Adam Langley95c29f32014-06-20 12:00:00 -07001192
1193 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001194 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001195 if childErr != nil {
1196 childError = childErr.Error()
1197 }
1198
1199 var msg string
1200 switch {
1201 case failed && !test.shouldFail:
1202 msg = "unexpected failure"
1203 case !failed && test.shouldFail:
1204 msg = "unexpected success"
1205 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001206 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001207 default:
1208 panic("internal error")
1209 }
1210
David Benjamin9aafb642016-09-20 19:36:53 -04001211 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001212 }
1213
David Benjamind2ba8892016-09-20 19:41:04 -04001214 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001215 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001216 }
1217
David Benjamind2ba8892016-09-20 19:41:04 -04001218 if *useValgrind && isValgrindError {
1219 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1220 }
1221
Adam Langley95c29f32014-06-20 12:00:00 -07001222 return nil
1223}
1224
David Benjaminaa012042016-12-10 13:33:05 -05001225type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001226 name string
1227 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001228 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001229 // excludeFlag is the legacy shim flag to disable the version.
1230 excludeFlag string
1231 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001232 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1233 versionDTLS uint16
1234 // versionWire, if non-zero, is the wire representation of the
1235 // version. Otherwise the wire version is the protocol version or
1236 // versionDTLS.
1237 versionWire uint16
1238 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001239}
1240
1241func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001242 // The shim uses the protocol version in its public API, but uses the
1243 // DTLS-specific version if it exists.
1244 if protocol == dtls && vers.versionDTLS != 0 {
1245 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001246 }
Steven Valdez520e1222017-06-13 12:45:25 -04001247 return strconv.Itoa(int(vers.version))
1248}
1249
1250func (vers tlsVersion) wire(protocol protocol) uint16 {
1251 if protocol == dtls && vers.versionDTLS != 0 {
1252 return vers.versionDTLS
1253 }
1254 if vers.versionWire != 0 {
1255 return vers.versionWire
1256 }
1257 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001258}
1259
1260var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001261 {
1262 name: "SSL3",
1263 version: VersionSSL30,
1264 excludeFlag: "-no-ssl3",
1265 },
1266 {
1267 name: "TLS1",
1268 version: VersionTLS10,
1269 excludeFlag: "-no-tls1",
1270 hasDTLS: true,
1271 versionDTLS: VersionDTLS10,
1272 },
1273 {
1274 name: "TLS11",
1275 version: VersionTLS11,
1276 excludeFlag: "-no-tls11",
1277 },
1278 {
1279 name: "TLS12",
1280 version: VersionTLS12,
1281 excludeFlag: "-no-tls12",
1282 hasDTLS: true,
1283 versionDTLS: VersionDTLS12,
1284 },
1285 {
1286 name: "TLS13",
1287 version: VersionTLS13,
1288 excludeFlag: "-no-tls13",
1289 versionWire: tls13DraftVersion,
1290 tls13Variant: TLS13Default,
1291 },
1292 {
1293 name: "TLS13Experiment",
1294 version: VersionTLS13,
1295 excludeFlag: "-no-tls13",
1296 versionWire: tls13ExperimentVersion,
1297 tls13Variant: TLS13Experiment,
1298 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001299 {
1300 name: "TLS13RecordTypeExperiment",
1301 version: VersionTLS13,
1302 excludeFlag: "-no-tls13",
1303 versionWire: tls13RecordTypeExperimentVersion,
1304 tls13Variant: TLS13RecordTypeExperiment,
1305 },
Steven Valdez520e1222017-06-13 12:45:25 -04001306}
1307
1308func allVersions(protocol protocol) []tlsVersion {
1309 if protocol == tls {
1310 return tlsVersions
1311 }
1312
1313 var ret []tlsVersion
1314 for _, vers := range tlsVersions {
1315 if vers.hasDTLS {
1316 ret = append(ret, vers)
1317 }
1318 }
1319 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001320}
1321
David Benjaminaa012042016-12-10 13:33:05 -05001322type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001323 name string
1324 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001325}
1326
1327var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001328 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001329 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001330 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001332 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001333 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001334 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001335 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1336 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001337 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1338 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001339 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001340 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001341 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001342 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001343 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001344 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001345 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001346 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001347 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001348 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001349 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1350 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001351 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1352 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001353 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001354 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1355 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1356 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001357 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001358}
1359
David Benjamin8b8c0062014-11-23 02:47:52 -05001360func hasComponent(suiteName, component string) bool {
1361 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1362}
1363
David Benjaminf7768e42014-08-31 02:06:47 -04001364func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001365 return hasComponent(suiteName, "GCM") ||
1366 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001367 hasComponent(suiteName, "SHA384") ||
1368 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001369}
1370
Nick Harper1fd39d82016-06-14 18:14:35 -07001371func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001372 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001373}
1374
David Benjamin8b8c0062014-11-23 02:47:52 -05001375func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001376 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001377}
1378
Adam Langleya7997f12015-05-14 17:38:50 -07001379func bigFromHex(hex string) *big.Int {
1380 ret, ok := new(big.Int).SetString(hex, 16)
1381 if !ok {
1382 panic("failed to parse hex number 0x" + hex)
1383 }
1384 return ret
1385}
1386
Adam Langley7c803a62015-06-15 15:35:05 -07001387func addBasicTests() {
1388 basicTests := []testCase{
1389 {
Adam Langley7c803a62015-06-15 15:35:05 -07001390 name: "NoFallbackSCSV",
1391 config: Config{
1392 Bugs: ProtocolBugs{
1393 FailIfNotFallbackSCSV: true,
1394 },
1395 },
1396 shouldFail: true,
1397 expectedLocalError: "no fallback SCSV found",
1398 },
1399 {
1400 name: "SendFallbackSCSV",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 FailIfNotFallbackSCSV: true,
1404 },
1405 },
1406 flags: []string{"-fallback-scsv"},
1407 },
1408 {
1409 name: "ClientCertificateTypes",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 ClientAuth: RequestClientCert,
1413 ClientCertificateTypes: []byte{
1414 CertTypeDSSSign,
1415 CertTypeRSASign,
1416 CertTypeECDSASign,
1417 },
1418 },
1419 flags: []string{
1420 "-expect-certificate-types",
1421 base64.StdEncoding.EncodeToString([]byte{
1422 CertTypeDSSSign,
1423 CertTypeRSASign,
1424 CertTypeECDSASign,
1425 }),
1426 },
1427 },
1428 {
Adam Langley7c803a62015-06-15 15:35:05 -07001429 name: "UnauthenticatedECDH",
1430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001431 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001432 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1433 Bugs: ProtocolBugs{
1434 UnauthenticatedECDH: true,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":UNEXPECTED_MESSAGE:",
1439 },
1440 {
1441 name: "SkipCertificateStatus",
1442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001443 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Bugs: ProtocolBugs{
1446 SkipCertificateStatus: true,
1447 },
1448 },
1449 flags: []string{
1450 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001451 // This test involves an optional message. Test the message callback
1452 // trace to ensure we do not miss or double-report any.
1453 "-expect-msg-callback",
1454 `write hs 1
1455read hs 2
1456read hs 11
1457read hs 12
1458read hs 14
1459write hs 16
1460write ccs
1461write hs 20
1462read hs 4
1463read ccs
1464read hs 20
1465read alert 1 0
1466`,
1467 },
1468 },
1469 {
1470 protocol: dtls,
1471 name: "SkipCertificateStatus-DTLS",
1472 config: Config{
1473 MaxVersion: VersionTLS12,
1474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1475 Bugs: ProtocolBugs{
1476 SkipCertificateStatus: true,
1477 },
1478 },
1479 flags: []string{
1480 "-enable-ocsp-stapling",
1481 // This test involves an optional message. Test the message callback
1482 // trace to ensure we do not miss or double-report any.
1483 "-expect-msg-callback",
1484 `write hs 1
1485read hs 3
1486write hs 1
1487read hs 2
1488read hs 11
1489read hs 12
1490read hs 14
1491write hs 16
1492write ccs
1493write hs 20
1494read hs 4
1495read ccs
1496read hs 20
1497read alert 1 0
1498`,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 },
1500 },
1501 {
1502 name: "SkipServerKeyExchange",
1503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001504 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1506 Bugs: ProtocolBugs{
1507 SkipServerKeyExchange: true,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_MESSAGE:",
1512 },
1513 {
Adam Langley7c803a62015-06-15 15:35:05 -07001514 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001515 name: "ServerSkipCertificateVerify",
1516 config: Config{
1517 MaxVersion: VersionTLS12,
1518 Certificates: []Certificate{rsaChainCertificate},
1519 Bugs: ProtocolBugs{
1520 SkipCertificateVerify: true,
1521 },
1522 },
1523 expectPeerCertificate: &rsaChainCertificate,
1524 flags: []string{
1525 "-require-any-client-certificate",
1526 },
1527 shouldFail: true,
1528 expectedError: ":UNEXPECTED_RECORD:",
1529 expectedLocalError: "remote error: unexpected message",
1530 },
1531 {
1532 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 name: "Alert",
1534 config: Config{
1535 Bugs: ProtocolBugs{
1536 SendSpuriousAlert: alertRecordOverflow,
1537 },
1538 },
1539 shouldFail: true,
1540 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1541 },
1542 {
1543 protocol: dtls,
1544 testType: serverTest,
1545 name: "Alert-DTLS",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 SendSpuriousAlert: alertRecordOverflow,
1549 },
1550 },
1551 shouldFail: true,
1552 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1553 },
1554 {
1555 testType: serverTest,
1556 name: "FragmentAlert",
1557 config: Config{
1558 Bugs: ProtocolBugs{
1559 FragmentAlert: true,
1560 SendSpuriousAlert: alertRecordOverflow,
1561 },
1562 },
1563 shouldFail: true,
1564 expectedError: ":BAD_ALERT:",
1565 },
1566 {
1567 protocol: dtls,
1568 testType: serverTest,
1569 name: "FragmentAlert-DTLS",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 FragmentAlert: true,
1573 SendSpuriousAlert: alertRecordOverflow,
1574 },
1575 },
1576 shouldFail: true,
1577 expectedError: ":BAD_ALERT:",
1578 },
1579 {
1580 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001581 name: "DoubleAlert",
1582 config: Config{
1583 Bugs: ProtocolBugs{
1584 DoubleAlert: true,
1585 SendSpuriousAlert: alertRecordOverflow,
1586 },
1587 },
1588 shouldFail: true,
1589 expectedError: ":BAD_ALERT:",
1590 },
1591 {
1592 protocol: dtls,
1593 testType: serverTest,
1594 name: "DoubleAlert-DTLS",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 DoubleAlert: true,
1598 SendSpuriousAlert: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":BAD_ALERT:",
1603 },
1604 {
Adam Langley7c803a62015-06-15 15:35:05 -07001605 name: "SkipNewSessionTicket",
1606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001607 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001608 Bugs: ProtocolBugs{
1609 SkipNewSessionTicket: true,
1610 },
1611 },
1612 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001613 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001614 },
1615 {
1616 testType: serverTest,
1617 name: "FallbackSCSV",
1618 config: Config{
1619 MaxVersion: VersionTLS11,
1620 Bugs: ProtocolBugs{
1621 SendFallbackSCSV: true,
1622 },
1623 },
David Benjamin56cadc32016-12-16 19:54:11 -05001624 shouldFail: true,
1625 expectedError: ":INAPPROPRIATE_FALLBACK:",
1626 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001627 },
1628 {
1629 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001630 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001631 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001632 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 Bugs: ProtocolBugs{
1634 SendFallbackSCSV: true,
1635 },
1636 },
1637 },
1638 {
1639 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001640 name: "FallbackSCSV-VersionMatch-TLS12",
1641 config: Config{
1642 MaxVersion: VersionTLS12,
1643 Bugs: ProtocolBugs{
1644 SendFallbackSCSV: true,
1645 },
1646 },
1647 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1648 },
1649 {
1650 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001651 name: "FragmentedClientVersion",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 MaxHandshakeRecordLength: 1,
1655 FragmentClientVersion: true,
1656 },
1657 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001658 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001659 },
1660 {
Adam Langley7c803a62015-06-15 15:35:05 -07001661 testType: serverTest,
1662 name: "HttpGET",
1663 sendPrefix: "GET / HTTP/1.0\n",
1664 shouldFail: true,
1665 expectedError: ":HTTP_REQUEST:",
1666 },
1667 {
1668 testType: serverTest,
1669 name: "HttpPOST",
1670 sendPrefix: "POST / HTTP/1.0\n",
1671 shouldFail: true,
1672 expectedError: ":HTTP_REQUEST:",
1673 },
1674 {
1675 testType: serverTest,
1676 name: "HttpHEAD",
1677 sendPrefix: "HEAD / HTTP/1.0\n",
1678 shouldFail: true,
1679 expectedError: ":HTTP_REQUEST:",
1680 },
1681 {
1682 testType: serverTest,
1683 name: "HttpPUT",
1684 sendPrefix: "PUT / HTTP/1.0\n",
1685 shouldFail: true,
1686 expectedError: ":HTTP_REQUEST:",
1687 },
1688 {
1689 testType: serverTest,
1690 name: "HttpCONNECT",
1691 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1692 shouldFail: true,
1693 expectedError: ":HTTPS_PROXY_REQUEST:",
1694 },
1695 {
1696 testType: serverTest,
1697 name: "Garbage",
1698 sendPrefix: "blah",
1699 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001700 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
Adam Langley7c803a62015-06-15 15:35:05 -07001703 name: "RSAEphemeralKey",
1704 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001705 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001706 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1707 Bugs: ProtocolBugs{
1708 RSAEphemeralKey: true,
1709 },
1710 },
1711 shouldFail: true,
1712 expectedError: ":UNEXPECTED_MESSAGE:",
1713 },
1714 {
1715 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001716 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001717 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001718 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001719 },
1720 {
1721 protocol: dtls,
1722 name: "DisableEverything-DTLS",
1723 flags: []string{"-no-tls12", "-no-tls1"},
1724 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001725 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001726 },
1727 {
Adam Langley7c803a62015-06-15 15:35:05 -07001728 protocol: dtls,
1729 testType: serverTest,
1730 name: "MTU",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxPacketLength: 256,
1734 },
1735 },
1736 flags: []string{"-mtu", "256"},
1737 },
1738 {
1739 protocol: dtls,
1740 testType: serverTest,
1741 name: "MTUExceeded",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 MaxPacketLength: 255,
1745 },
1746 },
1747 flags: []string{"-mtu", "256"},
1748 shouldFail: true,
1749 expectedLocalError: "dtls: exceeded maximum packet length",
1750 },
1751 {
Adam Langley7c803a62015-06-15 15:35:05 -07001752 name: "EmptyCertificateList",
1753 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001754 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001755 Bugs: ProtocolBugs{
1756 EmptyCertificateList: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DECODE_ERROR:",
1761 },
1762 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001763 name: "EmptyCertificateList-TLS13",
1764 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001765 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001766 Bugs: ProtocolBugs{
1767 EmptyCertificateList: true,
1768 },
1769 },
1770 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001771 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001772 },
1773 {
Adam Langley7c803a62015-06-15 15:35:05 -07001774 name: "TLSFatalBadPackets",
1775 damageFirstWrite: true,
1776 shouldFail: true,
1777 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1778 },
1779 {
1780 protocol: dtls,
1781 name: "DTLSIgnoreBadPackets",
1782 damageFirstWrite: true,
1783 },
1784 {
1785 protocol: dtls,
1786 name: "DTLSIgnoreBadPackets-Async",
1787 damageFirstWrite: true,
1788 flags: []string{"-async"},
1789 },
1790 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001791 name: "AppDataBeforeHandshake",
1792 config: Config{
1793 Bugs: ProtocolBugs{
1794 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1795 },
1796 },
1797 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001798 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001799 },
1800 {
1801 name: "AppDataBeforeHandshake-Empty",
1802 config: Config{
1803 Bugs: ProtocolBugs{
1804 AppDataBeforeHandshake: []byte{},
1805 },
1806 },
1807 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001808 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001809 },
1810 {
1811 protocol: dtls,
1812 name: "AppDataBeforeHandshake-DTLS",
1813 config: Config{
1814 Bugs: ProtocolBugs{
1815 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1816 },
1817 },
1818 shouldFail: true,
1819 expectedError: ":UNEXPECTED_RECORD:",
1820 },
1821 {
1822 protocol: dtls,
1823 name: "AppDataBeforeHandshake-DTLS-Empty",
1824 config: Config{
1825 Bugs: ProtocolBugs{
1826 AppDataBeforeHandshake: []byte{},
1827 },
1828 },
1829 shouldFail: true,
1830 expectedError: ":UNEXPECTED_RECORD:",
1831 },
1832 {
Adam Langley7c803a62015-06-15 15:35:05 -07001833 name: "AppDataAfterChangeCipherSpec",
1834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 Bugs: ProtocolBugs{
1837 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1838 },
1839 },
1840 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001841 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001842 },
1843 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001844 name: "AppDataAfterChangeCipherSpec-Empty",
1845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001846 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001847 Bugs: ProtocolBugs{
1848 AppDataAfterChangeCipherSpec: []byte{},
1849 },
1850 },
1851 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001852 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001853 },
1854 {
Adam Langley7c803a62015-06-15 15:35:05 -07001855 protocol: dtls,
1856 name: "AppDataAfterChangeCipherSpec-DTLS",
1857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001858 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001859 Bugs: ProtocolBugs{
1860 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1861 },
1862 },
1863 // BoringSSL's DTLS implementation will drop the out-of-order
1864 // application data.
1865 },
1866 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001867 protocol: dtls,
1868 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001870 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001871 Bugs: ProtocolBugs{
1872 AppDataAfterChangeCipherSpec: []byte{},
1873 },
1874 },
1875 // BoringSSL's DTLS implementation will drop the out-of-order
1876 // application data.
1877 },
1878 {
Adam Langley7c803a62015-06-15 15:35:05 -07001879 name: "AlertAfterChangeCipherSpec",
1880 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001881 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001882 Bugs: ProtocolBugs{
1883 AlertAfterChangeCipherSpec: alertRecordOverflow,
1884 },
1885 },
1886 shouldFail: true,
1887 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1888 },
1889 {
1890 protocol: dtls,
1891 name: "AlertAfterChangeCipherSpec-DTLS",
1892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001893 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001894 Bugs: ProtocolBugs{
1895 AlertAfterChangeCipherSpec: alertRecordOverflow,
1896 },
1897 },
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1900 },
1901 {
1902 protocol: dtls,
1903 name: "ReorderHandshakeFragments-Small-DTLS",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 ReorderHandshakeFragments: true,
1907 // Small enough that every handshake message is
1908 // fragmented.
1909 MaxHandshakeRecordLength: 2,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "ReorderHandshakeFragments-Large-DTLS",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 ReorderHandshakeFragments: true,
1919 // Large enough that no handshake message is
1920 // fragmented.
1921 MaxHandshakeRecordLength: 2048,
1922 },
1923 },
1924 },
1925 {
1926 protocol: dtls,
1927 name: "MixCompleteMessageWithFragments-DTLS",
1928 config: Config{
1929 Bugs: ProtocolBugs{
1930 ReorderHandshakeFragments: true,
1931 MixCompleteMessageWithFragments: true,
1932 MaxHandshakeRecordLength: 2,
1933 },
1934 },
1935 },
1936 {
1937 name: "SendInvalidRecordType",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendInvalidRecordType: true,
1941 },
1942 },
1943 shouldFail: true,
1944 expectedError: ":UNEXPECTED_RECORD:",
1945 },
1946 {
1947 protocol: dtls,
1948 name: "SendInvalidRecordType-DTLS",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 SendInvalidRecordType: true,
1952 },
1953 },
1954 shouldFail: true,
1955 expectedError: ":UNEXPECTED_RECORD:",
1956 },
1957 {
1958 name: "FalseStart-SkipServerSecondLeg",
1959 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001960 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1962 NextProtos: []string{"foo"},
1963 Bugs: ProtocolBugs{
1964 SkipNewSessionTicket: true,
1965 SkipChangeCipherSpec: true,
1966 SkipFinished: true,
1967 ExpectFalseStart: true,
1968 },
1969 },
1970 flags: []string{
1971 "-false-start",
1972 "-handshake-never-done",
1973 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001974 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001975 },
1976 shimWritesFirst: true,
1977 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001978 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001979 },
1980 {
1981 name: "FalseStart-SkipServerSecondLeg-Implicit",
1982 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001983 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1985 NextProtos: []string{"foo"},
1986 Bugs: ProtocolBugs{
1987 SkipNewSessionTicket: true,
1988 SkipChangeCipherSpec: true,
1989 SkipFinished: true,
1990 },
1991 },
1992 flags: []string{
1993 "-implicit-handshake",
1994 "-false-start",
1995 "-handshake-never-done",
1996 "-advertise-alpn", "\x03foo",
1997 },
1998 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001999 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002000 },
2001 {
2002 testType: serverTest,
2003 name: "FailEarlyCallback",
2004 flags: []string{"-fail-early-callback"},
2005 shouldFail: true,
2006 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002007 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002008 },
2009 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002010 name: "FailCertCallback-Client-TLS12",
2011 config: Config{
2012 MaxVersion: VersionTLS12,
2013 ClientAuth: RequestClientCert,
2014 },
2015 flags: []string{"-fail-cert-callback"},
2016 shouldFail: true,
2017 expectedError: ":CERT_CB_ERROR:",
2018 expectedLocalError: "remote error: internal error",
2019 },
2020 {
2021 testType: serverTest,
2022 name: "FailCertCallback-Server-TLS12",
2023 config: Config{
2024 MaxVersion: VersionTLS12,
2025 },
2026 flags: []string{"-fail-cert-callback"},
2027 shouldFail: true,
2028 expectedError: ":CERT_CB_ERROR:",
2029 expectedLocalError: "remote error: internal error",
2030 },
2031 {
2032 name: "FailCertCallback-Client-TLS13",
2033 config: Config{
2034 MaxVersion: VersionTLS13,
2035 ClientAuth: RequestClientCert,
2036 },
2037 flags: []string{"-fail-cert-callback"},
2038 shouldFail: true,
2039 expectedError: ":CERT_CB_ERROR:",
2040 expectedLocalError: "remote error: internal error",
2041 },
2042 {
2043 testType: serverTest,
2044 name: "FailCertCallback-Server-TLS13",
2045 config: Config{
2046 MaxVersion: VersionTLS13,
2047 },
2048 flags: []string{"-fail-cert-callback"},
2049 shouldFail: true,
2050 expectedError: ":CERT_CB_ERROR:",
2051 expectedLocalError: "remote error: internal error",
2052 },
2053 {
Adam Langley7c803a62015-06-15 15:35:05 -07002054 protocol: dtls,
2055 name: "FragmentMessageTypeMismatch-DTLS",
2056 config: Config{
2057 Bugs: ProtocolBugs{
2058 MaxHandshakeRecordLength: 2,
2059 FragmentMessageTypeMismatch: true,
2060 },
2061 },
2062 shouldFail: true,
2063 expectedError: ":FRAGMENT_MISMATCH:",
2064 },
2065 {
2066 protocol: dtls,
2067 name: "FragmentMessageLengthMismatch-DTLS",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 MaxHandshakeRecordLength: 2,
2071 FragmentMessageLengthMismatch: true,
2072 },
2073 },
2074 shouldFail: true,
2075 expectedError: ":FRAGMENT_MISMATCH:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "SplitFragments-Header-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SplitFragments: 2,
2083 },
2084 },
2085 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002086 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002087 },
2088 {
2089 protocol: dtls,
2090 name: "SplitFragments-Boundary-DTLS",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SplitFragments: dtlsRecordHeaderLen,
2094 },
2095 },
2096 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002097 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002098 },
2099 {
2100 protocol: dtls,
2101 name: "SplitFragments-Body-DTLS",
2102 config: Config{
2103 Bugs: ProtocolBugs{
2104 SplitFragments: dtlsRecordHeaderLen + 1,
2105 },
2106 },
2107 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002108 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002109 },
2110 {
2111 protocol: dtls,
2112 name: "SendEmptyFragments-DTLS",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendEmptyFragments: true,
2116 },
2117 },
2118 },
2119 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002120 name: "BadFinished-Client",
2121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002123 Bugs: ProtocolBugs{
2124 BadFinished: true,
2125 },
2126 },
2127 shouldFail: true,
2128 expectedError: ":DIGEST_CHECK_FAILED:",
2129 },
2130 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002131 name: "BadFinished-Client-TLS13",
2132 config: Config{
2133 MaxVersion: VersionTLS13,
2134 Bugs: ProtocolBugs{
2135 BadFinished: true,
2136 },
2137 },
2138 shouldFail: true,
2139 expectedError: ":DIGEST_CHECK_FAILED:",
2140 },
2141 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002142 testType: serverTest,
2143 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002145 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002146 Bugs: ProtocolBugs{
2147 BadFinished: true,
2148 },
2149 },
2150 shouldFail: true,
2151 expectedError: ":DIGEST_CHECK_FAILED:",
2152 },
2153 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002154 testType: serverTest,
2155 name: "BadFinished-Server-TLS13",
2156 config: Config{
2157 MaxVersion: VersionTLS13,
2158 Bugs: ProtocolBugs{
2159 BadFinished: true,
2160 },
2161 },
2162 shouldFail: true,
2163 expectedError: ":DIGEST_CHECK_FAILED:",
2164 },
2165 {
Adam Langley7c803a62015-06-15 15:35:05 -07002166 name: "FalseStart-BadFinished",
2167 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002168 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2170 NextProtos: []string{"foo"},
2171 Bugs: ProtocolBugs{
2172 BadFinished: true,
2173 ExpectFalseStart: true,
2174 },
2175 },
2176 flags: []string{
2177 "-false-start",
2178 "-handshake-never-done",
2179 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002180 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002181 },
2182 shimWritesFirst: true,
2183 shouldFail: true,
2184 expectedError: ":DIGEST_CHECK_FAILED:",
2185 },
2186 {
2187 name: "NoFalseStart-NoALPN",
2188 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2191 Bugs: ProtocolBugs{
2192 ExpectFalseStart: true,
2193 AlertBeforeFalseStartTest: alertAccessDenied,
2194 },
2195 },
2196 flags: []string{
2197 "-false-start",
2198 },
2199 shimWritesFirst: true,
2200 shouldFail: true,
2201 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2202 expectedLocalError: "tls: peer did not false start: EOF",
2203 },
2204 {
2205 name: "NoFalseStart-NoAEAD",
2206 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002207 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002208 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2209 NextProtos: []string{"foo"},
2210 Bugs: ProtocolBugs{
2211 ExpectFalseStart: true,
2212 AlertBeforeFalseStartTest: alertAccessDenied,
2213 },
2214 },
2215 flags: []string{
2216 "-false-start",
2217 "-advertise-alpn", "\x03foo",
2218 },
2219 shimWritesFirst: true,
2220 shouldFail: true,
2221 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2222 expectedLocalError: "tls: peer did not false start: EOF",
2223 },
2224 {
2225 name: "NoFalseStart-RSA",
2226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002227 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002228 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2229 NextProtos: []string{"foo"},
2230 Bugs: ProtocolBugs{
2231 ExpectFalseStart: true,
2232 AlertBeforeFalseStartTest: alertAccessDenied,
2233 },
2234 },
2235 flags: []string{
2236 "-false-start",
2237 "-advertise-alpn", "\x03foo",
2238 },
2239 shimWritesFirst: true,
2240 shouldFail: true,
2241 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2242 expectedLocalError: "tls: peer did not false start: EOF",
2243 },
2244 {
Adam Langley7c803a62015-06-15 15:35:05 -07002245 protocol: dtls,
2246 name: "SendSplitAlert-Sync",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendSplitAlert: true,
2250 },
2251 },
2252 },
2253 {
2254 protocol: dtls,
2255 name: "SendSplitAlert-Async",
2256 config: Config{
2257 Bugs: ProtocolBugs{
2258 SendSplitAlert: true,
2259 },
2260 },
2261 flags: []string{"-async"},
2262 },
2263 {
2264 protocol: dtls,
2265 name: "PackDTLSHandshake",
2266 config: Config{
2267 Bugs: ProtocolBugs{
2268 MaxHandshakeRecordLength: 2,
2269 PackHandshakeFragments: 20,
2270 PackHandshakeRecords: 200,
2271 },
2272 },
2273 },
2274 {
Adam Langley7c803a62015-06-15 15:35:05 -07002275 name: "SendEmptyRecords-Pass",
2276 sendEmptyRecords: 32,
2277 },
2278 {
2279 name: "SendEmptyRecords",
2280 sendEmptyRecords: 33,
2281 shouldFail: true,
2282 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2283 },
2284 {
2285 name: "SendEmptyRecords-Async",
2286 sendEmptyRecords: 33,
2287 flags: []string{"-async"},
2288 shouldFail: true,
2289 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2290 },
2291 {
David Benjamine8e84b92016-08-03 15:39:47 -04002292 name: "SendWarningAlerts-Pass",
2293 config: Config{
2294 MaxVersion: VersionTLS12,
2295 },
Adam Langley7c803a62015-06-15 15:35:05 -07002296 sendWarningAlerts: 4,
2297 },
2298 {
David Benjamine8e84b92016-08-03 15:39:47 -04002299 protocol: dtls,
2300 name: "SendWarningAlerts-DTLS-Pass",
2301 config: Config{
2302 MaxVersion: VersionTLS12,
2303 },
Adam Langley7c803a62015-06-15 15:35:05 -07002304 sendWarningAlerts: 4,
2305 },
2306 {
David Benjamine8e84b92016-08-03 15:39:47 -04002307 name: "SendWarningAlerts-TLS13",
2308 config: Config{
2309 MaxVersion: VersionTLS13,
2310 },
2311 sendWarningAlerts: 4,
2312 shouldFail: true,
2313 expectedError: ":BAD_ALERT:",
2314 expectedLocalError: "remote error: error decoding message",
2315 },
2316 {
2317 name: "SendWarningAlerts",
2318 config: Config{
2319 MaxVersion: VersionTLS12,
2320 },
Adam Langley7c803a62015-06-15 15:35:05 -07002321 sendWarningAlerts: 5,
2322 shouldFail: true,
2323 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2324 },
2325 {
David Benjamine8e84b92016-08-03 15:39:47 -04002326 name: "SendWarningAlerts-Async",
2327 config: Config{
2328 MaxVersion: VersionTLS12,
2329 },
Adam Langley7c803a62015-06-15 15:35:05 -07002330 sendWarningAlerts: 5,
2331 flags: []string{"-async"},
2332 shouldFail: true,
2333 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2334 },
David Benjaminba4594a2015-06-18 18:36:15 -04002335 {
David Benjamin24e58862017-06-14 18:45:29 -04002336 name: "SendBogusAlertType",
2337 sendBogusAlertType: true,
2338 shouldFail: true,
2339 expectedError: ":UNKNOWN_ALERT_TYPE:",
2340 expectedLocalError: "remote error: illegal parameter",
2341 },
2342 {
2343 protocol: dtls,
2344 name: "SendBogusAlertType-DTLS",
2345 sendBogusAlertType: true,
2346 shouldFail: true,
2347 expectedError: ":UNKNOWN_ALERT_TYPE:",
2348 expectedLocalError: "remote error: illegal parameter",
2349 },
2350 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002351 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002352 config: Config{
2353 MaxVersion: VersionTLS13,
2354 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002355 sendKeyUpdates: 33,
2356 keyUpdateRequest: keyUpdateNotRequested,
2357 shouldFail: true,
2358 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002359 },
2360 {
David Benjaminba4594a2015-06-18 18:36:15 -04002361 name: "EmptySessionID",
2362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002363 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002364 SessionTicketsDisabled: true,
2365 },
2366 noSessionCache: true,
2367 flags: []string{"-expect-no-session"},
2368 },
David Benjamin30789da2015-08-29 22:56:45 -04002369 {
2370 name: "Unclean-Shutdown",
2371 config: Config{
2372 Bugs: ProtocolBugs{
2373 NoCloseNotify: true,
2374 ExpectCloseNotify: true,
2375 },
2376 },
2377 shimShutsDown: true,
2378 flags: []string{"-check-close-notify"},
2379 shouldFail: true,
2380 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2381 },
2382 {
2383 name: "Unclean-Shutdown-Ignored",
2384 config: Config{
2385 Bugs: ProtocolBugs{
2386 NoCloseNotify: true,
2387 },
2388 },
2389 shimShutsDown: true,
2390 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002391 {
David Benjaminfa214e42016-05-10 17:03:10 -04002392 name: "Unclean-Shutdown-Alert",
2393 config: Config{
2394 Bugs: ProtocolBugs{
2395 SendAlertOnShutdown: alertDecompressionFailure,
2396 ExpectCloseNotify: true,
2397 },
2398 },
2399 shimShutsDown: true,
2400 flags: []string{"-check-close-notify"},
2401 shouldFail: true,
2402 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2403 },
2404 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002405 name: "LargePlaintext",
2406 config: Config{
2407 Bugs: ProtocolBugs{
2408 SendLargeRecords: true,
2409 },
2410 },
2411 messageLen: maxPlaintext + 1,
2412 shouldFail: true,
2413 expectedError: ":DATA_LENGTH_TOO_LONG:",
2414 },
2415 {
2416 protocol: dtls,
2417 name: "LargePlaintext-DTLS",
2418 config: Config{
2419 Bugs: ProtocolBugs{
2420 SendLargeRecords: true,
2421 },
2422 },
2423 messageLen: maxPlaintext + 1,
2424 shouldFail: true,
2425 expectedError: ":DATA_LENGTH_TOO_LONG:",
2426 },
2427 {
2428 name: "LargeCiphertext",
2429 config: Config{
2430 Bugs: ProtocolBugs{
2431 SendLargeRecords: true,
2432 },
2433 },
2434 messageLen: maxPlaintext * 2,
2435 shouldFail: true,
2436 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2437 },
2438 {
2439 protocol: dtls,
2440 name: "LargeCiphertext-DTLS",
2441 config: Config{
2442 Bugs: ProtocolBugs{
2443 SendLargeRecords: true,
2444 },
2445 },
2446 messageLen: maxPlaintext * 2,
2447 // Unlike the other four cases, DTLS drops records which
2448 // are invalid before authentication, so the connection
2449 // does not fail.
2450 expectMessageDropped: true,
2451 },
David Benjamindd6fed92015-10-23 17:41:12 -04002452 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002453 name: "BadHelloRequest-1",
2454 renegotiate: 1,
2455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002456 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002457 Bugs: ProtocolBugs{
2458 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2459 },
2460 },
2461 flags: []string{
2462 "-renegotiate-freely",
2463 "-expect-total-renegotiations", "1",
2464 },
2465 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002466 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002467 },
2468 {
2469 name: "BadHelloRequest-2",
2470 renegotiate: 1,
2471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002472 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002473 Bugs: ProtocolBugs{
2474 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2475 },
2476 },
2477 flags: []string{
2478 "-renegotiate-freely",
2479 "-expect-total-renegotiations", "1",
2480 },
2481 shouldFail: true,
2482 expectedError: ":BAD_HELLO_REQUEST:",
2483 },
David Benjaminef1b0092015-11-21 14:05:44 -05002484 {
2485 testType: serverTest,
2486 name: "SupportTicketsWithSessionID",
2487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002488 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002489 SessionTicketsDisabled: true,
2490 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002491 resumeConfig: &Config{
2492 MaxVersion: VersionTLS12,
2493 },
David Benjaminef1b0092015-11-21 14:05:44 -05002494 resumeSession: true,
2495 },
David Benjamin02edcd02016-07-27 17:40:37 -04002496 {
2497 protocol: dtls,
2498 name: "DTLS-SendExtraFinished",
2499 config: Config{
2500 Bugs: ProtocolBugs{
2501 SendExtraFinished: true,
2502 },
2503 },
2504 shouldFail: true,
2505 expectedError: ":UNEXPECTED_RECORD:",
2506 },
2507 {
2508 protocol: dtls,
2509 name: "DTLS-SendExtraFinished-Reordered",
2510 config: Config{
2511 Bugs: ProtocolBugs{
2512 MaxHandshakeRecordLength: 2,
2513 ReorderHandshakeFragments: true,
2514 SendExtraFinished: true,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNEXPECTED_RECORD:",
2519 },
David Benjamine97fb482016-07-29 09:23:07 -04002520 {
2521 testType: serverTest,
2522 name: "V2ClientHello-EmptyRecordPrefix",
2523 config: Config{
2524 // Choose a cipher suite that does not involve
2525 // elliptic curves, so no extensions are
2526 // involved.
2527 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002528 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002529 Bugs: ProtocolBugs{
2530 SendV2ClientHello: true,
2531 },
2532 },
2533 sendPrefix: string([]byte{
2534 byte(recordTypeHandshake),
2535 3, 1, // version
2536 0, 0, // length
2537 }),
2538 // A no-op empty record may not be sent before V2ClientHello.
2539 shouldFail: true,
2540 expectedError: ":WRONG_VERSION_NUMBER:",
2541 },
2542 {
2543 testType: serverTest,
2544 name: "V2ClientHello-WarningAlertPrefix",
2545 config: Config{
2546 // Choose a cipher suite that does not involve
2547 // elliptic curves, so no extensions are
2548 // involved.
2549 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002550 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002551 Bugs: ProtocolBugs{
2552 SendV2ClientHello: true,
2553 },
2554 },
2555 sendPrefix: string([]byte{
2556 byte(recordTypeAlert),
2557 3, 1, // version
2558 0, 2, // length
2559 alertLevelWarning, byte(alertDecompressionFailure),
2560 }),
2561 // A no-op warning alert may not be sent before V2ClientHello.
2562 shouldFail: true,
2563 expectedError: ":WRONG_VERSION_NUMBER:",
2564 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002565 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002566 name: "KeyUpdate-Client",
2567 config: Config{
2568 MaxVersion: VersionTLS13,
2569 },
2570 sendKeyUpdates: 1,
2571 keyUpdateRequest: keyUpdateNotRequested,
2572 },
2573 {
2574 testType: serverTest,
2575 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002576 config: Config{
2577 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002578 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002579 sendKeyUpdates: 1,
2580 keyUpdateRequest: keyUpdateNotRequested,
2581 },
2582 {
2583 name: "KeyUpdate-InvalidRequestMode",
2584 config: Config{
2585 MaxVersion: VersionTLS13,
2586 },
2587 sendKeyUpdates: 1,
2588 keyUpdateRequest: 42,
2589 shouldFail: true,
2590 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002591 },
David Benjaminabe94e32016-09-04 14:18:58 -04002592 {
David Benjaminbbba9392017-04-06 12:54:12 -04002593 // Test that KeyUpdates are acknowledged properly.
2594 name: "KeyUpdate-RequestACK",
2595 config: Config{
2596 MaxVersion: VersionTLS13,
2597 Bugs: ProtocolBugs{
2598 RejectUnsolicitedKeyUpdate: true,
2599 },
2600 },
2601 // Test the shim receiving many KeyUpdates in a row.
2602 sendKeyUpdates: 5,
2603 messageCount: 5,
2604 keyUpdateRequest: keyUpdateRequested,
2605 },
2606 {
2607 // Test that KeyUpdates are acknowledged properly if the
2608 // peer's KeyUpdate is discovered while a write is
2609 // pending.
2610 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2611 config: Config{
2612 MaxVersion: VersionTLS13,
2613 Bugs: ProtocolBugs{
2614 RejectUnsolicitedKeyUpdate: true,
2615 },
2616 },
2617 // Test the shim receiving many KeyUpdates in a row.
2618 sendKeyUpdates: 5,
2619 messageCount: 5,
2620 keyUpdateRequest: keyUpdateRequested,
2621 readWithUnfinishedWrite: true,
2622 flags: []string{"-async"},
2623 },
2624 {
David Benjaminabe94e32016-09-04 14:18:58 -04002625 name: "SendSNIWarningAlert",
2626 config: Config{
2627 MaxVersion: VersionTLS12,
2628 Bugs: ProtocolBugs{
2629 SendSNIWarningAlert: true,
2630 },
2631 },
2632 },
David Benjaminc241d792016-09-09 10:34:20 -04002633 {
2634 testType: serverTest,
2635 name: "ExtraCompressionMethods-TLS12",
2636 config: Config{
2637 MaxVersion: VersionTLS12,
2638 Bugs: ProtocolBugs{
2639 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2640 },
2641 },
2642 },
2643 {
2644 testType: serverTest,
2645 name: "ExtraCompressionMethods-TLS13",
2646 config: Config{
2647 MaxVersion: VersionTLS13,
2648 Bugs: ProtocolBugs{
2649 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2650 },
2651 },
2652 shouldFail: true,
2653 expectedError: ":INVALID_COMPRESSION_LIST:",
2654 expectedLocalError: "remote error: illegal parameter",
2655 },
2656 {
2657 testType: serverTest,
2658 name: "NoNullCompression-TLS12",
2659 config: Config{
2660 MaxVersion: VersionTLS12,
2661 Bugs: ProtocolBugs{
2662 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2663 },
2664 },
2665 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002666 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002667 expectedLocalError: "remote error: illegal parameter",
2668 },
2669 {
2670 testType: serverTest,
2671 name: "NoNullCompression-TLS13",
2672 config: Config{
2673 MaxVersion: VersionTLS13,
2674 Bugs: ProtocolBugs{
2675 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2676 },
2677 },
2678 shouldFail: true,
2679 expectedError: ":INVALID_COMPRESSION_LIST:",
2680 expectedLocalError: "remote error: illegal parameter",
2681 },
David Benjamin413e79e2017-07-01 10:11:53 -04002682 // Test that the client rejects invalid compression methods
2683 // from the server.
2684 {
2685 testType: clientTest,
2686 name: "InvalidCompressionMethod",
2687 config: Config{
2688 MaxVersion: VersionTLS12,
2689 Bugs: ProtocolBugs{
2690 SendCompressionMethod: 1,
2691 },
2692 },
2693 shouldFail: true,
2694 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2695 expectedLocalError: "remote error: illegal parameter",
2696 },
David Benjamin65ac9972016-09-02 21:35:25 -04002697 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002698 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002699 config: Config{
2700 MaxVersion: VersionTLS12,
2701 Bugs: ProtocolBugs{
2702 ExpectGREASE: true,
2703 },
2704 },
2705 flags: []string{"-enable-grease"},
2706 },
2707 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002708 name: "GREASE-Client-TLS13",
2709 config: Config{
2710 MaxVersion: VersionTLS13,
2711 Bugs: ProtocolBugs{
2712 ExpectGREASE: true,
2713 },
2714 },
2715 flags: []string{"-enable-grease"},
2716 },
2717 {
2718 testType: serverTest,
2719 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002720 config: Config{
2721 MaxVersion: VersionTLS13,
2722 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002723 // TLS 1.3 servers are expected to
2724 // always enable GREASE. TLS 1.3 is new,
2725 // so there is no existing ecosystem to
2726 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002727 ExpectGREASE: true,
2728 },
2729 },
David Benjamin65ac9972016-09-02 21:35:25 -04002730 },
David Benjamine3fbb362017-01-06 16:19:28 -05002731 {
2732 // Test the server so there is a large certificate as
2733 // well as application data.
2734 testType: serverTest,
2735 name: "MaxSendFragment",
2736 config: Config{
2737 Bugs: ProtocolBugs{
2738 MaxReceivePlaintext: 512,
2739 },
2740 },
2741 messageLen: 1024,
2742 flags: []string{
2743 "-max-send-fragment", "512",
2744 "-read-size", "1024",
2745 },
2746 },
2747 {
2748 // Test the server so there is a large certificate as
2749 // well as application data.
2750 testType: serverTest,
2751 name: "MaxSendFragment-TooLarge",
2752 config: Config{
2753 Bugs: ProtocolBugs{
2754 // Ensure that some of the records are
2755 // 512.
2756 MaxReceivePlaintext: 511,
2757 },
2758 },
2759 messageLen: 1024,
2760 flags: []string{
2761 "-max-send-fragment", "512",
2762 "-read-size", "1024",
2763 },
2764 shouldFail: true,
2765 expectedLocalError: "local error: record overflow",
2766 },
Adam Langley7c803a62015-06-15 15:35:05 -07002767 }
Adam Langley7c803a62015-06-15 15:35:05 -07002768 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002769
2770 // Test that very large messages can be received.
2771 cert := rsaCertificate
2772 for i := 0; i < 50; i++ {
2773 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2774 }
2775 testCases = append(testCases, testCase{
2776 name: "LargeMessage",
2777 config: Config{
2778 Certificates: []Certificate{cert},
2779 },
2780 })
2781 testCases = append(testCases, testCase{
2782 protocol: dtls,
2783 name: "LargeMessage-DTLS",
2784 config: Config{
2785 Certificates: []Certificate{cert},
2786 },
2787 })
2788
2789 // They are rejected if the maximum certificate chain length is capped.
2790 testCases = append(testCases, testCase{
2791 name: "LargeMessage-Reject",
2792 config: Config{
2793 Certificates: []Certificate{cert},
2794 },
2795 flags: []string{"-max-cert-list", "16384"},
2796 shouldFail: true,
2797 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2798 })
2799 testCases = append(testCases, testCase{
2800 protocol: dtls,
2801 name: "LargeMessage-Reject-DTLS",
2802 config: Config{
2803 Certificates: []Certificate{cert},
2804 },
2805 flags: []string{"-max-cert-list", "16384"},
2806 shouldFail: true,
2807 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2808 })
Adam Langley7c803a62015-06-15 15:35:05 -07002809}
2810
David Benjaminaa012042016-12-10 13:33:05 -05002811func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2812 const psk = "12345"
2813 const pskIdentity = "luggage combo"
2814
2815 var prefix string
2816 if protocol == dtls {
2817 if !ver.hasDTLS {
2818 return
2819 }
2820 prefix = "D"
2821 }
2822
2823 var cert Certificate
2824 var certFile string
2825 var keyFile string
2826 if hasComponent(suite.name, "ECDSA") {
2827 cert = ecdsaP256Certificate
2828 certFile = ecdsaP256CertificateFile
2829 keyFile = ecdsaP256KeyFile
2830 } else {
2831 cert = rsaCertificate
2832 certFile = rsaCertificateFile
2833 keyFile = rsaKeyFile
2834 }
2835
2836 var flags []string
2837 if hasComponent(suite.name, "PSK") {
2838 flags = append(flags,
2839 "-psk", psk,
2840 "-psk-identity", pskIdentity)
2841 }
2842 if hasComponent(suite.name, "NULL") {
2843 // NULL ciphers must be explicitly enabled.
2844 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2845 }
David Benjaminaa012042016-12-10 13:33:05 -05002846
2847 var shouldServerFail, shouldClientFail bool
2848 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2849 // BoringSSL clients accept ECDHE on SSLv3, but
2850 // a BoringSSL server will never select it
2851 // because the extension is missing.
2852 shouldServerFail = true
2853 }
2854 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2855 shouldClientFail = true
2856 shouldServerFail = true
2857 }
2858 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2859 shouldClientFail = true
2860 shouldServerFail = true
2861 }
2862 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2863 shouldClientFail = true
2864 shouldServerFail = true
2865 }
2866 if !isDTLSCipher(suite.name) && protocol == dtls {
2867 shouldClientFail = true
2868 shouldServerFail = true
2869 }
2870
2871 var sendCipherSuite uint16
2872 var expectedServerError, expectedClientError string
2873 serverCipherSuites := []uint16{suite.id}
2874 if shouldServerFail {
2875 expectedServerError = ":NO_SHARED_CIPHER:"
2876 }
2877 if shouldClientFail {
2878 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2879 // Configure the server to select ciphers as normal but
2880 // select an incompatible cipher in ServerHello.
2881 serverCipherSuites = nil
2882 sendCipherSuite = suite.id
2883 }
2884
David Benjamincdb6fe92017-02-07 16:06:48 -05002885 // For cipher suites and versions where exporters are defined, verify
2886 // that they interoperate.
2887 var exportKeyingMaterial int
2888 if ver.version > VersionSSL30 {
2889 exportKeyingMaterial = 1024
2890 }
2891
David Benjaminaa012042016-12-10 13:33:05 -05002892 testCases = append(testCases, testCase{
2893 testType: serverTest,
2894 protocol: protocol,
2895 name: prefix + ver.name + "-" + suite.name + "-server",
2896 config: Config{
2897 MinVersion: ver.version,
2898 MaxVersion: ver.version,
2899 CipherSuites: []uint16{suite.id},
2900 Certificates: []Certificate{cert},
2901 PreSharedKey: []byte(psk),
2902 PreSharedKeyIdentity: pskIdentity,
2903 Bugs: ProtocolBugs{
2904 AdvertiseAllConfiguredCiphers: true,
2905 },
2906 },
David Benjamina5022392017-07-10 17:40:39 -04002907 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002908 certFile: certFile,
2909 keyFile: keyFile,
2910 flags: flags,
2911 resumeSession: true,
2912 shouldFail: shouldServerFail,
2913 expectedError: expectedServerError,
2914 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002915 })
2916
2917 testCases = append(testCases, testCase{
2918 testType: clientTest,
2919 protocol: protocol,
2920 name: prefix + ver.name + "-" + suite.name + "-client",
2921 config: Config{
2922 MinVersion: ver.version,
2923 MaxVersion: ver.version,
2924 CipherSuites: serverCipherSuites,
2925 Certificates: []Certificate{cert},
2926 PreSharedKey: []byte(psk),
2927 PreSharedKeyIdentity: pskIdentity,
2928 Bugs: ProtocolBugs{
2929 IgnorePeerCipherPreferences: shouldClientFail,
2930 SendCipherSuite: sendCipherSuite,
2931 },
2932 },
David Benjamina5022392017-07-10 17:40:39 -04002933 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002934 flags: flags,
2935 resumeSession: true,
2936 shouldFail: shouldClientFail,
2937 expectedError: expectedClientError,
2938 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002939 })
2940
David Benjamin6f600d62016-12-21 16:06:54 -05002941 if shouldClientFail {
2942 return
2943 }
2944
2945 // Ensure the maximum record size is accepted.
2946 testCases = append(testCases, testCase{
2947 protocol: protocol,
2948 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2949 config: Config{
2950 MinVersion: ver.version,
2951 MaxVersion: ver.version,
2952 CipherSuites: []uint16{suite.id},
2953 Certificates: []Certificate{cert},
2954 PreSharedKey: []byte(psk),
2955 PreSharedKeyIdentity: pskIdentity,
2956 },
David Benjamina5022392017-07-10 17:40:39 -04002957 tls13Variant: ver.tls13Variant,
2958 flags: flags,
2959 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002960 })
2961
2962 // Test bad records for all ciphers. Bad records are fatal in TLS
2963 // and ignored in DTLS.
2964 var shouldFail bool
2965 var expectedError string
2966 if protocol == tls {
2967 shouldFail = true
2968 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2969 }
2970
2971 testCases = append(testCases, testCase{
2972 protocol: protocol,
2973 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2974 config: Config{
2975 MinVersion: ver.version,
2976 MaxVersion: ver.version,
2977 CipherSuites: []uint16{suite.id},
2978 Certificates: []Certificate{cert},
2979 PreSharedKey: []byte(psk),
2980 PreSharedKeyIdentity: pskIdentity,
2981 },
David Benjamina5022392017-07-10 17:40:39 -04002982 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002983 flags: flags,
2984 damageFirstWrite: true,
2985 messageLen: maxPlaintext,
2986 shouldFail: shouldFail,
2987 expectedError: expectedError,
2988 })
David Benjaminaa012042016-12-10 13:33:05 -05002989}
2990
Adam Langley95c29f32014-06-20 12:00:00 -07002991func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002992 const bogusCipher = 0xfe00
2993
Adam Langley95c29f32014-06-20 12:00:00 -07002994 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002995 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002996 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002997 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002998 }
David Benjamin2c99d282015-09-01 10:23:00 -04002999 }
Adam Langley95c29f32014-06-20 12:00:00 -07003000 }
Adam Langleya7997f12015-05-14 17:38:50 -07003001
3002 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003003 name: "NoSharedCipher",
3004 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003005 MaxVersion: VersionTLS12,
3006 CipherSuites: []uint16{},
3007 },
3008 shouldFail: true,
3009 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3010 })
3011
3012 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003013 name: "NoSharedCipher-TLS13",
3014 config: Config{
3015 MaxVersion: VersionTLS13,
3016 CipherSuites: []uint16{},
3017 },
3018 shouldFail: true,
3019 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3020 })
3021
3022 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003023 name: "UnsupportedCipherSuite",
3024 config: Config{
3025 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003026 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 Bugs: ProtocolBugs{
3028 IgnorePeerCipherPreferences: true,
3029 },
3030 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003031 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003032 shouldFail: true,
3033 expectedError: ":WRONG_CIPHER_RETURNED:",
3034 })
3035
3036 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003037 name: "ServerHelloBogusCipher",
3038 config: Config{
3039 MaxVersion: VersionTLS12,
3040 Bugs: ProtocolBugs{
3041 SendCipherSuite: bogusCipher,
3042 },
3043 },
3044 shouldFail: true,
3045 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3046 })
3047 testCases = append(testCases, testCase{
3048 name: "ServerHelloBogusCipher-TLS13",
3049 config: Config{
3050 MaxVersion: VersionTLS13,
3051 Bugs: ProtocolBugs{
3052 SendCipherSuite: bogusCipher,
3053 },
3054 },
3055 shouldFail: true,
3056 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3057 })
3058
David Benjamin241ae832016-01-15 03:04:54 -05003059 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003060 testCases = append(testCases, testCase{
3061 testType: serverTest,
3062 name: "UnknownCipher",
3063 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003064 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003065 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003066 Bugs: ProtocolBugs{
3067 AdvertiseAllConfiguredCiphers: true,
3068 },
3069 },
3070 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003071
3072 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003073 testCases = append(testCases, testCase{
3074 testType: serverTest,
3075 name: "UnknownCipher-TLS13",
3076 config: Config{
3077 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003078 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003079 Bugs: ProtocolBugs{
3080 AdvertiseAllConfiguredCiphers: true,
3081 },
David Benjamin241ae832016-01-15 03:04:54 -05003082 },
3083 })
3084
David Benjamin78679342016-09-16 19:42:05 -04003085 // Test empty ECDHE_PSK identity hints work as expected.
3086 testCases = append(testCases, testCase{
3087 name: "EmptyECDHEPSKHint",
3088 config: Config{
3089 MaxVersion: VersionTLS12,
3090 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3091 PreSharedKey: []byte("secret"),
3092 },
3093 flags: []string{"-psk", "secret"},
3094 })
3095
3096 // Test empty PSK identity hints work as expected, even if an explicit
3097 // ServerKeyExchange is sent.
3098 testCases = append(testCases, testCase{
3099 name: "ExplicitEmptyPSKHint",
3100 config: Config{
3101 MaxVersion: VersionTLS12,
3102 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3103 PreSharedKey: []byte("secret"),
3104 Bugs: ProtocolBugs{
3105 AlwaysSendPreSharedKeyIdentityHint: true,
3106 },
3107 },
3108 flags: []string{"-psk", "secret"},
3109 })
David Benjamin69522112017-03-28 15:38:29 -05003110
3111 // Test that clients enforce that the server-sent certificate and cipher
3112 // suite match in TLS 1.2.
3113 testCases = append(testCases, testCase{
3114 name: "CertificateCipherMismatch-RSA",
3115 config: Config{
3116 MaxVersion: VersionTLS12,
3117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3118 Certificates: []Certificate{rsaCertificate},
3119 Bugs: ProtocolBugs{
3120 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3121 },
3122 },
3123 shouldFail: true,
3124 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3125 })
3126 testCases = append(testCases, testCase{
3127 name: "CertificateCipherMismatch-ECDSA",
3128 config: Config{
3129 MaxVersion: VersionTLS12,
3130 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3131 Certificates: []Certificate{ecdsaP256Certificate},
3132 Bugs: ProtocolBugs{
3133 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3134 },
3135 },
3136 shouldFail: true,
3137 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3138 })
3139 testCases = append(testCases, testCase{
3140 name: "CertificateCipherMismatch-Ed25519",
3141 config: Config{
3142 MaxVersion: VersionTLS12,
3143 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3144 Certificates: []Certificate{ed25519Certificate},
3145 Bugs: ProtocolBugs{
3146 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 },
3149 shouldFail: true,
3150 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3151 })
3152
3153 // Test that servers decline to select a cipher suite which is
3154 // inconsistent with their configured certificate.
3155 testCases = append(testCases, testCase{
3156 testType: serverTest,
3157 name: "ServerCipherFilter-RSA",
3158 config: Config{
3159 MaxVersion: VersionTLS12,
3160 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3161 },
3162 flags: []string{
3163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3165 },
3166 shouldFail: true,
3167 expectedError: ":NO_SHARED_CIPHER:",
3168 })
3169 testCases = append(testCases, testCase{
3170 testType: serverTest,
3171 name: "ServerCipherFilter-ECDSA",
3172 config: Config{
3173 MaxVersion: VersionTLS12,
3174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3175 },
3176 flags: []string{
3177 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3178 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3179 },
3180 shouldFail: true,
3181 expectedError: ":NO_SHARED_CIPHER:",
3182 })
3183 testCases = append(testCases, testCase{
3184 testType: serverTest,
3185 name: "ServerCipherFilter-Ed25519",
3186 config: Config{
3187 MaxVersion: VersionTLS12,
3188 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3189 },
3190 flags: []string{
3191 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3192 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3193 },
3194 shouldFail: true,
3195 expectedError: ":NO_SHARED_CIPHER:",
3196 })
David Benjamin364af782017-07-01 10:35:27 -04003197
3198 // Test cipher suite negotiation works as expected. Configure a
3199 // complicated cipher suite configuration.
3200 const negotiationTestCiphers = "" +
3201 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3202 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3203 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3204 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3205 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3206 negotiationTests := []struct {
3207 ciphers []uint16
3208 expected uint16
3209 }{
3210 // Server preferences are honored, including when
3211 // equipreference groups are involved.
3212 {
3213 []uint16{
3214 TLS_RSA_WITH_AES_256_GCM_SHA384,
3215 TLS_RSA_WITH_AES_128_CBC_SHA,
3216 TLS_RSA_WITH_AES_128_GCM_SHA256,
3217 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3218 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3219 },
3220 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3221 },
3222 {
3223 []uint16{
3224 TLS_RSA_WITH_AES_256_GCM_SHA384,
3225 TLS_RSA_WITH_AES_128_CBC_SHA,
3226 TLS_RSA_WITH_AES_128_GCM_SHA256,
3227 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3228 },
3229 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3230 },
3231 {
3232 []uint16{
3233 TLS_RSA_WITH_AES_256_GCM_SHA384,
3234 TLS_RSA_WITH_AES_128_CBC_SHA,
3235 TLS_RSA_WITH_AES_128_GCM_SHA256,
3236 },
3237 TLS_RSA_WITH_AES_128_GCM_SHA256,
3238 },
3239 {
3240 []uint16{
3241 TLS_RSA_WITH_AES_256_GCM_SHA384,
3242 TLS_RSA_WITH_AES_128_CBC_SHA,
3243 },
3244 TLS_RSA_WITH_AES_128_CBC_SHA,
3245 },
3246 // Equipreference groups use the client preference.
3247 {
3248 []uint16{
3249 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3250 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3251 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3252 },
3253 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3254 },
3255 {
3256 []uint16{
3257 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3258 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3259 },
3260 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3261 },
3262 {
3263 []uint16{
3264 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3265 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3266 },
3267 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3268 },
3269 {
3270 []uint16{
3271 TLS_RSA_WITH_AES_256_GCM_SHA384,
3272 TLS_RSA_WITH_AES_256_CBC_SHA,
3273 },
3274 TLS_RSA_WITH_AES_256_GCM_SHA384,
3275 },
3276 {
3277 []uint16{
3278 TLS_RSA_WITH_AES_256_CBC_SHA,
3279 TLS_RSA_WITH_AES_256_GCM_SHA384,
3280 },
3281 TLS_RSA_WITH_AES_256_CBC_SHA,
3282 },
3283 // If there are two equipreference groups, the preferred one
3284 // takes precedence.
3285 {
3286 []uint16{
3287 TLS_RSA_WITH_AES_256_GCM_SHA384,
3288 TLS_RSA_WITH_AES_256_CBC_SHA,
3289 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3290 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3291 },
3292 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3293 },
3294 }
3295 for i, t := range negotiationTests {
3296 testCases = append(testCases, testCase{
3297 testType: serverTest,
3298 name: "CipherNegotiation-" + strconv.Itoa(i),
3299 config: Config{
3300 MaxVersion: VersionTLS12,
3301 CipherSuites: t.ciphers,
3302 },
3303 flags: []string{"-cipher", negotiationTestCiphers},
3304 expectedCipher: t.expected,
3305 })
3306 }
Adam Langley95c29f32014-06-20 12:00:00 -07003307}
3308
3309func addBadECDSASignatureTests() {
3310 for badR := BadValue(1); badR < NumBadValues; badR++ {
3311 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003312 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003313 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3314 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003315 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003316 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003317 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003318 Bugs: ProtocolBugs{
3319 BadECDSAR: badR,
3320 BadECDSAS: badS,
3321 },
3322 },
3323 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003324 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003325 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003326 testCases = append(testCases, testCase{
3327 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3328 config: Config{
3329 MaxVersion: VersionTLS13,
3330 Certificates: []Certificate{ecdsaP256Certificate},
3331 Bugs: ProtocolBugs{
3332 BadECDSAR: badR,
3333 BadECDSAS: badS,
3334 },
3335 },
3336 shouldFail: true,
3337 expectedError: ":BAD_SIGNATURE:",
3338 })
Adam Langley95c29f32014-06-20 12:00:00 -07003339 }
3340 }
3341}
3342
Adam Langley80842bd2014-06-20 12:00:00 -07003343func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003344 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003345 name: "MaxCBCPadding",
3346 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003347 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003348 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3349 Bugs: ProtocolBugs{
3350 MaxPadding: true,
3351 },
3352 },
3353 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3354 })
David Benjamin025b3d32014-07-01 19:53:04 -04003355 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003356 name: "BadCBCPadding",
3357 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003358 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003359 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3360 Bugs: ProtocolBugs{
3361 PaddingFirstByteBad: true,
3362 },
3363 },
3364 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003365 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003366 })
3367 // OpenSSL previously had an issue where the first byte of padding in
3368 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003369 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003370 name: "BadCBCPadding255",
3371 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003372 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3374 Bugs: ProtocolBugs{
3375 MaxPadding: true,
3376 PaddingFirstByteBadIf255: true,
3377 },
3378 },
3379 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3380 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003381 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003382 })
3383}
3384
Kenny Root7fdeaf12014-08-05 15:23:37 -07003385func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003386 var cbcCiphers = []struct {
3387 name string
3388 cipher uint16
3389 }{
3390 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3391 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3392 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3393 }
3394 for _, t := range cbcCiphers {
3395 testCases = append(testCases, testCase{
3396 name: "CBCRecordSplitting-" + t.name,
3397 config: Config{
3398 MaxVersion: VersionTLS10,
3399 MinVersion: VersionTLS10,
3400 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003401 Bugs: ProtocolBugs{
3402 ExpectRecordSplitting: true,
3403 },
David Benjamina1ce8562017-07-01 11:46:57 -04003404 },
3405 messageLen: -1, // read until EOF
3406 resumeSession: true,
3407 flags: []string{
3408 "-async",
3409 "-write-different-record-sizes",
3410 "-cbc-record-splitting",
3411 },
3412 })
3413 testCases = append(testCases, testCase{
3414 name: "CBCRecordSplittingPartialWrite-" + t.name,
3415 config: Config{
3416 MaxVersion: VersionTLS10,
3417 MinVersion: VersionTLS10,
3418 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003419 Bugs: ProtocolBugs{
3420 ExpectRecordSplitting: true,
3421 },
David Benjamina1ce8562017-07-01 11:46:57 -04003422 },
3423 messageLen: -1, // read until EOF
3424 flags: []string{
3425 "-async",
3426 "-write-different-record-sizes",
3427 "-cbc-record-splitting",
3428 "-partial-write",
3429 },
3430 })
3431 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003432}
3433
David Benjamin636293b2014-07-08 17:59:18 -04003434func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003435 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003436 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003437 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3438 cert, err := x509.ParseCertificate(cert.Certificate[0])
3439 if err != nil {
3440 panic(err)
3441 }
3442 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003443 }
Adam Langley2ff79332017-02-28 13:45:39 -08003444 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003445
David Benjamin636293b2014-07-08 17:59:18 -04003446 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003447 testCases = append(testCases, testCase{
3448 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003449 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003450 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003451 MinVersion: ver.version,
3452 MaxVersion: ver.version,
3453 ClientAuth: RequireAnyClientCert,
3454 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003455 },
David Benjamina5022392017-07-10 17:40:39 -04003456 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003457 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003458 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3459 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003460 },
3461 })
3462 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003463 testType: serverTest,
3464 name: ver.name + "-Server-ClientAuth-RSA",
3465 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003466 MinVersion: ver.version,
3467 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003468 Certificates: []Certificate{rsaCertificate},
3469 },
David Benjamina5022392017-07-10 17:40:39 -04003470 tls13Variant: ver.tls13Variant,
3471 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003472 })
David Benjamine098ec22014-08-27 23:13:20 -04003473 if ver.version != VersionSSL30 {
3474 testCases = append(testCases, testCase{
3475 testType: serverTest,
3476 name: ver.name + "-Server-ClientAuth-ECDSA",
3477 config: Config{
3478 MinVersion: ver.version,
3479 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003480 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003481 },
David Benjamina5022392017-07-10 17:40:39 -04003482 tls13Variant: ver.tls13Variant,
3483 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003484 })
3485 testCases = append(testCases, testCase{
3486 testType: clientTest,
3487 name: ver.name + "-Client-ClientAuth-ECDSA",
3488 config: Config{
3489 MinVersion: ver.version,
3490 MaxVersion: ver.version,
3491 ClientAuth: RequireAnyClientCert,
3492 ClientCAs: certPool,
3493 },
David Benjamina5022392017-07-10 17:40:39 -04003494 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003495 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003496 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3497 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003498 },
3499 })
3500 }
Adam Langley37646832016-08-01 16:16:46 -07003501
3502 testCases = append(testCases, testCase{
3503 name: "NoClientCertificate-" + ver.name,
3504 config: Config{
3505 MinVersion: ver.version,
3506 MaxVersion: ver.version,
3507 ClientAuth: RequireAnyClientCert,
3508 },
David Benjamina5022392017-07-10 17:40:39 -04003509 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003510 shouldFail: true,
3511 expectedLocalError: "client didn't provide a certificate",
3512 })
3513
3514 testCases = append(testCases, testCase{
3515 // Even if not configured to expect a certificate, OpenSSL will
3516 // return X509_V_OK as the verify_result.
3517 testType: serverTest,
3518 name: "NoClientCertificateRequested-Server-" + ver.name,
3519 config: Config{
3520 MinVersion: ver.version,
3521 MaxVersion: ver.version,
3522 },
David Benjamina5022392017-07-10 17:40:39 -04003523 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003524 flags: []string{
3525 "-expect-verify-result",
3526 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003527 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003528 })
3529
3530 testCases = append(testCases, testCase{
3531 // If a client certificate is not provided, OpenSSL will still
3532 // return X509_V_OK as the verify_result.
3533 testType: serverTest,
3534 name: "NoClientCertificate-Server-" + ver.name,
3535 config: Config{
3536 MinVersion: ver.version,
3537 MaxVersion: ver.version,
3538 },
David Benjamina5022392017-07-10 17:40:39 -04003539 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003540 flags: []string{
3541 "-expect-verify-result",
3542 "-verify-peer",
3543 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003544 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003545 })
3546
David Benjamin1db9e1b2016-10-07 20:51:43 -04003547 certificateRequired := "remote error: certificate required"
3548 if ver.version < VersionTLS13 {
3549 // Prior to TLS 1.3, the generic handshake_failure alert
3550 // was used.
3551 certificateRequired = "remote error: handshake failure"
3552 }
Adam Langley37646832016-08-01 16:16:46 -07003553 testCases = append(testCases, testCase{
3554 testType: serverTest,
3555 name: "RequireAnyClientCertificate-" + ver.name,
3556 config: Config{
3557 MinVersion: ver.version,
3558 MaxVersion: ver.version,
3559 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003560 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003561 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003562 shouldFail: true,
3563 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3564 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003565 })
3566
3567 if ver.version != VersionSSL30 {
3568 testCases = append(testCases, testCase{
3569 testType: serverTest,
3570 name: "SkipClientCertificate-" + ver.name,
3571 config: Config{
3572 MinVersion: ver.version,
3573 MaxVersion: ver.version,
3574 Bugs: ProtocolBugs{
3575 SkipClientCertificate: true,
3576 },
3577 },
3578 // Setting SSL_VERIFY_PEER allows anonymous clients.
3579 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003580 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003581 shouldFail: true,
3582 expectedError: ":UNEXPECTED_MESSAGE:",
3583 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003584
3585 testCases = append(testCases, testCase{
3586 testType: serverTest,
3587 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3588 config: Config{
3589 MinVersion: ver.version,
3590 MaxVersion: ver.version,
3591 },
3592 flags: []string{
3593 "-enable-channel-id",
3594 "-verify-peer-if-no-obc",
3595 },
David Benjamina5022392017-07-10 17:40:39 -04003596 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003597 shouldFail: true,
3598 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3599 expectedLocalError: certificateRequired,
3600 })
3601
3602 testCases = append(testCases, testCase{
3603 testType: serverTest,
3604 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3605 config: Config{
3606 MinVersion: ver.version,
3607 MaxVersion: ver.version,
3608 ChannelID: channelIDKey,
3609 },
3610 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003611 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003612 flags: []string{
3613 "-enable-channel-id",
3614 "-verify-peer-if-no-obc",
3615 },
3616 })
Adam Langley37646832016-08-01 16:16:46 -07003617 }
Adam Langley2ff79332017-02-28 13:45:39 -08003618
3619 testCases = append(testCases, testCase{
3620 testType: serverTest,
3621 name: ver.name + "-Server-CertReq-CA-List",
3622 config: Config{
3623 MinVersion: ver.version,
3624 MaxVersion: ver.version,
3625 Certificates: []Certificate{rsaCertificate},
3626 Bugs: ProtocolBugs{
3627 ExpectCertificateReqNames: caNames,
3628 },
3629 },
David Benjamina5022392017-07-10 17:40:39 -04003630 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003631 flags: []string{
3632 "-require-any-client-certificate",
3633 "-use-client-ca-list", encodeDERValues(caNames),
3634 },
3635 })
3636
3637 testCases = append(testCases, testCase{
3638 testType: clientTest,
3639 name: ver.name + "-Client-CertReq-CA-List",
3640 config: Config{
3641 MinVersion: ver.version,
3642 MaxVersion: ver.version,
3643 Certificates: []Certificate{rsaCertificate},
3644 ClientAuth: RequireAnyClientCert,
3645 ClientCAs: certPool,
3646 },
David Benjamina5022392017-07-10 17:40:39 -04003647 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003648 flags: []string{
3649 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3650 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3651 "-expect-client-ca-list", encodeDERValues(caNames),
3652 },
3653 })
David Benjamin636293b2014-07-08 17:59:18 -04003654 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003655
David Benjaminc032dfa2016-05-12 14:54:57 -04003656 // Client auth is only legal in certificate-based ciphers.
3657 testCases = append(testCases, testCase{
3658 testType: clientTest,
3659 name: "ClientAuth-PSK",
3660 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003661 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003662 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3663 PreSharedKey: []byte("secret"),
3664 ClientAuth: RequireAnyClientCert,
3665 },
3666 flags: []string{
3667 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3668 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3669 "-psk", "secret",
3670 },
3671 shouldFail: true,
3672 expectedError: ":UNEXPECTED_MESSAGE:",
3673 })
3674 testCases = append(testCases, testCase{
3675 testType: clientTest,
3676 name: "ClientAuth-ECDHE_PSK",
3677 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003678 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003679 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3680 PreSharedKey: []byte("secret"),
3681 ClientAuth: RequireAnyClientCert,
3682 },
3683 flags: []string{
3684 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3685 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3686 "-psk", "secret",
3687 },
3688 shouldFail: true,
3689 expectedError: ":UNEXPECTED_MESSAGE:",
3690 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003691
3692 // Regression test for a bug where the client CA list, if explicitly
3693 // set to NULL, was mis-encoded.
3694 testCases = append(testCases, testCase{
3695 testType: serverTest,
3696 name: "Null-Client-CA-List",
3697 config: Config{
3698 MaxVersion: VersionTLS12,
3699 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003700 Bugs: ProtocolBugs{
3701 ExpectCertificateReqNames: [][]byte{},
3702 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003703 },
3704 flags: []string{
3705 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003706 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003707 },
3708 })
David Benjamin636293b2014-07-08 17:59:18 -04003709}
3710
Adam Langley75712922014-10-10 16:23:43 -07003711func addExtendedMasterSecretTests() {
3712 const expectEMSFlag = "-expect-extended-master-secret"
3713
3714 for _, with := range []bool{false, true} {
3715 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003716 if with {
3717 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003718 }
3719
3720 for _, isClient := range []bool{false, true} {
3721 suffix := "-Server"
3722 testType := serverTest
3723 if isClient {
3724 suffix = "-Client"
3725 testType = clientTest
3726 }
3727
3728 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003729 // In TLS 1.3, the extension is irrelevant and
3730 // always reports as enabled.
3731 var flags []string
3732 if with || ver.version >= VersionTLS13 {
3733 flags = []string{expectEMSFlag}
3734 }
3735
Adam Langley75712922014-10-10 16:23:43 -07003736 test := testCase{
3737 testType: testType,
3738 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3739 config: Config{
3740 MinVersion: ver.version,
3741 MaxVersion: ver.version,
3742 Bugs: ProtocolBugs{
3743 NoExtendedMasterSecret: !with,
3744 RequireExtendedMasterSecret: with,
3745 },
3746 },
David Benjamina5022392017-07-10 17:40:39 -04003747 tls13Variant: ver.tls13Variant,
3748 flags: flags,
3749 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003750 }
3751 if test.shouldFail {
3752 test.expectedLocalError = "extended master secret required but not supported by peer"
3753 }
3754 testCases = append(testCases, test)
3755 }
3756 }
3757 }
3758
Adam Langleyba5934b2015-06-02 10:50:35 -07003759 for _, isClient := range []bool{false, true} {
3760 for _, supportedInFirstConnection := range []bool{false, true} {
3761 for _, supportedInResumeConnection := range []bool{false, true} {
3762 boolToWord := func(b bool) string {
3763 if b {
3764 return "Yes"
3765 }
3766 return "No"
3767 }
3768 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3769 if isClient {
3770 suffix += "Client"
3771 } else {
3772 suffix += "Server"
3773 }
3774
3775 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003776 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003777 Bugs: ProtocolBugs{
3778 RequireExtendedMasterSecret: true,
3779 },
3780 }
3781
3782 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003784 Bugs: ProtocolBugs{
3785 NoExtendedMasterSecret: true,
3786 },
3787 }
3788
3789 test := testCase{
3790 name: "ExtendedMasterSecret-" + suffix,
3791 resumeSession: true,
3792 }
3793
3794 if !isClient {
3795 test.testType = serverTest
3796 }
3797
3798 if supportedInFirstConnection {
3799 test.config = supportedConfig
3800 } else {
3801 test.config = noSupportConfig
3802 }
3803
3804 if supportedInResumeConnection {
3805 test.resumeConfig = &supportedConfig
3806 } else {
3807 test.resumeConfig = &noSupportConfig
3808 }
3809
3810 switch suffix {
3811 case "YesToYes-Client", "YesToYes-Server":
3812 // When a session is resumed, it should
3813 // still be aware that its master
3814 // secret was generated via EMS and
3815 // thus it's safe to use tls-unique.
3816 test.flags = []string{expectEMSFlag}
3817 case "NoToYes-Server":
3818 // If an original connection did not
3819 // contain EMS, but a resumption
3820 // handshake does, then a server should
3821 // not resume the session.
3822 test.expectResumeRejected = true
3823 case "YesToNo-Server":
3824 // Resuming an EMS session without the
3825 // EMS extension should cause the
3826 // server to abort the connection.
3827 test.shouldFail = true
3828 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3829 case "NoToYes-Client":
3830 // A client should abort a connection
3831 // where the server resumed a non-EMS
3832 // session but echoed the EMS
3833 // extension.
3834 test.shouldFail = true
3835 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3836 case "YesToNo-Client":
3837 // A client should abort a connection
3838 // where the server didn't echo EMS
3839 // when the session used it.
3840 test.shouldFail = true
3841 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3842 }
3843
3844 testCases = append(testCases, test)
3845 }
3846 }
3847 }
David Benjamin163c9562016-08-29 23:14:17 -04003848
3849 // Switching EMS on renegotiation is forbidden.
3850 testCases = append(testCases, testCase{
3851 name: "ExtendedMasterSecret-Renego-NoEMS",
3852 config: Config{
3853 MaxVersion: VersionTLS12,
3854 Bugs: ProtocolBugs{
3855 NoExtendedMasterSecret: true,
3856 NoExtendedMasterSecretOnRenegotiation: true,
3857 },
3858 },
3859 renegotiate: 1,
3860 flags: []string{
3861 "-renegotiate-freely",
3862 "-expect-total-renegotiations", "1",
3863 },
3864 })
3865
3866 testCases = append(testCases, testCase{
3867 name: "ExtendedMasterSecret-Renego-Upgrade",
3868 config: Config{
3869 MaxVersion: VersionTLS12,
3870 Bugs: ProtocolBugs{
3871 NoExtendedMasterSecret: true,
3872 },
3873 },
3874 renegotiate: 1,
3875 flags: []string{
3876 "-renegotiate-freely",
3877 "-expect-total-renegotiations", "1",
3878 },
3879 shouldFail: true,
3880 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3881 })
3882
3883 testCases = append(testCases, testCase{
3884 name: "ExtendedMasterSecret-Renego-Downgrade",
3885 config: Config{
3886 MaxVersion: VersionTLS12,
3887 Bugs: ProtocolBugs{
3888 NoExtendedMasterSecretOnRenegotiation: true,
3889 },
3890 },
3891 renegotiate: 1,
3892 flags: []string{
3893 "-renegotiate-freely",
3894 "-expect-total-renegotiations", "1",
3895 },
3896 shouldFail: true,
3897 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3898 })
Adam Langley75712922014-10-10 16:23:43 -07003899}
3900
David Benjamin582ba042016-07-07 12:33:25 -07003901type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003902 protocol protocol
3903 async bool
3904 splitHandshake bool
3905 packHandshakeFlight bool
3906 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003907}
3908
David Benjamin43ec06f2014-08-05 02:28:57 -04003909// Adds tests that try to cover the range of the handshake state machine, under
3910// various conditions. Some of these are redundant with other tests, but they
3911// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003912func addAllStateMachineCoverageTests() {
3913 for _, async := range []bool{false, true} {
3914 for _, protocol := range []protocol{tls, dtls} {
3915 addStateMachineCoverageTests(stateMachineTestConfig{
3916 protocol: protocol,
3917 async: async,
3918 })
3919 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003920 protocol: protocol,
3921 async: async,
3922 implicitHandshake: true,
3923 })
3924 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003925 protocol: protocol,
3926 async: async,
3927 splitHandshake: true,
3928 })
3929 if protocol == tls {
3930 addStateMachineCoverageTests(stateMachineTestConfig{
3931 protocol: protocol,
3932 async: async,
3933 packHandshakeFlight: true,
3934 })
3935 }
3936 }
3937 }
3938}
3939
3940func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003941 var tests []testCase
3942
3943 // Basic handshake, with resumption. Client and server,
3944 // session ID and session ticket.
3945 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 name: "Basic-Client",
3947 config: Config{
3948 MaxVersion: VersionTLS12,
3949 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003951 // Ensure session tickets are used, not session IDs.
3952 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 })
3954 tests = append(tests, testCase{
3955 name: "Basic-Client-RenewTicket",
3956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003957 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003958 Bugs: ProtocolBugs{
3959 RenewTicketOnResume: true,
3960 },
3961 },
David Benjamin46662482016-08-17 00:51:00 -04003962 flags: []string{"-expect-ticket-renewal"},
3963 resumeSession: true,
3964 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003965 })
3966 tests = append(tests, testCase{
3967 name: "Basic-Client-NoTicket",
3968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 SessionTicketsDisabled: true,
3971 },
3972 resumeSession: true,
3973 })
3974 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003975 testType: serverTest,
3976 name: "Basic-Server",
3977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003978 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003979 Bugs: ProtocolBugs{
3980 RequireSessionTickets: true,
3981 },
3982 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003983 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003984 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003985 })
3986 tests = append(tests, testCase{
3987 testType: serverTest,
3988 name: "Basic-Server-NoTickets",
3989 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003990 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003991 SessionTicketsDisabled: true,
3992 },
3993 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003994 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003995 })
3996 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003997 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003998 name: "Basic-Server-EarlyCallback",
3999 config: Config{
4000 MaxVersion: VersionTLS12,
4001 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004002 flags: []string{"-use-early-callback"},
4003 resumeSession: true,
4004 })
4005
Steven Valdez143e8b32016-07-11 13:19:03 -04004006 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004007 if config.protocol == tls {
4008 tests = append(tests, testCase{
4009 name: "TLS13-1RTT-Client",
4010 config: Config{
4011 MaxVersion: VersionTLS13,
4012 MinVersion: VersionTLS13,
4013 },
David Benjamin46662482016-08-17 00:51:00 -04004014 resumeSession: true,
4015 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004016 })
4017
4018 tests = append(tests, testCase{
4019 testType: serverTest,
4020 name: "TLS13-1RTT-Server",
4021 config: Config{
4022 MaxVersion: VersionTLS13,
4023 MinVersion: VersionTLS13,
4024 },
David Benjamin46662482016-08-17 00:51:00 -04004025 resumeSession: true,
4026 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004027 // TLS 1.3 uses tickets, so the session should not be
4028 // cached statefully.
4029 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004030 })
4031
4032 tests = append(tests, testCase{
4033 name: "TLS13-HelloRetryRequest-Client",
4034 config: Config{
4035 MaxVersion: VersionTLS13,
4036 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004037 // P-384 requires a HelloRetryRequest against BoringSSL's default
4038 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004039 CurvePreferences: []CurveID{CurveP384},
4040 Bugs: ProtocolBugs{
4041 ExpectMissingKeyShare: true,
4042 },
4043 },
4044 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4045 resumeSession: true,
4046 })
4047
4048 tests = append(tests, testCase{
4049 testType: serverTest,
4050 name: "TLS13-HelloRetryRequest-Server",
4051 config: Config{
4052 MaxVersion: VersionTLS13,
4053 MinVersion: VersionTLS13,
4054 // Require a HelloRetryRequest for every curve.
4055 DefaultCurves: []CurveID{},
4056 },
4057 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4058 resumeSession: true,
4059 })
Steven Valdez2d850622017-01-11 11:34:52 -05004060
Steven Valdez2d850622017-01-11 11:34:52 -05004061 tests = append(tests, testCase{
4062 testType: clientTest,
4063 name: "TLS13-EarlyData-Client",
4064 config: Config{
4065 MaxVersion: VersionTLS13,
4066 MinVersion: VersionTLS13,
4067 MaxEarlyDataSize: 16384,
4068 },
Steven Valdeze831a812017-03-09 14:56:07 -05004069 resumeConfig: &Config{
4070 MaxVersion: VersionTLS13,
4071 MinVersion: VersionTLS13,
4072 MaxEarlyDataSize: 16384,
4073 Bugs: ProtocolBugs{
4074 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4075 },
4076 },
Steven Valdez2d850622017-01-11 11:34:52 -05004077 resumeSession: true,
4078 flags: []string{
4079 "-enable-early-data",
4080 "-expect-early-data-info",
4081 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004082 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004083 },
4084 })
4085
4086 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004087 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004088 name: "TLS13Experiment-EarlyData-Client",
4089 config: Config{
4090 MaxVersion: VersionTLS13,
4091 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004092 MaxEarlyDataSize: 16384,
4093 },
4094 resumeConfig: &Config{
4095 MaxVersion: VersionTLS13,
4096 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004097 MaxEarlyDataSize: 16384,
4098 Bugs: ProtocolBugs{
4099 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4100 },
4101 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004102 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004103 resumeSession: true,
4104 flags: []string{
4105 "-enable-early-data",
4106 "-expect-early-data-info",
4107 "-expect-accept-early-data",
4108 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004109 },
4110 })
4111
4112 tests = append(tests, testCase{
4113 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004114 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4115 config: Config{
4116 MaxVersion: VersionTLS13,
4117 MinVersion: VersionTLS13,
4118 TLS13Variant: TLS13RecordTypeExperiment,
4119 MaxEarlyDataSize: 16384,
4120 },
4121 resumeConfig: &Config{
4122 MaxVersion: VersionTLS13,
4123 MinVersion: VersionTLS13,
4124 TLS13Variant: TLS13RecordTypeExperiment,
4125 MaxEarlyDataSize: 16384,
4126 Bugs: ProtocolBugs{
4127 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4128 },
4129 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004130 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004131 resumeSession: true,
4132 flags: []string{
4133 "-enable-early-data",
4134 "-expect-early-data-info",
4135 "-expect-accept-early-data",
4136 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004137 },
4138 })
4139
4140 tests = append(tests, testCase{
4141 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004142 name: "TLS13-EarlyData-TooMuchData-Client",
4143 config: Config{
4144 MaxVersion: VersionTLS13,
4145 MinVersion: VersionTLS13,
4146 MaxEarlyDataSize: 2,
4147 },
4148 resumeConfig: &Config{
4149 MaxVersion: VersionTLS13,
4150 MinVersion: VersionTLS13,
4151 MaxEarlyDataSize: 2,
4152 Bugs: ProtocolBugs{
4153 ExpectEarlyData: [][]byte{{'h', 'e'}},
4154 },
4155 },
4156 resumeShimPrefix: "llo",
4157 resumeSession: true,
4158 flags: []string{
4159 "-enable-early-data",
4160 "-expect-early-data-info",
4161 "-expect-accept-early-data",
4162 "-on-resume-shim-writes-first",
4163 },
4164 })
4165
4166 // Unfinished writes can only be tested when operations are async. EarlyData
4167 // can't be tested as part of an ImplicitHandshake in this case since
4168 // otherwise the early data will be sent as normal data.
4169 if config.async && !config.implicitHandshake {
4170 tests = append(tests, testCase{
4171 testType: clientTest,
4172 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4173 config: Config{
4174 MaxVersion: VersionTLS13,
4175 MinVersion: VersionTLS13,
4176 MaxEarlyDataSize: 16384,
4177 },
4178 resumeConfig: &Config{
4179 MaxVersion: VersionTLS13,
4180 MinVersion: VersionTLS13,
4181 MaxEarlyDataSize: 16384,
4182 Bugs: ProtocolBugs{
4183 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4184 },
4185 },
4186 resumeSession: true,
4187 flags: []string{
4188 "-enable-early-data",
4189 "-expect-early-data-info",
4190 "-expect-accept-early-data",
4191 "-on-resume-read-with-unfinished-write",
4192 "-on-resume-shim-writes-first",
4193 },
4194 })
4195
4196 // Rejected unfinished writes are discarded (from the
4197 // perspective of the calling application) on 0-RTT
4198 // reject.
4199 tests = append(tests, testCase{
4200 testType: clientTest,
4201 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4202 config: Config{
4203 MaxVersion: VersionTLS13,
4204 MinVersion: VersionTLS13,
4205 MaxEarlyDataSize: 16384,
4206 },
4207 resumeConfig: &Config{
4208 MaxVersion: VersionTLS13,
4209 MinVersion: VersionTLS13,
4210 MaxEarlyDataSize: 16384,
4211 Bugs: ProtocolBugs{
4212 AlwaysRejectEarlyData: true,
4213 },
4214 },
4215 resumeSession: true,
4216 flags: []string{
4217 "-enable-early-data",
4218 "-expect-early-data-info",
4219 "-expect-reject-early-data",
4220 "-on-resume-read-with-unfinished-write",
4221 "-on-resume-shim-writes-first",
4222 },
4223 })
4224 }
4225
4226 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004227 testType: serverTest,
4228 name: "TLS13-EarlyData-Server",
4229 config: Config{
4230 MaxVersion: VersionTLS13,
4231 MinVersion: VersionTLS13,
4232 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004233 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004234 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004235 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004236 },
4237 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004238 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004239 resumeSession: true,
4240 flags: []string{
4241 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004242 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004243 },
4244 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004245
4246 tests = append(tests, testCase{
4247 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004248 name: "TLS13Experiment-EarlyData-Server",
4249 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004250 MaxVersion: VersionTLS13,
4251 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004252 Bugs: ProtocolBugs{
4253 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4254 ExpectEarlyDataAccepted: true,
4255 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4256 },
4257 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004258 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004259 messageCount: 2,
4260 resumeSession: true,
4261 flags: []string{
4262 "-enable-early-data",
4263 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004264 },
4265 })
4266
4267 tests = append(tests, testCase{
4268 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004269 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4270 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004271 MaxVersion: VersionTLS13,
4272 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004273 Bugs: ProtocolBugs{
4274 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4275 ExpectEarlyDataAccepted: true,
4276 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4277 },
4278 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004279 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004280 messageCount: 2,
4281 resumeSession: true,
4282 flags: []string{
4283 "-enable-early-data",
4284 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004285 },
4286 })
4287
4288 tests = append(tests, testCase{
4289 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004290 name: "TLS13-MaxEarlyData-Server",
4291 config: Config{
4292 MaxVersion: VersionTLS13,
4293 MinVersion: VersionTLS13,
4294 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004295 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004296 ExpectEarlyDataAccepted: true,
4297 },
4298 },
4299 messageCount: 2,
4300 resumeSession: true,
4301 flags: []string{
4302 "-enable-early-data",
4303 "-expect-accept-early-data",
4304 },
4305 shouldFail: true,
4306 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4307 })
David Benjamine73c7f42016-08-17 00:29:33 -04004308 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004309
David Benjamin760b1dd2015-05-15 23:33:48 -04004310 // TLS client auth.
4311 tests = append(tests, testCase{
4312 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004313 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004315 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004316 ClientAuth: RequestClientCert,
4317 },
4318 })
4319 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004320 testType: serverTest,
4321 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 config: Config{
4323 MaxVersion: VersionTLS12,
4324 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004325 // Setting SSL_VERIFY_PEER allows anonymous clients.
4326 flags: []string{"-verify-peer"},
4327 })
David Benjamin582ba042016-07-07 12:33:25 -07004328 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004329 tests = append(tests, testCase{
4330 testType: clientTest,
4331 name: "ClientAuth-NoCertificate-Client-SSL3",
4332 config: Config{
4333 MaxVersion: VersionSSL30,
4334 ClientAuth: RequestClientCert,
4335 },
4336 })
4337 tests = append(tests, testCase{
4338 testType: serverTest,
4339 name: "ClientAuth-NoCertificate-Server-SSL3",
4340 config: Config{
4341 MaxVersion: VersionSSL30,
4342 },
4343 // Setting SSL_VERIFY_PEER allows anonymous clients.
4344 flags: []string{"-verify-peer"},
4345 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004346 tests = append(tests, testCase{
4347 testType: clientTest,
4348 name: "ClientAuth-NoCertificate-Client-TLS13",
4349 config: Config{
4350 MaxVersion: VersionTLS13,
4351 ClientAuth: RequestClientCert,
4352 },
4353 })
4354 tests = append(tests, testCase{
4355 testType: serverTest,
4356 name: "ClientAuth-NoCertificate-Server-TLS13",
4357 config: Config{
4358 MaxVersion: VersionTLS13,
4359 },
4360 // Setting SSL_VERIFY_PEER allows anonymous clients.
4361 flags: []string{"-verify-peer"},
4362 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004363 }
4364 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004365 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004366 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004368 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004369 ClientAuth: RequireAnyClientCert,
4370 },
4371 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004372 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4373 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004374 },
4375 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004376 tests = append(tests, testCase{
4377 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004378 name: "ClientAuth-RSA-Client-TLS13",
4379 config: Config{
4380 MaxVersion: VersionTLS13,
4381 ClientAuth: RequireAnyClientCert,
4382 },
4383 flags: []string{
4384 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4385 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4386 },
4387 })
4388 tests = append(tests, testCase{
4389 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004390 name: "ClientAuth-ECDSA-Client",
4391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004392 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004393 ClientAuth: RequireAnyClientCert,
4394 },
4395 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004396 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4397 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004398 },
4399 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004400 tests = append(tests, testCase{
4401 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004402 name: "ClientAuth-ECDSA-Client-TLS13",
4403 config: Config{
4404 MaxVersion: VersionTLS13,
4405 ClientAuth: RequireAnyClientCert,
4406 },
4407 flags: []string{
4408 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4409 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4410 },
4411 })
4412 tests = append(tests, testCase{
4413 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004414 name: "ClientAuth-NoCertificate-OldCallback",
4415 config: Config{
4416 MaxVersion: VersionTLS12,
4417 ClientAuth: RequestClientCert,
4418 },
4419 flags: []string{"-use-old-client-cert-callback"},
4420 })
4421 tests = append(tests, testCase{
4422 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004423 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4424 config: Config{
4425 MaxVersion: VersionTLS13,
4426 ClientAuth: RequestClientCert,
4427 },
4428 flags: []string{"-use-old-client-cert-callback"},
4429 })
4430 tests = append(tests, testCase{
4431 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004432 name: "ClientAuth-OldCallback",
4433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004434 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004435 ClientAuth: RequireAnyClientCert,
4436 },
4437 flags: []string{
4438 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4439 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4440 "-use-old-client-cert-callback",
4441 },
4442 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004443 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004444 testType: clientTest,
4445 name: "ClientAuth-OldCallback-TLS13",
4446 config: Config{
4447 MaxVersion: VersionTLS13,
4448 ClientAuth: RequireAnyClientCert,
4449 },
4450 flags: []string{
4451 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4452 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4453 "-use-old-client-cert-callback",
4454 },
4455 })
4456 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004457 testType: serverTest,
4458 name: "ClientAuth-Server",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 Certificates: []Certificate{rsaCertificate},
4462 },
4463 flags: []string{"-require-any-client-certificate"},
4464 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004465 tests = append(tests, testCase{
4466 testType: serverTest,
4467 name: "ClientAuth-Server-TLS13",
4468 config: Config{
4469 MaxVersion: VersionTLS13,
4470 Certificates: []Certificate{rsaCertificate},
4471 },
4472 flags: []string{"-require-any-client-certificate"},
4473 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004474
David Benjamin4c3ddf72016-06-29 18:13:53 -04004475 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004476 tests = append(tests, testCase{
4477 testType: serverTest,
4478 name: "Basic-Server-RSA",
4479 config: Config{
4480 MaxVersion: VersionTLS12,
4481 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4482 },
4483 flags: []string{
4484 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4485 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4486 },
4487 })
4488 tests = append(tests, testCase{
4489 testType: serverTest,
4490 name: "Basic-Server-ECDHE-RSA",
4491 config: Config{
4492 MaxVersion: VersionTLS12,
4493 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4494 },
4495 flags: []string{
4496 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4497 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4498 },
4499 })
4500 tests = append(tests, testCase{
4501 testType: serverTest,
4502 name: "Basic-Server-ECDHE-ECDSA",
4503 config: Config{
4504 MaxVersion: VersionTLS12,
4505 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4506 },
4507 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004508 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4509 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004510 },
4511 })
David Benjamin69522112017-03-28 15:38:29 -05004512 tests = append(tests, testCase{
4513 testType: serverTest,
4514 name: "Basic-Server-Ed25519",
4515 config: Config{
4516 MaxVersion: VersionTLS12,
4517 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4518 },
4519 flags: []string{
4520 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4521 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4522 "-enable-ed25519",
4523 },
4524 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004525
David Benjamin760b1dd2015-05-15 23:33:48 -04004526 // No session ticket support; server doesn't send NewSessionTicket.
4527 tests = append(tests, testCase{
4528 name: "SessionTicketsDisabled-Client",
4529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004530 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004531 SessionTicketsDisabled: true,
4532 },
4533 })
4534 tests = append(tests, testCase{
4535 testType: serverTest,
4536 name: "SessionTicketsDisabled-Server",
4537 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004538 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004539 SessionTicketsDisabled: true,
4540 },
4541 })
4542
4543 // Skip ServerKeyExchange in PSK key exchange if there's no
4544 // identity hint.
4545 tests = append(tests, testCase{
4546 name: "EmptyPSKHint-Client",
4547 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004548 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004549 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4550 PreSharedKey: []byte("secret"),
4551 },
4552 flags: []string{"-psk", "secret"},
4553 })
4554 tests = append(tests, testCase{
4555 testType: serverTest,
4556 name: "EmptyPSKHint-Server",
4557 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004558 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004559 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4560 PreSharedKey: []byte("secret"),
4561 },
4562 flags: []string{"-psk", "secret"},
4563 })
4564
David Benjamin4c3ddf72016-06-29 18:13:53 -04004565 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004566 tests = append(tests, testCase{
4567 testType: clientTest,
4568 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004569 config: Config{
4570 MaxVersion: VersionTLS12,
4571 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004572 flags: []string{
4573 "-enable-ocsp-stapling",
4574 "-expect-ocsp-response",
4575 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004576 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004577 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004578 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004579 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004580 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004581 testType: serverTest,
4582 name: "OCSPStapling-Server",
4583 config: Config{
4584 MaxVersion: VersionTLS12,
4585 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004586 expectedOCSPResponse: testOCSPResponse,
4587 flags: []string{
4588 "-ocsp-response",
4589 base64.StdEncoding.EncodeToString(testOCSPResponse),
4590 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004591 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004592 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004593 tests = append(tests, testCase{
4594 testType: clientTest,
4595 name: "OCSPStapling-Client-TLS13",
4596 config: Config{
4597 MaxVersion: VersionTLS13,
4598 },
4599 flags: []string{
4600 "-enable-ocsp-stapling",
4601 "-expect-ocsp-response",
4602 base64.StdEncoding.EncodeToString(testOCSPResponse),
4603 "-verify-peer",
4604 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004605 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004606 })
4607 tests = append(tests, testCase{
4608 testType: serverTest,
4609 name: "OCSPStapling-Server-TLS13",
4610 config: Config{
4611 MaxVersion: VersionTLS13,
4612 },
4613 expectedOCSPResponse: testOCSPResponse,
4614 flags: []string{
4615 "-ocsp-response",
4616 base64.StdEncoding.EncodeToString(testOCSPResponse),
4617 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004618 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004619 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004620
David Benjamin4c3ddf72016-06-29 18:13:53 -04004621 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004622 for _, vers := range tlsVersions {
4623 if config.protocol == dtls && !vers.hasDTLS {
4624 continue
4625 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004626 for _, useCustomCallback := range []bool{false, true} {
4627 for _, testType := range []testType{clientTest, serverTest} {
4628 suffix := "-Client"
4629 if testType == serverTest {
4630 suffix = "-Server"
4631 }
4632 suffix += "-" + vers.name
4633 if useCustomCallback {
4634 suffix += "-CustomCallback"
4635 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004636
David Benjamin3a1dd462017-07-11 16:13:10 -04004637 flags := []string{"-verify-peer"}
4638 if testType == serverTest {
4639 flags = append(flags, "-require-any-client-certificate")
4640 }
4641 if useCustomCallback {
4642 flags = append(flags, "-use-custom-verify-callback")
4643 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004644
David Benjamin3a1dd462017-07-11 16:13:10 -04004645 tests = append(tests, testCase{
4646 testType: testType,
4647 name: "CertificateVerificationSucceed" + suffix,
4648 config: Config{
4649 MaxVersion: vers.version,
4650 Certificates: []Certificate{rsaCertificate},
4651 },
4652 tls13Variant: vers.tls13Variant,
4653 flags: append([]string{"-expect-verify-result"}, flags...),
4654 resumeSession: true,
4655 })
4656 tests = append(tests, testCase{
4657 testType: testType,
4658 name: "CertificateVerificationFail" + suffix,
4659 config: Config{
4660 MaxVersion: vers.version,
4661 Certificates: []Certificate{rsaCertificate},
4662 },
4663 tls13Variant: vers.tls13Variant,
4664 flags: append([]string{"-verify-fail"}, flags...),
4665 shouldFail: true,
4666 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4667 })
4668 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004669 }
4670
4671 // By default, the client is in a soft fail mode where the peer
4672 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004673 tests = append(tests, testCase{
4674 testType: clientTest,
4675 name: "CertificateVerificationSoftFail-" + vers.name,
4676 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004677 MaxVersion: vers.version,
4678 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004679 },
David Benjamina5022392017-07-10 17:40:39 -04004680 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004681 flags: []string{
4682 "-verify-fail",
4683 "-expect-verify-result",
4684 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004685 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004686 })
4687 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004688
David Benjamin1d4f4c02016-07-26 18:03:08 -04004689 tests = append(tests, testCase{
4690 name: "ShimSendAlert",
4691 flags: []string{"-send-alert"},
4692 shimWritesFirst: true,
4693 shouldFail: true,
4694 expectedLocalError: "remote error: decompression failure",
4695 })
4696
David Benjamin582ba042016-07-07 12:33:25 -07004697 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004698 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004699 name: "Renegotiate-Client",
4700 config: Config{
4701 MaxVersion: VersionTLS12,
4702 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004703 renegotiate: 1,
4704 flags: []string{
4705 "-renegotiate-freely",
4706 "-expect-total-renegotiations", "1",
4707 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004709
David Benjamin47921102016-07-28 11:29:18 -04004710 tests = append(tests, testCase{
4711 name: "SendHalfHelloRequest",
4712 config: Config{
4713 MaxVersion: VersionTLS12,
4714 Bugs: ProtocolBugs{
4715 PackHelloRequestWithFinished: config.packHandshakeFlight,
4716 },
4717 },
4718 sendHalfHelloRequest: true,
4719 flags: []string{"-renegotiate-ignore"},
4720 shouldFail: true,
4721 expectedError: ":UNEXPECTED_RECORD:",
4722 })
4723
David Benjamin760b1dd2015-05-15 23:33:48 -04004724 // NPN on client and server; results in post-handshake message.
4725 tests = append(tests, testCase{
4726 name: "NPN-Client",
4727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004728 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004729 NextProtos: []string{"foo"},
4730 },
4731 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004732 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004733 expectedNextProto: "foo",
4734 expectedNextProtoType: npn,
4735 })
4736 tests = append(tests, testCase{
4737 testType: serverTest,
4738 name: "NPN-Server",
4739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004740 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004741 NextProtos: []string{"bar"},
4742 },
4743 flags: []string{
4744 "-advertise-npn", "\x03foo\x03bar\x03baz",
4745 "-expect-next-proto", "bar",
4746 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004747 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004748 expectedNextProto: "bar",
4749 expectedNextProtoType: npn,
4750 })
4751
4752 // TODO(davidben): Add tests for when False Start doesn't trigger.
4753
4754 // Client does False Start and negotiates NPN.
4755 tests = append(tests, testCase{
4756 name: "FalseStart",
4757 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004758 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004759 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4760 NextProtos: []string{"foo"},
4761 Bugs: ProtocolBugs{
4762 ExpectFalseStart: true,
4763 },
4764 },
4765 flags: []string{
4766 "-false-start",
4767 "-select-next-proto", "foo",
4768 },
4769 shimWritesFirst: true,
4770 resumeSession: true,
4771 })
4772
4773 // Client does False Start and negotiates ALPN.
4774 tests = append(tests, testCase{
4775 name: "FalseStart-ALPN",
4776 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004777 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4779 NextProtos: []string{"foo"},
4780 Bugs: ProtocolBugs{
4781 ExpectFalseStart: true,
4782 },
4783 },
4784 flags: []string{
4785 "-false-start",
4786 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004787 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004788 },
4789 shimWritesFirst: true,
4790 resumeSession: true,
4791 })
4792
David Benjamin760b1dd2015-05-15 23:33:48 -04004793 // False Start without session tickets.
4794 tests = append(tests, testCase{
4795 name: "FalseStart-SessionTicketsDisabled",
4796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004797 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4799 NextProtos: []string{"foo"},
4800 SessionTicketsDisabled: true,
4801 Bugs: ProtocolBugs{
4802 ExpectFalseStart: true,
4803 },
4804 },
4805 flags: []string{
4806 "-false-start",
4807 "-select-next-proto", "foo",
4808 },
4809 shimWritesFirst: true,
4810 })
4811
4812 // Server parses a V2ClientHello.
4813 tests = append(tests, testCase{
4814 testType: serverTest,
4815 name: "SendV2ClientHello",
4816 config: Config{
4817 // Choose a cipher suite that does not involve
4818 // elliptic curves, so no extensions are
4819 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004820 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004821 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004822 Bugs: ProtocolBugs{
4823 SendV2ClientHello: true,
4824 },
4825 },
David Benjamin78b8b992017-08-01 18:38:41 -04004826 flags: []string{
4827 "-expect-msg-callback",
4828 `read v2clienthello
4829write hs 2
4830write hs 11
4831write hs 14
4832read hs 16
4833read ccs
4834read hs 20
4835write ccs
4836write hs 20
4837read alert 1 0
4838`,
4839 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004840 })
4841
Nick Harper60a85cb2016-09-23 16:25:11 -07004842 // Test Channel ID
4843 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004844 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004845 continue
4846 }
4847 // Client sends a Channel ID.
4848 tests = append(tests, testCase{
4849 name: "ChannelID-Client-" + ver.name,
4850 config: Config{
4851 MaxVersion: ver.version,
4852 RequestChannelID: true,
4853 },
David Benjamina5022392017-07-10 17:40:39 -04004854 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004855 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4856 resumeSession: true,
4857 expectChannelID: true,
4858 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004859
Nick Harper60a85cb2016-09-23 16:25:11 -07004860 // Server accepts a Channel ID.
4861 tests = append(tests, testCase{
4862 testType: serverTest,
4863 name: "ChannelID-Server-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 ChannelID: channelIDKey,
4867 },
David Benjamina5022392017-07-10 17:40:39 -04004868 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004869 flags: []string{
4870 "-expect-channel-id",
4871 base64.StdEncoding.EncodeToString(channelIDBytes),
4872 },
4873 resumeSession: true,
4874 expectChannelID: true,
4875 })
4876
4877 tests = append(tests, testCase{
4878 testType: serverTest,
4879 name: "InvalidChannelIDSignature-" + ver.name,
4880 config: Config{
4881 MaxVersion: ver.version,
4882 ChannelID: channelIDKey,
4883 Bugs: ProtocolBugs{
4884 InvalidChannelIDSignature: true,
4885 },
4886 },
David Benjamina5022392017-07-10 17:40:39 -04004887 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004888 flags: []string{"-enable-channel-id"},
4889 shouldFail: true,
4890 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4891 })
David Benjamin634f4752017-07-01 11:08:41 -04004892
4893 if ver.version < VersionTLS13 {
4894 // Channel ID requires ECDHE ciphers.
4895 tests = append(tests, testCase{
4896 testType: serverTest,
4897 name: "ChannelID-NoECDHE-" + ver.name,
4898 config: Config{
4899 MaxVersion: ver.version,
4900 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4901 ChannelID: channelIDKey,
4902 },
4903 expectChannelID: false,
4904 flags: []string{"-enable-channel-id"},
4905 })
4906
4907 // Sanity-check setting expectChannelID false works.
4908 tests = append(tests, testCase{
4909 testType: serverTest,
4910 name: "ChannelID-ECDHE-" + ver.name,
4911 config: Config{
4912 MaxVersion: ver.version,
4913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4914 ChannelID: channelIDKey,
4915 },
4916 expectChannelID: false,
4917 flags: []string{"-enable-channel-id"},
4918 shouldFail: true,
4919 expectedLocalError: "channel ID unexpectedly negotiated",
4920 })
4921 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004922 }
David Benjamin30789da2015-08-29 22:56:45 -04004923
David Benjaminf8fcdf32016-06-08 15:56:13 -04004924 // Channel ID and NPN at the same time, to ensure their relative
4925 // ordering is correct.
4926 tests = append(tests, testCase{
4927 name: "ChannelID-NPN-Client",
4928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004929 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004930 RequestChannelID: true,
4931 NextProtos: []string{"foo"},
4932 },
4933 flags: []string{
4934 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4935 "-select-next-proto", "foo",
4936 },
4937 resumeSession: true,
4938 expectChannelID: true,
4939 expectedNextProto: "foo",
4940 expectedNextProtoType: npn,
4941 })
4942 tests = append(tests, testCase{
4943 testType: serverTest,
4944 name: "ChannelID-NPN-Server",
4945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004946 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004947 ChannelID: channelIDKey,
4948 NextProtos: []string{"bar"},
4949 },
4950 flags: []string{
4951 "-expect-channel-id",
4952 base64.StdEncoding.EncodeToString(channelIDBytes),
4953 "-advertise-npn", "\x03foo\x03bar\x03baz",
4954 "-expect-next-proto", "bar",
4955 },
4956 resumeSession: true,
4957 expectChannelID: true,
4958 expectedNextProto: "bar",
4959 expectedNextProtoType: npn,
4960 })
4961
David Benjamin30789da2015-08-29 22:56:45 -04004962 // Bidirectional shutdown with the runner initiating.
4963 tests = append(tests, testCase{
4964 name: "Shutdown-Runner",
4965 config: Config{
4966 Bugs: ProtocolBugs{
4967 ExpectCloseNotify: true,
4968 },
4969 },
4970 flags: []string{"-check-close-notify"},
4971 })
4972
David Benjamine3843d42017-03-25 18:00:56 -05004973 if !config.implicitHandshake {
4974 // Bidirectional shutdown with the shim initiating. The runner,
4975 // in the meantime, sends garbage before the close_notify which
4976 // the shim must ignore. This test is disabled under implicit
4977 // handshake tests because the shim never reads or writes.
4978 tests = append(tests, testCase{
4979 name: "Shutdown-Shim",
4980 config: Config{
4981 MaxVersion: VersionTLS12,
4982 Bugs: ProtocolBugs{
4983 ExpectCloseNotify: true,
4984 },
David Benjamin30789da2015-08-29 22:56:45 -04004985 },
David Benjamine3843d42017-03-25 18:00:56 -05004986 shimShutsDown: true,
4987 sendEmptyRecords: 1,
4988 sendWarningAlerts: 1,
4989 flags: []string{"-check-close-notify"},
4990 })
4991 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004992 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004993 // TODO(davidben): DTLS 1.3 will want a similar thing for
4994 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004995 tests = append(tests, testCase{
4996 name: "SkipHelloVerifyRequest",
4997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004998 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004999 Bugs: ProtocolBugs{
5000 SkipHelloVerifyRequest: true,
5001 },
5002 },
5003 })
5004 }
5005
David Benjamin760b1dd2015-05-15 23:33:48 -04005006 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07005007 test.protocol = config.protocol
5008 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005009 test.name += "-DTLS"
5010 }
David Benjamin582ba042016-07-07 12:33:25 -07005011 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05005012 test.name += "-Async"
5013 test.flags = append(test.flags, "-async")
5014 } else {
5015 test.name += "-Sync"
5016 }
David Benjamin582ba042016-07-07 12:33:25 -07005017 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005018 test.name += "-SplitHandshakeRecords"
5019 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005020 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005021 test.config.Bugs.MaxPacketLength = 256
5022 test.flags = append(test.flags, "-mtu", "256")
5023 }
5024 }
David Benjamin582ba042016-07-07 12:33:25 -07005025 if config.packHandshakeFlight {
5026 test.name += "-PackHandshakeFlight"
5027 test.config.Bugs.PackHandshakeFlight = true
5028 }
David Benjamine3843d42017-03-25 18:00:56 -05005029 if config.implicitHandshake {
5030 test.name += "-ImplicitHandshake"
5031 test.flags = append(test.flags, "-implicit-handshake")
5032 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005033 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005034 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005035}
5036
Adam Langley524e7172015-02-20 16:04:00 -08005037func addDDoSCallbackTests() {
5038 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005039 for _, resume := range []bool{false, true} {
5040 suffix := "Resume"
5041 if resume {
5042 suffix = "No" + suffix
5043 }
5044
5045 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005046 testType: serverTest,
5047 name: "Server-DDoS-OK-" + suffix,
5048 config: Config{
5049 MaxVersion: VersionTLS12,
5050 },
Adam Langley524e7172015-02-20 16:04:00 -08005051 flags: []string{"-install-ddos-callback"},
5052 resumeSession: resume,
5053 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005054 testCases = append(testCases, testCase{
5055 testType: serverTest,
5056 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5057 config: Config{
5058 MaxVersion: VersionTLS13,
5059 },
5060 flags: []string{"-install-ddos-callback"},
5061 resumeSession: resume,
5062 })
Adam Langley524e7172015-02-20 16:04:00 -08005063
5064 failFlag := "-fail-ddos-callback"
5065 if resume {
5066 failFlag = "-fail-second-ddos-callback"
5067 }
5068 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005069 testType: serverTest,
5070 name: "Server-DDoS-Reject-" + suffix,
5071 config: Config{
5072 MaxVersion: VersionTLS12,
5073 },
David Benjamin2c66e072016-09-16 15:58:00 -04005074 flags: []string{"-install-ddos-callback", failFlag},
5075 resumeSession: resume,
5076 shouldFail: true,
5077 expectedError: ":CONNECTION_REJECTED:",
5078 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005079 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5083 config: Config{
5084 MaxVersion: VersionTLS13,
5085 },
David Benjamin2c66e072016-09-16 15:58:00 -04005086 flags: []string{"-install-ddos-callback", failFlag},
5087 resumeSession: resume,
5088 shouldFail: true,
5089 expectedError: ":CONNECTION_REJECTED:",
5090 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005091 })
Adam Langley524e7172015-02-20 16:04:00 -08005092 }
5093}
5094
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005095func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005096 for _, protocol := range []protocol{tls, dtls} {
5097 for _, shimVers := range allVersions(protocol) {
5098 // Assemble flags to disable all newer versions on the shim.
5099 var flags []string
5100 for _, vers := range allVersions(protocol) {
5101 if vers.version > shimVers.version {
5102 flags = append(flags, vers.excludeFlag)
5103 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005104 }
Steven Valdez520e1222017-06-13 12:45:25 -04005105
5106 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5107
5108 if shimVers.tls13Variant != 0 {
5109 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5110 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5111 }
5112
5113 // Test configuring the runner's maximum version.
5114 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005115 expectedVersion := shimVers.version
5116 if runnerVers.version < shimVers.version {
5117 expectedVersion = runnerVers.version
5118 }
Steven Valdez520e1222017-06-13 12:45:25 -04005119 // When running and shim have different TLS 1.3 variants enabled,
5120 // shim clients are expected to fall back to TLS 1.2, while shim
5121 // servers support both variants when enabled when the experiment is
5122 // enabled.
5123 expectedServerVersion := expectedVersion
5124 expectedClientVersion := expectedVersion
5125 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5126 expectedClientVersion = VersionTLS12
5127 expectedServerVersion = VersionTLS12
5128 if shimVers.tls13Variant != TLS13Default {
5129 expectedServerVersion = VersionTLS13
5130 }
5131 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005132
David Benjamin8b8c0062014-11-23 02:47:52 -05005133 suffix := shimVers.name + "-" + runnerVers.name
5134 if protocol == dtls {
5135 suffix += "-DTLS"
5136 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005137
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005138 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005139 clientVers := shimVers.version
5140 if clientVers > VersionTLS10 {
5141 clientVers = VersionTLS10
5142 }
Steven Valdez520e1222017-06-13 12:45:25 -04005143 clientVers = recordVersionToWire(clientVers, protocol)
5144 serverVers := expectedServerVersion
5145 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005146 serverVers = VersionTLS10
5147 }
Steven Valdez520e1222017-06-13 12:45:25 -04005148 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005149
David Benjamin8b8c0062014-11-23 02:47:52 -05005150 testCases = append(testCases, testCase{
5151 protocol: protocol,
5152 testType: clientTest,
5153 name: "VersionNegotiation-Client-" + suffix,
5154 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005155 MaxVersion: runnerVers.version,
5156 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005157 Bugs: ProtocolBugs{
5158 ExpectInitialRecordVersion: clientVers,
5159 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005160 },
5161 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005162 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005163 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005164 testCases = append(testCases, testCase{
5165 protocol: protocol,
5166 testType: clientTest,
5167 name: "VersionNegotiation-Client2-" + suffix,
5168 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005169 MaxVersion: runnerVers.version,
5170 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005171 Bugs: ProtocolBugs{
5172 ExpectInitialRecordVersion: clientVers,
5173 },
5174 },
Steven Valdez520e1222017-06-13 12:45:25 -04005175 flags: flags2,
5176 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005177 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005178
5179 testCases = append(testCases, testCase{
5180 protocol: protocol,
5181 testType: serverTest,
5182 name: "VersionNegotiation-Server-" + suffix,
5183 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005184 MaxVersion: runnerVers.version,
5185 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005186 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005187 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005188 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005189 },
5190 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005191 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005192 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005193 testCases = append(testCases, testCase{
5194 protocol: protocol,
5195 testType: serverTest,
5196 name: "VersionNegotiation-Server2-" + suffix,
5197 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005198 MaxVersion: runnerVers.version,
5199 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005200 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005201 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005202 },
5203 },
Steven Valdez520e1222017-06-13 12:45:25 -04005204 flags: flags2,
5205 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005206 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005207 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005208 }
5209 }
David Benjamin95c69562016-06-29 18:15:03 -04005210
Steven Valdezfdd10992016-09-15 16:27:05 -04005211 // Test the version extension at all versions.
5212 for _, vers := range tlsVersions {
5213 protocols := []protocol{tls}
5214 if vers.hasDTLS {
5215 protocols = append(protocols, dtls)
5216 }
5217 for _, protocol := range protocols {
5218 suffix := vers.name
5219 if protocol == dtls {
5220 suffix += "-DTLS"
5221 }
5222
Steven Valdezfdd10992016-09-15 16:27:05 -04005223 testCases = append(testCases, testCase{
5224 protocol: protocol,
5225 testType: serverTest,
5226 name: "VersionNegotiationExtension-" + suffix,
5227 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005228 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005230 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005231 },
5232 },
5233 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005234 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005235 })
5236 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005237 }
5238
5239 // If all versions are unknown, negotiation fails.
5240 testCases = append(testCases, testCase{
5241 testType: serverTest,
5242 name: "NoSupportedVersions",
5243 config: Config{
5244 Bugs: ProtocolBugs{
5245 SendSupportedVersions: []uint16{0x1111},
5246 },
5247 },
5248 shouldFail: true,
5249 expectedError: ":UNSUPPORTED_PROTOCOL:",
5250 })
5251 testCases = append(testCases, testCase{
5252 protocol: dtls,
5253 testType: serverTest,
5254 name: "NoSupportedVersions-DTLS",
5255 config: Config{
5256 Bugs: ProtocolBugs{
5257 SendSupportedVersions: []uint16{0x1111},
5258 },
5259 },
5260 shouldFail: true,
5261 expectedError: ":UNSUPPORTED_PROTOCOL:",
5262 })
5263
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "ClientHelloVersionTooHigh",
5267 config: Config{
5268 MaxVersion: VersionTLS13,
5269 Bugs: ProtocolBugs{
5270 SendClientVersion: 0x0304,
5271 OmitSupportedVersions: true,
5272 },
5273 },
5274 expectedVersion: VersionTLS12,
5275 })
5276
5277 testCases = append(testCases, testCase{
5278 testType: serverTest,
5279 name: "ConflictingVersionNegotiation",
5280 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005281 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005282 SendClientVersion: VersionTLS12,
5283 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005284 },
5285 },
David Benjaminad75a662016-09-30 15:42:59 -04005286 // The extension takes precedence over the ClientHello version.
5287 expectedVersion: VersionTLS11,
5288 })
5289
5290 testCases = append(testCases, testCase{
5291 testType: serverTest,
5292 name: "ConflictingVersionNegotiation-2",
5293 config: Config{
5294 Bugs: ProtocolBugs{
5295 SendClientVersion: VersionTLS11,
5296 SendSupportedVersions: []uint16{VersionTLS12},
5297 },
5298 },
5299 // The extension takes precedence over the ClientHello version.
5300 expectedVersion: VersionTLS12,
5301 })
5302
5303 testCases = append(testCases, testCase{
5304 testType: serverTest,
5305 name: "RejectFinalTLS13",
5306 config: Config{
5307 Bugs: ProtocolBugs{
5308 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5309 },
5310 },
5311 // We currently implement a draft TLS 1.3 version. Ensure that
5312 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005313 expectedVersion: VersionTLS12,
5314 })
5315
Steven Valdez038da9b2017-07-10 12:57:25 -04005316 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5317 // the ServerHello.
5318 testCases = append(testCases, testCase{
5319 testType: clientTest,
5320 name: "SupportedVersionSelection-TLS12",
5321 config: Config{
5322 MaxVersion: VersionTLS12,
5323 Bugs: ProtocolBugs{
5324 SendServerSupportedExtensionVersion: VersionTLS12,
5325 },
5326 },
5327 shouldFail: true,
5328 expectedError: ":UNEXPECTED_EXTENSION:",
5329 })
5330
5331 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5332 // supported_versions extension in the ServerHello.
5333 testCases = append(testCases, testCase{
5334 testType: clientTest,
5335 name: "SupportedVersionSelection-TLS13",
5336 config: Config{
5337 MaxVersion: VersionTLS13,
5338 Bugs: ProtocolBugs{
5339 SendServerSupportedExtensionVersion: tls13DraftVersion,
5340 },
5341 },
5342 shouldFail: true,
5343 expectedError: ":UNEXPECTED_EXTENSION:",
5344 })
5345
Brian Smithf85d3232016-10-28 10:34:06 -10005346 // Test that the maximum version is selected regardless of the
5347 // client-sent order.
5348 testCases = append(testCases, testCase{
5349 testType: serverTest,
5350 name: "IgnoreClientVersionOrder",
5351 config: Config{
5352 Bugs: ProtocolBugs{
5353 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5354 },
5355 },
5356 expectedVersion: VersionTLS13,
5357 })
5358
David Benjamin95c69562016-06-29 18:15:03 -04005359 // Test for version tolerance.
5360 testCases = append(testCases, testCase{
5361 testType: serverTest,
5362 name: "MinorVersionTolerance",
5363 config: Config{
5364 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005365 SendClientVersion: 0x03ff,
5366 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005367 },
5368 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005369 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005370 })
5371 testCases = append(testCases, testCase{
5372 testType: serverTest,
5373 name: "MajorVersionTolerance",
5374 config: Config{
5375 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005376 SendClientVersion: 0x0400,
5377 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005378 },
5379 },
David Benjaminad75a662016-09-30 15:42:59 -04005380 // TLS 1.3 must be negotiated with the supported_versions
5381 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005382 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005383 })
David Benjaminad75a662016-09-30 15:42:59 -04005384 testCases = append(testCases, testCase{
5385 testType: serverTest,
5386 name: "VersionTolerance-TLS13",
5387 config: Config{
5388 Bugs: ProtocolBugs{
5389 // Although TLS 1.3 does not use
5390 // ClientHello.version, it still tolerates high
5391 // values there.
5392 SendClientVersion: 0x0400,
5393 },
5394 },
5395 expectedVersion: VersionTLS13,
5396 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005397
David Benjamin95c69562016-06-29 18:15:03 -04005398 testCases = append(testCases, testCase{
5399 protocol: dtls,
5400 testType: serverTest,
5401 name: "MinorVersionTolerance-DTLS",
5402 config: Config{
5403 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005404 SendClientVersion: 0xfe00,
5405 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005406 },
5407 },
5408 expectedVersion: VersionTLS12,
5409 })
5410 testCases = append(testCases, testCase{
5411 protocol: dtls,
5412 testType: serverTest,
5413 name: "MajorVersionTolerance-DTLS",
5414 config: Config{
5415 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005416 SendClientVersion: 0xfdff,
5417 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005418 },
5419 },
5420 expectedVersion: VersionTLS12,
5421 })
5422
5423 // Test that versions below 3.0 are rejected.
5424 testCases = append(testCases, testCase{
5425 testType: serverTest,
5426 name: "VersionTooLow",
5427 config: Config{
5428 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005429 SendClientVersion: 0x0200,
5430 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":UNSUPPORTED_PROTOCOL:",
5435 })
5436 testCases = append(testCases, testCase{
5437 protocol: dtls,
5438 testType: serverTest,
5439 name: "VersionTooLow-DTLS",
5440 config: Config{
5441 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005442 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":UNSUPPORTED_PROTOCOL:",
5447 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005448
David Benjamin2dc02042016-09-19 19:57:37 -04005449 testCases = append(testCases, testCase{
5450 name: "ServerBogusVersion",
5451 config: Config{
5452 Bugs: ProtocolBugs{
5453 SendServerHelloVersion: 0x1234,
5454 },
5455 },
5456 shouldFail: true,
5457 expectedError: ":UNSUPPORTED_PROTOCOL:",
5458 })
5459
David Benjamin1f61f0d2016-07-10 12:20:35 -04005460 // Test TLS 1.3's downgrade signal.
5461 testCases = append(testCases, testCase{
5462 name: "Downgrade-TLS12-Client",
5463 config: Config{
5464 Bugs: ProtocolBugs{
5465 NegotiateVersion: VersionTLS12,
5466 },
5467 },
David Benjamin592b5322016-09-30 15:15:01 -04005468 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005469 // TODO(davidben): This test should fail once TLS 1.3 is final
5470 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005471 })
5472 testCases = append(testCases, testCase{
5473 testType: serverTest,
5474 name: "Downgrade-TLS12-Server",
5475 config: Config{
5476 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005477 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005478 },
5479 },
David Benjamin592b5322016-09-30 15:15:01 -04005480 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005481 // TODO(davidben): This test should fail once TLS 1.3 is final
5482 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005483 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005484}
5485
David Benjaminaccb4542014-12-12 23:44:33 -05005486func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005487 for _, protocol := range []protocol{tls, dtls} {
5488 for _, shimVers := range allVersions(protocol) {
5489 // Assemble flags to disable all older versions on the shim.
5490 var flags []string
5491 for _, vers := range allVersions(protocol) {
5492 if vers.version < shimVers.version {
5493 flags = append(flags, vers.excludeFlag)
5494 }
David Benjaminaccb4542014-12-12 23:44:33 -05005495 }
Steven Valdez520e1222017-06-13 12:45:25 -04005496
5497 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5498
5499 if shimVers.tls13Variant != 0 {
5500 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5501 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5502 }
5503
5504 for _, runnerVers := range allVersions(protocol) {
5505 // Different TLS 1.3 variants are incompatible with each other and don't
5506 // produce consistent minimum versions.
5507 //
5508 // TODO(davidben): Fold these tests (the main value is in the
5509 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5510 // on intended shim behavior, not the shim + runner combination.
5511 if shimVers.tls13Variant != runnerVers.tls13Variant {
5512 continue
5513 }
5514
David Benjaminaccb4542014-12-12 23:44:33 -05005515 suffix := shimVers.name + "-" + runnerVers.name
5516 if protocol == dtls {
5517 suffix += "-DTLS"
5518 }
David Benjaminaccb4542014-12-12 23:44:33 -05005519
David Benjaminaccb4542014-12-12 23:44:33 -05005520 var expectedVersion uint16
5521 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005522 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005523 if runnerVers.version >= shimVers.version {
5524 expectedVersion = runnerVers.version
5525 } else {
5526 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005527 expectedError = ":UNSUPPORTED_PROTOCOL:"
5528 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005529 }
5530
5531 testCases = append(testCases, testCase{
5532 protocol: protocol,
5533 testType: clientTest,
5534 name: "MinimumVersion-Client-" + suffix,
5535 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005536 MaxVersion: runnerVers.version,
5537 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005538 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005539 // Ensure the server does not decline to
5540 // select a version (versions extension) or
5541 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005542 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005543 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005544 },
David Benjaminaccb4542014-12-12 23:44:33 -05005545 },
David Benjamin87909c02014-12-13 01:55:01 -05005546 flags: flags,
5547 expectedVersion: expectedVersion,
5548 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005549 expectedError: expectedError,
5550 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005551 })
5552 testCases = append(testCases, testCase{
5553 protocol: protocol,
5554 testType: clientTest,
5555 name: "MinimumVersion-Client2-" + suffix,
5556 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005557 MaxVersion: runnerVers.version,
5558 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005559 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005560 // Ensure the server does not decline to
5561 // select a version (versions extension) or
5562 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005563 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005564 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005565 },
David Benjaminaccb4542014-12-12 23:44:33 -05005566 },
Steven Valdez520e1222017-06-13 12:45:25 -04005567 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005568 expectedVersion: expectedVersion,
5569 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005570 expectedError: expectedError,
5571 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005572 })
5573
5574 testCases = append(testCases, testCase{
5575 protocol: protocol,
5576 testType: serverTest,
5577 name: "MinimumVersion-Server-" + suffix,
5578 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005579 MaxVersion: runnerVers.version,
5580 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005581 },
David Benjamin87909c02014-12-13 01:55:01 -05005582 flags: flags,
5583 expectedVersion: expectedVersion,
5584 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005585 expectedError: expectedError,
5586 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005587 })
5588 testCases = append(testCases, testCase{
5589 protocol: protocol,
5590 testType: serverTest,
5591 name: "MinimumVersion-Server2-" + suffix,
5592 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005593 MaxVersion: runnerVers.version,
5594 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005595 },
Steven Valdez520e1222017-06-13 12:45:25 -04005596 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005597 expectedVersion: expectedVersion,
5598 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005599 expectedError: expectedError,
5600 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005601 })
5602 }
5603 }
5604 }
5605}
5606
David Benjamine78bfde2014-09-06 12:45:15 -04005607func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005608 // TODO(davidben): Extensions, where applicable, all move their server
5609 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5610 // tests for both. Also test interaction with 0-RTT when implemented.
5611
David Benjamin97d17d92016-07-14 16:12:00 -04005612 // Repeat extensions tests all versions except SSL 3.0.
5613 for _, ver := range tlsVersions {
5614 if ver.version == VersionSSL30 {
5615 continue
5616 }
5617
David Benjamin97d17d92016-07-14 16:12:00 -04005618 // Test that duplicate extensions are rejected.
5619 testCases = append(testCases, testCase{
5620 testType: clientTest,
5621 name: "DuplicateExtensionClient-" + ver.name,
5622 config: Config{
5623 MaxVersion: ver.version,
5624 Bugs: ProtocolBugs{
5625 DuplicateExtension: true,
5626 },
David Benjamine78bfde2014-09-06 12:45:15 -04005627 },
David Benjamina5022392017-07-10 17:40:39 -04005628 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005629 shouldFail: true,
5630 expectedLocalError: "remote error: error decoding message",
5631 })
5632 testCases = append(testCases, testCase{
5633 testType: serverTest,
5634 name: "DuplicateExtensionServer-" + ver.name,
5635 config: Config{
5636 MaxVersion: ver.version,
5637 Bugs: ProtocolBugs{
5638 DuplicateExtension: true,
5639 },
David Benjamine78bfde2014-09-06 12:45:15 -04005640 },
David Benjamina5022392017-07-10 17:40:39 -04005641 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005642 shouldFail: true,
5643 expectedLocalError: "remote error: error decoding message",
5644 })
5645
5646 // Test SNI.
5647 testCases = append(testCases, testCase{
5648 testType: clientTest,
5649 name: "ServerNameExtensionClient-" + ver.name,
5650 config: Config{
5651 MaxVersion: ver.version,
5652 Bugs: ProtocolBugs{
5653 ExpectServerName: "example.com",
5654 },
David Benjamine78bfde2014-09-06 12:45:15 -04005655 },
David Benjamina5022392017-07-10 17:40:39 -04005656 tls13Variant: ver.tls13Variant,
5657 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005658 })
5659 testCases = append(testCases, testCase{
5660 testType: clientTest,
5661 name: "ServerNameExtensionClientMismatch-" + ver.name,
5662 config: Config{
5663 MaxVersion: ver.version,
5664 Bugs: ProtocolBugs{
5665 ExpectServerName: "mismatch.com",
5666 },
David Benjamine78bfde2014-09-06 12:45:15 -04005667 },
David Benjamin97d17d92016-07-14 16:12:00 -04005668 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005669 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005670 shouldFail: true,
5671 expectedLocalError: "tls: unexpected server name",
5672 })
5673 testCases = append(testCases, testCase{
5674 testType: clientTest,
5675 name: "ServerNameExtensionClientMissing-" + ver.name,
5676 config: Config{
5677 MaxVersion: ver.version,
5678 Bugs: ProtocolBugs{
5679 ExpectServerName: "missing.com",
5680 },
David Benjamine78bfde2014-09-06 12:45:15 -04005681 },
David Benjamina5022392017-07-10 17:40:39 -04005682 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005683 shouldFail: true,
5684 expectedLocalError: "tls: unexpected server name",
5685 })
5686 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005687 testType: clientTest,
5688 name: "TolerateServerNameAck-" + ver.name,
5689 config: Config{
5690 MaxVersion: ver.version,
5691 Bugs: ProtocolBugs{
5692 SendServerNameAck: true,
5693 },
5694 },
David Benjamina5022392017-07-10 17:40:39 -04005695 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005696 flags: []string{"-host-name", "example.com"},
5697 resumeSession: true,
5698 })
5699 testCases = append(testCases, testCase{
5700 testType: clientTest,
5701 name: "UnsolicitedServerNameAck-" + ver.name,
5702 config: Config{
5703 MaxVersion: ver.version,
5704 Bugs: ProtocolBugs{
5705 SendServerNameAck: true,
5706 },
5707 },
David Benjamina5022392017-07-10 17:40:39 -04005708 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005709 shouldFail: true,
5710 expectedError: ":UNEXPECTED_EXTENSION:",
5711 expectedLocalError: "remote error: unsupported extension",
5712 })
5713 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005714 testType: serverTest,
5715 name: "ServerNameExtensionServer-" + ver.name,
5716 config: Config{
5717 MaxVersion: ver.version,
5718 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005719 },
David Benjamina5022392017-07-10 17:40:39 -04005720 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005721 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005722 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005723 })
5724
5725 // Test ALPN.
5726 testCases = append(testCases, testCase{
5727 testType: clientTest,
5728 name: "ALPNClient-" + ver.name,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 NextProtos: []string{"foo"},
5732 },
5733 flags: []string{
5734 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5735 "-expect-alpn", "foo",
5736 },
David Benjamina5022392017-07-10 17:40:39 -04005737 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005738 expectedNextProto: "foo",
5739 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005740 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005741 })
5742 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005743 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005744 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005745 config: Config{
5746 MaxVersion: ver.version,
5747 Bugs: ProtocolBugs{
5748 SendALPN: "baz",
5749 },
5750 },
5751 flags: []string{
5752 "-advertise-alpn", "\x03foo\x03bar",
5753 },
David Benjamina5022392017-07-10 17:40:39 -04005754 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005755 shouldFail: true,
5756 expectedError: ":INVALID_ALPN_PROTOCOL:",
5757 expectedLocalError: "remote error: illegal parameter",
5758 })
5759 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005760 testType: clientTest,
5761 name: "ALPNClient-AllowUnknown-" + ver.name,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 Bugs: ProtocolBugs{
5765 SendALPN: "baz",
5766 },
5767 },
5768 flags: []string{
5769 "-advertise-alpn", "\x03foo\x03bar",
5770 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005771 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005772 },
David Benjamina5022392017-07-10 17:40:39 -04005773 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005774 })
5775 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005776 testType: serverTest,
5777 name: "ALPNServer-" + ver.name,
5778 config: Config{
5779 MaxVersion: ver.version,
5780 NextProtos: []string{"foo", "bar", "baz"},
5781 },
5782 flags: []string{
5783 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5784 "-select-alpn", "foo",
5785 },
David Benjamina5022392017-07-10 17:40:39 -04005786 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005787 expectedNextProto: "foo",
5788 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005789 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005790 })
5791 testCases = append(testCases, testCase{
5792 testType: serverTest,
5793 name: "ALPNServer-Decline-" + ver.name,
5794 config: Config{
5795 MaxVersion: ver.version,
5796 NextProtos: []string{"foo", "bar", "baz"},
5797 },
5798 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005799 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005800 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005801 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005802 })
5803
David Benjamin25fe85b2016-08-09 20:00:32 -04005804 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5805 // called once.
5806 testCases = append(testCases, testCase{
5807 testType: serverTest,
5808 name: "ALPNServer-Async-" + ver.name,
5809 config: Config{
5810 MaxVersion: ver.version,
5811 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005812 // Prior to TLS 1.3, exercise the asynchronous session callback.
5813 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005814 },
5815 flags: []string{
5816 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5817 "-select-alpn", "foo",
5818 "-async",
5819 },
David Benjamina5022392017-07-10 17:40:39 -04005820 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005821 expectedNextProto: "foo",
5822 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005823 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005824 })
5825
David Benjamin97d17d92016-07-14 16:12:00 -04005826 var emptyString string
5827 testCases = append(testCases, testCase{
5828 testType: clientTest,
5829 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5830 config: Config{
5831 MaxVersion: ver.version,
5832 NextProtos: []string{""},
5833 Bugs: ProtocolBugs{
5834 // A server returning an empty ALPN protocol
5835 // should be rejected.
5836 ALPNProtocol: &emptyString,
5837 },
5838 },
5839 flags: []string{
5840 "-advertise-alpn", "\x03foo",
5841 },
David Benjamina5022392017-07-10 17:40:39 -04005842 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005843 shouldFail: true,
5844 expectedError: ":PARSE_TLSEXT:",
5845 })
5846 testCases = append(testCases, testCase{
5847 testType: serverTest,
5848 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5849 config: Config{
5850 MaxVersion: ver.version,
5851 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005852 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005853 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005854 },
David Benjamin97d17d92016-07-14 16:12:00 -04005855 flags: []string{
5856 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005857 },
David Benjamina5022392017-07-10 17:40:39 -04005858 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005859 shouldFail: true,
5860 expectedError: ":PARSE_TLSEXT:",
5861 })
5862
5863 // Test NPN and the interaction with ALPN.
5864 if ver.version < VersionTLS13 {
5865 // Test that the server prefers ALPN over NPN.
5866 testCases = append(testCases, testCase{
5867 testType: serverTest,
5868 name: "ALPNServer-Preferred-" + ver.name,
5869 config: Config{
5870 MaxVersion: ver.version,
5871 NextProtos: []string{"foo", "bar", "baz"},
5872 },
5873 flags: []string{
5874 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5875 "-select-alpn", "foo",
5876 "-advertise-npn", "\x03foo\x03bar\x03baz",
5877 },
David Benjamina5022392017-07-10 17:40:39 -04005878 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005879 expectedNextProto: "foo",
5880 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005881 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005882 })
5883 testCases = append(testCases, testCase{
5884 testType: serverTest,
5885 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5886 config: Config{
5887 MaxVersion: ver.version,
5888 NextProtos: []string{"foo", "bar", "baz"},
5889 Bugs: ProtocolBugs{
5890 SwapNPNAndALPN: true,
5891 },
5892 },
5893 flags: []string{
5894 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5895 "-select-alpn", "foo",
5896 "-advertise-npn", "\x03foo\x03bar\x03baz",
5897 },
David Benjamina5022392017-07-10 17:40:39 -04005898 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005899 expectedNextProto: "foo",
5900 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005901 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005902 })
5903
5904 // Test that negotiating both NPN and ALPN is forbidden.
5905 testCases = append(testCases, testCase{
5906 name: "NegotiateALPNAndNPN-" + ver.name,
5907 config: Config{
5908 MaxVersion: ver.version,
5909 NextProtos: []string{"foo", "bar", "baz"},
5910 Bugs: ProtocolBugs{
5911 NegotiateALPNAndNPN: true,
5912 },
5913 },
5914 flags: []string{
5915 "-advertise-alpn", "\x03foo",
5916 "-select-next-proto", "foo",
5917 },
David Benjamina5022392017-07-10 17:40:39 -04005918 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005919 shouldFail: true,
5920 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5921 })
5922 testCases = append(testCases, testCase{
5923 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5924 config: Config{
5925 MaxVersion: ver.version,
5926 NextProtos: []string{"foo", "bar", "baz"},
5927 Bugs: ProtocolBugs{
5928 NegotiateALPNAndNPN: true,
5929 SwapNPNAndALPN: true,
5930 },
5931 },
5932 flags: []string{
5933 "-advertise-alpn", "\x03foo",
5934 "-select-next-proto", "foo",
5935 },
David Benjamina5022392017-07-10 17:40:39 -04005936 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005937 shouldFail: true,
5938 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5939 })
David Benjamin97d17d92016-07-14 16:12:00 -04005940 }
5941
5942 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005943
5944 // Resume with a corrupt ticket.
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
5947 name: "CorruptTicket-" + ver.name,
5948 config: Config{
5949 MaxVersion: ver.version,
5950 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005951 FilterTicket: func(in []byte) ([]byte, error) {
5952 in[len(in)-1] ^= 1
5953 return in, nil
5954 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005955 },
5956 },
David Benjamina5022392017-07-10 17:40:39 -04005957 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005958 resumeSession: true,
5959 expectResumeRejected: true,
5960 })
5961 // Test the ticket callback, with and without renewal.
5962 testCases = append(testCases, testCase{
5963 testType: serverTest,
5964 name: "TicketCallback-" + ver.name,
5965 config: Config{
5966 MaxVersion: ver.version,
5967 },
David Benjamina5022392017-07-10 17:40:39 -04005968 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005969 resumeSession: true,
5970 flags: []string{"-use-ticket-callback"},
5971 })
5972 testCases = append(testCases, testCase{
5973 testType: serverTest,
5974 name: "TicketCallback-Renew-" + ver.name,
5975 config: Config{
5976 MaxVersion: ver.version,
5977 Bugs: ProtocolBugs{
5978 ExpectNewTicket: true,
5979 },
5980 },
David Benjamina5022392017-07-10 17:40:39 -04005981 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005982 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5983 resumeSession: true,
5984 })
5985
5986 // Test that the ticket callback is only called once when everything before
5987 // it in the ClientHello is asynchronous. This corrupts the ticket so
5988 // certificate selection callbacks run.
5989 testCases = append(testCases, testCase{
5990 testType: serverTest,
5991 name: "TicketCallback-SingleCall-" + ver.name,
5992 config: Config{
5993 MaxVersion: ver.version,
5994 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005995 FilterTicket: func(in []byte) ([]byte, error) {
5996 in[len(in)-1] ^= 1
5997 return in, nil
5998 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005999 },
6000 },
David Benjamina5022392017-07-10 17:40:39 -04006001 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006002 resumeSession: true,
6003 expectResumeRejected: true,
6004 flags: []string{
6005 "-use-ticket-callback",
6006 "-async",
6007 },
6008 })
6009
David Benjamind4c349b2017-02-09 14:07:17 -05006010 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04006011 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04006012 testCases = append(testCases, testCase{
6013 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05006014 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04006015 config: Config{
6016 MaxVersion: ver.version,
6017 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006018 EmptyTicketSessionID: true,
6019 },
6020 },
6021 resumeSession: true,
6022 })
6023 testCases = append(testCases, testCase{
6024 testType: serverTest,
6025 name: "TicketSessionIDLength-16-" + ver.name,
6026 config: Config{
6027 MaxVersion: ver.version,
6028 Bugs: ProtocolBugs{
6029 TicketSessionIDLength: 16,
6030 },
6031 },
6032 resumeSession: true,
6033 })
6034 testCases = append(testCases, testCase{
6035 testType: serverTest,
6036 name: "TicketSessionIDLength-32-" + ver.name,
6037 config: Config{
6038 MaxVersion: ver.version,
6039 Bugs: ProtocolBugs{
6040 TicketSessionIDLength: 32,
6041 },
6042 },
6043 resumeSession: true,
6044 })
6045 testCases = append(testCases, testCase{
6046 testType: serverTest,
6047 name: "TicketSessionIDLength-33-" + ver.name,
6048 config: Config{
6049 MaxVersion: ver.version,
6050 Bugs: ProtocolBugs{
6051 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006052 },
6053 },
6054 resumeSession: true,
6055 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006056 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006057 expectedError: ":DECODE_ERROR:",
6058 })
6059 }
6060
6061 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6062 // are ignored.
6063 if ver.hasDTLS {
6064 testCases = append(testCases, testCase{
6065 protocol: dtls,
6066 name: "SRTP-Client-" + ver.name,
6067 config: Config{
6068 MaxVersion: ver.version,
6069 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6070 },
6071 flags: []string{
6072 "-srtp-profiles",
6073 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6074 },
6075 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6076 })
6077 testCases = append(testCases, testCase{
6078 protocol: dtls,
6079 testType: serverTest,
6080 name: "SRTP-Server-" + ver.name,
6081 config: Config{
6082 MaxVersion: ver.version,
6083 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6084 },
6085 flags: []string{
6086 "-srtp-profiles",
6087 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6088 },
6089 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6090 })
6091 // Test that the MKI is ignored.
6092 testCases = append(testCases, testCase{
6093 protocol: dtls,
6094 testType: serverTest,
6095 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6096 config: Config{
6097 MaxVersion: ver.version,
6098 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6099 Bugs: ProtocolBugs{
6100 SRTPMasterKeyIdentifer: "bogus",
6101 },
6102 },
6103 flags: []string{
6104 "-srtp-profiles",
6105 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6106 },
6107 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6108 })
6109 // Test that SRTP isn't negotiated on the server if there were
6110 // no matching profiles.
6111 testCases = append(testCases, testCase{
6112 protocol: dtls,
6113 testType: serverTest,
6114 name: "SRTP-Server-NoMatch-" + ver.name,
6115 config: Config{
6116 MaxVersion: ver.version,
6117 SRTPProtectionProfiles: []uint16{100, 101, 102},
6118 },
6119 flags: []string{
6120 "-srtp-profiles",
6121 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6122 },
6123 expectedSRTPProtectionProfile: 0,
6124 })
6125 // Test that the server returning an invalid SRTP profile is
6126 // flagged as an error by the client.
6127 testCases = append(testCases, testCase{
6128 protocol: dtls,
6129 name: "SRTP-Client-NoMatch-" + ver.name,
6130 config: Config{
6131 MaxVersion: ver.version,
6132 Bugs: ProtocolBugs{
6133 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6134 },
6135 },
6136 flags: []string{
6137 "-srtp-profiles",
6138 "SRTP_AES128_CM_SHA1_80",
6139 },
6140 shouldFail: true,
6141 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6142 })
6143 }
6144
6145 // Test SCT list.
6146 testCases = append(testCases, testCase{
6147 name: "SignedCertificateTimestampList-Client-" + ver.name,
6148 testType: clientTest,
6149 config: Config{
6150 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006151 },
David Benjamin97d17d92016-07-14 16:12:00 -04006152 flags: []string{
6153 "-enable-signed-cert-timestamps",
6154 "-expect-signed-cert-timestamps",
6155 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006156 },
David Benjamina5022392017-07-10 17:40:39 -04006157 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006158 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006159 })
David Benjamindaa88502016-10-04 16:32:16 -04006160
Adam Langleycfa08c32016-11-17 13:21:27 -08006161 var differentSCTList []byte
6162 differentSCTList = append(differentSCTList, testSCTList...)
6163 differentSCTList[len(differentSCTList)-1] ^= 1
6164
David Benjamindaa88502016-10-04 16:32:16 -04006165 // The SCT extension did not specify that it must only be sent on resumption as it
6166 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006167 testCases = append(testCases, testCase{
6168 name: "SendSCTListOnResume-" + ver.name,
6169 config: Config{
6170 MaxVersion: ver.version,
6171 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006172 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006173 },
David Benjamind98452d2015-06-16 14:16:23 -04006174 },
David Benjamin97d17d92016-07-14 16:12:00 -04006175 flags: []string{
6176 "-enable-signed-cert-timestamps",
6177 "-expect-signed-cert-timestamps",
6178 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006179 },
David Benjamina5022392017-07-10 17:40:39 -04006180 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006181 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006182 })
David Benjamindaa88502016-10-04 16:32:16 -04006183
David Benjamin97d17d92016-07-14 16:12:00 -04006184 testCases = append(testCases, testCase{
6185 name: "SignedCertificateTimestampList-Server-" + ver.name,
6186 testType: serverTest,
6187 config: Config{
6188 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006189 },
David Benjamin97d17d92016-07-14 16:12:00 -04006190 flags: []string{
6191 "-signed-cert-timestamps",
6192 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006193 },
David Benjamina5022392017-07-10 17:40:39 -04006194 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006195 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006196 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006197 })
David Benjamin53210cb2016-11-16 09:01:48 +09006198
Adam Langleycfa08c32016-11-17 13:21:27 -08006199 emptySCTListCert := *testCerts[0].cert
6200 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6201
6202 // Test empty SCT list.
6203 testCases = append(testCases, testCase{
6204 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6205 testType: clientTest,
6206 config: Config{
6207 MaxVersion: ver.version,
6208 Certificates: []Certificate{emptySCTListCert},
6209 },
6210 flags: []string{
6211 "-enable-signed-cert-timestamps",
6212 },
David Benjamina5022392017-07-10 17:40:39 -04006213 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006214 shouldFail: true,
6215 expectedError: ":ERROR_PARSING_EXTENSION:",
6216 })
6217
6218 emptySCTCert := *testCerts[0].cert
6219 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6220
6221 // Test empty SCT in non-empty list.
6222 testCases = append(testCases, testCase{
6223 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6224 testType: clientTest,
6225 config: Config{
6226 MaxVersion: ver.version,
6227 Certificates: []Certificate{emptySCTCert},
6228 },
6229 flags: []string{
6230 "-enable-signed-cert-timestamps",
6231 },
David Benjamina5022392017-07-10 17:40:39 -04006232 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006233 shouldFail: true,
6234 expectedError: ":ERROR_PARSING_EXTENSION:",
6235 })
6236
David Benjamin53210cb2016-11-16 09:01:48 +09006237 // Test that certificate-related extensions are not sent unsolicited.
6238 testCases = append(testCases, testCase{
6239 testType: serverTest,
6240 name: "UnsolicitedCertificateExtensions-" + ver.name,
6241 config: Config{
6242 MaxVersion: ver.version,
6243 Bugs: ProtocolBugs{
6244 NoOCSPStapling: true,
6245 NoSignedCertificateTimestamps: true,
6246 },
6247 },
David Benjamina5022392017-07-10 17:40:39 -04006248 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006249 flags: []string{
6250 "-ocsp-response",
6251 base64.StdEncoding.EncodeToString(testOCSPResponse),
6252 "-signed-cert-timestamps",
6253 base64.StdEncoding.EncodeToString(testSCTList),
6254 },
6255 })
David Benjamin97d17d92016-07-14 16:12:00 -04006256 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006257
Paul Lietar4fac72e2015-09-09 13:44:55 +01006258 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006259 testType: clientTest,
6260 name: "ClientHelloPadding",
6261 config: Config{
6262 Bugs: ProtocolBugs{
6263 RequireClientHelloSize: 512,
6264 },
6265 },
6266 // This hostname just needs to be long enough to push the
6267 // ClientHello into F5's danger zone between 256 and 511 bytes
6268 // long.
6269 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6270 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006271
6272 // Extensions should not function in SSL 3.0.
6273 testCases = append(testCases, testCase{
6274 testType: serverTest,
6275 name: "SSLv3Extensions-NoALPN",
6276 config: Config{
6277 MaxVersion: VersionSSL30,
6278 NextProtos: []string{"foo", "bar", "baz"},
6279 },
6280 flags: []string{
6281 "-select-alpn", "foo",
6282 },
6283 expectNoNextProto: true,
6284 })
6285
6286 // Test session tickets separately as they follow a different codepath.
6287 testCases = append(testCases, testCase{
6288 testType: serverTest,
6289 name: "SSLv3Extensions-NoTickets",
6290 config: Config{
6291 MaxVersion: VersionSSL30,
6292 Bugs: ProtocolBugs{
6293 // Historically, session tickets in SSL 3.0
6294 // failed in different ways depending on whether
6295 // the client supported renegotiation_info.
6296 NoRenegotiationInfo: true,
6297 },
6298 },
6299 resumeSession: true,
6300 })
6301 testCases = append(testCases, testCase{
6302 testType: serverTest,
6303 name: "SSLv3Extensions-NoTickets2",
6304 config: Config{
6305 MaxVersion: VersionSSL30,
6306 },
6307 resumeSession: true,
6308 })
6309
6310 // But SSL 3.0 does send and process renegotiation_info.
6311 testCases = append(testCases, testCase{
6312 testType: serverTest,
6313 name: "SSLv3Extensions-RenegotiationInfo",
6314 config: Config{
6315 MaxVersion: VersionSSL30,
6316 Bugs: ProtocolBugs{
6317 RequireRenegotiationInfo: true,
6318 },
6319 },
David Benjamind2610042017-01-03 10:49:28 -05006320 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006321 })
6322 testCases = append(testCases, testCase{
6323 testType: serverTest,
6324 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6325 config: Config{
6326 MaxVersion: VersionSSL30,
6327 Bugs: ProtocolBugs{
6328 NoRenegotiationInfo: true,
6329 SendRenegotiationSCSV: true,
6330 RequireRenegotiationInfo: true,
6331 },
6332 },
David Benjamind2610042017-01-03 10:49:28 -05006333 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006334 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006335
6336 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6337 // in ServerHello.
6338 testCases = append(testCases, testCase{
6339 name: "NPN-Forbidden-TLS13",
6340 config: Config{
6341 MaxVersion: VersionTLS13,
6342 NextProtos: []string{"foo"},
6343 Bugs: ProtocolBugs{
6344 NegotiateNPNAtAllVersions: true,
6345 },
6346 },
6347 flags: []string{"-select-next-proto", "foo"},
6348 shouldFail: true,
6349 expectedError: ":ERROR_PARSING_EXTENSION:",
6350 })
6351 testCases = append(testCases, testCase{
6352 name: "EMS-Forbidden-TLS13",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 Bugs: ProtocolBugs{
6356 NegotiateEMSAtAllVersions: true,
6357 },
6358 },
6359 shouldFail: true,
6360 expectedError: ":ERROR_PARSING_EXTENSION:",
6361 })
6362 testCases = append(testCases, testCase{
6363 name: "RenegotiationInfo-Forbidden-TLS13",
6364 config: Config{
6365 MaxVersion: VersionTLS13,
6366 Bugs: ProtocolBugs{
6367 NegotiateRenegotiationInfoAtAllVersions: true,
6368 },
6369 },
6370 shouldFail: true,
6371 expectedError: ":ERROR_PARSING_EXTENSION:",
6372 })
6373 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006374 name: "Ticket-Forbidden-TLS13",
6375 config: Config{
6376 MaxVersion: VersionTLS12,
6377 },
6378 resumeConfig: &Config{
6379 MaxVersion: VersionTLS13,
6380 Bugs: ProtocolBugs{
6381 AdvertiseTicketExtension: true,
6382 },
6383 },
6384 resumeSession: true,
6385 shouldFail: true,
6386 expectedError: ":ERROR_PARSING_EXTENSION:",
6387 })
6388
6389 // Test that illegal extensions in TLS 1.3 are declined by the server if
6390 // offered in ClientHello. The runner's server will fail if this occurs,
6391 // so we exercise the offering path. (EMS and Renegotiation Info are
6392 // implicit in every test.)
6393 testCases = append(testCases, testCase{
6394 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006395 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006396 config: Config{
6397 MaxVersion: VersionTLS13,
6398 NextProtos: []string{"bar"},
6399 },
6400 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6401 })
David Benjamin196df5b2016-09-21 16:23:27 -04006402
David Benjamindaa88502016-10-04 16:32:16 -04006403 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6404 // tolerated.
6405 testCases = append(testCases, testCase{
6406 name: "SendOCSPResponseOnResume-TLS12",
6407 config: Config{
6408 MaxVersion: VersionTLS12,
6409 Bugs: ProtocolBugs{
6410 SendOCSPResponseOnResume: []byte("bogus"),
6411 },
6412 },
6413 flags: []string{
6414 "-enable-ocsp-stapling",
6415 "-expect-ocsp-response",
6416 base64.StdEncoding.EncodeToString(testOCSPResponse),
6417 },
6418 resumeSession: true,
6419 })
6420
David Benjamindaa88502016-10-04 16:32:16 -04006421 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006422 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006423 config: Config{
6424 MaxVersion: VersionTLS13,
6425 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006426 SendExtensionOnCertificate: testOCSPExtension,
6427 },
6428 },
6429 shouldFail: true,
6430 expectedError: ":UNEXPECTED_EXTENSION:",
6431 })
6432
6433 testCases = append(testCases, testCase{
6434 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6435 config: Config{
6436 MaxVersion: VersionTLS13,
6437 Bugs: ProtocolBugs{
6438 SendExtensionOnCertificate: testSCTExtension,
6439 },
6440 },
6441 shouldFail: true,
6442 expectedError: ":UNEXPECTED_EXTENSION:",
6443 })
6444
6445 // Test that extensions on client certificates are never accepted.
6446 testCases = append(testCases, testCase{
6447 name: "SendExtensionOnClientCertificate-TLS13",
6448 testType: serverTest,
6449 config: Config{
6450 MaxVersion: VersionTLS13,
6451 Certificates: []Certificate{rsaCertificate},
6452 Bugs: ProtocolBugs{
6453 SendExtensionOnCertificate: testOCSPExtension,
6454 },
6455 },
6456 flags: []string{
6457 "-enable-ocsp-stapling",
6458 "-require-any-client-certificate",
6459 },
6460 shouldFail: true,
6461 expectedError: ":UNEXPECTED_EXTENSION:",
6462 })
6463
6464 testCases = append(testCases, testCase{
6465 name: "SendUnknownExtensionOnCertificate-TLS13",
6466 config: Config{
6467 MaxVersion: VersionTLS13,
6468 Bugs: ProtocolBugs{
6469 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6470 },
6471 },
6472 shouldFail: true,
6473 expectedError: ":UNEXPECTED_EXTENSION:",
6474 })
6475
Adam Langleycfa08c32016-11-17 13:21:27 -08006476 var differentSCTList []byte
6477 differentSCTList = append(differentSCTList, testSCTList...)
6478 differentSCTList[len(differentSCTList)-1] ^= 1
6479
Steven Valdeza833c352016-11-01 13:39:36 -04006480 // Test that extensions on intermediates are allowed but ignored.
6481 testCases = append(testCases, testCase{
6482 name: "IgnoreExtensionsOnIntermediates-TLS13",
6483 config: Config{
6484 MaxVersion: VersionTLS13,
6485 Certificates: []Certificate{rsaChainCertificate},
6486 Bugs: ProtocolBugs{
6487 // Send different values on the intermediate. This tests
6488 // the intermediate's extensions do not override the
6489 // leaf's.
6490 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006491 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006492 },
6493 },
6494 flags: []string{
6495 "-enable-ocsp-stapling",
6496 "-expect-ocsp-response",
6497 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006498 "-enable-signed-cert-timestamps",
6499 "-expect-signed-cert-timestamps",
6500 base64.StdEncoding.EncodeToString(testSCTList),
6501 },
6502 resumeSession: true,
6503 })
6504
6505 // Test that extensions are not sent on intermediates when configured
6506 // only for a leaf.
6507 testCases = append(testCases, testCase{
6508 testType: serverTest,
6509 name: "SendNoExtensionsOnIntermediate-TLS13",
6510 config: Config{
6511 MaxVersion: VersionTLS13,
6512 Bugs: ProtocolBugs{
6513 ExpectNoExtensionsOnIntermediate: true,
6514 },
6515 },
6516 flags: []string{
6517 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6518 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6519 "-ocsp-response",
6520 base64.StdEncoding.EncodeToString(testOCSPResponse),
6521 "-signed-cert-timestamps",
6522 base64.StdEncoding.EncodeToString(testSCTList),
6523 },
6524 })
6525
6526 // Test that extensions are not sent on client certificates.
6527 testCases = append(testCases, testCase{
6528 name: "SendNoClientCertificateExtensions-TLS13",
6529 config: Config{
6530 MaxVersion: VersionTLS13,
6531 ClientAuth: RequireAnyClientCert,
6532 },
6533 flags: []string{
6534 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6535 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6536 "-ocsp-response",
6537 base64.StdEncoding.EncodeToString(testOCSPResponse),
6538 "-signed-cert-timestamps",
6539 base64.StdEncoding.EncodeToString(testSCTList),
6540 },
6541 })
6542
6543 testCases = append(testCases, testCase{
6544 name: "SendDuplicateExtensionsOnCerts-TLS13",
6545 config: Config{
6546 MaxVersion: VersionTLS13,
6547 Bugs: ProtocolBugs{
6548 SendDuplicateCertExtensions: true,
6549 },
6550 },
6551 flags: []string{
6552 "-enable-ocsp-stapling",
6553 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006554 },
6555 resumeSession: true,
6556 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006557 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006558 })
Adam Langley9b885c52016-11-18 14:21:03 -08006559
6560 testCases = append(testCases, testCase{
6561 name: "SignedCertificateTimestampListInvalid-Server",
6562 testType: serverTest,
6563 flags: []string{
6564 "-signed-cert-timestamps",
6565 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6566 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006567 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006568 expectedError: ":INVALID_SCT_LIST:",
6569 })
David Benjamine78bfde2014-09-06 12:45:15 -04006570}
6571
David Benjamin01fe8202014-09-24 15:21:44 -04006572func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006573 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006574 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006575 // SSL 3.0 does not have tickets and TLS 1.3 does not
6576 // have session IDs, so skip their cross-resumption
6577 // tests.
6578 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6579 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6580 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006581 }
6582
David Benjamin8b8c0062014-11-23 02:47:52 -05006583 protocols := []protocol{tls}
6584 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6585 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006586 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006587 for _, protocol := range protocols {
6588 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6589 if protocol == dtls {
6590 suffix += "-DTLS"
6591 }
6592
Steven Valdez520e1222017-06-13 12:45:25 -04006593 // We can't resume across TLS 1.3 variants and error out earlier in the
6594 // session resumption.
6595 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6596 continue
6597 }
6598
David Benjaminece3de92015-03-16 18:02:20 -04006599 if sessionVers.version == resumeVers.version {
6600 testCases = append(testCases, testCase{
6601 protocol: protocol,
6602 name: "Resume-Client" + suffix,
6603 resumeSession: true,
6604 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: sessionVers.version,
6606 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006607 Bugs: ProtocolBugs{
6608 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6609 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6610 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006611 },
David Benjaminece3de92015-03-16 18:02:20 -04006612 expectedVersion: sessionVers.version,
6613 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006614 flags: []string{
6615 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6616 },
David Benjaminece3de92015-03-16 18:02:20 -04006617 })
6618 } else {
David Benjamin405da482016-08-08 17:25:07 -04006619 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6620
6621 // Offering a TLS 1.3 session sends an empty session ID, so
6622 // there is no way to convince a non-lookahead client the
6623 // session was resumed. It will appear to the client that a
6624 // stray ChangeCipherSpec was sent.
6625 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6626 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006627 }
6628
David Benjaminece3de92015-03-16 18:02:20 -04006629 testCases = append(testCases, testCase{
6630 protocol: protocol,
6631 name: "Resume-Client-Mismatch" + suffix,
6632 resumeSession: true,
6633 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006634 MaxVersion: sessionVers.version,
6635 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006636 },
David Benjaminece3de92015-03-16 18:02:20 -04006637 expectedVersion: sessionVers.version,
6638 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006639 MaxVersion: resumeVers.version,
6640 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006641 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006642 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006643 },
6644 },
6645 expectedResumeVersion: resumeVers.version,
6646 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006647 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006648 flags: []string{
6649 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6650 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6651 },
David Benjaminece3de92015-03-16 18:02:20 -04006652 })
6653 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006654
6655 testCases = append(testCases, testCase{
6656 protocol: protocol,
6657 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006658 resumeSession: true,
6659 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006660 MaxVersion: sessionVers.version,
6661 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006662 },
6663 expectedVersion: sessionVers.version,
6664 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006665 MaxVersion: resumeVers.version,
6666 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006667 },
6668 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006669 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006670 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006671 flags: []string{
6672 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6673 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6674 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006675 })
6676
David Benjamin8b8c0062014-11-23 02:47:52 -05006677 testCases = append(testCases, testCase{
6678 protocol: protocol,
6679 testType: serverTest,
6680 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006681 resumeSession: true,
6682 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006683 MaxVersion: sessionVers.version,
6684 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006685 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006686 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006687 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006688 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006689 MaxVersion: resumeVers.version,
6690 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006691 Bugs: ProtocolBugs{
6692 SendBothTickets: true,
6693 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006694 },
6695 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006696 flags: []string{
6697 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6698 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6699 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006700 })
6701 }
David Benjamin01fe8202014-09-24 15:21:44 -04006702 }
6703 }
David Benjaminece3de92015-03-16 18:02:20 -04006704
David Benjamin4199b0d2016-11-01 13:58:25 -04006705 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006706 testCases = append(testCases, testCase{
6707 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006708 name: "ShimTicketRewritable",
6709 resumeSession: true,
6710 config: Config{
6711 MaxVersion: VersionTLS12,
6712 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6713 Bugs: ProtocolBugs{
6714 FilterTicket: func(in []byte) ([]byte, error) {
6715 in, err := SetShimTicketVersion(in, VersionTLS12)
6716 if err != nil {
6717 return nil, err
6718 }
6719 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6720 },
6721 },
6722 },
6723 flags: []string{
6724 "-ticket-key",
6725 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6726 },
6727 })
6728
6729 // Resumptions are declined if the version does not match.
6730 testCases = append(testCases, testCase{
6731 testType: serverTest,
6732 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006733 resumeSession: true,
6734 config: Config{
6735 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006736 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006737 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006738 FilterTicket: func(in []byte) ([]byte, error) {
6739 return SetShimTicketVersion(in, VersionTLS13)
6740 },
6741 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006742 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006743 flags: []string{
6744 "-ticket-key",
6745 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6746 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006747 expectResumeRejected: true,
6748 })
6749
6750 testCases = append(testCases, testCase{
6751 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006752 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006753 resumeSession: true,
6754 config: Config{
6755 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006756 Bugs: ProtocolBugs{
6757 FilterTicket: func(in []byte) ([]byte, error) {
6758 return SetShimTicketVersion(in, VersionTLS12)
6759 },
6760 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006761 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006762 flags: []string{
6763 "-ticket-key",
6764 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6765 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006766 expectResumeRejected: true,
6767 })
6768
David Benjamin4199b0d2016-11-01 13:58:25 -04006769 // Resumptions are declined if the cipher is invalid or disabled.
6770 testCases = append(testCases, testCase{
6771 testType: serverTest,
6772 name: "Resume-Server-DeclineBadCipher",
6773 resumeSession: true,
6774 config: Config{
6775 MaxVersion: VersionTLS12,
6776 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006777 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006778 FilterTicket: func(in []byte) ([]byte, error) {
6779 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6780 },
6781 },
6782 },
6783 flags: []string{
6784 "-ticket-key",
6785 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6786 },
6787 expectResumeRejected: true,
6788 })
6789
6790 testCases = append(testCases, testCase{
6791 testType: serverTest,
6792 name: "Resume-Server-DeclineBadCipher-2",
6793 resumeSession: true,
6794 config: Config{
6795 MaxVersion: VersionTLS12,
6796 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006797 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006798 FilterTicket: func(in []byte) ([]byte, error) {
6799 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6800 },
6801 },
6802 },
6803 flags: []string{
6804 "-cipher", "AES128",
6805 "-ticket-key",
6806 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6807 },
6808 expectResumeRejected: true,
6809 })
6810
David Benjaminf01f42a2016-11-16 19:05:33 +09006811 // Sessions are not resumed if they do not use the preferred cipher.
6812 testCases = append(testCases, testCase{
6813 testType: serverTest,
6814 name: "Resume-Server-CipherNotPreferred",
6815 resumeSession: true,
6816 config: Config{
6817 MaxVersion: VersionTLS12,
6818 Bugs: ProtocolBugs{
6819 ExpectNewTicket: true,
6820 FilterTicket: func(in []byte) ([]byte, error) {
6821 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6822 },
6823 },
6824 },
6825 flags: []string{
6826 "-ticket-key",
6827 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6828 },
6829 shouldFail: false,
6830 expectResumeRejected: true,
6831 })
6832
6833 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6834 // PRF hashes match, but BoringSSL will always decline such resumptions.
6835 testCases = append(testCases, testCase{
6836 testType: serverTest,
6837 name: "Resume-Server-CipherNotPreferred-TLS13",
6838 resumeSession: true,
6839 config: Config{
6840 MaxVersion: VersionTLS13,
6841 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6842 Bugs: ProtocolBugs{
6843 FilterTicket: func(in []byte) ([]byte, error) {
6844 // If the client (runner) offers ChaCha20-Poly1305 first, the
6845 // server (shim) always prefers it. Switch it to AES-GCM.
6846 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6847 },
6848 },
6849 },
6850 flags: []string{
6851 "-ticket-key",
6852 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6853 },
6854 shouldFail: false,
6855 expectResumeRejected: true,
6856 })
6857
6858 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006859 testCases = append(testCases, testCase{
6860 testType: serverTest,
6861 name: "Resume-Server-DeclineBadCipher-TLS13",
6862 resumeSession: true,
6863 config: Config{
6864 MaxVersion: VersionTLS13,
6865 Bugs: ProtocolBugs{
6866 FilterTicket: func(in []byte) ([]byte, error) {
6867 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6868 },
6869 },
6870 },
6871 flags: []string{
6872 "-ticket-key",
6873 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6874 },
6875 expectResumeRejected: true,
6876 })
6877
David Benjaminf01f42a2016-11-16 19:05:33 +09006878 // If the client does not offer the cipher from the session, decline to
6879 // resume. Clients are forbidden from doing this, but BoringSSL selects
6880 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006881 testCases = append(testCases, testCase{
6882 testType: serverTest,
6883 name: "Resume-Server-UnofferedCipher",
6884 resumeSession: true,
6885 config: Config{
6886 MaxVersion: VersionTLS12,
6887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6888 },
6889 resumeConfig: &Config{
6890 MaxVersion: VersionTLS12,
6891 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6892 Bugs: ProtocolBugs{
6893 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6894 },
6895 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006896 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006897 })
6898
David Benjaminf01f42a2016-11-16 19:05:33 +09006899 // In TLS 1.3, clients may advertise a cipher list which does not
6900 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006901 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6902 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: "Resume-Server-UnofferedCipher-TLS13",
6906 resumeSession: true,
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6910 },
6911 resumeConfig: &Config{
6912 MaxVersion: VersionTLS13,
6913 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6914 Bugs: ProtocolBugs{
6915 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6916 },
6917 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006918 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006919 })
6920
David Benjamin4199b0d2016-11-01 13:58:25 -04006921 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006922 testCases = append(testCases, testCase{
6923 name: "Resume-Client-CipherMismatch",
6924 resumeSession: true,
6925 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006926 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006927 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6928 },
6929 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006930 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006931 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6932 Bugs: ProtocolBugs{
6933 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6934 },
6935 },
6936 shouldFail: true,
6937 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6938 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006939
David Benjamine1cc35e2016-11-16 16:25:58 +09006940 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6941 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006942 testCases = append(testCases, testCase{
6943 name: "Resume-Client-CipherMismatch-TLS13",
6944 resumeSession: true,
6945 config: Config{
6946 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006947 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006948 },
6949 resumeConfig: &Config{
6950 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006951 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6952 },
6953 })
6954
6955 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6956 testCases = append(testCases, testCase{
6957 name: "Resume-Client-PRFMismatch-TLS13",
6958 resumeSession: true,
6959 config: Config{
6960 MaxVersion: VersionTLS13,
6961 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6962 },
6963 resumeConfig: &Config{
6964 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006965 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006966 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006967 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006968 },
6969 },
6970 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006971 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006972 })
Steven Valdeza833c352016-11-01 13:39:36 -04006973
6974 testCases = append(testCases, testCase{
6975 testType: serverTest,
6976 name: "Resume-Server-BinderWrongLength",
6977 resumeSession: true,
6978 config: Config{
6979 MaxVersion: VersionTLS13,
6980 Bugs: ProtocolBugs{
6981 SendShortPSKBinder: true,
6982 },
6983 },
6984 shouldFail: true,
6985 expectedLocalError: "remote error: error decrypting message",
6986 expectedError: ":DIGEST_CHECK_FAILED:",
6987 })
6988
6989 testCases = append(testCases, testCase{
6990 testType: serverTest,
6991 name: "Resume-Server-NoPSKBinder",
6992 resumeSession: true,
6993 config: Config{
6994 MaxVersion: VersionTLS13,
6995 Bugs: ProtocolBugs{
6996 SendNoPSKBinder: true,
6997 },
6998 },
6999 shouldFail: true,
7000 expectedLocalError: "remote error: error decoding message",
7001 expectedError: ":DECODE_ERROR:",
7002 })
7003
7004 testCases = append(testCases, testCase{
7005 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05007006 name: "Resume-Server-ExtraPSKBinder",
7007 resumeSession: true,
7008 config: Config{
7009 MaxVersion: VersionTLS13,
7010 Bugs: ProtocolBugs{
7011 SendExtraPSKBinder: true,
7012 },
7013 },
7014 shouldFail: true,
7015 expectedLocalError: "remote error: illegal parameter",
7016 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7017 })
7018
7019 testCases = append(testCases, testCase{
7020 testType: serverTest,
7021 name: "Resume-Server-ExtraIdentityNoBinder",
7022 resumeSession: true,
7023 config: Config{
7024 MaxVersion: VersionTLS13,
7025 Bugs: ProtocolBugs{
7026 ExtraPSKIdentity: true,
7027 },
7028 },
7029 shouldFail: true,
7030 expectedLocalError: "remote error: illegal parameter",
7031 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7032 })
7033
7034 testCases = append(testCases, testCase{
7035 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007036 name: "Resume-Server-InvalidPSKBinder",
7037 resumeSession: true,
7038 config: Config{
7039 MaxVersion: VersionTLS13,
7040 Bugs: ProtocolBugs{
7041 SendInvalidPSKBinder: true,
7042 },
7043 },
7044 shouldFail: true,
7045 expectedLocalError: "remote error: error decrypting message",
7046 expectedError: ":DIGEST_CHECK_FAILED:",
7047 })
7048
7049 testCases = append(testCases, testCase{
7050 testType: serverTest,
7051 name: "Resume-Server-PSKBinderFirstExtension",
7052 resumeSession: true,
7053 config: Config{
7054 MaxVersion: VersionTLS13,
7055 Bugs: ProtocolBugs{
7056 PSKBinderFirst: true,
7057 },
7058 },
7059 shouldFail: true,
7060 expectedLocalError: "remote error: illegal parameter",
7061 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7062 })
David Benjamin01fe8202014-09-24 15:21:44 -04007063}
7064
Adam Langley2ae77d22014-10-28 17:29:33 -07007065func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007066 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007067 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007068 testType: serverTest,
7069 name: "Renegotiate-Server-Forbidden",
7070 config: Config{
7071 MaxVersion: VersionTLS12,
7072 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007073 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007074 shouldFail: true,
7075 expectedError: ":NO_RENEGOTIATION:",
7076 expectedLocalError: "remote error: no renegotiation",
7077 })
Adam Langley5021b222015-06-12 18:27:58 -07007078 // The server shouldn't echo the renegotiation extension unless
7079 // requested by the client.
7080 testCases = append(testCases, testCase{
7081 testType: serverTest,
7082 name: "Renegotiate-Server-NoExt",
7083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007084 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007085 Bugs: ProtocolBugs{
7086 NoRenegotiationInfo: true,
7087 RequireRenegotiationInfo: true,
7088 },
7089 },
7090 shouldFail: true,
7091 expectedLocalError: "renegotiation extension missing",
7092 })
7093 // The renegotiation SCSV should be sufficient for the server to echo
7094 // the extension.
7095 testCases = append(testCases, testCase{
7096 testType: serverTest,
7097 name: "Renegotiate-Server-NoExt-SCSV",
7098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007099 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007100 Bugs: ProtocolBugs{
7101 NoRenegotiationInfo: true,
7102 SendRenegotiationSCSV: true,
7103 RequireRenegotiationInfo: true,
7104 },
7105 },
7106 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007107 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007108 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007110 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007111 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007112 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007113 },
7114 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007115 renegotiate: 1,
7116 flags: []string{
7117 "-renegotiate-freely",
7118 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007119 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007120 },
David Benjamincdea40c2015-03-19 14:09:43 -04007121 })
7122 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007123 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007124 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007126 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 Bugs: ProtocolBugs{
7128 EmptyRenegotiationInfo: true,
7129 },
7130 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007131 flags: []string{"-renegotiate-freely"},
7132 shouldFail: true,
7133 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007134 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007135 })
7136 testCases = append(testCases, testCase{
7137 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007138 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007140 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007141 Bugs: ProtocolBugs{
7142 BadRenegotiationInfo: true,
7143 },
7144 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007145 flags: []string{"-renegotiate-freely"},
7146 shouldFail: true,
7147 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007148 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007149 })
7150 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007151 name: "Renegotiate-Client-BadExt2",
7152 renegotiate: 1,
7153 config: Config{
7154 MaxVersion: VersionTLS12,
7155 Bugs: ProtocolBugs{
7156 BadRenegotiationInfoEnd: true,
7157 },
7158 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007159 flags: []string{"-renegotiate-freely"},
7160 shouldFail: true,
7161 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007162 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007163 })
7164 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007165 name: "Renegotiate-Client-Downgrade",
7166 renegotiate: 1,
7167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007168 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007169 Bugs: ProtocolBugs{
7170 NoRenegotiationInfoAfterInitial: true,
7171 },
7172 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007173 flags: []string{"-renegotiate-freely"},
7174 shouldFail: true,
7175 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007176 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007177 })
7178 testCases = append(testCases, testCase{
7179 name: "Renegotiate-Client-Upgrade",
7180 renegotiate: 1,
7181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007182 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007183 Bugs: ProtocolBugs{
7184 NoRenegotiationInfoInInitial: true,
7185 },
7186 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007187 flags: []string{"-renegotiate-freely"},
7188 shouldFail: true,
7189 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007190 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007191 })
7192 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007193 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007194 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007197 Bugs: ProtocolBugs{
7198 NoRenegotiationInfo: true,
7199 },
7200 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007201 flags: []string{
7202 "-renegotiate-freely",
7203 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007204 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007205 },
David Benjamincff0b902015-05-15 23:09:47 -04007206 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007207
7208 // Test that the server may switch ciphers on renegotiation without
7209 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007210 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007211 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007212 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007213 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007214 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007215 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007216 },
7217 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007218 flags: []string{
7219 "-renegotiate-freely",
7220 "-expect-total-renegotiations", "1",
7221 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007222 })
7223 testCases = append(testCases, testCase{
7224 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007225 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007227 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007228 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7229 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007230 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007231 flags: []string{
7232 "-renegotiate-freely",
7233 "-expect-total-renegotiations", "1",
7234 },
David Benjaminb16346b2015-04-08 19:16:58 -04007235 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007236
7237 // Test that the server may not switch versions on renegotiation.
7238 testCases = append(testCases, testCase{
7239 name: "Renegotiate-Client-SwitchVersion",
7240 config: Config{
7241 MaxVersion: VersionTLS12,
7242 // Pick a cipher which exists at both versions.
7243 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7244 Bugs: ProtocolBugs{
7245 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007246 // Avoid failing early at the record layer.
7247 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007248 },
7249 },
7250 renegotiate: 1,
7251 flags: []string{
7252 "-renegotiate-freely",
7253 "-expect-total-renegotiations", "1",
7254 },
7255 shouldFail: true,
7256 expectedError: ":WRONG_SSL_VERSION:",
7257 })
7258
David Benjaminb16346b2015-04-08 19:16:58 -04007259 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007260 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007261 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007262 config: Config{
7263 MaxVersion: VersionTLS10,
7264 Bugs: ProtocolBugs{
7265 RequireSameRenegoClientVersion: true,
7266 },
7267 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007268 flags: []string{
7269 "-renegotiate-freely",
7270 "-expect-total-renegotiations", "1",
7271 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007272 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007273 testCases = append(testCases, testCase{
7274 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007275 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007276 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007277 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007278 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7279 NextProtos: []string{"foo"},
7280 },
7281 flags: []string{
7282 "-false-start",
7283 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007284 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007285 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007286 },
7287 shimWritesFirst: true,
7288 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007289
7290 // Client-side renegotiation controls.
7291 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007292 name: "Renegotiate-Client-Forbidden-1",
7293 config: Config{
7294 MaxVersion: VersionTLS12,
7295 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007296 renegotiate: 1,
7297 shouldFail: true,
7298 expectedError: ":NO_RENEGOTIATION:",
7299 expectedLocalError: "remote error: no renegotiation",
7300 })
7301 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007302 name: "Renegotiate-Client-Once-1",
7303 config: Config{
7304 MaxVersion: VersionTLS12,
7305 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007306 renegotiate: 1,
7307 flags: []string{
7308 "-renegotiate-once",
7309 "-expect-total-renegotiations", "1",
7310 },
7311 })
7312 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007313 name: "Renegotiate-Client-Freely-1",
7314 config: Config{
7315 MaxVersion: VersionTLS12,
7316 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007317 renegotiate: 1,
7318 flags: []string{
7319 "-renegotiate-freely",
7320 "-expect-total-renegotiations", "1",
7321 },
7322 })
7323 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007324 name: "Renegotiate-Client-Once-2",
7325 config: Config{
7326 MaxVersion: VersionTLS12,
7327 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007328 renegotiate: 2,
7329 flags: []string{"-renegotiate-once"},
7330 shouldFail: true,
7331 expectedError: ":NO_RENEGOTIATION:",
7332 expectedLocalError: "remote error: no renegotiation",
7333 })
7334 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007335 name: "Renegotiate-Client-Freely-2",
7336 config: Config{
7337 MaxVersion: VersionTLS12,
7338 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007339 renegotiate: 2,
7340 flags: []string{
7341 "-renegotiate-freely",
7342 "-expect-total-renegotiations", "2",
7343 },
7344 })
Adam Langley27a0d082015-11-03 13:34:10 -08007345 testCases = append(testCases, testCase{
7346 name: "Renegotiate-Client-NoIgnore",
7347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007349 Bugs: ProtocolBugs{
7350 SendHelloRequestBeforeEveryAppDataRecord: true,
7351 },
7352 },
7353 shouldFail: true,
7354 expectedError: ":NO_RENEGOTIATION:",
7355 })
7356 testCases = append(testCases, testCase{
7357 name: "Renegotiate-Client-Ignore",
7358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007359 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007360 Bugs: ProtocolBugs{
7361 SendHelloRequestBeforeEveryAppDataRecord: true,
7362 },
7363 },
7364 flags: []string{
7365 "-renegotiate-ignore",
7366 "-expect-total-renegotiations", "0",
7367 },
7368 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007369
David Benjamin34941c02016-10-08 11:45:31 -04007370 // Renegotiation is not allowed at SSL 3.0.
7371 testCases = append(testCases, testCase{
7372 name: "Renegotiate-Client-SSL3",
7373 config: Config{
7374 MaxVersion: VersionSSL30,
7375 },
7376 renegotiate: 1,
7377 flags: []string{
7378 "-renegotiate-freely",
7379 "-expect-total-renegotiations", "1",
7380 },
7381 shouldFail: true,
7382 expectedError: ":NO_RENEGOTIATION:",
7383 expectedLocalError: "remote error: no renegotiation",
7384 })
7385
David Benjamina1eaba12017-01-01 23:19:22 -05007386 // Renegotiation is not allowed when there is an unfinished write.
7387 testCases = append(testCases, testCase{
7388 name: "Renegotiate-Client-UnfinishedWrite",
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 },
David Benjaminbbba9392017-04-06 12:54:12 -04007392 renegotiate: 1,
7393 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007394 flags: []string{
7395 "-async",
7396 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007397 },
7398 shouldFail: true,
7399 expectedError: ":NO_RENEGOTIATION:",
7400 // We do not successfully send the no_renegotiation alert in
7401 // this case. https://crbug.com/boringssl/130
7402 })
7403
David Benjamin07ab5d42017-02-09 20:11:41 -05007404 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007405 testCases = append(testCases, testCase{
7406 name: "StrayHelloRequest",
7407 config: Config{
7408 MaxVersion: VersionTLS12,
7409 Bugs: ProtocolBugs{
7410 SendHelloRequestBeforeEveryHandshakeMessage: true,
7411 },
7412 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007415 })
7416 testCases = append(testCases, testCase{
7417 name: "StrayHelloRequest-Packed",
7418 config: Config{
7419 MaxVersion: VersionTLS12,
7420 Bugs: ProtocolBugs{
7421 PackHandshakeFlight: true,
7422 SendHelloRequestBeforeEveryHandshakeMessage: true,
7423 },
7424 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007425 shouldFail: true,
7426 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007427 })
7428
David Benjamin12d2c482016-07-24 10:56:51 -04007429 // Test renegotiation works if HelloRequest and server Finished come in
7430 // the same record.
7431 testCases = append(testCases, testCase{
7432 name: "Renegotiate-Client-Packed",
7433 config: Config{
7434 MaxVersion: VersionTLS12,
7435 Bugs: ProtocolBugs{
7436 PackHandshakeFlight: true,
7437 PackHelloRequestWithFinished: true,
7438 },
7439 },
7440 renegotiate: 1,
7441 flags: []string{
7442 "-renegotiate-freely",
7443 "-expect-total-renegotiations", "1",
7444 },
7445 })
7446
David Benjamin397c8e62016-07-08 14:14:36 -07007447 // Renegotiation is forbidden in TLS 1.3.
7448 testCases = append(testCases, testCase{
7449 name: "Renegotiate-Client-TLS13",
7450 config: Config{
7451 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007452 Bugs: ProtocolBugs{
7453 SendHelloRequestBeforeEveryAppDataRecord: true,
7454 },
David Benjamin397c8e62016-07-08 14:14:36 -07007455 },
David Benjamin397c8e62016-07-08 14:14:36 -07007456 flags: []string{
7457 "-renegotiate-freely",
7458 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007459 shouldFail: true,
7460 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007461 })
7462
7463 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7464 testCases = append(testCases, testCase{
7465 name: "StrayHelloRequest-TLS13",
7466 config: Config{
7467 MaxVersion: VersionTLS13,
7468 Bugs: ProtocolBugs{
7469 SendHelloRequestBeforeEveryHandshakeMessage: true,
7470 },
7471 },
7472 shouldFail: true,
7473 expectedError: ":UNEXPECTED_MESSAGE:",
7474 })
David Benjamind2610042017-01-03 10:49:28 -05007475
7476 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7477 // always reads as supporting it, regardless of whether it was
7478 // negotiated.
7479 testCases = append(testCases, testCase{
7480 name: "AlwaysReportRenegotiationInfo-TLS13",
7481 config: Config{
7482 MaxVersion: VersionTLS13,
7483 Bugs: ProtocolBugs{
7484 NoRenegotiationInfo: true,
7485 },
7486 },
7487 flags: []string{
7488 "-expect-secure-renegotiation",
7489 },
7490 })
David Benjamina58baaf2017-02-28 20:54:28 -05007491
7492 // Certificates may not change on renegotiation.
7493 testCases = append(testCases, testCase{
7494 name: "Renegotiation-CertificateChange",
7495 config: Config{
7496 MaxVersion: VersionTLS12,
7497 Certificates: []Certificate{rsaCertificate},
7498 Bugs: ProtocolBugs{
7499 RenegotiationCertificate: &rsaChainCertificate,
7500 },
7501 },
7502 renegotiate: 1,
7503 flags: []string{"-renegotiate-freely"},
7504 shouldFail: true,
7505 expectedError: ":SERVER_CERT_CHANGED:",
7506 })
7507 testCases = append(testCases, testCase{
7508 name: "Renegotiation-CertificateChange-2",
7509 config: Config{
7510 MaxVersion: VersionTLS12,
7511 Certificates: []Certificate{rsaCertificate},
7512 Bugs: ProtocolBugs{
7513 RenegotiationCertificate: &rsa1024Certificate,
7514 },
7515 },
7516 renegotiate: 1,
7517 flags: []string{"-renegotiate-freely"},
7518 shouldFail: true,
7519 expectedError: ":SERVER_CERT_CHANGED:",
7520 })
David Benjaminbbf42462017-03-14 21:27:10 -04007521
7522 // We do not negotiate ALPN after the initial handshake. This is
7523 // error-prone and only risks bugs in consumers.
7524 testCases = append(testCases, testCase{
7525 testType: clientTest,
7526 name: "Renegotiation-ForbidALPN",
7527 config: Config{
7528 MaxVersion: VersionTLS12,
7529 Bugs: ProtocolBugs{
7530 // Forcibly negotiate ALPN on both initial and
7531 // renegotiation handshakes. The test stack will
7532 // internally check the client does not offer
7533 // it.
7534 SendALPN: "foo",
7535 },
7536 },
7537 flags: []string{
7538 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7539 "-expect-alpn", "foo",
7540 "-renegotiate-freely",
7541 },
7542 renegotiate: 1,
7543 shouldFail: true,
7544 expectedError: ":UNEXPECTED_EXTENSION:",
7545 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007546}
7547
David Benjamin5e961c12014-11-07 01:48:35 -05007548func addDTLSReplayTests() {
7549 // Test that sequence number replays are detected.
7550 testCases = append(testCases, testCase{
7551 protocol: dtls,
7552 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007553 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007554 replayWrites: true,
7555 })
7556
David Benjamin8e6db492015-07-25 18:29:23 -04007557 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007558 // than the retransmit window.
7559 testCases = append(testCases, testCase{
7560 protocol: dtls,
7561 name: "DTLS-Replay-LargeGaps",
7562 config: Config{
7563 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007564 SequenceNumberMapping: func(in uint64) uint64 {
7565 return in * 127
7566 },
David Benjamin5e961c12014-11-07 01:48:35 -05007567 },
7568 },
David Benjamin8e6db492015-07-25 18:29:23 -04007569 messageCount: 200,
7570 replayWrites: true,
7571 })
7572
7573 // Test the incoming sequence number changing non-monotonically.
7574 testCases = append(testCases, testCase{
7575 protocol: dtls,
7576 name: "DTLS-Replay-NonMonotonic",
7577 config: Config{
7578 Bugs: ProtocolBugs{
7579 SequenceNumberMapping: func(in uint64) uint64 {
7580 return in ^ 31
7581 },
7582 },
7583 },
7584 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007585 replayWrites: true,
7586 })
7587}
7588
Nick Harper60edffd2016-06-21 15:19:24 -07007589var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007590 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007591 id signatureAlgorithm
7592 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007593}{
Nick Harper60edffd2016-06-21 15:19:24 -07007594 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7595 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7596 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7597 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007598 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007599 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7600 // hash function doesn't have to match the curve and so the same
7601 // signature algorithm works with P-224.
7602 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007603 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7604 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7605 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007606 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7607 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7608 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007609 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007610 // Tests for key types prior to TLS 1.2.
7611 {"RSA", 0, testCertRSA},
7612 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007613}
7614
Nick Harper60edffd2016-06-21 15:19:24 -07007615const fakeSigAlg1 signatureAlgorithm = 0x2a01
7616const fakeSigAlg2 signatureAlgorithm = 0xff01
7617
7618func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007619 // Not all ciphers involve a signature. Advertise a list which gives all
7620 // versions a signing cipher.
7621 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007622 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007623 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7624 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7625 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7626 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007627 }
David Benjamin5208fd42016-07-13 21:43:25 -04007628
David Benjaminca3d5452016-07-14 12:51:01 -04007629 var allAlgorithms []signatureAlgorithm
7630 for _, alg := range testSignatureAlgorithms {
7631 if alg.id != 0 {
7632 allAlgorithms = append(allAlgorithms, alg.id)
7633 }
7634 }
7635
Nick Harper60edffd2016-06-21 15:19:24 -07007636 // Make sure each signature algorithm works. Include some fake values in
7637 // the list and ensure they're ignored.
7638 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007639 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007640 if (ver.version < VersionTLS12) != (alg.id == 0) {
7641 continue
7642 }
7643
7644 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7645 // or remove it in C.
7646 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007647 continue
7648 }
Nick Harper60edffd2016-06-21 15:19:24 -07007649
David Benjamin3ef76972016-10-17 17:59:54 -04007650 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007651 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007652 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007653 shouldSignFail = true
7654 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007655 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007656 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007657 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7658 shouldSignFail = true
7659 shouldVerifyFail = true
7660 }
7661 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7662 // the curve has to match the hash size.
7663 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007664 shouldSignFail = true
7665 shouldVerifyFail = true
7666 }
7667
7668 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7669 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7670 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007671 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007672
7673 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007674 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007675 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007676 }
7677 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007678 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007679 }
David Benjamin000800a2014-11-14 01:43:59 -05007680
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007682
David Benjamin7a41d372016-07-09 11:21:54 -07007683 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007684 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007685 config: Config{
7686 MaxVersion: ver.version,
7687 ClientAuth: RequireAnyClientCert,
7688 VerifySignatureAlgorithms: []signatureAlgorithm{
7689 fakeSigAlg1,
7690 alg.id,
7691 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007692 },
David Benjamin7a41d372016-07-09 11:21:54 -07007693 },
7694 flags: []string{
7695 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7696 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7697 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007698 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007699 },
David Benjamina5022392017-07-10 17:40:39 -04007700 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007701 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007702 expectedError: signError,
7703 expectedPeerSignatureAlgorithm: alg.id,
7704 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007705
David Benjamin7a41d372016-07-09 11:21:54 -07007706 testCases = append(testCases, testCase{
7707 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007708 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007709 config: Config{
7710 MaxVersion: ver.version,
7711 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7712 SignSignatureAlgorithms: []signatureAlgorithm{
7713 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007714 },
David Benjamin7a41d372016-07-09 11:21:54 -07007715 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007716 SkipECDSACurveCheck: shouldVerifyFail,
7717 IgnoreSignatureVersionChecks: shouldVerifyFail,
7718 // Some signature algorithms may not be advertised.
7719 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007720 },
David Benjamin7a41d372016-07-09 11:21:54 -07007721 },
David Benjamina5022392017-07-10 17:40:39 -04007722 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007723 flags: []string{
7724 "-require-any-client-certificate",
7725 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7726 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007727 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007728 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007729 // Resume the session to assert the peer signature
7730 // algorithm is reported on both handshakes.
7731 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007732 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007733 expectedError: verifyError,
7734 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007735
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007736 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007737 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007738 testCases = append(testCases, testCase{
7739 testType: serverTest,
7740 name: "ServerAuth-Sign" + suffix,
7741 config: Config{
7742 MaxVersion: ver.version,
7743 CipherSuites: signingCiphers,
7744 VerifySignatureAlgorithms: []signatureAlgorithm{
7745 fakeSigAlg1,
7746 alg.id,
7747 fakeSigAlg2,
7748 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007749 },
David Benjamina5022392017-07-10 17:40:39 -04007750 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007751 flags: []string{
7752 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7753 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7754 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007755 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007756 },
7757 shouldFail: shouldSignFail,
7758 expectedError: signError,
7759 expectedPeerSignatureAlgorithm: alg.id,
7760 })
7761 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007762
7763 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007764 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007765 config: Config{
7766 MaxVersion: ver.version,
7767 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007768 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007769 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007770 alg.id,
7771 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007772 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007773 SkipECDSACurveCheck: shouldVerifyFail,
7774 IgnoreSignatureVersionChecks: shouldVerifyFail,
7775 // Some signature algorithms may not be advertised.
7776 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007777 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007778 },
David Benjamina5022392017-07-10 17:40:39 -04007779 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007780 flags: []string{
7781 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7782 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007783 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007784 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007785 // Resume the session to assert the peer signature
7786 // algorithm is reported on both handshakes.
7787 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007788 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007789 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007790 })
David Benjamin5208fd42016-07-13 21:43:25 -04007791
David Benjamin3ef76972016-10-17 17:59:54 -04007792 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007793 testCases = append(testCases, testCase{
7794 testType: serverTest,
7795 name: "ClientAuth-InvalidSignature" + suffix,
7796 config: Config{
7797 MaxVersion: ver.version,
7798 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7799 SignSignatureAlgorithms: []signatureAlgorithm{
7800 alg.id,
7801 },
7802 Bugs: ProtocolBugs{
7803 InvalidSignature: true,
7804 },
7805 },
David Benjamina5022392017-07-10 17:40:39 -04007806 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007807 flags: []string{
7808 "-require-any-client-certificate",
7809 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007810 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007811 },
7812 shouldFail: true,
7813 expectedError: ":BAD_SIGNATURE:",
7814 })
7815
7816 testCases = append(testCases, testCase{
7817 name: "ServerAuth-InvalidSignature" + suffix,
7818 config: Config{
7819 MaxVersion: ver.version,
7820 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7821 CipherSuites: signingCiphers,
7822 SignSignatureAlgorithms: []signatureAlgorithm{
7823 alg.id,
7824 },
7825 Bugs: ProtocolBugs{
7826 InvalidSignature: true,
7827 },
7828 },
David Benjamina5022392017-07-10 17:40:39 -04007829 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007830 flags: []string{
7831 "-enable-all-curves",
7832 "-enable-ed25519",
7833 },
David Benjamin5208fd42016-07-13 21:43:25 -04007834 shouldFail: true,
7835 expectedError: ":BAD_SIGNATURE:",
7836 })
7837 }
David Benjaminca3d5452016-07-14 12:51:01 -04007838
David Benjamin3ef76972016-10-17 17:59:54 -04007839 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007840 testCases = append(testCases, testCase{
7841 name: "ClientAuth-Sign-Negotiate" + suffix,
7842 config: Config{
7843 MaxVersion: ver.version,
7844 ClientAuth: RequireAnyClientCert,
7845 VerifySignatureAlgorithms: allAlgorithms,
7846 },
David Benjamina5022392017-07-10 17:40:39 -04007847 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007848 flags: []string{
7849 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7850 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7851 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007852 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007853 "-signing-prefs", strconv.Itoa(int(alg.id)),
7854 },
7855 expectedPeerSignatureAlgorithm: alg.id,
7856 })
7857
7858 testCases = append(testCases, testCase{
7859 testType: serverTest,
7860 name: "ServerAuth-Sign-Negotiate" + suffix,
7861 config: Config{
7862 MaxVersion: ver.version,
7863 CipherSuites: signingCiphers,
7864 VerifySignatureAlgorithms: allAlgorithms,
7865 },
David Benjamina5022392017-07-10 17:40:39 -04007866 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007867 flags: []string{
7868 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7869 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7870 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007871 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007872 "-signing-prefs", strconv.Itoa(int(alg.id)),
7873 },
7874 expectedPeerSignatureAlgorithm: alg.id,
7875 })
7876 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007877 }
David Benjamin000800a2014-11-14 01:43:59 -05007878 }
7879
Nick Harper60edffd2016-06-21 15:19:24 -07007880 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007881 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007882 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007883 config: Config{
7884 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007885 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007886 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007887 signatureECDSAWithP521AndSHA512,
7888 signatureRSAPKCS1WithSHA384,
7889 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007890 },
7891 },
7892 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007893 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7894 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007895 },
Nick Harper60edffd2016-06-21 15:19:24 -07007896 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007897 })
7898
7899 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007900 name: "ClientAuth-SignatureType-TLS13",
7901 config: Config{
7902 ClientAuth: RequireAnyClientCert,
7903 MaxVersion: VersionTLS13,
7904 VerifySignatureAlgorithms: []signatureAlgorithm{
7905 signatureECDSAWithP521AndSHA512,
7906 signatureRSAPKCS1WithSHA384,
7907 signatureRSAPSSWithSHA384,
7908 signatureECDSAWithSHA1,
7909 },
7910 },
7911 flags: []string{
7912 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7913 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7914 },
7915 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7916 })
7917
7918 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007919 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007920 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007922 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007923 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007924 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007925 signatureECDSAWithP521AndSHA512,
7926 signatureRSAPKCS1WithSHA384,
7927 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007928 },
7929 },
Nick Harper60edffd2016-06-21 15:19:24 -07007930 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007931 })
7932
Steven Valdez143e8b32016-07-11 13:19:03 -04007933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "ServerAuth-SignatureType-TLS13",
7936 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007937 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007938 VerifySignatureAlgorithms: []signatureAlgorithm{
7939 signatureECDSAWithP521AndSHA512,
7940 signatureRSAPKCS1WithSHA384,
7941 signatureRSAPSSWithSHA384,
7942 signatureECDSAWithSHA1,
7943 },
7944 },
7945 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7946 })
7947
David Benjamina95e9f32016-07-08 16:28:04 -07007948 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007949 testCases = append(testCases, testCase{
7950 testType: serverTest,
7951 name: "Verify-ClientAuth-SignatureType",
7952 config: Config{
7953 MaxVersion: VersionTLS12,
7954 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007955 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007956 signatureRSAPKCS1WithSHA256,
7957 },
7958 Bugs: ProtocolBugs{
7959 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7960 },
7961 },
7962 flags: []string{
7963 "-require-any-client-certificate",
7964 },
7965 shouldFail: true,
7966 expectedError: ":WRONG_SIGNATURE_TYPE:",
7967 })
7968
7969 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007970 testType: serverTest,
7971 name: "Verify-ClientAuth-SignatureType-TLS13",
7972 config: Config{
7973 MaxVersion: VersionTLS13,
7974 Certificates: []Certificate{rsaCertificate},
7975 SignSignatureAlgorithms: []signatureAlgorithm{
7976 signatureRSAPSSWithSHA256,
7977 },
7978 Bugs: ProtocolBugs{
7979 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7980 },
7981 },
7982 flags: []string{
7983 "-require-any-client-certificate",
7984 },
7985 shouldFail: true,
7986 expectedError: ":WRONG_SIGNATURE_TYPE:",
7987 })
7988
7989 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007990 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007991 config: Config{
7992 MaxVersion: VersionTLS12,
7993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007994 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007995 signatureRSAPKCS1WithSHA256,
7996 },
7997 Bugs: ProtocolBugs{
7998 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7999 },
8000 },
8001 shouldFail: true,
8002 expectedError: ":WRONG_SIGNATURE_TYPE:",
8003 })
8004
Steven Valdez143e8b32016-07-11 13:19:03 -04008005 testCases = append(testCases, testCase{
8006 name: "Verify-ServerAuth-SignatureType-TLS13",
8007 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008008 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008009 SignSignatureAlgorithms: []signatureAlgorithm{
8010 signatureRSAPSSWithSHA256,
8011 },
8012 Bugs: ProtocolBugs{
8013 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8014 },
8015 },
8016 shouldFail: true,
8017 expectedError: ":WRONG_SIGNATURE_TYPE:",
8018 })
8019
David Benjamin51dd7d62016-07-08 16:07:01 -07008020 // Test that, if the list is missing, the peer falls back to SHA-1 in
8021 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008022 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008023 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008025 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008026 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008027 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008028 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008029 },
8030 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008031 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008032 },
8033 },
8034 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008035 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8036 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008037 },
8038 })
8039
8040 testCases = append(testCases, testCase{
8041 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008042 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008043 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008044 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008045 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008046 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008047 },
8048 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008049 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008050 },
8051 },
David Benjaminee32bea2016-08-17 13:36:44 -04008052 flags: []string{
8053 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8054 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8055 },
8056 })
8057
8058 testCases = append(testCases, testCase{
8059 name: "ClientAuth-SHA1-Fallback-ECDSA",
8060 config: Config{
8061 MaxVersion: VersionTLS12,
8062 ClientAuth: RequireAnyClientCert,
8063 VerifySignatureAlgorithms: []signatureAlgorithm{
8064 signatureECDSAWithSHA1,
8065 },
8066 Bugs: ProtocolBugs{
8067 NoSignatureAlgorithms: true,
8068 },
8069 },
8070 flags: []string{
8071 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8072 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8073 },
8074 })
8075
8076 testCases = append(testCases, testCase{
8077 testType: serverTest,
8078 name: "ServerAuth-SHA1-Fallback-ECDSA",
8079 config: Config{
8080 MaxVersion: VersionTLS12,
8081 VerifySignatureAlgorithms: []signatureAlgorithm{
8082 signatureECDSAWithSHA1,
8083 },
8084 Bugs: ProtocolBugs{
8085 NoSignatureAlgorithms: true,
8086 },
8087 },
8088 flags: []string{
8089 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8090 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8091 },
David Benjamin000800a2014-11-14 01:43:59 -05008092 })
David Benjamin72dc7832015-03-16 17:49:43 -04008093
David Benjamin51dd7d62016-07-08 16:07:01 -07008094 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008095 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008096 config: Config{
8097 MaxVersion: VersionTLS13,
8098 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008099 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008100 signatureRSAPKCS1WithSHA1,
8101 },
8102 Bugs: ProtocolBugs{
8103 NoSignatureAlgorithms: true,
8104 },
8105 },
8106 flags: []string{
8107 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8108 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8109 },
David Benjamin48901652016-08-01 12:12:47 -04008110 shouldFail: true,
8111 // An empty CertificateRequest signature algorithm list is a
8112 // syntax error in TLS 1.3.
8113 expectedError: ":DECODE_ERROR:",
8114 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008115 })
8116
8117 testCases = append(testCases, testCase{
8118 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008119 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008120 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008121 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008122 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008123 signatureRSAPKCS1WithSHA1,
8124 },
8125 Bugs: ProtocolBugs{
8126 NoSignatureAlgorithms: true,
8127 },
8128 },
8129 shouldFail: true,
8130 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8131 })
8132
David Benjaminb62d2872016-07-18 14:55:02 +02008133 // Test that hash preferences are enforced. BoringSSL does not implement
8134 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008135 testCases = append(testCases, testCase{
8136 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008137 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008139 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008140 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008141 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008142 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008143 },
8144 Bugs: ProtocolBugs{
8145 IgnorePeerSignatureAlgorithmPreferences: true,
8146 },
8147 },
8148 flags: []string{"-require-any-client-certificate"},
8149 shouldFail: true,
8150 expectedError: ":WRONG_SIGNATURE_TYPE:",
8151 })
8152
8153 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008154 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008156 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008158 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008159 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008160 },
8161 Bugs: ProtocolBugs{
8162 IgnorePeerSignatureAlgorithmPreferences: true,
8163 },
8164 },
8165 shouldFail: true,
8166 expectedError: ":WRONG_SIGNATURE_TYPE:",
8167 })
David Benjaminb62d2872016-07-18 14:55:02 +02008168 testCases = append(testCases, testCase{
8169 testType: serverTest,
8170 name: "ClientAuth-Enforced-TLS13",
8171 config: Config{
8172 MaxVersion: VersionTLS13,
8173 Certificates: []Certificate{rsaCertificate},
8174 SignSignatureAlgorithms: []signatureAlgorithm{
8175 signatureRSAPKCS1WithMD5,
8176 },
8177 Bugs: ProtocolBugs{
8178 IgnorePeerSignatureAlgorithmPreferences: true,
8179 IgnoreSignatureVersionChecks: true,
8180 },
8181 },
8182 flags: []string{"-require-any-client-certificate"},
8183 shouldFail: true,
8184 expectedError: ":WRONG_SIGNATURE_TYPE:",
8185 })
8186
8187 testCases = append(testCases, testCase{
8188 name: "ServerAuth-Enforced-TLS13",
8189 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008190 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008191 SignSignatureAlgorithms: []signatureAlgorithm{
8192 signatureRSAPKCS1WithMD5,
8193 },
8194 Bugs: ProtocolBugs{
8195 IgnorePeerSignatureAlgorithmPreferences: true,
8196 IgnoreSignatureVersionChecks: true,
8197 },
8198 },
8199 shouldFail: true,
8200 expectedError: ":WRONG_SIGNATURE_TYPE:",
8201 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008202
8203 // Test that the agreed upon digest respects the client preferences and
8204 // the server digests.
8205 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008206 name: "NoCommonAlgorithms-Digests",
8207 config: Config{
8208 MaxVersion: VersionTLS12,
8209 ClientAuth: RequireAnyClientCert,
8210 VerifySignatureAlgorithms: []signatureAlgorithm{
8211 signatureRSAPKCS1WithSHA512,
8212 signatureRSAPKCS1WithSHA1,
8213 },
8214 },
8215 flags: []string{
8216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8218 "-digest-prefs", "SHA256",
8219 },
8220 shouldFail: true,
8221 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8222 })
8223 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008224 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008226 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008227 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008228 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008229 signatureRSAPKCS1WithSHA512,
8230 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008231 },
8232 },
8233 flags: []string{
8234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008236 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008237 },
David Benjaminca3d5452016-07-14 12:51:01 -04008238 shouldFail: true,
8239 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8240 })
8241 testCases = append(testCases, testCase{
8242 name: "NoCommonAlgorithms-TLS13",
8243 config: Config{
8244 MaxVersion: VersionTLS13,
8245 ClientAuth: RequireAnyClientCert,
8246 VerifySignatureAlgorithms: []signatureAlgorithm{
8247 signatureRSAPSSWithSHA512,
8248 signatureRSAPSSWithSHA384,
8249 },
8250 },
8251 flags: []string{
8252 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8253 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8254 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8255 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008256 shouldFail: true,
8257 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008258 })
8259 testCases = append(testCases, testCase{
8260 name: "Agree-Digest-SHA256",
8261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008262 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008263 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008264 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008265 signatureRSAPKCS1WithSHA1,
8266 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008267 },
8268 },
8269 flags: []string{
8270 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8271 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008272 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008273 },
Nick Harper60edffd2016-06-21 15:19:24 -07008274 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008275 })
8276 testCases = append(testCases, testCase{
8277 name: "Agree-Digest-SHA1",
8278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008279 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008280 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008281 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008282 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008283 },
8284 },
8285 flags: []string{
8286 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8287 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008288 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008289 },
Nick Harper60edffd2016-06-21 15:19:24 -07008290 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008291 })
8292 testCases = append(testCases, testCase{
8293 name: "Agree-Digest-Default",
8294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008295 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008296 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008297 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008298 signatureRSAPKCS1WithSHA256,
8299 signatureECDSAWithP256AndSHA256,
8300 signatureRSAPKCS1WithSHA1,
8301 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008302 },
8303 },
8304 flags: []string{
8305 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8306 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8307 },
Nick Harper60edffd2016-06-21 15:19:24 -07008308 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008309 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008310
David Benjaminca3d5452016-07-14 12:51:01 -04008311 // Test that the signing preference list may include extra algorithms
8312 // without negotiation problems.
8313 testCases = append(testCases, testCase{
8314 testType: serverTest,
8315 name: "FilterExtraAlgorithms",
8316 config: Config{
8317 MaxVersion: VersionTLS12,
8318 VerifySignatureAlgorithms: []signatureAlgorithm{
8319 signatureRSAPKCS1WithSHA256,
8320 },
8321 },
8322 flags: []string{
8323 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8324 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8325 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8326 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8327 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8328 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8329 },
8330 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8331 })
8332
David Benjamin4c3ddf72016-06-29 18:13:53 -04008333 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8334 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008335 testCases = append(testCases, testCase{
8336 name: "CheckLeafCurve",
8337 config: Config{
8338 MaxVersion: VersionTLS12,
8339 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008340 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008341 },
8342 flags: []string{"-p384-only"},
8343 shouldFail: true,
8344 expectedError: ":BAD_ECC_CERT:",
8345 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008346
8347 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8348 testCases = append(testCases, testCase{
8349 name: "CheckLeafCurve-TLS13",
8350 config: Config{
8351 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008352 Certificates: []Certificate{ecdsaP256Certificate},
8353 },
8354 flags: []string{"-p384-only"},
8355 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008356
8357 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8358 testCases = append(testCases, testCase{
8359 name: "ECDSACurveMismatch-Verify-TLS12",
8360 config: Config{
8361 MaxVersion: VersionTLS12,
8362 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8363 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008364 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008365 signatureECDSAWithP384AndSHA384,
8366 },
8367 },
8368 })
8369
8370 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8371 testCases = append(testCases, testCase{
8372 name: "ECDSACurveMismatch-Verify-TLS13",
8373 config: Config{
8374 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008375 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008376 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008377 signatureECDSAWithP384AndSHA384,
8378 },
8379 Bugs: ProtocolBugs{
8380 SkipECDSACurveCheck: true,
8381 },
8382 },
8383 shouldFail: true,
8384 expectedError: ":WRONG_SIGNATURE_TYPE:",
8385 })
8386
8387 // Signature algorithm selection in TLS 1.3 should take the curve into
8388 // account.
8389 testCases = append(testCases, testCase{
8390 testType: serverTest,
8391 name: "ECDSACurveMismatch-Sign-TLS13",
8392 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008393 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008394 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008395 signatureECDSAWithP384AndSHA384,
8396 signatureECDSAWithP256AndSHA256,
8397 },
8398 },
8399 flags: []string{
8400 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8401 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8402 },
8403 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8404 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008405
8406 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8407 // server does not attempt to sign in that case.
8408 testCases = append(testCases, testCase{
8409 testType: serverTest,
8410 name: "RSA-PSS-Large",
8411 config: Config{
8412 MaxVersion: VersionTLS13,
8413 VerifySignatureAlgorithms: []signatureAlgorithm{
8414 signatureRSAPSSWithSHA512,
8415 },
8416 },
8417 flags: []string{
8418 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8419 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8420 },
8421 shouldFail: true,
8422 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8423 })
David Benjamin57e929f2016-08-30 00:30:38 -04008424
8425 // Test that RSA-PSS is enabled by default for TLS 1.2.
8426 testCases = append(testCases, testCase{
8427 testType: clientTest,
8428 name: "RSA-PSS-Default-Verify",
8429 config: Config{
8430 MaxVersion: VersionTLS12,
8431 SignSignatureAlgorithms: []signatureAlgorithm{
8432 signatureRSAPSSWithSHA256,
8433 },
8434 },
8435 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8436 })
8437
8438 testCases = append(testCases, testCase{
8439 testType: serverTest,
8440 name: "RSA-PSS-Default-Sign",
8441 config: Config{
8442 MaxVersion: VersionTLS12,
8443 VerifySignatureAlgorithms: []signatureAlgorithm{
8444 signatureRSAPSSWithSHA256,
8445 },
8446 },
8447 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8448 })
David Benjamin69522112017-03-28 15:38:29 -05008449
8450 // TLS 1.1 and below has no way to advertise support for or negotiate
8451 // Ed25519's signature algorithm.
8452 testCases = append(testCases, testCase{
8453 testType: clientTest,
8454 name: "NoEd25519-TLS11-ServerAuth-Verify",
8455 config: Config{
8456 MaxVersion: VersionTLS11,
8457 Certificates: []Certificate{ed25519Certificate},
8458 Bugs: ProtocolBugs{
8459 // Sign with Ed25519 even though it is TLS 1.1.
8460 UseLegacySigningAlgorithm: signatureEd25519,
8461 },
8462 },
8463 flags: []string{"-enable-ed25519"},
8464 shouldFail: true,
8465 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8466 })
8467 testCases = append(testCases, testCase{
8468 testType: serverTest,
8469 name: "NoEd25519-TLS11-ServerAuth-Sign",
8470 config: Config{
8471 MaxVersion: VersionTLS11,
8472 },
8473 flags: []string{
8474 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8475 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8476 },
8477 shouldFail: true,
8478 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8479 })
8480 testCases = append(testCases, testCase{
8481 testType: serverTest,
8482 name: "NoEd25519-TLS11-ClientAuth-Verify",
8483 config: Config{
8484 MaxVersion: VersionTLS11,
8485 Certificates: []Certificate{ed25519Certificate},
8486 Bugs: ProtocolBugs{
8487 // Sign with Ed25519 even though it is TLS 1.1.
8488 UseLegacySigningAlgorithm: signatureEd25519,
8489 },
8490 },
8491 flags: []string{
8492 "-enable-ed25519",
8493 "-require-any-client-certificate",
8494 },
8495 shouldFail: true,
8496 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8497 })
8498 testCases = append(testCases, testCase{
8499 testType: clientTest,
8500 name: "NoEd25519-TLS11-ClientAuth-Sign",
8501 config: Config{
8502 MaxVersion: VersionTLS11,
8503 ClientAuth: RequireAnyClientCert,
8504 },
8505 flags: []string{
8506 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8507 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8508 },
8509 shouldFail: true,
8510 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8511 })
8512
8513 // Test Ed25519 is not advertised by default.
8514 testCases = append(testCases, testCase{
8515 testType: clientTest,
8516 name: "Ed25519DefaultDisable-NoAdvertise",
8517 config: Config{
8518 Certificates: []Certificate{ed25519Certificate},
8519 },
8520 shouldFail: true,
8521 expectedLocalError: "tls: no common signature algorithms",
8522 })
8523
8524 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8525 // preferences.
8526 testCases = append(testCases, testCase{
8527 testType: clientTest,
8528 name: "Ed25519DefaultDisable-NoAccept",
8529 config: Config{
8530 Certificates: []Certificate{ed25519Certificate},
8531 Bugs: ProtocolBugs{
8532 IgnorePeerSignatureAlgorithmPreferences: true,
8533 },
8534 },
8535 shouldFail: true,
8536 expectedLocalError: "remote error: illegal parameter",
8537 expectedError: ":WRONG_SIGNATURE_TYPE:",
8538 })
David Benjamin71c21b42017-04-14 17:05:40 -04008539
8540 // Test that configuring verify preferences changes what the client
8541 // advertises.
8542 testCases = append(testCases, testCase{
8543 name: "VerifyPreferences-Advertised",
8544 config: Config{
8545 Certificates: []Certificate{rsaCertificate},
8546 SignSignatureAlgorithms: []signatureAlgorithm{
8547 signatureRSAPSSWithSHA256,
8548 signatureRSAPSSWithSHA384,
8549 signatureRSAPSSWithSHA512,
8550 },
8551 },
8552 flags: []string{
8553 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8554 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8555 },
8556 })
8557
8558 // Test that the client advertises a set which the runner can find
8559 // nothing in common with.
8560 testCases = append(testCases, testCase{
8561 name: "VerifyPreferences-NoCommonAlgorithms",
8562 config: Config{
8563 Certificates: []Certificate{rsaCertificate},
8564 SignSignatureAlgorithms: []signatureAlgorithm{
8565 signatureRSAPSSWithSHA256,
8566 signatureRSAPSSWithSHA512,
8567 },
8568 },
8569 flags: []string{
8570 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8571 },
8572 shouldFail: true,
8573 expectedLocalError: "tls: no common signature algorithms",
8574 })
8575
8576 // Test that the client enforces its preferences when configured.
8577 testCases = append(testCases, testCase{
8578 name: "VerifyPreferences-Enforced",
8579 config: Config{
8580 Certificates: []Certificate{rsaCertificate},
8581 SignSignatureAlgorithms: []signatureAlgorithm{
8582 signatureRSAPSSWithSHA256,
8583 signatureRSAPSSWithSHA512,
8584 },
8585 Bugs: ProtocolBugs{
8586 IgnorePeerSignatureAlgorithmPreferences: true,
8587 },
8588 },
8589 flags: []string{
8590 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8591 },
8592 shouldFail: true,
8593 expectedLocalError: "remote error: illegal parameter",
8594 expectedError: ":WRONG_SIGNATURE_TYPE:",
8595 })
8596
8597 // Test that explicitly configuring Ed25519 is as good as changing the
8598 // boolean toggle.
8599 testCases = append(testCases, testCase{
8600 name: "VerifyPreferences-Ed25519",
8601 config: Config{
8602 Certificates: []Certificate{ed25519Certificate},
8603 },
8604 flags: []string{
8605 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8606 },
8607 })
David Benjamin000800a2014-11-14 01:43:59 -05008608}
8609
David Benjamin83f90402015-01-27 01:09:43 -05008610// timeouts is the retransmit schedule for BoringSSL. It doubles and
8611// caps at 60 seconds. On the 13th timeout, it gives up.
8612var timeouts = []time.Duration{
8613 1 * time.Second,
8614 2 * time.Second,
8615 4 * time.Second,
8616 8 * time.Second,
8617 16 * time.Second,
8618 32 * time.Second,
8619 60 * time.Second,
8620 60 * time.Second,
8621 60 * time.Second,
8622 60 * time.Second,
8623 60 * time.Second,
8624 60 * time.Second,
8625 60 * time.Second,
8626}
8627
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008628// shortTimeouts is an alternate set of timeouts which would occur if the
8629// initial timeout duration was set to 250ms.
8630var shortTimeouts = []time.Duration{
8631 250 * time.Millisecond,
8632 500 * time.Millisecond,
8633 1 * time.Second,
8634 2 * time.Second,
8635 4 * time.Second,
8636 8 * time.Second,
8637 16 * time.Second,
8638 32 * time.Second,
8639 60 * time.Second,
8640 60 * time.Second,
8641 60 * time.Second,
8642 60 * time.Second,
8643 60 * time.Second,
8644}
8645
David Benjamin83f90402015-01-27 01:09:43 -05008646func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008647 // These tests work by coordinating some behavior on both the shim and
8648 // the runner.
8649 //
8650 // TimeoutSchedule configures the runner to send a series of timeout
8651 // opcodes to the shim (see packetAdaptor) immediately before reading
8652 // each peer handshake flight N. The timeout opcode both simulates a
8653 // timeout in the shim and acts as a synchronization point to help the
8654 // runner bracket each handshake flight.
8655 //
8656 // We assume the shim does not read from the channel eagerly. It must
8657 // first wait until it has sent flight N and is ready to receive
8658 // handshake flight N+1. At this point, it will process the timeout
8659 // opcode. It must then immediately respond with a timeout ACK and act
8660 // as if the shim was idle for the specified amount of time.
8661 //
8662 // The runner then drops all packets received before the ACK and
8663 // continues waiting for flight N. This ordering results in one attempt
8664 // at sending flight N to be dropped. For the test to complete, the
8665 // shim must send flight N again, testing that the shim implements DTLS
8666 // retransmit on a timeout.
8667
Steven Valdez143e8b32016-07-11 13:19:03 -04008668 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008669 // likely be more epochs to cross and the final message's retransmit may
8670 // be more complex.
8671
David Benjamin11c82892017-02-23 20:40:31 -05008672 // Test that this is indeed the timeout schedule. Stress all
8673 // four patterns of handshake.
8674 for i := 1; i < len(timeouts); i++ {
8675 number := strconv.Itoa(i)
8676 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008677 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008678 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008679 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008680 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008681 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008682 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008683 },
8684 },
8685 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008686 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008687 })
David Benjamin11c82892017-02-23 20:40:31 -05008688 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008689 protocol: dtls,
8690 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008691 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008693 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008694 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008695 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008696 },
8697 },
8698 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008699 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008700 })
8701 }
David Benjamin11c82892017-02-23 20:40:31 -05008702
8703 // Test that exceeding the timeout schedule hits a read
8704 // timeout.
8705 testCases = append(testCases, testCase{
8706 protocol: dtls,
8707 name: "DTLS-Retransmit-Timeout",
8708 config: Config{
8709 MaxVersion: VersionTLS12,
8710 Bugs: ProtocolBugs{
8711 TimeoutSchedule: timeouts,
8712 },
8713 },
8714 resumeSession: true,
8715 flags: []string{"-async"},
8716 shouldFail: true,
8717 expectedError: ":READ_TIMEOUT_EXPIRED:",
8718 })
8719
8720 // Test that timeout handling has a fudge factor, due to API
8721 // problems.
8722 testCases = append(testCases, testCase{
8723 protocol: dtls,
8724 name: "DTLS-Retransmit-Fudge",
8725 config: Config{
8726 MaxVersion: VersionTLS12,
8727 Bugs: ProtocolBugs{
8728 TimeoutSchedule: []time.Duration{
8729 timeouts[0] - 10*time.Millisecond,
8730 },
8731 },
8732 },
8733 resumeSession: true,
8734 flags: []string{"-async"},
8735 })
8736
8737 // Test that the final Finished retransmitting isn't
8738 // duplicated if the peer badly fragments everything.
8739 testCases = append(testCases, testCase{
8740 testType: serverTest,
8741 protocol: dtls,
8742 name: "DTLS-Retransmit-Fragmented",
8743 config: Config{
8744 MaxVersion: VersionTLS12,
8745 Bugs: ProtocolBugs{
8746 TimeoutSchedule: []time.Duration{timeouts[0]},
8747 MaxHandshakeRecordLength: 2,
8748 },
8749 },
8750 flags: []string{"-async"},
8751 })
8752
8753 // Test the timeout schedule when a shorter initial timeout duration is set.
8754 testCases = append(testCases, testCase{
8755 protocol: dtls,
8756 name: "DTLS-Retransmit-Short-Client",
8757 config: Config{
8758 MaxVersion: VersionTLS12,
8759 Bugs: ProtocolBugs{
8760 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8761 },
8762 },
8763 resumeSession: true,
8764 flags: []string{
8765 "-async",
8766 "-initial-timeout-duration-ms", "250",
8767 },
8768 })
8769 testCases = append(testCases, testCase{
8770 protocol: dtls,
8771 testType: serverTest,
8772 name: "DTLS-Retransmit-Short-Server",
8773 config: Config{
8774 MaxVersion: VersionTLS12,
8775 Bugs: ProtocolBugs{
8776 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8777 },
8778 },
8779 resumeSession: true,
8780 flags: []string{
8781 "-async",
8782 "-initial-timeout-duration-ms", "250",
8783 },
8784 })
David Benjamin83f90402015-01-27 01:09:43 -05008785}
8786
David Benjaminc565ebb2015-04-03 04:06:36 -04008787func addExportKeyingMaterialTests() {
8788 for _, vers := range tlsVersions {
8789 if vers.version == VersionSSL30 {
8790 continue
8791 }
8792 testCases = append(testCases, testCase{
8793 name: "ExportKeyingMaterial-" + vers.name,
8794 config: Config{
8795 MaxVersion: vers.version,
8796 },
David Benjamina5022392017-07-10 17:40:39 -04008797 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008798 exportKeyingMaterial: 1024,
8799 exportLabel: "label",
8800 exportContext: "context",
8801 useExportContext: true,
8802 })
8803 testCases = append(testCases, testCase{
8804 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8805 config: Config{
8806 MaxVersion: vers.version,
8807 },
David Benjamina5022392017-07-10 17:40:39 -04008808 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008809 exportKeyingMaterial: 1024,
8810 })
8811 testCases = append(testCases, testCase{
8812 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8813 config: Config{
8814 MaxVersion: vers.version,
8815 },
David Benjamina5022392017-07-10 17:40:39 -04008816 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008817 exportKeyingMaterial: 1024,
8818 useExportContext: true,
8819 })
8820 testCases = append(testCases, testCase{
8821 name: "ExportKeyingMaterial-Small-" + vers.name,
8822 config: Config{
8823 MaxVersion: vers.version,
8824 },
David Benjamina5022392017-07-10 17:40:39 -04008825 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008826 exportKeyingMaterial: 1,
8827 exportLabel: "label",
8828 exportContext: "context",
8829 useExportContext: true,
8830 })
8831 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008832
David Benjaminc565ebb2015-04-03 04:06:36 -04008833 testCases = append(testCases, testCase{
8834 name: "ExportKeyingMaterial-SSL3",
8835 config: Config{
8836 MaxVersion: VersionSSL30,
8837 },
8838 exportKeyingMaterial: 1024,
8839 exportLabel: "label",
8840 exportContext: "context",
8841 useExportContext: true,
8842 shouldFail: true,
8843 expectedError: "failed to export keying material",
8844 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008845
8846 // Exporters work during a False Start.
8847 testCases = append(testCases, testCase{
8848 name: "ExportKeyingMaterial-FalseStart",
8849 config: Config{
8850 MaxVersion: VersionTLS12,
8851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8852 NextProtos: []string{"foo"},
8853 Bugs: ProtocolBugs{
8854 ExpectFalseStart: true,
8855 },
8856 },
8857 flags: []string{
8858 "-false-start",
8859 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008860 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008861 },
8862 shimWritesFirst: true,
8863 exportKeyingMaterial: 1024,
8864 exportLabel: "label",
8865 exportContext: "context",
8866 useExportContext: true,
8867 })
8868
8869 // Exporters do not work in the middle of a renegotiation. Test this by
8870 // triggering the exporter after every SSL_read call and configuring the
8871 // shim to run asynchronously.
8872 testCases = append(testCases, testCase{
8873 name: "ExportKeyingMaterial-Renegotiate",
8874 config: Config{
8875 MaxVersion: VersionTLS12,
8876 },
8877 renegotiate: 1,
8878 flags: []string{
8879 "-async",
8880 "-use-exporter-between-reads",
8881 "-renegotiate-freely",
8882 "-expect-total-renegotiations", "1",
8883 },
8884 shouldFail: true,
8885 expectedError: "failed to export keying material",
8886 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008887}
8888
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008889func addTLSUniqueTests() {
8890 for _, isClient := range []bool{false, true} {
8891 for _, isResumption := range []bool{false, true} {
8892 for _, hasEMS := range []bool{false, true} {
8893 var suffix string
8894 if isResumption {
8895 suffix = "Resume-"
8896 } else {
8897 suffix = "Full-"
8898 }
8899
8900 if hasEMS {
8901 suffix += "EMS-"
8902 } else {
8903 suffix += "NoEMS-"
8904 }
8905
8906 if isClient {
8907 suffix += "Client"
8908 } else {
8909 suffix += "Server"
8910 }
8911
8912 test := testCase{
8913 name: "TLSUnique-" + suffix,
8914 testTLSUnique: true,
8915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008916 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008917 Bugs: ProtocolBugs{
8918 NoExtendedMasterSecret: !hasEMS,
8919 },
8920 },
8921 }
8922
8923 if isResumption {
8924 test.resumeSession = true
8925 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008926 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008927 Bugs: ProtocolBugs{
8928 NoExtendedMasterSecret: !hasEMS,
8929 },
8930 }
8931 }
8932
8933 if isResumption && !hasEMS {
8934 test.shouldFail = true
8935 test.expectedError = "failed to get tls-unique"
8936 }
8937
8938 testCases = append(testCases, test)
8939 }
8940 }
8941 }
8942}
8943
Adam Langley09505632015-07-30 18:10:13 -07008944func addCustomExtensionTests() {
8945 expectedContents := "custom extension"
8946 emptyString := ""
8947
8948 for _, isClient := range []bool{false, true} {
8949 suffix := "Server"
8950 flag := "-enable-server-custom-extension"
8951 testType := serverTest
8952 if isClient {
8953 suffix = "Client"
8954 flag = "-enable-client-custom-extension"
8955 testType = clientTest
8956 }
8957
8958 testCases = append(testCases, testCase{
8959 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008960 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008962 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008963 Bugs: ProtocolBugs{
8964 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008965 ExpectedCustomExtension: &expectedContents,
8966 },
8967 },
8968 flags: []string{flag},
8969 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008970 testCases = append(testCases, testCase{
8971 testType: testType,
8972 name: "CustomExtensions-" + suffix + "-TLS13",
8973 config: Config{
8974 MaxVersion: VersionTLS13,
8975 Bugs: ProtocolBugs{
8976 CustomExtension: expectedContents,
8977 ExpectedCustomExtension: &expectedContents,
8978 },
8979 },
8980 flags: []string{flag},
8981 })
Adam Langley09505632015-07-30 18:10:13 -07008982
8983 // If the parse callback fails, the handshake should also fail.
8984 testCases = append(testCases, testCase{
8985 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008986 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008987 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008988 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008989 Bugs: ProtocolBugs{
8990 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008991 ExpectedCustomExtension: &expectedContents,
8992 },
8993 },
David Benjamin399e7c92015-07-30 23:01:27 -04008994 flags: []string{flag},
8995 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008996 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8997 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008998 testCases = append(testCases, testCase{
8999 testType: testType,
9000 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9001 config: Config{
9002 MaxVersion: VersionTLS13,
9003 Bugs: ProtocolBugs{
9004 CustomExtension: expectedContents + "foo",
9005 ExpectedCustomExtension: &expectedContents,
9006 },
9007 },
9008 flags: []string{flag},
9009 shouldFail: true,
9010 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9011 })
Adam Langley09505632015-07-30 18:10:13 -07009012
9013 // If the add callback fails, the handshake should also fail.
9014 testCases = append(testCases, testCase{
9015 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009016 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009017 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009018 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009019 Bugs: ProtocolBugs{
9020 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009021 ExpectedCustomExtension: &expectedContents,
9022 },
9023 },
David Benjamin399e7c92015-07-30 23:01:27 -04009024 flags: []string{flag, "-custom-extension-fail-add"},
9025 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009026 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9027 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009028 testCases = append(testCases, testCase{
9029 testType: testType,
9030 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9031 config: Config{
9032 MaxVersion: VersionTLS13,
9033 Bugs: ProtocolBugs{
9034 CustomExtension: expectedContents,
9035 ExpectedCustomExtension: &expectedContents,
9036 },
9037 },
9038 flags: []string{flag, "-custom-extension-fail-add"},
9039 shouldFail: true,
9040 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9041 })
Adam Langley09505632015-07-30 18:10:13 -07009042
9043 // If the add callback returns zero, no extension should be
9044 // added.
9045 skipCustomExtension := expectedContents
9046 if isClient {
9047 // For the case where the client skips sending the
9048 // custom extension, the server must not “echo” it.
9049 skipCustomExtension = ""
9050 }
9051 testCases = append(testCases, testCase{
9052 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009053 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009055 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009056 Bugs: ProtocolBugs{
9057 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009058 ExpectedCustomExtension: &emptyString,
9059 },
9060 },
9061 flags: []string{flag, "-custom-extension-skip"},
9062 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009063 testCases = append(testCases, testCase{
9064 testType: testType,
9065 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9066 config: Config{
9067 MaxVersion: VersionTLS13,
9068 Bugs: ProtocolBugs{
9069 CustomExtension: skipCustomExtension,
9070 ExpectedCustomExtension: &emptyString,
9071 },
9072 },
9073 flags: []string{flag, "-custom-extension-skip"},
9074 })
Adam Langley09505632015-07-30 18:10:13 -07009075 }
9076
Steven Valdezf4ecc842017-08-10 14:02:56 -04009077 // If the client sends both early data and custom extension, the handshake
9078 // should succeed as long as both the extensions aren't returned by the
9079 // server.
9080 testCases = append(testCases, testCase{
9081 testType: clientTest,
9082 name: "CustomExtensions-Client-EarlyData-None",
9083 config: Config{
9084 MaxVersion: VersionTLS13,
9085 MaxEarlyDataSize: 16384,
9086 Bugs: ProtocolBugs{
9087 ExpectedCustomExtension: &expectedContents,
9088 AlwaysRejectEarlyData: true,
9089 },
9090 },
9091 resumeSession: true,
9092 flags: []string{
9093 "-enable-client-custom-extension",
9094 "-enable-early-data",
9095 "-expect-early-data-info",
9096 "-expect-reject-early-data",
9097 },
9098 })
9099
9100 testCases = append(testCases, testCase{
9101 testType: clientTest,
9102 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9103 config: Config{
9104 MaxVersion: VersionTLS13,
9105 MaxEarlyDataSize: 16384,
9106 Bugs: ProtocolBugs{
9107 ExpectedCustomExtension: &expectedContents,
9108 },
9109 },
9110 resumeSession: true,
9111 flags: []string{
9112 "-enable-client-custom-extension",
9113 "-enable-early-data",
9114 "-expect-early-data-info",
9115 "-expect-accept-early-data",
9116 },
9117 })
9118
9119 testCases = append(testCases, testCase{
9120 testType: clientTest,
9121 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9122 config: Config{
9123 MaxVersion: VersionTLS13,
9124 MaxEarlyDataSize: 16384,
9125 Bugs: ProtocolBugs{
9126 AlwaysRejectEarlyData: true,
9127 CustomExtension: expectedContents,
9128 ExpectedCustomExtension: &expectedContents,
9129 },
9130 },
9131 resumeSession: true,
9132 flags: []string{
9133 "-enable-client-custom-extension",
9134 "-enable-early-data",
9135 "-expect-early-data-info",
9136 "-expect-reject-early-data",
9137 },
9138 })
9139
9140 testCases = append(testCases, testCase{
9141 testType: clientTest,
9142 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9143 config: Config{
9144 MaxVersion: VersionTLS13,
9145 MaxEarlyDataSize: 16384,
9146 Bugs: ProtocolBugs{
9147 CustomExtension: expectedContents,
9148 ExpectedCustomExtension: &expectedContents,
9149 },
9150 },
9151 resumeConfig: &Config{
9152 MaxVersion: VersionTLS13,
9153 MaxEarlyDataSize: 16384,
9154 Bugs: ProtocolBugs{
9155 CustomExtension: expectedContents,
9156 ExpectedCustomExtension: &expectedContents,
9157 SendEarlyDataExtension: true,
9158 },
9159 },
9160 resumeSession: true,
9161 shouldFail: true,
9162 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9163 flags: []string{
9164 "-enable-client-custom-extension",
9165 "-enable-early-data",
9166 "-expect-early-data-info",
9167 },
9168 })
9169
9170 // If the server receives both early data and custom extension, only the
9171 // custom extension should be accepted.
9172 testCases = append(testCases, testCase{
9173 testType: serverTest,
9174 name: "CustomExtensions-Server-EarlyDataAccepted",
9175 config: Config{
9176 MaxVersion: VersionTLS13,
9177 MaxEarlyDataSize: 16384,
9178 Bugs: ProtocolBugs{
9179 CustomExtension: expectedContents,
9180 ExpectedCustomExtension: &expectedContents,
9181 ExpectEarlyDataAccepted: false,
9182 },
9183 },
9184 resumeSession: true,
9185 flags: []string{
9186 "-enable-server-custom-extension",
9187 "-enable-early-data",
9188 "-expect-early-data-info",
9189 },
9190 })
9191
Adam Langley09505632015-07-30 18:10:13 -07009192 // The custom extension add callback should not be called if the client
9193 // doesn't send the extension.
9194 testCases = append(testCases, testCase{
9195 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009196 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009198 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009199 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009200 ExpectedCustomExtension: &emptyString,
9201 },
9202 },
9203 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9204 })
Adam Langley2deb9842015-08-07 11:15:37 -07009205
Steven Valdez143e8b32016-07-11 13:19:03 -04009206 testCases = append(testCases, testCase{
9207 testType: serverTest,
9208 name: "CustomExtensions-NotCalled-Server-TLS13",
9209 config: Config{
9210 MaxVersion: VersionTLS13,
9211 Bugs: ProtocolBugs{
9212 ExpectedCustomExtension: &emptyString,
9213 },
9214 },
9215 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9216 })
9217
Adam Langley2deb9842015-08-07 11:15:37 -07009218 // Test an unknown extension from the server.
9219 testCases = append(testCases, testCase{
9220 testType: clientTest,
9221 name: "UnknownExtension-Client",
9222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009223 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009224 Bugs: ProtocolBugs{
9225 CustomExtension: expectedContents,
9226 },
9227 },
David Benjamin0c40a962016-08-01 12:05:50 -04009228 shouldFail: true,
9229 expectedError: ":UNEXPECTED_EXTENSION:",
9230 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009231 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009232 testCases = append(testCases, testCase{
9233 testType: clientTest,
9234 name: "UnknownExtension-Client-TLS13",
9235 config: Config{
9236 MaxVersion: VersionTLS13,
9237 Bugs: ProtocolBugs{
9238 CustomExtension: expectedContents,
9239 },
9240 },
David Benjamin0c40a962016-08-01 12:05:50 -04009241 shouldFail: true,
9242 expectedError: ":UNEXPECTED_EXTENSION:",
9243 expectedLocalError: "remote error: unsupported extension",
9244 })
David Benjamin490469f2016-10-05 22:44:38 -04009245 testCases = append(testCases, testCase{
9246 testType: clientTest,
9247 name: "UnknownUnencryptedExtension-Client-TLS13",
9248 config: Config{
9249 MaxVersion: VersionTLS13,
9250 Bugs: ProtocolBugs{
9251 CustomUnencryptedExtension: expectedContents,
9252 },
9253 },
9254 shouldFail: true,
9255 expectedError: ":UNEXPECTED_EXTENSION:",
9256 // The shim must send an alert, but alerts at this point do not
9257 // get successfully decrypted by the runner.
9258 expectedLocalError: "local error: bad record MAC",
9259 })
9260 testCases = append(testCases, testCase{
9261 testType: clientTest,
9262 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9263 config: Config{
9264 MaxVersion: VersionTLS13,
9265 Bugs: ProtocolBugs{
9266 SendUnencryptedALPN: "foo",
9267 },
9268 },
9269 flags: []string{
9270 "-advertise-alpn", "\x03foo\x03bar",
9271 },
9272 shouldFail: true,
9273 expectedError: ":UNEXPECTED_EXTENSION:",
9274 // The shim must send an alert, but alerts at this point do not
9275 // get successfully decrypted by the runner.
9276 expectedLocalError: "local error: bad record MAC",
9277 })
David Benjamin0c40a962016-08-01 12:05:50 -04009278
9279 // Test a known but unoffered extension from the server.
9280 testCases = append(testCases, testCase{
9281 testType: clientTest,
9282 name: "UnofferedExtension-Client",
9283 config: Config{
9284 MaxVersion: VersionTLS12,
9285 Bugs: ProtocolBugs{
9286 SendALPN: "alpn",
9287 },
9288 },
9289 shouldFail: true,
9290 expectedError: ":UNEXPECTED_EXTENSION:",
9291 expectedLocalError: "remote error: unsupported extension",
9292 })
9293 testCases = append(testCases, testCase{
9294 testType: clientTest,
9295 name: "UnofferedExtension-Client-TLS13",
9296 config: Config{
9297 MaxVersion: VersionTLS13,
9298 Bugs: ProtocolBugs{
9299 SendALPN: "alpn",
9300 },
9301 },
9302 shouldFail: true,
9303 expectedError: ":UNEXPECTED_EXTENSION:",
9304 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009305 })
Adam Langley09505632015-07-30 18:10:13 -07009306}
9307
David Benjaminb36a3952015-12-01 18:53:13 -05009308func addRSAClientKeyExchangeTests() {
9309 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9310 testCases = append(testCases, testCase{
9311 testType: serverTest,
9312 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9313 config: Config{
9314 // Ensure the ClientHello version and final
9315 // version are different, to detect if the
9316 // server uses the wrong one.
9317 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009318 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009319 Bugs: ProtocolBugs{
9320 BadRSAClientKeyExchange: bad,
9321 },
9322 },
9323 shouldFail: true,
9324 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9325 })
9326 }
David Benjamine63d9d72016-09-19 18:27:34 -04009327
9328 // The server must compare whatever was in ClientHello.version for the
9329 // RSA premaster.
9330 testCases = append(testCases, testCase{
9331 testType: serverTest,
9332 name: "SendClientVersion-RSA",
9333 config: Config{
9334 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9335 Bugs: ProtocolBugs{
9336 SendClientVersion: 0x1234,
9337 },
9338 },
9339 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9340 })
David Benjaminb36a3952015-12-01 18:53:13 -05009341}
9342
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009343var testCurves = []struct {
9344 name string
9345 id CurveID
9346}{
Adam Langley764ab982017-03-10 18:01:30 -08009347 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009348 {"P-256", CurveP256},
9349 {"P-384", CurveP384},
9350 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009351 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009352}
9353
Steven Valdez5440fe02016-07-18 12:40:30 -04009354const bogusCurve = 0x1234
9355
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009356func addCurveTests() {
9357 for _, curve := range testCurves {
9358 testCases = append(testCases, testCase{
9359 name: "CurveTest-Client-" + curve.name,
9360 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009361 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009362 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9363 CurvePreferences: []CurveID{curve.id},
9364 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009365 flags: []string{
9366 "-enable-all-curves",
9367 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9368 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009369 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009370 })
9371 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009372 name: "CurveTest-Client-" + curve.name + "-TLS13",
9373 config: Config{
9374 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009375 CurvePreferences: []CurveID{curve.id},
9376 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009377 flags: []string{
9378 "-enable-all-curves",
9379 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9380 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009381 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009382 })
9383 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009384 testType: serverTest,
9385 name: "CurveTest-Server-" + curve.name,
9386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009387 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009388 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9389 CurvePreferences: []CurveID{curve.id},
9390 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009391 flags: []string{
9392 "-enable-all-curves",
9393 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9394 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009395 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009396 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009397 testCases = append(testCases, testCase{
9398 testType: serverTest,
9399 name: "CurveTest-Server-" + curve.name + "-TLS13",
9400 config: Config{
9401 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009402 CurvePreferences: []CurveID{curve.id},
9403 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009404 flags: []string{
9405 "-enable-all-curves",
9406 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9407 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009408 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009409 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009410 }
David Benjamin241ae832016-01-15 03:04:54 -05009411
9412 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009413 testCases = append(testCases, testCase{
9414 testType: serverTest,
9415 name: "UnknownCurve",
9416 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009417 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9419 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9420 },
9421 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009422
Steven Valdez803c77a2016-09-06 14:13:43 -04009423 // The server must be tolerant to bogus curves.
9424 testCases = append(testCases, testCase{
9425 testType: serverTest,
9426 name: "UnknownCurve-TLS13",
9427 config: Config{
9428 MaxVersion: VersionTLS13,
9429 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9430 },
9431 })
9432
David Benjamin4c3ddf72016-06-29 18:13:53 -04009433 // The server must not consider ECDHE ciphers when there are no
9434 // supported curves.
9435 testCases = append(testCases, testCase{
9436 testType: serverTest,
9437 name: "NoSupportedCurves",
9438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009439 MaxVersion: VersionTLS12,
9440 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9441 Bugs: ProtocolBugs{
9442 NoSupportedCurves: true,
9443 },
9444 },
9445 shouldFail: true,
9446 expectedError: ":NO_SHARED_CIPHER:",
9447 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009448 testCases = append(testCases, testCase{
9449 testType: serverTest,
9450 name: "NoSupportedCurves-TLS13",
9451 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009452 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009453 Bugs: ProtocolBugs{
9454 NoSupportedCurves: true,
9455 },
9456 },
9457 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009458 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009459 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009460
9461 // The server must fall back to another cipher when there are no
9462 // supported curves.
9463 testCases = append(testCases, testCase{
9464 testType: serverTest,
9465 name: "NoCommonCurves",
9466 config: Config{
9467 MaxVersion: VersionTLS12,
9468 CipherSuites: []uint16{
9469 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009470 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009471 },
9472 CurvePreferences: []CurveID{CurveP224},
9473 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009474 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009475 })
9476
9477 // The client must reject bogus curves and disabled curves.
9478 testCases = append(testCases, testCase{
9479 name: "BadECDHECurve",
9480 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009481 MaxVersion: VersionTLS12,
9482 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9483 Bugs: ProtocolBugs{
9484 SendCurve: bogusCurve,
9485 },
9486 },
9487 shouldFail: true,
9488 expectedError: ":WRONG_CURVE:",
9489 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009490 testCases = append(testCases, testCase{
9491 name: "BadECDHECurve-TLS13",
9492 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009493 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009494 Bugs: ProtocolBugs{
9495 SendCurve: bogusCurve,
9496 },
9497 },
9498 shouldFail: true,
9499 expectedError: ":WRONG_CURVE:",
9500 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009501
9502 testCases = append(testCases, testCase{
9503 name: "UnsupportedCurve",
9504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009505 MaxVersion: VersionTLS12,
9506 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9507 CurvePreferences: []CurveID{CurveP256},
9508 Bugs: ProtocolBugs{
9509 IgnorePeerCurvePreferences: true,
9510 },
9511 },
9512 flags: []string{"-p384-only"},
9513 shouldFail: true,
9514 expectedError: ":WRONG_CURVE:",
9515 })
9516
David Benjamin4f921572016-07-17 14:20:10 +02009517 testCases = append(testCases, testCase{
9518 // TODO(davidben): Add a TLS 1.3 version where
9519 // HelloRetryRequest requests an unsupported curve.
9520 name: "UnsupportedCurve-ServerHello-TLS13",
9521 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009522 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009523 CurvePreferences: []CurveID{CurveP384},
9524 Bugs: ProtocolBugs{
9525 SendCurve: CurveP256,
9526 },
9527 },
9528 flags: []string{"-p384-only"},
9529 shouldFail: true,
9530 expectedError: ":WRONG_CURVE:",
9531 })
9532
David Benjamin4c3ddf72016-06-29 18:13:53 -04009533 // Test invalid curve points.
9534 testCases = append(testCases, testCase{
9535 name: "InvalidECDHPoint-Client",
9536 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009537 MaxVersion: VersionTLS12,
9538 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9539 CurvePreferences: []CurveID{CurveP256},
9540 Bugs: ProtocolBugs{
9541 InvalidECDHPoint: true,
9542 },
9543 },
9544 shouldFail: true,
9545 expectedError: ":INVALID_ENCODING:",
9546 })
9547 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009548 name: "InvalidECDHPoint-Client-TLS13",
9549 config: Config{
9550 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009551 CurvePreferences: []CurveID{CurveP256},
9552 Bugs: ProtocolBugs{
9553 InvalidECDHPoint: true,
9554 },
9555 },
9556 shouldFail: true,
9557 expectedError: ":INVALID_ENCODING:",
9558 })
9559 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009560 testType: serverTest,
9561 name: "InvalidECDHPoint-Server",
9562 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009563 MaxVersion: VersionTLS12,
9564 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9565 CurvePreferences: []CurveID{CurveP256},
9566 Bugs: ProtocolBugs{
9567 InvalidECDHPoint: true,
9568 },
9569 },
9570 shouldFail: true,
9571 expectedError: ":INVALID_ENCODING:",
9572 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009573 testCases = append(testCases, testCase{
9574 testType: serverTest,
9575 name: "InvalidECDHPoint-Server-TLS13",
9576 config: Config{
9577 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009578 CurvePreferences: []CurveID{CurveP256},
9579 Bugs: ProtocolBugs{
9580 InvalidECDHPoint: true,
9581 },
9582 },
9583 shouldFail: true,
9584 expectedError: ":INVALID_ENCODING:",
9585 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009586
9587 // The previous curve ID should be reported on TLS 1.2 resumption.
9588 testCases = append(testCases, testCase{
9589 name: "CurveID-Resume-Client",
9590 config: Config{
9591 MaxVersion: VersionTLS12,
9592 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9593 CurvePreferences: []CurveID{CurveX25519},
9594 },
9595 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9596 resumeSession: true,
9597 })
9598 testCases = append(testCases, testCase{
9599 testType: serverTest,
9600 name: "CurveID-Resume-Server",
9601 config: Config{
9602 MaxVersion: VersionTLS12,
9603 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9604 CurvePreferences: []CurveID{CurveX25519},
9605 },
9606 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9607 resumeSession: true,
9608 })
9609
9610 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9611 // one should be reported.
9612 testCases = append(testCases, testCase{
9613 name: "CurveID-Resume-Client-TLS13",
9614 config: Config{
9615 MaxVersion: VersionTLS13,
9616 CurvePreferences: []CurveID{CurveX25519},
9617 },
9618 resumeConfig: &Config{
9619 MaxVersion: VersionTLS13,
9620 CurvePreferences: []CurveID{CurveP256},
9621 },
9622 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009623 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9624 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009625 },
9626 resumeSession: true,
9627 })
9628 testCases = append(testCases, testCase{
9629 testType: serverTest,
9630 name: "CurveID-Resume-Server-TLS13",
9631 config: Config{
9632 MaxVersion: VersionTLS13,
9633 CurvePreferences: []CurveID{CurveX25519},
9634 },
9635 resumeConfig: &Config{
9636 MaxVersion: VersionTLS13,
9637 CurvePreferences: []CurveID{CurveP256},
9638 },
9639 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009640 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9641 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009642 },
9643 resumeSession: true,
9644 })
David Benjamina81967b2016-12-22 09:16:57 -05009645
9646 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9647 testCases = append(testCases, testCase{
9648 name: "PointFormat-ServerHello-TLS12",
9649 config: Config{
9650 MaxVersion: VersionTLS12,
9651 Bugs: ProtocolBugs{
9652 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9653 },
9654 },
9655 })
9656 testCases = append(testCases, testCase{
9657 name: "PointFormat-EncryptedExtensions-TLS13",
9658 config: Config{
9659 MaxVersion: VersionTLS13,
9660 Bugs: ProtocolBugs{
9661 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9662 },
9663 },
9664 shouldFail: true,
9665 expectedError: ":ERROR_PARSING_EXTENSION:",
9666 })
9667
9668 // Test that we tolerate unknown point formats, as long as
9669 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9670 // check they are still functional.
9671 testCases = append(testCases, testCase{
9672 name: "PointFormat-Client-Tolerance",
9673 config: Config{
9674 MaxVersion: VersionTLS12,
9675 Bugs: ProtocolBugs{
9676 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9677 },
9678 },
9679 })
9680 testCases = append(testCases, testCase{
9681 testType: serverTest,
9682 name: "PointFormat-Server-Tolerance",
9683 config: Config{
9684 MaxVersion: VersionTLS12,
9685 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9686 Bugs: ProtocolBugs{
9687 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9688 },
9689 },
9690 })
9691
9692 // Test TLS 1.2 does not require the point format extension to be
9693 // present.
9694 testCases = append(testCases, testCase{
9695 name: "PointFormat-Client-Missing",
9696 config: Config{
9697 MaxVersion: VersionTLS12,
9698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9699 Bugs: ProtocolBugs{
9700 SendSupportedPointFormats: []byte{},
9701 },
9702 },
9703 })
9704 testCases = append(testCases, testCase{
9705 testType: serverTest,
9706 name: "PointFormat-Server-Missing",
9707 config: Config{
9708 MaxVersion: VersionTLS12,
9709 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9710 Bugs: ProtocolBugs{
9711 SendSupportedPointFormats: []byte{},
9712 },
9713 },
9714 })
9715
9716 // If the point format extension is present, uncompressed points must be
9717 // offered. BoringSSL requires this whether or not ECDHE is used.
9718 testCases = append(testCases, testCase{
9719 name: "PointFormat-Client-MissingUncompressed",
9720 config: Config{
9721 MaxVersion: VersionTLS12,
9722 Bugs: ProtocolBugs{
9723 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9724 },
9725 },
9726 shouldFail: true,
9727 expectedError: ":ERROR_PARSING_EXTENSION:",
9728 })
9729 testCases = append(testCases, testCase{
9730 testType: serverTest,
9731 name: "PointFormat-Server-MissingUncompressed",
9732 config: Config{
9733 MaxVersion: VersionTLS12,
9734 Bugs: ProtocolBugs{
9735 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9736 },
9737 },
9738 shouldFail: true,
9739 expectedError: ":ERROR_PARSING_EXTENSION:",
9740 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009741}
9742
David Benjaminc9ae27c2016-06-24 22:56:37 -04009743func addTLS13RecordTests() {
9744 testCases = append(testCases, testCase{
9745 name: "TLS13-RecordPadding",
9746 config: Config{
9747 MaxVersion: VersionTLS13,
9748 MinVersion: VersionTLS13,
9749 Bugs: ProtocolBugs{
9750 RecordPadding: 10,
9751 },
9752 },
9753 })
9754
9755 testCases = append(testCases, testCase{
9756 name: "TLS13-EmptyRecords",
9757 config: Config{
9758 MaxVersion: VersionTLS13,
9759 MinVersion: VersionTLS13,
9760 Bugs: ProtocolBugs{
9761 OmitRecordContents: true,
9762 },
9763 },
9764 shouldFail: true,
9765 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9766 })
9767
9768 testCases = append(testCases, testCase{
9769 name: "TLS13-OnlyPadding",
9770 config: Config{
9771 MaxVersion: VersionTLS13,
9772 MinVersion: VersionTLS13,
9773 Bugs: ProtocolBugs{
9774 OmitRecordContents: true,
9775 RecordPadding: 10,
9776 },
9777 },
9778 shouldFail: true,
9779 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9780 })
9781
9782 testCases = append(testCases, testCase{
9783 name: "TLS13-WrongOuterRecord",
9784 config: Config{
9785 MaxVersion: VersionTLS13,
9786 MinVersion: VersionTLS13,
9787 Bugs: ProtocolBugs{
9788 OuterRecordType: recordTypeHandshake,
9789 },
9790 },
9791 shouldFail: true,
9792 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9793 })
9794}
9795
Steven Valdez5b986082016-09-01 12:29:49 -04009796func addSessionTicketTests() {
9797 testCases = append(testCases, testCase{
9798 // In TLS 1.2 and below, empty NewSessionTicket messages
9799 // mean the server changed its mind on sending a ticket.
9800 name: "SendEmptySessionTicket",
9801 config: Config{
9802 MaxVersion: VersionTLS12,
9803 Bugs: ProtocolBugs{
9804 SendEmptySessionTicket: true,
9805 },
9806 },
9807 flags: []string{"-expect-no-session"},
9808 })
9809
9810 // Test that the server ignores unknown PSK modes.
9811 testCases = append(testCases, testCase{
9812 testType: serverTest,
9813 name: "TLS13-SendUnknownModeSessionTicket-Server",
9814 config: Config{
9815 MaxVersion: VersionTLS13,
9816 Bugs: ProtocolBugs{
9817 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009818 },
9819 },
9820 resumeSession: true,
9821 expectedResumeVersion: VersionTLS13,
9822 })
9823
Steven Valdeza833c352016-11-01 13:39:36 -04009824 // Test that the server does not send session tickets with no matching key exchange mode.
9825 testCases = append(testCases, testCase{
9826 testType: serverTest,
9827 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9828 config: Config{
9829 MaxVersion: VersionTLS13,
9830 Bugs: ProtocolBugs{
9831 SendPSKKeyExchangeModes: []byte{0x1a},
9832 ExpectNoNewSessionTicket: true,
9833 },
9834 },
9835 })
9836
9837 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009838 testCases = append(testCases, testCase{
9839 testType: serverTest,
9840 name: "TLS13-SendBadKEModeSessionTicket-Server",
9841 config: Config{
9842 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009843 },
9844 resumeConfig: &Config{
9845 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009846 Bugs: ProtocolBugs{
9847 SendPSKKeyExchangeModes: []byte{0x1a},
9848 },
9849 },
9850 resumeSession: true,
9851 expectResumeRejected: true,
9852 })
9853
Steven Valdeza833c352016-11-01 13:39:36 -04009854 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009855 testCases = append(testCases, testCase{
9856 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009857 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009858 config: Config{
9859 MaxVersion: VersionTLS13,
9860 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009861 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009862 },
9863 },
Steven Valdeza833c352016-11-01 13:39:36 -04009864 resumeSession: true,
9865 flags: []string{
9866 "-resumption-delay", "10",
9867 },
Steven Valdez5b986082016-09-01 12:29:49 -04009868 })
9869
Steven Valdeza833c352016-11-01 13:39:36 -04009870 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009871 testCases = append(testCases, testCase{
9872 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009873 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009874 config: Config{
9875 MaxVersion: VersionTLS13,
9876 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009877 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009878 },
9879 },
Steven Valdeza833c352016-11-01 13:39:36 -04009880 resumeSession: true,
9881 shouldFail: true,
9882 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009883 })
9884
David Benjamin35ac5b72017-03-03 15:05:56 -05009885 // Test that the server's ticket age skew reporting works.
9886 testCases = append(testCases, testCase{
9887 testType: serverTest,
9888 name: "TLS13-TicketAgeSkew-Forward",
9889 config: Config{
9890 MaxVersion: VersionTLS13,
9891 Bugs: ProtocolBugs{
9892 SendTicketAge: 15 * time.Second,
9893 },
9894 },
David Benjamin065d7332017-03-26 10:51:43 -05009895 resumeSession: true,
9896 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009897 flags: []string{
9898 "-resumption-delay", "10",
9899 "-expect-ticket-age-skew", "5",
9900 },
9901 })
9902 testCases = append(testCases, testCase{
9903 testType: serverTest,
9904 name: "TLS13-TicketAgeSkew-Backward",
9905 config: Config{
9906 MaxVersion: VersionTLS13,
9907 Bugs: ProtocolBugs{
9908 SendTicketAge: 5 * time.Second,
9909 },
9910 },
David Benjamin065d7332017-03-26 10:51:43 -05009911 resumeSession: true,
9912 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009913 flags: []string{
9914 "-resumption-delay", "10",
9915 "-expect-ticket-age-skew", "-5",
9916 },
9917 })
9918
Steven Valdez08b65f42016-12-07 15:29:45 -05009919 testCases = append(testCases, testCase{
9920 testType: clientTest,
9921 name: "TLS13-SendTicketEarlyDataInfo",
9922 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009923 MaxVersion: VersionTLS13,
9924 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009925 },
9926 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009927 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009928 "-expect-early-data-info",
9929 },
9930 })
9931
David Benjamin9b160662017-01-25 19:53:43 -05009932 // Test that 0-RTT tickets are ignored in clients unless opted in.
9933 testCases = append(testCases, testCase{
9934 testType: clientTest,
9935 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9936 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009937 MaxVersion: VersionTLS13,
9938 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009939 },
9940 })
9941
Steven Valdez08b65f42016-12-07 15:29:45 -05009942 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009943 testType: clientTest,
9944 name: "TLS13-DuplicateTicketEarlyDataInfo",
9945 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009946 MaxVersion: VersionTLS13,
9947 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009948 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009949 DuplicateTicketEarlyDataInfo: true,
9950 },
9951 },
9952 shouldFail: true,
9953 expectedError: ":DUPLICATE_EXTENSION:",
9954 expectedLocalError: "remote error: illegal parameter",
9955 })
9956
9957 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009958 testType: serverTest,
9959 name: "TLS13-ExpectTicketEarlyDataInfo",
9960 config: Config{
9961 MaxVersion: VersionTLS13,
9962 Bugs: ProtocolBugs{
9963 ExpectTicketEarlyDataInfo: true,
9964 },
9965 },
9966 flags: []string{
9967 "-enable-early-data",
9968 },
9969 })
David Benjamin17b30832017-01-28 14:00:32 -05009970
9971 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9972 // is honored.
9973 testCases = append(testCases, testCase{
9974 testType: clientTest,
9975 name: "TLS13-HonorServerSessionTicketLifetime",
9976 config: Config{
9977 MaxVersion: VersionTLS13,
9978 Bugs: ProtocolBugs{
9979 SendTicketLifetime: 20 * time.Second,
9980 },
9981 },
9982 flags: []string{
9983 "-resumption-delay", "19",
9984 },
9985 resumeSession: true,
9986 })
9987 testCases = append(testCases, testCase{
9988 testType: clientTest,
9989 name: "TLS13-HonorServerSessionTicketLifetime-2",
9990 config: Config{
9991 MaxVersion: VersionTLS13,
9992 Bugs: ProtocolBugs{
9993 SendTicketLifetime: 20 * time.Second,
9994 // The client should not offer the expired session.
9995 ExpectNoTLS13PSK: true,
9996 },
9997 },
9998 flags: []string{
9999 "-resumption-delay", "21",
10000 },
David Benjamin023d4192017-02-06 13:49:07 -050010001 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -050010002 expectResumeRejected: true,
10003 })
Steven Valdez5b986082016-09-01 12:29:49 -040010004}
10005
David Benjamin82261be2016-07-07 14:32:50 -070010006func addChangeCipherSpecTests() {
10007 // Test missing ChangeCipherSpecs.
10008 testCases = append(testCases, testCase{
10009 name: "SkipChangeCipherSpec-Client",
10010 config: Config{
10011 MaxVersion: VersionTLS12,
10012 Bugs: ProtocolBugs{
10013 SkipChangeCipherSpec: true,
10014 },
10015 },
10016 shouldFail: true,
10017 expectedError: ":UNEXPECTED_RECORD:",
10018 })
10019 testCases = append(testCases, testCase{
10020 testType: serverTest,
10021 name: "SkipChangeCipherSpec-Server",
10022 config: Config{
10023 MaxVersion: VersionTLS12,
10024 Bugs: ProtocolBugs{
10025 SkipChangeCipherSpec: true,
10026 },
10027 },
10028 shouldFail: true,
10029 expectedError: ":UNEXPECTED_RECORD:",
10030 })
10031 testCases = append(testCases, testCase{
10032 testType: serverTest,
10033 name: "SkipChangeCipherSpec-Server-NPN",
10034 config: Config{
10035 MaxVersion: VersionTLS12,
10036 NextProtos: []string{"bar"},
10037 Bugs: ProtocolBugs{
10038 SkipChangeCipherSpec: true,
10039 },
10040 },
10041 flags: []string{
10042 "-advertise-npn", "\x03foo\x03bar\x03baz",
10043 },
10044 shouldFail: true,
10045 expectedError: ":UNEXPECTED_RECORD:",
10046 })
10047
10048 // Test synchronization between the handshake and ChangeCipherSpec.
10049 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10050 // rejected. Test both with and without handshake packing to handle both
10051 // when the partial post-CCS message is in its own record and when it is
10052 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010053 for _, packed := range []bool{false, true} {
10054 var suffix string
10055 if packed {
10056 suffix = "-Packed"
10057 }
10058
10059 testCases = append(testCases, testCase{
10060 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10061 config: Config{
10062 MaxVersion: VersionTLS12,
10063 Bugs: ProtocolBugs{
10064 FragmentAcrossChangeCipherSpec: true,
10065 PackHandshakeFlight: packed,
10066 },
10067 },
10068 shouldFail: true,
10069 expectedError: ":UNEXPECTED_RECORD:",
10070 })
10071 testCases = append(testCases, testCase{
10072 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10073 config: Config{
10074 MaxVersion: VersionTLS12,
10075 },
10076 resumeSession: true,
10077 resumeConfig: &Config{
10078 MaxVersion: VersionTLS12,
10079 Bugs: ProtocolBugs{
10080 FragmentAcrossChangeCipherSpec: true,
10081 PackHandshakeFlight: packed,
10082 },
10083 },
10084 shouldFail: true,
10085 expectedError: ":UNEXPECTED_RECORD:",
10086 })
10087 testCases = append(testCases, testCase{
10088 testType: serverTest,
10089 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10090 config: Config{
10091 MaxVersion: VersionTLS12,
10092 Bugs: ProtocolBugs{
10093 FragmentAcrossChangeCipherSpec: true,
10094 PackHandshakeFlight: packed,
10095 },
10096 },
10097 shouldFail: true,
10098 expectedError: ":UNEXPECTED_RECORD:",
10099 })
10100 testCases = append(testCases, testCase{
10101 testType: serverTest,
10102 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10103 config: Config{
10104 MaxVersion: VersionTLS12,
10105 },
10106 resumeSession: true,
10107 resumeConfig: &Config{
10108 MaxVersion: VersionTLS12,
10109 Bugs: ProtocolBugs{
10110 FragmentAcrossChangeCipherSpec: true,
10111 PackHandshakeFlight: packed,
10112 },
10113 },
10114 shouldFail: true,
10115 expectedError: ":UNEXPECTED_RECORD:",
10116 })
10117 testCases = append(testCases, testCase{
10118 testType: serverTest,
10119 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10120 config: Config{
10121 MaxVersion: VersionTLS12,
10122 NextProtos: []string{"bar"},
10123 Bugs: ProtocolBugs{
10124 FragmentAcrossChangeCipherSpec: true,
10125 PackHandshakeFlight: packed,
10126 },
10127 },
10128 flags: []string{
10129 "-advertise-npn", "\x03foo\x03bar\x03baz",
10130 },
10131 shouldFail: true,
10132 expectedError: ":UNEXPECTED_RECORD:",
10133 })
10134 }
10135
David Benjamin61672812016-07-14 23:10:43 -040010136 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10137 // messages in the handshake queue. Do this by testing the server
10138 // reading the client Finished, reversing the flight so Finished comes
10139 // first.
10140 testCases = append(testCases, testCase{
10141 protocol: dtls,
10142 testType: serverTest,
10143 name: "SendUnencryptedFinished-DTLS",
10144 config: Config{
10145 MaxVersion: VersionTLS12,
10146 Bugs: ProtocolBugs{
10147 SendUnencryptedFinished: true,
10148 ReverseHandshakeFragments: true,
10149 },
10150 },
10151 shouldFail: true,
10152 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10153 })
10154
Steven Valdez143e8b32016-07-11 13:19:03 -040010155 // Test synchronization between encryption changes and the handshake in
10156 // TLS 1.3, where ChangeCipherSpec is implicit.
10157 testCases = append(testCases, testCase{
10158 name: "PartialEncryptedExtensionsWithServerHello",
10159 config: Config{
10160 MaxVersion: VersionTLS13,
10161 Bugs: ProtocolBugs{
10162 PartialEncryptedExtensionsWithServerHello: true,
10163 },
10164 },
10165 shouldFail: true,
10166 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10167 })
10168 testCases = append(testCases, testCase{
10169 testType: serverTest,
10170 name: "PartialClientFinishedWithClientHello",
10171 config: Config{
10172 MaxVersion: VersionTLS13,
10173 Bugs: ProtocolBugs{
10174 PartialClientFinishedWithClientHello: true,
10175 },
10176 },
10177 shouldFail: true,
10178 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10179 })
10180
David Benjamin82261be2016-07-07 14:32:50 -070010181 // Test that early ChangeCipherSpecs are handled correctly.
10182 testCases = append(testCases, testCase{
10183 testType: serverTest,
10184 name: "EarlyChangeCipherSpec-server-1",
10185 config: Config{
10186 MaxVersion: VersionTLS12,
10187 Bugs: ProtocolBugs{
10188 EarlyChangeCipherSpec: 1,
10189 },
10190 },
10191 shouldFail: true,
10192 expectedError: ":UNEXPECTED_RECORD:",
10193 })
10194 testCases = append(testCases, testCase{
10195 testType: serverTest,
10196 name: "EarlyChangeCipherSpec-server-2",
10197 config: Config{
10198 MaxVersion: VersionTLS12,
10199 Bugs: ProtocolBugs{
10200 EarlyChangeCipherSpec: 2,
10201 },
10202 },
10203 shouldFail: true,
10204 expectedError: ":UNEXPECTED_RECORD:",
10205 })
10206 testCases = append(testCases, testCase{
10207 protocol: dtls,
10208 name: "StrayChangeCipherSpec",
10209 config: Config{
10210 // TODO(davidben): Once DTLS 1.3 exists, test
10211 // that stray ChangeCipherSpec messages are
10212 // rejected.
10213 MaxVersion: VersionTLS12,
10214 Bugs: ProtocolBugs{
10215 StrayChangeCipherSpec: true,
10216 },
10217 },
10218 })
10219
David Benjaminb0c761e2017-06-25 22:42:55 -040010220 // Test that reordered ChangeCipherSpecs are tolerated.
10221 testCases = append(testCases, testCase{
10222 protocol: dtls,
10223 name: "ReorderChangeCipherSpec-DTLS-Client",
10224 config: Config{
10225 MaxVersion: VersionTLS12,
10226 Bugs: ProtocolBugs{
10227 ReorderChangeCipherSpec: true,
10228 },
10229 },
10230 resumeSession: true,
10231 })
10232 testCases = append(testCases, testCase{
10233 testType: serverTest,
10234 protocol: dtls,
10235 name: "ReorderChangeCipherSpec-DTLS-Server",
10236 config: Config{
10237 MaxVersion: VersionTLS12,
10238 Bugs: ProtocolBugs{
10239 ReorderChangeCipherSpec: true,
10240 },
10241 },
10242 resumeSession: true,
10243 })
10244
David Benjamin82261be2016-07-07 14:32:50 -070010245 // Test that the contents of ChangeCipherSpec are checked.
10246 testCases = append(testCases, testCase{
10247 name: "BadChangeCipherSpec-1",
10248 config: Config{
10249 MaxVersion: VersionTLS12,
10250 Bugs: ProtocolBugs{
10251 BadChangeCipherSpec: []byte{2},
10252 },
10253 },
10254 shouldFail: true,
10255 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10256 })
10257 testCases = append(testCases, testCase{
10258 name: "BadChangeCipherSpec-2",
10259 config: Config{
10260 MaxVersion: VersionTLS12,
10261 Bugs: ProtocolBugs{
10262 BadChangeCipherSpec: []byte{1, 1},
10263 },
10264 },
10265 shouldFail: true,
10266 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10267 })
10268 testCases = append(testCases, testCase{
10269 protocol: dtls,
10270 name: "BadChangeCipherSpec-DTLS-1",
10271 config: Config{
10272 MaxVersion: VersionTLS12,
10273 Bugs: ProtocolBugs{
10274 BadChangeCipherSpec: []byte{2},
10275 },
10276 },
10277 shouldFail: true,
10278 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10279 })
10280 testCases = append(testCases, testCase{
10281 protocol: dtls,
10282 name: "BadChangeCipherSpec-DTLS-2",
10283 config: Config{
10284 MaxVersion: VersionTLS12,
10285 Bugs: ProtocolBugs{
10286 BadChangeCipherSpec: []byte{1, 1},
10287 },
10288 },
10289 shouldFail: true,
10290 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10291 })
10292}
10293
David Benjamincd2c8062016-09-09 11:28:16 -040010294type perMessageTest struct {
10295 messageType uint8
10296 test testCase
10297}
10298
10299// makePerMessageTests returns a series of test templates which cover each
10300// message in the TLS handshake. These may be used with bugs like
10301// WrongMessageType to fully test a per-message bug.
10302func makePerMessageTests() []perMessageTest {
10303 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010304 for _, protocol := range []protocol{tls, dtls} {
10305 var suffix string
10306 if protocol == dtls {
10307 suffix = "-DTLS"
10308 }
10309
David Benjamincd2c8062016-09-09 11:28:16 -040010310 ret = append(ret, perMessageTest{
10311 messageType: typeClientHello,
10312 test: testCase{
10313 protocol: protocol,
10314 testType: serverTest,
10315 name: "ClientHello" + suffix,
10316 config: Config{
10317 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010318 },
10319 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010320 })
10321
10322 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010323 ret = append(ret, perMessageTest{
10324 messageType: typeHelloVerifyRequest,
10325 test: testCase{
10326 protocol: protocol,
10327 name: "HelloVerifyRequest" + suffix,
10328 config: Config{
10329 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010330 },
10331 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010332 })
10333 }
10334
David Benjamincd2c8062016-09-09 11:28:16 -040010335 ret = append(ret, perMessageTest{
10336 messageType: typeServerHello,
10337 test: testCase{
10338 protocol: protocol,
10339 name: "ServerHello" + suffix,
10340 config: Config{
10341 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010342 },
10343 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010344 })
10345
David Benjamincd2c8062016-09-09 11:28:16 -040010346 ret = append(ret, perMessageTest{
10347 messageType: typeCertificate,
10348 test: testCase{
10349 protocol: protocol,
10350 name: "ServerCertificate" + suffix,
10351 config: Config{
10352 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010353 },
10354 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010355 })
10356
David Benjamincd2c8062016-09-09 11:28:16 -040010357 ret = append(ret, perMessageTest{
10358 messageType: typeCertificateStatus,
10359 test: testCase{
10360 protocol: protocol,
10361 name: "CertificateStatus" + suffix,
10362 config: Config{
10363 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010364 },
David Benjamincd2c8062016-09-09 11:28:16 -040010365 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010366 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010367 })
10368
David Benjamincd2c8062016-09-09 11:28:16 -040010369 ret = append(ret, perMessageTest{
10370 messageType: typeServerKeyExchange,
10371 test: testCase{
10372 protocol: protocol,
10373 name: "ServerKeyExchange" + suffix,
10374 config: Config{
10375 MaxVersion: VersionTLS12,
10376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010377 },
10378 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010379 })
10380
David Benjamincd2c8062016-09-09 11:28:16 -040010381 ret = append(ret, perMessageTest{
10382 messageType: typeCertificateRequest,
10383 test: testCase{
10384 protocol: protocol,
10385 name: "CertificateRequest" + suffix,
10386 config: Config{
10387 MaxVersion: VersionTLS12,
10388 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010389 },
10390 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010391 })
10392
David Benjamincd2c8062016-09-09 11:28:16 -040010393 ret = append(ret, perMessageTest{
10394 messageType: typeServerHelloDone,
10395 test: testCase{
10396 protocol: protocol,
10397 name: "ServerHelloDone" + suffix,
10398 config: Config{
10399 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010400 },
10401 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010402 })
10403
David Benjamincd2c8062016-09-09 11:28:16 -040010404 ret = append(ret, perMessageTest{
10405 messageType: typeCertificate,
10406 test: testCase{
10407 testType: serverTest,
10408 protocol: protocol,
10409 name: "ClientCertificate" + suffix,
10410 config: Config{
10411 Certificates: []Certificate{rsaCertificate},
10412 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010413 },
David Benjamincd2c8062016-09-09 11:28:16 -040010414 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010415 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010416 })
10417
David Benjamincd2c8062016-09-09 11:28:16 -040010418 ret = append(ret, perMessageTest{
10419 messageType: typeCertificateVerify,
10420 test: testCase{
10421 testType: serverTest,
10422 protocol: protocol,
10423 name: "CertificateVerify" + suffix,
10424 config: Config{
10425 Certificates: []Certificate{rsaCertificate},
10426 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010427 },
David Benjamincd2c8062016-09-09 11:28:16 -040010428 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010429 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010430 })
10431
David Benjamincd2c8062016-09-09 11:28:16 -040010432 ret = append(ret, perMessageTest{
10433 messageType: typeClientKeyExchange,
10434 test: testCase{
10435 testType: serverTest,
10436 protocol: protocol,
10437 name: "ClientKeyExchange" + suffix,
10438 config: Config{
10439 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010440 },
10441 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010442 })
10443
10444 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010445 ret = append(ret, perMessageTest{
10446 messageType: typeNextProtocol,
10447 test: testCase{
10448 testType: serverTest,
10449 protocol: protocol,
10450 name: "NextProtocol" + suffix,
10451 config: Config{
10452 MaxVersion: VersionTLS12,
10453 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010454 },
David Benjamincd2c8062016-09-09 11:28:16 -040010455 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010456 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010457 })
10458
David Benjamincd2c8062016-09-09 11:28:16 -040010459 ret = append(ret, perMessageTest{
10460 messageType: typeChannelID,
10461 test: testCase{
10462 testType: serverTest,
10463 protocol: protocol,
10464 name: "ChannelID" + suffix,
10465 config: Config{
10466 MaxVersion: VersionTLS12,
10467 ChannelID: channelIDKey,
10468 },
10469 flags: []string{
10470 "-expect-channel-id",
10471 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010472 },
10473 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010474 })
10475 }
10476
David Benjamincd2c8062016-09-09 11:28:16 -040010477 ret = append(ret, perMessageTest{
10478 messageType: typeFinished,
10479 test: testCase{
10480 testType: serverTest,
10481 protocol: protocol,
10482 name: "ClientFinished" + suffix,
10483 config: Config{
10484 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010485 },
10486 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010487 })
10488
David Benjamincd2c8062016-09-09 11:28:16 -040010489 ret = append(ret, perMessageTest{
10490 messageType: typeNewSessionTicket,
10491 test: testCase{
10492 protocol: protocol,
10493 name: "NewSessionTicket" + suffix,
10494 config: Config{
10495 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010496 },
10497 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010498 })
10499
David Benjamincd2c8062016-09-09 11:28:16 -040010500 ret = append(ret, perMessageTest{
10501 messageType: typeFinished,
10502 test: testCase{
10503 protocol: protocol,
10504 name: "ServerFinished" + suffix,
10505 config: Config{
10506 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010507 },
10508 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010509 })
10510
10511 }
David Benjamincd2c8062016-09-09 11:28:16 -040010512
10513 ret = append(ret, perMessageTest{
10514 messageType: typeClientHello,
10515 test: testCase{
10516 testType: serverTest,
10517 name: "TLS13-ClientHello",
10518 config: Config{
10519 MaxVersion: VersionTLS13,
10520 },
10521 },
10522 })
10523
10524 ret = append(ret, perMessageTest{
10525 messageType: typeServerHello,
10526 test: testCase{
10527 name: "TLS13-ServerHello",
10528 config: Config{
10529 MaxVersion: VersionTLS13,
10530 },
10531 },
10532 })
10533
10534 ret = append(ret, perMessageTest{
10535 messageType: typeEncryptedExtensions,
10536 test: testCase{
10537 name: "TLS13-EncryptedExtensions",
10538 config: Config{
10539 MaxVersion: VersionTLS13,
10540 },
10541 },
10542 })
10543
10544 ret = append(ret, perMessageTest{
10545 messageType: typeCertificateRequest,
10546 test: testCase{
10547 name: "TLS13-CertificateRequest",
10548 config: Config{
10549 MaxVersion: VersionTLS13,
10550 ClientAuth: RequireAnyClientCert,
10551 },
10552 },
10553 })
10554
10555 ret = append(ret, perMessageTest{
10556 messageType: typeCertificate,
10557 test: testCase{
10558 name: "TLS13-ServerCertificate",
10559 config: Config{
10560 MaxVersion: VersionTLS13,
10561 },
10562 },
10563 })
10564
10565 ret = append(ret, perMessageTest{
10566 messageType: typeCertificateVerify,
10567 test: testCase{
10568 name: "TLS13-ServerCertificateVerify",
10569 config: Config{
10570 MaxVersion: VersionTLS13,
10571 },
10572 },
10573 })
10574
10575 ret = append(ret, perMessageTest{
10576 messageType: typeFinished,
10577 test: testCase{
10578 name: "TLS13-ServerFinished",
10579 config: Config{
10580 MaxVersion: VersionTLS13,
10581 },
10582 },
10583 })
10584
10585 ret = append(ret, perMessageTest{
10586 messageType: typeCertificate,
10587 test: testCase{
10588 testType: serverTest,
10589 name: "TLS13-ClientCertificate",
10590 config: Config{
10591 Certificates: []Certificate{rsaCertificate},
10592 MaxVersion: VersionTLS13,
10593 },
10594 flags: []string{"-require-any-client-certificate"},
10595 },
10596 })
10597
10598 ret = append(ret, perMessageTest{
10599 messageType: typeCertificateVerify,
10600 test: testCase{
10601 testType: serverTest,
10602 name: "TLS13-ClientCertificateVerify",
10603 config: Config{
10604 Certificates: []Certificate{rsaCertificate},
10605 MaxVersion: VersionTLS13,
10606 },
10607 flags: []string{"-require-any-client-certificate"},
10608 },
10609 })
10610
10611 ret = append(ret, perMessageTest{
10612 messageType: typeFinished,
10613 test: testCase{
10614 testType: serverTest,
10615 name: "TLS13-ClientFinished",
10616 config: Config{
10617 MaxVersion: VersionTLS13,
10618 },
10619 },
10620 })
10621
10622 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010623}
10624
David Benjamincd2c8062016-09-09 11:28:16 -040010625func addWrongMessageTypeTests() {
10626 for _, t := range makePerMessageTests() {
10627 t.test.name = "WrongMessageType-" + t.test.name
10628 t.test.config.Bugs.SendWrongMessageType = t.messageType
10629 t.test.shouldFail = true
10630 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10631 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010632
David Benjamincd2c8062016-09-09 11:28:16 -040010633 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10634 // In TLS 1.3, a bad ServerHello means the client sends
10635 // an unencrypted alert while the server expects
10636 // encryption, so the alert is not readable by runner.
10637 t.test.expectedLocalError = "local error: bad record MAC"
10638 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010639
David Benjamincd2c8062016-09-09 11:28:16 -040010640 testCases = append(testCases, t.test)
10641 }
David Benjaminebacdee2017-04-08 11:00:45 -040010642
10643 // The processing order for TLS 1.3 version negotiation is such that one
10644 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10645 // TLS 1.2. Test that we do not do this.
10646 testCases = append(testCases, testCase{
10647 name: "SendServerHelloAsHelloRetryRequest",
10648 config: Config{
10649 MaxVersion: VersionTLS12,
10650 Bugs: ProtocolBugs{
10651 SendServerHelloAsHelloRetryRequest: true,
10652 },
10653 },
10654 shouldFail: true,
10655 expectedError: ":UNEXPECTED_MESSAGE:",
10656 expectedLocalError: "remote error: unexpected message",
10657 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010658}
10659
David Benjamin639846e2016-09-09 11:41:18 -040010660func addTrailingMessageDataTests() {
10661 for _, t := range makePerMessageTests() {
10662 t.test.name = "TrailingMessageData-" + t.test.name
10663 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10664 t.test.shouldFail = true
10665 t.test.expectedError = ":DECODE_ERROR:"
10666 t.test.expectedLocalError = "remote error: error decoding message"
10667
10668 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10669 // In TLS 1.3, a bad ServerHello means the client sends
10670 // an unencrypted alert while the server expects
10671 // encryption, so the alert is not readable by runner.
10672 t.test.expectedLocalError = "local error: bad record MAC"
10673 }
10674
10675 if t.messageType == typeFinished {
10676 // Bad Finished messages read as the verify data having
10677 // the wrong length.
10678 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10679 t.test.expectedLocalError = "remote error: error decrypting message"
10680 }
10681
10682 testCases = append(testCases, t.test)
10683 }
10684}
10685
Steven Valdez143e8b32016-07-11 13:19:03 -040010686func addTLS13HandshakeTests() {
10687 testCases = append(testCases, testCase{
10688 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010689 name: "NegotiatePSKResumption-TLS13",
10690 config: Config{
10691 MaxVersion: VersionTLS13,
10692 Bugs: ProtocolBugs{
10693 NegotiatePSKResumption: true,
10694 },
10695 },
10696 resumeSession: true,
10697 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010698 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010699 })
10700
10701 testCases = append(testCases, testCase{
10702 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010703 name: "MissingKeyShare-Client",
10704 config: Config{
10705 MaxVersion: VersionTLS13,
10706 Bugs: ProtocolBugs{
10707 MissingKeyShare: true,
10708 },
10709 },
10710 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010711 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010712 })
10713
10714 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010715 testType: serverTest,
10716 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010717 config: Config{
10718 MaxVersion: VersionTLS13,
10719 Bugs: ProtocolBugs{
10720 MissingKeyShare: true,
10721 },
10722 },
10723 shouldFail: true,
10724 expectedError: ":MISSING_KEY_SHARE:",
10725 })
10726
10727 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010728 testType: serverTest,
10729 name: "DuplicateKeyShares",
10730 config: Config{
10731 MaxVersion: VersionTLS13,
10732 Bugs: ProtocolBugs{
10733 DuplicateKeyShares: true,
10734 },
10735 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010736 shouldFail: true,
10737 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010738 })
10739
10740 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010741 testType: serverTest,
10742 name: "SkipEarlyData",
10743 config: Config{
10744 MaxVersion: VersionTLS13,
10745 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010746 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010747 },
10748 },
10749 })
10750
10751 testCases = append(testCases, testCase{
10752 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010753 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010754 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010755 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010756 Bugs: ProtocolBugs{
10757 SendFakeEarlyDataLength: 4,
10758 },
10759 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010760 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010761 })
10762
10763 testCases = append(testCases, testCase{
10764 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010765 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10766 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010767 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010768 Bugs: ProtocolBugs{
10769 SendFakeEarlyDataLength: 4,
10770 },
10771 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010772 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010773 })
10774
10775 testCases = append(testCases, testCase{
10776 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010777 name: "SkipEarlyData-OmitEarlyDataExtension",
10778 config: Config{
10779 MaxVersion: VersionTLS13,
10780 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010781 SendFakeEarlyDataLength: 4,
10782 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010783 },
10784 },
10785 shouldFail: true,
10786 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10787 })
10788
10789 testCases = append(testCases, testCase{
10790 testType: serverTest,
10791 name: "SkipEarlyData-TooMuchData",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010795 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010796 },
10797 },
10798 shouldFail: true,
10799 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10800 })
10801
10802 testCases = append(testCases, testCase{
10803 testType: serverTest,
10804 name: "SkipEarlyData-Interleaved",
10805 config: Config{
10806 MaxVersion: VersionTLS13,
10807 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010808 SendFakeEarlyDataLength: 4,
10809 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010810 },
10811 },
10812 shouldFail: true,
10813 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10814 })
10815
10816 testCases = append(testCases, testCase{
10817 testType: serverTest,
10818 name: "SkipEarlyData-EarlyDataInTLS12",
10819 config: Config{
10820 MaxVersion: VersionTLS13,
10821 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010822 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010823 },
10824 },
10825 shouldFail: true,
10826 expectedError: ":UNEXPECTED_RECORD:",
10827 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10828 })
10829
10830 testCases = append(testCases, testCase{
10831 testType: serverTest,
10832 name: "SkipEarlyData-HRR",
10833 config: Config{
10834 MaxVersion: VersionTLS13,
10835 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010836 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010837 },
10838 DefaultCurves: []CurveID{},
10839 },
10840 })
10841
10842 testCases = append(testCases, testCase{
10843 testType: serverTest,
10844 name: "SkipEarlyData-HRR-Interleaved",
10845 config: Config{
10846 MaxVersion: VersionTLS13,
10847 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010848 SendFakeEarlyDataLength: 4,
10849 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010850 },
10851 DefaultCurves: []CurveID{},
10852 },
10853 shouldFail: true,
10854 expectedError: ":UNEXPECTED_RECORD:",
10855 })
10856
10857 testCases = append(testCases, testCase{
10858 testType: serverTest,
10859 name: "SkipEarlyData-HRR-TooMuchData",
10860 config: Config{
10861 MaxVersion: VersionTLS13,
10862 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010863 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010864 },
10865 DefaultCurves: []CurveID{},
10866 },
10867 shouldFail: true,
10868 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10869 })
10870
10871 // Test that skipping early data looking for cleartext correctly
10872 // processes an alert record.
10873 testCases = append(testCases, testCase{
10874 testType: serverTest,
10875 name: "SkipEarlyData-HRR-FatalAlert",
10876 config: Config{
10877 MaxVersion: VersionTLS13,
10878 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010879 SendEarlyAlert: true,
10880 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010881 },
10882 DefaultCurves: []CurveID{},
10883 },
10884 shouldFail: true,
10885 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10886 })
10887
10888 testCases = append(testCases, testCase{
10889 testType: serverTest,
10890 name: "SkipEarlyData-SecondClientHelloEarlyData",
10891 config: Config{
10892 MaxVersion: VersionTLS13,
10893 Bugs: ProtocolBugs{
10894 SendEarlyDataOnSecondClientHello: true,
10895 },
10896 DefaultCurves: []CurveID{},
10897 },
10898 shouldFail: true,
10899 expectedLocalError: "remote error: bad record MAC",
10900 })
10901
10902 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010903 testType: clientTest,
10904 name: "EmptyEncryptedExtensions",
10905 config: Config{
10906 MaxVersion: VersionTLS13,
10907 Bugs: ProtocolBugs{
10908 EmptyEncryptedExtensions: true,
10909 },
10910 },
10911 shouldFail: true,
10912 expectedLocalError: "remote error: error decoding message",
10913 })
10914
10915 testCases = append(testCases, testCase{
10916 testType: clientTest,
10917 name: "EncryptedExtensionsWithKeyShare",
10918 config: Config{
10919 MaxVersion: VersionTLS13,
10920 Bugs: ProtocolBugs{
10921 EncryptedExtensionsWithKeyShare: true,
10922 },
10923 },
10924 shouldFail: true,
10925 expectedLocalError: "remote error: unsupported extension",
10926 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010927
10928 testCases = append(testCases, testCase{
10929 testType: serverTest,
10930 name: "SendHelloRetryRequest",
10931 config: Config{
10932 MaxVersion: VersionTLS13,
10933 // Require a HelloRetryRequest for every curve.
10934 DefaultCurves: []CurveID{},
10935 },
10936 expectedCurveID: CurveX25519,
10937 })
10938
10939 testCases = append(testCases, testCase{
10940 testType: serverTest,
10941 name: "SendHelloRetryRequest-2",
10942 config: Config{
10943 MaxVersion: VersionTLS13,
10944 DefaultCurves: []CurveID{CurveP384},
10945 },
10946 // Although the ClientHello did not predict our preferred curve,
10947 // we always select it whether it is predicted or not.
10948 expectedCurveID: CurveX25519,
10949 })
10950
10951 testCases = append(testCases, testCase{
10952 name: "UnknownCurve-HelloRetryRequest",
10953 config: Config{
10954 MaxVersion: VersionTLS13,
10955 // P-384 requires HelloRetryRequest in BoringSSL.
10956 CurvePreferences: []CurveID{CurveP384},
10957 Bugs: ProtocolBugs{
10958 SendHelloRetryRequestCurve: bogusCurve,
10959 },
10960 },
10961 shouldFail: true,
10962 expectedError: ":WRONG_CURVE:",
10963 })
10964
10965 testCases = append(testCases, testCase{
10966 name: "DisabledCurve-HelloRetryRequest",
10967 config: Config{
10968 MaxVersion: VersionTLS13,
10969 CurvePreferences: []CurveID{CurveP256},
10970 Bugs: ProtocolBugs{
10971 IgnorePeerCurvePreferences: true,
10972 },
10973 },
10974 flags: []string{"-p384-only"},
10975 shouldFail: true,
10976 expectedError: ":WRONG_CURVE:",
10977 })
10978
10979 testCases = append(testCases, testCase{
10980 name: "UnnecessaryHelloRetryRequest",
10981 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010982 MaxVersion: VersionTLS13,
10983 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010984 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010985 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010986 },
10987 },
10988 shouldFail: true,
10989 expectedError: ":WRONG_CURVE:",
10990 })
10991
10992 testCases = append(testCases, testCase{
10993 name: "SecondHelloRetryRequest",
10994 config: Config{
10995 MaxVersion: VersionTLS13,
10996 // P-384 requires HelloRetryRequest in BoringSSL.
10997 CurvePreferences: []CurveID{CurveP384},
10998 Bugs: ProtocolBugs{
10999 SecondHelloRetryRequest: true,
11000 },
11001 },
11002 shouldFail: true,
11003 expectedError: ":UNEXPECTED_MESSAGE:",
11004 })
11005
11006 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011007 name: "HelloRetryRequest-Empty",
11008 config: Config{
11009 MaxVersion: VersionTLS13,
11010 Bugs: ProtocolBugs{
11011 AlwaysSendHelloRetryRequest: true,
11012 },
11013 },
11014 shouldFail: true,
11015 expectedError: ":DECODE_ERROR:",
11016 })
11017
11018 testCases = append(testCases, testCase{
11019 name: "HelloRetryRequest-DuplicateCurve",
11020 config: Config{
11021 MaxVersion: VersionTLS13,
11022 // P-384 requires a HelloRetryRequest against BoringSSL's default
11023 // configuration. Assert this ExpectMissingKeyShare.
11024 CurvePreferences: []CurveID{CurveP384},
11025 Bugs: ProtocolBugs{
11026 ExpectMissingKeyShare: true,
11027 DuplicateHelloRetryRequestExtensions: true,
11028 },
11029 },
11030 shouldFail: true,
11031 expectedError: ":DUPLICATE_EXTENSION:",
11032 expectedLocalError: "remote error: illegal parameter",
11033 })
11034
11035 testCases = append(testCases, testCase{
11036 name: "HelloRetryRequest-Cookie",
11037 config: Config{
11038 MaxVersion: VersionTLS13,
11039 Bugs: ProtocolBugs{
11040 SendHelloRetryRequestCookie: []byte("cookie"),
11041 },
11042 },
11043 })
11044
11045 testCases = append(testCases, testCase{
11046 name: "HelloRetryRequest-DuplicateCookie",
11047 config: Config{
11048 MaxVersion: VersionTLS13,
11049 Bugs: ProtocolBugs{
11050 SendHelloRetryRequestCookie: []byte("cookie"),
11051 DuplicateHelloRetryRequestExtensions: true,
11052 },
11053 },
11054 shouldFail: true,
11055 expectedError: ":DUPLICATE_EXTENSION:",
11056 expectedLocalError: "remote error: illegal parameter",
11057 })
11058
11059 testCases = append(testCases, testCase{
11060 name: "HelloRetryRequest-EmptyCookie",
11061 config: Config{
11062 MaxVersion: VersionTLS13,
11063 Bugs: ProtocolBugs{
11064 SendHelloRetryRequestCookie: []byte{},
11065 },
11066 },
11067 shouldFail: true,
11068 expectedError: ":DECODE_ERROR:",
11069 })
11070
11071 testCases = append(testCases, testCase{
11072 name: "HelloRetryRequest-Cookie-Curve",
11073 config: Config{
11074 MaxVersion: VersionTLS13,
11075 // P-384 requires HelloRetryRequest in BoringSSL.
11076 CurvePreferences: []CurveID{CurveP384},
11077 Bugs: ProtocolBugs{
11078 SendHelloRetryRequestCookie: []byte("cookie"),
11079 ExpectMissingKeyShare: true,
11080 },
11081 },
11082 })
11083
11084 testCases = append(testCases, testCase{
11085 name: "HelloRetryRequest-Unknown",
11086 config: Config{
11087 MaxVersion: VersionTLS13,
11088 Bugs: ProtocolBugs{
11089 CustomHelloRetryRequestExtension: "extension",
11090 },
11091 },
11092 shouldFail: true,
11093 expectedError: ":UNEXPECTED_EXTENSION:",
11094 expectedLocalError: "remote error: unsupported extension",
11095 })
11096
11097 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011098 testType: serverTest,
11099 name: "SecondClientHelloMissingKeyShare",
11100 config: Config{
11101 MaxVersion: VersionTLS13,
11102 DefaultCurves: []CurveID{},
11103 Bugs: ProtocolBugs{
11104 SecondClientHelloMissingKeyShare: true,
11105 },
11106 },
11107 shouldFail: true,
11108 expectedError: ":MISSING_KEY_SHARE:",
11109 })
11110
11111 testCases = append(testCases, testCase{
11112 testType: serverTest,
11113 name: "SecondClientHelloWrongCurve",
11114 config: Config{
11115 MaxVersion: VersionTLS13,
11116 DefaultCurves: []CurveID{},
11117 Bugs: ProtocolBugs{
11118 MisinterpretHelloRetryRequestCurve: CurveP521,
11119 },
11120 },
11121 shouldFail: true,
11122 expectedError: ":WRONG_CURVE:",
11123 })
11124
11125 testCases = append(testCases, testCase{
11126 name: "HelloRetryRequestVersionMismatch",
11127 config: Config{
11128 MaxVersion: VersionTLS13,
11129 // P-384 requires HelloRetryRequest in BoringSSL.
11130 CurvePreferences: []CurveID{CurveP384},
11131 Bugs: ProtocolBugs{
11132 SendServerHelloVersion: 0x0305,
11133 },
11134 },
11135 shouldFail: true,
11136 expectedError: ":WRONG_VERSION_NUMBER:",
11137 })
11138
11139 testCases = append(testCases, testCase{
11140 name: "HelloRetryRequestCurveMismatch",
11141 config: Config{
11142 MaxVersion: VersionTLS13,
11143 // P-384 requires HelloRetryRequest in BoringSSL.
11144 CurvePreferences: []CurveID{CurveP384},
11145 Bugs: ProtocolBugs{
11146 // Send P-384 (correct) in the HelloRetryRequest.
11147 SendHelloRetryRequestCurve: CurveP384,
11148 // But send P-256 in the ServerHello.
11149 SendCurve: CurveP256,
11150 },
11151 },
11152 shouldFail: true,
11153 expectedError: ":WRONG_CURVE:",
11154 })
11155
11156 // Test the server selecting a curve that requires a HelloRetryRequest
11157 // without sending it.
11158 testCases = append(testCases, testCase{
11159 name: "SkipHelloRetryRequest",
11160 config: Config{
11161 MaxVersion: VersionTLS13,
11162 // P-384 requires HelloRetryRequest in BoringSSL.
11163 CurvePreferences: []CurveID{CurveP384},
11164 Bugs: ProtocolBugs{
11165 SkipHelloRetryRequest: true,
11166 },
11167 },
11168 shouldFail: true,
11169 expectedError: ":WRONG_CURVE:",
11170 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011171
11172 testCases = append(testCases, testCase{
11173 name: "TLS13-RequestContextInHandshake",
11174 config: Config{
11175 MaxVersion: VersionTLS13,
11176 MinVersion: VersionTLS13,
11177 ClientAuth: RequireAnyClientCert,
11178 Bugs: ProtocolBugs{
11179 SendRequestContext: []byte("request context"),
11180 },
11181 },
11182 flags: []string{
11183 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11184 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11185 },
11186 shouldFail: true,
11187 expectedError: ":DECODE_ERROR:",
11188 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011189
11190 testCases = append(testCases, testCase{
11191 testType: serverTest,
11192 name: "TLS13-TrailingKeyShareData",
11193 config: Config{
11194 MaxVersion: VersionTLS13,
11195 Bugs: ProtocolBugs{
11196 TrailingKeyShareData: true,
11197 },
11198 },
11199 shouldFail: true,
11200 expectedError: ":DECODE_ERROR:",
11201 })
David Benjamin7f78df42016-10-05 22:33:19 -040011202
11203 testCases = append(testCases, testCase{
11204 name: "TLS13-AlwaysSelectPSKIdentity",
11205 config: Config{
11206 MaxVersion: VersionTLS13,
11207 Bugs: ProtocolBugs{
11208 AlwaysSelectPSKIdentity: true,
11209 },
11210 },
11211 shouldFail: true,
11212 expectedError: ":UNEXPECTED_EXTENSION:",
11213 })
11214
11215 testCases = append(testCases, testCase{
11216 name: "TLS13-InvalidPSKIdentity",
11217 config: Config{
11218 MaxVersion: VersionTLS13,
11219 Bugs: ProtocolBugs{
11220 SelectPSKIdentityOnResume: 1,
11221 },
11222 },
11223 resumeSession: true,
11224 shouldFail: true,
11225 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11226 })
David Benjamin1286bee2016-10-07 15:25:06 -040011227
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011228 testCases = append(testCases, testCase{
11229 testType: serverTest,
11230 name: "TLS13-ExtraPSKIdentity",
11231 config: Config{
11232 MaxVersion: VersionTLS13,
11233 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011234 ExtraPSKIdentity: true,
11235 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011236 },
11237 },
11238 resumeSession: true,
11239 })
11240
David Benjamin1286bee2016-10-07 15:25:06 -040011241 // Test that unknown NewSessionTicket extensions are tolerated.
11242 testCases = append(testCases, testCase{
11243 name: "TLS13-CustomTicketExtension",
11244 config: Config{
11245 MaxVersion: VersionTLS13,
11246 Bugs: ProtocolBugs{
11247 CustomTicketExtension: "1234",
11248 },
11249 },
11250 })
Steven Valdez2d850622017-01-11 11:34:52 -050011251
Steven Valdez0e4a4482017-07-17 11:12:34 -040011252 for _, noSessionID := range []bool{false, true} {
11253 prefix := "TLS13Experiment"
11254 variant := TLS13Experiment
11255 if noSessionID {
11256 prefix = "TLS13NoSessionIDExperiment"
11257 variant = TLS13NoSessionIDExperiment
11258 }
11259
11260 // Test that enabling a TLS 1.3 variant does not interfere with
11261 // TLS 1.2 session ID resumption.
11262 testCases = append(testCases, testCase{
11263 testType: clientTest,
11264 name: prefix + "-ResumeTLS12SessionID",
11265 config: Config{
11266 MaxVersion: VersionTLS12,
11267 SessionTicketsDisabled: true,
11268 },
11269 resumeSession: true,
11270 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11271 })
11272
11273 // Test that the server correctly echoes back session IDs of
11274 // various lengths.
11275 testCases = append(testCases, testCase{
11276 testType: serverTest,
11277 name: prefix + "-EmptySessionID",
11278 config: Config{
11279 MaxVersion: VersionTLS13,
11280 Bugs: ProtocolBugs{
11281 SendClientHelloSessionID: []byte{},
11282 },
11283 },
11284 tls13Variant: variant,
11285 })
11286
11287 testCases = append(testCases, testCase{
11288 testType: serverTest,
11289 name: prefix + "-ShortSessionID",
11290 config: Config{
11291 MaxVersion: VersionTLS13,
11292 Bugs: ProtocolBugs{
11293 SendClientHelloSessionID: make([]byte, 16),
11294 },
11295 },
11296 tls13Variant: variant,
11297 })
11298
11299 testCases = append(testCases, testCase{
11300 testType: serverTest,
11301 name: prefix + "-FullSessionID",
11302 config: Config{
11303 MaxVersion: VersionTLS13,
11304 Bugs: ProtocolBugs{
11305 SendClientHelloSessionID: make([]byte, 32),
11306 },
11307 },
11308 tls13Variant: variant,
11309 })
11310 }
11311
11312 // Test that the client sends a fake session ID in TLS13Experiment.
11313 testCases = append(testCases, testCase{
11314 testType: clientTest,
11315 name: "TLS13Experiment-RequireSessionID",
11316 config: Config{
11317 MaxVersion: VersionTLS13,
11318 Bugs: ProtocolBugs{
11319 ExpectClientHelloSessionID: true,
11320 },
11321 },
11322 tls13Variant: TLS13Experiment,
11323 })
11324
11325 // Test that the client does not send a fake session ID in
11326 // TLS13NoSessionIDExperiment.
11327 testCases = append(testCases, testCase{
11328 testType: clientTest,
11329 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11330 config: Config{
11331 MaxVersion: VersionTLS13,
11332 Bugs: ProtocolBugs{
11333 ExpectEmptyClientHelloSessionID: true,
11334 },
11335 },
11336 tls13Variant: TLS13NoSessionIDExperiment,
11337 })
11338
Steven Valdez2d850622017-01-11 11:34:52 -050011339 testCases = append(testCases, testCase{
11340 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011341 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011342 config: Config{
11343 MaxVersion: VersionTLS13,
11344 MaxEarlyDataSize: 16384,
11345 },
11346 resumeConfig: &Config{
11347 MaxVersion: VersionTLS13,
11348 MaxEarlyDataSize: 16384,
11349 Bugs: ProtocolBugs{
11350 AlwaysRejectEarlyData: true,
11351 },
11352 },
11353 resumeSession: true,
11354 flags: []string{
11355 "-enable-early-data",
11356 "-expect-early-data-info",
11357 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011358 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011359 },
11360 })
11361
11362 testCases = append(testCases, testCase{
11363 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011364 name: "TLS13Experiment-EarlyData-Reject-Client",
11365 config: Config{
11366 MaxVersion: VersionTLS13,
11367 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011368 },
11369 resumeConfig: &Config{
11370 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011371 MaxEarlyDataSize: 16384,
11372 Bugs: ProtocolBugs{
11373 AlwaysRejectEarlyData: true,
11374 },
11375 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011376 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011377 resumeSession: true,
11378 flags: []string{
11379 "-enable-early-data",
11380 "-expect-early-data-info",
11381 "-expect-reject-early-data",
11382 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011383 },
11384 })
11385
11386 testCases = append(testCases, testCase{
11387 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011388 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11389 config: Config{
11390 MaxVersion: VersionTLS13,
11391 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011392 },
11393 resumeConfig: &Config{
11394 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011395 MaxEarlyDataSize: 16384,
11396 Bugs: ProtocolBugs{
11397 AlwaysRejectEarlyData: true,
11398 },
11399 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011400 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011401 resumeSession: true,
11402 flags: []string{
11403 "-enable-early-data",
11404 "-expect-early-data-info",
11405 "-expect-reject-early-data",
11406 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011407 },
11408 })
11409
11410 testCases = append(testCases, testCase{
11411 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011412 name: "TLS13-EarlyData-RejectTicket-Client",
11413 config: Config{
11414 MaxVersion: VersionTLS13,
11415 MaxEarlyDataSize: 16384,
11416 Certificates: []Certificate{rsaCertificate},
11417 },
11418 resumeConfig: &Config{
11419 MaxVersion: VersionTLS13,
11420 MaxEarlyDataSize: 16384,
11421 Certificates: []Certificate{ecdsaP256Certificate},
11422 SessionTicketsDisabled: true,
11423 },
11424 resumeSession: true,
11425 expectResumeRejected: true,
11426 flags: []string{
11427 "-enable-early-data",
11428 "-expect-early-data-info",
11429 "-expect-reject-early-data",
11430 "-on-resume-shim-writes-first",
11431 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11432 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11433 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11434 // Session tickets are disabled, so the runner will not send a ticket.
11435 "-on-retry-expect-no-session",
11436 },
11437 })
11438
11439 testCases = append(testCases, testCase{
11440 testType: clientTest,
11441 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011442 config: Config{
11443 MaxVersion: VersionTLS13,
11444 MaxEarlyDataSize: 16384,
11445 },
11446 resumeConfig: &Config{
11447 MaxVersion: VersionTLS13,
11448 MaxEarlyDataSize: 16384,
11449 Bugs: ProtocolBugs{
11450 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11451 },
11452 },
11453 resumeSession: true,
11454 flags: []string{
11455 "-enable-early-data",
11456 "-expect-early-data-info",
11457 "-expect-reject-early-data",
11458 },
11459 })
11460
11461 // The client must check the server does not send the early_data
11462 // extension while rejecting the session.
11463 testCases = append(testCases, testCase{
11464 testType: clientTest,
11465 name: "TLS13-EarlyDataWithoutResume-Client",
11466 config: Config{
11467 MaxVersion: VersionTLS13,
11468 MaxEarlyDataSize: 16384,
11469 },
11470 resumeConfig: &Config{
11471 MaxVersion: VersionTLS13,
11472 SessionTicketsDisabled: true,
11473 Bugs: ProtocolBugs{
11474 SendEarlyDataExtension: true,
11475 },
11476 },
11477 resumeSession: true,
11478 flags: []string{
11479 "-enable-early-data",
11480 "-expect-early-data-info",
11481 },
11482 shouldFail: true,
11483 expectedError: ":UNEXPECTED_EXTENSION:",
11484 })
11485
11486 // The client must fail with a dedicated error code if the server
11487 // responds with TLS 1.2 when offering 0-RTT.
11488 testCases = append(testCases, testCase{
11489 testType: clientTest,
11490 name: "TLS13-EarlyDataVersionDowngrade-Client",
11491 config: Config{
11492 MaxVersion: VersionTLS13,
11493 MaxEarlyDataSize: 16384,
11494 },
11495 resumeConfig: &Config{
11496 MaxVersion: VersionTLS12,
11497 },
11498 resumeSession: true,
11499 flags: []string{
11500 "-enable-early-data",
11501 "-expect-early-data-info",
11502 },
11503 shouldFail: true,
11504 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11505 })
11506
11507 // Test that the client rejects an (unsolicited) early_data extension if
11508 // the server sent an HRR.
11509 testCases = append(testCases, testCase{
11510 testType: clientTest,
11511 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11512 config: Config{
11513 MaxVersion: VersionTLS13,
11514 MaxEarlyDataSize: 16384,
11515 },
11516 resumeConfig: &Config{
11517 MaxVersion: VersionTLS13,
11518 MaxEarlyDataSize: 16384,
11519 Bugs: ProtocolBugs{
11520 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11521 SendEarlyDataExtension: true,
11522 },
11523 },
11524 resumeSession: true,
11525 flags: []string{
11526 "-enable-early-data",
11527 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011528 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011529 },
11530 shouldFail: true,
11531 expectedError: ":UNEXPECTED_EXTENSION:",
11532 })
11533
11534 fooString := "foo"
11535 barString := "bar"
11536
11537 // Test that the client reports the correct ALPN after a 0-RTT reject
11538 // that changed it.
11539 testCases = append(testCases, testCase{
11540 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011541 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011542 config: Config{
11543 MaxVersion: VersionTLS13,
11544 MaxEarlyDataSize: 16384,
11545 Bugs: ProtocolBugs{
11546 ALPNProtocol: &fooString,
11547 },
11548 },
11549 resumeConfig: &Config{
11550 MaxVersion: VersionTLS13,
11551 MaxEarlyDataSize: 16384,
11552 Bugs: ProtocolBugs{
11553 ALPNProtocol: &barString,
11554 },
11555 },
11556 resumeSession: true,
11557 flags: []string{
11558 "-advertise-alpn", "\x03foo\x03bar",
11559 "-enable-early-data",
11560 "-expect-early-data-info",
11561 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011562 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011563 "-on-resume-expect-alpn", "foo",
11564 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011565 },
11566 })
11567
11568 // Test that the client reports the correct ALPN after a 0-RTT reject if
11569 // ALPN was omitted from the first connection.
11570 testCases = append(testCases, testCase{
11571 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011572 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011573 config: Config{
11574 MaxVersion: VersionTLS13,
11575 MaxEarlyDataSize: 16384,
11576 },
11577 resumeConfig: &Config{
11578 MaxVersion: VersionTLS13,
11579 MaxEarlyDataSize: 16384,
11580 NextProtos: []string{"foo"},
11581 },
11582 resumeSession: true,
11583 flags: []string{
11584 "-advertise-alpn", "\x03foo\x03bar",
11585 "-enable-early-data",
11586 "-expect-early-data-info",
11587 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011588 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011589 "-on-resume-expect-alpn", "",
11590 "-on-retry-expect-alpn", "foo",
11591 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011592 },
11593 })
11594
11595 // Test that the client reports the correct ALPN after a 0-RTT reject if
11596 // ALPN was omitted from the second connection.
11597 testCases = append(testCases, testCase{
11598 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011599 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011600 config: Config{
11601 MaxVersion: VersionTLS13,
11602 MaxEarlyDataSize: 16384,
11603 NextProtos: []string{"foo"},
11604 },
11605 resumeConfig: &Config{
11606 MaxVersion: VersionTLS13,
11607 MaxEarlyDataSize: 16384,
11608 },
11609 resumeSession: true,
11610 flags: []string{
11611 "-advertise-alpn", "\x03foo\x03bar",
11612 "-enable-early-data",
11613 "-expect-early-data-info",
11614 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011615 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011616 "-on-resume-expect-alpn", "foo",
11617 "-on-retry-expect-alpn", "",
11618 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011619 },
11620 })
11621
11622 // Test that the client enforces ALPN match on 0-RTT accept.
11623 testCases = append(testCases, testCase{
11624 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011625 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011626 config: Config{
11627 MaxVersion: VersionTLS13,
11628 MaxEarlyDataSize: 16384,
11629 Bugs: ProtocolBugs{
11630 ALPNProtocol: &fooString,
11631 },
11632 },
11633 resumeConfig: &Config{
11634 MaxVersion: VersionTLS13,
11635 MaxEarlyDataSize: 16384,
11636 Bugs: ProtocolBugs{
11637 AlwaysAcceptEarlyData: true,
11638 ALPNProtocol: &barString,
11639 },
11640 },
11641 resumeSession: true,
11642 flags: []string{
11643 "-advertise-alpn", "\x03foo\x03bar",
11644 "-enable-early-data",
11645 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011646 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011647 "-on-resume-expect-alpn", "foo",
11648 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011649 },
11650 shouldFail: true,
11651 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11652 })
11653
11654 // Test that the server correctly rejects 0-RTT when the previous
11655 // session did not allow early data on resumption.
11656 testCases = append(testCases, testCase{
11657 testType: serverTest,
11658 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11659 config: Config{
11660 MaxVersion: VersionTLS13,
11661 },
11662 resumeConfig: &Config{
11663 MaxVersion: VersionTLS13,
11664 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011665 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011666 ExpectEarlyDataAccepted: false,
11667 },
11668 },
11669 resumeSession: true,
11670 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011671 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011672 "-expect-reject-early-data",
11673 },
11674 })
11675
11676 // Test that we reject early data where ALPN is omitted from the first
11677 // connection.
11678 testCases = append(testCases, testCase{
11679 testType: serverTest,
11680 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11681 config: Config{
11682 MaxVersion: VersionTLS13,
11683 NextProtos: []string{},
11684 },
11685 resumeConfig: &Config{
11686 MaxVersion: VersionTLS13,
11687 NextProtos: []string{"foo"},
11688 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011689 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011690 ExpectEarlyDataAccepted: false,
11691 },
11692 },
11693 resumeSession: true,
11694 flags: []string{
11695 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011696 "-on-initial-select-alpn", "",
11697 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011698 },
11699 })
11700
11701 // Test that we reject early data where ALPN is omitted from the second
11702 // connection.
11703 testCases = append(testCases, testCase{
11704 testType: serverTest,
11705 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11706 config: Config{
11707 MaxVersion: VersionTLS13,
11708 NextProtos: []string{"foo"},
11709 },
11710 resumeConfig: &Config{
11711 MaxVersion: VersionTLS13,
11712 NextProtos: []string{},
11713 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011714 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011715 ExpectEarlyDataAccepted: false,
11716 },
11717 },
11718 resumeSession: true,
11719 flags: []string{
11720 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011721 "-on-initial-select-alpn", "foo",
11722 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011723 },
11724 })
11725
11726 // Test that we reject early data with mismatched ALPN.
11727 testCases = append(testCases, testCase{
11728 testType: serverTest,
11729 name: "TLS13-EarlyData-ALPNMismatch-Server",
11730 config: Config{
11731 MaxVersion: VersionTLS13,
11732 NextProtos: []string{"foo"},
11733 },
11734 resumeConfig: &Config{
11735 MaxVersion: VersionTLS13,
11736 NextProtos: []string{"bar"},
11737 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011738 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011739 ExpectEarlyDataAccepted: false,
11740 },
11741 },
11742 resumeSession: true,
11743 flags: []string{
11744 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011745 "-on-initial-select-alpn", "foo",
11746 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011747 },
11748 })
11749
David Benjamin6bb507b2017-03-29 16:35:57 -050011750 // Test that the client offering 0-RTT and Channel ID forbids the server
11751 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011752 testCases = append(testCases, testCase{
11753 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011754 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011755 config: Config{
11756 MaxVersion: VersionTLS13,
11757 MaxEarlyDataSize: 16384,
11758 RequestChannelID: true,
11759 },
11760 resumeSession: true,
11761 expectChannelID: true,
11762 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011763 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011764 flags: []string{
11765 "-enable-early-data",
11766 "-expect-early-data-info",
11767 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11768 },
11769 })
11770
David Benjamin6bb507b2017-03-29 16:35:57 -050011771 // Test that the client offering Channel ID and 0-RTT allows the server
11772 // to decline 0-RTT.
11773 testCases = append(testCases, testCase{
11774 testType: clientTest,
11775 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11776 config: Config{
11777 MaxVersion: VersionTLS13,
11778 MaxEarlyDataSize: 16384,
11779 RequestChannelID: true,
11780 Bugs: ProtocolBugs{
11781 AlwaysRejectEarlyData: true,
11782 },
11783 },
11784 resumeSession: true,
11785 expectChannelID: true,
11786 flags: []string{
11787 "-enable-early-data",
11788 "-expect-early-data-info",
11789 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11790 "-expect-reject-early-data",
11791 },
11792 })
11793
11794 // Test that the client offering Channel ID and 0-RTT allows the server
11795 // to decline Channel ID.
11796 testCases = append(testCases, testCase{
11797 testType: clientTest,
11798 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11799 config: Config{
11800 MaxVersion: VersionTLS13,
11801 MaxEarlyDataSize: 16384,
11802 },
11803 resumeSession: true,
11804 flags: []string{
11805 "-enable-early-data",
11806 "-expect-early-data-info",
11807 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11808 "-expect-accept-early-data",
11809 },
11810 })
11811
11812 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11813 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011814 testCases = append(testCases, testCase{
11815 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011816 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011817 config: Config{
11818 MaxVersion: VersionTLS13,
11819 ChannelID: channelIDKey,
11820 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011821 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011822 ExpectEarlyDataAccepted: false,
11823 },
11824 },
11825 resumeSession: true,
11826 expectChannelID: true,
11827 flags: []string{
11828 "-enable-early-data",
11829 "-expect-reject-early-data",
11830 "-expect-channel-id",
11831 base64.StdEncoding.EncodeToString(channelIDBytes),
11832 },
11833 })
11834
David Benjamin6bb507b2017-03-29 16:35:57 -050011835 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11836 // if not offered Channel ID.
11837 testCases = append(testCases, testCase{
11838 testType: serverTest,
11839 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11840 config: Config{
11841 MaxVersion: VersionTLS13,
11842 Bugs: ProtocolBugs{
11843 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11844 ExpectEarlyDataAccepted: true,
11845 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11846 },
11847 },
11848 resumeSession: true,
11849 expectChannelID: false,
11850 flags: []string{
11851 "-enable-early-data",
11852 "-expect-accept-early-data",
11853 "-enable-channel-id",
11854 },
11855 })
11856
David Benjamin32c89272017-03-26 13:54:21 -050011857 // Test that the server rejects 0-RTT streams without end_of_early_data.
11858 // The subsequent records should fail to decrypt.
11859 testCases = append(testCases, testCase{
11860 testType: serverTest,
11861 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11862 config: Config{
11863 MaxVersion: VersionTLS13,
11864 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011865 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011866 ExpectEarlyDataAccepted: true,
11867 SkipEndOfEarlyData: true,
11868 },
11869 },
11870 resumeSession: true,
11871 flags: []string{"-enable-early-data"},
11872 shouldFail: true,
11873 expectedLocalError: "remote error: bad record MAC",
11874 expectedError: ":BAD_DECRYPT:",
11875 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011876
11877 testCases = append(testCases, testCase{
11878 testType: serverTest,
11879 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11880 config: Config{
11881 MaxVersion: VersionTLS13,
11882 },
11883 resumeConfig: &Config{
11884 MaxVersion: VersionTLS13,
11885 Bugs: ProtocolBugs{
11886 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11887 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011888 ExpectEarlyDataAccepted: true,
11889 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011890 },
11891 resumeSession: true,
11892 shouldFail: true,
11893 expectedError: ":UNEXPECTED_RECORD:",
11894 expectedLocalError: "remote error: unexpected message",
11895 flags: []string{
11896 "-enable-early-data",
11897 },
11898 })
David Benjamind9cbb532017-07-07 13:17:19 -040011899
11900 // Test that the client reports TLS 1.3 as the version while sending
11901 // early data.
11902 testCases = append(testCases, testCase{
11903 testType: clientTest,
11904 name: "TLS13-EarlyData-Client-VersionAPI",
11905 config: Config{
11906 MaxVersion: VersionTLS13,
11907 MaxEarlyDataSize: 16384,
11908 },
11909 resumeSession: true,
11910 flags: []string{
11911 "-enable-early-data",
11912 "-expect-early-data-info",
11913 "-expect-accept-early-data",
11914 "-expect-version", strconv.Itoa(VersionTLS13),
11915 },
11916 })
David Benjamin4a37de02017-08-08 20:15:40 -040011917
11918 // Test that client and server both notice handshake errors after data
11919 // has started flowing.
11920 testCases = append(testCases, testCase{
11921 testType: clientTest,
11922 name: "TLS13-EarlyData-Client-BadFinished",
11923 config: Config{
11924 MaxVersion: VersionTLS13,
11925 MaxEarlyDataSize: 16384,
11926 },
11927 resumeConfig: &Config{
11928 MaxVersion: VersionTLS13,
11929 MaxEarlyDataSize: 16384,
11930 Bugs: ProtocolBugs{
11931 BadFinished: true,
11932 },
11933 },
11934 resumeSession: true,
11935 flags: []string{
11936 "-enable-early-data",
11937 "-expect-early-data-info",
11938 "-expect-accept-early-data",
11939 },
11940 shouldFail: true,
11941 expectedError: ":DIGEST_CHECK_FAILED:",
11942 expectedLocalError: "remote error: error decrypting message",
11943 })
11944 testCases = append(testCases, testCase{
11945 testType: serverTest,
11946 name: "TLS13-EarlyData-Server-BadFinished",
11947 config: Config{
11948 MaxVersion: VersionTLS13,
11949 MaxEarlyDataSize: 16384,
11950 },
11951 resumeConfig: &Config{
11952 MaxVersion: VersionTLS13,
11953 MaxEarlyDataSize: 16384,
11954 Bugs: ProtocolBugs{
11955 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11956 ExpectEarlyDataAccepted: true,
11957 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11958 BadFinished: true,
11959 },
11960 },
11961 resumeSession: true,
11962 flags: []string{
11963 "-enable-early-data",
11964 "-expect-accept-early-data",
11965 },
11966 shouldFail: true,
11967 expectedError: ":DIGEST_CHECK_FAILED:",
11968 expectedLocalError: "remote error: error decrypting message",
11969 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020011970 testCases = append(testCases, testCase{
11971 testType: serverTest,
11972 name: "TLS13-ServerSkipCertificateVerify",
11973 config: Config{
11974 MinVersion: VersionTLS13,
11975 MaxVersion: VersionTLS13,
11976 Certificates: []Certificate{rsaChainCertificate},
11977 Bugs: ProtocolBugs{
11978 SkipCertificateVerify: true,
11979 },
11980 },
11981 expectPeerCertificate: &rsaChainCertificate,
11982 flags: []string{
11983 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11984 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11985 "-require-any-client-certificate",
11986 },
11987 shouldFail: true,
11988 expectedError: ":UNEXPECTED_MESSAGE:",
11989 expectedLocalError: "remote error: unexpected message",
11990 })
11991 testCases = append(testCases, testCase{
11992 testType: clientTest,
11993 name: "TLS13-ClientSkipCertificateVerify",
11994 config: Config{
11995 MinVersion: VersionTLS13,
11996 MaxVersion: VersionTLS13,
11997 Certificates: []Certificate{rsaChainCertificate},
11998 Bugs: ProtocolBugs{
11999 SkipCertificateVerify: true,
12000 },
12001 },
12002 expectPeerCertificate: &rsaChainCertificate,
12003 flags: []string{
12004 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12005 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12006 },
12007 shouldFail: true,
12008 expectedError: ":UNEXPECTED_MESSAGE:",
12009 expectedLocalError: "remote error: unexpected message",
12010 })
Steven Valdez143e8b32016-07-11 13:19:03 -040012011}
12012
David Benjaminabbbee12016-10-31 19:20:42 -040012013func addTLS13CipherPreferenceTests() {
12014 // Test that client preference is honored if the shim has AES hardware
12015 // and ChaCha20-Poly1305 is preferred otherwise.
12016 testCases = append(testCases, testCase{
12017 testType: serverTest,
12018 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
12019 config: Config{
12020 MaxVersion: VersionTLS13,
12021 CipherSuites: []uint16{
12022 TLS_CHACHA20_POLY1305_SHA256,
12023 TLS_AES_128_GCM_SHA256,
12024 },
12025 },
12026 flags: []string{
12027 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12028 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12029 },
12030 })
12031
12032 testCases = append(testCases, testCase{
12033 testType: serverTest,
12034 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
12035 config: Config{
12036 MaxVersion: VersionTLS13,
12037 CipherSuites: []uint16{
12038 TLS_AES_128_GCM_SHA256,
12039 TLS_CHACHA20_POLY1305_SHA256,
12040 },
12041 },
12042 flags: []string{
12043 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12044 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12045 },
12046 })
12047
12048 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
12049 // whether it has AES hardware.
12050 testCases = append(testCases, testCase{
12051 name: "TLS13-CipherPreference-Client",
12052 config: Config{
12053 MaxVersion: VersionTLS13,
12054 // Use the client cipher order. (This is the default but
12055 // is listed to be explicit.)
12056 PreferServerCipherSuites: false,
12057 },
12058 flags: []string{
12059 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12060 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12061 },
12062 })
12063}
12064
David Benjaminf3fbade2016-09-19 13:08:16 -040012065func addPeekTests() {
12066 // Test SSL_peek works, including on empty records.
12067 testCases = append(testCases, testCase{
12068 name: "Peek-Basic",
12069 sendEmptyRecords: 1,
12070 flags: []string{"-peek-then-read"},
12071 })
12072
12073 // Test SSL_peek can drive the initial handshake.
12074 testCases = append(testCases, testCase{
12075 name: "Peek-ImplicitHandshake",
12076 flags: []string{
12077 "-peek-then-read",
12078 "-implicit-handshake",
12079 },
12080 })
12081
12082 // Test SSL_peek can discover and drive a renegotiation.
12083 testCases = append(testCases, testCase{
12084 name: "Peek-Renegotiate",
12085 config: Config{
12086 MaxVersion: VersionTLS12,
12087 },
12088 renegotiate: 1,
12089 flags: []string{
12090 "-peek-then-read",
12091 "-renegotiate-freely",
12092 "-expect-total-renegotiations", "1",
12093 },
12094 })
12095
12096 // Test SSL_peek can discover a close_notify.
12097 testCases = append(testCases, testCase{
12098 name: "Peek-Shutdown",
12099 config: Config{
12100 Bugs: ProtocolBugs{
12101 ExpectCloseNotify: true,
12102 },
12103 },
12104 flags: []string{
12105 "-peek-then-read",
12106 "-check-close-notify",
12107 },
12108 })
12109
12110 // Test SSL_peek can discover an alert.
12111 testCases = append(testCases, testCase{
12112 name: "Peek-Alert",
12113 config: Config{
12114 Bugs: ProtocolBugs{
12115 SendSpuriousAlert: alertRecordOverflow,
12116 },
12117 },
12118 flags: []string{"-peek-then-read"},
12119 shouldFail: true,
12120 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12121 })
12122
12123 // Test SSL_peek can handle KeyUpdate.
12124 testCases = append(testCases, testCase{
12125 name: "Peek-KeyUpdate",
12126 config: Config{
12127 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012128 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012129 sendKeyUpdates: 1,
12130 keyUpdateRequest: keyUpdateNotRequested,
12131 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012132 })
12133}
12134
David Benjamine6f22212016-11-08 14:28:24 -050012135func addRecordVersionTests() {
12136 for _, ver := range tlsVersions {
12137 // Test that the record version is enforced.
12138 testCases = append(testCases, testCase{
12139 name: "CheckRecordVersion-" + ver.name,
12140 config: Config{
12141 MinVersion: ver.version,
12142 MaxVersion: ver.version,
12143 Bugs: ProtocolBugs{
12144 SendRecordVersion: 0x03ff,
12145 },
12146 },
David Benjamina5022392017-07-10 17:40:39 -040012147 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012148 shouldFail: true,
12149 expectedError: ":WRONG_VERSION_NUMBER:",
12150 })
12151
12152 // Test that the ClientHello may use any record version, for
12153 // compatibility reasons.
12154 testCases = append(testCases, testCase{
12155 testType: serverTest,
12156 name: "LooseInitialRecordVersion-" + ver.name,
12157 config: Config{
12158 MinVersion: ver.version,
12159 MaxVersion: ver.version,
12160 Bugs: ProtocolBugs{
12161 SendInitialRecordVersion: 0x03ff,
12162 },
12163 },
David Benjamina5022392017-07-10 17:40:39 -040012164 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012165 })
12166
12167 // Test that garbage ClientHello record versions are rejected.
12168 testCases = append(testCases, testCase{
12169 testType: serverTest,
12170 name: "GarbageInitialRecordVersion-" + ver.name,
12171 config: Config{
12172 MinVersion: ver.version,
12173 MaxVersion: ver.version,
12174 Bugs: ProtocolBugs{
12175 SendInitialRecordVersion: 0xffff,
12176 },
12177 },
David Benjamina5022392017-07-10 17:40:39 -040012178 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012179 shouldFail: true,
12180 expectedError: ":WRONG_VERSION_NUMBER:",
12181 })
12182 }
12183}
12184
David Benjamin2c516452016-11-15 10:16:54 +090012185func addCertificateTests() {
12186 // Test that a certificate chain with intermediate may be sent and
12187 // received as both client and server.
12188 for _, ver := range tlsVersions {
12189 testCases = append(testCases, testCase{
12190 testType: clientTest,
12191 name: "SendReceiveIntermediate-Client-" + ver.name,
12192 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012193 MinVersion: ver.version,
12194 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012195 Certificates: []Certificate{rsaChainCertificate},
12196 ClientAuth: RequireAnyClientCert,
12197 },
David Benjamina5022392017-07-10 17:40:39 -040012198 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012199 expectPeerCertificate: &rsaChainCertificate,
12200 flags: []string{
12201 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12202 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12203 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12204 },
12205 })
12206
12207 testCases = append(testCases, testCase{
12208 testType: serverTest,
12209 name: "SendReceiveIntermediate-Server-" + ver.name,
12210 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012211 MinVersion: ver.version,
12212 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012213 Certificates: []Certificate{rsaChainCertificate},
12214 },
David Benjamina5022392017-07-10 17:40:39 -040012215 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012216 expectPeerCertificate: &rsaChainCertificate,
12217 flags: []string{
12218 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12219 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12220 "-require-any-client-certificate",
12221 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12222 },
12223 })
12224 }
12225}
12226
David Benjaminbbaf3672016-11-17 10:53:09 +090012227func addRetainOnlySHA256ClientCertTests() {
12228 for _, ver := range tlsVersions {
12229 // Test that enabling
12230 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12231 // actually requesting a client certificate is a no-op.
12232 testCases = append(testCases, testCase{
12233 testType: serverTest,
12234 name: "RetainOnlySHA256-NoCert-" + ver.name,
12235 config: Config{
12236 MinVersion: ver.version,
12237 MaxVersion: ver.version,
12238 },
David Benjamina5022392017-07-10 17:40:39 -040012239 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012240 flags: []string{
12241 "-retain-only-sha256-client-cert-initial",
12242 "-retain-only-sha256-client-cert-resume",
12243 },
12244 resumeSession: true,
12245 })
12246
12247 // Test that when retaining only a SHA-256 certificate is
12248 // enabled, the hash appears as expected.
12249 testCases = append(testCases, testCase{
12250 testType: serverTest,
12251 name: "RetainOnlySHA256-Cert-" + ver.name,
12252 config: Config{
12253 MinVersion: ver.version,
12254 MaxVersion: ver.version,
12255 Certificates: []Certificate{rsaCertificate},
12256 },
David Benjamina5022392017-07-10 17:40:39 -040012257 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012258 flags: []string{
12259 "-verify-peer",
12260 "-retain-only-sha256-client-cert-initial",
12261 "-retain-only-sha256-client-cert-resume",
12262 "-expect-sha256-client-cert-initial",
12263 "-expect-sha256-client-cert-resume",
12264 },
12265 resumeSession: true,
12266 })
12267
12268 // Test that when the config changes from on to off, a
12269 // resumption is rejected because the server now wants the full
12270 // certificate chain.
12271 testCases = append(testCases, testCase{
12272 testType: serverTest,
12273 name: "RetainOnlySHA256-OnOff-" + ver.name,
12274 config: Config{
12275 MinVersion: ver.version,
12276 MaxVersion: ver.version,
12277 Certificates: []Certificate{rsaCertificate},
12278 },
David Benjamina5022392017-07-10 17:40:39 -040012279 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012280 flags: []string{
12281 "-verify-peer",
12282 "-retain-only-sha256-client-cert-initial",
12283 "-expect-sha256-client-cert-initial",
12284 },
12285 resumeSession: true,
12286 expectResumeRejected: true,
12287 })
12288
12289 // Test that when the config changes from off to on, a
12290 // resumption is rejected because the server now wants just the
12291 // hash.
12292 testCases = append(testCases, testCase{
12293 testType: serverTest,
12294 name: "RetainOnlySHA256-OffOn-" + ver.name,
12295 config: Config{
12296 MinVersion: ver.version,
12297 MaxVersion: ver.version,
12298 Certificates: []Certificate{rsaCertificate},
12299 },
David Benjamina5022392017-07-10 17:40:39 -040012300 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012301 flags: []string{
12302 "-verify-peer",
12303 "-retain-only-sha256-client-cert-resume",
12304 "-expect-sha256-client-cert-resume",
12305 },
12306 resumeSession: true,
12307 expectResumeRejected: true,
12308 })
12309 }
12310}
12311
Adam Langleya4b91982016-12-12 12:05:53 -080012312func addECDSAKeyUsageTests() {
12313 p256 := elliptic.P256()
12314 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12315 if err != nil {
12316 panic(err)
12317 }
12318
12319 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12320 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12321 if err != nil {
12322 panic(err)
12323 }
12324
12325 template := x509.Certificate{
12326 SerialNumber: serialNumber,
12327 Subject: pkix.Name{
12328 Organization: []string{"Acme Co"},
12329 },
12330 NotBefore: time.Now(),
12331 NotAfter: time.Now(),
12332
12333 // An ECC certificate with only the keyAgreement key usgae may
12334 // be used with ECDH, but not ECDSA.
12335 KeyUsage: x509.KeyUsageKeyAgreement,
12336 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12337 BasicConstraintsValid: true,
12338 }
12339
12340 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12341 if err != nil {
12342 panic(err)
12343 }
12344
12345 cert := Certificate{
12346 Certificate: [][]byte{derBytes},
12347 PrivateKey: priv,
12348 }
12349
12350 for _, ver := range tlsVersions {
12351 if ver.version < VersionTLS12 {
12352 continue
12353 }
12354
12355 testCases = append(testCases, testCase{
12356 testType: clientTest,
12357 name: "ECDSAKeyUsage-" + ver.name,
12358 config: Config{
12359 MinVersion: ver.version,
12360 MaxVersion: ver.version,
12361 Certificates: []Certificate{cert},
12362 },
David Benjamina5022392017-07-10 17:40:39 -040012363 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012364 shouldFail: true,
12365 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12366 })
12367 }
12368}
12369
David Benjamin8c26d752017-03-26 15:13:51 -050012370func addExtraHandshakeTests() {
12371 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12372 // to ensure there is no transport I/O.
12373 testCases = append(testCases, testCase{
12374 testType: clientTest,
12375 name: "ExtraHandshake-Client-TLS12",
12376 config: Config{
12377 MinVersion: VersionTLS12,
12378 MaxVersion: VersionTLS12,
12379 },
12380 flags: []string{
12381 "-async",
12382 "-no-op-extra-handshake",
12383 },
12384 })
12385 testCases = append(testCases, testCase{
12386 testType: serverTest,
12387 name: "ExtraHandshake-Server-TLS12",
12388 config: Config{
12389 MinVersion: VersionTLS12,
12390 MaxVersion: VersionTLS12,
12391 },
12392 flags: []string{
12393 "-async",
12394 "-no-op-extra-handshake",
12395 },
12396 })
12397 testCases = append(testCases, testCase{
12398 testType: clientTest,
12399 name: "ExtraHandshake-Client-TLS13",
12400 config: Config{
12401 MinVersion: VersionTLS13,
12402 MaxVersion: VersionTLS13,
12403 },
12404 flags: []string{
12405 "-async",
12406 "-no-op-extra-handshake",
12407 },
12408 })
12409 testCases = append(testCases, testCase{
12410 testType: serverTest,
12411 name: "ExtraHandshake-Server-TLS13",
12412 config: Config{
12413 MinVersion: VersionTLS13,
12414 MaxVersion: VersionTLS13,
12415 },
12416 flags: []string{
12417 "-async",
12418 "-no-op-extra-handshake",
12419 },
12420 })
12421
12422 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12423 testCases = append(testCases, testCase{
12424 testType: serverTest,
12425 name: "ExtraHandshake-Server-EarlyData-TLS13",
12426 config: Config{
12427 MaxVersion: VersionTLS13,
12428 MinVersion: VersionTLS13,
12429 Bugs: ProtocolBugs{
12430 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12431 ExpectEarlyDataAccepted: true,
12432 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12433 },
12434 },
12435 messageCount: 2,
12436 resumeSession: true,
12437 flags: []string{
12438 "-async",
12439 "-enable-early-data",
12440 "-expect-accept-early-data",
12441 "-no-op-extra-handshake",
12442 },
12443 })
12444
12445 // An extra SSL_do_handshake drives the handshake to completion in False
12446 // Start. We test this by handshaking twice and asserting the False
12447 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12448 // how the test works.
12449 testCases = append(testCases, testCase{
12450 testType: clientTest,
12451 name: "ExtraHandshake-FalseStart",
12452 config: Config{
12453 MaxVersion: VersionTLS12,
12454 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12455 NextProtos: []string{"foo"},
12456 Bugs: ProtocolBugs{
12457 ExpectFalseStart: true,
12458 AlertBeforeFalseStartTest: alertAccessDenied,
12459 },
12460 },
12461 flags: []string{
12462 "-handshake-twice",
12463 "-false-start",
12464 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012465 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012466 },
12467 shimWritesFirst: true,
12468 shouldFail: true,
12469 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12470 expectedLocalError: "tls: peer did not false start: EOF",
12471 })
12472}
12473
David Benjaminb853f312017-07-14 18:40:34 -040012474// Test that omitted and empty extensions blocks are tolerated.
12475func addOmitExtensionsTests() {
12476 for _, ver := range tlsVersions {
12477 if ver.version > VersionTLS12 {
12478 continue
12479 }
12480
12481 testCases = append(testCases, testCase{
12482 testType: serverTest,
12483 name: "OmitExtensions-ClientHello-" + ver.name,
12484 config: Config{
12485 MinVersion: ver.version,
12486 MaxVersion: ver.version,
12487 SessionTicketsDisabled: true,
12488 Bugs: ProtocolBugs{
12489 OmitExtensions: true,
12490 },
12491 },
12492 })
12493
12494 testCases = append(testCases, testCase{
12495 testType: serverTest,
12496 name: "EmptyExtensions-ClientHello-" + ver.name,
12497 config: Config{
12498 MinVersion: ver.version,
12499 MaxVersion: ver.version,
12500 SessionTicketsDisabled: true,
12501 Bugs: ProtocolBugs{
12502 EmptyExtensions: true,
12503 },
12504 },
12505 })
12506
12507 testCases = append(testCases, testCase{
12508 testType: clientTest,
12509 name: "OmitExtensions-ServerHello-" + ver.name,
12510 config: Config{
12511 MinVersion: ver.version,
12512 MaxVersion: ver.version,
12513 SessionTicketsDisabled: true,
12514 Bugs: ProtocolBugs{
12515 OmitExtensions: true,
12516 // Disable all ServerHello extensions so
12517 // OmitExtensions works.
12518 NoExtendedMasterSecret: true,
12519 NoRenegotiationInfo: true,
12520 },
12521 },
12522 })
12523
12524 testCases = append(testCases, testCase{
12525 testType: clientTest,
12526 name: "EmptyExtensions-ServerHello-" + ver.name,
12527 config: Config{
12528 MinVersion: ver.version,
12529 MaxVersion: ver.version,
12530 SessionTicketsDisabled: true,
12531 Bugs: ProtocolBugs{
12532 EmptyExtensions: true,
12533 // Disable all ServerHello extensions so
12534 // EmptyExtensions works.
12535 NoExtendedMasterSecret: true,
12536 NoRenegotiationInfo: true,
12537 },
12538 },
12539 })
12540 }
12541}
12542
Adam Langley7c803a62015-06-15 15:35:05 -070012543func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012544 defer wg.Done()
12545
12546 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012547 var err error
12548
David Benjaminba28dfc2016-11-15 17:47:21 +090012549 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012550 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12551 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012552 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012553 if err != nil {
12554 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12555 }
12556 break
12557 }
12558 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012559 } else if *repeatUntilFailure {
12560 for err == nil {
12561 statusChan <- statusMsg{test: test, started: true}
12562 err = runTest(test, shimPath, -1)
12563 }
12564 } else {
12565 statusChan <- statusMsg{test: test, started: true}
12566 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012567 }
Adam Langley95c29f32014-06-20 12:00:00 -070012568 statusChan <- statusMsg{test: test, err: err}
12569 }
12570}
12571
12572type statusMsg struct {
12573 test *testCase
12574 started bool
12575 err error
12576}
12577
David Benjamin5f237bc2015-02-11 17:14:15 -050012578func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012579 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012580
David Benjamin5f237bc2015-02-11 17:14:15 -050012581 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012582 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012583 if !*pipe {
12584 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012585 var erase string
12586 for i := 0; i < lineLen; i++ {
12587 erase += "\b \b"
12588 }
12589 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012590 }
12591
Adam Langley95c29f32014-06-20 12:00:00 -070012592 if msg.started {
12593 started++
12594 } else {
12595 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012596
12597 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012598 if msg.err == errUnimplemented {
12599 if *pipe {
12600 // Print each test instead of a status line.
12601 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12602 }
12603 unimplemented++
12604 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12605 } else {
12606 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12607 failed++
12608 testOutput.addResult(msg.test.name, "FAIL")
12609 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012610 } else {
12611 if *pipe {
12612 // Print each test instead of a status line.
12613 fmt.Printf("PASSED (%s)\n", msg.test.name)
12614 }
12615 testOutput.addResult(msg.test.name, "PASS")
12616 }
Adam Langley95c29f32014-06-20 12:00:00 -070012617 }
12618
David Benjamin5f237bc2015-02-11 17:14:15 -050012619 if !*pipe {
12620 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012621 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012622 lineLen = len(line)
12623 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012624 }
Adam Langley95c29f32014-06-20 12:00:00 -070012625 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012626
12627 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012628}
12629
12630func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012631 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012632 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012633 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012634
Adam Langley7c803a62015-06-15 15:35:05 -070012635 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012636 addCipherSuiteTests()
12637 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012638 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012639 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012640 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012641 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012642 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012643 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012644 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012645 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012646 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012647 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012648 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012649 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012650 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012651 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012652 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012653 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012654 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012655 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012656 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012657 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012658 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012659 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012660 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012661 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012662 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012663 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012664 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012665 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012666 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012667 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012668 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012669 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012670 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012671
12672 var wg sync.WaitGroup
12673
Adam Langley7c803a62015-06-15 15:35:05 -070012674 statusChan := make(chan statusMsg, *numWorkers)
12675 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012676 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012677
EKRf71d7ed2016-08-06 13:25:12 -070012678 if len(*shimConfigFile) != 0 {
12679 encoded, err := ioutil.ReadFile(*shimConfigFile)
12680 if err != nil {
12681 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12682 os.Exit(1)
12683 }
12684
12685 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12686 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12687 os.Exit(1)
12688 }
12689 }
12690
David Benjamin025b3d32014-07-01 19:53:04 -040012691 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012692
Adam Langley7c803a62015-06-15 15:35:05 -070012693 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012694 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012695 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012696 }
12697
David Benjamin270f0a72016-03-17 14:41:36 -040012698 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012699 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012700 matched := true
12701 if len(*testToRun) != 0 {
12702 var err error
12703 matched, err = filepath.Match(*testToRun, testCases[i].name)
12704 if err != nil {
12705 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12706 os.Exit(1)
12707 }
12708 }
12709
EKRf71d7ed2016-08-06 13:25:12 -070012710 if !*includeDisabled {
12711 for pattern := range shimConfig.DisabledTests {
12712 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12713 if err != nil {
12714 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12715 os.Exit(1)
12716 }
12717
12718 if isDisabled {
12719 matched = false
12720 break
12721 }
12722 }
12723 }
12724
David Benjamin17e12922016-07-28 18:04:43 -040012725 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012726 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012727 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012728
12729 // Only run one test if repeating until failure.
12730 if *repeatUntilFailure {
12731 break
12732 }
Adam Langley95c29f32014-06-20 12:00:00 -070012733 }
12734 }
David Benjamin17e12922016-07-28 18:04:43 -040012735
David Benjamin270f0a72016-03-17 14:41:36 -040012736 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012737 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012738 os.Exit(1)
12739 }
Adam Langley95c29f32014-06-20 12:00:00 -070012740
12741 close(testChan)
12742 wg.Wait()
12743 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012744 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012745
12746 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012747
12748 if *jsonOutput != "" {
12749 if err := testOutput.writeTo(*jsonOutput); err != nil {
12750 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12751 }
12752 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012753
EKR842ae6c2016-07-27 09:22:05 +020012754 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12755 os.Exit(1)
12756 }
12757
12758 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012759 os.Exit(1)
12760 }
Adam Langley95c29f32014-06-20 12:00:00 -070012761}