blob: c5f997159055cc8a1e0f96cbd6b071ed84948c8d [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdez520e1222017-06-13 12:45:25 -0400266// recordVersionToWire maps a record-layer protocol version to its wire
267// representation.
268func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400269 if protocol == dtls {
270 switch vers {
271 case VersionTLS12:
272 return VersionDTLS12
273 case VersionTLS10:
274 return VersionDTLS10
275 }
276 } else {
277 switch vers {
278 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
279 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400280 }
281 }
282
283 panic("unknown version")
284}
285
Adam Langley2ff79332017-02-28 13:45:39 -0800286// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
287func encodeDERValues(values [][]byte) string {
288 var ret string
289 for i, v := range values {
290 if i > 0 {
291 ret += ","
292 }
293 ret += hex.EncodeToString(v)
294 }
295
296 return ret
297}
298
David Benjamin025b3d32014-07-01 19:53:04 -0400299type testType int
300
301const (
302 clientTest testType = iota
303 serverTest
304)
305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306type protocol int
307
308const (
309 tls protocol = iota
310 dtls
311)
312
David Benjaminfc7b0862014-09-06 13:21:53 -0400313const (
314 alpn = 1
315 npn = 2
316)
317
Adam Langley95c29f32014-06-20 12:00:00 -0700318type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400319 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400320 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700321 name string
322 config Config
323 shouldFail bool
324 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700325 // expectedLocalError, if not empty, contains a substring that must be
326 // found in the local error.
327 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400328 // expectedVersion, if non-zero, specifies the TLS version that must be
329 // negotiated.
330 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400331 // expectedResumeVersion, if non-zero, specifies the TLS version that
332 // must be negotiated on resumption. If zero, expectedVersion is used.
333 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400334 // expectedCipher, if non-zero, specifies the TLS cipher suite that
335 // should be negotiated.
336 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400337 // expectChannelID controls whether the connection should have
338 // negotiated a Channel ID with channelIDKey.
339 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400340 // expectedNextProto controls whether the connection should
341 // negotiate a next protocol via NPN or ALPN.
342 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400343 // expectNoNextProto, if true, means that no next protocol should be
344 // negotiated.
345 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400346 // expectedNextProtoType, if non-zero, is the expected next
347 // protocol negotiation mechanism.
348 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500349 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
350 // should be negotiated. If zero, none should be negotiated.
351 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100352 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
353 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 // expectedSCTList, if not nil, is the expected SCT list to be received.
355 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700356 // expectedPeerSignatureAlgorithm, if not zero, is the signature
357 // algorithm that the peer should have used in the handshake.
358 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400359 // expectedCurveID, if not zero, is the curve that the handshake should
360 // have used.
361 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700362 // messageLen is the length, in bytes, of the test message that will be
363 // sent.
364 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400365 // messageCount is the number of test messages that will be sent.
366 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400367 // certFile is the path to the certificate to use for the server.
368 certFile string
369 // keyFile is the path to the private key to use for the server.
370 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400371 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400372 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400373 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400374 // resumeRenewedSession controls whether a third connection should be
375 // tested which attempts to resume the second connection's session.
376 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700377 // expectResumeRejected, if true, specifies that the attempted
378 // resumption must be rejected by the client. This is only valid for a
379 // serverTest.
380 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400381 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500382 // resumption. Unless newSessionsOnResume is set,
383 // SessionTicketKey, ServerSessionCache, and
384 // ClientSessionCache are copied from the initial connection's
385 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400386 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // newSessionsOnResume, if true, will cause resumeConfig to
388 // use a different session resumption context.
389 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400390 // noSessionCache, if true, will cause the server to run without a
391 // session cache.
392 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400393 // sendPrefix sends a prefix on the socket before actually performing a
394 // handshake.
395 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400396 // shimWritesFirst controls whether the shim sends an initial "hello"
397 // message before doing a roundtrip with the runner.
398 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400399 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
400 // does not complete the write until responding to the first runner
401 // message.
402 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400403 // shimShutsDown, if true, runs a test where the shim shuts down the
404 // connection immediately after the handshake rather than echoing
405 // messages from the runner.
406 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400407 // renegotiate indicates the number of times the connection should be
408 // renegotiated during the exchange.
409 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400410 // sendHalfHelloRequest, if true, causes the server to send half a
411 // HelloRequest when the handshake completes.
412 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700413 // renegotiateCiphers is a list of ciphersuite ids that will be
414 // switched in just before renegotiation.
415 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500416 // replayWrites, if true, configures the underlying transport
417 // to replay every write it makes in DTLS tests.
418 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 // damageFirstWrite, if true, configures the underlying transport to
420 // damage the final byte of the first application data write.
421 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400422 // exportKeyingMaterial, if non-zero, configures the test to exchange
423 // keying material and verify they match.
424 exportKeyingMaterial int
425 exportLabel string
426 exportContext string
427 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400428 // flags, if not empty, contains a list of command-line flags that will
429 // be passed to the shim program.
430 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700431 // testTLSUnique, if true, causes the shim to send the tls-unique value
432 // which will be compared against the expected value.
433 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400434 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400435 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400436 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400437 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400438 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400439 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400440 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
441 // be sent before each test message.
442 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400443 // sendKeyUpdates is the number of consecutive key updates to send
444 // before and after the test message.
445 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400446 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
447 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400448 // expectMessageDropped, if true, means the test message is expected to
449 // be dropped by the client rather than echoed back.
450 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900451 // expectPeerCertificate, if not nil, is the certificate chain the peer
452 // is expected to send.
453 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500454 // shimPrefix is the prefix that the shim will send to the server.
455 shimPrefix string
456 // resumeShimPrefix is the prefix that the shim will send to the server on a
457 // resumption.
458 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400459 // tls13Variant, if non-zero, causes both runner and shim to be
460 // configured with the specified TLS 1.3 variant. This is a convenience
461 // option for configuring both concurrently.
462 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700463}
464
Adam Langley7c803a62015-06-15 15:35:05 -0700465var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin0fde2eb2017-06-30 19:11:22 -0400467func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if len(data) == 0 {
469 return
470 }
471
David Benjamin0fde2eb2017-06-30 19:11:22 -0400472 settings, err := ioutil.ReadFile(path)
473 if err != nil {
474 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings = append(settings, data...)
479 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
480 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 }
482}
483
David Benjamin3ed59772016-03-08 12:50:21 -0500484// A timeoutConn implements an idle timeout on each Read and Write operation.
485type timeoutConn struct {
486 net.Conn
487 timeout time.Duration
488}
489
490func (t *timeoutConn) Read(b []byte) (int, error) {
491 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
492 return 0, err
493 }
494 return t.Conn.Read(b)
495}
496
497func (t *timeoutConn) Write(b []byte) (int, error) {
498 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
499 return 0, err
500 }
501 return t.Conn.Write(b)
502}
503
David Benjamin0fde2eb2017-06-30 19:11:22 -0400504func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400505 if !test.noSessionCache {
506 if config.ClientSessionCache == nil {
507 config.ClientSessionCache = NewLRUClientSessionCache(1)
508 }
509 if config.ServerSessionCache == nil {
510 config.ServerSessionCache = NewLRUServerSessionCache(1)
511 }
512 }
513 if test.testType == clientTest {
514 if len(config.Certificates) == 0 {
515 config.Certificates = []Certificate{rsaCertificate}
516 }
517 } else {
518 // Supply a ServerName to ensure a constant session cache key,
519 // rather than falling back to net.Conn.RemoteAddr.
520 if len(config.ServerName) == 0 {
521 config.ServerName = "test"
522 }
523 }
524 if *fuzzer {
525 config.Bugs.NullAllCiphers = true
526 }
David Benjamin01a90572016-09-22 00:11:43 -0400527 if *deterministic {
528 config.Time = func() time.Time { return time.Unix(1234, 1234) }
529 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400530 if test.tls13Variant != 0 {
531 config.TLS13Variant = test.tls13Variant
532 }
David Benjamine54af062016-08-08 19:21:18 -0400533
David Benjamin01784b42016-06-07 18:00:52 -0400534 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500535
David Benjamin6fd297b2014-08-11 18:43:38 -0400536 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500537 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
538 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500539 }
540
David Benjamin9867b7d2016-03-01 23:25:48 -0500541 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500542 local, peer := "client", "server"
543 if test.testType == clientTest {
544 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500545 }
David Benjaminebda9b32015-11-02 15:33:18 -0500546 connDebug := &recordingConn{
547 Conn: conn,
548 isDatagram: test.protocol == dtls,
549 local: local,
550 peer: peer,
551 }
552 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500553 if *flagDebug {
554 defer connDebug.WriteTo(os.Stdout)
555 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500557 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400558 path := transcriptPrefix + strconv.Itoa(num)
559 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500560 }()
561 }
David Benjaminebda9b32015-11-02 15:33:18 -0500562
563 if config.Bugs.PacketAdaptor != nil {
564 config.Bugs.PacketAdaptor.debug = connDebug
565 }
566 }
567
568 if test.replayWrites {
569 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400570 }
571
David Benjamin3ed59772016-03-08 12:50:21 -0500572 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500573 if test.damageFirstWrite {
574 connDamage = newDamageAdaptor(conn)
575 conn = connDamage
576 }
577
David Benjamin6fd297b2014-08-11 18:43:38 -0400578 if test.sendPrefix != "" {
579 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
580 return err
581 }
David Benjamin98e882e2014-08-08 13:24:34 -0400582 }
583
David Benjamin1d5c83e2014-07-22 19:20:02 -0400584 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400585 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400586 if test.protocol == dtls {
587 tlsConn = DTLSServer(conn, config)
588 } else {
589 tlsConn = Server(conn, config)
590 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400591 } else {
592 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400593 if test.protocol == dtls {
594 tlsConn = DTLSClient(conn, config)
595 } else {
596 tlsConn = Client(conn, config)
597 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598 }
David Benjamin30789da2015-08-29 22:56:45 -0400599 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400600
Adam Langley95c29f32014-06-20 12:00:00 -0700601 if err := tlsConn.Handshake(); err != nil {
602 return err
603 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700604
David Benjamin01fe8202014-09-24 15:21:44 -0400605 // TODO(davidben): move all per-connection expectations into a dedicated
606 // expectations struct that can be specified separately for the two
607 // legs.
608 expectedVersion := test.expectedVersion
609 if isResume && test.expectedResumeVersion != 0 {
610 expectedVersion = test.expectedResumeVersion
611 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700612 connState := tlsConn.ConnectionState()
613 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400614 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400615 }
616
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700617 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400618 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
619 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700620 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
621 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
622 }
David Benjamin90da8c82015-04-20 14:57:57 -0400623
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700625 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400626 if channelID == nil {
627 return fmt.Errorf("no channel ID negotiated")
628 }
629 if channelID.Curve != channelIDKey.Curve ||
630 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
631 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
632 return fmt.Errorf("incorrect channel ID")
633 }
David Benjamin634f4752017-07-01 11:08:41 -0400634 } else if connState.ChannelID != nil {
635 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400636 }
637
David Benjaminae2888f2014-09-06 12:58:58 -0400638 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700639 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400640 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
641 }
642 }
643
David Benjaminc7ce9772015-10-09 19:32:41 -0400644 if test.expectNoNextProto {
645 if actual := connState.NegotiatedProtocol; actual != "" {
646 return fmt.Errorf("got unexpected next proto %s", actual)
647 }
648 }
649
David Benjaminfc7b0862014-09-06 13:21:53 -0400650 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700651 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400652 return fmt.Errorf("next proto type mismatch")
653 }
654 }
655
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700656 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500657 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
658 }
659
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100660 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300661 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100662 }
663
Paul Lietar4fac72e2015-09-09 13:44:55 +0100664 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
665 return fmt.Errorf("SCT list mismatch")
666 }
667
Nick Harper60edffd2016-06-21 15:19:24 -0700668 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
669 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400670 }
671
Steven Valdez5440fe02016-07-18 12:40:30 -0400672 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
673 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
674 }
675
David Benjamin2c516452016-11-15 10:16:54 +0900676 if test.expectPeerCertificate != nil {
677 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
678 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
679 }
680 for i, cert := range connState.PeerCertificates {
681 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
682 return fmt.Errorf("peer certificate %d did not match", i+1)
683 }
684 }
685 }
686
David Benjaminc565ebb2015-04-03 04:06:36 -0400687 if test.exportKeyingMaterial > 0 {
688 actual := make([]byte, test.exportKeyingMaterial)
689 if _, err := io.ReadFull(tlsConn, actual); err != nil {
690 return err
691 }
692 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
693 if err != nil {
694 return err
695 }
696 if !bytes.Equal(actual, expected) {
697 return fmt.Errorf("keying material mismatch")
698 }
699 }
700
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700701 if test.testTLSUnique {
702 var peersValue [12]byte
703 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
704 return err
705 }
706 expected := tlsConn.ConnectionState().TLSUnique
707 if !bytes.Equal(peersValue[:], expected) {
708 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
709 }
710 }
711
David Benjamin47921102016-07-28 11:29:18 -0400712 if test.sendHalfHelloRequest {
713 tlsConn.SendHalfHelloRequest()
714 }
715
Steven Valdeze831a812017-03-09 14:56:07 -0500716 shimPrefix := test.shimPrefix
717 if isResume {
718 shimPrefix = test.resumeShimPrefix
719 }
720 if test.shimWritesFirst || test.readWithUnfinishedWrite {
721 shimPrefix = "hello"
722 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400723 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400724 // If readWithUnfinishedWrite is set, the shim prefix will be
725 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500726 if shimPrefix != "" && !test.readWithUnfinishedWrite {
727 var buf = make([]byte, len(shimPrefix))
728 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400729 if err != nil {
730 return err
731 }
Steven Valdeze831a812017-03-09 14:56:07 -0500732 if string(buf) != shimPrefix {
733 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400734 }
Steven Valdeze831a812017-03-09 14:56:07 -0500735 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400736 }
737
Adam Langleycf2d4f42014-10-28 19:06:14 -0700738 if test.renegotiateCiphers != nil {
739 config.CipherSuites = test.renegotiateCiphers
740 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400741 for i := 0; i < test.renegotiate; i++ {
742 if err := tlsConn.Renegotiate(); err != nil {
743 return err
744 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700745 }
746 } else if test.renegotiateCiphers != nil {
747 panic("renegotiateCiphers without renegotiate")
748 }
749
David Benjamin5fa3eba2015-01-22 16:35:40 -0500750 if test.damageFirstWrite {
751 connDamage.setDamage(true)
752 tlsConn.Write([]byte("DAMAGED WRITE"))
753 connDamage.setDamage(false)
754 }
755
David Benjamin8e6db492015-07-25 18:29:23 -0400756 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700757 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400758 if test.protocol == dtls {
759 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
760 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700761 // Read until EOF.
762 _, err := io.Copy(ioutil.Discard, tlsConn)
763 return err
764 }
David Benjamin4417d052015-04-05 04:17:25 -0400765 if messageLen == 0 {
766 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700767 }
Adam Langley95c29f32014-06-20 12:00:00 -0700768
David Benjamin8e6db492015-07-25 18:29:23 -0400769 messageCount := test.messageCount
770 if messageCount == 0 {
771 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400772 }
773
David Benjamin8e6db492015-07-25 18:29:23 -0400774 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400775 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400776 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400777 }
778
David Benjamin8e6db492015-07-25 18:29:23 -0400779 for i := 0; i < test.sendEmptyRecords; i++ {
780 tlsConn.Write(nil)
781 }
782
783 for i := 0; i < test.sendWarningAlerts; i++ {
784 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
785 }
786
David Benjamin24e58862017-06-14 18:45:29 -0400787 if test.sendBogusAlertType {
788 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
789 }
790
David Benjaminbbba9392017-04-06 12:54:12 -0400791 testMessage := make([]byte, messageLen)
792 for i := range testMessage {
793 testMessage[i] = 0x42 ^ byte(j)
794 }
795 tlsConn.Write(testMessage)
796
797 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500798 if shimPrefix != "" {
799 var buf = make([]byte, len(shimPrefix))
800 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400801 if err != nil {
802 return err
803 }
Steven Valdeze831a812017-03-09 14:56:07 -0500804 if string(buf) != shimPrefix {
805 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400806 }
Steven Valdeze831a812017-03-09 14:56:07 -0500807 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400808 }
809
David Benjamin4f75aaf2015-09-01 16:53:10 -0400810 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400811 // The shim will not respond.
812 continue
813 }
814
David Benjaminbbba9392017-04-06 12:54:12 -0400815 // Process the KeyUpdate ACK. However many KeyUpdates the runner
816 // sends, the shim should respond only once.
817 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
818 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
819 return err
820 }
821 }
822
David Benjamin8e6db492015-07-25 18:29:23 -0400823 buf := make([]byte, len(testMessage))
824 if test.protocol == dtls {
825 bufTmp := make([]byte, len(buf)+1)
826 n, err := tlsConn.Read(bufTmp)
827 if err != nil {
828 return err
829 }
830 if n != len(buf) {
831 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
832 }
833 copy(buf, bufTmp)
834 } else {
835 _, err := io.ReadFull(tlsConn, buf)
836 if err != nil {
837 return err
838 }
839 }
840
841 for i, v := range buf {
842 if v != testMessage[i]^0xff {
843 return fmt.Errorf("bad reply contents at byte %d", i)
844 }
Adam Langley95c29f32014-06-20 12:00:00 -0700845 }
846 }
847
848 return nil
849}
850
David Benjamin325b5c32014-07-01 19:40:31 -0400851func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400852 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700853 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400854 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700855 }
David Benjamin325b5c32014-07-01 19:40:31 -0400856 valgrindArgs = append(valgrindArgs, path)
857 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700858
David Benjamin325b5c32014-07-01 19:40:31 -0400859 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700860}
861
David Benjamin325b5c32014-07-01 19:40:31 -0400862func gdbOf(path string, args ...string) *exec.Cmd {
863 xtermArgs := []string{"-e", "gdb", "--args"}
864 xtermArgs = append(xtermArgs, path)
865 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700866
David Benjamin325b5c32014-07-01 19:40:31 -0400867 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700868}
869
David Benjamind16bf342015-12-18 00:53:12 -0500870func lldbOf(path string, args ...string) *exec.Cmd {
871 xtermArgs := []string{"-e", "lldb", "--"}
872 xtermArgs = append(xtermArgs, path)
873 xtermArgs = append(xtermArgs, args...)
874
875 return exec.Command("xterm", xtermArgs...)
876}
877
EKR842ae6c2016-07-27 09:22:05 +0200878var (
879 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
880 errUnimplemented = errors.New("child process does not implement needed flags")
881)
Adam Langley69a01602014-11-17 17:26:55 -0800882
David Benjamin87c8a642015-02-21 01:54:29 -0500883// accept accepts a connection from listener, unless waitChan signals a process
884// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400885func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500886 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400887 conn net.Conn
888 err error
889 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500890 }
891 connChan := make(chan connOrError, 1)
892 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400893 startTime := time.Now()
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400894 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500895 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400896 endTime := time.Now()
897 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500898 close(connChan)
899 }()
900 select {
901 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400902 if result.err != nil {
903 // TODO(davidben): Remove this logging when
904 // https://crbug.com/boringssl/199 is resolved.
905 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
906 }
David Benjamin87c8a642015-02-21 01:54:29 -0500907 return result.conn, result.err
908 case childErr := <-waitChan:
909 waitChan <- childErr
910 return nil, fmt.Errorf("child exited early: %s", childErr)
911 }
912}
913
EKRf71d7ed2016-08-06 13:25:12 -0700914func translateExpectedError(errorStr string) string {
915 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
916 return translated
917 }
918
919 if *looseErrors {
920 return ""
921 }
922
923 return errorStr
924}
925
Adam Langley7c803a62015-06-15 15:35:05 -0700926func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400927 // Help debugging panics on the Go side.
928 defer func() {
929 if r := recover(); r != nil {
930 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
931 panic(r)
932 }
933 }()
934
Adam Langley38311732014-10-16 19:04:35 -0700935 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
936 panic("Error expected without shouldFail in " + test.name)
937 }
938
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700939 if test.expectResumeRejected && !test.resumeSession {
940 panic("expectResumeRejected without resumeSession in " + test.name)
941 }
942
Adam Langley33b1d4f2016-12-07 15:03:45 -0800943 for _, ver := range tlsVersions {
944 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
945 continue
946 }
947
David Benjamina5022392017-07-10 17:40:39 -0400948 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
949 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
Adam Langley33b1d4f2016-12-07 15:03:45 -0800950 }
951
David Benjamina5022392017-07-10 17:40:39 -0400952 if ver.tls13Variant != 0 {
953 var foundFlag bool
954 for _, flag := range test.flags {
955 if flag == "-tls13-variant" {
956 foundFlag = true
957 break
958 }
959 }
960 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
961 panic(fmt.Sprintf("The name of test %q suggests that uses an experimental TLS 1.3 variant, but neither the shim nor the runner configures it", test.name))
962 }
963 }
964
Adam Langley33b1d4f2016-12-07 15:03:45 -0800965 }
966
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700967 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
968 if err != nil {
969 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
970 }
David Benjamin87c8a642015-02-21 01:54:29 -0500971 if err != nil {
972 panic(err)
973 }
974 defer func() {
975 if listener != nil {
976 listener.Close()
977 }
978 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700979
David Benjamin87c8a642015-02-21 01:54:29 -0500980 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400981 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400982 flags = append(flags, "-server")
983
David Benjamin025b3d32014-07-01 19:53:04 -0400984 flags = append(flags, "-key-file")
985 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700986 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400987 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700988 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400989 }
990
991 flags = append(flags, "-cert-file")
992 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700993 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400994 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700995 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400996 }
997 }
David Benjamin5a593af2014-08-11 19:51:50 -0400998
David Benjamin6fd297b2014-08-11 18:43:38 -0400999 if test.protocol == dtls {
1000 flags = append(flags, "-dtls")
1001 }
1002
David Benjamin46662482016-08-17 00:51:00 -04001003 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001004 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001005 resumeCount++
1006 if test.resumeRenewedSession {
1007 resumeCount++
1008 }
1009 }
1010
1011 if resumeCount > 0 {
1012 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001013 }
1014
David Benjamine58c4f52014-08-24 03:47:07 -04001015 if test.shimWritesFirst {
1016 flags = append(flags, "-shim-writes-first")
1017 }
1018
David Benjaminbbba9392017-04-06 12:54:12 -04001019 if test.readWithUnfinishedWrite {
1020 flags = append(flags, "-read-with-unfinished-write")
1021 }
1022
David Benjamin30789da2015-08-29 22:56:45 -04001023 if test.shimShutsDown {
1024 flags = append(flags, "-shim-shuts-down")
1025 }
1026
David Benjaminc565ebb2015-04-03 04:06:36 -04001027 if test.exportKeyingMaterial > 0 {
1028 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1029 flags = append(flags, "-export-label", test.exportLabel)
1030 flags = append(flags, "-export-context", test.exportContext)
1031 if test.useExportContext {
1032 flags = append(flags, "-use-export-context")
1033 }
1034 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001035 if test.expectResumeRejected {
1036 flags = append(flags, "-expect-session-miss")
1037 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001038
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001039 if test.testTLSUnique {
1040 flags = append(flags, "-tls-unique")
1041 }
1042
David Benjamina5022392017-07-10 17:40:39 -04001043 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001044 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1045 }
1046
David Benjamin0fde2eb2017-06-30 19:11:22 -04001047 var transcriptPrefix string
1048 if len(*transcriptDir) != 0 {
1049 protocol := "tls"
1050 if test.protocol == dtls {
1051 protocol = "dtls"
1052 }
1053
1054 side := "client"
1055 if test.testType == serverTest {
1056 side = "server"
1057 }
1058
1059 dir := filepath.Join(*transcriptDir, protocol, side)
1060 if err := os.MkdirAll(dir, 0755); err != nil {
1061 return err
1062 }
1063 transcriptPrefix = filepath.Join(dir, test.name+"-")
1064 flags = append(flags, "-write-settings", transcriptPrefix)
1065 }
1066
David Benjamin025b3d32014-07-01 19:53:04 -04001067 flags = append(flags, test.flags...)
1068
1069 var shim *exec.Cmd
1070 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001071 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001072 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001073 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001074 } else if *useLLDB {
1075 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001076 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001077 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001078 }
David Benjamin025b3d32014-07-01 19:53:04 -04001079 shim.Stdin = os.Stdin
1080 var stdoutBuf, stderrBuf bytes.Buffer
1081 shim.Stdout = &stdoutBuf
1082 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001083 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001084 shim.Env = os.Environ()
1085 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001086 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001087 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001088 }
1089 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1090 }
David Benjamin025b3d32014-07-01 19:53:04 -04001091
1092 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001093 panic(err)
1094 }
David Benjamin87c8a642015-02-21 01:54:29 -05001095 waitChan := make(chan error, 1)
1096 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001097
1098 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001099
David Benjamin7a4aaa42016-09-20 17:58:14 -04001100 if *deterministic {
1101 config.Rand = &deterministicRand{}
1102 }
1103
David Benjamin87c8a642015-02-21 01:54:29 -05001104 conn, err := acceptOrWait(listener, waitChan)
1105 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001106 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001107 conn.Close()
1108 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001109
David Benjamin46662482016-08-17 00:51:00 -04001110 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001111 var resumeConfig Config
1112 if test.resumeConfig != nil {
1113 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001114 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001115 resumeConfig.SessionTicketKey = config.SessionTicketKey
1116 resumeConfig.ClientSessionCache = config.ClientSessionCache
1117 resumeConfig.ServerSessionCache = config.ServerSessionCache
1118 }
David Benjamin2e045a92016-06-08 13:09:56 -04001119 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001120 } else {
1121 resumeConfig = config
1122 }
David Benjamin87c8a642015-02-21 01:54:29 -05001123 var connResume net.Conn
1124 connResume, err = acceptOrWait(listener, waitChan)
1125 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001126 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001127 connResume.Close()
1128 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001129 }
1130
David Benjamin87c8a642015-02-21 01:54:29 -05001131 // Close the listener now. This is to avoid hangs should the shim try to
1132 // open more connections than expected.
1133 listener.Close()
1134 listener = nil
1135
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001136 var shimKilledLock sync.Mutex
1137 var shimKilled bool
1138 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1139 shimKilledLock.Lock()
1140 shimKilled = true
1141 shimKilledLock.Unlock()
1142 shim.Process.Kill()
1143 })
David Benjamin87c8a642015-02-21 01:54:29 -05001144 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001145 waitTimeout.Stop()
1146 shimKilledLock.Lock()
1147 if shimKilled && err == nil {
1148 err = errors.New("timeout waiting for the shim to exit.")
1149 }
1150 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001151 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001152 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001153 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1154 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001155 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001156 case 89:
1157 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001158 case 99:
1159 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001160 }
1161 }
Adam Langley95c29f32014-06-20 12:00:00 -07001162
David Benjamin9bea3492016-03-02 10:59:16 -05001163 // Account for Windows line endings.
1164 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1165 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001166
1167 // Separate the errors from the shim and those from tools like
1168 // AddressSanitizer.
1169 var extraStderr string
1170 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1171 stderr = stderrParts[0]
1172 extraStderr = stderrParts[1]
1173 }
1174
Adam Langley95c29f32014-06-20 12:00:00 -07001175 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001176 expectedError := translateExpectedError(test.expectedError)
1177 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001178
Adam Langleyac61fa32014-06-23 12:03:11 -07001179 localError := "none"
1180 if err != nil {
1181 localError = err.Error()
1182 }
1183 if len(test.expectedLocalError) != 0 {
1184 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1185 }
Adam Langley95c29f32014-06-20 12:00:00 -07001186
1187 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001188 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001189 if childErr != nil {
1190 childError = childErr.Error()
1191 }
1192
1193 var msg string
1194 switch {
1195 case failed && !test.shouldFail:
1196 msg = "unexpected failure"
1197 case !failed && test.shouldFail:
1198 msg = "unexpected success"
1199 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001200 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001201 default:
1202 panic("internal error")
1203 }
1204
David Benjamin9aafb642016-09-20 19:36:53 -04001205 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 -07001206 }
1207
David Benjamind2ba8892016-09-20 19:41:04 -04001208 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001209 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001210 }
1211
David Benjamind2ba8892016-09-20 19:41:04 -04001212 if *useValgrind && isValgrindError {
1213 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1214 }
1215
Adam Langley95c29f32014-06-20 12:00:00 -07001216 return nil
1217}
1218
David Benjaminaa012042016-12-10 13:33:05 -05001219type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001220 name string
1221 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001222 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001223 // excludeFlag is the legacy shim flag to disable the version.
1224 excludeFlag string
1225 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001226 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1227 versionDTLS uint16
1228 // versionWire, if non-zero, is the wire representation of the
1229 // version. Otherwise the wire version is the protocol version or
1230 // versionDTLS.
1231 versionWire uint16
1232 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001233}
1234
1235func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001236 // The shim uses the protocol version in its public API, but uses the
1237 // DTLS-specific version if it exists.
1238 if protocol == dtls && vers.versionDTLS != 0 {
1239 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001240 }
Steven Valdez520e1222017-06-13 12:45:25 -04001241 return strconv.Itoa(int(vers.version))
1242}
1243
1244func (vers tlsVersion) wire(protocol protocol) uint16 {
1245 if protocol == dtls && vers.versionDTLS != 0 {
1246 return vers.versionDTLS
1247 }
1248 if vers.versionWire != 0 {
1249 return vers.versionWire
1250 }
1251 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001252}
1253
1254var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001255 {
1256 name: "SSL3",
1257 version: VersionSSL30,
1258 excludeFlag: "-no-ssl3",
1259 },
1260 {
1261 name: "TLS1",
1262 version: VersionTLS10,
1263 excludeFlag: "-no-tls1",
1264 hasDTLS: true,
1265 versionDTLS: VersionDTLS10,
1266 },
1267 {
1268 name: "TLS11",
1269 version: VersionTLS11,
1270 excludeFlag: "-no-tls11",
1271 },
1272 {
1273 name: "TLS12",
1274 version: VersionTLS12,
1275 excludeFlag: "-no-tls12",
1276 hasDTLS: true,
1277 versionDTLS: VersionDTLS12,
1278 },
1279 {
1280 name: "TLS13",
1281 version: VersionTLS13,
1282 excludeFlag: "-no-tls13",
1283 versionWire: tls13DraftVersion,
1284 tls13Variant: TLS13Default,
1285 },
1286 {
1287 name: "TLS13Experiment",
1288 version: VersionTLS13,
1289 excludeFlag: "-no-tls13",
1290 versionWire: tls13ExperimentVersion,
1291 tls13Variant: TLS13Experiment,
1292 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001293 {
1294 name: "TLS13RecordTypeExperiment",
1295 version: VersionTLS13,
1296 excludeFlag: "-no-tls13",
1297 versionWire: tls13RecordTypeExperimentVersion,
1298 tls13Variant: TLS13RecordTypeExperiment,
1299 },
Steven Valdez520e1222017-06-13 12:45:25 -04001300}
1301
1302func allVersions(protocol protocol) []tlsVersion {
1303 if protocol == tls {
1304 return tlsVersions
1305 }
1306
1307 var ret []tlsVersion
1308 for _, vers := range tlsVersions {
1309 if vers.hasDTLS {
1310 ret = append(ret, vers)
1311 }
1312 }
1313 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001314}
1315
David Benjaminaa012042016-12-10 13:33:05 -05001316type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001317 name string
1318 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001319}
1320
1321var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001322 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001323 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001324 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001325 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001326 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001327 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001328 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001329 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1330 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001331 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1332 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001333 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001334 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001335 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001336 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001337 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001338 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001339 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001340 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001341 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001342 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001343 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1344 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001345 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1346 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001347 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001348 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1349 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1350 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001351 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001352}
1353
David Benjamin8b8c0062014-11-23 02:47:52 -05001354func hasComponent(suiteName, component string) bool {
1355 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1356}
1357
David Benjaminf7768e42014-08-31 02:06:47 -04001358func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001359 return hasComponent(suiteName, "GCM") ||
1360 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001361 hasComponent(suiteName, "SHA384") ||
1362 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001363}
1364
Nick Harper1fd39d82016-06-14 18:14:35 -07001365func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001366 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001367}
1368
David Benjamin8b8c0062014-11-23 02:47:52 -05001369func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001370 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001371}
1372
Adam Langleya7997f12015-05-14 17:38:50 -07001373func bigFromHex(hex string) *big.Int {
1374 ret, ok := new(big.Int).SetString(hex, 16)
1375 if !ok {
1376 panic("failed to parse hex number 0x" + hex)
1377 }
1378 return ret
1379}
1380
Adam Langley7c803a62015-06-15 15:35:05 -07001381func addBasicTests() {
1382 basicTests := []testCase{
1383 {
Adam Langley7c803a62015-06-15 15:35:05 -07001384 name: "NoFallbackSCSV",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 FailIfNotFallbackSCSV: true,
1388 },
1389 },
1390 shouldFail: true,
1391 expectedLocalError: "no fallback SCSV found",
1392 },
1393 {
1394 name: "SendFallbackSCSV",
1395 config: Config{
1396 Bugs: ProtocolBugs{
1397 FailIfNotFallbackSCSV: true,
1398 },
1399 },
1400 flags: []string{"-fallback-scsv"},
1401 },
1402 {
1403 name: "ClientCertificateTypes",
1404 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001405 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001406 ClientAuth: RequestClientCert,
1407 ClientCertificateTypes: []byte{
1408 CertTypeDSSSign,
1409 CertTypeRSASign,
1410 CertTypeECDSASign,
1411 },
1412 },
1413 flags: []string{
1414 "-expect-certificate-types",
1415 base64.StdEncoding.EncodeToString([]byte{
1416 CertTypeDSSSign,
1417 CertTypeRSASign,
1418 CertTypeECDSASign,
1419 }),
1420 },
1421 },
1422 {
Adam Langley7c803a62015-06-15 15:35:05 -07001423 name: "UnauthenticatedECDH",
1424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001425 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1427 Bugs: ProtocolBugs{
1428 UnauthenticatedECDH: true,
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":UNEXPECTED_MESSAGE:",
1433 },
1434 {
1435 name: "SkipCertificateStatus",
1436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001437 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1439 Bugs: ProtocolBugs{
1440 SkipCertificateStatus: true,
1441 },
1442 },
1443 flags: []string{
1444 "-enable-ocsp-stapling",
1445 },
1446 },
1447 {
1448 name: "SkipServerKeyExchange",
1449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001450 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Bugs: ProtocolBugs{
1453 SkipServerKeyExchange: true,
1454 },
1455 },
1456 shouldFail: true,
1457 expectedError: ":UNEXPECTED_MESSAGE:",
1458 },
1459 {
Adam Langley7c803a62015-06-15 15:35:05 -07001460 testType: serverTest,
1461 name: "Alert",
1462 config: Config{
1463 Bugs: ProtocolBugs{
1464 SendSpuriousAlert: alertRecordOverflow,
1465 },
1466 },
1467 shouldFail: true,
1468 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1469 },
1470 {
1471 protocol: dtls,
1472 testType: serverTest,
1473 name: "Alert-DTLS",
1474 config: Config{
1475 Bugs: ProtocolBugs{
1476 SendSpuriousAlert: alertRecordOverflow,
1477 },
1478 },
1479 shouldFail: true,
1480 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1481 },
1482 {
1483 testType: serverTest,
1484 name: "FragmentAlert",
1485 config: Config{
1486 Bugs: ProtocolBugs{
1487 FragmentAlert: true,
1488 SendSpuriousAlert: alertRecordOverflow,
1489 },
1490 },
1491 shouldFail: true,
1492 expectedError: ":BAD_ALERT:",
1493 },
1494 {
1495 protocol: dtls,
1496 testType: serverTest,
1497 name: "FragmentAlert-DTLS",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 FragmentAlert: true,
1501 SendSpuriousAlert: alertRecordOverflow,
1502 },
1503 },
1504 shouldFail: true,
1505 expectedError: ":BAD_ALERT:",
1506 },
1507 {
1508 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001509 name: "DoubleAlert",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 DoubleAlert: true,
1513 SendSpuriousAlert: alertRecordOverflow,
1514 },
1515 },
1516 shouldFail: true,
1517 expectedError: ":BAD_ALERT:",
1518 },
1519 {
1520 protocol: dtls,
1521 testType: serverTest,
1522 name: "DoubleAlert-DTLS",
1523 config: Config{
1524 Bugs: ProtocolBugs{
1525 DoubleAlert: true,
1526 SendSpuriousAlert: alertRecordOverflow,
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":BAD_ALERT:",
1531 },
1532 {
Adam Langley7c803a62015-06-15 15:35:05 -07001533 name: "SkipNewSessionTicket",
1534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001535 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001536 Bugs: ProtocolBugs{
1537 SkipNewSessionTicket: true,
1538 },
1539 },
1540 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001541 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001542 },
1543 {
1544 testType: serverTest,
1545 name: "FallbackSCSV",
1546 config: Config{
1547 MaxVersion: VersionTLS11,
1548 Bugs: ProtocolBugs{
1549 SendFallbackSCSV: true,
1550 },
1551 },
David Benjamin56cadc32016-12-16 19:54:11 -05001552 shouldFail: true,
1553 expectedError: ":INAPPROPRIATE_FALLBACK:",
1554 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001555 },
1556 {
1557 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001558 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001559 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001560 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001561 Bugs: ProtocolBugs{
1562 SendFallbackSCSV: true,
1563 },
1564 },
1565 },
1566 {
1567 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001568 name: "FallbackSCSV-VersionMatch-TLS12",
1569 config: Config{
1570 MaxVersion: VersionTLS12,
1571 Bugs: ProtocolBugs{
1572 SendFallbackSCSV: true,
1573 },
1574 },
1575 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1576 },
1577 {
1578 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001579 name: "FragmentedClientVersion",
1580 config: Config{
1581 Bugs: ProtocolBugs{
1582 MaxHandshakeRecordLength: 1,
1583 FragmentClientVersion: true,
1584 },
1585 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001586 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001587 },
1588 {
Adam Langley7c803a62015-06-15 15:35:05 -07001589 testType: serverTest,
1590 name: "HttpGET",
1591 sendPrefix: "GET / HTTP/1.0\n",
1592 shouldFail: true,
1593 expectedError: ":HTTP_REQUEST:",
1594 },
1595 {
1596 testType: serverTest,
1597 name: "HttpPOST",
1598 sendPrefix: "POST / HTTP/1.0\n",
1599 shouldFail: true,
1600 expectedError: ":HTTP_REQUEST:",
1601 },
1602 {
1603 testType: serverTest,
1604 name: "HttpHEAD",
1605 sendPrefix: "HEAD / HTTP/1.0\n",
1606 shouldFail: true,
1607 expectedError: ":HTTP_REQUEST:",
1608 },
1609 {
1610 testType: serverTest,
1611 name: "HttpPUT",
1612 sendPrefix: "PUT / HTTP/1.0\n",
1613 shouldFail: true,
1614 expectedError: ":HTTP_REQUEST:",
1615 },
1616 {
1617 testType: serverTest,
1618 name: "HttpCONNECT",
1619 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1620 shouldFail: true,
1621 expectedError: ":HTTPS_PROXY_REQUEST:",
1622 },
1623 {
1624 testType: serverTest,
1625 name: "Garbage",
1626 sendPrefix: "blah",
1627 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001628 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001629 },
1630 {
Adam Langley7c803a62015-06-15 15:35:05 -07001631 name: "RSAEphemeralKey",
1632 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001633 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001634 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1635 Bugs: ProtocolBugs{
1636 RSAEphemeralKey: true,
1637 },
1638 },
1639 shouldFail: true,
1640 expectedError: ":UNEXPECTED_MESSAGE:",
1641 },
1642 {
1643 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001644 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001645 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001646 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001647 },
1648 {
1649 protocol: dtls,
1650 name: "DisableEverything-DTLS",
1651 flags: []string{"-no-tls12", "-no-tls1"},
1652 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001653 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001654 },
1655 {
Adam Langley7c803a62015-06-15 15:35:05 -07001656 protocol: dtls,
1657 testType: serverTest,
1658 name: "MTU",
1659 config: Config{
1660 Bugs: ProtocolBugs{
1661 MaxPacketLength: 256,
1662 },
1663 },
1664 flags: []string{"-mtu", "256"},
1665 },
1666 {
1667 protocol: dtls,
1668 testType: serverTest,
1669 name: "MTUExceeded",
1670 config: Config{
1671 Bugs: ProtocolBugs{
1672 MaxPacketLength: 255,
1673 },
1674 },
1675 flags: []string{"-mtu", "256"},
1676 shouldFail: true,
1677 expectedLocalError: "dtls: exceeded maximum packet length",
1678 },
1679 {
Adam Langley7c803a62015-06-15 15:35:05 -07001680 name: "EmptyCertificateList",
1681 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001682 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001683 Bugs: ProtocolBugs{
1684 EmptyCertificateList: true,
1685 },
1686 },
1687 shouldFail: true,
1688 expectedError: ":DECODE_ERROR:",
1689 },
1690 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001691 name: "EmptyCertificateList-TLS13",
1692 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001693 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001694 Bugs: ProtocolBugs{
1695 EmptyCertificateList: true,
1696 },
1697 },
1698 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001699 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001700 },
1701 {
Adam Langley7c803a62015-06-15 15:35:05 -07001702 name: "TLSFatalBadPackets",
1703 damageFirstWrite: true,
1704 shouldFail: true,
1705 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1706 },
1707 {
1708 protocol: dtls,
1709 name: "DTLSIgnoreBadPackets",
1710 damageFirstWrite: true,
1711 },
1712 {
1713 protocol: dtls,
1714 name: "DTLSIgnoreBadPackets-Async",
1715 damageFirstWrite: true,
1716 flags: []string{"-async"},
1717 },
1718 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001719 name: "AppDataBeforeHandshake",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1723 },
1724 },
1725 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001726 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001727 },
1728 {
1729 name: "AppDataBeforeHandshake-Empty",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 AppDataBeforeHandshake: []byte{},
1733 },
1734 },
1735 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001736 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001737 },
1738 {
1739 protocol: dtls,
1740 name: "AppDataBeforeHandshake-DTLS",
1741 config: Config{
1742 Bugs: ProtocolBugs{
1743 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1744 },
1745 },
1746 shouldFail: true,
1747 expectedError: ":UNEXPECTED_RECORD:",
1748 },
1749 {
1750 protocol: dtls,
1751 name: "AppDataBeforeHandshake-DTLS-Empty",
1752 config: Config{
1753 Bugs: ProtocolBugs{
1754 AppDataBeforeHandshake: []byte{},
1755 },
1756 },
1757 shouldFail: true,
1758 expectedError: ":UNEXPECTED_RECORD:",
1759 },
1760 {
Adam Langley7c803a62015-06-15 15:35:05 -07001761 name: "AppDataAfterChangeCipherSpec",
1762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001763 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001764 Bugs: ProtocolBugs{
1765 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1766 },
1767 },
1768 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001769 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001770 },
1771 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001772 name: "AppDataAfterChangeCipherSpec-Empty",
1773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001774 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001775 Bugs: ProtocolBugs{
1776 AppDataAfterChangeCipherSpec: []byte{},
1777 },
1778 },
1779 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001780 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001781 },
1782 {
Adam Langley7c803a62015-06-15 15:35:05 -07001783 protocol: dtls,
1784 name: "AppDataAfterChangeCipherSpec-DTLS",
1785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001786 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001787 Bugs: ProtocolBugs{
1788 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1789 },
1790 },
1791 // BoringSSL's DTLS implementation will drop the out-of-order
1792 // application data.
1793 },
1794 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001795 protocol: dtls,
1796 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001798 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001799 Bugs: ProtocolBugs{
1800 AppDataAfterChangeCipherSpec: []byte{},
1801 },
1802 },
1803 // BoringSSL's DTLS implementation will drop the out-of-order
1804 // application data.
1805 },
1806 {
Adam Langley7c803a62015-06-15 15:35:05 -07001807 name: "AlertAfterChangeCipherSpec",
1808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001809 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001810 Bugs: ProtocolBugs{
1811 AlertAfterChangeCipherSpec: alertRecordOverflow,
1812 },
1813 },
1814 shouldFail: true,
1815 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1816 },
1817 {
1818 protocol: dtls,
1819 name: "AlertAfterChangeCipherSpec-DTLS",
1820 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001821 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001822 Bugs: ProtocolBugs{
1823 AlertAfterChangeCipherSpec: alertRecordOverflow,
1824 },
1825 },
1826 shouldFail: true,
1827 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1828 },
1829 {
1830 protocol: dtls,
1831 name: "ReorderHandshakeFragments-Small-DTLS",
1832 config: Config{
1833 Bugs: ProtocolBugs{
1834 ReorderHandshakeFragments: true,
1835 // Small enough that every handshake message is
1836 // fragmented.
1837 MaxHandshakeRecordLength: 2,
1838 },
1839 },
1840 },
1841 {
1842 protocol: dtls,
1843 name: "ReorderHandshakeFragments-Large-DTLS",
1844 config: Config{
1845 Bugs: ProtocolBugs{
1846 ReorderHandshakeFragments: true,
1847 // Large enough that no handshake message is
1848 // fragmented.
1849 MaxHandshakeRecordLength: 2048,
1850 },
1851 },
1852 },
1853 {
1854 protocol: dtls,
1855 name: "MixCompleteMessageWithFragments-DTLS",
1856 config: Config{
1857 Bugs: ProtocolBugs{
1858 ReorderHandshakeFragments: true,
1859 MixCompleteMessageWithFragments: true,
1860 MaxHandshakeRecordLength: 2,
1861 },
1862 },
1863 },
1864 {
1865 name: "SendInvalidRecordType",
1866 config: Config{
1867 Bugs: ProtocolBugs{
1868 SendInvalidRecordType: true,
1869 },
1870 },
1871 shouldFail: true,
1872 expectedError: ":UNEXPECTED_RECORD:",
1873 },
1874 {
1875 protocol: dtls,
1876 name: "SendInvalidRecordType-DTLS",
1877 config: Config{
1878 Bugs: ProtocolBugs{
1879 SendInvalidRecordType: true,
1880 },
1881 },
1882 shouldFail: true,
1883 expectedError: ":UNEXPECTED_RECORD:",
1884 },
1885 {
1886 name: "FalseStart-SkipServerSecondLeg",
1887 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001888 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001889 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1890 NextProtos: []string{"foo"},
1891 Bugs: ProtocolBugs{
1892 SkipNewSessionTicket: true,
1893 SkipChangeCipherSpec: true,
1894 SkipFinished: true,
1895 ExpectFalseStart: true,
1896 },
1897 },
1898 flags: []string{
1899 "-false-start",
1900 "-handshake-never-done",
1901 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001902 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001906 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001907 },
1908 {
1909 name: "FalseStart-SkipServerSecondLeg-Implicit",
1910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001911 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1913 NextProtos: []string{"foo"},
1914 Bugs: ProtocolBugs{
1915 SkipNewSessionTicket: true,
1916 SkipChangeCipherSpec: true,
1917 SkipFinished: true,
1918 },
1919 },
1920 flags: []string{
1921 "-implicit-handshake",
1922 "-false-start",
1923 "-handshake-never-done",
1924 "-advertise-alpn", "\x03foo",
1925 },
1926 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001927 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001928 },
1929 {
1930 testType: serverTest,
1931 name: "FailEarlyCallback",
1932 flags: []string{"-fail-early-callback"},
1933 shouldFail: true,
1934 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001935 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001936 },
1937 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001938 name: "FailCertCallback-Client-TLS12",
1939 config: Config{
1940 MaxVersion: VersionTLS12,
1941 ClientAuth: RequestClientCert,
1942 },
1943 flags: []string{"-fail-cert-callback"},
1944 shouldFail: true,
1945 expectedError: ":CERT_CB_ERROR:",
1946 expectedLocalError: "remote error: internal error",
1947 },
1948 {
1949 testType: serverTest,
1950 name: "FailCertCallback-Server-TLS12",
1951 config: Config{
1952 MaxVersion: VersionTLS12,
1953 },
1954 flags: []string{"-fail-cert-callback"},
1955 shouldFail: true,
1956 expectedError: ":CERT_CB_ERROR:",
1957 expectedLocalError: "remote error: internal error",
1958 },
1959 {
1960 name: "FailCertCallback-Client-TLS13",
1961 config: Config{
1962 MaxVersion: VersionTLS13,
1963 ClientAuth: RequestClientCert,
1964 },
1965 flags: []string{"-fail-cert-callback"},
1966 shouldFail: true,
1967 expectedError: ":CERT_CB_ERROR:",
1968 expectedLocalError: "remote error: internal error",
1969 },
1970 {
1971 testType: serverTest,
1972 name: "FailCertCallback-Server-TLS13",
1973 config: Config{
1974 MaxVersion: VersionTLS13,
1975 },
1976 flags: []string{"-fail-cert-callback"},
1977 shouldFail: true,
1978 expectedError: ":CERT_CB_ERROR:",
1979 expectedLocalError: "remote error: internal error",
1980 },
1981 {
Adam Langley7c803a62015-06-15 15:35:05 -07001982 protocol: dtls,
1983 name: "FragmentMessageTypeMismatch-DTLS",
1984 config: Config{
1985 Bugs: ProtocolBugs{
1986 MaxHandshakeRecordLength: 2,
1987 FragmentMessageTypeMismatch: true,
1988 },
1989 },
1990 shouldFail: true,
1991 expectedError: ":FRAGMENT_MISMATCH:",
1992 },
1993 {
1994 protocol: dtls,
1995 name: "FragmentMessageLengthMismatch-DTLS",
1996 config: Config{
1997 Bugs: ProtocolBugs{
1998 MaxHandshakeRecordLength: 2,
1999 FragmentMessageLengthMismatch: true,
2000 },
2001 },
2002 shouldFail: true,
2003 expectedError: ":FRAGMENT_MISMATCH:",
2004 },
2005 {
2006 protocol: dtls,
2007 name: "SplitFragments-Header-DTLS",
2008 config: Config{
2009 Bugs: ProtocolBugs{
2010 SplitFragments: 2,
2011 },
2012 },
2013 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002014 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002015 },
2016 {
2017 protocol: dtls,
2018 name: "SplitFragments-Boundary-DTLS",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 SplitFragments: dtlsRecordHeaderLen,
2022 },
2023 },
2024 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002025 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002026 },
2027 {
2028 protocol: dtls,
2029 name: "SplitFragments-Body-DTLS",
2030 config: Config{
2031 Bugs: ProtocolBugs{
2032 SplitFragments: dtlsRecordHeaderLen + 1,
2033 },
2034 },
2035 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002036 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002037 },
2038 {
2039 protocol: dtls,
2040 name: "SendEmptyFragments-DTLS",
2041 config: Config{
2042 Bugs: ProtocolBugs{
2043 SendEmptyFragments: true,
2044 },
2045 },
2046 },
2047 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002048 name: "BadFinished-Client",
2049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002050 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002051 Bugs: ProtocolBugs{
2052 BadFinished: true,
2053 },
2054 },
2055 shouldFail: true,
2056 expectedError: ":DIGEST_CHECK_FAILED:",
2057 },
2058 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002059 name: "BadFinished-Client-TLS13",
2060 config: Config{
2061 MaxVersion: VersionTLS13,
2062 Bugs: ProtocolBugs{
2063 BadFinished: true,
2064 },
2065 },
2066 shouldFail: true,
2067 expectedError: ":DIGEST_CHECK_FAILED:",
2068 },
2069 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002070 testType: serverTest,
2071 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002073 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002074 Bugs: ProtocolBugs{
2075 BadFinished: true,
2076 },
2077 },
2078 shouldFail: true,
2079 expectedError: ":DIGEST_CHECK_FAILED:",
2080 },
2081 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002082 testType: serverTest,
2083 name: "BadFinished-Server-TLS13",
2084 config: Config{
2085 MaxVersion: VersionTLS13,
2086 Bugs: ProtocolBugs{
2087 BadFinished: true,
2088 },
2089 },
2090 shouldFail: true,
2091 expectedError: ":DIGEST_CHECK_FAILED:",
2092 },
2093 {
Adam Langley7c803a62015-06-15 15:35:05 -07002094 name: "FalseStart-BadFinished",
2095 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002096 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002097 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2098 NextProtos: []string{"foo"},
2099 Bugs: ProtocolBugs{
2100 BadFinished: true,
2101 ExpectFalseStart: true,
2102 },
2103 },
2104 flags: []string{
2105 "-false-start",
2106 "-handshake-never-done",
2107 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002108 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002109 },
2110 shimWritesFirst: true,
2111 shouldFail: true,
2112 expectedError: ":DIGEST_CHECK_FAILED:",
2113 },
2114 {
2115 name: "NoFalseStart-NoALPN",
2116 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002117 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002118 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2119 Bugs: ProtocolBugs{
2120 ExpectFalseStart: true,
2121 AlertBeforeFalseStartTest: alertAccessDenied,
2122 },
2123 },
2124 flags: []string{
2125 "-false-start",
2126 },
2127 shimWritesFirst: true,
2128 shouldFail: true,
2129 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2130 expectedLocalError: "tls: peer did not false start: EOF",
2131 },
2132 {
2133 name: "NoFalseStart-NoAEAD",
2134 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002135 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002136 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2137 NextProtos: []string{"foo"},
2138 Bugs: ProtocolBugs{
2139 ExpectFalseStart: true,
2140 AlertBeforeFalseStartTest: alertAccessDenied,
2141 },
2142 },
2143 flags: []string{
2144 "-false-start",
2145 "-advertise-alpn", "\x03foo",
2146 },
2147 shimWritesFirst: true,
2148 shouldFail: true,
2149 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2150 expectedLocalError: "tls: peer did not false start: EOF",
2151 },
2152 {
2153 name: "NoFalseStart-RSA",
2154 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002155 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002156 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2157 NextProtos: []string{"foo"},
2158 Bugs: ProtocolBugs{
2159 ExpectFalseStart: true,
2160 AlertBeforeFalseStartTest: alertAccessDenied,
2161 },
2162 },
2163 flags: []string{
2164 "-false-start",
2165 "-advertise-alpn", "\x03foo",
2166 },
2167 shimWritesFirst: true,
2168 shouldFail: true,
2169 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2170 expectedLocalError: "tls: peer did not false start: EOF",
2171 },
2172 {
Adam Langley7c803a62015-06-15 15:35:05 -07002173 protocol: dtls,
2174 name: "SendSplitAlert-Sync",
2175 config: Config{
2176 Bugs: ProtocolBugs{
2177 SendSplitAlert: true,
2178 },
2179 },
2180 },
2181 {
2182 protocol: dtls,
2183 name: "SendSplitAlert-Async",
2184 config: Config{
2185 Bugs: ProtocolBugs{
2186 SendSplitAlert: true,
2187 },
2188 },
2189 flags: []string{"-async"},
2190 },
2191 {
2192 protocol: dtls,
2193 name: "PackDTLSHandshake",
2194 config: Config{
2195 Bugs: ProtocolBugs{
2196 MaxHandshakeRecordLength: 2,
2197 PackHandshakeFragments: 20,
2198 PackHandshakeRecords: 200,
2199 },
2200 },
2201 },
2202 {
Adam Langley7c803a62015-06-15 15:35:05 -07002203 name: "SendEmptyRecords-Pass",
2204 sendEmptyRecords: 32,
2205 },
2206 {
2207 name: "SendEmptyRecords",
2208 sendEmptyRecords: 33,
2209 shouldFail: true,
2210 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2211 },
2212 {
2213 name: "SendEmptyRecords-Async",
2214 sendEmptyRecords: 33,
2215 flags: []string{"-async"},
2216 shouldFail: true,
2217 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2218 },
2219 {
David Benjamine8e84b92016-08-03 15:39:47 -04002220 name: "SendWarningAlerts-Pass",
2221 config: Config{
2222 MaxVersion: VersionTLS12,
2223 },
Adam Langley7c803a62015-06-15 15:35:05 -07002224 sendWarningAlerts: 4,
2225 },
2226 {
David Benjamine8e84b92016-08-03 15:39:47 -04002227 protocol: dtls,
2228 name: "SendWarningAlerts-DTLS-Pass",
2229 config: Config{
2230 MaxVersion: VersionTLS12,
2231 },
Adam Langley7c803a62015-06-15 15:35:05 -07002232 sendWarningAlerts: 4,
2233 },
2234 {
David Benjamine8e84b92016-08-03 15:39:47 -04002235 name: "SendWarningAlerts-TLS13",
2236 config: Config{
2237 MaxVersion: VersionTLS13,
2238 },
2239 sendWarningAlerts: 4,
2240 shouldFail: true,
2241 expectedError: ":BAD_ALERT:",
2242 expectedLocalError: "remote error: error decoding message",
2243 },
2244 {
2245 name: "SendWarningAlerts",
2246 config: Config{
2247 MaxVersion: VersionTLS12,
2248 },
Adam Langley7c803a62015-06-15 15:35:05 -07002249 sendWarningAlerts: 5,
2250 shouldFail: true,
2251 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2252 },
2253 {
David Benjamine8e84b92016-08-03 15:39:47 -04002254 name: "SendWarningAlerts-Async",
2255 config: Config{
2256 MaxVersion: VersionTLS12,
2257 },
Adam Langley7c803a62015-06-15 15:35:05 -07002258 sendWarningAlerts: 5,
2259 flags: []string{"-async"},
2260 shouldFail: true,
2261 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2262 },
David Benjaminba4594a2015-06-18 18:36:15 -04002263 {
David Benjamin24e58862017-06-14 18:45:29 -04002264 name: "SendBogusAlertType",
2265 sendBogusAlertType: true,
2266 shouldFail: true,
2267 expectedError: ":UNKNOWN_ALERT_TYPE:",
2268 expectedLocalError: "remote error: illegal parameter",
2269 },
2270 {
2271 protocol: dtls,
2272 name: "SendBogusAlertType-DTLS",
2273 sendBogusAlertType: true,
2274 shouldFail: true,
2275 expectedError: ":UNKNOWN_ALERT_TYPE:",
2276 expectedLocalError: "remote error: illegal parameter",
2277 },
2278 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002279 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002280 config: Config{
2281 MaxVersion: VersionTLS13,
2282 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002283 sendKeyUpdates: 33,
2284 keyUpdateRequest: keyUpdateNotRequested,
2285 shouldFail: true,
2286 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002287 },
2288 {
David Benjaminba4594a2015-06-18 18:36:15 -04002289 name: "EmptySessionID",
2290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002291 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002292 SessionTicketsDisabled: true,
2293 },
2294 noSessionCache: true,
2295 flags: []string{"-expect-no-session"},
2296 },
David Benjamin30789da2015-08-29 22:56:45 -04002297 {
2298 name: "Unclean-Shutdown",
2299 config: Config{
2300 Bugs: ProtocolBugs{
2301 NoCloseNotify: true,
2302 ExpectCloseNotify: true,
2303 },
2304 },
2305 shimShutsDown: true,
2306 flags: []string{"-check-close-notify"},
2307 shouldFail: true,
2308 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2309 },
2310 {
2311 name: "Unclean-Shutdown-Ignored",
2312 config: Config{
2313 Bugs: ProtocolBugs{
2314 NoCloseNotify: true,
2315 },
2316 },
2317 shimShutsDown: true,
2318 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002319 {
David Benjaminfa214e42016-05-10 17:03:10 -04002320 name: "Unclean-Shutdown-Alert",
2321 config: Config{
2322 Bugs: ProtocolBugs{
2323 SendAlertOnShutdown: alertDecompressionFailure,
2324 ExpectCloseNotify: true,
2325 },
2326 },
2327 shimShutsDown: true,
2328 flags: []string{"-check-close-notify"},
2329 shouldFail: true,
2330 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2331 },
2332 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002333 name: "LargePlaintext",
2334 config: Config{
2335 Bugs: ProtocolBugs{
2336 SendLargeRecords: true,
2337 },
2338 },
2339 messageLen: maxPlaintext + 1,
2340 shouldFail: true,
2341 expectedError: ":DATA_LENGTH_TOO_LONG:",
2342 },
2343 {
2344 protocol: dtls,
2345 name: "LargePlaintext-DTLS",
2346 config: Config{
2347 Bugs: ProtocolBugs{
2348 SendLargeRecords: true,
2349 },
2350 },
2351 messageLen: maxPlaintext + 1,
2352 shouldFail: true,
2353 expectedError: ":DATA_LENGTH_TOO_LONG:",
2354 },
2355 {
2356 name: "LargeCiphertext",
2357 config: Config{
2358 Bugs: ProtocolBugs{
2359 SendLargeRecords: true,
2360 },
2361 },
2362 messageLen: maxPlaintext * 2,
2363 shouldFail: true,
2364 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2365 },
2366 {
2367 protocol: dtls,
2368 name: "LargeCiphertext-DTLS",
2369 config: Config{
2370 Bugs: ProtocolBugs{
2371 SendLargeRecords: true,
2372 },
2373 },
2374 messageLen: maxPlaintext * 2,
2375 // Unlike the other four cases, DTLS drops records which
2376 // are invalid before authentication, so the connection
2377 // does not fail.
2378 expectMessageDropped: true,
2379 },
David Benjamindd6fed92015-10-23 17:41:12 -04002380 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002381 name: "BadHelloRequest-1",
2382 renegotiate: 1,
2383 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002384 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002385 Bugs: ProtocolBugs{
2386 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2387 },
2388 },
2389 flags: []string{
2390 "-renegotiate-freely",
2391 "-expect-total-renegotiations", "1",
2392 },
2393 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002394 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002395 },
2396 {
2397 name: "BadHelloRequest-2",
2398 renegotiate: 1,
2399 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002400 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002401 Bugs: ProtocolBugs{
2402 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2403 },
2404 },
2405 flags: []string{
2406 "-renegotiate-freely",
2407 "-expect-total-renegotiations", "1",
2408 },
2409 shouldFail: true,
2410 expectedError: ":BAD_HELLO_REQUEST:",
2411 },
David Benjaminef1b0092015-11-21 14:05:44 -05002412 {
2413 testType: serverTest,
2414 name: "SupportTicketsWithSessionID",
2415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002416 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002417 SessionTicketsDisabled: true,
2418 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002419 resumeConfig: &Config{
2420 MaxVersion: VersionTLS12,
2421 },
David Benjaminef1b0092015-11-21 14:05:44 -05002422 resumeSession: true,
2423 },
David Benjamin02edcd02016-07-27 17:40:37 -04002424 {
2425 protocol: dtls,
2426 name: "DTLS-SendExtraFinished",
2427 config: Config{
2428 Bugs: ProtocolBugs{
2429 SendExtraFinished: true,
2430 },
2431 },
2432 shouldFail: true,
2433 expectedError: ":UNEXPECTED_RECORD:",
2434 },
2435 {
2436 protocol: dtls,
2437 name: "DTLS-SendExtraFinished-Reordered",
2438 config: Config{
2439 Bugs: ProtocolBugs{
2440 MaxHandshakeRecordLength: 2,
2441 ReorderHandshakeFragments: true,
2442 SendExtraFinished: true,
2443 },
2444 },
2445 shouldFail: true,
2446 expectedError: ":UNEXPECTED_RECORD:",
2447 },
David Benjamine97fb482016-07-29 09:23:07 -04002448 {
2449 testType: serverTest,
2450 name: "V2ClientHello-EmptyRecordPrefix",
2451 config: Config{
2452 // Choose a cipher suite that does not involve
2453 // elliptic curves, so no extensions are
2454 // involved.
2455 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002456 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002457 Bugs: ProtocolBugs{
2458 SendV2ClientHello: true,
2459 },
2460 },
2461 sendPrefix: string([]byte{
2462 byte(recordTypeHandshake),
2463 3, 1, // version
2464 0, 0, // length
2465 }),
2466 // A no-op empty record may not be sent before V2ClientHello.
2467 shouldFail: true,
2468 expectedError: ":WRONG_VERSION_NUMBER:",
2469 },
2470 {
2471 testType: serverTest,
2472 name: "V2ClientHello-WarningAlertPrefix",
2473 config: Config{
2474 // Choose a cipher suite that does not involve
2475 // elliptic curves, so no extensions are
2476 // involved.
2477 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002478 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002479 Bugs: ProtocolBugs{
2480 SendV2ClientHello: true,
2481 },
2482 },
2483 sendPrefix: string([]byte{
2484 byte(recordTypeAlert),
2485 3, 1, // version
2486 0, 2, // length
2487 alertLevelWarning, byte(alertDecompressionFailure),
2488 }),
2489 // A no-op warning alert may not be sent before V2ClientHello.
2490 shouldFail: true,
2491 expectedError: ":WRONG_VERSION_NUMBER:",
2492 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002493 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002494 name: "KeyUpdate-Client",
2495 config: Config{
2496 MaxVersion: VersionTLS13,
2497 },
2498 sendKeyUpdates: 1,
2499 keyUpdateRequest: keyUpdateNotRequested,
2500 },
2501 {
2502 testType: serverTest,
2503 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002504 config: Config{
2505 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002506 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002507 sendKeyUpdates: 1,
2508 keyUpdateRequest: keyUpdateNotRequested,
2509 },
2510 {
2511 name: "KeyUpdate-InvalidRequestMode",
2512 config: Config{
2513 MaxVersion: VersionTLS13,
2514 },
2515 sendKeyUpdates: 1,
2516 keyUpdateRequest: 42,
2517 shouldFail: true,
2518 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002519 },
David Benjaminabe94e32016-09-04 14:18:58 -04002520 {
David Benjaminbbba9392017-04-06 12:54:12 -04002521 // Test that KeyUpdates are acknowledged properly.
2522 name: "KeyUpdate-RequestACK",
2523 config: Config{
2524 MaxVersion: VersionTLS13,
2525 Bugs: ProtocolBugs{
2526 RejectUnsolicitedKeyUpdate: true,
2527 },
2528 },
2529 // Test the shim receiving many KeyUpdates in a row.
2530 sendKeyUpdates: 5,
2531 messageCount: 5,
2532 keyUpdateRequest: keyUpdateRequested,
2533 },
2534 {
2535 // Test that KeyUpdates are acknowledged properly if the
2536 // peer's KeyUpdate is discovered while a write is
2537 // pending.
2538 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2539 config: Config{
2540 MaxVersion: VersionTLS13,
2541 Bugs: ProtocolBugs{
2542 RejectUnsolicitedKeyUpdate: true,
2543 },
2544 },
2545 // Test the shim receiving many KeyUpdates in a row.
2546 sendKeyUpdates: 5,
2547 messageCount: 5,
2548 keyUpdateRequest: keyUpdateRequested,
2549 readWithUnfinishedWrite: true,
2550 flags: []string{"-async"},
2551 },
2552 {
David Benjaminabe94e32016-09-04 14:18:58 -04002553 name: "SendSNIWarningAlert",
2554 config: Config{
2555 MaxVersion: VersionTLS12,
2556 Bugs: ProtocolBugs{
2557 SendSNIWarningAlert: true,
2558 },
2559 },
2560 },
David Benjaminc241d792016-09-09 10:34:20 -04002561 {
2562 testType: serverTest,
2563 name: "ExtraCompressionMethods-TLS12",
2564 config: Config{
2565 MaxVersion: VersionTLS12,
2566 Bugs: ProtocolBugs{
2567 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2568 },
2569 },
2570 },
2571 {
2572 testType: serverTest,
2573 name: "ExtraCompressionMethods-TLS13",
2574 config: Config{
2575 MaxVersion: VersionTLS13,
2576 Bugs: ProtocolBugs{
2577 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2578 },
2579 },
2580 shouldFail: true,
2581 expectedError: ":INVALID_COMPRESSION_LIST:",
2582 expectedLocalError: "remote error: illegal parameter",
2583 },
2584 {
2585 testType: serverTest,
2586 name: "NoNullCompression-TLS12",
2587 config: Config{
2588 MaxVersion: VersionTLS12,
2589 Bugs: ProtocolBugs{
2590 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2591 },
2592 },
2593 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002594 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002595 expectedLocalError: "remote error: illegal parameter",
2596 },
2597 {
2598 testType: serverTest,
2599 name: "NoNullCompression-TLS13",
2600 config: Config{
2601 MaxVersion: VersionTLS13,
2602 Bugs: ProtocolBugs{
2603 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2604 },
2605 },
2606 shouldFail: true,
2607 expectedError: ":INVALID_COMPRESSION_LIST:",
2608 expectedLocalError: "remote error: illegal parameter",
2609 },
David Benjamin413e79e2017-07-01 10:11:53 -04002610 // Test that the client rejects invalid compression methods
2611 // from the server.
2612 {
2613 testType: clientTest,
2614 name: "InvalidCompressionMethod",
2615 config: Config{
2616 MaxVersion: VersionTLS12,
2617 Bugs: ProtocolBugs{
2618 SendCompressionMethod: 1,
2619 },
2620 },
2621 shouldFail: true,
2622 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2623 expectedLocalError: "remote error: illegal parameter",
2624 },
David Benjamin65ac9972016-09-02 21:35:25 -04002625 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002626 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002627 config: Config{
2628 MaxVersion: VersionTLS12,
2629 Bugs: ProtocolBugs{
2630 ExpectGREASE: true,
2631 },
2632 },
2633 flags: []string{"-enable-grease"},
2634 },
2635 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002636 name: "GREASE-Client-TLS13",
2637 config: Config{
2638 MaxVersion: VersionTLS13,
2639 Bugs: ProtocolBugs{
2640 ExpectGREASE: true,
2641 },
2642 },
2643 flags: []string{"-enable-grease"},
2644 },
2645 {
2646 testType: serverTest,
2647 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002648 config: Config{
2649 MaxVersion: VersionTLS13,
2650 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002651 // TLS 1.3 servers are expected to
2652 // always enable GREASE. TLS 1.3 is new,
2653 // so there is no existing ecosystem to
2654 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002655 ExpectGREASE: true,
2656 },
2657 },
David Benjamin65ac9972016-09-02 21:35:25 -04002658 },
David Benjamine3fbb362017-01-06 16:19:28 -05002659 {
2660 // Test the server so there is a large certificate as
2661 // well as application data.
2662 testType: serverTest,
2663 name: "MaxSendFragment",
2664 config: Config{
2665 Bugs: ProtocolBugs{
2666 MaxReceivePlaintext: 512,
2667 },
2668 },
2669 messageLen: 1024,
2670 flags: []string{
2671 "-max-send-fragment", "512",
2672 "-read-size", "1024",
2673 },
2674 },
2675 {
2676 // Test the server so there is a large certificate as
2677 // well as application data.
2678 testType: serverTest,
2679 name: "MaxSendFragment-TooLarge",
2680 config: Config{
2681 Bugs: ProtocolBugs{
2682 // Ensure that some of the records are
2683 // 512.
2684 MaxReceivePlaintext: 511,
2685 },
2686 },
2687 messageLen: 1024,
2688 flags: []string{
2689 "-max-send-fragment", "512",
2690 "-read-size", "1024",
2691 },
2692 shouldFail: true,
2693 expectedLocalError: "local error: record overflow",
2694 },
Adam Langley7c803a62015-06-15 15:35:05 -07002695 }
Adam Langley7c803a62015-06-15 15:35:05 -07002696 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002697
2698 // Test that very large messages can be received.
2699 cert := rsaCertificate
2700 for i := 0; i < 50; i++ {
2701 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2702 }
2703 testCases = append(testCases, testCase{
2704 name: "LargeMessage",
2705 config: Config{
2706 Certificates: []Certificate{cert},
2707 },
2708 })
2709 testCases = append(testCases, testCase{
2710 protocol: dtls,
2711 name: "LargeMessage-DTLS",
2712 config: Config{
2713 Certificates: []Certificate{cert},
2714 },
2715 })
2716
2717 // They are rejected if the maximum certificate chain length is capped.
2718 testCases = append(testCases, testCase{
2719 name: "LargeMessage-Reject",
2720 config: Config{
2721 Certificates: []Certificate{cert},
2722 },
2723 flags: []string{"-max-cert-list", "16384"},
2724 shouldFail: true,
2725 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2726 })
2727 testCases = append(testCases, testCase{
2728 protocol: dtls,
2729 name: "LargeMessage-Reject-DTLS",
2730 config: Config{
2731 Certificates: []Certificate{cert},
2732 },
2733 flags: []string{"-max-cert-list", "16384"},
2734 shouldFail: true,
2735 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2736 })
Adam Langley7c803a62015-06-15 15:35:05 -07002737}
2738
David Benjaminaa012042016-12-10 13:33:05 -05002739func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2740 const psk = "12345"
2741 const pskIdentity = "luggage combo"
2742
2743 var prefix string
2744 if protocol == dtls {
2745 if !ver.hasDTLS {
2746 return
2747 }
2748 prefix = "D"
2749 }
2750
2751 var cert Certificate
2752 var certFile string
2753 var keyFile string
2754 if hasComponent(suite.name, "ECDSA") {
2755 cert = ecdsaP256Certificate
2756 certFile = ecdsaP256CertificateFile
2757 keyFile = ecdsaP256KeyFile
2758 } else {
2759 cert = rsaCertificate
2760 certFile = rsaCertificateFile
2761 keyFile = rsaKeyFile
2762 }
2763
2764 var flags []string
2765 if hasComponent(suite.name, "PSK") {
2766 flags = append(flags,
2767 "-psk", psk,
2768 "-psk-identity", pskIdentity)
2769 }
2770 if hasComponent(suite.name, "NULL") {
2771 // NULL ciphers must be explicitly enabled.
2772 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2773 }
David Benjaminaa012042016-12-10 13:33:05 -05002774
2775 var shouldServerFail, shouldClientFail bool
2776 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2777 // BoringSSL clients accept ECDHE on SSLv3, but
2778 // a BoringSSL server will never select it
2779 // because the extension is missing.
2780 shouldServerFail = true
2781 }
2782 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2783 shouldClientFail = true
2784 shouldServerFail = true
2785 }
2786 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2787 shouldClientFail = true
2788 shouldServerFail = true
2789 }
2790 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2791 shouldClientFail = true
2792 shouldServerFail = true
2793 }
2794 if !isDTLSCipher(suite.name) && protocol == dtls {
2795 shouldClientFail = true
2796 shouldServerFail = true
2797 }
2798
2799 var sendCipherSuite uint16
2800 var expectedServerError, expectedClientError string
2801 serverCipherSuites := []uint16{suite.id}
2802 if shouldServerFail {
2803 expectedServerError = ":NO_SHARED_CIPHER:"
2804 }
2805 if shouldClientFail {
2806 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2807 // Configure the server to select ciphers as normal but
2808 // select an incompatible cipher in ServerHello.
2809 serverCipherSuites = nil
2810 sendCipherSuite = suite.id
2811 }
2812
David Benjamincdb6fe92017-02-07 16:06:48 -05002813 // For cipher suites and versions where exporters are defined, verify
2814 // that they interoperate.
2815 var exportKeyingMaterial int
2816 if ver.version > VersionSSL30 {
2817 exportKeyingMaterial = 1024
2818 }
2819
David Benjaminaa012042016-12-10 13:33:05 -05002820 testCases = append(testCases, testCase{
2821 testType: serverTest,
2822 protocol: protocol,
2823 name: prefix + ver.name + "-" + suite.name + "-server",
2824 config: Config{
2825 MinVersion: ver.version,
2826 MaxVersion: ver.version,
2827 CipherSuites: []uint16{suite.id},
2828 Certificates: []Certificate{cert},
2829 PreSharedKey: []byte(psk),
2830 PreSharedKeyIdentity: pskIdentity,
2831 Bugs: ProtocolBugs{
2832 AdvertiseAllConfiguredCiphers: true,
2833 },
2834 },
David Benjamina5022392017-07-10 17:40:39 -04002835 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002836 certFile: certFile,
2837 keyFile: keyFile,
2838 flags: flags,
2839 resumeSession: true,
2840 shouldFail: shouldServerFail,
2841 expectedError: expectedServerError,
2842 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002843 })
2844
2845 testCases = append(testCases, testCase{
2846 testType: clientTest,
2847 protocol: protocol,
2848 name: prefix + ver.name + "-" + suite.name + "-client",
2849 config: Config{
2850 MinVersion: ver.version,
2851 MaxVersion: ver.version,
2852 CipherSuites: serverCipherSuites,
2853 Certificates: []Certificate{cert},
2854 PreSharedKey: []byte(psk),
2855 PreSharedKeyIdentity: pskIdentity,
2856 Bugs: ProtocolBugs{
2857 IgnorePeerCipherPreferences: shouldClientFail,
2858 SendCipherSuite: sendCipherSuite,
2859 },
2860 },
David Benjamina5022392017-07-10 17:40:39 -04002861 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002862 flags: flags,
2863 resumeSession: true,
2864 shouldFail: shouldClientFail,
2865 expectedError: expectedClientError,
2866 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002867 })
2868
David Benjamin6f600d62016-12-21 16:06:54 -05002869 if shouldClientFail {
2870 return
2871 }
2872
2873 // Ensure the maximum record size is accepted.
2874 testCases = append(testCases, testCase{
2875 protocol: protocol,
2876 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2877 config: Config{
2878 MinVersion: ver.version,
2879 MaxVersion: ver.version,
2880 CipherSuites: []uint16{suite.id},
2881 Certificates: []Certificate{cert},
2882 PreSharedKey: []byte(psk),
2883 PreSharedKeyIdentity: pskIdentity,
2884 },
David Benjamina5022392017-07-10 17:40:39 -04002885 tls13Variant: ver.tls13Variant,
2886 flags: flags,
2887 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002888 })
2889
2890 // Test bad records for all ciphers. Bad records are fatal in TLS
2891 // and ignored in DTLS.
2892 var shouldFail bool
2893 var expectedError string
2894 if protocol == tls {
2895 shouldFail = true
2896 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2897 }
2898
2899 testCases = append(testCases, testCase{
2900 protocol: protocol,
2901 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2902 config: Config{
2903 MinVersion: ver.version,
2904 MaxVersion: ver.version,
2905 CipherSuites: []uint16{suite.id},
2906 Certificates: []Certificate{cert},
2907 PreSharedKey: []byte(psk),
2908 PreSharedKeyIdentity: pskIdentity,
2909 },
David Benjamina5022392017-07-10 17:40:39 -04002910 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002911 flags: flags,
2912 damageFirstWrite: true,
2913 messageLen: maxPlaintext,
2914 shouldFail: shouldFail,
2915 expectedError: expectedError,
2916 })
David Benjaminaa012042016-12-10 13:33:05 -05002917}
2918
Adam Langley95c29f32014-06-20 12:00:00 -07002919func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002920 const bogusCipher = 0xfe00
2921
Adam Langley95c29f32014-06-20 12:00:00 -07002922 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002923 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002924 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002925 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002926 }
David Benjamin2c99d282015-09-01 10:23:00 -04002927 }
Adam Langley95c29f32014-06-20 12:00:00 -07002928 }
Adam Langleya7997f12015-05-14 17:38:50 -07002929
2930 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002931 name: "NoSharedCipher",
2932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002933 MaxVersion: VersionTLS12,
2934 CipherSuites: []uint16{},
2935 },
2936 shouldFail: true,
2937 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2938 })
2939
2940 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002941 name: "NoSharedCipher-TLS13",
2942 config: Config{
2943 MaxVersion: VersionTLS13,
2944 CipherSuites: []uint16{},
2945 },
2946 shouldFail: true,
2947 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2948 })
2949
2950 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002951 name: "UnsupportedCipherSuite",
2952 config: Config{
2953 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002954 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002955 Bugs: ProtocolBugs{
2956 IgnorePeerCipherPreferences: true,
2957 },
2958 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002959 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002960 shouldFail: true,
2961 expectedError: ":WRONG_CIPHER_RETURNED:",
2962 })
2963
2964 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002965 name: "ServerHelloBogusCipher",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 Bugs: ProtocolBugs{
2969 SendCipherSuite: bogusCipher,
2970 },
2971 },
2972 shouldFail: true,
2973 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2974 })
2975 testCases = append(testCases, testCase{
2976 name: "ServerHelloBogusCipher-TLS13",
2977 config: Config{
2978 MaxVersion: VersionTLS13,
2979 Bugs: ProtocolBugs{
2980 SendCipherSuite: bogusCipher,
2981 },
2982 },
2983 shouldFail: true,
2984 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2985 })
2986
David Benjamin241ae832016-01-15 03:04:54 -05002987 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002988 testCases = append(testCases, testCase{
2989 testType: serverTest,
2990 name: "UnknownCipher",
2991 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002992 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002993 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002994 Bugs: ProtocolBugs{
2995 AdvertiseAllConfiguredCiphers: true,
2996 },
2997 },
2998 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002999
3000 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003001 testCases = append(testCases, testCase{
3002 testType: serverTest,
3003 name: "UnknownCipher-TLS13",
3004 config: Config{
3005 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003006 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003007 Bugs: ProtocolBugs{
3008 AdvertiseAllConfiguredCiphers: true,
3009 },
David Benjamin241ae832016-01-15 03:04:54 -05003010 },
3011 })
3012
David Benjamin78679342016-09-16 19:42:05 -04003013 // Test empty ECDHE_PSK identity hints work as expected.
3014 testCases = append(testCases, testCase{
3015 name: "EmptyECDHEPSKHint",
3016 config: Config{
3017 MaxVersion: VersionTLS12,
3018 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3019 PreSharedKey: []byte("secret"),
3020 },
3021 flags: []string{"-psk", "secret"},
3022 })
3023
3024 // Test empty PSK identity hints work as expected, even if an explicit
3025 // ServerKeyExchange is sent.
3026 testCases = append(testCases, testCase{
3027 name: "ExplicitEmptyPSKHint",
3028 config: Config{
3029 MaxVersion: VersionTLS12,
3030 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3031 PreSharedKey: []byte("secret"),
3032 Bugs: ProtocolBugs{
3033 AlwaysSendPreSharedKeyIdentityHint: true,
3034 },
3035 },
3036 flags: []string{"-psk", "secret"},
3037 })
David Benjamin69522112017-03-28 15:38:29 -05003038
3039 // Test that clients enforce that the server-sent certificate and cipher
3040 // suite match in TLS 1.2.
3041 testCases = append(testCases, testCase{
3042 name: "CertificateCipherMismatch-RSA",
3043 config: Config{
3044 MaxVersion: VersionTLS12,
3045 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3046 Certificates: []Certificate{rsaCertificate},
3047 Bugs: ProtocolBugs{
3048 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3049 },
3050 },
3051 shouldFail: true,
3052 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3053 })
3054 testCases = append(testCases, testCase{
3055 name: "CertificateCipherMismatch-ECDSA",
3056 config: Config{
3057 MaxVersion: VersionTLS12,
3058 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3059 Certificates: []Certificate{ecdsaP256Certificate},
3060 Bugs: ProtocolBugs{
3061 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3062 },
3063 },
3064 shouldFail: true,
3065 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3066 })
3067 testCases = append(testCases, testCase{
3068 name: "CertificateCipherMismatch-Ed25519",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3072 Certificates: []Certificate{ed25519Certificate},
3073 Bugs: ProtocolBugs{
3074 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3075 },
3076 },
3077 shouldFail: true,
3078 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3079 })
3080
3081 // Test that servers decline to select a cipher suite which is
3082 // inconsistent with their configured certificate.
3083 testCases = append(testCases, testCase{
3084 testType: serverTest,
3085 name: "ServerCipherFilter-RSA",
3086 config: Config{
3087 MaxVersion: VersionTLS12,
3088 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3089 },
3090 flags: []string{
3091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3093 },
3094 shouldFail: true,
3095 expectedError: ":NO_SHARED_CIPHER:",
3096 })
3097 testCases = append(testCases, testCase{
3098 testType: serverTest,
3099 name: "ServerCipherFilter-ECDSA",
3100 config: Config{
3101 MaxVersion: VersionTLS12,
3102 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3103 },
3104 flags: []string{
3105 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3106 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3107 },
3108 shouldFail: true,
3109 expectedError: ":NO_SHARED_CIPHER:",
3110 })
3111 testCases = append(testCases, testCase{
3112 testType: serverTest,
3113 name: "ServerCipherFilter-Ed25519",
3114 config: Config{
3115 MaxVersion: VersionTLS12,
3116 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3117 },
3118 flags: []string{
3119 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3120 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3121 },
3122 shouldFail: true,
3123 expectedError: ":NO_SHARED_CIPHER:",
3124 })
David Benjamin364af782017-07-01 10:35:27 -04003125
3126 // Test cipher suite negotiation works as expected. Configure a
3127 // complicated cipher suite configuration.
3128 const negotiationTestCiphers = "" +
3129 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3130 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3131 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3132 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3133 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3134 negotiationTests := []struct {
3135 ciphers []uint16
3136 expected uint16
3137 }{
3138 // Server preferences are honored, including when
3139 // equipreference groups are involved.
3140 {
3141 []uint16{
3142 TLS_RSA_WITH_AES_256_GCM_SHA384,
3143 TLS_RSA_WITH_AES_128_CBC_SHA,
3144 TLS_RSA_WITH_AES_128_GCM_SHA256,
3145 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3146 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3149 },
3150 {
3151 []uint16{
3152 TLS_RSA_WITH_AES_256_GCM_SHA384,
3153 TLS_RSA_WITH_AES_128_CBC_SHA,
3154 TLS_RSA_WITH_AES_128_GCM_SHA256,
3155 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3156 },
3157 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3158 },
3159 {
3160 []uint16{
3161 TLS_RSA_WITH_AES_256_GCM_SHA384,
3162 TLS_RSA_WITH_AES_128_CBC_SHA,
3163 TLS_RSA_WITH_AES_128_GCM_SHA256,
3164 },
3165 TLS_RSA_WITH_AES_128_GCM_SHA256,
3166 },
3167 {
3168 []uint16{
3169 TLS_RSA_WITH_AES_256_GCM_SHA384,
3170 TLS_RSA_WITH_AES_128_CBC_SHA,
3171 },
3172 TLS_RSA_WITH_AES_128_CBC_SHA,
3173 },
3174 // Equipreference groups use the client preference.
3175 {
3176 []uint16{
3177 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3178 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3179 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3180 },
3181 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3182 },
3183 {
3184 []uint16{
3185 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3186 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3187 },
3188 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3189 },
3190 {
3191 []uint16{
3192 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3193 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3194 },
3195 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3196 },
3197 {
3198 []uint16{
3199 TLS_RSA_WITH_AES_256_GCM_SHA384,
3200 TLS_RSA_WITH_AES_256_CBC_SHA,
3201 },
3202 TLS_RSA_WITH_AES_256_GCM_SHA384,
3203 },
3204 {
3205 []uint16{
3206 TLS_RSA_WITH_AES_256_CBC_SHA,
3207 TLS_RSA_WITH_AES_256_GCM_SHA384,
3208 },
3209 TLS_RSA_WITH_AES_256_CBC_SHA,
3210 },
3211 // If there are two equipreference groups, the preferred one
3212 // takes precedence.
3213 {
3214 []uint16{
3215 TLS_RSA_WITH_AES_256_GCM_SHA384,
3216 TLS_RSA_WITH_AES_256_CBC_SHA,
3217 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3218 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3219 },
3220 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3221 },
3222 }
3223 for i, t := range negotiationTests {
3224 testCases = append(testCases, testCase{
3225 testType: serverTest,
3226 name: "CipherNegotiation-" + strconv.Itoa(i),
3227 config: Config{
3228 MaxVersion: VersionTLS12,
3229 CipherSuites: t.ciphers,
3230 },
3231 flags: []string{"-cipher", negotiationTestCiphers},
3232 expectedCipher: t.expected,
3233 })
3234 }
Adam Langley95c29f32014-06-20 12:00:00 -07003235}
3236
3237func addBadECDSASignatureTests() {
3238 for badR := BadValue(1); badR < NumBadValues; badR++ {
3239 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003240 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003241 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3242 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003243 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003244 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003245 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003246 Bugs: ProtocolBugs{
3247 BadECDSAR: badR,
3248 BadECDSAS: badS,
3249 },
3250 },
3251 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003252 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003253 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003254 testCases = append(testCases, testCase{
3255 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3256 config: Config{
3257 MaxVersion: VersionTLS13,
3258 Certificates: []Certificate{ecdsaP256Certificate},
3259 Bugs: ProtocolBugs{
3260 BadECDSAR: badR,
3261 BadECDSAS: badS,
3262 },
3263 },
3264 shouldFail: true,
3265 expectedError: ":BAD_SIGNATURE:",
3266 })
Adam Langley95c29f32014-06-20 12:00:00 -07003267 }
3268 }
3269}
3270
Adam Langley80842bd2014-06-20 12:00:00 -07003271func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003272 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003273 name: "MaxCBCPadding",
3274 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003275 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003276 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3277 Bugs: ProtocolBugs{
3278 MaxPadding: true,
3279 },
3280 },
3281 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3282 })
David Benjamin025b3d32014-07-01 19:53:04 -04003283 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003284 name: "BadCBCPadding",
3285 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003286 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003287 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3288 Bugs: ProtocolBugs{
3289 PaddingFirstByteBad: true,
3290 },
3291 },
3292 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003293 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003294 })
3295 // OpenSSL previously had an issue where the first byte of padding in
3296 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003297 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003298 name: "BadCBCPadding255",
3299 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003300 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003301 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3302 Bugs: ProtocolBugs{
3303 MaxPadding: true,
3304 PaddingFirstByteBadIf255: true,
3305 },
3306 },
3307 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3308 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003309 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003310 })
3311}
3312
Kenny Root7fdeaf12014-08-05 15:23:37 -07003313func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003314 var cbcCiphers = []struct {
3315 name string
3316 cipher uint16
3317 }{
3318 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3319 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3320 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3321 }
3322 for _, t := range cbcCiphers {
3323 testCases = append(testCases, testCase{
3324 name: "CBCRecordSplitting-" + t.name,
3325 config: Config{
3326 MaxVersion: VersionTLS10,
3327 MinVersion: VersionTLS10,
3328 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003329 Bugs: ProtocolBugs{
3330 ExpectRecordSplitting: true,
3331 },
David Benjamina1ce8562017-07-01 11:46:57 -04003332 },
3333 messageLen: -1, // read until EOF
3334 resumeSession: true,
3335 flags: []string{
3336 "-async",
3337 "-write-different-record-sizes",
3338 "-cbc-record-splitting",
3339 },
3340 })
3341 testCases = append(testCases, testCase{
3342 name: "CBCRecordSplittingPartialWrite-" + t.name,
3343 config: Config{
3344 MaxVersion: VersionTLS10,
3345 MinVersion: VersionTLS10,
3346 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003347 Bugs: ProtocolBugs{
3348 ExpectRecordSplitting: true,
3349 },
David Benjamina1ce8562017-07-01 11:46:57 -04003350 },
3351 messageLen: -1, // read until EOF
3352 flags: []string{
3353 "-async",
3354 "-write-different-record-sizes",
3355 "-cbc-record-splitting",
3356 "-partial-write",
3357 },
3358 })
3359 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003360}
3361
David Benjamin636293b2014-07-08 17:59:18 -04003362func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003363 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003364 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003365 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3366 cert, err := x509.ParseCertificate(cert.Certificate[0])
3367 if err != nil {
3368 panic(err)
3369 }
3370 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003371 }
Adam Langley2ff79332017-02-28 13:45:39 -08003372 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003373
David Benjamin636293b2014-07-08 17:59:18 -04003374 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003375 testCases = append(testCases, testCase{
3376 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003377 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003378 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003379 MinVersion: ver.version,
3380 MaxVersion: ver.version,
3381 ClientAuth: RequireAnyClientCert,
3382 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003383 },
David Benjamina5022392017-07-10 17:40:39 -04003384 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003385 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003386 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3387 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003388 },
3389 })
3390 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003391 testType: serverTest,
3392 name: ver.name + "-Server-ClientAuth-RSA",
3393 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003394 MinVersion: ver.version,
3395 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003396 Certificates: []Certificate{rsaCertificate},
3397 },
David Benjamina5022392017-07-10 17:40:39 -04003398 tls13Variant: ver.tls13Variant,
3399 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003400 })
David Benjamine098ec22014-08-27 23:13:20 -04003401 if ver.version != VersionSSL30 {
3402 testCases = append(testCases, testCase{
3403 testType: serverTest,
3404 name: ver.name + "-Server-ClientAuth-ECDSA",
3405 config: Config{
3406 MinVersion: ver.version,
3407 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003408 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003409 },
David Benjamina5022392017-07-10 17:40:39 -04003410 tls13Variant: ver.tls13Variant,
3411 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003412 })
3413 testCases = append(testCases, testCase{
3414 testType: clientTest,
3415 name: ver.name + "-Client-ClientAuth-ECDSA",
3416 config: Config{
3417 MinVersion: ver.version,
3418 MaxVersion: ver.version,
3419 ClientAuth: RequireAnyClientCert,
3420 ClientCAs: certPool,
3421 },
David Benjamina5022392017-07-10 17:40:39 -04003422 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003423 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003424 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3425 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003426 },
3427 })
3428 }
Adam Langley37646832016-08-01 16:16:46 -07003429
3430 testCases = append(testCases, testCase{
3431 name: "NoClientCertificate-" + ver.name,
3432 config: Config{
3433 MinVersion: ver.version,
3434 MaxVersion: ver.version,
3435 ClientAuth: RequireAnyClientCert,
3436 },
David Benjamina5022392017-07-10 17:40:39 -04003437 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003438 shouldFail: true,
3439 expectedLocalError: "client didn't provide a certificate",
3440 })
3441
3442 testCases = append(testCases, testCase{
3443 // Even if not configured to expect a certificate, OpenSSL will
3444 // return X509_V_OK as the verify_result.
3445 testType: serverTest,
3446 name: "NoClientCertificateRequested-Server-" + ver.name,
3447 config: Config{
3448 MinVersion: ver.version,
3449 MaxVersion: ver.version,
3450 },
David Benjamina5022392017-07-10 17:40:39 -04003451 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003452 flags: []string{
3453 "-expect-verify-result",
3454 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003455 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003456 })
3457
3458 testCases = append(testCases, testCase{
3459 // If a client certificate is not provided, OpenSSL will still
3460 // return X509_V_OK as the verify_result.
3461 testType: serverTest,
3462 name: "NoClientCertificate-Server-" + ver.name,
3463 config: Config{
3464 MinVersion: ver.version,
3465 MaxVersion: ver.version,
3466 },
David Benjamina5022392017-07-10 17:40:39 -04003467 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003468 flags: []string{
3469 "-expect-verify-result",
3470 "-verify-peer",
3471 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003472 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003473 })
3474
David Benjamin1db9e1b2016-10-07 20:51:43 -04003475 certificateRequired := "remote error: certificate required"
3476 if ver.version < VersionTLS13 {
3477 // Prior to TLS 1.3, the generic handshake_failure alert
3478 // was used.
3479 certificateRequired = "remote error: handshake failure"
3480 }
Adam Langley37646832016-08-01 16:16:46 -07003481 testCases = append(testCases, testCase{
3482 testType: serverTest,
3483 name: "RequireAnyClientCertificate-" + ver.name,
3484 config: Config{
3485 MinVersion: ver.version,
3486 MaxVersion: ver.version,
3487 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003488 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003489 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003490 shouldFail: true,
3491 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3492 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003493 })
3494
3495 if ver.version != VersionSSL30 {
3496 testCases = append(testCases, testCase{
3497 testType: serverTest,
3498 name: "SkipClientCertificate-" + ver.name,
3499 config: Config{
3500 MinVersion: ver.version,
3501 MaxVersion: ver.version,
3502 Bugs: ProtocolBugs{
3503 SkipClientCertificate: true,
3504 },
3505 },
3506 // Setting SSL_VERIFY_PEER allows anonymous clients.
3507 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003508 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003509 shouldFail: true,
3510 expectedError: ":UNEXPECTED_MESSAGE:",
3511 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003512
3513 testCases = append(testCases, testCase{
3514 testType: serverTest,
3515 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3516 config: Config{
3517 MinVersion: ver.version,
3518 MaxVersion: ver.version,
3519 },
3520 flags: []string{
3521 "-enable-channel-id",
3522 "-verify-peer-if-no-obc",
3523 },
David Benjamina5022392017-07-10 17:40:39 -04003524 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003525 shouldFail: true,
3526 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3527 expectedLocalError: certificateRequired,
3528 })
3529
3530 testCases = append(testCases, testCase{
3531 testType: serverTest,
3532 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3533 config: Config{
3534 MinVersion: ver.version,
3535 MaxVersion: ver.version,
3536 ChannelID: channelIDKey,
3537 },
3538 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003539 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003540 flags: []string{
3541 "-enable-channel-id",
3542 "-verify-peer-if-no-obc",
3543 },
3544 })
Adam Langley37646832016-08-01 16:16:46 -07003545 }
Adam Langley2ff79332017-02-28 13:45:39 -08003546
3547 testCases = append(testCases, testCase{
3548 testType: serverTest,
3549 name: ver.name + "-Server-CertReq-CA-List",
3550 config: Config{
3551 MinVersion: ver.version,
3552 MaxVersion: ver.version,
3553 Certificates: []Certificate{rsaCertificate},
3554 Bugs: ProtocolBugs{
3555 ExpectCertificateReqNames: caNames,
3556 },
3557 },
David Benjamina5022392017-07-10 17:40:39 -04003558 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003559 flags: []string{
3560 "-require-any-client-certificate",
3561 "-use-client-ca-list", encodeDERValues(caNames),
3562 },
3563 })
3564
3565 testCases = append(testCases, testCase{
3566 testType: clientTest,
3567 name: ver.name + "-Client-CertReq-CA-List",
3568 config: Config{
3569 MinVersion: ver.version,
3570 MaxVersion: ver.version,
3571 Certificates: []Certificate{rsaCertificate},
3572 ClientAuth: RequireAnyClientCert,
3573 ClientCAs: certPool,
3574 },
David Benjamina5022392017-07-10 17:40:39 -04003575 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003576 flags: []string{
3577 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3578 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3579 "-expect-client-ca-list", encodeDERValues(caNames),
3580 },
3581 })
David Benjamin636293b2014-07-08 17:59:18 -04003582 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003583
David Benjaminc032dfa2016-05-12 14:54:57 -04003584 // Client auth is only legal in certificate-based ciphers.
3585 testCases = append(testCases, testCase{
3586 testType: clientTest,
3587 name: "ClientAuth-PSK",
3588 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003589 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003590 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3591 PreSharedKey: []byte("secret"),
3592 ClientAuth: RequireAnyClientCert,
3593 },
3594 flags: []string{
3595 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3596 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3597 "-psk", "secret",
3598 },
3599 shouldFail: true,
3600 expectedError: ":UNEXPECTED_MESSAGE:",
3601 })
3602 testCases = append(testCases, testCase{
3603 testType: clientTest,
3604 name: "ClientAuth-ECDHE_PSK",
3605 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003606 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003607 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3608 PreSharedKey: []byte("secret"),
3609 ClientAuth: RequireAnyClientCert,
3610 },
3611 flags: []string{
3612 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3613 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3614 "-psk", "secret",
3615 },
3616 shouldFail: true,
3617 expectedError: ":UNEXPECTED_MESSAGE:",
3618 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003619
3620 // Regression test for a bug where the client CA list, if explicitly
3621 // set to NULL, was mis-encoded.
3622 testCases = append(testCases, testCase{
3623 testType: serverTest,
3624 name: "Null-Client-CA-List",
3625 config: Config{
3626 MaxVersion: VersionTLS12,
3627 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003628 Bugs: ProtocolBugs{
3629 ExpectCertificateReqNames: [][]byte{},
3630 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003631 },
3632 flags: []string{
3633 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003634 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003635 },
3636 })
David Benjamin636293b2014-07-08 17:59:18 -04003637}
3638
Adam Langley75712922014-10-10 16:23:43 -07003639func addExtendedMasterSecretTests() {
3640 const expectEMSFlag = "-expect-extended-master-secret"
3641
3642 for _, with := range []bool{false, true} {
3643 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003644 if with {
3645 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003646 }
3647
3648 for _, isClient := range []bool{false, true} {
3649 suffix := "-Server"
3650 testType := serverTest
3651 if isClient {
3652 suffix = "-Client"
3653 testType = clientTest
3654 }
3655
3656 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003657 // In TLS 1.3, the extension is irrelevant and
3658 // always reports as enabled.
3659 var flags []string
3660 if with || ver.version >= VersionTLS13 {
3661 flags = []string{expectEMSFlag}
3662 }
3663
Adam Langley75712922014-10-10 16:23:43 -07003664 test := testCase{
3665 testType: testType,
3666 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3667 config: Config{
3668 MinVersion: ver.version,
3669 MaxVersion: ver.version,
3670 Bugs: ProtocolBugs{
3671 NoExtendedMasterSecret: !with,
3672 RequireExtendedMasterSecret: with,
3673 },
3674 },
David Benjamina5022392017-07-10 17:40:39 -04003675 tls13Variant: ver.tls13Variant,
3676 flags: flags,
3677 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003678 }
3679 if test.shouldFail {
3680 test.expectedLocalError = "extended master secret required but not supported by peer"
3681 }
3682 testCases = append(testCases, test)
3683 }
3684 }
3685 }
3686
Adam Langleyba5934b2015-06-02 10:50:35 -07003687 for _, isClient := range []bool{false, true} {
3688 for _, supportedInFirstConnection := range []bool{false, true} {
3689 for _, supportedInResumeConnection := range []bool{false, true} {
3690 boolToWord := func(b bool) string {
3691 if b {
3692 return "Yes"
3693 }
3694 return "No"
3695 }
3696 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3697 if isClient {
3698 suffix += "Client"
3699 } else {
3700 suffix += "Server"
3701 }
3702
3703 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003704 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003705 Bugs: ProtocolBugs{
3706 RequireExtendedMasterSecret: true,
3707 },
3708 }
3709
3710 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003711 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003712 Bugs: ProtocolBugs{
3713 NoExtendedMasterSecret: true,
3714 },
3715 }
3716
3717 test := testCase{
3718 name: "ExtendedMasterSecret-" + suffix,
3719 resumeSession: true,
3720 }
3721
3722 if !isClient {
3723 test.testType = serverTest
3724 }
3725
3726 if supportedInFirstConnection {
3727 test.config = supportedConfig
3728 } else {
3729 test.config = noSupportConfig
3730 }
3731
3732 if supportedInResumeConnection {
3733 test.resumeConfig = &supportedConfig
3734 } else {
3735 test.resumeConfig = &noSupportConfig
3736 }
3737
3738 switch suffix {
3739 case "YesToYes-Client", "YesToYes-Server":
3740 // When a session is resumed, it should
3741 // still be aware that its master
3742 // secret was generated via EMS and
3743 // thus it's safe to use tls-unique.
3744 test.flags = []string{expectEMSFlag}
3745 case "NoToYes-Server":
3746 // If an original connection did not
3747 // contain EMS, but a resumption
3748 // handshake does, then a server should
3749 // not resume the session.
3750 test.expectResumeRejected = true
3751 case "YesToNo-Server":
3752 // Resuming an EMS session without the
3753 // EMS extension should cause the
3754 // server to abort the connection.
3755 test.shouldFail = true
3756 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3757 case "NoToYes-Client":
3758 // A client should abort a connection
3759 // where the server resumed a non-EMS
3760 // session but echoed the EMS
3761 // extension.
3762 test.shouldFail = true
3763 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3764 case "YesToNo-Client":
3765 // A client should abort a connection
3766 // where the server didn't echo EMS
3767 // when the session used it.
3768 test.shouldFail = true
3769 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3770 }
3771
3772 testCases = append(testCases, test)
3773 }
3774 }
3775 }
David Benjamin163c9562016-08-29 23:14:17 -04003776
3777 // Switching EMS on renegotiation is forbidden.
3778 testCases = append(testCases, testCase{
3779 name: "ExtendedMasterSecret-Renego-NoEMS",
3780 config: Config{
3781 MaxVersion: VersionTLS12,
3782 Bugs: ProtocolBugs{
3783 NoExtendedMasterSecret: true,
3784 NoExtendedMasterSecretOnRenegotiation: true,
3785 },
3786 },
3787 renegotiate: 1,
3788 flags: []string{
3789 "-renegotiate-freely",
3790 "-expect-total-renegotiations", "1",
3791 },
3792 })
3793
3794 testCases = append(testCases, testCase{
3795 name: "ExtendedMasterSecret-Renego-Upgrade",
3796 config: Config{
3797 MaxVersion: VersionTLS12,
3798 Bugs: ProtocolBugs{
3799 NoExtendedMasterSecret: true,
3800 },
3801 },
3802 renegotiate: 1,
3803 flags: []string{
3804 "-renegotiate-freely",
3805 "-expect-total-renegotiations", "1",
3806 },
3807 shouldFail: true,
3808 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3809 })
3810
3811 testCases = append(testCases, testCase{
3812 name: "ExtendedMasterSecret-Renego-Downgrade",
3813 config: Config{
3814 MaxVersion: VersionTLS12,
3815 Bugs: ProtocolBugs{
3816 NoExtendedMasterSecretOnRenegotiation: true,
3817 },
3818 },
3819 renegotiate: 1,
3820 flags: []string{
3821 "-renegotiate-freely",
3822 "-expect-total-renegotiations", "1",
3823 },
3824 shouldFail: true,
3825 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3826 })
Adam Langley75712922014-10-10 16:23:43 -07003827}
3828
David Benjamin582ba042016-07-07 12:33:25 -07003829type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003830 protocol protocol
3831 async bool
3832 splitHandshake bool
3833 packHandshakeFlight bool
3834 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003835}
3836
David Benjamin43ec06f2014-08-05 02:28:57 -04003837// Adds tests that try to cover the range of the handshake state machine, under
3838// various conditions. Some of these are redundant with other tests, but they
3839// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003840func addAllStateMachineCoverageTests() {
3841 for _, async := range []bool{false, true} {
3842 for _, protocol := range []protocol{tls, dtls} {
3843 addStateMachineCoverageTests(stateMachineTestConfig{
3844 protocol: protocol,
3845 async: async,
3846 })
3847 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003848 protocol: protocol,
3849 async: async,
3850 implicitHandshake: true,
3851 })
3852 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003853 protocol: protocol,
3854 async: async,
3855 splitHandshake: true,
3856 })
3857 if protocol == tls {
3858 addStateMachineCoverageTests(stateMachineTestConfig{
3859 protocol: protocol,
3860 async: async,
3861 packHandshakeFlight: true,
3862 })
3863 }
3864 }
3865 }
3866}
3867
3868func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003869 var tests []testCase
3870
3871 // Basic handshake, with resumption. Client and server,
3872 // session ID and session ticket.
3873 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003874 name: "Basic-Client",
3875 config: Config{
3876 MaxVersion: VersionTLS12,
3877 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003878 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003879 // Ensure session tickets are used, not session IDs.
3880 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 })
3882 tests = append(tests, testCase{
3883 name: "Basic-Client-RenewTicket",
3884 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003885 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003886 Bugs: ProtocolBugs{
3887 RenewTicketOnResume: true,
3888 },
3889 },
David Benjamin46662482016-08-17 00:51:00 -04003890 flags: []string{"-expect-ticket-renewal"},
3891 resumeSession: true,
3892 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003893 })
3894 tests = append(tests, testCase{
3895 name: "Basic-Client-NoTicket",
3896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003897 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003898 SessionTicketsDisabled: true,
3899 },
3900 resumeSession: true,
3901 })
3902 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003903 testType: serverTest,
3904 name: "Basic-Server",
3905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003906 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003907 Bugs: ProtocolBugs{
3908 RequireSessionTickets: true,
3909 },
3910 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003911 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003912 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003913 })
3914 tests = append(tests, testCase{
3915 testType: serverTest,
3916 name: "Basic-Server-NoTickets",
3917 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003918 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003919 SessionTicketsDisabled: true,
3920 },
3921 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003922 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003923 })
3924 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003925 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003926 name: "Basic-Server-EarlyCallback",
3927 config: Config{
3928 MaxVersion: VersionTLS12,
3929 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003930 flags: []string{"-use-early-callback"},
3931 resumeSession: true,
3932 })
3933
Steven Valdez143e8b32016-07-11 13:19:03 -04003934 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003935 if config.protocol == tls {
3936 tests = append(tests, testCase{
3937 name: "TLS13-1RTT-Client",
3938 config: Config{
3939 MaxVersion: VersionTLS13,
3940 MinVersion: VersionTLS13,
3941 },
David Benjamin46662482016-08-17 00:51:00 -04003942 resumeSession: true,
3943 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003944 })
3945
3946 tests = append(tests, testCase{
3947 testType: serverTest,
3948 name: "TLS13-1RTT-Server",
3949 config: Config{
3950 MaxVersion: VersionTLS13,
3951 MinVersion: VersionTLS13,
3952 },
David Benjamin46662482016-08-17 00:51:00 -04003953 resumeSession: true,
3954 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003955 // TLS 1.3 uses tickets, so the session should not be
3956 // cached statefully.
3957 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003958 })
3959
3960 tests = append(tests, testCase{
3961 name: "TLS13-HelloRetryRequest-Client",
3962 config: Config{
3963 MaxVersion: VersionTLS13,
3964 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003965 // P-384 requires a HelloRetryRequest against BoringSSL's default
3966 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003967 CurvePreferences: []CurveID{CurveP384},
3968 Bugs: ProtocolBugs{
3969 ExpectMissingKeyShare: true,
3970 },
3971 },
3972 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3973 resumeSession: true,
3974 })
3975
3976 tests = append(tests, testCase{
3977 testType: serverTest,
3978 name: "TLS13-HelloRetryRequest-Server",
3979 config: Config{
3980 MaxVersion: VersionTLS13,
3981 MinVersion: VersionTLS13,
3982 // Require a HelloRetryRequest for every curve.
3983 DefaultCurves: []CurveID{},
3984 },
3985 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3986 resumeSession: true,
3987 })
Steven Valdez2d850622017-01-11 11:34:52 -05003988
Steven Valdez2d850622017-01-11 11:34:52 -05003989 tests = append(tests, testCase{
3990 testType: clientTest,
3991 name: "TLS13-EarlyData-Client",
3992 config: Config{
3993 MaxVersion: VersionTLS13,
3994 MinVersion: VersionTLS13,
3995 MaxEarlyDataSize: 16384,
3996 },
Steven Valdeze831a812017-03-09 14:56:07 -05003997 resumeConfig: &Config{
3998 MaxVersion: VersionTLS13,
3999 MinVersion: VersionTLS13,
4000 MaxEarlyDataSize: 16384,
4001 Bugs: ProtocolBugs{
4002 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4003 },
4004 },
Steven Valdez2d850622017-01-11 11:34:52 -05004005 resumeSession: true,
4006 flags: []string{
4007 "-enable-early-data",
4008 "-expect-early-data-info",
4009 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004010 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004011 },
4012 })
4013
4014 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004015 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004016 name: "TLS13Experiment-EarlyData-Client",
4017 config: Config{
4018 MaxVersion: VersionTLS13,
4019 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004020 MaxEarlyDataSize: 16384,
4021 },
4022 resumeConfig: &Config{
4023 MaxVersion: VersionTLS13,
4024 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004025 MaxEarlyDataSize: 16384,
4026 Bugs: ProtocolBugs{
4027 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4028 },
4029 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004030 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004031 resumeSession: true,
4032 flags: []string{
4033 "-enable-early-data",
4034 "-expect-early-data-info",
4035 "-expect-accept-early-data",
4036 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004037 },
4038 })
4039
4040 tests = append(tests, testCase{
4041 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004042 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4043 config: Config{
4044 MaxVersion: VersionTLS13,
4045 MinVersion: VersionTLS13,
4046 TLS13Variant: TLS13RecordTypeExperiment,
4047 MaxEarlyDataSize: 16384,
4048 },
4049 resumeConfig: &Config{
4050 MaxVersion: VersionTLS13,
4051 MinVersion: VersionTLS13,
4052 TLS13Variant: TLS13RecordTypeExperiment,
4053 MaxEarlyDataSize: 16384,
4054 Bugs: ProtocolBugs{
4055 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4056 },
4057 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004058 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004059 resumeSession: true,
4060 flags: []string{
4061 "-enable-early-data",
4062 "-expect-early-data-info",
4063 "-expect-accept-early-data",
4064 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004065 },
4066 })
4067
4068 tests = append(tests, testCase{
4069 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004070 name: "TLS13-EarlyData-TooMuchData-Client",
4071 config: Config{
4072 MaxVersion: VersionTLS13,
4073 MinVersion: VersionTLS13,
4074 MaxEarlyDataSize: 2,
4075 },
4076 resumeConfig: &Config{
4077 MaxVersion: VersionTLS13,
4078 MinVersion: VersionTLS13,
4079 MaxEarlyDataSize: 2,
4080 Bugs: ProtocolBugs{
4081 ExpectEarlyData: [][]byte{{'h', 'e'}},
4082 },
4083 },
4084 resumeShimPrefix: "llo",
4085 resumeSession: true,
4086 flags: []string{
4087 "-enable-early-data",
4088 "-expect-early-data-info",
4089 "-expect-accept-early-data",
4090 "-on-resume-shim-writes-first",
4091 },
4092 })
4093
4094 // Unfinished writes can only be tested when operations are async. EarlyData
4095 // can't be tested as part of an ImplicitHandshake in this case since
4096 // otherwise the early data will be sent as normal data.
4097 if config.async && !config.implicitHandshake {
4098 tests = append(tests, testCase{
4099 testType: clientTest,
4100 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4101 config: Config{
4102 MaxVersion: VersionTLS13,
4103 MinVersion: VersionTLS13,
4104 MaxEarlyDataSize: 16384,
4105 },
4106 resumeConfig: &Config{
4107 MaxVersion: VersionTLS13,
4108 MinVersion: VersionTLS13,
4109 MaxEarlyDataSize: 16384,
4110 Bugs: ProtocolBugs{
4111 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4112 },
4113 },
4114 resumeSession: true,
4115 flags: []string{
4116 "-enable-early-data",
4117 "-expect-early-data-info",
4118 "-expect-accept-early-data",
4119 "-on-resume-read-with-unfinished-write",
4120 "-on-resume-shim-writes-first",
4121 },
4122 })
4123
4124 // Rejected unfinished writes are discarded (from the
4125 // perspective of the calling application) on 0-RTT
4126 // reject.
4127 tests = append(tests, testCase{
4128 testType: clientTest,
4129 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4130 config: Config{
4131 MaxVersion: VersionTLS13,
4132 MinVersion: VersionTLS13,
4133 MaxEarlyDataSize: 16384,
4134 },
4135 resumeConfig: &Config{
4136 MaxVersion: VersionTLS13,
4137 MinVersion: VersionTLS13,
4138 MaxEarlyDataSize: 16384,
4139 Bugs: ProtocolBugs{
4140 AlwaysRejectEarlyData: true,
4141 },
4142 },
4143 resumeSession: true,
4144 flags: []string{
4145 "-enable-early-data",
4146 "-expect-early-data-info",
4147 "-expect-reject-early-data",
4148 "-on-resume-read-with-unfinished-write",
4149 "-on-resume-shim-writes-first",
4150 },
4151 })
4152 }
4153
4154 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004155 testType: serverTest,
4156 name: "TLS13-EarlyData-Server",
4157 config: Config{
4158 MaxVersion: VersionTLS13,
4159 MinVersion: VersionTLS13,
4160 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004161 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004162 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004163 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004164 },
4165 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004166 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004167 resumeSession: true,
4168 flags: []string{
4169 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004170 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004171 },
4172 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004173
4174 tests = append(tests, testCase{
4175 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004176 name: "TLS13Experiment-EarlyData-Server",
4177 config: Config{
4178 MaxVersion: VersionTLS13,
4179 MinVersion: VersionTLS13,
4180 TLS13Variant: TLS13Experiment,
4181 Bugs: ProtocolBugs{
4182 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4183 ExpectEarlyDataAccepted: true,
4184 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4185 },
4186 },
4187 messageCount: 2,
4188 resumeSession: true,
4189 flags: []string{
4190 "-enable-early-data",
4191 "-expect-accept-early-data",
4192 "-tls13-variant", "1",
4193 },
4194 })
4195
4196 tests = append(tests, testCase{
4197 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004198 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4199 config: Config{
4200 MaxVersion: VersionTLS13,
4201 MinVersion: VersionTLS13,
4202 TLS13Variant: TLS13RecordTypeExperiment,
4203 Bugs: ProtocolBugs{
4204 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4205 ExpectEarlyDataAccepted: true,
4206 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4207 },
4208 },
4209 messageCount: 2,
4210 resumeSession: true,
4211 flags: []string{
4212 "-enable-early-data",
4213 "-expect-accept-early-data",
4214 "-tls13-variant", "2",
4215 },
4216 })
4217
4218 tests = append(tests, testCase{
4219 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004220 name: "TLS13-MaxEarlyData-Server",
4221 config: Config{
4222 MaxVersion: VersionTLS13,
4223 MinVersion: VersionTLS13,
4224 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004225 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004226 ExpectEarlyDataAccepted: true,
4227 },
4228 },
4229 messageCount: 2,
4230 resumeSession: true,
4231 flags: []string{
4232 "-enable-early-data",
4233 "-expect-accept-early-data",
4234 },
4235 shouldFail: true,
4236 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4237 })
David Benjamine73c7f42016-08-17 00:29:33 -04004238 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004239
David Benjamin760b1dd2015-05-15 23:33:48 -04004240 // TLS client auth.
4241 tests = append(tests, testCase{
4242 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004243 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004244 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004245 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004246 ClientAuth: RequestClientCert,
4247 },
4248 })
4249 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004250 testType: serverTest,
4251 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004252 config: Config{
4253 MaxVersion: VersionTLS12,
4254 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004255 // Setting SSL_VERIFY_PEER allows anonymous clients.
4256 flags: []string{"-verify-peer"},
4257 })
David Benjamin582ba042016-07-07 12:33:25 -07004258 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004259 tests = append(tests, testCase{
4260 testType: clientTest,
4261 name: "ClientAuth-NoCertificate-Client-SSL3",
4262 config: Config{
4263 MaxVersion: VersionSSL30,
4264 ClientAuth: RequestClientCert,
4265 },
4266 })
4267 tests = append(tests, testCase{
4268 testType: serverTest,
4269 name: "ClientAuth-NoCertificate-Server-SSL3",
4270 config: Config{
4271 MaxVersion: VersionSSL30,
4272 },
4273 // Setting SSL_VERIFY_PEER allows anonymous clients.
4274 flags: []string{"-verify-peer"},
4275 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004276 tests = append(tests, testCase{
4277 testType: clientTest,
4278 name: "ClientAuth-NoCertificate-Client-TLS13",
4279 config: Config{
4280 MaxVersion: VersionTLS13,
4281 ClientAuth: RequestClientCert,
4282 },
4283 })
4284 tests = append(tests, testCase{
4285 testType: serverTest,
4286 name: "ClientAuth-NoCertificate-Server-TLS13",
4287 config: Config{
4288 MaxVersion: VersionTLS13,
4289 },
4290 // Setting SSL_VERIFY_PEER allows anonymous clients.
4291 flags: []string{"-verify-peer"},
4292 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004293 }
4294 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004295 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004296 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004297 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004298 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004299 ClientAuth: RequireAnyClientCert,
4300 },
4301 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004302 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4303 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004304 },
4305 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004306 tests = append(tests, testCase{
4307 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004308 name: "ClientAuth-RSA-Client-TLS13",
4309 config: Config{
4310 MaxVersion: VersionTLS13,
4311 ClientAuth: RequireAnyClientCert,
4312 },
4313 flags: []string{
4314 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4315 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4316 },
4317 })
4318 tests = append(tests, testCase{
4319 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004320 name: "ClientAuth-ECDSA-Client",
4321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004323 ClientAuth: RequireAnyClientCert,
4324 },
4325 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004326 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4327 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004328 },
4329 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004330 tests = append(tests, testCase{
4331 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004332 name: "ClientAuth-ECDSA-Client-TLS13",
4333 config: Config{
4334 MaxVersion: VersionTLS13,
4335 ClientAuth: RequireAnyClientCert,
4336 },
4337 flags: []string{
4338 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4339 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4340 },
4341 })
4342 tests = append(tests, testCase{
4343 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004344 name: "ClientAuth-NoCertificate-OldCallback",
4345 config: Config{
4346 MaxVersion: VersionTLS12,
4347 ClientAuth: RequestClientCert,
4348 },
4349 flags: []string{"-use-old-client-cert-callback"},
4350 })
4351 tests = append(tests, testCase{
4352 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004353 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4354 config: Config{
4355 MaxVersion: VersionTLS13,
4356 ClientAuth: RequestClientCert,
4357 },
4358 flags: []string{"-use-old-client-cert-callback"},
4359 })
4360 tests = append(tests, testCase{
4361 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004362 name: "ClientAuth-OldCallback",
4363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004364 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004365 ClientAuth: RequireAnyClientCert,
4366 },
4367 flags: []string{
4368 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4369 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4370 "-use-old-client-cert-callback",
4371 },
4372 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004373 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004374 testType: clientTest,
4375 name: "ClientAuth-OldCallback-TLS13",
4376 config: Config{
4377 MaxVersion: VersionTLS13,
4378 ClientAuth: RequireAnyClientCert,
4379 },
4380 flags: []string{
4381 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4382 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4383 "-use-old-client-cert-callback",
4384 },
4385 })
4386 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004387 testType: serverTest,
4388 name: "ClientAuth-Server",
4389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004390 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004391 Certificates: []Certificate{rsaCertificate},
4392 },
4393 flags: []string{"-require-any-client-certificate"},
4394 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004395 tests = append(tests, testCase{
4396 testType: serverTest,
4397 name: "ClientAuth-Server-TLS13",
4398 config: Config{
4399 MaxVersion: VersionTLS13,
4400 Certificates: []Certificate{rsaCertificate},
4401 },
4402 flags: []string{"-require-any-client-certificate"},
4403 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004404
David Benjamin4c3ddf72016-06-29 18:13:53 -04004405 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004406 tests = append(tests, testCase{
4407 testType: serverTest,
4408 name: "Basic-Server-RSA",
4409 config: Config{
4410 MaxVersion: VersionTLS12,
4411 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4412 },
4413 flags: []string{
4414 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4415 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4416 },
4417 })
4418 tests = append(tests, testCase{
4419 testType: serverTest,
4420 name: "Basic-Server-ECDHE-RSA",
4421 config: Config{
4422 MaxVersion: VersionTLS12,
4423 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4424 },
4425 flags: []string{
4426 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4427 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4428 },
4429 })
4430 tests = append(tests, testCase{
4431 testType: serverTest,
4432 name: "Basic-Server-ECDHE-ECDSA",
4433 config: Config{
4434 MaxVersion: VersionTLS12,
4435 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4436 },
4437 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004438 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4439 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004440 },
4441 })
David Benjamin69522112017-03-28 15:38:29 -05004442 tests = append(tests, testCase{
4443 testType: serverTest,
4444 name: "Basic-Server-Ed25519",
4445 config: Config{
4446 MaxVersion: VersionTLS12,
4447 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4448 },
4449 flags: []string{
4450 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4451 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4452 "-enable-ed25519",
4453 },
4454 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004455
David Benjamin760b1dd2015-05-15 23:33:48 -04004456 // No session ticket support; server doesn't send NewSessionTicket.
4457 tests = append(tests, testCase{
4458 name: "SessionTicketsDisabled-Client",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 SessionTicketsDisabled: true,
4462 },
4463 })
4464 tests = append(tests, testCase{
4465 testType: serverTest,
4466 name: "SessionTicketsDisabled-Server",
4467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004468 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004469 SessionTicketsDisabled: true,
4470 },
4471 })
4472
4473 // Skip ServerKeyExchange in PSK key exchange if there's no
4474 // identity hint.
4475 tests = append(tests, testCase{
4476 name: "EmptyPSKHint-Client",
4477 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004478 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004479 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4480 PreSharedKey: []byte("secret"),
4481 },
4482 flags: []string{"-psk", "secret"},
4483 })
4484 tests = append(tests, testCase{
4485 testType: serverTest,
4486 name: "EmptyPSKHint-Server",
4487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004488 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004489 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4490 PreSharedKey: []byte("secret"),
4491 },
4492 flags: []string{"-psk", "secret"},
4493 })
4494
David Benjamin4c3ddf72016-06-29 18:13:53 -04004495 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004496 tests = append(tests, testCase{
4497 testType: clientTest,
4498 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004499 config: Config{
4500 MaxVersion: VersionTLS12,
4501 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004502 flags: []string{
4503 "-enable-ocsp-stapling",
4504 "-expect-ocsp-response",
4505 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004506 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004507 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004508 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004509 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004510 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004511 testType: serverTest,
4512 name: "OCSPStapling-Server",
4513 config: Config{
4514 MaxVersion: VersionTLS12,
4515 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004516 expectedOCSPResponse: testOCSPResponse,
4517 flags: []string{
4518 "-ocsp-response",
4519 base64.StdEncoding.EncodeToString(testOCSPResponse),
4520 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004521 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004522 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004523 tests = append(tests, testCase{
4524 testType: clientTest,
4525 name: "OCSPStapling-Client-TLS13",
4526 config: Config{
4527 MaxVersion: VersionTLS13,
4528 },
4529 flags: []string{
4530 "-enable-ocsp-stapling",
4531 "-expect-ocsp-response",
4532 base64.StdEncoding.EncodeToString(testOCSPResponse),
4533 "-verify-peer",
4534 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004535 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004536 })
4537 tests = append(tests, testCase{
4538 testType: serverTest,
4539 name: "OCSPStapling-Server-TLS13",
4540 config: Config{
4541 MaxVersion: VersionTLS13,
4542 },
4543 expectedOCSPResponse: testOCSPResponse,
4544 flags: []string{
4545 "-ocsp-response",
4546 base64.StdEncoding.EncodeToString(testOCSPResponse),
4547 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004548 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004549 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004550
David Benjamin4c3ddf72016-06-29 18:13:53 -04004551 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004552 for _, vers := range tlsVersions {
4553 if config.protocol == dtls && !vers.hasDTLS {
4554 continue
4555 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004556 for _, useCustomCallback := range []bool{false, true} {
4557 for _, testType := range []testType{clientTest, serverTest} {
4558 suffix := "-Client"
4559 if testType == serverTest {
4560 suffix = "-Server"
4561 }
4562 suffix += "-" + vers.name
4563 if useCustomCallback {
4564 suffix += "-CustomCallback"
4565 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004566
David Benjamin3a1dd462017-07-11 16:13:10 -04004567 flags := []string{"-verify-peer"}
4568 if testType == serverTest {
4569 flags = append(flags, "-require-any-client-certificate")
4570 }
4571 if useCustomCallback {
4572 flags = append(flags, "-use-custom-verify-callback")
4573 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004574
David Benjamin3a1dd462017-07-11 16:13:10 -04004575 tests = append(tests, testCase{
4576 testType: testType,
4577 name: "CertificateVerificationSucceed" + suffix,
4578 config: Config{
4579 MaxVersion: vers.version,
4580 Certificates: []Certificate{rsaCertificate},
4581 },
4582 tls13Variant: vers.tls13Variant,
4583 flags: append([]string{"-expect-verify-result"}, flags...),
4584 resumeSession: true,
4585 })
4586 tests = append(tests, testCase{
4587 testType: testType,
4588 name: "CertificateVerificationFail" + suffix,
4589 config: Config{
4590 MaxVersion: vers.version,
4591 Certificates: []Certificate{rsaCertificate},
4592 },
4593 tls13Variant: vers.tls13Variant,
4594 flags: append([]string{"-verify-fail"}, flags...),
4595 shouldFail: true,
4596 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4597 })
4598 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004599 }
4600
4601 // By default, the client is in a soft fail mode where the peer
4602 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004603 tests = append(tests, testCase{
4604 testType: clientTest,
4605 name: "CertificateVerificationSoftFail-" + vers.name,
4606 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004607 MaxVersion: vers.version,
4608 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004609 },
David Benjamina5022392017-07-10 17:40:39 -04004610 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004611 flags: []string{
4612 "-verify-fail",
4613 "-expect-verify-result",
4614 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004615 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004616 })
4617 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004618
David Benjamin1d4f4c02016-07-26 18:03:08 -04004619 tests = append(tests, testCase{
4620 name: "ShimSendAlert",
4621 flags: []string{"-send-alert"},
4622 shimWritesFirst: true,
4623 shouldFail: true,
4624 expectedLocalError: "remote error: decompression failure",
4625 })
4626
David Benjamin582ba042016-07-07 12:33:25 -07004627 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004628 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004629 name: "Renegotiate-Client",
4630 config: Config{
4631 MaxVersion: VersionTLS12,
4632 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004633 renegotiate: 1,
4634 flags: []string{
4635 "-renegotiate-freely",
4636 "-expect-total-renegotiations", "1",
4637 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004638 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004639
David Benjamin47921102016-07-28 11:29:18 -04004640 tests = append(tests, testCase{
4641 name: "SendHalfHelloRequest",
4642 config: Config{
4643 MaxVersion: VersionTLS12,
4644 Bugs: ProtocolBugs{
4645 PackHelloRequestWithFinished: config.packHandshakeFlight,
4646 },
4647 },
4648 sendHalfHelloRequest: true,
4649 flags: []string{"-renegotiate-ignore"},
4650 shouldFail: true,
4651 expectedError: ":UNEXPECTED_RECORD:",
4652 })
4653
David Benjamin760b1dd2015-05-15 23:33:48 -04004654 // NPN on client and server; results in post-handshake message.
4655 tests = append(tests, testCase{
4656 name: "NPN-Client",
4657 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004658 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004659 NextProtos: []string{"foo"},
4660 },
4661 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004662 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004663 expectedNextProto: "foo",
4664 expectedNextProtoType: npn,
4665 })
4666 tests = append(tests, testCase{
4667 testType: serverTest,
4668 name: "NPN-Server",
4669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004670 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004671 NextProtos: []string{"bar"},
4672 },
4673 flags: []string{
4674 "-advertise-npn", "\x03foo\x03bar\x03baz",
4675 "-expect-next-proto", "bar",
4676 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004677 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004678 expectedNextProto: "bar",
4679 expectedNextProtoType: npn,
4680 })
4681
4682 // TODO(davidben): Add tests for when False Start doesn't trigger.
4683
4684 // Client does False Start and negotiates NPN.
4685 tests = append(tests, testCase{
4686 name: "FalseStart",
4687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4690 NextProtos: []string{"foo"},
4691 Bugs: ProtocolBugs{
4692 ExpectFalseStart: true,
4693 },
4694 },
4695 flags: []string{
4696 "-false-start",
4697 "-select-next-proto", "foo",
4698 },
4699 shimWritesFirst: true,
4700 resumeSession: true,
4701 })
4702
4703 // Client does False Start and negotiates ALPN.
4704 tests = append(tests, testCase{
4705 name: "FalseStart-ALPN",
4706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004707 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004708 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4709 NextProtos: []string{"foo"},
4710 Bugs: ProtocolBugs{
4711 ExpectFalseStart: true,
4712 },
4713 },
4714 flags: []string{
4715 "-false-start",
4716 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004717 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004718 },
4719 shimWritesFirst: true,
4720 resumeSession: true,
4721 })
4722
David Benjamin760b1dd2015-05-15 23:33:48 -04004723 // False Start without session tickets.
4724 tests = append(tests, testCase{
4725 name: "FalseStart-SessionTicketsDisabled",
4726 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4729 NextProtos: []string{"foo"},
4730 SessionTicketsDisabled: true,
4731 Bugs: ProtocolBugs{
4732 ExpectFalseStart: true,
4733 },
4734 },
4735 flags: []string{
4736 "-false-start",
4737 "-select-next-proto", "foo",
4738 },
4739 shimWritesFirst: true,
4740 })
4741
4742 // Server parses a V2ClientHello.
4743 tests = append(tests, testCase{
4744 testType: serverTest,
4745 name: "SendV2ClientHello",
4746 config: Config{
4747 // Choose a cipher suite that does not involve
4748 // elliptic curves, so no extensions are
4749 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004750 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004751 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004752 Bugs: ProtocolBugs{
4753 SendV2ClientHello: true,
4754 },
4755 },
4756 })
4757
Nick Harper60a85cb2016-09-23 16:25:11 -07004758 // Test Channel ID
4759 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004760 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004761 continue
4762 }
4763 // Client sends a Channel ID.
4764 tests = append(tests, testCase{
4765 name: "ChannelID-Client-" + ver.name,
4766 config: Config{
4767 MaxVersion: ver.version,
4768 RequestChannelID: true,
4769 },
David Benjamina5022392017-07-10 17:40:39 -04004770 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004771 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4772 resumeSession: true,
4773 expectChannelID: true,
4774 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004775
Nick Harper60a85cb2016-09-23 16:25:11 -07004776 // Server accepts a Channel ID.
4777 tests = append(tests, testCase{
4778 testType: serverTest,
4779 name: "ChannelID-Server-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 ChannelID: channelIDKey,
4783 },
David Benjamina5022392017-07-10 17:40:39 -04004784 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004785 flags: []string{
4786 "-expect-channel-id",
4787 base64.StdEncoding.EncodeToString(channelIDBytes),
4788 },
4789 resumeSession: true,
4790 expectChannelID: true,
4791 })
4792
4793 tests = append(tests, testCase{
4794 testType: serverTest,
4795 name: "InvalidChannelIDSignature-" + ver.name,
4796 config: Config{
4797 MaxVersion: ver.version,
4798 ChannelID: channelIDKey,
4799 Bugs: ProtocolBugs{
4800 InvalidChannelIDSignature: true,
4801 },
4802 },
David Benjamina5022392017-07-10 17:40:39 -04004803 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004804 flags: []string{"-enable-channel-id"},
4805 shouldFail: true,
4806 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4807 })
David Benjamin634f4752017-07-01 11:08:41 -04004808
4809 if ver.version < VersionTLS13 {
4810 // Channel ID requires ECDHE ciphers.
4811 tests = append(tests, testCase{
4812 testType: serverTest,
4813 name: "ChannelID-NoECDHE-" + ver.name,
4814 config: Config{
4815 MaxVersion: ver.version,
4816 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4817 ChannelID: channelIDKey,
4818 },
4819 expectChannelID: false,
4820 flags: []string{"-enable-channel-id"},
4821 })
4822
4823 // Sanity-check setting expectChannelID false works.
4824 tests = append(tests, testCase{
4825 testType: serverTest,
4826 name: "ChannelID-ECDHE-" + ver.name,
4827 config: Config{
4828 MaxVersion: ver.version,
4829 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4830 ChannelID: channelIDKey,
4831 },
4832 expectChannelID: false,
4833 flags: []string{"-enable-channel-id"},
4834 shouldFail: true,
4835 expectedLocalError: "channel ID unexpectedly negotiated",
4836 })
4837 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004838 }
David Benjamin30789da2015-08-29 22:56:45 -04004839
David Benjaminf8fcdf32016-06-08 15:56:13 -04004840 // Channel ID and NPN at the same time, to ensure their relative
4841 // ordering is correct.
4842 tests = append(tests, testCase{
4843 name: "ChannelID-NPN-Client",
4844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004845 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004846 RequestChannelID: true,
4847 NextProtos: []string{"foo"},
4848 },
4849 flags: []string{
4850 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4851 "-select-next-proto", "foo",
4852 },
4853 resumeSession: true,
4854 expectChannelID: true,
4855 expectedNextProto: "foo",
4856 expectedNextProtoType: npn,
4857 })
4858 tests = append(tests, testCase{
4859 testType: serverTest,
4860 name: "ChannelID-NPN-Server",
4861 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004862 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004863 ChannelID: channelIDKey,
4864 NextProtos: []string{"bar"},
4865 },
4866 flags: []string{
4867 "-expect-channel-id",
4868 base64.StdEncoding.EncodeToString(channelIDBytes),
4869 "-advertise-npn", "\x03foo\x03bar\x03baz",
4870 "-expect-next-proto", "bar",
4871 },
4872 resumeSession: true,
4873 expectChannelID: true,
4874 expectedNextProto: "bar",
4875 expectedNextProtoType: npn,
4876 })
4877
David Benjamin30789da2015-08-29 22:56:45 -04004878 // Bidirectional shutdown with the runner initiating.
4879 tests = append(tests, testCase{
4880 name: "Shutdown-Runner",
4881 config: Config{
4882 Bugs: ProtocolBugs{
4883 ExpectCloseNotify: true,
4884 },
4885 },
4886 flags: []string{"-check-close-notify"},
4887 })
4888
David Benjamine3843d42017-03-25 18:00:56 -05004889 if !config.implicitHandshake {
4890 // Bidirectional shutdown with the shim initiating. The runner,
4891 // in the meantime, sends garbage before the close_notify which
4892 // the shim must ignore. This test is disabled under implicit
4893 // handshake tests because the shim never reads or writes.
4894 tests = append(tests, testCase{
4895 name: "Shutdown-Shim",
4896 config: Config{
4897 MaxVersion: VersionTLS12,
4898 Bugs: ProtocolBugs{
4899 ExpectCloseNotify: true,
4900 },
David Benjamin30789da2015-08-29 22:56:45 -04004901 },
David Benjamine3843d42017-03-25 18:00:56 -05004902 shimShutsDown: true,
4903 sendEmptyRecords: 1,
4904 sendWarningAlerts: 1,
4905 flags: []string{"-check-close-notify"},
4906 })
4907 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004908 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004909 // TODO(davidben): DTLS 1.3 will want a similar thing for
4910 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004911 tests = append(tests, testCase{
4912 name: "SkipHelloVerifyRequest",
4913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004914 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004915 Bugs: ProtocolBugs{
4916 SkipHelloVerifyRequest: true,
4917 },
4918 },
4919 })
4920 }
4921
David Benjamin760b1dd2015-05-15 23:33:48 -04004922 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004923 test.protocol = config.protocol
4924 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004925 test.name += "-DTLS"
4926 }
David Benjamin582ba042016-07-07 12:33:25 -07004927 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004928 test.name += "-Async"
4929 test.flags = append(test.flags, "-async")
4930 } else {
4931 test.name += "-Sync"
4932 }
David Benjamin582ba042016-07-07 12:33:25 -07004933 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004934 test.name += "-SplitHandshakeRecords"
4935 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004936 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004937 test.config.Bugs.MaxPacketLength = 256
4938 test.flags = append(test.flags, "-mtu", "256")
4939 }
4940 }
David Benjamin582ba042016-07-07 12:33:25 -07004941 if config.packHandshakeFlight {
4942 test.name += "-PackHandshakeFlight"
4943 test.config.Bugs.PackHandshakeFlight = true
4944 }
David Benjamine3843d42017-03-25 18:00:56 -05004945 if config.implicitHandshake {
4946 test.name += "-ImplicitHandshake"
4947 test.flags = append(test.flags, "-implicit-handshake")
4948 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004949 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004950 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004951}
4952
Adam Langley524e7172015-02-20 16:04:00 -08004953func addDDoSCallbackTests() {
4954 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004955 for _, resume := range []bool{false, true} {
4956 suffix := "Resume"
4957 if resume {
4958 suffix = "No" + suffix
4959 }
4960
4961 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004962 testType: serverTest,
4963 name: "Server-DDoS-OK-" + suffix,
4964 config: Config{
4965 MaxVersion: VersionTLS12,
4966 },
Adam Langley524e7172015-02-20 16:04:00 -08004967 flags: []string{"-install-ddos-callback"},
4968 resumeSession: resume,
4969 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004970 testCases = append(testCases, testCase{
4971 testType: serverTest,
4972 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4973 config: Config{
4974 MaxVersion: VersionTLS13,
4975 },
4976 flags: []string{"-install-ddos-callback"},
4977 resumeSession: resume,
4978 })
Adam Langley524e7172015-02-20 16:04:00 -08004979
4980 failFlag := "-fail-ddos-callback"
4981 if resume {
4982 failFlag = "-fail-second-ddos-callback"
4983 }
4984 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004985 testType: serverTest,
4986 name: "Server-DDoS-Reject-" + suffix,
4987 config: Config{
4988 MaxVersion: VersionTLS12,
4989 },
David Benjamin2c66e072016-09-16 15:58:00 -04004990 flags: []string{"-install-ddos-callback", failFlag},
4991 resumeSession: resume,
4992 shouldFail: true,
4993 expectedError: ":CONNECTION_REJECTED:",
4994 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004995 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004996 testCases = append(testCases, testCase{
4997 testType: serverTest,
4998 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4999 config: Config{
5000 MaxVersion: VersionTLS13,
5001 },
David Benjamin2c66e072016-09-16 15:58:00 -04005002 flags: []string{"-install-ddos-callback", failFlag},
5003 resumeSession: resume,
5004 shouldFail: true,
5005 expectedError: ":CONNECTION_REJECTED:",
5006 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005007 })
Adam Langley524e7172015-02-20 16:04:00 -08005008 }
5009}
5010
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005011func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005012 for _, protocol := range []protocol{tls, dtls} {
5013 for _, shimVers := range allVersions(protocol) {
5014 // Assemble flags to disable all newer versions on the shim.
5015 var flags []string
5016 for _, vers := range allVersions(protocol) {
5017 if vers.version > shimVers.version {
5018 flags = append(flags, vers.excludeFlag)
5019 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005020 }
Steven Valdez520e1222017-06-13 12:45:25 -04005021
5022 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5023
5024 if shimVers.tls13Variant != 0 {
5025 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5026 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5027 }
5028
5029 // Test configuring the runner's maximum version.
5030 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005031 expectedVersion := shimVers.version
5032 if runnerVers.version < shimVers.version {
5033 expectedVersion = runnerVers.version
5034 }
Steven Valdez520e1222017-06-13 12:45:25 -04005035 // When running and shim have different TLS 1.3 variants enabled,
5036 // shim clients are expected to fall back to TLS 1.2, while shim
5037 // servers support both variants when enabled when the experiment is
5038 // enabled.
5039 expectedServerVersion := expectedVersion
5040 expectedClientVersion := expectedVersion
5041 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5042 expectedClientVersion = VersionTLS12
5043 expectedServerVersion = VersionTLS12
5044 if shimVers.tls13Variant != TLS13Default {
5045 expectedServerVersion = VersionTLS13
5046 }
5047 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005048
David Benjamin8b8c0062014-11-23 02:47:52 -05005049 suffix := shimVers.name + "-" + runnerVers.name
5050 if protocol == dtls {
5051 suffix += "-DTLS"
5052 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005053
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005054 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005055 clientVers := shimVers.version
5056 if clientVers > VersionTLS10 {
5057 clientVers = VersionTLS10
5058 }
Steven Valdez520e1222017-06-13 12:45:25 -04005059 clientVers = recordVersionToWire(clientVers, protocol)
5060 serverVers := expectedServerVersion
5061 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005062 serverVers = VersionTLS10
5063 }
Steven Valdez520e1222017-06-13 12:45:25 -04005064 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005065
David Benjamin8b8c0062014-11-23 02:47:52 -05005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 testType: clientTest,
5069 name: "VersionNegotiation-Client-" + suffix,
5070 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005071 MaxVersion: runnerVers.version,
5072 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005073 Bugs: ProtocolBugs{
5074 ExpectInitialRecordVersion: clientVers,
5075 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005076 },
5077 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005078 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005079 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005080 testCases = append(testCases, testCase{
5081 protocol: protocol,
5082 testType: clientTest,
5083 name: "VersionNegotiation-Client2-" + suffix,
5084 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005085 MaxVersion: runnerVers.version,
5086 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005087 Bugs: ProtocolBugs{
5088 ExpectInitialRecordVersion: clientVers,
5089 },
5090 },
Steven Valdez520e1222017-06-13 12:45:25 -04005091 flags: flags2,
5092 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005093 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005094
5095 testCases = append(testCases, testCase{
5096 protocol: protocol,
5097 testType: serverTest,
5098 name: "VersionNegotiation-Server-" + suffix,
5099 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005100 MaxVersion: runnerVers.version,
5101 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005102 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005103 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005105 },
5106 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005107 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005108 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005109 testCases = append(testCases, testCase{
5110 protocol: protocol,
5111 testType: serverTest,
5112 name: "VersionNegotiation-Server2-" + suffix,
5113 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005114 MaxVersion: runnerVers.version,
5115 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005116 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005117 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005118 },
5119 },
Steven Valdez520e1222017-06-13 12:45:25 -04005120 flags: flags2,
5121 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005122 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005123 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005124 }
5125 }
David Benjamin95c69562016-06-29 18:15:03 -04005126
Steven Valdezfdd10992016-09-15 16:27:05 -04005127 // Test the version extension at all versions.
5128 for _, vers := range tlsVersions {
5129 protocols := []protocol{tls}
5130 if vers.hasDTLS {
5131 protocols = append(protocols, dtls)
5132 }
5133 for _, protocol := range protocols {
5134 suffix := vers.name
5135 if protocol == dtls {
5136 suffix += "-DTLS"
5137 }
5138
Steven Valdezfdd10992016-09-15 16:27:05 -04005139 testCases = append(testCases, testCase{
5140 protocol: protocol,
5141 testType: serverTest,
5142 name: "VersionNegotiationExtension-" + suffix,
5143 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005144 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005145 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005146 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005147 },
5148 },
5149 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005150 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005151 })
5152 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005153 }
5154
5155 // If all versions are unknown, negotiation fails.
5156 testCases = append(testCases, testCase{
5157 testType: serverTest,
5158 name: "NoSupportedVersions",
5159 config: Config{
5160 Bugs: ProtocolBugs{
5161 SendSupportedVersions: []uint16{0x1111},
5162 },
5163 },
5164 shouldFail: true,
5165 expectedError: ":UNSUPPORTED_PROTOCOL:",
5166 })
5167 testCases = append(testCases, testCase{
5168 protocol: dtls,
5169 testType: serverTest,
5170 name: "NoSupportedVersions-DTLS",
5171 config: Config{
5172 Bugs: ProtocolBugs{
5173 SendSupportedVersions: []uint16{0x1111},
5174 },
5175 },
5176 shouldFail: true,
5177 expectedError: ":UNSUPPORTED_PROTOCOL:",
5178 })
5179
5180 testCases = append(testCases, testCase{
5181 testType: serverTest,
5182 name: "ClientHelloVersionTooHigh",
5183 config: Config{
5184 MaxVersion: VersionTLS13,
5185 Bugs: ProtocolBugs{
5186 SendClientVersion: 0x0304,
5187 OmitSupportedVersions: true,
5188 },
5189 },
5190 expectedVersion: VersionTLS12,
5191 })
5192
5193 testCases = append(testCases, testCase{
5194 testType: serverTest,
5195 name: "ConflictingVersionNegotiation",
5196 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005197 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005198 SendClientVersion: VersionTLS12,
5199 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005200 },
5201 },
David Benjaminad75a662016-09-30 15:42:59 -04005202 // The extension takes precedence over the ClientHello version.
5203 expectedVersion: VersionTLS11,
5204 })
5205
5206 testCases = append(testCases, testCase{
5207 testType: serverTest,
5208 name: "ConflictingVersionNegotiation-2",
5209 config: Config{
5210 Bugs: ProtocolBugs{
5211 SendClientVersion: VersionTLS11,
5212 SendSupportedVersions: []uint16{VersionTLS12},
5213 },
5214 },
5215 // The extension takes precedence over the ClientHello version.
5216 expectedVersion: VersionTLS12,
5217 })
5218
5219 testCases = append(testCases, testCase{
5220 testType: serverTest,
5221 name: "RejectFinalTLS13",
5222 config: Config{
5223 Bugs: ProtocolBugs{
5224 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5225 },
5226 },
5227 // We currently implement a draft TLS 1.3 version. Ensure that
5228 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 expectedVersion: VersionTLS12,
5230 })
5231
Steven Valdez038da9b2017-07-10 12:57:25 -04005232 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5233 // the ServerHello.
5234 testCases = append(testCases, testCase{
5235 testType: clientTest,
5236 name: "SupportedVersionSelection-TLS12",
5237 config: Config{
5238 MaxVersion: VersionTLS12,
5239 Bugs: ProtocolBugs{
5240 SendServerSupportedExtensionVersion: VersionTLS12,
5241 },
5242 },
5243 shouldFail: true,
5244 expectedError: ":UNEXPECTED_EXTENSION:",
5245 })
5246
5247 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5248 // supported_versions extension in the ServerHello.
5249 testCases = append(testCases, testCase{
5250 testType: clientTest,
5251 name: "SupportedVersionSelection-TLS13",
5252 config: Config{
5253 MaxVersion: VersionTLS13,
5254 Bugs: ProtocolBugs{
5255 SendServerSupportedExtensionVersion: tls13DraftVersion,
5256 },
5257 },
5258 shouldFail: true,
5259 expectedError: ":UNEXPECTED_EXTENSION:",
5260 })
5261
Brian Smithf85d3232016-10-28 10:34:06 -10005262 // Test that the maximum version is selected regardless of the
5263 // client-sent order.
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "IgnoreClientVersionOrder",
5267 config: Config{
5268 Bugs: ProtocolBugs{
5269 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5270 },
5271 },
5272 expectedVersion: VersionTLS13,
5273 })
5274
David Benjamin95c69562016-06-29 18:15:03 -04005275 // Test for version tolerance.
5276 testCases = append(testCases, testCase{
5277 testType: serverTest,
5278 name: "MinorVersionTolerance",
5279 config: Config{
5280 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005281 SendClientVersion: 0x03ff,
5282 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005283 },
5284 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005285 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005286 })
5287 testCases = append(testCases, testCase{
5288 testType: serverTest,
5289 name: "MajorVersionTolerance",
5290 config: Config{
5291 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005292 SendClientVersion: 0x0400,
5293 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005294 },
5295 },
David Benjaminad75a662016-09-30 15:42:59 -04005296 // TLS 1.3 must be negotiated with the supported_versions
5297 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005298 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005299 })
David Benjaminad75a662016-09-30 15:42:59 -04005300 testCases = append(testCases, testCase{
5301 testType: serverTest,
5302 name: "VersionTolerance-TLS13",
5303 config: Config{
5304 Bugs: ProtocolBugs{
5305 // Although TLS 1.3 does not use
5306 // ClientHello.version, it still tolerates high
5307 // values there.
5308 SendClientVersion: 0x0400,
5309 },
5310 },
5311 expectedVersion: VersionTLS13,
5312 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005313
David Benjamin95c69562016-06-29 18:15:03 -04005314 testCases = append(testCases, testCase{
5315 protocol: dtls,
5316 testType: serverTest,
5317 name: "MinorVersionTolerance-DTLS",
5318 config: Config{
5319 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005320 SendClientVersion: 0xfe00,
5321 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005322 },
5323 },
5324 expectedVersion: VersionTLS12,
5325 })
5326 testCases = append(testCases, testCase{
5327 protocol: dtls,
5328 testType: serverTest,
5329 name: "MajorVersionTolerance-DTLS",
5330 config: Config{
5331 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005332 SendClientVersion: 0xfdff,
5333 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005334 },
5335 },
5336 expectedVersion: VersionTLS12,
5337 })
5338
5339 // Test that versions below 3.0 are rejected.
5340 testCases = append(testCases, testCase{
5341 testType: serverTest,
5342 name: "VersionTooLow",
5343 config: Config{
5344 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005345 SendClientVersion: 0x0200,
5346 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005347 },
5348 },
5349 shouldFail: true,
5350 expectedError: ":UNSUPPORTED_PROTOCOL:",
5351 })
5352 testCases = append(testCases, testCase{
5353 protocol: dtls,
5354 testType: serverTest,
5355 name: "VersionTooLow-DTLS",
5356 config: Config{
5357 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005358 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005359 },
5360 },
5361 shouldFail: true,
5362 expectedError: ":UNSUPPORTED_PROTOCOL:",
5363 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005364
David Benjamin2dc02042016-09-19 19:57:37 -04005365 testCases = append(testCases, testCase{
5366 name: "ServerBogusVersion",
5367 config: Config{
5368 Bugs: ProtocolBugs{
5369 SendServerHelloVersion: 0x1234,
5370 },
5371 },
5372 shouldFail: true,
5373 expectedError: ":UNSUPPORTED_PROTOCOL:",
5374 })
5375
David Benjamin1f61f0d2016-07-10 12:20:35 -04005376 // Test TLS 1.3's downgrade signal.
5377 testCases = append(testCases, testCase{
5378 name: "Downgrade-TLS12-Client",
5379 config: Config{
5380 Bugs: ProtocolBugs{
5381 NegotiateVersion: VersionTLS12,
5382 },
5383 },
David Benjamin592b5322016-09-30 15:15:01 -04005384 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005385 // TODO(davidben): This test should fail once TLS 1.3 is final
5386 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005387 })
5388 testCases = append(testCases, testCase{
5389 testType: serverTest,
5390 name: "Downgrade-TLS12-Server",
5391 config: Config{
5392 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005393 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005394 },
5395 },
David Benjamin592b5322016-09-30 15:15:01 -04005396 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005397 // TODO(davidben): This test should fail once TLS 1.3 is final
5398 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005399 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005400}
5401
David Benjaminaccb4542014-12-12 23:44:33 -05005402func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005403 for _, protocol := range []protocol{tls, dtls} {
5404 for _, shimVers := range allVersions(protocol) {
5405 // Assemble flags to disable all older versions on the shim.
5406 var flags []string
5407 for _, vers := range allVersions(protocol) {
5408 if vers.version < shimVers.version {
5409 flags = append(flags, vers.excludeFlag)
5410 }
David Benjaminaccb4542014-12-12 23:44:33 -05005411 }
Steven Valdez520e1222017-06-13 12:45:25 -04005412
5413 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5414
5415 if shimVers.tls13Variant != 0 {
5416 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5417 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5418 }
5419
5420 for _, runnerVers := range allVersions(protocol) {
5421 // Different TLS 1.3 variants are incompatible with each other and don't
5422 // produce consistent minimum versions.
5423 //
5424 // TODO(davidben): Fold these tests (the main value is in the
5425 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5426 // on intended shim behavior, not the shim + runner combination.
5427 if shimVers.tls13Variant != runnerVers.tls13Variant {
5428 continue
5429 }
5430
David Benjaminaccb4542014-12-12 23:44:33 -05005431 suffix := shimVers.name + "-" + runnerVers.name
5432 if protocol == dtls {
5433 suffix += "-DTLS"
5434 }
David Benjaminaccb4542014-12-12 23:44:33 -05005435
David Benjaminaccb4542014-12-12 23:44:33 -05005436 var expectedVersion uint16
5437 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005438 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005439 if runnerVers.version >= shimVers.version {
5440 expectedVersion = runnerVers.version
5441 } else {
5442 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005443 expectedError = ":UNSUPPORTED_PROTOCOL:"
5444 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005445 }
5446
5447 testCases = append(testCases, testCase{
5448 protocol: protocol,
5449 testType: clientTest,
5450 name: "MinimumVersion-Client-" + suffix,
5451 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005452 MaxVersion: runnerVers.version,
5453 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005454 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005455 // Ensure the server does not decline to
5456 // select a version (versions extension) or
5457 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005458 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005459 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005460 },
David Benjaminaccb4542014-12-12 23:44:33 -05005461 },
David Benjamin87909c02014-12-13 01:55:01 -05005462 flags: flags,
5463 expectedVersion: expectedVersion,
5464 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005465 expectedError: expectedError,
5466 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005467 })
5468 testCases = append(testCases, testCase{
5469 protocol: protocol,
5470 testType: clientTest,
5471 name: "MinimumVersion-Client2-" + suffix,
5472 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005473 MaxVersion: runnerVers.version,
5474 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005475 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005476 // Ensure the server does not decline to
5477 // select a version (versions extension) or
5478 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005479 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005480 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005481 },
David Benjaminaccb4542014-12-12 23:44:33 -05005482 },
Steven Valdez520e1222017-06-13 12:45:25 -04005483 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005484 expectedVersion: expectedVersion,
5485 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005486 expectedError: expectedError,
5487 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005488 })
5489
5490 testCases = append(testCases, testCase{
5491 protocol: protocol,
5492 testType: serverTest,
5493 name: "MinimumVersion-Server-" + suffix,
5494 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005495 MaxVersion: runnerVers.version,
5496 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005497 },
David Benjamin87909c02014-12-13 01:55:01 -05005498 flags: flags,
5499 expectedVersion: expectedVersion,
5500 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005501 expectedError: expectedError,
5502 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005503 })
5504 testCases = append(testCases, testCase{
5505 protocol: protocol,
5506 testType: serverTest,
5507 name: "MinimumVersion-Server2-" + suffix,
5508 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005509 MaxVersion: runnerVers.version,
5510 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005511 },
Steven Valdez520e1222017-06-13 12:45:25 -04005512 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005513 expectedVersion: expectedVersion,
5514 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005515 expectedError: expectedError,
5516 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005517 })
5518 }
5519 }
5520 }
5521}
5522
David Benjamine78bfde2014-09-06 12:45:15 -04005523func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005524 // TODO(davidben): Extensions, where applicable, all move their server
5525 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5526 // tests for both. Also test interaction with 0-RTT when implemented.
5527
David Benjamin97d17d92016-07-14 16:12:00 -04005528 // Repeat extensions tests all versions except SSL 3.0.
5529 for _, ver := range tlsVersions {
5530 if ver.version == VersionSSL30 {
5531 continue
5532 }
5533
David Benjamin97d17d92016-07-14 16:12:00 -04005534 // Test that duplicate extensions are rejected.
5535 testCases = append(testCases, testCase{
5536 testType: clientTest,
5537 name: "DuplicateExtensionClient-" + ver.name,
5538 config: Config{
5539 MaxVersion: ver.version,
5540 Bugs: ProtocolBugs{
5541 DuplicateExtension: true,
5542 },
David Benjamine78bfde2014-09-06 12:45:15 -04005543 },
David Benjamina5022392017-07-10 17:40:39 -04005544 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005545 shouldFail: true,
5546 expectedLocalError: "remote error: error decoding message",
5547 })
5548 testCases = append(testCases, testCase{
5549 testType: serverTest,
5550 name: "DuplicateExtensionServer-" + ver.name,
5551 config: Config{
5552 MaxVersion: ver.version,
5553 Bugs: ProtocolBugs{
5554 DuplicateExtension: true,
5555 },
David Benjamine78bfde2014-09-06 12:45:15 -04005556 },
David Benjamina5022392017-07-10 17:40:39 -04005557 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005558 shouldFail: true,
5559 expectedLocalError: "remote error: error decoding message",
5560 })
5561
5562 // Test SNI.
5563 testCases = append(testCases, testCase{
5564 testType: clientTest,
5565 name: "ServerNameExtensionClient-" + ver.name,
5566 config: Config{
5567 MaxVersion: ver.version,
5568 Bugs: ProtocolBugs{
5569 ExpectServerName: "example.com",
5570 },
David Benjamine78bfde2014-09-06 12:45:15 -04005571 },
David Benjamina5022392017-07-10 17:40:39 -04005572 tls13Variant: ver.tls13Variant,
5573 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005574 })
5575 testCases = append(testCases, testCase{
5576 testType: clientTest,
5577 name: "ServerNameExtensionClientMismatch-" + ver.name,
5578 config: Config{
5579 MaxVersion: ver.version,
5580 Bugs: ProtocolBugs{
5581 ExpectServerName: "mismatch.com",
5582 },
David Benjamine78bfde2014-09-06 12:45:15 -04005583 },
David Benjamin97d17d92016-07-14 16:12:00 -04005584 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005585 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005586 shouldFail: true,
5587 expectedLocalError: "tls: unexpected server name",
5588 })
5589 testCases = append(testCases, testCase{
5590 testType: clientTest,
5591 name: "ServerNameExtensionClientMissing-" + ver.name,
5592 config: Config{
5593 MaxVersion: ver.version,
5594 Bugs: ProtocolBugs{
5595 ExpectServerName: "missing.com",
5596 },
David Benjamine78bfde2014-09-06 12:45:15 -04005597 },
David Benjamina5022392017-07-10 17:40:39 -04005598 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005599 shouldFail: true,
5600 expectedLocalError: "tls: unexpected server name",
5601 })
5602 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005603 testType: clientTest,
5604 name: "TolerateServerNameAck-" + ver.name,
5605 config: Config{
5606 MaxVersion: ver.version,
5607 Bugs: ProtocolBugs{
5608 SendServerNameAck: true,
5609 },
5610 },
David Benjamina5022392017-07-10 17:40:39 -04005611 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005612 flags: []string{"-host-name", "example.com"},
5613 resumeSession: true,
5614 })
5615 testCases = append(testCases, testCase{
5616 testType: clientTest,
5617 name: "UnsolicitedServerNameAck-" + ver.name,
5618 config: Config{
5619 MaxVersion: ver.version,
5620 Bugs: ProtocolBugs{
5621 SendServerNameAck: true,
5622 },
5623 },
David Benjamina5022392017-07-10 17:40:39 -04005624 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005625 shouldFail: true,
5626 expectedError: ":UNEXPECTED_EXTENSION:",
5627 expectedLocalError: "remote error: unsupported extension",
5628 })
5629 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005630 testType: serverTest,
5631 name: "ServerNameExtensionServer-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005635 },
David Benjamina5022392017-07-10 17:40:39 -04005636 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005637 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005638 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005639 })
5640
5641 // Test ALPN.
5642 testCases = append(testCases, testCase{
5643 testType: clientTest,
5644 name: "ALPNClient-" + ver.name,
5645 config: Config{
5646 MaxVersion: ver.version,
5647 NextProtos: []string{"foo"},
5648 },
5649 flags: []string{
5650 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5651 "-expect-alpn", "foo",
5652 },
David Benjamina5022392017-07-10 17:40:39 -04005653 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005654 expectedNextProto: "foo",
5655 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005656 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005657 })
5658 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005659 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005660 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005661 config: Config{
5662 MaxVersion: ver.version,
5663 Bugs: ProtocolBugs{
5664 SendALPN: "baz",
5665 },
5666 },
5667 flags: []string{
5668 "-advertise-alpn", "\x03foo\x03bar",
5669 },
David Benjamina5022392017-07-10 17:40:39 -04005670 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005671 shouldFail: true,
5672 expectedError: ":INVALID_ALPN_PROTOCOL:",
5673 expectedLocalError: "remote error: illegal parameter",
5674 })
5675 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005676 testType: clientTest,
5677 name: "ALPNClient-AllowUnknown-" + ver.name,
5678 config: Config{
5679 MaxVersion: ver.version,
5680 Bugs: ProtocolBugs{
5681 SendALPN: "baz",
5682 },
5683 },
5684 flags: []string{
5685 "-advertise-alpn", "\x03foo\x03bar",
5686 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005687 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005688 },
David Benjamina5022392017-07-10 17:40:39 -04005689 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005690 })
5691 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005692 testType: serverTest,
5693 name: "ALPNServer-" + ver.name,
5694 config: Config{
5695 MaxVersion: ver.version,
5696 NextProtos: []string{"foo", "bar", "baz"},
5697 },
5698 flags: []string{
5699 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5700 "-select-alpn", "foo",
5701 },
David Benjamina5022392017-07-10 17:40:39 -04005702 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005703 expectedNextProto: "foo",
5704 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005705 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005706 })
5707 testCases = append(testCases, testCase{
5708 testType: serverTest,
5709 name: "ALPNServer-Decline-" + ver.name,
5710 config: Config{
5711 MaxVersion: ver.version,
5712 NextProtos: []string{"foo", "bar", "baz"},
5713 },
5714 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005715 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005716 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005717 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005718 })
5719
David Benjamin25fe85b2016-08-09 20:00:32 -04005720 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5721 // called once.
5722 testCases = append(testCases, testCase{
5723 testType: serverTest,
5724 name: "ALPNServer-Async-" + ver.name,
5725 config: Config{
5726 MaxVersion: ver.version,
5727 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005728 // Prior to TLS 1.3, exercise the asynchronous session callback.
5729 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005730 },
5731 flags: []string{
5732 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5733 "-select-alpn", "foo",
5734 "-async",
5735 },
David Benjamina5022392017-07-10 17:40:39 -04005736 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005737 expectedNextProto: "foo",
5738 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005739 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005740 })
5741
David Benjamin97d17d92016-07-14 16:12:00 -04005742 var emptyString string
5743 testCases = append(testCases, testCase{
5744 testType: clientTest,
5745 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5746 config: Config{
5747 MaxVersion: ver.version,
5748 NextProtos: []string{""},
5749 Bugs: ProtocolBugs{
5750 // A server returning an empty ALPN protocol
5751 // should be rejected.
5752 ALPNProtocol: &emptyString,
5753 },
5754 },
5755 flags: []string{
5756 "-advertise-alpn", "\x03foo",
5757 },
David Benjamina5022392017-07-10 17:40:39 -04005758 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005759 shouldFail: true,
5760 expectedError: ":PARSE_TLSEXT:",
5761 })
5762 testCases = append(testCases, testCase{
5763 testType: serverTest,
5764 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5765 config: Config{
5766 MaxVersion: ver.version,
5767 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005768 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005769 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005770 },
David Benjamin97d17d92016-07-14 16:12:00 -04005771 flags: []string{
5772 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005773 },
David Benjamina5022392017-07-10 17:40:39 -04005774 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005775 shouldFail: true,
5776 expectedError: ":PARSE_TLSEXT:",
5777 })
5778
5779 // Test NPN and the interaction with ALPN.
5780 if ver.version < VersionTLS13 {
5781 // Test that the server prefers ALPN over NPN.
5782 testCases = append(testCases, testCase{
5783 testType: serverTest,
5784 name: "ALPNServer-Preferred-" + ver.name,
5785 config: Config{
5786 MaxVersion: ver.version,
5787 NextProtos: []string{"foo", "bar", "baz"},
5788 },
5789 flags: []string{
5790 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5791 "-select-alpn", "foo",
5792 "-advertise-npn", "\x03foo\x03bar\x03baz",
5793 },
David Benjamina5022392017-07-10 17:40:39 -04005794 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005795 expectedNextProto: "foo",
5796 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005797 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005798 })
5799 testCases = append(testCases, testCase{
5800 testType: serverTest,
5801 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5802 config: Config{
5803 MaxVersion: ver.version,
5804 NextProtos: []string{"foo", "bar", "baz"},
5805 Bugs: ProtocolBugs{
5806 SwapNPNAndALPN: true,
5807 },
5808 },
5809 flags: []string{
5810 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5811 "-select-alpn", "foo",
5812 "-advertise-npn", "\x03foo\x03bar\x03baz",
5813 },
David Benjamina5022392017-07-10 17:40:39 -04005814 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005815 expectedNextProto: "foo",
5816 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005817 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005818 })
5819
5820 // Test that negotiating both NPN and ALPN is forbidden.
5821 testCases = append(testCases, testCase{
5822 name: "NegotiateALPNAndNPN-" + ver.name,
5823 config: Config{
5824 MaxVersion: ver.version,
5825 NextProtos: []string{"foo", "bar", "baz"},
5826 Bugs: ProtocolBugs{
5827 NegotiateALPNAndNPN: true,
5828 },
5829 },
5830 flags: []string{
5831 "-advertise-alpn", "\x03foo",
5832 "-select-next-proto", "foo",
5833 },
David Benjamina5022392017-07-10 17:40:39 -04005834 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005835 shouldFail: true,
5836 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5837 })
5838 testCases = append(testCases, testCase{
5839 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5840 config: Config{
5841 MaxVersion: ver.version,
5842 NextProtos: []string{"foo", "bar", "baz"},
5843 Bugs: ProtocolBugs{
5844 NegotiateALPNAndNPN: true,
5845 SwapNPNAndALPN: true,
5846 },
5847 },
5848 flags: []string{
5849 "-advertise-alpn", "\x03foo",
5850 "-select-next-proto", "foo",
5851 },
David Benjamina5022392017-07-10 17:40:39 -04005852 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005853 shouldFail: true,
5854 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5855 })
David Benjamin97d17d92016-07-14 16:12:00 -04005856 }
5857
5858 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005859
5860 // Resume with a corrupt ticket.
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "CorruptTicket-" + ver.name,
5864 config: Config{
5865 MaxVersion: ver.version,
5866 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005867 FilterTicket: func(in []byte) ([]byte, error) {
5868 in[len(in)-1] ^= 1
5869 return in, nil
5870 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005871 },
5872 },
David Benjamina5022392017-07-10 17:40:39 -04005873 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005874 resumeSession: true,
5875 expectResumeRejected: true,
5876 })
5877 // Test the ticket callback, with and without renewal.
5878 testCases = append(testCases, testCase{
5879 testType: serverTest,
5880 name: "TicketCallback-" + ver.name,
5881 config: Config{
5882 MaxVersion: ver.version,
5883 },
David Benjamina5022392017-07-10 17:40:39 -04005884 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005885 resumeSession: true,
5886 flags: []string{"-use-ticket-callback"},
5887 })
5888 testCases = append(testCases, testCase{
5889 testType: serverTest,
5890 name: "TicketCallback-Renew-" + ver.name,
5891 config: Config{
5892 MaxVersion: ver.version,
5893 Bugs: ProtocolBugs{
5894 ExpectNewTicket: true,
5895 },
5896 },
David Benjamina5022392017-07-10 17:40:39 -04005897 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005898 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5899 resumeSession: true,
5900 })
5901
5902 // Test that the ticket callback is only called once when everything before
5903 // it in the ClientHello is asynchronous. This corrupts the ticket so
5904 // certificate selection callbacks run.
5905 testCases = append(testCases, testCase{
5906 testType: serverTest,
5907 name: "TicketCallback-SingleCall-" + ver.name,
5908 config: Config{
5909 MaxVersion: ver.version,
5910 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005911 FilterTicket: func(in []byte) ([]byte, error) {
5912 in[len(in)-1] ^= 1
5913 return in, nil
5914 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005915 },
5916 },
David Benjamina5022392017-07-10 17:40:39 -04005917 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005918 resumeSession: true,
5919 expectResumeRejected: true,
5920 flags: []string{
5921 "-use-ticket-callback",
5922 "-async",
5923 },
5924 })
5925
David Benjamind4c349b2017-02-09 14:07:17 -05005926 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005927 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005928 testCases = append(testCases, testCase{
5929 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005930 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005931 config: Config{
5932 MaxVersion: ver.version,
5933 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005934 EmptyTicketSessionID: true,
5935 },
5936 },
5937 resumeSession: true,
5938 })
5939 testCases = append(testCases, testCase{
5940 testType: serverTest,
5941 name: "TicketSessionIDLength-16-" + ver.name,
5942 config: Config{
5943 MaxVersion: ver.version,
5944 Bugs: ProtocolBugs{
5945 TicketSessionIDLength: 16,
5946 },
5947 },
5948 resumeSession: true,
5949 })
5950 testCases = append(testCases, testCase{
5951 testType: serverTest,
5952 name: "TicketSessionIDLength-32-" + ver.name,
5953 config: Config{
5954 MaxVersion: ver.version,
5955 Bugs: ProtocolBugs{
5956 TicketSessionIDLength: 32,
5957 },
5958 },
5959 resumeSession: true,
5960 })
5961 testCases = append(testCases, testCase{
5962 testType: serverTest,
5963 name: "TicketSessionIDLength-33-" + ver.name,
5964 config: Config{
5965 MaxVersion: ver.version,
5966 Bugs: ProtocolBugs{
5967 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005968 },
5969 },
5970 resumeSession: true,
5971 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005972 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005973 expectedError: ":DECODE_ERROR:",
5974 })
5975 }
5976
5977 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5978 // are ignored.
5979 if ver.hasDTLS {
5980 testCases = append(testCases, testCase{
5981 protocol: dtls,
5982 name: "SRTP-Client-" + ver.name,
5983 config: Config{
5984 MaxVersion: ver.version,
5985 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5986 },
5987 flags: []string{
5988 "-srtp-profiles",
5989 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5990 },
5991 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5992 })
5993 testCases = append(testCases, testCase{
5994 protocol: dtls,
5995 testType: serverTest,
5996 name: "SRTP-Server-" + ver.name,
5997 config: Config{
5998 MaxVersion: ver.version,
5999 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6000 },
6001 flags: []string{
6002 "-srtp-profiles",
6003 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6004 },
6005 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6006 })
6007 // Test that the MKI is ignored.
6008 testCases = append(testCases, testCase{
6009 protocol: dtls,
6010 testType: serverTest,
6011 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6012 config: Config{
6013 MaxVersion: ver.version,
6014 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6015 Bugs: ProtocolBugs{
6016 SRTPMasterKeyIdentifer: "bogus",
6017 },
6018 },
6019 flags: []string{
6020 "-srtp-profiles",
6021 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6022 },
6023 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6024 })
6025 // Test that SRTP isn't negotiated on the server if there were
6026 // no matching profiles.
6027 testCases = append(testCases, testCase{
6028 protocol: dtls,
6029 testType: serverTest,
6030 name: "SRTP-Server-NoMatch-" + ver.name,
6031 config: Config{
6032 MaxVersion: ver.version,
6033 SRTPProtectionProfiles: []uint16{100, 101, 102},
6034 },
6035 flags: []string{
6036 "-srtp-profiles",
6037 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6038 },
6039 expectedSRTPProtectionProfile: 0,
6040 })
6041 // Test that the server returning an invalid SRTP profile is
6042 // flagged as an error by the client.
6043 testCases = append(testCases, testCase{
6044 protocol: dtls,
6045 name: "SRTP-Client-NoMatch-" + ver.name,
6046 config: Config{
6047 MaxVersion: ver.version,
6048 Bugs: ProtocolBugs{
6049 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6050 },
6051 },
6052 flags: []string{
6053 "-srtp-profiles",
6054 "SRTP_AES128_CM_SHA1_80",
6055 },
6056 shouldFail: true,
6057 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6058 })
6059 }
6060
6061 // Test SCT list.
6062 testCases = append(testCases, testCase{
6063 name: "SignedCertificateTimestampList-Client-" + ver.name,
6064 testType: clientTest,
6065 config: Config{
6066 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006067 },
David Benjamin97d17d92016-07-14 16:12:00 -04006068 flags: []string{
6069 "-enable-signed-cert-timestamps",
6070 "-expect-signed-cert-timestamps",
6071 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006072 },
David Benjamina5022392017-07-10 17:40:39 -04006073 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006074 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006075 })
David Benjamindaa88502016-10-04 16:32:16 -04006076
Adam Langleycfa08c32016-11-17 13:21:27 -08006077 var differentSCTList []byte
6078 differentSCTList = append(differentSCTList, testSCTList...)
6079 differentSCTList[len(differentSCTList)-1] ^= 1
6080
David Benjamindaa88502016-10-04 16:32:16 -04006081 // The SCT extension did not specify that it must only be sent on resumption as it
6082 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006083 testCases = append(testCases, testCase{
6084 name: "SendSCTListOnResume-" + ver.name,
6085 config: Config{
6086 MaxVersion: ver.version,
6087 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006088 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006089 },
David Benjamind98452d2015-06-16 14:16:23 -04006090 },
David Benjamin97d17d92016-07-14 16:12:00 -04006091 flags: []string{
6092 "-enable-signed-cert-timestamps",
6093 "-expect-signed-cert-timestamps",
6094 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006095 },
David Benjamina5022392017-07-10 17:40:39 -04006096 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006097 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006098 })
David Benjamindaa88502016-10-04 16:32:16 -04006099
David Benjamin97d17d92016-07-14 16:12:00 -04006100 testCases = append(testCases, testCase{
6101 name: "SignedCertificateTimestampList-Server-" + ver.name,
6102 testType: serverTest,
6103 config: Config{
6104 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006105 },
David Benjamin97d17d92016-07-14 16:12:00 -04006106 flags: []string{
6107 "-signed-cert-timestamps",
6108 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006109 },
David Benjamina5022392017-07-10 17:40:39 -04006110 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006111 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006112 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006113 })
David Benjamin53210cb2016-11-16 09:01:48 +09006114
Adam Langleycfa08c32016-11-17 13:21:27 -08006115 emptySCTListCert := *testCerts[0].cert
6116 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6117
6118 // Test empty SCT list.
6119 testCases = append(testCases, testCase{
6120 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6121 testType: clientTest,
6122 config: Config{
6123 MaxVersion: ver.version,
6124 Certificates: []Certificate{emptySCTListCert},
6125 },
6126 flags: []string{
6127 "-enable-signed-cert-timestamps",
6128 },
David Benjamina5022392017-07-10 17:40:39 -04006129 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006130 shouldFail: true,
6131 expectedError: ":ERROR_PARSING_EXTENSION:",
6132 })
6133
6134 emptySCTCert := *testCerts[0].cert
6135 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6136
6137 // Test empty SCT in non-empty list.
6138 testCases = append(testCases, testCase{
6139 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6140 testType: clientTest,
6141 config: Config{
6142 MaxVersion: ver.version,
6143 Certificates: []Certificate{emptySCTCert},
6144 },
6145 flags: []string{
6146 "-enable-signed-cert-timestamps",
6147 },
David Benjamina5022392017-07-10 17:40:39 -04006148 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006149 shouldFail: true,
6150 expectedError: ":ERROR_PARSING_EXTENSION:",
6151 })
6152
David Benjamin53210cb2016-11-16 09:01:48 +09006153 // Test that certificate-related extensions are not sent unsolicited.
6154 testCases = append(testCases, testCase{
6155 testType: serverTest,
6156 name: "UnsolicitedCertificateExtensions-" + ver.name,
6157 config: Config{
6158 MaxVersion: ver.version,
6159 Bugs: ProtocolBugs{
6160 NoOCSPStapling: true,
6161 NoSignedCertificateTimestamps: true,
6162 },
6163 },
David Benjamina5022392017-07-10 17:40:39 -04006164 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006165 flags: []string{
6166 "-ocsp-response",
6167 base64.StdEncoding.EncodeToString(testOCSPResponse),
6168 "-signed-cert-timestamps",
6169 base64.StdEncoding.EncodeToString(testSCTList),
6170 },
6171 })
David Benjamin97d17d92016-07-14 16:12:00 -04006172 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006173
Paul Lietar4fac72e2015-09-09 13:44:55 +01006174 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006175 testType: clientTest,
6176 name: "ClientHelloPadding",
6177 config: Config{
6178 Bugs: ProtocolBugs{
6179 RequireClientHelloSize: 512,
6180 },
6181 },
6182 // This hostname just needs to be long enough to push the
6183 // ClientHello into F5's danger zone between 256 and 511 bytes
6184 // long.
6185 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6186 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006187
6188 // Extensions should not function in SSL 3.0.
6189 testCases = append(testCases, testCase{
6190 testType: serverTest,
6191 name: "SSLv3Extensions-NoALPN",
6192 config: Config{
6193 MaxVersion: VersionSSL30,
6194 NextProtos: []string{"foo", "bar", "baz"},
6195 },
6196 flags: []string{
6197 "-select-alpn", "foo",
6198 },
6199 expectNoNextProto: true,
6200 })
6201
6202 // Test session tickets separately as they follow a different codepath.
6203 testCases = append(testCases, testCase{
6204 testType: serverTest,
6205 name: "SSLv3Extensions-NoTickets",
6206 config: Config{
6207 MaxVersion: VersionSSL30,
6208 Bugs: ProtocolBugs{
6209 // Historically, session tickets in SSL 3.0
6210 // failed in different ways depending on whether
6211 // the client supported renegotiation_info.
6212 NoRenegotiationInfo: true,
6213 },
6214 },
6215 resumeSession: true,
6216 })
6217 testCases = append(testCases, testCase{
6218 testType: serverTest,
6219 name: "SSLv3Extensions-NoTickets2",
6220 config: Config{
6221 MaxVersion: VersionSSL30,
6222 },
6223 resumeSession: true,
6224 })
6225
6226 // But SSL 3.0 does send and process renegotiation_info.
6227 testCases = append(testCases, testCase{
6228 testType: serverTest,
6229 name: "SSLv3Extensions-RenegotiationInfo",
6230 config: Config{
6231 MaxVersion: VersionSSL30,
6232 Bugs: ProtocolBugs{
6233 RequireRenegotiationInfo: true,
6234 },
6235 },
David Benjamind2610042017-01-03 10:49:28 -05006236 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006237 })
6238 testCases = append(testCases, testCase{
6239 testType: serverTest,
6240 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6241 config: Config{
6242 MaxVersion: VersionSSL30,
6243 Bugs: ProtocolBugs{
6244 NoRenegotiationInfo: true,
6245 SendRenegotiationSCSV: true,
6246 RequireRenegotiationInfo: true,
6247 },
6248 },
David Benjamind2610042017-01-03 10:49:28 -05006249 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006250 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006251
6252 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6253 // in ServerHello.
6254 testCases = append(testCases, testCase{
6255 name: "NPN-Forbidden-TLS13",
6256 config: Config{
6257 MaxVersion: VersionTLS13,
6258 NextProtos: []string{"foo"},
6259 Bugs: ProtocolBugs{
6260 NegotiateNPNAtAllVersions: true,
6261 },
6262 },
6263 flags: []string{"-select-next-proto", "foo"},
6264 shouldFail: true,
6265 expectedError: ":ERROR_PARSING_EXTENSION:",
6266 })
6267 testCases = append(testCases, testCase{
6268 name: "EMS-Forbidden-TLS13",
6269 config: Config{
6270 MaxVersion: VersionTLS13,
6271 Bugs: ProtocolBugs{
6272 NegotiateEMSAtAllVersions: true,
6273 },
6274 },
6275 shouldFail: true,
6276 expectedError: ":ERROR_PARSING_EXTENSION:",
6277 })
6278 testCases = append(testCases, testCase{
6279 name: "RenegotiationInfo-Forbidden-TLS13",
6280 config: Config{
6281 MaxVersion: VersionTLS13,
6282 Bugs: ProtocolBugs{
6283 NegotiateRenegotiationInfoAtAllVersions: true,
6284 },
6285 },
6286 shouldFail: true,
6287 expectedError: ":ERROR_PARSING_EXTENSION:",
6288 })
6289 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006290 name: "Ticket-Forbidden-TLS13",
6291 config: Config{
6292 MaxVersion: VersionTLS12,
6293 },
6294 resumeConfig: &Config{
6295 MaxVersion: VersionTLS13,
6296 Bugs: ProtocolBugs{
6297 AdvertiseTicketExtension: true,
6298 },
6299 },
6300 resumeSession: true,
6301 shouldFail: true,
6302 expectedError: ":ERROR_PARSING_EXTENSION:",
6303 })
6304
6305 // Test that illegal extensions in TLS 1.3 are declined by the server if
6306 // offered in ClientHello. The runner's server will fail if this occurs,
6307 // so we exercise the offering path. (EMS and Renegotiation Info are
6308 // implicit in every test.)
6309 testCases = append(testCases, testCase{
6310 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006311 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006312 config: Config{
6313 MaxVersion: VersionTLS13,
6314 NextProtos: []string{"bar"},
6315 },
6316 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6317 })
David Benjamin196df5b2016-09-21 16:23:27 -04006318
David Benjamindaa88502016-10-04 16:32:16 -04006319 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6320 // tolerated.
6321 testCases = append(testCases, testCase{
6322 name: "SendOCSPResponseOnResume-TLS12",
6323 config: Config{
6324 MaxVersion: VersionTLS12,
6325 Bugs: ProtocolBugs{
6326 SendOCSPResponseOnResume: []byte("bogus"),
6327 },
6328 },
6329 flags: []string{
6330 "-enable-ocsp-stapling",
6331 "-expect-ocsp-response",
6332 base64.StdEncoding.EncodeToString(testOCSPResponse),
6333 },
6334 resumeSession: true,
6335 })
6336
David Benjamindaa88502016-10-04 16:32:16 -04006337 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006338 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006339 config: Config{
6340 MaxVersion: VersionTLS13,
6341 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006342 SendExtensionOnCertificate: testOCSPExtension,
6343 },
6344 },
6345 shouldFail: true,
6346 expectedError: ":UNEXPECTED_EXTENSION:",
6347 })
6348
6349 testCases = append(testCases, testCase{
6350 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6351 config: Config{
6352 MaxVersion: VersionTLS13,
6353 Bugs: ProtocolBugs{
6354 SendExtensionOnCertificate: testSCTExtension,
6355 },
6356 },
6357 shouldFail: true,
6358 expectedError: ":UNEXPECTED_EXTENSION:",
6359 })
6360
6361 // Test that extensions on client certificates are never accepted.
6362 testCases = append(testCases, testCase{
6363 name: "SendExtensionOnClientCertificate-TLS13",
6364 testType: serverTest,
6365 config: Config{
6366 MaxVersion: VersionTLS13,
6367 Certificates: []Certificate{rsaCertificate},
6368 Bugs: ProtocolBugs{
6369 SendExtensionOnCertificate: testOCSPExtension,
6370 },
6371 },
6372 flags: []string{
6373 "-enable-ocsp-stapling",
6374 "-require-any-client-certificate",
6375 },
6376 shouldFail: true,
6377 expectedError: ":UNEXPECTED_EXTENSION:",
6378 })
6379
6380 testCases = append(testCases, testCase{
6381 name: "SendUnknownExtensionOnCertificate-TLS13",
6382 config: Config{
6383 MaxVersion: VersionTLS13,
6384 Bugs: ProtocolBugs{
6385 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6386 },
6387 },
6388 shouldFail: true,
6389 expectedError: ":UNEXPECTED_EXTENSION:",
6390 })
6391
Adam Langleycfa08c32016-11-17 13:21:27 -08006392 var differentSCTList []byte
6393 differentSCTList = append(differentSCTList, testSCTList...)
6394 differentSCTList[len(differentSCTList)-1] ^= 1
6395
Steven Valdeza833c352016-11-01 13:39:36 -04006396 // Test that extensions on intermediates are allowed but ignored.
6397 testCases = append(testCases, testCase{
6398 name: "IgnoreExtensionsOnIntermediates-TLS13",
6399 config: Config{
6400 MaxVersion: VersionTLS13,
6401 Certificates: []Certificate{rsaChainCertificate},
6402 Bugs: ProtocolBugs{
6403 // Send different values on the intermediate. This tests
6404 // the intermediate's extensions do not override the
6405 // leaf's.
6406 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006407 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006408 },
6409 },
6410 flags: []string{
6411 "-enable-ocsp-stapling",
6412 "-expect-ocsp-response",
6413 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006414 "-enable-signed-cert-timestamps",
6415 "-expect-signed-cert-timestamps",
6416 base64.StdEncoding.EncodeToString(testSCTList),
6417 },
6418 resumeSession: true,
6419 })
6420
6421 // Test that extensions are not sent on intermediates when configured
6422 // only for a leaf.
6423 testCases = append(testCases, testCase{
6424 testType: serverTest,
6425 name: "SendNoExtensionsOnIntermediate-TLS13",
6426 config: Config{
6427 MaxVersion: VersionTLS13,
6428 Bugs: ProtocolBugs{
6429 ExpectNoExtensionsOnIntermediate: true,
6430 },
6431 },
6432 flags: []string{
6433 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6434 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6435 "-ocsp-response",
6436 base64.StdEncoding.EncodeToString(testOCSPResponse),
6437 "-signed-cert-timestamps",
6438 base64.StdEncoding.EncodeToString(testSCTList),
6439 },
6440 })
6441
6442 // Test that extensions are not sent on client certificates.
6443 testCases = append(testCases, testCase{
6444 name: "SendNoClientCertificateExtensions-TLS13",
6445 config: Config{
6446 MaxVersion: VersionTLS13,
6447 ClientAuth: RequireAnyClientCert,
6448 },
6449 flags: []string{
6450 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6451 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6452 "-ocsp-response",
6453 base64.StdEncoding.EncodeToString(testOCSPResponse),
6454 "-signed-cert-timestamps",
6455 base64.StdEncoding.EncodeToString(testSCTList),
6456 },
6457 })
6458
6459 testCases = append(testCases, testCase{
6460 name: "SendDuplicateExtensionsOnCerts-TLS13",
6461 config: Config{
6462 MaxVersion: VersionTLS13,
6463 Bugs: ProtocolBugs{
6464 SendDuplicateCertExtensions: true,
6465 },
6466 },
6467 flags: []string{
6468 "-enable-ocsp-stapling",
6469 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006470 },
6471 resumeSession: true,
6472 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006473 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006474 })
Adam Langley9b885c52016-11-18 14:21:03 -08006475
6476 testCases = append(testCases, testCase{
6477 name: "SignedCertificateTimestampListInvalid-Server",
6478 testType: serverTest,
6479 flags: []string{
6480 "-signed-cert-timestamps",
6481 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6482 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006483 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006484 expectedError: ":INVALID_SCT_LIST:",
6485 })
David Benjamine78bfde2014-09-06 12:45:15 -04006486}
6487
David Benjamin01fe8202014-09-24 15:21:44 -04006488func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006489 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006490 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006491 // SSL 3.0 does not have tickets and TLS 1.3 does not
6492 // have session IDs, so skip their cross-resumption
6493 // tests.
6494 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6495 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6496 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006497 }
6498
David Benjamin8b8c0062014-11-23 02:47:52 -05006499 protocols := []protocol{tls}
6500 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6501 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006502 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006503 for _, protocol := range protocols {
6504 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6505 if protocol == dtls {
6506 suffix += "-DTLS"
6507 }
6508
Steven Valdez520e1222017-06-13 12:45:25 -04006509 // We can't resume across TLS 1.3 variants and error out earlier in the
6510 // session resumption.
6511 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6512 continue
6513 }
6514
David Benjaminece3de92015-03-16 18:02:20 -04006515 if sessionVers.version == resumeVers.version {
6516 testCases = append(testCases, testCase{
6517 protocol: protocol,
6518 name: "Resume-Client" + suffix,
6519 resumeSession: true,
6520 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006521 MaxVersion: sessionVers.version,
6522 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006523 Bugs: ProtocolBugs{
6524 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6525 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6526 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006527 },
David Benjaminece3de92015-03-16 18:02:20 -04006528 expectedVersion: sessionVers.version,
6529 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006530 flags: []string{
6531 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6532 },
David Benjaminece3de92015-03-16 18:02:20 -04006533 })
6534 } else {
David Benjamin405da482016-08-08 17:25:07 -04006535 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6536
6537 // Offering a TLS 1.3 session sends an empty session ID, so
6538 // there is no way to convince a non-lookahead client the
6539 // session was resumed. It will appear to the client that a
6540 // stray ChangeCipherSpec was sent.
6541 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6542 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006543 }
6544
David Benjaminece3de92015-03-16 18:02:20 -04006545 testCases = append(testCases, testCase{
6546 protocol: protocol,
6547 name: "Resume-Client-Mismatch" + suffix,
6548 resumeSession: true,
6549 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006550 MaxVersion: sessionVers.version,
6551 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006552 },
David Benjaminece3de92015-03-16 18:02:20 -04006553 expectedVersion: sessionVers.version,
6554 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006555 MaxVersion: resumeVers.version,
6556 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006557 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006558 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006559 },
6560 },
6561 expectedResumeVersion: resumeVers.version,
6562 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006563 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006564 flags: []string{
6565 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6566 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6567 },
David Benjaminece3de92015-03-16 18:02:20 -04006568 })
6569 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006570
6571 testCases = append(testCases, testCase{
6572 protocol: protocol,
6573 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006574 resumeSession: true,
6575 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006576 MaxVersion: sessionVers.version,
6577 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006578 },
6579 expectedVersion: sessionVers.version,
6580 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006581 MaxVersion: resumeVers.version,
6582 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006583 },
6584 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006585 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006586 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006587 flags: []string{
6588 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6589 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6590 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006591 })
6592
David Benjamin8b8c0062014-11-23 02:47:52 -05006593 testCases = append(testCases, testCase{
6594 protocol: protocol,
6595 testType: serverTest,
6596 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006597 resumeSession: true,
6598 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006599 MaxVersion: sessionVers.version,
6600 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006601 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006602 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006603 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006604 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006605 MaxVersion: resumeVers.version,
6606 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006607 Bugs: ProtocolBugs{
6608 SendBothTickets: true,
6609 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006610 },
6611 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006612 flags: []string{
6613 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6614 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6615 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006616 })
6617 }
David Benjamin01fe8202014-09-24 15:21:44 -04006618 }
6619 }
David Benjaminece3de92015-03-16 18:02:20 -04006620
David Benjamin4199b0d2016-11-01 13:58:25 -04006621 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006622 testCases = append(testCases, testCase{
6623 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006624 name: "ShimTicketRewritable",
6625 resumeSession: true,
6626 config: Config{
6627 MaxVersion: VersionTLS12,
6628 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6629 Bugs: ProtocolBugs{
6630 FilterTicket: func(in []byte) ([]byte, error) {
6631 in, err := SetShimTicketVersion(in, VersionTLS12)
6632 if err != nil {
6633 return nil, err
6634 }
6635 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6636 },
6637 },
6638 },
6639 flags: []string{
6640 "-ticket-key",
6641 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6642 },
6643 })
6644
6645 // Resumptions are declined if the version does not match.
6646 testCases = append(testCases, testCase{
6647 testType: serverTest,
6648 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006649 resumeSession: true,
6650 config: Config{
6651 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006652 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006653 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006654 FilterTicket: func(in []byte) ([]byte, error) {
6655 return SetShimTicketVersion(in, VersionTLS13)
6656 },
6657 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006658 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006659 flags: []string{
6660 "-ticket-key",
6661 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6662 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006663 expectResumeRejected: true,
6664 })
6665
6666 testCases = append(testCases, testCase{
6667 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006668 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006669 resumeSession: true,
6670 config: Config{
6671 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006672 Bugs: ProtocolBugs{
6673 FilterTicket: func(in []byte) ([]byte, error) {
6674 return SetShimTicketVersion(in, VersionTLS12)
6675 },
6676 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006677 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006678 flags: []string{
6679 "-ticket-key",
6680 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6681 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006682 expectResumeRejected: true,
6683 })
6684
David Benjamin4199b0d2016-11-01 13:58:25 -04006685 // Resumptions are declined if the cipher is invalid or disabled.
6686 testCases = append(testCases, testCase{
6687 testType: serverTest,
6688 name: "Resume-Server-DeclineBadCipher",
6689 resumeSession: true,
6690 config: Config{
6691 MaxVersion: VersionTLS12,
6692 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006693 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006694 FilterTicket: func(in []byte) ([]byte, error) {
6695 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6696 },
6697 },
6698 },
6699 flags: []string{
6700 "-ticket-key",
6701 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6702 },
6703 expectResumeRejected: true,
6704 })
6705
6706 testCases = append(testCases, testCase{
6707 testType: serverTest,
6708 name: "Resume-Server-DeclineBadCipher-2",
6709 resumeSession: true,
6710 config: Config{
6711 MaxVersion: VersionTLS12,
6712 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006713 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006714 FilterTicket: func(in []byte) ([]byte, error) {
6715 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6716 },
6717 },
6718 },
6719 flags: []string{
6720 "-cipher", "AES128",
6721 "-ticket-key",
6722 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6723 },
6724 expectResumeRejected: true,
6725 })
6726
David Benjaminf01f42a2016-11-16 19:05:33 +09006727 // Sessions are not resumed if they do not use the preferred cipher.
6728 testCases = append(testCases, testCase{
6729 testType: serverTest,
6730 name: "Resume-Server-CipherNotPreferred",
6731 resumeSession: true,
6732 config: Config{
6733 MaxVersion: VersionTLS12,
6734 Bugs: ProtocolBugs{
6735 ExpectNewTicket: true,
6736 FilterTicket: func(in []byte) ([]byte, error) {
6737 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6738 },
6739 },
6740 },
6741 flags: []string{
6742 "-ticket-key",
6743 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6744 },
6745 shouldFail: false,
6746 expectResumeRejected: true,
6747 })
6748
6749 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6750 // PRF hashes match, but BoringSSL will always decline such resumptions.
6751 testCases = append(testCases, testCase{
6752 testType: serverTest,
6753 name: "Resume-Server-CipherNotPreferred-TLS13",
6754 resumeSession: true,
6755 config: Config{
6756 MaxVersion: VersionTLS13,
6757 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6758 Bugs: ProtocolBugs{
6759 FilterTicket: func(in []byte) ([]byte, error) {
6760 // If the client (runner) offers ChaCha20-Poly1305 first, the
6761 // server (shim) always prefers it. Switch it to AES-GCM.
6762 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6763 },
6764 },
6765 },
6766 flags: []string{
6767 "-ticket-key",
6768 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6769 },
6770 shouldFail: false,
6771 expectResumeRejected: true,
6772 })
6773
6774 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006775 testCases = append(testCases, testCase{
6776 testType: serverTest,
6777 name: "Resume-Server-DeclineBadCipher-TLS13",
6778 resumeSession: true,
6779 config: Config{
6780 MaxVersion: VersionTLS13,
6781 Bugs: ProtocolBugs{
6782 FilterTicket: func(in []byte) ([]byte, error) {
6783 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6784 },
6785 },
6786 },
6787 flags: []string{
6788 "-ticket-key",
6789 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6790 },
6791 expectResumeRejected: true,
6792 })
6793
David Benjaminf01f42a2016-11-16 19:05:33 +09006794 // If the client does not offer the cipher from the session, decline to
6795 // resume. Clients are forbidden from doing this, but BoringSSL selects
6796 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006797 testCases = append(testCases, testCase{
6798 testType: serverTest,
6799 name: "Resume-Server-UnofferedCipher",
6800 resumeSession: true,
6801 config: Config{
6802 MaxVersion: VersionTLS12,
6803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6804 },
6805 resumeConfig: &Config{
6806 MaxVersion: VersionTLS12,
6807 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6808 Bugs: ProtocolBugs{
6809 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6810 },
6811 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006812 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006813 })
6814
David Benjaminf01f42a2016-11-16 19:05:33 +09006815 // In TLS 1.3, clients may advertise a cipher list which does not
6816 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006817 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6818 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "Resume-Server-UnofferedCipher-TLS13",
6822 resumeSession: true,
6823 config: Config{
6824 MaxVersion: VersionTLS13,
6825 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6826 },
6827 resumeConfig: &Config{
6828 MaxVersion: VersionTLS13,
6829 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6830 Bugs: ProtocolBugs{
6831 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6832 },
6833 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006834 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006835 })
6836
David Benjamin4199b0d2016-11-01 13:58:25 -04006837 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006838 testCases = append(testCases, testCase{
6839 name: "Resume-Client-CipherMismatch",
6840 resumeSession: true,
6841 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006842 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006843 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6844 },
6845 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006846 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006847 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6848 Bugs: ProtocolBugs{
6849 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6850 },
6851 },
6852 shouldFail: true,
6853 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6854 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006855
David Benjamine1cc35e2016-11-16 16:25:58 +09006856 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6857 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006858 testCases = append(testCases, testCase{
6859 name: "Resume-Client-CipherMismatch-TLS13",
6860 resumeSession: true,
6861 config: Config{
6862 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006863 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006864 },
6865 resumeConfig: &Config{
6866 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006867 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6868 },
6869 })
6870
6871 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6872 testCases = append(testCases, testCase{
6873 name: "Resume-Client-PRFMismatch-TLS13",
6874 resumeSession: true,
6875 config: Config{
6876 MaxVersion: VersionTLS13,
6877 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6878 },
6879 resumeConfig: &Config{
6880 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006881 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006882 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006883 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006884 },
6885 },
6886 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006887 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006888 })
Steven Valdeza833c352016-11-01 13:39:36 -04006889
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: "Resume-Server-BinderWrongLength",
6893 resumeSession: true,
6894 config: Config{
6895 MaxVersion: VersionTLS13,
6896 Bugs: ProtocolBugs{
6897 SendShortPSKBinder: true,
6898 },
6899 },
6900 shouldFail: true,
6901 expectedLocalError: "remote error: error decrypting message",
6902 expectedError: ":DIGEST_CHECK_FAILED:",
6903 })
6904
6905 testCases = append(testCases, testCase{
6906 testType: serverTest,
6907 name: "Resume-Server-NoPSKBinder",
6908 resumeSession: true,
6909 config: Config{
6910 MaxVersion: VersionTLS13,
6911 Bugs: ProtocolBugs{
6912 SendNoPSKBinder: true,
6913 },
6914 },
6915 shouldFail: true,
6916 expectedLocalError: "remote error: error decoding message",
6917 expectedError: ":DECODE_ERROR:",
6918 })
6919
6920 testCases = append(testCases, testCase{
6921 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006922 name: "Resume-Server-ExtraPSKBinder",
6923 resumeSession: true,
6924 config: Config{
6925 MaxVersion: VersionTLS13,
6926 Bugs: ProtocolBugs{
6927 SendExtraPSKBinder: true,
6928 },
6929 },
6930 shouldFail: true,
6931 expectedLocalError: "remote error: illegal parameter",
6932 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6933 })
6934
6935 testCases = append(testCases, testCase{
6936 testType: serverTest,
6937 name: "Resume-Server-ExtraIdentityNoBinder",
6938 resumeSession: true,
6939 config: Config{
6940 MaxVersion: VersionTLS13,
6941 Bugs: ProtocolBugs{
6942 ExtraPSKIdentity: true,
6943 },
6944 },
6945 shouldFail: true,
6946 expectedLocalError: "remote error: illegal parameter",
6947 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6948 })
6949
6950 testCases = append(testCases, testCase{
6951 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006952 name: "Resume-Server-InvalidPSKBinder",
6953 resumeSession: true,
6954 config: Config{
6955 MaxVersion: VersionTLS13,
6956 Bugs: ProtocolBugs{
6957 SendInvalidPSKBinder: true,
6958 },
6959 },
6960 shouldFail: true,
6961 expectedLocalError: "remote error: error decrypting message",
6962 expectedError: ":DIGEST_CHECK_FAILED:",
6963 })
6964
6965 testCases = append(testCases, testCase{
6966 testType: serverTest,
6967 name: "Resume-Server-PSKBinderFirstExtension",
6968 resumeSession: true,
6969 config: Config{
6970 MaxVersion: VersionTLS13,
6971 Bugs: ProtocolBugs{
6972 PSKBinderFirst: true,
6973 },
6974 },
6975 shouldFail: true,
6976 expectedLocalError: "remote error: illegal parameter",
6977 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6978 })
David Benjamin01fe8202014-09-24 15:21:44 -04006979}
6980
Adam Langley2ae77d22014-10-28 17:29:33 -07006981func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006982 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006983 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006984 testType: serverTest,
6985 name: "Renegotiate-Server-Forbidden",
6986 config: Config{
6987 MaxVersion: VersionTLS12,
6988 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006989 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006990 shouldFail: true,
6991 expectedError: ":NO_RENEGOTIATION:",
6992 expectedLocalError: "remote error: no renegotiation",
6993 })
Adam Langley5021b222015-06-12 18:27:58 -07006994 // The server shouldn't echo the renegotiation extension unless
6995 // requested by the client.
6996 testCases = append(testCases, testCase{
6997 testType: serverTest,
6998 name: "Renegotiate-Server-NoExt",
6999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007001 Bugs: ProtocolBugs{
7002 NoRenegotiationInfo: true,
7003 RequireRenegotiationInfo: true,
7004 },
7005 },
7006 shouldFail: true,
7007 expectedLocalError: "renegotiation extension missing",
7008 })
7009 // The renegotiation SCSV should be sufficient for the server to echo
7010 // the extension.
7011 testCases = append(testCases, testCase{
7012 testType: serverTest,
7013 name: "Renegotiate-Server-NoExt-SCSV",
7014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007015 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007016 Bugs: ProtocolBugs{
7017 NoRenegotiationInfo: true,
7018 SendRenegotiationSCSV: true,
7019 RequireRenegotiationInfo: true,
7020 },
7021 },
7022 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007023 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007024 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007026 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007027 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007028 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007029 },
7030 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007031 renegotiate: 1,
7032 flags: []string{
7033 "-renegotiate-freely",
7034 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007035 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007036 },
David Benjamincdea40c2015-03-19 14:09:43 -04007037 })
7038 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007039 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007040 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007042 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007043 Bugs: ProtocolBugs{
7044 EmptyRenegotiationInfo: true,
7045 },
7046 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007047 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007048 shouldFail: true,
7049 expectedError: ":RENEGOTIATION_MISMATCH:",
7050 })
7051 testCases = append(testCases, testCase{
7052 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007053 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007055 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007056 Bugs: ProtocolBugs{
7057 BadRenegotiationInfo: true,
7058 },
7059 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007060 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007061 shouldFail: true,
7062 expectedError: ":RENEGOTIATION_MISMATCH:",
7063 })
7064 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007065 name: "Renegotiate-Client-BadExt2",
7066 renegotiate: 1,
7067 config: Config{
7068 MaxVersion: VersionTLS12,
7069 Bugs: ProtocolBugs{
7070 BadRenegotiationInfoEnd: true,
7071 },
7072 },
7073 flags: []string{"-renegotiate-freely"},
7074 shouldFail: true,
7075 expectedError: ":RENEGOTIATION_MISMATCH:",
7076 })
7077 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007078 name: "Renegotiate-Client-Downgrade",
7079 renegotiate: 1,
7080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007081 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007082 Bugs: ProtocolBugs{
7083 NoRenegotiationInfoAfterInitial: true,
7084 },
7085 },
7086 flags: []string{"-renegotiate-freely"},
7087 shouldFail: true,
7088 expectedError: ":RENEGOTIATION_MISMATCH:",
7089 })
7090 testCases = append(testCases, testCase{
7091 name: "Renegotiate-Client-Upgrade",
7092 renegotiate: 1,
7093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007094 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007095 Bugs: ProtocolBugs{
7096 NoRenegotiationInfoInInitial: true,
7097 },
7098 },
7099 flags: []string{"-renegotiate-freely"},
7100 shouldFail: true,
7101 expectedError: ":RENEGOTIATION_MISMATCH:",
7102 })
7103 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007104 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007105 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007107 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007108 Bugs: ProtocolBugs{
7109 NoRenegotiationInfo: true,
7110 },
7111 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007112 flags: []string{
7113 "-renegotiate-freely",
7114 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007115 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007116 },
David Benjamincff0b902015-05-15 23:09:47 -04007117 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007118
7119 // Test that the server may switch ciphers on renegotiation without
7120 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007121 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007122 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007123 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007124 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007125 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007126 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 },
7128 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007129 flags: []string{
7130 "-renegotiate-freely",
7131 "-expect-total-renegotiations", "1",
7132 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007133 })
7134 testCases = append(testCases, testCase{
7135 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007136 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007137 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007138 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007139 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7140 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007141 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007142 flags: []string{
7143 "-renegotiate-freely",
7144 "-expect-total-renegotiations", "1",
7145 },
David Benjaminb16346b2015-04-08 19:16:58 -04007146 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007147
7148 // Test that the server may not switch versions on renegotiation.
7149 testCases = append(testCases, testCase{
7150 name: "Renegotiate-Client-SwitchVersion",
7151 config: Config{
7152 MaxVersion: VersionTLS12,
7153 // Pick a cipher which exists at both versions.
7154 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7155 Bugs: ProtocolBugs{
7156 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007157 // Avoid failing early at the record layer.
7158 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007159 },
7160 },
7161 renegotiate: 1,
7162 flags: []string{
7163 "-renegotiate-freely",
7164 "-expect-total-renegotiations", "1",
7165 },
7166 shouldFail: true,
7167 expectedError: ":WRONG_SSL_VERSION:",
7168 })
7169
David Benjaminb16346b2015-04-08 19:16:58 -04007170 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007171 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007172 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007173 config: Config{
7174 MaxVersion: VersionTLS10,
7175 Bugs: ProtocolBugs{
7176 RequireSameRenegoClientVersion: true,
7177 },
7178 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007179 flags: []string{
7180 "-renegotiate-freely",
7181 "-expect-total-renegotiations", "1",
7182 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007183 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007184 testCases = append(testCases, testCase{
7185 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007186 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007187 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007188 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007189 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7190 NextProtos: []string{"foo"},
7191 },
7192 flags: []string{
7193 "-false-start",
7194 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007195 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007196 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007197 },
7198 shimWritesFirst: true,
7199 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007200
7201 // Client-side renegotiation controls.
7202 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007203 name: "Renegotiate-Client-Forbidden-1",
7204 config: Config{
7205 MaxVersion: VersionTLS12,
7206 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007207 renegotiate: 1,
7208 shouldFail: true,
7209 expectedError: ":NO_RENEGOTIATION:",
7210 expectedLocalError: "remote error: no renegotiation",
7211 })
7212 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007213 name: "Renegotiate-Client-Once-1",
7214 config: Config{
7215 MaxVersion: VersionTLS12,
7216 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007217 renegotiate: 1,
7218 flags: []string{
7219 "-renegotiate-once",
7220 "-expect-total-renegotiations", "1",
7221 },
7222 })
7223 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007224 name: "Renegotiate-Client-Freely-1",
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007228 renegotiate: 1,
7229 flags: []string{
7230 "-renegotiate-freely",
7231 "-expect-total-renegotiations", "1",
7232 },
7233 })
7234 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007235 name: "Renegotiate-Client-Once-2",
7236 config: Config{
7237 MaxVersion: VersionTLS12,
7238 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007239 renegotiate: 2,
7240 flags: []string{"-renegotiate-once"},
7241 shouldFail: true,
7242 expectedError: ":NO_RENEGOTIATION:",
7243 expectedLocalError: "remote error: no renegotiation",
7244 })
7245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007246 name: "Renegotiate-Client-Freely-2",
7247 config: Config{
7248 MaxVersion: VersionTLS12,
7249 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007250 renegotiate: 2,
7251 flags: []string{
7252 "-renegotiate-freely",
7253 "-expect-total-renegotiations", "2",
7254 },
7255 })
Adam Langley27a0d082015-11-03 13:34:10 -08007256 testCases = append(testCases, testCase{
7257 name: "Renegotiate-Client-NoIgnore",
7258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007259 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007260 Bugs: ProtocolBugs{
7261 SendHelloRequestBeforeEveryAppDataRecord: true,
7262 },
7263 },
7264 shouldFail: true,
7265 expectedError: ":NO_RENEGOTIATION:",
7266 })
7267 testCases = append(testCases, testCase{
7268 name: "Renegotiate-Client-Ignore",
7269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007270 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007271 Bugs: ProtocolBugs{
7272 SendHelloRequestBeforeEveryAppDataRecord: true,
7273 },
7274 },
7275 flags: []string{
7276 "-renegotiate-ignore",
7277 "-expect-total-renegotiations", "0",
7278 },
7279 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007280
David Benjamin34941c02016-10-08 11:45:31 -04007281 // Renegotiation is not allowed at SSL 3.0.
7282 testCases = append(testCases, testCase{
7283 name: "Renegotiate-Client-SSL3",
7284 config: Config{
7285 MaxVersion: VersionSSL30,
7286 },
7287 renegotiate: 1,
7288 flags: []string{
7289 "-renegotiate-freely",
7290 "-expect-total-renegotiations", "1",
7291 },
7292 shouldFail: true,
7293 expectedError: ":NO_RENEGOTIATION:",
7294 expectedLocalError: "remote error: no renegotiation",
7295 })
7296
David Benjamina1eaba12017-01-01 23:19:22 -05007297 // Renegotiation is not allowed when there is an unfinished write.
7298 testCases = append(testCases, testCase{
7299 name: "Renegotiate-Client-UnfinishedWrite",
7300 config: Config{
7301 MaxVersion: VersionTLS12,
7302 },
David Benjaminbbba9392017-04-06 12:54:12 -04007303 renegotiate: 1,
7304 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007305 flags: []string{
7306 "-async",
7307 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007308 },
7309 shouldFail: true,
7310 expectedError: ":NO_RENEGOTIATION:",
7311 // We do not successfully send the no_renegotiation alert in
7312 // this case. https://crbug.com/boringssl/130
7313 })
7314
David Benjamin07ab5d42017-02-09 20:11:41 -05007315 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007316 testCases = append(testCases, testCase{
7317 name: "StrayHelloRequest",
7318 config: Config{
7319 MaxVersion: VersionTLS12,
7320 Bugs: ProtocolBugs{
7321 SendHelloRequestBeforeEveryHandshakeMessage: true,
7322 },
7323 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007324 shouldFail: true,
7325 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007326 })
7327 testCases = append(testCases, testCase{
7328 name: "StrayHelloRequest-Packed",
7329 config: Config{
7330 MaxVersion: VersionTLS12,
7331 Bugs: ProtocolBugs{
7332 PackHandshakeFlight: true,
7333 SendHelloRequestBeforeEveryHandshakeMessage: true,
7334 },
7335 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007336 shouldFail: true,
7337 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007338 })
7339
David Benjamin12d2c482016-07-24 10:56:51 -04007340 // Test renegotiation works if HelloRequest and server Finished come in
7341 // the same record.
7342 testCases = append(testCases, testCase{
7343 name: "Renegotiate-Client-Packed",
7344 config: Config{
7345 MaxVersion: VersionTLS12,
7346 Bugs: ProtocolBugs{
7347 PackHandshakeFlight: true,
7348 PackHelloRequestWithFinished: true,
7349 },
7350 },
7351 renegotiate: 1,
7352 flags: []string{
7353 "-renegotiate-freely",
7354 "-expect-total-renegotiations", "1",
7355 },
7356 })
7357
David Benjamin397c8e62016-07-08 14:14:36 -07007358 // Renegotiation is forbidden in TLS 1.3.
7359 testCases = append(testCases, testCase{
7360 name: "Renegotiate-Client-TLS13",
7361 config: Config{
7362 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007363 Bugs: ProtocolBugs{
7364 SendHelloRequestBeforeEveryAppDataRecord: true,
7365 },
David Benjamin397c8e62016-07-08 14:14:36 -07007366 },
David Benjamin397c8e62016-07-08 14:14:36 -07007367 flags: []string{
7368 "-renegotiate-freely",
7369 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007370 shouldFail: true,
7371 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007372 })
7373
7374 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7375 testCases = append(testCases, testCase{
7376 name: "StrayHelloRequest-TLS13",
7377 config: Config{
7378 MaxVersion: VersionTLS13,
7379 Bugs: ProtocolBugs{
7380 SendHelloRequestBeforeEveryHandshakeMessage: true,
7381 },
7382 },
7383 shouldFail: true,
7384 expectedError: ":UNEXPECTED_MESSAGE:",
7385 })
David Benjamind2610042017-01-03 10:49:28 -05007386
7387 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7388 // always reads as supporting it, regardless of whether it was
7389 // negotiated.
7390 testCases = append(testCases, testCase{
7391 name: "AlwaysReportRenegotiationInfo-TLS13",
7392 config: Config{
7393 MaxVersion: VersionTLS13,
7394 Bugs: ProtocolBugs{
7395 NoRenegotiationInfo: true,
7396 },
7397 },
7398 flags: []string{
7399 "-expect-secure-renegotiation",
7400 },
7401 })
David Benjamina58baaf2017-02-28 20:54:28 -05007402
7403 // Certificates may not change on renegotiation.
7404 testCases = append(testCases, testCase{
7405 name: "Renegotiation-CertificateChange",
7406 config: Config{
7407 MaxVersion: VersionTLS12,
7408 Certificates: []Certificate{rsaCertificate},
7409 Bugs: ProtocolBugs{
7410 RenegotiationCertificate: &rsaChainCertificate,
7411 },
7412 },
7413 renegotiate: 1,
7414 flags: []string{"-renegotiate-freely"},
7415 shouldFail: true,
7416 expectedError: ":SERVER_CERT_CHANGED:",
7417 })
7418 testCases = append(testCases, testCase{
7419 name: "Renegotiation-CertificateChange-2",
7420 config: Config{
7421 MaxVersion: VersionTLS12,
7422 Certificates: []Certificate{rsaCertificate},
7423 Bugs: ProtocolBugs{
7424 RenegotiationCertificate: &rsa1024Certificate,
7425 },
7426 },
7427 renegotiate: 1,
7428 flags: []string{"-renegotiate-freely"},
7429 shouldFail: true,
7430 expectedError: ":SERVER_CERT_CHANGED:",
7431 })
David Benjaminbbf42462017-03-14 21:27:10 -04007432
7433 // We do not negotiate ALPN after the initial handshake. This is
7434 // error-prone and only risks bugs in consumers.
7435 testCases = append(testCases, testCase{
7436 testType: clientTest,
7437 name: "Renegotiation-ForbidALPN",
7438 config: Config{
7439 MaxVersion: VersionTLS12,
7440 Bugs: ProtocolBugs{
7441 // Forcibly negotiate ALPN on both initial and
7442 // renegotiation handshakes. The test stack will
7443 // internally check the client does not offer
7444 // it.
7445 SendALPN: "foo",
7446 },
7447 },
7448 flags: []string{
7449 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7450 "-expect-alpn", "foo",
7451 "-renegotiate-freely",
7452 },
7453 renegotiate: 1,
7454 shouldFail: true,
7455 expectedError: ":UNEXPECTED_EXTENSION:",
7456 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007457}
7458
David Benjamin5e961c12014-11-07 01:48:35 -05007459func addDTLSReplayTests() {
7460 // Test that sequence number replays are detected.
7461 testCases = append(testCases, testCase{
7462 protocol: dtls,
7463 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007464 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007465 replayWrites: true,
7466 })
7467
David Benjamin8e6db492015-07-25 18:29:23 -04007468 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007469 // than the retransmit window.
7470 testCases = append(testCases, testCase{
7471 protocol: dtls,
7472 name: "DTLS-Replay-LargeGaps",
7473 config: Config{
7474 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007475 SequenceNumberMapping: func(in uint64) uint64 {
7476 return in * 127
7477 },
David Benjamin5e961c12014-11-07 01:48:35 -05007478 },
7479 },
David Benjamin8e6db492015-07-25 18:29:23 -04007480 messageCount: 200,
7481 replayWrites: true,
7482 })
7483
7484 // Test the incoming sequence number changing non-monotonically.
7485 testCases = append(testCases, testCase{
7486 protocol: dtls,
7487 name: "DTLS-Replay-NonMonotonic",
7488 config: Config{
7489 Bugs: ProtocolBugs{
7490 SequenceNumberMapping: func(in uint64) uint64 {
7491 return in ^ 31
7492 },
7493 },
7494 },
7495 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007496 replayWrites: true,
7497 })
7498}
7499
Nick Harper60edffd2016-06-21 15:19:24 -07007500var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007501 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007502 id signatureAlgorithm
7503 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007504}{
Nick Harper60edffd2016-06-21 15:19:24 -07007505 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7506 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7507 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7508 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007509 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007510 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7511 // hash function doesn't have to match the curve and so the same
7512 // signature algorithm works with P-224.
7513 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007514 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7515 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7516 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007517 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7518 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7519 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007520 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007521 // Tests for key types prior to TLS 1.2.
7522 {"RSA", 0, testCertRSA},
7523 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007524}
7525
Nick Harper60edffd2016-06-21 15:19:24 -07007526const fakeSigAlg1 signatureAlgorithm = 0x2a01
7527const fakeSigAlg2 signatureAlgorithm = 0xff01
7528
7529func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007530 // Not all ciphers involve a signature. Advertise a list which gives all
7531 // versions a signing cipher.
7532 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007533 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007534 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7535 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7536 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7537 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007538 }
David Benjamin5208fd42016-07-13 21:43:25 -04007539
David Benjaminca3d5452016-07-14 12:51:01 -04007540 var allAlgorithms []signatureAlgorithm
7541 for _, alg := range testSignatureAlgorithms {
7542 if alg.id != 0 {
7543 allAlgorithms = append(allAlgorithms, alg.id)
7544 }
7545 }
7546
Nick Harper60edffd2016-06-21 15:19:24 -07007547 // Make sure each signature algorithm works. Include some fake values in
7548 // the list and ensure they're ignored.
7549 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007550 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007551 if (ver.version < VersionTLS12) != (alg.id == 0) {
7552 continue
7553 }
7554
7555 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7556 // or remove it in C.
7557 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007558 continue
7559 }
Nick Harper60edffd2016-06-21 15:19:24 -07007560
David Benjamin3ef76972016-10-17 17:59:54 -04007561 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007562 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007563 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007564 shouldSignFail = true
7565 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007566 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007567 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007568 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7569 shouldSignFail = true
7570 shouldVerifyFail = true
7571 }
7572 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7573 // the curve has to match the hash size.
7574 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007575 shouldSignFail = true
7576 shouldVerifyFail = true
7577 }
7578
7579 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7580 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7581 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007582 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007583
7584 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007585 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007586 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007587 }
7588 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007589 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007590 }
David Benjamin000800a2014-11-14 01:43:59 -05007591
David Benjamin1fb125c2016-07-08 18:52:12 -07007592 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007593
David Benjamin7a41d372016-07-09 11:21:54 -07007594 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007595 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007596 config: Config{
7597 MaxVersion: ver.version,
7598 ClientAuth: RequireAnyClientCert,
7599 VerifySignatureAlgorithms: []signatureAlgorithm{
7600 fakeSigAlg1,
7601 alg.id,
7602 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007603 },
David Benjamin7a41d372016-07-09 11:21:54 -07007604 },
7605 flags: []string{
7606 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7607 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7608 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007609 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007610 },
David Benjamina5022392017-07-10 17:40:39 -04007611 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007612 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007613 expectedError: signError,
7614 expectedPeerSignatureAlgorithm: alg.id,
7615 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007616
David Benjamin7a41d372016-07-09 11:21:54 -07007617 testCases = append(testCases, testCase{
7618 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007619 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007620 config: Config{
7621 MaxVersion: ver.version,
7622 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7623 SignSignatureAlgorithms: []signatureAlgorithm{
7624 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007625 },
David Benjamin7a41d372016-07-09 11:21:54 -07007626 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007627 SkipECDSACurveCheck: shouldVerifyFail,
7628 IgnoreSignatureVersionChecks: shouldVerifyFail,
7629 // Some signature algorithms may not be advertised.
7630 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007631 },
David Benjamin7a41d372016-07-09 11:21:54 -07007632 },
David Benjamina5022392017-07-10 17:40:39 -04007633 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007634 flags: []string{
7635 "-require-any-client-certificate",
7636 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7637 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007638 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007639 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007640 // Resume the session to assert the peer signature
7641 // algorithm is reported on both handshakes.
7642 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007643 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007644 expectedError: verifyError,
7645 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007646
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007647 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007648 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007649 testCases = append(testCases, testCase{
7650 testType: serverTest,
7651 name: "ServerAuth-Sign" + suffix,
7652 config: Config{
7653 MaxVersion: ver.version,
7654 CipherSuites: signingCiphers,
7655 VerifySignatureAlgorithms: []signatureAlgorithm{
7656 fakeSigAlg1,
7657 alg.id,
7658 fakeSigAlg2,
7659 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007660 },
David Benjamina5022392017-07-10 17:40:39 -04007661 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007662 flags: []string{
7663 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7664 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7665 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007666 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007667 },
7668 shouldFail: shouldSignFail,
7669 expectedError: signError,
7670 expectedPeerSignatureAlgorithm: alg.id,
7671 })
7672 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007673
7674 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007675 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007676 config: Config{
7677 MaxVersion: ver.version,
7678 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007679 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007680 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 alg.id,
7682 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007683 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007684 SkipECDSACurveCheck: shouldVerifyFail,
7685 IgnoreSignatureVersionChecks: shouldVerifyFail,
7686 // Some signature algorithms may not be advertised.
7687 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007688 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007689 },
David Benjamina5022392017-07-10 17:40:39 -04007690 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007691 flags: []string{
7692 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7693 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007694 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007695 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007696 // Resume the session to assert the peer signature
7697 // algorithm is reported on both handshakes.
7698 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007699 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007700 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007701 })
David Benjamin5208fd42016-07-13 21:43:25 -04007702
David Benjamin3ef76972016-10-17 17:59:54 -04007703 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007704 testCases = append(testCases, testCase{
7705 testType: serverTest,
7706 name: "ClientAuth-InvalidSignature" + suffix,
7707 config: Config{
7708 MaxVersion: ver.version,
7709 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7710 SignSignatureAlgorithms: []signatureAlgorithm{
7711 alg.id,
7712 },
7713 Bugs: ProtocolBugs{
7714 InvalidSignature: true,
7715 },
7716 },
David Benjamina5022392017-07-10 17:40:39 -04007717 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007718 flags: []string{
7719 "-require-any-client-certificate",
7720 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007721 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007722 },
7723 shouldFail: true,
7724 expectedError: ":BAD_SIGNATURE:",
7725 })
7726
7727 testCases = append(testCases, testCase{
7728 name: "ServerAuth-InvalidSignature" + suffix,
7729 config: Config{
7730 MaxVersion: ver.version,
7731 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7732 CipherSuites: signingCiphers,
7733 SignSignatureAlgorithms: []signatureAlgorithm{
7734 alg.id,
7735 },
7736 Bugs: ProtocolBugs{
7737 InvalidSignature: true,
7738 },
7739 },
David Benjamina5022392017-07-10 17:40:39 -04007740 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007741 flags: []string{
7742 "-enable-all-curves",
7743 "-enable-ed25519",
7744 },
David Benjamin5208fd42016-07-13 21:43:25 -04007745 shouldFail: true,
7746 expectedError: ":BAD_SIGNATURE:",
7747 })
7748 }
David Benjaminca3d5452016-07-14 12:51:01 -04007749
David Benjamin3ef76972016-10-17 17:59:54 -04007750 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007751 testCases = append(testCases, testCase{
7752 name: "ClientAuth-Sign-Negotiate" + suffix,
7753 config: Config{
7754 MaxVersion: ver.version,
7755 ClientAuth: RequireAnyClientCert,
7756 VerifySignatureAlgorithms: allAlgorithms,
7757 },
David Benjamina5022392017-07-10 17:40:39 -04007758 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007759 flags: []string{
7760 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7761 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7762 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007763 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007764 "-signing-prefs", strconv.Itoa(int(alg.id)),
7765 },
7766 expectedPeerSignatureAlgorithm: alg.id,
7767 })
7768
7769 testCases = append(testCases, testCase{
7770 testType: serverTest,
7771 name: "ServerAuth-Sign-Negotiate" + suffix,
7772 config: Config{
7773 MaxVersion: ver.version,
7774 CipherSuites: signingCiphers,
7775 VerifySignatureAlgorithms: allAlgorithms,
7776 },
David Benjamina5022392017-07-10 17:40:39 -04007777 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007778 flags: []string{
7779 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7780 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7781 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007782 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007783 "-signing-prefs", strconv.Itoa(int(alg.id)),
7784 },
7785 expectedPeerSignatureAlgorithm: alg.id,
7786 })
7787 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007788 }
David Benjamin000800a2014-11-14 01:43:59 -05007789 }
7790
Nick Harper60edffd2016-06-21 15:19:24 -07007791 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007792 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007793 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007794 config: Config{
7795 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007796 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007797 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007798 signatureECDSAWithP521AndSHA512,
7799 signatureRSAPKCS1WithSHA384,
7800 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007801 },
7802 },
7803 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007804 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7805 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007806 },
Nick Harper60edffd2016-06-21 15:19:24 -07007807 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007808 })
7809
7810 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007811 name: "ClientAuth-SignatureType-TLS13",
7812 config: Config{
7813 ClientAuth: RequireAnyClientCert,
7814 MaxVersion: VersionTLS13,
7815 VerifySignatureAlgorithms: []signatureAlgorithm{
7816 signatureECDSAWithP521AndSHA512,
7817 signatureRSAPKCS1WithSHA384,
7818 signatureRSAPSSWithSHA384,
7819 signatureECDSAWithSHA1,
7820 },
7821 },
7822 flags: []string{
7823 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7824 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7825 },
7826 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7827 })
7828
7829 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007830 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007831 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007832 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007833 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007834 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007835 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007836 signatureECDSAWithP521AndSHA512,
7837 signatureRSAPKCS1WithSHA384,
7838 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007839 },
7840 },
Nick Harper60edffd2016-06-21 15:19:24 -07007841 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007842 })
7843
Steven Valdez143e8b32016-07-11 13:19:03 -04007844 testCases = append(testCases, testCase{
7845 testType: serverTest,
7846 name: "ServerAuth-SignatureType-TLS13",
7847 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007848 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007849 VerifySignatureAlgorithms: []signatureAlgorithm{
7850 signatureECDSAWithP521AndSHA512,
7851 signatureRSAPKCS1WithSHA384,
7852 signatureRSAPSSWithSHA384,
7853 signatureECDSAWithSHA1,
7854 },
7855 },
7856 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7857 })
7858
David Benjamina95e9f32016-07-08 16:28:04 -07007859 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007860 testCases = append(testCases, testCase{
7861 testType: serverTest,
7862 name: "Verify-ClientAuth-SignatureType",
7863 config: Config{
7864 MaxVersion: VersionTLS12,
7865 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007866 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007867 signatureRSAPKCS1WithSHA256,
7868 },
7869 Bugs: ProtocolBugs{
7870 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7871 },
7872 },
7873 flags: []string{
7874 "-require-any-client-certificate",
7875 },
7876 shouldFail: true,
7877 expectedError: ":WRONG_SIGNATURE_TYPE:",
7878 })
7879
7880 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007881 testType: serverTest,
7882 name: "Verify-ClientAuth-SignatureType-TLS13",
7883 config: Config{
7884 MaxVersion: VersionTLS13,
7885 Certificates: []Certificate{rsaCertificate},
7886 SignSignatureAlgorithms: []signatureAlgorithm{
7887 signatureRSAPSSWithSHA256,
7888 },
7889 Bugs: ProtocolBugs{
7890 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7891 },
7892 },
7893 flags: []string{
7894 "-require-any-client-certificate",
7895 },
7896 shouldFail: true,
7897 expectedError: ":WRONG_SIGNATURE_TYPE:",
7898 })
7899
7900 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007901 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007902 config: Config{
7903 MaxVersion: VersionTLS12,
7904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007905 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007906 signatureRSAPKCS1WithSHA256,
7907 },
7908 Bugs: ProtocolBugs{
7909 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7910 },
7911 },
7912 shouldFail: true,
7913 expectedError: ":WRONG_SIGNATURE_TYPE:",
7914 })
7915
Steven Valdez143e8b32016-07-11 13:19:03 -04007916 testCases = append(testCases, testCase{
7917 name: "Verify-ServerAuth-SignatureType-TLS13",
7918 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007919 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007920 SignSignatureAlgorithms: []signatureAlgorithm{
7921 signatureRSAPSSWithSHA256,
7922 },
7923 Bugs: ProtocolBugs{
7924 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7925 },
7926 },
7927 shouldFail: true,
7928 expectedError: ":WRONG_SIGNATURE_TYPE:",
7929 })
7930
David Benjamin51dd7d62016-07-08 16:07:01 -07007931 // Test that, if the list is missing, the peer falls back to SHA-1 in
7932 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007933 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007934 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007936 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007937 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007938 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007939 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007940 },
7941 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007942 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007943 },
7944 },
7945 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007946 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7947 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007948 },
7949 })
7950
7951 testCases = append(testCases, testCase{
7952 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007953 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007954 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007955 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007956 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007957 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007958 },
7959 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007960 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007961 },
7962 },
David Benjaminee32bea2016-08-17 13:36:44 -04007963 flags: []string{
7964 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7965 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7966 },
7967 })
7968
7969 testCases = append(testCases, testCase{
7970 name: "ClientAuth-SHA1-Fallback-ECDSA",
7971 config: Config{
7972 MaxVersion: VersionTLS12,
7973 ClientAuth: RequireAnyClientCert,
7974 VerifySignatureAlgorithms: []signatureAlgorithm{
7975 signatureECDSAWithSHA1,
7976 },
7977 Bugs: ProtocolBugs{
7978 NoSignatureAlgorithms: true,
7979 },
7980 },
7981 flags: []string{
7982 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7983 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7984 },
7985 })
7986
7987 testCases = append(testCases, testCase{
7988 testType: serverTest,
7989 name: "ServerAuth-SHA1-Fallback-ECDSA",
7990 config: Config{
7991 MaxVersion: VersionTLS12,
7992 VerifySignatureAlgorithms: []signatureAlgorithm{
7993 signatureECDSAWithSHA1,
7994 },
7995 Bugs: ProtocolBugs{
7996 NoSignatureAlgorithms: true,
7997 },
7998 },
7999 flags: []string{
8000 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8001 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8002 },
David Benjamin000800a2014-11-14 01:43:59 -05008003 })
David Benjamin72dc7832015-03-16 17:49:43 -04008004
David Benjamin51dd7d62016-07-08 16:07:01 -07008005 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008006 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008007 config: Config{
8008 MaxVersion: VersionTLS13,
8009 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008010 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008011 signatureRSAPKCS1WithSHA1,
8012 },
8013 Bugs: ProtocolBugs{
8014 NoSignatureAlgorithms: true,
8015 },
8016 },
8017 flags: []string{
8018 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8019 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8020 },
David Benjamin48901652016-08-01 12:12:47 -04008021 shouldFail: true,
8022 // An empty CertificateRequest signature algorithm list is a
8023 // syntax error in TLS 1.3.
8024 expectedError: ":DECODE_ERROR:",
8025 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008026 })
8027
8028 testCases = append(testCases, testCase{
8029 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008030 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008031 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008032 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008033 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008034 signatureRSAPKCS1WithSHA1,
8035 },
8036 Bugs: ProtocolBugs{
8037 NoSignatureAlgorithms: true,
8038 },
8039 },
8040 shouldFail: true,
8041 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8042 })
8043
David Benjaminb62d2872016-07-18 14:55:02 +02008044 // Test that hash preferences are enforced. BoringSSL does not implement
8045 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008046 testCases = append(testCases, testCase{
8047 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008048 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008050 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008051 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008052 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008053 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008054 },
8055 Bugs: ProtocolBugs{
8056 IgnorePeerSignatureAlgorithmPreferences: true,
8057 },
8058 },
8059 flags: []string{"-require-any-client-certificate"},
8060 shouldFail: true,
8061 expectedError: ":WRONG_SIGNATURE_TYPE:",
8062 })
8063
8064 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008065 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008067 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008069 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008070 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008071 },
8072 Bugs: ProtocolBugs{
8073 IgnorePeerSignatureAlgorithmPreferences: true,
8074 },
8075 },
8076 shouldFail: true,
8077 expectedError: ":WRONG_SIGNATURE_TYPE:",
8078 })
David Benjaminb62d2872016-07-18 14:55:02 +02008079 testCases = append(testCases, testCase{
8080 testType: serverTest,
8081 name: "ClientAuth-Enforced-TLS13",
8082 config: Config{
8083 MaxVersion: VersionTLS13,
8084 Certificates: []Certificate{rsaCertificate},
8085 SignSignatureAlgorithms: []signatureAlgorithm{
8086 signatureRSAPKCS1WithMD5,
8087 },
8088 Bugs: ProtocolBugs{
8089 IgnorePeerSignatureAlgorithmPreferences: true,
8090 IgnoreSignatureVersionChecks: true,
8091 },
8092 },
8093 flags: []string{"-require-any-client-certificate"},
8094 shouldFail: true,
8095 expectedError: ":WRONG_SIGNATURE_TYPE:",
8096 })
8097
8098 testCases = append(testCases, testCase{
8099 name: "ServerAuth-Enforced-TLS13",
8100 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008101 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008102 SignSignatureAlgorithms: []signatureAlgorithm{
8103 signatureRSAPKCS1WithMD5,
8104 },
8105 Bugs: ProtocolBugs{
8106 IgnorePeerSignatureAlgorithmPreferences: true,
8107 IgnoreSignatureVersionChecks: true,
8108 },
8109 },
8110 shouldFail: true,
8111 expectedError: ":WRONG_SIGNATURE_TYPE:",
8112 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008113
8114 // Test that the agreed upon digest respects the client preferences and
8115 // the server digests.
8116 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008117 name: "NoCommonAlgorithms-Digests",
8118 config: Config{
8119 MaxVersion: VersionTLS12,
8120 ClientAuth: RequireAnyClientCert,
8121 VerifySignatureAlgorithms: []signatureAlgorithm{
8122 signatureRSAPKCS1WithSHA512,
8123 signatureRSAPKCS1WithSHA1,
8124 },
8125 },
8126 flags: []string{
8127 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8128 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8129 "-digest-prefs", "SHA256",
8130 },
8131 shouldFail: true,
8132 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8133 })
8134 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008135 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008137 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008138 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008139 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008140 signatureRSAPKCS1WithSHA512,
8141 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008142 },
8143 },
8144 flags: []string{
8145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008147 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008148 },
David Benjaminca3d5452016-07-14 12:51:01 -04008149 shouldFail: true,
8150 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8151 })
8152 testCases = append(testCases, testCase{
8153 name: "NoCommonAlgorithms-TLS13",
8154 config: Config{
8155 MaxVersion: VersionTLS13,
8156 ClientAuth: RequireAnyClientCert,
8157 VerifySignatureAlgorithms: []signatureAlgorithm{
8158 signatureRSAPSSWithSHA512,
8159 signatureRSAPSSWithSHA384,
8160 },
8161 },
8162 flags: []string{
8163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8165 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8166 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008167 shouldFail: true,
8168 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008169 })
8170 testCases = append(testCases, testCase{
8171 name: "Agree-Digest-SHA256",
8172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008173 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008174 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008175 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008176 signatureRSAPKCS1WithSHA1,
8177 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008178 },
8179 },
8180 flags: []string{
8181 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8182 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008183 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008184 },
Nick Harper60edffd2016-06-21 15:19:24 -07008185 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008186 })
8187 testCases = append(testCases, testCase{
8188 name: "Agree-Digest-SHA1",
8189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008190 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008191 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008192 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008193 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008194 },
8195 },
8196 flags: []string{
8197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008199 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008200 },
Nick Harper60edffd2016-06-21 15:19:24 -07008201 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008202 })
8203 testCases = append(testCases, testCase{
8204 name: "Agree-Digest-Default",
8205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008206 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008207 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008208 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008209 signatureRSAPKCS1WithSHA256,
8210 signatureECDSAWithP256AndSHA256,
8211 signatureRSAPKCS1WithSHA1,
8212 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008213 },
8214 },
8215 flags: []string{
8216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8218 },
Nick Harper60edffd2016-06-21 15:19:24 -07008219 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008220 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008221
David Benjaminca3d5452016-07-14 12:51:01 -04008222 // Test that the signing preference list may include extra algorithms
8223 // without negotiation problems.
8224 testCases = append(testCases, testCase{
8225 testType: serverTest,
8226 name: "FilterExtraAlgorithms",
8227 config: Config{
8228 MaxVersion: VersionTLS12,
8229 VerifySignatureAlgorithms: []signatureAlgorithm{
8230 signatureRSAPKCS1WithSHA256,
8231 },
8232 },
8233 flags: []string{
8234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8236 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8237 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8238 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8239 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8240 },
8241 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8242 })
8243
David Benjamin4c3ddf72016-06-29 18:13:53 -04008244 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8245 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008246 testCases = append(testCases, testCase{
8247 name: "CheckLeafCurve",
8248 config: Config{
8249 MaxVersion: VersionTLS12,
8250 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008251 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008252 },
8253 flags: []string{"-p384-only"},
8254 shouldFail: true,
8255 expectedError: ":BAD_ECC_CERT:",
8256 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008257
8258 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8259 testCases = append(testCases, testCase{
8260 name: "CheckLeafCurve-TLS13",
8261 config: Config{
8262 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008263 Certificates: []Certificate{ecdsaP256Certificate},
8264 },
8265 flags: []string{"-p384-only"},
8266 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008267
8268 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8269 testCases = append(testCases, testCase{
8270 name: "ECDSACurveMismatch-Verify-TLS12",
8271 config: Config{
8272 MaxVersion: VersionTLS12,
8273 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8274 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008275 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008276 signatureECDSAWithP384AndSHA384,
8277 },
8278 },
8279 })
8280
8281 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8282 testCases = append(testCases, testCase{
8283 name: "ECDSACurveMismatch-Verify-TLS13",
8284 config: Config{
8285 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008286 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008287 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008288 signatureECDSAWithP384AndSHA384,
8289 },
8290 Bugs: ProtocolBugs{
8291 SkipECDSACurveCheck: true,
8292 },
8293 },
8294 shouldFail: true,
8295 expectedError: ":WRONG_SIGNATURE_TYPE:",
8296 })
8297
8298 // Signature algorithm selection in TLS 1.3 should take the curve into
8299 // account.
8300 testCases = append(testCases, testCase{
8301 testType: serverTest,
8302 name: "ECDSACurveMismatch-Sign-TLS13",
8303 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008304 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008305 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008306 signatureECDSAWithP384AndSHA384,
8307 signatureECDSAWithP256AndSHA256,
8308 },
8309 },
8310 flags: []string{
8311 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8312 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8313 },
8314 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8315 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008316
8317 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8318 // server does not attempt to sign in that case.
8319 testCases = append(testCases, testCase{
8320 testType: serverTest,
8321 name: "RSA-PSS-Large",
8322 config: Config{
8323 MaxVersion: VersionTLS13,
8324 VerifySignatureAlgorithms: []signatureAlgorithm{
8325 signatureRSAPSSWithSHA512,
8326 },
8327 },
8328 flags: []string{
8329 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8330 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8331 },
8332 shouldFail: true,
8333 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8334 })
David Benjamin57e929f2016-08-30 00:30:38 -04008335
8336 // Test that RSA-PSS is enabled by default for TLS 1.2.
8337 testCases = append(testCases, testCase{
8338 testType: clientTest,
8339 name: "RSA-PSS-Default-Verify",
8340 config: Config{
8341 MaxVersion: VersionTLS12,
8342 SignSignatureAlgorithms: []signatureAlgorithm{
8343 signatureRSAPSSWithSHA256,
8344 },
8345 },
8346 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8347 })
8348
8349 testCases = append(testCases, testCase{
8350 testType: serverTest,
8351 name: "RSA-PSS-Default-Sign",
8352 config: Config{
8353 MaxVersion: VersionTLS12,
8354 VerifySignatureAlgorithms: []signatureAlgorithm{
8355 signatureRSAPSSWithSHA256,
8356 },
8357 },
8358 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8359 })
David Benjamin69522112017-03-28 15:38:29 -05008360
8361 // TLS 1.1 and below has no way to advertise support for or negotiate
8362 // Ed25519's signature algorithm.
8363 testCases = append(testCases, testCase{
8364 testType: clientTest,
8365 name: "NoEd25519-TLS11-ServerAuth-Verify",
8366 config: Config{
8367 MaxVersion: VersionTLS11,
8368 Certificates: []Certificate{ed25519Certificate},
8369 Bugs: ProtocolBugs{
8370 // Sign with Ed25519 even though it is TLS 1.1.
8371 UseLegacySigningAlgorithm: signatureEd25519,
8372 },
8373 },
8374 flags: []string{"-enable-ed25519"},
8375 shouldFail: true,
8376 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8377 })
8378 testCases = append(testCases, testCase{
8379 testType: serverTest,
8380 name: "NoEd25519-TLS11-ServerAuth-Sign",
8381 config: Config{
8382 MaxVersion: VersionTLS11,
8383 },
8384 flags: []string{
8385 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8386 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8387 },
8388 shouldFail: true,
8389 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8390 })
8391 testCases = append(testCases, testCase{
8392 testType: serverTest,
8393 name: "NoEd25519-TLS11-ClientAuth-Verify",
8394 config: Config{
8395 MaxVersion: VersionTLS11,
8396 Certificates: []Certificate{ed25519Certificate},
8397 Bugs: ProtocolBugs{
8398 // Sign with Ed25519 even though it is TLS 1.1.
8399 UseLegacySigningAlgorithm: signatureEd25519,
8400 },
8401 },
8402 flags: []string{
8403 "-enable-ed25519",
8404 "-require-any-client-certificate",
8405 },
8406 shouldFail: true,
8407 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8408 })
8409 testCases = append(testCases, testCase{
8410 testType: clientTest,
8411 name: "NoEd25519-TLS11-ClientAuth-Sign",
8412 config: Config{
8413 MaxVersion: VersionTLS11,
8414 ClientAuth: RequireAnyClientCert,
8415 },
8416 flags: []string{
8417 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8418 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8419 },
8420 shouldFail: true,
8421 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8422 })
8423
8424 // Test Ed25519 is not advertised by default.
8425 testCases = append(testCases, testCase{
8426 testType: clientTest,
8427 name: "Ed25519DefaultDisable-NoAdvertise",
8428 config: Config{
8429 Certificates: []Certificate{ed25519Certificate},
8430 },
8431 shouldFail: true,
8432 expectedLocalError: "tls: no common signature algorithms",
8433 })
8434
8435 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8436 // preferences.
8437 testCases = append(testCases, testCase{
8438 testType: clientTest,
8439 name: "Ed25519DefaultDisable-NoAccept",
8440 config: Config{
8441 Certificates: []Certificate{ed25519Certificate},
8442 Bugs: ProtocolBugs{
8443 IgnorePeerSignatureAlgorithmPreferences: true,
8444 },
8445 },
8446 shouldFail: true,
8447 expectedLocalError: "remote error: illegal parameter",
8448 expectedError: ":WRONG_SIGNATURE_TYPE:",
8449 })
David Benjamin71c21b42017-04-14 17:05:40 -04008450
8451 // Test that configuring verify preferences changes what the client
8452 // advertises.
8453 testCases = append(testCases, testCase{
8454 name: "VerifyPreferences-Advertised",
8455 config: Config{
8456 Certificates: []Certificate{rsaCertificate},
8457 SignSignatureAlgorithms: []signatureAlgorithm{
8458 signatureRSAPSSWithSHA256,
8459 signatureRSAPSSWithSHA384,
8460 signatureRSAPSSWithSHA512,
8461 },
8462 },
8463 flags: []string{
8464 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8465 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8466 },
8467 })
8468
8469 // Test that the client advertises a set which the runner can find
8470 // nothing in common with.
8471 testCases = append(testCases, testCase{
8472 name: "VerifyPreferences-NoCommonAlgorithms",
8473 config: Config{
8474 Certificates: []Certificate{rsaCertificate},
8475 SignSignatureAlgorithms: []signatureAlgorithm{
8476 signatureRSAPSSWithSHA256,
8477 signatureRSAPSSWithSHA512,
8478 },
8479 },
8480 flags: []string{
8481 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8482 },
8483 shouldFail: true,
8484 expectedLocalError: "tls: no common signature algorithms",
8485 })
8486
8487 // Test that the client enforces its preferences when configured.
8488 testCases = append(testCases, testCase{
8489 name: "VerifyPreferences-Enforced",
8490 config: Config{
8491 Certificates: []Certificate{rsaCertificate},
8492 SignSignatureAlgorithms: []signatureAlgorithm{
8493 signatureRSAPSSWithSHA256,
8494 signatureRSAPSSWithSHA512,
8495 },
8496 Bugs: ProtocolBugs{
8497 IgnorePeerSignatureAlgorithmPreferences: true,
8498 },
8499 },
8500 flags: []string{
8501 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8502 },
8503 shouldFail: true,
8504 expectedLocalError: "remote error: illegal parameter",
8505 expectedError: ":WRONG_SIGNATURE_TYPE:",
8506 })
8507
8508 // Test that explicitly configuring Ed25519 is as good as changing the
8509 // boolean toggle.
8510 testCases = append(testCases, testCase{
8511 name: "VerifyPreferences-Ed25519",
8512 config: Config{
8513 Certificates: []Certificate{ed25519Certificate},
8514 },
8515 flags: []string{
8516 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8517 },
8518 })
David Benjamin000800a2014-11-14 01:43:59 -05008519}
8520
David Benjamin83f90402015-01-27 01:09:43 -05008521// timeouts is the retransmit schedule for BoringSSL. It doubles and
8522// caps at 60 seconds. On the 13th timeout, it gives up.
8523var timeouts = []time.Duration{
8524 1 * time.Second,
8525 2 * time.Second,
8526 4 * time.Second,
8527 8 * time.Second,
8528 16 * time.Second,
8529 32 * time.Second,
8530 60 * time.Second,
8531 60 * time.Second,
8532 60 * time.Second,
8533 60 * time.Second,
8534 60 * time.Second,
8535 60 * time.Second,
8536 60 * time.Second,
8537}
8538
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008539// shortTimeouts is an alternate set of timeouts which would occur if the
8540// initial timeout duration was set to 250ms.
8541var shortTimeouts = []time.Duration{
8542 250 * time.Millisecond,
8543 500 * time.Millisecond,
8544 1 * time.Second,
8545 2 * time.Second,
8546 4 * time.Second,
8547 8 * time.Second,
8548 16 * time.Second,
8549 32 * time.Second,
8550 60 * time.Second,
8551 60 * time.Second,
8552 60 * time.Second,
8553 60 * time.Second,
8554 60 * time.Second,
8555}
8556
David Benjamin83f90402015-01-27 01:09:43 -05008557func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008558 // These tests work by coordinating some behavior on both the shim and
8559 // the runner.
8560 //
8561 // TimeoutSchedule configures the runner to send a series of timeout
8562 // opcodes to the shim (see packetAdaptor) immediately before reading
8563 // each peer handshake flight N. The timeout opcode both simulates a
8564 // timeout in the shim and acts as a synchronization point to help the
8565 // runner bracket each handshake flight.
8566 //
8567 // We assume the shim does not read from the channel eagerly. It must
8568 // first wait until it has sent flight N and is ready to receive
8569 // handshake flight N+1. At this point, it will process the timeout
8570 // opcode. It must then immediately respond with a timeout ACK and act
8571 // as if the shim was idle for the specified amount of time.
8572 //
8573 // The runner then drops all packets received before the ACK and
8574 // continues waiting for flight N. This ordering results in one attempt
8575 // at sending flight N to be dropped. For the test to complete, the
8576 // shim must send flight N again, testing that the shim implements DTLS
8577 // retransmit on a timeout.
8578
Steven Valdez143e8b32016-07-11 13:19:03 -04008579 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008580 // likely be more epochs to cross and the final message's retransmit may
8581 // be more complex.
8582
David Benjamin11c82892017-02-23 20:40:31 -05008583 // Test that this is indeed the timeout schedule. Stress all
8584 // four patterns of handshake.
8585 for i := 1; i < len(timeouts); i++ {
8586 number := strconv.Itoa(i)
8587 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008588 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008589 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008590 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008591 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008592 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008593 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008594 },
8595 },
8596 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008597 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008598 })
David Benjamin11c82892017-02-23 20:40:31 -05008599 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008600 protocol: dtls,
8601 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008602 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008604 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008605 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008606 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008607 },
8608 },
8609 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008610 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008611 })
8612 }
David Benjamin11c82892017-02-23 20:40:31 -05008613
8614 // Test that exceeding the timeout schedule hits a read
8615 // timeout.
8616 testCases = append(testCases, testCase{
8617 protocol: dtls,
8618 name: "DTLS-Retransmit-Timeout",
8619 config: Config{
8620 MaxVersion: VersionTLS12,
8621 Bugs: ProtocolBugs{
8622 TimeoutSchedule: timeouts,
8623 },
8624 },
8625 resumeSession: true,
8626 flags: []string{"-async"},
8627 shouldFail: true,
8628 expectedError: ":READ_TIMEOUT_EXPIRED:",
8629 })
8630
8631 // Test that timeout handling has a fudge factor, due to API
8632 // problems.
8633 testCases = append(testCases, testCase{
8634 protocol: dtls,
8635 name: "DTLS-Retransmit-Fudge",
8636 config: Config{
8637 MaxVersion: VersionTLS12,
8638 Bugs: ProtocolBugs{
8639 TimeoutSchedule: []time.Duration{
8640 timeouts[0] - 10*time.Millisecond,
8641 },
8642 },
8643 },
8644 resumeSession: true,
8645 flags: []string{"-async"},
8646 })
8647
8648 // Test that the final Finished retransmitting isn't
8649 // duplicated if the peer badly fragments everything.
8650 testCases = append(testCases, testCase{
8651 testType: serverTest,
8652 protocol: dtls,
8653 name: "DTLS-Retransmit-Fragmented",
8654 config: Config{
8655 MaxVersion: VersionTLS12,
8656 Bugs: ProtocolBugs{
8657 TimeoutSchedule: []time.Duration{timeouts[0]},
8658 MaxHandshakeRecordLength: 2,
8659 },
8660 },
8661 flags: []string{"-async"},
8662 })
8663
8664 // Test the timeout schedule when a shorter initial timeout duration is set.
8665 testCases = append(testCases, testCase{
8666 protocol: dtls,
8667 name: "DTLS-Retransmit-Short-Client",
8668 config: Config{
8669 MaxVersion: VersionTLS12,
8670 Bugs: ProtocolBugs{
8671 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8672 },
8673 },
8674 resumeSession: true,
8675 flags: []string{
8676 "-async",
8677 "-initial-timeout-duration-ms", "250",
8678 },
8679 })
8680 testCases = append(testCases, testCase{
8681 protocol: dtls,
8682 testType: serverTest,
8683 name: "DTLS-Retransmit-Short-Server",
8684 config: Config{
8685 MaxVersion: VersionTLS12,
8686 Bugs: ProtocolBugs{
8687 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8688 },
8689 },
8690 resumeSession: true,
8691 flags: []string{
8692 "-async",
8693 "-initial-timeout-duration-ms", "250",
8694 },
8695 })
David Benjamin83f90402015-01-27 01:09:43 -05008696}
8697
David Benjaminc565ebb2015-04-03 04:06:36 -04008698func addExportKeyingMaterialTests() {
8699 for _, vers := range tlsVersions {
8700 if vers.version == VersionSSL30 {
8701 continue
8702 }
8703 testCases = append(testCases, testCase{
8704 name: "ExportKeyingMaterial-" + vers.name,
8705 config: Config{
8706 MaxVersion: vers.version,
8707 },
David Benjamina5022392017-07-10 17:40:39 -04008708 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008709 exportKeyingMaterial: 1024,
8710 exportLabel: "label",
8711 exportContext: "context",
8712 useExportContext: true,
8713 })
8714 testCases = append(testCases, testCase{
8715 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8716 config: Config{
8717 MaxVersion: vers.version,
8718 },
David Benjamina5022392017-07-10 17:40:39 -04008719 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008720 exportKeyingMaterial: 1024,
8721 })
8722 testCases = append(testCases, testCase{
8723 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8724 config: Config{
8725 MaxVersion: vers.version,
8726 },
David Benjamina5022392017-07-10 17:40:39 -04008727 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008728 exportKeyingMaterial: 1024,
8729 useExportContext: true,
8730 })
8731 testCases = append(testCases, testCase{
8732 name: "ExportKeyingMaterial-Small-" + vers.name,
8733 config: Config{
8734 MaxVersion: vers.version,
8735 },
David Benjamina5022392017-07-10 17:40:39 -04008736 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008737 exportKeyingMaterial: 1,
8738 exportLabel: "label",
8739 exportContext: "context",
8740 useExportContext: true,
8741 })
8742 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008743
David Benjaminc565ebb2015-04-03 04:06:36 -04008744 testCases = append(testCases, testCase{
8745 name: "ExportKeyingMaterial-SSL3",
8746 config: Config{
8747 MaxVersion: VersionSSL30,
8748 },
8749 exportKeyingMaterial: 1024,
8750 exportLabel: "label",
8751 exportContext: "context",
8752 useExportContext: true,
8753 shouldFail: true,
8754 expectedError: "failed to export keying material",
8755 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008756
8757 // Exporters work during a False Start.
8758 testCases = append(testCases, testCase{
8759 name: "ExportKeyingMaterial-FalseStart",
8760 config: Config{
8761 MaxVersion: VersionTLS12,
8762 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8763 NextProtos: []string{"foo"},
8764 Bugs: ProtocolBugs{
8765 ExpectFalseStart: true,
8766 },
8767 },
8768 flags: []string{
8769 "-false-start",
8770 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008771 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008772 },
8773 shimWritesFirst: true,
8774 exportKeyingMaterial: 1024,
8775 exportLabel: "label",
8776 exportContext: "context",
8777 useExportContext: true,
8778 })
8779
8780 // Exporters do not work in the middle of a renegotiation. Test this by
8781 // triggering the exporter after every SSL_read call and configuring the
8782 // shim to run asynchronously.
8783 testCases = append(testCases, testCase{
8784 name: "ExportKeyingMaterial-Renegotiate",
8785 config: Config{
8786 MaxVersion: VersionTLS12,
8787 },
8788 renegotiate: 1,
8789 flags: []string{
8790 "-async",
8791 "-use-exporter-between-reads",
8792 "-renegotiate-freely",
8793 "-expect-total-renegotiations", "1",
8794 },
8795 shouldFail: true,
8796 expectedError: "failed to export keying material",
8797 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008798}
8799
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008800func addTLSUniqueTests() {
8801 for _, isClient := range []bool{false, true} {
8802 for _, isResumption := range []bool{false, true} {
8803 for _, hasEMS := range []bool{false, true} {
8804 var suffix string
8805 if isResumption {
8806 suffix = "Resume-"
8807 } else {
8808 suffix = "Full-"
8809 }
8810
8811 if hasEMS {
8812 suffix += "EMS-"
8813 } else {
8814 suffix += "NoEMS-"
8815 }
8816
8817 if isClient {
8818 suffix += "Client"
8819 } else {
8820 suffix += "Server"
8821 }
8822
8823 test := testCase{
8824 name: "TLSUnique-" + suffix,
8825 testTLSUnique: true,
8826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008827 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008828 Bugs: ProtocolBugs{
8829 NoExtendedMasterSecret: !hasEMS,
8830 },
8831 },
8832 }
8833
8834 if isResumption {
8835 test.resumeSession = true
8836 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008837 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008838 Bugs: ProtocolBugs{
8839 NoExtendedMasterSecret: !hasEMS,
8840 },
8841 }
8842 }
8843
8844 if isResumption && !hasEMS {
8845 test.shouldFail = true
8846 test.expectedError = "failed to get tls-unique"
8847 }
8848
8849 testCases = append(testCases, test)
8850 }
8851 }
8852 }
8853}
8854
Adam Langley09505632015-07-30 18:10:13 -07008855func addCustomExtensionTests() {
8856 expectedContents := "custom extension"
8857 emptyString := ""
8858
8859 for _, isClient := range []bool{false, true} {
8860 suffix := "Server"
8861 flag := "-enable-server-custom-extension"
8862 testType := serverTest
8863 if isClient {
8864 suffix = "Client"
8865 flag = "-enable-client-custom-extension"
8866 testType = clientTest
8867 }
8868
8869 testCases = append(testCases, testCase{
8870 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008871 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008873 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008874 Bugs: ProtocolBugs{
8875 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008876 ExpectedCustomExtension: &expectedContents,
8877 },
8878 },
8879 flags: []string{flag},
8880 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008881 testCases = append(testCases, testCase{
8882 testType: testType,
8883 name: "CustomExtensions-" + suffix + "-TLS13",
8884 config: Config{
8885 MaxVersion: VersionTLS13,
8886 Bugs: ProtocolBugs{
8887 CustomExtension: expectedContents,
8888 ExpectedCustomExtension: &expectedContents,
8889 },
8890 },
8891 flags: []string{flag},
8892 })
Adam Langley09505632015-07-30 18:10:13 -07008893
Steven Valdez2a070722017-03-25 20:54:16 -05008894 // 0-RTT is not currently supported with Custom Extensions.
8895 testCases = append(testCases, testCase{
8896 testType: testType,
8897 name: "CustomExtensions-" + suffix + "-EarlyData",
8898 config: Config{
8899 MaxVersion: VersionTLS13,
8900 Bugs: ProtocolBugs{
8901 CustomExtension: expectedContents,
8902 ExpectedCustomExtension: &expectedContents,
8903 },
8904 },
8905 shouldFail: true,
8906 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8907 flags: []string{flag, "-enable-early-data"},
8908 })
8909
Adam Langley09505632015-07-30 18:10:13 -07008910 // If the parse callback fails, the handshake should also fail.
8911 testCases = append(testCases, testCase{
8912 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008913 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008915 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008916 Bugs: ProtocolBugs{
8917 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008918 ExpectedCustomExtension: &expectedContents,
8919 },
8920 },
David Benjamin399e7c92015-07-30 23:01:27 -04008921 flags: []string{flag},
8922 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008923 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8924 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008925 testCases = append(testCases, testCase{
8926 testType: testType,
8927 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8928 config: Config{
8929 MaxVersion: VersionTLS13,
8930 Bugs: ProtocolBugs{
8931 CustomExtension: expectedContents + "foo",
8932 ExpectedCustomExtension: &expectedContents,
8933 },
8934 },
8935 flags: []string{flag},
8936 shouldFail: true,
8937 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8938 })
Adam Langley09505632015-07-30 18:10:13 -07008939
8940 // If the add callback fails, the handshake should also fail.
8941 testCases = append(testCases, testCase{
8942 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008943 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008945 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008946 Bugs: ProtocolBugs{
8947 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008948 ExpectedCustomExtension: &expectedContents,
8949 },
8950 },
David Benjamin399e7c92015-07-30 23:01:27 -04008951 flags: []string{flag, "-custom-extension-fail-add"},
8952 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008953 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8954 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008955 testCases = append(testCases, testCase{
8956 testType: testType,
8957 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8958 config: Config{
8959 MaxVersion: VersionTLS13,
8960 Bugs: ProtocolBugs{
8961 CustomExtension: expectedContents,
8962 ExpectedCustomExtension: &expectedContents,
8963 },
8964 },
8965 flags: []string{flag, "-custom-extension-fail-add"},
8966 shouldFail: true,
8967 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8968 })
Adam Langley09505632015-07-30 18:10:13 -07008969
8970 // If the add callback returns zero, no extension should be
8971 // added.
8972 skipCustomExtension := expectedContents
8973 if isClient {
8974 // For the case where the client skips sending the
8975 // custom extension, the server must not “echo” it.
8976 skipCustomExtension = ""
8977 }
8978 testCases = append(testCases, testCase{
8979 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008980 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008982 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008983 Bugs: ProtocolBugs{
8984 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008985 ExpectedCustomExtension: &emptyString,
8986 },
8987 },
8988 flags: []string{flag, "-custom-extension-skip"},
8989 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008990 testCases = append(testCases, testCase{
8991 testType: testType,
8992 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8993 config: Config{
8994 MaxVersion: VersionTLS13,
8995 Bugs: ProtocolBugs{
8996 CustomExtension: skipCustomExtension,
8997 ExpectedCustomExtension: &emptyString,
8998 },
8999 },
9000 flags: []string{flag, "-custom-extension-skip"},
9001 })
Adam Langley09505632015-07-30 18:10:13 -07009002 }
9003
9004 // The custom extension add callback should not be called if the client
9005 // doesn't send the extension.
9006 testCases = append(testCases, testCase{
9007 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009008 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009010 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009011 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009012 ExpectedCustomExtension: &emptyString,
9013 },
9014 },
9015 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9016 })
Adam Langley2deb9842015-08-07 11:15:37 -07009017
Steven Valdez143e8b32016-07-11 13:19:03 -04009018 testCases = append(testCases, testCase{
9019 testType: serverTest,
9020 name: "CustomExtensions-NotCalled-Server-TLS13",
9021 config: Config{
9022 MaxVersion: VersionTLS13,
9023 Bugs: ProtocolBugs{
9024 ExpectedCustomExtension: &emptyString,
9025 },
9026 },
9027 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9028 })
9029
Adam Langley2deb9842015-08-07 11:15:37 -07009030 // Test an unknown extension from the server.
9031 testCases = append(testCases, testCase{
9032 testType: clientTest,
9033 name: "UnknownExtension-Client",
9034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009035 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009036 Bugs: ProtocolBugs{
9037 CustomExtension: expectedContents,
9038 },
9039 },
David Benjamin0c40a962016-08-01 12:05:50 -04009040 shouldFail: true,
9041 expectedError: ":UNEXPECTED_EXTENSION:",
9042 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009043 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009044 testCases = append(testCases, testCase{
9045 testType: clientTest,
9046 name: "UnknownExtension-Client-TLS13",
9047 config: Config{
9048 MaxVersion: VersionTLS13,
9049 Bugs: ProtocolBugs{
9050 CustomExtension: expectedContents,
9051 },
9052 },
David Benjamin0c40a962016-08-01 12:05:50 -04009053 shouldFail: true,
9054 expectedError: ":UNEXPECTED_EXTENSION:",
9055 expectedLocalError: "remote error: unsupported extension",
9056 })
David Benjamin490469f2016-10-05 22:44:38 -04009057 testCases = append(testCases, testCase{
9058 testType: clientTest,
9059 name: "UnknownUnencryptedExtension-Client-TLS13",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 Bugs: ProtocolBugs{
9063 CustomUnencryptedExtension: expectedContents,
9064 },
9065 },
9066 shouldFail: true,
9067 expectedError: ":UNEXPECTED_EXTENSION:",
9068 // The shim must send an alert, but alerts at this point do not
9069 // get successfully decrypted by the runner.
9070 expectedLocalError: "local error: bad record MAC",
9071 })
9072 testCases = append(testCases, testCase{
9073 testType: clientTest,
9074 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 Bugs: ProtocolBugs{
9078 SendUnencryptedALPN: "foo",
9079 },
9080 },
9081 flags: []string{
9082 "-advertise-alpn", "\x03foo\x03bar",
9083 },
9084 shouldFail: true,
9085 expectedError: ":UNEXPECTED_EXTENSION:",
9086 // The shim must send an alert, but alerts at this point do not
9087 // get successfully decrypted by the runner.
9088 expectedLocalError: "local error: bad record MAC",
9089 })
David Benjamin0c40a962016-08-01 12:05:50 -04009090
9091 // Test a known but unoffered extension from the server.
9092 testCases = append(testCases, testCase{
9093 testType: clientTest,
9094 name: "UnofferedExtension-Client",
9095 config: Config{
9096 MaxVersion: VersionTLS12,
9097 Bugs: ProtocolBugs{
9098 SendALPN: "alpn",
9099 },
9100 },
9101 shouldFail: true,
9102 expectedError: ":UNEXPECTED_EXTENSION:",
9103 expectedLocalError: "remote error: unsupported extension",
9104 })
9105 testCases = append(testCases, testCase{
9106 testType: clientTest,
9107 name: "UnofferedExtension-Client-TLS13",
9108 config: Config{
9109 MaxVersion: VersionTLS13,
9110 Bugs: ProtocolBugs{
9111 SendALPN: "alpn",
9112 },
9113 },
9114 shouldFail: true,
9115 expectedError: ":UNEXPECTED_EXTENSION:",
9116 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009117 })
Adam Langley09505632015-07-30 18:10:13 -07009118}
9119
David Benjaminb36a3952015-12-01 18:53:13 -05009120func addRSAClientKeyExchangeTests() {
9121 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9122 testCases = append(testCases, testCase{
9123 testType: serverTest,
9124 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9125 config: Config{
9126 // Ensure the ClientHello version and final
9127 // version are different, to detect if the
9128 // server uses the wrong one.
9129 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009130 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009131 Bugs: ProtocolBugs{
9132 BadRSAClientKeyExchange: bad,
9133 },
9134 },
9135 shouldFail: true,
9136 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9137 })
9138 }
David Benjamine63d9d72016-09-19 18:27:34 -04009139
9140 // The server must compare whatever was in ClientHello.version for the
9141 // RSA premaster.
9142 testCases = append(testCases, testCase{
9143 testType: serverTest,
9144 name: "SendClientVersion-RSA",
9145 config: Config{
9146 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9147 Bugs: ProtocolBugs{
9148 SendClientVersion: 0x1234,
9149 },
9150 },
9151 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9152 })
David Benjaminb36a3952015-12-01 18:53:13 -05009153}
9154
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009155var testCurves = []struct {
9156 name string
9157 id CurveID
9158}{
Adam Langley764ab982017-03-10 18:01:30 -08009159 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009160 {"P-256", CurveP256},
9161 {"P-384", CurveP384},
9162 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009163 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009164}
9165
Steven Valdez5440fe02016-07-18 12:40:30 -04009166const bogusCurve = 0x1234
9167
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009168func addCurveTests() {
9169 for _, curve := range testCurves {
9170 testCases = append(testCases, testCase{
9171 name: "CurveTest-Client-" + curve.name,
9172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009173 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9175 CurvePreferences: []CurveID{curve.id},
9176 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009177 flags: []string{
9178 "-enable-all-curves",
9179 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9180 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009181 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009182 })
9183 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009184 name: "CurveTest-Client-" + curve.name + "-TLS13",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009187 CurvePreferences: []CurveID{curve.id},
9188 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009189 flags: []string{
9190 "-enable-all-curves",
9191 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9192 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009193 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009194 })
9195 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009196 testType: serverTest,
9197 name: "CurveTest-Server-" + curve.name,
9198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009199 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9201 CurvePreferences: []CurveID{curve.id},
9202 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009203 flags: []string{
9204 "-enable-all-curves",
9205 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9206 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009207 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009208 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009209 testCases = append(testCases, testCase{
9210 testType: serverTest,
9211 name: "CurveTest-Server-" + curve.name + "-TLS13",
9212 config: Config{
9213 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009214 CurvePreferences: []CurveID{curve.id},
9215 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009216 flags: []string{
9217 "-enable-all-curves",
9218 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9219 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009220 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009221 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009222 }
David Benjamin241ae832016-01-15 03:04:54 -05009223
9224 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009225 testCases = append(testCases, testCase{
9226 testType: serverTest,
9227 name: "UnknownCurve",
9228 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009229 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009230 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9231 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9232 },
9233 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009234
Steven Valdez803c77a2016-09-06 14:13:43 -04009235 // The server must be tolerant to bogus curves.
9236 testCases = append(testCases, testCase{
9237 testType: serverTest,
9238 name: "UnknownCurve-TLS13",
9239 config: Config{
9240 MaxVersion: VersionTLS13,
9241 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9242 },
9243 })
9244
David Benjamin4c3ddf72016-06-29 18:13:53 -04009245 // The server must not consider ECDHE ciphers when there are no
9246 // supported curves.
9247 testCases = append(testCases, testCase{
9248 testType: serverTest,
9249 name: "NoSupportedCurves",
9250 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009251 MaxVersion: VersionTLS12,
9252 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9253 Bugs: ProtocolBugs{
9254 NoSupportedCurves: true,
9255 },
9256 },
9257 shouldFail: true,
9258 expectedError: ":NO_SHARED_CIPHER:",
9259 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009260 testCases = append(testCases, testCase{
9261 testType: serverTest,
9262 name: "NoSupportedCurves-TLS13",
9263 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009264 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009265 Bugs: ProtocolBugs{
9266 NoSupportedCurves: true,
9267 },
9268 },
9269 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009270 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009271 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009272
9273 // The server must fall back to another cipher when there are no
9274 // supported curves.
9275 testCases = append(testCases, testCase{
9276 testType: serverTest,
9277 name: "NoCommonCurves",
9278 config: Config{
9279 MaxVersion: VersionTLS12,
9280 CipherSuites: []uint16{
9281 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009282 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009283 },
9284 CurvePreferences: []CurveID{CurveP224},
9285 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009286 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009287 })
9288
9289 // The client must reject bogus curves and disabled curves.
9290 testCases = append(testCases, testCase{
9291 name: "BadECDHECurve",
9292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009293 MaxVersion: VersionTLS12,
9294 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9295 Bugs: ProtocolBugs{
9296 SendCurve: bogusCurve,
9297 },
9298 },
9299 shouldFail: true,
9300 expectedError: ":WRONG_CURVE:",
9301 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009302 testCases = append(testCases, testCase{
9303 name: "BadECDHECurve-TLS13",
9304 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009305 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009306 Bugs: ProtocolBugs{
9307 SendCurve: bogusCurve,
9308 },
9309 },
9310 shouldFail: true,
9311 expectedError: ":WRONG_CURVE:",
9312 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009313
9314 testCases = append(testCases, testCase{
9315 name: "UnsupportedCurve",
9316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009317 MaxVersion: VersionTLS12,
9318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9319 CurvePreferences: []CurveID{CurveP256},
9320 Bugs: ProtocolBugs{
9321 IgnorePeerCurvePreferences: true,
9322 },
9323 },
9324 flags: []string{"-p384-only"},
9325 shouldFail: true,
9326 expectedError: ":WRONG_CURVE:",
9327 })
9328
David Benjamin4f921572016-07-17 14:20:10 +02009329 testCases = append(testCases, testCase{
9330 // TODO(davidben): Add a TLS 1.3 version where
9331 // HelloRetryRequest requests an unsupported curve.
9332 name: "UnsupportedCurve-ServerHello-TLS13",
9333 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009334 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009335 CurvePreferences: []CurveID{CurveP384},
9336 Bugs: ProtocolBugs{
9337 SendCurve: CurveP256,
9338 },
9339 },
9340 flags: []string{"-p384-only"},
9341 shouldFail: true,
9342 expectedError: ":WRONG_CURVE:",
9343 })
9344
David Benjamin4c3ddf72016-06-29 18:13:53 -04009345 // Test invalid curve points.
9346 testCases = append(testCases, testCase{
9347 name: "InvalidECDHPoint-Client",
9348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009349 MaxVersion: VersionTLS12,
9350 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9351 CurvePreferences: []CurveID{CurveP256},
9352 Bugs: ProtocolBugs{
9353 InvalidECDHPoint: true,
9354 },
9355 },
9356 shouldFail: true,
9357 expectedError: ":INVALID_ENCODING:",
9358 })
9359 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009360 name: "InvalidECDHPoint-Client-TLS13",
9361 config: Config{
9362 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009363 CurvePreferences: []CurveID{CurveP256},
9364 Bugs: ProtocolBugs{
9365 InvalidECDHPoint: true,
9366 },
9367 },
9368 shouldFail: true,
9369 expectedError: ":INVALID_ENCODING:",
9370 })
9371 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009372 testType: serverTest,
9373 name: "InvalidECDHPoint-Server",
9374 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009375 MaxVersion: VersionTLS12,
9376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9377 CurvePreferences: []CurveID{CurveP256},
9378 Bugs: ProtocolBugs{
9379 InvalidECDHPoint: true,
9380 },
9381 },
9382 shouldFail: true,
9383 expectedError: ":INVALID_ENCODING:",
9384 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009385 testCases = append(testCases, testCase{
9386 testType: serverTest,
9387 name: "InvalidECDHPoint-Server-TLS13",
9388 config: Config{
9389 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009390 CurvePreferences: []CurveID{CurveP256},
9391 Bugs: ProtocolBugs{
9392 InvalidECDHPoint: true,
9393 },
9394 },
9395 shouldFail: true,
9396 expectedError: ":INVALID_ENCODING:",
9397 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009398
9399 // The previous curve ID should be reported on TLS 1.2 resumption.
9400 testCases = append(testCases, testCase{
9401 name: "CurveID-Resume-Client",
9402 config: Config{
9403 MaxVersion: VersionTLS12,
9404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9405 CurvePreferences: []CurveID{CurveX25519},
9406 },
9407 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9408 resumeSession: true,
9409 })
9410 testCases = append(testCases, testCase{
9411 testType: serverTest,
9412 name: "CurveID-Resume-Server",
9413 config: Config{
9414 MaxVersion: VersionTLS12,
9415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9416 CurvePreferences: []CurveID{CurveX25519},
9417 },
9418 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9419 resumeSession: true,
9420 })
9421
9422 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9423 // one should be reported.
9424 testCases = append(testCases, testCase{
9425 name: "CurveID-Resume-Client-TLS13",
9426 config: Config{
9427 MaxVersion: VersionTLS13,
9428 CurvePreferences: []CurveID{CurveX25519},
9429 },
9430 resumeConfig: &Config{
9431 MaxVersion: VersionTLS13,
9432 CurvePreferences: []CurveID{CurveP256},
9433 },
9434 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009435 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9436 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009437 },
9438 resumeSession: true,
9439 })
9440 testCases = append(testCases, testCase{
9441 testType: serverTest,
9442 name: "CurveID-Resume-Server-TLS13",
9443 config: Config{
9444 MaxVersion: VersionTLS13,
9445 CurvePreferences: []CurveID{CurveX25519},
9446 },
9447 resumeConfig: &Config{
9448 MaxVersion: VersionTLS13,
9449 CurvePreferences: []CurveID{CurveP256},
9450 },
9451 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009452 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9453 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009454 },
9455 resumeSession: true,
9456 })
David Benjamina81967b2016-12-22 09:16:57 -05009457
9458 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9459 testCases = append(testCases, testCase{
9460 name: "PointFormat-ServerHello-TLS12",
9461 config: Config{
9462 MaxVersion: VersionTLS12,
9463 Bugs: ProtocolBugs{
9464 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9465 },
9466 },
9467 })
9468 testCases = append(testCases, testCase{
9469 name: "PointFormat-EncryptedExtensions-TLS13",
9470 config: Config{
9471 MaxVersion: VersionTLS13,
9472 Bugs: ProtocolBugs{
9473 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9474 },
9475 },
9476 shouldFail: true,
9477 expectedError: ":ERROR_PARSING_EXTENSION:",
9478 })
9479
9480 // Test that we tolerate unknown point formats, as long as
9481 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9482 // check they are still functional.
9483 testCases = append(testCases, testCase{
9484 name: "PointFormat-Client-Tolerance",
9485 config: Config{
9486 MaxVersion: VersionTLS12,
9487 Bugs: ProtocolBugs{
9488 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9489 },
9490 },
9491 })
9492 testCases = append(testCases, testCase{
9493 testType: serverTest,
9494 name: "PointFormat-Server-Tolerance",
9495 config: Config{
9496 MaxVersion: VersionTLS12,
9497 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9498 Bugs: ProtocolBugs{
9499 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9500 },
9501 },
9502 })
9503
9504 // Test TLS 1.2 does not require the point format extension to be
9505 // present.
9506 testCases = append(testCases, testCase{
9507 name: "PointFormat-Client-Missing",
9508 config: Config{
9509 MaxVersion: VersionTLS12,
9510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9511 Bugs: ProtocolBugs{
9512 SendSupportedPointFormats: []byte{},
9513 },
9514 },
9515 })
9516 testCases = append(testCases, testCase{
9517 testType: serverTest,
9518 name: "PointFormat-Server-Missing",
9519 config: Config{
9520 MaxVersion: VersionTLS12,
9521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9522 Bugs: ProtocolBugs{
9523 SendSupportedPointFormats: []byte{},
9524 },
9525 },
9526 })
9527
9528 // If the point format extension is present, uncompressed points must be
9529 // offered. BoringSSL requires this whether or not ECDHE is used.
9530 testCases = append(testCases, testCase{
9531 name: "PointFormat-Client-MissingUncompressed",
9532 config: Config{
9533 MaxVersion: VersionTLS12,
9534 Bugs: ProtocolBugs{
9535 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9536 },
9537 },
9538 shouldFail: true,
9539 expectedError: ":ERROR_PARSING_EXTENSION:",
9540 })
9541 testCases = append(testCases, testCase{
9542 testType: serverTest,
9543 name: "PointFormat-Server-MissingUncompressed",
9544 config: Config{
9545 MaxVersion: VersionTLS12,
9546 Bugs: ProtocolBugs{
9547 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9548 },
9549 },
9550 shouldFail: true,
9551 expectedError: ":ERROR_PARSING_EXTENSION:",
9552 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009553}
9554
David Benjaminc9ae27c2016-06-24 22:56:37 -04009555func addTLS13RecordTests() {
9556 testCases = append(testCases, testCase{
9557 name: "TLS13-RecordPadding",
9558 config: Config{
9559 MaxVersion: VersionTLS13,
9560 MinVersion: VersionTLS13,
9561 Bugs: ProtocolBugs{
9562 RecordPadding: 10,
9563 },
9564 },
9565 })
9566
9567 testCases = append(testCases, testCase{
9568 name: "TLS13-EmptyRecords",
9569 config: Config{
9570 MaxVersion: VersionTLS13,
9571 MinVersion: VersionTLS13,
9572 Bugs: ProtocolBugs{
9573 OmitRecordContents: true,
9574 },
9575 },
9576 shouldFail: true,
9577 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9578 })
9579
9580 testCases = append(testCases, testCase{
9581 name: "TLS13-OnlyPadding",
9582 config: Config{
9583 MaxVersion: VersionTLS13,
9584 MinVersion: VersionTLS13,
9585 Bugs: ProtocolBugs{
9586 OmitRecordContents: true,
9587 RecordPadding: 10,
9588 },
9589 },
9590 shouldFail: true,
9591 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9592 })
9593
9594 testCases = append(testCases, testCase{
9595 name: "TLS13-WrongOuterRecord",
9596 config: Config{
9597 MaxVersion: VersionTLS13,
9598 MinVersion: VersionTLS13,
9599 Bugs: ProtocolBugs{
9600 OuterRecordType: recordTypeHandshake,
9601 },
9602 },
9603 shouldFail: true,
9604 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9605 })
9606}
9607
Steven Valdez5b986082016-09-01 12:29:49 -04009608func addSessionTicketTests() {
9609 testCases = append(testCases, testCase{
9610 // In TLS 1.2 and below, empty NewSessionTicket messages
9611 // mean the server changed its mind on sending a ticket.
9612 name: "SendEmptySessionTicket",
9613 config: Config{
9614 MaxVersion: VersionTLS12,
9615 Bugs: ProtocolBugs{
9616 SendEmptySessionTicket: true,
9617 },
9618 },
9619 flags: []string{"-expect-no-session"},
9620 })
9621
9622 // Test that the server ignores unknown PSK modes.
9623 testCases = append(testCases, testCase{
9624 testType: serverTest,
9625 name: "TLS13-SendUnknownModeSessionTicket-Server",
9626 config: Config{
9627 MaxVersion: VersionTLS13,
9628 Bugs: ProtocolBugs{
9629 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009630 },
9631 },
9632 resumeSession: true,
9633 expectedResumeVersion: VersionTLS13,
9634 })
9635
Steven Valdeza833c352016-11-01 13:39:36 -04009636 // Test that the server does not send session tickets with no matching key exchange mode.
9637 testCases = append(testCases, testCase{
9638 testType: serverTest,
9639 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9640 config: Config{
9641 MaxVersion: VersionTLS13,
9642 Bugs: ProtocolBugs{
9643 SendPSKKeyExchangeModes: []byte{0x1a},
9644 ExpectNoNewSessionTicket: true,
9645 },
9646 },
9647 })
9648
9649 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009650 testCases = append(testCases, testCase{
9651 testType: serverTest,
9652 name: "TLS13-SendBadKEModeSessionTicket-Server",
9653 config: Config{
9654 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009655 },
9656 resumeConfig: &Config{
9657 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009658 Bugs: ProtocolBugs{
9659 SendPSKKeyExchangeModes: []byte{0x1a},
9660 },
9661 },
9662 resumeSession: true,
9663 expectResumeRejected: true,
9664 })
9665
Steven Valdeza833c352016-11-01 13:39:36 -04009666 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009667 testCases = append(testCases, testCase{
9668 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009669 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009670 config: Config{
9671 MaxVersion: VersionTLS13,
9672 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009673 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009674 },
9675 },
Steven Valdeza833c352016-11-01 13:39:36 -04009676 resumeSession: true,
9677 flags: []string{
9678 "-resumption-delay", "10",
9679 },
Steven Valdez5b986082016-09-01 12:29:49 -04009680 })
9681
Steven Valdeza833c352016-11-01 13:39:36 -04009682 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009683 testCases = append(testCases, testCase{
9684 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009685 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009686 config: Config{
9687 MaxVersion: VersionTLS13,
9688 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009689 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009690 },
9691 },
Steven Valdeza833c352016-11-01 13:39:36 -04009692 resumeSession: true,
9693 shouldFail: true,
9694 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009695 })
9696
David Benjamin35ac5b72017-03-03 15:05:56 -05009697 // Test that the server's ticket age skew reporting works.
9698 testCases = append(testCases, testCase{
9699 testType: serverTest,
9700 name: "TLS13-TicketAgeSkew-Forward",
9701 config: Config{
9702 MaxVersion: VersionTLS13,
9703 Bugs: ProtocolBugs{
9704 SendTicketAge: 15 * time.Second,
9705 },
9706 },
David Benjamin065d7332017-03-26 10:51:43 -05009707 resumeSession: true,
9708 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009709 flags: []string{
9710 "-resumption-delay", "10",
9711 "-expect-ticket-age-skew", "5",
9712 },
9713 })
9714 testCases = append(testCases, testCase{
9715 testType: serverTest,
9716 name: "TLS13-TicketAgeSkew-Backward",
9717 config: Config{
9718 MaxVersion: VersionTLS13,
9719 Bugs: ProtocolBugs{
9720 SendTicketAge: 5 * time.Second,
9721 },
9722 },
David Benjamin065d7332017-03-26 10:51:43 -05009723 resumeSession: true,
9724 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009725 flags: []string{
9726 "-resumption-delay", "10",
9727 "-expect-ticket-age-skew", "-5",
9728 },
9729 })
9730
Steven Valdez08b65f42016-12-07 15:29:45 -05009731 testCases = append(testCases, testCase{
9732 testType: clientTest,
9733 name: "TLS13-SendTicketEarlyDataInfo",
9734 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009735 MaxVersion: VersionTLS13,
9736 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009737 },
9738 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009739 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009740 "-expect-early-data-info",
9741 },
9742 })
9743
David Benjamin9b160662017-01-25 19:53:43 -05009744 // Test that 0-RTT tickets are ignored in clients unless opted in.
9745 testCases = append(testCases, testCase{
9746 testType: clientTest,
9747 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9748 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009749 MaxVersion: VersionTLS13,
9750 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009751 },
9752 })
9753
Steven Valdez08b65f42016-12-07 15:29:45 -05009754 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009755 testType: clientTest,
9756 name: "TLS13-DuplicateTicketEarlyDataInfo",
9757 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009758 MaxVersion: VersionTLS13,
9759 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009760 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009761 DuplicateTicketEarlyDataInfo: true,
9762 },
9763 },
9764 shouldFail: true,
9765 expectedError: ":DUPLICATE_EXTENSION:",
9766 expectedLocalError: "remote error: illegal parameter",
9767 })
9768
9769 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009770 testType: serverTest,
9771 name: "TLS13-ExpectTicketEarlyDataInfo",
9772 config: Config{
9773 MaxVersion: VersionTLS13,
9774 Bugs: ProtocolBugs{
9775 ExpectTicketEarlyDataInfo: true,
9776 },
9777 },
9778 flags: []string{
9779 "-enable-early-data",
9780 },
9781 })
David Benjamin17b30832017-01-28 14:00:32 -05009782
9783 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9784 // is honored.
9785 testCases = append(testCases, testCase{
9786 testType: clientTest,
9787 name: "TLS13-HonorServerSessionTicketLifetime",
9788 config: Config{
9789 MaxVersion: VersionTLS13,
9790 Bugs: ProtocolBugs{
9791 SendTicketLifetime: 20 * time.Second,
9792 },
9793 },
9794 flags: []string{
9795 "-resumption-delay", "19",
9796 },
9797 resumeSession: true,
9798 })
9799 testCases = append(testCases, testCase{
9800 testType: clientTest,
9801 name: "TLS13-HonorServerSessionTicketLifetime-2",
9802 config: Config{
9803 MaxVersion: VersionTLS13,
9804 Bugs: ProtocolBugs{
9805 SendTicketLifetime: 20 * time.Second,
9806 // The client should not offer the expired session.
9807 ExpectNoTLS13PSK: true,
9808 },
9809 },
9810 flags: []string{
9811 "-resumption-delay", "21",
9812 },
David Benjamin023d4192017-02-06 13:49:07 -05009813 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009814 expectResumeRejected: true,
9815 })
Steven Valdez5b986082016-09-01 12:29:49 -04009816}
9817
David Benjamin82261be2016-07-07 14:32:50 -07009818func addChangeCipherSpecTests() {
9819 // Test missing ChangeCipherSpecs.
9820 testCases = append(testCases, testCase{
9821 name: "SkipChangeCipherSpec-Client",
9822 config: Config{
9823 MaxVersion: VersionTLS12,
9824 Bugs: ProtocolBugs{
9825 SkipChangeCipherSpec: true,
9826 },
9827 },
9828 shouldFail: true,
9829 expectedError: ":UNEXPECTED_RECORD:",
9830 })
9831 testCases = append(testCases, testCase{
9832 testType: serverTest,
9833 name: "SkipChangeCipherSpec-Server",
9834 config: Config{
9835 MaxVersion: VersionTLS12,
9836 Bugs: ProtocolBugs{
9837 SkipChangeCipherSpec: true,
9838 },
9839 },
9840 shouldFail: true,
9841 expectedError: ":UNEXPECTED_RECORD:",
9842 })
9843 testCases = append(testCases, testCase{
9844 testType: serverTest,
9845 name: "SkipChangeCipherSpec-Server-NPN",
9846 config: Config{
9847 MaxVersion: VersionTLS12,
9848 NextProtos: []string{"bar"},
9849 Bugs: ProtocolBugs{
9850 SkipChangeCipherSpec: true,
9851 },
9852 },
9853 flags: []string{
9854 "-advertise-npn", "\x03foo\x03bar\x03baz",
9855 },
9856 shouldFail: true,
9857 expectedError: ":UNEXPECTED_RECORD:",
9858 })
9859
9860 // Test synchronization between the handshake and ChangeCipherSpec.
9861 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9862 // rejected. Test both with and without handshake packing to handle both
9863 // when the partial post-CCS message is in its own record and when it is
9864 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009865 for _, packed := range []bool{false, true} {
9866 var suffix string
9867 if packed {
9868 suffix = "-Packed"
9869 }
9870
9871 testCases = append(testCases, testCase{
9872 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9873 config: Config{
9874 MaxVersion: VersionTLS12,
9875 Bugs: ProtocolBugs{
9876 FragmentAcrossChangeCipherSpec: true,
9877 PackHandshakeFlight: packed,
9878 },
9879 },
9880 shouldFail: true,
9881 expectedError: ":UNEXPECTED_RECORD:",
9882 })
9883 testCases = append(testCases, testCase{
9884 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9885 config: Config{
9886 MaxVersion: VersionTLS12,
9887 },
9888 resumeSession: true,
9889 resumeConfig: &Config{
9890 MaxVersion: VersionTLS12,
9891 Bugs: ProtocolBugs{
9892 FragmentAcrossChangeCipherSpec: true,
9893 PackHandshakeFlight: packed,
9894 },
9895 },
9896 shouldFail: true,
9897 expectedError: ":UNEXPECTED_RECORD:",
9898 })
9899 testCases = append(testCases, testCase{
9900 testType: serverTest,
9901 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9902 config: Config{
9903 MaxVersion: VersionTLS12,
9904 Bugs: ProtocolBugs{
9905 FragmentAcrossChangeCipherSpec: true,
9906 PackHandshakeFlight: packed,
9907 },
9908 },
9909 shouldFail: true,
9910 expectedError: ":UNEXPECTED_RECORD:",
9911 })
9912 testCases = append(testCases, testCase{
9913 testType: serverTest,
9914 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9915 config: Config{
9916 MaxVersion: VersionTLS12,
9917 },
9918 resumeSession: true,
9919 resumeConfig: &Config{
9920 MaxVersion: VersionTLS12,
9921 Bugs: ProtocolBugs{
9922 FragmentAcrossChangeCipherSpec: true,
9923 PackHandshakeFlight: packed,
9924 },
9925 },
9926 shouldFail: true,
9927 expectedError: ":UNEXPECTED_RECORD:",
9928 })
9929 testCases = append(testCases, testCase{
9930 testType: serverTest,
9931 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9932 config: Config{
9933 MaxVersion: VersionTLS12,
9934 NextProtos: []string{"bar"},
9935 Bugs: ProtocolBugs{
9936 FragmentAcrossChangeCipherSpec: true,
9937 PackHandshakeFlight: packed,
9938 },
9939 },
9940 flags: []string{
9941 "-advertise-npn", "\x03foo\x03bar\x03baz",
9942 },
9943 shouldFail: true,
9944 expectedError: ":UNEXPECTED_RECORD:",
9945 })
9946 }
9947
David Benjamin61672812016-07-14 23:10:43 -04009948 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9949 // messages in the handshake queue. Do this by testing the server
9950 // reading the client Finished, reversing the flight so Finished comes
9951 // first.
9952 testCases = append(testCases, testCase{
9953 protocol: dtls,
9954 testType: serverTest,
9955 name: "SendUnencryptedFinished-DTLS",
9956 config: Config{
9957 MaxVersion: VersionTLS12,
9958 Bugs: ProtocolBugs{
9959 SendUnencryptedFinished: true,
9960 ReverseHandshakeFragments: true,
9961 },
9962 },
9963 shouldFail: true,
9964 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9965 })
9966
Steven Valdez143e8b32016-07-11 13:19:03 -04009967 // Test synchronization between encryption changes and the handshake in
9968 // TLS 1.3, where ChangeCipherSpec is implicit.
9969 testCases = append(testCases, testCase{
9970 name: "PartialEncryptedExtensionsWithServerHello",
9971 config: Config{
9972 MaxVersion: VersionTLS13,
9973 Bugs: ProtocolBugs{
9974 PartialEncryptedExtensionsWithServerHello: true,
9975 },
9976 },
9977 shouldFail: true,
9978 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9979 })
9980 testCases = append(testCases, testCase{
9981 testType: serverTest,
9982 name: "PartialClientFinishedWithClientHello",
9983 config: Config{
9984 MaxVersion: VersionTLS13,
9985 Bugs: ProtocolBugs{
9986 PartialClientFinishedWithClientHello: true,
9987 },
9988 },
9989 shouldFail: true,
9990 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9991 })
9992
David Benjamin82261be2016-07-07 14:32:50 -07009993 // Test that early ChangeCipherSpecs are handled correctly.
9994 testCases = append(testCases, testCase{
9995 testType: serverTest,
9996 name: "EarlyChangeCipherSpec-server-1",
9997 config: Config{
9998 MaxVersion: VersionTLS12,
9999 Bugs: ProtocolBugs{
10000 EarlyChangeCipherSpec: 1,
10001 },
10002 },
10003 shouldFail: true,
10004 expectedError: ":UNEXPECTED_RECORD:",
10005 })
10006 testCases = append(testCases, testCase{
10007 testType: serverTest,
10008 name: "EarlyChangeCipherSpec-server-2",
10009 config: Config{
10010 MaxVersion: VersionTLS12,
10011 Bugs: ProtocolBugs{
10012 EarlyChangeCipherSpec: 2,
10013 },
10014 },
10015 shouldFail: true,
10016 expectedError: ":UNEXPECTED_RECORD:",
10017 })
10018 testCases = append(testCases, testCase{
10019 protocol: dtls,
10020 name: "StrayChangeCipherSpec",
10021 config: Config{
10022 // TODO(davidben): Once DTLS 1.3 exists, test
10023 // that stray ChangeCipherSpec messages are
10024 // rejected.
10025 MaxVersion: VersionTLS12,
10026 Bugs: ProtocolBugs{
10027 StrayChangeCipherSpec: true,
10028 },
10029 },
10030 })
10031
10032 // Test that the contents of ChangeCipherSpec are checked.
10033 testCases = append(testCases, testCase{
10034 name: "BadChangeCipherSpec-1",
10035 config: Config{
10036 MaxVersion: VersionTLS12,
10037 Bugs: ProtocolBugs{
10038 BadChangeCipherSpec: []byte{2},
10039 },
10040 },
10041 shouldFail: true,
10042 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10043 })
10044 testCases = append(testCases, testCase{
10045 name: "BadChangeCipherSpec-2",
10046 config: Config{
10047 MaxVersion: VersionTLS12,
10048 Bugs: ProtocolBugs{
10049 BadChangeCipherSpec: []byte{1, 1},
10050 },
10051 },
10052 shouldFail: true,
10053 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10054 })
10055 testCases = append(testCases, testCase{
10056 protocol: dtls,
10057 name: "BadChangeCipherSpec-DTLS-1",
10058 config: Config{
10059 MaxVersion: VersionTLS12,
10060 Bugs: ProtocolBugs{
10061 BadChangeCipherSpec: []byte{2},
10062 },
10063 },
10064 shouldFail: true,
10065 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10066 })
10067 testCases = append(testCases, testCase{
10068 protocol: dtls,
10069 name: "BadChangeCipherSpec-DTLS-2",
10070 config: Config{
10071 MaxVersion: VersionTLS12,
10072 Bugs: ProtocolBugs{
10073 BadChangeCipherSpec: []byte{1, 1},
10074 },
10075 },
10076 shouldFail: true,
10077 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10078 })
10079}
10080
David Benjamincd2c8062016-09-09 11:28:16 -040010081type perMessageTest struct {
10082 messageType uint8
10083 test testCase
10084}
10085
10086// makePerMessageTests returns a series of test templates which cover each
10087// message in the TLS handshake. These may be used with bugs like
10088// WrongMessageType to fully test a per-message bug.
10089func makePerMessageTests() []perMessageTest {
10090 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010091 for _, protocol := range []protocol{tls, dtls} {
10092 var suffix string
10093 if protocol == dtls {
10094 suffix = "-DTLS"
10095 }
10096
David Benjamincd2c8062016-09-09 11:28:16 -040010097 ret = append(ret, perMessageTest{
10098 messageType: typeClientHello,
10099 test: testCase{
10100 protocol: protocol,
10101 testType: serverTest,
10102 name: "ClientHello" + suffix,
10103 config: Config{
10104 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010105 },
10106 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010107 })
10108
10109 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010110 ret = append(ret, perMessageTest{
10111 messageType: typeHelloVerifyRequest,
10112 test: testCase{
10113 protocol: protocol,
10114 name: "HelloVerifyRequest" + suffix,
10115 config: Config{
10116 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010117 },
10118 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010119 })
10120 }
10121
David Benjamincd2c8062016-09-09 11:28:16 -040010122 ret = append(ret, perMessageTest{
10123 messageType: typeServerHello,
10124 test: testCase{
10125 protocol: protocol,
10126 name: "ServerHello" + suffix,
10127 config: Config{
10128 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010129 },
10130 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010131 })
10132
David Benjamincd2c8062016-09-09 11:28:16 -040010133 ret = append(ret, perMessageTest{
10134 messageType: typeCertificate,
10135 test: testCase{
10136 protocol: protocol,
10137 name: "ServerCertificate" + suffix,
10138 config: Config{
10139 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010140 },
10141 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010142 })
10143
David Benjamincd2c8062016-09-09 11:28:16 -040010144 ret = append(ret, perMessageTest{
10145 messageType: typeCertificateStatus,
10146 test: testCase{
10147 protocol: protocol,
10148 name: "CertificateStatus" + suffix,
10149 config: Config{
10150 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010151 },
David Benjamincd2c8062016-09-09 11:28:16 -040010152 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010153 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010154 })
10155
David Benjamincd2c8062016-09-09 11:28:16 -040010156 ret = append(ret, perMessageTest{
10157 messageType: typeServerKeyExchange,
10158 test: testCase{
10159 protocol: protocol,
10160 name: "ServerKeyExchange" + suffix,
10161 config: Config{
10162 MaxVersion: VersionTLS12,
10163 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010164 },
10165 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010166 })
10167
David Benjamincd2c8062016-09-09 11:28:16 -040010168 ret = append(ret, perMessageTest{
10169 messageType: typeCertificateRequest,
10170 test: testCase{
10171 protocol: protocol,
10172 name: "CertificateRequest" + suffix,
10173 config: Config{
10174 MaxVersion: VersionTLS12,
10175 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010176 },
10177 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010178 })
10179
David Benjamincd2c8062016-09-09 11:28:16 -040010180 ret = append(ret, perMessageTest{
10181 messageType: typeServerHelloDone,
10182 test: testCase{
10183 protocol: protocol,
10184 name: "ServerHelloDone" + suffix,
10185 config: Config{
10186 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010187 },
10188 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010189 })
10190
David Benjamincd2c8062016-09-09 11:28:16 -040010191 ret = append(ret, perMessageTest{
10192 messageType: typeCertificate,
10193 test: testCase{
10194 testType: serverTest,
10195 protocol: protocol,
10196 name: "ClientCertificate" + suffix,
10197 config: Config{
10198 Certificates: []Certificate{rsaCertificate},
10199 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010200 },
David Benjamincd2c8062016-09-09 11:28:16 -040010201 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010202 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010203 })
10204
David Benjamincd2c8062016-09-09 11:28:16 -040010205 ret = append(ret, perMessageTest{
10206 messageType: typeCertificateVerify,
10207 test: testCase{
10208 testType: serverTest,
10209 protocol: protocol,
10210 name: "CertificateVerify" + suffix,
10211 config: Config{
10212 Certificates: []Certificate{rsaCertificate},
10213 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010214 },
David Benjamincd2c8062016-09-09 11:28:16 -040010215 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010216 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010217 })
10218
David Benjamincd2c8062016-09-09 11:28:16 -040010219 ret = append(ret, perMessageTest{
10220 messageType: typeClientKeyExchange,
10221 test: testCase{
10222 testType: serverTest,
10223 protocol: protocol,
10224 name: "ClientKeyExchange" + suffix,
10225 config: Config{
10226 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010227 },
10228 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010229 })
10230
10231 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010232 ret = append(ret, perMessageTest{
10233 messageType: typeNextProtocol,
10234 test: testCase{
10235 testType: serverTest,
10236 protocol: protocol,
10237 name: "NextProtocol" + suffix,
10238 config: Config{
10239 MaxVersion: VersionTLS12,
10240 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010241 },
David Benjamincd2c8062016-09-09 11:28:16 -040010242 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010243 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010244 })
10245
David Benjamincd2c8062016-09-09 11:28:16 -040010246 ret = append(ret, perMessageTest{
10247 messageType: typeChannelID,
10248 test: testCase{
10249 testType: serverTest,
10250 protocol: protocol,
10251 name: "ChannelID" + suffix,
10252 config: Config{
10253 MaxVersion: VersionTLS12,
10254 ChannelID: channelIDKey,
10255 },
10256 flags: []string{
10257 "-expect-channel-id",
10258 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010259 },
10260 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010261 })
10262 }
10263
David Benjamincd2c8062016-09-09 11:28:16 -040010264 ret = append(ret, perMessageTest{
10265 messageType: typeFinished,
10266 test: testCase{
10267 testType: serverTest,
10268 protocol: protocol,
10269 name: "ClientFinished" + suffix,
10270 config: Config{
10271 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010272 },
10273 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010274 })
10275
David Benjamincd2c8062016-09-09 11:28:16 -040010276 ret = append(ret, perMessageTest{
10277 messageType: typeNewSessionTicket,
10278 test: testCase{
10279 protocol: protocol,
10280 name: "NewSessionTicket" + suffix,
10281 config: Config{
10282 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010283 },
10284 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010285 })
10286
David Benjamincd2c8062016-09-09 11:28:16 -040010287 ret = append(ret, perMessageTest{
10288 messageType: typeFinished,
10289 test: testCase{
10290 protocol: protocol,
10291 name: "ServerFinished" + suffix,
10292 config: Config{
10293 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010294 },
10295 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010296 })
10297
10298 }
David Benjamincd2c8062016-09-09 11:28:16 -040010299
10300 ret = append(ret, perMessageTest{
10301 messageType: typeClientHello,
10302 test: testCase{
10303 testType: serverTest,
10304 name: "TLS13-ClientHello",
10305 config: Config{
10306 MaxVersion: VersionTLS13,
10307 },
10308 },
10309 })
10310
10311 ret = append(ret, perMessageTest{
10312 messageType: typeServerHello,
10313 test: testCase{
10314 name: "TLS13-ServerHello",
10315 config: Config{
10316 MaxVersion: VersionTLS13,
10317 },
10318 },
10319 })
10320
10321 ret = append(ret, perMessageTest{
10322 messageType: typeEncryptedExtensions,
10323 test: testCase{
10324 name: "TLS13-EncryptedExtensions",
10325 config: Config{
10326 MaxVersion: VersionTLS13,
10327 },
10328 },
10329 })
10330
10331 ret = append(ret, perMessageTest{
10332 messageType: typeCertificateRequest,
10333 test: testCase{
10334 name: "TLS13-CertificateRequest",
10335 config: Config{
10336 MaxVersion: VersionTLS13,
10337 ClientAuth: RequireAnyClientCert,
10338 },
10339 },
10340 })
10341
10342 ret = append(ret, perMessageTest{
10343 messageType: typeCertificate,
10344 test: testCase{
10345 name: "TLS13-ServerCertificate",
10346 config: Config{
10347 MaxVersion: VersionTLS13,
10348 },
10349 },
10350 })
10351
10352 ret = append(ret, perMessageTest{
10353 messageType: typeCertificateVerify,
10354 test: testCase{
10355 name: "TLS13-ServerCertificateVerify",
10356 config: Config{
10357 MaxVersion: VersionTLS13,
10358 },
10359 },
10360 })
10361
10362 ret = append(ret, perMessageTest{
10363 messageType: typeFinished,
10364 test: testCase{
10365 name: "TLS13-ServerFinished",
10366 config: Config{
10367 MaxVersion: VersionTLS13,
10368 },
10369 },
10370 })
10371
10372 ret = append(ret, perMessageTest{
10373 messageType: typeCertificate,
10374 test: testCase{
10375 testType: serverTest,
10376 name: "TLS13-ClientCertificate",
10377 config: Config{
10378 Certificates: []Certificate{rsaCertificate},
10379 MaxVersion: VersionTLS13,
10380 },
10381 flags: []string{"-require-any-client-certificate"},
10382 },
10383 })
10384
10385 ret = append(ret, perMessageTest{
10386 messageType: typeCertificateVerify,
10387 test: testCase{
10388 testType: serverTest,
10389 name: "TLS13-ClientCertificateVerify",
10390 config: Config{
10391 Certificates: []Certificate{rsaCertificate},
10392 MaxVersion: VersionTLS13,
10393 },
10394 flags: []string{"-require-any-client-certificate"},
10395 },
10396 })
10397
10398 ret = append(ret, perMessageTest{
10399 messageType: typeFinished,
10400 test: testCase{
10401 testType: serverTest,
10402 name: "TLS13-ClientFinished",
10403 config: Config{
10404 MaxVersion: VersionTLS13,
10405 },
10406 },
10407 })
10408
10409 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010410}
10411
David Benjamincd2c8062016-09-09 11:28:16 -040010412func addWrongMessageTypeTests() {
10413 for _, t := range makePerMessageTests() {
10414 t.test.name = "WrongMessageType-" + t.test.name
10415 t.test.config.Bugs.SendWrongMessageType = t.messageType
10416 t.test.shouldFail = true
10417 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10418 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010419
David Benjamincd2c8062016-09-09 11:28:16 -040010420 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10421 // In TLS 1.3, a bad ServerHello means the client sends
10422 // an unencrypted alert while the server expects
10423 // encryption, so the alert is not readable by runner.
10424 t.test.expectedLocalError = "local error: bad record MAC"
10425 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010426
David Benjamincd2c8062016-09-09 11:28:16 -040010427 testCases = append(testCases, t.test)
10428 }
David Benjaminebacdee2017-04-08 11:00:45 -040010429
10430 // The processing order for TLS 1.3 version negotiation is such that one
10431 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10432 // TLS 1.2. Test that we do not do this.
10433 testCases = append(testCases, testCase{
10434 name: "SendServerHelloAsHelloRetryRequest",
10435 config: Config{
10436 MaxVersion: VersionTLS12,
10437 Bugs: ProtocolBugs{
10438 SendServerHelloAsHelloRetryRequest: true,
10439 },
10440 },
10441 shouldFail: true,
10442 expectedError: ":UNEXPECTED_MESSAGE:",
10443 expectedLocalError: "remote error: unexpected message",
10444 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010445}
10446
David Benjamin639846e2016-09-09 11:41:18 -040010447func addTrailingMessageDataTests() {
10448 for _, t := range makePerMessageTests() {
10449 t.test.name = "TrailingMessageData-" + t.test.name
10450 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10451 t.test.shouldFail = true
10452 t.test.expectedError = ":DECODE_ERROR:"
10453 t.test.expectedLocalError = "remote error: error decoding message"
10454
10455 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10456 // In TLS 1.3, a bad ServerHello means the client sends
10457 // an unencrypted alert while the server expects
10458 // encryption, so the alert is not readable by runner.
10459 t.test.expectedLocalError = "local error: bad record MAC"
10460 }
10461
10462 if t.messageType == typeFinished {
10463 // Bad Finished messages read as the verify data having
10464 // the wrong length.
10465 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10466 t.test.expectedLocalError = "remote error: error decrypting message"
10467 }
10468
10469 testCases = append(testCases, t.test)
10470 }
10471}
10472
Steven Valdez143e8b32016-07-11 13:19:03 -040010473func addTLS13HandshakeTests() {
10474 testCases = append(testCases, testCase{
10475 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010476 name: "NegotiatePSKResumption-TLS13",
10477 config: Config{
10478 MaxVersion: VersionTLS13,
10479 Bugs: ProtocolBugs{
10480 NegotiatePSKResumption: true,
10481 },
10482 },
10483 resumeSession: true,
10484 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010485 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010486 })
10487
10488 testCases = append(testCases, testCase{
10489 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010490 name: "MissingKeyShare-Client",
10491 config: Config{
10492 MaxVersion: VersionTLS13,
10493 Bugs: ProtocolBugs{
10494 MissingKeyShare: true,
10495 },
10496 },
10497 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010498 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010499 })
10500
10501 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010502 testType: serverTest,
10503 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010504 config: Config{
10505 MaxVersion: VersionTLS13,
10506 Bugs: ProtocolBugs{
10507 MissingKeyShare: true,
10508 },
10509 },
10510 shouldFail: true,
10511 expectedError: ":MISSING_KEY_SHARE:",
10512 })
10513
10514 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010515 testType: serverTest,
10516 name: "DuplicateKeyShares",
10517 config: Config{
10518 MaxVersion: VersionTLS13,
10519 Bugs: ProtocolBugs{
10520 DuplicateKeyShares: true,
10521 },
10522 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010523 shouldFail: true,
10524 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010525 })
10526
10527 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010528 testType: serverTest,
10529 name: "SkipEarlyData",
10530 config: Config{
10531 MaxVersion: VersionTLS13,
10532 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010533 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010534 },
10535 },
10536 })
10537
10538 testCases = append(testCases, testCase{
10539 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010540 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010541 config: Config{
10542 MaxVersion: VersionTLS13,
10543 TLS13Variant: TLS13Experiment,
10544 Bugs: ProtocolBugs{
10545 SendFakeEarlyDataLength: 4,
10546 },
10547 },
10548 flags: []string{"-tls13-variant", "1"},
10549 })
10550
10551 testCases = append(testCases, testCase{
10552 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010553 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10554 config: Config{
10555 MaxVersion: VersionTLS13,
10556 TLS13Variant: TLS13RecordTypeExperiment,
10557 Bugs: ProtocolBugs{
10558 SendFakeEarlyDataLength: 4,
10559 },
10560 },
10561 flags: []string{"-tls13-variant", "2"},
10562 })
10563
10564 testCases = append(testCases, testCase{
10565 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010566 name: "SkipEarlyData-OmitEarlyDataExtension",
10567 config: Config{
10568 MaxVersion: VersionTLS13,
10569 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010570 SendFakeEarlyDataLength: 4,
10571 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010572 },
10573 },
10574 shouldFail: true,
10575 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10576 })
10577
10578 testCases = append(testCases, testCase{
10579 testType: serverTest,
10580 name: "SkipEarlyData-TooMuchData",
10581 config: Config{
10582 MaxVersion: VersionTLS13,
10583 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010584 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010585 },
10586 },
10587 shouldFail: true,
10588 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10589 })
10590
10591 testCases = append(testCases, testCase{
10592 testType: serverTest,
10593 name: "SkipEarlyData-Interleaved",
10594 config: Config{
10595 MaxVersion: VersionTLS13,
10596 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010597 SendFakeEarlyDataLength: 4,
10598 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010599 },
10600 },
10601 shouldFail: true,
10602 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10603 })
10604
10605 testCases = append(testCases, testCase{
10606 testType: serverTest,
10607 name: "SkipEarlyData-EarlyDataInTLS12",
10608 config: Config{
10609 MaxVersion: VersionTLS13,
10610 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010611 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010612 },
10613 },
10614 shouldFail: true,
10615 expectedError: ":UNEXPECTED_RECORD:",
10616 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10617 })
10618
10619 testCases = append(testCases, testCase{
10620 testType: serverTest,
10621 name: "SkipEarlyData-HRR",
10622 config: Config{
10623 MaxVersion: VersionTLS13,
10624 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010625 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010626 },
10627 DefaultCurves: []CurveID{},
10628 },
10629 })
10630
10631 testCases = append(testCases, testCase{
10632 testType: serverTest,
10633 name: "SkipEarlyData-HRR-Interleaved",
10634 config: Config{
10635 MaxVersion: VersionTLS13,
10636 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010637 SendFakeEarlyDataLength: 4,
10638 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010639 },
10640 DefaultCurves: []CurveID{},
10641 },
10642 shouldFail: true,
10643 expectedError: ":UNEXPECTED_RECORD:",
10644 })
10645
10646 testCases = append(testCases, testCase{
10647 testType: serverTest,
10648 name: "SkipEarlyData-HRR-TooMuchData",
10649 config: Config{
10650 MaxVersion: VersionTLS13,
10651 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010652 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010653 },
10654 DefaultCurves: []CurveID{},
10655 },
10656 shouldFail: true,
10657 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10658 })
10659
10660 // Test that skipping early data looking for cleartext correctly
10661 // processes an alert record.
10662 testCases = append(testCases, testCase{
10663 testType: serverTest,
10664 name: "SkipEarlyData-HRR-FatalAlert",
10665 config: Config{
10666 MaxVersion: VersionTLS13,
10667 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010668 SendEarlyAlert: true,
10669 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010670 },
10671 DefaultCurves: []CurveID{},
10672 },
10673 shouldFail: true,
10674 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10675 })
10676
10677 testCases = append(testCases, testCase{
10678 testType: serverTest,
10679 name: "SkipEarlyData-SecondClientHelloEarlyData",
10680 config: Config{
10681 MaxVersion: VersionTLS13,
10682 Bugs: ProtocolBugs{
10683 SendEarlyDataOnSecondClientHello: true,
10684 },
10685 DefaultCurves: []CurveID{},
10686 },
10687 shouldFail: true,
10688 expectedLocalError: "remote error: bad record MAC",
10689 })
10690
10691 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010692 testType: clientTest,
10693 name: "EmptyEncryptedExtensions",
10694 config: Config{
10695 MaxVersion: VersionTLS13,
10696 Bugs: ProtocolBugs{
10697 EmptyEncryptedExtensions: true,
10698 },
10699 },
10700 shouldFail: true,
10701 expectedLocalError: "remote error: error decoding message",
10702 })
10703
10704 testCases = append(testCases, testCase{
10705 testType: clientTest,
10706 name: "EncryptedExtensionsWithKeyShare",
10707 config: Config{
10708 MaxVersion: VersionTLS13,
10709 Bugs: ProtocolBugs{
10710 EncryptedExtensionsWithKeyShare: true,
10711 },
10712 },
10713 shouldFail: true,
10714 expectedLocalError: "remote error: unsupported extension",
10715 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010716
10717 testCases = append(testCases, testCase{
10718 testType: serverTest,
10719 name: "SendHelloRetryRequest",
10720 config: Config{
10721 MaxVersion: VersionTLS13,
10722 // Require a HelloRetryRequest for every curve.
10723 DefaultCurves: []CurveID{},
10724 },
10725 expectedCurveID: CurveX25519,
10726 })
10727
10728 testCases = append(testCases, testCase{
10729 testType: serverTest,
10730 name: "SendHelloRetryRequest-2",
10731 config: Config{
10732 MaxVersion: VersionTLS13,
10733 DefaultCurves: []CurveID{CurveP384},
10734 },
10735 // Although the ClientHello did not predict our preferred curve,
10736 // we always select it whether it is predicted or not.
10737 expectedCurveID: CurveX25519,
10738 })
10739
10740 testCases = append(testCases, testCase{
10741 name: "UnknownCurve-HelloRetryRequest",
10742 config: Config{
10743 MaxVersion: VersionTLS13,
10744 // P-384 requires HelloRetryRequest in BoringSSL.
10745 CurvePreferences: []CurveID{CurveP384},
10746 Bugs: ProtocolBugs{
10747 SendHelloRetryRequestCurve: bogusCurve,
10748 },
10749 },
10750 shouldFail: true,
10751 expectedError: ":WRONG_CURVE:",
10752 })
10753
10754 testCases = append(testCases, testCase{
10755 name: "DisabledCurve-HelloRetryRequest",
10756 config: Config{
10757 MaxVersion: VersionTLS13,
10758 CurvePreferences: []CurveID{CurveP256},
10759 Bugs: ProtocolBugs{
10760 IgnorePeerCurvePreferences: true,
10761 },
10762 },
10763 flags: []string{"-p384-only"},
10764 shouldFail: true,
10765 expectedError: ":WRONG_CURVE:",
10766 })
10767
10768 testCases = append(testCases, testCase{
10769 name: "UnnecessaryHelloRetryRequest",
10770 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010771 MaxVersion: VersionTLS13,
10772 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010773 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010774 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010775 },
10776 },
10777 shouldFail: true,
10778 expectedError: ":WRONG_CURVE:",
10779 })
10780
10781 testCases = append(testCases, testCase{
10782 name: "SecondHelloRetryRequest",
10783 config: Config{
10784 MaxVersion: VersionTLS13,
10785 // P-384 requires HelloRetryRequest in BoringSSL.
10786 CurvePreferences: []CurveID{CurveP384},
10787 Bugs: ProtocolBugs{
10788 SecondHelloRetryRequest: true,
10789 },
10790 },
10791 shouldFail: true,
10792 expectedError: ":UNEXPECTED_MESSAGE:",
10793 })
10794
10795 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010796 name: "HelloRetryRequest-Empty",
10797 config: Config{
10798 MaxVersion: VersionTLS13,
10799 Bugs: ProtocolBugs{
10800 AlwaysSendHelloRetryRequest: true,
10801 },
10802 },
10803 shouldFail: true,
10804 expectedError: ":DECODE_ERROR:",
10805 })
10806
10807 testCases = append(testCases, testCase{
10808 name: "HelloRetryRequest-DuplicateCurve",
10809 config: Config{
10810 MaxVersion: VersionTLS13,
10811 // P-384 requires a HelloRetryRequest against BoringSSL's default
10812 // configuration. Assert this ExpectMissingKeyShare.
10813 CurvePreferences: []CurveID{CurveP384},
10814 Bugs: ProtocolBugs{
10815 ExpectMissingKeyShare: true,
10816 DuplicateHelloRetryRequestExtensions: true,
10817 },
10818 },
10819 shouldFail: true,
10820 expectedError: ":DUPLICATE_EXTENSION:",
10821 expectedLocalError: "remote error: illegal parameter",
10822 })
10823
10824 testCases = append(testCases, testCase{
10825 name: "HelloRetryRequest-Cookie",
10826 config: Config{
10827 MaxVersion: VersionTLS13,
10828 Bugs: ProtocolBugs{
10829 SendHelloRetryRequestCookie: []byte("cookie"),
10830 },
10831 },
10832 })
10833
10834 testCases = append(testCases, testCase{
10835 name: "HelloRetryRequest-DuplicateCookie",
10836 config: Config{
10837 MaxVersion: VersionTLS13,
10838 Bugs: ProtocolBugs{
10839 SendHelloRetryRequestCookie: []byte("cookie"),
10840 DuplicateHelloRetryRequestExtensions: true,
10841 },
10842 },
10843 shouldFail: true,
10844 expectedError: ":DUPLICATE_EXTENSION:",
10845 expectedLocalError: "remote error: illegal parameter",
10846 })
10847
10848 testCases = append(testCases, testCase{
10849 name: "HelloRetryRequest-EmptyCookie",
10850 config: Config{
10851 MaxVersion: VersionTLS13,
10852 Bugs: ProtocolBugs{
10853 SendHelloRetryRequestCookie: []byte{},
10854 },
10855 },
10856 shouldFail: true,
10857 expectedError: ":DECODE_ERROR:",
10858 })
10859
10860 testCases = append(testCases, testCase{
10861 name: "HelloRetryRequest-Cookie-Curve",
10862 config: Config{
10863 MaxVersion: VersionTLS13,
10864 // P-384 requires HelloRetryRequest in BoringSSL.
10865 CurvePreferences: []CurveID{CurveP384},
10866 Bugs: ProtocolBugs{
10867 SendHelloRetryRequestCookie: []byte("cookie"),
10868 ExpectMissingKeyShare: true,
10869 },
10870 },
10871 })
10872
10873 testCases = append(testCases, testCase{
10874 name: "HelloRetryRequest-Unknown",
10875 config: Config{
10876 MaxVersion: VersionTLS13,
10877 Bugs: ProtocolBugs{
10878 CustomHelloRetryRequestExtension: "extension",
10879 },
10880 },
10881 shouldFail: true,
10882 expectedError: ":UNEXPECTED_EXTENSION:",
10883 expectedLocalError: "remote error: unsupported extension",
10884 })
10885
10886 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010887 testType: serverTest,
10888 name: "SecondClientHelloMissingKeyShare",
10889 config: Config{
10890 MaxVersion: VersionTLS13,
10891 DefaultCurves: []CurveID{},
10892 Bugs: ProtocolBugs{
10893 SecondClientHelloMissingKeyShare: true,
10894 },
10895 },
10896 shouldFail: true,
10897 expectedError: ":MISSING_KEY_SHARE:",
10898 })
10899
10900 testCases = append(testCases, testCase{
10901 testType: serverTest,
10902 name: "SecondClientHelloWrongCurve",
10903 config: Config{
10904 MaxVersion: VersionTLS13,
10905 DefaultCurves: []CurveID{},
10906 Bugs: ProtocolBugs{
10907 MisinterpretHelloRetryRequestCurve: CurveP521,
10908 },
10909 },
10910 shouldFail: true,
10911 expectedError: ":WRONG_CURVE:",
10912 })
10913
10914 testCases = append(testCases, testCase{
10915 name: "HelloRetryRequestVersionMismatch",
10916 config: Config{
10917 MaxVersion: VersionTLS13,
10918 // P-384 requires HelloRetryRequest in BoringSSL.
10919 CurvePreferences: []CurveID{CurveP384},
10920 Bugs: ProtocolBugs{
10921 SendServerHelloVersion: 0x0305,
10922 },
10923 },
10924 shouldFail: true,
10925 expectedError: ":WRONG_VERSION_NUMBER:",
10926 })
10927
10928 testCases = append(testCases, testCase{
10929 name: "HelloRetryRequestCurveMismatch",
10930 config: Config{
10931 MaxVersion: VersionTLS13,
10932 // P-384 requires HelloRetryRequest in BoringSSL.
10933 CurvePreferences: []CurveID{CurveP384},
10934 Bugs: ProtocolBugs{
10935 // Send P-384 (correct) in the HelloRetryRequest.
10936 SendHelloRetryRequestCurve: CurveP384,
10937 // But send P-256 in the ServerHello.
10938 SendCurve: CurveP256,
10939 },
10940 },
10941 shouldFail: true,
10942 expectedError: ":WRONG_CURVE:",
10943 })
10944
10945 // Test the server selecting a curve that requires a HelloRetryRequest
10946 // without sending it.
10947 testCases = append(testCases, testCase{
10948 name: "SkipHelloRetryRequest",
10949 config: Config{
10950 MaxVersion: VersionTLS13,
10951 // P-384 requires HelloRetryRequest in BoringSSL.
10952 CurvePreferences: []CurveID{CurveP384},
10953 Bugs: ProtocolBugs{
10954 SkipHelloRetryRequest: true,
10955 },
10956 },
10957 shouldFail: true,
10958 expectedError: ":WRONG_CURVE:",
10959 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010960
10961 testCases = append(testCases, testCase{
10962 name: "TLS13-RequestContextInHandshake",
10963 config: Config{
10964 MaxVersion: VersionTLS13,
10965 MinVersion: VersionTLS13,
10966 ClientAuth: RequireAnyClientCert,
10967 Bugs: ProtocolBugs{
10968 SendRequestContext: []byte("request context"),
10969 },
10970 },
10971 flags: []string{
10972 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10973 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10974 },
10975 shouldFail: true,
10976 expectedError: ":DECODE_ERROR:",
10977 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010978
10979 testCases = append(testCases, testCase{
10980 testType: serverTest,
10981 name: "TLS13-TrailingKeyShareData",
10982 config: Config{
10983 MaxVersion: VersionTLS13,
10984 Bugs: ProtocolBugs{
10985 TrailingKeyShareData: true,
10986 },
10987 },
10988 shouldFail: true,
10989 expectedError: ":DECODE_ERROR:",
10990 })
David Benjamin7f78df42016-10-05 22:33:19 -040010991
10992 testCases = append(testCases, testCase{
10993 name: "TLS13-AlwaysSelectPSKIdentity",
10994 config: Config{
10995 MaxVersion: VersionTLS13,
10996 Bugs: ProtocolBugs{
10997 AlwaysSelectPSKIdentity: true,
10998 },
10999 },
11000 shouldFail: true,
11001 expectedError: ":UNEXPECTED_EXTENSION:",
11002 })
11003
11004 testCases = append(testCases, testCase{
11005 name: "TLS13-InvalidPSKIdentity",
11006 config: Config{
11007 MaxVersion: VersionTLS13,
11008 Bugs: ProtocolBugs{
11009 SelectPSKIdentityOnResume: 1,
11010 },
11011 },
11012 resumeSession: true,
11013 shouldFail: true,
11014 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11015 })
David Benjamin1286bee2016-10-07 15:25:06 -040011016
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011017 testCases = append(testCases, testCase{
11018 testType: serverTest,
11019 name: "TLS13-ExtraPSKIdentity",
11020 config: Config{
11021 MaxVersion: VersionTLS13,
11022 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011023 ExtraPSKIdentity: true,
11024 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011025 },
11026 },
11027 resumeSession: true,
11028 })
11029
David Benjamin1286bee2016-10-07 15:25:06 -040011030 // Test that unknown NewSessionTicket extensions are tolerated.
11031 testCases = append(testCases, testCase{
11032 name: "TLS13-CustomTicketExtension",
11033 config: Config{
11034 MaxVersion: VersionTLS13,
11035 Bugs: ProtocolBugs{
11036 CustomTicketExtension: "1234",
11037 },
11038 },
11039 })
Steven Valdez2d850622017-01-11 11:34:52 -050011040
Steven Valdez0e4a4482017-07-17 11:12:34 -040011041 for _, noSessionID := range []bool{false, true} {
11042 prefix := "TLS13Experiment"
11043 variant := TLS13Experiment
11044 if noSessionID {
11045 prefix = "TLS13NoSessionIDExperiment"
11046 variant = TLS13NoSessionIDExperiment
11047 }
11048
11049 // Test that enabling a TLS 1.3 variant does not interfere with
11050 // TLS 1.2 session ID resumption.
11051 testCases = append(testCases, testCase{
11052 testType: clientTest,
11053 name: prefix + "-ResumeTLS12SessionID",
11054 config: Config{
11055 MaxVersion: VersionTLS12,
11056 SessionTicketsDisabled: true,
11057 },
11058 resumeSession: true,
11059 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11060 })
11061
11062 // Test that the server correctly echoes back session IDs of
11063 // various lengths.
11064 testCases = append(testCases, testCase{
11065 testType: serverTest,
11066 name: prefix + "-EmptySessionID",
11067 config: Config{
11068 MaxVersion: VersionTLS13,
11069 Bugs: ProtocolBugs{
11070 SendClientHelloSessionID: []byte{},
11071 },
11072 },
11073 tls13Variant: variant,
11074 })
11075
11076 testCases = append(testCases, testCase{
11077 testType: serverTest,
11078 name: prefix + "-ShortSessionID",
11079 config: Config{
11080 MaxVersion: VersionTLS13,
11081 Bugs: ProtocolBugs{
11082 SendClientHelloSessionID: make([]byte, 16),
11083 },
11084 },
11085 tls13Variant: variant,
11086 })
11087
11088 testCases = append(testCases, testCase{
11089 testType: serverTest,
11090 name: prefix + "-FullSessionID",
11091 config: Config{
11092 MaxVersion: VersionTLS13,
11093 Bugs: ProtocolBugs{
11094 SendClientHelloSessionID: make([]byte, 32),
11095 },
11096 },
11097 tls13Variant: variant,
11098 })
11099 }
11100
11101 // Test that the client sends a fake session ID in TLS13Experiment.
11102 testCases = append(testCases, testCase{
11103 testType: clientTest,
11104 name: "TLS13Experiment-RequireSessionID",
11105 config: Config{
11106 MaxVersion: VersionTLS13,
11107 Bugs: ProtocolBugs{
11108 ExpectClientHelloSessionID: true,
11109 },
11110 },
11111 tls13Variant: TLS13Experiment,
11112 })
11113
11114 // Test that the client does not send a fake session ID in
11115 // TLS13NoSessionIDExperiment.
11116 testCases = append(testCases, testCase{
11117 testType: clientTest,
11118 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11119 config: Config{
11120 MaxVersion: VersionTLS13,
11121 Bugs: ProtocolBugs{
11122 ExpectEmptyClientHelloSessionID: true,
11123 },
11124 },
11125 tls13Variant: TLS13NoSessionIDExperiment,
11126 })
11127
Steven Valdez2d850622017-01-11 11:34:52 -050011128 testCases = append(testCases, testCase{
11129 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011130 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011131 config: Config{
11132 MaxVersion: VersionTLS13,
11133 MaxEarlyDataSize: 16384,
11134 },
11135 resumeConfig: &Config{
11136 MaxVersion: VersionTLS13,
11137 MaxEarlyDataSize: 16384,
11138 Bugs: ProtocolBugs{
11139 AlwaysRejectEarlyData: true,
11140 },
11141 },
11142 resumeSession: true,
11143 flags: []string{
11144 "-enable-early-data",
11145 "-expect-early-data-info",
11146 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011147 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011148 },
11149 })
11150
11151 testCases = append(testCases, testCase{
11152 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011153 name: "TLS13Experiment-EarlyData-Reject-Client",
11154 config: Config{
11155 MaxVersion: VersionTLS13,
11156 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011157 },
11158 resumeConfig: &Config{
11159 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011160 MaxEarlyDataSize: 16384,
11161 Bugs: ProtocolBugs{
11162 AlwaysRejectEarlyData: true,
11163 },
11164 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011165 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011166 resumeSession: true,
11167 flags: []string{
11168 "-enable-early-data",
11169 "-expect-early-data-info",
11170 "-expect-reject-early-data",
11171 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011172 },
11173 })
11174
11175 testCases = append(testCases, testCase{
11176 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011177 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11178 config: Config{
11179 MaxVersion: VersionTLS13,
11180 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011181 },
11182 resumeConfig: &Config{
11183 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011184 MaxEarlyDataSize: 16384,
11185 Bugs: ProtocolBugs{
11186 AlwaysRejectEarlyData: true,
11187 },
11188 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011189 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011190 resumeSession: true,
11191 flags: []string{
11192 "-enable-early-data",
11193 "-expect-early-data-info",
11194 "-expect-reject-early-data",
11195 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011196 },
11197 })
11198
11199 testCases = append(testCases, testCase{
11200 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011201 name: "TLS13-EarlyData-RejectTicket-Client",
11202 config: Config{
11203 MaxVersion: VersionTLS13,
11204 MaxEarlyDataSize: 16384,
11205 Certificates: []Certificate{rsaCertificate},
11206 },
11207 resumeConfig: &Config{
11208 MaxVersion: VersionTLS13,
11209 MaxEarlyDataSize: 16384,
11210 Certificates: []Certificate{ecdsaP256Certificate},
11211 SessionTicketsDisabled: true,
11212 },
11213 resumeSession: true,
11214 expectResumeRejected: true,
11215 flags: []string{
11216 "-enable-early-data",
11217 "-expect-early-data-info",
11218 "-expect-reject-early-data",
11219 "-on-resume-shim-writes-first",
11220 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11221 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11222 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11223 // Session tickets are disabled, so the runner will not send a ticket.
11224 "-on-retry-expect-no-session",
11225 },
11226 })
11227
11228 testCases = append(testCases, testCase{
11229 testType: clientTest,
11230 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011231 config: Config{
11232 MaxVersion: VersionTLS13,
11233 MaxEarlyDataSize: 16384,
11234 },
11235 resumeConfig: &Config{
11236 MaxVersion: VersionTLS13,
11237 MaxEarlyDataSize: 16384,
11238 Bugs: ProtocolBugs{
11239 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11240 },
11241 },
11242 resumeSession: true,
11243 flags: []string{
11244 "-enable-early-data",
11245 "-expect-early-data-info",
11246 "-expect-reject-early-data",
11247 },
11248 })
11249
11250 // The client must check the server does not send the early_data
11251 // extension while rejecting the session.
11252 testCases = append(testCases, testCase{
11253 testType: clientTest,
11254 name: "TLS13-EarlyDataWithoutResume-Client",
11255 config: Config{
11256 MaxVersion: VersionTLS13,
11257 MaxEarlyDataSize: 16384,
11258 },
11259 resumeConfig: &Config{
11260 MaxVersion: VersionTLS13,
11261 SessionTicketsDisabled: true,
11262 Bugs: ProtocolBugs{
11263 SendEarlyDataExtension: true,
11264 },
11265 },
11266 resumeSession: true,
11267 flags: []string{
11268 "-enable-early-data",
11269 "-expect-early-data-info",
11270 },
11271 shouldFail: true,
11272 expectedError: ":UNEXPECTED_EXTENSION:",
11273 })
11274
11275 // The client must fail with a dedicated error code if the server
11276 // responds with TLS 1.2 when offering 0-RTT.
11277 testCases = append(testCases, testCase{
11278 testType: clientTest,
11279 name: "TLS13-EarlyDataVersionDowngrade-Client",
11280 config: Config{
11281 MaxVersion: VersionTLS13,
11282 MaxEarlyDataSize: 16384,
11283 },
11284 resumeConfig: &Config{
11285 MaxVersion: VersionTLS12,
11286 },
11287 resumeSession: true,
11288 flags: []string{
11289 "-enable-early-data",
11290 "-expect-early-data-info",
11291 },
11292 shouldFail: true,
11293 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11294 })
11295
11296 // Test that the client rejects an (unsolicited) early_data extension if
11297 // the server sent an HRR.
11298 testCases = append(testCases, testCase{
11299 testType: clientTest,
11300 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11301 config: Config{
11302 MaxVersion: VersionTLS13,
11303 MaxEarlyDataSize: 16384,
11304 },
11305 resumeConfig: &Config{
11306 MaxVersion: VersionTLS13,
11307 MaxEarlyDataSize: 16384,
11308 Bugs: ProtocolBugs{
11309 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11310 SendEarlyDataExtension: true,
11311 },
11312 },
11313 resumeSession: true,
11314 flags: []string{
11315 "-enable-early-data",
11316 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011317 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011318 },
11319 shouldFail: true,
11320 expectedError: ":UNEXPECTED_EXTENSION:",
11321 })
11322
11323 fooString := "foo"
11324 barString := "bar"
11325
11326 // Test that the client reports the correct ALPN after a 0-RTT reject
11327 // that changed it.
11328 testCases = append(testCases, testCase{
11329 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011330 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011331 config: Config{
11332 MaxVersion: VersionTLS13,
11333 MaxEarlyDataSize: 16384,
11334 Bugs: ProtocolBugs{
11335 ALPNProtocol: &fooString,
11336 },
11337 },
11338 resumeConfig: &Config{
11339 MaxVersion: VersionTLS13,
11340 MaxEarlyDataSize: 16384,
11341 Bugs: ProtocolBugs{
11342 ALPNProtocol: &barString,
11343 },
11344 },
11345 resumeSession: true,
11346 flags: []string{
11347 "-advertise-alpn", "\x03foo\x03bar",
11348 "-enable-early-data",
11349 "-expect-early-data-info",
11350 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011351 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011352 "-on-resume-expect-alpn", "foo",
11353 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011354 },
11355 })
11356
11357 // Test that the client reports the correct ALPN after a 0-RTT reject if
11358 // ALPN was omitted from the first connection.
11359 testCases = append(testCases, testCase{
11360 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011361 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011362 config: Config{
11363 MaxVersion: VersionTLS13,
11364 MaxEarlyDataSize: 16384,
11365 },
11366 resumeConfig: &Config{
11367 MaxVersion: VersionTLS13,
11368 MaxEarlyDataSize: 16384,
11369 NextProtos: []string{"foo"},
11370 },
11371 resumeSession: true,
11372 flags: []string{
11373 "-advertise-alpn", "\x03foo\x03bar",
11374 "-enable-early-data",
11375 "-expect-early-data-info",
11376 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011377 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011378 "-on-resume-expect-alpn", "",
11379 "-on-retry-expect-alpn", "foo",
11380 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011381 },
11382 })
11383
11384 // Test that the client reports the correct ALPN after a 0-RTT reject if
11385 // ALPN was omitted from the second connection.
11386 testCases = append(testCases, testCase{
11387 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011388 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011389 config: Config{
11390 MaxVersion: VersionTLS13,
11391 MaxEarlyDataSize: 16384,
11392 NextProtos: []string{"foo"},
11393 },
11394 resumeConfig: &Config{
11395 MaxVersion: VersionTLS13,
11396 MaxEarlyDataSize: 16384,
11397 },
11398 resumeSession: true,
11399 flags: []string{
11400 "-advertise-alpn", "\x03foo\x03bar",
11401 "-enable-early-data",
11402 "-expect-early-data-info",
11403 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011404 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011405 "-on-resume-expect-alpn", "foo",
11406 "-on-retry-expect-alpn", "",
11407 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011408 },
11409 })
11410
11411 // Test that the client enforces ALPN match on 0-RTT accept.
11412 testCases = append(testCases, testCase{
11413 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011414 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011415 config: Config{
11416 MaxVersion: VersionTLS13,
11417 MaxEarlyDataSize: 16384,
11418 Bugs: ProtocolBugs{
11419 ALPNProtocol: &fooString,
11420 },
11421 },
11422 resumeConfig: &Config{
11423 MaxVersion: VersionTLS13,
11424 MaxEarlyDataSize: 16384,
11425 Bugs: ProtocolBugs{
11426 AlwaysAcceptEarlyData: true,
11427 ALPNProtocol: &barString,
11428 },
11429 },
11430 resumeSession: true,
11431 flags: []string{
11432 "-advertise-alpn", "\x03foo\x03bar",
11433 "-enable-early-data",
11434 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011435 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011436 "-on-resume-expect-alpn", "foo",
11437 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011438 },
11439 shouldFail: true,
11440 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11441 })
11442
11443 // Test that the server correctly rejects 0-RTT when the previous
11444 // session did not allow early data on resumption.
11445 testCases = append(testCases, testCase{
11446 testType: serverTest,
11447 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11448 config: Config{
11449 MaxVersion: VersionTLS13,
11450 },
11451 resumeConfig: &Config{
11452 MaxVersion: VersionTLS13,
11453 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011454 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011455 ExpectEarlyDataAccepted: false,
11456 },
11457 },
11458 resumeSession: true,
11459 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011460 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011461 "-expect-reject-early-data",
11462 },
11463 })
11464
11465 // Test that we reject early data where ALPN is omitted from the first
11466 // connection.
11467 testCases = append(testCases, testCase{
11468 testType: serverTest,
11469 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11470 config: Config{
11471 MaxVersion: VersionTLS13,
11472 NextProtos: []string{},
11473 },
11474 resumeConfig: &Config{
11475 MaxVersion: VersionTLS13,
11476 NextProtos: []string{"foo"},
11477 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011478 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011479 ExpectEarlyDataAccepted: false,
11480 },
11481 },
11482 resumeSession: true,
11483 flags: []string{
11484 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011485 "-on-initial-select-alpn", "",
11486 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011487 },
11488 })
11489
11490 // Test that we reject early data where ALPN is omitted from the second
11491 // connection.
11492 testCases = append(testCases, testCase{
11493 testType: serverTest,
11494 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11495 config: Config{
11496 MaxVersion: VersionTLS13,
11497 NextProtos: []string{"foo"},
11498 },
11499 resumeConfig: &Config{
11500 MaxVersion: VersionTLS13,
11501 NextProtos: []string{},
11502 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011503 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011504 ExpectEarlyDataAccepted: false,
11505 },
11506 },
11507 resumeSession: true,
11508 flags: []string{
11509 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011510 "-on-initial-select-alpn", "foo",
11511 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011512 },
11513 })
11514
11515 // Test that we reject early data with mismatched ALPN.
11516 testCases = append(testCases, testCase{
11517 testType: serverTest,
11518 name: "TLS13-EarlyData-ALPNMismatch-Server",
11519 config: Config{
11520 MaxVersion: VersionTLS13,
11521 NextProtos: []string{"foo"},
11522 },
11523 resumeConfig: &Config{
11524 MaxVersion: VersionTLS13,
11525 NextProtos: []string{"bar"},
11526 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011527 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011528 ExpectEarlyDataAccepted: false,
11529 },
11530 },
11531 resumeSession: true,
11532 flags: []string{
11533 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011534 "-on-initial-select-alpn", "foo",
11535 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011536 },
11537 })
11538
David Benjamin6bb507b2017-03-29 16:35:57 -050011539 // Test that the client offering 0-RTT and Channel ID forbids the server
11540 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011541 testCases = append(testCases, testCase{
11542 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011543 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011544 config: Config{
11545 MaxVersion: VersionTLS13,
11546 MaxEarlyDataSize: 16384,
11547 RequestChannelID: true,
11548 },
11549 resumeSession: true,
11550 expectChannelID: true,
11551 shouldFail: true,
11552 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11553 flags: []string{
11554 "-enable-early-data",
11555 "-expect-early-data-info",
11556 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11557 },
11558 })
11559
David Benjamin6bb507b2017-03-29 16:35:57 -050011560 // Test that the client offering Channel ID and 0-RTT allows the server
11561 // to decline 0-RTT.
11562 testCases = append(testCases, testCase{
11563 testType: clientTest,
11564 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11565 config: Config{
11566 MaxVersion: VersionTLS13,
11567 MaxEarlyDataSize: 16384,
11568 RequestChannelID: true,
11569 Bugs: ProtocolBugs{
11570 AlwaysRejectEarlyData: true,
11571 },
11572 },
11573 resumeSession: true,
11574 expectChannelID: true,
11575 flags: []string{
11576 "-enable-early-data",
11577 "-expect-early-data-info",
11578 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11579 "-expect-reject-early-data",
11580 },
11581 })
11582
11583 // Test that the client offering Channel ID and 0-RTT allows the server
11584 // to decline Channel ID.
11585 testCases = append(testCases, testCase{
11586 testType: clientTest,
11587 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11588 config: Config{
11589 MaxVersion: VersionTLS13,
11590 MaxEarlyDataSize: 16384,
11591 },
11592 resumeSession: true,
11593 flags: []string{
11594 "-enable-early-data",
11595 "-expect-early-data-info",
11596 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11597 "-expect-accept-early-data",
11598 },
11599 })
11600
11601 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11602 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011603 testCases = append(testCases, testCase{
11604 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011605 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011606 config: Config{
11607 MaxVersion: VersionTLS13,
11608 ChannelID: channelIDKey,
11609 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011610 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011611 ExpectEarlyDataAccepted: false,
11612 },
11613 },
11614 resumeSession: true,
11615 expectChannelID: true,
11616 flags: []string{
11617 "-enable-early-data",
11618 "-expect-reject-early-data",
11619 "-expect-channel-id",
11620 base64.StdEncoding.EncodeToString(channelIDBytes),
11621 },
11622 })
11623
David Benjamin6bb507b2017-03-29 16:35:57 -050011624 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11625 // if not offered Channel ID.
11626 testCases = append(testCases, testCase{
11627 testType: serverTest,
11628 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11629 config: Config{
11630 MaxVersion: VersionTLS13,
11631 Bugs: ProtocolBugs{
11632 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11633 ExpectEarlyDataAccepted: true,
11634 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11635 },
11636 },
11637 resumeSession: true,
11638 expectChannelID: false,
11639 flags: []string{
11640 "-enable-early-data",
11641 "-expect-accept-early-data",
11642 "-enable-channel-id",
11643 },
11644 })
11645
David Benjamin32c89272017-03-26 13:54:21 -050011646 // Test that the server rejects 0-RTT streams without end_of_early_data.
11647 // The subsequent records should fail to decrypt.
11648 testCases = append(testCases, testCase{
11649 testType: serverTest,
11650 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11651 config: Config{
11652 MaxVersion: VersionTLS13,
11653 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011654 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011655 ExpectEarlyDataAccepted: true,
11656 SkipEndOfEarlyData: true,
11657 },
11658 },
11659 resumeSession: true,
11660 flags: []string{"-enable-early-data"},
11661 shouldFail: true,
11662 expectedLocalError: "remote error: bad record MAC",
11663 expectedError: ":BAD_DECRYPT:",
11664 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011665
11666 testCases = append(testCases, testCase{
11667 testType: serverTest,
11668 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11669 config: Config{
11670 MaxVersion: VersionTLS13,
11671 },
11672 resumeConfig: &Config{
11673 MaxVersion: VersionTLS13,
11674 Bugs: ProtocolBugs{
11675 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11676 SendStrayEarlyHandshake: true,
11677 ExpectEarlyDataAccepted: true},
11678 },
11679 resumeSession: true,
11680 shouldFail: true,
11681 expectedError: ":UNEXPECTED_RECORD:",
11682 expectedLocalError: "remote error: unexpected message",
11683 flags: []string{
11684 "-enable-early-data",
11685 },
11686 })
David Benjamind9cbb532017-07-07 13:17:19 -040011687
11688 // Test that the client reports TLS 1.3 as the version while sending
11689 // early data.
11690 testCases = append(testCases, testCase{
11691 testType: clientTest,
11692 name: "TLS13-EarlyData-Client-VersionAPI",
11693 config: Config{
11694 MaxVersion: VersionTLS13,
11695 MaxEarlyDataSize: 16384,
11696 },
11697 resumeSession: true,
11698 flags: []string{
11699 "-enable-early-data",
11700 "-expect-early-data-info",
11701 "-expect-accept-early-data",
11702 "-expect-version", strconv.Itoa(VersionTLS13),
11703 },
11704 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011705}
11706
David Benjaminabbbee12016-10-31 19:20:42 -040011707func addTLS13CipherPreferenceTests() {
11708 // Test that client preference is honored if the shim has AES hardware
11709 // and ChaCha20-Poly1305 is preferred otherwise.
11710 testCases = append(testCases, testCase{
11711 testType: serverTest,
11712 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11713 config: Config{
11714 MaxVersion: VersionTLS13,
11715 CipherSuites: []uint16{
11716 TLS_CHACHA20_POLY1305_SHA256,
11717 TLS_AES_128_GCM_SHA256,
11718 },
11719 },
11720 flags: []string{
11721 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11722 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11723 },
11724 })
11725
11726 testCases = append(testCases, testCase{
11727 testType: serverTest,
11728 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11729 config: Config{
11730 MaxVersion: VersionTLS13,
11731 CipherSuites: []uint16{
11732 TLS_AES_128_GCM_SHA256,
11733 TLS_CHACHA20_POLY1305_SHA256,
11734 },
11735 },
11736 flags: []string{
11737 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11738 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11739 },
11740 })
11741
11742 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11743 // whether it has AES hardware.
11744 testCases = append(testCases, testCase{
11745 name: "TLS13-CipherPreference-Client",
11746 config: Config{
11747 MaxVersion: VersionTLS13,
11748 // Use the client cipher order. (This is the default but
11749 // is listed to be explicit.)
11750 PreferServerCipherSuites: false,
11751 },
11752 flags: []string{
11753 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11754 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11755 },
11756 })
11757}
11758
David Benjaminf3fbade2016-09-19 13:08:16 -040011759func addPeekTests() {
11760 // Test SSL_peek works, including on empty records.
11761 testCases = append(testCases, testCase{
11762 name: "Peek-Basic",
11763 sendEmptyRecords: 1,
11764 flags: []string{"-peek-then-read"},
11765 })
11766
11767 // Test SSL_peek can drive the initial handshake.
11768 testCases = append(testCases, testCase{
11769 name: "Peek-ImplicitHandshake",
11770 flags: []string{
11771 "-peek-then-read",
11772 "-implicit-handshake",
11773 },
11774 })
11775
11776 // Test SSL_peek can discover and drive a renegotiation.
11777 testCases = append(testCases, testCase{
11778 name: "Peek-Renegotiate",
11779 config: Config{
11780 MaxVersion: VersionTLS12,
11781 },
11782 renegotiate: 1,
11783 flags: []string{
11784 "-peek-then-read",
11785 "-renegotiate-freely",
11786 "-expect-total-renegotiations", "1",
11787 },
11788 })
11789
11790 // Test SSL_peek can discover a close_notify.
11791 testCases = append(testCases, testCase{
11792 name: "Peek-Shutdown",
11793 config: Config{
11794 Bugs: ProtocolBugs{
11795 ExpectCloseNotify: true,
11796 },
11797 },
11798 flags: []string{
11799 "-peek-then-read",
11800 "-check-close-notify",
11801 },
11802 })
11803
11804 // Test SSL_peek can discover an alert.
11805 testCases = append(testCases, testCase{
11806 name: "Peek-Alert",
11807 config: Config{
11808 Bugs: ProtocolBugs{
11809 SendSpuriousAlert: alertRecordOverflow,
11810 },
11811 },
11812 flags: []string{"-peek-then-read"},
11813 shouldFail: true,
11814 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11815 })
11816
11817 // Test SSL_peek can handle KeyUpdate.
11818 testCases = append(testCases, testCase{
11819 name: "Peek-KeyUpdate",
11820 config: Config{
11821 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011822 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011823 sendKeyUpdates: 1,
11824 keyUpdateRequest: keyUpdateNotRequested,
11825 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011826 })
11827}
11828
David Benjamine6f22212016-11-08 14:28:24 -050011829func addRecordVersionTests() {
11830 for _, ver := range tlsVersions {
11831 // Test that the record version is enforced.
11832 testCases = append(testCases, testCase{
11833 name: "CheckRecordVersion-" + ver.name,
11834 config: Config{
11835 MinVersion: ver.version,
11836 MaxVersion: ver.version,
11837 Bugs: ProtocolBugs{
11838 SendRecordVersion: 0x03ff,
11839 },
11840 },
David Benjamina5022392017-07-10 17:40:39 -040011841 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011842 shouldFail: true,
11843 expectedError: ":WRONG_VERSION_NUMBER:",
11844 })
11845
11846 // Test that the ClientHello may use any record version, for
11847 // compatibility reasons.
11848 testCases = append(testCases, testCase{
11849 testType: serverTest,
11850 name: "LooseInitialRecordVersion-" + ver.name,
11851 config: Config{
11852 MinVersion: ver.version,
11853 MaxVersion: ver.version,
11854 Bugs: ProtocolBugs{
11855 SendInitialRecordVersion: 0x03ff,
11856 },
11857 },
David Benjamina5022392017-07-10 17:40:39 -040011858 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011859 })
11860
11861 // Test that garbage ClientHello record versions are rejected.
11862 testCases = append(testCases, testCase{
11863 testType: serverTest,
11864 name: "GarbageInitialRecordVersion-" + ver.name,
11865 config: Config{
11866 MinVersion: ver.version,
11867 MaxVersion: ver.version,
11868 Bugs: ProtocolBugs{
11869 SendInitialRecordVersion: 0xffff,
11870 },
11871 },
David Benjamina5022392017-07-10 17:40:39 -040011872 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050011873 shouldFail: true,
11874 expectedError: ":WRONG_VERSION_NUMBER:",
11875 })
11876 }
11877}
11878
David Benjamin2c516452016-11-15 10:16:54 +090011879func addCertificateTests() {
11880 // Test that a certificate chain with intermediate may be sent and
11881 // received as both client and server.
11882 for _, ver := range tlsVersions {
11883 testCases = append(testCases, testCase{
11884 testType: clientTest,
11885 name: "SendReceiveIntermediate-Client-" + ver.name,
11886 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011887 MinVersion: ver.version,
11888 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011889 Certificates: []Certificate{rsaChainCertificate},
11890 ClientAuth: RequireAnyClientCert,
11891 },
David Benjamina5022392017-07-10 17:40:39 -040011892 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011893 expectPeerCertificate: &rsaChainCertificate,
11894 flags: []string{
11895 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11896 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11897 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11898 },
11899 })
11900
11901 testCases = append(testCases, testCase{
11902 testType: serverTest,
11903 name: "SendReceiveIntermediate-Server-" + ver.name,
11904 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011905 MinVersion: ver.version,
11906 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011907 Certificates: []Certificate{rsaChainCertificate},
11908 },
David Benjamina5022392017-07-10 17:40:39 -040011909 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090011910 expectPeerCertificate: &rsaChainCertificate,
11911 flags: []string{
11912 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11913 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11914 "-require-any-client-certificate",
11915 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11916 },
11917 })
11918 }
11919}
11920
David Benjaminbbaf3672016-11-17 10:53:09 +090011921func addRetainOnlySHA256ClientCertTests() {
11922 for _, ver := range tlsVersions {
11923 // Test that enabling
11924 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11925 // actually requesting a client certificate is a no-op.
11926 testCases = append(testCases, testCase{
11927 testType: serverTest,
11928 name: "RetainOnlySHA256-NoCert-" + ver.name,
11929 config: Config{
11930 MinVersion: ver.version,
11931 MaxVersion: ver.version,
11932 },
David Benjamina5022392017-07-10 17:40:39 -040011933 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011934 flags: []string{
11935 "-retain-only-sha256-client-cert-initial",
11936 "-retain-only-sha256-client-cert-resume",
11937 },
11938 resumeSession: true,
11939 })
11940
11941 // Test that when retaining only a SHA-256 certificate is
11942 // enabled, the hash appears as expected.
11943 testCases = append(testCases, testCase{
11944 testType: serverTest,
11945 name: "RetainOnlySHA256-Cert-" + ver.name,
11946 config: Config{
11947 MinVersion: ver.version,
11948 MaxVersion: ver.version,
11949 Certificates: []Certificate{rsaCertificate},
11950 },
David Benjamina5022392017-07-10 17:40:39 -040011951 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011952 flags: []string{
11953 "-verify-peer",
11954 "-retain-only-sha256-client-cert-initial",
11955 "-retain-only-sha256-client-cert-resume",
11956 "-expect-sha256-client-cert-initial",
11957 "-expect-sha256-client-cert-resume",
11958 },
11959 resumeSession: true,
11960 })
11961
11962 // Test that when the config changes from on to off, a
11963 // resumption is rejected because the server now wants the full
11964 // certificate chain.
11965 testCases = append(testCases, testCase{
11966 testType: serverTest,
11967 name: "RetainOnlySHA256-OnOff-" + ver.name,
11968 config: Config{
11969 MinVersion: ver.version,
11970 MaxVersion: ver.version,
11971 Certificates: []Certificate{rsaCertificate},
11972 },
David Benjamina5022392017-07-10 17:40:39 -040011973 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011974 flags: []string{
11975 "-verify-peer",
11976 "-retain-only-sha256-client-cert-initial",
11977 "-expect-sha256-client-cert-initial",
11978 },
11979 resumeSession: true,
11980 expectResumeRejected: true,
11981 })
11982
11983 // Test that when the config changes from off to on, a
11984 // resumption is rejected because the server now wants just the
11985 // hash.
11986 testCases = append(testCases, testCase{
11987 testType: serverTest,
11988 name: "RetainOnlySHA256-OffOn-" + ver.name,
11989 config: Config{
11990 MinVersion: ver.version,
11991 MaxVersion: ver.version,
11992 Certificates: []Certificate{rsaCertificate},
11993 },
David Benjamina5022392017-07-10 17:40:39 -040011994 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090011995 flags: []string{
11996 "-verify-peer",
11997 "-retain-only-sha256-client-cert-resume",
11998 "-expect-sha256-client-cert-resume",
11999 },
12000 resumeSession: true,
12001 expectResumeRejected: true,
12002 })
12003 }
12004}
12005
Adam Langleya4b91982016-12-12 12:05:53 -080012006func addECDSAKeyUsageTests() {
12007 p256 := elliptic.P256()
12008 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12009 if err != nil {
12010 panic(err)
12011 }
12012
12013 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12014 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12015 if err != nil {
12016 panic(err)
12017 }
12018
12019 template := x509.Certificate{
12020 SerialNumber: serialNumber,
12021 Subject: pkix.Name{
12022 Organization: []string{"Acme Co"},
12023 },
12024 NotBefore: time.Now(),
12025 NotAfter: time.Now(),
12026
12027 // An ECC certificate with only the keyAgreement key usgae may
12028 // be used with ECDH, but not ECDSA.
12029 KeyUsage: x509.KeyUsageKeyAgreement,
12030 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12031 BasicConstraintsValid: true,
12032 }
12033
12034 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12035 if err != nil {
12036 panic(err)
12037 }
12038
12039 cert := Certificate{
12040 Certificate: [][]byte{derBytes},
12041 PrivateKey: priv,
12042 }
12043
12044 for _, ver := range tlsVersions {
12045 if ver.version < VersionTLS12 {
12046 continue
12047 }
12048
12049 testCases = append(testCases, testCase{
12050 testType: clientTest,
12051 name: "ECDSAKeyUsage-" + ver.name,
12052 config: Config{
12053 MinVersion: ver.version,
12054 MaxVersion: ver.version,
12055 Certificates: []Certificate{cert},
12056 },
David Benjamina5022392017-07-10 17:40:39 -040012057 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012058 shouldFail: true,
12059 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12060 })
12061 }
12062}
12063
David Benjamin8c26d752017-03-26 15:13:51 -050012064func addExtraHandshakeTests() {
12065 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12066 // to ensure there is no transport I/O.
12067 testCases = append(testCases, testCase{
12068 testType: clientTest,
12069 name: "ExtraHandshake-Client-TLS12",
12070 config: Config{
12071 MinVersion: VersionTLS12,
12072 MaxVersion: VersionTLS12,
12073 },
12074 flags: []string{
12075 "-async",
12076 "-no-op-extra-handshake",
12077 },
12078 })
12079 testCases = append(testCases, testCase{
12080 testType: serverTest,
12081 name: "ExtraHandshake-Server-TLS12",
12082 config: Config{
12083 MinVersion: VersionTLS12,
12084 MaxVersion: VersionTLS12,
12085 },
12086 flags: []string{
12087 "-async",
12088 "-no-op-extra-handshake",
12089 },
12090 })
12091 testCases = append(testCases, testCase{
12092 testType: clientTest,
12093 name: "ExtraHandshake-Client-TLS13",
12094 config: Config{
12095 MinVersion: VersionTLS13,
12096 MaxVersion: VersionTLS13,
12097 },
12098 flags: []string{
12099 "-async",
12100 "-no-op-extra-handshake",
12101 },
12102 })
12103 testCases = append(testCases, testCase{
12104 testType: serverTest,
12105 name: "ExtraHandshake-Server-TLS13",
12106 config: Config{
12107 MinVersion: VersionTLS13,
12108 MaxVersion: VersionTLS13,
12109 },
12110 flags: []string{
12111 "-async",
12112 "-no-op-extra-handshake",
12113 },
12114 })
12115
12116 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12117 testCases = append(testCases, testCase{
12118 testType: serverTest,
12119 name: "ExtraHandshake-Server-EarlyData-TLS13",
12120 config: Config{
12121 MaxVersion: VersionTLS13,
12122 MinVersion: VersionTLS13,
12123 Bugs: ProtocolBugs{
12124 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12125 ExpectEarlyDataAccepted: true,
12126 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12127 },
12128 },
12129 messageCount: 2,
12130 resumeSession: true,
12131 flags: []string{
12132 "-async",
12133 "-enable-early-data",
12134 "-expect-accept-early-data",
12135 "-no-op-extra-handshake",
12136 },
12137 })
12138
12139 // An extra SSL_do_handshake drives the handshake to completion in False
12140 // Start. We test this by handshaking twice and asserting the False
12141 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12142 // how the test works.
12143 testCases = append(testCases, testCase{
12144 testType: clientTest,
12145 name: "ExtraHandshake-FalseStart",
12146 config: Config{
12147 MaxVersion: VersionTLS12,
12148 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12149 NextProtos: []string{"foo"},
12150 Bugs: ProtocolBugs{
12151 ExpectFalseStart: true,
12152 AlertBeforeFalseStartTest: alertAccessDenied,
12153 },
12154 },
12155 flags: []string{
12156 "-handshake-twice",
12157 "-false-start",
12158 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012159 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012160 },
12161 shimWritesFirst: true,
12162 shouldFail: true,
12163 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12164 expectedLocalError: "tls: peer did not false start: EOF",
12165 })
12166}
12167
David Benjaminb853f312017-07-14 18:40:34 -040012168// Test that omitted and empty extensions blocks are tolerated.
12169func addOmitExtensionsTests() {
12170 for _, ver := range tlsVersions {
12171 if ver.version > VersionTLS12 {
12172 continue
12173 }
12174
12175 testCases = append(testCases, testCase{
12176 testType: serverTest,
12177 name: "OmitExtensions-ClientHello-" + ver.name,
12178 config: Config{
12179 MinVersion: ver.version,
12180 MaxVersion: ver.version,
12181 SessionTicketsDisabled: true,
12182 Bugs: ProtocolBugs{
12183 OmitExtensions: true,
12184 },
12185 },
12186 })
12187
12188 testCases = append(testCases, testCase{
12189 testType: serverTest,
12190 name: "EmptyExtensions-ClientHello-" + ver.name,
12191 config: Config{
12192 MinVersion: ver.version,
12193 MaxVersion: ver.version,
12194 SessionTicketsDisabled: true,
12195 Bugs: ProtocolBugs{
12196 EmptyExtensions: true,
12197 },
12198 },
12199 })
12200
12201 testCases = append(testCases, testCase{
12202 testType: clientTest,
12203 name: "OmitExtensions-ServerHello-" + ver.name,
12204 config: Config{
12205 MinVersion: ver.version,
12206 MaxVersion: ver.version,
12207 SessionTicketsDisabled: true,
12208 Bugs: ProtocolBugs{
12209 OmitExtensions: true,
12210 // Disable all ServerHello extensions so
12211 // OmitExtensions works.
12212 NoExtendedMasterSecret: true,
12213 NoRenegotiationInfo: true,
12214 },
12215 },
12216 })
12217
12218 testCases = append(testCases, testCase{
12219 testType: clientTest,
12220 name: "EmptyExtensions-ServerHello-" + ver.name,
12221 config: Config{
12222 MinVersion: ver.version,
12223 MaxVersion: ver.version,
12224 SessionTicketsDisabled: true,
12225 Bugs: ProtocolBugs{
12226 EmptyExtensions: true,
12227 // Disable all ServerHello extensions so
12228 // EmptyExtensions works.
12229 NoExtendedMasterSecret: true,
12230 NoRenegotiationInfo: true,
12231 },
12232 },
12233 })
12234 }
12235}
12236
Adam Langley7c803a62015-06-15 15:35:05 -070012237func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012238 defer wg.Done()
12239
12240 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012241 var err error
12242
David Benjaminba28dfc2016-11-15 17:47:21 +090012243 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012244 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12245 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012246 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012247 if err != nil {
12248 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12249 }
12250 break
12251 }
12252 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012253 } else if *repeatUntilFailure {
12254 for err == nil {
12255 statusChan <- statusMsg{test: test, started: true}
12256 err = runTest(test, shimPath, -1)
12257 }
12258 } else {
12259 statusChan <- statusMsg{test: test, started: true}
12260 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012261 }
Adam Langley95c29f32014-06-20 12:00:00 -070012262 statusChan <- statusMsg{test: test, err: err}
12263 }
12264}
12265
12266type statusMsg struct {
12267 test *testCase
12268 started bool
12269 err error
12270}
12271
David Benjamin5f237bc2015-02-11 17:14:15 -050012272func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012273 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012274
David Benjamin5f237bc2015-02-11 17:14:15 -050012275 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012276 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012277 if !*pipe {
12278 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012279 var erase string
12280 for i := 0; i < lineLen; i++ {
12281 erase += "\b \b"
12282 }
12283 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012284 }
12285
Adam Langley95c29f32014-06-20 12:00:00 -070012286 if msg.started {
12287 started++
12288 } else {
12289 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012290
12291 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012292 if msg.err == errUnimplemented {
12293 if *pipe {
12294 // Print each test instead of a status line.
12295 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12296 }
12297 unimplemented++
12298 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12299 } else {
12300 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12301 failed++
12302 testOutput.addResult(msg.test.name, "FAIL")
12303 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012304 } else {
12305 if *pipe {
12306 // Print each test instead of a status line.
12307 fmt.Printf("PASSED (%s)\n", msg.test.name)
12308 }
12309 testOutput.addResult(msg.test.name, "PASS")
12310 }
Adam Langley95c29f32014-06-20 12:00:00 -070012311 }
12312
David Benjamin5f237bc2015-02-11 17:14:15 -050012313 if !*pipe {
12314 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012315 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012316 lineLen = len(line)
12317 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012318 }
Adam Langley95c29f32014-06-20 12:00:00 -070012319 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012320
12321 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012322}
12323
12324func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012325 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012326 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012327 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012328
Adam Langley7c803a62015-06-15 15:35:05 -070012329 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012330 addCipherSuiteTests()
12331 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012332 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012333 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012334 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012335 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012336 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012337 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012338 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012339 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012340 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012341 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012342 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012343 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012344 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012345 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012346 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012347 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012348 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012349 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012350 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012351 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012352 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012353 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012354 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012355 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012356 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012357 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012358 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012359 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012360 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012361 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012362 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012363 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012364 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012365
12366 var wg sync.WaitGroup
12367
Adam Langley7c803a62015-06-15 15:35:05 -070012368 statusChan := make(chan statusMsg, *numWorkers)
12369 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012370 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012371
EKRf71d7ed2016-08-06 13:25:12 -070012372 if len(*shimConfigFile) != 0 {
12373 encoded, err := ioutil.ReadFile(*shimConfigFile)
12374 if err != nil {
12375 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12376 os.Exit(1)
12377 }
12378
12379 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12380 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12381 os.Exit(1)
12382 }
12383 }
12384
David Benjamin025b3d32014-07-01 19:53:04 -040012385 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012386
Adam Langley7c803a62015-06-15 15:35:05 -070012387 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012388 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012389 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012390 }
12391
David Benjamin270f0a72016-03-17 14:41:36 -040012392 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012393 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012394 matched := true
12395 if len(*testToRun) != 0 {
12396 var err error
12397 matched, err = filepath.Match(*testToRun, testCases[i].name)
12398 if err != nil {
12399 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12400 os.Exit(1)
12401 }
12402 }
12403
EKRf71d7ed2016-08-06 13:25:12 -070012404 if !*includeDisabled {
12405 for pattern := range shimConfig.DisabledTests {
12406 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12407 if err != nil {
12408 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12409 os.Exit(1)
12410 }
12411
12412 if isDisabled {
12413 matched = false
12414 break
12415 }
12416 }
12417 }
12418
David Benjamin17e12922016-07-28 18:04:43 -040012419 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012420 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012421 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012422
12423 // Only run one test if repeating until failure.
12424 if *repeatUntilFailure {
12425 break
12426 }
Adam Langley95c29f32014-06-20 12:00:00 -070012427 }
12428 }
David Benjamin17e12922016-07-28 18:04:43 -040012429
David Benjamin270f0a72016-03-17 14:41:36 -040012430 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012431 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012432 os.Exit(1)
12433 }
Adam Langley95c29f32014-06-20 12:00:00 -070012434
12435 close(testChan)
12436 wg.Wait()
12437 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012438 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012439
12440 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012441
12442 if *jsonOutput != "" {
12443 if err := testOutput.writeTo(*jsonOutput); err != nil {
12444 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12445 }
12446 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012447
EKR842ae6c2016-07-27 09:22:05 +020012448 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12449 os.Exit(1)
12450 }
12451
12452 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012453 os.Exit(1)
12454 }
Adam Langley95c29f32014-06-20 12:00:00 -070012455}