blob: 7c0175740a2468369ff48b2614dfd873d56afa22 [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 Benjamin65ac9972016-09-02 21:35:25 -04002511 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002512 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002513 config: Config{
2514 MaxVersion: VersionTLS12,
2515 Bugs: ProtocolBugs{
2516 ExpectGREASE: true,
2517 },
2518 },
2519 flags: []string{"-enable-grease"},
2520 },
2521 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002522 name: "GREASE-Client-TLS13",
2523 config: Config{
2524 MaxVersion: VersionTLS13,
2525 Bugs: ProtocolBugs{
2526 ExpectGREASE: true,
2527 },
2528 },
2529 flags: []string{"-enable-grease"},
2530 },
2531 {
2532 testType: serverTest,
2533 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002534 config: Config{
2535 MaxVersion: VersionTLS13,
2536 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002537 // TLS 1.3 servers are expected to
2538 // always enable GREASE. TLS 1.3 is new,
2539 // so there is no existing ecosystem to
2540 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002541 ExpectGREASE: true,
2542 },
2543 },
David Benjamin65ac9972016-09-02 21:35:25 -04002544 },
David Benjamine3fbb362017-01-06 16:19:28 -05002545 {
2546 // Test the server so there is a large certificate as
2547 // well as application data.
2548 testType: serverTest,
2549 name: "MaxSendFragment",
2550 config: Config{
2551 Bugs: ProtocolBugs{
2552 MaxReceivePlaintext: 512,
2553 },
2554 },
2555 messageLen: 1024,
2556 flags: []string{
2557 "-max-send-fragment", "512",
2558 "-read-size", "1024",
2559 },
2560 },
2561 {
2562 // Test the server so there is a large certificate as
2563 // well as application data.
2564 testType: serverTest,
2565 name: "MaxSendFragment-TooLarge",
2566 config: Config{
2567 Bugs: ProtocolBugs{
2568 // Ensure that some of the records are
2569 // 512.
2570 MaxReceivePlaintext: 511,
2571 },
2572 },
2573 messageLen: 1024,
2574 flags: []string{
2575 "-max-send-fragment", "512",
2576 "-read-size", "1024",
2577 },
2578 shouldFail: true,
2579 expectedLocalError: "local error: record overflow",
2580 },
Adam Langley7c803a62015-06-15 15:35:05 -07002581 }
Adam Langley7c803a62015-06-15 15:35:05 -07002582 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002583
2584 // Test that very large messages can be received.
2585 cert := rsaCertificate
2586 for i := 0; i < 50; i++ {
2587 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2588 }
2589 testCases = append(testCases, testCase{
2590 name: "LargeMessage",
2591 config: Config{
2592 Certificates: []Certificate{cert},
2593 },
2594 })
2595 testCases = append(testCases, testCase{
2596 protocol: dtls,
2597 name: "LargeMessage-DTLS",
2598 config: Config{
2599 Certificates: []Certificate{cert},
2600 },
2601 })
2602
2603 // They are rejected if the maximum certificate chain length is capped.
2604 testCases = append(testCases, testCase{
2605 name: "LargeMessage-Reject",
2606 config: Config{
2607 Certificates: []Certificate{cert},
2608 },
2609 flags: []string{"-max-cert-list", "16384"},
2610 shouldFail: true,
2611 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2612 })
2613 testCases = append(testCases, testCase{
2614 protocol: dtls,
2615 name: "LargeMessage-Reject-DTLS",
2616 config: Config{
2617 Certificates: []Certificate{cert},
2618 },
2619 flags: []string{"-max-cert-list", "16384"},
2620 shouldFail: true,
2621 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2622 })
Adam Langley7c803a62015-06-15 15:35:05 -07002623}
2624
David Benjaminaa012042016-12-10 13:33:05 -05002625func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2626 const psk = "12345"
2627 const pskIdentity = "luggage combo"
2628
2629 var prefix string
2630 if protocol == dtls {
2631 if !ver.hasDTLS {
2632 return
2633 }
2634 prefix = "D"
2635 }
2636
2637 var cert Certificate
2638 var certFile string
2639 var keyFile string
2640 if hasComponent(suite.name, "ECDSA") {
2641 cert = ecdsaP256Certificate
2642 certFile = ecdsaP256CertificateFile
2643 keyFile = ecdsaP256KeyFile
2644 } else {
2645 cert = rsaCertificate
2646 certFile = rsaCertificateFile
2647 keyFile = rsaKeyFile
2648 }
2649
2650 var flags []string
2651 if hasComponent(suite.name, "PSK") {
2652 flags = append(flags,
2653 "-psk", psk,
2654 "-psk-identity", pskIdentity)
2655 }
2656 if hasComponent(suite.name, "NULL") {
2657 // NULL ciphers must be explicitly enabled.
2658 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2659 }
David Benjaminaa012042016-12-10 13:33:05 -05002660
2661 var shouldServerFail, shouldClientFail bool
2662 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2663 // BoringSSL clients accept ECDHE on SSLv3, but
2664 // a BoringSSL server will never select it
2665 // because the extension is missing.
2666 shouldServerFail = true
2667 }
2668 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2669 shouldClientFail = true
2670 shouldServerFail = true
2671 }
2672 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2673 shouldClientFail = true
2674 shouldServerFail = true
2675 }
2676 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2677 shouldClientFail = true
2678 shouldServerFail = true
2679 }
2680 if !isDTLSCipher(suite.name) && protocol == dtls {
2681 shouldClientFail = true
2682 shouldServerFail = true
2683 }
2684
2685 var sendCipherSuite uint16
2686 var expectedServerError, expectedClientError string
2687 serverCipherSuites := []uint16{suite.id}
2688 if shouldServerFail {
2689 expectedServerError = ":NO_SHARED_CIPHER:"
2690 }
2691 if shouldClientFail {
2692 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2693 // Configure the server to select ciphers as normal but
2694 // select an incompatible cipher in ServerHello.
2695 serverCipherSuites = nil
2696 sendCipherSuite = suite.id
2697 }
2698
David Benjamincdb6fe92017-02-07 16:06:48 -05002699 // For cipher suites and versions where exporters are defined, verify
2700 // that they interoperate.
2701 var exportKeyingMaterial int
2702 if ver.version > VersionSSL30 {
2703 exportKeyingMaterial = 1024
2704 }
2705
David Benjaminaa012042016-12-10 13:33:05 -05002706 testCases = append(testCases, testCase{
2707 testType: serverTest,
2708 protocol: protocol,
2709 name: prefix + ver.name + "-" + suite.name + "-server",
2710 config: Config{
2711 MinVersion: ver.version,
2712 MaxVersion: ver.version,
2713 CipherSuites: []uint16{suite.id},
2714 Certificates: []Certificate{cert},
2715 PreSharedKey: []byte(psk),
2716 PreSharedKeyIdentity: pskIdentity,
2717 Bugs: ProtocolBugs{
2718 AdvertiseAllConfiguredCiphers: true,
2719 },
2720 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002721 certFile: certFile,
2722 keyFile: keyFile,
2723 flags: flags,
2724 resumeSession: true,
2725 shouldFail: shouldServerFail,
2726 expectedError: expectedServerError,
2727 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002728 })
2729
2730 testCases = append(testCases, testCase{
2731 testType: clientTest,
2732 protocol: protocol,
2733 name: prefix + ver.name + "-" + suite.name + "-client",
2734 config: Config{
2735 MinVersion: ver.version,
2736 MaxVersion: ver.version,
2737 CipherSuites: serverCipherSuites,
2738 Certificates: []Certificate{cert},
2739 PreSharedKey: []byte(psk),
2740 PreSharedKeyIdentity: pskIdentity,
2741 Bugs: ProtocolBugs{
2742 IgnorePeerCipherPreferences: shouldClientFail,
2743 SendCipherSuite: sendCipherSuite,
2744 },
2745 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002746 flags: flags,
2747 resumeSession: true,
2748 shouldFail: shouldClientFail,
2749 expectedError: expectedClientError,
2750 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002751 })
2752
David Benjamin6f600d62016-12-21 16:06:54 -05002753 if shouldClientFail {
2754 return
2755 }
2756
2757 // Ensure the maximum record size is accepted.
2758 testCases = append(testCases, testCase{
2759 protocol: protocol,
2760 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2761 config: Config{
2762 MinVersion: ver.version,
2763 MaxVersion: ver.version,
2764 CipherSuites: []uint16{suite.id},
2765 Certificates: []Certificate{cert},
2766 PreSharedKey: []byte(psk),
2767 PreSharedKeyIdentity: pskIdentity,
2768 },
2769 flags: flags,
2770 messageLen: maxPlaintext,
2771 })
2772
2773 // Test bad records for all ciphers. Bad records are fatal in TLS
2774 // and ignored in DTLS.
2775 var shouldFail bool
2776 var expectedError string
2777 if protocol == tls {
2778 shouldFail = true
2779 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2780 }
2781
2782 testCases = append(testCases, testCase{
2783 protocol: protocol,
2784 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2785 config: Config{
2786 MinVersion: ver.version,
2787 MaxVersion: ver.version,
2788 CipherSuites: []uint16{suite.id},
2789 Certificates: []Certificate{cert},
2790 PreSharedKey: []byte(psk),
2791 PreSharedKeyIdentity: pskIdentity,
2792 },
2793 flags: flags,
2794 damageFirstWrite: true,
2795 messageLen: maxPlaintext,
2796 shouldFail: shouldFail,
2797 expectedError: expectedError,
2798 })
David Benjaminaa012042016-12-10 13:33:05 -05002799}
2800
Adam Langley95c29f32014-06-20 12:00:00 -07002801func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002802 const bogusCipher = 0xfe00
2803
Adam Langley95c29f32014-06-20 12:00:00 -07002804 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002805 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002806 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002807 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002808 }
David Benjamin2c99d282015-09-01 10:23:00 -04002809 }
Adam Langley95c29f32014-06-20 12:00:00 -07002810 }
Adam Langleya7997f12015-05-14 17:38:50 -07002811
2812 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002813 name: "NoSharedCipher",
2814 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002815 MaxVersion: VersionTLS12,
2816 CipherSuites: []uint16{},
2817 },
2818 shouldFail: true,
2819 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2820 })
2821
2822 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002823 name: "NoSharedCipher-TLS13",
2824 config: Config{
2825 MaxVersion: VersionTLS13,
2826 CipherSuites: []uint16{},
2827 },
2828 shouldFail: true,
2829 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2830 })
2831
2832 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002833 name: "UnsupportedCipherSuite",
2834 config: Config{
2835 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002836 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002837 Bugs: ProtocolBugs{
2838 IgnorePeerCipherPreferences: true,
2839 },
2840 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002841 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002842 shouldFail: true,
2843 expectedError: ":WRONG_CIPHER_RETURNED:",
2844 })
2845
2846 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002847 name: "ServerHelloBogusCipher",
2848 config: Config{
2849 MaxVersion: VersionTLS12,
2850 Bugs: ProtocolBugs{
2851 SendCipherSuite: bogusCipher,
2852 },
2853 },
2854 shouldFail: true,
2855 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2856 })
2857 testCases = append(testCases, testCase{
2858 name: "ServerHelloBogusCipher-TLS13",
2859 config: Config{
2860 MaxVersion: VersionTLS13,
2861 Bugs: ProtocolBugs{
2862 SendCipherSuite: bogusCipher,
2863 },
2864 },
2865 shouldFail: true,
2866 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2867 })
2868
David Benjamin241ae832016-01-15 03:04:54 -05002869 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002870 testCases = append(testCases, testCase{
2871 testType: serverTest,
2872 name: "UnknownCipher",
2873 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002874 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002875 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002876 Bugs: ProtocolBugs{
2877 AdvertiseAllConfiguredCiphers: true,
2878 },
2879 },
2880 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002881
2882 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002883 testCases = append(testCases, testCase{
2884 testType: serverTest,
2885 name: "UnknownCipher-TLS13",
2886 config: Config{
2887 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002888 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002889 Bugs: ProtocolBugs{
2890 AdvertiseAllConfiguredCiphers: true,
2891 },
David Benjamin241ae832016-01-15 03:04:54 -05002892 },
2893 })
2894
David Benjamin78679342016-09-16 19:42:05 -04002895 // Test empty ECDHE_PSK identity hints work as expected.
2896 testCases = append(testCases, testCase{
2897 name: "EmptyECDHEPSKHint",
2898 config: Config{
2899 MaxVersion: VersionTLS12,
2900 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2901 PreSharedKey: []byte("secret"),
2902 },
2903 flags: []string{"-psk", "secret"},
2904 })
2905
2906 // Test empty PSK identity hints work as expected, even if an explicit
2907 // ServerKeyExchange is sent.
2908 testCases = append(testCases, testCase{
2909 name: "ExplicitEmptyPSKHint",
2910 config: Config{
2911 MaxVersion: VersionTLS12,
2912 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2913 PreSharedKey: []byte("secret"),
2914 Bugs: ProtocolBugs{
2915 AlwaysSendPreSharedKeyIdentityHint: true,
2916 },
2917 },
2918 flags: []string{"-psk", "secret"},
2919 })
David Benjamin69522112017-03-28 15:38:29 -05002920
2921 // Test that clients enforce that the server-sent certificate and cipher
2922 // suite match in TLS 1.2.
2923 testCases = append(testCases, testCase{
2924 name: "CertificateCipherMismatch-RSA",
2925 config: Config{
2926 MaxVersion: VersionTLS12,
2927 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2928 Certificates: []Certificate{rsaCertificate},
2929 Bugs: ProtocolBugs{
2930 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2931 },
2932 },
2933 shouldFail: true,
2934 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2935 })
2936 testCases = append(testCases, testCase{
2937 name: "CertificateCipherMismatch-ECDSA",
2938 config: Config{
2939 MaxVersion: VersionTLS12,
2940 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2941 Certificates: []Certificate{ecdsaP256Certificate},
2942 Bugs: ProtocolBugs{
2943 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2944 },
2945 },
2946 shouldFail: true,
2947 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2948 })
2949 testCases = append(testCases, testCase{
2950 name: "CertificateCipherMismatch-Ed25519",
2951 config: Config{
2952 MaxVersion: VersionTLS12,
2953 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2954 Certificates: []Certificate{ed25519Certificate},
2955 Bugs: ProtocolBugs{
2956 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2957 },
2958 },
2959 shouldFail: true,
2960 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2961 })
2962
2963 // Test that servers decline to select a cipher suite which is
2964 // inconsistent with their configured certificate.
2965 testCases = append(testCases, testCase{
2966 testType: serverTest,
2967 name: "ServerCipherFilter-RSA",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2971 },
2972 flags: []string{
2973 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2974 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2975 },
2976 shouldFail: true,
2977 expectedError: ":NO_SHARED_CIPHER:",
2978 })
2979 testCases = append(testCases, testCase{
2980 testType: serverTest,
2981 name: "ServerCipherFilter-ECDSA",
2982 config: Config{
2983 MaxVersion: VersionTLS12,
2984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2985 },
2986 flags: []string{
2987 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2988 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
2989 },
2990 shouldFail: true,
2991 expectedError: ":NO_SHARED_CIPHER:",
2992 })
2993 testCases = append(testCases, testCase{
2994 testType: serverTest,
2995 name: "ServerCipherFilter-Ed25519",
2996 config: Config{
2997 MaxVersion: VersionTLS12,
2998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2999 },
3000 flags: []string{
3001 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3002 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3003 },
3004 shouldFail: true,
3005 expectedError: ":NO_SHARED_CIPHER:",
3006 })
Adam Langley95c29f32014-06-20 12:00:00 -07003007}
3008
3009func addBadECDSASignatureTests() {
3010 for badR := BadValue(1); badR < NumBadValues; badR++ {
3011 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003012 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003013 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3014 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003015 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003016 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003017 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003018 Bugs: ProtocolBugs{
3019 BadECDSAR: badR,
3020 BadECDSAS: badS,
3021 },
3022 },
3023 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003024 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003025 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003026 testCases = append(testCases, testCase{
3027 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3028 config: Config{
3029 MaxVersion: VersionTLS13,
3030 Certificates: []Certificate{ecdsaP256Certificate},
3031 Bugs: ProtocolBugs{
3032 BadECDSAR: badR,
3033 BadECDSAS: badS,
3034 },
3035 },
3036 shouldFail: true,
3037 expectedError: ":BAD_SIGNATURE:",
3038 })
Adam Langley95c29f32014-06-20 12:00:00 -07003039 }
3040 }
3041}
3042
Adam Langley80842bd2014-06-20 12:00:00 -07003043func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003044 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003045 name: "MaxCBCPadding",
3046 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003047 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003048 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3049 Bugs: ProtocolBugs{
3050 MaxPadding: true,
3051 },
3052 },
3053 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3054 })
David Benjamin025b3d32014-07-01 19:53:04 -04003055 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003056 name: "BadCBCPadding",
3057 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003058 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3060 Bugs: ProtocolBugs{
3061 PaddingFirstByteBad: true,
3062 },
3063 },
3064 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003065 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003066 })
3067 // OpenSSL previously had an issue where the first byte of padding in
3068 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003069 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003070 name: "BadCBCPadding255",
3071 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003072 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003073 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3074 Bugs: ProtocolBugs{
3075 MaxPadding: true,
3076 PaddingFirstByteBadIf255: true,
3077 },
3078 },
3079 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3080 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003081 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003082 })
3083}
3084
Kenny Root7fdeaf12014-08-05 15:23:37 -07003085func addCBCSplittingTests() {
3086 testCases = append(testCases, testCase{
3087 name: "CBCRecordSplitting",
3088 config: Config{
3089 MaxVersion: VersionTLS10,
3090 MinVersion: VersionTLS10,
3091 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3092 },
David Benjaminac8302a2015-09-01 17:18:15 -04003093 messageLen: -1, // read until EOF
3094 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003095 flags: []string{
3096 "-async",
3097 "-write-different-record-sizes",
3098 "-cbc-record-splitting",
3099 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003100 })
3101 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003102 name: "CBCRecordSplittingPartialWrite",
3103 config: Config{
3104 MaxVersion: VersionTLS10,
3105 MinVersion: VersionTLS10,
3106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3107 },
3108 messageLen: -1, // read until EOF
3109 flags: []string{
3110 "-async",
3111 "-write-different-record-sizes",
3112 "-cbc-record-splitting",
3113 "-partial-write",
3114 },
3115 })
3116}
3117
David Benjamin636293b2014-07-08 17:59:18 -04003118func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003119 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003120 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003121 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3122 cert, err := x509.ParseCertificate(cert.Certificate[0])
3123 if err != nil {
3124 panic(err)
3125 }
3126 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003127 }
Adam Langley2ff79332017-02-28 13:45:39 -08003128 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003129
David Benjamin636293b2014-07-08 17:59:18 -04003130 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003131 testCases = append(testCases, testCase{
3132 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003133 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003134 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003135 MinVersion: ver.version,
3136 MaxVersion: ver.version,
3137 ClientAuth: RequireAnyClientCert,
3138 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003139 },
3140 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003141 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3142 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003143 },
3144 })
3145 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003146 testType: serverTest,
3147 name: ver.name + "-Server-ClientAuth-RSA",
3148 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003149 MinVersion: ver.version,
3150 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003151 Certificates: []Certificate{rsaCertificate},
3152 },
3153 flags: []string{"-require-any-client-certificate"},
3154 })
David Benjamine098ec22014-08-27 23:13:20 -04003155 if ver.version != VersionSSL30 {
3156 testCases = append(testCases, testCase{
3157 testType: serverTest,
3158 name: ver.name + "-Server-ClientAuth-ECDSA",
3159 config: Config{
3160 MinVersion: ver.version,
3161 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003162 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003163 },
3164 flags: []string{"-require-any-client-certificate"},
3165 })
3166 testCases = append(testCases, testCase{
3167 testType: clientTest,
3168 name: ver.name + "-Client-ClientAuth-ECDSA",
3169 config: Config{
3170 MinVersion: ver.version,
3171 MaxVersion: ver.version,
3172 ClientAuth: RequireAnyClientCert,
3173 ClientCAs: certPool,
3174 },
3175 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003176 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3177 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003178 },
3179 })
3180 }
Adam Langley37646832016-08-01 16:16:46 -07003181
3182 testCases = append(testCases, testCase{
3183 name: "NoClientCertificate-" + ver.name,
3184 config: Config{
3185 MinVersion: ver.version,
3186 MaxVersion: ver.version,
3187 ClientAuth: RequireAnyClientCert,
3188 },
3189 shouldFail: true,
3190 expectedLocalError: "client didn't provide a certificate",
3191 })
3192
3193 testCases = append(testCases, testCase{
3194 // Even if not configured to expect a certificate, OpenSSL will
3195 // return X509_V_OK as the verify_result.
3196 testType: serverTest,
3197 name: "NoClientCertificateRequested-Server-" + ver.name,
3198 config: Config{
3199 MinVersion: ver.version,
3200 MaxVersion: ver.version,
3201 },
3202 flags: []string{
3203 "-expect-verify-result",
3204 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003205 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003206 })
3207
3208 testCases = append(testCases, testCase{
3209 // If a client certificate is not provided, OpenSSL will still
3210 // return X509_V_OK as the verify_result.
3211 testType: serverTest,
3212 name: "NoClientCertificate-Server-" + ver.name,
3213 config: Config{
3214 MinVersion: ver.version,
3215 MaxVersion: ver.version,
3216 },
3217 flags: []string{
3218 "-expect-verify-result",
3219 "-verify-peer",
3220 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003221 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003222 })
3223
David Benjamin1db9e1b2016-10-07 20:51:43 -04003224 certificateRequired := "remote error: certificate required"
3225 if ver.version < VersionTLS13 {
3226 // Prior to TLS 1.3, the generic handshake_failure alert
3227 // was used.
3228 certificateRequired = "remote error: handshake failure"
3229 }
Adam Langley37646832016-08-01 16:16:46 -07003230 testCases = append(testCases, testCase{
3231 testType: serverTest,
3232 name: "RequireAnyClientCertificate-" + ver.name,
3233 config: Config{
3234 MinVersion: ver.version,
3235 MaxVersion: ver.version,
3236 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003237 flags: []string{"-require-any-client-certificate"},
3238 shouldFail: true,
3239 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3240 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003241 })
3242
3243 if ver.version != VersionSSL30 {
3244 testCases = append(testCases, testCase{
3245 testType: serverTest,
3246 name: "SkipClientCertificate-" + ver.name,
3247 config: Config{
3248 MinVersion: ver.version,
3249 MaxVersion: ver.version,
3250 Bugs: ProtocolBugs{
3251 SkipClientCertificate: true,
3252 },
3253 },
3254 // Setting SSL_VERIFY_PEER allows anonymous clients.
3255 flags: []string{"-verify-peer"},
3256 shouldFail: true,
3257 expectedError: ":UNEXPECTED_MESSAGE:",
3258 })
3259 }
Adam Langley2ff79332017-02-28 13:45:39 -08003260
3261 testCases = append(testCases, testCase{
3262 testType: serverTest,
3263 name: ver.name + "-Server-CertReq-CA-List",
3264 config: Config{
3265 MinVersion: ver.version,
3266 MaxVersion: ver.version,
3267 Certificates: []Certificate{rsaCertificate},
3268 Bugs: ProtocolBugs{
3269 ExpectCertificateReqNames: caNames,
3270 },
3271 },
3272 flags: []string{
3273 "-require-any-client-certificate",
3274 "-use-client-ca-list", encodeDERValues(caNames),
3275 },
3276 })
3277
3278 testCases = append(testCases, testCase{
3279 testType: clientTest,
3280 name: ver.name + "-Client-CertReq-CA-List",
3281 config: Config{
3282 MinVersion: ver.version,
3283 MaxVersion: ver.version,
3284 Certificates: []Certificate{rsaCertificate},
3285 ClientAuth: RequireAnyClientCert,
3286 ClientCAs: certPool,
3287 },
3288 flags: []string{
3289 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3290 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3291 "-expect-client-ca-list", encodeDERValues(caNames),
3292 },
3293 })
David Benjamin636293b2014-07-08 17:59:18 -04003294 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003295
David Benjaminc032dfa2016-05-12 14:54:57 -04003296 // Client auth is only legal in certificate-based ciphers.
3297 testCases = append(testCases, testCase{
3298 testType: clientTest,
3299 name: "ClientAuth-PSK",
3300 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003301 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003302 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3303 PreSharedKey: []byte("secret"),
3304 ClientAuth: RequireAnyClientCert,
3305 },
3306 flags: []string{
3307 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3308 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3309 "-psk", "secret",
3310 },
3311 shouldFail: true,
3312 expectedError: ":UNEXPECTED_MESSAGE:",
3313 })
3314 testCases = append(testCases, testCase{
3315 testType: clientTest,
3316 name: "ClientAuth-ECDHE_PSK",
3317 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003318 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003319 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3320 PreSharedKey: []byte("secret"),
3321 ClientAuth: RequireAnyClientCert,
3322 },
3323 flags: []string{
3324 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3325 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3326 "-psk", "secret",
3327 },
3328 shouldFail: true,
3329 expectedError: ":UNEXPECTED_MESSAGE:",
3330 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003331
3332 // Regression test for a bug where the client CA list, if explicitly
3333 // set to NULL, was mis-encoded.
3334 testCases = append(testCases, testCase{
3335 testType: serverTest,
3336 name: "Null-Client-CA-List",
3337 config: Config{
3338 MaxVersion: VersionTLS12,
3339 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003340 Bugs: ProtocolBugs{
3341 ExpectCertificateReqNames: [][]byte{},
3342 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003343 },
3344 flags: []string{
3345 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003346 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003347 },
3348 })
David Benjamin636293b2014-07-08 17:59:18 -04003349}
3350
Adam Langley75712922014-10-10 16:23:43 -07003351func addExtendedMasterSecretTests() {
3352 const expectEMSFlag = "-expect-extended-master-secret"
3353
3354 for _, with := range []bool{false, true} {
3355 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003356 if with {
3357 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003358 }
3359
3360 for _, isClient := range []bool{false, true} {
3361 suffix := "-Server"
3362 testType := serverTest
3363 if isClient {
3364 suffix = "-Client"
3365 testType = clientTest
3366 }
3367
3368 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003369 // In TLS 1.3, the extension is irrelevant and
3370 // always reports as enabled.
3371 var flags []string
3372 if with || ver.version >= VersionTLS13 {
3373 flags = []string{expectEMSFlag}
3374 }
3375
Adam Langley75712922014-10-10 16:23:43 -07003376 test := testCase{
3377 testType: testType,
3378 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3379 config: Config{
3380 MinVersion: ver.version,
3381 MaxVersion: ver.version,
3382 Bugs: ProtocolBugs{
3383 NoExtendedMasterSecret: !with,
3384 RequireExtendedMasterSecret: with,
3385 },
3386 },
David Benjamin48cae082014-10-27 01:06:24 -04003387 flags: flags,
3388 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003389 }
3390 if test.shouldFail {
3391 test.expectedLocalError = "extended master secret required but not supported by peer"
3392 }
3393 testCases = append(testCases, test)
3394 }
3395 }
3396 }
3397
Adam Langleyba5934b2015-06-02 10:50:35 -07003398 for _, isClient := range []bool{false, true} {
3399 for _, supportedInFirstConnection := range []bool{false, true} {
3400 for _, supportedInResumeConnection := range []bool{false, true} {
3401 boolToWord := func(b bool) string {
3402 if b {
3403 return "Yes"
3404 }
3405 return "No"
3406 }
3407 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3408 if isClient {
3409 suffix += "Client"
3410 } else {
3411 suffix += "Server"
3412 }
3413
3414 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003415 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003416 Bugs: ProtocolBugs{
3417 RequireExtendedMasterSecret: true,
3418 },
3419 }
3420
3421 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003422 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003423 Bugs: ProtocolBugs{
3424 NoExtendedMasterSecret: true,
3425 },
3426 }
3427
3428 test := testCase{
3429 name: "ExtendedMasterSecret-" + suffix,
3430 resumeSession: true,
3431 }
3432
3433 if !isClient {
3434 test.testType = serverTest
3435 }
3436
3437 if supportedInFirstConnection {
3438 test.config = supportedConfig
3439 } else {
3440 test.config = noSupportConfig
3441 }
3442
3443 if supportedInResumeConnection {
3444 test.resumeConfig = &supportedConfig
3445 } else {
3446 test.resumeConfig = &noSupportConfig
3447 }
3448
3449 switch suffix {
3450 case "YesToYes-Client", "YesToYes-Server":
3451 // When a session is resumed, it should
3452 // still be aware that its master
3453 // secret was generated via EMS and
3454 // thus it's safe to use tls-unique.
3455 test.flags = []string{expectEMSFlag}
3456 case "NoToYes-Server":
3457 // If an original connection did not
3458 // contain EMS, but a resumption
3459 // handshake does, then a server should
3460 // not resume the session.
3461 test.expectResumeRejected = true
3462 case "YesToNo-Server":
3463 // Resuming an EMS session without the
3464 // EMS extension should cause the
3465 // server to abort the connection.
3466 test.shouldFail = true
3467 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3468 case "NoToYes-Client":
3469 // A client should abort a connection
3470 // where the server resumed a non-EMS
3471 // session but echoed the EMS
3472 // extension.
3473 test.shouldFail = true
3474 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3475 case "YesToNo-Client":
3476 // A client should abort a connection
3477 // where the server didn't echo EMS
3478 // when the session used it.
3479 test.shouldFail = true
3480 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3481 }
3482
3483 testCases = append(testCases, test)
3484 }
3485 }
3486 }
David Benjamin163c9562016-08-29 23:14:17 -04003487
3488 // Switching EMS on renegotiation is forbidden.
3489 testCases = append(testCases, testCase{
3490 name: "ExtendedMasterSecret-Renego-NoEMS",
3491 config: Config{
3492 MaxVersion: VersionTLS12,
3493 Bugs: ProtocolBugs{
3494 NoExtendedMasterSecret: true,
3495 NoExtendedMasterSecretOnRenegotiation: true,
3496 },
3497 },
3498 renegotiate: 1,
3499 flags: []string{
3500 "-renegotiate-freely",
3501 "-expect-total-renegotiations", "1",
3502 },
3503 })
3504
3505 testCases = append(testCases, testCase{
3506 name: "ExtendedMasterSecret-Renego-Upgrade",
3507 config: Config{
3508 MaxVersion: VersionTLS12,
3509 Bugs: ProtocolBugs{
3510 NoExtendedMasterSecret: true,
3511 },
3512 },
3513 renegotiate: 1,
3514 flags: []string{
3515 "-renegotiate-freely",
3516 "-expect-total-renegotiations", "1",
3517 },
3518 shouldFail: true,
3519 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3520 })
3521
3522 testCases = append(testCases, testCase{
3523 name: "ExtendedMasterSecret-Renego-Downgrade",
3524 config: Config{
3525 MaxVersion: VersionTLS12,
3526 Bugs: ProtocolBugs{
3527 NoExtendedMasterSecretOnRenegotiation: true,
3528 },
3529 },
3530 renegotiate: 1,
3531 flags: []string{
3532 "-renegotiate-freely",
3533 "-expect-total-renegotiations", "1",
3534 },
3535 shouldFail: true,
3536 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3537 })
Adam Langley75712922014-10-10 16:23:43 -07003538}
3539
David Benjamin582ba042016-07-07 12:33:25 -07003540type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003541 protocol protocol
3542 async bool
3543 splitHandshake bool
3544 packHandshakeFlight bool
3545 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003546}
3547
David Benjamin43ec06f2014-08-05 02:28:57 -04003548// Adds tests that try to cover the range of the handshake state machine, under
3549// various conditions. Some of these are redundant with other tests, but they
3550// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003551func addAllStateMachineCoverageTests() {
3552 for _, async := range []bool{false, true} {
3553 for _, protocol := range []protocol{tls, dtls} {
3554 addStateMachineCoverageTests(stateMachineTestConfig{
3555 protocol: protocol,
3556 async: async,
3557 })
3558 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003559 protocol: protocol,
3560 async: async,
3561 implicitHandshake: true,
3562 })
3563 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003564 protocol: protocol,
3565 async: async,
3566 splitHandshake: true,
3567 })
3568 if protocol == tls {
3569 addStateMachineCoverageTests(stateMachineTestConfig{
3570 protocol: protocol,
3571 async: async,
3572 packHandshakeFlight: true,
3573 })
3574 }
3575 }
3576 }
3577}
3578
3579func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003580 var tests []testCase
3581
3582 // Basic handshake, with resumption. Client and server,
3583 // session ID and session ticket.
3584 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003585 name: "Basic-Client",
3586 config: Config{
3587 MaxVersion: VersionTLS12,
3588 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003590 // Ensure session tickets are used, not session IDs.
3591 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003592 })
3593 tests = append(tests, testCase{
3594 name: "Basic-Client-RenewTicket",
3595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003596 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003597 Bugs: ProtocolBugs{
3598 RenewTicketOnResume: true,
3599 },
3600 },
David Benjamin46662482016-08-17 00:51:00 -04003601 flags: []string{"-expect-ticket-renewal"},
3602 resumeSession: true,
3603 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003604 })
3605 tests = append(tests, testCase{
3606 name: "Basic-Client-NoTicket",
3607 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003608 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003609 SessionTicketsDisabled: true,
3610 },
3611 resumeSession: true,
3612 })
3613 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003614 testType: serverTest,
3615 name: "Basic-Server",
3616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003617 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003618 Bugs: ProtocolBugs{
3619 RequireSessionTickets: true,
3620 },
3621 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003622 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003623 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003624 })
3625 tests = append(tests, testCase{
3626 testType: serverTest,
3627 name: "Basic-Server-NoTickets",
3628 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003629 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003630 SessionTicketsDisabled: true,
3631 },
3632 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003633 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003634 })
3635 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003636 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003637 name: "Basic-Server-EarlyCallback",
3638 config: Config{
3639 MaxVersion: VersionTLS12,
3640 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003641 flags: []string{"-use-early-callback"},
3642 resumeSession: true,
3643 })
3644
Steven Valdez143e8b32016-07-11 13:19:03 -04003645 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003646 if config.protocol == tls {
3647 tests = append(tests, testCase{
3648 name: "TLS13-1RTT-Client",
3649 config: Config{
3650 MaxVersion: VersionTLS13,
3651 MinVersion: VersionTLS13,
3652 },
David Benjamin46662482016-08-17 00:51:00 -04003653 resumeSession: true,
3654 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003655 })
3656
3657 tests = append(tests, testCase{
3658 testType: serverTest,
3659 name: "TLS13-1RTT-Server",
3660 config: Config{
3661 MaxVersion: VersionTLS13,
3662 MinVersion: VersionTLS13,
3663 },
David Benjamin46662482016-08-17 00:51:00 -04003664 resumeSession: true,
3665 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003666 // TLS 1.3 uses tickets, so the session should not be
3667 // cached statefully.
3668 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003669 })
3670
3671 tests = append(tests, testCase{
3672 name: "TLS13-HelloRetryRequest-Client",
3673 config: Config{
3674 MaxVersion: VersionTLS13,
3675 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003676 // P-384 requires a HelloRetryRequest against BoringSSL's default
3677 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003678 CurvePreferences: []CurveID{CurveP384},
3679 Bugs: ProtocolBugs{
3680 ExpectMissingKeyShare: true,
3681 },
3682 },
3683 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3684 resumeSession: true,
3685 })
3686
3687 tests = append(tests, testCase{
3688 testType: serverTest,
3689 name: "TLS13-HelloRetryRequest-Server",
3690 config: Config{
3691 MaxVersion: VersionTLS13,
3692 MinVersion: VersionTLS13,
3693 // Require a HelloRetryRequest for every curve.
3694 DefaultCurves: []CurveID{},
3695 },
3696 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3697 resumeSession: true,
3698 })
Steven Valdez2d850622017-01-11 11:34:52 -05003699
Steven Valdez2d850622017-01-11 11:34:52 -05003700 tests = append(tests, testCase{
3701 testType: clientTest,
3702 name: "TLS13-EarlyData-Client",
3703 config: Config{
3704 MaxVersion: VersionTLS13,
3705 MinVersion: VersionTLS13,
3706 MaxEarlyDataSize: 16384,
3707 },
Steven Valdeze831a812017-03-09 14:56:07 -05003708 resumeConfig: &Config{
3709 MaxVersion: VersionTLS13,
3710 MinVersion: VersionTLS13,
3711 MaxEarlyDataSize: 16384,
3712 Bugs: ProtocolBugs{
3713 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3714 },
3715 },
Steven Valdez2d850622017-01-11 11:34:52 -05003716 resumeSession: true,
3717 flags: []string{
3718 "-enable-early-data",
3719 "-expect-early-data-info",
3720 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003721 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003722 },
3723 })
3724
3725 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003726 testType: clientTest,
3727 name: "TLS13-EarlyData-TooMuchData-Client",
3728 config: Config{
3729 MaxVersion: VersionTLS13,
3730 MinVersion: VersionTLS13,
3731 MaxEarlyDataSize: 2,
3732 },
3733 resumeConfig: &Config{
3734 MaxVersion: VersionTLS13,
3735 MinVersion: VersionTLS13,
3736 MaxEarlyDataSize: 2,
3737 Bugs: ProtocolBugs{
3738 ExpectEarlyData: [][]byte{{'h', 'e'}},
3739 },
3740 },
3741 resumeShimPrefix: "llo",
3742 resumeSession: true,
3743 flags: []string{
3744 "-enable-early-data",
3745 "-expect-early-data-info",
3746 "-expect-accept-early-data",
3747 "-on-resume-shim-writes-first",
3748 },
3749 })
3750
3751 // Unfinished writes can only be tested when operations are async. EarlyData
3752 // can't be tested as part of an ImplicitHandshake in this case since
3753 // otherwise the early data will be sent as normal data.
3754 if config.async && !config.implicitHandshake {
3755 tests = append(tests, testCase{
3756 testType: clientTest,
3757 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3758 config: Config{
3759 MaxVersion: VersionTLS13,
3760 MinVersion: VersionTLS13,
3761 MaxEarlyDataSize: 16384,
3762 },
3763 resumeConfig: &Config{
3764 MaxVersion: VersionTLS13,
3765 MinVersion: VersionTLS13,
3766 MaxEarlyDataSize: 16384,
3767 Bugs: ProtocolBugs{
3768 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3769 },
3770 },
3771 resumeSession: true,
3772 flags: []string{
3773 "-enable-early-data",
3774 "-expect-early-data-info",
3775 "-expect-accept-early-data",
3776 "-on-resume-read-with-unfinished-write",
3777 "-on-resume-shim-writes-first",
3778 },
3779 })
3780
3781 // Rejected unfinished writes are discarded (from the
3782 // perspective of the calling application) on 0-RTT
3783 // reject.
3784 tests = append(tests, testCase{
3785 testType: clientTest,
3786 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3787 config: Config{
3788 MaxVersion: VersionTLS13,
3789 MinVersion: VersionTLS13,
3790 MaxEarlyDataSize: 16384,
3791 },
3792 resumeConfig: &Config{
3793 MaxVersion: VersionTLS13,
3794 MinVersion: VersionTLS13,
3795 MaxEarlyDataSize: 16384,
3796 Bugs: ProtocolBugs{
3797 AlwaysRejectEarlyData: true,
3798 },
3799 },
3800 resumeSession: true,
3801 flags: []string{
3802 "-enable-early-data",
3803 "-expect-early-data-info",
3804 "-expect-reject-early-data",
3805 "-on-resume-read-with-unfinished-write",
3806 "-on-resume-shim-writes-first",
3807 },
3808 })
3809 }
3810
3811 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003812 testType: serverTest,
3813 name: "TLS13-EarlyData-Server",
3814 config: Config{
3815 MaxVersion: VersionTLS13,
3816 MinVersion: VersionTLS13,
3817 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003818 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003819 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003820 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003821 },
3822 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003823 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003824 resumeSession: true,
3825 flags: []string{
3826 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003827 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003828 },
3829 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003830
3831 tests = append(tests, testCase{
3832 testType: serverTest,
3833 name: "TLS13-MaxEarlyData-Server",
3834 config: Config{
3835 MaxVersion: VersionTLS13,
3836 MinVersion: VersionTLS13,
3837 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003838 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003839 ExpectEarlyDataAccepted: true,
3840 },
3841 },
3842 messageCount: 2,
3843 resumeSession: true,
3844 flags: []string{
3845 "-enable-early-data",
3846 "-expect-accept-early-data",
3847 },
3848 shouldFail: true,
3849 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
3850 })
David Benjamine73c7f42016-08-17 00:29:33 -04003851 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003852
David Benjamin760b1dd2015-05-15 23:33:48 -04003853 // TLS client auth.
3854 tests = append(tests, testCase{
3855 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003856 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003858 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003859 ClientAuth: RequestClientCert,
3860 },
3861 })
3862 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003863 testType: serverTest,
3864 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003865 config: Config{
3866 MaxVersion: VersionTLS12,
3867 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003868 // Setting SSL_VERIFY_PEER allows anonymous clients.
3869 flags: []string{"-verify-peer"},
3870 })
David Benjamin582ba042016-07-07 12:33:25 -07003871 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003872 tests = append(tests, testCase{
3873 testType: clientTest,
3874 name: "ClientAuth-NoCertificate-Client-SSL3",
3875 config: Config{
3876 MaxVersion: VersionSSL30,
3877 ClientAuth: RequestClientCert,
3878 },
3879 })
3880 tests = append(tests, testCase{
3881 testType: serverTest,
3882 name: "ClientAuth-NoCertificate-Server-SSL3",
3883 config: Config{
3884 MaxVersion: VersionSSL30,
3885 },
3886 // Setting SSL_VERIFY_PEER allows anonymous clients.
3887 flags: []string{"-verify-peer"},
3888 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003889 tests = append(tests, testCase{
3890 testType: clientTest,
3891 name: "ClientAuth-NoCertificate-Client-TLS13",
3892 config: Config{
3893 MaxVersion: VersionTLS13,
3894 ClientAuth: RequestClientCert,
3895 },
3896 })
3897 tests = append(tests, testCase{
3898 testType: serverTest,
3899 name: "ClientAuth-NoCertificate-Server-TLS13",
3900 config: Config{
3901 MaxVersion: VersionTLS13,
3902 },
3903 // Setting SSL_VERIFY_PEER allows anonymous clients.
3904 flags: []string{"-verify-peer"},
3905 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003906 }
3907 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003908 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003909 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003911 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003912 ClientAuth: RequireAnyClientCert,
3913 },
3914 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003915 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3916 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003917 },
3918 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003919 tests = append(tests, testCase{
3920 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003921 name: "ClientAuth-RSA-Client-TLS13",
3922 config: Config{
3923 MaxVersion: VersionTLS13,
3924 ClientAuth: RequireAnyClientCert,
3925 },
3926 flags: []string{
3927 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3928 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3929 },
3930 })
3931 tests = append(tests, testCase{
3932 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003933 name: "ClientAuth-ECDSA-Client",
3934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003935 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003936 ClientAuth: RequireAnyClientCert,
3937 },
3938 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003939 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3940 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003941 },
3942 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003943 tests = append(tests, testCase{
3944 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003945 name: "ClientAuth-ECDSA-Client-TLS13",
3946 config: Config{
3947 MaxVersion: VersionTLS13,
3948 ClientAuth: RequireAnyClientCert,
3949 },
3950 flags: []string{
3951 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3952 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3953 },
3954 })
3955 tests = append(tests, testCase{
3956 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003957 name: "ClientAuth-NoCertificate-OldCallback",
3958 config: Config{
3959 MaxVersion: VersionTLS12,
3960 ClientAuth: RequestClientCert,
3961 },
3962 flags: []string{"-use-old-client-cert-callback"},
3963 })
3964 tests = append(tests, testCase{
3965 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003966 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3967 config: Config{
3968 MaxVersion: VersionTLS13,
3969 ClientAuth: RequestClientCert,
3970 },
3971 flags: []string{"-use-old-client-cert-callback"},
3972 })
3973 tests = append(tests, testCase{
3974 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003975 name: "ClientAuth-OldCallback",
3976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003977 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003978 ClientAuth: RequireAnyClientCert,
3979 },
3980 flags: []string{
3981 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3982 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3983 "-use-old-client-cert-callback",
3984 },
3985 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003986 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003987 testType: clientTest,
3988 name: "ClientAuth-OldCallback-TLS13",
3989 config: Config{
3990 MaxVersion: VersionTLS13,
3991 ClientAuth: RequireAnyClientCert,
3992 },
3993 flags: []string{
3994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3996 "-use-old-client-cert-callback",
3997 },
3998 })
3999 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004000 testType: serverTest,
4001 name: "ClientAuth-Server",
4002 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004003 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004004 Certificates: []Certificate{rsaCertificate},
4005 },
4006 flags: []string{"-require-any-client-certificate"},
4007 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004008 tests = append(tests, testCase{
4009 testType: serverTest,
4010 name: "ClientAuth-Server-TLS13",
4011 config: Config{
4012 MaxVersion: VersionTLS13,
4013 Certificates: []Certificate{rsaCertificate},
4014 },
4015 flags: []string{"-require-any-client-certificate"},
4016 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004017
David Benjamin4c3ddf72016-06-29 18:13:53 -04004018 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004019 tests = append(tests, testCase{
4020 testType: serverTest,
4021 name: "Basic-Server-RSA",
4022 config: Config{
4023 MaxVersion: VersionTLS12,
4024 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4025 },
4026 flags: []string{
4027 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4028 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4029 },
4030 })
4031 tests = append(tests, testCase{
4032 testType: serverTest,
4033 name: "Basic-Server-ECDHE-RSA",
4034 config: Config{
4035 MaxVersion: VersionTLS12,
4036 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4037 },
4038 flags: []string{
4039 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4040 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4041 },
4042 })
4043 tests = append(tests, testCase{
4044 testType: serverTest,
4045 name: "Basic-Server-ECDHE-ECDSA",
4046 config: Config{
4047 MaxVersion: VersionTLS12,
4048 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4049 },
4050 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004051 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4052 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004053 },
4054 })
David Benjamin69522112017-03-28 15:38:29 -05004055 tests = append(tests, testCase{
4056 testType: serverTest,
4057 name: "Basic-Server-Ed25519",
4058 config: Config{
4059 MaxVersion: VersionTLS12,
4060 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4061 },
4062 flags: []string{
4063 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4064 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4065 "-enable-ed25519",
4066 },
4067 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004068
David Benjamin760b1dd2015-05-15 23:33:48 -04004069 // No session ticket support; server doesn't send NewSessionTicket.
4070 tests = append(tests, testCase{
4071 name: "SessionTicketsDisabled-Client",
4072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004073 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004074 SessionTicketsDisabled: true,
4075 },
4076 })
4077 tests = append(tests, testCase{
4078 testType: serverTest,
4079 name: "SessionTicketsDisabled-Server",
4080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004081 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004082 SessionTicketsDisabled: true,
4083 },
4084 })
4085
4086 // Skip ServerKeyExchange in PSK key exchange if there's no
4087 // identity hint.
4088 tests = append(tests, testCase{
4089 name: "EmptyPSKHint-Client",
4090 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004091 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004092 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4093 PreSharedKey: []byte("secret"),
4094 },
4095 flags: []string{"-psk", "secret"},
4096 })
4097 tests = append(tests, testCase{
4098 testType: serverTest,
4099 name: "EmptyPSKHint-Server",
4100 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004101 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004102 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4103 PreSharedKey: []byte("secret"),
4104 },
4105 flags: []string{"-psk", "secret"},
4106 })
4107
David Benjamin4c3ddf72016-06-29 18:13:53 -04004108 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004109 tests = append(tests, testCase{
4110 testType: clientTest,
4111 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004112 config: Config{
4113 MaxVersion: VersionTLS12,
4114 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004115 flags: []string{
4116 "-enable-ocsp-stapling",
4117 "-expect-ocsp-response",
4118 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004119 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004120 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004121 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004122 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004123 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004124 testType: serverTest,
4125 name: "OCSPStapling-Server",
4126 config: Config{
4127 MaxVersion: VersionTLS12,
4128 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004129 expectedOCSPResponse: testOCSPResponse,
4130 flags: []string{
4131 "-ocsp-response",
4132 base64.StdEncoding.EncodeToString(testOCSPResponse),
4133 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004134 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004135 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004136 tests = append(tests, testCase{
4137 testType: clientTest,
4138 name: "OCSPStapling-Client-TLS13",
4139 config: Config{
4140 MaxVersion: VersionTLS13,
4141 },
4142 flags: []string{
4143 "-enable-ocsp-stapling",
4144 "-expect-ocsp-response",
4145 base64.StdEncoding.EncodeToString(testOCSPResponse),
4146 "-verify-peer",
4147 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004148 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004149 })
4150 tests = append(tests, testCase{
4151 testType: serverTest,
4152 name: "OCSPStapling-Server-TLS13",
4153 config: Config{
4154 MaxVersion: VersionTLS13,
4155 },
4156 expectedOCSPResponse: testOCSPResponse,
4157 flags: []string{
4158 "-ocsp-response",
4159 base64.StdEncoding.EncodeToString(testOCSPResponse),
4160 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004161 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004162 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004163
David Benjamin4c3ddf72016-06-29 18:13:53 -04004164 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004165 for _, vers := range tlsVersions {
4166 if config.protocol == dtls && !vers.hasDTLS {
4167 continue
4168 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004169 for _, testType := range []testType{clientTest, serverTest} {
4170 suffix := "-Client"
4171 if testType == serverTest {
4172 suffix = "-Server"
4173 }
4174 suffix += "-" + vers.name
4175
4176 flag := "-verify-peer"
4177 if testType == serverTest {
4178 flag = "-require-any-client-certificate"
4179 }
4180
4181 tests = append(tests, testCase{
4182 testType: testType,
4183 name: "CertificateVerificationSucceed" + suffix,
4184 config: Config{
4185 MaxVersion: vers.version,
4186 Certificates: []Certificate{rsaCertificate},
4187 },
4188 flags: []string{
4189 flag,
4190 "-expect-verify-result",
4191 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004192 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004193 })
4194 tests = append(tests, testCase{
4195 testType: testType,
4196 name: "CertificateVerificationFail" + suffix,
4197 config: Config{
4198 MaxVersion: vers.version,
4199 Certificates: []Certificate{rsaCertificate},
4200 },
4201 flags: []string{
4202 flag,
4203 "-verify-fail",
4204 },
4205 shouldFail: true,
4206 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4207 })
4208 }
4209
4210 // By default, the client is in a soft fail mode where the peer
4211 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004212 tests = append(tests, testCase{
4213 testType: clientTest,
4214 name: "CertificateVerificationSoftFail-" + vers.name,
4215 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004216 MaxVersion: vers.version,
4217 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004218 },
4219 flags: []string{
4220 "-verify-fail",
4221 "-expect-verify-result",
4222 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004223 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004224 })
4225 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004226
David Benjamin1d4f4c02016-07-26 18:03:08 -04004227 tests = append(tests, testCase{
4228 name: "ShimSendAlert",
4229 flags: []string{"-send-alert"},
4230 shimWritesFirst: true,
4231 shouldFail: true,
4232 expectedLocalError: "remote error: decompression failure",
4233 })
4234
David Benjamin582ba042016-07-07 12:33:25 -07004235 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004236 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004237 name: "Renegotiate-Client",
4238 config: Config{
4239 MaxVersion: VersionTLS12,
4240 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004241 renegotiate: 1,
4242 flags: []string{
4243 "-renegotiate-freely",
4244 "-expect-total-renegotiations", "1",
4245 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004246 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004247
David Benjamin47921102016-07-28 11:29:18 -04004248 tests = append(tests, testCase{
4249 name: "SendHalfHelloRequest",
4250 config: Config{
4251 MaxVersion: VersionTLS12,
4252 Bugs: ProtocolBugs{
4253 PackHelloRequestWithFinished: config.packHandshakeFlight,
4254 },
4255 },
4256 sendHalfHelloRequest: true,
4257 flags: []string{"-renegotiate-ignore"},
4258 shouldFail: true,
4259 expectedError: ":UNEXPECTED_RECORD:",
4260 })
4261
David Benjamin760b1dd2015-05-15 23:33:48 -04004262 // NPN on client and server; results in post-handshake message.
4263 tests = append(tests, testCase{
4264 name: "NPN-Client",
4265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004266 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004267 NextProtos: []string{"foo"},
4268 },
4269 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004270 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004271 expectedNextProto: "foo",
4272 expectedNextProtoType: npn,
4273 })
4274 tests = append(tests, testCase{
4275 testType: serverTest,
4276 name: "NPN-Server",
4277 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004278 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004279 NextProtos: []string{"bar"},
4280 },
4281 flags: []string{
4282 "-advertise-npn", "\x03foo\x03bar\x03baz",
4283 "-expect-next-proto", "bar",
4284 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004285 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004286 expectedNextProto: "bar",
4287 expectedNextProtoType: npn,
4288 })
4289
4290 // TODO(davidben): Add tests for when False Start doesn't trigger.
4291
4292 // Client does False Start and negotiates NPN.
4293 tests = append(tests, testCase{
4294 name: "FalseStart",
4295 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004296 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004297 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4298 NextProtos: []string{"foo"},
4299 Bugs: ProtocolBugs{
4300 ExpectFalseStart: true,
4301 },
4302 },
4303 flags: []string{
4304 "-false-start",
4305 "-select-next-proto", "foo",
4306 },
4307 shimWritesFirst: true,
4308 resumeSession: true,
4309 })
4310
4311 // Client does False Start and negotiates ALPN.
4312 tests = append(tests, testCase{
4313 name: "FalseStart-ALPN",
4314 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004315 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004316 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4317 NextProtos: []string{"foo"},
4318 Bugs: ProtocolBugs{
4319 ExpectFalseStart: true,
4320 },
4321 },
4322 flags: []string{
4323 "-false-start",
4324 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004325 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004326 },
4327 shimWritesFirst: true,
4328 resumeSession: true,
4329 })
4330
David Benjamin760b1dd2015-05-15 23:33:48 -04004331 // False Start without session tickets.
4332 tests = append(tests, testCase{
4333 name: "FalseStart-SessionTicketsDisabled",
4334 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004335 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004336 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4337 NextProtos: []string{"foo"},
4338 SessionTicketsDisabled: true,
4339 Bugs: ProtocolBugs{
4340 ExpectFalseStart: true,
4341 },
4342 },
4343 flags: []string{
4344 "-false-start",
4345 "-select-next-proto", "foo",
4346 },
4347 shimWritesFirst: true,
4348 })
4349
4350 // Server parses a V2ClientHello.
4351 tests = append(tests, testCase{
4352 testType: serverTest,
4353 name: "SendV2ClientHello",
4354 config: Config{
4355 // Choose a cipher suite that does not involve
4356 // elliptic curves, so no extensions are
4357 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004358 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004359 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004360 Bugs: ProtocolBugs{
4361 SendV2ClientHello: true,
4362 },
4363 },
4364 })
4365
Nick Harper60a85cb2016-09-23 16:25:11 -07004366 // Test Channel ID
4367 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004368 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004369 continue
4370 }
4371 // Client sends a Channel ID.
4372 tests = append(tests, testCase{
4373 name: "ChannelID-Client-" + ver.name,
4374 config: Config{
4375 MaxVersion: ver.version,
4376 RequestChannelID: true,
4377 },
4378 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4379 resumeSession: true,
4380 expectChannelID: true,
4381 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004382
Nick Harper60a85cb2016-09-23 16:25:11 -07004383 // Server accepts a Channel ID.
4384 tests = append(tests, testCase{
4385 testType: serverTest,
4386 name: "ChannelID-Server-" + ver.name,
4387 config: Config{
4388 MaxVersion: ver.version,
4389 ChannelID: channelIDKey,
4390 },
4391 flags: []string{
4392 "-expect-channel-id",
4393 base64.StdEncoding.EncodeToString(channelIDBytes),
4394 },
4395 resumeSession: true,
4396 expectChannelID: true,
4397 })
4398
4399 tests = append(tests, testCase{
4400 testType: serverTest,
4401 name: "InvalidChannelIDSignature-" + ver.name,
4402 config: Config{
4403 MaxVersion: ver.version,
4404 ChannelID: channelIDKey,
4405 Bugs: ProtocolBugs{
4406 InvalidChannelIDSignature: true,
4407 },
4408 },
4409 flags: []string{"-enable-channel-id"},
4410 shouldFail: true,
4411 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4412 })
4413 }
David Benjamin30789da2015-08-29 22:56:45 -04004414
David Benjaminf8fcdf32016-06-08 15:56:13 -04004415 // Channel ID and NPN at the same time, to ensure their relative
4416 // ordering is correct.
4417 tests = append(tests, testCase{
4418 name: "ChannelID-NPN-Client",
4419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004420 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004421 RequestChannelID: true,
4422 NextProtos: []string{"foo"},
4423 },
4424 flags: []string{
4425 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4426 "-select-next-proto", "foo",
4427 },
4428 resumeSession: true,
4429 expectChannelID: true,
4430 expectedNextProto: "foo",
4431 expectedNextProtoType: npn,
4432 })
4433 tests = append(tests, testCase{
4434 testType: serverTest,
4435 name: "ChannelID-NPN-Server",
4436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004437 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004438 ChannelID: channelIDKey,
4439 NextProtos: []string{"bar"},
4440 },
4441 flags: []string{
4442 "-expect-channel-id",
4443 base64.StdEncoding.EncodeToString(channelIDBytes),
4444 "-advertise-npn", "\x03foo\x03bar\x03baz",
4445 "-expect-next-proto", "bar",
4446 },
4447 resumeSession: true,
4448 expectChannelID: true,
4449 expectedNextProto: "bar",
4450 expectedNextProtoType: npn,
4451 })
4452
David Benjamin30789da2015-08-29 22:56:45 -04004453 // Bidirectional shutdown with the runner initiating.
4454 tests = append(tests, testCase{
4455 name: "Shutdown-Runner",
4456 config: Config{
4457 Bugs: ProtocolBugs{
4458 ExpectCloseNotify: true,
4459 },
4460 },
4461 flags: []string{"-check-close-notify"},
4462 })
4463
David Benjamine3843d42017-03-25 18:00:56 -05004464 if !config.implicitHandshake {
4465 // Bidirectional shutdown with the shim initiating. The runner,
4466 // in the meantime, sends garbage before the close_notify which
4467 // the shim must ignore. This test is disabled under implicit
4468 // handshake tests because the shim never reads or writes.
4469 tests = append(tests, testCase{
4470 name: "Shutdown-Shim",
4471 config: Config{
4472 MaxVersion: VersionTLS12,
4473 Bugs: ProtocolBugs{
4474 ExpectCloseNotify: true,
4475 },
David Benjamin30789da2015-08-29 22:56:45 -04004476 },
David Benjamine3843d42017-03-25 18:00:56 -05004477 shimShutsDown: true,
4478 sendEmptyRecords: 1,
4479 sendWarningAlerts: 1,
4480 flags: []string{"-check-close-notify"},
4481 })
4482 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004483 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004484 // TODO(davidben): DTLS 1.3 will want a similar thing for
4485 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004486 tests = append(tests, testCase{
4487 name: "SkipHelloVerifyRequest",
4488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004489 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004490 Bugs: ProtocolBugs{
4491 SkipHelloVerifyRequest: true,
4492 },
4493 },
4494 })
4495 }
4496
David Benjamin760b1dd2015-05-15 23:33:48 -04004497 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004498 test.protocol = config.protocol
4499 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004500 test.name += "-DTLS"
4501 }
David Benjamin582ba042016-07-07 12:33:25 -07004502 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004503 test.name += "-Async"
4504 test.flags = append(test.flags, "-async")
4505 } else {
4506 test.name += "-Sync"
4507 }
David Benjamin582ba042016-07-07 12:33:25 -07004508 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004509 test.name += "-SplitHandshakeRecords"
4510 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004511 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004512 test.config.Bugs.MaxPacketLength = 256
4513 test.flags = append(test.flags, "-mtu", "256")
4514 }
4515 }
David Benjamin582ba042016-07-07 12:33:25 -07004516 if config.packHandshakeFlight {
4517 test.name += "-PackHandshakeFlight"
4518 test.config.Bugs.PackHandshakeFlight = true
4519 }
David Benjamine3843d42017-03-25 18:00:56 -05004520 if config.implicitHandshake {
4521 test.name += "-ImplicitHandshake"
4522 test.flags = append(test.flags, "-implicit-handshake")
4523 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004524 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004525 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004526}
4527
Adam Langley524e7172015-02-20 16:04:00 -08004528func addDDoSCallbackTests() {
4529 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004530 for _, resume := range []bool{false, true} {
4531 suffix := "Resume"
4532 if resume {
4533 suffix = "No" + suffix
4534 }
4535
4536 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004537 testType: serverTest,
4538 name: "Server-DDoS-OK-" + suffix,
4539 config: Config{
4540 MaxVersion: VersionTLS12,
4541 },
Adam Langley524e7172015-02-20 16:04:00 -08004542 flags: []string{"-install-ddos-callback"},
4543 resumeSession: resume,
4544 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004545 testCases = append(testCases, testCase{
4546 testType: serverTest,
4547 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4548 config: Config{
4549 MaxVersion: VersionTLS13,
4550 },
4551 flags: []string{"-install-ddos-callback"},
4552 resumeSession: resume,
4553 })
Adam Langley524e7172015-02-20 16:04:00 -08004554
4555 failFlag := "-fail-ddos-callback"
4556 if resume {
4557 failFlag = "-fail-second-ddos-callback"
4558 }
4559 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004560 testType: serverTest,
4561 name: "Server-DDoS-Reject-" + suffix,
4562 config: Config{
4563 MaxVersion: VersionTLS12,
4564 },
David Benjamin2c66e072016-09-16 15:58:00 -04004565 flags: []string{"-install-ddos-callback", failFlag},
4566 resumeSession: resume,
4567 shouldFail: true,
4568 expectedError: ":CONNECTION_REJECTED:",
4569 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004570 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004571 testCases = append(testCases, testCase{
4572 testType: serverTest,
4573 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4574 config: Config{
4575 MaxVersion: VersionTLS13,
4576 },
David Benjamin2c66e072016-09-16 15:58:00 -04004577 flags: []string{"-install-ddos-callback", failFlag},
4578 resumeSession: resume,
4579 shouldFail: true,
4580 expectedError: ":CONNECTION_REJECTED:",
4581 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004582 })
Adam Langley524e7172015-02-20 16:04:00 -08004583 }
4584}
4585
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004586func addVersionNegotiationTests() {
4587 for i, shimVers := range tlsVersions {
4588 // Assemble flags to disable all newer versions on the shim.
4589 var flags []string
4590 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004591 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004592 }
4593
Steven Valdezfdd10992016-09-15 16:27:05 -04004594 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004595 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004596 protocols := []protocol{tls}
4597 if runnerVers.hasDTLS && shimVers.hasDTLS {
4598 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004599 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004600 for _, protocol := range protocols {
4601 expectedVersion := shimVers.version
4602 if runnerVers.version < shimVers.version {
4603 expectedVersion = runnerVers.version
4604 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004605
David Benjamin8b8c0062014-11-23 02:47:52 -05004606 suffix := shimVers.name + "-" + runnerVers.name
4607 if protocol == dtls {
4608 suffix += "-DTLS"
4609 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004610
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004611 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004612 clientVers := shimVers.version
4613 if clientVers > VersionTLS10 {
4614 clientVers = VersionTLS10
4615 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004616 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004617 serverVers := expectedVersion
4618 if expectedVersion >= VersionTLS13 {
4619 serverVers = VersionTLS10
4620 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004621 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004622
David Benjamin8b8c0062014-11-23 02:47:52 -05004623 testCases = append(testCases, testCase{
4624 protocol: protocol,
4625 testType: clientTest,
4626 name: "VersionNegotiation-Client-" + suffix,
4627 config: Config{
4628 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004629 Bugs: ProtocolBugs{
4630 ExpectInitialRecordVersion: clientVers,
4631 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004632 },
4633 flags: flags,
4634 expectedVersion: expectedVersion,
4635 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004636 testCases = append(testCases, testCase{
4637 protocol: protocol,
4638 testType: clientTest,
4639 name: "VersionNegotiation-Client2-" + suffix,
4640 config: Config{
4641 MaxVersion: runnerVers.version,
4642 Bugs: ProtocolBugs{
4643 ExpectInitialRecordVersion: clientVers,
4644 },
4645 },
David Benjamin353577c2017-06-29 15:54:58 -04004646 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004647 expectedVersion: expectedVersion,
4648 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004649
4650 testCases = append(testCases, testCase{
4651 protocol: protocol,
4652 testType: serverTest,
4653 name: "VersionNegotiation-Server-" + suffix,
4654 config: Config{
4655 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004656 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004657 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004658 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004659 },
4660 flags: flags,
4661 expectedVersion: expectedVersion,
4662 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004663 testCases = append(testCases, testCase{
4664 protocol: protocol,
4665 testType: serverTest,
4666 name: "VersionNegotiation-Server2-" + suffix,
4667 config: Config{
4668 MaxVersion: runnerVers.version,
4669 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004670 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004671 },
4672 },
David Benjamin353577c2017-06-29 15:54:58 -04004673 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004674 expectedVersion: expectedVersion,
4675 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004676 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004677 }
4678 }
David Benjamin95c69562016-06-29 18:15:03 -04004679
Steven Valdezfdd10992016-09-15 16:27:05 -04004680 // Test the version extension at all versions.
4681 for _, vers := range tlsVersions {
4682 protocols := []protocol{tls}
4683 if vers.hasDTLS {
4684 protocols = append(protocols, dtls)
4685 }
4686 for _, protocol := range protocols {
4687 suffix := vers.name
4688 if protocol == dtls {
4689 suffix += "-DTLS"
4690 }
4691
Steven Valdezc94998a2017-06-20 10:55:02 -04004692 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004693 testCases = append(testCases, testCase{
4694 protocol: protocol,
4695 testType: serverTest,
4696 name: "VersionNegotiationExtension-" + suffix,
4697 config: Config{
4698 Bugs: ProtocolBugs{
4699 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4700 },
4701 },
4702 expectedVersion: vers.version,
4703 })
4704 }
4705
4706 }
4707
4708 // If all versions are unknown, negotiation fails.
4709 testCases = append(testCases, testCase{
4710 testType: serverTest,
4711 name: "NoSupportedVersions",
4712 config: Config{
4713 Bugs: ProtocolBugs{
4714 SendSupportedVersions: []uint16{0x1111},
4715 },
4716 },
4717 shouldFail: true,
4718 expectedError: ":UNSUPPORTED_PROTOCOL:",
4719 })
4720 testCases = append(testCases, testCase{
4721 protocol: dtls,
4722 testType: serverTest,
4723 name: "NoSupportedVersions-DTLS",
4724 config: Config{
4725 Bugs: ProtocolBugs{
4726 SendSupportedVersions: []uint16{0x1111},
4727 },
4728 },
4729 shouldFail: true,
4730 expectedError: ":UNSUPPORTED_PROTOCOL:",
4731 })
4732
4733 testCases = append(testCases, testCase{
4734 testType: serverTest,
4735 name: "ClientHelloVersionTooHigh",
4736 config: Config{
4737 MaxVersion: VersionTLS13,
4738 Bugs: ProtocolBugs{
4739 SendClientVersion: 0x0304,
4740 OmitSupportedVersions: true,
4741 },
4742 },
4743 expectedVersion: VersionTLS12,
4744 })
4745
4746 testCases = append(testCases, testCase{
4747 testType: serverTest,
4748 name: "ConflictingVersionNegotiation",
4749 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004750 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004751 SendClientVersion: VersionTLS12,
4752 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004753 },
4754 },
David Benjaminad75a662016-09-30 15:42:59 -04004755 // The extension takes precedence over the ClientHello version.
4756 expectedVersion: VersionTLS11,
4757 })
4758
4759 testCases = append(testCases, testCase{
4760 testType: serverTest,
4761 name: "ConflictingVersionNegotiation-2",
4762 config: Config{
4763 Bugs: ProtocolBugs{
4764 SendClientVersion: VersionTLS11,
4765 SendSupportedVersions: []uint16{VersionTLS12},
4766 },
4767 },
4768 // The extension takes precedence over the ClientHello version.
4769 expectedVersion: VersionTLS12,
4770 })
4771
4772 testCases = append(testCases, testCase{
4773 testType: serverTest,
4774 name: "RejectFinalTLS13",
4775 config: Config{
4776 Bugs: ProtocolBugs{
4777 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4778 },
4779 },
4780 // We currently implement a draft TLS 1.3 version. Ensure that
4781 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004782 expectedVersion: VersionTLS12,
4783 })
4784
Brian Smithf85d3232016-10-28 10:34:06 -10004785 // Test that the maximum version is selected regardless of the
4786 // client-sent order.
4787 testCases = append(testCases, testCase{
4788 testType: serverTest,
4789 name: "IgnoreClientVersionOrder",
4790 config: Config{
4791 Bugs: ProtocolBugs{
4792 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4793 },
4794 },
4795 expectedVersion: VersionTLS13,
4796 })
4797
David Benjamin95c69562016-06-29 18:15:03 -04004798 // Test for version tolerance.
4799 testCases = append(testCases, testCase{
4800 testType: serverTest,
4801 name: "MinorVersionTolerance",
4802 config: Config{
4803 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004804 SendClientVersion: 0x03ff,
4805 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004806 },
4807 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004808 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004809 })
4810 testCases = append(testCases, testCase{
4811 testType: serverTest,
4812 name: "MajorVersionTolerance",
4813 config: Config{
4814 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004815 SendClientVersion: 0x0400,
4816 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004817 },
4818 },
David Benjaminad75a662016-09-30 15:42:59 -04004819 // TLS 1.3 must be negotiated with the supported_versions
4820 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004821 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004822 })
David Benjaminad75a662016-09-30 15:42:59 -04004823 testCases = append(testCases, testCase{
4824 testType: serverTest,
4825 name: "VersionTolerance-TLS13",
4826 config: Config{
4827 Bugs: ProtocolBugs{
4828 // Although TLS 1.3 does not use
4829 // ClientHello.version, it still tolerates high
4830 // values there.
4831 SendClientVersion: 0x0400,
4832 },
4833 },
4834 expectedVersion: VersionTLS13,
4835 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004836
David Benjamin95c69562016-06-29 18:15:03 -04004837 testCases = append(testCases, testCase{
4838 protocol: dtls,
4839 testType: serverTest,
4840 name: "MinorVersionTolerance-DTLS",
4841 config: Config{
4842 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004843 SendClientVersion: 0xfe00,
4844 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004845 },
4846 },
4847 expectedVersion: VersionTLS12,
4848 })
4849 testCases = append(testCases, testCase{
4850 protocol: dtls,
4851 testType: serverTest,
4852 name: "MajorVersionTolerance-DTLS",
4853 config: Config{
4854 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004855 SendClientVersion: 0xfdff,
4856 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004857 },
4858 },
4859 expectedVersion: VersionTLS12,
4860 })
4861
4862 // Test that versions below 3.0 are rejected.
4863 testCases = append(testCases, testCase{
4864 testType: serverTest,
4865 name: "VersionTooLow",
4866 config: Config{
4867 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004868 SendClientVersion: 0x0200,
4869 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004870 },
4871 },
4872 shouldFail: true,
4873 expectedError: ":UNSUPPORTED_PROTOCOL:",
4874 })
4875 testCases = append(testCases, testCase{
4876 protocol: dtls,
4877 testType: serverTest,
4878 name: "VersionTooLow-DTLS",
4879 config: Config{
4880 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004881 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004882 },
4883 },
4884 shouldFail: true,
4885 expectedError: ":UNSUPPORTED_PROTOCOL:",
4886 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004887
David Benjamin2dc02042016-09-19 19:57:37 -04004888 testCases = append(testCases, testCase{
4889 name: "ServerBogusVersion",
4890 config: Config{
4891 Bugs: ProtocolBugs{
4892 SendServerHelloVersion: 0x1234,
4893 },
4894 },
4895 shouldFail: true,
4896 expectedError: ":UNSUPPORTED_PROTOCOL:",
4897 })
4898
David Benjamin1f61f0d2016-07-10 12:20:35 -04004899 // Test TLS 1.3's downgrade signal.
4900 testCases = append(testCases, testCase{
4901 name: "Downgrade-TLS12-Client",
4902 config: Config{
4903 Bugs: ProtocolBugs{
4904 NegotiateVersion: VersionTLS12,
4905 },
4906 },
David Benjamin592b5322016-09-30 15:15:01 -04004907 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004908 // TODO(davidben): This test should fail once TLS 1.3 is final
4909 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004910 })
4911 testCases = append(testCases, testCase{
4912 testType: serverTest,
4913 name: "Downgrade-TLS12-Server",
4914 config: Config{
4915 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004916 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004917 },
4918 },
David Benjamin592b5322016-09-30 15:15:01 -04004919 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004920 // TODO(davidben): This test should fail once TLS 1.3 is final
4921 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004922 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004923}
4924
David Benjaminaccb4542014-12-12 23:44:33 -05004925func addMinimumVersionTests() {
4926 for i, shimVers := range tlsVersions {
4927 // Assemble flags to disable all older versions on the shim.
4928 var flags []string
4929 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04004930 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05004931 }
4932
4933 for _, runnerVers := range tlsVersions {
4934 protocols := []protocol{tls}
4935 if runnerVers.hasDTLS && shimVers.hasDTLS {
4936 protocols = append(protocols, dtls)
4937 }
4938 for _, protocol := range protocols {
4939 suffix := shimVers.name + "-" + runnerVers.name
4940 if protocol == dtls {
4941 suffix += "-DTLS"
4942 }
David Benjaminaccb4542014-12-12 23:44:33 -05004943
David Benjaminaccb4542014-12-12 23:44:33 -05004944 var expectedVersion uint16
4945 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004946 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004947 if runnerVers.version >= shimVers.version {
4948 expectedVersion = runnerVers.version
4949 } else {
4950 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004951 expectedError = ":UNSUPPORTED_PROTOCOL:"
4952 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004953 }
4954
4955 testCases = append(testCases, testCase{
4956 protocol: protocol,
4957 testType: clientTest,
4958 name: "MinimumVersion-Client-" + suffix,
4959 config: Config{
4960 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004961 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004962 // Ensure the server does not decline to
4963 // select a version (versions extension) or
4964 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04004965 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04004966 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004967 },
David Benjaminaccb4542014-12-12 23:44:33 -05004968 },
David Benjamin87909c02014-12-13 01:55:01 -05004969 flags: flags,
4970 expectedVersion: expectedVersion,
4971 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004972 expectedError: expectedError,
4973 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004974 })
4975 testCases = append(testCases, testCase{
4976 protocol: protocol,
4977 testType: clientTest,
4978 name: "MinimumVersion-Client2-" + suffix,
4979 config: Config{
4980 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004981 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004982 // Ensure the server does not decline to
4983 // select a version (versions extension) or
4984 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04004985 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04004986 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004987 },
David Benjaminaccb4542014-12-12 23:44:33 -05004988 },
David Benjamin353577c2017-06-29 15:54:58 -04004989 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05004990 expectedVersion: expectedVersion,
4991 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004992 expectedError: expectedError,
4993 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004994 })
4995
4996 testCases = append(testCases, testCase{
4997 protocol: protocol,
4998 testType: serverTest,
4999 name: "MinimumVersion-Server-" + suffix,
5000 config: Config{
5001 MaxVersion: runnerVers.version,
5002 },
David Benjamin87909c02014-12-13 01:55:01 -05005003 flags: flags,
5004 expectedVersion: expectedVersion,
5005 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005006 expectedError: expectedError,
5007 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005008 })
5009 testCases = append(testCases, testCase{
5010 protocol: protocol,
5011 testType: serverTest,
5012 name: "MinimumVersion-Server2-" + suffix,
5013 config: Config{
5014 MaxVersion: runnerVers.version,
5015 },
David Benjamin353577c2017-06-29 15:54:58 -04005016 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005017 expectedVersion: expectedVersion,
5018 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005019 expectedError: expectedError,
5020 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005021 })
5022 }
5023 }
5024 }
5025}
5026
David Benjamine78bfde2014-09-06 12:45:15 -04005027func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005028 // TODO(davidben): Extensions, where applicable, all move their server
5029 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5030 // tests for both. Also test interaction with 0-RTT when implemented.
5031
David Benjamin97d17d92016-07-14 16:12:00 -04005032 // Repeat extensions tests all versions except SSL 3.0.
5033 for _, ver := range tlsVersions {
5034 if ver.version == VersionSSL30 {
5035 continue
5036 }
5037
David Benjamin97d17d92016-07-14 16:12:00 -04005038 // Test that duplicate extensions are rejected.
5039 testCases = append(testCases, testCase{
5040 testType: clientTest,
5041 name: "DuplicateExtensionClient-" + ver.name,
5042 config: Config{
5043 MaxVersion: ver.version,
5044 Bugs: ProtocolBugs{
5045 DuplicateExtension: true,
5046 },
David Benjamine78bfde2014-09-06 12:45:15 -04005047 },
David Benjamin97d17d92016-07-14 16:12:00 -04005048 shouldFail: true,
5049 expectedLocalError: "remote error: error decoding message",
5050 })
5051 testCases = append(testCases, testCase{
5052 testType: serverTest,
5053 name: "DuplicateExtensionServer-" + ver.name,
5054 config: Config{
5055 MaxVersion: ver.version,
5056 Bugs: ProtocolBugs{
5057 DuplicateExtension: true,
5058 },
David Benjamine78bfde2014-09-06 12:45:15 -04005059 },
David Benjamin97d17d92016-07-14 16:12:00 -04005060 shouldFail: true,
5061 expectedLocalError: "remote error: error decoding message",
5062 })
5063
5064 // Test SNI.
5065 testCases = append(testCases, testCase{
5066 testType: clientTest,
5067 name: "ServerNameExtensionClient-" + ver.name,
5068 config: Config{
5069 MaxVersion: ver.version,
5070 Bugs: ProtocolBugs{
5071 ExpectServerName: "example.com",
5072 },
David Benjamine78bfde2014-09-06 12:45:15 -04005073 },
David Benjamin97d17d92016-07-14 16:12:00 -04005074 flags: []string{"-host-name", "example.com"},
5075 })
5076 testCases = append(testCases, testCase{
5077 testType: clientTest,
5078 name: "ServerNameExtensionClientMismatch-" + ver.name,
5079 config: Config{
5080 MaxVersion: ver.version,
5081 Bugs: ProtocolBugs{
5082 ExpectServerName: "mismatch.com",
5083 },
David Benjamine78bfde2014-09-06 12:45:15 -04005084 },
David Benjamin97d17d92016-07-14 16:12:00 -04005085 flags: []string{"-host-name", "example.com"},
5086 shouldFail: true,
5087 expectedLocalError: "tls: unexpected server name",
5088 })
5089 testCases = append(testCases, testCase{
5090 testType: clientTest,
5091 name: "ServerNameExtensionClientMissing-" + ver.name,
5092 config: Config{
5093 MaxVersion: ver.version,
5094 Bugs: ProtocolBugs{
5095 ExpectServerName: "missing.com",
5096 },
David Benjamine78bfde2014-09-06 12:45:15 -04005097 },
David Benjamin97d17d92016-07-14 16:12:00 -04005098 shouldFail: true,
5099 expectedLocalError: "tls: unexpected server name",
5100 })
5101 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005102 testType: clientTest,
5103 name: "TolerateServerNameAck-" + ver.name,
5104 config: Config{
5105 MaxVersion: ver.version,
5106 Bugs: ProtocolBugs{
5107 SendServerNameAck: true,
5108 },
5109 },
5110 flags: []string{"-host-name", "example.com"},
5111 resumeSession: true,
5112 })
5113 testCases = append(testCases, testCase{
5114 testType: clientTest,
5115 name: "UnsolicitedServerNameAck-" + ver.name,
5116 config: Config{
5117 MaxVersion: ver.version,
5118 Bugs: ProtocolBugs{
5119 SendServerNameAck: true,
5120 },
5121 },
5122 shouldFail: true,
5123 expectedError: ":UNEXPECTED_EXTENSION:",
5124 expectedLocalError: "remote error: unsupported extension",
5125 })
5126 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005127 testType: serverTest,
5128 name: "ServerNameExtensionServer-" + ver.name,
5129 config: Config{
5130 MaxVersion: ver.version,
5131 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005132 },
David Benjamin97d17d92016-07-14 16:12:00 -04005133 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005134 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005135 })
5136
5137 // Test ALPN.
5138 testCases = append(testCases, testCase{
5139 testType: clientTest,
5140 name: "ALPNClient-" + ver.name,
5141 config: Config{
5142 MaxVersion: ver.version,
5143 NextProtos: []string{"foo"},
5144 },
5145 flags: []string{
5146 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5147 "-expect-alpn", "foo",
5148 },
5149 expectedNextProto: "foo",
5150 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005151 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005152 })
5153 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005154 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005155 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005156 config: Config{
5157 MaxVersion: ver.version,
5158 Bugs: ProtocolBugs{
5159 SendALPN: "baz",
5160 },
5161 },
5162 flags: []string{
5163 "-advertise-alpn", "\x03foo\x03bar",
5164 },
5165 shouldFail: true,
5166 expectedError: ":INVALID_ALPN_PROTOCOL:",
5167 expectedLocalError: "remote error: illegal parameter",
5168 })
5169 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005170 testType: clientTest,
5171 name: "ALPNClient-AllowUnknown-" + ver.name,
5172 config: Config{
5173 MaxVersion: ver.version,
5174 Bugs: ProtocolBugs{
5175 SendALPN: "baz",
5176 },
5177 },
5178 flags: []string{
5179 "-advertise-alpn", "\x03foo\x03bar",
5180 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005181 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005182 },
5183 })
5184 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005185 testType: serverTest,
5186 name: "ALPNServer-" + ver.name,
5187 config: Config{
5188 MaxVersion: ver.version,
5189 NextProtos: []string{"foo", "bar", "baz"},
5190 },
5191 flags: []string{
5192 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5193 "-select-alpn", "foo",
5194 },
5195 expectedNextProto: "foo",
5196 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005197 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005198 })
5199 testCases = append(testCases, testCase{
5200 testType: serverTest,
5201 name: "ALPNServer-Decline-" + ver.name,
5202 config: Config{
5203 MaxVersion: ver.version,
5204 NextProtos: []string{"foo", "bar", "baz"},
5205 },
5206 flags: []string{"-decline-alpn"},
5207 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005208 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005209 })
5210
David Benjamin25fe85b2016-08-09 20:00:32 -04005211 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5212 // called once.
5213 testCases = append(testCases, testCase{
5214 testType: serverTest,
5215 name: "ALPNServer-Async-" + ver.name,
5216 config: Config{
5217 MaxVersion: ver.version,
5218 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005219 // Prior to TLS 1.3, exercise the asynchronous session callback.
5220 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005221 },
5222 flags: []string{
5223 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5224 "-select-alpn", "foo",
5225 "-async",
5226 },
5227 expectedNextProto: "foo",
5228 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005229 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005230 })
5231
David Benjamin97d17d92016-07-14 16:12:00 -04005232 var emptyString string
5233 testCases = append(testCases, testCase{
5234 testType: clientTest,
5235 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5236 config: Config{
5237 MaxVersion: ver.version,
5238 NextProtos: []string{""},
5239 Bugs: ProtocolBugs{
5240 // A server returning an empty ALPN protocol
5241 // should be rejected.
5242 ALPNProtocol: &emptyString,
5243 },
5244 },
5245 flags: []string{
5246 "-advertise-alpn", "\x03foo",
5247 },
5248 shouldFail: true,
5249 expectedError: ":PARSE_TLSEXT:",
5250 })
5251 testCases = append(testCases, testCase{
5252 testType: serverTest,
5253 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5254 config: Config{
5255 MaxVersion: ver.version,
5256 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005257 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005258 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005259 },
David Benjamin97d17d92016-07-14 16:12:00 -04005260 flags: []string{
5261 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005262 },
David Benjamin97d17d92016-07-14 16:12:00 -04005263 shouldFail: true,
5264 expectedError: ":PARSE_TLSEXT:",
5265 })
5266
5267 // Test NPN and the interaction with ALPN.
5268 if ver.version < VersionTLS13 {
5269 // Test that the server prefers ALPN over NPN.
5270 testCases = append(testCases, testCase{
5271 testType: serverTest,
5272 name: "ALPNServer-Preferred-" + ver.name,
5273 config: Config{
5274 MaxVersion: ver.version,
5275 NextProtos: []string{"foo", "bar", "baz"},
5276 },
5277 flags: []string{
5278 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5279 "-select-alpn", "foo",
5280 "-advertise-npn", "\x03foo\x03bar\x03baz",
5281 },
5282 expectedNextProto: "foo",
5283 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005284 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005285 })
5286 testCases = append(testCases, testCase{
5287 testType: serverTest,
5288 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5289 config: Config{
5290 MaxVersion: ver.version,
5291 NextProtos: []string{"foo", "bar", "baz"},
5292 Bugs: ProtocolBugs{
5293 SwapNPNAndALPN: true,
5294 },
5295 },
5296 flags: []string{
5297 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5298 "-select-alpn", "foo",
5299 "-advertise-npn", "\x03foo\x03bar\x03baz",
5300 },
5301 expectedNextProto: "foo",
5302 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005303 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005304 })
5305
5306 // Test that negotiating both NPN and ALPN is forbidden.
5307 testCases = append(testCases, testCase{
5308 name: "NegotiateALPNAndNPN-" + ver.name,
5309 config: Config{
5310 MaxVersion: ver.version,
5311 NextProtos: []string{"foo", "bar", "baz"},
5312 Bugs: ProtocolBugs{
5313 NegotiateALPNAndNPN: true,
5314 },
5315 },
5316 flags: []string{
5317 "-advertise-alpn", "\x03foo",
5318 "-select-next-proto", "foo",
5319 },
5320 shouldFail: true,
5321 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5322 })
5323 testCases = append(testCases, testCase{
5324 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5325 config: Config{
5326 MaxVersion: ver.version,
5327 NextProtos: []string{"foo", "bar", "baz"},
5328 Bugs: ProtocolBugs{
5329 NegotiateALPNAndNPN: true,
5330 SwapNPNAndALPN: true,
5331 },
5332 },
5333 flags: []string{
5334 "-advertise-alpn", "\x03foo",
5335 "-select-next-proto", "foo",
5336 },
5337 shouldFail: true,
5338 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5339 })
David Benjamin97d17d92016-07-14 16:12:00 -04005340 }
5341
5342 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005343
5344 // Resume with a corrupt ticket.
5345 testCases = append(testCases, testCase{
5346 testType: serverTest,
5347 name: "CorruptTicket-" + ver.name,
5348 config: Config{
5349 MaxVersion: ver.version,
5350 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005351 FilterTicket: func(in []byte) ([]byte, error) {
5352 in[len(in)-1] ^= 1
5353 return in, nil
5354 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005355 },
5356 },
5357 resumeSession: true,
5358 expectResumeRejected: true,
5359 })
5360 // Test the ticket callback, with and without renewal.
5361 testCases = append(testCases, testCase{
5362 testType: serverTest,
5363 name: "TicketCallback-" + ver.name,
5364 config: Config{
5365 MaxVersion: ver.version,
5366 },
5367 resumeSession: true,
5368 flags: []string{"-use-ticket-callback"},
5369 })
5370 testCases = append(testCases, testCase{
5371 testType: serverTest,
5372 name: "TicketCallback-Renew-" + ver.name,
5373 config: Config{
5374 MaxVersion: ver.version,
5375 Bugs: ProtocolBugs{
5376 ExpectNewTicket: true,
5377 },
5378 },
5379 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5380 resumeSession: true,
5381 })
5382
5383 // Test that the ticket callback is only called once when everything before
5384 // it in the ClientHello is asynchronous. This corrupts the ticket so
5385 // certificate selection callbacks run.
5386 testCases = append(testCases, testCase{
5387 testType: serverTest,
5388 name: "TicketCallback-SingleCall-" + ver.name,
5389 config: Config{
5390 MaxVersion: ver.version,
5391 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005392 FilterTicket: func(in []byte) ([]byte, error) {
5393 in[len(in)-1] ^= 1
5394 return in, nil
5395 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005396 },
5397 },
5398 resumeSession: true,
5399 expectResumeRejected: true,
5400 flags: []string{
5401 "-use-ticket-callback",
5402 "-async",
5403 },
5404 })
5405
David Benjamind4c349b2017-02-09 14:07:17 -05005406 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005407 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005408 testCases = append(testCases, testCase{
5409 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005410 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005411 config: Config{
5412 MaxVersion: ver.version,
5413 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005414 EmptyTicketSessionID: true,
5415 },
5416 },
5417 resumeSession: true,
5418 })
5419 testCases = append(testCases, testCase{
5420 testType: serverTest,
5421 name: "TicketSessionIDLength-16-" + ver.name,
5422 config: Config{
5423 MaxVersion: ver.version,
5424 Bugs: ProtocolBugs{
5425 TicketSessionIDLength: 16,
5426 },
5427 },
5428 resumeSession: true,
5429 })
5430 testCases = append(testCases, testCase{
5431 testType: serverTest,
5432 name: "TicketSessionIDLength-32-" + ver.name,
5433 config: Config{
5434 MaxVersion: ver.version,
5435 Bugs: ProtocolBugs{
5436 TicketSessionIDLength: 32,
5437 },
5438 },
5439 resumeSession: true,
5440 })
5441 testCases = append(testCases, testCase{
5442 testType: serverTest,
5443 name: "TicketSessionIDLength-33-" + ver.name,
5444 config: Config{
5445 MaxVersion: ver.version,
5446 Bugs: ProtocolBugs{
5447 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005448 },
5449 },
5450 resumeSession: true,
5451 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005452 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005453 expectedError: ":DECODE_ERROR:",
5454 })
5455 }
5456
5457 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5458 // are ignored.
5459 if ver.hasDTLS {
5460 testCases = append(testCases, testCase{
5461 protocol: dtls,
5462 name: "SRTP-Client-" + ver.name,
5463 config: Config{
5464 MaxVersion: ver.version,
5465 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5466 },
5467 flags: []string{
5468 "-srtp-profiles",
5469 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5470 },
5471 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5472 })
5473 testCases = append(testCases, testCase{
5474 protocol: dtls,
5475 testType: serverTest,
5476 name: "SRTP-Server-" + ver.name,
5477 config: Config{
5478 MaxVersion: ver.version,
5479 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5480 },
5481 flags: []string{
5482 "-srtp-profiles",
5483 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5484 },
5485 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5486 })
5487 // Test that the MKI is ignored.
5488 testCases = append(testCases, testCase{
5489 protocol: dtls,
5490 testType: serverTest,
5491 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5492 config: Config{
5493 MaxVersion: ver.version,
5494 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5495 Bugs: ProtocolBugs{
5496 SRTPMasterKeyIdentifer: "bogus",
5497 },
5498 },
5499 flags: []string{
5500 "-srtp-profiles",
5501 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5502 },
5503 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5504 })
5505 // Test that SRTP isn't negotiated on the server if there were
5506 // no matching profiles.
5507 testCases = append(testCases, testCase{
5508 protocol: dtls,
5509 testType: serverTest,
5510 name: "SRTP-Server-NoMatch-" + ver.name,
5511 config: Config{
5512 MaxVersion: ver.version,
5513 SRTPProtectionProfiles: []uint16{100, 101, 102},
5514 },
5515 flags: []string{
5516 "-srtp-profiles",
5517 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5518 },
5519 expectedSRTPProtectionProfile: 0,
5520 })
5521 // Test that the server returning an invalid SRTP profile is
5522 // flagged as an error by the client.
5523 testCases = append(testCases, testCase{
5524 protocol: dtls,
5525 name: "SRTP-Client-NoMatch-" + ver.name,
5526 config: Config{
5527 MaxVersion: ver.version,
5528 Bugs: ProtocolBugs{
5529 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5530 },
5531 },
5532 flags: []string{
5533 "-srtp-profiles",
5534 "SRTP_AES128_CM_SHA1_80",
5535 },
5536 shouldFail: true,
5537 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5538 })
5539 }
5540
5541 // Test SCT list.
5542 testCases = append(testCases, testCase{
5543 name: "SignedCertificateTimestampList-Client-" + ver.name,
5544 testType: clientTest,
5545 config: Config{
5546 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005547 },
David Benjamin97d17d92016-07-14 16:12:00 -04005548 flags: []string{
5549 "-enable-signed-cert-timestamps",
5550 "-expect-signed-cert-timestamps",
5551 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005552 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005553 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005554 })
David Benjamindaa88502016-10-04 16:32:16 -04005555
Adam Langleycfa08c32016-11-17 13:21:27 -08005556 var differentSCTList []byte
5557 differentSCTList = append(differentSCTList, testSCTList...)
5558 differentSCTList[len(differentSCTList)-1] ^= 1
5559
David Benjamindaa88502016-10-04 16:32:16 -04005560 // The SCT extension did not specify that it must only be sent on resumption as it
5561 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005562 testCases = append(testCases, testCase{
5563 name: "SendSCTListOnResume-" + ver.name,
5564 config: Config{
5565 MaxVersion: ver.version,
5566 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005567 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005568 },
David Benjamind98452d2015-06-16 14:16:23 -04005569 },
David Benjamin97d17d92016-07-14 16:12:00 -04005570 flags: []string{
5571 "-enable-signed-cert-timestamps",
5572 "-expect-signed-cert-timestamps",
5573 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005574 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005575 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005576 })
David Benjamindaa88502016-10-04 16:32:16 -04005577
David Benjamin97d17d92016-07-14 16:12:00 -04005578 testCases = append(testCases, testCase{
5579 name: "SignedCertificateTimestampList-Server-" + ver.name,
5580 testType: serverTest,
5581 config: Config{
5582 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005583 },
David Benjamin97d17d92016-07-14 16:12:00 -04005584 flags: []string{
5585 "-signed-cert-timestamps",
5586 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005587 },
David Benjamin97d17d92016-07-14 16:12:00 -04005588 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005589 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005590 })
David Benjamin53210cb2016-11-16 09:01:48 +09005591
Adam Langleycfa08c32016-11-17 13:21:27 -08005592 emptySCTListCert := *testCerts[0].cert
5593 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5594
5595 // Test empty SCT list.
5596 testCases = append(testCases, testCase{
5597 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5598 testType: clientTest,
5599 config: Config{
5600 MaxVersion: ver.version,
5601 Certificates: []Certificate{emptySCTListCert},
5602 },
5603 flags: []string{
5604 "-enable-signed-cert-timestamps",
5605 },
5606 shouldFail: true,
5607 expectedError: ":ERROR_PARSING_EXTENSION:",
5608 })
5609
5610 emptySCTCert := *testCerts[0].cert
5611 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5612
5613 // Test empty SCT in non-empty list.
5614 testCases = append(testCases, testCase{
5615 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5616 testType: clientTest,
5617 config: Config{
5618 MaxVersion: ver.version,
5619 Certificates: []Certificate{emptySCTCert},
5620 },
5621 flags: []string{
5622 "-enable-signed-cert-timestamps",
5623 },
5624 shouldFail: true,
5625 expectedError: ":ERROR_PARSING_EXTENSION:",
5626 })
5627
David Benjamin53210cb2016-11-16 09:01:48 +09005628 // Test that certificate-related extensions are not sent unsolicited.
5629 testCases = append(testCases, testCase{
5630 testType: serverTest,
5631 name: "UnsolicitedCertificateExtensions-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 Bugs: ProtocolBugs{
5635 NoOCSPStapling: true,
5636 NoSignedCertificateTimestamps: true,
5637 },
5638 },
5639 flags: []string{
5640 "-ocsp-response",
5641 base64.StdEncoding.EncodeToString(testOCSPResponse),
5642 "-signed-cert-timestamps",
5643 base64.StdEncoding.EncodeToString(testSCTList),
5644 },
5645 })
David Benjamin97d17d92016-07-14 16:12:00 -04005646 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005647
Paul Lietar4fac72e2015-09-09 13:44:55 +01005648 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005649 testType: clientTest,
5650 name: "ClientHelloPadding",
5651 config: Config{
5652 Bugs: ProtocolBugs{
5653 RequireClientHelloSize: 512,
5654 },
5655 },
5656 // This hostname just needs to be long enough to push the
5657 // ClientHello into F5's danger zone between 256 and 511 bytes
5658 // long.
5659 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5660 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005661
5662 // Extensions should not function in SSL 3.0.
5663 testCases = append(testCases, testCase{
5664 testType: serverTest,
5665 name: "SSLv3Extensions-NoALPN",
5666 config: Config{
5667 MaxVersion: VersionSSL30,
5668 NextProtos: []string{"foo", "bar", "baz"},
5669 },
5670 flags: []string{
5671 "-select-alpn", "foo",
5672 },
5673 expectNoNextProto: true,
5674 })
5675
5676 // Test session tickets separately as they follow a different codepath.
5677 testCases = append(testCases, testCase{
5678 testType: serverTest,
5679 name: "SSLv3Extensions-NoTickets",
5680 config: Config{
5681 MaxVersion: VersionSSL30,
5682 Bugs: ProtocolBugs{
5683 // Historically, session tickets in SSL 3.0
5684 // failed in different ways depending on whether
5685 // the client supported renegotiation_info.
5686 NoRenegotiationInfo: true,
5687 },
5688 },
5689 resumeSession: true,
5690 })
5691 testCases = append(testCases, testCase{
5692 testType: serverTest,
5693 name: "SSLv3Extensions-NoTickets2",
5694 config: Config{
5695 MaxVersion: VersionSSL30,
5696 },
5697 resumeSession: true,
5698 })
5699
5700 // But SSL 3.0 does send and process renegotiation_info.
5701 testCases = append(testCases, testCase{
5702 testType: serverTest,
5703 name: "SSLv3Extensions-RenegotiationInfo",
5704 config: Config{
5705 MaxVersion: VersionSSL30,
5706 Bugs: ProtocolBugs{
5707 RequireRenegotiationInfo: true,
5708 },
5709 },
David Benjamind2610042017-01-03 10:49:28 -05005710 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005711 })
5712 testCases = append(testCases, testCase{
5713 testType: serverTest,
5714 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5715 config: Config{
5716 MaxVersion: VersionSSL30,
5717 Bugs: ProtocolBugs{
5718 NoRenegotiationInfo: true,
5719 SendRenegotiationSCSV: true,
5720 RequireRenegotiationInfo: true,
5721 },
5722 },
David Benjamind2610042017-01-03 10:49:28 -05005723 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005724 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005725
5726 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5727 // in ServerHello.
5728 testCases = append(testCases, testCase{
5729 name: "NPN-Forbidden-TLS13",
5730 config: Config{
5731 MaxVersion: VersionTLS13,
5732 NextProtos: []string{"foo"},
5733 Bugs: ProtocolBugs{
5734 NegotiateNPNAtAllVersions: true,
5735 },
5736 },
5737 flags: []string{"-select-next-proto", "foo"},
5738 shouldFail: true,
5739 expectedError: ":ERROR_PARSING_EXTENSION:",
5740 })
5741 testCases = append(testCases, testCase{
5742 name: "EMS-Forbidden-TLS13",
5743 config: Config{
5744 MaxVersion: VersionTLS13,
5745 Bugs: ProtocolBugs{
5746 NegotiateEMSAtAllVersions: true,
5747 },
5748 },
5749 shouldFail: true,
5750 expectedError: ":ERROR_PARSING_EXTENSION:",
5751 })
5752 testCases = append(testCases, testCase{
5753 name: "RenegotiationInfo-Forbidden-TLS13",
5754 config: Config{
5755 MaxVersion: VersionTLS13,
5756 Bugs: ProtocolBugs{
5757 NegotiateRenegotiationInfoAtAllVersions: true,
5758 },
5759 },
5760 shouldFail: true,
5761 expectedError: ":ERROR_PARSING_EXTENSION:",
5762 })
5763 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005764 name: "Ticket-Forbidden-TLS13",
5765 config: Config{
5766 MaxVersion: VersionTLS12,
5767 },
5768 resumeConfig: &Config{
5769 MaxVersion: VersionTLS13,
5770 Bugs: ProtocolBugs{
5771 AdvertiseTicketExtension: true,
5772 },
5773 },
5774 resumeSession: true,
5775 shouldFail: true,
5776 expectedError: ":ERROR_PARSING_EXTENSION:",
5777 })
5778
5779 // Test that illegal extensions in TLS 1.3 are declined by the server if
5780 // offered in ClientHello. The runner's server will fail if this occurs,
5781 // so we exercise the offering path. (EMS and Renegotiation Info are
5782 // implicit in every test.)
5783 testCases = append(testCases, testCase{
5784 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005785 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005786 config: Config{
5787 MaxVersion: VersionTLS13,
5788 NextProtos: []string{"bar"},
5789 },
5790 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5791 })
David Benjamin196df5b2016-09-21 16:23:27 -04005792
David Benjamindaa88502016-10-04 16:32:16 -04005793 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5794 // tolerated.
5795 testCases = append(testCases, testCase{
5796 name: "SendOCSPResponseOnResume-TLS12",
5797 config: Config{
5798 MaxVersion: VersionTLS12,
5799 Bugs: ProtocolBugs{
5800 SendOCSPResponseOnResume: []byte("bogus"),
5801 },
5802 },
5803 flags: []string{
5804 "-enable-ocsp-stapling",
5805 "-expect-ocsp-response",
5806 base64.StdEncoding.EncodeToString(testOCSPResponse),
5807 },
5808 resumeSession: true,
5809 })
5810
David Benjamindaa88502016-10-04 16:32:16 -04005811 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005812 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005813 config: Config{
5814 MaxVersion: VersionTLS13,
5815 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005816 SendExtensionOnCertificate: testOCSPExtension,
5817 },
5818 },
5819 shouldFail: true,
5820 expectedError: ":UNEXPECTED_EXTENSION:",
5821 })
5822
5823 testCases = append(testCases, testCase{
5824 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5825 config: Config{
5826 MaxVersion: VersionTLS13,
5827 Bugs: ProtocolBugs{
5828 SendExtensionOnCertificate: testSCTExtension,
5829 },
5830 },
5831 shouldFail: true,
5832 expectedError: ":UNEXPECTED_EXTENSION:",
5833 })
5834
5835 // Test that extensions on client certificates are never accepted.
5836 testCases = append(testCases, testCase{
5837 name: "SendExtensionOnClientCertificate-TLS13",
5838 testType: serverTest,
5839 config: Config{
5840 MaxVersion: VersionTLS13,
5841 Certificates: []Certificate{rsaCertificate},
5842 Bugs: ProtocolBugs{
5843 SendExtensionOnCertificate: testOCSPExtension,
5844 },
5845 },
5846 flags: []string{
5847 "-enable-ocsp-stapling",
5848 "-require-any-client-certificate",
5849 },
5850 shouldFail: true,
5851 expectedError: ":UNEXPECTED_EXTENSION:",
5852 })
5853
5854 testCases = append(testCases, testCase{
5855 name: "SendUnknownExtensionOnCertificate-TLS13",
5856 config: Config{
5857 MaxVersion: VersionTLS13,
5858 Bugs: ProtocolBugs{
5859 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5860 },
5861 },
5862 shouldFail: true,
5863 expectedError: ":UNEXPECTED_EXTENSION:",
5864 })
5865
Adam Langleycfa08c32016-11-17 13:21:27 -08005866 var differentSCTList []byte
5867 differentSCTList = append(differentSCTList, testSCTList...)
5868 differentSCTList[len(differentSCTList)-1] ^= 1
5869
Steven Valdeza833c352016-11-01 13:39:36 -04005870 // Test that extensions on intermediates are allowed but ignored.
5871 testCases = append(testCases, testCase{
5872 name: "IgnoreExtensionsOnIntermediates-TLS13",
5873 config: Config{
5874 MaxVersion: VersionTLS13,
5875 Certificates: []Certificate{rsaChainCertificate},
5876 Bugs: ProtocolBugs{
5877 // Send different values on the intermediate. This tests
5878 // the intermediate's extensions do not override the
5879 // leaf's.
5880 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005881 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005882 },
5883 },
5884 flags: []string{
5885 "-enable-ocsp-stapling",
5886 "-expect-ocsp-response",
5887 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005888 "-enable-signed-cert-timestamps",
5889 "-expect-signed-cert-timestamps",
5890 base64.StdEncoding.EncodeToString(testSCTList),
5891 },
5892 resumeSession: true,
5893 })
5894
5895 // Test that extensions are not sent on intermediates when configured
5896 // only for a leaf.
5897 testCases = append(testCases, testCase{
5898 testType: serverTest,
5899 name: "SendNoExtensionsOnIntermediate-TLS13",
5900 config: Config{
5901 MaxVersion: VersionTLS13,
5902 Bugs: ProtocolBugs{
5903 ExpectNoExtensionsOnIntermediate: true,
5904 },
5905 },
5906 flags: []string{
5907 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5908 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5909 "-ocsp-response",
5910 base64.StdEncoding.EncodeToString(testOCSPResponse),
5911 "-signed-cert-timestamps",
5912 base64.StdEncoding.EncodeToString(testSCTList),
5913 },
5914 })
5915
5916 // Test that extensions are not sent on client certificates.
5917 testCases = append(testCases, testCase{
5918 name: "SendNoClientCertificateExtensions-TLS13",
5919 config: Config{
5920 MaxVersion: VersionTLS13,
5921 ClientAuth: RequireAnyClientCert,
5922 },
5923 flags: []string{
5924 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5925 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5926 "-ocsp-response",
5927 base64.StdEncoding.EncodeToString(testOCSPResponse),
5928 "-signed-cert-timestamps",
5929 base64.StdEncoding.EncodeToString(testSCTList),
5930 },
5931 })
5932
5933 testCases = append(testCases, testCase{
5934 name: "SendDuplicateExtensionsOnCerts-TLS13",
5935 config: Config{
5936 MaxVersion: VersionTLS13,
5937 Bugs: ProtocolBugs{
5938 SendDuplicateCertExtensions: true,
5939 },
5940 },
5941 flags: []string{
5942 "-enable-ocsp-stapling",
5943 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005944 },
5945 resumeSession: true,
5946 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005947 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005948 })
Adam Langley9b885c52016-11-18 14:21:03 -08005949
5950 testCases = append(testCases, testCase{
5951 name: "SignedCertificateTimestampListInvalid-Server",
5952 testType: serverTest,
5953 flags: []string{
5954 "-signed-cert-timestamps",
5955 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5956 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005957 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005958 expectedError: ":INVALID_SCT_LIST:",
5959 })
David Benjamine78bfde2014-09-06 12:45:15 -04005960}
5961
David Benjamin01fe8202014-09-24 15:21:44 -04005962func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005963 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005964 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005965 // SSL 3.0 does not have tickets and TLS 1.3 does not
5966 // have session IDs, so skip their cross-resumption
5967 // tests.
5968 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5969 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5970 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005971 }
5972
David Benjamin8b8c0062014-11-23 02:47:52 -05005973 protocols := []protocol{tls}
5974 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5975 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005976 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005977 for _, protocol := range protocols {
5978 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5979 if protocol == dtls {
5980 suffix += "-DTLS"
5981 }
5982
David Benjaminece3de92015-03-16 18:02:20 -04005983 if sessionVers.version == resumeVers.version {
5984 testCases = append(testCases, testCase{
5985 protocol: protocol,
5986 name: "Resume-Client" + suffix,
5987 resumeSession: true,
5988 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005989 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005990 Bugs: ProtocolBugs{
5991 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5992 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5993 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005994 },
David Benjaminece3de92015-03-16 18:02:20 -04005995 expectedVersion: sessionVers.version,
5996 expectedResumeVersion: resumeVers.version,
5997 })
5998 } else {
David Benjamin405da482016-08-08 17:25:07 -04005999 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6000
6001 // Offering a TLS 1.3 session sends an empty session ID, so
6002 // there is no way to convince a non-lookahead client the
6003 // session was resumed. It will appear to the client that a
6004 // stray ChangeCipherSpec was sent.
6005 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6006 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006007 }
6008
David Benjaminece3de92015-03-16 18:02:20 -04006009 testCases = append(testCases, testCase{
6010 protocol: protocol,
6011 name: "Resume-Client-Mismatch" + suffix,
6012 resumeSession: true,
6013 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006014 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006015 },
David Benjaminece3de92015-03-16 18:02:20 -04006016 expectedVersion: sessionVers.version,
6017 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006018 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006019 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006020 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006021 },
6022 },
6023 expectedResumeVersion: resumeVers.version,
6024 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006025 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006026 })
6027 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006028
6029 testCases = append(testCases, testCase{
6030 protocol: protocol,
6031 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006032 resumeSession: true,
6033 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006034 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006035 },
6036 expectedVersion: sessionVers.version,
6037 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006038 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006039 },
6040 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006041 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006042 expectedResumeVersion: resumeVers.version,
6043 })
6044
David Benjamin8b8c0062014-11-23 02:47:52 -05006045 testCases = append(testCases, testCase{
6046 protocol: protocol,
6047 testType: serverTest,
6048 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006049 resumeSession: true,
6050 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006051 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006052 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006053 expectedVersion: sessionVers.version,
6054 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006055 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006056 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006057 Bugs: ProtocolBugs{
6058 SendBothTickets: true,
6059 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006060 },
6061 expectedResumeVersion: resumeVers.version,
6062 })
6063 }
David Benjamin01fe8202014-09-24 15:21:44 -04006064 }
6065 }
David Benjaminece3de92015-03-16 18:02:20 -04006066
David Benjamin4199b0d2016-11-01 13:58:25 -04006067 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006068 testCases = append(testCases, testCase{
6069 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006070 name: "ShimTicketRewritable",
6071 resumeSession: true,
6072 config: Config{
6073 MaxVersion: VersionTLS12,
6074 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6075 Bugs: ProtocolBugs{
6076 FilterTicket: func(in []byte) ([]byte, error) {
6077 in, err := SetShimTicketVersion(in, VersionTLS12)
6078 if err != nil {
6079 return nil, err
6080 }
6081 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6082 },
6083 },
6084 },
6085 flags: []string{
6086 "-ticket-key",
6087 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6088 },
6089 })
6090
6091 // Resumptions are declined if the version does not match.
6092 testCases = append(testCases, testCase{
6093 testType: serverTest,
6094 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006095 resumeSession: true,
6096 config: Config{
6097 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006098 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006099 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006100 FilterTicket: func(in []byte) ([]byte, error) {
6101 return SetShimTicketVersion(in, VersionTLS13)
6102 },
6103 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006104 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006105 flags: []string{
6106 "-ticket-key",
6107 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6108 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006109 expectResumeRejected: true,
6110 })
6111
6112 testCases = append(testCases, testCase{
6113 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006114 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006115 resumeSession: true,
6116 config: Config{
6117 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006118 Bugs: ProtocolBugs{
6119 FilterTicket: func(in []byte) ([]byte, error) {
6120 return SetShimTicketVersion(in, VersionTLS12)
6121 },
6122 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006123 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006124 flags: []string{
6125 "-ticket-key",
6126 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6127 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006128 expectResumeRejected: true,
6129 })
6130
David Benjamin4199b0d2016-11-01 13:58:25 -04006131 // Resumptions are declined if the cipher is invalid or disabled.
6132 testCases = append(testCases, testCase{
6133 testType: serverTest,
6134 name: "Resume-Server-DeclineBadCipher",
6135 resumeSession: true,
6136 config: Config{
6137 MaxVersion: VersionTLS12,
6138 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006139 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006140 FilterTicket: func(in []byte) ([]byte, error) {
6141 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6142 },
6143 },
6144 },
6145 flags: []string{
6146 "-ticket-key",
6147 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6148 },
6149 expectResumeRejected: true,
6150 })
6151
6152 testCases = append(testCases, testCase{
6153 testType: serverTest,
6154 name: "Resume-Server-DeclineBadCipher-2",
6155 resumeSession: true,
6156 config: Config{
6157 MaxVersion: VersionTLS12,
6158 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006159 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006160 FilterTicket: func(in []byte) ([]byte, error) {
6161 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6162 },
6163 },
6164 },
6165 flags: []string{
6166 "-cipher", "AES128",
6167 "-ticket-key",
6168 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6169 },
6170 expectResumeRejected: true,
6171 })
6172
David Benjaminf01f42a2016-11-16 19:05:33 +09006173 // Sessions are not resumed if they do not use the preferred cipher.
6174 testCases = append(testCases, testCase{
6175 testType: serverTest,
6176 name: "Resume-Server-CipherNotPreferred",
6177 resumeSession: true,
6178 config: Config{
6179 MaxVersion: VersionTLS12,
6180 Bugs: ProtocolBugs{
6181 ExpectNewTicket: true,
6182 FilterTicket: func(in []byte) ([]byte, error) {
6183 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6184 },
6185 },
6186 },
6187 flags: []string{
6188 "-ticket-key",
6189 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6190 },
6191 shouldFail: false,
6192 expectResumeRejected: true,
6193 })
6194
6195 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6196 // PRF hashes match, but BoringSSL will always decline such resumptions.
6197 testCases = append(testCases, testCase{
6198 testType: serverTest,
6199 name: "Resume-Server-CipherNotPreferred-TLS13",
6200 resumeSession: true,
6201 config: Config{
6202 MaxVersion: VersionTLS13,
6203 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6204 Bugs: ProtocolBugs{
6205 FilterTicket: func(in []byte) ([]byte, error) {
6206 // If the client (runner) offers ChaCha20-Poly1305 first, the
6207 // server (shim) always prefers it. Switch it to AES-GCM.
6208 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6209 },
6210 },
6211 },
6212 flags: []string{
6213 "-ticket-key",
6214 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6215 },
6216 shouldFail: false,
6217 expectResumeRejected: true,
6218 })
6219
6220 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006221 testCases = append(testCases, testCase{
6222 testType: serverTest,
6223 name: "Resume-Server-DeclineBadCipher-TLS13",
6224 resumeSession: true,
6225 config: Config{
6226 MaxVersion: VersionTLS13,
6227 Bugs: ProtocolBugs{
6228 FilterTicket: func(in []byte) ([]byte, error) {
6229 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6230 },
6231 },
6232 },
6233 flags: []string{
6234 "-ticket-key",
6235 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6236 },
6237 expectResumeRejected: true,
6238 })
6239
David Benjaminf01f42a2016-11-16 19:05:33 +09006240 // If the client does not offer the cipher from the session, decline to
6241 // resume. Clients are forbidden from doing this, but BoringSSL selects
6242 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006243 testCases = append(testCases, testCase{
6244 testType: serverTest,
6245 name: "Resume-Server-UnofferedCipher",
6246 resumeSession: true,
6247 config: Config{
6248 MaxVersion: VersionTLS12,
6249 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6250 },
6251 resumeConfig: &Config{
6252 MaxVersion: VersionTLS12,
6253 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6254 Bugs: ProtocolBugs{
6255 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6256 },
6257 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006258 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006259 })
6260
David Benjaminf01f42a2016-11-16 19:05:33 +09006261 // In TLS 1.3, clients may advertise a cipher list which does not
6262 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006263 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6264 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006265 testCases = append(testCases, testCase{
6266 testType: serverTest,
6267 name: "Resume-Server-UnofferedCipher-TLS13",
6268 resumeSession: true,
6269 config: Config{
6270 MaxVersion: VersionTLS13,
6271 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6272 },
6273 resumeConfig: &Config{
6274 MaxVersion: VersionTLS13,
6275 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6276 Bugs: ProtocolBugs{
6277 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6278 },
6279 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006280 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006281 })
6282
David Benjamin4199b0d2016-11-01 13:58:25 -04006283 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006284 testCases = append(testCases, testCase{
6285 name: "Resume-Client-CipherMismatch",
6286 resumeSession: true,
6287 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006288 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006289 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6290 },
6291 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006292 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006293 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6294 Bugs: ProtocolBugs{
6295 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6296 },
6297 },
6298 shouldFail: true,
6299 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6300 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006301
David Benjamine1cc35e2016-11-16 16:25:58 +09006302 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6303 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006304 testCases = append(testCases, testCase{
6305 name: "Resume-Client-CipherMismatch-TLS13",
6306 resumeSession: true,
6307 config: Config{
6308 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006309 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006310 },
6311 resumeConfig: &Config{
6312 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006313 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6314 },
6315 })
6316
6317 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6318 testCases = append(testCases, testCase{
6319 name: "Resume-Client-PRFMismatch-TLS13",
6320 resumeSession: true,
6321 config: Config{
6322 MaxVersion: VersionTLS13,
6323 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6324 },
6325 resumeConfig: &Config{
6326 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006327 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006328 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006329 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006330 },
6331 },
6332 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006333 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006334 })
Steven Valdeza833c352016-11-01 13:39:36 -04006335
6336 testCases = append(testCases, testCase{
6337 testType: serverTest,
6338 name: "Resume-Server-BinderWrongLength",
6339 resumeSession: true,
6340 config: Config{
6341 MaxVersion: VersionTLS13,
6342 Bugs: ProtocolBugs{
6343 SendShortPSKBinder: true,
6344 },
6345 },
6346 shouldFail: true,
6347 expectedLocalError: "remote error: error decrypting message",
6348 expectedError: ":DIGEST_CHECK_FAILED:",
6349 })
6350
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "Resume-Server-NoPSKBinder",
6354 resumeSession: true,
6355 config: Config{
6356 MaxVersion: VersionTLS13,
6357 Bugs: ProtocolBugs{
6358 SendNoPSKBinder: true,
6359 },
6360 },
6361 shouldFail: true,
6362 expectedLocalError: "remote error: error decoding message",
6363 expectedError: ":DECODE_ERROR:",
6364 })
6365
6366 testCases = append(testCases, testCase{
6367 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006368 name: "Resume-Server-ExtraPSKBinder",
6369 resumeSession: true,
6370 config: Config{
6371 MaxVersion: VersionTLS13,
6372 Bugs: ProtocolBugs{
6373 SendExtraPSKBinder: true,
6374 },
6375 },
6376 shouldFail: true,
6377 expectedLocalError: "remote error: illegal parameter",
6378 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6379 })
6380
6381 testCases = append(testCases, testCase{
6382 testType: serverTest,
6383 name: "Resume-Server-ExtraIdentityNoBinder",
6384 resumeSession: true,
6385 config: Config{
6386 MaxVersion: VersionTLS13,
6387 Bugs: ProtocolBugs{
6388 ExtraPSKIdentity: true,
6389 },
6390 },
6391 shouldFail: true,
6392 expectedLocalError: "remote error: illegal parameter",
6393 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6394 })
6395
6396 testCases = append(testCases, testCase{
6397 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006398 name: "Resume-Server-InvalidPSKBinder",
6399 resumeSession: true,
6400 config: Config{
6401 MaxVersion: VersionTLS13,
6402 Bugs: ProtocolBugs{
6403 SendInvalidPSKBinder: true,
6404 },
6405 },
6406 shouldFail: true,
6407 expectedLocalError: "remote error: error decrypting message",
6408 expectedError: ":DIGEST_CHECK_FAILED:",
6409 })
6410
6411 testCases = append(testCases, testCase{
6412 testType: serverTest,
6413 name: "Resume-Server-PSKBinderFirstExtension",
6414 resumeSession: true,
6415 config: Config{
6416 MaxVersion: VersionTLS13,
6417 Bugs: ProtocolBugs{
6418 PSKBinderFirst: true,
6419 },
6420 },
6421 shouldFail: true,
6422 expectedLocalError: "remote error: illegal parameter",
6423 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6424 })
David Benjamin01fe8202014-09-24 15:21:44 -04006425}
6426
Adam Langley2ae77d22014-10-28 17:29:33 -07006427func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006428 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006429 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006430 testType: serverTest,
6431 name: "Renegotiate-Server-Forbidden",
6432 config: Config{
6433 MaxVersion: VersionTLS12,
6434 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006435 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006436 shouldFail: true,
6437 expectedError: ":NO_RENEGOTIATION:",
6438 expectedLocalError: "remote error: no renegotiation",
6439 })
Adam Langley5021b222015-06-12 18:27:58 -07006440 // The server shouldn't echo the renegotiation extension unless
6441 // requested by the client.
6442 testCases = append(testCases, testCase{
6443 testType: serverTest,
6444 name: "Renegotiate-Server-NoExt",
6445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006446 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006447 Bugs: ProtocolBugs{
6448 NoRenegotiationInfo: true,
6449 RequireRenegotiationInfo: true,
6450 },
6451 },
6452 shouldFail: true,
6453 expectedLocalError: "renegotiation extension missing",
6454 })
6455 // The renegotiation SCSV should be sufficient for the server to echo
6456 // the extension.
6457 testCases = append(testCases, testCase{
6458 testType: serverTest,
6459 name: "Renegotiate-Server-NoExt-SCSV",
6460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006461 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006462 Bugs: ProtocolBugs{
6463 NoRenegotiationInfo: true,
6464 SendRenegotiationSCSV: true,
6465 RequireRenegotiationInfo: true,
6466 },
6467 },
6468 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006469 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006470 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006472 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006473 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006474 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006475 },
6476 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006477 renegotiate: 1,
6478 flags: []string{
6479 "-renegotiate-freely",
6480 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006481 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006482 },
David Benjamincdea40c2015-03-19 14:09:43 -04006483 })
6484 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006485 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006486 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006488 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006489 Bugs: ProtocolBugs{
6490 EmptyRenegotiationInfo: true,
6491 },
6492 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006493 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006494 shouldFail: true,
6495 expectedError: ":RENEGOTIATION_MISMATCH:",
6496 })
6497 testCases = append(testCases, testCase{
6498 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006499 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006500 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006501 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006502 Bugs: ProtocolBugs{
6503 BadRenegotiationInfo: true,
6504 },
6505 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006506 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006507 shouldFail: true,
6508 expectedError: ":RENEGOTIATION_MISMATCH:",
6509 })
6510 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006511 name: "Renegotiate-Client-BadExt2",
6512 renegotiate: 1,
6513 config: Config{
6514 MaxVersion: VersionTLS12,
6515 Bugs: ProtocolBugs{
6516 BadRenegotiationInfoEnd: true,
6517 },
6518 },
6519 flags: []string{"-renegotiate-freely"},
6520 shouldFail: true,
6521 expectedError: ":RENEGOTIATION_MISMATCH:",
6522 })
6523 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006524 name: "Renegotiate-Client-Downgrade",
6525 renegotiate: 1,
6526 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006527 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006528 Bugs: ProtocolBugs{
6529 NoRenegotiationInfoAfterInitial: true,
6530 },
6531 },
6532 flags: []string{"-renegotiate-freely"},
6533 shouldFail: true,
6534 expectedError: ":RENEGOTIATION_MISMATCH:",
6535 })
6536 testCases = append(testCases, testCase{
6537 name: "Renegotiate-Client-Upgrade",
6538 renegotiate: 1,
6539 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006540 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006541 Bugs: ProtocolBugs{
6542 NoRenegotiationInfoInInitial: true,
6543 },
6544 },
6545 flags: []string{"-renegotiate-freely"},
6546 shouldFail: true,
6547 expectedError: ":RENEGOTIATION_MISMATCH:",
6548 })
6549 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006550 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006551 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006553 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006554 Bugs: ProtocolBugs{
6555 NoRenegotiationInfo: true,
6556 },
6557 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006558 flags: []string{
6559 "-renegotiate-freely",
6560 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006561 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006562 },
David Benjamincff0b902015-05-15 23:09:47 -04006563 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006564
6565 // Test that the server may switch ciphers on renegotiation without
6566 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006567 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006568 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006569 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006570 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006571 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006572 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006573 },
6574 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006575 flags: []string{
6576 "-renegotiate-freely",
6577 "-expect-total-renegotiations", "1",
6578 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006579 })
6580 testCases = append(testCases, testCase{
6581 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006582 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006583 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006584 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006585 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6586 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006587 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006588 flags: []string{
6589 "-renegotiate-freely",
6590 "-expect-total-renegotiations", "1",
6591 },
David Benjaminb16346b2015-04-08 19:16:58 -04006592 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006593
6594 // Test that the server may not switch versions on renegotiation.
6595 testCases = append(testCases, testCase{
6596 name: "Renegotiate-Client-SwitchVersion",
6597 config: Config{
6598 MaxVersion: VersionTLS12,
6599 // Pick a cipher which exists at both versions.
6600 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6601 Bugs: ProtocolBugs{
6602 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006603 // Avoid failing early at the record layer.
6604 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006605 },
6606 },
6607 renegotiate: 1,
6608 flags: []string{
6609 "-renegotiate-freely",
6610 "-expect-total-renegotiations", "1",
6611 },
6612 shouldFail: true,
6613 expectedError: ":WRONG_SSL_VERSION:",
6614 })
6615
David Benjaminb16346b2015-04-08 19:16:58 -04006616 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006617 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006618 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006619 config: Config{
6620 MaxVersion: VersionTLS10,
6621 Bugs: ProtocolBugs{
6622 RequireSameRenegoClientVersion: true,
6623 },
6624 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006625 flags: []string{
6626 "-renegotiate-freely",
6627 "-expect-total-renegotiations", "1",
6628 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006629 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006630 testCases = append(testCases, testCase{
6631 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006632 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006633 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006634 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6636 NextProtos: []string{"foo"},
6637 },
6638 flags: []string{
6639 "-false-start",
6640 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006641 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006642 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006643 },
6644 shimWritesFirst: true,
6645 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006646
6647 // Client-side renegotiation controls.
6648 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006649 name: "Renegotiate-Client-Forbidden-1",
6650 config: Config{
6651 MaxVersion: VersionTLS12,
6652 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006653 renegotiate: 1,
6654 shouldFail: true,
6655 expectedError: ":NO_RENEGOTIATION:",
6656 expectedLocalError: "remote error: no renegotiation",
6657 })
6658 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006659 name: "Renegotiate-Client-Once-1",
6660 config: Config{
6661 MaxVersion: VersionTLS12,
6662 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006663 renegotiate: 1,
6664 flags: []string{
6665 "-renegotiate-once",
6666 "-expect-total-renegotiations", "1",
6667 },
6668 })
6669 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006670 name: "Renegotiate-Client-Freely-1",
6671 config: Config{
6672 MaxVersion: VersionTLS12,
6673 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006674 renegotiate: 1,
6675 flags: []string{
6676 "-renegotiate-freely",
6677 "-expect-total-renegotiations", "1",
6678 },
6679 })
6680 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006681 name: "Renegotiate-Client-Once-2",
6682 config: Config{
6683 MaxVersion: VersionTLS12,
6684 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006685 renegotiate: 2,
6686 flags: []string{"-renegotiate-once"},
6687 shouldFail: true,
6688 expectedError: ":NO_RENEGOTIATION:",
6689 expectedLocalError: "remote error: no renegotiation",
6690 })
6691 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006692 name: "Renegotiate-Client-Freely-2",
6693 config: Config{
6694 MaxVersion: VersionTLS12,
6695 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006696 renegotiate: 2,
6697 flags: []string{
6698 "-renegotiate-freely",
6699 "-expect-total-renegotiations", "2",
6700 },
6701 })
Adam Langley27a0d082015-11-03 13:34:10 -08006702 testCases = append(testCases, testCase{
6703 name: "Renegotiate-Client-NoIgnore",
6704 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006705 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006706 Bugs: ProtocolBugs{
6707 SendHelloRequestBeforeEveryAppDataRecord: true,
6708 },
6709 },
6710 shouldFail: true,
6711 expectedError: ":NO_RENEGOTIATION:",
6712 })
6713 testCases = append(testCases, testCase{
6714 name: "Renegotiate-Client-Ignore",
6715 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006716 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006717 Bugs: ProtocolBugs{
6718 SendHelloRequestBeforeEveryAppDataRecord: true,
6719 },
6720 },
6721 flags: []string{
6722 "-renegotiate-ignore",
6723 "-expect-total-renegotiations", "0",
6724 },
6725 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006726
David Benjamin34941c02016-10-08 11:45:31 -04006727 // Renegotiation is not allowed at SSL 3.0.
6728 testCases = append(testCases, testCase{
6729 name: "Renegotiate-Client-SSL3",
6730 config: Config{
6731 MaxVersion: VersionSSL30,
6732 },
6733 renegotiate: 1,
6734 flags: []string{
6735 "-renegotiate-freely",
6736 "-expect-total-renegotiations", "1",
6737 },
6738 shouldFail: true,
6739 expectedError: ":NO_RENEGOTIATION:",
6740 expectedLocalError: "remote error: no renegotiation",
6741 })
6742
David Benjamina1eaba12017-01-01 23:19:22 -05006743 // Renegotiation is not allowed when there is an unfinished write.
6744 testCases = append(testCases, testCase{
6745 name: "Renegotiate-Client-UnfinishedWrite",
6746 config: Config{
6747 MaxVersion: VersionTLS12,
6748 },
David Benjaminbbba9392017-04-06 12:54:12 -04006749 renegotiate: 1,
6750 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006751 flags: []string{
6752 "-async",
6753 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006754 },
6755 shouldFail: true,
6756 expectedError: ":NO_RENEGOTIATION:",
6757 // We do not successfully send the no_renegotiation alert in
6758 // this case. https://crbug.com/boringssl/130
6759 })
6760
David Benjamin07ab5d42017-02-09 20:11:41 -05006761 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006762 testCases = append(testCases, testCase{
6763 name: "StrayHelloRequest",
6764 config: Config{
6765 MaxVersion: VersionTLS12,
6766 Bugs: ProtocolBugs{
6767 SendHelloRequestBeforeEveryHandshakeMessage: true,
6768 },
6769 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006770 shouldFail: true,
6771 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006772 })
6773 testCases = append(testCases, testCase{
6774 name: "StrayHelloRequest-Packed",
6775 config: Config{
6776 MaxVersion: VersionTLS12,
6777 Bugs: ProtocolBugs{
6778 PackHandshakeFlight: true,
6779 SendHelloRequestBeforeEveryHandshakeMessage: true,
6780 },
6781 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006782 shouldFail: true,
6783 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006784 })
6785
David Benjamin12d2c482016-07-24 10:56:51 -04006786 // Test renegotiation works if HelloRequest and server Finished come in
6787 // the same record.
6788 testCases = append(testCases, testCase{
6789 name: "Renegotiate-Client-Packed",
6790 config: Config{
6791 MaxVersion: VersionTLS12,
6792 Bugs: ProtocolBugs{
6793 PackHandshakeFlight: true,
6794 PackHelloRequestWithFinished: true,
6795 },
6796 },
6797 renegotiate: 1,
6798 flags: []string{
6799 "-renegotiate-freely",
6800 "-expect-total-renegotiations", "1",
6801 },
6802 })
6803
David Benjamin397c8e62016-07-08 14:14:36 -07006804 // Renegotiation is forbidden in TLS 1.3.
6805 testCases = append(testCases, testCase{
6806 name: "Renegotiate-Client-TLS13",
6807 config: Config{
6808 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006809 Bugs: ProtocolBugs{
6810 SendHelloRequestBeforeEveryAppDataRecord: true,
6811 },
David Benjamin397c8e62016-07-08 14:14:36 -07006812 },
David Benjamin397c8e62016-07-08 14:14:36 -07006813 flags: []string{
6814 "-renegotiate-freely",
6815 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006816 shouldFail: true,
6817 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006818 })
6819
6820 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6821 testCases = append(testCases, testCase{
6822 name: "StrayHelloRequest-TLS13",
6823 config: Config{
6824 MaxVersion: VersionTLS13,
6825 Bugs: ProtocolBugs{
6826 SendHelloRequestBeforeEveryHandshakeMessage: true,
6827 },
6828 },
6829 shouldFail: true,
6830 expectedError: ":UNEXPECTED_MESSAGE:",
6831 })
David Benjamind2610042017-01-03 10:49:28 -05006832
6833 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6834 // always reads as supporting it, regardless of whether it was
6835 // negotiated.
6836 testCases = append(testCases, testCase{
6837 name: "AlwaysReportRenegotiationInfo-TLS13",
6838 config: Config{
6839 MaxVersion: VersionTLS13,
6840 Bugs: ProtocolBugs{
6841 NoRenegotiationInfo: true,
6842 },
6843 },
6844 flags: []string{
6845 "-expect-secure-renegotiation",
6846 },
6847 })
David Benjamina58baaf2017-02-28 20:54:28 -05006848
6849 // Certificates may not change on renegotiation.
6850 testCases = append(testCases, testCase{
6851 name: "Renegotiation-CertificateChange",
6852 config: Config{
6853 MaxVersion: VersionTLS12,
6854 Certificates: []Certificate{rsaCertificate},
6855 Bugs: ProtocolBugs{
6856 RenegotiationCertificate: &rsaChainCertificate,
6857 },
6858 },
6859 renegotiate: 1,
6860 flags: []string{"-renegotiate-freely"},
6861 shouldFail: true,
6862 expectedError: ":SERVER_CERT_CHANGED:",
6863 })
6864 testCases = append(testCases, testCase{
6865 name: "Renegotiation-CertificateChange-2",
6866 config: Config{
6867 MaxVersion: VersionTLS12,
6868 Certificates: []Certificate{rsaCertificate},
6869 Bugs: ProtocolBugs{
6870 RenegotiationCertificate: &rsa1024Certificate,
6871 },
6872 },
6873 renegotiate: 1,
6874 flags: []string{"-renegotiate-freely"},
6875 shouldFail: true,
6876 expectedError: ":SERVER_CERT_CHANGED:",
6877 })
David Benjaminbbf42462017-03-14 21:27:10 -04006878
6879 // We do not negotiate ALPN after the initial handshake. This is
6880 // error-prone and only risks bugs in consumers.
6881 testCases = append(testCases, testCase{
6882 testType: clientTest,
6883 name: "Renegotiation-ForbidALPN",
6884 config: Config{
6885 MaxVersion: VersionTLS12,
6886 Bugs: ProtocolBugs{
6887 // Forcibly negotiate ALPN on both initial and
6888 // renegotiation handshakes. The test stack will
6889 // internally check the client does not offer
6890 // it.
6891 SendALPN: "foo",
6892 },
6893 },
6894 flags: []string{
6895 "-advertise-alpn", "\x03foo\x03bar\x03baz",
6896 "-expect-alpn", "foo",
6897 "-renegotiate-freely",
6898 },
6899 renegotiate: 1,
6900 shouldFail: true,
6901 expectedError: ":UNEXPECTED_EXTENSION:",
6902 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006903}
6904
David Benjamin5e961c12014-11-07 01:48:35 -05006905func addDTLSReplayTests() {
6906 // Test that sequence number replays are detected.
6907 testCases = append(testCases, testCase{
6908 protocol: dtls,
6909 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006910 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006911 replayWrites: true,
6912 })
6913
David Benjamin8e6db492015-07-25 18:29:23 -04006914 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006915 // than the retransmit window.
6916 testCases = append(testCases, testCase{
6917 protocol: dtls,
6918 name: "DTLS-Replay-LargeGaps",
6919 config: Config{
6920 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006921 SequenceNumberMapping: func(in uint64) uint64 {
6922 return in * 127
6923 },
David Benjamin5e961c12014-11-07 01:48:35 -05006924 },
6925 },
David Benjamin8e6db492015-07-25 18:29:23 -04006926 messageCount: 200,
6927 replayWrites: true,
6928 })
6929
6930 // Test the incoming sequence number changing non-monotonically.
6931 testCases = append(testCases, testCase{
6932 protocol: dtls,
6933 name: "DTLS-Replay-NonMonotonic",
6934 config: Config{
6935 Bugs: ProtocolBugs{
6936 SequenceNumberMapping: func(in uint64) uint64 {
6937 return in ^ 31
6938 },
6939 },
6940 },
6941 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006942 replayWrites: true,
6943 })
6944}
6945
Nick Harper60edffd2016-06-21 15:19:24 -07006946var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006947 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006948 id signatureAlgorithm
6949 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006950}{
Nick Harper60edffd2016-06-21 15:19:24 -07006951 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6952 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6953 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6954 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006955 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08006956 // The “P256” in the following line is not a mistake. In TLS 1.2 the
6957 // hash function doesn't have to match the curve and so the same
6958 // signature algorithm works with P-224.
6959 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07006960 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6961 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6962 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006963 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6964 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6965 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05006966 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04006967 // Tests for key types prior to TLS 1.2.
6968 {"RSA", 0, testCertRSA},
6969 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006970}
6971
Nick Harper60edffd2016-06-21 15:19:24 -07006972const fakeSigAlg1 signatureAlgorithm = 0x2a01
6973const fakeSigAlg2 signatureAlgorithm = 0xff01
6974
6975func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006976 // Not all ciphers involve a signature. Advertise a list which gives all
6977 // versions a signing cipher.
6978 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006979 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006980 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6981 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6982 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6983 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006984 }
David Benjamin5208fd42016-07-13 21:43:25 -04006985
David Benjaminca3d5452016-07-14 12:51:01 -04006986 var allAlgorithms []signatureAlgorithm
6987 for _, alg := range testSignatureAlgorithms {
6988 if alg.id != 0 {
6989 allAlgorithms = append(allAlgorithms, alg.id)
6990 }
6991 }
6992
Nick Harper60edffd2016-06-21 15:19:24 -07006993 // Make sure each signature algorithm works. Include some fake values in
6994 // the list and ensure they're ignored.
6995 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006996 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006997 if (ver.version < VersionTLS12) != (alg.id == 0) {
6998 continue
6999 }
7000
7001 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7002 // or remove it in C.
7003 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007004 continue
7005 }
Nick Harper60edffd2016-06-21 15:19:24 -07007006
David Benjamin3ef76972016-10-17 17:59:54 -04007007 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007008 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007009 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007010 shouldSignFail = true
7011 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007012 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007013 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007014 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7015 shouldSignFail = true
7016 shouldVerifyFail = true
7017 }
7018 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7019 // the curve has to match the hash size.
7020 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007021 shouldSignFail = true
7022 shouldVerifyFail = true
7023 }
7024
7025 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7026 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7027 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007028 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007029
7030 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007031 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007032 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007033 }
7034 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007035 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007036 }
David Benjamin000800a2014-11-14 01:43:59 -05007037
David Benjamin1fb125c2016-07-08 18:52:12 -07007038 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007039
David Benjamin7a41d372016-07-09 11:21:54 -07007040 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007041 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007042 config: Config{
7043 MaxVersion: ver.version,
7044 ClientAuth: RequireAnyClientCert,
7045 VerifySignatureAlgorithms: []signatureAlgorithm{
7046 fakeSigAlg1,
7047 alg.id,
7048 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007049 },
David Benjamin7a41d372016-07-09 11:21:54 -07007050 },
7051 flags: []string{
7052 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7053 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7054 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007055 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007056 },
David Benjamin3ef76972016-10-17 17:59:54 -04007057 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007058 expectedError: signError,
7059 expectedPeerSignatureAlgorithm: alg.id,
7060 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007061
David Benjamin7a41d372016-07-09 11:21:54 -07007062 testCases = append(testCases, testCase{
7063 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007064 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007065 config: Config{
7066 MaxVersion: ver.version,
7067 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7068 SignSignatureAlgorithms: []signatureAlgorithm{
7069 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007070 },
David Benjamin7a41d372016-07-09 11:21:54 -07007071 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007072 SkipECDSACurveCheck: shouldVerifyFail,
7073 IgnoreSignatureVersionChecks: shouldVerifyFail,
7074 // Some signature algorithms may not be advertised.
7075 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007076 },
David Benjamin7a41d372016-07-09 11:21:54 -07007077 },
7078 flags: []string{
7079 "-require-any-client-certificate",
7080 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7081 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007082 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007083 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007084 // Resume the session to assert the peer signature
7085 // algorithm is reported on both handshakes.
7086 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007087 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007088 expectedError: verifyError,
7089 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007090
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007091 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007092 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007093 testCases = append(testCases, testCase{
7094 testType: serverTest,
7095 name: "ServerAuth-Sign" + suffix,
7096 config: Config{
7097 MaxVersion: ver.version,
7098 CipherSuites: signingCiphers,
7099 VerifySignatureAlgorithms: []signatureAlgorithm{
7100 fakeSigAlg1,
7101 alg.id,
7102 fakeSigAlg2,
7103 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007104 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007105 flags: []string{
7106 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7107 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7108 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007109 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007110 },
7111 shouldFail: shouldSignFail,
7112 expectedError: signError,
7113 expectedPeerSignatureAlgorithm: alg.id,
7114 })
7115 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007116
7117 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007118 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007119 config: Config{
7120 MaxVersion: ver.version,
7121 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007122 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007123 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007124 alg.id,
7125 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007126 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007127 SkipECDSACurveCheck: shouldVerifyFail,
7128 IgnoreSignatureVersionChecks: shouldVerifyFail,
7129 // Some signature algorithms may not be advertised.
7130 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007131 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007132 },
7133 flags: []string{
7134 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7135 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007136 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007137 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007138 // Resume the session to assert the peer signature
7139 // algorithm is reported on both handshakes.
7140 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007141 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007142 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007143 })
David Benjamin5208fd42016-07-13 21:43:25 -04007144
David Benjamin3ef76972016-10-17 17:59:54 -04007145 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007146 testCases = append(testCases, testCase{
7147 testType: serverTest,
7148 name: "ClientAuth-InvalidSignature" + suffix,
7149 config: Config{
7150 MaxVersion: ver.version,
7151 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7152 SignSignatureAlgorithms: []signatureAlgorithm{
7153 alg.id,
7154 },
7155 Bugs: ProtocolBugs{
7156 InvalidSignature: true,
7157 },
7158 },
7159 flags: []string{
7160 "-require-any-client-certificate",
7161 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007162 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007163 },
7164 shouldFail: true,
7165 expectedError: ":BAD_SIGNATURE:",
7166 })
7167
7168 testCases = append(testCases, testCase{
7169 name: "ServerAuth-InvalidSignature" + suffix,
7170 config: Config{
7171 MaxVersion: ver.version,
7172 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7173 CipherSuites: signingCiphers,
7174 SignSignatureAlgorithms: []signatureAlgorithm{
7175 alg.id,
7176 },
7177 Bugs: ProtocolBugs{
7178 InvalidSignature: true,
7179 },
7180 },
David Benjamin69522112017-03-28 15:38:29 -05007181 flags: []string{
7182 "-enable-all-curves",
7183 "-enable-ed25519",
7184 },
David Benjamin5208fd42016-07-13 21:43:25 -04007185 shouldFail: true,
7186 expectedError: ":BAD_SIGNATURE:",
7187 })
7188 }
David Benjaminca3d5452016-07-14 12:51:01 -04007189
David Benjamin3ef76972016-10-17 17:59:54 -04007190 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007191 testCases = append(testCases, testCase{
7192 name: "ClientAuth-Sign-Negotiate" + suffix,
7193 config: Config{
7194 MaxVersion: ver.version,
7195 ClientAuth: RequireAnyClientCert,
7196 VerifySignatureAlgorithms: allAlgorithms,
7197 },
7198 flags: []string{
7199 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7200 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7201 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007202 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007203 "-signing-prefs", strconv.Itoa(int(alg.id)),
7204 },
7205 expectedPeerSignatureAlgorithm: alg.id,
7206 })
7207
7208 testCases = append(testCases, testCase{
7209 testType: serverTest,
7210 name: "ServerAuth-Sign-Negotiate" + suffix,
7211 config: Config{
7212 MaxVersion: ver.version,
7213 CipherSuites: signingCiphers,
7214 VerifySignatureAlgorithms: allAlgorithms,
7215 },
7216 flags: []string{
7217 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7218 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7219 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007220 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007221 "-signing-prefs", strconv.Itoa(int(alg.id)),
7222 },
7223 expectedPeerSignatureAlgorithm: alg.id,
7224 })
7225 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007226 }
David Benjamin000800a2014-11-14 01:43:59 -05007227 }
7228
Nick Harper60edffd2016-06-21 15:19:24 -07007229 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007230 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007231 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007232 config: Config{
7233 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007234 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007235 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007236 signatureECDSAWithP521AndSHA512,
7237 signatureRSAPKCS1WithSHA384,
7238 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007239 },
7240 },
7241 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007242 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7243 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007244 },
Nick Harper60edffd2016-06-21 15:19:24 -07007245 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007246 })
7247
7248 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007249 name: "ClientAuth-SignatureType-TLS13",
7250 config: Config{
7251 ClientAuth: RequireAnyClientCert,
7252 MaxVersion: VersionTLS13,
7253 VerifySignatureAlgorithms: []signatureAlgorithm{
7254 signatureECDSAWithP521AndSHA512,
7255 signatureRSAPKCS1WithSHA384,
7256 signatureRSAPSSWithSHA384,
7257 signatureECDSAWithSHA1,
7258 },
7259 },
7260 flags: []string{
7261 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7262 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7263 },
7264 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7265 })
7266
7267 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007268 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007269 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007270 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007271 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007272 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007273 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007274 signatureECDSAWithP521AndSHA512,
7275 signatureRSAPKCS1WithSHA384,
7276 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007277 },
7278 },
Nick Harper60edffd2016-06-21 15:19:24 -07007279 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007280 })
7281
Steven Valdez143e8b32016-07-11 13:19:03 -04007282 testCases = append(testCases, testCase{
7283 testType: serverTest,
7284 name: "ServerAuth-SignatureType-TLS13",
7285 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007286 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007287 VerifySignatureAlgorithms: []signatureAlgorithm{
7288 signatureECDSAWithP521AndSHA512,
7289 signatureRSAPKCS1WithSHA384,
7290 signatureRSAPSSWithSHA384,
7291 signatureECDSAWithSHA1,
7292 },
7293 },
7294 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7295 })
7296
David Benjamina95e9f32016-07-08 16:28:04 -07007297 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007298 testCases = append(testCases, testCase{
7299 testType: serverTest,
7300 name: "Verify-ClientAuth-SignatureType",
7301 config: Config{
7302 MaxVersion: VersionTLS12,
7303 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007304 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007305 signatureRSAPKCS1WithSHA256,
7306 },
7307 Bugs: ProtocolBugs{
7308 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7309 },
7310 },
7311 flags: []string{
7312 "-require-any-client-certificate",
7313 },
7314 shouldFail: true,
7315 expectedError: ":WRONG_SIGNATURE_TYPE:",
7316 })
7317
7318 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007319 testType: serverTest,
7320 name: "Verify-ClientAuth-SignatureType-TLS13",
7321 config: Config{
7322 MaxVersion: VersionTLS13,
7323 Certificates: []Certificate{rsaCertificate},
7324 SignSignatureAlgorithms: []signatureAlgorithm{
7325 signatureRSAPSSWithSHA256,
7326 },
7327 Bugs: ProtocolBugs{
7328 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7329 },
7330 },
7331 flags: []string{
7332 "-require-any-client-certificate",
7333 },
7334 shouldFail: true,
7335 expectedError: ":WRONG_SIGNATURE_TYPE:",
7336 })
7337
7338 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007339 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007340 config: Config{
7341 MaxVersion: VersionTLS12,
7342 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007343 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007344 signatureRSAPKCS1WithSHA256,
7345 },
7346 Bugs: ProtocolBugs{
7347 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7348 },
7349 },
7350 shouldFail: true,
7351 expectedError: ":WRONG_SIGNATURE_TYPE:",
7352 })
7353
Steven Valdez143e8b32016-07-11 13:19:03 -04007354 testCases = append(testCases, testCase{
7355 name: "Verify-ServerAuth-SignatureType-TLS13",
7356 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007357 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007358 SignSignatureAlgorithms: []signatureAlgorithm{
7359 signatureRSAPSSWithSHA256,
7360 },
7361 Bugs: ProtocolBugs{
7362 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":WRONG_SIGNATURE_TYPE:",
7367 })
7368
David Benjamin51dd7d62016-07-08 16:07:01 -07007369 // Test that, if the list is missing, the peer falls back to SHA-1 in
7370 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007371 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007372 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007374 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007375 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007376 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007377 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007378 },
7379 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007380 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007381 },
7382 },
7383 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007384 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7385 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007386 },
7387 })
7388
7389 testCases = append(testCases, testCase{
7390 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007391 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007392 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007393 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007394 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007395 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007396 },
7397 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007398 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007399 },
7400 },
David Benjaminee32bea2016-08-17 13:36:44 -04007401 flags: []string{
7402 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7403 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7404 },
7405 })
7406
7407 testCases = append(testCases, testCase{
7408 name: "ClientAuth-SHA1-Fallback-ECDSA",
7409 config: Config{
7410 MaxVersion: VersionTLS12,
7411 ClientAuth: RequireAnyClientCert,
7412 VerifySignatureAlgorithms: []signatureAlgorithm{
7413 signatureECDSAWithSHA1,
7414 },
7415 Bugs: ProtocolBugs{
7416 NoSignatureAlgorithms: true,
7417 },
7418 },
7419 flags: []string{
7420 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7421 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7422 },
7423 })
7424
7425 testCases = append(testCases, testCase{
7426 testType: serverTest,
7427 name: "ServerAuth-SHA1-Fallback-ECDSA",
7428 config: Config{
7429 MaxVersion: VersionTLS12,
7430 VerifySignatureAlgorithms: []signatureAlgorithm{
7431 signatureECDSAWithSHA1,
7432 },
7433 Bugs: ProtocolBugs{
7434 NoSignatureAlgorithms: true,
7435 },
7436 },
7437 flags: []string{
7438 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7439 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7440 },
David Benjamin000800a2014-11-14 01:43:59 -05007441 })
David Benjamin72dc7832015-03-16 17:49:43 -04007442
David Benjamin51dd7d62016-07-08 16:07:01 -07007443 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007444 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007445 config: Config{
7446 MaxVersion: VersionTLS13,
7447 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007448 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007449 signatureRSAPKCS1WithSHA1,
7450 },
7451 Bugs: ProtocolBugs{
7452 NoSignatureAlgorithms: true,
7453 },
7454 },
7455 flags: []string{
7456 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7457 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7458 },
David Benjamin48901652016-08-01 12:12:47 -04007459 shouldFail: true,
7460 // An empty CertificateRequest signature algorithm list is a
7461 // syntax error in TLS 1.3.
7462 expectedError: ":DECODE_ERROR:",
7463 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007464 })
7465
7466 testCases = append(testCases, testCase{
7467 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007468 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007469 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007470 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007471 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007472 signatureRSAPKCS1WithSHA1,
7473 },
7474 Bugs: ProtocolBugs{
7475 NoSignatureAlgorithms: true,
7476 },
7477 },
7478 shouldFail: true,
7479 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7480 })
7481
David Benjaminb62d2872016-07-18 14:55:02 +02007482 // Test that hash preferences are enforced. BoringSSL does not implement
7483 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007484 testCases = append(testCases, testCase{
7485 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007486 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007488 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007489 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007490 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007491 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007492 },
7493 Bugs: ProtocolBugs{
7494 IgnorePeerSignatureAlgorithmPreferences: true,
7495 },
7496 },
7497 flags: []string{"-require-any-client-certificate"},
7498 shouldFail: true,
7499 expectedError: ":WRONG_SIGNATURE_TYPE:",
7500 })
7501
7502 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007503 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007505 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007506 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007507 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007508 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007509 },
7510 Bugs: ProtocolBugs{
7511 IgnorePeerSignatureAlgorithmPreferences: true,
7512 },
7513 },
7514 shouldFail: true,
7515 expectedError: ":WRONG_SIGNATURE_TYPE:",
7516 })
David Benjaminb62d2872016-07-18 14:55:02 +02007517 testCases = append(testCases, testCase{
7518 testType: serverTest,
7519 name: "ClientAuth-Enforced-TLS13",
7520 config: Config{
7521 MaxVersion: VersionTLS13,
7522 Certificates: []Certificate{rsaCertificate},
7523 SignSignatureAlgorithms: []signatureAlgorithm{
7524 signatureRSAPKCS1WithMD5,
7525 },
7526 Bugs: ProtocolBugs{
7527 IgnorePeerSignatureAlgorithmPreferences: true,
7528 IgnoreSignatureVersionChecks: true,
7529 },
7530 },
7531 flags: []string{"-require-any-client-certificate"},
7532 shouldFail: true,
7533 expectedError: ":WRONG_SIGNATURE_TYPE:",
7534 })
7535
7536 testCases = append(testCases, testCase{
7537 name: "ServerAuth-Enforced-TLS13",
7538 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007539 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007540 SignSignatureAlgorithms: []signatureAlgorithm{
7541 signatureRSAPKCS1WithMD5,
7542 },
7543 Bugs: ProtocolBugs{
7544 IgnorePeerSignatureAlgorithmPreferences: true,
7545 IgnoreSignatureVersionChecks: true,
7546 },
7547 },
7548 shouldFail: true,
7549 expectedError: ":WRONG_SIGNATURE_TYPE:",
7550 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007551
7552 // Test that the agreed upon digest respects the client preferences and
7553 // the server digests.
7554 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007555 name: "NoCommonAlgorithms-Digests",
7556 config: Config{
7557 MaxVersion: VersionTLS12,
7558 ClientAuth: RequireAnyClientCert,
7559 VerifySignatureAlgorithms: []signatureAlgorithm{
7560 signatureRSAPKCS1WithSHA512,
7561 signatureRSAPKCS1WithSHA1,
7562 },
7563 },
7564 flags: []string{
7565 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7566 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7567 "-digest-prefs", "SHA256",
7568 },
7569 shouldFail: true,
7570 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7571 })
7572 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007573 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007575 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007576 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007577 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007578 signatureRSAPKCS1WithSHA512,
7579 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007580 },
7581 },
7582 flags: []string{
7583 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7584 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007585 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007586 },
David Benjaminca3d5452016-07-14 12:51:01 -04007587 shouldFail: true,
7588 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7589 })
7590 testCases = append(testCases, testCase{
7591 name: "NoCommonAlgorithms-TLS13",
7592 config: Config{
7593 MaxVersion: VersionTLS13,
7594 ClientAuth: RequireAnyClientCert,
7595 VerifySignatureAlgorithms: []signatureAlgorithm{
7596 signatureRSAPSSWithSHA512,
7597 signatureRSAPSSWithSHA384,
7598 },
7599 },
7600 flags: []string{
7601 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7602 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7603 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7604 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007605 shouldFail: true,
7606 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007607 })
7608 testCases = append(testCases, testCase{
7609 name: "Agree-Digest-SHA256",
7610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007611 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007612 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007613 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007614 signatureRSAPKCS1WithSHA1,
7615 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007616 },
7617 },
7618 flags: []string{
7619 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7620 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007621 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007622 },
Nick Harper60edffd2016-06-21 15:19:24 -07007623 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007624 })
7625 testCases = append(testCases, testCase{
7626 name: "Agree-Digest-SHA1",
7627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007628 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007629 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007630 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007631 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007632 },
7633 },
7634 flags: []string{
7635 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7636 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007637 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007638 },
Nick Harper60edffd2016-06-21 15:19:24 -07007639 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007640 })
7641 testCases = append(testCases, testCase{
7642 name: "Agree-Digest-Default",
7643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007644 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007645 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007646 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007647 signatureRSAPKCS1WithSHA256,
7648 signatureECDSAWithP256AndSHA256,
7649 signatureRSAPKCS1WithSHA1,
7650 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007651 },
7652 },
7653 flags: []string{
7654 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7655 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7656 },
Nick Harper60edffd2016-06-21 15:19:24 -07007657 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007658 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007659
David Benjaminca3d5452016-07-14 12:51:01 -04007660 // Test that the signing preference list may include extra algorithms
7661 // without negotiation problems.
7662 testCases = append(testCases, testCase{
7663 testType: serverTest,
7664 name: "FilterExtraAlgorithms",
7665 config: Config{
7666 MaxVersion: VersionTLS12,
7667 VerifySignatureAlgorithms: []signatureAlgorithm{
7668 signatureRSAPKCS1WithSHA256,
7669 },
7670 },
7671 flags: []string{
7672 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7673 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7674 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7675 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7676 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7677 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7678 },
7679 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7680 })
7681
David Benjamin4c3ddf72016-06-29 18:13:53 -04007682 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7683 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007684 testCases = append(testCases, testCase{
7685 name: "CheckLeafCurve",
7686 config: Config{
7687 MaxVersion: VersionTLS12,
7688 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007689 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007690 },
7691 flags: []string{"-p384-only"},
7692 shouldFail: true,
7693 expectedError: ":BAD_ECC_CERT:",
7694 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007695
7696 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7697 testCases = append(testCases, testCase{
7698 name: "CheckLeafCurve-TLS13",
7699 config: Config{
7700 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007701 Certificates: []Certificate{ecdsaP256Certificate},
7702 },
7703 flags: []string{"-p384-only"},
7704 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007705
7706 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7707 testCases = append(testCases, testCase{
7708 name: "ECDSACurveMismatch-Verify-TLS12",
7709 config: Config{
7710 MaxVersion: VersionTLS12,
7711 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7712 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007713 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007714 signatureECDSAWithP384AndSHA384,
7715 },
7716 },
7717 })
7718
7719 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7720 testCases = append(testCases, testCase{
7721 name: "ECDSACurveMismatch-Verify-TLS13",
7722 config: Config{
7723 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007724 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007725 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007726 signatureECDSAWithP384AndSHA384,
7727 },
7728 Bugs: ProtocolBugs{
7729 SkipECDSACurveCheck: true,
7730 },
7731 },
7732 shouldFail: true,
7733 expectedError: ":WRONG_SIGNATURE_TYPE:",
7734 })
7735
7736 // Signature algorithm selection in TLS 1.3 should take the curve into
7737 // account.
7738 testCases = append(testCases, testCase{
7739 testType: serverTest,
7740 name: "ECDSACurveMismatch-Sign-TLS13",
7741 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007742 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007743 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007744 signatureECDSAWithP384AndSHA384,
7745 signatureECDSAWithP256AndSHA256,
7746 },
7747 },
7748 flags: []string{
7749 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7750 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7751 },
7752 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7753 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007754
7755 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7756 // server does not attempt to sign in that case.
7757 testCases = append(testCases, testCase{
7758 testType: serverTest,
7759 name: "RSA-PSS-Large",
7760 config: Config{
7761 MaxVersion: VersionTLS13,
7762 VerifySignatureAlgorithms: []signatureAlgorithm{
7763 signatureRSAPSSWithSHA512,
7764 },
7765 },
7766 flags: []string{
7767 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7768 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7769 },
7770 shouldFail: true,
7771 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7772 })
David Benjamin57e929f2016-08-30 00:30:38 -04007773
7774 // Test that RSA-PSS is enabled by default for TLS 1.2.
7775 testCases = append(testCases, testCase{
7776 testType: clientTest,
7777 name: "RSA-PSS-Default-Verify",
7778 config: Config{
7779 MaxVersion: VersionTLS12,
7780 SignSignatureAlgorithms: []signatureAlgorithm{
7781 signatureRSAPSSWithSHA256,
7782 },
7783 },
7784 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7785 })
7786
7787 testCases = append(testCases, testCase{
7788 testType: serverTest,
7789 name: "RSA-PSS-Default-Sign",
7790 config: Config{
7791 MaxVersion: VersionTLS12,
7792 VerifySignatureAlgorithms: []signatureAlgorithm{
7793 signatureRSAPSSWithSHA256,
7794 },
7795 },
7796 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7797 })
David Benjamin69522112017-03-28 15:38:29 -05007798
7799 // TLS 1.1 and below has no way to advertise support for or negotiate
7800 // Ed25519's signature algorithm.
7801 testCases = append(testCases, testCase{
7802 testType: clientTest,
7803 name: "NoEd25519-TLS11-ServerAuth-Verify",
7804 config: Config{
7805 MaxVersion: VersionTLS11,
7806 Certificates: []Certificate{ed25519Certificate},
7807 Bugs: ProtocolBugs{
7808 // Sign with Ed25519 even though it is TLS 1.1.
7809 UseLegacySigningAlgorithm: signatureEd25519,
7810 },
7811 },
7812 flags: []string{"-enable-ed25519"},
7813 shouldFail: true,
7814 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7815 })
7816 testCases = append(testCases, testCase{
7817 testType: serverTest,
7818 name: "NoEd25519-TLS11-ServerAuth-Sign",
7819 config: Config{
7820 MaxVersion: VersionTLS11,
7821 },
7822 flags: []string{
7823 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7824 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7825 },
7826 shouldFail: true,
7827 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7828 })
7829 testCases = append(testCases, testCase{
7830 testType: serverTest,
7831 name: "NoEd25519-TLS11-ClientAuth-Verify",
7832 config: Config{
7833 MaxVersion: VersionTLS11,
7834 Certificates: []Certificate{ed25519Certificate},
7835 Bugs: ProtocolBugs{
7836 // Sign with Ed25519 even though it is TLS 1.1.
7837 UseLegacySigningAlgorithm: signatureEd25519,
7838 },
7839 },
7840 flags: []string{
7841 "-enable-ed25519",
7842 "-require-any-client-certificate",
7843 },
7844 shouldFail: true,
7845 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7846 })
7847 testCases = append(testCases, testCase{
7848 testType: clientTest,
7849 name: "NoEd25519-TLS11-ClientAuth-Sign",
7850 config: Config{
7851 MaxVersion: VersionTLS11,
7852 ClientAuth: RequireAnyClientCert,
7853 },
7854 flags: []string{
7855 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7856 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7857 },
7858 shouldFail: true,
7859 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7860 })
7861
7862 // Test Ed25519 is not advertised by default.
7863 testCases = append(testCases, testCase{
7864 testType: clientTest,
7865 name: "Ed25519DefaultDisable-NoAdvertise",
7866 config: Config{
7867 Certificates: []Certificate{ed25519Certificate},
7868 },
7869 shouldFail: true,
7870 expectedLocalError: "tls: no common signature algorithms",
7871 })
7872
7873 // Test Ed25519, when disabled, is not accepted if the peer ignores our
7874 // preferences.
7875 testCases = append(testCases, testCase{
7876 testType: clientTest,
7877 name: "Ed25519DefaultDisable-NoAccept",
7878 config: Config{
7879 Certificates: []Certificate{ed25519Certificate},
7880 Bugs: ProtocolBugs{
7881 IgnorePeerSignatureAlgorithmPreferences: true,
7882 },
7883 },
7884 shouldFail: true,
7885 expectedLocalError: "remote error: illegal parameter",
7886 expectedError: ":WRONG_SIGNATURE_TYPE:",
7887 })
David Benjamin71c21b42017-04-14 17:05:40 -04007888
7889 // Test that configuring verify preferences changes what the client
7890 // advertises.
7891 testCases = append(testCases, testCase{
7892 name: "VerifyPreferences-Advertised",
7893 config: Config{
7894 Certificates: []Certificate{rsaCertificate},
7895 SignSignatureAlgorithms: []signatureAlgorithm{
7896 signatureRSAPSSWithSHA256,
7897 signatureRSAPSSWithSHA384,
7898 signatureRSAPSSWithSHA512,
7899 },
7900 },
7901 flags: []string{
7902 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7903 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7904 },
7905 })
7906
7907 // Test that the client advertises a set which the runner can find
7908 // nothing in common with.
7909 testCases = append(testCases, testCase{
7910 name: "VerifyPreferences-NoCommonAlgorithms",
7911 config: Config{
7912 Certificates: []Certificate{rsaCertificate},
7913 SignSignatureAlgorithms: []signatureAlgorithm{
7914 signatureRSAPSSWithSHA256,
7915 signatureRSAPSSWithSHA512,
7916 },
7917 },
7918 flags: []string{
7919 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7920 },
7921 shouldFail: true,
7922 expectedLocalError: "tls: no common signature algorithms",
7923 })
7924
7925 // Test that the client enforces its preferences when configured.
7926 testCases = append(testCases, testCase{
7927 name: "VerifyPreferences-Enforced",
7928 config: Config{
7929 Certificates: []Certificate{rsaCertificate},
7930 SignSignatureAlgorithms: []signatureAlgorithm{
7931 signatureRSAPSSWithSHA256,
7932 signatureRSAPSSWithSHA512,
7933 },
7934 Bugs: ProtocolBugs{
7935 IgnorePeerSignatureAlgorithmPreferences: true,
7936 },
7937 },
7938 flags: []string{
7939 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7940 },
7941 shouldFail: true,
7942 expectedLocalError: "remote error: illegal parameter",
7943 expectedError: ":WRONG_SIGNATURE_TYPE:",
7944 })
7945
7946 // Test that explicitly configuring Ed25519 is as good as changing the
7947 // boolean toggle.
7948 testCases = append(testCases, testCase{
7949 name: "VerifyPreferences-Ed25519",
7950 config: Config{
7951 Certificates: []Certificate{ed25519Certificate},
7952 },
7953 flags: []string{
7954 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
7955 },
7956 })
David Benjamin000800a2014-11-14 01:43:59 -05007957}
7958
David Benjamin83f90402015-01-27 01:09:43 -05007959// timeouts is the retransmit schedule for BoringSSL. It doubles and
7960// caps at 60 seconds. On the 13th timeout, it gives up.
7961var timeouts = []time.Duration{
7962 1 * time.Second,
7963 2 * time.Second,
7964 4 * time.Second,
7965 8 * time.Second,
7966 16 * time.Second,
7967 32 * time.Second,
7968 60 * time.Second,
7969 60 * time.Second,
7970 60 * time.Second,
7971 60 * time.Second,
7972 60 * time.Second,
7973 60 * time.Second,
7974 60 * time.Second,
7975}
7976
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007977// shortTimeouts is an alternate set of timeouts which would occur if the
7978// initial timeout duration was set to 250ms.
7979var shortTimeouts = []time.Duration{
7980 250 * time.Millisecond,
7981 500 * time.Millisecond,
7982 1 * time.Second,
7983 2 * time.Second,
7984 4 * time.Second,
7985 8 * time.Second,
7986 16 * time.Second,
7987 32 * time.Second,
7988 60 * time.Second,
7989 60 * time.Second,
7990 60 * time.Second,
7991 60 * time.Second,
7992 60 * time.Second,
7993}
7994
David Benjamin83f90402015-01-27 01:09:43 -05007995func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007996 // These tests work by coordinating some behavior on both the shim and
7997 // the runner.
7998 //
7999 // TimeoutSchedule configures the runner to send a series of timeout
8000 // opcodes to the shim (see packetAdaptor) immediately before reading
8001 // each peer handshake flight N. The timeout opcode both simulates a
8002 // timeout in the shim and acts as a synchronization point to help the
8003 // runner bracket each handshake flight.
8004 //
8005 // We assume the shim does not read from the channel eagerly. It must
8006 // first wait until it has sent flight N and is ready to receive
8007 // handshake flight N+1. At this point, it will process the timeout
8008 // opcode. It must then immediately respond with a timeout ACK and act
8009 // as if the shim was idle for the specified amount of time.
8010 //
8011 // The runner then drops all packets received before the ACK and
8012 // continues waiting for flight N. This ordering results in one attempt
8013 // at sending flight N to be dropped. For the test to complete, the
8014 // shim must send flight N again, testing that the shim implements DTLS
8015 // retransmit on a timeout.
8016
Steven Valdez143e8b32016-07-11 13:19:03 -04008017 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008018 // likely be more epochs to cross and the final message's retransmit may
8019 // be more complex.
8020
David Benjamin11c82892017-02-23 20:40:31 -05008021 // Test that this is indeed the timeout schedule. Stress all
8022 // four patterns of handshake.
8023 for i := 1; i < len(timeouts); i++ {
8024 number := strconv.Itoa(i)
8025 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008026 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008027 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008028 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008029 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008030 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008031 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008032 },
8033 },
8034 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008035 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008036 })
David Benjamin11c82892017-02-23 20:40:31 -05008037 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008038 protocol: dtls,
8039 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008040 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008042 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008043 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008044 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008045 },
8046 },
8047 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008048 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008049 })
8050 }
David Benjamin11c82892017-02-23 20:40:31 -05008051
8052 // Test that exceeding the timeout schedule hits a read
8053 // timeout.
8054 testCases = append(testCases, testCase{
8055 protocol: dtls,
8056 name: "DTLS-Retransmit-Timeout",
8057 config: Config{
8058 MaxVersion: VersionTLS12,
8059 Bugs: ProtocolBugs{
8060 TimeoutSchedule: timeouts,
8061 },
8062 },
8063 resumeSession: true,
8064 flags: []string{"-async"},
8065 shouldFail: true,
8066 expectedError: ":READ_TIMEOUT_EXPIRED:",
8067 })
8068
8069 // Test that timeout handling has a fudge factor, due to API
8070 // problems.
8071 testCases = append(testCases, testCase{
8072 protocol: dtls,
8073 name: "DTLS-Retransmit-Fudge",
8074 config: Config{
8075 MaxVersion: VersionTLS12,
8076 Bugs: ProtocolBugs{
8077 TimeoutSchedule: []time.Duration{
8078 timeouts[0] - 10*time.Millisecond,
8079 },
8080 },
8081 },
8082 resumeSession: true,
8083 flags: []string{"-async"},
8084 })
8085
8086 // Test that the final Finished retransmitting isn't
8087 // duplicated if the peer badly fragments everything.
8088 testCases = append(testCases, testCase{
8089 testType: serverTest,
8090 protocol: dtls,
8091 name: "DTLS-Retransmit-Fragmented",
8092 config: Config{
8093 MaxVersion: VersionTLS12,
8094 Bugs: ProtocolBugs{
8095 TimeoutSchedule: []time.Duration{timeouts[0]},
8096 MaxHandshakeRecordLength: 2,
8097 },
8098 },
8099 flags: []string{"-async"},
8100 })
8101
8102 // Test the timeout schedule when a shorter initial timeout duration is set.
8103 testCases = append(testCases, testCase{
8104 protocol: dtls,
8105 name: "DTLS-Retransmit-Short-Client",
8106 config: Config{
8107 MaxVersion: VersionTLS12,
8108 Bugs: ProtocolBugs{
8109 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8110 },
8111 },
8112 resumeSession: true,
8113 flags: []string{
8114 "-async",
8115 "-initial-timeout-duration-ms", "250",
8116 },
8117 })
8118 testCases = append(testCases, testCase{
8119 protocol: dtls,
8120 testType: serverTest,
8121 name: "DTLS-Retransmit-Short-Server",
8122 config: Config{
8123 MaxVersion: VersionTLS12,
8124 Bugs: ProtocolBugs{
8125 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8126 },
8127 },
8128 resumeSession: true,
8129 flags: []string{
8130 "-async",
8131 "-initial-timeout-duration-ms", "250",
8132 },
8133 })
David Benjamin83f90402015-01-27 01:09:43 -05008134}
8135
David Benjaminc565ebb2015-04-03 04:06:36 -04008136func addExportKeyingMaterialTests() {
8137 for _, vers := range tlsVersions {
8138 if vers.version == VersionSSL30 {
8139 continue
8140 }
8141 testCases = append(testCases, testCase{
8142 name: "ExportKeyingMaterial-" + vers.name,
8143 config: Config{
8144 MaxVersion: vers.version,
8145 },
8146 exportKeyingMaterial: 1024,
8147 exportLabel: "label",
8148 exportContext: "context",
8149 useExportContext: true,
8150 })
8151 testCases = append(testCases, testCase{
8152 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8153 config: Config{
8154 MaxVersion: vers.version,
8155 },
8156 exportKeyingMaterial: 1024,
8157 })
8158 testCases = append(testCases, testCase{
8159 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8160 config: Config{
8161 MaxVersion: vers.version,
8162 },
8163 exportKeyingMaterial: 1024,
8164 useExportContext: true,
8165 })
8166 testCases = append(testCases, testCase{
8167 name: "ExportKeyingMaterial-Small-" + vers.name,
8168 config: Config{
8169 MaxVersion: vers.version,
8170 },
8171 exportKeyingMaterial: 1,
8172 exportLabel: "label",
8173 exportContext: "context",
8174 useExportContext: true,
8175 })
8176 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008177
David Benjaminc565ebb2015-04-03 04:06:36 -04008178 testCases = append(testCases, testCase{
8179 name: "ExportKeyingMaterial-SSL3",
8180 config: Config{
8181 MaxVersion: VersionSSL30,
8182 },
8183 exportKeyingMaterial: 1024,
8184 exportLabel: "label",
8185 exportContext: "context",
8186 useExportContext: true,
8187 shouldFail: true,
8188 expectedError: "failed to export keying material",
8189 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008190
8191 // Exporters work during a False Start.
8192 testCases = append(testCases, testCase{
8193 name: "ExportKeyingMaterial-FalseStart",
8194 config: Config{
8195 MaxVersion: VersionTLS12,
8196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8197 NextProtos: []string{"foo"},
8198 Bugs: ProtocolBugs{
8199 ExpectFalseStart: true,
8200 },
8201 },
8202 flags: []string{
8203 "-false-start",
8204 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008205 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008206 },
8207 shimWritesFirst: true,
8208 exportKeyingMaterial: 1024,
8209 exportLabel: "label",
8210 exportContext: "context",
8211 useExportContext: true,
8212 })
8213
8214 // Exporters do not work in the middle of a renegotiation. Test this by
8215 // triggering the exporter after every SSL_read call and configuring the
8216 // shim to run asynchronously.
8217 testCases = append(testCases, testCase{
8218 name: "ExportKeyingMaterial-Renegotiate",
8219 config: Config{
8220 MaxVersion: VersionTLS12,
8221 },
8222 renegotiate: 1,
8223 flags: []string{
8224 "-async",
8225 "-use-exporter-between-reads",
8226 "-renegotiate-freely",
8227 "-expect-total-renegotiations", "1",
8228 },
8229 shouldFail: true,
8230 expectedError: "failed to export keying material",
8231 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008232}
8233
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008234func addTLSUniqueTests() {
8235 for _, isClient := range []bool{false, true} {
8236 for _, isResumption := range []bool{false, true} {
8237 for _, hasEMS := range []bool{false, true} {
8238 var suffix string
8239 if isResumption {
8240 suffix = "Resume-"
8241 } else {
8242 suffix = "Full-"
8243 }
8244
8245 if hasEMS {
8246 suffix += "EMS-"
8247 } else {
8248 suffix += "NoEMS-"
8249 }
8250
8251 if isClient {
8252 suffix += "Client"
8253 } else {
8254 suffix += "Server"
8255 }
8256
8257 test := testCase{
8258 name: "TLSUnique-" + suffix,
8259 testTLSUnique: true,
8260 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008261 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008262 Bugs: ProtocolBugs{
8263 NoExtendedMasterSecret: !hasEMS,
8264 },
8265 },
8266 }
8267
8268 if isResumption {
8269 test.resumeSession = true
8270 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008271 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008272 Bugs: ProtocolBugs{
8273 NoExtendedMasterSecret: !hasEMS,
8274 },
8275 }
8276 }
8277
8278 if isResumption && !hasEMS {
8279 test.shouldFail = true
8280 test.expectedError = "failed to get tls-unique"
8281 }
8282
8283 testCases = append(testCases, test)
8284 }
8285 }
8286 }
8287}
8288
Adam Langley09505632015-07-30 18:10:13 -07008289func addCustomExtensionTests() {
8290 expectedContents := "custom extension"
8291 emptyString := ""
8292
8293 for _, isClient := range []bool{false, true} {
8294 suffix := "Server"
8295 flag := "-enable-server-custom-extension"
8296 testType := serverTest
8297 if isClient {
8298 suffix = "Client"
8299 flag = "-enable-client-custom-extension"
8300 testType = clientTest
8301 }
8302
8303 testCases = append(testCases, testCase{
8304 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008305 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008307 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008308 Bugs: ProtocolBugs{
8309 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008310 ExpectedCustomExtension: &expectedContents,
8311 },
8312 },
8313 flags: []string{flag},
8314 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008315 testCases = append(testCases, testCase{
8316 testType: testType,
8317 name: "CustomExtensions-" + suffix + "-TLS13",
8318 config: Config{
8319 MaxVersion: VersionTLS13,
8320 Bugs: ProtocolBugs{
8321 CustomExtension: expectedContents,
8322 ExpectedCustomExtension: &expectedContents,
8323 },
8324 },
8325 flags: []string{flag},
8326 })
Adam Langley09505632015-07-30 18:10:13 -07008327
Steven Valdez2a070722017-03-25 20:54:16 -05008328 // 0-RTT is not currently supported with Custom Extensions.
8329 testCases = append(testCases, testCase{
8330 testType: testType,
8331 name: "CustomExtensions-" + suffix + "-EarlyData",
8332 config: Config{
8333 MaxVersion: VersionTLS13,
8334 Bugs: ProtocolBugs{
8335 CustomExtension: expectedContents,
8336 ExpectedCustomExtension: &expectedContents,
8337 },
8338 },
8339 shouldFail: true,
8340 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8341 flags: []string{flag, "-enable-early-data"},
8342 })
8343
Adam Langley09505632015-07-30 18:10:13 -07008344 // If the parse callback fails, the handshake should also fail.
8345 testCases = append(testCases, testCase{
8346 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008347 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008349 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008350 Bugs: ProtocolBugs{
8351 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008352 ExpectedCustomExtension: &expectedContents,
8353 },
8354 },
David Benjamin399e7c92015-07-30 23:01:27 -04008355 flags: []string{flag},
8356 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008357 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8358 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008359 testCases = append(testCases, testCase{
8360 testType: testType,
8361 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8362 config: Config{
8363 MaxVersion: VersionTLS13,
8364 Bugs: ProtocolBugs{
8365 CustomExtension: expectedContents + "foo",
8366 ExpectedCustomExtension: &expectedContents,
8367 },
8368 },
8369 flags: []string{flag},
8370 shouldFail: true,
8371 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8372 })
Adam Langley09505632015-07-30 18:10:13 -07008373
8374 // If the add callback fails, the handshake should also fail.
8375 testCases = append(testCases, testCase{
8376 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008377 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008378 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008379 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008380 Bugs: ProtocolBugs{
8381 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008382 ExpectedCustomExtension: &expectedContents,
8383 },
8384 },
David Benjamin399e7c92015-07-30 23:01:27 -04008385 flags: []string{flag, "-custom-extension-fail-add"},
8386 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008387 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8388 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008389 testCases = append(testCases, testCase{
8390 testType: testType,
8391 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8392 config: Config{
8393 MaxVersion: VersionTLS13,
8394 Bugs: ProtocolBugs{
8395 CustomExtension: expectedContents,
8396 ExpectedCustomExtension: &expectedContents,
8397 },
8398 },
8399 flags: []string{flag, "-custom-extension-fail-add"},
8400 shouldFail: true,
8401 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8402 })
Adam Langley09505632015-07-30 18:10:13 -07008403
8404 // If the add callback returns zero, no extension should be
8405 // added.
8406 skipCustomExtension := expectedContents
8407 if isClient {
8408 // For the case where the client skips sending the
8409 // custom extension, the server must not “echo” it.
8410 skipCustomExtension = ""
8411 }
8412 testCases = append(testCases, testCase{
8413 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008414 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008416 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008417 Bugs: ProtocolBugs{
8418 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008419 ExpectedCustomExtension: &emptyString,
8420 },
8421 },
8422 flags: []string{flag, "-custom-extension-skip"},
8423 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008424 testCases = append(testCases, testCase{
8425 testType: testType,
8426 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8427 config: Config{
8428 MaxVersion: VersionTLS13,
8429 Bugs: ProtocolBugs{
8430 CustomExtension: skipCustomExtension,
8431 ExpectedCustomExtension: &emptyString,
8432 },
8433 },
8434 flags: []string{flag, "-custom-extension-skip"},
8435 })
Adam Langley09505632015-07-30 18:10:13 -07008436 }
8437
8438 // The custom extension add callback should not be called if the client
8439 // doesn't send the extension.
8440 testCases = append(testCases, testCase{
8441 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008442 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008444 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008445 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008446 ExpectedCustomExtension: &emptyString,
8447 },
8448 },
8449 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8450 })
Adam Langley2deb9842015-08-07 11:15:37 -07008451
Steven Valdez143e8b32016-07-11 13:19:03 -04008452 testCases = append(testCases, testCase{
8453 testType: serverTest,
8454 name: "CustomExtensions-NotCalled-Server-TLS13",
8455 config: Config{
8456 MaxVersion: VersionTLS13,
8457 Bugs: ProtocolBugs{
8458 ExpectedCustomExtension: &emptyString,
8459 },
8460 },
8461 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8462 })
8463
Adam Langley2deb9842015-08-07 11:15:37 -07008464 // Test an unknown extension from the server.
8465 testCases = append(testCases, testCase{
8466 testType: clientTest,
8467 name: "UnknownExtension-Client",
8468 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008469 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008470 Bugs: ProtocolBugs{
8471 CustomExtension: expectedContents,
8472 },
8473 },
David Benjamin0c40a962016-08-01 12:05:50 -04008474 shouldFail: true,
8475 expectedError: ":UNEXPECTED_EXTENSION:",
8476 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008477 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008478 testCases = append(testCases, testCase{
8479 testType: clientTest,
8480 name: "UnknownExtension-Client-TLS13",
8481 config: Config{
8482 MaxVersion: VersionTLS13,
8483 Bugs: ProtocolBugs{
8484 CustomExtension: expectedContents,
8485 },
8486 },
David Benjamin0c40a962016-08-01 12:05:50 -04008487 shouldFail: true,
8488 expectedError: ":UNEXPECTED_EXTENSION:",
8489 expectedLocalError: "remote error: unsupported extension",
8490 })
David Benjamin490469f2016-10-05 22:44:38 -04008491 testCases = append(testCases, testCase{
8492 testType: clientTest,
8493 name: "UnknownUnencryptedExtension-Client-TLS13",
8494 config: Config{
8495 MaxVersion: VersionTLS13,
8496 Bugs: ProtocolBugs{
8497 CustomUnencryptedExtension: expectedContents,
8498 },
8499 },
8500 shouldFail: true,
8501 expectedError: ":UNEXPECTED_EXTENSION:",
8502 // The shim must send an alert, but alerts at this point do not
8503 // get successfully decrypted by the runner.
8504 expectedLocalError: "local error: bad record MAC",
8505 })
8506 testCases = append(testCases, testCase{
8507 testType: clientTest,
8508 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8509 config: Config{
8510 MaxVersion: VersionTLS13,
8511 Bugs: ProtocolBugs{
8512 SendUnencryptedALPN: "foo",
8513 },
8514 },
8515 flags: []string{
8516 "-advertise-alpn", "\x03foo\x03bar",
8517 },
8518 shouldFail: true,
8519 expectedError: ":UNEXPECTED_EXTENSION:",
8520 // The shim must send an alert, but alerts at this point do not
8521 // get successfully decrypted by the runner.
8522 expectedLocalError: "local error: bad record MAC",
8523 })
David Benjamin0c40a962016-08-01 12:05:50 -04008524
8525 // Test a known but unoffered extension from the server.
8526 testCases = append(testCases, testCase{
8527 testType: clientTest,
8528 name: "UnofferedExtension-Client",
8529 config: Config{
8530 MaxVersion: VersionTLS12,
8531 Bugs: ProtocolBugs{
8532 SendALPN: "alpn",
8533 },
8534 },
8535 shouldFail: true,
8536 expectedError: ":UNEXPECTED_EXTENSION:",
8537 expectedLocalError: "remote error: unsupported extension",
8538 })
8539 testCases = append(testCases, testCase{
8540 testType: clientTest,
8541 name: "UnofferedExtension-Client-TLS13",
8542 config: Config{
8543 MaxVersion: VersionTLS13,
8544 Bugs: ProtocolBugs{
8545 SendALPN: "alpn",
8546 },
8547 },
8548 shouldFail: true,
8549 expectedError: ":UNEXPECTED_EXTENSION:",
8550 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008551 })
Adam Langley09505632015-07-30 18:10:13 -07008552}
8553
David Benjaminb36a3952015-12-01 18:53:13 -05008554func addRSAClientKeyExchangeTests() {
8555 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8556 testCases = append(testCases, testCase{
8557 testType: serverTest,
8558 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8559 config: Config{
8560 // Ensure the ClientHello version and final
8561 // version are different, to detect if the
8562 // server uses the wrong one.
8563 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008564 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008565 Bugs: ProtocolBugs{
8566 BadRSAClientKeyExchange: bad,
8567 },
8568 },
8569 shouldFail: true,
8570 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8571 })
8572 }
David Benjamine63d9d72016-09-19 18:27:34 -04008573
8574 // The server must compare whatever was in ClientHello.version for the
8575 // RSA premaster.
8576 testCases = append(testCases, testCase{
8577 testType: serverTest,
8578 name: "SendClientVersion-RSA",
8579 config: Config{
8580 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8581 Bugs: ProtocolBugs{
8582 SendClientVersion: 0x1234,
8583 },
8584 },
8585 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8586 })
David Benjaminb36a3952015-12-01 18:53:13 -05008587}
8588
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008589var testCurves = []struct {
8590 name string
8591 id CurveID
8592}{
Adam Langley764ab982017-03-10 18:01:30 -08008593 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008594 {"P-256", CurveP256},
8595 {"P-384", CurveP384},
8596 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008597 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008598}
8599
Steven Valdez5440fe02016-07-18 12:40:30 -04008600const bogusCurve = 0x1234
8601
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008602func addCurveTests() {
8603 for _, curve := range testCurves {
8604 testCases = append(testCases, testCase{
8605 name: "CurveTest-Client-" + curve.name,
8606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008607 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008608 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8609 CurvePreferences: []CurveID{curve.id},
8610 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008611 flags: []string{
8612 "-enable-all-curves",
8613 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8614 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008615 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008616 })
8617 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008618 name: "CurveTest-Client-" + curve.name + "-TLS13",
8619 config: Config{
8620 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008621 CurvePreferences: []CurveID{curve.id},
8622 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008623 flags: []string{
8624 "-enable-all-curves",
8625 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8626 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008627 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008628 })
8629 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008630 testType: serverTest,
8631 name: "CurveTest-Server-" + curve.name,
8632 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008633 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008634 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8635 CurvePreferences: []CurveID{curve.id},
8636 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008637 flags: []string{
8638 "-enable-all-curves",
8639 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8640 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008641 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008642 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008643 testCases = append(testCases, testCase{
8644 testType: serverTest,
8645 name: "CurveTest-Server-" + curve.name + "-TLS13",
8646 config: Config{
8647 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008648 CurvePreferences: []CurveID{curve.id},
8649 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008650 flags: []string{
8651 "-enable-all-curves",
8652 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8653 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008654 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008655 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008656 }
David Benjamin241ae832016-01-15 03:04:54 -05008657
8658 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008659 testCases = append(testCases, testCase{
8660 testType: serverTest,
8661 name: "UnknownCurve",
8662 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008663 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008664 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8665 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8666 },
8667 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008668
Steven Valdez803c77a2016-09-06 14:13:43 -04008669 // The server must be tolerant to bogus curves.
8670 testCases = append(testCases, testCase{
8671 testType: serverTest,
8672 name: "UnknownCurve-TLS13",
8673 config: Config{
8674 MaxVersion: VersionTLS13,
8675 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8676 },
8677 })
8678
David Benjamin4c3ddf72016-06-29 18:13:53 -04008679 // The server must not consider ECDHE ciphers when there are no
8680 // supported curves.
8681 testCases = append(testCases, testCase{
8682 testType: serverTest,
8683 name: "NoSupportedCurves",
8684 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008685 MaxVersion: VersionTLS12,
8686 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8687 Bugs: ProtocolBugs{
8688 NoSupportedCurves: true,
8689 },
8690 },
8691 shouldFail: true,
8692 expectedError: ":NO_SHARED_CIPHER:",
8693 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008694 testCases = append(testCases, testCase{
8695 testType: serverTest,
8696 name: "NoSupportedCurves-TLS13",
8697 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008698 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008699 Bugs: ProtocolBugs{
8700 NoSupportedCurves: true,
8701 },
8702 },
8703 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008704 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008705 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008706
8707 // The server must fall back to another cipher when there are no
8708 // supported curves.
8709 testCases = append(testCases, testCase{
8710 testType: serverTest,
8711 name: "NoCommonCurves",
8712 config: Config{
8713 MaxVersion: VersionTLS12,
8714 CipherSuites: []uint16{
8715 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008716 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008717 },
8718 CurvePreferences: []CurveID{CurveP224},
8719 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008720 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008721 })
8722
8723 // The client must reject bogus curves and disabled curves.
8724 testCases = append(testCases, testCase{
8725 name: "BadECDHECurve",
8726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008727 MaxVersion: VersionTLS12,
8728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8729 Bugs: ProtocolBugs{
8730 SendCurve: bogusCurve,
8731 },
8732 },
8733 shouldFail: true,
8734 expectedError: ":WRONG_CURVE:",
8735 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008736 testCases = append(testCases, testCase{
8737 name: "BadECDHECurve-TLS13",
8738 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008739 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008740 Bugs: ProtocolBugs{
8741 SendCurve: bogusCurve,
8742 },
8743 },
8744 shouldFail: true,
8745 expectedError: ":WRONG_CURVE:",
8746 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008747
8748 testCases = append(testCases, testCase{
8749 name: "UnsupportedCurve",
8750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008751 MaxVersion: VersionTLS12,
8752 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8753 CurvePreferences: []CurveID{CurveP256},
8754 Bugs: ProtocolBugs{
8755 IgnorePeerCurvePreferences: true,
8756 },
8757 },
8758 flags: []string{"-p384-only"},
8759 shouldFail: true,
8760 expectedError: ":WRONG_CURVE:",
8761 })
8762
David Benjamin4f921572016-07-17 14:20:10 +02008763 testCases = append(testCases, testCase{
8764 // TODO(davidben): Add a TLS 1.3 version where
8765 // HelloRetryRequest requests an unsupported curve.
8766 name: "UnsupportedCurve-ServerHello-TLS13",
8767 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008768 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008769 CurvePreferences: []CurveID{CurveP384},
8770 Bugs: ProtocolBugs{
8771 SendCurve: CurveP256,
8772 },
8773 },
8774 flags: []string{"-p384-only"},
8775 shouldFail: true,
8776 expectedError: ":WRONG_CURVE:",
8777 })
8778
David Benjamin4c3ddf72016-06-29 18:13:53 -04008779 // Test invalid curve points.
8780 testCases = append(testCases, testCase{
8781 name: "InvalidECDHPoint-Client",
8782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008783 MaxVersion: VersionTLS12,
8784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8785 CurvePreferences: []CurveID{CurveP256},
8786 Bugs: ProtocolBugs{
8787 InvalidECDHPoint: true,
8788 },
8789 },
8790 shouldFail: true,
8791 expectedError: ":INVALID_ENCODING:",
8792 })
8793 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008794 name: "InvalidECDHPoint-Client-TLS13",
8795 config: Config{
8796 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008797 CurvePreferences: []CurveID{CurveP256},
8798 Bugs: ProtocolBugs{
8799 InvalidECDHPoint: true,
8800 },
8801 },
8802 shouldFail: true,
8803 expectedError: ":INVALID_ENCODING:",
8804 })
8805 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008806 testType: serverTest,
8807 name: "InvalidECDHPoint-Server",
8808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008809 MaxVersion: VersionTLS12,
8810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8811 CurvePreferences: []CurveID{CurveP256},
8812 Bugs: ProtocolBugs{
8813 InvalidECDHPoint: true,
8814 },
8815 },
8816 shouldFail: true,
8817 expectedError: ":INVALID_ENCODING:",
8818 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008819 testCases = append(testCases, testCase{
8820 testType: serverTest,
8821 name: "InvalidECDHPoint-Server-TLS13",
8822 config: Config{
8823 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008824 CurvePreferences: []CurveID{CurveP256},
8825 Bugs: ProtocolBugs{
8826 InvalidECDHPoint: true,
8827 },
8828 },
8829 shouldFail: true,
8830 expectedError: ":INVALID_ENCODING:",
8831 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008832
8833 // The previous curve ID should be reported on TLS 1.2 resumption.
8834 testCases = append(testCases, testCase{
8835 name: "CurveID-Resume-Client",
8836 config: Config{
8837 MaxVersion: VersionTLS12,
8838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8839 CurvePreferences: []CurveID{CurveX25519},
8840 },
8841 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8842 resumeSession: true,
8843 })
8844 testCases = append(testCases, testCase{
8845 testType: serverTest,
8846 name: "CurveID-Resume-Server",
8847 config: Config{
8848 MaxVersion: VersionTLS12,
8849 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8850 CurvePreferences: []CurveID{CurveX25519},
8851 },
8852 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8853 resumeSession: true,
8854 })
8855
8856 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8857 // one should be reported.
8858 testCases = append(testCases, testCase{
8859 name: "CurveID-Resume-Client-TLS13",
8860 config: Config{
8861 MaxVersion: VersionTLS13,
8862 CurvePreferences: []CurveID{CurveX25519},
8863 },
8864 resumeConfig: &Config{
8865 MaxVersion: VersionTLS13,
8866 CurvePreferences: []CurveID{CurveP256},
8867 },
8868 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008869 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8870 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008871 },
8872 resumeSession: true,
8873 })
8874 testCases = append(testCases, testCase{
8875 testType: serverTest,
8876 name: "CurveID-Resume-Server-TLS13",
8877 config: Config{
8878 MaxVersion: VersionTLS13,
8879 CurvePreferences: []CurveID{CurveX25519},
8880 },
8881 resumeConfig: &Config{
8882 MaxVersion: VersionTLS13,
8883 CurvePreferences: []CurveID{CurveP256},
8884 },
8885 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008886 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8887 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008888 },
8889 resumeSession: true,
8890 })
David Benjamina81967b2016-12-22 09:16:57 -05008891
8892 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8893 testCases = append(testCases, testCase{
8894 name: "PointFormat-ServerHello-TLS12",
8895 config: Config{
8896 MaxVersion: VersionTLS12,
8897 Bugs: ProtocolBugs{
8898 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8899 },
8900 },
8901 })
8902 testCases = append(testCases, testCase{
8903 name: "PointFormat-EncryptedExtensions-TLS13",
8904 config: Config{
8905 MaxVersion: VersionTLS13,
8906 Bugs: ProtocolBugs{
8907 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8908 },
8909 },
8910 shouldFail: true,
8911 expectedError: ":ERROR_PARSING_EXTENSION:",
8912 })
8913
8914 // Test that we tolerate unknown point formats, as long as
8915 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8916 // check they are still functional.
8917 testCases = append(testCases, testCase{
8918 name: "PointFormat-Client-Tolerance",
8919 config: Config{
8920 MaxVersion: VersionTLS12,
8921 Bugs: ProtocolBugs{
8922 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8923 },
8924 },
8925 })
8926 testCases = append(testCases, testCase{
8927 testType: serverTest,
8928 name: "PointFormat-Server-Tolerance",
8929 config: Config{
8930 MaxVersion: VersionTLS12,
8931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8932 Bugs: ProtocolBugs{
8933 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8934 },
8935 },
8936 })
8937
8938 // Test TLS 1.2 does not require the point format extension to be
8939 // present.
8940 testCases = append(testCases, testCase{
8941 name: "PointFormat-Client-Missing",
8942 config: Config{
8943 MaxVersion: VersionTLS12,
8944 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8945 Bugs: ProtocolBugs{
8946 SendSupportedPointFormats: []byte{},
8947 },
8948 },
8949 })
8950 testCases = append(testCases, testCase{
8951 testType: serverTest,
8952 name: "PointFormat-Server-Missing",
8953 config: Config{
8954 MaxVersion: VersionTLS12,
8955 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8956 Bugs: ProtocolBugs{
8957 SendSupportedPointFormats: []byte{},
8958 },
8959 },
8960 })
8961
8962 // If the point format extension is present, uncompressed points must be
8963 // offered. BoringSSL requires this whether or not ECDHE is used.
8964 testCases = append(testCases, testCase{
8965 name: "PointFormat-Client-MissingUncompressed",
8966 config: Config{
8967 MaxVersion: VersionTLS12,
8968 Bugs: ProtocolBugs{
8969 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8970 },
8971 },
8972 shouldFail: true,
8973 expectedError: ":ERROR_PARSING_EXTENSION:",
8974 })
8975 testCases = append(testCases, testCase{
8976 testType: serverTest,
8977 name: "PointFormat-Server-MissingUncompressed",
8978 config: Config{
8979 MaxVersion: VersionTLS12,
8980 Bugs: ProtocolBugs{
8981 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8982 },
8983 },
8984 shouldFail: true,
8985 expectedError: ":ERROR_PARSING_EXTENSION:",
8986 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008987}
8988
David Benjaminc9ae27c2016-06-24 22:56:37 -04008989func addTLS13RecordTests() {
8990 testCases = append(testCases, testCase{
8991 name: "TLS13-RecordPadding",
8992 config: Config{
8993 MaxVersion: VersionTLS13,
8994 MinVersion: VersionTLS13,
8995 Bugs: ProtocolBugs{
8996 RecordPadding: 10,
8997 },
8998 },
8999 })
9000
9001 testCases = append(testCases, testCase{
9002 name: "TLS13-EmptyRecords",
9003 config: Config{
9004 MaxVersion: VersionTLS13,
9005 MinVersion: VersionTLS13,
9006 Bugs: ProtocolBugs{
9007 OmitRecordContents: true,
9008 },
9009 },
9010 shouldFail: true,
9011 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9012 })
9013
9014 testCases = append(testCases, testCase{
9015 name: "TLS13-OnlyPadding",
9016 config: Config{
9017 MaxVersion: VersionTLS13,
9018 MinVersion: VersionTLS13,
9019 Bugs: ProtocolBugs{
9020 OmitRecordContents: true,
9021 RecordPadding: 10,
9022 },
9023 },
9024 shouldFail: true,
9025 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9026 })
9027
9028 testCases = append(testCases, testCase{
9029 name: "TLS13-WrongOuterRecord",
9030 config: Config{
9031 MaxVersion: VersionTLS13,
9032 MinVersion: VersionTLS13,
9033 Bugs: ProtocolBugs{
9034 OuterRecordType: recordTypeHandshake,
9035 },
9036 },
9037 shouldFail: true,
9038 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9039 })
9040}
9041
Steven Valdez5b986082016-09-01 12:29:49 -04009042func addSessionTicketTests() {
9043 testCases = append(testCases, testCase{
9044 // In TLS 1.2 and below, empty NewSessionTicket messages
9045 // mean the server changed its mind on sending a ticket.
9046 name: "SendEmptySessionTicket",
9047 config: Config{
9048 MaxVersion: VersionTLS12,
9049 Bugs: ProtocolBugs{
9050 SendEmptySessionTicket: true,
9051 },
9052 },
9053 flags: []string{"-expect-no-session"},
9054 })
9055
9056 // Test that the server ignores unknown PSK modes.
9057 testCases = append(testCases, testCase{
9058 testType: serverTest,
9059 name: "TLS13-SendUnknownModeSessionTicket-Server",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 Bugs: ProtocolBugs{
9063 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009064 },
9065 },
9066 resumeSession: true,
9067 expectedResumeVersion: VersionTLS13,
9068 })
9069
Steven Valdeza833c352016-11-01 13:39:36 -04009070 // Test that the server does not send session tickets with no matching key exchange mode.
9071 testCases = append(testCases, testCase{
9072 testType: serverTest,
9073 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9074 config: Config{
9075 MaxVersion: VersionTLS13,
9076 Bugs: ProtocolBugs{
9077 SendPSKKeyExchangeModes: []byte{0x1a},
9078 ExpectNoNewSessionTicket: true,
9079 },
9080 },
9081 })
9082
9083 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009084 testCases = append(testCases, testCase{
9085 testType: serverTest,
9086 name: "TLS13-SendBadKEModeSessionTicket-Server",
9087 config: Config{
9088 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009089 },
9090 resumeConfig: &Config{
9091 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009092 Bugs: ProtocolBugs{
9093 SendPSKKeyExchangeModes: []byte{0x1a},
9094 },
9095 },
9096 resumeSession: true,
9097 expectResumeRejected: true,
9098 })
9099
Steven Valdeza833c352016-11-01 13:39:36 -04009100 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009101 testCases = append(testCases, testCase{
9102 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009103 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009104 config: Config{
9105 MaxVersion: VersionTLS13,
9106 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009107 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009108 },
9109 },
Steven Valdeza833c352016-11-01 13:39:36 -04009110 resumeSession: true,
9111 flags: []string{
9112 "-resumption-delay", "10",
9113 },
Steven Valdez5b986082016-09-01 12:29:49 -04009114 })
9115
Steven Valdeza833c352016-11-01 13:39:36 -04009116 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009117 testCases = append(testCases, testCase{
9118 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009119 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009120 config: Config{
9121 MaxVersion: VersionTLS13,
9122 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009123 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009124 },
9125 },
Steven Valdeza833c352016-11-01 13:39:36 -04009126 resumeSession: true,
9127 shouldFail: true,
9128 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009129 })
9130
David Benjamin35ac5b72017-03-03 15:05:56 -05009131 // Test that the server's ticket age skew reporting works.
9132 testCases = append(testCases, testCase{
9133 testType: serverTest,
9134 name: "TLS13-TicketAgeSkew-Forward",
9135 config: Config{
9136 MaxVersion: VersionTLS13,
9137 Bugs: ProtocolBugs{
9138 SendTicketAge: 15 * time.Second,
9139 },
9140 },
David Benjamin065d7332017-03-26 10:51:43 -05009141 resumeSession: true,
9142 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009143 flags: []string{
9144 "-resumption-delay", "10",
9145 "-expect-ticket-age-skew", "5",
9146 },
9147 })
9148 testCases = append(testCases, testCase{
9149 testType: serverTest,
9150 name: "TLS13-TicketAgeSkew-Backward",
9151 config: Config{
9152 MaxVersion: VersionTLS13,
9153 Bugs: ProtocolBugs{
9154 SendTicketAge: 5 * time.Second,
9155 },
9156 },
David Benjamin065d7332017-03-26 10:51:43 -05009157 resumeSession: true,
9158 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009159 flags: []string{
9160 "-resumption-delay", "10",
9161 "-expect-ticket-age-skew", "-5",
9162 },
9163 })
9164
Steven Valdez08b65f42016-12-07 15:29:45 -05009165 testCases = append(testCases, testCase{
9166 testType: clientTest,
9167 name: "TLS13-SendTicketEarlyDataInfo",
9168 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009169 MaxVersion: VersionTLS13,
9170 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009171 },
9172 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009173 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009174 "-expect-early-data-info",
9175 },
9176 })
9177
David Benjamin9b160662017-01-25 19:53:43 -05009178 // Test that 0-RTT tickets are ignored in clients unless opted in.
9179 testCases = append(testCases, testCase{
9180 testType: clientTest,
9181 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9182 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009183 MaxVersion: VersionTLS13,
9184 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009185 },
9186 })
9187
Steven Valdez08b65f42016-12-07 15:29:45 -05009188 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009189 testType: clientTest,
9190 name: "TLS13-DuplicateTicketEarlyDataInfo",
9191 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009192 MaxVersion: VersionTLS13,
9193 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009194 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009195 DuplicateTicketEarlyDataInfo: true,
9196 },
9197 },
9198 shouldFail: true,
9199 expectedError: ":DUPLICATE_EXTENSION:",
9200 expectedLocalError: "remote error: illegal parameter",
9201 })
9202
9203 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009204 testType: serverTest,
9205 name: "TLS13-ExpectTicketEarlyDataInfo",
9206 config: Config{
9207 MaxVersion: VersionTLS13,
9208 Bugs: ProtocolBugs{
9209 ExpectTicketEarlyDataInfo: true,
9210 },
9211 },
9212 flags: []string{
9213 "-enable-early-data",
9214 },
9215 })
David Benjamin17b30832017-01-28 14:00:32 -05009216
9217 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9218 // is honored.
9219 testCases = append(testCases, testCase{
9220 testType: clientTest,
9221 name: "TLS13-HonorServerSessionTicketLifetime",
9222 config: Config{
9223 MaxVersion: VersionTLS13,
9224 Bugs: ProtocolBugs{
9225 SendTicketLifetime: 20 * time.Second,
9226 },
9227 },
9228 flags: []string{
9229 "-resumption-delay", "19",
9230 },
9231 resumeSession: true,
9232 })
9233 testCases = append(testCases, testCase{
9234 testType: clientTest,
9235 name: "TLS13-HonorServerSessionTicketLifetime-2",
9236 config: Config{
9237 MaxVersion: VersionTLS13,
9238 Bugs: ProtocolBugs{
9239 SendTicketLifetime: 20 * time.Second,
9240 // The client should not offer the expired session.
9241 ExpectNoTLS13PSK: true,
9242 },
9243 },
9244 flags: []string{
9245 "-resumption-delay", "21",
9246 },
David Benjamin023d4192017-02-06 13:49:07 -05009247 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009248 expectResumeRejected: true,
9249 })
Steven Valdez5b986082016-09-01 12:29:49 -04009250}
9251
David Benjamin82261be2016-07-07 14:32:50 -07009252func addChangeCipherSpecTests() {
9253 // Test missing ChangeCipherSpecs.
9254 testCases = append(testCases, testCase{
9255 name: "SkipChangeCipherSpec-Client",
9256 config: Config{
9257 MaxVersion: VersionTLS12,
9258 Bugs: ProtocolBugs{
9259 SkipChangeCipherSpec: true,
9260 },
9261 },
9262 shouldFail: true,
9263 expectedError: ":UNEXPECTED_RECORD:",
9264 })
9265 testCases = append(testCases, testCase{
9266 testType: serverTest,
9267 name: "SkipChangeCipherSpec-Server",
9268 config: Config{
9269 MaxVersion: VersionTLS12,
9270 Bugs: ProtocolBugs{
9271 SkipChangeCipherSpec: true,
9272 },
9273 },
9274 shouldFail: true,
9275 expectedError: ":UNEXPECTED_RECORD:",
9276 })
9277 testCases = append(testCases, testCase{
9278 testType: serverTest,
9279 name: "SkipChangeCipherSpec-Server-NPN",
9280 config: Config{
9281 MaxVersion: VersionTLS12,
9282 NextProtos: []string{"bar"},
9283 Bugs: ProtocolBugs{
9284 SkipChangeCipherSpec: true,
9285 },
9286 },
9287 flags: []string{
9288 "-advertise-npn", "\x03foo\x03bar\x03baz",
9289 },
9290 shouldFail: true,
9291 expectedError: ":UNEXPECTED_RECORD:",
9292 })
9293
9294 // Test synchronization between the handshake and ChangeCipherSpec.
9295 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9296 // rejected. Test both with and without handshake packing to handle both
9297 // when the partial post-CCS message is in its own record and when it is
9298 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009299 for _, packed := range []bool{false, true} {
9300 var suffix string
9301 if packed {
9302 suffix = "-Packed"
9303 }
9304
9305 testCases = append(testCases, testCase{
9306 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9307 config: Config{
9308 MaxVersion: VersionTLS12,
9309 Bugs: ProtocolBugs{
9310 FragmentAcrossChangeCipherSpec: true,
9311 PackHandshakeFlight: packed,
9312 },
9313 },
9314 shouldFail: true,
9315 expectedError: ":UNEXPECTED_RECORD:",
9316 })
9317 testCases = append(testCases, testCase{
9318 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9319 config: Config{
9320 MaxVersion: VersionTLS12,
9321 },
9322 resumeSession: true,
9323 resumeConfig: &Config{
9324 MaxVersion: VersionTLS12,
9325 Bugs: ProtocolBugs{
9326 FragmentAcrossChangeCipherSpec: true,
9327 PackHandshakeFlight: packed,
9328 },
9329 },
9330 shouldFail: true,
9331 expectedError: ":UNEXPECTED_RECORD:",
9332 })
9333 testCases = append(testCases, testCase{
9334 testType: serverTest,
9335 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9336 config: Config{
9337 MaxVersion: VersionTLS12,
9338 Bugs: ProtocolBugs{
9339 FragmentAcrossChangeCipherSpec: true,
9340 PackHandshakeFlight: packed,
9341 },
9342 },
9343 shouldFail: true,
9344 expectedError: ":UNEXPECTED_RECORD:",
9345 })
9346 testCases = append(testCases, testCase{
9347 testType: serverTest,
9348 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9349 config: Config{
9350 MaxVersion: VersionTLS12,
9351 },
9352 resumeSession: true,
9353 resumeConfig: &Config{
9354 MaxVersion: VersionTLS12,
9355 Bugs: ProtocolBugs{
9356 FragmentAcrossChangeCipherSpec: true,
9357 PackHandshakeFlight: packed,
9358 },
9359 },
9360 shouldFail: true,
9361 expectedError: ":UNEXPECTED_RECORD:",
9362 })
9363 testCases = append(testCases, testCase{
9364 testType: serverTest,
9365 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9366 config: Config{
9367 MaxVersion: VersionTLS12,
9368 NextProtos: []string{"bar"},
9369 Bugs: ProtocolBugs{
9370 FragmentAcrossChangeCipherSpec: true,
9371 PackHandshakeFlight: packed,
9372 },
9373 },
9374 flags: []string{
9375 "-advertise-npn", "\x03foo\x03bar\x03baz",
9376 },
9377 shouldFail: true,
9378 expectedError: ":UNEXPECTED_RECORD:",
9379 })
9380 }
9381
David Benjamin61672812016-07-14 23:10:43 -04009382 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9383 // messages in the handshake queue. Do this by testing the server
9384 // reading the client Finished, reversing the flight so Finished comes
9385 // first.
9386 testCases = append(testCases, testCase{
9387 protocol: dtls,
9388 testType: serverTest,
9389 name: "SendUnencryptedFinished-DTLS",
9390 config: Config{
9391 MaxVersion: VersionTLS12,
9392 Bugs: ProtocolBugs{
9393 SendUnencryptedFinished: true,
9394 ReverseHandshakeFragments: true,
9395 },
9396 },
9397 shouldFail: true,
9398 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9399 })
9400
Steven Valdez143e8b32016-07-11 13:19:03 -04009401 // Test synchronization between encryption changes and the handshake in
9402 // TLS 1.3, where ChangeCipherSpec is implicit.
9403 testCases = append(testCases, testCase{
9404 name: "PartialEncryptedExtensionsWithServerHello",
9405 config: Config{
9406 MaxVersion: VersionTLS13,
9407 Bugs: ProtocolBugs{
9408 PartialEncryptedExtensionsWithServerHello: true,
9409 },
9410 },
9411 shouldFail: true,
9412 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9413 })
9414 testCases = append(testCases, testCase{
9415 testType: serverTest,
9416 name: "PartialClientFinishedWithClientHello",
9417 config: Config{
9418 MaxVersion: VersionTLS13,
9419 Bugs: ProtocolBugs{
9420 PartialClientFinishedWithClientHello: true,
9421 },
9422 },
9423 shouldFail: true,
9424 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9425 })
9426
David Benjamin82261be2016-07-07 14:32:50 -07009427 // Test that early ChangeCipherSpecs are handled correctly.
9428 testCases = append(testCases, testCase{
9429 testType: serverTest,
9430 name: "EarlyChangeCipherSpec-server-1",
9431 config: Config{
9432 MaxVersion: VersionTLS12,
9433 Bugs: ProtocolBugs{
9434 EarlyChangeCipherSpec: 1,
9435 },
9436 },
9437 shouldFail: true,
9438 expectedError: ":UNEXPECTED_RECORD:",
9439 })
9440 testCases = append(testCases, testCase{
9441 testType: serverTest,
9442 name: "EarlyChangeCipherSpec-server-2",
9443 config: Config{
9444 MaxVersion: VersionTLS12,
9445 Bugs: ProtocolBugs{
9446 EarlyChangeCipherSpec: 2,
9447 },
9448 },
9449 shouldFail: true,
9450 expectedError: ":UNEXPECTED_RECORD:",
9451 })
9452 testCases = append(testCases, testCase{
9453 protocol: dtls,
9454 name: "StrayChangeCipherSpec",
9455 config: Config{
9456 // TODO(davidben): Once DTLS 1.3 exists, test
9457 // that stray ChangeCipherSpec messages are
9458 // rejected.
9459 MaxVersion: VersionTLS12,
9460 Bugs: ProtocolBugs{
9461 StrayChangeCipherSpec: true,
9462 },
9463 },
9464 })
9465
9466 // Test that the contents of ChangeCipherSpec are checked.
9467 testCases = append(testCases, testCase{
9468 name: "BadChangeCipherSpec-1",
9469 config: Config{
9470 MaxVersion: VersionTLS12,
9471 Bugs: ProtocolBugs{
9472 BadChangeCipherSpec: []byte{2},
9473 },
9474 },
9475 shouldFail: true,
9476 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9477 })
9478 testCases = append(testCases, testCase{
9479 name: "BadChangeCipherSpec-2",
9480 config: Config{
9481 MaxVersion: VersionTLS12,
9482 Bugs: ProtocolBugs{
9483 BadChangeCipherSpec: []byte{1, 1},
9484 },
9485 },
9486 shouldFail: true,
9487 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9488 })
9489 testCases = append(testCases, testCase{
9490 protocol: dtls,
9491 name: "BadChangeCipherSpec-DTLS-1",
9492 config: Config{
9493 MaxVersion: VersionTLS12,
9494 Bugs: ProtocolBugs{
9495 BadChangeCipherSpec: []byte{2},
9496 },
9497 },
9498 shouldFail: true,
9499 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9500 })
9501 testCases = append(testCases, testCase{
9502 protocol: dtls,
9503 name: "BadChangeCipherSpec-DTLS-2",
9504 config: Config{
9505 MaxVersion: VersionTLS12,
9506 Bugs: ProtocolBugs{
9507 BadChangeCipherSpec: []byte{1, 1},
9508 },
9509 },
9510 shouldFail: true,
9511 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9512 })
9513}
9514
David Benjamincd2c8062016-09-09 11:28:16 -04009515type perMessageTest struct {
9516 messageType uint8
9517 test testCase
9518}
9519
9520// makePerMessageTests returns a series of test templates which cover each
9521// message in the TLS handshake. These may be used with bugs like
9522// WrongMessageType to fully test a per-message bug.
9523func makePerMessageTests() []perMessageTest {
9524 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009525 for _, protocol := range []protocol{tls, dtls} {
9526 var suffix string
9527 if protocol == dtls {
9528 suffix = "-DTLS"
9529 }
9530
David Benjamincd2c8062016-09-09 11:28:16 -04009531 ret = append(ret, perMessageTest{
9532 messageType: typeClientHello,
9533 test: testCase{
9534 protocol: protocol,
9535 testType: serverTest,
9536 name: "ClientHello" + suffix,
9537 config: Config{
9538 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009539 },
9540 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009541 })
9542
9543 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009544 ret = append(ret, perMessageTest{
9545 messageType: typeHelloVerifyRequest,
9546 test: testCase{
9547 protocol: protocol,
9548 name: "HelloVerifyRequest" + suffix,
9549 config: Config{
9550 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009551 },
9552 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009553 })
9554 }
9555
David Benjamincd2c8062016-09-09 11:28:16 -04009556 ret = append(ret, perMessageTest{
9557 messageType: typeServerHello,
9558 test: testCase{
9559 protocol: protocol,
9560 name: "ServerHello" + suffix,
9561 config: Config{
9562 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009563 },
9564 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009565 })
9566
David Benjamincd2c8062016-09-09 11:28:16 -04009567 ret = append(ret, perMessageTest{
9568 messageType: typeCertificate,
9569 test: testCase{
9570 protocol: protocol,
9571 name: "ServerCertificate" + suffix,
9572 config: Config{
9573 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009574 },
9575 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009576 })
9577
David Benjamincd2c8062016-09-09 11:28:16 -04009578 ret = append(ret, perMessageTest{
9579 messageType: typeCertificateStatus,
9580 test: testCase{
9581 protocol: protocol,
9582 name: "CertificateStatus" + suffix,
9583 config: Config{
9584 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009585 },
David Benjamincd2c8062016-09-09 11:28:16 -04009586 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009587 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009588 })
9589
David Benjamincd2c8062016-09-09 11:28:16 -04009590 ret = append(ret, perMessageTest{
9591 messageType: typeServerKeyExchange,
9592 test: testCase{
9593 protocol: protocol,
9594 name: "ServerKeyExchange" + suffix,
9595 config: Config{
9596 MaxVersion: VersionTLS12,
9597 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009598 },
9599 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009600 })
9601
David Benjamincd2c8062016-09-09 11:28:16 -04009602 ret = append(ret, perMessageTest{
9603 messageType: typeCertificateRequest,
9604 test: testCase{
9605 protocol: protocol,
9606 name: "CertificateRequest" + suffix,
9607 config: Config{
9608 MaxVersion: VersionTLS12,
9609 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009610 },
9611 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009612 })
9613
David Benjamincd2c8062016-09-09 11:28:16 -04009614 ret = append(ret, perMessageTest{
9615 messageType: typeServerHelloDone,
9616 test: testCase{
9617 protocol: protocol,
9618 name: "ServerHelloDone" + suffix,
9619 config: Config{
9620 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009621 },
9622 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009623 })
9624
David Benjamincd2c8062016-09-09 11:28:16 -04009625 ret = append(ret, perMessageTest{
9626 messageType: typeCertificate,
9627 test: testCase{
9628 testType: serverTest,
9629 protocol: protocol,
9630 name: "ClientCertificate" + suffix,
9631 config: Config{
9632 Certificates: []Certificate{rsaCertificate},
9633 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009634 },
David Benjamincd2c8062016-09-09 11:28:16 -04009635 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009636 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009637 })
9638
David Benjamincd2c8062016-09-09 11:28:16 -04009639 ret = append(ret, perMessageTest{
9640 messageType: typeCertificateVerify,
9641 test: testCase{
9642 testType: serverTest,
9643 protocol: protocol,
9644 name: "CertificateVerify" + suffix,
9645 config: Config{
9646 Certificates: []Certificate{rsaCertificate},
9647 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009648 },
David Benjamincd2c8062016-09-09 11:28:16 -04009649 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009650 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009651 })
9652
David Benjamincd2c8062016-09-09 11:28:16 -04009653 ret = append(ret, perMessageTest{
9654 messageType: typeClientKeyExchange,
9655 test: testCase{
9656 testType: serverTest,
9657 protocol: protocol,
9658 name: "ClientKeyExchange" + suffix,
9659 config: Config{
9660 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009661 },
9662 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009663 })
9664
9665 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009666 ret = append(ret, perMessageTest{
9667 messageType: typeNextProtocol,
9668 test: testCase{
9669 testType: serverTest,
9670 protocol: protocol,
9671 name: "NextProtocol" + suffix,
9672 config: Config{
9673 MaxVersion: VersionTLS12,
9674 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009675 },
David Benjamincd2c8062016-09-09 11:28:16 -04009676 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009677 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009678 })
9679
David Benjamincd2c8062016-09-09 11:28:16 -04009680 ret = append(ret, perMessageTest{
9681 messageType: typeChannelID,
9682 test: testCase{
9683 testType: serverTest,
9684 protocol: protocol,
9685 name: "ChannelID" + suffix,
9686 config: Config{
9687 MaxVersion: VersionTLS12,
9688 ChannelID: channelIDKey,
9689 },
9690 flags: []string{
9691 "-expect-channel-id",
9692 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009693 },
9694 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009695 })
9696 }
9697
David Benjamincd2c8062016-09-09 11:28:16 -04009698 ret = append(ret, perMessageTest{
9699 messageType: typeFinished,
9700 test: testCase{
9701 testType: serverTest,
9702 protocol: protocol,
9703 name: "ClientFinished" + suffix,
9704 config: Config{
9705 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009706 },
9707 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009708 })
9709
David Benjamincd2c8062016-09-09 11:28:16 -04009710 ret = append(ret, perMessageTest{
9711 messageType: typeNewSessionTicket,
9712 test: testCase{
9713 protocol: protocol,
9714 name: "NewSessionTicket" + suffix,
9715 config: Config{
9716 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009717 },
9718 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009719 })
9720
David Benjamincd2c8062016-09-09 11:28:16 -04009721 ret = append(ret, perMessageTest{
9722 messageType: typeFinished,
9723 test: testCase{
9724 protocol: protocol,
9725 name: "ServerFinished" + suffix,
9726 config: Config{
9727 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009728 },
9729 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009730 })
9731
9732 }
David Benjamincd2c8062016-09-09 11:28:16 -04009733
9734 ret = append(ret, perMessageTest{
9735 messageType: typeClientHello,
9736 test: testCase{
9737 testType: serverTest,
9738 name: "TLS13-ClientHello",
9739 config: Config{
9740 MaxVersion: VersionTLS13,
9741 },
9742 },
9743 })
9744
9745 ret = append(ret, perMessageTest{
9746 messageType: typeServerHello,
9747 test: testCase{
9748 name: "TLS13-ServerHello",
9749 config: Config{
9750 MaxVersion: VersionTLS13,
9751 },
9752 },
9753 })
9754
9755 ret = append(ret, perMessageTest{
9756 messageType: typeEncryptedExtensions,
9757 test: testCase{
9758 name: "TLS13-EncryptedExtensions",
9759 config: Config{
9760 MaxVersion: VersionTLS13,
9761 },
9762 },
9763 })
9764
9765 ret = append(ret, perMessageTest{
9766 messageType: typeCertificateRequest,
9767 test: testCase{
9768 name: "TLS13-CertificateRequest",
9769 config: Config{
9770 MaxVersion: VersionTLS13,
9771 ClientAuth: RequireAnyClientCert,
9772 },
9773 },
9774 })
9775
9776 ret = append(ret, perMessageTest{
9777 messageType: typeCertificate,
9778 test: testCase{
9779 name: "TLS13-ServerCertificate",
9780 config: Config{
9781 MaxVersion: VersionTLS13,
9782 },
9783 },
9784 })
9785
9786 ret = append(ret, perMessageTest{
9787 messageType: typeCertificateVerify,
9788 test: testCase{
9789 name: "TLS13-ServerCertificateVerify",
9790 config: Config{
9791 MaxVersion: VersionTLS13,
9792 },
9793 },
9794 })
9795
9796 ret = append(ret, perMessageTest{
9797 messageType: typeFinished,
9798 test: testCase{
9799 name: "TLS13-ServerFinished",
9800 config: Config{
9801 MaxVersion: VersionTLS13,
9802 },
9803 },
9804 })
9805
9806 ret = append(ret, perMessageTest{
9807 messageType: typeCertificate,
9808 test: testCase{
9809 testType: serverTest,
9810 name: "TLS13-ClientCertificate",
9811 config: Config{
9812 Certificates: []Certificate{rsaCertificate},
9813 MaxVersion: VersionTLS13,
9814 },
9815 flags: []string{"-require-any-client-certificate"},
9816 },
9817 })
9818
9819 ret = append(ret, perMessageTest{
9820 messageType: typeCertificateVerify,
9821 test: testCase{
9822 testType: serverTest,
9823 name: "TLS13-ClientCertificateVerify",
9824 config: Config{
9825 Certificates: []Certificate{rsaCertificate},
9826 MaxVersion: VersionTLS13,
9827 },
9828 flags: []string{"-require-any-client-certificate"},
9829 },
9830 })
9831
9832 ret = append(ret, perMessageTest{
9833 messageType: typeFinished,
9834 test: testCase{
9835 testType: serverTest,
9836 name: "TLS13-ClientFinished",
9837 config: Config{
9838 MaxVersion: VersionTLS13,
9839 },
9840 },
9841 })
9842
9843 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009844}
9845
David Benjamincd2c8062016-09-09 11:28:16 -04009846func addWrongMessageTypeTests() {
9847 for _, t := range makePerMessageTests() {
9848 t.test.name = "WrongMessageType-" + t.test.name
9849 t.test.config.Bugs.SendWrongMessageType = t.messageType
9850 t.test.shouldFail = true
9851 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9852 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009853
David Benjamincd2c8062016-09-09 11:28:16 -04009854 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9855 // In TLS 1.3, a bad ServerHello means the client sends
9856 // an unencrypted alert while the server expects
9857 // encryption, so the alert is not readable by runner.
9858 t.test.expectedLocalError = "local error: bad record MAC"
9859 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009860
David Benjamincd2c8062016-09-09 11:28:16 -04009861 testCases = append(testCases, t.test)
9862 }
David Benjaminebacdee2017-04-08 11:00:45 -04009863
9864 // The processing order for TLS 1.3 version negotiation is such that one
9865 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
9866 // TLS 1.2. Test that we do not do this.
9867 testCases = append(testCases, testCase{
9868 name: "SendServerHelloAsHelloRetryRequest",
9869 config: Config{
9870 MaxVersion: VersionTLS12,
9871 Bugs: ProtocolBugs{
9872 SendServerHelloAsHelloRetryRequest: true,
9873 },
9874 },
9875 shouldFail: true,
9876 expectedError: ":UNEXPECTED_MESSAGE:",
9877 expectedLocalError: "remote error: unexpected message",
9878 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009879}
9880
David Benjamin639846e2016-09-09 11:41:18 -04009881func addTrailingMessageDataTests() {
9882 for _, t := range makePerMessageTests() {
9883 t.test.name = "TrailingMessageData-" + t.test.name
9884 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9885 t.test.shouldFail = true
9886 t.test.expectedError = ":DECODE_ERROR:"
9887 t.test.expectedLocalError = "remote error: error decoding message"
9888
9889 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9890 // In TLS 1.3, a bad ServerHello means the client sends
9891 // an unencrypted alert while the server expects
9892 // encryption, so the alert is not readable by runner.
9893 t.test.expectedLocalError = "local error: bad record MAC"
9894 }
9895
9896 if t.messageType == typeFinished {
9897 // Bad Finished messages read as the verify data having
9898 // the wrong length.
9899 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9900 t.test.expectedLocalError = "remote error: error decrypting message"
9901 }
9902
9903 testCases = append(testCases, t.test)
9904 }
9905}
9906
Steven Valdez143e8b32016-07-11 13:19:03 -04009907func addTLS13HandshakeTests() {
9908 testCases = append(testCases, testCase{
9909 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009910 name: "NegotiatePSKResumption-TLS13",
9911 config: Config{
9912 MaxVersion: VersionTLS13,
9913 Bugs: ProtocolBugs{
9914 NegotiatePSKResumption: true,
9915 },
9916 },
9917 resumeSession: true,
9918 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009919 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009920 })
9921
9922 testCases = append(testCases, testCase{
9923 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009924 name: "MissingKeyShare-Client",
9925 config: Config{
9926 MaxVersion: VersionTLS13,
9927 Bugs: ProtocolBugs{
9928 MissingKeyShare: true,
9929 },
9930 },
9931 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009932 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009933 })
9934
9935 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009936 testType: serverTest,
9937 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009938 config: Config{
9939 MaxVersion: VersionTLS13,
9940 Bugs: ProtocolBugs{
9941 MissingKeyShare: true,
9942 },
9943 },
9944 shouldFail: true,
9945 expectedError: ":MISSING_KEY_SHARE:",
9946 })
9947
9948 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009949 testType: serverTest,
9950 name: "DuplicateKeyShares",
9951 config: Config{
9952 MaxVersion: VersionTLS13,
9953 Bugs: ProtocolBugs{
9954 DuplicateKeyShares: true,
9955 },
9956 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009957 shouldFail: true,
9958 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009959 })
9960
9961 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009962 testType: serverTest,
9963 name: "SkipEarlyData",
9964 config: Config{
9965 MaxVersion: VersionTLS13,
9966 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009967 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009968 },
9969 },
9970 })
9971
9972 testCases = append(testCases, testCase{
9973 testType: serverTest,
9974 name: "SkipEarlyData-OmitEarlyDataExtension",
9975 config: Config{
9976 MaxVersion: VersionTLS13,
9977 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009978 SendFakeEarlyDataLength: 4,
9979 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009980 },
9981 },
9982 shouldFail: true,
9983 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9984 })
9985
9986 testCases = append(testCases, testCase{
9987 testType: serverTest,
9988 name: "SkipEarlyData-TooMuchData",
9989 config: Config{
9990 MaxVersion: VersionTLS13,
9991 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009992 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009993 },
9994 },
9995 shouldFail: true,
9996 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9997 })
9998
9999 testCases = append(testCases, testCase{
10000 testType: serverTest,
10001 name: "SkipEarlyData-Interleaved",
10002 config: Config{
10003 MaxVersion: VersionTLS13,
10004 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010005 SendFakeEarlyDataLength: 4,
10006 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010007 },
10008 },
10009 shouldFail: true,
10010 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10011 })
10012
10013 testCases = append(testCases, testCase{
10014 testType: serverTest,
10015 name: "SkipEarlyData-EarlyDataInTLS12",
10016 config: Config{
10017 MaxVersion: VersionTLS13,
10018 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010019 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010020 },
10021 },
10022 shouldFail: true,
10023 expectedError: ":UNEXPECTED_RECORD:",
10024 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10025 })
10026
10027 testCases = append(testCases, testCase{
10028 testType: serverTest,
10029 name: "SkipEarlyData-HRR",
10030 config: Config{
10031 MaxVersion: VersionTLS13,
10032 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010033 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010034 },
10035 DefaultCurves: []CurveID{},
10036 },
10037 })
10038
10039 testCases = append(testCases, testCase{
10040 testType: serverTest,
10041 name: "SkipEarlyData-HRR-Interleaved",
10042 config: Config{
10043 MaxVersion: VersionTLS13,
10044 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010045 SendFakeEarlyDataLength: 4,
10046 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010047 },
10048 DefaultCurves: []CurveID{},
10049 },
10050 shouldFail: true,
10051 expectedError: ":UNEXPECTED_RECORD:",
10052 })
10053
10054 testCases = append(testCases, testCase{
10055 testType: serverTest,
10056 name: "SkipEarlyData-HRR-TooMuchData",
10057 config: Config{
10058 MaxVersion: VersionTLS13,
10059 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010060 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010061 },
10062 DefaultCurves: []CurveID{},
10063 },
10064 shouldFail: true,
10065 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10066 })
10067
10068 // Test that skipping early data looking for cleartext correctly
10069 // processes an alert record.
10070 testCases = append(testCases, testCase{
10071 testType: serverTest,
10072 name: "SkipEarlyData-HRR-FatalAlert",
10073 config: Config{
10074 MaxVersion: VersionTLS13,
10075 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010076 SendEarlyAlert: true,
10077 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010078 },
10079 DefaultCurves: []CurveID{},
10080 },
10081 shouldFail: true,
10082 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10083 })
10084
10085 testCases = append(testCases, testCase{
10086 testType: serverTest,
10087 name: "SkipEarlyData-SecondClientHelloEarlyData",
10088 config: Config{
10089 MaxVersion: VersionTLS13,
10090 Bugs: ProtocolBugs{
10091 SendEarlyDataOnSecondClientHello: true,
10092 },
10093 DefaultCurves: []CurveID{},
10094 },
10095 shouldFail: true,
10096 expectedLocalError: "remote error: bad record MAC",
10097 })
10098
10099 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010100 testType: clientTest,
10101 name: "EmptyEncryptedExtensions",
10102 config: Config{
10103 MaxVersion: VersionTLS13,
10104 Bugs: ProtocolBugs{
10105 EmptyEncryptedExtensions: true,
10106 },
10107 },
10108 shouldFail: true,
10109 expectedLocalError: "remote error: error decoding message",
10110 })
10111
10112 testCases = append(testCases, testCase{
10113 testType: clientTest,
10114 name: "EncryptedExtensionsWithKeyShare",
10115 config: Config{
10116 MaxVersion: VersionTLS13,
10117 Bugs: ProtocolBugs{
10118 EncryptedExtensionsWithKeyShare: true,
10119 },
10120 },
10121 shouldFail: true,
10122 expectedLocalError: "remote error: unsupported extension",
10123 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010124
10125 testCases = append(testCases, testCase{
10126 testType: serverTest,
10127 name: "SendHelloRetryRequest",
10128 config: Config{
10129 MaxVersion: VersionTLS13,
10130 // Require a HelloRetryRequest for every curve.
10131 DefaultCurves: []CurveID{},
10132 },
10133 expectedCurveID: CurveX25519,
10134 })
10135
10136 testCases = append(testCases, testCase{
10137 testType: serverTest,
10138 name: "SendHelloRetryRequest-2",
10139 config: Config{
10140 MaxVersion: VersionTLS13,
10141 DefaultCurves: []CurveID{CurveP384},
10142 },
10143 // Although the ClientHello did not predict our preferred curve,
10144 // we always select it whether it is predicted or not.
10145 expectedCurveID: CurveX25519,
10146 })
10147
10148 testCases = append(testCases, testCase{
10149 name: "UnknownCurve-HelloRetryRequest",
10150 config: Config{
10151 MaxVersion: VersionTLS13,
10152 // P-384 requires HelloRetryRequest in BoringSSL.
10153 CurvePreferences: []CurveID{CurveP384},
10154 Bugs: ProtocolBugs{
10155 SendHelloRetryRequestCurve: bogusCurve,
10156 },
10157 },
10158 shouldFail: true,
10159 expectedError: ":WRONG_CURVE:",
10160 })
10161
10162 testCases = append(testCases, testCase{
10163 name: "DisabledCurve-HelloRetryRequest",
10164 config: Config{
10165 MaxVersion: VersionTLS13,
10166 CurvePreferences: []CurveID{CurveP256},
10167 Bugs: ProtocolBugs{
10168 IgnorePeerCurvePreferences: true,
10169 },
10170 },
10171 flags: []string{"-p384-only"},
10172 shouldFail: true,
10173 expectedError: ":WRONG_CURVE:",
10174 })
10175
10176 testCases = append(testCases, testCase{
10177 name: "UnnecessaryHelloRetryRequest",
10178 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010179 MaxVersion: VersionTLS13,
10180 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010181 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010182 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010183 },
10184 },
10185 shouldFail: true,
10186 expectedError: ":WRONG_CURVE:",
10187 })
10188
10189 testCases = append(testCases, testCase{
10190 name: "SecondHelloRetryRequest",
10191 config: Config{
10192 MaxVersion: VersionTLS13,
10193 // P-384 requires HelloRetryRequest in BoringSSL.
10194 CurvePreferences: []CurveID{CurveP384},
10195 Bugs: ProtocolBugs{
10196 SecondHelloRetryRequest: true,
10197 },
10198 },
10199 shouldFail: true,
10200 expectedError: ":UNEXPECTED_MESSAGE:",
10201 })
10202
10203 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010204 name: "HelloRetryRequest-Empty",
10205 config: Config{
10206 MaxVersion: VersionTLS13,
10207 Bugs: ProtocolBugs{
10208 AlwaysSendHelloRetryRequest: true,
10209 },
10210 },
10211 shouldFail: true,
10212 expectedError: ":DECODE_ERROR:",
10213 })
10214
10215 testCases = append(testCases, testCase{
10216 name: "HelloRetryRequest-DuplicateCurve",
10217 config: Config{
10218 MaxVersion: VersionTLS13,
10219 // P-384 requires a HelloRetryRequest against BoringSSL's default
10220 // configuration. Assert this ExpectMissingKeyShare.
10221 CurvePreferences: []CurveID{CurveP384},
10222 Bugs: ProtocolBugs{
10223 ExpectMissingKeyShare: true,
10224 DuplicateHelloRetryRequestExtensions: true,
10225 },
10226 },
10227 shouldFail: true,
10228 expectedError: ":DUPLICATE_EXTENSION:",
10229 expectedLocalError: "remote error: illegal parameter",
10230 })
10231
10232 testCases = append(testCases, testCase{
10233 name: "HelloRetryRequest-Cookie",
10234 config: Config{
10235 MaxVersion: VersionTLS13,
10236 Bugs: ProtocolBugs{
10237 SendHelloRetryRequestCookie: []byte("cookie"),
10238 },
10239 },
10240 })
10241
10242 testCases = append(testCases, testCase{
10243 name: "HelloRetryRequest-DuplicateCookie",
10244 config: Config{
10245 MaxVersion: VersionTLS13,
10246 Bugs: ProtocolBugs{
10247 SendHelloRetryRequestCookie: []byte("cookie"),
10248 DuplicateHelloRetryRequestExtensions: true,
10249 },
10250 },
10251 shouldFail: true,
10252 expectedError: ":DUPLICATE_EXTENSION:",
10253 expectedLocalError: "remote error: illegal parameter",
10254 })
10255
10256 testCases = append(testCases, testCase{
10257 name: "HelloRetryRequest-EmptyCookie",
10258 config: Config{
10259 MaxVersion: VersionTLS13,
10260 Bugs: ProtocolBugs{
10261 SendHelloRetryRequestCookie: []byte{},
10262 },
10263 },
10264 shouldFail: true,
10265 expectedError: ":DECODE_ERROR:",
10266 })
10267
10268 testCases = append(testCases, testCase{
10269 name: "HelloRetryRequest-Cookie-Curve",
10270 config: Config{
10271 MaxVersion: VersionTLS13,
10272 // P-384 requires HelloRetryRequest in BoringSSL.
10273 CurvePreferences: []CurveID{CurveP384},
10274 Bugs: ProtocolBugs{
10275 SendHelloRetryRequestCookie: []byte("cookie"),
10276 ExpectMissingKeyShare: true,
10277 },
10278 },
10279 })
10280
10281 testCases = append(testCases, testCase{
10282 name: "HelloRetryRequest-Unknown",
10283 config: Config{
10284 MaxVersion: VersionTLS13,
10285 Bugs: ProtocolBugs{
10286 CustomHelloRetryRequestExtension: "extension",
10287 },
10288 },
10289 shouldFail: true,
10290 expectedError: ":UNEXPECTED_EXTENSION:",
10291 expectedLocalError: "remote error: unsupported extension",
10292 })
10293
10294 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010295 testType: serverTest,
10296 name: "SecondClientHelloMissingKeyShare",
10297 config: Config{
10298 MaxVersion: VersionTLS13,
10299 DefaultCurves: []CurveID{},
10300 Bugs: ProtocolBugs{
10301 SecondClientHelloMissingKeyShare: true,
10302 },
10303 },
10304 shouldFail: true,
10305 expectedError: ":MISSING_KEY_SHARE:",
10306 })
10307
10308 testCases = append(testCases, testCase{
10309 testType: serverTest,
10310 name: "SecondClientHelloWrongCurve",
10311 config: Config{
10312 MaxVersion: VersionTLS13,
10313 DefaultCurves: []CurveID{},
10314 Bugs: ProtocolBugs{
10315 MisinterpretHelloRetryRequestCurve: CurveP521,
10316 },
10317 },
10318 shouldFail: true,
10319 expectedError: ":WRONG_CURVE:",
10320 })
10321
10322 testCases = append(testCases, testCase{
10323 name: "HelloRetryRequestVersionMismatch",
10324 config: Config{
10325 MaxVersion: VersionTLS13,
10326 // P-384 requires HelloRetryRequest in BoringSSL.
10327 CurvePreferences: []CurveID{CurveP384},
10328 Bugs: ProtocolBugs{
10329 SendServerHelloVersion: 0x0305,
10330 },
10331 },
10332 shouldFail: true,
10333 expectedError: ":WRONG_VERSION_NUMBER:",
10334 })
10335
10336 testCases = append(testCases, testCase{
10337 name: "HelloRetryRequestCurveMismatch",
10338 config: Config{
10339 MaxVersion: VersionTLS13,
10340 // P-384 requires HelloRetryRequest in BoringSSL.
10341 CurvePreferences: []CurveID{CurveP384},
10342 Bugs: ProtocolBugs{
10343 // Send P-384 (correct) in the HelloRetryRequest.
10344 SendHelloRetryRequestCurve: CurveP384,
10345 // But send P-256 in the ServerHello.
10346 SendCurve: CurveP256,
10347 },
10348 },
10349 shouldFail: true,
10350 expectedError: ":WRONG_CURVE:",
10351 })
10352
10353 // Test the server selecting a curve that requires a HelloRetryRequest
10354 // without sending it.
10355 testCases = append(testCases, testCase{
10356 name: "SkipHelloRetryRequest",
10357 config: Config{
10358 MaxVersion: VersionTLS13,
10359 // P-384 requires HelloRetryRequest in BoringSSL.
10360 CurvePreferences: []CurveID{CurveP384},
10361 Bugs: ProtocolBugs{
10362 SkipHelloRetryRequest: true,
10363 },
10364 },
10365 shouldFail: true,
10366 expectedError: ":WRONG_CURVE:",
10367 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010368
10369 testCases = append(testCases, testCase{
10370 name: "TLS13-RequestContextInHandshake",
10371 config: Config{
10372 MaxVersion: VersionTLS13,
10373 MinVersion: VersionTLS13,
10374 ClientAuth: RequireAnyClientCert,
10375 Bugs: ProtocolBugs{
10376 SendRequestContext: []byte("request context"),
10377 },
10378 },
10379 flags: []string{
10380 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10381 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10382 },
10383 shouldFail: true,
10384 expectedError: ":DECODE_ERROR:",
10385 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010386
10387 testCases = append(testCases, testCase{
10388 testType: serverTest,
10389 name: "TLS13-TrailingKeyShareData",
10390 config: Config{
10391 MaxVersion: VersionTLS13,
10392 Bugs: ProtocolBugs{
10393 TrailingKeyShareData: true,
10394 },
10395 },
10396 shouldFail: true,
10397 expectedError: ":DECODE_ERROR:",
10398 })
David Benjamin7f78df42016-10-05 22:33:19 -040010399
10400 testCases = append(testCases, testCase{
10401 name: "TLS13-AlwaysSelectPSKIdentity",
10402 config: Config{
10403 MaxVersion: VersionTLS13,
10404 Bugs: ProtocolBugs{
10405 AlwaysSelectPSKIdentity: true,
10406 },
10407 },
10408 shouldFail: true,
10409 expectedError: ":UNEXPECTED_EXTENSION:",
10410 })
10411
10412 testCases = append(testCases, testCase{
10413 name: "TLS13-InvalidPSKIdentity",
10414 config: Config{
10415 MaxVersion: VersionTLS13,
10416 Bugs: ProtocolBugs{
10417 SelectPSKIdentityOnResume: 1,
10418 },
10419 },
10420 resumeSession: true,
10421 shouldFail: true,
10422 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10423 })
David Benjamin1286bee2016-10-07 15:25:06 -040010424
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010425 testCases = append(testCases, testCase{
10426 testType: serverTest,
10427 name: "TLS13-ExtraPSKIdentity",
10428 config: Config{
10429 MaxVersion: VersionTLS13,
10430 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010431 ExtraPSKIdentity: true,
10432 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010433 },
10434 },
10435 resumeSession: true,
10436 })
10437
David Benjamin1286bee2016-10-07 15:25:06 -040010438 // Test that unknown NewSessionTicket extensions are tolerated.
10439 testCases = append(testCases, testCase{
10440 name: "TLS13-CustomTicketExtension",
10441 config: Config{
10442 MaxVersion: VersionTLS13,
10443 Bugs: ProtocolBugs{
10444 CustomTicketExtension: "1234",
10445 },
10446 },
10447 })
Steven Valdez2d850622017-01-11 11:34:52 -050010448
Steven Valdez2d850622017-01-11 11:34:52 -050010449 testCases = append(testCases, testCase{
10450 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010451 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010452 config: Config{
10453 MaxVersion: VersionTLS13,
10454 MaxEarlyDataSize: 16384,
10455 },
10456 resumeConfig: &Config{
10457 MaxVersion: VersionTLS13,
10458 MaxEarlyDataSize: 16384,
10459 Bugs: ProtocolBugs{
10460 AlwaysRejectEarlyData: true,
10461 },
10462 },
10463 resumeSession: true,
10464 flags: []string{
10465 "-enable-early-data",
10466 "-expect-early-data-info",
10467 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010468 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010469 },
10470 })
10471
10472 testCases = append(testCases, testCase{
10473 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010474 name: "TLS13-EarlyData-RejectTicket-Client",
10475 config: Config{
10476 MaxVersion: VersionTLS13,
10477 MaxEarlyDataSize: 16384,
10478 Certificates: []Certificate{rsaCertificate},
10479 },
10480 resumeConfig: &Config{
10481 MaxVersion: VersionTLS13,
10482 MaxEarlyDataSize: 16384,
10483 Certificates: []Certificate{ecdsaP256Certificate},
10484 SessionTicketsDisabled: true,
10485 },
10486 resumeSession: true,
10487 expectResumeRejected: true,
10488 flags: []string{
10489 "-enable-early-data",
10490 "-expect-early-data-info",
10491 "-expect-reject-early-data",
10492 "-on-resume-shim-writes-first",
10493 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10494 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10495 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10496 // Session tickets are disabled, so the runner will not send a ticket.
10497 "-on-retry-expect-no-session",
10498 },
10499 })
10500
10501 testCases = append(testCases, testCase{
10502 testType: clientTest,
10503 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010504 config: Config{
10505 MaxVersion: VersionTLS13,
10506 MaxEarlyDataSize: 16384,
10507 },
10508 resumeConfig: &Config{
10509 MaxVersion: VersionTLS13,
10510 MaxEarlyDataSize: 16384,
10511 Bugs: ProtocolBugs{
10512 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10513 },
10514 },
10515 resumeSession: true,
10516 flags: []string{
10517 "-enable-early-data",
10518 "-expect-early-data-info",
10519 "-expect-reject-early-data",
10520 },
10521 })
10522
10523 // The client must check the server does not send the early_data
10524 // extension while rejecting the session.
10525 testCases = append(testCases, testCase{
10526 testType: clientTest,
10527 name: "TLS13-EarlyDataWithoutResume-Client",
10528 config: Config{
10529 MaxVersion: VersionTLS13,
10530 MaxEarlyDataSize: 16384,
10531 },
10532 resumeConfig: &Config{
10533 MaxVersion: VersionTLS13,
10534 SessionTicketsDisabled: true,
10535 Bugs: ProtocolBugs{
10536 SendEarlyDataExtension: true,
10537 },
10538 },
10539 resumeSession: true,
10540 flags: []string{
10541 "-enable-early-data",
10542 "-expect-early-data-info",
10543 },
10544 shouldFail: true,
10545 expectedError: ":UNEXPECTED_EXTENSION:",
10546 })
10547
10548 // The client must fail with a dedicated error code if the server
10549 // responds with TLS 1.2 when offering 0-RTT.
10550 testCases = append(testCases, testCase{
10551 testType: clientTest,
10552 name: "TLS13-EarlyDataVersionDowngrade-Client",
10553 config: Config{
10554 MaxVersion: VersionTLS13,
10555 MaxEarlyDataSize: 16384,
10556 },
10557 resumeConfig: &Config{
10558 MaxVersion: VersionTLS12,
10559 },
10560 resumeSession: true,
10561 flags: []string{
10562 "-enable-early-data",
10563 "-expect-early-data-info",
10564 },
10565 shouldFail: true,
10566 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10567 })
10568
10569 // Test that the client rejects an (unsolicited) early_data extension if
10570 // the server sent an HRR.
10571 testCases = append(testCases, testCase{
10572 testType: clientTest,
10573 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10574 config: Config{
10575 MaxVersion: VersionTLS13,
10576 MaxEarlyDataSize: 16384,
10577 },
10578 resumeConfig: &Config{
10579 MaxVersion: VersionTLS13,
10580 MaxEarlyDataSize: 16384,
10581 Bugs: ProtocolBugs{
10582 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10583 SendEarlyDataExtension: true,
10584 },
10585 },
10586 resumeSession: true,
10587 flags: []string{
10588 "-enable-early-data",
10589 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010590 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010591 },
10592 shouldFail: true,
10593 expectedError: ":UNEXPECTED_EXTENSION:",
10594 })
10595
10596 fooString := "foo"
10597 barString := "bar"
10598
10599 // Test that the client reports the correct ALPN after a 0-RTT reject
10600 // that changed it.
10601 testCases = append(testCases, testCase{
10602 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010603 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010604 config: Config{
10605 MaxVersion: VersionTLS13,
10606 MaxEarlyDataSize: 16384,
10607 Bugs: ProtocolBugs{
10608 ALPNProtocol: &fooString,
10609 },
10610 },
10611 resumeConfig: &Config{
10612 MaxVersion: VersionTLS13,
10613 MaxEarlyDataSize: 16384,
10614 Bugs: ProtocolBugs{
10615 ALPNProtocol: &barString,
10616 },
10617 },
10618 resumeSession: true,
10619 flags: []string{
10620 "-advertise-alpn", "\x03foo\x03bar",
10621 "-enable-early-data",
10622 "-expect-early-data-info",
10623 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010624 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010625 "-on-resume-expect-alpn", "foo",
10626 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010627 },
10628 })
10629
10630 // Test that the client reports the correct ALPN after a 0-RTT reject if
10631 // ALPN was omitted from the first connection.
10632 testCases = append(testCases, testCase{
10633 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010634 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010635 config: Config{
10636 MaxVersion: VersionTLS13,
10637 MaxEarlyDataSize: 16384,
10638 },
10639 resumeConfig: &Config{
10640 MaxVersion: VersionTLS13,
10641 MaxEarlyDataSize: 16384,
10642 NextProtos: []string{"foo"},
10643 },
10644 resumeSession: true,
10645 flags: []string{
10646 "-advertise-alpn", "\x03foo\x03bar",
10647 "-enable-early-data",
10648 "-expect-early-data-info",
10649 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010650 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010651 "-on-resume-expect-alpn", "",
10652 "-on-retry-expect-alpn", "foo",
10653 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010654 },
10655 })
10656
10657 // Test that the client reports the correct ALPN after a 0-RTT reject if
10658 // ALPN was omitted from the second connection.
10659 testCases = append(testCases, testCase{
10660 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010661 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010662 config: Config{
10663 MaxVersion: VersionTLS13,
10664 MaxEarlyDataSize: 16384,
10665 NextProtos: []string{"foo"},
10666 },
10667 resumeConfig: &Config{
10668 MaxVersion: VersionTLS13,
10669 MaxEarlyDataSize: 16384,
10670 },
10671 resumeSession: true,
10672 flags: []string{
10673 "-advertise-alpn", "\x03foo\x03bar",
10674 "-enable-early-data",
10675 "-expect-early-data-info",
10676 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010677 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010678 "-on-resume-expect-alpn", "foo",
10679 "-on-retry-expect-alpn", "",
10680 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010681 },
10682 })
10683
10684 // Test that the client enforces ALPN match on 0-RTT accept.
10685 testCases = append(testCases, testCase{
10686 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010687 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010688 config: Config{
10689 MaxVersion: VersionTLS13,
10690 MaxEarlyDataSize: 16384,
10691 Bugs: ProtocolBugs{
10692 ALPNProtocol: &fooString,
10693 },
10694 },
10695 resumeConfig: &Config{
10696 MaxVersion: VersionTLS13,
10697 MaxEarlyDataSize: 16384,
10698 Bugs: ProtocolBugs{
10699 AlwaysAcceptEarlyData: true,
10700 ALPNProtocol: &barString,
10701 },
10702 },
10703 resumeSession: true,
10704 flags: []string{
10705 "-advertise-alpn", "\x03foo\x03bar",
10706 "-enable-early-data",
10707 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010708 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010709 "-on-resume-expect-alpn", "foo",
10710 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010711 },
10712 shouldFail: true,
10713 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10714 })
10715
10716 // Test that the server correctly rejects 0-RTT when the previous
10717 // session did not allow early data on resumption.
10718 testCases = append(testCases, testCase{
10719 testType: serverTest,
10720 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10721 config: Config{
10722 MaxVersion: VersionTLS13,
10723 },
10724 resumeConfig: &Config{
10725 MaxVersion: VersionTLS13,
10726 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010727 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010728 ExpectEarlyDataAccepted: false,
10729 },
10730 },
10731 resumeSession: true,
10732 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010733 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010734 "-expect-reject-early-data",
10735 },
10736 })
10737
10738 // Test that we reject early data where ALPN is omitted from the first
10739 // connection.
10740 testCases = append(testCases, testCase{
10741 testType: serverTest,
10742 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10743 config: Config{
10744 MaxVersion: VersionTLS13,
10745 NextProtos: []string{},
10746 },
10747 resumeConfig: &Config{
10748 MaxVersion: VersionTLS13,
10749 NextProtos: []string{"foo"},
10750 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010751 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010752 ExpectEarlyDataAccepted: false,
10753 },
10754 },
10755 resumeSession: true,
10756 flags: []string{
10757 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010758 "-on-initial-select-alpn", "",
10759 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010760 },
10761 })
10762
10763 // Test that we reject early data where ALPN is omitted from the second
10764 // connection.
10765 testCases = append(testCases, testCase{
10766 testType: serverTest,
10767 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10768 config: Config{
10769 MaxVersion: VersionTLS13,
10770 NextProtos: []string{"foo"},
10771 },
10772 resumeConfig: &Config{
10773 MaxVersion: VersionTLS13,
10774 NextProtos: []string{},
10775 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010776 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010777 ExpectEarlyDataAccepted: false,
10778 },
10779 },
10780 resumeSession: true,
10781 flags: []string{
10782 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010783 "-on-initial-select-alpn", "foo",
10784 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010785 },
10786 })
10787
10788 // Test that we reject early data with mismatched ALPN.
10789 testCases = append(testCases, testCase{
10790 testType: serverTest,
10791 name: "TLS13-EarlyData-ALPNMismatch-Server",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 NextProtos: []string{"foo"},
10795 },
10796 resumeConfig: &Config{
10797 MaxVersion: VersionTLS13,
10798 NextProtos: []string{"bar"},
10799 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010800 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010801 ExpectEarlyDataAccepted: false,
10802 },
10803 },
10804 resumeSession: true,
10805 flags: []string{
10806 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010807 "-on-initial-select-alpn", "foo",
10808 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010809 },
10810 })
10811
David Benjamin6bb507b2017-03-29 16:35:57 -050010812 // Test that the client offering 0-RTT and Channel ID forbids the server
10813 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010814 testCases = append(testCases, testCase{
10815 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010816 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010817 config: Config{
10818 MaxVersion: VersionTLS13,
10819 MaxEarlyDataSize: 16384,
10820 RequestChannelID: true,
10821 },
10822 resumeSession: true,
10823 expectChannelID: true,
10824 shouldFail: true,
10825 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10826 flags: []string{
10827 "-enable-early-data",
10828 "-expect-early-data-info",
10829 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10830 },
10831 })
10832
David Benjamin6bb507b2017-03-29 16:35:57 -050010833 // Test that the client offering Channel ID and 0-RTT allows the server
10834 // to decline 0-RTT.
10835 testCases = append(testCases, testCase{
10836 testType: clientTest,
10837 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10838 config: Config{
10839 MaxVersion: VersionTLS13,
10840 MaxEarlyDataSize: 16384,
10841 RequestChannelID: true,
10842 Bugs: ProtocolBugs{
10843 AlwaysRejectEarlyData: true,
10844 },
10845 },
10846 resumeSession: true,
10847 expectChannelID: true,
10848 flags: []string{
10849 "-enable-early-data",
10850 "-expect-early-data-info",
10851 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10852 "-expect-reject-early-data",
10853 },
10854 })
10855
10856 // Test that the client offering Channel ID and 0-RTT allows the server
10857 // to decline Channel ID.
10858 testCases = append(testCases, testCase{
10859 testType: clientTest,
10860 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10861 config: Config{
10862 MaxVersion: VersionTLS13,
10863 MaxEarlyDataSize: 16384,
10864 },
10865 resumeSession: true,
10866 flags: []string{
10867 "-enable-early-data",
10868 "-expect-early-data-info",
10869 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10870 "-expect-accept-early-data",
10871 },
10872 })
10873
10874 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
10875 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050010876 testCases = append(testCases, testCase{
10877 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010878 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050010879 config: Config{
10880 MaxVersion: VersionTLS13,
10881 ChannelID: channelIDKey,
10882 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050010883 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050010884 ExpectEarlyDataAccepted: false,
10885 },
10886 },
10887 resumeSession: true,
10888 expectChannelID: true,
10889 flags: []string{
10890 "-enable-early-data",
10891 "-expect-reject-early-data",
10892 "-expect-channel-id",
10893 base64.StdEncoding.EncodeToString(channelIDBytes),
10894 },
10895 })
10896
David Benjamin6bb507b2017-03-29 16:35:57 -050010897 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
10898 // if not offered Channel ID.
10899 testCases = append(testCases, testCase{
10900 testType: serverTest,
10901 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
10902 config: Config{
10903 MaxVersion: VersionTLS13,
10904 Bugs: ProtocolBugs{
10905 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10906 ExpectEarlyDataAccepted: true,
10907 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10908 },
10909 },
10910 resumeSession: true,
10911 expectChannelID: false,
10912 flags: []string{
10913 "-enable-early-data",
10914 "-expect-accept-early-data",
10915 "-enable-channel-id",
10916 },
10917 })
10918
David Benjamin32c89272017-03-26 13:54:21 -050010919 // Test that the server rejects 0-RTT streams without end_of_early_data.
10920 // The subsequent records should fail to decrypt.
10921 testCases = append(testCases, testCase{
10922 testType: serverTest,
10923 name: "TLS13-EarlyData-SkipEndOfEarlyData",
10924 config: Config{
10925 MaxVersion: VersionTLS13,
10926 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010927 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050010928 ExpectEarlyDataAccepted: true,
10929 SkipEndOfEarlyData: true,
10930 },
10931 },
10932 resumeSession: true,
10933 flags: []string{"-enable-early-data"},
10934 shouldFail: true,
10935 expectedLocalError: "remote error: bad record MAC",
10936 expectedError: ":BAD_DECRYPT:",
10937 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050010938
10939 testCases = append(testCases, testCase{
10940 testType: serverTest,
10941 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
10942 config: Config{
10943 MaxVersion: VersionTLS13,
10944 },
10945 resumeConfig: &Config{
10946 MaxVersion: VersionTLS13,
10947 Bugs: ProtocolBugs{
10948 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10949 SendStrayEarlyHandshake: true,
10950 ExpectEarlyDataAccepted: true},
10951 },
10952 resumeSession: true,
10953 shouldFail: true,
10954 expectedError: ":UNEXPECTED_RECORD:",
10955 expectedLocalError: "remote error: unexpected message",
10956 flags: []string{
10957 "-enable-early-data",
10958 },
10959 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010960}
10961
David Benjaminabbbee12016-10-31 19:20:42 -040010962func addTLS13CipherPreferenceTests() {
10963 // Test that client preference is honored if the shim has AES hardware
10964 // and ChaCha20-Poly1305 is preferred otherwise.
10965 testCases = append(testCases, testCase{
10966 testType: serverTest,
10967 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
10968 config: Config{
10969 MaxVersion: VersionTLS13,
10970 CipherSuites: []uint16{
10971 TLS_CHACHA20_POLY1305_SHA256,
10972 TLS_AES_128_GCM_SHA256,
10973 },
10974 },
10975 flags: []string{
10976 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10977 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10978 },
10979 })
10980
10981 testCases = append(testCases, testCase{
10982 testType: serverTest,
10983 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
10984 config: Config{
10985 MaxVersion: VersionTLS13,
10986 CipherSuites: []uint16{
10987 TLS_AES_128_GCM_SHA256,
10988 TLS_CHACHA20_POLY1305_SHA256,
10989 },
10990 },
10991 flags: []string{
10992 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10993 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10994 },
10995 })
10996
10997 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
10998 // whether it has AES hardware.
10999 testCases = append(testCases, testCase{
11000 name: "TLS13-CipherPreference-Client",
11001 config: Config{
11002 MaxVersion: VersionTLS13,
11003 // Use the client cipher order. (This is the default but
11004 // is listed to be explicit.)
11005 PreferServerCipherSuites: false,
11006 },
11007 flags: []string{
11008 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11009 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11010 },
11011 })
11012}
11013
David Benjaminf3fbade2016-09-19 13:08:16 -040011014func addPeekTests() {
11015 // Test SSL_peek works, including on empty records.
11016 testCases = append(testCases, testCase{
11017 name: "Peek-Basic",
11018 sendEmptyRecords: 1,
11019 flags: []string{"-peek-then-read"},
11020 })
11021
11022 // Test SSL_peek can drive the initial handshake.
11023 testCases = append(testCases, testCase{
11024 name: "Peek-ImplicitHandshake",
11025 flags: []string{
11026 "-peek-then-read",
11027 "-implicit-handshake",
11028 },
11029 })
11030
11031 // Test SSL_peek can discover and drive a renegotiation.
11032 testCases = append(testCases, testCase{
11033 name: "Peek-Renegotiate",
11034 config: Config{
11035 MaxVersion: VersionTLS12,
11036 },
11037 renegotiate: 1,
11038 flags: []string{
11039 "-peek-then-read",
11040 "-renegotiate-freely",
11041 "-expect-total-renegotiations", "1",
11042 },
11043 })
11044
11045 // Test SSL_peek can discover a close_notify.
11046 testCases = append(testCases, testCase{
11047 name: "Peek-Shutdown",
11048 config: Config{
11049 Bugs: ProtocolBugs{
11050 ExpectCloseNotify: true,
11051 },
11052 },
11053 flags: []string{
11054 "-peek-then-read",
11055 "-check-close-notify",
11056 },
11057 })
11058
11059 // Test SSL_peek can discover an alert.
11060 testCases = append(testCases, testCase{
11061 name: "Peek-Alert",
11062 config: Config{
11063 Bugs: ProtocolBugs{
11064 SendSpuriousAlert: alertRecordOverflow,
11065 },
11066 },
11067 flags: []string{"-peek-then-read"},
11068 shouldFail: true,
11069 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11070 })
11071
11072 // Test SSL_peek can handle KeyUpdate.
11073 testCases = append(testCases, testCase{
11074 name: "Peek-KeyUpdate",
11075 config: Config{
11076 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011077 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011078 sendKeyUpdates: 1,
11079 keyUpdateRequest: keyUpdateNotRequested,
11080 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011081 })
11082}
11083
David Benjamine6f22212016-11-08 14:28:24 -050011084func addRecordVersionTests() {
11085 for _, ver := range tlsVersions {
11086 // Test that the record version is enforced.
11087 testCases = append(testCases, testCase{
11088 name: "CheckRecordVersion-" + ver.name,
11089 config: Config{
11090 MinVersion: ver.version,
11091 MaxVersion: ver.version,
11092 Bugs: ProtocolBugs{
11093 SendRecordVersion: 0x03ff,
11094 },
11095 },
11096 shouldFail: true,
11097 expectedError: ":WRONG_VERSION_NUMBER:",
11098 })
11099
11100 // Test that the ClientHello may use any record version, for
11101 // compatibility reasons.
11102 testCases = append(testCases, testCase{
11103 testType: serverTest,
11104 name: "LooseInitialRecordVersion-" + ver.name,
11105 config: Config{
11106 MinVersion: ver.version,
11107 MaxVersion: ver.version,
11108 Bugs: ProtocolBugs{
11109 SendInitialRecordVersion: 0x03ff,
11110 },
11111 },
11112 })
11113
11114 // Test that garbage ClientHello record versions are rejected.
11115 testCases = append(testCases, testCase{
11116 testType: serverTest,
11117 name: "GarbageInitialRecordVersion-" + ver.name,
11118 config: Config{
11119 MinVersion: ver.version,
11120 MaxVersion: ver.version,
11121 Bugs: ProtocolBugs{
11122 SendInitialRecordVersion: 0xffff,
11123 },
11124 },
11125 shouldFail: true,
11126 expectedError: ":WRONG_VERSION_NUMBER:",
11127 })
11128 }
11129}
11130
David Benjamin2c516452016-11-15 10:16:54 +090011131func addCertificateTests() {
11132 // Test that a certificate chain with intermediate may be sent and
11133 // received as both client and server.
11134 for _, ver := range tlsVersions {
11135 testCases = append(testCases, testCase{
11136 testType: clientTest,
11137 name: "SendReceiveIntermediate-Client-" + ver.name,
11138 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011139 MinVersion: ver.version,
11140 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011141 Certificates: []Certificate{rsaChainCertificate},
11142 ClientAuth: RequireAnyClientCert,
11143 },
11144 expectPeerCertificate: &rsaChainCertificate,
11145 flags: []string{
11146 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11147 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11148 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11149 },
11150 })
11151
11152 testCases = append(testCases, testCase{
11153 testType: serverTest,
11154 name: "SendReceiveIntermediate-Server-" + ver.name,
11155 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011156 MinVersion: ver.version,
11157 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011158 Certificates: []Certificate{rsaChainCertificate},
11159 },
11160 expectPeerCertificate: &rsaChainCertificate,
11161 flags: []string{
11162 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11163 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11164 "-require-any-client-certificate",
11165 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11166 },
11167 })
11168 }
11169}
11170
David Benjaminbbaf3672016-11-17 10:53:09 +090011171func addRetainOnlySHA256ClientCertTests() {
11172 for _, ver := range tlsVersions {
11173 // Test that enabling
11174 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11175 // actually requesting a client certificate is a no-op.
11176 testCases = append(testCases, testCase{
11177 testType: serverTest,
11178 name: "RetainOnlySHA256-NoCert-" + ver.name,
11179 config: Config{
11180 MinVersion: ver.version,
11181 MaxVersion: ver.version,
11182 },
11183 flags: []string{
11184 "-retain-only-sha256-client-cert-initial",
11185 "-retain-only-sha256-client-cert-resume",
11186 },
11187 resumeSession: true,
11188 })
11189
11190 // Test that when retaining only a SHA-256 certificate is
11191 // enabled, the hash appears as expected.
11192 testCases = append(testCases, testCase{
11193 testType: serverTest,
11194 name: "RetainOnlySHA256-Cert-" + ver.name,
11195 config: Config{
11196 MinVersion: ver.version,
11197 MaxVersion: ver.version,
11198 Certificates: []Certificate{rsaCertificate},
11199 },
11200 flags: []string{
11201 "-verify-peer",
11202 "-retain-only-sha256-client-cert-initial",
11203 "-retain-only-sha256-client-cert-resume",
11204 "-expect-sha256-client-cert-initial",
11205 "-expect-sha256-client-cert-resume",
11206 },
11207 resumeSession: true,
11208 })
11209
11210 // Test that when the config changes from on to off, a
11211 // resumption is rejected because the server now wants the full
11212 // certificate chain.
11213 testCases = append(testCases, testCase{
11214 testType: serverTest,
11215 name: "RetainOnlySHA256-OnOff-" + ver.name,
11216 config: Config{
11217 MinVersion: ver.version,
11218 MaxVersion: ver.version,
11219 Certificates: []Certificate{rsaCertificate},
11220 },
11221 flags: []string{
11222 "-verify-peer",
11223 "-retain-only-sha256-client-cert-initial",
11224 "-expect-sha256-client-cert-initial",
11225 },
11226 resumeSession: true,
11227 expectResumeRejected: true,
11228 })
11229
11230 // Test that when the config changes from off to on, a
11231 // resumption is rejected because the server now wants just the
11232 // hash.
11233 testCases = append(testCases, testCase{
11234 testType: serverTest,
11235 name: "RetainOnlySHA256-OffOn-" + ver.name,
11236 config: Config{
11237 MinVersion: ver.version,
11238 MaxVersion: ver.version,
11239 Certificates: []Certificate{rsaCertificate},
11240 },
11241 flags: []string{
11242 "-verify-peer",
11243 "-retain-only-sha256-client-cert-resume",
11244 "-expect-sha256-client-cert-resume",
11245 },
11246 resumeSession: true,
11247 expectResumeRejected: true,
11248 })
11249 }
11250}
11251
Adam Langleya4b91982016-12-12 12:05:53 -080011252func addECDSAKeyUsageTests() {
11253 p256 := elliptic.P256()
11254 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11255 if err != nil {
11256 panic(err)
11257 }
11258
11259 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11260 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11261 if err != nil {
11262 panic(err)
11263 }
11264
11265 template := x509.Certificate{
11266 SerialNumber: serialNumber,
11267 Subject: pkix.Name{
11268 Organization: []string{"Acme Co"},
11269 },
11270 NotBefore: time.Now(),
11271 NotAfter: time.Now(),
11272
11273 // An ECC certificate with only the keyAgreement key usgae may
11274 // be used with ECDH, but not ECDSA.
11275 KeyUsage: x509.KeyUsageKeyAgreement,
11276 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11277 BasicConstraintsValid: true,
11278 }
11279
11280 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11281 if err != nil {
11282 panic(err)
11283 }
11284
11285 cert := Certificate{
11286 Certificate: [][]byte{derBytes},
11287 PrivateKey: priv,
11288 }
11289
11290 for _, ver := range tlsVersions {
11291 if ver.version < VersionTLS12 {
11292 continue
11293 }
11294
11295 testCases = append(testCases, testCase{
11296 testType: clientTest,
11297 name: "ECDSAKeyUsage-" + ver.name,
11298 config: Config{
11299 MinVersion: ver.version,
11300 MaxVersion: ver.version,
11301 Certificates: []Certificate{cert},
11302 },
11303 shouldFail: true,
11304 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11305 })
11306 }
11307}
11308
David Benjamin8c26d752017-03-26 15:13:51 -050011309func addExtraHandshakeTests() {
11310 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11311 // to ensure there is no transport I/O.
11312 testCases = append(testCases, testCase{
11313 testType: clientTest,
11314 name: "ExtraHandshake-Client-TLS12",
11315 config: Config{
11316 MinVersion: VersionTLS12,
11317 MaxVersion: VersionTLS12,
11318 },
11319 flags: []string{
11320 "-async",
11321 "-no-op-extra-handshake",
11322 },
11323 })
11324 testCases = append(testCases, testCase{
11325 testType: serverTest,
11326 name: "ExtraHandshake-Server-TLS12",
11327 config: Config{
11328 MinVersion: VersionTLS12,
11329 MaxVersion: VersionTLS12,
11330 },
11331 flags: []string{
11332 "-async",
11333 "-no-op-extra-handshake",
11334 },
11335 })
11336 testCases = append(testCases, testCase{
11337 testType: clientTest,
11338 name: "ExtraHandshake-Client-TLS13",
11339 config: Config{
11340 MinVersion: VersionTLS13,
11341 MaxVersion: VersionTLS13,
11342 },
11343 flags: []string{
11344 "-async",
11345 "-no-op-extra-handshake",
11346 },
11347 })
11348 testCases = append(testCases, testCase{
11349 testType: serverTest,
11350 name: "ExtraHandshake-Server-TLS13",
11351 config: Config{
11352 MinVersion: VersionTLS13,
11353 MaxVersion: VersionTLS13,
11354 },
11355 flags: []string{
11356 "-async",
11357 "-no-op-extra-handshake",
11358 },
11359 })
11360
11361 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11362 testCases = append(testCases, testCase{
11363 testType: serverTest,
11364 name: "ExtraHandshake-Server-EarlyData-TLS13",
11365 config: Config{
11366 MaxVersion: VersionTLS13,
11367 MinVersion: VersionTLS13,
11368 Bugs: ProtocolBugs{
11369 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11370 ExpectEarlyDataAccepted: true,
11371 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11372 },
11373 },
11374 messageCount: 2,
11375 resumeSession: true,
11376 flags: []string{
11377 "-async",
11378 "-enable-early-data",
11379 "-expect-accept-early-data",
11380 "-no-op-extra-handshake",
11381 },
11382 })
11383
11384 // An extra SSL_do_handshake drives the handshake to completion in False
11385 // Start. We test this by handshaking twice and asserting the False
11386 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11387 // how the test works.
11388 testCases = append(testCases, testCase{
11389 testType: clientTest,
11390 name: "ExtraHandshake-FalseStart",
11391 config: Config{
11392 MaxVersion: VersionTLS12,
11393 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11394 NextProtos: []string{"foo"},
11395 Bugs: ProtocolBugs{
11396 ExpectFalseStart: true,
11397 AlertBeforeFalseStartTest: alertAccessDenied,
11398 },
11399 },
11400 flags: []string{
11401 "-handshake-twice",
11402 "-false-start",
11403 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011404 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011405 },
11406 shimWritesFirst: true,
11407 shouldFail: true,
11408 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11409 expectedLocalError: "tls: peer did not false start: EOF",
11410 })
11411}
11412
Adam Langley7c803a62015-06-15 15:35:05 -070011413func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011414 defer wg.Done()
11415
11416 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011417 var err error
11418
David Benjaminba28dfc2016-11-15 17:47:21 +090011419 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011420 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11421 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011422 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011423 if err != nil {
11424 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11425 }
11426 break
11427 }
11428 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011429 } else if *repeatUntilFailure {
11430 for err == nil {
11431 statusChan <- statusMsg{test: test, started: true}
11432 err = runTest(test, shimPath, -1)
11433 }
11434 } else {
11435 statusChan <- statusMsg{test: test, started: true}
11436 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011437 }
Adam Langley95c29f32014-06-20 12:00:00 -070011438 statusChan <- statusMsg{test: test, err: err}
11439 }
11440}
11441
11442type statusMsg struct {
11443 test *testCase
11444 started bool
11445 err error
11446}
11447
David Benjamin5f237bc2015-02-11 17:14:15 -050011448func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011449 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011450
David Benjamin5f237bc2015-02-11 17:14:15 -050011451 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011452 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011453 if !*pipe {
11454 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011455 var erase string
11456 for i := 0; i < lineLen; i++ {
11457 erase += "\b \b"
11458 }
11459 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011460 }
11461
Adam Langley95c29f32014-06-20 12:00:00 -070011462 if msg.started {
11463 started++
11464 } else {
11465 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011466
11467 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011468 if msg.err == errUnimplemented {
11469 if *pipe {
11470 // Print each test instead of a status line.
11471 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11472 }
11473 unimplemented++
11474 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11475 } else {
11476 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11477 failed++
11478 testOutput.addResult(msg.test.name, "FAIL")
11479 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011480 } else {
11481 if *pipe {
11482 // Print each test instead of a status line.
11483 fmt.Printf("PASSED (%s)\n", msg.test.name)
11484 }
11485 testOutput.addResult(msg.test.name, "PASS")
11486 }
Adam Langley95c29f32014-06-20 12:00:00 -070011487 }
11488
David Benjamin5f237bc2015-02-11 17:14:15 -050011489 if !*pipe {
11490 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011491 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011492 lineLen = len(line)
11493 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011494 }
Adam Langley95c29f32014-06-20 12:00:00 -070011495 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011496
11497 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011498}
11499
11500func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011501 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011502 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011503 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011504
Adam Langley7c803a62015-06-15 15:35:05 -070011505 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011506 addCipherSuiteTests()
11507 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011508 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011509 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011510 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011511 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011512 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011513 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011514 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011515 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011516 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011517 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011518 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011519 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011520 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011521 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011522 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011523 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011524 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011525 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011526 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011527 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011528 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011529 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011530 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011531 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011532 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011533 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011534 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011535 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011536 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011537 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011538 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011539 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011540
11541 var wg sync.WaitGroup
11542
Adam Langley7c803a62015-06-15 15:35:05 -070011543 statusChan := make(chan statusMsg, *numWorkers)
11544 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011545 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011546
EKRf71d7ed2016-08-06 13:25:12 -070011547 if len(*shimConfigFile) != 0 {
11548 encoded, err := ioutil.ReadFile(*shimConfigFile)
11549 if err != nil {
11550 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11551 os.Exit(1)
11552 }
11553
11554 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11555 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11556 os.Exit(1)
11557 }
11558 }
11559
David Benjamin025b3d32014-07-01 19:53:04 -040011560 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011561
Adam Langley7c803a62015-06-15 15:35:05 -070011562 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011563 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011564 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011565 }
11566
David Benjamin270f0a72016-03-17 14:41:36 -040011567 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011568 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011569 matched := true
11570 if len(*testToRun) != 0 {
11571 var err error
11572 matched, err = filepath.Match(*testToRun, testCases[i].name)
11573 if err != nil {
11574 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11575 os.Exit(1)
11576 }
11577 }
11578
EKRf71d7ed2016-08-06 13:25:12 -070011579 if !*includeDisabled {
11580 for pattern := range shimConfig.DisabledTests {
11581 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11582 if err != nil {
11583 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11584 os.Exit(1)
11585 }
11586
11587 if isDisabled {
11588 matched = false
11589 break
11590 }
11591 }
11592 }
11593
David Benjamin17e12922016-07-28 18:04:43 -040011594 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011595 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011596 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011597
11598 // Only run one test if repeating until failure.
11599 if *repeatUntilFailure {
11600 break
11601 }
Adam Langley95c29f32014-06-20 12:00:00 -070011602 }
11603 }
David Benjamin17e12922016-07-28 18:04:43 -040011604
David Benjamin270f0a72016-03-17 14:41:36 -040011605 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011606 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011607 os.Exit(1)
11608 }
Adam Langley95c29f32014-06-20 12:00:00 -070011609
11610 close(testChan)
11611 wg.Wait()
11612 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011613 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011614
11615 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011616
11617 if *jsonOutput != "" {
11618 if err := testOutput.writeTo(*jsonOutput); err != nil {
11619 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11620 }
11621 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011622
EKR842ae6c2016-07-27 09:22:05 +020011623 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11624 os.Exit(1)
11625 }
11626
11627 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011628 os.Exit(1)
11629 }
Adam Langley95c29f32014-06-20 12:00:00 -070011630}