blob: cc5aa3ccccffbadfb529a31db0e34d096acf4e68 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdezc94998a2017-06-20 10:55:02 -0400266// configVersionToWire maps a protocol version to the default wire version to
267// test at that protocol.
268//
269// TODO(davidben): Rather than mapping these, make tlsVersions contains a list
270// of wire versions and test all of them.
271func configVersionToWire(vers uint16, protocol protocol) uint16 {
272 if protocol == dtls {
273 switch vers {
274 case VersionTLS12:
275 return VersionDTLS12
276 case VersionTLS10:
277 return VersionDTLS10
278 }
279 } else {
280 switch vers {
281 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
282 return vers
283 case VersionTLS13:
284 return tls13DraftVersion
285 }
286 }
287
288 panic("unknown version")
289}
290
Adam Langley2ff79332017-02-28 13:45:39 -0800291// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
292func encodeDERValues(values [][]byte) string {
293 var ret string
294 for i, v := range values {
295 if i > 0 {
296 ret += ","
297 }
298 ret += hex.EncodeToString(v)
299 }
300
301 return ret
302}
303
David Benjamin025b3d32014-07-01 19:53:04 -0400304type testType int
305
306const (
307 clientTest testType = iota
308 serverTest
309)
310
David Benjamin6fd297b2014-08-11 18:43:38 -0400311type protocol int
312
313const (
314 tls protocol = iota
315 dtls
316)
317
David Benjaminfc7b0862014-09-06 13:21:53 -0400318const (
319 alpn = 1
320 npn = 2
321)
322
Adam Langley95c29f32014-06-20 12:00:00 -0700323type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400324 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400325 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700326 name string
327 config Config
328 shouldFail bool
329 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700330 // expectedLocalError, if not empty, contains a substring that must be
331 // found in the local error.
332 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400333 // expectedVersion, if non-zero, specifies the TLS version that must be
334 // negotiated.
335 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400336 // expectedResumeVersion, if non-zero, specifies the TLS version that
337 // must be negotiated on resumption. If zero, expectedVersion is used.
338 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400339 // expectedCipher, if non-zero, specifies the TLS cipher suite that
340 // should be negotiated.
341 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400342 // expectChannelID controls whether the connection should have
343 // negotiated a Channel ID with channelIDKey.
344 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400345 // expectedNextProto controls whether the connection should
346 // negotiate a next protocol via NPN or ALPN.
347 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 // expectNoNextProto, if true, means that no next protocol should be
349 // negotiated.
350 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400351 // expectedNextProtoType, if non-zero, is the expected next
352 // protocol negotiation mechanism.
353 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500354 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
355 // should be negotiated. If zero, none should be negotiated.
356 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100357 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
358 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100359 // expectedSCTList, if not nil, is the expected SCT list to be received.
360 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700361 // expectedPeerSignatureAlgorithm, if not zero, is the signature
362 // algorithm that the peer should have used in the handshake.
363 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400364 // expectedCurveID, if not zero, is the curve that the handshake should
365 // have used.
366 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700367 // messageLen is the length, in bytes, of the test message that will be
368 // sent.
369 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400370 // messageCount is the number of test messages that will be sent.
371 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400372 // certFile is the path to the certificate to use for the server.
373 certFile string
374 // keyFile is the path to the private key to use for the server.
375 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400376 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400377 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400378 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400379 // resumeRenewedSession controls whether a third connection should be
380 // tested which attempts to resume the second connection's session.
381 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700382 // expectResumeRejected, if true, specifies that the attempted
383 // resumption must be rejected by the client. This is only valid for a
384 // serverTest.
385 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400386 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // resumption. Unless newSessionsOnResume is set,
388 // SessionTicketKey, ServerSessionCache, and
389 // ClientSessionCache are copied from the initial connection's
390 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400391 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500392 // newSessionsOnResume, if true, will cause resumeConfig to
393 // use a different session resumption context.
394 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400395 // noSessionCache, if true, will cause the server to run without a
396 // session cache.
397 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400398 // sendPrefix sends a prefix on the socket before actually performing a
399 // handshake.
400 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400401 // shimWritesFirst controls whether the shim sends an initial "hello"
402 // message before doing a roundtrip with the runner.
403 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400404 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
405 // does not complete the write until responding to the first runner
406 // message.
407 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400408 // shimShutsDown, if true, runs a test where the shim shuts down the
409 // connection immediately after the handshake rather than echoing
410 // messages from the runner.
411 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400412 // renegotiate indicates the number of times the connection should be
413 // renegotiated during the exchange.
414 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400415 // sendHalfHelloRequest, if true, causes the server to send half a
416 // HelloRequest when the handshake completes.
417 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700418 // renegotiateCiphers is a list of ciphersuite ids that will be
419 // switched in just before renegotiation.
420 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500421 // replayWrites, if true, configures the underlying transport
422 // to replay every write it makes in DTLS tests.
423 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 // damageFirstWrite, if true, configures the underlying transport to
425 // damage the final byte of the first application data write.
426 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400427 // exportKeyingMaterial, if non-zero, configures the test to exchange
428 // keying material and verify they match.
429 exportKeyingMaterial int
430 exportLabel string
431 exportContext string
432 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400433 // flags, if not empty, contains a list of command-line flags that will
434 // be passed to the shim program.
435 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700436 // testTLSUnique, if true, causes the shim to send the tls-unique value
437 // which will be compared against the expected value.
438 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400439 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400440 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400441 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400442 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400443 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400444 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400445 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
446 // be sent before each test message.
447 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400448 // sendKeyUpdates is the number of consecutive key updates to send
449 // before and after the test message.
450 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400451 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
452 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400453 // expectMessageDropped, if true, means the test message is expected to
454 // be dropped by the client rather than echoed back.
455 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900456 // expectPeerCertificate, if not nil, is the certificate chain the peer
457 // is expected to send.
458 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500459 // shimPrefix is the prefix that the shim will send to the server.
460 shimPrefix string
461 // resumeShimPrefix is the prefix that the shim will send to the server on a
462 // resumption.
463 resumeShimPrefix string
Adam Langley95c29f32014-06-20 12:00:00 -0700464}
465
Adam Langley7c803a62015-06-15 15:35:05 -0700466var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700467
David Benjamin0fde2eb2017-06-30 19:11:22 -0400468func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if len(data) == 0 {
470 return
471 }
472
David Benjamin0fde2eb2017-06-30 19:11:22 -0400473 settings, err := ioutil.ReadFile(path)
474 if err != nil {
475 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500476 return
477 }
478
David Benjamin0fde2eb2017-06-30 19:11:22 -0400479 settings = append(settings, data...)
480 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
481 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500482 }
483}
484
David Benjamin3ed59772016-03-08 12:50:21 -0500485// A timeoutConn implements an idle timeout on each Read and Write operation.
486type timeoutConn struct {
487 net.Conn
488 timeout time.Duration
489}
490
491func (t *timeoutConn) Read(b []byte) (int, error) {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
495 return t.Conn.Read(b)
496}
497
498func (t *timeoutConn) Write(b []byte) (int, error) {
499 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
500 return 0, err
501 }
502 return t.Conn.Write(b)
503}
504
David Benjamin0fde2eb2017-06-30 19:11:22 -0400505func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400506 if !test.noSessionCache {
507 if config.ClientSessionCache == nil {
508 config.ClientSessionCache = NewLRUClientSessionCache(1)
509 }
510 if config.ServerSessionCache == nil {
511 config.ServerSessionCache = NewLRUServerSessionCache(1)
512 }
513 }
514 if test.testType == clientTest {
515 if len(config.Certificates) == 0 {
516 config.Certificates = []Certificate{rsaCertificate}
517 }
518 } else {
519 // Supply a ServerName to ensure a constant session cache key,
520 // rather than falling back to net.Conn.RemoteAddr.
521 if len(config.ServerName) == 0 {
522 config.ServerName = "test"
523 }
524 }
525 if *fuzzer {
526 config.Bugs.NullAllCiphers = true
527 }
David Benjamin01a90572016-09-22 00:11:43 -0400528 if *deterministic {
529 config.Time = func() time.Time { return time.Unix(1234, 1234) }
530 }
David Benjamine54af062016-08-08 19:21:18 -0400531
David Benjamin01784b42016-06-07 18:00:52 -0400532 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500533
David Benjamin6fd297b2014-08-11 18:43:38 -0400534 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500535 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
536 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500537 }
538
David Benjamin9867b7d2016-03-01 23:25:48 -0500539 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500540 local, peer := "client", "server"
541 if test.testType == clientTest {
542 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500543 }
David Benjaminebda9b32015-11-02 15:33:18 -0500544 connDebug := &recordingConn{
545 Conn: conn,
546 isDatagram: test.protocol == dtls,
547 local: local,
548 peer: peer,
549 }
550 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500551 if *flagDebug {
552 defer connDebug.WriteTo(os.Stdout)
553 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400554 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500555 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 path := transcriptPrefix + strconv.Itoa(num)
557 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500558 }()
559 }
David Benjaminebda9b32015-11-02 15:33:18 -0500560
561 if config.Bugs.PacketAdaptor != nil {
562 config.Bugs.PacketAdaptor.debug = connDebug
563 }
564 }
565
566 if test.replayWrites {
567 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400568 }
569
David Benjamin3ed59772016-03-08 12:50:21 -0500570 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500571 if test.damageFirstWrite {
572 connDamage = newDamageAdaptor(conn)
573 conn = connDamage
574 }
575
David Benjamin6fd297b2014-08-11 18:43:38 -0400576 if test.sendPrefix != "" {
577 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
578 return err
579 }
David Benjamin98e882e2014-08-08 13:24:34 -0400580 }
581
David Benjamin1d5c83e2014-07-22 19:20:02 -0400582 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400583 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400584 if test.protocol == dtls {
585 tlsConn = DTLSServer(conn, config)
586 } else {
587 tlsConn = Server(conn, config)
588 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400589 } else {
590 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400591 if test.protocol == dtls {
592 tlsConn = DTLSClient(conn, config)
593 } else {
594 tlsConn = Client(conn, config)
595 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400596 }
David Benjamin30789da2015-08-29 22:56:45 -0400597 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598
Adam Langley95c29f32014-06-20 12:00:00 -0700599 if err := tlsConn.Handshake(); err != nil {
600 return err
601 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700602
David Benjamin01fe8202014-09-24 15:21:44 -0400603 // TODO(davidben): move all per-connection expectations into a dedicated
604 // expectations struct that can be specified separately for the two
605 // legs.
606 expectedVersion := test.expectedVersion
607 if isResume && test.expectedResumeVersion != 0 {
608 expectedVersion = test.expectedResumeVersion
609 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 connState := tlsConn.ConnectionState()
611 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400612 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400613 }
614
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700615 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400616 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
617 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700618 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
619 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
620 }
David Benjamin90da8c82015-04-20 14:57:57 -0400621
David Benjamina08e49d2014-08-24 01:46:07 -0400622 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700623 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if channelID == nil {
625 return fmt.Errorf("no channel ID negotiated")
626 }
627 if channelID.Curve != channelIDKey.Curve ||
628 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
629 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
630 return fmt.Errorf("incorrect channel ID")
631 }
632 }
633
David Benjaminae2888f2014-09-06 12:58:58 -0400634 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700635 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400636 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
637 }
638 }
639
David Benjaminc7ce9772015-10-09 19:32:41 -0400640 if test.expectNoNextProto {
641 if actual := connState.NegotiatedProtocol; actual != "" {
642 return fmt.Errorf("got unexpected next proto %s", actual)
643 }
644 }
645
David Benjaminfc7b0862014-09-06 13:21:53 -0400646 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700647 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400648 return fmt.Errorf("next proto type mismatch")
649 }
650 }
651
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700652 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500653 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
654 }
655
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100656 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300657 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100658 }
659
Paul Lietar4fac72e2015-09-09 13:44:55 +0100660 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
661 return fmt.Errorf("SCT list mismatch")
662 }
663
Nick Harper60edffd2016-06-21 15:19:24 -0700664 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
665 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400666 }
667
Steven Valdez5440fe02016-07-18 12:40:30 -0400668 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
669 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
670 }
671
David Benjamin2c516452016-11-15 10:16:54 +0900672 if test.expectPeerCertificate != nil {
673 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
674 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
675 }
676 for i, cert := range connState.PeerCertificates {
677 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
678 return fmt.Errorf("peer certificate %d did not match", i+1)
679 }
680 }
681 }
682
David Benjaminc565ebb2015-04-03 04:06:36 -0400683 if test.exportKeyingMaterial > 0 {
684 actual := make([]byte, test.exportKeyingMaterial)
685 if _, err := io.ReadFull(tlsConn, actual); err != nil {
686 return err
687 }
688 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
689 if err != nil {
690 return err
691 }
692 if !bytes.Equal(actual, expected) {
693 return fmt.Errorf("keying material mismatch")
694 }
695 }
696
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700697 if test.testTLSUnique {
698 var peersValue [12]byte
699 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
700 return err
701 }
702 expected := tlsConn.ConnectionState().TLSUnique
703 if !bytes.Equal(peersValue[:], expected) {
704 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
705 }
706 }
707
David Benjamin47921102016-07-28 11:29:18 -0400708 if test.sendHalfHelloRequest {
709 tlsConn.SendHalfHelloRequest()
710 }
711
Steven Valdeze831a812017-03-09 14:56:07 -0500712 shimPrefix := test.shimPrefix
713 if isResume {
714 shimPrefix = test.resumeShimPrefix
715 }
716 if test.shimWritesFirst || test.readWithUnfinishedWrite {
717 shimPrefix = "hello"
718 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400719 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400720 // If readWithUnfinishedWrite is set, the shim prefix will be
721 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500722 if shimPrefix != "" && !test.readWithUnfinishedWrite {
723 var buf = make([]byte, len(shimPrefix))
724 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400725 if err != nil {
726 return err
727 }
Steven Valdeze831a812017-03-09 14:56:07 -0500728 if string(buf) != shimPrefix {
729 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400730 }
Steven Valdeze831a812017-03-09 14:56:07 -0500731 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400732 }
733
Adam Langleycf2d4f42014-10-28 19:06:14 -0700734 if test.renegotiateCiphers != nil {
735 config.CipherSuites = test.renegotiateCiphers
736 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400737 for i := 0; i < test.renegotiate; i++ {
738 if err := tlsConn.Renegotiate(); err != nil {
739 return err
740 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700741 }
742 } else if test.renegotiateCiphers != nil {
743 panic("renegotiateCiphers without renegotiate")
744 }
745
David Benjamin5fa3eba2015-01-22 16:35:40 -0500746 if test.damageFirstWrite {
747 connDamage.setDamage(true)
748 tlsConn.Write([]byte("DAMAGED WRITE"))
749 connDamage.setDamage(false)
750 }
751
David Benjamin8e6db492015-07-25 18:29:23 -0400752 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700753 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400754 if test.protocol == dtls {
755 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
756 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700757 // Read until EOF.
758 _, err := io.Copy(ioutil.Discard, tlsConn)
759 return err
760 }
David Benjamin4417d052015-04-05 04:17:25 -0400761 if messageLen == 0 {
762 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700763 }
Adam Langley95c29f32014-06-20 12:00:00 -0700764
David Benjamin8e6db492015-07-25 18:29:23 -0400765 messageCount := test.messageCount
766 if messageCount == 0 {
767 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400768 }
769
David Benjamin8e6db492015-07-25 18:29:23 -0400770 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400771 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400772 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400773 }
774
David Benjamin8e6db492015-07-25 18:29:23 -0400775 for i := 0; i < test.sendEmptyRecords; i++ {
776 tlsConn.Write(nil)
777 }
778
779 for i := 0; i < test.sendWarningAlerts; i++ {
780 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
781 }
782
David Benjamin24e58862017-06-14 18:45:29 -0400783 if test.sendBogusAlertType {
784 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
785 }
786
David Benjaminbbba9392017-04-06 12:54:12 -0400787 testMessage := make([]byte, messageLen)
788 for i := range testMessage {
789 testMessage[i] = 0x42 ^ byte(j)
790 }
791 tlsConn.Write(testMessage)
792
793 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500794 if shimPrefix != "" {
795 var buf = make([]byte, len(shimPrefix))
796 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400797 if err != nil {
798 return err
799 }
Steven Valdeze831a812017-03-09 14:56:07 -0500800 if string(buf) != shimPrefix {
801 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400802 }
Steven Valdeze831a812017-03-09 14:56:07 -0500803 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400804 }
805
David Benjamin4f75aaf2015-09-01 16:53:10 -0400806 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400807 // The shim will not respond.
808 continue
809 }
810
David Benjaminbbba9392017-04-06 12:54:12 -0400811 // Process the KeyUpdate ACK. However many KeyUpdates the runner
812 // sends, the shim should respond only once.
813 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
814 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
815 return err
816 }
817 }
818
David Benjamin8e6db492015-07-25 18:29:23 -0400819 buf := make([]byte, len(testMessage))
820 if test.protocol == dtls {
821 bufTmp := make([]byte, len(buf)+1)
822 n, err := tlsConn.Read(bufTmp)
823 if err != nil {
824 return err
825 }
826 if n != len(buf) {
827 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
828 }
829 copy(buf, bufTmp)
830 } else {
831 _, err := io.ReadFull(tlsConn, buf)
832 if err != nil {
833 return err
834 }
835 }
836
837 for i, v := range buf {
838 if v != testMessage[i]^0xff {
839 return fmt.Errorf("bad reply contents at byte %d", i)
840 }
Adam Langley95c29f32014-06-20 12:00:00 -0700841 }
842 }
843
844 return nil
845}
846
David Benjamin325b5c32014-07-01 19:40:31 -0400847func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400848 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700849 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400850 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700851 }
David Benjamin325b5c32014-07-01 19:40:31 -0400852 valgrindArgs = append(valgrindArgs, path)
853 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700854
David Benjamin325b5c32014-07-01 19:40:31 -0400855 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700856}
857
David Benjamin325b5c32014-07-01 19:40:31 -0400858func gdbOf(path string, args ...string) *exec.Cmd {
859 xtermArgs := []string{"-e", "gdb", "--args"}
860 xtermArgs = append(xtermArgs, path)
861 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamind16bf342015-12-18 00:53:12 -0500866func lldbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "lldb", "--"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
870
871 return exec.Command("xterm", xtermArgs...)
872}
873
EKR842ae6c2016-07-27 09:22:05 +0200874var (
875 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
876 errUnimplemented = errors.New("child process does not implement needed flags")
877)
Adam Langley69a01602014-11-17 17:26:55 -0800878
David Benjamin87c8a642015-02-21 01:54:29 -0500879// accept accepts a connection from listener, unless waitChan signals a process
880// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400881func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500882 type connOrError struct {
883 conn net.Conn
884 err error
885 }
886 connChan := make(chan connOrError, 1)
887 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400888 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500889 conn, err := listener.Accept()
890 connChan <- connOrError{conn, err}
891 close(connChan)
892 }()
893 select {
894 case result := <-connChan:
895 return result.conn, result.err
896 case childErr := <-waitChan:
897 waitChan <- childErr
898 return nil, fmt.Errorf("child exited early: %s", childErr)
899 }
900}
901
EKRf71d7ed2016-08-06 13:25:12 -0700902func translateExpectedError(errorStr string) string {
903 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
904 return translated
905 }
906
907 if *looseErrors {
908 return ""
909 }
910
911 return errorStr
912}
913
Adam Langley7c803a62015-06-15 15:35:05 -0700914func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400915 // Help debugging panics on the Go side.
916 defer func() {
917 if r := recover(); r != nil {
918 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
919 panic(r)
920 }
921 }()
922
Adam Langley38311732014-10-16 19:04:35 -0700923 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
924 panic("Error expected without shouldFail in " + test.name)
925 }
926
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700927 if test.expectResumeRejected && !test.resumeSession {
928 panic("expectResumeRejected without resumeSession in " + test.name)
929 }
930
Adam Langley33b1d4f2016-12-07 15:03:45 -0800931 for _, ver := range tlsVersions {
932 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
933 continue
934 }
935
936 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
937 continue
938 }
939
940 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))
941 }
942
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700943 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
944 if err != nil {
945 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
946 }
David Benjamin87c8a642015-02-21 01:54:29 -0500947 if err != nil {
948 panic(err)
949 }
950 defer func() {
951 if listener != nil {
952 listener.Close()
953 }
954 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700955
David Benjamin87c8a642015-02-21 01:54:29 -0500956 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400957 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400958 flags = append(flags, "-server")
959
David Benjamin025b3d32014-07-01 19:53:04 -0400960 flags = append(flags, "-key-file")
961 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700962 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400963 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700964 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400965 }
966
967 flags = append(flags, "-cert-file")
968 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700969 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400970 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700971 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400972 }
973 }
David Benjamin5a593af2014-08-11 19:51:50 -0400974
David Benjamin6fd297b2014-08-11 18:43:38 -0400975 if test.protocol == dtls {
976 flags = append(flags, "-dtls")
977 }
978
David Benjamin46662482016-08-17 00:51:00 -0400979 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400980 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400981 resumeCount++
982 if test.resumeRenewedSession {
983 resumeCount++
984 }
985 }
986
987 if resumeCount > 0 {
988 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400989 }
990
David Benjamine58c4f52014-08-24 03:47:07 -0400991 if test.shimWritesFirst {
992 flags = append(flags, "-shim-writes-first")
993 }
994
David Benjaminbbba9392017-04-06 12:54:12 -0400995 if test.readWithUnfinishedWrite {
996 flags = append(flags, "-read-with-unfinished-write")
997 }
998
David Benjamin30789da2015-08-29 22:56:45 -0400999 if test.shimShutsDown {
1000 flags = append(flags, "-shim-shuts-down")
1001 }
1002
David Benjaminc565ebb2015-04-03 04:06:36 -04001003 if test.exportKeyingMaterial > 0 {
1004 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1005 flags = append(flags, "-export-label", test.exportLabel)
1006 flags = append(flags, "-export-context", test.exportContext)
1007 if test.useExportContext {
1008 flags = append(flags, "-use-export-context")
1009 }
1010 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001011 if test.expectResumeRejected {
1012 flags = append(flags, "-expect-session-miss")
1013 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001014
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001015 if test.testTLSUnique {
1016 flags = append(flags, "-tls-unique")
1017 }
1018
David Benjamin0fde2eb2017-06-30 19:11:22 -04001019 var transcriptPrefix string
1020 if len(*transcriptDir) != 0 {
1021 protocol := "tls"
1022 if test.protocol == dtls {
1023 protocol = "dtls"
1024 }
1025
1026 side := "client"
1027 if test.testType == serverTest {
1028 side = "server"
1029 }
1030
1031 dir := filepath.Join(*transcriptDir, protocol, side)
1032 if err := os.MkdirAll(dir, 0755); err != nil {
1033 return err
1034 }
1035 transcriptPrefix = filepath.Join(dir, test.name+"-")
1036 flags = append(flags, "-write-settings", transcriptPrefix)
1037 }
1038
David Benjamin025b3d32014-07-01 19:53:04 -04001039 flags = append(flags, test.flags...)
1040
1041 var shim *exec.Cmd
1042 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001043 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001044 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001045 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001046 } else if *useLLDB {
1047 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001048 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001049 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001050 }
David Benjamin025b3d32014-07-01 19:53:04 -04001051 shim.Stdin = os.Stdin
1052 var stdoutBuf, stderrBuf bytes.Buffer
1053 shim.Stdout = &stdoutBuf
1054 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001055 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001056 shim.Env = os.Environ()
1057 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001058 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001059 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001060 }
1061 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1062 }
David Benjamin025b3d32014-07-01 19:53:04 -04001063
1064 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001065 panic(err)
1066 }
David Benjamin87c8a642015-02-21 01:54:29 -05001067 waitChan := make(chan error, 1)
1068 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001069
1070 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001071
David Benjamin7a4aaa42016-09-20 17:58:14 -04001072 if *deterministic {
1073 config.Rand = &deterministicRand{}
1074 }
1075
David Benjamin87c8a642015-02-21 01:54:29 -05001076 conn, err := acceptOrWait(listener, waitChan)
1077 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001078 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001079 conn.Close()
1080 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001081
David Benjamin46662482016-08-17 00:51:00 -04001082 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001083 var resumeConfig Config
1084 if test.resumeConfig != nil {
1085 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001086 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001087 resumeConfig.SessionTicketKey = config.SessionTicketKey
1088 resumeConfig.ClientSessionCache = config.ClientSessionCache
1089 resumeConfig.ServerSessionCache = config.ServerSessionCache
1090 }
David Benjamin2e045a92016-06-08 13:09:56 -04001091 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001092 } else {
1093 resumeConfig = config
1094 }
David Benjamin87c8a642015-02-21 01:54:29 -05001095 var connResume net.Conn
1096 connResume, err = acceptOrWait(listener, waitChan)
1097 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001098 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001099 connResume.Close()
1100 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001101 }
1102
David Benjamin87c8a642015-02-21 01:54:29 -05001103 // Close the listener now. This is to avoid hangs should the shim try to
1104 // open more connections than expected.
1105 listener.Close()
1106 listener = nil
1107
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001108 var shimKilledLock sync.Mutex
1109 var shimKilled bool
1110 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1111 shimKilledLock.Lock()
1112 shimKilled = true
1113 shimKilledLock.Unlock()
1114 shim.Process.Kill()
1115 })
David Benjamin87c8a642015-02-21 01:54:29 -05001116 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001117 waitTimeout.Stop()
1118 shimKilledLock.Lock()
1119 if shimKilled && err == nil {
1120 err = errors.New("timeout waiting for the shim to exit.")
1121 }
1122 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001123 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001124 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001125 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1126 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001127 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001128 case 89:
1129 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001130 case 99:
1131 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001132 }
1133 }
Adam Langley95c29f32014-06-20 12:00:00 -07001134
David Benjamin9bea3492016-03-02 10:59:16 -05001135 // Account for Windows line endings.
1136 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1137 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001138
1139 // Separate the errors from the shim and those from tools like
1140 // AddressSanitizer.
1141 var extraStderr string
1142 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1143 stderr = stderrParts[0]
1144 extraStderr = stderrParts[1]
1145 }
1146
Adam Langley95c29f32014-06-20 12:00:00 -07001147 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001148 expectedError := translateExpectedError(test.expectedError)
1149 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001150
Adam Langleyac61fa32014-06-23 12:03:11 -07001151 localError := "none"
1152 if err != nil {
1153 localError = err.Error()
1154 }
1155 if len(test.expectedLocalError) != 0 {
1156 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1157 }
Adam Langley95c29f32014-06-20 12:00:00 -07001158
1159 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001160 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001161 if childErr != nil {
1162 childError = childErr.Error()
1163 }
1164
1165 var msg string
1166 switch {
1167 case failed && !test.shouldFail:
1168 msg = "unexpected failure"
1169 case !failed && test.shouldFail:
1170 msg = "unexpected success"
1171 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001172 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001173 default:
1174 panic("internal error")
1175 }
1176
David Benjamin9aafb642016-09-20 19:36:53 -04001177 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 -07001178 }
1179
David Benjamind2ba8892016-09-20 19:41:04 -04001180 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001181 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001182 }
1183
David Benjamind2ba8892016-09-20 19:41:04 -04001184 if *useValgrind && isValgrindError {
1185 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1186 }
1187
Adam Langley95c29f32014-06-20 12:00:00 -07001188 return nil
1189}
1190
David Benjaminaa012042016-12-10 13:33:05 -05001191type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001192 name string
1193 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001194 // excludeFlag is the legacy shim flag to disable the version.
1195 excludeFlag string
1196 hasDTLS bool
1197 // shimTLS and shimDTLS are values the shim uses to refer to these
1198 // versions in TLS and DTLS, respectively.
1199 shimTLS, shimDTLS int
1200}
1201
1202func (vers tlsVersion) shimFlag(protocol protocol) string {
1203 if protocol == dtls {
1204 return strconv.Itoa(vers.shimDTLS)
1205 }
1206 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001207}
1208
1209var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001210 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1211 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1212 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1213 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1214 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001215}
1216
David Benjaminaa012042016-12-10 13:33:05 -05001217type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001218 name string
1219 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001220}
1221
1222var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001223 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001224 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001225 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001226 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001227 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001228 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001229 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001230 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1231 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001232 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1233 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001234 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001235 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001236 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001237 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001238 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001239 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001240 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001241 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001242 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001243 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001244 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1245 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001246 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1247 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001248 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001249 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1250 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1251 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001252 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001253}
1254
David Benjamin8b8c0062014-11-23 02:47:52 -05001255func hasComponent(suiteName, component string) bool {
1256 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1257}
1258
David Benjaminf7768e42014-08-31 02:06:47 -04001259func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001260 return hasComponent(suiteName, "GCM") ||
1261 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001262 hasComponent(suiteName, "SHA384") ||
1263 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001264}
1265
Nick Harper1fd39d82016-06-14 18:14:35 -07001266func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001267 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001268}
1269
David Benjamin8b8c0062014-11-23 02:47:52 -05001270func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001271 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001272}
1273
Adam Langleya7997f12015-05-14 17:38:50 -07001274func bigFromHex(hex string) *big.Int {
1275 ret, ok := new(big.Int).SetString(hex, 16)
1276 if !ok {
1277 panic("failed to parse hex number 0x" + hex)
1278 }
1279 return ret
1280}
1281
Adam Langley7c803a62015-06-15 15:35:05 -07001282func addBasicTests() {
1283 basicTests := []testCase{
1284 {
Adam Langley7c803a62015-06-15 15:35:05 -07001285 name: "NoFallbackSCSV",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 FailIfNotFallbackSCSV: true,
1289 },
1290 },
1291 shouldFail: true,
1292 expectedLocalError: "no fallback SCSV found",
1293 },
1294 {
1295 name: "SendFallbackSCSV",
1296 config: Config{
1297 Bugs: ProtocolBugs{
1298 FailIfNotFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-fallback-scsv"},
1302 },
1303 {
1304 name: "ClientCertificateTypes",
1305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001306 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 ClientAuth: RequestClientCert,
1308 ClientCertificateTypes: []byte{
1309 CertTypeDSSSign,
1310 CertTypeRSASign,
1311 CertTypeECDSASign,
1312 },
1313 },
1314 flags: []string{
1315 "-expect-certificate-types",
1316 base64.StdEncoding.EncodeToString([]byte{
1317 CertTypeDSSSign,
1318 CertTypeRSASign,
1319 CertTypeECDSASign,
1320 }),
1321 },
1322 },
1323 {
Adam Langley7c803a62015-06-15 15:35:05 -07001324 name: "UnauthenticatedECDH",
1325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001326 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1328 Bugs: ProtocolBugs{
1329 UnauthenticatedECDH: true,
1330 },
1331 },
1332 shouldFail: true,
1333 expectedError: ":UNEXPECTED_MESSAGE:",
1334 },
1335 {
1336 name: "SkipCertificateStatus",
1337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001338 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1340 Bugs: ProtocolBugs{
1341 SkipCertificateStatus: true,
1342 },
1343 },
1344 flags: []string{
1345 "-enable-ocsp-stapling",
1346 },
1347 },
1348 {
1349 name: "SkipServerKeyExchange",
1350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001351 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001352 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1353 Bugs: ProtocolBugs{
1354 SkipServerKeyExchange: true,
1355 },
1356 },
1357 shouldFail: true,
1358 expectedError: ":UNEXPECTED_MESSAGE:",
1359 },
1360 {
Adam Langley7c803a62015-06-15 15:35:05 -07001361 testType: serverTest,
1362 name: "Alert",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 SendSpuriousAlert: alertRecordOverflow,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1370 },
1371 {
1372 protocol: dtls,
1373 testType: serverTest,
1374 name: "Alert-DTLS",
1375 config: Config{
1376 Bugs: ProtocolBugs{
1377 SendSpuriousAlert: alertRecordOverflow,
1378 },
1379 },
1380 shouldFail: true,
1381 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1382 },
1383 {
1384 testType: serverTest,
1385 name: "FragmentAlert",
1386 config: Config{
1387 Bugs: ProtocolBugs{
1388 FragmentAlert: true,
1389 SendSpuriousAlert: alertRecordOverflow,
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":BAD_ALERT:",
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "FragmentAlert-DTLS",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 FragmentAlert: true,
1402 SendSpuriousAlert: alertRecordOverflow,
1403 },
1404 },
1405 shouldFail: true,
1406 expectedError: ":BAD_ALERT:",
1407 },
1408 {
1409 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001410 name: "DoubleAlert",
1411 config: Config{
1412 Bugs: ProtocolBugs{
1413 DoubleAlert: true,
1414 SendSpuriousAlert: alertRecordOverflow,
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":BAD_ALERT:",
1419 },
1420 {
1421 protocol: dtls,
1422 testType: serverTest,
1423 name: "DoubleAlert-DTLS",
1424 config: Config{
1425 Bugs: ProtocolBugs{
1426 DoubleAlert: true,
1427 SendSpuriousAlert: alertRecordOverflow,
1428 },
1429 },
1430 shouldFail: true,
1431 expectedError: ":BAD_ALERT:",
1432 },
1433 {
Adam Langley7c803a62015-06-15 15:35:05 -07001434 name: "SkipNewSessionTicket",
1435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001436 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SkipNewSessionTicket: true,
1439 },
1440 },
1441 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001442 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001443 },
1444 {
1445 testType: serverTest,
1446 name: "FallbackSCSV",
1447 config: Config{
1448 MaxVersion: VersionTLS11,
1449 Bugs: ProtocolBugs{
1450 SendFallbackSCSV: true,
1451 },
1452 },
David Benjamin56cadc32016-12-16 19:54:11 -05001453 shouldFail: true,
1454 expectedError: ":INAPPROPRIATE_FALLBACK:",
1455 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001456 },
1457 {
1458 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001459 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001460 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001461 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001462 Bugs: ProtocolBugs{
1463 SendFallbackSCSV: true,
1464 },
1465 },
1466 },
1467 {
1468 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001469 name: "FallbackSCSV-VersionMatch-TLS12",
1470 config: Config{
1471 MaxVersion: VersionTLS12,
1472 Bugs: ProtocolBugs{
1473 SendFallbackSCSV: true,
1474 },
1475 },
1476 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1477 },
1478 {
1479 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001480 name: "FragmentedClientVersion",
1481 config: Config{
1482 Bugs: ProtocolBugs{
1483 MaxHandshakeRecordLength: 1,
1484 FragmentClientVersion: true,
1485 },
1486 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001487 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001488 },
1489 {
Adam Langley7c803a62015-06-15 15:35:05 -07001490 testType: serverTest,
1491 name: "HttpGET",
1492 sendPrefix: "GET / HTTP/1.0\n",
1493 shouldFail: true,
1494 expectedError: ":HTTP_REQUEST:",
1495 },
1496 {
1497 testType: serverTest,
1498 name: "HttpPOST",
1499 sendPrefix: "POST / HTTP/1.0\n",
1500 shouldFail: true,
1501 expectedError: ":HTTP_REQUEST:",
1502 },
1503 {
1504 testType: serverTest,
1505 name: "HttpHEAD",
1506 sendPrefix: "HEAD / HTTP/1.0\n",
1507 shouldFail: true,
1508 expectedError: ":HTTP_REQUEST:",
1509 },
1510 {
1511 testType: serverTest,
1512 name: "HttpPUT",
1513 sendPrefix: "PUT / HTTP/1.0\n",
1514 shouldFail: true,
1515 expectedError: ":HTTP_REQUEST:",
1516 },
1517 {
1518 testType: serverTest,
1519 name: "HttpCONNECT",
1520 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1521 shouldFail: true,
1522 expectedError: ":HTTPS_PROXY_REQUEST:",
1523 },
1524 {
1525 testType: serverTest,
1526 name: "Garbage",
1527 sendPrefix: "blah",
1528 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001529 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001530 },
1531 {
Adam Langley7c803a62015-06-15 15:35:05 -07001532 name: "RSAEphemeralKey",
1533 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001534 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001535 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1536 Bugs: ProtocolBugs{
1537 RSAEphemeralKey: true,
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_MESSAGE:",
1542 },
1543 {
1544 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001545 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001546 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001547 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001548 },
1549 {
1550 protocol: dtls,
1551 name: "DisableEverything-DTLS",
1552 flags: []string{"-no-tls12", "-no-tls1"},
1553 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001554 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001555 },
1556 {
Adam Langley7c803a62015-06-15 15:35:05 -07001557 protocol: dtls,
1558 testType: serverTest,
1559 name: "MTU",
1560 config: Config{
1561 Bugs: ProtocolBugs{
1562 MaxPacketLength: 256,
1563 },
1564 },
1565 flags: []string{"-mtu", "256"},
1566 },
1567 {
1568 protocol: dtls,
1569 testType: serverTest,
1570 name: "MTUExceeded",
1571 config: Config{
1572 Bugs: ProtocolBugs{
1573 MaxPacketLength: 255,
1574 },
1575 },
1576 flags: []string{"-mtu", "256"},
1577 shouldFail: true,
1578 expectedLocalError: "dtls: exceeded maximum packet length",
1579 },
1580 {
Adam Langley7c803a62015-06-15 15:35:05 -07001581 name: "EmptyCertificateList",
1582 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001583 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001584 Bugs: ProtocolBugs{
1585 EmptyCertificateList: true,
1586 },
1587 },
1588 shouldFail: true,
1589 expectedError: ":DECODE_ERROR:",
1590 },
1591 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001592 name: "EmptyCertificateList-TLS13",
1593 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001594 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001595 Bugs: ProtocolBugs{
1596 EmptyCertificateList: true,
1597 },
1598 },
1599 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001600 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001601 },
1602 {
Adam Langley7c803a62015-06-15 15:35:05 -07001603 name: "TLSFatalBadPackets",
1604 damageFirstWrite: true,
1605 shouldFail: true,
1606 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1607 },
1608 {
1609 protocol: dtls,
1610 name: "DTLSIgnoreBadPackets",
1611 damageFirstWrite: true,
1612 },
1613 {
1614 protocol: dtls,
1615 name: "DTLSIgnoreBadPackets-Async",
1616 damageFirstWrite: true,
1617 flags: []string{"-async"},
1618 },
1619 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001620 name: "AppDataBeforeHandshake",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1624 },
1625 },
1626 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001627 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001628 },
1629 {
1630 name: "AppDataBeforeHandshake-Empty",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 AppDataBeforeHandshake: []byte{},
1634 },
1635 },
1636 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001637 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001638 },
1639 {
1640 protocol: dtls,
1641 name: "AppDataBeforeHandshake-DTLS",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "AppDataBeforeHandshake-DTLS-Empty",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 AppDataBeforeHandshake: []byte{},
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
Adam Langley7c803a62015-06-15 15:35:05 -07001662 name: "AppDataAfterChangeCipherSpec",
1663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 Bugs: ProtocolBugs{
1666 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1667 },
1668 },
1669 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001670 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001671 },
1672 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001673 name: "AppDataAfterChangeCipherSpec-Empty",
1674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001675 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001676 Bugs: ProtocolBugs{
1677 AppDataAfterChangeCipherSpec: []byte{},
1678 },
1679 },
1680 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001681 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001682 },
1683 {
Adam Langley7c803a62015-06-15 15:35:05 -07001684 protocol: dtls,
1685 name: "AppDataAfterChangeCipherSpec-DTLS",
1686 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001687 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001688 Bugs: ProtocolBugs{
1689 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1690 },
1691 },
1692 // BoringSSL's DTLS implementation will drop the out-of-order
1693 // application data.
1694 },
1695 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001696 protocol: dtls,
1697 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001699 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001700 Bugs: ProtocolBugs{
1701 AppDataAfterChangeCipherSpec: []byte{},
1702 },
1703 },
1704 // BoringSSL's DTLS implementation will drop the out-of-order
1705 // application data.
1706 },
1707 {
Adam Langley7c803a62015-06-15 15:35:05 -07001708 name: "AlertAfterChangeCipherSpec",
1709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001710 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001711 Bugs: ProtocolBugs{
1712 AlertAfterChangeCipherSpec: alertRecordOverflow,
1713 },
1714 },
1715 shouldFail: true,
1716 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1717 },
1718 {
1719 protocol: dtls,
1720 name: "AlertAfterChangeCipherSpec-DTLS",
1721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001722 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001723 Bugs: ProtocolBugs{
1724 AlertAfterChangeCipherSpec: alertRecordOverflow,
1725 },
1726 },
1727 shouldFail: true,
1728 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1729 },
1730 {
1731 protocol: dtls,
1732 name: "ReorderHandshakeFragments-Small-DTLS",
1733 config: Config{
1734 Bugs: ProtocolBugs{
1735 ReorderHandshakeFragments: true,
1736 // Small enough that every handshake message is
1737 // fragmented.
1738 MaxHandshakeRecordLength: 2,
1739 },
1740 },
1741 },
1742 {
1743 protocol: dtls,
1744 name: "ReorderHandshakeFragments-Large-DTLS",
1745 config: Config{
1746 Bugs: ProtocolBugs{
1747 ReorderHandshakeFragments: true,
1748 // Large enough that no handshake message is
1749 // fragmented.
1750 MaxHandshakeRecordLength: 2048,
1751 },
1752 },
1753 },
1754 {
1755 protocol: dtls,
1756 name: "MixCompleteMessageWithFragments-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 ReorderHandshakeFragments: true,
1760 MixCompleteMessageWithFragments: true,
1761 MaxHandshakeRecordLength: 2,
1762 },
1763 },
1764 },
1765 {
1766 name: "SendInvalidRecordType",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 SendInvalidRecordType: true,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":UNEXPECTED_RECORD:",
1774 },
1775 {
1776 protocol: dtls,
1777 name: "SendInvalidRecordType-DTLS",
1778 config: Config{
1779 Bugs: ProtocolBugs{
1780 SendInvalidRecordType: true,
1781 },
1782 },
1783 shouldFail: true,
1784 expectedError: ":UNEXPECTED_RECORD:",
1785 },
1786 {
1787 name: "FalseStart-SkipServerSecondLeg",
1788 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001789 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1791 NextProtos: []string{"foo"},
1792 Bugs: ProtocolBugs{
1793 SkipNewSessionTicket: true,
1794 SkipChangeCipherSpec: true,
1795 SkipFinished: true,
1796 ExpectFalseStart: true,
1797 },
1798 },
1799 flags: []string{
1800 "-false-start",
1801 "-handshake-never-done",
1802 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001803 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001804 },
1805 shimWritesFirst: true,
1806 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001807 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001808 },
1809 {
1810 name: "FalseStart-SkipServerSecondLeg-Implicit",
1811 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001812 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1814 NextProtos: []string{"foo"},
1815 Bugs: ProtocolBugs{
1816 SkipNewSessionTicket: true,
1817 SkipChangeCipherSpec: true,
1818 SkipFinished: true,
1819 },
1820 },
1821 flags: []string{
1822 "-implicit-handshake",
1823 "-false-start",
1824 "-handshake-never-done",
1825 "-advertise-alpn", "\x03foo",
1826 },
1827 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001828 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001829 },
1830 {
1831 testType: serverTest,
1832 name: "FailEarlyCallback",
1833 flags: []string{"-fail-early-callback"},
1834 shouldFail: true,
1835 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001836 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001837 },
1838 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001839 name: "FailCertCallback-Client-TLS12",
1840 config: Config{
1841 MaxVersion: VersionTLS12,
1842 ClientAuth: RequestClientCert,
1843 },
1844 flags: []string{"-fail-cert-callback"},
1845 shouldFail: true,
1846 expectedError: ":CERT_CB_ERROR:",
1847 expectedLocalError: "remote error: internal error",
1848 },
1849 {
1850 testType: serverTest,
1851 name: "FailCertCallback-Server-TLS12",
1852 config: Config{
1853 MaxVersion: VersionTLS12,
1854 },
1855 flags: []string{"-fail-cert-callback"},
1856 shouldFail: true,
1857 expectedError: ":CERT_CB_ERROR:",
1858 expectedLocalError: "remote error: internal error",
1859 },
1860 {
1861 name: "FailCertCallback-Client-TLS13",
1862 config: Config{
1863 MaxVersion: VersionTLS13,
1864 ClientAuth: RequestClientCert,
1865 },
1866 flags: []string{"-fail-cert-callback"},
1867 shouldFail: true,
1868 expectedError: ":CERT_CB_ERROR:",
1869 expectedLocalError: "remote error: internal error",
1870 },
1871 {
1872 testType: serverTest,
1873 name: "FailCertCallback-Server-TLS13",
1874 config: Config{
1875 MaxVersion: VersionTLS13,
1876 },
1877 flags: []string{"-fail-cert-callback"},
1878 shouldFail: true,
1879 expectedError: ":CERT_CB_ERROR:",
1880 expectedLocalError: "remote error: internal error",
1881 },
1882 {
Adam Langley7c803a62015-06-15 15:35:05 -07001883 protocol: dtls,
1884 name: "FragmentMessageTypeMismatch-DTLS",
1885 config: Config{
1886 Bugs: ProtocolBugs{
1887 MaxHandshakeRecordLength: 2,
1888 FragmentMessageTypeMismatch: true,
1889 },
1890 },
1891 shouldFail: true,
1892 expectedError: ":FRAGMENT_MISMATCH:",
1893 },
1894 {
1895 protocol: dtls,
1896 name: "FragmentMessageLengthMismatch-DTLS",
1897 config: Config{
1898 Bugs: ProtocolBugs{
1899 MaxHandshakeRecordLength: 2,
1900 FragmentMessageLengthMismatch: true,
1901 },
1902 },
1903 shouldFail: true,
1904 expectedError: ":FRAGMENT_MISMATCH:",
1905 },
1906 {
1907 protocol: dtls,
1908 name: "SplitFragments-Header-DTLS",
1909 config: Config{
1910 Bugs: ProtocolBugs{
1911 SplitFragments: 2,
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-Boundary-DTLS",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 SplitFragments: dtlsRecordHeaderLen,
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: "SplitFragments-Body-DTLS",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SplitFragments: dtlsRecordHeaderLen + 1,
1934 },
1935 },
1936 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001937 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001938 },
1939 {
1940 protocol: dtls,
1941 name: "SendEmptyFragments-DTLS",
1942 config: Config{
1943 Bugs: ProtocolBugs{
1944 SendEmptyFragments: true,
1945 },
1946 },
1947 },
1948 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001949 name: "BadFinished-Client",
1950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001951 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001952 Bugs: ProtocolBugs{
1953 BadFinished: true,
1954 },
1955 },
1956 shouldFail: true,
1957 expectedError: ":DIGEST_CHECK_FAILED:",
1958 },
1959 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001960 name: "BadFinished-Client-TLS13",
1961 config: Config{
1962 MaxVersion: VersionTLS13,
1963 Bugs: ProtocolBugs{
1964 BadFinished: true,
1965 },
1966 },
1967 shouldFail: true,
1968 expectedError: ":DIGEST_CHECK_FAILED:",
1969 },
1970 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001971 testType: serverTest,
1972 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001974 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001975 Bugs: ProtocolBugs{
1976 BadFinished: true,
1977 },
1978 },
1979 shouldFail: true,
1980 expectedError: ":DIGEST_CHECK_FAILED:",
1981 },
1982 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001983 testType: serverTest,
1984 name: "BadFinished-Server-TLS13",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 Bugs: ProtocolBugs{
1988 BadFinished: true,
1989 },
1990 },
1991 shouldFail: true,
1992 expectedError: ":DIGEST_CHECK_FAILED:",
1993 },
1994 {
Adam Langley7c803a62015-06-15 15:35:05 -07001995 name: "FalseStart-BadFinished",
1996 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001997 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1999 NextProtos: []string{"foo"},
2000 Bugs: ProtocolBugs{
2001 BadFinished: true,
2002 ExpectFalseStart: true,
2003 },
2004 },
2005 flags: []string{
2006 "-false-start",
2007 "-handshake-never-done",
2008 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002009 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002010 },
2011 shimWritesFirst: true,
2012 shouldFail: true,
2013 expectedError: ":DIGEST_CHECK_FAILED:",
2014 },
2015 {
2016 name: "NoFalseStart-NoALPN",
2017 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002018 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002019 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2020 Bugs: ProtocolBugs{
2021 ExpectFalseStart: true,
2022 AlertBeforeFalseStartTest: alertAccessDenied,
2023 },
2024 },
2025 flags: []string{
2026 "-false-start",
2027 },
2028 shimWritesFirst: true,
2029 shouldFail: true,
2030 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2031 expectedLocalError: "tls: peer did not false start: EOF",
2032 },
2033 {
2034 name: "NoFalseStart-NoAEAD",
2035 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002036 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2038 NextProtos: []string{"foo"},
2039 Bugs: ProtocolBugs{
2040 ExpectFalseStart: true,
2041 AlertBeforeFalseStartTest: alertAccessDenied,
2042 },
2043 },
2044 flags: []string{
2045 "-false-start",
2046 "-advertise-alpn", "\x03foo",
2047 },
2048 shimWritesFirst: true,
2049 shouldFail: true,
2050 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2051 expectedLocalError: "tls: peer did not false start: EOF",
2052 },
2053 {
2054 name: "NoFalseStart-RSA",
2055 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002056 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002057 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2058 NextProtos: []string{"foo"},
2059 Bugs: ProtocolBugs{
2060 ExpectFalseStart: true,
2061 AlertBeforeFalseStartTest: alertAccessDenied,
2062 },
2063 },
2064 flags: []string{
2065 "-false-start",
2066 "-advertise-alpn", "\x03foo",
2067 },
2068 shimWritesFirst: true,
2069 shouldFail: true,
2070 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2071 expectedLocalError: "tls: peer did not false start: EOF",
2072 },
2073 {
Adam Langley7c803a62015-06-15 15:35:05 -07002074 protocol: dtls,
2075 name: "SendSplitAlert-Sync",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 SendSplitAlert: true,
2079 },
2080 },
2081 },
2082 {
2083 protocol: dtls,
2084 name: "SendSplitAlert-Async",
2085 config: Config{
2086 Bugs: ProtocolBugs{
2087 SendSplitAlert: true,
2088 },
2089 },
2090 flags: []string{"-async"},
2091 },
2092 {
2093 protocol: dtls,
2094 name: "PackDTLSHandshake",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 MaxHandshakeRecordLength: 2,
2098 PackHandshakeFragments: 20,
2099 PackHandshakeRecords: 200,
2100 },
2101 },
2102 },
2103 {
Adam Langley7c803a62015-06-15 15:35:05 -07002104 name: "SendEmptyRecords-Pass",
2105 sendEmptyRecords: 32,
2106 },
2107 {
2108 name: "SendEmptyRecords",
2109 sendEmptyRecords: 33,
2110 shouldFail: true,
2111 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2112 },
2113 {
2114 name: "SendEmptyRecords-Async",
2115 sendEmptyRecords: 33,
2116 flags: []string{"-async"},
2117 shouldFail: true,
2118 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2119 },
2120 {
David Benjamine8e84b92016-08-03 15:39:47 -04002121 name: "SendWarningAlerts-Pass",
2122 config: Config{
2123 MaxVersion: VersionTLS12,
2124 },
Adam Langley7c803a62015-06-15 15:35:05 -07002125 sendWarningAlerts: 4,
2126 },
2127 {
David Benjamine8e84b92016-08-03 15:39:47 -04002128 protocol: dtls,
2129 name: "SendWarningAlerts-DTLS-Pass",
2130 config: Config{
2131 MaxVersion: VersionTLS12,
2132 },
Adam Langley7c803a62015-06-15 15:35:05 -07002133 sendWarningAlerts: 4,
2134 },
2135 {
David Benjamine8e84b92016-08-03 15:39:47 -04002136 name: "SendWarningAlerts-TLS13",
2137 config: Config{
2138 MaxVersion: VersionTLS13,
2139 },
2140 sendWarningAlerts: 4,
2141 shouldFail: true,
2142 expectedError: ":BAD_ALERT:",
2143 expectedLocalError: "remote error: error decoding message",
2144 },
2145 {
2146 name: "SendWarningAlerts",
2147 config: Config{
2148 MaxVersion: VersionTLS12,
2149 },
Adam Langley7c803a62015-06-15 15:35:05 -07002150 sendWarningAlerts: 5,
2151 shouldFail: true,
2152 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2153 },
2154 {
David Benjamine8e84b92016-08-03 15:39:47 -04002155 name: "SendWarningAlerts-Async",
2156 config: Config{
2157 MaxVersion: VersionTLS12,
2158 },
Adam Langley7c803a62015-06-15 15:35:05 -07002159 sendWarningAlerts: 5,
2160 flags: []string{"-async"},
2161 shouldFail: true,
2162 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2163 },
David Benjaminba4594a2015-06-18 18:36:15 -04002164 {
David Benjamin24e58862017-06-14 18:45:29 -04002165 name: "SendBogusAlertType",
2166 sendBogusAlertType: true,
2167 shouldFail: true,
2168 expectedError: ":UNKNOWN_ALERT_TYPE:",
2169 expectedLocalError: "remote error: illegal parameter",
2170 },
2171 {
2172 protocol: dtls,
2173 name: "SendBogusAlertType-DTLS",
2174 sendBogusAlertType: true,
2175 shouldFail: true,
2176 expectedError: ":UNKNOWN_ALERT_TYPE:",
2177 expectedLocalError: "remote error: illegal parameter",
2178 },
2179 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002180 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002181 config: Config{
2182 MaxVersion: VersionTLS13,
2183 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002184 sendKeyUpdates: 33,
2185 keyUpdateRequest: keyUpdateNotRequested,
2186 shouldFail: true,
2187 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002188 },
2189 {
David Benjaminba4594a2015-06-18 18:36:15 -04002190 name: "EmptySessionID",
2191 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002192 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002193 SessionTicketsDisabled: true,
2194 },
2195 noSessionCache: true,
2196 flags: []string{"-expect-no-session"},
2197 },
David Benjamin30789da2015-08-29 22:56:45 -04002198 {
2199 name: "Unclean-Shutdown",
2200 config: Config{
2201 Bugs: ProtocolBugs{
2202 NoCloseNotify: true,
2203 ExpectCloseNotify: true,
2204 },
2205 },
2206 shimShutsDown: true,
2207 flags: []string{"-check-close-notify"},
2208 shouldFail: true,
2209 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2210 },
2211 {
2212 name: "Unclean-Shutdown-Ignored",
2213 config: Config{
2214 Bugs: ProtocolBugs{
2215 NoCloseNotify: true,
2216 },
2217 },
2218 shimShutsDown: true,
2219 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002220 {
David Benjaminfa214e42016-05-10 17:03:10 -04002221 name: "Unclean-Shutdown-Alert",
2222 config: Config{
2223 Bugs: ProtocolBugs{
2224 SendAlertOnShutdown: alertDecompressionFailure,
2225 ExpectCloseNotify: true,
2226 },
2227 },
2228 shimShutsDown: true,
2229 flags: []string{"-check-close-notify"},
2230 shouldFail: true,
2231 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2232 },
2233 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002234 name: "LargePlaintext",
2235 config: Config{
2236 Bugs: ProtocolBugs{
2237 SendLargeRecords: true,
2238 },
2239 },
2240 messageLen: maxPlaintext + 1,
2241 shouldFail: true,
2242 expectedError: ":DATA_LENGTH_TOO_LONG:",
2243 },
2244 {
2245 protocol: dtls,
2246 name: "LargePlaintext-DTLS",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendLargeRecords: true,
2250 },
2251 },
2252 messageLen: maxPlaintext + 1,
2253 shouldFail: true,
2254 expectedError: ":DATA_LENGTH_TOO_LONG:",
2255 },
2256 {
2257 name: "LargeCiphertext",
2258 config: Config{
2259 Bugs: ProtocolBugs{
2260 SendLargeRecords: true,
2261 },
2262 },
2263 messageLen: maxPlaintext * 2,
2264 shouldFail: true,
2265 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2266 },
2267 {
2268 protocol: dtls,
2269 name: "LargeCiphertext-DTLS",
2270 config: Config{
2271 Bugs: ProtocolBugs{
2272 SendLargeRecords: true,
2273 },
2274 },
2275 messageLen: maxPlaintext * 2,
2276 // Unlike the other four cases, DTLS drops records which
2277 // are invalid before authentication, so the connection
2278 // does not fail.
2279 expectMessageDropped: true,
2280 },
David Benjamindd6fed92015-10-23 17:41:12 -04002281 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002282 name: "BadHelloRequest-1",
2283 renegotiate: 1,
2284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002285 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002286 Bugs: ProtocolBugs{
2287 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2288 },
2289 },
2290 flags: []string{
2291 "-renegotiate-freely",
2292 "-expect-total-renegotiations", "1",
2293 },
2294 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002295 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002296 },
2297 {
2298 name: "BadHelloRequest-2",
2299 renegotiate: 1,
2300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002301 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002302 Bugs: ProtocolBugs{
2303 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2304 },
2305 },
2306 flags: []string{
2307 "-renegotiate-freely",
2308 "-expect-total-renegotiations", "1",
2309 },
2310 shouldFail: true,
2311 expectedError: ":BAD_HELLO_REQUEST:",
2312 },
David Benjaminef1b0092015-11-21 14:05:44 -05002313 {
2314 testType: serverTest,
2315 name: "SupportTicketsWithSessionID",
2316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002317 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002318 SessionTicketsDisabled: true,
2319 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002320 resumeConfig: &Config{
2321 MaxVersion: VersionTLS12,
2322 },
David Benjaminef1b0092015-11-21 14:05:44 -05002323 resumeSession: true,
2324 },
David Benjamin02edcd02016-07-27 17:40:37 -04002325 {
2326 protocol: dtls,
2327 name: "DTLS-SendExtraFinished",
2328 config: Config{
2329 Bugs: ProtocolBugs{
2330 SendExtraFinished: true,
2331 },
2332 },
2333 shouldFail: true,
2334 expectedError: ":UNEXPECTED_RECORD:",
2335 },
2336 {
2337 protocol: dtls,
2338 name: "DTLS-SendExtraFinished-Reordered",
2339 config: Config{
2340 Bugs: ProtocolBugs{
2341 MaxHandshakeRecordLength: 2,
2342 ReorderHandshakeFragments: true,
2343 SendExtraFinished: true,
2344 },
2345 },
2346 shouldFail: true,
2347 expectedError: ":UNEXPECTED_RECORD:",
2348 },
David Benjamine97fb482016-07-29 09:23:07 -04002349 {
2350 testType: serverTest,
2351 name: "V2ClientHello-EmptyRecordPrefix",
2352 config: Config{
2353 // Choose a cipher suite that does not involve
2354 // elliptic curves, so no extensions are
2355 // involved.
2356 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002357 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002358 Bugs: ProtocolBugs{
2359 SendV2ClientHello: true,
2360 },
2361 },
2362 sendPrefix: string([]byte{
2363 byte(recordTypeHandshake),
2364 3, 1, // version
2365 0, 0, // length
2366 }),
2367 // A no-op empty record may not be sent before V2ClientHello.
2368 shouldFail: true,
2369 expectedError: ":WRONG_VERSION_NUMBER:",
2370 },
2371 {
2372 testType: serverTest,
2373 name: "V2ClientHello-WarningAlertPrefix",
2374 config: Config{
2375 // Choose a cipher suite that does not involve
2376 // elliptic curves, so no extensions are
2377 // involved.
2378 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002379 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002380 Bugs: ProtocolBugs{
2381 SendV2ClientHello: true,
2382 },
2383 },
2384 sendPrefix: string([]byte{
2385 byte(recordTypeAlert),
2386 3, 1, // version
2387 0, 2, // length
2388 alertLevelWarning, byte(alertDecompressionFailure),
2389 }),
2390 // A no-op warning alert may not be sent before V2ClientHello.
2391 shouldFail: true,
2392 expectedError: ":WRONG_VERSION_NUMBER:",
2393 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002394 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002395 name: "KeyUpdate-Client",
2396 config: Config{
2397 MaxVersion: VersionTLS13,
2398 },
2399 sendKeyUpdates: 1,
2400 keyUpdateRequest: keyUpdateNotRequested,
2401 },
2402 {
2403 testType: serverTest,
2404 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002405 config: Config{
2406 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002407 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002408 sendKeyUpdates: 1,
2409 keyUpdateRequest: keyUpdateNotRequested,
2410 },
2411 {
2412 name: "KeyUpdate-InvalidRequestMode",
2413 config: Config{
2414 MaxVersion: VersionTLS13,
2415 },
2416 sendKeyUpdates: 1,
2417 keyUpdateRequest: 42,
2418 shouldFail: true,
2419 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002420 },
David Benjaminabe94e32016-09-04 14:18:58 -04002421 {
David Benjaminbbba9392017-04-06 12:54:12 -04002422 // Test that KeyUpdates are acknowledged properly.
2423 name: "KeyUpdate-RequestACK",
2424 config: Config{
2425 MaxVersion: VersionTLS13,
2426 Bugs: ProtocolBugs{
2427 RejectUnsolicitedKeyUpdate: true,
2428 },
2429 },
2430 // Test the shim receiving many KeyUpdates in a row.
2431 sendKeyUpdates: 5,
2432 messageCount: 5,
2433 keyUpdateRequest: keyUpdateRequested,
2434 },
2435 {
2436 // Test that KeyUpdates are acknowledged properly if the
2437 // peer's KeyUpdate is discovered while a write is
2438 // pending.
2439 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2440 config: Config{
2441 MaxVersion: VersionTLS13,
2442 Bugs: ProtocolBugs{
2443 RejectUnsolicitedKeyUpdate: true,
2444 },
2445 },
2446 // Test the shim receiving many KeyUpdates in a row.
2447 sendKeyUpdates: 5,
2448 messageCount: 5,
2449 keyUpdateRequest: keyUpdateRequested,
2450 readWithUnfinishedWrite: true,
2451 flags: []string{"-async"},
2452 },
2453 {
David Benjaminabe94e32016-09-04 14:18:58 -04002454 name: "SendSNIWarningAlert",
2455 config: Config{
2456 MaxVersion: VersionTLS12,
2457 Bugs: ProtocolBugs{
2458 SendSNIWarningAlert: true,
2459 },
2460 },
2461 },
David Benjaminc241d792016-09-09 10:34:20 -04002462 {
2463 testType: serverTest,
2464 name: "ExtraCompressionMethods-TLS12",
2465 config: Config{
2466 MaxVersion: VersionTLS12,
2467 Bugs: ProtocolBugs{
2468 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2469 },
2470 },
2471 },
2472 {
2473 testType: serverTest,
2474 name: "ExtraCompressionMethods-TLS13",
2475 config: Config{
2476 MaxVersion: VersionTLS13,
2477 Bugs: ProtocolBugs{
2478 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2479 },
2480 },
2481 shouldFail: true,
2482 expectedError: ":INVALID_COMPRESSION_LIST:",
2483 expectedLocalError: "remote error: illegal parameter",
2484 },
2485 {
2486 testType: serverTest,
2487 name: "NoNullCompression-TLS12",
2488 config: Config{
2489 MaxVersion: VersionTLS12,
2490 Bugs: ProtocolBugs{
2491 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2492 },
2493 },
2494 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002495 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002496 expectedLocalError: "remote error: illegal parameter",
2497 },
2498 {
2499 testType: serverTest,
2500 name: "NoNullCompression-TLS13",
2501 config: Config{
2502 MaxVersion: VersionTLS13,
2503 Bugs: ProtocolBugs{
2504 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2505 },
2506 },
2507 shouldFail: true,
2508 expectedError: ":INVALID_COMPRESSION_LIST:",
2509 expectedLocalError: "remote error: illegal parameter",
2510 },
David Benjamin413e79e2017-07-01 10:11:53 -04002511 // Test that the client rejects invalid compression methods
2512 // from the server.
2513 {
2514 testType: clientTest,
2515 name: "InvalidCompressionMethod",
2516 config: Config{
2517 MaxVersion: VersionTLS12,
2518 Bugs: ProtocolBugs{
2519 SendCompressionMethod: 1,
2520 },
2521 },
2522 shouldFail: true,
2523 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2524 expectedLocalError: "remote error: illegal parameter",
2525 },
David Benjamin65ac9972016-09-02 21:35:25 -04002526 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002527 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002528 config: Config{
2529 MaxVersion: VersionTLS12,
2530 Bugs: ProtocolBugs{
2531 ExpectGREASE: true,
2532 },
2533 },
2534 flags: []string{"-enable-grease"},
2535 },
2536 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002537 name: "GREASE-Client-TLS13",
2538 config: Config{
2539 MaxVersion: VersionTLS13,
2540 Bugs: ProtocolBugs{
2541 ExpectGREASE: true,
2542 },
2543 },
2544 flags: []string{"-enable-grease"},
2545 },
2546 {
2547 testType: serverTest,
2548 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002549 config: Config{
2550 MaxVersion: VersionTLS13,
2551 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002552 // TLS 1.3 servers are expected to
2553 // always enable GREASE. TLS 1.3 is new,
2554 // so there is no existing ecosystem to
2555 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002556 ExpectGREASE: true,
2557 },
2558 },
David Benjamin65ac9972016-09-02 21:35:25 -04002559 },
David Benjamine3fbb362017-01-06 16:19:28 -05002560 {
2561 // Test the server so there is a large certificate as
2562 // well as application data.
2563 testType: serverTest,
2564 name: "MaxSendFragment",
2565 config: Config{
2566 Bugs: ProtocolBugs{
2567 MaxReceivePlaintext: 512,
2568 },
2569 },
2570 messageLen: 1024,
2571 flags: []string{
2572 "-max-send-fragment", "512",
2573 "-read-size", "1024",
2574 },
2575 },
2576 {
2577 // Test the server so there is a large certificate as
2578 // well as application data.
2579 testType: serverTest,
2580 name: "MaxSendFragment-TooLarge",
2581 config: Config{
2582 Bugs: ProtocolBugs{
2583 // Ensure that some of the records are
2584 // 512.
2585 MaxReceivePlaintext: 511,
2586 },
2587 },
2588 messageLen: 1024,
2589 flags: []string{
2590 "-max-send-fragment", "512",
2591 "-read-size", "1024",
2592 },
2593 shouldFail: true,
2594 expectedLocalError: "local error: record overflow",
2595 },
Adam Langley7c803a62015-06-15 15:35:05 -07002596 }
Adam Langley7c803a62015-06-15 15:35:05 -07002597 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002598
2599 // Test that very large messages can be received.
2600 cert := rsaCertificate
2601 for i := 0; i < 50; i++ {
2602 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2603 }
2604 testCases = append(testCases, testCase{
2605 name: "LargeMessage",
2606 config: Config{
2607 Certificates: []Certificate{cert},
2608 },
2609 })
2610 testCases = append(testCases, testCase{
2611 protocol: dtls,
2612 name: "LargeMessage-DTLS",
2613 config: Config{
2614 Certificates: []Certificate{cert},
2615 },
2616 })
2617
2618 // They are rejected if the maximum certificate chain length is capped.
2619 testCases = append(testCases, testCase{
2620 name: "LargeMessage-Reject",
2621 config: Config{
2622 Certificates: []Certificate{cert},
2623 },
2624 flags: []string{"-max-cert-list", "16384"},
2625 shouldFail: true,
2626 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2627 })
2628 testCases = append(testCases, testCase{
2629 protocol: dtls,
2630 name: "LargeMessage-Reject-DTLS",
2631 config: Config{
2632 Certificates: []Certificate{cert},
2633 },
2634 flags: []string{"-max-cert-list", "16384"},
2635 shouldFail: true,
2636 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2637 })
Adam Langley7c803a62015-06-15 15:35:05 -07002638}
2639
David Benjaminaa012042016-12-10 13:33:05 -05002640func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2641 const psk = "12345"
2642 const pskIdentity = "luggage combo"
2643
2644 var prefix string
2645 if protocol == dtls {
2646 if !ver.hasDTLS {
2647 return
2648 }
2649 prefix = "D"
2650 }
2651
2652 var cert Certificate
2653 var certFile string
2654 var keyFile string
2655 if hasComponent(suite.name, "ECDSA") {
2656 cert = ecdsaP256Certificate
2657 certFile = ecdsaP256CertificateFile
2658 keyFile = ecdsaP256KeyFile
2659 } else {
2660 cert = rsaCertificate
2661 certFile = rsaCertificateFile
2662 keyFile = rsaKeyFile
2663 }
2664
2665 var flags []string
2666 if hasComponent(suite.name, "PSK") {
2667 flags = append(flags,
2668 "-psk", psk,
2669 "-psk-identity", pskIdentity)
2670 }
2671 if hasComponent(suite.name, "NULL") {
2672 // NULL ciphers must be explicitly enabled.
2673 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2674 }
David Benjaminaa012042016-12-10 13:33:05 -05002675
2676 var shouldServerFail, shouldClientFail bool
2677 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2678 // BoringSSL clients accept ECDHE on SSLv3, but
2679 // a BoringSSL server will never select it
2680 // because the extension is missing.
2681 shouldServerFail = true
2682 }
2683 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2684 shouldClientFail = true
2685 shouldServerFail = true
2686 }
2687 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2688 shouldClientFail = true
2689 shouldServerFail = true
2690 }
2691 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2692 shouldClientFail = true
2693 shouldServerFail = true
2694 }
2695 if !isDTLSCipher(suite.name) && protocol == dtls {
2696 shouldClientFail = true
2697 shouldServerFail = true
2698 }
2699
2700 var sendCipherSuite uint16
2701 var expectedServerError, expectedClientError string
2702 serverCipherSuites := []uint16{suite.id}
2703 if shouldServerFail {
2704 expectedServerError = ":NO_SHARED_CIPHER:"
2705 }
2706 if shouldClientFail {
2707 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2708 // Configure the server to select ciphers as normal but
2709 // select an incompatible cipher in ServerHello.
2710 serverCipherSuites = nil
2711 sendCipherSuite = suite.id
2712 }
2713
David Benjamincdb6fe92017-02-07 16:06:48 -05002714 // For cipher suites and versions where exporters are defined, verify
2715 // that they interoperate.
2716 var exportKeyingMaterial int
2717 if ver.version > VersionSSL30 {
2718 exportKeyingMaterial = 1024
2719 }
2720
David Benjaminaa012042016-12-10 13:33:05 -05002721 testCases = append(testCases, testCase{
2722 testType: serverTest,
2723 protocol: protocol,
2724 name: prefix + ver.name + "-" + suite.name + "-server",
2725 config: Config{
2726 MinVersion: ver.version,
2727 MaxVersion: ver.version,
2728 CipherSuites: []uint16{suite.id},
2729 Certificates: []Certificate{cert},
2730 PreSharedKey: []byte(psk),
2731 PreSharedKeyIdentity: pskIdentity,
2732 Bugs: ProtocolBugs{
2733 AdvertiseAllConfiguredCiphers: true,
2734 },
2735 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002736 certFile: certFile,
2737 keyFile: keyFile,
2738 flags: flags,
2739 resumeSession: true,
2740 shouldFail: shouldServerFail,
2741 expectedError: expectedServerError,
2742 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002743 })
2744
2745 testCases = append(testCases, testCase{
2746 testType: clientTest,
2747 protocol: protocol,
2748 name: prefix + ver.name + "-" + suite.name + "-client",
2749 config: Config{
2750 MinVersion: ver.version,
2751 MaxVersion: ver.version,
2752 CipherSuites: serverCipherSuites,
2753 Certificates: []Certificate{cert},
2754 PreSharedKey: []byte(psk),
2755 PreSharedKeyIdentity: pskIdentity,
2756 Bugs: ProtocolBugs{
2757 IgnorePeerCipherPreferences: shouldClientFail,
2758 SendCipherSuite: sendCipherSuite,
2759 },
2760 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002761 flags: flags,
2762 resumeSession: true,
2763 shouldFail: shouldClientFail,
2764 expectedError: expectedClientError,
2765 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002766 })
2767
David Benjamin6f600d62016-12-21 16:06:54 -05002768 if shouldClientFail {
2769 return
2770 }
2771
2772 // Ensure the maximum record size is accepted.
2773 testCases = append(testCases, testCase{
2774 protocol: protocol,
2775 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2776 config: Config{
2777 MinVersion: ver.version,
2778 MaxVersion: ver.version,
2779 CipherSuites: []uint16{suite.id},
2780 Certificates: []Certificate{cert},
2781 PreSharedKey: []byte(psk),
2782 PreSharedKeyIdentity: pskIdentity,
2783 },
2784 flags: flags,
2785 messageLen: maxPlaintext,
2786 })
2787
2788 // Test bad records for all ciphers. Bad records are fatal in TLS
2789 // and ignored in DTLS.
2790 var shouldFail bool
2791 var expectedError string
2792 if protocol == tls {
2793 shouldFail = true
2794 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2795 }
2796
2797 testCases = append(testCases, testCase{
2798 protocol: protocol,
2799 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2800 config: Config{
2801 MinVersion: ver.version,
2802 MaxVersion: ver.version,
2803 CipherSuites: []uint16{suite.id},
2804 Certificates: []Certificate{cert},
2805 PreSharedKey: []byte(psk),
2806 PreSharedKeyIdentity: pskIdentity,
2807 },
2808 flags: flags,
2809 damageFirstWrite: true,
2810 messageLen: maxPlaintext,
2811 shouldFail: shouldFail,
2812 expectedError: expectedError,
2813 })
David Benjaminaa012042016-12-10 13:33:05 -05002814}
2815
Adam Langley95c29f32014-06-20 12:00:00 -07002816func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002817 const bogusCipher = 0xfe00
2818
Adam Langley95c29f32014-06-20 12:00:00 -07002819 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002820 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002821 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002822 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002823 }
David Benjamin2c99d282015-09-01 10:23:00 -04002824 }
Adam Langley95c29f32014-06-20 12:00:00 -07002825 }
Adam Langleya7997f12015-05-14 17:38:50 -07002826
2827 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002828 name: "NoSharedCipher",
2829 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002830 MaxVersion: VersionTLS12,
2831 CipherSuites: []uint16{},
2832 },
2833 shouldFail: true,
2834 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2835 })
2836
2837 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002838 name: "NoSharedCipher-TLS13",
2839 config: Config{
2840 MaxVersion: VersionTLS13,
2841 CipherSuites: []uint16{},
2842 },
2843 shouldFail: true,
2844 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2845 })
2846
2847 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002848 name: "UnsupportedCipherSuite",
2849 config: Config{
2850 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002851 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002852 Bugs: ProtocolBugs{
2853 IgnorePeerCipherPreferences: true,
2854 },
2855 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002856 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002857 shouldFail: true,
2858 expectedError: ":WRONG_CIPHER_RETURNED:",
2859 })
2860
2861 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002862 name: "ServerHelloBogusCipher",
2863 config: Config{
2864 MaxVersion: VersionTLS12,
2865 Bugs: ProtocolBugs{
2866 SendCipherSuite: bogusCipher,
2867 },
2868 },
2869 shouldFail: true,
2870 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2871 })
2872 testCases = append(testCases, testCase{
2873 name: "ServerHelloBogusCipher-TLS13",
2874 config: Config{
2875 MaxVersion: VersionTLS13,
2876 Bugs: ProtocolBugs{
2877 SendCipherSuite: bogusCipher,
2878 },
2879 },
2880 shouldFail: true,
2881 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2882 })
2883
David Benjamin241ae832016-01-15 03:04:54 -05002884 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002885 testCases = append(testCases, testCase{
2886 testType: serverTest,
2887 name: "UnknownCipher",
2888 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002889 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002890 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002891 Bugs: ProtocolBugs{
2892 AdvertiseAllConfiguredCiphers: true,
2893 },
2894 },
2895 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002896
2897 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002898 testCases = append(testCases, testCase{
2899 testType: serverTest,
2900 name: "UnknownCipher-TLS13",
2901 config: Config{
2902 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002903 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002904 Bugs: ProtocolBugs{
2905 AdvertiseAllConfiguredCiphers: true,
2906 },
David Benjamin241ae832016-01-15 03:04:54 -05002907 },
2908 })
2909
David Benjamin78679342016-09-16 19:42:05 -04002910 // Test empty ECDHE_PSK identity hints work as expected.
2911 testCases = append(testCases, testCase{
2912 name: "EmptyECDHEPSKHint",
2913 config: Config{
2914 MaxVersion: VersionTLS12,
2915 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2916 PreSharedKey: []byte("secret"),
2917 },
2918 flags: []string{"-psk", "secret"},
2919 })
2920
2921 // Test empty PSK identity hints work as expected, even if an explicit
2922 // ServerKeyExchange is sent.
2923 testCases = append(testCases, testCase{
2924 name: "ExplicitEmptyPSKHint",
2925 config: Config{
2926 MaxVersion: VersionTLS12,
2927 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2928 PreSharedKey: []byte("secret"),
2929 Bugs: ProtocolBugs{
2930 AlwaysSendPreSharedKeyIdentityHint: true,
2931 },
2932 },
2933 flags: []string{"-psk", "secret"},
2934 })
David Benjamin69522112017-03-28 15:38:29 -05002935
2936 // Test that clients enforce that the server-sent certificate and cipher
2937 // suite match in TLS 1.2.
2938 testCases = append(testCases, testCase{
2939 name: "CertificateCipherMismatch-RSA",
2940 config: Config{
2941 MaxVersion: VersionTLS12,
2942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2943 Certificates: []Certificate{rsaCertificate},
2944 Bugs: ProtocolBugs{
2945 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2946 },
2947 },
2948 shouldFail: true,
2949 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2950 })
2951 testCases = append(testCases, testCase{
2952 name: "CertificateCipherMismatch-ECDSA",
2953 config: Config{
2954 MaxVersion: VersionTLS12,
2955 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2956 Certificates: []Certificate{ecdsaP256Certificate},
2957 Bugs: ProtocolBugs{
2958 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2959 },
2960 },
2961 shouldFail: true,
2962 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2963 })
2964 testCases = append(testCases, testCase{
2965 name: "CertificateCipherMismatch-Ed25519",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2969 Certificates: []Certificate{ed25519Certificate},
2970 Bugs: ProtocolBugs{
2971 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2972 },
2973 },
2974 shouldFail: true,
2975 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2976 })
2977
2978 // Test that servers decline to select a cipher suite which is
2979 // inconsistent with their configured certificate.
2980 testCases = append(testCases, testCase{
2981 testType: serverTest,
2982 name: "ServerCipherFilter-RSA",
2983 config: Config{
2984 MaxVersion: VersionTLS12,
2985 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2986 },
2987 flags: []string{
2988 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2989 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2990 },
2991 shouldFail: true,
2992 expectedError: ":NO_SHARED_CIPHER:",
2993 })
2994 testCases = append(testCases, testCase{
2995 testType: serverTest,
2996 name: "ServerCipherFilter-ECDSA",
2997 config: Config{
2998 MaxVersion: VersionTLS12,
2999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3000 },
3001 flags: []string{
3002 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3003 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3004 },
3005 shouldFail: true,
3006 expectedError: ":NO_SHARED_CIPHER:",
3007 })
3008 testCases = append(testCases, testCase{
3009 testType: serverTest,
3010 name: "ServerCipherFilter-Ed25519",
3011 config: Config{
3012 MaxVersion: VersionTLS12,
3013 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3014 },
3015 flags: []string{
3016 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3017 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3018 },
3019 shouldFail: true,
3020 expectedError: ":NO_SHARED_CIPHER:",
3021 })
David Benjamin364af782017-07-01 10:35:27 -04003022
3023 // Test cipher suite negotiation works as expected. Configure a
3024 // complicated cipher suite configuration.
3025 const negotiationTestCiphers = "" +
3026 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3027 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3028 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3029 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3030 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3031 negotiationTests := []struct {
3032 ciphers []uint16
3033 expected uint16
3034 }{
3035 // Server preferences are honored, including when
3036 // equipreference groups are involved.
3037 {
3038 []uint16{
3039 TLS_RSA_WITH_AES_256_GCM_SHA384,
3040 TLS_RSA_WITH_AES_128_CBC_SHA,
3041 TLS_RSA_WITH_AES_128_GCM_SHA256,
3042 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3043 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3044 },
3045 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3046 },
3047 {
3048 []uint16{
3049 TLS_RSA_WITH_AES_256_GCM_SHA384,
3050 TLS_RSA_WITH_AES_128_CBC_SHA,
3051 TLS_RSA_WITH_AES_128_GCM_SHA256,
3052 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3053 },
3054 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3055 },
3056 {
3057 []uint16{
3058 TLS_RSA_WITH_AES_256_GCM_SHA384,
3059 TLS_RSA_WITH_AES_128_CBC_SHA,
3060 TLS_RSA_WITH_AES_128_GCM_SHA256,
3061 },
3062 TLS_RSA_WITH_AES_128_GCM_SHA256,
3063 },
3064 {
3065 []uint16{
3066 TLS_RSA_WITH_AES_256_GCM_SHA384,
3067 TLS_RSA_WITH_AES_128_CBC_SHA,
3068 },
3069 TLS_RSA_WITH_AES_128_CBC_SHA,
3070 },
3071 // Equipreference groups use the client preference.
3072 {
3073 []uint16{
3074 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3075 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3076 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3077 },
3078 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3079 },
3080 {
3081 []uint16{
3082 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3083 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3084 },
3085 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3086 },
3087 {
3088 []uint16{
3089 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3090 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3091 },
3092 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3093 },
3094 {
3095 []uint16{
3096 TLS_RSA_WITH_AES_256_GCM_SHA384,
3097 TLS_RSA_WITH_AES_256_CBC_SHA,
3098 },
3099 TLS_RSA_WITH_AES_256_GCM_SHA384,
3100 },
3101 {
3102 []uint16{
3103 TLS_RSA_WITH_AES_256_CBC_SHA,
3104 TLS_RSA_WITH_AES_256_GCM_SHA384,
3105 },
3106 TLS_RSA_WITH_AES_256_CBC_SHA,
3107 },
3108 // If there are two equipreference groups, the preferred one
3109 // takes precedence.
3110 {
3111 []uint16{
3112 TLS_RSA_WITH_AES_256_GCM_SHA384,
3113 TLS_RSA_WITH_AES_256_CBC_SHA,
3114 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3115 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3116 },
3117 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3118 },
3119 }
3120 for i, t := range negotiationTests {
3121 testCases = append(testCases, testCase{
3122 testType: serverTest,
3123 name: "CipherNegotiation-" + strconv.Itoa(i),
3124 config: Config{
3125 MaxVersion: VersionTLS12,
3126 CipherSuites: t.ciphers,
3127 },
3128 flags: []string{"-cipher", negotiationTestCiphers},
3129 expectedCipher: t.expected,
3130 })
3131 }
Adam Langley95c29f32014-06-20 12:00:00 -07003132}
3133
3134func addBadECDSASignatureTests() {
3135 for badR := BadValue(1); badR < NumBadValues; badR++ {
3136 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003137 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003138 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3139 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003140 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003141 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003142 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003143 Bugs: ProtocolBugs{
3144 BadECDSAR: badR,
3145 BadECDSAS: badS,
3146 },
3147 },
3148 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003149 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003150 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003151 testCases = append(testCases, testCase{
3152 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3153 config: Config{
3154 MaxVersion: VersionTLS13,
3155 Certificates: []Certificate{ecdsaP256Certificate},
3156 Bugs: ProtocolBugs{
3157 BadECDSAR: badR,
3158 BadECDSAS: badS,
3159 },
3160 },
3161 shouldFail: true,
3162 expectedError: ":BAD_SIGNATURE:",
3163 })
Adam Langley95c29f32014-06-20 12:00:00 -07003164 }
3165 }
3166}
3167
Adam Langley80842bd2014-06-20 12:00:00 -07003168func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003169 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003170 name: "MaxCBCPadding",
3171 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003172 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3174 Bugs: ProtocolBugs{
3175 MaxPadding: true,
3176 },
3177 },
3178 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3179 })
David Benjamin025b3d32014-07-01 19:53:04 -04003180 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003181 name: "BadCBCPadding",
3182 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003183 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3185 Bugs: ProtocolBugs{
3186 PaddingFirstByteBad: true,
3187 },
3188 },
3189 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003190 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003191 })
3192 // OpenSSL previously had an issue where the first byte of padding in
3193 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003194 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003195 name: "BadCBCPadding255",
3196 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003197 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3199 Bugs: ProtocolBugs{
3200 MaxPadding: true,
3201 PaddingFirstByteBadIf255: true,
3202 },
3203 },
3204 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3205 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003206 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003207 })
3208}
3209
Kenny Root7fdeaf12014-08-05 15:23:37 -07003210func addCBCSplittingTests() {
3211 testCases = append(testCases, testCase{
3212 name: "CBCRecordSplitting",
3213 config: Config{
3214 MaxVersion: VersionTLS10,
3215 MinVersion: VersionTLS10,
3216 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3217 },
David Benjaminac8302a2015-09-01 17:18:15 -04003218 messageLen: -1, // read until EOF
3219 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003220 flags: []string{
3221 "-async",
3222 "-write-different-record-sizes",
3223 "-cbc-record-splitting",
3224 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003225 })
3226 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003227 name: "CBCRecordSplittingPartialWrite",
3228 config: Config{
3229 MaxVersion: VersionTLS10,
3230 MinVersion: VersionTLS10,
3231 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3232 },
3233 messageLen: -1, // read until EOF
3234 flags: []string{
3235 "-async",
3236 "-write-different-record-sizes",
3237 "-cbc-record-splitting",
3238 "-partial-write",
3239 },
3240 })
3241}
3242
David Benjamin636293b2014-07-08 17:59:18 -04003243func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003244 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003245 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003246 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3247 cert, err := x509.ParseCertificate(cert.Certificate[0])
3248 if err != nil {
3249 panic(err)
3250 }
3251 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003252 }
Adam Langley2ff79332017-02-28 13:45:39 -08003253 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003254
David Benjamin636293b2014-07-08 17:59:18 -04003255 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003256 testCases = append(testCases, testCase{
3257 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003258 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003259 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003260 MinVersion: ver.version,
3261 MaxVersion: ver.version,
3262 ClientAuth: RequireAnyClientCert,
3263 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003264 },
3265 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003266 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3267 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003268 },
3269 })
3270 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003271 testType: serverTest,
3272 name: ver.name + "-Server-ClientAuth-RSA",
3273 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003274 MinVersion: ver.version,
3275 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003276 Certificates: []Certificate{rsaCertificate},
3277 },
3278 flags: []string{"-require-any-client-certificate"},
3279 })
David Benjamine098ec22014-08-27 23:13:20 -04003280 if ver.version != VersionSSL30 {
3281 testCases = append(testCases, testCase{
3282 testType: serverTest,
3283 name: ver.name + "-Server-ClientAuth-ECDSA",
3284 config: Config{
3285 MinVersion: ver.version,
3286 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003287 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003288 },
3289 flags: []string{"-require-any-client-certificate"},
3290 })
3291 testCases = append(testCases, testCase{
3292 testType: clientTest,
3293 name: ver.name + "-Client-ClientAuth-ECDSA",
3294 config: Config{
3295 MinVersion: ver.version,
3296 MaxVersion: ver.version,
3297 ClientAuth: RequireAnyClientCert,
3298 ClientCAs: certPool,
3299 },
3300 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003301 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3302 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003303 },
3304 })
3305 }
Adam Langley37646832016-08-01 16:16:46 -07003306
3307 testCases = append(testCases, testCase{
3308 name: "NoClientCertificate-" + ver.name,
3309 config: Config{
3310 MinVersion: ver.version,
3311 MaxVersion: ver.version,
3312 ClientAuth: RequireAnyClientCert,
3313 },
3314 shouldFail: true,
3315 expectedLocalError: "client didn't provide a certificate",
3316 })
3317
3318 testCases = append(testCases, testCase{
3319 // Even if not configured to expect a certificate, OpenSSL will
3320 // return X509_V_OK as the verify_result.
3321 testType: serverTest,
3322 name: "NoClientCertificateRequested-Server-" + ver.name,
3323 config: Config{
3324 MinVersion: ver.version,
3325 MaxVersion: ver.version,
3326 },
3327 flags: []string{
3328 "-expect-verify-result",
3329 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003330 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003331 })
3332
3333 testCases = append(testCases, testCase{
3334 // If a client certificate is not provided, OpenSSL will still
3335 // return X509_V_OK as the verify_result.
3336 testType: serverTest,
3337 name: "NoClientCertificate-Server-" + ver.name,
3338 config: Config{
3339 MinVersion: ver.version,
3340 MaxVersion: ver.version,
3341 },
3342 flags: []string{
3343 "-expect-verify-result",
3344 "-verify-peer",
3345 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003346 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003347 })
3348
David Benjamin1db9e1b2016-10-07 20:51:43 -04003349 certificateRequired := "remote error: certificate required"
3350 if ver.version < VersionTLS13 {
3351 // Prior to TLS 1.3, the generic handshake_failure alert
3352 // was used.
3353 certificateRequired = "remote error: handshake failure"
3354 }
Adam Langley37646832016-08-01 16:16:46 -07003355 testCases = append(testCases, testCase{
3356 testType: serverTest,
3357 name: "RequireAnyClientCertificate-" + ver.name,
3358 config: Config{
3359 MinVersion: ver.version,
3360 MaxVersion: ver.version,
3361 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003362 flags: []string{"-require-any-client-certificate"},
3363 shouldFail: true,
3364 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3365 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003366 })
3367
3368 if ver.version != VersionSSL30 {
3369 testCases = append(testCases, testCase{
3370 testType: serverTest,
3371 name: "SkipClientCertificate-" + ver.name,
3372 config: Config{
3373 MinVersion: ver.version,
3374 MaxVersion: ver.version,
3375 Bugs: ProtocolBugs{
3376 SkipClientCertificate: true,
3377 },
3378 },
3379 // Setting SSL_VERIFY_PEER allows anonymous clients.
3380 flags: []string{"-verify-peer"},
3381 shouldFail: true,
3382 expectedError: ":UNEXPECTED_MESSAGE:",
3383 })
3384 }
Adam Langley2ff79332017-02-28 13:45:39 -08003385
3386 testCases = append(testCases, testCase{
3387 testType: serverTest,
3388 name: ver.name + "-Server-CertReq-CA-List",
3389 config: Config{
3390 MinVersion: ver.version,
3391 MaxVersion: ver.version,
3392 Certificates: []Certificate{rsaCertificate},
3393 Bugs: ProtocolBugs{
3394 ExpectCertificateReqNames: caNames,
3395 },
3396 },
3397 flags: []string{
3398 "-require-any-client-certificate",
3399 "-use-client-ca-list", encodeDERValues(caNames),
3400 },
3401 })
3402
3403 testCases = append(testCases, testCase{
3404 testType: clientTest,
3405 name: ver.name + "-Client-CertReq-CA-List",
3406 config: Config{
3407 MinVersion: ver.version,
3408 MaxVersion: ver.version,
3409 Certificates: []Certificate{rsaCertificate},
3410 ClientAuth: RequireAnyClientCert,
3411 ClientCAs: certPool,
3412 },
3413 flags: []string{
3414 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3415 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3416 "-expect-client-ca-list", encodeDERValues(caNames),
3417 },
3418 })
David Benjamin636293b2014-07-08 17:59:18 -04003419 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003420
David Benjaminc032dfa2016-05-12 14:54:57 -04003421 // Client auth is only legal in certificate-based ciphers.
3422 testCases = append(testCases, testCase{
3423 testType: clientTest,
3424 name: "ClientAuth-PSK",
3425 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003426 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003427 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3428 PreSharedKey: []byte("secret"),
3429 ClientAuth: RequireAnyClientCert,
3430 },
3431 flags: []string{
3432 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3433 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3434 "-psk", "secret",
3435 },
3436 shouldFail: true,
3437 expectedError: ":UNEXPECTED_MESSAGE:",
3438 })
3439 testCases = append(testCases, testCase{
3440 testType: clientTest,
3441 name: "ClientAuth-ECDHE_PSK",
3442 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003443 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003444 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3445 PreSharedKey: []byte("secret"),
3446 ClientAuth: RequireAnyClientCert,
3447 },
3448 flags: []string{
3449 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3450 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3451 "-psk", "secret",
3452 },
3453 shouldFail: true,
3454 expectedError: ":UNEXPECTED_MESSAGE:",
3455 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003456
3457 // Regression test for a bug where the client CA list, if explicitly
3458 // set to NULL, was mis-encoded.
3459 testCases = append(testCases, testCase{
3460 testType: serverTest,
3461 name: "Null-Client-CA-List",
3462 config: Config{
3463 MaxVersion: VersionTLS12,
3464 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003465 Bugs: ProtocolBugs{
3466 ExpectCertificateReqNames: [][]byte{},
3467 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003468 },
3469 flags: []string{
3470 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003471 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003472 },
3473 })
David Benjamin636293b2014-07-08 17:59:18 -04003474}
3475
Adam Langley75712922014-10-10 16:23:43 -07003476func addExtendedMasterSecretTests() {
3477 const expectEMSFlag = "-expect-extended-master-secret"
3478
3479 for _, with := range []bool{false, true} {
3480 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003481 if with {
3482 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003483 }
3484
3485 for _, isClient := range []bool{false, true} {
3486 suffix := "-Server"
3487 testType := serverTest
3488 if isClient {
3489 suffix = "-Client"
3490 testType = clientTest
3491 }
3492
3493 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003494 // In TLS 1.3, the extension is irrelevant and
3495 // always reports as enabled.
3496 var flags []string
3497 if with || ver.version >= VersionTLS13 {
3498 flags = []string{expectEMSFlag}
3499 }
3500
Adam Langley75712922014-10-10 16:23:43 -07003501 test := testCase{
3502 testType: testType,
3503 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3504 config: Config{
3505 MinVersion: ver.version,
3506 MaxVersion: ver.version,
3507 Bugs: ProtocolBugs{
3508 NoExtendedMasterSecret: !with,
3509 RequireExtendedMasterSecret: with,
3510 },
3511 },
David Benjamin48cae082014-10-27 01:06:24 -04003512 flags: flags,
3513 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003514 }
3515 if test.shouldFail {
3516 test.expectedLocalError = "extended master secret required but not supported by peer"
3517 }
3518 testCases = append(testCases, test)
3519 }
3520 }
3521 }
3522
Adam Langleyba5934b2015-06-02 10:50:35 -07003523 for _, isClient := range []bool{false, true} {
3524 for _, supportedInFirstConnection := range []bool{false, true} {
3525 for _, supportedInResumeConnection := range []bool{false, true} {
3526 boolToWord := func(b bool) string {
3527 if b {
3528 return "Yes"
3529 }
3530 return "No"
3531 }
3532 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3533 if isClient {
3534 suffix += "Client"
3535 } else {
3536 suffix += "Server"
3537 }
3538
3539 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003540 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003541 Bugs: ProtocolBugs{
3542 RequireExtendedMasterSecret: true,
3543 },
3544 }
3545
3546 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003547 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003548 Bugs: ProtocolBugs{
3549 NoExtendedMasterSecret: true,
3550 },
3551 }
3552
3553 test := testCase{
3554 name: "ExtendedMasterSecret-" + suffix,
3555 resumeSession: true,
3556 }
3557
3558 if !isClient {
3559 test.testType = serverTest
3560 }
3561
3562 if supportedInFirstConnection {
3563 test.config = supportedConfig
3564 } else {
3565 test.config = noSupportConfig
3566 }
3567
3568 if supportedInResumeConnection {
3569 test.resumeConfig = &supportedConfig
3570 } else {
3571 test.resumeConfig = &noSupportConfig
3572 }
3573
3574 switch suffix {
3575 case "YesToYes-Client", "YesToYes-Server":
3576 // When a session is resumed, it should
3577 // still be aware that its master
3578 // secret was generated via EMS and
3579 // thus it's safe to use tls-unique.
3580 test.flags = []string{expectEMSFlag}
3581 case "NoToYes-Server":
3582 // If an original connection did not
3583 // contain EMS, but a resumption
3584 // handshake does, then a server should
3585 // not resume the session.
3586 test.expectResumeRejected = true
3587 case "YesToNo-Server":
3588 // Resuming an EMS session without the
3589 // EMS extension should cause the
3590 // server to abort the connection.
3591 test.shouldFail = true
3592 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3593 case "NoToYes-Client":
3594 // A client should abort a connection
3595 // where the server resumed a non-EMS
3596 // session but echoed the EMS
3597 // extension.
3598 test.shouldFail = true
3599 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3600 case "YesToNo-Client":
3601 // A client should abort a connection
3602 // where the server didn't echo EMS
3603 // when the session used it.
3604 test.shouldFail = true
3605 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3606 }
3607
3608 testCases = append(testCases, test)
3609 }
3610 }
3611 }
David Benjamin163c9562016-08-29 23:14:17 -04003612
3613 // Switching EMS on renegotiation is forbidden.
3614 testCases = append(testCases, testCase{
3615 name: "ExtendedMasterSecret-Renego-NoEMS",
3616 config: Config{
3617 MaxVersion: VersionTLS12,
3618 Bugs: ProtocolBugs{
3619 NoExtendedMasterSecret: true,
3620 NoExtendedMasterSecretOnRenegotiation: true,
3621 },
3622 },
3623 renegotiate: 1,
3624 flags: []string{
3625 "-renegotiate-freely",
3626 "-expect-total-renegotiations", "1",
3627 },
3628 })
3629
3630 testCases = append(testCases, testCase{
3631 name: "ExtendedMasterSecret-Renego-Upgrade",
3632 config: Config{
3633 MaxVersion: VersionTLS12,
3634 Bugs: ProtocolBugs{
3635 NoExtendedMasterSecret: true,
3636 },
3637 },
3638 renegotiate: 1,
3639 flags: []string{
3640 "-renegotiate-freely",
3641 "-expect-total-renegotiations", "1",
3642 },
3643 shouldFail: true,
3644 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3645 })
3646
3647 testCases = append(testCases, testCase{
3648 name: "ExtendedMasterSecret-Renego-Downgrade",
3649 config: Config{
3650 MaxVersion: VersionTLS12,
3651 Bugs: ProtocolBugs{
3652 NoExtendedMasterSecretOnRenegotiation: true,
3653 },
3654 },
3655 renegotiate: 1,
3656 flags: []string{
3657 "-renegotiate-freely",
3658 "-expect-total-renegotiations", "1",
3659 },
3660 shouldFail: true,
3661 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3662 })
Adam Langley75712922014-10-10 16:23:43 -07003663}
3664
David Benjamin582ba042016-07-07 12:33:25 -07003665type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003666 protocol protocol
3667 async bool
3668 splitHandshake bool
3669 packHandshakeFlight bool
3670 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003671}
3672
David Benjamin43ec06f2014-08-05 02:28:57 -04003673// Adds tests that try to cover the range of the handshake state machine, under
3674// various conditions. Some of these are redundant with other tests, but they
3675// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003676func addAllStateMachineCoverageTests() {
3677 for _, async := range []bool{false, true} {
3678 for _, protocol := range []protocol{tls, dtls} {
3679 addStateMachineCoverageTests(stateMachineTestConfig{
3680 protocol: protocol,
3681 async: async,
3682 })
3683 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003684 protocol: protocol,
3685 async: async,
3686 implicitHandshake: true,
3687 })
3688 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003689 protocol: protocol,
3690 async: async,
3691 splitHandshake: true,
3692 })
3693 if protocol == tls {
3694 addStateMachineCoverageTests(stateMachineTestConfig{
3695 protocol: protocol,
3696 async: async,
3697 packHandshakeFlight: true,
3698 })
3699 }
3700 }
3701 }
3702}
3703
3704func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003705 var tests []testCase
3706
3707 // Basic handshake, with resumption. Client and server,
3708 // session ID and session ticket.
3709 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003710 name: "Basic-Client",
3711 config: Config{
3712 MaxVersion: VersionTLS12,
3713 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003714 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003715 // Ensure session tickets are used, not session IDs.
3716 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003717 })
3718 tests = append(tests, testCase{
3719 name: "Basic-Client-RenewTicket",
3720 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003721 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003722 Bugs: ProtocolBugs{
3723 RenewTicketOnResume: true,
3724 },
3725 },
David Benjamin46662482016-08-17 00:51:00 -04003726 flags: []string{"-expect-ticket-renewal"},
3727 resumeSession: true,
3728 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003729 })
3730 tests = append(tests, testCase{
3731 name: "Basic-Client-NoTicket",
3732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003733 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003734 SessionTicketsDisabled: true,
3735 },
3736 resumeSession: true,
3737 })
3738 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003739 testType: serverTest,
3740 name: "Basic-Server",
3741 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003742 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003743 Bugs: ProtocolBugs{
3744 RequireSessionTickets: true,
3745 },
3746 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003747 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003748 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 })
3750 tests = append(tests, testCase{
3751 testType: serverTest,
3752 name: "Basic-Server-NoTickets",
3753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003754 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003755 SessionTicketsDisabled: true,
3756 },
3757 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003758 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003759 })
3760 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003761 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003762 name: "Basic-Server-EarlyCallback",
3763 config: Config{
3764 MaxVersion: VersionTLS12,
3765 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003766 flags: []string{"-use-early-callback"},
3767 resumeSession: true,
3768 })
3769
Steven Valdez143e8b32016-07-11 13:19:03 -04003770 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003771 if config.protocol == tls {
3772 tests = append(tests, testCase{
3773 name: "TLS13-1RTT-Client",
3774 config: Config{
3775 MaxVersion: VersionTLS13,
3776 MinVersion: VersionTLS13,
3777 },
David Benjamin46662482016-08-17 00:51:00 -04003778 resumeSession: true,
3779 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003780 })
3781
3782 tests = append(tests, testCase{
3783 testType: serverTest,
3784 name: "TLS13-1RTT-Server",
3785 config: Config{
3786 MaxVersion: VersionTLS13,
3787 MinVersion: VersionTLS13,
3788 },
David Benjamin46662482016-08-17 00:51:00 -04003789 resumeSession: true,
3790 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003791 // TLS 1.3 uses tickets, so the session should not be
3792 // cached statefully.
3793 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003794 })
3795
3796 tests = append(tests, testCase{
3797 name: "TLS13-HelloRetryRequest-Client",
3798 config: Config{
3799 MaxVersion: VersionTLS13,
3800 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003801 // P-384 requires a HelloRetryRequest against BoringSSL's default
3802 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003803 CurvePreferences: []CurveID{CurveP384},
3804 Bugs: ProtocolBugs{
3805 ExpectMissingKeyShare: true,
3806 },
3807 },
3808 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3809 resumeSession: true,
3810 })
3811
3812 tests = append(tests, testCase{
3813 testType: serverTest,
3814 name: "TLS13-HelloRetryRequest-Server",
3815 config: Config{
3816 MaxVersion: VersionTLS13,
3817 MinVersion: VersionTLS13,
3818 // Require a HelloRetryRequest for every curve.
3819 DefaultCurves: []CurveID{},
3820 },
3821 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3822 resumeSession: true,
3823 })
Steven Valdez2d850622017-01-11 11:34:52 -05003824
Steven Valdez2d850622017-01-11 11:34:52 -05003825 tests = append(tests, testCase{
3826 testType: clientTest,
3827 name: "TLS13-EarlyData-Client",
3828 config: Config{
3829 MaxVersion: VersionTLS13,
3830 MinVersion: VersionTLS13,
3831 MaxEarlyDataSize: 16384,
3832 },
Steven Valdeze831a812017-03-09 14:56:07 -05003833 resumeConfig: &Config{
3834 MaxVersion: VersionTLS13,
3835 MinVersion: VersionTLS13,
3836 MaxEarlyDataSize: 16384,
3837 Bugs: ProtocolBugs{
3838 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3839 },
3840 },
Steven Valdez2d850622017-01-11 11:34:52 -05003841 resumeSession: true,
3842 flags: []string{
3843 "-enable-early-data",
3844 "-expect-early-data-info",
3845 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003846 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003847 },
3848 })
3849
3850 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003851 testType: clientTest,
3852 name: "TLS13-EarlyData-TooMuchData-Client",
3853 config: Config{
3854 MaxVersion: VersionTLS13,
3855 MinVersion: VersionTLS13,
3856 MaxEarlyDataSize: 2,
3857 },
3858 resumeConfig: &Config{
3859 MaxVersion: VersionTLS13,
3860 MinVersion: VersionTLS13,
3861 MaxEarlyDataSize: 2,
3862 Bugs: ProtocolBugs{
3863 ExpectEarlyData: [][]byte{{'h', 'e'}},
3864 },
3865 },
3866 resumeShimPrefix: "llo",
3867 resumeSession: true,
3868 flags: []string{
3869 "-enable-early-data",
3870 "-expect-early-data-info",
3871 "-expect-accept-early-data",
3872 "-on-resume-shim-writes-first",
3873 },
3874 })
3875
3876 // Unfinished writes can only be tested when operations are async. EarlyData
3877 // can't be tested as part of an ImplicitHandshake in this case since
3878 // otherwise the early data will be sent as normal data.
3879 if config.async && !config.implicitHandshake {
3880 tests = append(tests, testCase{
3881 testType: clientTest,
3882 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3883 config: Config{
3884 MaxVersion: VersionTLS13,
3885 MinVersion: VersionTLS13,
3886 MaxEarlyDataSize: 16384,
3887 },
3888 resumeConfig: &Config{
3889 MaxVersion: VersionTLS13,
3890 MinVersion: VersionTLS13,
3891 MaxEarlyDataSize: 16384,
3892 Bugs: ProtocolBugs{
3893 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3894 },
3895 },
3896 resumeSession: true,
3897 flags: []string{
3898 "-enable-early-data",
3899 "-expect-early-data-info",
3900 "-expect-accept-early-data",
3901 "-on-resume-read-with-unfinished-write",
3902 "-on-resume-shim-writes-first",
3903 },
3904 })
3905
3906 // Rejected unfinished writes are discarded (from the
3907 // perspective of the calling application) on 0-RTT
3908 // reject.
3909 tests = append(tests, testCase{
3910 testType: clientTest,
3911 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3912 config: Config{
3913 MaxVersion: VersionTLS13,
3914 MinVersion: VersionTLS13,
3915 MaxEarlyDataSize: 16384,
3916 },
3917 resumeConfig: &Config{
3918 MaxVersion: VersionTLS13,
3919 MinVersion: VersionTLS13,
3920 MaxEarlyDataSize: 16384,
3921 Bugs: ProtocolBugs{
3922 AlwaysRejectEarlyData: true,
3923 },
3924 },
3925 resumeSession: true,
3926 flags: []string{
3927 "-enable-early-data",
3928 "-expect-early-data-info",
3929 "-expect-reject-early-data",
3930 "-on-resume-read-with-unfinished-write",
3931 "-on-resume-shim-writes-first",
3932 },
3933 })
3934 }
3935
3936 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003937 testType: serverTest,
3938 name: "TLS13-EarlyData-Server",
3939 config: Config{
3940 MaxVersion: VersionTLS13,
3941 MinVersion: VersionTLS13,
3942 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003943 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003944 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003945 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003946 },
3947 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003948 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003949 resumeSession: true,
3950 flags: []string{
3951 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003952 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003953 },
3954 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003955
3956 tests = append(tests, testCase{
3957 testType: serverTest,
3958 name: "TLS13-MaxEarlyData-Server",
3959 config: Config{
3960 MaxVersion: VersionTLS13,
3961 MinVersion: VersionTLS13,
3962 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003963 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003964 ExpectEarlyDataAccepted: true,
3965 },
3966 },
3967 messageCount: 2,
3968 resumeSession: true,
3969 flags: []string{
3970 "-enable-early-data",
3971 "-expect-accept-early-data",
3972 },
3973 shouldFail: true,
3974 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
3975 })
David Benjamine73c7f42016-08-17 00:29:33 -04003976 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003977
David Benjamin760b1dd2015-05-15 23:33:48 -04003978 // TLS client auth.
3979 tests = append(tests, testCase{
3980 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003981 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003983 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003984 ClientAuth: RequestClientCert,
3985 },
3986 })
3987 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003988 testType: serverTest,
3989 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003990 config: Config{
3991 MaxVersion: VersionTLS12,
3992 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003993 // Setting SSL_VERIFY_PEER allows anonymous clients.
3994 flags: []string{"-verify-peer"},
3995 })
David Benjamin582ba042016-07-07 12:33:25 -07003996 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003997 tests = append(tests, testCase{
3998 testType: clientTest,
3999 name: "ClientAuth-NoCertificate-Client-SSL3",
4000 config: Config{
4001 MaxVersion: VersionSSL30,
4002 ClientAuth: RequestClientCert,
4003 },
4004 })
4005 tests = append(tests, testCase{
4006 testType: serverTest,
4007 name: "ClientAuth-NoCertificate-Server-SSL3",
4008 config: Config{
4009 MaxVersion: VersionSSL30,
4010 },
4011 // Setting SSL_VERIFY_PEER allows anonymous clients.
4012 flags: []string{"-verify-peer"},
4013 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004014 tests = append(tests, testCase{
4015 testType: clientTest,
4016 name: "ClientAuth-NoCertificate-Client-TLS13",
4017 config: Config{
4018 MaxVersion: VersionTLS13,
4019 ClientAuth: RequestClientCert,
4020 },
4021 })
4022 tests = append(tests, testCase{
4023 testType: serverTest,
4024 name: "ClientAuth-NoCertificate-Server-TLS13",
4025 config: Config{
4026 MaxVersion: VersionTLS13,
4027 },
4028 // Setting SSL_VERIFY_PEER allows anonymous clients.
4029 flags: []string{"-verify-peer"},
4030 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004031 }
4032 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004033 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004034 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004037 ClientAuth: RequireAnyClientCert,
4038 },
4039 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004040 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4041 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004042 },
4043 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004044 tests = append(tests, testCase{
4045 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004046 name: "ClientAuth-RSA-Client-TLS13",
4047 config: Config{
4048 MaxVersion: VersionTLS13,
4049 ClientAuth: RequireAnyClientCert,
4050 },
4051 flags: []string{
4052 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4053 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4054 },
4055 })
4056 tests = append(tests, testCase{
4057 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004058 name: "ClientAuth-ECDSA-Client",
4059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004060 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004061 ClientAuth: RequireAnyClientCert,
4062 },
4063 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004064 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4065 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004066 },
4067 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004068 tests = append(tests, testCase{
4069 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004070 name: "ClientAuth-ECDSA-Client-TLS13",
4071 config: Config{
4072 MaxVersion: VersionTLS13,
4073 ClientAuth: RequireAnyClientCert,
4074 },
4075 flags: []string{
4076 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4077 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4078 },
4079 })
4080 tests = append(tests, testCase{
4081 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004082 name: "ClientAuth-NoCertificate-OldCallback",
4083 config: Config{
4084 MaxVersion: VersionTLS12,
4085 ClientAuth: RequestClientCert,
4086 },
4087 flags: []string{"-use-old-client-cert-callback"},
4088 })
4089 tests = append(tests, testCase{
4090 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004091 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4092 config: Config{
4093 MaxVersion: VersionTLS13,
4094 ClientAuth: RequestClientCert,
4095 },
4096 flags: []string{"-use-old-client-cert-callback"},
4097 })
4098 tests = append(tests, testCase{
4099 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004100 name: "ClientAuth-OldCallback",
4101 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004102 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004103 ClientAuth: RequireAnyClientCert,
4104 },
4105 flags: []string{
4106 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4107 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4108 "-use-old-client-cert-callback",
4109 },
4110 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004111 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004112 testType: clientTest,
4113 name: "ClientAuth-OldCallback-TLS13",
4114 config: Config{
4115 MaxVersion: VersionTLS13,
4116 ClientAuth: RequireAnyClientCert,
4117 },
4118 flags: []string{
4119 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4120 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4121 "-use-old-client-cert-callback",
4122 },
4123 })
4124 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004125 testType: serverTest,
4126 name: "ClientAuth-Server",
4127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004128 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004129 Certificates: []Certificate{rsaCertificate},
4130 },
4131 flags: []string{"-require-any-client-certificate"},
4132 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004133 tests = append(tests, testCase{
4134 testType: serverTest,
4135 name: "ClientAuth-Server-TLS13",
4136 config: Config{
4137 MaxVersion: VersionTLS13,
4138 Certificates: []Certificate{rsaCertificate},
4139 },
4140 flags: []string{"-require-any-client-certificate"},
4141 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004142
David Benjamin4c3ddf72016-06-29 18:13:53 -04004143 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004144 tests = append(tests, testCase{
4145 testType: serverTest,
4146 name: "Basic-Server-RSA",
4147 config: Config{
4148 MaxVersion: VersionTLS12,
4149 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4150 },
4151 flags: []string{
4152 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4153 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4154 },
4155 })
4156 tests = append(tests, testCase{
4157 testType: serverTest,
4158 name: "Basic-Server-ECDHE-RSA",
4159 config: Config{
4160 MaxVersion: VersionTLS12,
4161 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4162 },
4163 flags: []string{
4164 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4165 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4166 },
4167 })
4168 tests = append(tests, testCase{
4169 testType: serverTest,
4170 name: "Basic-Server-ECDHE-ECDSA",
4171 config: Config{
4172 MaxVersion: VersionTLS12,
4173 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4174 },
4175 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004176 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4177 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004178 },
4179 })
David Benjamin69522112017-03-28 15:38:29 -05004180 tests = append(tests, testCase{
4181 testType: serverTest,
4182 name: "Basic-Server-Ed25519",
4183 config: Config{
4184 MaxVersion: VersionTLS12,
4185 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4186 },
4187 flags: []string{
4188 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4189 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4190 "-enable-ed25519",
4191 },
4192 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004193
David Benjamin760b1dd2015-05-15 23:33:48 -04004194 // No session ticket support; server doesn't send NewSessionTicket.
4195 tests = append(tests, testCase{
4196 name: "SessionTicketsDisabled-Client",
4197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004198 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004199 SessionTicketsDisabled: true,
4200 },
4201 })
4202 tests = append(tests, testCase{
4203 testType: serverTest,
4204 name: "SessionTicketsDisabled-Server",
4205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004206 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004207 SessionTicketsDisabled: true,
4208 },
4209 })
4210
4211 // Skip ServerKeyExchange in PSK key exchange if there's no
4212 // identity hint.
4213 tests = append(tests, testCase{
4214 name: "EmptyPSKHint-Client",
4215 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004216 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004217 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4218 PreSharedKey: []byte("secret"),
4219 },
4220 flags: []string{"-psk", "secret"},
4221 })
4222 tests = append(tests, testCase{
4223 testType: serverTest,
4224 name: "EmptyPSKHint-Server",
4225 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004226 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004227 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4228 PreSharedKey: []byte("secret"),
4229 },
4230 flags: []string{"-psk", "secret"},
4231 })
4232
David Benjamin4c3ddf72016-06-29 18:13:53 -04004233 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004234 tests = append(tests, testCase{
4235 testType: clientTest,
4236 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004237 config: Config{
4238 MaxVersion: VersionTLS12,
4239 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004240 flags: []string{
4241 "-enable-ocsp-stapling",
4242 "-expect-ocsp-response",
4243 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004244 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004245 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004246 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004247 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004248 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004249 testType: serverTest,
4250 name: "OCSPStapling-Server",
4251 config: Config{
4252 MaxVersion: VersionTLS12,
4253 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004254 expectedOCSPResponse: testOCSPResponse,
4255 flags: []string{
4256 "-ocsp-response",
4257 base64.StdEncoding.EncodeToString(testOCSPResponse),
4258 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004259 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004260 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004261 tests = append(tests, testCase{
4262 testType: clientTest,
4263 name: "OCSPStapling-Client-TLS13",
4264 config: Config{
4265 MaxVersion: VersionTLS13,
4266 },
4267 flags: []string{
4268 "-enable-ocsp-stapling",
4269 "-expect-ocsp-response",
4270 base64.StdEncoding.EncodeToString(testOCSPResponse),
4271 "-verify-peer",
4272 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004273 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004274 })
4275 tests = append(tests, testCase{
4276 testType: serverTest,
4277 name: "OCSPStapling-Server-TLS13",
4278 config: Config{
4279 MaxVersion: VersionTLS13,
4280 },
4281 expectedOCSPResponse: testOCSPResponse,
4282 flags: []string{
4283 "-ocsp-response",
4284 base64.StdEncoding.EncodeToString(testOCSPResponse),
4285 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004286 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004287 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004288
David Benjamin4c3ddf72016-06-29 18:13:53 -04004289 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004290 for _, vers := range tlsVersions {
4291 if config.protocol == dtls && !vers.hasDTLS {
4292 continue
4293 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004294 for _, testType := range []testType{clientTest, serverTest} {
4295 suffix := "-Client"
4296 if testType == serverTest {
4297 suffix = "-Server"
4298 }
4299 suffix += "-" + vers.name
4300
4301 flag := "-verify-peer"
4302 if testType == serverTest {
4303 flag = "-require-any-client-certificate"
4304 }
4305
4306 tests = append(tests, testCase{
4307 testType: testType,
4308 name: "CertificateVerificationSucceed" + suffix,
4309 config: Config{
4310 MaxVersion: vers.version,
4311 Certificates: []Certificate{rsaCertificate},
4312 },
4313 flags: []string{
4314 flag,
4315 "-expect-verify-result",
4316 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004317 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004318 })
4319 tests = append(tests, testCase{
4320 testType: testType,
4321 name: "CertificateVerificationFail" + suffix,
4322 config: Config{
4323 MaxVersion: vers.version,
4324 Certificates: []Certificate{rsaCertificate},
4325 },
4326 flags: []string{
4327 flag,
4328 "-verify-fail",
4329 },
4330 shouldFail: true,
4331 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4332 })
4333 }
4334
4335 // By default, the client is in a soft fail mode where the peer
4336 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004337 tests = append(tests, testCase{
4338 testType: clientTest,
4339 name: "CertificateVerificationSoftFail-" + vers.name,
4340 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004341 MaxVersion: vers.version,
4342 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004343 },
4344 flags: []string{
4345 "-verify-fail",
4346 "-expect-verify-result",
4347 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004348 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004349 })
4350 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004351
David Benjamin1d4f4c02016-07-26 18:03:08 -04004352 tests = append(tests, testCase{
4353 name: "ShimSendAlert",
4354 flags: []string{"-send-alert"},
4355 shimWritesFirst: true,
4356 shouldFail: true,
4357 expectedLocalError: "remote error: decompression failure",
4358 })
4359
David Benjamin582ba042016-07-07 12:33:25 -07004360 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004361 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004362 name: "Renegotiate-Client",
4363 config: Config{
4364 MaxVersion: VersionTLS12,
4365 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004366 renegotiate: 1,
4367 flags: []string{
4368 "-renegotiate-freely",
4369 "-expect-total-renegotiations", "1",
4370 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004371 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004372
David Benjamin47921102016-07-28 11:29:18 -04004373 tests = append(tests, testCase{
4374 name: "SendHalfHelloRequest",
4375 config: Config{
4376 MaxVersion: VersionTLS12,
4377 Bugs: ProtocolBugs{
4378 PackHelloRequestWithFinished: config.packHandshakeFlight,
4379 },
4380 },
4381 sendHalfHelloRequest: true,
4382 flags: []string{"-renegotiate-ignore"},
4383 shouldFail: true,
4384 expectedError: ":UNEXPECTED_RECORD:",
4385 })
4386
David Benjamin760b1dd2015-05-15 23:33:48 -04004387 // NPN on client and server; results in post-handshake message.
4388 tests = append(tests, testCase{
4389 name: "NPN-Client",
4390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004391 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004392 NextProtos: []string{"foo"},
4393 },
4394 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004395 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004396 expectedNextProto: "foo",
4397 expectedNextProtoType: npn,
4398 })
4399 tests = append(tests, testCase{
4400 testType: serverTest,
4401 name: "NPN-Server",
4402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004403 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004404 NextProtos: []string{"bar"},
4405 },
4406 flags: []string{
4407 "-advertise-npn", "\x03foo\x03bar\x03baz",
4408 "-expect-next-proto", "bar",
4409 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004410 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004411 expectedNextProto: "bar",
4412 expectedNextProtoType: npn,
4413 })
4414
4415 // TODO(davidben): Add tests for when False Start doesn't trigger.
4416
4417 // Client does False Start and negotiates NPN.
4418 tests = append(tests, testCase{
4419 name: "FalseStart",
4420 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004421 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004422 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4423 NextProtos: []string{"foo"},
4424 Bugs: ProtocolBugs{
4425 ExpectFalseStart: true,
4426 },
4427 },
4428 flags: []string{
4429 "-false-start",
4430 "-select-next-proto", "foo",
4431 },
4432 shimWritesFirst: true,
4433 resumeSession: true,
4434 })
4435
4436 // Client does False Start and negotiates ALPN.
4437 tests = append(tests, testCase{
4438 name: "FalseStart-ALPN",
4439 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004440 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004441 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4442 NextProtos: []string{"foo"},
4443 Bugs: ProtocolBugs{
4444 ExpectFalseStart: true,
4445 },
4446 },
4447 flags: []string{
4448 "-false-start",
4449 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004450 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004451 },
4452 shimWritesFirst: true,
4453 resumeSession: true,
4454 })
4455
David Benjamin760b1dd2015-05-15 23:33:48 -04004456 // False Start without session tickets.
4457 tests = append(tests, testCase{
4458 name: "FalseStart-SessionTicketsDisabled",
4459 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004461 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4462 NextProtos: []string{"foo"},
4463 SessionTicketsDisabled: true,
4464 Bugs: ProtocolBugs{
4465 ExpectFalseStart: true,
4466 },
4467 },
4468 flags: []string{
4469 "-false-start",
4470 "-select-next-proto", "foo",
4471 },
4472 shimWritesFirst: true,
4473 })
4474
4475 // Server parses a V2ClientHello.
4476 tests = append(tests, testCase{
4477 testType: serverTest,
4478 name: "SendV2ClientHello",
4479 config: Config{
4480 // Choose a cipher suite that does not involve
4481 // elliptic curves, so no extensions are
4482 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004483 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004484 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004485 Bugs: ProtocolBugs{
4486 SendV2ClientHello: true,
4487 },
4488 },
4489 })
4490
Nick Harper60a85cb2016-09-23 16:25:11 -07004491 // Test Channel ID
4492 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004493 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004494 continue
4495 }
4496 // Client sends a Channel ID.
4497 tests = append(tests, testCase{
4498 name: "ChannelID-Client-" + ver.name,
4499 config: Config{
4500 MaxVersion: ver.version,
4501 RequestChannelID: true,
4502 },
4503 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4504 resumeSession: true,
4505 expectChannelID: true,
4506 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004507
Nick Harper60a85cb2016-09-23 16:25:11 -07004508 // Server accepts a Channel ID.
4509 tests = append(tests, testCase{
4510 testType: serverTest,
4511 name: "ChannelID-Server-" + ver.name,
4512 config: Config{
4513 MaxVersion: ver.version,
4514 ChannelID: channelIDKey,
4515 },
4516 flags: []string{
4517 "-expect-channel-id",
4518 base64.StdEncoding.EncodeToString(channelIDBytes),
4519 },
4520 resumeSession: true,
4521 expectChannelID: true,
4522 })
4523
4524 tests = append(tests, testCase{
4525 testType: serverTest,
4526 name: "InvalidChannelIDSignature-" + ver.name,
4527 config: Config{
4528 MaxVersion: ver.version,
4529 ChannelID: channelIDKey,
4530 Bugs: ProtocolBugs{
4531 InvalidChannelIDSignature: true,
4532 },
4533 },
4534 flags: []string{"-enable-channel-id"},
4535 shouldFail: true,
4536 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4537 })
4538 }
David Benjamin30789da2015-08-29 22:56:45 -04004539
David Benjaminf8fcdf32016-06-08 15:56:13 -04004540 // Channel ID and NPN at the same time, to ensure their relative
4541 // ordering is correct.
4542 tests = append(tests, testCase{
4543 name: "ChannelID-NPN-Client",
4544 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004545 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004546 RequestChannelID: true,
4547 NextProtos: []string{"foo"},
4548 },
4549 flags: []string{
4550 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4551 "-select-next-proto", "foo",
4552 },
4553 resumeSession: true,
4554 expectChannelID: true,
4555 expectedNextProto: "foo",
4556 expectedNextProtoType: npn,
4557 })
4558 tests = append(tests, testCase{
4559 testType: serverTest,
4560 name: "ChannelID-NPN-Server",
4561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004562 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004563 ChannelID: channelIDKey,
4564 NextProtos: []string{"bar"},
4565 },
4566 flags: []string{
4567 "-expect-channel-id",
4568 base64.StdEncoding.EncodeToString(channelIDBytes),
4569 "-advertise-npn", "\x03foo\x03bar\x03baz",
4570 "-expect-next-proto", "bar",
4571 },
4572 resumeSession: true,
4573 expectChannelID: true,
4574 expectedNextProto: "bar",
4575 expectedNextProtoType: npn,
4576 })
4577
David Benjamin30789da2015-08-29 22:56:45 -04004578 // Bidirectional shutdown with the runner initiating.
4579 tests = append(tests, testCase{
4580 name: "Shutdown-Runner",
4581 config: Config{
4582 Bugs: ProtocolBugs{
4583 ExpectCloseNotify: true,
4584 },
4585 },
4586 flags: []string{"-check-close-notify"},
4587 })
4588
David Benjamine3843d42017-03-25 18:00:56 -05004589 if !config.implicitHandshake {
4590 // Bidirectional shutdown with the shim initiating. The runner,
4591 // in the meantime, sends garbage before the close_notify which
4592 // the shim must ignore. This test is disabled under implicit
4593 // handshake tests because the shim never reads or writes.
4594 tests = append(tests, testCase{
4595 name: "Shutdown-Shim",
4596 config: Config{
4597 MaxVersion: VersionTLS12,
4598 Bugs: ProtocolBugs{
4599 ExpectCloseNotify: true,
4600 },
David Benjamin30789da2015-08-29 22:56:45 -04004601 },
David Benjamine3843d42017-03-25 18:00:56 -05004602 shimShutsDown: true,
4603 sendEmptyRecords: 1,
4604 sendWarningAlerts: 1,
4605 flags: []string{"-check-close-notify"},
4606 })
4607 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004608 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004609 // TODO(davidben): DTLS 1.3 will want a similar thing for
4610 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004611 tests = append(tests, testCase{
4612 name: "SkipHelloVerifyRequest",
4613 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004614 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004615 Bugs: ProtocolBugs{
4616 SkipHelloVerifyRequest: true,
4617 },
4618 },
4619 })
4620 }
4621
David Benjamin760b1dd2015-05-15 23:33:48 -04004622 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004623 test.protocol = config.protocol
4624 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004625 test.name += "-DTLS"
4626 }
David Benjamin582ba042016-07-07 12:33:25 -07004627 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004628 test.name += "-Async"
4629 test.flags = append(test.flags, "-async")
4630 } else {
4631 test.name += "-Sync"
4632 }
David Benjamin582ba042016-07-07 12:33:25 -07004633 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004634 test.name += "-SplitHandshakeRecords"
4635 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004636 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004637 test.config.Bugs.MaxPacketLength = 256
4638 test.flags = append(test.flags, "-mtu", "256")
4639 }
4640 }
David Benjamin582ba042016-07-07 12:33:25 -07004641 if config.packHandshakeFlight {
4642 test.name += "-PackHandshakeFlight"
4643 test.config.Bugs.PackHandshakeFlight = true
4644 }
David Benjamine3843d42017-03-25 18:00:56 -05004645 if config.implicitHandshake {
4646 test.name += "-ImplicitHandshake"
4647 test.flags = append(test.flags, "-implicit-handshake")
4648 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004649 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004650 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004651}
4652
Adam Langley524e7172015-02-20 16:04:00 -08004653func addDDoSCallbackTests() {
4654 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004655 for _, resume := range []bool{false, true} {
4656 suffix := "Resume"
4657 if resume {
4658 suffix = "No" + suffix
4659 }
4660
4661 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004662 testType: serverTest,
4663 name: "Server-DDoS-OK-" + suffix,
4664 config: Config{
4665 MaxVersion: VersionTLS12,
4666 },
Adam Langley524e7172015-02-20 16:04:00 -08004667 flags: []string{"-install-ddos-callback"},
4668 resumeSession: resume,
4669 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004670 testCases = append(testCases, testCase{
4671 testType: serverTest,
4672 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4673 config: Config{
4674 MaxVersion: VersionTLS13,
4675 },
4676 flags: []string{"-install-ddos-callback"},
4677 resumeSession: resume,
4678 })
Adam Langley524e7172015-02-20 16:04:00 -08004679
4680 failFlag := "-fail-ddos-callback"
4681 if resume {
4682 failFlag = "-fail-second-ddos-callback"
4683 }
4684 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004685 testType: serverTest,
4686 name: "Server-DDoS-Reject-" + suffix,
4687 config: Config{
4688 MaxVersion: VersionTLS12,
4689 },
David Benjamin2c66e072016-09-16 15:58:00 -04004690 flags: []string{"-install-ddos-callback", failFlag},
4691 resumeSession: resume,
4692 shouldFail: true,
4693 expectedError: ":CONNECTION_REJECTED:",
4694 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004695 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004696 testCases = append(testCases, testCase{
4697 testType: serverTest,
4698 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4699 config: Config{
4700 MaxVersion: VersionTLS13,
4701 },
David Benjamin2c66e072016-09-16 15:58:00 -04004702 flags: []string{"-install-ddos-callback", failFlag},
4703 resumeSession: resume,
4704 shouldFail: true,
4705 expectedError: ":CONNECTION_REJECTED:",
4706 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004707 })
Adam Langley524e7172015-02-20 16:04:00 -08004708 }
4709}
4710
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004711func addVersionNegotiationTests() {
4712 for i, shimVers := range tlsVersions {
4713 // Assemble flags to disable all newer versions on the shim.
4714 var flags []string
4715 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004716 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004717 }
4718
Steven Valdezfdd10992016-09-15 16:27:05 -04004719 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004720 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004721 protocols := []protocol{tls}
4722 if runnerVers.hasDTLS && shimVers.hasDTLS {
4723 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004724 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004725 for _, protocol := range protocols {
4726 expectedVersion := shimVers.version
4727 if runnerVers.version < shimVers.version {
4728 expectedVersion = runnerVers.version
4729 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004730
David Benjamin8b8c0062014-11-23 02:47:52 -05004731 suffix := shimVers.name + "-" + runnerVers.name
4732 if protocol == dtls {
4733 suffix += "-DTLS"
4734 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004735
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004736 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004737 clientVers := shimVers.version
4738 if clientVers > VersionTLS10 {
4739 clientVers = VersionTLS10
4740 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004741 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004742 serverVers := expectedVersion
4743 if expectedVersion >= VersionTLS13 {
4744 serverVers = VersionTLS10
4745 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004746 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004747
David Benjamin8b8c0062014-11-23 02:47:52 -05004748 testCases = append(testCases, testCase{
4749 protocol: protocol,
4750 testType: clientTest,
4751 name: "VersionNegotiation-Client-" + suffix,
4752 config: Config{
4753 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004754 Bugs: ProtocolBugs{
4755 ExpectInitialRecordVersion: clientVers,
4756 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004757 },
4758 flags: flags,
4759 expectedVersion: expectedVersion,
4760 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004761 testCases = append(testCases, testCase{
4762 protocol: protocol,
4763 testType: clientTest,
4764 name: "VersionNegotiation-Client2-" + suffix,
4765 config: Config{
4766 MaxVersion: runnerVers.version,
4767 Bugs: ProtocolBugs{
4768 ExpectInitialRecordVersion: clientVers,
4769 },
4770 },
David Benjamin353577c2017-06-29 15:54:58 -04004771 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004772 expectedVersion: expectedVersion,
4773 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004774
4775 testCases = append(testCases, testCase{
4776 protocol: protocol,
4777 testType: serverTest,
4778 name: "VersionNegotiation-Server-" + suffix,
4779 config: Config{
4780 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004781 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004782 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004783 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004784 },
4785 flags: flags,
4786 expectedVersion: expectedVersion,
4787 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004788 testCases = append(testCases, testCase{
4789 protocol: protocol,
4790 testType: serverTest,
4791 name: "VersionNegotiation-Server2-" + suffix,
4792 config: Config{
4793 MaxVersion: runnerVers.version,
4794 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004795 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004796 },
4797 },
David Benjamin353577c2017-06-29 15:54:58 -04004798 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004799 expectedVersion: expectedVersion,
4800 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004801 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004802 }
4803 }
David Benjamin95c69562016-06-29 18:15:03 -04004804
Steven Valdezfdd10992016-09-15 16:27:05 -04004805 // Test the version extension at all versions.
4806 for _, vers := range tlsVersions {
4807 protocols := []protocol{tls}
4808 if vers.hasDTLS {
4809 protocols = append(protocols, dtls)
4810 }
4811 for _, protocol := range protocols {
4812 suffix := vers.name
4813 if protocol == dtls {
4814 suffix += "-DTLS"
4815 }
4816
Steven Valdezc94998a2017-06-20 10:55:02 -04004817 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004818 testCases = append(testCases, testCase{
4819 protocol: protocol,
4820 testType: serverTest,
4821 name: "VersionNegotiationExtension-" + suffix,
4822 config: Config{
4823 Bugs: ProtocolBugs{
4824 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4825 },
4826 },
4827 expectedVersion: vers.version,
4828 })
4829 }
4830
4831 }
4832
4833 // If all versions are unknown, negotiation fails.
4834 testCases = append(testCases, testCase{
4835 testType: serverTest,
4836 name: "NoSupportedVersions",
4837 config: Config{
4838 Bugs: ProtocolBugs{
4839 SendSupportedVersions: []uint16{0x1111},
4840 },
4841 },
4842 shouldFail: true,
4843 expectedError: ":UNSUPPORTED_PROTOCOL:",
4844 })
4845 testCases = append(testCases, testCase{
4846 protocol: dtls,
4847 testType: serverTest,
4848 name: "NoSupportedVersions-DTLS",
4849 config: Config{
4850 Bugs: ProtocolBugs{
4851 SendSupportedVersions: []uint16{0x1111},
4852 },
4853 },
4854 shouldFail: true,
4855 expectedError: ":UNSUPPORTED_PROTOCOL:",
4856 })
4857
4858 testCases = append(testCases, testCase{
4859 testType: serverTest,
4860 name: "ClientHelloVersionTooHigh",
4861 config: Config{
4862 MaxVersion: VersionTLS13,
4863 Bugs: ProtocolBugs{
4864 SendClientVersion: 0x0304,
4865 OmitSupportedVersions: true,
4866 },
4867 },
4868 expectedVersion: VersionTLS12,
4869 })
4870
4871 testCases = append(testCases, testCase{
4872 testType: serverTest,
4873 name: "ConflictingVersionNegotiation",
4874 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004875 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004876 SendClientVersion: VersionTLS12,
4877 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004878 },
4879 },
David Benjaminad75a662016-09-30 15:42:59 -04004880 // The extension takes precedence over the ClientHello version.
4881 expectedVersion: VersionTLS11,
4882 })
4883
4884 testCases = append(testCases, testCase{
4885 testType: serverTest,
4886 name: "ConflictingVersionNegotiation-2",
4887 config: Config{
4888 Bugs: ProtocolBugs{
4889 SendClientVersion: VersionTLS11,
4890 SendSupportedVersions: []uint16{VersionTLS12},
4891 },
4892 },
4893 // The extension takes precedence over the ClientHello version.
4894 expectedVersion: VersionTLS12,
4895 })
4896
4897 testCases = append(testCases, testCase{
4898 testType: serverTest,
4899 name: "RejectFinalTLS13",
4900 config: Config{
4901 Bugs: ProtocolBugs{
4902 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4903 },
4904 },
4905 // We currently implement a draft TLS 1.3 version. Ensure that
4906 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004907 expectedVersion: VersionTLS12,
4908 })
4909
Brian Smithf85d3232016-10-28 10:34:06 -10004910 // Test that the maximum version is selected regardless of the
4911 // client-sent order.
4912 testCases = append(testCases, testCase{
4913 testType: serverTest,
4914 name: "IgnoreClientVersionOrder",
4915 config: Config{
4916 Bugs: ProtocolBugs{
4917 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4918 },
4919 },
4920 expectedVersion: VersionTLS13,
4921 })
4922
David Benjamin95c69562016-06-29 18:15:03 -04004923 // Test for version tolerance.
4924 testCases = append(testCases, testCase{
4925 testType: serverTest,
4926 name: "MinorVersionTolerance",
4927 config: Config{
4928 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004929 SendClientVersion: 0x03ff,
4930 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004931 },
4932 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004933 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004934 })
4935 testCases = append(testCases, testCase{
4936 testType: serverTest,
4937 name: "MajorVersionTolerance",
4938 config: Config{
4939 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004940 SendClientVersion: 0x0400,
4941 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004942 },
4943 },
David Benjaminad75a662016-09-30 15:42:59 -04004944 // TLS 1.3 must be negotiated with the supported_versions
4945 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004946 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004947 })
David Benjaminad75a662016-09-30 15:42:59 -04004948 testCases = append(testCases, testCase{
4949 testType: serverTest,
4950 name: "VersionTolerance-TLS13",
4951 config: Config{
4952 Bugs: ProtocolBugs{
4953 // Although TLS 1.3 does not use
4954 // ClientHello.version, it still tolerates high
4955 // values there.
4956 SendClientVersion: 0x0400,
4957 },
4958 },
4959 expectedVersion: VersionTLS13,
4960 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004961
David Benjamin95c69562016-06-29 18:15:03 -04004962 testCases = append(testCases, testCase{
4963 protocol: dtls,
4964 testType: serverTest,
4965 name: "MinorVersionTolerance-DTLS",
4966 config: Config{
4967 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004968 SendClientVersion: 0xfe00,
4969 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004970 },
4971 },
4972 expectedVersion: VersionTLS12,
4973 })
4974 testCases = append(testCases, testCase{
4975 protocol: dtls,
4976 testType: serverTest,
4977 name: "MajorVersionTolerance-DTLS",
4978 config: Config{
4979 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004980 SendClientVersion: 0xfdff,
4981 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004982 },
4983 },
4984 expectedVersion: VersionTLS12,
4985 })
4986
4987 // Test that versions below 3.0 are rejected.
4988 testCases = append(testCases, testCase{
4989 testType: serverTest,
4990 name: "VersionTooLow",
4991 config: Config{
4992 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004993 SendClientVersion: 0x0200,
4994 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004995 },
4996 },
4997 shouldFail: true,
4998 expectedError: ":UNSUPPORTED_PROTOCOL:",
4999 })
5000 testCases = append(testCases, testCase{
5001 protocol: dtls,
5002 testType: serverTest,
5003 name: "VersionTooLow-DTLS",
5004 config: Config{
5005 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005006 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005007 },
5008 },
5009 shouldFail: true,
5010 expectedError: ":UNSUPPORTED_PROTOCOL:",
5011 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005012
David Benjamin2dc02042016-09-19 19:57:37 -04005013 testCases = append(testCases, testCase{
5014 name: "ServerBogusVersion",
5015 config: Config{
5016 Bugs: ProtocolBugs{
5017 SendServerHelloVersion: 0x1234,
5018 },
5019 },
5020 shouldFail: true,
5021 expectedError: ":UNSUPPORTED_PROTOCOL:",
5022 })
5023
David Benjamin1f61f0d2016-07-10 12:20:35 -04005024 // Test TLS 1.3's downgrade signal.
5025 testCases = append(testCases, testCase{
5026 name: "Downgrade-TLS12-Client",
5027 config: Config{
5028 Bugs: ProtocolBugs{
5029 NegotiateVersion: VersionTLS12,
5030 },
5031 },
David Benjamin592b5322016-09-30 15:15:01 -04005032 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005033 // TODO(davidben): This test should fail once TLS 1.3 is final
5034 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005035 })
5036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "Downgrade-TLS12-Server",
5039 config: Config{
5040 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005041 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005042 },
5043 },
David Benjamin592b5322016-09-30 15:15:01 -04005044 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005045 // TODO(davidben): This test should fail once TLS 1.3 is final
5046 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005047 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005048}
5049
David Benjaminaccb4542014-12-12 23:44:33 -05005050func addMinimumVersionTests() {
5051 for i, shimVers := range tlsVersions {
5052 // Assemble flags to disable all older versions on the shim.
5053 var flags []string
5054 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04005055 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05005056 }
5057
5058 for _, runnerVers := range tlsVersions {
5059 protocols := []protocol{tls}
5060 if runnerVers.hasDTLS && shimVers.hasDTLS {
5061 protocols = append(protocols, dtls)
5062 }
5063 for _, protocol := range protocols {
5064 suffix := shimVers.name + "-" + runnerVers.name
5065 if protocol == dtls {
5066 suffix += "-DTLS"
5067 }
David Benjaminaccb4542014-12-12 23:44:33 -05005068
David Benjaminaccb4542014-12-12 23:44:33 -05005069 var expectedVersion uint16
5070 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005071 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005072 if runnerVers.version >= shimVers.version {
5073 expectedVersion = runnerVers.version
5074 } else {
5075 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005076 expectedError = ":UNSUPPORTED_PROTOCOL:"
5077 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005078 }
5079
5080 testCases = append(testCases, testCase{
5081 protocol: protocol,
5082 testType: clientTest,
5083 name: "MinimumVersion-Client-" + suffix,
5084 config: Config{
5085 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005086 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005087 // Ensure the server does not decline to
5088 // select a version (versions extension) or
5089 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005090 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005091 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005092 },
David Benjaminaccb4542014-12-12 23:44:33 -05005093 },
David Benjamin87909c02014-12-13 01:55:01 -05005094 flags: flags,
5095 expectedVersion: expectedVersion,
5096 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005097 expectedError: expectedError,
5098 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005099 })
5100 testCases = append(testCases, testCase{
5101 protocol: protocol,
5102 testType: clientTest,
5103 name: "MinimumVersion-Client2-" + suffix,
5104 config: Config{
5105 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005106 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005107 // Ensure the server does not decline to
5108 // select a version (versions extension) or
5109 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005110 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005111 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005112 },
David Benjaminaccb4542014-12-12 23:44:33 -05005113 },
David Benjamin353577c2017-06-29 15:54:58 -04005114 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005115 expectedVersion: expectedVersion,
5116 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005117 expectedError: expectedError,
5118 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005119 })
5120
5121 testCases = append(testCases, testCase{
5122 protocol: protocol,
5123 testType: serverTest,
5124 name: "MinimumVersion-Server-" + suffix,
5125 config: Config{
5126 MaxVersion: runnerVers.version,
5127 },
David Benjamin87909c02014-12-13 01:55:01 -05005128 flags: flags,
5129 expectedVersion: expectedVersion,
5130 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005131 expectedError: expectedError,
5132 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005133 })
5134 testCases = append(testCases, testCase{
5135 protocol: protocol,
5136 testType: serverTest,
5137 name: "MinimumVersion-Server2-" + suffix,
5138 config: Config{
5139 MaxVersion: runnerVers.version,
5140 },
David Benjamin353577c2017-06-29 15:54:58 -04005141 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005142 expectedVersion: expectedVersion,
5143 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005144 expectedError: expectedError,
5145 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005146 })
5147 }
5148 }
5149 }
5150}
5151
David Benjamine78bfde2014-09-06 12:45:15 -04005152func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005153 // TODO(davidben): Extensions, where applicable, all move their server
5154 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5155 // tests for both. Also test interaction with 0-RTT when implemented.
5156
David Benjamin97d17d92016-07-14 16:12:00 -04005157 // Repeat extensions tests all versions except SSL 3.0.
5158 for _, ver := range tlsVersions {
5159 if ver.version == VersionSSL30 {
5160 continue
5161 }
5162
David Benjamin97d17d92016-07-14 16:12:00 -04005163 // Test that duplicate extensions are rejected.
5164 testCases = append(testCases, testCase{
5165 testType: clientTest,
5166 name: "DuplicateExtensionClient-" + ver.name,
5167 config: Config{
5168 MaxVersion: ver.version,
5169 Bugs: ProtocolBugs{
5170 DuplicateExtension: true,
5171 },
David Benjamine78bfde2014-09-06 12:45:15 -04005172 },
David Benjamin97d17d92016-07-14 16:12:00 -04005173 shouldFail: true,
5174 expectedLocalError: "remote error: error decoding message",
5175 })
5176 testCases = append(testCases, testCase{
5177 testType: serverTest,
5178 name: "DuplicateExtensionServer-" + ver.name,
5179 config: Config{
5180 MaxVersion: ver.version,
5181 Bugs: ProtocolBugs{
5182 DuplicateExtension: true,
5183 },
David Benjamine78bfde2014-09-06 12:45:15 -04005184 },
David Benjamin97d17d92016-07-14 16:12:00 -04005185 shouldFail: true,
5186 expectedLocalError: "remote error: error decoding message",
5187 })
5188
5189 // Test SNI.
5190 testCases = append(testCases, testCase{
5191 testType: clientTest,
5192 name: "ServerNameExtensionClient-" + ver.name,
5193 config: Config{
5194 MaxVersion: ver.version,
5195 Bugs: ProtocolBugs{
5196 ExpectServerName: "example.com",
5197 },
David Benjamine78bfde2014-09-06 12:45:15 -04005198 },
David Benjamin97d17d92016-07-14 16:12:00 -04005199 flags: []string{"-host-name", "example.com"},
5200 })
5201 testCases = append(testCases, testCase{
5202 testType: clientTest,
5203 name: "ServerNameExtensionClientMismatch-" + ver.name,
5204 config: Config{
5205 MaxVersion: ver.version,
5206 Bugs: ProtocolBugs{
5207 ExpectServerName: "mismatch.com",
5208 },
David Benjamine78bfde2014-09-06 12:45:15 -04005209 },
David Benjamin97d17d92016-07-14 16:12:00 -04005210 flags: []string{"-host-name", "example.com"},
5211 shouldFail: true,
5212 expectedLocalError: "tls: unexpected server name",
5213 })
5214 testCases = append(testCases, testCase{
5215 testType: clientTest,
5216 name: "ServerNameExtensionClientMissing-" + ver.name,
5217 config: Config{
5218 MaxVersion: ver.version,
5219 Bugs: ProtocolBugs{
5220 ExpectServerName: "missing.com",
5221 },
David Benjamine78bfde2014-09-06 12:45:15 -04005222 },
David Benjamin97d17d92016-07-14 16:12:00 -04005223 shouldFail: true,
5224 expectedLocalError: "tls: unexpected server name",
5225 })
5226 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005227 testType: clientTest,
5228 name: "TolerateServerNameAck-" + ver.name,
5229 config: Config{
5230 MaxVersion: ver.version,
5231 Bugs: ProtocolBugs{
5232 SendServerNameAck: true,
5233 },
5234 },
5235 flags: []string{"-host-name", "example.com"},
5236 resumeSession: true,
5237 })
5238 testCases = append(testCases, testCase{
5239 testType: clientTest,
5240 name: "UnsolicitedServerNameAck-" + ver.name,
5241 config: Config{
5242 MaxVersion: ver.version,
5243 Bugs: ProtocolBugs{
5244 SendServerNameAck: true,
5245 },
5246 },
5247 shouldFail: true,
5248 expectedError: ":UNEXPECTED_EXTENSION:",
5249 expectedLocalError: "remote error: unsupported extension",
5250 })
5251 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005252 testType: serverTest,
5253 name: "ServerNameExtensionServer-" + ver.name,
5254 config: Config{
5255 MaxVersion: ver.version,
5256 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005257 },
David Benjamin97d17d92016-07-14 16:12:00 -04005258 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005259 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005260 })
5261
5262 // Test ALPN.
5263 testCases = append(testCases, testCase{
5264 testType: clientTest,
5265 name: "ALPNClient-" + ver.name,
5266 config: Config{
5267 MaxVersion: ver.version,
5268 NextProtos: []string{"foo"},
5269 },
5270 flags: []string{
5271 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5272 "-expect-alpn", "foo",
5273 },
5274 expectedNextProto: "foo",
5275 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005276 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005277 })
5278 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005279 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005280 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005281 config: Config{
5282 MaxVersion: ver.version,
5283 Bugs: ProtocolBugs{
5284 SendALPN: "baz",
5285 },
5286 },
5287 flags: []string{
5288 "-advertise-alpn", "\x03foo\x03bar",
5289 },
5290 shouldFail: true,
5291 expectedError: ":INVALID_ALPN_PROTOCOL:",
5292 expectedLocalError: "remote error: illegal parameter",
5293 })
5294 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005295 testType: clientTest,
5296 name: "ALPNClient-AllowUnknown-" + ver.name,
5297 config: Config{
5298 MaxVersion: ver.version,
5299 Bugs: ProtocolBugs{
5300 SendALPN: "baz",
5301 },
5302 },
5303 flags: []string{
5304 "-advertise-alpn", "\x03foo\x03bar",
5305 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005306 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005307 },
5308 })
5309 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005310 testType: serverTest,
5311 name: "ALPNServer-" + ver.name,
5312 config: Config{
5313 MaxVersion: ver.version,
5314 NextProtos: []string{"foo", "bar", "baz"},
5315 },
5316 flags: []string{
5317 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5318 "-select-alpn", "foo",
5319 },
5320 expectedNextProto: "foo",
5321 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005322 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005323 })
5324 testCases = append(testCases, testCase{
5325 testType: serverTest,
5326 name: "ALPNServer-Decline-" + ver.name,
5327 config: Config{
5328 MaxVersion: ver.version,
5329 NextProtos: []string{"foo", "bar", "baz"},
5330 },
5331 flags: []string{"-decline-alpn"},
5332 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005333 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005334 })
5335
David Benjamin25fe85b2016-08-09 20:00:32 -04005336 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5337 // called once.
5338 testCases = append(testCases, testCase{
5339 testType: serverTest,
5340 name: "ALPNServer-Async-" + ver.name,
5341 config: Config{
5342 MaxVersion: ver.version,
5343 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005344 // Prior to TLS 1.3, exercise the asynchronous session callback.
5345 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005346 },
5347 flags: []string{
5348 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5349 "-select-alpn", "foo",
5350 "-async",
5351 },
5352 expectedNextProto: "foo",
5353 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005354 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005355 })
5356
David Benjamin97d17d92016-07-14 16:12:00 -04005357 var emptyString string
5358 testCases = append(testCases, testCase{
5359 testType: clientTest,
5360 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5361 config: Config{
5362 MaxVersion: ver.version,
5363 NextProtos: []string{""},
5364 Bugs: ProtocolBugs{
5365 // A server returning an empty ALPN protocol
5366 // should be rejected.
5367 ALPNProtocol: &emptyString,
5368 },
5369 },
5370 flags: []string{
5371 "-advertise-alpn", "\x03foo",
5372 },
5373 shouldFail: true,
5374 expectedError: ":PARSE_TLSEXT:",
5375 })
5376 testCases = append(testCases, testCase{
5377 testType: serverTest,
5378 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5379 config: Config{
5380 MaxVersion: ver.version,
5381 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005382 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005383 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005384 },
David Benjamin97d17d92016-07-14 16:12:00 -04005385 flags: []string{
5386 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005387 },
David Benjamin97d17d92016-07-14 16:12:00 -04005388 shouldFail: true,
5389 expectedError: ":PARSE_TLSEXT:",
5390 })
5391
5392 // Test NPN and the interaction with ALPN.
5393 if ver.version < VersionTLS13 {
5394 // Test that the server prefers ALPN over NPN.
5395 testCases = append(testCases, testCase{
5396 testType: serverTest,
5397 name: "ALPNServer-Preferred-" + ver.name,
5398 config: Config{
5399 MaxVersion: ver.version,
5400 NextProtos: []string{"foo", "bar", "baz"},
5401 },
5402 flags: []string{
5403 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5404 "-select-alpn", "foo",
5405 "-advertise-npn", "\x03foo\x03bar\x03baz",
5406 },
5407 expectedNextProto: "foo",
5408 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005409 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005410 })
5411 testCases = append(testCases, testCase{
5412 testType: serverTest,
5413 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5414 config: Config{
5415 MaxVersion: ver.version,
5416 NextProtos: []string{"foo", "bar", "baz"},
5417 Bugs: ProtocolBugs{
5418 SwapNPNAndALPN: true,
5419 },
5420 },
5421 flags: []string{
5422 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5423 "-select-alpn", "foo",
5424 "-advertise-npn", "\x03foo\x03bar\x03baz",
5425 },
5426 expectedNextProto: "foo",
5427 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005428 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005429 })
5430
5431 // Test that negotiating both NPN and ALPN is forbidden.
5432 testCases = append(testCases, testCase{
5433 name: "NegotiateALPNAndNPN-" + ver.name,
5434 config: Config{
5435 MaxVersion: ver.version,
5436 NextProtos: []string{"foo", "bar", "baz"},
5437 Bugs: ProtocolBugs{
5438 NegotiateALPNAndNPN: true,
5439 },
5440 },
5441 flags: []string{
5442 "-advertise-alpn", "\x03foo",
5443 "-select-next-proto", "foo",
5444 },
5445 shouldFail: true,
5446 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5447 })
5448 testCases = append(testCases, testCase{
5449 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5450 config: Config{
5451 MaxVersion: ver.version,
5452 NextProtos: []string{"foo", "bar", "baz"},
5453 Bugs: ProtocolBugs{
5454 NegotiateALPNAndNPN: true,
5455 SwapNPNAndALPN: true,
5456 },
5457 },
5458 flags: []string{
5459 "-advertise-alpn", "\x03foo",
5460 "-select-next-proto", "foo",
5461 },
5462 shouldFail: true,
5463 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5464 })
David Benjamin97d17d92016-07-14 16:12:00 -04005465 }
5466
5467 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005468
5469 // Resume with a corrupt ticket.
5470 testCases = append(testCases, testCase{
5471 testType: serverTest,
5472 name: "CorruptTicket-" + ver.name,
5473 config: Config{
5474 MaxVersion: ver.version,
5475 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005476 FilterTicket: func(in []byte) ([]byte, error) {
5477 in[len(in)-1] ^= 1
5478 return in, nil
5479 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005480 },
5481 },
5482 resumeSession: true,
5483 expectResumeRejected: true,
5484 })
5485 // Test the ticket callback, with and without renewal.
5486 testCases = append(testCases, testCase{
5487 testType: serverTest,
5488 name: "TicketCallback-" + ver.name,
5489 config: Config{
5490 MaxVersion: ver.version,
5491 },
5492 resumeSession: true,
5493 flags: []string{"-use-ticket-callback"},
5494 })
5495 testCases = append(testCases, testCase{
5496 testType: serverTest,
5497 name: "TicketCallback-Renew-" + ver.name,
5498 config: Config{
5499 MaxVersion: ver.version,
5500 Bugs: ProtocolBugs{
5501 ExpectNewTicket: true,
5502 },
5503 },
5504 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5505 resumeSession: true,
5506 })
5507
5508 // Test that the ticket callback is only called once when everything before
5509 // it in the ClientHello is asynchronous. This corrupts the ticket so
5510 // certificate selection callbacks run.
5511 testCases = append(testCases, testCase{
5512 testType: serverTest,
5513 name: "TicketCallback-SingleCall-" + ver.name,
5514 config: Config{
5515 MaxVersion: ver.version,
5516 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005517 FilterTicket: func(in []byte) ([]byte, error) {
5518 in[len(in)-1] ^= 1
5519 return in, nil
5520 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005521 },
5522 },
5523 resumeSession: true,
5524 expectResumeRejected: true,
5525 flags: []string{
5526 "-use-ticket-callback",
5527 "-async",
5528 },
5529 })
5530
David Benjamind4c349b2017-02-09 14:07:17 -05005531 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005532 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005533 testCases = append(testCases, testCase{
5534 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005535 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005536 config: Config{
5537 MaxVersion: ver.version,
5538 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005539 EmptyTicketSessionID: true,
5540 },
5541 },
5542 resumeSession: true,
5543 })
5544 testCases = append(testCases, testCase{
5545 testType: serverTest,
5546 name: "TicketSessionIDLength-16-" + ver.name,
5547 config: Config{
5548 MaxVersion: ver.version,
5549 Bugs: ProtocolBugs{
5550 TicketSessionIDLength: 16,
5551 },
5552 },
5553 resumeSession: true,
5554 })
5555 testCases = append(testCases, testCase{
5556 testType: serverTest,
5557 name: "TicketSessionIDLength-32-" + ver.name,
5558 config: Config{
5559 MaxVersion: ver.version,
5560 Bugs: ProtocolBugs{
5561 TicketSessionIDLength: 32,
5562 },
5563 },
5564 resumeSession: true,
5565 })
5566 testCases = append(testCases, testCase{
5567 testType: serverTest,
5568 name: "TicketSessionIDLength-33-" + ver.name,
5569 config: Config{
5570 MaxVersion: ver.version,
5571 Bugs: ProtocolBugs{
5572 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005573 },
5574 },
5575 resumeSession: true,
5576 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005577 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005578 expectedError: ":DECODE_ERROR:",
5579 })
5580 }
5581
5582 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5583 // are ignored.
5584 if ver.hasDTLS {
5585 testCases = append(testCases, testCase{
5586 protocol: dtls,
5587 name: "SRTP-Client-" + ver.name,
5588 config: Config{
5589 MaxVersion: ver.version,
5590 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5591 },
5592 flags: []string{
5593 "-srtp-profiles",
5594 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5595 },
5596 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5597 })
5598 testCases = append(testCases, testCase{
5599 protocol: dtls,
5600 testType: serverTest,
5601 name: "SRTP-Server-" + ver.name,
5602 config: Config{
5603 MaxVersion: ver.version,
5604 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5605 },
5606 flags: []string{
5607 "-srtp-profiles",
5608 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5609 },
5610 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5611 })
5612 // Test that the MKI is ignored.
5613 testCases = append(testCases, testCase{
5614 protocol: dtls,
5615 testType: serverTest,
5616 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5617 config: Config{
5618 MaxVersion: ver.version,
5619 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5620 Bugs: ProtocolBugs{
5621 SRTPMasterKeyIdentifer: "bogus",
5622 },
5623 },
5624 flags: []string{
5625 "-srtp-profiles",
5626 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5627 },
5628 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5629 })
5630 // Test that SRTP isn't negotiated on the server if there were
5631 // no matching profiles.
5632 testCases = append(testCases, testCase{
5633 protocol: dtls,
5634 testType: serverTest,
5635 name: "SRTP-Server-NoMatch-" + ver.name,
5636 config: Config{
5637 MaxVersion: ver.version,
5638 SRTPProtectionProfiles: []uint16{100, 101, 102},
5639 },
5640 flags: []string{
5641 "-srtp-profiles",
5642 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5643 },
5644 expectedSRTPProtectionProfile: 0,
5645 })
5646 // Test that the server returning an invalid SRTP profile is
5647 // flagged as an error by the client.
5648 testCases = append(testCases, testCase{
5649 protocol: dtls,
5650 name: "SRTP-Client-NoMatch-" + ver.name,
5651 config: Config{
5652 MaxVersion: ver.version,
5653 Bugs: ProtocolBugs{
5654 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5655 },
5656 },
5657 flags: []string{
5658 "-srtp-profiles",
5659 "SRTP_AES128_CM_SHA1_80",
5660 },
5661 shouldFail: true,
5662 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5663 })
5664 }
5665
5666 // Test SCT list.
5667 testCases = append(testCases, testCase{
5668 name: "SignedCertificateTimestampList-Client-" + ver.name,
5669 testType: clientTest,
5670 config: Config{
5671 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005672 },
David Benjamin97d17d92016-07-14 16:12:00 -04005673 flags: []string{
5674 "-enable-signed-cert-timestamps",
5675 "-expect-signed-cert-timestamps",
5676 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005677 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005678 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005679 })
David Benjamindaa88502016-10-04 16:32:16 -04005680
Adam Langleycfa08c32016-11-17 13:21:27 -08005681 var differentSCTList []byte
5682 differentSCTList = append(differentSCTList, testSCTList...)
5683 differentSCTList[len(differentSCTList)-1] ^= 1
5684
David Benjamindaa88502016-10-04 16:32:16 -04005685 // The SCT extension did not specify that it must only be sent on resumption as it
5686 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005687 testCases = append(testCases, testCase{
5688 name: "SendSCTListOnResume-" + ver.name,
5689 config: Config{
5690 MaxVersion: ver.version,
5691 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005692 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005693 },
David Benjamind98452d2015-06-16 14:16:23 -04005694 },
David Benjamin97d17d92016-07-14 16:12:00 -04005695 flags: []string{
5696 "-enable-signed-cert-timestamps",
5697 "-expect-signed-cert-timestamps",
5698 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005699 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005700 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005701 })
David Benjamindaa88502016-10-04 16:32:16 -04005702
David Benjamin97d17d92016-07-14 16:12:00 -04005703 testCases = append(testCases, testCase{
5704 name: "SignedCertificateTimestampList-Server-" + ver.name,
5705 testType: serverTest,
5706 config: Config{
5707 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005708 },
David Benjamin97d17d92016-07-14 16:12:00 -04005709 flags: []string{
5710 "-signed-cert-timestamps",
5711 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005712 },
David Benjamin97d17d92016-07-14 16:12:00 -04005713 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005714 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005715 })
David Benjamin53210cb2016-11-16 09:01:48 +09005716
Adam Langleycfa08c32016-11-17 13:21:27 -08005717 emptySCTListCert := *testCerts[0].cert
5718 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5719
5720 // Test empty SCT list.
5721 testCases = append(testCases, testCase{
5722 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5723 testType: clientTest,
5724 config: Config{
5725 MaxVersion: ver.version,
5726 Certificates: []Certificate{emptySCTListCert},
5727 },
5728 flags: []string{
5729 "-enable-signed-cert-timestamps",
5730 },
5731 shouldFail: true,
5732 expectedError: ":ERROR_PARSING_EXTENSION:",
5733 })
5734
5735 emptySCTCert := *testCerts[0].cert
5736 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5737
5738 // Test empty SCT in non-empty list.
5739 testCases = append(testCases, testCase{
5740 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5741 testType: clientTest,
5742 config: Config{
5743 MaxVersion: ver.version,
5744 Certificates: []Certificate{emptySCTCert},
5745 },
5746 flags: []string{
5747 "-enable-signed-cert-timestamps",
5748 },
5749 shouldFail: true,
5750 expectedError: ":ERROR_PARSING_EXTENSION:",
5751 })
5752
David Benjamin53210cb2016-11-16 09:01:48 +09005753 // Test that certificate-related extensions are not sent unsolicited.
5754 testCases = append(testCases, testCase{
5755 testType: serverTest,
5756 name: "UnsolicitedCertificateExtensions-" + ver.name,
5757 config: Config{
5758 MaxVersion: ver.version,
5759 Bugs: ProtocolBugs{
5760 NoOCSPStapling: true,
5761 NoSignedCertificateTimestamps: true,
5762 },
5763 },
5764 flags: []string{
5765 "-ocsp-response",
5766 base64.StdEncoding.EncodeToString(testOCSPResponse),
5767 "-signed-cert-timestamps",
5768 base64.StdEncoding.EncodeToString(testSCTList),
5769 },
5770 })
David Benjamin97d17d92016-07-14 16:12:00 -04005771 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005772
Paul Lietar4fac72e2015-09-09 13:44:55 +01005773 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005774 testType: clientTest,
5775 name: "ClientHelloPadding",
5776 config: Config{
5777 Bugs: ProtocolBugs{
5778 RequireClientHelloSize: 512,
5779 },
5780 },
5781 // This hostname just needs to be long enough to push the
5782 // ClientHello into F5's danger zone between 256 and 511 bytes
5783 // long.
5784 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5785 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005786
5787 // Extensions should not function in SSL 3.0.
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "SSLv3Extensions-NoALPN",
5791 config: Config{
5792 MaxVersion: VersionSSL30,
5793 NextProtos: []string{"foo", "bar", "baz"},
5794 },
5795 flags: []string{
5796 "-select-alpn", "foo",
5797 },
5798 expectNoNextProto: true,
5799 })
5800
5801 // Test session tickets separately as they follow a different codepath.
5802 testCases = append(testCases, testCase{
5803 testType: serverTest,
5804 name: "SSLv3Extensions-NoTickets",
5805 config: Config{
5806 MaxVersion: VersionSSL30,
5807 Bugs: ProtocolBugs{
5808 // Historically, session tickets in SSL 3.0
5809 // failed in different ways depending on whether
5810 // the client supported renegotiation_info.
5811 NoRenegotiationInfo: true,
5812 },
5813 },
5814 resumeSession: true,
5815 })
5816 testCases = append(testCases, testCase{
5817 testType: serverTest,
5818 name: "SSLv3Extensions-NoTickets2",
5819 config: Config{
5820 MaxVersion: VersionSSL30,
5821 },
5822 resumeSession: true,
5823 })
5824
5825 // But SSL 3.0 does send and process renegotiation_info.
5826 testCases = append(testCases, testCase{
5827 testType: serverTest,
5828 name: "SSLv3Extensions-RenegotiationInfo",
5829 config: Config{
5830 MaxVersion: VersionSSL30,
5831 Bugs: ProtocolBugs{
5832 RequireRenegotiationInfo: true,
5833 },
5834 },
David Benjamind2610042017-01-03 10:49:28 -05005835 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005836 })
5837 testCases = append(testCases, testCase{
5838 testType: serverTest,
5839 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5840 config: Config{
5841 MaxVersion: VersionSSL30,
5842 Bugs: ProtocolBugs{
5843 NoRenegotiationInfo: true,
5844 SendRenegotiationSCSV: true,
5845 RequireRenegotiationInfo: true,
5846 },
5847 },
David Benjamind2610042017-01-03 10:49:28 -05005848 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005849 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005850
5851 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5852 // in ServerHello.
5853 testCases = append(testCases, testCase{
5854 name: "NPN-Forbidden-TLS13",
5855 config: Config{
5856 MaxVersion: VersionTLS13,
5857 NextProtos: []string{"foo"},
5858 Bugs: ProtocolBugs{
5859 NegotiateNPNAtAllVersions: true,
5860 },
5861 },
5862 flags: []string{"-select-next-proto", "foo"},
5863 shouldFail: true,
5864 expectedError: ":ERROR_PARSING_EXTENSION:",
5865 })
5866 testCases = append(testCases, testCase{
5867 name: "EMS-Forbidden-TLS13",
5868 config: Config{
5869 MaxVersion: VersionTLS13,
5870 Bugs: ProtocolBugs{
5871 NegotiateEMSAtAllVersions: true,
5872 },
5873 },
5874 shouldFail: true,
5875 expectedError: ":ERROR_PARSING_EXTENSION:",
5876 })
5877 testCases = append(testCases, testCase{
5878 name: "RenegotiationInfo-Forbidden-TLS13",
5879 config: Config{
5880 MaxVersion: VersionTLS13,
5881 Bugs: ProtocolBugs{
5882 NegotiateRenegotiationInfoAtAllVersions: true,
5883 },
5884 },
5885 shouldFail: true,
5886 expectedError: ":ERROR_PARSING_EXTENSION:",
5887 })
5888 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005889 name: "Ticket-Forbidden-TLS13",
5890 config: Config{
5891 MaxVersion: VersionTLS12,
5892 },
5893 resumeConfig: &Config{
5894 MaxVersion: VersionTLS13,
5895 Bugs: ProtocolBugs{
5896 AdvertiseTicketExtension: true,
5897 },
5898 },
5899 resumeSession: true,
5900 shouldFail: true,
5901 expectedError: ":ERROR_PARSING_EXTENSION:",
5902 })
5903
5904 // Test that illegal extensions in TLS 1.3 are declined by the server if
5905 // offered in ClientHello. The runner's server will fail if this occurs,
5906 // so we exercise the offering path. (EMS and Renegotiation Info are
5907 // implicit in every test.)
5908 testCases = append(testCases, testCase{
5909 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005910 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005911 config: Config{
5912 MaxVersion: VersionTLS13,
5913 NextProtos: []string{"bar"},
5914 },
5915 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5916 })
David Benjamin196df5b2016-09-21 16:23:27 -04005917
David Benjamindaa88502016-10-04 16:32:16 -04005918 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5919 // tolerated.
5920 testCases = append(testCases, testCase{
5921 name: "SendOCSPResponseOnResume-TLS12",
5922 config: Config{
5923 MaxVersion: VersionTLS12,
5924 Bugs: ProtocolBugs{
5925 SendOCSPResponseOnResume: []byte("bogus"),
5926 },
5927 },
5928 flags: []string{
5929 "-enable-ocsp-stapling",
5930 "-expect-ocsp-response",
5931 base64.StdEncoding.EncodeToString(testOCSPResponse),
5932 },
5933 resumeSession: true,
5934 })
5935
David Benjamindaa88502016-10-04 16:32:16 -04005936 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005937 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005938 config: Config{
5939 MaxVersion: VersionTLS13,
5940 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005941 SendExtensionOnCertificate: testOCSPExtension,
5942 },
5943 },
5944 shouldFail: true,
5945 expectedError: ":UNEXPECTED_EXTENSION:",
5946 })
5947
5948 testCases = append(testCases, testCase{
5949 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5950 config: Config{
5951 MaxVersion: VersionTLS13,
5952 Bugs: ProtocolBugs{
5953 SendExtensionOnCertificate: testSCTExtension,
5954 },
5955 },
5956 shouldFail: true,
5957 expectedError: ":UNEXPECTED_EXTENSION:",
5958 })
5959
5960 // Test that extensions on client certificates are never accepted.
5961 testCases = append(testCases, testCase{
5962 name: "SendExtensionOnClientCertificate-TLS13",
5963 testType: serverTest,
5964 config: Config{
5965 MaxVersion: VersionTLS13,
5966 Certificates: []Certificate{rsaCertificate},
5967 Bugs: ProtocolBugs{
5968 SendExtensionOnCertificate: testOCSPExtension,
5969 },
5970 },
5971 flags: []string{
5972 "-enable-ocsp-stapling",
5973 "-require-any-client-certificate",
5974 },
5975 shouldFail: true,
5976 expectedError: ":UNEXPECTED_EXTENSION:",
5977 })
5978
5979 testCases = append(testCases, testCase{
5980 name: "SendUnknownExtensionOnCertificate-TLS13",
5981 config: Config{
5982 MaxVersion: VersionTLS13,
5983 Bugs: ProtocolBugs{
5984 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5985 },
5986 },
5987 shouldFail: true,
5988 expectedError: ":UNEXPECTED_EXTENSION:",
5989 })
5990
Adam Langleycfa08c32016-11-17 13:21:27 -08005991 var differentSCTList []byte
5992 differentSCTList = append(differentSCTList, testSCTList...)
5993 differentSCTList[len(differentSCTList)-1] ^= 1
5994
Steven Valdeza833c352016-11-01 13:39:36 -04005995 // Test that extensions on intermediates are allowed but ignored.
5996 testCases = append(testCases, testCase{
5997 name: "IgnoreExtensionsOnIntermediates-TLS13",
5998 config: Config{
5999 MaxVersion: VersionTLS13,
6000 Certificates: []Certificate{rsaChainCertificate},
6001 Bugs: ProtocolBugs{
6002 // Send different values on the intermediate. This tests
6003 // the intermediate's extensions do not override the
6004 // leaf's.
6005 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006006 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006007 },
6008 },
6009 flags: []string{
6010 "-enable-ocsp-stapling",
6011 "-expect-ocsp-response",
6012 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006013 "-enable-signed-cert-timestamps",
6014 "-expect-signed-cert-timestamps",
6015 base64.StdEncoding.EncodeToString(testSCTList),
6016 },
6017 resumeSession: true,
6018 })
6019
6020 // Test that extensions are not sent on intermediates when configured
6021 // only for a leaf.
6022 testCases = append(testCases, testCase{
6023 testType: serverTest,
6024 name: "SendNoExtensionsOnIntermediate-TLS13",
6025 config: Config{
6026 MaxVersion: VersionTLS13,
6027 Bugs: ProtocolBugs{
6028 ExpectNoExtensionsOnIntermediate: true,
6029 },
6030 },
6031 flags: []string{
6032 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6033 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6034 "-ocsp-response",
6035 base64.StdEncoding.EncodeToString(testOCSPResponse),
6036 "-signed-cert-timestamps",
6037 base64.StdEncoding.EncodeToString(testSCTList),
6038 },
6039 })
6040
6041 // Test that extensions are not sent on client certificates.
6042 testCases = append(testCases, testCase{
6043 name: "SendNoClientCertificateExtensions-TLS13",
6044 config: Config{
6045 MaxVersion: VersionTLS13,
6046 ClientAuth: RequireAnyClientCert,
6047 },
6048 flags: []string{
6049 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6050 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6051 "-ocsp-response",
6052 base64.StdEncoding.EncodeToString(testOCSPResponse),
6053 "-signed-cert-timestamps",
6054 base64.StdEncoding.EncodeToString(testSCTList),
6055 },
6056 })
6057
6058 testCases = append(testCases, testCase{
6059 name: "SendDuplicateExtensionsOnCerts-TLS13",
6060 config: Config{
6061 MaxVersion: VersionTLS13,
6062 Bugs: ProtocolBugs{
6063 SendDuplicateCertExtensions: true,
6064 },
6065 },
6066 flags: []string{
6067 "-enable-ocsp-stapling",
6068 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006069 },
6070 resumeSession: true,
6071 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006072 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006073 })
Adam Langley9b885c52016-11-18 14:21:03 -08006074
6075 testCases = append(testCases, testCase{
6076 name: "SignedCertificateTimestampListInvalid-Server",
6077 testType: serverTest,
6078 flags: []string{
6079 "-signed-cert-timestamps",
6080 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6081 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006082 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006083 expectedError: ":INVALID_SCT_LIST:",
6084 })
David Benjamine78bfde2014-09-06 12:45:15 -04006085}
6086
David Benjamin01fe8202014-09-24 15:21:44 -04006087func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006088 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006089 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006090 // SSL 3.0 does not have tickets and TLS 1.3 does not
6091 // have session IDs, so skip their cross-resumption
6092 // tests.
6093 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6094 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6095 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006096 }
6097
David Benjamin8b8c0062014-11-23 02:47:52 -05006098 protocols := []protocol{tls}
6099 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6100 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006101 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006102 for _, protocol := range protocols {
6103 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6104 if protocol == dtls {
6105 suffix += "-DTLS"
6106 }
6107
David Benjaminece3de92015-03-16 18:02:20 -04006108 if sessionVers.version == resumeVers.version {
6109 testCases = append(testCases, testCase{
6110 protocol: protocol,
6111 name: "Resume-Client" + suffix,
6112 resumeSession: true,
6113 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006114 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006115 Bugs: ProtocolBugs{
6116 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6117 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6118 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006119 },
David Benjaminece3de92015-03-16 18:02:20 -04006120 expectedVersion: sessionVers.version,
6121 expectedResumeVersion: resumeVers.version,
6122 })
6123 } else {
David Benjamin405da482016-08-08 17:25:07 -04006124 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6125
6126 // Offering a TLS 1.3 session sends an empty session ID, so
6127 // there is no way to convince a non-lookahead client the
6128 // session was resumed. It will appear to the client that a
6129 // stray ChangeCipherSpec was sent.
6130 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6131 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006132 }
6133
David Benjaminece3de92015-03-16 18:02:20 -04006134 testCases = append(testCases, testCase{
6135 protocol: protocol,
6136 name: "Resume-Client-Mismatch" + suffix,
6137 resumeSession: true,
6138 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006139 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006140 },
David Benjaminece3de92015-03-16 18:02:20 -04006141 expectedVersion: sessionVers.version,
6142 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006143 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006144 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006145 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006146 },
6147 },
6148 expectedResumeVersion: resumeVers.version,
6149 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006150 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006151 })
6152 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006153
6154 testCases = append(testCases, testCase{
6155 protocol: protocol,
6156 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006157 resumeSession: true,
6158 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006159 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006160 },
6161 expectedVersion: sessionVers.version,
6162 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006163 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006164 },
6165 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006166 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006167 expectedResumeVersion: resumeVers.version,
6168 })
6169
David Benjamin8b8c0062014-11-23 02:47:52 -05006170 testCases = append(testCases, testCase{
6171 protocol: protocol,
6172 testType: serverTest,
6173 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006174 resumeSession: true,
6175 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006176 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006177 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006178 expectedVersion: sessionVers.version,
6179 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006180 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006181 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006182 Bugs: ProtocolBugs{
6183 SendBothTickets: true,
6184 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006185 },
6186 expectedResumeVersion: resumeVers.version,
6187 })
6188 }
David Benjamin01fe8202014-09-24 15:21:44 -04006189 }
6190 }
David Benjaminece3de92015-03-16 18:02:20 -04006191
David Benjamin4199b0d2016-11-01 13:58:25 -04006192 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006193 testCases = append(testCases, testCase{
6194 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006195 name: "ShimTicketRewritable",
6196 resumeSession: true,
6197 config: Config{
6198 MaxVersion: VersionTLS12,
6199 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6200 Bugs: ProtocolBugs{
6201 FilterTicket: func(in []byte) ([]byte, error) {
6202 in, err := SetShimTicketVersion(in, VersionTLS12)
6203 if err != nil {
6204 return nil, err
6205 }
6206 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6207 },
6208 },
6209 },
6210 flags: []string{
6211 "-ticket-key",
6212 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6213 },
6214 })
6215
6216 // Resumptions are declined if the version does not match.
6217 testCases = append(testCases, testCase{
6218 testType: serverTest,
6219 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006220 resumeSession: true,
6221 config: Config{
6222 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006223 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006224 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006225 FilterTicket: func(in []byte) ([]byte, error) {
6226 return SetShimTicketVersion(in, VersionTLS13)
6227 },
6228 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006229 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006230 flags: []string{
6231 "-ticket-key",
6232 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6233 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006234 expectResumeRejected: true,
6235 })
6236
6237 testCases = append(testCases, testCase{
6238 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006239 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006240 resumeSession: true,
6241 config: Config{
6242 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006243 Bugs: ProtocolBugs{
6244 FilterTicket: func(in []byte) ([]byte, error) {
6245 return SetShimTicketVersion(in, VersionTLS12)
6246 },
6247 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006248 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006249 flags: []string{
6250 "-ticket-key",
6251 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6252 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006253 expectResumeRejected: true,
6254 })
6255
David Benjamin4199b0d2016-11-01 13:58:25 -04006256 // Resumptions are declined if the cipher is invalid or disabled.
6257 testCases = append(testCases, testCase{
6258 testType: serverTest,
6259 name: "Resume-Server-DeclineBadCipher",
6260 resumeSession: true,
6261 config: Config{
6262 MaxVersion: VersionTLS12,
6263 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006264 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006265 FilterTicket: func(in []byte) ([]byte, error) {
6266 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6267 },
6268 },
6269 },
6270 flags: []string{
6271 "-ticket-key",
6272 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6273 },
6274 expectResumeRejected: true,
6275 })
6276
6277 testCases = append(testCases, testCase{
6278 testType: serverTest,
6279 name: "Resume-Server-DeclineBadCipher-2",
6280 resumeSession: true,
6281 config: Config{
6282 MaxVersion: VersionTLS12,
6283 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006284 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006285 FilterTicket: func(in []byte) ([]byte, error) {
6286 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6287 },
6288 },
6289 },
6290 flags: []string{
6291 "-cipher", "AES128",
6292 "-ticket-key",
6293 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6294 },
6295 expectResumeRejected: true,
6296 })
6297
David Benjaminf01f42a2016-11-16 19:05:33 +09006298 // Sessions are not resumed if they do not use the preferred cipher.
6299 testCases = append(testCases, testCase{
6300 testType: serverTest,
6301 name: "Resume-Server-CipherNotPreferred",
6302 resumeSession: true,
6303 config: Config{
6304 MaxVersion: VersionTLS12,
6305 Bugs: ProtocolBugs{
6306 ExpectNewTicket: true,
6307 FilterTicket: func(in []byte) ([]byte, error) {
6308 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6309 },
6310 },
6311 },
6312 flags: []string{
6313 "-ticket-key",
6314 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6315 },
6316 shouldFail: false,
6317 expectResumeRejected: true,
6318 })
6319
6320 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6321 // PRF hashes match, but BoringSSL will always decline such resumptions.
6322 testCases = append(testCases, testCase{
6323 testType: serverTest,
6324 name: "Resume-Server-CipherNotPreferred-TLS13",
6325 resumeSession: true,
6326 config: Config{
6327 MaxVersion: VersionTLS13,
6328 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6329 Bugs: ProtocolBugs{
6330 FilterTicket: func(in []byte) ([]byte, error) {
6331 // If the client (runner) offers ChaCha20-Poly1305 first, the
6332 // server (shim) always prefers it. Switch it to AES-GCM.
6333 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6334 },
6335 },
6336 },
6337 flags: []string{
6338 "-ticket-key",
6339 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6340 },
6341 shouldFail: false,
6342 expectResumeRejected: true,
6343 })
6344
6345 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006346 testCases = append(testCases, testCase{
6347 testType: serverTest,
6348 name: "Resume-Server-DeclineBadCipher-TLS13",
6349 resumeSession: true,
6350 config: Config{
6351 MaxVersion: VersionTLS13,
6352 Bugs: ProtocolBugs{
6353 FilterTicket: func(in []byte) ([]byte, error) {
6354 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6355 },
6356 },
6357 },
6358 flags: []string{
6359 "-ticket-key",
6360 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6361 },
6362 expectResumeRejected: true,
6363 })
6364
David Benjaminf01f42a2016-11-16 19:05:33 +09006365 // If the client does not offer the cipher from the session, decline to
6366 // resume. Clients are forbidden from doing this, but BoringSSL selects
6367 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006368 testCases = append(testCases, testCase{
6369 testType: serverTest,
6370 name: "Resume-Server-UnofferedCipher",
6371 resumeSession: true,
6372 config: Config{
6373 MaxVersion: VersionTLS12,
6374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6375 },
6376 resumeConfig: &Config{
6377 MaxVersion: VersionTLS12,
6378 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6379 Bugs: ProtocolBugs{
6380 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6381 },
6382 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006383 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006384 })
6385
David Benjaminf01f42a2016-11-16 19:05:33 +09006386 // In TLS 1.3, clients may advertise a cipher list which does not
6387 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006388 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6389 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006390 testCases = append(testCases, testCase{
6391 testType: serverTest,
6392 name: "Resume-Server-UnofferedCipher-TLS13",
6393 resumeSession: true,
6394 config: Config{
6395 MaxVersion: VersionTLS13,
6396 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6397 },
6398 resumeConfig: &Config{
6399 MaxVersion: VersionTLS13,
6400 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6401 Bugs: ProtocolBugs{
6402 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6403 },
6404 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006405 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006406 })
6407
David Benjamin4199b0d2016-11-01 13:58:25 -04006408 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006409 testCases = append(testCases, testCase{
6410 name: "Resume-Client-CipherMismatch",
6411 resumeSession: true,
6412 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006413 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006414 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6415 },
6416 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006417 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006418 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6419 Bugs: ProtocolBugs{
6420 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6421 },
6422 },
6423 shouldFail: true,
6424 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6425 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006426
David Benjamine1cc35e2016-11-16 16:25:58 +09006427 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6428 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006429 testCases = append(testCases, testCase{
6430 name: "Resume-Client-CipherMismatch-TLS13",
6431 resumeSession: true,
6432 config: Config{
6433 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006434 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006435 },
6436 resumeConfig: &Config{
6437 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006438 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6439 },
6440 })
6441
6442 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6443 testCases = append(testCases, testCase{
6444 name: "Resume-Client-PRFMismatch-TLS13",
6445 resumeSession: true,
6446 config: Config{
6447 MaxVersion: VersionTLS13,
6448 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6449 },
6450 resumeConfig: &Config{
6451 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006452 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006453 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006454 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006455 },
6456 },
6457 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006458 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006459 })
Steven Valdeza833c352016-11-01 13:39:36 -04006460
6461 testCases = append(testCases, testCase{
6462 testType: serverTest,
6463 name: "Resume-Server-BinderWrongLength",
6464 resumeSession: true,
6465 config: Config{
6466 MaxVersion: VersionTLS13,
6467 Bugs: ProtocolBugs{
6468 SendShortPSKBinder: true,
6469 },
6470 },
6471 shouldFail: true,
6472 expectedLocalError: "remote error: error decrypting message",
6473 expectedError: ":DIGEST_CHECK_FAILED:",
6474 })
6475
6476 testCases = append(testCases, testCase{
6477 testType: serverTest,
6478 name: "Resume-Server-NoPSKBinder",
6479 resumeSession: true,
6480 config: Config{
6481 MaxVersion: VersionTLS13,
6482 Bugs: ProtocolBugs{
6483 SendNoPSKBinder: true,
6484 },
6485 },
6486 shouldFail: true,
6487 expectedLocalError: "remote error: error decoding message",
6488 expectedError: ":DECODE_ERROR:",
6489 })
6490
6491 testCases = append(testCases, testCase{
6492 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006493 name: "Resume-Server-ExtraPSKBinder",
6494 resumeSession: true,
6495 config: Config{
6496 MaxVersion: VersionTLS13,
6497 Bugs: ProtocolBugs{
6498 SendExtraPSKBinder: true,
6499 },
6500 },
6501 shouldFail: true,
6502 expectedLocalError: "remote error: illegal parameter",
6503 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6504 })
6505
6506 testCases = append(testCases, testCase{
6507 testType: serverTest,
6508 name: "Resume-Server-ExtraIdentityNoBinder",
6509 resumeSession: true,
6510 config: Config{
6511 MaxVersion: VersionTLS13,
6512 Bugs: ProtocolBugs{
6513 ExtraPSKIdentity: true,
6514 },
6515 },
6516 shouldFail: true,
6517 expectedLocalError: "remote error: illegal parameter",
6518 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6519 })
6520
6521 testCases = append(testCases, testCase{
6522 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006523 name: "Resume-Server-InvalidPSKBinder",
6524 resumeSession: true,
6525 config: Config{
6526 MaxVersion: VersionTLS13,
6527 Bugs: ProtocolBugs{
6528 SendInvalidPSKBinder: true,
6529 },
6530 },
6531 shouldFail: true,
6532 expectedLocalError: "remote error: error decrypting message",
6533 expectedError: ":DIGEST_CHECK_FAILED:",
6534 })
6535
6536 testCases = append(testCases, testCase{
6537 testType: serverTest,
6538 name: "Resume-Server-PSKBinderFirstExtension",
6539 resumeSession: true,
6540 config: Config{
6541 MaxVersion: VersionTLS13,
6542 Bugs: ProtocolBugs{
6543 PSKBinderFirst: true,
6544 },
6545 },
6546 shouldFail: true,
6547 expectedLocalError: "remote error: illegal parameter",
6548 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6549 })
David Benjamin01fe8202014-09-24 15:21:44 -04006550}
6551
Adam Langley2ae77d22014-10-28 17:29:33 -07006552func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006553 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006554 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006555 testType: serverTest,
6556 name: "Renegotiate-Server-Forbidden",
6557 config: Config{
6558 MaxVersion: VersionTLS12,
6559 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006560 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006561 shouldFail: true,
6562 expectedError: ":NO_RENEGOTIATION:",
6563 expectedLocalError: "remote error: no renegotiation",
6564 })
Adam Langley5021b222015-06-12 18:27:58 -07006565 // The server shouldn't echo the renegotiation extension unless
6566 // requested by the client.
6567 testCases = append(testCases, testCase{
6568 testType: serverTest,
6569 name: "Renegotiate-Server-NoExt",
6570 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006571 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006572 Bugs: ProtocolBugs{
6573 NoRenegotiationInfo: true,
6574 RequireRenegotiationInfo: true,
6575 },
6576 },
6577 shouldFail: true,
6578 expectedLocalError: "renegotiation extension missing",
6579 })
6580 // The renegotiation SCSV should be sufficient for the server to echo
6581 // the extension.
6582 testCases = append(testCases, testCase{
6583 testType: serverTest,
6584 name: "Renegotiate-Server-NoExt-SCSV",
6585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006586 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006587 Bugs: ProtocolBugs{
6588 NoRenegotiationInfo: true,
6589 SendRenegotiationSCSV: true,
6590 RequireRenegotiationInfo: true,
6591 },
6592 },
6593 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006594 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006595 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006597 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006598 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006599 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006600 },
6601 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006602 renegotiate: 1,
6603 flags: []string{
6604 "-renegotiate-freely",
6605 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006606 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006607 },
David Benjamincdea40c2015-03-19 14:09:43 -04006608 })
6609 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006610 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006611 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006613 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006614 Bugs: ProtocolBugs{
6615 EmptyRenegotiationInfo: true,
6616 },
6617 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006618 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006619 shouldFail: true,
6620 expectedError: ":RENEGOTIATION_MISMATCH:",
6621 })
6622 testCases = append(testCases, testCase{
6623 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006624 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006626 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006627 Bugs: ProtocolBugs{
6628 BadRenegotiationInfo: true,
6629 },
6630 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006631 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006632 shouldFail: true,
6633 expectedError: ":RENEGOTIATION_MISMATCH:",
6634 })
6635 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006636 name: "Renegotiate-Client-BadExt2",
6637 renegotiate: 1,
6638 config: Config{
6639 MaxVersion: VersionTLS12,
6640 Bugs: ProtocolBugs{
6641 BadRenegotiationInfoEnd: true,
6642 },
6643 },
6644 flags: []string{"-renegotiate-freely"},
6645 shouldFail: true,
6646 expectedError: ":RENEGOTIATION_MISMATCH:",
6647 })
6648 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006649 name: "Renegotiate-Client-Downgrade",
6650 renegotiate: 1,
6651 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006652 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006653 Bugs: ProtocolBugs{
6654 NoRenegotiationInfoAfterInitial: true,
6655 },
6656 },
6657 flags: []string{"-renegotiate-freely"},
6658 shouldFail: true,
6659 expectedError: ":RENEGOTIATION_MISMATCH:",
6660 })
6661 testCases = append(testCases, testCase{
6662 name: "Renegotiate-Client-Upgrade",
6663 renegotiate: 1,
6664 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006665 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006666 Bugs: ProtocolBugs{
6667 NoRenegotiationInfoInInitial: true,
6668 },
6669 },
6670 flags: []string{"-renegotiate-freely"},
6671 shouldFail: true,
6672 expectedError: ":RENEGOTIATION_MISMATCH:",
6673 })
6674 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006675 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006676 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006677 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006678 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006679 Bugs: ProtocolBugs{
6680 NoRenegotiationInfo: true,
6681 },
6682 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006683 flags: []string{
6684 "-renegotiate-freely",
6685 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006686 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006687 },
David Benjamincff0b902015-05-15 23:09:47 -04006688 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006689
6690 // Test that the server may switch ciphers on renegotiation without
6691 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006692 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006693 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006694 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006695 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006696 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006697 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006698 },
6699 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006700 flags: []string{
6701 "-renegotiate-freely",
6702 "-expect-total-renegotiations", "1",
6703 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006704 })
6705 testCases = append(testCases, testCase{
6706 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006707 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006708 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006709 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006710 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6711 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006712 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006713 flags: []string{
6714 "-renegotiate-freely",
6715 "-expect-total-renegotiations", "1",
6716 },
David Benjaminb16346b2015-04-08 19:16:58 -04006717 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006718
6719 // Test that the server may not switch versions on renegotiation.
6720 testCases = append(testCases, testCase{
6721 name: "Renegotiate-Client-SwitchVersion",
6722 config: Config{
6723 MaxVersion: VersionTLS12,
6724 // Pick a cipher which exists at both versions.
6725 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6726 Bugs: ProtocolBugs{
6727 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006728 // Avoid failing early at the record layer.
6729 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006730 },
6731 },
6732 renegotiate: 1,
6733 flags: []string{
6734 "-renegotiate-freely",
6735 "-expect-total-renegotiations", "1",
6736 },
6737 shouldFail: true,
6738 expectedError: ":WRONG_SSL_VERSION:",
6739 })
6740
David Benjaminb16346b2015-04-08 19:16:58 -04006741 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006742 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006743 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006744 config: Config{
6745 MaxVersion: VersionTLS10,
6746 Bugs: ProtocolBugs{
6747 RequireSameRenegoClientVersion: true,
6748 },
6749 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006750 flags: []string{
6751 "-renegotiate-freely",
6752 "-expect-total-renegotiations", "1",
6753 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006754 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006755 testCases = append(testCases, testCase{
6756 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006757 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006759 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6761 NextProtos: []string{"foo"},
6762 },
6763 flags: []string{
6764 "-false-start",
6765 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006766 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006767 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006768 },
6769 shimWritesFirst: true,
6770 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006771
6772 // Client-side renegotiation controls.
6773 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006774 name: "Renegotiate-Client-Forbidden-1",
6775 config: Config{
6776 MaxVersion: VersionTLS12,
6777 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006778 renegotiate: 1,
6779 shouldFail: true,
6780 expectedError: ":NO_RENEGOTIATION:",
6781 expectedLocalError: "remote error: no renegotiation",
6782 })
6783 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006784 name: "Renegotiate-Client-Once-1",
6785 config: Config{
6786 MaxVersion: VersionTLS12,
6787 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006788 renegotiate: 1,
6789 flags: []string{
6790 "-renegotiate-once",
6791 "-expect-total-renegotiations", "1",
6792 },
6793 })
6794 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006795 name: "Renegotiate-Client-Freely-1",
6796 config: Config{
6797 MaxVersion: VersionTLS12,
6798 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006799 renegotiate: 1,
6800 flags: []string{
6801 "-renegotiate-freely",
6802 "-expect-total-renegotiations", "1",
6803 },
6804 })
6805 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006806 name: "Renegotiate-Client-Once-2",
6807 config: Config{
6808 MaxVersion: VersionTLS12,
6809 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006810 renegotiate: 2,
6811 flags: []string{"-renegotiate-once"},
6812 shouldFail: true,
6813 expectedError: ":NO_RENEGOTIATION:",
6814 expectedLocalError: "remote error: no renegotiation",
6815 })
6816 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006817 name: "Renegotiate-Client-Freely-2",
6818 config: Config{
6819 MaxVersion: VersionTLS12,
6820 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006821 renegotiate: 2,
6822 flags: []string{
6823 "-renegotiate-freely",
6824 "-expect-total-renegotiations", "2",
6825 },
6826 })
Adam Langley27a0d082015-11-03 13:34:10 -08006827 testCases = append(testCases, testCase{
6828 name: "Renegotiate-Client-NoIgnore",
6829 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006830 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006831 Bugs: ProtocolBugs{
6832 SendHelloRequestBeforeEveryAppDataRecord: true,
6833 },
6834 },
6835 shouldFail: true,
6836 expectedError: ":NO_RENEGOTIATION:",
6837 })
6838 testCases = append(testCases, testCase{
6839 name: "Renegotiate-Client-Ignore",
6840 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006841 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006842 Bugs: ProtocolBugs{
6843 SendHelloRequestBeforeEveryAppDataRecord: true,
6844 },
6845 },
6846 flags: []string{
6847 "-renegotiate-ignore",
6848 "-expect-total-renegotiations", "0",
6849 },
6850 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006851
David Benjamin34941c02016-10-08 11:45:31 -04006852 // Renegotiation is not allowed at SSL 3.0.
6853 testCases = append(testCases, testCase{
6854 name: "Renegotiate-Client-SSL3",
6855 config: Config{
6856 MaxVersion: VersionSSL30,
6857 },
6858 renegotiate: 1,
6859 flags: []string{
6860 "-renegotiate-freely",
6861 "-expect-total-renegotiations", "1",
6862 },
6863 shouldFail: true,
6864 expectedError: ":NO_RENEGOTIATION:",
6865 expectedLocalError: "remote error: no renegotiation",
6866 })
6867
David Benjamina1eaba12017-01-01 23:19:22 -05006868 // Renegotiation is not allowed when there is an unfinished write.
6869 testCases = append(testCases, testCase{
6870 name: "Renegotiate-Client-UnfinishedWrite",
6871 config: Config{
6872 MaxVersion: VersionTLS12,
6873 },
David Benjaminbbba9392017-04-06 12:54:12 -04006874 renegotiate: 1,
6875 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006876 flags: []string{
6877 "-async",
6878 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006879 },
6880 shouldFail: true,
6881 expectedError: ":NO_RENEGOTIATION:",
6882 // We do not successfully send the no_renegotiation alert in
6883 // this case. https://crbug.com/boringssl/130
6884 })
6885
David Benjamin07ab5d42017-02-09 20:11:41 -05006886 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006887 testCases = append(testCases, testCase{
6888 name: "StrayHelloRequest",
6889 config: Config{
6890 MaxVersion: VersionTLS12,
6891 Bugs: ProtocolBugs{
6892 SendHelloRequestBeforeEveryHandshakeMessage: true,
6893 },
6894 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006895 shouldFail: true,
6896 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006897 })
6898 testCases = append(testCases, testCase{
6899 name: "StrayHelloRequest-Packed",
6900 config: Config{
6901 MaxVersion: VersionTLS12,
6902 Bugs: ProtocolBugs{
6903 PackHandshakeFlight: true,
6904 SendHelloRequestBeforeEveryHandshakeMessage: true,
6905 },
6906 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006907 shouldFail: true,
6908 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006909 })
6910
David Benjamin12d2c482016-07-24 10:56:51 -04006911 // Test renegotiation works if HelloRequest and server Finished come in
6912 // the same record.
6913 testCases = append(testCases, testCase{
6914 name: "Renegotiate-Client-Packed",
6915 config: Config{
6916 MaxVersion: VersionTLS12,
6917 Bugs: ProtocolBugs{
6918 PackHandshakeFlight: true,
6919 PackHelloRequestWithFinished: true,
6920 },
6921 },
6922 renegotiate: 1,
6923 flags: []string{
6924 "-renegotiate-freely",
6925 "-expect-total-renegotiations", "1",
6926 },
6927 })
6928
David Benjamin397c8e62016-07-08 14:14:36 -07006929 // Renegotiation is forbidden in TLS 1.3.
6930 testCases = append(testCases, testCase{
6931 name: "Renegotiate-Client-TLS13",
6932 config: Config{
6933 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006934 Bugs: ProtocolBugs{
6935 SendHelloRequestBeforeEveryAppDataRecord: true,
6936 },
David Benjamin397c8e62016-07-08 14:14:36 -07006937 },
David Benjamin397c8e62016-07-08 14:14:36 -07006938 flags: []string{
6939 "-renegotiate-freely",
6940 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006941 shouldFail: true,
6942 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006943 })
6944
6945 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6946 testCases = append(testCases, testCase{
6947 name: "StrayHelloRequest-TLS13",
6948 config: Config{
6949 MaxVersion: VersionTLS13,
6950 Bugs: ProtocolBugs{
6951 SendHelloRequestBeforeEveryHandshakeMessage: true,
6952 },
6953 },
6954 shouldFail: true,
6955 expectedError: ":UNEXPECTED_MESSAGE:",
6956 })
David Benjamind2610042017-01-03 10:49:28 -05006957
6958 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6959 // always reads as supporting it, regardless of whether it was
6960 // negotiated.
6961 testCases = append(testCases, testCase{
6962 name: "AlwaysReportRenegotiationInfo-TLS13",
6963 config: Config{
6964 MaxVersion: VersionTLS13,
6965 Bugs: ProtocolBugs{
6966 NoRenegotiationInfo: true,
6967 },
6968 },
6969 flags: []string{
6970 "-expect-secure-renegotiation",
6971 },
6972 })
David Benjamina58baaf2017-02-28 20:54:28 -05006973
6974 // Certificates may not change on renegotiation.
6975 testCases = append(testCases, testCase{
6976 name: "Renegotiation-CertificateChange",
6977 config: Config{
6978 MaxVersion: VersionTLS12,
6979 Certificates: []Certificate{rsaCertificate},
6980 Bugs: ProtocolBugs{
6981 RenegotiationCertificate: &rsaChainCertificate,
6982 },
6983 },
6984 renegotiate: 1,
6985 flags: []string{"-renegotiate-freely"},
6986 shouldFail: true,
6987 expectedError: ":SERVER_CERT_CHANGED:",
6988 })
6989 testCases = append(testCases, testCase{
6990 name: "Renegotiation-CertificateChange-2",
6991 config: Config{
6992 MaxVersion: VersionTLS12,
6993 Certificates: []Certificate{rsaCertificate},
6994 Bugs: ProtocolBugs{
6995 RenegotiationCertificate: &rsa1024Certificate,
6996 },
6997 },
6998 renegotiate: 1,
6999 flags: []string{"-renegotiate-freely"},
7000 shouldFail: true,
7001 expectedError: ":SERVER_CERT_CHANGED:",
7002 })
David Benjaminbbf42462017-03-14 21:27:10 -04007003
7004 // We do not negotiate ALPN after the initial handshake. This is
7005 // error-prone and only risks bugs in consumers.
7006 testCases = append(testCases, testCase{
7007 testType: clientTest,
7008 name: "Renegotiation-ForbidALPN",
7009 config: Config{
7010 MaxVersion: VersionTLS12,
7011 Bugs: ProtocolBugs{
7012 // Forcibly negotiate ALPN on both initial and
7013 // renegotiation handshakes. The test stack will
7014 // internally check the client does not offer
7015 // it.
7016 SendALPN: "foo",
7017 },
7018 },
7019 flags: []string{
7020 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7021 "-expect-alpn", "foo",
7022 "-renegotiate-freely",
7023 },
7024 renegotiate: 1,
7025 shouldFail: true,
7026 expectedError: ":UNEXPECTED_EXTENSION:",
7027 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007028}
7029
David Benjamin5e961c12014-11-07 01:48:35 -05007030func addDTLSReplayTests() {
7031 // Test that sequence number replays are detected.
7032 testCases = append(testCases, testCase{
7033 protocol: dtls,
7034 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007035 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007036 replayWrites: true,
7037 })
7038
David Benjamin8e6db492015-07-25 18:29:23 -04007039 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007040 // than the retransmit window.
7041 testCases = append(testCases, testCase{
7042 protocol: dtls,
7043 name: "DTLS-Replay-LargeGaps",
7044 config: Config{
7045 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007046 SequenceNumberMapping: func(in uint64) uint64 {
7047 return in * 127
7048 },
David Benjamin5e961c12014-11-07 01:48:35 -05007049 },
7050 },
David Benjamin8e6db492015-07-25 18:29:23 -04007051 messageCount: 200,
7052 replayWrites: true,
7053 })
7054
7055 // Test the incoming sequence number changing non-monotonically.
7056 testCases = append(testCases, testCase{
7057 protocol: dtls,
7058 name: "DTLS-Replay-NonMonotonic",
7059 config: Config{
7060 Bugs: ProtocolBugs{
7061 SequenceNumberMapping: func(in uint64) uint64 {
7062 return in ^ 31
7063 },
7064 },
7065 },
7066 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007067 replayWrites: true,
7068 })
7069}
7070
Nick Harper60edffd2016-06-21 15:19:24 -07007071var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007072 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007073 id signatureAlgorithm
7074 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007075}{
Nick Harper60edffd2016-06-21 15:19:24 -07007076 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7077 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7078 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7079 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007080 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007081 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7082 // hash function doesn't have to match the curve and so the same
7083 // signature algorithm works with P-224.
7084 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007085 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7086 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7087 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007088 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7089 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7090 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007091 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007092 // Tests for key types prior to TLS 1.2.
7093 {"RSA", 0, testCertRSA},
7094 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007095}
7096
Nick Harper60edffd2016-06-21 15:19:24 -07007097const fakeSigAlg1 signatureAlgorithm = 0x2a01
7098const fakeSigAlg2 signatureAlgorithm = 0xff01
7099
7100func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007101 // Not all ciphers involve a signature. Advertise a list which gives all
7102 // versions a signing cipher.
7103 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007104 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007105 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7106 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7107 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7108 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007109 }
David Benjamin5208fd42016-07-13 21:43:25 -04007110
David Benjaminca3d5452016-07-14 12:51:01 -04007111 var allAlgorithms []signatureAlgorithm
7112 for _, alg := range testSignatureAlgorithms {
7113 if alg.id != 0 {
7114 allAlgorithms = append(allAlgorithms, alg.id)
7115 }
7116 }
7117
Nick Harper60edffd2016-06-21 15:19:24 -07007118 // Make sure each signature algorithm works. Include some fake values in
7119 // the list and ensure they're ignored.
7120 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007121 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007122 if (ver.version < VersionTLS12) != (alg.id == 0) {
7123 continue
7124 }
7125
7126 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7127 // or remove it in C.
7128 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007129 continue
7130 }
Nick Harper60edffd2016-06-21 15:19:24 -07007131
David Benjamin3ef76972016-10-17 17:59:54 -04007132 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007133 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007134 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007135 shouldSignFail = true
7136 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007137 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007138 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007139 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7140 shouldSignFail = true
7141 shouldVerifyFail = true
7142 }
7143 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7144 // the curve has to match the hash size.
7145 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007146 shouldSignFail = true
7147 shouldVerifyFail = true
7148 }
7149
7150 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7151 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7152 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007153 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007154
7155 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007156 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007157 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007158 }
7159 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007160 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007161 }
David Benjamin000800a2014-11-14 01:43:59 -05007162
David Benjamin1fb125c2016-07-08 18:52:12 -07007163 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007164
David Benjamin7a41d372016-07-09 11:21:54 -07007165 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007166 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007167 config: Config{
7168 MaxVersion: ver.version,
7169 ClientAuth: RequireAnyClientCert,
7170 VerifySignatureAlgorithms: []signatureAlgorithm{
7171 fakeSigAlg1,
7172 alg.id,
7173 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007174 },
David Benjamin7a41d372016-07-09 11:21:54 -07007175 },
7176 flags: []string{
7177 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7178 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7179 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007180 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007181 },
David Benjamin3ef76972016-10-17 17:59:54 -04007182 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007183 expectedError: signError,
7184 expectedPeerSignatureAlgorithm: alg.id,
7185 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007186
David Benjamin7a41d372016-07-09 11:21:54 -07007187 testCases = append(testCases, testCase{
7188 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007189 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007190 config: Config{
7191 MaxVersion: ver.version,
7192 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7193 SignSignatureAlgorithms: []signatureAlgorithm{
7194 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007195 },
David Benjamin7a41d372016-07-09 11:21:54 -07007196 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007197 SkipECDSACurveCheck: shouldVerifyFail,
7198 IgnoreSignatureVersionChecks: shouldVerifyFail,
7199 // Some signature algorithms may not be advertised.
7200 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007201 },
David Benjamin7a41d372016-07-09 11:21:54 -07007202 },
7203 flags: []string{
7204 "-require-any-client-certificate",
7205 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7206 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007207 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007208 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007209 // Resume the session to assert the peer signature
7210 // algorithm is reported on both handshakes.
7211 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007212 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007213 expectedError: verifyError,
7214 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007215
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007216 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007217 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007218 testCases = append(testCases, testCase{
7219 testType: serverTest,
7220 name: "ServerAuth-Sign" + suffix,
7221 config: Config{
7222 MaxVersion: ver.version,
7223 CipherSuites: signingCiphers,
7224 VerifySignatureAlgorithms: []signatureAlgorithm{
7225 fakeSigAlg1,
7226 alg.id,
7227 fakeSigAlg2,
7228 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007229 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007230 flags: []string{
7231 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7232 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7233 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007234 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007235 },
7236 shouldFail: shouldSignFail,
7237 expectedError: signError,
7238 expectedPeerSignatureAlgorithm: alg.id,
7239 })
7240 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007241
7242 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007243 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007244 config: Config{
7245 MaxVersion: ver.version,
7246 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007247 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007248 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007249 alg.id,
7250 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007251 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007252 SkipECDSACurveCheck: shouldVerifyFail,
7253 IgnoreSignatureVersionChecks: shouldVerifyFail,
7254 // Some signature algorithms may not be advertised.
7255 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007256 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007257 },
7258 flags: []string{
7259 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7260 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007261 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007262 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007263 // Resume the session to assert the peer signature
7264 // algorithm is reported on both handshakes.
7265 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007266 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007267 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007268 })
David Benjamin5208fd42016-07-13 21:43:25 -04007269
David Benjamin3ef76972016-10-17 17:59:54 -04007270 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007271 testCases = append(testCases, testCase{
7272 testType: serverTest,
7273 name: "ClientAuth-InvalidSignature" + suffix,
7274 config: Config{
7275 MaxVersion: ver.version,
7276 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7277 SignSignatureAlgorithms: []signatureAlgorithm{
7278 alg.id,
7279 },
7280 Bugs: ProtocolBugs{
7281 InvalidSignature: true,
7282 },
7283 },
7284 flags: []string{
7285 "-require-any-client-certificate",
7286 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007287 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007288 },
7289 shouldFail: true,
7290 expectedError: ":BAD_SIGNATURE:",
7291 })
7292
7293 testCases = append(testCases, testCase{
7294 name: "ServerAuth-InvalidSignature" + suffix,
7295 config: Config{
7296 MaxVersion: ver.version,
7297 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7298 CipherSuites: signingCiphers,
7299 SignSignatureAlgorithms: []signatureAlgorithm{
7300 alg.id,
7301 },
7302 Bugs: ProtocolBugs{
7303 InvalidSignature: true,
7304 },
7305 },
David Benjamin69522112017-03-28 15:38:29 -05007306 flags: []string{
7307 "-enable-all-curves",
7308 "-enable-ed25519",
7309 },
David Benjamin5208fd42016-07-13 21:43:25 -04007310 shouldFail: true,
7311 expectedError: ":BAD_SIGNATURE:",
7312 })
7313 }
David Benjaminca3d5452016-07-14 12:51:01 -04007314
David Benjamin3ef76972016-10-17 17:59:54 -04007315 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007316 testCases = append(testCases, testCase{
7317 name: "ClientAuth-Sign-Negotiate" + suffix,
7318 config: Config{
7319 MaxVersion: ver.version,
7320 ClientAuth: RequireAnyClientCert,
7321 VerifySignatureAlgorithms: allAlgorithms,
7322 },
7323 flags: []string{
7324 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7325 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7326 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007327 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007328 "-signing-prefs", strconv.Itoa(int(alg.id)),
7329 },
7330 expectedPeerSignatureAlgorithm: alg.id,
7331 })
7332
7333 testCases = append(testCases, testCase{
7334 testType: serverTest,
7335 name: "ServerAuth-Sign-Negotiate" + suffix,
7336 config: Config{
7337 MaxVersion: ver.version,
7338 CipherSuites: signingCiphers,
7339 VerifySignatureAlgorithms: allAlgorithms,
7340 },
7341 flags: []string{
7342 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7343 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7344 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007345 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007346 "-signing-prefs", strconv.Itoa(int(alg.id)),
7347 },
7348 expectedPeerSignatureAlgorithm: alg.id,
7349 })
7350 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007351 }
David Benjamin000800a2014-11-14 01:43:59 -05007352 }
7353
Nick Harper60edffd2016-06-21 15:19:24 -07007354 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007355 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007356 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007357 config: Config{
7358 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007359 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007360 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007361 signatureECDSAWithP521AndSHA512,
7362 signatureRSAPKCS1WithSHA384,
7363 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007364 },
7365 },
7366 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007367 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7368 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007369 },
Nick Harper60edffd2016-06-21 15:19:24 -07007370 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007371 })
7372
7373 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007374 name: "ClientAuth-SignatureType-TLS13",
7375 config: Config{
7376 ClientAuth: RequireAnyClientCert,
7377 MaxVersion: VersionTLS13,
7378 VerifySignatureAlgorithms: []signatureAlgorithm{
7379 signatureECDSAWithP521AndSHA512,
7380 signatureRSAPKCS1WithSHA384,
7381 signatureRSAPSSWithSHA384,
7382 signatureECDSAWithSHA1,
7383 },
7384 },
7385 flags: []string{
7386 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7387 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7388 },
7389 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7390 })
7391
7392 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007393 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007394 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007395 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007396 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007397 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007398 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007399 signatureECDSAWithP521AndSHA512,
7400 signatureRSAPKCS1WithSHA384,
7401 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007402 },
7403 },
Nick Harper60edffd2016-06-21 15:19:24 -07007404 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007405 })
7406
Steven Valdez143e8b32016-07-11 13:19:03 -04007407 testCases = append(testCases, testCase{
7408 testType: serverTest,
7409 name: "ServerAuth-SignatureType-TLS13",
7410 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007411 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007412 VerifySignatureAlgorithms: []signatureAlgorithm{
7413 signatureECDSAWithP521AndSHA512,
7414 signatureRSAPKCS1WithSHA384,
7415 signatureRSAPSSWithSHA384,
7416 signatureECDSAWithSHA1,
7417 },
7418 },
7419 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7420 })
7421
David Benjamina95e9f32016-07-08 16:28:04 -07007422 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007423 testCases = append(testCases, testCase{
7424 testType: serverTest,
7425 name: "Verify-ClientAuth-SignatureType",
7426 config: Config{
7427 MaxVersion: VersionTLS12,
7428 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007429 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007430 signatureRSAPKCS1WithSHA256,
7431 },
7432 Bugs: ProtocolBugs{
7433 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7434 },
7435 },
7436 flags: []string{
7437 "-require-any-client-certificate",
7438 },
7439 shouldFail: true,
7440 expectedError: ":WRONG_SIGNATURE_TYPE:",
7441 })
7442
7443 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007444 testType: serverTest,
7445 name: "Verify-ClientAuth-SignatureType-TLS13",
7446 config: Config{
7447 MaxVersion: VersionTLS13,
7448 Certificates: []Certificate{rsaCertificate},
7449 SignSignatureAlgorithms: []signatureAlgorithm{
7450 signatureRSAPSSWithSHA256,
7451 },
7452 Bugs: ProtocolBugs{
7453 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7454 },
7455 },
7456 flags: []string{
7457 "-require-any-client-certificate",
7458 },
7459 shouldFail: true,
7460 expectedError: ":WRONG_SIGNATURE_TYPE:",
7461 })
7462
7463 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007464 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007465 config: Config{
7466 MaxVersion: VersionTLS12,
7467 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007468 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007469 signatureRSAPKCS1WithSHA256,
7470 },
7471 Bugs: ProtocolBugs{
7472 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7473 },
7474 },
7475 shouldFail: true,
7476 expectedError: ":WRONG_SIGNATURE_TYPE:",
7477 })
7478
Steven Valdez143e8b32016-07-11 13:19:03 -04007479 testCases = append(testCases, testCase{
7480 name: "Verify-ServerAuth-SignatureType-TLS13",
7481 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007482 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007483 SignSignatureAlgorithms: []signatureAlgorithm{
7484 signatureRSAPSSWithSHA256,
7485 },
7486 Bugs: ProtocolBugs{
7487 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7488 },
7489 },
7490 shouldFail: true,
7491 expectedError: ":WRONG_SIGNATURE_TYPE:",
7492 })
7493
David Benjamin51dd7d62016-07-08 16:07:01 -07007494 // Test that, if the list is missing, the peer falls back to SHA-1 in
7495 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007496 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007497 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007498 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007499 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007500 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007501 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007502 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007503 },
7504 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007505 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007506 },
7507 },
7508 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007509 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7510 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007511 },
7512 })
7513
7514 testCases = append(testCases, testCase{
7515 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007516 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007517 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007518 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007519 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007520 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007521 },
7522 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007523 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007524 },
7525 },
David Benjaminee32bea2016-08-17 13:36:44 -04007526 flags: []string{
7527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7529 },
7530 })
7531
7532 testCases = append(testCases, testCase{
7533 name: "ClientAuth-SHA1-Fallback-ECDSA",
7534 config: Config{
7535 MaxVersion: VersionTLS12,
7536 ClientAuth: RequireAnyClientCert,
7537 VerifySignatureAlgorithms: []signatureAlgorithm{
7538 signatureECDSAWithSHA1,
7539 },
7540 Bugs: ProtocolBugs{
7541 NoSignatureAlgorithms: true,
7542 },
7543 },
7544 flags: []string{
7545 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7546 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7547 },
7548 })
7549
7550 testCases = append(testCases, testCase{
7551 testType: serverTest,
7552 name: "ServerAuth-SHA1-Fallback-ECDSA",
7553 config: Config{
7554 MaxVersion: VersionTLS12,
7555 VerifySignatureAlgorithms: []signatureAlgorithm{
7556 signatureECDSAWithSHA1,
7557 },
7558 Bugs: ProtocolBugs{
7559 NoSignatureAlgorithms: true,
7560 },
7561 },
7562 flags: []string{
7563 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7564 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7565 },
David Benjamin000800a2014-11-14 01:43:59 -05007566 })
David Benjamin72dc7832015-03-16 17:49:43 -04007567
David Benjamin51dd7d62016-07-08 16:07:01 -07007568 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007569 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007570 config: Config{
7571 MaxVersion: VersionTLS13,
7572 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007573 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007574 signatureRSAPKCS1WithSHA1,
7575 },
7576 Bugs: ProtocolBugs{
7577 NoSignatureAlgorithms: true,
7578 },
7579 },
7580 flags: []string{
7581 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7582 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7583 },
David Benjamin48901652016-08-01 12:12:47 -04007584 shouldFail: true,
7585 // An empty CertificateRequest signature algorithm list is a
7586 // syntax error in TLS 1.3.
7587 expectedError: ":DECODE_ERROR:",
7588 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007589 })
7590
7591 testCases = append(testCases, testCase{
7592 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007593 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007594 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007595 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007596 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007597 signatureRSAPKCS1WithSHA1,
7598 },
7599 Bugs: ProtocolBugs{
7600 NoSignatureAlgorithms: true,
7601 },
7602 },
7603 shouldFail: true,
7604 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7605 })
7606
David Benjaminb62d2872016-07-18 14:55:02 +02007607 // Test that hash preferences are enforced. BoringSSL does not implement
7608 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007609 testCases = append(testCases, testCase{
7610 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007611 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007613 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007614 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007615 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007616 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007617 },
7618 Bugs: ProtocolBugs{
7619 IgnorePeerSignatureAlgorithmPreferences: true,
7620 },
7621 },
7622 flags: []string{"-require-any-client-certificate"},
7623 shouldFail: true,
7624 expectedError: ":WRONG_SIGNATURE_TYPE:",
7625 })
7626
7627 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007628 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007629 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007630 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007631 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007632 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007633 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007634 },
7635 Bugs: ProtocolBugs{
7636 IgnorePeerSignatureAlgorithmPreferences: true,
7637 },
7638 },
7639 shouldFail: true,
7640 expectedError: ":WRONG_SIGNATURE_TYPE:",
7641 })
David Benjaminb62d2872016-07-18 14:55:02 +02007642 testCases = append(testCases, testCase{
7643 testType: serverTest,
7644 name: "ClientAuth-Enforced-TLS13",
7645 config: Config{
7646 MaxVersion: VersionTLS13,
7647 Certificates: []Certificate{rsaCertificate},
7648 SignSignatureAlgorithms: []signatureAlgorithm{
7649 signatureRSAPKCS1WithMD5,
7650 },
7651 Bugs: ProtocolBugs{
7652 IgnorePeerSignatureAlgorithmPreferences: true,
7653 IgnoreSignatureVersionChecks: true,
7654 },
7655 },
7656 flags: []string{"-require-any-client-certificate"},
7657 shouldFail: true,
7658 expectedError: ":WRONG_SIGNATURE_TYPE:",
7659 })
7660
7661 testCases = append(testCases, testCase{
7662 name: "ServerAuth-Enforced-TLS13",
7663 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007664 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007665 SignSignatureAlgorithms: []signatureAlgorithm{
7666 signatureRSAPKCS1WithMD5,
7667 },
7668 Bugs: ProtocolBugs{
7669 IgnorePeerSignatureAlgorithmPreferences: true,
7670 IgnoreSignatureVersionChecks: true,
7671 },
7672 },
7673 shouldFail: true,
7674 expectedError: ":WRONG_SIGNATURE_TYPE:",
7675 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007676
7677 // Test that the agreed upon digest respects the client preferences and
7678 // the server digests.
7679 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007680 name: "NoCommonAlgorithms-Digests",
7681 config: Config{
7682 MaxVersion: VersionTLS12,
7683 ClientAuth: RequireAnyClientCert,
7684 VerifySignatureAlgorithms: []signatureAlgorithm{
7685 signatureRSAPKCS1WithSHA512,
7686 signatureRSAPKCS1WithSHA1,
7687 },
7688 },
7689 flags: []string{
7690 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7691 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7692 "-digest-prefs", "SHA256",
7693 },
7694 shouldFail: true,
7695 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7696 })
7697 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007698 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007699 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007700 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007701 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007702 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007703 signatureRSAPKCS1WithSHA512,
7704 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007705 },
7706 },
7707 flags: []string{
7708 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7709 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007710 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007711 },
David Benjaminca3d5452016-07-14 12:51:01 -04007712 shouldFail: true,
7713 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7714 })
7715 testCases = append(testCases, testCase{
7716 name: "NoCommonAlgorithms-TLS13",
7717 config: Config{
7718 MaxVersion: VersionTLS13,
7719 ClientAuth: RequireAnyClientCert,
7720 VerifySignatureAlgorithms: []signatureAlgorithm{
7721 signatureRSAPSSWithSHA512,
7722 signatureRSAPSSWithSHA384,
7723 },
7724 },
7725 flags: []string{
7726 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7727 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7728 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7729 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007730 shouldFail: true,
7731 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007732 })
7733 testCases = append(testCases, testCase{
7734 name: "Agree-Digest-SHA256",
7735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007736 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007737 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007738 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007739 signatureRSAPKCS1WithSHA1,
7740 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007741 },
7742 },
7743 flags: []string{
7744 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7745 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007746 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007747 },
Nick Harper60edffd2016-06-21 15:19:24 -07007748 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007749 })
7750 testCases = append(testCases, testCase{
7751 name: "Agree-Digest-SHA1",
7752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007753 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007754 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007755 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007756 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007757 },
7758 },
7759 flags: []string{
7760 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7761 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007762 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007763 },
Nick Harper60edffd2016-06-21 15:19:24 -07007764 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007765 })
7766 testCases = append(testCases, testCase{
7767 name: "Agree-Digest-Default",
7768 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007769 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007770 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007771 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007772 signatureRSAPKCS1WithSHA256,
7773 signatureECDSAWithP256AndSHA256,
7774 signatureRSAPKCS1WithSHA1,
7775 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007776 },
7777 },
7778 flags: []string{
7779 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7780 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7781 },
Nick Harper60edffd2016-06-21 15:19:24 -07007782 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007783 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007784
David Benjaminca3d5452016-07-14 12:51:01 -04007785 // Test that the signing preference list may include extra algorithms
7786 // without negotiation problems.
7787 testCases = append(testCases, testCase{
7788 testType: serverTest,
7789 name: "FilterExtraAlgorithms",
7790 config: Config{
7791 MaxVersion: VersionTLS12,
7792 VerifySignatureAlgorithms: []signatureAlgorithm{
7793 signatureRSAPKCS1WithSHA256,
7794 },
7795 },
7796 flags: []string{
7797 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7798 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7799 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7800 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7801 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7802 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7803 },
7804 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7805 })
7806
David Benjamin4c3ddf72016-06-29 18:13:53 -04007807 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7808 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007809 testCases = append(testCases, testCase{
7810 name: "CheckLeafCurve",
7811 config: Config{
7812 MaxVersion: VersionTLS12,
7813 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007814 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007815 },
7816 flags: []string{"-p384-only"},
7817 shouldFail: true,
7818 expectedError: ":BAD_ECC_CERT:",
7819 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007820
7821 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7822 testCases = append(testCases, testCase{
7823 name: "CheckLeafCurve-TLS13",
7824 config: Config{
7825 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007826 Certificates: []Certificate{ecdsaP256Certificate},
7827 },
7828 flags: []string{"-p384-only"},
7829 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007830
7831 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7832 testCases = append(testCases, testCase{
7833 name: "ECDSACurveMismatch-Verify-TLS12",
7834 config: Config{
7835 MaxVersion: VersionTLS12,
7836 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7837 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007838 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007839 signatureECDSAWithP384AndSHA384,
7840 },
7841 },
7842 })
7843
7844 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7845 testCases = append(testCases, testCase{
7846 name: "ECDSACurveMismatch-Verify-TLS13",
7847 config: Config{
7848 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007849 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007850 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007851 signatureECDSAWithP384AndSHA384,
7852 },
7853 Bugs: ProtocolBugs{
7854 SkipECDSACurveCheck: true,
7855 },
7856 },
7857 shouldFail: true,
7858 expectedError: ":WRONG_SIGNATURE_TYPE:",
7859 })
7860
7861 // Signature algorithm selection in TLS 1.3 should take the curve into
7862 // account.
7863 testCases = append(testCases, testCase{
7864 testType: serverTest,
7865 name: "ECDSACurveMismatch-Sign-TLS13",
7866 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007867 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007868 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007869 signatureECDSAWithP384AndSHA384,
7870 signatureECDSAWithP256AndSHA256,
7871 },
7872 },
7873 flags: []string{
7874 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7875 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7876 },
7877 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7878 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007879
7880 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7881 // server does not attempt to sign in that case.
7882 testCases = append(testCases, testCase{
7883 testType: serverTest,
7884 name: "RSA-PSS-Large",
7885 config: Config{
7886 MaxVersion: VersionTLS13,
7887 VerifySignatureAlgorithms: []signatureAlgorithm{
7888 signatureRSAPSSWithSHA512,
7889 },
7890 },
7891 flags: []string{
7892 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7893 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7894 },
7895 shouldFail: true,
7896 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7897 })
David Benjamin57e929f2016-08-30 00:30:38 -04007898
7899 // Test that RSA-PSS is enabled by default for TLS 1.2.
7900 testCases = append(testCases, testCase{
7901 testType: clientTest,
7902 name: "RSA-PSS-Default-Verify",
7903 config: Config{
7904 MaxVersion: VersionTLS12,
7905 SignSignatureAlgorithms: []signatureAlgorithm{
7906 signatureRSAPSSWithSHA256,
7907 },
7908 },
7909 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7910 })
7911
7912 testCases = append(testCases, testCase{
7913 testType: serverTest,
7914 name: "RSA-PSS-Default-Sign",
7915 config: Config{
7916 MaxVersion: VersionTLS12,
7917 VerifySignatureAlgorithms: []signatureAlgorithm{
7918 signatureRSAPSSWithSHA256,
7919 },
7920 },
7921 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7922 })
David Benjamin69522112017-03-28 15:38:29 -05007923
7924 // TLS 1.1 and below has no way to advertise support for or negotiate
7925 // Ed25519's signature algorithm.
7926 testCases = append(testCases, testCase{
7927 testType: clientTest,
7928 name: "NoEd25519-TLS11-ServerAuth-Verify",
7929 config: Config{
7930 MaxVersion: VersionTLS11,
7931 Certificates: []Certificate{ed25519Certificate},
7932 Bugs: ProtocolBugs{
7933 // Sign with Ed25519 even though it is TLS 1.1.
7934 UseLegacySigningAlgorithm: signatureEd25519,
7935 },
7936 },
7937 flags: []string{"-enable-ed25519"},
7938 shouldFail: true,
7939 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7940 })
7941 testCases = append(testCases, testCase{
7942 testType: serverTest,
7943 name: "NoEd25519-TLS11-ServerAuth-Sign",
7944 config: Config{
7945 MaxVersion: VersionTLS11,
7946 },
7947 flags: []string{
7948 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7949 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7950 },
7951 shouldFail: true,
7952 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7953 })
7954 testCases = append(testCases, testCase{
7955 testType: serverTest,
7956 name: "NoEd25519-TLS11-ClientAuth-Verify",
7957 config: Config{
7958 MaxVersion: VersionTLS11,
7959 Certificates: []Certificate{ed25519Certificate},
7960 Bugs: ProtocolBugs{
7961 // Sign with Ed25519 even though it is TLS 1.1.
7962 UseLegacySigningAlgorithm: signatureEd25519,
7963 },
7964 },
7965 flags: []string{
7966 "-enable-ed25519",
7967 "-require-any-client-certificate",
7968 },
7969 shouldFail: true,
7970 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7971 })
7972 testCases = append(testCases, testCase{
7973 testType: clientTest,
7974 name: "NoEd25519-TLS11-ClientAuth-Sign",
7975 config: Config{
7976 MaxVersion: VersionTLS11,
7977 ClientAuth: RequireAnyClientCert,
7978 },
7979 flags: []string{
7980 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7981 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7982 },
7983 shouldFail: true,
7984 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7985 })
7986
7987 // Test Ed25519 is not advertised by default.
7988 testCases = append(testCases, testCase{
7989 testType: clientTest,
7990 name: "Ed25519DefaultDisable-NoAdvertise",
7991 config: Config{
7992 Certificates: []Certificate{ed25519Certificate},
7993 },
7994 shouldFail: true,
7995 expectedLocalError: "tls: no common signature algorithms",
7996 })
7997
7998 // Test Ed25519, when disabled, is not accepted if the peer ignores our
7999 // preferences.
8000 testCases = append(testCases, testCase{
8001 testType: clientTest,
8002 name: "Ed25519DefaultDisable-NoAccept",
8003 config: Config{
8004 Certificates: []Certificate{ed25519Certificate},
8005 Bugs: ProtocolBugs{
8006 IgnorePeerSignatureAlgorithmPreferences: true,
8007 },
8008 },
8009 shouldFail: true,
8010 expectedLocalError: "remote error: illegal parameter",
8011 expectedError: ":WRONG_SIGNATURE_TYPE:",
8012 })
David Benjamin71c21b42017-04-14 17:05:40 -04008013
8014 // Test that configuring verify preferences changes what the client
8015 // advertises.
8016 testCases = append(testCases, testCase{
8017 name: "VerifyPreferences-Advertised",
8018 config: Config{
8019 Certificates: []Certificate{rsaCertificate},
8020 SignSignatureAlgorithms: []signatureAlgorithm{
8021 signatureRSAPSSWithSHA256,
8022 signatureRSAPSSWithSHA384,
8023 signatureRSAPSSWithSHA512,
8024 },
8025 },
8026 flags: []string{
8027 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8028 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8029 },
8030 })
8031
8032 // Test that the client advertises a set which the runner can find
8033 // nothing in common with.
8034 testCases = append(testCases, testCase{
8035 name: "VerifyPreferences-NoCommonAlgorithms",
8036 config: Config{
8037 Certificates: []Certificate{rsaCertificate},
8038 SignSignatureAlgorithms: []signatureAlgorithm{
8039 signatureRSAPSSWithSHA256,
8040 signatureRSAPSSWithSHA512,
8041 },
8042 },
8043 flags: []string{
8044 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8045 },
8046 shouldFail: true,
8047 expectedLocalError: "tls: no common signature algorithms",
8048 })
8049
8050 // Test that the client enforces its preferences when configured.
8051 testCases = append(testCases, testCase{
8052 name: "VerifyPreferences-Enforced",
8053 config: Config{
8054 Certificates: []Certificate{rsaCertificate},
8055 SignSignatureAlgorithms: []signatureAlgorithm{
8056 signatureRSAPSSWithSHA256,
8057 signatureRSAPSSWithSHA512,
8058 },
8059 Bugs: ProtocolBugs{
8060 IgnorePeerSignatureAlgorithmPreferences: true,
8061 },
8062 },
8063 flags: []string{
8064 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8065 },
8066 shouldFail: true,
8067 expectedLocalError: "remote error: illegal parameter",
8068 expectedError: ":WRONG_SIGNATURE_TYPE:",
8069 })
8070
8071 // Test that explicitly configuring Ed25519 is as good as changing the
8072 // boolean toggle.
8073 testCases = append(testCases, testCase{
8074 name: "VerifyPreferences-Ed25519",
8075 config: Config{
8076 Certificates: []Certificate{ed25519Certificate},
8077 },
8078 flags: []string{
8079 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8080 },
8081 })
David Benjamin000800a2014-11-14 01:43:59 -05008082}
8083
David Benjamin83f90402015-01-27 01:09:43 -05008084// timeouts is the retransmit schedule for BoringSSL. It doubles and
8085// caps at 60 seconds. On the 13th timeout, it gives up.
8086var timeouts = []time.Duration{
8087 1 * time.Second,
8088 2 * time.Second,
8089 4 * time.Second,
8090 8 * time.Second,
8091 16 * time.Second,
8092 32 * time.Second,
8093 60 * time.Second,
8094 60 * time.Second,
8095 60 * time.Second,
8096 60 * time.Second,
8097 60 * time.Second,
8098 60 * time.Second,
8099 60 * time.Second,
8100}
8101
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008102// shortTimeouts is an alternate set of timeouts which would occur if the
8103// initial timeout duration was set to 250ms.
8104var shortTimeouts = []time.Duration{
8105 250 * time.Millisecond,
8106 500 * time.Millisecond,
8107 1 * time.Second,
8108 2 * time.Second,
8109 4 * time.Second,
8110 8 * time.Second,
8111 16 * time.Second,
8112 32 * time.Second,
8113 60 * time.Second,
8114 60 * time.Second,
8115 60 * time.Second,
8116 60 * time.Second,
8117 60 * time.Second,
8118}
8119
David Benjamin83f90402015-01-27 01:09:43 -05008120func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008121 // These tests work by coordinating some behavior on both the shim and
8122 // the runner.
8123 //
8124 // TimeoutSchedule configures the runner to send a series of timeout
8125 // opcodes to the shim (see packetAdaptor) immediately before reading
8126 // each peer handshake flight N. The timeout opcode both simulates a
8127 // timeout in the shim and acts as a synchronization point to help the
8128 // runner bracket each handshake flight.
8129 //
8130 // We assume the shim does not read from the channel eagerly. It must
8131 // first wait until it has sent flight N and is ready to receive
8132 // handshake flight N+1. At this point, it will process the timeout
8133 // opcode. It must then immediately respond with a timeout ACK and act
8134 // as if the shim was idle for the specified amount of time.
8135 //
8136 // The runner then drops all packets received before the ACK and
8137 // continues waiting for flight N. This ordering results in one attempt
8138 // at sending flight N to be dropped. For the test to complete, the
8139 // shim must send flight N again, testing that the shim implements DTLS
8140 // retransmit on a timeout.
8141
Steven Valdez143e8b32016-07-11 13:19:03 -04008142 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008143 // likely be more epochs to cross and the final message's retransmit may
8144 // be more complex.
8145
David Benjamin11c82892017-02-23 20:40:31 -05008146 // Test that this is indeed the timeout schedule. Stress all
8147 // four patterns of handshake.
8148 for i := 1; i < len(timeouts); i++ {
8149 number := strconv.Itoa(i)
8150 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008151 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008152 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008154 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008155 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008156 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008157 },
8158 },
8159 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008160 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008161 })
David Benjamin11c82892017-02-23 20:40:31 -05008162 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008163 protocol: dtls,
8164 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008165 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008167 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008168 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008169 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008170 },
8171 },
8172 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008173 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008174 })
8175 }
David Benjamin11c82892017-02-23 20:40:31 -05008176
8177 // Test that exceeding the timeout schedule hits a read
8178 // timeout.
8179 testCases = append(testCases, testCase{
8180 protocol: dtls,
8181 name: "DTLS-Retransmit-Timeout",
8182 config: Config{
8183 MaxVersion: VersionTLS12,
8184 Bugs: ProtocolBugs{
8185 TimeoutSchedule: timeouts,
8186 },
8187 },
8188 resumeSession: true,
8189 flags: []string{"-async"},
8190 shouldFail: true,
8191 expectedError: ":READ_TIMEOUT_EXPIRED:",
8192 })
8193
8194 // Test that timeout handling has a fudge factor, due to API
8195 // problems.
8196 testCases = append(testCases, testCase{
8197 protocol: dtls,
8198 name: "DTLS-Retransmit-Fudge",
8199 config: Config{
8200 MaxVersion: VersionTLS12,
8201 Bugs: ProtocolBugs{
8202 TimeoutSchedule: []time.Duration{
8203 timeouts[0] - 10*time.Millisecond,
8204 },
8205 },
8206 },
8207 resumeSession: true,
8208 flags: []string{"-async"},
8209 })
8210
8211 // Test that the final Finished retransmitting isn't
8212 // duplicated if the peer badly fragments everything.
8213 testCases = append(testCases, testCase{
8214 testType: serverTest,
8215 protocol: dtls,
8216 name: "DTLS-Retransmit-Fragmented",
8217 config: Config{
8218 MaxVersion: VersionTLS12,
8219 Bugs: ProtocolBugs{
8220 TimeoutSchedule: []time.Duration{timeouts[0]},
8221 MaxHandshakeRecordLength: 2,
8222 },
8223 },
8224 flags: []string{"-async"},
8225 })
8226
8227 // Test the timeout schedule when a shorter initial timeout duration is set.
8228 testCases = append(testCases, testCase{
8229 protocol: dtls,
8230 name: "DTLS-Retransmit-Short-Client",
8231 config: Config{
8232 MaxVersion: VersionTLS12,
8233 Bugs: ProtocolBugs{
8234 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8235 },
8236 },
8237 resumeSession: true,
8238 flags: []string{
8239 "-async",
8240 "-initial-timeout-duration-ms", "250",
8241 },
8242 })
8243 testCases = append(testCases, testCase{
8244 protocol: dtls,
8245 testType: serverTest,
8246 name: "DTLS-Retransmit-Short-Server",
8247 config: Config{
8248 MaxVersion: VersionTLS12,
8249 Bugs: ProtocolBugs{
8250 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8251 },
8252 },
8253 resumeSession: true,
8254 flags: []string{
8255 "-async",
8256 "-initial-timeout-duration-ms", "250",
8257 },
8258 })
David Benjamin83f90402015-01-27 01:09:43 -05008259}
8260
David Benjaminc565ebb2015-04-03 04:06:36 -04008261func addExportKeyingMaterialTests() {
8262 for _, vers := range tlsVersions {
8263 if vers.version == VersionSSL30 {
8264 continue
8265 }
8266 testCases = append(testCases, testCase{
8267 name: "ExportKeyingMaterial-" + vers.name,
8268 config: Config{
8269 MaxVersion: vers.version,
8270 },
8271 exportKeyingMaterial: 1024,
8272 exportLabel: "label",
8273 exportContext: "context",
8274 useExportContext: true,
8275 })
8276 testCases = append(testCases, testCase{
8277 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8278 config: Config{
8279 MaxVersion: vers.version,
8280 },
8281 exportKeyingMaterial: 1024,
8282 })
8283 testCases = append(testCases, testCase{
8284 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8285 config: Config{
8286 MaxVersion: vers.version,
8287 },
8288 exportKeyingMaterial: 1024,
8289 useExportContext: true,
8290 })
8291 testCases = append(testCases, testCase{
8292 name: "ExportKeyingMaterial-Small-" + vers.name,
8293 config: Config{
8294 MaxVersion: vers.version,
8295 },
8296 exportKeyingMaterial: 1,
8297 exportLabel: "label",
8298 exportContext: "context",
8299 useExportContext: true,
8300 })
8301 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008302
David Benjaminc565ebb2015-04-03 04:06:36 -04008303 testCases = append(testCases, testCase{
8304 name: "ExportKeyingMaterial-SSL3",
8305 config: Config{
8306 MaxVersion: VersionSSL30,
8307 },
8308 exportKeyingMaterial: 1024,
8309 exportLabel: "label",
8310 exportContext: "context",
8311 useExportContext: true,
8312 shouldFail: true,
8313 expectedError: "failed to export keying material",
8314 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008315
8316 // Exporters work during a False Start.
8317 testCases = append(testCases, testCase{
8318 name: "ExportKeyingMaterial-FalseStart",
8319 config: Config{
8320 MaxVersion: VersionTLS12,
8321 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8322 NextProtos: []string{"foo"},
8323 Bugs: ProtocolBugs{
8324 ExpectFalseStart: true,
8325 },
8326 },
8327 flags: []string{
8328 "-false-start",
8329 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008330 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008331 },
8332 shimWritesFirst: true,
8333 exportKeyingMaterial: 1024,
8334 exportLabel: "label",
8335 exportContext: "context",
8336 useExportContext: true,
8337 })
8338
8339 // Exporters do not work in the middle of a renegotiation. Test this by
8340 // triggering the exporter after every SSL_read call and configuring the
8341 // shim to run asynchronously.
8342 testCases = append(testCases, testCase{
8343 name: "ExportKeyingMaterial-Renegotiate",
8344 config: Config{
8345 MaxVersion: VersionTLS12,
8346 },
8347 renegotiate: 1,
8348 flags: []string{
8349 "-async",
8350 "-use-exporter-between-reads",
8351 "-renegotiate-freely",
8352 "-expect-total-renegotiations", "1",
8353 },
8354 shouldFail: true,
8355 expectedError: "failed to export keying material",
8356 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008357}
8358
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008359func addTLSUniqueTests() {
8360 for _, isClient := range []bool{false, true} {
8361 for _, isResumption := range []bool{false, true} {
8362 for _, hasEMS := range []bool{false, true} {
8363 var suffix string
8364 if isResumption {
8365 suffix = "Resume-"
8366 } else {
8367 suffix = "Full-"
8368 }
8369
8370 if hasEMS {
8371 suffix += "EMS-"
8372 } else {
8373 suffix += "NoEMS-"
8374 }
8375
8376 if isClient {
8377 suffix += "Client"
8378 } else {
8379 suffix += "Server"
8380 }
8381
8382 test := testCase{
8383 name: "TLSUnique-" + suffix,
8384 testTLSUnique: true,
8385 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008386 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008387 Bugs: ProtocolBugs{
8388 NoExtendedMasterSecret: !hasEMS,
8389 },
8390 },
8391 }
8392
8393 if isResumption {
8394 test.resumeSession = true
8395 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008396 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008397 Bugs: ProtocolBugs{
8398 NoExtendedMasterSecret: !hasEMS,
8399 },
8400 }
8401 }
8402
8403 if isResumption && !hasEMS {
8404 test.shouldFail = true
8405 test.expectedError = "failed to get tls-unique"
8406 }
8407
8408 testCases = append(testCases, test)
8409 }
8410 }
8411 }
8412}
8413
Adam Langley09505632015-07-30 18:10:13 -07008414func addCustomExtensionTests() {
8415 expectedContents := "custom extension"
8416 emptyString := ""
8417
8418 for _, isClient := range []bool{false, true} {
8419 suffix := "Server"
8420 flag := "-enable-server-custom-extension"
8421 testType := serverTest
8422 if isClient {
8423 suffix = "Client"
8424 flag = "-enable-client-custom-extension"
8425 testType = clientTest
8426 }
8427
8428 testCases = append(testCases, testCase{
8429 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008430 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008432 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008433 Bugs: ProtocolBugs{
8434 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008435 ExpectedCustomExtension: &expectedContents,
8436 },
8437 },
8438 flags: []string{flag},
8439 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008440 testCases = append(testCases, testCase{
8441 testType: testType,
8442 name: "CustomExtensions-" + suffix + "-TLS13",
8443 config: Config{
8444 MaxVersion: VersionTLS13,
8445 Bugs: ProtocolBugs{
8446 CustomExtension: expectedContents,
8447 ExpectedCustomExtension: &expectedContents,
8448 },
8449 },
8450 flags: []string{flag},
8451 })
Adam Langley09505632015-07-30 18:10:13 -07008452
Steven Valdez2a070722017-03-25 20:54:16 -05008453 // 0-RTT is not currently supported with Custom Extensions.
8454 testCases = append(testCases, testCase{
8455 testType: testType,
8456 name: "CustomExtensions-" + suffix + "-EarlyData",
8457 config: Config{
8458 MaxVersion: VersionTLS13,
8459 Bugs: ProtocolBugs{
8460 CustomExtension: expectedContents,
8461 ExpectedCustomExtension: &expectedContents,
8462 },
8463 },
8464 shouldFail: true,
8465 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8466 flags: []string{flag, "-enable-early-data"},
8467 })
8468
Adam Langley09505632015-07-30 18:10:13 -07008469 // If the parse callback fails, the handshake should also fail.
8470 testCases = append(testCases, testCase{
8471 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008472 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008474 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008475 Bugs: ProtocolBugs{
8476 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008477 ExpectedCustomExtension: &expectedContents,
8478 },
8479 },
David Benjamin399e7c92015-07-30 23:01:27 -04008480 flags: []string{flag},
8481 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008482 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8483 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008484 testCases = append(testCases, testCase{
8485 testType: testType,
8486 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8487 config: Config{
8488 MaxVersion: VersionTLS13,
8489 Bugs: ProtocolBugs{
8490 CustomExtension: expectedContents + "foo",
8491 ExpectedCustomExtension: &expectedContents,
8492 },
8493 },
8494 flags: []string{flag},
8495 shouldFail: true,
8496 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8497 })
Adam Langley09505632015-07-30 18:10:13 -07008498
8499 // If the add callback fails, the handshake should also fail.
8500 testCases = append(testCases, testCase{
8501 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008502 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008504 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008505 Bugs: ProtocolBugs{
8506 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008507 ExpectedCustomExtension: &expectedContents,
8508 },
8509 },
David Benjamin399e7c92015-07-30 23:01:27 -04008510 flags: []string{flag, "-custom-extension-fail-add"},
8511 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008512 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8513 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008514 testCases = append(testCases, testCase{
8515 testType: testType,
8516 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8517 config: Config{
8518 MaxVersion: VersionTLS13,
8519 Bugs: ProtocolBugs{
8520 CustomExtension: expectedContents,
8521 ExpectedCustomExtension: &expectedContents,
8522 },
8523 },
8524 flags: []string{flag, "-custom-extension-fail-add"},
8525 shouldFail: true,
8526 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8527 })
Adam Langley09505632015-07-30 18:10:13 -07008528
8529 // If the add callback returns zero, no extension should be
8530 // added.
8531 skipCustomExtension := expectedContents
8532 if isClient {
8533 // For the case where the client skips sending the
8534 // custom extension, the server must not “echo” it.
8535 skipCustomExtension = ""
8536 }
8537 testCases = append(testCases, testCase{
8538 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008539 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008540 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008541 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008542 Bugs: ProtocolBugs{
8543 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008544 ExpectedCustomExtension: &emptyString,
8545 },
8546 },
8547 flags: []string{flag, "-custom-extension-skip"},
8548 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008549 testCases = append(testCases, testCase{
8550 testType: testType,
8551 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8552 config: Config{
8553 MaxVersion: VersionTLS13,
8554 Bugs: ProtocolBugs{
8555 CustomExtension: skipCustomExtension,
8556 ExpectedCustomExtension: &emptyString,
8557 },
8558 },
8559 flags: []string{flag, "-custom-extension-skip"},
8560 })
Adam Langley09505632015-07-30 18:10:13 -07008561 }
8562
8563 // The custom extension add callback should not be called if the client
8564 // doesn't send the extension.
8565 testCases = append(testCases, testCase{
8566 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008567 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008569 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008570 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008571 ExpectedCustomExtension: &emptyString,
8572 },
8573 },
8574 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8575 })
Adam Langley2deb9842015-08-07 11:15:37 -07008576
Steven Valdez143e8b32016-07-11 13:19:03 -04008577 testCases = append(testCases, testCase{
8578 testType: serverTest,
8579 name: "CustomExtensions-NotCalled-Server-TLS13",
8580 config: Config{
8581 MaxVersion: VersionTLS13,
8582 Bugs: ProtocolBugs{
8583 ExpectedCustomExtension: &emptyString,
8584 },
8585 },
8586 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8587 })
8588
Adam Langley2deb9842015-08-07 11:15:37 -07008589 // Test an unknown extension from the server.
8590 testCases = append(testCases, testCase{
8591 testType: clientTest,
8592 name: "UnknownExtension-Client",
8593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008594 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008595 Bugs: ProtocolBugs{
8596 CustomExtension: expectedContents,
8597 },
8598 },
David Benjamin0c40a962016-08-01 12:05:50 -04008599 shouldFail: true,
8600 expectedError: ":UNEXPECTED_EXTENSION:",
8601 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008602 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008603 testCases = append(testCases, testCase{
8604 testType: clientTest,
8605 name: "UnknownExtension-Client-TLS13",
8606 config: Config{
8607 MaxVersion: VersionTLS13,
8608 Bugs: ProtocolBugs{
8609 CustomExtension: expectedContents,
8610 },
8611 },
David Benjamin0c40a962016-08-01 12:05:50 -04008612 shouldFail: true,
8613 expectedError: ":UNEXPECTED_EXTENSION:",
8614 expectedLocalError: "remote error: unsupported extension",
8615 })
David Benjamin490469f2016-10-05 22:44:38 -04008616 testCases = append(testCases, testCase{
8617 testType: clientTest,
8618 name: "UnknownUnencryptedExtension-Client-TLS13",
8619 config: Config{
8620 MaxVersion: VersionTLS13,
8621 Bugs: ProtocolBugs{
8622 CustomUnencryptedExtension: expectedContents,
8623 },
8624 },
8625 shouldFail: true,
8626 expectedError: ":UNEXPECTED_EXTENSION:",
8627 // The shim must send an alert, but alerts at this point do not
8628 // get successfully decrypted by the runner.
8629 expectedLocalError: "local error: bad record MAC",
8630 })
8631 testCases = append(testCases, testCase{
8632 testType: clientTest,
8633 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8634 config: Config{
8635 MaxVersion: VersionTLS13,
8636 Bugs: ProtocolBugs{
8637 SendUnencryptedALPN: "foo",
8638 },
8639 },
8640 flags: []string{
8641 "-advertise-alpn", "\x03foo\x03bar",
8642 },
8643 shouldFail: true,
8644 expectedError: ":UNEXPECTED_EXTENSION:",
8645 // The shim must send an alert, but alerts at this point do not
8646 // get successfully decrypted by the runner.
8647 expectedLocalError: "local error: bad record MAC",
8648 })
David Benjamin0c40a962016-08-01 12:05:50 -04008649
8650 // Test a known but unoffered extension from the server.
8651 testCases = append(testCases, testCase{
8652 testType: clientTest,
8653 name: "UnofferedExtension-Client",
8654 config: Config{
8655 MaxVersion: VersionTLS12,
8656 Bugs: ProtocolBugs{
8657 SendALPN: "alpn",
8658 },
8659 },
8660 shouldFail: true,
8661 expectedError: ":UNEXPECTED_EXTENSION:",
8662 expectedLocalError: "remote error: unsupported extension",
8663 })
8664 testCases = append(testCases, testCase{
8665 testType: clientTest,
8666 name: "UnofferedExtension-Client-TLS13",
8667 config: Config{
8668 MaxVersion: VersionTLS13,
8669 Bugs: ProtocolBugs{
8670 SendALPN: "alpn",
8671 },
8672 },
8673 shouldFail: true,
8674 expectedError: ":UNEXPECTED_EXTENSION:",
8675 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008676 })
Adam Langley09505632015-07-30 18:10:13 -07008677}
8678
David Benjaminb36a3952015-12-01 18:53:13 -05008679func addRSAClientKeyExchangeTests() {
8680 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8681 testCases = append(testCases, testCase{
8682 testType: serverTest,
8683 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8684 config: Config{
8685 // Ensure the ClientHello version and final
8686 // version are different, to detect if the
8687 // server uses the wrong one.
8688 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008689 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008690 Bugs: ProtocolBugs{
8691 BadRSAClientKeyExchange: bad,
8692 },
8693 },
8694 shouldFail: true,
8695 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8696 })
8697 }
David Benjamine63d9d72016-09-19 18:27:34 -04008698
8699 // The server must compare whatever was in ClientHello.version for the
8700 // RSA premaster.
8701 testCases = append(testCases, testCase{
8702 testType: serverTest,
8703 name: "SendClientVersion-RSA",
8704 config: Config{
8705 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8706 Bugs: ProtocolBugs{
8707 SendClientVersion: 0x1234,
8708 },
8709 },
8710 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8711 })
David Benjaminb36a3952015-12-01 18:53:13 -05008712}
8713
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008714var testCurves = []struct {
8715 name string
8716 id CurveID
8717}{
Adam Langley764ab982017-03-10 18:01:30 -08008718 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008719 {"P-256", CurveP256},
8720 {"P-384", CurveP384},
8721 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008722 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008723}
8724
Steven Valdez5440fe02016-07-18 12:40:30 -04008725const bogusCurve = 0x1234
8726
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008727func addCurveTests() {
8728 for _, curve := range testCurves {
8729 testCases = append(testCases, testCase{
8730 name: "CurveTest-Client-" + curve.name,
8731 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008732 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008733 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8734 CurvePreferences: []CurveID{curve.id},
8735 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008736 flags: []string{
8737 "-enable-all-curves",
8738 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8739 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008740 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008741 })
8742 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008743 name: "CurveTest-Client-" + curve.name + "-TLS13",
8744 config: Config{
8745 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008746 CurvePreferences: []CurveID{curve.id},
8747 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008748 flags: []string{
8749 "-enable-all-curves",
8750 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8751 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008752 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008753 })
8754 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008755 testType: serverTest,
8756 name: "CurveTest-Server-" + curve.name,
8757 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008758 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008759 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8760 CurvePreferences: []CurveID{curve.id},
8761 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008762 flags: []string{
8763 "-enable-all-curves",
8764 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8765 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008766 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008767 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008768 testCases = append(testCases, testCase{
8769 testType: serverTest,
8770 name: "CurveTest-Server-" + curve.name + "-TLS13",
8771 config: Config{
8772 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008773 CurvePreferences: []CurveID{curve.id},
8774 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008775 flags: []string{
8776 "-enable-all-curves",
8777 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8778 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008779 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008780 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008781 }
David Benjamin241ae832016-01-15 03:04:54 -05008782
8783 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008784 testCases = append(testCases, testCase{
8785 testType: serverTest,
8786 name: "UnknownCurve",
8787 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008788 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8790 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8791 },
8792 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008793
Steven Valdez803c77a2016-09-06 14:13:43 -04008794 // The server must be tolerant to bogus curves.
8795 testCases = append(testCases, testCase{
8796 testType: serverTest,
8797 name: "UnknownCurve-TLS13",
8798 config: Config{
8799 MaxVersion: VersionTLS13,
8800 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8801 },
8802 })
8803
David Benjamin4c3ddf72016-06-29 18:13:53 -04008804 // The server must not consider ECDHE ciphers when there are no
8805 // supported curves.
8806 testCases = append(testCases, testCase{
8807 testType: serverTest,
8808 name: "NoSupportedCurves",
8809 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008810 MaxVersion: VersionTLS12,
8811 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8812 Bugs: ProtocolBugs{
8813 NoSupportedCurves: true,
8814 },
8815 },
8816 shouldFail: true,
8817 expectedError: ":NO_SHARED_CIPHER:",
8818 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008819 testCases = append(testCases, testCase{
8820 testType: serverTest,
8821 name: "NoSupportedCurves-TLS13",
8822 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008823 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008824 Bugs: ProtocolBugs{
8825 NoSupportedCurves: true,
8826 },
8827 },
8828 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008829 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008830 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008831
8832 // The server must fall back to another cipher when there are no
8833 // supported curves.
8834 testCases = append(testCases, testCase{
8835 testType: serverTest,
8836 name: "NoCommonCurves",
8837 config: Config{
8838 MaxVersion: VersionTLS12,
8839 CipherSuites: []uint16{
8840 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008841 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008842 },
8843 CurvePreferences: []CurveID{CurveP224},
8844 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008845 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008846 })
8847
8848 // The client must reject bogus curves and disabled curves.
8849 testCases = append(testCases, testCase{
8850 name: "BadECDHECurve",
8851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008852 MaxVersion: VersionTLS12,
8853 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8854 Bugs: ProtocolBugs{
8855 SendCurve: bogusCurve,
8856 },
8857 },
8858 shouldFail: true,
8859 expectedError: ":WRONG_CURVE:",
8860 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008861 testCases = append(testCases, testCase{
8862 name: "BadECDHECurve-TLS13",
8863 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008864 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008865 Bugs: ProtocolBugs{
8866 SendCurve: bogusCurve,
8867 },
8868 },
8869 shouldFail: true,
8870 expectedError: ":WRONG_CURVE:",
8871 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008872
8873 testCases = append(testCases, testCase{
8874 name: "UnsupportedCurve",
8875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008876 MaxVersion: VersionTLS12,
8877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8878 CurvePreferences: []CurveID{CurveP256},
8879 Bugs: ProtocolBugs{
8880 IgnorePeerCurvePreferences: true,
8881 },
8882 },
8883 flags: []string{"-p384-only"},
8884 shouldFail: true,
8885 expectedError: ":WRONG_CURVE:",
8886 })
8887
David Benjamin4f921572016-07-17 14:20:10 +02008888 testCases = append(testCases, testCase{
8889 // TODO(davidben): Add a TLS 1.3 version where
8890 // HelloRetryRequest requests an unsupported curve.
8891 name: "UnsupportedCurve-ServerHello-TLS13",
8892 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008893 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008894 CurvePreferences: []CurveID{CurveP384},
8895 Bugs: ProtocolBugs{
8896 SendCurve: CurveP256,
8897 },
8898 },
8899 flags: []string{"-p384-only"},
8900 shouldFail: true,
8901 expectedError: ":WRONG_CURVE:",
8902 })
8903
David Benjamin4c3ddf72016-06-29 18:13:53 -04008904 // Test invalid curve points.
8905 testCases = append(testCases, testCase{
8906 name: "InvalidECDHPoint-Client",
8907 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008908 MaxVersion: VersionTLS12,
8909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8910 CurvePreferences: []CurveID{CurveP256},
8911 Bugs: ProtocolBugs{
8912 InvalidECDHPoint: true,
8913 },
8914 },
8915 shouldFail: true,
8916 expectedError: ":INVALID_ENCODING:",
8917 })
8918 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008919 name: "InvalidECDHPoint-Client-TLS13",
8920 config: Config{
8921 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008922 CurvePreferences: []CurveID{CurveP256},
8923 Bugs: ProtocolBugs{
8924 InvalidECDHPoint: true,
8925 },
8926 },
8927 shouldFail: true,
8928 expectedError: ":INVALID_ENCODING:",
8929 })
8930 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008931 testType: serverTest,
8932 name: "InvalidECDHPoint-Server",
8933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008934 MaxVersion: VersionTLS12,
8935 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8936 CurvePreferences: []CurveID{CurveP256},
8937 Bugs: ProtocolBugs{
8938 InvalidECDHPoint: true,
8939 },
8940 },
8941 shouldFail: true,
8942 expectedError: ":INVALID_ENCODING:",
8943 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008944 testCases = append(testCases, testCase{
8945 testType: serverTest,
8946 name: "InvalidECDHPoint-Server-TLS13",
8947 config: Config{
8948 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008949 CurvePreferences: []CurveID{CurveP256},
8950 Bugs: ProtocolBugs{
8951 InvalidECDHPoint: true,
8952 },
8953 },
8954 shouldFail: true,
8955 expectedError: ":INVALID_ENCODING:",
8956 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008957
8958 // The previous curve ID should be reported on TLS 1.2 resumption.
8959 testCases = append(testCases, testCase{
8960 name: "CurveID-Resume-Client",
8961 config: Config{
8962 MaxVersion: VersionTLS12,
8963 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8964 CurvePreferences: []CurveID{CurveX25519},
8965 },
8966 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8967 resumeSession: true,
8968 })
8969 testCases = append(testCases, testCase{
8970 testType: serverTest,
8971 name: "CurveID-Resume-Server",
8972 config: Config{
8973 MaxVersion: VersionTLS12,
8974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8975 CurvePreferences: []CurveID{CurveX25519},
8976 },
8977 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8978 resumeSession: true,
8979 })
8980
8981 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8982 // one should be reported.
8983 testCases = append(testCases, testCase{
8984 name: "CurveID-Resume-Client-TLS13",
8985 config: Config{
8986 MaxVersion: VersionTLS13,
8987 CurvePreferences: []CurveID{CurveX25519},
8988 },
8989 resumeConfig: &Config{
8990 MaxVersion: VersionTLS13,
8991 CurvePreferences: []CurveID{CurveP256},
8992 },
8993 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008994 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8995 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008996 },
8997 resumeSession: true,
8998 })
8999 testCases = append(testCases, testCase{
9000 testType: serverTest,
9001 name: "CurveID-Resume-Server-TLS13",
9002 config: Config{
9003 MaxVersion: VersionTLS13,
9004 CurvePreferences: []CurveID{CurveX25519},
9005 },
9006 resumeConfig: &Config{
9007 MaxVersion: VersionTLS13,
9008 CurvePreferences: []CurveID{CurveP256},
9009 },
9010 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009011 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9012 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009013 },
9014 resumeSession: true,
9015 })
David Benjamina81967b2016-12-22 09:16:57 -05009016
9017 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9018 testCases = append(testCases, testCase{
9019 name: "PointFormat-ServerHello-TLS12",
9020 config: Config{
9021 MaxVersion: VersionTLS12,
9022 Bugs: ProtocolBugs{
9023 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9024 },
9025 },
9026 })
9027 testCases = append(testCases, testCase{
9028 name: "PointFormat-EncryptedExtensions-TLS13",
9029 config: Config{
9030 MaxVersion: VersionTLS13,
9031 Bugs: ProtocolBugs{
9032 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9033 },
9034 },
9035 shouldFail: true,
9036 expectedError: ":ERROR_PARSING_EXTENSION:",
9037 })
9038
9039 // Test that we tolerate unknown point formats, as long as
9040 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9041 // check they are still functional.
9042 testCases = append(testCases, testCase{
9043 name: "PointFormat-Client-Tolerance",
9044 config: Config{
9045 MaxVersion: VersionTLS12,
9046 Bugs: ProtocolBugs{
9047 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9048 },
9049 },
9050 })
9051 testCases = append(testCases, testCase{
9052 testType: serverTest,
9053 name: "PointFormat-Server-Tolerance",
9054 config: Config{
9055 MaxVersion: VersionTLS12,
9056 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9057 Bugs: ProtocolBugs{
9058 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9059 },
9060 },
9061 })
9062
9063 // Test TLS 1.2 does not require the point format extension to be
9064 // present.
9065 testCases = append(testCases, testCase{
9066 name: "PointFormat-Client-Missing",
9067 config: Config{
9068 MaxVersion: VersionTLS12,
9069 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9070 Bugs: ProtocolBugs{
9071 SendSupportedPointFormats: []byte{},
9072 },
9073 },
9074 })
9075 testCases = append(testCases, testCase{
9076 testType: serverTest,
9077 name: "PointFormat-Server-Missing",
9078 config: Config{
9079 MaxVersion: VersionTLS12,
9080 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9081 Bugs: ProtocolBugs{
9082 SendSupportedPointFormats: []byte{},
9083 },
9084 },
9085 })
9086
9087 // If the point format extension is present, uncompressed points must be
9088 // offered. BoringSSL requires this whether or not ECDHE is used.
9089 testCases = append(testCases, testCase{
9090 name: "PointFormat-Client-MissingUncompressed",
9091 config: Config{
9092 MaxVersion: VersionTLS12,
9093 Bugs: ProtocolBugs{
9094 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9095 },
9096 },
9097 shouldFail: true,
9098 expectedError: ":ERROR_PARSING_EXTENSION:",
9099 })
9100 testCases = append(testCases, testCase{
9101 testType: serverTest,
9102 name: "PointFormat-Server-MissingUncompressed",
9103 config: Config{
9104 MaxVersion: VersionTLS12,
9105 Bugs: ProtocolBugs{
9106 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9107 },
9108 },
9109 shouldFail: true,
9110 expectedError: ":ERROR_PARSING_EXTENSION:",
9111 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009112}
9113
David Benjaminc9ae27c2016-06-24 22:56:37 -04009114func addTLS13RecordTests() {
9115 testCases = append(testCases, testCase{
9116 name: "TLS13-RecordPadding",
9117 config: Config{
9118 MaxVersion: VersionTLS13,
9119 MinVersion: VersionTLS13,
9120 Bugs: ProtocolBugs{
9121 RecordPadding: 10,
9122 },
9123 },
9124 })
9125
9126 testCases = append(testCases, testCase{
9127 name: "TLS13-EmptyRecords",
9128 config: Config{
9129 MaxVersion: VersionTLS13,
9130 MinVersion: VersionTLS13,
9131 Bugs: ProtocolBugs{
9132 OmitRecordContents: true,
9133 },
9134 },
9135 shouldFail: true,
9136 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9137 })
9138
9139 testCases = append(testCases, testCase{
9140 name: "TLS13-OnlyPadding",
9141 config: Config{
9142 MaxVersion: VersionTLS13,
9143 MinVersion: VersionTLS13,
9144 Bugs: ProtocolBugs{
9145 OmitRecordContents: true,
9146 RecordPadding: 10,
9147 },
9148 },
9149 shouldFail: true,
9150 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9151 })
9152
9153 testCases = append(testCases, testCase{
9154 name: "TLS13-WrongOuterRecord",
9155 config: Config{
9156 MaxVersion: VersionTLS13,
9157 MinVersion: VersionTLS13,
9158 Bugs: ProtocolBugs{
9159 OuterRecordType: recordTypeHandshake,
9160 },
9161 },
9162 shouldFail: true,
9163 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9164 })
9165}
9166
Steven Valdez5b986082016-09-01 12:29:49 -04009167func addSessionTicketTests() {
9168 testCases = append(testCases, testCase{
9169 // In TLS 1.2 and below, empty NewSessionTicket messages
9170 // mean the server changed its mind on sending a ticket.
9171 name: "SendEmptySessionTicket",
9172 config: Config{
9173 MaxVersion: VersionTLS12,
9174 Bugs: ProtocolBugs{
9175 SendEmptySessionTicket: true,
9176 },
9177 },
9178 flags: []string{"-expect-no-session"},
9179 })
9180
9181 // Test that the server ignores unknown PSK modes.
9182 testCases = append(testCases, testCase{
9183 testType: serverTest,
9184 name: "TLS13-SendUnknownModeSessionTicket-Server",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
9187 Bugs: ProtocolBugs{
9188 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009189 },
9190 },
9191 resumeSession: true,
9192 expectedResumeVersion: VersionTLS13,
9193 })
9194
Steven Valdeza833c352016-11-01 13:39:36 -04009195 // Test that the server does not send session tickets with no matching key exchange mode.
9196 testCases = append(testCases, testCase{
9197 testType: serverTest,
9198 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9199 config: Config{
9200 MaxVersion: VersionTLS13,
9201 Bugs: ProtocolBugs{
9202 SendPSKKeyExchangeModes: []byte{0x1a},
9203 ExpectNoNewSessionTicket: true,
9204 },
9205 },
9206 })
9207
9208 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009209 testCases = append(testCases, testCase{
9210 testType: serverTest,
9211 name: "TLS13-SendBadKEModeSessionTicket-Server",
9212 config: Config{
9213 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009214 },
9215 resumeConfig: &Config{
9216 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009217 Bugs: ProtocolBugs{
9218 SendPSKKeyExchangeModes: []byte{0x1a},
9219 },
9220 },
9221 resumeSession: true,
9222 expectResumeRejected: true,
9223 })
9224
Steven Valdeza833c352016-11-01 13:39:36 -04009225 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009226 testCases = append(testCases, testCase{
9227 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009228 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009229 config: Config{
9230 MaxVersion: VersionTLS13,
9231 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009232 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009233 },
9234 },
Steven Valdeza833c352016-11-01 13:39:36 -04009235 resumeSession: true,
9236 flags: []string{
9237 "-resumption-delay", "10",
9238 },
Steven Valdez5b986082016-09-01 12:29:49 -04009239 })
9240
Steven Valdeza833c352016-11-01 13:39:36 -04009241 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009242 testCases = append(testCases, testCase{
9243 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009244 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009245 config: Config{
9246 MaxVersion: VersionTLS13,
9247 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009248 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009249 },
9250 },
Steven Valdeza833c352016-11-01 13:39:36 -04009251 resumeSession: true,
9252 shouldFail: true,
9253 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009254 })
9255
David Benjamin35ac5b72017-03-03 15:05:56 -05009256 // Test that the server's ticket age skew reporting works.
9257 testCases = append(testCases, testCase{
9258 testType: serverTest,
9259 name: "TLS13-TicketAgeSkew-Forward",
9260 config: Config{
9261 MaxVersion: VersionTLS13,
9262 Bugs: ProtocolBugs{
9263 SendTicketAge: 15 * time.Second,
9264 },
9265 },
David Benjamin065d7332017-03-26 10:51:43 -05009266 resumeSession: true,
9267 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009268 flags: []string{
9269 "-resumption-delay", "10",
9270 "-expect-ticket-age-skew", "5",
9271 },
9272 })
9273 testCases = append(testCases, testCase{
9274 testType: serverTest,
9275 name: "TLS13-TicketAgeSkew-Backward",
9276 config: Config{
9277 MaxVersion: VersionTLS13,
9278 Bugs: ProtocolBugs{
9279 SendTicketAge: 5 * time.Second,
9280 },
9281 },
David Benjamin065d7332017-03-26 10:51:43 -05009282 resumeSession: true,
9283 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009284 flags: []string{
9285 "-resumption-delay", "10",
9286 "-expect-ticket-age-skew", "-5",
9287 },
9288 })
9289
Steven Valdez08b65f42016-12-07 15:29:45 -05009290 testCases = append(testCases, testCase{
9291 testType: clientTest,
9292 name: "TLS13-SendTicketEarlyDataInfo",
9293 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009294 MaxVersion: VersionTLS13,
9295 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009296 },
9297 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009298 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009299 "-expect-early-data-info",
9300 },
9301 })
9302
David Benjamin9b160662017-01-25 19:53:43 -05009303 // Test that 0-RTT tickets are ignored in clients unless opted in.
9304 testCases = append(testCases, testCase{
9305 testType: clientTest,
9306 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9307 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009308 MaxVersion: VersionTLS13,
9309 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009310 },
9311 })
9312
Steven Valdez08b65f42016-12-07 15:29:45 -05009313 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009314 testType: clientTest,
9315 name: "TLS13-DuplicateTicketEarlyDataInfo",
9316 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009317 MaxVersion: VersionTLS13,
9318 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009319 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009320 DuplicateTicketEarlyDataInfo: true,
9321 },
9322 },
9323 shouldFail: true,
9324 expectedError: ":DUPLICATE_EXTENSION:",
9325 expectedLocalError: "remote error: illegal parameter",
9326 })
9327
9328 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009329 testType: serverTest,
9330 name: "TLS13-ExpectTicketEarlyDataInfo",
9331 config: Config{
9332 MaxVersion: VersionTLS13,
9333 Bugs: ProtocolBugs{
9334 ExpectTicketEarlyDataInfo: true,
9335 },
9336 },
9337 flags: []string{
9338 "-enable-early-data",
9339 },
9340 })
David Benjamin17b30832017-01-28 14:00:32 -05009341
9342 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9343 // is honored.
9344 testCases = append(testCases, testCase{
9345 testType: clientTest,
9346 name: "TLS13-HonorServerSessionTicketLifetime",
9347 config: Config{
9348 MaxVersion: VersionTLS13,
9349 Bugs: ProtocolBugs{
9350 SendTicketLifetime: 20 * time.Second,
9351 },
9352 },
9353 flags: []string{
9354 "-resumption-delay", "19",
9355 },
9356 resumeSession: true,
9357 })
9358 testCases = append(testCases, testCase{
9359 testType: clientTest,
9360 name: "TLS13-HonorServerSessionTicketLifetime-2",
9361 config: Config{
9362 MaxVersion: VersionTLS13,
9363 Bugs: ProtocolBugs{
9364 SendTicketLifetime: 20 * time.Second,
9365 // The client should not offer the expired session.
9366 ExpectNoTLS13PSK: true,
9367 },
9368 },
9369 flags: []string{
9370 "-resumption-delay", "21",
9371 },
David Benjamin023d4192017-02-06 13:49:07 -05009372 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009373 expectResumeRejected: true,
9374 })
Steven Valdez5b986082016-09-01 12:29:49 -04009375}
9376
David Benjamin82261be2016-07-07 14:32:50 -07009377func addChangeCipherSpecTests() {
9378 // Test missing ChangeCipherSpecs.
9379 testCases = append(testCases, testCase{
9380 name: "SkipChangeCipherSpec-Client",
9381 config: Config{
9382 MaxVersion: VersionTLS12,
9383 Bugs: ProtocolBugs{
9384 SkipChangeCipherSpec: true,
9385 },
9386 },
9387 shouldFail: true,
9388 expectedError: ":UNEXPECTED_RECORD:",
9389 })
9390 testCases = append(testCases, testCase{
9391 testType: serverTest,
9392 name: "SkipChangeCipherSpec-Server",
9393 config: Config{
9394 MaxVersion: VersionTLS12,
9395 Bugs: ProtocolBugs{
9396 SkipChangeCipherSpec: true,
9397 },
9398 },
9399 shouldFail: true,
9400 expectedError: ":UNEXPECTED_RECORD:",
9401 })
9402 testCases = append(testCases, testCase{
9403 testType: serverTest,
9404 name: "SkipChangeCipherSpec-Server-NPN",
9405 config: Config{
9406 MaxVersion: VersionTLS12,
9407 NextProtos: []string{"bar"},
9408 Bugs: ProtocolBugs{
9409 SkipChangeCipherSpec: true,
9410 },
9411 },
9412 flags: []string{
9413 "-advertise-npn", "\x03foo\x03bar\x03baz",
9414 },
9415 shouldFail: true,
9416 expectedError: ":UNEXPECTED_RECORD:",
9417 })
9418
9419 // Test synchronization between the handshake and ChangeCipherSpec.
9420 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9421 // rejected. Test both with and without handshake packing to handle both
9422 // when the partial post-CCS message is in its own record and when it is
9423 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009424 for _, packed := range []bool{false, true} {
9425 var suffix string
9426 if packed {
9427 suffix = "-Packed"
9428 }
9429
9430 testCases = append(testCases, testCase{
9431 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9432 config: Config{
9433 MaxVersion: VersionTLS12,
9434 Bugs: ProtocolBugs{
9435 FragmentAcrossChangeCipherSpec: true,
9436 PackHandshakeFlight: packed,
9437 },
9438 },
9439 shouldFail: true,
9440 expectedError: ":UNEXPECTED_RECORD:",
9441 })
9442 testCases = append(testCases, testCase{
9443 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9444 config: Config{
9445 MaxVersion: VersionTLS12,
9446 },
9447 resumeSession: true,
9448 resumeConfig: &Config{
9449 MaxVersion: VersionTLS12,
9450 Bugs: ProtocolBugs{
9451 FragmentAcrossChangeCipherSpec: true,
9452 PackHandshakeFlight: packed,
9453 },
9454 },
9455 shouldFail: true,
9456 expectedError: ":UNEXPECTED_RECORD:",
9457 })
9458 testCases = append(testCases, testCase{
9459 testType: serverTest,
9460 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9461 config: Config{
9462 MaxVersion: VersionTLS12,
9463 Bugs: ProtocolBugs{
9464 FragmentAcrossChangeCipherSpec: true,
9465 PackHandshakeFlight: packed,
9466 },
9467 },
9468 shouldFail: true,
9469 expectedError: ":UNEXPECTED_RECORD:",
9470 })
9471 testCases = append(testCases, testCase{
9472 testType: serverTest,
9473 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9474 config: Config{
9475 MaxVersion: VersionTLS12,
9476 },
9477 resumeSession: true,
9478 resumeConfig: &Config{
9479 MaxVersion: VersionTLS12,
9480 Bugs: ProtocolBugs{
9481 FragmentAcrossChangeCipherSpec: true,
9482 PackHandshakeFlight: packed,
9483 },
9484 },
9485 shouldFail: true,
9486 expectedError: ":UNEXPECTED_RECORD:",
9487 })
9488 testCases = append(testCases, testCase{
9489 testType: serverTest,
9490 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9491 config: Config{
9492 MaxVersion: VersionTLS12,
9493 NextProtos: []string{"bar"},
9494 Bugs: ProtocolBugs{
9495 FragmentAcrossChangeCipherSpec: true,
9496 PackHandshakeFlight: packed,
9497 },
9498 },
9499 flags: []string{
9500 "-advertise-npn", "\x03foo\x03bar\x03baz",
9501 },
9502 shouldFail: true,
9503 expectedError: ":UNEXPECTED_RECORD:",
9504 })
9505 }
9506
David Benjamin61672812016-07-14 23:10:43 -04009507 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9508 // messages in the handshake queue. Do this by testing the server
9509 // reading the client Finished, reversing the flight so Finished comes
9510 // first.
9511 testCases = append(testCases, testCase{
9512 protocol: dtls,
9513 testType: serverTest,
9514 name: "SendUnencryptedFinished-DTLS",
9515 config: Config{
9516 MaxVersion: VersionTLS12,
9517 Bugs: ProtocolBugs{
9518 SendUnencryptedFinished: true,
9519 ReverseHandshakeFragments: true,
9520 },
9521 },
9522 shouldFail: true,
9523 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9524 })
9525
Steven Valdez143e8b32016-07-11 13:19:03 -04009526 // Test synchronization between encryption changes and the handshake in
9527 // TLS 1.3, where ChangeCipherSpec is implicit.
9528 testCases = append(testCases, testCase{
9529 name: "PartialEncryptedExtensionsWithServerHello",
9530 config: Config{
9531 MaxVersion: VersionTLS13,
9532 Bugs: ProtocolBugs{
9533 PartialEncryptedExtensionsWithServerHello: true,
9534 },
9535 },
9536 shouldFail: true,
9537 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9538 })
9539 testCases = append(testCases, testCase{
9540 testType: serverTest,
9541 name: "PartialClientFinishedWithClientHello",
9542 config: Config{
9543 MaxVersion: VersionTLS13,
9544 Bugs: ProtocolBugs{
9545 PartialClientFinishedWithClientHello: true,
9546 },
9547 },
9548 shouldFail: true,
9549 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9550 })
9551
David Benjamin82261be2016-07-07 14:32:50 -07009552 // Test that early ChangeCipherSpecs are handled correctly.
9553 testCases = append(testCases, testCase{
9554 testType: serverTest,
9555 name: "EarlyChangeCipherSpec-server-1",
9556 config: Config{
9557 MaxVersion: VersionTLS12,
9558 Bugs: ProtocolBugs{
9559 EarlyChangeCipherSpec: 1,
9560 },
9561 },
9562 shouldFail: true,
9563 expectedError: ":UNEXPECTED_RECORD:",
9564 })
9565 testCases = append(testCases, testCase{
9566 testType: serverTest,
9567 name: "EarlyChangeCipherSpec-server-2",
9568 config: Config{
9569 MaxVersion: VersionTLS12,
9570 Bugs: ProtocolBugs{
9571 EarlyChangeCipherSpec: 2,
9572 },
9573 },
9574 shouldFail: true,
9575 expectedError: ":UNEXPECTED_RECORD:",
9576 })
9577 testCases = append(testCases, testCase{
9578 protocol: dtls,
9579 name: "StrayChangeCipherSpec",
9580 config: Config{
9581 // TODO(davidben): Once DTLS 1.3 exists, test
9582 // that stray ChangeCipherSpec messages are
9583 // rejected.
9584 MaxVersion: VersionTLS12,
9585 Bugs: ProtocolBugs{
9586 StrayChangeCipherSpec: true,
9587 },
9588 },
9589 })
9590
9591 // Test that the contents of ChangeCipherSpec are checked.
9592 testCases = append(testCases, testCase{
9593 name: "BadChangeCipherSpec-1",
9594 config: Config{
9595 MaxVersion: VersionTLS12,
9596 Bugs: ProtocolBugs{
9597 BadChangeCipherSpec: []byte{2},
9598 },
9599 },
9600 shouldFail: true,
9601 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9602 })
9603 testCases = append(testCases, testCase{
9604 name: "BadChangeCipherSpec-2",
9605 config: Config{
9606 MaxVersion: VersionTLS12,
9607 Bugs: ProtocolBugs{
9608 BadChangeCipherSpec: []byte{1, 1},
9609 },
9610 },
9611 shouldFail: true,
9612 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9613 })
9614 testCases = append(testCases, testCase{
9615 protocol: dtls,
9616 name: "BadChangeCipherSpec-DTLS-1",
9617 config: Config{
9618 MaxVersion: VersionTLS12,
9619 Bugs: ProtocolBugs{
9620 BadChangeCipherSpec: []byte{2},
9621 },
9622 },
9623 shouldFail: true,
9624 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9625 })
9626 testCases = append(testCases, testCase{
9627 protocol: dtls,
9628 name: "BadChangeCipherSpec-DTLS-2",
9629 config: Config{
9630 MaxVersion: VersionTLS12,
9631 Bugs: ProtocolBugs{
9632 BadChangeCipherSpec: []byte{1, 1},
9633 },
9634 },
9635 shouldFail: true,
9636 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9637 })
9638}
9639
David Benjamincd2c8062016-09-09 11:28:16 -04009640type perMessageTest struct {
9641 messageType uint8
9642 test testCase
9643}
9644
9645// makePerMessageTests returns a series of test templates which cover each
9646// message in the TLS handshake. These may be used with bugs like
9647// WrongMessageType to fully test a per-message bug.
9648func makePerMessageTests() []perMessageTest {
9649 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009650 for _, protocol := range []protocol{tls, dtls} {
9651 var suffix string
9652 if protocol == dtls {
9653 suffix = "-DTLS"
9654 }
9655
David Benjamincd2c8062016-09-09 11:28:16 -04009656 ret = append(ret, perMessageTest{
9657 messageType: typeClientHello,
9658 test: testCase{
9659 protocol: protocol,
9660 testType: serverTest,
9661 name: "ClientHello" + suffix,
9662 config: Config{
9663 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009664 },
9665 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009666 })
9667
9668 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009669 ret = append(ret, perMessageTest{
9670 messageType: typeHelloVerifyRequest,
9671 test: testCase{
9672 protocol: protocol,
9673 name: "HelloVerifyRequest" + suffix,
9674 config: Config{
9675 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009676 },
9677 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009678 })
9679 }
9680
David Benjamincd2c8062016-09-09 11:28:16 -04009681 ret = append(ret, perMessageTest{
9682 messageType: typeServerHello,
9683 test: testCase{
9684 protocol: protocol,
9685 name: "ServerHello" + suffix,
9686 config: Config{
9687 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009688 },
9689 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009690 })
9691
David Benjamincd2c8062016-09-09 11:28:16 -04009692 ret = append(ret, perMessageTest{
9693 messageType: typeCertificate,
9694 test: testCase{
9695 protocol: protocol,
9696 name: "ServerCertificate" + suffix,
9697 config: Config{
9698 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009699 },
9700 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009701 })
9702
David Benjamincd2c8062016-09-09 11:28:16 -04009703 ret = append(ret, perMessageTest{
9704 messageType: typeCertificateStatus,
9705 test: testCase{
9706 protocol: protocol,
9707 name: "CertificateStatus" + suffix,
9708 config: Config{
9709 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009710 },
David Benjamincd2c8062016-09-09 11:28:16 -04009711 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009712 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009713 })
9714
David Benjamincd2c8062016-09-09 11:28:16 -04009715 ret = append(ret, perMessageTest{
9716 messageType: typeServerKeyExchange,
9717 test: testCase{
9718 protocol: protocol,
9719 name: "ServerKeyExchange" + suffix,
9720 config: Config{
9721 MaxVersion: VersionTLS12,
9722 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009723 },
9724 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009725 })
9726
David Benjamincd2c8062016-09-09 11:28:16 -04009727 ret = append(ret, perMessageTest{
9728 messageType: typeCertificateRequest,
9729 test: testCase{
9730 protocol: protocol,
9731 name: "CertificateRequest" + suffix,
9732 config: Config{
9733 MaxVersion: VersionTLS12,
9734 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009735 },
9736 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009737 })
9738
David Benjamincd2c8062016-09-09 11:28:16 -04009739 ret = append(ret, perMessageTest{
9740 messageType: typeServerHelloDone,
9741 test: testCase{
9742 protocol: protocol,
9743 name: "ServerHelloDone" + suffix,
9744 config: Config{
9745 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009746 },
9747 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009748 })
9749
David Benjamincd2c8062016-09-09 11:28:16 -04009750 ret = append(ret, perMessageTest{
9751 messageType: typeCertificate,
9752 test: testCase{
9753 testType: serverTest,
9754 protocol: protocol,
9755 name: "ClientCertificate" + suffix,
9756 config: Config{
9757 Certificates: []Certificate{rsaCertificate},
9758 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009759 },
David Benjamincd2c8062016-09-09 11:28:16 -04009760 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009761 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009762 })
9763
David Benjamincd2c8062016-09-09 11:28:16 -04009764 ret = append(ret, perMessageTest{
9765 messageType: typeCertificateVerify,
9766 test: testCase{
9767 testType: serverTest,
9768 protocol: protocol,
9769 name: "CertificateVerify" + suffix,
9770 config: Config{
9771 Certificates: []Certificate{rsaCertificate},
9772 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009773 },
David Benjamincd2c8062016-09-09 11:28:16 -04009774 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009775 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009776 })
9777
David Benjamincd2c8062016-09-09 11:28:16 -04009778 ret = append(ret, perMessageTest{
9779 messageType: typeClientKeyExchange,
9780 test: testCase{
9781 testType: serverTest,
9782 protocol: protocol,
9783 name: "ClientKeyExchange" + suffix,
9784 config: Config{
9785 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009786 },
9787 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009788 })
9789
9790 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009791 ret = append(ret, perMessageTest{
9792 messageType: typeNextProtocol,
9793 test: testCase{
9794 testType: serverTest,
9795 protocol: protocol,
9796 name: "NextProtocol" + suffix,
9797 config: Config{
9798 MaxVersion: VersionTLS12,
9799 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009800 },
David Benjamincd2c8062016-09-09 11:28:16 -04009801 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009802 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009803 })
9804
David Benjamincd2c8062016-09-09 11:28:16 -04009805 ret = append(ret, perMessageTest{
9806 messageType: typeChannelID,
9807 test: testCase{
9808 testType: serverTest,
9809 protocol: protocol,
9810 name: "ChannelID" + suffix,
9811 config: Config{
9812 MaxVersion: VersionTLS12,
9813 ChannelID: channelIDKey,
9814 },
9815 flags: []string{
9816 "-expect-channel-id",
9817 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009818 },
9819 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009820 })
9821 }
9822
David Benjamincd2c8062016-09-09 11:28:16 -04009823 ret = append(ret, perMessageTest{
9824 messageType: typeFinished,
9825 test: testCase{
9826 testType: serverTest,
9827 protocol: protocol,
9828 name: "ClientFinished" + suffix,
9829 config: Config{
9830 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009831 },
9832 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009833 })
9834
David Benjamincd2c8062016-09-09 11:28:16 -04009835 ret = append(ret, perMessageTest{
9836 messageType: typeNewSessionTicket,
9837 test: testCase{
9838 protocol: protocol,
9839 name: "NewSessionTicket" + suffix,
9840 config: Config{
9841 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009842 },
9843 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009844 })
9845
David Benjamincd2c8062016-09-09 11:28:16 -04009846 ret = append(ret, perMessageTest{
9847 messageType: typeFinished,
9848 test: testCase{
9849 protocol: protocol,
9850 name: "ServerFinished" + suffix,
9851 config: Config{
9852 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009853 },
9854 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009855 })
9856
9857 }
David Benjamincd2c8062016-09-09 11:28:16 -04009858
9859 ret = append(ret, perMessageTest{
9860 messageType: typeClientHello,
9861 test: testCase{
9862 testType: serverTest,
9863 name: "TLS13-ClientHello",
9864 config: Config{
9865 MaxVersion: VersionTLS13,
9866 },
9867 },
9868 })
9869
9870 ret = append(ret, perMessageTest{
9871 messageType: typeServerHello,
9872 test: testCase{
9873 name: "TLS13-ServerHello",
9874 config: Config{
9875 MaxVersion: VersionTLS13,
9876 },
9877 },
9878 })
9879
9880 ret = append(ret, perMessageTest{
9881 messageType: typeEncryptedExtensions,
9882 test: testCase{
9883 name: "TLS13-EncryptedExtensions",
9884 config: Config{
9885 MaxVersion: VersionTLS13,
9886 },
9887 },
9888 })
9889
9890 ret = append(ret, perMessageTest{
9891 messageType: typeCertificateRequest,
9892 test: testCase{
9893 name: "TLS13-CertificateRequest",
9894 config: Config{
9895 MaxVersion: VersionTLS13,
9896 ClientAuth: RequireAnyClientCert,
9897 },
9898 },
9899 })
9900
9901 ret = append(ret, perMessageTest{
9902 messageType: typeCertificate,
9903 test: testCase{
9904 name: "TLS13-ServerCertificate",
9905 config: Config{
9906 MaxVersion: VersionTLS13,
9907 },
9908 },
9909 })
9910
9911 ret = append(ret, perMessageTest{
9912 messageType: typeCertificateVerify,
9913 test: testCase{
9914 name: "TLS13-ServerCertificateVerify",
9915 config: Config{
9916 MaxVersion: VersionTLS13,
9917 },
9918 },
9919 })
9920
9921 ret = append(ret, perMessageTest{
9922 messageType: typeFinished,
9923 test: testCase{
9924 name: "TLS13-ServerFinished",
9925 config: Config{
9926 MaxVersion: VersionTLS13,
9927 },
9928 },
9929 })
9930
9931 ret = append(ret, perMessageTest{
9932 messageType: typeCertificate,
9933 test: testCase{
9934 testType: serverTest,
9935 name: "TLS13-ClientCertificate",
9936 config: Config{
9937 Certificates: []Certificate{rsaCertificate},
9938 MaxVersion: VersionTLS13,
9939 },
9940 flags: []string{"-require-any-client-certificate"},
9941 },
9942 })
9943
9944 ret = append(ret, perMessageTest{
9945 messageType: typeCertificateVerify,
9946 test: testCase{
9947 testType: serverTest,
9948 name: "TLS13-ClientCertificateVerify",
9949 config: Config{
9950 Certificates: []Certificate{rsaCertificate},
9951 MaxVersion: VersionTLS13,
9952 },
9953 flags: []string{"-require-any-client-certificate"},
9954 },
9955 })
9956
9957 ret = append(ret, perMessageTest{
9958 messageType: typeFinished,
9959 test: testCase{
9960 testType: serverTest,
9961 name: "TLS13-ClientFinished",
9962 config: Config{
9963 MaxVersion: VersionTLS13,
9964 },
9965 },
9966 })
9967
9968 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009969}
9970
David Benjamincd2c8062016-09-09 11:28:16 -04009971func addWrongMessageTypeTests() {
9972 for _, t := range makePerMessageTests() {
9973 t.test.name = "WrongMessageType-" + t.test.name
9974 t.test.config.Bugs.SendWrongMessageType = t.messageType
9975 t.test.shouldFail = true
9976 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9977 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009978
David Benjamincd2c8062016-09-09 11:28:16 -04009979 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9980 // In TLS 1.3, a bad ServerHello means the client sends
9981 // an unencrypted alert while the server expects
9982 // encryption, so the alert is not readable by runner.
9983 t.test.expectedLocalError = "local error: bad record MAC"
9984 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009985
David Benjamincd2c8062016-09-09 11:28:16 -04009986 testCases = append(testCases, t.test)
9987 }
David Benjaminebacdee2017-04-08 11:00:45 -04009988
9989 // The processing order for TLS 1.3 version negotiation is such that one
9990 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
9991 // TLS 1.2. Test that we do not do this.
9992 testCases = append(testCases, testCase{
9993 name: "SendServerHelloAsHelloRetryRequest",
9994 config: Config{
9995 MaxVersion: VersionTLS12,
9996 Bugs: ProtocolBugs{
9997 SendServerHelloAsHelloRetryRequest: true,
9998 },
9999 },
10000 shouldFail: true,
10001 expectedError: ":UNEXPECTED_MESSAGE:",
10002 expectedLocalError: "remote error: unexpected message",
10003 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010004}
10005
David Benjamin639846e2016-09-09 11:41:18 -040010006func addTrailingMessageDataTests() {
10007 for _, t := range makePerMessageTests() {
10008 t.test.name = "TrailingMessageData-" + t.test.name
10009 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10010 t.test.shouldFail = true
10011 t.test.expectedError = ":DECODE_ERROR:"
10012 t.test.expectedLocalError = "remote error: error decoding message"
10013
10014 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10015 // In TLS 1.3, a bad ServerHello means the client sends
10016 // an unencrypted alert while the server expects
10017 // encryption, so the alert is not readable by runner.
10018 t.test.expectedLocalError = "local error: bad record MAC"
10019 }
10020
10021 if t.messageType == typeFinished {
10022 // Bad Finished messages read as the verify data having
10023 // the wrong length.
10024 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10025 t.test.expectedLocalError = "remote error: error decrypting message"
10026 }
10027
10028 testCases = append(testCases, t.test)
10029 }
10030}
10031
Steven Valdez143e8b32016-07-11 13:19:03 -040010032func addTLS13HandshakeTests() {
10033 testCases = append(testCases, testCase{
10034 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010035 name: "NegotiatePSKResumption-TLS13",
10036 config: Config{
10037 MaxVersion: VersionTLS13,
10038 Bugs: ProtocolBugs{
10039 NegotiatePSKResumption: true,
10040 },
10041 },
10042 resumeSession: true,
10043 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010044 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010045 })
10046
10047 testCases = append(testCases, testCase{
10048 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010049 name: "MissingKeyShare-Client",
10050 config: Config{
10051 MaxVersion: VersionTLS13,
10052 Bugs: ProtocolBugs{
10053 MissingKeyShare: true,
10054 },
10055 },
10056 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010057 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010058 })
10059
10060 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010061 testType: serverTest,
10062 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010063 config: Config{
10064 MaxVersion: VersionTLS13,
10065 Bugs: ProtocolBugs{
10066 MissingKeyShare: true,
10067 },
10068 },
10069 shouldFail: true,
10070 expectedError: ":MISSING_KEY_SHARE:",
10071 })
10072
10073 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010074 testType: serverTest,
10075 name: "DuplicateKeyShares",
10076 config: Config{
10077 MaxVersion: VersionTLS13,
10078 Bugs: ProtocolBugs{
10079 DuplicateKeyShares: true,
10080 },
10081 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010082 shouldFail: true,
10083 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010084 })
10085
10086 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010087 testType: serverTest,
10088 name: "SkipEarlyData",
10089 config: Config{
10090 MaxVersion: VersionTLS13,
10091 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010092 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010093 },
10094 },
10095 })
10096
10097 testCases = append(testCases, testCase{
10098 testType: serverTest,
10099 name: "SkipEarlyData-OmitEarlyDataExtension",
10100 config: Config{
10101 MaxVersion: VersionTLS13,
10102 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010103 SendFakeEarlyDataLength: 4,
10104 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010105 },
10106 },
10107 shouldFail: true,
10108 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10109 })
10110
10111 testCases = append(testCases, testCase{
10112 testType: serverTest,
10113 name: "SkipEarlyData-TooMuchData",
10114 config: Config{
10115 MaxVersion: VersionTLS13,
10116 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010117 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010118 },
10119 },
10120 shouldFail: true,
10121 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10122 })
10123
10124 testCases = append(testCases, testCase{
10125 testType: serverTest,
10126 name: "SkipEarlyData-Interleaved",
10127 config: Config{
10128 MaxVersion: VersionTLS13,
10129 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010130 SendFakeEarlyDataLength: 4,
10131 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010132 },
10133 },
10134 shouldFail: true,
10135 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10136 })
10137
10138 testCases = append(testCases, testCase{
10139 testType: serverTest,
10140 name: "SkipEarlyData-EarlyDataInTLS12",
10141 config: Config{
10142 MaxVersion: VersionTLS13,
10143 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010144 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010145 },
10146 },
10147 shouldFail: true,
10148 expectedError: ":UNEXPECTED_RECORD:",
10149 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10150 })
10151
10152 testCases = append(testCases, testCase{
10153 testType: serverTest,
10154 name: "SkipEarlyData-HRR",
10155 config: Config{
10156 MaxVersion: VersionTLS13,
10157 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010158 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010159 },
10160 DefaultCurves: []CurveID{},
10161 },
10162 })
10163
10164 testCases = append(testCases, testCase{
10165 testType: serverTest,
10166 name: "SkipEarlyData-HRR-Interleaved",
10167 config: Config{
10168 MaxVersion: VersionTLS13,
10169 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010170 SendFakeEarlyDataLength: 4,
10171 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010172 },
10173 DefaultCurves: []CurveID{},
10174 },
10175 shouldFail: true,
10176 expectedError: ":UNEXPECTED_RECORD:",
10177 })
10178
10179 testCases = append(testCases, testCase{
10180 testType: serverTest,
10181 name: "SkipEarlyData-HRR-TooMuchData",
10182 config: Config{
10183 MaxVersion: VersionTLS13,
10184 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010185 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010186 },
10187 DefaultCurves: []CurveID{},
10188 },
10189 shouldFail: true,
10190 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10191 })
10192
10193 // Test that skipping early data looking for cleartext correctly
10194 // processes an alert record.
10195 testCases = append(testCases, testCase{
10196 testType: serverTest,
10197 name: "SkipEarlyData-HRR-FatalAlert",
10198 config: Config{
10199 MaxVersion: VersionTLS13,
10200 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010201 SendEarlyAlert: true,
10202 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010203 },
10204 DefaultCurves: []CurveID{},
10205 },
10206 shouldFail: true,
10207 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10208 })
10209
10210 testCases = append(testCases, testCase{
10211 testType: serverTest,
10212 name: "SkipEarlyData-SecondClientHelloEarlyData",
10213 config: Config{
10214 MaxVersion: VersionTLS13,
10215 Bugs: ProtocolBugs{
10216 SendEarlyDataOnSecondClientHello: true,
10217 },
10218 DefaultCurves: []CurveID{},
10219 },
10220 shouldFail: true,
10221 expectedLocalError: "remote error: bad record MAC",
10222 })
10223
10224 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010225 testType: clientTest,
10226 name: "EmptyEncryptedExtensions",
10227 config: Config{
10228 MaxVersion: VersionTLS13,
10229 Bugs: ProtocolBugs{
10230 EmptyEncryptedExtensions: true,
10231 },
10232 },
10233 shouldFail: true,
10234 expectedLocalError: "remote error: error decoding message",
10235 })
10236
10237 testCases = append(testCases, testCase{
10238 testType: clientTest,
10239 name: "EncryptedExtensionsWithKeyShare",
10240 config: Config{
10241 MaxVersion: VersionTLS13,
10242 Bugs: ProtocolBugs{
10243 EncryptedExtensionsWithKeyShare: true,
10244 },
10245 },
10246 shouldFail: true,
10247 expectedLocalError: "remote error: unsupported extension",
10248 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010249
10250 testCases = append(testCases, testCase{
10251 testType: serverTest,
10252 name: "SendHelloRetryRequest",
10253 config: Config{
10254 MaxVersion: VersionTLS13,
10255 // Require a HelloRetryRequest for every curve.
10256 DefaultCurves: []CurveID{},
10257 },
10258 expectedCurveID: CurveX25519,
10259 })
10260
10261 testCases = append(testCases, testCase{
10262 testType: serverTest,
10263 name: "SendHelloRetryRequest-2",
10264 config: Config{
10265 MaxVersion: VersionTLS13,
10266 DefaultCurves: []CurveID{CurveP384},
10267 },
10268 // Although the ClientHello did not predict our preferred curve,
10269 // we always select it whether it is predicted or not.
10270 expectedCurveID: CurveX25519,
10271 })
10272
10273 testCases = append(testCases, testCase{
10274 name: "UnknownCurve-HelloRetryRequest",
10275 config: Config{
10276 MaxVersion: VersionTLS13,
10277 // P-384 requires HelloRetryRequest in BoringSSL.
10278 CurvePreferences: []CurveID{CurveP384},
10279 Bugs: ProtocolBugs{
10280 SendHelloRetryRequestCurve: bogusCurve,
10281 },
10282 },
10283 shouldFail: true,
10284 expectedError: ":WRONG_CURVE:",
10285 })
10286
10287 testCases = append(testCases, testCase{
10288 name: "DisabledCurve-HelloRetryRequest",
10289 config: Config{
10290 MaxVersion: VersionTLS13,
10291 CurvePreferences: []CurveID{CurveP256},
10292 Bugs: ProtocolBugs{
10293 IgnorePeerCurvePreferences: true,
10294 },
10295 },
10296 flags: []string{"-p384-only"},
10297 shouldFail: true,
10298 expectedError: ":WRONG_CURVE:",
10299 })
10300
10301 testCases = append(testCases, testCase{
10302 name: "UnnecessaryHelloRetryRequest",
10303 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010304 MaxVersion: VersionTLS13,
10305 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010306 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010307 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010308 },
10309 },
10310 shouldFail: true,
10311 expectedError: ":WRONG_CURVE:",
10312 })
10313
10314 testCases = append(testCases, testCase{
10315 name: "SecondHelloRetryRequest",
10316 config: Config{
10317 MaxVersion: VersionTLS13,
10318 // P-384 requires HelloRetryRequest in BoringSSL.
10319 CurvePreferences: []CurveID{CurveP384},
10320 Bugs: ProtocolBugs{
10321 SecondHelloRetryRequest: true,
10322 },
10323 },
10324 shouldFail: true,
10325 expectedError: ":UNEXPECTED_MESSAGE:",
10326 })
10327
10328 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010329 name: "HelloRetryRequest-Empty",
10330 config: Config{
10331 MaxVersion: VersionTLS13,
10332 Bugs: ProtocolBugs{
10333 AlwaysSendHelloRetryRequest: true,
10334 },
10335 },
10336 shouldFail: true,
10337 expectedError: ":DECODE_ERROR:",
10338 })
10339
10340 testCases = append(testCases, testCase{
10341 name: "HelloRetryRequest-DuplicateCurve",
10342 config: Config{
10343 MaxVersion: VersionTLS13,
10344 // P-384 requires a HelloRetryRequest against BoringSSL's default
10345 // configuration. Assert this ExpectMissingKeyShare.
10346 CurvePreferences: []CurveID{CurveP384},
10347 Bugs: ProtocolBugs{
10348 ExpectMissingKeyShare: true,
10349 DuplicateHelloRetryRequestExtensions: true,
10350 },
10351 },
10352 shouldFail: true,
10353 expectedError: ":DUPLICATE_EXTENSION:",
10354 expectedLocalError: "remote error: illegal parameter",
10355 })
10356
10357 testCases = append(testCases, testCase{
10358 name: "HelloRetryRequest-Cookie",
10359 config: Config{
10360 MaxVersion: VersionTLS13,
10361 Bugs: ProtocolBugs{
10362 SendHelloRetryRequestCookie: []byte("cookie"),
10363 },
10364 },
10365 })
10366
10367 testCases = append(testCases, testCase{
10368 name: "HelloRetryRequest-DuplicateCookie",
10369 config: Config{
10370 MaxVersion: VersionTLS13,
10371 Bugs: ProtocolBugs{
10372 SendHelloRetryRequestCookie: []byte("cookie"),
10373 DuplicateHelloRetryRequestExtensions: true,
10374 },
10375 },
10376 shouldFail: true,
10377 expectedError: ":DUPLICATE_EXTENSION:",
10378 expectedLocalError: "remote error: illegal parameter",
10379 })
10380
10381 testCases = append(testCases, testCase{
10382 name: "HelloRetryRequest-EmptyCookie",
10383 config: Config{
10384 MaxVersion: VersionTLS13,
10385 Bugs: ProtocolBugs{
10386 SendHelloRetryRequestCookie: []byte{},
10387 },
10388 },
10389 shouldFail: true,
10390 expectedError: ":DECODE_ERROR:",
10391 })
10392
10393 testCases = append(testCases, testCase{
10394 name: "HelloRetryRequest-Cookie-Curve",
10395 config: Config{
10396 MaxVersion: VersionTLS13,
10397 // P-384 requires HelloRetryRequest in BoringSSL.
10398 CurvePreferences: []CurveID{CurveP384},
10399 Bugs: ProtocolBugs{
10400 SendHelloRetryRequestCookie: []byte("cookie"),
10401 ExpectMissingKeyShare: true,
10402 },
10403 },
10404 })
10405
10406 testCases = append(testCases, testCase{
10407 name: "HelloRetryRequest-Unknown",
10408 config: Config{
10409 MaxVersion: VersionTLS13,
10410 Bugs: ProtocolBugs{
10411 CustomHelloRetryRequestExtension: "extension",
10412 },
10413 },
10414 shouldFail: true,
10415 expectedError: ":UNEXPECTED_EXTENSION:",
10416 expectedLocalError: "remote error: unsupported extension",
10417 })
10418
10419 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010420 testType: serverTest,
10421 name: "SecondClientHelloMissingKeyShare",
10422 config: Config{
10423 MaxVersion: VersionTLS13,
10424 DefaultCurves: []CurveID{},
10425 Bugs: ProtocolBugs{
10426 SecondClientHelloMissingKeyShare: true,
10427 },
10428 },
10429 shouldFail: true,
10430 expectedError: ":MISSING_KEY_SHARE:",
10431 })
10432
10433 testCases = append(testCases, testCase{
10434 testType: serverTest,
10435 name: "SecondClientHelloWrongCurve",
10436 config: Config{
10437 MaxVersion: VersionTLS13,
10438 DefaultCurves: []CurveID{},
10439 Bugs: ProtocolBugs{
10440 MisinterpretHelloRetryRequestCurve: CurveP521,
10441 },
10442 },
10443 shouldFail: true,
10444 expectedError: ":WRONG_CURVE:",
10445 })
10446
10447 testCases = append(testCases, testCase{
10448 name: "HelloRetryRequestVersionMismatch",
10449 config: Config{
10450 MaxVersion: VersionTLS13,
10451 // P-384 requires HelloRetryRequest in BoringSSL.
10452 CurvePreferences: []CurveID{CurveP384},
10453 Bugs: ProtocolBugs{
10454 SendServerHelloVersion: 0x0305,
10455 },
10456 },
10457 shouldFail: true,
10458 expectedError: ":WRONG_VERSION_NUMBER:",
10459 })
10460
10461 testCases = append(testCases, testCase{
10462 name: "HelloRetryRequestCurveMismatch",
10463 config: Config{
10464 MaxVersion: VersionTLS13,
10465 // P-384 requires HelloRetryRequest in BoringSSL.
10466 CurvePreferences: []CurveID{CurveP384},
10467 Bugs: ProtocolBugs{
10468 // Send P-384 (correct) in the HelloRetryRequest.
10469 SendHelloRetryRequestCurve: CurveP384,
10470 // But send P-256 in the ServerHello.
10471 SendCurve: CurveP256,
10472 },
10473 },
10474 shouldFail: true,
10475 expectedError: ":WRONG_CURVE:",
10476 })
10477
10478 // Test the server selecting a curve that requires a HelloRetryRequest
10479 // without sending it.
10480 testCases = append(testCases, testCase{
10481 name: "SkipHelloRetryRequest",
10482 config: Config{
10483 MaxVersion: VersionTLS13,
10484 // P-384 requires HelloRetryRequest in BoringSSL.
10485 CurvePreferences: []CurveID{CurveP384},
10486 Bugs: ProtocolBugs{
10487 SkipHelloRetryRequest: true,
10488 },
10489 },
10490 shouldFail: true,
10491 expectedError: ":WRONG_CURVE:",
10492 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010493
10494 testCases = append(testCases, testCase{
10495 name: "TLS13-RequestContextInHandshake",
10496 config: Config{
10497 MaxVersion: VersionTLS13,
10498 MinVersion: VersionTLS13,
10499 ClientAuth: RequireAnyClientCert,
10500 Bugs: ProtocolBugs{
10501 SendRequestContext: []byte("request context"),
10502 },
10503 },
10504 flags: []string{
10505 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10506 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10507 },
10508 shouldFail: true,
10509 expectedError: ":DECODE_ERROR:",
10510 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010511
10512 testCases = append(testCases, testCase{
10513 testType: serverTest,
10514 name: "TLS13-TrailingKeyShareData",
10515 config: Config{
10516 MaxVersion: VersionTLS13,
10517 Bugs: ProtocolBugs{
10518 TrailingKeyShareData: true,
10519 },
10520 },
10521 shouldFail: true,
10522 expectedError: ":DECODE_ERROR:",
10523 })
David Benjamin7f78df42016-10-05 22:33:19 -040010524
10525 testCases = append(testCases, testCase{
10526 name: "TLS13-AlwaysSelectPSKIdentity",
10527 config: Config{
10528 MaxVersion: VersionTLS13,
10529 Bugs: ProtocolBugs{
10530 AlwaysSelectPSKIdentity: true,
10531 },
10532 },
10533 shouldFail: true,
10534 expectedError: ":UNEXPECTED_EXTENSION:",
10535 })
10536
10537 testCases = append(testCases, testCase{
10538 name: "TLS13-InvalidPSKIdentity",
10539 config: Config{
10540 MaxVersion: VersionTLS13,
10541 Bugs: ProtocolBugs{
10542 SelectPSKIdentityOnResume: 1,
10543 },
10544 },
10545 resumeSession: true,
10546 shouldFail: true,
10547 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10548 })
David Benjamin1286bee2016-10-07 15:25:06 -040010549
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010550 testCases = append(testCases, testCase{
10551 testType: serverTest,
10552 name: "TLS13-ExtraPSKIdentity",
10553 config: Config{
10554 MaxVersion: VersionTLS13,
10555 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010556 ExtraPSKIdentity: true,
10557 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010558 },
10559 },
10560 resumeSession: true,
10561 })
10562
David Benjamin1286bee2016-10-07 15:25:06 -040010563 // Test that unknown NewSessionTicket extensions are tolerated.
10564 testCases = append(testCases, testCase{
10565 name: "TLS13-CustomTicketExtension",
10566 config: Config{
10567 MaxVersion: VersionTLS13,
10568 Bugs: ProtocolBugs{
10569 CustomTicketExtension: "1234",
10570 },
10571 },
10572 })
Steven Valdez2d850622017-01-11 11:34:52 -050010573
Steven Valdez2d850622017-01-11 11:34:52 -050010574 testCases = append(testCases, testCase{
10575 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010576 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010577 config: Config{
10578 MaxVersion: VersionTLS13,
10579 MaxEarlyDataSize: 16384,
10580 },
10581 resumeConfig: &Config{
10582 MaxVersion: VersionTLS13,
10583 MaxEarlyDataSize: 16384,
10584 Bugs: ProtocolBugs{
10585 AlwaysRejectEarlyData: true,
10586 },
10587 },
10588 resumeSession: true,
10589 flags: []string{
10590 "-enable-early-data",
10591 "-expect-early-data-info",
10592 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010593 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010594 },
10595 })
10596
10597 testCases = append(testCases, testCase{
10598 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010599 name: "TLS13-EarlyData-RejectTicket-Client",
10600 config: Config{
10601 MaxVersion: VersionTLS13,
10602 MaxEarlyDataSize: 16384,
10603 Certificates: []Certificate{rsaCertificate},
10604 },
10605 resumeConfig: &Config{
10606 MaxVersion: VersionTLS13,
10607 MaxEarlyDataSize: 16384,
10608 Certificates: []Certificate{ecdsaP256Certificate},
10609 SessionTicketsDisabled: true,
10610 },
10611 resumeSession: true,
10612 expectResumeRejected: true,
10613 flags: []string{
10614 "-enable-early-data",
10615 "-expect-early-data-info",
10616 "-expect-reject-early-data",
10617 "-on-resume-shim-writes-first",
10618 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10619 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10620 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10621 // Session tickets are disabled, so the runner will not send a ticket.
10622 "-on-retry-expect-no-session",
10623 },
10624 })
10625
10626 testCases = append(testCases, testCase{
10627 testType: clientTest,
10628 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010629 config: Config{
10630 MaxVersion: VersionTLS13,
10631 MaxEarlyDataSize: 16384,
10632 },
10633 resumeConfig: &Config{
10634 MaxVersion: VersionTLS13,
10635 MaxEarlyDataSize: 16384,
10636 Bugs: ProtocolBugs{
10637 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10638 },
10639 },
10640 resumeSession: true,
10641 flags: []string{
10642 "-enable-early-data",
10643 "-expect-early-data-info",
10644 "-expect-reject-early-data",
10645 },
10646 })
10647
10648 // The client must check the server does not send the early_data
10649 // extension while rejecting the session.
10650 testCases = append(testCases, testCase{
10651 testType: clientTest,
10652 name: "TLS13-EarlyDataWithoutResume-Client",
10653 config: Config{
10654 MaxVersion: VersionTLS13,
10655 MaxEarlyDataSize: 16384,
10656 },
10657 resumeConfig: &Config{
10658 MaxVersion: VersionTLS13,
10659 SessionTicketsDisabled: true,
10660 Bugs: ProtocolBugs{
10661 SendEarlyDataExtension: true,
10662 },
10663 },
10664 resumeSession: true,
10665 flags: []string{
10666 "-enable-early-data",
10667 "-expect-early-data-info",
10668 },
10669 shouldFail: true,
10670 expectedError: ":UNEXPECTED_EXTENSION:",
10671 })
10672
10673 // The client must fail with a dedicated error code if the server
10674 // responds with TLS 1.2 when offering 0-RTT.
10675 testCases = append(testCases, testCase{
10676 testType: clientTest,
10677 name: "TLS13-EarlyDataVersionDowngrade-Client",
10678 config: Config{
10679 MaxVersion: VersionTLS13,
10680 MaxEarlyDataSize: 16384,
10681 },
10682 resumeConfig: &Config{
10683 MaxVersion: VersionTLS12,
10684 },
10685 resumeSession: true,
10686 flags: []string{
10687 "-enable-early-data",
10688 "-expect-early-data-info",
10689 },
10690 shouldFail: true,
10691 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10692 })
10693
10694 // Test that the client rejects an (unsolicited) early_data extension if
10695 // the server sent an HRR.
10696 testCases = append(testCases, testCase{
10697 testType: clientTest,
10698 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10699 config: Config{
10700 MaxVersion: VersionTLS13,
10701 MaxEarlyDataSize: 16384,
10702 },
10703 resumeConfig: &Config{
10704 MaxVersion: VersionTLS13,
10705 MaxEarlyDataSize: 16384,
10706 Bugs: ProtocolBugs{
10707 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10708 SendEarlyDataExtension: true,
10709 },
10710 },
10711 resumeSession: true,
10712 flags: []string{
10713 "-enable-early-data",
10714 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010715 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010716 },
10717 shouldFail: true,
10718 expectedError: ":UNEXPECTED_EXTENSION:",
10719 })
10720
10721 fooString := "foo"
10722 barString := "bar"
10723
10724 // Test that the client reports the correct ALPN after a 0-RTT reject
10725 // that changed it.
10726 testCases = append(testCases, testCase{
10727 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010728 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010729 config: Config{
10730 MaxVersion: VersionTLS13,
10731 MaxEarlyDataSize: 16384,
10732 Bugs: ProtocolBugs{
10733 ALPNProtocol: &fooString,
10734 },
10735 },
10736 resumeConfig: &Config{
10737 MaxVersion: VersionTLS13,
10738 MaxEarlyDataSize: 16384,
10739 Bugs: ProtocolBugs{
10740 ALPNProtocol: &barString,
10741 },
10742 },
10743 resumeSession: true,
10744 flags: []string{
10745 "-advertise-alpn", "\x03foo\x03bar",
10746 "-enable-early-data",
10747 "-expect-early-data-info",
10748 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010749 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010750 "-on-resume-expect-alpn", "foo",
10751 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010752 },
10753 })
10754
10755 // Test that the client reports the correct ALPN after a 0-RTT reject if
10756 // ALPN was omitted from the first connection.
10757 testCases = append(testCases, testCase{
10758 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010759 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010760 config: Config{
10761 MaxVersion: VersionTLS13,
10762 MaxEarlyDataSize: 16384,
10763 },
10764 resumeConfig: &Config{
10765 MaxVersion: VersionTLS13,
10766 MaxEarlyDataSize: 16384,
10767 NextProtos: []string{"foo"},
10768 },
10769 resumeSession: true,
10770 flags: []string{
10771 "-advertise-alpn", "\x03foo\x03bar",
10772 "-enable-early-data",
10773 "-expect-early-data-info",
10774 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010775 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010776 "-on-resume-expect-alpn", "",
10777 "-on-retry-expect-alpn", "foo",
10778 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010779 },
10780 })
10781
10782 // Test that the client reports the correct ALPN after a 0-RTT reject if
10783 // ALPN was omitted from the second connection.
10784 testCases = append(testCases, testCase{
10785 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010786 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010787 config: Config{
10788 MaxVersion: VersionTLS13,
10789 MaxEarlyDataSize: 16384,
10790 NextProtos: []string{"foo"},
10791 },
10792 resumeConfig: &Config{
10793 MaxVersion: VersionTLS13,
10794 MaxEarlyDataSize: 16384,
10795 },
10796 resumeSession: true,
10797 flags: []string{
10798 "-advertise-alpn", "\x03foo\x03bar",
10799 "-enable-early-data",
10800 "-expect-early-data-info",
10801 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010802 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010803 "-on-resume-expect-alpn", "foo",
10804 "-on-retry-expect-alpn", "",
10805 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010806 },
10807 })
10808
10809 // Test that the client enforces ALPN match on 0-RTT accept.
10810 testCases = append(testCases, testCase{
10811 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010812 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010813 config: Config{
10814 MaxVersion: VersionTLS13,
10815 MaxEarlyDataSize: 16384,
10816 Bugs: ProtocolBugs{
10817 ALPNProtocol: &fooString,
10818 },
10819 },
10820 resumeConfig: &Config{
10821 MaxVersion: VersionTLS13,
10822 MaxEarlyDataSize: 16384,
10823 Bugs: ProtocolBugs{
10824 AlwaysAcceptEarlyData: true,
10825 ALPNProtocol: &barString,
10826 },
10827 },
10828 resumeSession: true,
10829 flags: []string{
10830 "-advertise-alpn", "\x03foo\x03bar",
10831 "-enable-early-data",
10832 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010833 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010834 "-on-resume-expect-alpn", "foo",
10835 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010836 },
10837 shouldFail: true,
10838 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10839 })
10840
10841 // Test that the server correctly rejects 0-RTT when the previous
10842 // session did not allow early data on resumption.
10843 testCases = append(testCases, testCase{
10844 testType: serverTest,
10845 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10846 config: Config{
10847 MaxVersion: VersionTLS13,
10848 },
10849 resumeConfig: &Config{
10850 MaxVersion: VersionTLS13,
10851 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010852 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010853 ExpectEarlyDataAccepted: false,
10854 },
10855 },
10856 resumeSession: true,
10857 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010858 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010859 "-expect-reject-early-data",
10860 },
10861 })
10862
10863 // Test that we reject early data where ALPN is omitted from the first
10864 // connection.
10865 testCases = append(testCases, testCase{
10866 testType: serverTest,
10867 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10868 config: Config{
10869 MaxVersion: VersionTLS13,
10870 NextProtos: []string{},
10871 },
10872 resumeConfig: &Config{
10873 MaxVersion: VersionTLS13,
10874 NextProtos: []string{"foo"},
10875 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010876 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010877 ExpectEarlyDataAccepted: false,
10878 },
10879 },
10880 resumeSession: true,
10881 flags: []string{
10882 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010883 "-on-initial-select-alpn", "",
10884 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010885 },
10886 })
10887
10888 // Test that we reject early data where ALPN is omitted from the second
10889 // connection.
10890 testCases = append(testCases, testCase{
10891 testType: serverTest,
10892 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10893 config: Config{
10894 MaxVersion: VersionTLS13,
10895 NextProtos: []string{"foo"},
10896 },
10897 resumeConfig: &Config{
10898 MaxVersion: VersionTLS13,
10899 NextProtos: []string{},
10900 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010901 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010902 ExpectEarlyDataAccepted: false,
10903 },
10904 },
10905 resumeSession: true,
10906 flags: []string{
10907 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010908 "-on-initial-select-alpn", "foo",
10909 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010910 },
10911 })
10912
10913 // Test that we reject early data with mismatched ALPN.
10914 testCases = append(testCases, testCase{
10915 testType: serverTest,
10916 name: "TLS13-EarlyData-ALPNMismatch-Server",
10917 config: Config{
10918 MaxVersion: VersionTLS13,
10919 NextProtos: []string{"foo"},
10920 },
10921 resumeConfig: &Config{
10922 MaxVersion: VersionTLS13,
10923 NextProtos: []string{"bar"},
10924 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010925 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010926 ExpectEarlyDataAccepted: false,
10927 },
10928 },
10929 resumeSession: true,
10930 flags: []string{
10931 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010932 "-on-initial-select-alpn", "foo",
10933 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010934 },
10935 })
10936
David Benjamin6bb507b2017-03-29 16:35:57 -050010937 // Test that the client offering 0-RTT and Channel ID forbids the server
10938 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010939 testCases = append(testCases, testCase{
10940 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010941 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010942 config: Config{
10943 MaxVersion: VersionTLS13,
10944 MaxEarlyDataSize: 16384,
10945 RequestChannelID: true,
10946 },
10947 resumeSession: true,
10948 expectChannelID: true,
10949 shouldFail: true,
10950 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10951 flags: []string{
10952 "-enable-early-data",
10953 "-expect-early-data-info",
10954 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10955 },
10956 })
10957
David Benjamin6bb507b2017-03-29 16:35:57 -050010958 // Test that the client offering Channel ID and 0-RTT allows the server
10959 // to decline 0-RTT.
10960 testCases = append(testCases, testCase{
10961 testType: clientTest,
10962 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10963 config: Config{
10964 MaxVersion: VersionTLS13,
10965 MaxEarlyDataSize: 16384,
10966 RequestChannelID: true,
10967 Bugs: ProtocolBugs{
10968 AlwaysRejectEarlyData: true,
10969 },
10970 },
10971 resumeSession: true,
10972 expectChannelID: true,
10973 flags: []string{
10974 "-enable-early-data",
10975 "-expect-early-data-info",
10976 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10977 "-expect-reject-early-data",
10978 },
10979 })
10980
10981 // Test that the client offering Channel ID and 0-RTT allows the server
10982 // to decline Channel ID.
10983 testCases = append(testCases, testCase{
10984 testType: clientTest,
10985 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10986 config: Config{
10987 MaxVersion: VersionTLS13,
10988 MaxEarlyDataSize: 16384,
10989 },
10990 resumeSession: true,
10991 flags: []string{
10992 "-enable-early-data",
10993 "-expect-early-data-info",
10994 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10995 "-expect-accept-early-data",
10996 },
10997 })
10998
10999 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11000 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011001 testCases = append(testCases, testCase{
11002 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011003 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011004 config: Config{
11005 MaxVersion: VersionTLS13,
11006 ChannelID: channelIDKey,
11007 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011008 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011009 ExpectEarlyDataAccepted: false,
11010 },
11011 },
11012 resumeSession: true,
11013 expectChannelID: true,
11014 flags: []string{
11015 "-enable-early-data",
11016 "-expect-reject-early-data",
11017 "-expect-channel-id",
11018 base64.StdEncoding.EncodeToString(channelIDBytes),
11019 },
11020 })
11021
David Benjamin6bb507b2017-03-29 16:35:57 -050011022 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11023 // if not offered Channel ID.
11024 testCases = append(testCases, testCase{
11025 testType: serverTest,
11026 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11027 config: Config{
11028 MaxVersion: VersionTLS13,
11029 Bugs: ProtocolBugs{
11030 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11031 ExpectEarlyDataAccepted: true,
11032 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11033 },
11034 },
11035 resumeSession: true,
11036 expectChannelID: false,
11037 flags: []string{
11038 "-enable-early-data",
11039 "-expect-accept-early-data",
11040 "-enable-channel-id",
11041 },
11042 })
11043
David Benjamin32c89272017-03-26 13:54:21 -050011044 // Test that the server rejects 0-RTT streams without end_of_early_data.
11045 // The subsequent records should fail to decrypt.
11046 testCases = append(testCases, testCase{
11047 testType: serverTest,
11048 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11049 config: Config{
11050 MaxVersion: VersionTLS13,
11051 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011052 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011053 ExpectEarlyDataAccepted: true,
11054 SkipEndOfEarlyData: true,
11055 },
11056 },
11057 resumeSession: true,
11058 flags: []string{"-enable-early-data"},
11059 shouldFail: true,
11060 expectedLocalError: "remote error: bad record MAC",
11061 expectedError: ":BAD_DECRYPT:",
11062 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011063
11064 testCases = append(testCases, testCase{
11065 testType: serverTest,
11066 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11067 config: Config{
11068 MaxVersion: VersionTLS13,
11069 },
11070 resumeConfig: &Config{
11071 MaxVersion: VersionTLS13,
11072 Bugs: ProtocolBugs{
11073 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11074 SendStrayEarlyHandshake: true,
11075 ExpectEarlyDataAccepted: true},
11076 },
11077 resumeSession: true,
11078 shouldFail: true,
11079 expectedError: ":UNEXPECTED_RECORD:",
11080 expectedLocalError: "remote error: unexpected message",
11081 flags: []string{
11082 "-enable-early-data",
11083 },
11084 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011085}
11086
David Benjaminabbbee12016-10-31 19:20:42 -040011087func addTLS13CipherPreferenceTests() {
11088 // Test that client preference is honored if the shim has AES hardware
11089 // and ChaCha20-Poly1305 is preferred otherwise.
11090 testCases = append(testCases, testCase{
11091 testType: serverTest,
11092 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11093 config: Config{
11094 MaxVersion: VersionTLS13,
11095 CipherSuites: []uint16{
11096 TLS_CHACHA20_POLY1305_SHA256,
11097 TLS_AES_128_GCM_SHA256,
11098 },
11099 },
11100 flags: []string{
11101 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11102 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11103 },
11104 })
11105
11106 testCases = append(testCases, testCase{
11107 testType: serverTest,
11108 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11109 config: Config{
11110 MaxVersion: VersionTLS13,
11111 CipherSuites: []uint16{
11112 TLS_AES_128_GCM_SHA256,
11113 TLS_CHACHA20_POLY1305_SHA256,
11114 },
11115 },
11116 flags: []string{
11117 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11118 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11119 },
11120 })
11121
11122 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11123 // whether it has AES hardware.
11124 testCases = append(testCases, testCase{
11125 name: "TLS13-CipherPreference-Client",
11126 config: Config{
11127 MaxVersion: VersionTLS13,
11128 // Use the client cipher order. (This is the default but
11129 // is listed to be explicit.)
11130 PreferServerCipherSuites: false,
11131 },
11132 flags: []string{
11133 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11134 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11135 },
11136 })
11137}
11138
David Benjaminf3fbade2016-09-19 13:08:16 -040011139func addPeekTests() {
11140 // Test SSL_peek works, including on empty records.
11141 testCases = append(testCases, testCase{
11142 name: "Peek-Basic",
11143 sendEmptyRecords: 1,
11144 flags: []string{"-peek-then-read"},
11145 })
11146
11147 // Test SSL_peek can drive the initial handshake.
11148 testCases = append(testCases, testCase{
11149 name: "Peek-ImplicitHandshake",
11150 flags: []string{
11151 "-peek-then-read",
11152 "-implicit-handshake",
11153 },
11154 })
11155
11156 // Test SSL_peek can discover and drive a renegotiation.
11157 testCases = append(testCases, testCase{
11158 name: "Peek-Renegotiate",
11159 config: Config{
11160 MaxVersion: VersionTLS12,
11161 },
11162 renegotiate: 1,
11163 flags: []string{
11164 "-peek-then-read",
11165 "-renegotiate-freely",
11166 "-expect-total-renegotiations", "1",
11167 },
11168 })
11169
11170 // Test SSL_peek can discover a close_notify.
11171 testCases = append(testCases, testCase{
11172 name: "Peek-Shutdown",
11173 config: Config{
11174 Bugs: ProtocolBugs{
11175 ExpectCloseNotify: true,
11176 },
11177 },
11178 flags: []string{
11179 "-peek-then-read",
11180 "-check-close-notify",
11181 },
11182 })
11183
11184 // Test SSL_peek can discover an alert.
11185 testCases = append(testCases, testCase{
11186 name: "Peek-Alert",
11187 config: Config{
11188 Bugs: ProtocolBugs{
11189 SendSpuriousAlert: alertRecordOverflow,
11190 },
11191 },
11192 flags: []string{"-peek-then-read"},
11193 shouldFail: true,
11194 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11195 })
11196
11197 // Test SSL_peek can handle KeyUpdate.
11198 testCases = append(testCases, testCase{
11199 name: "Peek-KeyUpdate",
11200 config: Config{
11201 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011202 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011203 sendKeyUpdates: 1,
11204 keyUpdateRequest: keyUpdateNotRequested,
11205 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011206 })
11207}
11208
David Benjamine6f22212016-11-08 14:28:24 -050011209func addRecordVersionTests() {
11210 for _, ver := range tlsVersions {
11211 // Test that the record version is enforced.
11212 testCases = append(testCases, testCase{
11213 name: "CheckRecordVersion-" + ver.name,
11214 config: Config{
11215 MinVersion: ver.version,
11216 MaxVersion: ver.version,
11217 Bugs: ProtocolBugs{
11218 SendRecordVersion: 0x03ff,
11219 },
11220 },
11221 shouldFail: true,
11222 expectedError: ":WRONG_VERSION_NUMBER:",
11223 })
11224
11225 // Test that the ClientHello may use any record version, for
11226 // compatibility reasons.
11227 testCases = append(testCases, testCase{
11228 testType: serverTest,
11229 name: "LooseInitialRecordVersion-" + ver.name,
11230 config: Config{
11231 MinVersion: ver.version,
11232 MaxVersion: ver.version,
11233 Bugs: ProtocolBugs{
11234 SendInitialRecordVersion: 0x03ff,
11235 },
11236 },
11237 })
11238
11239 // Test that garbage ClientHello record versions are rejected.
11240 testCases = append(testCases, testCase{
11241 testType: serverTest,
11242 name: "GarbageInitialRecordVersion-" + ver.name,
11243 config: Config{
11244 MinVersion: ver.version,
11245 MaxVersion: ver.version,
11246 Bugs: ProtocolBugs{
11247 SendInitialRecordVersion: 0xffff,
11248 },
11249 },
11250 shouldFail: true,
11251 expectedError: ":WRONG_VERSION_NUMBER:",
11252 })
11253 }
11254}
11255
David Benjamin2c516452016-11-15 10:16:54 +090011256func addCertificateTests() {
11257 // Test that a certificate chain with intermediate may be sent and
11258 // received as both client and server.
11259 for _, ver := range tlsVersions {
11260 testCases = append(testCases, testCase{
11261 testType: clientTest,
11262 name: "SendReceiveIntermediate-Client-" + ver.name,
11263 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011264 MinVersion: ver.version,
11265 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011266 Certificates: []Certificate{rsaChainCertificate},
11267 ClientAuth: RequireAnyClientCert,
11268 },
11269 expectPeerCertificate: &rsaChainCertificate,
11270 flags: []string{
11271 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11272 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11273 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11274 },
11275 })
11276
11277 testCases = append(testCases, testCase{
11278 testType: serverTest,
11279 name: "SendReceiveIntermediate-Server-" + ver.name,
11280 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011281 MinVersion: ver.version,
11282 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011283 Certificates: []Certificate{rsaChainCertificate},
11284 },
11285 expectPeerCertificate: &rsaChainCertificate,
11286 flags: []string{
11287 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11288 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11289 "-require-any-client-certificate",
11290 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11291 },
11292 })
11293 }
11294}
11295
David Benjaminbbaf3672016-11-17 10:53:09 +090011296func addRetainOnlySHA256ClientCertTests() {
11297 for _, ver := range tlsVersions {
11298 // Test that enabling
11299 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11300 // actually requesting a client certificate is a no-op.
11301 testCases = append(testCases, testCase{
11302 testType: serverTest,
11303 name: "RetainOnlySHA256-NoCert-" + ver.name,
11304 config: Config{
11305 MinVersion: ver.version,
11306 MaxVersion: ver.version,
11307 },
11308 flags: []string{
11309 "-retain-only-sha256-client-cert-initial",
11310 "-retain-only-sha256-client-cert-resume",
11311 },
11312 resumeSession: true,
11313 })
11314
11315 // Test that when retaining only a SHA-256 certificate is
11316 // enabled, the hash appears as expected.
11317 testCases = append(testCases, testCase{
11318 testType: serverTest,
11319 name: "RetainOnlySHA256-Cert-" + ver.name,
11320 config: Config{
11321 MinVersion: ver.version,
11322 MaxVersion: ver.version,
11323 Certificates: []Certificate{rsaCertificate},
11324 },
11325 flags: []string{
11326 "-verify-peer",
11327 "-retain-only-sha256-client-cert-initial",
11328 "-retain-only-sha256-client-cert-resume",
11329 "-expect-sha256-client-cert-initial",
11330 "-expect-sha256-client-cert-resume",
11331 },
11332 resumeSession: true,
11333 })
11334
11335 // Test that when the config changes from on to off, a
11336 // resumption is rejected because the server now wants the full
11337 // certificate chain.
11338 testCases = append(testCases, testCase{
11339 testType: serverTest,
11340 name: "RetainOnlySHA256-OnOff-" + ver.name,
11341 config: Config{
11342 MinVersion: ver.version,
11343 MaxVersion: ver.version,
11344 Certificates: []Certificate{rsaCertificate},
11345 },
11346 flags: []string{
11347 "-verify-peer",
11348 "-retain-only-sha256-client-cert-initial",
11349 "-expect-sha256-client-cert-initial",
11350 },
11351 resumeSession: true,
11352 expectResumeRejected: true,
11353 })
11354
11355 // Test that when the config changes from off to on, a
11356 // resumption is rejected because the server now wants just the
11357 // hash.
11358 testCases = append(testCases, testCase{
11359 testType: serverTest,
11360 name: "RetainOnlySHA256-OffOn-" + ver.name,
11361 config: Config{
11362 MinVersion: ver.version,
11363 MaxVersion: ver.version,
11364 Certificates: []Certificate{rsaCertificate},
11365 },
11366 flags: []string{
11367 "-verify-peer",
11368 "-retain-only-sha256-client-cert-resume",
11369 "-expect-sha256-client-cert-resume",
11370 },
11371 resumeSession: true,
11372 expectResumeRejected: true,
11373 })
11374 }
11375}
11376
Adam Langleya4b91982016-12-12 12:05:53 -080011377func addECDSAKeyUsageTests() {
11378 p256 := elliptic.P256()
11379 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11380 if err != nil {
11381 panic(err)
11382 }
11383
11384 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11385 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11386 if err != nil {
11387 panic(err)
11388 }
11389
11390 template := x509.Certificate{
11391 SerialNumber: serialNumber,
11392 Subject: pkix.Name{
11393 Organization: []string{"Acme Co"},
11394 },
11395 NotBefore: time.Now(),
11396 NotAfter: time.Now(),
11397
11398 // An ECC certificate with only the keyAgreement key usgae may
11399 // be used with ECDH, but not ECDSA.
11400 KeyUsage: x509.KeyUsageKeyAgreement,
11401 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11402 BasicConstraintsValid: true,
11403 }
11404
11405 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11406 if err != nil {
11407 panic(err)
11408 }
11409
11410 cert := Certificate{
11411 Certificate: [][]byte{derBytes},
11412 PrivateKey: priv,
11413 }
11414
11415 for _, ver := range tlsVersions {
11416 if ver.version < VersionTLS12 {
11417 continue
11418 }
11419
11420 testCases = append(testCases, testCase{
11421 testType: clientTest,
11422 name: "ECDSAKeyUsage-" + ver.name,
11423 config: Config{
11424 MinVersion: ver.version,
11425 MaxVersion: ver.version,
11426 Certificates: []Certificate{cert},
11427 },
11428 shouldFail: true,
11429 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11430 })
11431 }
11432}
11433
David Benjamin8c26d752017-03-26 15:13:51 -050011434func addExtraHandshakeTests() {
11435 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11436 // to ensure there is no transport I/O.
11437 testCases = append(testCases, testCase{
11438 testType: clientTest,
11439 name: "ExtraHandshake-Client-TLS12",
11440 config: Config{
11441 MinVersion: VersionTLS12,
11442 MaxVersion: VersionTLS12,
11443 },
11444 flags: []string{
11445 "-async",
11446 "-no-op-extra-handshake",
11447 },
11448 })
11449 testCases = append(testCases, testCase{
11450 testType: serverTest,
11451 name: "ExtraHandshake-Server-TLS12",
11452 config: Config{
11453 MinVersion: VersionTLS12,
11454 MaxVersion: VersionTLS12,
11455 },
11456 flags: []string{
11457 "-async",
11458 "-no-op-extra-handshake",
11459 },
11460 })
11461 testCases = append(testCases, testCase{
11462 testType: clientTest,
11463 name: "ExtraHandshake-Client-TLS13",
11464 config: Config{
11465 MinVersion: VersionTLS13,
11466 MaxVersion: VersionTLS13,
11467 },
11468 flags: []string{
11469 "-async",
11470 "-no-op-extra-handshake",
11471 },
11472 })
11473 testCases = append(testCases, testCase{
11474 testType: serverTest,
11475 name: "ExtraHandshake-Server-TLS13",
11476 config: Config{
11477 MinVersion: VersionTLS13,
11478 MaxVersion: VersionTLS13,
11479 },
11480 flags: []string{
11481 "-async",
11482 "-no-op-extra-handshake",
11483 },
11484 })
11485
11486 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11487 testCases = append(testCases, testCase{
11488 testType: serverTest,
11489 name: "ExtraHandshake-Server-EarlyData-TLS13",
11490 config: Config{
11491 MaxVersion: VersionTLS13,
11492 MinVersion: VersionTLS13,
11493 Bugs: ProtocolBugs{
11494 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11495 ExpectEarlyDataAccepted: true,
11496 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11497 },
11498 },
11499 messageCount: 2,
11500 resumeSession: true,
11501 flags: []string{
11502 "-async",
11503 "-enable-early-data",
11504 "-expect-accept-early-data",
11505 "-no-op-extra-handshake",
11506 },
11507 })
11508
11509 // An extra SSL_do_handshake drives the handshake to completion in False
11510 // Start. We test this by handshaking twice and asserting the False
11511 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11512 // how the test works.
11513 testCases = append(testCases, testCase{
11514 testType: clientTest,
11515 name: "ExtraHandshake-FalseStart",
11516 config: Config{
11517 MaxVersion: VersionTLS12,
11518 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11519 NextProtos: []string{"foo"},
11520 Bugs: ProtocolBugs{
11521 ExpectFalseStart: true,
11522 AlertBeforeFalseStartTest: alertAccessDenied,
11523 },
11524 },
11525 flags: []string{
11526 "-handshake-twice",
11527 "-false-start",
11528 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011529 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011530 },
11531 shimWritesFirst: true,
11532 shouldFail: true,
11533 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11534 expectedLocalError: "tls: peer did not false start: EOF",
11535 })
11536}
11537
Adam Langley7c803a62015-06-15 15:35:05 -070011538func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011539 defer wg.Done()
11540
11541 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011542 var err error
11543
David Benjaminba28dfc2016-11-15 17:47:21 +090011544 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011545 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11546 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011547 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011548 if err != nil {
11549 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11550 }
11551 break
11552 }
11553 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011554 } else if *repeatUntilFailure {
11555 for err == nil {
11556 statusChan <- statusMsg{test: test, started: true}
11557 err = runTest(test, shimPath, -1)
11558 }
11559 } else {
11560 statusChan <- statusMsg{test: test, started: true}
11561 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011562 }
Adam Langley95c29f32014-06-20 12:00:00 -070011563 statusChan <- statusMsg{test: test, err: err}
11564 }
11565}
11566
11567type statusMsg struct {
11568 test *testCase
11569 started bool
11570 err error
11571}
11572
David Benjamin5f237bc2015-02-11 17:14:15 -050011573func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011574 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011575
David Benjamin5f237bc2015-02-11 17:14:15 -050011576 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011577 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011578 if !*pipe {
11579 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011580 var erase string
11581 for i := 0; i < lineLen; i++ {
11582 erase += "\b \b"
11583 }
11584 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011585 }
11586
Adam Langley95c29f32014-06-20 12:00:00 -070011587 if msg.started {
11588 started++
11589 } else {
11590 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011591
11592 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011593 if msg.err == errUnimplemented {
11594 if *pipe {
11595 // Print each test instead of a status line.
11596 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11597 }
11598 unimplemented++
11599 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11600 } else {
11601 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11602 failed++
11603 testOutput.addResult(msg.test.name, "FAIL")
11604 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011605 } else {
11606 if *pipe {
11607 // Print each test instead of a status line.
11608 fmt.Printf("PASSED (%s)\n", msg.test.name)
11609 }
11610 testOutput.addResult(msg.test.name, "PASS")
11611 }
Adam Langley95c29f32014-06-20 12:00:00 -070011612 }
11613
David Benjamin5f237bc2015-02-11 17:14:15 -050011614 if !*pipe {
11615 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011616 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011617 lineLen = len(line)
11618 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011619 }
Adam Langley95c29f32014-06-20 12:00:00 -070011620 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011621
11622 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011623}
11624
11625func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011626 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011627 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011628 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011629
Adam Langley7c803a62015-06-15 15:35:05 -070011630 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011631 addCipherSuiteTests()
11632 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011633 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011634 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011635 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011636 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011637 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011638 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011639 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011640 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011641 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011642 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011643 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011644 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011645 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011646 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011647 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011648 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011649 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011650 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011651 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011652 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011653 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011654 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011655 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011656 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011657 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011658 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011659 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011660 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011661 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011662 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011663 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011664 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011665
11666 var wg sync.WaitGroup
11667
Adam Langley7c803a62015-06-15 15:35:05 -070011668 statusChan := make(chan statusMsg, *numWorkers)
11669 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011670 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011671
EKRf71d7ed2016-08-06 13:25:12 -070011672 if len(*shimConfigFile) != 0 {
11673 encoded, err := ioutil.ReadFile(*shimConfigFile)
11674 if err != nil {
11675 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11676 os.Exit(1)
11677 }
11678
11679 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11680 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11681 os.Exit(1)
11682 }
11683 }
11684
David Benjamin025b3d32014-07-01 19:53:04 -040011685 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011686
Adam Langley7c803a62015-06-15 15:35:05 -070011687 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011688 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011689 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011690 }
11691
David Benjamin270f0a72016-03-17 14:41:36 -040011692 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011693 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011694 matched := true
11695 if len(*testToRun) != 0 {
11696 var err error
11697 matched, err = filepath.Match(*testToRun, testCases[i].name)
11698 if err != nil {
11699 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11700 os.Exit(1)
11701 }
11702 }
11703
EKRf71d7ed2016-08-06 13:25:12 -070011704 if !*includeDisabled {
11705 for pattern := range shimConfig.DisabledTests {
11706 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11707 if err != nil {
11708 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11709 os.Exit(1)
11710 }
11711
11712 if isDisabled {
11713 matched = false
11714 break
11715 }
11716 }
11717 }
11718
David Benjamin17e12922016-07-28 18:04:43 -040011719 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011720 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011721 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011722
11723 // Only run one test if repeating until failure.
11724 if *repeatUntilFailure {
11725 break
11726 }
Adam Langley95c29f32014-06-20 12:00:00 -070011727 }
11728 }
David Benjamin17e12922016-07-28 18:04:43 -040011729
David Benjamin270f0a72016-03-17 14:41:36 -040011730 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011731 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011732 os.Exit(1)
11733 }
Adam Langley95c29f32014-06-20 12:00:00 -070011734
11735 close(testChan)
11736 wg.Wait()
11737 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011738 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011739
11740 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011741
11742 if *jsonOutput != "" {
11743 if err := testOutput.writeTo(*jsonOutput); err != nil {
11744 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11745 }
11746 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011747
EKR842ae6c2016-07-27 09:22:05 +020011748 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11749 os.Exit(1)
11750 }
11751
11752 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011753 os.Exit(1)
11754 }
Adam Langley95c29f32014-06-20 12:00:00 -070011755}