blob: 0005725861fd37c4c21f3dc7f180623726db4bd3 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
491 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
492 return 0, err
493 }
494 return t.Conn.Read(b)
495}
496
497func (t *timeoutConn) Write(b []byte) (int, error) {
498 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
499 return 0, err
500 }
501 return t.Conn.Write(b)
502}
503
David Benjamin0fde2eb2017-06-30 19:11:22 -0400504func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400505 if !test.noSessionCache {
506 if config.ClientSessionCache == nil {
507 config.ClientSessionCache = NewLRUClientSessionCache(1)
508 }
509 if config.ServerSessionCache == nil {
510 config.ServerSessionCache = NewLRUServerSessionCache(1)
511 }
512 }
513 if test.testType == clientTest {
514 if len(config.Certificates) == 0 {
515 config.Certificates = []Certificate{rsaCertificate}
516 }
517 } else {
518 // Supply a ServerName to ensure a constant session cache key,
519 // rather than falling back to net.Conn.RemoteAddr.
520 if len(config.ServerName) == 0 {
521 config.ServerName = "test"
522 }
523 }
524 if *fuzzer {
525 config.Bugs.NullAllCiphers = true
526 }
David Benjamin01a90572016-09-22 00:11:43 -0400527 if *deterministic {
528 config.Time = func() time.Time { return time.Unix(1234, 1234) }
529 }
David Benjamine54af062016-08-08 19:21:18 -0400530
David Benjamin01784b42016-06-07 18:00:52 -0400531 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500532
David Benjamin6fd297b2014-08-11 18:43:38 -0400533 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500534 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
535 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500536 }
537
David Benjamin9867b7d2016-03-01 23:25:48 -0500538 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500539 local, peer := "client", "server"
540 if test.testType == clientTest {
541 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500542 }
David Benjaminebda9b32015-11-02 15:33:18 -0500543 connDebug := &recordingConn{
544 Conn: conn,
545 isDatagram: test.protocol == dtls,
546 local: local,
547 peer: peer,
548 }
549 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500550 if *flagDebug {
551 defer connDebug.WriteTo(os.Stdout)
552 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400553 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500554 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400555 path := transcriptPrefix + strconv.Itoa(num)
556 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 }()
558 }
David Benjaminebda9b32015-11-02 15:33:18 -0500559
560 if config.Bugs.PacketAdaptor != nil {
561 config.Bugs.PacketAdaptor.debug = connDebug
562 }
563 }
564
565 if test.replayWrites {
566 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400567 }
568
David Benjamin3ed59772016-03-08 12:50:21 -0500569 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500570 if test.damageFirstWrite {
571 connDamage = newDamageAdaptor(conn)
572 conn = connDamage
573 }
574
David Benjamin6fd297b2014-08-11 18:43:38 -0400575 if test.sendPrefix != "" {
576 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
577 return err
578 }
David Benjamin98e882e2014-08-08 13:24:34 -0400579 }
580
David Benjamin1d5c83e2014-07-22 19:20:02 -0400581 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400582 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400583 if test.protocol == dtls {
584 tlsConn = DTLSServer(conn, config)
585 } else {
586 tlsConn = Server(conn, config)
587 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 } else {
589 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400590 if test.protocol == dtls {
591 tlsConn = DTLSClient(conn, config)
592 } else {
593 tlsConn = Client(conn, config)
594 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400595 }
David Benjamin30789da2015-08-29 22:56:45 -0400596 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400597
Adam Langley95c29f32014-06-20 12:00:00 -0700598 if err := tlsConn.Handshake(); err != nil {
599 return err
600 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700601
David Benjamin01fe8202014-09-24 15:21:44 -0400602 // TODO(davidben): move all per-connection expectations into a dedicated
603 // expectations struct that can be specified separately for the two
604 // legs.
605 expectedVersion := test.expectedVersion
606 if isResume && test.expectedResumeVersion != 0 {
607 expectedVersion = test.expectedResumeVersion
608 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700609 connState := tlsConn.ConnectionState()
610 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400611 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400612 }
613
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700614 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400615 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
616 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700617 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
618 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
619 }
David Benjamin90da8c82015-04-20 14:57:57 -0400620
David Benjamina08e49d2014-08-24 01:46:07 -0400621 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700622 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400623 if channelID == nil {
624 return fmt.Errorf("no channel ID negotiated")
625 }
626 if channelID.Curve != channelIDKey.Curve ||
627 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
628 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
629 return fmt.Errorf("incorrect channel ID")
630 }
David Benjamin634f4752017-07-01 11:08:41 -0400631 } else if connState.ChannelID != nil {
632 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400633 }
634
David Benjaminae2888f2014-09-06 12:58:58 -0400635 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700636 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400637 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
638 }
639 }
640
David Benjaminc7ce9772015-10-09 19:32:41 -0400641 if test.expectNoNextProto {
642 if actual := connState.NegotiatedProtocol; actual != "" {
643 return fmt.Errorf("got unexpected next proto %s", actual)
644 }
645 }
646
David Benjaminfc7b0862014-09-06 13:21:53 -0400647 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700648 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400649 return fmt.Errorf("next proto type mismatch")
650 }
651 }
652
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700653 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500654 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
655 }
656
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100657 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300658 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100659 }
660
Paul Lietar4fac72e2015-09-09 13:44:55 +0100661 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
662 return fmt.Errorf("SCT list mismatch")
663 }
664
Nick Harper60edffd2016-06-21 15:19:24 -0700665 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
666 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400667 }
668
Steven Valdez5440fe02016-07-18 12:40:30 -0400669 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
670 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
671 }
672
David Benjamin2c516452016-11-15 10:16:54 +0900673 if test.expectPeerCertificate != nil {
674 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
675 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
676 }
677 for i, cert := range connState.PeerCertificates {
678 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
679 return fmt.Errorf("peer certificate %d did not match", i+1)
680 }
681 }
682 }
683
David Benjaminc565ebb2015-04-03 04:06:36 -0400684 if test.exportKeyingMaterial > 0 {
685 actual := make([]byte, test.exportKeyingMaterial)
686 if _, err := io.ReadFull(tlsConn, actual); err != nil {
687 return err
688 }
689 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
690 if err != nil {
691 return err
692 }
693 if !bytes.Equal(actual, expected) {
694 return fmt.Errorf("keying material mismatch")
695 }
696 }
697
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700698 if test.testTLSUnique {
699 var peersValue [12]byte
700 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
701 return err
702 }
703 expected := tlsConn.ConnectionState().TLSUnique
704 if !bytes.Equal(peersValue[:], expected) {
705 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
706 }
707 }
708
David Benjamin47921102016-07-28 11:29:18 -0400709 if test.sendHalfHelloRequest {
710 tlsConn.SendHalfHelloRequest()
711 }
712
Steven Valdeze831a812017-03-09 14:56:07 -0500713 shimPrefix := test.shimPrefix
714 if isResume {
715 shimPrefix = test.resumeShimPrefix
716 }
717 if test.shimWritesFirst || test.readWithUnfinishedWrite {
718 shimPrefix = "hello"
719 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400720 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400721 // If readWithUnfinishedWrite is set, the shim prefix will be
722 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500723 if shimPrefix != "" && !test.readWithUnfinishedWrite {
724 var buf = make([]byte, len(shimPrefix))
725 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400726 if err != nil {
727 return err
728 }
Steven Valdeze831a812017-03-09 14:56:07 -0500729 if string(buf) != shimPrefix {
730 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400731 }
Steven Valdeze831a812017-03-09 14:56:07 -0500732 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400733 }
734
Adam Langleycf2d4f42014-10-28 19:06:14 -0700735 if test.renegotiateCiphers != nil {
736 config.CipherSuites = test.renegotiateCiphers
737 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400738 for i := 0; i < test.renegotiate; i++ {
739 if err := tlsConn.Renegotiate(); err != nil {
740 return err
741 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700742 }
743 } else if test.renegotiateCiphers != nil {
744 panic("renegotiateCiphers without renegotiate")
745 }
746
David Benjamin5fa3eba2015-01-22 16:35:40 -0500747 if test.damageFirstWrite {
748 connDamage.setDamage(true)
749 tlsConn.Write([]byte("DAMAGED WRITE"))
750 connDamage.setDamage(false)
751 }
752
David Benjamin8e6db492015-07-25 18:29:23 -0400753 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700754 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400755 if test.protocol == dtls {
756 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
757 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700758 // Read until EOF.
759 _, err := io.Copy(ioutil.Discard, tlsConn)
760 return err
761 }
David Benjamin4417d052015-04-05 04:17:25 -0400762 if messageLen == 0 {
763 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700764 }
Adam Langley95c29f32014-06-20 12:00:00 -0700765
David Benjamin8e6db492015-07-25 18:29:23 -0400766 messageCount := test.messageCount
767 if messageCount == 0 {
768 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400769 }
770
David Benjamin8e6db492015-07-25 18:29:23 -0400771 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400772 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400773 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400774 }
775
David Benjamin8e6db492015-07-25 18:29:23 -0400776 for i := 0; i < test.sendEmptyRecords; i++ {
777 tlsConn.Write(nil)
778 }
779
780 for i := 0; i < test.sendWarningAlerts; i++ {
781 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
782 }
783
David Benjamin24e58862017-06-14 18:45:29 -0400784 if test.sendBogusAlertType {
785 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
786 }
787
David Benjaminbbba9392017-04-06 12:54:12 -0400788 testMessage := make([]byte, messageLen)
789 for i := range testMessage {
790 testMessage[i] = 0x42 ^ byte(j)
791 }
792 tlsConn.Write(testMessage)
793
794 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500795 if shimPrefix != "" {
796 var buf = make([]byte, len(shimPrefix))
797 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400798 if err != nil {
799 return err
800 }
Steven Valdeze831a812017-03-09 14:56:07 -0500801 if string(buf) != shimPrefix {
802 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400803 }
Steven Valdeze831a812017-03-09 14:56:07 -0500804 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400805 }
806
David Benjamin4f75aaf2015-09-01 16:53:10 -0400807 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400808 // The shim will not respond.
809 continue
810 }
811
David Benjaminbbba9392017-04-06 12:54:12 -0400812 // Process the KeyUpdate ACK. However many KeyUpdates the runner
813 // sends, the shim should respond only once.
814 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
815 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
816 return err
817 }
818 }
819
David Benjamin8e6db492015-07-25 18:29:23 -0400820 buf := make([]byte, len(testMessage))
821 if test.protocol == dtls {
822 bufTmp := make([]byte, len(buf)+1)
823 n, err := tlsConn.Read(bufTmp)
824 if err != nil {
825 return err
826 }
827 if n != len(buf) {
828 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
829 }
830 copy(buf, bufTmp)
831 } else {
832 _, err := io.ReadFull(tlsConn, buf)
833 if err != nil {
834 return err
835 }
836 }
837
838 for i, v := range buf {
839 if v != testMessage[i]^0xff {
840 return fmt.Errorf("bad reply contents at byte %d", i)
841 }
Adam Langley95c29f32014-06-20 12:00:00 -0700842 }
843 }
844
845 return nil
846}
847
David Benjamin325b5c32014-07-01 19:40:31 -0400848func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400849 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700850 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400851 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700852 }
David Benjamin325b5c32014-07-01 19:40:31 -0400853 valgrindArgs = append(valgrindArgs, path)
854 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700855
David Benjamin325b5c32014-07-01 19:40:31 -0400856 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700857}
858
David Benjamin325b5c32014-07-01 19:40:31 -0400859func gdbOf(path string, args ...string) *exec.Cmd {
860 xtermArgs := []string{"-e", "gdb", "--args"}
861 xtermArgs = append(xtermArgs, path)
862 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700863
David Benjamin325b5c32014-07-01 19:40:31 -0400864 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700865}
866
David Benjamind16bf342015-12-18 00:53:12 -0500867func lldbOf(path string, args ...string) *exec.Cmd {
868 xtermArgs := []string{"-e", "lldb", "--"}
869 xtermArgs = append(xtermArgs, path)
870 xtermArgs = append(xtermArgs, args...)
871
872 return exec.Command("xterm", xtermArgs...)
873}
874
EKR842ae6c2016-07-27 09:22:05 +0200875var (
876 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
877 errUnimplemented = errors.New("child process does not implement needed flags")
878)
Adam Langley69a01602014-11-17 17:26:55 -0800879
David Benjamin87c8a642015-02-21 01:54:29 -0500880// accept accepts a connection from listener, unless waitChan signals a process
881// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400882func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500883 type connOrError struct {
884 conn net.Conn
885 err error
886 }
887 connChan := make(chan connOrError, 1)
888 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400889 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500890 conn, err := listener.Accept()
891 connChan <- connOrError{conn, err}
892 close(connChan)
893 }()
894 select {
895 case result := <-connChan:
896 return result.conn, result.err
897 case childErr := <-waitChan:
898 waitChan <- childErr
899 return nil, fmt.Errorf("child exited early: %s", childErr)
900 }
901}
902
EKRf71d7ed2016-08-06 13:25:12 -0700903func translateExpectedError(errorStr string) string {
904 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
905 return translated
906 }
907
908 if *looseErrors {
909 return ""
910 }
911
912 return errorStr
913}
914
Adam Langley7c803a62015-06-15 15:35:05 -0700915func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400916 // Help debugging panics on the Go side.
917 defer func() {
918 if r := recover(); r != nil {
919 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
920 panic(r)
921 }
922 }()
923
Adam Langley38311732014-10-16 19:04:35 -0700924 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
925 panic("Error expected without shouldFail in " + test.name)
926 }
927
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700928 if test.expectResumeRejected && !test.resumeSession {
929 panic("expectResumeRejected without resumeSession in " + test.name)
930 }
931
Adam Langley33b1d4f2016-12-07 15:03:45 -0800932 for _, ver := range tlsVersions {
933 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
934 continue
935 }
936
David Benjamina5022392017-07-10 17:40:39 -0400937 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
938 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 -0800939 }
940
David Benjamina5022392017-07-10 17:40:39 -0400941 if ver.tls13Variant != 0 {
942 var foundFlag bool
943 for _, flag := range test.flags {
944 if flag == "-tls13-variant" {
945 foundFlag = true
946 break
947 }
948 }
949 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
950 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))
951 }
952 }
953
Adam Langley33b1d4f2016-12-07 15:03:45 -0800954 }
955
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700956 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
957 if err != nil {
958 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
959 }
David Benjamin87c8a642015-02-21 01:54:29 -0500960 if err != nil {
961 panic(err)
962 }
963 defer func() {
964 if listener != nil {
965 listener.Close()
966 }
967 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700968
David Benjamin87c8a642015-02-21 01:54:29 -0500969 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400970 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400971 flags = append(flags, "-server")
972
David Benjamin025b3d32014-07-01 19:53:04 -0400973 flags = append(flags, "-key-file")
974 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700975 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400976 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700977 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400978 }
979
980 flags = append(flags, "-cert-file")
981 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700982 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400983 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700984 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400985 }
986 }
David Benjamin5a593af2014-08-11 19:51:50 -0400987
David Benjamin6fd297b2014-08-11 18:43:38 -0400988 if test.protocol == dtls {
989 flags = append(flags, "-dtls")
990 }
991
David Benjamin46662482016-08-17 00:51:00 -0400992 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400993 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400994 resumeCount++
995 if test.resumeRenewedSession {
996 resumeCount++
997 }
998 }
999
1000 if resumeCount > 0 {
1001 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001002 }
1003
David Benjamine58c4f52014-08-24 03:47:07 -04001004 if test.shimWritesFirst {
1005 flags = append(flags, "-shim-writes-first")
1006 }
1007
David Benjaminbbba9392017-04-06 12:54:12 -04001008 if test.readWithUnfinishedWrite {
1009 flags = append(flags, "-read-with-unfinished-write")
1010 }
1011
David Benjamin30789da2015-08-29 22:56:45 -04001012 if test.shimShutsDown {
1013 flags = append(flags, "-shim-shuts-down")
1014 }
1015
David Benjaminc565ebb2015-04-03 04:06:36 -04001016 if test.exportKeyingMaterial > 0 {
1017 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1018 flags = append(flags, "-export-label", test.exportLabel)
1019 flags = append(flags, "-export-context", test.exportContext)
1020 if test.useExportContext {
1021 flags = append(flags, "-use-export-context")
1022 }
1023 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001024 if test.expectResumeRejected {
1025 flags = append(flags, "-expect-session-miss")
1026 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001027
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001028 if test.testTLSUnique {
1029 flags = append(flags, "-tls-unique")
1030 }
1031
David Benjamina5022392017-07-10 17:40:39 -04001032 if test.tls13Variant != 0 {
1033 test.config.TLS13Variant = test.tls13Variant
1034 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1035 }
1036
David Benjamin0fde2eb2017-06-30 19:11:22 -04001037 var transcriptPrefix string
1038 if len(*transcriptDir) != 0 {
1039 protocol := "tls"
1040 if test.protocol == dtls {
1041 protocol = "dtls"
1042 }
1043
1044 side := "client"
1045 if test.testType == serverTest {
1046 side = "server"
1047 }
1048
1049 dir := filepath.Join(*transcriptDir, protocol, side)
1050 if err := os.MkdirAll(dir, 0755); err != nil {
1051 return err
1052 }
1053 transcriptPrefix = filepath.Join(dir, test.name+"-")
1054 flags = append(flags, "-write-settings", transcriptPrefix)
1055 }
1056
David Benjamin025b3d32014-07-01 19:53:04 -04001057 flags = append(flags, test.flags...)
1058
1059 var shim *exec.Cmd
1060 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001061 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001062 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001063 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001064 } else if *useLLDB {
1065 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001066 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001067 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001068 }
David Benjamin025b3d32014-07-01 19:53:04 -04001069 shim.Stdin = os.Stdin
1070 var stdoutBuf, stderrBuf bytes.Buffer
1071 shim.Stdout = &stdoutBuf
1072 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001073 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001074 shim.Env = os.Environ()
1075 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001076 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001077 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001078 }
1079 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1080 }
David Benjamin025b3d32014-07-01 19:53:04 -04001081
1082 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001083 panic(err)
1084 }
David Benjamin87c8a642015-02-21 01:54:29 -05001085 waitChan := make(chan error, 1)
1086 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001087
1088 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001089
David Benjamin7a4aaa42016-09-20 17:58:14 -04001090 if *deterministic {
1091 config.Rand = &deterministicRand{}
1092 }
1093
David Benjamin87c8a642015-02-21 01:54:29 -05001094 conn, err := acceptOrWait(listener, waitChan)
1095 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001096 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001097 conn.Close()
1098 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001099
David Benjamin46662482016-08-17 00:51:00 -04001100 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001101 var resumeConfig Config
1102 if test.resumeConfig != nil {
1103 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001104 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001105 resumeConfig.SessionTicketKey = config.SessionTicketKey
1106 resumeConfig.ClientSessionCache = config.ClientSessionCache
1107 resumeConfig.ServerSessionCache = config.ServerSessionCache
1108 }
David Benjamin2e045a92016-06-08 13:09:56 -04001109 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001110 } else {
1111 resumeConfig = config
1112 }
David Benjamin87c8a642015-02-21 01:54:29 -05001113 var connResume net.Conn
1114 connResume, err = acceptOrWait(listener, waitChan)
1115 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001116 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001117 connResume.Close()
1118 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001119 }
1120
David Benjamin87c8a642015-02-21 01:54:29 -05001121 // Close the listener now. This is to avoid hangs should the shim try to
1122 // open more connections than expected.
1123 listener.Close()
1124 listener = nil
1125
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001126 var shimKilledLock sync.Mutex
1127 var shimKilled bool
1128 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1129 shimKilledLock.Lock()
1130 shimKilled = true
1131 shimKilledLock.Unlock()
1132 shim.Process.Kill()
1133 })
David Benjamin87c8a642015-02-21 01:54:29 -05001134 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001135 waitTimeout.Stop()
1136 shimKilledLock.Lock()
1137 if shimKilled && err == nil {
1138 err = errors.New("timeout waiting for the shim to exit.")
1139 }
1140 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001141 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001142 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001143 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1144 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001145 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001146 case 89:
1147 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001148 case 99:
1149 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001150 }
1151 }
Adam Langley95c29f32014-06-20 12:00:00 -07001152
David Benjamin9bea3492016-03-02 10:59:16 -05001153 // Account for Windows line endings.
1154 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1155 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001156
1157 // Separate the errors from the shim and those from tools like
1158 // AddressSanitizer.
1159 var extraStderr string
1160 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1161 stderr = stderrParts[0]
1162 extraStderr = stderrParts[1]
1163 }
1164
Adam Langley95c29f32014-06-20 12:00:00 -07001165 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001166 expectedError := translateExpectedError(test.expectedError)
1167 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001168
Adam Langleyac61fa32014-06-23 12:03:11 -07001169 localError := "none"
1170 if err != nil {
1171 localError = err.Error()
1172 }
1173 if len(test.expectedLocalError) != 0 {
1174 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1175 }
Adam Langley95c29f32014-06-20 12:00:00 -07001176
1177 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001178 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001179 if childErr != nil {
1180 childError = childErr.Error()
1181 }
1182
1183 var msg string
1184 switch {
1185 case failed && !test.shouldFail:
1186 msg = "unexpected failure"
1187 case !failed && test.shouldFail:
1188 msg = "unexpected success"
1189 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001190 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001191 default:
1192 panic("internal error")
1193 }
1194
David Benjamin9aafb642016-09-20 19:36:53 -04001195 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 -07001196 }
1197
David Benjamind2ba8892016-09-20 19:41:04 -04001198 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001199 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001200 }
1201
David Benjamind2ba8892016-09-20 19:41:04 -04001202 if *useValgrind && isValgrindError {
1203 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1204 }
1205
Adam Langley95c29f32014-06-20 12:00:00 -07001206 return nil
1207}
1208
David Benjaminaa012042016-12-10 13:33:05 -05001209type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001210 name string
1211 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001212 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001213 // excludeFlag is the legacy shim flag to disable the version.
1214 excludeFlag string
1215 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001216 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1217 versionDTLS uint16
1218 // versionWire, if non-zero, is the wire representation of the
1219 // version. Otherwise the wire version is the protocol version or
1220 // versionDTLS.
1221 versionWire uint16
1222 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001223}
1224
1225func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001226 // The shim uses the protocol version in its public API, but uses the
1227 // DTLS-specific version if it exists.
1228 if protocol == dtls && vers.versionDTLS != 0 {
1229 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001230 }
Steven Valdez520e1222017-06-13 12:45:25 -04001231 return strconv.Itoa(int(vers.version))
1232}
1233
1234func (vers tlsVersion) wire(protocol protocol) uint16 {
1235 if protocol == dtls && vers.versionDTLS != 0 {
1236 return vers.versionDTLS
1237 }
1238 if vers.versionWire != 0 {
1239 return vers.versionWire
1240 }
1241 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001242}
1243
1244var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001245 {
1246 name: "SSL3",
1247 version: VersionSSL30,
1248 excludeFlag: "-no-ssl3",
1249 },
1250 {
1251 name: "TLS1",
1252 version: VersionTLS10,
1253 excludeFlag: "-no-tls1",
1254 hasDTLS: true,
1255 versionDTLS: VersionDTLS10,
1256 },
1257 {
1258 name: "TLS11",
1259 version: VersionTLS11,
1260 excludeFlag: "-no-tls11",
1261 },
1262 {
1263 name: "TLS12",
1264 version: VersionTLS12,
1265 excludeFlag: "-no-tls12",
1266 hasDTLS: true,
1267 versionDTLS: VersionDTLS12,
1268 },
1269 {
1270 name: "TLS13",
1271 version: VersionTLS13,
1272 excludeFlag: "-no-tls13",
1273 versionWire: tls13DraftVersion,
1274 tls13Variant: TLS13Default,
1275 },
1276 {
1277 name: "TLS13Experiment",
1278 version: VersionTLS13,
1279 excludeFlag: "-no-tls13",
1280 versionWire: tls13ExperimentVersion,
1281 tls13Variant: TLS13Experiment,
1282 },
1283}
1284
1285func allVersions(protocol protocol) []tlsVersion {
1286 if protocol == tls {
1287 return tlsVersions
1288 }
1289
1290 var ret []tlsVersion
1291 for _, vers := range tlsVersions {
1292 if vers.hasDTLS {
1293 ret = append(ret, vers)
1294 }
1295 }
1296 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001297}
1298
David Benjaminaa012042016-12-10 13:33:05 -05001299type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001300 name string
1301 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001302}
1303
1304var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001305 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001306 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001307 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001308 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001309 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001310 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001311 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001312 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1313 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001314 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1315 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001316 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001317 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001318 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001319 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001320 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001321 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001322 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001323 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001324 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001325 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001326 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1327 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001328 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1329 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001330 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001331 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1332 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1333 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001334 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001335}
1336
David Benjamin8b8c0062014-11-23 02:47:52 -05001337func hasComponent(suiteName, component string) bool {
1338 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1339}
1340
David Benjaminf7768e42014-08-31 02:06:47 -04001341func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001342 return hasComponent(suiteName, "GCM") ||
1343 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001344 hasComponent(suiteName, "SHA384") ||
1345 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001346}
1347
Nick Harper1fd39d82016-06-14 18:14:35 -07001348func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001349 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001350}
1351
David Benjamin8b8c0062014-11-23 02:47:52 -05001352func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001353 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001354}
1355
Adam Langleya7997f12015-05-14 17:38:50 -07001356func bigFromHex(hex string) *big.Int {
1357 ret, ok := new(big.Int).SetString(hex, 16)
1358 if !ok {
1359 panic("failed to parse hex number 0x" + hex)
1360 }
1361 return ret
1362}
1363
Adam Langley7c803a62015-06-15 15:35:05 -07001364func addBasicTests() {
1365 basicTests := []testCase{
1366 {
Adam Langley7c803a62015-06-15 15:35:05 -07001367 name: "NoFallbackSCSV",
1368 config: Config{
1369 Bugs: ProtocolBugs{
1370 FailIfNotFallbackSCSV: true,
1371 },
1372 },
1373 shouldFail: true,
1374 expectedLocalError: "no fallback SCSV found",
1375 },
1376 {
1377 name: "SendFallbackSCSV",
1378 config: Config{
1379 Bugs: ProtocolBugs{
1380 FailIfNotFallbackSCSV: true,
1381 },
1382 },
1383 flags: []string{"-fallback-scsv"},
1384 },
1385 {
1386 name: "ClientCertificateTypes",
1387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001388 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001389 ClientAuth: RequestClientCert,
1390 ClientCertificateTypes: []byte{
1391 CertTypeDSSSign,
1392 CertTypeRSASign,
1393 CertTypeECDSASign,
1394 },
1395 },
1396 flags: []string{
1397 "-expect-certificate-types",
1398 base64.StdEncoding.EncodeToString([]byte{
1399 CertTypeDSSSign,
1400 CertTypeRSASign,
1401 CertTypeECDSASign,
1402 }),
1403 },
1404 },
1405 {
Adam Langley7c803a62015-06-15 15:35:05 -07001406 name: "UnauthenticatedECDH",
1407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1410 Bugs: ProtocolBugs{
1411 UnauthenticatedECDH: true,
1412 },
1413 },
1414 shouldFail: true,
1415 expectedError: ":UNEXPECTED_MESSAGE:",
1416 },
1417 {
1418 name: "SkipCertificateStatus",
1419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001420 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001421 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1422 Bugs: ProtocolBugs{
1423 SkipCertificateStatus: true,
1424 },
1425 },
1426 flags: []string{
1427 "-enable-ocsp-stapling",
1428 },
1429 },
1430 {
1431 name: "SkipServerKeyExchange",
1432 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001433 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001434 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1435 Bugs: ProtocolBugs{
1436 SkipServerKeyExchange: true,
1437 },
1438 },
1439 shouldFail: true,
1440 expectedError: ":UNEXPECTED_MESSAGE:",
1441 },
1442 {
Adam Langley7c803a62015-06-15 15:35:05 -07001443 testType: serverTest,
1444 name: "Alert",
1445 config: Config{
1446 Bugs: ProtocolBugs{
1447 SendSpuriousAlert: alertRecordOverflow,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1452 },
1453 {
1454 protocol: dtls,
1455 testType: serverTest,
1456 name: "Alert-DTLS",
1457 config: Config{
1458 Bugs: ProtocolBugs{
1459 SendSpuriousAlert: alertRecordOverflow,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1464 },
1465 {
1466 testType: serverTest,
1467 name: "FragmentAlert",
1468 config: Config{
1469 Bugs: ProtocolBugs{
1470 FragmentAlert: true,
1471 SendSpuriousAlert: alertRecordOverflow,
1472 },
1473 },
1474 shouldFail: true,
1475 expectedError: ":BAD_ALERT:",
1476 },
1477 {
1478 protocol: dtls,
1479 testType: serverTest,
1480 name: "FragmentAlert-DTLS",
1481 config: Config{
1482 Bugs: ProtocolBugs{
1483 FragmentAlert: true,
1484 SendSpuriousAlert: alertRecordOverflow,
1485 },
1486 },
1487 shouldFail: true,
1488 expectedError: ":BAD_ALERT:",
1489 },
1490 {
1491 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001492 name: "DoubleAlert",
1493 config: Config{
1494 Bugs: ProtocolBugs{
1495 DoubleAlert: true,
1496 SendSpuriousAlert: alertRecordOverflow,
1497 },
1498 },
1499 shouldFail: true,
1500 expectedError: ":BAD_ALERT:",
1501 },
1502 {
1503 protocol: dtls,
1504 testType: serverTest,
1505 name: "DoubleAlert-DTLS",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 DoubleAlert: true,
1509 SendSpuriousAlert: alertRecordOverflow,
1510 },
1511 },
1512 shouldFail: true,
1513 expectedError: ":BAD_ALERT:",
1514 },
1515 {
Adam Langley7c803a62015-06-15 15:35:05 -07001516 name: "SkipNewSessionTicket",
1517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001518 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001519 Bugs: ProtocolBugs{
1520 SkipNewSessionTicket: true,
1521 },
1522 },
1523 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001524 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001525 },
1526 {
1527 testType: serverTest,
1528 name: "FallbackSCSV",
1529 config: Config{
1530 MaxVersion: VersionTLS11,
1531 Bugs: ProtocolBugs{
1532 SendFallbackSCSV: true,
1533 },
1534 },
David Benjamin56cadc32016-12-16 19:54:11 -05001535 shouldFail: true,
1536 expectedError: ":INAPPROPRIATE_FALLBACK:",
1537 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001538 },
1539 {
1540 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001541 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001542 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001543 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001544 Bugs: ProtocolBugs{
1545 SendFallbackSCSV: true,
1546 },
1547 },
1548 },
1549 {
1550 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001551 name: "FallbackSCSV-VersionMatch-TLS12",
1552 config: Config{
1553 MaxVersion: VersionTLS12,
1554 Bugs: ProtocolBugs{
1555 SendFallbackSCSV: true,
1556 },
1557 },
1558 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1559 },
1560 {
1561 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001562 name: "FragmentedClientVersion",
1563 config: Config{
1564 Bugs: ProtocolBugs{
1565 MaxHandshakeRecordLength: 1,
1566 FragmentClientVersion: true,
1567 },
1568 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001569 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001570 },
1571 {
Adam Langley7c803a62015-06-15 15:35:05 -07001572 testType: serverTest,
1573 name: "HttpGET",
1574 sendPrefix: "GET / HTTP/1.0\n",
1575 shouldFail: true,
1576 expectedError: ":HTTP_REQUEST:",
1577 },
1578 {
1579 testType: serverTest,
1580 name: "HttpPOST",
1581 sendPrefix: "POST / HTTP/1.0\n",
1582 shouldFail: true,
1583 expectedError: ":HTTP_REQUEST:",
1584 },
1585 {
1586 testType: serverTest,
1587 name: "HttpHEAD",
1588 sendPrefix: "HEAD / HTTP/1.0\n",
1589 shouldFail: true,
1590 expectedError: ":HTTP_REQUEST:",
1591 },
1592 {
1593 testType: serverTest,
1594 name: "HttpPUT",
1595 sendPrefix: "PUT / HTTP/1.0\n",
1596 shouldFail: true,
1597 expectedError: ":HTTP_REQUEST:",
1598 },
1599 {
1600 testType: serverTest,
1601 name: "HttpCONNECT",
1602 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1603 shouldFail: true,
1604 expectedError: ":HTTPS_PROXY_REQUEST:",
1605 },
1606 {
1607 testType: serverTest,
1608 name: "Garbage",
1609 sendPrefix: "blah",
1610 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001611 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001612 },
1613 {
Adam Langley7c803a62015-06-15 15:35:05 -07001614 name: "RSAEphemeralKey",
1615 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001616 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001617 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1618 Bugs: ProtocolBugs{
1619 RSAEphemeralKey: true,
1620 },
1621 },
1622 shouldFail: true,
1623 expectedError: ":UNEXPECTED_MESSAGE:",
1624 },
1625 {
1626 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001627 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001628 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001629 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001630 },
1631 {
1632 protocol: dtls,
1633 name: "DisableEverything-DTLS",
1634 flags: []string{"-no-tls12", "-no-tls1"},
1635 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001636 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001637 },
1638 {
Adam Langley7c803a62015-06-15 15:35:05 -07001639 protocol: dtls,
1640 testType: serverTest,
1641 name: "MTU",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 MaxPacketLength: 256,
1645 },
1646 },
1647 flags: []string{"-mtu", "256"},
1648 },
1649 {
1650 protocol: dtls,
1651 testType: serverTest,
1652 name: "MTUExceeded",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 MaxPacketLength: 255,
1656 },
1657 },
1658 flags: []string{"-mtu", "256"},
1659 shouldFail: true,
1660 expectedLocalError: "dtls: exceeded maximum packet length",
1661 },
1662 {
Adam Langley7c803a62015-06-15 15:35:05 -07001663 name: "EmptyCertificateList",
1664 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001665 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001666 Bugs: ProtocolBugs{
1667 EmptyCertificateList: true,
1668 },
1669 },
1670 shouldFail: true,
1671 expectedError: ":DECODE_ERROR:",
1672 },
1673 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001674 name: "EmptyCertificateList-TLS13",
1675 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001676 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001677 Bugs: ProtocolBugs{
1678 EmptyCertificateList: true,
1679 },
1680 },
1681 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001682 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001683 },
1684 {
Adam Langley7c803a62015-06-15 15:35:05 -07001685 name: "TLSFatalBadPackets",
1686 damageFirstWrite: true,
1687 shouldFail: true,
1688 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1689 },
1690 {
1691 protocol: dtls,
1692 name: "DTLSIgnoreBadPackets",
1693 damageFirstWrite: true,
1694 },
1695 {
1696 protocol: dtls,
1697 name: "DTLSIgnoreBadPackets-Async",
1698 damageFirstWrite: true,
1699 flags: []string{"-async"},
1700 },
1701 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001702 name: "AppDataBeforeHandshake",
1703 config: Config{
1704 Bugs: ProtocolBugs{
1705 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1706 },
1707 },
1708 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001709 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001710 },
1711 {
1712 name: "AppDataBeforeHandshake-Empty",
1713 config: Config{
1714 Bugs: ProtocolBugs{
1715 AppDataBeforeHandshake: []byte{},
1716 },
1717 },
1718 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001719 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001720 },
1721 {
1722 protocol: dtls,
1723 name: "AppDataBeforeHandshake-DTLS",
1724 config: Config{
1725 Bugs: ProtocolBugs{
1726 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1727 },
1728 },
1729 shouldFail: true,
1730 expectedError: ":UNEXPECTED_RECORD:",
1731 },
1732 {
1733 protocol: dtls,
1734 name: "AppDataBeforeHandshake-DTLS-Empty",
1735 config: Config{
1736 Bugs: ProtocolBugs{
1737 AppDataBeforeHandshake: []byte{},
1738 },
1739 },
1740 shouldFail: true,
1741 expectedError: ":UNEXPECTED_RECORD:",
1742 },
1743 {
Adam Langley7c803a62015-06-15 15:35:05 -07001744 name: "AppDataAfterChangeCipherSpec",
1745 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001746 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001747 Bugs: ProtocolBugs{
1748 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1749 },
1750 },
1751 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001752 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001753 },
1754 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001755 name: "AppDataAfterChangeCipherSpec-Empty",
1756 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001757 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001758 Bugs: ProtocolBugs{
1759 AppDataAfterChangeCipherSpec: []byte{},
1760 },
1761 },
1762 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001763 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001764 },
1765 {
Adam Langley7c803a62015-06-15 15:35:05 -07001766 protocol: dtls,
1767 name: "AppDataAfterChangeCipherSpec-DTLS",
1768 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001769 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001770 Bugs: ProtocolBugs{
1771 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1772 },
1773 },
1774 // BoringSSL's DTLS implementation will drop the out-of-order
1775 // application data.
1776 },
1777 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001778 protocol: dtls,
1779 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001781 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001782 Bugs: ProtocolBugs{
1783 AppDataAfterChangeCipherSpec: []byte{},
1784 },
1785 },
1786 // BoringSSL's DTLS implementation will drop the out-of-order
1787 // application data.
1788 },
1789 {
Adam Langley7c803a62015-06-15 15:35:05 -07001790 name: "AlertAfterChangeCipherSpec",
1791 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001792 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001793 Bugs: ProtocolBugs{
1794 AlertAfterChangeCipherSpec: alertRecordOverflow,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1799 },
1800 {
1801 protocol: dtls,
1802 name: "AlertAfterChangeCipherSpec-DTLS",
1803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001804 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001805 Bugs: ProtocolBugs{
1806 AlertAfterChangeCipherSpec: alertRecordOverflow,
1807 },
1808 },
1809 shouldFail: true,
1810 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1811 },
1812 {
1813 protocol: dtls,
1814 name: "ReorderHandshakeFragments-Small-DTLS",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 ReorderHandshakeFragments: true,
1818 // Small enough that every handshake message is
1819 // fragmented.
1820 MaxHandshakeRecordLength: 2,
1821 },
1822 },
1823 },
1824 {
1825 protocol: dtls,
1826 name: "ReorderHandshakeFragments-Large-DTLS",
1827 config: Config{
1828 Bugs: ProtocolBugs{
1829 ReorderHandshakeFragments: true,
1830 // Large enough that no handshake message is
1831 // fragmented.
1832 MaxHandshakeRecordLength: 2048,
1833 },
1834 },
1835 },
1836 {
1837 protocol: dtls,
1838 name: "MixCompleteMessageWithFragments-DTLS",
1839 config: Config{
1840 Bugs: ProtocolBugs{
1841 ReorderHandshakeFragments: true,
1842 MixCompleteMessageWithFragments: true,
1843 MaxHandshakeRecordLength: 2,
1844 },
1845 },
1846 },
1847 {
1848 name: "SendInvalidRecordType",
1849 config: Config{
1850 Bugs: ProtocolBugs{
1851 SendInvalidRecordType: true,
1852 },
1853 },
1854 shouldFail: true,
1855 expectedError: ":UNEXPECTED_RECORD:",
1856 },
1857 {
1858 protocol: dtls,
1859 name: "SendInvalidRecordType-DTLS",
1860 config: Config{
1861 Bugs: ProtocolBugs{
1862 SendInvalidRecordType: true,
1863 },
1864 },
1865 shouldFail: true,
1866 expectedError: ":UNEXPECTED_RECORD:",
1867 },
1868 {
1869 name: "FalseStart-SkipServerSecondLeg",
1870 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001871 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001872 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1873 NextProtos: []string{"foo"},
1874 Bugs: ProtocolBugs{
1875 SkipNewSessionTicket: true,
1876 SkipChangeCipherSpec: true,
1877 SkipFinished: true,
1878 ExpectFalseStart: true,
1879 },
1880 },
1881 flags: []string{
1882 "-false-start",
1883 "-handshake-never-done",
1884 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001885 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001886 },
1887 shimWritesFirst: true,
1888 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001889 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001890 },
1891 {
1892 name: "FalseStart-SkipServerSecondLeg-Implicit",
1893 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001894 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001895 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1896 NextProtos: []string{"foo"},
1897 Bugs: ProtocolBugs{
1898 SkipNewSessionTicket: true,
1899 SkipChangeCipherSpec: true,
1900 SkipFinished: true,
1901 },
1902 },
1903 flags: []string{
1904 "-implicit-handshake",
1905 "-false-start",
1906 "-handshake-never-done",
1907 "-advertise-alpn", "\x03foo",
1908 },
1909 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001910 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001911 },
1912 {
1913 testType: serverTest,
1914 name: "FailEarlyCallback",
1915 flags: []string{"-fail-early-callback"},
1916 shouldFail: true,
1917 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001918 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001919 },
1920 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001921 name: "FailCertCallback-Client-TLS12",
1922 config: Config{
1923 MaxVersion: VersionTLS12,
1924 ClientAuth: RequestClientCert,
1925 },
1926 flags: []string{"-fail-cert-callback"},
1927 shouldFail: true,
1928 expectedError: ":CERT_CB_ERROR:",
1929 expectedLocalError: "remote error: internal error",
1930 },
1931 {
1932 testType: serverTest,
1933 name: "FailCertCallback-Server-TLS12",
1934 config: Config{
1935 MaxVersion: VersionTLS12,
1936 },
1937 flags: []string{"-fail-cert-callback"},
1938 shouldFail: true,
1939 expectedError: ":CERT_CB_ERROR:",
1940 expectedLocalError: "remote error: internal error",
1941 },
1942 {
1943 name: "FailCertCallback-Client-TLS13",
1944 config: Config{
1945 MaxVersion: VersionTLS13,
1946 ClientAuth: RequestClientCert,
1947 },
1948 flags: []string{"-fail-cert-callback"},
1949 shouldFail: true,
1950 expectedError: ":CERT_CB_ERROR:",
1951 expectedLocalError: "remote error: internal error",
1952 },
1953 {
1954 testType: serverTest,
1955 name: "FailCertCallback-Server-TLS13",
1956 config: Config{
1957 MaxVersion: VersionTLS13,
1958 },
1959 flags: []string{"-fail-cert-callback"},
1960 shouldFail: true,
1961 expectedError: ":CERT_CB_ERROR:",
1962 expectedLocalError: "remote error: internal error",
1963 },
1964 {
Adam Langley7c803a62015-06-15 15:35:05 -07001965 protocol: dtls,
1966 name: "FragmentMessageTypeMismatch-DTLS",
1967 config: Config{
1968 Bugs: ProtocolBugs{
1969 MaxHandshakeRecordLength: 2,
1970 FragmentMessageTypeMismatch: true,
1971 },
1972 },
1973 shouldFail: true,
1974 expectedError: ":FRAGMENT_MISMATCH:",
1975 },
1976 {
1977 protocol: dtls,
1978 name: "FragmentMessageLengthMismatch-DTLS",
1979 config: Config{
1980 Bugs: ProtocolBugs{
1981 MaxHandshakeRecordLength: 2,
1982 FragmentMessageLengthMismatch: true,
1983 },
1984 },
1985 shouldFail: true,
1986 expectedError: ":FRAGMENT_MISMATCH:",
1987 },
1988 {
1989 protocol: dtls,
1990 name: "SplitFragments-Header-DTLS",
1991 config: Config{
1992 Bugs: ProtocolBugs{
1993 SplitFragments: 2,
1994 },
1995 },
1996 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001997 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001998 },
1999 {
2000 protocol: dtls,
2001 name: "SplitFragments-Boundary-DTLS",
2002 config: Config{
2003 Bugs: ProtocolBugs{
2004 SplitFragments: dtlsRecordHeaderLen,
2005 },
2006 },
2007 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002008 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002009 },
2010 {
2011 protocol: dtls,
2012 name: "SplitFragments-Body-DTLS",
2013 config: Config{
2014 Bugs: ProtocolBugs{
2015 SplitFragments: dtlsRecordHeaderLen + 1,
2016 },
2017 },
2018 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002019 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002020 },
2021 {
2022 protocol: dtls,
2023 name: "SendEmptyFragments-DTLS",
2024 config: Config{
2025 Bugs: ProtocolBugs{
2026 SendEmptyFragments: true,
2027 },
2028 },
2029 },
2030 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002031 name: "BadFinished-Client",
2032 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002033 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002034 Bugs: ProtocolBugs{
2035 BadFinished: true,
2036 },
2037 },
2038 shouldFail: true,
2039 expectedError: ":DIGEST_CHECK_FAILED:",
2040 },
2041 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002042 name: "BadFinished-Client-TLS13",
2043 config: Config{
2044 MaxVersion: VersionTLS13,
2045 Bugs: ProtocolBugs{
2046 BadFinished: true,
2047 },
2048 },
2049 shouldFail: true,
2050 expectedError: ":DIGEST_CHECK_FAILED:",
2051 },
2052 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002053 testType: serverTest,
2054 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002056 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002057 Bugs: ProtocolBugs{
2058 BadFinished: true,
2059 },
2060 },
2061 shouldFail: true,
2062 expectedError: ":DIGEST_CHECK_FAILED:",
2063 },
2064 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002065 testType: serverTest,
2066 name: "BadFinished-Server-TLS13",
2067 config: Config{
2068 MaxVersion: VersionTLS13,
2069 Bugs: ProtocolBugs{
2070 BadFinished: true,
2071 },
2072 },
2073 shouldFail: true,
2074 expectedError: ":DIGEST_CHECK_FAILED:",
2075 },
2076 {
Adam Langley7c803a62015-06-15 15:35:05 -07002077 name: "FalseStart-BadFinished",
2078 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002079 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002080 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2081 NextProtos: []string{"foo"},
2082 Bugs: ProtocolBugs{
2083 BadFinished: true,
2084 ExpectFalseStart: true,
2085 },
2086 },
2087 flags: []string{
2088 "-false-start",
2089 "-handshake-never-done",
2090 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002091 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002092 },
2093 shimWritesFirst: true,
2094 shouldFail: true,
2095 expectedError: ":DIGEST_CHECK_FAILED:",
2096 },
2097 {
2098 name: "NoFalseStart-NoALPN",
2099 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002100 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002101 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2102 Bugs: ProtocolBugs{
2103 ExpectFalseStart: true,
2104 AlertBeforeFalseStartTest: alertAccessDenied,
2105 },
2106 },
2107 flags: []string{
2108 "-false-start",
2109 },
2110 shimWritesFirst: true,
2111 shouldFail: true,
2112 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2113 expectedLocalError: "tls: peer did not false start: EOF",
2114 },
2115 {
2116 name: "NoFalseStart-NoAEAD",
2117 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002118 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002119 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2120 NextProtos: []string{"foo"},
2121 Bugs: ProtocolBugs{
2122 ExpectFalseStart: true,
2123 AlertBeforeFalseStartTest: alertAccessDenied,
2124 },
2125 },
2126 flags: []string{
2127 "-false-start",
2128 "-advertise-alpn", "\x03foo",
2129 },
2130 shimWritesFirst: true,
2131 shouldFail: true,
2132 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2133 expectedLocalError: "tls: peer did not false start: EOF",
2134 },
2135 {
2136 name: "NoFalseStart-RSA",
2137 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002138 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002139 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2140 NextProtos: []string{"foo"},
2141 Bugs: ProtocolBugs{
2142 ExpectFalseStart: true,
2143 AlertBeforeFalseStartTest: alertAccessDenied,
2144 },
2145 },
2146 flags: []string{
2147 "-false-start",
2148 "-advertise-alpn", "\x03foo",
2149 },
2150 shimWritesFirst: true,
2151 shouldFail: true,
2152 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2153 expectedLocalError: "tls: peer did not false start: EOF",
2154 },
2155 {
Adam Langley7c803a62015-06-15 15:35:05 -07002156 protocol: dtls,
2157 name: "SendSplitAlert-Sync",
2158 config: Config{
2159 Bugs: ProtocolBugs{
2160 SendSplitAlert: true,
2161 },
2162 },
2163 },
2164 {
2165 protocol: dtls,
2166 name: "SendSplitAlert-Async",
2167 config: Config{
2168 Bugs: ProtocolBugs{
2169 SendSplitAlert: true,
2170 },
2171 },
2172 flags: []string{"-async"},
2173 },
2174 {
2175 protocol: dtls,
2176 name: "PackDTLSHandshake",
2177 config: Config{
2178 Bugs: ProtocolBugs{
2179 MaxHandshakeRecordLength: 2,
2180 PackHandshakeFragments: 20,
2181 PackHandshakeRecords: 200,
2182 },
2183 },
2184 },
2185 {
Adam Langley7c803a62015-06-15 15:35:05 -07002186 name: "SendEmptyRecords-Pass",
2187 sendEmptyRecords: 32,
2188 },
2189 {
2190 name: "SendEmptyRecords",
2191 sendEmptyRecords: 33,
2192 shouldFail: true,
2193 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2194 },
2195 {
2196 name: "SendEmptyRecords-Async",
2197 sendEmptyRecords: 33,
2198 flags: []string{"-async"},
2199 shouldFail: true,
2200 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2201 },
2202 {
David Benjamine8e84b92016-08-03 15:39:47 -04002203 name: "SendWarningAlerts-Pass",
2204 config: Config{
2205 MaxVersion: VersionTLS12,
2206 },
Adam Langley7c803a62015-06-15 15:35:05 -07002207 sendWarningAlerts: 4,
2208 },
2209 {
David Benjamine8e84b92016-08-03 15:39:47 -04002210 protocol: dtls,
2211 name: "SendWarningAlerts-DTLS-Pass",
2212 config: Config{
2213 MaxVersion: VersionTLS12,
2214 },
Adam Langley7c803a62015-06-15 15:35:05 -07002215 sendWarningAlerts: 4,
2216 },
2217 {
David Benjamine8e84b92016-08-03 15:39:47 -04002218 name: "SendWarningAlerts-TLS13",
2219 config: Config{
2220 MaxVersion: VersionTLS13,
2221 },
2222 sendWarningAlerts: 4,
2223 shouldFail: true,
2224 expectedError: ":BAD_ALERT:",
2225 expectedLocalError: "remote error: error decoding message",
2226 },
2227 {
2228 name: "SendWarningAlerts",
2229 config: Config{
2230 MaxVersion: VersionTLS12,
2231 },
Adam Langley7c803a62015-06-15 15:35:05 -07002232 sendWarningAlerts: 5,
2233 shouldFail: true,
2234 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2235 },
2236 {
David Benjamine8e84b92016-08-03 15:39:47 -04002237 name: "SendWarningAlerts-Async",
2238 config: Config{
2239 MaxVersion: VersionTLS12,
2240 },
Adam Langley7c803a62015-06-15 15:35:05 -07002241 sendWarningAlerts: 5,
2242 flags: []string{"-async"},
2243 shouldFail: true,
2244 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2245 },
David Benjaminba4594a2015-06-18 18:36:15 -04002246 {
David Benjamin24e58862017-06-14 18:45:29 -04002247 name: "SendBogusAlertType",
2248 sendBogusAlertType: true,
2249 shouldFail: true,
2250 expectedError: ":UNKNOWN_ALERT_TYPE:",
2251 expectedLocalError: "remote error: illegal parameter",
2252 },
2253 {
2254 protocol: dtls,
2255 name: "SendBogusAlertType-DTLS",
2256 sendBogusAlertType: true,
2257 shouldFail: true,
2258 expectedError: ":UNKNOWN_ALERT_TYPE:",
2259 expectedLocalError: "remote error: illegal parameter",
2260 },
2261 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002262 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002263 config: Config{
2264 MaxVersion: VersionTLS13,
2265 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002266 sendKeyUpdates: 33,
2267 keyUpdateRequest: keyUpdateNotRequested,
2268 shouldFail: true,
2269 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002270 },
2271 {
David Benjaminba4594a2015-06-18 18:36:15 -04002272 name: "EmptySessionID",
2273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002274 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002275 SessionTicketsDisabled: true,
2276 },
2277 noSessionCache: true,
2278 flags: []string{"-expect-no-session"},
2279 },
David Benjamin30789da2015-08-29 22:56:45 -04002280 {
2281 name: "Unclean-Shutdown",
2282 config: Config{
2283 Bugs: ProtocolBugs{
2284 NoCloseNotify: true,
2285 ExpectCloseNotify: true,
2286 },
2287 },
2288 shimShutsDown: true,
2289 flags: []string{"-check-close-notify"},
2290 shouldFail: true,
2291 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2292 },
2293 {
2294 name: "Unclean-Shutdown-Ignored",
2295 config: Config{
2296 Bugs: ProtocolBugs{
2297 NoCloseNotify: true,
2298 },
2299 },
2300 shimShutsDown: true,
2301 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002302 {
David Benjaminfa214e42016-05-10 17:03:10 -04002303 name: "Unclean-Shutdown-Alert",
2304 config: Config{
2305 Bugs: ProtocolBugs{
2306 SendAlertOnShutdown: alertDecompressionFailure,
2307 ExpectCloseNotify: true,
2308 },
2309 },
2310 shimShutsDown: true,
2311 flags: []string{"-check-close-notify"},
2312 shouldFail: true,
2313 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2314 },
2315 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002316 name: "LargePlaintext",
2317 config: Config{
2318 Bugs: ProtocolBugs{
2319 SendLargeRecords: true,
2320 },
2321 },
2322 messageLen: maxPlaintext + 1,
2323 shouldFail: true,
2324 expectedError: ":DATA_LENGTH_TOO_LONG:",
2325 },
2326 {
2327 protocol: dtls,
2328 name: "LargePlaintext-DTLS",
2329 config: Config{
2330 Bugs: ProtocolBugs{
2331 SendLargeRecords: true,
2332 },
2333 },
2334 messageLen: maxPlaintext + 1,
2335 shouldFail: true,
2336 expectedError: ":DATA_LENGTH_TOO_LONG:",
2337 },
2338 {
2339 name: "LargeCiphertext",
2340 config: Config{
2341 Bugs: ProtocolBugs{
2342 SendLargeRecords: true,
2343 },
2344 },
2345 messageLen: maxPlaintext * 2,
2346 shouldFail: true,
2347 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2348 },
2349 {
2350 protocol: dtls,
2351 name: "LargeCiphertext-DTLS",
2352 config: Config{
2353 Bugs: ProtocolBugs{
2354 SendLargeRecords: true,
2355 },
2356 },
2357 messageLen: maxPlaintext * 2,
2358 // Unlike the other four cases, DTLS drops records which
2359 // are invalid before authentication, so the connection
2360 // does not fail.
2361 expectMessageDropped: true,
2362 },
David Benjamindd6fed92015-10-23 17:41:12 -04002363 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002364 name: "BadHelloRequest-1",
2365 renegotiate: 1,
2366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002367 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002368 Bugs: ProtocolBugs{
2369 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2370 },
2371 },
2372 flags: []string{
2373 "-renegotiate-freely",
2374 "-expect-total-renegotiations", "1",
2375 },
2376 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002377 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002378 },
2379 {
2380 name: "BadHelloRequest-2",
2381 renegotiate: 1,
2382 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002383 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002384 Bugs: ProtocolBugs{
2385 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2386 },
2387 },
2388 flags: []string{
2389 "-renegotiate-freely",
2390 "-expect-total-renegotiations", "1",
2391 },
2392 shouldFail: true,
2393 expectedError: ":BAD_HELLO_REQUEST:",
2394 },
David Benjaminef1b0092015-11-21 14:05:44 -05002395 {
2396 testType: serverTest,
2397 name: "SupportTicketsWithSessionID",
2398 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002399 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002400 SessionTicketsDisabled: true,
2401 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002402 resumeConfig: &Config{
2403 MaxVersion: VersionTLS12,
2404 },
David Benjaminef1b0092015-11-21 14:05:44 -05002405 resumeSession: true,
2406 },
David Benjamin02edcd02016-07-27 17:40:37 -04002407 {
2408 protocol: dtls,
2409 name: "DTLS-SendExtraFinished",
2410 config: Config{
2411 Bugs: ProtocolBugs{
2412 SendExtraFinished: true,
2413 },
2414 },
2415 shouldFail: true,
2416 expectedError: ":UNEXPECTED_RECORD:",
2417 },
2418 {
2419 protocol: dtls,
2420 name: "DTLS-SendExtraFinished-Reordered",
2421 config: Config{
2422 Bugs: ProtocolBugs{
2423 MaxHandshakeRecordLength: 2,
2424 ReorderHandshakeFragments: true,
2425 SendExtraFinished: true,
2426 },
2427 },
2428 shouldFail: true,
2429 expectedError: ":UNEXPECTED_RECORD:",
2430 },
David Benjamine97fb482016-07-29 09:23:07 -04002431 {
2432 testType: serverTest,
2433 name: "V2ClientHello-EmptyRecordPrefix",
2434 config: Config{
2435 // Choose a cipher suite that does not involve
2436 // elliptic curves, so no extensions are
2437 // involved.
2438 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002439 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002440 Bugs: ProtocolBugs{
2441 SendV2ClientHello: true,
2442 },
2443 },
2444 sendPrefix: string([]byte{
2445 byte(recordTypeHandshake),
2446 3, 1, // version
2447 0, 0, // length
2448 }),
2449 // A no-op empty record may not be sent before V2ClientHello.
2450 shouldFail: true,
2451 expectedError: ":WRONG_VERSION_NUMBER:",
2452 },
2453 {
2454 testType: serverTest,
2455 name: "V2ClientHello-WarningAlertPrefix",
2456 config: Config{
2457 // Choose a cipher suite that does not involve
2458 // elliptic curves, so no extensions are
2459 // involved.
2460 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002461 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002462 Bugs: ProtocolBugs{
2463 SendV2ClientHello: true,
2464 },
2465 },
2466 sendPrefix: string([]byte{
2467 byte(recordTypeAlert),
2468 3, 1, // version
2469 0, 2, // length
2470 alertLevelWarning, byte(alertDecompressionFailure),
2471 }),
2472 // A no-op warning alert may not be sent before V2ClientHello.
2473 shouldFail: true,
2474 expectedError: ":WRONG_VERSION_NUMBER:",
2475 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002476 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002477 name: "KeyUpdate-Client",
2478 config: Config{
2479 MaxVersion: VersionTLS13,
2480 },
2481 sendKeyUpdates: 1,
2482 keyUpdateRequest: keyUpdateNotRequested,
2483 },
2484 {
2485 testType: serverTest,
2486 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002487 config: Config{
2488 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002489 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002490 sendKeyUpdates: 1,
2491 keyUpdateRequest: keyUpdateNotRequested,
2492 },
2493 {
2494 name: "KeyUpdate-InvalidRequestMode",
2495 config: Config{
2496 MaxVersion: VersionTLS13,
2497 },
2498 sendKeyUpdates: 1,
2499 keyUpdateRequest: 42,
2500 shouldFail: true,
2501 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002502 },
David Benjaminabe94e32016-09-04 14:18:58 -04002503 {
David Benjaminbbba9392017-04-06 12:54:12 -04002504 // Test that KeyUpdates are acknowledged properly.
2505 name: "KeyUpdate-RequestACK",
2506 config: Config{
2507 MaxVersion: VersionTLS13,
2508 Bugs: ProtocolBugs{
2509 RejectUnsolicitedKeyUpdate: true,
2510 },
2511 },
2512 // Test the shim receiving many KeyUpdates in a row.
2513 sendKeyUpdates: 5,
2514 messageCount: 5,
2515 keyUpdateRequest: keyUpdateRequested,
2516 },
2517 {
2518 // Test that KeyUpdates are acknowledged properly if the
2519 // peer's KeyUpdate is discovered while a write is
2520 // pending.
2521 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2522 config: Config{
2523 MaxVersion: VersionTLS13,
2524 Bugs: ProtocolBugs{
2525 RejectUnsolicitedKeyUpdate: true,
2526 },
2527 },
2528 // Test the shim receiving many KeyUpdates in a row.
2529 sendKeyUpdates: 5,
2530 messageCount: 5,
2531 keyUpdateRequest: keyUpdateRequested,
2532 readWithUnfinishedWrite: true,
2533 flags: []string{"-async"},
2534 },
2535 {
David Benjaminabe94e32016-09-04 14:18:58 -04002536 name: "SendSNIWarningAlert",
2537 config: Config{
2538 MaxVersion: VersionTLS12,
2539 Bugs: ProtocolBugs{
2540 SendSNIWarningAlert: true,
2541 },
2542 },
2543 },
David Benjaminc241d792016-09-09 10:34:20 -04002544 {
2545 testType: serverTest,
2546 name: "ExtraCompressionMethods-TLS12",
2547 config: Config{
2548 MaxVersion: VersionTLS12,
2549 Bugs: ProtocolBugs{
2550 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2551 },
2552 },
2553 },
2554 {
2555 testType: serverTest,
2556 name: "ExtraCompressionMethods-TLS13",
2557 config: Config{
2558 MaxVersion: VersionTLS13,
2559 Bugs: ProtocolBugs{
2560 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2561 },
2562 },
2563 shouldFail: true,
2564 expectedError: ":INVALID_COMPRESSION_LIST:",
2565 expectedLocalError: "remote error: illegal parameter",
2566 },
2567 {
2568 testType: serverTest,
2569 name: "NoNullCompression-TLS12",
2570 config: Config{
2571 MaxVersion: VersionTLS12,
2572 Bugs: ProtocolBugs{
2573 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2574 },
2575 },
2576 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002577 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002578 expectedLocalError: "remote error: illegal parameter",
2579 },
2580 {
2581 testType: serverTest,
2582 name: "NoNullCompression-TLS13",
2583 config: Config{
2584 MaxVersion: VersionTLS13,
2585 Bugs: ProtocolBugs{
2586 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2587 },
2588 },
2589 shouldFail: true,
2590 expectedError: ":INVALID_COMPRESSION_LIST:",
2591 expectedLocalError: "remote error: illegal parameter",
2592 },
David Benjamin413e79e2017-07-01 10:11:53 -04002593 // Test that the client rejects invalid compression methods
2594 // from the server.
2595 {
2596 testType: clientTest,
2597 name: "InvalidCompressionMethod",
2598 config: Config{
2599 MaxVersion: VersionTLS12,
2600 Bugs: ProtocolBugs{
2601 SendCompressionMethod: 1,
2602 },
2603 },
2604 shouldFail: true,
2605 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2606 expectedLocalError: "remote error: illegal parameter",
2607 },
David Benjamin65ac9972016-09-02 21:35:25 -04002608 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002609 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002610 config: Config{
2611 MaxVersion: VersionTLS12,
2612 Bugs: ProtocolBugs{
2613 ExpectGREASE: true,
2614 },
2615 },
2616 flags: []string{"-enable-grease"},
2617 },
2618 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002619 name: "GREASE-Client-TLS13",
2620 config: Config{
2621 MaxVersion: VersionTLS13,
2622 Bugs: ProtocolBugs{
2623 ExpectGREASE: true,
2624 },
2625 },
2626 flags: []string{"-enable-grease"},
2627 },
2628 {
2629 testType: serverTest,
2630 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002631 config: Config{
2632 MaxVersion: VersionTLS13,
2633 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002634 // TLS 1.3 servers are expected to
2635 // always enable GREASE. TLS 1.3 is new,
2636 // so there is no existing ecosystem to
2637 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002638 ExpectGREASE: true,
2639 },
2640 },
David Benjamin65ac9972016-09-02 21:35:25 -04002641 },
David Benjamine3fbb362017-01-06 16:19:28 -05002642 {
2643 // Test the server so there is a large certificate as
2644 // well as application data.
2645 testType: serverTest,
2646 name: "MaxSendFragment",
2647 config: Config{
2648 Bugs: ProtocolBugs{
2649 MaxReceivePlaintext: 512,
2650 },
2651 },
2652 messageLen: 1024,
2653 flags: []string{
2654 "-max-send-fragment", "512",
2655 "-read-size", "1024",
2656 },
2657 },
2658 {
2659 // Test the server so there is a large certificate as
2660 // well as application data.
2661 testType: serverTest,
2662 name: "MaxSendFragment-TooLarge",
2663 config: Config{
2664 Bugs: ProtocolBugs{
2665 // Ensure that some of the records are
2666 // 512.
2667 MaxReceivePlaintext: 511,
2668 },
2669 },
2670 messageLen: 1024,
2671 flags: []string{
2672 "-max-send-fragment", "512",
2673 "-read-size", "1024",
2674 },
2675 shouldFail: true,
2676 expectedLocalError: "local error: record overflow",
2677 },
Adam Langley7c803a62015-06-15 15:35:05 -07002678 }
Adam Langley7c803a62015-06-15 15:35:05 -07002679 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002680
2681 // Test that very large messages can be received.
2682 cert := rsaCertificate
2683 for i := 0; i < 50; i++ {
2684 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2685 }
2686 testCases = append(testCases, testCase{
2687 name: "LargeMessage",
2688 config: Config{
2689 Certificates: []Certificate{cert},
2690 },
2691 })
2692 testCases = append(testCases, testCase{
2693 protocol: dtls,
2694 name: "LargeMessage-DTLS",
2695 config: Config{
2696 Certificates: []Certificate{cert},
2697 },
2698 })
2699
2700 // They are rejected if the maximum certificate chain length is capped.
2701 testCases = append(testCases, testCase{
2702 name: "LargeMessage-Reject",
2703 config: Config{
2704 Certificates: []Certificate{cert},
2705 },
2706 flags: []string{"-max-cert-list", "16384"},
2707 shouldFail: true,
2708 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2709 })
2710 testCases = append(testCases, testCase{
2711 protocol: dtls,
2712 name: "LargeMessage-Reject-DTLS",
2713 config: Config{
2714 Certificates: []Certificate{cert},
2715 },
2716 flags: []string{"-max-cert-list", "16384"},
2717 shouldFail: true,
2718 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2719 })
Adam Langley7c803a62015-06-15 15:35:05 -07002720}
2721
David Benjaminaa012042016-12-10 13:33:05 -05002722func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2723 const psk = "12345"
2724 const pskIdentity = "luggage combo"
2725
2726 var prefix string
2727 if protocol == dtls {
2728 if !ver.hasDTLS {
2729 return
2730 }
2731 prefix = "D"
2732 }
2733
2734 var cert Certificate
2735 var certFile string
2736 var keyFile string
2737 if hasComponent(suite.name, "ECDSA") {
2738 cert = ecdsaP256Certificate
2739 certFile = ecdsaP256CertificateFile
2740 keyFile = ecdsaP256KeyFile
2741 } else {
2742 cert = rsaCertificate
2743 certFile = rsaCertificateFile
2744 keyFile = rsaKeyFile
2745 }
2746
2747 var flags []string
2748 if hasComponent(suite.name, "PSK") {
2749 flags = append(flags,
2750 "-psk", psk,
2751 "-psk-identity", pskIdentity)
2752 }
2753 if hasComponent(suite.name, "NULL") {
2754 // NULL ciphers must be explicitly enabled.
2755 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2756 }
David Benjaminaa012042016-12-10 13:33:05 -05002757
2758 var shouldServerFail, shouldClientFail bool
2759 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2760 // BoringSSL clients accept ECDHE on SSLv3, but
2761 // a BoringSSL server will never select it
2762 // because the extension is missing.
2763 shouldServerFail = true
2764 }
2765 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2766 shouldClientFail = true
2767 shouldServerFail = true
2768 }
2769 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2770 shouldClientFail = true
2771 shouldServerFail = true
2772 }
2773 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2774 shouldClientFail = true
2775 shouldServerFail = true
2776 }
2777 if !isDTLSCipher(suite.name) && protocol == dtls {
2778 shouldClientFail = true
2779 shouldServerFail = true
2780 }
2781
2782 var sendCipherSuite uint16
2783 var expectedServerError, expectedClientError string
2784 serverCipherSuites := []uint16{suite.id}
2785 if shouldServerFail {
2786 expectedServerError = ":NO_SHARED_CIPHER:"
2787 }
2788 if shouldClientFail {
2789 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2790 // Configure the server to select ciphers as normal but
2791 // select an incompatible cipher in ServerHello.
2792 serverCipherSuites = nil
2793 sendCipherSuite = suite.id
2794 }
2795
David Benjamincdb6fe92017-02-07 16:06:48 -05002796 // For cipher suites and versions where exporters are defined, verify
2797 // that they interoperate.
2798 var exportKeyingMaterial int
2799 if ver.version > VersionSSL30 {
2800 exportKeyingMaterial = 1024
2801 }
2802
David Benjaminaa012042016-12-10 13:33:05 -05002803 testCases = append(testCases, testCase{
2804 testType: serverTest,
2805 protocol: protocol,
2806 name: prefix + ver.name + "-" + suite.name + "-server",
2807 config: Config{
2808 MinVersion: ver.version,
2809 MaxVersion: ver.version,
2810 CipherSuites: []uint16{suite.id},
2811 Certificates: []Certificate{cert},
2812 PreSharedKey: []byte(psk),
2813 PreSharedKeyIdentity: pskIdentity,
2814 Bugs: ProtocolBugs{
2815 AdvertiseAllConfiguredCiphers: true,
2816 },
2817 },
David Benjamina5022392017-07-10 17:40:39 -04002818 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002819 certFile: certFile,
2820 keyFile: keyFile,
2821 flags: flags,
2822 resumeSession: true,
2823 shouldFail: shouldServerFail,
2824 expectedError: expectedServerError,
2825 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002826 })
2827
2828 testCases = append(testCases, testCase{
2829 testType: clientTest,
2830 protocol: protocol,
2831 name: prefix + ver.name + "-" + suite.name + "-client",
2832 config: Config{
2833 MinVersion: ver.version,
2834 MaxVersion: ver.version,
2835 CipherSuites: serverCipherSuites,
2836 Certificates: []Certificate{cert},
2837 PreSharedKey: []byte(psk),
2838 PreSharedKeyIdentity: pskIdentity,
2839 Bugs: ProtocolBugs{
2840 IgnorePeerCipherPreferences: shouldClientFail,
2841 SendCipherSuite: sendCipherSuite,
2842 },
2843 },
David Benjamina5022392017-07-10 17:40:39 -04002844 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002845 flags: flags,
2846 resumeSession: true,
2847 shouldFail: shouldClientFail,
2848 expectedError: expectedClientError,
2849 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002850 })
2851
David Benjamin6f600d62016-12-21 16:06:54 -05002852 if shouldClientFail {
2853 return
2854 }
2855
2856 // Ensure the maximum record size is accepted.
2857 testCases = append(testCases, testCase{
2858 protocol: protocol,
2859 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2860 config: Config{
2861 MinVersion: ver.version,
2862 MaxVersion: ver.version,
2863 CipherSuites: []uint16{suite.id},
2864 Certificates: []Certificate{cert},
2865 PreSharedKey: []byte(psk),
2866 PreSharedKeyIdentity: pskIdentity,
2867 },
David Benjamina5022392017-07-10 17:40:39 -04002868 tls13Variant: ver.tls13Variant,
2869 flags: flags,
2870 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002871 })
2872
2873 // Test bad records for all ciphers. Bad records are fatal in TLS
2874 // and ignored in DTLS.
2875 var shouldFail bool
2876 var expectedError string
2877 if protocol == tls {
2878 shouldFail = true
2879 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2880 }
2881
2882 testCases = append(testCases, testCase{
2883 protocol: protocol,
2884 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2885 config: Config{
2886 MinVersion: ver.version,
2887 MaxVersion: ver.version,
2888 CipherSuites: []uint16{suite.id},
2889 Certificates: []Certificate{cert},
2890 PreSharedKey: []byte(psk),
2891 PreSharedKeyIdentity: pskIdentity,
2892 },
David Benjamina5022392017-07-10 17:40:39 -04002893 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002894 flags: flags,
2895 damageFirstWrite: true,
2896 messageLen: maxPlaintext,
2897 shouldFail: shouldFail,
2898 expectedError: expectedError,
2899 })
David Benjaminaa012042016-12-10 13:33:05 -05002900}
2901
Adam Langley95c29f32014-06-20 12:00:00 -07002902func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002903 const bogusCipher = 0xfe00
2904
Adam Langley95c29f32014-06-20 12:00:00 -07002905 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002906 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002907 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002908 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002909 }
David Benjamin2c99d282015-09-01 10:23:00 -04002910 }
Adam Langley95c29f32014-06-20 12:00:00 -07002911 }
Adam Langleya7997f12015-05-14 17:38:50 -07002912
2913 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002914 name: "NoSharedCipher",
2915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002916 MaxVersion: VersionTLS12,
2917 CipherSuites: []uint16{},
2918 },
2919 shouldFail: true,
2920 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2921 })
2922
2923 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002924 name: "NoSharedCipher-TLS13",
2925 config: Config{
2926 MaxVersion: VersionTLS13,
2927 CipherSuites: []uint16{},
2928 },
2929 shouldFail: true,
2930 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2931 })
2932
2933 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002934 name: "UnsupportedCipherSuite",
2935 config: Config{
2936 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002937 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002938 Bugs: ProtocolBugs{
2939 IgnorePeerCipherPreferences: true,
2940 },
2941 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002942 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002943 shouldFail: true,
2944 expectedError: ":WRONG_CIPHER_RETURNED:",
2945 })
2946
2947 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002948 name: "ServerHelloBogusCipher",
2949 config: Config{
2950 MaxVersion: VersionTLS12,
2951 Bugs: ProtocolBugs{
2952 SendCipherSuite: bogusCipher,
2953 },
2954 },
2955 shouldFail: true,
2956 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2957 })
2958 testCases = append(testCases, testCase{
2959 name: "ServerHelloBogusCipher-TLS13",
2960 config: Config{
2961 MaxVersion: VersionTLS13,
2962 Bugs: ProtocolBugs{
2963 SendCipherSuite: bogusCipher,
2964 },
2965 },
2966 shouldFail: true,
2967 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2968 })
2969
David Benjamin241ae832016-01-15 03:04:54 -05002970 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002971 testCases = append(testCases, testCase{
2972 testType: serverTest,
2973 name: "UnknownCipher",
2974 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002975 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002976 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002977 Bugs: ProtocolBugs{
2978 AdvertiseAllConfiguredCiphers: true,
2979 },
2980 },
2981 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002982
2983 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002984 testCases = append(testCases, testCase{
2985 testType: serverTest,
2986 name: "UnknownCipher-TLS13",
2987 config: Config{
2988 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002989 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002990 Bugs: ProtocolBugs{
2991 AdvertiseAllConfiguredCiphers: true,
2992 },
David Benjamin241ae832016-01-15 03:04:54 -05002993 },
2994 })
2995
David Benjamin78679342016-09-16 19:42:05 -04002996 // Test empty ECDHE_PSK identity hints work as expected.
2997 testCases = append(testCases, testCase{
2998 name: "EmptyECDHEPSKHint",
2999 config: Config{
3000 MaxVersion: VersionTLS12,
3001 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3002 PreSharedKey: []byte("secret"),
3003 },
3004 flags: []string{"-psk", "secret"},
3005 })
3006
3007 // Test empty PSK identity hints work as expected, even if an explicit
3008 // ServerKeyExchange is sent.
3009 testCases = append(testCases, testCase{
3010 name: "ExplicitEmptyPSKHint",
3011 config: Config{
3012 MaxVersion: VersionTLS12,
3013 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3014 PreSharedKey: []byte("secret"),
3015 Bugs: ProtocolBugs{
3016 AlwaysSendPreSharedKeyIdentityHint: true,
3017 },
3018 },
3019 flags: []string{"-psk", "secret"},
3020 })
David Benjamin69522112017-03-28 15:38:29 -05003021
3022 // Test that clients enforce that the server-sent certificate and cipher
3023 // suite match in TLS 1.2.
3024 testCases = append(testCases, testCase{
3025 name: "CertificateCipherMismatch-RSA",
3026 config: Config{
3027 MaxVersion: VersionTLS12,
3028 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3029 Certificates: []Certificate{rsaCertificate},
3030 Bugs: ProtocolBugs{
3031 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3032 },
3033 },
3034 shouldFail: true,
3035 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3036 })
3037 testCases = append(testCases, testCase{
3038 name: "CertificateCipherMismatch-ECDSA",
3039 config: Config{
3040 MaxVersion: VersionTLS12,
3041 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3042 Certificates: []Certificate{ecdsaP256Certificate},
3043 Bugs: ProtocolBugs{
3044 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3045 },
3046 },
3047 shouldFail: true,
3048 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3049 })
3050 testCases = append(testCases, testCase{
3051 name: "CertificateCipherMismatch-Ed25519",
3052 config: Config{
3053 MaxVersion: VersionTLS12,
3054 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3055 Certificates: []Certificate{ed25519Certificate},
3056 Bugs: ProtocolBugs{
3057 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3058 },
3059 },
3060 shouldFail: true,
3061 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3062 })
3063
3064 // Test that servers decline to select a cipher suite which is
3065 // inconsistent with their configured certificate.
3066 testCases = append(testCases, testCase{
3067 testType: serverTest,
3068 name: "ServerCipherFilter-RSA",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3072 },
3073 flags: []string{
3074 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3075 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3076 },
3077 shouldFail: true,
3078 expectedError: ":NO_SHARED_CIPHER:",
3079 })
3080 testCases = append(testCases, testCase{
3081 testType: serverTest,
3082 name: "ServerCipherFilter-ECDSA",
3083 config: Config{
3084 MaxVersion: VersionTLS12,
3085 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3086 },
3087 flags: []string{
3088 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3089 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3090 },
3091 shouldFail: true,
3092 expectedError: ":NO_SHARED_CIPHER:",
3093 })
3094 testCases = append(testCases, testCase{
3095 testType: serverTest,
3096 name: "ServerCipherFilter-Ed25519",
3097 config: Config{
3098 MaxVersion: VersionTLS12,
3099 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3100 },
3101 flags: []string{
3102 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3103 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3104 },
3105 shouldFail: true,
3106 expectedError: ":NO_SHARED_CIPHER:",
3107 })
David Benjamin364af782017-07-01 10:35:27 -04003108
3109 // Test cipher suite negotiation works as expected. Configure a
3110 // complicated cipher suite configuration.
3111 const negotiationTestCiphers = "" +
3112 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3113 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3114 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3115 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3116 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3117 negotiationTests := []struct {
3118 ciphers []uint16
3119 expected uint16
3120 }{
3121 // Server preferences are honored, including when
3122 // equipreference groups are involved.
3123 {
3124 []uint16{
3125 TLS_RSA_WITH_AES_256_GCM_SHA384,
3126 TLS_RSA_WITH_AES_128_CBC_SHA,
3127 TLS_RSA_WITH_AES_128_GCM_SHA256,
3128 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3129 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3130 },
3131 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3132 },
3133 {
3134 []uint16{
3135 TLS_RSA_WITH_AES_256_GCM_SHA384,
3136 TLS_RSA_WITH_AES_128_CBC_SHA,
3137 TLS_RSA_WITH_AES_128_GCM_SHA256,
3138 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3139 },
3140 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3141 },
3142 {
3143 []uint16{
3144 TLS_RSA_WITH_AES_256_GCM_SHA384,
3145 TLS_RSA_WITH_AES_128_CBC_SHA,
3146 TLS_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 TLS_RSA_WITH_AES_128_GCM_SHA256,
3149 },
3150 {
3151 []uint16{
3152 TLS_RSA_WITH_AES_256_GCM_SHA384,
3153 TLS_RSA_WITH_AES_128_CBC_SHA,
3154 },
3155 TLS_RSA_WITH_AES_128_CBC_SHA,
3156 },
3157 // Equipreference groups use the client preference.
3158 {
3159 []uint16{
3160 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3161 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3162 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3163 },
3164 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3165 },
3166 {
3167 []uint16{
3168 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3169 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3170 },
3171 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3172 },
3173 {
3174 []uint16{
3175 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3176 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3177 },
3178 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3179 },
3180 {
3181 []uint16{
3182 TLS_RSA_WITH_AES_256_GCM_SHA384,
3183 TLS_RSA_WITH_AES_256_CBC_SHA,
3184 },
3185 TLS_RSA_WITH_AES_256_GCM_SHA384,
3186 },
3187 {
3188 []uint16{
3189 TLS_RSA_WITH_AES_256_CBC_SHA,
3190 TLS_RSA_WITH_AES_256_GCM_SHA384,
3191 },
3192 TLS_RSA_WITH_AES_256_CBC_SHA,
3193 },
3194 // If there are two equipreference groups, the preferred one
3195 // takes precedence.
3196 {
3197 []uint16{
3198 TLS_RSA_WITH_AES_256_GCM_SHA384,
3199 TLS_RSA_WITH_AES_256_CBC_SHA,
3200 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3201 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3202 },
3203 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3204 },
3205 }
3206 for i, t := range negotiationTests {
3207 testCases = append(testCases, testCase{
3208 testType: serverTest,
3209 name: "CipherNegotiation-" + strconv.Itoa(i),
3210 config: Config{
3211 MaxVersion: VersionTLS12,
3212 CipherSuites: t.ciphers,
3213 },
3214 flags: []string{"-cipher", negotiationTestCiphers},
3215 expectedCipher: t.expected,
3216 })
3217 }
Adam Langley95c29f32014-06-20 12:00:00 -07003218}
3219
3220func addBadECDSASignatureTests() {
3221 for badR := BadValue(1); badR < NumBadValues; badR++ {
3222 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003223 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003224 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3225 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003226 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003227 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003228 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003229 Bugs: ProtocolBugs{
3230 BadECDSAR: badR,
3231 BadECDSAS: badS,
3232 },
3233 },
3234 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003235 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003236 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003237 testCases = append(testCases, testCase{
3238 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3239 config: Config{
3240 MaxVersion: VersionTLS13,
3241 Certificates: []Certificate{ecdsaP256Certificate},
3242 Bugs: ProtocolBugs{
3243 BadECDSAR: badR,
3244 BadECDSAS: badS,
3245 },
3246 },
3247 shouldFail: true,
3248 expectedError: ":BAD_SIGNATURE:",
3249 })
Adam Langley95c29f32014-06-20 12:00:00 -07003250 }
3251 }
3252}
3253
Adam Langley80842bd2014-06-20 12:00:00 -07003254func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003255 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003256 name: "MaxCBCPadding",
3257 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003258 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003259 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3260 Bugs: ProtocolBugs{
3261 MaxPadding: true,
3262 },
3263 },
3264 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3265 })
David Benjamin025b3d32014-07-01 19:53:04 -04003266 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003267 name: "BadCBCPadding",
3268 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003269 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003270 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3271 Bugs: ProtocolBugs{
3272 PaddingFirstByteBad: true,
3273 },
3274 },
3275 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003276 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003277 })
3278 // OpenSSL previously had an issue where the first byte of padding in
3279 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003280 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003281 name: "BadCBCPadding255",
3282 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003283 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003284 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3285 Bugs: ProtocolBugs{
3286 MaxPadding: true,
3287 PaddingFirstByteBadIf255: true,
3288 },
3289 },
3290 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3291 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003292 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003293 })
3294}
3295
Kenny Root7fdeaf12014-08-05 15:23:37 -07003296func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003297 var cbcCiphers = []struct {
3298 name string
3299 cipher uint16
3300 }{
3301 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3302 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3303 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3304 }
3305 for _, t := range cbcCiphers {
3306 testCases = append(testCases, testCase{
3307 name: "CBCRecordSplitting-" + t.name,
3308 config: Config{
3309 MaxVersion: VersionTLS10,
3310 MinVersion: VersionTLS10,
3311 CipherSuites: []uint16{t.cipher},
3312 },
3313 messageLen: -1, // read until EOF
3314 resumeSession: true,
3315 flags: []string{
3316 "-async",
3317 "-write-different-record-sizes",
3318 "-cbc-record-splitting",
3319 },
3320 })
3321 testCases = append(testCases, testCase{
3322 name: "CBCRecordSplittingPartialWrite-" + t.name,
3323 config: Config{
3324 MaxVersion: VersionTLS10,
3325 MinVersion: VersionTLS10,
3326 CipherSuites: []uint16{t.cipher},
3327 },
3328 messageLen: -1, // read until EOF
3329 flags: []string{
3330 "-async",
3331 "-write-different-record-sizes",
3332 "-cbc-record-splitting",
3333 "-partial-write",
3334 },
3335 })
3336 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003337}
3338
David Benjamin636293b2014-07-08 17:59:18 -04003339func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003340 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003341 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003342 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3343 cert, err := x509.ParseCertificate(cert.Certificate[0])
3344 if err != nil {
3345 panic(err)
3346 }
3347 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003348 }
Adam Langley2ff79332017-02-28 13:45:39 -08003349 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003350
David Benjamin636293b2014-07-08 17:59:18 -04003351 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003352 testCases = append(testCases, testCase{
3353 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003354 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003355 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003356 MinVersion: ver.version,
3357 MaxVersion: ver.version,
3358 ClientAuth: RequireAnyClientCert,
3359 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003360 },
David Benjamina5022392017-07-10 17:40:39 -04003361 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003362 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003363 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3364 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003365 },
3366 })
3367 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003368 testType: serverTest,
3369 name: ver.name + "-Server-ClientAuth-RSA",
3370 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003371 MinVersion: ver.version,
3372 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003373 Certificates: []Certificate{rsaCertificate},
3374 },
David Benjamina5022392017-07-10 17:40:39 -04003375 tls13Variant: ver.tls13Variant,
3376 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003377 })
David Benjamine098ec22014-08-27 23:13:20 -04003378 if ver.version != VersionSSL30 {
3379 testCases = append(testCases, testCase{
3380 testType: serverTest,
3381 name: ver.name + "-Server-ClientAuth-ECDSA",
3382 config: Config{
3383 MinVersion: ver.version,
3384 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003385 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003386 },
David Benjamina5022392017-07-10 17:40:39 -04003387 tls13Variant: ver.tls13Variant,
3388 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003389 })
3390 testCases = append(testCases, testCase{
3391 testType: clientTest,
3392 name: ver.name + "-Client-ClientAuth-ECDSA",
3393 config: Config{
3394 MinVersion: ver.version,
3395 MaxVersion: ver.version,
3396 ClientAuth: RequireAnyClientCert,
3397 ClientCAs: certPool,
3398 },
David Benjamina5022392017-07-10 17:40:39 -04003399 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003400 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003401 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3402 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003403 },
3404 })
3405 }
Adam Langley37646832016-08-01 16:16:46 -07003406
3407 testCases = append(testCases, testCase{
3408 name: "NoClientCertificate-" + ver.name,
3409 config: Config{
3410 MinVersion: ver.version,
3411 MaxVersion: ver.version,
3412 ClientAuth: RequireAnyClientCert,
3413 },
David Benjamina5022392017-07-10 17:40:39 -04003414 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003415 shouldFail: true,
3416 expectedLocalError: "client didn't provide a certificate",
3417 })
3418
3419 testCases = append(testCases, testCase{
3420 // Even if not configured to expect a certificate, OpenSSL will
3421 // return X509_V_OK as the verify_result.
3422 testType: serverTest,
3423 name: "NoClientCertificateRequested-Server-" + ver.name,
3424 config: Config{
3425 MinVersion: ver.version,
3426 MaxVersion: ver.version,
3427 },
David Benjamina5022392017-07-10 17:40:39 -04003428 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003429 flags: []string{
3430 "-expect-verify-result",
3431 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003432 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003433 })
3434
3435 testCases = append(testCases, testCase{
3436 // If a client certificate is not provided, OpenSSL will still
3437 // return X509_V_OK as the verify_result.
3438 testType: serverTest,
3439 name: "NoClientCertificate-Server-" + ver.name,
3440 config: Config{
3441 MinVersion: ver.version,
3442 MaxVersion: ver.version,
3443 },
David Benjamina5022392017-07-10 17:40:39 -04003444 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003445 flags: []string{
3446 "-expect-verify-result",
3447 "-verify-peer",
3448 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003449 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003450 })
3451
David Benjamin1db9e1b2016-10-07 20:51:43 -04003452 certificateRequired := "remote error: certificate required"
3453 if ver.version < VersionTLS13 {
3454 // Prior to TLS 1.3, the generic handshake_failure alert
3455 // was used.
3456 certificateRequired = "remote error: handshake failure"
3457 }
Adam Langley37646832016-08-01 16:16:46 -07003458 testCases = append(testCases, testCase{
3459 testType: serverTest,
3460 name: "RequireAnyClientCertificate-" + ver.name,
3461 config: Config{
3462 MinVersion: ver.version,
3463 MaxVersion: ver.version,
3464 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003465 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003466 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003467 shouldFail: true,
3468 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3469 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003470 })
3471
3472 if ver.version != VersionSSL30 {
3473 testCases = append(testCases, testCase{
3474 testType: serverTest,
3475 name: "SkipClientCertificate-" + ver.name,
3476 config: Config{
3477 MinVersion: ver.version,
3478 MaxVersion: ver.version,
3479 Bugs: ProtocolBugs{
3480 SkipClientCertificate: true,
3481 },
3482 },
3483 // Setting SSL_VERIFY_PEER allows anonymous clients.
3484 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003485 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003486 shouldFail: true,
3487 expectedError: ":UNEXPECTED_MESSAGE:",
3488 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003489
3490 testCases = append(testCases, testCase{
3491 testType: serverTest,
3492 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3493 config: Config{
3494 MinVersion: ver.version,
3495 MaxVersion: ver.version,
3496 },
3497 flags: []string{
3498 "-enable-channel-id",
3499 "-verify-peer-if-no-obc",
3500 },
David Benjamina5022392017-07-10 17:40:39 -04003501 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003502 shouldFail: true,
3503 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3504 expectedLocalError: certificateRequired,
3505 })
3506
3507 testCases = append(testCases, testCase{
3508 testType: serverTest,
3509 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3510 config: Config{
3511 MinVersion: ver.version,
3512 MaxVersion: ver.version,
3513 ChannelID: channelIDKey,
3514 },
3515 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003516 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003517 flags: []string{
3518 "-enable-channel-id",
3519 "-verify-peer-if-no-obc",
3520 },
3521 })
Adam Langley37646832016-08-01 16:16:46 -07003522 }
Adam Langley2ff79332017-02-28 13:45:39 -08003523
3524 testCases = append(testCases, testCase{
3525 testType: serverTest,
3526 name: ver.name + "-Server-CertReq-CA-List",
3527 config: Config{
3528 MinVersion: ver.version,
3529 MaxVersion: ver.version,
3530 Certificates: []Certificate{rsaCertificate},
3531 Bugs: ProtocolBugs{
3532 ExpectCertificateReqNames: caNames,
3533 },
3534 },
David Benjamina5022392017-07-10 17:40:39 -04003535 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003536 flags: []string{
3537 "-require-any-client-certificate",
3538 "-use-client-ca-list", encodeDERValues(caNames),
3539 },
3540 })
3541
3542 testCases = append(testCases, testCase{
3543 testType: clientTest,
3544 name: ver.name + "-Client-CertReq-CA-List",
3545 config: Config{
3546 MinVersion: ver.version,
3547 MaxVersion: ver.version,
3548 Certificates: []Certificate{rsaCertificate},
3549 ClientAuth: RequireAnyClientCert,
3550 ClientCAs: certPool,
3551 },
David Benjamina5022392017-07-10 17:40:39 -04003552 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003553 flags: []string{
3554 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3555 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3556 "-expect-client-ca-list", encodeDERValues(caNames),
3557 },
3558 })
David Benjamin636293b2014-07-08 17:59:18 -04003559 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003560
David Benjaminc032dfa2016-05-12 14:54:57 -04003561 // Client auth is only legal in certificate-based ciphers.
3562 testCases = append(testCases, testCase{
3563 testType: clientTest,
3564 name: "ClientAuth-PSK",
3565 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003566 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003567 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3568 PreSharedKey: []byte("secret"),
3569 ClientAuth: RequireAnyClientCert,
3570 },
3571 flags: []string{
3572 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3573 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3574 "-psk", "secret",
3575 },
3576 shouldFail: true,
3577 expectedError: ":UNEXPECTED_MESSAGE:",
3578 })
3579 testCases = append(testCases, testCase{
3580 testType: clientTest,
3581 name: "ClientAuth-ECDHE_PSK",
3582 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003583 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003584 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3585 PreSharedKey: []byte("secret"),
3586 ClientAuth: RequireAnyClientCert,
3587 },
3588 flags: []string{
3589 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3590 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3591 "-psk", "secret",
3592 },
3593 shouldFail: true,
3594 expectedError: ":UNEXPECTED_MESSAGE:",
3595 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003596
3597 // Regression test for a bug where the client CA list, if explicitly
3598 // set to NULL, was mis-encoded.
3599 testCases = append(testCases, testCase{
3600 testType: serverTest,
3601 name: "Null-Client-CA-List",
3602 config: Config{
3603 MaxVersion: VersionTLS12,
3604 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003605 Bugs: ProtocolBugs{
3606 ExpectCertificateReqNames: [][]byte{},
3607 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003608 },
3609 flags: []string{
3610 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003611 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003612 },
3613 })
David Benjamin636293b2014-07-08 17:59:18 -04003614}
3615
Adam Langley75712922014-10-10 16:23:43 -07003616func addExtendedMasterSecretTests() {
3617 const expectEMSFlag = "-expect-extended-master-secret"
3618
3619 for _, with := range []bool{false, true} {
3620 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003621 if with {
3622 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003623 }
3624
3625 for _, isClient := range []bool{false, true} {
3626 suffix := "-Server"
3627 testType := serverTest
3628 if isClient {
3629 suffix = "-Client"
3630 testType = clientTest
3631 }
3632
3633 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003634 // In TLS 1.3, the extension is irrelevant and
3635 // always reports as enabled.
3636 var flags []string
3637 if with || ver.version >= VersionTLS13 {
3638 flags = []string{expectEMSFlag}
3639 }
3640
Adam Langley75712922014-10-10 16:23:43 -07003641 test := testCase{
3642 testType: testType,
3643 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3644 config: Config{
3645 MinVersion: ver.version,
3646 MaxVersion: ver.version,
3647 Bugs: ProtocolBugs{
3648 NoExtendedMasterSecret: !with,
3649 RequireExtendedMasterSecret: with,
3650 },
3651 },
David Benjamina5022392017-07-10 17:40:39 -04003652 tls13Variant: ver.tls13Variant,
3653 flags: flags,
3654 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003655 }
3656 if test.shouldFail {
3657 test.expectedLocalError = "extended master secret required but not supported by peer"
3658 }
3659 testCases = append(testCases, test)
3660 }
3661 }
3662 }
3663
Adam Langleyba5934b2015-06-02 10:50:35 -07003664 for _, isClient := range []bool{false, true} {
3665 for _, supportedInFirstConnection := range []bool{false, true} {
3666 for _, supportedInResumeConnection := range []bool{false, true} {
3667 boolToWord := func(b bool) string {
3668 if b {
3669 return "Yes"
3670 }
3671 return "No"
3672 }
3673 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3674 if isClient {
3675 suffix += "Client"
3676 } else {
3677 suffix += "Server"
3678 }
3679
3680 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003681 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003682 Bugs: ProtocolBugs{
3683 RequireExtendedMasterSecret: true,
3684 },
3685 }
3686
3687 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003688 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003689 Bugs: ProtocolBugs{
3690 NoExtendedMasterSecret: true,
3691 },
3692 }
3693
3694 test := testCase{
3695 name: "ExtendedMasterSecret-" + suffix,
3696 resumeSession: true,
3697 }
3698
3699 if !isClient {
3700 test.testType = serverTest
3701 }
3702
3703 if supportedInFirstConnection {
3704 test.config = supportedConfig
3705 } else {
3706 test.config = noSupportConfig
3707 }
3708
3709 if supportedInResumeConnection {
3710 test.resumeConfig = &supportedConfig
3711 } else {
3712 test.resumeConfig = &noSupportConfig
3713 }
3714
3715 switch suffix {
3716 case "YesToYes-Client", "YesToYes-Server":
3717 // When a session is resumed, it should
3718 // still be aware that its master
3719 // secret was generated via EMS and
3720 // thus it's safe to use tls-unique.
3721 test.flags = []string{expectEMSFlag}
3722 case "NoToYes-Server":
3723 // If an original connection did not
3724 // contain EMS, but a resumption
3725 // handshake does, then a server should
3726 // not resume the session.
3727 test.expectResumeRejected = true
3728 case "YesToNo-Server":
3729 // Resuming an EMS session without the
3730 // EMS extension should cause the
3731 // server to abort the connection.
3732 test.shouldFail = true
3733 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3734 case "NoToYes-Client":
3735 // A client should abort a connection
3736 // where the server resumed a non-EMS
3737 // session but echoed the EMS
3738 // extension.
3739 test.shouldFail = true
3740 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3741 case "YesToNo-Client":
3742 // A client should abort a connection
3743 // where the server didn't echo EMS
3744 // when the session used it.
3745 test.shouldFail = true
3746 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3747 }
3748
3749 testCases = append(testCases, test)
3750 }
3751 }
3752 }
David Benjamin163c9562016-08-29 23:14:17 -04003753
3754 // Switching EMS on renegotiation is forbidden.
3755 testCases = append(testCases, testCase{
3756 name: "ExtendedMasterSecret-Renego-NoEMS",
3757 config: Config{
3758 MaxVersion: VersionTLS12,
3759 Bugs: ProtocolBugs{
3760 NoExtendedMasterSecret: true,
3761 NoExtendedMasterSecretOnRenegotiation: true,
3762 },
3763 },
3764 renegotiate: 1,
3765 flags: []string{
3766 "-renegotiate-freely",
3767 "-expect-total-renegotiations", "1",
3768 },
3769 })
3770
3771 testCases = append(testCases, testCase{
3772 name: "ExtendedMasterSecret-Renego-Upgrade",
3773 config: Config{
3774 MaxVersion: VersionTLS12,
3775 Bugs: ProtocolBugs{
3776 NoExtendedMasterSecret: true,
3777 },
3778 },
3779 renegotiate: 1,
3780 flags: []string{
3781 "-renegotiate-freely",
3782 "-expect-total-renegotiations", "1",
3783 },
3784 shouldFail: true,
3785 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3786 })
3787
3788 testCases = append(testCases, testCase{
3789 name: "ExtendedMasterSecret-Renego-Downgrade",
3790 config: Config{
3791 MaxVersion: VersionTLS12,
3792 Bugs: ProtocolBugs{
3793 NoExtendedMasterSecretOnRenegotiation: true,
3794 },
3795 },
3796 renegotiate: 1,
3797 flags: []string{
3798 "-renegotiate-freely",
3799 "-expect-total-renegotiations", "1",
3800 },
3801 shouldFail: true,
3802 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3803 })
Adam Langley75712922014-10-10 16:23:43 -07003804}
3805
David Benjamin582ba042016-07-07 12:33:25 -07003806type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003807 protocol protocol
3808 async bool
3809 splitHandshake bool
3810 packHandshakeFlight bool
3811 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003812}
3813
David Benjamin43ec06f2014-08-05 02:28:57 -04003814// Adds tests that try to cover the range of the handshake state machine, under
3815// various conditions. Some of these are redundant with other tests, but they
3816// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003817func addAllStateMachineCoverageTests() {
3818 for _, async := range []bool{false, true} {
3819 for _, protocol := range []protocol{tls, dtls} {
3820 addStateMachineCoverageTests(stateMachineTestConfig{
3821 protocol: protocol,
3822 async: async,
3823 })
3824 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003825 protocol: protocol,
3826 async: async,
3827 implicitHandshake: true,
3828 })
3829 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003830 protocol: protocol,
3831 async: async,
3832 splitHandshake: true,
3833 })
3834 if protocol == tls {
3835 addStateMachineCoverageTests(stateMachineTestConfig{
3836 protocol: protocol,
3837 async: async,
3838 packHandshakeFlight: true,
3839 })
3840 }
3841 }
3842 }
3843}
3844
3845func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003846 var tests []testCase
3847
3848 // Basic handshake, with resumption. Client and server,
3849 // session ID and session ticket.
3850 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003851 name: "Basic-Client",
3852 config: Config{
3853 MaxVersion: VersionTLS12,
3854 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003855 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003856 // Ensure session tickets are used, not session IDs.
3857 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003858 })
3859 tests = append(tests, testCase{
3860 name: "Basic-Client-RenewTicket",
3861 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003862 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003863 Bugs: ProtocolBugs{
3864 RenewTicketOnResume: true,
3865 },
3866 },
David Benjamin46662482016-08-17 00:51:00 -04003867 flags: []string{"-expect-ticket-renewal"},
3868 resumeSession: true,
3869 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003870 })
3871 tests = append(tests, testCase{
3872 name: "Basic-Client-NoTicket",
3873 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003874 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003875 SessionTicketsDisabled: true,
3876 },
3877 resumeSession: true,
3878 })
3879 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003880 testType: serverTest,
3881 name: "Basic-Server",
3882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003884 Bugs: ProtocolBugs{
3885 RequireSessionTickets: true,
3886 },
3887 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003888 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003889 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003890 })
3891 tests = append(tests, testCase{
3892 testType: serverTest,
3893 name: "Basic-Server-NoTickets",
3894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003895 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003896 SessionTicketsDisabled: true,
3897 },
3898 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003899 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003900 })
3901 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003902 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003903 name: "Basic-Server-EarlyCallback",
3904 config: Config{
3905 MaxVersion: VersionTLS12,
3906 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003907 flags: []string{"-use-early-callback"},
3908 resumeSession: true,
3909 })
3910
Steven Valdez143e8b32016-07-11 13:19:03 -04003911 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003912 if config.protocol == tls {
3913 tests = append(tests, testCase{
3914 name: "TLS13-1RTT-Client",
3915 config: Config{
3916 MaxVersion: VersionTLS13,
3917 MinVersion: VersionTLS13,
3918 },
David Benjamin46662482016-08-17 00:51:00 -04003919 resumeSession: true,
3920 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003921 })
3922
3923 tests = append(tests, testCase{
3924 testType: serverTest,
3925 name: "TLS13-1RTT-Server",
3926 config: Config{
3927 MaxVersion: VersionTLS13,
3928 MinVersion: VersionTLS13,
3929 },
David Benjamin46662482016-08-17 00:51:00 -04003930 resumeSession: true,
3931 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003932 // TLS 1.3 uses tickets, so the session should not be
3933 // cached statefully.
3934 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003935 })
3936
3937 tests = append(tests, testCase{
3938 name: "TLS13-HelloRetryRequest-Client",
3939 config: Config{
3940 MaxVersion: VersionTLS13,
3941 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003942 // P-384 requires a HelloRetryRequest against BoringSSL's default
3943 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003944 CurvePreferences: []CurveID{CurveP384},
3945 Bugs: ProtocolBugs{
3946 ExpectMissingKeyShare: true,
3947 },
3948 },
3949 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3950 resumeSession: true,
3951 })
3952
3953 tests = append(tests, testCase{
3954 testType: serverTest,
3955 name: "TLS13-HelloRetryRequest-Server",
3956 config: Config{
3957 MaxVersion: VersionTLS13,
3958 MinVersion: VersionTLS13,
3959 // Require a HelloRetryRequest for every curve.
3960 DefaultCurves: []CurveID{},
3961 },
3962 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3963 resumeSession: true,
3964 })
Steven Valdez2d850622017-01-11 11:34:52 -05003965
Steven Valdez2d850622017-01-11 11:34:52 -05003966 tests = append(tests, testCase{
3967 testType: clientTest,
3968 name: "TLS13-EarlyData-Client",
3969 config: Config{
3970 MaxVersion: VersionTLS13,
3971 MinVersion: VersionTLS13,
3972 MaxEarlyDataSize: 16384,
3973 },
Steven Valdeze831a812017-03-09 14:56:07 -05003974 resumeConfig: &Config{
3975 MaxVersion: VersionTLS13,
3976 MinVersion: VersionTLS13,
3977 MaxEarlyDataSize: 16384,
3978 Bugs: ProtocolBugs{
3979 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3980 },
3981 },
Steven Valdez2d850622017-01-11 11:34:52 -05003982 resumeSession: true,
3983 flags: []string{
3984 "-enable-early-data",
3985 "-expect-early-data-info",
3986 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003987 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003988 },
3989 })
3990
3991 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003992 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04003993 name: "TLS13Experiment-EarlyData-Client",
3994 config: Config{
3995 MaxVersion: VersionTLS13,
3996 MinVersion: VersionTLS13,
3997 TLS13Variant: TLS13Experiment,
3998 MaxEarlyDataSize: 16384,
3999 },
4000 resumeConfig: &Config{
4001 MaxVersion: VersionTLS13,
4002 MinVersion: VersionTLS13,
4003 TLS13Variant: TLS13Experiment,
4004 MaxEarlyDataSize: 16384,
4005 Bugs: ProtocolBugs{
4006 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4007 },
4008 },
4009 resumeSession: true,
4010 flags: []string{
4011 "-enable-early-data",
4012 "-expect-early-data-info",
4013 "-expect-accept-early-data",
4014 "-on-resume-shim-writes-first",
4015 "-tls13-variant", "1",
4016 },
4017 })
4018
4019 tests = append(tests, testCase{
4020 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004021 name: "TLS13-EarlyData-TooMuchData-Client",
4022 config: Config{
4023 MaxVersion: VersionTLS13,
4024 MinVersion: VersionTLS13,
4025 MaxEarlyDataSize: 2,
4026 },
4027 resumeConfig: &Config{
4028 MaxVersion: VersionTLS13,
4029 MinVersion: VersionTLS13,
4030 MaxEarlyDataSize: 2,
4031 Bugs: ProtocolBugs{
4032 ExpectEarlyData: [][]byte{{'h', 'e'}},
4033 },
4034 },
4035 resumeShimPrefix: "llo",
4036 resumeSession: true,
4037 flags: []string{
4038 "-enable-early-data",
4039 "-expect-early-data-info",
4040 "-expect-accept-early-data",
4041 "-on-resume-shim-writes-first",
4042 },
4043 })
4044
4045 // Unfinished writes can only be tested when operations are async. EarlyData
4046 // can't be tested as part of an ImplicitHandshake in this case since
4047 // otherwise the early data will be sent as normal data.
4048 if config.async && !config.implicitHandshake {
4049 tests = append(tests, testCase{
4050 testType: clientTest,
4051 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4052 config: Config{
4053 MaxVersion: VersionTLS13,
4054 MinVersion: VersionTLS13,
4055 MaxEarlyDataSize: 16384,
4056 },
4057 resumeConfig: &Config{
4058 MaxVersion: VersionTLS13,
4059 MinVersion: VersionTLS13,
4060 MaxEarlyDataSize: 16384,
4061 Bugs: ProtocolBugs{
4062 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4063 },
4064 },
4065 resumeSession: true,
4066 flags: []string{
4067 "-enable-early-data",
4068 "-expect-early-data-info",
4069 "-expect-accept-early-data",
4070 "-on-resume-read-with-unfinished-write",
4071 "-on-resume-shim-writes-first",
4072 },
4073 })
4074
4075 // Rejected unfinished writes are discarded (from the
4076 // perspective of the calling application) on 0-RTT
4077 // reject.
4078 tests = append(tests, testCase{
4079 testType: clientTest,
4080 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4081 config: Config{
4082 MaxVersion: VersionTLS13,
4083 MinVersion: VersionTLS13,
4084 MaxEarlyDataSize: 16384,
4085 },
4086 resumeConfig: &Config{
4087 MaxVersion: VersionTLS13,
4088 MinVersion: VersionTLS13,
4089 MaxEarlyDataSize: 16384,
4090 Bugs: ProtocolBugs{
4091 AlwaysRejectEarlyData: true,
4092 },
4093 },
4094 resumeSession: true,
4095 flags: []string{
4096 "-enable-early-data",
4097 "-expect-early-data-info",
4098 "-expect-reject-early-data",
4099 "-on-resume-read-with-unfinished-write",
4100 "-on-resume-shim-writes-first",
4101 },
4102 })
4103 }
4104
4105 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004106 testType: serverTest,
4107 name: "TLS13-EarlyData-Server",
4108 config: Config{
4109 MaxVersion: VersionTLS13,
4110 MinVersion: VersionTLS13,
4111 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004112 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004113 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004114 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004115 },
4116 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004117 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004118 resumeSession: true,
4119 flags: []string{
4120 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004121 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004122 },
4123 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004124
4125 tests = append(tests, testCase{
4126 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004127 name: "TLS13Experiment-EarlyData-Server",
4128 config: Config{
4129 MaxVersion: VersionTLS13,
4130 MinVersion: VersionTLS13,
4131 TLS13Variant: TLS13Experiment,
4132 Bugs: ProtocolBugs{
4133 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4134 ExpectEarlyDataAccepted: true,
4135 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4136 },
4137 },
4138 messageCount: 2,
4139 resumeSession: true,
4140 flags: []string{
4141 "-enable-early-data",
4142 "-expect-accept-early-data",
4143 "-tls13-variant", "1",
4144 },
4145 })
4146
4147 tests = append(tests, testCase{
4148 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004149 name: "TLS13-MaxEarlyData-Server",
4150 config: Config{
4151 MaxVersion: VersionTLS13,
4152 MinVersion: VersionTLS13,
4153 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004154 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004155 ExpectEarlyDataAccepted: true,
4156 },
4157 },
4158 messageCount: 2,
4159 resumeSession: true,
4160 flags: []string{
4161 "-enable-early-data",
4162 "-expect-accept-early-data",
4163 },
4164 shouldFail: true,
4165 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4166 })
David Benjamine73c7f42016-08-17 00:29:33 -04004167 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004168
David Benjamin760b1dd2015-05-15 23:33:48 -04004169 // TLS client auth.
4170 tests = append(tests, testCase{
4171 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004172 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004174 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004175 ClientAuth: RequestClientCert,
4176 },
4177 })
4178 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004179 testType: serverTest,
4180 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004181 config: Config{
4182 MaxVersion: VersionTLS12,
4183 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004184 // Setting SSL_VERIFY_PEER allows anonymous clients.
4185 flags: []string{"-verify-peer"},
4186 })
David Benjamin582ba042016-07-07 12:33:25 -07004187 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004188 tests = append(tests, testCase{
4189 testType: clientTest,
4190 name: "ClientAuth-NoCertificate-Client-SSL3",
4191 config: Config{
4192 MaxVersion: VersionSSL30,
4193 ClientAuth: RequestClientCert,
4194 },
4195 })
4196 tests = append(tests, testCase{
4197 testType: serverTest,
4198 name: "ClientAuth-NoCertificate-Server-SSL3",
4199 config: Config{
4200 MaxVersion: VersionSSL30,
4201 },
4202 // Setting SSL_VERIFY_PEER allows anonymous clients.
4203 flags: []string{"-verify-peer"},
4204 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004205 tests = append(tests, testCase{
4206 testType: clientTest,
4207 name: "ClientAuth-NoCertificate-Client-TLS13",
4208 config: Config{
4209 MaxVersion: VersionTLS13,
4210 ClientAuth: RequestClientCert,
4211 },
4212 })
4213 tests = append(tests, testCase{
4214 testType: serverTest,
4215 name: "ClientAuth-NoCertificate-Server-TLS13",
4216 config: Config{
4217 MaxVersion: VersionTLS13,
4218 },
4219 // Setting SSL_VERIFY_PEER allows anonymous clients.
4220 flags: []string{"-verify-peer"},
4221 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004222 }
4223 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004224 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004225 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004227 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004228 ClientAuth: RequireAnyClientCert,
4229 },
4230 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004231 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4232 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004233 },
4234 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004235 tests = append(tests, testCase{
4236 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004237 name: "ClientAuth-RSA-Client-TLS13",
4238 config: Config{
4239 MaxVersion: VersionTLS13,
4240 ClientAuth: RequireAnyClientCert,
4241 },
4242 flags: []string{
4243 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4244 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4245 },
4246 })
4247 tests = append(tests, testCase{
4248 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004249 name: "ClientAuth-ECDSA-Client",
4250 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004251 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004252 ClientAuth: RequireAnyClientCert,
4253 },
4254 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004255 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4256 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004257 },
4258 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004259 tests = append(tests, testCase{
4260 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004261 name: "ClientAuth-ECDSA-Client-TLS13",
4262 config: Config{
4263 MaxVersion: VersionTLS13,
4264 ClientAuth: RequireAnyClientCert,
4265 },
4266 flags: []string{
4267 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4268 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4269 },
4270 })
4271 tests = append(tests, testCase{
4272 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004273 name: "ClientAuth-NoCertificate-OldCallback",
4274 config: Config{
4275 MaxVersion: VersionTLS12,
4276 ClientAuth: RequestClientCert,
4277 },
4278 flags: []string{"-use-old-client-cert-callback"},
4279 })
4280 tests = append(tests, testCase{
4281 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004282 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4283 config: Config{
4284 MaxVersion: VersionTLS13,
4285 ClientAuth: RequestClientCert,
4286 },
4287 flags: []string{"-use-old-client-cert-callback"},
4288 })
4289 tests = append(tests, testCase{
4290 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004291 name: "ClientAuth-OldCallback",
4292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004293 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004294 ClientAuth: RequireAnyClientCert,
4295 },
4296 flags: []string{
4297 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4298 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4299 "-use-old-client-cert-callback",
4300 },
4301 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004302 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004303 testType: clientTest,
4304 name: "ClientAuth-OldCallback-TLS13",
4305 config: Config{
4306 MaxVersion: VersionTLS13,
4307 ClientAuth: RequireAnyClientCert,
4308 },
4309 flags: []string{
4310 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4311 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4312 "-use-old-client-cert-callback",
4313 },
4314 })
4315 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004316 testType: serverTest,
4317 name: "ClientAuth-Server",
4318 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004319 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004320 Certificates: []Certificate{rsaCertificate},
4321 },
4322 flags: []string{"-require-any-client-certificate"},
4323 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004324 tests = append(tests, testCase{
4325 testType: serverTest,
4326 name: "ClientAuth-Server-TLS13",
4327 config: Config{
4328 MaxVersion: VersionTLS13,
4329 Certificates: []Certificate{rsaCertificate},
4330 },
4331 flags: []string{"-require-any-client-certificate"},
4332 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004333
David Benjamin4c3ddf72016-06-29 18:13:53 -04004334 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004335 tests = append(tests, testCase{
4336 testType: serverTest,
4337 name: "Basic-Server-RSA",
4338 config: Config{
4339 MaxVersion: VersionTLS12,
4340 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4341 },
4342 flags: []string{
4343 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4344 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4345 },
4346 })
4347 tests = append(tests, testCase{
4348 testType: serverTest,
4349 name: "Basic-Server-ECDHE-RSA",
4350 config: Config{
4351 MaxVersion: VersionTLS12,
4352 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4353 },
4354 flags: []string{
4355 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4356 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4357 },
4358 })
4359 tests = append(tests, testCase{
4360 testType: serverTest,
4361 name: "Basic-Server-ECDHE-ECDSA",
4362 config: Config{
4363 MaxVersion: VersionTLS12,
4364 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4365 },
4366 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004367 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4368 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004369 },
4370 })
David Benjamin69522112017-03-28 15:38:29 -05004371 tests = append(tests, testCase{
4372 testType: serverTest,
4373 name: "Basic-Server-Ed25519",
4374 config: Config{
4375 MaxVersion: VersionTLS12,
4376 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4377 },
4378 flags: []string{
4379 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4380 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4381 "-enable-ed25519",
4382 },
4383 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004384
David Benjamin760b1dd2015-05-15 23:33:48 -04004385 // No session ticket support; server doesn't send NewSessionTicket.
4386 tests = append(tests, testCase{
4387 name: "SessionTicketsDisabled-Client",
4388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004389 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004390 SessionTicketsDisabled: true,
4391 },
4392 })
4393 tests = append(tests, testCase{
4394 testType: serverTest,
4395 name: "SessionTicketsDisabled-Server",
4396 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004397 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004398 SessionTicketsDisabled: true,
4399 },
4400 })
4401
4402 // Skip ServerKeyExchange in PSK key exchange if there's no
4403 // identity hint.
4404 tests = append(tests, testCase{
4405 name: "EmptyPSKHint-Client",
4406 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004407 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004408 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4409 PreSharedKey: []byte("secret"),
4410 },
4411 flags: []string{"-psk", "secret"},
4412 })
4413 tests = append(tests, testCase{
4414 testType: serverTest,
4415 name: "EmptyPSKHint-Server",
4416 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004417 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004418 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4419 PreSharedKey: []byte("secret"),
4420 },
4421 flags: []string{"-psk", "secret"},
4422 })
4423
David Benjamin4c3ddf72016-06-29 18:13:53 -04004424 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004425 tests = append(tests, testCase{
4426 testType: clientTest,
4427 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004428 config: Config{
4429 MaxVersion: VersionTLS12,
4430 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004431 flags: []string{
4432 "-enable-ocsp-stapling",
4433 "-expect-ocsp-response",
4434 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004435 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004436 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004437 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004438 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004439 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004440 testType: serverTest,
4441 name: "OCSPStapling-Server",
4442 config: Config{
4443 MaxVersion: VersionTLS12,
4444 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004445 expectedOCSPResponse: testOCSPResponse,
4446 flags: []string{
4447 "-ocsp-response",
4448 base64.StdEncoding.EncodeToString(testOCSPResponse),
4449 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004450 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004451 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004452 tests = append(tests, testCase{
4453 testType: clientTest,
4454 name: "OCSPStapling-Client-TLS13",
4455 config: Config{
4456 MaxVersion: VersionTLS13,
4457 },
4458 flags: []string{
4459 "-enable-ocsp-stapling",
4460 "-expect-ocsp-response",
4461 base64.StdEncoding.EncodeToString(testOCSPResponse),
4462 "-verify-peer",
4463 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004464 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004465 })
4466 tests = append(tests, testCase{
4467 testType: serverTest,
4468 name: "OCSPStapling-Server-TLS13",
4469 config: Config{
4470 MaxVersion: VersionTLS13,
4471 },
4472 expectedOCSPResponse: testOCSPResponse,
4473 flags: []string{
4474 "-ocsp-response",
4475 base64.StdEncoding.EncodeToString(testOCSPResponse),
4476 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004477 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004478 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004479
David Benjamin4c3ddf72016-06-29 18:13:53 -04004480 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004481 for _, vers := range tlsVersions {
4482 if config.protocol == dtls && !vers.hasDTLS {
4483 continue
4484 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004485 for _, testType := range []testType{clientTest, serverTest} {
4486 suffix := "-Client"
4487 if testType == serverTest {
4488 suffix = "-Server"
4489 }
4490 suffix += "-" + vers.name
4491
4492 flag := "-verify-peer"
4493 if testType == serverTest {
4494 flag = "-require-any-client-certificate"
4495 }
4496
4497 tests = append(tests, testCase{
4498 testType: testType,
4499 name: "CertificateVerificationSucceed" + suffix,
4500 config: Config{
4501 MaxVersion: vers.version,
4502 Certificates: []Certificate{rsaCertificate},
4503 },
David Benjamina5022392017-07-10 17:40:39 -04004504 tls13Variant: vers.tls13Variant,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004505 flags: []string{
4506 flag,
4507 "-expect-verify-result",
4508 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004509 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004510 })
4511 tests = append(tests, testCase{
4512 testType: testType,
4513 name: "CertificateVerificationFail" + suffix,
4514 config: Config{
4515 MaxVersion: vers.version,
4516 Certificates: []Certificate{rsaCertificate},
4517 },
David Benjamina5022392017-07-10 17:40:39 -04004518 tls13Variant: vers.tls13Variant,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004519 flags: []string{
4520 flag,
4521 "-verify-fail",
4522 },
4523 shouldFail: true,
4524 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4525 })
4526 }
4527
4528 // By default, the client is in a soft fail mode where the peer
4529 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004530 tests = append(tests, testCase{
4531 testType: clientTest,
4532 name: "CertificateVerificationSoftFail-" + vers.name,
4533 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004534 MaxVersion: vers.version,
4535 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004536 },
David Benjamina5022392017-07-10 17:40:39 -04004537 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004538 flags: []string{
4539 "-verify-fail",
4540 "-expect-verify-result",
4541 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004542 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004543 })
4544 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004545
David Benjamin1d4f4c02016-07-26 18:03:08 -04004546 tests = append(tests, testCase{
4547 name: "ShimSendAlert",
4548 flags: []string{"-send-alert"},
4549 shimWritesFirst: true,
4550 shouldFail: true,
4551 expectedLocalError: "remote error: decompression failure",
4552 })
4553
David Benjamin582ba042016-07-07 12:33:25 -07004554 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004555 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004556 name: "Renegotiate-Client",
4557 config: Config{
4558 MaxVersion: VersionTLS12,
4559 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004560 renegotiate: 1,
4561 flags: []string{
4562 "-renegotiate-freely",
4563 "-expect-total-renegotiations", "1",
4564 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004565 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004566
David Benjamin47921102016-07-28 11:29:18 -04004567 tests = append(tests, testCase{
4568 name: "SendHalfHelloRequest",
4569 config: Config{
4570 MaxVersion: VersionTLS12,
4571 Bugs: ProtocolBugs{
4572 PackHelloRequestWithFinished: config.packHandshakeFlight,
4573 },
4574 },
4575 sendHalfHelloRequest: true,
4576 flags: []string{"-renegotiate-ignore"},
4577 shouldFail: true,
4578 expectedError: ":UNEXPECTED_RECORD:",
4579 })
4580
David Benjamin760b1dd2015-05-15 23:33:48 -04004581 // NPN on client and server; results in post-handshake message.
4582 tests = append(tests, testCase{
4583 name: "NPN-Client",
4584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004585 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004586 NextProtos: []string{"foo"},
4587 },
4588 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004589 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004590 expectedNextProto: "foo",
4591 expectedNextProtoType: npn,
4592 })
4593 tests = append(tests, testCase{
4594 testType: serverTest,
4595 name: "NPN-Server",
4596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004597 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004598 NextProtos: []string{"bar"},
4599 },
4600 flags: []string{
4601 "-advertise-npn", "\x03foo\x03bar\x03baz",
4602 "-expect-next-proto", "bar",
4603 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004604 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004605 expectedNextProto: "bar",
4606 expectedNextProtoType: npn,
4607 })
4608
4609 // TODO(davidben): Add tests for when False Start doesn't trigger.
4610
4611 // Client does False Start and negotiates NPN.
4612 tests = append(tests, testCase{
4613 name: "FalseStart",
4614 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004615 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004616 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4617 NextProtos: []string{"foo"},
4618 Bugs: ProtocolBugs{
4619 ExpectFalseStart: true,
4620 },
4621 },
4622 flags: []string{
4623 "-false-start",
4624 "-select-next-proto", "foo",
4625 },
4626 shimWritesFirst: true,
4627 resumeSession: true,
4628 })
4629
4630 // Client does False Start and negotiates ALPN.
4631 tests = append(tests, testCase{
4632 name: "FalseStart-ALPN",
4633 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004634 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4636 NextProtos: []string{"foo"},
4637 Bugs: ProtocolBugs{
4638 ExpectFalseStart: true,
4639 },
4640 },
4641 flags: []string{
4642 "-false-start",
4643 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004644 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004645 },
4646 shimWritesFirst: true,
4647 resumeSession: true,
4648 })
4649
David Benjamin760b1dd2015-05-15 23:33:48 -04004650 // False Start without session tickets.
4651 tests = append(tests, testCase{
4652 name: "FalseStart-SessionTicketsDisabled",
4653 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004654 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004655 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4656 NextProtos: []string{"foo"},
4657 SessionTicketsDisabled: true,
4658 Bugs: ProtocolBugs{
4659 ExpectFalseStart: true,
4660 },
4661 },
4662 flags: []string{
4663 "-false-start",
4664 "-select-next-proto", "foo",
4665 },
4666 shimWritesFirst: true,
4667 })
4668
4669 // Server parses a V2ClientHello.
4670 tests = append(tests, testCase{
4671 testType: serverTest,
4672 name: "SendV2ClientHello",
4673 config: Config{
4674 // Choose a cipher suite that does not involve
4675 // elliptic curves, so no extensions are
4676 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004677 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004678 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004679 Bugs: ProtocolBugs{
4680 SendV2ClientHello: true,
4681 },
4682 },
4683 })
4684
Nick Harper60a85cb2016-09-23 16:25:11 -07004685 // Test Channel ID
4686 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004687 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004688 continue
4689 }
4690 // Client sends a Channel ID.
4691 tests = append(tests, testCase{
4692 name: "ChannelID-Client-" + ver.name,
4693 config: Config{
4694 MaxVersion: ver.version,
4695 RequestChannelID: true,
4696 },
David Benjamina5022392017-07-10 17:40:39 -04004697 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004698 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4699 resumeSession: true,
4700 expectChannelID: true,
4701 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004702
Nick Harper60a85cb2016-09-23 16:25:11 -07004703 // Server accepts a Channel ID.
4704 tests = append(tests, testCase{
4705 testType: serverTest,
4706 name: "ChannelID-Server-" + ver.name,
4707 config: Config{
4708 MaxVersion: ver.version,
4709 ChannelID: channelIDKey,
4710 },
David Benjamina5022392017-07-10 17:40:39 -04004711 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004712 flags: []string{
4713 "-expect-channel-id",
4714 base64.StdEncoding.EncodeToString(channelIDBytes),
4715 },
4716 resumeSession: true,
4717 expectChannelID: true,
4718 })
4719
4720 tests = append(tests, testCase{
4721 testType: serverTest,
4722 name: "InvalidChannelIDSignature-" + ver.name,
4723 config: Config{
4724 MaxVersion: ver.version,
4725 ChannelID: channelIDKey,
4726 Bugs: ProtocolBugs{
4727 InvalidChannelIDSignature: true,
4728 },
4729 },
David Benjamina5022392017-07-10 17:40:39 -04004730 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004731 flags: []string{"-enable-channel-id"},
4732 shouldFail: true,
4733 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4734 })
David Benjamin634f4752017-07-01 11:08:41 -04004735
4736 if ver.version < VersionTLS13 {
4737 // Channel ID requires ECDHE ciphers.
4738 tests = append(tests, testCase{
4739 testType: serverTest,
4740 name: "ChannelID-NoECDHE-" + ver.name,
4741 config: Config{
4742 MaxVersion: ver.version,
4743 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4744 ChannelID: channelIDKey,
4745 },
4746 expectChannelID: false,
4747 flags: []string{"-enable-channel-id"},
4748 })
4749
4750 // Sanity-check setting expectChannelID false works.
4751 tests = append(tests, testCase{
4752 testType: serverTest,
4753 name: "ChannelID-ECDHE-" + ver.name,
4754 config: Config{
4755 MaxVersion: ver.version,
4756 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4757 ChannelID: channelIDKey,
4758 },
4759 expectChannelID: false,
4760 flags: []string{"-enable-channel-id"},
4761 shouldFail: true,
4762 expectedLocalError: "channel ID unexpectedly negotiated",
4763 })
4764 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004765 }
David Benjamin30789da2015-08-29 22:56:45 -04004766
David Benjaminf8fcdf32016-06-08 15:56:13 -04004767 // Channel ID and NPN at the same time, to ensure their relative
4768 // ordering is correct.
4769 tests = append(tests, testCase{
4770 name: "ChannelID-NPN-Client",
4771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004772 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004773 RequestChannelID: true,
4774 NextProtos: []string{"foo"},
4775 },
4776 flags: []string{
4777 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4778 "-select-next-proto", "foo",
4779 },
4780 resumeSession: true,
4781 expectChannelID: true,
4782 expectedNextProto: "foo",
4783 expectedNextProtoType: npn,
4784 })
4785 tests = append(tests, testCase{
4786 testType: serverTest,
4787 name: "ChannelID-NPN-Server",
4788 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004789 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004790 ChannelID: channelIDKey,
4791 NextProtos: []string{"bar"},
4792 },
4793 flags: []string{
4794 "-expect-channel-id",
4795 base64.StdEncoding.EncodeToString(channelIDBytes),
4796 "-advertise-npn", "\x03foo\x03bar\x03baz",
4797 "-expect-next-proto", "bar",
4798 },
4799 resumeSession: true,
4800 expectChannelID: true,
4801 expectedNextProto: "bar",
4802 expectedNextProtoType: npn,
4803 })
4804
David Benjamin30789da2015-08-29 22:56:45 -04004805 // Bidirectional shutdown with the runner initiating.
4806 tests = append(tests, testCase{
4807 name: "Shutdown-Runner",
4808 config: Config{
4809 Bugs: ProtocolBugs{
4810 ExpectCloseNotify: true,
4811 },
4812 },
4813 flags: []string{"-check-close-notify"},
4814 })
4815
David Benjamine3843d42017-03-25 18:00:56 -05004816 if !config.implicitHandshake {
4817 // Bidirectional shutdown with the shim initiating. The runner,
4818 // in the meantime, sends garbage before the close_notify which
4819 // the shim must ignore. This test is disabled under implicit
4820 // handshake tests because the shim never reads or writes.
4821 tests = append(tests, testCase{
4822 name: "Shutdown-Shim",
4823 config: Config{
4824 MaxVersion: VersionTLS12,
4825 Bugs: ProtocolBugs{
4826 ExpectCloseNotify: true,
4827 },
David Benjamin30789da2015-08-29 22:56:45 -04004828 },
David Benjamine3843d42017-03-25 18:00:56 -05004829 shimShutsDown: true,
4830 sendEmptyRecords: 1,
4831 sendWarningAlerts: 1,
4832 flags: []string{"-check-close-notify"},
4833 })
4834 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004835 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004836 // TODO(davidben): DTLS 1.3 will want a similar thing for
4837 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004838 tests = append(tests, testCase{
4839 name: "SkipHelloVerifyRequest",
4840 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004841 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004842 Bugs: ProtocolBugs{
4843 SkipHelloVerifyRequest: true,
4844 },
4845 },
4846 })
4847 }
4848
David Benjamin760b1dd2015-05-15 23:33:48 -04004849 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004850 test.protocol = config.protocol
4851 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004852 test.name += "-DTLS"
4853 }
David Benjamin582ba042016-07-07 12:33:25 -07004854 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004855 test.name += "-Async"
4856 test.flags = append(test.flags, "-async")
4857 } else {
4858 test.name += "-Sync"
4859 }
David Benjamin582ba042016-07-07 12:33:25 -07004860 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004861 test.name += "-SplitHandshakeRecords"
4862 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004863 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004864 test.config.Bugs.MaxPacketLength = 256
4865 test.flags = append(test.flags, "-mtu", "256")
4866 }
4867 }
David Benjamin582ba042016-07-07 12:33:25 -07004868 if config.packHandshakeFlight {
4869 test.name += "-PackHandshakeFlight"
4870 test.config.Bugs.PackHandshakeFlight = true
4871 }
David Benjamine3843d42017-03-25 18:00:56 -05004872 if config.implicitHandshake {
4873 test.name += "-ImplicitHandshake"
4874 test.flags = append(test.flags, "-implicit-handshake")
4875 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004876 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004877 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004878}
4879
Adam Langley524e7172015-02-20 16:04:00 -08004880func addDDoSCallbackTests() {
4881 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004882 for _, resume := range []bool{false, true} {
4883 suffix := "Resume"
4884 if resume {
4885 suffix = "No" + suffix
4886 }
4887
4888 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004889 testType: serverTest,
4890 name: "Server-DDoS-OK-" + suffix,
4891 config: Config{
4892 MaxVersion: VersionTLS12,
4893 },
Adam Langley524e7172015-02-20 16:04:00 -08004894 flags: []string{"-install-ddos-callback"},
4895 resumeSession: resume,
4896 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004897 testCases = append(testCases, testCase{
4898 testType: serverTest,
4899 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4900 config: Config{
4901 MaxVersion: VersionTLS13,
4902 },
4903 flags: []string{"-install-ddos-callback"},
4904 resumeSession: resume,
4905 })
Adam Langley524e7172015-02-20 16:04:00 -08004906
4907 failFlag := "-fail-ddos-callback"
4908 if resume {
4909 failFlag = "-fail-second-ddos-callback"
4910 }
4911 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004912 testType: serverTest,
4913 name: "Server-DDoS-Reject-" + suffix,
4914 config: Config{
4915 MaxVersion: VersionTLS12,
4916 },
David Benjamin2c66e072016-09-16 15:58:00 -04004917 flags: []string{"-install-ddos-callback", failFlag},
4918 resumeSession: resume,
4919 shouldFail: true,
4920 expectedError: ":CONNECTION_REJECTED:",
4921 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004922 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004923 testCases = append(testCases, testCase{
4924 testType: serverTest,
4925 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4926 config: Config{
4927 MaxVersion: VersionTLS13,
4928 },
David Benjamin2c66e072016-09-16 15:58:00 -04004929 flags: []string{"-install-ddos-callback", failFlag},
4930 resumeSession: resume,
4931 shouldFail: true,
4932 expectedError: ":CONNECTION_REJECTED:",
4933 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004934 })
Adam Langley524e7172015-02-20 16:04:00 -08004935 }
4936}
4937
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004938func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04004939 for _, protocol := range []protocol{tls, dtls} {
4940 for _, shimVers := range allVersions(protocol) {
4941 // Assemble flags to disable all newer versions on the shim.
4942 var flags []string
4943 for _, vers := range allVersions(protocol) {
4944 if vers.version > shimVers.version {
4945 flags = append(flags, vers.excludeFlag)
4946 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004947 }
Steven Valdez520e1222017-06-13 12:45:25 -04004948
4949 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
4950
4951 if shimVers.tls13Variant != 0 {
4952 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
4953 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
4954 }
4955
4956 // Test configuring the runner's maximum version.
4957 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05004958 expectedVersion := shimVers.version
4959 if runnerVers.version < shimVers.version {
4960 expectedVersion = runnerVers.version
4961 }
Steven Valdez520e1222017-06-13 12:45:25 -04004962 // When running and shim have different TLS 1.3 variants enabled,
4963 // shim clients are expected to fall back to TLS 1.2, while shim
4964 // servers support both variants when enabled when the experiment is
4965 // enabled.
4966 expectedServerVersion := expectedVersion
4967 expectedClientVersion := expectedVersion
4968 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
4969 expectedClientVersion = VersionTLS12
4970 expectedServerVersion = VersionTLS12
4971 if shimVers.tls13Variant != TLS13Default {
4972 expectedServerVersion = VersionTLS13
4973 }
4974 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004975
David Benjamin8b8c0062014-11-23 02:47:52 -05004976 suffix := shimVers.name + "-" + runnerVers.name
4977 if protocol == dtls {
4978 suffix += "-DTLS"
4979 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004980
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004981 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004982 clientVers := shimVers.version
4983 if clientVers > VersionTLS10 {
4984 clientVers = VersionTLS10
4985 }
Steven Valdez520e1222017-06-13 12:45:25 -04004986 clientVers = recordVersionToWire(clientVers, protocol)
4987 serverVers := expectedServerVersion
4988 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07004989 serverVers = VersionTLS10
4990 }
Steven Valdez520e1222017-06-13 12:45:25 -04004991 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004992
David Benjamin8b8c0062014-11-23 02:47:52 -05004993 testCases = append(testCases, testCase{
4994 protocol: protocol,
4995 testType: clientTest,
4996 name: "VersionNegotiation-Client-" + suffix,
4997 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04004998 MaxVersion: runnerVers.version,
4999 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005000 Bugs: ProtocolBugs{
5001 ExpectInitialRecordVersion: clientVers,
5002 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005003 },
5004 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005005 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005006 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005007 testCases = append(testCases, testCase{
5008 protocol: protocol,
5009 testType: clientTest,
5010 name: "VersionNegotiation-Client2-" + suffix,
5011 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005012 MaxVersion: runnerVers.version,
5013 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005014 Bugs: ProtocolBugs{
5015 ExpectInitialRecordVersion: clientVers,
5016 },
5017 },
Steven Valdez520e1222017-06-13 12:45:25 -04005018 flags: flags2,
5019 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005020 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005021
5022 testCases = append(testCases, testCase{
5023 protocol: protocol,
5024 testType: serverTest,
5025 name: "VersionNegotiation-Server-" + suffix,
5026 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005027 MaxVersion: runnerVers.version,
5028 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005029 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005030 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005031 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005032 },
5033 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005034 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005035 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005036 testCases = append(testCases, testCase{
5037 protocol: protocol,
5038 testType: serverTest,
5039 name: "VersionNegotiation-Server2-" + suffix,
5040 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005041 MaxVersion: runnerVers.version,
5042 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005043 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005044 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005045 },
5046 },
Steven Valdez520e1222017-06-13 12:45:25 -04005047 flags: flags2,
5048 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005049 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005050 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005051 }
5052 }
David Benjamin95c69562016-06-29 18:15:03 -04005053
Steven Valdezfdd10992016-09-15 16:27:05 -04005054 // Test the version extension at all versions.
5055 for _, vers := range tlsVersions {
5056 protocols := []protocol{tls}
5057 if vers.hasDTLS {
5058 protocols = append(protocols, dtls)
5059 }
5060 for _, protocol := range protocols {
5061 suffix := vers.name
5062 if protocol == dtls {
5063 suffix += "-DTLS"
5064 }
5065
Steven Valdezfdd10992016-09-15 16:27:05 -04005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 testType: serverTest,
5069 name: "VersionNegotiationExtension-" + suffix,
5070 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005071 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005072 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005073 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005074 },
5075 },
5076 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005077 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005078 })
5079 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005080 }
5081
5082 // If all versions are unknown, negotiation fails.
5083 testCases = append(testCases, testCase{
5084 testType: serverTest,
5085 name: "NoSupportedVersions",
5086 config: Config{
5087 Bugs: ProtocolBugs{
5088 SendSupportedVersions: []uint16{0x1111},
5089 },
5090 },
5091 shouldFail: true,
5092 expectedError: ":UNSUPPORTED_PROTOCOL:",
5093 })
5094 testCases = append(testCases, testCase{
5095 protocol: dtls,
5096 testType: serverTest,
5097 name: "NoSupportedVersions-DTLS",
5098 config: Config{
5099 Bugs: ProtocolBugs{
5100 SendSupportedVersions: []uint16{0x1111},
5101 },
5102 },
5103 shouldFail: true,
5104 expectedError: ":UNSUPPORTED_PROTOCOL:",
5105 })
5106
5107 testCases = append(testCases, testCase{
5108 testType: serverTest,
5109 name: "ClientHelloVersionTooHigh",
5110 config: Config{
5111 MaxVersion: VersionTLS13,
5112 Bugs: ProtocolBugs{
5113 SendClientVersion: 0x0304,
5114 OmitSupportedVersions: true,
5115 },
5116 },
5117 expectedVersion: VersionTLS12,
5118 })
5119
5120 testCases = append(testCases, testCase{
5121 testType: serverTest,
5122 name: "ConflictingVersionNegotiation",
5123 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005124 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005125 SendClientVersion: VersionTLS12,
5126 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005127 },
5128 },
David Benjaminad75a662016-09-30 15:42:59 -04005129 // The extension takes precedence over the ClientHello version.
5130 expectedVersion: VersionTLS11,
5131 })
5132
5133 testCases = append(testCases, testCase{
5134 testType: serverTest,
5135 name: "ConflictingVersionNegotiation-2",
5136 config: Config{
5137 Bugs: ProtocolBugs{
5138 SendClientVersion: VersionTLS11,
5139 SendSupportedVersions: []uint16{VersionTLS12},
5140 },
5141 },
5142 // The extension takes precedence over the ClientHello version.
5143 expectedVersion: VersionTLS12,
5144 })
5145
5146 testCases = append(testCases, testCase{
5147 testType: serverTest,
5148 name: "RejectFinalTLS13",
5149 config: Config{
5150 Bugs: ProtocolBugs{
5151 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5152 },
5153 },
5154 // We currently implement a draft TLS 1.3 version. Ensure that
5155 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005156 expectedVersion: VersionTLS12,
5157 })
5158
Steven Valdez038da9b2017-07-10 12:57:25 -04005159 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5160 // the ServerHello.
5161 testCases = append(testCases, testCase{
5162 testType: clientTest,
5163 name: "SupportedVersionSelection-TLS12",
5164 config: Config{
5165 MaxVersion: VersionTLS12,
5166 Bugs: ProtocolBugs{
5167 SendServerSupportedExtensionVersion: VersionTLS12,
5168 },
5169 },
5170 shouldFail: true,
5171 expectedError: ":UNEXPECTED_EXTENSION:",
5172 })
5173
5174 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5175 // supported_versions extension in the ServerHello.
5176 testCases = append(testCases, testCase{
5177 testType: clientTest,
5178 name: "SupportedVersionSelection-TLS13",
5179 config: Config{
5180 MaxVersion: VersionTLS13,
5181 Bugs: ProtocolBugs{
5182 SendServerSupportedExtensionVersion: tls13DraftVersion,
5183 },
5184 },
5185 shouldFail: true,
5186 expectedError: ":UNEXPECTED_EXTENSION:",
5187 })
5188
Brian Smithf85d3232016-10-28 10:34:06 -10005189 // Test that the maximum version is selected regardless of the
5190 // client-sent order.
5191 testCases = append(testCases, testCase{
5192 testType: serverTest,
5193 name: "IgnoreClientVersionOrder",
5194 config: Config{
5195 Bugs: ProtocolBugs{
5196 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5197 },
5198 },
5199 expectedVersion: VersionTLS13,
5200 })
5201
David Benjamin95c69562016-06-29 18:15:03 -04005202 // Test for version tolerance.
5203 testCases = append(testCases, testCase{
5204 testType: serverTest,
5205 name: "MinorVersionTolerance",
5206 config: Config{
5207 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005208 SendClientVersion: 0x03ff,
5209 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005210 },
5211 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005212 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005213 })
5214 testCases = append(testCases, testCase{
5215 testType: serverTest,
5216 name: "MajorVersionTolerance",
5217 config: Config{
5218 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005219 SendClientVersion: 0x0400,
5220 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005221 },
5222 },
David Benjaminad75a662016-09-30 15:42:59 -04005223 // TLS 1.3 must be negotiated with the supported_versions
5224 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005225 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005226 })
David Benjaminad75a662016-09-30 15:42:59 -04005227 testCases = append(testCases, testCase{
5228 testType: serverTest,
5229 name: "VersionTolerance-TLS13",
5230 config: Config{
5231 Bugs: ProtocolBugs{
5232 // Although TLS 1.3 does not use
5233 // ClientHello.version, it still tolerates high
5234 // values there.
5235 SendClientVersion: 0x0400,
5236 },
5237 },
5238 expectedVersion: VersionTLS13,
5239 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005240
David Benjamin95c69562016-06-29 18:15:03 -04005241 testCases = append(testCases, testCase{
5242 protocol: dtls,
5243 testType: serverTest,
5244 name: "MinorVersionTolerance-DTLS",
5245 config: Config{
5246 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005247 SendClientVersion: 0xfe00,
5248 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005249 },
5250 },
5251 expectedVersion: VersionTLS12,
5252 })
5253 testCases = append(testCases, testCase{
5254 protocol: dtls,
5255 testType: serverTest,
5256 name: "MajorVersionTolerance-DTLS",
5257 config: Config{
5258 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005259 SendClientVersion: 0xfdff,
5260 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005261 },
5262 },
5263 expectedVersion: VersionTLS12,
5264 })
5265
5266 // Test that versions below 3.0 are rejected.
5267 testCases = append(testCases, testCase{
5268 testType: serverTest,
5269 name: "VersionTooLow",
5270 config: Config{
5271 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005272 SendClientVersion: 0x0200,
5273 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005274 },
5275 },
5276 shouldFail: true,
5277 expectedError: ":UNSUPPORTED_PROTOCOL:",
5278 })
5279 testCases = append(testCases, testCase{
5280 protocol: dtls,
5281 testType: serverTest,
5282 name: "VersionTooLow-DTLS",
5283 config: Config{
5284 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005285 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005286 },
5287 },
5288 shouldFail: true,
5289 expectedError: ":UNSUPPORTED_PROTOCOL:",
5290 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005291
David Benjamin2dc02042016-09-19 19:57:37 -04005292 testCases = append(testCases, testCase{
5293 name: "ServerBogusVersion",
5294 config: Config{
5295 Bugs: ProtocolBugs{
5296 SendServerHelloVersion: 0x1234,
5297 },
5298 },
5299 shouldFail: true,
5300 expectedError: ":UNSUPPORTED_PROTOCOL:",
5301 })
5302
David Benjamin1f61f0d2016-07-10 12:20:35 -04005303 // Test TLS 1.3's downgrade signal.
5304 testCases = append(testCases, testCase{
5305 name: "Downgrade-TLS12-Client",
5306 config: Config{
5307 Bugs: ProtocolBugs{
5308 NegotiateVersion: VersionTLS12,
5309 },
5310 },
David Benjamin592b5322016-09-30 15:15:01 -04005311 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005312 // TODO(davidben): This test should fail once TLS 1.3 is final
5313 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005314 })
5315 testCases = append(testCases, testCase{
5316 testType: serverTest,
5317 name: "Downgrade-TLS12-Server",
5318 config: Config{
5319 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005320 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005321 },
5322 },
David Benjamin592b5322016-09-30 15:15:01 -04005323 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005324 // TODO(davidben): This test should fail once TLS 1.3 is final
5325 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005326 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005327}
5328
David Benjaminaccb4542014-12-12 23:44:33 -05005329func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005330 for _, protocol := range []protocol{tls, dtls} {
5331 for _, shimVers := range allVersions(protocol) {
5332 // Assemble flags to disable all older versions on the shim.
5333 var flags []string
5334 for _, vers := range allVersions(protocol) {
5335 if vers.version < shimVers.version {
5336 flags = append(flags, vers.excludeFlag)
5337 }
David Benjaminaccb4542014-12-12 23:44:33 -05005338 }
Steven Valdez520e1222017-06-13 12:45:25 -04005339
5340 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5341
5342 if shimVers.tls13Variant != 0 {
5343 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5344 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5345 }
5346
5347 for _, runnerVers := range allVersions(protocol) {
5348 // Different TLS 1.3 variants are incompatible with each other and don't
5349 // produce consistent minimum versions.
5350 //
5351 // TODO(davidben): Fold these tests (the main value is in the
5352 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5353 // on intended shim behavior, not the shim + runner combination.
5354 if shimVers.tls13Variant != runnerVers.tls13Variant {
5355 continue
5356 }
5357
David Benjaminaccb4542014-12-12 23:44:33 -05005358 suffix := shimVers.name + "-" + runnerVers.name
5359 if protocol == dtls {
5360 suffix += "-DTLS"
5361 }
David Benjaminaccb4542014-12-12 23:44:33 -05005362
David Benjaminaccb4542014-12-12 23:44:33 -05005363 var expectedVersion uint16
5364 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005365 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005366 if runnerVers.version >= shimVers.version {
5367 expectedVersion = runnerVers.version
5368 } else {
5369 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005370 expectedError = ":UNSUPPORTED_PROTOCOL:"
5371 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005372 }
5373
5374 testCases = append(testCases, testCase{
5375 protocol: protocol,
5376 testType: clientTest,
5377 name: "MinimumVersion-Client-" + suffix,
5378 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005379 MaxVersion: runnerVers.version,
5380 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005381 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005382 // Ensure the server does not decline to
5383 // select a version (versions extension) or
5384 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005385 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005386 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005387 },
David Benjaminaccb4542014-12-12 23:44:33 -05005388 },
David Benjamin87909c02014-12-13 01:55:01 -05005389 flags: flags,
5390 expectedVersion: expectedVersion,
5391 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005392 expectedError: expectedError,
5393 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005394 })
5395 testCases = append(testCases, testCase{
5396 protocol: protocol,
5397 testType: clientTest,
5398 name: "MinimumVersion-Client2-" + suffix,
5399 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005400 MaxVersion: runnerVers.version,
5401 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005402 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005403 // Ensure the server does not decline to
5404 // select a version (versions extension) or
5405 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005406 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005407 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005408 },
David Benjaminaccb4542014-12-12 23:44:33 -05005409 },
Steven Valdez520e1222017-06-13 12:45:25 -04005410 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005411 expectedVersion: expectedVersion,
5412 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005413 expectedError: expectedError,
5414 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005415 })
5416
5417 testCases = append(testCases, testCase{
5418 protocol: protocol,
5419 testType: serverTest,
5420 name: "MinimumVersion-Server-" + suffix,
5421 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005422 MaxVersion: runnerVers.version,
5423 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005424 },
David Benjamin87909c02014-12-13 01:55:01 -05005425 flags: flags,
5426 expectedVersion: expectedVersion,
5427 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005428 expectedError: expectedError,
5429 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005430 })
5431 testCases = append(testCases, testCase{
5432 protocol: protocol,
5433 testType: serverTest,
5434 name: "MinimumVersion-Server2-" + suffix,
5435 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005436 MaxVersion: runnerVers.version,
5437 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005438 },
Steven Valdez520e1222017-06-13 12:45:25 -04005439 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005440 expectedVersion: expectedVersion,
5441 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005442 expectedError: expectedError,
5443 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005444 })
5445 }
5446 }
5447 }
5448}
5449
David Benjamine78bfde2014-09-06 12:45:15 -04005450func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005451 // TODO(davidben): Extensions, where applicable, all move their server
5452 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5453 // tests for both. Also test interaction with 0-RTT when implemented.
5454
David Benjamin97d17d92016-07-14 16:12:00 -04005455 // Repeat extensions tests all versions except SSL 3.0.
5456 for _, ver := range tlsVersions {
5457 if ver.version == VersionSSL30 {
5458 continue
5459 }
5460
David Benjamin97d17d92016-07-14 16:12:00 -04005461 // Test that duplicate extensions are rejected.
5462 testCases = append(testCases, testCase{
5463 testType: clientTest,
5464 name: "DuplicateExtensionClient-" + ver.name,
5465 config: Config{
5466 MaxVersion: ver.version,
5467 Bugs: ProtocolBugs{
5468 DuplicateExtension: true,
5469 },
David Benjamine78bfde2014-09-06 12:45:15 -04005470 },
David Benjamina5022392017-07-10 17:40:39 -04005471 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005472 shouldFail: true,
5473 expectedLocalError: "remote error: error decoding message",
5474 })
5475 testCases = append(testCases, testCase{
5476 testType: serverTest,
5477 name: "DuplicateExtensionServer-" + ver.name,
5478 config: Config{
5479 MaxVersion: ver.version,
5480 Bugs: ProtocolBugs{
5481 DuplicateExtension: true,
5482 },
David Benjamine78bfde2014-09-06 12:45:15 -04005483 },
David Benjamina5022392017-07-10 17:40:39 -04005484 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005485 shouldFail: true,
5486 expectedLocalError: "remote error: error decoding message",
5487 })
5488
5489 // Test SNI.
5490 testCases = append(testCases, testCase{
5491 testType: clientTest,
5492 name: "ServerNameExtensionClient-" + ver.name,
5493 config: Config{
5494 MaxVersion: ver.version,
5495 Bugs: ProtocolBugs{
5496 ExpectServerName: "example.com",
5497 },
David Benjamine78bfde2014-09-06 12:45:15 -04005498 },
David Benjamina5022392017-07-10 17:40:39 -04005499 tls13Variant: ver.tls13Variant,
5500 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005501 })
5502 testCases = append(testCases, testCase{
5503 testType: clientTest,
5504 name: "ServerNameExtensionClientMismatch-" + ver.name,
5505 config: Config{
5506 MaxVersion: ver.version,
5507 Bugs: ProtocolBugs{
5508 ExpectServerName: "mismatch.com",
5509 },
David Benjamine78bfde2014-09-06 12:45:15 -04005510 },
David Benjamin97d17d92016-07-14 16:12:00 -04005511 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005512 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005513 shouldFail: true,
5514 expectedLocalError: "tls: unexpected server name",
5515 })
5516 testCases = append(testCases, testCase{
5517 testType: clientTest,
5518 name: "ServerNameExtensionClientMissing-" + ver.name,
5519 config: Config{
5520 MaxVersion: ver.version,
5521 Bugs: ProtocolBugs{
5522 ExpectServerName: "missing.com",
5523 },
David Benjamine78bfde2014-09-06 12:45:15 -04005524 },
David Benjamina5022392017-07-10 17:40:39 -04005525 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005526 shouldFail: true,
5527 expectedLocalError: "tls: unexpected server name",
5528 })
5529 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005530 testType: clientTest,
5531 name: "TolerateServerNameAck-" + ver.name,
5532 config: Config{
5533 MaxVersion: ver.version,
5534 Bugs: ProtocolBugs{
5535 SendServerNameAck: true,
5536 },
5537 },
David Benjamina5022392017-07-10 17:40:39 -04005538 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005539 flags: []string{"-host-name", "example.com"},
5540 resumeSession: true,
5541 })
5542 testCases = append(testCases, testCase{
5543 testType: clientTest,
5544 name: "UnsolicitedServerNameAck-" + ver.name,
5545 config: Config{
5546 MaxVersion: ver.version,
5547 Bugs: ProtocolBugs{
5548 SendServerNameAck: true,
5549 },
5550 },
David Benjamina5022392017-07-10 17:40:39 -04005551 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005552 shouldFail: true,
5553 expectedError: ":UNEXPECTED_EXTENSION:",
5554 expectedLocalError: "remote error: unsupported extension",
5555 })
5556 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005557 testType: serverTest,
5558 name: "ServerNameExtensionServer-" + ver.name,
5559 config: Config{
5560 MaxVersion: ver.version,
5561 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005562 },
David Benjamina5022392017-07-10 17:40:39 -04005563 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005564 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005565 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005566 })
5567
5568 // Test ALPN.
5569 testCases = append(testCases, testCase{
5570 testType: clientTest,
5571 name: "ALPNClient-" + ver.name,
5572 config: Config{
5573 MaxVersion: ver.version,
5574 NextProtos: []string{"foo"},
5575 },
5576 flags: []string{
5577 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5578 "-expect-alpn", "foo",
5579 },
David Benjamina5022392017-07-10 17:40:39 -04005580 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005581 expectedNextProto: "foo",
5582 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005583 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005584 })
5585 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005586 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005587 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005588 config: Config{
5589 MaxVersion: ver.version,
5590 Bugs: ProtocolBugs{
5591 SendALPN: "baz",
5592 },
5593 },
5594 flags: []string{
5595 "-advertise-alpn", "\x03foo\x03bar",
5596 },
David Benjamina5022392017-07-10 17:40:39 -04005597 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005598 shouldFail: true,
5599 expectedError: ":INVALID_ALPN_PROTOCOL:",
5600 expectedLocalError: "remote error: illegal parameter",
5601 })
5602 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005603 testType: clientTest,
5604 name: "ALPNClient-AllowUnknown-" + ver.name,
5605 config: Config{
5606 MaxVersion: ver.version,
5607 Bugs: ProtocolBugs{
5608 SendALPN: "baz",
5609 },
5610 },
5611 flags: []string{
5612 "-advertise-alpn", "\x03foo\x03bar",
5613 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005614 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005615 },
David Benjamina5022392017-07-10 17:40:39 -04005616 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005617 })
5618 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005619 testType: serverTest,
5620 name: "ALPNServer-" + ver.name,
5621 config: Config{
5622 MaxVersion: ver.version,
5623 NextProtos: []string{"foo", "bar", "baz"},
5624 },
5625 flags: []string{
5626 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5627 "-select-alpn", "foo",
5628 },
David Benjamina5022392017-07-10 17:40:39 -04005629 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005630 expectedNextProto: "foo",
5631 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005632 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005633 })
5634 testCases = append(testCases, testCase{
5635 testType: serverTest,
5636 name: "ALPNServer-Decline-" + ver.name,
5637 config: Config{
5638 MaxVersion: ver.version,
5639 NextProtos: []string{"foo", "bar", "baz"},
5640 },
5641 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005642 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005643 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005644 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005645 })
5646
David Benjamin25fe85b2016-08-09 20:00:32 -04005647 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5648 // called once.
5649 testCases = append(testCases, testCase{
5650 testType: serverTest,
5651 name: "ALPNServer-Async-" + ver.name,
5652 config: Config{
5653 MaxVersion: ver.version,
5654 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005655 // Prior to TLS 1.3, exercise the asynchronous session callback.
5656 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005657 },
5658 flags: []string{
5659 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5660 "-select-alpn", "foo",
5661 "-async",
5662 },
David Benjamina5022392017-07-10 17:40:39 -04005663 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005664 expectedNextProto: "foo",
5665 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005666 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005667 })
5668
David Benjamin97d17d92016-07-14 16:12:00 -04005669 var emptyString string
5670 testCases = append(testCases, testCase{
5671 testType: clientTest,
5672 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5673 config: Config{
5674 MaxVersion: ver.version,
5675 NextProtos: []string{""},
5676 Bugs: ProtocolBugs{
5677 // A server returning an empty ALPN protocol
5678 // should be rejected.
5679 ALPNProtocol: &emptyString,
5680 },
5681 },
5682 flags: []string{
5683 "-advertise-alpn", "\x03foo",
5684 },
David Benjamina5022392017-07-10 17:40:39 -04005685 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005686 shouldFail: true,
5687 expectedError: ":PARSE_TLSEXT:",
5688 })
5689 testCases = append(testCases, testCase{
5690 testType: serverTest,
5691 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5692 config: Config{
5693 MaxVersion: ver.version,
5694 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005695 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005696 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005697 },
David Benjamin97d17d92016-07-14 16:12:00 -04005698 flags: []string{
5699 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005700 },
David Benjamina5022392017-07-10 17:40:39 -04005701 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005702 shouldFail: true,
5703 expectedError: ":PARSE_TLSEXT:",
5704 })
5705
5706 // Test NPN and the interaction with ALPN.
5707 if ver.version < VersionTLS13 {
5708 // Test that the server prefers ALPN over NPN.
5709 testCases = append(testCases, testCase{
5710 testType: serverTest,
5711 name: "ALPNServer-Preferred-" + ver.name,
5712 config: Config{
5713 MaxVersion: ver.version,
5714 NextProtos: []string{"foo", "bar", "baz"},
5715 },
5716 flags: []string{
5717 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5718 "-select-alpn", "foo",
5719 "-advertise-npn", "\x03foo\x03bar\x03baz",
5720 },
David Benjamina5022392017-07-10 17:40:39 -04005721 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005722 expectedNextProto: "foo",
5723 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005724 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005725 })
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 NextProtos: []string{"foo", "bar", "baz"},
5732 Bugs: ProtocolBugs{
5733 SwapNPNAndALPN: true,
5734 },
5735 },
5736 flags: []string{
5737 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5738 "-select-alpn", "foo",
5739 "-advertise-npn", "\x03foo\x03bar\x03baz",
5740 },
David Benjamina5022392017-07-10 17:40:39 -04005741 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005742 expectedNextProto: "foo",
5743 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005744 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005745 })
5746
5747 // Test that negotiating both NPN and ALPN is forbidden.
5748 testCases = append(testCases, testCase{
5749 name: "NegotiateALPNAndNPN-" + ver.name,
5750 config: Config{
5751 MaxVersion: ver.version,
5752 NextProtos: []string{"foo", "bar", "baz"},
5753 Bugs: ProtocolBugs{
5754 NegotiateALPNAndNPN: true,
5755 },
5756 },
5757 flags: []string{
5758 "-advertise-alpn", "\x03foo",
5759 "-select-next-proto", "foo",
5760 },
David Benjamina5022392017-07-10 17:40:39 -04005761 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005762 shouldFail: true,
5763 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5764 })
5765 testCases = append(testCases, testCase{
5766 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5767 config: Config{
5768 MaxVersion: ver.version,
5769 NextProtos: []string{"foo", "bar", "baz"},
5770 Bugs: ProtocolBugs{
5771 NegotiateALPNAndNPN: true,
5772 SwapNPNAndALPN: true,
5773 },
5774 },
5775 flags: []string{
5776 "-advertise-alpn", "\x03foo",
5777 "-select-next-proto", "foo",
5778 },
David Benjamina5022392017-07-10 17:40:39 -04005779 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005780 shouldFail: true,
5781 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5782 })
David Benjamin97d17d92016-07-14 16:12:00 -04005783 }
5784
5785 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005786
5787 // Resume with a corrupt ticket.
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "CorruptTicket-" + ver.name,
5791 config: Config{
5792 MaxVersion: ver.version,
5793 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005794 FilterTicket: func(in []byte) ([]byte, error) {
5795 in[len(in)-1] ^= 1
5796 return in, nil
5797 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005798 },
5799 },
David Benjamina5022392017-07-10 17:40:39 -04005800 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005801 resumeSession: true,
5802 expectResumeRejected: true,
5803 })
5804 // Test the ticket callback, with and without renewal.
5805 testCases = append(testCases, testCase{
5806 testType: serverTest,
5807 name: "TicketCallback-" + ver.name,
5808 config: Config{
5809 MaxVersion: ver.version,
5810 },
David Benjamina5022392017-07-10 17:40:39 -04005811 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005812 resumeSession: true,
5813 flags: []string{"-use-ticket-callback"},
5814 })
5815 testCases = append(testCases, testCase{
5816 testType: serverTest,
5817 name: "TicketCallback-Renew-" + ver.name,
5818 config: Config{
5819 MaxVersion: ver.version,
5820 Bugs: ProtocolBugs{
5821 ExpectNewTicket: true,
5822 },
5823 },
David Benjamina5022392017-07-10 17:40:39 -04005824 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005825 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5826 resumeSession: true,
5827 })
5828
5829 // Test that the ticket callback is only called once when everything before
5830 // it in the ClientHello is asynchronous. This corrupts the ticket so
5831 // certificate selection callbacks run.
5832 testCases = append(testCases, testCase{
5833 testType: serverTest,
5834 name: "TicketCallback-SingleCall-" + ver.name,
5835 config: Config{
5836 MaxVersion: ver.version,
5837 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005838 FilterTicket: func(in []byte) ([]byte, error) {
5839 in[len(in)-1] ^= 1
5840 return in, nil
5841 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005842 },
5843 },
David Benjamina5022392017-07-10 17:40:39 -04005844 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005845 resumeSession: true,
5846 expectResumeRejected: true,
5847 flags: []string{
5848 "-use-ticket-callback",
5849 "-async",
5850 },
5851 })
5852
David Benjamind4c349b2017-02-09 14:07:17 -05005853 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005854 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005855 testCases = append(testCases, testCase{
5856 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005857 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005858 config: Config{
5859 MaxVersion: ver.version,
5860 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005861 EmptyTicketSessionID: true,
5862 },
5863 },
5864 resumeSession: true,
5865 })
5866 testCases = append(testCases, testCase{
5867 testType: serverTest,
5868 name: "TicketSessionIDLength-16-" + ver.name,
5869 config: Config{
5870 MaxVersion: ver.version,
5871 Bugs: ProtocolBugs{
5872 TicketSessionIDLength: 16,
5873 },
5874 },
5875 resumeSession: true,
5876 })
5877 testCases = append(testCases, testCase{
5878 testType: serverTest,
5879 name: "TicketSessionIDLength-32-" + ver.name,
5880 config: Config{
5881 MaxVersion: ver.version,
5882 Bugs: ProtocolBugs{
5883 TicketSessionIDLength: 32,
5884 },
5885 },
5886 resumeSession: true,
5887 })
5888 testCases = append(testCases, testCase{
5889 testType: serverTest,
5890 name: "TicketSessionIDLength-33-" + ver.name,
5891 config: Config{
5892 MaxVersion: ver.version,
5893 Bugs: ProtocolBugs{
5894 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005895 },
5896 },
5897 resumeSession: true,
5898 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005899 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005900 expectedError: ":DECODE_ERROR:",
5901 })
5902 }
5903
5904 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5905 // are ignored.
5906 if ver.hasDTLS {
5907 testCases = append(testCases, testCase{
5908 protocol: dtls,
5909 name: "SRTP-Client-" + ver.name,
5910 config: Config{
5911 MaxVersion: ver.version,
5912 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5913 },
5914 flags: []string{
5915 "-srtp-profiles",
5916 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5917 },
5918 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5919 })
5920 testCases = append(testCases, testCase{
5921 protocol: dtls,
5922 testType: serverTest,
5923 name: "SRTP-Server-" + ver.name,
5924 config: Config{
5925 MaxVersion: ver.version,
5926 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5927 },
5928 flags: []string{
5929 "-srtp-profiles",
5930 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5931 },
5932 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5933 })
5934 // Test that the MKI is ignored.
5935 testCases = append(testCases, testCase{
5936 protocol: dtls,
5937 testType: serverTest,
5938 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5939 config: Config{
5940 MaxVersion: ver.version,
5941 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5942 Bugs: ProtocolBugs{
5943 SRTPMasterKeyIdentifer: "bogus",
5944 },
5945 },
5946 flags: []string{
5947 "-srtp-profiles",
5948 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5949 },
5950 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5951 })
5952 // Test that SRTP isn't negotiated on the server if there were
5953 // no matching profiles.
5954 testCases = append(testCases, testCase{
5955 protocol: dtls,
5956 testType: serverTest,
5957 name: "SRTP-Server-NoMatch-" + ver.name,
5958 config: Config{
5959 MaxVersion: ver.version,
5960 SRTPProtectionProfiles: []uint16{100, 101, 102},
5961 },
5962 flags: []string{
5963 "-srtp-profiles",
5964 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5965 },
5966 expectedSRTPProtectionProfile: 0,
5967 })
5968 // Test that the server returning an invalid SRTP profile is
5969 // flagged as an error by the client.
5970 testCases = append(testCases, testCase{
5971 protocol: dtls,
5972 name: "SRTP-Client-NoMatch-" + ver.name,
5973 config: Config{
5974 MaxVersion: ver.version,
5975 Bugs: ProtocolBugs{
5976 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5977 },
5978 },
5979 flags: []string{
5980 "-srtp-profiles",
5981 "SRTP_AES128_CM_SHA1_80",
5982 },
5983 shouldFail: true,
5984 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5985 })
5986 }
5987
5988 // Test SCT list.
5989 testCases = append(testCases, testCase{
5990 name: "SignedCertificateTimestampList-Client-" + ver.name,
5991 testType: clientTest,
5992 config: Config{
5993 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005994 },
David Benjamin97d17d92016-07-14 16:12:00 -04005995 flags: []string{
5996 "-enable-signed-cert-timestamps",
5997 "-expect-signed-cert-timestamps",
5998 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005999 },
David Benjamina5022392017-07-10 17:40:39 -04006000 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006001 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006002 })
David Benjamindaa88502016-10-04 16:32:16 -04006003
Adam Langleycfa08c32016-11-17 13:21:27 -08006004 var differentSCTList []byte
6005 differentSCTList = append(differentSCTList, testSCTList...)
6006 differentSCTList[len(differentSCTList)-1] ^= 1
6007
David Benjamindaa88502016-10-04 16:32:16 -04006008 // The SCT extension did not specify that it must only be sent on resumption as it
6009 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006010 testCases = append(testCases, testCase{
6011 name: "SendSCTListOnResume-" + ver.name,
6012 config: Config{
6013 MaxVersion: ver.version,
6014 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006015 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006016 },
David Benjamind98452d2015-06-16 14:16:23 -04006017 },
David Benjamin97d17d92016-07-14 16:12:00 -04006018 flags: []string{
6019 "-enable-signed-cert-timestamps",
6020 "-expect-signed-cert-timestamps",
6021 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006022 },
David Benjamina5022392017-07-10 17:40:39 -04006023 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006024 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006025 })
David Benjamindaa88502016-10-04 16:32:16 -04006026
David Benjamin97d17d92016-07-14 16:12:00 -04006027 testCases = append(testCases, testCase{
6028 name: "SignedCertificateTimestampList-Server-" + ver.name,
6029 testType: serverTest,
6030 config: Config{
6031 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006032 },
David Benjamin97d17d92016-07-14 16:12:00 -04006033 flags: []string{
6034 "-signed-cert-timestamps",
6035 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006036 },
David Benjamina5022392017-07-10 17:40:39 -04006037 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006038 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006039 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006040 })
David Benjamin53210cb2016-11-16 09:01:48 +09006041
Adam Langleycfa08c32016-11-17 13:21:27 -08006042 emptySCTListCert := *testCerts[0].cert
6043 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6044
6045 // Test empty SCT list.
6046 testCases = append(testCases, testCase{
6047 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6048 testType: clientTest,
6049 config: Config{
6050 MaxVersion: ver.version,
6051 Certificates: []Certificate{emptySCTListCert},
6052 },
6053 flags: []string{
6054 "-enable-signed-cert-timestamps",
6055 },
David Benjamina5022392017-07-10 17:40:39 -04006056 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006057 shouldFail: true,
6058 expectedError: ":ERROR_PARSING_EXTENSION:",
6059 })
6060
6061 emptySCTCert := *testCerts[0].cert
6062 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6063
6064 // Test empty SCT in non-empty list.
6065 testCases = append(testCases, testCase{
6066 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6067 testType: clientTest,
6068 config: Config{
6069 MaxVersion: ver.version,
6070 Certificates: []Certificate{emptySCTCert},
6071 },
6072 flags: []string{
6073 "-enable-signed-cert-timestamps",
6074 },
David Benjamina5022392017-07-10 17:40:39 -04006075 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006076 shouldFail: true,
6077 expectedError: ":ERROR_PARSING_EXTENSION:",
6078 })
6079
David Benjamin53210cb2016-11-16 09:01:48 +09006080 // Test that certificate-related extensions are not sent unsolicited.
6081 testCases = append(testCases, testCase{
6082 testType: serverTest,
6083 name: "UnsolicitedCertificateExtensions-" + ver.name,
6084 config: Config{
6085 MaxVersion: ver.version,
6086 Bugs: ProtocolBugs{
6087 NoOCSPStapling: true,
6088 NoSignedCertificateTimestamps: true,
6089 },
6090 },
David Benjamina5022392017-07-10 17:40:39 -04006091 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006092 flags: []string{
6093 "-ocsp-response",
6094 base64.StdEncoding.EncodeToString(testOCSPResponse),
6095 "-signed-cert-timestamps",
6096 base64.StdEncoding.EncodeToString(testSCTList),
6097 },
6098 })
David Benjamin97d17d92016-07-14 16:12:00 -04006099 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006100
Paul Lietar4fac72e2015-09-09 13:44:55 +01006101 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006102 testType: clientTest,
6103 name: "ClientHelloPadding",
6104 config: Config{
6105 Bugs: ProtocolBugs{
6106 RequireClientHelloSize: 512,
6107 },
6108 },
6109 // This hostname just needs to be long enough to push the
6110 // ClientHello into F5's danger zone between 256 and 511 bytes
6111 // long.
6112 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6113 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006114
6115 // Extensions should not function in SSL 3.0.
6116 testCases = append(testCases, testCase{
6117 testType: serverTest,
6118 name: "SSLv3Extensions-NoALPN",
6119 config: Config{
6120 MaxVersion: VersionSSL30,
6121 NextProtos: []string{"foo", "bar", "baz"},
6122 },
6123 flags: []string{
6124 "-select-alpn", "foo",
6125 },
6126 expectNoNextProto: true,
6127 })
6128
6129 // Test session tickets separately as they follow a different codepath.
6130 testCases = append(testCases, testCase{
6131 testType: serverTest,
6132 name: "SSLv3Extensions-NoTickets",
6133 config: Config{
6134 MaxVersion: VersionSSL30,
6135 Bugs: ProtocolBugs{
6136 // Historically, session tickets in SSL 3.0
6137 // failed in different ways depending on whether
6138 // the client supported renegotiation_info.
6139 NoRenegotiationInfo: true,
6140 },
6141 },
6142 resumeSession: true,
6143 })
6144 testCases = append(testCases, testCase{
6145 testType: serverTest,
6146 name: "SSLv3Extensions-NoTickets2",
6147 config: Config{
6148 MaxVersion: VersionSSL30,
6149 },
6150 resumeSession: true,
6151 })
6152
6153 // But SSL 3.0 does send and process renegotiation_info.
6154 testCases = append(testCases, testCase{
6155 testType: serverTest,
6156 name: "SSLv3Extensions-RenegotiationInfo",
6157 config: Config{
6158 MaxVersion: VersionSSL30,
6159 Bugs: ProtocolBugs{
6160 RequireRenegotiationInfo: true,
6161 },
6162 },
David Benjamind2610042017-01-03 10:49:28 -05006163 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006164 })
6165 testCases = append(testCases, testCase{
6166 testType: serverTest,
6167 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6168 config: Config{
6169 MaxVersion: VersionSSL30,
6170 Bugs: ProtocolBugs{
6171 NoRenegotiationInfo: true,
6172 SendRenegotiationSCSV: true,
6173 RequireRenegotiationInfo: true,
6174 },
6175 },
David Benjamind2610042017-01-03 10:49:28 -05006176 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006177 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006178
6179 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6180 // in ServerHello.
6181 testCases = append(testCases, testCase{
6182 name: "NPN-Forbidden-TLS13",
6183 config: Config{
6184 MaxVersion: VersionTLS13,
6185 NextProtos: []string{"foo"},
6186 Bugs: ProtocolBugs{
6187 NegotiateNPNAtAllVersions: true,
6188 },
6189 },
6190 flags: []string{"-select-next-proto", "foo"},
6191 shouldFail: true,
6192 expectedError: ":ERROR_PARSING_EXTENSION:",
6193 })
6194 testCases = append(testCases, testCase{
6195 name: "EMS-Forbidden-TLS13",
6196 config: Config{
6197 MaxVersion: VersionTLS13,
6198 Bugs: ProtocolBugs{
6199 NegotiateEMSAtAllVersions: true,
6200 },
6201 },
6202 shouldFail: true,
6203 expectedError: ":ERROR_PARSING_EXTENSION:",
6204 })
6205 testCases = append(testCases, testCase{
6206 name: "RenegotiationInfo-Forbidden-TLS13",
6207 config: Config{
6208 MaxVersion: VersionTLS13,
6209 Bugs: ProtocolBugs{
6210 NegotiateRenegotiationInfoAtAllVersions: true,
6211 },
6212 },
6213 shouldFail: true,
6214 expectedError: ":ERROR_PARSING_EXTENSION:",
6215 })
6216 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006217 name: "Ticket-Forbidden-TLS13",
6218 config: Config{
6219 MaxVersion: VersionTLS12,
6220 },
6221 resumeConfig: &Config{
6222 MaxVersion: VersionTLS13,
6223 Bugs: ProtocolBugs{
6224 AdvertiseTicketExtension: true,
6225 },
6226 },
6227 resumeSession: true,
6228 shouldFail: true,
6229 expectedError: ":ERROR_PARSING_EXTENSION:",
6230 })
6231
6232 // Test that illegal extensions in TLS 1.3 are declined by the server if
6233 // offered in ClientHello. The runner's server will fail if this occurs,
6234 // so we exercise the offering path. (EMS and Renegotiation Info are
6235 // implicit in every test.)
6236 testCases = append(testCases, testCase{
6237 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006238 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006239 config: Config{
6240 MaxVersion: VersionTLS13,
6241 NextProtos: []string{"bar"},
6242 },
6243 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6244 })
David Benjamin196df5b2016-09-21 16:23:27 -04006245
David Benjamindaa88502016-10-04 16:32:16 -04006246 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6247 // tolerated.
6248 testCases = append(testCases, testCase{
6249 name: "SendOCSPResponseOnResume-TLS12",
6250 config: Config{
6251 MaxVersion: VersionTLS12,
6252 Bugs: ProtocolBugs{
6253 SendOCSPResponseOnResume: []byte("bogus"),
6254 },
6255 },
6256 flags: []string{
6257 "-enable-ocsp-stapling",
6258 "-expect-ocsp-response",
6259 base64.StdEncoding.EncodeToString(testOCSPResponse),
6260 },
6261 resumeSession: true,
6262 })
6263
David Benjamindaa88502016-10-04 16:32:16 -04006264 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006265 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006266 config: Config{
6267 MaxVersion: VersionTLS13,
6268 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006269 SendExtensionOnCertificate: testOCSPExtension,
6270 },
6271 },
6272 shouldFail: true,
6273 expectedError: ":UNEXPECTED_EXTENSION:",
6274 })
6275
6276 testCases = append(testCases, testCase{
6277 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6278 config: Config{
6279 MaxVersion: VersionTLS13,
6280 Bugs: ProtocolBugs{
6281 SendExtensionOnCertificate: testSCTExtension,
6282 },
6283 },
6284 shouldFail: true,
6285 expectedError: ":UNEXPECTED_EXTENSION:",
6286 })
6287
6288 // Test that extensions on client certificates are never accepted.
6289 testCases = append(testCases, testCase{
6290 name: "SendExtensionOnClientCertificate-TLS13",
6291 testType: serverTest,
6292 config: Config{
6293 MaxVersion: VersionTLS13,
6294 Certificates: []Certificate{rsaCertificate},
6295 Bugs: ProtocolBugs{
6296 SendExtensionOnCertificate: testOCSPExtension,
6297 },
6298 },
6299 flags: []string{
6300 "-enable-ocsp-stapling",
6301 "-require-any-client-certificate",
6302 },
6303 shouldFail: true,
6304 expectedError: ":UNEXPECTED_EXTENSION:",
6305 })
6306
6307 testCases = append(testCases, testCase{
6308 name: "SendUnknownExtensionOnCertificate-TLS13",
6309 config: Config{
6310 MaxVersion: VersionTLS13,
6311 Bugs: ProtocolBugs{
6312 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6313 },
6314 },
6315 shouldFail: true,
6316 expectedError: ":UNEXPECTED_EXTENSION:",
6317 })
6318
Adam Langleycfa08c32016-11-17 13:21:27 -08006319 var differentSCTList []byte
6320 differentSCTList = append(differentSCTList, testSCTList...)
6321 differentSCTList[len(differentSCTList)-1] ^= 1
6322
Steven Valdeza833c352016-11-01 13:39:36 -04006323 // Test that extensions on intermediates are allowed but ignored.
6324 testCases = append(testCases, testCase{
6325 name: "IgnoreExtensionsOnIntermediates-TLS13",
6326 config: Config{
6327 MaxVersion: VersionTLS13,
6328 Certificates: []Certificate{rsaChainCertificate},
6329 Bugs: ProtocolBugs{
6330 // Send different values on the intermediate. This tests
6331 // the intermediate's extensions do not override the
6332 // leaf's.
6333 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006334 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006335 },
6336 },
6337 flags: []string{
6338 "-enable-ocsp-stapling",
6339 "-expect-ocsp-response",
6340 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006341 "-enable-signed-cert-timestamps",
6342 "-expect-signed-cert-timestamps",
6343 base64.StdEncoding.EncodeToString(testSCTList),
6344 },
6345 resumeSession: true,
6346 })
6347
6348 // Test that extensions are not sent on intermediates when configured
6349 // only for a leaf.
6350 testCases = append(testCases, testCase{
6351 testType: serverTest,
6352 name: "SendNoExtensionsOnIntermediate-TLS13",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 Bugs: ProtocolBugs{
6356 ExpectNoExtensionsOnIntermediate: true,
6357 },
6358 },
6359 flags: []string{
6360 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6361 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6362 "-ocsp-response",
6363 base64.StdEncoding.EncodeToString(testOCSPResponse),
6364 "-signed-cert-timestamps",
6365 base64.StdEncoding.EncodeToString(testSCTList),
6366 },
6367 })
6368
6369 // Test that extensions are not sent on client certificates.
6370 testCases = append(testCases, testCase{
6371 name: "SendNoClientCertificateExtensions-TLS13",
6372 config: Config{
6373 MaxVersion: VersionTLS13,
6374 ClientAuth: RequireAnyClientCert,
6375 },
6376 flags: []string{
6377 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6378 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6379 "-ocsp-response",
6380 base64.StdEncoding.EncodeToString(testOCSPResponse),
6381 "-signed-cert-timestamps",
6382 base64.StdEncoding.EncodeToString(testSCTList),
6383 },
6384 })
6385
6386 testCases = append(testCases, testCase{
6387 name: "SendDuplicateExtensionsOnCerts-TLS13",
6388 config: Config{
6389 MaxVersion: VersionTLS13,
6390 Bugs: ProtocolBugs{
6391 SendDuplicateCertExtensions: true,
6392 },
6393 },
6394 flags: []string{
6395 "-enable-ocsp-stapling",
6396 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006397 },
6398 resumeSession: true,
6399 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006400 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006401 })
Adam Langley9b885c52016-11-18 14:21:03 -08006402
6403 testCases = append(testCases, testCase{
6404 name: "SignedCertificateTimestampListInvalid-Server",
6405 testType: serverTest,
6406 flags: []string{
6407 "-signed-cert-timestamps",
6408 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6409 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006410 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006411 expectedError: ":INVALID_SCT_LIST:",
6412 })
David Benjamine78bfde2014-09-06 12:45:15 -04006413}
6414
David Benjamin01fe8202014-09-24 15:21:44 -04006415func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006416 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006417 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006418 // SSL 3.0 does not have tickets and TLS 1.3 does not
6419 // have session IDs, so skip their cross-resumption
6420 // tests.
6421 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6422 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6423 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006424 }
6425
David Benjamin8b8c0062014-11-23 02:47:52 -05006426 protocols := []protocol{tls}
6427 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6428 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006429 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006430 for _, protocol := range protocols {
6431 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6432 if protocol == dtls {
6433 suffix += "-DTLS"
6434 }
6435
Steven Valdez520e1222017-06-13 12:45:25 -04006436 // We can't resume across TLS 1.3 variants and error out earlier in the
6437 // session resumption.
6438 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6439 continue
6440 }
6441
David Benjaminece3de92015-03-16 18:02:20 -04006442 if sessionVers.version == resumeVers.version {
6443 testCases = append(testCases, testCase{
6444 protocol: protocol,
6445 name: "Resume-Client" + suffix,
6446 resumeSession: true,
6447 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006448 MaxVersion: sessionVers.version,
6449 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006450 Bugs: ProtocolBugs{
6451 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6452 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6453 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006454 },
David Benjaminece3de92015-03-16 18:02:20 -04006455 expectedVersion: sessionVers.version,
6456 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006457 flags: []string{
6458 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6459 },
David Benjaminece3de92015-03-16 18:02:20 -04006460 })
6461 } else {
David Benjamin405da482016-08-08 17:25:07 -04006462 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6463
6464 // Offering a TLS 1.3 session sends an empty session ID, so
6465 // there is no way to convince a non-lookahead client the
6466 // session was resumed. It will appear to the client that a
6467 // stray ChangeCipherSpec was sent.
6468 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6469 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006470 }
6471
David Benjaminece3de92015-03-16 18:02:20 -04006472 testCases = append(testCases, testCase{
6473 protocol: protocol,
6474 name: "Resume-Client-Mismatch" + suffix,
6475 resumeSession: true,
6476 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006477 MaxVersion: sessionVers.version,
6478 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006479 },
David Benjaminece3de92015-03-16 18:02:20 -04006480 expectedVersion: sessionVers.version,
6481 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006482 MaxVersion: resumeVers.version,
6483 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006484 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006485 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006486 },
6487 },
6488 expectedResumeVersion: resumeVers.version,
6489 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006490 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006491 flags: []string{
6492 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6493 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6494 },
David Benjaminece3de92015-03-16 18:02:20 -04006495 })
6496 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006497
6498 testCases = append(testCases, testCase{
6499 protocol: protocol,
6500 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006501 resumeSession: true,
6502 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006503 MaxVersion: sessionVers.version,
6504 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006505 },
6506 expectedVersion: sessionVers.version,
6507 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006508 MaxVersion: resumeVers.version,
6509 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006510 },
6511 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006512 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006513 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006514 flags: []string{
6515 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6516 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6517 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006518 })
6519
David Benjamin8b8c0062014-11-23 02:47:52 -05006520 testCases = append(testCases, testCase{
6521 protocol: protocol,
6522 testType: serverTest,
6523 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006524 resumeSession: true,
6525 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006526 MaxVersion: sessionVers.version,
6527 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006528 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006529 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006530 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006531 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006532 MaxVersion: resumeVers.version,
6533 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006534 Bugs: ProtocolBugs{
6535 SendBothTickets: true,
6536 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006537 },
6538 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006539 flags: []string{
6540 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6541 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6542 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006543 })
6544 }
David Benjamin01fe8202014-09-24 15:21:44 -04006545 }
6546 }
David Benjaminece3de92015-03-16 18:02:20 -04006547
David Benjamin4199b0d2016-11-01 13:58:25 -04006548 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006549 testCases = append(testCases, testCase{
6550 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006551 name: "ShimTicketRewritable",
6552 resumeSession: true,
6553 config: Config{
6554 MaxVersion: VersionTLS12,
6555 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6556 Bugs: ProtocolBugs{
6557 FilterTicket: func(in []byte) ([]byte, error) {
6558 in, err := SetShimTicketVersion(in, VersionTLS12)
6559 if err != nil {
6560 return nil, err
6561 }
6562 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6563 },
6564 },
6565 },
6566 flags: []string{
6567 "-ticket-key",
6568 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6569 },
6570 })
6571
6572 // Resumptions are declined if the version does not match.
6573 testCases = append(testCases, testCase{
6574 testType: serverTest,
6575 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006576 resumeSession: true,
6577 config: Config{
6578 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006579 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006580 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006581 FilterTicket: func(in []byte) ([]byte, error) {
6582 return SetShimTicketVersion(in, VersionTLS13)
6583 },
6584 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006585 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006586 flags: []string{
6587 "-ticket-key",
6588 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6589 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006590 expectResumeRejected: true,
6591 })
6592
6593 testCases = append(testCases, testCase{
6594 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006595 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006596 resumeSession: true,
6597 config: Config{
6598 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006599 Bugs: ProtocolBugs{
6600 FilterTicket: func(in []byte) ([]byte, error) {
6601 return SetShimTicketVersion(in, VersionTLS12)
6602 },
6603 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006604 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006605 flags: []string{
6606 "-ticket-key",
6607 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6608 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006609 expectResumeRejected: true,
6610 })
6611
David Benjamin4199b0d2016-11-01 13:58:25 -04006612 // Resumptions are declined if the cipher is invalid or disabled.
6613 testCases = append(testCases, testCase{
6614 testType: serverTest,
6615 name: "Resume-Server-DeclineBadCipher",
6616 resumeSession: true,
6617 config: Config{
6618 MaxVersion: VersionTLS12,
6619 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006620 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006621 FilterTicket: func(in []byte) ([]byte, error) {
6622 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6623 },
6624 },
6625 },
6626 flags: []string{
6627 "-ticket-key",
6628 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6629 },
6630 expectResumeRejected: true,
6631 })
6632
6633 testCases = append(testCases, testCase{
6634 testType: serverTest,
6635 name: "Resume-Server-DeclineBadCipher-2",
6636 resumeSession: true,
6637 config: Config{
6638 MaxVersion: VersionTLS12,
6639 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006640 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006641 FilterTicket: func(in []byte) ([]byte, error) {
6642 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6643 },
6644 },
6645 },
6646 flags: []string{
6647 "-cipher", "AES128",
6648 "-ticket-key",
6649 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6650 },
6651 expectResumeRejected: true,
6652 })
6653
David Benjaminf01f42a2016-11-16 19:05:33 +09006654 // Sessions are not resumed if they do not use the preferred cipher.
6655 testCases = append(testCases, testCase{
6656 testType: serverTest,
6657 name: "Resume-Server-CipherNotPreferred",
6658 resumeSession: true,
6659 config: Config{
6660 MaxVersion: VersionTLS12,
6661 Bugs: ProtocolBugs{
6662 ExpectNewTicket: true,
6663 FilterTicket: func(in []byte) ([]byte, error) {
6664 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6665 },
6666 },
6667 },
6668 flags: []string{
6669 "-ticket-key",
6670 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6671 },
6672 shouldFail: false,
6673 expectResumeRejected: true,
6674 })
6675
6676 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6677 // PRF hashes match, but BoringSSL will always decline such resumptions.
6678 testCases = append(testCases, testCase{
6679 testType: serverTest,
6680 name: "Resume-Server-CipherNotPreferred-TLS13",
6681 resumeSession: true,
6682 config: Config{
6683 MaxVersion: VersionTLS13,
6684 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6685 Bugs: ProtocolBugs{
6686 FilterTicket: func(in []byte) ([]byte, error) {
6687 // If the client (runner) offers ChaCha20-Poly1305 first, the
6688 // server (shim) always prefers it. Switch it to AES-GCM.
6689 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6690 },
6691 },
6692 },
6693 flags: []string{
6694 "-ticket-key",
6695 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6696 },
6697 shouldFail: false,
6698 expectResumeRejected: true,
6699 })
6700
6701 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006702 testCases = append(testCases, testCase{
6703 testType: serverTest,
6704 name: "Resume-Server-DeclineBadCipher-TLS13",
6705 resumeSession: true,
6706 config: Config{
6707 MaxVersion: VersionTLS13,
6708 Bugs: ProtocolBugs{
6709 FilterTicket: func(in []byte) ([]byte, error) {
6710 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6711 },
6712 },
6713 },
6714 flags: []string{
6715 "-ticket-key",
6716 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6717 },
6718 expectResumeRejected: true,
6719 })
6720
David Benjaminf01f42a2016-11-16 19:05:33 +09006721 // If the client does not offer the cipher from the session, decline to
6722 // resume. Clients are forbidden from doing this, but BoringSSL selects
6723 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006724 testCases = append(testCases, testCase{
6725 testType: serverTest,
6726 name: "Resume-Server-UnofferedCipher",
6727 resumeSession: true,
6728 config: Config{
6729 MaxVersion: VersionTLS12,
6730 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6731 },
6732 resumeConfig: &Config{
6733 MaxVersion: VersionTLS12,
6734 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6735 Bugs: ProtocolBugs{
6736 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6737 },
6738 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006739 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006740 })
6741
David Benjaminf01f42a2016-11-16 19:05:33 +09006742 // In TLS 1.3, clients may advertise a cipher list which does not
6743 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006744 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6745 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006746 testCases = append(testCases, testCase{
6747 testType: serverTest,
6748 name: "Resume-Server-UnofferedCipher-TLS13",
6749 resumeSession: true,
6750 config: Config{
6751 MaxVersion: VersionTLS13,
6752 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6753 },
6754 resumeConfig: &Config{
6755 MaxVersion: VersionTLS13,
6756 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6757 Bugs: ProtocolBugs{
6758 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6759 },
6760 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006761 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006762 })
6763
David Benjamin4199b0d2016-11-01 13:58:25 -04006764 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006765 testCases = append(testCases, testCase{
6766 name: "Resume-Client-CipherMismatch",
6767 resumeSession: true,
6768 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006769 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006770 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6771 },
6772 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006773 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006774 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6775 Bugs: ProtocolBugs{
6776 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6777 },
6778 },
6779 shouldFail: true,
6780 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6781 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006782
David Benjamine1cc35e2016-11-16 16:25:58 +09006783 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6784 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006785 testCases = append(testCases, testCase{
6786 name: "Resume-Client-CipherMismatch-TLS13",
6787 resumeSession: true,
6788 config: Config{
6789 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006790 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006791 },
6792 resumeConfig: &Config{
6793 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006794 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6795 },
6796 })
6797
6798 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6799 testCases = append(testCases, testCase{
6800 name: "Resume-Client-PRFMismatch-TLS13",
6801 resumeSession: true,
6802 config: Config{
6803 MaxVersion: VersionTLS13,
6804 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6805 },
6806 resumeConfig: &Config{
6807 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006808 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006809 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006810 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006811 },
6812 },
6813 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006814 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006815 })
Steven Valdeza833c352016-11-01 13:39:36 -04006816
6817 testCases = append(testCases, testCase{
6818 testType: serverTest,
6819 name: "Resume-Server-BinderWrongLength",
6820 resumeSession: true,
6821 config: Config{
6822 MaxVersion: VersionTLS13,
6823 Bugs: ProtocolBugs{
6824 SendShortPSKBinder: true,
6825 },
6826 },
6827 shouldFail: true,
6828 expectedLocalError: "remote error: error decrypting message",
6829 expectedError: ":DIGEST_CHECK_FAILED:",
6830 })
6831
6832 testCases = append(testCases, testCase{
6833 testType: serverTest,
6834 name: "Resume-Server-NoPSKBinder",
6835 resumeSession: true,
6836 config: Config{
6837 MaxVersion: VersionTLS13,
6838 Bugs: ProtocolBugs{
6839 SendNoPSKBinder: true,
6840 },
6841 },
6842 shouldFail: true,
6843 expectedLocalError: "remote error: error decoding message",
6844 expectedError: ":DECODE_ERROR:",
6845 })
6846
6847 testCases = append(testCases, testCase{
6848 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006849 name: "Resume-Server-ExtraPSKBinder",
6850 resumeSession: true,
6851 config: Config{
6852 MaxVersion: VersionTLS13,
6853 Bugs: ProtocolBugs{
6854 SendExtraPSKBinder: true,
6855 },
6856 },
6857 shouldFail: true,
6858 expectedLocalError: "remote error: illegal parameter",
6859 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6860 })
6861
6862 testCases = append(testCases, testCase{
6863 testType: serverTest,
6864 name: "Resume-Server-ExtraIdentityNoBinder",
6865 resumeSession: true,
6866 config: Config{
6867 MaxVersion: VersionTLS13,
6868 Bugs: ProtocolBugs{
6869 ExtraPSKIdentity: true,
6870 },
6871 },
6872 shouldFail: true,
6873 expectedLocalError: "remote error: illegal parameter",
6874 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6875 })
6876
6877 testCases = append(testCases, testCase{
6878 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006879 name: "Resume-Server-InvalidPSKBinder",
6880 resumeSession: true,
6881 config: Config{
6882 MaxVersion: VersionTLS13,
6883 Bugs: ProtocolBugs{
6884 SendInvalidPSKBinder: true,
6885 },
6886 },
6887 shouldFail: true,
6888 expectedLocalError: "remote error: error decrypting message",
6889 expectedError: ":DIGEST_CHECK_FAILED:",
6890 })
6891
6892 testCases = append(testCases, testCase{
6893 testType: serverTest,
6894 name: "Resume-Server-PSKBinderFirstExtension",
6895 resumeSession: true,
6896 config: Config{
6897 MaxVersion: VersionTLS13,
6898 Bugs: ProtocolBugs{
6899 PSKBinderFirst: true,
6900 },
6901 },
6902 shouldFail: true,
6903 expectedLocalError: "remote error: illegal parameter",
6904 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6905 })
David Benjamin01fe8202014-09-24 15:21:44 -04006906}
6907
Adam Langley2ae77d22014-10-28 17:29:33 -07006908func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006909 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006910 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006911 testType: serverTest,
6912 name: "Renegotiate-Server-Forbidden",
6913 config: Config{
6914 MaxVersion: VersionTLS12,
6915 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006916 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006917 shouldFail: true,
6918 expectedError: ":NO_RENEGOTIATION:",
6919 expectedLocalError: "remote error: no renegotiation",
6920 })
Adam Langley5021b222015-06-12 18:27:58 -07006921 // The server shouldn't echo the renegotiation extension unless
6922 // requested by the client.
6923 testCases = append(testCases, testCase{
6924 testType: serverTest,
6925 name: "Renegotiate-Server-NoExt",
6926 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006927 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006928 Bugs: ProtocolBugs{
6929 NoRenegotiationInfo: true,
6930 RequireRenegotiationInfo: true,
6931 },
6932 },
6933 shouldFail: true,
6934 expectedLocalError: "renegotiation extension missing",
6935 })
6936 // The renegotiation SCSV should be sufficient for the server to echo
6937 // the extension.
6938 testCases = append(testCases, testCase{
6939 testType: serverTest,
6940 name: "Renegotiate-Server-NoExt-SCSV",
6941 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006942 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006943 Bugs: ProtocolBugs{
6944 NoRenegotiationInfo: true,
6945 SendRenegotiationSCSV: true,
6946 RequireRenegotiationInfo: true,
6947 },
6948 },
6949 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006950 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006951 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006953 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006954 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006955 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006956 },
6957 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006958 renegotiate: 1,
6959 flags: []string{
6960 "-renegotiate-freely",
6961 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006962 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006963 },
David Benjamincdea40c2015-03-19 14:09:43 -04006964 })
6965 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006966 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006967 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006969 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006970 Bugs: ProtocolBugs{
6971 EmptyRenegotiationInfo: true,
6972 },
6973 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006974 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006975 shouldFail: true,
6976 expectedError: ":RENEGOTIATION_MISMATCH:",
6977 })
6978 testCases = append(testCases, testCase{
6979 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006980 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006982 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006983 Bugs: ProtocolBugs{
6984 BadRenegotiationInfo: true,
6985 },
6986 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006987 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006988 shouldFail: true,
6989 expectedError: ":RENEGOTIATION_MISMATCH:",
6990 })
6991 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006992 name: "Renegotiate-Client-BadExt2",
6993 renegotiate: 1,
6994 config: Config{
6995 MaxVersion: VersionTLS12,
6996 Bugs: ProtocolBugs{
6997 BadRenegotiationInfoEnd: true,
6998 },
6999 },
7000 flags: []string{"-renegotiate-freely"},
7001 shouldFail: true,
7002 expectedError: ":RENEGOTIATION_MISMATCH:",
7003 })
7004 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007005 name: "Renegotiate-Client-Downgrade",
7006 renegotiate: 1,
7007 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007008 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007009 Bugs: ProtocolBugs{
7010 NoRenegotiationInfoAfterInitial: true,
7011 },
7012 },
7013 flags: []string{"-renegotiate-freely"},
7014 shouldFail: true,
7015 expectedError: ":RENEGOTIATION_MISMATCH:",
7016 })
7017 testCases = append(testCases, testCase{
7018 name: "Renegotiate-Client-Upgrade",
7019 renegotiate: 1,
7020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007021 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007022 Bugs: ProtocolBugs{
7023 NoRenegotiationInfoInInitial: true,
7024 },
7025 },
7026 flags: []string{"-renegotiate-freely"},
7027 shouldFail: true,
7028 expectedError: ":RENEGOTIATION_MISMATCH:",
7029 })
7030 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007031 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007032 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007034 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007035 Bugs: ProtocolBugs{
7036 NoRenegotiationInfo: true,
7037 },
7038 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007039 flags: []string{
7040 "-renegotiate-freely",
7041 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007042 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007043 },
David Benjamincff0b902015-05-15 23:09:47 -04007044 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007045
7046 // Test that the server may switch ciphers on renegotiation without
7047 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007048 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007049 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007050 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007051 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007052 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007053 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007054 },
7055 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007056 flags: []string{
7057 "-renegotiate-freely",
7058 "-expect-total-renegotiations", "1",
7059 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007060 })
7061 testCases = append(testCases, testCase{
7062 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007063 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007064 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007065 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007066 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7067 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007068 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007069 flags: []string{
7070 "-renegotiate-freely",
7071 "-expect-total-renegotiations", "1",
7072 },
David Benjaminb16346b2015-04-08 19:16:58 -04007073 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007074
7075 // Test that the server may not switch versions on renegotiation.
7076 testCases = append(testCases, testCase{
7077 name: "Renegotiate-Client-SwitchVersion",
7078 config: Config{
7079 MaxVersion: VersionTLS12,
7080 // Pick a cipher which exists at both versions.
7081 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7082 Bugs: ProtocolBugs{
7083 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007084 // Avoid failing early at the record layer.
7085 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007086 },
7087 },
7088 renegotiate: 1,
7089 flags: []string{
7090 "-renegotiate-freely",
7091 "-expect-total-renegotiations", "1",
7092 },
7093 shouldFail: true,
7094 expectedError: ":WRONG_SSL_VERSION:",
7095 })
7096
David Benjaminb16346b2015-04-08 19:16:58 -04007097 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007098 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007099 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007100 config: Config{
7101 MaxVersion: VersionTLS10,
7102 Bugs: ProtocolBugs{
7103 RequireSameRenegoClientVersion: true,
7104 },
7105 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007106 flags: []string{
7107 "-renegotiate-freely",
7108 "-expect-total-renegotiations", "1",
7109 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007110 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007111 testCases = append(testCases, testCase{
7112 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007113 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007114 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007115 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7117 NextProtos: []string{"foo"},
7118 },
7119 flags: []string{
7120 "-false-start",
7121 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007122 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007123 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007124 },
7125 shimWritesFirst: true,
7126 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007127
7128 // Client-side renegotiation controls.
7129 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007130 name: "Renegotiate-Client-Forbidden-1",
7131 config: Config{
7132 MaxVersion: VersionTLS12,
7133 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007134 renegotiate: 1,
7135 shouldFail: true,
7136 expectedError: ":NO_RENEGOTIATION:",
7137 expectedLocalError: "remote error: no renegotiation",
7138 })
7139 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007140 name: "Renegotiate-Client-Once-1",
7141 config: Config{
7142 MaxVersion: VersionTLS12,
7143 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007144 renegotiate: 1,
7145 flags: []string{
7146 "-renegotiate-once",
7147 "-expect-total-renegotiations", "1",
7148 },
7149 })
7150 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007151 name: "Renegotiate-Client-Freely-1",
7152 config: Config{
7153 MaxVersion: VersionTLS12,
7154 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007155 renegotiate: 1,
7156 flags: []string{
7157 "-renegotiate-freely",
7158 "-expect-total-renegotiations", "1",
7159 },
7160 })
7161 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007162 name: "Renegotiate-Client-Once-2",
7163 config: Config{
7164 MaxVersion: VersionTLS12,
7165 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007166 renegotiate: 2,
7167 flags: []string{"-renegotiate-once"},
7168 shouldFail: true,
7169 expectedError: ":NO_RENEGOTIATION:",
7170 expectedLocalError: "remote error: no renegotiation",
7171 })
7172 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007173 name: "Renegotiate-Client-Freely-2",
7174 config: Config{
7175 MaxVersion: VersionTLS12,
7176 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007177 renegotiate: 2,
7178 flags: []string{
7179 "-renegotiate-freely",
7180 "-expect-total-renegotiations", "2",
7181 },
7182 })
Adam Langley27a0d082015-11-03 13:34:10 -08007183 testCases = append(testCases, testCase{
7184 name: "Renegotiate-Client-NoIgnore",
7185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007186 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007187 Bugs: ProtocolBugs{
7188 SendHelloRequestBeforeEveryAppDataRecord: true,
7189 },
7190 },
7191 shouldFail: true,
7192 expectedError: ":NO_RENEGOTIATION:",
7193 })
7194 testCases = append(testCases, testCase{
7195 name: "Renegotiate-Client-Ignore",
7196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007197 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007198 Bugs: ProtocolBugs{
7199 SendHelloRequestBeforeEveryAppDataRecord: true,
7200 },
7201 },
7202 flags: []string{
7203 "-renegotiate-ignore",
7204 "-expect-total-renegotiations", "0",
7205 },
7206 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007207
David Benjamin34941c02016-10-08 11:45:31 -04007208 // Renegotiation is not allowed at SSL 3.0.
7209 testCases = append(testCases, testCase{
7210 name: "Renegotiate-Client-SSL3",
7211 config: Config{
7212 MaxVersion: VersionSSL30,
7213 },
7214 renegotiate: 1,
7215 flags: []string{
7216 "-renegotiate-freely",
7217 "-expect-total-renegotiations", "1",
7218 },
7219 shouldFail: true,
7220 expectedError: ":NO_RENEGOTIATION:",
7221 expectedLocalError: "remote error: no renegotiation",
7222 })
7223
David Benjamina1eaba12017-01-01 23:19:22 -05007224 // Renegotiation is not allowed when there is an unfinished write.
7225 testCases = append(testCases, testCase{
7226 name: "Renegotiate-Client-UnfinishedWrite",
7227 config: Config{
7228 MaxVersion: VersionTLS12,
7229 },
David Benjaminbbba9392017-04-06 12:54:12 -04007230 renegotiate: 1,
7231 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007232 flags: []string{
7233 "-async",
7234 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007235 },
7236 shouldFail: true,
7237 expectedError: ":NO_RENEGOTIATION:",
7238 // We do not successfully send the no_renegotiation alert in
7239 // this case. https://crbug.com/boringssl/130
7240 })
7241
David Benjamin07ab5d42017-02-09 20:11:41 -05007242 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007243 testCases = append(testCases, testCase{
7244 name: "StrayHelloRequest",
7245 config: Config{
7246 MaxVersion: VersionTLS12,
7247 Bugs: ProtocolBugs{
7248 SendHelloRequestBeforeEveryHandshakeMessage: true,
7249 },
7250 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007251 shouldFail: true,
7252 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007253 })
7254 testCases = append(testCases, testCase{
7255 name: "StrayHelloRequest-Packed",
7256 config: Config{
7257 MaxVersion: VersionTLS12,
7258 Bugs: ProtocolBugs{
7259 PackHandshakeFlight: true,
7260 SendHelloRequestBeforeEveryHandshakeMessage: true,
7261 },
7262 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007263 shouldFail: true,
7264 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007265 })
7266
David Benjamin12d2c482016-07-24 10:56:51 -04007267 // Test renegotiation works if HelloRequest and server Finished come in
7268 // the same record.
7269 testCases = append(testCases, testCase{
7270 name: "Renegotiate-Client-Packed",
7271 config: Config{
7272 MaxVersion: VersionTLS12,
7273 Bugs: ProtocolBugs{
7274 PackHandshakeFlight: true,
7275 PackHelloRequestWithFinished: true,
7276 },
7277 },
7278 renegotiate: 1,
7279 flags: []string{
7280 "-renegotiate-freely",
7281 "-expect-total-renegotiations", "1",
7282 },
7283 })
7284
David Benjamin397c8e62016-07-08 14:14:36 -07007285 // Renegotiation is forbidden in TLS 1.3.
7286 testCases = append(testCases, testCase{
7287 name: "Renegotiate-Client-TLS13",
7288 config: Config{
7289 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007290 Bugs: ProtocolBugs{
7291 SendHelloRequestBeforeEveryAppDataRecord: true,
7292 },
David Benjamin397c8e62016-07-08 14:14:36 -07007293 },
David Benjamin397c8e62016-07-08 14:14:36 -07007294 flags: []string{
7295 "-renegotiate-freely",
7296 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007297 shouldFail: true,
7298 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007299 })
7300
7301 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7302 testCases = append(testCases, testCase{
7303 name: "StrayHelloRequest-TLS13",
7304 config: Config{
7305 MaxVersion: VersionTLS13,
7306 Bugs: ProtocolBugs{
7307 SendHelloRequestBeforeEveryHandshakeMessage: true,
7308 },
7309 },
7310 shouldFail: true,
7311 expectedError: ":UNEXPECTED_MESSAGE:",
7312 })
David Benjamind2610042017-01-03 10:49:28 -05007313
7314 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7315 // always reads as supporting it, regardless of whether it was
7316 // negotiated.
7317 testCases = append(testCases, testCase{
7318 name: "AlwaysReportRenegotiationInfo-TLS13",
7319 config: Config{
7320 MaxVersion: VersionTLS13,
7321 Bugs: ProtocolBugs{
7322 NoRenegotiationInfo: true,
7323 },
7324 },
7325 flags: []string{
7326 "-expect-secure-renegotiation",
7327 },
7328 })
David Benjamina58baaf2017-02-28 20:54:28 -05007329
7330 // Certificates may not change on renegotiation.
7331 testCases = append(testCases, testCase{
7332 name: "Renegotiation-CertificateChange",
7333 config: Config{
7334 MaxVersion: VersionTLS12,
7335 Certificates: []Certificate{rsaCertificate},
7336 Bugs: ProtocolBugs{
7337 RenegotiationCertificate: &rsaChainCertificate,
7338 },
7339 },
7340 renegotiate: 1,
7341 flags: []string{"-renegotiate-freely"},
7342 shouldFail: true,
7343 expectedError: ":SERVER_CERT_CHANGED:",
7344 })
7345 testCases = append(testCases, testCase{
7346 name: "Renegotiation-CertificateChange-2",
7347 config: Config{
7348 MaxVersion: VersionTLS12,
7349 Certificates: []Certificate{rsaCertificate},
7350 Bugs: ProtocolBugs{
7351 RenegotiationCertificate: &rsa1024Certificate,
7352 },
7353 },
7354 renegotiate: 1,
7355 flags: []string{"-renegotiate-freely"},
7356 shouldFail: true,
7357 expectedError: ":SERVER_CERT_CHANGED:",
7358 })
David Benjaminbbf42462017-03-14 21:27:10 -04007359
7360 // We do not negotiate ALPN after the initial handshake. This is
7361 // error-prone and only risks bugs in consumers.
7362 testCases = append(testCases, testCase{
7363 testType: clientTest,
7364 name: "Renegotiation-ForbidALPN",
7365 config: Config{
7366 MaxVersion: VersionTLS12,
7367 Bugs: ProtocolBugs{
7368 // Forcibly negotiate ALPN on both initial and
7369 // renegotiation handshakes. The test stack will
7370 // internally check the client does not offer
7371 // it.
7372 SendALPN: "foo",
7373 },
7374 },
7375 flags: []string{
7376 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7377 "-expect-alpn", "foo",
7378 "-renegotiate-freely",
7379 },
7380 renegotiate: 1,
7381 shouldFail: true,
7382 expectedError: ":UNEXPECTED_EXTENSION:",
7383 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007384}
7385
David Benjamin5e961c12014-11-07 01:48:35 -05007386func addDTLSReplayTests() {
7387 // Test that sequence number replays are detected.
7388 testCases = append(testCases, testCase{
7389 protocol: dtls,
7390 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007391 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007392 replayWrites: true,
7393 })
7394
David Benjamin8e6db492015-07-25 18:29:23 -04007395 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007396 // than the retransmit window.
7397 testCases = append(testCases, testCase{
7398 protocol: dtls,
7399 name: "DTLS-Replay-LargeGaps",
7400 config: Config{
7401 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007402 SequenceNumberMapping: func(in uint64) uint64 {
7403 return in * 127
7404 },
David Benjamin5e961c12014-11-07 01:48:35 -05007405 },
7406 },
David Benjamin8e6db492015-07-25 18:29:23 -04007407 messageCount: 200,
7408 replayWrites: true,
7409 })
7410
7411 // Test the incoming sequence number changing non-monotonically.
7412 testCases = append(testCases, testCase{
7413 protocol: dtls,
7414 name: "DTLS-Replay-NonMonotonic",
7415 config: Config{
7416 Bugs: ProtocolBugs{
7417 SequenceNumberMapping: func(in uint64) uint64 {
7418 return in ^ 31
7419 },
7420 },
7421 },
7422 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007423 replayWrites: true,
7424 })
7425}
7426
Nick Harper60edffd2016-06-21 15:19:24 -07007427var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007428 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007429 id signatureAlgorithm
7430 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007431}{
Nick Harper60edffd2016-06-21 15:19:24 -07007432 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7433 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7434 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7435 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007436 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007437 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7438 // hash function doesn't have to match the curve and so the same
7439 // signature algorithm works with P-224.
7440 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007441 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7442 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7443 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007444 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7445 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7446 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007447 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007448 // Tests for key types prior to TLS 1.2.
7449 {"RSA", 0, testCertRSA},
7450 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007451}
7452
Nick Harper60edffd2016-06-21 15:19:24 -07007453const fakeSigAlg1 signatureAlgorithm = 0x2a01
7454const fakeSigAlg2 signatureAlgorithm = 0xff01
7455
7456func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007457 // Not all ciphers involve a signature. Advertise a list which gives all
7458 // versions a signing cipher.
7459 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007460 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007461 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7462 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7463 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7464 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007465 }
David Benjamin5208fd42016-07-13 21:43:25 -04007466
David Benjaminca3d5452016-07-14 12:51:01 -04007467 var allAlgorithms []signatureAlgorithm
7468 for _, alg := range testSignatureAlgorithms {
7469 if alg.id != 0 {
7470 allAlgorithms = append(allAlgorithms, alg.id)
7471 }
7472 }
7473
Nick Harper60edffd2016-06-21 15:19:24 -07007474 // Make sure each signature algorithm works. Include some fake values in
7475 // the list and ensure they're ignored.
7476 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007477 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007478 if (ver.version < VersionTLS12) != (alg.id == 0) {
7479 continue
7480 }
7481
7482 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7483 // or remove it in C.
7484 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007485 continue
7486 }
Nick Harper60edffd2016-06-21 15:19:24 -07007487
David Benjamin3ef76972016-10-17 17:59:54 -04007488 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007489 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007490 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007491 shouldSignFail = true
7492 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007493 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007494 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007495 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7496 shouldSignFail = true
7497 shouldVerifyFail = true
7498 }
7499 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7500 // the curve has to match the hash size.
7501 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007502 shouldSignFail = true
7503 shouldVerifyFail = true
7504 }
7505
7506 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7507 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7508 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007509 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007510
7511 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007512 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007513 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007514 }
7515 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007516 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007517 }
David Benjamin000800a2014-11-14 01:43:59 -05007518
David Benjamin1fb125c2016-07-08 18:52:12 -07007519 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007520
David Benjamin7a41d372016-07-09 11:21:54 -07007521 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007522 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007523 config: Config{
7524 MaxVersion: ver.version,
7525 ClientAuth: RequireAnyClientCert,
7526 VerifySignatureAlgorithms: []signatureAlgorithm{
7527 fakeSigAlg1,
7528 alg.id,
7529 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007530 },
David Benjamin7a41d372016-07-09 11:21:54 -07007531 },
7532 flags: []string{
7533 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7534 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7535 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007536 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007537 },
David Benjamina5022392017-07-10 17:40:39 -04007538 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007539 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007540 expectedError: signError,
7541 expectedPeerSignatureAlgorithm: alg.id,
7542 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007543
David Benjamin7a41d372016-07-09 11:21:54 -07007544 testCases = append(testCases, testCase{
7545 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007546 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007547 config: Config{
7548 MaxVersion: ver.version,
7549 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7550 SignSignatureAlgorithms: []signatureAlgorithm{
7551 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007552 },
David Benjamin7a41d372016-07-09 11:21:54 -07007553 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007554 SkipECDSACurveCheck: shouldVerifyFail,
7555 IgnoreSignatureVersionChecks: shouldVerifyFail,
7556 // Some signature algorithms may not be advertised.
7557 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007558 },
David Benjamin7a41d372016-07-09 11:21:54 -07007559 },
David Benjamina5022392017-07-10 17:40:39 -04007560 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007561 flags: []string{
7562 "-require-any-client-certificate",
7563 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7564 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007565 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007566 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007567 // Resume the session to assert the peer signature
7568 // algorithm is reported on both handshakes.
7569 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007570 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007571 expectedError: verifyError,
7572 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007573
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007574 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007575 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007576 testCases = append(testCases, testCase{
7577 testType: serverTest,
7578 name: "ServerAuth-Sign" + suffix,
7579 config: Config{
7580 MaxVersion: ver.version,
7581 CipherSuites: signingCiphers,
7582 VerifySignatureAlgorithms: []signatureAlgorithm{
7583 fakeSigAlg1,
7584 alg.id,
7585 fakeSigAlg2,
7586 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007587 },
David Benjamina5022392017-07-10 17:40:39 -04007588 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007589 flags: []string{
7590 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7591 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7592 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007593 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007594 },
7595 shouldFail: shouldSignFail,
7596 expectedError: signError,
7597 expectedPeerSignatureAlgorithm: alg.id,
7598 })
7599 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007600
7601 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007602 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007603 config: Config{
7604 MaxVersion: ver.version,
7605 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007606 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007607 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007608 alg.id,
7609 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007610 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007611 SkipECDSACurveCheck: shouldVerifyFail,
7612 IgnoreSignatureVersionChecks: shouldVerifyFail,
7613 // Some signature algorithms may not be advertised.
7614 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007615 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007616 },
David Benjamina5022392017-07-10 17:40:39 -04007617 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007618 flags: []string{
7619 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7620 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007621 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007622 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007623 // Resume the session to assert the peer signature
7624 // algorithm is reported on both handshakes.
7625 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007626 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007627 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007628 })
David Benjamin5208fd42016-07-13 21:43:25 -04007629
David Benjamin3ef76972016-10-17 17:59:54 -04007630 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007631 testCases = append(testCases, testCase{
7632 testType: serverTest,
7633 name: "ClientAuth-InvalidSignature" + suffix,
7634 config: Config{
7635 MaxVersion: ver.version,
7636 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7637 SignSignatureAlgorithms: []signatureAlgorithm{
7638 alg.id,
7639 },
7640 Bugs: ProtocolBugs{
7641 InvalidSignature: true,
7642 },
7643 },
David Benjamina5022392017-07-10 17:40:39 -04007644 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007645 flags: []string{
7646 "-require-any-client-certificate",
7647 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007648 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007649 },
7650 shouldFail: true,
7651 expectedError: ":BAD_SIGNATURE:",
7652 })
7653
7654 testCases = append(testCases, testCase{
7655 name: "ServerAuth-InvalidSignature" + suffix,
7656 config: Config{
7657 MaxVersion: ver.version,
7658 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7659 CipherSuites: signingCiphers,
7660 SignSignatureAlgorithms: []signatureAlgorithm{
7661 alg.id,
7662 },
7663 Bugs: ProtocolBugs{
7664 InvalidSignature: true,
7665 },
7666 },
David Benjamina5022392017-07-10 17:40:39 -04007667 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007668 flags: []string{
7669 "-enable-all-curves",
7670 "-enable-ed25519",
7671 },
David Benjamin5208fd42016-07-13 21:43:25 -04007672 shouldFail: true,
7673 expectedError: ":BAD_SIGNATURE:",
7674 })
7675 }
David Benjaminca3d5452016-07-14 12:51:01 -04007676
David Benjamin3ef76972016-10-17 17:59:54 -04007677 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007678 testCases = append(testCases, testCase{
7679 name: "ClientAuth-Sign-Negotiate" + suffix,
7680 config: Config{
7681 MaxVersion: ver.version,
7682 ClientAuth: RequireAnyClientCert,
7683 VerifySignatureAlgorithms: allAlgorithms,
7684 },
David Benjamina5022392017-07-10 17:40:39 -04007685 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007686 flags: []string{
7687 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7688 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7689 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007690 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007691 "-signing-prefs", strconv.Itoa(int(alg.id)),
7692 },
7693 expectedPeerSignatureAlgorithm: alg.id,
7694 })
7695
7696 testCases = append(testCases, testCase{
7697 testType: serverTest,
7698 name: "ServerAuth-Sign-Negotiate" + suffix,
7699 config: Config{
7700 MaxVersion: ver.version,
7701 CipherSuites: signingCiphers,
7702 VerifySignatureAlgorithms: allAlgorithms,
7703 },
David Benjamina5022392017-07-10 17:40:39 -04007704 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007705 flags: []string{
7706 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7707 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7708 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007709 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007710 "-signing-prefs", strconv.Itoa(int(alg.id)),
7711 },
7712 expectedPeerSignatureAlgorithm: alg.id,
7713 })
7714 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007715 }
David Benjamin000800a2014-11-14 01:43:59 -05007716 }
7717
Nick Harper60edffd2016-06-21 15:19:24 -07007718 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007719 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007720 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007721 config: Config{
7722 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007723 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007724 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007725 signatureECDSAWithP521AndSHA512,
7726 signatureRSAPKCS1WithSHA384,
7727 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007728 },
7729 },
7730 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007731 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7732 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007733 },
Nick Harper60edffd2016-06-21 15:19:24 -07007734 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007735 })
7736
7737 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007738 name: "ClientAuth-SignatureType-TLS13",
7739 config: Config{
7740 ClientAuth: RequireAnyClientCert,
7741 MaxVersion: VersionTLS13,
7742 VerifySignatureAlgorithms: []signatureAlgorithm{
7743 signatureECDSAWithP521AndSHA512,
7744 signatureRSAPKCS1WithSHA384,
7745 signatureRSAPSSWithSHA384,
7746 signatureECDSAWithSHA1,
7747 },
7748 },
7749 flags: []string{
7750 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7751 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7752 },
7753 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7754 })
7755
7756 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007757 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007758 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007759 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007760 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007762 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007763 signatureECDSAWithP521AndSHA512,
7764 signatureRSAPKCS1WithSHA384,
7765 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007766 },
7767 },
Nick Harper60edffd2016-06-21 15:19:24 -07007768 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007769 })
7770
Steven Valdez143e8b32016-07-11 13:19:03 -04007771 testCases = append(testCases, testCase{
7772 testType: serverTest,
7773 name: "ServerAuth-SignatureType-TLS13",
7774 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007775 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007776 VerifySignatureAlgorithms: []signatureAlgorithm{
7777 signatureECDSAWithP521AndSHA512,
7778 signatureRSAPKCS1WithSHA384,
7779 signatureRSAPSSWithSHA384,
7780 signatureECDSAWithSHA1,
7781 },
7782 },
7783 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7784 })
7785
David Benjamina95e9f32016-07-08 16:28:04 -07007786 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007787 testCases = append(testCases, testCase{
7788 testType: serverTest,
7789 name: "Verify-ClientAuth-SignatureType",
7790 config: Config{
7791 MaxVersion: VersionTLS12,
7792 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007793 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007794 signatureRSAPKCS1WithSHA256,
7795 },
7796 Bugs: ProtocolBugs{
7797 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7798 },
7799 },
7800 flags: []string{
7801 "-require-any-client-certificate",
7802 },
7803 shouldFail: true,
7804 expectedError: ":WRONG_SIGNATURE_TYPE:",
7805 })
7806
7807 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007808 testType: serverTest,
7809 name: "Verify-ClientAuth-SignatureType-TLS13",
7810 config: Config{
7811 MaxVersion: VersionTLS13,
7812 Certificates: []Certificate{rsaCertificate},
7813 SignSignatureAlgorithms: []signatureAlgorithm{
7814 signatureRSAPSSWithSHA256,
7815 },
7816 Bugs: ProtocolBugs{
7817 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7818 },
7819 },
7820 flags: []string{
7821 "-require-any-client-certificate",
7822 },
7823 shouldFail: true,
7824 expectedError: ":WRONG_SIGNATURE_TYPE:",
7825 })
7826
7827 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007828 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007829 config: Config{
7830 MaxVersion: VersionTLS12,
7831 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007832 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007833 signatureRSAPKCS1WithSHA256,
7834 },
7835 Bugs: ProtocolBugs{
7836 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7837 },
7838 },
7839 shouldFail: true,
7840 expectedError: ":WRONG_SIGNATURE_TYPE:",
7841 })
7842
Steven Valdez143e8b32016-07-11 13:19:03 -04007843 testCases = append(testCases, testCase{
7844 name: "Verify-ServerAuth-SignatureType-TLS13",
7845 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007846 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007847 SignSignatureAlgorithms: []signatureAlgorithm{
7848 signatureRSAPSSWithSHA256,
7849 },
7850 Bugs: ProtocolBugs{
7851 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7852 },
7853 },
7854 shouldFail: true,
7855 expectedError: ":WRONG_SIGNATURE_TYPE:",
7856 })
7857
David Benjamin51dd7d62016-07-08 16:07:01 -07007858 // Test that, if the list is missing, the peer falls back to SHA-1 in
7859 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007860 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007861 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007863 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007864 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007865 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007866 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007867 },
7868 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007869 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007870 },
7871 },
7872 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007873 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7874 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007875 },
7876 })
7877
7878 testCases = append(testCases, testCase{
7879 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007880 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007881 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007882 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007883 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007884 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007885 },
7886 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007887 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007888 },
7889 },
David Benjaminee32bea2016-08-17 13:36:44 -04007890 flags: []string{
7891 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7892 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7893 },
7894 })
7895
7896 testCases = append(testCases, testCase{
7897 name: "ClientAuth-SHA1-Fallback-ECDSA",
7898 config: Config{
7899 MaxVersion: VersionTLS12,
7900 ClientAuth: RequireAnyClientCert,
7901 VerifySignatureAlgorithms: []signatureAlgorithm{
7902 signatureECDSAWithSHA1,
7903 },
7904 Bugs: ProtocolBugs{
7905 NoSignatureAlgorithms: true,
7906 },
7907 },
7908 flags: []string{
7909 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7910 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7911 },
7912 })
7913
7914 testCases = append(testCases, testCase{
7915 testType: serverTest,
7916 name: "ServerAuth-SHA1-Fallback-ECDSA",
7917 config: Config{
7918 MaxVersion: VersionTLS12,
7919 VerifySignatureAlgorithms: []signatureAlgorithm{
7920 signatureECDSAWithSHA1,
7921 },
7922 Bugs: ProtocolBugs{
7923 NoSignatureAlgorithms: true,
7924 },
7925 },
7926 flags: []string{
7927 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7928 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7929 },
David Benjamin000800a2014-11-14 01:43:59 -05007930 })
David Benjamin72dc7832015-03-16 17:49:43 -04007931
David Benjamin51dd7d62016-07-08 16:07:01 -07007932 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007933 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007934 config: Config{
7935 MaxVersion: VersionTLS13,
7936 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007937 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007938 signatureRSAPKCS1WithSHA1,
7939 },
7940 Bugs: ProtocolBugs{
7941 NoSignatureAlgorithms: true,
7942 },
7943 },
7944 flags: []string{
7945 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7946 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7947 },
David Benjamin48901652016-08-01 12:12:47 -04007948 shouldFail: true,
7949 // An empty CertificateRequest signature algorithm list is a
7950 // syntax error in TLS 1.3.
7951 expectedError: ":DECODE_ERROR:",
7952 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007953 })
7954
7955 testCases = append(testCases, testCase{
7956 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007957 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007958 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007959 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007960 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007961 signatureRSAPKCS1WithSHA1,
7962 },
7963 Bugs: ProtocolBugs{
7964 NoSignatureAlgorithms: true,
7965 },
7966 },
7967 shouldFail: true,
7968 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7969 })
7970
David Benjaminb62d2872016-07-18 14:55:02 +02007971 // Test that hash preferences are enforced. BoringSSL does not implement
7972 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007973 testCases = append(testCases, testCase{
7974 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007975 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007977 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007978 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007979 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007980 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007981 },
7982 Bugs: ProtocolBugs{
7983 IgnorePeerSignatureAlgorithmPreferences: true,
7984 },
7985 },
7986 flags: []string{"-require-any-client-certificate"},
7987 shouldFail: true,
7988 expectedError: ":WRONG_SIGNATURE_TYPE:",
7989 })
7990
7991 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007992 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007994 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007995 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007996 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007997 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007998 },
7999 Bugs: ProtocolBugs{
8000 IgnorePeerSignatureAlgorithmPreferences: true,
8001 },
8002 },
8003 shouldFail: true,
8004 expectedError: ":WRONG_SIGNATURE_TYPE:",
8005 })
David Benjaminb62d2872016-07-18 14:55:02 +02008006 testCases = append(testCases, testCase{
8007 testType: serverTest,
8008 name: "ClientAuth-Enforced-TLS13",
8009 config: Config{
8010 MaxVersion: VersionTLS13,
8011 Certificates: []Certificate{rsaCertificate},
8012 SignSignatureAlgorithms: []signatureAlgorithm{
8013 signatureRSAPKCS1WithMD5,
8014 },
8015 Bugs: ProtocolBugs{
8016 IgnorePeerSignatureAlgorithmPreferences: true,
8017 IgnoreSignatureVersionChecks: true,
8018 },
8019 },
8020 flags: []string{"-require-any-client-certificate"},
8021 shouldFail: true,
8022 expectedError: ":WRONG_SIGNATURE_TYPE:",
8023 })
8024
8025 testCases = append(testCases, testCase{
8026 name: "ServerAuth-Enforced-TLS13",
8027 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008028 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008029 SignSignatureAlgorithms: []signatureAlgorithm{
8030 signatureRSAPKCS1WithMD5,
8031 },
8032 Bugs: ProtocolBugs{
8033 IgnorePeerSignatureAlgorithmPreferences: true,
8034 IgnoreSignatureVersionChecks: true,
8035 },
8036 },
8037 shouldFail: true,
8038 expectedError: ":WRONG_SIGNATURE_TYPE:",
8039 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008040
8041 // Test that the agreed upon digest respects the client preferences and
8042 // the server digests.
8043 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008044 name: "NoCommonAlgorithms-Digests",
8045 config: Config{
8046 MaxVersion: VersionTLS12,
8047 ClientAuth: RequireAnyClientCert,
8048 VerifySignatureAlgorithms: []signatureAlgorithm{
8049 signatureRSAPKCS1WithSHA512,
8050 signatureRSAPKCS1WithSHA1,
8051 },
8052 },
8053 flags: []string{
8054 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8055 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8056 "-digest-prefs", "SHA256",
8057 },
8058 shouldFail: true,
8059 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8060 })
8061 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008062 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008064 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008065 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008066 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008067 signatureRSAPKCS1WithSHA512,
8068 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008069 },
8070 },
8071 flags: []string{
8072 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8073 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008074 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008075 },
David Benjaminca3d5452016-07-14 12:51:01 -04008076 shouldFail: true,
8077 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8078 })
8079 testCases = append(testCases, testCase{
8080 name: "NoCommonAlgorithms-TLS13",
8081 config: Config{
8082 MaxVersion: VersionTLS13,
8083 ClientAuth: RequireAnyClientCert,
8084 VerifySignatureAlgorithms: []signatureAlgorithm{
8085 signatureRSAPSSWithSHA512,
8086 signatureRSAPSSWithSHA384,
8087 },
8088 },
8089 flags: []string{
8090 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8091 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8092 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8093 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008094 shouldFail: true,
8095 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008096 })
8097 testCases = append(testCases, testCase{
8098 name: "Agree-Digest-SHA256",
8099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008100 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008101 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008102 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008103 signatureRSAPKCS1WithSHA1,
8104 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008105 },
8106 },
8107 flags: []string{
8108 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8109 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008110 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008111 },
Nick Harper60edffd2016-06-21 15:19:24 -07008112 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008113 })
8114 testCases = append(testCases, testCase{
8115 name: "Agree-Digest-SHA1",
8116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008117 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008118 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008119 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008120 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008121 },
8122 },
8123 flags: []string{
8124 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8125 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008126 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008127 },
Nick Harper60edffd2016-06-21 15:19:24 -07008128 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008129 })
8130 testCases = append(testCases, testCase{
8131 name: "Agree-Digest-Default",
8132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008133 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008134 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008135 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008136 signatureRSAPKCS1WithSHA256,
8137 signatureECDSAWithP256AndSHA256,
8138 signatureRSAPKCS1WithSHA1,
8139 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008140 },
8141 },
8142 flags: []string{
8143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8145 },
Nick Harper60edffd2016-06-21 15:19:24 -07008146 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008147 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008148
David Benjaminca3d5452016-07-14 12:51:01 -04008149 // Test that the signing preference list may include extra algorithms
8150 // without negotiation problems.
8151 testCases = append(testCases, testCase{
8152 testType: serverTest,
8153 name: "FilterExtraAlgorithms",
8154 config: Config{
8155 MaxVersion: VersionTLS12,
8156 VerifySignatureAlgorithms: []signatureAlgorithm{
8157 signatureRSAPKCS1WithSHA256,
8158 },
8159 },
8160 flags: []string{
8161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8163 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8164 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8165 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8166 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8167 },
8168 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8169 })
8170
David Benjamin4c3ddf72016-06-29 18:13:53 -04008171 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8172 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008173 testCases = append(testCases, testCase{
8174 name: "CheckLeafCurve",
8175 config: Config{
8176 MaxVersion: VersionTLS12,
8177 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008178 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008179 },
8180 flags: []string{"-p384-only"},
8181 shouldFail: true,
8182 expectedError: ":BAD_ECC_CERT:",
8183 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008184
8185 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8186 testCases = append(testCases, testCase{
8187 name: "CheckLeafCurve-TLS13",
8188 config: Config{
8189 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008190 Certificates: []Certificate{ecdsaP256Certificate},
8191 },
8192 flags: []string{"-p384-only"},
8193 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008194
8195 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8196 testCases = append(testCases, testCase{
8197 name: "ECDSACurveMismatch-Verify-TLS12",
8198 config: Config{
8199 MaxVersion: VersionTLS12,
8200 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8201 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008202 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008203 signatureECDSAWithP384AndSHA384,
8204 },
8205 },
8206 })
8207
8208 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8209 testCases = append(testCases, testCase{
8210 name: "ECDSACurveMismatch-Verify-TLS13",
8211 config: Config{
8212 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008213 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008214 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008215 signatureECDSAWithP384AndSHA384,
8216 },
8217 Bugs: ProtocolBugs{
8218 SkipECDSACurveCheck: true,
8219 },
8220 },
8221 shouldFail: true,
8222 expectedError: ":WRONG_SIGNATURE_TYPE:",
8223 })
8224
8225 // Signature algorithm selection in TLS 1.3 should take the curve into
8226 // account.
8227 testCases = append(testCases, testCase{
8228 testType: serverTest,
8229 name: "ECDSACurveMismatch-Sign-TLS13",
8230 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008231 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008232 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008233 signatureECDSAWithP384AndSHA384,
8234 signatureECDSAWithP256AndSHA256,
8235 },
8236 },
8237 flags: []string{
8238 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8239 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8240 },
8241 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8242 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008243
8244 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8245 // server does not attempt to sign in that case.
8246 testCases = append(testCases, testCase{
8247 testType: serverTest,
8248 name: "RSA-PSS-Large",
8249 config: Config{
8250 MaxVersion: VersionTLS13,
8251 VerifySignatureAlgorithms: []signatureAlgorithm{
8252 signatureRSAPSSWithSHA512,
8253 },
8254 },
8255 flags: []string{
8256 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8257 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8258 },
8259 shouldFail: true,
8260 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8261 })
David Benjamin57e929f2016-08-30 00:30:38 -04008262
8263 // Test that RSA-PSS is enabled by default for TLS 1.2.
8264 testCases = append(testCases, testCase{
8265 testType: clientTest,
8266 name: "RSA-PSS-Default-Verify",
8267 config: Config{
8268 MaxVersion: VersionTLS12,
8269 SignSignatureAlgorithms: []signatureAlgorithm{
8270 signatureRSAPSSWithSHA256,
8271 },
8272 },
8273 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8274 })
8275
8276 testCases = append(testCases, testCase{
8277 testType: serverTest,
8278 name: "RSA-PSS-Default-Sign",
8279 config: Config{
8280 MaxVersion: VersionTLS12,
8281 VerifySignatureAlgorithms: []signatureAlgorithm{
8282 signatureRSAPSSWithSHA256,
8283 },
8284 },
8285 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8286 })
David Benjamin69522112017-03-28 15:38:29 -05008287
8288 // TLS 1.1 and below has no way to advertise support for or negotiate
8289 // Ed25519's signature algorithm.
8290 testCases = append(testCases, testCase{
8291 testType: clientTest,
8292 name: "NoEd25519-TLS11-ServerAuth-Verify",
8293 config: Config{
8294 MaxVersion: VersionTLS11,
8295 Certificates: []Certificate{ed25519Certificate},
8296 Bugs: ProtocolBugs{
8297 // Sign with Ed25519 even though it is TLS 1.1.
8298 UseLegacySigningAlgorithm: signatureEd25519,
8299 },
8300 },
8301 flags: []string{"-enable-ed25519"},
8302 shouldFail: true,
8303 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8304 })
8305 testCases = append(testCases, testCase{
8306 testType: serverTest,
8307 name: "NoEd25519-TLS11-ServerAuth-Sign",
8308 config: Config{
8309 MaxVersion: VersionTLS11,
8310 },
8311 flags: []string{
8312 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8313 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8314 },
8315 shouldFail: true,
8316 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8317 })
8318 testCases = append(testCases, testCase{
8319 testType: serverTest,
8320 name: "NoEd25519-TLS11-ClientAuth-Verify",
8321 config: Config{
8322 MaxVersion: VersionTLS11,
8323 Certificates: []Certificate{ed25519Certificate},
8324 Bugs: ProtocolBugs{
8325 // Sign with Ed25519 even though it is TLS 1.1.
8326 UseLegacySigningAlgorithm: signatureEd25519,
8327 },
8328 },
8329 flags: []string{
8330 "-enable-ed25519",
8331 "-require-any-client-certificate",
8332 },
8333 shouldFail: true,
8334 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8335 })
8336 testCases = append(testCases, testCase{
8337 testType: clientTest,
8338 name: "NoEd25519-TLS11-ClientAuth-Sign",
8339 config: Config{
8340 MaxVersion: VersionTLS11,
8341 ClientAuth: RequireAnyClientCert,
8342 },
8343 flags: []string{
8344 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8345 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8346 },
8347 shouldFail: true,
8348 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8349 })
8350
8351 // Test Ed25519 is not advertised by default.
8352 testCases = append(testCases, testCase{
8353 testType: clientTest,
8354 name: "Ed25519DefaultDisable-NoAdvertise",
8355 config: Config{
8356 Certificates: []Certificate{ed25519Certificate},
8357 },
8358 shouldFail: true,
8359 expectedLocalError: "tls: no common signature algorithms",
8360 })
8361
8362 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8363 // preferences.
8364 testCases = append(testCases, testCase{
8365 testType: clientTest,
8366 name: "Ed25519DefaultDisable-NoAccept",
8367 config: Config{
8368 Certificates: []Certificate{ed25519Certificate},
8369 Bugs: ProtocolBugs{
8370 IgnorePeerSignatureAlgorithmPreferences: true,
8371 },
8372 },
8373 shouldFail: true,
8374 expectedLocalError: "remote error: illegal parameter",
8375 expectedError: ":WRONG_SIGNATURE_TYPE:",
8376 })
David Benjamin71c21b42017-04-14 17:05:40 -04008377
8378 // Test that configuring verify preferences changes what the client
8379 // advertises.
8380 testCases = append(testCases, testCase{
8381 name: "VerifyPreferences-Advertised",
8382 config: Config{
8383 Certificates: []Certificate{rsaCertificate},
8384 SignSignatureAlgorithms: []signatureAlgorithm{
8385 signatureRSAPSSWithSHA256,
8386 signatureRSAPSSWithSHA384,
8387 signatureRSAPSSWithSHA512,
8388 },
8389 },
8390 flags: []string{
8391 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8392 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8393 },
8394 })
8395
8396 // Test that the client advertises a set which the runner can find
8397 // nothing in common with.
8398 testCases = append(testCases, testCase{
8399 name: "VerifyPreferences-NoCommonAlgorithms",
8400 config: Config{
8401 Certificates: []Certificate{rsaCertificate},
8402 SignSignatureAlgorithms: []signatureAlgorithm{
8403 signatureRSAPSSWithSHA256,
8404 signatureRSAPSSWithSHA512,
8405 },
8406 },
8407 flags: []string{
8408 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8409 },
8410 shouldFail: true,
8411 expectedLocalError: "tls: no common signature algorithms",
8412 })
8413
8414 // Test that the client enforces its preferences when configured.
8415 testCases = append(testCases, testCase{
8416 name: "VerifyPreferences-Enforced",
8417 config: Config{
8418 Certificates: []Certificate{rsaCertificate},
8419 SignSignatureAlgorithms: []signatureAlgorithm{
8420 signatureRSAPSSWithSHA256,
8421 signatureRSAPSSWithSHA512,
8422 },
8423 Bugs: ProtocolBugs{
8424 IgnorePeerSignatureAlgorithmPreferences: true,
8425 },
8426 },
8427 flags: []string{
8428 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8429 },
8430 shouldFail: true,
8431 expectedLocalError: "remote error: illegal parameter",
8432 expectedError: ":WRONG_SIGNATURE_TYPE:",
8433 })
8434
8435 // Test that explicitly configuring Ed25519 is as good as changing the
8436 // boolean toggle.
8437 testCases = append(testCases, testCase{
8438 name: "VerifyPreferences-Ed25519",
8439 config: Config{
8440 Certificates: []Certificate{ed25519Certificate},
8441 },
8442 flags: []string{
8443 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8444 },
8445 })
David Benjamin000800a2014-11-14 01:43:59 -05008446}
8447
David Benjamin83f90402015-01-27 01:09:43 -05008448// timeouts is the retransmit schedule for BoringSSL. It doubles and
8449// caps at 60 seconds. On the 13th timeout, it gives up.
8450var timeouts = []time.Duration{
8451 1 * time.Second,
8452 2 * time.Second,
8453 4 * time.Second,
8454 8 * time.Second,
8455 16 * time.Second,
8456 32 * time.Second,
8457 60 * time.Second,
8458 60 * time.Second,
8459 60 * time.Second,
8460 60 * time.Second,
8461 60 * time.Second,
8462 60 * time.Second,
8463 60 * time.Second,
8464}
8465
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008466// shortTimeouts is an alternate set of timeouts which would occur if the
8467// initial timeout duration was set to 250ms.
8468var shortTimeouts = []time.Duration{
8469 250 * time.Millisecond,
8470 500 * time.Millisecond,
8471 1 * time.Second,
8472 2 * time.Second,
8473 4 * time.Second,
8474 8 * time.Second,
8475 16 * time.Second,
8476 32 * time.Second,
8477 60 * time.Second,
8478 60 * time.Second,
8479 60 * time.Second,
8480 60 * time.Second,
8481 60 * time.Second,
8482}
8483
David Benjamin83f90402015-01-27 01:09:43 -05008484func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008485 // These tests work by coordinating some behavior on both the shim and
8486 // the runner.
8487 //
8488 // TimeoutSchedule configures the runner to send a series of timeout
8489 // opcodes to the shim (see packetAdaptor) immediately before reading
8490 // each peer handshake flight N. The timeout opcode both simulates a
8491 // timeout in the shim and acts as a synchronization point to help the
8492 // runner bracket each handshake flight.
8493 //
8494 // We assume the shim does not read from the channel eagerly. It must
8495 // first wait until it has sent flight N and is ready to receive
8496 // handshake flight N+1. At this point, it will process the timeout
8497 // opcode. It must then immediately respond with a timeout ACK and act
8498 // as if the shim was idle for the specified amount of time.
8499 //
8500 // The runner then drops all packets received before the ACK and
8501 // continues waiting for flight N. This ordering results in one attempt
8502 // at sending flight N to be dropped. For the test to complete, the
8503 // shim must send flight N again, testing that the shim implements DTLS
8504 // retransmit on a timeout.
8505
Steven Valdez143e8b32016-07-11 13:19:03 -04008506 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008507 // likely be more epochs to cross and the final message's retransmit may
8508 // be more complex.
8509
David Benjamin11c82892017-02-23 20:40:31 -05008510 // Test that this is indeed the timeout schedule. Stress all
8511 // four patterns of handshake.
8512 for i := 1; i < len(timeouts); i++ {
8513 number := strconv.Itoa(i)
8514 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008515 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008516 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008518 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008519 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008520 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008521 },
8522 },
8523 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008524 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008525 })
David Benjamin11c82892017-02-23 20:40:31 -05008526 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008527 protocol: dtls,
8528 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008529 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008531 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008532 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008533 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008534 },
8535 },
8536 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008537 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008538 })
8539 }
David Benjamin11c82892017-02-23 20:40:31 -05008540
8541 // Test that exceeding the timeout schedule hits a read
8542 // timeout.
8543 testCases = append(testCases, testCase{
8544 protocol: dtls,
8545 name: "DTLS-Retransmit-Timeout",
8546 config: Config{
8547 MaxVersion: VersionTLS12,
8548 Bugs: ProtocolBugs{
8549 TimeoutSchedule: timeouts,
8550 },
8551 },
8552 resumeSession: true,
8553 flags: []string{"-async"},
8554 shouldFail: true,
8555 expectedError: ":READ_TIMEOUT_EXPIRED:",
8556 })
8557
8558 // Test that timeout handling has a fudge factor, due to API
8559 // problems.
8560 testCases = append(testCases, testCase{
8561 protocol: dtls,
8562 name: "DTLS-Retransmit-Fudge",
8563 config: Config{
8564 MaxVersion: VersionTLS12,
8565 Bugs: ProtocolBugs{
8566 TimeoutSchedule: []time.Duration{
8567 timeouts[0] - 10*time.Millisecond,
8568 },
8569 },
8570 },
8571 resumeSession: true,
8572 flags: []string{"-async"},
8573 })
8574
8575 // Test that the final Finished retransmitting isn't
8576 // duplicated if the peer badly fragments everything.
8577 testCases = append(testCases, testCase{
8578 testType: serverTest,
8579 protocol: dtls,
8580 name: "DTLS-Retransmit-Fragmented",
8581 config: Config{
8582 MaxVersion: VersionTLS12,
8583 Bugs: ProtocolBugs{
8584 TimeoutSchedule: []time.Duration{timeouts[0]},
8585 MaxHandshakeRecordLength: 2,
8586 },
8587 },
8588 flags: []string{"-async"},
8589 })
8590
8591 // Test the timeout schedule when a shorter initial timeout duration is set.
8592 testCases = append(testCases, testCase{
8593 protocol: dtls,
8594 name: "DTLS-Retransmit-Short-Client",
8595 config: Config{
8596 MaxVersion: VersionTLS12,
8597 Bugs: ProtocolBugs{
8598 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8599 },
8600 },
8601 resumeSession: true,
8602 flags: []string{
8603 "-async",
8604 "-initial-timeout-duration-ms", "250",
8605 },
8606 })
8607 testCases = append(testCases, testCase{
8608 protocol: dtls,
8609 testType: serverTest,
8610 name: "DTLS-Retransmit-Short-Server",
8611 config: Config{
8612 MaxVersion: VersionTLS12,
8613 Bugs: ProtocolBugs{
8614 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8615 },
8616 },
8617 resumeSession: true,
8618 flags: []string{
8619 "-async",
8620 "-initial-timeout-duration-ms", "250",
8621 },
8622 })
David Benjamin83f90402015-01-27 01:09:43 -05008623}
8624
David Benjaminc565ebb2015-04-03 04:06:36 -04008625func addExportKeyingMaterialTests() {
8626 for _, vers := range tlsVersions {
8627 if vers.version == VersionSSL30 {
8628 continue
8629 }
8630 testCases = append(testCases, testCase{
8631 name: "ExportKeyingMaterial-" + vers.name,
8632 config: Config{
8633 MaxVersion: vers.version,
8634 },
David Benjamina5022392017-07-10 17:40:39 -04008635 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008636 exportKeyingMaterial: 1024,
8637 exportLabel: "label",
8638 exportContext: "context",
8639 useExportContext: true,
8640 })
8641 testCases = append(testCases, testCase{
8642 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8643 config: Config{
8644 MaxVersion: vers.version,
8645 },
David Benjamina5022392017-07-10 17:40:39 -04008646 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008647 exportKeyingMaterial: 1024,
8648 })
8649 testCases = append(testCases, testCase{
8650 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8651 config: Config{
8652 MaxVersion: vers.version,
8653 },
David Benjamina5022392017-07-10 17:40:39 -04008654 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008655 exportKeyingMaterial: 1024,
8656 useExportContext: true,
8657 })
8658 testCases = append(testCases, testCase{
8659 name: "ExportKeyingMaterial-Small-" + vers.name,
8660 config: Config{
8661 MaxVersion: vers.version,
8662 },
David Benjamina5022392017-07-10 17:40:39 -04008663 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008664 exportKeyingMaterial: 1,
8665 exportLabel: "label",
8666 exportContext: "context",
8667 useExportContext: true,
8668 })
8669 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008670
David Benjaminc565ebb2015-04-03 04:06:36 -04008671 testCases = append(testCases, testCase{
8672 name: "ExportKeyingMaterial-SSL3",
8673 config: Config{
8674 MaxVersion: VersionSSL30,
8675 },
8676 exportKeyingMaterial: 1024,
8677 exportLabel: "label",
8678 exportContext: "context",
8679 useExportContext: true,
8680 shouldFail: true,
8681 expectedError: "failed to export keying material",
8682 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008683
8684 // Exporters work during a False Start.
8685 testCases = append(testCases, testCase{
8686 name: "ExportKeyingMaterial-FalseStart",
8687 config: Config{
8688 MaxVersion: VersionTLS12,
8689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8690 NextProtos: []string{"foo"},
8691 Bugs: ProtocolBugs{
8692 ExpectFalseStart: true,
8693 },
8694 },
8695 flags: []string{
8696 "-false-start",
8697 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008698 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008699 },
8700 shimWritesFirst: true,
8701 exportKeyingMaterial: 1024,
8702 exportLabel: "label",
8703 exportContext: "context",
8704 useExportContext: true,
8705 })
8706
8707 // Exporters do not work in the middle of a renegotiation. Test this by
8708 // triggering the exporter after every SSL_read call and configuring the
8709 // shim to run asynchronously.
8710 testCases = append(testCases, testCase{
8711 name: "ExportKeyingMaterial-Renegotiate",
8712 config: Config{
8713 MaxVersion: VersionTLS12,
8714 },
8715 renegotiate: 1,
8716 flags: []string{
8717 "-async",
8718 "-use-exporter-between-reads",
8719 "-renegotiate-freely",
8720 "-expect-total-renegotiations", "1",
8721 },
8722 shouldFail: true,
8723 expectedError: "failed to export keying material",
8724 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008725}
8726
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008727func addTLSUniqueTests() {
8728 for _, isClient := range []bool{false, true} {
8729 for _, isResumption := range []bool{false, true} {
8730 for _, hasEMS := range []bool{false, true} {
8731 var suffix string
8732 if isResumption {
8733 suffix = "Resume-"
8734 } else {
8735 suffix = "Full-"
8736 }
8737
8738 if hasEMS {
8739 suffix += "EMS-"
8740 } else {
8741 suffix += "NoEMS-"
8742 }
8743
8744 if isClient {
8745 suffix += "Client"
8746 } else {
8747 suffix += "Server"
8748 }
8749
8750 test := testCase{
8751 name: "TLSUnique-" + suffix,
8752 testTLSUnique: true,
8753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008754 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008755 Bugs: ProtocolBugs{
8756 NoExtendedMasterSecret: !hasEMS,
8757 },
8758 },
8759 }
8760
8761 if isResumption {
8762 test.resumeSession = true
8763 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008764 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008765 Bugs: ProtocolBugs{
8766 NoExtendedMasterSecret: !hasEMS,
8767 },
8768 }
8769 }
8770
8771 if isResumption && !hasEMS {
8772 test.shouldFail = true
8773 test.expectedError = "failed to get tls-unique"
8774 }
8775
8776 testCases = append(testCases, test)
8777 }
8778 }
8779 }
8780}
8781
Adam Langley09505632015-07-30 18:10:13 -07008782func addCustomExtensionTests() {
8783 expectedContents := "custom extension"
8784 emptyString := ""
8785
8786 for _, isClient := range []bool{false, true} {
8787 suffix := "Server"
8788 flag := "-enable-server-custom-extension"
8789 testType := serverTest
8790 if isClient {
8791 suffix = "Client"
8792 flag = "-enable-client-custom-extension"
8793 testType = clientTest
8794 }
8795
8796 testCases = append(testCases, testCase{
8797 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008798 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008799 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008800 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008801 Bugs: ProtocolBugs{
8802 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008803 ExpectedCustomExtension: &expectedContents,
8804 },
8805 },
8806 flags: []string{flag},
8807 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008808 testCases = append(testCases, testCase{
8809 testType: testType,
8810 name: "CustomExtensions-" + suffix + "-TLS13",
8811 config: Config{
8812 MaxVersion: VersionTLS13,
8813 Bugs: ProtocolBugs{
8814 CustomExtension: expectedContents,
8815 ExpectedCustomExtension: &expectedContents,
8816 },
8817 },
8818 flags: []string{flag},
8819 })
Adam Langley09505632015-07-30 18:10:13 -07008820
Steven Valdez2a070722017-03-25 20:54:16 -05008821 // 0-RTT is not currently supported with Custom Extensions.
8822 testCases = append(testCases, testCase{
8823 testType: testType,
8824 name: "CustomExtensions-" + suffix + "-EarlyData",
8825 config: Config{
8826 MaxVersion: VersionTLS13,
8827 Bugs: ProtocolBugs{
8828 CustomExtension: expectedContents,
8829 ExpectedCustomExtension: &expectedContents,
8830 },
8831 },
8832 shouldFail: true,
8833 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8834 flags: []string{flag, "-enable-early-data"},
8835 })
8836
Adam Langley09505632015-07-30 18:10:13 -07008837 // If the parse callback fails, the handshake should also fail.
8838 testCases = append(testCases, testCase{
8839 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008840 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008841 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008842 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008843 Bugs: ProtocolBugs{
8844 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008845 ExpectedCustomExtension: &expectedContents,
8846 },
8847 },
David Benjamin399e7c92015-07-30 23:01:27 -04008848 flags: []string{flag},
8849 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008850 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8851 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008852 testCases = append(testCases, testCase{
8853 testType: testType,
8854 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8855 config: Config{
8856 MaxVersion: VersionTLS13,
8857 Bugs: ProtocolBugs{
8858 CustomExtension: expectedContents + "foo",
8859 ExpectedCustomExtension: &expectedContents,
8860 },
8861 },
8862 flags: []string{flag},
8863 shouldFail: true,
8864 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8865 })
Adam Langley09505632015-07-30 18:10:13 -07008866
8867 // If the add callback fails, the handshake should also fail.
8868 testCases = append(testCases, testCase{
8869 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008870 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008871 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008872 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008873 Bugs: ProtocolBugs{
8874 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008875 ExpectedCustomExtension: &expectedContents,
8876 },
8877 },
David Benjamin399e7c92015-07-30 23:01:27 -04008878 flags: []string{flag, "-custom-extension-fail-add"},
8879 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008880 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8881 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008882 testCases = append(testCases, testCase{
8883 testType: testType,
8884 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8885 config: Config{
8886 MaxVersion: VersionTLS13,
8887 Bugs: ProtocolBugs{
8888 CustomExtension: expectedContents,
8889 ExpectedCustomExtension: &expectedContents,
8890 },
8891 },
8892 flags: []string{flag, "-custom-extension-fail-add"},
8893 shouldFail: true,
8894 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8895 })
Adam Langley09505632015-07-30 18:10:13 -07008896
8897 // If the add callback returns zero, no extension should be
8898 // added.
8899 skipCustomExtension := expectedContents
8900 if isClient {
8901 // For the case where the client skips sending the
8902 // custom extension, the server must not “echo” it.
8903 skipCustomExtension = ""
8904 }
8905 testCases = append(testCases, testCase{
8906 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008907 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008908 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008909 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008910 Bugs: ProtocolBugs{
8911 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008912 ExpectedCustomExtension: &emptyString,
8913 },
8914 },
8915 flags: []string{flag, "-custom-extension-skip"},
8916 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008917 testCases = append(testCases, testCase{
8918 testType: testType,
8919 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8920 config: Config{
8921 MaxVersion: VersionTLS13,
8922 Bugs: ProtocolBugs{
8923 CustomExtension: skipCustomExtension,
8924 ExpectedCustomExtension: &emptyString,
8925 },
8926 },
8927 flags: []string{flag, "-custom-extension-skip"},
8928 })
Adam Langley09505632015-07-30 18:10:13 -07008929 }
8930
8931 // The custom extension add callback should not be called if the client
8932 // doesn't send the extension.
8933 testCases = append(testCases, testCase{
8934 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008935 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008937 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008938 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008939 ExpectedCustomExtension: &emptyString,
8940 },
8941 },
8942 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8943 })
Adam Langley2deb9842015-08-07 11:15:37 -07008944
Steven Valdez143e8b32016-07-11 13:19:03 -04008945 testCases = append(testCases, testCase{
8946 testType: serverTest,
8947 name: "CustomExtensions-NotCalled-Server-TLS13",
8948 config: Config{
8949 MaxVersion: VersionTLS13,
8950 Bugs: ProtocolBugs{
8951 ExpectedCustomExtension: &emptyString,
8952 },
8953 },
8954 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8955 })
8956
Adam Langley2deb9842015-08-07 11:15:37 -07008957 // Test an unknown extension from the server.
8958 testCases = append(testCases, testCase{
8959 testType: clientTest,
8960 name: "UnknownExtension-Client",
8961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008962 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008963 Bugs: ProtocolBugs{
8964 CustomExtension: expectedContents,
8965 },
8966 },
David Benjamin0c40a962016-08-01 12:05:50 -04008967 shouldFail: true,
8968 expectedError: ":UNEXPECTED_EXTENSION:",
8969 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008970 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008971 testCases = append(testCases, testCase{
8972 testType: clientTest,
8973 name: "UnknownExtension-Client-TLS13",
8974 config: Config{
8975 MaxVersion: VersionTLS13,
8976 Bugs: ProtocolBugs{
8977 CustomExtension: expectedContents,
8978 },
8979 },
David Benjamin0c40a962016-08-01 12:05:50 -04008980 shouldFail: true,
8981 expectedError: ":UNEXPECTED_EXTENSION:",
8982 expectedLocalError: "remote error: unsupported extension",
8983 })
David Benjamin490469f2016-10-05 22:44:38 -04008984 testCases = append(testCases, testCase{
8985 testType: clientTest,
8986 name: "UnknownUnencryptedExtension-Client-TLS13",
8987 config: Config{
8988 MaxVersion: VersionTLS13,
8989 Bugs: ProtocolBugs{
8990 CustomUnencryptedExtension: expectedContents,
8991 },
8992 },
8993 shouldFail: true,
8994 expectedError: ":UNEXPECTED_EXTENSION:",
8995 // The shim must send an alert, but alerts at this point do not
8996 // get successfully decrypted by the runner.
8997 expectedLocalError: "local error: bad record MAC",
8998 })
8999 testCases = append(testCases, testCase{
9000 testType: clientTest,
9001 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9002 config: Config{
9003 MaxVersion: VersionTLS13,
9004 Bugs: ProtocolBugs{
9005 SendUnencryptedALPN: "foo",
9006 },
9007 },
9008 flags: []string{
9009 "-advertise-alpn", "\x03foo\x03bar",
9010 },
9011 shouldFail: true,
9012 expectedError: ":UNEXPECTED_EXTENSION:",
9013 // The shim must send an alert, but alerts at this point do not
9014 // get successfully decrypted by the runner.
9015 expectedLocalError: "local error: bad record MAC",
9016 })
David Benjamin0c40a962016-08-01 12:05:50 -04009017
9018 // Test a known but unoffered extension from the server.
9019 testCases = append(testCases, testCase{
9020 testType: clientTest,
9021 name: "UnofferedExtension-Client",
9022 config: Config{
9023 MaxVersion: VersionTLS12,
9024 Bugs: ProtocolBugs{
9025 SendALPN: "alpn",
9026 },
9027 },
9028 shouldFail: true,
9029 expectedError: ":UNEXPECTED_EXTENSION:",
9030 expectedLocalError: "remote error: unsupported extension",
9031 })
9032 testCases = append(testCases, testCase{
9033 testType: clientTest,
9034 name: "UnofferedExtension-Client-TLS13",
9035 config: Config{
9036 MaxVersion: VersionTLS13,
9037 Bugs: ProtocolBugs{
9038 SendALPN: "alpn",
9039 },
9040 },
9041 shouldFail: true,
9042 expectedError: ":UNEXPECTED_EXTENSION:",
9043 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009044 })
Adam Langley09505632015-07-30 18:10:13 -07009045}
9046
David Benjaminb36a3952015-12-01 18:53:13 -05009047func addRSAClientKeyExchangeTests() {
9048 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9049 testCases = append(testCases, testCase{
9050 testType: serverTest,
9051 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9052 config: Config{
9053 // Ensure the ClientHello version and final
9054 // version are different, to detect if the
9055 // server uses the wrong one.
9056 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009057 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009058 Bugs: ProtocolBugs{
9059 BadRSAClientKeyExchange: bad,
9060 },
9061 },
9062 shouldFail: true,
9063 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9064 })
9065 }
David Benjamine63d9d72016-09-19 18:27:34 -04009066
9067 // The server must compare whatever was in ClientHello.version for the
9068 // RSA premaster.
9069 testCases = append(testCases, testCase{
9070 testType: serverTest,
9071 name: "SendClientVersion-RSA",
9072 config: Config{
9073 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9074 Bugs: ProtocolBugs{
9075 SendClientVersion: 0x1234,
9076 },
9077 },
9078 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9079 })
David Benjaminb36a3952015-12-01 18:53:13 -05009080}
9081
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009082var testCurves = []struct {
9083 name string
9084 id CurveID
9085}{
Adam Langley764ab982017-03-10 18:01:30 -08009086 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009087 {"P-256", CurveP256},
9088 {"P-384", CurveP384},
9089 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009090 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009091}
9092
Steven Valdez5440fe02016-07-18 12:40:30 -04009093const bogusCurve = 0x1234
9094
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009095func addCurveTests() {
9096 for _, curve := range testCurves {
9097 testCases = append(testCases, testCase{
9098 name: "CurveTest-Client-" + curve.name,
9099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009100 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009101 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9102 CurvePreferences: []CurveID{curve.id},
9103 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009104 flags: []string{
9105 "-enable-all-curves",
9106 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9107 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009108 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009109 })
9110 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009111 name: "CurveTest-Client-" + curve.name + "-TLS13",
9112 config: Config{
9113 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009114 CurvePreferences: []CurveID{curve.id},
9115 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009116 flags: []string{
9117 "-enable-all-curves",
9118 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9119 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009120 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009121 })
9122 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009123 testType: serverTest,
9124 name: "CurveTest-Server-" + curve.name,
9125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009126 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009127 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9128 CurvePreferences: []CurveID{curve.id},
9129 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009130 flags: []string{
9131 "-enable-all-curves",
9132 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9133 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009134 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009135 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009136 testCases = append(testCases, testCase{
9137 testType: serverTest,
9138 name: "CurveTest-Server-" + curve.name + "-TLS13",
9139 config: Config{
9140 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009141 CurvePreferences: []CurveID{curve.id},
9142 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009143 flags: []string{
9144 "-enable-all-curves",
9145 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9146 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009147 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009148 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009149 }
David Benjamin241ae832016-01-15 03:04:54 -05009150
9151 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009152 testCases = append(testCases, testCase{
9153 testType: serverTest,
9154 name: "UnknownCurve",
9155 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009156 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9158 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9159 },
9160 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009161
Steven Valdez803c77a2016-09-06 14:13:43 -04009162 // The server must be tolerant to bogus curves.
9163 testCases = append(testCases, testCase{
9164 testType: serverTest,
9165 name: "UnknownCurve-TLS13",
9166 config: Config{
9167 MaxVersion: VersionTLS13,
9168 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9169 },
9170 })
9171
David Benjamin4c3ddf72016-06-29 18:13:53 -04009172 // The server must not consider ECDHE ciphers when there are no
9173 // supported curves.
9174 testCases = append(testCases, testCase{
9175 testType: serverTest,
9176 name: "NoSupportedCurves",
9177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009178 MaxVersion: VersionTLS12,
9179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9180 Bugs: ProtocolBugs{
9181 NoSupportedCurves: true,
9182 },
9183 },
9184 shouldFail: true,
9185 expectedError: ":NO_SHARED_CIPHER:",
9186 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009187 testCases = append(testCases, testCase{
9188 testType: serverTest,
9189 name: "NoSupportedCurves-TLS13",
9190 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009191 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009192 Bugs: ProtocolBugs{
9193 NoSupportedCurves: true,
9194 },
9195 },
9196 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009197 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009198 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009199
9200 // The server must fall back to another cipher when there are no
9201 // supported curves.
9202 testCases = append(testCases, testCase{
9203 testType: serverTest,
9204 name: "NoCommonCurves",
9205 config: Config{
9206 MaxVersion: VersionTLS12,
9207 CipherSuites: []uint16{
9208 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009209 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009210 },
9211 CurvePreferences: []CurveID{CurveP224},
9212 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009213 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009214 })
9215
9216 // The client must reject bogus curves and disabled curves.
9217 testCases = append(testCases, testCase{
9218 name: "BadECDHECurve",
9219 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009220 MaxVersion: VersionTLS12,
9221 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9222 Bugs: ProtocolBugs{
9223 SendCurve: bogusCurve,
9224 },
9225 },
9226 shouldFail: true,
9227 expectedError: ":WRONG_CURVE:",
9228 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009229 testCases = append(testCases, testCase{
9230 name: "BadECDHECurve-TLS13",
9231 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009232 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009233 Bugs: ProtocolBugs{
9234 SendCurve: bogusCurve,
9235 },
9236 },
9237 shouldFail: true,
9238 expectedError: ":WRONG_CURVE:",
9239 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009240
9241 testCases = append(testCases, testCase{
9242 name: "UnsupportedCurve",
9243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009244 MaxVersion: VersionTLS12,
9245 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9246 CurvePreferences: []CurveID{CurveP256},
9247 Bugs: ProtocolBugs{
9248 IgnorePeerCurvePreferences: true,
9249 },
9250 },
9251 flags: []string{"-p384-only"},
9252 shouldFail: true,
9253 expectedError: ":WRONG_CURVE:",
9254 })
9255
David Benjamin4f921572016-07-17 14:20:10 +02009256 testCases = append(testCases, testCase{
9257 // TODO(davidben): Add a TLS 1.3 version where
9258 // HelloRetryRequest requests an unsupported curve.
9259 name: "UnsupportedCurve-ServerHello-TLS13",
9260 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009261 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009262 CurvePreferences: []CurveID{CurveP384},
9263 Bugs: ProtocolBugs{
9264 SendCurve: CurveP256,
9265 },
9266 },
9267 flags: []string{"-p384-only"},
9268 shouldFail: true,
9269 expectedError: ":WRONG_CURVE:",
9270 })
9271
David Benjamin4c3ddf72016-06-29 18:13:53 -04009272 // Test invalid curve points.
9273 testCases = append(testCases, testCase{
9274 name: "InvalidECDHPoint-Client",
9275 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009276 MaxVersion: VersionTLS12,
9277 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9278 CurvePreferences: []CurveID{CurveP256},
9279 Bugs: ProtocolBugs{
9280 InvalidECDHPoint: true,
9281 },
9282 },
9283 shouldFail: true,
9284 expectedError: ":INVALID_ENCODING:",
9285 })
9286 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009287 name: "InvalidECDHPoint-Client-TLS13",
9288 config: Config{
9289 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009290 CurvePreferences: []CurveID{CurveP256},
9291 Bugs: ProtocolBugs{
9292 InvalidECDHPoint: true,
9293 },
9294 },
9295 shouldFail: true,
9296 expectedError: ":INVALID_ENCODING:",
9297 })
9298 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009299 testType: serverTest,
9300 name: "InvalidECDHPoint-Server",
9301 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009302 MaxVersion: VersionTLS12,
9303 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9304 CurvePreferences: []CurveID{CurveP256},
9305 Bugs: ProtocolBugs{
9306 InvalidECDHPoint: true,
9307 },
9308 },
9309 shouldFail: true,
9310 expectedError: ":INVALID_ENCODING:",
9311 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009312 testCases = append(testCases, testCase{
9313 testType: serverTest,
9314 name: "InvalidECDHPoint-Server-TLS13",
9315 config: Config{
9316 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009317 CurvePreferences: []CurveID{CurveP256},
9318 Bugs: ProtocolBugs{
9319 InvalidECDHPoint: true,
9320 },
9321 },
9322 shouldFail: true,
9323 expectedError: ":INVALID_ENCODING:",
9324 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009325
9326 // The previous curve ID should be reported on TLS 1.2 resumption.
9327 testCases = append(testCases, testCase{
9328 name: "CurveID-Resume-Client",
9329 config: Config{
9330 MaxVersion: VersionTLS12,
9331 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9332 CurvePreferences: []CurveID{CurveX25519},
9333 },
9334 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9335 resumeSession: true,
9336 })
9337 testCases = append(testCases, testCase{
9338 testType: serverTest,
9339 name: "CurveID-Resume-Server",
9340 config: Config{
9341 MaxVersion: VersionTLS12,
9342 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9343 CurvePreferences: []CurveID{CurveX25519},
9344 },
9345 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9346 resumeSession: true,
9347 })
9348
9349 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9350 // one should be reported.
9351 testCases = append(testCases, testCase{
9352 name: "CurveID-Resume-Client-TLS13",
9353 config: Config{
9354 MaxVersion: VersionTLS13,
9355 CurvePreferences: []CurveID{CurveX25519},
9356 },
9357 resumeConfig: &Config{
9358 MaxVersion: VersionTLS13,
9359 CurvePreferences: []CurveID{CurveP256},
9360 },
9361 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009362 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9363 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009364 },
9365 resumeSession: true,
9366 })
9367 testCases = append(testCases, testCase{
9368 testType: serverTest,
9369 name: "CurveID-Resume-Server-TLS13",
9370 config: Config{
9371 MaxVersion: VersionTLS13,
9372 CurvePreferences: []CurveID{CurveX25519},
9373 },
9374 resumeConfig: &Config{
9375 MaxVersion: VersionTLS13,
9376 CurvePreferences: []CurveID{CurveP256},
9377 },
9378 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009379 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9380 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009381 },
9382 resumeSession: true,
9383 })
David Benjamina81967b2016-12-22 09:16:57 -05009384
9385 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9386 testCases = append(testCases, testCase{
9387 name: "PointFormat-ServerHello-TLS12",
9388 config: Config{
9389 MaxVersion: VersionTLS12,
9390 Bugs: ProtocolBugs{
9391 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9392 },
9393 },
9394 })
9395 testCases = append(testCases, testCase{
9396 name: "PointFormat-EncryptedExtensions-TLS13",
9397 config: Config{
9398 MaxVersion: VersionTLS13,
9399 Bugs: ProtocolBugs{
9400 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9401 },
9402 },
9403 shouldFail: true,
9404 expectedError: ":ERROR_PARSING_EXTENSION:",
9405 })
9406
9407 // Test that we tolerate unknown point formats, as long as
9408 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9409 // check they are still functional.
9410 testCases = append(testCases, testCase{
9411 name: "PointFormat-Client-Tolerance",
9412 config: Config{
9413 MaxVersion: VersionTLS12,
9414 Bugs: ProtocolBugs{
9415 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9416 },
9417 },
9418 })
9419 testCases = append(testCases, testCase{
9420 testType: serverTest,
9421 name: "PointFormat-Server-Tolerance",
9422 config: Config{
9423 MaxVersion: VersionTLS12,
9424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9425 Bugs: ProtocolBugs{
9426 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9427 },
9428 },
9429 })
9430
9431 // Test TLS 1.2 does not require the point format extension to be
9432 // present.
9433 testCases = append(testCases, testCase{
9434 name: "PointFormat-Client-Missing",
9435 config: Config{
9436 MaxVersion: VersionTLS12,
9437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9438 Bugs: ProtocolBugs{
9439 SendSupportedPointFormats: []byte{},
9440 },
9441 },
9442 })
9443 testCases = append(testCases, testCase{
9444 testType: serverTest,
9445 name: "PointFormat-Server-Missing",
9446 config: Config{
9447 MaxVersion: VersionTLS12,
9448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9449 Bugs: ProtocolBugs{
9450 SendSupportedPointFormats: []byte{},
9451 },
9452 },
9453 })
9454
9455 // If the point format extension is present, uncompressed points must be
9456 // offered. BoringSSL requires this whether or not ECDHE is used.
9457 testCases = append(testCases, testCase{
9458 name: "PointFormat-Client-MissingUncompressed",
9459 config: Config{
9460 MaxVersion: VersionTLS12,
9461 Bugs: ProtocolBugs{
9462 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9463 },
9464 },
9465 shouldFail: true,
9466 expectedError: ":ERROR_PARSING_EXTENSION:",
9467 })
9468 testCases = append(testCases, testCase{
9469 testType: serverTest,
9470 name: "PointFormat-Server-MissingUncompressed",
9471 config: Config{
9472 MaxVersion: VersionTLS12,
9473 Bugs: ProtocolBugs{
9474 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9475 },
9476 },
9477 shouldFail: true,
9478 expectedError: ":ERROR_PARSING_EXTENSION:",
9479 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009480}
9481
David Benjaminc9ae27c2016-06-24 22:56:37 -04009482func addTLS13RecordTests() {
9483 testCases = append(testCases, testCase{
9484 name: "TLS13-RecordPadding",
9485 config: Config{
9486 MaxVersion: VersionTLS13,
9487 MinVersion: VersionTLS13,
9488 Bugs: ProtocolBugs{
9489 RecordPadding: 10,
9490 },
9491 },
9492 })
9493
9494 testCases = append(testCases, testCase{
9495 name: "TLS13-EmptyRecords",
9496 config: Config{
9497 MaxVersion: VersionTLS13,
9498 MinVersion: VersionTLS13,
9499 Bugs: ProtocolBugs{
9500 OmitRecordContents: true,
9501 },
9502 },
9503 shouldFail: true,
9504 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9505 })
9506
9507 testCases = append(testCases, testCase{
9508 name: "TLS13-OnlyPadding",
9509 config: Config{
9510 MaxVersion: VersionTLS13,
9511 MinVersion: VersionTLS13,
9512 Bugs: ProtocolBugs{
9513 OmitRecordContents: true,
9514 RecordPadding: 10,
9515 },
9516 },
9517 shouldFail: true,
9518 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9519 })
9520
9521 testCases = append(testCases, testCase{
9522 name: "TLS13-WrongOuterRecord",
9523 config: Config{
9524 MaxVersion: VersionTLS13,
9525 MinVersion: VersionTLS13,
9526 Bugs: ProtocolBugs{
9527 OuterRecordType: recordTypeHandshake,
9528 },
9529 },
9530 shouldFail: true,
9531 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9532 })
9533}
9534
Steven Valdez5b986082016-09-01 12:29:49 -04009535func addSessionTicketTests() {
9536 testCases = append(testCases, testCase{
9537 // In TLS 1.2 and below, empty NewSessionTicket messages
9538 // mean the server changed its mind on sending a ticket.
9539 name: "SendEmptySessionTicket",
9540 config: Config{
9541 MaxVersion: VersionTLS12,
9542 Bugs: ProtocolBugs{
9543 SendEmptySessionTicket: true,
9544 },
9545 },
9546 flags: []string{"-expect-no-session"},
9547 })
9548
9549 // Test that the server ignores unknown PSK modes.
9550 testCases = append(testCases, testCase{
9551 testType: serverTest,
9552 name: "TLS13-SendUnknownModeSessionTicket-Server",
9553 config: Config{
9554 MaxVersion: VersionTLS13,
9555 Bugs: ProtocolBugs{
9556 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009557 },
9558 },
9559 resumeSession: true,
9560 expectedResumeVersion: VersionTLS13,
9561 })
9562
Steven Valdeza833c352016-11-01 13:39:36 -04009563 // Test that the server does not send session tickets with no matching key exchange mode.
9564 testCases = append(testCases, testCase{
9565 testType: serverTest,
9566 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9567 config: Config{
9568 MaxVersion: VersionTLS13,
9569 Bugs: ProtocolBugs{
9570 SendPSKKeyExchangeModes: []byte{0x1a},
9571 ExpectNoNewSessionTicket: true,
9572 },
9573 },
9574 })
9575
9576 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009577 testCases = append(testCases, testCase{
9578 testType: serverTest,
9579 name: "TLS13-SendBadKEModeSessionTicket-Server",
9580 config: Config{
9581 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009582 },
9583 resumeConfig: &Config{
9584 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009585 Bugs: ProtocolBugs{
9586 SendPSKKeyExchangeModes: []byte{0x1a},
9587 },
9588 },
9589 resumeSession: true,
9590 expectResumeRejected: true,
9591 })
9592
Steven Valdeza833c352016-11-01 13:39:36 -04009593 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009594 testCases = append(testCases, testCase{
9595 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009596 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009597 config: Config{
9598 MaxVersion: VersionTLS13,
9599 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009600 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009601 },
9602 },
Steven Valdeza833c352016-11-01 13:39:36 -04009603 resumeSession: true,
9604 flags: []string{
9605 "-resumption-delay", "10",
9606 },
Steven Valdez5b986082016-09-01 12:29:49 -04009607 })
9608
Steven Valdeza833c352016-11-01 13:39:36 -04009609 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009610 testCases = append(testCases, testCase{
9611 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009612 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009613 config: Config{
9614 MaxVersion: VersionTLS13,
9615 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009616 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009617 },
9618 },
Steven Valdeza833c352016-11-01 13:39:36 -04009619 resumeSession: true,
9620 shouldFail: true,
9621 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009622 })
9623
David Benjamin35ac5b72017-03-03 15:05:56 -05009624 // Test that the server's ticket age skew reporting works.
9625 testCases = append(testCases, testCase{
9626 testType: serverTest,
9627 name: "TLS13-TicketAgeSkew-Forward",
9628 config: Config{
9629 MaxVersion: VersionTLS13,
9630 Bugs: ProtocolBugs{
9631 SendTicketAge: 15 * time.Second,
9632 },
9633 },
David Benjamin065d7332017-03-26 10:51:43 -05009634 resumeSession: true,
9635 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009636 flags: []string{
9637 "-resumption-delay", "10",
9638 "-expect-ticket-age-skew", "5",
9639 },
9640 })
9641 testCases = append(testCases, testCase{
9642 testType: serverTest,
9643 name: "TLS13-TicketAgeSkew-Backward",
9644 config: Config{
9645 MaxVersion: VersionTLS13,
9646 Bugs: ProtocolBugs{
9647 SendTicketAge: 5 * time.Second,
9648 },
9649 },
David Benjamin065d7332017-03-26 10:51:43 -05009650 resumeSession: true,
9651 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009652 flags: []string{
9653 "-resumption-delay", "10",
9654 "-expect-ticket-age-skew", "-5",
9655 },
9656 })
9657
Steven Valdez08b65f42016-12-07 15:29:45 -05009658 testCases = append(testCases, testCase{
9659 testType: clientTest,
9660 name: "TLS13-SendTicketEarlyDataInfo",
9661 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009662 MaxVersion: VersionTLS13,
9663 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009664 },
9665 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009666 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009667 "-expect-early-data-info",
9668 },
9669 })
9670
David Benjamin9b160662017-01-25 19:53:43 -05009671 // Test that 0-RTT tickets are ignored in clients unless opted in.
9672 testCases = append(testCases, testCase{
9673 testType: clientTest,
9674 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9675 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009676 MaxVersion: VersionTLS13,
9677 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009678 },
9679 })
9680
Steven Valdez08b65f42016-12-07 15:29:45 -05009681 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009682 testType: clientTest,
9683 name: "TLS13-DuplicateTicketEarlyDataInfo",
9684 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009685 MaxVersion: VersionTLS13,
9686 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009687 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009688 DuplicateTicketEarlyDataInfo: true,
9689 },
9690 },
9691 shouldFail: true,
9692 expectedError: ":DUPLICATE_EXTENSION:",
9693 expectedLocalError: "remote error: illegal parameter",
9694 })
9695
9696 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009697 testType: serverTest,
9698 name: "TLS13-ExpectTicketEarlyDataInfo",
9699 config: Config{
9700 MaxVersion: VersionTLS13,
9701 Bugs: ProtocolBugs{
9702 ExpectTicketEarlyDataInfo: true,
9703 },
9704 },
9705 flags: []string{
9706 "-enable-early-data",
9707 },
9708 })
David Benjamin17b30832017-01-28 14:00:32 -05009709
9710 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9711 // is honored.
9712 testCases = append(testCases, testCase{
9713 testType: clientTest,
9714 name: "TLS13-HonorServerSessionTicketLifetime",
9715 config: Config{
9716 MaxVersion: VersionTLS13,
9717 Bugs: ProtocolBugs{
9718 SendTicketLifetime: 20 * time.Second,
9719 },
9720 },
9721 flags: []string{
9722 "-resumption-delay", "19",
9723 },
9724 resumeSession: true,
9725 })
9726 testCases = append(testCases, testCase{
9727 testType: clientTest,
9728 name: "TLS13-HonorServerSessionTicketLifetime-2",
9729 config: Config{
9730 MaxVersion: VersionTLS13,
9731 Bugs: ProtocolBugs{
9732 SendTicketLifetime: 20 * time.Second,
9733 // The client should not offer the expired session.
9734 ExpectNoTLS13PSK: true,
9735 },
9736 },
9737 flags: []string{
9738 "-resumption-delay", "21",
9739 },
David Benjamin023d4192017-02-06 13:49:07 -05009740 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009741 expectResumeRejected: true,
9742 })
Steven Valdez5b986082016-09-01 12:29:49 -04009743}
9744
David Benjamin82261be2016-07-07 14:32:50 -07009745func addChangeCipherSpecTests() {
9746 // Test missing ChangeCipherSpecs.
9747 testCases = append(testCases, testCase{
9748 name: "SkipChangeCipherSpec-Client",
9749 config: Config{
9750 MaxVersion: VersionTLS12,
9751 Bugs: ProtocolBugs{
9752 SkipChangeCipherSpec: true,
9753 },
9754 },
9755 shouldFail: true,
9756 expectedError: ":UNEXPECTED_RECORD:",
9757 })
9758 testCases = append(testCases, testCase{
9759 testType: serverTest,
9760 name: "SkipChangeCipherSpec-Server",
9761 config: Config{
9762 MaxVersion: VersionTLS12,
9763 Bugs: ProtocolBugs{
9764 SkipChangeCipherSpec: true,
9765 },
9766 },
9767 shouldFail: true,
9768 expectedError: ":UNEXPECTED_RECORD:",
9769 })
9770 testCases = append(testCases, testCase{
9771 testType: serverTest,
9772 name: "SkipChangeCipherSpec-Server-NPN",
9773 config: Config{
9774 MaxVersion: VersionTLS12,
9775 NextProtos: []string{"bar"},
9776 Bugs: ProtocolBugs{
9777 SkipChangeCipherSpec: true,
9778 },
9779 },
9780 flags: []string{
9781 "-advertise-npn", "\x03foo\x03bar\x03baz",
9782 },
9783 shouldFail: true,
9784 expectedError: ":UNEXPECTED_RECORD:",
9785 })
9786
9787 // Test synchronization between the handshake and ChangeCipherSpec.
9788 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9789 // rejected. Test both with and without handshake packing to handle both
9790 // when the partial post-CCS message is in its own record and when it is
9791 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009792 for _, packed := range []bool{false, true} {
9793 var suffix string
9794 if packed {
9795 suffix = "-Packed"
9796 }
9797
9798 testCases = append(testCases, testCase{
9799 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9800 config: Config{
9801 MaxVersion: VersionTLS12,
9802 Bugs: ProtocolBugs{
9803 FragmentAcrossChangeCipherSpec: true,
9804 PackHandshakeFlight: packed,
9805 },
9806 },
9807 shouldFail: true,
9808 expectedError: ":UNEXPECTED_RECORD:",
9809 })
9810 testCases = append(testCases, testCase{
9811 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9812 config: Config{
9813 MaxVersion: VersionTLS12,
9814 },
9815 resumeSession: true,
9816 resumeConfig: &Config{
9817 MaxVersion: VersionTLS12,
9818 Bugs: ProtocolBugs{
9819 FragmentAcrossChangeCipherSpec: true,
9820 PackHandshakeFlight: packed,
9821 },
9822 },
9823 shouldFail: true,
9824 expectedError: ":UNEXPECTED_RECORD:",
9825 })
9826 testCases = append(testCases, testCase{
9827 testType: serverTest,
9828 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9829 config: Config{
9830 MaxVersion: VersionTLS12,
9831 Bugs: ProtocolBugs{
9832 FragmentAcrossChangeCipherSpec: true,
9833 PackHandshakeFlight: packed,
9834 },
9835 },
9836 shouldFail: true,
9837 expectedError: ":UNEXPECTED_RECORD:",
9838 })
9839 testCases = append(testCases, testCase{
9840 testType: serverTest,
9841 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9842 config: Config{
9843 MaxVersion: VersionTLS12,
9844 },
9845 resumeSession: true,
9846 resumeConfig: &Config{
9847 MaxVersion: VersionTLS12,
9848 Bugs: ProtocolBugs{
9849 FragmentAcrossChangeCipherSpec: true,
9850 PackHandshakeFlight: packed,
9851 },
9852 },
9853 shouldFail: true,
9854 expectedError: ":UNEXPECTED_RECORD:",
9855 })
9856 testCases = append(testCases, testCase{
9857 testType: serverTest,
9858 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9859 config: Config{
9860 MaxVersion: VersionTLS12,
9861 NextProtos: []string{"bar"},
9862 Bugs: ProtocolBugs{
9863 FragmentAcrossChangeCipherSpec: true,
9864 PackHandshakeFlight: packed,
9865 },
9866 },
9867 flags: []string{
9868 "-advertise-npn", "\x03foo\x03bar\x03baz",
9869 },
9870 shouldFail: true,
9871 expectedError: ":UNEXPECTED_RECORD:",
9872 })
9873 }
9874
David Benjamin61672812016-07-14 23:10:43 -04009875 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9876 // messages in the handshake queue. Do this by testing the server
9877 // reading the client Finished, reversing the flight so Finished comes
9878 // first.
9879 testCases = append(testCases, testCase{
9880 protocol: dtls,
9881 testType: serverTest,
9882 name: "SendUnencryptedFinished-DTLS",
9883 config: Config{
9884 MaxVersion: VersionTLS12,
9885 Bugs: ProtocolBugs{
9886 SendUnencryptedFinished: true,
9887 ReverseHandshakeFragments: true,
9888 },
9889 },
9890 shouldFail: true,
9891 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9892 })
9893
Steven Valdez143e8b32016-07-11 13:19:03 -04009894 // Test synchronization between encryption changes and the handshake in
9895 // TLS 1.3, where ChangeCipherSpec is implicit.
9896 testCases = append(testCases, testCase{
9897 name: "PartialEncryptedExtensionsWithServerHello",
9898 config: Config{
9899 MaxVersion: VersionTLS13,
9900 Bugs: ProtocolBugs{
9901 PartialEncryptedExtensionsWithServerHello: true,
9902 },
9903 },
9904 shouldFail: true,
9905 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9906 })
9907 testCases = append(testCases, testCase{
9908 testType: serverTest,
9909 name: "PartialClientFinishedWithClientHello",
9910 config: Config{
9911 MaxVersion: VersionTLS13,
9912 Bugs: ProtocolBugs{
9913 PartialClientFinishedWithClientHello: true,
9914 },
9915 },
9916 shouldFail: true,
9917 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9918 })
9919
David Benjamin82261be2016-07-07 14:32:50 -07009920 // Test that early ChangeCipherSpecs are handled correctly.
9921 testCases = append(testCases, testCase{
9922 testType: serverTest,
9923 name: "EarlyChangeCipherSpec-server-1",
9924 config: Config{
9925 MaxVersion: VersionTLS12,
9926 Bugs: ProtocolBugs{
9927 EarlyChangeCipherSpec: 1,
9928 },
9929 },
9930 shouldFail: true,
9931 expectedError: ":UNEXPECTED_RECORD:",
9932 })
9933 testCases = append(testCases, testCase{
9934 testType: serverTest,
9935 name: "EarlyChangeCipherSpec-server-2",
9936 config: Config{
9937 MaxVersion: VersionTLS12,
9938 Bugs: ProtocolBugs{
9939 EarlyChangeCipherSpec: 2,
9940 },
9941 },
9942 shouldFail: true,
9943 expectedError: ":UNEXPECTED_RECORD:",
9944 })
9945 testCases = append(testCases, testCase{
9946 protocol: dtls,
9947 name: "StrayChangeCipherSpec",
9948 config: Config{
9949 // TODO(davidben): Once DTLS 1.3 exists, test
9950 // that stray ChangeCipherSpec messages are
9951 // rejected.
9952 MaxVersion: VersionTLS12,
9953 Bugs: ProtocolBugs{
9954 StrayChangeCipherSpec: true,
9955 },
9956 },
9957 })
9958
9959 // Test that the contents of ChangeCipherSpec are checked.
9960 testCases = append(testCases, testCase{
9961 name: "BadChangeCipherSpec-1",
9962 config: Config{
9963 MaxVersion: VersionTLS12,
9964 Bugs: ProtocolBugs{
9965 BadChangeCipherSpec: []byte{2},
9966 },
9967 },
9968 shouldFail: true,
9969 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9970 })
9971 testCases = append(testCases, testCase{
9972 name: "BadChangeCipherSpec-2",
9973 config: Config{
9974 MaxVersion: VersionTLS12,
9975 Bugs: ProtocolBugs{
9976 BadChangeCipherSpec: []byte{1, 1},
9977 },
9978 },
9979 shouldFail: true,
9980 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9981 })
9982 testCases = append(testCases, testCase{
9983 protocol: dtls,
9984 name: "BadChangeCipherSpec-DTLS-1",
9985 config: Config{
9986 MaxVersion: VersionTLS12,
9987 Bugs: ProtocolBugs{
9988 BadChangeCipherSpec: []byte{2},
9989 },
9990 },
9991 shouldFail: true,
9992 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9993 })
9994 testCases = append(testCases, testCase{
9995 protocol: dtls,
9996 name: "BadChangeCipherSpec-DTLS-2",
9997 config: Config{
9998 MaxVersion: VersionTLS12,
9999 Bugs: ProtocolBugs{
10000 BadChangeCipherSpec: []byte{1, 1},
10001 },
10002 },
10003 shouldFail: true,
10004 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10005 })
10006}
10007
David Benjamincd2c8062016-09-09 11:28:16 -040010008type perMessageTest struct {
10009 messageType uint8
10010 test testCase
10011}
10012
10013// makePerMessageTests returns a series of test templates which cover each
10014// message in the TLS handshake. These may be used with bugs like
10015// WrongMessageType to fully test a per-message bug.
10016func makePerMessageTests() []perMessageTest {
10017 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010018 for _, protocol := range []protocol{tls, dtls} {
10019 var suffix string
10020 if protocol == dtls {
10021 suffix = "-DTLS"
10022 }
10023
David Benjamincd2c8062016-09-09 11:28:16 -040010024 ret = append(ret, perMessageTest{
10025 messageType: typeClientHello,
10026 test: testCase{
10027 protocol: protocol,
10028 testType: serverTest,
10029 name: "ClientHello" + suffix,
10030 config: Config{
10031 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010032 },
10033 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010034 })
10035
10036 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010037 ret = append(ret, perMessageTest{
10038 messageType: typeHelloVerifyRequest,
10039 test: testCase{
10040 protocol: protocol,
10041 name: "HelloVerifyRequest" + suffix,
10042 config: Config{
10043 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010044 },
10045 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010046 })
10047 }
10048
David Benjamincd2c8062016-09-09 11:28:16 -040010049 ret = append(ret, perMessageTest{
10050 messageType: typeServerHello,
10051 test: testCase{
10052 protocol: protocol,
10053 name: "ServerHello" + suffix,
10054 config: Config{
10055 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010056 },
10057 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010058 })
10059
David Benjamincd2c8062016-09-09 11:28:16 -040010060 ret = append(ret, perMessageTest{
10061 messageType: typeCertificate,
10062 test: testCase{
10063 protocol: protocol,
10064 name: "ServerCertificate" + suffix,
10065 config: Config{
10066 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010067 },
10068 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010069 })
10070
David Benjamincd2c8062016-09-09 11:28:16 -040010071 ret = append(ret, perMessageTest{
10072 messageType: typeCertificateStatus,
10073 test: testCase{
10074 protocol: protocol,
10075 name: "CertificateStatus" + suffix,
10076 config: Config{
10077 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010078 },
David Benjamincd2c8062016-09-09 11:28:16 -040010079 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010080 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010081 })
10082
David Benjamincd2c8062016-09-09 11:28:16 -040010083 ret = append(ret, perMessageTest{
10084 messageType: typeServerKeyExchange,
10085 test: testCase{
10086 protocol: protocol,
10087 name: "ServerKeyExchange" + suffix,
10088 config: Config{
10089 MaxVersion: VersionTLS12,
10090 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010091 },
10092 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010093 })
10094
David Benjamincd2c8062016-09-09 11:28:16 -040010095 ret = append(ret, perMessageTest{
10096 messageType: typeCertificateRequest,
10097 test: testCase{
10098 protocol: protocol,
10099 name: "CertificateRequest" + suffix,
10100 config: Config{
10101 MaxVersion: VersionTLS12,
10102 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010103 },
10104 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010105 })
10106
David Benjamincd2c8062016-09-09 11:28:16 -040010107 ret = append(ret, perMessageTest{
10108 messageType: typeServerHelloDone,
10109 test: testCase{
10110 protocol: protocol,
10111 name: "ServerHelloDone" + suffix,
10112 config: Config{
10113 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010114 },
10115 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010116 })
10117
David Benjamincd2c8062016-09-09 11:28:16 -040010118 ret = append(ret, perMessageTest{
10119 messageType: typeCertificate,
10120 test: testCase{
10121 testType: serverTest,
10122 protocol: protocol,
10123 name: "ClientCertificate" + suffix,
10124 config: Config{
10125 Certificates: []Certificate{rsaCertificate},
10126 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010127 },
David Benjamincd2c8062016-09-09 11:28:16 -040010128 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010129 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010130 })
10131
David Benjamincd2c8062016-09-09 11:28:16 -040010132 ret = append(ret, perMessageTest{
10133 messageType: typeCertificateVerify,
10134 test: testCase{
10135 testType: serverTest,
10136 protocol: protocol,
10137 name: "CertificateVerify" + suffix,
10138 config: Config{
10139 Certificates: []Certificate{rsaCertificate},
10140 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010141 },
David Benjamincd2c8062016-09-09 11:28:16 -040010142 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010143 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010144 })
10145
David Benjamincd2c8062016-09-09 11:28:16 -040010146 ret = append(ret, perMessageTest{
10147 messageType: typeClientKeyExchange,
10148 test: testCase{
10149 testType: serverTest,
10150 protocol: protocol,
10151 name: "ClientKeyExchange" + suffix,
10152 config: Config{
10153 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010154 },
10155 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010156 })
10157
10158 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010159 ret = append(ret, perMessageTest{
10160 messageType: typeNextProtocol,
10161 test: testCase{
10162 testType: serverTest,
10163 protocol: protocol,
10164 name: "NextProtocol" + suffix,
10165 config: Config{
10166 MaxVersion: VersionTLS12,
10167 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010168 },
David Benjamincd2c8062016-09-09 11:28:16 -040010169 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010170 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010171 })
10172
David Benjamincd2c8062016-09-09 11:28:16 -040010173 ret = append(ret, perMessageTest{
10174 messageType: typeChannelID,
10175 test: testCase{
10176 testType: serverTest,
10177 protocol: protocol,
10178 name: "ChannelID" + suffix,
10179 config: Config{
10180 MaxVersion: VersionTLS12,
10181 ChannelID: channelIDKey,
10182 },
10183 flags: []string{
10184 "-expect-channel-id",
10185 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010186 },
10187 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010188 })
10189 }
10190
David Benjamincd2c8062016-09-09 11:28:16 -040010191 ret = append(ret, perMessageTest{
10192 messageType: typeFinished,
10193 test: testCase{
10194 testType: serverTest,
10195 protocol: protocol,
10196 name: "ClientFinished" + suffix,
10197 config: Config{
10198 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010199 },
10200 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010201 })
10202
David Benjamincd2c8062016-09-09 11:28:16 -040010203 ret = append(ret, perMessageTest{
10204 messageType: typeNewSessionTicket,
10205 test: testCase{
10206 protocol: protocol,
10207 name: "NewSessionTicket" + suffix,
10208 config: Config{
10209 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010210 },
10211 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010212 })
10213
David Benjamincd2c8062016-09-09 11:28:16 -040010214 ret = append(ret, perMessageTest{
10215 messageType: typeFinished,
10216 test: testCase{
10217 protocol: protocol,
10218 name: "ServerFinished" + suffix,
10219 config: Config{
10220 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010221 },
10222 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010223 })
10224
10225 }
David Benjamincd2c8062016-09-09 11:28:16 -040010226
10227 ret = append(ret, perMessageTest{
10228 messageType: typeClientHello,
10229 test: testCase{
10230 testType: serverTest,
10231 name: "TLS13-ClientHello",
10232 config: Config{
10233 MaxVersion: VersionTLS13,
10234 },
10235 },
10236 })
10237
10238 ret = append(ret, perMessageTest{
10239 messageType: typeServerHello,
10240 test: testCase{
10241 name: "TLS13-ServerHello",
10242 config: Config{
10243 MaxVersion: VersionTLS13,
10244 },
10245 },
10246 })
10247
10248 ret = append(ret, perMessageTest{
10249 messageType: typeEncryptedExtensions,
10250 test: testCase{
10251 name: "TLS13-EncryptedExtensions",
10252 config: Config{
10253 MaxVersion: VersionTLS13,
10254 },
10255 },
10256 })
10257
10258 ret = append(ret, perMessageTest{
10259 messageType: typeCertificateRequest,
10260 test: testCase{
10261 name: "TLS13-CertificateRequest",
10262 config: Config{
10263 MaxVersion: VersionTLS13,
10264 ClientAuth: RequireAnyClientCert,
10265 },
10266 },
10267 })
10268
10269 ret = append(ret, perMessageTest{
10270 messageType: typeCertificate,
10271 test: testCase{
10272 name: "TLS13-ServerCertificate",
10273 config: Config{
10274 MaxVersion: VersionTLS13,
10275 },
10276 },
10277 })
10278
10279 ret = append(ret, perMessageTest{
10280 messageType: typeCertificateVerify,
10281 test: testCase{
10282 name: "TLS13-ServerCertificateVerify",
10283 config: Config{
10284 MaxVersion: VersionTLS13,
10285 },
10286 },
10287 })
10288
10289 ret = append(ret, perMessageTest{
10290 messageType: typeFinished,
10291 test: testCase{
10292 name: "TLS13-ServerFinished",
10293 config: Config{
10294 MaxVersion: VersionTLS13,
10295 },
10296 },
10297 })
10298
10299 ret = append(ret, perMessageTest{
10300 messageType: typeCertificate,
10301 test: testCase{
10302 testType: serverTest,
10303 name: "TLS13-ClientCertificate",
10304 config: Config{
10305 Certificates: []Certificate{rsaCertificate},
10306 MaxVersion: VersionTLS13,
10307 },
10308 flags: []string{"-require-any-client-certificate"},
10309 },
10310 })
10311
10312 ret = append(ret, perMessageTest{
10313 messageType: typeCertificateVerify,
10314 test: testCase{
10315 testType: serverTest,
10316 name: "TLS13-ClientCertificateVerify",
10317 config: Config{
10318 Certificates: []Certificate{rsaCertificate},
10319 MaxVersion: VersionTLS13,
10320 },
10321 flags: []string{"-require-any-client-certificate"},
10322 },
10323 })
10324
10325 ret = append(ret, perMessageTest{
10326 messageType: typeFinished,
10327 test: testCase{
10328 testType: serverTest,
10329 name: "TLS13-ClientFinished",
10330 config: Config{
10331 MaxVersion: VersionTLS13,
10332 },
10333 },
10334 })
10335
10336 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010337}
10338
David Benjamincd2c8062016-09-09 11:28:16 -040010339func addWrongMessageTypeTests() {
10340 for _, t := range makePerMessageTests() {
10341 t.test.name = "WrongMessageType-" + t.test.name
10342 t.test.config.Bugs.SendWrongMessageType = t.messageType
10343 t.test.shouldFail = true
10344 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10345 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010346
David Benjamincd2c8062016-09-09 11:28:16 -040010347 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10348 // In TLS 1.3, a bad ServerHello means the client sends
10349 // an unencrypted alert while the server expects
10350 // encryption, so the alert is not readable by runner.
10351 t.test.expectedLocalError = "local error: bad record MAC"
10352 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010353
David Benjamincd2c8062016-09-09 11:28:16 -040010354 testCases = append(testCases, t.test)
10355 }
David Benjaminebacdee2017-04-08 11:00:45 -040010356
10357 // The processing order for TLS 1.3 version negotiation is such that one
10358 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10359 // TLS 1.2. Test that we do not do this.
10360 testCases = append(testCases, testCase{
10361 name: "SendServerHelloAsHelloRetryRequest",
10362 config: Config{
10363 MaxVersion: VersionTLS12,
10364 Bugs: ProtocolBugs{
10365 SendServerHelloAsHelloRetryRequest: true,
10366 },
10367 },
10368 shouldFail: true,
10369 expectedError: ":UNEXPECTED_MESSAGE:",
10370 expectedLocalError: "remote error: unexpected message",
10371 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010372}
10373
David Benjamin639846e2016-09-09 11:41:18 -040010374func addTrailingMessageDataTests() {
10375 for _, t := range makePerMessageTests() {
10376 t.test.name = "TrailingMessageData-" + t.test.name
10377 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10378 t.test.shouldFail = true
10379 t.test.expectedError = ":DECODE_ERROR:"
10380 t.test.expectedLocalError = "remote error: error decoding message"
10381
10382 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10383 // In TLS 1.3, a bad ServerHello means the client sends
10384 // an unencrypted alert while the server expects
10385 // encryption, so the alert is not readable by runner.
10386 t.test.expectedLocalError = "local error: bad record MAC"
10387 }
10388
10389 if t.messageType == typeFinished {
10390 // Bad Finished messages read as the verify data having
10391 // the wrong length.
10392 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10393 t.test.expectedLocalError = "remote error: error decrypting message"
10394 }
10395
10396 testCases = append(testCases, t.test)
10397 }
10398}
10399
Steven Valdez143e8b32016-07-11 13:19:03 -040010400func addTLS13HandshakeTests() {
10401 testCases = append(testCases, testCase{
10402 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010403 name: "NegotiatePSKResumption-TLS13",
10404 config: Config{
10405 MaxVersion: VersionTLS13,
10406 Bugs: ProtocolBugs{
10407 NegotiatePSKResumption: true,
10408 },
10409 },
10410 resumeSession: true,
10411 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010412 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010413 })
10414
10415 testCases = append(testCases, testCase{
10416 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010417 name: "MissingKeyShare-Client",
10418 config: Config{
10419 MaxVersion: VersionTLS13,
10420 Bugs: ProtocolBugs{
10421 MissingKeyShare: true,
10422 },
10423 },
10424 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010425 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010426 })
10427
10428 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010429 testType: serverTest,
10430 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010431 config: Config{
10432 MaxVersion: VersionTLS13,
10433 Bugs: ProtocolBugs{
10434 MissingKeyShare: true,
10435 },
10436 },
10437 shouldFail: true,
10438 expectedError: ":MISSING_KEY_SHARE:",
10439 })
10440
10441 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010442 testType: serverTest,
10443 name: "DuplicateKeyShares",
10444 config: Config{
10445 MaxVersion: VersionTLS13,
10446 Bugs: ProtocolBugs{
10447 DuplicateKeyShares: true,
10448 },
10449 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010450 shouldFail: true,
10451 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010452 })
10453
10454 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010455 testType: serverTest,
10456 name: "SkipEarlyData",
10457 config: Config{
10458 MaxVersion: VersionTLS13,
10459 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010460 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010461 },
10462 },
10463 })
10464
10465 testCases = append(testCases, testCase{
10466 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010467 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010468 config: Config{
10469 MaxVersion: VersionTLS13,
10470 TLS13Variant: TLS13Experiment,
10471 Bugs: ProtocolBugs{
10472 SendFakeEarlyDataLength: 4,
10473 },
10474 },
10475 flags: []string{"-tls13-variant", "1"},
10476 })
10477
10478 testCases = append(testCases, testCase{
10479 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010480 name: "SkipEarlyData-OmitEarlyDataExtension",
10481 config: Config{
10482 MaxVersion: VersionTLS13,
10483 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010484 SendFakeEarlyDataLength: 4,
10485 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010486 },
10487 },
10488 shouldFail: true,
10489 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10490 })
10491
10492 testCases = append(testCases, testCase{
10493 testType: serverTest,
10494 name: "SkipEarlyData-TooMuchData",
10495 config: Config{
10496 MaxVersion: VersionTLS13,
10497 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010498 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010499 },
10500 },
10501 shouldFail: true,
10502 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10503 })
10504
10505 testCases = append(testCases, testCase{
10506 testType: serverTest,
10507 name: "SkipEarlyData-Interleaved",
10508 config: Config{
10509 MaxVersion: VersionTLS13,
10510 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010511 SendFakeEarlyDataLength: 4,
10512 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010513 },
10514 },
10515 shouldFail: true,
10516 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10517 })
10518
10519 testCases = append(testCases, testCase{
10520 testType: serverTest,
10521 name: "SkipEarlyData-EarlyDataInTLS12",
10522 config: Config{
10523 MaxVersion: VersionTLS13,
10524 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010525 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010526 },
10527 },
10528 shouldFail: true,
10529 expectedError: ":UNEXPECTED_RECORD:",
10530 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10531 })
10532
10533 testCases = append(testCases, testCase{
10534 testType: serverTest,
10535 name: "SkipEarlyData-HRR",
10536 config: Config{
10537 MaxVersion: VersionTLS13,
10538 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010539 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010540 },
10541 DefaultCurves: []CurveID{},
10542 },
10543 })
10544
10545 testCases = append(testCases, testCase{
10546 testType: serverTest,
10547 name: "SkipEarlyData-HRR-Interleaved",
10548 config: Config{
10549 MaxVersion: VersionTLS13,
10550 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010551 SendFakeEarlyDataLength: 4,
10552 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010553 },
10554 DefaultCurves: []CurveID{},
10555 },
10556 shouldFail: true,
10557 expectedError: ":UNEXPECTED_RECORD:",
10558 })
10559
10560 testCases = append(testCases, testCase{
10561 testType: serverTest,
10562 name: "SkipEarlyData-HRR-TooMuchData",
10563 config: Config{
10564 MaxVersion: VersionTLS13,
10565 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010566 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010567 },
10568 DefaultCurves: []CurveID{},
10569 },
10570 shouldFail: true,
10571 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10572 })
10573
10574 // Test that skipping early data looking for cleartext correctly
10575 // processes an alert record.
10576 testCases = append(testCases, testCase{
10577 testType: serverTest,
10578 name: "SkipEarlyData-HRR-FatalAlert",
10579 config: Config{
10580 MaxVersion: VersionTLS13,
10581 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010582 SendEarlyAlert: true,
10583 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010584 },
10585 DefaultCurves: []CurveID{},
10586 },
10587 shouldFail: true,
10588 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10589 })
10590
10591 testCases = append(testCases, testCase{
10592 testType: serverTest,
10593 name: "SkipEarlyData-SecondClientHelloEarlyData",
10594 config: Config{
10595 MaxVersion: VersionTLS13,
10596 Bugs: ProtocolBugs{
10597 SendEarlyDataOnSecondClientHello: true,
10598 },
10599 DefaultCurves: []CurveID{},
10600 },
10601 shouldFail: true,
10602 expectedLocalError: "remote error: bad record MAC",
10603 })
10604
10605 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010606 testType: clientTest,
10607 name: "EmptyEncryptedExtensions",
10608 config: Config{
10609 MaxVersion: VersionTLS13,
10610 Bugs: ProtocolBugs{
10611 EmptyEncryptedExtensions: true,
10612 },
10613 },
10614 shouldFail: true,
10615 expectedLocalError: "remote error: error decoding message",
10616 })
10617
10618 testCases = append(testCases, testCase{
10619 testType: clientTest,
10620 name: "EncryptedExtensionsWithKeyShare",
10621 config: Config{
10622 MaxVersion: VersionTLS13,
10623 Bugs: ProtocolBugs{
10624 EncryptedExtensionsWithKeyShare: true,
10625 },
10626 },
10627 shouldFail: true,
10628 expectedLocalError: "remote error: unsupported extension",
10629 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010630
10631 testCases = append(testCases, testCase{
10632 testType: serverTest,
10633 name: "SendHelloRetryRequest",
10634 config: Config{
10635 MaxVersion: VersionTLS13,
10636 // Require a HelloRetryRequest for every curve.
10637 DefaultCurves: []CurveID{},
10638 },
10639 expectedCurveID: CurveX25519,
10640 })
10641
10642 testCases = append(testCases, testCase{
10643 testType: serverTest,
10644 name: "SendHelloRetryRequest-2",
10645 config: Config{
10646 MaxVersion: VersionTLS13,
10647 DefaultCurves: []CurveID{CurveP384},
10648 },
10649 // Although the ClientHello did not predict our preferred curve,
10650 // we always select it whether it is predicted or not.
10651 expectedCurveID: CurveX25519,
10652 })
10653
10654 testCases = append(testCases, testCase{
10655 name: "UnknownCurve-HelloRetryRequest",
10656 config: Config{
10657 MaxVersion: VersionTLS13,
10658 // P-384 requires HelloRetryRequest in BoringSSL.
10659 CurvePreferences: []CurveID{CurveP384},
10660 Bugs: ProtocolBugs{
10661 SendHelloRetryRequestCurve: bogusCurve,
10662 },
10663 },
10664 shouldFail: true,
10665 expectedError: ":WRONG_CURVE:",
10666 })
10667
10668 testCases = append(testCases, testCase{
10669 name: "DisabledCurve-HelloRetryRequest",
10670 config: Config{
10671 MaxVersion: VersionTLS13,
10672 CurvePreferences: []CurveID{CurveP256},
10673 Bugs: ProtocolBugs{
10674 IgnorePeerCurvePreferences: true,
10675 },
10676 },
10677 flags: []string{"-p384-only"},
10678 shouldFail: true,
10679 expectedError: ":WRONG_CURVE:",
10680 })
10681
10682 testCases = append(testCases, testCase{
10683 name: "UnnecessaryHelloRetryRequest",
10684 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010685 MaxVersion: VersionTLS13,
10686 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010687 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010688 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010689 },
10690 },
10691 shouldFail: true,
10692 expectedError: ":WRONG_CURVE:",
10693 })
10694
10695 testCases = append(testCases, testCase{
10696 name: "SecondHelloRetryRequest",
10697 config: Config{
10698 MaxVersion: VersionTLS13,
10699 // P-384 requires HelloRetryRequest in BoringSSL.
10700 CurvePreferences: []CurveID{CurveP384},
10701 Bugs: ProtocolBugs{
10702 SecondHelloRetryRequest: true,
10703 },
10704 },
10705 shouldFail: true,
10706 expectedError: ":UNEXPECTED_MESSAGE:",
10707 })
10708
10709 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010710 name: "HelloRetryRequest-Empty",
10711 config: Config{
10712 MaxVersion: VersionTLS13,
10713 Bugs: ProtocolBugs{
10714 AlwaysSendHelloRetryRequest: true,
10715 },
10716 },
10717 shouldFail: true,
10718 expectedError: ":DECODE_ERROR:",
10719 })
10720
10721 testCases = append(testCases, testCase{
10722 name: "HelloRetryRequest-DuplicateCurve",
10723 config: Config{
10724 MaxVersion: VersionTLS13,
10725 // P-384 requires a HelloRetryRequest against BoringSSL's default
10726 // configuration. Assert this ExpectMissingKeyShare.
10727 CurvePreferences: []CurveID{CurveP384},
10728 Bugs: ProtocolBugs{
10729 ExpectMissingKeyShare: true,
10730 DuplicateHelloRetryRequestExtensions: true,
10731 },
10732 },
10733 shouldFail: true,
10734 expectedError: ":DUPLICATE_EXTENSION:",
10735 expectedLocalError: "remote error: illegal parameter",
10736 })
10737
10738 testCases = append(testCases, testCase{
10739 name: "HelloRetryRequest-Cookie",
10740 config: Config{
10741 MaxVersion: VersionTLS13,
10742 Bugs: ProtocolBugs{
10743 SendHelloRetryRequestCookie: []byte("cookie"),
10744 },
10745 },
10746 })
10747
10748 testCases = append(testCases, testCase{
10749 name: "HelloRetryRequest-DuplicateCookie",
10750 config: Config{
10751 MaxVersion: VersionTLS13,
10752 Bugs: ProtocolBugs{
10753 SendHelloRetryRequestCookie: []byte("cookie"),
10754 DuplicateHelloRetryRequestExtensions: true,
10755 },
10756 },
10757 shouldFail: true,
10758 expectedError: ":DUPLICATE_EXTENSION:",
10759 expectedLocalError: "remote error: illegal parameter",
10760 })
10761
10762 testCases = append(testCases, testCase{
10763 name: "HelloRetryRequest-EmptyCookie",
10764 config: Config{
10765 MaxVersion: VersionTLS13,
10766 Bugs: ProtocolBugs{
10767 SendHelloRetryRequestCookie: []byte{},
10768 },
10769 },
10770 shouldFail: true,
10771 expectedError: ":DECODE_ERROR:",
10772 })
10773
10774 testCases = append(testCases, testCase{
10775 name: "HelloRetryRequest-Cookie-Curve",
10776 config: Config{
10777 MaxVersion: VersionTLS13,
10778 // P-384 requires HelloRetryRequest in BoringSSL.
10779 CurvePreferences: []CurveID{CurveP384},
10780 Bugs: ProtocolBugs{
10781 SendHelloRetryRequestCookie: []byte("cookie"),
10782 ExpectMissingKeyShare: true,
10783 },
10784 },
10785 })
10786
10787 testCases = append(testCases, testCase{
10788 name: "HelloRetryRequest-Unknown",
10789 config: Config{
10790 MaxVersion: VersionTLS13,
10791 Bugs: ProtocolBugs{
10792 CustomHelloRetryRequestExtension: "extension",
10793 },
10794 },
10795 shouldFail: true,
10796 expectedError: ":UNEXPECTED_EXTENSION:",
10797 expectedLocalError: "remote error: unsupported extension",
10798 })
10799
10800 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010801 testType: serverTest,
10802 name: "SecondClientHelloMissingKeyShare",
10803 config: Config{
10804 MaxVersion: VersionTLS13,
10805 DefaultCurves: []CurveID{},
10806 Bugs: ProtocolBugs{
10807 SecondClientHelloMissingKeyShare: true,
10808 },
10809 },
10810 shouldFail: true,
10811 expectedError: ":MISSING_KEY_SHARE:",
10812 })
10813
10814 testCases = append(testCases, testCase{
10815 testType: serverTest,
10816 name: "SecondClientHelloWrongCurve",
10817 config: Config{
10818 MaxVersion: VersionTLS13,
10819 DefaultCurves: []CurveID{},
10820 Bugs: ProtocolBugs{
10821 MisinterpretHelloRetryRequestCurve: CurveP521,
10822 },
10823 },
10824 shouldFail: true,
10825 expectedError: ":WRONG_CURVE:",
10826 })
10827
10828 testCases = append(testCases, testCase{
10829 name: "HelloRetryRequestVersionMismatch",
10830 config: Config{
10831 MaxVersion: VersionTLS13,
10832 // P-384 requires HelloRetryRequest in BoringSSL.
10833 CurvePreferences: []CurveID{CurveP384},
10834 Bugs: ProtocolBugs{
10835 SendServerHelloVersion: 0x0305,
10836 },
10837 },
10838 shouldFail: true,
10839 expectedError: ":WRONG_VERSION_NUMBER:",
10840 })
10841
10842 testCases = append(testCases, testCase{
10843 name: "HelloRetryRequestCurveMismatch",
10844 config: Config{
10845 MaxVersion: VersionTLS13,
10846 // P-384 requires HelloRetryRequest in BoringSSL.
10847 CurvePreferences: []CurveID{CurveP384},
10848 Bugs: ProtocolBugs{
10849 // Send P-384 (correct) in the HelloRetryRequest.
10850 SendHelloRetryRequestCurve: CurveP384,
10851 // But send P-256 in the ServerHello.
10852 SendCurve: CurveP256,
10853 },
10854 },
10855 shouldFail: true,
10856 expectedError: ":WRONG_CURVE:",
10857 })
10858
10859 // Test the server selecting a curve that requires a HelloRetryRequest
10860 // without sending it.
10861 testCases = append(testCases, testCase{
10862 name: "SkipHelloRetryRequest",
10863 config: Config{
10864 MaxVersion: VersionTLS13,
10865 // P-384 requires HelloRetryRequest in BoringSSL.
10866 CurvePreferences: []CurveID{CurveP384},
10867 Bugs: ProtocolBugs{
10868 SkipHelloRetryRequest: true,
10869 },
10870 },
10871 shouldFail: true,
10872 expectedError: ":WRONG_CURVE:",
10873 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010874
10875 testCases = append(testCases, testCase{
10876 name: "TLS13-RequestContextInHandshake",
10877 config: Config{
10878 MaxVersion: VersionTLS13,
10879 MinVersion: VersionTLS13,
10880 ClientAuth: RequireAnyClientCert,
10881 Bugs: ProtocolBugs{
10882 SendRequestContext: []byte("request context"),
10883 },
10884 },
10885 flags: []string{
10886 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10887 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10888 },
10889 shouldFail: true,
10890 expectedError: ":DECODE_ERROR:",
10891 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010892
10893 testCases = append(testCases, testCase{
10894 testType: serverTest,
10895 name: "TLS13-TrailingKeyShareData",
10896 config: Config{
10897 MaxVersion: VersionTLS13,
10898 Bugs: ProtocolBugs{
10899 TrailingKeyShareData: true,
10900 },
10901 },
10902 shouldFail: true,
10903 expectedError: ":DECODE_ERROR:",
10904 })
David Benjamin7f78df42016-10-05 22:33:19 -040010905
10906 testCases = append(testCases, testCase{
10907 name: "TLS13-AlwaysSelectPSKIdentity",
10908 config: Config{
10909 MaxVersion: VersionTLS13,
10910 Bugs: ProtocolBugs{
10911 AlwaysSelectPSKIdentity: true,
10912 },
10913 },
10914 shouldFail: true,
10915 expectedError: ":UNEXPECTED_EXTENSION:",
10916 })
10917
10918 testCases = append(testCases, testCase{
10919 name: "TLS13-InvalidPSKIdentity",
10920 config: Config{
10921 MaxVersion: VersionTLS13,
10922 Bugs: ProtocolBugs{
10923 SelectPSKIdentityOnResume: 1,
10924 },
10925 },
10926 resumeSession: true,
10927 shouldFail: true,
10928 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10929 })
David Benjamin1286bee2016-10-07 15:25:06 -040010930
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010931 testCases = append(testCases, testCase{
10932 testType: serverTest,
10933 name: "TLS13-ExtraPSKIdentity",
10934 config: Config{
10935 MaxVersion: VersionTLS13,
10936 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010937 ExtraPSKIdentity: true,
10938 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010939 },
10940 },
10941 resumeSession: true,
10942 })
10943
David Benjamin1286bee2016-10-07 15:25:06 -040010944 // Test that unknown NewSessionTicket extensions are tolerated.
10945 testCases = append(testCases, testCase{
10946 name: "TLS13-CustomTicketExtension",
10947 config: Config{
10948 MaxVersion: VersionTLS13,
10949 Bugs: ProtocolBugs{
10950 CustomTicketExtension: "1234",
10951 },
10952 },
10953 })
Steven Valdez2d850622017-01-11 11:34:52 -050010954
Steven Valdez2d850622017-01-11 11:34:52 -050010955 testCases = append(testCases, testCase{
10956 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010957 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010958 config: Config{
10959 MaxVersion: VersionTLS13,
10960 MaxEarlyDataSize: 16384,
10961 },
10962 resumeConfig: &Config{
10963 MaxVersion: VersionTLS13,
10964 MaxEarlyDataSize: 16384,
10965 Bugs: ProtocolBugs{
10966 AlwaysRejectEarlyData: true,
10967 },
10968 },
10969 resumeSession: true,
10970 flags: []string{
10971 "-enable-early-data",
10972 "-expect-early-data-info",
10973 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010974 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010975 },
10976 })
10977
10978 testCases = append(testCases, testCase{
10979 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040010980 name: "TLS13Experiment-EarlyData-Reject-Client",
10981 config: Config{
10982 MaxVersion: VersionTLS13,
10983 MaxEarlyDataSize: 16384,
10984 TLS13Variant: TLS13Experiment,
10985 },
10986 resumeConfig: &Config{
10987 MaxVersion: VersionTLS13,
10988 TLS13Variant: TLS13Experiment,
10989 MaxEarlyDataSize: 16384,
10990 Bugs: ProtocolBugs{
10991 AlwaysRejectEarlyData: true,
10992 },
10993 },
10994 resumeSession: true,
10995 flags: []string{
10996 "-enable-early-data",
10997 "-expect-early-data-info",
10998 "-expect-reject-early-data",
10999 "-on-resume-shim-writes-first",
11000 "-tls13-variant", "1",
11001 },
11002 })
11003
11004 testCases = append(testCases, testCase{
11005 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011006 name: "TLS13-EarlyData-RejectTicket-Client",
11007 config: Config{
11008 MaxVersion: VersionTLS13,
11009 MaxEarlyDataSize: 16384,
11010 Certificates: []Certificate{rsaCertificate},
11011 },
11012 resumeConfig: &Config{
11013 MaxVersion: VersionTLS13,
11014 MaxEarlyDataSize: 16384,
11015 Certificates: []Certificate{ecdsaP256Certificate},
11016 SessionTicketsDisabled: true,
11017 },
11018 resumeSession: true,
11019 expectResumeRejected: true,
11020 flags: []string{
11021 "-enable-early-data",
11022 "-expect-early-data-info",
11023 "-expect-reject-early-data",
11024 "-on-resume-shim-writes-first",
11025 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11026 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11027 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11028 // Session tickets are disabled, so the runner will not send a ticket.
11029 "-on-retry-expect-no-session",
11030 },
11031 })
11032
11033 testCases = append(testCases, testCase{
11034 testType: clientTest,
11035 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011036 config: Config{
11037 MaxVersion: VersionTLS13,
11038 MaxEarlyDataSize: 16384,
11039 },
11040 resumeConfig: &Config{
11041 MaxVersion: VersionTLS13,
11042 MaxEarlyDataSize: 16384,
11043 Bugs: ProtocolBugs{
11044 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11045 },
11046 },
11047 resumeSession: true,
11048 flags: []string{
11049 "-enable-early-data",
11050 "-expect-early-data-info",
11051 "-expect-reject-early-data",
11052 },
11053 })
11054
11055 // The client must check the server does not send the early_data
11056 // extension while rejecting the session.
11057 testCases = append(testCases, testCase{
11058 testType: clientTest,
11059 name: "TLS13-EarlyDataWithoutResume-Client",
11060 config: Config{
11061 MaxVersion: VersionTLS13,
11062 MaxEarlyDataSize: 16384,
11063 },
11064 resumeConfig: &Config{
11065 MaxVersion: VersionTLS13,
11066 SessionTicketsDisabled: true,
11067 Bugs: ProtocolBugs{
11068 SendEarlyDataExtension: true,
11069 },
11070 },
11071 resumeSession: true,
11072 flags: []string{
11073 "-enable-early-data",
11074 "-expect-early-data-info",
11075 },
11076 shouldFail: true,
11077 expectedError: ":UNEXPECTED_EXTENSION:",
11078 })
11079
11080 // The client must fail with a dedicated error code if the server
11081 // responds with TLS 1.2 when offering 0-RTT.
11082 testCases = append(testCases, testCase{
11083 testType: clientTest,
11084 name: "TLS13-EarlyDataVersionDowngrade-Client",
11085 config: Config{
11086 MaxVersion: VersionTLS13,
11087 MaxEarlyDataSize: 16384,
11088 },
11089 resumeConfig: &Config{
11090 MaxVersion: VersionTLS12,
11091 },
11092 resumeSession: true,
11093 flags: []string{
11094 "-enable-early-data",
11095 "-expect-early-data-info",
11096 },
11097 shouldFail: true,
11098 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11099 })
11100
11101 // Test that the client rejects an (unsolicited) early_data extension if
11102 // the server sent an HRR.
11103 testCases = append(testCases, testCase{
11104 testType: clientTest,
11105 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11106 config: Config{
11107 MaxVersion: VersionTLS13,
11108 MaxEarlyDataSize: 16384,
11109 },
11110 resumeConfig: &Config{
11111 MaxVersion: VersionTLS13,
11112 MaxEarlyDataSize: 16384,
11113 Bugs: ProtocolBugs{
11114 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11115 SendEarlyDataExtension: true,
11116 },
11117 },
11118 resumeSession: true,
11119 flags: []string{
11120 "-enable-early-data",
11121 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011122 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011123 },
11124 shouldFail: true,
11125 expectedError: ":UNEXPECTED_EXTENSION:",
11126 })
11127
11128 fooString := "foo"
11129 barString := "bar"
11130
11131 // Test that the client reports the correct ALPN after a 0-RTT reject
11132 // that changed it.
11133 testCases = append(testCases, testCase{
11134 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011135 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011136 config: Config{
11137 MaxVersion: VersionTLS13,
11138 MaxEarlyDataSize: 16384,
11139 Bugs: ProtocolBugs{
11140 ALPNProtocol: &fooString,
11141 },
11142 },
11143 resumeConfig: &Config{
11144 MaxVersion: VersionTLS13,
11145 MaxEarlyDataSize: 16384,
11146 Bugs: ProtocolBugs{
11147 ALPNProtocol: &barString,
11148 },
11149 },
11150 resumeSession: true,
11151 flags: []string{
11152 "-advertise-alpn", "\x03foo\x03bar",
11153 "-enable-early-data",
11154 "-expect-early-data-info",
11155 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011156 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011157 "-on-resume-expect-alpn", "foo",
11158 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011159 },
11160 })
11161
11162 // Test that the client reports the correct ALPN after a 0-RTT reject if
11163 // ALPN was omitted from the first connection.
11164 testCases = append(testCases, testCase{
11165 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011166 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011167 config: Config{
11168 MaxVersion: VersionTLS13,
11169 MaxEarlyDataSize: 16384,
11170 },
11171 resumeConfig: &Config{
11172 MaxVersion: VersionTLS13,
11173 MaxEarlyDataSize: 16384,
11174 NextProtos: []string{"foo"},
11175 },
11176 resumeSession: true,
11177 flags: []string{
11178 "-advertise-alpn", "\x03foo\x03bar",
11179 "-enable-early-data",
11180 "-expect-early-data-info",
11181 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011182 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011183 "-on-resume-expect-alpn", "",
11184 "-on-retry-expect-alpn", "foo",
11185 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011186 },
11187 })
11188
11189 // Test that the client reports the correct ALPN after a 0-RTT reject if
11190 // ALPN was omitted from the second connection.
11191 testCases = append(testCases, testCase{
11192 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011193 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011194 config: Config{
11195 MaxVersion: VersionTLS13,
11196 MaxEarlyDataSize: 16384,
11197 NextProtos: []string{"foo"},
11198 },
11199 resumeConfig: &Config{
11200 MaxVersion: VersionTLS13,
11201 MaxEarlyDataSize: 16384,
11202 },
11203 resumeSession: true,
11204 flags: []string{
11205 "-advertise-alpn", "\x03foo\x03bar",
11206 "-enable-early-data",
11207 "-expect-early-data-info",
11208 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011209 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011210 "-on-resume-expect-alpn", "foo",
11211 "-on-retry-expect-alpn", "",
11212 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011213 },
11214 })
11215
11216 // Test that the client enforces ALPN match on 0-RTT accept.
11217 testCases = append(testCases, testCase{
11218 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011219 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011220 config: Config{
11221 MaxVersion: VersionTLS13,
11222 MaxEarlyDataSize: 16384,
11223 Bugs: ProtocolBugs{
11224 ALPNProtocol: &fooString,
11225 },
11226 },
11227 resumeConfig: &Config{
11228 MaxVersion: VersionTLS13,
11229 MaxEarlyDataSize: 16384,
11230 Bugs: ProtocolBugs{
11231 AlwaysAcceptEarlyData: true,
11232 ALPNProtocol: &barString,
11233 },
11234 },
11235 resumeSession: true,
11236 flags: []string{
11237 "-advertise-alpn", "\x03foo\x03bar",
11238 "-enable-early-data",
11239 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011240 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011241 "-on-resume-expect-alpn", "foo",
11242 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011243 },
11244 shouldFail: true,
11245 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11246 })
11247
11248 // Test that the server correctly rejects 0-RTT when the previous
11249 // session did not allow early data on resumption.
11250 testCases = append(testCases, testCase{
11251 testType: serverTest,
11252 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11253 config: Config{
11254 MaxVersion: VersionTLS13,
11255 },
11256 resumeConfig: &Config{
11257 MaxVersion: VersionTLS13,
11258 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011259 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011260 ExpectEarlyDataAccepted: false,
11261 },
11262 },
11263 resumeSession: true,
11264 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011265 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011266 "-expect-reject-early-data",
11267 },
11268 })
11269
11270 // Test that we reject early data where ALPN is omitted from the first
11271 // connection.
11272 testCases = append(testCases, testCase{
11273 testType: serverTest,
11274 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11275 config: Config{
11276 MaxVersion: VersionTLS13,
11277 NextProtos: []string{},
11278 },
11279 resumeConfig: &Config{
11280 MaxVersion: VersionTLS13,
11281 NextProtos: []string{"foo"},
11282 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011283 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011284 ExpectEarlyDataAccepted: false,
11285 },
11286 },
11287 resumeSession: true,
11288 flags: []string{
11289 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011290 "-on-initial-select-alpn", "",
11291 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011292 },
11293 })
11294
11295 // Test that we reject early data where ALPN is omitted from the second
11296 // connection.
11297 testCases = append(testCases, testCase{
11298 testType: serverTest,
11299 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11300 config: Config{
11301 MaxVersion: VersionTLS13,
11302 NextProtos: []string{"foo"},
11303 },
11304 resumeConfig: &Config{
11305 MaxVersion: VersionTLS13,
11306 NextProtos: []string{},
11307 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011308 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011309 ExpectEarlyDataAccepted: false,
11310 },
11311 },
11312 resumeSession: true,
11313 flags: []string{
11314 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011315 "-on-initial-select-alpn", "foo",
11316 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011317 },
11318 })
11319
11320 // Test that we reject early data with mismatched ALPN.
11321 testCases = append(testCases, testCase{
11322 testType: serverTest,
11323 name: "TLS13-EarlyData-ALPNMismatch-Server",
11324 config: Config{
11325 MaxVersion: VersionTLS13,
11326 NextProtos: []string{"foo"},
11327 },
11328 resumeConfig: &Config{
11329 MaxVersion: VersionTLS13,
11330 NextProtos: []string{"bar"},
11331 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011332 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011333 ExpectEarlyDataAccepted: false,
11334 },
11335 },
11336 resumeSession: true,
11337 flags: []string{
11338 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011339 "-on-initial-select-alpn", "foo",
11340 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011341 },
11342 })
11343
David Benjamin6bb507b2017-03-29 16:35:57 -050011344 // Test that the client offering 0-RTT and Channel ID forbids the server
11345 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011346 testCases = append(testCases, testCase{
11347 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011348 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011349 config: Config{
11350 MaxVersion: VersionTLS13,
11351 MaxEarlyDataSize: 16384,
11352 RequestChannelID: true,
11353 },
11354 resumeSession: true,
11355 expectChannelID: true,
11356 shouldFail: true,
11357 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11358 flags: []string{
11359 "-enable-early-data",
11360 "-expect-early-data-info",
11361 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11362 },
11363 })
11364
David Benjamin6bb507b2017-03-29 16:35:57 -050011365 // Test that the client offering Channel ID and 0-RTT allows the server
11366 // to decline 0-RTT.
11367 testCases = append(testCases, testCase{
11368 testType: clientTest,
11369 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11370 config: Config{
11371 MaxVersion: VersionTLS13,
11372 MaxEarlyDataSize: 16384,
11373 RequestChannelID: true,
11374 Bugs: ProtocolBugs{
11375 AlwaysRejectEarlyData: true,
11376 },
11377 },
11378 resumeSession: true,
11379 expectChannelID: true,
11380 flags: []string{
11381 "-enable-early-data",
11382 "-expect-early-data-info",
11383 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11384 "-expect-reject-early-data",
11385 },
11386 })
11387
11388 // Test that the client offering Channel ID and 0-RTT allows the server
11389 // to decline Channel ID.
11390 testCases = append(testCases, testCase{
11391 testType: clientTest,
11392 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11393 config: Config{
11394 MaxVersion: VersionTLS13,
11395 MaxEarlyDataSize: 16384,
11396 },
11397 resumeSession: true,
11398 flags: []string{
11399 "-enable-early-data",
11400 "-expect-early-data-info",
11401 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11402 "-expect-accept-early-data",
11403 },
11404 })
11405
11406 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11407 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011408 testCases = append(testCases, testCase{
11409 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011410 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011411 config: Config{
11412 MaxVersion: VersionTLS13,
11413 ChannelID: channelIDKey,
11414 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011415 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011416 ExpectEarlyDataAccepted: false,
11417 },
11418 },
11419 resumeSession: true,
11420 expectChannelID: true,
11421 flags: []string{
11422 "-enable-early-data",
11423 "-expect-reject-early-data",
11424 "-expect-channel-id",
11425 base64.StdEncoding.EncodeToString(channelIDBytes),
11426 },
11427 })
11428
David Benjamin6bb507b2017-03-29 16:35:57 -050011429 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11430 // if not offered Channel ID.
11431 testCases = append(testCases, testCase{
11432 testType: serverTest,
11433 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11434 config: Config{
11435 MaxVersion: VersionTLS13,
11436 Bugs: ProtocolBugs{
11437 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11438 ExpectEarlyDataAccepted: true,
11439 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11440 },
11441 },
11442 resumeSession: true,
11443 expectChannelID: false,
11444 flags: []string{
11445 "-enable-early-data",
11446 "-expect-accept-early-data",
11447 "-enable-channel-id",
11448 },
11449 })
11450
David Benjamin32c89272017-03-26 13:54:21 -050011451 // Test that the server rejects 0-RTT streams without end_of_early_data.
11452 // The subsequent records should fail to decrypt.
11453 testCases = append(testCases, testCase{
11454 testType: serverTest,
11455 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11456 config: Config{
11457 MaxVersion: VersionTLS13,
11458 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011459 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011460 ExpectEarlyDataAccepted: true,
11461 SkipEndOfEarlyData: true,
11462 },
11463 },
11464 resumeSession: true,
11465 flags: []string{"-enable-early-data"},
11466 shouldFail: true,
11467 expectedLocalError: "remote error: bad record MAC",
11468 expectedError: ":BAD_DECRYPT:",
11469 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011470
11471 testCases = append(testCases, testCase{
11472 testType: serverTest,
11473 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11474 config: Config{
11475 MaxVersion: VersionTLS13,
11476 },
11477 resumeConfig: &Config{
11478 MaxVersion: VersionTLS13,
11479 Bugs: ProtocolBugs{
11480 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11481 SendStrayEarlyHandshake: true,
11482 ExpectEarlyDataAccepted: true},
11483 },
11484 resumeSession: true,
11485 shouldFail: true,
11486 expectedError: ":UNEXPECTED_RECORD:",
11487 expectedLocalError: "remote error: unexpected message",
11488 flags: []string{
11489 "-enable-early-data",
11490 },
11491 })
David Benjamind9cbb532017-07-07 13:17:19 -040011492
11493 // Test that the client reports TLS 1.3 as the version while sending
11494 // early data.
11495 testCases = append(testCases, testCase{
11496 testType: clientTest,
11497 name: "TLS13-EarlyData-Client-VersionAPI",
11498 config: Config{
11499 MaxVersion: VersionTLS13,
11500 MaxEarlyDataSize: 16384,
11501 },
11502 resumeSession: true,
11503 flags: []string{
11504 "-enable-early-data",
11505 "-expect-early-data-info",
11506 "-expect-accept-early-data",
11507 "-expect-version", strconv.Itoa(VersionTLS13),
11508 },
11509 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011510}
11511
David Benjaminabbbee12016-10-31 19:20:42 -040011512func addTLS13CipherPreferenceTests() {
11513 // Test that client preference is honored if the shim has AES hardware
11514 // and ChaCha20-Poly1305 is preferred otherwise.
11515 testCases = append(testCases, testCase{
11516 testType: serverTest,
11517 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11518 config: Config{
11519 MaxVersion: VersionTLS13,
11520 CipherSuites: []uint16{
11521 TLS_CHACHA20_POLY1305_SHA256,
11522 TLS_AES_128_GCM_SHA256,
11523 },
11524 },
11525 flags: []string{
11526 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11527 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11528 },
11529 })
11530
11531 testCases = append(testCases, testCase{
11532 testType: serverTest,
11533 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11534 config: Config{
11535 MaxVersion: VersionTLS13,
11536 CipherSuites: []uint16{
11537 TLS_AES_128_GCM_SHA256,
11538 TLS_CHACHA20_POLY1305_SHA256,
11539 },
11540 },
11541 flags: []string{
11542 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11543 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11544 },
11545 })
11546
11547 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11548 // whether it has AES hardware.
11549 testCases = append(testCases, testCase{
11550 name: "TLS13-CipherPreference-Client",
11551 config: Config{
11552 MaxVersion: VersionTLS13,
11553 // Use the client cipher order. (This is the default but
11554 // is listed to be explicit.)
11555 PreferServerCipherSuites: false,
11556 },
11557 flags: []string{
11558 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11559 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11560 },
11561 })
11562}
11563
David Benjaminf3fbade2016-09-19 13:08:16 -040011564func addPeekTests() {
11565 // Test SSL_peek works, including on empty records.
11566 testCases = append(testCases, testCase{
11567 name: "Peek-Basic",
11568 sendEmptyRecords: 1,
11569 flags: []string{"-peek-then-read"},
11570 })
11571
11572 // Test SSL_peek can drive the initial handshake.
11573 testCases = append(testCases, testCase{
11574 name: "Peek-ImplicitHandshake",
11575 flags: []string{
11576 "-peek-then-read",
11577 "-implicit-handshake",
11578 },
11579 })
11580
11581 // Test SSL_peek can discover and drive a renegotiation.
11582 testCases = append(testCases, testCase{
11583 name: "Peek-Renegotiate",
11584 config: Config{
11585 MaxVersion: VersionTLS12,
11586 },
11587 renegotiate: 1,
11588 flags: []string{
11589 "-peek-then-read",
11590 "-renegotiate-freely",
11591 "-expect-total-renegotiations", "1",
11592 },
11593 })
11594
11595 // Test SSL_peek can discover a close_notify.
11596 testCases = append(testCases, testCase{
11597 name: "Peek-Shutdown",
11598 config: Config{
11599 Bugs: ProtocolBugs{
11600 ExpectCloseNotify: true,
11601 },
11602 },
11603 flags: []string{
11604 "-peek-then-read",
11605 "-check-close-notify",
11606 },
11607 })
11608
11609 // Test SSL_peek can discover an alert.
11610 testCases = append(testCases, testCase{
11611 name: "Peek-Alert",
11612 config: Config{
11613 Bugs: ProtocolBugs{
11614 SendSpuriousAlert: alertRecordOverflow,
11615 },
11616 },
11617 flags: []string{"-peek-then-read"},
11618 shouldFail: true,
11619 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11620 })
11621
11622 // Test SSL_peek can handle KeyUpdate.
11623 testCases = append(testCases, testCase{
11624 name: "Peek-KeyUpdate",
11625 config: Config{
11626 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011627 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011628 sendKeyUpdates: 1,
11629 keyUpdateRequest: keyUpdateNotRequested,
11630 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011631 })
11632}
11633
David Benjamine6f22212016-11-08 14:28:24 -050011634func addRecordVersionTests() {
11635 for _, ver := range tlsVersions {
11636 // Test that the record version is enforced.
11637 testCases = append(testCases, testCase{
11638 name: "CheckRecordVersion-" + ver.name,
11639 config: Config{
11640 MinVersion: ver.version,
11641 MaxVersion: ver.version,
11642 Bugs: ProtocolBugs{
11643 SendRecordVersion: 0x03ff,
11644 },
11645 },
David Benjamina5022392017-07-10 17:40:39 -040011646 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011647 shouldFail: true,
11648 expectedError: ":WRONG_VERSION_NUMBER:",
11649 })
11650
11651 // Test that the ClientHello may use any record version, for
11652 // compatibility reasons.
11653 testCases = append(testCases, testCase{
11654 testType: serverTest,
11655 name: "LooseInitialRecordVersion-" + ver.name,
11656 config: Config{
11657 MinVersion: ver.version,
11658 MaxVersion: ver.version,
11659 Bugs: ProtocolBugs{
11660 SendInitialRecordVersion: 0x03ff,
11661 },
11662 },
David Benjamina5022392017-07-10 17:40:39 -040011663 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011664 })
11665
11666 // Test that garbage ClientHello record versions are rejected.
11667 testCases = append(testCases, testCase{
11668 testType: serverTest,
11669 name: "GarbageInitialRecordVersion-" + ver.name,
11670 config: Config{
11671 MinVersion: ver.version,
11672 MaxVersion: ver.version,
11673 Bugs: ProtocolBugs{
11674 SendInitialRecordVersion: 0xffff,
11675 },
11676 },
David Benjamina5022392017-07-10 17:40:39 -040011677 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011678 shouldFail: true,
11679 expectedError: ":WRONG_VERSION_NUMBER:",
11680 })
11681 }
11682}
11683
David Benjamin2c516452016-11-15 10:16:54 +090011684func addCertificateTests() {
11685 // Test that a certificate chain with intermediate may be sent and
11686 // received as both client and server.
11687 for _, ver := range tlsVersions {
11688 testCases = append(testCases, testCase{
11689 testType: clientTest,
11690 name: "SendReceiveIntermediate-Client-" + ver.name,
11691 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011692 MinVersion: ver.version,
11693 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011694 Certificates: []Certificate{rsaChainCertificate},
11695 ClientAuth: RequireAnyClientCert,
11696 },
David Benjamina5022392017-07-10 17:40:39 -040011697 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011698 expectPeerCertificate: &rsaChainCertificate,
11699 flags: []string{
11700 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11701 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11702 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11703 },
11704 })
11705
11706 testCases = append(testCases, testCase{
11707 testType: serverTest,
11708 name: "SendReceiveIntermediate-Server-" + ver.name,
11709 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011710 MinVersion: ver.version,
11711 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011712 Certificates: []Certificate{rsaChainCertificate},
11713 },
David Benjamina5022392017-07-10 17:40:39 -040011714 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011715 expectPeerCertificate: &rsaChainCertificate,
11716 flags: []string{
11717 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11718 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11719 "-require-any-client-certificate",
11720 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11721 },
11722 })
11723 }
11724}
11725
David Benjaminbbaf3672016-11-17 10:53:09 +090011726func addRetainOnlySHA256ClientCertTests() {
11727 for _, ver := range tlsVersions {
11728 // Test that enabling
11729 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11730 // actually requesting a client certificate is a no-op.
11731 testCases = append(testCases, testCase{
11732 testType: serverTest,
11733 name: "RetainOnlySHA256-NoCert-" + ver.name,
11734 config: Config{
11735 MinVersion: ver.version,
11736 MaxVersion: ver.version,
11737 },
David Benjamina5022392017-07-10 17:40:39 -040011738 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011739 flags: []string{
11740 "-retain-only-sha256-client-cert-initial",
11741 "-retain-only-sha256-client-cert-resume",
11742 },
11743 resumeSession: true,
11744 })
11745
11746 // Test that when retaining only a SHA-256 certificate is
11747 // enabled, the hash appears as expected.
11748 testCases = append(testCases, testCase{
11749 testType: serverTest,
11750 name: "RetainOnlySHA256-Cert-" + ver.name,
11751 config: Config{
11752 MinVersion: ver.version,
11753 MaxVersion: ver.version,
11754 Certificates: []Certificate{rsaCertificate},
11755 },
David Benjamina5022392017-07-10 17:40:39 -040011756 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011757 flags: []string{
11758 "-verify-peer",
11759 "-retain-only-sha256-client-cert-initial",
11760 "-retain-only-sha256-client-cert-resume",
11761 "-expect-sha256-client-cert-initial",
11762 "-expect-sha256-client-cert-resume",
11763 },
11764 resumeSession: true,
11765 })
11766
11767 // Test that when the config changes from on to off, a
11768 // resumption is rejected because the server now wants the full
11769 // certificate chain.
11770 testCases = append(testCases, testCase{
11771 testType: serverTest,
11772 name: "RetainOnlySHA256-OnOff-" + ver.name,
11773 config: Config{
11774 MinVersion: ver.version,
11775 MaxVersion: ver.version,
11776 Certificates: []Certificate{rsaCertificate},
11777 },
David Benjamina5022392017-07-10 17:40:39 -040011778 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011779 flags: []string{
11780 "-verify-peer",
11781 "-retain-only-sha256-client-cert-initial",
11782 "-expect-sha256-client-cert-initial",
11783 },
11784 resumeSession: true,
11785 expectResumeRejected: true,
11786 })
11787
11788 // Test that when the config changes from off to on, a
11789 // resumption is rejected because the server now wants just the
11790 // hash.
11791 testCases = append(testCases, testCase{
11792 testType: serverTest,
11793 name: "RetainOnlySHA256-OffOn-" + ver.name,
11794 config: Config{
11795 MinVersion: ver.version,
11796 MaxVersion: ver.version,
11797 Certificates: []Certificate{rsaCertificate},
11798 },
David Benjamina5022392017-07-10 17:40:39 -040011799 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011800 flags: []string{
11801 "-verify-peer",
11802 "-retain-only-sha256-client-cert-resume",
11803 "-expect-sha256-client-cert-resume",
11804 },
11805 resumeSession: true,
11806 expectResumeRejected: true,
11807 })
11808 }
11809}
11810
Adam Langleya4b91982016-12-12 12:05:53 -080011811func addECDSAKeyUsageTests() {
11812 p256 := elliptic.P256()
11813 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11814 if err != nil {
11815 panic(err)
11816 }
11817
11818 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11819 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11820 if err != nil {
11821 panic(err)
11822 }
11823
11824 template := x509.Certificate{
11825 SerialNumber: serialNumber,
11826 Subject: pkix.Name{
11827 Organization: []string{"Acme Co"},
11828 },
11829 NotBefore: time.Now(),
11830 NotAfter: time.Now(),
11831
11832 // An ECC certificate with only the keyAgreement key usgae may
11833 // be used with ECDH, but not ECDSA.
11834 KeyUsage: x509.KeyUsageKeyAgreement,
11835 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11836 BasicConstraintsValid: true,
11837 }
11838
11839 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11840 if err != nil {
11841 panic(err)
11842 }
11843
11844 cert := Certificate{
11845 Certificate: [][]byte{derBytes},
11846 PrivateKey: priv,
11847 }
11848
11849 for _, ver := range tlsVersions {
11850 if ver.version < VersionTLS12 {
11851 continue
11852 }
11853
11854 testCases = append(testCases, testCase{
11855 testType: clientTest,
11856 name: "ECDSAKeyUsage-" + ver.name,
11857 config: Config{
11858 MinVersion: ver.version,
11859 MaxVersion: ver.version,
11860 Certificates: []Certificate{cert},
11861 },
David Benjamina5022392017-07-10 17:40:39 -040011862 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080011863 shouldFail: true,
11864 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11865 })
11866 }
11867}
11868
David Benjamin8c26d752017-03-26 15:13:51 -050011869func addExtraHandshakeTests() {
11870 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11871 // to ensure there is no transport I/O.
11872 testCases = append(testCases, testCase{
11873 testType: clientTest,
11874 name: "ExtraHandshake-Client-TLS12",
11875 config: Config{
11876 MinVersion: VersionTLS12,
11877 MaxVersion: VersionTLS12,
11878 },
11879 flags: []string{
11880 "-async",
11881 "-no-op-extra-handshake",
11882 },
11883 })
11884 testCases = append(testCases, testCase{
11885 testType: serverTest,
11886 name: "ExtraHandshake-Server-TLS12",
11887 config: Config{
11888 MinVersion: VersionTLS12,
11889 MaxVersion: VersionTLS12,
11890 },
11891 flags: []string{
11892 "-async",
11893 "-no-op-extra-handshake",
11894 },
11895 })
11896 testCases = append(testCases, testCase{
11897 testType: clientTest,
11898 name: "ExtraHandshake-Client-TLS13",
11899 config: Config{
11900 MinVersion: VersionTLS13,
11901 MaxVersion: VersionTLS13,
11902 },
11903 flags: []string{
11904 "-async",
11905 "-no-op-extra-handshake",
11906 },
11907 })
11908 testCases = append(testCases, testCase{
11909 testType: serverTest,
11910 name: "ExtraHandshake-Server-TLS13",
11911 config: Config{
11912 MinVersion: VersionTLS13,
11913 MaxVersion: VersionTLS13,
11914 },
11915 flags: []string{
11916 "-async",
11917 "-no-op-extra-handshake",
11918 },
11919 })
11920
11921 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11922 testCases = append(testCases, testCase{
11923 testType: serverTest,
11924 name: "ExtraHandshake-Server-EarlyData-TLS13",
11925 config: Config{
11926 MaxVersion: VersionTLS13,
11927 MinVersion: VersionTLS13,
11928 Bugs: ProtocolBugs{
11929 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11930 ExpectEarlyDataAccepted: true,
11931 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11932 },
11933 },
11934 messageCount: 2,
11935 resumeSession: true,
11936 flags: []string{
11937 "-async",
11938 "-enable-early-data",
11939 "-expect-accept-early-data",
11940 "-no-op-extra-handshake",
11941 },
11942 })
11943
11944 // An extra SSL_do_handshake drives the handshake to completion in False
11945 // Start. We test this by handshaking twice and asserting the False
11946 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11947 // how the test works.
11948 testCases = append(testCases, testCase{
11949 testType: clientTest,
11950 name: "ExtraHandshake-FalseStart",
11951 config: Config{
11952 MaxVersion: VersionTLS12,
11953 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11954 NextProtos: []string{"foo"},
11955 Bugs: ProtocolBugs{
11956 ExpectFalseStart: true,
11957 AlertBeforeFalseStartTest: alertAccessDenied,
11958 },
11959 },
11960 flags: []string{
11961 "-handshake-twice",
11962 "-false-start",
11963 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011964 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011965 },
11966 shimWritesFirst: true,
11967 shouldFail: true,
11968 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11969 expectedLocalError: "tls: peer did not false start: EOF",
11970 })
11971}
11972
Adam Langley7c803a62015-06-15 15:35:05 -070011973func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011974 defer wg.Done()
11975
11976 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011977 var err error
11978
David Benjaminba28dfc2016-11-15 17:47:21 +090011979 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011980 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11981 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011982 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011983 if err != nil {
11984 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11985 }
11986 break
11987 }
11988 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011989 } else if *repeatUntilFailure {
11990 for err == nil {
11991 statusChan <- statusMsg{test: test, started: true}
11992 err = runTest(test, shimPath, -1)
11993 }
11994 } else {
11995 statusChan <- statusMsg{test: test, started: true}
11996 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011997 }
Adam Langley95c29f32014-06-20 12:00:00 -070011998 statusChan <- statusMsg{test: test, err: err}
11999 }
12000}
12001
12002type statusMsg struct {
12003 test *testCase
12004 started bool
12005 err error
12006}
12007
David Benjamin5f237bc2015-02-11 17:14:15 -050012008func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012009 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012010
David Benjamin5f237bc2015-02-11 17:14:15 -050012011 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012012 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012013 if !*pipe {
12014 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012015 var erase string
12016 for i := 0; i < lineLen; i++ {
12017 erase += "\b \b"
12018 }
12019 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012020 }
12021
Adam Langley95c29f32014-06-20 12:00:00 -070012022 if msg.started {
12023 started++
12024 } else {
12025 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012026
12027 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012028 if msg.err == errUnimplemented {
12029 if *pipe {
12030 // Print each test instead of a status line.
12031 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12032 }
12033 unimplemented++
12034 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12035 } else {
12036 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12037 failed++
12038 testOutput.addResult(msg.test.name, "FAIL")
12039 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012040 } else {
12041 if *pipe {
12042 // Print each test instead of a status line.
12043 fmt.Printf("PASSED (%s)\n", msg.test.name)
12044 }
12045 testOutput.addResult(msg.test.name, "PASS")
12046 }
Adam Langley95c29f32014-06-20 12:00:00 -070012047 }
12048
David Benjamin5f237bc2015-02-11 17:14:15 -050012049 if !*pipe {
12050 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012051 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012052 lineLen = len(line)
12053 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012054 }
Adam Langley95c29f32014-06-20 12:00:00 -070012055 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012056
12057 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012058}
12059
12060func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012061 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012062 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012063 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012064
Adam Langley7c803a62015-06-15 15:35:05 -070012065 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012066 addCipherSuiteTests()
12067 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012068 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012069 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012070 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012071 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012072 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012073 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012074 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012075 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012076 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012077 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012078 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012079 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012080 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012081 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012082 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012083 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012084 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012085 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012086 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012087 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012088 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012089 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012090 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012091 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012092 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012093 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012094 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012095 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012096 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012097 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012098 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012099 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012100
12101 var wg sync.WaitGroup
12102
Adam Langley7c803a62015-06-15 15:35:05 -070012103 statusChan := make(chan statusMsg, *numWorkers)
12104 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012105 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012106
EKRf71d7ed2016-08-06 13:25:12 -070012107 if len(*shimConfigFile) != 0 {
12108 encoded, err := ioutil.ReadFile(*shimConfigFile)
12109 if err != nil {
12110 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12111 os.Exit(1)
12112 }
12113
12114 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12115 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12116 os.Exit(1)
12117 }
12118 }
12119
David Benjamin025b3d32014-07-01 19:53:04 -040012120 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012121
Adam Langley7c803a62015-06-15 15:35:05 -070012122 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012123 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012124 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012125 }
12126
David Benjamin270f0a72016-03-17 14:41:36 -040012127 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012128 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012129 matched := true
12130 if len(*testToRun) != 0 {
12131 var err error
12132 matched, err = filepath.Match(*testToRun, testCases[i].name)
12133 if err != nil {
12134 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12135 os.Exit(1)
12136 }
12137 }
12138
EKRf71d7ed2016-08-06 13:25:12 -070012139 if !*includeDisabled {
12140 for pattern := range shimConfig.DisabledTests {
12141 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12142 if err != nil {
12143 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12144 os.Exit(1)
12145 }
12146
12147 if isDisabled {
12148 matched = false
12149 break
12150 }
12151 }
12152 }
12153
David Benjamin17e12922016-07-28 18:04:43 -040012154 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012155 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012156 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012157
12158 // Only run one test if repeating until failure.
12159 if *repeatUntilFailure {
12160 break
12161 }
Adam Langley95c29f32014-06-20 12:00:00 -070012162 }
12163 }
David Benjamin17e12922016-07-28 18:04:43 -040012164
David Benjamin270f0a72016-03-17 14:41:36 -040012165 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012166 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012167 os.Exit(1)
12168 }
Adam Langley95c29f32014-06-20 12:00:00 -070012169
12170 close(testChan)
12171 wg.Wait()
12172 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012173 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012174
12175 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012176
12177 if *jsonOutput != "" {
12178 if err := testOutput.writeTo(*jsonOutput); err != nil {
12179 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12180 }
12181 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012182
EKR842ae6c2016-07-27 09:22:05 +020012183 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12184 os.Exit(1)
12185 }
12186
12187 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012188 os.Exit(1)
12189 }
Adam Langley95c29f32014-06-20 12:00:00 -070012190}