blob: be74ffe7f23f9f600df30ad4b0e4cc1da01d2219 [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
Adam Langley95c29f32014-06-20 12:00:00 -0700459}
460
Adam Langley7c803a62015-06-15 15:35:05 -0700461var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700462
David Benjamin0fde2eb2017-06-30 19:11:22 -0400463func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500464 if len(data) == 0 {
465 return
466 }
467
David Benjamin0fde2eb2017-06-30 19:11:22 -0400468 settings, err := ioutil.ReadFile(path)
469 if err != nil {
470 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500471 return
472 }
473
David Benjamin0fde2eb2017-06-30 19:11:22 -0400474 settings = append(settings, data...)
475 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
476 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500477 }
478}
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480// A timeoutConn implements an idle timeout on each Read and Write operation.
481type timeoutConn struct {
482 net.Conn
483 timeout time.Duration
484}
485
486func (t *timeoutConn) Read(b []byte) (int, error) {
487 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
488 return 0, err
489 }
490 return t.Conn.Read(b)
491}
492
493func (t *timeoutConn) Write(b []byte) (int, error) {
494 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
495 return 0, err
496 }
497 return t.Conn.Write(b)
498}
499
David Benjamin0fde2eb2017-06-30 19:11:22 -0400500func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400501 if !test.noSessionCache {
502 if config.ClientSessionCache == nil {
503 config.ClientSessionCache = NewLRUClientSessionCache(1)
504 }
505 if config.ServerSessionCache == nil {
506 config.ServerSessionCache = NewLRUServerSessionCache(1)
507 }
508 }
509 if test.testType == clientTest {
510 if len(config.Certificates) == 0 {
511 config.Certificates = []Certificate{rsaCertificate}
512 }
513 } else {
514 // Supply a ServerName to ensure a constant session cache key,
515 // rather than falling back to net.Conn.RemoteAddr.
516 if len(config.ServerName) == 0 {
517 config.ServerName = "test"
518 }
519 }
520 if *fuzzer {
521 config.Bugs.NullAllCiphers = true
522 }
David Benjamin01a90572016-09-22 00:11:43 -0400523 if *deterministic {
524 config.Time = func() time.Time { return time.Unix(1234, 1234) }
525 }
David Benjamine54af062016-08-08 19:21:18 -0400526
David Benjamin01784b42016-06-07 18:00:52 -0400527 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500528
David Benjamin6fd297b2014-08-11 18:43:38 -0400529 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500530 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
531 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500532 }
533
David Benjamin9867b7d2016-03-01 23:25:48 -0500534 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500535 local, peer := "client", "server"
536 if test.testType == clientTest {
537 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500538 }
David Benjaminebda9b32015-11-02 15:33:18 -0500539 connDebug := &recordingConn{
540 Conn: conn,
541 isDatagram: test.protocol == dtls,
542 local: local,
543 peer: peer,
544 }
545 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500546 if *flagDebug {
547 defer connDebug.WriteTo(os.Stdout)
548 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400549 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500550 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400551 path := transcriptPrefix + strconv.Itoa(num)
552 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500553 }()
554 }
David Benjaminebda9b32015-11-02 15:33:18 -0500555
556 if config.Bugs.PacketAdaptor != nil {
557 config.Bugs.PacketAdaptor.debug = connDebug
558 }
559 }
560
561 if test.replayWrites {
562 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400563 }
564
David Benjamin3ed59772016-03-08 12:50:21 -0500565 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500566 if test.damageFirstWrite {
567 connDamage = newDamageAdaptor(conn)
568 conn = connDamage
569 }
570
David Benjamin6fd297b2014-08-11 18:43:38 -0400571 if test.sendPrefix != "" {
572 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
573 return err
574 }
David Benjamin98e882e2014-08-08 13:24:34 -0400575 }
576
David Benjamin1d5c83e2014-07-22 19:20:02 -0400577 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400578 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400579 if test.protocol == dtls {
580 tlsConn = DTLSServer(conn, config)
581 } else {
582 tlsConn = Server(conn, config)
583 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400584 } else {
585 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400586 if test.protocol == dtls {
587 tlsConn = DTLSClient(conn, config)
588 } else {
589 tlsConn = Client(conn, config)
590 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400591 }
David Benjamin30789da2015-08-29 22:56:45 -0400592 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400593
Adam Langley95c29f32014-06-20 12:00:00 -0700594 if err := tlsConn.Handshake(); err != nil {
595 return err
596 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700597
David Benjamin01fe8202014-09-24 15:21:44 -0400598 // TODO(davidben): move all per-connection expectations into a dedicated
599 // expectations struct that can be specified separately for the two
600 // legs.
601 expectedVersion := test.expectedVersion
602 if isResume && test.expectedResumeVersion != 0 {
603 expectedVersion = test.expectedResumeVersion
604 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700605 connState := tlsConn.ConnectionState()
606 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400607 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400608 }
609
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400611 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
612 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700613 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
614 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
615 }
David Benjamin90da8c82015-04-20 14:57:57 -0400616
David Benjamina08e49d2014-08-24 01:46:07 -0400617 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700618 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400619 if channelID == nil {
620 return fmt.Errorf("no channel ID negotiated")
621 }
622 if channelID.Curve != channelIDKey.Curve ||
623 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
624 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
625 return fmt.Errorf("incorrect channel ID")
626 }
David Benjamin634f4752017-07-01 11:08:41 -0400627 } else if connState.ChannelID != nil {
628 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400629 }
630
David Benjaminae2888f2014-09-06 12:58:58 -0400631 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700632 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400633 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
634 }
635 }
636
David Benjaminc7ce9772015-10-09 19:32:41 -0400637 if test.expectNoNextProto {
638 if actual := connState.NegotiatedProtocol; actual != "" {
639 return fmt.Errorf("got unexpected next proto %s", actual)
640 }
641 }
642
David Benjaminfc7b0862014-09-06 13:21:53 -0400643 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700644 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400645 return fmt.Errorf("next proto type mismatch")
646 }
647 }
648
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700649 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500650 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
651 }
652
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100653 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300654 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100655 }
656
Paul Lietar4fac72e2015-09-09 13:44:55 +0100657 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
658 return fmt.Errorf("SCT list mismatch")
659 }
660
Nick Harper60edffd2016-06-21 15:19:24 -0700661 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
662 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400663 }
664
Steven Valdez5440fe02016-07-18 12:40:30 -0400665 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
666 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
667 }
668
David Benjamin2c516452016-11-15 10:16:54 +0900669 if test.expectPeerCertificate != nil {
670 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
671 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
672 }
673 for i, cert := range connState.PeerCertificates {
674 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
675 return fmt.Errorf("peer certificate %d did not match", i+1)
676 }
677 }
678 }
679
David Benjaminc565ebb2015-04-03 04:06:36 -0400680 if test.exportKeyingMaterial > 0 {
681 actual := make([]byte, test.exportKeyingMaterial)
682 if _, err := io.ReadFull(tlsConn, actual); err != nil {
683 return err
684 }
685 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
686 if err != nil {
687 return err
688 }
689 if !bytes.Equal(actual, expected) {
690 return fmt.Errorf("keying material mismatch")
691 }
692 }
693
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700694 if test.testTLSUnique {
695 var peersValue [12]byte
696 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
697 return err
698 }
699 expected := tlsConn.ConnectionState().TLSUnique
700 if !bytes.Equal(peersValue[:], expected) {
701 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
702 }
703 }
704
David Benjamin47921102016-07-28 11:29:18 -0400705 if test.sendHalfHelloRequest {
706 tlsConn.SendHalfHelloRequest()
707 }
708
Steven Valdeze831a812017-03-09 14:56:07 -0500709 shimPrefix := test.shimPrefix
710 if isResume {
711 shimPrefix = test.resumeShimPrefix
712 }
713 if test.shimWritesFirst || test.readWithUnfinishedWrite {
714 shimPrefix = "hello"
715 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400716 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400717 // If readWithUnfinishedWrite is set, the shim prefix will be
718 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500719 if shimPrefix != "" && !test.readWithUnfinishedWrite {
720 var buf = make([]byte, len(shimPrefix))
721 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400722 if err != nil {
723 return err
724 }
Steven Valdeze831a812017-03-09 14:56:07 -0500725 if string(buf) != shimPrefix {
726 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400727 }
Steven Valdeze831a812017-03-09 14:56:07 -0500728 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400729 }
730
Adam Langleycf2d4f42014-10-28 19:06:14 -0700731 if test.renegotiateCiphers != nil {
732 config.CipherSuites = test.renegotiateCiphers
733 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400734 for i := 0; i < test.renegotiate; i++ {
735 if err := tlsConn.Renegotiate(); err != nil {
736 return err
737 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700738 }
739 } else if test.renegotiateCiphers != nil {
740 panic("renegotiateCiphers without renegotiate")
741 }
742
David Benjamin5fa3eba2015-01-22 16:35:40 -0500743 if test.damageFirstWrite {
744 connDamage.setDamage(true)
745 tlsConn.Write([]byte("DAMAGED WRITE"))
746 connDamage.setDamage(false)
747 }
748
David Benjamin8e6db492015-07-25 18:29:23 -0400749 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700750 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400751 if test.protocol == dtls {
752 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
753 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700754 // Read until EOF.
755 _, err := io.Copy(ioutil.Discard, tlsConn)
756 return err
757 }
David Benjamin4417d052015-04-05 04:17:25 -0400758 if messageLen == 0 {
759 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700760 }
Adam Langley95c29f32014-06-20 12:00:00 -0700761
David Benjamin8e6db492015-07-25 18:29:23 -0400762 messageCount := test.messageCount
763 if messageCount == 0 {
764 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400765 }
766
David Benjamin8e6db492015-07-25 18:29:23 -0400767 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400768 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400769 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400770 }
771
David Benjamin8e6db492015-07-25 18:29:23 -0400772 for i := 0; i < test.sendEmptyRecords; i++ {
773 tlsConn.Write(nil)
774 }
775
776 for i := 0; i < test.sendWarningAlerts; i++ {
777 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
778 }
779
David Benjamin24e58862017-06-14 18:45:29 -0400780 if test.sendBogusAlertType {
781 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
782 }
783
David Benjaminbbba9392017-04-06 12:54:12 -0400784 testMessage := make([]byte, messageLen)
785 for i := range testMessage {
786 testMessage[i] = 0x42 ^ byte(j)
787 }
788 tlsConn.Write(testMessage)
789
790 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500791 if shimPrefix != "" {
792 var buf = make([]byte, len(shimPrefix))
793 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400794 if err != nil {
795 return err
796 }
Steven Valdeze831a812017-03-09 14:56:07 -0500797 if string(buf) != shimPrefix {
798 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400799 }
Steven Valdeze831a812017-03-09 14:56:07 -0500800 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400801 }
802
David Benjamin4f75aaf2015-09-01 16:53:10 -0400803 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400804 // The shim will not respond.
805 continue
806 }
807
David Benjaminbbba9392017-04-06 12:54:12 -0400808 // Process the KeyUpdate ACK. However many KeyUpdates the runner
809 // sends, the shim should respond only once.
810 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
811 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
812 return err
813 }
814 }
815
David Benjamin8e6db492015-07-25 18:29:23 -0400816 buf := make([]byte, len(testMessage))
817 if test.protocol == dtls {
818 bufTmp := make([]byte, len(buf)+1)
819 n, err := tlsConn.Read(bufTmp)
820 if err != nil {
821 return err
822 }
823 if n != len(buf) {
824 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
825 }
826 copy(buf, bufTmp)
827 } else {
828 _, err := io.ReadFull(tlsConn, buf)
829 if err != nil {
830 return err
831 }
832 }
833
834 for i, v := range buf {
835 if v != testMessage[i]^0xff {
836 return fmt.Errorf("bad reply contents at byte %d", i)
837 }
Adam Langley95c29f32014-06-20 12:00:00 -0700838 }
839 }
840
841 return nil
842}
843
David Benjamin325b5c32014-07-01 19:40:31 -0400844func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400845 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700846 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400847 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700848 }
David Benjamin325b5c32014-07-01 19:40:31 -0400849 valgrindArgs = append(valgrindArgs, path)
850 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700851
David Benjamin325b5c32014-07-01 19:40:31 -0400852 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700853}
854
David Benjamin325b5c32014-07-01 19:40:31 -0400855func gdbOf(path string, args ...string) *exec.Cmd {
856 xtermArgs := []string{"-e", "gdb", "--args"}
857 xtermArgs = append(xtermArgs, path)
858 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700859
David Benjamin325b5c32014-07-01 19:40:31 -0400860 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700861}
862
David Benjamind16bf342015-12-18 00:53:12 -0500863func lldbOf(path string, args ...string) *exec.Cmd {
864 xtermArgs := []string{"-e", "lldb", "--"}
865 xtermArgs = append(xtermArgs, path)
866 xtermArgs = append(xtermArgs, args...)
867
868 return exec.Command("xterm", xtermArgs...)
869}
870
EKR842ae6c2016-07-27 09:22:05 +0200871var (
872 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
873 errUnimplemented = errors.New("child process does not implement needed flags")
874)
Adam Langley69a01602014-11-17 17:26:55 -0800875
David Benjamin87c8a642015-02-21 01:54:29 -0500876// accept accepts a connection from listener, unless waitChan signals a process
877// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400878func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500879 type connOrError struct {
880 conn net.Conn
881 err error
882 }
883 connChan := make(chan connOrError, 1)
884 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400885 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500886 conn, err := listener.Accept()
887 connChan <- connOrError{conn, err}
888 close(connChan)
889 }()
890 select {
891 case result := <-connChan:
892 return result.conn, result.err
893 case childErr := <-waitChan:
894 waitChan <- childErr
895 return nil, fmt.Errorf("child exited early: %s", childErr)
896 }
897}
898
EKRf71d7ed2016-08-06 13:25:12 -0700899func translateExpectedError(errorStr string) string {
900 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
901 return translated
902 }
903
904 if *looseErrors {
905 return ""
906 }
907
908 return errorStr
909}
910
Adam Langley7c803a62015-06-15 15:35:05 -0700911func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400912 // Help debugging panics on the Go side.
913 defer func() {
914 if r := recover(); r != nil {
915 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
916 panic(r)
917 }
918 }()
919
Adam Langley38311732014-10-16 19:04:35 -0700920 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
921 panic("Error expected without shouldFail in " + test.name)
922 }
923
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700924 if test.expectResumeRejected && !test.resumeSession {
925 panic("expectResumeRejected without resumeSession in " + test.name)
926 }
927
Adam Langley33b1d4f2016-12-07 15:03:45 -0800928 for _, ver := range tlsVersions {
929 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
930 continue
931 }
932
933 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
934 continue
935 }
936
937 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))
938 }
939
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700940 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
941 if err != nil {
942 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
943 }
David Benjamin87c8a642015-02-21 01:54:29 -0500944 if err != nil {
945 panic(err)
946 }
947 defer func() {
948 if listener != nil {
949 listener.Close()
950 }
951 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700952
David Benjamin87c8a642015-02-21 01:54:29 -0500953 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400954 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400955 flags = append(flags, "-server")
956
David Benjamin025b3d32014-07-01 19:53:04 -0400957 flags = append(flags, "-key-file")
958 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700959 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400960 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700961 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400962 }
963
964 flags = append(flags, "-cert-file")
965 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700966 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400967 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700968 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400969 }
970 }
David Benjamin5a593af2014-08-11 19:51:50 -0400971
David Benjamin6fd297b2014-08-11 18:43:38 -0400972 if test.protocol == dtls {
973 flags = append(flags, "-dtls")
974 }
975
David Benjamin46662482016-08-17 00:51:00 -0400976 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400977 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400978 resumeCount++
979 if test.resumeRenewedSession {
980 resumeCount++
981 }
982 }
983
984 if resumeCount > 0 {
985 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400986 }
987
David Benjamine58c4f52014-08-24 03:47:07 -0400988 if test.shimWritesFirst {
989 flags = append(flags, "-shim-writes-first")
990 }
991
David Benjaminbbba9392017-04-06 12:54:12 -0400992 if test.readWithUnfinishedWrite {
993 flags = append(flags, "-read-with-unfinished-write")
994 }
995
David Benjamin30789da2015-08-29 22:56:45 -0400996 if test.shimShutsDown {
997 flags = append(flags, "-shim-shuts-down")
998 }
999
David Benjaminc565ebb2015-04-03 04:06:36 -04001000 if test.exportKeyingMaterial > 0 {
1001 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1002 flags = append(flags, "-export-label", test.exportLabel)
1003 flags = append(flags, "-export-context", test.exportContext)
1004 if test.useExportContext {
1005 flags = append(flags, "-use-export-context")
1006 }
1007 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001008 if test.expectResumeRejected {
1009 flags = append(flags, "-expect-session-miss")
1010 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001011
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001012 if test.testTLSUnique {
1013 flags = append(flags, "-tls-unique")
1014 }
1015
David Benjamin0fde2eb2017-06-30 19:11:22 -04001016 var transcriptPrefix string
1017 if len(*transcriptDir) != 0 {
1018 protocol := "tls"
1019 if test.protocol == dtls {
1020 protocol = "dtls"
1021 }
1022
1023 side := "client"
1024 if test.testType == serverTest {
1025 side = "server"
1026 }
1027
1028 dir := filepath.Join(*transcriptDir, protocol, side)
1029 if err := os.MkdirAll(dir, 0755); err != nil {
1030 return err
1031 }
1032 transcriptPrefix = filepath.Join(dir, test.name+"-")
1033 flags = append(flags, "-write-settings", transcriptPrefix)
1034 }
1035
David Benjamin025b3d32014-07-01 19:53:04 -04001036 flags = append(flags, test.flags...)
1037
1038 var shim *exec.Cmd
1039 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001040 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001041 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001042 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001043 } else if *useLLDB {
1044 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001045 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001046 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001047 }
David Benjamin025b3d32014-07-01 19:53:04 -04001048 shim.Stdin = os.Stdin
1049 var stdoutBuf, stderrBuf bytes.Buffer
1050 shim.Stdout = &stdoutBuf
1051 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001052 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001053 shim.Env = os.Environ()
1054 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001055 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001056 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001057 }
1058 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1059 }
David Benjamin025b3d32014-07-01 19:53:04 -04001060
1061 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001062 panic(err)
1063 }
David Benjamin87c8a642015-02-21 01:54:29 -05001064 waitChan := make(chan error, 1)
1065 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001066
1067 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001068
David Benjamin7a4aaa42016-09-20 17:58:14 -04001069 if *deterministic {
1070 config.Rand = &deterministicRand{}
1071 }
1072
David Benjamin87c8a642015-02-21 01:54:29 -05001073 conn, err := acceptOrWait(listener, waitChan)
1074 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001075 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001076 conn.Close()
1077 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001078
David Benjamin46662482016-08-17 00:51:00 -04001079 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001080 var resumeConfig Config
1081 if test.resumeConfig != nil {
1082 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001083 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001084 resumeConfig.SessionTicketKey = config.SessionTicketKey
1085 resumeConfig.ClientSessionCache = config.ClientSessionCache
1086 resumeConfig.ServerSessionCache = config.ServerSessionCache
1087 }
David Benjamin2e045a92016-06-08 13:09:56 -04001088 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001089 } else {
1090 resumeConfig = config
1091 }
David Benjamin87c8a642015-02-21 01:54:29 -05001092 var connResume net.Conn
1093 connResume, err = acceptOrWait(listener, waitChan)
1094 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001095 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001096 connResume.Close()
1097 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001098 }
1099
David Benjamin87c8a642015-02-21 01:54:29 -05001100 // Close the listener now. This is to avoid hangs should the shim try to
1101 // open more connections than expected.
1102 listener.Close()
1103 listener = nil
1104
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001105 var shimKilledLock sync.Mutex
1106 var shimKilled bool
1107 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1108 shimKilledLock.Lock()
1109 shimKilled = true
1110 shimKilledLock.Unlock()
1111 shim.Process.Kill()
1112 })
David Benjamin87c8a642015-02-21 01:54:29 -05001113 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001114 waitTimeout.Stop()
1115 shimKilledLock.Lock()
1116 if shimKilled && err == nil {
1117 err = errors.New("timeout waiting for the shim to exit.")
1118 }
1119 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001120 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001121 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001122 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1123 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001124 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001125 case 89:
1126 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001127 case 99:
1128 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001129 }
1130 }
Adam Langley95c29f32014-06-20 12:00:00 -07001131
David Benjamin9bea3492016-03-02 10:59:16 -05001132 // Account for Windows line endings.
1133 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1134 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001135
1136 // Separate the errors from the shim and those from tools like
1137 // AddressSanitizer.
1138 var extraStderr string
1139 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1140 stderr = stderrParts[0]
1141 extraStderr = stderrParts[1]
1142 }
1143
Adam Langley95c29f32014-06-20 12:00:00 -07001144 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001145 expectedError := translateExpectedError(test.expectedError)
1146 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001147
Adam Langleyac61fa32014-06-23 12:03:11 -07001148 localError := "none"
1149 if err != nil {
1150 localError = err.Error()
1151 }
1152 if len(test.expectedLocalError) != 0 {
1153 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1154 }
Adam Langley95c29f32014-06-20 12:00:00 -07001155
1156 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001157 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001158 if childErr != nil {
1159 childError = childErr.Error()
1160 }
1161
1162 var msg string
1163 switch {
1164 case failed && !test.shouldFail:
1165 msg = "unexpected failure"
1166 case !failed && test.shouldFail:
1167 msg = "unexpected success"
1168 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001169 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001170 default:
1171 panic("internal error")
1172 }
1173
David Benjamin9aafb642016-09-20 19:36:53 -04001174 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 -07001175 }
1176
David Benjamind2ba8892016-09-20 19:41:04 -04001177 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001178 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001179 }
1180
David Benjamind2ba8892016-09-20 19:41:04 -04001181 if *useValgrind && isValgrindError {
1182 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1183 }
1184
Adam Langley95c29f32014-06-20 12:00:00 -07001185 return nil
1186}
1187
David Benjaminaa012042016-12-10 13:33:05 -05001188type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001189 name string
1190 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001191 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001192 // excludeFlag is the legacy shim flag to disable the version.
1193 excludeFlag string
1194 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001195 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1196 versionDTLS uint16
1197 // versionWire, if non-zero, is the wire representation of the
1198 // version. Otherwise the wire version is the protocol version or
1199 // versionDTLS.
1200 versionWire uint16
1201 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001202}
1203
1204func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001205 // The shim uses the protocol version in its public API, but uses the
1206 // DTLS-specific version if it exists.
1207 if protocol == dtls && vers.versionDTLS != 0 {
1208 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001209 }
Steven Valdez520e1222017-06-13 12:45:25 -04001210 return strconv.Itoa(int(vers.version))
1211}
1212
1213func (vers tlsVersion) wire(protocol protocol) uint16 {
1214 if protocol == dtls && vers.versionDTLS != 0 {
1215 return vers.versionDTLS
1216 }
1217 if vers.versionWire != 0 {
1218 return vers.versionWire
1219 }
1220 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001221}
1222
1223var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001224 {
1225 name: "SSL3",
1226 version: VersionSSL30,
1227 excludeFlag: "-no-ssl3",
1228 },
1229 {
1230 name: "TLS1",
1231 version: VersionTLS10,
1232 excludeFlag: "-no-tls1",
1233 hasDTLS: true,
1234 versionDTLS: VersionDTLS10,
1235 },
1236 {
1237 name: "TLS11",
1238 version: VersionTLS11,
1239 excludeFlag: "-no-tls11",
1240 },
1241 {
1242 name: "TLS12",
1243 version: VersionTLS12,
1244 excludeFlag: "-no-tls12",
1245 hasDTLS: true,
1246 versionDTLS: VersionDTLS12,
1247 },
1248 {
1249 name: "TLS13",
1250 version: VersionTLS13,
1251 excludeFlag: "-no-tls13",
1252 versionWire: tls13DraftVersion,
1253 tls13Variant: TLS13Default,
1254 },
1255 {
1256 name: "TLS13Experiment",
1257 version: VersionTLS13,
1258 excludeFlag: "-no-tls13",
1259 versionWire: tls13ExperimentVersion,
1260 tls13Variant: TLS13Experiment,
1261 },
1262}
1263
1264func allVersions(protocol protocol) []tlsVersion {
1265 if protocol == tls {
1266 return tlsVersions
1267 }
1268
1269 var ret []tlsVersion
1270 for _, vers := range tlsVersions {
1271 if vers.hasDTLS {
1272 ret = append(ret, vers)
1273 }
1274 }
1275 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001276}
1277
David Benjaminaa012042016-12-10 13:33:05 -05001278type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001279 name string
1280 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001281}
1282
1283var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001284 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001285 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001286 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001287 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001288 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001289 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001290 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001291 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1292 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001293 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1294 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001295 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001296 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001297 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001298 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001299 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001300 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001301 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001302 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001303 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001304 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001305 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1306 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001307 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1308 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001309 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001310 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1311 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1312 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001313 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001314}
1315
David Benjamin8b8c0062014-11-23 02:47:52 -05001316func hasComponent(suiteName, component string) bool {
1317 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1318}
1319
David Benjaminf7768e42014-08-31 02:06:47 -04001320func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001321 return hasComponent(suiteName, "GCM") ||
1322 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001323 hasComponent(suiteName, "SHA384") ||
1324 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001325}
1326
Nick Harper1fd39d82016-06-14 18:14:35 -07001327func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001328 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001329}
1330
David Benjamin8b8c0062014-11-23 02:47:52 -05001331func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001332 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001333}
1334
Adam Langleya7997f12015-05-14 17:38:50 -07001335func bigFromHex(hex string) *big.Int {
1336 ret, ok := new(big.Int).SetString(hex, 16)
1337 if !ok {
1338 panic("failed to parse hex number 0x" + hex)
1339 }
1340 return ret
1341}
1342
Adam Langley7c803a62015-06-15 15:35:05 -07001343func addBasicTests() {
1344 basicTests := []testCase{
1345 {
Adam Langley7c803a62015-06-15 15:35:05 -07001346 name: "NoFallbackSCSV",
1347 config: Config{
1348 Bugs: ProtocolBugs{
1349 FailIfNotFallbackSCSV: true,
1350 },
1351 },
1352 shouldFail: true,
1353 expectedLocalError: "no fallback SCSV found",
1354 },
1355 {
1356 name: "SendFallbackSCSV",
1357 config: Config{
1358 Bugs: ProtocolBugs{
1359 FailIfNotFallbackSCSV: true,
1360 },
1361 },
1362 flags: []string{"-fallback-scsv"},
1363 },
1364 {
1365 name: "ClientCertificateTypes",
1366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001367 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001368 ClientAuth: RequestClientCert,
1369 ClientCertificateTypes: []byte{
1370 CertTypeDSSSign,
1371 CertTypeRSASign,
1372 CertTypeECDSASign,
1373 },
1374 },
1375 flags: []string{
1376 "-expect-certificate-types",
1377 base64.StdEncoding.EncodeToString([]byte{
1378 CertTypeDSSSign,
1379 CertTypeRSASign,
1380 CertTypeECDSASign,
1381 }),
1382 },
1383 },
1384 {
Adam Langley7c803a62015-06-15 15:35:05 -07001385 name: "UnauthenticatedECDH",
1386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001387 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001388 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1389 Bugs: ProtocolBugs{
1390 UnauthenticatedECDH: true,
1391 },
1392 },
1393 shouldFail: true,
1394 expectedError: ":UNEXPECTED_MESSAGE:",
1395 },
1396 {
1397 name: "SkipCertificateStatus",
1398 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001399 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001400 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1401 Bugs: ProtocolBugs{
1402 SkipCertificateStatus: true,
1403 },
1404 },
1405 flags: []string{
1406 "-enable-ocsp-stapling",
1407 },
1408 },
1409 {
1410 name: "SkipServerKeyExchange",
1411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001412 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1414 Bugs: ProtocolBugs{
1415 SkipServerKeyExchange: true,
1416 },
1417 },
1418 shouldFail: true,
1419 expectedError: ":UNEXPECTED_MESSAGE:",
1420 },
1421 {
Adam Langley7c803a62015-06-15 15:35:05 -07001422 testType: serverTest,
1423 name: "Alert",
1424 config: Config{
1425 Bugs: ProtocolBugs{
1426 SendSpuriousAlert: alertRecordOverflow,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1431 },
1432 {
1433 protocol: dtls,
1434 testType: serverTest,
1435 name: "Alert-DTLS",
1436 config: Config{
1437 Bugs: ProtocolBugs{
1438 SendSpuriousAlert: alertRecordOverflow,
1439 },
1440 },
1441 shouldFail: true,
1442 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1443 },
1444 {
1445 testType: serverTest,
1446 name: "FragmentAlert",
1447 config: Config{
1448 Bugs: ProtocolBugs{
1449 FragmentAlert: true,
1450 SendSpuriousAlert: alertRecordOverflow,
1451 },
1452 },
1453 shouldFail: true,
1454 expectedError: ":BAD_ALERT:",
1455 },
1456 {
1457 protocol: dtls,
1458 testType: serverTest,
1459 name: "FragmentAlert-DTLS",
1460 config: Config{
1461 Bugs: ProtocolBugs{
1462 FragmentAlert: true,
1463 SendSpuriousAlert: alertRecordOverflow,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":BAD_ALERT:",
1468 },
1469 {
1470 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001471 name: "DoubleAlert",
1472 config: Config{
1473 Bugs: ProtocolBugs{
1474 DoubleAlert: true,
1475 SendSpuriousAlert: alertRecordOverflow,
1476 },
1477 },
1478 shouldFail: true,
1479 expectedError: ":BAD_ALERT:",
1480 },
1481 {
1482 protocol: dtls,
1483 testType: serverTest,
1484 name: "DoubleAlert-DTLS",
1485 config: Config{
1486 Bugs: ProtocolBugs{
1487 DoubleAlert: true,
1488 SendSpuriousAlert: alertRecordOverflow,
1489 },
1490 },
1491 shouldFail: true,
1492 expectedError: ":BAD_ALERT:",
1493 },
1494 {
Adam Langley7c803a62015-06-15 15:35:05 -07001495 name: "SkipNewSessionTicket",
1496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001497 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001498 Bugs: ProtocolBugs{
1499 SkipNewSessionTicket: true,
1500 },
1501 },
1502 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001503 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001504 },
1505 {
1506 testType: serverTest,
1507 name: "FallbackSCSV",
1508 config: Config{
1509 MaxVersion: VersionTLS11,
1510 Bugs: ProtocolBugs{
1511 SendFallbackSCSV: true,
1512 },
1513 },
David Benjamin56cadc32016-12-16 19:54:11 -05001514 shouldFail: true,
1515 expectedError: ":INAPPROPRIATE_FALLBACK:",
1516 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001517 },
1518 {
1519 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001520 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001521 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001522 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001523 Bugs: ProtocolBugs{
1524 SendFallbackSCSV: true,
1525 },
1526 },
1527 },
1528 {
1529 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001530 name: "FallbackSCSV-VersionMatch-TLS12",
1531 config: Config{
1532 MaxVersion: VersionTLS12,
1533 Bugs: ProtocolBugs{
1534 SendFallbackSCSV: true,
1535 },
1536 },
1537 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1538 },
1539 {
1540 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001541 name: "FragmentedClientVersion",
1542 config: Config{
1543 Bugs: ProtocolBugs{
1544 MaxHandshakeRecordLength: 1,
1545 FragmentClientVersion: true,
1546 },
1547 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001548 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001549 },
1550 {
Adam Langley7c803a62015-06-15 15:35:05 -07001551 testType: serverTest,
1552 name: "HttpGET",
1553 sendPrefix: "GET / HTTP/1.0\n",
1554 shouldFail: true,
1555 expectedError: ":HTTP_REQUEST:",
1556 },
1557 {
1558 testType: serverTest,
1559 name: "HttpPOST",
1560 sendPrefix: "POST / HTTP/1.0\n",
1561 shouldFail: true,
1562 expectedError: ":HTTP_REQUEST:",
1563 },
1564 {
1565 testType: serverTest,
1566 name: "HttpHEAD",
1567 sendPrefix: "HEAD / HTTP/1.0\n",
1568 shouldFail: true,
1569 expectedError: ":HTTP_REQUEST:",
1570 },
1571 {
1572 testType: serverTest,
1573 name: "HttpPUT",
1574 sendPrefix: "PUT / HTTP/1.0\n",
1575 shouldFail: true,
1576 expectedError: ":HTTP_REQUEST:",
1577 },
1578 {
1579 testType: serverTest,
1580 name: "HttpCONNECT",
1581 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1582 shouldFail: true,
1583 expectedError: ":HTTPS_PROXY_REQUEST:",
1584 },
1585 {
1586 testType: serverTest,
1587 name: "Garbage",
1588 sendPrefix: "blah",
1589 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001590 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001591 },
1592 {
Adam Langley7c803a62015-06-15 15:35:05 -07001593 name: "RSAEphemeralKey",
1594 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001595 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001596 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1597 Bugs: ProtocolBugs{
1598 RSAEphemeralKey: true,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":UNEXPECTED_MESSAGE:",
1603 },
1604 {
1605 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001606 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001607 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001608 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001609 },
1610 {
1611 protocol: dtls,
1612 name: "DisableEverything-DTLS",
1613 flags: []string{"-no-tls12", "-no-tls1"},
1614 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001615 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001616 },
1617 {
Adam Langley7c803a62015-06-15 15:35:05 -07001618 protocol: dtls,
1619 testType: serverTest,
1620 name: "MTU",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 MaxPacketLength: 256,
1624 },
1625 },
1626 flags: []string{"-mtu", "256"},
1627 },
1628 {
1629 protocol: dtls,
1630 testType: serverTest,
1631 name: "MTUExceeded",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 MaxPacketLength: 255,
1635 },
1636 },
1637 flags: []string{"-mtu", "256"},
1638 shouldFail: true,
1639 expectedLocalError: "dtls: exceeded maximum packet length",
1640 },
1641 {
Adam Langley7c803a62015-06-15 15:35:05 -07001642 name: "EmptyCertificateList",
1643 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001644 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001645 Bugs: ProtocolBugs{
1646 EmptyCertificateList: true,
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":DECODE_ERROR:",
1651 },
1652 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001653 name: "EmptyCertificateList-TLS13",
1654 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001655 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001656 Bugs: ProtocolBugs{
1657 EmptyCertificateList: true,
1658 },
1659 },
1660 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001661 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001662 },
1663 {
Adam Langley7c803a62015-06-15 15:35:05 -07001664 name: "TLSFatalBadPackets",
1665 damageFirstWrite: true,
1666 shouldFail: true,
1667 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1668 },
1669 {
1670 protocol: dtls,
1671 name: "DTLSIgnoreBadPackets",
1672 damageFirstWrite: true,
1673 },
1674 {
1675 protocol: dtls,
1676 name: "DTLSIgnoreBadPackets-Async",
1677 damageFirstWrite: true,
1678 flags: []string{"-async"},
1679 },
1680 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001681 name: "AppDataBeforeHandshake",
1682 config: Config{
1683 Bugs: ProtocolBugs{
1684 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1685 },
1686 },
1687 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001688 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001689 },
1690 {
1691 name: "AppDataBeforeHandshake-Empty",
1692 config: Config{
1693 Bugs: ProtocolBugs{
1694 AppDataBeforeHandshake: []byte{},
1695 },
1696 },
1697 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001698 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001699 },
1700 {
1701 protocol: dtls,
1702 name: "AppDataBeforeHandshake-DTLS",
1703 config: Config{
1704 Bugs: ProtocolBugs{
1705 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1706 },
1707 },
1708 shouldFail: true,
1709 expectedError: ":UNEXPECTED_RECORD:",
1710 },
1711 {
1712 protocol: dtls,
1713 name: "AppDataBeforeHandshake-DTLS-Empty",
1714 config: Config{
1715 Bugs: ProtocolBugs{
1716 AppDataBeforeHandshake: []byte{},
1717 },
1718 },
1719 shouldFail: true,
1720 expectedError: ":UNEXPECTED_RECORD:",
1721 },
1722 {
Adam Langley7c803a62015-06-15 15:35:05 -07001723 name: "AppDataAfterChangeCipherSpec",
1724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001725 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001726 Bugs: ProtocolBugs{
1727 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1728 },
1729 },
1730 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001731 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001732 },
1733 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001734 name: "AppDataAfterChangeCipherSpec-Empty",
1735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001736 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001737 Bugs: ProtocolBugs{
1738 AppDataAfterChangeCipherSpec: []byte{},
1739 },
1740 },
1741 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001742 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001743 },
1744 {
Adam Langley7c803a62015-06-15 15:35:05 -07001745 protocol: dtls,
1746 name: "AppDataAfterChangeCipherSpec-DTLS",
1747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001748 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001749 Bugs: ProtocolBugs{
1750 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1751 },
1752 },
1753 // BoringSSL's DTLS implementation will drop the out-of-order
1754 // application data.
1755 },
1756 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001757 protocol: dtls,
1758 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1759 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001760 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001761 Bugs: ProtocolBugs{
1762 AppDataAfterChangeCipherSpec: []byte{},
1763 },
1764 },
1765 // BoringSSL's DTLS implementation will drop the out-of-order
1766 // application data.
1767 },
1768 {
Adam Langley7c803a62015-06-15 15:35:05 -07001769 name: "AlertAfterChangeCipherSpec",
1770 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001771 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001772 Bugs: ProtocolBugs{
1773 AlertAfterChangeCipherSpec: alertRecordOverflow,
1774 },
1775 },
1776 shouldFail: true,
1777 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1778 },
1779 {
1780 protocol: dtls,
1781 name: "AlertAfterChangeCipherSpec-DTLS",
1782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001783 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001784 Bugs: ProtocolBugs{
1785 AlertAfterChangeCipherSpec: alertRecordOverflow,
1786 },
1787 },
1788 shouldFail: true,
1789 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1790 },
1791 {
1792 protocol: dtls,
1793 name: "ReorderHandshakeFragments-Small-DTLS",
1794 config: Config{
1795 Bugs: ProtocolBugs{
1796 ReorderHandshakeFragments: true,
1797 // Small enough that every handshake message is
1798 // fragmented.
1799 MaxHandshakeRecordLength: 2,
1800 },
1801 },
1802 },
1803 {
1804 protocol: dtls,
1805 name: "ReorderHandshakeFragments-Large-DTLS",
1806 config: Config{
1807 Bugs: ProtocolBugs{
1808 ReorderHandshakeFragments: true,
1809 // Large enough that no handshake message is
1810 // fragmented.
1811 MaxHandshakeRecordLength: 2048,
1812 },
1813 },
1814 },
1815 {
1816 protocol: dtls,
1817 name: "MixCompleteMessageWithFragments-DTLS",
1818 config: Config{
1819 Bugs: ProtocolBugs{
1820 ReorderHandshakeFragments: true,
1821 MixCompleteMessageWithFragments: true,
1822 MaxHandshakeRecordLength: 2,
1823 },
1824 },
1825 },
1826 {
1827 name: "SendInvalidRecordType",
1828 config: Config{
1829 Bugs: ProtocolBugs{
1830 SendInvalidRecordType: true,
1831 },
1832 },
1833 shouldFail: true,
1834 expectedError: ":UNEXPECTED_RECORD:",
1835 },
1836 {
1837 protocol: dtls,
1838 name: "SendInvalidRecordType-DTLS",
1839 config: Config{
1840 Bugs: ProtocolBugs{
1841 SendInvalidRecordType: true,
1842 },
1843 },
1844 shouldFail: true,
1845 expectedError: ":UNEXPECTED_RECORD:",
1846 },
1847 {
1848 name: "FalseStart-SkipServerSecondLeg",
1849 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001850 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1852 NextProtos: []string{"foo"},
1853 Bugs: ProtocolBugs{
1854 SkipNewSessionTicket: true,
1855 SkipChangeCipherSpec: true,
1856 SkipFinished: true,
1857 ExpectFalseStart: true,
1858 },
1859 },
1860 flags: []string{
1861 "-false-start",
1862 "-handshake-never-done",
1863 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001864 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001865 },
1866 shimWritesFirst: true,
1867 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001868 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001869 },
1870 {
1871 name: "FalseStart-SkipServerSecondLeg-Implicit",
1872 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001873 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1875 NextProtos: []string{"foo"},
1876 Bugs: ProtocolBugs{
1877 SkipNewSessionTicket: true,
1878 SkipChangeCipherSpec: true,
1879 SkipFinished: true,
1880 },
1881 },
1882 flags: []string{
1883 "-implicit-handshake",
1884 "-false-start",
1885 "-handshake-never-done",
1886 "-advertise-alpn", "\x03foo",
1887 },
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 testType: serverTest,
1893 name: "FailEarlyCallback",
1894 flags: []string{"-fail-early-callback"},
1895 shouldFail: true,
1896 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001897 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001898 },
1899 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001900 name: "FailCertCallback-Client-TLS12",
1901 config: Config{
1902 MaxVersion: VersionTLS12,
1903 ClientAuth: RequestClientCert,
1904 },
1905 flags: []string{"-fail-cert-callback"},
1906 shouldFail: true,
1907 expectedError: ":CERT_CB_ERROR:",
1908 expectedLocalError: "remote error: internal error",
1909 },
1910 {
1911 testType: serverTest,
1912 name: "FailCertCallback-Server-TLS12",
1913 config: Config{
1914 MaxVersion: VersionTLS12,
1915 },
1916 flags: []string{"-fail-cert-callback"},
1917 shouldFail: true,
1918 expectedError: ":CERT_CB_ERROR:",
1919 expectedLocalError: "remote error: internal error",
1920 },
1921 {
1922 name: "FailCertCallback-Client-TLS13",
1923 config: Config{
1924 MaxVersion: VersionTLS13,
1925 ClientAuth: RequestClientCert,
1926 },
1927 flags: []string{"-fail-cert-callback"},
1928 shouldFail: true,
1929 expectedError: ":CERT_CB_ERROR:",
1930 expectedLocalError: "remote error: internal error",
1931 },
1932 {
1933 testType: serverTest,
1934 name: "FailCertCallback-Server-TLS13",
1935 config: Config{
1936 MaxVersion: VersionTLS13,
1937 },
1938 flags: []string{"-fail-cert-callback"},
1939 shouldFail: true,
1940 expectedError: ":CERT_CB_ERROR:",
1941 expectedLocalError: "remote error: internal error",
1942 },
1943 {
Adam Langley7c803a62015-06-15 15:35:05 -07001944 protocol: dtls,
1945 name: "FragmentMessageTypeMismatch-DTLS",
1946 config: Config{
1947 Bugs: ProtocolBugs{
1948 MaxHandshakeRecordLength: 2,
1949 FragmentMessageTypeMismatch: true,
1950 },
1951 },
1952 shouldFail: true,
1953 expectedError: ":FRAGMENT_MISMATCH:",
1954 },
1955 {
1956 protocol: dtls,
1957 name: "FragmentMessageLengthMismatch-DTLS",
1958 config: Config{
1959 Bugs: ProtocolBugs{
1960 MaxHandshakeRecordLength: 2,
1961 FragmentMessageLengthMismatch: true,
1962 },
1963 },
1964 shouldFail: true,
1965 expectedError: ":FRAGMENT_MISMATCH:",
1966 },
1967 {
1968 protocol: dtls,
1969 name: "SplitFragments-Header-DTLS",
1970 config: Config{
1971 Bugs: ProtocolBugs{
1972 SplitFragments: 2,
1973 },
1974 },
1975 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001976 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001977 },
1978 {
1979 protocol: dtls,
1980 name: "SplitFragments-Boundary-DTLS",
1981 config: Config{
1982 Bugs: ProtocolBugs{
1983 SplitFragments: dtlsRecordHeaderLen,
1984 },
1985 },
1986 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001987 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001988 },
1989 {
1990 protocol: dtls,
1991 name: "SplitFragments-Body-DTLS",
1992 config: Config{
1993 Bugs: ProtocolBugs{
1994 SplitFragments: dtlsRecordHeaderLen + 1,
1995 },
1996 },
1997 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001998 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001999 },
2000 {
2001 protocol: dtls,
2002 name: "SendEmptyFragments-DTLS",
2003 config: Config{
2004 Bugs: ProtocolBugs{
2005 SendEmptyFragments: true,
2006 },
2007 },
2008 },
2009 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002010 name: "BadFinished-Client",
2011 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002012 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002013 Bugs: ProtocolBugs{
2014 BadFinished: true,
2015 },
2016 },
2017 shouldFail: true,
2018 expectedError: ":DIGEST_CHECK_FAILED:",
2019 },
2020 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002021 name: "BadFinished-Client-TLS13",
2022 config: Config{
2023 MaxVersion: VersionTLS13,
2024 Bugs: ProtocolBugs{
2025 BadFinished: true,
2026 },
2027 },
2028 shouldFail: true,
2029 expectedError: ":DIGEST_CHECK_FAILED:",
2030 },
2031 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002032 testType: serverTest,
2033 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002035 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002036 Bugs: ProtocolBugs{
2037 BadFinished: true,
2038 },
2039 },
2040 shouldFail: true,
2041 expectedError: ":DIGEST_CHECK_FAILED:",
2042 },
2043 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002044 testType: serverTest,
2045 name: "BadFinished-Server-TLS13",
2046 config: Config{
2047 MaxVersion: VersionTLS13,
2048 Bugs: ProtocolBugs{
2049 BadFinished: true,
2050 },
2051 },
2052 shouldFail: true,
2053 expectedError: ":DIGEST_CHECK_FAILED:",
2054 },
2055 {
Adam Langley7c803a62015-06-15 15:35:05 -07002056 name: "FalseStart-BadFinished",
2057 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002058 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2060 NextProtos: []string{"foo"},
2061 Bugs: ProtocolBugs{
2062 BadFinished: true,
2063 ExpectFalseStart: true,
2064 },
2065 },
2066 flags: []string{
2067 "-false-start",
2068 "-handshake-never-done",
2069 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002070 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002071 },
2072 shimWritesFirst: true,
2073 shouldFail: true,
2074 expectedError: ":DIGEST_CHECK_FAILED:",
2075 },
2076 {
2077 name: "NoFalseStart-NoALPN",
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 Bugs: ProtocolBugs{
2082 ExpectFalseStart: true,
2083 AlertBeforeFalseStartTest: alertAccessDenied,
2084 },
2085 },
2086 flags: []string{
2087 "-false-start",
2088 },
2089 shimWritesFirst: true,
2090 shouldFail: true,
2091 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2092 expectedLocalError: "tls: peer did not false start: EOF",
2093 },
2094 {
2095 name: "NoFalseStart-NoAEAD",
2096 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002097 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2099 NextProtos: []string{"foo"},
2100 Bugs: ProtocolBugs{
2101 ExpectFalseStart: true,
2102 AlertBeforeFalseStartTest: alertAccessDenied,
2103 },
2104 },
2105 flags: []string{
2106 "-false-start",
2107 "-advertise-alpn", "\x03foo",
2108 },
2109 shimWritesFirst: true,
2110 shouldFail: true,
2111 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2112 expectedLocalError: "tls: peer did not false start: EOF",
2113 },
2114 {
2115 name: "NoFalseStart-RSA",
2116 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002117 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002118 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2119 NextProtos: []string{"foo"},
2120 Bugs: ProtocolBugs{
2121 ExpectFalseStart: true,
2122 AlertBeforeFalseStartTest: alertAccessDenied,
2123 },
2124 },
2125 flags: []string{
2126 "-false-start",
2127 "-advertise-alpn", "\x03foo",
2128 },
2129 shimWritesFirst: true,
2130 shouldFail: true,
2131 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2132 expectedLocalError: "tls: peer did not false start: EOF",
2133 },
2134 {
Adam Langley7c803a62015-06-15 15:35:05 -07002135 protocol: dtls,
2136 name: "SendSplitAlert-Sync",
2137 config: Config{
2138 Bugs: ProtocolBugs{
2139 SendSplitAlert: true,
2140 },
2141 },
2142 },
2143 {
2144 protocol: dtls,
2145 name: "SendSplitAlert-Async",
2146 config: Config{
2147 Bugs: ProtocolBugs{
2148 SendSplitAlert: true,
2149 },
2150 },
2151 flags: []string{"-async"},
2152 },
2153 {
2154 protocol: dtls,
2155 name: "PackDTLSHandshake",
2156 config: Config{
2157 Bugs: ProtocolBugs{
2158 MaxHandshakeRecordLength: 2,
2159 PackHandshakeFragments: 20,
2160 PackHandshakeRecords: 200,
2161 },
2162 },
2163 },
2164 {
Adam Langley7c803a62015-06-15 15:35:05 -07002165 name: "SendEmptyRecords-Pass",
2166 sendEmptyRecords: 32,
2167 },
2168 {
2169 name: "SendEmptyRecords",
2170 sendEmptyRecords: 33,
2171 shouldFail: true,
2172 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2173 },
2174 {
2175 name: "SendEmptyRecords-Async",
2176 sendEmptyRecords: 33,
2177 flags: []string{"-async"},
2178 shouldFail: true,
2179 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2180 },
2181 {
David Benjamine8e84b92016-08-03 15:39:47 -04002182 name: "SendWarningAlerts-Pass",
2183 config: Config{
2184 MaxVersion: VersionTLS12,
2185 },
Adam Langley7c803a62015-06-15 15:35:05 -07002186 sendWarningAlerts: 4,
2187 },
2188 {
David Benjamine8e84b92016-08-03 15:39:47 -04002189 protocol: dtls,
2190 name: "SendWarningAlerts-DTLS-Pass",
2191 config: Config{
2192 MaxVersion: VersionTLS12,
2193 },
Adam Langley7c803a62015-06-15 15:35:05 -07002194 sendWarningAlerts: 4,
2195 },
2196 {
David Benjamine8e84b92016-08-03 15:39:47 -04002197 name: "SendWarningAlerts-TLS13",
2198 config: Config{
2199 MaxVersion: VersionTLS13,
2200 },
2201 sendWarningAlerts: 4,
2202 shouldFail: true,
2203 expectedError: ":BAD_ALERT:",
2204 expectedLocalError: "remote error: error decoding message",
2205 },
2206 {
2207 name: "SendWarningAlerts",
2208 config: Config{
2209 MaxVersion: VersionTLS12,
2210 },
Adam Langley7c803a62015-06-15 15:35:05 -07002211 sendWarningAlerts: 5,
2212 shouldFail: true,
2213 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2214 },
2215 {
David Benjamine8e84b92016-08-03 15:39:47 -04002216 name: "SendWarningAlerts-Async",
2217 config: Config{
2218 MaxVersion: VersionTLS12,
2219 },
Adam Langley7c803a62015-06-15 15:35:05 -07002220 sendWarningAlerts: 5,
2221 flags: []string{"-async"},
2222 shouldFail: true,
2223 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2224 },
David Benjaminba4594a2015-06-18 18:36:15 -04002225 {
David Benjamin24e58862017-06-14 18:45:29 -04002226 name: "SendBogusAlertType",
2227 sendBogusAlertType: true,
2228 shouldFail: true,
2229 expectedError: ":UNKNOWN_ALERT_TYPE:",
2230 expectedLocalError: "remote error: illegal parameter",
2231 },
2232 {
2233 protocol: dtls,
2234 name: "SendBogusAlertType-DTLS",
2235 sendBogusAlertType: true,
2236 shouldFail: true,
2237 expectedError: ":UNKNOWN_ALERT_TYPE:",
2238 expectedLocalError: "remote error: illegal parameter",
2239 },
2240 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002241 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002242 config: Config{
2243 MaxVersion: VersionTLS13,
2244 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002245 sendKeyUpdates: 33,
2246 keyUpdateRequest: keyUpdateNotRequested,
2247 shouldFail: true,
2248 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002249 },
2250 {
David Benjaminba4594a2015-06-18 18:36:15 -04002251 name: "EmptySessionID",
2252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002253 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002254 SessionTicketsDisabled: true,
2255 },
2256 noSessionCache: true,
2257 flags: []string{"-expect-no-session"},
2258 },
David Benjamin30789da2015-08-29 22:56:45 -04002259 {
2260 name: "Unclean-Shutdown",
2261 config: Config{
2262 Bugs: ProtocolBugs{
2263 NoCloseNotify: true,
2264 ExpectCloseNotify: true,
2265 },
2266 },
2267 shimShutsDown: true,
2268 flags: []string{"-check-close-notify"},
2269 shouldFail: true,
2270 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2271 },
2272 {
2273 name: "Unclean-Shutdown-Ignored",
2274 config: Config{
2275 Bugs: ProtocolBugs{
2276 NoCloseNotify: true,
2277 },
2278 },
2279 shimShutsDown: true,
2280 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002281 {
David Benjaminfa214e42016-05-10 17:03:10 -04002282 name: "Unclean-Shutdown-Alert",
2283 config: Config{
2284 Bugs: ProtocolBugs{
2285 SendAlertOnShutdown: alertDecompressionFailure,
2286 ExpectCloseNotify: true,
2287 },
2288 },
2289 shimShutsDown: true,
2290 flags: []string{"-check-close-notify"},
2291 shouldFail: true,
2292 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2293 },
2294 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002295 name: "LargePlaintext",
2296 config: Config{
2297 Bugs: ProtocolBugs{
2298 SendLargeRecords: true,
2299 },
2300 },
2301 messageLen: maxPlaintext + 1,
2302 shouldFail: true,
2303 expectedError: ":DATA_LENGTH_TOO_LONG:",
2304 },
2305 {
2306 protocol: dtls,
2307 name: "LargePlaintext-DTLS",
2308 config: Config{
2309 Bugs: ProtocolBugs{
2310 SendLargeRecords: true,
2311 },
2312 },
2313 messageLen: maxPlaintext + 1,
2314 shouldFail: true,
2315 expectedError: ":DATA_LENGTH_TOO_LONG:",
2316 },
2317 {
2318 name: "LargeCiphertext",
2319 config: Config{
2320 Bugs: ProtocolBugs{
2321 SendLargeRecords: true,
2322 },
2323 },
2324 messageLen: maxPlaintext * 2,
2325 shouldFail: true,
2326 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2327 },
2328 {
2329 protocol: dtls,
2330 name: "LargeCiphertext-DTLS",
2331 config: Config{
2332 Bugs: ProtocolBugs{
2333 SendLargeRecords: true,
2334 },
2335 },
2336 messageLen: maxPlaintext * 2,
2337 // Unlike the other four cases, DTLS drops records which
2338 // are invalid before authentication, so the connection
2339 // does not fail.
2340 expectMessageDropped: true,
2341 },
David Benjamindd6fed92015-10-23 17:41:12 -04002342 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002343 name: "BadHelloRequest-1",
2344 renegotiate: 1,
2345 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002346 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002347 Bugs: ProtocolBugs{
2348 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2349 },
2350 },
2351 flags: []string{
2352 "-renegotiate-freely",
2353 "-expect-total-renegotiations", "1",
2354 },
2355 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002356 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002357 },
2358 {
2359 name: "BadHelloRequest-2",
2360 renegotiate: 1,
2361 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002362 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002363 Bugs: ProtocolBugs{
2364 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2365 },
2366 },
2367 flags: []string{
2368 "-renegotiate-freely",
2369 "-expect-total-renegotiations", "1",
2370 },
2371 shouldFail: true,
2372 expectedError: ":BAD_HELLO_REQUEST:",
2373 },
David Benjaminef1b0092015-11-21 14:05:44 -05002374 {
2375 testType: serverTest,
2376 name: "SupportTicketsWithSessionID",
2377 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002378 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002379 SessionTicketsDisabled: true,
2380 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002381 resumeConfig: &Config{
2382 MaxVersion: VersionTLS12,
2383 },
David Benjaminef1b0092015-11-21 14:05:44 -05002384 resumeSession: true,
2385 },
David Benjamin02edcd02016-07-27 17:40:37 -04002386 {
2387 protocol: dtls,
2388 name: "DTLS-SendExtraFinished",
2389 config: Config{
2390 Bugs: ProtocolBugs{
2391 SendExtraFinished: true,
2392 },
2393 },
2394 shouldFail: true,
2395 expectedError: ":UNEXPECTED_RECORD:",
2396 },
2397 {
2398 protocol: dtls,
2399 name: "DTLS-SendExtraFinished-Reordered",
2400 config: Config{
2401 Bugs: ProtocolBugs{
2402 MaxHandshakeRecordLength: 2,
2403 ReorderHandshakeFragments: true,
2404 SendExtraFinished: true,
2405 },
2406 },
2407 shouldFail: true,
2408 expectedError: ":UNEXPECTED_RECORD:",
2409 },
David Benjamine97fb482016-07-29 09:23:07 -04002410 {
2411 testType: serverTest,
2412 name: "V2ClientHello-EmptyRecordPrefix",
2413 config: Config{
2414 // Choose a cipher suite that does not involve
2415 // elliptic curves, so no extensions are
2416 // involved.
2417 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002418 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002419 Bugs: ProtocolBugs{
2420 SendV2ClientHello: true,
2421 },
2422 },
2423 sendPrefix: string([]byte{
2424 byte(recordTypeHandshake),
2425 3, 1, // version
2426 0, 0, // length
2427 }),
2428 // A no-op empty record may not be sent before V2ClientHello.
2429 shouldFail: true,
2430 expectedError: ":WRONG_VERSION_NUMBER:",
2431 },
2432 {
2433 testType: serverTest,
2434 name: "V2ClientHello-WarningAlertPrefix",
2435 config: Config{
2436 // Choose a cipher suite that does not involve
2437 // elliptic curves, so no extensions are
2438 // involved.
2439 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002440 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002441 Bugs: ProtocolBugs{
2442 SendV2ClientHello: true,
2443 },
2444 },
2445 sendPrefix: string([]byte{
2446 byte(recordTypeAlert),
2447 3, 1, // version
2448 0, 2, // length
2449 alertLevelWarning, byte(alertDecompressionFailure),
2450 }),
2451 // A no-op warning alert may not be sent before V2ClientHello.
2452 shouldFail: true,
2453 expectedError: ":WRONG_VERSION_NUMBER:",
2454 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002455 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002456 name: "KeyUpdate-Client",
2457 config: Config{
2458 MaxVersion: VersionTLS13,
2459 },
2460 sendKeyUpdates: 1,
2461 keyUpdateRequest: keyUpdateNotRequested,
2462 },
2463 {
2464 testType: serverTest,
2465 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002466 config: Config{
2467 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002468 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002469 sendKeyUpdates: 1,
2470 keyUpdateRequest: keyUpdateNotRequested,
2471 },
2472 {
2473 name: "KeyUpdate-InvalidRequestMode",
2474 config: Config{
2475 MaxVersion: VersionTLS13,
2476 },
2477 sendKeyUpdates: 1,
2478 keyUpdateRequest: 42,
2479 shouldFail: true,
2480 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002481 },
David Benjaminabe94e32016-09-04 14:18:58 -04002482 {
David Benjaminbbba9392017-04-06 12:54:12 -04002483 // Test that KeyUpdates are acknowledged properly.
2484 name: "KeyUpdate-RequestACK",
2485 config: Config{
2486 MaxVersion: VersionTLS13,
2487 Bugs: ProtocolBugs{
2488 RejectUnsolicitedKeyUpdate: true,
2489 },
2490 },
2491 // Test the shim receiving many KeyUpdates in a row.
2492 sendKeyUpdates: 5,
2493 messageCount: 5,
2494 keyUpdateRequest: keyUpdateRequested,
2495 },
2496 {
2497 // Test that KeyUpdates are acknowledged properly if the
2498 // peer's KeyUpdate is discovered while a write is
2499 // pending.
2500 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2501 config: Config{
2502 MaxVersion: VersionTLS13,
2503 Bugs: ProtocolBugs{
2504 RejectUnsolicitedKeyUpdate: true,
2505 },
2506 },
2507 // Test the shim receiving many KeyUpdates in a row.
2508 sendKeyUpdates: 5,
2509 messageCount: 5,
2510 keyUpdateRequest: keyUpdateRequested,
2511 readWithUnfinishedWrite: true,
2512 flags: []string{"-async"},
2513 },
2514 {
David Benjaminabe94e32016-09-04 14:18:58 -04002515 name: "SendSNIWarningAlert",
2516 config: Config{
2517 MaxVersion: VersionTLS12,
2518 Bugs: ProtocolBugs{
2519 SendSNIWarningAlert: true,
2520 },
2521 },
2522 },
David Benjaminc241d792016-09-09 10:34:20 -04002523 {
2524 testType: serverTest,
2525 name: "ExtraCompressionMethods-TLS12",
2526 config: Config{
2527 MaxVersion: VersionTLS12,
2528 Bugs: ProtocolBugs{
2529 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2530 },
2531 },
2532 },
2533 {
2534 testType: serverTest,
2535 name: "ExtraCompressionMethods-TLS13",
2536 config: Config{
2537 MaxVersion: VersionTLS13,
2538 Bugs: ProtocolBugs{
2539 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2540 },
2541 },
2542 shouldFail: true,
2543 expectedError: ":INVALID_COMPRESSION_LIST:",
2544 expectedLocalError: "remote error: illegal parameter",
2545 },
2546 {
2547 testType: serverTest,
2548 name: "NoNullCompression-TLS12",
2549 config: Config{
2550 MaxVersion: VersionTLS12,
2551 Bugs: ProtocolBugs{
2552 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2553 },
2554 },
2555 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002556 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002557 expectedLocalError: "remote error: illegal parameter",
2558 },
2559 {
2560 testType: serverTest,
2561 name: "NoNullCompression-TLS13",
2562 config: Config{
2563 MaxVersion: VersionTLS13,
2564 Bugs: ProtocolBugs{
2565 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2566 },
2567 },
2568 shouldFail: true,
2569 expectedError: ":INVALID_COMPRESSION_LIST:",
2570 expectedLocalError: "remote error: illegal parameter",
2571 },
David Benjamin413e79e2017-07-01 10:11:53 -04002572 // Test that the client rejects invalid compression methods
2573 // from the server.
2574 {
2575 testType: clientTest,
2576 name: "InvalidCompressionMethod",
2577 config: Config{
2578 MaxVersion: VersionTLS12,
2579 Bugs: ProtocolBugs{
2580 SendCompressionMethod: 1,
2581 },
2582 },
2583 shouldFail: true,
2584 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2585 expectedLocalError: "remote error: illegal parameter",
2586 },
David Benjamin65ac9972016-09-02 21:35:25 -04002587 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002588 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002589 config: Config{
2590 MaxVersion: VersionTLS12,
2591 Bugs: ProtocolBugs{
2592 ExpectGREASE: true,
2593 },
2594 },
2595 flags: []string{"-enable-grease"},
2596 },
2597 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002598 name: "GREASE-Client-TLS13",
2599 config: Config{
2600 MaxVersion: VersionTLS13,
2601 Bugs: ProtocolBugs{
2602 ExpectGREASE: true,
2603 },
2604 },
2605 flags: []string{"-enable-grease"},
2606 },
2607 {
2608 testType: serverTest,
2609 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002610 config: Config{
2611 MaxVersion: VersionTLS13,
2612 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002613 // TLS 1.3 servers are expected to
2614 // always enable GREASE. TLS 1.3 is new,
2615 // so there is no existing ecosystem to
2616 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002617 ExpectGREASE: true,
2618 },
2619 },
David Benjamin65ac9972016-09-02 21:35:25 -04002620 },
David Benjamine3fbb362017-01-06 16:19:28 -05002621 {
2622 // Test the server so there is a large certificate as
2623 // well as application data.
2624 testType: serverTest,
2625 name: "MaxSendFragment",
2626 config: Config{
2627 Bugs: ProtocolBugs{
2628 MaxReceivePlaintext: 512,
2629 },
2630 },
2631 messageLen: 1024,
2632 flags: []string{
2633 "-max-send-fragment", "512",
2634 "-read-size", "1024",
2635 },
2636 },
2637 {
2638 // Test the server so there is a large certificate as
2639 // well as application data.
2640 testType: serverTest,
2641 name: "MaxSendFragment-TooLarge",
2642 config: Config{
2643 Bugs: ProtocolBugs{
2644 // Ensure that some of the records are
2645 // 512.
2646 MaxReceivePlaintext: 511,
2647 },
2648 },
2649 messageLen: 1024,
2650 flags: []string{
2651 "-max-send-fragment", "512",
2652 "-read-size", "1024",
2653 },
2654 shouldFail: true,
2655 expectedLocalError: "local error: record overflow",
2656 },
Adam Langley7c803a62015-06-15 15:35:05 -07002657 }
Adam Langley7c803a62015-06-15 15:35:05 -07002658 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002659
2660 // Test that very large messages can be received.
2661 cert := rsaCertificate
2662 for i := 0; i < 50; i++ {
2663 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2664 }
2665 testCases = append(testCases, testCase{
2666 name: "LargeMessage",
2667 config: Config{
2668 Certificates: []Certificate{cert},
2669 },
2670 })
2671 testCases = append(testCases, testCase{
2672 protocol: dtls,
2673 name: "LargeMessage-DTLS",
2674 config: Config{
2675 Certificates: []Certificate{cert},
2676 },
2677 })
2678
2679 // They are rejected if the maximum certificate chain length is capped.
2680 testCases = append(testCases, testCase{
2681 name: "LargeMessage-Reject",
2682 config: Config{
2683 Certificates: []Certificate{cert},
2684 },
2685 flags: []string{"-max-cert-list", "16384"},
2686 shouldFail: true,
2687 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2688 })
2689 testCases = append(testCases, testCase{
2690 protocol: dtls,
2691 name: "LargeMessage-Reject-DTLS",
2692 config: Config{
2693 Certificates: []Certificate{cert},
2694 },
2695 flags: []string{"-max-cert-list", "16384"},
2696 shouldFail: true,
2697 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2698 })
Adam Langley7c803a62015-06-15 15:35:05 -07002699}
2700
David Benjaminaa012042016-12-10 13:33:05 -05002701func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2702 const psk = "12345"
2703 const pskIdentity = "luggage combo"
2704
2705 var prefix string
2706 if protocol == dtls {
2707 if !ver.hasDTLS {
2708 return
2709 }
2710 prefix = "D"
2711 }
2712
2713 var cert Certificate
2714 var certFile string
2715 var keyFile string
2716 if hasComponent(suite.name, "ECDSA") {
2717 cert = ecdsaP256Certificate
2718 certFile = ecdsaP256CertificateFile
2719 keyFile = ecdsaP256KeyFile
2720 } else {
2721 cert = rsaCertificate
2722 certFile = rsaCertificateFile
2723 keyFile = rsaKeyFile
2724 }
2725
2726 var flags []string
2727 if hasComponent(suite.name, "PSK") {
2728 flags = append(flags,
2729 "-psk", psk,
2730 "-psk-identity", pskIdentity)
2731 }
2732 if hasComponent(suite.name, "NULL") {
2733 // NULL ciphers must be explicitly enabled.
2734 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2735 }
David Benjaminaa012042016-12-10 13:33:05 -05002736
2737 var shouldServerFail, shouldClientFail bool
2738 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2739 // BoringSSL clients accept ECDHE on SSLv3, but
2740 // a BoringSSL server will never select it
2741 // because the extension is missing.
2742 shouldServerFail = true
2743 }
2744 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2745 shouldClientFail = true
2746 shouldServerFail = true
2747 }
2748 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2749 shouldClientFail = true
2750 shouldServerFail = true
2751 }
2752 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2753 shouldClientFail = true
2754 shouldServerFail = true
2755 }
2756 if !isDTLSCipher(suite.name) && protocol == dtls {
2757 shouldClientFail = true
2758 shouldServerFail = true
2759 }
2760
2761 var sendCipherSuite uint16
2762 var expectedServerError, expectedClientError string
2763 serverCipherSuites := []uint16{suite.id}
2764 if shouldServerFail {
2765 expectedServerError = ":NO_SHARED_CIPHER:"
2766 }
2767 if shouldClientFail {
2768 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2769 // Configure the server to select ciphers as normal but
2770 // select an incompatible cipher in ServerHello.
2771 serverCipherSuites = nil
2772 sendCipherSuite = suite.id
2773 }
2774
David Benjamincdb6fe92017-02-07 16:06:48 -05002775 // For cipher suites and versions where exporters are defined, verify
2776 // that they interoperate.
2777 var exportKeyingMaterial int
2778 if ver.version > VersionSSL30 {
2779 exportKeyingMaterial = 1024
2780 }
2781
David Benjaminaa012042016-12-10 13:33:05 -05002782 testCases = append(testCases, testCase{
2783 testType: serverTest,
2784 protocol: protocol,
2785 name: prefix + ver.name + "-" + suite.name + "-server",
2786 config: Config{
2787 MinVersion: ver.version,
2788 MaxVersion: ver.version,
2789 CipherSuites: []uint16{suite.id},
2790 Certificates: []Certificate{cert},
2791 PreSharedKey: []byte(psk),
2792 PreSharedKeyIdentity: pskIdentity,
2793 Bugs: ProtocolBugs{
2794 AdvertiseAllConfiguredCiphers: true,
2795 },
2796 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002797 certFile: certFile,
2798 keyFile: keyFile,
2799 flags: flags,
2800 resumeSession: true,
2801 shouldFail: shouldServerFail,
2802 expectedError: expectedServerError,
2803 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002804 })
2805
2806 testCases = append(testCases, testCase{
2807 testType: clientTest,
2808 protocol: protocol,
2809 name: prefix + ver.name + "-" + suite.name + "-client",
2810 config: Config{
2811 MinVersion: ver.version,
2812 MaxVersion: ver.version,
2813 CipherSuites: serverCipherSuites,
2814 Certificates: []Certificate{cert},
2815 PreSharedKey: []byte(psk),
2816 PreSharedKeyIdentity: pskIdentity,
2817 Bugs: ProtocolBugs{
2818 IgnorePeerCipherPreferences: shouldClientFail,
2819 SendCipherSuite: sendCipherSuite,
2820 },
2821 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002822 flags: flags,
2823 resumeSession: true,
2824 shouldFail: shouldClientFail,
2825 expectedError: expectedClientError,
2826 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002827 })
2828
David Benjamin6f600d62016-12-21 16:06:54 -05002829 if shouldClientFail {
2830 return
2831 }
2832
2833 // Ensure the maximum record size is accepted.
2834 testCases = append(testCases, testCase{
2835 protocol: protocol,
2836 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2837 config: Config{
2838 MinVersion: ver.version,
2839 MaxVersion: ver.version,
2840 CipherSuites: []uint16{suite.id},
2841 Certificates: []Certificate{cert},
2842 PreSharedKey: []byte(psk),
2843 PreSharedKeyIdentity: pskIdentity,
2844 },
2845 flags: flags,
2846 messageLen: maxPlaintext,
2847 })
2848
2849 // Test bad records for all ciphers. Bad records are fatal in TLS
2850 // and ignored in DTLS.
2851 var shouldFail bool
2852 var expectedError string
2853 if protocol == tls {
2854 shouldFail = true
2855 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2856 }
2857
2858 testCases = append(testCases, testCase{
2859 protocol: protocol,
2860 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2861 config: Config{
2862 MinVersion: ver.version,
2863 MaxVersion: ver.version,
2864 CipherSuites: []uint16{suite.id},
2865 Certificates: []Certificate{cert},
2866 PreSharedKey: []byte(psk),
2867 PreSharedKeyIdentity: pskIdentity,
2868 },
2869 flags: flags,
2870 damageFirstWrite: true,
2871 messageLen: maxPlaintext,
2872 shouldFail: shouldFail,
2873 expectedError: expectedError,
2874 })
David Benjaminaa012042016-12-10 13:33:05 -05002875}
2876
Adam Langley95c29f32014-06-20 12:00:00 -07002877func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002878 const bogusCipher = 0xfe00
2879
Adam Langley95c29f32014-06-20 12:00:00 -07002880 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002881 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002882 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002883 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002884 }
David Benjamin2c99d282015-09-01 10:23:00 -04002885 }
Adam Langley95c29f32014-06-20 12:00:00 -07002886 }
Adam Langleya7997f12015-05-14 17:38:50 -07002887
2888 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002889 name: "NoSharedCipher",
2890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002891 MaxVersion: VersionTLS12,
2892 CipherSuites: []uint16{},
2893 },
2894 shouldFail: true,
2895 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2896 })
2897
2898 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002899 name: "NoSharedCipher-TLS13",
2900 config: Config{
2901 MaxVersion: VersionTLS13,
2902 CipherSuites: []uint16{},
2903 },
2904 shouldFail: true,
2905 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2906 })
2907
2908 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002909 name: "UnsupportedCipherSuite",
2910 config: Config{
2911 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002912 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002913 Bugs: ProtocolBugs{
2914 IgnorePeerCipherPreferences: true,
2915 },
2916 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002917 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002918 shouldFail: true,
2919 expectedError: ":WRONG_CIPHER_RETURNED:",
2920 })
2921
2922 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002923 name: "ServerHelloBogusCipher",
2924 config: Config{
2925 MaxVersion: VersionTLS12,
2926 Bugs: ProtocolBugs{
2927 SendCipherSuite: bogusCipher,
2928 },
2929 },
2930 shouldFail: true,
2931 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2932 })
2933 testCases = append(testCases, testCase{
2934 name: "ServerHelloBogusCipher-TLS13",
2935 config: Config{
2936 MaxVersion: VersionTLS13,
2937 Bugs: ProtocolBugs{
2938 SendCipherSuite: bogusCipher,
2939 },
2940 },
2941 shouldFail: true,
2942 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2943 })
2944
David Benjamin241ae832016-01-15 03:04:54 -05002945 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002946 testCases = append(testCases, testCase{
2947 testType: serverTest,
2948 name: "UnknownCipher",
2949 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002950 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002951 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002952 Bugs: ProtocolBugs{
2953 AdvertiseAllConfiguredCiphers: true,
2954 },
2955 },
2956 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002957
2958 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002959 testCases = append(testCases, testCase{
2960 testType: serverTest,
2961 name: "UnknownCipher-TLS13",
2962 config: Config{
2963 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002964 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002965 Bugs: ProtocolBugs{
2966 AdvertiseAllConfiguredCiphers: true,
2967 },
David Benjamin241ae832016-01-15 03:04:54 -05002968 },
2969 })
2970
David Benjamin78679342016-09-16 19:42:05 -04002971 // Test empty ECDHE_PSK identity hints work as expected.
2972 testCases = append(testCases, testCase{
2973 name: "EmptyECDHEPSKHint",
2974 config: Config{
2975 MaxVersion: VersionTLS12,
2976 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2977 PreSharedKey: []byte("secret"),
2978 },
2979 flags: []string{"-psk", "secret"},
2980 })
2981
2982 // Test empty PSK identity hints work as expected, even if an explicit
2983 // ServerKeyExchange is sent.
2984 testCases = append(testCases, testCase{
2985 name: "ExplicitEmptyPSKHint",
2986 config: Config{
2987 MaxVersion: VersionTLS12,
2988 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2989 PreSharedKey: []byte("secret"),
2990 Bugs: ProtocolBugs{
2991 AlwaysSendPreSharedKeyIdentityHint: true,
2992 },
2993 },
2994 flags: []string{"-psk", "secret"},
2995 })
David Benjamin69522112017-03-28 15:38:29 -05002996
2997 // Test that clients enforce that the server-sent certificate and cipher
2998 // suite match in TLS 1.2.
2999 testCases = append(testCases, testCase{
3000 name: "CertificateCipherMismatch-RSA",
3001 config: Config{
3002 MaxVersion: VersionTLS12,
3003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3004 Certificates: []Certificate{rsaCertificate},
3005 Bugs: ProtocolBugs{
3006 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3007 },
3008 },
3009 shouldFail: true,
3010 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3011 })
3012 testCases = append(testCases, testCase{
3013 name: "CertificateCipherMismatch-ECDSA",
3014 config: Config{
3015 MaxVersion: VersionTLS12,
3016 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3017 Certificates: []Certificate{ecdsaP256Certificate},
3018 Bugs: ProtocolBugs{
3019 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3020 },
3021 },
3022 shouldFail: true,
3023 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3024 })
3025 testCases = append(testCases, testCase{
3026 name: "CertificateCipherMismatch-Ed25519",
3027 config: Config{
3028 MaxVersion: VersionTLS12,
3029 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3030 Certificates: []Certificate{ed25519Certificate},
3031 Bugs: ProtocolBugs{
3032 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3033 },
3034 },
3035 shouldFail: true,
3036 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3037 })
3038
3039 // Test that servers decline to select a cipher suite which is
3040 // inconsistent with their configured certificate.
3041 testCases = append(testCases, testCase{
3042 testType: serverTest,
3043 name: "ServerCipherFilter-RSA",
3044 config: Config{
3045 MaxVersion: VersionTLS12,
3046 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3047 },
3048 flags: []string{
3049 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3050 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3051 },
3052 shouldFail: true,
3053 expectedError: ":NO_SHARED_CIPHER:",
3054 })
3055 testCases = append(testCases, testCase{
3056 testType: serverTest,
3057 name: "ServerCipherFilter-ECDSA",
3058 config: Config{
3059 MaxVersion: VersionTLS12,
3060 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3061 },
3062 flags: []string{
3063 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3064 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3065 },
3066 shouldFail: true,
3067 expectedError: ":NO_SHARED_CIPHER:",
3068 })
3069 testCases = append(testCases, testCase{
3070 testType: serverTest,
3071 name: "ServerCipherFilter-Ed25519",
3072 config: Config{
3073 MaxVersion: VersionTLS12,
3074 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3075 },
3076 flags: []string{
3077 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3078 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3079 },
3080 shouldFail: true,
3081 expectedError: ":NO_SHARED_CIPHER:",
3082 })
David Benjamin364af782017-07-01 10:35:27 -04003083
3084 // Test cipher suite negotiation works as expected. Configure a
3085 // complicated cipher suite configuration.
3086 const negotiationTestCiphers = "" +
3087 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3088 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3089 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3090 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3091 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3092 negotiationTests := []struct {
3093 ciphers []uint16
3094 expected uint16
3095 }{
3096 // Server preferences are honored, including when
3097 // equipreference groups are involved.
3098 {
3099 []uint16{
3100 TLS_RSA_WITH_AES_256_GCM_SHA384,
3101 TLS_RSA_WITH_AES_128_CBC_SHA,
3102 TLS_RSA_WITH_AES_128_GCM_SHA256,
3103 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3104 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3105 },
3106 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3107 },
3108 {
3109 []uint16{
3110 TLS_RSA_WITH_AES_256_GCM_SHA384,
3111 TLS_RSA_WITH_AES_128_CBC_SHA,
3112 TLS_RSA_WITH_AES_128_GCM_SHA256,
3113 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3114 },
3115 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3116 },
3117 {
3118 []uint16{
3119 TLS_RSA_WITH_AES_256_GCM_SHA384,
3120 TLS_RSA_WITH_AES_128_CBC_SHA,
3121 TLS_RSA_WITH_AES_128_GCM_SHA256,
3122 },
3123 TLS_RSA_WITH_AES_128_GCM_SHA256,
3124 },
3125 {
3126 []uint16{
3127 TLS_RSA_WITH_AES_256_GCM_SHA384,
3128 TLS_RSA_WITH_AES_128_CBC_SHA,
3129 },
3130 TLS_RSA_WITH_AES_128_CBC_SHA,
3131 },
3132 // Equipreference groups use the client preference.
3133 {
3134 []uint16{
3135 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3136 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3137 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3138 },
3139 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3140 },
3141 {
3142 []uint16{
3143 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3144 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3145 },
3146 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3147 },
3148 {
3149 []uint16{
3150 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3151 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3152 },
3153 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3154 },
3155 {
3156 []uint16{
3157 TLS_RSA_WITH_AES_256_GCM_SHA384,
3158 TLS_RSA_WITH_AES_256_CBC_SHA,
3159 },
3160 TLS_RSA_WITH_AES_256_GCM_SHA384,
3161 },
3162 {
3163 []uint16{
3164 TLS_RSA_WITH_AES_256_CBC_SHA,
3165 TLS_RSA_WITH_AES_256_GCM_SHA384,
3166 },
3167 TLS_RSA_WITH_AES_256_CBC_SHA,
3168 },
3169 // If there are two equipreference groups, the preferred one
3170 // takes precedence.
3171 {
3172 []uint16{
3173 TLS_RSA_WITH_AES_256_GCM_SHA384,
3174 TLS_RSA_WITH_AES_256_CBC_SHA,
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 for i, t := range negotiationTests {
3182 testCases = append(testCases, testCase{
3183 testType: serverTest,
3184 name: "CipherNegotiation-" + strconv.Itoa(i),
3185 config: Config{
3186 MaxVersion: VersionTLS12,
3187 CipherSuites: t.ciphers,
3188 },
3189 flags: []string{"-cipher", negotiationTestCiphers},
3190 expectedCipher: t.expected,
3191 })
3192 }
Adam Langley95c29f32014-06-20 12:00:00 -07003193}
3194
3195func addBadECDSASignatureTests() {
3196 for badR := BadValue(1); badR < NumBadValues; badR++ {
3197 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003198 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003199 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3200 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003201 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003202 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003203 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003204 Bugs: ProtocolBugs{
3205 BadECDSAR: badR,
3206 BadECDSAS: badS,
3207 },
3208 },
3209 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003210 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003211 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003212 testCases = append(testCases, testCase{
3213 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3214 config: Config{
3215 MaxVersion: VersionTLS13,
3216 Certificates: []Certificate{ecdsaP256Certificate},
3217 Bugs: ProtocolBugs{
3218 BadECDSAR: badR,
3219 BadECDSAS: badS,
3220 },
3221 },
3222 shouldFail: true,
3223 expectedError: ":BAD_SIGNATURE:",
3224 })
Adam Langley95c29f32014-06-20 12:00:00 -07003225 }
3226 }
3227}
3228
Adam Langley80842bd2014-06-20 12:00:00 -07003229func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003230 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003231 name: "MaxCBCPadding",
3232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003233 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003234 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3235 Bugs: ProtocolBugs{
3236 MaxPadding: true,
3237 },
3238 },
3239 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3240 })
David Benjamin025b3d32014-07-01 19:53:04 -04003241 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003242 name: "BadCBCPadding",
3243 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003244 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003245 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3246 Bugs: ProtocolBugs{
3247 PaddingFirstByteBad: true,
3248 },
3249 },
3250 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003251 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003252 })
3253 // OpenSSL previously had an issue where the first byte of padding in
3254 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003255 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003256 name: "BadCBCPadding255",
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 PaddingFirstByteBadIf255: true,
3263 },
3264 },
3265 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3266 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003267 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003268 })
3269}
3270
Kenny Root7fdeaf12014-08-05 15:23:37 -07003271func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003272 var cbcCiphers = []struct {
3273 name string
3274 cipher uint16
3275 }{
3276 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3277 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3278 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3279 }
3280 for _, t := range cbcCiphers {
3281 testCases = append(testCases, testCase{
3282 name: "CBCRecordSplitting-" + t.name,
3283 config: Config{
3284 MaxVersion: VersionTLS10,
3285 MinVersion: VersionTLS10,
3286 CipherSuites: []uint16{t.cipher},
3287 },
3288 messageLen: -1, // read until EOF
3289 resumeSession: true,
3290 flags: []string{
3291 "-async",
3292 "-write-different-record-sizes",
3293 "-cbc-record-splitting",
3294 },
3295 })
3296 testCases = append(testCases, testCase{
3297 name: "CBCRecordSplittingPartialWrite-" + t.name,
3298 config: Config{
3299 MaxVersion: VersionTLS10,
3300 MinVersion: VersionTLS10,
3301 CipherSuites: []uint16{t.cipher},
3302 },
3303 messageLen: -1, // read until EOF
3304 flags: []string{
3305 "-async",
3306 "-write-different-record-sizes",
3307 "-cbc-record-splitting",
3308 "-partial-write",
3309 },
3310 })
3311 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003312}
3313
David Benjamin636293b2014-07-08 17:59:18 -04003314func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003315 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003316 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003317 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3318 cert, err := x509.ParseCertificate(cert.Certificate[0])
3319 if err != nil {
3320 panic(err)
3321 }
3322 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003323 }
Adam Langley2ff79332017-02-28 13:45:39 -08003324 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003325
David Benjamin636293b2014-07-08 17:59:18 -04003326 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003327 testCases = append(testCases, testCase{
3328 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003329 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003330 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003331 MinVersion: ver.version,
3332 MaxVersion: ver.version,
3333 ClientAuth: RequireAnyClientCert,
3334 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003335 },
3336 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003337 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3338 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003339 },
3340 })
3341 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003342 testType: serverTest,
3343 name: ver.name + "-Server-ClientAuth-RSA",
3344 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003345 MinVersion: ver.version,
3346 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003347 Certificates: []Certificate{rsaCertificate},
3348 },
3349 flags: []string{"-require-any-client-certificate"},
3350 })
David Benjamine098ec22014-08-27 23:13:20 -04003351 if ver.version != VersionSSL30 {
3352 testCases = append(testCases, testCase{
3353 testType: serverTest,
3354 name: ver.name + "-Server-ClientAuth-ECDSA",
3355 config: Config{
3356 MinVersion: ver.version,
3357 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003358 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003359 },
3360 flags: []string{"-require-any-client-certificate"},
3361 })
3362 testCases = append(testCases, testCase{
3363 testType: clientTest,
3364 name: ver.name + "-Client-ClientAuth-ECDSA",
3365 config: Config{
3366 MinVersion: ver.version,
3367 MaxVersion: ver.version,
3368 ClientAuth: RequireAnyClientCert,
3369 ClientCAs: certPool,
3370 },
3371 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003372 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3373 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003374 },
3375 })
3376 }
Adam Langley37646832016-08-01 16:16:46 -07003377
3378 testCases = append(testCases, testCase{
3379 name: "NoClientCertificate-" + ver.name,
3380 config: Config{
3381 MinVersion: ver.version,
3382 MaxVersion: ver.version,
3383 ClientAuth: RequireAnyClientCert,
3384 },
3385 shouldFail: true,
3386 expectedLocalError: "client didn't provide a certificate",
3387 })
3388
3389 testCases = append(testCases, testCase{
3390 // Even if not configured to expect a certificate, OpenSSL will
3391 // return X509_V_OK as the verify_result.
3392 testType: serverTest,
3393 name: "NoClientCertificateRequested-Server-" + ver.name,
3394 config: Config{
3395 MinVersion: ver.version,
3396 MaxVersion: ver.version,
3397 },
3398 flags: []string{
3399 "-expect-verify-result",
3400 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003401 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003402 })
3403
3404 testCases = append(testCases, testCase{
3405 // If a client certificate is not provided, OpenSSL will still
3406 // return X509_V_OK as the verify_result.
3407 testType: serverTest,
3408 name: "NoClientCertificate-Server-" + ver.name,
3409 config: Config{
3410 MinVersion: ver.version,
3411 MaxVersion: ver.version,
3412 },
3413 flags: []string{
3414 "-expect-verify-result",
3415 "-verify-peer",
3416 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003417 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003418 })
3419
David Benjamin1db9e1b2016-10-07 20:51:43 -04003420 certificateRequired := "remote error: certificate required"
3421 if ver.version < VersionTLS13 {
3422 // Prior to TLS 1.3, the generic handshake_failure alert
3423 // was used.
3424 certificateRequired = "remote error: handshake failure"
3425 }
Adam Langley37646832016-08-01 16:16:46 -07003426 testCases = append(testCases, testCase{
3427 testType: serverTest,
3428 name: "RequireAnyClientCertificate-" + ver.name,
3429 config: Config{
3430 MinVersion: ver.version,
3431 MaxVersion: ver.version,
3432 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003433 flags: []string{"-require-any-client-certificate"},
3434 shouldFail: true,
3435 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3436 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003437 })
3438
3439 if ver.version != VersionSSL30 {
3440 testCases = append(testCases, testCase{
3441 testType: serverTest,
3442 name: "SkipClientCertificate-" + ver.name,
3443 config: Config{
3444 MinVersion: ver.version,
3445 MaxVersion: ver.version,
3446 Bugs: ProtocolBugs{
3447 SkipClientCertificate: true,
3448 },
3449 },
3450 // Setting SSL_VERIFY_PEER allows anonymous clients.
3451 flags: []string{"-verify-peer"},
3452 shouldFail: true,
3453 expectedError: ":UNEXPECTED_MESSAGE:",
3454 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003455
3456 testCases = append(testCases, testCase{
3457 testType: serverTest,
3458 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3459 config: Config{
3460 MinVersion: ver.version,
3461 MaxVersion: ver.version,
3462 },
3463 flags: []string{
3464 "-enable-channel-id",
3465 "-verify-peer-if-no-obc",
3466 },
3467 shouldFail: true,
3468 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3469 expectedLocalError: certificateRequired,
3470 })
3471
3472 testCases = append(testCases, testCase{
3473 testType: serverTest,
3474 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3475 config: Config{
3476 MinVersion: ver.version,
3477 MaxVersion: ver.version,
3478 ChannelID: channelIDKey,
3479 },
3480 expectChannelID: true,
3481 flags: []string{
3482 "-enable-channel-id",
3483 "-verify-peer-if-no-obc",
3484 },
3485 })
Adam Langley37646832016-08-01 16:16:46 -07003486 }
Adam Langley2ff79332017-02-28 13:45:39 -08003487
3488 testCases = append(testCases, testCase{
3489 testType: serverTest,
3490 name: ver.name + "-Server-CertReq-CA-List",
3491 config: Config{
3492 MinVersion: ver.version,
3493 MaxVersion: ver.version,
3494 Certificates: []Certificate{rsaCertificate},
3495 Bugs: ProtocolBugs{
3496 ExpectCertificateReqNames: caNames,
3497 },
3498 },
3499 flags: []string{
3500 "-require-any-client-certificate",
3501 "-use-client-ca-list", encodeDERValues(caNames),
3502 },
3503 })
3504
3505 testCases = append(testCases, testCase{
3506 testType: clientTest,
3507 name: ver.name + "-Client-CertReq-CA-List",
3508 config: Config{
3509 MinVersion: ver.version,
3510 MaxVersion: ver.version,
3511 Certificates: []Certificate{rsaCertificate},
3512 ClientAuth: RequireAnyClientCert,
3513 ClientCAs: certPool,
3514 },
3515 flags: []string{
3516 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3517 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3518 "-expect-client-ca-list", encodeDERValues(caNames),
3519 },
3520 })
David Benjamin636293b2014-07-08 17:59:18 -04003521 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003522
David Benjaminc032dfa2016-05-12 14:54:57 -04003523 // Client auth is only legal in certificate-based ciphers.
3524 testCases = append(testCases, testCase{
3525 testType: clientTest,
3526 name: "ClientAuth-PSK",
3527 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003528 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003529 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3530 PreSharedKey: []byte("secret"),
3531 ClientAuth: RequireAnyClientCert,
3532 },
3533 flags: []string{
3534 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3535 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3536 "-psk", "secret",
3537 },
3538 shouldFail: true,
3539 expectedError: ":UNEXPECTED_MESSAGE:",
3540 })
3541 testCases = append(testCases, testCase{
3542 testType: clientTest,
3543 name: "ClientAuth-ECDHE_PSK",
3544 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003545 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003546 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3547 PreSharedKey: []byte("secret"),
3548 ClientAuth: RequireAnyClientCert,
3549 },
3550 flags: []string{
3551 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3552 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3553 "-psk", "secret",
3554 },
3555 shouldFail: true,
3556 expectedError: ":UNEXPECTED_MESSAGE:",
3557 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003558
3559 // Regression test for a bug where the client CA list, if explicitly
3560 // set to NULL, was mis-encoded.
3561 testCases = append(testCases, testCase{
3562 testType: serverTest,
3563 name: "Null-Client-CA-List",
3564 config: Config{
3565 MaxVersion: VersionTLS12,
3566 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003567 Bugs: ProtocolBugs{
3568 ExpectCertificateReqNames: [][]byte{},
3569 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003570 },
3571 flags: []string{
3572 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003573 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003574 },
3575 })
David Benjamin636293b2014-07-08 17:59:18 -04003576}
3577
Adam Langley75712922014-10-10 16:23:43 -07003578func addExtendedMasterSecretTests() {
3579 const expectEMSFlag = "-expect-extended-master-secret"
3580
3581 for _, with := range []bool{false, true} {
3582 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003583 if with {
3584 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003585 }
3586
3587 for _, isClient := range []bool{false, true} {
3588 suffix := "-Server"
3589 testType := serverTest
3590 if isClient {
3591 suffix = "-Client"
3592 testType = clientTest
3593 }
3594
3595 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003596 // In TLS 1.3, the extension is irrelevant and
3597 // always reports as enabled.
3598 var flags []string
3599 if with || ver.version >= VersionTLS13 {
3600 flags = []string{expectEMSFlag}
3601 }
3602
Adam Langley75712922014-10-10 16:23:43 -07003603 test := testCase{
3604 testType: testType,
3605 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3606 config: Config{
3607 MinVersion: ver.version,
3608 MaxVersion: ver.version,
3609 Bugs: ProtocolBugs{
3610 NoExtendedMasterSecret: !with,
3611 RequireExtendedMasterSecret: with,
3612 },
3613 },
David Benjamin48cae082014-10-27 01:06:24 -04003614 flags: flags,
3615 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003616 }
3617 if test.shouldFail {
3618 test.expectedLocalError = "extended master secret required but not supported by peer"
3619 }
3620 testCases = append(testCases, test)
3621 }
3622 }
3623 }
3624
Adam Langleyba5934b2015-06-02 10:50:35 -07003625 for _, isClient := range []bool{false, true} {
3626 for _, supportedInFirstConnection := range []bool{false, true} {
3627 for _, supportedInResumeConnection := range []bool{false, true} {
3628 boolToWord := func(b bool) string {
3629 if b {
3630 return "Yes"
3631 }
3632 return "No"
3633 }
3634 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3635 if isClient {
3636 suffix += "Client"
3637 } else {
3638 suffix += "Server"
3639 }
3640
3641 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003642 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003643 Bugs: ProtocolBugs{
3644 RequireExtendedMasterSecret: true,
3645 },
3646 }
3647
3648 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003649 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003650 Bugs: ProtocolBugs{
3651 NoExtendedMasterSecret: true,
3652 },
3653 }
3654
3655 test := testCase{
3656 name: "ExtendedMasterSecret-" + suffix,
3657 resumeSession: true,
3658 }
3659
3660 if !isClient {
3661 test.testType = serverTest
3662 }
3663
3664 if supportedInFirstConnection {
3665 test.config = supportedConfig
3666 } else {
3667 test.config = noSupportConfig
3668 }
3669
3670 if supportedInResumeConnection {
3671 test.resumeConfig = &supportedConfig
3672 } else {
3673 test.resumeConfig = &noSupportConfig
3674 }
3675
3676 switch suffix {
3677 case "YesToYes-Client", "YesToYes-Server":
3678 // When a session is resumed, it should
3679 // still be aware that its master
3680 // secret was generated via EMS and
3681 // thus it's safe to use tls-unique.
3682 test.flags = []string{expectEMSFlag}
3683 case "NoToYes-Server":
3684 // If an original connection did not
3685 // contain EMS, but a resumption
3686 // handshake does, then a server should
3687 // not resume the session.
3688 test.expectResumeRejected = true
3689 case "YesToNo-Server":
3690 // Resuming an EMS session without the
3691 // EMS extension should cause the
3692 // server to abort the connection.
3693 test.shouldFail = true
3694 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3695 case "NoToYes-Client":
3696 // A client should abort a connection
3697 // where the server resumed a non-EMS
3698 // session but echoed the EMS
3699 // extension.
3700 test.shouldFail = true
3701 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3702 case "YesToNo-Client":
3703 // A client should abort a connection
3704 // where the server didn't echo EMS
3705 // when the session used it.
3706 test.shouldFail = true
3707 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3708 }
3709
3710 testCases = append(testCases, test)
3711 }
3712 }
3713 }
David Benjamin163c9562016-08-29 23:14:17 -04003714
3715 // Switching EMS on renegotiation is forbidden.
3716 testCases = append(testCases, testCase{
3717 name: "ExtendedMasterSecret-Renego-NoEMS",
3718 config: Config{
3719 MaxVersion: VersionTLS12,
3720 Bugs: ProtocolBugs{
3721 NoExtendedMasterSecret: true,
3722 NoExtendedMasterSecretOnRenegotiation: true,
3723 },
3724 },
3725 renegotiate: 1,
3726 flags: []string{
3727 "-renegotiate-freely",
3728 "-expect-total-renegotiations", "1",
3729 },
3730 })
3731
3732 testCases = append(testCases, testCase{
3733 name: "ExtendedMasterSecret-Renego-Upgrade",
3734 config: Config{
3735 MaxVersion: VersionTLS12,
3736 Bugs: ProtocolBugs{
3737 NoExtendedMasterSecret: true,
3738 },
3739 },
3740 renegotiate: 1,
3741 flags: []string{
3742 "-renegotiate-freely",
3743 "-expect-total-renegotiations", "1",
3744 },
3745 shouldFail: true,
3746 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3747 })
3748
3749 testCases = append(testCases, testCase{
3750 name: "ExtendedMasterSecret-Renego-Downgrade",
3751 config: Config{
3752 MaxVersion: VersionTLS12,
3753 Bugs: ProtocolBugs{
3754 NoExtendedMasterSecretOnRenegotiation: true,
3755 },
3756 },
3757 renegotiate: 1,
3758 flags: []string{
3759 "-renegotiate-freely",
3760 "-expect-total-renegotiations", "1",
3761 },
3762 shouldFail: true,
3763 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3764 })
Adam Langley75712922014-10-10 16:23:43 -07003765}
3766
David Benjamin582ba042016-07-07 12:33:25 -07003767type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003768 protocol protocol
3769 async bool
3770 splitHandshake bool
3771 packHandshakeFlight bool
3772 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003773}
3774
David Benjamin43ec06f2014-08-05 02:28:57 -04003775// Adds tests that try to cover the range of the handshake state machine, under
3776// various conditions. Some of these are redundant with other tests, but they
3777// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003778func addAllStateMachineCoverageTests() {
3779 for _, async := range []bool{false, true} {
3780 for _, protocol := range []protocol{tls, dtls} {
3781 addStateMachineCoverageTests(stateMachineTestConfig{
3782 protocol: protocol,
3783 async: async,
3784 })
3785 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003786 protocol: protocol,
3787 async: async,
3788 implicitHandshake: true,
3789 })
3790 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003791 protocol: protocol,
3792 async: async,
3793 splitHandshake: true,
3794 })
3795 if protocol == tls {
3796 addStateMachineCoverageTests(stateMachineTestConfig{
3797 protocol: protocol,
3798 async: async,
3799 packHandshakeFlight: true,
3800 })
3801 }
3802 }
3803 }
3804}
3805
3806func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003807 var tests []testCase
3808
3809 // Basic handshake, with resumption. Client and server,
3810 // session ID and session ticket.
3811 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003812 name: "Basic-Client",
3813 config: Config{
3814 MaxVersion: VersionTLS12,
3815 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003816 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003817 // Ensure session tickets are used, not session IDs.
3818 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003819 })
3820 tests = append(tests, testCase{
3821 name: "Basic-Client-RenewTicket",
3822 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003823 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003824 Bugs: ProtocolBugs{
3825 RenewTicketOnResume: true,
3826 },
3827 },
David Benjamin46662482016-08-17 00:51:00 -04003828 flags: []string{"-expect-ticket-renewal"},
3829 resumeSession: true,
3830 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003831 })
3832 tests = append(tests, testCase{
3833 name: "Basic-Client-NoTicket",
3834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003835 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003836 SessionTicketsDisabled: true,
3837 },
3838 resumeSession: true,
3839 })
3840 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003841 testType: serverTest,
3842 name: "Basic-Server",
3843 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003844 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003845 Bugs: ProtocolBugs{
3846 RequireSessionTickets: true,
3847 },
3848 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003849 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003850 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003851 })
3852 tests = append(tests, testCase{
3853 testType: serverTest,
3854 name: "Basic-Server-NoTickets",
3855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003856 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003857 SessionTicketsDisabled: true,
3858 },
3859 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003860 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003861 })
3862 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003863 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003864 name: "Basic-Server-EarlyCallback",
3865 config: Config{
3866 MaxVersion: VersionTLS12,
3867 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003868 flags: []string{"-use-early-callback"},
3869 resumeSession: true,
3870 })
3871
Steven Valdez143e8b32016-07-11 13:19:03 -04003872 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003873 if config.protocol == tls {
3874 tests = append(tests, testCase{
3875 name: "TLS13-1RTT-Client",
3876 config: Config{
3877 MaxVersion: VersionTLS13,
3878 MinVersion: VersionTLS13,
3879 },
David Benjamin46662482016-08-17 00:51:00 -04003880 resumeSession: true,
3881 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003882 })
3883
3884 tests = append(tests, testCase{
3885 testType: serverTest,
3886 name: "TLS13-1RTT-Server",
3887 config: Config{
3888 MaxVersion: VersionTLS13,
3889 MinVersion: VersionTLS13,
3890 },
David Benjamin46662482016-08-17 00:51:00 -04003891 resumeSession: true,
3892 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003893 // TLS 1.3 uses tickets, so the session should not be
3894 // cached statefully.
3895 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003896 })
3897
3898 tests = append(tests, testCase{
3899 name: "TLS13-HelloRetryRequest-Client",
3900 config: Config{
3901 MaxVersion: VersionTLS13,
3902 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003903 // P-384 requires a HelloRetryRequest against BoringSSL's default
3904 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003905 CurvePreferences: []CurveID{CurveP384},
3906 Bugs: ProtocolBugs{
3907 ExpectMissingKeyShare: true,
3908 },
3909 },
3910 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3911 resumeSession: true,
3912 })
3913
3914 tests = append(tests, testCase{
3915 testType: serverTest,
3916 name: "TLS13-HelloRetryRequest-Server",
3917 config: Config{
3918 MaxVersion: VersionTLS13,
3919 MinVersion: VersionTLS13,
3920 // Require a HelloRetryRequest for every curve.
3921 DefaultCurves: []CurveID{},
3922 },
3923 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3924 resumeSession: true,
3925 })
Steven Valdez2d850622017-01-11 11:34:52 -05003926
Steven Valdez2d850622017-01-11 11:34:52 -05003927 tests = append(tests, testCase{
3928 testType: clientTest,
3929 name: "TLS13-EarlyData-Client",
3930 config: Config{
3931 MaxVersion: VersionTLS13,
3932 MinVersion: VersionTLS13,
3933 MaxEarlyDataSize: 16384,
3934 },
Steven Valdeze831a812017-03-09 14:56:07 -05003935 resumeConfig: &Config{
3936 MaxVersion: VersionTLS13,
3937 MinVersion: VersionTLS13,
3938 MaxEarlyDataSize: 16384,
3939 Bugs: ProtocolBugs{
3940 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3941 },
3942 },
Steven Valdez2d850622017-01-11 11:34:52 -05003943 resumeSession: true,
3944 flags: []string{
3945 "-enable-early-data",
3946 "-expect-early-data-info",
3947 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003948 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003949 },
3950 })
3951
3952 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003953 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04003954 name: "TLS13Experiment-EarlyData-Client",
3955 config: Config{
3956 MaxVersion: VersionTLS13,
3957 MinVersion: VersionTLS13,
3958 TLS13Variant: TLS13Experiment,
3959 MaxEarlyDataSize: 16384,
3960 },
3961 resumeConfig: &Config{
3962 MaxVersion: VersionTLS13,
3963 MinVersion: VersionTLS13,
3964 TLS13Variant: TLS13Experiment,
3965 MaxEarlyDataSize: 16384,
3966 Bugs: ProtocolBugs{
3967 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3968 },
3969 },
3970 resumeSession: true,
3971 flags: []string{
3972 "-enable-early-data",
3973 "-expect-early-data-info",
3974 "-expect-accept-early-data",
3975 "-on-resume-shim-writes-first",
3976 "-tls13-variant", "1",
3977 },
3978 })
3979
3980 tests = append(tests, testCase{
3981 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05003982 name: "TLS13-EarlyData-TooMuchData-Client",
3983 config: Config{
3984 MaxVersion: VersionTLS13,
3985 MinVersion: VersionTLS13,
3986 MaxEarlyDataSize: 2,
3987 },
3988 resumeConfig: &Config{
3989 MaxVersion: VersionTLS13,
3990 MinVersion: VersionTLS13,
3991 MaxEarlyDataSize: 2,
3992 Bugs: ProtocolBugs{
3993 ExpectEarlyData: [][]byte{{'h', 'e'}},
3994 },
3995 },
3996 resumeShimPrefix: "llo",
3997 resumeSession: true,
3998 flags: []string{
3999 "-enable-early-data",
4000 "-expect-early-data-info",
4001 "-expect-accept-early-data",
4002 "-on-resume-shim-writes-first",
4003 },
4004 })
4005
4006 // Unfinished writes can only be tested when operations are async. EarlyData
4007 // can't be tested as part of an ImplicitHandshake in this case since
4008 // otherwise the early data will be sent as normal data.
4009 if config.async && !config.implicitHandshake {
4010 tests = append(tests, testCase{
4011 testType: clientTest,
4012 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4013 config: Config{
4014 MaxVersion: VersionTLS13,
4015 MinVersion: VersionTLS13,
4016 MaxEarlyDataSize: 16384,
4017 },
4018 resumeConfig: &Config{
4019 MaxVersion: VersionTLS13,
4020 MinVersion: VersionTLS13,
4021 MaxEarlyDataSize: 16384,
4022 Bugs: ProtocolBugs{
4023 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4024 },
4025 },
4026 resumeSession: true,
4027 flags: []string{
4028 "-enable-early-data",
4029 "-expect-early-data-info",
4030 "-expect-accept-early-data",
4031 "-on-resume-read-with-unfinished-write",
4032 "-on-resume-shim-writes-first",
4033 },
4034 })
4035
4036 // Rejected unfinished writes are discarded (from the
4037 // perspective of the calling application) on 0-RTT
4038 // reject.
4039 tests = append(tests, testCase{
4040 testType: clientTest,
4041 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4042 config: Config{
4043 MaxVersion: VersionTLS13,
4044 MinVersion: VersionTLS13,
4045 MaxEarlyDataSize: 16384,
4046 },
4047 resumeConfig: &Config{
4048 MaxVersion: VersionTLS13,
4049 MinVersion: VersionTLS13,
4050 MaxEarlyDataSize: 16384,
4051 Bugs: ProtocolBugs{
4052 AlwaysRejectEarlyData: true,
4053 },
4054 },
4055 resumeSession: true,
4056 flags: []string{
4057 "-enable-early-data",
4058 "-expect-early-data-info",
4059 "-expect-reject-early-data",
4060 "-on-resume-read-with-unfinished-write",
4061 "-on-resume-shim-writes-first",
4062 },
4063 })
4064 }
4065
4066 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004067 testType: serverTest,
4068 name: "TLS13-EarlyData-Server",
4069 config: Config{
4070 MaxVersion: VersionTLS13,
4071 MinVersion: VersionTLS13,
4072 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004073 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004074 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004075 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004076 },
4077 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004078 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004079 resumeSession: true,
4080 flags: []string{
4081 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004082 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004083 },
4084 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004085
4086 tests = append(tests, testCase{
4087 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004088 name: "TLS13Experiment-EarlyData-Server",
4089 config: Config{
4090 MaxVersion: VersionTLS13,
4091 MinVersion: VersionTLS13,
4092 TLS13Variant: TLS13Experiment,
4093 Bugs: ProtocolBugs{
4094 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4095 ExpectEarlyDataAccepted: true,
4096 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4097 },
4098 },
4099 messageCount: 2,
4100 resumeSession: true,
4101 flags: []string{
4102 "-enable-early-data",
4103 "-expect-accept-early-data",
4104 "-tls13-variant", "1",
4105 },
4106 })
4107
4108 tests = append(tests, testCase{
4109 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004110 name: "TLS13-MaxEarlyData-Server",
4111 config: Config{
4112 MaxVersion: VersionTLS13,
4113 MinVersion: VersionTLS13,
4114 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004115 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004116 ExpectEarlyDataAccepted: true,
4117 },
4118 },
4119 messageCount: 2,
4120 resumeSession: true,
4121 flags: []string{
4122 "-enable-early-data",
4123 "-expect-accept-early-data",
4124 },
4125 shouldFail: true,
4126 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4127 })
David Benjamine73c7f42016-08-17 00:29:33 -04004128 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004129
David Benjamin760b1dd2015-05-15 23:33:48 -04004130 // TLS client auth.
4131 tests = append(tests, testCase{
4132 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004133 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004135 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004136 ClientAuth: RequestClientCert,
4137 },
4138 })
4139 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004140 testType: serverTest,
4141 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004142 config: Config{
4143 MaxVersion: VersionTLS12,
4144 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004145 // Setting SSL_VERIFY_PEER allows anonymous clients.
4146 flags: []string{"-verify-peer"},
4147 })
David Benjamin582ba042016-07-07 12:33:25 -07004148 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004149 tests = append(tests, testCase{
4150 testType: clientTest,
4151 name: "ClientAuth-NoCertificate-Client-SSL3",
4152 config: Config{
4153 MaxVersion: VersionSSL30,
4154 ClientAuth: RequestClientCert,
4155 },
4156 })
4157 tests = append(tests, testCase{
4158 testType: serverTest,
4159 name: "ClientAuth-NoCertificate-Server-SSL3",
4160 config: Config{
4161 MaxVersion: VersionSSL30,
4162 },
4163 // Setting SSL_VERIFY_PEER allows anonymous clients.
4164 flags: []string{"-verify-peer"},
4165 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004166 tests = append(tests, testCase{
4167 testType: clientTest,
4168 name: "ClientAuth-NoCertificate-Client-TLS13",
4169 config: Config{
4170 MaxVersion: VersionTLS13,
4171 ClientAuth: RequestClientCert,
4172 },
4173 })
4174 tests = append(tests, testCase{
4175 testType: serverTest,
4176 name: "ClientAuth-NoCertificate-Server-TLS13",
4177 config: Config{
4178 MaxVersion: VersionTLS13,
4179 },
4180 // Setting SSL_VERIFY_PEER allows anonymous clients.
4181 flags: []string{"-verify-peer"},
4182 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004183 }
4184 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004185 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004186 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004188 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004189 ClientAuth: RequireAnyClientCert,
4190 },
4191 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004192 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4193 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004194 },
4195 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004196 tests = append(tests, testCase{
4197 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004198 name: "ClientAuth-RSA-Client-TLS13",
4199 config: Config{
4200 MaxVersion: VersionTLS13,
4201 ClientAuth: RequireAnyClientCert,
4202 },
4203 flags: []string{
4204 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4205 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4206 },
4207 })
4208 tests = append(tests, testCase{
4209 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004210 name: "ClientAuth-ECDSA-Client",
4211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004212 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004213 ClientAuth: RequireAnyClientCert,
4214 },
4215 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004216 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4217 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004218 },
4219 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004220 tests = append(tests, testCase{
4221 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004222 name: "ClientAuth-ECDSA-Client-TLS13",
4223 config: Config{
4224 MaxVersion: VersionTLS13,
4225 ClientAuth: RequireAnyClientCert,
4226 },
4227 flags: []string{
4228 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4229 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4230 },
4231 })
4232 tests = append(tests, testCase{
4233 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004234 name: "ClientAuth-NoCertificate-OldCallback",
4235 config: Config{
4236 MaxVersion: VersionTLS12,
4237 ClientAuth: RequestClientCert,
4238 },
4239 flags: []string{"-use-old-client-cert-callback"},
4240 })
4241 tests = append(tests, testCase{
4242 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004243 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4244 config: Config{
4245 MaxVersion: VersionTLS13,
4246 ClientAuth: RequestClientCert,
4247 },
4248 flags: []string{"-use-old-client-cert-callback"},
4249 })
4250 tests = append(tests, testCase{
4251 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004252 name: "ClientAuth-OldCallback",
4253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004254 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004255 ClientAuth: RequireAnyClientCert,
4256 },
4257 flags: []string{
4258 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4259 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4260 "-use-old-client-cert-callback",
4261 },
4262 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004263 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004264 testType: clientTest,
4265 name: "ClientAuth-OldCallback-TLS13",
4266 config: Config{
4267 MaxVersion: VersionTLS13,
4268 ClientAuth: RequireAnyClientCert,
4269 },
4270 flags: []string{
4271 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4272 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4273 "-use-old-client-cert-callback",
4274 },
4275 })
4276 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004277 testType: serverTest,
4278 name: "ClientAuth-Server",
4279 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004280 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004281 Certificates: []Certificate{rsaCertificate},
4282 },
4283 flags: []string{"-require-any-client-certificate"},
4284 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004285 tests = append(tests, testCase{
4286 testType: serverTest,
4287 name: "ClientAuth-Server-TLS13",
4288 config: Config{
4289 MaxVersion: VersionTLS13,
4290 Certificates: []Certificate{rsaCertificate},
4291 },
4292 flags: []string{"-require-any-client-certificate"},
4293 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004294
David Benjamin4c3ddf72016-06-29 18:13:53 -04004295 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004296 tests = append(tests, testCase{
4297 testType: serverTest,
4298 name: "Basic-Server-RSA",
4299 config: Config{
4300 MaxVersion: VersionTLS12,
4301 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4302 },
4303 flags: []string{
4304 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4305 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4306 },
4307 })
4308 tests = append(tests, testCase{
4309 testType: serverTest,
4310 name: "Basic-Server-ECDHE-RSA",
4311 config: Config{
4312 MaxVersion: VersionTLS12,
4313 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4314 },
4315 flags: []string{
4316 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4317 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4318 },
4319 })
4320 tests = append(tests, testCase{
4321 testType: serverTest,
4322 name: "Basic-Server-ECDHE-ECDSA",
4323 config: Config{
4324 MaxVersion: VersionTLS12,
4325 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4326 },
4327 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004328 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4329 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004330 },
4331 })
David Benjamin69522112017-03-28 15:38:29 -05004332 tests = append(tests, testCase{
4333 testType: serverTest,
4334 name: "Basic-Server-Ed25519",
4335 config: Config{
4336 MaxVersion: VersionTLS12,
4337 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4338 },
4339 flags: []string{
4340 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4341 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4342 "-enable-ed25519",
4343 },
4344 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004345
David Benjamin760b1dd2015-05-15 23:33:48 -04004346 // No session ticket support; server doesn't send NewSessionTicket.
4347 tests = append(tests, testCase{
4348 name: "SessionTicketsDisabled-Client",
4349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004350 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004351 SessionTicketsDisabled: true,
4352 },
4353 })
4354 tests = append(tests, testCase{
4355 testType: serverTest,
4356 name: "SessionTicketsDisabled-Server",
4357 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004358 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004359 SessionTicketsDisabled: true,
4360 },
4361 })
4362
4363 // Skip ServerKeyExchange in PSK key exchange if there's no
4364 // identity hint.
4365 tests = append(tests, testCase{
4366 name: "EmptyPSKHint-Client",
4367 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004368 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004369 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4370 PreSharedKey: []byte("secret"),
4371 },
4372 flags: []string{"-psk", "secret"},
4373 })
4374 tests = append(tests, testCase{
4375 testType: serverTest,
4376 name: "EmptyPSKHint-Server",
4377 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004378 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004379 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4380 PreSharedKey: []byte("secret"),
4381 },
4382 flags: []string{"-psk", "secret"},
4383 })
4384
David Benjamin4c3ddf72016-06-29 18:13:53 -04004385 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004386 tests = append(tests, testCase{
4387 testType: clientTest,
4388 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004389 config: Config{
4390 MaxVersion: VersionTLS12,
4391 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004392 flags: []string{
4393 "-enable-ocsp-stapling",
4394 "-expect-ocsp-response",
4395 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004396 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004397 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004398 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004399 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004400 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004401 testType: serverTest,
4402 name: "OCSPStapling-Server",
4403 config: Config{
4404 MaxVersion: VersionTLS12,
4405 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004406 expectedOCSPResponse: testOCSPResponse,
4407 flags: []string{
4408 "-ocsp-response",
4409 base64.StdEncoding.EncodeToString(testOCSPResponse),
4410 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004411 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004412 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004413 tests = append(tests, testCase{
4414 testType: clientTest,
4415 name: "OCSPStapling-Client-TLS13",
4416 config: Config{
4417 MaxVersion: VersionTLS13,
4418 },
4419 flags: []string{
4420 "-enable-ocsp-stapling",
4421 "-expect-ocsp-response",
4422 base64.StdEncoding.EncodeToString(testOCSPResponse),
4423 "-verify-peer",
4424 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004425 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004426 })
4427 tests = append(tests, testCase{
4428 testType: serverTest,
4429 name: "OCSPStapling-Server-TLS13",
4430 config: Config{
4431 MaxVersion: VersionTLS13,
4432 },
4433 expectedOCSPResponse: testOCSPResponse,
4434 flags: []string{
4435 "-ocsp-response",
4436 base64.StdEncoding.EncodeToString(testOCSPResponse),
4437 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004438 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004439 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004440
David Benjamin4c3ddf72016-06-29 18:13:53 -04004441 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004442 for _, vers := range tlsVersions {
4443 if config.protocol == dtls && !vers.hasDTLS {
4444 continue
4445 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004446 for _, testType := range []testType{clientTest, serverTest} {
4447 suffix := "-Client"
4448 if testType == serverTest {
4449 suffix = "-Server"
4450 }
4451 suffix += "-" + vers.name
4452
4453 flag := "-verify-peer"
4454 if testType == serverTest {
4455 flag = "-require-any-client-certificate"
4456 }
4457
4458 tests = append(tests, testCase{
4459 testType: testType,
4460 name: "CertificateVerificationSucceed" + suffix,
4461 config: Config{
4462 MaxVersion: vers.version,
4463 Certificates: []Certificate{rsaCertificate},
4464 },
4465 flags: []string{
4466 flag,
4467 "-expect-verify-result",
4468 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004469 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004470 })
4471 tests = append(tests, testCase{
4472 testType: testType,
4473 name: "CertificateVerificationFail" + suffix,
4474 config: Config{
4475 MaxVersion: vers.version,
4476 Certificates: []Certificate{rsaCertificate},
4477 },
4478 flags: []string{
4479 flag,
4480 "-verify-fail",
4481 },
4482 shouldFail: true,
4483 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4484 })
4485 }
4486
4487 // By default, the client is in a soft fail mode where the peer
4488 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004489 tests = append(tests, testCase{
4490 testType: clientTest,
4491 name: "CertificateVerificationSoftFail-" + vers.name,
4492 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004493 MaxVersion: vers.version,
4494 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004495 },
4496 flags: []string{
4497 "-verify-fail",
4498 "-expect-verify-result",
4499 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004500 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004501 })
4502 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004503
David Benjamin1d4f4c02016-07-26 18:03:08 -04004504 tests = append(tests, testCase{
4505 name: "ShimSendAlert",
4506 flags: []string{"-send-alert"},
4507 shimWritesFirst: true,
4508 shouldFail: true,
4509 expectedLocalError: "remote error: decompression failure",
4510 })
4511
David Benjamin582ba042016-07-07 12:33:25 -07004512 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004513 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004514 name: "Renegotiate-Client",
4515 config: Config{
4516 MaxVersion: VersionTLS12,
4517 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004518 renegotiate: 1,
4519 flags: []string{
4520 "-renegotiate-freely",
4521 "-expect-total-renegotiations", "1",
4522 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004523 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004524
David Benjamin47921102016-07-28 11:29:18 -04004525 tests = append(tests, testCase{
4526 name: "SendHalfHelloRequest",
4527 config: Config{
4528 MaxVersion: VersionTLS12,
4529 Bugs: ProtocolBugs{
4530 PackHelloRequestWithFinished: config.packHandshakeFlight,
4531 },
4532 },
4533 sendHalfHelloRequest: true,
4534 flags: []string{"-renegotiate-ignore"},
4535 shouldFail: true,
4536 expectedError: ":UNEXPECTED_RECORD:",
4537 })
4538
David Benjamin760b1dd2015-05-15 23:33:48 -04004539 // NPN on client and server; results in post-handshake message.
4540 tests = append(tests, testCase{
4541 name: "NPN-Client",
4542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004543 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004544 NextProtos: []string{"foo"},
4545 },
4546 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004547 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004548 expectedNextProto: "foo",
4549 expectedNextProtoType: npn,
4550 })
4551 tests = append(tests, testCase{
4552 testType: serverTest,
4553 name: "NPN-Server",
4554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004555 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004556 NextProtos: []string{"bar"},
4557 },
4558 flags: []string{
4559 "-advertise-npn", "\x03foo\x03bar\x03baz",
4560 "-expect-next-proto", "bar",
4561 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004562 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004563 expectedNextProto: "bar",
4564 expectedNextProtoType: npn,
4565 })
4566
4567 // TODO(davidben): Add tests for when False Start doesn't trigger.
4568
4569 // Client does False Start and negotiates NPN.
4570 tests = append(tests, testCase{
4571 name: "FalseStart",
4572 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004573 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004574 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4575 NextProtos: []string{"foo"},
4576 Bugs: ProtocolBugs{
4577 ExpectFalseStart: true,
4578 },
4579 },
4580 flags: []string{
4581 "-false-start",
4582 "-select-next-proto", "foo",
4583 },
4584 shimWritesFirst: true,
4585 resumeSession: true,
4586 })
4587
4588 // Client does False Start and negotiates ALPN.
4589 tests = append(tests, testCase{
4590 name: "FalseStart-ALPN",
4591 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004592 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004593 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4594 NextProtos: []string{"foo"},
4595 Bugs: ProtocolBugs{
4596 ExpectFalseStart: true,
4597 },
4598 },
4599 flags: []string{
4600 "-false-start",
4601 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004602 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004603 },
4604 shimWritesFirst: true,
4605 resumeSession: true,
4606 })
4607
David Benjamin760b1dd2015-05-15 23:33:48 -04004608 // False Start without session tickets.
4609 tests = append(tests, testCase{
4610 name: "FalseStart-SessionTicketsDisabled",
4611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004612 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004613 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4614 NextProtos: []string{"foo"},
4615 SessionTicketsDisabled: true,
4616 Bugs: ProtocolBugs{
4617 ExpectFalseStart: true,
4618 },
4619 },
4620 flags: []string{
4621 "-false-start",
4622 "-select-next-proto", "foo",
4623 },
4624 shimWritesFirst: true,
4625 })
4626
4627 // Server parses a V2ClientHello.
4628 tests = append(tests, testCase{
4629 testType: serverTest,
4630 name: "SendV2ClientHello",
4631 config: Config{
4632 // Choose a cipher suite that does not involve
4633 // elliptic curves, so no extensions are
4634 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004635 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004636 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004637 Bugs: ProtocolBugs{
4638 SendV2ClientHello: true,
4639 },
4640 },
4641 })
4642
Nick Harper60a85cb2016-09-23 16:25:11 -07004643 // Test Channel ID
4644 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004645 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004646 continue
4647 }
4648 // Client sends a Channel ID.
4649 tests = append(tests, testCase{
4650 name: "ChannelID-Client-" + ver.name,
4651 config: Config{
4652 MaxVersion: ver.version,
4653 RequestChannelID: true,
4654 },
4655 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4656 resumeSession: true,
4657 expectChannelID: true,
4658 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004659
Nick Harper60a85cb2016-09-23 16:25:11 -07004660 // Server accepts a Channel ID.
4661 tests = append(tests, testCase{
4662 testType: serverTest,
4663 name: "ChannelID-Server-" + ver.name,
4664 config: Config{
4665 MaxVersion: ver.version,
4666 ChannelID: channelIDKey,
4667 },
4668 flags: []string{
4669 "-expect-channel-id",
4670 base64.StdEncoding.EncodeToString(channelIDBytes),
4671 },
4672 resumeSession: true,
4673 expectChannelID: true,
4674 })
4675
4676 tests = append(tests, testCase{
4677 testType: serverTest,
4678 name: "InvalidChannelIDSignature-" + ver.name,
4679 config: Config{
4680 MaxVersion: ver.version,
4681 ChannelID: channelIDKey,
4682 Bugs: ProtocolBugs{
4683 InvalidChannelIDSignature: true,
4684 },
4685 },
4686 flags: []string{"-enable-channel-id"},
4687 shouldFail: true,
4688 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4689 })
David Benjamin634f4752017-07-01 11:08:41 -04004690
4691 if ver.version < VersionTLS13 {
4692 // Channel ID requires ECDHE ciphers.
4693 tests = append(tests, testCase{
4694 testType: serverTest,
4695 name: "ChannelID-NoECDHE-" + ver.name,
4696 config: Config{
4697 MaxVersion: ver.version,
4698 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4699 ChannelID: channelIDKey,
4700 },
4701 expectChannelID: false,
4702 flags: []string{"-enable-channel-id"},
4703 })
4704
4705 // Sanity-check setting expectChannelID false works.
4706 tests = append(tests, testCase{
4707 testType: serverTest,
4708 name: "ChannelID-ECDHE-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4712 ChannelID: channelIDKey,
4713 },
4714 expectChannelID: false,
4715 flags: []string{"-enable-channel-id"},
4716 shouldFail: true,
4717 expectedLocalError: "channel ID unexpectedly negotiated",
4718 })
4719 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004720 }
David Benjamin30789da2015-08-29 22:56:45 -04004721
David Benjaminf8fcdf32016-06-08 15:56:13 -04004722 // Channel ID and NPN at the same time, to ensure their relative
4723 // ordering is correct.
4724 tests = append(tests, testCase{
4725 name: "ChannelID-NPN-Client",
4726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004727 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004728 RequestChannelID: true,
4729 NextProtos: []string{"foo"},
4730 },
4731 flags: []string{
4732 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4733 "-select-next-proto", "foo",
4734 },
4735 resumeSession: true,
4736 expectChannelID: true,
4737 expectedNextProto: "foo",
4738 expectedNextProtoType: npn,
4739 })
4740 tests = append(tests, testCase{
4741 testType: serverTest,
4742 name: "ChannelID-NPN-Server",
4743 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004744 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004745 ChannelID: channelIDKey,
4746 NextProtos: []string{"bar"},
4747 },
4748 flags: []string{
4749 "-expect-channel-id",
4750 base64.StdEncoding.EncodeToString(channelIDBytes),
4751 "-advertise-npn", "\x03foo\x03bar\x03baz",
4752 "-expect-next-proto", "bar",
4753 },
4754 resumeSession: true,
4755 expectChannelID: true,
4756 expectedNextProto: "bar",
4757 expectedNextProtoType: npn,
4758 })
4759
David Benjamin30789da2015-08-29 22:56:45 -04004760 // Bidirectional shutdown with the runner initiating.
4761 tests = append(tests, testCase{
4762 name: "Shutdown-Runner",
4763 config: Config{
4764 Bugs: ProtocolBugs{
4765 ExpectCloseNotify: true,
4766 },
4767 },
4768 flags: []string{"-check-close-notify"},
4769 })
4770
David Benjamine3843d42017-03-25 18:00:56 -05004771 if !config.implicitHandshake {
4772 // Bidirectional shutdown with the shim initiating. The runner,
4773 // in the meantime, sends garbage before the close_notify which
4774 // the shim must ignore. This test is disabled under implicit
4775 // handshake tests because the shim never reads or writes.
4776 tests = append(tests, testCase{
4777 name: "Shutdown-Shim",
4778 config: Config{
4779 MaxVersion: VersionTLS12,
4780 Bugs: ProtocolBugs{
4781 ExpectCloseNotify: true,
4782 },
David Benjamin30789da2015-08-29 22:56:45 -04004783 },
David Benjamine3843d42017-03-25 18:00:56 -05004784 shimShutsDown: true,
4785 sendEmptyRecords: 1,
4786 sendWarningAlerts: 1,
4787 flags: []string{"-check-close-notify"},
4788 })
4789 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004790 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004791 // TODO(davidben): DTLS 1.3 will want a similar thing for
4792 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004793 tests = append(tests, testCase{
4794 name: "SkipHelloVerifyRequest",
4795 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004796 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004797 Bugs: ProtocolBugs{
4798 SkipHelloVerifyRequest: true,
4799 },
4800 },
4801 })
4802 }
4803
David Benjamin760b1dd2015-05-15 23:33:48 -04004804 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004805 test.protocol = config.protocol
4806 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004807 test.name += "-DTLS"
4808 }
David Benjamin582ba042016-07-07 12:33:25 -07004809 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004810 test.name += "-Async"
4811 test.flags = append(test.flags, "-async")
4812 } else {
4813 test.name += "-Sync"
4814 }
David Benjamin582ba042016-07-07 12:33:25 -07004815 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004816 test.name += "-SplitHandshakeRecords"
4817 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004818 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004819 test.config.Bugs.MaxPacketLength = 256
4820 test.flags = append(test.flags, "-mtu", "256")
4821 }
4822 }
David Benjamin582ba042016-07-07 12:33:25 -07004823 if config.packHandshakeFlight {
4824 test.name += "-PackHandshakeFlight"
4825 test.config.Bugs.PackHandshakeFlight = true
4826 }
David Benjamine3843d42017-03-25 18:00:56 -05004827 if config.implicitHandshake {
4828 test.name += "-ImplicitHandshake"
4829 test.flags = append(test.flags, "-implicit-handshake")
4830 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004831 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004832 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004833}
4834
Adam Langley524e7172015-02-20 16:04:00 -08004835func addDDoSCallbackTests() {
4836 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004837 for _, resume := range []bool{false, true} {
4838 suffix := "Resume"
4839 if resume {
4840 suffix = "No" + suffix
4841 }
4842
4843 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004844 testType: serverTest,
4845 name: "Server-DDoS-OK-" + suffix,
4846 config: Config{
4847 MaxVersion: VersionTLS12,
4848 },
Adam Langley524e7172015-02-20 16:04:00 -08004849 flags: []string{"-install-ddos-callback"},
4850 resumeSession: resume,
4851 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004852 testCases = append(testCases, testCase{
4853 testType: serverTest,
4854 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4855 config: Config{
4856 MaxVersion: VersionTLS13,
4857 },
4858 flags: []string{"-install-ddos-callback"},
4859 resumeSession: resume,
4860 })
Adam Langley524e7172015-02-20 16:04:00 -08004861
4862 failFlag := "-fail-ddos-callback"
4863 if resume {
4864 failFlag = "-fail-second-ddos-callback"
4865 }
4866 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004867 testType: serverTest,
4868 name: "Server-DDoS-Reject-" + suffix,
4869 config: Config{
4870 MaxVersion: VersionTLS12,
4871 },
David Benjamin2c66e072016-09-16 15:58:00 -04004872 flags: []string{"-install-ddos-callback", failFlag},
4873 resumeSession: resume,
4874 shouldFail: true,
4875 expectedError: ":CONNECTION_REJECTED:",
4876 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004877 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4881 config: Config{
4882 MaxVersion: VersionTLS13,
4883 },
David Benjamin2c66e072016-09-16 15:58:00 -04004884 flags: []string{"-install-ddos-callback", failFlag},
4885 resumeSession: resume,
4886 shouldFail: true,
4887 expectedError: ":CONNECTION_REJECTED:",
4888 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004889 })
Adam Langley524e7172015-02-20 16:04:00 -08004890 }
4891}
4892
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004893func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04004894 for _, protocol := range []protocol{tls, dtls} {
4895 for _, shimVers := range allVersions(protocol) {
4896 // Assemble flags to disable all newer versions on the shim.
4897 var flags []string
4898 for _, vers := range allVersions(protocol) {
4899 if vers.version > shimVers.version {
4900 flags = append(flags, vers.excludeFlag)
4901 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004902 }
Steven Valdez520e1222017-06-13 12:45:25 -04004903
4904 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
4905
4906 if shimVers.tls13Variant != 0 {
4907 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
4908 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
4909 }
4910
4911 // Test configuring the runner's maximum version.
4912 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05004913 expectedVersion := shimVers.version
4914 if runnerVers.version < shimVers.version {
4915 expectedVersion = runnerVers.version
4916 }
Steven Valdez520e1222017-06-13 12:45:25 -04004917 // When running and shim have different TLS 1.3 variants enabled,
4918 // shim clients are expected to fall back to TLS 1.2, while shim
4919 // servers support both variants when enabled when the experiment is
4920 // enabled.
4921 expectedServerVersion := expectedVersion
4922 expectedClientVersion := expectedVersion
4923 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
4924 expectedClientVersion = VersionTLS12
4925 expectedServerVersion = VersionTLS12
4926 if shimVers.tls13Variant != TLS13Default {
4927 expectedServerVersion = VersionTLS13
4928 }
4929 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004930
David Benjamin8b8c0062014-11-23 02:47:52 -05004931 suffix := shimVers.name + "-" + runnerVers.name
4932 if protocol == dtls {
4933 suffix += "-DTLS"
4934 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004935
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004936 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004937 clientVers := shimVers.version
4938 if clientVers > VersionTLS10 {
4939 clientVers = VersionTLS10
4940 }
Steven Valdez520e1222017-06-13 12:45:25 -04004941 clientVers = recordVersionToWire(clientVers, protocol)
4942 serverVers := expectedServerVersion
4943 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07004944 serverVers = VersionTLS10
4945 }
Steven Valdez520e1222017-06-13 12:45:25 -04004946 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004947
David Benjamin8b8c0062014-11-23 02:47:52 -05004948 testCases = append(testCases, testCase{
4949 protocol: protocol,
4950 testType: clientTest,
4951 name: "VersionNegotiation-Client-" + suffix,
4952 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04004953 MaxVersion: runnerVers.version,
4954 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004955 Bugs: ProtocolBugs{
4956 ExpectInitialRecordVersion: clientVers,
4957 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004958 },
4959 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04004960 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05004961 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004962 testCases = append(testCases, testCase{
4963 protocol: protocol,
4964 testType: clientTest,
4965 name: "VersionNegotiation-Client2-" + suffix,
4966 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04004967 MaxVersion: runnerVers.version,
4968 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05004969 Bugs: ProtocolBugs{
4970 ExpectInitialRecordVersion: clientVers,
4971 },
4972 },
Steven Valdez520e1222017-06-13 12:45:25 -04004973 flags: flags2,
4974 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05004975 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004976
4977 testCases = append(testCases, testCase{
4978 protocol: protocol,
4979 testType: serverTest,
4980 name: "VersionNegotiation-Server-" + suffix,
4981 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04004982 MaxVersion: runnerVers.version,
4983 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004984 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004985 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004986 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004987 },
4988 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04004989 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05004990 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004991 testCases = append(testCases, testCase{
4992 protocol: protocol,
4993 testType: serverTest,
4994 name: "VersionNegotiation-Server2-" + suffix,
4995 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04004996 MaxVersion: runnerVers.version,
4997 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05004998 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004999 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005000 },
5001 },
Steven Valdez520e1222017-06-13 12:45:25 -04005002 flags: flags2,
5003 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005004 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005005 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005006 }
5007 }
David Benjamin95c69562016-06-29 18:15:03 -04005008
Steven Valdezfdd10992016-09-15 16:27:05 -04005009 // Test the version extension at all versions.
5010 for _, vers := range tlsVersions {
5011 protocols := []protocol{tls}
5012 if vers.hasDTLS {
5013 protocols = append(protocols, dtls)
5014 }
5015 for _, protocol := range protocols {
5016 suffix := vers.name
5017 if protocol == dtls {
5018 suffix += "-DTLS"
5019 }
5020
Steven Valdezfdd10992016-09-15 16:27:05 -04005021 testCases = append(testCases, testCase{
5022 protocol: protocol,
5023 testType: serverTest,
5024 name: "VersionNegotiationExtension-" + suffix,
5025 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005026 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005027 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005028 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005029 },
5030 },
5031 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005032 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005033 })
5034 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005035 }
5036
5037 // If all versions are unknown, negotiation fails.
5038 testCases = append(testCases, testCase{
5039 testType: serverTest,
5040 name: "NoSupportedVersions",
5041 config: Config{
5042 Bugs: ProtocolBugs{
5043 SendSupportedVersions: []uint16{0x1111},
5044 },
5045 },
5046 shouldFail: true,
5047 expectedError: ":UNSUPPORTED_PROTOCOL:",
5048 })
5049 testCases = append(testCases, testCase{
5050 protocol: dtls,
5051 testType: serverTest,
5052 name: "NoSupportedVersions-DTLS",
5053 config: Config{
5054 Bugs: ProtocolBugs{
5055 SendSupportedVersions: []uint16{0x1111},
5056 },
5057 },
5058 shouldFail: true,
5059 expectedError: ":UNSUPPORTED_PROTOCOL:",
5060 })
5061
5062 testCases = append(testCases, testCase{
5063 testType: serverTest,
5064 name: "ClientHelloVersionTooHigh",
5065 config: Config{
5066 MaxVersion: VersionTLS13,
5067 Bugs: ProtocolBugs{
5068 SendClientVersion: 0x0304,
5069 OmitSupportedVersions: true,
5070 },
5071 },
5072 expectedVersion: VersionTLS12,
5073 })
5074
5075 testCases = append(testCases, testCase{
5076 testType: serverTest,
5077 name: "ConflictingVersionNegotiation",
5078 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005079 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005080 SendClientVersion: VersionTLS12,
5081 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005082 },
5083 },
David Benjaminad75a662016-09-30 15:42:59 -04005084 // The extension takes precedence over the ClientHello version.
5085 expectedVersion: VersionTLS11,
5086 })
5087
5088 testCases = append(testCases, testCase{
5089 testType: serverTest,
5090 name: "ConflictingVersionNegotiation-2",
5091 config: Config{
5092 Bugs: ProtocolBugs{
5093 SendClientVersion: VersionTLS11,
5094 SendSupportedVersions: []uint16{VersionTLS12},
5095 },
5096 },
5097 // The extension takes precedence over the ClientHello version.
5098 expectedVersion: VersionTLS12,
5099 })
5100
5101 testCases = append(testCases, testCase{
5102 testType: serverTest,
5103 name: "RejectFinalTLS13",
5104 config: Config{
5105 Bugs: ProtocolBugs{
5106 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5107 },
5108 },
5109 // We currently implement a draft TLS 1.3 version. Ensure that
5110 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005111 expectedVersion: VersionTLS12,
5112 })
5113
Steven Valdez038da9b2017-07-10 12:57:25 -04005114 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5115 // the ServerHello.
5116 testCases = append(testCases, testCase{
5117 testType: clientTest,
5118 name: "SupportedVersionSelection-TLS12",
5119 config: Config{
5120 MaxVersion: VersionTLS12,
5121 Bugs: ProtocolBugs{
5122 SendServerSupportedExtensionVersion: VersionTLS12,
5123 },
5124 },
5125 shouldFail: true,
5126 expectedError: ":UNEXPECTED_EXTENSION:",
5127 })
5128
5129 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5130 // supported_versions extension in the ServerHello.
5131 testCases = append(testCases, testCase{
5132 testType: clientTest,
5133 name: "SupportedVersionSelection-TLS13",
5134 config: Config{
5135 MaxVersion: VersionTLS13,
5136 Bugs: ProtocolBugs{
5137 SendServerSupportedExtensionVersion: tls13DraftVersion,
5138 },
5139 },
5140 shouldFail: true,
5141 expectedError: ":UNEXPECTED_EXTENSION:",
5142 })
5143
Brian Smithf85d3232016-10-28 10:34:06 -10005144 // Test that the maximum version is selected regardless of the
5145 // client-sent order.
5146 testCases = append(testCases, testCase{
5147 testType: serverTest,
5148 name: "IgnoreClientVersionOrder",
5149 config: Config{
5150 Bugs: ProtocolBugs{
5151 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5152 },
5153 },
5154 expectedVersion: VersionTLS13,
5155 })
5156
David Benjamin95c69562016-06-29 18:15:03 -04005157 // Test for version tolerance.
5158 testCases = append(testCases, testCase{
5159 testType: serverTest,
5160 name: "MinorVersionTolerance",
5161 config: Config{
5162 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005163 SendClientVersion: 0x03ff,
5164 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005165 },
5166 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005167 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005168 })
5169 testCases = append(testCases, testCase{
5170 testType: serverTest,
5171 name: "MajorVersionTolerance",
5172 config: Config{
5173 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005174 SendClientVersion: 0x0400,
5175 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005176 },
5177 },
David Benjaminad75a662016-09-30 15:42:59 -04005178 // TLS 1.3 must be negotiated with the supported_versions
5179 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005180 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005181 })
David Benjaminad75a662016-09-30 15:42:59 -04005182 testCases = append(testCases, testCase{
5183 testType: serverTest,
5184 name: "VersionTolerance-TLS13",
5185 config: Config{
5186 Bugs: ProtocolBugs{
5187 // Although TLS 1.3 does not use
5188 // ClientHello.version, it still tolerates high
5189 // values there.
5190 SendClientVersion: 0x0400,
5191 },
5192 },
5193 expectedVersion: VersionTLS13,
5194 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005195
David Benjamin95c69562016-06-29 18:15:03 -04005196 testCases = append(testCases, testCase{
5197 protocol: dtls,
5198 testType: serverTest,
5199 name: "MinorVersionTolerance-DTLS",
5200 config: Config{
5201 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005202 SendClientVersion: 0xfe00,
5203 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005204 },
5205 },
5206 expectedVersion: VersionTLS12,
5207 })
5208 testCases = append(testCases, testCase{
5209 protocol: dtls,
5210 testType: serverTest,
5211 name: "MajorVersionTolerance-DTLS",
5212 config: Config{
5213 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005214 SendClientVersion: 0xfdff,
5215 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005216 },
5217 },
5218 expectedVersion: VersionTLS12,
5219 })
5220
5221 // Test that versions below 3.0 are rejected.
5222 testCases = append(testCases, testCase{
5223 testType: serverTest,
5224 name: "VersionTooLow",
5225 config: Config{
5226 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005227 SendClientVersion: 0x0200,
5228 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005229 },
5230 },
5231 shouldFail: true,
5232 expectedError: ":UNSUPPORTED_PROTOCOL:",
5233 })
5234 testCases = append(testCases, testCase{
5235 protocol: dtls,
5236 testType: serverTest,
5237 name: "VersionTooLow-DTLS",
5238 config: Config{
5239 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005240 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005241 },
5242 },
5243 shouldFail: true,
5244 expectedError: ":UNSUPPORTED_PROTOCOL:",
5245 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005246
David Benjamin2dc02042016-09-19 19:57:37 -04005247 testCases = append(testCases, testCase{
5248 name: "ServerBogusVersion",
5249 config: Config{
5250 Bugs: ProtocolBugs{
5251 SendServerHelloVersion: 0x1234,
5252 },
5253 },
5254 shouldFail: true,
5255 expectedError: ":UNSUPPORTED_PROTOCOL:",
5256 })
5257
David Benjamin1f61f0d2016-07-10 12:20:35 -04005258 // Test TLS 1.3's downgrade signal.
5259 testCases = append(testCases, testCase{
5260 name: "Downgrade-TLS12-Client",
5261 config: Config{
5262 Bugs: ProtocolBugs{
5263 NegotiateVersion: VersionTLS12,
5264 },
5265 },
David Benjamin592b5322016-09-30 15:15:01 -04005266 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005267 // TODO(davidben): This test should fail once TLS 1.3 is final
5268 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005269 })
5270 testCases = append(testCases, testCase{
5271 testType: serverTest,
5272 name: "Downgrade-TLS12-Server",
5273 config: Config{
5274 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005275 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005276 },
5277 },
David Benjamin592b5322016-09-30 15:15:01 -04005278 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005279 // TODO(davidben): This test should fail once TLS 1.3 is final
5280 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005281 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005282}
5283
David Benjaminaccb4542014-12-12 23:44:33 -05005284func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005285 for _, protocol := range []protocol{tls, dtls} {
5286 for _, shimVers := range allVersions(protocol) {
5287 // Assemble flags to disable all older versions on the shim.
5288 var flags []string
5289 for _, vers := range allVersions(protocol) {
5290 if vers.version < shimVers.version {
5291 flags = append(flags, vers.excludeFlag)
5292 }
David Benjaminaccb4542014-12-12 23:44:33 -05005293 }
Steven Valdez520e1222017-06-13 12:45:25 -04005294
5295 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5296
5297 if shimVers.tls13Variant != 0 {
5298 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5299 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5300 }
5301
5302 for _, runnerVers := range allVersions(protocol) {
5303 // Different TLS 1.3 variants are incompatible with each other and don't
5304 // produce consistent minimum versions.
5305 //
5306 // TODO(davidben): Fold these tests (the main value is in the
5307 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5308 // on intended shim behavior, not the shim + runner combination.
5309 if shimVers.tls13Variant != runnerVers.tls13Variant {
5310 continue
5311 }
5312
David Benjaminaccb4542014-12-12 23:44:33 -05005313 suffix := shimVers.name + "-" + runnerVers.name
5314 if protocol == dtls {
5315 suffix += "-DTLS"
5316 }
David Benjaminaccb4542014-12-12 23:44:33 -05005317
David Benjaminaccb4542014-12-12 23:44:33 -05005318 var expectedVersion uint16
5319 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005320 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005321 if runnerVers.version >= shimVers.version {
5322 expectedVersion = runnerVers.version
5323 } else {
5324 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005325 expectedError = ":UNSUPPORTED_PROTOCOL:"
5326 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005327 }
5328
5329 testCases = append(testCases, testCase{
5330 protocol: protocol,
5331 testType: clientTest,
5332 name: "MinimumVersion-Client-" + suffix,
5333 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005334 MaxVersion: runnerVers.version,
5335 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005336 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005337 // Ensure the server does not decline to
5338 // select a version (versions extension) or
5339 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005340 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005341 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005342 },
David Benjaminaccb4542014-12-12 23:44:33 -05005343 },
David Benjamin87909c02014-12-13 01:55:01 -05005344 flags: flags,
5345 expectedVersion: expectedVersion,
5346 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005347 expectedError: expectedError,
5348 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005349 })
5350 testCases = append(testCases, testCase{
5351 protocol: protocol,
5352 testType: clientTest,
5353 name: "MinimumVersion-Client2-" + suffix,
5354 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005355 MaxVersion: runnerVers.version,
5356 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005357 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005358 // Ensure the server does not decline to
5359 // select a version (versions extension) or
5360 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005361 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005362 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005363 },
David Benjaminaccb4542014-12-12 23:44:33 -05005364 },
Steven Valdez520e1222017-06-13 12:45:25 -04005365 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005366 expectedVersion: expectedVersion,
5367 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005368 expectedError: expectedError,
5369 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005370 })
5371
5372 testCases = append(testCases, testCase{
5373 protocol: protocol,
5374 testType: serverTest,
5375 name: "MinimumVersion-Server-" + suffix,
5376 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005377 MaxVersion: runnerVers.version,
5378 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005379 },
David Benjamin87909c02014-12-13 01:55:01 -05005380 flags: flags,
5381 expectedVersion: expectedVersion,
5382 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005383 expectedError: expectedError,
5384 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005385 })
5386 testCases = append(testCases, testCase{
5387 protocol: protocol,
5388 testType: serverTest,
5389 name: "MinimumVersion-Server2-" + suffix,
5390 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005391 MaxVersion: runnerVers.version,
5392 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005393 },
Steven Valdez520e1222017-06-13 12:45:25 -04005394 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005395 expectedVersion: expectedVersion,
5396 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005397 expectedError: expectedError,
5398 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005399 })
5400 }
5401 }
5402 }
5403}
5404
David Benjamine78bfde2014-09-06 12:45:15 -04005405func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005406 // TODO(davidben): Extensions, where applicable, all move their server
5407 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5408 // tests for both. Also test interaction with 0-RTT when implemented.
5409
David Benjamin97d17d92016-07-14 16:12:00 -04005410 // Repeat extensions tests all versions except SSL 3.0.
5411 for _, ver := range tlsVersions {
5412 if ver.version == VersionSSL30 {
5413 continue
5414 }
5415
David Benjamin97d17d92016-07-14 16:12:00 -04005416 // Test that duplicate extensions are rejected.
5417 testCases = append(testCases, testCase{
5418 testType: clientTest,
5419 name: "DuplicateExtensionClient-" + ver.name,
5420 config: Config{
5421 MaxVersion: ver.version,
5422 Bugs: ProtocolBugs{
5423 DuplicateExtension: true,
5424 },
David Benjamine78bfde2014-09-06 12:45:15 -04005425 },
David Benjamin97d17d92016-07-14 16:12:00 -04005426 shouldFail: true,
5427 expectedLocalError: "remote error: error decoding message",
5428 })
5429 testCases = append(testCases, testCase{
5430 testType: serverTest,
5431 name: "DuplicateExtensionServer-" + ver.name,
5432 config: Config{
5433 MaxVersion: ver.version,
5434 Bugs: ProtocolBugs{
5435 DuplicateExtension: true,
5436 },
David Benjamine78bfde2014-09-06 12:45:15 -04005437 },
David Benjamin97d17d92016-07-14 16:12:00 -04005438 shouldFail: true,
5439 expectedLocalError: "remote error: error decoding message",
5440 })
5441
5442 // Test SNI.
5443 testCases = append(testCases, testCase{
5444 testType: clientTest,
5445 name: "ServerNameExtensionClient-" + ver.name,
5446 config: Config{
5447 MaxVersion: ver.version,
5448 Bugs: ProtocolBugs{
5449 ExpectServerName: "example.com",
5450 },
David Benjamine78bfde2014-09-06 12:45:15 -04005451 },
David Benjamin97d17d92016-07-14 16:12:00 -04005452 flags: []string{"-host-name", "example.com"},
5453 })
5454 testCases = append(testCases, testCase{
5455 testType: clientTest,
5456 name: "ServerNameExtensionClientMismatch-" + ver.name,
5457 config: Config{
5458 MaxVersion: ver.version,
5459 Bugs: ProtocolBugs{
5460 ExpectServerName: "mismatch.com",
5461 },
David Benjamine78bfde2014-09-06 12:45:15 -04005462 },
David Benjamin97d17d92016-07-14 16:12:00 -04005463 flags: []string{"-host-name", "example.com"},
5464 shouldFail: true,
5465 expectedLocalError: "tls: unexpected server name",
5466 })
5467 testCases = append(testCases, testCase{
5468 testType: clientTest,
5469 name: "ServerNameExtensionClientMissing-" + ver.name,
5470 config: Config{
5471 MaxVersion: ver.version,
5472 Bugs: ProtocolBugs{
5473 ExpectServerName: "missing.com",
5474 },
David Benjamine78bfde2014-09-06 12:45:15 -04005475 },
David Benjamin97d17d92016-07-14 16:12:00 -04005476 shouldFail: true,
5477 expectedLocalError: "tls: unexpected server name",
5478 })
5479 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005480 testType: clientTest,
5481 name: "TolerateServerNameAck-" + ver.name,
5482 config: Config{
5483 MaxVersion: ver.version,
5484 Bugs: ProtocolBugs{
5485 SendServerNameAck: true,
5486 },
5487 },
5488 flags: []string{"-host-name", "example.com"},
5489 resumeSession: true,
5490 })
5491 testCases = append(testCases, testCase{
5492 testType: clientTest,
5493 name: "UnsolicitedServerNameAck-" + ver.name,
5494 config: Config{
5495 MaxVersion: ver.version,
5496 Bugs: ProtocolBugs{
5497 SendServerNameAck: true,
5498 },
5499 },
5500 shouldFail: true,
5501 expectedError: ":UNEXPECTED_EXTENSION:",
5502 expectedLocalError: "remote error: unsupported extension",
5503 })
5504 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005505 testType: serverTest,
5506 name: "ServerNameExtensionServer-" + ver.name,
5507 config: Config{
5508 MaxVersion: ver.version,
5509 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005510 },
David Benjamin97d17d92016-07-14 16:12:00 -04005511 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005512 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005513 })
5514
5515 // Test ALPN.
5516 testCases = append(testCases, testCase{
5517 testType: clientTest,
5518 name: "ALPNClient-" + ver.name,
5519 config: Config{
5520 MaxVersion: ver.version,
5521 NextProtos: []string{"foo"},
5522 },
5523 flags: []string{
5524 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5525 "-expect-alpn", "foo",
5526 },
5527 expectedNextProto: "foo",
5528 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005529 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005530 })
5531 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005532 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005533 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005534 config: Config{
5535 MaxVersion: ver.version,
5536 Bugs: ProtocolBugs{
5537 SendALPN: "baz",
5538 },
5539 },
5540 flags: []string{
5541 "-advertise-alpn", "\x03foo\x03bar",
5542 },
5543 shouldFail: true,
5544 expectedError: ":INVALID_ALPN_PROTOCOL:",
5545 expectedLocalError: "remote error: illegal parameter",
5546 })
5547 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005548 testType: clientTest,
5549 name: "ALPNClient-AllowUnknown-" + ver.name,
5550 config: Config{
5551 MaxVersion: ver.version,
5552 Bugs: ProtocolBugs{
5553 SendALPN: "baz",
5554 },
5555 },
5556 flags: []string{
5557 "-advertise-alpn", "\x03foo\x03bar",
5558 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005559 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005560 },
5561 })
5562 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005563 testType: serverTest,
5564 name: "ALPNServer-" + ver.name,
5565 config: Config{
5566 MaxVersion: ver.version,
5567 NextProtos: []string{"foo", "bar", "baz"},
5568 },
5569 flags: []string{
5570 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5571 "-select-alpn", "foo",
5572 },
5573 expectedNextProto: "foo",
5574 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005575 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005576 })
5577 testCases = append(testCases, testCase{
5578 testType: serverTest,
5579 name: "ALPNServer-Decline-" + ver.name,
5580 config: Config{
5581 MaxVersion: ver.version,
5582 NextProtos: []string{"foo", "bar", "baz"},
5583 },
5584 flags: []string{"-decline-alpn"},
5585 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005586 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005587 })
5588
David Benjamin25fe85b2016-08-09 20:00:32 -04005589 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5590 // called once.
5591 testCases = append(testCases, testCase{
5592 testType: serverTest,
5593 name: "ALPNServer-Async-" + ver.name,
5594 config: Config{
5595 MaxVersion: ver.version,
5596 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005597 // Prior to TLS 1.3, exercise the asynchronous session callback.
5598 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005599 },
5600 flags: []string{
5601 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5602 "-select-alpn", "foo",
5603 "-async",
5604 },
5605 expectedNextProto: "foo",
5606 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005607 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005608 })
5609
David Benjamin97d17d92016-07-14 16:12:00 -04005610 var emptyString string
5611 testCases = append(testCases, testCase{
5612 testType: clientTest,
5613 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5614 config: Config{
5615 MaxVersion: ver.version,
5616 NextProtos: []string{""},
5617 Bugs: ProtocolBugs{
5618 // A server returning an empty ALPN protocol
5619 // should be rejected.
5620 ALPNProtocol: &emptyString,
5621 },
5622 },
5623 flags: []string{
5624 "-advertise-alpn", "\x03foo",
5625 },
5626 shouldFail: true,
5627 expectedError: ":PARSE_TLSEXT:",
5628 })
5629 testCases = append(testCases, testCase{
5630 testType: serverTest,
5631 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005635 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005636 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005637 },
David Benjamin97d17d92016-07-14 16:12:00 -04005638 flags: []string{
5639 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005640 },
David Benjamin97d17d92016-07-14 16:12:00 -04005641 shouldFail: true,
5642 expectedError: ":PARSE_TLSEXT:",
5643 })
5644
5645 // Test NPN and the interaction with ALPN.
5646 if ver.version < VersionTLS13 {
5647 // Test that the server prefers ALPN over NPN.
5648 testCases = append(testCases, testCase{
5649 testType: serverTest,
5650 name: "ALPNServer-Preferred-" + ver.name,
5651 config: Config{
5652 MaxVersion: ver.version,
5653 NextProtos: []string{"foo", "bar", "baz"},
5654 },
5655 flags: []string{
5656 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5657 "-select-alpn", "foo",
5658 "-advertise-npn", "\x03foo\x03bar\x03baz",
5659 },
5660 expectedNextProto: "foo",
5661 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005662 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005663 })
5664 testCases = append(testCases, testCase{
5665 testType: serverTest,
5666 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5667 config: Config{
5668 MaxVersion: ver.version,
5669 NextProtos: []string{"foo", "bar", "baz"},
5670 Bugs: ProtocolBugs{
5671 SwapNPNAndALPN: true,
5672 },
5673 },
5674 flags: []string{
5675 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5676 "-select-alpn", "foo",
5677 "-advertise-npn", "\x03foo\x03bar\x03baz",
5678 },
5679 expectedNextProto: "foo",
5680 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005681 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005682 })
5683
5684 // Test that negotiating both NPN and ALPN is forbidden.
5685 testCases = append(testCases, testCase{
5686 name: "NegotiateALPNAndNPN-" + ver.name,
5687 config: Config{
5688 MaxVersion: ver.version,
5689 NextProtos: []string{"foo", "bar", "baz"},
5690 Bugs: ProtocolBugs{
5691 NegotiateALPNAndNPN: true,
5692 },
5693 },
5694 flags: []string{
5695 "-advertise-alpn", "\x03foo",
5696 "-select-next-proto", "foo",
5697 },
5698 shouldFail: true,
5699 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5700 })
5701 testCases = append(testCases, testCase{
5702 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5703 config: Config{
5704 MaxVersion: ver.version,
5705 NextProtos: []string{"foo", "bar", "baz"},
5706 Bugs: ProtocolBugs{
5707 NegotiateALPNAndNPN: true,
5708 SwapNPNAndALPN: true,
5709 },
5710 },
5711 flags: []string{
5712 "-advertise-alpn", "\x03foo",
5713 "-select-next-proto", "foo",
5714 },
5715 shouldFail: true,
5716 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5717 })
David Benjamin97d17d92016-07-14 16:12:00 -04005718 }
5719
5720 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005721
5722 // Resume with a corrupt ticket.
5723 testCases = append(testCases, testCase{
5724 testType: serverTest,
5725 name: "CorruptTicket-" + ver.name,
5726 config: Config{
5727 MaxVersion: ver.version,
5728 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005729 FilterTicket: func(in []byte) ([]byte, error) {
5730 in[len(in)-1] ^= 1
5731 return in, nil
5732 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005733 },
5734 },
5735 resumeSession: true,
5736 expectResumeRejected: true,
5737 })
5738 // Test the ticket callback, with and without renewal.
5739 testCases = append(testCases, testCase{
5740 testType: serverTest,
5741 name: "TicketCallback-" + ver.name,
5742 config: Config{
5743 MaxVersion: ver.version,
5744 },
5745 resumeSession: true,
5746 flags: []string{"-use-ticket-callback"},
5747 })
5748 testCases = append(testCases, testCase{
5749 testType: serverTest,
5750 name: "TicketCallback-Renew-" + ver.name,
5751 config: Config{
5752 MaxVersion: ver.version,
5753 Bugs: ProtocolBugs{
5754 ExpectNewTicket: true,
5755 },
5756 },
5757 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5758 resumeSession: true,
5759 })
5760
5761 // Test that the ticket callback is only called once when everything before
5762 // it in the ClientHello is asynchronous. This corrupts the ticket so
5763 // certificate selection callbacks run.
5764 testCases = append(testCases, testCase{
5765 testType: serverTest,
5766 name: "TicketCallback-SingleCall-" + ver.name,
5767 config: Config{
5768 MaxVersion: ver.version,
5769 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005770 FilterTicket: func(in []byte) ([]byte, error) {
5771 in[len(in)-1] ^= 1
5772 return in, nil
5773 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005774 },
5775 },
5776 resumeSession: true,
5777 expectResumeRejected: true,
5778 flags: []string{
5779 "-use-ticket-callback",
5780 "-async",
5781 },
5782 })
5783
David Benjamind4c349b2017-02-09 14:07:17 -05005784 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005785 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005786 testCases = append(testCases, testCase{
5787 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005788 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005789 config: Config{
5790 MaxVersion: ver.version,
5791 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005792 EmptyTicketSessionID: true,
5793 },
5794 },
5795 resumeSession: true,
5796 })
5797 testCases = append(testCases, testCase{
5798 testType: serverTest,
5799 name: "TicketSessionIDLength-16-" + ver.name,
5800 config: Config{
5801 MaxVersion: ver.version,
5802 Bugs: ProtocolBugs{
5803 TicketSessionIDLength: 16,
5804 },
5805 },
5806 resumeSession: true,
5807 })
5808 testCases = append(testCases, testCase{
5809 testType: serverTest,
5810 name: "TicketSessionIDLength-32-" + ver.name,
5811 config: Config{
5812 MaxVersion: ver.version,
5813 Bugs: ProtocolBugs{
5814 TicketSessionIDLength: 32,
5815 },
5816 },
5817 resumeSession: true,
5818 })
5819 testCases = append(testCases, testCase{
5820 testType: serverTest,
5821 name: "TicketSessionIDLength-33-" + ver.name,
5822 config: Config{
5823 MaxVersion: ver.version,
5824 Bugs: ProtocolBugs{
5825 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005826 },
5827 },
5828 resumeSession: true,
5829 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005830 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005831 expectedError: ":DECODE_ERROR:",
5832 })
5833 }
5834
5835 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5836 // are ignored.
5837 if ver.hasDTLS {
5838 testCases = append(testCases, testCase{
5839 protocol: dtls,
5840 name: "SRTP-Client-" + ver.name,
5841 config: Config{
5842 MaxVersion: ver.version,
5843 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5844 },
5845 flags: []string{
5846 "-srtp-profiles",
5847 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5848 },
5849 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5850 })
5851 testCases = append(testCases, testCase{
5852 protocol: dtls,
5853 testType: serverTest,
5854 name: "SRTP-Server-" + ver.name,
5855 config: Config{
5856 MaxVersion: ver.version,
5857 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5858 },
5859 flags: []string{
5860 "-srtp-profiles",
5861 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5862 },
5863 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5864 })
5865 // Test that the MKI is ignored.
5866 testCases = append(testCases, testCase{
5867 protocol: dtls,
5868 testType: serverTest,
5869 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5870 config: Config{
5871 MaxVersion: ver.version,
5872 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5873 Bugs: ProtocolBugs{
5874 SRTPMasterKeyIdentifer: "bogus",
5875 },
5876 },
5877 flags: []string{
5878 "-srtp-profiles",
5879 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5880 },
5881 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5882 })
5883 // Test that SRTP isn't negotiated on the server if there were
5884 // no matching profiles.
5885 testCases = append(testCases, testCase{
5886 protocol: dtls,
5887 testType: serverTest,
5888 name: "SRTP-Server-NoMatch-" + ver.name,
5889 config: Config{
5890 MaxVersion: ver.version,
5891 SRTPProtectionProfiles: []uint16{100, 101, 102},
5892 },
5893 flags: []string{
5894 "-srtp-profiles",
5895 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5896 },
5897 expectedSRTPProtectionProfile: 0,
5898 })
5899 // Test that the server returning an invalid SRTP profile is
5900 // flagged as an error by the client.
5901 testCases = append(testCases, testCase{
5902 protocol: dtls,
5903 name: "SRTP-Client-NoMatch-" + ver.name,
5904 config: Config{
5905 MaxVersion: ver.version,
5906 Bugs: ProtocolBugs{
5907 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5908 },
5909 },
5910 flags: []string{
5911 "-srtp-profiles",
5912 "SRTP_AES128_CM_SHA1_80",
5913 },
5914 shouldFail: true,
5915 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5916 })
5917 }
5918
5919 // Test SCT list.
5920 testCases = append(testCases, testCase{
5921 name: "SignedCertificateTimestampList-Client-" + ver.name,
5922 testType: clientTest,
5923 config: Config{
5924 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005925 },
David Benjamin97d17d92016-07-14 16:12:00 -04005926 flags: []string{
5927 "-enable-signed-cert-timestamps",
5928 "-expect-signed-cert-timestamps",
5929 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005930 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005931 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005932 })
David Benjamindaa88502016-10-04 16:32:16 -04005933
Adam Langleycfa08c32016-11-17 13:21:27 -08005934 var differentSCTList []byte
5935 differentSCTList = append(differentSCTList, testSCTList...)
5936 differentSCTList[len(differentSCTList)-1] ^= 1
5937
David Benjamindaa88502016-10-04 16:32:16 -04005938 // The SCT extension did not specify that it must only be sent on resumption as it
5939 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005940 testCases = append(testCases, testCase{
5941 name: "SendSCTListOnResume-" + ver.name,
5942 config: Config{
5943 MaxVersion: ver.version,
5944 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005945 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005946 },
David Benjamind98452d2015-06-16 14:16:23 -04005947 },
David Benjamin97d17d92016-07-14 16:12:00 -04005948 flags: []string{
5949 "-enable-signed-cert-timestamps",
5950 "-expect-signed-cert-timestamps",
5951 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005952 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005953 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005954 })
David Benjamindaa88502016-10-04 16:32:16 -04005955
David Benjamin97d17d92016-07-14 16:12:00 -04005956 testCases = append(testCases, testCase{
5957 name: "SignedCertificateTimestampList-Server-" + ver.name,
5958 testType: serverTest,
5959 config: Config{
5960 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005961 },
David Benjamin97d17d92016-07-14 16:12:00 -04005962 flags: []string{
5963 "-signed-cert-timestamps",
5964 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005965 },
David Benjamin97d17d92016-07-14 16:12:00 -04005966 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005967 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005968 })
David Benjamin53210cb2016-11-16 09:01:48 +09005969
Adam Langleycfa08c32016-11-17 13:21:27 -08005970 emptySCTListCert := *testCerts[0].cert
5971 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5972
5973 // Test empty SCT list.
5974 testCases = append(testCases, testCase{
5975 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5976 testType: clientTest,
5977 config: Config{
5978 MaxVersion: ver.version,
5979 Certificates: []Certificate{emptySCTListCert},
5980 },
5981 flags: []string{
5982 "-enable-signed-cert-timestamps",
5983 },
5984 shouldFail: true,
5985 expectedError: ":ERROR_PARSING_EXTENSION:",
5986 })
5987
5988 emptySCTCert := *testCerts[0].cert
5989 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5990
5991 // Test empty SCT in non-empty list.
5992 testCases = append(testCases, testCase{
5993 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5994 testType: clientTest,
5995 config: Config{
5996 MaxVersion: ver.version,
5997 Certificates: []Certificate{emptySCTCert},
5998 },
5999 flags: []string{
6000 "-enable-signed-cert-timestamps",
6001 },
6002 shouldFail: true,
6003 expectedError: ":ERROR_PARSING_EXTENSION:",
6004 })
6005
David Benjamin53210cb2016-11-16 09:01:48 +09006006 // Test that certificate-related extensions are not sent unsolicited.
6007 testCases = append(testCases, testCase{
6008 testType: serverTest,
6009 name: "UnsolicitedCertificateExtensions-" + ver.name,
6010 config: Config{
6011 MaxVersion: ver.version,
6012 Bugs: ProtocolBugs{
6013 NoOCSPStapling: true,
6014 NoSignedCertificateTimestamps: true,
6015 },
6016 },
6017 flags: []string{
6018 "-ocsp-response",
6019 base64.StdEncoding.EncodeToString(testOCSPResponse),
6020 "-signed-cert-timestamps",
6021 base64.StdEncoding.EncodeToString(testSCTList),
6022 },
6023 })
David Benjamin97d17d92016-07-14 16:12:00 -04006024 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006025
Paul Lietar4fac72e2015-09-09 13:44:55 +01006026 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006027 testType: clientTest,
6028 name: "ClientHelloPadding",
6029 config: Config{
6030 Bugs: ProtocolBugs{
6031 RequireClientHelloSize: 512,
6032 },
6033 },
6034 // This hostname just needs to be long enough to push the
6035 // ClientHello into F5's danger zone between 256 and 511 bytes
6036 // long.
6037 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6038 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006039
6040 // Extensions should not function in SSL 3.0.
6041 testCases = append(testCases, testCase{
6042 testType: serverTest,
6043 name: "SSLv3Extensions-NoALPN",
6044 config: Config{
6045 MaxVersion: VersionSSL30,
6046 NextProtos: []string{"foo", "bar", "baz"},
6047 },
6048 flags: []string{
6049 "-select-alpn", "foo",
6050 },
6051 expectNoNextProto: true,
6052 })
6053
6054 // Test session tickets separately as they follow a different codepath.
6055 testCases = append(testCases, testCase{
6056 testType: serverTest,
6057 name: "SSLv3Extensions-NoTickets",
6058 config: Config{
6059 MaxVersion: VersionSSL30,
6060 Bugs: ProtocolBugs{
6061 // Historically, session tickets in SSL 3.0
6062 // failed in different ways depending on whether
6063 // the client supported renegotiation_info.
6064 NoRenegotiationInfo: true,
6065 },
6066 },
6067 resumeSession: true,
6068 })
6069 testCases = append(testCases, testCase{
6070 testType: serverTest,
6071 name: "SSLv3Extensions-NoTickets2",
6072 config: Config{
6073 MaxVersion: VersionSSL30,
6074 },
6075 resumeSession: true,
6076 })
6077
6078 // But SSL 3.0 does send and process renegotiation_info.
6079 testCases = append(testCases, testCase{
6080 testType: serverTest,
6081 name: "SSLv3Extensions-RenegotiationInfo",
6082 config: Config{
6083 MaxVersion: VersionSSL30,
6084 Bugs: ProtocolBugs{
6085 RequireRenegotiationInfo: true,
6086 },
6087 },
David Benjamind2610042017-01-03 10:49:28 -05006088 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006089 })
6090 testCases = append(testCases, testCase{
6091 testType: serverTest,
6092 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6093 config: Config{
6094 MaxVersion: VersionSSL30,
6095 Bugs: ProtocolBugs{
6096 NoRenegotiationInfo: true,
6097 SendRenegotiationSCSV: true,
6098 RequireRenegotiationInfo: true,
6099 },
6100 },
David Benjamind2610042017-01-03 10:49:28 -05006101 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006102 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006103
6104 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6105 // in ServerHello.
6106 testCases = append(testCases, testCase{
6107 name: "NPN-Forbidden-TLS13",
6108 config: Config{
6109 MaxVersion: VersionTLS13,
6110 NextProtos: []string{"foo"},
6111 Bugs: ProtocolBugs{
6112 NegotiateNPNAtAllVersions: true,
6113 },
6114 },
6115 flags: []string{"-select-next-proto", "foo"},
6116 shouldFail: true,
6117 expectedError: ":ERROR_PARSING_EXTENSION:",
6118 })
6119 testCases = append(testCases, testCase{
6120 name: "EMS-Forbidden-TLS13",
6121 config: Config{
6122 MaxVersion: VersionTLS13,
6123 Bugs: ProtocolBugs{
6124 NegotiateEMSAtAllVersions: true,
6125 },
6126 },
6127 shouldFail: true,
6128 expectedError: ":ERROR_PARSING_EXTENSION:",
6129 })
6130 testCases = append(testCases, testCase{
6131 name: "RenegotiationInfo-Forbidden-TLS13",
6132 config: Config{
6133 MaxVersion: VersionTLS13,
6134 Bugs: ProtocolBugs{
6135 NegotiateRenegotiationInfoAtAllVersions: true,
6136 },
6137 },
6138 shouldFail: true,
6139 expectedError: ":ERROR_PARSING_EXTENSION:",
6140 })
6141 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006142 name: "Ticket-Forbidden-TLS13",
6143 config: Config{
6144 MaxVersion: VersionTLS12,
6145 },
6146 resumeConfig: &Config{
6147 MaxVersion: VersionTLS13,
6148 Bugs: ProtocolBugs{
6149 AdvertiseTicketExtension: true,
6150 },
6151 },
6152 resumeSession: true,
6153 shouldFail: true,
6154 expectedError: ":ERROR_PARSING_EXTENSION:",
6155 })
6156
6157 // Test that illegal extensions in TLS 1.3 are declined by the server if
6158 // offered in ClientHello. The runner's server will fail if this occurs,
6159 // so we exercise the offering path. (EMS and Renegotiation Info are
6160 // implicit in every test.)
6161 testCases = append(testCases, testCase{
6162 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006163 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006164 config: Config{
6165 MaxVersion: VersionTLS13,
6166 NextProtos: []string{"bar"},
6167 },
6168 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6169 })
David Benjamin196df5b2016-09-21 16:23:27 -04006170
David Benjamindaa88502016-10-04 16:32:16 -04006171 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6172 // tolerated.
6173 testCases = append(testCases, testCase{
6174 name: "SendOCSPResponseOnResume-TLS12",
6175 config: Config{
6176 MaxVersion: VersionTLS12,
6177 Bugs: ProtocolBugs{
6178 SendOCSPResponseOnResume: []byte("bogus"),
6179 },
6180 },
6181 flags: []string{
6182 "-enable-ocsp-stapling",
6183 "-expect-ocsp-response",
6184 base64.StdEncoding.EncodeToString(testOCSPResponse),
6185 },
6186 resumeSession: true,
6187 })
6188
David Benjamindaa88502016-10-04 16:32:16 -04006189 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006190 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006191 config: Config{
6192 MaxVersion: VersionTLS13,
6193 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006194 SendExtensionOnCertificate: testOCSPExtension,
6195 },
6196 },
6197 shouldFail: true,
6198 expectedError: ":UNEXPECTED_EXTENSION:",
6199 })
6200
6201 testCases = append(testCases, testCase{
6202 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6203 config: Config{
6204 MaxVersion: VersionTLS13,
6205 Bugs: ProtocolBugs{
6206 SendExtensionOnCertificate: testSCTExtension,
6207 },
6208 },
6209 shouldFail: true,
6210 expectedError: ":UNEXPECTED_EXTENSION:",
6211 })
6212
6213 // Test that extensions on client certificates are never accepted.
6214 testCases = append(testCases, testCase{
6215 name: "SendExtensionOnClientCertificate-TLS13",
6216 testType: serverTest,
6217 config: Config{
6218 MaxVersion: VersionTLS13,
6219 Certificates: []Certificate{rsaCertificate},
6220 Bugs: ProtocolBugs{
6221 SendExtensionOnCertificate: testOCSPExtension,
6222 },
6223 },
6224 flags: []string{
6225 "-enable-ocsp-stapling",
6226 "-require-any-client-certificate",
6227 },
6228 shouldFail: true,
6229 expectedError: ":UNEXPECTED_EXTENSION:",
6230 })
6231
6232 testCases = append(testCases, testCase{
6233 name: "SendUnknownExtensionOnCertificate-TLS13",
6234 config: Config{
6235 MaxVersion: VersionTLS13,
6236 Bugs: ProtocolBugs{
6237 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6238 },
6239 },
6240 shouldFail: true,
6241 expectedError: ":UNEXPECTED_EXTENSION:",
6242 })
6243
Adam Langleycfa08c32016-11-17 13:21:27 -08006244 var differentSCTList []byte
6245 differentSCTList = append(differentSCTList, testSCTList...)
6246 differentSCTList[len(differentSCTList)-1] ^= 1
6247
Steven Valdeza833c352016-11-01 13:39:36 -04006248 // Test that extensions on intermediates are allowed but ignored.
6249 testCases = append(testCases, testCase{
6250 name: "IgnoreExtensionsOnIntermediates-TLS13",
6251 config: Config{
6252 MaxVersion: VersionTLS13,
6253 Certificates: []Certificate{rsaChainCertificate},
6254 Bugs: ProtocolBugs{
6255 // Send different values on the intermediate. This tests
6256 // the intermediate's extensions do not override the
6257 // leaf's.
6258 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006259 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006260 },
6261 },
6262 flags: []string{
6263 "-enable-ocsp-stapling",
6264 "-expect-ocsp-response",
6265 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006266 "-enable-signed-cert-timestamps",
6267 "-expect-signed-cert-timestamps",
6268 base64.StdEncoding.EncodeToString(testSCTList),
6269 },
6270 resumeSession: true,
6271 })
6272
6273 // Test that extensions are not sent on intermediates when configured
6274 // only for a leaf.
6275 testCases = append(testCases, testCase{
6276 testType: serverTest,
6277 name: "SendNoExtensionsOnIntermediate-TLS13",
6278 config: Config{
6279 MaxVersion: VersionTLS13,
6280 Bugs: ProtocolBugs{
6281 ExpectNoExtensionsOnIntermediate: true,
6282 },
6283 },
6284 flags: []string{
6285 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6286 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6287 "-ocsp-response",
6288 base64.StdEncoding.EncodeToString(testOCSPResponse),
6289 "-signed-cert-timestamps",
6290 base64.StdEncoding.EncodeToString(testSCTList),
6291 },
6292 })
6293
6294 // Test that extensions are not sent on client certificates.
6295 testCases = append(testCases, testCase{
6296 name: "SendNoClientCertificateExtensions-TLS13",
6297 config: Config{
6298 MaxVersion: VersionTLS13,
6299 ClientAuth: RequireAnyClientCert,
6300 },
6301 flags: []string{
6302 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6303 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6304 "-ocsp-response",
6305 base64.StdEncoding.EncodeToString(testOCSPResponse),
6306 "-signed-cert-timestamps",
6307 base64.StdEncoding.EncodeToString(testSCTList),
6308 },
6309 })
6310
6311 testCases = append(testCases, testCase{
6312 name: "SendDuplicateExtensionsOnCerts-TLS13",
6313 config: Config{
6314 MaxVersion: VersionTLS13,
6315 Bugs: ProtocolBugs{
6316 SendDuplicateCertExtensions: true,
6317 },
6318 },
6319 flags: []string{
6320 "-enable-ocsp-stapling",
6321 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006322 },
6323 resumeSession: true,
6324 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006325 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006326 })
Adam Langley9b885c52016-11-18 14:21:03 -08006327
6328 testCases = append(testCases, testCase{
6329 name: "SignedCertificateTimestampListInvalid-Server",
6330 testType: serverTest,
6331 flags: []string{
6332 "-signed-cert-timestamps",
6333 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6334 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006335 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006336 expectedError: ":INVALID_SCT_LIST:",
6337 })
David Benjamine78bfde2014-09-06 12:45:15 -04006338}
6339
David Benjamin01fe8202014-09-24 15:21:44 -04006340func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006341 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006342 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006343 // SSL 3.0 does not have tickets and TLS 1.3 does not
6344 // have session IDs, so skip their cross-resumption
6345 // tests.
6346 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6347 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6348 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006349 }
6350
David Benjamin8b8c0062014-11-23 02:47:52 -05006351 protocols := []protocol{tls}
6352 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6353 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006354 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006355 for _, protocol := range protocols {
6356 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6357 if protocol == dtls {
6358 suffix += "-DTLS"
6359 }
6360
Steven Valdez520e1222017-06-13 12:45:25 -04006361 // We can't resume across TLS 1.3 variants and error out earlier in the
6362 // session resumption.
6363 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6364 continue
6365 }
6366
David Benjaminece3de92015-03-16 18:02:20 -04006367 if sessionVers.version == resumeVers.version {
6368 testCases = append(testCases, testCase{
6369 protocol: protocol,
6370 name: "Resume-Client" + suffix,
6371 resumeSession: true,
6372 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006373 MaxVersion: sessionVers.version,
6374 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006375 Bugs: ProtocolBugs{
6376 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6377 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6378 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006379 },
David Benjaminece3de92015-03-16 18:02:20 -04006380 expectedVersion: sessionVers.version,
6381 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006382 flags: []string{
6383 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6384 },
David Benjaminece3de92015-03-16 18:02:20 -04006385 })
6386 } else {
David Benjamin405da482016-08-08 17:25:07 -04006387 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6388
6389 // Offering a TLS 1.3 session sends an empty session ID, so
6390 // there is no way to convince a non-lookahead client the
6391 // session was resumed. It will appear to the client that a
6392 // stray ChangeCipherSpec was sent.
6393 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6394 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006395 }
6396
David Benjaminece3de92015-03-16 18:02:20 -04006397 testCases = append(testCases, testCase{
6398 protocol: protocol,
6399 name: "Resume-Client-Mismatch" + suffix,
6400 resumeSession: true,
6401 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006402 MaxVersion: sessionVers.version,
6403 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006404 },
David Benjaminece3de92015-03-16 18:02:20 -04006405 expectedVersion: sessionVers.version,
6406 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006407 MaxVersion: resumeVers.version,
6408 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006409 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006410 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006411 },
6412 },
6413 expectedResumeVersion: resumeVers.version,
6414 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006415 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006416 flags: []string{
6417 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6418 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6419 },
David Benjaminece3de92015-03-16 18:02:20 -04006420 })
6421 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006422
6423 testCases = append(testCases, testCase{
6424 protocol: protocol,
6425 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006426 resumeSession: true,
6427 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006428 MaxVersion: sessionVers.version,
6429 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006430 },
6431 expectedVersion: sessionVers.version,
6432 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006433 MaxVersion: resumeVers.version,
6434 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006435 },
6436 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006437 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006438 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006439 flags: []string{
6440 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6441 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6442 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006443 })
6444
David Benjamin8b8c0062014-11-23 02:47:52 -05006445 testCases = append(testCases, testCase{
6446 protocol: protocol,
6447 testType: serverTest,
6448 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006449 resumeSession: true,
6450 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006451 MaxVersion: sessionVers.version,
6452 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006453 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006454 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006455 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006456 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006457 MaxVersion: resumeVers.version,
6458 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006459 Bugs: ProtocolBugs{
6460 SendBothTickets: true,
6461 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006462 },
6463 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006464 flags: []string{
6465 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6466 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6467 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006468 })
6469 }
David Benjamin01fe8202014-09-24 15:21:44 -04006470 }
6471 }
David Benjaminece3de92015-03-16 18:02:20 -04006472
David Benjamin4199b0d2016-11-01 13:58:25 -04006473 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006474 testCases = append(testCases, testCase{
6475 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006476 name: "ShimTicketRewritable",
6477 resumeSession: true,
6478 config: Config{
6479 MaxVersion: VersionTLS12,
6480 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6481 Bugs: ProtocolBugs{
6482 FilterTicket: func(in []byte) ([]byte, error) {
6483 in, err := SetShimTicketVersion(in, VersionTLS12)
6484 if err != nil {
6485 return nil, err
6486 }
6487 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6488 },
6489 },
6490 },
6491 flags: []string{
6492 "-ticket-key",
6493 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6494 },
6495 })
6496
6497 // Resumptions are declined if the version does not match.
6498 testCases = append(testCases, testCase{
6499 testType: serverTest,
6500 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006501 resumeSession: true,
6502 config: Config{
6503 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006504 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006505 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006506 FilterTicket: func(in []byte) ([]byte, error) {
6507 return SetShimTicketVersion(in, VersionTLS13)
6508 },
6509 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006510 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006511 flags: []string{
6512 "-ticket-key",
6513 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6514 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006515 expectResumeRejected: true,
6516 })
6517
6518 testCases = append(testCases, testCase{
6519 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006520 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006521 resumeSession: true,
6522 config: Config{
6523 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006524 Bugs: ProtocolBugs{
6525 FilterTicket: func(in []byte) ([]byte, error) {
6526 return SetShimTicketVersion(in, VersionTLS12)
6527 },
6528 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006529 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006530 flags: []string{
6531 "-ticket-key",
6532 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6533 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006534 expectResumeRejected: true,
6535 })
6536
David Benjamin4199b0d2016-11-01 13:58:25 -04006537 // Resumptions are declined if the cipher is invalid or disabled.
6538 testCases = append(testCases, testCase{
6539 testType: serverTest,
6540 name: "Resume-Server-DeclineBadCipher",
6541 resumeSession: true,
6542 config: Config{
6543 MaxVersion: VersionTLS12,
6544 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006545 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006546 FilterTicket: func(in []byte) ([]byte, error) {
6547 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6548 },
6549 },
6550 },
6551 flags: []string{
6552 "-ticket-key",
6553 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6554 },
6555 expectResumeRejected: true,
6556 })
6557
6558 testCases = append(testCases, testCase{
6559 testType: serverTest,
6560 name: "Resume-Server-DeclineBadCipher-2",
6561 resumeSession: true,
6562 config: Config{
6563 MaxVersion: VersionTLS12,
6564 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006565 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006566 FilterTicket: func(in []byte) ([]byte, error) {
6567 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6568 },
6569 },
6570 },
6571 flags: []string{
6572 "-cipher", "AES128",
6573 "-ticket-key",
6574 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6575 },
6576 expectResumeRejected: true,
6577 })
6578
David Benjaminf01f42a2016-11-16 19:05:33 +09006579 // Sessions are not resumed if they do not use the preferred cipher.
6580 testCases = append(testCases, testCase{
6581 testType: serverTest,
6582 name: "Resume-Server-CipherNotPreferred",
6583 resumeSession: true,
6584 config: Config{
6585 MaxVersion: VersionTLS12,
6586 Bugs: ProtocolBugs{
6587 ExpectNewTicket: true,
6588 FilterTicket: func(in []byte) ([]byte, error) {
6589 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6590 },
6591 },
6592 },
6593 flags: []string{
6594 "-ticket-key",
6595 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6596 },
6597 shouldFail: false,
6598 expectResumeRejected: true,
6599 })
6600
6601 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6602 // PRF hashes match, but BoringSSL will always decline such resumptions.
6603 testCases = append(testCases, testCase{
6604 testType: serverTest,
6605 name: "Resume-Server-CipherNotPreferred-TLS13",
6606 resumeSession: true,
6607 config: Config{
6608 MaxVersion: VersionTLS13,
6609 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6610 Bugs: ProtocolBugs{
6611 FilterTicket: func(in []byte) ([]byte, error) {
6612 // If the client (runner) offers ChaCha20-Poly1305 first, the
6613 // server (shim) always prefers it. Switch it to AES-GCM.
6614 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6615 },
6616 },
6617 },
6618 flags: []string{
6619 "-ticket-key",
6620 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6621 },
6622 shouldFail: false,
6623 expectResumeRejected: true,
6624 })
6625
6626 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006627 testCases = append(testCases, testCase{
6628 testType: serverTest,
6629 name: "Resume-Server-DeclineBadCipher-TLS13",
6630 resumeSession: true,
6631 config: Config{
6632 MaxVersion: VersionTLS13,
6633 Bugs: ProtocolBugs{
6634 FilterTicket: func(in []byte) ([]byte, error) {
6635 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6636 },
6637 },
6638 },
6639 flags: []string{
6640 "-ticket-key",
6641 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6642 },
6643 expectResumeRejected: true,
6644 })
6645
David Benjaminf01f42a2016-11-16 19:05:33 +09006646 // If the client does not offer the cipher from the session, decline to
6647 // resume. Clients are forbidden from doing this, but BoringSSL selects
6648 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006649 testCases = append(testCases, testCase{
6650 testType: serverTest,
6651 name: "Resume-Server-UnofferedCipher",
6652 resumeSession: true,
6653 config: Config{
6654 MaxVersion: VersionTLS12,
6655 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6656 },
6657 resumeConfig: &Config{
6658 MaxVersion: VersionTLS12,
6659 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6660 Bugs: ProtocolBugs{
6661 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6662 },
6663 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006664 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006665 })
6666
David Benjaminf01f42a2016-11-16 19:05:33 +09006667 // In TLS 1.3, clients may advertise a cipher list which does not
6668 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006669 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6670 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006671 testCases = append(testCases, testCase{
6672 testType: serverTest,
6673 name: "Resume-Server-UnofferedCipher-TLS13",
6674 resumeSession: true,
6675 config: Config{
6676 MaxVersion: VersionTLS13,
6677 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6678 },
6679 resumeConfig: &Config{
6680 MaxVersion: VersionTLS13,
6681 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6682 Bugs: ProtocolBugs{
6683 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6684 },
6685 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006686 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006687 })
6688
David Benjamin4199b0d2016-11-01 13:58:25 -04006689 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006690 testCases = append(testCases, testCase{
6691 name: "Resume-Client-CipherMismatch",
6692 resumeSession: true,
6693 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006694 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006695 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6696 },
6697 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006698 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006699 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6700 Bugs: ProtocolBugs{
6701 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6702 },
6703 },
6704 shouldFail: true,
6705 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6706 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006707
David Benjamine1cc35e2016-11-16 16:25:58 +09006708 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6709 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006710 testCases = append(testCases, testCase{
6711 name: "Resume-Client-CipherMismatch-TLS13",
6712 resumeSession: true,
6713 config: Config{
6714 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006715 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006716 },
6717 resumeConfig: &Config{
6718 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006719 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6720 },
6721 })
6722
6723 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6724 testCases = append(testCases, testCase{
6725 name: "Resume-Client-PRFMismatch-TLS13",
6726 resumeSession: true,
6727 config: Config{
6728 MaxVersion: VersionTLS13,
6729 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6730 },
6731 resumeConfig: &Config{
6732 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006733 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006734 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006735 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006736 },
6737 },
6738 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006739 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006740 })
Steven Valdeza833c352016-11-01 13:39:36 -04006741
6742 testCases = append(testCases, testCase{
6743 testType: serverTest,
6744 name: "Resume-Server-BinderWrongLength",
6745 resumeSession: true,
6746 config: Config{
6747 MaxVersion: VersionTLS13,
6748 Bugs: ProtocolBugs{
6749 SendShortPSKBinder: true,
6750 },
6751 },
6752 shouldFail: true,
6753 expectedLocalError: "remote error: error decrypting message",
6754 expectedError: ":DIGEST_CHECK_FAILED:",
6755 })
6756
6757 testCases = append(testCases, testCase{
6758 testType: serverTest,
6759 name: "Resume-Server-NoPSKBinder",
6760 resumeSession: true,
6761 config: Config{
6762 MaxVersion: VersionTLS13,
6763 Bugs: ProtocolBugs{
6764 SendNoPSKBinder: true,
6765 },
6766 },
6767 shouldFail: true,
6768 expectedLocalError: "remote error: error decoding message",
6769 expectedError: ":DECODE_ERROR:",
6770 })
6771
6772 testCases = append(testCases, testCase{
6773 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006774 name: "Resume-Server-ExtraPSKBinder",
6775 resumeSession: true,
6776 config: Config{
6777 MaxVersion: VersionTLS13,
6778 Bugs: ProtocolBugs{
6779 SendExtraPSKBinder: true,
6780 },
6781 },
6782 shouldFail: true,
6783 expectedLocalError: "remote error: illegal parameter",
6784 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6785 })
6786
6787 testCases = append(testCases, testCase{
6788 testType: serverTest,
6789 name: "Resume-Server-ExtraIdentityNoBinder",
6790 resumeSession: true,
6791 config: Config{
6792 MaxVersion: VersionTLS13,
6793 Bugs: ProtocolBugs{
6794 ExtraPSKIdentity: true,
6795 },
6796 },
6797 shouldFail: true,
6798 expectedLocalError: "remote error: illegal parameter",
6799 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6800 })
6801
6802 testCases = append(testCases, testCase{
6803 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006804 name: "Resume-Server-InvalidPSKBinder",
6805 resumeSession: true,
6806 config: Config{
6807 MaxVersion: VersionTLS13,
6808 Bugs: ProtocolBugs{
6809 SendInvalidPSKBinder: true,
6810 },
6811 },
6812 shouldFail: true,
6813 expectedLocalError: "remote error: error decrypting message",
6814 expectedError: ":DIGEST_CHECK_FAILED:",
6815 })
6816
6817 testCases = append(testCases, testCase{
6818 testType: serverTest,
6819 name: "Resume-Server-PSKBinderFirstExtension",
6820 resumeSession: true,
6821 config: Config{
6822 MaxVersion: VersionTLS13,
6823 Bugs: ProtocolBugs{
6824 PSKBinderFirst: true,
6825 },
6826 },
6827 shouldFail: true,
6828 expectedLocalError: "remote error: illegal parameter",
6829 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6830 })
David Benjamin01fe8202014-09-24 15:21:44 -04006831}
6832
Adam Langley2ae77d22014-10-28 17:29:33 -07006833func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006834 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006835 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006836 testType: serverTest,
6837 name: "Renegotiate-Server-Forbidden",
6838 config: Config{
6839 MaxVersion: VersionTLS12,
6840 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006841 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006842 shouldFail: true,
6843 expectedError: ":NO_RENEGOTIATION:",
6844 expectedLocalError: "remote error: no renegotiation",
6845 })
Adam Langley5021b222015-06-12 18:27:58 -07006846 // The server shouldn't echo the renegotiation extension unless
6847 // requested by the client.
6848 testCases = append(testCases, testCase{
6849 testType: serverTest,
6850 name: "Renegotiate-Server-NoExt",
6851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006852 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006853 Bugs: ProtocolBugs{
6854 NoRenegotiationInfo: true,
6855 RequireRenegotiationInfo: true,
6856 },
6857 },
6858 shouldFail: true,
6859 expectedLocalError: "renegotiation extension missing",
6860 })
6861 // The renegotiation SCSV should be sufficient for the server to echo
6862 // the extension.
6863 testCases = append(testCases, testCase{
6864 testType: serverTest,
6865 name: "Renegotiate-Server-NoExt-SCSV",
6866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006867 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006868 Bugs: ProtocolBugs{
6869 NoRenegotiationInfo: true,
6870 SendRenegotiationSCSV: true,
6871 RequireRenegotiationInfo: true,
6872 },
6873 },
6874 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006875 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006876 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006877 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006878 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006879 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006880 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006881 },
6882 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006883 renegotiate: 1,
6884 flags: []string{
6885 "-renegotiate-freely",
6886 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006887 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006888 },
David Benjamincdea40c2015-03-19 14:09:43 -04006889 })
6890 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006891 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006892 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006894 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006895 Bugs: ProtocolBugs{
6896 EmptyRenegotiationInfo: true,
6897 },
6898 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006899 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006900 shouldFail: true,
6901 expectedError: ":RENEGOTIATION_MISMATCH:",
6902 })
6903 testCases = append(testCases, testCase{
6904 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006905 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006907 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006908 Bugs: ProtocolBugs{
6909 BadRenegotiationInfo: true,
6910 },
6911 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006912 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006913 shouldFail: true,
6914 expectedError: ":RENEGOTIATION_MISMATCH:",
6915 })
6916 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006917 name: "Renegotiate-Client-BadExt2",
6918 renegotiate: 1,
6919 config: Config{
6920 MaxVersion: VersionTLS12,
6921 Bugs: ProtocolBugs{
6922 BadRenegotiationInfoEnd: true,
6923 },
6924 },
6925 flags: []string{"-renegotiate-freely"},
6926 shouldFail: true,
6927 expectedError: ":RENEGOTIATION_MISMATCH:",
6928 })
6929 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006930 name: "Renegotiate-Client-Downgrade",
6931 renegotiate: 1,
6932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006933 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006934 Bugs: ProtocolBugs{
6935 NoRenegotiationInfoAfterInitial: true,
6936 },
6937 },
6938 flags: []string{"-renegotiate-freely"},
6939 shouldFail: true,
6940 expectedError: ":RENEGOTIATION_MISMATCH:",
6941 })
6942 testCases = append(testCases, testCase{
6943 name: "Renegotiate-Client-Upgrade",
6944 renegotiate: 1,
6945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006946 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006947 Bugs: ProtocolBugs{
6948 NoRenegotiationInfoInInitial: true,
6949 },
6950 },
6951 flags: []string{"-renegotiate-freely"},
6952 shouldFail: true,
6953 expectedError: ":RENEGOTIATION_MISMATCH:",
6954 })
6955 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006956 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006957 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006959 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006960 Bugs: ProtocolBugs{
6961 NoRenegotiationInfo: true,
6962 },
6963 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006964 flags: []string{
6965 "-renegotiate-freely",
6966 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006967 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006968 },
David Benjamincff0b902015-05-15 23:09:47 -04006969 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006970
6971 // Test that the server may switch ciphers on renegotiation without
6972 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006973 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006974 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006975 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006976 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006977 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006978 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006979 },
6980 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006981 flags: []string{
6982 "-renegotiate-freely",
6983 "-expect-total-renegotiations", "1",
6984 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006985 })
6986 testCases = append(testCases, testCase{
6987 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006988 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006989 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006990 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006991 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6992 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006993 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006994 flags: []string{
6995 "-renegotiate-freely",
6996 "-expect-total-renegotiations", "1",
6997 },
David Benjaminb16346b2015-04-08 19:16:58 -04006998 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006999
7000 // Test that the server may not switch versions on renegotiation.
7001 testCases = append(testCases, testCase{
7002 name: "Renegotiate-Client-SwitchVersion",
7003 config: Config{
7004 MaxVersion: VersionTLS12,
7005 // Pick a cipher which exists at both versions.
7006 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7007 Bugs: ProtocolBugs{
7008 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007009 // Avoid failing early at the record layer.
7010 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007011 },
7012 },
7013 renegotiate: 1,
7014 flags: []string{
7015 "-renegotiate-freely",
7016 "-expect-total-renegotiations", "1",
7017 },
7018 shouldFail: true,
7019 expectedError: ":WRONG_SSL_VERSION:",
7020 })
7021
David Benjaminb16346b2015-04-08 19:16:58 -04007022 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007023 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007024 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007025 config: Config{
7026 MaxVersion: VersionTLS10,
7027 Bugs: ProtocolBugs{
7028 RequireSameRenegoClientVersion: true,
7029 },
7030 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007031 flags: []string{
7032 "-renegotiate-freely",
7033 "-expect-total-renegotiations", "1",
7034 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007035 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007036 testCases = append(testCases, testCase{
7037 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007038 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007039 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007040 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007041 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7042 NextProtos: []string{"foo"},
7043 },
7044 flags: []string{
7045 "-false-start",
7046 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007047 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007048 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007049 },
7050 shimWritesFirst: true,
7051 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007052
7053 // Client-side renegotiation controls.
7054 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007055 name: "Renegotiate-Client-Forbidden-1",
7056 config: Config{
7057 MaxVersion: VersionTLS12,
7058 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007059 renegotiate: 1,
7060 shouldFail: true,
7061 expectedError: ":NO_RENEGOTIATION:",
7062 expectedLocalError: "remote error: no renegotiation",
7063 })
7064 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007065 name: "Renegotiate-Client-Once-1",
7066 config: Config{
7067 MaxVersion: VersionTLS12,
7068 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007069 renegotiate: 1,
7070 flags: []string{
7071 "-renegotiate-once",
7072 "-expect-total-renegotiations", "1",
7073 },
7074 })
7075 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007076 name: "Renegotiate-Client-Freely-1",
7077 config: Config{
7078 MaxVersion: VersionTLS12,
7079 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007080 renegotiate: 1,
7081 flags: []string{
7082 "-renegotiate-freely",
7083 "-expect-total-renegotiations", "1",
7084 },
7085 })
7086 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007087 name: "Renegotiate-Client-Once-2",
7088 config: Config{
7089 MaxVersion: VersionTLS12,
7090 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007091 renegotiate: 2,
7092 flags: []string{"-renegotiate-once"},
7093 shouldFail: true,
7094 expectedError: ":NO_RENEGOTIATION:",
7095 expectedLocalError: "remote error: no renegotiation",
7096 })
7097 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007098 name: "Renegotiate-Client-Freely-2",
7099 config: Config{
7100 MaxVersion: VersionTLS12,
7101 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007102 renegotiate: 2,
7103 flags: []string{
7104 "-renegotiate-freely",
7105 "-expect-total-renegotiations", "2",
7106 },
7107 })
Adam Langley27a0d082015-11-03 13:34:10 -08007108 testCases = append(testCases, testCase{
7109 name: "Renegotiate-Client-NoIgnore",
7110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007111 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007112 Bugs: ProtocolBugs{
7113 SendHelloRequestBeforeEveryAppDataRecord: true,
7114 },
7115 },
7116 shouldFail: true,
7117 expectedError: ":NO_RENEGOTIATION:",
7118 })
7119 testCases = append(testCases, testCase{
7120 name: "Renegotiate-Client-Ignore",
7121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007122 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007123 Bugs: ProtocolBugs{
7124 SendHelloRequestBeforeEveryAppDataRecord: true,
7125 },
7126 },
7127 flags: []string{
7128 "-renegotiate-ignore",
7129 "-expect-total-renegotiations", "0",
7130 },
7131 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007132
David Benjamin34941c02016-10-08 11:45:31 -04007133 // Renegotiation is not allowed at SSL 3.0.
7134 testCases = append(testCases, testCase{
7135 name: "Renegotiate-Client-SSL3",
7136 config: Config{
7137 MaxVersion: VersionSSL30,
7138 },
7139 renegotiate: 1,
7140 flags: []string{
7141 "-renegotiate-freely",
7142 "-expect-total-renegotiations", "1",
7143 },
7144 shouldFail: true,
7145 expectedError: ":NO_RENEGOTIATION:",
7146 expectedLocalError: "remote error: no renegotiation",
7147 })
7148
David Benjamina1eaba12017-01-01 23:19:22 -05007149 // Renegotiation is not allowed when there is an unfinished write.
7150 testCases = append(testCases, testCase{
7151 name: "Renegotiate-Client-UnfinishedWrite",
7152 config: Config{
7153 MaxVersion: VersionTLS12,
7154 },
David Benjaminbbba9392017-04-06 12:54:12 -04007155 renegotiate: 1,
7156 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007157 flags: []string{
7158 "-async",
7159 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007160 },
7161 shouldFail: true,
7162 expectedError: ":NO_RENEGOTIATION:",
7163 // We do not successfully send the no_renegotiation alert in
7164 // this case. https://crbug.com/boringssl/130
7165 })
7166
David Benjamin07ab5d42017-02-09 20:11:41 -05007167 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007168 testCases = append(testCases, testCase{
7169 name: "StrayHelloRequest",
7170 config: Config{
7171 MaxVersion: VersionTLS12,
7172 Bugs: ProtocolBugs{
7173 SendHelloRequestBeforeEveryHandshakeMessage: true,
7174 },
7175 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007176 shouldFail: true,
7177 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007178 })
7179 testCases = append(testCases, testCase{
7180 name: "StrayHelloRequest-Packed",
7181 config: Config{
7182 MaxVersion: VersionTLS12,
7183 Bugs: ProtocolBugs{
7184 PackHandshakeFlight: true,
7185 SendHelloRequestBeforeEveryHandshakeMessage: true,
7186 },
7187 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007188 shouldFail: true,
7189 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007190 })
7191
David Benjamin12d2c482016-07-24 10:56:51 -04007192 // Test renegotiation works if HelloRequest and server Finished come in
7193 // the same record.
7194 testCases = append(testCases, testCase{
7195 name: "Renegotiate-Client-Packed",
7196 config: Config{
7197 MaxVersion: VersionTLS12,
7198 Bugs: ProtocolBugs{
7199 PackHandshakeFlight: true,
7200 PackHelloRequestWithFinished: true,
7201 },
7202 },
7203 renegotiate: 1,
7204 flags: []string{
7205 "-renegotiate-freely",
7206 "-expect-total-renegotiations", "1",
7207 },
7208 })
7209
David Benjamin397c8e62016-07-08 14:14:36 -07007210 // Renegotiation is forbidden in TLS 1.3.
7211 testCases = append(testCases, testCase{
7212 name: "Renegotiate-Client-TLS13",
7213 config: Config{
7214 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007215 Bugs: ProtocolBugs{
7216 SendHelloRequestBeforeEveryAppDataRecord: true,
7217 },
David Benjamin397c8e62016-07-08 14:14:36 -07007218 },
David Benjamin397c8e62016-07-08 14:14:36 -07007219 flags: []string{
7220 "-renegotiate-freely",
7221 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007222 shouldFail: true,
7223 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007224 })
7225
7226 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7227 testCases = append(testCases, testCase{
7228 name: "StrayHelloRequest-TLS13",
7229 config: Config{
7230 MaxVersion: VersionTLS13,
7231 Bugs: ProtocolBugs{
7232 SendHelloRequestBeforeEveryHandshakeMessage: true,
7233 },
7234 },
7235 shouldFail: true,
7236 expectedError: ":UNEXPECTED_MESSAGE:",
7237 })
David Benjamind2610042017-01-03 10:49:28 -05007238
7239 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7240 // always reads as supporting it, regardless of whether it was
7241 // negotiated.
7242 testCases = append(testCases, testCase{
7243 name: "AlwaysReportRenegotiationInfo-TLS13",
7244 config: Config{
7245 MaxVersion: VersionTLS13,
7246 Bugs: ProtocolBugs{
7247 NoRenegotiationInfo: true,
7248 },
7249 },
7250 flags: []string{
7251 "-expect-secure-renegotiation",
7252 },
7253 })
David Benjamina58baaf2017-02-28 20:54:28 -05007254
7255 // Certificates may not change on renegotiation.
7256 testCases = append(testCases, testCase{
7257 name: "Renegotiation-CertificateChange",
7258 config: Config{
7259 MaxVersion: VersionTLS12,
7260 Certificates: []Certificate{rsaCertificate},
7261 Bugs: ProtocolBugs{
7262 RenegotiationCertificate: &rsaChainCertificate,
7263 },
7264 },
7265 renegotiate: 1,
7266 flags: []string{"-renegotiate-freely"},
7267 shouldFail: true,
7268 expectedError: ":SERVER_CERT_CHANGED:",
7269 })
7270 testCases = append(testCases, testCase{
7271 name: "Renegotiation-CertificateChange-2",
7272 config: Config{
7273 MaxVersion: VersionTLS12,
7274 Certificates: []Certificate{rsaCertificate},
7275 Bugs: ProtocolBugs{
7276 RenegotiationCertificate: &rsa1024Certificate,
7277 },
7278 },
7279 renegotiate: 1,
7280 flags: []string{"-renegotiate-freely"},
7281 shouldFail: true,
7282 expectedError: ":SERVER_CERT_CHANGED:",
7283 })
David Benjaminbbf42462017-03-14 21:27:10 -04007284
7285 // We do not negotiate ALPN after the initial handshake. This is
7286 // error-prone and only risks bugs in consumers.
7287 testCases = append(testCases, testCase{
7288 testType: clientTest,
7289 name: "Renegotiation-ForbidALPN",
7290 config: Config{
7291 MaxVersion: VersionTLS12,
7292 Bugs: ProtocolBugs{
7293 // Forcibly negotiate ALPN on both initial and
7294 // renegotiation handshakes. The test stack will
7295 // internally check the client does not offer
7296 // it.
7297 SendALPN: "foo",
7298 },
7299 },
7300 flags: []string{
7301 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7302 "-expect-alpn", "foo",
7303 "-renegotiate-freely",
7304 },
7305 renegotiate: 1,
7306 shouldFail: true,
7307 expectedError: ":UNEXPECTED_EXTENSION:",
7308 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007309}
7310
David Benjamin5e961c12014-11-07 01:48:35 -05007311func addDTLSReplayTests() {
7312 // Test that sequence number replays are detected.
7313 testCases = append(testCases, testCase{
7314 protocol: dtls,
7315 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007316 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007317 replayWrites: true,
7318 })
7319
David Benjamin8e6db492015-07-25 18:29:23 -04007320 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007321 // than the retransmit window.
7322 testCases = append(testCases, testCase{
7323 protocol: dtls,
7324 name: "DTLS-Replay-LargeGaps",
7325 config: Config{
7326 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007327 SequenceNumberMapping: func(in uint64) uint64 {
7328 return in * 127
7329 },
David Benjamin5e961c12014-11-07 01:48:35 -05007330 },
7331 },
David Benjamin8e6db492015-07-25 18:29:23 -04007332 messageCount: 200,
7333 replayWrites: true,
7334 })
7335
7336 // Test the incoming sequence number changing non-monotonically.
7337 testCases = append(testCases, testCase{
7338 protocol: dtls,
7339 name: "DTLS-Replay-NonMonotonic",
7340 config: Config{
7341 Bugs: ProtocolBugs{
7342 SequenceNumberMapping: func(in uint64) uint64 {
7343 return in ^ 31
7344 },
7345 },
7346 },
7347 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007348 replayWrites: true,
7349 })
7350}
7351
Nick Harper60edffd2016-06-21 15:19:24 -07007352var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007353 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007354 id signatureAlgorithm
7355 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007356}{
Nick Harper60edffd2016-06-21 15:19:24 -07007357 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7358 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7359 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7360 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007361 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007362 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7363 // hash function doesn't have to match the curve and so the same
7364 // signature algorithm works with P-224.
7365 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007366 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7367 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7368 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007369 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7370 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7371 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007372 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007373 // Tests for key types prior to TLS 1.2.
7374 {"RSA", 0, testCertRSA},
7375 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007376}
7377
Nick Harper60edffd2016-06-21 15:19:24 -07007378const fakeSigAlg1 signatureAlgorithm = 0x2a01
7379const fakeSigAlg2 signatureAlgorithm = 0xff01
7380
7381func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007382 // Not all ciphers involve a signature. Advertise a list which gives all
7383 // versions a signing cipher.
7384 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007385 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007386 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7387 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7388 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7389 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007390 }
David Benjamin5208fd42016-07-13 21:43:25 -04007391
David Benjaminca3d5452016-07-14 12:51:01 -04007392 var allAlgorithms []signatureAlgorithm
7393 for _, alg := range testSignatureAlgorithms {
7394 if alg.id != 0 {
7395 allAlgorithms = append(allAlgorithms, alg.id)
7396 }
7397 }
7398
Nick Harper60edffd2016-06-21 15:19:24 -07007399 // Make sure each signature algorithm works. Include some fake values in
7400 // the list and ensure they're ignored.
7401 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007402 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007403 if (ver.version < VersionTLS12) != (alg.id == 0) {
7404 continue
7405 }
7406
7407 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7408 // or remove it in C.
7409 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007410 continue
7411 }
Nick Harper60edffd2016-06-21 15:19:24 -07007412
David Benjamin3ef76972016-10-17 17:59:54 -04007413 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007414 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007415 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007416 shouldSignFail = true
7417 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007418 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007419 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007420 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7421 shouldSignFail = true
7422 shouldVerifyFail = true
7423 }
7424 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7425 // the curve has to match the hash size.
7426 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007427 shouldSignFail = true
7428 shouldVerifyFail = true
7429 }
7430
7431 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7432 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7433 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007434 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007435
7436 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007437 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007438 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007439 }
7440 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007441 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007442 }
David Benjamin000800a2014-11-14 01:43:59 -05007443
David Benjamin1fb125c2016-07-08 18:52:12 -07007444 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007445
David Benjamin7a41d372016-07-09 11:21:54 -07007446 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007447 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007448 config: Config{
7449 MaxVersion: ver.version,
7450 ClientAuth: RequireAnyClientCert,
7451 VerifySignatureAlgorithms: []signatureAlgorithm{
7452 fakeSigAlg1,
7453 alg.id,
7454 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007455 },
David Benjamin7a41d372016-07-09 11:21:54 -07007456 },
7457 flags: []string{
7458 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7459 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7460 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007461 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007462 },
David Benjamin3ef76972016-10-17 17:59:54 -04007463 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007464 expectedError: signError,
7465 expectedPeerSignatureAlgorithm: alg.id,
7466 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007467
David Benjamin7a41d372016-07-09 11:21:54 -07007468 testCases = append(testCases, testCase{
7469 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007470 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007471 config: Config{
7472 MaxVersion: ver.version,
7473 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7474 SignSignatureAlgorithms: []signatureAlgorithm{
7475 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007476 },
David Benjamin7a41d372016-07-09 11:21:54 -07007477 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007478 SkipECDSACurveCheck: shouldVerifyFail,
7479 IgnoreSignatureVersionChecks: shouldVerifyFail,
7480 // Some signature algorithms may not be advertised.
7481 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007482 },
David Benjamin7a41d372016-07-09 11:21:54 -07007483 },
7484 flags: []string{
7485 "-require-any-client-certificate",
7486 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7487 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007488 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007489 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007490 // Resume the session to assert the peer signature
7491 // algorithm is reported on both handshakes.
7492 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007493 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007494 expectedError: verifyError,
7495 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007496
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007497 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007498 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007499 testCases = append(testCases, testCase{
7500 testType: serverTest,
7501 name: "ServerAuth-Sign" + suffix,
7502 config: Config{
7503 MaxVersion: ver.version,
7504 CipherSuites: signingCiphers,
7505 VerifySignatureAlgorithms: []signatureAlgorithm{
7506 fakeSigAlg1,
7507 alg.id,
7508 fakeSigAlg2,
7509 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007510 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007511 flags: []string{
7512 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7513 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7514 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007515 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007516 },
7517 shouldFail: shouldSignFail,
7518 expectedError: signError,
7519 expectedPeerSignatureAlgorithm: alg.id,
7520 })
7521 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007522
7523 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007524 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007525 config: Config{
7526 MaxVersion: ver.version,
7527 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007528 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007529 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007530 alg.id,
7531 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007532 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007533 SkipECDSACurveCheck: shouldVerifyFail,
7534 IgnoreSignatureVersionChecks: shouldVerifyFail,
7535 // Some signature algorithms may not be advertised.
7536 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007537 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007538 },
7539 flags: []string{
7540 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7541 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007542 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007543 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007544 // Resume the session to assert the peer signature
7545 // algorithm is reported on both handshakes.
7546 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007547 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007548 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007549 })
David Benjamin5208fd42016-07-13 21:43:25 -04007550
David Benjamin3ef76972016-10-17 17:59:54 -04007551 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007552 testCases = append(testCases, testCase{
7553 testType: serverTest,
7554 name: "ClientAuth-InvalidSignature" + suffix,
7555 config: Config{
7556 MaxVersion: ver.version,
7557 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7558 SignSignatureAlgorithms: []signatureAlgorithm{
7559 alg.id,
7560 },
7561 Bugs: ProtocolBugs{
7562 InvalidSignature: true,
7563 },
7564 },
7565 flags: []string{
7566 "-require-any-client-certificate",
7567 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007568 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007569 },
7570 shouldFail: true,
7571 expectedError: ":BAD_SIGNATURE:",
7572 })
7573
7574 testCases = append(testCases, testCase{
7575 name: "ServerAuth-InvalidSignature" + suffix,
7576 config: Config{
7577 MaxVersion: ver.version,
7578 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7579 CipherSuites: signingCiphers,
7580 SignSignatureAlgorithms: []signatureAlgorithm{
7581 alg.id,
7582 },
7583 Bugs: ProtocolBugs{
7584 InvalidSignature: true,
7585 },
7586 },
David Benjamin69522112017-03-28 15:38:29 -05007587 flags: []string{
7588 "-enable-all-curves",
7589 "-enable-ed25519",
7590 },
David Benjamin5208fd42016-07-13 21:43:25 -04007591 shouldFail: true,
7592 expectedError: ":BAD_SIGNATURE:",
7593 })
7594 }
David Benjaminca3d5452016-07-14 12:51:01 -04007595
David Benjamin3ef76972016-10-17 17:59:54 -04007596 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007597 testCases = append(testCases, testCase{
7598 name: "ClientAuth-Sign-Negotiate" + suffix,
7599 config: Config{
7600 MaxVersion: ver.version,
7601 ClientAuth: RequireAnyClientCert,
7602 VerifySignatureAlgorithms: allAlgorithms,
7603 },
7604 flags: []string{
7605 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7606 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7607 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007608 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007609 "-signing-prefs", strconv.Itoa(int(alg.id)),
7610 },
7611 expectedPeerSignatureAlgorithm: alg.id,
7612 })
7613
7614 testCases = append(testCases, testCase{
7615 testType: serverTest,
7616 name: "ServerAuth-Sign-Negotiate" + suffix,
7617 config: Config{
7618 MaxVersion: ver.version,
7619 CipherSuites: signingCiphers,
7620 VerifySignatureAlgorithms: allAlgorithms,
7621 },
7622 flags: []string{
7623 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7624 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7625 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007626 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007627 "-signing-prefs", strconv.Itoa(int(alg.id)),
7628 },
7629 expectedPeerSignatureAlgorithm: alg.id,
7630 })
7631 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007632 }
David Benjamin000800a2014-11-14 01:43:59 -05007633 }
7634
Nick Harper60edffd2016-06-21 15:19:24 -07007635 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007636 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007637 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007638 config: Config{
7639 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007640 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007641 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007642 signatureECDSAWithP521AndSHA512,
7643 signatureRSAPKCS1WithSHA384,
7644 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007645 },
7646 },
7647 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007648 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7649 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007650 },
Nick Harper60edffd2016-06-21 15:19:24 -07007651 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007652 })
7653
7654 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007655 name: "ClientAuth-SignatureType-TLS13",
7656 config: Config{
7657 ClientAuth: RequireAnyClientCert,
7658 MaxVersion: VersionTLS13,
7659 VerifySignatureAlgorithms: []signatureAlgorithm{
7660 signatureECDSAWithP521AndSHA512,
7661 signatureRSAPKCS1WithSHA384,
7662 signatureRSAPSSWithSHA384,
7663 signatureECDSAWithSHA1,
7664 },
7665 },
7666 flags: []string{
7667 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7668 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7669 },
7670 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7671 })
7672
7673 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007674 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007675 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007677 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007679 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007680 signatureECDSAWithP521AndSHA512,
7681 signatureRSAPKCS1WithSHA384,
7682 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007683 },
7684 },
Nick Harper60edffd2016-06-21 15:19:24 -07007685 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007686 })
7687
Steven Valdez143e8b32016-07-11 13:19:03 -04007688 testCases = append(testCases, testCase{
7689 testType: serverTest,
7690 name: "ServerAuth-SignatureType-TLS13",
7691 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007692 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007693 VerifySignatureAlgorithms: []signatureAlgorithm{
7694 signatureECDSAWithP521AndSHA512,
7695 signatureRSAPKCS1WithSHA384,
7696 signatureRSAPSSWithSHA384,
7697 signatureECDSAWithSHA1,
7698 },
7699 },
7700 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7701 })
7702
David Benjamina95e9f32016-07-08 16:28:04 -07007703 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007704 testCases = append(testCases, testCase{
7705 testType: serverTest,
7706 name: "Verify-ClientAuth-SignatureType",
7707 config: Config{
7708 MaxVersion: VersionTLS12,
7709 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007710 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007711 signatureRSAPKCS1WithSHA256,
7712 },
7713 Bugs: ProtocolBugs{
7714 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7715 },
7716 },
7717 flags: []string{
7718 "-require-any-client-certificate",
7719 },
7720 shouldFail: true,
7721 expectedError: ":WRONG_SIGNATURE_TYPE:",
7722 })
7723
7724 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007725 testType: serverTest,
7726 name: "Verify-ClientAuth-SignatureType-TLS13",
7727 config: Config{
7728 MaxVersion: VersionTLS13,
7729 Certificates: []Certificate{rsaCertificate},
7730 SignSignatureAlgorithms: []signatureAlgorithm{
7731 signatureRSAPSSWithSHA256,
7732 },
7733 Bugs: ProtocolBugs{
7734 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7735 },
7736 },
7737 flags: []string{
7738 "-require-any-client-certificate",
7739 },
7740 shouldFail: true,
7741 expectedError: ":WRONG_SIGNATURE_TYPE:",
7742 })
7743
7744 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007745 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007746 config: Config{
7747 MaxVersion: VersionTLS12,
7748 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007749 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007750 signatureRSAPKCS1WithSHA256,
7751 },
7752 Bugs: ProtocolBugs{
7753 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7754 },
7755 },
7756 shouldFail: true,
7757 expectedError: ":WRONG_SIGNATURE_TYPE:",
7758 })
7759
Steven Valdez143e8b32016-07-11 13:19:03 -04007760 testCases = append(testCases, testCase{
7761 name: "Verify-ServerAuth-SignatureType-TLS13",
7762 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007763 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007764 SignSignatureAlgorithms: []signatureAlgorithm{
7765 signatureRSAPSSWithSHA256,
7766 },
7767 Bugs: ProtocolBugs{
7768 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7769 },
7770 },
7771 shouldFail: true,
7772 expectedError: ":WRONG_SIGNATURE_TYPE:",
7773 })
7774
David Benjamin51dd7d62016-07-08 16:07:01 -07007775 // Test that, if the list is missing, the peer falls back to SHA-1 in
7776 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007777 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007778 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007780 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007781 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007782 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007783 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007784 },
7785 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007786 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007787 },
7788 },
7789 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007790 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7791 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007792 },
7793 })
7794
7795 testCases = append(testCases, testCase{
7796 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007797 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007798 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007799 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007800 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007801 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007802 },
7803 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007804 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007805 },
7806 },
David Benjaminee32bea2016-08-17 13:36:44 -04007807 flags: []string{
7808 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7809 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7810 },
7811 })
7812
7813 testCases = append(testCases, testCase{
7814 name: "ClientAuth-SHA1-Fallback-ECDSA",
7815 config: Config{
7816 MaxVersion: VersionTLS12,
7817 ClientAuth: RequireAnyClientCert,
7818 VerifySignatureAlgorithms: []signatureAlgorithm{
7819 signatureECDSAWithSHA1,
7820 },
7821 Bugs: ProtocolBugs{
7822 NoSignatureAlgorithms: true,
7823 },
7824 },
7825 flags: []string{
7826 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7827 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7828 },
7829 })
7830
7831 testCases = append(testCases, testCase{
7832 testType: serverTest,
7833 name: "ServerAuth-SHA1-Fallback-ECDSA",
7834 config: Config{
7835 MaxVersion: VersionTLS12,
7836 VerifySignatureAlgorithms: []signatureAlgorithm{
7837 signatureECDSAWithSHA1,
7838 },
7839 Bugs: ProtocolBugs{
7840 NoSignatureAlgorithms: true,
7841 },
7842 },
7843 flags: []string{
7844 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7845 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7846 },
David Benjamin000800a2014-11-14 01:43:59 -05007847 })
David Benjamin72dc7832015-03-16 17:49:43 -04007848
David Benjamin51dd7d62016-07-08 16:07:01 -07007849 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007850 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007851 config: Config{
7852 MaxVersion: VersionTLS13,
7853 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007854 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007855 signatureRSAPKCS1WithSHA1,
7856 },
7857 Bugs: ProtocolBugs{
7858 NoSignatureAlgorithms: true,
7859 },
7860 },
7861 flags: []string{
7862 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7863 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7864 },
David Benjamin48901652016-08-01 12:12:47 -04007865 shouldFail: true,
7866 // An empty CertificateRequest signature algorithm list is a
7867 // syntax error in TLS 1.3.
7868 expectedError: ":DECODE_ERROR:",
7869 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007870 })
7871
7872 testCases = append(testCases, testCase{
7873 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007874 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007875 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007876 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007877 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007878 signatureRSAPKCS1WithSHA1,
7879 },
7880 Bugs: ProtocolBugs{
7881 NoSignatureAlgorithms: true,
7882 },
7883 },
7884 shouldFail: true,
7885 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7886 })
7887
David Benjaminb62d2872016-07-18 14:55:02 +02007888 // Test that hash preferences are enforced. BoringSSL does not implement
7889 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007890 testCases = append(testCases, testCase{
7891 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007892 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007894 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007895 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007896 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007897 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007898 },
7899 Bugs: ProtocolBugs{
7900 IgnorePeerSignatureAlgorithmPreferences: true,
7901 },
7902 },
7903 flags: []string{"-require-any-client-certificate"},
7904 shouldFail: true,
7905 expectedError: ":WRONG_SIGNATURE_TYPE:",
7906 })
7907
7908 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007909 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007911 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007913 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007914 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007915 },
7916 Bugs: ProtocolBugs{
7917 IgnorePeerSignatureAlgorithmPreferences: true,
7918 },
7919 },
7920 shouldFail: true,
7921 expectedError: ":WRONG_SIGNATURE_TYPE:",
7922 })
David Benjaminb62d2872016-07-18 14:55:02 +02007923 testCases = append(testCases, testCase{
7924 testType: serverTest,
7925 name: "ClientAuth-Enforced-TLS13",
7926 config: Config{
7927 MaxVersion: VersionTLS13,
7928 Certificates: []Certificate{rsaCertificate},
7929 SignSignatureAlgorithms: []signatureAlgorithm{
7930 signatureRSAPKCS1WithMD5,
7931 },
7932 Bugs: ProtocolBugs{
7933 IgnorePeerSignatureAlgorithmPreferences: true,
7934 IgnoreSignatureVersionChecks: true,
7935 },
7936 },
7937 flags: []string{"-require-any-client-certificate"},
7938 shouldFail: true,
7939 expectedError: ":WRONG_SIGNATURE_TYPE:",
7940 })
7941
7942 testCases = append(testCases, testCase{
7943 name: "ServerAuth-Enforced-TLS13",
7944 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007945 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007946 SignSignatureAlgorithms: []signatureAlgorithm{
7947 signatureRSAPKCS1WithMD5,
7948 },
7949 Bugs: ProtocolBugs{
7950 IgnorePeerSignatureAlgorithmPreferences: true,
7951 IgnoreSignatureVersionChecks: true,
7952 },
7953 },
7954 shouldFail: true,
7955 expectedError: ":WRONG_SIGNATURE_TYPE:",
7956 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007957
7958 // Test that the agreed upon digest respects the client preferences and
7959 // the server digests.
7960 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007961 name: "NoCommonAlgorithms-Digests",
7962 config: Config{
7963 MaxVersion: VersionTLS12,
7964 ClientAuth: RequireAnyClientCert,
7965 VerifySignatureAlgorithms: []signatureAlgorithm{
7966 signatureRSAPKCS1WithSHA512,
7967 signatureRSAPKCS1WithSHA1,
7968 },
7969 },
7970 flags: []string{
7971 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7972 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7973 "-digest-prefs", "SHA256",
7974 },
7975 shouldFail: true,
7976 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7977 })
7978 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007979 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007980 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007981 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007982 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007983 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007984 signatureRSAPKCS1WithSHA512,
7985 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007986 },
7987 },
7988 flags: []string{
7989 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7990 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007991 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007992 },
David Benjaminca3d5452016-07-14 12:51:01 -04007993 shouldFail: true,
7994 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7995 })
7996 testCases = append(testCases, testCase{
7997 name: "NoCommonAlgorithms-TLS13",
7998 config: Config{
7999 MaxVersion: VersionTLS13,
8000 ClientAuth: RequireAnyClientCert,
8001 VerifySignatureAlgorithms: []signatureAlgorithm{
8002 signatureRSAPSSWithSHA512,
8003 signatureRSAPSSWithSHA384,
8004 },
8005 },
8006 flags: []string{
8007 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8008 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8009 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8010 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008011 shouldFail: true,
8012 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008013 })
8014 testCases = append(testCases, testCase{
8015 name: "Agree-Digest-SHA256",
8016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008017 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008018 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008019 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008020 signatureRSAPKCS1WithSHA1,
8021 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008022 },
8023 },
8024 flags: []string{
8025 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8026 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008027 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008028 },
Nick Harper60edffd2016-06-21 15:19:24 -07008029 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008030 })
8031 testCases = append(testCases, testCase{
8032 name: "Agree-Digest-SHA1",
8033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008034 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008035 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008036 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008037 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008038 },
8039 },
8040 flags: []string{
8041 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8042 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008043 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008044 },
Nick Harper60edffd2016-06-21 15:19:24 -07008045 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008046 })
8047 testCases = append(testCases, testCase{
8048 name: "Agree-Digest-Default",
8049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008050 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008051 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008052 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008053 signatureRSAPKCS1WithSHA256,
8054 signatureECDSAWithP256AndSHA256,
8055 signatureRSAPKCS1WithSHA1,
8056 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008057 },
8058 },
8059 flags: []string{
8060 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8061 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8062 },
Nick Harper60edffd2016-06-21 15:19:24 -07008063 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008064 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008065
David Benjaminca3d5452016-07-14 12:51:01 -04008066 // Test that the signing preference list may include extra algorithms
8067 // without negotiation problems.
8068 testCases = append(testCases, testCase{
8069 testType: serverTest,
8070 name: "FilterExtraAlgorithms",
8071 config: Config{
8072 MaxVersion: VersionTLS12,
8073 VerifySignatureAlgorithms: []signatureAlgorithm{
8074 signatureRSAPKCS1WithSHA256,
8075 },
8076 },
8077 flags: []string{
8078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8080 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8081 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8082 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8083 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8084 },
8085 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8086 })
8087
David Benjamin4c3ddf72016-06-29 18:13:53 -04008088 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8089 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008090 testCases = append(testCases, testCase{
8091 name: "CheckLeafCurve",
8092 config: Config{
8093 MaxVersion: VersionTLS12,
8094 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008095 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008096 },
8097 flags: []string{"-p384-only"},
8098 shouldFail: true,
8099 expectedError: ":BAD_ECC_CERT:",
8100 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008101
8102 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8103 testCases = append(testCases, testCase{
8104 name: "CheckLeafCurve-TLS13",
8105 config: Config{
8106 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008107 Certificates: []Certificate{ecdsaP256Certificate},
8108 },
8109 flags: []string{"-p384-only"},
8110 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008111
8112 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8113 testCases = append(testCases, testCase{
8114 name: "ECDSACurveMismatch-Verify-TLS12",
8115 config: Config{
8116 MaxVersion: VersionTLS12,
8117 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8118 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008119 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008120 signatureECDSAWithP384AndSHA384,
8121 },
8122 },
8123 })
8124
8125 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8126 testCases = append(testCases, testCase{
8127 name: "ECDSACurveMismatch-Verify-TLS13",
8128 config: Config{
8129 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008130 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008131 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008132 signatureECDSAWithP384AndSHA384,
8133 },
8134 Bugs: ProtocolBugs{
8135 SkipECDSACurveCheck: true,
8136 },
8137 },
8138 shouldFail: true,
8139 expectedError: ":WRONG_SIGNATURE_TYPE:",
8140 })
8141
8142 // Signature algorithm selection in TLS 1.3 should take the curve into
8143 // account.
8144 testCases = append(testCases, testCase{
8145 testType: serverTest,
8146 name: "ECDSACurveMismatch-Sign-TLS13",
8147 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008148 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008149 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008150 signatureECDSAWithP384AndSHA384,
8151 signatureECDSAWithP256AndSHA256,
8152 },
8153 },
8154 flags: []string{
8155 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8156 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8157 },
8158 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8159 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008160
8161 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8162 // server does not attempt to sign in that case.
8163 testCases = append(testCases, testCase{
8164 testType: serverTest,
8165 name: "RSA-PSS-Large",
8166 config: Config{
8167 MaxVersion: VersionTLS13,
8168 VerifySignatureAlgorithms: []signatureAlgorithm{
8169 signatureRSAPSSWithSHA512,
8170 },
8171 },
8172 flags: []string{
8173 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8174 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8175 },
8176 shouldFail: true,
8177 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8178 })
David Benjamin57e929f2016-08-30 00:30:38 -04008179
8180 // Test that RSA-PSS is enabled by default for TLS 1.2.
8181 testCases = append(testCases, testCase{
8182 testType: clientTest,
8183 name: "RSA-PSS-Default-Verify",
8184 config: Config{
8185 MaxVersion: VersionTLS12,
8186 SignSignatureAlgorithms: []signatureAlgorithm{
8187 signatureRSAPSSWithSHA256,
8188 },
8189 },
8190 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8191 })
8192
8193 testCases = append(testCases, testCase{
8194 testType: serverTest,
8195 name: "RSA-PSS-Default-Sign",
8196 config: Config{
8197 MaxVersion: VersionTLS12,
8198 VerifySignatureAlgorithms: []signatureAlgorithm{
8199 signatureRSAPSSWithSHA256,
8200 },
8201 },
8202 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8203 })
David Benjamin69522112017-03-28 15:38:29 -05008204
8205 // TLS 1.1 and below has no way to advertise support for or negotiate
8206 // Ed25519's signature algorithm.
8207 testCases = append(testCases, testCase{
8208 testType: clientTest,
8209 name: "NoEd25519-TLS11-ServerAuth-Verify",
8210 config: Config{
8211 MaxVersion: VersionTLS11,
8212 Certificates: []Certificate{ed25519Certificate},
8213 Bugs: ProtocolBugs{
8214 // Sign with Ed25519 even though it is TLS 1.1.
8215 UseLegacySigningAlgorithm: signatureEd25519,
8216 },
8217 },
8218 flags: []string{"-enable-ed25519"},
8219 shouldFail: true,
8220 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8221 })
8222 testCases = append(testCases, testCase{
8223 testType: serverTest,
8224 name: "NoEd25519-TLS11-ServerAuth-Sign",
8225 config: Config{
8226 MaxVersion: VersionTLS11,
8227 },
8228 flags: []string{
8229 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8230 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8231 },
8232 shouldFail: true,
8233 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8234 })
8235 testCases = append(testCases, testCase{
8236 testType: serverTest,
8237 name: "NoEd25519-TLS11-ClientAuth-Verify",
8238 config: Config{
8239 MaxVersion: VersionTLS11,
8240 Certificates: []Certificate{ed25519Certificate},
8241 Bugs: ProtocolBugs{
8242 // Sign with Ed25519 even though it is TLS 1.1.
8243 UseLegacySigningAlgorithm: signatureEd25519,
8244 },
8245 },
8246 flags: []string{
8247 "-enable-ed25519",
8248 "-require-any-client-certificate",
8249 },
8250 shouldFail: true,
8251 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8252 })
8253 testCases = append(testCases, testCase{
8254 testType: clientTest,
8255 name: "NoEd25519-TLS11-ClientAuth-Sign",
8256 config: Config{
8257 MaxVersion: VersionTLS11,
8258 ClientAuth: RequireAnyClientCert,
8259 },
8260 flags: []string{
8261 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8262 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8263 },
8264 shouldFail: true,
8265 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8266 })
8267
8268 // Test Ed25519 is not advertised by default.
8269 testCases = append(testCases, testCase{
8270 testType: clientTest,
8271 name: "Ed25519DefaultDisable-NoAdvertise",
8272 config: Config{
8273 Certificates: []Certificate{ed25519Certificate},
8274 },
8275 shouldFail: true,
8276 expectedLocalError: "tls: no common signature algorithms",
8277 })
8278
8279 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8280 // preferences.
8281 testCases = append(testCases, testCase{
8282 testType: clientTest,
8283 name: "Ed25519DefaultDisable-NoAccept",
8284 config: Config{
8285 Certificates: []Certificate{ed25519Certificate},
8286 Bugs: ProtocolBugs{
8287 IgnorePeerSignatureAlgorithmPreferences: true,
8288 },
8289 },
8290 shouldFail: true,
8291 expectedLocalError: "remote error: illegal parameter",
8292 expectedError: ":WRONG_SIGNATURE_TYPE:",
8293 })
David Benjamin71c21b42017-04-14 17:05:40 -04008294
8295 // Test that configuring verify preferences changes what the client
8296 // advertises.
8297 testCases = append(testCases, testCase{
8298 name: "VerifyPreferences-Advertised",
8299 config: Config{
8300 Certificates: []Certificate{rsaCertificate},
8301 SignSignatureAlgorithms: []signatureAlgorithm{
8302 signatureRSAPSSWithSHA256,
8303 signatureRSAPSSWithSHA384,
8304 signatureRSAPSSWithSHA512,
8305 },
8306 },
8307 flags: []string{
8308 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8309 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8310 },
8311 })
8312
8313 // Test that the client advertises a set which the runner can find
8314 // nothing in common with.
8315 testCases = append(testCases, testCase{
8316 name: "VerifyPreferences-NoCommonAlgorithms",
8317 config: Config{
8318 Certificates: []Certificate{rsaCertificate},
8319 SignSignatureAlgorithms: []signatureAlgorithm{
8320 signatureRSAPSSWithSHA256,
8321 signatureRSAPSSWithSHA512,
8322 },
8323 },
8324 flags: []string{
8325 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8326 },
8327 shouldFail: true,
8328 expectedLocalError: "tls: no common signature algorithms",
8329 })
8330
8331 // Test that the client enforces its preferences when configured.
8332 testCases = append(testCases, testCase{
8333 name: "VerifyPreferences-Enforced",
8334 config: Config{
8335 Certificates: []Certificate{rsaCertificate},
8336 SignSignatureAlgorithms: []signatureAlgorithm{
8337 signatureRSAPSSWithSHA256,
8338 signatureRSAPSSWithSHA512,
8339 },
8340 Bugs: ProtocolBugs{
8341 IgnorePeerSignatureAlgorithmPreferences: true,
8342 },
8343 },
8344 flags: []string{
8345 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8346 },
8347 shouldFail: true,
8348 expectedLocalError: "remote error: illegal parameter",
8349 expectedError: ":WRONG_SIGNATURE_TYPE:",
8350 })
8351
8352 // Test that explicitly configuring Ed25519 is as good as changing the
8353 // boolean toggle.
8354 testCases = append(testCases, testCase{
8355 name: "VerifyPreferences-Ed25519",
8356 config: Config{
8357 Certificates: []Certificate{ed25519Certificate},
8358 },
8359 flags: []string{
8360 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8361 },
8362 })
David Benjamin000800a2014-11-14 01:43:59 -05008363}
8364
David Benjamin83f90402015-01-27 01:09:43 -05008365// timeouts is the retransmit schedule for BoringSSL. It doubles and
8366// caps at 60 seconds. On the 13th timeout, it gives up.
8367var timeouts = []time.Duration{
8368 1 * time.Second,
8369 2 * time.Second,
8370 4 * time.Second,
8371 8 * time.Second,
8372 16 * time.Second,
8373 32 * time.Second,
8374 60 * time.Second,
8375 60 * time.Second,
8376 60 * time.Second,
8377 60 * time.Second,
8378 60 * time.Second,
8379 60 * time.Second,
8380 60 * time.Second,
8381}
8382
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008383// shortTimeouts is an alternate set of timeouts which would occur if the
8384// initial timeout duration was set to 250ms.
8385var shortTimeouts = []time.Duration{
8386 250 * time.Millisecond,
8387 500 * time.Millisecond,
8388 1 * time.Second,
8389 2 * time.Second,
8390 4 * time.Second,
8391 8 * time.Second,
8392 16 * time.Second,
8393 32 * time.Second,
8394 60 * time.Second,
8395 60 * time.Second,
8396 60 * time.Second,
8397 60 * time.Second,
8398 60 * time.Second,
8399}
8400
David Benjamin83f90402015-01-27 01:09:43 -05008401func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008402 // These tests work by coordinating some behavior on both the shim and
8403 // the runner.
8404 //
8405 // TimeoutSchedule configures the runner to send a series of timeout
8406 // opcodes to the shim (see packetAdaptor) immediately before reading
8407 // each peer handshake flight N. The timeout opcode both simulates a
8408 // timeout in the shim and acts as a synchronization point to help the
8409 // runner bracket each handshake flight.
8410 //
8411 // We assume the shim does not read from the channel eagerly. It must
8412 // first wait until it has sent flight N and is ready to receive
8413 // handshake flight N+1. At this point, it will process the timeout
8414 // opcode. It must then immediately respond with a timeout ACK and act
8415 // as if the shim was idle for the specified amount of time.
8416 //
8417 // The runner then drops all packets received before the ACK and
8418 // continues waiting for flight N. This ordering results in one attempt
8419 // at sending flight N to be dropped. For the test to complete, the
8420 // shim must send flight N again, testing that the shim implements DTLS
8421 // retransmit on a timeout.
8422
Steven Valdez143e8b32016-07-11 13:19:03 -04008423 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008424 // likely be more epochs to cross and the final message's retransmit may
8425 // be more complex.
8426
David Benjamin11c82892017-02-23 20:40:31 -05008427 // Test that this is indeed the timeout schedule. Stress all
8428 // four patterns of handshake.
8429 for i := 1; i < len(timeouts); i++ {
8430 number := strconv.Itoa(i)
8431 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008432 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008433 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008435 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008436 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008437 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008438 },
8439 },
8440 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008441 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008442 })
David Benjamin11c82892017-02-23 20:40:31 -05008443 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008444 protocol: dtls,
8445 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008446 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008448 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008449 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008450 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008451 },
8452 },
8453 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008454 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008455 })
8456 }
David Benjamin11c82892017-02-23 20:40:31 -05008457
8458 // Test that exceeding the timeout schedule hits a read
8459 // timeout.
8460 testCases = append(testCases, testCase{
8461 protocol: dtls,
8462 name: "DTLS-Retransmit-Timeout",
8463 config: Config{
8464 MaxVersion: VersionTLS12,
8465 Bugs: ProtocolBugs{
8466 TimeoutSchedule: timeouts,
8467 },
8468 },
8469 resumeSession: true,
8470 flags: []string{"-async"},
8471 shouldFail: true,
8472 expectedError: ":READ_TIMEOUT_EXPIRED:",
8473 })
8474
8475 // Test that timeout handling has a fudge factor, due to API
8476 // problems.
8477 testCases = append(testCases, testCase{
8478 protocol: dtls,
8479 name: "DTLS-Retransmit-Fudge",
8480 config: Config{
8481 MaxVersion: VersionTLS12,
8482 Bugs: ProtocolBugs{
8483 TimeoutSchedule: []time.Duration{
8484 timeouts[0] - 10*time.Millisecond,
8485 },
8486 },
8487 },
8488 resumeSession: true,
8489 flags: []string{"-async"},
8490 })
8491
8492 // Test that the final Finished retransmitting isn't
8493 // duplicated if the peer badly fragments everything.
8494 testCases = append(testCases, testCase{
8495 testType: serverTest,
8496 protocol: dtls,
8497 name: "DTLS-Retransmit-Fragmented",
8498 config: Config{
8499 MaxVersion: VersionTLS12,
8500 Bugs: ProtocolBugs{
8501 TimeoutSchedule: []time.Duration{timeouts[0]},
8502 MaxHandshakeRecordLength: 2,
8503 },
8504 },
8505 flags: []string{"-async"},
8506 })
8507
8508 // Test the timeout schedule when a shorter initial timeout duration is set.
8509 testCases = append(testCases, testCase{
8510 protocol: dtls,
8511 name: "DTLS-Retransmit-Short-Client",
8512 config: Config{
8513 MaxVersion: VersionTLS12,
8514 Bugs: ProtocolBugs{
8515 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8516 },
8517 },
8518 resumeSession: true,
8519 flags: []string{
8520 "-async",
8521 "-initial-timeout-duration-ms", "250",
8522 },
8523 })
8524 testCases = append(testCases, testCase{
8525 protocol: dtls,
8526 testType: serverTest,
8527 name: "DTLS-Retransmit-Short-Server",
8528 config: Config{
8529 MaxVersion: VersionTLS12,
8530 Bugs: ProtocolBugs{
8531 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8532 },
8533 },
8534 resumeSession: true,
8535 flags: []string{
8536 "-async",
8537 "-initial-timeout-duration-ms", "250",
8538 },
8539 })
David Benjamin83f90402015-01-27 01:09:43 -05008540}
8541
David Benjaminc565ebb2015-04-03 04:06:36 -04008542func addExportKeyingMaterialTests() {
8543 for _, vers := range tlsVersions {
8544 if vers.version == VersionSSL30 {
8545 continue
8546 }
8547 testCases = append(testCases, testCase{
8548 name: "ExportKeyingMaterial-" + vers.name,
8549 config: Config{
8550 MaxVersion: vers.version,
8551 },
8552 exportKeyingMaterial: 1024,
8553 exportLabel: "label",
8554 exportContext: "context",
8555 useExportContext: true,
8556 })
8557 testCases = append(testCases, testCase{
8558 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8559 config: Config{
8560 MaxVersion: vers.version,
8561 },
8562 exportKeyingMaterial: 1024,
8563 })
8564 testCases = append(testCases, testCase{
8565 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8566 config: Config{
8567 MaxVersion: vers.version,
8568 },
8569 exportKeyingMaterial: 1024,
8570 useExportContext: true,
8571 })
8572 testCases = append(testCases, testCase{
8573 name: "ExportKeyingMaterial-Small-" + vers.name,
8574 config: Config{
8575 MaxVersion: vers.version,
8576 },
8577 exportKeyingMaterial: 1,
8578 exportLabel: "label",
8579 exportContext: "context",
8580 useExportContext: true,
8581 })
8582 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008583
David Benjaminc565ebb2015-04-03 04:06:36 -04008584 testCases = append(testCases, testCase{
8585 name: "ExportKeyingMaterial-SSL3",
8586 config: Config{
8587 MaxVersion: VersionSSL30,
8588 },
8589 exportKeyingMaterial: 1024,
8590 exportLabel: "label",
8591 exportContext: "context",
8592 useExportContext: true,
8593 shouldFail: true,
8594 expectedError: "failed to export keying material",
8595 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008596
8597 // Exporters work during a False Start.
8598 testCases = append(testCases, testCase{
8599 name: "ExportKeyingMaterial-FalseStart",
8600 config: Config{
8601 MaxVersion: VersionTLS12,
8602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8603 NextProtos: []string{"foo"},
8604 Bugs: ProtocolBugs{
8605 ExpectFalseStart: true,
8606 },
8607 },
8608 flags: []string{
8609 "-false-start",
8610 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008611 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008612 },
8613 shimWritesFirst: true,
8614 exportKeyingMaterial: 1024,
8615 exportLabel: "label",
8616 exportContext: "context",
8617 useExportContext: true,
8618 })
8619
8620 // Exporters do not work in the middle of a renegotiation. Test this by
8621 // triggering the exporter after every SSL_read call and configuring the
8622 // shim to run asynchronously.
8623 testCases = append(testCases, testCase{
8624 name: "ExportKeyingMaterial-Renegotiate",
8625 config: Config{
8626 MaxVersion: VersionTLS12,
8627 },
8628 renegotiate: 1,
8629 flags: []string{
8630 "-async",
8631 "-use-exporter-between-reads",
8632 "-renegotiate-freely",
8633 "-expect-total-renegotiations", "1",
8634 },
8635 shouldFail: true,
8636 expectedError: "failed to export keying material",
8637 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008638}
8639
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008640func addTLSUniqueTests() {
8641 for _, isClient := range []bool{false, true} {
8642 for _, isResumption := range []bool{false, true} {
8643 for _, hasEMS := range []bool{false, true} {
8644 var suffix string
8645 if isResumption {
8646 suffix = "Resume-"
8647 } else {
8648 suffix = "Full-"
8649 }
8650
8651 if hasEMS {
8652 suffix += "EMS-"
8653 } else {
8654 suffix += "NoEMS-"
8655 }
8656
8657 if isClient {
8658 suffix += "Client"
8659 } else {
8660 suffix += "Server"
8661 }
8662
8663 test := testCase{
8664 name: "TLSUnique-" + suffix,
8665 testTLSUnique: true,
8666 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008667 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008668 Bugs: ProtocolBugs{
8669 NoExtendedMasterSecret: !hasEMS,
8670 },
8671 },
8672 }
8673
8674 if isResumption {
8675 test.resumeSession = true
8676 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008677 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008678 Bugs: ProtocolBugs{
8679 NoExtendedMasterSecret: !hasEMS,
8680 },
8681 }
8682 }
8683
8684 if isResumption && !hasEMS {
8685 test.shouldFail = true
8686 test.expectedError = "failed to get tls-unique"
8687 }
8688
8689 testCases = append(testCases, test)
8690 }
8691 }
8692 }
8693}
8694
Adam Langley09505632015-07-30 18:10:13 -07008695func addCustomExtensionTests() {
8696 expectedContents := "custom extension"
8697 emptyString := ""
8698
8699 for _, isClient := range []bool{false, true} {
8700 suffix := "Server"
8701 flag := "-enable-server-custom-extension"
8702 testType := serverTest
8703 if isClient {
8704 suffix = "Client"
8705 flag = "-enable-client-custom-extension"
8706 testType = clientTest
8707 }
8708
8709 testCases = append(testCases, testCase{
8710 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008711 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008712 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008713 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008714 Bugs: ProtocolBugs{
8715 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008716 ExpectedCustomExtension: &expectedContents,
8717 },
8718 },
8719 flags: []string{flag},
8720 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008721 testCases = append(testCases, testCase{
8722 testType: testType,
8723 name: "CustomExtensions-" + suffix + "-TLS13",
8724 config: Config{
8725 MaxVersion: VersionTLS13,
8726 Bugs: ProtocolBugs{
8727 CustomExtension: expectedContents,
8728 ExpectedCustomExtension: &expectedContents,
8729 },
8730 },
8731 flags: []string{flag},
8732 })
Adam Langley09505632015-07-30 18:10:13 -07008733
Steven Valdez2a070722017-03-25 20:54:16 -05008734 // 0-RTT is not currently supported with Custom Extensions.
8735 testCases = append(testCases, testCase{
8736 testType: testType,
8737 name: "CustomExtensions-" + suffix + "-EarlyData",
8738 config: Config{
8739 MaxVersion: VersionTLS13,
8740 Bugs: ProtocolBugs{
8741 CustomExtension: expectedContents,
8742 ExpectedCustomExtension: &expectedContents,
8743 },
8744 },
8745 shouldFail: true,
8746 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8747 flags: []string{flag, "-enable-early-data"},
8748 })
8749
Adam Langley09505632015-07-30 18:10:13 -07008750 // If the parse callback fails, the handshake should also fail.
8751 testCases = append(testCases, testCase{
8752 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008753 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008754 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008755 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008756 Bugs: ProtocolBugs{
8757 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008758 ExpectedCustomExtension: &expectedContents,
8759 },
8760 },
David Benjamin399e7c92015-07-30 23:01:27 -04008761 flags: []string{flag},
8762 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008763 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8764 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008765 testCases = append(testCases, testCase{
8766 testType: testType,
8767 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8768 config: Config{
8769 MaxVersion: VersionTLS13,
8770 Bugs: ProtocolBugs{
8771 CustomExtension: expectedContents + "foo",
8772 ExpectedCustomExtension: &expectedContents,
8773 },
8774 },
8775 flags: []string{flag},
8776 shouldFail: true,
8777 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8778 })
Adam Langley09505632015-07-30 18:10:13 -07008779
8780 // If the add callback fails, the handshake should also fail.
8781 testCases = append(testCases, testCase{
8782 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008783 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008785 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008786 Bugs: ProtocolBugs{
8787 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008788 ExpectedCustomExtension: &expectedContents,
8789 },
8790 },
David Benjamin399e7c92015-07-30 23:01:27 -04008791 flags: []string{flag, "-custom-extension-fail-add"},
8792 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008793 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8794 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008795 testCases = append(testCases, testCase{
8796 testType: testType,
8797 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8798 config: Config{
8799 MaxVersion: VersionTLS13,
8800 Bugs: ProtocolBugs{
8801 CustomExtension: expectedContents,
8802 ExpectedCustomExtension: &expectedContents,
8803 },
8804 },
8805 flags: []string{flag, "-custom-extension-fail-add"},
8806 shouldFail: true,
8807 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8808 })
Adam Langley09505632015-07-30 18:10:13 -07008809
8810 // If the add callback returns zero, no extension should be
8811 // added.
8812 skipCustomExtension := expectedContents
8813 if isClient {
8814 // For the case where the client skips sending the
8815 // custom extension, the server must not “echo” it.
8816 skipCustomExtension = ""
8817 }
8818 testCases = append(testCases, testCase{
8819 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008820 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008822 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008823 Bugs: ProtocolBugs{
8824 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008825 ExpectedCustomExtension: &emptyString,
8826 },
8827 },
8828 flags: []string{flag, "-custom-extension-skip"},
8829 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008830 testCases = append(testCases, testCase{
8831 testType: testType,
8832 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8833 config: Config{
8834 MaxVersion: VersionTLS13,
8835 Bugs: ProtocolBugs{
8836 CustomExtension: skipCustomExtension,
8837 ExpectedCustomExtension: &emptyString,
8838 },
8839 },
8840 flags: []string{flag, "-custom-extension-skip"},
8841 })
Adam Langley09505632015-07-30 18:10:13 -07008842 }
8843
8844 // The custom extension add callback should not be called if the client
8845 // doesn't send the extension.
8846 testCases = append(testCases, testCase{
8847 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008848 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008849 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008850 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008851 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008852 ExpectedCustomExtension: &emptyString,
8853 },
8854 },
8855 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8856 })
Adam Langley2deb9842015-08-07 11:15:37 -07008857
Steven Valdez143e8b32016-07-11 13:19:03 -04008858 testCases = append(testCases, testCase{
8859 testType: serverTest,
8860 name: "CustomExtensions-NotCalled-Server-TLS13",
8861 config: Config{
8862 MaxVersion: VersionTLS13,
8863 Bugs: ProtocolBugs{
8864 ExpectedCustomExtension: &emptyString,
8865 },
8866 },
8867 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8868 })
8869
Adam Langley2deb9842015-08-07 11:15:37 -07008870 // Test an unknown extension from the server.
8871 testCases = append(testCases, testCase{
8872 testType: clientTest,
8873 name: "UnknownExtension-Client",
8874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008875 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008876 Bugs: ProtocolBugs{
8877 CustomExtension: expectedContents,
8878 },
8879 },
David Benjamin0c40a962016-08-01 12:05:50 -04008880 shouldFail: true,
8881 expectedError: ":UNEXPECTED_EXTENSION:",
8882 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008883 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008884 testCases = append(testCases, testCase{
8885 testType: clientTest,
8886 name: "UnknownExtension-Client-TLS13",
8887 config: Config{
8888 MaxVersion: VersionTLS13,
8889 Bugs: ProtocolBugs{
8890 CustomExtension: expectedContents,
8891 },
8892 },
David Benjamin0c40a962016-08-01 12:05:50 -04008893 shouldFail: true,
8894 expectedError: ":UNEXPECTED_EXTENSION:",
8895 expectedLocalError: "remote error: unsupported extension",
8896 })
David Benjamin490469f2016-10-05 22:44:38 -04008897 testCases = append(testCases, testCase{
8898 testType: clientTest,
8899 name: "UnknownUnencryptedExtension-Client-TLS13",
8900 config: Config{
8901 MaxVersion: VersionTLS13,
8902 Bugs: ProtocolBugs{
8903 CustomUnencryptedExtension: expectedContents,
8904 },
8905 },
8906 shouldFail: true,
8907 expectedError: ":UNEXPECTED_EXTENSION:",
8908 // The shim must send an alert, but alerts at this point do not
8909 // get successfully decrypted by the runner.
8910 expectedLocalError: "local error: bad record MAC",
8911 })
8912 testCases = append(testCases, testCase{
8913 testType: clientTest,
8914 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8915 config: Config{
8916 MaxVersion: VersionTLS13,
8917 Bugs: ProtocolBugs{
8918 SendUnencryptedALPN: "foo",
8919 },
8920 },
8921 flags: []string{
8922 "-advertise-alpn", "\x03foo\x03bar",
8923 },
8924 shouldFail: true,
8925 expectedError: ":UNEXPECTED_EXTENSION:",
8926 // The shim must send an alert, but alerts at this point do not
8927 // get successfully decrypted by the runner.
8928 expectedLocalError: "local error: bad record MAC",
8929 })
David Benjamin0c40a962016-08-01 12:05:50 -04008930
8931 // Test a known but unoffered extension from the server.
8932 testCases = append(testCases, testCase{
8933 testType: clientTest,
8934 name: "UnofferedExtension-Client",
8935 config: Config{
8936 MaxVersion: VersionTLS12,
8937 Bugs: ProtocolBugs{
8938 SendALPN: "alpn",
8939 },
8940 },
8941 shouldFail: true,
8942 expectedError: ":UNEXPECTED_EXTENSION:",
8943 expectedLocalError: "remote error: unsupported extension",
8944 })
8945 testCases = append(testCases, testCase{
8946 testType: clientTest,
8947 name: "UnofferedExtension-Client-TLS13",
8948 config: Config{
8949 MaxVersion: VersionTLS13,
8950 Bugs: ProtocolBugs{
8951 SendALPN: "alpn",
8952 },
8953 },
8954 shouldFail: true,
8955 expectedError: ":UNEXPECTED_EXTENSION:",
8956 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008957 })
Adam Langley09505632015-07-30 18:10:13 -07008958}
8959
David Benjaminb36a3952015-12-01 18:53:13 -05008960func addRSAClientKeyExchangeTests() {
8961 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8962 testCases = append(testCases, testCase{
8963 testType: serverTest,
8964 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8965 config: Config{
8966 // Ensure the ClientHello version and final
8967 // version are different, to detect if the
8968 // server uses the wrong one.
8969 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008970 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008971 Bugs: ProtocolBugs{
8972 BadRSAClientKeyExchange: bad,
8973 },
8974 },
8975 shouldFail: true,
8976 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8977 })
8978 }
David Benjamine63d9d72016-09-19 18:27:34 -04008979
8980 // The server must compare whatever was in ClientHello.version for the
8981 // RSA premaster.
8982 testCases = append(testCases, testCase{
8983 testType: serverTest,
8984 name: "SendClientVersion-RSA",
8985 config: Config{
8986 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8987 Bugs: ProtocolBugs{
8988 SendClientVersion: 0x1234,
8989 },
8990 },
8991 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8992 })
David Benjaminb36a3952015-12-01 18:53:13 -05008993}
8994
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008995var testCurves = []struct {
8996 name string
8997 id CurveID
8998}{
Adam Langley764ab982017-03-10 18:01:30 -08008999 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009000 {"P-256", CurveP256},
9001 {"P-384", CurveP384},
9002 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009003 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009004}
9005
Steven Valdez5440fe02016-07-18 12:40:30 -04009006const bogusCurve = 0x1234
9007
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009008func addCurveTests() {
9009 for _, curve := range testCurves {
9010 testCases = append(testCases, testCase{
9011 name: "CurveTest-Client-" + curve.name,
9012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009013 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9015 CurvePreferences: []CurveID{curve.id},
9016 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009017 flags: []string{
9018 "-enable-all-curves",
9019 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9020 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009021 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009022 })
9023 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009024 name: "CurveTest-Client-" + curve.name + "-TLS13",
9025 config: Config{
9026 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009027 CurvePreferences: []CurveID{curve.id},
9028 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009029 flags: []string{
9030 "-enable-all-curves",
9031 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9032 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009033 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009034 })
9035 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009036 testType: serverTest,
9037 name: "CurveTest-Server-" + curve.name,
9038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009039 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009040 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9041 CurvePreferences: []CurveID{curve.id},
9042 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009043 flags: []string{
9044 "-enable-all-curves",
9045 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9046 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009047 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009048 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009049 testCases = append(testCases, testCase{
9050 testType: serverTest,
9051 name: "CurveTest-Server-" + curve.name + "-TLS13",
9052 config: Config{
9053 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009054 CurvePreferences: []CurveID{curve.id},
9055 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009056 flags: []string{
9057 "-enable-all-curves",
9058 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9059 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009060 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009061 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009062 }
David Benjamin241ae832016-01-15 03:04:54 -05009063
9064 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009065 testCases = append(testCases, testCase{
9066 testType: serverTest,
9067 name: "UnknownCurve",
9068 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009069 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009070 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9071 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9072 },
9073 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009074
Steven Valdez803c77a2016-09-06 14:13:43 -04009075 // The server must be tolerant to bogus curves.
9076 testCases = append(testCases, testCase{
9077 testType: serverTest,
9078 name: "UnknownCurve-TLS13",
9079 config: Config{
9080 MaxVersion: VersionTLS13,
9081 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9082 },
9083 })
9084
David Benjamin4c3ddf72016-06-29 18:13:53 -04009085 // The server must not consider ECDHE ciphers when there are no
9086 // supported curves.
9087 testCases = append(testCases, testCase{
9088 testType: serverTest,
9089 name: "NoSupportedCurves",
9090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009091 MaxVersion: VersionTLS12,
9092 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9093 Bugs: ProtocolBugs{
9094 NoSupportedCurves: true,
9095 },
9096 },
9097 shouldFail: true,
9098 expectedError: ":NO_SHARED_CIPHER:",
9099 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009100 testCases = append(testCases, testCase{
9101 testType: serverTest,
9102 name: "NoSupportedCurves-TLS13",
9103 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009104 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009105 Bugs: ProtocolBugs{
9106 NoSupportedCurves: true,
9107 },
9108 },
9109 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009110 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009111 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009112
9113 // The server must fall back to another cipher when there are no
9114 // supported curves.
9115 testCases = append(testCases, testCase{
9116 testType: serverTest,
9117 name: "NoCommonCurves",
9118 config: Config{
9119 MaxVersion: VersionTLS12,
9120 CipherSuites: []uint16{
9121 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009122 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009123 },
9124 CurvePreferences: []CurveID{CurveP224},
9125 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009126 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009127 })
9128
9129 // The client must reject bogus curves and disabled curves.
9130 testCases = append(testCases, testCase{
9131 name: "BadECDHECurve",
9132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009133 MaxVersion: VersionTLS12,
9134 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9135 Bugs: ProtocolBugs{
9136 SendCurve: bogusCurve,
9137 },
9138 },
9139 shouldFail: true,
9140 expectedError: ":WRONG_CURVE:",
9141 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009142 testCases = append(testCases, testCase{
9143 name: "BadECDHECurve-TLS13",
9144 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009145 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009146 Bugs: ProtocolBugs{
9147 SendCurve: bogusCurve,
9148 },
9149 },
9150 shouldFail: true,
9151 expectedError: ":WRONG_CURVE:",
9152 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009153
9154 testCases = append(testCases, testCase{
9155 name: "UnsupportedCurve",
9156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009157 MaxVersion: VersionTLS12,
9158 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9159 CurvePreferences: []CurveID{CurveP256},
9160 Bugs: ProtocolBugs{
9161 IgnorePeerCurvePreferences: true,
9162 },
9163 },
9164 flags: []string{"-p384-only"},
9165 shouldFail: true,
9166 expectedError: ":WRONG_CURVE:",
9167 })
9168
David Benjamin4f921572016-07-17 14:20:10 +02009169 testCases = append(testCases, testCase{
9170 // TODO(davidben): Add a TLS 1.3 version where
9171 // HelloRetryRequest requests an unsupported curve.
9172 name: "UnsupportedCurve-ServerHello-TLS13",
9173 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009174 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009175 CurvePreferences: []CurveID{CurveP384},
9176 Bugs: ProtocolBugs{
9177 SendCurve: CurveP256,
9178 },
9179 },
9180 flags: []string{"-p384-only"},
9181 shouldFail: true,
9182 expectedError: ":WRONG_CURVE:",
9183 })
9184
David Benjamin4c3ddf72016-06-29 18:13:53 -04009185 // Test invalid curve points.
9186 testCases = append(testCases, testCase{
9187 name: "InvalidECDHPoint-Client",
9188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009189 MaxVersion: VersionTLS12,
9190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9191 CurvePreferences: []CurveID{CurveP256},
9192 Bugs: ProtocolBugs{
9193 InvalidECDHPoint: true,
9194 },
9195 },
9196 shouldFail: true,
9197 expectedError: ":INVALID_ENCODING:",
9198 })
9199 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009200 name: "InvalidECDHPoint-Client-TLS13",
9201 config: Config{
9202 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009203 CurvePreferences: []CurveID{CurveP256},
9204 Bugs: ProtocolBugs{
9205 InvalidECDHPoint: true,
9206 },
9207 },
9208 shouldFail: true,
9209 expectedError: ":INVALID_ENCODING:",
9210 })
9211 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009212 testType: serverTest,
9213 name: "InvalidECDHPoint-Server",
9214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009215 MaxVersion: VersionTLS12,
9216 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9217 CurvePreferences: []CurveID{CurveP256},
9218 Bugs: ProtocolBugs{
9219 InvalidECDHPoint: true,
9220 },
9221 },
9222 shouldFail: true,
9223 expectedError: ":INVALID_ENCODING:",
9224 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009225 testCases = append(testCases, testCase{
9226 testType: serverTest,
9227 name: "InvalidECDHPoint-Server-TLS13",
9228 config: Config{
9229 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009230 CurvePreferences: []CurveID{CurveP256},
9231 Bugs: ProtocolBugs{
9232 InvalidECDHPoint: true,
9233 },
9234 },
9235 shouldFail: true,
9236 expectedError: ":INVALID_ENCODING:",
9237 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009238
9239 // The previous curve ID should be reported on TLS 1.2 resumption.
9240 testCases = append(testCases, testCase{
9241 name: "CurveID-Resume-Client",
9242 config: Config{
9243 MaxVersion: VersionTLS12,
9244 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9245 CurvePreferences: []CurveID{CurveX25519},
9246 },
9247 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9248 resumeSession: true,
9249 })
9250 testCases = append(testCases, testCase{
9251 testType: serverTest,
9252 name: "CurveID-Resume-Server",
9253 config: Config{
9254 MaxVersion: VersionTLS12,
9255 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9256 CurvePreferences: []CurveID{CurveX25519},
9257 },
9258 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9259 resumeSession: true,
9260 })
9261
9262 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9263 // one should be reported.
9264 testCases = append(testCases, testCase{
9265 name: "CurveID-Resume-Client-TLS13",
9266 config: Config{
9267 MaxVersion: VersionTLS13,
9268 CurvePreferences: []CurveID{CurveX25519},
9269 },
9270 resumeConfig: &Config{
9271 MaxVersion: VersionTLS13,
9272 CurvePreferences: []CurveID{CurveP256},
9273 },
9274 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009275 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9276 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009277 },
9278 resumeSession: true,
9279 })
9280 testCases = append(testCases, testCase{
9281 testType: serverTest,
9282 name: "CurveID-Resume-Server-TLS13",
9283 config: Config{
9284 MaxVersion: VersionTLS13,
9285 CurvePreferences: []CurveID{CurveX25519},
9286 },
9287 resumeConfig: &Config{
9288 MaxVersion: VersionTLS13,
9289 CurvePreferences: []CurveID{CurveP256},
9290 },
9291 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009292 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9293 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009294 },
9295 resumeSession: true,
9296 })
David Benjamina81967b2016-12-22 09:16:57 -05009297
9298 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9299 testCases = append(testCases, testCase{
9300 name: "PointFormat-ServerHello-TLS12",
9301 config: Config{
9302 MaxVersion: VersionTLS12,
9303 Bugs: ProtocolBugs{
9304 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9305 },
9306 },
9307 })
9308 testCases = append(testCases, testCase{
9309 name: "PointFormat-EncryptedExtensions-TLS13",
9310 config: Config{
9311 MaxVersion: VersionTLS13,
9312 Bugs: ProtocolBugs{
9313 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9314 },
9315 },
9316 shouldFail: true,
9317 expectedError: ":ERROR_PARSING_EXTENSION:",
9318 })
9319
9320 // Test that we tolerate unknown point formats, as long as
9321 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9322 // check they are still functional.
9323 testCases = append(testCases, testCase{
9324 name: "PointFormat-Client-Tolerance",
9325 config: Config{
9326 MaxVersion: VersionTLS12,
9327 Bugs: ProtocolBugs{
9328 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9329 },
9330 },
9331 })
9332 testCases = append(testCases, testCase{
9333 testType: serverTest,
9334 name: "PointFormat-Server-Tolerance",
9335 config: Config{
9336 MaxVersion: VersionTLS12,
9337 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9338 Bugs: ProtocolBugs{
9339 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9340 },
9341 },
9342 })
9343
9344 // Test TLS 1.2 does not require the point format extension to be
9345 // present.
9346 testCases = append(testCases, testCase{
9347 name: "PointFormat-Client-Missing",
9348 config: Config{
9349 MaxVersion: VersionTLS12,
9350 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9351 Bugs: ProtocolBugs{
9352 SendSupportedPointFormats: []byte{},
9353 },
9354 },
9355 })
9356 testCases = append(testCases, testCase{
9357 testType: serverTest,
9358 name: "PointFormat-Server-Missing",
9359 config: Config{
9360 MaxVersion: VersionTLS12,
9361 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9362 Bugs: ProtocolBugs{
9363 SendSupportedPointFormats: []byte{},
9364 },
9365 },
9366 })
9367
9368 // If the point format extension is present, uncompressed points must be
9369 // offered. BoringSSL requires this whether or not ECDHE is used.
9370 testCases = append(testCases, testCase{
9371 name: "PointFormat-Client-MissingUncompressed",
9372 config: Config{
9373 MaxVersion: VersionTLS12,
9374 Bugs: ProtocolBugs{
9375 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9376 },
9377 },
9378 shouldFail: true,
9379 expectedError: ":ERROR_PARSING_EXTENSION:",
9380 })
9381 testCases = append(testCases, testCase{
9382 testType: serverTest,
9383 name: "PointFormat-Server-MissingUncompressed",
9384 config: Config{
9385 MaxVersion: VersionTLS12,
9386 Bugs: ProtocolBugs{
9387 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9388 },
9389 },
9390 shouldFail: true,
9391 expectedError: ":ERROR_PARSING_EXTENSION:",
9392 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009393}
9394
David Benjaminc9ae27c2016-06-24 22:56:37 -04009395func addTLS13RecordTests() {
9396 testCases = append(testCases, testCase{
9397 name: "TLS13-RecordPadding",
9398 config: Config{
9399 MaxVersion: VersionTLS13,
9400 MinVersion: VersionTLS13,
9401 Bugs: ProtocolBugs{
9402 RecordPadding: 10,
9403 },
9404 },
9405 })
9406
9407 testCases = append(testCases, testCase{
9408 name: "TLS13-EmptyRecords",
9409 config: Config{
9410 MaxVersion: VersionTLS13,
9411 MinVersion: VersionTLS13,
9412 Bugs: ProtocolBugs{
9413 OmitRecordContents: true,
9414 },
9415 },
9416 shouldFail: true,
9417 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9418 })
9419
9420 testCases = append(testCases, testCase{
9421 name: "TLS13-OnlyPadding",
9422 config: Config{
9423 MaxVersion: VersionTLS13,
9424 MinVersion: VersionTLS13,
9425 Bugs: ProtocolBugs{
9426 OmitRecordContents: true,
9427 RecordPadding: 10,
9428 },
9429 },
9430 shouldFail: true,
9431 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9432 })
9433
9434 testCases = append(testCases, testCase{
9435 name: "TLS13-WrongOuterRecord",
9436 config: Config{
9437 MaxVersion: VersionTLS13,
9438 MinVersion: VersionTLS13,
9439 Bugs: ProtocolBugs{
9440 OuterRecordType: recordTypeHandshake,
9441 },
9442 },
9443 shouldFail: true,
9444 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9445 })
9446}
9447
Steven Valdez5b986082016-09-01 12:29:49 -04009448func addSessionTicketTests() {
9449 testCases = append(testCases, testCase{
9450 // In TLS 1.2 and below, empty NewSessionTicket messages
9451 // mean the server changed its mind on sending a ticket.
9452 name: "SendEmptySessionTicket",
9453 config: Config{
9454 MaxVersion: VersionTLS12,
9455 Bugs: ProtocolBugs{
9456 SendEmptySessionTicket: true,
9457 },
9458 },
9459 flags: []string{"-expect-no-session"},
9460 })
9461
9462 // Test that the server ignores unknown PSK modes.
9463 testCases = append(testCases, testCase{
9464 testType: serverTest,
9465 name: "TLS13-SendUnknownModeSessionTicket-Server",
9466 config: Config{
9467 MaxVersion: VersionTLS13,
9468 Bugs: ProtocolBugs{
9469 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009470 },
9471 },
9472 resumeSession: true,
9473 expectedResumeVersion: VersionTLS13,
9474 })
9475
Steven Valdeza833c352016-11-01 13:39:36 -04009476 // Test that the server does not send session tickets with no matching key exchange mode.
9477 testCases = append(testCases, testCase{
9478 testType: serverTest,
9479 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9480 config: Config{
9481 MaxVersion: VersionTLS13,
9482 Bugs: ProtocolBugs{
9483 SendPSKKeyExchangeModes: []byte{0x1a},
9484 ExpectNoNewSessionTicket: true,
9485 },
9486 },
9487 })
9488
9489 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009490 testCases = append(testCases, testCase{
9491 testType: serverTest,
9492 name: "TLS13-SendBadKEModeSessionTicket-Server",
9493 config: Config{
9494 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009495 },
9496 resumeConfig: &Config{
9497 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009498 Bugs: ProtocolBugs{
9499 SendPSKKeyExchangeModes: []byte{0x1a},
9500 },
9501 },
9502 resumeSession: true,
9503 expectResumeRejected: true,
9504 })
9505
Steven Valdeza833c352016-11-01 13:39:36 -04009506 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009507 testCases = append(testCases, testCase{
9508 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009509 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009510 config: Config{
9511 MaxVersion: VersionTLS13,
9512 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009513 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009514 },
9515 },
Steven Valdeza833c352016-11-01 13:39:36 -04009516 resumeSession: true,
9517 flags: []string{
9518 "-resumption-delay", "10",
9519 },
Steven Valdez5b986082016-09-01 12:29:49 -04009520 })
9521
Steven Valdeza833c352016-11-01 13:39:36 -04009522 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009523 testCases = append(testCases, testCase{
9524 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009525 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009526 config: Config{
9527 MaxVersion: VersionTLS13,
9528 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009529 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009530 },
9531 },
Steven Valdeza833c352016-11-01 13:39:36 -04009532 resumeSession: true,
9533 shouldFail: true,
9534 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009535 })
9536
David Benjamin35ac5b72017-03-03 15:05:56 -05009537 // Test that the server's ticket age skew reporting works.
9538 testCases = append(testCases, testCase{
9539 testType: serverTest,
9540 name: "TLS13-TicketAgeSkew-Forward",
9541 config: Config{
9542 MaxVersion: VersionTLS13,
9543 Bugs: ProtocolBugs{
9544 SendTicketAge: 15 * time.Second,
9545 },
9546 },
David Benjamin065d7332017-03-26 10:51:43 -05009547 resumeSession: true,
9548 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009549 flags: []string{
9550 "-resumption-delay", "10",
9551 "-expect-ticket-age-skew", "5",
9552 },
9553 })
9554 testCases = append(testCases, testCase{
9555 testType: serverTest,
9556 name: "TLS13-TicketAgeSkew-Backward",
9557 config: Config{
9558 MaxVersion: VersionTLS13,
9559 Bugs: ProtocolBugs{
9560 SendTicketAge: 5 * time.Second,
9561 },
9562 },
David Benjamin065d7332017-03-26 10:51:43 -05009563 resumeSession: true,
9564 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009565 flags: []string{
9566 "-resumption-delay", "10",
9567 "-expect-ticket-age-skew", "-5",
9568 },
9569 })
9570
Steven Valdez08b65f42016-12-07 15:29:45 -05009571 testCases = append(testCases, testCase{
9572 testType: clientTest,
9573 name: "TLS13-SendTicketEarlyDataInfo",
9574 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009575 MaxVersion: VersionTLS13,
9576 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009577 },
9578 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009579 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009580 "-expect-early-data-info",
9581 },
9582 })
9583
David Benjamin9b160662017-01-25 19:53:43 -05009584 // Test that 0-RTT tickets are ignored in clients unless opted in.
9585 testCases = append(testCases, testCase{
9586 testType: clientTest,
9587 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9588 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009589 MaxVersion: VersionTLS13,
9590 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009591 },
9592 })
9593
Steven Valdez08b65f42016-12-07 15:29:45 -05009594 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009595 testType: clientTest,
9596 name: "TLS13-DuplicateTicketEarlyDataInfo",
9597 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009598 MaxVersion: VersionTLS13,
9599 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009600 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009601 DuplicateTicketEarlyDataInfo: true,
9602 },
9603 },
9604 shouldFail: true,
9605 expectedError: ":DUPLICATE_EXTENSION:",
9606 expectedLocalError: "remote error: illegal parameter",
9607 })
9608
9609 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009610 testType: serverTest,
9611 name: "TLS13-ExpectTicketEarlyDataInfo",
9612 config: Config{
9613 MaxVersion: VersionTLS13,
9614 Bugs: ProtocolBugs{
9615 ExpectTicketEarlyDataInfo: true,
9616 },
9617 },
9618 flags: []string{
9619 "-enable-early-data",
9620 },
9621 })
David Benjamin17b30832017-01-28 14:00:32 -05009622
9623 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9624 // is honored.
9625 testCases = append(testCases, testCase{
9626 testType: clientTest,
9627 name: "TLS13-HonorServerSessionTicketLifetime",
9628 config: Config{
9629 MaxVersion: VersionTLS13,
9630 Bugs: ProtocolBugs{
9631 SendTicketLifetime: 20 * time.Second,
9632 },
9633 },
9634 flags: []string{
9635 "-resumption-delay", "19",
9636 },
9637 resumeSession: true,
9638 })
9639 testCases = append(testCases, testCase{
9640 testType: clientTest,
9641 name: "TLS13-HonorServerSessionTicketLifetime-2",
9642 config: Config{
9643 MaxVersion: VersionTLS13,
9644 Bugs: ProtocolBugs{
9645 SendTicketLifetime: 20 * time.Second,
9646 // The client should not offer the expired session.
9647 ExpectNoTLS13PSK: true,
9648 },
9649 },
9650 flags: []string{
9651 "-resumption-delay", "21",
9652 },
David Benjamin023d4192017-02-06 13:49:07 -05009653 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009654 expectResumeRejected: true,
9655 })
Steven Valdez5b986082016-09-01 12:29:49 -04009656}
9657
David Benjamin82261be2016-07-07 14:32:50 -07009658func addChangeCipherSpecTests() {
9659 // Test missing ChangeCipherSpecs.
9660 testCases = append(testCases, testCase{
9661 name: "SkipChangeCipherSpec-Client",
9662 config: Config{
9663 MaxVersion: VersionTLS12,
9664 Bugs: ProtocolBugs{
9665 SkipChangeCipherSpec: true,
9666 },
9667 },
9668 shouldFail: true,
9669 expectedError: ":UNEXPECTED_RECORD:",
9670 })
9671 testCases = append(testCases, testCase{
9672 testType: serverTest,
9673 name: "SkipChangeCipherSpec-Server",
9674 config: Config{
9675 MaxVersion: VersionTLS12,
9676 Bugs: ProtocolBugs{
9677 SkipChangeCipherSpec: true,
9678 },
9679 },
9680 shouldFail: true,
9681 expectedError: ":UNEXPECTED_RECORD:",
9682 })
9683 testCases = append(testCases, testCase{
9684 testType: serverTest,
9685 name: "SkipChangeCipherSpec-Server-NPN",
9686 config: Config{
9687 MaxVersion: VersionTLS12,
9688 NextProtos: []string{"bar"},
9689 Bugs: ProtocolBugs{
9690 SkipChangeCipherSpec: true,
9691 },
9692 },
9693 flags: []string{
9694 "-advertise-npn", "\x03foo\x03bar\x03baz",
9695 },
9696 shouldFail: true,
9697 expectedError: ":UNEXPECTED_RECORD:",
9698 })
9699
9700 // Test synchronization between the handshake and ChangeCipherSpec.
9701 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9702 // rejected. Test both with and without handshake packing to handle both
9703 // when the partial post-CCS message is in its own record and when it is
9704 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009705 for _, packed := range []bool{false, true} {
9706 var suffix string
9707 if packed {
9708 suffix = "-Packed"
9709 }
9710
9711 testCases = append(testCases, testCase{
9712 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9713 config: Config{
9714 MaxVersion: VersionTLS12,
9715 Bugs: ProtocolBugs{
9716 FragmentAcrossChangeCipherSpec: true,
9717 PackHandshakeFlight: packed,
9718 },
9719 },
9720 shouldFail: true,
9721 expectedError: ":UNEXPECTED_RECORD:",
9722 })
9723 testCases = append(testCases, testCase{
9724 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9725 config: Config{
9726 MaxVersion: VersionTLS12,
9727 },
9728 resumeSession: true,
9729 resumeConfig: &Config{
9730 MaxVersion: VersionTLS12,
9731 Bugs: ProtocolBugs{
9732 FragmentAcrossChangeCipherSpec: true,
9733 PackHandshakeFlight: packed,
9734 },
9735 },
9736 shouldFail: true,
9737 expectedError: ":UNEXPECTED_RECORD:",
9738 })
9739 testCases = append(testCases, testCase{
9740 testType: serverTest,
9741 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9742 config: Config{
9743 MaxVersion: VersionTLS12,
9744 Bugs: ProtocolBugs{
9745 FragmentAcrossChangeCipherSpec: true,
9746 PackHandshakeFlight: packed,
9747 },
9748 },
9749 shouldFail: true,
9750 expectedError: ":UNEXPECTED_RECORD:",
9751 })
9752 testCases = append(testCases, testCase{
9753 testType: serverTest,
9754 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9755 config: Config{
9756 MaxVersion: VersionTLS12,
9757 },
9758 resumeSession: true,
9759 resumeConfig: &Config{
9760 MaxVersion: VersionTLS12,
9761 Bugs: ProtocolBugs{
9762 FragmentAcrossChangeCipherSpec: true,
9763 PackHandshakeFlight: packed,
9764 },
9765 },
9766 shouldFail: true,
9767 expectedError: ":UNEXPECTED_RECORD:",
9768 })
9769 testCases = append(testCases, testCase{
9770 testType: serverTest,
9771 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9772 config: Config{
9773 MaxVersion: VersionTLS12,
9774 NextProtos: []string{"bar"},
9775 Bugs: ProtocolBugs{
9776 FragmentAcrossChangeCipherSpec: true,
9777 PackHandshakeFlight: packed,
9778 },
9779 },
9780 flags: []string{
9781 "-advertise-npn", "\x03foo\x03bar\x03baz",
9782 },
9783 shouldFail: true,
9784 expectedError: ":UNEXPECTED_RECORD:",
9785 })
9786 }
9787
David Benjamin61672812016-07-14 23:10:43 -04009788 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9789 // messages in the handshake queue. Do this by testing the server
9790 // reading the client Finished, reversing the flight so Finished comes
9791 // first.
9792 testCases = append(testCases, testCase{
9793 protocol: dtls,
9794 testType: serverTest,
9795 name: "SendUnencryptedFinished-DTLS",
9796 config: Config{
9797 MaxVersion: VersionTLS12,
9798 Bugs: ProtocolBugs{
9799 SendUnencryptedFinished: true,
9800 ReverseHandshakeFragments: true,
9801 },
9802 },
9803 shouldFail: true,
9804 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9805 })
9806
Steven Valdez143e8b32016-07-11 13:19:03 -04009807 // Test synchronization between encryption changes and the handshake in
9808 // TLS 1.3, where ChangeCipherSpec is implicit.
9809 testCases = append(testCases, testCase{
9810 name: "PartialEncryptedExtensionsWithServerHello",
9811 config: Config{
9812 MaxVersion: VersionTLS13,
9813 Bugs: ProtocolBugs{
9814 PartialEncryptedExtensionsWithServerHello: true,
9815 },
9816 },
9817 shouldFail: true,
9818 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9819 })
9820 testCases = append(testCases, testCase{
9821 testType: serverTest,
9822 name: "PartialClientFinishedWithClientHello",
9823 config: Config{
9824 MaxVersion: VersionTLS13,
9825 Bugs: ProtocolBugs{
9826 PartialClientFinishedWithClientHello: true,
9827 },
9828 },
9829 shouldFail: true,
9830 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9831 })
9832
David Benjamin82261be2016-07-07 14:32:50 -07009833 // Test that early ChangeCipherSpecs are handled correctly.
9834 testCases = append(testCases, testCase{
9835 testType: serverTest,
9836 name: "EarlyChangeCipherSpec-server-1",
9837 config: Config{
9838 MaxVersion: VersionTLS12,
9839 Bugs: ProtocolBugs{
9840 EarlyChangeCipherSpec: 1,
9841 },
9842 },
9843 shouldFail: true,
9844 expectedError: ":UNEXPECTED_RECORD:",
9845 })
9846 testCases = append(testCases, testCase{
9847 testType: serverTest,
9848 name: "EarlyChangeCipherSpec-server-2",
9849 config: Config{
9850 MaxVersion: VersionTLS12,
9851 Bugs: ProtocolBugs{
9852 EarlyChangeCipherSpec: 2,
9853 },
9854 },
9855 shouldFail: true,
9856 expectedError: ":UNEXPECTED_RECORD:",
9857 })
9858 testCases = append(testCases, testCase{
9859 protocol: dtls,
9860 name: "StrayChangeCipherSpec",
9861 config: Config{
9862 // TODO(davidben): Once DTLS 1.3 exists, test
9863 // that stray ChangeCipherSpec messages are
9864 // rejected.
9865 MaxVersion: VersionTLS12,
9866 Bugs: ProtocolBugs{
9867 StrayChangeCipherSpec: true,
9868 },
9869 },
9870 })
9871
9872 // Test that the contents of ChangeCipherSpec are checked.
9873 testCases = append(testCases, testCase{
9874 name: "BadChangeCipherSpec-1",
9875 config: Config{
9876 MaxVersion: VersionTLS12,
9877 Bugs: ProtocolBugs{
9878 BadChangeCipherSpec: []byte{2},
9879 },
9880 },
9881 shouldFail: true,
9882 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9883 })
9884 testCases = append(testCases, testCase{
9885 name: "BadChangeCipherSpec-2",
9886 config: Config{
9887 MaxVersion: VersionTLS12,
9888 Bugs: ProtocolBugs{
9889 BadChangeCipherSpec: []byte{1, 1},
9890 },
9891 },
9892 shouldFail: true,
9893 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9894 })
9895 testCases = append(testCases, testCase{
9896 protocol: dtls,
9897 name: "BadChangeCipherSpec-DTLS-1",
9898 config: Config{
9899 MaxVersion: VersionTLS12,
9900 Bugs: ProtocolBugs{
9901 BadChangeCipherSpec: []byte{2},
9902 },
9903 },
9904 shouldFail: true,
9905 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9906 })
9907 testCases = append(testCases, testCase{
9908 protocol: dtls,
9909 name: "BadChangeCipherSpec-DTLS-2",
9910 config: Config{
9911 MaxVersion: VersionTLS12,
9912 Bugs: ProtocolBugs{
9913 BadChangeCipherSpec: []byte{1, 1},
9914 },
9915 },
9916 shouldFail: true,
9917 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9918 })
9919}
9920
David Benjamincd2c8062016-09-09 11:28:16 -04009921type perMessageTest struct {
9922 messageType uint8
9923 test testCase
9924}
9925
9926// makePerMessageTests returns a series of test templates which cover each
9927// message in the TLS handshake. These may be used with bugs like
9928// WrongMessageType to fully test a per-message bug.
9929func makePerMessageTests() []perMessageTest {
9930 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009931 for _, protocol := range []protocol{tls, dtls} {
9932 var suffix string
9933 if protocol == dtls {
9934 suffix = "-DTLS"
9935 }
9936
David Benjamincd2c8062016-09-09 11:28:16 -04009937 ret = append(ret, perMessageTest{
9938 messageType: typeClientHello,
9939 test: testCase{
9940 protocol: protocol,
9941 testType: serverTest,
9942 name: "ClientHello" + suffix,
9943 config: Config{
9944 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009945 },
9946 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009947 })
9948
9949 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009950 ret = append(ret, perMessageTest{
9951 messageType: typeHelloVerifyRequest,
9952 test: testCase{
9953 protocol: protocol,
9954 name: "HelloVerifyRequest" + suffix,
9955 config: Config{
9956 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009957 },
9958 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009959 })
9960 }
9961
David Benjamincd2c8062016-09-09 11:28:16 -04009962 ret = append(ret, perMessageTest{
9963 messageType: typeServerHello,
9964 test: testCase{
9965 protocol: protocol,
9966 name: "ServerHello" + suffix,
9967 config: Config{
9968 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009969 },
9970 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009971 })
9972
David Benjamincd2c8062016-09-09 11:28:16 -04009973 ret = append(ret, perMessageTest{
9974 messageType: typeCertificate,
9975 test: testCase{
9976 protocol: protocol,
9977 name: "ServerCertificate" + suffix,
9978 config: Config{
9979 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009980 },
9981 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009982 })
9983
David Benjamincd2c8062016-09-09 11:28:16 -04009984 ret = append(ret, perMessageTest{
9985 messageType: typeCertificateStatus,
9986 test: testCase{
9987 protocol: protocol,
9988 name: "CertificateStatus" + suffix,
9989 config: Config{
9990 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009991 },
David Benjamincd2c8062016-09-09 11:28:16 -04009992 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009993 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009994 })
9995
David Benjamincd2c8062016-09-09 11:28:16 -04009996 ret = append(ret, perMessageTest{
9997 messageType: typeServerKeyExchange,
9998 test: testCase{
9999 protocol: protocol,
10000 name: "ServerKeyExchange" + suffix,
10001 config: Config{
10002 MaxVersion: VersionTLS12,
10003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010004 },
10005 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010006 })
10007
David Benjamincd2c8062016-09-09 11:28:16 -040010008 ret = append(ret, perMessageTest{
10009 messageType: typeCertificateRequest,
10010 test: testCase{
10011 protocol: protocol,
10012 name: "CertificateRequest" + suffix,
10013 config: Config{
10014 MaxVersion: VersionTLS12,
10015 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010016 },
10017 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010018 })
10019
David Benjamincd2c8062016-09-09 11:28:16 -040010020 ret = append(ret, perMessageTest{
10021 messageType: typeServerHelloDone,
10022 test: testCase{
10023 protocol: protocol,
10024 name: "ServerHelloDone" + suffix,
10025 config: Config{
10026 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010027 },
10028 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010029 })
10030
David Benjamincd2c8062016-09-09 11:28:16 -040010031 ret = append(ret, perMessageTest{
10032 messageType: typeCertificate,
10033 test: testCase{
10034 testType: serverTest,
10035 protocol: protocol,
10036 name: "ClientCertificate" + suffix,
10037 config: Config{
10038 Certificates: []Certificate{rsaCertificate},
10039 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010040 },
David Benjamincd2c8062016-09-09 11:28:16 -040010041 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010042 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010043 })
10044
David Benjamincd2c8062016-09-09 11:28:16 -040010045 ret = append(ret, perMessageTest{
10046 messageType: typeCertificateVerify,
10047 test: testCase{
10048 testType: serverTest,
10049 protocol: protocol,
10050 name: "CertificateVerify" + suffix,
10051 config: Config{
10052 Certificates: []Certificate{rsaCertificate},
10053 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010054 },
David Benjamincd2c8062016-09-09 11:28:16 -040010055 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010056 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010057 })
10058
David Benjamincd2c8062016-09-09 11:28:16 -040010059 ret = append(ret, perMessageTest{
10060 messageType: typeClientKeyExchange,
10061 test: testCase{
10062 testType: serverTest,
10063 protocol: protocol,
10064 name: "ClientKeyExchange" + 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
10071 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010072 ret = append(ret, perMessageTest{
10073 messageType: typeNextProtocol,
10074 test: testCase{
10075 testType: serverTest,
10076 protocol: protocol,
10077 name: "NextProtocol" + suffix,
10078 config: Config{
10079 MaxVersion: VersionTLS12,
10080 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010081 },
David Benjamincd2c8062016-09-09 11:28:16 -040010082 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010083 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010084 })
10085
David Benjamincd2c8062016-09-09 11:28:16 -040010086 ret = append(ret, perMessageTest{
10087 messageType: typeChannelID,
10088 test: testCase{
10089 testType: serverTest,
10090 protocol: protocol,
10091 name: "ChannelID" + suffix,
10092 config: Config{
10093 MaxVersion: VersionTLS12,
10094 ChannelID: channelIDKey,
10095 },
10096 flags: []string{
10097 "-expect-channel-id",
10098 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010099 },
10100 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010101 })
10102 }
10103
David Benjamincd2c8062016-09-09 11:28:16 -040010104 ret = append(ret, perMessageTest{
10105 messageType: typeFinished,
10106 test: testCase{
10107 testType: serverTest,
10108 protocol: protocol,
10109 name: "ClientFinished" + suffix,
10110 config: Config{
10111 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010112 },
10113 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010114 })
10115
David Benjamincd2c8062016-09-09 11:28:16 -040010116 ret = append(ret, perMessageTest{
10117 messageType: typeNewSessionTicket,
10118 test: testCase{
10119 protocol: protocol,
10120 name: "NewSessionTicket" + suffix,
10121 config: Config{
10122 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010123 },
10124 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010125 })
10126
David Benjamincd2c8062016-09-09 11:28:16 -040010127 ret = append(ret, perMessageTest{
10128 messageType: typeFinished,
10129 test: testCase{
10130 protocol: protocol,
10131 name: "ServerFinished" + suffix,
10132 config: Config{
10133 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010134 },
10135 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010136 })
10137
10138 }
David Benjamincd2c8062016-09-09 11:28:16 -040010139
10140 ret = append(ret, perMessageTest{
10141 messageType: typeClientHello,
10142 test: testCase{
10143 testType: serverTest,
10144 name: "TLS13-ClientHello",
10145 config: Config{
10146 MaxVersion: VersionTLS13,
10147 },
10148 },
10149 })
10150
10151 ret = append(ret, perMessageTest{
10152 messageType: typeServerHello,
10153 test: testCase{
10154 name: "TLS13-ServerHello",
10155 config: Config{
10156 MaxVersion: VersionTLS13,
10157 },
10158 },
10159 })
10160
10161 ret = append(ret, perMessageTest{
10162 messageType: typeEncryptedExtensions,
10163 test: testCase{
10164 name: "TLS13-EncryptedExtensions",
10165 config: Config{
10166 MaxVersion: VersionTLS13,
10167 },
10168 },
10169 })
10170
10171 ret = append(ret, perMessageTest{
10172 messageType: typeCertificateRequest,
10173 test: testCase{
10174 name: "TLS13-CertificateRequest",
10175 config: Config{
10176 MaxVersion: VersionTLS13,
10177 ClientAuth: RequireAnyClientCert,
10178 },
10179 },
10180 })
10181
10182 ret = append(ret, perMessageTest{
10183 messageType: typeCertificate,
10184 test: testCase{
10185 name: "TLS13-ServerCertificate",
10186 config: Config{
10187 MaxVersion: VersionTLS13,
10188 },
10189 },
10190 })
10191
10192 ret = append(ret, perMessageTest{
10193 messageType: typeCertificateVerify,
10194 test: testCase{
10195 name: "TLS13-ServerCertificateVerify",
10196 config: Config{
10197 MaxVersion: VersionTLS13,
10198 },
10199 },
10200 })
10201
10202 ret = append(ret, perMessageTest{
10203 messageType: typeFinished,
10204 test: testCase{
10205 name: "TLS13-ServerFinished",
10206 config: Config{
10207 MaxVersion: VersionTLS13,
10208 },
10209 },
10210 })
10211
10212 ret = append(ret, perMessageTest{
10213 messageType: typeCertificate,
10214 test: testCase{
10215 testType: serverTest,
10216 name: "TLS13-ClientCertificate",
10217 config: Config{
10218 Certificates: []Certificate{rsaCertificate},
10219 MaxVersion: VersionTLS13,
10220 },
10221 flags: []string{"-require-any-client-certificate"},
10222 },
10223 })
10224
10225 ret = append(ret, perMessageTest{
10226 messageType: typeCertificateVerify,
10227 test: testCase{
10228 testType: serverTest,
10229 name: "TLS13-ClientCertificateVerify",
10230 config: Config{
10231 Certificates: []Certificate{rsaCertificate},
10232 MaxVersion: VersionTLS13,
10233 },
10234 flags: []string{"-require-any-client-certificate"},
10235 },
10236 })
10237
10238 ret = append(ret, perMessageTest{
10239 messageType: typeFinished,
10240 test: testCase{
10241 testType: serverTest,
10242 name: "TLS13-ClientFinished",
10243 config: Config{
10244 MaxVersion: VersionTLS13,
10245 },
10246 },
10247 })
10248
10249 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010250}
10251
David Benjamincd2c8062016-09-09 11:28:16 -040010252func addWrongMessageTypeTests() {
10253 for _, t := range makePerMessageTests() {
10254 t.test.name = "WrongMessageType-" + t.test.name
10255 t.test.config.Bugs.SendWrongMessageType = t.messageType
10256 t.test.shouldFail = true
10257 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10258 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010259
David Benjamincd2c8062016-09-09 11:28:16 -040010260 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10261 // In TLS 1.3, a bad ServerHello means the client sends
10262 // an unencrypted alert while the server expects
10263 // encryption, so the alert is not readable by runner.
10264 t.test.expectedLocalError = "local error: bad record MAC"
10265 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010266
David Benjamincd2c8062016-09-09 11:28:16 -040010267 testCases = append(testCases, t.test)
10268 }
David Benjaminebacdee2017-04-08 11:00:45 -040010269
10270 // The processing order for TLS 1.3 version negotiation is such that one
10271 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10272 // TLS 1.2. Test that we do not do this.
10273 testCases = append(testCases, testCase{
10274 name: "SendServerHelloAsHelloRetryRequest",
10275 config: Config{
10276 MaxVersion: VersionTLS12,
10277 Bugs: ProtocolBugs{
10278 SendServerHelloAsHelloRetryRequest: true,
10279 },
10280 },
10281 shouldFail: true,
10282 expectedError: ":UNEXPECTED_MESSAGE:",
10283 expectedLocalError: "remote error: unexpected message",
10284 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010285}
10286
David Benjamin639846e2016-09-09 11:41:18 -040010287func addTrailingMessageDataTests() {
10288 for _, t := range makePerMessageTests() {
10289 t.test.name = "TrailingMessageData-" + t.test.name
10290 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10291 t.test.shouldFail = true
10292 t.test.expectedError = ":DECODE_ERROR:"
10293 t.test.expectedLocalError = "remote error: error decoding message"
10294
10295 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10296 // In TLS 1.3, a bad ServerHello means the client sends
10297 // an unencrypted alert while the server expects
10298 // encryption, so the alert is not readable by runner.
10299 t.test.expectedLocalError = "local error: bad record MAC"
10300 }
10301
10302 if t.messageType == typeFinished {
10303 // Bad Finished messages read as the verify data having
10304 // the wrong length.
10305 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10306 t.test.expectedLocalError = "remote error: error decrypting message"
10307 }
10308
10309 testCases = append(testCases, t.test)
10310 }
10311}
10312
Steven Valdez143e8b32016-07-11 13:19:03 -040010313func addTLS13HandshakeTests() {
10314 testCases = append(testCases, testCase{
10315 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010316 name: "NegotiatePSKResumption-TLS13",
10317 config: Config{
10318 MaxVersion: VersionTLS13,
10319 Bugs: ProtocolBugs{
10320 NegotiatePSKResumption: true,
10321 },
10322 },
10323 resumeSession: true,
10324 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010325 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010326 })
10327
10328 testCases = append(testCases, testCase{
10329 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010330 name: "MissingKeyShare-Client",
10331 config: Config{
10332 MaxVersion: VersionTLS13,
10333 Bugs: ProtocolBugs{
10334 MissingKeyShare: true,
10335 },
10336 },
10337 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010338 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010339 })
10340
10341 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010342 testType: serverTest,
10343 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010344 config: Config{
10345 MaxVersion: VersionTLS13,
10346 Bugs: ProtocolBugs{
10347 MissingKeyShare: true,
10348 },
10349 },
10350 shouldFail: true,
10351 expectedError: ":MISSING_KEY_SHARE:",
10352 })
10353
10354 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010355 testType: serverTest,
10356 name: "DuplicateKeyShares",
10357 config: Config{
10358 MaxVersion: VersionTLS13,
10359 Bugs: ProtocolBugs{
10360 DuplicateKeyShares: true,
10361 },
10362 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010363 shouldFail: true,
10364 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010365 })
10366
10367 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010368 testType: serverTest,
10369 name: "SkipEarlyData",
10370 config: Config{
10371 MaxVersion: VersionTLS13,
10372 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010373 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010374 },
10375 },
10376 })
10377
10378 testCases = append(testCases, testCase{
10379 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -040010380 name: "SkipEarlyData-Experiment",
10381 config: Config{
10382 MaxVersion: VersionTLS13,
10383 TLS13Variant: TLS13Experiment,
10384 Bugs: ProtocolBugs{
10385 SendFakeEarlyDataLength: 4,
10386 },
10387 },
10388 flags: []string{"-tls13-variant", "1"},
10389 })
10390
10391 testCases = append(testCases, testCase{
10392 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010393 name: "SkipEarlyData-OmitEarlyDataExtension",
10394 config: Config{
10395 MaxVersion: VersionTLS13,
10396 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010397 SendFakeEarlyDataLength: 4,
10398 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010399 },
10400 },
10401 shouldFail: true,
10402 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10403 })
10404
10405 testCases = append(testCases, testCase{
10406 testType: serverTest,
10407 name: "SkipEarlyData-TooMuchData",
10408 config: Config{
10409 MaxVersion: VersionTLS13,
10410 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010411 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010412 },
10413 },
10414 shouldFail: true,
10415 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10416 })
10417
10418 testCases = append(testCases, testCase{
10419 testType: serverTest,
10420 name: "SkipEarlyData-Interleaved",
10421 config: Config{
10422 MaxVersion: VersionTLS13,
10423 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010424 SendFakeEarlyDataLength: 4,
10425 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010426 },
10427 },
10428 shouldFail: true,
10429 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10430 })
10431
10432 testCases = append(testCases, testCase{
10433 testType: serverTest,
10434 name: "SkipEarlyData-EarlyDataInTLS12",
10435 config: Config{
10436 MaxVersion: VersionTLS13,
10437 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010438 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010439 },
10440 },
10441 shouldFail: true,
10442 expectedError: ":UNEXPECTED_RECORD:",
10443 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10444 })
10445
10446 testCases = append(testCases, testCase{
10447 testType: serverTest,
10448 name: "SkipEarlyData-HRR",
10449 config: Config{
10450 MaxVersion: VersionTLS13,
10451 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010452 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010453 },
10454 DefaultCurves: []CurveID{},
10455 },
10456 })
10457
10458 testCases = append(testCases, testCase{
10459 testType: serverTest,
10460 name: "SkipEarlyData-HRR-Interleaved",
10461 config: Config{
10462 MaxVersion: VersionTLS13,
10463 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010464 SendFakeEarlyDataLength: 4,
10465 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010466 },
10467 DefaultCurves: []CurveID{},
10468 },
10469 shouldFail: true,
10470 expectedError: ":UNEXPECTED_RECORD:",
10471 })
10472
10473 testCases = append(testCases, testCase{
10474 testType: serverTest,
10475 name: "SkipEarlyData-HRR-TooMuchData",
10476 config: Config{
10477 MaxVersion: VersionTLS13,
10478 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010479 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010480 },
10481 DefaultCurves: []CurveID{},
10482 },
10483 shouldFail: true,
10484 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10485 })
10486
10487 // Test that skipping early data looking for cleartext correctly
10488 // processes an alert record.
10489 testCases = append(testCases, testCase{
10490 testType: serverTest,
10491 name: "SkipEarlyData-HRR-FatalAlert",
10492 config: Config{
10493 MaxVersion: VersionTLS13,
10494 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010495 SendEarlyAlert: true,
10496 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010497 },
10498 DefaultCurves: []CurveID{},
10499 },
10500 shouldFail: true,
10501 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10502 })
10503
10504 testCases = append(testCases, testCase{
10505 testType: serverTest,
10506 name: "SkipEarlyData-SecondClientHelloEarlyData",
10507 config: Config{
10508 MaxVersion: VersionTLS13,
10509 Bugs: ProtocolBugs{
10510 SendEarlyDataOnSecondClientHello: true,
10511 },
10512 DefaultCurves: []CurveID{},
10513 },
10514 shouldFail: true,
10515 expectedLocalError: "remote error: bad record MAC",
10516 })
10517
10518 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010519 testType: clientTest,
10520 name: "EmptyEncryptedExtensions",
10521 config: Config{
10522 MaxVersion: VersionTLS13,
10523 Bugs: ProtocolBugs{
10524 EmptyEncryptedExtensions: true,
10525 },
10526 },
10527 shouldFail: true,
10528 expectedLocalError: "remote error: error decoding message",
10529 })
10530
10531 testCases = append(testCases, testCase{
10532 testType: clientTest,
10533 name: "EncryptedExtensionsWithKeyShare",
10534 config: Config{
10535 MaxVersion: VersionTLS13,
10536 Bugs: ProtocolBugs{
10537 EncryptedExtensionsWithKeyShare: true,
10538 },
10539 },
10540 shouldFail: true,
10541 expectedLocalError: "remote error: unsupported extension",
10542 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010543
10544 testCases = append(testCases, testCase{
10545 testType: serverTest,
10546 name: "SendHelloRetryRequest",
10547 config: Config{
10548 MaxVersion: VersionTLS13,
10549 // Require a HelloRetryRequest for every curve.
10550 DefaultCurves: []CurveID{},
10551 },
10552 expectedCurveID: CurveX25519,
10553 })
10554
10555 testCases = append(testCases, testCase{
10556 testType: serverTest,
10557 name: "SendHelloRetryRequest-2",
10558 config: Config{
10559 MaxVersion: VersionTLS13,
10560 DefaultCurves: []CurveID{CurveP384},
10561 },
10562 // Although the ClientHello did not predict our preferred curve,
10563 // we always select it whether it is predicted or not.
10564 expectedCurveID: CurveX25519,
10565 })
10566
10567 testCases = append(testCases, testCase{
10568 name: "UnknownCurve-HelloRetryRequest",
10569 config: Config{
10570 MaxVersion: VersionTLS13,
10571 // P-384 requires HelloRetryRequest in BoringSSL.
10572 CurvePreferences: []CurveID{CurveP384},
10573 Bugs: ProtocolBugs{
10574 SendHelloRetryRequestCurve: bogusCurve,
10575 },
10576 },
10577 shouldFail: true,
10578 expectedError: ":WRONG_CURVE:",
10579 })
10580
10581 testCases = append(testCases, testCase{
10582 name: "DisabledCurve-HelloRetryRequest",
10583 config: Config{
10584 MaxVersion: VersionTLS13,
10585 CurvePreferences: []CurveID{CurveP256},
10586 Bugs: ProtocolBugs{
10587 IgnorePeerCurvePreferences: true,
10588 },
10589 },
10590 flags: []string{"-p384-only"},
10591 shouldFail: true,
10592 expectedError: ":WRONG_CURVE:",
10593 })
10594
10595 testCases = append(testCases, testCase{
10596 name: "UnnecessaryHelloRetryRequest",
10597 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010598 MaxVersion: VersionTLS13,
10599 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010600 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010601 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010602 },
10603 },
10604 shouldFail: true,
10605 expectedError: ":WRONG_CURVE:",
10606 })
10607
10608 testCases = append(testCases, testCase{
10609 name: "SecondHelloRetryRequest",
10610 config: Config{
10611 MaxVersion: VersionTLS13,
10612 // P-384 requires HelloRetryRequest in BoringSSL.
10613 CurvePreferences: []CurveID{CurveP384},
10614 Bugs: ProtocolBugs{
10615 SecondHelloRetryRequest: true,
10616 },
10617 },
10618 shouldFail: true,
10619 expectedError: ":UNEXPECTED_MESSAGE:",
10620 })
10621
10622 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010623 name: "HelloRetryRequest-Empty",
10624 config: Config{
10625 MaxVersion: VersionTLS13,
10626 Bugs: ProtocolBugs{
10627 AlwaysSendHelloRetryRequest: true,
10628 },
10629 },
10630 shouldFail: true,
10631 expectedError: ":DECODE_ERROR:",
10632 })
10633
10634 testCases = append(testCases, testCase{
10635 name: "HelloRetryRequest-DuplicateCurve",
10636 config: Config{
10637 MaxVersion: VersionTLS13,
10638 // P-384 requires a HelloRetryRequest against BoringSSL's default
10639 // configuration. Assert this ExpectMissingKeyShare.
10640 CurvePreferences: []CurveID{CurveP384},
10641 Bugs: ProtocolBugs{
10642 ExpectMissingKeyShare: true,
10643 DuplicateHelloRetryRequestExtensions: true,
10644 },
10645 },
10646 shouldFail: true,
10647 expectedError: ":DUPLICATE_EXTENSION:",
10648 expectedLocalError: "remote error: illegal parameter",
10649 })
10650
10651 testCases = append(testCases, testCase{
10652 name: "HelloRetryRequest-Cookie",
10653 config: Config{
10654 MaxVersion: VersionTLS13,
10655 Bugs: ProtocolBugs{
10656 SendHelloRetryRequestCookie: []byte("cookie"),
10657 },
10658 },
10659 })
10660
10661 testCases = append(testCases, testCase{
10662 name: "HelloRetryRequest-DuplicateCookie",
10663 config: Config{
10664 MaxVersion: VersionTLS13,
10665 Bugs: ProtocolBugs{
10666 SendHelloRetryRequestCookie: []byte("cookie"),
10667 DuplicateHelloRetryRequestExtensions: true,
10668 },
10669 },
10670 shouldFail: true,
10671 expectedError: ":DUPLICATE_EXTENSION:",
10672 expectedLocalError: "remote error: illegal parameter",
10673 })
10674
10675 testCases = append(testCases, testCase{
10676 name: "HelloRetryRequest-EmptyCookie",
10677 config: Config{
10678 MaxVersion: VersionTLS13,
10679 Bugs: ProtocolBugs{
10680 SendHelloRetryRequestCookie: []byte{},
10681 },
10682 },
10683 shouldFail: true,
10684 expectedError: ":DECODE_ERROR:",
10685 })
10686
10687 testCases = append(testCases, testCase{
10688 name: "HelloRetryRequest-Cookie-Curve",
10689 config: Config{
10690 MaxVersion: VersionTLS13,
10691 // P-384 requires HelloRetryRequest in BoringSSL.
10692 CurvePreferences: []CurveID{CurveP384},
10693 Bugs: ProtocolBugs{
10694 SendHelloRetryRequestCookie: []byte("cookie"),
10695 ExpectMissingKeyShare: true,
10696 },
10697 },
10698 })
10699
10700 testCases = append(testCases, testCase{
10701 name: "HelloRetryRequest-Unknown",
10702 config: Config{
10703 MaxVersion: VersionTLS13,
10704 Bugs: ProtocolBugs{
10705 CustomHelloRetryRequestExtension: "extension",
10706 },
10707 },
10708 shouldFail: true,
10709 expectedError: ":UNEXPECTED_EXTENSION:",
10710 expectedLocalError: "remote error: unsupported extension",
10711 })
10712
10713 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010714 testType: serverTest,
10715 name: "SecondClientHelloMissingKeyShare",
10716 config: Config{
10717 MaxVersion: VersionTLS13,
10718 DefaultCurves: []CurveID{},
10719 Bugs: ProtocolBugs{
10720 SecondClientHelloMissingKeyShare: true,
10721 },
10722 },
10723 shouldFail: true,
10724 expectedError: ":MISSING_KEY_SHARE:",
10725 })
10726
10727 testCases = append(testCases, testCase{
10728 testType: serverTest,
10729 name: "SecondClientHelloWrongCurve",
10730 config: Config{
10731 MaxVersion: VersionTLS13,
10732 DefaultCurves: []CurveID{},
10733 Bugs: ProtocolBugs{
10734 MisinterpretHelloRetryRequestCurve: CurveP521,
10735 },
10736 },
10737 shouldFail: true,
10738 expectedError: ":WRONG_CURVE:",
10739 })
10740
10741 testCases = append(testCases, testCase{
10742 name: "HelloRetryRequestVersionMismatch",
10743 config: Config{
10744 MaxVersion: VersionTLS13,
10745 // P-384 requires HelloRetryRequest in BoringSSL.
10746 CurvePreferences: []CurveID{CurveP384},
10747 Bugs: ProtocolBugs{
10748 SendServerHelloVersion: 0x0305,
10749 },
10750 },
10751 shouldFail: true,
10752 expectedError: ":WRONG_VERSION_NUMBER:",
10753 })
10754
10755 testCases = append(testCases, testCase{
10756 name: "HelloRetryRequestCurveMismatch",
10757 config: Config{
10758 MaxVersion: VersionTLS13,
10759 // P-384 requires HelloRetryRequest in BoringSSL.
10760 CurvePreferences: []CurveID{CurveP384},
10761 Bugs: ProtocolBugs{
10762 // Send P-384 (correct) in the HelloRetryRequest.
10763 SendHelloRetryRequestCurve: CurveP384,
10764 // But send P-256 in the ServerHello.
10765 SendCurve: CurveP256,
10766 },
10767 },
10768 shouldFail: true,
10769 expectedError: ":WRONG_CURVE:",
10770 })
10771
10772 // Test the server selecting a curve that requires a HelloRetryRequest
10773 // without sending it.
10774 testCases = append(testCases, testCase{
10775 name: "SkipHelloRetryRequest",
10776 config: Config{
10777 MaxVersion: VersionTLS13,
10778 // P-384 requires HelloRetryRequest in BoringSSL.
10779 CurvePreferences: []CurveID{CurveP384},
10780 Bugs: ProtocolBugs{
10781 SkipHelloRetryRequest: true,
10782 },
10783 },
10784 shouldFail: true,
10785 expectedError: ":WRONG_CURVE:",
10786 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010787
10788 testCases = append(testCases, testCase{
10789 name: "TLS13-RequestContextInHandshake",
10790 config: Config{
10791 MaxVersion: VersionTLS13,
10792 MinVersion: VersionTLS13,
10793 ClientAuth: RequireAnyClientCert,
10794 Bugs: ProtocolBugs{
10795 SendRequestContext: []byte("request context"),
10796 },
10797 },
10798 flags: []string{
10799 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10800 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10801 },
10802 shouldFail: true,
10803 expectedError: ":DECODE_ERROR:",
10804 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010805
10806 testCases = append(testCases, testCase{
10807 testType: serverTest,
10808 name: "TLS13-TrailingKeyShareData",
10809 config: Config{
10810 MaxVersion: VersionTLS13,
10811 Bugs: ProtocolBugs{
10812 TrailingKeyShareData: true,
10813 },
10814 },
10815 shouldFail: true,
10816 expectedError: ":DECODE_ERROR:",
10817 })
David Benjamin7f78df42016-10-05 22:33:19 -040010818
10819 testCases = append(testCases, testCase{
10820 name: "TLS13-AlwaysSelectPSKIdentity",
10821 config: Config{
10822 MaxVersion: VersionTLS13,
10823 Bugs: ProtocolBugs{
10824 AlwaysSelectPSKIdentity: true,
10825 },
10826 },
10827 shouldFail: true,
10828 expectedError: ":UNEXPECTED_EXTENSION:",
10829 })
10830
10831 testCases = append(testCases, testCase{
10832 name: "TLS13-InvalidPSKIdentity",
10833 config: Config{
10834 MaxVersion: VersionTLS13,
10835 Bugs: ProtocolBugs{
10836 SelectPSKIdentityOnResume: 1,
10837 },
10838 },
10839 resumeSession: true,
10840 shouldFail: true,
10841 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10842 })
David Benjamin1286bee2016-10-07 15:25:06 -040010843
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010844 testCases = append(testCases, testCase{
10845 testType: serverTest,
10846 name: "TLS13-ExtraPSKIdentity",
10847 config: Config{
10848 MaxVersion: VersionTLS13,
10849 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010850 ExtraPSKIdentity: true,
10851 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010852 },
10853 },
10854 resumeSession: true,
10855 })
10856
David Benjamin1286bee2016-10-07 15:25:06 -040010857 // Test that unknown NewSessionTicket extensions are tolerated.
10858 testCases = append(testCases, testCase{
10859 name: "TLS13-CustomTicketExtension",
10860 config: Config{
10861 MaxVersion: VersionTLS13,
10862 Bugs: ProtocolBugs{
10863 CustomTicketExtension: "1234",
10864 },
10865 },
10866 })
Steven Valdez2d850622017-01-11 11:34:52 -050010867
Steven Valdez2d850622017-01-11 11:34:52 -050010868 testCases = append(testCases, testCase{
10869 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010870 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010871 config: Config{
10872 MaxVersion: VersionTLS13,
10873 MaxEarlyDataSize: 16384,
10874 },
10875 resumeConfig: &Config{
10876 MaxVersion: VersionTLS13,
10877 MaxEarlyDataSize: 16384,
10878 Bugs: ProtocolBugs{
10879 AlwaysRejectEarlyData: true,
10880 },
10881 },
10882 resumeSession: true,
10883 flags: []string{
10884 "-enable-early-data",
10885 "-expect-early-data-info",
10886 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010887 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010888 },
10889 })
10890
10891 testCases = append(testCases, testCase{
10892 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040010893 name: "TLS13Experiment-EarlyData-Reject-Client",
10894 config: Config{
10895 MaxVersion: VersionTLS13,
10896 MaxEarlyDataSize: 16384,
10897 TLS13Variant: TLS13Experiment,
10898 },
10899 resumeConfig: &Config{
10900 MaxVersion: VersionTLS13,
10901 TLS13Variant: TLS13Experiment,
10902 MaxEarlyDataSize: 16384,
10903 Bugs: ProtocolBugs{
10904 AlwaysRejectEarlyData: true,
10905 },
10906 },
10907 resumeSession: true,
10908 flags: []string{
10909 "-enable-early-data",
10910 "-expect-early-data-info",
10911 "-expect-reject-early-data",
10912 "-on-resume-shim-writes-first",
10913 "-tls13-variant", "1",
10914 },
10915 })
10916
10917 testCases = append(testCases, testCase{
10918 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010919 name: "TLS13-EarlyData-RejectTicket-Client",
10920 config: Config{
10921 MaxVersion: VersionTLS13,
10922 MaxEarlyDataSize: 16384,
10923 Certificates: []Certificate{rsaCertificate},
10924 },
10925 resumeConfig: &Config{
10926 MaxVersion: VersionTLS13,
10927 MaxEarlyDataSize: 16384,
10928 Certificates: []Certificate{ecdsaP256Certificate},
10929 SessionTicketsDisabled: true,
10930 },
10931 resumeSession: true,
10932 expectResumeRejected: true,
10933 flags: []string{
10934 "-enable-early-data",
10935 "-expect-early-data-info",
10936 "-expect-reject-early-data",
10937 "-on-resume-shim-writes-first",
10938 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10939 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10940 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10941 // Session tickets are disabled, so the runner will not send a ticket.
10942 "-on-retry-expect-no-session",
10943 },
10944 })
10945
10946 testCases = append(testCases, testCase{
10947 testType: clientTest,
10948 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010949 config: Config{
10950 MaxVersion: VersionTLS13,
10951 MaxEarlyDataSize: 16384,
10952 },
10953 resumeConfig: &Config{
10954 MaxVersion: VersionTLS13,
10955 MaxEarlyDataSize: 16384,
10956 Bugs: ProtocolBugs{
10957 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10958 },
10959 },
10960 resumeSession: true,
10961 flags: []string{
10962 "-enable-early-data",
10963 "-expect-early-data-info",
10964 "-expect-reject-early-data",
10965 },
10966 })
10967
10968 // The client must check the server does not send the early_data
10969 // extension while rejecting the session.
10970 testCases = append(testCases, testCase{
10971 testType: clientTest,
10972 name: "TLS13-EarlyDataWithoutResume-Client",
10973 config: Config{
10974 MaxVersion: VersionTLS13,
10975 MaxEarlyDataSize: 16384,
10976 },
10977 resumeConfig: &Config{
10978 MaxVersion: VersionTLS13,
10979 SessionTicketsDisabled: true,
10980 Bugs: ProtocolBugs{
10981 SendEarlyDataExtension: true,
10982 },
10983 },
10984 resumeSession: true,
10985 flags: []string{
10986 "-enable-early-data",
10987 "-expect-early-data-info",
10988 },
10989 shouldFail: true,
10990 expectedError: ":UNEXPECTED_EXTENSION:",
10991 })
10992
10993 // The client must fail with a dedicated error code if the server
10994 // responds with TLS 1.2 when offering 0-RTT.
10995 testCases = append(testCases, testCase{
10996 testType: clientTest,
10997 name: "TLS13-EarlyDataVersionDowngrade-Client",
10998 config: Config{
10999 MaxVersion: VersionTLS13,
11000 MaxEarlyDataSize: 16384,
11001 },
11002 resumeConfig: &Config{
11003 MaxVersion: VersionTLS12,
11004 },
11005 resumeSession: true,
11006 flags: []string{
11007 "-enable-early-data",
11008 "-expect-early-data-info",
11009 },
11010 shouldFail: true,
11011 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11012 })
11013
11014 // Test that the client rejects an (unsolicited) early_data extension if
11015 // the server sent an HRR.
11016 testCases = append(testCases, testCase{
11017 testType: clientTest,
11018 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11019 config: Config{
11020 MaxVersion: VersionTLS13,
11021 MaxEarlyDataSize: 16384,
11022 },
11023 resumeConfig: &Config{
11024 MaxVersion: VersionTLS13,
11025 MaxEarlyDataSize: 16384,
11026 Bugs: ProtocolBugs{
11027 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11028 SendEarlyDataExtension: true,
11029 },
11030 },
11031 resumeSession: true,
11032 flags: []string{
11033 "-enable-early-data",
11034 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011035 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011036 },
11037 shouldFail: true,
11038 expectedError: ":UNEXPECTED_EXTENSION:",
11039 })
11040
11041 fooString := "foo"
11042 barString := "bar"
11043
11044 // Test that the client reports the correct ALPN after a 0-RTT reject
11045 // that changed it.
11046 testCases = append(testCases, testCase{
11047 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011048 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011049 config: Config{
11050 MaxVersion: VersionTLS13,
11051 MaxEarlyDataSize: 16384,
11052 Bugs: ProtocolBugs{
11053 ALPNProtocol: &fooString,
11054 },
11055 },
11056 resumeConfig: &Config{
11057 MaxVersion: VersionTLS13,
11058 MaxEarlyDataSize: 16384,
11059 Bugs: ProtocolBugs{
11060 ALPNProtocol: &barString,
11061 },
11062 },
11063 resumeSession: true,
11064 flags: []string{
11065 "-advertise-alpn", "\x03foo\x03bar",
11066 "-enable-early-data",
11067 "-expect-early-data-info",
11068 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011069 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011070 "-on-resume-expect-alpn", "foo",
11071 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011072 },
11073 })
11074
11075 // Test that the client reports the correct ALPN after a 0-RTT reject if
11076 // ALPN was omitted from the first connection.
11077 testCases = append(testCases, testCase{
11078 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011079 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011080 config: Config{
11081 MaxVersion: VersionTLS13,
11082 MaxEarlyDataSize: 16384,
11083 },
11084 resumeConfig: &Config{
11085 MaxVersion: VersionTLS13,
11086 MaxEarlyDataSize: 16384,
11087 NextProtos: []string{"foo"},
11088 },
11089 resumeSession: true,
11090 flags: []string{
11091 "-advertise-alpn", "\x03foo\x03bar",
11092 "-enable-early-data",
11093 "-expect-early-data-info",
11094 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011095 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011096 "-on-resume-expect-alpn", "",
11097 "-on-retry-expect-alpn", "foo",
11098 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011099 },
11100 })
11101
11102 // Test that the client reports the correct ALPN after a 0-RTT reject if
11103 // ALPN was omitted from the second connection.
11104 testCases = append(testCases, testCase{
11105 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011106 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011107 config: Config{
11108 MaxVersion: VersionTLS13,
11109 MaxEarlyDataSize: 16384,
11110 NextProtos: []string{"foo"},
11111 },
11112 resumeConfig: &Config{
11113 MaxVersion: VersionTLS13,
11114 MaxEarlyDataSize: 16384,
11115 },
11116 resumeSession: true,
11117 flags: []string{
11118 "-advertise-alpn", "\x03foo\x03bar",
11119 "-enable-early-data",
11120 "-expect-early-data-info",
11121 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011122 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011123 "-on-resume-expect-alpn", "foo",
11124 "-on-retry-expect-alpn", "",
11125 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011126 },
11127 })
11128
11129 // Test that the client enforces ALPN match on 0-RTT accept.
11130 testCases = append(testCases, testCase{
11131 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011132 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011133 config: Config{
11134 MaxVersion: VersionTLS13,
11135 MaxEarlyDataSize: 16384,
11136 Bugs: ProtocolBugs{
11137 ALPNProtocol: &fooString,
11138 },
11139 },
11140 resumeConfig: &Config{
11141 MaxVersion: VersionTLS13,
11142 MaxEarlyDataSize: 16384,
11143 Bugs: ProtocolBugs{
11144 AlwaysAcceptEarlyData: true,
11145 ALPNProtocol: &barString,
11146 },
11147 },
11148 resumeSession: true,
11149 flags: []string{
11150 "-advertise-alpn", "\x03foo\x03bar",
11151 "-enable-early-data",
11152 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011153 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011154 "-on-resume-expect-alpn", "foo",
11155 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011156 },
11157 shouldFail: true,
11158 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11159 })
11160
11161 // Test that the server correctly rejects 0-RTT when the previous
11162 // session did not allow early data on resumption.
11163 testCases = append(testCases, testCase{
11164 testType: serverTest,
11165 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11166 config: Config{
11167 MaxVersion: VersionTLS13,
11168 },
11169 resumeConfig: &Config{
11170 MaxVersion: VersionTLS13,
11171 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011172 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011173 ExpectEarlyDataAccepted: false,
11174 },
11175 },
11176 resumeSession: true,
11177 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011178 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011179 "-expect-reject-early-data",
11180 },
11181 })
11182
11183 // Test that we reject early data where ALPN is omitted from the first
11184 // connection.
11185 testCases = append(testCases, testCase{
11186 testType: serverTest,
11187 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11188 config: Config{
11189 MaxVersion: VersionTLS13,
11190 NextProtos: []string{},
11191 },
11192 resumeConfig: &Config{
11193 MaxVersion: VersionTLS13,
11194 NextProtos: []string{"foo"},
11195 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011196 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011197 ExpectEarlyDataAccepted: false,
11198 },
11199 },
11200 resumeSession: true,
11201 flags: []string{
11202 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011203 "-on-initial-select-alpn", "",
11204 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011205 },
11206 })
11207
11208 // Test that we reject early data where ALPN is omitted from the second
11209 // connection.
11210 testCases = append(testCases, testCase{
11211 testType: serverTest,
11212 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11213 config: Config{
11214 MaxVersion: VersionTLS13,
11215 NextProtos: []string{"foo"},
11216 },
11217 resumeConfig: &Config{
11218 MaxVersion: VersionTLS13,
11219 NextProtos: []string{},
11220 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011221 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011222 ExpectEarlyDataAccepted: false,
11223 },
11224 },
11225 resumeSession: true,
11226 flags: []string{
11227 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011228 "-on-initial-select-alpn", "foo",
11229 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011230 },
11231 })
11232
11233 // Test that we reject early data with mismatched ALPN.
11234 testCases = append(testCases, testCase{
11235 testType: serverTest,
11236 name: "TLS13-EarlyData-ALPNMismatch-Server",
11237 config: Config{
11238 MaxVersion: VersionTLS13,
11239 NextProtos: []string{"foo"},
11240 },
11241 resumeConfig: &Config{
11242 MaxVersion: VersionTLS13,
11243 NextProtos: []string{"bar"},
11244 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011245 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011246 ExpectEarlyDataAccepted: false,
11247 },
11248 },
11249 resumeSession: true,
11250 flags: []string{
11251 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011252 "-on-initial-select-alpn", "foo",
11253 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011254 },
11255 })
11256
David Benjamin6bb507b2017-03-29 16:35:57 -050011257 // Test that the client offering 0-RTT and Channel ID forbids the server
11258 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011259 testCases = append(testCases, testCase{
11260 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011261 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011262 config: Config{
11263 MaxVersion: VersionTLS13,
11264 MaxEarlyDataSize: 16384,
11265 RequestChannelID: true,
11266 },
11267 resumeSession: true,
11268 expectChannelID: true,
11269 shouldFail: true,
11270 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11271 flags: []string{
11272 "-enable-early-data",
11273 "-expect-early-data-info",
11274 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11275 },
11276 })
11277
David Benjamin6bb507b2017-03-29 16:35:57 -050011278 // Test that the client offering Channel ID and 0-RTT allows the server
11279 // to decline 0-RTT.
11280 testCases = append(testCases, testCase{
11281 testType: clientTest,
11282 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11283 config: Config{
11284 MaxVersion: VersionTLS13,
11285 MaxEarlyDataSize: 16384,
11286 RequestChannelID: true,
11287 Bugs: ProtocolBugs{
11288 AlwaysRejectEarlyData: true,
11289 },
11290 },
11291 resumeSession: true,
11292 expectChannelID: true,
11293 flags: []string{
11294 "-enable-early-data",
11295 "-expect-early-data-info",
11296 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11297 "-expect-reject-early-data",
11298 },
11299 })
11300
11301 // Test that the client offering Channel ID and 0-RTT allows the server
11302 // to decline Channel ID.
11303 testCases = append(testCases, testCase{
11304 testType: clientTest,
11305 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11306 config: Config{
11307 MaxVersion: VersionTLS13,
11308 MaxEarlyDataSize: 16384,
11309 },
11310 resumeSession: true,
11311 flags: []string{
11312 "-enable-early-data",
11313 "-expect-early-data-info",
11314 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11315 "-expect-accept-early-data",
11316 },
11317 })
11318
11319 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11320 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011321 testCases = append(testCases, testCase{
11322 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011323 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011324 config: Config{
11325 MaxVersion: VersionTLS13,
11326 ChannelID: channelIDKey,
11327 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011328 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011329 ExpectEarlyDataAccepted: false,
11330 },
11331 },
11332 resumeSession: true,
11333 expectChannelID: true,
11334 flags: []string{
11335 "-enable-early-data",
11336 "-expect-reject-early-data",
11337 "-expect-channel-id",
11338 base64.StdEncoding.EncodeToString(channelIDBytes),
11339 },
11340 })
11341
David Benjamin6bb507b2017-03-29 16:35:57 -050011342 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11343 // if not offered Channel ID.
11344 testCases = append(testCases, testCase{
11345 testType: serverTest,
11346 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11347 config: Config{
11348 MaxVersion: VersionTLS13,
11349 Bugs: ProtocolBugs{
11350 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11351 ExpectEarlyDataAccepted: true,
11352 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11353 },
11354 },
11355 resumeSession: true,
11356 expectChannelID: false,
11357 flags: []string{
11358 "-enable-early-data",
11359 "-expect-accept-early-data",
11360 "-enable-channel-id",
11361 },
11362 })
11363
David Benjamin32c89272017-03-26 13:54:21 -050011364 // Test that the server rejects 0-RTT streams without end_of_early_data.
11365 // The subsequent records should fail to decrypt.
11366 testCases = append(testCases, testCase{
11367 testType: serverTest,
11368 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11369 config: Config{
11370 MaxVersion: VersionTLS13,
11371 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011372 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011373 ExpectEarlyDataAccepted: true,
11374 SkipEndOfEarlyData: true,
11375 },
11376 },
11377 resumeSession: true,
11378 flags: []string{"-enable-early-data"},
11379 shouldFail: true,
11380 expectedLocalError: "remote error: bad record MAC",
11381 expectedError: ":BAD_DECRYPT:",
11382 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011383
11384 testCases = append(testCases, testCase{
11385 testType: serverTest,
11386 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11387 config: Config{
11388 MaxVersion: VersionTLS13,
11389 },
11390 resumeConfig: &Config{
11391 MaxVersion: VersionTLS13,
11392 Bugs: ProtocolBugs{
11393 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11394 SendStrayEarlyHandshake: true,
11395 ExpectEarlyDataAccepted: true},
11396 },
11397 resumeSession: true,
11398 shouldFail: true,
11399 expectedError: ":UNEXPECTED_RECORD:",
11400 expectedLocalError: "remote error: unexpected message",
11401 flags: []string{
11402 "-enable-early-data",
11403 },
11404 })
David Benjamind9cbb532017-07-07 13:17:19 -040011405
11406 // Test that the client reports TLS 1.3 as the version while sending
11407 // early data.
11408 testCases = append(testCases, testCase{
11409 testType: clientTest,
11410 name: "TLS13-EarlyData-Client-VersionAPI",
11411 config: Config{
11412 MaxVersion: VersionTLS13,
11413 MaxEarlyDataSize: 16384,
11414 },
11415 resumeSession: true,
11416 flags: []string{
11417 "-enable-early-data",
11418 "-expect-early-data-info",
11419 "-expect-accept-early-data",
11420 "-expect-version", strconv.Itoa(VersionTLS13),
11421 },
11422 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011423}
11424
David Benjaminabbbee12016-10-31 19:20:42 -040011425func addTLS13CipherPreferenceTests() {
11426 // Test that client preference is honored if the shim has AES hardware
11427 // and ChaCha20-Poly1305 is preferred otherwise.
11428 testCases = append(testCases, testCase{
11429 testType: serverTest,
11430 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11431 config: Config{
11432 MaxVersion: VersionTLS13,
11433 CipherSuites: []uint16{
11434 TLS_CHACHA20_POLY1305_SHA256,
11435 TLS_AES_128_GCM_SHA256,
11436 },
11437 },
11438 flags: []string{
11439 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11440 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11441 },
11442 })
11443
11444 testCases = append(testCases, testCase{
11445 testType: serverTest,
11446 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11447 config: Config{
11448 MaxVersion: VersionTLS13,
11449 CipherSuites: []uint16{
11450 TLS_AES_128_GCM_SHA256,
11451 TLS_CHACHA20_POLY1305_SHA256,
11452 },
11453 },
11454 flags: []string{
11455 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11456 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11457 },
11458 })
11459
11460 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11461 // whether it has AES hardware.
11462 testCases = append(testCases, testCase{
11463 name: "TLS13-CipherPreference-Client",
11464 config: Config{
11465 MaxVersion: VersionTLS13,
11466 // Use the client cipher order. (This is the default but
11467 // is listed to be explicit.)
11468 PreferServerCipherSuites: false,
11469 },
11470 flags: []string{
11471 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11472 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11473 },
11474 })
11475}
11476
David Benjaminf3fbade2016-09-19 13:08:16 -040011477func addPeekTests() {
11478 // Test SSL_peek works, including on empty records.
11479 testCases = append(testCases, testCase{
11480 name: "Peek-Basic",
11481 sendEmptyRecords: 1,
11482 flags: []string{"-peek-then-read"},
11483 })
11484
11485 // Test SSL_peek can drive the initial handshake.
11486 testCases = append(testCases, testCase{
11487 name: "Peek-ImplicitHandshake",
11488 flags: []string{
11489 "-peek-then-read",
11490 "-implicit-handshake",
11491 },
11492 })
11493
11494 // Test SSL_peek can discover and drive a renegotiation.
11495 testCases = append(testCases, testCase{
11496 name: "Peek-Renegotiate",
11497 config: Config{
11498 MaxVersion: VersionTLS12,
11499 },
11500 renegotiate: 1,
11501 flags: []string{
11502 "-peek-then-read",
11503 "-renegotiate-freely",
11504 "-expect-total-renegotiations", "1",
11505 },
11506 })
11507
11508 // Test SSL_peek can discover a close_notify.
11509 testCases = append(testCases, testCase{
11510 name: "Peek-Shutdown",
11511 config: Config{
11512 Bugs: ProtocolBugs{
11513 ExpectCloseNotify: true,
11514 },
11515 },
11516 flags: []string{
11517 "-peek-then-read",
11518 "-check-close-notify",
11519 },
11520 })
11521
11522 // Test SSL_peek can discover an alert.
11523 testCases = append(testCases, testCase{
11524 name: "Peek-Alert",
11525 config: Config{
11526 Bugs: ProtocolBugs{
11527 SendSpuriousAlert: alertRecordOverflow,
11528 },
11529 },
11530 flags: []string{"-peek-then-read"},
11531 shouldFail: true,
11532 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11533 })
11534
11535 // Test SSL_peek can handle KeyUpdate.
11536 testCases = append(testCases, testCase{
11537 name: "Peek-KeyUpdate",
11538 config: Config{
11539 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011540 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011541 sendKeyUpdates: 1,
11542 keyUpdateRequest: keyUpdateNotRequested,
11543 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011544 })
11545}
11546
David Benjamine6f22212016-11-08 14:28:24 -050011547func addRecordVersionTests() {
11548 for _, ver := range tlsVersions {
11549 // Test that the record version is enforced.
11550 testCases = append(testCases, testCase{
11551 name: "CheckRecordVersion-" + ver.name,
11552 config: Config{
11553 MinVersion: ver.version,
11554 MaxVersion: ver.version,
11555 Bugs: ProtocolBugs{
11556 SendRecordVersion: 0x03ff,
11557 },
11558 },
11559 shouldFail: true,
11560 expectedError: ":WRONG_VERSION_NUMBER:",
11561 })
11562
11563 // Test that the ClientHello may use any record version, for
11564 // compatibility reasons.
11565 testCases = append(testCases, testCase{
11566 testType: serverTest,
11567 name: "LooseInitialRecordVersion-" + ver.name,
11568 config: Config{
11569 MinVersion: ver.version,
11570 MaxVersion: ver.version,
11571 Bugs: ProtocolBugs{
11572 SendInitialRecordVersion: 0x03ff,
11573 },
11574 },
11575 })
11576
11577 // Test that garbage ClientHello record versions are rejected.
11578 testCases = append(testCases, testCase{
11579 testType: serverTest,
11580 name: "GarbageInitialRecordVersion-" + ver.name,
11581 config: Config{
11582 MinVersion: ver.version,
11583 MaxVersion: ver.version,
11584 Bugs: ProtocolBugs{
11585 SendInitialRecordVersion: 0xffff,
11586 },
11587 },
11588 shouldFail: true,
11589 expectedError: ":WRONG_VERSION_NUMBER:",
11590 })
11591 }
11592}
11593
David Benjamin2c516452016-11-15 10:16:54 +090011594func addCertificateTests() {
11595 // Test that a certificate chain with intermediate may be sent and
11596 // received as both client and server.
11597 for _, ver := range tlsVersions {
11598 testCases = append(testCases, testCase{
11599 testType: clientTest,
11600 name: "SendReceiveIntermediate-Client-" + ver.name,
11601 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011602 MinVersion: ver.version,
11603 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011604 Certificates: []Certificate{rsaChainCertificate},
11605 ClientAuth: RequireAnyClientCert,
11606 },
11607 expectPeerCertificate: &rsaChainCertificate,
11608 flags: []string{
11609 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11610 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11611 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11612 },
11613 })
11614
11615 testCases = append(testCases, testCase{
11616 testType: serverTest,
11617 name: "SendReceiveIntermediate-Server-" + ver.name,
11618 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011619 MinVersion: ver.version,
11620 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011621 Certificates: []Certificate{rsaChainCertificate},
11622 },
11623 expectPeerCertificate: &rsaChainCertificate,
11624 flags: []string{
11625 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11626 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11627 "-require-any-client-certificate",
11628 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11629 },
11630 })
11631 }
11632}
11633
David Benjaminbbaf3672016-11-17 10:53:09 +090011634func addRetainOnlySHA256ClientCertTests() {
11635 for _, ver := range tlsVersions {
11636 // Test that enabling
11637 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11638 // actually requesting a client certificate is a no-op.
11639 testCases = append(testCases, testCase{
11640 testType: serverTest,
11641 name: "RetainOnlySHA256-NoCert-" + ver.name,
11642 config: Config{
11643 MinVersion: ver.version,
11644 MaxVersion: ver.version,
11645 },
11646 flags: []string{
11647 "-retain-only-sha256-client-cert-initial",
11648 "-retain-only-sha256-client-cert-resume",
11649 },
11650 resumeSession: true,
11651 })
11652
11653 // Test that when retaining only a SHA-256 certificate is
11654 // enabled, the hash appears as expected.
11655 testCases = append(testCases, testCase{
11656 testType: serverTest,
11657 name: "RetainOnlySHA256-Cert-" + ver.name,
11658 config: Config{
11659 MinVersion: ver.version,
11660 MaxVersion: ver.version,
11661 Certificates: []Certificate{rsaCertificate},
11662 },
11663 flags: []string{
11664 "-verify-peer",
11665 "-retain-only-sha256-client-cert-initial",
11666 "-retain-only-sha256-client-cert-resume",
11667 "-expect-sha256-client-cert-initial",
11668 "-expect-sha256-client-cert-resume",
11669 },
11670 resumeSession: true,
11671 })
11672
11673 // Test that when the config changes from on to off, a
11674 // resumption is rejected because the server now wants the full
11675 // certificate chain.
11676 testCases = append(testCases, testCase{
11677 testType: serverTest,
11678 name: "RetainOnlySHA256-OnOff-" + ver.name,
11679 config: Config{
11680 MinVersion: ver.version,
11681 MaxVersion: ver.version,
11682 Certificates: []Certificate{rsaCertificate},
11683 },
11684 flags: []string{
11685 "-verify-peer",
11686 "-retain-only-sha256-client-cert-initial",
11687 "-expect-sha256-client-cert-initial",
11688 },
11689 resumeSession: true,
11690 expectResumeRejected: true,
11691 })
11692
11693 // Test that when the config changes from off to on, a
11694 // resumption is rejected because the server now wants just the
11695 // hash.
11696 testCases = append(testCases, testCase{
11697 testType: serverTest,
11698 name: "RetainOnlySHA256-OffOn-" + ver.name,
11699 config: Config{
11700 MinVersion: ver.version,
11701 MaxVersion: ver.version,
11702 Certificates: []Certificate{rsaCertificate},
11703 },
11704 flags: []string{
11705 "-verify-peer",
11706 "-retain-only-sha256-client-cert-resume",
11707 "-expect-sha256-client-cert-resume",
11708 },
11709 resumeSession: true,
11710 expectResumeRejected: true,
11711 })
11712 }
11713}
11714
Adam Langleya4b91982016-12-12 12:05:53 -080011715func addECDSAKeyUsageTests() {
11716 p256 := elliptic.P256()
11717 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11718 if err != nil {
11719 panic(err)
11720 }
11721
11722 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11723 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11724 if err != nil {
11725 panic(err)
11726 }
11727
11728 template := x509.Certificate{
11729 SerialNumber: serialNumber,
11730 Subject: pkix.Name{
11731 Organization: []string{"Acme Co"},
11732 },
11733 NotBefore: time.Now(),
11734 NotAfter: time.Now(),
11735
11736 // An ECC certificate with only the keyAgreement key usgae may
11737 // be used with ECDH, but not ECDSA.
11738 KeyUsage: x509.KeyUsageKeyAgreement,
11739 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11740 BasicConstraintsValid: true,
11741 }
11742
11743 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11744 if err != nil {
11745 panic(err)
11746 }
11747
11748 cert := Certificate{
11749 Certificate: [][]byte{derBytes},
11750 PrivateKey: priv,
11751 }
11752
11753 for _, ver := range tlsVersions {
11754 if ver.version < VersionTLS12 {
11755 continue
11756 }
11757
11758 testCases = append(testCases, testCase{
11759 testType: clientTest,
11760 name: "ECDSAKeyUsage-" + ver.name,
11761 config: Config{
11762 MinVersion: ver.version,
11763 MaxVersion: ver.version,
11764 Certificates: []Certificate{cert},
11765 },
11766 shouldFail: true,
11767 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11768 })
11769 }
11770}
11771
David Benjamin8c26d752017-03-26 15:13:51 -050011772func addExtraHandshakeTests() {
11773 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11774 // to ensure there is no transport I/O.
11775 testCases = append(testCases, testCase{
11776 testType: clientTest,
11777 name: "ExtraHandshake-Client-TLS12",
11778 config: Config{
11779 MinVersion: VersionTLS12,
11780 MaxVersion: VersionTLS12,
11781 },
11782 flags: []string{
11783 "-async",
11784 "-no-op-extra-handshake",
11785 },
11786 })
11787 testCases = append(testCases, testCase{
11788 testType: serverTest,
11789 name: "ExtraHandshake-Server-TLS12",
11790 config: Config{
11791 MinVersion: VersionTLS12,
11792 MaxVersion: VersionTLS12,
11793 },
11794 flags: []string{
11795 "-async",
11796 "-no-op-extra-handshake",
11797 },
11798 })
11799 testCases = append(testCases, testCase{
11800 testType: clientTest,
11801 name: "ExtraHandshake-Client-TLS13",
11802 config: Config{
11803 MinVersion: VersionTLS13,
11804 MaxVersion: VersionTLS13,
11805 },
11806 flags: []string{
11807 "-async",
11808 "-no-op-extra-handshake",
11809 },
11810 })
11811 testCases = append(testCases, testCase{
11812 testType: serverTest,
11813 name: "ExtraHandshake-Server-TLS13",
11814 config: Config{
11815 MinVersion: VersionTLS13,
11816 MaxVersion: VersionTLS13,
11817 },
11818 flags: []string{
11819 "-async",
11820 "-no-op-extra-handshake",
11821 },
11822 })
11823
11824 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11825 testCases = append(testCases, testCase{
11826 testType: serverTest,
11827 name: "ExtraHandshake-Server-EarlyData-TLS13",
11828 config: Config{
11829 MaxVersion: VersionTLS13,
11830 MinVersion: VersionTLS13,
11831 Bugs: ProtocolBugs{
11832 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11833 ExpectEarlyDataAccepted: true,
11834 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11835 },
11836 },
11837 messageCount: 2,
11838 resumeSession: true,
11839 flags: []string{
11840 "-async",
11841 "-enable-early-data",
11842 "-expect-accept-early-data",
11843 "-no-op-extra-handshake",
11844 },
11845 })
11846
11847 // An extra SSL_do_handshake drives the handshake to completion in False
11848 // Start. We test this by handshaking twice and asserting the False
11849 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11850 // how the test works.
11851 testCases = append(testCases, testCase{
11852 testType: clientTest,
11853 name: "ExtraHandshake-FalseStart",
11854 config: Config{
11855 MaxVersion: VersionTLS12,
11856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11857 NextProtos: []string{"foo"},
11858 Bugs: ProtocolBugs{
11859 ExpectFalseStart: true,
11860 AlertBeforeFalseStartTest: alertAccessDenied,
11861 },
11862 },
11863 flags: []string{
11864 "-handshake-twice",
11865 "-false-start",
11866 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011867 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011868 },
11869 shimWritesFirst: true,
11870 shouldFail: true,
11871 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11872 expectedLocalError: "tls: peer did not false start: EOF",
11873 })
11874}
11875
Adam Langley7c803a62015-06-15 15:35:05 -070011876func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011877 defer wg.Done()
11878
11879 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011880 var err error
11881
David Benjaminba28dfc2016-11-15 17:47:21 +090011882 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011883 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11884 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011885 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011886 if err != nil {
11887 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11888 }
11889 break
11890 }
11891 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011892 } else if *repeatUntilFailure {
11893 for err == nil {
11894 statusChan <- statusMsg{test: test, started: true}
11895 err = runTest(test, shimPath, -1)
11896 }
11897 } else {
11898 statusChan <- statusMsg{test: test, started: true}
11899 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011900 }
Adam Langley95c29f32014-06-20 12:00:00 -070011901 statusChan <- statusMsg{test: test, err: err}
11902 }
11903}
11904
11905type statusMsg struct {
11906 test *testCase
11907 started bool
11908 err error
11909}
11910
David Benjamin5f237bc2015-02-11 17:14:15 -050011911func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011912 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011913
David Benjamin5f237bc2015-02-11 17:14:15 -050011914 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011915 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011916 if !*pipe {
11917 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011918 var erase string
11919 for i := 0; i < lineLen; i++ {
11920 erase += "\b \b"
11921 }
11922 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011923 }
11924
Adam Langley95c29f32014-06-20 12:00:00 -070011925 if msg.started {
11926 started++
11927 } else {
11928 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011929
11930 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011931 if msg.err == errUnimplemented {
11932 if *pipe {
11933 // Print each test instead of a status line.
11934 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11935 }
11936 unimplemented++
11937 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11938 } else {
11939 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11940 failed++
11941 testOutput.addResult(msg.test.name, "FAIL")
11942 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011943 } else {
11944 if *pipe {
11945 // Print each test instead of a status line.
11946 fmt.Printf("PASSED (%s)\n", msg.test.name)
11947 }
11948 testOutput.addResult(msg.test.name, "PASS")
11949 }
Adam Langley95c29f32014-06-20 12:00:00 -070011950 }
11951
David Benjamin5f237bc2015-02-11 17:14:15 -050011952 if !*pipe {
11953 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011954 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011955 lineLen = len(line)
11956 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011957 }
Adam Langley95c29f32014-06-20 12:00:00 -070011958 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011959
11960 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011961}
11962
11963func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011964 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011965 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011966 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011967
Adam Langley7c803a62015-06-15 15:35:05 -070011968 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011969 addCipherSuiteTests()
11970 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011971 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011972 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011973 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011974 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011975 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011976 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011977 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011978 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011979 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011980 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011981 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011982 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011983 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011984 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011985 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011986 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011987 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011988 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011989 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011990 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011991 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011992 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011993 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011994 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011995 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011996 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011997 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011998 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011999 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012000 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012001 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012002 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012003
12004 var wg sync.WaitGroup
12005
Adam Langley7c803a62015-06-15 15:35:05 -070012006 statusChan := make(chan statusMsg, *numWorkers)
12007 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012008 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012009
EKRf71d7ed2016-08-06 13:25:12 -070012010 if len(*shimConfigFile) != 0 {
12011 encoded, err := ioutil.ReadFile(*shimConfigFile)
12012 if err != nil {
12013 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12014 os.Exit(1)
12015 }
12016
12017 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12018 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12019 os.Exit(1)
12020 }
12021 }
12022
David Benjamin025b3d32014-07-01 19:53:04 -040012023 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012024
Adam Langley7c803a62015-06-15 15:35:05 -070012025 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012026 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012027 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012028 }
12029
David Benjamin270f0a72016-03-17 14:41:36 -040012030 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012031 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012032 matched := true
12033 if len(*testToRun) != 0 {
12034 var err error
12035 matched, err = filepath.Match(*testToRun, testCases[i].name)
12036 if err != nil {
12037 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12038 os.Exit(1)
12039 }
12040 }
12041
EKRf71d7ed2016-08-06 13:25:12 -070012042 if !*includeDisabled {
12043 for pattern := range shimConfig.DisabledTests {
12044 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12045 if err != nil {
12046 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12047 os.Exit(1)
12048 }
12049
12050 if isDisabled {
12051 matched = false
12052 break
12053 }
12054 }
12055 }
12056
David Benjamin17e12922016-07-28 18:04:43 -040012057 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012058 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012059 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012060
12061 // Only run one test if repeating until failure.
12062 if *repeatUntilFailure {
12063 break
12064 }
Adam Langley95c29f32014-06-20 12:00:00 -070012065 }
12066 }
David Benjamin17e12922016-07-28 18:04:43 -040012067
David Benjamin270f0a72016-03-17 14:41:36 -040012068 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012069 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012070 os.Exit(1)
12071 }
Adam Langley95c29f32014-06-20 12:00:00 -070012072
12073 close(testChan)
12074 wg.Wait()
12075 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012076 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012077
12078 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012079
12080 if *jsonOutput != "" {
12081 if err := testOutput.writeTo(*jsonOutput); err != nil {
12082 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12083 }
12084 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012085
EKR842ae6c2016-07-27 09:22:05 +020012086 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12087 os.Exit(1)
12088 }
12089
12090 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012091 os.Exit(1)
12092 }
Adam Langley95c29f32014-06-20 12:00:00 -070012093}