blob: 7ba0c085b2e841689d01d4398d08555d15d370ea [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 Benjaminc07afb72016-09-22 10:18:58 -0400468func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if len(data) == 0 {
470 return
471 }
472
473 protocol := "tls"
474 if test.protocol == dtls {
475 protocol = "dtls"
476 }
477
478 side := "client"
479 if test.testType == serverTest {
480 side = "server"
481 }
482
483 dir := path.Join(*transcriptDir, protocol, side)
484 if err := os.MkdirAll(dir, 0755); err != nil {
485 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
486 return
487 }
488
David Benjaminc07afb72016-09-22 10:18:58 -0400489 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500490 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
491 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
492 }
493}
494
David Benjamin3ed59772016-03-08 12:50:21 -0500495// A timeoutConn implements an idle timeout on each Read and Write operation.
496type timeoutConn struct {
497 net.Conn
498 timeout time.Duration
499}
500
501func (t *timeoutConn) Read(b []byte) (int, error) {
502 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
503 return 0, err
504 }
505 return t.Conn.Read(b)
506}
507
508func (t *timeoutConn) Write(b []byte) (int, error) {
509 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
510 return 0, err
511 }
512 return t.Conn.Write(b)
513}
514
David Benjaminc07afb72016-09-22 10:18:58 -0400515func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400516 if !test.noSessionCache {
517 if config.ClientSessionCache == nil {
518 config.ClientSessionCache = NewLRUClientSessionCache(1)
519 }
520 if config.ServerSessionCache == nil {
521 config.ServerSessionCache = NewLRUServerSessionCache(1)
522 }
523 }
524 if test.testType == clientTest {
525 if len(config.Certificates) == 0 {
526 config.Certificates = []Certificate{rsaCertificate}
527 }
528 } else {
529 // Supply a ServerName to ensure a constant session cache key,
530 // rather than falling back to net.Conn.RemoteAddr.
531 if len(config.ServerName) == 0 {
532 config.ServerName = "test"
533 }
534 }
535 if *fuzzer {
536 config.Bugs.NullAllCiphers = true
537 }
David Benjamin01a90572016-09-22 00:11:43 -0400538 if *deterministic {
539 config.Time = func() time.Time { return time.Unix(1234, 1234) }
540 }
David Benjamine54af062016-08-08 19:21:18 -0400541
David Benjamin01784b42016-06-07 18:00:52 -0400542 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500543
David Benjamin6fd297b2014-08-11 18:43:38 -0400544 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500545 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
546 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500547 }
548
David Benjamin9867b7d2016-03-01 23:25:48 -0500549 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500550 local, peer := "client", "server"
551 if test.testType == clientTest {
552 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500553 }
David Benjaminebda9b32015-11-02 15:33:18 -0500554 connDebug := &recordingConn{
555 Conn: conn,
556 isDatagram: test.protocol == dtls,
557 local: local,
558 peer: peer,
559 }
560 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500561 if *flagDebug {
562 defer connDebug.WriteTo(os.Stdout)
563 }
564 if len(*transcriptDir) != 0 {
565 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400566 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500567 }()
568 }
David Benjaminebda9b32015-11-02 15:33:18 -0500569
570 if config.Bugs.PacketAdaptor != nil {
571 config.Bugs.PacketAdaptor.debug = connDebug
572 }
573 }
574
575 if test.replayWrites {
576 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400577 }
578
David Benjamin3ed59772016-03-08 12:50:21 -0500579 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500580 if test.damageFirstWrite {
581 connDamage = newDamageAdaptor(conn)
582 conn = connDamage
583 }
584
David Benjamin6fd297b2014-08-11 18:43:38 -0400585 if test.sendPrefix != "" {
586 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
587 return err
588 }
David Benjamin98e882e2014-08-08 13:24:34 -0400589 }
590
David Benjamin1d5c83e2014-07-22 19:20:02 -0400591 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400592 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400593 if test.protocol == dtls {
594 tlsConn = DTLSServer(conn, config)
595 } else {
596 tlsConn = Server(conn, config)
597 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598 } else {
599 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400600 if test.protocol == dtls {
601 tlsConn = DTLSClient(conn, config)
602 } else {
603 tlsConn = Client(conn, config)
604 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400605 }
David Benjamin30789da2015-08-29 22:56:45 -0400606 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400607
Adam Langley95c29f32014-06-20 12:00:00 -0700608 if err := tlsConn.Handshake(); err != nil {
609 return err
610 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700611
David Benjamin01fe8202014-09-24 15:21:44 -0400612 // TODO(davidben): move all per-connection expectations into a dedicated
613 // expectations struct that can be specified separately for the two
614 // legs.
615 expectedVersion := test.expectedVersion
616 if isResume && test.expectedResumeVersion != 0 {
617 expectedVersion = test.expectedResumeVersion
618 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700619 connState := tlsConn.ConnectionState()
620 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400621 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400622 }
623
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700624 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400625 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
626 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700627 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
628 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
629 }
David Benjamin90da8c82015-04-20 14:57:57 -0400630
David Benjamina08e49d2014-08-24 01:46:07 -0400631 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700632 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400633 if channelID == nil {
634 return fmt.Errorf("no channel ID negotiated")
635 }
636 if channelID.Curve != channelIDKey.Curve ||
637 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
638 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
639 return fmt.Errorf("incorrect channel ID")
640 }
641 }
642
David Benjaminae2888f2014-09-06 12:58:58 -0400643 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700644 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400645 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
646 }
647 }
648
David Benjaminc7ce9772015-10-09 19:32:41 -0400649 if test.expectNoNextProto {
650 if actual := connState.NegotiatedProtocol; actual != "" {
651 return fmt.Errorf("got unexpected next proto %s", actual)
652 }
653 }
654
David Benjaminfc7b0862014-09-06 13:21:53 -0400655 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700656 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400657 return fmt.Errorf("next proto type mismatch")
658 }
659 }
660
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700661 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500662 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
663 }
664
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100665 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300666 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100667 }
668
Paul Lietar4fac72e2015-09-09 13:44:55 +0100669 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
670 return fmt.Errorf("SCT list mismatch")
671 }
672
Nick Harper60edffd2016-06-21 15:19:24 -0700673 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
674 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400675 }
676
Steven Valdez5440fe02016-07-18 12:40:30 -0400677 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
678 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
679 }
680
David Benjamin2c516452016-11-15 10:16:54 +0900681 if test.expectPeerCertificate != nil {
682 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
683 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
684 }
685 for i, cert := range connState.PeerCertificates {
686 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
687 return fmt.Errorf("peer certificate %d did not match", i+1)
688 }
689 }
690 }
691
David Benjaminc565ebb2015-04-03 04:06:36 -0400692 if test.exportKeyingMaterial > 0 {
693 actual := make([]byte, test.exportKeyingMaterial)
694 if _, err := io.ReadFull(tlsConn, actual); err != nil {
695 return err
696 }
697 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
698 if err != nil {
699 return err
700 }
701 if !bytes.Equal(actual, expected) {
702 return fmt.Errorf("keying material mismatch")
703 }
704 }
705
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700706 if test.testTLSUnique {
707 var peersValue [12]byte
708 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
709 return err
710 }
711 expected := tlsConn.ConnectionState().TLSUnique
712 if !bytes.Equal(peersValue[:], expected) {
713 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
714 }
715 }
716
David Benjamin47921102016-07-28 11:29:18 -0400717 if test.sendHalfHelloRequest {
718 tlsConn.SendHalfHelloRequest()
719 }
720
Steven Valdeze831a812017-03-09 14:56:07 -0500721 shimPrefix := test.shimPrefix
722 if isResume {
723 shimPrefix = test.resumeShimPrefix
724 }
725 if test.shimWritesFirst || test.readWithUnfinishedWrite {
726 shimPrefix = "hello"
727 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400728 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400729 // If readWithUnfinishedWrite is set, the shim prefix will be
730 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500731 if shimPrefix != "" && !test.readWithUnfinishedWrite {
732 var buf = make([]byte, len(shimPrefix))
733 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400734 if err != nil {
735 return err
736 }
Steven Valdeze831a812017-03-09 14:56:07 -0500737 if string(buf) != shimPrefix {
738 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400739 }
Steven Valdeze831a812017-03-09 14:56:07 -0500740 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400741 }
742
Adam Langleycf2d4f42014-10-28 19:06:14 -0700743 if test.renegotiateCiphers != nil {
744 config.CipherSuites = test.renegotiateCiphers
745 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400746 for i := 0; i < test.renegotiate; i++ {
747 if err := tlsConn.Renegotiate(); err != nil {
748 return err
749 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700750 }
751 } else if test.renegotiateCiphers != nil {
752 panic("renegotiateCiphers without renegotiate")
753 }
754
David Benjamin5fa3eba2015-01-22 16:35:40 -0500755 if test.damageFirstWrite {
756 connDamage.setDamage(true)
757 tlsConn.Write([]byte("DAMAGED WRITE"))
758 connDamage.setDamage(false)
759 }
760
David Benjamin8e6db492015-07-25 18:29:23 -0400761 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700762 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400763 if test.protocol == dtls {
764 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
765 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700766 // Read until EOF.
767 _, err := io.Copy(ioutil.Discard, tlsConn)
768 return err
769 }
David Benjamin4417d052015-04-05 04:17:25 -0400770 if messageLen == 0 {
771 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700772 }
Adam Langley95c29f32014-06-20 12:00:00 -0700773
David Benjamin8e6db492015-07-25 18:29:23 -0400774 messageCount := test.messageCount
775 if messageCount == 0 {
776 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400777 }
778
David Benjamin8e6db492015-07-25 18:29:23 -0400779 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400780 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400781 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400782 }
783
David Benjamin8e6db492015-07-25 18:29:23 -0400784 for i := 0; i < test.sendEmptyRecords; i++ {
785 tlsConn.Write(nil)
786 }
787
788 for i := 0; i < test.sendWarningAlerts; i++ {
789 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
790 }
791
David Benjamin24e58862017-06-14 18:45:29 -0400792 if test.sendBogusAlertType {
793 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
794 }
795
David Benjaminbbba9392017-04-06 12:54:12 -0400796 testMessage := make([]byte, messageLen)
797 for i := range testMessage {
798 testMessage[i] = 0x42 ^ byte(j)
799 }
800 tlsConn.Write(testMessage)
801
802 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500803 if shimPrefix != "" {
804 var buf = make([]byte, len(shimPrefix))
805 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400806 if err != nil {
807 return err
808 }
Steven Valdeze831a812017-03-09 14:56:07 -0500809 if string(buf) != shimPrefix {
810 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400811 }
Steven Valdeze831a812017-03-09 14:56:07 -0500812 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400813 }
814
David Benjamin4f75aaf2015-09-01 16:53:10 -0400815 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400816 // The shim will not respond.
817 continue
818 }
819
David Benjaminbbba9392017-04-06 12:54:12 -0400820 // Process the KeyUpdate ACK. However many KeyUpdates the runner
821 // sends, the shim should respond only once.
822 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
823 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
824 return err
825 }
826 }
827
David Benjamin8e6db492015-07-25 18:29:23 -0400828 buf := make([]byte, len(testMessage))
829 if test.protocol == dtls {
830 bufTmp := make([]byte, len(buf)+1)
831 n, err := tlsConn.Read(bufTmp)
832 if err != nil {
833 return err
834 }
835 if n != len(buf) {
836 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
837 }
838 copy(buf, bufTmp)
839 } else {
840 _, err := io.ReadFull(tlsConn, buf)
841 if err != nil {
842 return err
843 }
844 }
845
846 for i, v := range buf {
847 if v != testMessage[i]^0xff {
848 return fmt.Errorf("bad reply contents at byte %d", i)
849 }
Adam Langley95c29f32014-06-20 12:00:00 -0700850 }
851 }
852
853 return nil
854}
855
David Benjamin325b5c32014-07-01 19:40:31 -0400856func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400857 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700858 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400859 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700860 }
David Benjamin325b5c32014-07-01 19:40:31 -0400861 valgrindArgs = append(valgrindArgs, path)
862 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700863
David Benjamin325b5c32014-07-01 19:40:31 -0400864 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700865}
866
David Benjamin325b5c32014-07-01 19:40:31 -0400867func gdbOf(path string, args ...string) *exec.Cmd {
868 xtermArgs := []string{"-e", "gdb", "--args"}
869 xtermArgs = append(xtermArgs, path)
870 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700871
David Benjamin325b5c32014-07-01 19:40:31 -0400872 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700873}
874
David Benjamind16bf342015-12-18 00:53:12 -0500875func lldbOf(path string, args ...string) *exec.Cmd {
876 xtermArgs := []string{"-e", "lldb", "--"}
877 xtermArgs = append(xtermArgs, path)
878 xtermArgs = append(xtermArgs, args...)
879
880 return exec.Command("xterm", xtermArgs...)
881}
882
EKR842ae6c2016-07-27 09:22:05 +0200883var (
884 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
885 errUnimplemented = errors.New("child process does not implement needed flags")
886)
Adam Langley69a01602014-11-17 17:26:55 -0800887
David Benjamin87c8a642015-02-21 01:54:29 -0500888// accept accepts a connection from listener, unless waitChan signals a process
889// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400890func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500891 type connOrError struct {
892 conn net.Conn
893 err error
894 }
895 connChan := make(chan connOrError, 1)
896 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400897 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500898 conn, err := listener.Accept()
899 connChan <- connOrError{conn, err}
900 close(connChan)
901 }()
902 select {
903 case result := <-connChan:
904 return result.conn, result.err
905 case childErr := <-waitChan:
906 waitChan <- childErr
907 return nil, fmt.Errorf("child exited early: %s", childErr)
908 }
909}
910
EKRf71d7ed2016-08-06 13:25:12 -0700911func translateExpectedError(errorStr string) string {
912 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
913 return translated
914 }
915
916 if *looseErrors {
917 return ""
918 }
919
920 return errorStr
921}
922
Adam Langley7c803a62015-06-15 15:35:05 -0700923func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400924 // Help debugging panics on the Go side.
925 defer func() {
926 if r := recover(); r != nil {
927 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
928 panic(r)
929 }
930 }()
931
Adam Langley38311732014-10-16 19:04:35 -0700932 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
933 panic("Error expected without shouldFail in " + test.name)
934 }
935
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700936 if test.expectResumeRejected && !test.resumeSession {
937 panic("expectResumeRejected without resumeSession in " + test.name)
938 }
939
Adam Langley33b1d4f2016-12-07 15:03:45 -0800940 for _, ver := range tlsVersions {
941 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
942 continue
943 }
944
945 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
946 continue
947 }
948
949 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
950 }
951
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700952 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
953 if err != nil {
954 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
955 }
David Benjamin87c8a642015-02-21 01:54:29 -0500956 if err != nil {
957 panic(err)
958 }
959 defer func() {
960 if listener != nil {
961 listener.Close()
962 }
963 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700964
David Benjamin87c8a642015-02-21 01:54:29 -0500965 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400966 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400967 flags = append(flags, "-server")
968
David Benjamin025b3d32014-07-01 19:53:04 -0400969 flags = append(flags, "-key-file")
970 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700971 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400972 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700973 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400974 }
975
976 flags = append(flags, "-cert-file")
977 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700978 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400979 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700980 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400981 }
982 }
David Benjamin5a593af2014-08-11 19:51:50 -0400983
David Benjamin6fd297b2014-08-11 18:43:38 -0400984 if test.protocol == dtls {
985 flags = append(flags, "-dtls")
986 }
987
David Benjamin46662482016-08-17 00:51:00 -0400988 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400989 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400990 resumeCount++
991 if test.resumeRenewedSession {
992 resumeCount++
993 }
994 }
995
996 if resumeCount > 0 {
997 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400998 }
999
David Benjamine58c4f52014-08-24 03:47:07 -04001000 if test.shimWritesFirst {
1001 flags = append(flags, "-shim-writes-first")
1002 }
1003
David Benjaminbbba9392017-04-06 12:54:12 -04001004 if test.readWithUnfinishedWrite {
1005 flags = append(flags, "-read-with-unfinished-write")
1006 }
1007
David Benjamin30789da2015-08-29 22:56:45 -04001008 if test.shimShutsDown {
1009 flags = append(flags, "-shim-shuts-down")
1010 }
1011
David Benjaminc565ebb2015-04-03 04:06:36 -04001012 if test.exportKeyingMaterial > 0 {
1013 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1014 flags = append(flags, "-export-label", test.exportLabel)
1015 flags = append(flags, "-export-context", test.exportContext)
1016 if test.useExportContext {
1017 flags = append(flags, "-use-export-context")
1018 }
1019 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001020 if test.expectResumeRejected {
1021 flags = append(flags, "-expect-session-miss")
1022 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001023
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001024 if test.testTLSUnique {
1025 flags = append(flags, "-tls-unique")
1026 }
1027
David Benjamin025b3d32014-07-01 19:53:04 -04001028 flags = append(flags, test.flags...)
1029
1030 var shim *exec.Cmd
1031 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001032 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001033 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001034 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001035 } else if *useLLDB {
1036 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001037 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001038 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001039 }
David Benjamin025b3d32014-07-01 19:53:04 -04001040 shim.Stdin = os.Stdin
1041 var stdoutBuf, stderrBuf bytes.Buffer
1042 shim.Stdout = &stdoutBuf
1043 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001044 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001045 shim.Env = os.Environ()
1046 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001047 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001048 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001049 }
1050 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1051 }
David Benjamin025b3d32014-07-01 19:53:04 -04001052
1053 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001054 panic(err)
1055 }
David Benjamin87c8a642015-02-21 01:54:29 -05001056 waitChan := make(chan error, 1)
1057 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001058
1059 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001060
David Benjamin7a4aaa42016-09-20 17:58:14 -04001061 if *deterministic {
1062 config.Rand = &deterministicRand{}
1063 }
1064
David Benjamin87c8a642015-02-21 01:54:29 -05001065 conn, err := acceptOrWait(listener, waitChan)
1066 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001067 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001068 conn.Close()
1069 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001070
David Benjamin46662482016-08-17 00:51:00 -04001071 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001072 var resumeConfig Config
1073 if test.resumeConfig != nil {
1074 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001075 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001076 resumeConfig.SessionTicketKey = config.SessionTicketKey
1077 resumeConfig.ClientSessionCache = config.ClientSessionCache
1078 resumeConfig.ServerSessionCache = config.ServerSessionCache
1079 }
David Benjamin2e045a92016-06-08 13:09:56 -04001080 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001081 } else {
1082 resumeConfig = config
1083 }
David Benjamin87c8a642015-02-21 01:54:29 -05001084 var connResume net.Conn
1085 connResume, err = acceptOrWait(listener, waitChan)
1086 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001087 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001088 connResume.Close()
1089 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001090 }
1091
David Benjamin87c8a642015-02-21 01:54:29 -05001092 // Close the listener now. This is to avoid hangs should the shim try to
1093 // open more connections than expected.
1094 listener.Close()
1095 listener = nil
1096
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001097 var shimKilledLock sync.Mutex
1098 var shimKilled bool
1099 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1100 shimKilledLock.Lock()
1101 shimKilled = true
1102 shimKilledLock.Unlock()
1103 shim.Process.Kill()
1104 })
David Benjamin87c8a642015-02-21 01:54:29 -05001105 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001106 waitTimeout.Stop()
1107 shimKilledLock.Lock()
1108 if shimKilled && err == nil {
1109 err = errors.New("timeout waiting for the shim to exit.")
1110 }
1111 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001112 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001113 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001114 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1115 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001116 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001117 case 89:
1118 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001119 case 99:
1120 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001121 }
1122 }
Adam Langley95c29f32014-06-20 12:00:00 -07001123
David Benjamin9bea3492016-03-02 10:59:16 -05001124 // Account for Windows line endings.
1125 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1126 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001127
1128 // Separate the errors from the shim and those from tools like
1129 // AddressSanitizer.
1130 var extraStderr string
1131 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1132 stderr = stderrParts[0]
1133 extraStderr = stderrParts[1]
1134 }
1135
Adam Langley95c29f32014-06-20 12:00:00 -07001136 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001137 expectedError := translateExpectedError(test.expectedError)
1138 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001139
Adam Langleyac61fa32014-06-23 12:03:11 -07001140 localError := "none"
1141 if err != nil {
1142 localError = err.Error()
1143 }
1144 if len(test.expectedLocalError) != 0 {
1145 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1146 }
Adam Langley95c29f32014-06-20 12:00:00 -07001147
1148 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001149 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001150 if childErr != nil {
1151 childError = childErr.Error()
1152 }
1153
1154 var msg string
1155 switch {
1156 case failed && !test.shouldFail:
1157 msg = "unexpected failure"
1158 case !failed && test.shouldFail:
1159 msg = "unexpected success"
1160 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001161 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001162 default:
1163 panic("internal error")
1164 }
1165
David Benjamin9aafb642016-09-20 19:36:53 -04001166 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 -07001167 }
1168
David Benjamind2ba8892016-09-20 19:41:04 -04001169 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001170 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001171 }
1172
David Benjamind2ba8892016-09-20 19:41:04 -04001173 if *useValgrind && isValgrindError {
1174 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1175 }
1176
Adam Langley95c29f32014-06-20 12:00:00 -07001177 return nil
1178}
1179
David Benjaminaa012042016-12-10 13:33:05 -05001180type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001181 name string
1182 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001183 // excludeFlag is the legacy shim flag to disable the version.
1184 excludeFlag string
1185 hasDTLS bool
1186 // shimTLS and shimDTLS are values the shim uses to refer to these
1187 // versions in TLS and DTLS, respectively.
1188 shimTLS, shimDTLS int
1189}
1190
1191func (vers tlsVersion) shimFlag(protocol protocol) string {
1192 if protocol == dtls {
1193 return strconv.Itoa(vers.shimDTLS)
1194 }
1195 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001196}
1197
1198var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001199 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1200 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1201 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1202 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1203 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001204}
1205
David Benjaminaa012042016-12-10 13:33:05 -05001206type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001207 name string
1208 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001209}
1210
1211var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001212 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001213 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001214 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001215 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001216 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001217 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001218 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001219 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1220 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001221 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1222 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001223 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001224 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001225 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001226 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001227 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001228 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001229 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001230 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001231 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001232 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001233 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1234 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001235 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1236 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001237 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001238 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1239 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1240 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001241 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001242}
1243
David Benjamin8b8c0062014-11-23 02:47:52 -05001244func hasComponent(suiteName, component string) bool {
1245 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1246}
1247
David Benjaminf7768e42014-08-31 02:06:47 -04001248func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001249 return hasComponent(suiteName, "GCM") ||
1250 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001251 hasComponent(suiteName, "SHA384") ||
1252 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001253}
1254
Nick Harper1fd39d82016-06-14 18:14:35 -07001255func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001256 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001257}
1258
David Benjamin8b8c0062014-11-23 02:47:52 -05001259func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001260 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001261}
1262
Adam Langleya7997f12015-05-14 17:38:50 -07001263func bigFromHex(hex string) *big.Int {
1264 ret, ok := new(big.Int).SetString(hex, 16)
1265 if !ok {
1266 panic("failed to parse hex number 0x" + hex)
1267 }
1268 return ret
1269}
1270
Adam Langley7c803a62015-06-15 15:35:05 -07001271func addBasicTests() {
1272 basicTests := []testCase{
1273 {
Adam Langley7c803a62015-06-15 15:35:05 -07001274 name: "NoFallbackSCSV",
1275 config: Config{
1276 Bugs: ProtocolBugs{
1277 FailIfNotFallbackSCSV: true,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedLocalError: "no fallback SCSV found",
1282 },
1283 {
1284 name: "SendFallbackSCSV",
1285 config: Config{
1286 Bugs: ProtocolBugs{
1287 FailIfNotFallbackSCSV: true,
1288 },
1289 },
1290 flags: []string{"-fallback-scsv"},
1291 },
1292 {
1293 name: "ClientCertificateTypes",
1294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001295 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001296 ClientAuth: RequestClientCert,
1297 ClientCertificateTypes: []byte{
1298 CertTypeDSSSign,
1299 CertTypeRSASign,
1300 CertTypeECDSASign,
1301 },
1302 },
1303 flags: []string{
1304 "-expect-certificate-types",
1305 base64.StdEncoding.EncodeToString([]byte{
1306 CertTypeDSSSign,
1307 CertTypeRSASign,
1308 CertTypeECDSASign,
1309 }),
1310 },
1311 },
1312 {
Adam Langley7c803a62015-06-15 15:35:05 -07001313 name: "UnauthenticatedECDH",
1314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001315 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001316 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1317 Bugs: ProtocolBugs{
1318 UnauthenticatedECDH: true,
1319 },
1320 },
1321 shouldFail: true,
1322 expectedError: ":UNEXPECTED_MESSAGE:",
1323 },
1324 {
1325 name: "SkipCertificateStatus",
1326 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001327 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001328 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1329 Bugs: ProtocolBugs{
1330 SkipCertificateStatus: true,
1331 },
1332 },
1333 flags: []string{
1334 "-enable-ocsp-stapling",
1335 },
1336 },
1337 {
1338 name: "SkipServerKeyExchange",
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 SkipServerKeyExchange: true,
1344 },
1345 },
1346 shouldFail: true,
1347 expectedError: ":UNEXPECTED_MESSAGE:",
1348 },
1349 {
Adam Langley7c803a62015-06-15 15:35:05 -07001350 testType: serverTest,
1351 name: "Alert",
1352 config: Config{
1353 Bugs: ProtocolBugs{
1354 SendSpuriousAlert: alertRecordOverflow,
1355 },
1356 },
1357 shouldFail: true,
1358 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1359 },
1360 {
1361 protocol: dtls,
1362 testType: serverTest,
1363 name: "Alert-DTLS",
1364 config: Config{
1365 Bugs: ProtocolBugs{
1366 SendSpuriousAlert: alertRecordOverflow,
1367 },
1368 },
1369 shouldFail: true,
1370 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1371 },
1372 {
1373 testType: serverTest,
1374 name: "FragmentAlert",
1375 config: Config{
1376 Bugs: ProtocolBugs{
1377 FragmentAlert: true,
1378 SendSpuriousAlert: alertRecordOverflow,
1379 },
1380 },
1381 shouldFail: true,
1382 expectedError: ":BAD_ALERT:",
1383 },
1384 {
1385 protocol: dtls,
1386 testType: serverTest,
1387 name: "FragmentAlert-DTLS",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 FragmentAlert: true,
1391 SendSpuriousAlert: alertRecordOverflow,
1392 },
1393 },
1394 shouldFail: true,
1395 expectedError: ":BAD_ALERT:",
1396 },
1397 {
1398 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001399 name: "DoubleAlert",
1400 config: Config{
1401 Bugs: ProtocolBugs{
1402 DoubleAlert: true,
1403 SendSpuriousAlert: alertRecordOverflow,
1404 },
1405 },
1406 shouldFail: true,
1407 expectedError: ":BAD_ALERT:",
1408 },
1409 {
1410 protocol: dtls,
1411 testType: serverTest,
1412 name: "DoubleAlert-DTLS",
1413 config: Config{
1414 Bugs: ProtocolBugs{
1415 DoubleAlert: true,
1416 SendSpuriousAlert: alertRecordOverflow,
1417 },
1418 },
1419 shouldFail: true,
1420 expectedError: ":BAD_ALERT:",
1421 },
1422 {
Adam Langley7c803a62015-06-15 15:35:05 -07001423 name: "SkipNewSessionTicket",
1424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001425 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001426 Bugs: ProtocolBugs{
1427 SkipNewSessionTicket: true,
1428 },
1429 },
1430 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001431 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001432 },
1433 {
1434 testType: serverTest,
1435 name: "FallbackSCSV",
1436 config: Config{
1437 MaxVersion: VersionTLS11,
1438 Bugs: ProtocolBugs{
1439 SendFallbackSCSV: true,
1440 },
1441 },
David Benjamin56cadc32016-12-16 19:54:11 -05001442 shouldFail: true,
1443 expectedError: ":INAPPROPRIATE_FALLBACK:",
1444 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001445 },
1446 {
1447 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001448 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001449 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001450 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001451 Bugs: ProtocolBugs{
1452 SendFallbackSCSV: true,
1453 },
1454 },
1455 },
1456 {
1457 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001458 name: "FallbackSCSV-VersionMatch-TLS12",
1459 config: Config{
1460 MaxVersion: VersionTLS12,
1461 Bugs: ProtocolBugs{
1462 SendFallbackSCSV: true,
1463 },
1464 },
1465 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1466 },
1467 {
1468 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001469 name: "FragmentedClientVersion",
1470 config: Config{
1471 Bugs: ProtocolBugs{
1472 MaxHandshakeRecordLength: 1,
1473 FragmentClientVersion: true,
1474 },
1475 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001476 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001477 },
1478 {
Adam Langley7c803a62015-06-15 15:35:05 -07001479 testType: serverTest,
1480 name: "HttpGET",
1481 sendPrefix: "GET / HTTP/1.0\n",
1482 shouldFail: true,
1483 expectedError: ":HTTP_REQUEST:",
1484 },
1485 {
1486 testType: serverTest,
1487 name: "HttpPOST",
1488 sendPrefix: "POST / HTTP/1.0\n",
1489 shouldFail: true,
1490 expectedError: ":HTTP_REQUEST:",
1491 },
1492 {
1493 testType: serverTest,
1494 name: "HttpHEAD",
1495 sendPrefix: "HEAD / HTTP/1.0\n",
1496 shouldFail: true,
1497 expectedError: ":HTTP_REQUEST:",
1498 },
1499 {
1500 testType: serverTest,
1501 name: "HttpPUT",
1502 sendPrefix: "PUT / HTTP/1.0\n",
1503 shouldFail: true,
1504 expectedError: ":HTTP_REQUEST:",
1505 },
1506 {
1507 testType: serverTest,
1508 name: "HttpCONNECT",
1509 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1510 shouldFail: true,
1511 expectedError: ":HTTPS_PROXY_REQUEST:",
1512 },
1513 {
1514 testType: serverTest,
1515 name: "Garbage",
1516 sendPrefix: "blah",
1517 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001518 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001519 },
1520 {
Adam Langley7c803a62015-06-15 15:35:05 -07001521 name: "RSAEphemeralKey",
1522 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001523 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001524 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1525 Bugs: ProtocolBugs{
1526 RSAEphemeralKey: true,
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_MESSAGE:",
1531 },
1532 {
1533 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001534 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001535 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001536 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001537 },
1538 {
1539 protocol: dtls,
1540 name: "DisableEverything-DTLS",
1541 flags: []string{"-no-tls12", "-no-tls1"},
1542 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001543 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001544 },
1545 {
Adam Langley7c803a62015-06-15 15:35:05 -07001546 protocol: dtls,
1547 testType: serverTest,
1548 name: "MTU",
1549 config: Config{
1550 Bugs: ProtocolBugs{
1551 MaxPacketLength: 256,
1552 },
1553 },
1554 flags: []string{"-mtu", "256"},
1555 },
1556 {
1557 protocol: dtls,
1558 testType: serverTest,
1559 name: "MTUExceeded",
1560 config: Config{
1561 Bugs: ProtocolBugs{
1562 MaxPacketLength: 255,
1563 },
1564 },
1565 flags: []string{"-mtu", "256"},
1566 shouldFail: true,
1567 expectedLocalError: "dtls: exceeded maximum packet length",
1568 },
1569 {
Adam Langley7c803a62015-06-15 15:35:05 -07001570 name: "EmptyCertificateList",
1571 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001572 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001573 Bugs: ProtocolBugs{
1574 EmptyCertificateList: true,
1575 },
1576 },
1577 shouldFail: true,
1578 expectedError: ":DECODE_ERROR:",
1579 },
1580 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001581 name: "EmptyCertificateList-TLS13",
1582 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001583 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001584 Bugs: ProtocolBugs{
1585 EmptyCertificateList: true,
1586 },
1587 },
1588 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001589 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001590 },
1591 {
Adam Langley7c803a62015-06-15 15:35:05 -07001592 name: "TLSFatalBadPackets",
1593 damageFirstWrite: true,
1594 shouldFail: true,
1595 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "DTLSIgnoreBadPackets",
1600 damageFirstWrite: true,
1601 },
1602 {
1603 protocol: dtls,
1604 name: "DTLSIgnoreBadPackets-Async",
1605 damageFirstWrite: true,
1606 flags: []string{"-async"},
1607 },
1608 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001609 name: "AppDataBeforeHandshake",
1610 config: Config{
1611 Bugs: ProtocolBugs{
1612 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1613 },
1614 },
1615 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001616 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001617 },
1618 {
1619 name: "AppDataBeforeHandshake-Empty",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 AppDataBeforeHandshake: []byte{},
1623 },
1624 },
1625 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001626 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001627 },
1628 {
1629 protocol: dtls,
1630 name: "AppDataBeforeHandshake-DTLS",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1634 },
1635 },
1636 shouldFail: true,
1637 expectedError: ":UNEXPECTED_RECORD:",
1638 },
1639 {
1640 protocol: dtls,
1641 name: "AppDataBeforeHandshake-DTLS-Empty",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 AppDataBeforeHandshake: []byte{},
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
Adam Langley7c803a62015-06-15 15:35:05 -07001651 name: "AppDataAfterChangeCipherSpec",
1652 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001653 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001654 Bugs: ProtocolBugs{
1655 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1656 },
1657 },
1658 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001659 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001660 },
1661 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001662 name: "AppDataAfterChangeCipherSpec-Empty",
1663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001664 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001665 Bugs: ProtocolBugs{
1666 AppDataAfterChangeCipherSpec: []byte{},
1667 },
1668 },
1669 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001670 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001671 },
1672 {
Adam Langley7c803a62015-06-15 15:35:05 -07001673 protocol: dtls,
1674 name: "AppDataAfterChangeCipherSpec-DTLS",
1675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001676 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001677 Bugs: ProtocolBugs{
1678 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1679 },
1680 },
1681 // BoringSSL's DTLS implementation will drop the out-of-order
1682 // application data.
1683 },
1684 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001685 protocol: dtls,
1686 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1687 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001688 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001689 Bugs: ProtocolBugs{
1690 AppDataAfterChangeCipherSpec: []byte{},
1691 },
1692 },
1693 // BoringSSL's DTLS implementation will drop the out-of-order
1694 // application data.
1695 },
1696 {
Adam Langley7c803a62015-06-15 15:35:05 -07001697 name: "AlertAfterChangeCipherSpec",
1698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001699 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001700 Bugs: ProtocolBugs{
1701 AlertAfterChangeCipherSpec: alertRecordOverflow,
1702 },
1703 },
1704 shouldFail: true,
1705 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1706 },
1707 {
1708 protocol: dtls,
1709 name: "AlertAfterChangeCipherSpec-DTLS",
1710 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001711 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001712 Bugs: ProtocolBugs{
1713 AlertAfterChangeCipherSpec: alertRecordOverflow,
1714 },
1715 },
1716 shouldFail: true,
1717 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1718 },
1719 {
1720 protocol: dtls,
1721 name: "ReorderHandshakeFragments-Small-DTLS",
1722 config: Config{
1723 Bugs: ProtocolBugs{
1724 ReorderHandshakeFragments: true,
1725 // Small enough that every handshake message is
1726 // fragmented.
1727 MaxHandshakeRecordLength: 2,
1728 },
1729 },
1730 },
1731 {
1732 protocol: dtls,
1733 name: "ReorderHandshakeFragments-Large-DTLS",
1734 config: Config{
1735 Bugs: ProtocolBugs{
1736 ReorderHandshakeFragments: true,
1737 // Large enough that no handshake message is
1738 // fragmented.
1739 MaxHandshakeRecordLength: 2048,
1740 },
1741 },
1742 },
1743 {
1744 protocol: dtls,
1745 name: "MixCompleteMessageWithFragments-DTLS",
1746 config: Config{
1747 Bugs: ProtocolBugs{
1748 ReorderHandshakeFragments: true,
1749 MixCompleteMessageWithFragments: true,
1750 MaxHandshakeRecordLength: 2,
1751 },
1752 },
1753 },
1754 {
1755 name: "SendInvalidRecordType",
1756 config: Config{
1757 Bugs: ProtocolBugs{
1758 SendInvalidRecordType: true,
1759 },
1760 },
1761 shouldFail: true,
1762 expectedError: ":UNEXPECTED_RECORD:",
1763 },
1764 {
1765 protocol: dtls,
1766 name: "SendInvalidRecordType-DTLS",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 SendInvalidRecordType: true,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":UNEXPECTED_RECORD:",
1774 },
1775 {
1776 name: "FalseStart-SkipServerSecondLeg",
1777 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001778 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1780 NextProtos: []string{"foo"},
1781 Bugs: ProtocolBugs{
1782 SkipNewSessionTicket: true,
1783 SkipChangeCipherSpec: true,
1784 SkipFinished: true,
1785 ExpectFalseStart: true,
1786 },
1787 },
1788 flags: []string{
1789 "-false-start",
1790 "-handshake-never-done",
1791 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001792 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001793 },
1794 shimWritesFirst: true,
1795 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001796 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001797 },
1798 {
1799 name: "FalseStart-SkipServerSecondLeg-Implicit",
1800 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001801 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1803 NextProtos: []string{"foo"},
1804 Bugs: ProtocolBugs{
1805 SkipNewSessionTicket: true,
1806 SkipChangeCipherSpec: true,
1807 SkipFinished: true,
1808 },
1809 },
1810 flags: []string{
1811 "-implicit-handshake",
1812 "-false-start",
1813 "-handshake-never-done",
1814 "-advertise-alpn", "\x03foo",
1815 },
1816 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001817 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001818 },
1819 {
1820 testType: serverTest,
1821 name: "FailEarlyCallback",
1822 flags: []string{"-fail-early-callback"},
1823 shouldFail: true,
1824 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001825 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001826 },
1827 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001828 name: "FailCertCallback-Client-TLS12",
1829 config: Config{
1830 MaxVersion: VersionTLS12,
1831 ClientAuth: RequestClientCert,
1832 },
1833 flags: []string{"-fail-cert-callback"},
1834 shouldFail: true,
1835 expectedError: ":CERT_CB_ERROR:",
1836 expectedLocalError: "remote error: internal error",
1837 },
1838 {
1839 testType: serverTest,
1840 name: "FailCertCallback-Server-TLS12",
1841 config: Config{
1842 MaxVersion: VersionTLS12,
1843 },
1844 flags: []string{"-fail-cert-callback"},
1845 shouldFail: true,
1846 expectedError: ":CERT_CB_ERROR:",
1847 expectedLocalError: "remote error: internal error",
1848 },
1849 {
1850 name: "FailCertCallback-Client-TLS13",
1851 config: Config{
1852 MaxVersion: VersionTLS13,
1853 ClientAuth: RequestClientCert,
1854 },
1855 flags: []string{"-fail-cert-callback"},
1856 shouldFail: true,
1857 expectedError: ":CERT_CB_ERROR:",
1858 expectedLocalError: "remote error: internal error",
1859 },
1860 {
1861 testType: serverTest,
1862 name: "FailCertCallback-Server-TLS13",
1863 config: Config{
1864 MaxVersion: VersionTLS13,
1865 },
1866 flags: []string{"-fail-cert-callback"},
1867 shouldFail: true,
1868 expectedError: ":CERT_CB_ERROR:",
1869 expectedLocalError: "remote error: internal error",
1870 },
1871 {
Adam Langley7c803a62015-06-15 15:35:05 -07001872 protocol: dtls,
1873 name: "FragmentMessageTypeMismatch-DTLS",
1874 config: Config{
1875 Bugs: ProtocolBugs{
1876 MaxHandshakeRecordLength: 2,
1877 FragmentMessageTypeMismatch: true,
1878 },
1879 },
1880 shouldFail: true,
1881 expectedError: ":FRAGMENT_MISMATCH:",
1882 },
1883 {
1884 protocol: dtls,
1885 name: "FragmentMessageLengthMismatch-DTLS",
1886 config: Config{
1887 Bugs: ProtocolBugs{
1888 MaxHandshakeRecordLength: 2,
1889 FragmentMessageLengthMismatch: true,
1890 },
1891 },
1892 shouldFail: true,
1893 expectedError: ":FRAGMENT_MISMATCH:",
1894 },
1895 {
1896 protocol: dtls,
1897 name: "SplitFragments-Header-DTLS",
1898 config: Config{
1899 Bugs: ProtocolBugs{
1900 SplitFragments: 2,
1901 },
1902 },
1903 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001904 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001905 },
1906 {
1907 protocol: dtls,
1908 name: "SplitFragments-Boundary-DTLS",
1909 config: Config{
1910 Bugs: ProtocolBugs{
1911 SplitFragments: dtlsRecordHeaderLen,
1912 },
1913 },
1914 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001915 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001916 },
1917 {
1918 protocol: dtls,
1919 name: "SplitFragments-Body-DTLS",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 SplitFragments: dtlsRecordHeaderLen + 1,
1923 },
1924 },
1925 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001926 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001927 },
1928 {
1929 protocol: dtls,
1930 name: "SendEmptyFragments-DTLS",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SendEmptyFragments: true,
1934 },
1935 },
1936 },
1937 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001938 name: "BadFinished-Client",
1939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001940 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001941 Bugs: ProtocolBugs{
1942 BadFinished: true,
1943 },
1944 },
1945 shouldFail: true,
1946 expectedError: ":DIGEST_CHECK_FAILED:",
1947 },
1948 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001949 name: "BadFinished-Client-TLS13",
1950 config: Config{
1951 MaxVersion: VersionTLS13,
1952 Bugs: ProtocolBugs{
1953 BadFinished: true,
1954 },
1955 },
1956 shouldFail: true,
1957 expectedError: ":DIGEST_CHECK_FAILED:",
1958 },
1959 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001960 testType: serverTest,
1961 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001962 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001963 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001964 Bugs: ProtocolBugs{
1965 BadFinished: true,
1966 },
1967 },
1968 shouldFail: true,
1969 expectedError: ":DIGEST_CHECK_FAILED:",
1970 },
1971 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001972 testType: serverTest,
1973 name: "BadFinished-Server-TLS13",
1974 config: Config{
1975 MaxVersion: VersionTLS13,
1976 Bugs: ProtocolBugs{
1977 BadFinished: true,
1978 },
1979 },
1980 shouldFail: true,
1981 expectedError: ":DIGEST_CHECK_FAILED:",
1982 },
1983 {
Adam Langley7c803a62015-06-15 15:35:05 -07001984 name: "FalseStart-BadFinished",
1985 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001986 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1988 NextProtos: []string{"foo"},
1989 Bugs: ProtocolBugs{
1990 BadFinished: true,
1991 ExpectFalseStart: true,
1992 },
1993 },
1994 flags: []string{
1995 "-false-start",
1996 "-handshake-never-done",
1997 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001998 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001999 },
2000 shimWritesFirst: true,
2001 shouldFail: true,
2002 expectedError: ":DIGEST_CHECK_FAILED:",
2003 },
2004 {
2005 name: "NoFalseStart-NoALPN",
2006 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002007 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002008 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2009 Bugs: ProtocolBugs{
2010 ExpectFalseStart: true,
2011 AlertBeforeFalseStartTest: alertAccessDenied,
2012 },
2013 },
2014 flags: []string{
2015 "-false-start",
2016 },
2017 shimWritesFirst: true,
2018 shouldFail: true,
2019 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2020 expectedLocalError: "tls: peer did not false start: EOF",
2021 },
2022 {
2023 name: "NoFalseStart-NoAEAD",
2024 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002025 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2027 NextProtos: []string{"foo"},
2028 Bugs: ProtocolBugs{
2029 ExpectFalseStart: true,
2030 AlertBeforeFalseStartTest: alertAccessDenied,
2031 },
2032 },
2033 flags: []string{
2034 "-false-start",
2035 "-advertise-alpn", "\x03foo",
2036 },
2037 shimWritesFirst: true,
2038 shouldFail: true,
2039 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2040 expectedLocalError: "tls: peer did not false start: EOF",
2041 },
2042 {
2043 name: "NoFalseStart-RSA",
2044 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002045 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002046 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2047 NextProtos: []string{"foo"},
2048 Bugs: ProtocolBugs{
2049 ExpectFalseStart: true,
2050 AlertBeforeFalseStartTest: alertAccessDenied,
2051 },
2052 },
2053 flags: []string{
2054 "-false-start",
2055 "-advertise-alpn", "\x03foo",
2056 },
2057 shimWritesFirst: true,
2058 shouldFail: true,
2059 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2060 expectedLocalError: "tls: peer did not false start: EOF",
2061 },
2062 {
Adam Langley7c803a62015-06-15 15:35:05 -07002063 protocol: dtls,
2064 name: "SendSplitAlert-Sync",
2065 config: Config{
2066 Bugs: ProtocolBugs{
2067 SendSplitAlert: true,
2068 },
2069 },
2070 },
2071 {
2072 protocol: dtls,
2073 name: "SendSplitAlert-Async",
2074 config: Config{
2075 Bugs: ProtocolBugs{
2076 SendSplitAlert: true,
2077 },
2078 },
2079 flags: []string{"-async"},
2080 },
2081 {
2082 protocol: dtls,
2083 name: "PackDTLSHandshake",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 MaxHandshakeRecordLength: 2,
2087 PackHandshakeFragments: 20,
2088 PackHandshakeRecords: 200,
2089 },
2090 },
2091 },
2092 {
Adam Langley7c803a62015-06-15 15:35:05 -07002093 name: "SendEmptyRecords-Pass",
2094 sendEmptyRecords: 32,
2095 },
2096 {
2097 name: "SendEmptyRecords",
2098 sendEmptyRecords: 33,
2099 shouldFail: true,
2100 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2101 },
2102 {
2103 name: "SendEmptyRecords-Async",
2104 sendEmptyRecords: 33,
2105 flags: []string{"-async"},
2106 shouldFail: true,
2107 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2108 },
2109 {
David Benjamine8e84b92016-08-03 15:39:47 -04002110 name: "SendWarningAlerts-Pass",
2111 config: Config{
2112 MaxVersion: VersionTLS12,
2113 },
Adam Langley7c803a62015-06-15 15:35:05 -07002114 sendWarningAlerts: 4,
2115 },
2116 {
David Benjamine8e84b92016-08-03 15:39:47 -04002117 protocol: dtls,
2118 name: "SendWarningAlerts-DTLS-Pass",
2119 config: Config{
2120 MaxVersion: VersionTLS12,
2121 },
Adam Langley7c803a62015-06-15 15:35:05 -07002122 sendWarningAlerts: 4,
2123 },
2124 {
David Benjamine8e84b92016-08-03 15:39:47 -04002125 name: "SendWarningAlerts-TLS13",
2126 config: Config{
2127 MaxVersion: VersionTLS13,
2128 },
2129 sendWarningAlerts: 4,
2130 shouldFail: true,
2131 expectedError: ":BAD_ALERT:",
2132 expectedLocalError: "remote error: error decoding message",
2133 },
2134 {
2135 name: "SendWarningAlerts",
2136 config: Config{
2137 MaxVersion: VersionTLS12,
2138 },
Adam Langley7c803a62015-06-15 15:35:05 -07002139 sendWarningAlerts: 5,
2140 shouldFail: true,
2141 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2142 },
2143 {
David Benjamine8e84b92016-08-03 15:39:47 -04002144 name: "SendWarningAlerts-Async",
2145 config: Config{
2146 MaxVersion: VersionTLS12,
2147 },
Adam Langley7c803a62015-06-15 15:35:05 -07002148 sendWarningAlerts: 5,
2149 flags: []string{"-async"},
2150 shouldFail: true,
2151 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2152 },
David Benjaminba4594a2015-06-18 18:36:15 -04002153 {
David Benjamin24e58862017-06-14 18:45:29 -04002154 name: "SendBogusAlertType",
2155 sendBogusAlertType: true,
2156 shouldFail: true,
2157 expectedError: ":UNKNOWN_ALERT_TYPE:",
2158 expectedLocalError: "remote error: illegal parameter",
2159 },
2160 {
2161 protocol: dtls,
2162 name: "SendBogusAlertType-DTLS",
2163 sendBogusAlertType: true,
2164 shouldFail: true,
2165 expectedError: ":UNKNOWN_ALERT_TYPE:",
2166 expectedLocalError: "remote error: illegal parameter",
2167 },
2168 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002169 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002170 config: Config{
2171 MaxVersion: VersionTLS13,
2172 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002173 sendKeyUpdates: 33,
2174 keyUpdateRequest: keyUpdateNotRequested,
2175 shouldFail: true,
2176 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002177 },
2178 {
David Benjaminba4594a2015-06-18 18:36:15 -04002179 name: "EmptySessionID",
2180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002181 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002182 SessionTicketsDisabled: true,
2183 },
2184 noSessionCache: true,
2185 flags: []string{"-expect-no-session"},
2186 },
David Benjamin30789da2015-08-29 22:56:45 -04002187 {
2188 name: "Unclean-Shutdown",
2189 config: Config{
2190 Bugs: ProtocolBugs{
2191 NoCloseNotify: true,
2192 ExpectCloseNotify: true,
2193 },
2194 },
2195 shimShutsDown: true,
2196 flags: []string{"-check-close-notify"},
2197 shouldFail: true,
2198 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2199 },
2200 {
2201 name: "Unclean-Shutdown-Ignored",
2202 config: Config{
2203 Bugs: ProtocolBugs{
2204 NoCloseNotify: true,
2205 },
2206 },
2207 shimShutsDown: true,
2208 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002209 {
David Benjaminfa214e42016-05-10 17:03:10 -04002210 name: "Unclean-Shutdown-Alert",
2211 config: Config{
2212 Bugs: ProtocolBugs{
2213 SendAlertOnShutdown: alertDecompressionFailure,
2214 ExpectCloseNotify: true,
2215 },
2216 },
2217 shimShutsDown: true,
2218 flags: []string{"-check-close-notify"},
2219 shouldFail: true,
2220 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2221 },
2222 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002223 name: "LargePlaintext",
2224 config: Config{
2225 Bugs: ProtocolBugs{
2226 SendLargeRecords: true,
2227 },
2228 },
2229 messageLen: maxPlaintext + 1,
2230 shouldFail: true,
2231 expectedError: ":DATA_LENGTH_TOO_LONG:",
2232 },
2233 {
2234 protocol: dtls,
2235 name: "LargePlaintext-DTLS",
2236 config: Config{
2237 Bugs: ProtocolBugs{
2238 SendLargeRecords: true,
2239 },
2240 },
2241 messageLen: maxPlaintext + 1,
2242 shouldFail: true,
2243 expectedError: ":DATA_LENGTH_TOO_LONG:",
2244 },
2245 {
2246 name: "LargeCiphertext",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendLargeRecords: true,
2250 },
2251 },
2252 messageLen: maxPlaintext * 2,
2253 shouldFail: true,
2254 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2255 },
2256 {
2257 protocol: dtls,
2258 name: "LargeCiphertext-DTLS",
2259 config: Config{
2260 Bugs: ProtocolBugs{
2261 SendLargeRecords: true,
2262 },
2263 },
2264 messageLen: maxPlaintext * 2,
2265 // Unlike the other four cases, DTLS drops records which
2266 // are invalid before authentication, so the connection
2267 // does not fail.
2268 expectMessageDropped: true,
2269 },
David Benjamindd6fed92015-10-23 17:41:12 -04002270 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002271 name: "BadHelloRequest-1",
2272 renegotiate: 1,
2273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002274 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002275 Bugs: ProtocolBugs{
2276 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2277 },
2278 },
2279 flags: []string{
2280 "-renegotiate-freely",
2281 "-expect-total-renegotiations", "1",
2282 },
2283 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002284 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002285 },
2286 {
2287 name: "BadHelloRequest-2",
2288 renegotiate: 1,
2289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002290 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002291 Bugs: ProtocolBugs{
2292 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2293 },
2294 },
2295 flags: []string{
2296 "-renegotiate-freely",
2297 "-expect-total-renegotiations", "1",
2298 },
2299 shouldFail: true,
2300 expectedError: ":BAD_HELLO_REQUEST:",
2301 },
David Benjaminef1b0092015-11-21 14:05:44 -05002302 {
2303 testType: serverTest,
2304 name: "SupportTicketsWithSessionID",
2305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002306 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002307 SessionTicketsDisabled: true,
2308 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002309 resumeConfig: &Config{
2310 MaxVersion: VersionTLS12,
2311 },
David Benjaminef1b0092015-11-21 14:05:44 -05002312 resumeSession: true,
2313 },
David Benjamin02edcd02016-07-27 17:40:37 -04002314 {
2315 protocol: dtls,
2316 name: "DTLS-SendExtraFinished",
2317 config: Config{
2318 Bugs: ProtocolBugs{
2319 SendExtraFinished: true,
2320 },
2321 },
2322 shouldFail: true,
2323 expectedError: ":UNEXPECTED_RECORD:",
2324 },
2325 {
2326 protocol: dtls,
2327 name: "DTLS-SendExtraFinished-Reordered",
2328 config: Config{
2329 Bugs: ProtocolBugs{
2330 MaxHandshakeRecordLength: 2,
2331 ReorderHandshakeFragments: true,
2332 SendExtraFinished: true,
2333 },
2334 },
2335 shouldFail: true,
2336 expectedError: ":UNEXPECTED_RECORD:",
2337 },
David Benjamine97fb482016-07-29 09:23:07 -04002338 {
2339 testType: serverTest,
2340 name: "V2ClientHello-EmptyRecordPrefix",
2341 config: Config{
2342 // Choose a cipher suite that does not involve
2343 // elliptic curves, so no extensions are
2344 // involved.
2345 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002346 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002347 Bugs: ProtocolBugs{
2348 SendV2ClientHello: true,
2349 },
2350 },
2351 sendPrefix: string([]byte{
2352 byte(recordTypeHandshake),
2353 3, 1, // version
2354 0, 0, // length
2355 }),
2356 // A no-op empty record may not be sent before V2ClientHello.
2357 shouldFail: true,
2358 expectedError: ":WRONG_VERSION_NUMBER:",
2359 },
2360 {
2361 testType: serverTest,
2362 name: "V2ClientHello-WarningAlertPrefix",
2363 config: Config{
2364 // Choose a cipher suite that does not involve
2365 // elliptic curves, so no extensions are
2366 // involved.
2367 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002368 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002369 Bugs: ProtocolBugs{
2370 SendV2ClientHello: true,
2371 },
2372 },
2373 sendPrefix: string([]byte{
2374 byte(recordTypeAlert),
2375 3, 1, // version
2376 0, 2, // length
2377 alertLevelWarning, byte(alertDecompressionFailure),
2378 }),
2379 // A no-op warning alert may not be sent before V2ClientHello.
2380 shouldFail: true,
2381 expectedError: ":WRONG_VERSION_NUMBER:",
2382 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002383 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002384 name: "KeyUpdate-Client",
2385 config: Config{
2386 MaxVersion: VersionTLS13,
2387 },
2388 sendKeyUpdates: 1,
2389 keyUpdateRequest: keyUpdateNotRequested,
2390 },
2391 {
2392 testType: serverTest,
2393 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002394 config: Config{
2395 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002396 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002397 sendKeyUpdates: 1,
2398 keyUpdateRequest: keyUpdateNotRequested,
2399 },
2400 {
2401 name: "KeyUpdate-InvalidRequestMode",
2402 config: Config{
2403 MaxVersion: VersionTLS13,
2404 },
2405 sendKeyUpdates: 1,
2406 keyUpdateRequest: 42,
2407 shouldFail: true,
2408 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002409 },
David Benjaminabe94e32016-09-04 14:18:58 -04002410 {
David Benjaminbbba9392017-04-06 12:54:12 -04002411 // Test that KeyUpdates are acknowledged properly.
2412 name: "KeyUpdate-RequestACK",
2413 config: Config{
2414 MaxVersion: VersionTLS13,
2415 Bugs: ProtocolBugs{
2416 RejectUnsolicitedKeyUpdate: true,
2417 },
2418 },
2419 // Test the shim receiving many KeyUpdates in a row.
2420 sendKeyUpdates: 5,
2421 messageCount: 5,
2422 keyUpdateRequest: keyUpdateRequested,
2423 },
2424 {
2425 // Test that KeyUpdates are acknowledged properly if the
2426 // peer's KeyUpdate is discovered while a write is
2427 // pending.
2428 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2429 config: Config{
2430 MaxVersion: VersionTLS13,
2431 Bugs: ProtocolBugs{
2432 RejectUnsolicitedKeyUpdate: true,
2433 },
2434 },
2435 // Test the shim receiving many KeyUpdates in a row.
2436 sendKeyUpdates: 5,
2437 messageCount: 5,
2438 keyUpdateRequest: keyUpdateRequested,
2439 readWithUnfinishedWrite: true,
2440 flags: []string{"-async"},
2441 },
2442 {
David Benjaminabe94e32016-09-04 14:18:58 -04002443 name: "SendSNIWarningAlert",
2444 config: Config{
2445 MaxVersion: VersionTLS12,
2446 Bugs: ProtocolBugs{
2447 SendSNIWarningAlert: true,
2448 },
2449 },
2450 },
David Benjaminc241d792016-09-09 10:34:20 -04002451 {
2452 testType: serverTest,
2453 name: "ExtraCompressionMethods-TLS12",
2454 config: Config{
2455 MaxVersion: VersionTLS12,
2456 Bugs: ProtocolBugs{
2457 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2458 },
2459 },
2460 },
2461 {
2462 testType: serverTest,
2463 name: "ExtraCompressionMethods-TLS13",
2464 config: Config{
2465 MaxVersion: VersionTLS13,
2466 Bugs: ProtocolBugs{
2467 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2468 },
2469 },
2470 shouldFail: true,
2471 expectedError: ":INVALID_COMPRESSION_LIST:",
2472 expectedLocalError: "remote error: illegal parameter",
2473 },
2474 {
2475 testType: serverTest,
2476 name: "NoNullCompression-TLS12",
2477 config: Config{
2478 MaxVersion: VersionTLS12,
2479 Bugs: ProtocolBugs{
2480 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2481 },
2482 },
2483 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002484 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002485 expectedLocalError: "remote error: illegal parameter",
2486 },
2487 {
2488 testType: serverTest,
2489 name: "NoNullCompression-TLS13",
2490 config: Config{
2491 MaxVersion: VersionTLS13,
2492 Bugs: ProtocolBugs{
2493 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2494 },
2495 },
2496 shouldFail: true,
2497 expectedError: ":INVALID_COMPRESSION_LIST:",
2498 expectedLocalError: "remote error: illegal parameter",
2499 },
David Benjamin65ac9972016-09-02 21:35:25 -04002500 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002501 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002502 config: Config{
2503 MaxVersion: VersionTLS12,
2504 Bugs: ProtocolBugs{
2505 ExpectGREASE: true,
2506 },
2507 },
2508 flags: []string{"-enable-grease"},
2509 },
2510 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002511 name: "GREASE-Client-TLS13",
2512 config: Config{
2513 MaxVersion: VersionTLS13,
2514 Bugs: ProtocolBugs{
2515 ExpectGREASE: true,
2516 },
2517 },
2518 flags: []string{"-enable-grease"},
2519 },
2520 {
2521 testType: serverTest,
2522 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002523 config: Config{
2524 MaxVersion: VersionTLS13,
2525 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002526 // TLS 1.3 servers are expected to
2527 // always enable GREASE. TLS 1.3 is new,
2528 // so there is no existing ecosystem to
2529 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002530 ExpectGREASE: true,
2531 },
2532 },
David Benjamin65ac9972016-09-02 21:35:25 -04002533 },
David Benjamine3fbb362017-01-06 16:19:28 -05002534 {
2535 // Test the server so there is a large certificate as
2536 // well as application data.
2537 testType: serverTest,
2538 name: "MaxSendFragment",
2539 config: Config{
2540 Bugs: ProtocolBugs{
2541 MaxReceivePlaintext: 512,
2542 },
2543 },
2544 messageLen: 1024,
2545 flags: []string{
2546 "-max-send-fragment", "512",
2547 "-read-size", "1024",
2548 },
2549 },
2550 {
2551 // Test the server so there is a large certificate as
2552 // well as application data.
2553 testType: serverTest,
2554 name: "MaxSendFragment-TooLarge",
2555 config: Config{
2556 Bugs: ProtocolBugs{
2557 // Ensure that some of the records are
2558 // 512.
2559 MaxReceivePlaintext: 511,
2560 },
2561 },
2562 messageLen: 1024,
2563 flags: []string{
2564 "-max-send-fragment", "512",
2565 "-read-size", "1024",
2566 },
2567 shouldFail: true,
2568 expectedLocalError: "local error: record overflow",
2569 },
Adam Langley7c803a62015-06-15 15:35:05 -07002570 }
Adam Langley7c803a62015-06-15 15:35:05 -07002571 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002572
2573 // Test that very large messages can be received.
2574 cert := rsaCertificate
2575 for i := 0; i < 50; i++ {
2576 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2577 }
2578 testCases = append(testCases, testCase{
2579 name: "LargeMessage",
2580 config: Config{
2581 Certificates: []Certificate{cert},
2582 },
2583 })
2584 testCases = append(testCases, testCase{
2585 protocol: dtls,
2586 name: "LargeMessage-DTLS",
2587 config: Config{
2588 Certificates: []Certificate{cert},
2589 },
2590 })
2591
2592 // They are rejected if the maximum certificate chain length is capped.
2593 testCases = append(testCases, testCase{
2594 name: "LargeMessage-Reject",
2595 config: Config{
2596 Certificates: []Certificate{cert},
2597 },
2598 flags: []string{"-max-cert-list", "16384"},
2599 shouldFail: true,
2600 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2601 })
2602 testCases = append(testCases, testCase{
2603 protocol: dtls,
2604 name: "LargeMessage-Reject-DTLS",
2605 config: Config{
2606 Certificates: []Certificate{cert},
2607 },
2608 flags: []string{"-max-cert-list", "16384"},
2609 shouldFail: true,
2610 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2611 })
Adam Langley7c803a62015-06-15 15:35:05 -07002612}
2613
David Benjaminaa012042016-12-10 13:33:05 -05002614func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2615 const psk = "12345"
2616 const pskIdentity = "luggage combo"
2617
2618 var prefix string
2619 if protocol == dtls {
2620 if !ver.hasDTLS {
2621 return
2622 }
2623 prefix = "D"
2624 }
2625
2626 var cert Certificate
2627 var certFile string
2628 var keyFile string
2629 if hasComponent(suite.name, "ECDSA") {
2630 cert = ecdsaP256Certificate
2631 certFile = ecdsaP256CertificateFile
2632 keyFile = ecdsaP256KeyFile
2633 } else {
2634 cert = rsaCertificate
2635 certFile = rsaCertificateFile
2636 keyFile = rsaKeyFile
2637 }
2638
2639 var flags []string
2640 if hasComponent(suite.name, "PSK") {
2641 flags = append(flags,
2642 "-psk", psk,
2643 "-psk-identity", pskIdentity)
2644 }
2645 if hasComponent(suite.name, "NULL") {
2646 // NULL ciphers must be explicitly enabled.
2647 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2648 }
David Benjaminaa012042016-12-10 13:33:05 -05002649
2650 var shouldServerFail, shouldClientFail bool
2651 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2652 // BoringSSL clients accept ECDHE on SSLv3, but
2653 // a BoringSSL server will never select it
2654 // because the extension is missing.
2655 shouldServerFail = true
2656 }
2657 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2658 shouldClientFail = true
2659 shouldServerFail = true
2660 }
2661 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2662 shouldClientFail = true
2663 shouldServerFail = true
2664 }
2665 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2666 shouldClientFail = true
2667 shouldServerFail = true
2668 }
2669 if !isDTLSCipher(suite.name) && protocol == dtls {
2670 shouldClientFail = true
2671 shouldServerFail = true
2672 }
2673
2674 var sendCipherSuite uint16
2675 var expectedServerError, expectedClientError string
2676 serverCipherSuites := []uint16{suite.id}
2677 if shouldServerFail {
2678 expectedServerError = ":NO_SHARED_CIPHER:"
2679 }
2680 if shouldClientFail {
2681 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2682 // Configure the server to select ciphers as normal but
2683 // select an incompatible cipher in ServerHello.
2684 serverCipherSuites = nil
2685 sendCipherSuite = suite.id
2686 }
2687
David Benjamincdb6fe92017-02-07 16:06:48 -05002688 // For cipher suites and versions where exporters are defined, verify
2689 // that they interoperate.
2690 var exportKeyingMaterial int
2691 if ver.version > VersionSSL30 {
2692 exportKeyingMaterial = 1024
2693 }
2694
David Benjaminaa012042016-12-10 13:33:05 -05002695 testCases = append(testCases, testCase{
2696 testType: serverTest,
2697 protocol: protocol,
2698 name: prefix + ver.name + "-" + suite.name + "-server",
2699 config: Config{
2700 MinVersion: ver.version,
2701 MaxVersion: ver.version,
2702 CipherSuites: []uint16{suite.id},
2703 Certificates: []Certificate{cert},
2704 PreSharedKey: []byte(psk),
2705 PreSharedKeyIdentity: pskIdentity,
2706 Bugs: ProtocolBugs{
2707 AdvertiseAllConfiguredCiphers: true,
2708 },
2709 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002710 certFile: certFile,
2711 keyFile: keyFile,
2712 flags: flags,
2713 resumeSession: true,
2714 shouldFail: shouldServerFail,
2715 expectedError: expectedServerError,
2716 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002717 })
2718
2719 testCases = append(testCases, testCase{
2720 testType: clientTest,
2721 protocol: protocol,
2722 name: prefix + ver.name + "-" + suite.name + "-client",
2723 config: Config{
2724 MinVersion: ver.version,
2725 MaxVersion: ver.version,
2726 CipherSuites: serverCipherSuites,
2727 Certificates: []Certificate{cert},
2728 PreSharedKey: []byte(psk),
2729 PreSharedKeyIdentity: pskIdentity,
2730 Bugs: ProtocolBugs{
2731 IgnorePeerCipherPreferences: shouldClientFail,
2732 SendCipherSuite: sendCipherSuite,
2733 },
2734 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002735 flags: flags,
2736 resumeSession: true,
2737 shouldFail: shouldClientFail,
2738 expectedError: expectedClientError,
2739 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002740 })
2741
David Benjamin6f600d62016-12-21 16:06:54 -05002742 if shouldClientFail {
2743 return
2744 }
2745
2746 // Ensure the maximum record size is accepted.
2747 testCases = append(testCases, testCase{
2748 protocol: protocol,
2749 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2750 config: Config{
2751 MinVersion: ver.version,
2752 MaxVersion: ver.version,
2753 CipherSuites: []uint16{suite.id},
2754 Certificates: []Certificate{cert},
2755 PreSharedKey: []byte(psk),
2756 PreSharedKeyIdentity: pskIdentity,
2757 },
2758 flags: flags,
2759 messageLen: maxPlaintext,
2760 })
2761
2762 // Test bad records for all ciphers. Bad records are fatal in TLS
2763 // and ignored in DTLS.
2764 var shouldFail bool
2765 var expectedError string
2766 if protocol == tls {
2767 shouldFail = true
2768 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2769 }
2770
2771 testCases = append(testCases, testCase{
2772 protocol: protocol,
2773 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2774 config: Config{
2775 MinVersion: ver.version,
2776 MaxVersion: ver.version,
2777 CipherSuites: []uint16{suite.id},
2778 Certificates: []Certificate{cert},
2779 PreSharedKey: []byte(psk),
2780 PreSharedKeyIdentity: pskIdentity,
2781 },
2782 flags: flags,
2783 damageFirstWrite: true,
2784 messageLen: maxPlaintext,
2785 shouldFail: shouldFail,
2786 expectedError: expectedError,
2787 })
David Benjaminaa012042016-12-10 13:33:05 -05002788}
2789
Adam Langley95c29f32014-06-20 12:00:00 -07002790func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002791 const bogusCipher = 0xfe00
2792
Adam Langley95c29f32014-06-20 12:00:00 -07002793 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002794 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002795 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002796 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002797 }
David Benjamin2c99d282015-09-01 10:23:00 -04002798 }
Adam Langley95c29f32014-06-20 12:00:00 -07002799 }
Adam Langleya7997f12015-05-14 17:38:50 -07002800
2801 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002802 name: "NoSharedCipher",
2803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002804 MaxVersion: VersionTLS12,
2805 CipherSuites: []uint16{},
2806 },
2807 shouldFail: true,
2808 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2809 })
2810
2811 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002812 name: "NoSharedCipher-TLS13",
2813 config: Config{
2814 MaxVersion: VersionTLS13,
2815 CipherSuites: []uint16{},
2816 },
2817 shouldFail: true,
2818 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2819 })
2820
2821 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002822 name: "UnsupportedCipherSuite",
2823 config: Config{
2824 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002825 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002826 Bugs: ProtocolBugs{
2827 IgnorePeerCipherPreferences: true,
2828 },
2829 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002830 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002831 shouldFail: true,
2832 expectedError: ":WRONG_CIPHER_RETURNED:",
2833 })
2834
2835 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002836 name: "ServerHelloBogusCipher",
2837 config: Config{
2838 MaxVersion: VersionTLS12,
2839 Bugs: ProtocolBugs{
2840 SendCipherSuite: bogusCipher,
2841 },
2842 },
2843 shouldFail: true,
2844 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2845 })
2846 testCases = append(testCases, testCase{
2847 name: "ServerHelloBogusCipher-TLS13",
2848 config: Config{
2849 MaxVersion: VersionTLS13,
2850 Bugs: ProtocolBugs{
2851 SendCipherSuite: bogusCipher,
2852 },
2853 },
2854 shouldFail: true,
2855 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2856 })
2857
David Benjamin241ae832016-01-15 03:04:54 -05002858 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002859 testCases = append(testCases, testCase{
2860 testType: serverTest,
2861 name: "UnknownCipher",
2862 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002863 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002864 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002865 Bugs: ProtocolBugs{
2866 AdvertiseAllConfiguredCiphers: true,
2867 },
2868 },
2869 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002870
2871 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002872 testCases = append(testCases, testCase{
2873 testType: serverTest,
2874 name: "UnknownCipher-TLS13",
2875 config: Config{
2876 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002877 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002878 Bugs: ProtocolBugs{
2879 AdvertiseAllConfiguredCiphers: true,
2880 },
David Benjamin241ae832016-01-15 03:04:54 -05002881 },
2882 })
2883
David Benjamin78679342016-09-16 19:42:05 -04002884 // Test empty ECDHE_PSK identity hints work as expected.
2885 testCases = append(testCases, testCase{
2886 name: "EmptyECDHEPSKHint",
2887 config: Config{
2888 MaxVersion: VersionTLS12,
2889 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2890 PreSharedKey: []byte("secret"),
2891 },
2892 flags: []string{"-psk", "secret"},
2893 })
2894
2895 // Test empty PSK identity hints work as expected, even if an explicit
2896 // ServerKeyExchange is sent.
2897 testCases = append(testCases, testCase{
2898 name: "ExplicitEmptyPSKHint",
2899 config: Config{
2900 MaxVersion: VersionTLS12,
2901 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2902 PreSharedKey: []byte("secret"),
2903 Bugs: ProtocolBugs{
2904 AlwaysSendPreSharedKeyIdentityHint: true,
2905 },
2906 },
2907 flags: []string{"-psk", "secret"},
2908 })
David Benjamin69522112017-03-28 15:38:29 -05002909
2910 // Test that clients enforce that the server-sent certificate and cipher
2911 // suite match in TLS 1.2.
2912 testCases = append(testCases, testCase{
2913 name: "CertificateCipherMismatch-RSA",
2914 config: Config{
2915 MaxVersion: VersionTLS12,
2916 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2917 Certificates: []Certificate{rsaCertificate},
2918 Bugs: ProtocolBugs{
2919 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2920 },
2921 },
2922 shouldFail: true,
2923 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2924 })
2925 testCases = append(testCases, testCase{
2926 name: "CertificateCipherMismatch-ECDSA",
2927 config: Config{
2928 MaxVersion: VersionTLS12,
2929 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2930 Certificates: []Certificate{ecdsaP256Certificate},
2931 Bugs: ProtocolBugs{
2932 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2933 },
2934 },
2935 shouldFail: true,
2936 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2937 })
2938 testCases = append(testCases, testCase{
2939 name: "CertificateCipherMismatch-Ed25519",
2940 config: Config{
2941 MaxVersion: VersionTLS12,
2942 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2943 Certificates: []Certificate{ed25519Certificate},
2944 Bugs: ProtocolBugs{
2945 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2946 },
2947 },
2948 shouldFail: true,
2949 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2950 })
2951
2952 // Test that servers decline to select a cipher suite which is
2953 // inconsistent with their configured certificate.
2954 testCases = append(testCases, testCase{
2955 testType: serverTest,
2956 name: "ServerCipherFilter-RSA",
2957 config: Config{
2958 MaxVersion: VersionTLS12,
2959 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2960 },
2961 flags: []string{
2962 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2963 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2964 },
2965 shouldFail: true,
2966 expectedError: ":NO_SHARED_CIPHER:",
2967 })
2968 testCases = append(testCases, testCase{
2969 testType: serverTest,
2970 name: "ServerCipherFilter-ECDSA",
2971 config: Config{
2972 MaxVersion: VersionTLS12,
2973 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2974 },
2975 flags: []string{
2976 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2977 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
2978 },
2979 shouldFail: true,
2980 expectedError: ":NO_SHARED_CIPHER:",
2981 })
2982 testCases = append(testCases, testCase{
2983 testType: serverTest,
2984 name: "ServerCipherFilter-Ed25519",
2985 config: Config{
2986 MaxVersion: VersionTLS12,
2987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2988 },
2989 flags: []string{
2990 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
2991 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
2992 },
2993 shouldFail: true,
2994 expectedError: ":NO_SHARED_CIPHER:",
2995 })
Adam Langley95c29f32014-06-20 12:00:00 -07002996}
2997
2998func addBadECDSASignatureTests() {
2999 for badR := BadValue(1); badR < NumBadValues; badR++ {
3000 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003001 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003002 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3003 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003004 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003005 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003006 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003007 Bugs: ProtocolBugs{
3008 BadECDSAR: badR,
3009 BadECDSAS: badS,
3010 },
3011 },
3012 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003013 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003014 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003015 testCases = append(testCases, testCase{
3016 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3017 config: Config{
3018 MaxVersion: VersionTLS13,
3019 Certificates: []Certificate{ecdsaP256Certificate},
3020 Bugs: ProtocolBugs{
3021 BadECDSAR: badR,
3022 BadECDSAS: badS,
3023 },
3024 },
3025 shouldFail: true,
3026 expectedError: ":BAD_SIGNATURE:",
3027 })
Adam Langley95c29f32014-06-20 12:00:00 -07003028 }
3029 }
3030}
3031
Adam Langley80842bd2014-06-20 12:00:00 -07003032func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003033 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003034 name: "MaxCBCPadding",
3035 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003036 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3038 Bugs: ProtocolBugs{
3039 MaxPadding: true,
3040 },
3041 },
3042 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3043 })
David Benjamin025b3d32014-07-01 19:53:04 -04003044 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003045 name: "BadCBCPadding",
3046 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003047 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003048 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3049 Bugs: ProtocolBugs{
3050 PaddingFirstByteBad: true,
3051 },
3052 },
3053 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003054 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003055 })
3056 // OpenSSL previously had an issue where the first byte of padding in
3057 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003058 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003059 name: "BadCBCPadding255",
3060 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003061 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003062 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3063 Bugs: ProtocolBugs{
3064 MaxPadding: true,
3065 PaddingFirstByteBadIf255: true,
3066 },
3067 },
3068 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3069 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003070 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003071 })
3072}
3073
Kenny Root7fdeaf12014-08-05 15:23:37 -07003074func addCBCSplittingTests() {
3075 testCases = append(testCases, testCase{
3076 name: "CBCRecordSplitting",
3077 config: Config{
3078 MaxVersion: VersionTLS10,
3079 MinVersion: VersionTLS10,
3080 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3081 },
David Benjaminac8302a2015-09-01 17:18:15 -04003082 messageLen: -1, // read until EOF
3083 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003084 flags: []string{
3085 "-async",
3086 "-write-different-record-sizes",
3087 "-cbc-record-splitting",
3088 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003089 })
3090 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003091 name: "CBCRecordSplittingPartialWrite",
3092 config: Config{
3093 MaxVersion: VersionTLS10,
3094 MinVersion: VersionTLS10,
3095 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3096 },
3097 messageLen: -1, // read until EOF
3098 flags: []string{
3099 "-async",
3100 "-write-different-record-sizes",
3101 "-cbc-record-splitting",
3102 "-partial-write",
3103 },
3104 })
3105}
3106
David Benjamin636293b2014-07-08 17:59:18 -04003107func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003108 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003109 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003110 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3111 cert, err := x509.ParseCertificate(cert.Certificate[0])
3112 if err != nil {
3113 panic(err)
3114 }
3115 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003116 }
Adam Langley2ff79332017-02-28 13:45:39 -08003117 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003118
David Benjamin636293b2014-07-08 17:59:18 -04003119 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003120 testCases = append(testCases, testCase{
3121 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003122 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003123 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003124 MinVersion: ver.version,
3125 MaxVersion: ver.version,
3126 ClientAuth: RequireAnyClientCert,
3127 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003128 },
3129 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003130 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3131 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003132 },
3133 })
3134 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003135 testType: serverTest,
3136 name: ver.name + "-Server-ClientAuth-RSA",
3137 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003138 MinVersion: ver.version,
3139 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003140 Certificates: []Certificate{rsaCertificate},
3141 },
3142 flags: []string{"-require-any-client-certificate"},
3143 })
David Benjamine098ec22014-08-27 23:13:20 -04003144 if ver.version != VersionSSL30 {
3145 testCases = append(testCases, testCase{
3146 testType: serverTest,
3147 name: ver.name + "-Server-ClientAuth-ECDSA",
3148 config: Config{
3149 MinVersion: ver.version,
3150 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003151 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003152 },
3153 flags: []string{"-require-any-client-certificate"},
3154 })
3155 testCases = append(testCases, testCase{
3156 testType: clientTest,
3157 name: ver.name + "-Client-ClientAuth-ECDSA",
3158 config: Config{
3159 MinVersion: ver.version,
3160 MaxVersion: ver.version,
3161 ClientAuth: RequireAnyClientCert,
3162 ClientCAs: certPool,
3163 },
3164 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003165 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3166 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003167 },
3168 })
3169 }
Adam Langley37646832016-08-01 16:16:46 -07003170
3171 testCases = append(testCases, testCase{
3172 name: "NoClientCertificate-" + ver.name,
3173 config: Config{
3174 MinVersion: ver.version,
3175 MaxVersion: ver.version,
3176 ClientAuth: RequireAnyClientCert,
3177 },
3178 shouldFail: true,
3179 expectedLocalError: "client didn't provide a certificate",
3180 })
3181
3182 testCases = append(testCases, testCase{
3183 // Even if not configured to expect a certificate, OpenSSL will
3184 // return X509_V_OK as the verify_result.
3185 testType: serverTest,
3186 name: "NoClientCertificateRequested-Server-" + ver.name,
3187 config: Config{
3188 MinVersion: ver.version,
3189 MaxVersion: ver.version,
3190 },
3191 flags: []string{
3192 "-expect-verify-result",
3193 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003194 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003195 })
3196
3197 testCases = append(testCases, testCase{
3198 // If a client certificate is not provided, OpenSSL will still
3199 // return X509_V_OK as the verify_result.
3200 testType: serverTest,
3201 name: "NoClientCertificate-Server-" + ver.name,
3202 config: Config{
3203 MinVersion: ver.version,
3204 MaxVersion: ver.version,
3205 },
3206 flags: []string{
3207 "-expect-verify-result",
3208 "-verify-peer",
3209 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003210 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003211 })
3212
David Benjamin1db9e1b2016-10-07 20:51:43 -04003213 certificateRequired := "remote error: certificate required"
3214 if ver.version < VersionTLS13 {
3215 // Prior to TLS 1.3, the generic handshake_failure alert
3216 // was used.
3217 certificateRequired = "remote error: handshake failure"
3218 }
Adam Langley37646832016-08-01 16:16:46 -07003219 testCases = append(testCases, testCase{
3220 testType: serverTest,
3221 name: "RequireAnyClientCertificate-" + ver.name,
3222 config: Config{
3223 MinVersion: ver.version,
3224 MaxVersion: ver.version,
3225 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003226 flags: []string{"-require-any-client-certificate"},
3227 shouldFail: true,
3228 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3229 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003230 })
3231
3232 if ver.version != VersionSSL30 {
3233 testCases = append(testCases, testCase{
3234 testType: serverTest,
3235 name: "SkipClientCertificate-" + ver.name,
3236 config: Config{
3237 MinVersion: ver.version,
3238 MaxVersion: ver.version,
3239 Bugs: ProtocolBugs{
3240 SkipClientCertificate: true,
3241 },
3242 },
3243 // Setting SSL_VERIFY_PEER allows anonymous clients.
3244 flags: []string{"-verify-peer"},
3245 shouldFail: true,
3246 expectedError: ":UNEXPECTED_MESSAGE:",
3247 })
3248 }
Adam Langley2ff79332017-02-28 13:45:39 -08003249
3250 testCases = append(testCases, testCase{
3251 testType: serverTest,
3252 name: ver.name + "-Server-CertReq-CA-List",
3253 config: Config{
3254 MinVersion: ver.version,
3255 MaxVersion: ver.version,
3256 Certificates: []Certificate{rsaCertificate},
3257 Bugs: ProtocolBugs{
3258 ExpectCertificateReqNames: caNames,
3259 },
3260 },
3261 flags: []string{
3262 "-require-any-client-certificate",
3263 "-use-client-ca-list", encodeDERValues(caNames),
3264 },
3265 })
3266
3267 testCases = append(testCases, testCase{
3268 testType: clientTest,
3269 name: ver.name + "-Client-CertReq-CA-List",
3270 config: Config{
3271 MinVersion: ver.version,
3272 MaxVersion: ver.version,
3273 Certificates: []Certificate{rsaCertificate},
3274 ClientAuth: RequireAnyClientCert,
3275 ClientCAs: certPool,
3276 },
3277 flags: []string{
3278 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3279 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3280 "-expect-client-ca-list", encodeDERValues(caNames),
3281 },
3282 })
David Benjamin636293b2014-07-08 17:59:18 -04003283 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003284
David Benjaminc032dfa2016-05-12 14:54:57 -04003285 // Client auth is only legal in certificate-based ciphers.
3286 testCases = append(testCases, testCase{
3287 testType: clientTest,
3288 name: "ClientAuth-PSK",
3289 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003290 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003291 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3292 PreSharedKey: []byte("secret"),
3293 ClientAuth: RequireAnyClientCert,
3294 },
3295 flags: []string{
3296 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3297 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3298 "-psk", "secret",
3299 },
3300 shouldFail: true,
3301 expectedError: ":UNEXPECTED_MESSAGE:",
3302 })
3303 testCases = append(testCases, testCase{
3304 testType: clientTest,
3305 name: "ClientAuth-ECDHE_PSK",
3306 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003307 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003308 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3309 PreSharedKey: []byte("secret"),
3310 ClientAuth: RequireAnyClientCert,
3311 },
3312 flags: []string{
3313 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3314 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3315 "-psk", "secret",
3316 },
3317 shouldFail: true,
3318 expectedError: ":UNEXPECTED_MESSAGE:",
3319 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003320
3321 // Regression test for a bug where the client CA list, if explicitly
3322 // set to NULL, was mis-encoded.
3323 testCases = append(testCases, testCase{
3324 testType: serverTest,
3325 name: "Null-Client-CA-List",
3326 config: Config{
3327 MaxVersion: VersionTLS12,
3328 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003329 Bugs: ProtocolBugs{
3330 ExpectCertificateReqNames: [][]byte{},
3331 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003332 },
3333 flags: []string{
3334 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003335 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003336 },
3337 })
David Benjamin636293b2014-07-08 17:59:18 -04003338}
3339
Adam Langley75712922014-10-10 16:23:43 -07003340func addExtendedMasterSecretTests() {
3341 const expectEMSFlag = "-expect-extended-master-secret"
3342
3343 for _, with := range []bool{false, true} {
3344 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003345 if with {
3346 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003347 }
3348
3349 for _, isClient := range []bool{false, true} {
3350 suffix := "-Server"
3351 testType := serverTest
3352 if isClient {
3353 suffix = "-Client"
3354 testType = clientTest
3355 }
3356
3357 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003358 // In TLS 1.3, the extension is irrelevant and
3359 // always reports as enabled.
3360 var flags []string
3361 if with || ver.version >= VersionTLS13 {
3362 flags = []string{expectEMSFlag}
3363 }
3364
Adam Langley75712922014-10-10 16:23:43 -07003365 test := testCase{
3366 testType: testType,
3367 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3368 config: Config{
3369 MinVersion: ver.version,
3370 MaxVersion: ver.version,
3371 Bugs: ProtocolBugs{
3372 NoExtendedMasterSecret: !with,
3373 RequireExtendedMasterSecret: with,
3374 },
3375 },
David Benjamin48cae082014-10-27 01:06:24 -04003376 flags: flags,
3377 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003378 }
3379 if test.shouldFail {
3380 test.expectedLocalError = "extended master secret required but not supported by peer"
3381 }
3382 testCases = append(testCases, test)
3383 }
3384 }
3385 }
3386
Adam Langleyba5934b2015-06-02 10:50:35 -07003387 for _, isClient := range []bool{false, true} {
3388 for _, supportedInFirstConnection := range []bool{false, true} {
3389 for _, supportedInResumeConnection := range []bool{false, true} {
3390 boolToWord := func(b bool) string {
3391 if b {
3392 return "Yes"
3393 }
3394 return "No"
3395 }
3396 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3397 if isClient {
3398 suffix += "Client"
3399 } else {
3400 suffix += "Server"
3401 }
3402
3403 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003404 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003405 Bugs: ProtocolBugs{
3406 RequireExtendedMasterSecret: true,
3407 },
3408 }
3409
3410 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003412 Bugs: ProtocolBugs{
3413 NoExtendedMasterSecret: true,
3414 },
3415 }
3416
3417 test := testCase{
3418 name: "ExtendedMasterSecret-" + suffix,
3419 resumeSession: true,
3420 }
3421
3422 if !isClient {
3423 test.testType = serverTest
3424 }
3425
3426 if supportedInFirstConnection {
3427 test.config = supportedConfig
3428 } else {
3429 test.config = noSupportConfig
3430 }
3431
3432 if supportedInResumeConnection {
3433 test.resumeConfig = &supportedConfig
3434 } else {
3435 test.resumeConfig = &noSupportConfig
3436 }
3437
3438 switch suffix {
3439 case "YesToYes-Client", "YesToYes-Server":
3440 // When a session is resumed, it should
3441 // still be aware that its master
3442 // secret was generated via EMS and
3443 // thus it's safe to use tls-unique.
3444 test.flags = []string{expectEMSFlag}
3445 case "NoToYes-Server":
3446 // If an original connection did not
3447 // contain EMS, but a resumption
3448 // handshake does, then a server should
3449 // not resume the session.
3450 test.expectResumeRejected = true
3451 case "YesToNo-Server":
3452 // Resuming an EMS session without the
3453 // EMS extension should cause the
3454 // server to abort the connection.
3455 test.shouldFail = true
3456 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3457 case "NoToYes-Client":
3458 // A client should abort a connection
3459 // where the server resumed a non-EMS
3460 // session but echoed the EMS
3461 // extension.
3462 test.shouldFail = true
3463 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3464 case "YesToNo-Client":
3465 // A client should abort a connection
3466 // where the server didn't echo EMS
3467 // when the session used it.
3468 test.shouldFail = true
3469 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3470 }
3471
3472 testCases = append(testCases, test)
3473 }
3474 }
3475 }
David Benjamin163c9562016-08-29 23:14:17 -04003476
3477 // Switching EMS on renegotiation is forbidden.
3478 testCases = append(testCases, testCase{
3479 name: "ExtendedMasterSecret-Renego-NoEMS",
3480 config: Config{
3481 MaxVersion: VersionTLS12,
3482 Bugs: ProtocolBugs{
3483 NoExtendedMasterSecret: true,
3484 NoExtendedMasterSecretOnRenegotiation: true,
3485 },
3486 },
3487 renegotiate: 1,
3488 flags: []string{
3489 "-renegotiate-freely",
3490 "-expect-total-renegotiations", "1",
3491 },
3492 })
3493
3494 testCases = append(testCases, testCase{
3495 name: "ExtendedMasterSecret-Renego-Upgrade",
3496 config: Config{
3497 MaxVersion: VersionTLS12,
3498 Bugs: ProtocolBugs{
3499 NoExtendedMasterSecret: true,
3500 },
3501 },
3502 renegotiate: 1,
3503 flags: []string{
3504 "-renegotiate-freely",
3505 "-expect-total-renegotiations", "1",
3506 },
3507 shouldFail: true,
3508 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3509 })
3510
3511 testCases = append(testCases, testCase{
3512 name: "ExtendedMasterSecret-Renego-Downgrade",
3513 config: Config{
3514 MaxVersion: VersionTLS12,
3515 Bugs: ProtocolBugs{
3516 NoExtendedMasterSecretOnRenegotiation: true,
3517 },
3518 },
3519 renegotiate: 1,
3520 flags: []string{
3521 "-renegotiate-freely",
3522 "-expect-total-renegotiations", "1",
3523 },
3524 shouldFail: true,
3525 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3526 })
Adam Langley75712922014-10-10 16:23:43 -07003527}
3528
David Benjamin582ba042016-07-07 12:33:25 -07003529type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003530 protocol protocol
3531 async bool
3532 splitHandshake bool
3533 packHandshakeFlight bool
3534 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003535}
3536
David Benjamin43ec06f2014-08-05 02:28:57 -04003537// Adds tests that try to cover the range of the handshake state machine, under
3538// various conditions. Some of these are redundant with other tests, but they
3539// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003540func addAllStateMachineCoverageTests() {
3541 for _, async := range []bool{false, true} {
3542 for _, protocol := range []protocol{tls, dtls} {
3543 addStateMachineCoverageTests(stateMachineTestConfig{
3544 protocol: protocol,
3545 async: async,
3546 })
3547 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003548 protocol: protocol,
3549 async: async,
3550 implicitHandshake: true,
3551 })
3552 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003553 protocol: protocol,
3554 async: async,
3555 splitHandshake: true,
3556 })
3557 if protocol == tls {
3558 addStateMachineCoverageTests(stateMachineTestConfig{
3559 protocol: protocol,
3560 async: async,
3561 packHandshakeFlight: true,
3562 })
3563 }
3564 }
3565 }
3566}
3567
3568func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 var tests []testCase
3570
3571 // Basic handshake, with resumption. Client and server,
3572 // session ID and session ticket.
3573 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003574 name: "Basic-Client",
3575 config: Config{
3576 MaxVersion: VersionTLS12,
3577 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003578 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003579 // Ensure session tickets are used, not session IDs.
3580 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003581 })
3582 tests = append(tests, testCase{
3583 name: "Basic-Client-RenewTicket",
3584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003585 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003586 Bugs: ProtocolBugs{
3587 RenewTicketOnResume: true,
3588 },
3589 },
David Benjamin46662482016-08-17 00:51:00 -04003590 flags: []string{"-expect-ticket-renewal"},
3591 resumeSession: true,
3592 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003593 })
3594 tests = append(tests, testCase{
3595 name: "Basic-Client-NoTicket",
3596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003597 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003598 SessionTicketsDisabled: true,
3599 },
3600 resumeSession: true,
3601 })
3602 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003603 testType: serverTest,
3604 name: "Basic-Server",
3605 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003606 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003607 Bugs: ProtocolBugs{
3608 RequireSessionTickets: true,
3609 },
3610 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003611 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003612 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003613 })
3614 tests = append(tests, testCase{
3615 testType: serverTest,
3616 name: "Basic-Server-NoTickets",
3617 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003618 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003619 SessionTicketsDisabled: true,
3620 },
3621 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003622 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003623 })
3624 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003625 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003626 name: "Basic-Server-EarlyCallback",
3627 config: Config{
3628 MaxVersion: VersionTLS12,
3629 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003630 flags: []string{"-use-early-callback"},
3631 resumeSession: true,
3632 })
3633
Steven Valdez143e8b32016-07-11 13:19:03 -04003634 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003635 if config.protocol == tls {
3636 tests = append(tests, testCase{
3637 name: "TLS13-1RTT-Client",
3638 config: Config{
3639 MaxVersion: VersionTLS13,
3640 MinVersion: VersionTLS13,
3641 },
David Benjamin46662482016-08-17 00:51:00 -04003642 resumeSession: true,
3643 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003644 })
3645
3646 tests = append(tests, testCase{
3647 testType: serverTest,
3648 name: "TLS13-1RTT-Server",
3649 config: Config{
3650 MaxVersion: VersionTLS13,
3651 MinVersion: VersionTLS13,
3652 },
David Benjamin46662482016-08-17 00:51:00 -04003653 resumeSession: true,
3654 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003655 // TLS 1.3 uses tickets, so the session should not be
3656 // cached statefully.
3657 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003658 })
3659
3660 tests = append(tests, testCase{
3661 name: "TLS13-HelloRetryRequest-Client",
3662 config: Config{
3663 MaxVersion: VersionTLS13,
3664 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003665 // P-384 requires a HelloRetryRequest against BoringSSL's default
3666 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003667 CurvePreferences: []CurveID{CurveP384},
3668 Bugs: ProtocolBugs{
3669 ExpectMissingKeyShare: true,
3670 },
3671 },
3672 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3673 resumeSession: true,
3674 })
3675
3676 tests = append(tests, testCase{
3677 testType: serverTest,
3678 name: "TLS13-HelloRetryRequest-Server",
3679 config: Config{
3680 MaxVersion: VersionTLS13,
3681 MinVersion: VersionTLS13,
3682 // Require a HelloRetryRequest for every curve.
3683 DefaultCurves: []CurveID{},
3684 },
3685 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3686 resumeSession: true,
3687 })
Steven Valdez2d850622017-01-11 11:34:52 -05003688
Steven Valdez2d850622017-01-11 11:34:52 -05003689 tests = append(tests, testCase{
3690 testType: clientTest,
3691 name: "TLS13-EarlyData-Client",
3692 config: Config{
3693 MaxVersion: VersionTLS13,
3694 MinVersion: VersionTLS13,
3695 MaxEarlyDataSize: 16384,
3696 },
Steven Valdeze831a812017-03-09 14:56:07 -05003697 resumeConfig: &Config{
3698 MaxVersion: VersionTLS13,
3699 MinVersion: VersionTLS13,
3700 MaxEarlyDataSize: 16384,
3701 Bugs: ProtocolBugs{
3702 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3703 },
3704 },
Steven Valdez2d850622017-01-11 11:34:52 -05003705 resumeSession: true,
3706 flags: []string{
3707 "-enable-early-data",
3708 "-expect-early-data-info",
3709 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003710 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003711 },
3712 })
3713
3714 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003715 testType: clientTest,
3716 name: "TLS13-EarlyData-TooMuchData-Client",
3717 config: Config{
3718 MaxVersion: VersionTLS13,
3719 MinVersion: VersionTLS13,
3720 MaxEarlyDataSize: 2,
3721 },
3722 resumeConfig: &Config{
3723 MaxVersion: VersionTLS13,
3724 MinVersion: VersionTLS13,
3725 MaxEarlyDataSize: 2,
3726 Bugs: ProtocolBugs{
3727 ExpectEarlyData: [][]byte{{'h', 'e'}},
3728 },
3729 },
3730 resumeShimPrefix: "llo",
3731 resumeSession: true,
3732 flags: []string{
3733 "-enable-early-data",
3734 "-expect-early-data-info",
3735 "-expect-accept-early-data",
3736 "-on-resume-shim-writes-first",
3737 },
3738 })
3739
3740 // Unfinished writes can only be tested when operations are async. EarlyData
3741 // can't be tested as part of an ImplicitHandshake in this case since
3742 // otherwise the early data will be sent as normal data.
3743 if config.async && !config.implicitHandshake {
3744 tests = append(tests, testCase{
3745 testType: clientTest,
3746 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3747 config: Config{
3748 MaxVersion: VersionTLS13,
3749 MinVersion: VersionTLS13,
3750 MaxEarlyDataSize: 16384,
3751 },
3752 resumeConfig: &Config{
3753 MaxVersion: VersionTLS13,
3754 MinVersion: VersionTLS13,
3755 MaxEarlyDataSize: 16384,
3756 Bugs: ProtocolBugs{
3757 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3758 },
3759 },
3760 resumeSession: true,
3761 flags: []string{
3762 "-enable-early-data",
3763 "-expect-early-data-info",
3764 "-expect-accept-early-data",
3765 "-on-resume-read-with-unfinished-write",
3766 "-on-resume-shim-writes-first",
3767 },
3768 })
3769
3770 // Rejected unfinished writes are discarded (from the
3771 // perspective of the calling application) on 0-RTT
3772 // reject.
3773 tests = append(tests, testCase{
3774 testType: clientTest,
3775 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3776 config: Config{
3777 MaxVersion: VersionTLS13,
3778 MinVersion: VersionTLS13,
3779 MaxEarlyDataSize: 16384,
3780 },
3781 resumeConfig: &Config{
3782 MaxVersion: VersionTLS13,
3783 MinVersion: VersionTLS13,
3784 MaxEarlyDataSize: 16384,
3785 Bugs: ProtocolBugs{
3786 AlwaysRejectEarlyData: true,
3787 },
3788 },
3789 resumeSession: true,
3790 flags: []string{
3791 "-enable-early-data",
3792 "-expect-early-data-info",
3793 "-expect-reject-early-data",
3794 "-on-resume-read-with-unfinished-write",
3795 "-on-resume-shim-writes-first",
3796 },
3797 })
3798 }
3799
3800 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003801 testType: serverTest,
3802 name: "TLS13-EarlyData-Server",
3803 config: Config{
3804 MaxVersion: VersionTLS13,
3805 MinVersion: VersionTLS13,
3806 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003807 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003808 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003809 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003810 },
3811 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003812 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003813 resumeSession: true,
3814 flags: []string{
3815 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003816 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003817 },
3818 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003819
3820 tests = append(tests, testCase{
3821 testType: serverTest,
3822 name: "TLS13-MaxEarlyData-Server",
3823 config: Config{
3824 MaxVersion: VersionTLS13,
3825 MinVersion: VersionTLS13,
3826 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003827 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003828 ExpectEarlyDataAccepted: true,
3829 },
3830 },
3831 messageCount: 2,
3832 resumeSession: true,
3833 flags: []string{
3834 "-enable-early-data",
3835 "-expect-accept-early-data",
3836 },
3837 shouldFail: true,
3838 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
3839 })
David Benjamine73c7f42016-08-17 00:29:33 -04003840 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003841
David Benjamin760b1dd2015-05-15 23:33:48 -04003842 // TLS client auth.
3843 tests = append(tests, testCase{
3844 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003845 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003846 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003847 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003848 ClientAuth: RequestClientCert,
3849 },
3850 })
3851 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003852 testType: serverTest,
3853 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003854 config: Config{
3855 MaxVersion: VersionTLS12,
3856 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003857 // Setting SSL_VERIFY_PEER allows anonymous clients.
3858 flags: []string{"-verify-peer"},
3859 })
David Benjamin582ba042016-07-07 12:33:25 -07003860 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003861 tests = append(tests, testCase{
3862 testType: clientTest,
3863 name: "ClientAuth-NoCertificate-Client-SSL3",
3864 config: Config{
3865 MaxVersion: VersionSSL30,
3866 ClientAuth: RequestClientCert,
3867 },
3868 })
3869 tests = append(tests, testCase{
3870 testType: serverTest,
3871 name: "ClientAuth-NoCertificate-Server-SSL3",
3872 config: Config{
3873 MaxVersion: VersionSSL30,
3874 },
3875 // Setting SSL_VERIFY_PEER allows anonymous clients.
3876 flags: []string{"-verify-peer"},
3877 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003878 tests = append(tests, testCase{
3879 testType: clientTest,
3880 name: "ClientAuth-NoCertificate-Client-TLS13",
3881 config: Config{
3882 MaxVersion: VersionTLS13,
3883 ClientAuth: RequestClientCert,
3884 },
3885 })
3886 tests = append(tests, testCase{
3887 testType: serverTest,
3888 name: "ClientAuth-NoCertificate-Server-TLS13",
3889 config: Config{
3890 MaxVersion: VersionTLS13,
3891 },
3892 // Setting SSL_VERIFY_PEER allows anonymous clients.
3893 flags: []string{"-verify-peer"},
3894 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003895 }
3896 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003897 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003898 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003900 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003901 ClientAuth: RequireAnyClientCert,
3902 },
3903 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003904 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3905 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003906 },
3907 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003908 tests = append(tests, testCase{
3909 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003910 name: "ClientAuth-RSA-Client-TLS13",
3911 config: Config{
3912 MaxVersion: VersionTLS13,
3913 ClientAuth: RequireAnyClientCert,
3914 },
3915 flags: []string{
3916 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3917 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3918 },
3919 })
3920 tests = append(tests, testCase{
3921 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003922 name: "ClientAuth-ECDSA-Client",
3923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003925 ClientAuth: RequireAnyClientCert,
3926 },
3927 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003928 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3929 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003930 },
3931 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003932 tests = append(tests, testCase{
3933 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003934 name: "ClientAuth-ECDSA-Client-TLS13",
3935 config: Config{
3936 MaxVersion: VersionTLS13,
3937 ClientAuth: RequireAnyClientCert,
3938 },
3939 flags: []string{
3940 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3941 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3942 },
3943 })
3944 tests = append(tests, testCase{
3945 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 name: "ClientAuth-NoCertificate-OldCallback",
3947 config: Config{
3948 MaxVersion: VersionTLS12,
3949 ClientAuth: RequestClientCert,
3950 },
3951 flags: []string{"-use-old-client-cert-callback"},
3952 })
3953 tests = append(tests, testCase{
3954 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003955 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3956 config: Config{
3957 MaxVersion: VersionTLS13,
3958 ClientAuth: RequestClientCert,
3959 },
3960 flags: []string{"-use-old-client-cert-callback"},
3961 })
3962 tests = append(tests, testCase{
3963 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003964 name: "ClientAuth-OldCallback",
3965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003966 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003967 ClientAuth: RequireAnyClientCert,
3968 },
3969 flags: []string{
3970 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3971 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3972 "-use-old-client-cert-callback",
3973 },
3974 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003975 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003976 testType: clientTest,
3977 name: "ClientAuth-OldCallback-TLS13",
3978 config: Config{
3979 MaxVersion: VersionTLS13,
3980 ClientAuth: RequireAnyClientCert,
3981 },
3982 flags: []string{
3983 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3984 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3985 "-use-old-client-cert-callback",
3986 },
3987 })
3988 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003989 testType: serverTest,
3990 name: "ClientAuth-Server",
3991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003992 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003993 Certificates: []Certificate{rsaCertificate},
3994 },
3995 flags: []string{"-require-any-client-certificate"},
3996 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003997 tests = append(tests, testCase{
3998 testType: serverTest,
3999 name: "ClientAuth-Server-TLS13",
4000 config: Config{
4001 MaxVersion: VersionTLS13,
4002 Certificates: []Certificate{rsaCertificate},
4003 },
4004 flags: []string{"-require-any-client-certificate"},
4005 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004006
David Benjamin4c3ddf72016-06-29 18:13:53 -04004007 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004008 tests = append(tests, testCase{
4009 testType: serverTest,
4010 name: "Basic-Server-RSA",
4011 config: Config{
4012 MaxVersion: VersionTLS12,
4013 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4014 },
4015 flags: []string{
4016 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4017 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4018 },
4019 })
4020 tests = append(tests, testCase{
4021 testType: serverTest,
4022 name: "Basic-Server-ECDHE-RSA",
4023 config: Config{
4024 MaxVersion: VersionTLS12,
4025 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4026 },
4027 flags: []string{
4028 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4029 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4030 },
4031 })
4032 tests = append(tests, testCase{
4033 testType: serverTest,
4034 name: "Basic-Server-ECDHE-ECDSA",
4035 config: Config{
4036 MaxVersion: VersionTLS12,
4037 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4038 },
4039 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004040 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4041 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004042 },
4043 })
David Benjamin69522112017-03-28 15:38:29 -05004044 tests = append(tests, testCase{
4045 testType: serverTest,
4046 name: "Basic-Server-Ed25519",
4047 config: Config{
4048 MaxVersion: VersionTLS12,
4049 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4050 },
4051 flags: []string{
4052 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4053 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4054 "-enable-ed25519",
4055 },
4056 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004057
David Benjamin760b1dd2015-05-15 23:33:48 -04004058 // No session ticket support; server doesn't send NewSessionTicket.
4059 tests = append(tests, testCase{
4060 name: "SessionTicketsDisabled-Client",
4061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004062 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004063 SessionTicketsDisabled: true,
4064 },
4065 })
4066 tests = append(tests, testCase{
4067 testType: serverTest,
4068 name: "SessionTicketsDisabled-Server",
4069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004070 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004071 SessionTicketsDisabled: true,
4072 },
4073 })
4074
4075 // Skip ServerKeyExchange in PSK key exchange if there's no
4076 // identity hint.
4077 tests = append(tests, testCase{
4078 name: "EmptyPSKHint-Client",
4079 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004080 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004081 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4082 PreSharedKey: []byte("secret"),
4083 },
4084 flags: []string{"-psk", "secret"},
4085 })
4086 tests = append(tests, testCase{
4087 testType: serverTest,
4088 name: "EmptyPSKHint-Server",
4089 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004090 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004091 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4092 PreSharedKey: []byte("secret"),
4093 },
4094 flags: []string{"-psk", "secret"},
4095 })
4096
David Benjamin4c3ddf72016-06-29 18:13:53 -04004097 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004098 tests = append(tests, testCase{
4099 testType: clientTest,
4100 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004101 config: Config{
4102 MaxVersion: VersionTLS12,
4103 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004104 flags: []string{
4105 "-enable-ocsp-stapling",
4106 "-expect-ocsp-response",
4107 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004108 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004109 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004110 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004111 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004112 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004113 testType: serverTest,
4114 name: "OCSPStapling-Server",
4115 config: Config{
4116 MaxVersion: VersionTLS12,
4117 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004118 expectedOCSPResponse: testOCSPResponse,
4119 flags: []string{
4120 "-ocsp-response",
4121 base64.StdEncoding.EncodeToString(testOCSPResponse),
4122 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004123 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004124 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004125 tests = append(tests, testCase{
4126 testType: clientTest,
4127 name: "OCSPStapling-Client-TLS13",
4128 config: Config{
4129 MaxVersion: VersionTLS13,
4130 },
4131 flags: []string{
4132 "-enable-ocsp-stapling",
4133 "-expect-ocsp-response",
4134 base64.StdEncoding.EncodeToString(testOCSPResponse),
4135 "-verify-peer",
4136 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004137 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004138 })
4139 tests = append(tests, testCase{
4140 testType: serverTest,
4141 name: "OCSPStapling-Server-TLS13",
4142 config: Config{
4143 MaxVersion: VersionTLS13,
4144 },
4145 expectedOCSPResponse: testOCSPResponse,
4146 flags: []string{
4147 "-ocsp-response",
4148 base64.StdEncoding.EncodeToString(testOCSPResponse),
4149 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004150 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004151 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004152
David Benjamin4c3ddf72016-06-29 18:13:53 -04004153 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004154 for _, vers := range tlsVersions {
4155 if config.protocol == dtls && !vers.hasDTLS {
4156 continue
4157 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004158 for _, testType := range []testType{clientTest, serverTest} {
4159 suffix := "-Client"
4160 if testType == serverTest {
4161 suffix = "-Server"
4162 }
4163 suffix += "-" + vers.name
4164
4165 flag := "-verify-peer"
4166 if testType == serverTest {
4167 flag = "-require-any-client-certificate"
4168 }
4169
4170 tests = append(tests, testCase{
4171 testType: testType,
4172 name: "CertificateVerificationSucceed" + suffix,
4173 config: Config{
4174 MaxVersion: vers.version,
4175 Certificates: []Certificate{rsaCertificate},
4176 },
4177 flags: []string{
4178 flag,
4179 "-expect-verify-result",
4180 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004181 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004182 })
4183 tests = append(tests, testCase{
4184 testType: testType,
4185 name: "CertificateVerificationFail" + suffix,
4186 config: Config{
4187 MaxVersion: vers.version,
4188 Certificates: []Certificate{rsaCertificate},
4189 },
4190 flags: []string{
4191 flag,
4192 "-verify-fail",
4193 },
4194 shouldFail: true,
4195 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4196 })
4197 }
4198
4199 // By default, the client is in a soft fail mode where the peer
4200 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004201 tests = append(tests, testCase{
4202 testType: clientTest,
4203 name: "CertificateVerificationSoftFail-" + vers.name,
4204 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004205 MaxVersion: vers.version,
4206 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004207 },
4208 flags: []string{
4209 "-verify-fail",
4210 "-expect-verify-result",
4211 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004212 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004213 })
4214 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004215
David Benjamin1d4f4c02016-07-26 18:03:08 -04004216 tests = append(tests, testCase{
4217 name: "ShimSendAlert",
4218 flags: []string{"-send-alert"},
4219 shimWritesFirst: true,
4220 shouldFail: true,
4221 expectedLocalError: "remote error: decompression failure",
4222 })
4223
David Benjamin582ba042016-07-07 12:33:25 -07004224 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004225 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004226 name: "Renegotiate-Client",
4227 config: Config{
4228 MaxVersion: VersionTLS12,
4229 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004230 renegotiate: 1,
4231 flags: []string{
4232 "-renegotiate-freely",
4233 "-expect-total-renegotiations", "1",
4234 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004235 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004236
David Benjamin47921102016-07-28 11:29:18 -04004237 tests = append(tests, testCase{
4238 name: "SendHalfHelloRequest",
4239 config: Config{
4240 MaxVersion: VersionTLS12,
4241 Bugs: ProtocolBugs{
4242 PackHelloRequestWithFinished: config.packHandshakeFlight,
4243 },
4244 },
4245 sendHalfHelloRequest: true,
4246 flags: []string{"-renegotiate-ignore"},
4247 shouldFail: true,
4248 expectedError: ":UNEXPECTED_RECORD:",
4249 })
4250
David Benjamin760b1dd2015-05-15 23:33:48 -04004251 // NPN on client and server; results in post-handshake message.
4252 tests = append(tests, testCase{
4253 name: "NPN-Client",
4254 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004255 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004256 NextProtos: []string{"foo"},
4257 },
4258 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004259 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004260 expectedNextProto: "foo",
4261 expectedNextProtoType: npn,
4262 })
4263 tests = append(tests, testCase{
4264 testType: serverTest,
4265 name: "NPN-Server",
4266 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004267 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004268 NextProtos: []string{"bar"},
4269 },
4270 flags: []string{
4271 "-advertise-npn", "\x03foo\x03bar\x03baz",
4272 "-expect-next-proto", "bar",
4273 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004274 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004275 expectedNextProto: "bar",
4276 expectedNextProtoType: npn,
4277 })
4278
4279 // TODO(davidben): Add tests for when False Start doesn't trigger.
4280
4281 // Client does False Start and negotiates NPN.
4282 tests = append(tests, testCase{
4283 name: "FalseStart",
4284 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004285 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004286 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4287 NextProtos: []string{"foo"},
4288 Bugs: ProtocolBugs{
4289 ExpectFalseStart: true,
4290 },
4291 },
4292 flags: []string{
4293 "-false-start",
4294 "-select-next-proto", "foo",
4295 },
4296 shimWritesFirst: true,
4297 resumeSession: true,
4298 })
4299
4300 // Client does False Start and negotiates ALPN.
4301 tests = append(tests, testCase{
4302 name: "FalseStart-ALPN",
4303 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004304 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004305 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4306 NextProtos: []string{"foo"},
4307 Bugs: ProtocolBugs{
4308 ExpectFalseStart: true,
4309 },
4310 },
4311 flags: []string{
4312 "-false-start",
4313 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004314 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004315 },
4316 shimWritesFirst: true,
4317 resumeSession: true,
4318 })
4319
David Benjamin760b1dd2015-05-15 23:33:48 -04004320 // False Start without session tickets.
4321 tests = append(tests, testCase{
4322 name: "FalseStart-SessionTicketsDisabled",
4323 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004324 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4326 NextProtos: []string{"foo"},
4327 SessionTicketsDisabled: true,
4328 Bugs: ProtocolBugs{
4329 ExpectFalseStart: true,
4330 },
4331 },
4332 flags: []string{
4333 "-false-start",
4334 "-select-next-proto", "foo",
4335 },
4336 shimWritesFirst: true,
4337 })
4338
4339 // Server parses a V2ClientHello.
4340 tests = append(tests, testCase{
4341 testType: serverTest,
4342 name: "SendV2ClientHello",
4343 config: Config{
4344 // Choose a cipher suite that does not involve
4345 // elliptic curves, so no extensions are
4346 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004347 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004348 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004349 Bugs: ProtocolBugs{
4350 SendV2ClientHello: true,
4351 },
4352 },
4353 })
4354
Nick Harper60a85cb2016-09-23 16:25:11 -07004355 // Test Channel ID
4356 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004357 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004358 continue
4359 }
4360 // Client sends a Channel ID.
4361 tests = append(tests, testCase{
4362 name: "ChannelID-Client-" + ver.name,
4363 config: Config{
4364 MaxVersion: ver.version,
4365 RequestChannelID: true,
4366 },
4367 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4368 resumeSession: true,
4369 expectChannelID: true,
4370 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004371
Nick Harper60a85cb2016-09-23 16:25:11 -07004372 // Server accepts a Channel ID.
4373 tests = append(tests, testCase{
4374 testType: serverTest,
4375 name: "ChannelID-Server-" + ver.name,
4376 config: Config{
4377 MaxVersion: ver.version,
4378 ChannelID: channelIDKey,
4379 },
4380 flags: []string{
4381 "-expect-channel-id",
4382 base64.StdEncoding.EncodeToString(channelIDBytes),
4383 },
4384 resumeSession: true,
4385 expectChannelID: true,
4386 })
4387
4388 tests = append(tests, testCase{
4389 testType: serverTest,
4390 name: "InvalidChannelIDSignature-" + ver.name,
4391 config: Config{
4392 MaxVersion: ver.version,
4393 ChannelID: channelIDKey,
4394 Bugs: ProtocolBugs{
4395 InvalidChannelIDSignature: true,
4396 },
4397 },
4398 flags: []string{"-enable-channel-id"},
4399 shouldFail: true,
4400 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4401 })
4402 }
David Benjamin30789da2015-08-29 22:56:45 -04004403
David Benjaminf8fcdf32016-06-08 15:56:13 -04004404 // Channel ID and NPN at the same time, to ensure their relative
4405 // ordering is correct.
4406 tests = append(tests, testCase{
4407 name: "ChannelID-NPN-Client",
4408 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004409 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004410 RequestChannelID: true,
4411 NextProtos: []string{"foo"},
4412 },
4413 flags: []string{
4414 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4415 "-select-next-proto", "foo",
4416 },
4417 resumeSession: true,
4418 expectChannelID: true,
4419 expectedNextProto: "foo",
4420 expectedNextProtoType: npn,
4421 })
4422 tests = append(tests, testCase{
4423 testType: serverTest,
4424 name: "ChannelID-NPN-Server",
4425 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004426 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004427 ChannelID: channelIDKey,
4428 NextProtos: []string{"bar"},
4429 },
4430 flags: []string{
4431 "-expect-channel-id",
4432 base64.StdEncoding.EncodeToString(channelIDBytes),
4433 "-advertise-npn", "\x03foo\x03bar\x03baz",
4434 "-expect-next-proto", "bar",
4435 },
4436 resumeSession: true,
4437 expectChannelID: true,
4438 expectedNextProto: "bar",
4439 expectedNextProtoType: npn,
4440 })
4441
David Benjamin30789da2015-08-29 22:56:45 -04004442 // Bidirectional shutdown with the runner initiating.
4443 tests = append(tests, testCase{
4444 name: "Shutdown-Runner",
4445 config: Config{
4446 Bugs: ProtocolBugs{
4447 ExpectCloseNotify: true,
4448 },
4449 },
4450 flags: []string{"-check-close-notify"},
4451 })
4452
David Benjamine3843d42017-03-25 18:00:56 -05004453 if !config.implicitHandshake {
4454 // Bidirectional shutdown with the shim initiating. The runner,
4455 // in the meantime, sends garbage before the close_notify which
4456 // the shim must ignore. This test is disabled under implicit
4457 // handshake tests because the shim never reads or writes.
4458 tests = append(tests, testCase{
4459 name: "Shutdown-Shim",
4460 config: Config{
4461 MaxVersion: VersionTLS12,
4462 Bugs: ProtocolBugs{
4463 ExpectCloseNotify: true,
4464 },
David Benjamin30789da2015-08-29 22:56:45 -04004465 },
David Benjamine3843d42017-03-25 18:00:56 -05004466 shimShutsDown: true,
4467 sendEmptyRecords: 1,
4468 sendWarningAlerts: 1,
4469 flags: []string{"-check-close-notify"},
4470 })
4471 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004472 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004473 // TODO(davidben): DTLS 1.3 will want a similar thing for
4474 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004475 tests = append(tests, testCase{
4476 name: "SkipHelloVerifyRequest",
4477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004478 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004479 Bugs: ProtocolBugs{
4480 SkipHelloVerifyRequest: true,
4481 },
4482 },
4483 })
4484 }
4485
David Benjamin760b1dd2015-05-15 23:33:48 -04004486 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004487 test.protocol = config.protocol
4488 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004489 test.name += "-DTLS"
4490 }
David Benjamin582ba042016-07-07 12:33:25 -07004491 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004492 test.name += "-Async"
4493 test.flags = append(test.flags, "-async")
4494 } else {
4495 test.name += "-Sync"
4496 }
David Benjamin582ba042016-07-07 12:33:25 -07004497 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004498 test.name += "-SplitHandshakeRecords"
4499 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004500 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004501 test.config.Bugs.MaxPacketLength = 256
4502 test.flags = append(test.flags, "-mtu", "256")
4503 }
4504 }
David Benjamin582ba042016-07-07 12:33:25 -07004505 if config.packHandshakeFlight {
4506 test.name += "-PackHandshakeFlight"
4507 test.config.Bugs.PackHandshakeFlight = true
4508 }
David Benjamine3843d42017-03-25 18:00:56 -05004509 if config.implicitHandshake {
4510 test.name += "-ImplicitHandshake"
4511 test.flags = append(test.flags, "-implicit-handshake")
4512 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004513 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004514 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004515}
4516
Adam Langley524e7172015-02-20 16:04:00 -08004517func addDDoSCallbackTests() {
4518 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004519 for _, resume := range []bool{false, true} {
4520 suffix := "Resume"
4521 if resume {
4522 suffix = "No" + suffix
4523 }
4524
4525 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004526 testType: serverTest,
4527 name: "Server-DDoS-OK-" + suffix,
4528 config: Config{
4529 MaxVersion: VersionTLS12,
4530 },
Adam Langley524e7172015-02-20 16:04:00 -08004531 flags: []string{"-install-ddos-callback"},
4532 resumeSession: resume,
4533 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004534 testCases = append(testCases, testCase{
4535 testType: serverTest,
4536 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4537 config: Config{
4538 MaxVersion: VersionTLS13,
4539 },
4540 flags: []string{"-install-ddos-callback"},
4541 resumeSession: resume,
4542 })
Adam Langley524e7172015-02-20 16:04:00 -08004543
4544 failFlag := "-fail-ddos-callback"
4545 if resume {
4546 failFlag = "-fail-second-ddos-callback"
4547 }
4548 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004549 testType: serverTest,
4550 name: "Server-DDoS-Reject-" + suffix,
4551 config: Config{
4552 MaxVersion: VersionTLS12,
4553 },
David Benjamin2c66e072016-09-16 15:58:00 -04004554 flags: []string{"-install-ddos-callback", failFlag},
4555 resumeSession: resume,
4556 shouldFail: true,
4557 expectedError: ":CONNECTION_REJECTED:",
4558 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004559 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4563 config: Config{
4564 MaxVersion: VersionTLS13,
4565 },
David Benjamin2c66e072016-09-16 15:58:00 -04004566 flags: []string{"-install-ddos-callback", failFlag},
4567 resumeSession: resume,
4568 shouldFail: true,
4569 expectedError: ":CONNECTION_REJECTED:",
4570 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004571 })
Adam Langley524e7172015-02-20 16:04:00 -08004572 }
4573}
4574
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004575func addVersionNegotiationTests() {
4576 for i, shimVers := range tlsVersions {
4577 // Assemble flags to disable all newer versions on the shim.
4578 var flags []string
4579 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004580 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004581 }
4582
Steven Valdezfdd10992016-09-15 16:27:05 -04004583 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004584 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004585 protocols := []protocol{tls}
4586 if runnerVers.hasDTLS && shimVers.hasDTLS {
4587 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004588 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004589 for _, protocol := range protocols {
4590 expectedVersion := shimVers.version
4591 if runnerVers.version < shimVers.version {
4592 expectedVersion = runnerVers.version
4593 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004594
David Benjamin8b8c0062014-11-23 02:47:52 -05004595 suffix := shimVers.name + "-" + runnerVers.name
4596 if protocol == dtls {
4597 suffix += "-DTLS"
4598 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004599
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004600 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004601 clientVers := shimVers.version
4602 if clientVers > VersionTLS10 {
4603 clientVers = VersionTLS10
4604 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004605 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004606 serverVers := expectedVersion
4607 if expectedVersion >= VersionTLS13 {
4608 serverVers = VersionTLS10
4609 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004610 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004611
David Benjamin8b8c0062014-11-23 02:47:52 -05004612 testCases = append(testCases, testCase{
4613 protocol: protocol,
4614 testType: clientTest,
4615 name: "VersionNegotiation-Client-" + suffix,
4616 config: Config{
4617 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004618 Bugs: ProtocolBugs{
4619 ExpectInitialRecordVersion: clientVers,
4620 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004621 },
4622 flags: flags,
4623 expectedVersion: expectedVersion,
4624 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004625 testCases = append(testCases, testCase{
4626 protocol: protocol,
4627 testType: clientTest,
4628 name: "VersionNegotiation-Client2-" + suffix,
4629 config: Config{
4630 MaxVersion: runnerVers.version,
4631 Bugs: ProtocolBugs{
4632 ExpectInitialRecordVersion: clientVers,
4633 },
4634 },
David Benjamin353577c2017-06-29 15:54:58 -04004635 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004636 expectedVersion: expectedVersion,
4637 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004638
4639 testCases = append(testCases, testCase{
4640 protocol: protocol,
4641 testType: serverTest,
4642 name: "VersionNegotiation-Server-" + suffix,
4643 config: Config{
4644 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004645 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004646 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004647 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004648 },
4649 flags: flags,
4650 expectedVersion: expectedVersion,
4651 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004652 testCases = append(testCases, testCase{
4653 protocol: protocol,
4654 testType: serverTest,
4655 name: "VersionNegotiation-Server2-" + suffix,
4656 config: Config{
4657 MaxVersion: runnerVers.version,
4658 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004659 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004660 },
4661 },
David Benjamin353577c2017-06-29 15:54:58 -04004662 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004663 expectedVersion: expectedVersion,
4664 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004665 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004666 }
4667 }
David Benjamin95c69562016-06-29 18:15:03 -04004668
Steven Valdezfdd10992016-09-15 16:27:05 -04004669 // Test the version extension at all versions.
4670 for _, vers := range tlsVersions {
4671 protocols := []protocol{tls}
4672 if vers.hasDTLS {
4673 protocols = append(protocols, dtls)
4674 }
4675 for _, protocol := range protocols {
4676 suffix := vers.name
4677 if protocol == dtls {
4678 suffix += "-DTLS"
4679 }
4680
Steven Valdezc94998a2017-06-20 10:55:02 -04004681 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004682 testCases = append(testCases, testCase{
4683 protocol: protocol,
4684 testType: serverTest,
4685 name: "VersionNegotiationExtension-" + suffix,
4686 config: Config{
4687 Bugs: ProtocolBugs{
4688 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4689 },
4690 },
4691 expectedVersion: vers.version,
4692 })
4693 }
4694
4695 }
4696
4697 // If all versions are unknown, negotiation fails.
4698 testCases = append(testCases, testCase{
4699 testType: serverTest,
4700 name: "NoSupportedVersions",
4701 config: Config{
4702 Bugs: ProtocolBugs{
4703 SendSupportedVersions: []uint16{0x1111},
4704 },
4705 },
4706 shouldFail: true,
4707 expectedError: ":UNSUPPORTED_PROTOCOL:",
4708 })
4709 testCases = append(testCases, testCase{
4710 protocol: dtls,
4711 testType: serverTest,
4712 name: "NoSupportedVersions-DTLS",
4713 config: Config{
4714 Bugs: ProtocolBugs{
4715 SendSupportedVersions: []uint16{0x1111},
4716 },
4717 },
4718 shouldFail: true,
4719 expectedError: ":UNSUPPORTED_PROTOCOL:",
4720 })
4721
4722 testCases = append(testCases, testCase{
4723 testType: serverTest,
4724 name: "ClientHelloVersionTooHigh",
4725 config: Config{
4726 MaxVersion: VersionTLS13,
4727 Bugs: ProtocolBugs{
4728 SendClientVersion: 0x0304,
4729 OmitSupportedVersions: true,
4730 },
4731 },
4732 expectedVersion: VersionTLS12,
4733 })
4734
4735 testCases = append(testCases, testCase{
4736 testType: serverTest,
4737 name: "ConflictingVersionNegotiation",
4738 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004739 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004740 SendClientVersion: VersionTLS12,
4741 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004742 },
4743 },
David Benjaminad75a662016-09-30 15:42:59 -04004744 // The extension takes precedence over the ClientHello version.
4745 expectedVersion: VersionTLS11,
4746 })
4747
4748 testCases = append(testCases, testCase{
4749 testType: serverTest,
4750 name: "ConflictingVersionNegotiation-2",
4751 config: Config{
4752 Bugs: ProtocolBugs{
4753 SendClientVersion: VersionTLS11,
4754 SendSupportedVersions: []uint16{VersionTLS12},
4755 },
4756 },
4757 // The extension takes precedence over the ClientHello version.
4758 expectedVersion: VersionTLS12,
4759 })
4760
4761 testCases = append(testCases, testCase{
4762 testType: serverTest,
4763 name: "RejectFinalTLS13",
4764 config: Config{
4765 Bugs: ProtocolBugs{
4766 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4767 },
4768 },
4769 // We currently implement a draft TLS 1.3 version. Ensure that
4770 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004771 expectedVersion: VersionTLS12,
4772 })
4773
Brian Smithf85d3232016-10-28 10:34:06 -10004774 // Test that the maximum version is selected regardless of the
4775 // client-sent order.
4776 testCases = append(testCases, testCase{
4777 testType: serverTest,
4778 name: "IgnoreClientVersionOrder",
4779 config: Config{
4780 Bugs: ProtocolBugs{
4781 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4782 },
4783 },
4784 expectedVersion: VersionTLS13,
4785 })
4786
David Benjamin95c69562016-06-29 18:15:03 -04004787 // Test for version tolerance.
4788 testCases = append(testCases, testCase{
4789 testType: serverTest,
4790 name: "MinorVersionTolerance",
4791 config: Config{
4792 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004793 SendClientVersion: 0x03ff,
4794 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004795 },
4796 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004797 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004798 })
4799 testCases = append(testCases, testCase{
4800 testType: serverTest,
4801 name: "MajorVersionTolerance",
4802 config: Config{
4803 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004804 SendClientVersion: 0x0400,
4805 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004806 },
4807 },
David Benjaminad75a662016-09-30 15:42:59 -04004808 // TLS 1.3 must be negotiated with the supported_versions
4809 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004810 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004811 })
David Benjaminad75a662016-09-30 15:42:59 -04004812 testCases = append(testCases, testCase{
4813 testType: serverTest,
4814 name: "VersionTolerance-TLS13",
4815 config: Config{
4816 Bugs: ProtocolBugs{
4817 // Although TLS 1.3 does not use
4818 // ClientHello.version, it still tolerates high
4819 // values there.
4820 SendClientVersion: 0x0400,
4821 },
4822 },
4823 expectedVersion: VersionTLS13,
4824 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004825
David Benjamin95c69562016-06-29 18:15:03 -04004826 testCases = append(testCases, testCase{
4827 protocol: dtls,
4828 testType: serverTest,
4829 name: "MinorVersionTolerance-DTLS",
4830 config: Config{
4831 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004832 SendClientVersion: 0xfe00,
4833 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004834 },
4835 },
4836 expectedVersion: VersionTLS12,
4837 })
4838 testCases = append(testCases, testCase{
4839 protocol: dtls,
4840 testType: serverTest,
4841 name: "MajorVersionTolerance-DTLS",
4842 config: Config{
4843 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004844 SendClientVersion: 0xfdff,
4845 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004846 },
4847 },
4848 expectedVersion: VersionTLS12,
4849 })
4850
4851 // Test that versions below 3.0 are rejected.
4852 testCases = append(testCases, testCase{
4853 testType: serverTest,
4854 name: "VersionTooLow",
4855 config: Config{
4856 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004857 SendClientVersion: 0x0200,
4858 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004859 },
4860 },
4861 shouldFail: true,
4862 expectedError: ":UNSUPPORTED_PROTOCOL:",
4863 })
4864 testCases = append(testCases, testCase{
4865 protocol: dtls,
4866 testType: serverTest,
4867 name: "VersionTooLow-DTLS",
4868 config: Config{
4869 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004870 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004871 },
4872 },
4873 shouldFail: true,
4874 expectedError: ":UNSUPPORTED_PROTOCOL:",
4875 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004876
David Benjamin2dc02042016-09-19 19:57:37 -04004877 testCases = append(testCases, testCase{
4878 name: "ServerBogusVersion",
4879 config: Config{
4880 Bugs: ProtocolBugs{
4881 SendServerHelloVersion: 0x1234,
4882 },
4883 },
4884 shouldFail: true,
4885 expectedError: ":UNSUPPORTED_PROTOCOL:",
4886 })
4887
David Benjamin1f61f0d2016-07-10 12:20:35 -04004888 // Test TLS 1.3's downgrade signal.
4889 testCases = append(testCases, testCase{
4890 name: "Downgrade-TLS12-Client",
4891 config: Config{
4892 Bugs: ProtocolBugs{
4893 NegotiateVersion: VersionTLS12,
4894 },
4895 },
David Benjamin592b5322016-09-30 15:15:01 -04004896 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004897 // TODO(davidben): This test should fail once TLS 1.3 is final
4898 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004899 })
4900 testCases = append(testCases, testCase{
4901 testType: serverTest,
4902 name: "Downgrade-TLS12-Server",
4903 config: Config{
4904 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004905 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004906 },
4907 },
David Benjamin592b5322016-09-30 15:15:01 -04004908 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004909 // TODO(davidben): This test should fail once TLS 1.3 is final
4910 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004911 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004912}
4913
David Benjaminaccb4542014-12-12 23:44:33 -05004914func addMinimumVersionTests() {
4915 for i, shimVers := range tlsVersions {
4916 // Assemble flags to disable all older versions on the shim.
4917 var flags []string
4918 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04004919 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05004920 }
4921
4922 for _, runnerVers := range tlsVersions {
4923 protocols := []protocol{tls}
4924 if runnerVers.hasDTLS && shimVers.hasDTLS {
4925 protocols = append(protocols, dtls)
4926 }
4927 for _, protocol := range protocols {
4928 suffix := shimVers.name + "-" + runnerVers.name
4929 if protocol == dtls {
4930 suffix += "-DTLS"
4931 }
David Benjaminaccb4542014-12-12 23:44:33 -05004932
David Benjaminaccb4542014-12-12 23:44:33 -05004933 var expectedVersion uint16
4934 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004935 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004936 if runnerVers.version >= shimVers.version {
4937 expectedVersion = runnerVers.version
4938 } else {
4939 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004940 expectedError = ":UNSUPPORTED_PROTOCOL:"
4941 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004942 }
4943
4944 testCases = append(testCases, testCase{
4945 protocol: protocol,
4946 testType: clientTest,
4947 name: "MinimumVersion-Client-" + suffix,
4948 config: Config{
4949 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004950 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004951 // Ensure the server does not decline to
4952 // select a version (versions extension) or
4953 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04004954 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04004955 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004956 },
David Benjaminaccb4542014-12-12 23:44:33 -05004957 },
David Benjamin87909c02014-12-13 01:55:01 -05004958 flags: flags,
4959 expectedVersion: expectedVersion,
4960 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004961 expectedError: expectedError,
4962 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004963 })
4964 testCases = append(testCases, testCase{
4965 protocol: protocol,
4966 testType: clientTest,
4967 name: "MinimumVersion-Client2-" + suffix,
4968 config: Config{
4969 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004970 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004971 // Ensure the server does not decline to
4972 // select a version (versions extension) or
4973 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04004974 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04004975 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004976 },
David Benjaminaccb4542014-12-12 23:44:33 -05004977 },
David Benjamin353577c2017-06-29 15:54:58 -04004978 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05004979 expectedVersion: expectedVersion,
4980 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004981 expectedError: expectedError,
4982 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004983 })
4984
4985 testCases = append(testCases, testCase{
4986 protocol: protocol,
4987 testType: serverTest,
4988 name: "MinimumVersion-Server-" + suffix,
4989 config: Config{
4990 MaxVersion: runnerVers.version,
4991 },
David Benjamin87909c02014-12-13 01:55:01 -05004992 flags: flags,
4993 expectedVersion: expectedVersion,
4994 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004995 expectedError: expectedError,
4996 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004997 })
4998 testCases = append(testCases, testCase{
4999 protocol: protocol,
5000 testType: serverTest,
5001 name: "MinimumVersion-Server2-" + suffix,
5002 config: Config{
5003 MaxVersion: runnerVers.version,
5004 },
David Benjamin353577c2017-06-29 15:54:58 -04005005 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005006 expectedVersion: expectedVersion,
5007 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005008 expectedError: expectedError,
5009 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005010 })
5011 }
5012 }
5013 }
5014}
5015
David Benjamine78bfde2014-09-06 12:45:15 -04005016func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005017 // TODO(davidben): Extensions, where applicable, all move their server
5018 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5019 // tests for both. Also test interaction with 0-RTT when implemented.
5020
David Benjamin97d17d92016-07-14 16:12:00 -04005021 // Repeat extensions tests all versions except SSL 3.0.
5022 for _, ver := range tlsVersions {
5023 if ver.version == VersionSSL30 {
5024 continue
5025 }
5026
David Benjamin97d17d92016-07-14 16:12:00 -04005027 // Test that duplicate extensions are rejected.
5028 testCases = append(testCases, testCase{
5029 testType: clientTest,
5030 name: "DuplicateExtensionClient-" + ver.name,
5031 config: Config{
5032 MaxVersion: ver.version,
5033 Bugs: ProtocolBugs{
5034 DuplicateExtension: true,
5035 },
David Benjamine78bfde2014-09-06 12:45:15 -04005036 },
David Benjamin97d17d92016-07-14 16:12:00 -04005037 shouldFail: true,
5038 expectedLocalError: "remote error: error decoding message",
5039 })
5040 testCases = append(testCases, testCase{
5041 testType: serverTest,
5042 name: "DuplicateExtensionServer-" + ver.name,
5043 config: Config{
5044 MaxVersion: ver.version,
5045 Bugs: ProtocolBugs{
5046 DuplicateExtension: true,
5047 },
David Benjamine78bfde2014-09-06 12:45:15 -04005048 },
David Benjamin97d17d92016-07-14 16:12:00 -04005049 shouldFail: true,
5050 expectedLocalError: "remote error: error decoding message",
5051 })
5052
5053 // Test SNI.
5054 testCases = append(testCases, testCase{
5055 testType: clientTest,
5056 name: "ServerNameExtensionClient-" + ver.name,
5057 config: Config{
5058 MaxVersion: ver.version,
5059 Bugs: ProtocolBugs{
5060 ExpectServerName: "example.com",
5061 },
David Benjamine78bfde2014-09-06 12:45:15 -04005062 },
David Benjamin97d17d92016-07-14 16:12:00 -04005063 flags: []string{"-host-name", "example.com"},
5064 })
5065 testCases = append(testCases, testCase{
5066 testType: clientTest,
5067 name: "ServerNameExtensionClientMismatch-" + ver.name,
5068 config: Config{
5069 MaxVersion: ver.version,
5070 Bugs: ProtocolBugs{
5071 ExpectServerName: "mismatch.com",
5072 },
David Benjamine78bfde2014-09-06 12:45:15 -04005073 },
David Benjamin97d17d92016-07-14 16:12:00 -04005074 flags: []string{"-host-name", "example.com"},
5075 shouldFail: true,
5076 expectedLocalError: "tls: unexpected server name",
5077 })
5078 testCases = append(testCases, testCase{
5079 testType: clientTest,
5080 name: "ServerNameExtensionClientMissing-" + ver.name,
5081 config: Config{
5082 MaxVersion: ver.version,
5083 Bugs: ProtocolBugs{
5084 ExpectServerName: "missing.com",
5085 },
David Benjamine78bfde2014-09-06 12:45:15 -04005086 },
David Benjamin97d17d92016-07-14 16:12:00 -04005087 shouldFail: true,
5088 expectedLocalError: "tls: unexpected server name",
5089 })
5090 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005091 testType: clientTest,
5092 name: "TolerateServerNameAck-" + ver.name,
5093 config: Config{
5094 MaxVersion: ver.version,
5095 Bugs: ProtocolBugs{
5096 SendServerNameAck: true,
5097 },
5098 },
5099 flags: []string{"-host-name", "example.com"},
5100 resumeSession: true,
5101 })
5102 testCases = append(testCases, testCase{
5103 testType: clientTest,
5104 name: "UnsolicitedServerNameAck-" + ver.name,
5105 config: Config{
5106 MaxVersion: ver.version,
5107 Bugs: ProtocolBugs{
5108 SendServerNameAck: true,
5109 },
5110 },
5111 shouldFail: true,
5112 expectedError: ":UNEXPECTED_EXTENSION:",
5113 expectedLocalError: "remote error: unsupported extension",
5114 })
5115 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005116 testType: serverTest,
5117 name: "ServerNameExtensionServer-" + ver.name,
5118 config: Config{
5119 MaxVersion: ver.version,
5120 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005121 },
David Benjamin97d17d92016-07-14 16:12:00 -04005122 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005123 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005124 })
5125
5126 // Test ALPN.
5127 testCases = append(testCases, testCase{
5128 testType: clientTest,
5129 name: "ALPNClient-" + ver.name,
5130 config: Config{
5131 MaxVersion: ver.version,
5132 NextProtos: []string{"foo"},
5133 },
5134 flags: []string{
5135 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5136 "-expect-alpn", "foo",
5137 },
5138 expectedNextProto: "foo",
5139 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005140 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005141 })
5142 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005143 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005144 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005145 config: Config{
5146 MaxVersion: ver.version,
5147 Bugs: ProtocolBugs{
5148 SendALPN: "baz",
5149 },
5150 },
5151 flags: []string{
5152 "-advertise-alpn", "\x03foo\x03bar",
5153 },
5154 shouldFail: true,
5155 expectedError: ":INVALID_ALPN_PROTOCOL:",
5156 expectedLocalError: "remote error: illegal parameter",
5157 })
5158 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005159 testType: clientTest,
5160 name: "ALPNClient-AllowUnknown-" + ver.name,
5161 config: Config{
5162 MaxVersion: ver.version,
5163 Bugs: ProtocolBugs{
5164 SendALPN: "baz",
5165 },
5166 },
5167 flags: []string{
5168 "-advertise-alpn", "\x03foo\x03bar",
5169 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005170 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005171 },
5172 })
5173 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005174 testType: serverTest,
5175 name: "ALPNServer-" + ver.name,
5176 config: Config{
5177 MaxVersion: ver.version,
5178 NextProtos: []string{"foo", "bar", "baz"},
5179 },
5180 flags: []string{
5181 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5182 "-select-alpn", "foo",
5183 },
5184 expectedNextProto: "foo",
5185 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005186 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005187 })
5188 testCases = append(testCases, testCase{
5189 testType: serverTest,
5190 name: "ALPNServer-Decline-" + ver.name,
5191 config: Config{
5192 MaxVersion: ver.version,
5193 NextProtos: []string{"foo", "bar", "baz"},
5194 },
5195 flags: []string{"-decline-alpn"},
5196 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005197 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005198 })
5199
David Benjamin25fe85b2016-08-09 20:00:32 -04005200 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5201 // called once.
5202 testCases = append(testCases, testCase{
5203 testType: serverTest,
5204 name: "ALPNServer-Async-" + ver.name,
5205 config: Config{
5206 MaxVersion: ver.version,
5207 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005208 // Prior to TLS 1.3, exercise the asynchronous session callback.
5209 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005210 },
5211 flags: []string{
5212 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5213 "-select-alpn", "foo",
5214 "-async",
5215 },
5216 expectedNextProto: "foo",
5217 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005218 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005219 })
5220
David Benjamin97d17d92016-07-14 16:12:00 -04005221 var emptyString string
5222 testCases = append(testCases, testCase{
5223 testType: clientTest,
5224 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5225 config: Config{
5226 MaxVersion: ver.version,
5227 NextProtos: []string{""},
5228 Bugs: ProtocolBugs{
5229 // A server returning an empty ALPN protocol
5230 // should be rejected.
5231 ALPNProtocol: &emptyString,
5232 },
5233 },
5234 flags: []string{
5235 "-advertise-alpn", "\x03foo",
5236 },
5237 shouldFail: true,
5238 expectedError: ":PARSE_TLSEXT:",
5239 })
5240 testCases = append(testCases, testCase{
5241 testType: serverTest,
5242 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5243 config: Config{
5244 MaxVersion: ver.version,
5245 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005246 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005247 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005248 },
David Benjamin97d17d92016-07-14 16:12:00 -04005249 flags: []string{
5250 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005251 },
David Benjamin97d17d92016-07-14 16:12:00 -04005252 shouldFail: true,
5253 expectedError: ":PARSE_TLSEXT:",
5254 })
5255
5256 // Test NPN and the interaction with ALPN.
5257 if ver.version < VersionTLS13 {
5258 // Test that the server prefers ALPN over NPN.
5259 testCases = append(testCases, testCase{
5260 testType: serverTest,
5261 name: "ALPNServer-Preferred-" + ver.name,
5262 config: Config{
5263 MaxVersion: ver.version,
5264 NextProtos: []string{"foo", "bar", "baz"},
5265 },
5266 flags: []string{
5267 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5268 "-select-alpn", "foo",
5269 "-advertise-npn", "\x03foo\x03bar\x03baz",
5270 },
5271 expectedNextProto: "foo",
5272 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005273 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005274 })
5275 testCases = append(testCases, testCase{
5276 testType: serverTest,
5277 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5278 config: Config{
5279 MaxVersion: ver.version,
5280 NextProtos: []string{"foo", "bar", "baz"},
5281 Bugs: ProtocolBugs{
5282 SwapNPNAndALPN: true,
5283 },
5284 },
5285 flags: []string{
5286 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5287 "-select-alpn", "foo",
5288 "-advertise-npn", "\x03foo\x03bar\x03baz",
5289 },
5290 expectedNextProto: "foo",
5291 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005292 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005293 })
5294
5295 // Test that negotiating both NPN and ALPN is forbidden.
5296 testCases = append(testCases, testCase{
5297 name: "NegotiateALPNAndNPN-" + ver.name,
5298 config: Config{
5299 MaxVersion: ver.version,
5300 NextProtos: []string{"foo", "bar", "baz"},
5301 Bugs: ProtocolBugs{
5302 NegotiateALPNAndNPN: true,
5303 },
5304 },
5305 flags: []string{
5306 "-advertise-alpn", "\x03foo",
5307 "-select-next-proto", "foo",
5308 },
5309 shouldFail: true,
5310 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5311 })
5312 testCases = append(testCases, testCase{
5313 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5314 config: Config{
5315 MaxVersion: ver.version,
5316 NextProtos: []string{"foo", "bar", "baz"},
5317 Bugs: ProtocolBugs{
5318 NegotiateALPNAndNPN: true,
5319 SwapNPNAndALPN: true,
5320 },
5321 },
5322 flags: []string{
5323 "-advertise-alpn", "\x03foo",
5324 "-select-next-proto", "foo",
5325 },
5326 shouldFail: true,
5327 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5328 })
David Benjamin97d17d92016-07-14 16:12:00 -04005329 }
5330
5331 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005332
5333 // Resume with a corrupt ticket.
5334 testCases = append(testCases, testCase{
5335 testType: serverTest,
5336 name: "CorruptTicket-" + ver.name,
5337 config: Config{
5338 MaxVersion: ver.version,
5339 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005340 FilterTicket: func(in []byte) ([]byte, error) {
5341 in[len(in)-1] ^= 1
5342 return in, nil
5343 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005344 },
5345 },
5346 resumeSession: true,
5347 expectResumeRejected: true,
5348 })
5349 // Test the ticket callback, with and without renewal.
5350 testCases = append(testCases, testCase{
5351 testType: serverTest,
5352 name: "TicketCallback-" + ver.name,
5353 config: Config{
5354 MaxVersion: ver.version,
5355 },
5356 resumeSession: true,
5357 flags: []string{"-use-ticket-callback"},
5358 })
5359 testCases = append(testCases, testCase{
5360 testType: serverTest,
5361 name: "TicketCallback-Renew-" + ver.name,
5362 config: Config{
5363 MaxVersion: ver.version,
5364 Bugs: ProtocolBugs{
5365 ExpectNewTicket: true,
5366 },
5367 },
5368 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5369 resumeSession: true,
5370 })
5371
5372 // Test that the ticket callback is only called once when everything before
5373 // it in the ClientHello is asynchronous. This corrupts the ticket so
5374 // certificate selection callbacks run.
5375 testCases = append(testCases, testCase{
5376 testType: serverTest,
5377 name: "TicketCallback-SingleCall-" + ver.name,
5378 config: Config{
5379 MaxVersion: ver.version,
5380 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005381 FilterTicket: func(in []byte) ([]byte, error) {
5382 in[len(in)-1] ^= 1
5383 return in, nil
5384 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005385 },
5386 },
5387 resumeSession: true,
5388 expectResumeRejected: true,
5389 flags: []string{
5390 "-use-ticket-callback",
5391 "-async",
5392 },
5393 })
5394
David Benjamind4c349b2017-02-09 14:07:17 -05005395 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005396 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005397 testCases = append(testCases, testCase{
5398 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005399 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005400 config: Config{
5401 MaxVersion: ver.version,
5402 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005403 EmptyTicketSessionID: true,
5404 },
5405 },
5406 resumeSession: true,
5407 })
5408 testCases = append(testCases, testCase{
5409 testType: serverTest,
5410 name: "TicketSessionIDLength-16-" + ver.name,
5411 config: Config{
5412 MaxVersion: ver.version,
5413 Bugs: ProtocolBugs{
5414 TicketSessionIDLength: 16,
5415 },
5416 },
5417 resumeSession: true,
5418 })
5419 testCases = append(testCases, testCase{
5420 testType: serverTest,
5421 name: "TicketSessionIDLength-32-" + ver.name,
5422 config: Config{
5423 MaxVersion: ver.version,
5424 Bugs: ProtocolBugs{
5425 TicketSessionIDLength: 32,
5426 },
5427 },
5428 resumeSession: true,
5429 })
5430 testCases = append(testCases, testCase{
5431 testType: serverTest,
5432 name: "TicketSessionIDLength-33-" + ver.name,
5433 config: Config{
5434 MaxVersion: ver.version,
5435 Bugs: ProtocolBugs{
5436 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005437 },
5438 },
5439 resumeSession: true,
5440 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005441 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005442 expectedError: ":DECODE_ERROR:",
5443 })
5444 }
5445
5446 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5447 // are ignored.
5448 if ver.hasDTLS {
5449 testCases = append(testCases, testCase{
5450 protocol: dtls,
5451 name: "SRTP-Client-" + ver.name,
5452 config: Config{
5453 MaxVersion: ver.version,
5454 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5455 },
5456 flags: []string{
5457 "-srtp-profiles",
5458 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5459 },
5460 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5461 })
5462 testCases = append(testCases, testCase{
5463 protocol: dtls,
5464 testType: serverTest,
5465 name: "SRTP-Server-" + ver.name,
5466 config: Config{
5467 MaxVersion: ver.version,
5468 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5469 },
5470 flags: []string{
5471 "-srtp-profiles",
5472 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5473 },
5474 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5475 })
5476 // Test that the MKI is ignored.
5477 testCases = append(testCases, testCase{
5478 protocol: dtls,
5479 testType: serverTest,
5480 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5481 config: Config{
5482 MaxVersion: ver.version,
5483 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5484 Bugs: ProtocolBugs{
5485 SRTPMasterKeyIdentifer: "bogus",
5486 },
5487 },
5488 flags: []string{
5489 "-srtp-profiles",
5490 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5491 },
5492 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5493 })
5494 // Test that SRTP isn't negotiated on the server if there were
5495 // no matching profiles.
5496 testCases = append(testCases, testCase{
5497 protocol: dtls,
5498 testType: serverTest,
5499 name: "SRTP-Server-NoMatch-" + ver.name,
5500 config: Config{
5501 MaxVersion: ver.version,
5502 SRTPProtectionProfiles: []uint16{100, 101, 102},
5503 },
5504 flags: []string{
5505 "-srtp-profiles",
5506 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5507 },
5508 expectedSRTPProtectionProfile: 0,
5509 })
5510 // Test that the server returning an invalid SRTP profile is
5511 // flagged as an error by the client.
5512 testCases = append(testCases, testCase{
5513 protocol: dtls,
5514 name: "SRTP-Client-NoMatch-" + ver.name,
5515 config: Config{
5516 MaxVersion: ver.version,
5517 Bugs: ProtocolBugs{
5518 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5519 },
5520 },
5521 flags: []string{
5522 "-srtp-profiles",
5523 "SRTP_AES128_CM_SHA1_80",
5524 },
5525 shouldFail: true,
5526 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5527 })
5528 }
5529
5530 // Test SCT list.
5531 testCases = append(testCases, testCase{
5532 name: "SignedCertificateTimestampList-Client-" + ver.name,
5533 testType: clientTest,
5534 config: Config{
5535 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005536 },
David Benjamin97d17d92016-07-14 16:12:00 -04005537 flags: []string{
5538 "-enable-signed-cert-timestamps",
5539 "-expect-signed-cert-timestamps",
5540 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005541 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005542 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005543 })
David Benjamindaa88502016-10-04 16:32:16 -04005544
Adam Langleycfa08c32016-11-17 13:21:27 -08005545 var differentSCTList []byte
5546 differentSCTList = append(differentSCTList, testSCTList...)
5547 differentSCTList[len(differentSCTList)-1] ^= 1
5548
David Benjamindaa88502016-10-04 16:32:16 -04005549 // The SCT extension did not specify that it must only be sent on resumption as it
5550 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005551 testCases = append(testCases, testCase{
5552 name: "SendSCTListOnResume-" + ver.name,
5553 config: Config{
5554 MaxVersion: ver.version,
5555 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005556 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005557 },
David Benjamind98452d2015-06-16 14:16:23 -04005558 },
David Benjamin97d17d92016-07-14 16:12:00 -04005559 flags: []string{
5560 "-enable-signed-cert-timestamps",
5561 "-expect-signed-cert-timestamps",
5562 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005563 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005564 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005565 })
David Benjamindaa88502016-10-04 16:32:16 -04005566
David Benjamin97d17d92016-07-14 16:12:00 -04005567 testCases = append(testCases, testCase{
5568 name: "SignedCertificateTimestampList-Server-" + ver.name,
5569 testType: serverTest,
5570 config: Config{
5571 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005572 },
David Benjamin97d17d92016-07-14 16:12:00 -04005573 flags: []string{
5574 "-signed-cert-timestamps",
5575 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005576 },
David Benjamin97d17d92016-07-14 16:12:00 -04005577 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005578 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005579 })
David Benjamin53210cb2016-11-16 09:01:48 +09005580
Adam Langleycfa08c32016-11-17 13:21:27 -08005581 emptySCTListCert := *testCerts[0].cert
5582 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5583
5584 // Test empty SCT list.
5585 testCases = append(testCases, testCase{
5586 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5587 testType: clientTest,
5588 config: Config{
5589 MaxVersion: ver.version,
5590 Certificates: []Certificate{emptySCTListCert},
5591 },
5592 flags: []string{
5593 "-enable-signed-cert-timestamps",
5594 },
5595 shouldFail: true,
5596 expectedError: ":ERROR_PARSING_EXTENSION:",
5597 })
5598
5599 emptySCTCert := *testCerts[0].cert
5600 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5601
5602 // Test empty SCT in non-empty list.
5603 testCases = append(testCases, testCase{
5604 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5605 testType: clientTest,
5606 config: Config{
5607 MaxVersion: ver.version,
5608 Certificates: []Certificate{emptySCTCert},
5609 },
5610 flags: []string{
5611 "-enable-signed-cert-timestamps",
5612 },
5613 shouldFail: true,
5614 expectedError: ":ERROR_PARSING_EXTENSION:",
5615 })
5616
David Benjamin53210cb2016-11-16 09:01:48 +09005617 // Test that certificate-related extensions are not sent unsolicited.
5618 testCases = append(testCases, testCase{
5619 testType: serverTest,
5620 name: "UnsolicitedCertificateExtensions-" + ver.name,
5621 config: Config{
5622 MaxVersion: ver.version,
5623 Bugs: ProtocolBugs{
5624 NoOCSPStapling: true,
5625 NoSignedCertificateTimestamps: true,
5626 },
5627 },
5628 flags: []string{
5629 "-ocsp-response",
5630 base64.StdEncoding.EncodeToString(testOCSPResponse),
5631 "-signed-cert-timestamps",
5632 base64.StdEncoding.EncodeToString(testSCTList),
5633 },
5634 })
David Benjamin97d17d92016-07-14 16:12:00 -04005635 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005636
Paul Lietar4fac72e2015-09-09 13:44:55 +01005637 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005638 testType: clientTest,
5639 name: "ClientHelloPadding",
5640 config: Config{
5641 Bugs: ProtocolBugs{
5642 RequireClientHelloSize: 512,
5643 },
5644 },
5645 // This hostname just needs to be long enough to push the
5646 // ClientHello into F5's danger zone between 256 and 511 bytes
5647 // long.
5648 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5649 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005650
5651 // Extensions should not function in SSL 3.0.
5652 testCases = append(testCases, testCase{
5653 testType: serverTest,
5654 name: "SSLv3Extensions-NoALPN",
5655 config: Config{
5656 MaxVersion: VersionSSL30,
5657 NextProtos: []string{"foo", "bar", "baz"},
5658 },
5659 flags: []string{
5660 "-select-alpn", "foo",
5661 },
5662 expectNoNextProto: true,
5663 })
5664
5665 // Test session tickets separately as they follow a different codepath.
5666 testCases = append(testCases, testCase{
5667 testType: serverTest,
5668 name: "SSLv3Extensions-NoTickets",
5669 config: Config{
5670 MaxVersion: VersionSSL30,
5671 Bugs: ProtocolBugs{
5672 // Historically, session tickets in SSL 3.0
5673 // failed in different ways depending on whether
5674 // the client supported renegotiation_info.
5675 NoRenegotiationInfo: true,
5676 },
5677 },
5678 resumeSession: true,
5679 })
5680 testCases = append(testCases, testCase{
5681 testType: serverTest,
5682 name: "SSLv3Extensions-NoTickets2",
5683 config: Config{
5684 MaxVersion: VersionSSL30,
5685 },
5686 resumeSession: true,
5687 })
5688
5689 // But SSL 3.0 does send and process renegotiation_info.
5690 testCases = append(testCases, testCase{
5691 testType: serverTest,
5692 name: "SSLv3Extensions-RenegotiationInfo",
5693 config: Config{
5694 MaxVersion: VersionSSL30,
5695 Bugs: ProtocolBugs{
5696 RequireRenegotiationInfo: true,
5697 },
5698 },
David Benjamind2610042017-01-03 10:49:28 -05005699 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005700 })
5701 testCases = append(testCases, testCase{
5702 testType: serverTest,
5703 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5704 config: Config{
5705 MaxVersion: VersionSSL30,
5706 Bugs: ProtocolBugs{
5707 NoRenegotiationInfo: true,
5708 SendRenegotiationSCSV: true,
5709 RequireRenegotiationInfo: true,
5710 },
5711 },
David Benjamind2610042017-01-03 10:49:28 -05005712 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005713 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005714
5715 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5716 // in ServerHello.
5717 testCases = append(testCases, testCase{
5718 name: "NPN-Forbidden-TLS13",
5719 config: Config{
5720 MaxVersion: VersionTLS13,
5721 NextProtos: []string{"foo"},
5722 Bugs: ProtocolBugs{
5723 NegotiateNPNAtAllVersions: true,
5724 },
5725 },
5726 flags: []string{"-select-next-proto", "foo"},
5727 shouldFail: true,
5728 expectedError: ":ERROR_PARSING_EXTENSION:",
5729 })
5730 testCases = append(testCases, testCase{
5731 name: "EMS-Forbidden-TLS13",
5732 config: Config{
5733 MaxVersion: VersionTLS13,
5734 Bugs: ProtocolBugs{
5735 NegotiateEMSAtAllVersions: true,
5736 },
5737 },
5738 shouldFail: true,
5739 expectedError: ":ERROR_PARSING_EXTENSION:",
5740 })
5741 testCases = append(testCases, testCase{
5742 name: "RenegotiationInfo-Forbidden-TLS13",
5743 config: Config{
5744 MaxVersion: VersionTLS13,
5745 Bugs: ProtocolBugs{
5746 NegotiateRenegotiationInfoAtAllVersions: true,
5747 },
5748 },
5749 shouldFail: true,
5750 expectedError: ":ERROR_PARSING_EXTENSION:",
5751 })
5752 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005753 name: "Ticket-Forbidden-TLS13",
5754 config: Config{
5755 MaxVersion: VersionTLS12,
5756 },
5757 resumeConfig: &Config{
5758 MaxVersion: VersionTLS13,
5759 Bugs: ProtocolBugs{
5760 AdvertiseTicketExtension: true,
5761 },
5762 },
5763 resumeSession: true,
5764 shouldFail: true,
5765 expectedError: ":ERROR_PARSING_EXTENSION:",
5766 })
5767
5768 // Test that illegal extensions in TLS 1.3 are declined by the server if
5769 // offered in ClientHello. The runner's server will fail if this occurs,
5770 // so we exercise the offering path. (EMS and Renegotiation Info are
5771 // implicit in every test.)
5772 testCases = append(testCases, testCase{
5773 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005774 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005775 config: Config{
5776 MaxVersion: VersionTLS13,
5777 NextProtos: []string{"bar"},
5778 },
5779 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5780 })
David Benjamin196df5b2016-09-21 16:23:27 -04005781
David Benjamindaa88502016-10-04 16:32:16 -04005782 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5783 // tolerated.
5784 testCases = append(testCases, testCase{
5785 name: "SendOCSPResponseOnResume-TLS12",
5786 config: Config{
5787 MaxVersion: VersionTLS12,
5788 Bugs: ProtocolBugs{
5789 SendOCSPResponseOnResume: []byte("bogus"),
5790 },
5791 },
5792 flags: []string{
5793 "-enable-ocsp-stapling",
5794 "-expect-ocsp-response",
5795 base64.StdEncoding.EncodeToString(testOCSPResponse),
5796 },
5797 resumeSession: true,
5798 })
5799
David Benjamindaa88502016-10-04 16:32:16 -04005800 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005801 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005802 config: Config{
5803 MaxVersion: VersionTLS13,
5804 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005805 SendExtensionOnCertificate: testOCSPExtension,
5806 },
5807 },
5808 shouldFail: true,
5809 expectedError: ":UNEXPECTED_EXTENSION:",
5810 })
5811
5812 testCases = append(testCases, testCase{
5813 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5814 config: Config{
5815 MaxVersion: VersionTLS13,
5816 Bugs: ProtocolBugs{
5817 SendExtensionOnCertificate: testSCTExtension,
5818 },
5819 },
5820 shouldFail: true,
5821 expectedError: ":UNEXPECTED_EXTENSION:",
5822 })
5823
5824 // Test that extensions on client certificates are never accepted.
5825 testCases = append(testCases, testCase{
5826 name: "SendExtensionOnClientCertificate-TLS13",
5827 testType: serverTest,
5828 config: Config{
5829 MaxVersion: VersionTLS13,
5830 Certificates: []Certificate{rsaCertificate},
5831 Bugs: ProtocolBugs{
5832 SendExtensionOnCertificate: testOCSPExtension,
5833 },
5834 },
5835 flags: []string{
5836 "-enable-ocsp-stapling",
5837 "-require-any-client-certificate",
5838 },
5839 shouldFail: true,
5840 expectedError: ":UNEXPECTED_EXTENSION:",
5841 })
5842
5843 testCases = append(testCases, testCase{
5844 name: "SendUnknownExtensionOnCertificate-TLS13",
5845 config: Config{
5846 MaxVersion: VersionTLS13,
5847 Bugs: ProtocolBugs{
5848 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5849 },
5850 },
5851 shouldFail: true,
5852 expectedError: ":UNEXPECTED_EXTENSION:",
5853 })
5854
Adam Langleycfa08c32016-11-17 13:21:27 -08005855 var differentSCTList []byte
5856 differentSCTList = append(differentSCTList, testSCTList...)
5857 differentSCTList[len(differentSCTList)-1] ^= 1
5858
Steven Valdeza833c352016-11-01 13:39:36 -04005859 // Test that extensions on intermediates are allowed but ignored.
5860 testCases = append(testCases, testCase{
5861 name: "IgnoreExtensionsOnIntermediates-TLS13",
5862 config: Config{
5863 MaxVersion: VersionTLS13,
5864 Certificates: []Certificate{rsaChainCertificate},
5865 Bugs: ProtocolBugs{
5866 // Send different values on the intermediate. This tests
5867 // the intermediate's extensions do not override the
5868 // leaf's.
5869 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005870 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005871 },
5872 },
5873 flags: []string{
5874 "-enable-ocsp-stapling",
5875 "-expect-ocsp-response",
5876 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005877 "-enable-signed-cert-timestamps",
5878 "-expect-signed-cert-timestamps",
5879 base64.StdEncoding.EncodeToString(testSCTList),
5880 },
5881 resumeSession: true,
5882 })
5883
5884 // Test that extensions are not sent on intermediates when configured
5885 // only for a leaf.
5886 testCases = append(testCases, testCase{
5887 testType: serverTest,
5888 name: "SendNoExtensionsOnIntermediate-TLS13",
5889 config: Config{
5890 MaxVersion: VersionTLS13,
5891 Bugs: ProtocolBugs{
5892 ExpectNoExtensionsOnIntermediate: true,
5893 },
5894 },
5895 flags: []string{
5896 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5897 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5898 "-ocsp-response",
5899 base64.StdEncoding.EncodeToString(testOCSPResponse),
5900 "-signed-cert-timestamps",
5901 base64.StdEncoding.EncodeToString(testSCTList),
5902 },
5903 })
5904
5905 // Test that extensions are not sent on client certificates.
5906 testCases = append(testCases, testCase{
5907 name: "SendNoClientCertificateExtensions-TLS13",
5908 config: Config{
5909 MaxVersion: VersionTLS13,
5910 ClientAuth: RequireAnyClientCert,
5911 },
5912 flags: []string{
5913 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5914 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5915 "-ocsp-response",
5916 base64.StdEncoding.EncodeToString(testOCSPResponse),
5917 "-signed-cert-timestamps",
5918 base64.StdEncoding.EncodeToString(testSCTList),
5919 },
5920 })
5921
5922 testCases = append(testCases, testCase{
5923 name: "SendDuplicateExtensionsOnCerts-TLS13",
5924 config: Config{
5925 MaxVersion: VersionTLS13,
5926 Bugs: ProtocolBugs{
5927 SendDuplicateCertExtensions: true,
5928 },
5929 },
5930 flags: []string{
5931 "-enable-ocsp-stapling",
5932 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005933 },
5934 resumeSession: true,
5935 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005936 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005937 })
Adam Langley9b885c52016-11-18 14:21:03 -08005938
5939 testCases = append(testCases, testCase{
5940 name: "SignedCertificateTimestampListInvalid-Server",
5941 testType: serverTest,
5942 flags: []string{
5943 "-signed-cert-timestamps",
5944 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5945 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005946 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005947 expectedError: ":INVALID_SCT_LIST:",
5948 })
David Benjamine78bfde2014-09-06 12:45:15 -04005949}
5950
David Benjamin01fe8202014-09-24 15:21:44 -04005951func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005952 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005953 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005954 // SSL 3.0 does not have tickets and TLS 1.3 does not
5955 // have session IDs, so skip their cross-resumption
5956 // tests.
5957 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5958 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5959 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005960 }
5961
David Benjamin8b8c0062014-11-23 02:47:52 -05005962 protocols := []protocol{tls}
5963 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5964 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005965 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005966 for _, protocol := range protocols {
5967 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5968 if protocol == dtls {
5969 suffix += "-DTLS"
5970 }
5971
David Benjaminece3de92015-03-16 18:02:20 -04005972 if sessionVers.version == resumeVers.version {
5973 testCases = append(testCases, testCase{
5974 protocol: protocol,
5975 name: "Resume-Client" + suffix,
5976 resumeSession: true,
5977 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005978 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005979 Bugs: ProtocolBugs{
5980 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5981 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5982 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005983 },
David Benjaminece3de92015-03-16 18:02:20 -04005984 expectedVersion: sessionVers.version,
5985 expectedResumeVersion: resumeVers.version,
5986 })
5987 } else {
David Benjamin405da482016-08-08 17:25:07 -04005988 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5989
5990 // Offering a TLS 1.3 session sends an empty session ID, so
5991 // there is no way to convince a non-lookahead client the
5992 // session was resumed. It will appear to the client that a
5993 // stray ChangeCipherSpec was sent.
5994 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5995 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005996 }
5997
David Benjaminece3de92015-03-16 18:02:20 -04005998 testCases = append(testCases, testCase{
5999 protocol: protocol,
6000 name: "Resume-Client-Mismatch" + suffix,
6001 resumeSession: true,
6002 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006003 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006004 },
David Benjaminece3de92015-03-16 18:02:20 -04006005 expectedVersion: sessionVers.version,
6006 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006007 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006008 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006009 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006010 },
6011 },
6012 expectedResumeVersion: resumeVers.version,
6013 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006014 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006015 })
6016 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006017
6018 testCases = append(testCases, testCase{
6019 protocol: protocol,
6020 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006021 resumeSession: true,
6022 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006023 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006024 },
6025 expectedVersion: sessionVers.version,
6026 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006027 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006028 },
6029 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006030 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006031 expectedResumeVersion: resumeVers.version,
6032 })
6033
David Benjamin8b8c0062014-11-23 02:47:52 -05006034 testCases = append(testCases, testCase{
6035 protocol: protocol,
6036 testType: serverTest,
6037 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006038 resumeSession: true,
6039 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006040 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006041 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006042 expectedVersion: sessionVers.version,
6043 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006044 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006045 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006046 Bugs: ProtocolBugs{
6047 SendBothTickets: true,
6048 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006049 },
6050 expectedResumeVersion: resumeVers.version,
6051 })
6052 }
David Benjamin01fe8202014-09-24 15:21:44 -04006053 }
6054 }
David Benjaminece3de92015-03-16 18:02:20 -04006055
David Benjamin4199b0d2016-11-01 13:58:25 -04006056 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006057 testCases = append(testCases, testCase{
6058 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006059 name: "ShimTicketRewritable",
6060 resumeSession: true,
6061 config: Config{
6062 MaxVersion: VersionTLS12,
6063 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6064 Bugs: ProtocolBugs{
6065 FilterTicket: func(in []byte) ([]byte, error) {
6066 in, err := SetShimTicketVersion(in, VersionTLS12)
6067 if err != nil {
6068 return nil, err
6069 }
6070 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6071 },
6072 },
6073 },
6074 flags: []string{
6075 "-ticket-key",
6076 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6077 },
6078 })
6079
6080 // Resumptions are declined if the version does not match.
6081 testCases = append(testCases, testCase{
6082 testType: serverTest,
6083 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006084 resumeSession: true,
6085 config: Config{
6086 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006087 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006088 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006089 FilterTicket: func(in []byte) ([]byte, error) {
6090 return SetShimTicketVersion(in, VersionTLS13)
6091 },
6092 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006093 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006094 flags: []string{
6095 "-ticket-key",
6096 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6097 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006098 expectResumeRejected: true,
6099 })
6100
6101 testCases = append(testCases, testCase{
6102 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006103 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006104 resumeSession: true,
6105 config: Config{
6106 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006107 Bugs: ProtocolBugs{
6108 FilterTicket: func(in []byte) ([]byte, error) {
6109 return SetShimTicketVersion(in, VersionTLS12)
6110 },
6111 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006112 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006113 flags: []string{
6114 "-ticket-key",
6115 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6116 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006117 expectResumeRejected: true,
6118 })
6119
David Benjamin4199b0d2016-11-01 13:58:25 -04006120 // Resumptions are declined if the cipher is invalid or disabled.
6121 testCases = append(testCases, testCase{
6122 testType: serverTest,
6123 name: "Resume-Server-DeclineBadCipher",
6124 resumeSession: true,
6125 config: Config{
6126 MaxVersion: VersionTLS12,
6127 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006128 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006129 FilterTicket: func(in []byte) ([]byte, error) {
6130 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6131 },
6132 },
6133 },
6134 flags: []string{
6135 "-ticket-key",
6136 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6137 },
6138 expectResumeRejected: true,
6139 })
6140
6141 testCases = append(testCases, testCase{
6142 testType: serverTest,
6143 name: "Resume-Server-DeclineBadCipher-2",
6144 resumeSession: true,
6145 config: Config{
6146 MaxVersion: VersionTLS12,
6147 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006148 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006149 FilterTicket: func(in []byte) ([]byte, error) {
6150 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6151 },
6152 },
6153 },
6154 flags: []string{
6155 "-cipher", "AES128",
6156 "-ticket-key",
6157 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6158 },
6159 expectResumeRejected: true,
6160 })
6161
David Benjaminf01f42a2016-11-16 19:05:33 +09006162 // Sessions are not resumed if they do not use the preferred cipher.
6163 testCases = append(testCases, testCase{
6164 testType: serverTest,
6165 name: "Resume-Server-CipherNotPreferred",
6166 resumeSession: true,
6167 config: Config{
6168 MaxVersion: VersionTLS12,
6169 Bugs: ProtocolBugs{
6170 ExpectNewTicket: true,
6171 FilterTicket: func(in []byte) ([]byte, error) {
6172 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6173 },
6174 },
6175 },
6176 flags: []string{
6177 "-ticket-key",
6178 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6179 },
6180 shouldFail: false,
6181 expectResumeRejected: true,
6182 })
6183
6184 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6185 // PRF hashes match, but BoringSSL will always decline such resumptions.
6186 testCases = append(testCases, testCase{
6187 testType: serverTest,
6188 name: "Resume-Server-CipherNotPreferred-TLS13",
6189 resumeSession: true,
6190 config: Config{
6191 MaxVersion: VersionTLS13,
6192 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6193 Bugs: ProtocolBugs{
6194 FilterTicket: func(in []byte) ([]byte, error) {
6195 // If the client (runner) offers ChaCha20-Poly1305 first, the
6196 // server (shim) always prefers it. Switch it to AES-GCM.
6197 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6198 },
6199 },
6200 },
6201 flags: []string{
6202 "-ticket-key",
6203 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6204 },
6205 shouldFail: false,
6206 expectResumeRejected: true,
6207 })
6208
6209 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006210 testCases = append(testCases, testCase{
6211 testType: serverTest,
6212 name: "Resume-Server-DeclineBadCipher-TLS13",
6213 resumeSession: true,
6214 config: Config{
6215 MaxVersion: VersionTLS13,
6216 Bugs: ProtocolBugs{
6217 FilterTicket: func(in []byte) ([]byte, error) {
6218 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6219 },
6220 },
6221 },
6222 flags: []string{
6223 "-ticket-key",
6224 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6225 },
6226 expectResumeRejected: true,
6227 })
6228
David Benjaminf01f42a2016-11-16 19:05:33 +09006229 // If the client does not offer the cipher from the session, decline to
6230 // resume. Clients are forbidden from doing this, but BoringSSL selects
6231 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006232 testCases = append(testCases, testCase{
6233 testType: serverTest,
6234 name: "Resume-Server-UnofferedCipher",
6235 resumeSession: true,
6236 config: Config{
6237 MaxVersion: VersionTLS12,
6238 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6239 },
6240 resumeConfig: &Config{
6241 MaxVersion: VersionTLS12,
6242 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6243 Bugs: ProtocolBugs{
6244 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6245 },
6246 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006247 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006248 })
6249
David Benjaminf01f42a2016-11-16 19:05:33 +09006250 // In TLS 1.3, clients may advertise a cipher list which does not
6251 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006252 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6253 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006254 testCases = append(testCases, testCase{
6255 testType: serverTest,
6256 name: "Resume-Server-UnofferedCipher-TLS13",
6257 resumeSession: true,
6258 config: Config{
6259 MaxVersion: VersionTLS13,
6260 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6261 },
6262 resumeConfig: &Config{
6263 MaxVersion: VersionTLS13,
6264 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6265 Bugs: ProtocolBugs{
6266 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6267 },
6268 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006269 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006270 })
6271
David Benjamin4199b0d2016-11-01 13:58:25 -04006272 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006273 testCases = append(testCases, testCase{
6274 name: "Resume-Client-CipherMismatch",
6275 resumeSession: true,
6276 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006277 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006278 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6279 },
6280 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006281 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006282 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6283 Bugs: ProtocolBugs{
6284 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6285 },
6286 },
6287 shouldFail: true,
6288 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6289 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006290
David Benjamine1cc35e2016-11-16 16:25:58 +09006291 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6292 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006293 testCases = append(testCases, testCase{
6294 name: "Resume-Client-CipherMismatch-TLS13",
6295 resumeSession: true,
6296 config: Config{
6297 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006298 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006299 },
6300 resumeConfig: &Config{
6301 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006302 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6303 },
6304 })
6305
6306 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6307 testCases = append(testCases, testCase{
6308 name: "Resume-Client-PRFMismatch-TLS13",
6309 resumeSession: true,
6310 config: Config{
6311 MaxVersion: VersionTLS13,
6312 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6313 },
6314 resumeConfig: &Config{
6315 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006316 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006317 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006318 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006319 },
6320 },
6321 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006322 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006323 })
Steven Valdeza833c352016-11-01 13:39:36 -04006324
6325 testCases = append(testCases, testCase{
6326 testType: serverTest,
6327 name: "Resume-Server-BinderWrongLength",
6328 resumeSession: true,
6329 config: Config{
6330 MaxVersion: VersionTLS13,
6331 Bugs: ProtocolBugs{
6332 SendShortPSKBinder: true,
6333 },
6334 },
6335 shouldFail: true,
6336 expectedLocalError: "remote error: error decrypting message",
6337 expectedError: ":DIGEST_CHECK_FAILED:",
6338 })
6339
6340 testCases = append(testCases, testCase{
6341 testType: serverTest,
6342 name: "Resume-Server-NoPSKBinder",
6343 resumeSession: true,
6344 config: Config{
6345 MaxVersion: VersionTLS13,
6346 Bugs: ProtocolBugs{
6347 SendNoPSKBinder: true,
6348 },
6349 },
6350 shouldFail: true,
6351 expectedLocalError: "remote error: error decoding message",
6352 expectedError: ":DECODE_ERROR:",
6353 })
6354
6355 testCases = append(testCases, testCase{
6356 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006357 name: "Resume-Server-ExtraPSKBinder",
6358 resumeSession: true,
6359 config: Config{
6360 MaxVersion: VersionTLS13,
6361 Bugs: ProtocolBugs{
6362 SendExtraPSKBinder: true,
6363 },
6364 },
6365 shouldFail: true,
6366 expectedLocalError: "remote error: illegal parameter",
6367 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6368 })
6369
6370 testCases = append(testCases, testCase{
6371 testType: serverTest,
6372 name: "Resume-Server-ExtraIdentityNoBinder",
6373 resumeSession: true,
6374 config: Config{
6375 MaxVersion: VersionTLS13,
6376 Bugs: ProtocolBugs{
6377 ExtraPSKIdentity: true,
6378 },
6379 },
6380 shouldFail: true,
6381 expectedLocalError: "remote error: illegal parameter",
6382 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6383 })
6384
6385 testCases = append(testCases, testCase{
6386 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006387 name: "Resume-Server-InvalidPSKBinder",
6388 resumeSession: true,
6389 config: Config{
6390 MaxVersion: VersionTLS13,
6391 Bugs: ProtocolBugs{
6392 SendInvalidPSKBinder: true,
6393 },
6394 },
6395 shouldFail: true,
6396 expectedLocalError: "remote error: error decrypting message",
6397 expectedError: ":DIGEST_CHECK_FAILED:",
6398 })
6399
6400 testCases = append(testCases, testCase{
6401 testType: serverTest,
6402 name: "Resume-Server-PSKBinderFirstExtension",
6403 resumeSession: true,
6404 config: Config{
6405 MaxVersion: VersionTLS13,
6406 Bugs: ProtocolBugs{
6407 PSKBinderFirst: true,
6408 },
6409 },
6410 shouldFail: true,
6411 expectedLocalError: "remote error: illegal parameter",
6412 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6413 })
David Benjamin01fe8202014-09-24 15:21:44 -04006414}
6415
Adam Langley2ae77d22014-10-28 17:29:33 -07006416func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006417 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006418 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006419 testType: serverTest,
6420 name: "Renegotiate-Server-Forbidden",
6421 config: Config{
6422 MaxVersion: VersionTLS12,
6423 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006424 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006425 shouldFail: true,
6426 expectedError: ":NO_RENEGOTIATION:",
6427 expectedLocalError: "remote error: no renegotiation",
6428 })
Adam Langley5021b222015-06-12 18:27:58 -07006429 // The server shouldn't echo the renegotiation extension unless
6430 // requested by the client.
6431 testCases = append(testCases, testCase{
6432 testType: serverTest,
6433 name: "Renegotiate-Server-NoExt",
6434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006435 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006436 Bugs: ProtocolBugs{
6437 NoRenegotiationInfo: true,
6438 RequireRenegotiationInfo: true,
6439 },
6440 },
6441 shouldFail: true,
6442 expectedLocalError: "renegotiation extension missing",
6443 })
6444 // The renegotiation SCSV should be sufficient for the server to echo
6445 // the extension.
6446 testCases = append(testCases, testCase{
6447 testType: serverTest,
6448 name: "Renegotiate-Server-NoExt-SCSV",
6449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006450 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006451 Bugs: ProtocolBugs{
6452 NoRenegotiationInfo: true,
6453 SendRenegotiationSCSV: true,
6454 RequireRenegotiationInfo: true,
6455 },
6456 },
6457 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006458 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006459 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006461 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006462 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006463 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006464 },
6465 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006466 renegotiate: 1,
6467 flags: []string{
6468 "-renegotiate-freely",
6469 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006470 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006471 },
David Benjamincdea40c2015-03-19 14:09:43 -04006472 })
6473 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006474 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006475 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006477 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006478 Bugs: ProtocolBugs{
6479 EmptyRenegotiationInfo: true,
6480 },
6481 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006482 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006483 shouldFail: true,
6484 expectedError: ":RENEGOTIATION_MISMATCH:",
6485 })
6486 testCases = append(testCases, testCase{
6487 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006488 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006489 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006490 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006491 Bugs: ProtocolBugs{
6492 BadRenegotiationInfo: true,
6493 },
6494 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006495 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006496 shouldFail: true,
6497 expectedError: ":RENEGOTIATION_MISMATCH:",
6498 })
6499 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006500 name: "Renegotiate-Client-Downgrade",
6501 renegotiate: 1,
6502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006503 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006504 Bugs: ProtocolBugs{
6505 NoRenegotiationInfoAfterInitial: true,
6506 },
6507 },
6508 flags: []string{"-renegotiate-freely"},
6509 shouldFail: true,
6510 expectedError: ":RENEGOTIATION_MISMATCH:",
6511 })
6512 testCases = append(testCases, testCase{
6513 name: "Renegotiate-Client-Upgrade",
6514 renegotiate: 1,
6515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006517 Bugs: ProtocolBugs{
6518 NoRenegotiationInfoInInitial: true,
6519 },
6520 },
6521 flags: []string{"-renegotiate-freely"},
6522 shouldFail: true,
6523 expectedError: ":RENEGOTIATION_MISMATCH:",
6524 })
6525 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006526 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006527 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006529 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006530 Bugs: ProtocolBugs{
6531 NoRenegotiationInfo: true,
6532 },
6533 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006534 flags: []string{
6535 "-renegotiate-freely",
6536 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006537 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006538 },
David Benjamincff0b902015-05-15 23:09:47 -04006539 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006540
6541 // Test that the server may switch ciphers on renegotiation without
6542 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006543 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006544 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006545 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006546 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006547 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006548 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006549 },
6550 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006551 flags: []string{
6552 "-renegotiate-freely",
6553 "-expect-total-renegotiations", "1",
6554 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006555 })
6556 testCases = append(testCases, testCase{
6557 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006558 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006559 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006560 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006561 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6562 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006563 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006564 flags: []string{
6565 "-renegotiate-freely",
6566 "-expect-total-renegotiations", "1",
6567 },
David Benjaminb16346b2015-04-08 19:16:58 -04006568 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006569
6570 // Test that the server may not switch versions on renegotiation.
6571 testCases = append(testCases, testCase{
6572 name: "Renegotiate-Client-SwitchVersion",
6573 config: Config{
6574 MaxVersion: VersionTLS12,
6575 // Pick a cipher which exists at both versions.
6576 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6577 Bugs: ProtocolBugs{
6578 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006579 // Avoid failing early at the record layer.
6580 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006581 },
6582 },
6583 renegotiate: 1,
6584 flags: []string{
6585 "-renegotiate-freely",
6586 "-expect-total-renegotiations", "1",
6587 },
6588 shouldFail: true,
6589 expectedError: ":WRONG_SSL_VERSION:",
6590 })
6591
David Benjaminb16346b2015-04-08 19:16:58 -04006592 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006593 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006594 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006595 config: Config{
6596 MaxVersion: VersionTLS10,
6597 Bugs: ProtocolBugs{
6598 RequireSameRenegoClientVersion: true,
6599 },
6600 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006601 flags: []string{
6602 "-renegotiate-freely",
6603 "-expect-total-renegotiations", "1",
6604 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006605 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006606 testCases = append(testCases, testCase{
6607 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006608 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006609 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006610 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006611 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6612 NextProtos: []string{"foo"},
6613 },
6614 flags: []string{
6615 "-false-start",
6616 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006617 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006618 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006619 },
6620 shimWritesFirst: true,
6621 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006622
6623 // Client-side renegotiation controls.
6624 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006625 name: "Renegotiate-Client-Forbidden-1",
6626 config: Config{
6627 MaxVersion: VersionTLS12,
6628 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006629 renegotiate: 1,
6630 shouldFail: true,
6631 expectedError: ":NO_RENEGOTIATION:",
6632 expectedLocalError: "remote error: no renegotiation",
6633 })
6634 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006635 name: "Renegotiate-Client-Once-1",
6636 config: Config{
6637 MaxVersion: VersionTLS12,
6638 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006639 renegotiate: 1,
6640 flags: []string{
6641 "-renegotiate-once",
6642 "-expect-total-renegotiations", "1",
6643 },
6644 })
6645 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006646 name: "Renegotiate-Client-Freely-1",
6647 config: Config{
6648 MaxVersion: VersionTLS12,
6649 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006650 renegotiate: 1,
6651 flags: []string{
6652 "-renegotiate-freely",
6653 "-expect-total-renegotiations", "1",
6654 },
6655 })
6656 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006657 name: "Renegotiate-Client-Once-2",
6658 config: Config{
6659 MaxVersion: VersionTLS12,
6660 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006661 renegotiate: 2,
6662 flags: []string{"-renegotiate-once"},
6663 shouldFail: true,
6664 expectedError: ":NO_RENEGOTIATION:",
6665 expectedLocalError: "remote error: no renegotiation",
6666 })
6667 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006668 name: "Renegotiate-Client-Freely-2",
6669 config: Config{
6670 MaxVersion: VersionTLS12,
6671 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006672 renegotiate: 2,
6673 flags: []string{
6674 "-renegotiate-freely",
6675 "-expect-total-renegotiations", "2",
6676 },
6677 })
Adam Langley27a0d082015-11-03 13:34:10 -08006678 testCases = append(testCases, testCase{
6679 name: "Renegotiate-Client-NoIgnore",
6680 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006681 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006682 Bugs: ProtocolBugs{
6683 SendHelloRequestBeforeEveryAppDataRecord: true,
6684 },
6685 },
6686 shouldFail: true,
6687 expectedError: ":NO_RENEGOTIATION:",
6688 })
6689 testCases = append(testCases, testCase{
6690 name: "Renegotiate-Client-Ignore",
6691 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006692 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006693 Bugs: ProtocolBugs{
6694 SendHelloRequestBeforeEveryAppDataRecord: true,
6695 },
6696 },
6697 flags: []string{
6698 "-renegotiate-ignore",
6699 "-expect-total-renegotiations", "0",
6700 },
6701 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006702
David Benjamin34941c02016-10-08 11:45:31 -04006703 // Renegotiation is not allowed at SSL 3.0.
6704 testCases = append(testCases, testCase{
6705 name: "Renegotiate-Client-SSL3",
6706 config: Config{
6707 MaxVersion: VersionSSL30,
6708 },
6709 renegotiate: 1,
6710 flags: []string{
6711 "-renegotiate-freely",
6712 "-expect-total-renegotiations", "1",
6713 },
6714 shouldFail: true,
6715 expectedError: ":NO_RENEGOTIATION:",
6716 expectedLocalError: "remote error: no renegotiation",
6717 })
6718
David Benjamina1eaba12017-01-01 23:19:22 -05006719 // Renegotiation is not allowed when there is an unfinished write.
6720 testCases = append(testCases, testCase{
6721 name: "Renegotiate-Client-UnfinishedWrite",
6722 config: Config{
6723 MaxVersion: VersionTLS12,
6724 },
David Benjaminbbba9392017-04-06 12:54:12 -04006725 renegotiate: 1,
6726 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006727 flags: []string{
6728 "-async",
6729 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006730 },
6731 shouldFail: true,
6732 expectedError: ":NO_RENEGOTIATION:",
6733 // We do not successfully send the no_renegotiation alert in
6734 // this case. https://crbug.com/boringssl/130
6735 })
6736
David Benjamin07ab5d42017-02-09 20:11:41 -05006737 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006738 testCases = append(testCases, testCase{
6739 name: "StrayHelloRequest",
6740 config: Config{
6741 MaxVersion: VersionTLS12,
6742 Bugs: ProtocolBugs{
6743 SendHelloRequestBeforeEveryHandshakeMessage: true,
6744 },
6745 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006746 shouldFail: true,
6747 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006748 })
6749 testCases = append(testCases, testCase{
6750 name: "StrayHelloRequest-Packed",
6751 config: Config{
6752 MaxVersion: VersionTLS12,
6753 Bugs: ProtocolBugs{
6754 PackHandshakeFlight: true,
6755 SendHelloRequestBeforeEveryHandshakeMessage: true,
6756 },
6757 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006758 shouldFail: true,
6759 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006760 })
6761
David Benjamin12d2c482016-07-24 10:56:51 -04006762 // Test renegotiation works if HelloRequest and server Finished come in
6763 // the same record.
6764 testCases = append(testCases, testCase{
6765 name: "Renegotiate-Client-Packed",
6766 config: Config{
6767 MaxVersion: VersionTLS12,
6768 Bugs: ProtocolBugs{
6769 PackHandshakeFlight: true,
6770 PackHelloRequestWithFinished: true,
6771 },
6772 },
6773 renegotiate: 1,
6774 flags: []string{
6775 "-renegotiate-freely",
6776 "-expect-total-renegotiations", "1",
6777 },
6778 })
6779
David Benjamin397c8e62016-07-08 14:14:36 -07006780 // Renegotiation is forbidden in TLS 1.3.
6781 testCases = append(testCases, testCase{
6782 name: "Renegotiate-Client-TLS13",
6783 config: Config{
6784 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006785 Bugs: ProtocolBugs{
6786 SendHelloRequestBeforeEveryAppDataRecord: true,
6787 },
David Benjamin397c8e62016-07-08 14:14:36 -07006788 },
David Benjamin397c8e62016-07-08 14:14:36 -07006789 flags: []string{
6790 "-renegotiate-freely",
6791 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006792 shouldFail: true,
6793 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006794 })
6795
6796 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6797 testCases = append(testCases, testCase{
6798 name: "StrayHelloRequest-TLS13",
6799 config: Config{
6800 MaxVersion: VersionTLS13,
6801 Bugs: ProtocolBugs{
6802 SendHelloRequestBeforeEveryHandshakeMessage: true,
6803 },
6804 },
6805 shouldFail: true,
6806 expectedError: ":UNEXPECTED_MESSAGE:",
6807 })
David Benjamind2610042017-01-03 10:49:28 -05006808
6809 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6810 // always reads as supporting it, regardless of whether it was
6811 // negotiated.
6812 testCases = append(testCases, testCase{
6813 name: "AlwaysReportRenegotiationInfo-TLS13",
6814 config: Config{
6815 MaxVersion: VersionTLS13,
6816 Bugs: ProtocolBugs{
6817 NoRenegotiationInfo: true,
6818 },
6819 },
6820 flags: []string{
6821 "-expect-secure-renegotiation",
6822 },
6823 })
David Benjamina58baaf2017-02-28 20:54:28 -05006824
6825 // Certificates may not change on renegotiation.
6826 testCases = append(testCases, testCase{
6827 name: "Renegotiation-CertificateChange",
6828 config: Config{
6829 MaxVersion: VersionTLS12,
6830 Certificates: []Certificate{rsaCertificate},
6831 Bugs: ProtocolBugs{
6832 RenegotiationCertificate: &rsaChainCertificate,
6833 },
6834 },
6835 renegotiate: 1,
6836 flags: []string{"-renegotiate-freely"},
6837 shouldFail: true,
6838 expectedError: ":SERVER_CERT_CHANGED:",
6839 })
6840 testCases = append(testCases, testCase{
6841 name: "Renegotiation-CertificateChange-2",
6842 config: Config{
6843 MaxVersion: VersionTLS12,
6844 Certificates: []Certificate{rsaCertificate},
6845 Bugs: ProtocolBugs{
6846 RenegotiationCertificate: &rsa1024Certificate,
6847 },
6848 },
6849 renegotiate: 1,
6850 flags: []string{"-renegotiate-freely"},
6851 shouldFail: true,
6852 expectedError: ":SERVER_CERT_CHANGED:",
6853 })
David Benjaminbbf42462017-03-14 21:27:10 -04006854
6855 // We do not negotiate ALPN after the initial handshake. This is
6856 // error-prone and only risks bugs in consumers.
6857 testCases = append(testCases, testCase{
6858 testType: clientTest,
6859 name: "Renegotiation-ForbidALPN",
6860 config: Config{
6861 MaxVersion: VersionTLS12,
6862 Bugs: ProtocolBugs{
6863 // Forcibly negotiate ALPN on both initial and
6864 // renegotiation handshakes. The test stack will
6865 // internally check the client does not offer
6866 // it.
6867 SendALPN: "foo",
6868 },
6869 },
6870 flags: []string{
6871 "-advertise-alpn", "\x03foo\x03bar\x03baz",
6872 "-expect-alpn", "foo",
6873 "-renegotiate-freely",
6874 },
6875 renegotiate: 1,
6876 shouldFail: true,
6877 expectedError: ":UNEXPECTED_EXTENSION:",
6878 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006879}
6880
David Benjamin5e961c12014-11-07 01:48:35 -05006881func addDTLSReplayTests() {
6882 // Test that sequence number replays are detected.
6883 testCases = append(testCases, testCase{
6884 protocol: dtls,
6885 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006886 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006887 replayWrites: true,
6888 })
6889
David Benjamin8e6db492015-07-25 18:29:23 -04006890 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006891 // than the retransmit window.
6892 testCases = append(testCases, testCase{
6893 protocol: dtls,
6894 name: "DTLS-Replay-LargeGaps",
6895 config: Config{
6896 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006897 SequenceNumberMapping: func(in uint64) uint64 {
6898 return in * 127
6899 },
David Benjamin5e961c12014-11-07 01:48:35 -05006900 },
6901 },
David Benjamin8e6db492015-07-25 18:29:23 -04006902 messageCount: 200,
6903 replayWrites: true,
6904 })
6905
6906 // Test the incoming sequence number changing non-monotonically.
6907 testCases = append(testCases, testCase{
6908 protocol: dtls,
6909 name: "DTLS-Replay-NonMonotonic",
6910 config: Config{
6911 Bugs: ProtocolBugs{
6912 SequenceNumberMapping: func(in uint64) uint64 {
6913 return in ^ 31
6914 },
6915 },
6916 },
6917 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006918 replayWrites: true,
6919 })
6920}
6921
Nick Harper60edffd2016-06-21 15:19:24 -07006922var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006923 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006924 id signatureAlgorithm
6925 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006926}{
Nick Harper60edffd2016-06-21 15:19:24 -07006927 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6928 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6929 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6930 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006931 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08006932 // The “P256” in the following line is not a mistake. In TLS 1.2 the
6933 // hash function doesn't have to match the curve and so the same
6934 // signature algorithm works with P-224.
6935 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07006936 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6937 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6938 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006939 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6940 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6941 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05006942 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04006943 // Tests for key types prior to TLS 1.2.
6944 {"RSA", 0, testCertRSA},
6945 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006946}
6947
Nick Harper60edffd2016-06-21 15:19:24 -07006948const fakeSigAlg1 signatureAlgorithm = 0x2a01
6949const fakeSigAlg2 signatureAlgorithm = 0xff01
6950
6951func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006952 // Not all ciphers involve a signature. Advertise a list which gives all
6953 // versions a signing cipher.
6954 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006955 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006956 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6957 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6958 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6959 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006960 }
David Benjamin5208fd42016-07-13 21:43:25 -04006961
David Benjaminca3d5452016-07-14 12:51:01 -04006962 var allAlgorithms []signatureAlgorithm
6963 for _, alg := range testSignatureAlgorithms {
6964 if alg.id != 0 {
6965 allAlgorithms = append(allAlgorithms, alg.id)
6966 }
6967 }
6968
Nick Harper60edffd2016-06-21 15:19:24 -07006969 // Make sure each signature algorithm works. Include some fake values in
6970 // the list and ensure they're ignored.
6971 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006972 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006973 if (ver.version < VersionTLS12) != (alg.id == 0) {
6974 continue
6975 }
6976
6977 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6978 // or remove it in C.
6979 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006980 continue
6981 }
Nick Harper60edffd2016-06-21 15:19:24 -07006982
David Benjamin3ef76972016-10-17 17:59:54 -04006983 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006984 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006985 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006986 shouldSignFail = true
6987 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006988 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006989 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08006990 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
6991 shouldSignFail = true
6992 shouldVerifyFail = true
6993 }
6994 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
6995 // the curve has to match the hash size.
6996 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04006997 shouldSignFail = true
6998 shouldVerifyFail = true
6999 }
7000
7001 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7002 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7003 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007004 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007005
7006 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007007 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007008 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007009 }
7010 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007011 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007012 }
David Benjamin000800a2014-11-14 01:43:59 -05007013
David Benjamin1fb125c2016-07-08 18:52:12 -07007014 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007015
David Benjamin7a41d372016-07-09 11:21:54 -07007016 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007017 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007018 config: Config{
7019 MaxVersion: ver.version,
7020 ClientAuth: RequireAnyClientCert,
7021 VerifySignatureAlgorithms: []signatureAlgorithm{
7022 fakeSigAlg1,
7023 alg.id,
7024 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007025 },
David Benjamin7a41d372016-07-09 11:21:54 -07007026 },
7027 flags: []string{
7028 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7029 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7030 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007031 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007032 },
David Benjamin3ef76972016-10-17 17:59:54 -04007033 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007034 expectedError: signError,
7035 expectedPeerSignatureAlgorithm: alg.id,
7036 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007037
David Benjamin7a41d372016-07-09 11:21:54 -07007038 testCases = append(testCases, testCase{
7039 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007040 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007041 config: Config{
7042 MaxVersion: ver.version,
7043 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7044 SignSignatureAlgorithms: []signatureAlgorithm{
7045 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007046 },
David Benjamin7a41d372016-07-09 11:21:54 -07007047 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007048 SkipECDSACurveCheck: shouldVerifyFail,
7049 IgnoreSignatureVersionChecks: shouldVerifyFail,
7050 // Some signature algorithms may not be advertised.
7051 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007052 },
David Benjamin7a41d372016-07-09 11:21:54 -07007053 },
7054 flags: []string{
7055 "-require-any-client-certificate",
7056 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7057 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007058 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007059 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007060 // Resume the session to assert the peer signature
7061 // algorithm is reported on both handshakes.
7062 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007063 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007064 expectedError: verifyError,
7065 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007066
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007067 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007068 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007069 testCases = append(testCases, testCase{
7070 testType: serverTest,
7071 name: "ServerAuth-Sign" + suffix,
7072 config: Config{
7073 MaxVersion: ver.version,
7074 CipherSuites: signingCiphers,
7075 VerifySignatureAlgorithms: []signatureAlgorithm{
7076 fakeSigAlg1,
7077 alg.id,
7078 fakeSigAlg2,
7079 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007080 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007081 flags: []string{
7082 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7083 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7084 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007085 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007086 },
7087 shouldFail: shouldSignFail,
7088 expectedError: signError,
7089 expectedPeerSignatureAlgorithm: alg.id,
7090 })
7091 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007092
7093 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007094 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007095 config: Config{
7096 MaxVersion: ver.version,
7097 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007098 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007099 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007100 alg.id,
7101 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007102 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007103 SkipECDSACurveCheck: shouldVerifyFail,
7104 IgnoreSignatureVersionChecks: shouldVerifyFail,
7105 // Some signature algorithms may not be advertised.
7106 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007107 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007108 },
7109 flags: []string{
7110 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7111 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007112 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007113 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007114 // Resume the session to assert the peer signature
7115 // algorithm is reported on both handshakes.
7116 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007117 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007118 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007119 })
David Benjamin5208fd42016-07-13 21:43:25 -04007120
David Benjamin3ef76972016-10-17 17:59:54 -04007121 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007122 testCases = append(testCases, testCase{
7123 testType: serverTest,
7124 name: "ClientAuth-InvalidSignature" + suffix,
7125 config: Config{
7126 MaxVersion: ver.version,
7127 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7128 SignSignatureAlgorithms: []signatureAlgorithm{
7129 alg.id,
7130 },
7131 Bugs: ProtocolBugs{
7132 InvalidSignature: true,
7133 },
7134 },
7135 flags: []string{
7136 "-require-any-client-certificate",
7137 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007138 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007139 },
7140 shouldFail: true,
7141 expectedError: ":BAD_SIGNATURE:",
7142 })
7143
7144 testCases = append(testCases, testCase{
7145 name: "ServerAuth-InvalidSignature" + suffix,
7146 config: Config{
7147 MaxVersion: ver.version,
7148 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7149 CipherSuites: signingCiphers,
7150 SignSignatureAlgorithms: []signatureAlgorithm{
7151 alg.id,
7152 },
7153 Bugs: ProtocolBugs{
7154 InvalidSignature: true,
7155 },
7156 },
David Benjamin69522112017-03-28 15:38:29 -05007157 flags: []string{
7158 "-enable-all-curves",
7159 "-enable-ed25519",
7160 },
David Benjamin5208fd42016-07-13 21:43:25 -04007161 shouldFail: true,
7162 expectedError: ":BAD_SIGNATURE:",
7163 })
7164 }
David Benjaminca3d5452016-07-14 12:51:01 -04007165
David Benjamin3ef76972016-10-17 17:59:54 -04007166 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007167 testCases = append(testCases, testCase{
7168 name: "ClientAuth-Sign-Negotiate" + suffix,
7169 config: Config{
7170 MaxVersion: ver.version,
7171 ClientAuth: RequireAnyClientCert,
7172 VerifySignatureAlgorithms: allAlgorithms,
7173 },
7174 flags: []string{
7175 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7176 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7177 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007178 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007179 "-signing-prefs", strconv.Itoa(int(alg.id)),
7180 },
7181 expectedPeerSignatureAlgorithm: alg.id,
7182 })
7183
7184 testCases = append(testCases, testCase{
7185 testType: serverTest,
7186 name: "ServerAuth-Sign-Negotiate" + suffix,
7187 config: Config{
7188 MaxVersion: ver.version,
7189 CipherSuites: signingCiphers,
7190 VerifySignatureAlgorithms: allAlgorithms,
7191 },
7192 flags: []string{
7193 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7194 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7195 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007196 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007197 "-signing-prefs", strconv.Itoa(int(alg.id)),
7198 },
7199 expectedPeerSignatureAlgorithm: alg.id,
7200 })
7201 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007202 }
David Benjamin000800a2014-11-14 01:43:59 -05007203 }
7204
Nick Harper60edffd2016-06-21 15:19:24 -07007205 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007206 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007207 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007208 config: Config{
7209 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007210 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007211 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007212 signatureECDSAWithP521AndSHA512,
7213 signatureRSAPKCS1WithSHA384,
7214 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007215 },
7216 },
7217 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007218 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7219 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007220 },
Nick Harper60edffd2016-06-21 15:19:24 -07007221 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007222 })
7223
7224 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007225 name: "ClientAuth-SignatureType-TLS13",
7226 config: Config{
7227 ClientAuth: RequireAnyClientCert,
7228 MaxVersion: VersionTLS13,
7229 VerifySignatureAlgorithms: []signatureAlgorithm{
7230 signatureECDSAWithP521AndSHA512,
7231 signatureRSAPKCS1WithSHA384,
7232 signatureRSAPSSWithSHA384,
7233 signatureECDSAWithSHA1,
7234 },
7235 },
7236 flags: []string{
7237 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7238 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7239 },
7240 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7241 })
7242
7243 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007244 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007245 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007246 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007247 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007248 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007249 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007250 signatureECDSAWithP521AndSHA512,
7251 signatureRSAPKCS1WithSHA384,
7252 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007253 },
7254 },
Nick Harper60edffd2016-06-21 15:19:24 -07007255 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007256 })
7257
Steven Valdez143e8b32016-07-11 13:19:03 -04007258 testCases = append(testCases, testCase{
7259 testType: serverTest,
7260 name: "ServerAuth-SignatureType-TLS13",
7261 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007262 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007263 VerifySignatureAlgorithms: []signatureAlgorithm{
7264 signatureECDSAWithP521AndSHA512,
7265 signatureRSAPKCS1WithSHA384,
7266 signatureRSAPSSWithSHA384,
7267 signatureECDSAWithSHA1,
7268 },
7269 },
7270 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7271 })
7272
David Benjamina95e9f32016-07-08 16:28:04 -07007273 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007274 testCases = append(testCases, testCase{
7275 testType: serverTest,
7276 name: "Verify-ClientAuth-SignatureType",
7277 config: Config{
7278 MaxVersion: VersionTLS12,
7279 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007280 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007281 signatureRSAPKCS1WithSHA256,
7282 },
7283 Bugs: ProtocolBugs{
7284 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7285 },
7286 },
7287 flags: []string{
7288 "-require-any-client-certificate",
7289 },
7290 shouldFail: true,
7291 expectedError: ":WRONG_SIGNATURE_TYPE:",
7292 })
7293
7294 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007295 testType: serverTest,
7296 name: "Verify-ClientAuth-SignatureType-TLS13",
7297 config: Config{
7298 MaxVersion: VersionTLS13,
7299 Certificates: []Certificate{rsaCertificate},
7300 SignSignatureAlgorithms: []signatureAlgorithm{
7301 signatureRSAPSSWithSHA256,
7302 },
7303 Bugs: ProtocolBugs{
7304 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7305 },
7306 },
7307 flags: []string{
7308 "-require-any-client-certificate",
7309 },
7310 shouldFail: true,
7311 expectedError: ":WRONG_SIGNATURE_TYPE:",
7312 })
7313
7314 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007315 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007316 config: Config{
7317 MaxVersion: VersionTLS12,
7318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007319 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007320 signatureRSAPKCS1WithSHA256,
7321 },
7322 Bugs: ProtocolBugs{
7323 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7324 },
7325 },
7326 shouldFail: true,
7327 expectedError: ":WRONG_SIGNATURE_TYPE:",
7328 })
7329
Steven Valdez143e8b32016-07-11 13:19:03 -04007330 testCases = append(testCases, testCase{
7331 name: "Verify-ServerAuth-SignatureType-TLS13",
7332 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007333 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007334 SignSignatureAlgorithms: []signatureAlgorithm{
7335 signatureRSAPSSWithSHA256,
7336 },
7337 Bugs: ProtocolBugs{
7338 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7339 },
7340 },
7341 shouldFail: true,
7342 expectedError: ":WRONG_SIGNATURE_TYPE:",
7343 })
7344
David Benjamin51dd7d62016-07-08 16:07:01 -07007345 // Test that, if the list is missing, the peer falls back to SHA-1 in
7346 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007347 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007348 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007350 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007351 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007352 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007353 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007354 },
7355 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007356 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007357 },
7358 },
7359 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007360 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7361 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007362 },
7363 })
7364
7365 testCases = append(testCases, testCase{
7366 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007367 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007368 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007369 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007370 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007371 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007372 },
7373 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007374 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007375 },
7376 },
David Benjaminee32bea2016-08-17 13:36:44 -04007377 flags: []string{
7378 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7379 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7380 },
7381 })
7382
7383 testCases = append(testCases, testCase{
7384 name: "ClientAuth-SHA1-Fallback-ECDSA",
7385 config: Config{
7386 MaxVersion: VersionTLS12,
7387 ClientAuth: RequireAnyClientCert,
7388 VerifySignatureAlgorithms: []signatureAlgorithm{
7389 signatureECDSAWithSHA1,
7390 },
7391 Bugs: ProtocolBugs{
7392 NoSignatureAlgorithms: true,
7393 },
7394 },
7395 flags: []string{
7396 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7397 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7398 },
7399 })
7400
7401 testCases = append(testCases, testCase{
7402 testType: serverTest,
7403 name: "ServerAuth-SHA1-Fallback-ECDSA",
7404 config: Config{
7405 MaxVersion: VersionTLS12,
7406 VerifySignatureAlgorithms: []signatureAlgorithm{
7407 signatureECDSAWithSHA1,
7408 },
7409 Bugs: ProtocolBugs{
7410 NoSignatureAlgorithms: true,
7411 },
7412 },
7413 flags: []string{
7414 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7415 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7416 },
David Benjamin000800a2014-11-14 01:43:59 -05007417 })
David Benjamin72dc7832015-03-16 17:49:43 -04007418
David Benjamin51dd7d62016-07-08 16:07:01 -07007419 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007420 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007421 config: Config{
7422 MaxVersion: VersionTLS13,
7423 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007424 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007425 signatureRSAPKCS1WithSHA1,
7426 },
7427 Bugs: ProtocolBugs{
7428 NoSignatureAlgorithms: true,
7429 },
7430 },
7431 flags: []string{
7432 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7433 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7434 },
David Benjamin48901652016-08-01 12:12:47 -04007435 shouldFail: true,
7436 // An empty CertificateRequest signature algorithm list is a
7437 // syntax error in TLS 1.3.
7438 expectedError: ":DECODE_ERROR:",
7439 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007440 })
7441
7442 testCases = append(testCases, testCase{
7443 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007444 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007445 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007446 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007447 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007448 signatureRSAPKCS1WithSHA1,
7449 },
7450 Bugs: ProtocolBugs{
7451 NoSignatureAlgorithms: true,
7452 },
7453 },
7454 shouldFail: true,
7455 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7456 })
7457
David Benjaminb62d2872016-07-18 14:55:02 +02007458 // Test that hash preferences are enforced. BoringSSL does not implement
7459 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007460 testCases = append(testCases, testCase{
7461 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007462 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007464 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007465 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007466 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007467 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007468 },
7469 Bugs: ProtocolBugs{
7470 IgnorePeerSignatureAlgorithmPreferences: true,
7471 },
7472 },
7473 flags: []string{"-require-any-client-certificate"},
7474 shouldFail: true,
7475 expectedError: ":WRONG_SIGNATURE_TYPE:",
7476 })
7477
7478 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007479 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007480 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007481 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007482 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007483 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007484 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007485 },
7486 Bugs: ProtocolBugs{
7487 IgnorePeerSignatureAlgorithmPreferences: true,
7488 },
7489 },
7490 shouldFail: true,
7491 expectedError: ":WRONG_SIGNATURE_TYPE:",
7492 })
David Benjaminb62d2872016-07-18 14:55:02 +02007493 testCases = append(testCases, testCase{
7494 testType: serverTest,
7495 name: "ClientAuth-Enforced-TLS13",
7496 config: Config{
7497 MaxVersion: VersionTLS13,
7498 Certificates: []Certificate{rsaCertificate},
7499 SignSignatureAlgorithms: []signatureAlgorithm{
7500 signatureRSAPKCS1WithMD5,
7501 },
7502 Bugs: ProtocolBugs{
7503 IgnorePeerSignatureAlgorithmPreferences: true,
7504 IgnoreSignatureVersionChecks: true,
7505 },
7506 },
7507 flags: []string{"-require-any-client-certificate"},
7508 shouldFail: true,
7509 expectedError: ":WRONG_SIGNATURE_TYPE:",
7510 })
7511
7512 testCases = append(testCases, testCase{
7513 name: "ServerAuth-Enforced-TLS13",
7514 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007515 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007516 SignSignatureAlgorithms: []signatureAlgorithm{
7517 signatureRSAPKCS1WithMD5,
7518 },
7519 Bugs: ProtocolBugs{
7520 IgnorePeerSignatureAlgorithmPreferences: true,
7521 IgnoreSignatureVersionChecks: true,
7522 },
7523 },
7524 shouldFail: true,
7525 expectedError: ":WRONG_SIGNATURE_TYPE:",
7526 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007527
7528 // Test that the agreed upon digest respects the client preferences and
7529 // the server digests.
7530 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007531 name: "NoCommonAlgorithms-Digests",
7532 config: Config{
7533 MaxVersion: VersionTLS12,
7534 ClientAuth: RequireAnyClientCert,
7535 VerifySignatureAlgorithms: []signatureAlgorithm{
7536 signatureRSAPKCS1WithSHA512,
7537 signatureRSAPKCS1WithSHA1,
7538 },
7539 },
7540 flags: []string{
7541 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7542 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7543 "-digest-prefs", "SHA256",
7544 },
7545 shouldFail: true,
7546 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7547 })
7548 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007549 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007551 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007552 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007553 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007554 signatureRSAPKCS1WithSHA512,
7555 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007556 },
7557 },
7558 flags: []string{
7559 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7560 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007561 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007562 },
David Benjaminca3d5452016-07-14 12:51:01 -04007563 shouldFail: true,
7564 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7565 })
7566 testCases = append(testCases, testCase{
7567 name: "NoCommonAlgorithms-TLS13",
7568 config: Config{
7569 MaxVersion: VersionTLS13,
7570 ClientAuth: RequireAnyClientCert,
7571 VerifySignatureAlgorithms: []signatureAlgorithm{
7572 signatureRSAPSSWithSHA512,
7573 signatureRSAPSSWithSHA384,
7574 },
7575 },
7576 flags: []string{
7577 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7578 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7579 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7580 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007581 shouldFail: true,
7582 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007583 })
7584 testCases = append(testCases, testCase{
7585 name: "Agree-Digest-SHA256",
7586 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007587 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007588 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007589 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007590 signatureRSAPKCS1WithSHA1,
7591 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007592 },
7593 },
7594 flags: []string{
7595 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7596 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007597 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007598 },
Nick Harper60edffd2016-06-21 15:19:24 -07007599 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007600 })
7601 testCases = append(testCases, testCase{
7602 name: "Agree-Digest-SHA1",
7603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007604 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007605 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007606 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007607 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007608 },
7609 },
7610 flags: []string{
7611 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7612 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007613 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007614 },
Nick Harper60edffd2016-06-21 15:19:24 -07007615 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007616 })
7617 testCases = append(testCases, testCase{
7618 name: "Agree-Digest-Default",
7619 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007620 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007621 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007622 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007623 signatureRSAPKCS1WithSHA256,
7624 signatureECDSAWithP256AndSHA256,
7625 signatureRSAPKCS1WithSHA1,
7626 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007627 },
7628 },
7629 flags: []string{
7630 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7631 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7632 },
Nick Harper60edffd2016-06-21 15:19:24 -07007633 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007634 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007635
David Benjaminca3d5452016-07-14 12:51:01 -04007636 // Test that the signing preference list may include extra algorithms
7637 // without negotiation problems.
7638 testCases = append(testCases, testCase{
7639 testType: serverTest,
7640 name: "FilterExtraAlgorithms",
7641 config: Config{
7642 MaxVersion: VersionTLS12,
7643 VerifySignatureAlgorithms: []signatureAlgorithm{
7644 signatureRSAPKCS1WithSHA256,
7645 },
7646 },
7647 flags: []string{
7648 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7649 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7650 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7651 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7652 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7653 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7654 },
7655 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7656 })
7657
David Benjamin4c3ddf72016-06-29 18:13:53 -04007658 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7659 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007660 testCases = append(testCases, testCase{
7661 name: "CheckLeafCurve",
7662 config: Config{
7663 MaxVersion: VersionTLS12,
7664 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007665 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007666 },
7667 flags: []string{"-p384-only"},
7668 shouldFail: true,
7669 expectedError: ":BAD_ECC_CERT:",
7670 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007671
7672 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7673 testCases = append(testCases, testCase{
7674 name: "CheckLeafCurve-TLS13",
7675 config: Config{
7676 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007677 Certificates: []Certificate{ecdsaP256Certificate},
7678 },
7679 flags: []string{"-p384-only"},
7680 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007681
7682 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7683 testCases = append(testCases, testCase{
7684 name: "ECDSACurveMismatch-Verify-TLS12",
7685 config: Config{
7686 MaxVersion: VersionTLS12,
7687 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7688 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007689 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007690 signatureECDSAWithP384AndSHA384,
7691 },
7692 },
7693 })
7694
7695 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7696 testCases = append(testCases, testCase{
7697 name: "ECDSACurveMismatch-Verify-TLS13",
7698 config: Config{
7699 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007700 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007701 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007702 signatureECDSAWithP384AndSHA384,
7703 },
7704 Bugs: ProtocolBugs{
7705 SkipECDSACurveCheck: true,
7706 },
7707 },
7708 shouldFail: true,
7709 expectedError: ":WRONG_SIGNATURE_TYPE:",
7710 })
7711
7712 // Signature algorithm selection in TLS 1.3 should take the curve into
7713 // account.
7714 testCases = append(testCases, testCase{
7715 testType: serverTest,
7716 name: "ECDSACurveMismatch-Sign-TLS13",
7717 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007718 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007719 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007720 signatureECDSAWithP384AndSHA384,
7721 signatureECDSAWithP256AndSHA256,
7722 },
7723 },
7724 flags: []string{
7725 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7726 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7727 },
7728 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7729 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007730
7731 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7732 // server does not attempt to sign in that case.
7733 testCases = append(testCases, testCase{
7734 testType: serverTest,
7735 name: "RSA-PSS-Large",
7736 config: Config{
7737 MaxVersion: VersionTLS13,
7738 VerifySignatureAlgorithms: []signatureAlgorithm{
7739 signatureRSAPSSWithSHA512,
7740 },
7741 },
7742 flags: []string{
7743 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7744 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7745 },
7746 shouldFail: true,
7747 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7748 })
David Benjamin57e929f2016-08-30 00:30:38 -04007749
7750 // Test that RSA-PSS is enabled by default for TLS 1.2.
7751 testCases = append(testCases, testCase{
7752 testType: clientTest,
7753 name: "RSA-PSS-Default-Verify",
7754 config: Config{
7755 MaxVersion: VersionTLS12,
7756 SignSignatureAlgorithms: []signatureAlgorithm{
7757 signatureRSAPSSWithSHA256,
7758 },
7759 },
7760 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7761 })
7762
7763 testCases = append(testCases, testCase{
7764 testType: serverTest,
7765 name: "RSA-PSS-Default-Sign",
7766 config: Config{
7767 MaxVersion: VersionTLS12,
7768 VerifySignatureAlgorithms: []signatureAlgorithm{
7769 signatureRSAPSSWithSHA256,
7770 },
7771 },
7772 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7773 })
David Benjamin69522112017-03-28 15:38:29 -05007774
7775 // TLS 1.1 and below has no way to advertise support for or negotiate
7776 // Ed25519's signature algorithm.
7777 testCases = append(testCases, testCase{
7778 testType: clientTest,
7779 name: "NoEd25519-TLS11-ServerAuth-Verify",
7780 config: Config{
7781 MaxVersion: VersionTLS11,
7782 Certificates: []Certificate{ed25519Certificate},
7783 Bugs: ProtocolBugs{
7784 // Sign with Ed25519 even though it is TLS 1.1.
7785 UseLegacySigningAlgorithm: signatureEd25519,
7786 },
7787 },
7788 flags: []string{"-enable-ed25519"},
7789 shouldFail: true,
7790 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7791 })
7792 testCases = append(testCases, testCase{
7793 testType: serverTest,
7794 name: "NoEd25519-TLS11-ServerAuth-Sign",
7795 config: Config{
7796 MaxVersion: VersionTLS11,
7797 },
7798 flags: []string{
7799 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7800 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7801 },
7802 shouldFail: true,
7803 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7804 })
7805 testCases = append(testCases, testCase{
7806 testType: serverTest,
7807 name: "NoEd25519-TLS11-ClientAuth-Verify",
7808 config: Config{
7809 MaxVersion: VersionTLS11,
7810 Certificates: []Certificate{ed25519Certificate},
7811 Bugs: ProtocolBugs{
7812 // Sign with Ed25519 even though it is TLS 1.1.
7813 UseLegacySigningAlgorithm: signatureEd25519,
7814 },
7815 },
7816 flags: []string{
7817 "-enable-ed25519",
7818 "-require-any-client-certificate",
7819 },
7820 shouldFail: true,
7821 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7822 })
7823 testCases = append(testCases, testCase{
7824 testType: clientTest,
7825 name: "NoEd25519-TLS11-ClientAuth-Sign",
7826 config: Config{
7827 MaxVersion: VersionTLS11,
7828 ClientAuth: RequireAnyClientCert,
7829 },
7830 flags: []string{
7831 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7832 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7833 },
7834 shouldFail: true,
7835 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7836 })
7837
7838 // Test Ed25519 is not advertised by default.
7839 testCases = append(testCases, testCase{
7840 testType: clientTest,
7841 name: "Ed25519DefaultDisable-NoAdvertise",
7842 config: Config{
7843 Certificates: []Certificate{ed25519Certificate},
7844 },
7845 shouldFail: true,
7846 expectedLocalError: "tls: no common signature algorithms",
7847 })
7848
7849 // Test Ed25519, when disabled, is not accepted if the peer ignores our
7850 // preferences.
7851 testCases = append(testCases, testCase{
7852 testType: clientTest,
7853 name: "Ed25519DefaultDisable-NoAccept",
7854 config: Config{
7855 Certificates: []Certificate{ed25519Certificate},
7856 Bugs: ProtocolBugs{
7857 IgnorePeerSignatureAlgorithmPreferences: true,
7858 },
7859 },
7860 shouldFail: true,
7861 expectedLocalError: "remote error: illegal parameter",
7862 expectedError: ":WRONG_SIGNATURE_TYPE:",
7863 })
David Benjamin71c21b42017-04-14 17:05:40 -04007864
7865 // Test that configuring verify preferences changes what the client
7866 // advertises.
7867 testCases = append(testCases, testCase{
7868 name: "VerifyPreferences-Advertised",
7869 config: Config{
7870 Certificates: []Certificate{rsaCertificate},
7871 SignSignatureAlgorithms: []signatureAlgorithm{
7872 signatureRSAPSSWithSHA256,
7873 signatureRSAPSSWithSHA384,
7874 signatureRSAPSSWithSHA512,
7875 },
7876 },
7877 flags: []string{
7878 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7879 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7880 },
7881 })
7882
7883 // Test that the client advertises a set which the runner can find
7884 // nothing in common with.
7885 testCases = append(testCases, testCase{
7886 name: "VerifyPreferences-NoCommonAlgorithms",
7887 config: Config{
7888 Certificates: []Certificate{rsaCertificate},
7889 SignSignatureAlgorithms: []signatureAlgorithm{
7890 signatureRSAPSSWithSHA256,
7891 signatureRSAPSSWithSHA512,
7892 },
7893 },
7894 flags: []string{
7895 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7896 },
7897 shouldFail: true,
7898 expectedLocalError: "tls: no common signature algorithms",
7899 })
7900
7901 // Test that the client enforces its preferences when configured.
7902 testCases = append(testCases, testCase{
7903 name: "VerifyPreferences-Enforced",
7904 config: Config{
7905 Certificates: []Certificate{rsaCertificate},
7906 SignSignatureAlgorithms: []signatureAlgorithm{
7907 signatureRSAPSSWithSHA256,
7908 signatureRSAPSSWithSHA512,
7909 },
7910 Bugs: ProtocolBugs{
7911 IgnorePeerSignatureAlgorithmPreferences: true,
7912 },
7913 },
7914 flags: []string{
7915 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7916 },
7917 shouldFail: true,
7918 expectedLocalError: "remote error: illegal parameter",
7919 expectedError: ":WRONG_SIGNATURE_TYPE:",
7920 })
7921
7922 // Test that explicitly configuring Ed25519 is as good as changing the
7923 // boolean toggle.
7924 testCases = append(testCases, testCase{
7925 name: "VerifyPreferences-Ed25519",
7926 config: Config{
7927 Certificates: []Certificate{ed25519Certificate},
7928 },
7929 flags: []string{
7930 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
7931 },
7932 })
David Benjamin000800a2014-11-14 01:43:59 -05007933}
7934
David Benjamin83f90402015-01-27 01:09:43 -05007935// timeouts is the retransmit schedule for BoringSSL. It doubles and
7936// caps at 60 seconds. On the 13th timeout, it gives up.
7937var timeouts = []time.Duration{
7938 1 * time.Second,
7939 2 * time.Second,
7940 4 * time.Second,
7941 8 * time.Second,
7942 16 * time.Second,
7943 32 * time.Second,
7944 60 * time.Second,
7945 60 * time.Second,
7946 60 * time.Second,
7947 60 * time.Second,
7948 60 * time.Second,
7949 60 * time.Second,
7950 60 * time.Second,
7951}
7952
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007953// shortTimeouts is an alternate set of timeouts which would occur if the
7954// initial timeout duration was set to 250ms.
7955var shortTimeouts = []time.Duration{
7956 250 * time.Millisecond,
7957 500 * time.Millisecond,
7958 1 * time.Second,
7959 2 * time.Second,
7960 4 * time.Second,
7961 8 * time.Second,
7962 16 * time.Second,
7963 32 * time.Second,
7964 60 * time.Second,
7965 60 * time.Second,
7966 60 * time.Second,
7967 60 * time.Second,
7968 60 * time.Second,
7969}
7970
David Benjamin83f90402015-01-27 01:09:43 -05007971func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007972 // These tests work by coordinating some behavior on both the shim and
7973 // the runner.
7974 //
7975 // TimeoutSchedule configures the runner to send a series of timeout
7976 // opcodes to the shim (see packetAdaptor) immediately before reading
7977 // each peer handshake flight N. The timeout opcode both simulates a
7978 // timeout in the shim and acts as a synchronization point to help the
7979 // runner bracket each handshake flight.
7980 //
7981 // We assume the shim does not read from the channel eagerly. It must
7982 // first wait until it has sent flight N and is ready to receive
7983 // handshake flight N+1. At this point, it will process the timeout
7984 // opcode. It must then immediately respond with a timeout ACK and act
7985 // as if the shim was idle for the specified amount of time.
7986 //
7987 // The runner then drops all packets received before the ACK and
7988 // continues waiting for flight N. This ordering results in one attempt
7989 // at sending flight N to be dropped. For the test to complete, the
7990 // shim must send flight N again, testing that the shim implements DTLS
7991 // retransmit on a timeout.
7992
Steven Valdez143e8b32016-07-11 13:19:03 -04007993 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007994 // likely be more epochs to cross and the final message's retransmit may
7995 // be more complex.
7996
David Benjamin11c82892017-02-23 20:40:31 -05007997 // Test that this is indeed the timeout schedule. Stress all
7998 // four patterns of handshake.
7999 for i := 1; i < len(timeouts); i++ {
8000 number := strconv.Itoa(i)
8001 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008002 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008003 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008004 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008005 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008006 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008007 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008008 },
8009 },
8010 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008011 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008012 })
David Benjamin11c82892017-02-23 20:40:31 -05008013 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008014 protocol: dtls,
8015 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008016 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008017 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008018 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008019 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008020 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008021 },
8022 },
8023 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008024 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008025 })
8026 }
David Benjamin11c82892017-02-23 20:40:31 -05008027
8028 // Test that exceeding the timeout schedule hits a read
8029 // timeout.
8030 testCases = append(testCases, testCase{
8031 protocol: dtls,
8032 name: "DTLS-Retransmit-Timeout",
8033 config: Config{
8034 MaxVersion: VersionTLS12,
8035 Bugs: ProtocolBugs{
8036 TimeoutSchedule: timeouts,
8037 },
8038 },
8039 resumeSession: true,
8040 flags: []string{"-async"},
8041 shouldFail: true,
8042 expectedError: ":READ_TIMEOUT_EXPIRED:",
8043 })
8044
8045 // Test that timeout handling has a fudge factor, due to API
8046 // problems.
8047 testCases = append(testCases, testCase{
8048 protocol: dtls,
8049 name: "DTLS-Retransmit-Fudge",
8050 config: Config{
8051 MaxVersion: VersionTLS12,
8052 Bugs: ProtocolBugs{
8053 TimeoutSchedule: []time.Duration{
8054 timeouts[0] - 10*time.Millisecond,
8055 },
8056 },
8057 },
8058 resumeSession: true,
8059 flags: []string{"-async"},
8060 })
8061
8062 // Test that the final Finished retransmitting isn't
8063 // duplicated if the peer badly fragments everything.
8064 testCases = append(testCases, testCase{
8065 testType: serverTest,
8066 protocol: dtls,
8067 name: "DTLS-Retransmit-Fragmented",
8068 config: Config{
8069 MaxVersion: VersionTLS12,
8070 Bugs: ProtocolBugs{
8071 TimeoutSchedule: []time.Duration{timeouts[0]},
8072 MaxHandshakeRecordLength: 2,
8073 },
8074 },
8075 flags: []string{"-async"},
8076 })
8077
8078 // Test the timeout schedule when a shorter initial timeout duration is set.
8079 testCases = append(testCases, testCase{
8080 protocol: dtls,
8081 name: "DTLS-Retransmit-Short-Client",
8082 config: Config{
8083 MaxVersion: VersionTLS12,
8084 Bugs: ProtocolBugs{
8085 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8086 },
8087 },
8088 resumeSession: true,
8089 flags: []string{
8090 "-async",
8091 "-initial-timeout-duration-ms", "250",
8092 },
8093 })
8094 testCases = append(testCases, testCase{
8095 protocol: dtls,
8096 testType: serverTest,
8097 name: "DTLS-Retransmit-Short-Server",
8098 config: Config{
8099 MaxVersion: VersionTLS12,
8100 Bugs: ProtocolBugs{
8101 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8102 },
8103 },
8104 resumeSession: true,
8105 flags: []string{
8106 "-async",
8107 "-initial-timeout-duration-ms", "250",
8108 },
8109 })
David Benjamin83f90402015-01-27 01:09:43 -05008110}
8111
David Benjaminc565ebb2015-04-03 04:06:36 -04008112func addExportKeyingMaterialTests() {
8113 for _, vers := range tlsVersions {
8114 if vers.version == VersionSSL30 {
8115 continue
8116 }
8117 testCases = append(testCases, testCase{
8118 name: "ExportKeyingMaterial-" + vers.name,
8119 config: Config{
8120 MaxVersion: vers.version,
8121 },
8122 exportKeyingMaterial: 1024,
8123 exportLabel: "label",
8124 exportContext: "context",
8125 useExportContext: true,
8126 })
8127 testCases = append(testCases, testCase{
8128 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8129 config: Config{
8130 MaxVersion: vers.version,
8131 },
8132 exportKeyingMaterial: 1024,
8133 })
8134 testCases = append(testCases, testCase{
8135 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8136 config: Config{
8137 MaxVersion: vers.version,
8138 },
8139 exportKeyingMaterial: 1024,
8140 useExportContext: true,
8141 })
8142 testCases = append(testCases, testCase{
8143 name: "ExportKeyingMaterial-Small-" + vers.name,
8144 config: Config{
8145 MaxVersion: vers.version,
8146 },
8147 exportKeyingMaterial: 1,
8148 exportLabel: "label",
8149 exportContext: "context",
8150 useExportContext: true,
8151 })
8152 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008153
David Benjaminc565ebb2015-04-03 04:06:36 -04008154 testCases = append(testCases, testCase{
8155 name: "ExportKeyingMaterial-SSL3",
8156 config: Config{
8157 MaxVersion: VersionSSL30,
8158 },
8159 exportKeyingMaterial: 1024,
8160 exportLabel: "label",
8161 exportContext: "context",
8162 useExportContext: true,
8163 shouldFail: true,
8164 expectedError: "failed to export keying material",
8165 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008166
8167 // Exporters work during a False Start.
8168 testCases = append(testCases, testCase{
8169 name: "ExportKeyingMaterial-FalseStart",
8170 config: Config{
8171 MaxVersion: VersionTLS12,
8172 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8173 NextProtos: []string{"foo"},
8174 Bugs: ProtocolBugs{
8175 ExpectFalseStart: true,
8176 },
8177 },
8178 flags: []string{
8179 "-false-start",
8180 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008181 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008182 },
8183 shimWritesFirst: true,
8184 exportKeyingMaterial: 1024,
8185 exportLabel: "label",
8186 exportContext: "context",
8187 useExportContext: true,
8188 })
8189
8190 // Exporters do not work in the middle of a renegotiation. Test this by
8191 // triggering the exporter after every SSL_read call and configuring the
8192 // shim to run asynchronously.
8193 testCases = append(testCases, testCase{
8194 name: "ExportKeyingMaterial-Renegotiate",
8195 config: Config{
8196 MaxVersion: VersionTLS12,
8197 },
8198 renegotiate: 1,
8199 flags: []string{
8200 "-async",
8201 "-use-exporter-between-reads",
8202 "-renegotiate-freely",
8203 "-expect-total-renegotiations", "1",
8204 },
8205 shouldFail: true,
8206 expectedError: "failed to export keying material",
8207 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008208}
8209
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008210func addTLSUniqueTests() {
8211 for _, isClient := range []bool{false, true} {
8212 for _, isResumption := range []bool{false, true} {
8213 for _, hasEMS := range []bool{false, true} {
8214 var suffix string
8215 if isResumption {
8216 suffix = "Resume-"
8217 } else {
8218 suffix = "Full-"
8219 }
8220
8221 if hasEMS {
8222 suffix += "EMS-"
8223 } else {
8224 suffix += "NoEMS-"
8225 }
8226
8227 if isClient {
8228 suffix += "Client"
8229 } else {
8230 suffix += "Server"
8231 }
8232
8233 test := testCase{
8234 name: "TLSUnique-" + suffix,
8235 testTLSUnique: true,
8236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008237 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008238 Bugs: ProtocolBugs{
8239 NoExtendedMasterSecret: !hasEMS,
8240 },
8241 },
8242 }
8243
8244 if isResumption {
8245 test.resumeSession = true
8246 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008247 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008248 Bugs: ProtocolBugs{
8249 NoExtendedMasterSecret: !hasEMS,
8250 },
8251 }
8252 }
8253
8254 if isResumption && !hasEMS {
8255 test.shouldFail = true
8256 test.expectedError = "failed to get tls-unique"
8257 }
8258
8259 testCases = append(testCases, test)
8260 }
8261 }
8262 }
8263}
8264
Adam Langley09505632015-07-30 18:10:13 -07008265func addCustomExtensionTests() {
8266 expectedContents := "custom extension"
8267 emptyString := ""
8268
8269 for _, isClient := range []bool{false, true} {
8270 suffix := "Server"
8271 flag := "-enable-server-custom-extension"
8272 testType := serverTest
8273 if isClient {
8274 suffix = "Client"
8275 flag = "-enable-client-custom-extension"
8276 testType = clientTest
8277 }
8278
8279 testCases = append(testCases, testCase{
8280 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008281 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008283 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008284 Bugs: ProtocolBugs{
8285 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008286 ExpectedCustomExtension: &expectedContents,
8287 },
8288 },
8289 flags: []string{flag},
8290 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008291 testCases = append(testCases, testCase{
8292 testType: testType,
8293 name: "CustomExtensions-" + suffix + "-TLS13",
8294 config: Config{
8295 MaxVersion: VersionTLS13,
8296 Bugs: ProtocolBugs{
8297 CustomExtension: expectedContents,
8298 ExpectedCustomExtension: &expectedContents,
8299 },
8300 },
8301 flags: []string{flag},
8302 })
Adam Langley09505632015-07-30 18:10:13 -07008303
Steven Valdez2a070722017-03-25 20:54:16 -05008304 // 0-RTT is not currently supported with Custom Extensions.
8305 testCases = append(testCases, testCase{
8306 testType: testType,
8307 name: "CustomExtensions-" + suffix + "-EarlyData",
8308 config: Config{
8309 MaxVersion: VersionTLS13,
8310 Bugs: ProtocolBugs{
8311 CustomExtension: expectedContents,
8312 ExpectedCustomExtension: &expectedContents,
8313 },
8314 },
8315 shouldFail: true,
8316 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8317 flags: []string{flag, "-enable-early-data"},
8318 })
8319
Adam Langley09505632015-07-30 18:10:13 -07008320 // If the parse callback fails, the handshake should also fail.
8321 testCases = append(testCases, testCase{
8322 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008323 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008324 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008325 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008326 Bugs: ProtocolBugs{
8327 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008328 ExpectedCustomExtension: &expectedContents,
8329 },
8330 },
David Benjamin399e7c92015-07-30 23:01:27 -04008331 flags: []string{flag},
8332 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008333 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8334 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008335 testCases = append(testCases, testCase{
8336 testType: testType,
8337 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8338 config: Config{
8339 MaxVersion: VersionTLS13,
8340 Bugs: ProtocolBugs{
8341 CustomExtension: expectedContents + "foo",
8342 ExpectedCustomExtension: &expectedContents,
8343 },
8344 },
8345 flags: []string{flag},
8346 shouldFail: true,
8347 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8348 })
Adam Langley09505632015-07-30 18:10:13 -07008349
8350 // If the add callback fails, the handshake should also fail.
8351 testCases = append(testCases, testCase{
8352 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008353 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008354 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008355 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008356 Bugs: ProtocolBugs{
8357 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008358 ExpectedCustomExtension: &expectedContents,
8359 },
8360 },
David Benjamin399e7c92015-07-30 23:01:27 -04008361 flags: []string{flag, "-custom-extension-fail-add"},
8362 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008363 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8364 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008365 testCases = append(testCases, testCase{
8366 testType: testType,
8367 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8368 config: Config{
8369 MaxVersion: VersionTLS13,
8370 Bugs: ProtocolBugs{
8371 CustomExtension: expectedContents,
8372 ExpectedCustomExtension: &expectedContents,
8373 },
8374 },
8375 flags: []string{flag, "-custom-extension-fail-add"},
8376 shouldFail: true,
8377 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8378 })
Adam Langley09505632015-07-30 18:10:13 -07008379
8380 // If the add callback returns zero, no extension should be
8381 // added.
8382 skipCustomExtension := expectedContents
8383 if isClient {
8384 // For the case where the client skips sending the
8385 // custom extension, the server must not “echo” it.
8386 skipCustomExtension = ""
8387 }
8388 testCases = append(testCases, testCase{
8389 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008390 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008392 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008393 Bugs: ProtocolBugs{
8394 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008395 ExpectedCustomExtension: &emptyString,
8396 },
8397 },
8398 flags: []string{flag, "-custom-extension-skip"},
8399 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008400 testCases = append(testCases, testCase{
8401 testType: testType,
8402 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8403 config: Config{
8404 MaxVersion: VersionTLS13,
8405 Bugs: ProtocolBugs{
8406 CustomExtension: skipCustomExtension,
8407 ExpectedCustomExtension: &emptyString,
8408 },
8409 },
8410 flags: []string{flag, "-custom-extension-skip"},
8411 })
Adam Langley09505632015-07-30 18:10:13 -07008412 }
8413
8414 // The custom extension add callback should not be called if the client
8415 // doesn't send the extension.
8416 testCases = append(testCases, testCase{
8417 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008418 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008420 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008421 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008422 ExpectedCustomExtension: &emptyString,
8423 },
8424 },
8425 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8426 })
Adam Langley2deb9842015-08-07 11:15:37 -07008427
Steven Valdez143e8b32016-07-11 13:19:03 -04008428 testCases = append(testCases, testCase{
8429 testType: serverTest,
8430 name: "CustomExtensions-NotCalled-Server-TLS13",
8431 config: Config{
8432 MaxVersion: VersionTLS13,
8433 Bugs: ProtocolBugs{
8434 ExpectedCustomExtension: &emptyString,
8435 },
8436 },
8437 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8438 })
8439
Adam Langley2deb9842015-08-07 11:15:37 -07008440 // Test an unknown extension from the server.
8441 testCases = append(testCases, testCase{
8442 testType: clientTest,
8443 name: "UnknownExtension-Client",
8444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008445 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008446 Bugs: ProtocolBugs{
8447 CustomExtension: expectedContents,
8448 },
8449 },
David Benjamin0c40a962016-08-01 12:05:50 -04008450 shouldFail: true,
8451 expectedError: ":UNEXPECTED_EXTENSION:",
8452 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008453 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008454 testCases = append(testCases, testCase{
8455 testType: clientTest,
8456 name: "UnknownExtension-Client-TLS13",
8457 config: Config{
8458 MaxVersion: VersionTLS13,
8459 Bugs: ProtocolBugs{
8460 CustomExtension: expectedContents,
8461 },
8462 },
David Benjamin0c40a962016-08-01 12:05:50 -04008463 shouldFail: true,
8464 expectedError: ":UNEXPECTED_EXTENSION:",
8465 expectedLocalError: "remote error: unsupported extension",
8466 })
David Benjamin490469f2016-10-05 22:44:38 -04008467 testCases = append(testCases, testCase{
8468 testType: clientTest,
8469 name: "UnknownUnencryptedExtension-Client-TLS13",
8470 config: Config{
8471 MaxVersion: VersionTLS13,
8472 Bugs: ProtocolBugs{
8473 CustomUnencryptedExtension: expectedContents,
8474 },
8475 },
8476 shouldFail: true,
8477 expectedError: ":UNEXPECTED_EXTENSION:",
8478 // The shim must send an alert, but alerts at this point do not
8479 // get successfully decrypted by the runner.
8480 expectedLocalError: "local error: bad record MAC",
8481 })
8482 testCases = append(testCases, testCase{
8483 testType: clientTest,
8484 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8485 config: Config{
8486 MaxVersion: VersionTLS13,
8487 Bugs: ProtocolBugs{
8488 SendUnencryptedALPN: "foo",
8489 },
8490 },
8491 flags: []string{
8492 "-advertise-alpn", "\x03foo\x03bar",
8493 },
8494 shouldFail: true,
8495 expectedError: ":UNEXPECTED_EXTENSION:",
8496 // The shim must send an alert, but alerts at this point do not
8497 // get successfully decrypted by the runner.
8498 expectedLocalError: "local error: bad record MAC",
8499 })
David Benjamin0c40a962016-08-01 12:05:50 -04008500
8501 // Test a known but unoffered extension from the server.
8502 testCases = append(testCases, testCase{
8503 testType: clientTest,
8504 name: "UnofferedExtension-Client",
8505 config: Config{
8506 MaxVersion: VersionTLS12,
8507 Bugs: ProtocolBugs{
8508 SendALPN: "alpn",
8509 },
8510 },
8511 shouldFail: true,
8512 expectedError: ":UNEXPECTED_EXTENSION:",
8513 expectedLocalError: "remote error: unsupported extension",
8514 })
8515 testCases = append(testCases, testCase{
8516 testType: clientTest,
8517 name: "UnofferedExtension-Client-TLS13",
8518 config: Config{
8519 MaxVersion: VersionTLS13,
8520 Bugs: ProtocolBugs{
8521 SendALPN: "alpn",
8522 },
8523 },
8524 shouldFail: true,
8525 expectedError: ":UNEXPECTED_EXTENSION:",
8526 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008527 })
Adam Langley09505632015-07-30 18:10:13 -07008528}
8529
David Benjaminb36a3952015-12-01 18:53:13 -05008530func addRSAClientKeyExchangeTests() {
8531 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8532 testCases = append(testCases, testCase{
8533 testType: serverTest,
8534 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8535 config: Config{
8536 // Ensure the ClientHello version and final
8537 // version are different, to detect if the
8538 // server uses the wrong one.
8539 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008540 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008541 Bugs: ProtocolBugs{
8542 BadRSAClientKeyExchange: bad,
8543 },
8544 },
8545 shouldFail: true,
8546 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8547 })
8548 }
David Benjamine63d9d72016-09-19 18:27:34 -04008549
8550 // The server must compare whatever was in ClientHello.version for the
8551 // RSA premaster.
8552 testCases = append(testCases, testCase{
8553 testType: serverTest,
8554 name: "SendClientVersion-RSA",
8555 config: Config{
8556 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8557 Bugs: ProtocolBugs{
8558 SendClientVersion: 0x1234,
8559 },
8560 },
8561 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8562 })
David Benjaminb36a3952015-12-01 18:53:13 -05008563}
8564
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008565var testCurves = []struct {
8566 name string
8567 id CurveID
8568}{
Adam Langley764ab982017-03-10 18:01:30 -08008569 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008570 {"P-256", CurveP256},
8571 {"P-384", CurveP384},
8572 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008573 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008574}
8575
Steven Valdez5440fe02016-07-18 12:40:30 -04008576const bogusCurve = 0x1234
8577
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008578func addCurveTests() {
8579 for _, curve := range testCurves {
8580 testCases = append(testCases, testCase{
8581 name: "CurveTest-Client-" + curve.name,
8582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008583 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008584 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8585 CurvePreferences: []CurveID{curve.id},
8586 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008587 flags: []string{
8588 "-enable-all-curves",
8589 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8590 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008591 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008592 })
8593 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008594 name: "CurveTest-Client-" + curve.name + "-TLS13",
8595 config: Config{
8596 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008597 CurvePreferences: []CurveID{curve.id},
8598 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008599 flags: []string{
8600 "-enable-all-curves",
8601 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8602 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008603 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008604 })
8605 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008606 testType: serverTest,
8607 name: "CurveTest-Server-" + curve.name,
8608 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008609 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008610 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8611 CurvePreferences: []CurveID{curve.id},
8612 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008613 flags: []string{
8614 "-enable-all-curves",
8615 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8616 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008617 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008618 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008619 testCases = append(testCases, testCase{
8620 testType: serverTest,
8621 name: "CurveTest-Server-" + curve.name + "-TLS13",
8622 config: Config{
8623 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008624 CurvePreferences: []CurveID{curve.id},
8625 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008626 flags: []string{
8627 "-enable-all-curves",
8628 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8629 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008630 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008631 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008632 }
David Benjamin241ae832016-01-15 03:04:54 -05008633
8634 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008635 testCases = append(testCases, testCase{
8636 testType: serverTest,
8637 name: "UnknownCurve",
8638 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008639 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8641 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8642 },
8643 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008644
Steven Valdez803c77a2016-09-06 14:13:43 -04008645 // The server must be tolerant to bogus curves.
8646 testCases = append(testCases, testCase{
8647 testType: serverTest,
8648 name: "UnknownCurve-TLS13",
8649 config: Config{
8650 MaxVersion: VersionTLS13,
8651 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8652 },
8653 })
8654
David Benjamin4c3ddf72016-06-29 18:13:53 -04008655 // The server must not consider ECDHE ciphers when there are no
8656 // supported curves.
8657 testCases = append(testCases, testCase{
8658 testType: serverTest,
8659 name: "NoSupportedCurves",
8660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008661 MaxVersion: VersionTLS12,
8662 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8663 Bugs: ProtocolBugs{
8664 NoSupportedCurves: true,
8665 },
8666 },
8667 shouldFail: true,
8668 expectedError: ":NO_SHARED_CIPHER:",
8669 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008670 testCases = append(testCases, testCase{
8671 testType: serverTest,
8672 name: "NoSupportedCurves-TLS13",
8673 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008674 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008675 Bugs: ProtocolBugs{
8676 NoSupportedCurves: true,
8677 },
8678 },
8679 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008680 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008681 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008682
8683 // The server must fall back to another cipher when there are no
8684 // supported curves.
8685 testCases = append(testCases, testCase{
8686 testType: serverTest,
8687 name: "NoCommonCurves",
8688 config: Config{
8689 MaxVersion: VersionTLS12,
8690 CipherSuites: []uint16{
8691 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008692 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008693 },
8694 CurvePreferences: []CurveID{CurveP224},
8695 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008696 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008697 })
8698
8699 // The client must reject bogus curves and disabled curves.
8700 testCases = append(testCases, testCase{
8701 name: "BadECDHECurve",
8702 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008703 MaxVersion: VersionTLS12,
8704 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8705 Bugs: ProtocolBugs{
8706 SendCurve: bogusCurve,
8707 },
8708 },
8709 shouldFail: true,
8710 expectedError: ":WRONG_CURVE:",
8711 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008712 testCases = append(testCases, testCase{
8713 name: "BadECDHECurve-TLS13",
8714 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008715 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008716 Bugs: ProtocolBugs{
8717 SendCurve: bogusCurve,
8718 },
8719 },
8720 shouldFail: true,
8721 expectedError: ":WRONG_CURVE:",
8722 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008723
8724 testCases = append(testCases, testCase{
8725 name: "UnsupportedCurve",
8726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008727 MaxVersion: VersionTLS12,
8728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8729 CurvePreferences: []CurveID{CurveP256},
8730 Bugs: ProtocolBugs{
8731 IgnorePeerCurvePreferences: true,
8732 },
8733 },
8734 flags: []string{"-p384-only"},
8735 shouldFail: true,
8736 expectedError: ":WRONG_CURVE:",
8737 })
8738
David Benjamin4f921572016-07-17 14:20:10 +02008739 testCases = append(testCases, testCase{
8740 // TODO(davidben): Add a TLS 1.3 version where
8741 // HelloRetryRequest requests an unsupported curve.
8742 name: "UnsupportedCurve-ServerHello-TLS13",
8743 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008744 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008745 CurvePreferences: []CurveID{CurveP384},
8746 Bugs: ProtocolBugs{
8747 SendCurve: CurveP256,
8748 },
8749 },
8750 flags: []string{"-p384-only"},
8751 shouldFail: true,
8752 expectedError: ":WRONG_CURVE:",
8753 })
8754
David Benjamin4c3ddf72016-06-29 18:13:53 -04008755 // Test invalid curve points.
8756 testCases = append(testCases, testCase{
8757 name: "InvalidECDHPoint-Client",
8758 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008759 MaxVersion: VersionTLS12,
8760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8761 CurvePreferences: []CurveID{CurveP256},
8762 Bugs: ProtocolBugs{
8763 InvalidECDHPoint: true,
8764 },
8765 },
8766 shouldFail: true,
8767 expectedError: ":INVALID_ENCODING:",
8768 })
8769 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008770 name: "InvalidECDHPoint-Client-TLS13",
8771 config: Config{
8772 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008773 CurvePreferences: []CurveID{CurveP256},
8774 Bugs: ProtocolBugs{
8775 InvalidECDHPoint: true,
8776 },
8777 },
8778 shouldFail: true,
8779 expectedError: ":INVALID_ENCODING:",
8780 })
8781 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008782 testType: serverTest,
8783 name: "InvalidECDHPoint-Server",
8784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008785 MaxVersion: VersionTLS12,
8786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8787 CurvePreferences: []CurveID{CurveP256},
8788 Bugs: ProtocolBugs{
8789 InvalidECDHPoint: true,
8790 },
8791 },
8792 shouldFail: true,
8793 expectedError: ":INVALID_ENCODING:",
8794 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008795 testCases = append(testCases, testCase{
8796 testType: serverTest,
8797 name: "InvalidECDHPoint-Server-TLS13",
8798 config: Config{
8799 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008800 CurvePreferences: []CurveID{CurveP256},
8801 Bugs: ProtocolBugs{
8802 InvalidECDHPoint: true,
8803 },
8804 },
8805 shouldFail: true,
8806 expectedError: ":INVALID_ENCODING:",
8807 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008808
8809 // The previous curve ID should be reported on TLS 1.2 resumption.
8810 testCases = append(testCases, testCase{
8811 name: "CurveID-Resume-Client",
8812 config: Config{
8813 MaxVersion: VersionTLS12,
8814 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8815 CurvePreferences: []CurveID{CurveX25519},
8816 },
8817 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8818 resumeSession: true,
8819 })
8820 testCases = append(testCases, testCase{
8821 testType: serverTest,
8822 name: "CurveID-Resume-Server",
8823 config: Config{
8824 MaxVersion: VersionTLS12,
8825 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8826 CurvePreferences: []CurveID{CurveX25519},
8827 },
8828 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8829 resumeSession: true,
8830 })
8831
8832 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8833 // one should be reported.
8834 testCases = append(testCases, testCase{
8835 name: "CurveID-Resume-Client-TLS13",
8836 config: Config{
8837 MaxVersion: VersionTLS13,
8838 CurvePreferences: []CurveID{CurveX25519},
8839 },
8840 resumeConfig: &Config{
8841 MaxVersion: VersionTLS13,
8842 CurvePreferences: []CurveID{CurveP256},
8843 },
8844 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008845 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8846 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008847 },
8848 resumeSession: true,
8849 })
8850 testCases = append(testCases, testCase{
8851 testType: serverTest,
8852 name: "CurveID-Resume-Server-TLS13",
8853 config: Config{
8854 MaxVersion: VersionTLS13,
8855 CurvePreferences: []CurveID{CurveX25519},
8856 },
8857 resumeConfig: &Config{
8858 MaxVersion: VersionTLS13,
8859 CurvePreferences: []CurveID{CurveP256},
8860 },
8861 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008862 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8863 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008864 },
8865 resumeSession: true,
8866 })
David Benjamina81967b2016-12-22 09:16:57 -05008867
8868 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8869 testCases = append(testCases, testCase{
8870 name: "PointFormat-ServerHello-TLS12",
8871 config: Config{
8872 MaxVersion: VersionTLS12,
8873 Bugs: ProtocolBugs{
8874 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8875 },
8876 },
8877 })
8878 testCases = append(testCases, testCase{
8879 name: "PointFormat-EncryptedExtensions-TLS13",
8880 config: Config{
8881 MaxVersion: VersionTLS13,
8882 Bugs: ProtocolBugs{
8883 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8884 },
8885 },
8886 shouldFail: true,
8887 expectedError: ":ERROR_PARSING_EXTENSION:",
8888 })
8889
8890 // Test that we tolerate unknown point formats, as long as
8891 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8892 // check they are still functional.
8893 testCases = append(testCases, testCase{
8894 name: "PointFormat-Client-Tolerance",
8895 config: Config{
8896 MaxVersion: VersionTLS12,
8897 Bugs: ProtocolBugs{
8898 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8899 },
8900 },
8901 })
8902 testCases = append(testCases, testCase{
8903 testType: serverTest,
8904 name: "PointFormat-Server-Tolerance",
8905 config: Config{
8906 MaxVersion: VersionTLS12,
8907 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8908 Bugs: ProtocolBugs{
8909 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8910 },
8911 },
8912 })
8913
8914 // Test TLS 1.2 does not require the point format extension to be
8915 // present.
8916 testCases = append(testCases, testCase{
8917 name: "PointFormat-Client-Missing",
8918 config: Config{
8919 MaxVersion: VersionTLS12,
8920 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8921 Bugs: ProtocolBugs{
8922 SendSupportedPointFormats: []byte{},
8923 },
8924 },
8925 })
8926 testCases = append(testCases, testCase{
8927 testType: serverTest,
8928 name: "PointFormat-Server-Missing",
8929 config: Config{
8930 MaxVersion: VersionTLS12,
8931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8932 Bugs: ProtocolBugs{
8933 SendSupportedPointFormats: []byte{},
8934 },
8935 },
8936 })
8937
8938 // If the point format extension is present, uncompressed points must be
8939 // offered. BoringSSL requires this whether or not ECDHE is used.
8940 testCases = append(testCases, testCase{
8941 name: "PointFormat-Client-MissingUncompressed",
8942 config: Config{
8943 MaxVersion: VersionTLS12,
8944 Bugs: ProtocolBugs{
8945 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8946 },
8947 },
8948 shouldFail: true,
8949 expectedError: ":ERROR_PARSING_EXTENSION:",
8950 })
8951 testCases = append(testCases, testCase{
8952 testType: serverTest,
8953 name: "PointFormat-Server-MissingUncompressed",
8954 config: Config{
8955 MaxVersion: VersionTLS12,
8956 Bugs: ProtocolBugs{
8957 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8958 },
8959 },
8960 shouldFail: true,
8961 expectedError: ":ERROR_PARSING_EXTENSION:",
8962 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008963}
8964
David Benjaminc9ae27c2016-06-24 22:56:37 -04008965func addTLS13RecordTests() {
8966 testCases = append(testCases, testCase{
8967 name: "TLS13-RecordPadding",
8968 config: Config{
8969 MaxVersion: VersionTLS13,
8970 MinVersion: VersionTLS13,
8971 Bugs: ProtocolBugs{
8972 RecordPadding: 10,
8973 },
8974 },
8975 })
8976
8977 testCases = append(testCases, testCase{
8978 name: "TLS13-EmptyRecords",
8979 config: Config{
8980 MaxVersion: VersionTLS13,
8981 MinVersion: VersionTLS13,
8982 Bugs: ProtocolBugs{
8983 OmitRecordContents: true,
8984 },
8985 },
8986 shouldFail: true,
8987 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8988 })
8989
8990 testCases = append(testCases, testCase{
8991 name: "TLS13-OnlyPadding",
8992 config: Config{
8993 MaxVersion: VersionTLS13,
8994 MinVersion: VersionTLS13,
8995 Bugs: ProtocolBugs{
8996 OmitRecordContents: true,
8997 RecordPadding: 10,
8998 },
8999 },
9000 shouldFail: true,
9001 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9002 })
9003
9004 testCases = append(testCases, testCase{
9005 name: "TLS13-WrongOuterRecord",
9006 config: Config{
9007 MaxVersion: VersionTLS13,
9008 MinVersion: VersionTLS13,
9009 Bugs: ProtocolBugs{
9010 OuterRecordType: recordTypeHandshake,
9011 },
9012 },
9013 shouldFail: true,
9014 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9015 })
9016}
9017
Steven Valdez5b986082016-09-01 12:29:49 -04009018func addSessionTicketTests() {
9019 testCases = append(testCases, testCase{
9020 // In TLS 1.2 and below, empty NewSessionTicket messages
9021 // mean the server changed its mind on sending a ticket.
9022 name: "SendEmptySessionTicket",
9023 config: Config{
9024 MaxVersion: VersionTLS12,
9025 Bugs: ProtocolBugs{
9026 SendEmptySessionTicket: true,
9027 },
9028 },
9029 flags: []string{"-expect-no-session"},
9030 })
9031
9032 // Test that the server ignores unknown PSK modes.
9033 testCases = append(testCases, testCase{
9034 testType: serverTest,
9035 name: "TLS13-SendUnknownModeSessionTicket-Server",
9036 config: Config{
9037 MaxVersion: VersionTLS13,
9038 Bugs: ProtocolBugs{
9039 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009040 },
9041 },
9042 resumeSession: true,
9043 expectedResumeVersion: VersionTLS13,
9044 })
9045
Steven Valdeza833c352016-11-01 13:39:36 -04009046 // Test that the server does not send session tickets with no matching key exchange mode.
9047 testCases = append(testCases, testCase{
9048 testType: serverTest,
9049 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9050 config: Config{
9051 MaxVersion: VersionTLS13,
9052 Bugs: ProtocolBugs{
9053 SendPSKKeyExchangeModes: []byte{0x1a},
9054 ExpectNoNewSessionTicket: true,
9055 },
9056 },
9057 })
9058
9059 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009060 testCases = append(testCases, testCase{
9061 testType: serverTest,
9062 name: "TLS13-SendBadKEModeSessionTicket-Server",
9063 config: Config{
9064 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009065 },
9066 resumeConfig: &Config{
9067 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009068 Bugs: ProtocolBugs{
9069 SendPSKKeyExchangeModes: []byte{0x1a},
9070 },
9071 },
9072 resumeSession: true,
9073 expectResumeRejected: true,
9074 })
9075
Steven Valdeza833c352016-11-01 13:39:36 -04009076 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009077 testCases = append(testCases, testCase{
9078 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009079 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009080 config: Config{
9081 MaxVersion: VersionTLS13,
9082 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009083 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009084 },
9085 },
Steven Valdeza833c352016-11-01 13:39:36 -04009086 resumeSession: true,
9087 flags: []string{
9088 "-resumption-delay", "10",
9089 },
Steven Valdez5b986082016-09-01 12:29:49 -04009090 })
9091
Steven Valdeza833c352016-11-01 13:39:36 -04009092 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009093 testCases = append(testCases, testCase{
9094 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009095 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009096 config: Config{
9097 MaxVersion: VersionTLS13,
9098 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009099 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009100 },
9101 },
Steven Valdeza833c352016-11-01 13:39:36 -04009102 resumeSession: true,
9103 shouldFail: true,
9104 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009105 })
9106
David Benjamin35ac5b72017-03-03 15:05:56 -05009107 // Test that the server's ticket age skew reporting works.
9108 testCases = append(testCases, testCase{
9109 testType: serverTest,
9110 name: "TLS13-TicketAgeSkew-Forward",
9111 config: Config{
9112 MaxVersion: VersionTLS13,
9113 Bugs: ProtocolBugs{
9114 SendTicketAge: 15 * time.Second,
9115 },
9116 },
David Benjamin065d7332017-03-26 10:51:43 -05009117 resumeSession: true,
9118 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009119 flags: []string{
9120 "-resumption-delay", "10",
9121 "-expect-ticket-age-skew", "5",
9122 },
9123 })
9124 testCases = append(testCases, testCase{
9125 testType: serverTest,
9126 name: "TLS13-TicketAgeSkew-Backward",
9127 config: Config{
9128 MaxVersion: VersionTLS13,
9129 Bugs: ProtocolBugs{
9130 SendTicketAge: 5 * time.Second,
9131 },
9132 },
David Benjamin065d7332017-03-26 10:51:43 -05009133 resumeSession: true,
9134 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009135 flags: []string{
9136 "-resumption-delay", "10",
9137 "-expect-ticket-age-skew", "-5",
9138 },
9139 })
9140
Steven Valdez08b65f42016-12-07 15:29:45 -05009141 testCases = append(testCases, testCase{
9142 testType: clientTest,
9143 name: "TLS13-SendTicketEarlyDataInfo",
9144 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009145 MaxVersion: VersionTLS13,
9146 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009147 },
9148 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009149 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009150 "-expect-early-data-info",
9151 },
9152 })
9153
David Benjamin9b160662017-01-25 19:53:43 -05009154 // Test that 0-RTT tickets are ignored in clients unless opted in.
9155 testCases = append(testCases, testCase{
9156 testType: clientTest,
9157 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9158 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009159 MaxVersion: VersionTLS13,
9160 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009161 },
9162 })
9163
Steven Valdez08b65f42016-12-07 15:29:45 -05009164 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009165 testType: clientTest,
9166 name: "TLS13-DuplicateTicketEarlyDataInfo",
9167 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009168 MaxVersion: VersionTLS13,
9169 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009170 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009171 DuplicateTicketEarlyDataInfo: true,
9172 },
9173 },
9174 shouldFail: true,
9175 expectedError: ":DUPLICATE_EXTENSION:",
9176 expectedLocalError: "remote error: illegal parameter",
9177 })
9178
9179 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009180 testType: serverTest,
9181 name: "TLS13-ExpectTicketEarlyDataInfo",
9182 config: Config{
9183 MaxVersion: VersionTLS13,
9184 Bugs: ProtocolBugs{
9185 ExpectTicketEarlyDataInfo: true,
9186 },
9187 },
9188 flags: []string{
9189 "-enable-early-data",
9190 },
9191 })
David Benjamin17b30832017-01-28 14:00:32 -05009192
9193 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9194 // is honored.
9195 testCases = append(testCases, testCase{
9196 testType: clientTest,
9197 name: "TLS13-HonorServerSessionTicketLifetime",
9198 config: Config{
9199 MaxVersion: VersionTLS13,
9200 Bugs: ProtocolBugs{
9201 SendTicketLifetime: 20 * time.Second,
9202 },
9203 },
9204 flags: []string{
9205 "-resumption-delay", "19",
9206 },
9207 resumeSession: true,
9208 })
9209 testCases = append(testCases, testCase{
9210 testType: clientTest,
9211 name: "TLS13-HonorServerSessionTicketLifetime-2",
9212 config: Config{
9213 MaxVersion: VersionTLS13,
9214 Bugs: ProtocolBugs{
9215 SendTicketLifetime: 20 * time.Second,
9216 // The client should not offer the expired session.
9217 ExpectNoTLS13PSK: true,
9218 },
9219 },
9220 flags: []string{
9221 "-resumption-delay", "21",
9222 },
David Benjamin023d4192017-02-06 13:49:07 -05009223 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009224 expectResumeRejected: true,
9225 })
Steven Valdez5b986082016-09-01 12:29:49 -04009226}
9227
David Benjamin82261be2016-07-07 14:32:50 -07009228func addChangeCipherSpecTests() {
9229 // Test missing ChangeCipherSpecs.
9230 testCases = append(testCases, testCase{
9231 name: "SkipChangeCipherSpec-Client",
9232 config: Config{
9233 MaxVersion: VersionTLS12,
9234 Bugs: ProtocolBugs{
9235 SkipChangeCipherSpec: true,
9236 },
9237 },
9238 shouldFail: true,
9239 expectedError: ":UNEXPECTED_RECORD:",
9240 })
9241 testCases = append(testCases, testCase{
9242 testType: serverTest,
9243 name: "SkipChangeCipherSpec-Server",
9244 config: Config{
9245 MaxVersion: VersionTLS12,
9246 Bugs: ProtocolBugs{
9247 SkipChangeCipherSpec: true,
9248 },
9249 },
9250 shouldFail: true,
9251 expectedError: ":UNEXPECTED_RECORD:",
9252 })
9253 testCases = append(testCases, testCase{
9254 testType: serverTest,
9255 name: "SkipChangeCipherSpec-Server-NPN",
9256 config: Config{
9257 MaxVersion: VersionTLS12,
9258 NextProtos: []string{"bar"},
9259 Bugs: ProtocolBugs{
9260 SkipChangeCipherSpec: true,
9261 },
9262 },
9263 flags: []string{
9264 "-advertise-npn", "\x03foo\x03bar\x03baz",
9265 },
9266 shouldFail: true,
9267 expectedError: ":UNEXPECTED_RECORD:",
9268 })
9269
9270 // Test synchronization between the handshake and ChangeCipherSpec.
9271 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9272 // rejected. Test both with and without handshake packing to handle both
9273 // when the partial post-CCS message is in its own record and when it is
9274 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009275 for _, packed := range []bool{false, true} {
9276 var suffix string
9277 if packed {
9278 suffix = "-Packed"
9279 }
9280
9281 testCases = append(testCases, testCase{
9282 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9283 config: Config{
9284 MaxVersion: VersionTLS12,
9285 Bugs: ProtocolBugs{
9286 FragmentAcrossChangeCipherSpec: true,
9287 PackHandshakeFlight: packed,
9288 },
9289 },
9290 shouldFail: true,
9291 expectedError: ":UNEXPECTED_RECORD:",
9292 })
9293 testCases = append(testCases, testCase{
9294 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9295 config: Config{
9296 MaxVersion: VersionTLS12,
9297 },
9298 resumeSession: true,
9299 resumeConfig: &Config{
9300 MaxVersion: VersionTLS12,
9301 Bugs: ProtocolBugs{
9302 FragmentAcrossChangeCipherSpec: true,
9303 PackHandshakeFlight: packed,
9304 },
9305 },
9306 shouldFail: true,
9307 expectedError: ":UNEXPECTED_RECORD:",
9308 })
9309 testCases = append(testCases, testCase{
9310 testType: serverTest,
9311 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9312 config: Config{
9313 MaxVersion: VersionTLS12,
9314 Bugs: ProtocolBugs{
9315 FragmentAcrossChangeCipherSpec: true,
9316 PackHandshakeFlight: packed,
9317 },
9318 },
9319 shouldFail: true,
9320 expectedError: ":UNEXPECTED_RECORD:",
9321 })
9322 testCases = append(testCases, testCase{
9323 testType: serverTest,
9324 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9325 config: Config{
9326 MaxVersion: VersionTLS12,
9327 },
9328 resumeSession: true,
9329 resumeConfig: &Config{
9330 MaxVersion: VersionTLS12,
9331 Bugs: ProtocolBugs{
9332 FragmentAcrossChangeCipherSpec: true,
9333 PackHandshakeFlight: packed,
9334 },
9335 },
9336 shouldFail: true,
9337 expectedError: ":UNEXPECTED_RECORD:",
9338 })
9339 testCases = append(testCases, testCase{
9340 testType: serverTest,
9341 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9342 config: Config{
9343 MaxVersion: VersionTLS12,
9344 NextProtos: []string{"bar"},
9345 Bugs: ProtocolBugs{
9346 FragmentAcrossChangeCipherSpec: true,
9347 PackHandshakeFlight: packed,
9348 },
9349 },
9350 flags: []string{
9351 "-advertise-npn", "\x03foo\x03bar\x03baz",
9352 },
9353 shouldFail: true,
9354 expectedError: ":UNEXPECTED_RECORD:",
9355 })
9356 }
9357
David Benjamin61672812016-07-14 23:10:43 -04009358 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9359 // messages in the handshake queue. Do this by testing the server
9360 // reading the client Finished, reversing the flight so Finished comes
9361 // first.
9362 testCases = append(testCases, testCase{
9363 protocol: dtls,
9364 testType: serverTest,
9365 name: "SendUnencryptedFinished-DTLS",
9366 config: Config{
9367 MaxVersion: VersionTLS12,
9368 Bugs: ProtocolBugs{
9369 SendUnencryptedFinished: true,
9370 ReverseHandshakeFragments: true,
9371 },
9372 },
9373 shouldFail: true,
9374 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9375 })
9376
Steven Valdez143e8b32016-07-11 13:19:03 -04009377 // Test synchronization between encryption changes and the handshake in
9378 // TLS 1.3, where ChangeCipherSpec is implicit.
9379 testCases = append(testCases, testCase{
9380 name: "PartialEncryptedExtensionsWithServerHello",
9381 config: Config{
9382 MaxVersion: VersionTLS13,
9383 Bugs: ProtocolBugs{
9384 PartialEncryptedExtensionsWithServerHello: true,
9385 },
9386 },
9387 shouldFail: true,
9388 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9389 })
9390 testCases = append(testCases, testCase{
9391 testType: serverTest,
9392 name: "PartialClientFinishedWithClientHello",
9393 config: Config{
9394 MaxVersion: VersionTLS13,
9395 Bugs: ProtocolBugs{
9396 PartialClientFinishedWithClientHello: true,
9397 },
9398 },
9399 shouldFail: true,
9400 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9401 })
9402
David Benjamin82261be2016-07-07 14:32:50 -07009403 // Test that early ChangeCipherSpecs are handled correctly.
9404 testCases = append(testCases, testCase{
9405 testType: serverTest,
9406 name: "EarlyChangeCipherSpec-server-1",
9407 config: Config{
9408 MaxVersion: VersionTLS12,
9409 Bugs: ProtocolBugs{
9410 EarlyChangeCipherSpec: 1,
9411 },
9412 },
9413 shouldFail: true,
9414 expectedError: ":UNEXPECTED_RECORD:",
9415 })
9416 testCases = append(testCases, testCase{
9417 testType: serverTest,
9418 name: "EarlyChangeCipherSpec-server-2",
9419 config: Config{
9420 MaxVersion: VersionTLS12,
9421 Bugs: ProtocolBugs{
9422 EarlyChangeCipherSpec: 2,
9423 },
9424 },
9425 shouldFail: true,
9426 expectedError: ":UNEXPECTED_RECORD:",
9427 })
9428 testCases = append(testCases, testCase{
9429 protocol: dtls,
9430 name: "StrayChangeCipherSpec",
9431 config: Config{
9432 // TODO(davidben): Once DTLS 1.3 exists, test
9433 // that stray ChangeCipherSpec messages are
9434 // rejected.
9435 MaxVersion: VersionTLS12,
9436 Bugs: ProtocolBugs{
9437 StrayChangeCipherSpec: true,
9438 },
9439 },
9440 })
9441
9442 // Test that the contents of ChangeCipherSpec are checked.
9443 testCases = append(testCases, testCase{
9444 name: "BadChangeCipherSpec-1",
9445 config: Config{
9446 MaxVersion: VersionTLS12,
9447 Bugs: ProtocolBugs{
9448 BadChangeCipherSpec: []byte{2},
9449 },
9450 },
9451 shouldFail: true,
9452 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9453 })
9454 testCases = append(testCases, testCase{
9455 name: "BadChangeCipherSpec-2",
9456 config: Config{
9457 MaxVersion: VersionTLS12,
9458 Bugs: ProtocolBugs{
9459 BadChangeCipherSpec: []byte{1, 1},
9460 },
9461 },
9462 shouldFail: true,
9463 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9464 })
9465 testCases = append(testCases, testCase{
9466 protocol: dtls,
9467 name: "BadChangeCipherSpec-DTLS-1",
9468 config: Config{
9469 MaxVersion: VersionTLS12,
9470 Bugs: ProtocolBugs{
9471 BadChangeCipherSpec: []byte{2},
9472 },
9473 },
9474 shouldFail: true,
9475 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9476 })
9477 testCases = append(testCases, testCase{
9478 protocol: dtls,
9479 name: "BadChangeCipherSpec-DTLS-2",
9480 config: Config{
9481 MaxVersion: VersionTLS12,
9482 Bugs: ProtocolBugs{
9483 BadChangeCipherSpec: []byte{1, 1},
9484 },
9485 },
9486 shouldFail: true,
9487 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9488 })
9489}
9490
David Benjamincd2c8062016-09-09 11:28:16 -04009491type perMessageTest struct {
9492 messageType uint8
9493 test testCase
9494}
9495
9496// makePerMessageTests returns a series of test templates which cover each
9497// message in the TLS handshake. These may be used with bugs like
9498// WrongMessageType to fully test a per-message bug.
9499func makePerMessageTests() []perMessageTest {
9500 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009501 for _, protocol := range []protocol{tls, dtls} {
9502 var suffix string
9503 if protocol == dtls {
9504 suffix = "-DTLS"
9505 }
9506
David Benjamincd2c8062016-09-09 11:28:16 -04009507 ret = append(ret, perMessageTest{
9508 messageType: typeClientHello,
9509 test: testCase{
9510 protocol: protocol,
9511 testType: serverTest,
9512 name: "ClientHello" + suffix,
9513 config: Config{
9514 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009515 },
9516 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009517 })
9518
9519 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009520 ret = append(ret, perMessageTest{
9521 messageType: typeHelloVerifyRequest,
9522 test: testCase{
9523 protocol: protocol,
9524 name: "HelloVerifyRequest" + suffix,
9525 config: Config{
9526 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009527 },
9528 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009529 })
9530 }
9531
David Benjamincd2c8062016-09-09 11:28:16 -04009532 ret = append(ret, perMessageTest{
9533 messageType: typeServerHello,
9534 test: testCase{
9535 protocol: protocol,
9536 name: "ServerHello" + suffix,
9537 config: Config{
9538 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009539 },
9540 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009541 })
9542
David Benjamincd2c8062016-09-09 11:28:16 -04009543 ret = append(ret, perMessageTest{
9544 messageType: typeCertificate,
9545 test: testCase{
9546 protocol: protocol,
9547 name: "ServerCertificate" + suffix,
9548 config: Config{
9549 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009550 },
9551 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009552 })
9553
David Benjamincd2c8062016-09-09 11:28:16 -04009554 ret = append(ret, perMessageTest{
9555 messageType: typeCertificateStatus,
9556 test: testCase{
9557 protocol: protocol,
9558 name: "CertificateStatus" + suffix,
9559 config: Config{
9560 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009561 },
David Benjamincd2c8062016-09-09 11:28:16 -04009562 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009563 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009564 })
9565
David Benjamincd2c8062016-09-09 11:28:16 -04009566 ret = append(ret, perMessageTest{
9567 messageType: typeServerKeyExchange,
9568 test: testCase{
9569 protocol: protocol,
9570 name: "ServerKeyExchange" + suffix,
9571 config: Config{
9572 MaxVersion: VersionTLS12,
9573 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009574 },
9575 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009576 })
9577
David Benjamincd2c8062016-09-09 11:28:16 -04009578 ret = append(ret, perMessageTest{
9579 messageType: typeCertificateRequest,
9580 test: testCase{
9581 protocol: protocol,
9582 name: "CertificateRequest" + suffix,
9583 config: Config{
9584 MaxVersion: VersionTLS12,
9585 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009586 },
9587 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009588 })
9589
David Benjamincd2c8062016-09-09 11:28:16 -04009590 ret = append(ret, perMessageTest{
9591 messageType: typeServerHelloDone,
9592 test: testCase{
9593 protocol: protocol,
9594 name: "ServerHelloDone" + suffix,
9595 config: Config{
9596 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009597 },
9598 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009599 })
9600
David Benjamincd2c8062016-09-09 11:28:16 -04009601 ret = append(ret, perMessageTest{
9602 messageType: typeCertificate,
9603 test: testCase{
9604 testType: serverTest,
9605 protocol: protocol,
9606 name: "ClientCertificate" + suffix,
9607 config: Config{
9608 Certificates: []Certificate{rsaCertificate},
9609 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009610 },
David Benjamincd2c8062016-09-09 11:28:16 -04009611 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009612 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009613 })
9614
David Benjamincd2c8062016-09-09 11:28:16 -04009615 ret = append(ret, perMessageTest{
9616 messageType: typeCertificateVerify,
9617 test: testCase{
9618 testType: serverTest,
9619 protocol: protocol,
9620 name: "CertificateVerify" + suffix,
9621 config: Config{
9622 Certificates: []Certificate{rsaCertificate},
9623 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009624 },
David Benjamincd2c8062016-09-09 11:28:16 -04009625 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009626 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009627 })
9628
David Benjamincd2c8062016-09-09 11:28:16 -04009629 ret = append(ret, perMessageTest{
9630 messageType: typeClientKeyExchange,
9631 test: testCase{
9632 testType: serverTest,
9633 protocol: protocol,
9634 name: "ClientKeyExchange" + suffix,
9635 config: Config{
9636 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009637 },
9638 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009639 })
9640
9641 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009642 ret = append(ret, perMessageTest{
9643 messageType: typeNextProtocol,
9644 test: testCase{
9645 testType: serverTest,
9646 protocol: protocol,
9647 name: "NextProtocol" + suffix,
9648 config: Config{
9649 MaxVersion: VersionTLS12,
9650 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009651 },
David Benjamincd2c8062016-09-09 11:28:16 -04009652 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009653 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009654 })
9655
David Benjamincd2c8062016-09-09 11:28:16 -04009656 ret = append(ret, perMessageTest{
9657 messageType: typeChannelID,
9658 test: testCase{
9659 testType: serverTest,
9660 protocol: protocol,
9661 name: "ChannelID" + suffix,
9662 config: Config{
9663 MaxVersion: VersionTLS12,
9664 ChannelID: channelIDKey,
9665 },
9666 flags: []string{
9667 "-expect-channel-id",
9668 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009669 },
9670 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009671 })
9672 }
9673
David Benjamincd2c8062016-09-09 11:28:16 -04009674 ret = append(ret, perMessageTest{
9675 messageType: typeFinished,
9676 test: testCase{
9677 testType: serverTest,
9678 protocol: protocol,
9679 name: "ClientFinished" + suffix,
9680 config: Config{
9681 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009682 },
9683 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009684 })
9685
David Benjamincd2c8062016-09-09 11:28:16 -04009686 ret = append(ret, perMessageTest{
9687 messageType: typeNewSessionTicket,
9688 test: testCase{
9689 protocol: protocol,
9690 name: "NewSessionTicket" + suffix,
9691 config: Config{
9692 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009693 },
9694 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009695 })
9696
David Benjamincd2c8062016-09-09 11:28:16 -04009697 ret = append(ret, perMessageTest{
9698 messageType: typeFinished,
9699 test: testCase{
9700 protocol: protocol,
9701 name: "ServerFinished" + suffix,
9702 config: Config{
9703 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009704 },
9705 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009706 })
9707
9708 }
David Benjamincd2c8062016-09-09 11:28:16 -04009709
9710 ret = append(ret, perMessageTest{
9711 messageType: typeClientHello,
9712 test: testCase{
9713 testType: serverTest,
9714 name: "TLS13-ClientHello",
9715 config: Config{
9716 MaxVersion: VersionTLS13,
9717 },
9718 },
9719 })
9720
9721 ret = append(ret, perMessageTest{
9722 messageType: typeServerHello,
9723 test: testCase{
9724 name: "TLS13-ServerHello",
9725 config: Config{
9726 MaxVersion: VersionTLS13,
9727 },
9728 },
9729 })
9730
9731 ret = append(ret, perMessageTest{
9732 messageType: typeEncryptedExtensions,
9733 test: testCase{
9734 name: "TLS13-EncryptedExtensions",
9735 config: Config{
9736 MaxVersion: VersionTLS13,
9737 },
9738 },
9739 })
9740
9741 ret = append(ret, perMessageTest{
9742 messageType: typeCertificateRequest,
9743 test: testCase{
9744 name: "TLS13-CertificateRequest",
9745 config: Config{
9746 MaxVersion: VersionTLS13,
9747 ClientAuth: RequireAnyClientCert,
9748 },
9749 },
9750 })
9751
9752 ret = append(ret, perMessageTest{
9753 messageType: typeCertificate,
9754 test: testCase{
9755 name: "TLS13-ServerCertificate",
9756 config: Config{
9757 MaxVersion: VersionTLS13,
9758 },
9759 },
9760 })
9761
9762 ret = append(ret, perMessageTest{
9763 messageType: typeCertificateVerify,
9764 test: testCase{
9765 name: "TLS13-ServerCertificateVerify",
9766 config: Config{
9767 MaxVersion: VersionTLS13,
9768 },
9769 },
9770 })
9771
9772 ret = append(ret, perMessageTest{
9773 messageType: typeFinished,
9774 test: testCase{
9775 name: "TLS13-ServerFinished",
9776 config: Config{
9777 MaxVersion: VersionTLS13,
9778 },
9779 },
9780 })
9781
9782 ret = append(ret, perMessageTest{
9783 messageType: typeCertificate,
9784 test: testCase{
9785 testType: serverTest,
9786 name: "TLS13-ClientCertificate",
9787 config: Config{
9788 Certificates: []Certificate{rsaCertificate},
9789 MaxVersion: VersionTLS13,
9790 },
9791 flags: []string{"-require-any-client-certificate"},
9792 },
9793 })
9794
9795 ret = append(ret, perMessageTest{
9796 messageType: typeCertificateVerify,
9797 test: testCase{
9798 testType: serverTest,
9799 name: "TLS13-ClientCertificateVerify",
9800 config: Config{
9801 Certificates: []Certificate{rsaCertificate},
9802 MaxVersion: VersionTLS13,
9803 },
9804 flags: []string{"-require-any-client-certificate"},
9805 },
9806 })
9807
9808 ret = append(ret, perMessageTest{
9809 messageType: typeFinished,
9810 test: testCase{
9811 testType: serverTest,
9812 name: "TLS13-ClientFinished",
9813 config: Config{
9814 MaxVersion: VersionTLS13,
9815 },
9816 },
9817 })
9818
9819 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009820}
9821
David Benjamincd2c8062016-09-09 11:28:16 -04009822func addWrongMessageTypeTests() {
9823 for _, t := range makePerMessageTests() {
9824 t.test.name = "WrongMessageType-" + t.test.name
9825 t.test.config.Bugs.SendWrongMessageType = t.messageType
9826 t.test.shouldFail = true
9827 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9828 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009829
David Benjamincd2c8062016-09-09 11:28:16 -04009830 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9831 // In TLS 1.3, a bad ServerHello means the client sends
9832 // an unencrypted alert while the server expects
9833 // encryption, so the alert is not readable by runner.
9834 t.test.expectedLocalError = "local error: bad record MAC"
9835 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009836
David Benjamincd2c8062016-09-09 11:28:16 -04009837 testCases = append(testCases, t.test)
9838 }
David Benjaminebacdee2017-04-08 11:00:45 -04009839
9840 // The processing order for TLS 1.3 version negotiation is such that one
9841 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
9842 // TLS 1.2. Test that we do not do this.
9843 testCases = append(testCases, testCase{
9844 name: "SendServerHelloAsHelloRetryRequest",
9845 config: Config{
9846 MaxVersion: VersionTLS12,
9847 Bugs: ProtocolBugs{
9848 SendServerHelloAsHelloRetryRequest: true,
9849 },
9850 },
9851 shouldFail: true,
9852 expectedError: ":UNEXPECTED_MESSAGE:",
9853 expectedLocalError: "remote error: unexpected message",
9854 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009855}
9856
David Benjamin639846e2016-09-09 11:41:18 -04009857func addTrailingMessageDataTests() {
9858 for _, t := range makePerMessageTests() {
9859 t.test.name = "TrailingMessageData-" + t.test.name
9860 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9861 t.test.shouldFail = true
9862 t.test.expectedError = ":DECODE_ERROR:"
9863 t.test.expectedLocalError = "remote error: error decoding message"
9864
9865 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9866 // In TLS 1.3, a bad ServerHello means the client sends
9867 // an unencrypted alert while the server expects
9868 // encryption, so the alert is not readable by runner.
9869 t.test.expectedLocalError = "local error: bad record MAC"
9870 }
9871
9872 if t.messageType == typeFinished {
9873 // Bad Finished messages read as the verify data having
9874 // the wrong length.
9875 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9876 t.test.expectedLocalError = "remote error: error decrypting message"
9877 }
9878
9879 testCases = append(testCases, t.test)
9880 }
9881}
9882
Steven Valdez143e8b32016-07-11 13:19:03 -04009883func addTLS13HandshakeTests() {
9884 testCases = append(testCases, testCase{
9885 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009886 name: "NegotiatePSKResumption-TLS13",
9887 config: Config{
9888 MaxVersion: VersionTLS13,
9889 Bugs: ProtocolBugs{
9890 NegotiatePSKResumption: true,
9891 },
9892 },
9893 resumeSession: true,
9894 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009895 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009896 })
9897
9898 testCases = append(testCases, testCase{
9899 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009900 name: "MissingKeyShare-Client",
9901 config: Config{
9902 MaxVersion: VersionTLS13,
9903 Bugs: ProtocolBugs{
9904 MissingKeyShare: true,
9905 },
9906 },
9907 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009908 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009909 })
9910
9911 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009912 testType: serverTest,
9913 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009914 config: Config{
9915 MaxVersion: VersionTLS13,
9916 Bugs: ProtocolBugs{
9917 MissingKeyShare: true,
9918 },
9919 },
9920 shouldFail: true,
9921 expectedError: ":MISSING_KEY_SHARE:",
9922 })
9923
9924 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009925 testType: serverTest,
9926 name: "DuplicateKeyShares",
9927 config: Config{
9928 MaxVersion: VersionTLS13,
9929 Bugs: ProtocolBugs{
9930 DuplicateKeyShares: true,
9931 },
9932 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009933 shouldFail: true,
9934 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009935 })
9936
9937 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009938 testType: serverTest,
9939 name: "SkipEarlyData",
9940 config: Config{
9941 MaxVersion: VersionTLS13,
9942 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009943 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009944 },
9945 },
9946 })
9947
9948 testCases = append(testCases, testCase{
9949 testType: serverTest,
9950 name: "SkipEarlyData-OmitEarlyDataExtension",
9951 config: Config{
9952 MaxVersion: VersionTLS13,
9953 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009954 SendFakeEarlyDataLength: 4,
9955 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009956 },
9957 },
9958 shouldFail: true,
9959 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9960 })
9961
9962 testCases = append(testCases, testCase{
9963 testType: serverTest,
9964 name: "SkipEarlyData-TooMuchData",
9965 config: Config{
9966 MaxVersion: VersionTLS13,
9967 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009968 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009969 },
9970 },
9971 shouldFail: true,
9972 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9973 })
9974
9975 testCases = append(testCases, testCase{
9976 testType: serverTest,
9977 name: "SkipEarlyData-Interleaved",
9978 config: Config{
9979 MaxVersion: VersionTLS13,
9980 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009981 SendFakeEarlyDataLength: 4,
9982 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009983 },
9984 },
9985 shouldFail: true,
9986 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9987 })
9988
9989 testCases = append(testCases, testCase{
9990 testType: serverTest,
9991 name: "SkipEarlyData-EarlyDataInTLS12",
9992 config: Config{
9993 MaxVersion: VersionTLS13,
9994 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009995 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009996 },
9997 },
9998 shouldFail: true,
9999 expectedError: ":UNEXPECTED_RECORD:",
10000 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10001 })
10002
10003 testCases = append(testCases, testCase{
10004 testType: serverTest,
10005 name: "SkipEarlyData-HRR",
10006 config: Config{
10007 MaxVersion: VersionTLS13,
10008 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010009 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010010 },
10011 DefaultCurves: []CurveID{},
10012 },
10013 })
10014
10015 testCases = append(testCases, testCase{
10016 testType: serverTest,
10017 name: "SkipEarlyData-HRR-Interleaved",
10018 config: Config{
10019 MaxVersion: VersionTLS13,
10020 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010021 SendFakeEarlyDataLength: 4,
10022 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010023 },
10024 DefaultCurves: []CurveID{},
10025 },
10026 shouldFail: true,
10027 expectedError: ":UNEXPECTED_RECORD:",
10028 })
10029
10030 testCases = append(testCases, testCase{
10031 testType: serverTest,
10032 name: "SkipEarlyData-HRR-TooMuchData",
10033 config: Config{
10034 MaxVersion: VersionTLS13,
10035 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010036 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010037 },
10038 DefaultCurves: []CurveID{},
10039 },
10040 shouldFail: true,
10041 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10042 })
10043
10044 // Test that skipping early data looking for cleartext correctly
10045 // processes an alert record.
10046 testCases = append(testCases, testCase{
10047 testType: serverTest,
10048 name: "SkipEarlyData-HRR-FatalAlert",
10049 config: Config{
10050 MaxVersion: VersionTLS13,
10051 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010052 SendEarlyAlert: true,
10053 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010054 },
10055 DefaultCurves: []CurveID{},
10056 },
10057 shouldFail: true,
10058 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10059 })
10060
10061 testCases = append(testCases, testCase{
10062 testType: serverTest,
10063 name: "SkipEarlyData-SecondClientHelloEarlyData",
10064 config: Config{
10065 MaxVersion: VersionTLS13,
10066 Bugs: ProtocolBugs{
10067 SendEarlyDataOnSecondClientHello: true,
10068 },
10069 DefaultCurves: []CurveID{},
10070 },
10071 shouldFail: true,
10072 expectedLocalError: "remote error: bad record MAC",
10073 })
10074
10075 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010076 testType: clientTest,
10077 name: "EmptyEncryptedExtensions",
10078 config: Config{
10079 MaxVersion: VersionTLS13,
10080 Bugs: ProtocolBugs{
10081 EmptyEncryptedExtensions: true,
10082 },
10083 },
10084 shouldFail: true,
10085 expectedLocalError: "remote error: error decoding message",
10086 })
10087
10088 testCases = append(testCases, testCase{
10089 testType: clientTest,
10090 name: "EncryptedExtensionsWithKeyShare",
10091 config: Config{
10092 MaxVersion: VersionTLS13,
10093 Bugs: ProtocolBugs{
10094 EncryptedExtensionsWithKeyShare: true,
10095 },
10096 },
10097 shouldFail: true,
10098 expectedLocalError: "remote error: unsupported extension",
10099 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010100
10101 testCases = append(testCases, testCase{
10102 testType: serverTest,
10103 name: "SendHelloRetryRequest",
10104 config: Config{
10105 MaxVersion: VersionTLS13,
10106 // Require a HelloRetryRequest for every curve.
10107 DefaultCurves: []CurveID{},
10108 },
10109 expectedCurveID: CurveX25519,
10110 })
10111
10112 testCases = append(testCases, testCase{
10113 testType: serverTest,
10114 name: "SendHelloRetryRequest-2",
10115 config: Config{
10116 MaxVersion: VersionTLS13,
10117 DefaultCurves: []CurveID{CurveP384},
10118 },
10119 // Although the ClientHello did not predict our preferred curve,
10120 // we always select it whether it is predicted or not.
10121 expectedCurveID: CurveX25519,
10122 })
10123
10124 testCases = append(testCases, testCase{
10125 name: "UnknownCurve-HelloRetryRequest",
10126 config: Config{
10127 MaxVersion: VersionTLS13,
10128 // P-384 requires HelloRetryRequest in BoringSSL.
10129 CurvePreferences: []CurveID{CurveP384},
10130 Bugs: ProtocolBugs{
10131 SendHelloRetryRequestCurve: bogusCurve,
10132 },
10133 },
10134 shouldFail: true,
10135 expectedError: ":WRONG_CURVE:",
10136 })
10137
10138 testCases = append(testCases, testCase{
10139 name: "DisabledCurve-HelloRetryRequest",
10140 config: Config{
10141 MaxVersion: VersionTLS13,
10142 CurvePreferences: []CurveID{CurveP256},
10143 Bugs: ProtocolBugs{
10144 IgnorePeerCurvePreferences: true,
10145 },
10146 },
10147 flags: []string{"-p384-only"},
10148 shouldFail: true,
10149 expectedError: ":WRONG_CURVE:",
10150 })
10151
10152 testCases = append(testCases, testCase{
10153 name: "UnnecessaryHelloRetryRequest",
10154 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010155 MaxVersion: VersionTLS13,
10156 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010157 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010158 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010159 },
10160 },
10161 shouldFail: true,
10162 expectedError: ":WRONG_CURVE:",
10163 })
10164
10165 testCases = append(testCases, testCase{
10166 name: "SecondHelloRetryRequest",
10167 config: Config{
10168 MaxVersion: VersionTLS13,
10169 // P-384 requires HelloRetryRequest in BoringSSL.
10170 CurvePreferences: []CurveID{CurveP384},
10171 Bugs: ProtocolBugs{
10172 SecondHelloRetryRequest: true,
10173 },
10174 },
10175 shouldFail: true,
10176 expectedError: ":UNEXPECTED_MESSAGE:",
10177 })
10178
10179 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010180 name: "HelloRetryRequest-Empty",
10181 config: Config{
10182 MaxVersion: VersionTLS13,
10183 Bugs: ProtocolBugs{
10184 AlwaysSendHelloRetryRequest: true,
10185 },
10186 },
10187 shouldFail: true,
10188 expectedError: ":DECODE_ERROR:",
10189 })
10190
10191 testCases = append(testCases, testCase{
10192 name: "HelloRetryRequest-DuplicateCurve",
10193 config: Config{
10194 MaxVersion: VersionTLS13,
10195 // P-384 requires a HelloRetryRequest against BoringSSL's default
10196 // configuration. Assert this ExpectMissingKeyShare.
10197 CurvePreferences: []CurveID{CurveP384},
10198 Bugs: ProtocolBugs{
10199 ExpectMissingKeyShare: true,
10200 DuplicateHelloRetryRequestExtensions: true,
10201 },
10202 },
10203 shouldFail: true,
10204 expectedError: ":DUPLICATE_EXTENSION:",
10205 expectedLocalError: "remote error: illegal parameter",
10206 })
10207
10208 testCases = append(testCases, testCase{
10209 name: "HelloRetryRequest-Cookie",
10210 config: Config{
10211 MaxVersion: VersionTLS13,
10212 Bugs: ProtocolBugs{
10213 SendHelloRetryRequestCookie: []byte("cookie"),
10214 },
10215 },
10216 })
10217
10218 testCases = append(testCases, testCase{
10219 name: "HelloRetryRequest-DuplicateCookie",
10220 config: Config{
10221 MaxVersion: VersionTLS13,
10222 Bugs: ProtocolBugs{
10223 SendHelloRetryRequestCookie: []byte("cookie"),
10224 DuplicateHelloRetryRequestExtensions: true,
10225 },
10226 },
10227 shouldFail: true,
10228 expectedError: ":DUPLICATE_EXTENSION:",
10229 expectedLocalError: "remote error: illegal parameter",
10230 })
10231
10232 testCases = append(testCases, testCase{
10233 name: "HelloRetryRequest-EmptyCookie",
10234 config: Config{
10235 MaxVersion: VersionTLS13,
10236 Bugs: ProtocolBugs{
10237 SendHelloRetryRequestCookie: []byte{},
10238 },
10239 },
10240 shouldFail: true,
10241 expectedError: ":DECODE_ERROR:",
10242 })
10243
10244 testCases = append(testCases, testCase{
10245 name: "HelloRetryRequest-Cookie-Curve",
10246 config: Config{
10247 MaxVersion: VersionTLS13,
10248 // P-384 requires HelloRetryRequest in BoringSSL.
10249 CurvePreferences: []CurveID{CurveP384},
10250 Bugs: ProtocolBugs{
10251 SendHelloRetryRequestCookie: []byte("cookie"),
10252 ExpectMissingKeyShare: true,
10253 },
10254 },
10255 })
10256
10257 testCases = append(testCases, testCase{
10258 name: "HelloRetryRequest-Unknown",
10259 config: Config{
10260 MaxVersion: VersionTLS13,
10261 Bugs: ProtocolBugs{
10262 CustomHelloRetryRequestExtension: "extension",
10263 },
10264 },
10265 shouldFail: true,
10266 expectedError: ":UNEXPECTED_EXTENSION:",
10267 expectedLocalError: "remote error: unsupported extension",
10268 })
10269
10270 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010271 testType: serverTest,
10272 name: "SecondClientHelloMissingKeyShare",
10273 config: Config{
10274 MaxVersion: VersionTLS13,
10275 DefaultCurves: []CurveID{},
10276 Bugs: ProtocolBugs{
10277 SecondClientHelloMissingKeyShare: true,
10278 },
10279 },
10280 shouldFail: true,
10281 expectedError: ":MISSING_KEY_SHARE:",
10282 })
10283
10284 testCases = append(testCases, testCase{
10285 testType: serverTest,
10286 name: "SecondClientHelloWrongCurve",
10287 config: Config{
10288 MaxVersion: VersionTLS13,
10289 DefaultCurves: []CurveID{},
10290 Bugs: ProtocolBugs{
10291 MisinterpretHelloRetryRequestCurve: CurveP521,
10292 },
10293 },
10294 shouldFail: true,
10295 expectedError: ":WRONG_CURVE:",
10296 })
10297
10298 testCases = append(testCases, testCase{
10299 name: "HelloRetryRequestVersionMismatch",
10300 config: Config{
10301 MaxVersion: VersionTLS13,
10302 // P-384 requires HelloRetryRequest in BoringSSL.
10303 CurvePreferences: []CurveID{CurveP384},
10304 Bugs: ProtocolBugs{
10305 SendServerHelloVersion: 0x0305,
10306 },
10307 },
10308 shouldFail: true,
10309 expectedError: ":WRONG_VERSION_NUMBER:",
10310 })
10311
10312 testCases = append(testCases, testCase{
10313 name: "HelloRetryRequestCurveMismatch",
10314 config: Config{
10315 MaxVersion: VersionTLS13,
10316 // P-384 requires HelloRetryRequest in BoringSSL.
10317 CurvePreferences: []CurveID{CurveP384},
10318 Bugs: ProtocolBugs{
10319 // Send P-384 (correct) in the HelloRetryRequest.
10320 SendHelloRetryRequestCurve: CurveP384,
10321 // But send P-256 in the ServerHello.
10322 SendCurve: CurveP256,
10323 },
10324 },
10325 shouldFail: true,
10326 expectedError: ":WRONG_CURVE:",
10327 })
10328
10329 // Test the server selecting a curve that requires a HelloRetryRequest
10330 // without sending it.
10331 testCases = append(testCases, testCase{
10332 name: "SkipHelloRetryRequest",
10333 config: Config{
10334 MaxVersion: VersionTLS13,
10335 // P-384 requires HelloRetryRequest in BoringSSL.
10336 CurvePreferences: []CurveID{CurveP384},
10337 Bugs: ProtocolBugs{
10338 SkipHelloRetryRequest: true,
10339 },
10340 },
10341 shouldFail: true,
10342 expectedError: ":WRONG_CURVE:",
10343 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010344
10345 testCases = append(testCases, testCase{
10346 name: "TLS13-RequestContextInHandshake",
10347 config: Config{
10348 MaxVersion: VersionTLS13,
10349 MinVersion: VersionTLS13,
10350 ClientAuth: RequireAnyClientCert,
10351 Bugs: ProtocolBugs{
10352 SendRequestContext: []byte("request context"),
10353 },
10354 },
10355 flags: []string{
10356 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10357 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10358 },
10359 shouldFail: true,
10360 expectedError: ":DECODE_ERROR:",
10361 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010362
10363 testCases = append(testCases, testCase{
10364 testType: serverTest,
10365 name: "TLS13-TrailingKeyShareData",
10366 config: Config{
10367 MaxVersion: VersionTLS13,
10368 Bugs: ProtocolBugs{
10369 TrailingKeyShareData: true,
10370 },
10371 },
10372 shouldFail: true,
10373 expectedError: ":DECODE_ERROR:",
10374 })
David Benjamin7f78df42016-10-05 22:33:19 -040010375
10376 testCases = append(testCases, testCase{
10377 name: "TLS13-AlwaysSelectPSKIdentity",
10378 config: Config{
10379 MaxVersion: VersionTLS13,
10380 Bugs: ProtocolBugs{
10381 AlwaysSelectPSKIdentity: true,
10382 },
10383 },
10384 shouldFail: true,
10385 expectedError: ":UNEXPECTED_EXTENSION:",
10386 })
10387
10388 testCases = append(testCases, testCase{
10389 name: "TLS13-InvalidPSKIdentity",
10390 config: Config{
10391 MaxVersion: VersionTLS13,
10392 Bugs: ProtocolBugs{
10393 SelectPSKIdentityOnResume: 1,
10394 },
10395 },
10396 resumeSession: true,
10397 shouldFail: true,
10398 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10399 })
David Benjamin1286bee2016-10-07 15:25:06 -040010400
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010401 testCases = append(testCases, testCase{
10402 testType: serverTest,
10403 name: "TLS13-ExtraPSKIdentity",
10404 config: Config{
10405 MaxVersion: VersionTLS13,
10406 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010407 ExtraPSKIdentity: true,
10408 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010409 },
10410 },
10411 resumeSession: true,
10412 })
10413
David Benjamin1286bee2016-10-07 15:25:06 -040010414 // Test that unknown NewSessionTicket extensions are tolerated.
10415 testCases = append(testCases, testCase{
10416 name: "TLS13-CustomTicketExtension",
10417 config: Config{
10418 MaxVersion: VersionTLS13,
10419 Bugs: ProtocolBugs{
10420 CustomTicketExtension: "1234",
10421 },
10422 },
10423 })
Steven Valdez2d850622017-01-11 11:34:52 -050010424
Steven Valdez2d850622017-01-11 11:34:52 -050010425 testCases = append(testCases, testCase{
10426 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010427 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010428 config: Config{
10429 MaxVersion: VersionTLS13,
10430 MaxEarlyDataSize: 16384,
10431 },
10432 resumeConfig: &Config{
10433 MaxVersion: VersionTLS13,
10434 MaxEarlyDataSize: 16384,
10435 Bugs: ProtocolBugs{
10436 AlwaysRejectEarlyData: true,
10437 },
10438 },
10439 resumeSession: true,
10440 flags: []string{
10441 "-enable-early-data",
10442 "-expect-early-data-info",
10443 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010444 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010445 },
10446 })
10447
10448 testCases = append(testCases, testCase{
10449 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010450 name: "TLS13-EarlyData-RejectTicket-Client",
10451 config: Config{
10452 MaxVersion: VersionTLS13,
10453 MaxEarlyDataSize: 16384,
10454 Certificates: []Certificate{rsaCertificate},
10455 },
10456 resumeConfig: &Config{
10457 MaxVersion: VersionTLS13,
10458 MaxEarlyDataSize: 16384,
10459 Certificates: []Certificate{ecdsaP256Certificate},
10460 SessionTicketsDisabled: true,
10461 },
10462 resumeSession: true,
10463 expectResumeRejected: true,
10464 flags: []string{
10465 "-enable-early-data",
10466 "-expect-early-data-info",
10467 "-expect-reject-early-data",
10468 "-on-resume-shim-writes-first",
10469 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10470 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10471 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10472 // Session tickets are disabled, so the runner will not send a ticket.
10473 "-on-retry-expect-no-session",
10474 },
10475 })
10476
10477 testCases = append(testCases, testCase{
10478 testType: clientTest,
10479 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010480 config: Config{
10481 MaxVersion: VersionTLS13,
10482 MaxEarlyDataSize: 16384,
10483 },
10484 resumeConfig: &Config{
10485 MaxVersion: VersionTLS13,
10486 MaxEarlyDataSize: 16384,
10487 Bugs: ProtocolBugs{
10488 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10489 },
10490 },
10491 resumeSession: true,
10492 flags: []string{
10493 "-enable-early-data",
10494 "-expect-early-data-info",
10495 "-expect-reject-early-data",
10496 },
10497 })
10498
10499 // The client must check the server does not send the early_data
10500 // extension while rejecting the session.
10501 testCases = append(testCases, testCase{
10502 testType: clientTest,
10503 name: "TLS13-EarlyDataWithoutResume-Client",
10504 config: Config{
10505 MaxVersion: VersionTLS13,
10506 MaxEarlyDataSize: 16384,
10507 },
10508 resumeConfig: &Config{
10509 MaxVersion: VersionTLS13,
10510 SessionTicketsDisabled: true,
10511 Bugs: ProtocolBugs{
10512 SendEarlyDataExtension: true,
10513 },
10514 },
10515 resumeSession: true,
10516 flags: []string{
10517 "-enable-early-data",
10518 "-expect-early-data-info",
10519 },
10520 shouldFail: true,
10521 expectedError: ":UNEXPECTED_EXTENSION:",
10522 })
10523
10524 // The client must fail with a dedicated error code if the server
10525 // responds with TLS 1.2 when offering 0-RTT.
10526 testCases = append(testCases, testCase{
10527 testType: clientTest,
10528 name: "TLS13-EarlyDataVersionDowngrade-Client",
10529 config: Config{
10530 MaxVersion: VersionTLS13,
10531 MaxEarlyDataSize: 16384,
10532 },
10533 resumeConfig: &Config{
10534 MaxVersion: VersionTLS12,
10535 },
10536 resumeSession: true,
10537 flags: []string{
10538 "-enable-early-data",
10539 "-expect-early-data-info",
10540 },
10541 shouldFail: true,
10542 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10543 })
10544
10545 // Test that the client rejects an (unsolicited) early_data extension if
10546 // the server sent an HRR.
10547 testCases = append(testCases, testCase{
10548 testType: clientTest,
10549 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10550 config: Config{
10551 MaxVersion: VersionTLS13,
10552 MaxEarlyDataSize: 16384,
10553 },
10554 resumeConfig: &Config{
10555 MaxVersion: VersionTLS13,
10556 MaxEarlyDataSize: 16384,
10557 Bugs: ProtocolBugs{
10558 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10559 SendEarlyDataExtension: true,
10560 },
10561 },
10562 resumeSession: true,
10563 flags: []string{
10564 "-enable-early-data",
10565 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010566 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010567 },
10568 shouldFail: true,
10569 expectedError: ":UNEXPECTED_EXTENSION:",
10570 })
10571
10572 fooString := "foo"
10573 barString := "bar"
10574
10575 // Test that the client reports the correct ALPN after a 0-RTT reject
10576 // that changed it.
10577 testCases = append(testCases, testCase{
10578 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010579 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010580 config: Config{
10581 MaxVersion: VersionTLS13,
10582 MaxEarlyDataSize: 16384,
10583 Bugs: ProtocolBugs{
10584 ALPNProtocol: &fooString,
10585 },
10586 },
10587 resumeConfig: &Config{
10588 MaxVersion: VersionTLS13,
10589 MaxEarlyDataSize: 16384,
10590 Bugs: ProtocolBugs{
10591 ALPNProtocol: &barString,
10592 },
10593 },
10594 resumeSession: true,
10595 flags: []string{
10596 "-advertise-alpn", "\x03foo\x03bar",
10597 "-enable-early-data",
10598 "-expect-early-data-info",
10599 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010600 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010601 "-on-resume-expect-alpn", "foo",
10602 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010603 },
10604 })
10605
10606 // Test that the client reports the correct ALPN after a 0-RTT reject if
10607 // ALPN was omitted from the first connection.
10608 testCases = append(testCases, testCase{
10609 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010610 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010611 config: Config{
10612 MaxVersion: VersionTLS13,
10613 MaxEarlyDataSize: 16384,
10614 },
10615 resumeConfig: &Config{
10616 MaxVersion: VersionTLS13,
10617 MaxEarlyDataSize: 16384,
10618 NextProtos: []string{"foo"},
10619 },
10620 resumeSession: true,
10621 flags: []string{
10622 "-advertise-alpn", "\x03foo\x03bar",
10623 "-enable-early-data",
10624 "-expect-early-data-info",
10625 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010626 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010627 "-on-resume-expect-alpn", "",
10628 "-on-retry-expect-alpn", "foo",
10629 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010630 },
10631 })
10632
10633 // Test that the client reports the correct ALPN after a 0-RTT reject if
10634 // ALPN was omitted from the second connection.
10635 testCases = append(testCases, testCase{
10636 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010637 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010638 config: Config{
10639 MaxVersion: VersionTLS13,
10640 MaxEarlyDataSize: 16384,
10641 NextProtos: []string{"foo"},
10642 },
10643 resumeConfig: &Config{
10644 MaxVersion: VersionTLS13,
10645 MaxEarlyDataSize: 16384,
10646 },
10647 resumeSession: true,
10648 flags: []string{
10649 "-advertise-alpn", "\x03foo\x03bar",
10650 "-enable-early-data",
10651 "-expect-early-data-info",
10652 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010653 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010654 "-on-resume-expect-alpn", "foo",
10655 "-on-retry-expect-alpn", "",
10656 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010657 },
10658 })
10659
10660 // Test that the client enforces ALPN match on 0-RTT accept.
10661 testCases = append(testCases, testCase{
10662 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010663 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010664 config: Config{
10665 MaxVersion: VersionTLS13,
10666 MaxEarlyDataSize: 16384,
10667 Bugs: ProtocolBugs{
10668 ALPNProtocol: &fooString,
10669 },
10670 },
10671 resumeConfig: &Config{
10672 MaxVersion: VersionTLS13,
10673 MaxEarlyDataSize: 16384,
10674 Bugs: ProtocolBugs{
10675 AlwaysAcceptEarlyData: true,
10676 ALPNProtocol: &barString,
10677 },
10678 },
10679 resumeSession: true,
10680 flags: []string{
10681 "-advertise-alpn", "\x03foo\x03bar",
10682 "-enable-early-data",
10683 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010684 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010685 "-on-resume-expect-alpn", "foo",
10686 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010687 },
10688 shouldFail: true,
10689 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10690 })
10691
10692 // Test that the server correctly rejects 0-RTT when the previous
10693 // session did not allow early data on resumption.
10694 testCases = append(testCases, testCase{
10695 testType: serverTest,
10696 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10697 config: Config{
10698 MaxVersion: VersionTLS13,
10699 },
10700 resumeConfig: &Config{
10701 MaxVersion: VersionTLS13,
10702 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010703 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010704 ExpectEarlyDataAccepted: false,
10705 },
10706 },
10707 resumeSession: true,
10708 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010709 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010710 "-expect-reject-early-data",
10711 },
10712 })
10713
10714 // Test that we reject early data where ALPN is omitted from the first
10715 // connection.
10716 testCases = append(testCases, testCase{
10717 testType: serverTest,
10718 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10719 config: Config{
10720 MaxVersion: VersionTLS13,
10721 NextProtos: []string{},
10722 },
10723 resumeConfig: &Config{
10724 MaxVersion: VersionTLS13,
10725 NextProtos: []string{"foo"},
10726 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010727 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010728 ExpectEarlyDataAccepted: false,
10729 },
10730 },
10731 resumeSession: true,
10732 flags: []string{
10733 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010734 "-on-initial-select-alpn", "",
10735 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010736 },
10737 })
10738
10739 // Test that we reject early data where ALPN is omitted from the second
10740 // connection.
10741 testCases = append(testCases, testCase{
10742 testType: serverTest,
10743 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10744 config: Config{
10745 MaxVersion: VersionTLS13,
10746 NextProtos: []string{"foo"},
10747 },
10748 resumeConfig: &Config{
10749 MaxVersion: VersionTLS13,
10750 NextProtos: []string{},
10751 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010752 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010753 ExpectEarlyDataAccepted: false,
10754 },
10755 },
10756 resumeSession: true,
10757 flags: []string{
10758 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010759 "-on-initial-select-alpn", "foo",
10760 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010761 },
10762 })
10763
10764 // Test that we reject early data with mismatched ALPN.
10765 testCases = append(testCases, testCase{
10766 testType: serverTest,
10767 name: "TLS13-EarlyData-ALPNMismatch-Server",
10768 config: Config{
10769 MaxVersion: VersionTLS13,
10770 NextProtos: []string{"foo"},
10771 },
10772 resumeConfig: &Config{
10773 MaxVersion: VersionTLS13,
10774 NextProtos: []string{"bar"},
10775 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010776 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010777 ExpectEarlyDataAccepted: false,
10778 },
10779 },
10780 resumeSession: true,
10781 flags: []string{
10782 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010783 "-on-initial-select-alpn", "foo",
10784 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010785 },
10786 })
10787
David Benjamin6bb507b2017-03-29 16:35:57 -050010788 // Test that the client offering 0-RTT and Channel ID forbids the server
10789 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010790 testCases = append(testCases, testCase{
10791 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010792 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010793 config: Config{
10794 MaxVersion: VersionTLS13,
10795 MaxEarlyDataSize: 16384,
10796 RequestChannelID: true,
10797 },
10798 resumeSession: true,
10799 expectChannelID: true,
10800 shouldFail: true,
10801 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10802 flags: []string{
10803 "-enable-early-data",
10804 "-expect-early-data-info",
10805 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10806 },
10807 })
10808
David Benjamin6bb507b2017-03-29 16:35:57 -050010809 // Test that the client offering Channel ID and 0-RTT allows the server
10810 // to decline 0-RTT.
10811 testCases = append(testCases, testCase{
10812 testType: clientTest,
10813 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10814 config: Config{
10815 MaxVersion: VersionTLS13,
10816 MaxEarlyDataSize: 16384,
10817 RequestChannelID: true,
10818 Bugs: ProtocolBugs{
10819 AlwaysRejectEarlyData: true,
10820 },
10821 },
10822 resumeSession: true,
10823 expectChannelID: true,
10824 flags: []string{
10825 "-enable-early-data",
10826 "-expect-early-data-info",
10827 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10828 "-expect-reject-early-data",
10829 },
10830 })
10831
10832 // Test that the client offering Channel ID and 0-RTT allows the server
10833 // to decline Channel ID.
10834 testCases = append(testCases, testCase{
10835 testType: clientTest,
10836 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10837 config: Config{
10838 MaxVersion: VersionTLS13,
10839 MaxEarlyDataSize: 16384,
10840 },
10841 resumeSession: true,
10842 flags: []string{
10843 "-enable-early-data",
10844 "-expect-early-data-info",
10845 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10846 "-expect-accept-early-data",
10847 },
10848 })
10849
10850 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
10851 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050010852 testCases = append(testCases, testCase{
10853 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010854 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050010855 config: Config{
10856 MaxVersion: VersionTLS13,
10857 ChannelID: channelIDKey,
10858 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050010859 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050010860 ExpectEarlyDataAccepted: false,
10861 },
10862 },
10863 resumeSession: true,
10864 expectChannelID: true,
10865 flags: []string{
10866 "-enable-early-data",
10867 "-expect-reject-early-data",
10868 "-expect-channel-id",
10869 base64.StdEncoding.EncodeToString(channelIDBytes),
10870 },
10871 })
10872
David Benjamin6bb507b2017-03-29 16:35:57 -050010873 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
10874 // if not offered Channel ID.
10875 testCases = append(testCases, testCase{
10876 testType: serverTest,
10877 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
10878 config: Config{
10879 MaxVersion: VersionTLS13,
10880 Bugs: ProtocolBugs{
10881 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10882 ExpectEarlyDataAccepted: true,
10883 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10884 },
10885 },
10886 resumeSession: true,
10887 expectChannelID: false,
10888 flags: []string{
10889 "-enable-early-data",
10890 "-expect-accept-early-data",
10891 "-enable-channel-id",
10892 },
10893 })
10894
David Benjamin32c89272017-03-26 13:54:21 -050010895 // Test that the server rejects 0-RTT streams without end_of_early_data.
10896 // The subsequent records should fail to decrypt.
10897 testCases = append(testCases, testCase{
10898 testType: serverTest,
10899 name: "TLS13-EarlyData-SkipEndOfEarlyData",
10900 config: Config{
10901 MaxVersion: VersionTLS13,
10902 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010903 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050010904 ExpectEarlyDataAccepted: true,
10905 SkipEndOfEarlyData: true,
10906 },
10907 },
10908 resumeSession: true,
10909 flags: []string{"-enable-early-data"},
10910 shouldFail: true,
10911 expectedLocalError: "remote error: bad record MAC",
10912 expectedError: ":BAD_DECRYPT:",
10913 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050010914
10915 testCases = append(testCases, testCase{
10916 testType: serverTest,
10917 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
10918 config: Config{
10919 MaxVersion: VersionTLS13,
10920 },
10921 resumeConfig: &Config{
10922 MaxVersion: VersionTLS13,
10923 Bugs: ProtocolBugs{
10924 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10925 SendStrayEarlyHandshake: true,
10926 ExpectEarlyDataAccepted: true},
10927 },
10928 resumeSession: true,
10929 shouldFail: true,
10930 expectedError: ":UNEXPECTED_RECORD:",
10931 expectedLocalError: "remote error: unexpected message",
10932 flags: []string{
10933 "-enable-early-data",
10934 },
10935 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010936}
10937
David Benjaminabbbee12016-10-31 19:20:42 -040010938func addTLS13CipherPreferenceTests() {
10939 // Test that client preference is honored if the shim has AES hardware
10940 // and ChaCha20-Poly1305 is preferred otherwise.
10941 testCases = append(testCases, testCase{
10942 testType: serverTest,
10943 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
10944 config: Config{
10945 MaxVersion: VersionTLS13,
10946 CipherSuites: []uint16{
10947 TLS_CHACHA20_POLY1305_SHA256,
10948 TLS_AES_128_GCM_SHA256,
10949 },
10950 },
10951 flags: []string{
10952 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10953 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10954 },
10955 })
10956
10957 testCases = append(testCases, testCase{
10958 testType: serverTest,
10959 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
10960 config: Config{
10961 MaxVersion: VersionTLS13,
10962 CipherSuites: []uint16{
10963 TLS_AES_128_GCM_SHA256,
10964 TLS_CHACHA20_POLY1305_SHA256,
10965 },
10966 },
10967 flags: []string{
10968 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10969 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10970 },
10971 })
10972
10973 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
10974 // whether it has AES hardware.
10975 testCases = append(testCases, testCase{
10976 name: "TLS13-CipherPreference-Client",
10977 config: Config{
10978 MaxVersion: VersionTLS13,
10979 // Use the client cipher order. (This is the default but
10980 // is listed to be explicit.)
10981 PreferServerCipherSuites: false,
10982 },
10983 flags: []string{
10984 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10985 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10986 },
10987 })
10988}
10989
David Benjaminf3fbade2016-09-19 13:08:16 -040010990func addPeekTests() {
10991 // Test SSL_peek works, including on empty records.
10992 testCases = append(testCases, testCase{
10993 name: "Peek-Basic",
10994 sendEmptyRecords: 1,
10995 flags: []string{"-peek-then-read"},
10996 })
10997
10998 // Test SSL_peek can drive the initial handshake.
10999 testCases = append(testCases, testCase{
11000 name: "Peek-ImplicitHandshake",
11001 flags: []string{
11002 "-peek-then-read",
11003 "-implicit-handshake",
11004 },
11005 })
11006
11007 // Test SSL_peek can discover and drive a renegotiation.
11008 testCases = append(testCases, testCase{
11009 name: "Peek-Renegotiate",
11010 config: Config{
11011 MaxVersion: VersionTLS12,
11012 },
11013 renegotiate: 1,
11014 flags: []string{
11015 "-peek-then-read",
11016 "-renegotiate-freely",
11017 "-expect-total-renegotiations", "1",
11018 },
11019 })
11020
11021 // Test SSL_peek can discover a close_notify.
11022 testCases = append(testCases, testCase{
11023 name: "Peek-Shutdown",
11024 config: Config{
11025 Bugs: ProtocolBugs{
11026 ExpectCloseNotify: true,
11027 },
11028 },
11029 flags: []string{
11030 "-peek-then-read",
11031 "-check-close-notify",
11032 },
11033 })
11034
11035 // Test SSL_peek can discover an alert.
11036 testCases = append(testCases, testCase{
11037 name: "Peek-Alert",
11038 config: Config{
11039 Bugs: ProtocolBugs{
11040 SendSpuriousAlert: alertRecordOverflow,
11041 },
11042 },
11043 flags: []string{"-peek-then-read"},
11044 shouldFail: true,
11045 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11046 })
11047
11048 // Test SSL_peek can handle KeyUpdate.
11049 testCases = append(testCases, testCase{
11050 name: "Peek-KeyUpdate",
11051 config: Config{
11052 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011053 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011054 sendKeyUpdates: 1,
11055 keyUpdateRequest: keyUpdateNotRequested,
11056 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011057 })
11058}
11059
David Benjamine6f22212016-11-08 14:28:24 -050011060func addRecordVersionTests() {
11061 for _, ver := range tlsVersions {
11062 // Test that the record version is enforced.
11063 testCases = append(testCases, testCase{
11064 name: "CheckRecordVersion-" + ver.name,
11065 config: Config{
11066 MinVersion: ver.version,
11067 MaxVersion: ver.version,
11068 Bugs: ProtocolBugs{
11069 SendRecordVersion: 0x03ff,
11070 },
11071 },
11072 shouldFail: true,
11073 expectedError: ":WRONG_VERSION_NUMBER:",
11074 })
11075
11076 // Test that the ClientHello may use any record version, for
11077 // compatibility reasons.
11078 testCases = append(testCases, testCase{
11079 testType: serverTest,
11080 name: "LooseInitialRecordVersion-" + ver.name,
11081 config: Config{
11082 MinVersion: ver.version,
11083 MaxVersion: ver.version,
11084 Bugs: ProtocolBugs{
11085 SendInitialRecordVersion: 0x03ff,
11086 },
11087 },
11088 })
11089
11090 // Test that garbage ClientHello record versions are rejected.
11091 testCases = append(testCases, testCase{
11092 testType: serverTest,
11093 name: "GarbageInitialRecordVersion-" + ver.name,
11094 config: Config{
11095 MinVersion: ver.version,
11096 MaxVersion: ver.version,
11097 Bugs: ProtocolBugs{
11098 SendInitialRecordVersion: 0xffff,
11099 },
11100 },
11101 shouldFail: true,
11102 expectedError: ":WRONG_VERSION_NUMBER:",
11103 })
11104 }
11105}
11106
David Benjamin2c516452016-11-15 10:16:54 +090011107func addCertificateTests() {
11108 // Test that a certificate chain with intermediate may be sent and
11109 // received as both client and server.
11110 for _, ver := range tlsVersions {
11111 testCases = append(testCases, testCase{
11112 testType: clientTest,
11113 name: "SendReceiveIntermediate-Client-" + ver.name,
11114 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011115 MinVersion: ver.version,
11116 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011117 Certificates: []Certificate{rsaChainCertificate},
11118 ClientAuth: RequireAnyClientCert,
11119 },
11120 expectPeerCertificate: &rsaChainCertificate,
11121 flags: []string{
11122 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11123 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11124 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11125 },
11126 })
11127
11128 testCases = append(testCases, testCase{
11129 testType: serverTest,
11130 name: "SendReceiveIntermediate-Server-" + ver.name,
11131 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011132 MinVersion: ver.version,
11133 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011134 Certificates: []Certificate{rsaChainCertificate},
11135 },
11136 expectPeerCertificate: &rsaChainCertificate,
11137 flags: []string{
11138 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11139 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11140 "-require-any-client-certificate",
11141 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11142 },
11143 })
11144 }
11145}
11146
David Benjaminbbaf3672016-11-17 10:53:09 +090011147func addRetainOnlySHA256ClientCertTests() {
11148 for _, ver := range tlsVersions {
11149 // Test that enabling
11150 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11151 // actually requesting a client certificate is a no-op.
11152 testCases = append(testCases, testCase{
11153 testType: serverTest,
11154 name: "RetainOnlySHA256-NoCert-" + ver.name,
11155 config: Config{
11156 MinVersion: ver.version,
11157 MaxVersion: ver.version,
11158 },
11159 flags: []string{
11160 "-retain-only-sha256-client-cert-initial",
11161 "-retain-only-sha256-client-cert-resume",
11162 },
11163 resumeSession: true,
11164 })
11165
11166 // Test that when retaining only a SHA-256 certificate is
11167 // enabled, the hash appears as expected.
11168 testCases = append(testCases, testCase{
11169 testType: serverTest,
11170 name: "RetainOnlySHA256-Cert-" + ver.name,
11171 config: Config{
11172 MinVersion: ver.version,
11173 MaxVersion: ver.version,
11174 Certificates: []Certificate{rsaCertificate},
11175 },
11176 flags: []string{
11177 "-verify-peer",
11178 "-retain-only-sha256-client-cert-initial",
11179 "-retain-only-sha256-client-cert-resume",
11180 "-expect-sha256-client-cert-initial",
11181 "-expect-sha256-client-cert-resume",
11182 },
11183 resumeSession: true,
11184 })
11185
11186 // Test that when the config changes from on to off, a
11187 // resumption is rejected because the server now wants the full
11188 // certificate chain.
11189 testCases = append(testCases, testCase{
11190 testType: serverTest,
11191 name: "RetainOnlySHA256-OnOff-" + ver.name,
11192 config: Config{
11193 MinVersion: ver.version,
11194 MaxVersion: ver.version,
11195 Certificates: []Certificate{rsaCertificate},
11196 },
11197 flags: []string{
11198 "-verify-peer",
11199 "-retain-only-sha256-client-cert-initial",
11200 "-expect-sha256-client-cert-initial",
11201 },
11202 resumeSession: true,
11203 expectResumeRejected: true,
11204 })
11205
11206 // Test that when the config changes from off to on, a
11207 // resumption is rejected because the server now wants just the
11208 // hash.
11209 testCases = append(testCases, testCase{
11210 testType: serverTest,
11211 name: "RetainOnlySHA256-OffOn-" + ver.name,
11212 config: Config{
11213 MinVersion: ver.version,
11214 MaxVersion: ver.version,
11215 Certificates: []Certificate{rsaCertificate},
11216 },
11217 flags: []string{
11218 "-verify-peer",
11219 "-retain-only-sha256-client-cert-resume",
11220 "-expect-sha256-client-cert-resume",
11221 },
11222 resumeSession: true,
11223 expectResumeRejected: true,
11224 })
11225 }
11226}
11227
Adam Langleya4b91982016-12-12 12:05:53 -080011228func addECDSAKeyUsageTests() {
11229 p256 := elliptic.P256()
11230 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11231 if err != nil {
11232 panic(err)
11233 }
11234
11235 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11236 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11237 if err != nil {
11238 panic(err)
11239 }
11240
11241 template := x509.Certificate{
11242 SerialNumber: serialNumber,
11243 Subject: pkix.Name{
11244 Organization: []string{"Acme Co"},
11245 },
11246 NotBefore: time.Now(),
11247 NotAfter: time.Now(),
11248
11249 // An ECC certificate with only the keyAgreement key usgae may
11250 // be used with ECDH, but not ECDSA.
11251 KeyUsage: x509.KeyUsageKeyAgreement,
11252 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11253 BasicConstraintsValid: true,
11254 }
11255
11256 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11257 if err != nil {
11258 panic(err)
11259 }
11260
11261 cert := Certificate{
11262 Certificate: [][]byte{derBytes},
11263 PrivateKey: priv,
11264 }
11265
11266 for _, ver := range tlsVersions {
11267 if ver.version < VersionTLS12 {
11268 continue
11269 }
11270
11271 testCases = append(testCases, testCase{
11272 testType: clientTest,
11273 name: "ECDSAKeyUsage-" + ver.name,
11274 config: Config{
11275 MinVersion: ver.version,
11276 MaxVersion: ver.version,
11277 Certificates: []Certificate{cert},
11278 },
11279 shouldFail: true,
11280 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11281 })
11282 }
11283}
11284
David Benjamin8c26d752017-03-26 15:13:51 -050011285func addExtraHandshakeTests() {
11286 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11287 // to ensure there is no transport I/O.
11288 testCases = append(testCases, testCase{
11289 testType: clientTest,
11290 name: "ExtraHandshake-Client-TLS12",
11291 config: Config{
11292 MinVersion: VersionTLS12,
11293 MaxVersion: VersionTLS12,
11294 },
11295 flags: []string{
11296 "-async",
11297 "-no-op-extra-handshake",
11298 },
11299 })
11300 testCases = append(testCases, testCase{
11301 testType: serverTest,
11302 name: "ExtraHandshake-Server-TLS12",
11303 config: Config{
11304 MinVersion: VersionTLS12,
11305 MaxVersion: VersionTLS12,
11306 },
11307 flags: []string{
11308 "-async",
11309 "-no-op-extra-handshake",
11310 },
11311 })
11312 testCases = append(testCases, testCase{
11313 testType: clientTest,
11314 name: "ExtraHandshake-Client-TLS13",
11315 config: Config{
11316 MinVersion: VersionTLS13,
11317 MaxVersion: VersionTLS13,
11318 },
11319 flags: []string{
11320 "-async",
11321 "-no-op-extra-handshake",
11322 },
11323 })
11324 testCases = append(testCases, testCase{
11325 testType: serverTest,
11326 name: "ExtraHandshake-Server-TLS13",
11327 config: Config{
11328 MinVersion: VersionTLS13,
11329 MaxVersion: VersionTLS13,
11330 },
11331 flags: []string{
11332 "-async",
11333 "-no-op-extra-handshake",
11334 },
11335 })
11336
11337 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11338 testCases = append(testCases, testCase{
11339 testType: serverTest,
11340 name: "ExtraHandshake-Server-EarlyData-TLS13",
11341 config: Config{
11342 MaxVersion: VersionTLS13,
11343 MinVersion: VersionTLS13,
11344 Bugs: ProtocolBugs{
11345 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11346 ExpectEarlyDataAccepted: true,
11347 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11348 },
11349 },
11350 messageCount: 2,
11351 resumeSession: true,
11352 flags: []string{
11353 "-async",
11354 "-enable-early-data",
11355 "-expect-accept-early-data",
11356 "-no-op-extra-handshake",
11357 },
11358 })
11359
11360 // An extra SSL_do_handshake drives the handshake to completion in False
11361 // Start. We test this by handshaking twice and asserting the False
11362 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11363 // how the test works.
11364 testCases = append(testCases, testCase{
11365 testType: clientTest,
11366 name: "ExtraHandshake-FalseStart",
11367 config: Config{
11368 MaxVersion: VersionTLS12,
11369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11370 NextProtos: []string{"foo"},
11371 Bugs: ProtocolBugs{
11372 ExpectFalseStart: true,
11373 AlertBeforeFalseStartTest: alertAccessDenied,
11374 },
11375 },
11376 flags: []string{
11377 "-handshake-twice",
11378 "-false-start",
11379 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011380 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011381 },
11382 shimWritesFirst: true,
11383 shouldFail: true,
11384 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11385 expectedLocalError: "tls: peer did not false start: EOF",
11386 })
11387}
11388
Adam Langley7c803a62015-06-15 15:35:05 -070011389func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011390 defer wg.Done()
11391
11392 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011393 var err error
11394
David Benjaminba28dfc2016-11-15 17:47:21 +090011395 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011396 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11397 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011398 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011399 if err != nil {
11400 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11401 }
11402 break
11403 }
11404 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011405 } else if *repeatUntilFailure {
11406 for err == nil {
11407 statusChan <- statusMsg{test: test, started: true}
11408 err = runTest(test, shimPath, -1)
11409 }
11410 } else {
11411 statusChan <- statusMsg{test: test, started: true}
11412 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011413 }
Adam Langley95c29f32014-06-20 12:00:00 -070011414 statusChan <- statusMsg{test: test, err: err}
11415 }
11416}
11417
11418type statusMsg struct {
11419 test *testCase
11420 started bool
11421 err error
11422}
11423
David Benjamin5f237bc2015-02-11 17:14:15 -050011424func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011425 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011426
David Benjamin5f237bc2015-02-11 17:14:15 -050011427 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011428 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011429 if !*pipe {
11430 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011431 var erase string
11432 for i := 0; i < lineLen; i++ {
11433 erase += "\b \b"
11434 }
11435 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011436 }
11437
Adam Langley95c29f32014-06-20 12:00:00 -070011438 if msg.started {
11439 started++
11440 } else {
11441 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011442
11443 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011444 if msg.err == errUnimplemented {
11445 if *pipe {
11446 // Print each test instead of a status line.
11447 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11448 }
11449 unimplemented++
11450 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11451 } else {
11452 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11453 failed++
11454 testOutput.addResult(msg.test.name, "FAIL")
11455 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011456 } else {
11457 if *pipe {
11458 // Print each test instead of a status line.
11459 fmt.Printf("PASSED (%s)\n", msg.test.name)
11460 }
11461 testOutput.addResult(msg.test.name, "PASS")
11462 }
Adam Langley95c29f32014-06-20 12:00:00 -070011463 }
11464
David Benjamin5f237bc2015-02-11 17:14:15 -050011465 if !*pipe {
11466 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011467 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011468 lineLen = len(line)
11469 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011470 }
Adam Langley95c29f32014-06-20 12:00:00 -070011471 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011472
11473 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011474}
11475
11476func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011477 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011478 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011479 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011480
Adam Langley7c803a62015-06-15 15:35:05 -070011481 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011482 addCipherSuiteTests()
11483 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011484 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011485 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011486 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011487 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011488 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011489 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011490 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011491 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011492 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011493 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011494 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011495 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011496 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011497 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011498 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011499 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011500 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011501 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011502 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011503 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011504 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011505 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011506 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011507 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011508 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011509 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011510 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011511 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011512 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011513 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011514 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011515 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011516
11517 var wg sync.WaitGroup
11518
Adam Langley7c803a62015-06-15 15:35:05 -070011519 statusChan := make(chan statusMsg, *numWorkers)
11520 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011521 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011522
EKRf71d7ed2016-08-06 13:25:12 -070011523 if len(*shimConfigFile) != 0 {
11524 encoded, err := ioutil.ReadFile(*shimConfigFile)
11525 if err != nil {
11526 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11527 os.Exit(1)
11528 }
11529
11530 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11531 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11532 os.Exit(1)
11533 }
11534 }
11535
David Benjamin025b3d32014-07-01 19:53:04 -040011536 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011537
Adam Langley7c803a62015-06-15 15:35:05 -070011538 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011539 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011540 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011541 }
11542
David Benjamin270f0a72016-03-17 14:41:36 -040011543 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011544 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011545 matched := true
11546 if len(*testToRun) != 0 {
11547 var err error
11548 matched, err = filepath.Match(*testToRun, testCases[i].name)
11549 if err != nil {
11550 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11551 os.Exit(1)
11552 }
11553 }
11554
EKRf71d7ed2016-08-06 13:25:12 -070011555 if !*includeDisabled {
11556 for pattern := range shimConfig.DisabledTests {
11557 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11558 if err != nil {
11559 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11560 os.Exit(1)
11561 }
11562
11563 if isDisabled {
11564 matched = false
11565 break
11566 }
11567 }
11568 }
11569
David Benjamin17e12922016-07-28 18:04:43 -040011570 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011571 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011572 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011573
11574 // Only run one test if repeating until failure.
11575 if *repeatUntilFailure {
11576 break
11577 }
Adam Langley95c29f32014-06-20 12:00:00 -070011578 }
11579 }
David Benjamin17e12922016-07-28 18:04:43 -040011580
David Benjamin270f0a72016-03-17 14:41:36 -040011581 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011582 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011583 os.Exit(1)
11584 }
Adam Langley95c29f32014-06-20 12:00:00 -070011585
11586 close(testChan)
11587 wg.Wait()
11588 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011589 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011590
11591 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011592
11593 if *jsonOutput != "" {
11594 if err := testOutput.writeTo(*jsonOutput); err != nil {
11595 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11596 }
11597 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011598
EKR842ae6c2016-07-27 09:22:05 +020011599 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11600 os.Exit(1)
11601 }
11602
11603 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011604 os.Exit(1)
11605 }
Adam Langley95c29f32014-06-20 12:00:00 -070011606}