blob: 04c94b2a0ebc99910ece2ba458133639cdd9f77e [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 Valdezc94998a2017-06-20 10:55:02 -0400266// configVersionToWire maps a protocol version to the default wire version to
267// test at that protocol.
268//
269// TODO(davidben): Rather than mapping these, make tlsVersions contains a list
270// of wire versions and test all of them.
271func configVersionToWire(vers uint16, protocol protocol) uint16 {
272 if protocol == dtls {
273 switch vers {
274 case VersionTLS12:
275 return VersionDTLS12
276 case VersionTLS10:
277 return VersionDTLS10
278 }
279 } else {
280 switch vers {
281 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
282 return vers
283 case VersionTLS13:
284 return tls13DraftVersion
285 }
286 }
287
288 panic("unknown version")
289}
290
Adam Langley2ff79332017-02-28 13:45:39 -0800291// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
292func encodeDERValues(values [][]byte) string {
293 var ret string
294 for i, v := range values {
295 if i > 0 {
296 ret += ","
297 }
298 ret += hex.EncodeToString(v)
299 }
300
301 return ret
302}
303
David Benjamin025b3d32014-07-01 19:53:04 -0400304type testType int
305
306const (
307 clientTest testType = iota
308 serverTest
309)
310
David Benjamin6fd297b2014-08-11 18:43:38 -0400311type protocol int
312
313const (
314 tls protocol = iota
315 dtls
316)
317
David Benjaminfc7b0862014-09-06 13:21:53 -0400318const (
319 alpn = 1
320 npn = 2
321)
322
Adam Langley95c29f32014-06-20 12:00:00 -0700323type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400324 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400325 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700326 name string
327 config Config
328 shouldFail bool
329 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700330 // expectedLocalError, if not empty, contains a substring that must be
331 // found in the local error.
332 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400333 // expectedVersion, if non-zero, specifies the TLS version that must be
334 // negotiated.
335 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400336 // expectedResumeVersion, if non-zero, specifies the TLS version that
337 // must be negotiated on resumption. If zero, expectedVersion is used.
338 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400339 // expectedCipher, if non-zero, specifies the TLS cipher suite that
340 // should be negotiated.
341 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400342 // expectChannelID controls whether the connection should have
343 // negotiated a Channel ID with channelIDKey.
344 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400345 // expectedNextProto controls whether the connection should
346 // negotiate a next protocol via NPN or ALPN.
347 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 // expectNoNextProto, if true, means that no next protocol should be
349 // negotiated.
350 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400351 // expectedNextProtoType, if non-zero, is the expected next
352 // protocol negotiation mechanism.
353 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500354 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
355 // should be negotiated. If zero, none should be negotiated.
356 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100357 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
358 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100359 // expectedSCTList, if not nil, is the expected SCT list to be received.
360 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700361 // expectedPeerSignatureAlgorithm, if not zero, is the signature
362 // algorithm that the peer should have used in the handshake.
363 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400364 // expectedCurveID, if not zero, is the curve that the handshake should
365 // have used.
366 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700367 // messageLen is the length, in bytes, of the test message that will be
368 // sent.
369 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400370 // messageCount is the number of test messages that will be sent.
371 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400372 // certFile is the path to the certificate to use for the server.
373 certFile string
374 // keyFile is the path to the private key to use for the server.
375 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400376 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400377 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400378 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400379 // resumeRenewedSession controls whether a third connection should be
380 // tested which attempts to resume the second connection's session.
381 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700382 // expectResumeRejected, if true, specifies that the attempted
383 // resumption must be rejected by the client. This is only valid for a
384 // serverTest.
385 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400386 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // resumption. Unless newSessionsOnResume is set,
388 // SessionTicketKey, ServerSessionCache, and
389 // ClientSessionCache are copied from the initial connection's
390 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400391 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500392 // newSessionsOnResume, if true, will cause resumeConfig to
393 // use a different session resumption context.
394 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400395 // noSessionCache, if true, will cause the server to run without a
396 // session cache.
397 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400398 // sendPrefix sends a prefix on the socket before actually performing a
399 // handshake.
400 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400401 // shimWritesFirst controls whether the shim sends an initial "hello"
402 // message before doing a roundtrip with the runner.
403 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400404 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
405 // does not complete the write until responding to the first runner
406 // message.
407 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400408 // shimShutsDown, if true, runs a test where the shim shuts down the
409 // connection immediately after the handshake rather than echoing
410 // messages from the runner.
411 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400412 // renegotiate indicates the number of times the connection should be
413 // renegotiated during the exchange.
414 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400415 // sendHalfHelloRequest, if true, causes the server to send half a
416 // HelloRequest when the handshake completes.
417 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700418 // renegotiateCiphers is a list of ciphersuite ids that will be
419 // switched in just before renegotiation.
420 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500421 // replayWrites, if true, configures the underlying transport
422 // to replay every write it makes in DTLS tests.
423 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 // damageFirstWrite, if true, configures the underlying transport to
425 // damage the final byte of the first application data write.
426 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400427 // exportKeyingMaterial, if non-zero, configures the test to exchange
428 // keying material and verify they match.
429 exportKeyingMaterial int
430 exportLabel string
431 exportContext string
432 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400433 // flags, if not empty, contains a list of command-line flags that will
434 // be passed to the shim program.
435 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700436 // testTLSUnique, if true, causes the shim to send the tls-unique value
437 // which will be compared against the expected value.
438 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400439 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400440 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400441 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400442 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400443 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400444 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400445 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
446 // be sent before each test message.
447 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400448 // sendKeyUpdates is the number of consecutive key updates to send
449 // before and after the test message.
450 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400451 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
452 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400453 // expectMessageDropped, if true, means the test message is expected to
454 // be dropped by the client rather than echoed back.
455 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900456 // expectPeerCertificate, if not nil, is the certificate chain the peer
457 // is expected to send.
458 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500459 // shimPrefix is the prefix that the shim will send to the server.
460 shimPrefix string
461 // resumeShimPrefix is the prefix that the shim will send to the server on a
462 // resumption.
463 resumeShimPrefix string
Adam Langley95c29f32014-06-20 12:00:00 -0700464}
465
Adam Langley7c803a62015-06-15 15:35:05 -0700466var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700467
David Benjamin0fde2eb2017-06-30 19:11:22 -0400468func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if len(data) == 0 {
470 return
471 }
472
David Benjamin0fde2eb2017-06-30 19:11:22 -0400473 settings, err := ioutil.ReadFile(path)
474 if err != nil {
475 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500476 return
477 }
478
David Benjamin0fde2eb2017-06-30 19:11:22 -0400479 settings = append(settings, data...)
480 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
481 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500482 }
483}
484
David Benjamin3ed59772016-03-08 12:50:21 -0500485// A timeoutConn implements an idle timeout on each Read and Write operation.
486type timeoutConn struct {
487 net.Conn
488 timeout time.Duration
489}
490
491func (t *timeoutConn) Read(b []byte) (int, error) {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
495 return t.Conn.Read(b)
496}
497
498func (t *timeoutConn) Write(b []byte) (int, error) {
499 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
500 return 0, err
501 }
502 return t.Conn.Write(b)
503}
504
David Benjamin0fde2eb2017-06-30 19:11:22 -0400505func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400506 if !test.noSessionCache {
507 if config.ClientSessionCache == nil {
508 config.ClientSessionCache = NewLRUClientSessionCache(1)
509 }
510 if config.ServerSessionCache == nil {
511 config.ServerSessionCache = NewLRUServerSessionCache(1)
512 }
513 }
514 if test.testType == clientTest {
515 if len(config.Certificates) == 0 {
516 config.Certificates = []Certificate{rsaCertificate}
517 }
518 } else {
519 // Supply a ServerName to ensure a constant session cache key,
520 // rather than falling back to net.Conn.RemoteAddr.
521 if len(config.ServerName) == 0 {
522 config.ServerName = "test"
523 }
524 }
525 if *fuzzer {
526 config.Bugs.NullAllCiphers = true
527 }
David Benjamin01a90572016-09-22 00:11:43 -0400528 if *deterministic {
529 config.Time = func() time.Time { return time.Unix(1234, 1234) }
530 }
David Benjamine54af062016-08-08 19:21:18 -0400531
David Benjamin01784b42016-06-07 18:00:52 -0400532 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500533
David Benjamin6fd297b2014-08-11 18:43:38 -0400534 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500535 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
536 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500537 }
538
David Benjamin9867b7d2016-03-01 23:25:48 -0500539 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500540 local, peer := "client", "server"
541 if test.testType == clientTest {
542 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500543 }
David Benjaminebda9b32015-11-02 15:33:18 -0500544 connDebug := &recordingConn{
545 Conn: conn,
546 isDatagram: test.protocol == dtls,
547 local: local,
548 peer: peer,
549 }
550 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500551 if *flagDebug {
552 defer connDebug.WriteTo(os.Stdout)
553 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400554 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500555 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 path := transcriptPrefix + strconv.Itoa(num)
557 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500558 }()
559 }
David Benjaminebda9b32015-11-02 15:33:18 -0500560
561 if config.Bugs.PacketAdaptor != nil {
562 config.Bugs.PacketAdaptor.debug = connDebug
563 }
564 }
565
566 if test.replayWrites {
567 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400568 }
569
David Benjamin3ed59772016-03-08 12:50:21 -0500570 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500571 if test.damageFirstWrite {
572 connDamage = newDamageAdaptor(conn)
573 conn = connDamage
574 }
575
David Benjamin6fd297b2014-08-11 18:43:38 -0400576 if test.sendPrefix != "" {
577 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
578 return err
579 }
David Benjamin98e882e2014-08-08 13:24:34 -0400580 }
581
David Benjamin1d5c83e2014-07-22 19:20:02 -0400582 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400583 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400584 if test.protocol == dtls {
585 tlsConn = DTLSServer(conn, config)
586 } else {
587 tlsConn = Server(conn, config)
588 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400589 } else {
590 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400591 if test.protocol == dtls {
592 tlsConn = DTLSClient(conn, config)
593 } else {
594 tlsConn = Client(conn, config)
595 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400596 }
David Benjamin30789da2015-08-29 22:56:45 -0400597 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598
Adam Langley95c29f32014-06-20 12:00:00 -0700599 if err := tlsConn.Handshake(); err != nil {
600 return err
601 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700602
David Benjamin01fe8202014-09-24 15:21:44 -0400603 // TODO(davidben): move all per-connection expectations into a dedicated
604 // expectations struct that can be specified separately for the two
605 // legs.
606 expectedVersion := test.expectedVersion
607 if isResume && test.expectedResumeVersion != 0 {
608 expectedVersion = test.expectedResumeVersion
609 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 connState := tlsConn.ConnectionState()
611 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400612 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400613 }
614
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700615 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400616 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
617 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700618 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
619 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
620 }
David Benjamin90da8c82015-04-20 14:57:57 -0400621
David Benjamina08e49d2014-08-24 01:46:07 -0400622 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700623 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if channelID == nil {
625 return fmt.Errorf("no channel ID negotiated")
626 }
627 if channelID.Curve != channelIDKey.Curve ||
628 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
629 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
630 return fmt.Errorf("incorrect channel ID")
631 }
David Benjamin634f4752017-07-01 11:08:41 -0400632 } else if connState.ChannelID != nil {
633 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400634 }
635
David Benjaminae2888f2014-09-06 12:58:58 -0400636 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700637 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400638 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
639 }
640 }
641
David Benjaminc7ce9772015-10-09 19:32:41 -0400642 if test.expectNoNextProto {
643 if actual := connState.NegotiatedProtocol; actual != "" {
644 return fmt.Errorf("got unexpected next proto %s", actual)
645 }
646 }
647
David Benjaminfc7b0862014-09-06 13:21:53 -0400648 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700649 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400650 return fmt.Errorf("next proto type mismatch")
651 }
652 }
653
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700654 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500655 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
656 }
657
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100658 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300659 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100660 }
661
Paul Lietar4fac72e2015-09-09 13:44:55 +0100662 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
663 return fmt.Errorf("SCT list mismatch")
664 }
665
Nick Harper60edffd2016-06-21 15:19:24 -0700666 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
667 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400668 }
669
Steven Valdez5440fe02016-07-18 12:40:30 -0400670 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
671 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
672 }
673
David Benjamin2c516452016-11-15 10:16:54 +0900674 if test.expectPeerCertificate != nil {
675 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
676 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
677 }
678 for i, cert := range connState.PeerCertificates {
679 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
680 return fmt.Errorf("peer certificate %d did not match", i+1)
681 }
682 }
683 }
684
David Benjaminc565ebb2015-04-03 04:06:36 -0400685 if test.exportKeyingMaterial > 0 {
686 actual := make([]byte, test.exportKeyingMaterial)
687 if _, err := io.ReadFull(tlsConn, actual); err != nil {
688 return err
689 }
690 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
691 if err != nil {
692 return err
693 }
694 if !bytes.Equal(actual, expected) {
695 return fmt.Errorf("keying material mismatch")
696 }
697 }
698
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700699 if test.testTLSUnique {
700 var peersValue [12]byte
701 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
702 return err
703 }
704 expected := tlsConn.ConnectionState().TLSUnique
705 if !bytes.Equal(peersValue[:], expected) {
706 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
707 }
708 }
709
David Benjamin47921102016-07-28 11:29:18 -0400710 if test.sendHalfHelloRequest {
711 tlsConn.SendHalfHelloRequest()
712 }
713
Steven Valdeze831a812017-03-09 14:56:07 -0500714 shimPrefix := test.shimPrefix
715 if isResume {
716 shimPrefix = test.resumeShimPrefix
717 }
718 if test.shimWritesFirst || test.readWithUnfinishedWrite {
719 shimPrefix = "hello"
720 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400721 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400722 // If readWithUnfinishedWrite is set, the shim prefix will be
723 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500724 if shimPrefix != "" && !test.readWithUnfinishedWrite {
725 var buf = make([]byte, len(shimPrefix))
726 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400727 if err != nil {
728 return err
729 }
Steven Valdeze831a812017-03-09 14:56:07 -0500730 if string(buf) != shimPrefix {
731 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400732 }
Steven Valdeze831a812017-03-09 14:56:07 -0500733 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400734 }
735
Adam Langleycf2d4f42014-10-28 19:06:14 -0700736 if test.renegotiateCiphers != nil {
737 config.CipherSuites = test.renegotiateCiphers
738 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400739 for i := 0; i < test.renegotiate; i++ {
740 if err := tlsConn.Renegotiate(); err != nil {
741 return err
742 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700743 }
744 } else if test.renegotiateCiphers != nil {
745 panic("renegotiateCiphers without renegotiate")
746 }
747
David Benjamin5fa3eba2015-01-22 16:35:40 -0500748 if test.damageFirstWrite {
749 connDamage.setDamage(true)
750 tlsConn.Write([]byte("DAMAGED WRITE"))
751 connDamage.setDamage(false)
752 }
753
David Benjamin8e6db492015-07-25 18:29:23 -0400754 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700755 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400756 if test.protocol == dtls {
757 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
758 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700759 // Read until EOF.
760 _, err := io.Copy(ioutil.Discard, tlsConn)
761 return err
762 }
David Benjamin4417d052015-04-05 04:17:25 -0400763 if messageLen == 0 {
764 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700765 }
Adam Langley95c29f32014-06-20 12:00:00 -0700766
David Benjamin8e6db492015-07-25 18:29:23 -0400767 messageCount := test.messageCount
768 if messageCount == 0 {
769 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400770 }
771
David Benjamin8e6db492015-07-25 18:29:23 -0400772 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400773 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400774 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400775 }
776
David Benjamin8e6db492015-07-25 18:29:23 -0400777 for i := 0; i < test.sendEmptyRecords; i++ {
778 tlsConn.Write(nil)
779 }
780
781 for i := 0; i < test.sendWarningAlerts; i++ {
782 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
783 }
784
David Benjamin24e58862017-06-14 18:45:29 -0400785 if test.sendBogusAlertType {
786 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
787 }
788
David Benjaminbbba9392017-04-06 12:54:12 -0400789 testMessage := make([]byte, messageLen)
790 for i := range testMessage {
791 testMessage[i] = 0x42 ^ byte(j)
792 }
793 tlsConn.Write(testMessage)
794
795 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500796 if shimPrefix != "" {
797 var buf = make([]byte, len(shimPrefix))
798 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400799 if err != nil {
800 return err
801 }
Steven Valdeze831a812017-03-09 14:56:07 -0500802 if string(buf) != shimPrefix {
803 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400804 }
Steven Valdeze831a812017-03-09 14:56:07 -0500805 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400806 }
807
David Benjamin4f75aaf2015-09-01 16:53:10 -0400808 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400809 // The shim will not respond.
810 continue
811 }
812
David Benjaminbbba9392017-04-06 12:54:12 -0400813 // Process the KeyUpdate ACK. However many KeyUpdates the runner
814 // sends, the shim should respond only once.
815 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
816 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
817 return err
818 }
819 }
820
David Benjamin8e6db492015-07-25 18:29:23 -0400821 buf := make([]byte, len(testMessage))
822 if test.protocol == dtls {
823 bufTmp := make([]byte, len(buf)+1)
824 n, err := tlsConn.Read(bufTmp)
825 if err != nil {
826 return err
827 }
828 if n != len(buf) {
829 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
830 }
831 copy(buf, bufTmp)
832 } else {
833 _, err := io.ReadFull(tlsConn, buf)
834 if err != nil {
835 return err
836 }
837 }
838
839 for i, v := range buf {
840 if v != testMessage[i]^0xff {
841 return fmt.Errorf("bad reply contents at byte %d", i)
842 }
Adam Langley95c29f32014-06-20 12:00:00 -0700843 }
844 }
845
846 return nil
847}
848
David Benjamin325b5c32014-07-01 19:40:31 -0400849func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400850 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700851 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400852 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700853 }
David Benjamin325b5c32014-07-01 19:40:31 -0400854 valgrindArgs = append(valgrindArgs, path)
855 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700856
David Benjamin325b5c32014-07-01 19:40:31 -0400857 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700858}
859
David Benjamin325b5c32014-07-01 19:40:31 -0400860func gdbOf(path string, args ...string) *exec.Cmd {
861 xtermArgs := []string{"-e", "gdb", "--args"}
862 xtermArgs = append(xtermArgs, path)
863 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864
David Benjamin325b5c32014-07-01 19:40:31 -0400865 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700866}
867
David Benjamind16bf342015-12-18 00:53:12 -0500868func lldbOf(path string, args ...string) *exec.Cmd {
869 xtermArgs := []string{"-e", "lldb", "--"}
870 xtermArgs = append(xtermArgs, path)
871 xtermArgs = append(xtermArgs, args...)
872
873 return exec.Command("xterm", xtermArgs...)
874}
875
EKR842ae6c2016-07-27 09:22:05 +0200876var (
877 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
878 errUnimplemented = errors.New("child process does not implement needed flags")
879)
Adam Langley69a01602014-11-17 17:26:55 -0800880
David Benjamin87c8a642015-02-21 01:54:29 -0500881// accept accepts a connection from listener, unless waitChan signals a process
882// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400883func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500884 type connOrError struct {
885 conn net.Conn
886 err error
887 }
888 connChan := make(chan connOrError, 1)
889 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400890 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500891 conn, err := listener.Accept()
892 connChan <- connOrError{conn, err}
893 close(connChan)
894 }()
895 select {
896 case result := <-connChan:
897 return result.conn, result.err
898 case childErr := <-waitChan:
899 waitChan <- childErr
900 return nil, fmt.Errorf("child exited early: %s", childErr)
901 }
902}
903
EKRf71d7ed2016-08-06 13:25:12 -0700904func translateExpectedError(errorStr string) string {
905 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
906 return translated
907 }
908
909 if *looseErrors {
910 return ""
911 }
912
913 return errorStr
914}
915
Adam Langley7c803a62015-06-15 15:35:05 -0700916func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400917 // Help debugging panics on the Go side.
918 defer func() {
919 if r := recover(); r != nil {
920 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
921 panic(r)
922 }
923 }()
924
Adam Langley38311732014-10-16 19:04:35 -0700925 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
926 panic("Error expected without shouldFail in " + test.name)
927 }
928
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700929 if test.expectResumeRejected && !test.resumeSession {
930 panic("expectResumeRejected without resumeSession in " + test.name)
931 }
932
Adam Langley33b1d4f2016-12-07 15:03:45 -0800933 for _, ver := range tlsVersions {
934 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
935 continue
936 }
937
938 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
939 continue
940 }
941
942 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))
943 }
944
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700945 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
946 if err != nil {
947 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
948 }
David Benjamin87c8a642015-02-21 01:54:29 -0500949 if err != nil {
950 panic(err)
951 }
952 defer func() {
953 if listener != nil {
954 listener.Close()
955 }
956 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700957
David Benjamin87c8a642015-02-21 01:54:29 -0500958 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400959 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400960 flags = append(flags, "-server")
961
David Benjamin025b3d32014-07-01 19:53:04 -0400962 flags = append(flags, "-key-file")
963 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700964 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400965 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700966 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400967 }
968
969 flags = append(flags, "-cert-file")
970 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700971 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400972 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700973 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400974 }
975 }
David Benjamin5a593af2014-08-11 19:51:50 -0400976
David Benjamin6fd297b2014-08-11 18:43:38 -0400977 if test.protocol == dtls {
978 flags = append(flags, "-dtls")
979 }
980
David Benjamin46662482016-08-17 00:51:00 -0400981 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400982 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400983 resumeCount++
984 if test.resumeRenewedSession {
985 resumeCount++
986 }
987 }
988
989 if resumeCount > 0 {
990 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400991 }
992
David Benjamine58c4f52014-08-24 03:47:07 -0400993 if test.shimWritesFirst {
994 flags = append(flags, "-shim-writes-first")
995 }
996
David Benjaminbbba9392017-04-06 12:54:12 -0400997 if test.readWithUnfinishedWrite {
998 flags = append(flags, "-read-with-unfinished-write")
999 }
1000
David Benjamin30789da2015-08-29 22:56:45 -04001001 if test.shimShutsDown {
1002 flags = append(flags, "-shim-shuts-down")
1003 }
1004
David Benjaminc565ebb2015-04-03 04:06:36 -04001005 if test.exportKeyingMaterial > 0 {
1006 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1007 flags = append(flags, "-export-label", test.exportLabel)
1008 flags = append(flags, "-export-context", test.exportContext)
1009 if test.useExportContext {
1010 flags = append(flags, "-use-export-context")
1011 }
1012 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001013 if test.expectResumeRejected {
1014 flags = append(flags, "-expect-session-miss")
1015 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001016
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001017 if test.testTLSUnique {
1018 flags = append(flags, "-tls-unique")
1019 }
1020
David Benjamin0fde2eb2017-06-30 19:11:22 -04001021 var transcriptPrefix string
1022 if len(*transcriptDir) != 0 {
1023 protocol := "tls"
1024 if test.protocol == dtls {
1025 protocol = "dtls"
1026 }
1027
1028 side := "client"
1029 if test.testType == serverTest {
1030 side = "server"
1031 }
1032
1033 dir := filepath.Join(*transcriptDir, protocol, side)
1034 if err := os.MkdirAll(dir, 0755); err != nil {
1035 return err
1036 }
1037 transcriptPrefix = filepath.Join(dir, test.name+"-")
1038 flags = append(flags, "-write-settings", transcriptPrefix)
1039 }
1040
David Benjamin025b3d32014-07-01 19:53:04 -04001041 flags = append(flags, test.flags...)
1042
1043 var shim *exec.Cmd
1044 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001045 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001046 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001047 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001048 } else if *useLLDB {
1049 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001050 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001051 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001052 }
David Benjamin025b3d32014-07-01 19:53:04 -04001053 shim.Stdin = os.Stdin
1054 var stdoutBuf, stderrBuf bytes.Buffer
1055 shim.Stdout = &stdoutBuf
1056 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001057 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001058 shim.Env = os.Environ()
1059 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001060 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001061 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001062 }
1063 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1064 }
David Benjamin025b3d32014-07-01 19:53:04 -04001065
1066 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001067 panic(err)
1068 }
David Benjamin87c8a642015-02-21 01:54:29 -05001069 waitChan := make(chan error, 1)
1070 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001071
1072 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001073
David Benjamin7a4aaa42016-09-20 17:58:14 -04001074 if *deterministic {
1075 config.Rand = &deterministicRand{}
1076 }
1077
David Benjamin87c8a642015-02-21 01:54:29 -05001078 conn, err := acceptOrWait(listener, waitChan)
1079 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001080 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001081 conn.Close()
1082 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001083
David Benjamin46662482016-08-17 00:51:00 -04001084 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001085 var resumeConfig Config
1086 if test.resumeConfig != nil {
1087 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001088 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001089 resumeConfig.SessionTicketKey = config.SessionTicketKey
1090 resumeConfig.ClientSessionCache = config.ClientSessionCache
1091 resumeConfig.ServerSessionCache = config.ServerSessionCache
1092 }
David Benjamin2e045a92016-06-08 13:09:56 -04001093 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001094 } else {
1095 resumeConfig = config
1096 }
David Benjamin87c8a642015-02-21 01:54:29 -05001097 var connResume net.Conn
1098 connResume, err = acceptOrWait(listener, waitChan)
1099 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001100 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001101 connResume.Close()
1102 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001103 }
1104
David Benjamin87c8a642015-02-21 01:54:29 -05001105 // Close the listener now. This is to avoid hangs should the shim try to
1106 // open more connections than expected.
1107 listener.Close()
1108 listener = nil
1109
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001110 var shimKilledLock sync.Mutex
1111 var shimKilled bool
1112 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1113 shimKilledLock.Lock()
1114 shimKilled = true
1115 shimKilledLock.Unlock()
1116 shim.Process.Kill()
1117 })
David Benjamin87c8a642015-02-21 01:54:29 -05001118 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001119 waitTimeout.Stop()
1120 shimKilledLock.Lock()
1121 if shimKilled && err == nil {
1122 err = errors.New("timeout waiting for the shim to exit.")
1123 }
1124 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001125 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001126 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001127 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1128 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001129 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001130 case 89:
1131 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001132 case 99:
1133 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001134 }
1135 }
Adam Langley95c29f32014-06-20 12:00:00 -07001136
David Benjamin9bea3492016-03-02 10:59:16 -05001137 // Account for Windows line endings.
1138 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1139 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001140
1141 // Separate the errors from the shim and those from tools like
1142 // AddressSanitizer.
1143 var extraStderr string
1144 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1145 stderr = stderrParts[0]
1146 extraStderr = stderrParts[1]
1147 }
1148
Adam Langley95c29f32014-06-20 12:00:00 -07001149 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001150 expectedError := translateExpectedError(test.expectedError)
1151 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001152
Adam Langleyac61fa32014-06-23 12:03:11 -07001153 localError := "none"
1154 if err != nil {
1155 localError = err.Error()
1156 }
1157 if len(test.expectedLocalError) != 0 {
1158 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1159 }
Adam Langley95c29f32014-06-20 12:00:00 -07001160
1161 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001162 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001163 if childErr != nil {
1164 childError = childErr.Error()
1165 }
1166
1167 var msg string
1168 switch {
1169 case failed && !test.shouldFail:
1170 msg = "unexpected failure"
1171 case !failed && test.shouldFail:
1172 msg = "unexpected success"
1173 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001174 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001175 default:
1176 panic("internal error")
1177 }
1178
David Benjamin9aafb642016-09-20 19:36:53 -04001179 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 -07001180 }
1181
David Benjamind2ba8892016-09-20 19:41:04 -04001182 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001183 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001184 }
1185
David Benjamind2ba8892016-09-20 19:41:04 -04001186 if *useValgrind && isValgrindError {
1187 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1188 }
1189
Adam Langley95c29f32014-06-20 12:00:00 -07001190 return nil
1191}
1192
David Benjaminaa012042016-12-10 13:33:05 -05001193type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001194 name string
1195 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001196 // excludeFlag is the legacy shim flag to disable the version.
1197 excludeFlag string
1198 hasDTLS bool
1199 // shimTLS and shimDTLS are values the shim uses to refer to these
1200 // versions in TLS and DTLS, respectively.
1201 shimTLS, shimDTLS int
1202}
1203
1204func (vers tlsVersion) shimFlag(protocol protocol) string {
1205 if protocol == dtls {
1206 return strconv.Itoa(vers.shimDTLS)
1207 }
1208 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001209}
1210
1211var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001212 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1213 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1214 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1215 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1216 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001217}
1218
David Benjaminaa012042016-12-10 13:33:05 -05001219type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001220 name string
1221 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001222}
1223
1224var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001225 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001226 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001227 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001228 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001229 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001230 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001231 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001232 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1233 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001234 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1235 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001236 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001237 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001238 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001239 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001240 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001241 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001242 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001243 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001244 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001245 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001246 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1247 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001248 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1249 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001250 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001251 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1252 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1253 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001254 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001255}
1256
David Benjamin8b8c0062014-11-23 02:47:52 -05001257func hasComponent(suiteName, component string) bool {
1258 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1259}
1260
David Benjaminf7768e42014-08-31 02:06:47 -04001261func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001262 return hasComponent(suiteName, "GCM") ||
1263 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001264 hasComponent(suiteName, "SHA384") ||
1265 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001266}
1267
Nick Harper1fd39d82016-06-14 18:14:35 -07001268func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001269 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001270}
1271
David Benjamin8b8c0062014-11-23 02:47:52 -05001272func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001273 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001274}
1275
Adam Langleya7997f12015-05-14 17:38:50 -07001276func bigFromHex(hex string) *big.Int {
1277 ret, ok := new(big.Int).SetString(hex, 16)
1278 if !ok {
1279 panic("failed to parse hex number 0x" + hex)
1280 }
1281 return ret
1282}
1283
Adam Langley7c803a62015-06-15 15:35:05 -07001284func addBasicTests() {
1285 basicTests := []testCase{
1286 {
Adam Langley7c803a62015-06-15 15:35:05 -07001287 name: "NoFallbackSCSV",
1288 config: Config{
1289 Bugs: ProtocolBugs{
1290 FailIfNotFallbackSCSV: true,
1291 },
1292 },
1293 shouldFail: true,
1294 expectedLocalError: "no fallback SCSV found",
1295 },
1296 {
1297 name: "SendFallbackSCSV",
1298 config: Config{
1299 Bugs: ProtocolBugs{
1300 FailIfNotFallbackSCSV: true,
1301 },
1302 },
1303 flags: []string{"-fallback-scsv"},
1304 },
1305 {
1306 name: "ClientCertificateTypes",
1307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001308 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 ClientAuth: RequestClientCert,
1310 ClientCertificateTypes: []byte{
1311 CertTypeDSSSign,
1312 CertTypeRSASign,
1313 CertTypeECDSASign,
1314 },
1315 },
1316 flags: []string{
1317 "-expect-certificate-types",
1318 base64.StdEncoding.EncodeToString([]byte{
1319 CertTypeDSSSign,
1320 CertTypeRSASign,
1321 CertTypeECDSASign,
1322 }),
1323 },
1324 },
1325 {
Adam Langley7c803a62015-06-15 15:35:05 -07001326 name: "UnauthenticatedECDH",
1327 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001328 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001329 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1330 Bugs: ProtocolBugs{
1331 UnauthenticatedECDH: true,
1332 },
1333 },
1334 shouldFail: true,
1335 expectedError: ":UNEXPECTED_MESSAGE:",
1336 },
1337 {
1338 name: "SkipCertificateStatus",
1339 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001340 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1342 Bugs: ProtocolBugs{
1343 SkipCertificateStatus: true,
1344 },
1345 },
1346 flags: []string{
1347 "-enable-ocsp-stapling",
1348 },
1349 },
1350 {
1351 name: "SkipServerKeyExchange",
1352 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001353 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001354 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1355 Bugs: ProtocolBugs{
1356 SkipServerKeyExchange: true,
1357 },
1358 },
1359 shouldFail: true,
1360 expectedError: ":UNEXPECTED_MESSAGE:",
1361 },
1362 {
Adam Langley7c803a62015-06-15 15:35:05 -07001363 testType: serverTest,
1364 name: "Alert",
1365 config: Config{
1366 Bugs: ProtocolBugs{
1367 SendSpuriousAlert: alertRecordOverflow,
1368 },
1369 },
1370 shouldFail: true,
1371 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1372 },
1373 {
1374 protocol: dtls,
1375 testType: serverTest,
1376 name: "Alert-DTLS",
1377 config: Config{
1378 Bugs: ProtocolBugs{
1379 SendSpuriousAlert: alertRecordOverflow,
1380 },
1381 },
1382 shouldFail: true,
1383 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1384 },
1385 {
1386 testType: serverTest,
1387 name: "FragmentAlert",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 FragmentAlert: true,
1391 SendSpuriousAlert: alertRecordOverflow,
1392 },
1393 },
1394 shouldFail: true,
1395 expectedError: ":BAD_ALERT:",
1396 },
1397 {
1398 protocol: dtls,
1399 testType: serverTest,
1400 name: "FragmentAlert-DTLS",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 FragmentAlert: true,
1404 SendSpuriousAlert: alertRecordOverflow,
1405 },
1406 },
1407 shouldFail: true,
1408 expectedError: ":BAD_ALERT:",
1409 },
1410 {
1411 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001412 name: "DoubleAlert",
1413 config: Config{
1414 Bugs: ProtocolBugs{
1415 DoubleAlert: true,
1416 SendSpuriousAlert: alertRecordOverflow,
1417 },
1418 },
1419 shouldFail: true,
1420 expectedError: ":BAD_ALERT:",
1421 },
1422 {
1423 protocol: dtls,
1424 testType: serverTest,
1425 name: "DoubleAlert-DTLS",
1426 config: Config{
1427 Bugs: ProtocolBugs{
1428 DoubleAlert: true,
1429 SendSpuriousAlert: alertRecordOverflow,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":BAD_ALERT:",
1434 },
1435 {
Adam Langley7c803a62015-06-15 15:35:05 -07001436 name: "SkipNewSessionTicket",
1437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001438 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001439 Bugs: ProtocolBugs{
1440 SkipNewSessionTicket: true,
1441 },
1442 },
1443 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001444 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001445 },
1446 {
1447 testType: serverTest,
1448 name: "FallbackSCSV",
1449 config: Config{
1450 MaxVersion: VersionTLS11,
1451 Bugs: ProtocolBugs{
1452 SendFallbackSCSV: true,
1453 },
1454 },
David Benjamin56cadc32016-12-16 19:54:11 -05001455 shouldFail: true,
1456 expectedError: ":INAPPROPRIATE_FALLBACK:",
1457 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001458 },
1459 {
1460 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001461 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001462 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001463 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001464 Bugs: ProtocolBugs{
1465 SendFallbackSCSV: true,
1466 },
1467 },
1468 },
1469 {
1470 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001471 name: "FallbackSCSV-VersionMatch-TLS12",
1472 config: Config{
1473 MaxVersion: VersionTLS12,
1474 Bugs: ProtocolBugs{
1475 SendFallbackSCSV: true,
1476 },
1477 },
1478 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1479 },
1480 {
1481 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "FragmentedClientVersion",
1483 config: Config{
1484 Bugs: ProtocolBugs{
1485 MaxHandshakeRecordLength: 1,
1486 FragmentClientVersion: true,
1487 },
1488 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001489 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001490 },
1491 {
Adam Langley7c803a62015-06-15 15:35:05 -07001492 testType: serverTest,
1493 name: "HttpGET",
1494 sendPrefix: "GET / HTTP/1.0\n",
1495 shouldFail: true,
1496 expectedError: ":HTTP_REQUEST:",
1497 },
1498 {
1499 testType: serverTest,
1500 name: "HttpPOST",
1501 sendPrefix: "POST / HTTP/1.0\n",
1502 shouldFail: true,
1503 expectedError: ":HTTP_REQUEST:",
1504 },
1505 {
1506 testType: serverTest,
1507 name: "HttpHEAD",
1508 sendPrefix: "HEAD / HTTP/1.0\n",
1509 shouldFail: true,
1510 expectedError: ":HTTP_REQUEST:",
1511 },
1512 {
1513 testType: serverTest,
1514 name: "HttpPUT",
1515 sendPrefix: "PUT / HTTP/1.0\n",
1516 shouldFail: true,
1517 expectedError: ":HTTP_REQUEST:",
1518 },
1519 {
1520 testType: serverTest,
1521 name: "HttpCONNECT",
1522 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1523 shouldFail: true,
1524 expectedError: ":HTTPS_PROXY_REQUEST:",
1525 },
1526 {
1527 testType: serverTest,
1528 name: "Garbage",
1529 sendPrefix: "blah",
1530 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001531 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001532 },
1533 {
Adam Langley7c803a62015-06-15 15:35:05 -07001534 name: "RSAEphemeralKey",
1535 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001536 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001537 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1538 Bugs: ProtocolBugs{
1539 RSAEphemeralKey: true,
1540 },
1541 },
1542 shouldFail: true,
1543 expectedError: ":UNEXPECTED_MESSAGE:",
1544 },
1545 {
1546 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001547 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001548 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001549 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001550 },
1551 {
1552 protocol: dtls,
1553 name: "DisableEverything-DTLS",
1554 flags: []string{"-no-tls12", "-no-tls1"},
1555 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001556 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 testType: serverTest,
1561 name: "MTU",
1562 config: Config{
1563 Bugs: ProtocolBugs{
1564 MaxPacketLength: 256,
1565 },
1566 },
1567 flags: []string{"-mtu", "256"},
1568 },
1569 {
1570 protocol: dtls,
1571 testType: serverTest,
1572 name: "MTUExceeded",
1573 config: Config{
1574 Bugs: ProtocolBugs{
1575 MaxPacketLength: 255,
1576 },
1577 },
1578 flags: []string{"-mtu", "256"},
1579 shouldFail: true,
1580 expectedLocalError: "dtls: exceeded maximum packet length",
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "EmptyCertificateList",
1584 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 EmptyCertificateList: true,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":DECODE_ERROR:",
1592 },
1593 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001594 name: "EmptyCertificateList-TLS13",
1595 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001596 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001597 Bugs: ProtocolBugs{
1598 EmptyCertificateList: true,
1599 },
1600 },
1601 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001602 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001603 },
1604 {
Adam Langley7c803a62015-06-15 15:35:05 -07001605 name: "TLSFatalBadPackets",
1606 damageFirstWrite: true,
1607 shouldFail: true,
1608 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1609 },
1610 {
1611 protocol: dtls,
1612 name: "DTLSIgnoreBadPackets",
1613 damageFirstWrite: true,
1614 },
1615 {
1616 protocol: dtls,
1617 name: "DTLSIgnoreBadPackets-Async",
1618 damageFirstWrite: true,
1619 flags: []string{"-async"},
1620 },
1621 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001622 name: "AppDataBeforeHandshake",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1626 },
1627 },
1628 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001629 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001630 },
1631 {
1632 name: "AppDataBeforeHandshake-Empty",
1633 config: Config{
1634 Bugs: ProtocolBugs{
1635 AppDataBeforeHandshake: []byte{},
1636 },
1637 },
1638 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001639 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001640 },
1641 {
1642 protocol: dtls,
1643 name: "AppDataBeforeHandshake-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":UNEXPECTED_RECORD:",
1651 },
1652 {
1653 protocol: dtls,
1654 name: "AppDataBeforeHandshake-DTLS-Empty",
1655 config: Config{
1656 Bugs: ProtocolBugs{
1657 AppDataBeforeHandshake: []byte{},
1658 },
1659 },
1660 shouldFail: true,
1661 expectedError: ":UNEXPECTED_RECORD:",
1662 },
1663 {
Adam Langley7c803a62015-06-15 15:35:05 -07001664 name: "AppDataAfterChangeCipherSpec",
1665 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001666 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001667 Bugs: ProtocolBugs{
1668 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1669 },
1670 },
1671 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001672 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001673 },
1674 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001675 name: "AppDataAfterChangeCipherSpec-Empty",
1676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001677 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001678 Bugs: ProtocolBugs{
1679 AppDataAfterChangeCipherSpec: []byte{},
1680 },
1681 },
1682 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001683 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001684 },
1685 {
Adam Langley7c803a62015-06-15 15:35:05 -07001686 protocol: dtls,
1687 name: "AppDataAfterChangeCipherSpec-DTLS",
1688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001689 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001690 Bugs: ProtocolBugs{
1691 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1692 },
1693 },
1694 // BoringSSL's DTLS implementation will drop the out-of-order
1695 // application data.
1696 },
1697 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001698 protocol: dtls,
1699 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1700 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001701 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001702 Bugs: ProtocolBugs{
1703 AppDataAfterChangeCipherSpec: []byte{},
1704 },
1705 },
1706 // BoringSSL's DTLS implementation will drop the out-of-order
1707 // application data.
1708 },
1709 {
Adam Langley7c803a62015-06-15 15:35:05 -07001710 name: "AlertAfterChangeCipherSpec",
1711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001712 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001713 Bugs: ProtocolBugs{
1714 AlertAfterChangeCipherSpec: alertRecordOverflow,
1715 },
1716 },
1717 shouldFail: true,
1718 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1719 },
1720 {
1721 protocol: dtls,
1722 name: "AlertAfterChangeCipherSpec-DTLS",
1723 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001724 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001725 Bugs: ProtocolBugs{
1726 AlertAfterChangeCipherSpec: alertRecordOverflow,
1727 },
1728 },
1729 shouldFail: true,
1730 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1731 },
1732 {
1733 protocol: dtls,
1734 name: "ReorderHandshakeFragments-Small-DTLS",
1735 config: Config{
1736 Bugs: ProtocolBugs{
1737 ReorderHandshakeFragments: true,
1738 // Small enough that every handshake message is
1739 // fragmented.
1740 MaxHandshakeRecordLength: 2,
1741 },
1742 },
1743 },
1744 {
1745 protocol: dtls,
1746 name: "ReorderHandshakeFragments-Large-DTLS",
1747 config: Config{
1748 Bugs: ProtocolBugs{
1749 ReorderHandshakeFragments: true,
1750 // Large enough that no handshake message is
1751 // fragmented.
1752 MaxHandshakeRecordLength: 2048,
1753 },
1754 },
1755 },
1756 {
1757 protocol: dtls,
1758 name: "MixCompleteMessageWithFragments-DTLS",
1759 config: Config{
1760 Bugs: ProtocolBugs{
1761 ReorderHandshakeFragments: true,
1762 MixCompleteMessageWithFragments: true,
1763 MaxHandshakeRecordLength: 2,
1764 },
1765 },
1766 },
1767 {
1768 name: "SendInvalidRecordType",
1769 config: Config{
1770 Bugs: ProtocolBugs{
1771 SendInvalidRecordType: true,
1772 },
1773 },
1774 shouldFail: true,
1775 expectedError: ":UNEXPECTED_RECORD:",
1776 },
1777 {
1778 protocol: dtls,
1779 name: "SendInvalidRecordType-DTLS",
1780 config: Config{
1781 Bugs: ProtocolBugs{
1782 SendInvalidRecordType: true,
1783 },
1784 },
1785 shouldFail: true,
1786 expectedError: ":UNEXPECTED_RECORD:",
1787 },
1788 {
1789 name: "FalseStart-SkipServerSecondLeg",
1790 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001791 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1793 NextProtos: []string{"foo"},
1794 Bugs: ProtocolBugs{
1795 SkipNewSessionTicket: true,
1796 SkipChangeCipherSpec: true,
1797 SkipFinished: true,
1798 ExpectFalseStart: true,
1799 },
1800 },
1801 flags: []string{
1802 "-false-start",
1803 "-handshake-never-done",
1804 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001805 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001806 },
1807 shimWritesFirst: true,
1808 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001809 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 },
1811 {
1812 name: "FalseStart-SkipServerSecondLeg-Implicit",
1813 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001814 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1816 NextProtos: []string{"foo"},
1817 Bugs: ProtocolBugs{
1818 SkipNewSessionTicket: true,
1819 SkipChangeCipherSpec: true,
1820 SkipFinished: true,
1821 },
1822 },
1823 flags: []string{
1824 "-implicit-handshake",
1825 "-false-start",
1826 "-handshake-never-done",
1827 "-advertise-alpn", "\x03foo",
1828 },
1829 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001830 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001831 },
1832 {
1833 testType: serverTest,
1834 name: "FailEarlyCallback",
1835 flags: []string{"-fail-early-callback"},
1836 shouldFail: true,
1837 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001838 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001839 },
1840 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001841 name: "FailCertCallback-Client-TLS12",
1842 config: Config{
1843 MaxVersion: VersionTLS12,
1844 ClientAuth: RequestClientCert,
1845 },
1846 flags: []string{"-fail-cert-callback"},
1847 shouldFail: true,
1848 expectedError: ":CERT_CB_ERROR:",
1849 expectedLocalError: "remote error: internal error",
1850 },
1851 {
1852 testType: serverTest,
1853 name: "FailCertCallback-Server-TLS12",
1854 config: Config{
1855 MaxVersion: VersionTLS12,
1856 },
1857 flags: []string{"-fail-cert-callback"},
1858 shouldFail: true,
1859 expectedError: ":CERT_CB_ERROR:",
1860 expectedLocalError: "remote error: internal error",
1861 },
1862 {
1863 name: "FailCertCallback-Client-TLS13",
1864 config: Config{
1865 MaxVersion: VersionTLS13,
1866 ClientAuth: RequestClientCert,
1867 },
1868 flags: []string{"-fail-cert-callback"},
1869 shouldFail: true,
1870 expectedError: ":CERT_CB_ERROR:",
1871 expectedLocalError: "remote error: internal error",
1872 },
1873 {
1874 testType: serverTest,
1875 name: "FailCertCallback-Server-TLS13",
1876 config: Config{
1877 MaxVersion: VersionTLS13,
1878 },
1879 flags: []string{"-fail-cert-callback"},
1880 shouldFail: true,
1881 expectedError: ":CERT_CB_ERROR:",
1882 expectedLocalError: "remote error: internal error",
1883 },
1884 {
Adam Langley7c803a62015-06-15 15:35:05 -07001885 protocol: dtls,
1886 name: "FragmentMessageTypeMismatch-DTLS",
1887 config: Config{
1888 Bugs: ProtocolBugs{
1889 MaxHandshakeRecordLength: 2,
1890 FragmentMessageTypeMismatch: true,
1891 },
1892 },
1893 shouldFail: true,
1894 expectedError: ":FRAGMENT_MISMATCH:",
1895 },
1896 {
1897 protocol: dtls,
1898 name: "FragmentMessageLengthMismatch-DTLS",
1899 config: Config{
1900 Bugs: ProtocolBugs{
1901 MaxHandshakeRecordLength: 2,
1902 FragmentMessageLengthMismatch: true,
1903 },
1904 },
1905 shouldFail: true,
1906 expectedError: ":FRAGMENT_MISMATCH:",
1907 },
1908 {
1909 protocol: dtls,
1910 name: "SplitFragments-Header-DTLS",
1911 config: Config{
1912 Bugs: ProtocolBugs{
1913 SplitFragments: 2,
1914 },
1915 },
1916 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001917 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001918 },
1919 {
1920 protocol: dtls,
1921 name: "SplitFragments-Boundary-DTLS",
1922 config: Config{
1923 Bugs: ProtocolBugs{
1924 SplitFragments: dtlsRecordHeaderLen,
1925 },
1926 },
1927 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001928 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001929 },
1930 {
1931 protocol: dtls,
1932 name: "SplitFragments-Body-DTLS",
1933 config: Config{
1934 Bugs: ProtocolBugs{
1935 SplitFragments: dtlsRecordHeaderLen + 1,
1936 },
1937 },
1938 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001939 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001940 },
1941 {
1942 protocol: dtls,
1943 name: "SendEmptyFragments-DTLS",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 SendEmptyFragments: true,
1947 },
1948 },
1949 },
1950 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001951 name: "BadFinished-Client",
1952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001953 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001954 Bugs: ProtocolBugs{
1955 BadFinished: true,
1956 },
1957 },
1958 shouldFail: true,
1959 expectedError: ":DIGEST_CHECK_FAILED:",
1960 },
1961 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001962 name: "BadFinished-Client-TLS13",
1963 config: Config{
1964 MaxVersion: VersionTLS13,
1965 Bugs: ProtocolBugs{
1966 BadFinished: true,
1967 },
1968 },
1969 shouldFail: true,
1970 expectedError: ":DIGEST_CHECK_FAILED:",
1971 },
1972 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001973 testType: serverTest,
1974 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001976 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001977 Bugs: ProtocolBugs{
1978 BadFinished: true,
1979 },
1980 },
1981 shouldFail: true,
1982 expectedError: ":DIGEST_CHECK_FAILED:",
1983 },
1984 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001985 testType: serverTest,
1986 name: "BadFinished-Server-TLS13",
1987 config: Config{
1988 MaxVersion: VersionTLS13,
1989 Bugs: ProtocolBugs{
1990 BadFinished: true,
1991 },
1992 },
1993 shouldFail: true,
1994 expectedError: ":DIGEST_CHECK_FAILED:",
1995 },
1996 {
Adam Langley7c803a62015-06-15 15:35:05 -07001997 name: "FalseStart-BadFinished",
1998 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001999 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002000 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2001 NextProtos: []string{"foo"},
2002 Bugs: ProtocolBugs{
2003 BadFinished: true,
2004 ExpectFalseStart: true,
2005 },
2006 },
2007 flags: []string{
2008 "-false-start",
2009 "-handshake-never-done",
2010 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002011 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002012 },
2013 shimWritesFirst: true,
2014 shouldFail: true,
2015 expectedError: ":DIGEST_CHECK_FAILED:",
2016 },
2017 {
2018 name: "NoFalseStart-NoALPN",
2019 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002020 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002021 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2022 Bugs: ProtocolBugs{
2023 ExpectFalseStart: true,
2024 AlertBeforeFalseStartTest: alertAccessDenied,
2025 },
2026 },
2027 flags: []string{
2028 "-false-start",
2029 },
2030 shimWritesFirst: true,
2031 shouldFail: true,
2032 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2033 expectedLocalError: "tls: peer did not false start: EOF",
2034 },
2035 {
2036 name: "NoFalseStart-NoAEAD",
2037 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002038 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002039 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2040 NextProtos: []string{"foo"},
2041 Bugs: ProtocolBugs{
2042 ExpectFalseStart: true,
2043 AlertBeforeFalseStartTest: alertAccessDenied,
2044 },
2045 },
2046 flags: []string{
2047 "-false-start",
2048 "-advertise-alpn", "\x03foo",
2049 },
2050 shimWritesFirst: true,
2051 shouldFail: true,
2052 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2053 expectedLocalError: "tls: peer did not false start: EOF",
2054 },
2055 {
2056 name: "NoFalseStart-RSA",
2057 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002058 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002059 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2060 NextProtos: []string{"foo"},
2061 Bugs: ProtocolBugs{
2062 ExpectFalseStart: true,
2063 AlertBeforeFalseStartTest: alertAccessDenied,
2064 },
2065 },
2066 flags: []string{
2067 "-false-start",
2068 "-advertise-alpn", "\x03foo",
2069 },
2070 shimWritesFirst: true,
2071 shouldFail: true,
2072 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2073 expectedLocalError: "tls: peer did not false start: EOF",
2074 },
2075 {
Adam Langley7c803a62015-06-15 15:35:05 -07002076 protocol: dtls,
2077 name: "SendSplitAlert-Sync",
2078 config: Config{
2079 Bugs: ProtocolBugs{
2080 SendSplitAlert: true,
2081 },
2082 },
2083 },
2084 {
2085 protocol: dtls,
2086 name: "SendSplitAlert-Async",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendSplitAlert: true,
2090 },
2091 },
2092 flags: []string{"-async"},
2093 },
2094 {
2095 protocol: dtls,
2096 name: "PackDTLSHandshake",
2097 config: Config{
2098 Bugs: ProtocolBugs{
2099 MaxHandshakeRecordLength: 2,
2100 PackHandshakeFragments: 20,
2101 PackHandshakeRecords: 200,
2102 },
2103 },
2104 },
2105 {
Adam Langley7c803a62015-06-15 15:35:05 -07002106 name: "SendEmptyRecords-Pass",
2107 sendEmptyRecords: 32,
2108 },
2109 {
2110 name: "SendEmptyRecords",
2111 sendEmptyRecords: 33,
2112 shouldFail: true,
2113 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2114 },
2115 {
2116 name: "SendEmptyRecords-Async",
2117 sendEmptyRecords: 33,
2118 flags: []string{"-async"},
2119 shouldFail: true,
2120 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2121 },
2122 {
David Benjamine8e84b92016-08-03 15:39:47 -04002123 name: "SendWarningAlerts-Pass",
2124 config: Config{
2125 MaxVersion: VersionTLS12,
2126 },
Adam Langley7c803a62015-06-15 15:35:05 -07002127 sendWarningAlerts: 4,
2128 },
2129 {
David Benjamine8e84b92016-08-03 15:39:47 -04002130 protocol: dtls,
2131 name: "SendWarningAlerts-DTLS-Pass",
2132 config: Config{
2133 MaxVersion: VersionTLS12,
2134 },
Adam Langley7c803a62015-06-15 15:35:05 -07002135 sendWarningAlerts: 4,
2136 },
2137 {
David Benjamine8e84b92016-08-03 15:39:47 -04002138 name: "SendWarningAlerts-TLS13",
2139 config: Config{
2140 MaxVersion: VersionTLS13,
2141 },
2142 sendWarningAlerts: 4,
2143 shouldFail: true,
2144 expectedError: ":BAD_ALERT:",
2145 expectedLocalError: "remote error: error decoding message",
2146 },
2147 {
2148 name: "SendWarningAlerts",
2149 config: Config{
2150 MaxVersion: VersionTLS12,
2151 },
Adam Langley7c803a62015-06-15 15:35:05 -07002152 sendWarningAlerts: 5,
2153 shouldFail: true,
2154 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2155 },
2156 {
David Benjamine8e84b92016-08-03 15:39:47 -04002157 name: "SendWarningAlerts-Async",
2158 config: Config{
2159 MaxVersion: VersionTLS12,
2160 },
Adam Langley7c803a62015-06-15 15:35:05 -07002161 sendWarningAlerts: 5,
2162 flags: []string{"-async"},
2163 shouldFail: true,
2164 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2165 },
David Benjaminba4594a2015-06-18 18:36:15 -04002166 {
David Benjamin24e58862017-06-14 18:45:29 -04002167 name: "SendBogusAlertType",
2168 sendBogusAlertType: true,
2169 shouldFail: true,
2170 expectedError: ":UNKNOWN_ALERT_TYPE:",
2171 expectedLocalError: "remote error: illegal parameter",
2172 },
2173 {
2174 protocol: dtls,
2175 name: "SendBogusAlertType-DTLS",
2176 sendBogusAlertType: true,
2177 shouldFail: true,
2178 expectedError: ":UNKNOWN_ALERT_TYPE:",
2179 expectedLocalError: "remote error: illegal parameter",
2180 },
2181 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002182 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002183 config: Config{
2184 MaxVersion: VersionTLS13,
2185 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002186 sendKeyUpdates: 33,
2187 keyUpdateRequest: keyUpdateNotRequested,
2188 shouldFail: true,
2189 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002190 },
2191 {
David Benjaminba4594a2015-06-18 18:36:15 -04002192 name: "EmptySessionID",
2193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002194 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002195 SessionTicketsDisabled: true,
2196 },
2197 noSessionCache: true,
2198 flags: []string{"-expect-no-session"},
2199 },
David Benjamin30789da2015-08-29 22:56:45 -04002200 {
2201 name: "Unclean-Shutdown",
2202 config: Config{
2203 Bugs: ProtocolBugs{
2204 NoCloseNotify: true,
2205 ExpectCloseNotify: true,
2206 },
2207 },
2208 shimShutsDown: true,
2209 flags: []string{"-check-close-notify"},
2210 shouldFail: true,
2211 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2212 },
2213 {
2214 name: "Unclean-Shutdown-Ignored",
2215 config: Config{
2216 Bugs: ProtocolBugs{
2217 NoCloseNotify: true,
2218 },
2219 },
2220 shimShutsDown: true,
2221 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002222 {
David Benjaminfa214e42016-05-10 17:03:10 -04002223 name: "Unclean-Shutdown-Alert",
2224 config: Config{
2225 Bugs: ProtocolBugs{
2226 SendAlertOnShutdown: alertDecompressionFailure,
2227 ExpectCloseNotify: true,
2228 },
2229 },
2230 shimShutsDown: true,
2231 flags: []string{"-check-close-notify"},
2232 shouldFail: true,
2233 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2234 },
2235 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002236 name: "LargePlaintext",
2237 config: Config{
2238 Bugs: ProtocolBugs{
2239 SendLargeRecords: true,
2240 },
2241 },
2242 messageLen: maxPlaintext + 1,
2243 shouldFail: true,
2244 expectedError: ":DATA_LENGTH_TOO_LONG:",
2245 },
2246 {
2247 protocol: dtls,
2248 name: "LargePlaintext-DTLS",
2249 config: Config{
2250 Bugs: ProtocolBugs{
2251 SendLargeRecords: true,
2252 },
2253 },
2254 messageLen: maxPlaintext + 1,
2255 shouldFail: true,
2256 expectedError: ":DATA_LENGTH_TOO_LONG:",
2257 },
2258 {
2259 name: "LargeCiphertext",
2260 config: Config{
2261 Bugs: ProtocolBugs{
2262 SendLargeRecords: true,
2263 },
2264 },
2265 messageLen: maxPlaintext * 2,
2266 shouldFail: true,
2267 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2268 },
2269 {
2270 protocol: dtls,
2271 name: "LargeCiphertext-DTLS",
2272 config: Config{
2273 Bugs: ProtocolBugs{
2274 SendLargeRecords: true,
2275 },
2276 },
2277 messageLen: maxPlaintext * 2,
2278 // Unlike the other four cases, DTLS drops records which
2279 // are invalid before authentication, so the connection
2280 // does not fail.
2281 expectMessageDropped: true,
2282 },
David Benjamindd6fed92015-10-23 17:41:12 -04002283 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002284 name: "BadHelloRequest-1",
2285 renegotiate: 1,
2286 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002287 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002288 Bugs: ProtocolBugs{
2289 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2290 },
2291 },
2292 flags: []string{
2293 "-renegotiate-freely",
2294 "-expect-total-renegotiations", "1",
2295 },
2296 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002297 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002298 },
2299 {
2300 name: "BadHelloRequest-2",
2301 renegotiate: 1,
2302 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002303 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002304 Bugs: ProtocolBugs{
2305 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2306 },
2307 },
2308 flags: []string{
2309 "-renegotiate-freely",
2310 "-expect-total-renegotiations", "1",
2311 },
2312 shouldFail: true,
2313 expectedError: ":BAD_HELLO_REQUEST:",
2314 },
David Benjaminef1b0092015-11-21 14:05:44 -05002315 {
2316 testType: serverTest,
2317 name: "SupportTicketsWithSessionID",
2318 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002319 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002320 SessionTicketsDisabled: true,
2321 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002322 resumeConfig: &Config{
2323 MaxVersion: VersionTLS12,
2324 },
David Benjaminef1b0092015-11-21 14:05:44 -05002325 resumeSession: true,
2326 },
David Benjamin02edcd02016-07-27 17:40:37 -04002327 {
2328 protocol: dtls,
2329 name: "DTLS-SendExtraFinished",
2330 config: Config{
2331 Bugs: ProtocolBugs{
2332 SendExtraFinished: true,
2333 },
2334 },
2335 shouldFail: true,
2336 expectedError: ":UNEXPECTED_RECORD:",
2337 },
2338 {
2339 protocol: dtls,
2340 name: "DTLS-SendExtraFinished-Reordered",
2341 config: Config{
2342 Bugs: ProtocolBugs{
2343 MaxHandshakeRecordLength: 2,
2344 ReorderHandshakeFragments: true,
2345 SendExtraFinished: true,
2346 },
2347 },
2348 shouldFail: true,
2349 expectedError: ":UNEXPECTED_RECORD:",
2350 },
David Benjamine97fb482016-07-29 09:23:07 -04002351 {
2352 testType: serverTest,
2353 name: "V2ClientHello-EmptyRecordPrefix",
2354 config: Config{
2355 // Choose a cipher suite that does not involve
2356 // elliptic curves, so no extensions are
2357 // involved.
2358 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002359 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002360 Bugs: ProtocolBugs{
2361 SendV2ClientHello: true,
2362 },
2363 },
2364 sendPrefix: string([]byte{
2365 byte(recordTypeHandshake),
2366 3, 1, // version
2367 0, 0, // length
2368 }),
2369 // A no-op empty record may not be sent before V2ClientHello.
2370 shouldFail: true,
2371 expectedError: ":WRONG_VERSION_NUMBER:",
2372 },
2373 {
2374 testType: serverTest,
2375 name: "V2ClientHello-WarningAlertPrefix",
2376 config: Config{
2377 // Choose a cipher suite that does not involve
2378 // elliptic curves, so no extensions are
2379 // involved.
2380 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002381 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002382 Bugs: ProtocolBugs{
2383 SendV2ClientHello: true,
2384 },
2385 },
2386 sendPrefix: string([]byte{
2387 byte(recordTypeAlert),
2388 3, 1, // version
2389 0, 2, // length
2390 alertLevelWarning, byte(alertDecompressionFailure),
2391 }),
2392 // A no-op warning alert may not be sent before V2ClientHello.
2393 shouldFail: true,
2394 expectedError: ":WRONG_VERSION_NUMBER:",
2395 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002396 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002397 name: "KeyUpdate-Client",
2398 config: Config{
2399 MaxVersion: VersionTLS13,
2400 },
2401 sendKeyUpdates: 1,
2402 keyUpdateRequest: keyUpdateNotRequested,
2403 },
2404 {
2405 testType: serverTest,
2406 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002407 config: Config{
2408 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002409 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002410 sendKeyUpdates: 1,
2411 keyUpdateRequest: keyUpdateNotRequested,
2412 },
2413 {
2414 name: "KeyUpdate-InvalidRequestMode",
2415 config: Config{
2416 MaxVersion: VersionTLS13,
2417 },
2418 sendKeyUpdates: 1,
2419 keyUpdateRequest: 42,
2420 shouldFail: true,
2421 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002422 },
David Benjaminabe94e32016-09-04 14:18:58 -04002423 {
David Benjaminbbba9392017-04-06 12:54:12 -04002424 // Test that KeyUpdates are acknowledged properly.
2425 name: "KeyUpdate-RequestACK",
2426 config: Config{
2427 MaxVersion: VersionTLS13,
2428 Bugs: ProtocolBugs{
2429 RejectUnsolicitedKeyUpdate: true,
2430 },
2431 },
2432 // Test the shim receiving many KeyUpdates in a row.
2433 sendKeyUpdates: 5,
2434 messageCount: 5,
2435 keyUpdateRequest: keyUpdateRequested,
2436 },
2437 {
2438 // Test that KeyUpdates are acknowledged properly if the
2439 // peer's KeyUpdate is discovered while a write is
2440 // pending.
2441 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2442 config: Config{
2443 MaxVersion: VersionTLS13,
2444 Bugs: ProtocolBugs{
2445 RejectUnsolicitedKeyUpdate: true,
2446 },
2447 },
2448 // Test the shim receiving many KeyUpdates in a row.
2449 sendKeyUpdates: 5,
2450 messageCount: 5,
2451 keyUpdateRequest: keyUpdateRequested,
2452 readWithUnfinishedWrite: true,
2453 flags: []string{"-async"},
2454 },
2455 {
David Benjaminabe94e32016-09-04 14:18:58 -04002456 name: "SendSNIWarningAlert",
2457 config: Config{
2458 MaxVersion: VersionTLS12,
2459 Bugs: ProtocolBugs{
2460 SendSNIWarningAlert: true,
2461 },
2462 },
2463 },
David Benjaminc241d792016-09-09 10:34:20 -04002464 {
2465 testType: serverTest,
2466 name: "ExtraCompressionMethods-TLS12",
2467 config: Config{
2468 MaxVersion: VersionTLS12,
2469 Bugs: ProtocolBugs{
2470 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2471 },
2472 },
2473 },
2474 {
2475 testType: serverTest,
2476 name: "ExtraCompressionMethods-TLS13",
2477 config: Config{
2478 MaxVersion: VersionTLS13,
2479 Bugs: ProtocolBugs{
2480 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2481 },
2482 },
2483 shouldFail: true,
2484 expectedError: ":INVALID_COMPRESSION_LIST:",
2485 expectedLocalError: "remote error: illegal parameter",
2486 },
2487 {
2488 testType: serverTest,
2489 name: "NoNullCompression-TLS12",
2490 config: Config{
2491 MaxVersion: VersionTLS12,
2492 Bugs: ProtocolBugs{
2493 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2494 },
2495 },
2496 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002497 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002498 expectedLocalError: "remote error: illegal parameter",
2499 },
2500 {
2501 testType: serverTest,
2502 name: "NoNullCompression-TLS13",
2503 config: Config{
2504 MaxVersion: VersionTLS13,
2505 Bugs: ProtocolBugs{
2506 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2507 },
2508 },
2509 shouldFail: true,
2510 expectedError: ":INVALID_COMPRESSION_LIST:",
2511 expectedLocalError: "remote error: illegal parameter",
2512 },
David Benjamin413e79e2017-07-01 10:11:53 -04002513 // Test that the client rejects invalid compression methods
2514 // from the server.
2515 {
2516 testType: clientTest,
2517 name: "InvalidCompressionMethod",
2518 config: Config{
2519 MaxVersion: VersionTLS12,
2520 Bugs: ProtocolBugs{
2521 SendCompressionMethod: 1,
2522 },
2523 },
2524 shouldFail: true,
2525 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2526 expectedLocalError: "remote error: illegal parameter",
2527 },
David Benjamin65ac9972016-09-02 21:35:25 -04002528 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002529 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002530 config: Config{
2531 MaxVersion: VersionTLS12,
2532 Bugs: ProtocolBugs{
2533 ExpectGREASE: true,
2534 },
2535 },
2536 flags: []string{"-enable-grease"},
2537 },
2538 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002539 name: "GREASE-Client-TLS13",
2540 config: Config{
2541 MaxVersion: VersionTLS13,
2542 Bugs: ProtocolBugs{
2543 ExpectGREASE: true,
2544 },
2545 },
2546 flags: []string{"-enable-grease"},
2547 },
2548 {
2549 testType: serverTest,
2550 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002551 config: Config{
2552 MaxVersion: VersionTLS13,
2553 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002554 // TLS 1.3 servers are expected to
2555 // always enable GREASE. TLS 1.3 is new,
2556 // so there is no existing ecosystem to
2557 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002558 ExpectGREASE: true,
2559 },
2560 },
David Benjamin65ac9972016-09-02 21:35:25 -04002561 },
David Benjamine3fbb362017-01-06 16:19:28 -05002562 {
2563 // Test the server so there is a large certificate as
2564 // well as application data.
2565 testType: serverTest,
2566 name: "MaxSendFragment",
2567 config: Config{
2568 Bugs: ProtocolBugs{
2569 MaxReceivePlaintext: 512,
2570 },
2571 },
2572 messageLen: 1024,
2573 flags: []string{
2574 "-max-send-fragment", "512",
2575 "-read-size", "1024",
2576 },
2577 },
2578 {
2579 // Test the server so there is a large certificate as
2580 // well as application data.
2581 testType: serverTest,
2582 name: "MaxSendFragment-TooLarge",
2583 config: Config{
2584 Bugs: ProtocolBugs{
2585 // Ensure that some of the records are
2586 // 512.
2587 MaxReceivePlaintext: 511,
2588 },
2589 },
2590 messageLen: 1024,
2591 flags: []string{
2592 "-max-send-fragment", "512",
2593 "-read-size", "1024",
2594 },
2595 shouldFail: true,
2596 expectedLocalError: "local error: record overflow",
2597 },
Adam Langley7c803a62015-06-15 15:35:05 -07002598 }
Adam Langley7c803a62015-06-15 15:35:05 -07002599 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002600
2601 // Test that very large messages can be received.
2602 cert := rsaCertificate
2603 for i := 0; i < 50; i++ {
2604 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2605 }
2606 testCases = append(testCases, testCase{
2607 name: "LargeMessage",
2608 config: Config{
2609 Certificates: []Certificate{cert},
2610 },
2611 })
2612 testCases = append(testCases, testCase{
2613 protocol: dtls,
2614 name: "LargeMessage-DTLS",
2615 config: Config{
2616 Certificates: []Certificate{cert},
2617 },
2618 })
2619
2620 // They are rejected if the maximum certificate chain length is capped.
2621 testCases = append(testCases, testCase{
2622 name: "LargeMessage-Reject",
2623 config: Config{
2624 Certificates: []Certificate{cert},
2625 },
2626 flags: []string{"-max-cert-list", "16384"},
2627 shouldFail: true,
2628 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2629 })
2630 testCases = append(testCases, testCase{
2631 protocol: dtls,
2632 name: "LargeMessage-Reject-DTLS",
2633 config: Config{
2634 Certificates: []Certificate{cert},
2635 },
2636 flags: []string{"-max-cert-list", "16384"},
2637 shouldFail: true,
2638 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2639 })
Adam Langley7c803a62015-06-15 15:35:05 -07002640}
2641
David Benjaminaa012042016-12-10 13:33:05 -05002642func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2643 const psk = "12345"
2644 const pskIdentity = "luggage combo"
2645
2646 var prefix string
2647 if protocol == dtls {
2648 if !ver.hasDTLS {
2649 return
2650 }
2651 prefix = "D"
2652 }
2653
2654 var cert Certificate
2655 var certFile string
2656 var keyFile string
2657 if hasComponent(suite.name, "ECDSA") {
2658 cert = ecdsaP256Certificate
2659 certFile = ecdsaP256CertificateFile
2660 keyFile = ecdsaP256KeyFile
2661 } else {
2662 cert = rsaCertificate
2663 certFile = rsaCertificateFile
2664 keyFile = rsaKeyFile
2665 }
2666
2667 var flags []string
2668 if hasComponent(suite.name, "PSK") {
2669 flags = append(flags,
2670 "-psk", psk,
2671 "-psk-identity", pskIdentity)
2672 }
2673 if hasComponent(suite.name, "NULL") {
2674 // NULL ciphers must be explicitly enabled.
2675 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2676 }
David Benjaminaa012042016-12-10 13:33:05 -05002677
2678 var shouldServerFail, shouldClientFail bool
2679 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2680 // BoringSSL clients accept ECDHE on SSLv3, but
2681 // a BoringSSL server will never select it
2682 // because the extension is missing.
2683 shouldServerFail = true
2684 }
2685 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2686 shouldClientFail = true
2687 shouldServerFail = true
2688 }
2689 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2690 shouldClientFail = true
2691 shouldServerFail = true
2692 }
2693 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2694 shouldClientFail = true
2695 shouldServerFail = true
2696 }
2697 if !isDTLSCipher(suite.name) && protocol == dtls {
2698 shouldClientFail = true
2699 shouldServerFail = true
2700 }
2701
2702 var sendCipherSuite uint16
2703 var expectedServerError, expectedClientError string
2704 serverCipherSuites := []uint16{suite.id}
2705 if shouldServerFail {
2706 expectedServerError = ":NO_SHARED_CIPHER:"
2707 }
2708 if shouldClientFail {
2709 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2710 // Configure the server to select ciphers as normal but
2711 // select an incompatible cipher in ServerHello.
2712 serverCipherSuites = nil
2713 sendCipherSuite = suite.id
2714 }
2715
David Benjamincdb6fe92017-02-07 16:06:48 -05002716 // For cipher suites and versions where exporters are defined, verify
2717 // that they interoperate.
2718 var exportKeyingMaterial int
2719 if ver.version > VersionSSL30 {
2720 exportKeyingMaterial = 1024
2721 }
2722
David Benjaminaa012042016-12-10 13:33:05 -05002723 testCases = append(testCases, testCase{
2724 testType: serverTest,
2725 protocol: protocol,
2726 name: prefix + ver.name + "-" + suite.name + "-server",
2727 config: Config{
2728 MinVersion: ver.version,
2729 MaxVersion: ver.version,
2730 CipherSuites: []uint16{suite.id},
2731 Certificates: []Certificate{cert},
2732 PreSharedKey: []byte(psk),
2733 PreSharedKeyIdentity: pskIdentity,
2734 Bugs: ProtocolBugs{
2735 AdvertiseAllConfiguredCiphers: true,
2736 },
2737 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002738 certFile: certFile,
2739 keyFile: keyFile,
2740 flags: flags,
2741 resumeSession: true,
2742 shouldFail: shouldServerFail,
2743 expectedError: expectedServerError,
2744 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002745 })
2746
2747 testCases = append(testCases, testCase{
2748 testType: clientTest,
2749 protocol: protocol,
2750 name: prefix + ver.name + "-" + suite.name + "-client",
2751 config: Config{
2752 MinVersion: ver.version,
2753 MaxVersion: ver.version,
2754 CipherSuites: serverCipherSuites,
2755 Certificates: []Certificate{cert},
2756 PreSharedKey: []byte(psk),
2757 PreSharedKeyIdentity: pskIdentity,
2758 Bugs: ProtocolBugs{
2759 IgnorePeerCipherPreferences: shouldClientFail,
2760 SendCipherSuite: sendCipherSuite,
2761 },
2762 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002763 flags: flags,
2764 resumeSession: true,
2765 shouldFail: shouldClientFail,
2766 expectedError: expectedClientError,
2767 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002768 })
2769
David Benjamin6f600d62016-12-21 16:06:54 -05002770 if shouldClientFail {
2771 return
2772 }
2773
2774 // Ensure the maximum record size is accepted.
2775 testCases = append(testCases, testCase{
2776 protocol: protocol,
2777 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2778 config: Config{
2779 MinVersion: ver.version,
2780 MaxVersion: ver.version,
2781 CipherSuites: []uint16{suite.id},
2782 Certificates: []Certificate{cert},
2783 PreSharedKey: []byte(psk),
2784 PreSharedKeyIdentity: pskIdentity,
2785 },
2786 flags: flags,
2787 messageLen: maxPlaintext,
2788 })
2789
2790 // Test bad records for all ciphers. Bad records are fatal in TLS
2791 // and ignored in DTLS.
2792 var shouldFail bool
2793 var expectedError string
2794 if protocol == tls {
2795 shouldFail = true
2796 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2797 }
2798
2799 testCases = append(testCases, testCase{
2800 protocol: protocol,
2801 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2802 config: Config{
2803 MinVersion: ver.version,
2804 MaxVersion: ver.version,
2805 CipherSuites: []uint16{suite.id},
2806 Certificates: []Certificate{cert},
2807 PreSharedKey: []byte(psk),
2808 PreSharedKeyIdentity: pskIdentity,
2809 },
2810 flags: flags,
2811 damageFirstWrite: true,
2812 messageLen: maxPlaintext,
2813 shouldFail: shouldFail,
2814 expectedError: expectedError,
2815 })
David Benjaminaa012042016-12-10 13:33:05 -05002816}
2817
Adam Langley95c29f32014-06-20 12:00:00 -07002818func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002819 const bogusCipher = 0xfe00
2820
Adam Langley95c29f32014-06-20 12:00:00 -07002821 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002822 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002823 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002824 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002825 }
David Benjamin2c99d282015-09-01 10:23:00 -04002826 }
Adam Langley95c29f32014-06-20 12:00:00 -07002827 }
Adam Langleya7997f12015-05-14 17:38:50 -07002828
2829 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002830 name: "NoSharedCipher",
2831 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002832 MaxVersion: VersionTLS12,
2833 CipherSuites: []uint16{},
2834 },
2835 shouldFail: true,
2836 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2837 })
2838
2839 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002840 name: "NoSharedCipher-TLS13",
2841 config: Config{
2842 MaxVersion: VersionTLS13,
2843 CipherSuites: []uint16{},
2844 },
2845 shouldFail: true,
2846 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2847 })
2848
2849 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002850 name: "UnsupportedCipherSuite",
2851 config: Config{
2852 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002853 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002854 Bugs: ProtocolBugs{
2855 IgnorePeerCipherPreferences: true,
2856 },
2857 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002858 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002859 shouldFail: true,
2860 expectedError: ":WRONG_CIPHER_RETURNED:",
2861 })
2862
2863 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002864 name: "ServerHelloBogusCipher",
2865 config: Config{
2866 MaxVersion: VersionTLS12,
2867 Bugs: ProtocolBugs{
2868 SendCipherSuite: bogusCipher,
2869 },
2870 },
2871 shouldFail: true,
2872 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2873 })
2874 testCases = append(testCases, testCase{
2875 name: "ServerHelloBogusCipher-TLS13",
2876 config: Config{
2877 MaxVersion: VersionTLS13,
2878 Bugs: ProtocolBugs{
2879 SendCipherSuite: bogusCipher,
2880 },
2881 },
2882 shouldFail: true,
2883 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2884 })
2885
David Benjamin241ae832016-01-15 03:04:54 -05002886 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002887 testCases = append(testCases, testCase{
2888 testType: serverTest,
2889 name: "UnknownCipher",
2890 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002891 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002892 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002893 Bugs: ProtocolBugs{
2894 AdvertiseAllConfiguredCiphers: true,
2895 },
2896 },
2897 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002898
2899 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002900 testCases = append(testCases, testCase{
2901 testType: serverTest,
2902 name: "UnknownCipher-TLS13",
2903 config: Config{
2904 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002905 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002906 Bugs: ProtocolBugs{
2907 AdvertiseAllConfiguredCiphers: true,
2908 },
David Benjamin241ae832016-01-15 03:04:54 -05002909 },
2910 })
2911
David Benjamin78679342016-09-16 19:42:05 -04002912 // Test empty ECDHE_PSK identity hints work as expected.
2913 testCases = append(testCases, testCase{
2914 name: "EmptyECDHEPSKHint",
2915 config: Config{
2916 MaxVersion: VersionTLS12,
2917 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2918 PreSharedKey: []byte("secret"),
2919 },
2920 flags: []string{"-psk", "secret"},
2921 })
2922
2923 // Test empty PSK identity hints work as expected, even if an explicit
2924 // ServerKeyExchange is sent.
2925 testCases = append(testCases, testCase{
2926 name: "ExplicitEmptyPSKHint",
2927 config: Config{
2928 MaxVersion: VersionTLS12,
2929 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2930 PreSharedKey: []byte("secret"),
2931 Bugs: ProtocolBugs{
2932 AlwaysSendPreSharedKeyIdentityHint: true,
2933 },
2934 },
2935 flags: []string{"-psk", "secret"},
2936 })
David Benjamin69522112017-03-28 15:38:29 -05002937
2938 // Test that clients enforce that the server-sent certificate and cipher
2939 // suite match in TLS 1.2.
2940 testCases = append(testCases, testCase{
2941 name: "CertificateCipherMismatch-RSA",
2942 config: Config{
2943 MaxVersion: VersionTLS12,
2944 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2945 Certificates: []Certificate{rsaCertificate},
2946 Bugs: ProtocolBugs{
2947 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2948 },
2949 },
2950 shouldFail: true,
2951 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2952 })
2953 testCases = append(testCases, testCase{
2954 name: "CertificateCipherMismatch-ECDSA",
2955 config: Config{
2956 MaxVersion: VersionTLS12,
2957 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2958 Certificates: []Certificate{ecdsaP256Certificate},
2959 Bugs: ProtocolBugs{
2960 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2961 },
2962 },
2963 shouldFail: true,
2964 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2965 })
2966 testCases = append(testCases, testCase{
2967 name: "CertificateCipherMismatch-Ed25519",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2971 Certificates: []Certificate{ed25519Certificate},
2972 Bugs: ProtocolBugs{
2973 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2974 },
2975 },
2976 shouldFail: true,
2977 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2978 })
2979
2980 // Test that servers decline to select a cipher suite which is
2981 // inconsistent with their configured certificate.
2982 testCases = append(testCases, testCase{
2983 testType: serverTest,
2984 name: "ServerCipherFilter-RSA",
2985 config: Config{
2986 MaxVersion: VersionTLS12,
2987 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2988 },
2989 flags: []string{
2990 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2991 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2992 },
2993 shouldFail: true,
2994 expectedError: ":NO_SHARED_CIPHER:",
2995 })
2996 testCases = append(testCases, testCase{
2997 testType: serverTest,
2998 name: "ServerCipherFilter-ECDSA",
2999 config: Config{
3000 MaxVersion: VersionTLS12,
3001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3002 },
3003 flags: []string{
3004 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3005 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3006 },
3007 shouldFail: true,
3008 expectedError: ":NO_SHARED_CIPHER:",
3009 })
3010 testCases = append(testCases, testCase{
3011 testType: serverTest,
3012 name: "ServerCipherFilter-Ed25519",
3013 config: Config{
3014 MaxVersion: VersionTLS12,
3015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3016 },
3017 flags: []string{
3018 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3019 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3020 },
3021 shouldFail: true,
3022 expectedError: ":NO_SHARED_CIPHER:",
3023 })
David Benjamin364af782017-07-01 10:35:27 -04003024
3025 // Test cipher suite negotiation works as expected. Configure a
3026 // complicated cipher suite configuration.
3027 const negotiationTestCiphers = "" +
3028 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3029 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3030 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3031 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3032 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3033 negotiationTests := []struct {
3034 ciphers []uint16
3035 expected uint16
3036 }{
3037 // Server preferences are honored, including when
3038 // equipreference groups are involved.
3039 {
3040 []uint16{
3041 TLS_RSA_WITH_AES_256_GCM_SHA384,
3042 TLS_RSA_WITH_AES_128_CBC_SHA,
3043 TLS_RSA_WITH_AES_128_GCM_SHA256,
3044 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3045 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3046 },
3047 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3048 },
3049 {
3050 []uint16{
3051 TLS_RSA_WITH_AES_256_GCM_SHA384,
3052 TLS_RSA_WITH_AES_128_CBC_SHA,
3053 TLS_RSA_WITH_AES_128_GCM_SHA256,
3054 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3055 },
3056 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3057 },
3058 {
3059 []uint16{
3060 TLS_RSA_WITH_AES_256_GCM_SHA384,
3061 TLS_RSA_WITH_AES_128_CBC_SHA,
3062 TLS_RSA_WITH_AES_128_GCM_SHA256,
3063 },
3064 TLS_RSA_WITH_AES_128_GCM_SHA256,
3065 },
3066 {
3067 []uint16{
3068 TLS_RSA_WITH_AES_256_GCM_SHA384,
3069 TLS_RSA_WITH_AES_128_CBC_SHA,
3070 },
3071 TLS_RSA_WITH_AES_128_CBC_SHA,
3072 },
3073 // Equipreference groups use the client preference.
3074 {
3075 []uint16{
3076 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3077 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3078 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3079 },
3080 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3081 },
3082 {
3083 []uint16{
3084 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3085 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3086 },
3087 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3088 },
3089 {
3090 []uint16{
3091 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3092 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3093 },
3094 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3095 },
3096 {
3097 []uint16{
3098 TLS_RSA_WITH_AES_256_GCM_SHA384,
3099 TLS_RSA_WITH_AES_256_CBC_SHA,
3100 },
3101 TLS_RSA_WITH_AES_256_GCM_SHA384,
3102 },
3103 {
3104 []uint16{
3105 TLS_RSA_WITH_AES_256_CBC_SHA,
3106 TLS_RSA_WITH_AES_256_GCM_SHA384,
3107 },
3108 TLS_RSA_WITH_AES_256_CBC_SHA,
3109 },
3110 // If there are two equipreference groups, the preferred one
3111 // takes precedence.
3112 {
3113 []uint16{
3114 TLS_RSA_WITH_AES_256_GCM_SHA384,
3115 TLS_RSA_WITH_AES_256_CBC_SHA,
3116 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3117 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3118 },
3119 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3120 },
3121 }
3122 for i, t := range negotiationTests {
3123 testCases = append(testCases, testCase{
3124 testType: serverTest,
3125 name: "CipherNegotiation-" + strconv.Itoa(i),
3126 config: Config{
3127 MaxVersion: VersionTLS12,
3128 CipherSuites: t.ciphers,
3129 },
3130 flags: []string{"-cipher", negotiationTestCiphers},
3131 expectedCipher: t.expected,
3132 })
3133 }
Adam Langley95c29f32014-06-20 12:00:00 -07003134}
3135
3136func addBadECDSASignatureTests() {
3137 for badR := BadValue(1); badR < NumBadValues; badR++ {
3138 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003139 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003140 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3141 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003142 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003143 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003144 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003145 Bugs: ProtocolBugs{
3146 BadECDSAR: badR,
3147 BadECDSAS: badS,
3148 },
3149 },
3150 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003151 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003152 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003153 testCases = append(testCases, testCase{
3154 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3155 config: Config{
3156 MaxVersion: VersionTLS13,
3157 Certificates: []Certificate{ecdsaP256Certificate},
3158 Bugs: ProtocolBugs{
3159 BadECDSAR: badR,
3160 BadECDSAS: badS,
3161 },
3162 },
3163 shouldFail: true,
3164 expectedError: ":BAD_SIGNATURE:",
3165 })
Adam Langley95c29f32014-06-20 12:00:00 -07003166 }
3167 }
3168}
3169
Adam Langley80842bd2014-06-20 12:00:00 -07003170func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003171 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003172 name: "MaxCBCPadding",
3173 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003174 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3176 Bugs: ProtocolBugs{
3177 MaxPadding: true,
3178 },
3179 },
3180 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3181 })
David Benjamin025b3d32014-07-01 19:53:04 -04003182 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003183 name: "BadCBCPadding",
3184 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003185 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003186 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3187 Bugs: ProtocolBugs{
3188 PaddingFirstByteBad: true,
3189 },
3190 },
3191 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003192 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003193 })
3194 // OpenSSL previously had an issue where the first byte of padding in
3195 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003196 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003197 name: "BadCBCPadding255",
3198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003199 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3201 Bugs: ProtocolBugs{
3202 MaxPadding: true,
3203 PaddingFirstByteBadIf255: true,
3204 },
3205 },
3206 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3207 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003208 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003209 })
3210}
3211
Kenny Root7fdeaf12014-08-05 15:23:37 -07003212func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003213 var cbcCiphers = []struct {
3214 name string
3215 cipher uint16
3216 }{
3217 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3218 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3219 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3220 }
3221 for _, t := range cbcCiphers {
3222 testCases = append(testCases, testCase{
3223 name: "CBCRecordSplitting-" + t.name,
3224 config: Config{
3225 MaxVersion: VersionTLS10,
3226 MinVersion: VersionTLS10,
3227 CipherSuites: []uint16{t.cipher},
3228 },
3229 messageLen: -1, // read until EOF
3230 resumeSession: true,
3231 flags: []string{
3232 "-async",
3233 "-write-different-record-sizes",
3234 "-cbc-record-splitting",
3235 },
3236 })
3237 testCases = append(testCases, testCase{
3238 name: "CBCRecordSplittingPartialWrite-" + t.name,
3239 config: Config{
3240 MaxVersion: VersionTLS10,
3241 MinVersion: VersionTLS10,
3242 CipherSuites: []uint16{t.cipher},
3243 },
3244 messageLen: -1, // read until EOF
3245 flags: []string{
3246 "-async",
3247 "-write-different-record-sizes",
3248 "-cbc-record-splitting",
3249 "-partial-write",
3250 },
3251 })
3252 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003253}
3254
David Benjamin636293b2014-07-08 17:59:18 -04003255func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003256 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003257 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003258 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3259 cert, err := x509.ParseCertificate(cert.Certificate[0])
3260 if err != nil {
3261 panic(err)
3262 }
3263 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003264 }
Adam Langley2ff79332017-02-28 13:45:39 -08003265 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003266
David Benjamin636293b2014-07-08 17:59:18 -04003267 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003268 testCases = append(testCases, testCase{
3269 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003270 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003271 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003272 MinVersion: ver.version,
3273 MaxVersion: ver.version,
3274 ClientAuth: RequireAnyClientCert,
3275 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003276 },
3277 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003278 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3279 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003280 },
3281 })
3282 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003283 testType: serverTest,
3284 name: ver.name + "-Server-ClientAuth-RSA",
3285 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003286 MinVersion: ver.version,
3287 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003288 Certificates: []Certificate{rsaCertificate},
3289 },
3290 flags: []string{"-require-any-client-certificate"},
3291 })
David Benjamine098ec22014-08-27 23:13:20 -04003292 if ver.version != VersionSSL30 {
3293 testCases = append(testCases, testCase{
3294 testType: serverTest,
3295 name: ver.name + "-Server-ClientAuth-ECDSA",
3296 config: Config{
3297 MinVersion: ver.version,
3298 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003299 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003300 },
3301 flags: []string{"-require-any-client-certificate"},
3302 })
3303 testCases = append(testCases, testCase{
3304 testType: clientTest,
3305 name: ver.name + "-Client-ClientAuth-ECDSA",
3306 config: Config{
3307 MinVersion: ver.version,
3308 MaxVersion: ver.version,
3309 ClientAuth: RequireAnyClientCert,
3310 ClientCAs: certPool,
3311 },
3312 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003313 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3314 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003315 },
3316 })
3317 }
Adam Langley37646832016-08-01 16:16:46 -07003318
3319 testCases = append(testCases, testCase{
3320 name: "NoClientCertificate-" + ver.name,
3321 config: Config{
3322 MinVersion: ver.version,
3323 MaxVersion: ver.version,
3324 ClientAuth: RequireAnyClientCert,
3325 },
3326 shouldFail: true,
3327 expectedLocalError: "client didn't provide a certificate",
3328 })
3329
3330 testCases = append(testCases, testCase{
3331 // Even if not configured to expect a certificate, OpenSSL will
3332 // return X509_V_OK as the verify_result.
3333 testType: serverTest,
3334 name: "NoClientCertificateRequested-Server-" + ver.name,
3335 config: Config{
3336 MinVersion: ver.version,
3337 MaxVersion: ver.version,
3338 },
3339 flags: []string{
3340 "-expect-verify-result",
3341 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003342 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003343 })
3344
3345 testCases = append(testCases, testCase{
3346 // If a client certificate is not provided, OpenSSL will still
3347 // return X509_V_OK as the verify_result.
3348 testType: serverTest,
3349 name: "NoClientCertificate-Server-" + ver.name,
3350 config: Config{
3351 MinVersion: ver.version,
3352 MaxVersion: ver.version,
3353 },
3354 flags: []string{
3355 "-expect-verify-result",
3356 "-verify-peer",
3357 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003358 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003359 })
3360
David Benjamin1db9e1b2016-10-07 20:51:43 -04003361 certificateRequired := "remote error: certificate required"
3362 if ver.version < VersionTLS13 {
3363 // Prior to TLS 1.3, the generic handshake_failure alert
3364 // was used.
3365 certificateRequired = "remote error: handshake failure"
3366 }
Adam Langley37646832016-08-01 16:16:46 -07003367 testCases = append(testCases, testCase{
3368 testType: serverTest,
3369 name: "RequireAnyClientCertificate-" + ver.name,
3370 config: Config{
3371 MinVersion: ver.version,
3372 MaxVersion: ver.version,
3373 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003374 flags: []string{"-require-any-client-certificate"},
3375 shouldFail: true,
3376 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3377 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003378 })
3379
3380 if ver.version != VersionSSL30 {
3381 testCases = append(testCases, testCase{
3382 testType: serverTest,
3383 name: "SkipClientCertificate-" + ver.name,
3384 config: Config{
3385 MinVersion: ver.version,
3386 MaxVersion: ver.version,
3387 Bugs: ProtocolBugs{
3388 SkipClientCertificate: true,
3389 },
3390 },
3391 // Setting SSL_VERIFY_PEER allows anonymous clients.
3392 flags: []string{"-verify-peer"},
3393 shouldFail: true,
3394 expectedError: ":UNEXPECTED_MESSAGE:",
3395 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003396
3397 testCases = append(testCases, testCase{
3398 testType: serverTest,
3399 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3400 config: Config{
3401 MinVersion: ver.version,
3402 MaxVersion: ver.version,
3403 },
3404 flags: []string{
3405 "-enable-channel-id",
3406 "-verify-peer-if-no-obc",
3407 },
3408 shouldFail: true,
3409 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3410 expectedLocalError: certificateRequired,
3411 })
3412
3413 testCases = append(testCases, testCase{
3414 testType: serverTest,
3415 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3416 config: Config{
3417 MinVersion: ver.version,
3418 MaxVersion: ver.version,
3419 ChannelID: channelIDKey,
3420 },
3421 expectChannelID: true,
3422 flags: []string{
3423 "-enable-channel-id",
3424 "-verify-peer-if-no-obc",
3425 },
3426 })
Adam Langley37646832016-08-01 16:16:46 -07003427 }
Adam Langley2ff79332017-02-28 13:45:39 -08003428
3429 testCases = append(testCases, testCase{
3430 testType: serverTest,
3431 name: ver.name + "-Server-CertReq-CA-List",
3432 config: Config{
3433 MinVersion: ver.version,
3434 MaxVersion: ver.version,
3435 Certificates: []Certificate{rsaCertificate},
3436 Bugs: ProtocolBugs{
3437 ExpectCertificateReqNames: caNames,
3438 },
3439 },
3440 flags: []string{
3441 "-require-any-client-certificate",
3442 "-use-client-ca-list", encodeDERValues(caNames),
3443 },
3444 })
3445
3446 testCases = append(testCases, testCase{
3447 testType: clientTest,
3448 name: ver.name + "-Client-CertReq-CA-List",
3449 config: Config{
3450 MinVersion: ver.version,
3451 MaxVersion: ver.version,
3452 Certificates: []Certificate{rsaCertificate},
3453 ClientAuth: RequireAnyClientCert,
3454 ClientCAs: certPool,
3455 },
3456 flags: []string{
3457 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3458 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3459 "-expect-client-ca-list", encodeDERValues(caNames),
3460 },
3461 })
David Benjamin636293b2014-07-08 17:59:18 -04003462 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003463
David Benjaminc032dfa2016-05-12 14:54:57 -04003464 // Client auth is only legal in certificate-based ciphers.
3465 testCases = append(testCases, testCase{
3466 testType: clientTest,
3467 name: "ClientAuth-PSK",
3468 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003469 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003470 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3471 PreSharedKey: []byte("secret"),
3472 ClientAuth: RequireAnyClientCert,
3473 },
3474 flags: []string{
3475 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3476 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3477 "-psk", "secret",
3478 },
3479 shouldFail: true,
3480 expectedError: ":UNEXPECTED_MESSAGE:",
3481 })
3482 testCases = append(testCases, testCase{
3483 testType: clientTest,
3484 name: "ClientAuth-ECDHE_PSK",
3485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003486 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003487 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3488 PreSharedKey: []byte("secret"),
3489 ClientAuth: RequireAnyClientCert,
3490 },
3491 flags: []string{
3492 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3493 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3494 "-psk", "secret",
3495 },
3496 shouldFail: true,
3497 expectedError: ":UNEXPECTED_MESSAGE:",
3498 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003499
3500 // Regression test for a bug where the client CA list, if explicitly
3501 // set to NULL, was mis-encoded.
3502 testCases = append(testCases, testCase{
3503 testType: serverTest,
3504 name: "Null-Client-CA-List",
3505 config: Config{
3506 MaxVersion: VersionTLS12,
3507 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003508 Bugs: ProtocolBugs{
3509 ExpectCertificateReqNames: [][]byte{},
3510 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003511 },
3512 flags: []string{
3513 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003514 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003515 },
3516 })
David Benjamin636293b2014-07-08 17:59:18 -04003517}
3518
Adam Langley75712922014-10-10 16:23:43 -07003519func addExtendedMasterSecretTests() {
3520 const expectEMSFlag = "-expect-extended-master-secret"
3521
3522 for _, with := range []bool{false, true} {
3523 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003524 if with {
3525 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003526 }
3527
3528 for _, isClient := range []bool{false, true} {
3529 suffix := "-Server"
3530 testType := serverTest
3531 if isClient {
3532 suffix = "-Client"
3533 testType = clientTest
3534 }
3535
3536 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003537 // In TLS 1.3, the extension is irrelevant and
3538 // always reports as enabled.
3539 var flags []string
3540 if with || ver.version >= VersionTLS13 {
3541 flags = []string{expectEMSFlag}
3542 }
3543
Adam Langley75712922014-10-10 16:23:43 -07003544 test := testCase{
3545 testType: testType,
3546 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3547 config: Config{
3548 MinVersion: ver.version,
3549 MaxVersion: ver.version,
3550 Bugs: ProtocolBugs{
3551 NoExtendedMasterSecret: !with,
3552 RequireExtendedMasterSecret: with,
3553 },
3554 },
David Benjamin48cae082014-10-27 01:06:24 -04003555 flags: flags,
3556 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003557 }
3558 if test.shouldFail {
3559 test.expectedLocalError = "extended master secret required but not supported by peer"
3560 }
3561 testCases = append(testCases, test)
3562 }
3563 }
3564 }
3565
Adam Langleyba5934b2015-06-02 10:50:35 -07003566 for _, isClient := range []bool{false, true} {
3567 for _, supportedInFirstConnection := range []bool{false, true} {
3568 for _, supportedInResumeConnection := range []bool{false, true} {
3569 boolToWord := func(b bool) string {
3570 if b {
3571 return "Yes"
3572 }
3573 return "No"
3574 }
3575 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3576 if isClient {
3577 suffix += "Client"
3578 } else {
3579 suffix += "Server"
3580 }
3581
3582 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003583 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003584 Bugs: ProtocolBugs{
3585 RequireExtendedMasterSecret: true,
3586 },
3587 }
3588
3589 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003590 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003591 Bugs: ProtocolBugs{
3592 NoExtendedMasterSecret: true,
3593 },
3594 }
3595
3596 test := testCase{
3597 name: "ExtendedMasterSecret-" + suffix,
3598 resumeSession: true,
3599 }
3600
3601 if !isClient {
3602 test.testType = serverTest
3603 }
3604
3605 if supportedInFirstConnection {
3606 test.config = supportedConfig
3607 } else {
3608 test.config = noSupportConfig
3609 }
3610
3611 if supportedInResumeConnection {
3612 test.resumeConfig = &supportedConfig
3613 } else {
3614 test.resumeConfig = &noSupportConfig
3615 }
3616
3617 switch suffix {
3618 case "YesToYes-Client", "YesToYes-Server":
3619 // When a session is resumed, it should
3620 // still be aware that its master
3621 // secret was generated via EMS and
3622 // thus it's safe to use tls-unique.
3623 test.flags = []string{expectEMSFlag}
3624 case "NoToYes-Server":
3625 // If an original connection did not
3626 // contain EMS, but a resumption
3627 // handshake does, then a server should
3628 // not resume the session.
3629 test.expectResumeRejected = true
3630 case "YesToNo-Server":
3631 // Resuming an EMS session without the
3632 // EMS extension should cause the
3633 // server to abort the connection.
3634 test.shouldFail = true
3635 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3636 case "NoToYes-Client":
3637 // A client should abort a connection
3638 // where the server resumed a non-EMS
3639 // session but echoed the EMS
3640 // extension.
3641 test.shouldFail = true
3642 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3643 case "YesToNo-Client":
3644 // A client should abort a connection
3645 // where the server didn't echo EMS
3646 // when the session used it.
3647 test.shouldFail = true
3648 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3649 }
3650
3651 testCases = append(testCases, test)
3652 }
3653 }
3654 }
David Benjamin163c9562016-08-29 23:14:17 -04003655
3656 // Switching EMS on renegotiation is forbidden.
3657 testCases = append(testCases, testCase{
3658 name: "ExtendedMasterSecret-Renego-NoEMS",
3659 config: Config{
3660 MaxVersion: VersionTLS12,
3661 Bugs: ProtocolBugs{
3662 NoExtendedMasterSecret: true,
3663 NoExtendedMasterSecretOnRenegotiation: true,
3664 },
3665 },
3666 renegotiate: 1,
3667 flags: []string{
3668 "-renegotiate-freely",
3669 "-expect-total-renegotiations", "1",
3670 },
3671 })
3672
3673 testCases = append(testCases, testCase{
3674 name: "ExtendedMasterSecret-Renego-Upgrade",
3675 config: Config{
3676 MaxVersion: VersionTLS12,
3677 Bugs: ProtocolBugs{
3678 NoExtendedMasterSecret: true,
3679 },
3680 },
3681 renegotiate: 1,
3682 flags: []string{
3683 "-renegotiate-freely",
3684 "-expect-total-renegotiations", "1",
3685 },
3686 shouldFail: true,
3687 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3688 })
3689
3690 testCases = append(testCases, testCase{
3691 name: "ExtendedMasterSecret-Renego-Downgrade",
3692 config: Config{
3693 MaxVersion: VersionTLS12,
3694 Bugs: ProtocolBugs{
3695 NoExtendedMasterSecretOnRenegotiation: true,
3696 },
3697 },
3698 renegotiate: 1,
3699 flags: []string{
3700 "-renegotiate-freely",
3701 "-expect-total-renegotiations", "1",
3702 },
3703 shouldFail: true,
3704 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3705 })
Adam Langley75712922014-10-10 16:23:43 -07003706}
3707
David Benjamin582ba042016-07-07 12:33:25 -07003708type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003709 protocol protocol
3710 async bool
3711 splitHandshake bool
3712 packHandshakeFlight bool
3713 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003714}
3715
David Benjamin43ec06f2014-08-05 02:28:57 -04003716// Adds tests that try to cover the range of the handshake state machine, under
3717// various conditions. Some of these are redundant with other tests, but they
3718// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003719func addAllStateMachineCoverageTests() {
3720 for _, async := range []bool{false, true} {
3721 for _, protocol := range []protocol{tls, dtls} {
3722 addStateMachineCoverageTests(stateMachineTestConfig{
3723 protocol: protocol,
3724 async: async,
3725 })
3726 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003727 protocol: protocol,
3728 async: async,
3729 implicitHandshake: true,
3730 })
3731 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003732 protocol: protocol,
3733 async: async,
3734 splitHandshake: true,
3735 })
3736 if protocol == tls {
3737 addStateMachineCoverageTests(stateMachineTestConfig{
3738 protocol: protocol,
3739 async: async,
3740 packHandshakeFlight: true,
3741 })
3742 }
3743 }
3744 }
3745}
3746
3747func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003748 var tests []testCase
3749
3750 // Basic handshake, with resumption. Client and server,
3751 // session ID and session ticket.
3752 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 name: "Basic-Client",
3754 config: Config{
3755 MaxVersion: VersionTLS12,
3756 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003757 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003758 // Ensure session tickets are used, not session IDs.
3759 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003760 })
3761 tests = append(tests, testCase{
3762 name: "Basic-Client-RenewTicket",
3763 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003764 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003765 Bugs: ProtocolBugs{
3766 RenewTicketOnResume: true,
3767 },
3768 },
David Benjamin46662482016-08-17 00:51:00 -04003769 flags: []string{"-expect-ticket-renewal"},
3770 resumeSession: true,
3771 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003772 })
3773 tests = append(tests, testCase{
3774 name: "Basic-Client-NoTicket",
3775 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003776 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003777 SessionTicketsDisabled: true,
3778 },
3779 resumeSession: true,
3780 })
3781 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003782 testType: serverTest,
3783 name: "Basic-Server",
3784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003785 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003786 Bugs: ProtocolBugs{
3787 RequireSessionTickets: true,
3788 },
3789 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003790 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003791 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003792 })
3793 tests = append(tests, testCase{
3794 testType: serverTest,
3795 name: "Basic-Server-NoTickets",
3796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003797 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003798 SessionTicketsDisabled: true,
3799 },
3800 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003801 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003802 })
3803 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003804 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003805 name: "Basic-Server-EarlyCallback",
3806 config: Config{
3807 MaxVersion: VersionTLS12,
3808 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003809 flags: []string{"-use-early-callback"},
3810 resumeSession: true,
3811 })
3812
Steven Valdez143e8b32016-07-11 13:19:03 -04003813 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003814 if config.protocol == tls {
3815 tests = append(tests, testCase{
3816 name: "TLS13-1RTT-Client",
3817 config: Config{
3818 MaxVersion: VersionTLS13,
3819 MinVersion: VersionTLS13,
3820 },
David Benjamin46662482016-08-17 00:51:00 -04003821 resumeSession: true,
3822 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003823 })
3824
3825 tests = append(tests, testCase{
3826 testType: serverTest,
3827 name: "TLS13-1RTT-Server",
3828 config: Config{
3829 MaxVersion: VersionTLS13,
3830 MinVersion: VersionTLS13,
3831 },
David Benjamin46662482016-08-17 00:51:00 -04003832 resumeSession: true,
3833 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003834 // TLS 1.3 uses tickets, so the session should not be
3835 // cached statefully.
3836 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003837 })
3838
3839 tests = append(tests, testCase{
3840 name: "TLS13-HelloRetryRequest-Client",
3841 config: Config{
3842 MaxVersion: VersionTLS13,
3843 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003844 // P-384 requires a HelloRetryRequest against BoringSSL's default
3845 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003846 CurvePreferences: []CurveID{CurveP384},
3847 Bugs: ProtocolBugs{
3848 ExpectMissingKeyShare: true,
3849 },
3850 },
3851 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3852 resumeSession: true,
3853 })
3854
3855 tests = append(tests, testCase{
3856 testType: serverTest,
3857 name: "TLS13-HelloRetryRequest-Server",
3858 config: Config{
3859 MaxVersion: VersionTLS13,
3860 MinVersion: VersionTLS13,
3861 // Require a HelloRetryRequest for every curve.
3862 DefaultCurves: []CurveID{},
3863 },
3864 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3865 resumeSession: true,
3866 })
Steven Valdez2d850622017-01-11 11:34:52 -05003867
Steven Valdez2d850622017-01-11 11:34:52 -05003868 tests = append(tests, testCase{
3869 testType: clientTest,
3870 name: "TLS13-EarlyData-Client",
3871 config: Config{
3872 MaxVersion: VersionTLS13,
3873 MinVersion: VersionTLS13,
3874 MaxEarlyDataSize: 16384,
3875 },
Steven Valdeze831a812017-03-09 14:56:07 -05003876 resumeConfig: &Config{
3877 MaxVersion: VersionTLS13,
3878 MinVersion: VersionTLS13,
3879 MaxEarlyDataSize: 16384,
3880 Bugs: ProtocolBugs{
3881 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3882 },
3883 },
Steven Valdez2d850622017-01-11 11:34:52 -05003884 resumeSession: true,
3885 flags: []string{
3886 "-enable-early-data",
3887 "-expect-early-data-info",
3888 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003889 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003890 },
3891 })
3892
3893 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003894 testType: clientTest,
3895 name: "TLS13-EarlyData-TooMuchData-Client",
3896 config: Config{
3897 MaxVersion: VersionTLS13,
3898 MinVersion: VersionTLS13,
3899 MaxEarlyDataSize: 2,
3900 },
3901 resumeConfig: &Config{
3902 MaxVersion: VersionTLS13,
3903 MinVersion: VersionTLS13,
3904 MaxEarlyDataSize: 2,
3905 Bugs: ProtocolBugs{
3906 ExpectEarlyData: [][]byte{{'h', 'e'}},
3907 },
3908 },
3909 resumeShimPrefix: "llo",
3910 resumeSession: true,
3911 flags: []string{
3912 "-enable-early-data",
3913 "-expect-early-data-info",
3914 "-expect-accept-early-data",
3915 "-on-resume-shim-writes-first",
3916 },
3917 })
3918
3919 // Unfinished writes can only be tested when operations are async. EarlyData
3920 // can't be tested as part of an ImplicitHandshake in this case since
3921 // otherwise the early data will be sent as normal data.
3922 if config.async && !config.implicitHandshake {
3923 tests = append(tests, testCase{
3924 testType: clientTest,
3925 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3926 config: Config{
3927 MaxVersion: VersionTLS13,
3928 MinVersion: VersionTLS13,
3929 MaxEarlyDataSize: 16384,
3930 },
3931 resumeConfig: &Config{
3932 MaxVersion: VersionTLS13,
3933 MinVersion: VersionTLS13,
3934 MaxEarlyDataSize: 16384,
3935 Bugs: ProtocolBugs{
3936 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3937 },
3938 },
3939 resumeSession: true,
3940 flags: []string{
3941 "-enable-early-data",
3942 "-expect-early-data-info",
3943 "-expect-accept-early-data",
3944 "-on-resume-read-with-unfinished-write",
3945 "-on-resume-shim-writes-first",
3946 },
3947 })
3948
3949 // Rejected unfinished writes are discarded (from the
3950 // perspective of the calling application) on 0-RTT
3951 // reject.
3952 tests = append(tests, testCase{
3953 testType: clientTest,
3954 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3955 config: Config{
3956 MaxVersion: VersionTLS13,
3957 MinVersion: VersionTLS13,
3958 MaxEarlyDataSize: 16384,
3959 },
3960 resumeConfig: &Config{
3961 MaxVersion: VersionTLS13,
3962 MinVersion: VersionTLS13,
3963 MaxEarlyDataSize: 16384,
3964 Bugs: ProtocolBugs{
3965 AlwaysRejectEarlyData: true,
3966 },
3967 },
3968 resumeSession: true,
3969 flags: []string{
3970 "-enable-early-data",
3971 "-expect-early-data-info",
3972 "-expect-reject-early-data",
3973 "-on-resume-read-with-unfinished-write",
3974 "-on-resume-shim-writes-first",
3975 },
3976 })
3977 }
3978
3979 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003980 testType: serverTest,
3981 name: "TLS13-EarlyData-Server",
3982 config: Config{
3983 MaxVersion: VersionTLS13,
3984 MinVersion: VersionTLS13,
3985 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003986 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003987 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003988 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003989 },
3990 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003991 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003992 resumeSession: true,
3993 flags: []string{
3994 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003995 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003996 },
3997 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003998
3999 tests = append(tests, testCase{
4000 testType: serverTest,
4001 name: "TLS13-MaxEarlyData-Server",
4002 config: Config{
4003 MaxVersion: VersionTLS13,
4004 MinVersion: VersionTLS13,
4005 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004006 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004007 ExpectEarlyDataAccepted: true,
4008 },
4009 },
4010 messageCount: 2,
4011 resumeSession: true,
4012 flags: []string{
4013 "-enable-early-data",
4014 "-expect-accept-early-data",
4015 },
4016 shouldFail: true,
4017 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4018 })
David Benjamine73c7f42016-08-17 00:29:33 -04004019 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004020
David Benjamin760b1dd2015-05-15 23:33:48 -04004021 // TLS client auth.
4022 tests = append(tests, testCase{
4023 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004024 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004026 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004027 ClientAuth: RequestClientCert,
4028 },
4029 })
4030 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004031 testType: serverTest,
4032 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004033 config: Config{
4034 MaxVersion: VersionTLS12,
4035 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004036 // Setting SSL_VERIFY_PEER allows anonymous clients.
4037 flags: []string{"-verify-peer"},
4038 })
David Benjamin582ba042016-07-07 12:33:25 -07004039 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004040 tests = append(tests, testCase{
4041 testType: clientTest,
4042 name: "ClientAuth-NoCertificate-Client-SSL3",
4043 config: Config{
4044 MaxVersion: VersionSSL30,
4045 ClientAuth: RequestClientCert,
4046 },
4047 })
4048 tests = append(tests, testCase{
4049 testType: serverTest,
4050 name: "ClientAuth-NoCertificate-Server-SSL3",
4051 config: Config{
4052 MaxVersion: VersionSSL30,
4053 },
4054 // Setting SSL_VERIFY_PEER allows anonymous clients.
4055 flags: []string{"-verify-peer"},
4056 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004057 tests = append(tests, testCase{
4058 testType: clientTest,
4059 name: "ClientAuth-NoCertificate-Client-TLS13",
4060 config: Config{
4061 MaxVersion: VersionTLS13,
4062 ClientAuth: RequestClientCert,
4063 },
4064 })
4065 tests = append(tests, testCase{
4066 testType: serverTest,
4067 name: "ClientAuth-NoCertificate-Server-TLS13",
4068 config: Config{
4069 MaxVersion: VersionTLS13,
4070 },
4071 // Setting SSL_VERIFY_PEER allows anonymous clients.
4072 flags: []string{"-verify-peer"},
4073 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004074 }
4075 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004076 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004077 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004079 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004080 ClientAuth: RequireAnyClientCert,
4081 },
4082 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004083 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4084 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004085 },
4086 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004087 tests = append(tests, testCase{
4088 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004089 name: "ClientAuth-RSA-Client-TLS13",
4090 config: Config{
4091 MaxVersion: VersionTLS13,
4092 ClientAuth: RequireAnyClientCert,
4093 },
4094 flags: []string{
4095 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4096 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4097 },
4098 })
4099 tests = append(tests, testCase{
4100 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004101 name: "ClientAuth-ECDSA-Client",
4102 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004103 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004104 ClientAuth: RequireAnyClientCert,
4105 },
4106 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004107 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4108 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004109 },
4110 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004111 tests = append(tests, testCase{
4112 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004113 name: "ClientAuth-ECDSA-Client-TLS13",
4114 config: Config{
4115 MaxVersion: VersionTLS13,
4116 ClientAuth: RequireAnyClientCert,
4117 },
4118 flags: []string{
4119 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4120 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4121 },
4122 })
4123 tests = append(tests, testCase{
4124 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004125 name: "ClientAuth-NoCertificate-OldCallback",
4126 config: Config{
4127 MaxVersion: VersionTLS12,
4128 ClientAuth: RequestClientCert,
4129 },
4130 flags: []string{"-use-old-client-cert-callback"},
4131 })
4132 tests = append(tests, testCase{
4133 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004134 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4135 config: Config{
4136 MaxVersion: VersionTLS13,
4137 ClientAuth: RequestClientCert,
4138 },
4139 flags: []string{"-use-old-client-cert-callback"},
4140 })
4141 tests = append(tests, testCase{
4142 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004143 name: "ClientAuth-OldCallback",
4144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004145 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004146 ClientAuth: RequireAnyClientCert,
4147 },
4148 flags: []string{
4149 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4150 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4151 "-use-old-client-cert-callback",
4152 },
4153 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004154 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004155 testType: clientTest,
4156 name: "ClientAuth-OldCallback-TLS13",
4157 config: Config{
4158 MaxVersion: VersionTLS13,
4159 ClientAuth: RequireAnyClientCert,
4160 },
4161 flags: []string{
4162 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4163 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4164 "-use-old-client-cert-callback",
4165 },
4166 })
4167 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004168 testType: serverTest,
4169 name: "ClientAuth-Server",
4170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004171 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004172 Certificates: []Certificate{rsaCertificate},
4173 },
4174 flags: []string{"-require-any-client-certificate"},
4175 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004176 tests = append(tests, testCase{
4177 testType: serverTest,
4178 name: "ClientAuth-Server-TLS13",
4179 config: Config{
4180 MaxVersion: VersionTLS13,
4181 Certificates: []Certificate{rsaCertificate},
4182 },
4183 flags: []string{"-require-any-client-certificate"},
4184 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004185
David Benjamin4c3ddf72016-06-29 18:13:53 -04004186 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004187 tests = append(tests, testCase{
4188 testType: serverTest,
4189 name: "Basic-Server-RSA",
4190 config: Config{
4191 MaxVersion: VersionTLS12,
4192 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4193 },
4194 flags: []string{
4195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4197 },
4198 })
4199 tests = append(tests, testCase{
4200 testType: serverTest,
4201 name: "Basic-Server-ECDHE-RSA",
4202 config: Config{
4203 MaxVersion: VersionTLS12,
4204 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4205 },
4206 flags: []string{
4207 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4208 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4209 },
4210 })
4211 tests = append(tests, testCase{
4212 testType: serverTest,
4213 name: "Basic-Server-ECDHE-ECDSA",
4214 config: Config{
4215 MaxVersion: VersionTLS12,
4216 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4217 },
4218 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004219 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4220 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004221 },
4222 })
David Benjamin69522112017-03-28 15:38:29 -05004223 tests = append(tests, testCase{
4224 testType: serverTest,
4225 name: "Basic-Server-Ed25519",
4226 config: Config{
4227 MaxVersion: VersionTLS12,
4228 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4229 },
4230 flags: []string{
4231 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4232 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4233 "-enable-ed25519",
4234 },
4235 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004236
David Benjamin760b1dd2015-05-15 23:33:48 -04004237 // No session ticket support; server doesn't send NewSessionTicket.
4238 tests = append(tests, testCase{
4239 name: "SessionTicketsDisabled-Client",
4240 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004241 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004242 SessionTicketsDisabled: true,
4243 },
4244 })
4245 tests = append(tests, testCase{
4246 testType: serverTest,
4247 name: "SessionTicketsDisabled-Server",
4248 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004249 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004250 SessionTicketsDisabled: true,
4251 },
4252 })
4253
4254 // Skip ServerKeyExchange in PSK key exchange if there's no
4255 // identity hint.
4256 tests = append(tests, testCase{
4257 name: "EmptyPSKHint-Client",
4258 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004259 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004260 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4261 PreSharedKey: []byte("secret"),
4262 },
4263 flags: []string{"-psk", "secret"},
4264 })
4265 tests = append(tests, testCase{
4266 testType: serverTest,
4267 name: "EmptyPSKHint-Server",
4268 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004269 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004270 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4271 PreSharedKey: []byte("secret"),
4272 },
4273 flags: []string{"-psk", "secret"},
4274 })
4275
David Benjamin4c3ddf72016-06-29 18:13:53 -04004276 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004277 tests = append(tests, testCase{
4278 testType: clientTest,
4279 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004280 config: Config{
4281 MaxVersion: VersionTLS12,
4282 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004283 flags: []string{
4284 "-enable-ocsp-stapling",
4285 "-expect-ocsp-response",
4286 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004287 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004288 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004289 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004290 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004291 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004292 testType: serverTest,
4293 name: "OCSPStapling-Server",
4294 config: Config{
4295 MaxVersion: VersionTLS12,
4296 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004297 expectedOCSPResponse: testOCSPResponse,
4298 flags: []string{
4299 "-ocsp-response",
4300 base64.StdEncoding.EncodeToString(testOCSPResponse),
4301 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004302 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004303 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004304 tests = append(tests, testCase{
4305 testType: clientTest,
4306 name: "OCSPStapling-Client-TLS13",
4307 config: Config{
4308 MaxVersion: VersionTLS13,
4309 },
4310 flags: []string{
4311 "-enable-ocsp-stapling",
4312 "-expect-ocsp-response",
4313 base64.StdEncoding.EncodeToString(testOCSPResponse),
4314 "-verify-peer",
4315 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004316 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004317 })
4318 tests = append(tests, testCase{
4319 testType: serverTest,
4320 name: "OCSPStapling-Server-TLS13",
4321 config: Config{
4322 MaxVersion: VersionTLS13,
4323 },
4324 expectedOCSPResponse: testOCSPResponse,
4325 flags: []string{
4326 "-ocsp-response",
4327 base64.StdEncoding.EncodeToString(testOCSPResponse),
4328 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004329 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004330 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004331
David Benjamin4c3ddf72016-06-29 18:13:53 -04004332 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004333 for _, vers := range tlsVersions {
4334 if config.protocol == dtls && !vers.hasDTLS {
4335 continue
4336 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004337 for _, testType := range []testType{clientTest, serverTest} {
4338 suffix := "-Client"
4339 if testType == serverTest {
4340 suffix = "-Server"
4341 }
4342 suffix += "-" + vers.name
4343
4344 flag := "-verify-peer"
4345 if testType == serverTest {
4346 flag = "-require-any-client-certificate"
4347 }
4348
4349 tests = append(tests, testCase{
4350 testType: testType,
4351 name: "CertificateVerificationSucceed" + suffix,
4352 config: Config{
4353 MaxVersion: vers.version,
4354 Certificates: []Certificate{rsaCertificate},
4355 },
4356 flags: []string{
4357 flag,
4358 "-expect-verify-result",
4359 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004360 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004361 })
4362 tests = append(tests, testCase{
4363 testType: testType,
4364 name: "CertificateVerificationFail" + suffix,
4365 config: Config{
4366 MaxVersion: vers.version,
4367 Certificates: []Certificate{rsaCertificate},
4368 },
4369 flags: []string{
4370 flag,
4371 "-verify-fail",
4372 },
4373 shouldFail: true,
4374 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4375 })
4376 }
4377
4378 // By default, the client is in a soft fail mode where the peer
4379 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004380 tests = append(tests, testCase{
4381 testType: clientTest,
4382 name: "CertificateVerificationSoftFail-" + vers.name,
4383 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004384 MaxVersion: vers.version,
4385 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004386 },
4387 flags: []string{
4388 "-verify-fail",
4389 "-expect-verify-result",
4390 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004391 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004392 })
4393 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004394
David Benjamin1d4f4c02016-07-26 18:03:08 -04004395 tests = append(tests, testCase{
4396 name: "ShimSendAlert",
4397 flags: []string{"-send-alert"},
4398 shimWritesFirst: true,
4399 shouldFail: true,
4400 expectedLocalError: "remote error: decompression failure",
4401 })
4402
David Benjamin582ba042016-07-07 12:33:25 -07004403 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004404 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004405 name: "Renegotiate-Client",
4406 config: Config{
4407 MaxVersion: VersionTLS12,
4408 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004409 renegotiate: 1,
4410 flags: []string{
4411 "-renegotiate-freely",
4412 "-expect-total-renegotiations", "1",
4413 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004414 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004415
David Benjamin47921102016-07-28 11:29:18 -04004416 tests = append(tests, testCase{
4417 name: "SendHalfHelloRequest",
4418 config: Config{
4419 MaxVersion: VersionTLS12,
4420 Bugs: ProtocolBugs{
4421 PackHelloRequestWithFinished: config.packHandshakeFlight,
4422 },
4423 },
4424 sendHalfHelloRequest: true,
4425 flags: []string{"-renegotiate-ignore"},
4426 shouldFail: true,
4427 expectedError: ":UNEXPECTED_RECORD:",
4428 })
4429
David Benjamin760b1dd2015-05-15 23:33:48 -04004430 // NPN on client and server; results in post-handshake message.
4431 tests = append(tests, testCase{
4432 name: "NPN-Client",
4433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004434 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004435 NextProtos: []string{"foo"},
4436 },
4437 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004438 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004439 expectedNextProto: "foo",
4440 expectedNextProtoType: npn,
4441 })
4442 tests = append(tests, testCase{
4443 testType: serverTest,
4444 name: "NPN-Server",
4445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004446 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004447 NextProtos: []string{"bar"},
4448 },
4449 flags: []string{
4450 "-advertise-npn", "\x03foo\x03bar\x03baz",
4451 "-expect-next-proto", "bar",
4452 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004453 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004454 expectedNextProto: "bar",
4455 expectedNextProtoType: npn,
4456 })
4457
4458 // TODO(davidben): Add tests for when False Start doesn't trigger.
4459
4460 // Client does False Start and negotiates NPN.
4461 tests = append(tests, testCase{
4462 name: "FalseStart",
4463 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004464 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004465 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4466 NextProtos: []string{"foo"},
4467 Bugs: ProtocolBugs{
4468 ExpectFalseStart: true,
4469 },
4470 },
4471 flags: []string{
4472 "-false-start",
4473 "-select-next-proto", "foo",
4474 },
4475 shimWritesFirst: true,
4476 resumeSession: true,
4477 })
4478
4479 // Client does False Start and negotiates ALPN.
4480 tests = append(tests, testCase{
4481 name: "FalseStart-ALPN",
4482 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004483 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004484 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4485 NextProtos: []string{"foo"},
4486 Bugs: ProtocolBugs{
4487 ExpectFalseStart: true,
4488 },
4489 },
4490 flags: []string{
4491 "-false-start",
4492 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004493 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004494 },
4495 shimWritesFirst: true,
4496 resumeSession: true,
4497 })
4498
David Benjamin760b1dd2015-05-15 23:33:48 -04004499 // False Start without session tickets.
4500 tests = append(tests, testCase{
4501 name: "FalseStart-SessionTicketsDisabled",
4502 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004503 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004504 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4505 NextProtos: []string{"foo"},
4506 SessionTicketsDisabled: true,
4507 Bugs: ProtocolBugs{
4508 ExpectFalseStart: true,
4509 },
4510 },
4511 flags: []string{
4512 "-false-start",
4513 "-select-next-proto", "foo",
4514 },
4515 shimWritesFirst: true,
4516 })
4517
4518 // Server parses a V2ClientHello.
4519 tests = append(tests, testCase{
4520 testType: serverTest,
4521 name: "SendV2ClientHello",
4522 config: Config{
4523 // Choose a cipher suite that does not involve
4524 // elliptic curves, so no extensions are
4525 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004526 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004527 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004528 Bugs: ProtocolBugs{
4529 SendV2ClientHello: true,
4530 },
4531 },
4532 })
4533
Nick Harper60a85cb2016-09-23 16:25:11 -07004534 // Test Channel ID
4535 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004536 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004537 continue
4538 }
4539 // Client sends a Channel ID.
4540 tests = append(tests, testCase{
4541 name: "ChannelID-Client-" + ver.name,
4542 config: Config{
4543 MaxVersion: ver.version,
4544 RequestChannelID: true,
4545 },
4546 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4547 resumeSession: true,
4548 expectChannelID: true,
4549 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004550
Nick Harper60a85cb2016-09-23 16:25:11 -07004551 // Server accepts a Channel ID.
4552 tests = append(tests, testCase{
4553 testType: serverTest,
4554 name: "ChannelID-Server-" + ver.name,
4555 config: Config{
4556 MaxVersion: ver.version,
4557 ChannelID: channelIDKey,
4558 },
4559 flags: []string{
4560 "-expect-channel-id",
4561 base64.StdEncoding.EncodeToString(channelIDBytes),
4562 },
4563 resumeSession: true,
4564 expectChannelID: true,
4565 })
4566
4567 tests = append(tests, testCase{
4568 testType: serverTest,
4569 name: "InvalidChannelIDSignature-" + ver.name,
4570 config: Config{
4571 MaxVersion: ver.version,
4572 ChannelID: channelIDKey,
4573 Bugs: ProtocolBugs{
4574 InvalidChannelIDSignature: true,
4575 },
4576 },
4577 flags: []string{"-enable-channel-id"},
4578 shouldFail: true,
4579 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4580 })
David Benjamin634f4752017-07-01 11:08:41 -04004581
4582 if ver.version < VersionTLS13 {
4583 // Channel ID requires ECDHE ciphers.
4584 tests = append(tests, testCase{
4585 testType: serverTest,
4586 name: "ChannelID-NoECDHE-" + ver.name,
4587 config: Config{
4588 MaxVersion: ver.version,
4589 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4590 ChannelID: channelIDKey,
4591 },
4592 expectChannelID: false,
4593 flags: []string{"-enable-channel-id"},
4594 })
4595
4596 // Sanity-check setting expectChannelID false works.
4597 tests = append(tests, testCase{
4598 testType: serverTest,
4599 name: "ChannelID-ECDHE-" + ver.name,
4600 config: Config{
4601 MaxVersion: ver.version,
4602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4603 ChannelID: channelIDKey,
4604 },
4605 expectChannelID: false,
4606 flags: []string{"-enable-channel-id"},
4607 shouldFail: true,
4608 expectedLocalError: "channel ID unexpectedly negotiated",
4609 })
4610 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004611 }
David Benjamin30789da2015-08-29 22:56:45 -04004612
David Benjaminf8fcdf32016-06-08 15:56:13 -04004613 // Channel ID and NPN at the same time, to ensure their relative
4614 // ordering is correct.
4615 tests = append(tests, testCase{
4616 name: "ChannelID-NPN-Client",
4617 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004618 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004619 RequestChannelID: true,
4620 NextProtos: []string{"foo"},
4621 },
4622 flags: []string{
4623 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4624 "-select-next-proto", "foo",
4625 },
4626 resumeSession: true,
4627 expectChannelID: true,
4628 expectedNextProto: "foo",
4629 expectedNextProtoType: npn,
4630 })
4631 tests = append(tests, testCase{
4632 testType: serverTest,
4633 name: "ChannelID-NPN-Server",
4634 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004635 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004636 ChannelID: channelIDKey,
4637 NextProtos: []string{"bar"},
4638 },
4639 flags: []string{
4640 "-expect-channel-id",
4641 base64.StdEncoding.EncodeToString(channelIDBytes),
4642 "-advertise-npn", "\x03foo\x03bar\x03baz",
4643 "-expect-next-proto", "bar",
4644 },
4645 resumeSession: true,
4646 expectChannelID: true,
4647 expectedNextProto: "bar",
4648 expectedNextProtoType: npn,
4649 })
4650
David Benjamin30789da2015-08-29 22:56:45 -04004651 // Bidirectional shutdown with the runner initiating.
4652 tests = append(tests, testCase{
4653 name: "Shutdown-Runner",
4654 config: Config{
4655 Bugs: ProtocolBugs{
4656 ExpectCloseNotify: true,
4657 },
4658 },
4659 flags: []string{"-check-close-notify"},
4660 })
4661
David Benjamine3843d42017-03-25 18:00:56 -05004662 if !config.implicitHandshake {
4663 // Bidirectional shutdown with the shim initiating. The runner,
4664 // in the meantime, sends garbage before the close_notify which
4665 // the shim must ignore. This test is disabled under implicit
4666 // handshake tests because the shim never reads or writes.
4667 tests = append(tests, testCase{
4668 name: "Shutdown-Shim",
4669 config: Config{
4670 MaxVersion: VersionTLS12,
4671 Bugs: ProtocolBugs{
4672 ExpectCloseNotify: true,
4673 },
David Benjamin30789da2015-08-29 22:56:45 -04004674 },
David Benjamine3843d42017-03-25 18:00:56 -05004675 shimShutsDown: true,
4676 sendEmptyRecords: 1,
4677 sendWarningAlerts: 1,
4678 flags: []string{"-check-close-notify"},
4679 })
4680 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004681 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004682 // TODO(davidben): DTLS 1.3 will want a similar thing for
4683 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004684 tests = append(tests, testCase{
4685 name: "SkipHelloVerifyRequest",
4686 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004687 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004688 Bugs: ProtocolBugs{
4689 SkipHelloVerifyRequest: true,
4690 },
4691 },
4692 })
4693 }
4694
David Benjamin760b1dd2015-05-15 23:33:48 -04004695 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004696 test.protocol = config.protocol
4697 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004698 test.name += "-DTLS"
4699 }
David Benjamin582ba042016-07-07 12:33:25 -07004700 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004701 test.name += "-Async"
4702 test.flags = append(test.flags, "-async")
4703 } else {
4704 test.name += "-Sync"
4705 }
David Benjamin582ba042016-07-07 12:33:25 -07004706 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004707 test.name += "-SplitHandshakeRecords"
4708 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004709 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004710 test.config.Bugs.MaxPacketLength = 256
4711 test.flags = append(test.flags, "-mtu", "256")
4712 }
4713 }
David Benjamin582ba042016-07-07 12:33:25 -07004714 if config.packHandshakeFlight {
4715 test.name += "-PackHandshakeFlight"
4716 test.config.Bugs.PackHandshakeFlight = true
4717 }
David Benjamine3843d42017-03-25 18:00:56 -05004718 if config.implicitHandshake {
4719 test.name += "-ImplicitHandshake"
4720 test.flags = append(test.flags, "-implicit-handshake")
4721 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004722 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004723 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004724}
4725
Adam Langley524e7172015-02-20 16:04:00 -08004726func addDDoSCallbackTests() {
4727 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004728 for _, resume := range []bool{false, true} {
4729 suffix := "Resume"
4730 if resume {
4731 suffix = "No" + suffix
4732 }
4733
4734 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004735 testType: serverTest,
4736 name: "Server-DDoS-OK-" + suffix,
4737 config: Config{
4738 MaxVersion: VersionTLS12,
4739 },
Adam Langley524e7172015-02-20 16:04:00 -08004740 flags: []string{"-install-ddos-callback"},
4741 resumeSession: resume,
4742 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004743 testCases = append(testCases, testCase{
4744 testType: serverTest,
4745 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4746 config: Config{
4747 MaxVersion: VersionTLS13,
4748 },
4749 flags: []string{"-install-ddos-callback"},
4750 resumeSession: resume,
4751 })
Adam Langley524e7172015-02-20 16:04:00 -08004752
4753 failFlag := "-fail-ddos-callback"
4754 if resume {
4755 failFlag = "-fail-second-ddos-callback"
4756 }
4757 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004758 testType: serverTest,
4759 name: "Server-DDoS-Reject-" + suffix,
4760 config: Config{
4761 MaxVersion: VersionTLS12,
4762 },
David Benjamin2c66e072016-09-16 15:58:00 -04004763 flags: []string{"-install-ddos-callback", failFlag},
4764 resumeSession: resume,
4765 shouldFail: true,
4766 expectedError: ":CONNECTION_REJECTED:",
4767 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004768 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004769 testCases = append(testCases, testCase{
4770 testType: serverTest,
4771 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4772 config: Config{
4773 MaxVersion: VersionTLS13,
4774 },
David Benjamin2c66e072016-09-16 15:58:00 -04004775 flags: []string{"-install-ddos-callback", failFlag},
4776 resumeSession: resume,
4777 shouldFail: true,
4778 expectedError: ":CONNECTION_REJECTED:",
4779 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004780 })
Adam Langley524e7172015-02-20 16:04:00 -08004781 }
4782}
4783
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004784func addVersionNegotiationTests() {
4785 for i, shimVers := range tlsVersions {
4786 // Assemble flags to disable all newer versions on the shim.
4787 var flags []string
4788 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004789 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004790 }
4791
Steven Valdezfdd10992016-09-15 16:27:05 -04004792 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004793 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004794 protocols := []protocol{tls}
4795 if runnerVers.hasDTLS && shimVers.hasDTLS {
4796 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004797 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004798 for _, protocol := range protocols {
4799 expectedVersion := shimVers.version
4800 if runnerVers.version < shimVers.version {
4801 expectedVersion = runnerVers.version
4802 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004803
David Benjamin8b8c0062014-11-23 02:47:52 -05004804 suffix := shimVers.name + "-" + runnerVers.name
4805 if protocol == dtls {
4806 suffix += "-DTLS"
4807 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004808
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004809 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004810 clientVers := shimVers.version
4811 if clientVers > VersionTLS10 {
4812 clientVers = VersionTLS10
4813 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004814 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004815 serverVers := expectedVersion
4816 if expectedVersion >= VersionTLS13 {
4817 serverVers = VersionTLS10
4818 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004819 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004820
David Benjamin8b8c0062014-11-23 02:47:52 -05004821 testCases = append(testCases, testCase{
4822 protocol: protocol,
4823 testType: clientTest,
4824 name: "VersionNegotiation-Client-" + suffix,
4825 config: Config{
4826 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004827 Bugs: ProtocolBugs{
4828 ExpectInitialRecordVersion: clientVers,
4829 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004830 },
4831 flags: flags,
4832 expectedVersion: expectedVersion,
4833 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004834 testCases = append(testCases, testCase{
4835 protocol: protocol,
4836 testType: clientTest,
4837 name: "VersionNegotiation-Client2-" + suffix,
4838 config: Config{
4839 MaxVersion: runnerVers.version,
4840 Bugs: ProtocolBugs{
4841 ExpectInitialRecordVersion: clientVers,
4842 },
4843 },
David Benjamin353577c2017-06-29 15:54:58 -04004844 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004845 expectedVersion: expectedVersion,
4846 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004847
4848 testCases = append(testCases, testCase{
4849 protocol: protocol,
4850 testType: serverTest,
4851 name: "VersionNegotiation-Server-" + suffix,
4852 config: Config{
4853 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004854 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004855 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004856 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004857 },
4858 flags: flags,
4859 expectedVersion: expectedVersion,
4860 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004861 testCases = append(testCases, testCase{
4862 protocol: protocol,
4863 testType: serverTest,
4864 name: "VersionNegotiation-Server2-" + suffix,
4865 config: Config{
4866 MaxVersion: runnerVers.version,
4867 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004868 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004869 },
4870 },
David Benjamin353577c2017-06-29 15:54:58 -04004871 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004872 expectedVersion: expectedVersion,
4873 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004874 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004875 }
4876 }
David Benjamin95c69562016-06-29 18:15:03 -04004877
Steven Valdezfdd10992016-09-15 16:27:05 -04004878 // Test the version extension at all versions.
4879 for _, vers := range tlsVersions {
4880 protocols := []protocol{tls}
4881 if vers.hasDTLS {
4882 protocols = append(protocols, dtls)
4883 }
4884 for _, protocol := range protocols {
4885 suffix := vers.name
4886 if protocol == dtls {
4887 suffix += "-DTLS"
4888 }
4889
Steven Valdezc94998a2017-06-20 10:55:02 -04004890 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004891 testCases = append(testCases, testCase{
4892 protocol: protocol,
4893 testType: serverTest,
4894 name: "VersionNegotiationExtension-" + suffix,
4895 config: Config{
4896 Bugs: ProtocolBugs{
4897 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4898 },
4899 },
4900 expectedVersion: vers.version,
4901 })
4902 }
4903
4904 }
4905
4906 // If all versions are unknown, negotiation fails.
4907 testCases = append(testCases, testCase{
4908 testType: serverTest,
4909 name: "NoSupportedVersions",
4910 config: Config{
4911 Bugs: ProtocolBugs{
4912 SendSupportedVersions: []uint16{0x1111},
4913 },
4914 },
4915 shouldFail: true,
4916 expectedError: ":UNSUPPORTED_PROTOCOL:",
4917 })
4918 testCases = append(testCases, testCase{
4919 protocol: dtls,
4920 testType: serverTest,
4921 name: "NoSupportedVersions-DTLS",
4922 config: Config{
4923 Bugs: ProtocolBugs{
4924 SendSupportedVersions: []uint16{0x1111},
4925 },
4926 },
4927 shouldFail: true,
4928 expectedError: ":UNSUPPORTED_PROTOCOL:",
4929 })
4930
4931 testCases = append(testCases, testCase{
4932 testType: serverTest,
4933 name: "ClientHelloVersionTooHigh",
4934 config: Config{
4935 MaxVersion: VersionTLS13,
4936 Bugs: ProtocolBugs{
4937 SendClientVersion: 0x0304,
4938 OmitSupportedVersions: true,
4939 },
4940 },
4941 expectedVersion: VersionTLS12,
4942 })
4943
4944 testCases = append(testCases, testCase{
4945 testType: serverTest,
4946 name: "ConflictingVersionNegotiation",
4947 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004948 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004949 SendClientVersion: VersionTLS12,
4950 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004951 },
4952 },
David Benjaminad75a662016-09-30 15:42:59 -04004953 // The extension takes precedence over the ClientHello version.
4954 expectedVersion: VersionTLS11,
4955 })
4956
4957 testCases = append(testCases, testCase{
4958 testType: serverTest,
4959 name: "ConflictingVersionNegotiation-2",
4960 config: Config{
4961 Bugs: ProtocolBugs{
4962 SendClientVersion: VersionTLS11,
4963 SendSupportedVersions: []uint16{VersionTLS12},
4964 },
4965 },
4966 // The extension takes precedence over the ClientHello version.
4967 expectedVersion: VersionTLS12,
4968 })
4969
4970 testCases = append(testCases, testCase{
4971 testType: serverTest,
4972 name: "RejectFinalTLS13",
4973 config: Config{
4974 Bugs: ProtocolBugs{
4975 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4976 },
4977 },
4978 // We currently implement a draft TLS 1.3 version. Ensure that
4979 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004980 expectedVersion: VersionTLS12,
4981 })
4982
Brian Smithf85d3232016-10-28 10:34:06 -10004983 // Test that the maximum version is selected regardless of the
4984 // client-sent order.
4985 testCases = append(testCases, testCase{
4986 testType: serverTest,
4987 name: "IgnoreClientVersionOrder",
4988 config: Config{
4989 Bugs: ProtocolBugs{
4990 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4991 },
4992 },
4993 expectedVersion: VersionTLS13,
4994 })
4995
David Benjamin95c69562016-06-29 18:15:03 -04004996 // Test for version tolerance.
4997 testCases = append(testCases, testCase{
4998 testType: serverTest,
4999 name: "MinorVersionTolerance",
5000 config: Config{
5001 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005002 SendClientVersion: 0x03ff,
5003 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005004 },
5005 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005006 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005007 })
5008 testCases = append(testCases, testCase{
5009 testType: serverTest,
5010 name: "MajorVersionTolerance",
5011 config: Config{
5012 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005013 SendClientVersion: 0x0400,
5014 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005015 },
5016 },
David Benjaminad75a662016-09-30 15:42:59 -04005017 // TLS 1.3 must be negotiated with the supported_versions
5018 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005019 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005020 })
David Benjaminad75a662016-09-30 15:42:59 -04005021 testCases = append(testCases, testCase{
5022 testType: serverTest,
5023 name: "VersionTolerance-TLS13",
5024 config: Config{
5025 Bugs: ProtocolBugs{
5026 // Although TLS 1.3 does not use
5027 // ClientHello.version, it still tolerates high
5028 // values there.
5029 SendClientVersion: 0x0400,
5030 },
5031 },
5032 expectedVersion: VersionTLS13,
5033 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005034
David Benjamin95c69562016-06-29 18:15:03 -04005035 testCases = append(testCases, testCase{
5036 protocol: dtls,
5037 testType: serverTest,
5038 name: "MinorVersionTolerance-DTLS",
5039 config: Config{
5040 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005041 SendClientVersion: 0xfe00,
5042 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005043 },
5044 },
5045 expectedVersion: VersionTLS12,
5046 })
5047 testCases = append(testCases, testCase{
5048 protocol: dtls,
5049 testType: serverTest,
5050 name: "MajorVersionTolerance-DTLS",
5051 config: Config{
5052 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005053 SendClientVersion: 0xfdff,
5054 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005055 },
5056 },
5057 expectedVersion: VersionTLS12,
5058 })
5059
5060 // Test that versions below 3.0 are rejected.
5061 testCases = append(testCases, testCase{
5062 testType: serverTest,
5063 name: "VersionTooLow",
5064 config: Config{
5065 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005066 SendClientVersion: 0x0200,
5067 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005068 },
5069 },
5070 shouldFail: true,
5071 expectedError: ":UNSUPPORTED_PROTOCOL:",
5072 })
5073 testCases = append(testCases, testCase{
5074 protocol: dtls,
5075 testType: serverTest,
5076 name: "VersionTooLow-DTLS",
5077 config: Config{
5078 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005079 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005080 },
5081 },
5082 shouldFail: true,
5083 expectedError: ":UNSUPPORTED_PROTOCOL:",
5084 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005085
David Benjamin2dc02042016-09-19 19:57:37 -04005086 testCases = append(testCases, testCase{
5087 name: "ServerBogusVersion",
5088 config: Config{
5089 Bugs: ProtocolBugs{
5090 SendServerHelloVersion: 0x1234,
5091 },
5092 },
5093 shouldFail: true,
5094 expectedError: ":UNSUPPORTED_PROTOCOL:",
5095 })
5096
David Benjamin1f61f0d2016-07-10 12:20:35 -04005097 // Test TLS 1.3's downgrade signal.
5098 testCases = append(testCases, testCase{
5099 name: "Downgrade-TLS12-Client",
5100 config: Config{
5101 Bugs: ProtocolBugs{
5102 NegotiateVersion: VersionTLS12,
5103 },
5104 },
David Benjamin592b5322016-09-30 15:15:01 -04005105 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005106 // TODO(davidben): This test should fail once TLS 1.3 is final
5107 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005108 })
5109 testCases = append(testCases, testCase{
5110 testType: serverTest,
5111 name: "Downgrade-TLS12-Server",
5112 config: Config{
5113 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005114 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005115 },
5116 },
David Benjamin592b5322016-09-30 15:15:01 -04005117 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005118 // TODO(davidben): This test should fail once TLS 1.3 is final
5119 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005120 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005121}
5122
David Benjaminaccb4542014-12-12 23:44:33 -05005123func addMinimumVersionTests() {
5124 for i, shimVers := range tlsVersions {
5125 // Assemble flags to disable all older versions on the shim.
5126 var flags []string
5127 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04005128 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05005129 }
5130
5131 for _, runnerVers := range tlsVersions {
5132 protocols := []protocol{tls}
5133 if runnerVers.hasDTLS && shimVers.hasDTLS {
5134 protocols = append(protocols, dtls)
5135 }
5136 for _, protocol := range protocols {
5137 suffix := shimVers.name + "-" + runnerVers.name
5138 if protocol == dtls {
5139 suffix += "-DTLS"
5140 }
David Benjaminaccb4542014-12-12 23:44:33 -05005141
David Benjaminaccb4542014-12-12 23:44:33 -05005142 var expectedVersion uint16
5143 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005144 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005145 if runnerVers.version >= shimVers.version {
5146 expectedVersion = runnerVers.version
5147 } else {
5148 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005149 expectedError = ":UNSUPPORTED_PROTOCOL:"
5150 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005151 }
5152
5153 testCases = append(testCases, testCase{
5154 protocol: protocol,
5155 testType: clientTest,
5156 name: "MinimumVersion-Client-" + suffix,
5157 config: Config{
5158 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005159 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005160 // Ensure the server does not decline to
5161 // select a version (versions extension) or
5162 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005163 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005164 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005165 },
David Benjaminaccb4542014-12-12 23:44:33 -05005166 },
David Benjamin87909c02014-12-13 01:55:01 -05005167 flags: flags,
5168 expectedVersion: expectedVersion,
5169 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005170 expectedError: expectedError,
5171 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005172 })
5173 testCases = append(testCases, testCase{
5174 protocol: protocol,
5175 testType: clientTest,
5176 name: "MinimumVersion-Client2-" + suffix,
5177 config: Config{
5178 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005179 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005180 // Ensure the server does not decline to
5181 // select a version (versions extension) or
5182 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005183 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005184 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005185 },
David Benjaminaccb4542014-12-12 23:44:33 -05005186 },
David Benjamin353577c2017-06-29 15:54:58 -04005187 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005188 expectedVersion: expectedVersion,
5189 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005190 expectedError: expectedError,
5191 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005192 })
5193
5194 testCases = append(testCases, testCase{
5195 protocol: protocol,
5196 testType: serverTest,
5197 name: "MinimumVersion-Server-" + suffix,
5198 config: Config{
5199 MaxVersion: runnerVers.version,
5200 },
David Benjamin87909c02014-12-13 01:55:01 -05005201 flags: flags,
5202 expectedVersion: expectedVersion,
5203 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005204 expectedError: expectedError,
5205 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005206 })
5207 testCases = append(testCases, testCase{
5208 protocol: protocol,
5209 testType: serverTest,
5210 name: "MinimumVersion-Server2-" + suffix,
5211 config: Config{
5212 MaxVersion: runnerVers.version,
5213 },
David Benjamin353577c2017-06-29 15:54:58 -04005214 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005215 expectedVersion: expectedVersion,
5216 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005217 expectedError: expectedError,
5218 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005219 })
5220 }
5221 }
5222 }
5223}
5224
David Benjamine78bfde2014-09-06 12:45:15 -04005225func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005226 // TODO(davidben): Extensions, where applicable, all move their server
5227 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5228 // tests for both. Also test interaction with 0-RTT when implemented.
5229
David Benjamin97d17d92016-07-14 16:12:00 -04005230 // Repeat extensions tests all versions except SSL 3.0.
5231 for _, ver := range tlsVersions {
5232 if ver.version == VersionSSL30 {
5233 continue
5234 }
5235
David Benjamin97d17d92016-07-14 16:12:00 -04005236 // Test that duplicate extensions are rejected.
5237 testCases = append(testCases, testCase{
5238 testType: clientTest,
5239 name: "DuplicateExtensionClient-" + ver.name,
5240 config: Config{
5241 MaxVersion: ver.version,
5242 Bugs: ProtocolBugs{
5243 DuplicateExtension: true,
5244 },
David Benjamine78bfde2014-09-06 12:45:15 -04005245 },
David Benjamin97d17d92016-07-14 16:12:00 -04005246 shouldFail: true,
5247 expectedLocalError: "remote error: error decoding message",
5248 })
5249 testCases = append(testCases, testCase{
5250 testType: serverTest,
5251 name: "DuplicateExtensionServer-" + ver.name,
5252 config: Config{
5253 MaxVersion: ver.version,
5254 Bugs: ProtocolBugs{
5255 DuplicateExtension: true,
5256 },
David Benjamine78bfde2014-09-06 12:45:15 -04005257 },
David Benjamin97d17d92016-07-14 16:12:00 -04005258 shouldFail: true,
5259 expectedLocalError: "remote error: error decoding message",
5260 })
5261
5262 // Test SNI.
5263 testCases = append(testCases, testCase{
5264 testType: clientTest,
5265 name: "ServerNameExtensionClient-" + ver.name,
5266 config: Config{
5267 MaxVersion: ver.version,
5268 Bugs: ProtocolBugs{
5269 ExpectServerName: "example.com",
5270 },
David Benjamine78bfde2014-09-06 12:45:15 -04005271 },
David Benjamin97d17d92016-07-14 16:12:00 -04005272 flags: []string{"-host-name", "example.com"},
5273 })
5274 testCases = append(testCases, testCase{
5275 testType: clientTest,
5276 name: "ServerNameExtensionClientMismatch-" + ver.name,
5277 config: Config{
5278 MaxVersion: ver.version,
5279 Bugs: ProtocolBugs{
5280 ExpectServerName: "mismatch.com",
5281 },
David Benjamine78bfde2014-09-06 12:45:15 -04005282 },
David Benjamin97d17d92016-07-14 16:12:00 -04005283 flags: []string{"-host-name", "example.com"},
5284 shouldFail: true,
5285 expectedLocalError: "tls: unexpected server name",
5286 })
5287 testCases = append(testCases, testCase{
5288 testType: clientTest,
5289 name: "ServerNameExtensionClientMissing-" + ver.name,
5290 config: Config{
5291 MaxVersion: ver.version,
5292 Bugs: ProtocolBugs{
5293 ExpectServerName: "missing.com",
5294 },
David Benjamine78bfde2014-09-06 12:45:15 -04005295 },
David Benjamin97d17d92016-07-14 16:12:00 -04005296 shouldFail: true,
5297 expectedLocalError: "tls: unexpected server name",
5298 })
5299 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005300 testType: clientTest,
5301 name: "TolerateServerNameAck-" + ver.name,
5302 config: Config{
5303 MaxVersion: ver.version,
5304 Bugs: ProtocolBugs{
5305 SendServerNameAck: true,
5306 },
5307 },
5308 flags: []string{"-host-name", "example.com"},
5309 resumeSession: true,
5310 })
5311 testCases = append(testCases, testCase{
5312 testType: clientTest,
5313 name: "UnsolicitedServerNameAck-" + ver.name,
5314 config: Config{
5315 MaxVersion: ver.version,
5316 Bugs: ProtocolBugs{
5317 SendServerNameAck: true,
5318 },
5319 },
5320 shouldFail: true,
5321 expectedError: ":UNEXPECTED_EXTENSION:",
5322 expectedLocalError: "remote error: unsupported extension",
5323 })
5324 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005325 testType: serverTest,
5326 name: "ServerNameExtensionServer-" + ver.name,
5327 config: Config{
5328 MaxVersion: ver.version,
5329 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005330 },
David Benjamin97d17d92016-07-14 16:12:00 -04005331 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005332 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005333 })
5334
5335 // Test ALPN.
5336 testCases = append(testCases, testCase{
5337 testType: clientTest,
5338 name: "ALPNClient-" + ver.name,
5339 config: Config{
5340 MaxVersion: ver.version,
5341 NextProtos: []string{"foo"},
5342 },
5343 flags: []string{
5344 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5345 "-expect-alpn", "foo",
5346 },
5347 expectedNextProto: "foo",
5348 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005349 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005350 })
5351 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005352 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005353 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005354 config: Config{
5355 MaxVersion: ver.version,
5356 Bugs: ProtocolBugs{
5357 SendALPN: "baz",
5358 },
5359 },
5360 flags: []string{
5361 "-advertise-alpn", "\x03foo\x03bar",
5362 },
5363 shouldFail: true,
5364 expectedError: ":INVALID_ALPN_PROTOCOL:",
5365 expectedLocalError: "remote error: illegal parameter",
5366 })
5367 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005368 testType: clientTest,
5369 name: "ALPNClient-AllowUnknown-" + ver.name,
5370 config: Config{
5371 MaxVersion: ver.version,
5372 Bugs: ProtocolBugs{
5373 SendALPN: "baz",
5374 },
5375 },
5376 flags: []string{
5377 "-advertise-alpn", "\x03foo\x03bar",
5378 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005379 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005380 },
5381 })
5382 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005383 testType: serverTest,
5384 name: "ALPNServer-" + ver.name,
5385 config: Config{
5386 MaxVersion: ver.version,
5387 NextProtos: []string{"foo", "bar", "baz"},
5388 },
5389 flags: []string{
5390 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5391 "-select-alpn", "foo",
5392 },
5393 expectedNextProto: "foo",
5394 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005395 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005396 })
5397 testCases = append(testCases, testCase{
5398 testType: serverTest,
5399 name: "ALPNServer-Decline-" + ver.name,
5400 config: Config{
5401 MaxVersion: ver.version,
5402 NextProtos: []string{"foo", "bar", "baz"},
5403 },
5404 flags: []string{"-decline-alpn"},
5405 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005406 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005407 })
5408
David Benjamin25fe85b2016-08-09 20:00:32 -04005409 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5410 // called once.
5411 testCases = append(testCases, testCase{
5412 testType: serverTest,
5413 name: "ALPNServer-Async-" + ver.name,
5414 config: Config{
5415 MaxVersion: ver.version,
5416 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005417 // Prior to TLS 1.3, exercise the asynchronous session callback.
5418 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005419 },
5420 flags: []string{
5421 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5422 "-select-alpn", "foo",
5423 "-async",
5424 },
5425 expectedNextProto: "foo",
5426 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005427 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005428 })
5429
David Benjamin97d17d92016-07-14 16:12:00 -04005430 var emptyString string
5431 testCases = append(testCases, testCase{
5432 testType: clientTest,
5433 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5434 config: Config{
5435 MaxVersion: ver.version,
5436 NextProtos: []string{""},
5437 Bugs: ProtocolBugs{
5438 // A server returning an empty ALPN protocol
5439 // should be rejected.
5440 ALPNProtocol: &emptyString,
5441 },
5442 },
5443 flags: []string{
5444 "-advertise-alpn", "\x03foo",
5445 },
5446 shouldFail: true,
5447 expectedError: ":PARSE_TLSEXT:",
5448 })
5449 testCases = append(testCases, testCase{
5450 testType: serverTest,
5451 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5452 config: Config{
5453 MaxVersion: ver.version,
5454 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005455 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005456 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005457 },
David Benjamin97d17d92016-07-14 16:12:00 -04005458 flags: []string{
5459 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005460 },
David Benjamin97d17d92016-07-14 16:12:00 -04005461 shouldFail: true,
5462 expectedError: ":PARSE_TLSEXT:",
5463 })
5464
5465 // Test NPN and the interaction with ALPN.
5466 if ver.version < VersionTLS13 {
5467 // Test that the server prefers ALPN over NPN.
5468 testCases = append(testCases, testCase{
5469 testType: serverTest,
5470 name: "ALPNServer-Preferred-" + ver.name,
5471 config: Config{
5472 MaxVersion: ver.version,
5473 NextProtos: []string{"foo", "bar", "baz"},
5474 },
5475 flags: []string{
5476 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5477 "-select-alpn", "foo",
5478 "-advertise-npn", "\x03foo\x03bar\x03baz",
5479 },
5480 expectedNextProto: "foo",
5481 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005482 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005483 })
5484 testCases = append(testCases, testCase{
5485 testType: serverTest,
5486 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5487 config: Config{
5488 MaxVersion: ver.version,
5489 NextProtos: []string{"foo", "bar", "baz"},
5490 Bugs: ProtocolBugs{
5491 SwapNPNAndALPN: true,
5492 },
5493 },
5494 flags: []string{
5495 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5496 "-select-alpn", "foo",
5497 "-advertise-npn", "\x03foo\x03bar\x03baz",
5498 },
5499 expectedNextProto: "foo",
5500 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005501 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005502 })
5503
5504 // Test that negotiating both NPN and ALPN is forbidden.
5505 testCases = append(testCases, testCase{
5506 name: "NegotiateALPNAndNPN-" + ver.name,
5507 config: Config{
5508 MaxVersion: ver.version,
5509 NextProtos: []string{"foo", "bar", "baz"},
5510 Bugs: ProtocolBugs{
5511 NegotiateALPNAndNPN: true,
5512 },
5513 },
5514 flags: []string{
5515 "-advertise-alpn", "\x03foo",
5516 "-select-next-proto", "foo",
5517 },
5518 shouldFail: true,
5519 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5520 })
5521 testCases = append(testCases, testCase{
5522 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5523 config: Config{
5524 MaxVersion: ver.version,
5525 NextProtos: []string{"foo", "bar", "baz"},
5526 Bugs: ProtocolBugs{
5527 NegotiateALPNAndNPN: true,
5528 SwapNPNAndALPN: true,
5529 },
5530 },
5531 flags: []string{
5532 "-advertise-alpn", "\x03foo",
5533 "-select-next-proto", "foo",
5534 },
5535 shouldFail: true,
5536 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5537 })
David Benjamin97d17d92016-07-14 16:12:00 -04005538 }
5539
5540 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005541
5542 // Resume with a corrupt ticket.
5543 testCases = append(testCases, testCase{
5544 testType: serverTest,
5545 name: "CorruptTicket-" + ver.name,
5546 config: Config{
5547 MaxVersion: ver.version,
5548 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005549 FilterTicket: func(in []byte) ([]byte, error) {
5550 in[len(in)-1] ^= 1
5551 return in, nil
5552 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005553 },
5554 },
5555 resumeSession: true,
5556 expectResumeRejected: true,
5557 })
5558 // Test the ticket callback, with and without renewal.
5559 testCases = append(testCases, testCase{
5560 testType: serverTest,
5561 name: "TicketCallback-" + ver.name,
5562 config: Config{
5563 MaxVersion: ver.version,
5564 },
5565 resumeSession: true,
5566 flags: []string{"-use-ticket-callback"},
5567 })
5568 testCases = append(testCases, testCase{
5569 testType: serverTest,
5570 name: "TicketCallback-Renew-" + ver.name,
5571 config: Config{
5572 MaxVersion: ver.version,
5573 Bugs: ProtocolBugs{
5574 ExpectNewTicket: true,
5575 },
5576 },
5577 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5578 resumeSession: true,
5579 })
5580
5581 // Test that the ticket callback is only called once when everything before
5582 // it in the ClientHello is asynchronous. This corrupts the ticket so
5583 // certificate selection callbacks run.
5584 testCases = append(testCases, testCase{
5585 testType: serverTest,
5586 name: "TicketCallback-SingleCall-" + ver.name,
5587 config: Config{
5588 MaxVersion: ver.version,
5589 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005590 FilterTicket: func(in []byte) ([]byte, error) {
5591 in[len(in)-1] ^= 1
5592 return in, nil
5593 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005594 },
5595 },
5596 resumeSession: true,
5597 expectResumeRejected: true,
5598 flags: []string{
5599 "-use-ticket-callback",
5600 "-async",
5601 },
5602 })
5603
David Benjamind4c349b2017-02-09 14:07:17 -05005604 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005605 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005606 testCases = append(testCases, testCase{
5607 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005608 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005609 config: Config{
5610 MaxVersion: ver.version,
5611 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005612 EmptyTicketSessionID: true,
5613 },
5614 },
5615 resumeSession: true,
5616 })
5617 testCases = append(testCases, testCase{
5618 testType: serverTest,
5619 name: "TicketSessionIDLength-16-" + ver.name,
5620 config: Config{
5621 MaxVersion: ver.version,
5622 Bugs: ProtocolBugs{
5623 TicketSessionIDLength: 16,
5624 },
5625 },
5626 resumeSession: true,
5627 })
5628 testCases = append(testCases, testCase{
5629 testType: serverTest,
5630 name: "TicketSessionIDLength-32-" + ver.name,
5631 config: Config{
5632 MaxVersion: ver.version,
5633 Bugs: ProtocolBugs{
5634 TicketSessionIDLength: 32,
5635 },
5636 },
5637 resumeSession: true,
5638 })
5639 testCases = append(testCases, testCase{
5640 testType: serverTest,
5641 name: "TicketSessionIDLength-33-" + ver.name,
5642 config: Config{
5643 MaxVersion: ver.version,
5644 Bugs: ProtocolBugs{
5645 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005646 },
5647 },
5648 resumeSession: true,
5649 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005650 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005651 expectedError: ":DECODE_ERROR:",
5652 })
5653 }
5654
5655 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5656 // are ignored.
5657 if ver.hasDTLS {
5658 testCases = append(testCases, testCase{
5659 protocol: dtls,
5660 name: "SRTP-Client-" + ver.name,
5661 config: Config{
5662 MaxVersion: ver.version,
5663 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5664 },
5665 flags: []string{
5666 "-srtp-profiles",
5667 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5668 },
5669 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5670 })
5671 testCases = append(testCases, testCase{
5672 protocol: dtls,
5673 testType: serverTest,
5674 name: "SRTP-Server-" + ver.name,
5675 config: Config{
5676 MaxVersion: ver.version,
5677 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5678 },
5679 flags: []string{
5680 "-srtp-profiles",
5681 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5682 },
5683 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5684 })
5685 // Test that the MKI is ignored.
5686 testCases = append(testCases, testCase{
5687 protocol: dtls,
5688 testType: serverTest,
5689 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5690 config: Config{
5691 MaxVersion: ver.version,
5692 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5693 Bugs: ProtocolBugs{
5694 SRTPMasterKeyIdentifer: "bogus",
5695 },
5696 },
5697 flags: []string{
5698 "-srtp-profiles",
5699 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5700 },
5701 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5702 })
5703 // Test that SRTP isn't negotiated on the server if there were
5704 // no matching profiles.
5705 testCases = append(testCases, testCase{
5706 protocol: dtls,
5707 testType: serverTest,
5708 name: "SRTP-Server-NoMatch-" + ver.name,
5709 config: Config{
5710 MaxVersion: ver.version,
5711 SRTPProtectionProfiles: []uint16{100, 101, 102},
5712 },
5713 flags: []string{
5714 "-srtp-profiles",
5715 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5716 },
5717 expectedSRTPProtectionProfile: 0,
5718 })
5719 // Test that the server returning an invalid SRTP profile is
5720 // flagged as an error by the client.
5721 testCases = append(testCases, testCase{
5722 protocol: dtls,
5723 name: "SRTP-Client-NoMatch-" + ver.name,
5724 config: Config{
5725 MaxVersion: ver.version,
5726 Bugs: ProtocolBugs{
5727 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5728 },
5729 },
5730 flags: []string{
5731 "-srtp-profiles",
5732 "SRTP_AES128_CM_SHA1_80",
5733 },
5734 shouldFail: true,
5735 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5736 })
5737 }
5738
5739 // Test SCT list.
5740 testCases = append(testCases, testCase{
5741 name: "SignedCertificateTimestampList-Client-" + ver.name,
5742 testType: clientTest,
5743 config: Config{
5744 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005745 },
David Benjamin97d17d92016-07-14 16:12:00 -04005746 flags: []string{
5747 "-enable-signed-cert-timestamps",
5748 "-expect-signed-cert-timestamps",
5749 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005750 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005751 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005752 })
David Benjamindaa88502016-10-04 16:32:16 -04005753
Adam Langleycfa08c32016-11-17 13:21:27 -08005754 var differentSCTList []byte
5755 differentSCTList = append(differentSCTList, testSCTList...)
5756 differentSCTList[len(differentSCTList)-1] ^= 1
5757
David Benjamindaa88502016-10-04 16:32:16 -04005758 // The SCT extension did not specify that it must only be sent on resumption as it
5759 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005760 testCases = append(testCases, testCase{
5761 name: "SendSCTListOnResume-" + ver.name,
5762 config: Config{
5763 MaxVersion: ver.version,
5764 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005765 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005766 },
David Benjamind98452d2015-06-16 14:16:23 -04005767 },
David Benjamin97d17d92016-07-14 16:12:00 -04005768 flags: []string{
5769 "-enable-signed-cert-timestamps",
5770 "-expect-signed-cert-timestamps",
5771 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005772 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005773 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005774 })
David Benjamindaa88502016-10-04 16:32:16 -04005775
David Benjamin97d17d92016-07-14 16:12:00 -04005776 testCases = append(testCases, testCase{
5777 name: "SignedCertificateTimestampList-Server-" + ver.name,
5778 testType: serverTest,
5779 config: Config{
5780 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005781 },
David Benjamin97d17d92016-07-14 16:12:00 -04005782 flags: []string{
5783 "-signed-cert-timestamps",
5784 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005785 },
David Benjamin97d17d92016-07-14 16:12:00 -04005786 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005787 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005788 })
David Benjamin53210cb2016-11-16 09:01:48 +09005789
Adam Langleycfa08c32016-11-17 13:21:27 -08005790 emptySCTListCert := *testCerts[0].cert
5791 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5792
5793 // Test empty SCT list.
5794 testCases = append(testCases, testCase{
5795 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5796 testType: clientTest,
5797 config: Config{
5798 MaxVersion: ver.version,
5799 Certificates: []Certificate{emptySCTListCert},
5800 },
5801 flags: []string{
5802 "-enable-signed-cert-timestamps",
5803 },
5804 shouldFail: true,
5805 expectedError: ":ERROR_PARSING_EXTENSION:",
5806 })
5807
5808 emptySCTCert := *testCerts[0].cert
5809 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5810
5811 // Test empty SCT in non-empty list.
5812 testCases = append(testCases, testCase{
5813 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5814 testType: clientTest,
5815 config: Config{
5816 MaxVersion: ver.version,
5817 Certificates: []Certificate{emptySCTCert},
5818 },
5819 flags: []string{
5820 "-enable-signed-cert-timestamps",
5821 },
5822 shouldFail: true,
5823 expectedError: ":ERROR_PARSING_EXTENSION:",
5824 })
5825
David Benjamin53210cb2016-11-16 09:01:48 +09005826 // Test that certificate-related extensions are not sent unsolicited.
5827 testCases = append(testCases, testCase{
5828 testType: serverTest,
5829 name: "UnsolicitedCertificateExtensions-" + ver.name,
5830 config: Config{
5831 MaxVersion: ver.version,
5832 Bugs: ProtocolBugs{
5833 NoOCSPStapling: true,
5834 NoSignedCertificateTimestamps: true,
5835 },
5836 },
5837 flags: []string{
5838 "-ocsp-response",
5839 base64.StdEncoding.EncodeToString(testOCSPResponse),
5840 "-signed-cert-timestamps",
5841 base64.StdEncoding.EncodeToString(testSCTList),
5842 },
5843 })
David Benjamin97d17d92016-07-14 16:12:00 -04005844 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005845
Paul Lietar4fac72e2015-09-09 13:44:55 +01005846 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005847 testType: clientTest,
5848 name: "ClientHelloPadding",
5849 config: Config{
5850 Bugs: ProtocolBugs{
5851 RequireClientHelloSize: 512,
5852 },
5853 },
5854 // This hostname just needs to be long enough to push the
5855 // ClientHello into F5's danger zone between 256 and 511 bytes
5856 // long.
5857 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5858 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005859
5860 // Extensions should not function in SSL 3.0.
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "SSLv3Extensions-NoALPN",
5864 config: Config{
5865 MaxVersion: VersionSSL30,
5866 NextProtos: []string{"foo", "bar", "baz"},
5867 },
5868 flags: []string{
5869 "-select-alpn", "foo",
5870 },
5871 expectNoNextProto: true,
5872 })
5873
5874 // Test session tickets separately as they follow a different codepath.
5875 testCases = append(testCases, testCase{
5876 testType: serverTest,
5877 name: "SSLv3Extensions-NoTickets",
5878 config: Config{
5879 MaxVersion: VersionSSL30,
5880 Bugs: ProtocolBugs{
5881 // Historically, session tickets in SSL 3.0
5882 // failed in different ways depending on whether
5883 // the client supported renegotiation_info.
5884 NoRenegotiationInfo: true,
5885 },
5886 },
5887 resumeSession: true,
5888 })
5889 testCases = append(testCases, testCase{
5890 testType: serverTest,
5891 name: "SSLv3Extensions-NoTickets2",
5892 config: Config{
5893 MaxVersion: VersionSSL30,
5894 },
5895 resumeSession: true,
5896 })
5897
5898 // But SSL 3.0 does send and process renegotiation_info.
5899 testCases = append(testCases, testCase{
5900 testType: serverTest,
5901 name: "SSLv3Extensions-RenegotiationInfo",
5902 config: Config{
5903 MaxVersion: VersionSSL30,
5904 Bugs: ProtocolBugs{
5905 RequireRenegotiationInfo: true,
5906 },
5907 },
David Benjamind2610042017-01-03 10:49:28 -05005908 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005909 })
5910 testCases = append(testCases, testCase{
5911 testType: serverTest,
5912 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5913 config: Config{
5914 MaxVersion: VersionSSL30,
5915 Bugs: ProtocolBugs{
5916 NoRenegotiationInfo: true,
5917 SendRenegotiationSCSV: true,
5918 RequireRenegotiationInfo: true,
5919 },
5920 },
David Benjamind2610042017-01-03 10:49:28 -05005921 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005922 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005923
5924 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5925 // in ServerHello.
5926 testCases = append(testCases, testCase{
5927 name: "NPN-Forbidden-TLS13",
5928 config: Config{
5929 MaxVersion: VersionTLS13,
5930 NextProtos: []string{"foo"},
5931 Bugs: ProtocolBugs{
5932 NegotiateNPNAtAllVersions: true,
5933 },
5934 },
5935 flags: []string{"-select-next-proto", "foo"},
5936 shouldFail: true,
5937 expectedError: ":ERROR_PARSING_EXTENSION:",
5938 })
5939 testCases = append(testCases, testCase{
5940 name: "EMS-Forbidden-TLS13",
5941 config: Config{
5942 MaxVersion: VersionTLS13,
5943 Bugs: ProtocolBugs{
5944 NegotiateEMSAtAllVersions: true,
5945 },
5946 },
5947 shouldFail: true,
5948 expectedError: ":ERROR_PARSING_EXTENSION:",
5949 })
5950 testCases = append(testCases, testCase{
5951 name: "RenegotiationInfo-Forbidden-TLS13",
5952 config: Config{
5953 MaxVersion: VersionTLS13,
5954 Bugs: ProtocolBugs{
5955 NegotiateRenegotiationInfoAtAllVersions: true,
5956 },
5957 },
5958 shouldFail: true,
5959 expectedError: ":ERROR_PARSING_EXTENSION:",
5960 })
5961 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005962 name: "Ticket-Forbidden-TLS13",
5963 config: Config{
5964 MaxVersion: VersionTLS12,
5965 },
5966 resumeConfig: &Config{
5967 MaxVersion: VersionTLS13,
5968 Bugs: ProtocolBugs{
5969 AdvertiseTicketExtension: true,
5970 },
5971 },
5972 resumeSession: true,
5973 shouldFail: true,
5974 expectedError: ":ERROR_PARSING_EXTENSION:",
5975 })
5976
5977 // Test that illegal extensions in TLS 1.3 are declined by the server if
5978 // offered in ClientHello. The runner's server will fail if this occurs,
5979 // so we exercise the offering path. (EMS and Renegotiation Info are
5980 // implicit in every test.)
5981 testCases = append(testCases, testCase{
5982 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005983 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005984 config: Config{
5985 MaxVersion: VersionTLS13,
5986 NextProtos: []string{"bar"},
5987 },
5988 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5989 })
David Benjamin196df5b2016-09-21 16:23:27 -04005990
David Benjamindaa88502016-10-04 16:32:16 -04005991 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5992 // tolerated.
5993 testCases = append(testCases, testCase{
5994 name: "SendOCSPResponseOnResume-TLS12",
5995 config: Config{
5996 MaxVersion: VersionTLS12,
5997 Bugs: ProtocolBugs{
5998 SendOCSPResponseOnResume: []byte("bogus"),
5999 },
6000 },
6001 flags: []string{
6002 "-enable-ocsp-stapling",
6003 "-expect-ocsp-response",
6004 base64.StdEncoding.EncodeToString(testOCSPResponse),
6005 },
6006 resumeSession: true,
6007 })
6008
David Benjamindaa88502016-10-04 16:32:16 -04006009 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006010 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006011 config: Config{
6012 MaxVersion: VersionTLS13,
6013 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006014 SendExtensionOnCertificate: testOCSPExtension,
6015 },
6016 },
6017 shouldFail: true,
6018 expectedError: ":UNEXPECTED_EXTENSION:",
6019 })
6020
6021 testCases = append(testCases, testCase{
6022 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6023 config: Config{
6024 MaxVersion: VersionTLS13,
6025 Bugs: ProtocolBugs{
6026 SendExtensionOnCertificate: testSCTExtension,
6027 },
6028 },
6029 shouldFail: true,
6030 expectedError: ":UNEXPECTED_EXTENSION:",
6031 })
6032
6033 // Test that extensions on client certificates are never accepted.
6034 testCases = append(testCases, testCase{
6035 name: "SendExtensionOnClientCertificate-TLS13",
6036 testType: serverTest,
6037 config: Config{
6038 MaxVersion: VersionTLS13,
6039 Certificates: []Certificate{rsaCertificate},
6040 Bugs: ProtocolBugs{
6041 SendExtensionOnCertificate: testOCSPExtension,
6042 },
6043 },
6044 flags: []string{
6045 "-enable-ocsp-stapling",
6046 "-require-any-client-certificate",
6047 },
6048 shouldFail: true,
6049 expectedError: ":UNEXPECTED_EXTENSION:",
6050 })
6051
6052 testCases = append(testCases, testCase{
6053 name: "SendUnknownExtensionOnCertificate-TLS13",
6054 config: Config{
6055 MaxVersion: VersionTLS13,
6056 Bugs: ProtocolBugs{
6057 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6058 },
6059 },
6060 shouldFail: true,
6061 expectedError: ":UNEXPECTED_EXTENSION:",
6062 })
6063
Adam Langleycfa08c32016-11-17 13:21:27 -08006064 var differentSCTList []byte
6065 differentSCTList = append(differentSCTList, testSCTList...)
6066 differentSCTList[len(differentSCTList)-1] ^= 1
6067
Steven Valdeza833c352016-11-01 13:39:36 -04006068 // Test that extensions on intermediates are allowed but ignored.
6069 testCases = append(testCases, testCase{
6070 name: "IgnoreExtensionsOnIntermediates-TLS13",
6071 config: Config{
6072 MaxVersion: VersionTLS13,
6073 Certificates: []Certificate{rsaChainCertificate},
6074 Bugs: ProtocolBugs{
6075 // Send different values on the intermediate. This tests
6076 // the intermediate's extensions do not override the
6077 // leaf's.
6078 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006079 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006080 },
6081 },
6082 flags: []string{
6083 "-enable-ocsp-stapling",
6084 "-expect-ocsp-response",
6085 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006086 "-enable-signed-cert-timestamps",
6087 "-expect-signed-cert-timestamps",
6088 base64.StdEncoding.EncodeToString(testSCTList),
6089 },
6090 resumeSession: true,
6091 })
6092
6093 // Test that extensions are not sent on intermediates when configured
6094 // only for a leaf.
6095 testCases = append(testCases, testCase{
6096 testType: serverTest,
6097 name: "SendNoExtensionsOnIntermediate-TLS13",
6098 config: Config{
6099 MaxVersion: VersionTLS13,
6100 Bugs: ProtocolBugs{
6101 ExpectNoExtensionsOnIntermediate: true,
6102 },
6103 },
6104 flags: []string{
6105 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6106 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6107 "-ocsp-response",
6108 base64.StdEncoding.EncodeToString(testOCSPResponse),
6109 "-signed-cert-timestamps",
6110 base64.StdEncoding.EncodeToString(testSCTList),
6111 },
6112 })
6113
6114 // Test that extensions are not sent on client certificates.
6115 testCases = append(testCases, testCase{
6116 name: "SendNoClientCertificateExtensions-TLS13",
6117 config: Config{
6118 MaxVersion: VersionTLS13,
6119 ClientAuth: RequireAnyClientCert,
6120 },
6121 flags: []string{
6122 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6123 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6124 "-ocsp-response",
6125 base64.StdEncoding.EncodeToString(testOCSPResponse),
6126 "-signed-cert-timestamps",
6127 base64.StdEncoding.EncodeToString(testSCTList),
6128 },
6129 })
6130
6131 testCases = append(testCases, testCase{
6132 name: "SendDuplicateExtensionsOnCerts-TLS13",
6133 config: Config{
6134 MaxVersion: VersionTLS13,
6135 Bugs: ProtocolBugs{
6136 SendDuplicateCertExtensions: true,
6137 },
6138 },
6139 flags: []string{
6140 "-enable-ocsp-stapling",
6141 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006142 },
6143 resumeSession: true,
6144 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006145 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006146 })
Adam Langley9b885c52016-11-18 14:21:03 -08006147
6148 testCases = append(testCases, testCase{
6149 name: "SignedCertificateTimestampListInvalid-Server",
6150 testType: serverTest,
6151 flags: []string{
6152 "-signed-cert-timestamps",
6153 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6154 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006155 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006156 expectedError: ":INVALID_SCT_LIST:",
6157 })
David Benjamine78bfde2014-09-06 12:45:15 -04006158}
6159
David Benjamin01fe8202014-09-24 15:21:44 -04006160func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006161 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006162 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006163 // SSL 3.0 does not have tickets and TLS 1.3 does not
6164 // have session IDs, so skip their cross-resumption
6165 // tests.
6166 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6167 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6168 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006169 }
6170
David Benjamin8b8c0062014-11-23 02:47:52 -05006171 protocols := []protocol{tls}
6172 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6173 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006174 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006175 for _, protocol := range protocols {
6176 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6177 if protocol == dtls {
6178 suffix += "-DTLS"
6179 }
6180
David Benjaminece3de92015-03-16 18:02:20 -04006181 if sessionVers.version == resumeVers.version {
6182 testCases = append(testCases, testCase{
6183 protocol: protocol,
6184 name: "Resume-Client" + suffix,
6185 resumeSession: true,
6186 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006187 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006188 Bugs: ProtocolBugs{
6189 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6190 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6191 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006192 },
David Benjaminece3de92015-03-16 18:02:20 -04006193 expectedVersion: sessionVers.version,
6194 expectedResumeVersion: resumeVers.version,
6195 })
6196 } else {
David Benjamin405da482016-08-08 17:25:07 -04006197 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6198
6199 // Offering a TLS 1.3 session sends an empty session ID, so
6200 // there is no way to convince a non-lookahead client the
6201 // session was resumed. It will appear to the client that a
6202 // stray ChangeCipherSpec was sent.
6203 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6204 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006205 }
6206
David Benjaminece3de92015-03-16 18:02:20 -04006207 testCases = append(testCases, testCase{
6208 protocol: protocol,
6209 name: "Resume-Client-Mismatch" + suffix,
6210 resumeSession: true,
6211 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006212 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006213 },
David Benjaminece3de92015-03-16 18:02:20 -04006214 expectedVersion: sessionVers.version,
6215 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006216 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006217 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006218 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006219 },
6220 },
6221 expectedResumeVersion: resumeVers.version,
6222 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006223 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006224 })
6225 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006226
6227 testCases = append(testCases, testCase{
6228 protocol: protocol,
6229 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006230 resumeSession: true,
6231 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006232 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006233 },
6234 expectedVersion: sessionVers.version,
6235 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006236 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006237 },
6238 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006239 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006240 expectedResumeVersion: resumeVers.version,
6241 })
6242
David Benjamin8b8c0062014-11-23 02:47:52 -05006243 testCases = append(testCases, testCase{
6244 protocol: protocol,
6245 testType: serverTest,
6246 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006247 resumeSession: true,
6248 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006249 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006250 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006251 expectedVersion: sessionVers.version,
6252 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006253 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006254 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006255 Bugs: ProtocolBugs{
6256 SendBothTickets: true,
6257 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006258 },
6259 expectedResumeVersion: resumeVers.version,
6260 })
6261 }
David Benjamin01fe8202014-09-24 15:21:44 -04006262 }
6263 }
David Benjaminece3de92015-03-16 18:02:20 -04006264
David Benjamin4199b0d2016-11-01 13:58:25 -04006265 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006266 testCases = append(testCases, testCase{
6267 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006268 name: "ShimTicketRewritable",
6269 resumeSession: true,
6270 config: Config{
6271 MaxVersion: VersionTLS12,
6272 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6273 Bugs: ProtocolBugs{
6274 FilterTicket: func(in []byte) ([]byte, error) {
6275 in, err := SetShimTicketVersion(in, VersionTLS12)
6276 if err != nil {
6277 return nil, err
6278 }
6279 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6280 },
6281 },
6282 },
6283 flags: []string{
6284 "-ticket-key",
6285 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6286 },
6287 })
6288
6289 // Resumptions are declined if the version does not match.
6290 testCases = append(testCases, testCase{
6291 testType: serverTest,
6292 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006293 resumeSession: true,
6294 config: Config{
6295 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006296 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006297 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006298 FilterTicket: func(in []byte) ([]byte, error) {
6299 return SetShimTicketVersion(in, VersionTLS13)
6300 },
6301 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006302 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006303 flags: []string{
6304 "-ticket-key",
6305 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6306 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006307 expectResumeRejected: true,
6308 })
6309
6310 testCases = append(testCases, testCase{
6311 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006312 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006313 resumeSession: true,
6314 config: Config{
6315 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006316 Bugs: ProtocolBugs{
6317 FilterTicket: func(in []byte) ([]byte, error) {
6318 return SetShimTicketVersion(in, VersionTLS12)
6319 },
6320 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006321 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006322 flags: []string{
6323 "-ticket-key",
6324 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6325 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006326 expectResumeRejected: true,
6327 })
6328
David Benjamin4199b0d2016-11-01 13:58:25 -04006329 // Resumptions are declined if the cipher is invalid or disabled.
6330 testCases = append(testCases, testCase{
6331 testType: serverTest,
6332 name: "Resume-Server-DeclineBadCipher",
6333 resumeSession: true,
6334 config: Config{
6335 MaxVersion: VersionTLS12,
6336 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006337 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006338 FilterTicket: func(in []byte) ([]byte, error) {
6339 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6340 },
6341 },
6342 },
6343 flags: []string{
6344 "-ticket-key",
6345 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6346 },
6347 expectResumeRejected: true,
6348 })
6349
6350 testCases = append(testCases, testCase{
6351 testType: serverTest,
6352 name: "Resume-Server-DeclineBadCipher-2",
6353 resumeSession: true,
6354 config: Config{
6355 MaxVersion: VersionTLS12,
6356 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006357 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006358 FilterTicket: func(in []byte) ([]byte, error) {
6359 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6360 },
6361 },
6362 },
6363 flags: []string{
6364 "-cipher", "AES128",
6365 "-ticket-key",
6366 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6367 },
6368 expectResumeRejected: true,
6369 })
6370
David Benjaminf01f42a2016-11-16 19:05:33 +09006371 // Sessions are not resumed if they do not use the preferred cipher.
6372 testCases = append(testCases, testCase{
6373 testType: serverTest,
6374 name: "Resume-Server-CipherNotPreferred",
6375 resumeSession: true,
6376 config: Config{
6377 MaxVersion: VersionTLS12,
6378 Bugs: ProtocolBugs{
6379 ExpectNewTicket: true,
6380 FilterTicket: func(in []byte) ([]byte, error) {
6381 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6382 },
6383 },
6384 },
6385 flags: []string{
6386 "-ticket-key",
6387 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6388 },
6389 shouldFail: false,
6390 expectResumeRejected: true,
6391 })
6392
6393 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6394 // PRF hashes match, but BoringSSL will always decline such resumptions.
6395 testCases = append(testCases, testCase{
6396 testType: serverTest,
6397 name: "Resume-Server-CipherNotPreferred-TLS13",
6398 resumeSession: true,
6399 config: Config{
6400 MaxVersion: VersionTLS13,
6401 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6402 Bugs: ProtocolBugs{
6403 FilterTicket: func(in []byte) ([]byte, error) {
6404 // If the client (runner) offers ChaCha20-Poly1305 first, the
6405 // server (shim) always prefers it. Switch it to AES-GCM.
6406 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6407 },
6408 },
6409 },
6410 flags: []string{
6411 "-ticket-key",
6412 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6413 },
6414 shouldFail: false,
6415 expectResumeRejected: true,
6416 })
6417
6418 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006419 testCases = append(testCases, testCase{
6420 testType: serverTest,
6421 name: "Resume-Server-DeclineBadCipher-TLS13",
6422 resumeSession: true,
6423 config: Config{
6424 MaxVersion: VersionTLS13,
6425 Bugs: ProtocolBugs{
6426 FilterTicket: func(in []byte) ([]byte, error) {
6427 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6428 },
6429 },
6430 },
6431 flags: []string{
6432 "-ticket-key",
6433 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6434 },
6435 expectResumeRejected: true,
6436 })
6437
David Benjaminf01f42a2016-11-16 19:05:33 +09006438 // If the client does not offer the cipher from the session, decline to
6439 // resume. Clients are forbidden from doing this, but BoringSSL selects
6440 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006441 testCases = append(testCases, testCase{
6442 testType: serverTest,
6443 name: "Resume-Server-UnofferedCipher",
6444 resumeSession: true,
6445 config: Config{
6446 MaxVersion: VersionTLS12,
6447 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6448 },
6449 resumeConfig: &Config{
6450 MaxVersion: VersionTLS12,
6451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6452 Bugs: ProtocolBugs{
6453 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6454 },
6455 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006456 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006457 })
6458
David Benjaminf01f42a2016-11-16 19:05:33 +09006459 // In TLS 1.3, clients may advertise a cipher list which does not
6460 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006461 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6462 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006463 testCases = append(testCases, testCase{
6464 testType: serverTest,
6465 name: "Resume-Server-UnofferedCipher-TLS13",
6466 resumeSession: true,
6467 config: Config{
6468 MaxVersion: VersionTLS13,
6469 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6470 },
6471 resumeConfig: &Config{
6472 MaxVersion: VersionTLS13,
6473 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6474 Bugs: ProtocolBugs{
6475 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6476 },
6477 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006478 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006479 })
6480
David Benjamin4199b0d2016-11-01 13:58:25 -04006481 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006482 testCases = append(testCases, testCase{
6483 name: "Resume-Client-CipherMismatch",
6484 resumeSession: true,
6485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006486 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006487 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6488 },
6489 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006490 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006491 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6492 Bugs: ProtocolBugs{
6493 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6494 },
6495 },
6496 shouldFail: true,
6497 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6498 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006499
David Benjamine1cc35e2016-11-16 16:25:58 +09006500 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6501 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006502 testCases = append(testCases, testCase{
6503 name: "Resume-Client-CipherMismatch-TLS13",
6504 resumeSession: true,
6505 config: Config{
6506 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006507 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006508 },
6509 resumeConfig: &Config{
6510 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006511 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6512 },
6513 })
6514
6515 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6516 testCases = append(testCases, testCase{
6517 name: "Resume-Client-PRFMismatch-TLS13",
6518 resumeSession: true,
6519 config: Config{
6520 MaxVersion: VersionTLS13,
6521 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6522 },
6523 resumeConfig: &Config{
6524 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006525 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006526 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006527 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006528 },
6529 },
6530 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006531 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006532 })
Steven Valdeza833c352016-11-01 13:39:36 -04006533
6534 testCases = append(testCases, testCase{
6535 testType: serverTest,
6536 name: "Resume-Server-BinderWrongLength",
6537 resumeSession: true,
6538 config: Config{
6539 MaxVersion: VersionTLS13,
6540 Bugs: ProtocolBugs{
6541 SendShortPSKBinder: true,
6542 },
6543 },
6544 shouldFail: true,
6545 expectedLocalError: "remote error: error decrypting message",
6546 expectedError: ":DIGEST_CHECK_FAILED:",
6547 })
6548
6549 testCases = append(testCases, testCase{
6550 testType: serverTest,
6551 name: "Resume-Server-NoPSKBinder",
6552 resumeSession: true,
6553 config: Config{
6554 MaxVersion: VersionTLS13,
6555 Bugs: ProtocolBugs{
6556 SendNoPSKBinder: true,
6557 },
6558 },
6559 shouldFail: true,
6560 expectedLocalError: "remote error: error decoding message",
6561 expectedError: ":DECODE_ERROR:",
6562 })
6563
6564 testCases = append(testCases, testCase{
6565 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006566 name: "Resume-Server-ExtraPSKBinder",
6567 resumeSession: true,
6568 config: Config{
6569 MaxVersion: VersionTLS13,
6570 Bugs: ProtocolBugs{
6571 SendExtraPSKBinder: true,
6572 },
6573 },
6574 shouldFail: true,
6575 expectedLocalError: "remote error: illegal parameter",
6576 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6577 })
6578
6579 testCases = append(testCases, testCase{
6580 testType: serverTest,
6581 name: "Resume-Server-ExtraIdentityNoBinder",
6582 resumeSession: true,
6583 config: Config{
6584 MaxVersion: VersionTLS13,
6585 Bugs: ProtocolBugs{
6586 ExtraPSKIdentity: true,
6587 },
6588 },
6589 shouldFail: true,
6590 expectedLocalError: "remote error: illegal parameter",
6591 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6592 })
6593
6594 testCases = append(testCases, testCase{
6595 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006596 name: "Resume-Server-InvalidPSKBinder",
6597 resumeSession: true,
6598 config: Config{
6599 MaxVersion: VersionTLS13,
6600 Bugs: ProtocolBugs{
6601 SendInvalidPSKBinder: true,
6602 },
6603 },
6604 shouldFail: true,
6605 expectedLocalError: "remote error: error decrypting message",
6606 expectedError: ":DIGEST_CHECK_FAILED:",
6607 })
6608
6609 testCases = append(testCases, testCase{
6610 testType: serverTest,
6611 name: "Resume-Server-PSKBinderFirstExtension",
6612 resumeSession: true,
6613 config: Config{
6614 MaxVersion: VersionTLS13,
6615 Bugs: ProtocolBugs{
6616 PSKBinderFirst: true,
6617 },
6618 },
6619 shouldFail: true,
6620 expectedLocalError: "remote error: illegal parameter",
6621 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6622 })
David Benjamin01fe8202014-09-24 15:21:44 -04006623}
6624
Adam Langley2ae77d22014-10-28 17:29:33 -07006625func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006626 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006627 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006628 testType: serverTest,
6629 name: "Renegotiate-Server-Forbidden",
6630 config: Config{
6631 MaxVersion: VersionTLS12,
6632 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006633 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006634 shouldFail: true,
6635 expectedError: ":NO_RENEGOTIATION:",
6636 expectedLocalError: "remote error: no renegotiation",
6637 })
Adam Langley5021b222015-06-12 18:27:58 -07006638 // The server shouldn't echo the renegotiation extension unless
6639 // requested by the client.
6640 testCases = append(testCases, testCase{
6641 testType: serverTest,
6642 name: "Renegotiate-Server-NoExt",
6643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006644 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006645 Bugs: ProtocolBugs{
6646 NoRenegotiationInfo: true,
6647 RequireRenegotiationInfo: true,
6648 },
6649 },
6650 shouldFail: true,
6651 expectedLocalError: "renegotiation extension missing",
6652 })
6653 // The renegotiation SCSV should be sufficient for the server to echo
6654 // the extension.
6655 testCases = append(testCases, testCase{
6656 testType: serverTest,
6657 name: "Renegotiate-Server-NoExt-SCSV",
6658 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006659 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006660 Bugs: ProtocolBugs{
6661 NoRenegotiationInfo: true,
6662 SendRenegotiationSCSV: true,
6663 RequireRenegotiationInfo: true,
6664 },
6665 },
6666 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006667 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006668 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006670 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006671 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006672 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006673 },
6674 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006675 renegotiate: 1,
6676 flags: []string{
6677 "-renegotiate-freely",
6678 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006679 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006680 },
David Benjamincdea40c2015-03-19 14:09:43 -04006681 })
6682 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006683 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006684 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006685 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006686 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006687 Bugs: ProtocolBugs{
6688 EmptyRenegotiationInfo: true,
6689 },
6690 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006691 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006692 shouldFail: true,
6693 expectedError: ":RENEGOTIATION_MISMATCH:",
6694 })
6695 testCases = append(testCases, testCase{
6696 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006697 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006699 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006700 Bugs: ProtocolBugs{
6701 BadRenegotiationInfo: true,
6702 },
6703 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006704 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006705 shouldFail: true,
6706 expectedError: ":RENEGOTIATION_MISMATCH:",
6707 })
6708 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006709 name: "Renegotiate-Client-BadExt2",
6710 renegotiate: 1,
6711 config: Config{
6712 MaxVersion: VersionTLS12,
6713 Bugs: ProtocolBugs{
6714 BadRenegotiationInfoEnd: true,
6715 },
6716 },
6717 flags: []string{"-renegotiate-freely"},
6718 shouldFail: true,
6719 expectedError: ":RENEGOTIATION_MISMATCH:",
6720 })
6721 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006722 name: "Renegotiate-Client-Downgrade",
6723 renegotiate: 1,
6724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006725 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006726 Bugs: ProtocolBugs{
6727 NoRenegotiationInfoAfterInitial: true,
6728 },
6729 },
6730 flags: []string{"-renegotiate-freely"},
6731 shouldFail: true,
6732 expectedError: ":RENEGOTIATION_MISMATCH:",
6733 })
6734 testCases = append(testCases, testCase{
6735 name: "Renegotiate-Client-Upgrade",
6736 renegotiate: 1,
6737 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006738 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006739 Bugs: ProtocolBugs{
6740 NoRenegotiationInfoInInitial: true,
6741 },
6742 },
6743 flags: []string{"-renegotiate-freely"},
6744 shouldFail: true,
6745 expectedError: ":RENEGOTIATION_MISMATCH:",
6746 })
6747 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006748 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006749 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006751 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006752 Bugs: ProtocolBugs{
6753 NoRenegotiationInfo: true,
6754 },
6755 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006756 flags: []string{
6757 "-renegotiate-freely",
6758 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006759 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006760 },
David Benjamincff0b902015-05-15 23:09:47 -04006761 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006762
6763 // Test that the server may switch ciphers on renegotiation without
6764 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006765 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006766 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006767 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006768 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006769 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006770 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006771 },
6772 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006773 flags: []string{
6774 "-renegotiate-freely",
6775 "-expect-total-renegotiations", "1",
6776 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006777 })
6778 testCases = append(testCases, testCase{
6779 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006780 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006781 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006782 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6784 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006785 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006786 flags: []string{
6787 "-renegotiate-freely",
6788 "-expect-total-renegotiations", "1",
6789 },
David Benjaminb16346b2015-04-08 19:16:58 -04006790 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006791
6792 // Test that the server may not switch versions on renegotiation.
6793 testCases = append(testCases, testCase{
6794 name: "Renegotiate-Client-SwitchVersion",
6795 config: Config{
6796 MaxVersion: VersionTLS12,
6797 // Pick a cipher which exists at both versions.
6798 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6799 Bugs: ProtocolBugs{
6800 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006801 // Avoid failing early at the record layer.
6802 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006803 },
6804 },
6805 renegotiate: 1,
6806 flags: []string{
6807 "-renegotiate-freely",
6808 "-expect-total-renegotiations", "1",
6809 },
6810 shouldFail: true,
6811 expectedError: ":WRONG_SSL_VERSION:",
6812 })
6813
David Benjaminb16346b2015-04-08 19:16:58 -04006814 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006815 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006816 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006817 config: Config{
6818 MaxVersion: VersionTLS10,
6819 Bugs: ProtocolBugs{
6820 RequireSameRenegoClientVersion: true,
6821 },
6822 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006823 flags: []string{
6824 "-renegotiate-freely",
6825 "-expect-total-renegotiations", "1",
6826 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006827 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006828 testCases = append(testCases, testCase{
6829 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006830 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006831 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006832 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006833 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6834 NextProtos: []string{"foo"},
6835 },
6836 flags: []string{
6837 "-false-start",
6838 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006839 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006840 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006841 },
6842 shimWritesFirst: true,
6843 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006844
6845 // Client-side renegotiation controls.
6846 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006847 name: "Renegotiate-Client-Forbidden-1",
6848 config: Config{
6849 MaxVersion: VersionTLS12,
6850 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006851 renegotiate: 1,
6852 shouldFail: true,
6853 expectedError: ":NO_RENEGOTIATION:",
6854 expectedLocalError: "remote error: no renegotiation",
6855 })
6856 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006857 name: "Renegotiate-Client-Once-1",
6858 config: Config{
6859 MaxVersion: VersionTLS12,
6860 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006861 renegotiate: 1,
6862 flags: []string{
6863 "-renegotiate-once",
6864 "-expect-total-renegotiations", "1",
6865 },
6866 })
6867 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006868 name: "Renegotiate-Client-Freely-1",
6869 config: Config{
6870 MaxVersion: VersionTLS12,
6871 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006872 renegotiate: 1,
6873 flags: []string{
6874 "-renegotiate-freely",
6875 "-expect-total-renegotiations", "1",
6876 },
6877 })
6878 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006879 name: "Renegotiate-Client-Once-2",
6880 config: Config{
6881 MaxVersion: VersionTLS12,
6882 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006883 renegotiate: 2,
6884 flags: []string{"-renegotiate-once"},
6885 shouldFail: true,
6886 expectedError: ":NO_RENEGOTIATION:",
6887 expectedLocalError: "remote error: no renegotiation",
6888 })
6889 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006890 name: "Renegotiate-Client-Freely-2",
6891 config: Config{
6892 MaxVersion: VersionTLS12,
6893 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006894 renegotiate: 2,
6895 flags: []string{
6896 "-renegotiate-freely",
6897 "-expect-total-renegotiations", "2",
6898 },
6899 })
Adam Langley27a0d082015-11-03 13:34:10 -08006900 testCases = append(testCases, testCase{
6901 name: "Renegotiate-Client-NoIgnore",
6902 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006903 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006904 Bugs: ProtocolBugs{
6905 SendHelloRequestBeforeEveryAppDataRecord: true,
6906 },
6907 },
6908 shouldFail: true,
6909 expectedError: ":NO_RENEGOTIATION:",
6910 })
6911 testCases = append(testCases, testCase{
6912 name: "Renegotiate-Client-Ignore",
6913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006914 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006915 Bugs: ProtocolBugs{
6916 SendHelloRequestBeforeEveryAppDataRecord: true,
6917 },
6918 },
6919 flags: []string{
6920 "-renegotiate-ignore",
6921 "-expect-total-renegotiations", "0",
6922 },
6923 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006924
David Benjamin34941c02016-10-08 11:45:31 -04006925 // Renegotiation is not allowed at SSL 3.0.
6926 testCases = append(testCases, testCase{
6927 name: "Renegotiate-Client-SSL3",
6928 config: Config{
6929 MaxVersion: VersionSSL30,
6930 },
6931 renegotiate: 1,
6932 flags: []string{
6933 "-renegotiate-freely",
6934 "-expect-total-renegotiations", "1",
6935 },
6936 shouldFail: true,
6937 expectedError: ":NO_RENEGOTIATION:",
6938 expectedLocalError: "remote error: no renegotiation",
6939 })
6940
David Benjamina1eaba12017-01-01 23:19:22 -05006941 // Renegotiation is not allowed when there is an unfinished write.
6942 testCases = append(testCases, testCase{
6943 name: "Renegotiate-Client-UnfinishedWrite",
6944 config: Config{
6945 MaxVersion: VersionTLS12,
6946 },
David Benjaminbbba9392017-04-06 12:54:12 -04006947 renegotiate: 1,
6948 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006949 flags: []string{
6950 "-async",
6951 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006952 },
6953 shouldFail: true,
6954 expectedError: ":NO_RENEGOTIATION:",
6955 // We do not successfully send the no_renegotiation alert in
6956 // this case. https://crbug.com/boringssl/130
6957 })
6958
David Benjamin07ab5d42017-02-09 20:11:41 -05006959 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006960 testCases = append(testCases, testCase{
6961 name: "StrayHelloRequest",
6962 config: Config{
6963 MaxVersion: VersionTLS12,
6964 Bugs: ProtocolBugs{
6965 SendHelloRequestBeforeEveryHandshakeMessage: true,
6966 },
6967 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006968 shouldFail: true,
6969 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006970 })
6971 testCases = append(testCases, testCase{
6972 name: "StrayHelloRequest-Packed",
6973 config: Config{
6974 MaxVersion: VersionTLS12,
6975 Bugs: ProtocolBugs{
6976 PackHandshakeFlight: true,
6977 SendHelloRequestBeforeEveryHandshakeMessage: true,
6978 },
6979 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006980 shouldFail: true,
6981 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006982 })
6983
David Benjamin12d2c482016-07-24 10:56:51 -04006984 // Test renegotiation works if HelloRequest and server Finished come in
6985 // the same record.
6986 testCases = append(testCases, testCase{
6987 name: "Renegotiate-Client-Packed",
6988 config: Config{
6989 MaxVersion: VersionTLS12,
6990 Bugs: ProtocolBugs{
6991 PackHandshakeFlight: true,
6992 PackHelloRequestWithFinished: true,
6993 },
6994 },
6995 renegotiate: 1,
6996 flags: []string{
6997 "-renegotiate-freely",
6998 "-expect-total-renegotiations", "1",
6999 },
7000 })
7001
David Benjamin397c8e62016-07-08 14:14:36 -07007002 // Renegotiation is forbidden in TLS 1.3.
7003 testCases = append(testCases, testCase{
7004 name: "Renegotiate-Client-TLS13",
7005 config: Config{
7006 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007007 Bugs: ProtocolBugs{
7008 SendHelloRequestBeforeEveryAppDataRecord: true,
7009 },
David Benjamin397c8e62016-07-08 14:14:36 -07007010 },
David Benjamin397c8e62016-07-08 14:14:36 -07007011 flags: []string{
7012 "-renegotiate-freely",
7013 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007014 shouldFail: true,
7015 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007016 })
7017
7018 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7019 testCases = append(testCases, testCase{
7020 name: "StrayHelloRequest-TLS13",
7021 config: Config{
7022 MaxVersion: VersionTLS13,
7023 Bugs: ProtocolBugs{
7024 SendHelloRequestBeforeEveryHandshakeMessage: true,
7025 },
7026 },
7027 shouldFail: true,
7028 expectedError: ":UNEXPECTED_MESSAGE:",
7029 })
David Benjamind2610042017-01-03 10:49:28 -05007030
7031 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7032 // always reads as supporting it, regardless of whether it was
7033 // negotiated.
7034 testCases = append(testCases, testCase{
7035 name: "AlwaysReportRenegotiationInfo-TLS13",
7036 config: Config{
7037 MaxVersion: VersionTLS13,
7038 Bugs: ProtocolBugs{
7039 NoRenegotiationInfo: true,
7040 },
7041 },
7042 flags: []string{
7043 "-expect-secure-renegotiation",
7044 },
7045 })
David Benjamina58baaf2017-02-28 20:54:28 -05007046
7047 // Certificates may not change on renegotiation.
7048 testCases = append(testCases, testCase{
7049 name: "Renegotiation-CertificateChange",
7050 config: Config{
7051 MaxVersion: VersionTLS12,
7052 Certificates: []Certificate{rsaCertificate},
7053 Bugs: ProtocolBugs{
7054 RenegotiationCertificate: &rsaChainCertificate,
7055 },
7056 },
7057 renegotiate: 1,
7058 flags: []string{"-renegotiate-freely"},
7059 shouldFail: true,
7060 expectedError: ":SERVER_CERT_CHANGED:",
7061 })
7062 testCases = append(testCases, testCase{
7063 name: "Renegotiation-CertificateChange-2",
7064 config: Config{
7065 MaxVersion: VersionTLS12,
7066 Certificates: []Certificate{rsaCertificate},
7067 Bugs: ProtocolBugs{
7068 RenegotiationCertificate: &rsa1024Certificate,
7069 },
7070 },
7071 renegotiate: 1,
7072 flags: []string{"-renegotiate-freely"},
7073 shouldFail: true,
7074 expectedError: ":SERVER_CERT_CHANGED:",
7075 })
David Benjaminbbf42462017-03-14 21:27:10 -04007076
7077 // We do not negotiate ALPN after the initial handshake. This is
7078 // error-prone and only risks bugs in consumers.
7079 testCases = append(testCases, testCase{
7080 testType: clientTest,
7081 name: "Renegotiation-ForbidALPN",
7082 config: Config{
7083 MaxVersion: VersionTLS12,
7084 Bugs: ProtocolBugs{
7085 // Forcibly negotiate ALPN on both initial and
7086 // renegotiation handshakes. The test stack will
7087 // internally check the client does not offer
7088 // it.
7089 SendALPN: "foo",
7090 },
7091 },
7092 flags: []string{
7093 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7094 "-expect-alpn", "foo",
7095 "-renegotiate-freely",
7096 },
7097 renegotiate: 1,
7098 shouldFail: true,
7099 expectedError: ":UNEXPECTED_EXTENSION:",
7100 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007101}
7102
David Benjamin5e961c12014-11-07 01:48:35 -05007103func addDTLSReplayTests() {
7104 // Test that sequence number replays are detected.
7105 testCases = append(testCases, testCase{
7106 protocol: dtls,
7107 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007108 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007109 replayWrites: true,
7110 })
7111
David Benjamin8e6db492015-07-25 18:29:23 -04007112 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007113 // than the retransmit window.
7114 testCases = append(testCases, testCase{
7115 protocol: dtls,
7116 name: "DTLS-Replay-LargeGaps",
7117 config: Config{
7118 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007119 SequenceNumberMapping: func(in uint64) uint64 {
7120 return in * 127
7121 },
David Benjamin5e961c12014-11-07 01:48:35 -05007122 },
7123 },
David Benjamin8e6db492015-07-25 18:29:23 -04007124 messageCount: 200,
7125 replayWrites: true,
7126 })
7127
7128 // Test the incoming sequence number changing non-monotonically.
7129 testCases = append(testCases, testCase{
7130 protocol: dtls,
7131 name: "DTLS-Replay-NonMonotonic",
7132 config: Config{
7133 Bugs: ProtocolBugs{
7134 SequenceNumberMapping: func(in uint64) uint64 {
7135 return in ^ 31
7136 },
7137 },
7138 },
7139 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007140 replayWrites: true,
7141 })
7142}
7143
Nick Harper60edffd2016-06-21 15:19:24 -07007144var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007145 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007146 id signatureAlgorithm
7147 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007148}{
Nick Harper60edffd2016-06-21 15:19:24 -07007149 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7150 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7151 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7152 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007153 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007154 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7155 // hash function doesn't have to match the curve and so the same
7156 // signature algorithm works with P-224.
7157 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007158 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7159 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7160 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007161 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7162 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7163 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007164 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007165 // Tests for key types prior to TLS 1.2.
7166 {"RSA", 0, testCertRSA},
7167 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007168}
7169
Nick Harper60edffd2016-06-21 15:19:24 -07007170const fakeSigAlg1 signatureAlgorithm = 0x2a01
7171const fakeSigAlg2 signatureAlgorithm = 0xff01
7172
7173func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007174 // Not all ciphers involve a signature. Advertise a list which gives all
7175 // versions a signing cipher.
7176 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007177 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007178 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7179 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7180 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7181 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007182 }
David Benjamin5208fd42016-07-13 21:43:25 -04007183
David Benjaminca3d5452016-07-14 12:51:01 -04007184 var allAlgorithms []signatureAlgorithm
7185 for _, alg := range testSignatureAlgorithms {
7186 if alg.id != 0 {
7187 allAlgorithms = append(allAlgorithms, alg.id)
7188 }
7189 }
7190
Nick Harper60edffd2016-06-21 15:19:24 -07007191 // Make sure each signature algorithm works. Include some fake values in
7192 // the list and ensure they're ignored.
7193 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007194 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007195 if (ver.version < VersionTLS12) != (alg.id == 0) {
7196 continue
7197 }
7198
7199 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7200 // or remove it in C.
7201 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007202 continue
7203 }
Nick Harper60edffd2016-06-21 15:19:24 -07007204
David Benjamin3ef76972016-10-17 17:59:54 -04007205 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007206 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007207 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007208 shouldSignFail = true
7209 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007210 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007211 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007212 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7213 shouldSignFail = true
7214 shouldVerifyFail = true
7215 }
7216 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7217 // the curve has to match the hash size.
7218 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007219 shouldSignFail = true
7220 shouldVerifyFail = true
7221 }
7222
7223 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7224 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7225 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007226 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007227
7228 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007229 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007230 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007231 }
7232 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007233 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007234 }
David Benjamin000800a2014-11-14 01:43:59 -05007235
David Benjamin1fb125c2016-07-08 18:52:12 -07007236 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007237
David Benjamin7a41d372016-07-09 11:21:54 -07007238 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007239 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007240 config: Config{
7241 MaxVersion: ver.version,
7242 ClientAuth: RequireAnyClientCert,
7243 VerifySignatureAlgorithms: []signatureAlgorithm{
7244 fakeSigAlg1,
7245 alg.id,
7246 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007247 },
David Benjamin7a41d372016-07-09 11:21:54 -07007248 },
7249 flags: []string{
7250 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7251 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7252 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007253 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007254 },
David Benjamin3ef76972016-10-17 17:59:54 -04007255 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007256 expectedError: signError,
7257 expectedPeerSignatureAlgorithm: alg.id,
7258 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007259
David Benjamin7a41d372016-07-09 11:21:54 -07007260 testCases = append(testCases, testCase{
7261 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007262 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007263 config: Config{
7264 MaxVersion: ver.version,
7265 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7266 SignSignatureAlgorithms: []signatureAlgorithm{
7267 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007268 },
David Benjamin7a41d372016-07-09 11:21:54 -07007269 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007270 SkipECDSACurveCheck: shouldVerifyFail,
7271 IgnoreSignatureVersionChecks: shouldVerifyFail,
7272 // Some signature algorithms may not be advertised.
7273 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007274 },
David Benjamin7a41d372016-07-09 11:21:54 -07007275 },
7276 flags: []string{
7277 "-require-any-client-certificate",
7278 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7279 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007280 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007281 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007282 // Resume the session to assert the peer signature
7283 // algorithm is reported on both handshakes.
7284 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007285 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007286 expectedError: verifyError,
7287 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007288
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007289 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007290 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007291 testCases = append(testCases, testCase{
7292 testType: serverTest,
7293 name: "ServerAuth-Sign" + suffix,
7294 config: Config{
7295 MaxVersion: ver.version,
7296 CipherSuites: signingCiphers,
7297 VerifySignatureAlgorithms: []signatureAlgorithm{
7298 fakeSigAlg1,
7299 alg.id,
7300 fakeSigAlg2,
7301 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007302 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007303 flags: []string{
7304 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7305 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7306 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007307 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007308 },
7309 shouldFail: shouldSignFail,
7310 expectedError: signError,
7311 expectedPeerSignatureAlgorithm: alg.id,
7312 })
7313 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007314
7315 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007316 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007317 config: Config{
7318 MaxVersion: ver.version,
7319 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007320 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007321 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007322 alg.id,
7323 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007324 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007325 SkipECDSACurveCheck: shouldVerifyFail,
7326 IgnoreSignatureVersionChecks: shouldVerifyFail,
7327 // Some signature algorithms may not be advertised.
7328 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007329 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007330 },
7331 flags: []string{
7332 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7333 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007334 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007335 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007336 // Resume the session to assert the peer signature
7337 // algorithm is reported on both handshakes.
7338 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007339 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007340 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007341 })
David Benjamin5208fd42016-07-13 21:43:25 -04007342
David Benjamin3ef76972016-10-17 17:59:54 -04007343 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007344 testCases = append(testCases, testCase{
7345 testType: serverTest,
7346 name: "ClientAuth-InvalidSignature" + suffix,
7347 config: Config{
7348 MaxVersion: ver.version,
7349 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7350 SignSignatureAlgorithms: []signatureAlgorithm{
7351 alg.id,
7352 },
7353 Bugs: ProtocolBugs{
7354 InvalidSignature: true,
7355 },
7356 },
7357 flags: []string{
7358 "-require-any-client-certificate",
7359 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007360 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007361 },
7362 shouldFail: true,
7363 expectedError: ":BAD_SIGNATURE:",
7364 })
7365
7366 testCases = append(testCases, testCase{
7367 name: "ServerAuth-InvalidSignature" + suffix,
7368 config: Config{
7369 MaxVersion: ver.version,
7370 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7371 CipherSuites: signingCiphers,
7372 SignSignatureAlgorithms: []signatureAlgorithm{
7373 alg.id,
7374 },
7375 Bugs: ProtocolBugs{
7376 InvalidSignature: true,
7377 },
7378 },
David Benjamin69522112017-03-28 15:38:29 -05007379 flags: []string{
7380 "-enable-all-curves",
7381 "-enable-ed25519",
7382 },
David Benjamin5208fd42016-07-13 21:43:25 -04007383 shouldFail: true,
7384 expectedError: ":BAD_SIGNATURE:",
7385 })
7386 }
David Benjaminca3d5452016-07-14 12:51:01 -04007387
David Benjamin3ef76972016-10-17 17:59:54 -04007388 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007389 testCases = append(testCases, testCase{
7390 name: "ClientAuth-Sign-Negotiate" + suffix,
7391 config: Config{
7392 MaxVersion: ver.version,
7393 ClientAuth: RequireAnyClientCert,
7394 VerifySignatureAlgorithms: allAlgorithms,
7395 },
7396 flags: []string{
7397 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7398 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7399 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007400 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007401 "-signing-prefs", strconv.Itoa(int(alg.id)),
7402 },
7403 expectedPeerSignatureAlgorithm: alg.id,
7404 })
7405
7406 testCases = append(testCases, testCase{
7407 testType: serverTest,
7408 name: "ServerAuth-Sign-Negotiate" + suffix,
7409 config: Config{
7410 MaxVersion: ver.version,
7411 CipherSuites: signingCiphers,
7412 VerifySignatureAlgorithms: allAlgorithms,
7413 },
7414 flags: []string{
7415 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7416 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7417 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007418 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007419 "-signing-prefs", strconv.Itoa(int(alg.id)),
7420 },
7421 expectedPeerSignatureAlgorithm: alg.id,
7422 })
7423 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007424 }
David Benjamin000800a2014-11-14 01:43:59 -05007425 }
7426
Nick Harper60edffd2016-06-21 15:19:24 -07007427 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007428 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007429 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007430 config: Config{
7431 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007432 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007433 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007434 signatureECDSAWithP521AndSHA512,
7435 signatureRSAPKCS1WithSHA384,
7436 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007437 },
7438 },
7439 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007440 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7441 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007442 },
Nick Harper60edffd2016-06-21 15:19:24 -07007443 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007444 })
7445
7446 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007447 name: "ClientAuth-SignatureType-TLS13",
7448 config: Config{
7449 ClientAuth: RequireAnyClientCert,
7450 MaxVersion: VersionTLS13,
7451 VerifySignatureAlgorithms: []signatureAlgorithm{
7452 signatureECDSAWithP521AndSHA512,
7453 signatureRSAPKCS1WithSHA384,
7454 signatureRSAPSSWithSHA384,
7455 signatureECDSAWithSHA1,
7456 },
7457 },
7458 flags: []string{
7459 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7460 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7461 },
7462 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7463 })
7464
7465 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007466 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007467 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007468 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007469 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007470 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007471 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007472 signatureECDSAWithP521AndSHA512,
7473 signatureRSAPKCS1WithSHA384,
7474 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007475 },
7476 },
Nick Harper60edffd2016-06-21 15:19:24 -07007477 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007478 })
7479
Steven Valdez143e8b32016-07-11 13:19:03 -04007480 testCases = append(testCases, testCase{
7481 testType: serverTest,
7482 name: "ServerAuth-SignatureType-TLS13",
7483 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007484 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007485 VerifySignatureAlgorithms: []signatureAlgorithm{
7486 signatureECDSAWithP521AndSHA512,
7487 signatureRSAPKCS1WithSHA384,
7488 signatureRSAPSSWithSHA384,
7489 signatureECDSAWithSHA1,
7490 },
7491 },
7492 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7493 })
7494
David Benjamina95e9f32016-07-08 16:28:04 -07007495 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007496 testCases = append(testCases, testCase{
7497 testType: serverTest,
7498 name: "Verify-ClientAuth-SignatureType",
7499 config: Config{
7500 MaxVersion: VersionTLS12,
7501 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007502 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007503 signatureRSAPKCS1WithSHA256,
7504 },
7505 Bugs: ProtocolBugs{
7506 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7507 },
7508 },
7509 flags: []string{
7510 "-require-any-client-certificate",
7511 },
7512 shouldFail: true,
7513 expectedError: ":WRONG_SIGNATURE_TYPE:",
7514 })
7515
7516 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007517 testType: serverTest,
7518 name: "Verify-ClientAuth-SignatureType-TLS13",
7519 config: Config{
7520 MaxVersion: VersionTLS13,
7521 Certificates: []Certificate{rsaCertificate},
7522 SignSignatureAlgorithms: []signatureAlgorithm{
7523 signatureRSAPSSWithSHA256,
7524 },
7525 Bugs: ProtocolBugs{
7526 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7527 },
7528 },
7529 flags: []string{
7530 "-require-any-client-certificate",
7531 },
7532 shouldFail: true,
7533 expectedError: ":WRONG_SIGNATURE_TYPE:",
7534 })
7535
7536 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007537 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007538 config: Config{
7539 MaxVersion: VersionTLS12,
7540 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007541 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007542 signatureRSAPKCS1WithSHA256,
7543 },
7544 Bugs: ProtocolBugs{
7545 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7546 },
7547 },
7548 shouldFail: true,
7549 expectedError: ":WRONG_SIGNATURE_TYPE:",
7550 })
7551
Steven Valdez143e8b32016-07-11 13:19:03 -04007552 testCases = append(testCases, testCase{
7553 name: "Verify-ServerAuth-SignatureType-TLS13",
7554 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007555 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007556 SignSignatureAlgorithms: []signatureAlgorithm{
7557 signatureRSAPSSWithSHA256,
7558 },
7559 Bugs: ProtocolBugs{
7560 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7561 },
7562 },
7563 shouldFail: true,
7564 expectedError: ":WRONG_SIGNATURE_TYPE:",
7565 })
7566
David Benjamin51dd7d62016-07-08 16:07:01 -07007567 // Test that, if the list is missing, the peer falls back to SHA-1 in
7568 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007569 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007570 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007572 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007573 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007574 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007575 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007576 },
7577 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007578 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007579 },
7580 },
7581 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007582 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7583 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007584 },
7585 })
7586
7587 testCases = append(testCases, testCase{
7588 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007589 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007590 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007591 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007592 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007593 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007594 },
7595 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007596 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007597 },
7598 },
David Benjaminee32bea2016-08-17 13:36:44 -04007599 flags: []string{
7600 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7601 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7602 },
7603 })
7604
7605 testCases = append(testCases, testCase{
7606 name: "ClientAuth-SHA1-Fallback-ECDSA",
7607 config: Config{
7608 MaxVersion: VersionTLS12,
7609 ClientAuth: RequireAnyClientCert,
7610 VerifySignatureAlgorithms: []signatureAlgorithm{
7611 signatureECDSAWithSHA1,
7612 },
7613 Bugs: ProtocolBugs{
7614 NoSignatureAlgorithms: true,
7615 },
7616 },
7617 flags: []string{
7618 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7619 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7620 },
7621 })
7622
7623 testCases = append(testCases, testCase{
7624 testType: serverTest,
7625 name: "ServerAuth-SHA1-Fallback-ECDSA",
7626 config: Config{
7627 MaxVersion: VersionTLS12,
7628 VerifySignatureAlgorithms: []signatureAlgorithm{
7629 signatureECDSAWithSHA1,
7630 },
7631 Bugs: ProtocolBugs{
7632 NoSignatureAlgorithms: true,
7633 },
7634 },
7635 flags: []string{
7636 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7637 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7638 },
David Benjamin000800a2014-11-14 01:43:59 -05007639 })
David Benjamin72dc7832015-03-16 17:49:43 -04007640
David Benjamin51dd7d62016-07-08 16:07:01 -07007641 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007642 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007643 config: Config{
7644 MaxVersion: VersionTLS13,
7645 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007646 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007647 signatureRSAPKCS1WithSHA1,
7648 },
7649 Bugs: ProtocolBugs{
7650 NoSignatureAlgorithms: true,
7651 },
7652 },
7653 flags: []string{
7654 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7655 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7656 },
David Benjamin48901652016-08-01 12:12:47 -04007657 shouldFail: true,
7658 // An empty CertificateRequest signature algorithm list is a
7659 // syntax error in TLS 1.3.
7660 expectedError: ":DECODE_ERROR:",
7661 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007662 })
7663
7664 testCases = append(testCases, testCase{
7665 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007666 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007667 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007668 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007669 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007670 signatureRSAPKCS1WithSHA1,
7671 },
7672 Bugs: ProtocolBugs{
7673 NoSignatureAlgorithms: true,
7674 },
7675 },
7676 shouldFail: true,
7677 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7678 })
7679
David Benjaminb62d2872016-07-18 14:55:02 +02007680 // Test that hash preferences are enforced. BoringSSL does not implement
7681 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007682 testCases = append(testCases, testCase{
7683 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007684 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007685 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007686 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007687 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007688 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007689 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007690 },
7691 Bugs: ProtocolBugs{
7692 IgnorePeerSignatureAlgorithmPreferences: true,
7693 },
7694 },
7695 flags: []string{"-require-any-client-certificate"},
7696 shouldFail: true,
7697 expectedError: ":WRONG_SIGNATURE_TYPE:",
7698 })
7699
7700 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007701 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007702 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007703 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007704 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007705 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007706 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007707 },
7708 Bugs: ProtocolBugs{
7709 IgnorePeerSignatureAlgorithmPreferences: true,
7710 },
7711 },
7712 shouldFail: true,
7713 expectedError: ":WRONG_SIGNATURE_TYPE:",
7714 })
David Benjaminb62d2872016-07-18 14:55:02 +02007715 testCases = append(testCases, testCase{
7716 testType: serverTest,
7717 name: "ClientAuth-Enforced-TLS13",
7718 config: Config{
7719 MaxVersion: VersionTLS13,
7720 Certificates: []Certificate{rsaCertificate},
7721 SignSignatureAlgorithms: []signatureAlgorithm{
7722 signatureRSAPKCS1WithMD5,
7723 },
7724 Bugs: ProtocolBugs{
7725 IgnorePeerSignatureAlgorithmPreferences: true,
7726 IgnoreSignatureVersionChecks: true,
7727 },
7728 },
7729 flags: []string{"-require-any-client-certificate"},
7730 shouldFail: true,
7731 expectedError: ":WRONG_SIGNATURE_TYPE:",
7732 })
7733
7734 testCases = append(testCases, testCase{
7735 name: "ServerAuth-Enforced-TLS13",
7736 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007737 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007738 SignSignatureAlgorithms: []signatureAlgorithm{
7739 signatureRSAPKCS1WithMD5,
7740 },
7741 Bugs: ProtocolBugs{
7742 IgnorePeerSignatureAlgorithmPreferences: true,
7743 IgnoreSignatureVersionChecks: true,
7744 },
7745 },
7746 shouldFail: true,
7747 expectedError: ":WRONG_SIGNATURE_TYPE:",
7748 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007749
7750 // Test that the agreed upon digest respects the client preferences and
7751 // the server digests.
7752 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007753 name: "NoCommonAlgorithms-Digests",
7754 config: Config{
7755 MaxVersion: VersionTLS12,
7756 ClientAuth: RequireAnyClientCert,
7757 VerifySignatureAlgorithms: []signatureAlgorithm{
7758 signatureRSAPKCS1WithSHA512,
7759 signatureRSAPKCS1WithSHA1,
7760 },
7761 },
7762 flags: []string{
7763 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7764 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7765 "-digest-prefs", "SHA256",
7766 },
7767 shouldFail: true,
7768 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7769 })
7770 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007771 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007773 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007774 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007775 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007776 signatureRSAPKCS1WithSHA512,
7777 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007778 },
7779 },
7780 flags: []string{
7781 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7782 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007783 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007784 },
David Benjaminca3d5452016-07-14 12:51:01 -04007785 shouldFail: true,
7786 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7787 })
7788 testCases = append(testCases, testCase{
7789 name: "NoCommonAlgorithms-TLS13",
7790 config: Config{
7791 MaxVersion: VersionTLS13,
7792 ClientAuth: RequireAnyClientCert,
7793 VerifySignatureAlgorithms: []signatureAlgorithm{
7794 signatureRSAPSSWithSHA512,
7795 signatureRSAPSSWithSHA384,
7796 },
7797 },
7798 flags: []string{
7799 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7800 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7801 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7802 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007803 shouldFail: true,
7804 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007805 })
7806 testCases = append(testCases, testCase{
7807 name: "Agree-Digest-SHA256",
7808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007809 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007810 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007811 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007812 signatureRSAPKCS1WithSHA1,
7813 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007814 },
7815 },
7816 flags: []string{
7817 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7818 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007819 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007820 },
Nick Harper60edffd2016-06-21 15:19:24 -07007821 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007822 })
7823 testCases = append(testCases, testCase{
7824 name: "Agree-Digest-SHA1",
7825 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007826 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007827 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007828 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007829 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007830 },
7831 },
7832 flags: []string{
7833 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7834 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007835 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007836 },
Nick Harper60edffd2016-06-21 15:19:24 -07007837 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007838 })
7839 testCases = append(testCases, testCase{
7840 name: "Agree-Digest-Default",
7841 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007842 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007843 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007844 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007845 signatureRSAPKCS1WithSHA256,
7846 signatureECDSAWithP256AndSHA256,
7847 signatureRSAPKCS1WithSHA1,
7848 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007849 },
7850 },
7851 flags: []string{
7852 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7853 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7854 },
Nick Harper60edffd2016-06-21 15:19:24 -07007855 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007856 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007857
David Benjaminca3d5452016-07-14 12:51:01 -04007858 // Test that the signing preference list may include extra algorithms
7859 // without negotiation problems.
7860 testCases = append(testCases, testCase{
7861 testType: serverTest,
7862 name: "FilterExtraAlgorithms",
7863 config: Config{
7864 MaxVersion: VersionTLS12,
7865 VerifySignatureAlgorithms: []signatureAlgorithm{
7866 signatureRSAPKCS1WithSHA256,
7867 },
7868 },
7869 flags: []string{
7870 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7871 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7872 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7873 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7874 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7875 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7876 },
7877 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7878 })
7879
David Benjamin4c3ddf72016-06-29 18:13:53 -04007880 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7881 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007882 testCases = append(testCases, testCase{
7883 name: "CheckLeafCurve",
7884 config: Config{
7885 MaxVersion: VersionTLS12,
7886 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007887 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007888 },
7889 flags: []string{"-p384-only"},
7890 shouldFail: true,
7891 expectedError: ":BAD_ECC_CERT:",
7892 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007893
7894 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7895 testCases = append(testCases, testCase{
7896 name: "CheckLeafCurve-TLS13",
7897 config: Config{
7898 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007899 Certificates: []Certificate{ecdsaP256Certificate},
7900 },
7901 flags: []string{"-p384-only"},
7902 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007903
7904 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7905 testCases = append(testCases, testCase{
7906 name: "ECDSACurveMismatch-Verify-TLS12",
7907 config: Config{
7908 MaxVersion: VersionTLS12,
7909 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7910 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007911 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007912 signatureECDSAWithP384AndSHA384,
7913 },
7914 },
7915 })
7916
7917 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7918 testCases = append(testCases, testCase{
7919 name: "ECDSACurveMismatch-Verify-TLS13",
7920 config: Config{
7921 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007922 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007923 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007924 signatureECDSAWithP384AndSHA384,
7925 },
7926 Bugs: ProtocolBugs{
7927 SkipECDSACurveCheck: true,
7928 },
7929 },
7930 shouldFail: true,
7931 expectedError: ":WRONG_SIGNATURE_TYPE:",
7932 })
7933
7934 // Signature algorithm selection in TLS 1.3 should take the curve into
7935 // account.
7936 testCases = append(testCases, testCase{
7937 testType: serverTest,
7938 name: "ECDSACurveMismatch-Sign-TLS13",
7939 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007940 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007941 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007942 signatureECDSAWithP384AndSHA384,
7943 signatureECDSAWithP256AndSHA256,
7944 },
7945 },
7946 flags: []string{
7947 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7948 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7949 },
7950 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7951 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007952
7953 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7954 // server does not attempt to sign in that case.
7955 testCases = append(testCases, testCase{
7956 testType: serverTest,
7957 name: "RSA-PSS-Large",
7958 config: Config{
7959 MaxVersion: VersionTLS13,
7960 VerifySignatureAlgorithms: []signatureAlgorithm{
7961 signatureRSAPSSWithSHA512,
7962 },
7963 },
7964 flags: []string{
7965 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7966 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7967 },
7968 shouldFail: true,
7969 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7970 })
David Benjamin57e929f2016-08-30 00:30:38 -04007971
7972 // Test that RSA-PSS is enabled by default for TLS 1.2.
7973 testCases = append(testCases, testCase{
7974 testType: clientTest,
7975 name: "RSA-PSS-Default-Verify",
7976 config: Config{
7977 MaxVersion: VersionTLS12,
7978 SignSignatureAlgorithms: []signatureAlgorithm{
7979 signatureRSAPSSWithSHA256,
7980 },
7981 },
7982 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7983 })
7984
7985 testCases = append(testCases, testCase{
7986 testType: serverTest,
7987 name: "RSA-PSS-Default-Sign",
7988 config: Config{
7989 MaxVersion: VersionTLS12,
7990 VerifySignatureAlgorithms: []signatureAlgorithm{
7991 signatureRSAPSSWithSHA256,
7992 },
7993 },
7994 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7995 })
David Benjamin69522112017-03-28 15:38:29 -05007996
7997 // TLS 1.1 and below has no way to advertise support for or negotiate
7998 // Ed25519's signature algorithm.
7999 testCases = append(testCases, testCase{
8000 testType: clientTest,
8001 name: "NoEd25519-TLS11-ServerAuth-Verify",
8002 config: Config{
8003 MaxVersion: VersionTLS11,
8004 Certificates: []Certificate{ed25519Certificate},
8005 Bugs: ProtocolBugs{
8006 // Sign with Ed25519 even though it is TLS 1.1.
8007 UseLegacySigningAlgorithm: signatureEd25519,
8008 },
8009 },
8010 flags: []string{"-enable-ed25519"},
8011 shouldFail: true,
8012 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8013 })
8014 testCases = append(testCases, testCase{
8015 testType: serverTest,
8016 name: "NoEd25519-TLS11-ServerAuth-Sign",
8017 config: Config{
8018 MaxVersion: VersionTLS11,
8019 },
8020 flags: []string{
8021 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8022 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8023 },
8024 shouldFail: true,
8025 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8026 })
8027 testCases = append(testCases, testCase{
8028 testType: serverTest,
8029 name: "NoEd25519-TLS11-ClientAuth-Verify",
8030 config: Config{
8031 MaxVersion: VersionTLS11,
8032 Certificates: []Certificate{ed25519Certificate},
8033 Bugs: ProtocolBugs{
8034 // Sign with Ed25519 even though it is TLS 1.1.
8035 UseLegacySigningAlgorithm: signatureEd25519,
8036 },
8037 },
8038 flags: []string{
8039 "-enable-ed25519",
8040 "-require-any-client-certificate",
8041 },
8042 shouldFail: true,
8043 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8044 })
8045 testCases = append(testCases, testCase{
8046 testType: clientTest,
8047 name: "NoEd25519-TLS11-ClientAuth-Sign",
8048 config: Config{
8049 MaxVersion: VersionTLS11,
8050 ClientAuth: RequireAnyClientCert,
8051 },
8052 flags: []string{
8053 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8054 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8055 },
8056 shouldFail: true,
8057 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8058 })
8059
8060 // Test Ed25519 is not advertised by default.
8061 testCases = append(testCases, testCase{
8062 testType: clientTest,
8063 name: "Ed25519DefaultDisable-NoAdvertise",
8064 config: Config{
8065 Certificates: []Certificate{ed25519Certificate},
8066 },
8067 shouldFail: true,
8068 expectedLocalError: "tls: no common signature algorithms",
8069 })
8070
8071 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8072 // preferences.
8073 testCases = append(testCases, testCase{
8074 testType: clientTest,
8075 name: "Ed25519DefaultDisable-NoAccept",
8076 config: Config{
8077 Certificates: []Certificate{ed25519Certificate},
8078 Bugs: ProtocolBugs{
8079 IgnorePeerSignatureAlgorithmPreferences: true,
8080 },
8081 },
8082 shouldFail: true,
8083 expectedLocalError: "remote error: illegal parameter",
8084 expectedError: ":WRONG_SIGNATURE_TYPE:",
8085 })
David Benjamin71c21b42017-04-14 17:05:40 -04008086
8087 // Test that configuring verify preferences changes what the client
8088 // advertises.
8089 testCases = append(testCases, testCase{
8090 name: "VerifyPreferences-Advertised",
8091 config: Config{
8092 Certificates: []Certificate{rsaCertificate},
8093 SignSignatureAlgorithms: []signatureAlgorithm{
8094 signatureRSAPSSWithSHA256,
8095 signatureRSAPSSWithSHA384,
8096 signatureRSAPSSWithSHA512,
8097 },
8098 },
8099 flags: []string{
8100 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8101 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8102 },
8103 })
8104
8105 // Test that the client advertises a set which the runner can find
8106 // nothing in common with.
8107 testCases = append(testCases, testCase{
8108 name: "VerifyPreferences-NoCommonAlgorithms",
8109 config: Config{
8110 Certificates: []Certificate{rsaCertificate},
8111 SignSignatureAlgorithms: []signatureAlgorithm{
8112 signatureRSAPSSWithSHA256,
8113 signatureRSAPSSWithSHA512,
8114 },
8115 },
8116 flags: []string{
8117 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8118 },
8119 shouldFail: true,
8120 expectedLocalError: "tls: no common signature algorithms",
8121 })
8122
8123 // Test that the client enforces its preferences when configured.
8124 testCases = append(testCases, testCase{
8125 name: "VerifyPreferences-Enforced",
8126 config: Config{
8127 Certificates: []Certificate{rsaCertificate},
8128 SignSignatureAlgorithms: []signatureAlgorithm{
8129 signatureRSAPSSWithSHA256,
8130 signatureRSAPSSWithSHA512,
8131 },
8132 Bugs: ProtocolBugs{
8133 IgnorePeerSignatureAlgorithmPreferences: true,
8134 },
8135 },
8136 flags: []string{
8137 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8138 },
8139 shouldFail: true,
8140 expectedLocalError: "remote error: illegal parameter",
8141 expectedError: ":WRONG_SIGNATURE_TYPE:",
8142 })
8143
8144 // Test that explicitly configuring Ed25519 is as good as changing the
8145 // boolean toggle.
8146 testCases = append(testCases, testCase{
8147 name: "VerifyPreferences-Ed25519",
8148 config: Config{
8149 Certificates: []Certificate{ed25519Certificate},
8150 },
8151 flags: []string{
8152 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8153 },
8154 })
David Benjamin000800a2014-11-14 01:43:59 -05008155}
8156
David Benjamin83f90402015-01-27 01:09:43 -05008157// timeouts is the retransmit schedule for BoringSSL. It doubles and
8158// caps at 60 seconds. On the 13th timeout, it gives up.
8159var timeouts = []time.Duration{
8160 1 * time.Second,
8161 2 * time.Second,
8162 4 * time.Second,
8163 8 * time.Second,
8164 16 * time.Second,
8165 32 * time.Second,
8166 60 * time.Second,
8167 60 * time.Second,
8168 60 * time.Second,
8169 60 * time.Second,
8170 60 * time.Second,
8171 60 * time.Second,
8172 60 * time.Second,
8173}
8174
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008175// shortTimeouts is an alternate set of timeouts which would occur if the
8176// initial timeout duration was set to 250ms.
8177var shortTimeouts = []time.Duration{
8178 250 * time.Millisecond,
8179 500 * time.Millisecond,
8180 1 * time.Second,
8181 2 * time.Second,
8182 4 * time.Second,
8183 8 * time.Second,
8184 16 * time.Second,
8185 32 * time.Second,
8186 60 * time.Second,
8187 60 * time.Second,
8188 60 * time.Second,
8189 60 * time.Second,
8190 60 * time.Second,
8191}
8192
David Benjamin83f90402015-01-27 01:09:43 -05008193func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008194 // These tests work by coordinating some behavior on both the shim and
8195 // the runner.
8196 //
8197 // TimeoutSchedule configures the runner to send a series of timeout
8198 // opcodes to the shim (see packetAdaptor) immediately before reading
8199 // each peer handshake flight N. The timeout opcode both simulates a
8200 // timeout in the shim and acts as a synchronization point to help the
8201 // runner bracket each handshake flight.
8202 //
8203 // We assume the shim does not read from the channel eagerly. It must
8204 // first wait until it has sent flight N and is ready to receive
8205 // handshake flight N+1. At this point, it will process the timeout
8206 // opcode. It must then immediately respond with a timeout ACK and act
8207 // as if the shim was idle for the specified amount of time.
8208 //
8209 // The runner then drops all packets received before the ACK and
8210 // continues waiting for flight N. This ordering results in one attempt
8211 // at sending flight N to be dropped. For the test to complete, the
8212 // shim must send flight N again, testing that the shim implements DTLS
8213 // retransmit on a timeout.
8214
Steven Valdez143e8b32016-07-11 13:19:03 -04008215 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008216 // likely be more epochs to cross and the final message's retransmit may
8217 // be more complex.
8218
David Benjamin11c82892017-02-23 20:40:31 -05008219 // Test that this is indeed the timeout schedule. Stress all
8220 // four patterns of handshake.
8221 for i := 1; i < len(timeouts); i++ {
8222 number := strconv.Itoa(i)
8223 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008224 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008225 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008227 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008228 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008229 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008230 },
8231 },
8232 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008233 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008234 })
David Benjamin11c82892017-02-23 20:40:31 -05008235 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008236 protocol: dtls,
8237 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008238 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008240 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008241 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008242 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008243 },
8244 },
8245 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008246 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008247 })
8248 }
David Benjamin11c82892017-02-23 20:40:31 -05008249
8250 // Test that exceeding the timeout schedule hits a read
8251 // timeout.
8252 testCases = append(testCases, testCase{
8253 protocol: dtls,
8254 name: "DTLS-Retransmit-Timeout",
8255 config: Config{
8256 MaxVersion: VersionTLS12,
8257 Bugs: ProtocolBugs{
8258 TimeoutSchedule: timeouts,
8259 },
8260 },
8261 resumeSession: true,
8262 flags: []string{"-async"},
8263 shouldFail: true,
8264 expectedError: ":READ_TIMEOUT_EXPIRED:",
8265 })
8266
8267 // Test that timeout handling has a fudge factor, due to API
8268 // problems.
8269 testCases = append(testCases, testCase{
8270 protocol: dtls,
8271 name: "DTLS-Retransmit-Fudge",
8272 config: Config{
8273 MaxVersion: VersionTLS12,
8274 Bugs: ProtocolBugs{
8275 TimeoutSchedule: []time.Duration{
8276 timeouts[0] - 10*time.Millisecond,
8277 },
8278 },
8279 },
8280 resumeSession: true,
8281 flags: []string{"-async"},
8282 })
8283
8284 // Test that the final Finished retransmitting isn't
8285 // duplicated if the peer badly fragments everything.
8286 testCases = append(testCases, testCase{
8287 testType: serverTest,
8288 protocol: dtls,
8289 name: "DTLS-Retransmit-Fragmented",
8290 config: Config{
8291 MaxVersion: VersionTLS12,
8292 Bugs: ProtocolBugs{
8293 TimeoutSchedule: []time.Duration{timeouts[0]},
8294 MaxHandshakeRecordLength: 2,
8295 },
8296 },
8297 flags: []string{"-async"},
8298 })
8299
8300 // Test the timeout schedule when a shorter initial timeout duration is set.
8301 testCases = append(testCases, testCase{
8302 protocol: dtls,
8303 name: "DTLS-Retransmit-Short-Client",
8304 config: Config{
8305 MaxVersion: VersionTLS12,
8306 Bugs: ProtocolBugs{
8307 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8308 },
8309 },
8310 resumeSession: true,
8311 flags: []string{
8312 "-async",
8313 "-initial-timeout-duration-ms", "250",
8314 },
8315 })
8316 testCases = append(testCases, testCase{
8317 protocol: dtls,
8318 testType: serverTest,
8319 name: "DTLS-Retransmit-Short-Server",
8320 config: Config{
8321 MaxVersion: VersionTLS12,
8322 Bugs: ProtocolBugs{
8323 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8324 },
8325 },
8326 resumeSession: true,
8327 flags: []string{
8328 "-async",
8329 "-initial-timeout-duration-ms", "250",
8330 },
8331 })
David Benjamin83f90402015-01-27 01:09:43 -05008332}
8333
David Benjaminc565ebb2015-04-03 04:06:36 -04008334func addExportKeyingMaterialTests() {
8335 for _, vers := range tlsVersions {
8336 if vers.version == VersionSSL30 {
8337 continue
8338 }
8339 testCases = append(testCases, testCase{
8340 name: "ExportKeyingMaterial-" + vers.name,
8341 config: Config{
8342 MaxVersion: vers.version,
8343 },
8344 exportKeyingMaterial: 1024,
8345 exportLabel: "label",
8346 exportContext: "context",
8347 useExportContext: true,
8348 })
8349 testCases = append(testCases, testCase{
8350 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8351 config: Config{
8352 MaxVersion: vers.version,
8353 },
8354 exportKeyingMaterial: 1024,
8355 })
8356 testCases = append(testCases, testCase{
8357 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8358 config: Config{
8359 MaxVersion: vers.version,
8360 },
8361 exportKeyingMaterial: 1024,
8362 useExportContext: true,
8363 })
8364 testCases = append(testCases, testCase{
8365 name: "ExportKeyingMaterial-Small-" + vers.name,
8366 config: Config{
8367 MaxVersion: vers.version,
8368 },
8369 exportKeyingMaterial: 1,
8370 exportLabel: "label",
8371 exportContext: "context",
8372 useExportContext: true,
8373 })
8374 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008375
David Benjaminc565ebb2015-04-03 04:06:36 -04008376 testCases = append(testCases, testCase{
8377 name: "ExportKeyingMaterial-SSL3",
8378 config: Config{
8379 MaxVersion: VersionSSL30,
8380 },
8381 exportKeyingMaterial: 1024,
8382 exportLabel: "label",
8383 exportContext: "context",
8384 useExportContext: true,
8385 shouldFail: true,
8386 expectedError: "failed to export keying material",
8387 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008388
8389 // Exporters work during a False Start.
8390 testCases = append(testCases, testCase{
8391 name: "ExportKeyingMaterial-FalseStart",
8392 config: Config{
8393 MaxVersion: VersionTLS12,
8394 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8395 NextProtos: []string{"foo"},
8396 Bugs: ProtocolBugs{
8397 ExpectFalseStart: true,
8398 },
8399 },
8400 flags: []string{
8401 "-false-start",
8402 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008403 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008404 },
8405 shimWritesFirst: true,
8406 exportKeyingMaterial: 1024,
8407 exportLabel: "label",
8408 exportContext: "context",
8409 useExportContext: true,
8410 })
8411
8412 // Exporters do not work in the middle of a renegotiation. Test this by
8413 // triggering the exporter after every SSL_read call and configuring the
8414 // shim to run asynchronously.
8415 testCases = append(testCases, testCase{
8416 name: "ExportKeyingMaterial-Renegotiate",
8417 config: Config{
8418 MaxVersion: VersionTLS12,
8419 },
8420 renegotiate: 1,
8421 flags: []string{
8422 "-async",
8423 "-use-exporter-between-reads",
8424 "-renegotiate-freely",
8425 "-expect-total-renegotiations", "1",
8426 },
8427 shouldFail: true,
8428 expectedError: "failed to export keying material",
8429 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008430}
8431
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008432func addTLSUniqueTests() {
8433 for _, isClient := range []bool{false, true} {
8434 for _, isResumption := range []bool{false, true} {
8435 for _, hasEMS := range []bool{false, true} {
8436 var suffix string
8437 if isResumption {
8438 suffix = "Resume-"
8439 } else {
8440 suffix = "Full-"
8441 }
8442
8443 if hasEMS {
8444 suffix += "EMS-"
8445 } else {
8446 suffix += "NoEMS-"
8447 }
8448
8449 if isClient {
8450 suffix += "Client"
8451 } else {
8452 suffix += "Server"
8453 }
8454
8455 test := testCase{
8456 name: "TLSUnique-" + suffix,
8457 testTLSUnique: true,
8458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008459 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008460 Bugs: ProtocolBugs{
8461 NoExtendedMasterSecret: !hasEMS,
8462 },
8463 },
8464 }
8465
8466 if isResumption {
8467 test.resumeSession = true
8468 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008469 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008470 Bugs: ProtocolBugs{
8471 NoExtendedMasterSecret: !hasEMS,
8472 },
8473 }
8474 }
8475
8476 if isResumption && !hasEMS {
8477 test.shouldFail = true
8478 test.expectedError = "failed to get tls-unique"
8479 }
8480
8481 testCases = append(testCases, test)
8482 }
8483 }
8484 }
8485}
8486
Adam Langley09505632015-07-30 18:10:13 -07008487func addCustomExtensionTests() {
8488 expectedContents := "custom extension"
8489 emptyString := ""
8490
8491 for _, isClient := range []bool{false, true} {
8492 suffix := "Server"
8493 flag := "-enable-server-custom-extension"
8494 testType := serverTest
8495 if isClient {
8496 suffix = "Client"
8497 flag = "-enable-client-custom-extension"
8498 testType = clientTest
8499 }
8500
8501 testCases = append(testCases, testCase{
8502 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008503 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008505 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008506 Bugs: ProtocolBugs{
8507 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008508 ExpectedCustomExtension: &expectedContents,
8509 },
8510 },
8511 flags: []string{flag},
8512 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008513 testCases = append(testCases, testCase{
8514 testType: testType,
8515 name: "CustomExtensions-" + suffix + "-TLS13",
8516 config: Config{
8517 MaxVersion: VersionTLS13,
8518 Bugs: ProtocolBugs{
8519 CustomExtension: expectedContents,
8520 ExpectedCustomExtension: &expectedContents,
8521 },
8522 },
8523 flags: []string{flag},
8524 })
Adam Langley09505632015-07-30 18:10:13 -07008525
Steven Valdez2a070722017-03-25 20:54:16 -05008526 // 0-RTT is not currently supported with Custom Extensions.
8527 testCases = append(testCases, testCase{
8528 testType: testType,
8529 name: "CustomExtensions-" + suffix + "-EarlyData",
8530 config: Config{
8531 MaxVersion: VersionTLS13,
8532 Bugs: ProtocolBugs{
8533 CustomExtension: expectedContents,
8534 ExpectedCustomExtension: &expectedContents,
8535 },
8536 },
8537 shouldFail: true,
8538 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8539 flags: []string{flag, "-enable-early-data"},
8540 })
8541
Adam Langley09505632015-07-30 18:10:13 -07008542 // If the parse callback fails, the handshake should also fail.
8543 testCases = append(testCases, testCase{
8544 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008545 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008546 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008547 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008548 Bugs: ProtocolBugs{
8549 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008550 ExpectedCustomExtension: &expectedContents,
8551 },
8552 },
David Benjamin399e7c92015-07-30 23:01:27 -04008553 flags: []string{flag},
8554 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008555 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8556 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008557 testCases = append(testCases, testCase{
8558 testType: testType,
8559 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8560 config: Config{
8561 MaxVersion: VersionTLS13,
8562 Bugs: ProtocolBugs{
8563 CustomExtension: expectedContents + "foo",
8564 ExpectedCustomExtension: &expectedContents,
8565 },
8566 },
8567 flags: []string{flag},
8568 shouldFail: true,
8569 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8570 })
Adam Langley09505632015-07-30 18:10:13 -07008571
8572 // If the add callback fails, the handshake should also fail.
8573 testCases = append(testCases, testCase{
8574 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008575 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008576 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008577 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008578 Bugs: ProtocolBugs{
8579 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008580 ExpectedCustomExtension: &expectedContents,
8581 },
8582 },
David Benjamin399e7c92015-07-30 23:01:27 -04008583 flags: []string{flag, "-custom-extension-fail-add"},
8584 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008585 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8586 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008587 testCases = append(testCases, testCase{
8588 testType: testType,
8589 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8590 config: Config{
8591 MaxVersion: VersionTLS13,
8592 Bugs: ProtocolBugs{
8593 CustomExtension: expectedContents,
8594 ExpectedCustomExtension: &expectedContents,
8595 },
8596 },
8597 flags: []string{flag, "-custom-extension-fail-add"},
8598 shouldFail: true,
8599 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8600 })
Adam Langley09505632015-07-30 18:10:13 -07008601
8602 // If the add callback returns zero, no extension should be
8603 // added.
8604 skipCustomExtension := expectedContents
8605 if isClient {
8606 // For the case where the client skips sending the
8607 // custom extension, the server must not “echo” it.
8608 skipCustomExtension = ""
8609 }
8610 testCases = append(testCases, testCase{
8611 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008612 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008613 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008614 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008615 Bugs: ProtocolBugs{
8616 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008617 ExpectedCustomExtension: &emptyString,
8618 },
8619 },
8620 flags: []string{flag, "-custom-extension-skip"},
8621 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008622 testCases = append(testCases, testCase{
8623 testType: testType,
8624 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8625 config: Config{
8626 MaxVersion: VersionTLS13,
8627 Bugs: ProtocolBugs{
8628 CustomExtension: skipCustomExtension,
8629 ExpectedCustomExtension: &emptyString,
8630 },
8631 },
8632 flags: []string{flag, "-custom-extension-skip"},
8633 })
Adam Langley09505632015-07-30 18:10:13 -07008634 }
8635
8636 // The custom extension add callback should not be called if the client
8637 // doesn't send the extension.
8638 testCases = append(testCases, testCase{
8639 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008640 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008641 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008642 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008643 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008644 ExpectedCustomExtension: &emptyString,
8645 },
8646 },
8647 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8648 })
Adam Langley2deb9842015-08-07 11:15:37 -07008649
Steven Valdez143e8b32016-07-11 13:19:03 -04008650 testCases = append(testCases, testCase{
8651 testType: serverTest,
8652 name: "CustomExtensions-NotCalled-Server-TLS13",
8653 config: Config{
8654 MaxVersion: VersionTLS13,
8655 Bugs: ProtocolBugs{
8656 ExpectedCustomExtension: &emptyString,
8657 },
8658 },
8659 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8660 })
8661
Adam Langley2deb9842015-08-07 11:15:37 -07008662 // Test an unknown extension from the server.
8663 testCases = append(testCases, testCase{
8664 testType: clientTest,
8665 name: "UnknownExtension-Client",
8666 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008667 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008668 Bugs: ProtocolBugs{
8669 CustomExtension: expectedContents,
8670 },
8671 },
David Benjamin0c40a962016-08-01 12:05:50 -04008672 shouldFail: true,
8673 expectedError: ":UNEXPECTED_EXTENSION:",
8674 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008675 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008676 testCases = append(testCases, testCase{
8677 testType: clientTest,
8678 name: "UnknownExtension-Client-TLS13",
8679 config: Config{
8680 MaxVersion: VersionTLS13,
8681 Bugs: ProtocolBugs{
8682 CustomExtension: expectedContents,
8683 },
8684 },
David Benjamin0c40a962016-08-01 12:05:50 -04008685 shouldFail: true,
8686 expectedError: ":UNEXPECTED_EXTENSION:",
8687 expectedLocalError: "remote error: unsupported extension",
8688 })
David Benjamin490469f2016-10-05 22:44:38 -04008689 testCases = append(testCases, testCase{
8690 testType: clientTest,
8691 name: "UnknownUnencryptedExtension-Client-TLS13",
8692 config: Config{
8693 MaxVersion: VersionTLS13,
8694 Bugs: ProtocolBugs{
8695 CustomUnencryptedExtension: expectedContents,
8696 },
8697 },
8698 shouldFail: true,
8699 expectedError: ":UNEXPECTED_EXTENSION:",
8700 // The shim must send an alert, but alerts at this point do not
8701 // get successfully decrypted by the runner.
8702 expectedLocalError: "local error: bad record MAC",
8703 })
8704 testCases = append(testCases, testCase{
8705 testType: clientTest,
8706 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8707 config: Config{
8708 MaxVersion: VersionTLS13,
8709 Bugs: ProtocolBugs{
8710 SendUnencryptedALPN: "foo",
8711 },
8712 },
8713 flags: []string{
8714 "-advertise-alpn", "\x03foo\x03bar",
8715 },
8716 shouldFail: true,
8717 expectedError: ":UNEXPECTED_EXTENSION:",
8718 // The shim must send an alert, but alerts at this point do not
8719 // get successfully decrypted by the runner.
8720 expectedLocalError: "local error: bad record MAC",
8721 })
David Benjamin0c40a962016-08-01 12:05:50 -04008722
8723 // Test a known but unoffered extension from the server.
8724 testCases = append(testCases, testCase{
8725 testType: clientTest,
8726 name: "UnofferedExtension-Client",
8727 config: Config{
8728 MaxVersion: VersionTLS12,
8729 Bugs: ProtocolBugs{
8730 SendALPN: "alpn",
8731 },
8732 },
8733 shouldFail: true,
8734 expectedError: ":UNEXPECTED_EXTENSION:",
8735 expectedLocalError: "remote error: unsupported extension",
8736 })
8737 testCases = append(testCases, testCase{
8738 testType: clientTest,
8739 name: "UnofferedExtension-Client-TLS13",
8740 config: Config{
8741 MaxVersion: VersionTLS13,
8742 Bugs: ProtocolBugs{
8743 SendALPN: "alpn",
8744 },
8745 },
8746 shouldFail: true,
8747 expectedError: ":UNEXPECTED_EXTENSION:",
8748 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008749 })
Adam Langley09505632015-07-30 18:10:13 -07008750}
8751
David Benjaminb36a3952015-12-01 18:53:13 -05008752func addRSAClientKeyExchangeTests() {
8753 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8754 testCases = append(testCases, testCase{
8755 testType: serverTest,
8756 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8757 config: Config{
8758 // Ensure the ClientHello version and final
8759 // version are different, to detect if the
8760 // server uses the wrong one.
8761 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008762 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008763 Bugs: ProtocolBugs{
8764 BadRSAClientKeyExchange: bad,
8765 },
8766 },
8767 shouldFail: true,
8768 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8769 })
8770 }
David Benjamine63d9d72016-09-19 18:27:34 -04008771
8772 // The server must compare whatever was in ClientHello.version for the
8773 // RSA premaster.
8774 testCases = append(testCases, testCase{
8775 testType: serverTest,
8776 name: "SendClientVersion-RSA",
8777 config: Config{
8778 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8779 Bugs: ProtocolBugs{
8780 SendClientVersion: 0x1234,
8781 },
8782 },
8783 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8784 })
David Benjaminb36a3952015-12-01 18:53:13 -05008785}
8786
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008787var testCurves = []struct {
8788 name string
8789 id CurveID
8790}{
Adam Langley764ab982017-03-10 18:01:30 -08008791 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008792 {"P-256", CurveP256},
8793 {"P-384", CurveP384},
8794 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008795 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008796}
8797
Steven Valdez5440fe02016-07-18 12:40:30 -04008798const bogusCurve = 0x1234
8799
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008800func addCurveTests() {
8801 for _, curve := range testCurves {
8802 testCases = append(testCases, testCase{
8803 name: "CurveTest-Client-" + curve.name,
8804 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008805 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8807 CurvePreferences: []CurveID{curve.id},
8808 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008809 flags: []string{
8810 "-enable-all-curves",
8811 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8812 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008813 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008814 })
8815 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008816 name: "CurveTest-Client-" + curve.name + "-TLS13",
8817 config: Config{
8818 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008819 CurvePreferences: []CurveID{curve.id},
8820 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008821 flags: []string{
8822 "-enable-all-curves",
8823 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8824 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008825 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008826 })
8827 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008828 testType: serverTest,
8829 name: "CurveTest-Server-" + curve.name,
8830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008831 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8833 CurvePreferences: []CurveID{curve.id},
8834 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008835 flags: []string{
8836 "-enable-all-curves",
8837 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8838 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008839 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008840 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008841 testCases = append(testCases, testCase{
8842 testType: serverTest,
8843 name: "CurveTest-Server-" + curve.name + "-TLS13",
8844 config: Config{
8845 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008846 CurvePreferences: []CurveID{curve.id},
8847 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008848 flags: []string{
8849 "-enable-all-curves",
8850 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8851 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008852 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008853 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008854 }
David Benjamin241ae832016-01-15 03:04:54 -05008855
8856 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008857 testCases = append(testCases, testCase{
8858 testType: serverTest,
8859 name: "UnknownCurve",
8860 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008861 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008862 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8863 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8864 },
8865 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008866
Steven Valdez803c77a2016-09-06 14:13:43 -04008867 // The server must be tolerant to bogus curves.
8868 testCases = append(testCases, testCase{
8869 testType: serverTest,
8870 name: "UnknownCurve-TLS13",
8871 config: Config{
8872 MaxVersion: VersionTLS13,
8873 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8874 },
8875 })
8876
David Benjamin4c3ddf72016-06-29 18:13:53 -04008877 // The server must not consider ECDHE ciphers when there are no
8878 // supported curves.
8879 testCases = append(testCases, testCase{
8880 testType: serverTest,
8881 name: "NoSupportedCurves",
8882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008883 MaxVersion: VersionTLS12,
8884 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8885 Bugs: ProtocolBugs{
8886 NoSupportedCurves: true,
8887 },
8888 },
8889 shouldFail: true,
8890 expectedError: ":NO_SHARED_CIPHER:",
8891 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008892 testCases = append(testCases, testCase{
8893 testType: serverTest,
8894 name: "NoSupportedCurves-TLS13",
8895 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008896 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008897 Bugs: ProtocolBugs{
8898 NoSupportedCurves: true,
8899 },
8900 },
8901 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008902 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008903 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008904
8905 // The server must fall back to another cipher when there are no
8906 // supported curves.
8907 testCases = append(testCases, testCase{
8908 testType: serverTest,
8909 name: "NoCommonCurves",
8910 config: Config{
8911 MaxVersion: VersionTLS12,
8912 CipherSuites: []uint16{
8913 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008914 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008915 },
8916 CurvePreferences: []CurveID{CurveP224},
8917 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008918 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008919 })
8920
8921 // The client must reject bogus curves and disabled curves.
8922 testCases = append(testCases, testCase{
8923 name: "BadECDHECurve",
8924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008925 MaxVersion: VersionTLS12,
8926 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8927 Bugs: ProtocolBugs{
8928 SendCurve: bogusCurve,
8929 },
8930 },
8931 shouldFail: true,
8932 expectedError: ":WRONG_CURVE:",
8933 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008934 testCases = append(testCases, testCase{
8935 name: "BadECDHECurve-TLS13",
8936 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008937 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008938 Bugs: ProtocolBugs{
8939 SendCurve: bogusCurve,
8940 },
8941 },
8942 shouldFail: true,
8943 expectedError: ":WRONG_CURVE:",
8944 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008945
8946 testCases = append(testCases, testCase{
8947 name: "UnsupportedCurve",
8948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008949 MaxVersion: VersionTLS12,
8950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8951 CurvePreferences: []CurveID{CurveP256},
8952 Bugs: ProtocolBugs{
8953 IgnorePeerCurvePreferences: true,
8954 },
8955 },
8956 flags: []string{"-p384-only"},
8957 shouldFail: true,
8958 expectedError: ":WRONG_CURVE:",
8959 })
8960
David Benjamin4f921572016-07-17 14:20:10 +02008961 testCases = append(testCases, testCase{
8962 // TODO(davidben): Add a TLS 1.3 version where
8963 // HelloRetryRequest requests an unsupported curve.
8964 name: "UnsupportedCurve-ServerHello-TLS13",
8965 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008966 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008967 CurvePreferences: []CurveID{CurveP384},
8968 Bugs: ProtocolBugs{
8969 SendCurve: CurveP256,
8970 },
8971 },
8972 flags: []string{"-p384-only"},
8973 shouldFail: true,
8974 expectedError: ":WRONG_CURVE:",
8975 })
8976
David Benjamin4c3ddf72016-06-29 18:13:53 -04008977 // Test invalid curve points.
8978 testCases = append(testCases, testCase{
8979 name: "InvalidECDHPoint-Client",
8980 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008981 MaxVersion: VersionTLS12,
8982 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8983 CurvePreferences: []CurveID{CurveP256},
8984 Bugs: ProtocolBugs{
8985 InvalidECDHPoint: true,
8986 },
8987 },
8988 shouldFail: true,
8989 expectedError: ":INVALID_ENCODING:",
8990 })
8991 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008992 name: "InvalidECDHPoint-Client-TLS13",
8993 config: Config{
8994 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008995 CurvePreferences: []CurveID{CurveP256},
8996 Bugs: ProtocolBugs{
8997 InvalidECDHPoint: true,
8998 },
8999 },
9000 shouldFail: true,
9001 expectedError: ":INVALID_ENCODING:",
9002 })
9003 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009004 testType: serverTest,
9005 name: "InvalidECDHPoint-Server",
9006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009007 MaxVersion: VersionTLS12,
9008 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9009 CurvePreferences: []CurveID{CurveP256},
9010 Bugs: ProtocolBugs{
9011 InvalidECDHPoint: true,
9012 },
9013 },
9014 shouldFail: true,
9015 expectedError: ":INVALID_ENCODING:",
9016 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009017 testCases = append(testCases, testCase{
9018 testType: serverTest,
9019 name: "InvalidECDHPoint-Server-TLS13",
9020 config: Config{
9021 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009022 CurvePreferences: []CurveID{CurveP256},
9023 Bugs: ProtocolBugs{
9024 InvalidECDHPoint: true,
9025 },
9026 },
9027 shouldFail: true,
9028 expectedError: ":INVALID_ENCODING:",
9029 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009030
9031 // The previous curve ID should be reported on TLS 1.2 resumption.
9032 testCases = append(testCases, testCase{
9033 name: "CurveID-Resume-Client",
9034 config: Config{
9035 MaxVersion: VersionTLS12,
9036 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9037 CurvePreferences: []CurveID{CurveX25519},
9038 },
9039 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9040 resumeSession: true,
9041 })
9042 testCases = append(testCases, testCase{
9043 testType: serverTest,
9044 name: "CurveID-Resume-Server",
9045 config: Config{
9046 MaxVersion: VersionTLS12,
9047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9048 CurvePreferences: []CurveID{CurveX25519},
9049 },
9050 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9051 resumeSession: true,
9052 })
9053
9054 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9055 // one should be reported.
9056 testCases = append(testCases, testCase{
9057 name: "CurveID-Resume-Client-TLS13",
9058 config: Config{
9059 MaxVersion: VersionTLS13,
9060 CurvePreferences: []CurveID{CurveX25519},
9061 },
9062 resumeConfig: &Config{
9063 MaxVersion: VersionTLS13,
9064 CurvePreferences: []CurveID{CurveP256},
9065 },
9066 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009067 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9068 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009069 },
9070 resumeSession: true,
9071 })
9072 testCases = append(testCases, testCase{
9073 testType: serverTest,
9074 name: "CurveID-Resume-Server-TLS13",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 CurvePreferences: []CurveID{CurveX25519},
9078 },
9079 resumeConfig: &Config{
9080 MaxVersion: VersionTLS13,
9081 CurvePreferences: []CurveID{CurveP256},
9082 },
9083 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009084 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9085 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009086 },
9087 resumeSession: true,
9088 })
David Benjamina81967b2016-12-22 09:16:57 -05009089
9090 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9091 testCases = append(testCases, testCase{
9092 name: "PointFormat-ServerHello-TLS12",
9093 config: Config{
9094 MaxVersion: VersionTLS12,
9095 Bugs: ProtocolBugs{
9096 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9097 },
9098 },
9099 })
9100 testCases = append(testCases, testCase{
9101 name: "PointFormat-EncryptedExtensions-TLS13",
9102 config: Config{
9103 MaxVersion: VersionTLS13,
9104 Bugs: ProtocolBugs{
9105 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9106 },
9107 },
9108 shouldFail: true,
9109 expectedError: ":ERROR_PARSING_EXTENSION:",
9110 })
9111
9112 // Test that we tolerate unknown point formats, as long as
9113 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9114 // check they are still functional.
9115 testCases = append(testCases, testCase{
9116 name: "PointFormat-Client-Tolerance",
9117 config: Config{
9118 MaxVersion: VersionTLS12,
9119 Bugs: ProtocolBugs{
9120 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9121 },
9122 },
9123 })
9124 testCases = append(testCases, testCase{
9125 testType: serverTest,
9126 name: "PointFormat-Server-Tolerance",
9127 config: Config{
9128 MaxVersion: VersionTLS12,
9129 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9130 Bugs: ProtocolBugs{
9131 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9132 },
9133 },
9134 })
9135
9136 // Test TLS 1.2 does not require the point format extension to be
9137 // present.
9138 testCases = append(testCases, testCase{
9139 name: "PointFormat-Client-Missing",
9140 config: Config{
9141 MaxVersion: VersionTLS12,
9142 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9143 Bugs: ProtocolBugs{
9144 SendSupportedPointFormats: []byte{},
9145 },
9146 },
9147 })
9148 testCases = append(testCases, testCase{
9149 testType: serverTest,
9150 name: "PointFormat-Server-Missing",
9151 config: Config{
9152 MaxVersion: VersionTLS12,
9153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9154 Bugs: ProtocolBugs{
9155 SendSupportedPointFormats: []byte{},
9156 },
9157 },
9158 })
9159
9160 // If the point format extension is present, uncompressed points must be
9161 // offered. BoringSSL requires this whether or not ECDHE is used.
9162 testCases = append(testCases, testCase{
9163 name: "PointFormat-Client-MissingUncompressed",
9164 config: Config{
9165 MaxVersion: VersionTLS12,
9166 Bugs: ProtocolBugs{
9167 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9168 },
9169 },
9170 shouldFail: true,
9171 expectedError: ":ERROR_PARSING_EXTENSION:",
9172 })
9173 testCases = append(testCases, testCase{
9174 testType: serverTest,
9175 name: "PointFormat-Server-MissingUncompressed",
9176 config: Config{
9177 MaxVersion: VersionTLS12,
9178 Bugs: ProtocolBugs{
9179 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9180 },
9181 },
9182 shouldFail: true,
9183 expectedError: ":ERROR_PARSING_EXTENSION:",
9184 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009185}
9186
David Benjaminc9ae27c2016-06-24 22:56:37 -04009187func addTLS13RecordTests() {
9188 testCases = append(testCases, testCase{
9189 name: "TLS13-RecordPadding",
9190 config: Config{
9191 MaxVersion: VersionTLS13,
9192 MinVersion: VersionTLS13,
9193 Bugs: ProtocolBugs{
9194 RecordPadding: 10,
9195 },
9196 },
9197 })
9198
9199 testCases = append(testCases, testCase{
9200 name: "TLS13-EmptyRecords",
9201 config: Config{
9202 MaxVersion: VersionTLS13,
9203 MinVersion: VersionTLS13,
9204 Bugs: ProtocolBugs{
9205 OmitRecordContents: true,
9206 },
9207 },
9208 shouldFail: true,
9209 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9210 })
9211
9212 testCases = append(testCases, testCase{
9213 name: "TLS13-OnlyPadding",
9214 config: Config{
9215 MaxVersion: VersionTLS13,
9216 MinVersion: VersionTLS13,
9217 Bugs: ProtocolBugs{
9218 OmitRecordContents: true,
9219 RecordPadding: 10,
9220 },
9221 },
9222 shouldFail: true,
9223 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9224 })
9225
9226 testCases = append(testCases, testCase{
9227 name: "TLS13-WrongOuterRecord",
9228 config: Config{
9229 MaxVersion: VersionTLS13,
9230 MinVersion: VersionTLS13,
9231 Bugs: ProtocolBugs{
9232 OuterRecordType: recordTypeHandshake,
9233 },
9234 },
9235 shouldFail: true,
9236 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9237 })
9238}
9239
Steven Valdez5b986082016-09-01 12:29:49 -04009240func addSessionTicketTests() {
9241 testCases = append(testCases, testCase{
9242 // In TLS 1.2 and below, empty NewSessionTicket messages
9243 // mean the server changed its mind on sending a ticket.
9244 name: "SendEmptySessionTicket",
9245 config: Config{
9246 MaxVersion: VersionTLS12,
9247 Bugs: ProtocolBugs{
9248 SendEmptySessionTicket: true,
9249 },
9250 },
9251 flags: []string{"-expect-no-session"},
9252 })
9253
9254 // Test that the server ignores unknown PSK modes.
9255 testCases = append(testCases, testCase{
9256 testType: serverTest,
9257 name: "TLS13-SendUnknownModeSessionTicket-Server",
9258 config: Config{
9259 MaxVersion: VersionTLS13,
9260 Bugs: ProtocolBugs{
9261 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009262 },
9263 },
9264 resumeSession: true,
9265 expectedResumeVersion: VersionTLS13,
9266 })
9267
Steven Valdeza833c352016-11-01 13:39:36 -04009268 // Test that the server does not send session tickets with no matching key exchange mode.
9269 testCases = append(testCases, testCase{
9270 testType: serverTest,
9271 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9272 config: Config{
9273 MaxVersion: VersionTLS13,
9274 Bugs: ProtocolBugs{
9275 SendPSKKeyExchangeModes: []byte{0x1a},
9276 ExpectNoNewSessionTicket: true,
9277 },
9278 },
9279 })
9280
9281 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009282 testCases = append(testCases, testCase{
9283 testType: serverTest,
9284 name: "TLS13-SendBadKEModeSessionTicket-Server",
9285 config: Config{
9286 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009287 },
9288 resumeConfig: &Config{
9289 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009290 Bugs: ProtocolBugs{
9291 SendPSKKeyExchangeModes: []byte{0x1a},
9292 },
9293 },
9294 resumeSession: true,
9295 expectResumeRejected: true,
9296 })
9297
Steven Valdeza833c352016-11-01 13:39:36 -04009298 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009299 testCases = append(testCases, testCase{
9300 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009301 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009302 config: Config{
9303 MaxVersion: VersionTLS13,
9304 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009305 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009306 },
9307 },
Steven Valdeza833c352016-11-01 13:39:36 -04009308 resumeSession: true,
9309 flags: []string{
9310 "-resumption-delay", "10",
9311 },
Steven Valdez5b986082016-09-01 12:29:49 -04009312 })
9313
Steven Valdeza833c352016-11-01 13:39:36 -04009314 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009315 testCases = append(testCases, testCase{
9316 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009317 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009318 config: Config{
9319 MaxVersion: VersionTLS13,
9320 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009321 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009322 },
9323 },
Steven Valdeza833c352016-11-01 13:39:36 -04009324 resumeSession: true,
9325 shouldFail: true,
9326 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009327 })
9328
David Benjamin35ac5b72017-03-03 15:05:56 -05009329 // Test that the server's ticket age skew reporting works.
9330 testCases = append(testCases, testCase{
9331 testType: serverTest,
9332 name: "TLS13-TicketAgeSkew-Forward",
9333 config: Config{
9334 MaxVersion: VersionTLS13,
9335 Bugs: ProtocolBugs{
9336 SendTicketAge: 15 * time.Second,
9337 },
9338 },
David Benjamin065d7332017-03-26 10:51:43 -05009339 resumeSession: true,
9340 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009341 flags: []string{
9342 "-resumption-delay", "10",
9343 "-expect-ticket-age-skew", "5",
9344 },
9345 })
9346 testCases = append(testCases, testCase{
9347 testType: serverTest,
9348 name: "TLS13-TicketAgeSkew-Backward",
9349 config: Config{
9350 MaxVersion: VersionTLS13,
9351 Bugs: ProtocolBugs{
9352 SendTicketAge: 5 * time.Second,
9353 },
9354 },
David Benjamin065d7332017-03-26 10:51:43 -05009355 resumeSession: true,
9356 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009357 flags: []string{
9358 "-resumption-delay", "10",
9359 "-expect-ticket-age-skew", "-5",
9360 },
9361 })
9362
Steven Valdez08b65f42016-12-07 15:29:45 -05009363 testCases = append(testCases, testCase{
9364 testType: clientTest,
9365 name: "TLS13-SendTicketEarlyDataInfo",
9366 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009367 MaxVersion: VersionTLS13,
9368 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009369 },
9370 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009371 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009372 "-expect-early-data-info",
9373 },
9374 })
9375
David Benjamin9b160662017-01-25 19:53:43 -05009376 // Test that 0-RTT tickets are ignored in clients unless opted in.
9377 testCases = append(testCases, testCase{
9378 testType: clientTest,
9379 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9380 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009381 MaxVersion: VersionTLS13,
9382 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009383 },
9384 })
9385
Steven Valdez08b65f42016-12-07 15:29:45 -05009386 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009387 testType: clientTest,
9388 name: "TLS13-DuplicateTicketEarlyDataInfo",
9389 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009390 MaxVersion: VersionTLS13,
9391 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009392 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009393 DuplicateTicketEarlyDataInfo: true,
9394 },
9395 },
9396 shouldFail: true,
9397 expectedError: ":DUPLICATE_EXTENSION:",
9398 expectedLocalError: "remote error: illegal parameter",
9399 })
9400
9401 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009402 testType: serverTest,
9403 name: "TLS13-ExpectTicketEarlyDataInfo",
9404 config: Config{
9405 MaxVersion: VersionTLS13,
9406 Bugs: ProtocolBugs{
9407 ExpectTicketEarlyDataInfo: true,
9408 },
9409 },
9410 flags: []string{
9411 "-enable-early-data",
9412 },
9413 })
David Benjamin17b30832017-01-28 14:00:32 -05009414
9415 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9416 // is honored.
9417 testCases = append(testCases, testCase{
9418 testType: clientTest,
9419 name: "TLS13-HonorServerSessionTicketLifetime",
9420 config: Config{
9421 MaxVersion: VersionTLS13,
9422 Bugs: ProtocolBugs{
9423 SendTicketLifetime: 20 * time.Second,
9424 },
9425 },
9426 flags: []string{
9427 "-resumption-delay", "19",
9428 },
9429 resumeSession: true,
9430 })
9431 testCases = append(testCases, testCase{
9432 testType: clientTest,
9433 name: "TLS13-HonorServerSessionTicketLifetime-2",
9434 config: Config{
9435 MaxVersion: VersionTLS13,
9436 Bugs: ProtocolBugs{
9437 SendTicketLifetime: 20 * time.Second,
9438 // The client should not offer the expired session.
9439 ExpectNoTLS13PSK: true,
9440 },
9441 },
9442 flags: []string{
9443 "-resumption-delay", "21",
9444 },
David Benjamin023d4192017-02-06 13:49:07 -05009445 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009446 expectResumeRejected: true,
9447 })
Steven Valdez5b986082016-09-01 12:29:49 -04009448}
9449
David Benjamin82261be2016-07-07 14:32:50 -07009450func addChangeCipherSpecTests() {
9451 // Test missing ChangeCipherSpecs.
9452 testCases = append(testCases, testCase{
9453 name: "SkipChangeCipherSpec-Client",
9454 config: Config{
9455 MaxVersion: VersionTLS12,
9456 Bugs: ProtocolBugs{
9457 SkipChangeCipherSpec: true,
9458 },
9459 },
9460 shouldFail: true,
9461 expectedError: ":UNEXPECTED_RECORD:",
9462 })
9463 testCases = append(testCases, testCase{
9464 testType: serverTest,
9465 name: "SkipChangeCipherSpec-Server",
9466 config: Config{
9467 MaxVersion: VersionTLS12,
9468 Bugs: ProtocolBugs{
9469 SkipChangeCipherSpec: true,
9470 },
9471 },
9472 shouldFail: true,
9473 expectedError: ":UNEXPECTED_RECORD:",
9474 })
9475 testCases = append(testCases, testCase{
9476 testType: serverTest,
9477 name: "SkipChangeCipherSpec-Server-NPN",
9478 config: Config{
9479 MaxVersion: VersionTLS12,
9480 NextProtos: []string{"bar"},
9481 Bugs: ProtocolBugs{
9482 SkipChangeCipherSpec: true,
9483 },
9484 },
9485 flags: []string{
9486 "-advertise-npn", "\x03foo\x03bar\x03baz",
9487 },
9488 shouldFail: true,
9489 expectedError: ":UNEXPECTED_RECORD:",
9490 })
9491
9492 // Test synchronization between the handshake and ChangeCipherSpec.
9493 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9494 // rejected. Test both with and without handshake packing to handle both
9495 // when the partial post-CCS message is in its own record and when it is
9496 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009497 for _, packed := range []bool{false, true} {
9498 var suffix string
9499 if packed {
9500 suffix = "-Packed"
9501 }
9502
9503 testCases = append(testCases, testCase{
9504 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9505 config: Config{
9506 MaxVersion: VersionTLS12,
9507 Bugs: ProtocolBugs{
9508 FragmentAcrossChangeCipherSpec: true,
9509 PackHandshakeFlight: packed,
9510 },
9511 },
9512 shouldFail: true,
9513 expectedError: ":UNEXPECTED_RECORD:",
9514 })
9515 testCases = append(testCases, testCase{
9516 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9517 config: Config{
9518 MaxVersion: VersionTLS12,
9519 },
9520 resumeSession: true,
9521 resumeConfig: &Config{
9522 MaxVersion: VersionTLS12,
9523 Bugs: ProtocolBugs{
9524 FragmentAcrossChangeCipherSpec: true,
9525 PackHandshakeFlight: packed,
9526 },
9527 },
9528 shouldFail: true,
9529 expectedError: ":UNEXPECTED_RECORD:",
9530 })
9531 testCases = append(testCases, testCase{
9532 testType: serverTest,
9533 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9534 config: Config{
9535 MaxVersion: VersionTLS12,
9536 Bugs: ProtocolBugs{
9537 FragmentAcrossChangeCipherSpec: true,
9538 PackHandshakeFlight: packed,
9539 },
9540 },
9541 shouldFail: true,
9542 expectedError: ":UNEXPECTED_RECORD:",
9543 })
9544 testCases = append(testCases, testCase{
9545 testType: serverTest,
9546 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9547 config: Config{
9548 MaxVersion: VersionTLS12,
9549 },
9550 resumeSession: true,
9551 resumeConfig: &Config{
9552 MaxVersion: VersionTLS12,
9553 Bugs: ProtocolBugs{
9554 FragmentAcrossChangeCipherSpec: true,
9555 PackHandshakeFlight: packed,
9556 },
9557 },
9558 shouldFail: true,
9559 expectedError: ":UNEXPECTED_RECORD:",
9560 })
9561 testCases = append(testCases, testCase{
9562 testType: serverTest,
9563 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9564 config: Config{
9565 MaxVersion: VersionTLS12,
9566 NextProtos: []string{"bar"},
9567 Bugs: ProtocolBugs{
9568 FragmentAcrossChangeCipherSpec: true,
9569 PackHandshakeFlight: packed,
9570 },
9571 },
9572 flags: []string{
9573 "-advertise-npn", "\x03foo\x03bar\x03baz",
9574 },
9575 shouldFail: true,
9576 expectedError: ":UNEXPECTED_RECORD:",
9577 })
9578 }
9579
David Benjamin61672812016-07-14 23:10:43 -04009580 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9581 // messages in the handshake queue. Do this by testing the server
9582 // reading the client Finished, reversing the flight so Finished comes
9583 // first.
9584 testCases = append(testCases, testCase{
9585 protocol: dtls,
9586 testType: serverTest,
9587 name: "SendUnencryptedFinished-DTLS",
9588 config: Config{
9589 MaxVersion: VersionTLS12,
9590 Bugs: ProtocolBugs{
9591 SendUnencryptedFinished: true,
9592 ReverseHandshakeFragments: true,
9593 },
9594 },
9595 shouldFail: true,
9596 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9597 })
9598
Steven Valdez143e8b32016-07-11 13:19:03 -04009599 // Test synchronization between encryption changes and the handshake in
9600 // TLS 1.3, where ChangeCipherSpec is implicit.
9601 testCases = append(testCases, testCase{
9602 name: "PartialEncryptedExtensionsWithServerHello",
9603 config: Config{
9604 MaxVersion: VersionTLS13,
9605 Bugs: ProtocolBugs{
9606 PartialEncryptedExtensionsWithServerHello: true,
9607 },
9608 },
9609 shouldFail: true,
9610 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9611 })
9612 testCases = append(testCases, testCase{
9613 testType: serverTest,
9614 name: "PartialClientFinishedWithClientHello",
9615 config: Config{
9616 MaxVersion: VersionTLS13,
9617 Bugs: ProtocolBugs{
9618 PartialClientFinishedWithClientHello: true,
9619 },
9620 },
9621 shouldFail: true,
9622 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9623 })
9624
David Benjamin82261be2016-07-07 14:32:50 -07009625 // Test that early ChangeCipherSpecs are handled correctly.
9626 testCases = append(testCases, testCase{
9627 testType: serverTest,
9628 name: "EarlyChangeCipherSpec-server-1",
9629 config: Config{
9630 MaxVersion: VersionTLS12,
9631 Bugs: ProtocolBugs{
9632 EarlyChangeCipherSpec: 1,
9633 },
9634 },
9635 shouldFail: true,
9636 expectedError: ":UNEXPECTED_RECORD:",
9637 })
9638 testCases = append(testCases, testCase{
9639 testType: serverTest,
9640 name: "EarlyChangeCipherSpec-server-2",
9641 config: Config{
9642 MaxVersion: VersionTLS12,
9643 Bugs: ProtocolBugs{
9644 EarlyChangeCipherSpec: 2,
9645 },
9646 },
9647 shouldFail: true,
9648 expectedError: ":UNEXPECTED_RECORD:",
9649 })
9650 testCases = append(testCases, testCase{
9651 protocol: dtls,
9652 name: "StrayChangeCipherSpec",
9653 config: Config{
9654 // TODO(davidben): Once DTLS 1.3 exists, test
9655 // that stray ChangeCipherSpec messages are
9656 // rejected.
9657 MaxVersion: VersionTLS12,
9658 Bugs: ProtocolBugs{
9659 StrayChangeCipherSpec: true,
9660 },
9661 },
9662 })
9663
9664 // Test that the contents of ChangeCipherSpec are checked.
9665 testCases = append(testCases, testCase{
9666 name: "BadChangeCipherSpec-1",
9667 config: Config{
9668 MaxVersion: VersionTLS12,
9669 Bugs: ProtocolBugs{
9670 BadChangeCipherSpec: []byte{2},
9671 },
9672 },
9673 shouldFail: true,
9674 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9675 })
9676 testCases = append(testCases, testCase{
9677 name: "BadChangeCipherSpec-2",
9678 config: Config{
9679 MaxVersion: VersionTLS12,
9680 Bugs: ProtocolBugs{
9681 BadChangeCipherSpec: []byte{1, 1},
9682 },
9683 },
9684 shouldFail: true,
9685 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9686 })
9687 testCases = append(testCases, testCase{
9688 protocol: dtls,
9689 name: "BadChangeCipherSpec-DTLS-1",
9690 config: Config{
9691 MaxVersion: VersionTLS12,
9692 Bugs: ProtocolBugs{
9693 BadChangeCipherSpec: []byte{2},
9694 },
9695 },
9696 shouldFail: true,
9697 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9698 })
9699 testCases = append(testCases, testCase{
9700 protocol: dtls,
9701 name: "BadChangeCipherSpec-DTLS-2",
9702 config: Config{
9703 MaxVersion: VersionTLS12,
9704 Bugs: ProtocolBugs{
9705 BadChangeCipherSpec: []byte{1, 1},
9706 },
9707 },
9708 shouldFail: true,
9709 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9710 })
9711}
9712
David Benjamincd2c8062016-09-09 11:28:16 -04009713type perMessageTest struct {
9714 messageType uint8
9715 test testCase
9716}
9717
9718// makePerMessageTests returns a series of test templates which cover each
9719// message in the TLS handshake. These may be used with bugs like
9720// WrongMessageType to fully test a per-message bug.
9721func makePerMessageTests() []perMessageTest {
9722 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009723 for _, protocol := range []protocol{tls, dtls} {
9724 var suffix string
9725 if protocol == dtls {
9726 suffix = "-DTLS"
9727 }
9728
David Benjamincd2c8062016-09-09 11:28:16 -04009729 ret = append(ret, perMessageTest{
9730 messageType: typeClientHello,
9731 test: testCase{
9732 protocol: protocol,
9733 testType: serverTest,
9734 name: "ClientHello" + suffix,
9735 config: Config{
9736 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009737 },
9738 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009739 })
9740
9741 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009742 ret = append(ret, perMessageTest{
9743 messageType: typeHelloVerifyRequest,
9744 test: testCase{
9745 protocol: protocol,
9746 name: "HelloVerifyRequest" + suffix,
9747 config: Config{
9748 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009749 },
9750 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009751 })
9752 }
9753
David Benjamincd2c8062016-09-09 11:28:16 -04009754 ret = append(ret, perMessageTest{
9755 messageType: typeServerHello,
9756 test: testCase{
9757 protocol: protocol,
9758 name: "ServerHello" + suffix,
9759 config: Config{
9760 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009761 },
9762 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009763 })
9764
David Benjamincd2c8062016-09-09 11:28:16 -04009765 ret = append(ret, perMessageTest{
9766 messageType: typeCertificate,
9767 test: testCase{
9768 protocol: protocol,
9769 name: "ServerCertificate" + suffix,
9770 config: Config{
9771 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009772 },
9773 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009774 })
9775
David Benjamincd2c8062016-09-09 11:28:16 -04009776 ret = append(ret, perMessageTest{
9777 messageType: typeCertificateStatus,
9778 test: testCase{
9779 protocol: protocol,
9780 name: "CertificateStatus" + suffix,
9781 config: Config{
9782 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009783 },
David Benjamincd2c8062016-09-09 11:28:16 -04009784 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009785 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009786 })
9787
David Benjamincd2c8062016-09-09 11:28:16 -04009788 ret = append(ret, perMessageTest{
9789 messageType: typeServerKeyExchange,
9790 test: testCase{
9791 protocol: protocol,
9792 name: "ServerKeyExchange" + suffix,
9793 config: Config{
9794 MaxVersion: VersionTLS12,
9795 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009796 },
9797 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009798 })
9799
David Benjamincd2c8062016-09-09 11:28:16 -04009800 ret = append(ret, perMessageTest{
9801 messageType: typeCertificateRequest,
9802 test: testCase{
9803 protocol: protocol,
9804 name: "CertificateRequest" + suffix,
9805 config: Config{
9806 MaxVersion: VersionTLS12,
9807 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009808 },
9809 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009810 })
9811
David Benjamincd2c8062016-09-09 11:28:16 -04009812 ret = append(ret, perMessageTest{
9813 messageType: typeServerHelloDone,
9814 test: testCase{
9815 protocol: protocol,
9816 name: "ServerHelloDone" + suffix,
9817 config: Config{
9818 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009819 },
9820 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009821 })
9822
David Benjamincd2c8062016-09-09 11:28:16 -04009823 ret = append(ret, perMessageTest{
9824 messageType: typeCertificate,
9825 test: testCase{
9826 testType: serverTest,
9827 protocol: protocol,
9828 name: "ClientCertificate" + suffix,
9829 config: Config{
9830 Certificates: []Certificate{rsaCertificate},
9831 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009832 },
David Benjamincd2c8062016-09-09 11:28:16 -04009833 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009834 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009835 })
9836
David Benjamincd2c8062016-09-09 11:28:16 -04009837 ret = append(ret, perMessageTest{
9838 messageType: typeCertificateVerify,
9839 test: testCase{
9840 testType: serverTest,
9841 protocol: protocol,
9842 name: "CertificateVerify" + suffix,
9843 config: Config{
9844 Certificates: []Certificate{rsaCertificate},
9845 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009846 },
David Benjamincd2c8062016-09-09 11:28:16 -04009847 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009848 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009849 })
9850
David Benjamincd2c8062016-09-09 11:28:16 -04009851 ret = append(ret, perMessageTest{
9852 messageType: typeClientKeyExchange,
9853 test: testCase{
9854 testType: serverTest,
9855 protocol: protocol,
9856 name: "ClientKeyExchange" + suffix,
9857 config: Config{
9858 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009859 },
9860 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009861 })
9862
9863 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009864 ret = append(ret, perMessageTest{
9865 messageType: typeNextProtocol,
9866 test: testCase{
9867 testType: serverTest,
9868 protocol: protocol,
9869 name: "NextProtocol" + suffix,
9870 config: Config{
9871 MaxVersion: VersionTLS12,
9872 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009873 },
David Benjamincd2c8062016-09-09 11:28:16 -04009874 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009875 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009876 })
9877
David Benjamincd2c8062016-09-09 11:28:16 -04009878 ret = append(ret, perMessageTest{
9879 messageType: typeChannelID,
9880 test: testCase{
9881 testType: serverTest,
9882 protocol: protocol,
9883 name: "ChannelID" + suffix,
9884 config: Config{
9885 MaxVersion: VersionTLS12,
9886 ChannelID: channelIDKey,
9887 },
9888 flags: []string{
9889 "-expect-channel-id",
9890 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009891 },
9892 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009893 })
9894 }
9895
David Benjamincd2c8062016-09-09 11:28:16 -04009896 ret = append(ret, perMessageTest{
9897 messageType: typeFinished,
9898 test: testCase{
9899 testType: serverTest,
9900 protocol: protocol,
9901 name: "ClientFinished" + suffix,
9902 config: Config{
9903 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009904 },
9905 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009906 })
9907
David Benjamincd2c8062016-09-09 11:28:16 -04009908 ret = append(ret, perMessageTest{
9909 messageType: typeNewSessionTicket,
9910 test: testCase{
9911 protocol: protocol,
9912 name: "NewSessionTicket" + suffix,
9913 config: Config{
9914 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009915 },
9916 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009917 })
9918
David Benjamincd2c8062016-09-09 11:28:16 -04009919 ret = append(ret, perMessageTest{
9920 messageType: typeFinished,
9921 test: testCase{
9922 protocol: protocol,
9923 name: "ServerFinished" + suffix,
9924 config: Config{
9925 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009926 },
9927 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009928 })
9929
9930 }
David Benjamincd2c8062016-09-09 11:28:16 -04009931
9932 ret = append(ret, perMessageTest{
9933 messageType: typeClientHello,
9934 test: testCase{
9935 testType: serverTest,
9936 name: "TLS13-ClientHello",
9937 config: Config{
9938 MaxVersion: VersionTLS13,
9939 },
9940 },
9941 })
9942
9943 ret = append(ret, perMessageTest{
9944 messageType: typeServerHello,
9945 test: testCase{
9946 name: "TLS13-ServerHello",
9947 config: Config{
9948 MaxVersion: VersionTLS13,
9949 },
9950 },
9951 })
9952
9953 ret = append(ret, perMessageTest{
9954 messageType: typeEncryptedExtensions,
9955 test: testCase{
9956 name: "TLS13-EncryptedExtensions",
9957 config: Config{
9958 MaxVersion: VersionTLS13,
9959 },
9960 },
9961 })
9962
9963 ret = append(ret, perMessageTest{
9964 messageType: typeCertificateRequest,
9965 test: testCase{
9966 name: "TLS13-CertificateRequest",
9967 config: Config{
9968 MaxVersion: VersionTLS13,
9969 ClientAuth: RequireAnyClientCert,
9970 },
9971 },
9972 })
9973
9974 ret = append(ret, perMessageTest{
9975 messageType: typeCertificate,
9976 test: testCase{
9977 name: "TLS13-ServerCertificate",
9978 config: Config{
9979 MaxVersion: VersionTLS13,
9980 },
9981 },
9982 })
9983
9984 ret = append(ret, perMessageTest{
9985 messageType: typeCertificateVerify,
9986 test: testCase{
9987 name: "TLS13-ServerCertificateVerify",
9988 config: Config{
9989 MaxVersion: VersionTLS13,
9990 },
9991 },
9992 })
9993
9994 ret = append(ret, perMessageTest{
9995 messageType: typeFinished,
9996 test: testCase{
9997 name: "TLS13-ServerFinished",
9998 config: Config{
9999 MaxVersion: VersionTLS13,
10000 },
10001 },
10002 })
10003
10004 ret = append(ret, perMessageTest{
10005 messageType: typeCertificate,
10006 test: testCase{
10007 testType: serverTest,
10008 name: "TLS13-ClientCertificate",
10009 config: Config{
10010 Certificates: []Certificate{rsaCertificate},
10011 MaxVersion: VersionTLS13,
10012 },
10013 flags: []string{"-require-any-client-certificate"},
10014 },
10015 })
10016
10017 ret = append(ret, perMessageTest{
10018 messageType: typeCertificateVerify,
10019 test: testCase{
10020 testType: serverTest,
10021 name: "TLS13-ClientCertificateVerify",
10022 config: Config{
10023 Certificates: []Certificate{rsaCertificate},
10024 MaxVersion: VersionTLS13,
10025 },
10026 flags: []string{"-require-any-client-certificate"},
10027 },
10028 })
10029
10030 ret = append(ret, perMessageTest{
10031 messageType: typeFinished,
10032 test: testCase{
10033 testType: serverTest,
10034 name: "TLS13-ClientFinished",
10035 config: Config{
10036 MaxVersion: VersionTLS13,
10037 },
10038 },
10039 })
10040
10041 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010042}
10043
David Benjamincd2c8062016-09-09 11:28:16 -040010044func addWrongMessageTypeTests() {
10045 for _, t := range makePerMessageTests() {
10046 t.test.name = "WrongMessageType-" + t.test.name
10047 t.test.config.Bugs.SendWrongMessageType = t.messageType
10048 t.test.shouldFail = true
10049 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10050 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010051
David Benjamincd2c8062016-09-09 11:28:16 -040010052 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10053 // In TLS 1.3, a bad ServerHello means the client sends
10054 // an unencrypted alert while the server expects
10055 // encryption, so the alert is not readable by runner.
10056 t.test.expectedLocalError = "local error: bad record MAC"
10057 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010058
David Benjamincd2c8062016-09-09 11:28:16 -040010059 testCases = append(testCases, t.test)
10060 }
David Benjaminebacdee2017-04-08 11:00:45 -040010061
10062 // The processing order for TLS 1.3 version negotiation is such that one
10063 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10064 // TLS 1.2. Test that we do not do this.
10065 testCases = append(testCases, testCase{
10066 name: "SendServerHelloAsHelloRetryRequest",
10067 config: Config{
10068 MaxVersion: VersionTLS12,
10069 Bugs: ProtocolBugs{
10070 SendServerHelloAsHelloRetryRequest: true,
10071 },
10072 },
10073 shouldFail: true,
10074 expectedError: ":UNEXPECTED_MESSAGE:",
10075 expectedLocalError: "remote error: unexpected message",
10076 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010077}
10078
David Benjamin639846e2016-09-09 11:41:18 -040010079func addTrailingMessageDataTests() {
10080 for _, t := range makePerMessageTests() {
10081 t.test.name = "TrailingMessageData-" + t.test.name
10082 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10083 t.test.shouldFail = true
10084 t.test.expectedError = ":DECODE_ERROR:"
10085 t.test.expectedLocalError = "remote error: error decoding message"
10086
10087 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10088 // In TLS 1.3, a bad ServerHello means the client sends
10089 // an unencrypted alert while the server expects
10090 // encryption, so the alert is not readable by runner.
10091 t.test.expectedLocalError = "local error: bad record MAC"
10092 }
10093
10094 if t.messageType == typeFinished {
10095 // Bad Finished messages read as the verify data having
10096 // the wrong length.
10097 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10098 t.test.expectedLocalError = "remote error: error decrypting message"
10099 }
10100
10101 testCases = append(testCases, t.test)
10102 }
10103}
10104
Steven Valdez143e8b32016-07-11 13:19:03 -040010105func addTLS13HandshakeTests() {
10106 testCases = append(testCases, testCase{
10107 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010108 name: "NegotiatePSKResumption-TLS13",
10109 config: Config{
10110 MaxVersion: VersionTLS13,
10111 Bugs: ProtocolBugs{
10112 NegotiatePSKResumption: true,
10113 },
10114 },
10115 resumeSession: true,
10116 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010117 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010118 })
10119
10120 testCases = append(testCases, testCase{
10121 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010122 name: "MissingKeyShare-Client",
10123 config: Config{
10124 MaxVersion: VersionTLS13,
10125 Bugs: ProtocolBugs{
10126 MissingKeyShare: true,
10127 },
10128 },
10129 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010130 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010131 })
10132
10133 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010134 testType: serverTest,
10135 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010136 config: Config{
10137 MaxVersion: VersionTLS13,
10138 Bugs: ProtocolBugs{
10139 MissingKeyShare: true,
10140 },
10141 },
10142 shouldFail: true,
10143 expectedError: ":MISSING_KEY_SHARE:",
10144 })
10145
10146 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010147 testType: serverTest,
10148 name: "DuplicateKeyShares",
10149 config: Config{
10150 MaxVersion: VersionTLS13,
10151 Bugs: ProtocolBugs{
10152 DuplicateKeyShares: true,
10153 },
10154 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010155 shouldFail: true,
10156 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010157 })
10158
10159 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010160 testType: serverTest,
10161 name: "SkipEarlyData",
10162 config: Config{
10163 MaxVersion: VersionTLS13,
10164 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010165 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010166 },
10167 },
10168 })
10169
10170 testCases = append(testCases, testCase{
10171 testType: serverTest,
10172 name: "SkipEarlyData-OmitEarlyDataExtension",
10173 config: Config{
10174 MaxVersion: VersionTLS13,
10175 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010176 SendFakeEarlyDataLength: 4,
10177 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010178 },
10179 },
10180 shouldFail: true,
10181 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10182 })
10183
10184 testCases = append(testCases, testCase{
10185 testType: serverTest,
10186 name: "SkipEarlyData-TooMuchData",
10187 config: Config{
10188 MaxVersion: VersionTLS13,
10189 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010190 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010191 },
10192 },
10193 shouldFail: true,
10194 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10195 })
10196
10197 testCases = append(testCases, testCase{
10198 testType: serverTest,
10199 name: "SkipEarlyData-Interleaved",
10200 config: Config{
10201 MaxVersion: VersionTLS13,
10202 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010203 SendFakeEarlyDataLength: 4,
10204 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010205 },
10206 },
10207 shouldFail: true,
10208 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10209 })
10210
10211 testCases = append(testCases, testCase{
10212 testType: serverTest,
10213 name: "SkipEarlyData-EarlyDataInTLS12",
10214 config: Config{
10215 MaxVersion: VersionTLS13,
10216 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010217 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010218 },
10219 },
10220 shouldFail: true,
10221 expectedError: ":UNEXPECTED_RECORD:",
10222 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10223 })
10224
10225 testCases = append(testCases, testCase{
10226 testType: serverTest,
10227 name: "SkipEarlyData-HRR",
10228 config: Config{
10229 MaxVersion: VersionTLS13,
10230 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010231 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010232 },
10233 DefaultCurves: []CurveID{},
10234 },
10235 })
10236
10237 testCases = append(testCases, testCase{
10238 testType: serverTest,
10239 name: "SkipEarlyData-HRR-Interleaved",
10240 config: Config{
10241 MaxVersion: VersionTLS13,
10242 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010243 SendFakeEarlyDataLength: 4,
10244 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010245 },
10246 DefaultCurves: []CurveID{},
10247 },
10248 shouldFail: true,
10249 expectedError: ":UNEXPECTED_RECORD:",
10250 })
10251
10252 testCases = append(testCases, testCase{
10253 testType: serverTest,
10254 name: "SkipEarlyData-HRR-TooMuchData",
10255 config: Config{
10256 MaxVersion: VersionTLS13,
10257 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010258 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010259 },
10260 DefaultCurves: []CurveID{},
10261 },
10262 shouldFail: true,
10263 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10264 })
10265
10266 // Test that skipping early data looking for cleartext correctly
10267 // processes an alert record.
10268 testCases = append(testCases, testCase{
10269 testType: serverTest,
10270 name: "SkipEarlyData-HRR-FatalAlert",
10271 config: Config{
10272 MaxVersion: VersionTLS13,
10273 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010274 SendEarlyAlert: true,
10275 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010276 },
10277 DefaultCurves: []CurveID{},
10278 },
10279 shouldFail: true,
10280 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10281 })
10282
10283 testCases = append(testCases, testCase{
10284 testType: serverTest,
10285 name: "SkipEarlyData-SecondClientHelloEarlyData",
10286 config: Config{
10287 MaxVersion: VersionTLS13,
10288 Bugs: ProtocolBugs{
10289 SendEarlyDataOnSecondClientHello: true,
10290 },
10291 DefaultCurves: []CurveID{},
10292 },
10293 shouldFail: true,
10294 expectedLocalError: "remote error: bad record MAC",
10295 })
10296
10297 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010298 testType: clientTest,
10299 name: "EmptyEncryptedExtensions",
10300 config: Config{
10301 MaxVersion: VersionTLS13,
10302 Bugs: ProtocolBugs{
10303 EmptyEncryptedExtensions: true,
10304 },
10305 },
10306 shouldFail: true,
10307 expectedLocalError: "remote error: error decoding message",
10308 })
10309
10310 testCases = append(testCases, testCase{
10311 testType: clientTest,
10312 name: "EncryptedExtensionsWithKeyShare",
10313 config: Config{
10314 MaxVersion: VersionTLS13,
10315 Bugs: ProtocolBugs{
10316 EncryptedExtensionsWithKeyShare: true,
10317 },
10318 },
10319 shouldFail: true,
10320 expectedLocalError: "remote error: unsupported extension",
10321 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010322
10323 testCases = append(testCases, testCase{
10324 testType: serverTest,
10325 name: "SendHelloRetryRequest",
10326 config: Config{
10327 MaxVersion: VersionTLS13,
10328 // Require a HelloRetryRequest for every curve.
10329 DefaultCurves: []CurveID{},
10330 },
10331 expectedCurveID: CurveX25519,
10332 })
10333
10334 testCases = append(testCases, testCase{
10335 testType: serverTest,
10336 name: "SendHelloRetryRequest-2",
10337 config: Config{
10338 MaxVersion: VersionTLS13,
10339 DefaultCurves: []CurveID{CurveP384},
10340 },
10341 // Although the ClientHello did not predict our preferred curve,
10342 // we always select it whether it is predicted or not.
10343 expectedCurveID: CurveX25519,
10344 })
10345
10346 testCases = append(testCases, testCase{
10347 name: "UnknownCurve-HelloRetryRequest",
10348 config: Config{
10349 MaxVersion: VersionTLS13,
10350 // P-384 requires HelloRetryRequest in BoringSSL.
10351 CurvePreferences: []CurveID{CurveP384},
10352 Bugs: ProtocolBugs{
10353 SendHelloRetryRequestCurve: bogusCurve,
10354 },
10355 },
10356 shouldFail: true,
10357 expectedError: ":WRONG_CURVE:",
10358 })
10359
10360 testCases = append(testCases, testCase{
10361 name: "DisabledCurve-HelloRetryRequest",
10362 config: Config{
10363 MaxVersion: VersionTLS13,
10364 CurvePreferences: []CurveID{CurveP256},
10365 Bugs: ProtocolBugs{
10366 IgnorePeerCurvePreferences: true,
10367 },
10368 },
10369 flags: []string{"-p384-only"},
10370 shouldFail: true,
10371 expectedError: ":WRONG_CURVE:",
10372 })
10373
10374 testCases = append(testCases, testCase{
10375 name: "UnnecessaryHelloRetryRequest",
10376 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010377 MaxVersion: VersionTLS13,
10378 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010379 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010380 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010381 },
10382 },
10383 shouldFail: true,
10384 expectedError: ":WRONG_CURVE:",
10385 })
10386
10387 testCases = append(testCases, testCase{
10388 name: "SecondHelloRetryRequest",
10389 config: Config{
10390 MaxVersion: VersionTLS13,
10391 // P-384 requires HelloRetryRequest in BoringSSL.
10392 CurvePreferences: []CurveID{CurveP384},
10393 Bugs: ProtocolBugs{
10394 SecondHelloRetryRequest: true,
10395 },
10396 },
10397 shouldFail: true,
10398 expectedError: ":UNEXPECTED_MESSAGE:",
10399 })
10400
10401 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010402 name: "HelloRetryRequest-Empty",
10403 config: Config{
10404 MaxVersion: VersionTLS13,
10405 Bugs: ProtocolBugs{
10406 AlwaysSendHelloRetryRequest: true,
10407 },
10408 },
10409 shouldFail: true,
10410 expectedError: ":DECODE_ERROR:",
10411 })
10412
10413 testCases = append(testCases, testCase{
10414 name: "HelloRetryRequest-DuplicateCurve",
10415 config: Config{
10416 MaxVersion: VersionTLS13,
10417 // P-384 requires a HelloRetryRequest against BoringSSL's default
10418 // configuration. Assert this ExpectMissingKeyShare.
10419 CurvePreferences: []CurveID{CurveP384},
10420 Bugs: ProtocolBugs{
10421 ExpectMissingKeyShare: true,
10422 DuplicateHelloRetryRequestExtensions: true,
10423 },
10424 },
10425 shouldFail: true,
10426 expectedError: ":DUPLICATE_EXTENSION:",
10427 expectedLocalError: "remote error: illegal parameter",
10428 })
10429
10430 testCases = append(testCases, testCase{
10431 name: "HelloRetryRequest-Cookie",
10432 config: Config{
10433 MaxVersion: VersionTLS13,
10434 Bugs: ProtocolBugs{
10435 SendHelloRetryRequestCookie: []byte("cookie"),
10436 },
10437 },
10438 })
10439
10440 testCases = append(testCases, testCase{
10441 name: "HelloRetryRequest-DuplicateCookie",
10442 config: Config{
10443 MaxVersion: VersionTLS13,
10444 Bugs: ProtocolBugs{
10445 SendHelloRetryRequestCookie: []byte("cookie"),
10446 DuplicateHelloRetryRequestExtensions: true,
10447 },
10448 },
10449 shouldFail: true,
10450 expectedError: ":DUPLICATE_EXTENSION:",
10451 expectedLocalError: "remote error: illegal parameter",
10452 })
10453
10454 testCases = append(testCases, testCase{
10455 name: "HelloRetryRequest-EmptyCookie",
10456 config: Config{
10457 MaxVersion: VersionTLS13,
10458 Bugs: ProtocolBugs{
10459 SendHelloRetryRequestCookie: []byte{},
10460 },
10461 },
10462 shouldFail: true,
10463 expectedError: ":DECODE_ERROR:",
10464 })
10465
10466 testCases = append(testCases, testCase{
10467 name: "HelloRetryRequest-Cookie-Curve",
10468 config: Config{
10469 MaxVersion: VersionTLS13,
10470 // P-384 requires HelloRetryRequest in BoringSSL.
10471 CurvePreferences: []CurveID{CurveP384},
10472 Bugs: ProtocolBugs{
10473 SendHelloRetryRequestCookie: []byte("cookie"),
10474 ExpectMissingKeyShare: true,
10475 },
10476 },
10477 })
10478
10479 testCases = append(testCases, testCase{
10480 name: "HelloRetryRequest-Unknown",
10481 config: Config{
10482 MaxVersion: VersionTLS13,
10483 Bugs: ProtocolBugs{
10484 CustomHelloRetryRequestExtension: "extension",
10485 },
10486 },
10487 shouldFail: true,
10488 expectedError: ":UNEXPECTED_EXTENSION:",
10489 expectedLocalError: "remote error: unsupported extension",
10490 })
10491
10492 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010493 testType: serverTest,
10494 name: "SecondClientHelloMissingKeyShare",
10495 config: Config{
10496 MaxVersion: VersionTLS13,
10497 DefaultCurves: []CurveID{},
10498 Bugs: ProtocolBugs{
10499 SecondClientHelloMissingKeyShare: true,
10500 },
10501 },
10502 shouldFail: true,
10503 expectedError: ":MISSING_KEY_SHARE:",
10504 })
10505
10506 testCases = append(testCases, testCase{
10507 testType: serverTest,
10508 name: "SecondClientHelloWrongCurve",
10509 config: Config{
10510 MaxVersion: VersionTLS13,
10511 DefaultCurves: []CurveID{},
10512 Bugs: ProtocolBugs{
10513 MisinterpretHelloRetryRequestCurve: CurveP521,
10514 },
10515 },
10516 shouldFail: true,
10517 expectedError: ":WRONG_CURVE:",
10518 })
10519
10520 testCases = append(testCases, testCase{
10521 name: "HelloRetryRequestVersionMismatch",
10522 config: Config{
10523 MaxVersion: VersionTLS13,
10524 // P-384 requires HelloRetryRequest in BoringSSL.
10525 CurvePreferences: []CurveID{CurveP384},
10526 Bugs: ProtocolBugs{
10527 SendServerHelloVersion: 0x0305,
10528 },
10529 },
10530 shouldFail: true,
10531 expectedError: ":WRONG_VERSION_NUMBER:",
10532 })
10533
10534 testCases = append(testCases, testCase{
10535 name: "HelloRetryRequestCurveMismatch",
10536 config: Config{
10537 MaxVersion: VersionTLS13,
10538 // P-384 requires HelloRetryRequest in BoringSSL.
10539 CurvePreferences: []CurveID{CurveP384},
10540 Bugs: ProtocolBugs{
10541 // Send P-384 (correct) in the HelloRetryRequest.
10542 SendHelloRetryRequestCurve: CurveP384,
10543 // But send P-256 in the ServerHello.
10544 SendCurve: CurveP256,
10545 },
10546 },
10547 shouldFail: true,
10548 expectedError: ":WRONG_CURVE:",
10549 })
10550
10551 // Test the server selecting a curve that requires a HelloRetryRequest
10552 // without sending it.
10553 testCases = append(testCases, testCase{
10554 name: "SkipHelloRetryRequest",
10555 config: Config{
10556 MaxVersion: VersionTLS13,
10557 // P-384 requires HelloRetryRequest in BoringSSL.
10558 CurvePreferences: []CurveID{CurveP384},
10559 Bugs: ProtocolBugs{
10560 SkipHelloRetryRequest: true,
10561 },
10562 },
10563 shouldFail: true,
10564 expectedError: ":WRONG_CURVE:",
10565 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010566
10567 testCases = append(testCases, testCase{
10568 name: "TLS13-RequestContextInHandshake",
10569 config: Config{
10570 MaxVersion: VersionTLS13,
10571 MinVersion: VersionTLS13,
10572 ClientAuth: RequireAnyClientCert,
10573 Bugs: ProtocolBugs{
10574 SendRequestContext: []byte("request context"),
10575 },
10576 },
10577 flags: []string{
10578 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10579 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10580 },
10581 shouldFail: true,
10582 expectedError: ":DECODE_ERROR:",
10583 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010584
10585 testCases = append(testCases, testCase{
10586 testType: serverTest,
10587 name: "TLS13-TrailingKeyShareData",
10588 config: Config{
10589 MaxVersion: VersionTLS13,
10590 Bugs: ProtocolBugs{
10591 TrailingKeyShareData: true,
10592 },
10593 },
10594 shouldFail: true,
10595 expectedError: ":DECODE_ERROR:",
10596 })
David Benjamin7f78df42016-10-05 22:33:19 -040010597
10598 testCases = append(testCases, testCase{
10599 name: "TLS13-AlwaysSelectPSKIdentity",
10600 config: Config{
10601 MaxVersion: VersionTLS13,
10602 Bugs: ProtocolBugs{
10603 AlwaysSelectPSKIdentity: true,
10604 },
10605 },
10606 shouldFail: true,
10607 expectedError: ":UNEXPECTED_EXTENSION:",
10608 })
10609
10610 testCases = append(testCases, testCase{
10611 name: "TLS13-InvalidPSKIdentity",
10612 config: Config{
10613 MaxVersion: VersionTLS13,
10614 Bugs: ProtocolBugs{
10615 SelectPSKIdentityOnResume: 1,
10616 },
10617 },
10618 resumeSession: true,
10619 shouldFail: true,
10620 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10621 })
David Benjamin1286bee2016-10-07 15:25:06 -040010622
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010623 testCases = append(testCases, testCase{
10624 testType: serverTest,
10625 name: "TLS13-ExtraPSKIdentity",
10626 config: Config{
10627 MaxVersion: VersionTLS13,
10628 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010629 ExtraPSKIdentity: true,
10630 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010631 },
10632 },
10633 resumeSession: true,
10634 })
10635
David Benjamin1286bee2016-10-07 15:25:06 -040010636 // Test that unknown NewSessionTicket extensions are tolerated.
10637 testCases = append(testCases, testCase{
10638 name: "TLS13-CustomTicketExtension",
10639 config: Config{
10640 MaxVersion: VersionTLS13,
10641 Bugs: ProtocolBugs{
10642 CustomTicketExtension: "1234",
10643 },
10644 },
10645 })
Steven Valdez2d850622017-01-11 11:34:52 -050010646
Steven Valdez2d850622017-01-11 11:34:52 -050010647 testCases = append(testCases, testCase{
10648 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010649 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010650 config: Config{
10651 MaxVersion: VersionTLS13,
10652 MaxEarlyDataSize: 16384,
10653 },
10654 resumeConfig: &Config{
10655 MaxVersion: VersionTLS13,
10656 MaxEarlyDataSize: 16384,
10657 Bugs: ProtocolBugs{
10658 AlwaysRejectEarlyData: true,
10659 },
10660 },
10661 resumeSession: true,
10662 flags: []string{
10663 "-enable-early-data",
10664 "-expect-early-data-info",
10665 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010666 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010667 },
10668 })
10669
10670 testCases = append(testCases, testCase{
10671 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010672 name: "TLS13-EarlyData-RejectTicket-Client",
10673 config: Config{
10674 MaxVersion: VersionTLS13,
10675 MaxEarlyDataSize: 16384,
10676 Certificates: []Certificate{rsaCertificate},
10677 },
10678 resumeConfig: &Config{
10679 MaxVersion: VersionTLS13,
10680 MaxEarlyDataSize: 16384,
10681 Certificates: []Certificate{ecdsaP256Certificate},
10682 SessionTicketsDisabled: true,
10683 },
10684 resumeSession: true,
10685 expectResumeRejected: true,
10686 flags: []string{
10687 "-enable-early-data",
10688 "-expect-early-data-info",
10689 "-expect-reject-early-data",
10690 "-on-resume-shim-writes-first",
10691 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10692 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10693 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10694 // Session tickets are disabled, so the runner will not send a ticket.
10695 "-on-retry-expect-no-session",
10696 },
10697 })
10698
10699 testCases = append(testCases, testCase{
10700 testType: clientTest,
10701 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010702 config: Config{
10703 MaxVersion: VersionTLS13,
10704 MaxEarlyDataSize: 16384,
10705 },
10706 resumeConfig: &Config{
10707 MaxVersion: VersionTLS13,
10708 MaxEarlyDataSize: 16384,
10709 Bugs: ProtocolBugs{
10710 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10711 },
10712 },
10713 resumeSession: true,
10714 flags: []string{
10715 "-enable-early-data",
10716 "-expect-early-data-info",
10717 "-expect-reject-early-data",
10718 },
10719 })
10720
10721 // The client must check the server does not send the early_data
10722 // extension while rejecting the session.
10723 testCases = append(testCases, testCase{
10724 testType: clientTest,
10725 name: "TLS13-EarlyDataWithoutResume-Client",
10726 config: Config{
10727 MaxVersion: VersionTLS13,
10728 MaxEarlyDataSize: 16384,
10729 },
10730 resumeConfig: &Config{
10731 MaxVersion: VersionTLS13,
10732 SessionTicketsDisabled: true,
10733 Bugs: ProtocolBugs{
10734 SendEarlyDataExtension: true,
10735 },
10736 },
10737 resumeSession: true,
10738 flags: []string{
10739 "-enable-early-data",
10740 "-expect-early-data-info",
10741 },
10742 shouldFail: true,
10743 expectedError: ":UNEXPECTED_EXTENSION:",
10744 })
10745
10746 // The client must fail with a dedicated error code if the server
10747 // responds with TLS 1.2 when offering 0-RTT.
10748 testCases = append(testCases, testCase{
10749 testType: clientTest,
10750 name: "TLS13-EarlyDataVersionDowngrade-Client",
10751 config: Config{
10752 MaxVersion: VersionTLS13,
10753 MaxEarlyDataSize: 16384,
10754 },
10755 resumeConfig: &Config{
10756 MaxVersion: VersionTLS12,
10757 },
10758 resumeSession: true,
10759 flags: []string{
10760 "-enable-early-data",
10761 "-expect-early-data-info",
10762 },
10763 shouldFail: true,
10764 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10765 })
10766
10767 // Test that the client rejects an (unsolicited) early_data extension if
10768 // the server sent an HRR.
10769 testCases = append(testCases, testCase{
10770 testType: clientTest,
10771 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10772 config: Config{
10773 MaxVersion: VersionTLS13,
10774 MaxEarlyDataSize: 16384,
10775 },
10776 resumeConfig: &Config{
10777 MaxVersion: VersionTLS13,
10778 MaxEarlyDataSize: 16384,
10779 Bugs: ProtocolBugs{
10780 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10781 SendEarlyDataExtension: true,
10782 },
10783 },
10784 resumeSession: true,
10785 flags: []string{
10786 "-enable-early-data",
10787 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010788 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010789 },
10790 shouldFail: true,
10791 expectedError: ":UNEXPECTED_EXTENSION:",
10792 })
10793
10794 fooString := "foo"
10795 barString := "bar"
10796
10797 // Test that the client reports the correct ALPN after a 0-RTT reject
10798 // that changed it.
10799 testCases = append(testCases, testCase{
10800 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010801 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010802 config: Config{
10803 MaxVersion: VersionTLS13,
10804 MaxEarlyDataSize: 16384,
10805 Bugs: ProtocolBugs{
10806 ALPNProtocol: &fooString,
10807 },
10808 },
10809 resumeConfig: &Config{
10810 MaxVersion: VersionTLS13,
10811 MaxEarlyDataSize: 16384,
10812 Bugs: ProtocolBugs{
10813 ALPNProtocol: &barString,
10814 },
10815 },
10816 resumeSession: true,
10817 flags: []string{
10818 "-advertise-alpn", "\x03foo\x03bar",
10819 "-enable-early-data",
10820 "-expect-early-data-info",
10821 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010822 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010823 "-on-resume-expect-alpn", "foo",
10824 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010825 },
10826 })
10827
10828 // Test that the client reports the correct ALPN after a 0-RTT reject if
10829 // ALPN was omitted from the first connection.
10830 testCases = append(testCases, testCase{
10831 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010832 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010833 config: Config{
10834 MaxVersion: VersionTLS13,
10835 MaxEarlyDataSize: 16384,
10836 },
10837 resumeConfig: &Config{
10838 MaxVersion: VersionTLS13,
10839 MaxEarlyDataSize: 16384,
10840 NextProtos: []string{"foo"},
10841 },
10842 resumeSession: true,
10843 flags: []string{
10844 "-advertise-alpn", "\x03foo\x03bar",
10845 "-enable-early-data",
10846 "-expect-early-data-info",
10847 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010848 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010849 "-on-resume-expect-alpn", "",
10850 "-on-retry-expect-alpn", "foo",
10851 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010852 },
10853 })
10854
10855 // Test that the client reports the correct ALPN after a 0-RTT reject if
10856 // ALPN was omitted from the second connection.
10857 testCases = append(testCases, testCase{
10858 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010859 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010860 config: Config{
10861 MaxVersion: VersionTLS13,
10862 MaxEarlyDataSize: 16384,
10863 NextProtos: []string{"foo"},
10864 },
10865 resumeConfig: &Config{
10866 MaxVersion: VersionTLS13,
10867 MaxEarlyDataSize: 16384,
10868 },
10869 resumeSession: true,
10870 flags: []string{
10871 "-advertise-alpn", "\x03foo\x03bar",
10872 "-enable-early-data",
10873 "-expect-early-data-info",
10874 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010875 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010876 "-on-resume-expect-alpn", "foo",
10877 "-on-retry-expect-alpn", "",
10878 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010879 },
10880 })
10881
10882 // Test that the client enforces ALPN match on 0-RTT accept.
10883 testCases = append(testCases, testCase{
10884 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010885 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010886 config: Config{
10887 MaxVersion: VersionTLS13,
10888 MaxEarlyDataSize: 16384,
10889 Bugs: ProtocolBugs{
10890 ALPNProtocol: &fooString,
10891 },
10892 },
10893 resumeConfig: &Config{
10894 MaxVersion: VersionTLS13,
10895 MaxEarlyDataSize: 16384,
10896 Bugs: ProtocolBugs{
10897 AlwaysAcceptEarlyData: true,
10898 ALPNProtocol: &barString,
10899 },
10900 },
10901 resumeSession: true,
10902 flags: []string{
10903 "-advertise-alpn", "\x03foo\x03bar",
10904 "-enable-early-data",
10905 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010906 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010907 "-on-resume-expect-alpn", "foo",
10908 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010909 },
10910 shouldFail: true,
10911 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10912 })
10913
10914 // Test that the server correctly rejects 0-RTT when the previous
10915 // session did not allow early data on resumption.
10916 testCases = append(testCases, testCase{
10917 testType: serverTest,
10918 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10919 config: Config{
10920 MaxVersion: VersionTLS13,
10921 },
10922 resumeConfig: &Config{
10923 MaxVersion: VersionTLS13,
10924 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010925 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010926 ExpectEarlyDataAccepted: false,
10927 },
10928 },
10929 resumeSession: true,
10930 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010931 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010932 "-expect-reject-early-data",
10933 },
10934 })
10935
10936 // Test that we reject early data where ALPN is omitted from the first
10937 // connection.
10938 testCases = append(testCases, testCase{
10939 testType: serverTest,
10940 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10941 config: Config{
10942 MaxVersion: VersionTLS13,
10943 NextProtos: []string{},
10944 },
10945 resumeConfig: &Config{
10946 MaxVersion: VersionTLS13,
10947 NextProtos: []string{"foo"},
10948 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010949 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010950 ExpectEarlyDataAccepted: false,
10951 },
10952 },
10953 resumeSession: true,
10954 flags: []string{
10955 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010956 "-on-initial-select-alpn", "",
10957 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010958 },
10959 })
10960
10961 // Test that we reject early data where ALPN is omitted from the second
10962 // connection.
10963 testCases = append(testCases, testCase{
10964 testType: serverTest,
10965 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10966 config: Config{
10967 MaxVersion: VersionTLS13,
10968 NextProtos: []string{"foo"},
10969 },
10970 resumeConfig: &Config{
10971 MaxVersion: VersionTLS13,
10972 NextProtos: []string{},
10973 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010974 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010975 ExpectEarlyDataAccepted: false,
10976 },
10977 },
10978 resumeSession: true,
10979 flags: []string{
10980 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010981 "-on-initial-select-alpn", "foo",
10982 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010983 },
10984 })
10985
10986 // Test that we reject early data with mismatched ALPN.
10987 testCases = append(testCases, testCase{
10988 testType: serverTest,
10989 name: "TLS13-EarlyData-ALPNMismatch-Server",
10990 config: Config{
10991 MaxVersion: VersionTLS13,
10992 NextProtos: []string{"foo"},
10993 },
10994 resumeConfig: &Config{
10995 MaxVersion: VersionTLS13,
10996 NextProtos: []string{"bar"},
10997 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010998 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010999 ExpectEarlyDataAccepted: false,
11000 },
11001 },
11002 resumeSession: true,
11003 flags: []string{
11004 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011005 "-on-initial-select-alpn", "foo",
11006 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011007 },
11008 })
11009
David Benjamin6bb507b2017-03-29 16:35:57 -050011010 // Test that the client offering 0-RTT and Channel ID forbids the server
11011 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011012 testCases = append(testCases, testCase{
11013 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011014 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011015 config: Config{
11016 MaxVersion: VersionTLS13,
11017 MaxEarlyDataSize: 16384,
11018 RequestChannelID: true,
11019 },
11020 resumeSession: true,
11021 expectChannelID: true,
11022 shouldFail: true,
11023 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11024 flags: []string{
11025 "-enable-early-data",
11026 "-expect-early-data-info",
11027 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11028 },
11029 })
11030
David Benjamin6bb507b2017-03-29 16:35:57 -050011031 // Test that the client offering Channel ID and 0-RTT allows the server
11032 // to decline 0-RTT.
11033 testCases = append(testCases, testCase{
11034 testType: clientTest,
11035 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11036 config: Config{
11037 MaxVersion: VersionTLS13,
11038 MaxEarlyDataSize: 16384,
11039 RequestChannelID: true,
11040 Bugs: ProtocolBugs{
11041 AlwaysRejectEarlyData: true,
11042 },
11043 },
11044 resumeSession: true,
11045 expectChannelID: true,
11046 flags: []string{
11047 "-enable-early-data",
11048 "-expect-early-data-info",
11049 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11050 "-expect-reject-early-data",
11051 },
11052 })
11053
11054 // Test that the client offering Channel ID and 0-RTT allows the server
11055 // to decline Channel ID.
11056 testCases = append(testCases, testCase{
11057 testType: clientTest,
11058 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11059 config: Config{
11060 MaxVersion: VersionTLS13,
11061 MaxEarlyDataSize: 16384,
11062 },
11063 resumeSession: true,
11064 flags: []string{
11065 "-enable-early-data",
11066 "-expect-early-data-info",
11067 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11068 "-expect-accept-early-data",
11069 },
11070 })
11071
11072 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11073 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011074 testCases = append(testCases, testCase{
11075 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011076 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011077 config: Config{
11078 MaxVersion: VersionTLS13,
11079 ChannelID: channelIDKey,
11080 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011081 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011082 ExpectEarlyDataAccepted: false,
11083 },
11084 },
11085 resumeSession: true,
11086 expectChannelID: true,
11087 flags: []string{
11088 "-enable-early-data",
11089 "-expect-reject-early-data",
11090 "-expect-channel-id",
11091 base64.StdEncoding.EncodeToString(channelIDBytes),
11092 },
11093 })
11094
David Benjamin6bb507b2017-03-29 16:35:57 -050011095 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11096 // if not offered Channel ID.
11097 testCases = append(testCases, testCase{
11098 testType: serverTest,
11099 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11100 config: Config{
11101 MaxVersion: VersionTLS13,
11102 Bugs: ProtocolBugs{
11103 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11104 ExpectEarlyDataAccepted: true,
11105 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11106 },
11107 },
11108 resumeSession: true,
11109 expectChannelID: false,
11110 flags: []string{
11111 "-enable-early-data",
11112 "-expect-accept-early-data",
11113 "-enable-channel-id",
11114 },
11115 })
11116
David Benjamin32c89272017-03-26 13:54:21 -050011117 // Test that the server rejects 0-RTT streams without end_of_early_data.
11118 // The subsequent records should fail to decrypt.
11119 testCases = append(testCases, testCase{
11120 testType: serverTest,
11121 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11122 config: Config{
11123 MaxVersion: VersionTLS13,
11124 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011125 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011126 ExpectEarlyDataAccepted: true,
11127 SkipEndOfEarlyData: true,
11128 },
11129 },
11130 resumeSession: true,
11131 flags: []string{"-enable-early-data"},
11132 shouldFail: true,
11133 expectedLocalError: "remote error: bad record MAC",
11134 expectedError: ":BAD_DECRYPT:",
11135 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011136
11137 testCases = append(testCases, testCase{
11138 testType: serverTest,
11139 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11140 config: Config{
11141 MaxVersion: VersionTLS13,
11142 },
11143 resumeConfig: &Config{
11144 MaxVersion: VersionTLS13,
11145 Bugs: ProtocolBugs{
11146 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11147 SendStrayEarlyHandshake: true,
11148 ExpectEarlyDataAccepted: true},
11149 },
11150 resumeSession: true,
11151 shouldFail: true,
11152 expectedError: ":UNEXPECTED_RECORD:",
11153 expectedLocalError: "remote error: unexpected message",
11154 flags: []string{
11155 "-enable-early-data",
11156 },
11157 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011158}
11159
David Benjaminabbbee12016-10-31 19:20:42 -040011160func addTLS13CipherPreferenceTests() {
11161 // Test that client preference is honored if the shim has AES hardware
11162 // and ChaCha20-Poly1305 is preferred otherwise.
11163 testCases = append(testCases, testCase{
11164 testType: serverTest,
11165 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11166 config: Config{
11167 MaxVersion: VersionTLS13,
11168 CipherSuites: []uint16{
11169 TLS_CHACHA20_POLY1305_SHA256,
11170 TLS_AES_128_GCM_SHA256,
11171 },
11172 },
11173 flags: []string{
11174 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11175 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11176 },
11177 })
11178
11179 testCases = append(testCases, testCase{
11180 testType: serverTest,
11181 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11182 config: Config{
11183 MaxVersion: VersionTLS13,
11184 CipherSuites: []uint16{
11185 TLS_AES_128_GCM_SHA256,
11186 TLS_CHACHA20_POLY1305_SHA256,
11187 },
11188 },
11189 flags: []string{
11190 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11191 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11192 },
11193 })
11194
11195 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11196 // whether it has AES hardware.
11197 testCases = append(testCases, testCase{
11198 name: "TLS13-CipherPreference-Client",
11199 config: Config{
11200 MaxVersion: VersionTLS13,
11201 // Use the client cipher order. (This is the default but
11202 // is listed to be explicit.)
11203 PreferServerCipherSuites: false,
11204 },
11205 flags: []string{
11206 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11207 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11208 },
11209 })
11210}
11211
David Benjaminf3fbade2016-09-19 13:08:16 -040011212func addPeekTests() {
11213 // Test SSL_peek works, including on empty records.
11214 testCases = append(testCases, testCase{
11215 name: "Peek-Basic",
11216 sendEmptyRecords: 1,
11217 flags: []string{"-peek-then-read"},
11218 })
11219
11220 // Test SSL_peek can drive the initial handshake.
11221 testCases = append(testCases, testCase{
11222 name: "Peek-ImplicitHandshake",
11223 flags: []string{
11224 "-peek-then-read",
11225 "-implicit-handshake",
11226 },
11227 })
11228
11229 // Test SSL_peek can discover and drive a renegotiation.
11230 testCases = append(testCases, testCase{
11231 name: "Peek-Renegotiate",
11232 config: Config{
11233 MaxVersion: VersionTLS12,
11234 },
11235 renegotiate: 1,
11236 flags: []string{
11237 "-peek-then-read",
11238 "-renegotiate-freely",
11239 "-expect-total-renegotiations", "1",
11240 },
11241 })
11242
11243 // Test SSL_peek can discover a close_notify.
11244 testCases = append(testCases, testCase{
11245 name: "Peek-Shutdown",
11246 config: Config{
11247 Bugs: ProtocolBugs{
11248 ExpectCloseNotify: true,
11249 },
11250 },
11251 flags: []string{
11252 "-peek-then-read",
11253 "-check-close-notify",
11254 },
11255 })
11256
11257 // Test SSL_peek can discover an alert.
11258 testCases = append(testCases, testCase{
11259 name: "Peek-Alert",
11260 config: Config{
11261 Bugs: ProtocolBugs{
11262 SendSpuriousAlert: alertRecordOverflow,
11263 },
11264 },
11265 flags: []string{"-peek-then-read"},
11266 shouldFail: true,
11267 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11268 })
11269
11270 // Test SSL_peek can handle KeyUpdate.
11271 testCases = append(testCases, testCase{
11272 name: "Peek-KeyUpdate",
11273 config: Config{
11274 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011275 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011276 sendKeyUpdates: 1,
11277 keyUpdateRequest: keyUpdateNotRequested,
11278 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011279 })
11280}
11281
David Benjamine6f22212016-11-08 14:28:24 -050011282func addRecordVersionTests() {
11283 for _, ver := range tlsVersions {
11284 // Test that the record version is enforced.
11285 testCases = append(testCases, testCase{
11286 name: "CheckRecordVersion-" + ver.name,
11287 config: Config{
11288 MinVersion: ver.version,
11289 MaxVersion: ver.version,
11290 Bugs: ProtocolBugs{
11291 SendRecordVersion: 0x03ff,
11292 },
11293 },
11294 shouldFail: true,
11295 expectedError: ":WRONG_VERSION_NUMBER:",
11296 })
11297
11298 // Test that the ClientHello may use any record version, for
11299 // compatibility reasons.
11300 testCases = append(testCases, testCase{
11301 testType: serverTest,
11302 name: "LooseInitialRecordVersion-" + ver.name,
11303 config: Config{
11304 MinVersion: ver.version,
11305 MaxVersion: ver.version,
11306 Bugs: ProtocolBugs{
11307 SendInitialRecordVersion: 0x03ff,
11308 },
11309 },
11310 })
11311
11312 // Test that garbage ClientHello record versions are rejected.
11313 testCases = append(testCases, testCase{
11314 testType: serverTest,
11315 name: "GarbageInitialRecordVersion-" + ver.name,
11316 config: Config{
11317 MinVersion: ver.version,
11318 MaxVersion: ver.version,
11319 Bugs: ProtocolBugs{
11320 SendInitialRecordVersion: 0xffff,
11321 },
11322 },
11323 shouldFail: true,
11324 expectedError: ":WRONG_VERSION_NUMBER:",
11325 })
11326 }
11327}
11328
David Benjamin2c516452016-11-15 10:16:54 +090011329func addCertificateTests() {
11330 // Test that a certificate chain with intermediate may be sent and
11331 // received as both client and server.
11332 for _, ver := range tlsVersions {
11333 testCases = append(testCases, testCase{
11334 testType: clientTest,
11335 name: "SendReceiveIntermediate-Client-" + ver.name,
11336 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011337 MinVersion: ver.version,
11338 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011339 Certificates: []Certificate{rsaChainCertificate},
11340 ClientAuth: RequireAnyClientCert,
11341 },
11342 expectPeerCertificate: &rsaChainCertificate,
11343 flags: []string{
11344 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11345 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11346 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11347 },
11348 })
11349
11350 testCases = append(testCases, testCase{
11351 testType: serverTest,
11352 name: "SendReceiveIntermediate-Server-" + ver.name,
11353 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011354 MinVersion: ver.version,
11355 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011356 Certificates: []Certificate{rsaChainCertificate},
11357 },
11358 expectPeerCertificate: &rsaChainCertificate,
11359 flags: []string{
11360 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11361 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11362 "-require-any-client-certificate",
11363 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11364 },
11365 })
11366 }
11367}
11368
David Benjaminbbaf3672016-11-17 10:53:09 +090011369func addRetainOnlySHA256ClientCertTests() {
11370 for _, ver := range tlsVersions {
11371 // Test that enabling
11372 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11373 // actually requesting a client certificate is a no-op.
11374 testCases = append(testCases, testCase{
11375 testType: serverTest,
11376 name: "RetainOnlySHA256-NoCert-" + ver.name,
11377 config: Config{
11378 MinVersion: ver.version,
11379 MaxVersion: ver.version,
11380 },
11381 flags: []string{
11382 "-retain-only-sha256-client-cert-initial",
11383 "-retain-only-sha256-client-cert-resume",
11384 },
11385 resumeSession: true,
11386 })
11387
11388 // Test that when retaining only a SHA-256 certificate is
11389 // enabled, the hash appears as expected.
11390 testCases = append(testCases, testCase{
11391 testType: serverTest,
11392 name: "RetainOnlySHA256-Cert-" + ver.name,
11393 config: Config{
11394 MinVersion: ver.version,
11395 MaxVersion: ver.version,
11396 Certificates: []Certificate{rsaCertificate},
11397 },
11398 flags: []string{
11399 "-verify-peer",
11400 "-retain-only-sha256-client-cert-initial",
11401 "-retain-only-sha256-client-cert-resume",
11402 "-expect-sha256-client-cert-initial",
11403 "-expect-sha256-client-cert-resume",
11404 },
11405 resumeSession: true,
11406 })
11407
11408 // Test that when the config changes from on to off, a
11409 // resumption is rejected because the server now wants the full
11410 // certificate chain.
11411 testCases = append(testCases, testCase{
11412 testType: serverTest,
11413 name: "RetainOnlySHA256-OnOff-" + ver.name,
11414 config: Config{
11415 MinVersion: ver.version,
11416 MaxVersion: ver.version,
11417 Certificates: []Certificate{rsaCertificate},
11418 },
11419 flags: []string{
11420 "-verify-peer",
11421 "-retain-only-sha256-client-cert-initial",
11422 "-expect-sha256-client-cert-initial",
11423 },
11424 resumeSession: true,
11425 expectResumeRejected: true,
11426 })
11427
11428 // Test that when the config changes from off to on, a
11429 // resumption is rejected because the server now wants just the
11430 // hash.
11431 testCases = append(testCases, testCase{
11432 testType: serverTest,
11433 name: "RetainOnlySHA256-OffOn-" + ver.name,
11434 config: Config{
11435 MinVersion: ver.version,
11436 MaxVersion: ver.version,
11437 Certificates: []Certificate{rsaCertificate},
11438 },
11439 flags: []string{
11440 "-verify-peer",
11441 "-retain-only-sha256-client-cert-resume",
11442 "-expect-sha256-client-cert-resume",
11443 },
11444 resumeSession: true,
11445 expectResumeRejected: true,
11446 })
11447 }
11448}
11449
Adam Langleya4b91982016-12-12 12:05:53 -080011450func addECDSAKeyUsageTests() {
11451 p256 := elliptic.P256()
11452 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11453 if err != nil {
11454 panic(err)
11455 }
11456
11457 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11458 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11459 if err != nil {
11460 panic(err)
11461 }
11462
11463 template := x509.Certificate{
11464 SerialNumber: serialNumber,
11465 Subject: pkix.Name{
11466 Organization: []string{"Acme Co"},
11467 },
11468 NotBefore: time.Now(),
11469 NotAfter: time.Now(),
11470
11471 // An ECC certificate with only the keyAgreement key usgae may
11472 // be used with ECDH, but not ECDSA.
11473 KeyUsage: x509.KeyUsageKeyAgreement,
11474 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11475 BasicConstraintsValid: true,
11476 }
11477
11478 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11479 if err != nil {
11480 panic(err)
11481 }
11482
11483 cert := Certificate{
11484 Certificate: [][]byte{derBytes},
11485 PrivateKey: priv,
11486 }
11487
11488 for _, ver := range tlsVersions {
11489 if ver.version < VersionTLS12 {
11490 continue
11491 }
11492
11493 testCases = append(testCases, testCase{
11494 testType: clientTest,
11495 name: "ECDSAKeyUsage-" + ver.name,
11496 config: Config{
11497 MinVersion: ver.version,
11498 MaxVersion: ver.version,
11499 Certificates: []Certificate{cert},
11500 },
11501 shouldFail: true,
11502 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11503 })
11504 }
11505}
11506
David Benjamin8c26d752017-03-26 15:13:51 -050011507func addExtraHandshakeTests() {
11508 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11509 // to ensure there is no transport I/O.
11510 testCases = append(testCases, testCase{
11511 testType: clientTest,
11512 name: "ExtraHandshake-Client-TLS12",
11513 config: Config{
11514 MinVersion: VersionTLS12,
11515 MaxVersion: VersionTLS12,
11516 },
11517 flags: []string{
11518 "-async",
11519 "-no-op-extra-handshake",
11520 },
11521 })
11522 testCases = append(testCases, testCase{
11523 testType: serverTest,
11524 name: "ExtraHandshake-Server-TLS12",
11525 config: Config{
11526 MinVersion: VersionTLS12,
11527 MaxVersion: VersionTLS12,
11528 },
11529 flags: []string{
11530 "-async",
11531 "-no-op-extra-handshake",
11532 },
11533 })
11534 testCases = append(testCases, testCase{
11535 testType: clientTest,
11536 name: "ExtraHandshake-Client-TLS13",
11537 config: Config{
11538 MinVersion: VersionTLS13,
11539 MaxVersion: VersionTLS13,
11540 },
11541 flags: []string{
11542 "-async",
11543 "-no-op-extra-handshake",
11544 },
11545 })
11546 testCases = append(testCases, testCase{
11547 testType: serverTest,
11548 name: "ExtraHandshake-Server-TLS13",
11549 config: Config{
11550 MinVersion: VersionTLS13,
11551 MaxVersion: VersionTLS13,
11552 },
11553 flags: []string{
11554 "-async",
11555 "-no-op-extra-handshake",
11556 },
11557 })
11558
11559 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11560 testCases = append(testCases, testCase{
11561 testType: serverTest,
11562 name: "ExtraHandshake-Server-EarlyData-TLS13",
11563 config: Config{
11564 MaxVersion: VersionTLS13,
11565 MinVersion: VersionTLS13,
11566 Bugs: ProtocolBugs{
11567 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11568 ExpectEarlyDataAccepted: true,
11569 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11570 },
11571 },
11572 messageCount: 2,
11573 resumeSession: true,
11574 flags: []string{
11575 "-async",
11576 "-enable-early-data",
11577 "-expect-accept-early-data",
11578 "-no-op-extra-handshake",
11579 },
11580 })
11581
11582 // An extra SSL_do_handshake drives the handshake to completion in False
11583 // Start. We test this by handshaking twice and asserting the False
11584 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11585 // how the test works.
11586 testCases = append(testCases, testCase{
11587 testType: clientTest,
11588 name: "ExtraHandshake-FalseStart",
11589 config: Config{
11590 MaxVersion: VersionTLS12,
11591 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11592 NextProtos: []string{"foo"},
11593 Bugs: ProtocolBugs{
11594 ExpectFalseStart: true,
11595 AlertBeforeFalseStartTest: alertAccessDenied,
11596 },
11597 },
11598 flags: []string{
11599 "-handshake-twice",
11600 "-false-start",
11601 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011602 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011603 },
11604 shimWritesFirst: true,
11605 shouldFail: true,
11606 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11607 expectedLocalError: "tls: peer did not false start: EOF",
11608 })
11609}
11610
Adam Langley7c803a62015-06-15 15:35:05 -070011611func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011612 defer wg.Done()
11613
11614 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011615 var err error
11616
David Benjaminba28dfc2016-11-15 17:47:21 +090011617 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011618 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11619 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011620 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011621 if err != nil {
11622 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11623 }
11624 break
11625 }
11626 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011627 } else if *repeatUntilFailure {
11628 for err == nil {
11629 statusChan <- statusMsg{test: test, started: true}
11630 err = runTest(test, shimPath, -1)
11631 }
11632 } else {
11633 statusChan <- statusMsg{test: test, started: true}
11634 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011635 }
Adam Langley95c29f32014-06-20 12:00:00 -070011636 statusChan <- statusMsg{test: test, err: err}
11637 }
11638}
11639
11640type statusMsg struct {
11641 test *testCase
11642 started bool
11643 err error
11644}
11645
David Benjamin5f237bc2015-02-11 17:14:15 -050011646func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011647 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011648
David Benjamin5f237bc2015-02-11 17:14:15 -050011649 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011650 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011651 if !*pipe {
11652 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011653 var erase string
11654 for i := 0; i < lineLen; i++ {
11655 erase += "\b \b"
11656 }
11657 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011658 }
11659
Adam Langley95c29f32014-06-20 12:00:00 -070011660 if msg.started {
11661 started++
11662 } else {
11663 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011664
11665 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011666 if msg.err == errUnimplemented {
11667 if *pipe {
11668 // Print each test instead of a status line.
11669 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11670 }
11671 unimplemented++
11672 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11673 } else {
11674 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11675 failed++
11676 testOutput.addResult(msg.test.name, "FAIL")
11677 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011678 } else {
11679 if *pipe {
11680 // Print each test instead of a status line.
11681 fmt.Printf("PASSED (%s)\n", msg.test.name)
11682 }
11683 testOutput.addResult(msg.test.name, "PASS")
11684 }
Adam Langley95c29f32014-06-20 12:00:00 -070011685 }
11686
David Benjamin5f237bc2015-02-11 17:14:15 -050011687 if !*pipe {
11688 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011689 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011690 lineLen = len(line)
11691 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011692 }
Adam Langley95c29f32014-06-20 12:00:00 -070011693 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011694
11695 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011696}
11697
11698func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011699 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011700 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011701 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011702
Adam Langley7c803a62015-06-15 15:35:05 -070011703 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011704 addCipherSuiteTests()
11705 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011706 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011707 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011708 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011709 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011710 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011711 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011712 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011713 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011714 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011715 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011716 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011717 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011718 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011719 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011720 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011721 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011722 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011723 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011724 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011725 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011726 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011727 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011728 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011729 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011730 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011731 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011732 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011733 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011734 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011735 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011736 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011737 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011738
11739 var wg sync.WaitGroup
11740
Adam Langley7c803a62015-06-15 15:35:05 -070011741 statusChan := make(chan statusMsg, *numWorkers)
11742 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011743 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011744
EKRf71d7ed2016-08-06 13:25:12 -070011745 if len(*shimConfigFile) != 0 {
11746 encoded, err := ioutil.ReadFile(*shimConfigFile)
11747 if err != nil {
11748 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11749 os.Exit(1)
11750 }
11751
11752 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11753 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11754 os.Exit(1)
11755 }
11756 }
11757
David Benjamin025b3d32014-07-01 19:53:04 -040011758 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011759
Adam Langley7c803a62015-06-15 15:35:05 -070011760 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011761 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011762 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011763 }
11764
David Benjamin270f0a72016-03-17 14:41:36 -040011765 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011766 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011767 matched := true
11768 if len(*testToRun) != 0 {
11769 var err error
11770 matched, err = filepath.Match(*testToRun, testCases[i].name)
11771 if err != nil {
11772 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11773 os.Exit(1)
11774 }
11775 }
11776
EKRf71d7ed2016-08-06 13:25:12 -070011777 if !*includeDisabled {
11778 for pattern := range shimConfig.DisabledTests {
11779 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11780 if err != nil {
11781 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11782 os.Exit(1)
11783 }
11784
11785 if isDisabled {
11786 matched = false
11787 break
11788 }
11789 }
11790 }
11791
David Benjamin17e12922016-07-28 18:04:43 -040011792 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011793 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011794 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011795
11796 // Only run one test if repeating until failure.
11797 if *repeatUntilFailure {
11798 break
11799 }
Adam Langley95c29f32014-06-20 12:00:00 -070011800 }
11801 }
David Benjamin17e12922016-07-28 18:04:43 -040011802
David Benjamin270f0a72016-03-17 14:41:36 -040011803 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011804 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011805 os.Exit(1)
11806 }
Adam Langley95c29f32014-06-20 12:00:00 -070011807
11808 close(testChan)
11809 wg.Wait()
11810 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011811 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011812
11813 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011814
11815 if *jsonOutput != "" {
11816 if err := testOutput.writeTo(*jsonOutput); err != nil {
11817 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11818 }
11819 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011820
EKR842ae6c2016-07-27 09:22:05 +020011821 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11822 os.Exit(1)
11823 }
11824
11825 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011826 os.Exit(1)
11827 }
Adam Langley95c29f32014-06-20 12:00:00 -070011828}