blob: 1ee602f2f77187755d30271ab48d955a73200ccd [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdezc94998a2017-06-20 10:55:02 -0400266// configVersionToWire maps a protocol version to the default wire version to
267// test at that protocol.
268//
269// TODO(davidben): Rather than mapping these, make tlsVersions contains a list
270// of wire versions and test all of them.
271func configVersionToWire(vers uint16, protocol protocol) uint16 {
272 if protocol == dtls {
273 switch vers {
274 case VersionTLS12:
275 return VersionDTLS12
276 case VersionTLS10:
277 return VersionDTLS10
278 }
279 } else {
280 switch vers {
281 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
282 return vers
283 case VersionTLS13:
284 return tls13DraftVersion
285 }
286 }
287
288 panic("unknown version")
289}
290
Adam Langley2ff79332017-02-28 13:45:39 -0800291// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
292func encodeDERValues(values [][]byte) string {
293 var ret string
294 for i, v := range values {
295 if i > 0 {
296 ret += ","
297 }
298 ret += hex.EncodeToString(v)
299 }
300
301 return ret
302}
303
David Benjamin025b3d32014-07-01 19:53:04 -0400304type testType int
305
306const (
307 clientTest testType = iota
308 serverTest
309)
310
David Benjamin6fd297b2014-08-11 18:43:38 -0400311type protocol int
312
313const (
314 tls protocol = iota
315 dtls
316)
317
David Benjaminfc7b0862014-09-06 13:21:53 -0400318const (
319 alpn = 1
320 npn = 2
321)
322
Adam Langley95c29f32014-06-20 12:00:00 -0700323type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400324 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400325 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700326 name string
327 config Config
328 shouldFail bool
329 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700330 // expectedLocalError, if not empty, contains a substring that must be
331 // found in the local error.
332 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400333 // expectedVersion, if non-zero, specifies the TLS version that must be
334 // negotiated.
335 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400336 // expectedResumeVersion, if non-zero, specifies the TLS version that
337 // must be negotiated on resumption. If zero, expectedVersion is used.
338 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400339 // expectedCipher, if non-zero, specifies the TLS cipher suite that
340 // should be negotiated.
341 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400342 // expectChannelID controls whether the connection should have
343 // negotiated a Channel ID with channelIDKey.
344 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400345 // expectedNextProto controls whether the connection should
346 // negotiate a next protocol via NPN or ALPN.
347 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 // expectNoNextProto, if true, means that no next protocol should be
349 // negotiated.
350 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400351 // expectedNextProtoType, if non-zero, is the expected next
352 // protocol negotiation mechanism.
353 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500354 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
355 // should be negotiated. If zero, none should be negotiated.
356 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100357 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
358 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100359 // expectedSCTList, if not nil, is the expected SCT list to be received.
360 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700361 // expectedPeerSignatureAlgorithm, if not zero, is the signature
362 // algorithm that the peer should have used in the handshake.
363 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400364 // expectedCurveID, if not zero, is the curve that the handshake should
365 // have used.
366 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700367 // messageLen is the length, in bytes, of the test message that will be
368 // sent.
369 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400370 // messageCount is the number of test messages that will be sent.
371 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400372 // certFile is the path to the certificate to use for the server.
373 certFile string
374 // keyFile is the path to the private key to use for the server.
375 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400376 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400377 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400378 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400379 // resumeRenewedSession controls whether a third connection should be
380 // tested which attempts to resume the second connection's session.
381 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700382 // expectResumeRejected, if true, specifies that the attempted
383 // resumption must be rejected by the client. This is only valid for a
384 // serverTest.
385 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400386 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // resumption. Unless newSessionsOnResume is set,
388 // SessionTicketKey, ServerSessionCache, and
389 // ClientSessionCache are copied from the initial connection's
390 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400391 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500392 // newSessionsOnResume, if true, will cause resumeConfig to
393 // use a different session resumption context.
394 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400395 // noSessionCache, if true, will cause the server to run without a
396 // session cache.
397 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400398 // sendPrefix sends a prefix on the socket before actually performing a
399 // handshake.
400 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400401 // shimWritesFirst controls whether the shim sends an initial "hello"
402 // message before doing a roundtrip with the runner.
403 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400404 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
405 // does not complete the write until responding to the first runner
406 // message.
407 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400408 // shimShutsDown, if true, runs a test where the shim shuts down the
409 // connection immediately after the handshake rather than echoing
410 // messages from the runner.
411 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400412 // renegotiate indicates the number of times the connection should be
413 // renegotiated during the exchange.
414 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400415 // sendHalfHelloRequest, if true, causes the server to send half a
416 // HelloRequest when the handshake completes.
417 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700418 // renegotiateCiphers is a list of ciphersuite ids that will be
419 // switched in just before renegotiation.
420 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500421 // replayWrites, if true, configures the underlying transport
422 // to replay every write it makes in DTLS tests.
423 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 // damageFirstWrite, if true, configures the underlying transport to
425 // damage the final byte of the first application data write.
426 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400427 // exportKeyingMaterial, if non-zero, configures the test to exchange
428 // keying material and verify they match.
429 exportKeyingMaterial int
430 exportLabel string
431 exportContext string
432 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400433 // flags, if not empty, contains a list of command-line flags that will
434 // be passed to the shim program.
435 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700436 // testTLSUnique, if true, causes the shim to send the tls-unique value
437 // which will be compared against the expected value.
438 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400439 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400440 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400441 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400442 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400443 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400444 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400445 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
446 // be sent before each test message.
447 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400448 // sendKeyUpdates is the number of consecutive key updates to send
449 // before and after the test message.
450 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400451 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
452 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400453 // expectMessageDropped, if true, means the test message is expected to
454 // be dropped by the client rather than echoed back.
455 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900456 // expectPeerCertificate, if not nil, is the certificate chain the peer
457 // is expected to send.
458 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500459 // shimPrefix is the prefix that the shim will send to the server.
460 shimPrefix string
461 // resumeShimPrefix is the prefix that the shim will send to the server on a
462 // resumption.
463 resumeShimPrefix string
Adam Langley95c29f32014-06-20 12:00:00 -0700464}
465
Adam Langley7c803a62015-06-15 15:35:05 -0700466var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700467
David Benjamin0fde2eb2017-06-30 19:11:22 -0400468func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if len(data) == 0 {
470 return
471 }
472
David Benjamin0fde2eb2017-06-30 19:11:22 -0400473 settings, err := ioutil.ReadFile(path)
474 if err != nil {
475 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500476 return
477 }
478
David Benjamin0fde2eb2017-06-30 19:11:22 -0400479 settings = append(settings, data...)
480 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
481 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500482 }
483}
484
David Benjamin3ed59772016-03-08 12:50:21 -0500485// A timeoutConn implements an idle timeout on each Read and Write operation.
486type timeoutConn struct {
487 net.Conn
488 timeout time.Duration
489}
490
491func (t *timeoutConn) Read(b []byte) (int, error) {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
495 return t.Conn.Read(b)
496}
497
498func (t *timeoutConn) Write(b []byte) (int, error) {
499 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
500 return 0, err
501 }
502 return t.Conn.Write(b)
503}
504
David Benjamin0fde2eb2017-06-30 19:11:22 -0400505func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400506 if !test.noSessionCache {
507 if config.ClientSessionCache == nil {
508 config.ClientSessionCache = NewLRUClientSessionCache(1)
509 }
510 if config.ServerSessionCache == nil {
511 config.ServerSessionCache = NewLRUServerSessionCache(1)
512 }
513 }
514 if test.testType == clientTest {
515 if len(config.Certificates) == 0 {
516 config.Certificates = []Certificate{rsaCertificate}
517 }
518 } else {
519 // Supply a ServerName to ensure a constant session cache key,
520 // rather than falling back to net.Conn.RemoteAddr.
521 if len(config.ServerName) == 0 {
522 config.ServerName = "test"
523 }
524 }
525 if *fuzzer {
526 config.Bugs.NullAllCiphers = true
527 }
David Benjamin01a90572016-09-22 00:11:43 -0400528 if *deterministic {
529 config.Time = func() time.Time { return time.Unix(1234, 1234) }
530 }
David Benjamine54af062016-08-08 19:21:18 -0400531
David Benjamin01784b42016-06-07 18:00:52 -0400532 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500533
David Benjamin6fd297b2014-08-11 18:43:38 -0400534 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500535 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
536 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500537 }
538
David Benjamin9867b7d2016-03-01 23:25:48 -0500539 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500540 local, peer := "client", "server"
541 if test.testType == clientTest {
542 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500543 }
David Benjaminebda9b32015-11-02 15:33:18 -0500544 connDebug := &recordingConn{
545 Conn: conn,
546 isDatagram: test.protocol == dtls,
547 local: local,
548 peer: peer,
549 }
550 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500551 if *flagDebug {
552 defer connDebug.WriteTo(os.Stdout)
553 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400554 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500555 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 path := transcriptPrefix + strconv.Itoa(num)
557 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500558 }()
559 }
David Benjaminebda9b32015-11-02 15:33:18 -0500560
561 if config.Bugs.PacketAdaptor != nil {
562 config.Bugs.PacketAdaptor.debug = connDebug
563 }
564 }
565
566 if test.replayWrites {
567 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400568 }
569
David Benjamin3ed59772016-03-08 12:50:21 -0500570 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500571 if test.damageFirstWrite {
572 connDamage = newDamageAdaptor(conn)
573 conn = connDamage
574 }
575
David Benjamin6fd297b2014-08-11 18:43:38 -0400576 if test.sendPrefix != "" {
577 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
578 return err
579 }
David Benjamin98e882e2014-08-08 13:24:34 -0400580 }
581
David Benjamin1d5c83e2014-07-22 19:20:02 -0400582 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400583 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400584 if test.protocol == dtls {
585 tlsConn = DTLSServer(conn, config)
586 } else {
587 tlsConn = Server(conn, config)
588 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400589 } else {
590 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400591 if test.protocol == dtls {
592 tlsConn = DTLSClient(conn, config)
593 } else {
594 tlsConn = Client(conn, config)
595 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400596 }
David Benjamin30789da2015-08-29 22:56:45 -0400597 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598
Adam Langley95c29f32014-06-20 12:00:00 -0700599 if err := tlsConn.Handshake(); err != nil {
600 return err
601 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700602
David Benjamin01fe8202014-09-24 15:21:44 -0400603 // TODO(davidben): move all per-connection expectations into a dedicated
604 // expectations struct that can be specified separately for the two
605 // legs.
606 expectedVersion := test.expectedVersion
607 if isResume && test.expectedResumeVersion != 0 {
608 expectedVersion = test.expectedResumeVersion
609 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 connState := tlsConn.ConnectionState()
611 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400612 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400613 }
614
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700615 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400616 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
617 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700618 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
619 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
620 }
David Benjamin90da8c82015-04-20 14:57:57 -0400621
David Benjamina08e49d2014-08-24 01:46:07 -0400622 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700623 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if channelID == nil {
625 return fmt.Errorf("no channel ID negotiated")
626 }
627 if channelID.Curve != channelIDKey.Curve ||
628 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
629 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
630 return fmt.Errorf("incorrect channel ID")
631 }
David Benjamin634f4752017-07-01 11:08:41 -0400632 } else if connState.ChannelID != nil {
633 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400634 }
635
David Benjaminae2888f2014-09-06 12:58:58 -0400636 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700637 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400638 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
639 }
640 }
641
David Benjaminc7ce9772015-10-09 19:32:41 -0400642 if test.expectNoNextProto {
643 if actual := connState.NegotiatedProtocol; actual != "" {
644 return fmt.Errorf("got unexpected next proto %s", actual)
645 }
646 }
647
David Benjaminfc7b0862014-09-06 13:21:53 -0400648 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700649 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400650 return fmt.Errorf("next proto type mismatch")
651 }
652 }
653
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700654 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500655 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
656 }
657
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100658 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300659 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100660 }
661
Paul Lietar4fac72e2015-09-09 13:44:55 +0100662 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
663 return fmt.Errorf("SCT list mismatch")
664 }
665
Nick Harper60edffd2016-06-21 15:19:24 -0700666 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
667 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400668 }
669
Steven Valdez5440fe02016-07-18 12:40:30 -0400670 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
671 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
672 }
673
David Benjamin2c516452016-11-15 10:16:54 +0900674 if test.expectPeerCertificate != nil {
675 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
676 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
677 }
678 for i, cert := range connState.PeerCertificates {
679 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
680 return fmt.Errorf("peer certificate %d did not match", i+1)
681 }
682 }
683 }
684
David Benjaminc565ebb2015-04-03 04:06:36 -0400685 if test.exportKeyingMaterial > 0 {
686 actual := make([]byte, test.exportKeyingMaterial)
687 if _, err := io.ReadFull(tlsConn, actual); err != nil {
688 return err
689 }
690 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
691 if err != nil {
692 return err
693 }
694 if !bytes.Equal(actual, expected) {
695 return fmt.Errorf("keying material mismatch")
696 }
697 }
698
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700699 if test.testTLSUnique {
700 var peersValue [12]byte
701 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
702 return err
703 }
704 expected := tlsConn.ConnectionState().TLSUnique
705 if !bytes.Equal(peersValue[:], expected) {
706 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
707 }
708 }
709
David Benjamin47921102016-07-28 11:29:18 -0400710 if test.sendHalfHelloRequest {
711 tlsConn.SendHalfHelloRequest()
712 }
713
Steven Valdeze831a812017-03-09 14:56:07 -0500714 shimPrefix := test.shimPrefix
715 if isResume {
716 shimPrefix = test.resumeShimPrefix
717 }
718 if test.shimWritesFirst || test.readWithUnfinishedWrite {
719 shimPrefix = "hello"
720 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400721 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400722 // If readWithUnfinishedWrite is set, the shim prefix will be
723 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500724 if shimPrefix != "" && !test.readWithUnfinishedWrite {
725 var buf = make([]byte, len(shimPrefix))
726 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400727 if err != nil {
728 return err
729 }
Steven Valdeze831a812017-03-09 14:56:07 -0500730 if string(buf) != shimPrefix {
731 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400732 }
Steven Valdeze831a812017-03-09 14:56:07 -0500733 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400734 }
735
Adam Langleycf2d4f42014-10-28 19:06:14 -0700736 if test.renegotiateCiphers != nil {
737 config.CipherSuites = test.renegotiateCiphers
738 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400739 for i := 0; i < test.renegotiate; i++ {
740 if err := tlsConn.Renegotiate(); err != nil {
741 return err
742 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700743 }
744 } else if test.renegotiateCiphers != nil {
745 panic("renegotiateCiphers without renegotiate")
746 }
747
David Benjamin5fa3eba2015-01-22 16:35:40 -0500748 if test.damageFirstWrite {
749 connDamage.setDamage(true)
750 tlsConn.Write([]byte("DAMAGED WRITE"))
751 connDamage.setDamage(false)
752 }
753
David Benjamin8e6db492015-07-25 18:29:23 -0400754 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700755 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400756 if test.protocol == dtls {
757 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
758 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700759 // Read until EOF.
760 _, err := io.Copy(ioutil.Discard, tlsConn)
761 return err
762 }
David Benjamin4417d052015-04-05 04:17:25 -0400763 if messageLen == 0 {
764 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700765 }
Adam Langley95c29f32014-06-20 12:00:00 -0700766
David Benjamin8e6db492015-07-25 18:29:23 -0400767 messageCount := test.messageCount
768 if messageCount == 0 {
769 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400770 }
771
David Benjamin8e6db492015-07-25 18:29:23 -0400772 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400773 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400774 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400775 }
776
David Benjamin8e6db492015-07-25 18:29:23 -0400777 for i := 0; i < test.sendEmptyRecords; i++ {
778 tlsConn.Write(nil)
779 }
780
781 for i := 0; i < test.sendWarningAlerts; i++ {
782 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
783 }
784
David Benjamin24e58862017-06-14 18:45:29 -0400785 if test.sendBogusAlertType {
786 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
787 }
788
David Benjaminbbba9392017-04-06 12:54:12 -0400789 testMessage := make([]byte, messageLen)
790 for i := range testMessage {
791 testMessage[i] = 0x42 ^ byte(j)
792 }
793 tlsConn.Write(testMessage)
794
795 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500796 if shimPrefix != "" {
797 var buf = make([]byte, len(shimPrefix))
798 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400799 if err != nil {
800 return err
801 }
Steven Valdeze831a812017-03-09 14:56:07 -0500802 if string(buf) != shimPrefix {
803 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400804 }
Steven Valdeze831a812017-03-09 14:56:07 -0500805 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400806 }
807
David Benjamin4f75aaf2015-09-01 16:53:10 -0400808 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400809 // The shim will not respond.
810 continue
811 }
812
David Benjaminbbba9392017-04-06 12:54:12 -0400813 // Process the KeyUpdate ACK. However many KeyUpdates the runner
814 // sends, the shim should respond only once.
815 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
816 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
817 return err
818 }
819 }
820
David Benjamin8e6db492015-07-25 18:29:23 -0400821 buf := make([]byte, len(testMessage))
822 if test.protocol == dtls {
823 bufTmp := make([]byte, len(buf)+1)
824 n, err := tlsConn.Read(bufTmp)
825 if err != nil {
826 return err
827 }
828 if n != len(buf) {
829 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
830 }
831 copy(buf, bufTmp)
832 } else {
833 _, err := io.ReadFull(tlsConn, buf)
834 if err != nil {
835 return err
836 }
837 }
838
839 for i, v := range buf {
840 if v != testMessage[i]^0xff {
841 return fmt.Errorf("bad reply contents at byte %d", i)
842 }
Adam Langley95c29f32014-06-20 12:00:00 -0700843 }
844 }
845
846 return nil
847}
848
David Benjamin325b5c32014-07-01 19:40:31 -0400849func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400850 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700851 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400852 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700853 }
David Benjamin325b5c32014-07-01 19:40:31 -0400854 valgrindArgs = append(valgrindArgs, path)
855 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700856
David Benjamin325b5c32014-07-01 19:40:31 -0400857 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700858}
859
David Benjamin325b5c32014-07-01 19:40:31 -0400860func gdbOf(path string, args ...string) *exec.Cmd {
861 xtermArgs := []string{"-e", "gdb", "--args"}
862 xtermArgs = append(xtermArgs, path)
863 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864
David Benjamin325b5c32014-07-01 19:40:31 -0400865 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700866}
867
David Benjamind16bf342015-12-18 00:53:12 -0500868func lldbOf(path string, args ...string) *exec.Cmd {
869 xtermArgs := []string{"-e", "lldb", "--"}
870 xtermArgs = append(xtermArgs, path)
871 xtermArgs = append(xtermArgs, args...)
872
873 return exec.Command("xterm", xtermArgs...)
874}
875
EKR842ae6c2016-07-27 09:22:05 +0200876var (
877 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
878 errUnimplemented = errors.New("child process does not implement needed flags")
879)
Adam Langley69a01602014-11-17 17:26:55 -0800880
David Benjamin87c8a642015-02-21 01:54:29 -0500881// accept accepts a connection from listener, unless waitChan signals a process
882// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400883func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500884 type connOrError struct {
885 conn net.Conn
886 err error
887 }
888 connChan := make(chan connOrError, 1)
889 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400890 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500891 conn, err := listener.Accept()
892 connChan <- connOrError{conn, err}
893 close(connChan)
894 }()
895 select {
896 case result := <-connChan:
897 return result.conn, result.err
898 case childErr := <-waitChan:
899 waitChan <- childErr
900 return nil, fmt.Errorf("child exited early: %s", childErr)
901 }
902}
903
EKRf71d7ed2016-08-06 13:25:12 -0700904func translateExpectedError(errorStr string) string {
905 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
906 return translated
907 }
908
909 if *looseErrors {
910 return ""
911 }
912
913 return errorStr
914}
915
Adam Langley7c803a62015-06-15 15:35:05 -0700916func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400917 // Help debugging panics on the Go side.
918 defer func() {
919 if r := recover(); r != nil {
920 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
921 panic(r)
922 }
923 }()
924
Adam Langley38311732014-10-16 19:04:35 -0700925 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
926 panic("Error expected without shouldFail in " + test.name)
927 }
928
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700929 if test.expectResumeRejected && !test.resumeSession {
930 panic("expectResumeRejected without resumeSession in " + test.name)
931 }
932
Adam Langley33b1d4f2016-12-07 15:03:45 -0800933 for _, ver := range tlsVersions {
934 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
935 continue
936 }
937
938 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
939 continue
940 }
941
942 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
943 }
944
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700945 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
946 if err != nil {
947 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
948 }
David Benjamin87c8a642015-02-21 01:54:29 -0500949 if err != nil {
950 panic(err)
951 }
952 defer func() {
953 if listener != nil {
954 listener.Close()
955 }
956 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700957
David Benjamin87c8a642015-02-21 01:54:29 -0500958 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400959 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400960 flags = append(flags, "-server")
961
David Benjamin025b3d32014-07-01 19:53:04 -0400962 flags = append(flags, "-key-file")
963 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700964 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400965 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700966 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400967 }
968
969 flags = append(flags, "-cert-file")
970 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700971 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400972 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700973 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400974 }
975 }
David Benjamin5a593af2014-08-11 19:51:50 -0400976
David Benjamin6fd297b2014-08-11 18:43:38 -0400977 if test.protocol == dtls {
978 flags = append(flags, "-dtls")
979 }
980
David Benjamin46662482016-08-17 00:51:00 -0400981 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400982 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400983 resumeCount++
984 if test.resumeRenewedSession {
985 resumeCount++
986 }
987 }
988
989 if resumeCount > 0 {
990 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400991 }
992
David Benjamine58c4f52014-08-24 03:47:07 -0400993 if test.shimWritesFirst {
994 flags = append(flags, "-shim-writes-first")
995 }
996
David Benjaminbbba9392017-04-06 12:54:12 -0400997 if test.readWithUnfinishedWrite {
998 flags = append(flags, "-read-with-unfinished-write")
999 }
1000
David Benjamin30789da2015-08-29 22:56:45 -04001001 if test.shimShutsDown {
1002 flags = append(flags, "-shim-shuts-down")
1003 }
1004
David Benjaminc565ebb2015-04-03 04:06:36 -04001005 if test.exportKeyingMaterial > 0 {
1006 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1007 flags = append(flags, "-export-label", test.exportLabel)
1008 flags = append(flags, "-export-context", test.exportContext)
1009 if test.useExportContext {
1010 flags = append(flags, "-use-export-context")
1011 }
1012 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001013 if test.expectResumeRejected {
1014 flags = append(flags, "-expect-session-miss")
1015 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001016
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001017 if test.testTLSUnique {
1018 flags = append(flags, "-tls-unique")
1019 }
1020
David Benjamin0fde2eb2017-06-30 19:11:22 -04001021 var transcriptPrefix string
1022 if len(*transcriptDir) != 0 {
1023 protocol := "tls"
1024 if test.protocol == dtls {
1025 protocol = "dtls"
1026 }
1027
1028 side := "client"
1029 if test.testType == serverTest {
1030 side = "server"
1031 }
1032
1033 dir := filepath.Join(*transcriptDir, protocol, side)
1034 if err := os.MkdirAll(dir, 0755); err != nil {
1035 return err
1036 }
1037 transcriptPrefix = filepath.Join(dir, test.name+"-")
1038 flags = append(flags, "-write-settings", transcriptPrefix)
1039 }
1040
David Benjamin025b3d32014-07-01 19:53:04 -04001041 flags = append(flags, test.flags...)
1042
1043 var shim *exec.Cmd
1044 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001045 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001046 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001047 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001048 } else if *useLLDB {
1049 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001050 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001051 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001052 }
David Benjamin025b3d32014-07-01 19:53:04 -04001053 shim.Stdin = os.Stdin
1054 var stdoutBuf, stderrBuf bytes.Buffer
1055 shim.Stdout = &stdoutBuf
1056 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001057 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001058 shim.Env = os.Environ()
1059 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001060 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001061 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001062 }
1063 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1064 }
David Benjamin025b3d32014-07-01 19:53:04 -04001065
1066 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001067 panic(err)
1068 }
David Benjamin87c8a642015-02-21 01:54:29 -05001069 waitChan := make(chan error, 1)
1070 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001071
1072 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001073
David Benjamin7a4aaa42016-09-20 17:58:14 -04001074 if *deterministic {
1075 config.Rand = &deterministicRand{}
1076 }
1077
David Benjamin87c8a642015-02-21 01:54:29 -05001078 conn, err := acceptOrWait(listener, waitChan)
1079 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001080 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001081 conn.Close()
1082 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001083
David Benjamin46662482016-08-17 00:51:00 -04001084 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001085 var resumeConfig Config
1086 if test.resumeConfig != nil {
1087 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001088 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001089 resumeConfig.SessionTicketKey = config.SessionTicketKey
1090 resumeConfig.ClientSessionCache = config.ClientSessionCache
1091 resumeConfig.ServerSessionCache = config.ServerSessionCache
1092 }
David Benjamin2e045a92016-06-08 13:09:56 -04001093 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001094 } else {
1095 resumeConfig = config
1096 }
David Benjamin87c8a642015-02-21 01:54:29 -05001097 var connResume net.Conn
1098 connResume, err = acceptOrWait(listener, waitChan)
1099 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001100 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001101 connResume.Close()
1102 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001103 }
1104
David Benjamin87c8a642015-02-21 01:54:29 -05001105 // Close the listener now. This is to avoid hangs should the shim try to
1106 // open more connections than expected.
1107 listener.Close()
1108 listener = nil
1109
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001110 var shimKilledLock sync.Mutex
1111 var shimKilled bool
1112 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1113 shimKilledLock.Lock()
1114 shimKilled = true
1115 shimKilledLock.Unlock()
1116 shim.Process.Kill()
1117 })
David Benjamin87c8a642015-02-21 01:54:29 -05001118 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001119 waitTimeout.Stop()
1120 shimKilledLock.Lock()
1121 if shimKilled && err == nil {
1122 err = errors.New("timeout waiting for the shim to exit.")
1123 }
1124 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001125 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001126 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001127 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1128 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001129 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001130 case 89:
1131 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001132 case 99:
1133 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001134 }
1135 }
Adam Langley95c29f32014-06-20 12:00:00 -07001136
David Benjamin9bea3492016-03-02 10:59:16 -05001137 // Account for Windows line endings.
1138 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1139 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001140
1141 // Separate the errors from the shim and those from tools like
1142 // AddressSanitizer.
1143 var extraStderr string
1144 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1145 stderr = stderrParts[0]
1146 extraStderr = stderrParts[1]
1147 }
1148
Adam Langley95c29f32014-06-20 12:00:00 -07001149 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001150 expectedError := translateExpectedError(test.expectedError)
1151 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001152
Adam Langleyac61fa32014-06-23 12:03:11 -07001153 localError := "none"
1154 if err != nil {
1155 localError = err.Error()
1156 }
1157 if len(test.expectedLocalError) != 0 {
1158 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1159 }
Adam Langley95c29f32014-06-20 12:00:00 -07001160
1161 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001162 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001163 if childErr != nil {
1164 childError = childErr.Error()
1165 }
1166
1167 var msg string
1168 switch {
1169 case failed && !test.shouldFail:
1170 msg = "unexpected failure"
1171 case !failed && test.shouldFail:
1172 msg = "unexpected success"
1173 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001174 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001175 default:
1176 panic("internal error")
1177 }
1178
David Benjamin9aafb642016-09-20 19:36:53 -04001179 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001180 }
1181
David Benjamind2ba8892016-09-20 19:41:04 -04001182 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001183 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001184 }
1185
David Benjamind2ba8892016-09-20 19:41:04 -04001186 if *useValgrind && isValgrindError {
1187 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1188 }
1189
Adam Langley95c29f32014-06-20 12:00:00 -07001190 return nil
1191}
1192
David Benjaminaa012042016-12-10 13:33:05 -05001193type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001194 name string
1195 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001196 // excludeFlag is the legacy shim flag to disable the version.
1197 excludeFlag string
1198 hasDTLS bool
1199 // shimTLS and shimDTLS are values the shim uses to refer to these
1200 // versions in TLS and DTLS, respectively.
1201 shimTLS, shimDTLS int
1202}
1203
1204func (vers tlsVersion) shimFlag(protocol protocol) string {
1205 if protocol == dtls {
1206 return strconv.Itoa(vers.shimDTLS)
1207 }
1208 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001209}
1210
1211var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001212 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1213 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1214 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1215 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1216 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001217}
1218
David Benjaminaa012042016-12-10 13:33:05 -05001219type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001220 name string
1221 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001222}
1223
1224var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001225 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001226 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001227 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001228 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001229 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001230 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001231 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001232 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1233 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001234 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1235 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001236 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001237 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001238 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001239 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001240 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001241 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001242 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001243 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001244 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001245 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001246 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1247 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001248 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1249 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001250 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001251 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1252 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1253 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001254 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001255}
1256
David Benjamin8b8c0062014-11-23 02:47:52 -05001257func hasComponent(suiteName, component string) bool {
1258 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1259}
1260
David Benjaminf7768e42014-08-31 02:06:47 -04001261func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001262 return hasComponent(suiteName, "GCM") ||
1263 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001264 hasComponent(suiteName, "SHA384") ||
1265 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001266}
1267
Nick Harper1fd39d82016-06-14 18:14:35 -07001268func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001269 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001270}
1271
David Benjamin8b8c0062014-11-23 02:47:52 -05001272func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001273 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001274}
1275
Adam Langleya7997f12015-05-14 17:38:50 -07001276func bigFromHex(hex string) *big.Int {
1277 ret, ok := new(big.Int).SetString(hex, 16)
1278 if !ok {
1279 panic("failed to parse hex number 0x" + hex)
1280 }
1281 return ret
1282}
1283
Adam Langley7c803a62015-06-15 15:35:05 -07001284func addBasicTests() {
1285 basicTests := []testCase{
1286 {
Adam Langley7c803a62015-06-15 15:35:05 -07001287 name: "NoFallbackSCSV",
1288 config: Config{
1289 Bugs: ProtocolBugs{
1290 FailIfNotFallbackSCSV: true,
1291 },
1292 },
1293 shouldFail: true,
1294 expectedLocalError: "no fallback SCSV found",
1295 },
1296 {
1297 name: "SendFallbackSCSV",
1298 config: Config{
1299 Bugs: ProtocolBugs{
1300 FailIfNotFallbackSCSV: true,
1301 },
1302 },
1303 flags: []string{"-fallback-scsv"},
1304 },
1305 {
1306 name: "ClientCertificateTypes",
1307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001308 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 ClientAuth: RequestClientCert,
1310 ClientCertificateTypes: []byte{
1311 CertTypeDSSSign,
1312 CertTypeRSASign,
1313 CertTypeECDSASign,
1314 },
1315 },
1316 flags: []string{
1317 "-expect-certificate-types",
1318 base64.StdEncoding.EncodeToString([]byte{
1319 CertTypeDSSSign,
1320 CertTypeRSASign,
1321 CertTypeECDSASign,
1322 }),
1323 },
1324 },
1325 {
Adam Langley7c803a62015-06-15 15:35:05 -07001326 name: "UnauthenticatedECDH",
1327 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001328 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001329 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1330 Bugs: ProtocolBugs{
1331 UnauthenticatedECDH: true,
1332 },
1333 },
1334 shouldFail: true,
1335 expectedError: ":UNEXPECTED_MESSAGE:",
1336 },
1337 {
1338 name: "SkipCertificateStatus",
1339 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001340 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1342 Bugs: ProtocolBugs{
1343 SkipCertificateStatus: true,
1344 },
1345 },
1346 flags: []string{
1347 "-enable-ocsp-stapling",
1348 },
1349 },
1350 {
1351 name: "SkipServerKeyExchange",
1352 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001353 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001354 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1355 Bugs: ProtocolBugs{
1356 SkipServerKeyExchange: true,
1357 },
1358 },
1359 shouldFail: true,
1360 expectedError: ":UNEXPECTED_MESSAGE:",
1361 },
1362 {
Adam Langley7c803a62015-06-15 15:35:05 -07001363 testType: serverTest,
1364 name: "Alert",
1365 config: Config{
1366 Bugs: ProtocolBugs{
1367 SendSpuriousAlert: alertRecordOverflow,
1368 },
1369 },
1370 shouldFail: true,
1371 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1372 },
1373 {
1374 protocol: dtls,
1375 testType: serverTest,
1376 name: "Alert-DTLS",
1377 config: Config{
1378 Bugs: ProtocolBugs{
1379 SendSpuriousAlert: alertRecordOverflow,
1380 },
1381 },
1382 shouldFail: true,
1383 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1384 },
1385 {
1386 testType: serverTest,
1387 name: "FragmentAlert",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 FragmentAlert: true,
1391 SendSpuriousAlert: alertRecordOverflow,
1392 },
1393 },
1394 shouldFail: true,
1395 expectedError: ":BAD_ALERT:",
1396 },
1397 {
1398 protocol: dtls,
1399 testType: serverTest,
1400 name: "FragmentAlert-DTLS",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 FragmentAlert: true,
1404 SendSpuriousAlert: alertRecordOverflow,
1405 },
1406 },
1407 shouldFail: true,
1408 expectedError: ":BAD_ALERT:",
1409 },
1410 {
1411 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001412 name: "DoubleAlert",
1413 config: Config{
1414 Bugs: ProtocolBugs{
1415 DoubleAlert: true,
1416 SendSpuriousAlert: alertRecordOverflow,
1417 },
1418 },
1419 shouldFail: true,
1420 expectedError: ":BAD_ALERT:",
1421 },
1422 {
1423 protocol: dtls,
1424 testType: serverTest,
1425 name: "DoubleAlert-DTLS",
1426 config: Config{
1427 Bugs: ProtocolBugs{
1428 DoubleAlert: true,
1429 SendSpuriousAlert: alertRecordOverflow,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":BAD_ALERT:",
1434 },
1435 {
Adam Langley7c803a62015-06-15 15:35:05 -07001436 name: "SkipNewSessionTicket",
1437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001438 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001439 Bugs: ProtocolBugs{
1440 SkipNewSessionTicket: true,
1441 },
1442 },
1443 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001444 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001445 },
1446 {
1447 testType: serverTest,
1448 name: "FallbackSCSV",
1449 config: Config{
1450 MaxVersion: VersionTLS11,
1451 Bugs: ProtocolBugs{
1452 SendFallbackSCSV: true,
1453 },
1454 },
David Benjamin56cadc32016-12-16 19:54:11 -05001455 shouldFail: true,
1456 expectedError: ":INAPPROPRIATE_FALLBACK:",
1457 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001458 },
1459 {
1460 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001461 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001462 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001463 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001464 Bugs: ProtocolBugs{
1465 SendFallbackSCSV: true,
1466 },
1467 },
1468 },
1469 {
1470 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001471 name: "FallbackSCSV-VersionMatch-TLS12",
1472 config: Config{
1473 MaxVersion: VersionTLS12,
1474 Bugs: ProtocolBugs{
1475 SendFallbackSCSV: true,
1476 },
1477 },
1478 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1479 },
1480 {
1481 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "FragmentedClientVersion",
1483 config: Config{
1484 Bugs: ProtocolBugs{
1485 MaxHandshakeRecordLength: 1,
1486 FragmentClientVersion: true,
1487 },
1488 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001489 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001490 },
1491 {
Adam Langley7c803a62015-06-15 15:35:05 -07001492 testType: serverTest,
1493 name: "HttpGET",
1494 sendPrefix: "GET / HTTP/1.0\n",
1495 shouldFail: true,
1496 expectedError: ":HTTP_REQUEST:",
1497 },
1498 {
1499 testType: serverTest,
1500 name: "HttpPOST",
1501 sendPrefix: "POST / HTTP/1.0\n",
1502 shouldFail: true,
1503 expectedError: ":HTTP_REQUEST:",
1504 },
1505 {
1506 testType: serverTest,
1507 name: "HttpHEAD",
1508 sendPrefix: "HEAD / HTTP/1.0\n",
1509 shouldFail: true,
1510 expectedError: ":HTTP_REQUEST:",
1511 },
1512 {
1513 testType: serverTest,
1514 name: "HttpPUT",
1515 sendPrefix: "PUT / HTTP/1.0\n",
1516 shouldFail: true,
1517 expectedError: ":HTTP_REQUEST:",
1518 },
1519 {
1520 testType: serverTest,
1521 name: "HttpCONNECT",
1522 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1523 shouldFail: true,
1524 expectedError: ":HTTPS_PROXY_REQUEST:",
1525 },
1526 {
1527 testType: serverTest,
1528 name: "Garbage",
1529 sendPrefix: "blah",
1530 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001531 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001532 },
1533 {
Adam Langley7c803a62015-06-15 15:35:05 -07001534 name: "RSAEphemeralKey",
1535 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001536 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001537 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1538 Bugs: ProtocolBugs{
1539 RSAEphemeralKey: true,
1540 },
1541 },
1542 shouldFail: true,
1543 expectedError: ":UNEXPECTED_MESSAGE:",
1544 },
1545 {
1546 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001547 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001548 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001549 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001550 },
1551 {
1552 protocol: dtls,
1553 name: "DisableEverything-DTLS",
1554 flags: []string{"-no-tls12", "-no-tls1"},
1555 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001556 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 testType: serverTest,
1561 name: "MTU",
1562 config: Config{
1563 Bugs: ProtocolBugs{
1564 MaxPacketLength: 256,
1565 },
1566 },
1567 flags: []string{"-mtu", "256"},
1568 },
1569 {
1570 protocol: dtls,
1571 testType: serverTest,
1572 name: "MTUExceeded",
1573 config: Config{
1574 Bugs: ProtocolBugs{
1575 MaxPacketLength: 255,
1576 },
1577 },
1578 flags: []string{"-mtu", "256"},
1579 shouldFail: true,
1580 expectedLocalError: "dtls: exceeded maximum packet length",
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "EmptyCertificateList",
1584 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 EmptyCertificateList: true,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":DECODE_ERROR:",
1592 },
1593 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001594 name: "EmptyCertificateList-TLS13",
1595 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001596 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001597 Bugs: ProtocolBugs{
1598 EmptyCertificateList: true,
1599 },
1600 },
1601 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001602 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001603 },
1604 {
Adam Langley7c803a62015-06-15 15:35:05 -07001605 name: "TLSFatalBadPackets",
1606 damageFirstWrite: true,
1607 shouldFail: true,
1608 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1609 },
1610 {
1611 protocol: dtls,
1612 name: "DTLSIgnoreBadPackets",
1613 damageFirstWrite: true,
1614 },
1615 {
1616 protocol: dtls,
1617 name: "DTLSIgnoreBadPackets-Async",
1618 damageFirstWrite: true,
1619 flags: []string{"-async"},
1620 },
1621 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001622 name: "AppDataBeforeHandshake",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1626 },
1627 },
1628 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001629 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001630 },
1631 {
1632 name: "AppDataBeforeHandshake-Empty",
1633 config: Config{
1634 Bugs: ProtocolBugs{
1635 AppDataBeforeHandshake: []byte{},
1636 },
1637 },
1638 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001639 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001640 },
1641 {
1642 protocol: dtls,
1643 name: "AppDataBeforeHandshake-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":UNEXPECTED_RECORD:",
1651 },
1652 {
1653 protocol: dtls,
1654 name: "AppDataBeforeHandshake-DTLS-Empty",
1655 config: Config{
1656 Bugs: ProtocolBugs{
1657 AppDataBeforeHandshake: []byte{},
1658 },
1659 },
1660 shouldFail: true,
1661 expectedError: ":UNEXPECTED_RECORD:",
1662 },
1663 {
Adam Langley7c803a62015-06-15 15:35:05 -07001664 name: "AppDataAfterChangeCipherSpec",
1665 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001666 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001667 Bugs: ProtocolBugs{
1668 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1669 },
1670 },
1671 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001672 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001673 },
1674 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001675 name: "AppDataAfterChangeCipherSpec-Empty",
1676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001677 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001678 Bugs: ProtocolBugs{
1679 AppDataAfterChangeCipherSpec: []byte{},
1680 },
1681 },
1682 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001683 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001684 },
1685 {
Adam Langley7c803a62015-06-15 15:35:05 -07001686 protocol: dtls,
1687 name: "AppDataAfterChangeCipherSpec-DTLS",
1688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001689 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001690 Bugs: ProtocolBugs{
1691 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1692 },
1693 },
1694 // BoringSSL's DTLS implementation will drop the out-of-order
1695 // application data.
1696 },
1697 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001698 protocol: dtls,
1699 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1700 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001701 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001702 Bugs: ProtocolBugs{
1703 AppDataAfterChangeCipherSpec: []byte{},
1704 },
1705 },
1706 // BoringSSL's DTLS implementation will drop the out-of-order
1707 // application data.
1708 },
1709 {
Adam Langley7c803a62015-06-15 15:35:05 -07001710 name: "AlertAfterChangeCipherSpec",
1711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001712 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001713 Bugs: ProtocolBugs{
1714 AlertAfterChangeCipherSpec: alertRecordOverflow,
1715 },
1716 },
1717 shouldFail: true,
1718 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1719 },
1720 {
1721 protocol: dtls,
1722 name: "AlertAfterChangeCipherSpec-DTLS",
1723 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001724 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001725 Bugs: ProtocolBugs{
1726 AlertAfterChangeCipherSpec: alertRecordOverflow,
1727 },
1728 },
1729 shouldFail: true,
1730 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1731 },
1732 {
1733 protocol: dtls,
1734 name: "ReorderHandshakeFragments-Small-DTLS",
1735 config: Config{
1736 Bugs: ProtocolBugs{
1737 ReorderHandshakeFragments: true,
1738 // Small enough that every handshake message is
1739 // fragmented.
1740 MaxHandshakeRecordLength: 2,
1741 },
1742 },
1743 },
1744 {
1745 protocol: dtls,
1746 name: "ReorderHandshakeFragments-Large-DTLS",
1747 config: Config{
1748 Bugs: ProtocolBugs{
1749 ReorderHandshakeFragments: true,
1750 // Large enough that no handshake message is
1751 // fragmented.
1752 MaxHandshakeRecordLength: 2048,
1753 },
1754 },
1755 },
1756 {
1757 protocol: dtls,
1758 name: "MixCompleteMessageWithFragments-DTLS",
1759 config: Config{
1760 Bugs: ProtocolBugs{
1761 ReorderHandshakeFragments: true,
1762 MixCompleteMessageWithFragments: true,
1763 MaxHandshakeRecordLength: 2,
1764 },
1765 },
1766 },
1767 {
1768 name: "SendInvalidRecordType",
1769 config: Config{
1770 Bugs: ProtocolBugs{
1771 SendInvalidRecordType: true,
1772 },
1773 },
1774 shouldFail: true,
1775 expectedError: ":UNEXPECTED_RECORD:",
1776 },
1777 {
1778 protocol: dtls,
1779 name: "SendInvalidRecordType-DTLS",
1780 config: Config{
1781 Bugs: ProtocolBugs{
1782 SendInvalidRecordType: true,
1783 },
1784 },
1785 shouldFail: true,
1786 expectedError: ":UNEXPECTED_RECORD:",
1787 },
1788 {
1789 name: "FalseStart-SkipServerSecondLeg",
1790 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001791 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1793 NextProtos: []string{"foo"},
1794 Bugs: ProtocolBugs{
1795 SkipNewSessionTicket: true,
1796 SkipChangeCipherSpec: true,
1797 SkipFinished: true,
1798 ExpectFalseStart: true,
1799 },
1800 },
1801 flags: []string{
1802 "-false-start",
1803 "-handshake-never-done",
1804 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001805 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001806 },
1807 shimWritesFirst: true,
1808 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001809 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 },
1811 {
1812 name: "FalseStart-SkipServerSecondLeg-Implicit",
1813 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001814 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1816 NextProtos: []string{"foo"},
1817 Bugs: ProtocolBugs{
1818 SkipNewSessionTicket: true,
1819 SkipChangeCipherSpec: true,
1820 SkipFinished: true,
1821 },
1822 },
1823 flags: []string{
1824 "-implicit-handshake",
1825 "-false-start",
1826 "-handshake-never-done",
1827 "-advertise-alpn", "\x03foo",
1828 },
1829 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001830 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001831 },
1832 {
1833 testType: serverTest,
1834 name: "FailEarlyCallback",
1835 flags: []string{"-fail-early-callback"},
1836 shouldFail: true,
1837 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001838 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001839 },
1840 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001841 name: "FailCertCallback-Client-TLS12",
1842 config: Config{
1843 MaxVersion: VersionTLS12,
1844 ClientAuth: RequestClientCert,
1845 },
1846 flags: []string{"-fail-cert-callback"},
1847 shouldFail: true,
1848 expectedError: ":CERT_CB_ERROR:",
1849 expectedLocalError: "remote error: internal error",
1850 },
1851 {
1852 testType: serverTest,
1853 name: "FailCertCallback-Server-TLS12",
1854 config: Config{
1855 MaxVersion: VersionTLS12,
1856 },
1857 flags: []string{"-fail-cert-callback"},
1858 shouldFail: true,
1859 expectedError: ":CERT_CB_ERROR:",
1860 expectedLocalError: "remote error: internal error",
1861 },
1862 {
1863 name: "FailCertCallback-Client-TLS13",
1864 config: Config{
1865 MaxVersion: VersionTLS13,
1866 ClientAuth: RequestClientCert,
1867 },
1868 flags: []string{"-fail-cert-callback"},
1869 shouldFail: true,
1870 expectedError: ":CERT_CB_ERROR:",
1871 expectedLocalError: "remote error: internal error",
1872 },
1873 {
1874 testType: serverTest,
1875 name: "FailCertCallback-Server-TLS13",
1876 config: Config{
1877 MaxVersion: VersionTLS13,
1878 },
1879 flags: []string{"-fail-cert-callback"},
1880 shouldFail: true,
1881 expectedError: ":CERT_CB_ERROR:",
1882 expectedLocalError: "remote error: internal error",
1883 },
1884 {
Adam Langley7c803a62015-06-15 15:35:05 -07001885 protocol: dtls,
1886 name: "FragmentMessageTypeMismatch-DTLS",
1887 config: Config{
1888 Bugs: ProtocolBugs{
1889 MaxHandshakeRecordLength: 2,
1890 FragmentMessageTypeMismatch: true,
1891 },
1892 },
1893 shouldFail: true,
1894 expectedError: ":FRAGMENT_MISMATCH:",
1895 },
1896 {
1897 protocol: dtls,
1898 name: "FragmentMessageLengthMismatch-DTLS",
1899 config: Config{
1900 Bugs: ProtocolBugs{
1901 MaxHandshakeRecordLength: 2,
1902 FragmentMessageLengthMismatch: true,
1903 },
1904 },
1905 shouldFail: true,
1906 expectedError: ":FRAGMENT_MISMATCH:",
1907 },
1908 {
1909 protocol: dtls,
1910 name: "SplitFragments-Header-DTLS",
1911 config: Config{
1912 Bugs: ProtocolBugs{
1913 SplitFragments: 2,
1914 },
1915 },
1916 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001917 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001918 },
1919 {
1920 protocol: dtls,
1921 name: "SplitFragments-Boundary-DTLS",
1922 config: Config{
1923 Bugs: ProtocolBugs{
1924 SplitFragments: dtlsRecordHeaderLen,
1925 },
1926 },
1927 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001928 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001929 },
1930 {
1931 protocol: dtls,
1932 name: "SplitFragments-Body-DTLS",
1933 config: Config{
1934 Bugs: ProtocolBugs{
1935 SplitFragments: dtlsRecordHeaderLen + 1,
1936 },
1937 },
1938 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001939 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001940 },
1941 {
1942 protocol: dtls,
1943 name: "SendEmptyFragments-DTLS",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 SendEmptyFragments: true,
1947 },
1948 },
1949 },
1950 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001951 name: "BadFinished-Client",
1952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001953 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001954 Bugs: ProtocolBugs{
1955 BadFinished: true,
1956 },
1957 },
1958 shouldFail: true,
1959 expectedError: ":DIGEST_CHECK_FAILED:",
1960 },
1961 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001962 name: "BadFinished-Client-TLS13",
1963 config: Config{
1964 MaxVersion: VersionTLS13,
1965 Bugs: ProtocolBugs{
1966 BadFinished: true,
1967 },
1968 },
1969 shouldFail: true,
1970 expectedError: ":DIGEST_CHECK_FAILED:",
1971 },
1972 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001973 testType: serverTest,
1974 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001976 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001977 Bugs: ProtocolBugs{
1978 BadFinished: true,
1979 },
1980 },
1981 shouldFail: true,
1982 expectedError: ":DIGEST_CHECK_FAILED:",
1983 },
1984 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001985 testType: serverTest,
1986 name: "BadFinished-Server-TLS13",
1987 config: Config{
1988 MaxVersion: VersionTLS13,
1989 Bugs: ProtocolBugs{
1990 BadFinished: true,
1991 },
1992 },
1993 shouldFail: true,
1994 expectedError: ":DIGEST_CHECK_FAILED:",
1995 },
1996 {
Adam Langley7c803a62015-06-15 15:35:05 -07001997 name: "FalseStart-BadFinished",
1998 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001999 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002000 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2001 NextProtos: []string{"foo"},
2002 Bugs: ProtocolBugs{
2003 BadFinished: true,
2004 ExpectFalseStart: true,
2005 },
2006 },
2007 flags: []string{
2008 "-false-start",
2009 "-handshake-never-done",
2010 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002011 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002012 },
2013 shimWritesFirst: true,
2014 shouldFail: true,
2015 expectedError: ":DIGEST_CHECK_FAILED:",
2016 },
2017 {
2018 name: "NoFalseStart-NoALPN",
2019 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002020 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002021 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2022 Bugs: ProtocolBugs{
2023 ExpectFalseStart: true,
2024 AlertBeforeFalseStartTest: alertAccessDenied,
2025 },
2026 },
2027 flags: []string{
2028 "-false-start",
2029 },
2030 shimWritesFirst: true,
2031 shouldFail: true,
2032 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2033 expectedLocalError: "tls: peer did not false start: EOF",
2034 },
2035 {
2036 name: "NoFalseStart-NoAEAD",
2037 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002038 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002039 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2040 NextProtos: []string{"foo"},
2041 Bugs: ProtocolBugs{
2042 ExpectFalseStart: true,
2043 AlertBeforeFalseStartTest: alertAccessDenied,
2044 },
2045 },
2046 flags: []string{
2047 "-false-start",
2048 "-advertise-alpn", "\x03foo",
2049 },
2050 shimWritesFirst: true,
2051 shouldFail: true,
2052 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2053 expectedLocalError: "tls: peer did not false start: EOF",
2054 },
2055 {
2056 name: "NoFalseStart-RSA",
2057 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002058 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002059 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2060 NextProtos: []string{"foo"},
2061 Bugs: ProtocolBugs{
2062 ExpectFalseStart: true,
2063 AlertBeforeFalseStartTest: alertAccessDenied,
2064 },
2065 },
2066 flags: []string{
2067 "-false-start",
2068 "-advertise-alpn", "\x03foo",
2069 },
2070 shimWritesFirst: true,
2071 shouldFail: true,
2072 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2073 expectedLocalError: "tls: peer did not false start: EOF",
2074 },
2075 {
Adam Langley7c803a62015-06-15 15:35:05 -07002076 protocol: dtls,
2077 name: "SendSplitAlert-Sync",
2078 config: Config{
2079 Bugs: ProtocolBugs{
2080 SendSplitAlert: true,
2081 },
2082 },
2083 },
2084 {
2085 protocol: dtls,
2086 name: "SendSplitAlert-Async",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendSplitAlert: true,
2090 },
2091 },
2092 flags: []string{"-async"},
2093 },
2094 {
2095 protocol: dtls,
2096 name: "PackDTLSHandshake",
2097 config: Config{
2098 Bugs: ProtocolBugs{
2099 MaxHandshakeRecordLength: 2,
2100 PackHandshakeFragments: 20,
2101 PackHandshakeRecords: 200,
2102 },
2103 },
2104 },
2105 {
Adam Langley7c803a62015-06-15 15:35:05 -07002106 name: "SendEmptyRecords-Pass",
2107 sendEmptyRecords: 32,
2108 },
2109 {
2110 name: "SendEmptyRecords",
2111 sendEmptyRecords: 33,
2112 shouldFail: true,
2113 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2114 },
2115 {
2116 name: "SendEmptyRecords-Async",
2117 sendEmptyRecords: 33,
2118 flags: []string{"-async"},
2119 shouldFail: true,
2120 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2121 },
2122 {
David Benjamine8e84b92016-08-03 15:39:47 -04002123 name: "SendWarningAlerts-Pass",
2124 config: Config{
2125 MaxVersion: VersionTLS12,
2126 },
Adam Langley7c803a62015-06-15 15:35:05 -07002127 sendWarningAlerts: 4,
2128 },
2129 {
David Benjamine8e84b92016-08-03 15:39:47 -04002130 protocol: dtls,
2131 name: "SendWarningAlerts-DTLS-Pass",
2132 config: Config{
2133 MaxVersion: VersionTLS12,
2134 },
Adam Langley7c803a62015-06-15 15:35:05 -07002135 sendWarningAlerts: 4,
2136 },
2137 {
David Benjamine8e84b92016-08-03 15:39:47 -04002138 name: "SendWarningAlerts-TLS13",
2139 config: Config{
2140 MaxVersion: VersionTLS13,
2141 },
2142 sendWarningAlerts: 4,
2143 shouldFail: true,
2144 expectedError: ":BAD_ALERT:",
2145 expectedLocalError: "remote error: error decoding message",
2146 },
2147 {
2148 name: "SendWarningAlerts",
2149 config: Config{
2150 MaxVersion: VersionTLS12,
2151 },
Adam Langley7c803a62015-06-15 15:35:05 -07002152 sendWarningAlerts: 5,
2153 shouldFail: true,
2154 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2155 },
2156 {
David Benjamine8e84b92016-08-03 15:39:47 -04002157 name: "SendWarningAlerts-Async",
2158 config: Config{
2159 MaxVersion: VersionTLS12,
2160 },
Adam Langley7c803a62015-06-15 15:35:05 -07002161 sendWarningAlerts: 5,
2162 flags: []string{"-async"},
2163 shouldFail: true,
2164 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2165 },
David Benjaminba4594a2015-06-18 18:36:15 -04002166 {
David Benjamin24e58862017-06-14 18:45:29 -04002167 name: "SendBogusAlertType",
2168 sendBogusAlertType: true,
2169 shouldFail: true,
2170 expectedError: ":UNKNOWN_ALERT_TYPE:",
2171 expectedLocalError: "remote error: illegal parameter",
2172 },
2173 {
2174 protocol: dtls,
2175 name: "SendBogusAlertType-DTLS",
2176 sendBogusAlertType: true,
2177 shouldFail: true,
2178 expectedError: ":UNKNOWN_ALERT_TYPE:",
2179 expectedLocalError: "remote error: illegal parameter",
2180 },
2181 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002182 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002183 config: Config{
2184 MaxVersion: VersionTLS13,
2185 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002186 sendKeyUpdates: 33,
2187 keyUpdateRequest: keyUpdateNotRequested,
2188 shouldFail: true,
2189 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002190 },
2191 {
David Benjaminba4594a2015-06-18 18:36:15 -04002192 name: "EmptySessionID",
2193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002194 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002195 SessionTicketsDisabled: true,
2196 },
2197 noSessionCache: true,
2198 flags: []string{"-expect-no-session"},
2199 },
David Benjamin30789da2015-08-29 22:56:45 -04002200 {
2201 name: "Unclean-Shutdown",
2202 config: Config{
2203 Bugs: ProtocolBugs{
2204 NoCloseNotify: true,
2205 ExpectCloseNotify: true,
2206 },
2207 },
2208 shimShutsDown: true,
2209 flags: []string{"-check-close-notify"},
2210 shouldFail: true,
2211 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2212 },
2213 {
2214 name: "Unclean-Shutdown-Ignored",
2215 config: Config{
2216 Bugs: ProtocolBugs{
2217 NoCloseNotify: true,
2218 },
2219 },
2220 shimShutsDown: true,
2221 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002222 {
David Benjaminfa214e42016-05-10 17:03:10 -04002223 name: "Unclean-Shutdown-Alert",
2224 config: Config{
2225 Bugs: ProtocolBugs{
2226 SendAlertOnShutdown: alertDecompressionFailure,
2227 ExpectCloseNotify: true,
2228 },
2229 },
2230 shimShutsDown: true,
2231 flags: []string{"-check-close-notify"},
2232 shouldFail: true,
2233 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2234 },
2235 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002236 name: "LargePlaintext",
2237 config: Config{
2238 Bugs: ProtocolBugs{
2239 SendLargeRecords: true,
2240 },
2241 },
2242 messageLen: maxPlaintext + 1,
2243 shouldFail: true,
2244 expectedError: ":DATA_LENGTH_TOO_LONG:",
2245 },
2246 {
2247 protocol: dtls,
2248 name: "LargePlaintext-DTLS",
2249 config: Config{
2250 Bugs: ProtocolBugs{
2251 SendLargeRecords: true,
2252 },
2253 },
2254 messageLen: maxPlaintext + 1,
2255 shouldFail: true,
2256 expectedError: ":DATA_LENGTH_TOO_LONG:",
2257 },
2258 {
2259 name: "LargeCiphertext",
2260 config: Config{
2261 Bugs: ProtocolBugs{
2262 SendLargeRecords: true,
2263 },
2264 },
2265 messageLen: maxPlaintext * 2,
2266 shouldFail: true,
2267 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2268 },
2269 {
2270 protocol: dtls,
2271 name: "LargeCiphertext-DTLS",
2272 config: Config{
2273 Bugs: ProtocolBugs{
2274 SendLargeRecords: true,
2275 },
2276 },
2277 messageLen: maxPlaintext * 2,
2278 // Unlike the other four cases, DTLS drops records which
2279 // are invalid before authentication, so the connection
2280 // does not fail.
2281 expectMessageDropped: true,
2282 },
David Benjamindd6fed92015-10-23 17:41:12 -04002283 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002284 name: "BadHelloRequest-1",
2285 renegotiate: 1,
2286 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002287 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002288 Bugs: ProtocolBugs{
2289 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2290 },
2291 },
2292 flags: []string{
2293 "-renegotiate-freely",
2294 "-expect-total-renegotiations", "1",
2295 },
2296 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002297 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002298 },
2299 {
2300 name: "BadHelloRequest-2",
2301 renegotiate: 1,
2302 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002303 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002304 Bugs: ProtocolBugs{
2305 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2306 },
2307 },
2308 flags: []string{
2309 "-renegotiate-freely",
2310 "-expect-total-renegotiations", "1",
2311 },
2312 shouldFail: true,
2313 expectedError: ":BAD_HELLO_REQUEST:",
2314 },
David Benjaminef1b0092015-11-21 14:05:44 -05002315 {
2316 testType: serverTest,
2317 name: "SupportTicketsWithSessionID",
2318 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002319 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002320 SessionTicketsDisabled: true,
2321 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002322 resumeConfig: &Config{
2323 MaxVersion: VersionTLS12,
2324 },
David Benjaminef1b0092015-11-21 14:05:44 -05002325 resumeSession: true,
2326 },
David Benjamin02edcd02016-07-27 17:40:37 -04002327 {
2328 protocol: dtls,
2329 name: "DTLS-SendExtraFinished",
2330 config: Config{
2331 Bugs: ProtocolBugs{
2332 SendExtraFinished: true,
2333 },
2334 },
2335 shouldFail: true,
2336 expectedError: ":UNEXPECTED_RECORD:",
2337 },
2338 {
2339 protocol: dtls,
2340 name: "DTLS-SendExtraFinished-Reordered",
2341 config: Config{
2342 Bugs: ProtocolBugs{
2343 MaxHandshakeRecordLength: 2,
2344 ReorderHandshakeFragments: true,
2345 SendExtraFinished: true,
2346 },
2347 },
2348 shouldFail: true,
2349 expectedError: ":UNEXPECTED_RECORD:",
2350 },
David Benjamine97fb482016-07-29 09:23:07 -04002351 {
2352 testType: serverTest,
2353 name: "V2ClientHello-EmptyRecordPrefix",
2354 config: Config{
2355 // Choose a cipher suite that does not involve
2356 // elliptic curves, so no extensions are
2357 // involved.
2358 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002359 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002360 Bugs: ProtocolBugs{
2361 SendV2ClientHello: true,
2362 },
2363 },
2364 sendPrefix: string([]byte{
2365 byte(recordTypeHandshake),
2366 3, 1, // version
2367 0, 0, // length
2368 }),
2369 // A no-op empty record may not be sent before V2ClientHello.
2370 shouldFail: true,
2371 expectedError: ":WRONG_VERSION_NUMBER:",
2372 },
2373 {
2374 testType: serverTest,
2375 name: "V2ClientHello-WarningAlertPrefix",
2376 config: Config{
2377 // Choose a cipher suite that does not involve
2378 // elliptic curves, so no extensions are
2379 // involved.
2380 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002381 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002382 Bugs: ProtocolBugs{
2383 SendV2ClientHello: true,
2384 },
2385 },
2386 sendPrefix: string([]byte{
2387 byte(recordTypeAlert),
2388 3, 1, // version
2389 0, 2, // length
2390 alertLevelWarning, byte(alertDecompressionFailure),
2391 }),
2392 // A no-op warning alert may not be sent before V2ClientHello.
2393 shouldFail: true,
2394 expectedError: ":WRONG_VERSION_NUMBER:",
2395 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002396 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002397 name: "KeyUpdate-Client",
2398 config: Config{
2399 MaxVersion: VersionTLS13,
2400 },
2401 sendKeyUpdates: 1,
2402 keyUpdateRequest: keyUpdateNotRequested,
2403 },
2404 {
2405 testType: serverTest,
2406 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002407 config: Config{
2408 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002409 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002410 sendKeyUpdates: 1,
2411 keyUpdateRequest: keyUpdateNotRequested,
2412 },
2413 {
2414 name: "KeyUpdate-InvalidRequestMode",
2415 config: Config{
2416 MaxVersion: VersionTLS13,
2417 },
2418 sendKeyUpdates: 1,
2419 keyUpdateRequest: 42,
2420 shouldFail: true,
2421 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002422 },
David Benjaminabe94e32016-09-04 14:18:58 -04002423 {
David Benjaminbbba9392017-04-06 12:54:12 -04002424 // Test that KeyUpdates are acknowledged properly.
2425 name: "KeyUpdate-RequestACK",
2426 config: Config{
2427 MaxVersion: VersionTLS13,
2428 Bugs: ProtocolBugs{
2429 RejectUnsolicitedKeyUpdate: true,
2430 },
2431 },
2432 // Test the shim receiving many KeyUpdates in a row.
2433 sendKeyUpdates: 5,
2434 messageCount: 5,
2435 keyUpdateRequest: keyUpdateRequested,
2436 },
2437 {
2438 // Test that KeyUpdates are acknowledged properly if the
2439 // peer's KeyUpdate is discovered while a write is
2440 // pending.
2441 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2442 config: Config{
2443 MaxVersion: VersionTLS13,
2444 Bugs: ProtocolBugs{
2445 RejectUnsolicitedKeyUpdate: true,
2446 },
2447 },
2448 // Test the shim receiving many KeyUpdates in a row.
2449 sendKeyUpdates: 5,
2450 messageCount: 5,
2451 keyUpdateRequest: keyUpdateRequested,
2452 readWithUnfinishedWrite: true,
2453 flags: []string{"-async"},
2454 },
2455 {
David Benjaminabe94e32016-09-04 14:18:58 -04002456 name: "SendSNIWarningAlert",
2457 config: Config{
2458 MaxVersion: VersionTLS12,
2459 Bugs: ProtocolBugs{
2460 SendSNIWarningAlert: true,
2461 },
2462 },
2463 },
David Benjaminc241d792016-09-09 10:34:20 -04002464 {
2465 testType: serverTest,
2466 name: "ExtraCompressionMethods-TLS12",
2467 config: Config{
2468 MaxVersion: VersionTLS12,
2469 Bugs: ProtocolBugs{
2470 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2471 },
2472 },
2473 },
2474 {
2475 testType: serverTest,
2476 name: "ExtraCompressionMethods-TLS13",
2477 config: Config{
2478 MaxVersion: VersionTLS13,
2479 Bugs: ProtocolBugs{
2480 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2481 },
2482 },
2483 shouldFail: true,
2484 expectedError: ":INVALID_COMPRESSION_LIST:",
2485 expectedLocalError: "remote error: illegal parameter",
2486 },
2487 {
2488 testType: serverTest,
2489 name: "NoNullCompression-TLS12",
2490 config: Config{
2491 MaxVersion: VersionTLS12,
2492 Bugs: ProtocolBugs{
2493 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2494 },
2495 },
2496 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002497 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002498 expectedLocalError: "remote error: illegal parameter",
2499 },
2500 {
2501 testType: serverTest,
2502 name: "NoNullCompression-TLS13",
2503 config: Config{
2504 MaxVersion: VersionTLS13,
2505 Bugs: ProtocolBugs{
2506 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2507 },
2508 },
2509 shouldFail: true,
2510 expectedError: ":INVALID_COMPRESSION_LIST:",
2511 expectedLocalError: "remote error: illegal parameter",
2512 },
David Benjamin413e79e2017-07-01 10:11:53 -04002513 // Test that the client rejects invalid compression methods
2514 // from the server.
2515 {
2516 testType: clientTest,
2517 name: "InvalidCompressionMethod",
2518 config: Config{
2519 MaxVersion: VersionTLS12,
2520 Bugs: ProtocolBugs{
2521 SendCompressionMethod: 1,
2522 },
2523 },
2524 shouldFail: true,
2525 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2526 expectedLocalError: "remote error: illegal parameter",
2527 },
David Benjamin65ac9972016-09-02 21:35:25 -04002528 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002529 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002530 config: Config{
2531 MaxVersion: VersionTLS12,
2532 Bugs: ProtocolBugs{
2533 ExpectGREASE: true,
2534 },
2535 },
2536 flags: []string{"-enable-grease"},
2537 },
2538 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002539 name: "GREASE-Client-TLS13",
2540 config: Config{
2541 MaxVersion: VersionTLS13,
2542 Bugs: ProtocolBugs{
2543 ExpectGREASE: true,
2544 },
2545 },
2546 flags: []string{"-enable-grease"},
2547 },
2548 {
2549 testType: serverTest,
2550 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002551 config: Config{
2552 MaxVersion: VersionTLS13,
2553 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002554 // TLS 1.3 servers are expected to
2555 // always enable GREASE. TLS 1.3 is new,
2556 // so there is no existing ecosystem to
2557 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002558 ExpectGREASE: true,
2559 },
2560 },
David Benjamin65ac9972016-09-02 21:35:25 -04002561 },
David Benjamine3fbb362017-01-06 16:19:28 -05002562 {
2563 // Test the server so there is a large certificate as
2564 // well as application data.
2565 testType: serverTest,
2566 name: "MaxSendFragment",
2567 config: Config{
2568 Bugs: ProtocolBugs{
2569 MaxReceivePlaintext: 512,
2570 },
2571 },
2572 messageLen: 1024,
2573 flags: []string{
2574 "-max-send-fragment", "512",
2575 "-read-size", "1024",
2576 },
2577 },
2578 {
2579 // Test the server so there is a large certificate as
2580 // well as application data.
2581 testType: serverTest,
2582 name: "MaxSendFragment-TooLarge",
2583 config: Config{
2584 Bugs: ProtocolBugs{
2585 // Ensure that some of the records are
2586 // 512.
2587 MaxReceivePlaintext: 511,
2588 },
2589 },
2590 messageLen: 1024,
2591 flags: []string{
2592 "-max-send-fragment", "512",
2593 "-read-size", "1024",
2594 },
2595 shouldFail: true,
2596 expectedLocalError: "local error: record overflow",
2597 },
Adam Langley7c803a62015-06-15 15:35:05 -07002598 }
Adam Langley7c803a62015-06-15 15:35:05 -07002599 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002600
2601 // Test that very large messages can be received.
2602 cert := rsaCertificate
2603 for i := 0; i < 50; i++ {
2604 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2605 }
2606 testCases = append(testCases, testCase{
2607 name: "LargeMessage",
2608 config: Config{
2609 Certificates: []Certificate{cert},
2610 },
2611 })
2612 testCases = append(testCases, testCase{
2613 protocol: dtls,
2614 name: "LargeMessage-DTLS",
2615 config: Config{
2616 Certificates: []Certificate{cert},
2617 },
2618 })
2619
2620 // They are rejected if the maximum certificate chain length is capped.
2621 testCases = append(testCases, testCase{
2622 name: "LargeMessage-Reject",
2623 config: Config{
2624 Certificates: []Certificate{cert},
2625 },
2626 flags: []string{"-max-cert-list", "16384"},
2627 shouldFail: true,
2628 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2629 })
2630 testCases = append(testCases, testCase{
2631 protocol: dtls,
2632 name: "LargeMessage-Reject-DTLS",
2633 config: Config{
2634 Certificates: []Certificate{cert},
2635 },
2636 flags: []string{"-max-cert-list", "16384"},
2637 shouldFail: true,
2638 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2639 })
Adam Langley7c803a62015-06-15 15:35:05 -07002640}
2641
David Benjaminaa012042016-12-10 13:33:05 -05002642func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2643 const psk = "12345"
2644 const pskIdentity = "luggage combo"
2645
2646 var prefix string
2647 if protocol == dtls {
2648 if !ver.hasDTLS {
2649 return
2650 }
2651 prefix = "D"
2652 }
2653
2654 var cert Certificate
2655 var certFile string
2656 var keyFile string
2657 if hasComponent(suite.name, "ECDSA") {
2658 cert = ecdsaP256Certificate
2659 certFile = ecdsaP256CertificateFile
2660 keyFile = ecdsaP256KeyFile
2661 } else {
2662 cert = rsaCertificate
2663 certFile = rsaCertificateFile
2664 keyFile = rsaKeyFile
2665 }
2666
2667 var flags []string
2668 if hasComponent(suite.name, "PSK") {
2669 flags = append(flags,
2670 "-psk", psk,
2671 "-psk-identity", pskIdentity)
2672 }
2673 if hasComponent(suite.name, "NULL") {
2674 // NULL ciphers must be explicitly enabled.
2675 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2676 }
David Benjaminaa012042016-12-10 13:33:05 -05002677
2678 var shouldServerFail, shouldClientFail bool
2679 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2680 // BoringSSL clients accept ECDHE on SSLv3, but
2681 // a BoringSSL server will never select it
2682 // because the extension is missing.
2683 shouldServerFail = true
2684 }
2685 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2686 shouldClientFail = true
2687 shouldServerFail = true
2688 }
2689 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2690 shouldClientFail = true
2691 shouldServerFail = true
2692 }
2693 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2694 shouldClientFail = true
2695 shouldServerFail = true
2696 }
2697 if !isDTLSCipher(suite.name) && protocol == dtls {
2698 shouldClientFail = true
2699 shouldServerFail = true
2700 }
2701
2702 var sendCipherSuite uint16
2703 var expectedServerError, expectedClientError string
2704 serverCipherSuites := []uint16{suite.id}
2705 if shouldServerFail {
2706 expectedServerError = ":NO_SHARED_CIPHER:"
2707 }
2708 if shouldClientFail {
2709 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2710 // Configure the server to select ciphers as normal but
2711 // select an incompatible cipher in ServerHello.
2712 serverCipherSuites = nil
2713 sendCipherSuite = suite.id
2714 }
2715
David Benjamincdb6fe92017-02-07 16:06:48 -05002716 // For cipher suites and versions where exporters are defined, verify
2717 // that they interoperate.
2718 var exportKeyingMaterial int
2719 if ver.version > VersionSSL30 {
2720 exportKeyingMaterial = 1024
2721 }
2722
David Benjaminaa012042016-12-10 13:33:05 -05002723 testCases = append(testCases, testCase{
2724 testType: serverTest,
2725 protocol: protocol,
2726 name: prefix + ver.name + "-" + suite.name + "-server",
2727 config: Config{
2728 MinVersion: ver.version,
2729 MaxVersion: ver.version,
2730 CipherSuites: []uint16{suite.id},
2731 Certificates: []Certificate{cert},
2732 PreSharedKey: []byte(psk),
2733 PreSharedKeyIdentity: pskIdentity,
2734 Bugs: ProtocolBugs{
2735 AdvertiseAllConfiguredCiphers: true,
2736 },
2737 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002738 certFile: certFile,
2739 keyFile: keyFile,
2740 flags: flags,
2741 resumeSession: true,
2742 shouldFail: shouldServerFail,
2743 expectedError: expectedServerError,
2744 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002745 })
2746
2747 testCases = append(testCases, testCase{
2748 testType: clientTest,
2749 protocol: protocol,
2750 name: prefix + ver.name + "-" + suite.name + "-client",
2751 config: Config{
2752 MinVersion: ver.version,
2753 MaxVersion: ver.version,
2754 CipherSuites: serverCipherSuites,
2755 Certificates: []Certificate{cert},
2756 PreSharedKey: []byte(psk),
2757 PreSharedKeyIdentity: pskIdentity,
2758 Bugs: ProtocolBugs{
2759 IgnorePeerCipherPreferences: shouldClientFail,
2760 SendCipherSuite: sendCipherSuite,
2761 },
2762 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002763 flags: flags,
2764 resumeSession: true,
2765 shouldFail: shouldClientFail,
2766 expectedError: expectedClientError,
2767 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002768 })
2769
David Benjamin6f600d62016-12-21 16:06:54 -05002770 if shouldClientFail {
2771 return
2772 }
2773
2774 // Ensure the maximum record size is accepted.
2775 testCases = append(testCases, testCase{
2776 protocol: protocol,
2777 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2778 config: Config{
2779 MinVersion: ver.version,
2780 MaxVersion: ver.version,
2781 CipherSuites: []uint16{suite.id},
2782 Certificates: []Certificate{cert},
2783 PreSharedKey: []byte(psk),
2784 PreSharedKeyIdentity: pskIdentity,
2785 },
2786 flags: flags,
2787 messageLen: maxPlaintext,
2788 })
2789
2790 // Test bad records for all ciphers. Bad records are fatal in TLS
2791 // and ignored in DTLS.
2792 var shouldFail bool
2793 var expectedError string
2794 if protocol == tls {
2795 shouldFail = true
2796 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2797 }
2798
2799 testCases = append(testCases, testCase{
2800 protocol: protocol,
2801 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2802 config: Config{
2803 MinVersion: ver.version,
2804 MaxVersion: ver.version,
2805 CipherSuites: []uint16{suite.id},
2806 Certificates: []Certificate{cert},
2807 PreSharedKey: []byte(psk),
2808 PreSharedKeyIdentity: pskIdentity,
2809 },
2810 flags: flags,
2811 damageFirstWrite: true,
2812 messageLen: maxPlaintext,
2813 shouldFail: shouldFail,
2814 expectedError: expectedError,
2815 })
David Benjaminaa012042016-12-10 13:33:05 -05002816}
2817
Adam Langley95c29f32014-06-20 12:00:00 -07002818func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002819 const bogusCipher = 0xfe00
2820
Adam Langley95c29f32014-06-20 12:00:00 -07002821 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002822 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002823 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002824 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002825 }
David Benjamin2c99d282015-09-01 10:23:00 -04002826 }
Adam Langley95c29f32014-06-20 12:00:00 -07002827 }
Adam Langleya7997f12015-05-14 17:38:50 -07002828
2829 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002830 name: "NoSharedCipher",
2831 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002832 MaxVersion: VersionTLS12,
2833 CipherSuites: []uint16{},
2834 },
2835 shouldFail: true,
2836 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2837 })
2838
2839 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002840 name: "NoSharedCipher-TLS13",
2841 config: Config{
2842 MaxVersion: VersionTLS13,
2843 CipherSuites: []uint16{},
2844 },
2845 shouldFail: true,
2846 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2847 })
2848
2849 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002850 name: "UnsupportedCipherSuite",
2851 config: Config{
2852 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002853 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002854 Bugs: ProtocolBugs{
2855 IgnorePeerCipherPreferences: true,
2856 },
2857 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002858 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002859 shouldFail: true,
2860 expectedError: ":WRONG_CIPHER_RETURNED:",
2861 })
2862
2863 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002864 name: "ServerHelloBogusCipher",
2865 config: Config{
2866 MaxVersion: VersionTLS12,
2867 Bugs: ProtocolBugs{
2868 SendCipherSuite: bogusCipher,
2869 },
2870 },
2871 shouldFail: true,
2872 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2873 })
2874 testCases = append(testCases, testCase{
2875 name: "ServerHelloBogusCipher-TLS13",
2876 config: Config{
2877 MaxVersion: VersionTLS13,
2878 Bugs: ProtocolBugs{
2879 SendCipherSuite: bogusCipher,
2880 },
2881 },
2882 shouldFail: true,
2883 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2884 })
2885
David Benjamin241ae832016-01-15 03:04:54 -05002886 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002887 testCases = append(testCases, testCase{
2888 testType: serverTest,
2889 name: "UnknownCipher",
2890 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002891 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002892 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002893 Bugs: ProtocolBugs{
2894 AdvertiseAllConfiguredCiphers: true,
2895 },
2896 },
2897 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002898
2899 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002900 testCases = append(testCases, testCase{
2901 testType: serverTest,
2902 name: "UnknownCipher-TLS13",
2903 config: Config{
2904 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002905 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002906 Bugs: ProtocolBugs{
2907 AdvertiseAllConfiguredCiphers: true,
2908 },
David Benjamin241ae832016-01-15 03:04:54 -05002909 },
2910 })
2911
David Benjamin78679342016-09-16 19:42:05 -04002912 // Test empty ECDHE_PSK identity hints work as expected.
2913 testCases = append(testCases, testCase{
2914 name: "EmptyECDHEPSKHint",
2915 config: Config{
2916 MaxVersion: VersionTLS12,
2917 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2918 PreSharedKey: []byte("secret"),
2919 },
2920 flags: []string{"-psk", "secret"},
2921 })
2922
2923 // Test empty PSK identity hints work as expected, even if an explicit
2924 // ServerKeyExchange is sent.
2925 testCases = append(testCases, testCase{
2926 name: "ExplicitEmptyPSKHint",
2927 config: Config{
2928 MaxVersion: VersionTLS12,
2929 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2930 PreSharedKey: []byte("secret"),
2931 Bugs: ProtocolBugs{
2932 AlwaysSendPreSharedKeyIdentityHint: true,
2933 },
2934 },
2935 flags: []string{"-psk", "secret"},
2936 })
David Benjamin69522112017-03-28 15:38:29 -05002937
2938 // Test that clients enforce that the server-sent certificate and cipher
2939 // suite match in TLS 1.2.
2940 testCases = append(testCases, testCase{
2941 name: "CertificateCipherMismatch-RSA",
2942 config: Config{
2943 MaxVersion: VersionTLS12,
2944 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2945 Certificates: []Certificate{rsaCertificate},
2946 Bugs: ProtocolBugs{
2947 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2948 },
2949 },
2950 shouldFail: true,
2951 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2952 })
2953 testCases = append(testCases, testCase{
2954 name: "CertificateCipherMismatch-ECDSA",
2955 config: Config{
2956 MaxVersion: VersionTLS12,
2957 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2958 Certificates: []Certificate{ecdsaP256Certificate},
2959 Bugs: ProtocolBugs{
2960 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2961 },
2962 },
2963 shouldFail: true,
2964 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2965 })
2966 testCases = append(testCases, testCase{
2967 name: "CertificateCipherMismatch-Ed25519",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2971 Certificates: []Certificate{ed25519Certificate},
2972 Bugs: ProtocolBugs{
2973 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2974 },
2975 },
2976 shouldFail: true,
2977 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2978 })
2979
2980 // Test that servers decline to select a cipher suite which is
2981 // inconsistent with their configured certificate.
2982 testCases = append(testCases, testCase{
2983 testType: serverTest,
2984 name: "ServerCipherFilter-RSA",
2985 config: Config{
2986 MaxVersion: VersionTLS12,
2987 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2988 },
2989 flags: []string{
2990 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2991 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2992 },
2993 shouldFail: true,
2994 expectedError: ":NO_SHARED_CIPHER:",
2995 })
2996 testCases = append(testCases, testCase{
2997 testType: serverTest,
2998 name: "ServerCipherFilter-ECDSA",
2999 config: Config{
3000 MaxVersion: VersionTLS12,
3001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3002 },
3003 flags: []string{
3004 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3005 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3006 },
3007 shouldFail: true,
3008 expectedError: ":NO_SHARED_CIPHER:",
3009 })
3010 testCases = append(testCases, testCase{
3011 testType: serverTest,
3012 name: "ServerCipherFilter-Ed25519",
3013 config: Config{
3014 MaxVersion: VersionTLS12,
3015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3016 },
3017 flags: []string{
3018 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3019 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3020 },
3021 shouldFail: true,
3022 expectedError: ":NO_SHARED_CIPHER:",
3023 })
David Benjamin364af782017-07-01 10:35:27 -04003024
3025 // Test cipher suite negotiation works as expected. Configure a
3026 // complicated cipher suite configuration.
3027 const negotiationTestCiphers = "" +
3028 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3029 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3030 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3031 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3032 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3033 negotiationTests := []struct {
3034 ciphers []uint16
3035 expected uint16
3036 }{
3037 // Server preferences are honored, including when
3038 // equipreference groups are involved.
3039 {
3040 []uint16{
3041 TLS_RSA_WITH_AES_256_GCM_SHA384,
3042 TLS_RSA_WITH_AES_128_CBC_SHA,
3043 TLS_RSA_WITH_AES_128_GCM_SHA256,
3044 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3045 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3046 },
3047 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3048 },
3049 {
3050 []uint16{
3051 TLS_RSA_WITH_AES_256_GCM_SHA384,
3052 TLS_RSA_WITH_AES_128_CBC_SHA,
3053 TLS_RSA_WITH_AES_128_GCM_SHA256,
3054 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3055 },
3056 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3057 },
3058 {
3059 []uint16{
3060 TLS_RSA_WITH_AES_256_GCM_SHA384,
3061 TLS_RSA_WITH_AES_128_CBC_SHA,
3062 TLS_RSA_WITH_AES_128_GCM_SHA256,
3063 },
3064 TLS_RSA_WITH_AES_128_GCM_SHA256,
3065 },
3066 {
3067 []uint16{
3068 TLS_RSA_WITH_AES_256_GCM_SHA384,
3069 TLS_RSA_WITH_AES_128_CBC_SHA,
3070 },
3071 TLS_RSA_WITH_AES_128_CBC_SHA,
3072 },
3073 // Equipreference groups use the client preference.
3074 {
3075 []uint16{
3076 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3077 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3078 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3079 },
3080 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3081 },
3082 {
3083 []uint16{
3084 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3085 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3086 },
3087 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3088 },
3089 {
3090 []uint16{
3091 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3092 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3093 },
3094 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3095 },
3096 {
3097 []uint16{
3098 TLS_RSA_WITH_AES_256_GCM_SHA384,
3099 TLS_RSA_WITH_AES_256_CBC_SHA,
3100 },
3101 TLS_RSA_WITH_AES_256_GCM_SHA384,
3102 },
3103 {
3104 []uint16{
3105 TLS_RSA_WITH_AES_256_CBC_SHA,
3106 TLS_RSA_WITH_AES_256_GCM_SHA384,
3107 },
3108 TLS_RSA_WITH_AES_256_CBC_SHA,
3109 },
3110 // If there are two equipreference groups, the preferred one
3111 // takes precedence.
3112 {
3113 []uint16{
3114 TLS_RSA_WITH_AES_256_GCM_SHA384,
3115 TLS_RSA_WITH_AES_256_CBC_SHA,
3116 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3117 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3118 },
3119 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3120 },
3121 }
3122 for i, t := range negotiationTests {
3123 testCases = append(testCases, testCase{
3124 testType: serverTest,
3125 name: "CipherNegotiation-" + strconv.Itoa(i),
3126 config: Config{
3127 MaxVersion: VersionTLS12,
3128 CipherSuites: t.ciphers,
3129 },
3130 flags: []string{"-cipher", negotiationTestCiphers},
3131 expectedCipher: t.expected,
3132 })
3133 }
Adam Langley95c29f32014-06-20 12:00:00 -07003134}
3135
3136func addBadECDSASignatureTests() {
3137 for badR := BadValue(1); badR < NumBadValues; badR++ {
3138 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003139 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003140 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3141 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003142 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003143 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003144 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003145 Bugs: ProtocolBugs{
3146 BadECDSAR: badR,
3147 BadECDSAS: badS,
3148 },
3149 },
3150 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003151 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003152 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003153 testCases = append(testCases, testCase{
3154 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3155 config: Config{
3156 MaxVersion: VersionTLS13,
3157 Certificates: []Certificate{ecdsaP256Certificate},
3158 Bugs: ProtocolBugs{
3159 BadECDSAR: badR,
3160 BadECDSAS: badS,
3161 },
3162 },
3163 shouldFail: true,
3164 expectedError: ":BAD_SIGNATURE:",
3165 })
Adam Langley95c29f32014-06-20 12:00:00 -07003166 }
3167 }
3168}
3169
Adam Langley80842bd2014-06-20 12:00:00 -07003170func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003171 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003172 name: "MaxCBCPadding",
3173 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003174 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3176 Bugs: ProtocolBugs{
3177 MaxPadding: true,
3178 },
3179 },
3180 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3181 })
David Benjamin025b3d32014-07-01 19:53:04 -04003182 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003183 name: "BadCBCPadding",
3184 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003185 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003186 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3187 Bugs: ProtocolBugs{
3188 PaddingFirstByteBad: true,
3189 },
3190 },
3191 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003192 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003193 })
3194 // OpenSSL previously had an issue where the first byte of padding in
3195 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003196 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003197 name: "BadCBCPadding255",
3198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003199 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3201 Bugs: ProtocolBugs{
3202 MaxPadding: true,
3203 PaddingFirstByteBadIf255: true,
3204 },
3205 },
3206 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3207 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003208 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003209 })
3210}
3211
Kenny Root7fdeaf12014-08-05 15:23:37 -07003212func addCBCSplittingTests() {
3213 testCases = append(testCases, testCase{
3214 name: "CBCRecordSplitting",
3215 config: Config{
3216 MaxVersion: VersionTLS10,
3217 MinVersion: VersionTLS10,
3218 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3219 },
David Benjaminac8302a2015-09-01 17:18:15 -04003220 messageLen: -1, // read until EOF
3221 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003222 flags: []string{
3223 "-async",
3224 "-write-different-record-sizes",
3225 "-cbc-record-splitting",
3226 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003227 })
3228 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003229 name: "CBCRecordSplittingPartialWrite",
3230 config: Config{
3231 MaxVersion: VersionTLS10,
3232 MinVersion: VersionTLS10,
3233 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3234 },
3235 messageLen: -1, // read until EOF
3236 flags: []string{
3237 "-async",
3238 "-write-different-record-sizes",
3239 "-cbc-record-splitting",
3240 "-partial-write",
3241 },
3242 })
3243}
3244
David Benjamin636293b2014-07-08 17:59:18 -04003245func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003246 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003247 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003248 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3249 cert, err := x509.ParseCertificate(cert.Certificate[0])
3250 if err != nil {
3251 panic(err)
3252 }
3253 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003254 }
Adam Langley2ff79332017-02-28 13:45:39 -08003255 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003256
David Benjamin636293b2014-07-08 17:59:18 -04003257 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003258 testCases = append(testCases, testCase{
3259 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003260 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003261 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003262 MinVersion: ver.version,
3263 MaxVersion: ver.version,
3264 ClientAuth: RequireAnyClientCert,
3265 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003266 },
3267 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003268 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3269 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003270 },
3271 })
3272 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003273 testType: serverTest,
3274 name: ver.name + "-Server-ClientAuth-RSA",
3275 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003276 MinVersion: ver.version,
3277 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003278 Certificates: []Certificate{rsaCertificate},
3279 },
3280 flags: []string{"-require-any-client-certificate"},
3281 })
David Benjamine098ec22014-08-27 23:13:20 -04003282 if ver.version != VersionSSL30 {
3283 testCases = append(testCases, testCase{
3284 testType: serverTest,
3285 name: ver.name + "-Server-ClientAuth-ECDSA",
3286 config: Config{
3287 MinVersion: ver.version,
3288 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003289 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003290 },
3291 flags: []string{"-require-any-client-certificate"},
3292 })
3293 testCases = append(testCases, testCase{
3294 testType: clientTest,
3295 name: ver.name + "-Client-ClientAuth-ECDSA",
3296 config: Config{
3297 MinVersion: ver.version,
3298 MaxVersion: ver.version,
3299 ClientAuth: RequireAnyClientCert,
3300 ClientCAs: certPool,
3301 },
3302 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003303 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3304 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003305 },
3306 })
3307 }
Adam Langley37646832016-08-01 16:16:46 -07003308
3309 testCases = append(testCases, testCase{
3310 name: "NoClientCertificate-" + ver.name,
3311 config: Config{
3312 MinVersion: ver.version,
3313 MaxVersion: ver.version,
3314 ClientAuth: RequireAnyClientCert,
3315 },
3316 shouldFail: true,
3317 expectedLocalError: "client didn't provide a certificate",
3318 })
3319
3320 testCases = append(testCases, testCase{
3321 // Even if not configured to expect a certificate, OpenSSL will
3322 // return X509_V_OK as the verify_result.
3323 testType: serverTest,
3324 name: "NoClientCertificateRequested-Server-" + ver.name,
3325 config: Config{
3326 MinVersion: ver.version,
3327 MaxVersion: ver.version,
3328 },
3329 flags: []string{
3330 "-expect-verify-result",
3331 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003332 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003333 })
3334
3335 testCases = append(testCases, testCase{
3336 // If a client certificate is not provided, OpenSSL will still
3337 // return X509_V_OK as the verify_result.
3338 testType: serverTest,
3339 name: "NoClientCertificate-Server-" + ver.name,
3340 config: Config{
3341 MinVersion: ver.version,
3342 MaxVersion: ver.version,
3343 },
3344 flags: []string{
3345 "-expect-verify-result",
3346 "-verify-peer",
3347 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003348 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003349 })
3350
David Benjamin1db9e1b2016-10-07 20:51:43 -04003351 certificateRequired := "remote error: certificate required"
3352 if ver.version < VersionTLS13 {
3353 // Prior to TLS 1.3, the generic handshake_failure alert
3354 // was used.
3355 certificateRequired = "remote error: handshake failure"
3356 }
Adam Langley37646832016-08-01 16:16:46 -07003357 testCases = append(testCases, testCase{
3358 testType: serverTest,
3359 name: "RequireAnyClientCertificate-" + ver.name,
3360 config: Config{
3361 MinVersion: ver.version,
3362 MaxVersion: ver.version,
3363 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003364 flags: []string{"-require-any-client-certificate"},
3365 shouldFail: true,
3366 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3367 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003368 })
3369
3370 if ver.version != VersionSSL30 {
3371 testCases = append(testCases, testCase{
3372 testType: serverTest,
3373 name: "SkipClientCertificate-" + ver.name,
3374 config: Config{
3375 MinVersion: ver.version,
3376 MaxVersion: ver.version,
3377 Bugs: ProtocolBugs{
3378 SkipClientCertificate: true,
3379 },
3380 },
3381 // Setting SSL_VERIFY_PEER allows anonymous clients.
3382 flags: []string{"-verify-peer"},
3383 shouldFail: true,
3384 expectedError: ":UNEXPECTED_MESSAGE:",
3385 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003386
3387 testCases = append(testCases, testCase{
3388 testType: serverTest,
3389 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3390 config: Config{
3391 MinVersion: ver.version,
3392 MaxVersion: ver.version,
3393 },
3394 flags: []string{
3395 "-enable-channel-id",
3396 "-verify-peer-if-no-obc",
3397 },
3398 shouldFail: true,
3399 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3400 expectedLocalError: certificateRequired,
3401 })
3402
3403 testCases = append(testCases, testCase{
3404 testType: serverTest,
3405 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3406 config: Config{
3407 MinVersion: ver.version,
3408 MaxVersion: ver.version,
3409 ChannelID: channelIDKey,
3410 },
3411 expectChannelID: true,
3412 flags: []string{
3413 "-enable-channel-id",
3414 "-verify-peer-if-no-obc",
3415 },
3416 })
Adam Langley37646832016-08-01 16:16:46 -07003417 }
Adam Langley2ff79332017-02-28 13:45:39 -08003418
3419 testCases = append(testCases, testCase{
3420 testType: serverTest,
3421 name: ver.name + "-Server-CertReq-CA-List",
3422 config: Config{
3423 MinVersion: ver.version,
3424 MaxVersion: ver.version,
3425 Certificates: []Certificate{rsaCertificate},
3426 Bugs: ProtocolBugs{
3427 ExpectCertificateReqNames: caNames,
3428 },
3429 },
3430 flags: []string{
3431 "-require-any-client-certificate",
3432 "-use-client-ca-list", encodeDERValues(caNames),
3433 },
3434 })
3435
3436 testCases = append(testCases, testCase{
3437 testType: clientTest,
3438 name: ver.name + "-Client-CertReq-CA-List",
3439 config: Config{
3440 MinVersion: ver.version,
3441 MaxVersion: ver.version,
3442 Certificates: []Certificate{rsaCertificate},
3443 ClientAuth: RequireAnyClientCert,
3444 ClientCAs: certPool,
3445 },
3446 flags: []string{
3447 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3448 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3449 "-expect-client-ca-list", encodeDERValues(caNames),
3450 },
3451 })
David Benjamin636293b2014-07-08 17:59:18 -04003452 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003453
David Benjaminc032dfa2016-05-12 14:54:57 -04003454 // Client auth is only legal in certificate-based ciphers.
3455 testCases = append(testCases, testCase{
3456 testType: clientTest,
3457 name: "ClientAuth-PSK",
3458 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003459 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003460 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3461 PreSharedKey: []byte("secret"),
3462 ClientAuth: RequireAnyClientCert,
3463 },
3464 flags: []string{
3465 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3466 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3467 "-psk", "secret",
3468 },
3469 shouldFail: true,
3470 expectedError: ":UNEXPECTED_MESSAGE:",
3471 })
3472 testCases = append(testCases, testCase{
3473 testType: clientTest,
3474 name: "ClientAuth-ECDHE_PSK",
3475 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003476 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003477 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3478 PreSharedKey: []byte("secret"),
3479 ClientAuth: RequireAnyClientCert,
3480 },
3481 flags: []string{
3482 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3483 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3484 "-psk", "secret",
3485 },
3486 shouldFail: true,
3487 expectedError: ":UNEXPECTED_MESSAGE:",
3488 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003489
3490 // Regression test for a bug where the client CA list, if explicitly
3491 // set to NULL, was mis-encoded.
3492 testCases = append(testCases, testCase{
3493 testType: serverTest,
3494 name: "Null-Client-CA-List",
3495 config: Config{
3496 MaxVersion: VersionTLS12,
3497 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003498 Bugs: ProtocolBugs{
3499 ExpectCertificateReqNames: [][]byte{},
3500 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003501 },
3502 flags: []string{
3503 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003504 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003505 },
3506 })
David Benjamin636293b2014-07-08 17:59:18 -04003507}
3508
Adam Langley75712922014-10-10 16:23:43 -07003509func addExtendedMasterSecretTests() {
3510 const expectEMSFlag = "-expect-extended-master-secret"
3511
3512 for _, with := range []bool{false, true} {
3513 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003514 if with {
3515 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003516 }
3517
3518 for _, isClient := range []bool{false, true} {
3519 suffix := "-Server"
3520 testType := serverTest
3521 if isClient {
3522 suffix = "-Client"
3523 testType = clientTest
3524 }
3525
3526 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003527 // In TLS 1.3, the extension is irrelevant and
3528 // always reports as enabled.
3529 var flags []string
3530 if with || ver.version >= VersionTLS13 {
3531 flags = []string{expectEMSFlag}
3532 }
3533
Adam Langley75712922014-10-10 16:23:43 -07003534 test := testCase{
3535 testType: testType,
3536 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3537 config: Config{
3538 MinVersion: ver.version,
3539 MaxVersion: ver.version,
3540 Bugs: ProtocolBugs{
3541 NoExtendedMasterSecret: !with,
3542 RequireExtendedMasterSecret: with,
3543 },
3544 },
David Benjamin48cae082014-10-27 01:06:24 -04003545 flags: flags,
3546 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003547 }
3548 if test.shouldFail {
3549 test.expectedLocalError = "extended master secret required but not supported by peer"
3550 }
3551 testCases = append(testCases, test)
3552 }
3553 }
3554 }
3555
Adam Langleyba5934b2015-06-02 10:50:35 -07003556 for _, isClient := range []bool{false, true} {
3557 for _, supportedInFirstConnection := range []bool{false, true} {
3558 for _, supportedInResumeConnection := range []bool{false, true} {
3559 boolToWord := func(b bool) string {
3560 if b {
3561 return "Yes"
3562 }
3563 return "No"
3564 }
3565 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3566 if isClient {
3567 suffix += "Client"
3568 } else {
3569 suffix += "Server"
3570 }
3571
3572 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003573 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003574 Bugs: ProtocolBugs{
3575 RequireExtendedMasterSecret: true,
3576 },
3577 }
3578
3579 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003580 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003581 Bugs: ProtocolBugs{
3582 NoExtendedMasterSecret: true,
3583 },
3584 }
3585
3586 test := testCase{
3587 name: "ExtendedMasterSecret-" + suffix,
3588 resumeSession: true,
3589 }
3590
3591 if !isClient {
3592 test.testType = serverTest
3593 }
3594
3595 if supportedInFirstConnection {
3596 test.config = supportedConfig
3597 } else {
3598 test.config = noSupportConfig
3599 }
3600
3601 if supportedInResumeConnection {
3602 test.resumeConfig = &supportedConfig
3603 } else {
3604 test.resumeConfig = &noSupportConfig
3605 }
3606
3607 switch suffix {
3608 case "YesToYes-Client", "YesToYes-Server":
3609 // When a session is resumed, it should
3610 // still be aware that its master
3611 // secret was generated via EMS and
3612 // thus it's safe to use tls-unique.
3613 test.flags = []string{expectEMSFlag}
3614 case "NoToYes-Server":
3615 // If an original connection did not
3616 // contain EMS, but a resumption
3617 // handshake does, then a server should
3618 // not resume the session.
3619 test.expectResumeRejected = true
3620 case "YesToNo-Server":
3621 // Resuming an EMS session without the
3622 // EMS extension should cause the
3623 // server to abort the connection.
3624 test.shouldFail = true
3625 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3626 case "NoToYes-Client":
3627 // A client should abort a connection
3628 // where the server resumed a non-EMS
3629 // session but echoed the EMS
3630 // extension.
3631 test.shouldFail = true
3632 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3633 case "YesToNo-Client":
3634 // A client should abort a connection
3635 // where the server didn't echo EMS
3636 // when the session used it.
3637 test.shouldFail = true
3638 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3639 }
3640
3641 testCases = append(testCases, test)
3642 }
3643 }
3644 }
David Benjamin163c9562016-08-29 23:14:17 -04003645
3646 // Switching EMS on renegotiation is forbidden.
3647 testCases = append(testCases, testCase{
3648 name: "ExtendedMasterSecret-Renego-NoEMS",
3649 config: Config{
3650 MaxVersion: VersionTLS12,
3651 Bugs: ProtocolBugs{
3652 NoExtendedMasterSecret: true,
3653 NoExtendedMasterSecretOnRenegotiation: true,
3654 },
3655 },
3656 renegotiate: 1,
3657 flags: []string{
3658 "-renegotiate-freely",
3659 "-expect-total-renegotiations", "1",
3660 },
3661 })
3662
3663 testCases = append(testCases, testCase{
3664 name: "ExtendedMasterSecret-Renego-Upgrade",
3665 config: Config{
3666 MaxVersion: VersionTLS12,
3667 Bugs: ProtocolBugs{
3668 NoExtendedMasterSecret: true,
3669 },
3670 },
3671 renegotiate: 1,
3672 flags: []string{
3673 "-renegotiate-freely",
3674 "-expect-total-renegotiations", "1",
3675 },
3676 shouldFail: true,
3677 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3678 })
3679
3680 testCases = append(testCases, testCase{
3681 name: "ExtendedMasterSecret-Renego-Downgrade",
3682 config: Config{
3683 MaxVersion: VersionTLS12,
3684 Bugs: ProtocolBugs{
3685 NoExtendedMasterSecretOnRenegotiation: true,
3686 },
3687 },
3688 renegotiate: 1,
3689 flags: []string{
3690 "-renegotiate-freely",
3691 "-expect-total-renegotiations", "1",
3692 },
3693 shouldFail: true,
3694 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3695 })
Adam Langley75712922014-10-10 16:23:43 -07003696}
3697
David Benjamin582ba042016-07-07 12:33:25 -07003698type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003699 protocol protocol
3700 async bool
3701 splitHandshake bool
3702 packHandshakeFlight bool
3703 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003704}
3705
David Benjamin43ec06f2014-08-05 02:28:57 -04003706// Adds tests that try to cover the range of the handshake state machine, under
3707// various conditions. Some of these are redundant with other tests, but they
3708// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003709func addAllStateMachineCoverageTests() {
3710 for _, async := range []bool{false, true} {
3711 for _, protocol := range []protocol{tls, dtls} {
3712 addStateMachineCoverageTests(stateMachineTestConfig{
3713 protocol: protocol,
3714 async: async,
3715 })
3716 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003717 protocol: protocol,
3718 async: async,
3719 implicitHandshake: true,
3720 })
3721 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003722 protocol: protocol,
3723 async: async,
3724 splitHandshake: true,
3725 })
3726 if protocol == tls {
3727 addStateMachineCoverageTests(stateMachineTestConfig{
3728 protocol: protocol,
3729 async: async,
3730 packHandshakeFlight: true,
3731 })
3732 }
3733 }
3734 }
3735}
3736
3737func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003738 var tests []testCase
3739
3740 // Basic handshake, with resumption. Client and server,
3741 // session ID and session ticket.
3742 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003743 name: "Basic-Client",
3744 config: Config{
3745 MaxVersion: VersionTLS12,
3746 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003747 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003748 // Ensure session tickets are used, not session IDs.
3749 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003750 })
3751 tests = append(tests, testCase{
3752 name: "Basic-Client-RenewTicket",
3753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003754 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003755 Bugs: ProtocolBugs{
3756 RenewTicketOnResume: true,
3757 },
3758 },
David Benjamin46662482016-08-17 00:51:00 -04003759 flags: []string{"-expect-ticket-renewal"},
3760 resumeSession: true,
3761 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003762 })
3763 tests = append(tests, testCase{
3764 name: "Basic-Client-NoTicket",
3765 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003766 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003767 SessionTicketsDisabled: true,
3768 },
3769 resumeSession: true,
3770 })
3771 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003772 testType: serverTest,
3773 name: "Basic-Server",
3774 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003775 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003776 Bugs: ProtocolBugs{
3777 RequireSessionTickets: true,
3778 },
3779 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003780 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003781 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003782 })
3783 tests = append(tests, testCase{
3784 testType: serverTest,
3785 name: "Basic-Server-NoTickets",
3786 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003787 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003788 SessionTicketsDisabled: true,
3789 },
3790 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003791 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003792 })
3793 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003794 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003795 name: "Basic-Server-EarlyCallback",
3796 config: Config{
3797 MaxVersion: VersionTLS12,
3798 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003799 flags: []string{"-use-early-callback"},
3800 resumeSession: true,
3801 })
3802
Steven Valdez143e8b32016-07-11 13:19:03 -04003803 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003804 if config.protocol == tls {
3805 tests = append(tests, testCase{
3806 name: "TLS13-1RTT-Client",
3807 config: Config{
3808 MaxVersion: VersionTLS13,
3809 MinVersion: VersionTLS13,
3810 },
David Benjamin46662482016-08-17 00:51:00 -04003811 resumeSession: true,
3812 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003813 })
3814
3815 tests = append(tests, testCase{
3816 testType: serverTest,
3817 name: "TLS13-1RTT-Server",
3818 config: Config{
3819 MaxVersion: VersionTLS13,
3820 MinVersion: VersionTLS13,
3821 },
David Benjamin46662482016-08-17 00:51:00 -04003822 resumeSession: true,
3823 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003824 // TLS 1.3 uses tickets, so the session should not be
3825 // cached statefully.
3826 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003827 })
3828
3829 tests = append(tests, testCase{
3830 name: "TLS13-HelloRetryRequest-Client",
3831 config: Config{
3832 MaxVersion: VersionTLS13,
3833 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003834 // P-384 requires a HelloRetryRequest against BoringSSL's default
3835 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003836 CurvePreferences: []CurveID{CurveP384},
3837 Bugs: ProtocolBugs{
3838 ExpectMissingKeyShare: true,
3839 },
3840 },
3841 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3842 resumeSession: true,
3843 })
3844
3845 tests = append(tests, testCase{
3846 testType: serverTest,
3847 name: "TLS13-HelloRetryRequest-Server",
3848 config: Config{
3849 MaxVersion: VersionTLS13,
3850 MinVersion: VersionTLS13,
3851 // Require a HelloRetryRequest for every curve.
3852 DefaultCurves: []CurveID{},
3853 },
3854 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3855 resumeSession: true,
3856 })
Steven Valdez2d850622017-01-11 11:34:52 -05003857
Steven Valdez2d850622017-01-11 11:34:52 -05003858 tests = append(tests, testCase{
3859 testType: clientTest,
3860 name: "TLS13-EarlyData-Client",
3861 config: Config{
3862 MaxVersion: VersionTLS13,
3863 MinVersion: VersionTLS13,
3864 MaxEarlyDataSize: 16384,
3865 },
Steven Valdeze831a812017-03-09 14:56:07 -05003866 resumeConfig: &Config{
3867 MaxVersion: VersionTLS13,
3868 MinVersion: VersionTLS13,
3869 MaxEarlyDataSize: 16384,
3870 Bugs: ProtocolBugs{
3871 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3872 },
3873 },
Steven Valdez2d850622017-01-11 11:34:52 -05003874 resumeSession: true,
3875 flags: []string{
3876 "-enable-early-data",
3877 "-expect-early-data-info",
3878 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003879 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003880 },
3881 })
3882
3883 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003884 testType: clientTest,
3885 name: "TLS13-EarlyData-TooMuchData-Client",
3886 config: Config{
3887 MaxVersion: VersionTLS13,
3888 MinVersion: VersionTLS13,
3889 MaxEarlyDataSize: 2,
3890 },
3891 resumeConfig: &Config{
3892 MaxVersion: VersionTLS13,
3893 MinVersion: VersionTLS13,
3894 MaxEarlyDataSize: 2,
3895 Bugs: ProtocolBugs{
3896 ExpectEarlyData: [][]byte{{'h', 'e'}},
3897 },
3898 },
3899 resumeShimPrefix: "llo",
3900 resumeSession: true,
3901 flags: []string{
3902 "-enable-early-data",
3903 "-expect-early-data-info",
3904 "-expect-accept-early-data",
3905 "-on-resume-shim-writes-first",
3906 },
3907 })
3908
3909 // Unfinished writes can only be tested when operations are async. EarlyData
3910 // can't be tested as part of an ImplicitHandshake in this case since
3911 // otherwise the early data will be sent as normal data.
3912 if config.async && !config.implicitHandshake {
3913 tests = append(tests, testCase{
3914 testType: clientTest,
3915 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3916 config: Config{
3917 MaxVersion: VersionTLS13,
3918 MinVersion: VersionTLS13,
3919 MaxEarlyDataSize: 16384,
3920 },
3921 resumeConfig: &Config{
3922 MaxVersion: VersionTLS13,
3923 MinVersion: VersionTLS13,
3924 MaxEarlyDataSize: 16384,
3925 Bugs: ProtocolBugs{
3926 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3927 },
3928 },
3929 resumeSession: true,
3930 flags: []string{
3931 "-enable-early-data",
3932 "-expect-early-data-info",
3933 "-expect-accept-early-data",
3934 "-on-resume-read-with-unfinished-write",
3935 "-on-resume-shim-writes-first",
3936 },
3937 })
3938
3939 // Rejected unfinished writes are discarded (from the
3940 // perspective of the calling application) on 0-RTT
3941 // reject.
3942 tests = append(tests, testCase{
3943 testType: clientTest,
3944 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3945 config: Config{
3946 MaxVersion: VersionTLS13,
3947 MinVersion: VersionTLS13,
3948 MaxEarlyDataSize: 16384,
3949 },
3950 resumeConfig: &Config{
3951 MaxVersion: VersionTLS13,
3952 MinVersion: VersionTLS13,
3953 MaxEarlyDataSize: 16384,
3954 Bugs: ProtocolBugs{
3955 AlwaysRejectEarlyData: true,
3956 },
3957 },
3958 resumeSession: true,
3959 flags: []string{
3960 "-enable-early-data",
3961 "-expect-early-data-info",
3962 "-expect-reject-early-data",
3963 "-on-resume-read-with-unfinished-write",
3964 "-on-resume-shim-writes-first",
3965 },
3966 })
3967 }
3968
3969 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003970 testType: serverTest,
3971 name: "TLS13-EarlyData-Server",
3972 config: Config{
3973 MaxVersion: VersionTLS13,
3974 MinVersion: VersionTLS13,
3975 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003976 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003977 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003978 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003979 },
3980 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003981 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003982 resumeSession: true,
3983 flags: []string{
3984 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003985 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003986 },
3987 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003988
3989 tests = append(tests, testCase{
3990 testType: serverTest,
3991 name: "TLS13-MaxEarlyData-Server",
3992 config: Config{
3993 MaxVersion: VersionTLS13,
3994 MinVersion: VersionTLS13,
3995 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003996 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003997 ExpectEarlyDataAccepted: true,
3998 },
3999 },
4000 messageCount: 2,
4001 resumeSession: true,
4002 flags: []string{
4003 "-enable-early-data",
4004 "-expect-accept-early-data",
4005 },
4006 shouldFail: true,
4007 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4008 })
David Benjamine73c7f42016-08-17 00:29:33 -04004009 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004010
David Benjamin760b1dd2015-05-15 23:33:48 -04004011 // TLS client auth.
4012 tests = append(tests, testCase{
4013 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004014 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004015 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004016 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004017 ClientAuth: RequestClientCert,
4018 },
4019 })
4020 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004021 testType: serverTest,
4022 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004023 config: Config{
4024 MaxVersion: VersionTLS12,
4025 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004026 // Setting SSL_VERIFY_PEER allows anonymous clients.
4027 flags: []string{"-verify-peer"},
4028 })
David Benjamin582ba042016-07-07 12:33:25 -07004029 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004030 tests = append(tests, testCase{
4031 testType: clientTest,
4032 name: "ClientAuth-NoCertificate-Client-SSL3",
4033 config: Config{
4034 MaxVersion: VersionSSL30,
4035 ClientAuth: RequestClientCert,
4036 },
4037 })
4038 tests = append(tests, testCase{
4039 testType: serverTest,
4040 name: "ClientAuth-NoCertificate-Server-SSL3",
4041 config: Config{
4042 MaxVersion: VersionSSL30,
4043 },
4044 // Setting SSL_VERIFY_PEER allows anonymous clients.
4045 flags: []string{"-verify-peer"},
4046 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004047 tests = append(tests, testCase{
4048 testType: clientTest,
4049 name: "ClientAuth-NoCertificate-Client-TLS13",
4050 config: Config{
4051 MaxVersion: VersionTLS13,
4052 ClientAuth: RequestClientCert,
4053 },
4054 })
4055 tests = append(tests, testCase{
4056 testType: serverTest,
4057 name: "ClientAuth-NoCertificate-Server-TLS13",
4058 config: Config{
4059 MaxVersion: VersionTLS13,
4060 },
4061 // Setting SSL_VERIFY_PEER allows anonymous clients.
4062 flags: []string{"-verify-peer"},
4063 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004064 }
4065 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004066 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004067 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004069 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004070 ClientAuth: RequireAnyClientCert,
4071 },
4072 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004073 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4074 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004075 },
4076 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004077 tests = append(tests, testCase{
4078 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004079 name: "ClientAuth-RSA-Client-TLS13",
4080 config: Config{
4081 MaxVersion: VersionTLS13,
4082 ClientAuth: RequireAnyClientCert,
4083 },
4084 flags: []string{
4085 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4086 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4087 },
4088 })
4089 tests = append(tests, testCase{
4090 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004091 name: "ClientAuth-ECDSA-Client",
4092 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004093 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004094 ClientAuth: RequireAnyClientCert,
4095 },
4096 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004097 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4098 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004099 },
4100 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004101 tests = append(tests, testCase{
4102 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004103 name: "ClientAuth-ECDSA-Client-TLS13",
4104 config: Config{
4105 MaxVersion: VersionTLS13,
4106 ClientAuth: RequireAnyClientCert,
4107 },
4108 flags: []string{
4109 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4110 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4111 },
4112 })
4113 tests = append(tests, testCase{
4114 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004115 name: "ClientAuth-NoCertificate-OldCallback",
4116 config: Config{
4117 MaxVersion: VersionTLS12,
4118 ClientAuth: RequestClientCert,
4119 },
4120 flags: []string{"-use-old-client-cert-callback"},
4121 })
4122 tests = append(tests, testCase{
4123 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004124 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4125 config: Config{
4126 MaxVersion: VersionTLS13,
4127 ClientAuth: RequestClientCert,
4128 },
4129 flags: []string{"-use-old-client-cert-callback"},
4130 })
4131 tests = append(tests, testCase{
4132 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004133 name: "ClientAuth-OldCallback",
4134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004135 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004136 ClientAuth: RequireAnyClientCert,
4137 },
4138 flags: []string{
4139 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4140 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4141 "-use-old-client-cert-callback",
4142 },
4143 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004144 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004145 testType: clientTest,
4146 name: "ClientAuth-OldCallback-TLS13",
4147 config: Config{
4148 MaxVersion: VersionTLS13,
4149 ClientAuth: RequireAnyClientCert,
4150 },
4151 flags: []string{
4152 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4153 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4154 "-use-old-client-cert-callback",
4155 },
4156 })
4157 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004158 testType: serverTest,
4159 name: "ClientAuth-Server",
4160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004161 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004162 Certificates: []Certificate{rsaCertificate},
4163 },
4164 flags: []string{"-require-any-client-certificate"},
4165 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004166 tests = append(tests, testCase{
4167 testType: serverTest,
4168 name: "ClientAuth-Server-TLS13",
4169 config: Config{
4170 MaxVersion: VersionTLS13,
4171 Certificates: []Certificate{rsaCertificate},
4172 },
4173 flags: []string{"-require-any-client-certificate"},
4174 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004175
David Benjamin4c3ddf72016-06-29 18:13:53 -04004176 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004177 tests = append(tests, testCase{
4178 testType: serverTest,
4179 name: "Basic-Server-RSA",
4180 config: Config{
4181 MaxVersion: VersionTLS12,
4182 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4183 },
4184 flags: []string{
4185 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4186 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4187 },
4188 })
4189 tests = append(tests, testCase{
4190 testType: serverTest,
4191 name: "Basic-Server-ECDHE-RSA",
4192 config: Config{
4193 MaxVersion: VersionTLS12,
4194 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4195 },
4196 flags: []string{
4197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4199 },
4200 })
4201 tests = append(tests, testCase{
4202 testType: serverTest,
4203 name: "Basic-Server-ECDHE-ECDSA",
4204 config: Config{
4205 MaxVersion: VersionTLS12,
4206 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4207 },
4208 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004209 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4210 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004211 },
4212 })
David Benjamin69522112017-03-28 15:38:29 -05004213 tests = append(tests, testCase{
4214 testType: serverTest,
4215 name: "Basic-Server-Ed25519",
4216 config: Config{
4217 MaxVersion: VersionTLS12,
4218 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4219 },
4220 flags: []string{
4221 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4222 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4223 "-enable-ed25519",
4224 },
4225 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004226
David Benjamin760b1dd2015-05-15 23:33:48 -04004227 // No session ticket support; server doesn't send NewSessionTicket.
4228 tests = append(tests, testCase{
4229 name: "SessionTicketsDisabled-Client",
4230 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004231 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004232 SessionTicketsDisabled: true,
4233 },
4234 })
4235 tests = append(tests, testCase{
4236 testType: serverTest,
4237 name: "SessionTicketsDisabled-Server",
4238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004239 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004240 SessionTicketsDisabled: true,
4241 },
4242 })
4243
4244 // Skip ServerKeyExchange in PSK key exchange if there's no
4245 // identity hint.
4246 tests = append(tests, testCase{
4247 name: "EmptyPSKHint-Client",
4248 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004249 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004250 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4251 PreSharedKey: []byte("secret"),
4252 },
4253 flags: []string{"-psk", "secret"},
4254 })
4255 tests = append(tests, testCase{
4256 testType: serverTest,
4257 name: "EmptyPSKHint-Server",
4258 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004259 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004260 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4261 PreSharedKey: []byte("secret"),
4262 },
4263 flags: []string{"-psk", "secret"},
4264 })
4265
David Benjamin4c3ddf72016-06-29 18:13:53 -04004266 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004267 tests = append(tests, testCase{
4268 testType: clientTest,
4269 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004270 config: Config{
4271 MaxVersion: VersionTLS12,
4272 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004273 flags: []string{
4274 "-enable-ocsp-stapling",
4275 "-expect-ocsp-response",
4276 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004277 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004278 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004279 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004280 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004281 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004282 testType: serverTest,
4283 name: "OCSPStapling-Server",
4284 config: Config{
4285 MaxVersion: VersionTLS12,
4286 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004287 expectedOCSPResponse: testOCSPResponse,
4288 flags: []string{
4289 "-ocsp-response",
4290 base64.StdEncoding.EncodeToString(testOCSPResponse),
4291 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004292 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004293 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004294 tests = append(tests, testCase{
4295 testType: clientTest,
4296 name: "OCSPStapling-Client-TLS13",
4297 config: Config{
4298 MaxVersion: VersionTLS13,
4299 },
4300 flags: []string{
4301 "-enable-ocsp-stapling",
4302 "-expect-ocsp-response",
4303 base64.StdEncoding.EncodeToString(testOCSPResponse),
4304 "-verify-peer",
4305 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004306 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004307 })
4308 tests = append(tests, testCase{
4309 testType: serverTest,
4310 name: "OCSPStapling-Server-TLS13",
4311 config: Config{
4312 MaxVersion: VersionTLS13,
4313 },
4314 expectedOCSPResponse: testOCSPResponse,
4315 flags: []string{
4316 "-ocsp-response",
4317 base64.StdEncoding.EncodeToString(testOCSPResponse),
4318 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004319 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004320 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004321
David Benjamin4c3ddf72016-06-29 18:13:53 -04004322 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004323 for _, vers := range tlsVersions {
4324 if config.protocol == dtls && !vers.hasDTLS {
4325 continue
4326 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004327 for _, testType := range []testType{clientTest, serverTest} {
4328 suffix := "-Client"
4329 if testType == serverTest {
4330 suffix = "-Server"
4331 }
4332 suffix += "-" + vers.name
4333
4334 flag := "-verify-peer"
4335 if testType == serverTest {
4336 flag = "-require-any-client-certificate"
4337 }
4338
4339 tests = append(tests, testCase{
4340 testType: testType,
4341 name: "CertificateVerificationSucceed" + suffix,
4342 config: Config{
4343 MaxVersion: vers.version,
4344 Certificates: []Certificate{rsaCertificate},
4345 },
4346 flags: []string{
4347 flag,
4348 "-expect-verify-result",
4349 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004350 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004351 })
4352 tests = append(tests, testCase{
4353 testType: testType,
4354 name: "CertificateVerificationFail" + suffix,
4355 config: Config{
4356 MaxVersion: vers.version,
4357 Certificates: []Certificate{rsaCertificate},
4358 },
4359 flags: []string{
4360 flag,
4361 "-verify-fail",
4362 },
4363 shouldFail: true,
4364 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4365 })
4366 }
4367
4368 // By default, the client is in a soft fail mode where the peer
4369 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004370 tests = append(tests, testCase{
4371 testType: clientTest,
4372 name: "CertificateVerificationSoftFail-" + vers.name,
4373 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004374 MaxVersion: vers.version,
4375 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004376 },
4377 flags: []string{
4378 "-verify-fail",
4379 "-expect-verify-result",
4380 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004381 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004382 })
4383 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004384
David Benjamin1d4f4c02016-07-26 18:03:08 -04004385 tests = append(tests, testCase{
4386 name: "ShimSendAlert",
4387 flags: []string{"-send-alert"},
4388 shimWritesFirst: true,
4389 shouldFail: true,
4390 expectedLocalError: "remote error: decompression failure",
4391 })
4392
David Benjamin582ba042016-07-07 12:33:25 -07004393 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004394 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004395 name: "Renegotiate-Client",
4396 config: Config{
4397 MaxVersion: VersionTLS12,
4398 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004399 renegotiate: 1,
4400 flags: []string{
4401 "-renegotiate-freely",
4402 "-expect-total-renegotiations", "1",
4403 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004404 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004405
David Benjamin47921102016-07-28 11:29:18 -04004406 tests = append(tests, testCase{
4407 name: "SendHalfHelloRequest",
4408 config: Config{
4409 MaxVersion: VersionTLS12,
4410 Bugs: ProtocolBugs{
4411 PackHelloRequestWithFinished: config.packHandshakeFlight,
4412 },
4413 },
4414 sendHalfHelloRequest: true,
4415 flags: []string{"-renegotiate-ignore"},
4416 shouldFail: true,
4417 expectedError: ":UNEXPECTED_RECORD:",
4418 })
4419
David Benjamin760b1dd2015-05-15 23:33:48 -04004420 // NPN on client and server; results in post-handshake message.
4421 tests = append(tests, testCase{
4422 name: "NPN-Client",
4423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004424 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004425 NextProtos: []string{"foo"},
4426 },
4427 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004428 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004429 expectedNextProto: "foo",
4430 expectedNextProtoType: npn,
4431 })
4432 tests = append(tests, testCase{
4433 testType: serverTest,
4434 name: "NPN-Server",
4435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004436 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004437 NextProtos: []string{"bar"},
4438 },
4439 flags: []string{
4440 "-advertise-npn", "\x03foo\x03bar\x03baz",
4441 "-expect-next-proto", "bar",
4442 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004443 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004444 expectedNextProto: "bar",
4445 expectedNextProtoType: npn,
4446 })
4447
4448 // TODO(davidben): Add tests for when False Start doesn't trigger.
4449
4450 // Client does False Start and negotiates NPN.
4451 tests = append(tests, testCase{
4452 name: "FalseStart",
4453 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004454 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004455 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4456 NextProtos: []string{"foo"},
4457 Bugs: ProtocolBugs{
4458 ExpectFalseStart: true,
4459 },
4460 },
4461 flags: []string{
4462 "-false-start",
4463 "-select-next-proto", "foo",
4464 },
4465 shimWritesFirst: true,
4466 resumeSession: true,
4467 })
4468
4469 // Client does False Start and negotiates ALPN.
4470 tests = append(tests, testCase{
4471 name: "FalseStart-ALPN",
4472 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004473 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4475 NextProtos: []string{"foo"},
4476 Bugs: ProtocolBugs{
4477 ExpectFalseStart: true,
4478 },
4479 },
4480 flags: []string{
4481 "-false-start",
4482 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004483 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004484 },
4485 shimWritesFirst: true,
4486 resumeSession: true,
4487 })
4488
David Benjamin760b1dd2015-05-15 23:33:48 -04004489 // False Start without session tickets.
4490 tests = append(tests, testCase{
4491 name: "FalseStart-SessionTicketsDisabled",
4492 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004493 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004494 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4495 NextProtos: []string{"foo"},
4496 SessionTicketsDisabled: true,
4497 Bugs: ProtocolBugs{
4498 ExpectFalseStart: true,
4499 },
4500 },
4501 flags: []string{
4502 "-false-start",
4503 "-select-next-proto", "foo",
4504 },
4505 shimWritesFirst: true,
4506 })
4507
4508 // Server parses a V2ClientHello.
4509 tests = append(tests, testCase{
4510 testType: serverTest,
4511 name: "SendV2ClientHello",
4512 config: Config{
4513 // Choose a cipher suite that does not involve
4514 // elliptic curves, so no extensions are
4515 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004516 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004517 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004518 Bugs: ProtocolBugs{
4519 SendV2ClientHello: true,
4520 },
4521 },
4522 })
4523
Nick Harper60a85cb2016-09-23 16:25:11 -07004524 // Test Channel ID
4525 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004526 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004527 continue
4528 }
4529 // Client sends a Channel ID.
4530 tests = append(tests, testCase{
4531 name: "ChannelID-Client-" + ver.name,
4532 config: Config{
4533 MaxVersion: ver.version,
4534 RequestChannelID: true,
4535 },
4536 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4537 resumeSession: true,
4538 expectChannelID: true,
4539 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004540
Nick Harper60a85cb2016-09-23 16:25:11 -07004541 // Server accepts a Channel ID.
4542 tests = append(tests, testCase{
4543 testType: serverTest,
4544 name: "ChannelID-Server-" + ver.name,
4545 config: Config{
4546 MaxVersion: ver.version,
4547 ChannelID: channelIDKey,
4548 },
4549 flags: []string{
4550 "-expect-channel-id",
4551 base64.StdEncoding.EncodeToString(channelIDBytes),
4552 },
4553 resumeSession: true,
4554 expectChannelID: true,
4555 })
4556
4557 tests = append(tests, testCase{
4558 testType: serverTest,
4559 name: "InvalidChannelIDSignature-" + ver.name,
4560 config: Config{
4561 MaxVersion: ver.version,
4562 ChannelID: channelIDKey,
4563 Bugs: ProtocolBugs{
4564 InvalidChannelIDSignature: true,
4565 },
4566 },
4567 flags: []string{"-enable-channel-id"},
4568 shouldFail: true,
4569 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4570 })
David Benjamin634f4752017-07-01 11:08:41 -04004571
4572 if ver.version < VersionTLS13 {
4573 // Channel ID requires ECDHE ciphers.
4574 tests = append(tests, testCase{
4575 testType: serverTest,
4576 name: "ChannelID-NoECDHE-" + ver.name,
4577 config: Config{
4578 MaxVersion: ver.version,
4579 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4580 ChannelID: channelIDKey,
4581 },
4582 expectChannelID: false,
4583 flags: []string{"-enable-channel-id"},
4584 })
4585
4586 // Sanity-check setting expectChannelID false works.
4587 tests = append(tests, testCase{
4588 testType: serverTest,
4589 name: "ChannelID-ECDHE-" + ver.name,
4590 config: Config{
4591 MaxVersion: ver.version,
4592 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4593 ChannelID: channelIDKey,
4594 },
4595 expectChannelID: false,
4596 flags: []string{"-enable-channel-id"},
4597 shouldFail: true,
4598 expectedLocalError: "channel ID unexpectedly negotiated",
4599 })
4600 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004601 }
David Benjamin30789da2015-08-29 22:56:45 -04004602
David Benjaminf8fcdf32016-06-08 15:56:13 -04004603 // Channel ID and NPN at the same time, to ensure their relative
4604 // ordering is correct.
4605 tests = append(tests, testCase{
4606 name: "ChannelID-NPN-Client",
4607 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004608 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004609 RequestChannelID: true,
4610 NextProtos: []string{"foo"},
4611 },
4612 flags: []string{
4613 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4614 "-select-next-proto", "foo",
4615 },
4616 resumeSession: true,
4617 expectChannelID: true,
4618 expectedNextProto: "foo",
4619 expectedNextProtoType: npn,
4620 })
4621 tests = append(tests, testCase{
4622 testType: serverTest,
4623 name: "ChannelID-NPN-Server",
4624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004625 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004626 ChannelID: channelIDKey,
4627 NextProtos: []string{"bar"},
4628 },
4629 flags: []string{
4630 "-expect-channel-id",
4631 base64.StdEncoding.EncodeToString(channelIDBytes),
4632 "-advertise-npn", "\x03foo\x03bar\x03baz",
4633 "-expect-next-proto", "bar",
4634 },
4635 resumeSession: true,
4636 expectChannelID: true,
4637 expectedNextProto: "bar",
4638 expectedNextProtoType: npn,
4639 })
4640
David Benjamin30789da2015-08-29 22:56:45 -04004641 // Bidirectional shutdown with the runner initiating.
4642 tests = append(tests, testCase{
4643 name: "Shutdown-Runner",
4644 config: Config{
4645 Bugs: ProtocolBugs{
4646 ExpectCloseNotify: true,
4647 },
4648 },
4649 flags: []string{"-check-close-notify"},
4650 })
4651
David Benjamine3843d42017-03-25 18:00:56 -05004652 if !config.implicitHandshake {
4653 // Bidirectional shutdown with the shim initiating. The runner,
4654 // in the meantime, sends garbage before the close_notify which
4655 // the shim must ignore. This test is disabled under implicit
4656 // handshake tests because the shim never reads or writes.
4657 tests = append(tests, testCase{
4658 name: "Shutdown-Shim",
4659 config: Config{
4660 MaxVersion: VersionTLS12,
4661 Bugs: ProtocolBugs{
4662 ExpectCloseNotify: true,
4663 },
David Benjamin30789da2015-08-29 22:56:45 -04004664 },
David Benjamine3843d42017-03-25 18:00:56 -05004665 shimShutsDown: true,
4666 sendEmptyRecords: 1,
4667 sendWarningAlerts: 1,
4668 flags: []string{"-check-close-notify"},
4669 })
4670 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004671 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004672 // TODO(davidben): DTLS 1.3 will want a similar thing for
4673 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004674 tests = append(tests, testCase{
4675 name: "SkipHelloVerifyRequest",
4676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004677 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004678 Bugs: ProtocolBugs{
4679 SkipHelloVerifyRequest: true,
4680 },
4681 },
4682 })
4683 }
4684
David Benjamin760b1dd2015-05-15 23:33:48 -04004685 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004686 test.protocol = config.protocol
4687 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004688 test.name += "-DTLS"
4689 }
David Benjamin582ba042016-07-07 12:33:25 -07004690 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004691 test.name += "-Async"
4692 test.flags = append(test.flags, "-async")
4693 } else {
4694 test.name += "-Sync"
4695 }
David Benjamin582ba042016-07-07 12:33:25 -07004696 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004697 test.name += "-SplitHandshakeRecords"
4698 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004699 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004700 test.config.Bugs.MaxPacketLength = 256
4701 test.flags = append(test.flags, "-mtu", "256")
4702 }
4703 }
David Benjamin582ba042016-07-07 12:33:25 -07004704 if config.packHandshakeFlight {
4705 test.name += "-PackHandshakeFlight"
4706 test.config.Bugs.PackHandshakeFlight = true
4707 }
David Benjamine3843d42017-03-25 18:00:56 -05004708 if config.implicitHandshake {
4709 test.name += "-ImplicitHandshake"
4710 test.flags = append(test.flags, "-implicit-handshake")
4711 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004712 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004713 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004714}
4715
Adam Langley524e7172015-02-20 16:04:00 -08004716func addDDoSCallbackTests() {
4717 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004718 for _, resume := range []bool{false, true} {
4719 suffix := "Resume"
4720 if resume {
4721 suffix = "No" + suffix
4722 }
4723
4724 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004725 testType: serverTest,
4726 name: "Server-DDoS-OK-" + suffix,
4727 config: Config{
4728 MaxVersion: VersionTLS12,
4729 },
Adam Langley524e7172015-02-20 16:04:00 -08004730 flags: []string{"-install-ddos-callback"},
4731 resumeSession: resume,
4732 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004733 testCases = append(testCases, testCase{
4734 testType: serverTest,
4735 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4736 config: Config{
4737 MaxVersion: VersionTLS13,
4738 },
4739 flags: []string{"-install-ddos-callback"},
4740 resumeSession: resume,
4741 })
Adam Langley524e7172015-02-20 16:04:00 -08004742
4743 failFlag := "-fail-ddos-callback"
4744 if resume {
4745 failFlag = "-fail-second-ddos-callback"
4746 }
4747 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004748 testType: serverTest,
4749 name: "Server-DDoS-Reject-" + suffix,
4750 config: Config{
4751 MaxVersion: VersionTLS12,
4752 },
David Benjamin2c66e072016-09-16 15:58:00 -04004753 flags: []string{"-install-ddos-callback", failFlag},
4754 resumeSession: resume,
4755 shouldFail: true,
4756 expectedError: ":CONNECTION_REJECTED:",
4757 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004758 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004759 testCases = append(testCases, testCase{
4760 testType: serverTest,
4761 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4762 config: Config{
4763 MaxVersion: VersionTLS13,
4764 },
David Benjamin2c66e072016-09-16 15:58:00 -04004765 flags: []string{"-install-ddos-callback", failFlag},
4766 resumeSession: resume,
4767 shouldFail: true,
4768 expectedError: ":CONNECTION_REJECTED:",
4769 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004770 })
Adam Langley524e7172015-02-20 16:04:00 -08004771 }
4772}
4773
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004774func addVersionNegotiationTests() {
4775 for i, shimVers := range tlsVersions {
4776 // Assemble flags to disable all newer versions on the shim.
4777 var flags []string
4778 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004779 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004780 }
4781
Steven Valdezfdd10992016-09-15 16:27:05 -04004782 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004783 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004784 protocols := []protocol{tls}
4785 if runnerVers.hasDTLS && shimVers.hasDTLS {
4786 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004787 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004788 for _, protocol := range protocols {
4789 expectedVersion := shimVers.version
4790 if runnerVers.version < shimVers.version {
4791 expectedVersion = runnerVers.version
4792 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004793
David Benjamin8b8c0062014-11-23 02:47:52 -05004794 suffix := shimVers.name + "-" + runnerVers.name
4795 if protocol == dtls {
4796 suffix += "-DTLS"
4797 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004798
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004799 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004800 clientVers := shimVers.version
4801 if clientVers > VersionTLS10 {
4802 clientVers = VersionTLS10
4803 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004804 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004805 serverVers := expectedVersion
4806 if expectedVersion >= VersionTLS13 {
4807 serverVers = VersionTLS10
4808 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004809 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004810
David Benjamin8b8c0062014-11-23 02:47:52 -05004811 testCases = append(testCases, testCase{
4812 protocol: protocol,
4813 testType: clientTest,
4814 name: "VersionNegotiation-Client-" + suffix,
4815 config: Config{
4816 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004817 Bugs: ProtocolBugs{
4818 ExpectInitialRecordVersion: clientVers,
4819 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004820 },
4821 flags: flags,
4822 expectedVersion: expectedVersion,
4823 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004824 testCases = append(testCases, testCase{
4825 protocol: protocol,
4826 testType: clientTest,
4827 name: "VersionNegotiation-Client2-" + suffix,
4828 config: Config{
4829 MaxVersion: runnerVers.version,
4830 Bugs: ProtocolBugs{
4831 ExpectInitialRecordVersion: clientVers,
4832 },
4833 },
David Benjamin353577c2017-06-29 15:54:58 -04004834 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004835 expectedVersion: expectedVersion,
4836 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004837
4838 testCases = append(testCases, testCase{
4839 protocol: protocol,
4840 testType: serverTest,
4841 name: "VersionNegotiation-Server-" + suffix,
4842 config: Config{
4843 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004844 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004845 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004846 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004847 },
4848 flags: flags,
4849 expectedVersion: expectedVersion,
4850 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004851 testCases = append(testCases, testCase{
4852 protocol: protocol,
4853 testType: serverTest,
4854 name: "VersionNegotiation-Server2-" + suffix,
4855 config: Config{
4856 MaxVersion: runnerVers.version,
4857 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004858 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004859 },
4860 },
David Benjamin353577c2017-06-29 15:54:58 -04004861 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004862 expectedVersion: expectedVersion,
4863 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004864 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004865 }
4866 }
David Benjamin95c69562016-06-29 18:15:03 -04004867
Steven Valdezfdd10992016-09-15 16:27:05 -04004868 // Test the version extension at all versions.
4869 for _, vers := range tlsVersions {
4870 protocols := []protocol{tls}
4871 if vers.hasDTLS {
4872 protocols = append(protocols, dtls)
4873 }
4874 for _, protocol := range protocols {
4875 suffix := vers.name
4876 if protocol == dtls {
4877 suffix += "-DTLS"
4878 }
4879
Steven Valdezc94998a2017-06-20 10:55:02 -04004880 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004881 testCases = append(testCases, testCase{
4882 protocol: protocol,
4883 testType: serverTest,
4884 name: "VersionNegotiationExtension-" + suffix,
4885 config: Config{
4886 Bugs: ProtocolBugs{
4887 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4888 },
4889 },
4890 expectedVersion: vers.version,
4891 })
4892 }
4893
4894 }
4895
4896 // If all versions are unknown, negotiation fails.
4897 testCases = append(testCases, testCase{
4898 testType: serverTest,
4899 name: "NoSupportedVersions",
4900 config: Config{
4901 Bugs: ProtocolBugs{
4902 SendSupportedVersions: []uint16{0x1111},
4903 },
4904 },
4905 shouldFail: true,
4906 expectedError: ":UNSUPPORTED_PROTOCOL:",
4907 })
4908 testCases = append(testCases, testCase{
4909 protocol: dtls,
4910 testType: serverTest,
4911 name: "NoSupportedVersions-DTLS",
4912 config: Config{
4913 Bugs: ProtocolBugs{
4914 SendSupportedVersions: []uint16{0x1111},
4915 },
4916 },
4917 shouldFail: true,
4918 expectedError: ":UNSUPPORTED_PROTOCOL:",
4919 })
4920
4921 testCases = append(testCases, testCase{
4922 testType: serverTest,
4923 name: "ClientHelloVersionTooHigh",
4924 config: Config{
4925 MaxVersion: VersionTLS13,
4926 Bugs: ProtocolBugs{
4927 SendClientVersion: 0x0304,
4928 OmitSupportedVersions: true,
4929 },
4930 },
4931 expectedVersion: VersionTLS12,
4932 })
4933
4934 testCases = append(testCases, testCase{
4935 testType: serverTest,
4936 name: "ConflictingVersionNegotiation",
4937 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004938 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004939 SendClientVersion: VersionTLS12,
4940 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004941 },
4942 },
David Benjaminad75a662016-09-30 15:42:59 -04004943 // The extension takes precedence over the ClientHello version.
4944 expectedVersion: VersionTLS11,
4945 })
4946
4947 testCases = append(testCases, testCase{
4948 testType: serverTest,
4949 name: "ConflictingVersionNegotiation-2",
4950 config: Config{
4951 Bugs: ProtocolBugs{
4952 SendClientVersion: VersionTLS11,
4953 SendSupportedVersions: []uint16{VersionTLS12},
4954 },
4955 },
4956 // The extension takes precedence over the ClientHello version.
4957 expectedVersion: VersionTLS12,
4958 })
4959
4960 testCases = append(testCases, testCase{
4961 testType: serverTest,
4962 name: "RejectFinalTLS13",
4963 config: Config{
4964 Bugs: ProtocolBugs{
4965 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4966 },
4967 },
4968 // We currently implement a draft TLS 1.3 version. Ensure that
4969 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004970 expectedVersion: VersionTLS12,
4971 })
4972
Brian Smithf85d3232016-10-28 10:34:06 -10004973 // Test that the maximum version is selected regardless of the
4974 // client-sent order.
4975 testCases = append(testCases, testCase{
4976 testType: serverTest,
4977 name: "IgnoreClientVersionOrder",
4978 config: Config{
4979 Bugs: ProtocolBugs{
4980 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4981 },
4982 },
4983 expectedVersion: VersionTLS13,
4984 })
4985
David Benjamin95c69562016-06-29 18:15:03 -04004986 // Test for version tolerance.
4987 testCases = append(testCases, testCase{
4988 testType: serverTest,
4989 name: "MinorVersionTolerance",
4990 config: Config{
4991 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004992 SendClientVersion: 0x03ff,
4993 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004994 },
4995 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004996 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004997 })
4998 testCases = append(testCases, testCase{
4999 testType: serverTest,
5000 name: "MajorVersionTolerance",
5001 config: Config{
5002 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005003 SendClientVersion: 0x0400,
5004 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005005 },
5006 },
David Benjaminad75a662016-09-30 15:42:59 -04005007 // TLS 1.3 must be negotiated with the supported_versions
5008 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005009 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005010 })
David Benjaminad75a662016-09-30 15:42:59 -04005011 testCases = append(testCases, testCase{
5012 testType: serverTest,
5013 name: "VersionTolerance-TLS13",
5014 config: Config{
5015 Bugs: ProtocolBugs{
5016 // Although TLS 1.3 does not use
5017 // ClientHello.version, it still tolerates high
5018 // values there.
5019 SendClientVersion: 0x0400,
5020 },
5021 },
5022 expectedVersion: VersionTLS13,
5023 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005024
David Benjamin95c69562016-06-29 18:15:03 -04005025 testCases = append(testCases, testCase{
5026 protocol: dtls,
5027 testType: serverTest,
5028 name: "MinorVersionTolerance-DTLS",
5029 config: Config{
5030 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005031 SendClientVersion: 0xfe00,
5032 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005033 },
5034 },
5035 expectedVersion: VersionTLS12,
5036 })
5037 testCases = append(testCases, testCase{
5038 protocol: dtls,
5039 testType: serverTest,
5040 name: "MajorVersionTolerance-DTLS",
5041 config: Config{
5042 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005043 SendClientVersion: 0xfdff,
5044 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005045 },
5046 },
5047 expectedVersion: VersionTLS12,
5048 })
5049
5050 // Test that versions below 3.0 are rejected.
5051 testCases = append(testCases, testCase{
5052 testType: serverTest,
5053 name: "VersionTooLow",
5054 config: Config{
5055 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005056 SendClientVersion: 0x0200,
5057 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005058 },
5059 },
5060 shouldFail: true,
5061 expectedError: ":UNSUPPORTED_PROTOCOL:",
5062 })
5063 testCases = append(testCases, testCase{
5064 protocol: dtls,
5065 testType: serverTest,
5066 name: "VersionTooLow-DTLS",
5067 config: Config{
5068 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005069 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005070 },
5071 },
5072 shouldFail: true,
5073 expectedError: ":UNSUPPORTED_PROTOCOL:",
5074 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005075
David Benjamin2dc02042016-09-19 19:57:37 -04005076 testCases = append(testCases, testCase{
5077 name: "ServerBogusVersion",
5078 config: Config{
5079 Bugs: ProtocolBugs{
5080 SendServerHelloVersion: 0x1234,
5081 },
5082 },
5083 shouldFail: true,
5084 expectedError: ":UNSUPPORTED_PROTOCOL:",
5085 })
5086
David Benjamin1f61f0d2016-07-10 12:20:35 -04005087 // Test TLS 1.3's downgrade signal.
5088 testCases = append(testCases, testCase{
5089 name: "Downgrade-TLS12-Client",
5090 config: Config{
5091 Bugs: ProtocolBugs{
5092 NegotiateVersion: VersionTLS12,
5093 },
5094 },
David Benjamin592b5322016-09-30 15:15:01 -04005095 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005096 // TODO(davidben): This test should fail once TLS 1.3 is final
5097 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005098 })
5099 testCases = append(testCases, testCase{
5100 testType: serverTest,
5101 name: "Downgrade-TLS12-Server",
5102 config: Config{
5103 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005104 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005105 },
5106 },
David Benjamin592b5322016-09-30 15:15:01 -04005107 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005108 // TODO(davidben): This test should fail once TLS 1.3 is final
5109 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005110 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005111}
5112
David Benjaminaccb4542014-12-12 23:44:33 -05005113func addMinimumVersionTests() {
5114 for i, shimVers := range tlsVersions {
5115 // Assemble flags to disable all older versions on the shim.
5116 var flags []string
5117 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04005118 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05005119 }
5120
5121 for _, runnerVers := range tlsVersions {
5122 protocols := []protocol{tls}
5123 if runnerVers.hasDTLS && shimVers.hasDTLS {
5124 protocols = append(protocols, dtls)
5125 }
5126 for _, protocol := range protocols {
5127 suffix := shimVers.name + "-" + runnerVers.name
5128 if protocol == dtls {
5129 suffix += "-DTLS"
5130 }
David Benjaminaccb4542014-12-12 23:44:33 -05005131
David Benjaminaccb4542014-12-12 23:44:33 -05005132 var expectedVersion uint16
5133 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005134 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005135 if runnerVers.version >= shimVers.version {
5136 expectedVersion = runnerVers.version
5137 } else {
5138 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005139 expectedError = ":UNSUPPORTED_PROTOCOL:"
5140 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005141 }
5142
5143 testCases = append(testCases, testCase{
5144 protocol: protocol,
5145 testType: clientTest,
5146 name: "MinimumVersion-Client-" + suffix,
5147 config: Config{
5148 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005149 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005150 // Ensure the server does not decline to
5151 // select a version (versions extension) or
5152 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005153 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005154 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005155 },
David Benjaminaccb4542014-12-12 23:44:33 -05005156 },
David Benjamin87909c02014-12-13 01:55:01 -05005157 flags: flags,
5158 expectedVersion: expectedVersion,
5159 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005160 expectedError: expectedError,
5161 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005162 })
5163 testCases = append(testCases, testCase{
5164 protocol: protocol,
5165 testType: clientTest,
5166 name: "MinimumVersion-Client2-" + suffix,
5167 config: Config{
5168 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005169 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005170 // Ensure the server does not decline to
5171 // select a version (versions extension) or
5172 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005173 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005174 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005175 },
David Benjaminaccb4542014-12-12 23:44:33 -05005176 },
David Benjamin353577c2017-06-29 15:54:58 -04005177 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005178 expectedVersion: expectedVersion,
5179 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005180 expectedError: expectedError,
5181 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005182 })
5183
5184 testCases = append(testCases, testCase{
5185 protocol: protocol,
5186 testType: serverTest,
5187 name: "MinimumVersion-Server-" + suffix,
5188 config: Config{
5189 MaxVersion: runnerVers.version,
5190 },
David Benjamin87909c02014-12-13 01:55:01 -05005191 flags: flags,
5192 expectedVersion: expectedVersion,
5193 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005194 expectedError: expectedError,
5195 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005196 })
5197 testCases = append(testCases, testCase{
5198 protocol: protocol,
5199 testType: serverTest,
5200 name: "MinimumVersion-Server2-" + suffix,
5201 config: Config{
5202 MaxVersion: runnerVers.version,
5203 },
David Benjamin353577c2017-06-29 15:54:58 -04005204 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005205 expectedVersion: expectedVersion,
5206 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005207 expectedError: expectedError,
5208 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005209 })
5210 }
5211 }
5212 }
5213}
5214
David Benjamine78bfde2014-09-06 12:45:15 -04005215func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005216 // TODO(davidben): Extensions, where applicable, all move their server
5217 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5218 // tests for both. Also test interaction with 0-RTT when implemented.
5219
David Benjamin97d17d92016-07-14 16:12:00 -04005220 // Repeat extensions tests all versions except SSL 3.0.
5221 for _, ver := range tlsVersions {
5222 if ver.version == VersionSSL30 {
5223 continue
5224 }
5225
David Benjamin97d17d92016-07-14 16:12:00 -04005226 // Test that duplicate extensions are rejected.
5227 testCases = append(testCases, testCase{
5228 testType: clientTest,
5229 name: "DuplicateExtensionClient-" + ver.name,
5230 config: Config{
5231 MaxVersion: ver.version,
5232 Bugs: ProtocolBugs{
5233 DuplicateExtension: true,
5234 },
David Benjamine78bfde2014-09-06 12:45:15 -04005235 },
David Benjamin97d17d92016-07-14 16:12:00 -04005236 shouldFail: true,
5237 expectedLocalError: "remote error: error decoding message",
5238 })
5239 testCases = append(testCases, testCase{
5240 testType: serverTest,
5241 name: "DuplicateExtensionServer-" + ver.name,
5242 config: Config{
5243 MaxVersion: ver.version,
5244 Bugs: ProtocolBugs{
5245 DuplicateExtension: true,
5246 },
David Benjamine78bfde2014-09-06 12:45:15 -04005247 },
David Benjamin97d17d92016-07-14 16:12:00 -04005248 shouldFail: true,
5249 expectedLocalError: "remote error: error decoding message",
5250 })
5251
5252 // Test SNI.
5253 testCases = append(testCases, testCase{
5254 testType: clientTest,
5255 name: "ServerNameExtensionClient-" + ver.name,
5256 config: Config{
5257 MaxVersion: ver.version,
5258 Bugs: ProtocolBugs{
5259 ExpectServerName: "example.com",
5260 },
David Benjamine78bfde2014-09-06 12:45:15 -04005261 },
David Benjamin97d17d92016-07-14 16:12:00 -04005262 flags: []string{"-host-name", "example.com"},
5263 })
5264 testCases = append(testCases, testCase{
5265 testType: clientTest,
5266 name: "ServerNameExtensionClientMismatch-" + ver.name,
5267 config: Config{
5268 MaxVersion: ver.version,
5269 Bugs: ProtocolBugs{
5270 ExpectServerName: "mismatch.com",
5271 },
David Benjamine78bfde2014-09-06 12:45:15 -04005272 },
David Benjamin97d17d92016-07-14 16:12:00 -04005273 flags: []string{"-host-name", "example.com"},
5274 shouldFail: true,
5275 expectedLocalError: "tls: unexpected server name",
5276 })
5277 testCases = append(testCases, testCase{
5278 testType: clientTest,
5279 name: "ServerNameExtensionClientMissing-" + ver.name,
5280 config: Config{
5281 MaxVersion: ver.version,
5282 Bugs: ProtocolBugs{
5283 ExpectServerName: "missing.com",
5284 },
David Benjamine78bfde2014-09-06 12:45:15 -04005285 },
David Benjamin97d17d92016-07-14 16:12:00 -04005286 shouldFail: true,
5287 expectedLocalError: "tls: unexpected server name",
5288 })
5289 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005290 testType: clientTest,
5291 name: "TolerateServerNameAck-" + ver.name,
5292 config: Config{
5293 MaxVersion: ver.version,
5294 Bugs: ProtocolBugs{
5295 SendServerNameAck: true,
5296 },
5297 },
5298 flags: []string{"-host-name", "example.com"},
5299 resumeSession: true,
5300 })
5301 testCases = append(testCases, testCase{
5302 testType: clientTest,
5303 name: "UnsolicitedServerNameAck-" + ver.name,
5304 config: Config{
5305 MaxVersion: ver.version,
5306 Bugs: ProtocolBugs{
5307 SendServerNameAck: true,
5308 },
5309 },
5310 shouldFail: true,
5311 expectedError: ":UNEXPECTED_EXTENSION:",
5312 expectedLocalError: "remote error: unsupported extension",
5313 })
5314 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005315 testType: serverTest,
5316 name: "ServerNameExtensionServer-" + ver.name,
5317 config: Config{
5318 MaxVersion: ver.version,
5319 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005320 },
David Benjamin97d17d92016-07-14 16:12:00 -04005321 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005322 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005323 })
5324
5325 // Test ALPN.
5326 testCases = append(testCases, testCase{
5327 testType: clientTest,
5328 name: "ALPNClient-" + ver.name,
5329 config: Config{
5330 MaxVersion: ver.version,
5331 NextProtos: []string{"foo"},
5332 },
5333 flags: []string{
5334 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5335 "-expect-alpn", "foo",
5336 },
5337 expectedNextProto: "foo",
5338 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005339 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005340 })
5341 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005342 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005343 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005344 config: Config{
5345 MaxVersion: ver.version,
5346 Bugs: ProtocolBugs{
5347 SendALPN: "baz",
5348 },
5349 },
5350 flags: []string{
5351 "-advertise-alpn", "\x03foo\x03bar",
5352 },
5353 shouldFail: true,
5354 expectedError: ":INVALID_ALPN_PROTOCOL:",
5355 expectedLocalError: "remote error: illegal parameter",
5356 })
5357 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005358 testType: clientTest,
5359 name: "ALPNClient-AllowUnknown-" + ver.name,
5360 config: Config{
5361 MaxVersion: ver.version,
5362 Bugs: ProtocolBugs{
5363 SendALPN: "baz",
5364 },
5365 },
5366 flags: []string{
5367 "-advertise-alpn", "\x03foo\x03bar",
5368 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005369 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005370 },
5371 })
5372 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005373 testType: serverTest,
5374 name: "ALPNServer-" + ver.name,
5375 config: Config{
5376 MaxVersion: ver.version,
5377 NextProtos: []string{"foo", "bar", "baz"},
5378 },
5379 flags: []string{
5380 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5381 "-select-alpn", "foo",
5382 },
5383 expectedNextProto: "foo",
5384 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005385 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005386 })
5387 testCases = append(testCases, testCase{
5388 testType: serverTest,
5389 name: "ALPNServer-Decline-" + ver.name,
5390 config: Config{
5391 MaxVersion: ver.version,
5392 NextProtos: []string{"foo", "bar", "baz"},
5393 },
5394 flags: []string{"-decline-alpn"},
5395 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005396 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005397 })
5398
David Benjamin25fe85b2016-08-09 20:00:32 -04005399 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5400 // called once.
5401 testCases = append(testCases, testCase{
5402 testType: serverTest,
5403 name: "ALPNServer-Async-" + ver.name,
5404 config: Config{
5405 MaxVersion: ver.version,
5406 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005407 // Prior to TLS 1.3, exercise the asynchronous session callback.
5408 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005409 },
5410 flags: []string{
5411 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5412 "-select-alpn", "foo",
5413 "-async",
5414 },
5415 expectedNextProto: "foo",
5416 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005417 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005418 })
5419
David Benjamin97d17d92016-07-14 16:12:00 -04005420 var emptyString string
5421 testCases = append(testCases, testCase{
5422 testType: clientTest,
5423 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5424 config: Config{
5425 MaxVersion: ver.version,
5426 NextProtos: []string{""},
5427 Bugs: ProtocolBugs{
5428 // A server returning an empty ALPN protocol
5429 // should be rejected.
5430 ALPNProtocol: &emptyString,
5431 },
5432 },
5433 flags: []string{
5434 "-advertise-alpn", "\x03foo",
5435 },
5436 shouldFail: true,
5437 expectedError: ":PARSE_TLSEXT:",
5438 })
5439 testCases = append(testCases, testCase{
5440 testType: serverTest,
5441 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5442 config: Config{
5443 MaxVersion: ver.version,
5444 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005445 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005446 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005447 },
David Benjamin97d17d92016-07-14 16:12:00 -04005448 flags: []string{
5449 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005450 },
David Benjamin97d17d92016-07-14 16:12:00 -04005451 shouldFail: true,
5452 expectedError: ":PARSE_TLSEXT:",
5453 })
5454
5455 // Test NPN and the interaction with ALPN.
5456 if ver.version < VersionTLS13 {
5457 // Test that the server prefers ALPN over NPN.
5458 testCases = append(testCases, testCase{
5459 testType: serverTest,
5460 name: "ALPNServer-Preferred-" + ver.name,
5461 config: Config{
5462 MaxVersion: ver.version,
5463 NextProtos: []string{"foo", "bar", "baz"},
5464 },
5465 flags: []string{
5466 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5467 "-select-alpn", "foo",
5468 "-advertise-npn", "\x03foo\x03bar\x03baz",
5469 },
5470 expectedNextProto: "foo",
5471 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005472 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005473 })
5474 testCases = append(testCases, testCase{
5475 testType: serverTest,
5476 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5477 config: Config{
5478 MaxVersion: ver.version,
5479 NextProtos: []string{"foo", "bar", "baz"},
5480 Bugs: ProtocolBugs{
5481 SwapNPNAndALPN: true,
5482 },
5483 },
5484 flags: []string{
5485 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5486 "-select-alpn", "foo",
5487 "-advertise-npn", "\x03foo\x03bar\x03baz",
5488 },
5489 expectedNextProto: "foo",
5490 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005491 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005492 })
5493
5494 // Test that negotiating both NPN and ALPN is forbidden.
5495 testCases = append(testCases, testCase{
5496 name: "NegotiateALPNAndNPN-" + ver.name,
5497 config: Config{
5498 MaxVersion: ver.version,
5499 NextProtos: []string{"foo", "bar", "baz"},
5500 Bugs: ProtocolBugs{
5501 NegotiateALPNAndNPN: true,
5502 },
5503 },
5504 flags: []string{
5505 "-advertise-alpn", "\x03foo",
5506 "-select-next-proto", "foo",
5507 },
5508 shouldFail: true,
5509 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5510 })
5511 testCases = append(testCases, testCase{
5512 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5513 config: Config{
5514 MaxVersion: ver.version,
5515 NextProtos: []string{"foo", "bar", "baz"},
5516 Bugs: ProtocolBugs{
5517 NegotiateALPNAndNPN: true,
5518 SwapNPNAndALPN: true,
5519 },
5520 },
5521 flags: []string{
5522 "-advertise-alpn", "\x03foo",
5523 "-select-next-proto", "foo",
5524 },
5525 shouldFail: true,
5526 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5527 })
David Benjamin97d17d92016-07-14 16:12:00 -04005528 }
5529
5530 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005531
5532 // Resume with a corrupt ticket.
5533 testCases = append(testCases, testCase{
5534 testType: serverTest,
5535 name: "CorruptTicket-" + ver.name,
5536 config: Config{
5537 MaxVersion: ver.version,
5538 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005539 FilterTicket: func(in []byte) ([]byte, error) {
5540 in[len(in)-1] ^= 1
5541 return in, nil
5542 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005543 },
5544 },
5545 resumeSession: true,
5546 expectResumeRejected: true,
5547 })
5548 // Test the ticket callback, with and without renewal.
5549 testCases = append(testCases, testCase{
5550 testType: serverTest,
5551 name: "TicketCallback-" + ver.name,
5552 config: Config{
5553 MaxVersion: ver.version,
5554 },
5555 resumeSession: true,
5556 flags: []string{"-use-ticket-callback"},
5557 })
5558 testCases = append(testCases, testCase{
5559 testType: serverTest,
5560 name: "TicketCallback-Renew-" + ver.name,
5561 config: Config{
5562 MaxVersion: ver.version,
5563 Bugs: ProtocolBugs{
5564 ExpectNewTicket: true,
5565 },
5566 },
5567 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5568 resumeSession: true,
5569 })
5570
5571 // Test that the ticket callback is only called once when everything before
5572 // it in the ClientHello is asynchronous. This corrupts the ticket so
5573 // certificate selection callbacks run.
5574 testCases = append(testCases, testCase{
5575 testType: serverTest,
5576 name: "TicketCallback-SingleCall-" + ver.name,
5577 config: Config{
5578 MaxVersion: ver.version,
5579 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005580 FilterTicket: func(in []byte) ([]byte, error) {
5581 in[len(in)-1] ^= 1
5582 return in, nil
5583 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005584 },
5585 },
5586 resumeSession: true,
5587 expectResumeRejected: true,
5588 flags: []string{
5589 "-use-ticket-callback",
5590 "-async",
5591 },
5592 })
5593
David Benjamind4c349b2017-02-09 14:07:17 -05005594 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005595 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005596 testCases = append(testCases, testCase{
5597 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005598 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005599 config: Config{
5600 MaxVersion: ver.version,
5601 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005602 EmptyTicketSessionID: true,
5603 },
5604 },
5605 resumeSession: true,
5606 })
5607 testCases = append(testCases, testCase{
5608 testType: serverTest,
5609 name: "TicketSessionIDLength-16-" + ver.name,
5610 config: Config{
5611 MaxVersion: ver.version,
5612 Bugs: ProtocolBugs{
5613 TicketSessionIDLength: 16,
5614 },
5615 },
5616 resumeSession: true,
5617 })
5618 testCases = append(testCases, testCase{
5619 testType: serverTest,
5620 name: "TicketSessionIDLength-32-" + ver.name,
5621 config: Config{
5622 MaxVersion: ver.version,
5623 Bugs: ProtocolBugs{
5624 TicketSessionIDLength: 32,
5625 },
5626 },
5627 resumeSession: true,
5628 })
5629 testCases = append(testCases, testCase{
5630 testType: serverTest,
5631 name: "TicketSessionIDLength-33-" + ver.name,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 Bugs: ProtocolBugs{
5635 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005636 },
5637 },
5638 resumeSession: true,
5639 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005640 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005641 expectedError: ":DECODE_ERROR:",
5642 })
5643 }
5644
5645 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5646 // are ignored.
5647 if ver.hasDTLS {
5648 testCases = append(testCases, testCase{
5649 protocol: dtls,
5650 name: "SRTP-Client-" + ver.name,
5651 config: Config{
5652 MaxVersion: ver.version,
5653 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5654 },
5655 flags: []string{
5656 "-srtp-profiles",
5657 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5658 },
5659 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5660 })
5661 testCases = append(testCases, testCase{
5662 protocol: dtls,
5663 testType: serverTest,
5664 name: "SRTP-Server-" + ver.name,
5665 config: Config{
5666 MaxVersion: ver.version,
5667 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5668 },
5669 flags: []string{
5670 "-srtp-profiles",
5671 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5672 },
5673 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5674 })
5675 // Test that the MKI is ignored.
5676 testCases = append(testCases, testCase{
5677 protocol: dtls,
5678 testType: serverTest,
5679 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5680 config: Config{
5681 MaxVersion: ver.version,
5682 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5683 Bugs: ProtocolBugs{
5684 SRTPMasterKeyIdentifer: "bogus",
5685 },
5686 },
5687 flags: []string{
5688 "-srtp-profiles",
5689 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5690 },
5691 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5692 })
5693 // Test that SRTP isn't negotiated on the server if there were
5694 // no matching profiles.
5695 testCases = append(testCases, testCase{
5696 protocol: dtls,
5697 testType: serverTest,
5698 name: "SRTP-Server-NoMatch-" + ver.name,
5699 config: Config{
5700 MaxVersion: ver.version,
5701 SRTPProtectionProfiles: []uint16{100, 101, 102},
5702 },
5703 flags: []string{
5704 "-srtp-profiles",
5705 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5706 },
5707 expectedSRTPProtectionProfile: 0,
5708 })
5709 // Test that the server returning an invalid SRTP profile is
5710 // flagged as an error by the client.
5711 testCases = append(testCases, testCase{
5712 protocol: dtls,
5713 name: "SRTP-Client-NoMatch-" + ver.name,
5714 config: Config{
5715 MaxVersion: ver.version,
5716 Bugs: ProtocolBugs{
5717 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5718 },
5719 },
5720 flags: []string{
5721 "-srtp-profiles",
5722 "SRTP_AES128_CM_SHA1_80",
5723 },
5724 shouldFail: true,
5725 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5726 })
5727 }
5728
5729 // Test SCT list.
5730 testCases = append(testCases, testCase{
5731 name: "SignedCertificateTimestampList-Client-" + ver.name,
5732 testType: clientTest,
5733 config: Config{
5734 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005735 },
David Benjamin97d17d92016-07-14 16:12:00 -04005736 flags: []string{
5737 "-enable-signed-cert-timestamps",
5738 "-expect-signed-cert-timestamps",
5739 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005740 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005741 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005742 })
David Benjamindaa88502016-10-04 16:32:16 -04005743
Adam Langleycfa08c32016-11-17 13:21:27 -08005744 var differentSCTList []byte
5745 differentSCTList = append(differentSCTList, testSCTList...)
5746 differentSCTList[len(differentSCTList)-1] ^= 1
5747
David Benjamindaa88502016-10-04 16:32:16 -04005748 // The SCT extension did not specify that it must only be sent on resumption as it
5749 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005750 testCases = append(testCases, testCase{
5751 name: "SendSCTListOnResume-" + ver.name,
5752 config: Config{
5753 MaxVersion: ver.version,
5754 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005755 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005756 },
David Benjamind98452d2015-06-16 14:16:23 -04005757 },
David Benjamin97d17d92016-07-14 16:12:00 -04005758 flags: []string{
5759 "-enable-signed-cert-timestamps",
5760 "-expect-signed-cert-timestamps",
5761 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005762 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005763 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005764 })
David Benjamindaa88502016-10-04 16:32:16 -04005765
David Benjamin97d17d92016-07-14 16:12:00 -04005766 testCases = append(testCases, testCase{
5767 name: "SignedCertificateTimestampList-Server-" + ver.name,
5768 testType: serverTest,
5769 config: Config{
5770 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005771 },
David Benjamin97d17d92016-07-14 16:12:00 -04005772 flags: []string{
5773 "-signed-cert-timestamps",
5774 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005775 },
David Benjamin97d17d92016-07-14 16:12:00 -04005776 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005777 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005778 })
David Benjamin53210cb2016-11-16 09:01:48 +09005779
Adam Langleycfa08c32016-11-17 13:21:27 -08005780 emptySCTListCert := *testCerts[0].cert
5781 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5782
5783 // Test empty SCT list.
5784 testCases = append(testCases, testCase{
5785 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5786 testType: clientTest,
5787 config: Config{
5788 MaxVersion: ver.version,
5789 Certificates: []Certificate{emptySCTListCert},
5790 },
5791 flags: []string{
5792 "-enable-signed-cert-timestamps",
5793 },
5794 shouldFail: true,
5795 expectedError: ":ERROR_PARSING_EXTENSION:",
5796 })
5797
5798 emptySCTCert := *testCerts[0].cert
5799 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5800
5801 // Test empty SCT in non-empty list.
5802 testCases = append(testCases, testCase{
5803 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5804 testType: clientTest,
5805 config: Config{
5806 MaxVersion: ver.version,
5807 Certificates: []Certificate{emptySCTCert},
5808 },
5809 flags: []string{
5810 "-enable-signed-cert-timestamps",
5811 },
5812 shouldFail: true,
5813 expectedError: ":ERROR_PARSING_EXTENSION:",
5814 })
5815
David Benjamin53210cb2016-11-16 09:01:48 +09005816 // Test that certificate-related extensions are not sent unsolicited.
5817 testCases = append(testCases, testCase{
5818 testType: serverTest,
5819 name: "UnsolicitedCertificateExtensions-" + ver.name,
5820 config: Config{
5821 MaxVersion: ver.version,
5822 Bugs: ProtocolBugs{
5823 NoOCSPStapling: true,
5824 NoSignedCertificateTimestamps: true,
5825 },
5826 },
5827 flags: []string{
5828 "-ocsp-response",
5829 base64.StdEncoding.EncodeToString(testOCSPResponse),
5830 "-signed-cert-timestamps",
5831 base64.StdEncoding.EncodeToString(testSCTList),
5832 },
5833 })
David Benjamin97d17d92016-07-14 16:12:00 -04005834 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005835
Paul Lietar4fac72e2015-09-09 13:44:55 +01005836 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005837 testType: clientTest,
5838 name: "ClientHelloPadding",
5839 config: Config{
5840 Bugs: ProtocolBugs{
5841 RequireClientHelloSize: 512,
5842 },
5843 },
5844 // This hostname just needs to be long enough to push the
5845 // ClientHello into F5's danger zone between 256 and 511 bytes
5846 // long.
5847 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5848 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005849
5850 // Extensions should not function in SSL 3.0.
5851 testCases = append(testCases, testCase{
5852 testType: serverTest,
5853 name: "SSLv3Extensions-NoALPN",
5854 config: Config{
5855 MaxVersion: VersionSSL30,
5856 NextProtos: []string{"foo", "bar", "baz"},
5857 },
5858 flags: []string{
5859 "-select-alpn", "foo",
5860 },
5861 expectNoNextProto: true,
5862 })
5863
5864 // Test session tickets separately as they follow a different codepath.
5865 testCases = append(testCases, testCase{
5866 testType: serverTest,
5867 name: "SSLv3Extensions-NoTickets",
5868 config: Config{
5869 MaxVersion: VersionSSL30,
5870 Bugs: ProtocolBugs{
5871 // Historically, session tickets in SSL 3.0
5872 // failed in different ways depending on whether
5873 // the client supported renegotiation_info.
5874 NoRenegotiationInfo: true,
5875 },
5876 },
5877 resumeSession: true,
5878 })
5879 testCases = append(testCases, testCase{
5880 testType: serverTest,
5881 name: "SSLv3Extensions-NoTickets2",
5882 config: Config{
5883 MaxVersion: VersionSSL30,
5884 },
5885 resumeSession: true,
5886 })
5887
5888 // But SSL 3.0 does send and process renegotiation_info.
5889 testCases = append(testCases, testCase{
5890 testType: serverTest,
5891 name: "SSLv3Extensions-RenegotiationInfo",
5892 config: Config{
5893 MaxVersion: VersionSSL30,
5894 Bugs: ProtocolBugs{
5895 RequireRenegotiationInfo: true,
5896 },
5897 },
David Benjamind2610042017-01-03 10:49:28 -05005898 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005899 })
5900 testCases = append(testCases, testCase{
5901 testType: serverTest,
5902 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5903 config: Config{
5904 MaxVersion: VersionSSL30,
5905 Bugs: ProtocolBugs{
5906 NoRenegotiationInfo: true,
5907 SendRenegotiationSCSV: true,
5908 RequireRenegotiationInfo: true,
5909 },
5910 },
David Benjamind2610042017-01-03 10:49:28 -05005911 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005912 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005913
5914 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5915 // in ServerHello.
5916 testCases = append(testCases, testCase{
5917 name: "NPN-Forbidden-TLS13",
5918 config: Config{
5919 MaxVersion: VersionTLS13,
5920 NextProtos: []string{"foo"},
5921 Bugs: ProtocolBugs{
5922 NegotiateNPNAtAllVersions: true,
5923 },
5924 },
5925 flags: []string{"-select-next-proto", "foo"},
5926 shouldFail: true,
5927 expectedError: ":ERROR_PARSING_EXTENSION:",
5928 })
5929 testCases = append(testCases, testCase{
5930 name: "EMS-Forbidden-TLS13",
5931 config: Config{
5932 MaxVersion: VersionTLS13,
5933 Bugs: ProtocolBugs{
5934 NegotiateEMSAtAllVersions: true,
5935 },
5936 },
5937 shouldFail: true,
5938 expectedError: ":ERROR_PARSING_EXTENSION:",
5939 })
5940 testCases = append(testCases, testCase{
5941 name: "RenegotiationInfo-Forbidden-TLS13",
5942 config: Config{
5943 MaxVersion: VersionTLS13,
5944 Bugs: ProtocolBugs{
5945 NegotiateRenegotiationInfoAtAllVersions: true,
5946 },
5947 },
5948 shouldFail: true,
5949 expectedError: ":ERROR_PARSING_EXTENSION:",
5950 })
5951 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005952 name: "Ticket-Forbidden-TLS13",
5953 config: Config{
5954 MaxVersion: VersionTLS12,
5955 },
5956 resumeConfig: &Config{
5957 MaxVersion: VersionTLS13,
5958 Bugs: ProtocolBugs{
5959 AdvertiseTicketExtension: true,
5960 },
5961 },
5962 resumeSession: true,
5963 shouldFail: true,
5964 expectedError: ":ERROR_PARSING_EXTENSION:",
5965 })
5966
5967 // Test that illegal extensions in TLS 1.3 are declined by the server if
5968 // offered in ClientHello. The runner's server will fail if this occurs,
5969 // so we exercise the offering path. (EMS and Renegotiation Info are
5970 // implicit in every test.)
5971 testCases = append(testCases, testCase{
5972 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005973 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005974 config: Config{
5975 MaxVersion: VersionTLS13,
5976 NextProtos: []string{"bar"},
5977 },
5978 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5979 })
David Benjamin196df5b2016-09-21 16:23:27 -04005980
David Benjamindaa88502016-10-04 16:32:16 -04005981 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5982 // tolerated.
5983 testCases = append(testCases, testCase{
5984 name: "SendOCSPResponseOnResume-TLS12",
5985 config: Config{
5986 MaxVersion: VersionTLS12,
5987 Bugs: ProtocolBugs{
5988 SendOCSPResponseOnResume: []byte("bogus"),
5989 },
5990 },
5991 flags: []string{
5992 "-enable-ocsp-stapling",
5993 "-expect-ocsp-response",
5994 base64.StdEncoding.EncodeToString(testOCSPResponse),
5995 },
5996 resumeSession: true,
5997 })
5998
David Benjamindaa88502016-10-04 16:32:16 -04005999 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006000 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006001 config: Config{
6002 MaxVersion: VersionTLS13,
6003 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006004 SendExtensionOnCertificate: testOCSPExtension,
6005 },
6006 },
6007 shouldFail: true,
6008 expectedError: ":UNEXPECTED_EXTENSION:",
6009 })
6010
6011 testCases = append(testCases, testCase{
6012 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6013 config: Config{
6014 MaxVersion: VersionTLS13,
6015 Bugs: ProtocolBugs{
6016 SendExtensionOnCertificate: testSCTExtension,
6017 },
6018 },
6019 shouldFail: true,
6020 expectedError: ":UNEXPECTED_EXTENSION:",
6021 })
6022
6023 // Test that extensions on client certificates are never accepted.
6024 testCases = append(testCases, testCase{
6025 name: "SendExtensionOnClientCertificate-TLS13",
6026 testType: serverTest,
6027 config: Config{
6028 MaxVersion: VersionTLS13,
6029 Certificates: []Certificate{rsaCertificate},
6030 Bugs: ProtocolBugs{
6031 SendExtensionOnCertificate: testOCSPExtension,
6032 },
6033 },
6034 flags: []string{
6035 "-enable-ocsp-stapling",
6036 "-require-any-client-certificate",
6037 },
6038 shouldFail: true,
6039 expectedError: ":UNEXPECTED_EXTENSION:",
6040 })
6041
6042 testCases = append(testCases, testCase{
6043 name: "SendUnknownExtensionOnCertificate-TLS13",
6044 config: Config{
6045 MaxVersion: VersionTLS13,
6046 Bugs: ProtocolBugs{
6047 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6048 },
6049 },
6050 shouldFail: true,
6051 expectedError: ":UNEXPECTED_EXTENSION:",
6052 })
6053
Adam Langleycfa08c32016-11-17 13:21:27 -08006054 var differentSCTList []byte
6055 differentSCTList = append(differentSCTList, testSCTList...)
6056 differentSCTList[len(differentSCTList)-1] ^= 1
6057
Steven Valdeza833c352016-11-01 13:39:36 -04006058 // Test that extensions on intermediates are allowed but ignored.
6059 testCases = append(testCases, testCase{
6060 name: "IgnoreExtensionsOnIntermediates-TLS13",
6061 config: Config{
6062 MaxVersion: VersionTLS13,
6063 Certificates: []Certificate{rsaChainCertificate},
6064 Bugs: ProtocolBugs{
6065 // Send different values on the intermediate. This tests
6066 // the intermediate's extensions do not override the
6067 // leaf's.
6068 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006069 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006070 },
6071 },
6072 flags: []string{
6073 "-enable-ocsp-stapling",
6074 "-expect-ocsp-response",
6075 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006076 "-enable-signed-cert-timestamps",
6077 "-expect-signed-cert-timestamps",
6078 base64.StdEncoding.EncodeToString(testSCTList),
6079 },
6080 resumeSession: true,
6081 })
6082
6083 // Test that extensions are not sent on intermediates when configured
6084 // only for a leaf.
6085 testCases = append(testCases, testCase{
6086 testType: serverTest,
6087 name: "SendNoExtensionsOnIntermediate-TLS13",
6088 config: Config{
6089 MaxVersion: VersionTLS13,
6090 Bugs: ProtocolBugs{
6091 ExpectNoExtensionsOnIntermediate: true,
6092 },
6093 },
6094 flags: []string{
6095 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6096 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6097 "-ocsp-response",
6098 base64.StdEncoding.EncodeToString(testOCSPResponse),
6099 "-signed-cert-timestamps",
6100 base64.StdEncoding.EncodeToString(testSCTList),
6101 },
6102 })
6103
6104 // Test that extensions are not sent on client certificates.
6105 testCases = append(testCases, testCase{
6106 name: "SendNoClientCertificateExtensions-TLS13",
6107 config: Config{
6108 MaxVersion: VersionTLS13,
6109 ClientAuth: RequireAnyClientCert,
6110 },
6111 flags: []string{
6112 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6113 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6114 "-ocsp-response",
6115 base64.StdEncoding.EncodeToString(testOCSPResponse),
6116 "-signed-cert-timestamps",
6117 base64.StdEncoding.EncodeToString(testSCTList),
6118 },
6119 })
6120
6121 testCases = append(testCases, testCase{
6122 name: "SendDuplicateExtensionsOnCerts-TLS13",
6123 config: Config{
6124 MaxVersion: VersionTLS13,
6125 Bugs: ProtocolBugs{
6126 SendDuplicateCertExtensions: true,
6127 },
6128 },
6129 flags: []string{
6130 "-enable-ocsp-stapling",
6131 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006132 },
6133 resumeSession: true,
6134 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006135 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006136 })
Adam Langley9b885c52016-11-18 14:21:03 -08006137
6138 testCases = append(testCases, testCase{
6139 name: "SignedCertificateTimestampListInvalid-Server",
6140 testType: serverTest,
6141 flags: []string{
6142 "-signed-cert-timestamps",
6143 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6144 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006145 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006146 expectedError: ":INVALID_SCT_LIST:",
6147 })
David Benjamine78bfde2014-09-06 12:45:15 -04006148}
6149
David Benjamin01fe8202014-09-24 15:21:44 -04006150func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006151 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006152 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006153 // SSL 3.0 does not have tickets and TLS 1.3 does not
6154 // have session IDs, so skip their cross-resumption
6155 // tests.
6156 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6157 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6158 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006159 }
6160
David Benjamin8b8c0062014-11-23 02:47:52 -05006161 protocols := []protocol{tls}
6162 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6163 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006164 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006165 for _, protocol := range protocols {
6166 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6167 if protocol == dtls {
6168 suffix += "-DTLS"
6169 }
6170
David Benjaminece3de92015-03-16 18:02:20 -04006171 if sessionVers.version == resumeVers.version {
6172 testCases = append(testCases, testCase{
6173 protocol: protocol,
6174 name: "Resume-Client" + suffix,
6175 resumeSession: true,
6176 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006177 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006178 Bugs: ProtocolBugs{
6179 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6180 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6181 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006182 },
David Benjaminece3de92015-03-16 18:02:20 -04006183 expectedVersion: sessionVers.version,
6184 expectedResumeVersion: resumeVers.version,
6185 })
6186 } else {
David Benjamin405da482016-08-08 17:25:07 -04006187 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6188
6189 // Offering a TLS 1.3 session sends an empty session ID, so
6190 // there is no way to convince a non-lookahead client the
6191 // session was resumed. It will appear to the client that a
6192 // stray ChangeCipherSpec was sent.
6193 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6194 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006195 }
6196
David Benjaminece3de92015-03-16 18:02:20 -04006197 testCases = append(testCases, testCase{
6198 protocol: protocol,
6199 name: "Resume-Client-Mismatch" + suffix,
6200 resumeSession: true,
6201 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006202 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006203 },
David Benjaminece3de92015-03-16 18:02:20 -04006204 expectedVersion: sessionVers.version,
6205 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006206 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006207 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006208 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006209 },
6210 },
6211 expectedResumeVersion: resumeVers.version,
6212 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006213 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006214 })
6215 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006216
6217 testCases = append(testCases, testCase{
6218 protocol: protocol,
6219 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006220 resumeSession: true,
6221 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006222 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006223 },
6224 expectedVersion: sessionVers.version,
6225 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006226 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006227 },
6228 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006229 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006230 expectedResumeVersion: resumeVers.version,
6231 })
6232
David Benjamin8b8c0062014-11-23 02:47:52 -05006233 testCases = append(testCases, testCase{
6234 protocol: protocol,
6235 testType: serverTest,
6236 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006237 resumeSession: true,
6238 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006239 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006240 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006241 expectedVersion: sessionVers.version,
6242 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006243 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006244 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006245 Bugs: ProtocolBugs{
6246 SendBothTickets: true,
6247 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006248 },
6249 expectedResumeVersion: resumeVers.version,
6250 })
6251 }
David Benjamin01fe8202014-09-24 15:21:44 -04006252 }
6253 }
David Benjaminece3de92015-03-16 18:02:20 -04006254
David Benjamin4199b0d2016-11-01 13:58:25 -04006255 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006256 testCases = append(testCases, testCase{
6257 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006258 name: "ShimTicketRewritable",
6259 resumeSession: true,
6260 config: Config{
6261 MaxVersion: VersionTLS12,
6262 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6263 Bugs: ProtocolBugs{
6264 FilterTicket: func(in []byte) ([]byte, error) {
6265 in, err := SetShimTicketVersion(in, VersionTLS12)
6266 if err != nil {
6267 return nil, err
6268 }
6269 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6270 },
6271 },
6272 },
6273 flags: []string{
6274 "-ticket-key",
6275 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6276 },
6277 })
6278
6279 // Resumptions are declined if the version does not match.
6280 testCases = append(testCases, testCase{
6281 testType: serverTest,
6282 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006283 resumeSession: true,
6284 config: Config{
6285 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006286 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006287 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006288 FilterTicket: func(in []byte) ([]byte, error) {
6289 return SetShimTicketVersion(in, VersionTLS13)
6290 },
6291 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006292 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006293 flags: []string{
6294 "-ticket-key",
6295 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6296 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006297 expectResumeRejected: true,
6298 })
6299
6300 testCases = append(testCases, testCase{
6301 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006302 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006303 resumeSession: true,
6304 config: Config{
6305 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006306 Bugs: ProtocolBugs{
6307 FilterTicket: func(in []byte) ([]byte, error) {
6308 return SetShimTicketVersion(in, VersionTLS12)
6309 },
6310 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006311 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006312 flags: []string{
6313 "-ticket-key",
6314 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6315 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006316 expectResumeRejected: true,
6317 })
6318
David Benjamin4199b0d2016-11-01 13:58:25 -04006319 // Resumptions are declined if the cipher is invalid or disabled.
6320 testCases = append(testCases, testCase{
6321 testType: serverTest,
6322 name: "Resume-Server-DeclineBadCipher",
6323 resumeSession: true,
6324 config: Config{
6325 MaxVersion: VersionTLS12,
6326 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006327 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006328 FilterTicket: func(in []byte) ([]byte, error) {
6329 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6330 },
6331 },
6332 },
6333 flags: []string{
6334 "-ticket-key",
6335 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6336 },
6337 expectResumeRejected: true,
6338 })
6339
6340 testCases = append(testCases, testCase{
6341 testType: serverTest,
6342 name: "Resume-Server-DeclineBadCipher-2",
6343 resumeSession: true,
6344 config: Config{
6345 MaxVersion: VersionTLS12,
6346 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006347 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006348 FilterTicket: func(in []byte) ([]byte, error) {
6349 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6350 },
6351 },
6352 },
6353 flags: []string{
6354 "-cipher", "AES128",
6355 "-ticket-key",
6356 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6357 },
6358 expectResumeRejected: true,
6359 })
6360
David Benjaminf01f42a2016-11-16 19:05:33 +09006361 // Sessions are not resumed if they do not use the preferred cipher.
6362 testCases = append(testCases, testCase{
6363 testType: serverTest,
6364 name: "Resume-Server-CipherNotPreferred",
6365 resumeSession: true,
6366 config: Config{
6367 MaxVersion: VersionTLS12,
6368 Bugs: ProtocolBugs{
6369 ExpectNewTicket: true,
6370 FilterTicket: func(in []byte) ([]byte, error) {
6371 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6372 },
6373 },
6374 },
6375 flags: []string{
6376 "-ticket-key",
6377 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6378 },
6379 shouldFail: false,
6380 expectResumeRejected: true,
6381 })
6382
6383 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6384 // PRF hashes match, but BoringSSL will always decline such resumptions.
6385 testCases = append(testCases, testCase{
6386 testType: serverTest,
6387 name: "Resume-Server-CipherNotPreferred-TLS13",
6388 resumeSession: true,
6389 config: Config{
6390 MaxVersion: VersionTLS13,
6391 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6392 Bugs: ProtocolBugs{
6393 FilterTicket: func(in []byte) ([]byte, error) {
6394 // If the client (runner) offers ChaCha20-Poly1305 first, the
6395 // server (shim) always prefers it. Switch it to AES-GCM.
6396 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6397 },
6398 },
6399 },
6400 flags: []string{
6401 "-ticket-key",
6402 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6403 },
6404 shouldFail: false,
6405 expectResumeRejected: true,
6406 })
6407
6408 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006409 testCases = append(testCases, testCase{
6410 testType: serverTest,
6411 name: "Resume-Server-DeclineBadCipher-TLS13",
6412 resumeSession: true,
6413 config: Config{
6414 MaxVersion: VersionTLS13,
6415 Bugs: ProtocolBugs{
6416 FilterTicket: func(in []byte) ([]byte, error) {
6417 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6418 },
6419 },
6420 },
6421 flags: []string{
6422 "-ticket-key",
6423 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6424 },
6425 expectResumeRejected: true,
6426 })
6427
David Benjaminf01f42a2016-11-16 19:05:33 +09006428 // If the client does not offer the cipher from the session, decline to
6429 // resume. Clients are forbidden from doing this, but BoringSSL selects
6430 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006431 testCases = append(testCases, testCase{
6432 testType: serverTest,
6433 name: "Resume-Server-UnofferedCipher",
6434 resumeSession: true,
6435 config: Config{
6436 MaxVersion: VersionTLS12,
6437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6438 },
6439 resumeConfig: &Config{
6440 MaxVersion: VersionTLS12,
6441 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6442 Bugs: ProtocolBugs{
6443 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6444 },
6445 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006446 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006447 })
6448
David Benjaminf01f42a2016-11-16 19:05:33 +09006449 // In TLS 1.3, clients may advertise a cipher list which does not
6450 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006451 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6452 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006453 testCases = append(testCases, testCase{
6454 testType: serverTest,
6455 name: "Resume-Server-UnofferedCipher-TLS13",
6456 resumeSession: true,
6457 config: Config{
6458 MaxVersion: VersionTLS13,
6459 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6460 },
6461 resumeConfig: &Config{
6462 MaxVersion: VersionTLS13,
6463 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6464 Bugs: ProtocolBugs{
6465 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6466 },
6467 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006468 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006469 })
6470
David Benjamin4199b0d2016-11-01 13:58:25 -04006471 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006472 testCases = append(testCases, testCase{
6473 name: "Resume-Client-CipherMismatch",
6474 resumeSession: true,
6475 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006476 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006477 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6478 },
6479 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006480 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006481 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6482 Bugs: ProtocolBugs{
6483 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6484 },
6485 },
6486 shouldFail: true,
6487 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6488 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006489
David Benjamine1cc35e2016-11-16 16:25:58 +09006490 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6491 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006492 testCases = append(testCases, testCase{
6493 name: "Resume-Client-CipherMismatch-TLS13",
6494 resumeSession: true,
6495 config: Config{
6496 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006497 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006498 },
6499 resumeConfig: &Config{
6500 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006501 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6502 },
6503 })
6504
6505 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6506 testCases = append(testCases, testCase{
6507 name: "Resume-Client-PRFMismatch-TLS13",
6508 resumeSession: true,
6509 config: Config{
6510 MaxVersion: VersionTLS13,
6511 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6512 },
6513 resumeConfig: &Config{
6514 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006515 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006516 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006517 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006518 },
6519 },
6520 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006521 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006522 })
Steven Valdeza833c352016-11-01 13:39:36 -04006523
6524 testCases = append(testCases, testCase{
6525 testType: serverTest,
6526 name: "Resume-Server-BinderWrongLength",
6527 resumeSession: true,
6528 config: Config{
6529 MaxVersion: VersionTLS13,
6530 Bugs: ProtocolBugs{
6531 SendShortPSKBinder: true,
6532 },
6533 },
6534 shouldFail: true,
6535 expectedLocalError: "remote error: error decrypting message",
6536 expectedError: ":DIGEST_CHECK_FAILED:",
6537 })
6538
6539 testCases = append(testCases, testCase{
6540 testType: serverTest,
6541 name: "Resume-Server-NoPSKBinder",
6542 resumeSession: true,
6543 config: Config{
6544 MaxVersion: VersionTLS13,
6545 Bugs: ProtocolBugs{
6546 SendNoPSKBinder: true,
6547 },
6548 },
6549 shouldFail: true,
6550 expectedLocalError: "remote error: error decoding message",
6551 expectedError: ":DECODE_ERROR:",
6552 })
6553
6554 testCases = append(testCases, testCase{
6555 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006556 name: "Resume-Server-ExtraPSKBinder",
6557 resumeSession: true,
6558 config: Config{
6559 MaxVersion: VersionTLS13,
6560 Bugs: ProtocolBugs{
6561 SendExtraPSKBinder: true,
6562 },
6563 },
6564 shouldFail: true,
6565 expectedLocalError: "remote error: illegal parameter",
6566 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6567 })
6568
6569 testCases = append(testCases, testCase{
6570 testType: serverTest,
6571 name: "Resume-Server-ExtraIdentityNoBinder",
6572 resumeSession: true,
6573 config: Config{
6574 MaxVersion: VersionTLS13,
6575 Bugs: ProtocolBugs{
6576 ExtraPSKIdentity: true,
6577 },
6578 },
6579 shouldFail: true,
6580 expectedLocalError: "remote error: illegal parameter",
6581 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6582 })
6583
6584 testCases = append(testCases, testCase{
6585 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006586 name: "Resume-Server-InvalidPSKBinder",
6587 resumeSession: true,
6588 config: Config{
6589 MaxVersion: VersionTLS13,
6590 Bugs: ProtocolBugs{
6591 SendInvalidPSKBinder: true,
6592 },
6593 },
6594 shouldFail: true,
6595 expectedLocalError: "remote error: error decrypting message",
6596 expectedError: ":DIGEST_CHECK_FAILED:",
6597 })
6598
6599 testCases = append(testCases, testCase{
6600 testType: serverTest,
6601 name: "Resume-Server-PSKBinderFirstExtension",
6602 resumeSession: true,
6603 config: Config{
6604 MaxVersion: VersionTLS13,
6605 Bugs: ProtocolBugs{
6606 PSKBinderFirst: true,
6607 },
6608 },
6609 shouldFail: true,
6610 expectedLocalError: "remote error: illegal parameter",
6611 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6612 })
David Benjamin01fe8202014-09-24 15:21:44 -04006613}
6614
Adam Langley2ae77d22014-10-28 17:29:33 -07006615func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006616 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006617 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006618 testType: serverTest,
6619 name: "Renegotiate-Server-Forbidden",
6620 config: Config{
6621 MaxVersion: VersionTLS12,
6622 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006623 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006624 shouldFail: true,
6625 expectedError: ":NO_RENEGOTIATION:",
6626 expectedLocalError: "remote error: no renegotiation",
6627 })
Adam Langley5021b222015-06-12 18:27:58 -07006628 // The server shouldn't echo the renegotiation extension unless
6629 // requested by the client.
6630 testCases = append(testCases, testCase{
6631 testType: serverTest,
6632 name: "Renegotiate-Server-NoExt",
6633 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006634 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006635 Bugs: ProtocolBugs{
6636 NoRenegotiationInfo: true,
6637 RequireRenegotiationInfo: true,
6638 },
6639 },
6640 shouldFail: true,
6641 expectedLocalError: "renegotiation extension missing",
6642 })
6643 // The renegotiation SCSV should be sufficient for the server to echo
6644 // the extension.
6645 testCases = append(testCases, testCase{
6646 testType: serverTest,
6647 name: "Renegotiate-Server-NoExt-SCSV",
6648 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006649 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006650 Bugs: ProtocolBugs{
6651 NoRenegotiationInfo: true,
6652 SendRenegotiationSCSV: true,
6653 RequireRenegotiationInfo: true,
6654 },
6655 },
6656 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006657 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006658 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006659 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006660 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006661 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006662 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006663 },
6664 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006665 renegotiate: 1,
6666 flags: []string{
6667 "-renegotiate-freely",
6668 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006669 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006670 },
David Benjamincdea40c2015-03-19 14:09:43 -04006671 })
6672 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006673 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006674 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006676 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006677 Bugs: ProtocolBugs{
6678 EmptyRenegotiationInfo: true,
6679 },
6680 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006681 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006682 shouldFail: true,
6683 expectedError: ":RENEGOTIATION_MISMATCH:",
6684 })
6685 testCases = append(testCases, testCase{
6686 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006687 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006689 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006690 Bugs: ProtocolBugs{
6691 BadRenegotiationInfo: true,
6692 },
6693 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006694 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006695 shouldFail: true,
6696 expectedError: ":RENEGOTIATION_MISMATCH:",
6697 })
6698 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006699 name: "Renegotiate-Client-BadExt2",
6700 renegotiate: 1,
6701 config: Config{
6702 MaxVersion: VersionTLS12,
6703 Bugs: ProtocolBugs{
6704 BadRenegotiationInfoEnd: true,
6705 },
6706 },
6707 flags: []string{"-renegotiate-freely"},
6708 shouldFail: true,
6709 expectedError: ":RENEGOTIATION_MISMATCH:",
6710 })
6711 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006712 name: "Renegotiate-Client-Downgrade",
6713 renegotiate: 1,
6714 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006715 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006716 Bugs: ProtocolBugs{
6717 NoRenegotiationInfoAfterInitial: true,
6718 },
6719 },
6720 flags: []string{"-renegotiate-freely"},
6721 shouldFail: true,
6722 expectedError: ":RENEGOTIATION_MISMATCH:",
6723 })
6724 testCases = append(testCases, testCase{
6725 name: "Renegotiate-Client-Upgrade",
6726 renegotiate: 1,
6727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006728 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006729 Bugs: ProtocolBugs{
6730 NoRenegotiationInfoInInitial: true,
6731 },
6732 },
6733 flags: []string{"-renegotiate-freely"},
6734 shouldFail: true,
6735 expectedError: ":RENEGOTIATION_MISMATCH:",
6736 })
6737 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006738 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006739 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006740 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006741 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006742 Bugs: ProtocolBugs{
6743 NoRenegotiationInfo: true,
6744 },
6745 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006746 flags: []string{
6747 "-renegotiate-freely",
6748 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006749 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006750 },
David Benjamincff0b902015-05-15 23:09:47 -04006751 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006752
6753 // Test that the server may switch ciphers on renegotiation without
6754 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006755 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006756 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006757 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006759 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006760 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006761 },
6762 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006763 flags: []string{
6764 "-renegotiate-freely",
6765 "-expect-total-renegotiations", "1",
6766 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006767 })
6768 testCases = append(testCases, testCase{
6769 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006770 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006771 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006772 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6774 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006775 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006776 flags: []string{
6777 "-renegotiate-freely",
6778 "-expect-total-renegotiations", "1",
6779 },
David Benjaminb16346b2015-04-08 19:16:58 -04006780 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006781
6782 // Test that the server may not switch versions on renegotiation.
6783 testCases = append(testCases, testCase{
6784 name: "Renegotiate-Client-SwitchVersion",
6785 config: Config{
6786 MaxVersion: VersionTLS12,
6787 // Pick a cipher which exists at both versions.
6788 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6789 Bugs: ProtocolBugs{
6790 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006791 // Avoid failing early at the record layer.
6792 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006793 },
6794 },
6795 renegotiate: 1,
6796 flags: []string{
6797 "-renegotiate-freely",
6798 "-expect-total-renegotiations", "1",
6799 },
6800 shouldFail: true,
6801 expectedError: ":WRONG_SSL_VERSION:",
6802 })
6803
David Benjaminb16346b2015-04-08 19:16:58 -04006804 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006805 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006806 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006807 config: Config{
6808 MaxVersion: VersionTLS10,
6809 Bugs: ProtocolBugs{
6810 RequireSameRenegoClientVersion: true,
6811 },
6812 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006813 flags: []string{
6814 "-renegotiate-freely",
6815 "-expect-total-renegotiations", "1",
6816 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006817 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006818 testCases = append(testCases, testCase{
6819 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006820 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006821 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006822 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006823 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6824 NextProtos: []string{"foo"},
6825 },
6826 flags: []string{
6827 "-false-start",
6828 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006829 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006830 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006831 },
6832 shimWritesFirst: true,
6833 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006834
6835 // Client-side renegotiation controls.
6836 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006837 name: "Renegotiate-Client-Forbidden-1",
6838 config: Config{
6839 MaxVersion: VersionTLS12,
6840 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006841 renegotiate: 1,
6842 shouldFail: true,
6843 expectedError: ":NO_RENEGOTIATION:",
6844 expectedLocalError: "remote error: no renegotiation",
6845 })
6846 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006847 name: "Renegotiate-Client-Once-1",
6848 config: Config{
6849 MaxVersion: VersionTLS12,
6850 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006851 renegotiate: 1,
6852 flags: []string{
6853 "-renegotiate-once",
6854 "-expect-total-renegotiations", "1",
6855 },
6856 })
6857 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006858 name: "Renegotiate-Client-Freely-1",
6859 config: Config{
6860 MaxVersion: VersionTLS12,
6861 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006862 renegotiate: 1,
6863 flags: []string{
6864 "-renegotiate-freely",
6865 "-expect-total-renegotiations", "1",
6866 },
6867 })
6868 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006869 name: "Renegotiate-Client-Once-2",
6870 config: Config{
6871 MaxVersion: VersionTLS12,
6872 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006873 renegotiate: 2,
6874 flags: []string{"-renegotiate-once"},
6875 shouldFail: true,
6876 expectedError: ":NO_RENEGOTIATION:",
6877 expectedLocalError: "remote error: no renegotiation",
6878 })
6879 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006880 name: "Renegotiate-Client-Freely-2",
6881 config: Config{
6882 MaxVersion: VersionTLS12,
6883 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006884 renegotiate: 2,
6885 flags: []string{
6886 "-renegotiate-freely",
6887 "-expect-total-renegotiations", "2",
6888 },
6889 })
Adam Langley27a0d082015-11-03 13:34:10 -08006890 testCases = append(testCases, testCase{
6891 name: "Renegotiate-Client-NoIgnore",
6892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006893 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006894 Bugs: ProtocolBugs{
6895 SendHelloRequestBeforeEveryAppDataRecord: true,
6896 },
6897 },
6898 shouldFail: true,
6899 expectedError: ":NO_RENEGOTIATION:",
6900 })
6901 testCases = append(testCases, testCase{
6902 name: "Renegotiate-Client-Ignore",
6903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006904 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006905 Bugs: ProtocolBugs{
6906 SendHelloRequestBeforeEveryAppDataRecord: true,
6907 },
6908 },
6909 flags: []string{
6910 "-renegotiate-ignore",
6911 "-expect-total-renegotiations", "0",
6912 },
6913 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006914
David Benjamin34941c02016-10-08 11:45:31 -04006915 // Renegotiation is not allowed at SSL 3.0.
6916 testCases = append(testCases, testCase{
6917 name: "Renegotiate-Client-SSL3",
6918 config: Config{
6919 MaxVersion: VersionSSL30,
6920 },
6921 renegotiate: 1,
6922 flags: []string{
6923 "-renegotiate-freely",
6924 "-expect-total-renegotiations", "1",
6925 },
6926 shouldFail: true,
6927 expectedError: ":NO_RENEGOTIATION:",
6928 expectedLocalError: "remote error: no renegotiation",
6929 })
6930
David Benjamina1eaba12017-01-01 23:19:22 -05006931 // Renegotiation is not allowed when there is an unfinished write.
6932 testCases = append(testCases, testCase{
6933 name: "Renegotiate-Client-UnfinishedWrite",
6934 config: Config{
6935 MaxVersion: VersionTLS12,
6936 },
David Benjaminbbba9392017-04-06 12:54:12 -04006937 renegotiate: 1,
6938 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006939 flags: []string{
6940 "-async",
6941 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006942 },
6943 shouldFail: true,
6944 expectedError: ":NO_RENEGOTIATION:",
6945 // We do not successfully send the no_renegotiation alert in
6946 // this case. https://crbug.com/boringssl/130
6947 })
6948
David Benjamin07ab5d42017-02-09 20:11:41 -05006949 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006950 testCases = append(testCases, testCase{
6951 name: "StrayHelloRequest",
6952 config: Config{
6953 MaxVersion: VersionTLS12,
6954 Bugs: ProtocolBugs{
6955 SendHelloRequestBeforeEveryHandshakeMessage: true,
6956 },
6957 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006958 shouldFail: true,
6959 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006960 })
6961 testCases = append(testCases, testCase{
6962 name: "StrayHelloRequest-Packed",
6963 config: Config{
6964 MaxVersion: VersionTLS12,
6965 Bugs: ProtocolBugs{
6966 PackHandshakeFlight: true,
6967 SendHelloRequestBeforeEveryHandshakeMessage: true,
6968 },
6969 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006970 shouldFail: true,
6971 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006972 })
6973
David Benjamin12d2c482016-07-24 10:56:51 -04006974 // Test renegotiation works if HelloRequest and server Finished come in
6975 // the same record.
6976 testCases = append(testCases, testCase{
6977 name: "Renegotiate-Client-Packed",
6978 config: Config{
6979 MaxVersion: VersionTLS12,
6980 Bugs: ProtocolBugs{
6981 PackHandshakeFlight: true,
6982 PackHelloRequestWithFinished: true,
6983 },
6984 },
6985 renegotiate: 1,
6986 flags: []string{
6987 "-renegotiate-freely",
6988 "-expect-total-renegotiations", "1",
6989 },
6990 })
6991
David Benjamin397c8e62016-07-08 14:14:36 -07006992 // Renegotiation is forbidden in TLS 1.3.
6993 testCases = append(testCases, testCase{
6994 name: "Renegotiate-Client-TLS13",
6995 config: Config{
6996 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006997 Bugs: ProtocolBugs{
6998 SendHelloRequestBeforeEveryAppDataRecord: true,
6999 },
David Benjamin397c8e62016-07-08 14:14:36 -07007000 },
David Benjamin397c8e62016-07-08 14:14:36 -07007001 flags: []string{
7002 "-renegotiate-freely",
7003 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007004 shouldFail: true,
7005 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007006 })
7007
7008 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7009 testCases = append(testCases, testCase{
7010 name: "StrayHelloRequest-TLS13",
7011 config: Config{
7012 MaxVersion: VersionTLS13,
7013 Bugs: ProtocolBugs{
7014 SendHelloRequestBeforeEveryHandshakeMessage: true,
7015 },
7016 },
7017 shouldFail: true,
7018 expectedError: ":UNEXPECTED_MESSAGE:",
7019 })
David Benjamind2610042017-01-03 10:49:28 -05007020
7021 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7022 // always reads as supporting it, regardless of whether it was
7023 // negotiated.
7024 testCases = append(testCases, testCase{
7025 name: "AlwaysReportRenegotiationInfo-TLS13",
7026 config: Config{
7027 MaxVersion: VersionTLS13,
7028 Bugs: ProtocolBugs{
7029 NoRenegotiationInfo: true,
7030 },
7031 },
7032 flags: []string{
7033 "-expect-secure-renegotiation",
7034 },
7035 })
David Benjamina58baaf2017-02-28 20:54:28 -05007036
7037 // Certificates may not change on renegotiation.
7038 testCases = append(testCases, testCase{
7039 name: "Renegotiation-CertificateChange",
7040 config: Config{
7041 MaxVersion: VersionTLS12,
7042 Certificates: []Certificate{rsaCertificate},
7043 Bugs: ProtocolBugs{
7044 RenegotiationCertificate: &rsaChainCertificate,
7045 },
7046 },
7047 renegotiate: 1,
7048 flags: []string{"-renegotiate-freely"},
7049 shouldFail: true,
7050 expectedError: ":SERVER_CERT_CHANGED:",
7051 })
7052 testCases = append(testCases, testCase{
7053 name: "Renegotiation-CertificateChange-2",
7054 config: Config{
7055 MaxVersion: VersionTLS12,
7056 Certificates: []Certificate{rsaCertificate},
7057 Bugs: ProtocolBugs{
7058 RenegotiationCertificate: &rsa1024Certificate,
7059 },
7060 },
7061 renegotiate: 1,
7062 flags: []string{"-renegotiate-freely"},
7063 shouldFail: true,
7064 expectedError: ":SERVER_CERT_CHANGED:",
7065 })
David Benjaminbbf42462017-03-14 21:27:10 -04007066
7067 // We do not negotiate ALPN after the initial handshake. This is
7068 // error-prone and only risks bugs in consumers.
7069 testCases = append(testCases, testCase{
7070 testType: clientTest,
7071 name: "Renegotiation-ForbidALPN",
7072 config: Config{
7073 MaxVersion: VersionTLS12,
7074 Bugs: ProtocolBugs{
7075 // Forcibly negotiate ALPN on both initial and
7076 // renegotiation handshakes. The test stack will
7077 // internally check the client does not offer
7078 // it.
7079 SendALPN: "foo",
7080 },
7081 },
7082 flags: []string{
7083 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7084 "-expect-alpn", "foo",
7085 "-renegotiate-freely",
7086 },
7087 renegotiate: 1,
7088 shouldFail: true,
7089 expectedError: ":UNEXPECTED_EXTENSION:",
7090 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007091}
7092
David Benjamin5e961c12014-11-07 01:48:35 -05007093func addDTLSReplayTests() {
7094 // Test that sequence number replays are detected.
7095 testCases = append(testCases, testCase{
7096 protocol: dtls,
7097 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007098 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007099 replayWrites: true,
7100 })
7101
David Benjamin8e6db492015-07-25 18:29:23 -04007102 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007103 // than the retransmit window.
7104 testCases = append(testCases, testCase{
7105 protocol: dtls,
7106 name: "DTLS-Replay-LargeGaps",
7107 config: Config{
7108 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007109 SequenceNumberMapping: func(in uint64) uint64 {
7110 return in * 127
7111 },
David Benjamin5e961c12014-11-07 01:48:35 -05007112 },
7113 },
David Benjamin8e6db492015-07-25 18:29:23 -04007114 messageCount: 200,
7115 replayWrites: true,
7116 })
7117
7118 // Test the incoming sequence number changing non-monotonically.
7119 testCases = append(testCases, testCase{
7120 protocol: dtls,
7121 name: "DTLS-Replay-NonMonotonic",
7122 config: Config{
7123 Bugs: ProtocolBugs{
7124 SequenceNumberMapping: func(in uint64) uint64 {
7125 return in ^ 31
7126 },
7127 },
7128 },
7129 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007130 replayWrites: true,
7131 })
7132}
7133
Nick Harper60edffd2016-06-21 15:19:24 -07007134var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007135 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007136 id signatureAlgorithm
7137 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007138}{
Nick Harper60edffd2016-06-21 15:19:24 -07007139 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7140 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7141 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7142 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007143 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007144 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7145 // hash function doesn't have to match the curve and so the same
7146 // signature algorithm works with P-224.
7147 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007148 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7149 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7150 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007151 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7152 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7153 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007154 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007155 // Tests for key types prior to TLS 1.2.
7156 {"RSA", 0, testCertRSA},
7157 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007158}
7159
Nick Harper60edffd2016-06-21 15:19:24 -07007160const fakeSigAlg1 signatureAlgorithm = 0x2a01
7161const fakeSigAlg2 signatureAlgorithm = 0xff01
7162
7163func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007164 // Not all ciphers involve a signature. Advertise a list which gives all
7165 // versions a signing cipher.
7166 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007167 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007168 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7169 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7170 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7171 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007172 }
David Benjamin5208fd42016-07-13 21:43:25 -04007173
David Benjaminca3d5452016-07-14 12:51:01 -04007174 var allAlgorithms []signatureAlgorithm
7175 for _, alg := range testSignatureAlgorithms {
7176 if alg.id != 0 {
7177 allAlgorithms = append(allAlgorithms, alg.id)
7178 }
7179 }
7180
Nick Harper60edffd2016-06-21 15:19:24 -07007181 // Make sure each signature algorithm works. Include some fake values in
7182 // the list and ensure they're ignored.
7183 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007184 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007185 if (ver.version < VersionTLS12) != (alg.id == 0) {
7186 continue
7187 }
7188
7189 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7190 // or remove it in C.
7191 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007192 continue
7193 }
Nick Harper60edffd2016-06-21 15:19:24 -07007194
David Benjamin3ef76972016-10-17 17:59:54 -04007195 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007196 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007197 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007198 shouldSignFail = true
7199 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007200 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007201 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007202 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7203 shouldSignFail = true
7204 shouldVerifyFail = true
7205 }
7206 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7207 // the curve has to match the hash size.
7208 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007209 shouldSignFail = true
7210 shouldVerifyFail = true
7211 }
7212
7213 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7214 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7215 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007216 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007217
7218 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007219 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007220 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007221 }
7222 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007223 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007224 }
David Benjamin000800a2014-11-14 01:43:59 -05007225
David Benjamin1fb125c2016-07-08 18:52:12 -07007226 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007227
David Benjamin7a41d372016-07-09 11:21:54 -07007228 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007229 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007230 config: Config{
7231 MaxVersion: ver.version,
7232 ClientAuth: RequireAnyClientCert,
7233 VerifySignatureAlgorithms: []signatureAlgorithm{
7234 fakeSigAlg1,
7235 alg.id,
7236 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007237 },
David Benjamin7a41d372016-07-09 11:21:54 -07007238 },
7239 flags: []string{
7240 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7241 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7242 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007243 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007244 },
David Benjamin3ef76972016-10-17 17:59:54 -04007245 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007246 expectedError: signError,
7247 expectedPeerSignatureAlgorithm: alg.id,
7248 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007249
David Benjamin7a41d372016-07-09 11:21:54 -07007250 testCases = append(testCases, testCase{
7251 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007252 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007253 config: Config{
7254 MaxVersion: ver.version,
7255 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7256 SignSignatureAlgorithms: []signatureAlgorithm{
7257 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007258 },
David Benjamin7a41d372016-07-09 11:21:54 -07007259 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007260 SkipECDSACurveCheck: shouldVerifyFail,
7261 IgnoreSignatureVersionChecks: shouldVerifyFail,
7262 // Some signature algorithms may not be advertised.
7263 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007264 },
David Benjamin7a41d372016-07-09 11:21:54 -07007265 },
7266 flags: []string{
7267 "-require-any-client-certificate",
7268 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7269 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007270 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007271 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007272 // Resume the session to assert the peer signature
7273 // algorithm is reported on both handshakes.
7274 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007275 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007276 expectedError: verifyError,
7277 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007278
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007279 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007280 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007281 testCases = append(testCases, testCase{
7282 testType: serverTest,
7283 name: "ServerAuth-Sign" + suffix,
7284 config: Config{
7285 MaxVersion: ver.version,
7286 CipherSuites: signingCiphers,
7287 VerifySignatureAlgorithms: []signatureAlgorithm{
7288 fakeSigAlg1,
7289 alg.id,
7290 fakeSigAlg2,
7291 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007292 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007293 flags: []string{
7294 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7295 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7296 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007297 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007298 },
7299 shouldFail: shouldSignFail,
7300 expectedError: signError,
7301 expectedPeerSignatureAlgorithm: alg.id,
7302 })
7303 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007304
7305 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007306 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007307 config: Config{
7308 MaxVersion: ver.version,
7309 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007310 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007311 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007312 alg.id,
7313 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007314 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007315 SkipECDSACurveCheck: shouldVerifyFail,
7316 IgnoreSignatureVersionChecks: shouldVerifyFail,
7317 // Some signature algorithms may not be advertised.
7318 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007319 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007320 },
7321 flags: []string{
7322 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7323 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007324 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007325 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007326 // Resume the session to assert the peer signature
7327 // algorithm is reported on both handshakes.
7328 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007329 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007330 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007331 })
David Benjamin5208fd42016-07-13 21:43:25 -04007332
David Benjamin3ef76972016-10-17 17:59:54 -04007333 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007334 testCases = append(testCases, testCase{
7335 testType: serverTest,
7336 name: "ClientAuth-InvalidSignature" + suffix,
7337 config: Config{
7338 MaxVersion: ver.version,
7339 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7340 SignSignatureAlgorithms: []signatureAlgorithm{
7341 alg.id,
7342 },
7343 Bugs: ProtocolBugs{
7344 InvalidSignature: true,
7345 },
7346 },
7347 flags: []string{
7348 "-require-any-client-certificate",
7349 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007350 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007351 },
7352 shouldFail: true,
7353 expectedError: ":BAD_SIGNATURE:",
7354 })
7355
7356 testCases = append(testCases, testCase{
7357 name: "ServerAuth-InvalidSignature" + suffix,
7358 config: Config{
7359 MaxVersion: ver.version,
7360 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7361 CipherSuites: signingCiphers,
7362 SignSignatureAlgorithms: []signatureAlgorithm{
7363 alg.id,
7364 },
7365 Bugs: ProtocolBugs{
7366 InvalidSignature: true,
7367 },
7368 },
David Benjamin69522112017-03-28 15:38:29 -05007369 flags: []string{
7370 "-enable-all-curves",
7371 "-enable-ed25519",
7372 },
David Benjamin5208fd42016-07-13 21:43:25 -04007373 shouldFail: true,
7374 expectedError: ":BAD_SIGNATURE:",
7375 })
7376 }
David Benjaminca3d5452016-07-14 12:51:01 -04007377
David Benjamin3ef76972016-10-17 17:59:54 -04007378 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007379 testCases = append(testCases, testCase{
7380 name: "ClientAuth-Sign-Negotiate" + suffix,
7381 config: Config{
7382 MaxVersion: ver.version,
7383 ClientAuth: RequireAnyClientCert,
7384 VerifySignatureAlgorithms: allAlgorithms,
7385 },
7386 flags: []string{
7387 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7388 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7389 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007390 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007391 "-signing-prefs", strconv.Itoa(int(alg.id)),
7392 },
7393 expectedPeerSignatureAlgorithm: alg.id,
7394 })
7395
7396 testCases = append(testCases, testCase{
7397 testType: serverTest,
7398 name: "ServerAuth-Sign-Negotiate" + suffix,
7399 config: Config{
7400 MaxVersion: ver.version,
7401 CipherSuites: signingCiphers,
7402 VerifySignatureAlgorithms: allAlgorithms,
7403 },
7404 flags: []string{
7405 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7406 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7407 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007408 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007409 "-signing-prefs", strconv.Itoa(int(alg.id)),
7410 },
7411 expectedPeerSignatureAlgorithm: alg.id,
7412 })
7413 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007414 }
David Benjamin000800a2014-11-14 01:43:59 -05007415 }
7416
Nick Harper60edffd2016-06-21 15:19:24 -07007417 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007418 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007419 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007420 config: Config{
7421 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007422 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007423 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007424 signatureECDSAWithP521AndSHA512,
7425 signatureRSAPKCS1WithSHA384,
7426 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007427 },
7428 },
7429 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007430 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7431 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007432 },
Nick Harper60edffd2016-06-21 15:19:24 -07007433 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007434 })
7435
7436 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007437 name: "ClientAuth-SignatureType-TLS13",
7438 config: Config{
7439 ClientAuth: RequireAnyClientCert,
7440 MaxVersion: VersionTLS13,
7441 VerifySignatureAlgorithms: []signatureAlgorithm{
7442 signatureECDSAWithP521AndSHA512,
7443 signatureRSAPKCS1WithSHA384,
7444 signatureRSAPSSWithSHA384,
7445 signatureECDSAWithSHA1,
7446 },
7447 },
7448 flags: []string{
7449 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7450 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7451 },
7452 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7453 })
7454
7455 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007456 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007457 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007459 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007460 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007461 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007462 signatureECDSAWithP521AndSHA512,
7463 signatureRSAPKCS1WithSHA384,
7464 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007465 },
7466 },
Nick Harper60edffd2016-06-21 15:19:24 -07007467 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007468 })
7469
Steven Valdez143e8b32016-07-11 13:19:03 -04007470 testCases = append(testCases, testCase{
7471 testType: serverTest,
7472 name: "ServerAuth-SignatureType-TLS13",
7473 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007474 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007475 VerifySignatureAlgorithms: []signatureAlgorithm{
7476 signatureECDSAWithP521AndSHA512,
7477 signatureRSAPKCS1WithSHA384,
7478 signatureRSAPSSWithSHA384,
7479 signatureECDSAWithSHA1,
7480 },
7481 },
7482 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7483 })
7484
David Benjamina95e9f32016-07-08 16:28:04 -07007485 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007486 testCases = append(testCases, testCase{
7487 testType: serverTest,
7488 name: "Verify-ClientAuth-SignatureType",
7489 config: Config{
7490 MaxVersion: VersionTLS12,
7491 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007492 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007493 signatureRSAPKCS1WithSHA256,
7494 },
7495 Bugs: ProtocolBugs{
7496 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7497 },
7498 },
7499 flags: []string{
7500 "-require-any-client-certificate",
7501 },
7502 shouldFail: true,
7503 expectedError: ":WRONG_SIGNATURE_TYPE:",
7504 })
7505
7506 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007507 testType: serverTest,
7508 name: "Verify-ClientAuth-SignatureType-TLS13",
7509 config: Config{
7510 MaxVersion: VersionTLS13,
7511 Certificates: []Certificate{rsaCertificate},
7512 SignSignatureAlgorithms: []signatureAlgorithm{
7513 signatureRSAPSSWithSHA256,
7514 },
7515 Bugs: ProtocolBugs{
7516 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7517 },
7518 },
7519 flags: []string{
7520 "-require-any-client-certificate",
7521 },
7522 shouldFail: true,
7523 expectedError: ":WRONG_SIGNATURE_TYPE:",
7524 })
7525
7526 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007527 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007528 config: Config{
7529 MaxVersion: VersionTLS12,
7530 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007531 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007532 signatureRSAPKCS1WithSHA256,
7533 },
7534 Bugs: ProtocolBugs{
7535 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7536 },
7537 },
7538 shouldFail: true,
7539 expectedError: ":WRONG_SIGNATURE_TYPE:",
7540 })
7541
Steven Valdez143e8b32016-07-11 13:19:03 -04007542 testCases = append(testCases, testCase{
7543 name: "Verify-ServerAuth-SignatureType-TLS13",
7544 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007545 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007546 SignSignatureAlgorithms: []signatureAlgorithm{
7547 signatureRSAPSSWithSHA256,
7548 },
7549 Bugs: ProtocolBugs{
7550 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7551 },
7552 },
7553 shouldFail: true,
7554 expectedError: ":WRONG_SIGNATURE_TYPE:",
7555 })
7556
David Benjamin51dd7d62016-07-08 16:07:01 -07007557 // Test that, if the list is missing, the peer falls back to SHA-1 in
7558 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007559 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007560 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007562 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007563 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007564 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007565 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007566 },
7567 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007568 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007569 },
7570 },
7571 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007572 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7573 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007574 },
7575 })
7576
7577 testCases = append(testCases, testCase{
7578 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007579 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007580 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007581 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007582 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007583 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007584 },
7585 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007586 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007587 },
7588 },
David Benjaminee32bea2016-08-17 13:36:44 -04007589 flags: []string{
7590 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7591 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7592 },
7593 })
7594
7595 testCases = append(testCases, testCase{
7596 name: "ClientAuth-SHA1-Fallback-ECDSA",
7597 config: Config{
7598 MaxVersion: VersionTLS12,
7599 ClientAuth: RequireAnyClientCert,
7600 VerifySignatureAlgorithms: []signatureAlgorithm{
7601 signatureECDSAWithSHA1,
7602 },
7603 Bugs: ProtocolBugs{
7604 NoSignatureAlgorithms: true,
7605 },
7606 },
7607 flags: []string{
7608 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7609 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7610 },
7611 })
7612
7613 testCases = append(testCases, testCase{
7614 testType: serverTest,
7615 name: "ServerAuth-SHA1-Fallback-ECDSA",
7616 config: Config{
7617 MaxVersion: VersionTLS12,
7618 VerifySignatureAlgorithms: []signatureAlgorithm{
7619 signatureECDSAWithSHA1,
7620 },
7621 Bugs: ProtocolBugs{
7622 NoSignatureAlgorithms: true,
7623 },
7624 },
7625 flags: []string{
7626 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7627 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7628 },
David Benjamin000800a2014-11-14 01:43:59 -05007629 })
David Benjamin72dc7832015-03-16 17:49:43 -04007630
David Benjamin51dd7d62016-07-08 16:07:01 -07007631 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007632 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007633 config: Config{
7634 MaxVersion: VersionTLS13,
7635 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007636 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007637 signatureRSAPKCS1WithSHA1,
7638 },
7639 Bugs: ProtocolBugs{
7640 NoSignatureAlgorithms: true,
7641 },
7642 },
7643 flags: []string{
7644 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7645 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7646 },
David Benjamin48901652016-08-01 12:12:47 -04007647 shouldFail: true,
7648 // An empty CertificateRequest signature algorithm list is a
7649 // syntax error in TLS 1.3.
7650 expectedError: ":DECODE_ERROR:",
7651 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007652 })
7653
7654 testCases = append(testCases, testCase{
7655 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007656 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007657 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007658 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007659 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007660 signatureRSAPKCS1WithSHA1,
7661 },
7662 Bugs: ProtocolBugs{
7663 NoSignatureAlgorithms: true,
7664 },
7665 },
7666 shouldFail: true,
7667 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7668 })
7669
David Benjaminb62d2872016-07-18 14:55:02 +02007670 // Test that hash preferences are enforced. BoringSSL does not implement
7671 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007672 testCases = append(testCases, testCase{
7673 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007674 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007676 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007677 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007678 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007679 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007680 },
7681 Bugs: ProtocolBugs{
7682 IgnorePeerSignatureAlgorithmPreferences: true,
7683 },
7684 },
7685 flags: []string{"-require-any-client-certificate"},
7686 shouldFail: true,
7687 expectedError: ":WRONG_SIGNATURE_TYPE:",
7688 })
7689
7690 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007691 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007693 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007695 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007696 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007697 },
7698 Bugs: ProtocolBugs{
7699 IgnorePeerSignatureAlgorithmPreferences: true,
7700 },
7701 },
7702 shouldFail: true,
7703 expectedError: ":WRONG_SIGNATURE_TYPE:",
7704 })
David Benjaminb62d2872016-07-18 14:55:02 +02007705 testCases = append(testCases, testCase{
7706 testType: serverTest,
7707 name: "ClientAuth-Enforced-TLS13",
7708 config: Config{
7709 MaxVersion: VersionTLS13,
7710 Certificates: []Certificate{rsaCertificate},
7711 SignSignatureAlgorithms: []signatureAlgorithm{
7712 signatureRSAPKCS1WithMD5,
7713 },
7714 Bugs: ProtocolBugs{
7715 IgnorePeerSignatureAlgorithmPreferences: true,
7716 IgnoreSignatureVersionChecks: true,
7717 },
7718 },
7719 flags: []string{"-require-any-client-certificate"},
7720 shouldFail: true,
7721 expectedError: ":WRONG_SIGNATURE_TYPE:",
7722 })
7723
7724 testCases = append(testCases, testCase{
7725 name: "ServerAuth-Enforced-TLS13",
7726 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007727 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007728 SignSignatureAlgorithms: []signatureAlgorithm{
7729 signatureRSAPKCS1WithMD5,
7730 },
7731 Bugs: ProtocolBugs{
7732 IgnorePeerSignatureAlgorithmPreferences: true,
7733 IgnoreSignatureVersionChecks: true,
7734 },
7735 },
7736 shouldFail: true,
7737 expectedError: ":WRONG_SIGNATURE_TYPE:",
7738 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007739
7740 // Test that the agreed upon digest respects the client preferences and
7741 // the server digests.
7742 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007743 name: "NoCommonAlgorithms-Digests",
7744 config: Config{
7745 MaxVersion: VersionTLS12,
7746 ClientAuth: RequireAnyClientCert,
7747 VerifySignatureAlgorithms: []signatureAlgorithm{
7748 signatureRSAPKCS1WithSHA512,
7749 signatureRSAPKCS1WithSHA1,
7750 },
7751 },
7752 flags: []string{
7753 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7754 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7755 "-digest-prefs", "SHA256",
7756 },
7757 shouldFail: true,
7758 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7759 })
7760 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007761 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007763 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007764 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007765 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007766 signatureRSAPKCS1WithSHA512,
7767 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007768 },
7769 },
7770 flags: []string{
7771 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7772 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007773 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007774 },
David Benjaminca3d5452016-07-14 12:51:01 -04007775 shouldFail: true,
7776 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7777 })
7778 testCases = append(testCases, testCase{
7779 name: "NoCommonAlgorithms-TLS13",
7780 config: Config{
7781 MaxVersion: VersionTLS13,
7782 ClientAuth: RequireAnyClientCert,
7783 VerifySignatureAlgorithms: []signatureAlgorithm{
7784 signatureRSAPSSWithSHA512,
7785 signatureRSAPSSWithSHA384,
7786 },
7787 },
7788 flags: []string{
7789 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7790 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7791 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7792 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007793 shouldFail: true,
7794 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007795 })
7796 testCases = append(testCases, testCase{
7797 name: "Agree-Digest-SHA256",
7798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007799 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007800 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007801 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007802 signatureRSAPKCS1WithSHA1,
7803 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007804 },
7805 },
7806 flags: []string{
7807 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7808 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007809 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007810 },
Nick Harper60edffd2016-06-21 15:19:24 -07007811 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007812 })
7813 testCases = append(testCases, testCase{
7814 name: "Agree-Digest-SHA1",
7815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007816 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007817 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007818 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007819 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007820 },
7821 },
7822 flags: []string{
7823 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7824 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007825 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007826 },
Nick Harper60edffd2016-06-21 15:19:24 -07007827 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007828 })
7829 testCases = append(testCases, testCase{
7830 name: "Agree-Digest-Default",
7831 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007832 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007833 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007834 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007835 signatureRSAPKCS1WithSHA256,
7836 signatureECDSAWithP256AndSHA256,
7837 signatureRSAPKCS1WithSHA1,
7838 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007839 },
7840 },
7841 flags: []string{
7842 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7843 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7844 },
Nick Harper60edffd2016-06-21 15:19:24 -07007845 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007846 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007847
David Benjaminca3d5452016-07-14 12:51:01 -04007848 // Test that the signing preference list may include extra algorithms
7849 // without negotiation problems.
7850 testCases = append(testCases, testCase{
7851 testType: serverTest,
7852 name: "FilterExtraAlgorithms",
7853 config: Config{
7854 MaxVersion: VersionTLS12,
7855 VerifySignatureAlgorithms: []signatureAlgorithm{
7856 signatureRSAPKCS1WithSHA256,
7857 },
7858 },
7859 flags: []string{
7860 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7861 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7862 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7863 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7864 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7865 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7866 },
7867 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7868 })
7869
David Benjamin4c3ddf72016-06-29 18:13:53 -04007870 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7871 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007872 testCases = append(testCases, testCase{
7873 name: "CheckLeafCurve",
7874 config: Config{
7875 MaxVersion: VersionTLS12,
7876 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007877 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007878 },
7879 flags: []string{"-p384-only"},
7880 shouldFail: true,
7881 expectedError: ":BAD_ECC_CERT:",
7882 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007883
7884 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7885 testCases = append(testCases, testCase{
7886 name: "CheckLeafCurve-TLS13",
7887 config: Config{
7888 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007889 Certificates: []Certificate{ecdsaP256Certificate},
7890 },
7891 flags: []string{"-p384-only"},
7892 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007893
7894 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7895 testCases = append(testCases, testCase{
7896 name: "ECDSACurveMismatch-Verify-TLS12",
7897 config: Config{
7898 MaxVersion: VersionTLS12,
7899 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7900 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007901 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007902 signatureECDSAWithP384AndSHA384,
7903 },
7904 },
7905 })
7906
7907 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7908 testCases = append(testCases, testCase{
7909 name: "ECDSACurveMismatch-Verify-TLS13",
7910 config: Config{
7911 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007912 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007913 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007914 signatureECDSAWithP384AndSHA384,
7915 },
7916 Bugs: ProtocolBugs{
7917 SkipECDSACurveCheck: true,
7918 },
7919 },
7920 shouldFail: true,
7921 expectedError: ":WRONG_SIGNATURE_TYPE:",
7922 })
7923
7924 // Signature algorithm selection in TLS 1.3 should take the curve into
7925 // account.
7926 testCases = append(testCases, testCase{
7927 testType: serverTest,
7928 name: "ECDSACurveMismatch-Sign-TLS13",
7929 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007930 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007931 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007932 signatureECDSAWithP384AndSHA384,
7933 signatureECDSAWithP256AndSHA256,
7934 },
7935 },
7936 flags: []string{
7937 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7938 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7939 },
7940 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7941 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007942
7943 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7944 // server does not attempt to sign in that case.
7945 testCases = append(testCases, testCase{
7946 testType: serverTest,
7947 name: "RSA-PSS-Large",
7948 config: Config{
7949 MaxVersion: VersionTLS13,
7950 VerifySignatureAlgorithms: []signatureAlgorithm{
7951 signatureRSAPSSWithSHA512,
7952 },
7953 },
7954 flags: []string{
7955 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7956 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7957 },
7958 shouldFail: true,
7959 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7960 })
David Benjamin57e929f2016-08-30 00:30:38 -04007961
7962 // Test that RSA-PSS is enabled by default for TLS 1.2.
7963 testCases = append(testCases, testCase{
7964 testType: clientTest,
7965 name: "RSA-PSS-Default-Verify",
7966 config: Config{
7967 MaxVersion: VersionTLS12,
7968 SignSignatureAlgorithms: []signatureAlgorithm{
7969 signatureRSAPSSWithSHA256,
7970 },
7971 },
7972 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7973 })
7974
7975 testCases = append(testCases, testCase{
7976 testType: serverTest,
7977 name: "RSA-PSS-Default-Sign",
7978 config: Config{
7979 MaxVersion: VersionTLS12,
7980 VerifySignatureAlgorithms: []signatureAlgorithm{
7981 signatureRSAPSSWithSHA256,
7982 },
7983 },
7984 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7985 })
David Benjamin69522112017-03-28 15:38:29 -05007986
7987 // TLS 1.1 and below has no way to advertise support for or negotiate
7988 // Ed25519's signature algorithm.
7989 testCases = append(testCases, testCase{
7990 testType: clientTest,
7991 name: "NoEd25519-TLS11-ServerAuth-Verify",
7992 config: Config{
7993 MaxVersion: VersionTLS11,
7994 Certificates: []Certificate{ed25519Certificate},
7995 Bugs: ProtocolBugs{
7996 // Sign with Ed25519 even though it is TLS 1.1.
7997 UseLegacySigningAlgorithm: signatureEd25519,
7998 },
7999 },
8000 flags: []string{"-enable-ed25519"},
8001 shouldFail: true,
8002 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8003 })
8004 testCases = append(testCases, testCase{
8005 testType: serverTest,
8006 name: "NoEd25519-TLS11-ServerAuth-Sign",
8007 config: Config{
8008 MaxVersion: VersionTLS11,
8009 },
8010 flags: []string{
8011 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8012 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8013 },
8014 shouldFail: true,
8015 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8016 })
8017 testCases = append(testCases, testCase{
8018 testType: serverTest,
8019 name: "NoEd25519-TLS11-ClientAuth-Verify",
8020 config: Config{
8021 MaxVersion: VersionTLS11,
8022 Certificates: []Certificate{ed25519Certificate},
8023 Bugs: ProtocolBugs{
8024 // Sign with Ed25519 even though it is TLS 1.1.
8025 UseLegacySigningAlgorithm: signatureEd25519,
8026 },
8027 },
8028 flags: []string{
8029 "-enable-ed25519",
8030 "-require-any-client-certificate",
8031 },
8032 shouldFail: true,
8033 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8034 })
8035 testCases = append(testCases, testCase{
8036 testType: clientTest,
8037 name: "NoEd25519-TLS11-ClientAuth-Sign",
8038 config: Config{
8039 MaxVersion: VersionTLS11,
8040 ClientAuth: RequireAnyClientCert,
8041 },
8042 flags: []string{
8043 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8044 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8045 },
8046 shouldFail: true,
8047 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8048 })
8049
8050 // Test Ed25519 is not advertised by default.
8051 testCases = append(testCases, testCase{
8052 testType: clientTest,
8053 name: "Ed25519DefaultDisable-NoAdvertise",
8054 config: Config{
8055 Certificates: []Certificate{ed25519Certificate},
8056 },
8057 shouldFail: true,
8058 expectedLocalError: "tls: no common signature algorithms",
8059 })
8060
8061 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8062 // preferences.
8063 testCases = append(testCases, testCase{
8064 testType: clientTest,
8065 name: "Ed25519DefaultDisable-NoAccept",
8066 config: Config{
8067 Certificates: []Certificate{ed25519Certificate},
8068 Bugs: ProtocolBugs{
8069 IgnorePeerSignatureAlgorithmPreferences: true,
8070 },
8071 },
8072 shouldFail: true,
8073 expectedLocalError: "remote error: illegal parameter",
8074 expectedError: ":WRONG_SIGNATURE_TYPE:",
8075 })
David Benjamin71c21b42017-04-14 17:05:40 -04008076
8077 // Test that configuring verify preferences changes what the client
8078 // advertises.
8079 testCases = append(testCases, testCase{
8080 name: "VerifyPreferences-Advertised",
8081 config: Config{
8082 Certificates: []Certificate{rsaCertificate},
8083 SignSignatureAlgorithms: []signatureAlgorithm{
8084 signatureRSAPSSWithSHA256,
8085 signatureRSAPSSWithSHA384,
8086 signatureRSAPSSWithSHA512,
8087 },
8088 },
8089 flags: []string{
8090 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8091 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8092 },
8093 })
8094
8095 // Test that the client advertises a set which the runner can find
8096 // nothing in common with.
8097 testCases = append(testCases, testCase{
8098 name: "VerifyPreferences-NoCommonAlgorithms",
8099 config: Config{
8100 Certificates: []Certificate{rsaCertificate},
8101 SignSignatureAlgorithms: []signatureAlgorithm{
8102 signatureRSAPSSWithSHA256,
8103 signatureRSAPSSWithSHA512,
8104 },
8105 },
8106 flags: []string{
8107 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8108 },
8109 shouldFail: true,
8110 expectedLocalError: "tls: no common signature algorithms",
8111 })
8112
8113 // Test that the client enforces its preferences when configured.
8114 testCases = append(testCases, testCase{
8115 name: "VerifyPreferences-Enforced",
8116 config: Config{
8117 Certificates: []Certificate{rsaCertificate},
8118 SignSignatureAlgorithms: []signatureAlgorithm{
8119 signatureRSAPSSWithSHA256,
8120 signatureRSAPSSWithSHA512,
8121 },
8122 Bugs: ProtocolBugs{
8123 IgnorePeerSignatureAlgorithmPreferences: true,
8124 },
8125 },
8126 flags: []string{
8127 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8128 },
8129 shouldFail: true,
8130 expectedLocalError: "remote error: illegal parameter",
8131 expectedError: ":WRONG_SIGNATURE_TYPE:",
8132 })
8133
8134 // Test that explicitly configuring Ed25519 is as good as changing the
8135 // boolean toggle.
8136 testCases = append(testCases, testCase{
8137 name: "VerifyPreferences-Ed25519",
8138 config: Config{
8139 Certificates: []Certificate{ed25519Certificate},
8140 },
8141 flags: []string{
8142 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8143 },
8144 })
David Benjamin000800a2014-11-14 01:43:59 -05008145}
8146
David Benjamin83f90402015-01-27 01:09:43 -05008147// timeouts is the retransmit schedule for BoringSSL. It doubles and
8148// caps at 60 seconds. On the 13th timeout, it gives up.
8149var timeouts = []time.Duration{
8150 1 * time.Second,
8151 2 * time.Second,
8152 4 * time.Second,
8153 8 * time.Second,
8154 16 * time.Second,
8155 32 * time.Second,
8156 60 * time.Second,
8157 60 * time.Second,
8158 60 * time.Second,
8159 60 * time.Second,
8160 60 * time.Second,
8161 60 * time.Second,
8162 60 * time.Second,
8163}
8164
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008165// shortTimeouts is an alternate set of timeouts which would occur if the
8166// initial timeout duration was set to 250ms.
8167var shortTimeouts = []time.Duration{
8168 250 * time.Millisecond,
8169 500 * time.Millisecond,
8170 1 * time.Second,
8171 2 * time.Second,
8172 4 * time.Second,
8173 8 * time.Second,
8174 16 * time.Second,
8175 32 * time.Second,
8176 60 * time.Second,
8177 60 * time.Second,
8178 60 * time.Second,
8179 60 * time.Second,
8180 60 * time.Second,
8181}
8182
David Benjamin83f90402015-01-27 01:09:43 -05008183func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008184 // These tests work by coordinating some behavior on both the shim and
8185 // the runner.
8186 //
8187 // TimeoutSchedule configures the runner to send a series of timeout
8188 // opcodes to the shim (see packetAdaptor) immediately before reading
8189 // each peer handshake flight N. The timeout opcode both simulates a
8190 // timeout in the shim and acts as a synchronization point to help the
8191 // runner bracket each handshake flight.
8192 //
8193 // We assume the shim does not read from the channel eagerly. It must
8194 // first wait until it has sent flight N and is ready to receive
8195 // handshake flight N+1. At this point, it will process the timeout
8196 // opcode. It must then immediately respond with a timeout ACK and act
8197 // as if the shim was idle for the specified amount of time.
8198 //
8199 // The runner then drops all packets received before the ACK and
8200 // continues waiting for flight N. This ordering results in one attempt
8201 // at sending flight N to be dropped. For the test to complete, the
8202 // shim must send flight N again, testing that the shim implements DTLS
8203 // retransmit on a timeout.
8204
Steven Valdez143e8b32016-07-11 13:19:03 -04008205 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008206 // likely be more epochs to cross and the final message's retransmit may
8207 // be more complex.
8208
David Benjamin11c82892017-02-23 20:40:31 -05008209 // Test that this is indeed the timeout schedule. Stress all
8210 // four patterns of handshake.
8211 for i := 1; i < len(timeouts); i++ {
8212 number := strconv.Itoa(i)
8213 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008214 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008215 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008217 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008218 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008219 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008220 },
8221 },
8222 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008223 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008224 })
David Benjamin11c82892017-02-23 20:40:31 -05008225 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008226 protocol: dtls,
8227 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008228 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008229 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008230 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008231 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008232 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008233 },
8234 },
8235 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008236 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008237 })
8238 }
David Benjamin11c82892017-02-23 20:40:31 -05008239
8240 // Test that exceeding the timeout schedule hits a read
8241 // timeout.
8242 testCases = append(testCases, testCase{
8243 protocol: dtls,
8244 name: "DTLS-Retransmit-Timeout",
8245 config: Config{
8246 MaxVersion: VersionTLS12,
8247 Bugs: ProtocolBugs{
8248 TimeoutSchedule: timeouts,
8249 },
8250 },
8251 resumeSession: true,
8252 flags: []string{"-async"},
8253 shouldFail: true,
8254 expectedError: ":READ_TIMEOUT_EXPIRED:",
8255 })
8256
8257 // Test that timeout handling has a fudge factor, due to API
8258 // problems.
8259 testCases = append(testCases, testCase{
8260 protocol: dtls,
8261 name: "DTLS-Retransmit-Fudge",
8262 config: Config{
8263 MaxVersion: VersionTLS12,
8264 Bugs: ProtocolBugs{
8265 TimeoutSchedule: []time.Duration{
8266 timeouts[0] - 10*time.Millisecond,
8267 },
8268 },
8269 },
8270 resumeSession: true,
8271 flags: []string{"-async"},
8272 })
8273
8274 // Test that the final Finished retransmitting isn't
8275 // duplicated if the peer badly fragments everything.
8276 testCases = append(testCases, testCase{
8277 testType: serverTest,
8278 protocol: dtls,
8279 name: "DTLS-Retransmit-Fragmented",
8280 config: Config{
8281 MaxVersion: VersionTLS12,
8282 Bugs: ProtocolBugs{
8283 TimeoutSchedule: []time.Duration{timeouts[0]},
8284 MaxHandshakeRecordLength: 2,
8285 },
8286 },
8287 flags: []string{"-async"},
8288 })
8289
8290 // Test the timeout schedule when a shorter initial timeout duration is set.
8291 testCases = append(testCases, testCase{
8292 protocol: dtls,
8293 name: "DTLS-Retransmit-Short-Client",
8294 config: Config{
8295 MaxVersion: VersionTLS12,
8296 Bugs: ProtocolBugs{
8297 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8298 },
8299 },
8300 resumeSession: true,
8301 flags: []string{
8302 "-async",
8303 "-initial-timeout-duration-ms", "250",
8304 },
8305 })
8306 testCases = append(testCases, testCase{
8307 protocol: dtls,
8308 testType: serverTest,
8309 name: "DTLS-Retransmit-Short-Server",
8310 config: Config{
8311 MaxVersion: VersionTLS12,
8312 Bugs: ProtocolBugs{
8313 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8314 },
8315 },
8316 resumeSession: true,
8317 flags: []string{
8318 "-async",
8319 "-initial-timeout-duration-ms", "250",
8320 },
8321 })
David Benjamin83f90402015-01-27 01:09:43 -05008322}
8323
David Benjaminc565ebb2015-04-03 04:06:36 -04008324func addExportKeyingMaterialTests() {
8325 for _, vers := range tlsVersions {
8326 if vers.version == VersionSSL30 {
8327 continue
8328 }
8329 testCases = append(testCases, testCase{
8330 name: "ExportKeyingMaterial-" + vers.name,
8331 config: Config{
8332 MaxVersion: vers.version,
8333 },
8334 exportKeyingMaterial: 1024,
8335 exportLabel: "label",
8336 exportContext: "context",
8337 useExportContext: true,
8338 })
8339 testCases = append(testCases, testCase{
8340 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8341 config: Config{
8342 MaxVersion: vers.version,
8343 },
8344 exportKeyingMaterial: 1024,
8345 })
8346 testCases = append(testCases, testCase{
8347 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8348 config: Config{
8349 MaxVersion: vers.version,
8350 },
8351 exportKeyingMaterial: 1024,
8352 useExportContext: true,
8353 })
8354 testCases = append(testCases, testCase{
8355 name: "ExportKeyingMaterial-Small-" + vers.name,
8356 config: Config{
8357 MaxVersion: vers.version,
8358 },
8359 exportKeyingMaterial: 1,
8360 exportLabel: "label",
8361 exportContext: "context",
8362 useExportContext: true,
8363 })
8364 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008365
David Benjaminc565ebb2015-04-03 04:06:36 -04008366 testCases = append(testCases, testCase{
8367 name: "ExportKeyingMaterial-SSL3",
8368 config: Config{
8369 MaxVersion: VersionSSL30,
8370 },
8371 exportKeyingMaterial: 1024,
8372 exportLabel: "label",
8373 exportContext: "context",
8374 useExportContext: true,
8375 shouldFail: true,
8376 expectedError: "failed to export keying material",
8377 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008378
8379 // Exporters work during a False Start.
8380 testCases = append(testCases, testCase{
8381 name: "ExportKeyingMaterial-FalseStart",
8382 config: Config{
8383 MaxVersion: VersionTLS12,
8384 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8385 NextProtos: []string{"foo"},
8386 Bugs: ProtocolBugs{
8387 ExpectFalseStart: true,
8388 },
8389 },
8390 flags: []string{
8391 "-false-start",
8392 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008393 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008394 },
8395 shimWritesFirst: true,
8396 exportKeyingMaterial: 1024,
8397 exportLabel: "label",
8398 exportContext: "context",
8399 useExportContext: true,
8400 })
8401
8402 // Exporters do not work in the middle of a renegotiation. Test this by
8403 // triggering the exporter after every SSL_read call and configuring the
8404 // shim to run asynchronously.
8405 testCases = append(testCases, testCase{
8406 name: "ExportKeyingMaterial-Renegotiate",
8407 config: Config{
8408 MaxVersion: VersionTLS12,
8409 },
8410 renegotiate: 1,
8411 flags: []string{
8412 "-async",
8413 "-use-exporter-between-reads",
8414 "-renegotiate-freely",
8415 "-expect-total-renegotiations", "1",
8416 },
8417 shouldFail: true,
8418 expectedError: "failed to export keying material",
8419 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008420}
8421
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008422func addTLSUniqueTests() {
8423 for _, isClient := range []bool{false, true} {
8424 for _, isResumption := range []bool{false, true} {
8425 for _, hasEMS := range []bool{false, true} {
8426 var suffix string
8427 if isResumption {
8428 suffix = "Resume-"
8429 } else {
8430 suffix = "Full-"
8431 }
8432
8433 if hasEMS {
8434 suffix += "EMS-"
8435 } else {
8436 suffix += "NoEMS-"
8437 }
8438
8439 if isClient {
8440 suffix += "Client"
8441 } else {
8442 suffix += "Server"
8443 }
8444
8445 test := testCase{
8446 name: "TLSUnique-" + suffix,
8447 testTLSUnique: true,
8448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008449 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008450 Bugs: ProtocolBugs{
8451 NoExtendedMasterSecret: !hasEMS,
8452 },
8453 },
8454 }
8455
8456 if isResumption {
8457 test.resumeSession = true
8458 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008459 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008460 Bugs: ProtocolBugs{
8461 NoExtendedMasterSecret: !hasEMS,
8462 },
8463 }
8464 }
8465
8466 if isResumption && !hasEMS {
8467 test.shouldFail = true
8468 test.expectedError = "failed to get tls-unique"
8469 }
8470
8471 testCases = append(testCases, test)
8472 }
8473 }
8474 }
8475}
8476
Adam Langley09505632015-07-30 18:10:13 -07008477func addCustomExtensionTests() {
8478 expectedContents := "custom extension"
8479 emptyString := ""
8480
8481 for _, isClient := range []bool{false, true} {
8482 suffix := "Server"
8483 flag := "-enable-server-custom-extension"
8484 testType := serverTest
8485 if isClient {
8486 suffix = "Client"
8487 flag = "-enable-client-custom-extension"
8488 testType = clientTest
8489 }
8490
8491 testCases = append(testCases, testCase{
8492 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008493 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008494 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008495 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008496 Bugs: ProtocolBugs{
8497 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008498 ExpectedCustomExtension: &expectedContents,
8499 },
8500 },
8501 flags: []string{flag},
8502 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008503 testCases = append(testCases, testCase{
8504 testType: testType,
8505 name: "CustomExtensions-" + suffix + "-TLS13",
8506 config: Config{
8507 MaxVersion: VersionTLS13,
8508 Bugs: ProtocolBugs{
8509 CustomExtension: expectedContents,
8510 ExpectedCustomExtension: &expectedContents,
8511 },
8512 },
8513 flags: []string{flag},
8514 })
Adam Langley09505632015-07-30 18:10:13 -07008515
Steven Valdez2a070722017-03-25 20:54:16 -05008516 // 0-RTT is not currently supported with Custom Extensions.
8517 testCases = append(testCases, testCase{
8518 testType: testType,
8519 name: "CustomExtensions-" + suffix + "-EarlyData",
8520 config: Config{
8521 MaxVersion: VersionTLS13,
8522 Bugs: ProtocolBugs{
8523 CustomExtension: expectedContents,
8524 ExpectedCustomExtension: &expectedContents,
8525 },
8526 },
8527 shouldFail: true,
8528 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8529 flags: []string{flag, "-enable-early-data"},
8530 })
8531
Adam Langley09505632015-07-30 18:10:13 -07008532 // If the parse callback fails, the handshake should also fail.
8533 testCases = append(testCases, testCase{
8534 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008535 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008536 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008537 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008538 Bugs: ProtocolBugs{
8539 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008540 ExpectedCustomExtension: &expectedContents,
8541 },
8542 },
David Benjamin399e7c92015-07-30 23:01:27 -04008543 flags: []string{flag},
8544 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008545 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8546 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008547 testCases = append(testCases, testCase{
8548 testType: testType,
8549 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8550 config: Config{
8551 MaxVersion: VersionTLS13,
8552 Bugs: ProtocolBugs{
8553 CustomExtension: expectedContents + "foo",
8554 ExpectedCustomExtension: &expectedContents,
8555 },
8556 },
8557 flags: []string{flag},
8558 shouldFail: true,
8559 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8560 })
Adam Langley09505632015-07-30 18:10:13 -07008561
8562 // If the add callback fails, the handshake should also fail.
8563 testCases = append(testCases, testCase{
8564 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008565 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008567 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008568 Bugs: ProtocolBugs{
8569 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008570 ExpectedCustomExtension: &expectedContents,
8571 },
8572 },
David Benjamin399e7c92015-07-30 23:01:27 -04008573 flags: []string{flag, "-custom-extension-fail-add"},
8574 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008575 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8576 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008577 testCases = append(testCases, testCase{
8578 testType: testType,
8579 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8580 config: Config{
8581 MaxVersion: VersionTLS13,
8582 Bugs: ProtocolBugs{
8583 CustomExtension: expectedContents,
8584 ExpectedCustomExtension: &expectedContents,
8585 },
8586 },
8587 flags: []string{flag, "-custom-extension-fail-add"},
8588 shouldFail: true,
8589 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8590 })
Adam Langley09505632015-07-30 18:10:13 -07008591
8592 // If the add callback returns zero, no extension should be
8593 // added.
8594 skipCustomExtension := expectedContents
8595 if isClient {
8596 // For the case where the client skips sending the
8597 // custom extension, the server must not “echo” it.
8598 skipCustomExtension = ""
8599 }
8600 testCases = append(testCases, testCase{
8601 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008602 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008604 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008605 Bugs: ProtocolBugs{
8606 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008607 ExpectedCustomExtension: &emptyString,
8608 },
8609 },
8610 flags: []string{flag, "-custom-extension-skip"},
8611 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008612 testCases = append(testCases, testCase{
8613 testType: testType,
8614 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8615 config: Config{
8616 MaxVersion: VersionTLS13,
8617 Bugs: ProtocolBugs{
8618 CustomExtension: skipCustomExtension,
8619 ExpectedCustomExtension: &emptyString,
8620 },
8621 },
8622 flags: []string{flag, "-custom-extension-skip"},
8623 })
Adam Langley09505632015-07-30 18:10:13 -07008624 }
8625
8626 // The custom extension add callback should not be called if the client
8627 // doesn't send the extension.
8628 testCases = append(testCases, testCase{
8629 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008630 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008631 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008632 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008633 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008634 ExpectedCustomExtension: &emptyString,
8635 },
8636 },
8637 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8638 })
Adam Langley2deb9842015-08-07 11:15:37 -07008639
Steven Valdez143e8b32016-07-11 13:19:03 -04008640 testCases = append(testCases, testCase{
8641 testType: serverTest,
8642 name: "CustomExtensions-NotCalled-Server-TLS13",
8643 config: Config{
8644 MaxVersion: VersionTLS13,
8645 Bugs: ProtocolBugs{
8646 ExpectedCustomExtension: &emptyString,
8647 },
8648 },
8649 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8650 })
8651
Adam Langley2deb9842015-08-07 11:15:37 -07008652 // Test an unknown extension from the server.
8653 testCases = append(testCases, testCase{
8654 testType: clientTest,
8655 name: "UnknownExtension-Client",
8656 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008657 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008658 Bugs: ProtocolBugs{
8659 CustomExtension: expectedContents,
8660 },
8661 },
David Benjamin0c40a962016-08-01 12:05:50 -04008662 shouldFail: true,
8663 expectedError: ":UNEXPECTED_EXTENSION:",
8664 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008665 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008666 testCases = append(testCases, testCase{
8667 testType: clientTest,
8668 name: "UnknownExtension-Client-TLS13",
8669 config: Config{
8670 MaxVersion: VersionTLS13,
8671 Bugs: ProtocolBugs{
8672 CustomExtension: expectedContents,
8673 },
8674 },
David Benjamin0c40a962016-08-01 12:05:50 -04008675 shouldFail: true,
8676 expectedError: ":UNEXPECTED_EXTENSION:",
8677 expectedLocalError: "remote error: unsupported extension",
8678 })
David Benjamin490469f2016-10-05 22:44:38 -04008679 testCases = append(testCases, testCase{
8680 testType: clientTest,
8681 name: "UnknownUnencryptedExtension-Client-TLS13",
8682 config: Config{
8683 MaxVersion: VersionTLS13,
8684 Bugs: ProtocolBugs{
8685 CustomUnencryptedExtension: expectedContents,
8686 },
8687 },
8688 shouldFail: true,
8689 expectedError: ":UNEXPECTED_EXTENSION:",
8690 // The shim must send an alert, but alerts at this point do not
8691 // get successfully decrypted by the runner.
8692 expectedLocalError: "local error: bad record MAC",
8693 })
8694 testCases = append(testCases, testCase{
8695 testType: clientTest,
8696 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8697 config: Config{
8698 MaxVersion: VersionTLS13,
8699 Bugs: ProtocolBugs{
8700 SendUnencryptedALPN: "foo",
8701 },
8702 },
8703 flags: []string{
8704 "-advertise-alpn", "\x03foo\x03bar",
8705 },
8706 shouldFail: true,
8707 expectedError: ":UNEXPECTED_EXTENSION:",
8708 // The shim must send an alert, but alerts at this point do not
8709 // get successfully decrypted by the runner.
8710 expectedLocalError: "local error: bad record MAC",
8711 })
David Benjamin0c40a962016-08-01 12:05:50 -04008712
8713 // Test a known but unoffered extension from the server.
8714 testCases = append(testCases, testCase{
8715 testType: clientTest,
8716 name: "UnofferedExtension-Client",
8717 config: Config{
8718 MaxVersion: VersionTLS12,
8719 Bugs: ProtocolBugs{
8720 SendALPN: "alpn",
8721 },
8722 },
8723 shouldFail: true,
8724 expectedError: ":UNEXPECTED_EXTENSION:",
8725 expectedLocalError: "remote error: unsupported extension",
8726 })
8727 testCases = append(testCases, testCase{
8728 testType: clientTest,
8729 name: "UnofferedExtension-Client-TLS13",
8730 config: Config{
8731 MaxVersion: VersionTLS13,
8732 Bugs: ProtocolBugs{
8733 SendALPN: "alpn",
8734 },
8735 },
8736 shouldFail: true,
8737 expectedError: ":UNEXPECTED_EXTENSION:",
8738 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008739 })
Adam Langley09505632015-07-30 18:10:13 -07008740}
8741
David Benjaminb36a3952015-12-01 18:53:13 -05008742func addRSAClientKeyExchangeTests() {
8743 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8744 testCases = append(testCases, testCase{
8745 testType: serverTest,
8746 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8747 config: Config{
8748 // Ensure the ClientHello version and final
8749 // version are different, to detect if the
8750 // server uses the wrong one.
8751 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008752 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008753 Bugs: ProtocolBugs{
8754 BadRSAClientKeyExchange: bad,
8755 },
8756 },
8757 shouldFail: true,
8758 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8759 })
8760 }
David Benjamine63d9d72016-09-19 18:27:34 -04008761
8762 // The server must compare whatever was in ClientHello.version for the
8763 // RSA premaster.
8764 testCases = append(testCases, testCase{
8765 testType: serverTest,
8766 name: "SendClientVersion-RSA",
8767 config: Config{
8768 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8769 Bugs: ProtocolBugs{
8770 SendClientVersion: 0x1234,
8771 },
8772 },
8773 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8774 })
David Benjaminb36a3952015-12-01 18:53:13 -05008775}
8776
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008777var testCurves = []struct {
8778 name string
8779 id CurveID
8780}{
Adam Langley764ab982017-03-10 18:01:30 -08008781 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008782 {"P-256", CurveP256},
8783 {"P-384", CurveP384},
8784 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008785 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008786}
8787
Steven Valdez5440fe02016-07-18 12:40:30 -04008788const bogusCurve = 0x1234
8789
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008790func addCurveTests() {
8791 for _, curve := range testCurves {
8792 testCases = append(testCases, testCase{
8793 name: "CurveTest-Client-" + curve.name,
8794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008795 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8797 CurvePreferences: []CurveID{curve.id},
8798 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008799 flags: []string{
8800 "-enable-all-curves",
8801 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8802 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008803 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008804 })
8805 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008806 name: "CurveTest-Client-" + curve.name + "-TLS13",
8807 config: Config{
8808 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008809 CurvePreferences: []CurveID{curve.id},
8810 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008811 flags: []string{
8812 "-enable-all-curves",
8813 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8814 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008815 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008816 })
8817 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008818 testType: serverTest,
8819 name: "CurveTest-Server-" + curve.name,
8820 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008821 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008822 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8823 CurvePreferences: []CurveID{curve.id},
8824 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008825 flags: []string{
8826 "-enable-all-curves",
8827 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8828 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008829 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008830 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008831 testCases = append(testCases, testCase{
8832 testType: serverTest,
8833 name: "CurveTest-Server-" + curve.name + "-TLS13",
8834 config: Config{
8835 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008836 CurvePreferences: []CurveID{curve.id},
8837 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008838 flags: []string{
8839 "-enable-all-curves",
8840 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8841 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008842 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008843 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008844 }
David Benjamin241ae832016-01-15 03:04:54 -05008845
8846 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008847 testCases = append(testCases, testCase{
8848 testType: serverTest,
8849 name: "UnknownCurve",
8850 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008851 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8853 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8854 },
8855 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008856
Steven Valdez803c77a2016-09-06 14:13:43 -04008857 // The server must be tolerant to bogus curves.
8858 testCases = append(testCases, testCase{
8859 testType: serverTest,
8860 name: "UnknownCurve-TLS13",
8861 config: Config{
8862 MaxVersion: VersionTLS13,
8863 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8864 },
8865 })
8866
David Benjamin4c3ddf72016-06-29 18:13:53 -04008867 // The server must not consider ECDHE ciphers when there are no
8868 // supported curves.
8869 testCases = append(testCases, testCase{
8870 testType: serverTest,
8871 name: "NoSupportedCurves",
8872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008873 MaxVersion: VersionTLS12,
8874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8875 Bugs: ProtocolBugs{
8876 NoSupportedCurves: true,
8877 },
8878 },
8879 shouldFail: true,
8880 expectedError: ":NO_SHARED_CIPHER:",
8881 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008882 testCases = append(testCases, testCase{
8883 testType: serverTest,
8884 name: "NoSupportedCurves-TLS13",
8885 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008886 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008887 Bugs: ProtocolBugs{
8888 NoSupportedCurves: true,
8889 },
8890 },
8891 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008892 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008893 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008894
8895 // The server must fall back to another cipher when there are no
8896 // supported curves.
8897 testCases = append(testCases, testCase{
8898 testType: serverTest,
8899 name: "NoCommonCurves",
8900 config: Config{
8901 MaxVersion: VersionTLS12,
8902 CipherSuites: []uint16{
8903 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008904 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008905 },
8906 CurvePreferences: []CurveID{CurveP224},
8907 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008908 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008909 })
8910
8911 // The client must reject bogus curves and disabled curves.
8912 testCases = append(testCases, testCase{
8913 name: "BadECDHECurve",
8914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008915 MaxVersion: VersionTLS12,
8916 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8917 Bugs: ProtocolBugs{
8918 SendCurve: bogusCurve,
8919 },
8920 },
8921 shouldFail: true,
8922 expectedError: ":WRONG_CURVE:",
8923 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008924 testCases = append(testCases, testCase{
8925 name: "BadECDHECurve-TLS13",
8926 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008927 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008928 Bugs: ProtocolBugs{
8929 SendCurve: bogusCurve,
8930 },
8931 },
8932 shouldFail: true,
8933 expectedError: ":WRONG_CURVE:",
8934 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008935
8936 testCases = append(testCases, testCase{
8937 name: "UnsupportedCurve",
8938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008939 MaxVersion: VersionTLS12,
8940 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8941 CurvePreferences: []CurveID{CurveP256},
8942 Bugs: ProtocolBugs{
8943 IgnorePeerCurvePreferences: true,
8944 },
8945 },
8946 flags: []string{"-p384-only"},
8947 shouldFail: true,
8948 expectedError: ":WRONG_CURVE:",
8949 })
8950
David Benjamin4f921572016-07-17 14:20:10 +02008951 testCases = append(testCases, testCase{
8952 // TODO(davidben): Add a TLS 1.3 version where
8953 // HelloRetryRequest requests an unsupported curve.
8954 name: "UnsupportedCurve-ServerHello-TLS13",
8955 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008956 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008957 CurvePreferences: []CurveID{CurveP384},
8958 Bugs: ProtocolBugs{
8959 SendCurve: CurveP256,
8960 },
8961 },
8962 flags: []string{"-p384-only"},
8963 shouldFail: true,
8964 expectedError: ":WRONG_CURVE:",
8965 })
8966
David Benjamin4c3ddf72016-06-29 18:13:53 -04008967 // Test invalid curve points.
8968 testCases = append(testCases, testCase{
8969 name: "InvalidECDHPoint-Client",
8970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008971 MaxVersion: VersionTLS12,
8972 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8973 CurvePreferences: []CurveID{CurveP256},
8974 Bugs: ProtocolBugs{
8975 InvalidECDHPoint: true,
8976 },
8977 },
8978 shouldFail: true,
8979 expectedError: ":INVALID_ENCODING:",
8980 })
8981 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008982 name: "InvalidECDHPoint-Client-TLS13",
8983 config: Config{
8984 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008985 CurvePreferences: []CurveID{CurveP256},
8986 Bugs: ProtocolBugs{
8987 InvalidECDHPoint: true,
8988 },
8989 },
8990 shouldFail: true,
8991 expectedError: ":INVALID_ENCODING:",
8992 })
8993 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008994 testType: serverTest,
8995 name: "InvalidECDHPoint-Server",
8996 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008997 MaxVersion: VersionTLS12,
8998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8999 CurvePreferences: []CurveID{CurveP256},
9000 Bugs: ProtocolBugs{
9001 InvalidECDHPoint: true,
9002 },
9003 },
9004 shouldFail: true,
9005 expectedError: ":INVALID_ENCODING:",
9006 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009007 testCases = append(testCases, testCase{
9008 testType: serverTest,
9009 name: "InvalidECDHPoint-Server-TLS13",
9010 config: Config{
9011 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009012 CurvePreferences: []CurveID{CurveP256},
9013 Bugs: ProtocolBugs{
9014 InvalidECDHPoint: true,
9015 },
9016 },
9017 shouldFail: true,
9018 expectedError: ":INVALID_ENCODING:",
9019 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009020
9021 // The previous curve ID should be reported on TLS 1.2 resumption.
9022 testCases = append(testCases, testCase{
9023 name: "CurveID-Resume-Client",
9024 config: Config{
9025 MaxVersion: VersionTLS12,
9026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9027 CurvePreferences: []CurveID{CurveX25519},
9028 },
9029 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9030 resumeSession: true,
9031 })
9032 testCases = append(testCases, testCase{
9033 testType: serverTest,
9034 name: "CurveID-Resume-Server",
9035 config: Config{
9036 MaxVersion: VersionTLS12,
9037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9038 CurvePreferences: []CurveID{CurveX25519},
9039 },
9040 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9041 resumeSession: true,
9042 })
9043
9044 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9045 // one should be reported.
9046 testCases = append(testCases, testCase{
9047 name: "CurveID-Resume-Client-TLS13",
9048 config: Config{
9049 MaxVersion: VersionTLS13,
9050 CurvePreferences: []CurveID{CurveX25519},
9051 },
9052 resumeConfig: &Config{
9053 MaxVersion: VersionTLS13,
9054 CurvePreferences: []CurveID{CurveP256},
9055 },
9056 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009057 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9058 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009059 },
9060 resumeSession: true,
9061 })
9062 testCases = append(testCases, testCase{
9063 testType: serverTest,
9064 name: "CurveID-Resume-Server-TLS13",
9065 config: Config{
9066 MaxVersion: VersionTLS13,
9067 CurvePreferences: []CurveID{CurveX25519},
9068 },
9069 resumeConfig: &Config{
9070 MaxVersion: VersionTLS13,
9071 CurvePreferences: []CurveID{CurveP256},
9072 },
9073 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009074 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9075 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009076 },
9077 resumeSession: true,
9078 })
David Benjamina81967b2016-12-22 09:16:57 -05009079
9080 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9081 testCases = append(testCases, testCase{
9082 name: "PointFormat-ServerHello-TLS12",
9083 config: Config{
9084 MaxVersion: VersionTLS12,
9085 Bugs: ProtocolBugs{
9086 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9087 },
9088 },
9089 })
9090 testCases = append(testCases, testCase{
9091 name: "PointFormat-EncryptedExtensions-TLS13",
9092 config: Config{
9093 MaxVersion: VersionTLS13,
9094 Bugs: ProtocolBugs{
9095 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9096 },
9097 },
9098 shouldFail: true,
9099 expectedError: ":ERROR_PARSING_EXTENSION:",
9100 })
9101
9102 // Test that we tolerate unknown point formats, as long as
9103 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9104 // check they are still functional.
9105 testCases = append(testCases, testCase{
9106 name: "PointFormat-Client-Tolerance",
9107 config: Config{
9108 MaxVersion: VersionTLS12,
9109 Bugs: ProtocolBugs{
9110 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9111 },
9112 },
9113 })
9114 testCases = append(testCases, testCase{
9115 testType: serverTest,
9116 name: "PointFormat-Server-Tolerance",
9117 config: Config{
9118 MaxVersion: VersionTLS12,
9119 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9120 Bugs: ProtocolBugs{
9121 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9122 },
9123 },
9124 })
9125
9126 // Test TLS 1.2 does not require the point format extension to be
9127 // present.
9128 testCases = append(testCases, testCase{
9129 name: "PointFormat-Client-Missing",
9130 config: Config{
9131 MaxVersion: VersionTLS12,
9132 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9133 Bugs: ProtocolBugs{
9134 SendSupportedPointFormats: []byte{},
9135 },
9136 },
9137 })
9138 testCases = append(testCases, testCase{
9139 testType: serverTest,
9140 name: "PointFormat-Server-Missing",
9141 config: Config{
9142 MaxVersion: VersionTLS12,
9143 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9144 Bugs: ProtocolBugs{
9145 SendSupportedPointFormats: []byte{},
9146 },
9147 },
9148 })
9149
9150 // If the point format extension is present, uncompressed points must be
9151 // offered. BoringSSL requires this whether or not ECDHE is used.
9152 testCases = append(testCases, testCase{
9153 name: "PointFormat-Client-MissingUncompressed",
9154 config: Config{
9155 MaxVersion: VersionTLS12,
9156 Bugs: ProtocolBugs{
9157 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9158 },
9159 },
9160 shouldFail: true,
9161 expectedError: ":ERROR_PARSING_EXTENSION:",
9162 })
9163 testCases = append(testCases, testCase{
9164 testType: serverTest,
9165 name: "PointFormat-Server-MissingUncompressed",
9166 config: Config{
9167 MaxVersion: VersionTLS12,
9168 Bugs: ProtocolBugs{
9169 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9170 },
9171 },
9172 shouldFail: true,
9173 expectedError: ":ERROR_PARSING_EXTENSION:",
9174 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009175}
9176
David Benjaminc9ae27c2016-06-24 22:56:37 -04009177func addTLS13RecordTests() {
9178 testCases = append(testCases, testCase{
9179 name: "TLS13-RecordPadding",
9180 config: Config{
9181 MaxVersion: VersionTLS13,
9182 MinVersion: VersionTLS13,
9183 Bugs: ProtocolBugs{
9184 RecordPadding: 10,
9185 },
9186 },
9187 })
9188
9189 testCases = append(testCases, testCase{
9190 name: "TLS13-EmptyRecords",
9191 config: Config{
9192 MaxVersion: VersionTLS13,
9193 MinVersion: VersionTLS13,
9194 Bugs: ProtocolBugs{
9195 OmitRecordContents: true,
9196 },
9197 },
9198 shouldFail: true,
9199 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9200 })
9201
9202 testCases = append(testCases, testCase{
9203 name: "TLS13-OnlyPadding",
9204 config: Config{
9205 MaxVersion: VersionTLS13,
9206 MinVersion: VersionTLS13,
9207 Bugs: ProtocolBugs{
9208 OmitRecordContents: true,
9209 RecordPadding: 10,
9210 },
9211 },
9212 shouldFail: true,
9213 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9214 })
9215
9216 testCases = append(testCases, testCase{
9217 name: "TLS13-WrongOuterRecord",
9218 config: Config{
9219 MaxVersion: VersionTLS13,
9220 MinVersion: VersionTLS13,
9221 Bugs: ProtocolBugs{
9222 OuterRecordType: recordTypeHandshake,
9223 },
9224 },
9225 shouldFail: true,
9226 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9227 })
9228}
9229
Steven Valdez5b986082016-09-01 12:29:49 -04009230func addSessionTicketTests() {
9231 testCases = append(testCases, testCase{
9232 // In TLS 1.2 and below, empty NewSessionTicket messages
9233 // mean the server changed its mind on sending a ticket.
9234 name: "SendEmptySessionTicket",
9235 config: Config{
9236 MaxVersion: VersionTLS12,
9237 Bugs: ProtocolBugs{
9238 SendEmptySessionTicket: true,
9239 },
9240 },
9241 flags: []string{"-expect-no-session"},
9242 })
9243
9244 // Test that the server ignores unknown PSK modes.
9245 testCases = append(testCases, testCase{
9246 testType: serverTest,
9247 name: "TLS13-SendUnknownModeSessionTicket-Server",
9248 config: Config{
9249 MaxVersion: VersionTLS13,
9250 Bugs: ProtocolBugs{
9251 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009252 },
9253 },
9254 resumeSession: true,
9255 expectedResumeVersion: VersionTLS13,
9256 })
9257
Steven Valdeza833c352016-11-01 13:39:36 -04009258 // Test that the server does not send session tickets with no matching key exchange mode.
9259 testCases = append(testCases, testCase{
9260 testType: serverTest,
9261 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9262 config: Config{
9263 MaxVersion: VersionTLS13,
9264 Bugs: ProtocolBugs{
9265 SendPSKKeyExchangeModes: []byte{0x1a},
9266 ExpectNoNewSessionTicket: true,
9267 },
9268 },
9269 })
9270
9271 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009272 testCases = append(testCases, testCase{
9273 testType: serverTest,
9274 name: "TLS13-SendBadKEModeSessionTicket-Server",
9275 config: Config{
9276 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009277 },
9278 resumeConfig: &Config{
9279 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009280 Bugs: ProtocolBugs{
9281 SendPSKKeyExchangeModes: []byte{0x1a},
9282 },
9283 },
9284 resumeSession: true,
9285 expectResumeRejected: true,
9286 })
9287
Steven Valdeza833c352016-11-01 13:39:36 -04009288 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009289 testCases = append(testCases, testCase{
9290 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009291 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009292 config: Config{
9293 MaxVersion: VersionTLS13,
9294 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009295 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009296 },
9297 },
Steven Valdeza833c352016-11-01 13:39:36 -04009298 resumeSession: true,
9299 flags: []string{
9300 "-resumption-delay", "10",
9301 },
Steven Valdez5b986082016-09-01 12:29:49 -04009302 })
9303
Steven Valdeza833c352016-11-01 13:39:36 -04009304 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009305 testCases = append(testCases, testCase{
9306 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009307 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009308 config: Config{
9309 MaxVersion: VersionTLS13,
9310 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009311 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009312 },
9313 },
Steven Valdeza833c352016-11-01 13:39:36 -04009314 resumeSession: true,
9315 shouldFail: true,
9316 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009317 })
9318
David Benjamin35ac5b72017-03-03 15:05:56 -05009319 // Test that the server's ticket age skew reporting works.
9320 testCases = append(testCases, testCase{
9321 testType: serverTest,
9322 name: "TLS13-TicketAgeSkew-Forward",
9323 config: Config{
9324 MaxVersion: VersionTLS13,
9325 Bugs: ProtocolBugs{
9326 SendTicketAge: 15 * time.Second,
9327 },
9328 },
David Benjamin065d7332017-03-26 10:51:43 -05009329 resumeSession: true,
9330 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009331 flags: []string{
9332 "-resumption-delay", "10",
9333 "-expect-ticket-age-skew", "5",
9334 },
9335 })
9336 testCases = append(testCases, testCase{
9337 testType: serverTest,
9338 name: "TLS13-TicketAgeSkew-Backward",
9339 config: Config{
9340 MaxVersion: VersionTLS13,
9341 Bugs: ProtocolBugs{
9342 SendTicketAge: 5 * time.Second,
9343 },
9344 },
David Benjamin065d7332017-03-26 10:51:43 -05009345 resumeSession: true,
9346 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009347 flags: []string{
9348 "-resumption-delay", "10",
9349 "-expect-ticket-age-skew", "-5",
9350 },
9351 })
9352
Steven Valdez08b65f42016-12-07 15:29:45 -05009353 testCases = append(testCases, testCase{
9354 testType: clientTest,
9355 name: "TLS13-SendTicketEarlyDataInfo",
9356 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009357 MaxVersion: VersionTLS13,
9358 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009359 },
9360 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009361 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009362 "-expect-early-data-info",
9363 },
9364 })
9365
David Benjamin9b160662017-01-25 19:53:43 -05009366 // Test that 0-RTT tickets are ignored in clients unless opted in.
9367 testCases = append(testCases, testCase{
9368 testType: clientTest,
9369 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9370 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009371 MaxVersion: VersionTLS13,
9372 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009373 },
9374 })
9375
Steven Valdez08b65f42016-12-07 15:29:45 -05009376 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009377 testType: clientTest,
9378 name: "TLS13-DuplicateTicketEarlyDataInfo",
9379 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009380 MaxVersion: VersionTLS13,
9381 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009382 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009383 DuplicateTicketEarlyDataInfo: true,
9384 },
9385 },
9386 shouldFail: true,
9387 expectedError: ":DUPLICATE_EXTENSION:",
9388 expectedLocalError: "remote error: illegal parameter",
9389 })
9390
9391 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009392 testType: serverTest,
9393 name: "TLS13-ExpectTicketEarlyDataInfo",
9394 config: Config{
9395 MaxVersion: VersionTLS13,
9396 Bugs: ProtocolBugs{
9397 ExpectTicketEarlyDataInfo: true,
9398 },
9399 },
9400 flags: []string{
9401 "-enable-early-data",
9402 },
9403 })
David Benjamin17b30832017-01-28 14:00:32 -05009404
9405 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9406 // is honored.
9407 testCases = append(testCases, testCase{
9408 testType: clientTest,
9409 name: "TLS13-HonorServerSessionTicketLifetime",
9410 config: Config{
9411 MaxVersion: VersionTLS13,
9412 Bugs: ProtocolBugs{
9413 SendTicketLifetime: 20 * time.Second,
9414 },
9415 },
9416 flags: []string{
9417 "-resumption-delay", "19",
9418 },
9419 resumeSession: true,
9420 })
9421 testCases = append(testCases, testCase{
9422 testType: clientTest,
9423 name: "TLS13-HonorServerSessionTicketLifetime-2",
9424 config: Config{
9425 MaxVersion: VersionTLS13,
9426 Bugs: ProtocolBugs{
9427 SendTicketLifetime: 20 * time.Second,
9428 // The client should not offer the expired session.
9429 ExpectNoTLS13PSK: true,
9430 },
9431 },
9432 flags: []string{
9433 "-resumption-delay", "21",
9434 },
David Benjamin023d4192017-02-06 13:49:07 -05009435 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009436 expectResumeRejected: true,
9437 })
Steven Valdez5b986082016-09-01 12:29:49 -04009438}
9439
David Benjamin82261be2016-07-07 14:32:50 -07009440func addChangeCipherSpecTests() {
9441 // Test missing ChangeCipherSpecs.
9442 testCases = append(testCases, testCase{
9443 name: "SkipChangeCipherSpec-Client",
9444 config: Config{
9445 MaxVersion: VersionTLS12,
9446 Bugs: ProtocolBugs{
9447 SkipChangeCipherSpec: true,
9448 },
9449 },
9450 shouldFail: true,
9451 expectedError: ":UNEXPECTED_RECORD:",
9452 })
9453 testCases = append(testCases, testCase{
9454 testType: serverTest,
9455 name: "SkipChangeCipherSpec-Server",
9456 config: Config{
9457 MaxVersion: VersionTLS12,
9458 Bugs: ProtocolBugs{
9459 SkipChangeCipherSpec: true,
9460 },
9461 },
9462 shouldFail: true,
9463 expectedError: ":UNEXPECTED_RECORD:",
9464 })
9465 testCases = append(testCases, testCase{
9466 testType: serverTest,
9467 name: "SkipChangeCipherSpec-Server-NPN",
9468 config: Config{
9469 MaxVersion: VersionTLS12,
9470 NextProtos: []string{"bar"},
9471 Bugs: ProtocolBugs{
9472 SkipChangeCipherSpec: true,
9473 },
9474 },
9475 flags: []string{
9476 "-advertise-npn", "\x03foo\x03bar\x03baz",
9477 },
9478 shouldFail: true,
9479 expectedError: ":UNEXPECTED_RECORD:",
9480 })
9481
9482 // Test synchronization between the handshake and ChangeCipherSpec.
9483 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9484 // rejected. Test both with and without handshake packing to handle both
9485 // when the partial post-CCS message is in its own record and when it is
9486 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009487 for _, packed := range []bool{false, true} {
9488 var suffix string
9489 if packed {
9490 suffix = "-Packed"
9491 }
9492
9493 testCases = append(testCases, testCase{
9494 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9495 config: Config{
9496 MaxVersion: VersionTLS12,
9497 Bugs: ProtocolBugs{
9498 FragmentAcrossChangeCipherSpec: true,
9499 PackHandshakeFlight: packed,
9500 },
9501 },
9502 shouldFail: true,
9503 expectedError: ":UNEXPECTED_RECORD:",
9504 })
9505 testCases = append(testCases, testCase{
9506 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9507 config: Config{
9508 MaxVersion: VersionTLS12,
9509 },
9510 resumeSession: true,
9511 resumeConfig: &Config{
9512 MaxVersion: VersionTLS12,
9513 Bugs: ProtocolBugs{
9514 FragmentAcrossChangeCipherSpec: true,
9515 PackHandshakeFlight: packed,
9516 },
9517 },
9518 shouldFail: true,
9519 expectedError: ":UNEXPECTED_RECORD:",
9520 })
9521 testCases = append(testCases, testCase{
9522 testType: serverTest,
9523 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9524 config: Config{
9525 MaxVersion: VersionTLS12,
9526 Bugs: ProtocolBugs{
9527 FragmentAcrossChangeCipherSpec: true,
9528 PackHandshakeFlight: packed,
9529 },
9530 },
9531 shouldFail: true,
9532 expectedError: ":UNEXPECTED_RECORD:",
9533 })
9534 testCases = append(testCases, testCase{
9535 testType: serverTest,
9536 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9537 config: Config{
9538 MaxVersion: VersionTLS12,
9539 },
9540 resumeSession: true,
9541 resumeConfig: &Config{
9542 MaxVersion: VersionTLS12,
9543 Bugs: ProtocolBugs{
9544 FragmentAcrossChangeCipherSpec: true,
9545 PackHandshakeFlight: packed,
9546 },
9547 },
9548 shouldFail: true,
9549 expectedError: ":UNEXPECTED_RECORD:",
9550 })
9551 testCases = append(testCases, testCase{
9552 testType: serverTest,
9553 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9554 config: Config{
9555 MaxVersion: VersionTLS12,
9556 NextProtos: []string{"bar"},
9557 Bugs: ProtocolBugs{
9558 FragmentAcrossChangeCipherSpec: true,
9559 PackHandshakeFlight: packed,
9560 },
9561 },
9562 flags: []string{
9563 "-advertise-npn", "\x03foo\x03bar\x03baz",
9564 },
9565 shouldFail: true,
9566 expectedError: ":UNEXPECTED_RECORD:",
9567 })
9568 }
9569
David Benjamin61672812016-07-14 23:10:43 -04009570 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9571 // messages in the handshake queue. Do this by testing the server
9572 // reading the client Finished, reversing the flight so Finished comes
9573 // first.
9574 testCases = append(testCases, testCase{
9575 protocol: dtls,
9576 testType: serverTest,
9577 name: "SendUnencryptedFinished-DTLS",
9578 config: Config{
9579 MaxVersion: VersionTLS12,
9580 Bugs: ProtocolBugs{
9581 SendUnencryptedFinished: true,
9582 ReverseHandshakeFragments: true,
9583 },
9584 },
9585 shouldFail: true,
9586 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9587 })
9588
Steven Valdez143e8b32016-07-11 13:19:03 -04009589 // Test synchronization between encryption changes and the handshake in
9590 // TLS 1.3, where ChangeCipherSpec is implicit.
9591 testCases = append(testCases, testCase{
9592 name: "PartialEncryptedExtensionsWithServerHello",
9593 config: Config{
9594 MaxVersion: VersionTLS13,
9595 Bugs: ProtocolBugs{
9596 PartialEncryptedExtensionsWithServerHello: true,
9597 },
9598 },
9599 shouldFail: true,
9600 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9601 })
9602 testCases = append(testCases, testCase{
9603 testType: serverTest,
9604 name: "PartialClientFinishedWithClientHello",
9605 config: Config{
9606 MaxVersion: VersionTLS13,
9607 Bugs: ProtocolBugs{
9608 PartialClientFinishedWithClientHello: true,
9609 },
9610 },
9611 shouldFail: true,
9612 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9613 })
9614
David Benjamin82261be2016-07-07 14:32:50 -07009615 // Test that early ChangeCipherSpecs are handled correctly.
9616 testCases = append(testCases, testCase{
9617 testType: serverTest,
9618 name: "EarlyChangeCipherSpec-server-1",
9619 config: Config{
9620 MaxVersion: VersionTLS12,
9621 Bugs: ProtocolBugs{
9622 EarlyChangeCipherSpec: 1,
9623 },
9624 },
9625 shouldFail: true,
9626 expectedError: ":UNEXPECTED_RECORD:",
9627 })
9628 testCases = append(testCases, testCase{
9629 testType: serverTest,
9630 name: "EarlyChangeCipherSpec-server-2",
9631 config: Config{
9632 MaxVersion: VersionTLS12,
9633 Bugs: ProtocolBugs{
9634 EarlyChangeCipherSpec: 2,
9635 },
9636 },
9637 shouldFail: true,
9638 expectedError: ":UNEXPECTED_RECORD:",
9639 })
9640 testCases = append(testCases, testCase{
9641 protocol: dtls,
9642 name: "StrayChangeCipherSpec",
9643 config: Config{
9644 // TODO(davidben): Once DTLS 1.3 exists, test
9645 // that stray ChangeCipherSpec messages are
9646 // rejected.
9647 MaxVersion: VersionTLS12,
9648 Bugs: ProtocolBugs{
9649 StrayChangeCipherSpec: true,
9650 },
9651 },
9652 })
9653
9654 // Test that the contents of ChangeCipherSpec are checked.
9655 testCases = append(testCases, testCase{
9656 name: "BadChangeCipherSpec-1",
9657 config: Config{
9658 MaxVersion: VersionTLS12,
9659 Bugs: ProtocolBugs{
9660 BadChangeCipherSpec: []byte{2},
9661 },
9662 },
9663 shouldFail: true,
9664 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9665 })
9666 testCases = append(testCases, testCase{
9667 name: "BadChangeCipherSpec-2",
9668 config: Config{
9669 MaxVersion: VersionTLS12,
9670 Bugs: ProtocolBugs{
9671 BadChangeCipherSpec: []byte{1, 1},
9672 },
9673 },
9674 shouldFail: true,
9675 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9676 })
9677 testCases = append(testCases, testCase{
9678 protocol: dtls,
9679 name: "BadChangeCipherSpec-DTLS-1",
9680 config: Config{
9681 MaxVersion: VersionTLS12,
9682 Bugs: ProtocolBugs{
9683 BadChangeCipherSpec: []byte{2},
9684 },
9685 },
9686 shouldFail: true,
9687 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9688 })
9689 testCases = append(testCases, testCase{
9690 protocol: dtls,
9691 name: "BadChangeCipherSpec-DTLS-2",
9692 config: Config{
9693 MaxVersion: VersionTLS12,
9694 Bugs: ProtocolBugs{
9695 BadChangeCipherSpec: []byte{1, 1},
9696 },
9697 },
9698 shouldFail: true,
9699 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9700 })
9701}
9702
David Benjamincd2c8062016-09-09 11:28:16 -04009703type perMessageTest struct {
9704 messageType uint8
9705 test testCase
9706}
9707
9708// makePerMessageTests returns a series of test templates which cover each
9709// message in the TLS handshake. These may be used with bugs like
9710// WrongMessageType to fully test a per-message bug.
9711func makePerMessageTests() []perMessageTest {
9712 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009713 for _, protocol := range []protocol{tls, dtls} {
9714 var suffix string
9715 if protocol == dtls {
9716 suffix = "-DTLS"
9717 }
9718
David Benjamincd2c8062016-09-09 11:28:16 -04009719 ret = append(ret, perMessageTest{
9720 messageType: typeClientHello,
9721 test: testCase{
9722 protocol: protocol,
9723 testType: serverTest,
9724 name: "ClientHello" + suffix,
9725 config: Config{
9726 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009727 },
9728 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009729 })
9730
9731 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009732 ret = append(ret, perMessageTest{
9733 messageType: typeHelloVerifyRequest,
9734 test: testCase{
9735 protocol: protocol,
9736 name: "HelloVerifyRequest" + suffix,
9737 config: Config{
9738 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009739 },
9740 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009741 })
9742 }
9743
David Benjamincd2c8062016-09-09 11:28:16 -04009744 ret = append(ret, perMessageTest{
9745 messageType: typeServerHello,
9746 test: testCase{
9747 protocol: protocol,
9748 name: "ServerHello" + suffix,
9749 config: Config{
9750 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009751 },
9752 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009753 })
9754
David Benjamincd2c8062016-09-09 11:28:16 -04009755 ret = append(ret, perMessageTest{
9756 messageType: typeCertificate,
9757 test: testCase{
9758 protocol: protocol,
9759 name: "ServerCertificate" + suffix,
9760 config: Config{
9761 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009762 },
9763 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009764 })
9765
David Benjamincd2c8062016-09-09 11:28:16 -04009766 ret = append(ret, perMessageTest{
9767 messageType: typeCertificateStatus,
9768 test: testCase{
9769 protocol: protocol,
9770 name: "CertificateStatus" + suffix,
9771 config: Config{
9772 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009773 },
David Benjamincd2c8062016-09-09 11:28:16 -04009774 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009775 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009776 })
9777
David Benjamincd2c8062016-09-09 11:28:16 -04009778 ret = append(ret, perMessageTest{
9779 messageType: typeServerKeyExchange,
9780 test: testCase{
9781 protocol: protocol,
9782 name: "ServerKeyExchange" + suffix,
9783 config: Config{
9784 MaxVersion: VersionTLS12,
9785 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009786 },
9787 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009788 })
9789
David Benjamincd2c8062016-09-09 11:28:16 -04009790 ret = append(ret, perMessageTest{
9791 messageType: typeCertificateRequest,
9792 test: testCase{
9793 protocol: protocol,
9794 name: "CertificateRequest" + suffix,
9795 config: Config{
9796 MaxVersion: VersionTLS12,
9797 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009798 },
9799 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009800 })
9801
David Benjamincd2c8062016-09-09 11:28:16 -04009802 ret = append(ret, perMessageTest{
9803 messageType: typeServerHelloDone,
9804 test: testCase{
9805 protocol: protocol,
9806 name: "ServerHelloDone" + suffix,
9807 config: Config{
9808 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009809 },
9810 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009811 })
9812
David Benjamincd2c8062016-09-09 11:28:16 -04009813 ret = append(ret, perMessageTest{
9814 messageType: typeCertificate,
9815 test: testCase{
9816 testType: serverTest,
9817 protocol: protocol,
9818 name: "ClientCertificate" + suffix,
9819 config: Config{
9820 Certificates: []Certificate{rsaCertificate},
9821 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009822 },
David Benjamincd2c8062016-09-09 11:28:16 -04009823 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009824 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009825 })
9826
David Benjamincd2c8062016-09-09 11:28:16 -04009827 ret = append(ret, perMessageTest{
9828 messageType: typeCertificateVerify,
9829 test: testCase{
9830 testType: serverTest,
9831 protocol: protocol,
9832 name: "CertificateVerify" + suffix,
9833 config: Config{
9834 Certificates: []Certificate{rsaCertificate},
9835 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009836 },
David Benjamincd2c8062016-09-09 11:28:16 -04009837 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009838 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009839 })
9840
David Benjamincd2c8062016-09-09 11:28:16 -04009841 ret = append(ret, perMessageTest{
9842 messageType: typeClientKeyExchange,
9843 test: testCase{
9844 testType: serverTest,
9845 protocol: protocol,
9846 name: "ClientKeyExchange" + suffix,
9847 config: Config{
9848 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009849 },
9850 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009851 })
9852
9853 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009854 ret = append(ret, perMessageTest{
9855 messageType: typeNextProtocol,
9856 test: testCase{
9857 testType: serverTest,
9858 protocol: protocol,
9859 name: "NextProtocol" + suffix,
9860 config: Config{
9861 MaxVersion: VersionTLS12,
9862 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009863 },
David Benjamincd2c8062016-09-09 11:28:16 -04009864 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009865 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009866 })
9867
David Benjamincd2c8062016-09-09 11:28:16 -04009868 ret = append(ret, perMessageTest{
9869 messageType: typeChannelID,
9870 test: testCase{
9871 testType: serverTest,
9872 protocol: protocol,
9873 name: "ChannelID" + suffix,
9874 config: Config{
9875 MaxVersion: VersionTLS12,
9876 ChannelID: channelIDKey,
9877 },
9878 flags: []string{
9879 "-expect-channel-id",
9880 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009881 },
9882 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009883 })
9884 }
9885
David Benjamincd2c8062016-09-09 11:28:16 -04009886 ret = append(ret, perMessageTest{
9887 messageType: typeFinished,
9888 test: testCase{
9889 testType: serverTest,
9890 protocol: protocol,
9891 name: "ClientFinished" + suffix,
9892 config: Config{
9893 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009894 },
9895 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009896 })
9897
David Benjamincd2c8062016-09-09 11:28:16 -04009898 ret = append(ret, perMessageTest{
9899 messageType: typeNewSessionTicket,
9900 test: testCase{
9901 protocol: protocol,
9902 name: "NewSessionTicket" + suffix,
9903 config: Config{
9904 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009905 },
9906 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009907 })
9908
David Benjamincd2c8062016-09-09 11:28:16 -04009909 ret = append(ret, perMessageTest{
9910 messageType: typeFinished,
9911 test: testCase{
9912 protocol: protocol,
9913 name: "ServerFinished" + suffix,
9914 config: Config{
9915 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009916 },
9917 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009918 })
9919
9920 }
David Benjamincd2c8062016-09-09 11:28:16 -04009921
9922 ret = append(ret, perMessageTest{
9923 messageType: typeClientHello,
9924 test: testCase{
9925 testType: serverTest,
9926 name: "TLS13-ClientHello",
9927 config: Config{
9928 MaxVersion: VersionTLS13,
9929 },
9930 },
9931 })
9932
9933 ret = append(ret, perMessageTest{
9934 messageType: typeServerHello,
9935 test: testCase{
9936 name: "TLS13-ServerHello",
9937 config: Config{
9938 MaxVersion: VersionTLS13,
9939 },
9940 },
9941 })
9942
9943 ret = append(ret, perMessageTest{
9944 messageType: typeEncryptedExtensions,
9945 test: testCase{
9946 name: "TLS13-EncryptedExtensions",
9947 config: Config{
9948 MaxVersion: VersionTLS13,
9949 },
9950 },
9951 })
9952
9953 ret = append(ret, perMessageTest{
9954 messageType: typeCertificateRequest,
9955 test: testCase{
9956 name: "TLS13-CertificateRequest",
9957 config: Config{
9958 MaxVersion: VersionTLS13,
9959 ClientAuth: RequireAnyClientCert,
9960 },
9961 },
9962 })
9963
9964 ret = append(ret, perMessageTest{
9965 messageType: typeCertificate,
9966 test: testCase{
9967 name: "TLS13-ServerCertificate",
9968 config: Config{
9969 MaxVersion: VersionTLS13,
9970 },
9971 },
9972 })
9973
9974 ret = append(ret, perMessageTest{
9975 messageType: typeCertificateVerify,
9976 test: testCase{
9977 name: "TLS13-ServerCertificateVerify",
9978 config: Config{
9979 MaxVersion: VersionTLS13,
9980 },
9981 },
9982 })
9983
9984 ret = append(ret, perMessageTest{
9985 messageType: typeFinished,
9986 test: testCase{
9987 name: "TLS13-ServerFinished",
9988 config: Config{
9989 MaxVersion: VersionTLS13,
9990 },
9991 },
9992 })
9993
9994 ret = append(ret, perMessageTest{
9995 messageType: typeCertificate,
9996 test: testCase{
9997 testType: serverTest,
9998 name: "TLS13-ClientCertificate",
9999 config: Config{
10000 Certificates: []Certificate{rsaCertificate},
10001 MaxVersion: VersionTLS13,
10002 },
10003 flags: []string{"-require-any-client-certificate"},
10004 },
10005 })
10006
10007 ret = append(ret, perMessageTest{
10008 messageType: typeCertificateVerify,
10009 test: testCase{
10010 testType: serverTest,
10011 name: "TLS13-ClientCertificateVerify",
10012 config: Config{
10013 Certificates: []Certificate{rsaCertificate},
10014 MaxVersion: VersionTLS13,
10015 },
10016 flags: []string{"-require-any-client-certificate"},
10017 },
10018 })
10019
10020 ret = append(ret, perMessageTest{
10021 messageType: typeFinished,
10022 test: testCase{
10023 testType: serverTest,
10024 name: "TLS13-ClientFinished",
10025 config: Config{
10026 MaxVersion: VersionTLS13,
10027 },
10028 },
10029 })
10030
10031 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010032}
10033
David Benjamincd2c8062016-09-09 11:28:16 -040010034func addWrongMessageTypeTests() {
10035 for _, t := range makePerMessageTests() {
10036 t.test.name = "WrongMessageType-" + t.test.name
10037 t.test.config.Bugs.SendWrongMessageType = t.messageType
10038 t.test.shouldFail = true
10039 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10040 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010041
David Benjamincd2c8062016-09-09 11:28:16 -040010042 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10043 // In TLS 1.3, a bad ServerHello means the client sends
10044 // an unencrypted alert while the server expects
10045 // encryption, so the alert is not readable by runner.
10046 t.test.expectedLocalError = "local error: bad record MAC"
10047 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010048
David Benjamincd2c8062016-09-09 11:28:16 -040010049 testCases = append(testCases, t.test)
10050 }
David Benjaminebacdee2017-04-08 11:00:45 -040010051
10052 // The processing order for TLS 1.3 version negotiation is such that one
10053 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10054 // TLS 1.2. Test that we do not do this.
10055 testCases = append(testCases, testCase{
10056 name: "SendServerHelloAsHelloRetryRequest",
10057 config: Config{
10058 MaxVersion: VersionTLS12,
10059 Bugs: ProtocolBugs{
10060 SendServerHelloAsHelloRetryRequest: true,
10061 },
10062 },
10063 shouldFail: true,
10064 expectedError: ":UNEXPECTED_MESSAGE:",
10065 expectedLocalError: "remote error: unexpected message",
10066 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010067}
10068
David Benjamin639846e2016-09-09 11:41:18 -040010069func addTrailingMessageDataTests() {
10070 for _, t := range makePerMessageTests() {
10071 t.test.name = "TrailingMessageData-" + t.test.name
10072 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10073 t.test.shouldFail = true
10074 t.test.expectedError = ":DECODE_ERROR:"
10075 t.test.expectedLocalError = "remote error: error decoding message"
10076
10077 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10078 // In TLS 1.3, a bad ServerHello means the client sends
10079 // an unencrypted alert while the server expects
10080 // encryption, so the alert is not readable by runner.
10081 t.test.expectedLocalError = "local error: bad record MAC"
10082 }
10083
10084 if t.messageType == typeFinished {
10085 // Bad Finished messages read as the verify data having
10086 // the wrong length.
10087 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10088 t.test.expectedLocalError = "remote error: error decrypting message"
10089 }
10090
10091 testCases = append(testCases, t.test)
10092 }
10093}
10094
Steven Valdez143e8b32016-07-11 13:19:03 -040010095func addTLS13HandshakeTests() {
10096 testCases = append(testCases, testCase{
10097 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010098 name: "NegotiatePSKResumption-TLS13",
10099 config: Config{
10100 MaxVersion: VersionTLS13,
10101 Bugs: ProtocolBugs{
10102 NegotiatePSKResumption: true,
10103 },
10104 },
10105 resumeSession: true,
10106 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010107 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010108 })
10109
10110 testCases = append(testCases, testCase{
10111 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010112 name: "MissingKeyShare-Client",
10113 config: Config{
10114 MaxVersion: VersionTLS13,
10115 Bugs: ProtocolBugs{
10116 MissingKeyShare: true,
10117 },
10118 },
10119 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010120 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010121 })
10122
10123 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010124 testType: serverTest,
10125 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010126 config: Config{
10127 MaxVersion: VersionTLS13,
10128 Bugs: ProtocolBugs{
10129 MissingKeyShare: true,
10130 },
10131 },
10132 shouldFail: true,
10133 expectedError: ":MISSING_KEY_SHARE:",
10134 })
10135
10136 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010137 testType: serverTest,
10138 name: "DuplicateKeyShares",
10139 config: Config{
10140 MaxVersion: VersionTLS13,
10141 Bugs: ProtocolBugs{
10142 DuplicateKeyShares: true,
10143 },
10144 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010145 shouldFail: true,
10146 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010147 })
10148
10149 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010150 testType: serverTest,
10151 name: "SkipEarlyData",
10152 config: Config{
10153 MaxVersion: VersionTLS13,
10154 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010155 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010156 },
10157 },
10158 })
10159
10160 testCases = append(testCases, testCase{
10161 testType: serverTest,
10162 name: "SkipEarlyData-OmitEarlyDataExtension",
10163 config: Config{
10164 MaxVersion: VersionTLS13,
10165 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010166 SendFakeEarlyDataLength: 4,
10167 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010168 },
10169 },
10170 shouldFail: true,
10171 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10172 })
10173
10174 testCases = append(testCases, testCase{
10175 testType: serverTest,
10176 name: "SkipEarlyData-TooMuchData",
10177 config: Config{
10178 MaxVersion: VersionTLS13,
10179 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010180 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010181 },
10182 },
10183 shouldFail: true,
10184 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10185 })
10186
10187 testCases = append(testCases, testCase{
10188 testType: serverTest,
10189 name: "SkipEarlyData-Interleaved",
10190 config: Config{
10191 MaxVersion: VersionTLS13,
10192 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010193 SendFakeEarlyDataLength: 4,
10194 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010195 },
10196 },
10197 shouldFail: true,
10198 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10199 })
10200
10201 testCases = append(testCases, testCase{
10202 testType: serverTest,
10203 name: "SkipEarlyData-EarlyDataInTLS12",
10204 config: Config{
10205 MaxVersion: VersionTLS13,
10206 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010207 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010208 },
10209 },
10210 shouldFail: true,
10211 expectedError: ":UNEXPECTED_RECORD:",
10212 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10213 })
10214
10215 testCases = append(testCases, testCase{
10216 testType: serverTest,
10217 name: "SkipEarlyData-HRR",
10218 config: Config{
10219 MaxVersion: VersionTLS13,
10220 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010221 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010222 },
10223 DefaultCurves: []CurveID{},
10224 },
10225 })
10226
10227 testCases = append(testCases, testCase{
10228 testType: serverTest,
10229 name: "SkipEarlyData-HRR-Interleaved",
10230 config: Config{
10231 MaxVersion: VersionTLS13,
10232 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010233 SendFakeEarlyDataLength: 4,
10234 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010235 },
10236 DefaultCurves: []CurveID{},
10237 },
10238 shouldFail: true,
10239 expectedError: ":UNEXPECTED_RECORD:",
10240 })
10241
10242 testCases = append(testCases, testCase{
10243 testType: serverTest,
10244 name: "SkipEarlyData-HRR-TooMuchData",
10245 config: Config{
10246 MaxVersion: VersionTLS13,
10247 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010248 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010249 },
10250 DefaultCurves: []CurveID{},
10251 },
10252 shouldFail: true,
10253 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10254 })
10255
10256 // Test that skipping early data looking for cleartext correctly
10257 // processes an alert record.
10258 testCases = append(testCases, testCase{
10259 testType: serverTest,
10260 name: "SkipEarlyData-HRR-FatalAlert",
10261 config: Config{
10262 MaxVersion: VersionTLS13,
10263 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010264 SendEarlyAlert: true,
10265 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010266 },
10267 DefaultCurves: []CurveID{},
10268 },
10269 shouldFail: true,
10270 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10271 })
10272
10273 testCases = append(testCases, testCase{
10274 testType: serverTest,
10275 name: "SkipEarlyData-SecondClientHelloEarlyData",
10276 config: Config{
10277 MaxVersion: VersionTLS13,
10278 Bugs: ProtocolBugs{
10279 SendEarlyDataOnSecondClientHello: true,
10280 },
10281 DefaultCurves: []CurveID{},
10282 },
10283 shouldFail: true,
10284 expectedLocalError: "remote error: bad record MAC",
10285 })
10286
10287 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010288 testType: clientTest,
10289 name: "EmptyEncryptedExtensions",
10290 config: Config{
10291 MaxVersion: VersionTLS13,
10292 Bugs: ProtocolBugs{
10293 EmptyEncryptedExtensions: true,
10294 },
10295 },
10296 shouldFail: true,
10297 expectedLocalError: "remote error: error decoding message",
10298 })
10299
10300 testCases = append(testCases, testCase{
10301 testType: clientTest,
10302 name: "EncryptedExtensionsWithKeyShare",
10303 config: Config{
10304 MaxVersion: VersionTLS13,
10305 Bugs: ProtocolBugs{
10306 EncryptedExtensionsWithKeyShare: true,
10307 },
10308 },
10309 shouldFail: true,
10310 expectedLocalError: "remote error: unsupported extension",
10311 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010312
10313 testCases = append(testCases, testCase{
10314 testType: serverTest,
10315 name: "SendHelloRetryRequest",
10316 config: Config{
10317 MaxVersion: VersionTLS13,
10318 // Require a HelloRetryRequest for every curve.
10319 DefaultCurves: []CurveID{},
10320 },
10321 expectedCurveID: CurveX25519,
10322 })
10323
10324 testCases = append(testCases, testCase{
10325 testType: serverTest,
10326 name: "SendHelloRetryRequest-2",
10327 config: Config{
10328 MaxVersion: VersionTLS13,
10329 DefaultCurves: []CurveID{CurveP384},
10330 },
10331 // Although the ClientHello did not predict our preferred curve,
10332 // we always select it whether it is predicted or not.
10333 expectedCurveID: CurveX25519,
10334 })
10335
10336 testCases = append(testCases, testCase{
10337 name: "UnknownCurve-HelloRetryRequest",
10338 config: Config{
10339 MaxVersion: VersionTLS13,
10340 // P-384 requires HelloRetryRequest in BoringSSL.
10341 CurvePreferences: []CurveID{CurveP384},
10342 Bugs: ProtocolBugs{
10343 SendHelloRetryRequestCurve: bogusCurve,
10344 },
10345 },
10346 shouldFail: true,
10347 expectedError: ":WRONG_CURVE:",
10348 })
10349
10350 testCases = append(testCases, testCase{
10351 name: "DisabledCurve-HelloRetryRequest",
10352 config: Config{
10353 MaxVersion: VersionTLS13,
10354 CurvePreferences: []CurveID{CurveP256},
10355 Bugs: ProtocolBugs{
10356 IgnorePeerCurvePreferences: true,
10357 },
10358 },
10359 flags: []string{"-p384-only"},
10360 shouldFail: true,
10361 expectedError: ":WRONG_CURVE:",
10362 })
10363
10364 testCases = append(testCases, testCase{
10365 name: "UnnecessaryHelloRetryRequest",
10366 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010367 MaxVersion: VersionTLS13,
10368 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010369 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010370 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010371 },
10372 },
10373 shouldFail: true,
10374 expectedError: ":WRONG_CURVE:",
10375 })
10376
10377 testCases = append(testCases, testCase{
10378 name: "SecondHelloRetryRequest",
10379 config: Config{
10380 MaxVersion: VersionTLS13,
10381 // P-384 requires HelloRetryRequest in BoringSSL.
10382 CurvePreferences: []CurveID{CurveP384},
10383 Bugs: ProtocolBugs{
10384 SecondHelloRetryRequest: true,
10385 },
10386 },
10387 shouldFail: true,
10388 expectedError: ":UNEXPECTED_MESSAGE:",
10389 })
10390
10391 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010392 name: "HelloRetryRequest-Empty",
10393 config: Config{
10394 MaxVersion: VersionTLS13,
10395 Bugs: ProtocolBugs{
10396 AlwaysSendHelloRetryRequest: true,
10397 },
10398 },
10399 shouldFail: true,
10400 expectedError: ":DECODE_ERROR:",
10401 })
10402
10403 testCases = append(testCases, testCase{
10404 name: "HelloRetryRequest-DuplicateCurve",
10405 config: Config{
10406 MaxVersion: VersionTLS13,
10407 // P-384 requires a HelloRetryRequest against BoringSSL's default
10408 // configuration. Assert this ExpectMissingKeyShare.
10409 CurvePreferences: []CurveID{CurveP384},
10410 Bugs: ProtocolBugs{
10411 ExpectMissingKeyShare: true,
10412 DuplicateHelloRetryRequestExtensions: true,
10413 },
10414 },
10415 shouldFail: true,
10416 expectedError: ":DUPLICATE_EXTENSION:",
10417 expectedLocalError: "remote error: illegal parameter",
10418 })
10419
10420 testCases = append(testCases, testCase{
10421 name: "HelloRetryRequest-Cookie",
10422 config: Config{
10423 MaxVersion: VersionTLS13,
10424 Bugs: ProtocolBugs{
10425 SendHelloRetryRequestCookie: []byte("cookie"),
10426 },
10427 },
10428 })
10429
10430 testCases = append(testCases, testCase{
10431 name: "HelloRetryRequest-DuplicateCookie",
10432 config: Config{
10433 MaxVersion: VersionTLS13,
10434 Bugs: ProtocolBugs{
10435 SendHelloRetryRequestCookie: []byte("cookie"),
10436 DuplicateHelloRetryRequestExtensions: true,
10437 },
10438 },
10439 shouldFail: true,
10440 expectedError: ":DUPLICATE_EXTENSION:",
10441 expectedLocalError: "remote error: illegal parameter",
10442 })
10443
10444 testCases = append(testCases, testCase{
10445 name: "HelloRetryRequest-EmptyCookie",
10446 config: Config{
10447 MaxVersion: VersionTLS13,
10448 Bugs: ProtocolBugs{
10449 SendHelloRetryRequestCookie: []byte{},
10450 },
10451 },
10452 shouldFail: true,
10453 expectedError: ":DECODE_ERROR:",
10454 })
10455
10456 testCases = append(testCases, testCase{
10457 name: "HelloRetryRequest-Cookie-Curve",
10458 config: Config{
10459 MaxVersion: VersionTLS13,
10460 // P-384 requires HelloRetryRequest in BoringSSL.
10461 CurvePreferences: []CurveID{CurveP384},
10462 Bugs: ProtocolBugs{
10463 SendHelloRetryRequestCookie: []byte("cookie"),
10464 ExpectMissingKeyShare: true,
10465 },
10466 },
10467 })
10468
10469 testCases = append(testCases, testCase{
10470 name: "HelloRetryRequest-Unknown",
10471 config: Config{
10472 MaxVersion: VersionTLS13,
10473 Bugs: ProtocolBugs{
10474 CustomHelloRetryRequestExtension: "extension",
10475 },
10476 },
10477 shouldFail: true,
10478 expectedError: ":UNEXPECTED_EXTENSION:",
10479 expectedLocalError: "remote error: unsupported extension",
10480 })
10481
10482 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010483 testType: serverTest,
10484 name: "SecondClientHelloMissingKeyShare",
10485 config: Config{
10486 MaxVersion: VersionTLS13,
10487 DefaultCurves: []CurveID{},
10488 Bugs: ProtocolBugs{
10489 SecondClientHelloMissingKeyShare: true,
10490 },
10491 },
10492 shouldFail: true,
10493 expectedError: ":MISSING_KEY_SHARE:",
10494 })
10495
10496 testCases = append(testCases, testCase{
10497 testType: serverTest,
10498 name: "SecondClientHelloWrongCurve",
10499 config: Config{
10500 MaxVersion: VersionTLS13,
10501 DefaultCurves: []CurveID{},
10502 Bugs: ProtocolBugs{
10503 MisinterpretHelloRetryRequestCurve: CurveP521,
10504 },
10505 },
10506 shouldFail: true,
10507 expectedError: ":WRONG_CURVE:",
10508 })
10509
10510 testCases = append(testCases, testCase{
10511 name: "HelloRetryRequestVersionMismatch",
10512 config: Config{
10513 MaxVersion: VersionTLS13,
10514 // P-384 requires HelloRetryRequest in BoringSSL.
10515 CurvePreferences: []CurveID{CurveP384},
10516 Bugs: ProtocolBugs{
10517 SendServerHelloVersion: 0x0305,
10518 },
10519 },
10520 shouldFail: true,
10521 expectedError: ":WRONG_VERSION_NUMBER:",
10522 })
10523
10524 testCases = append(testCases, testCase{
10525 name: "HelloRetryRequestCurveMismatch",
10526 config: Config{
10527 MaxVersion: VersionTLS13,
10528 // P-384 requires HelloRetryRequest in BoringSSL.
10529 CurvePreferences: []CurveID{CurveP384},
10530 Bugs: ProtocolBugs{
10531 // Send P-384 (correct) in the HelloRetryRequest.
10532 SendHelloRetryRequestCurve: CurveP384,
10533 // But send P-256 in the ServerHello.
10534 SendCurve: CurveP256,
10535 },
10536 },
10537 shouldFail: true,
10538 expectedError: ":WRONG_CURVE:",
10539 })
10540
10541 // Test the server selecting a curve that requires a HelloRetryRequest
10542 // without sending it.
10543 testCases = append(testCases, testCase{
10544 name: "SkipHelloRetryRequest",
10545 config: Config{
10546 MaxVersion: VersionTLS13,
10547 // P-384 requires HelloRetryRequest in BoringSSL.
10548 CurvePreferences: []CurveID{CurveP384},
10549 Bugs: ProtocolBugs{
10550 SkipHelloRetryRequest: true,
10551 },
10552 },
10553 shouldFail: true,
10554 expectedError: ":WRONG_CURVE:",
10555 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010556
10557 testCases = append(testCases, testCase{
10558 name: "TLS13-RequestContextInHandshake",
10559 config: Config{
10560 MaxVersion: VersionTLS13,
10561 MinVersion: VersionTLS13,
10562 ClientAuth: RequireAnyClientCert,
10563 Bugs: ProtocolBugs{
10564 SendRequestContext: []byte("request context"),
10565 },
10566 },
10567 flags: []string{
10568 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10569 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10570 },
10571 shouldFail: true,
10572 expectedError: ":DECODE_ERROR:",
10573 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010574
10575 testCases = append(testCases, testCase{
10576 testType: serverTest,
10577 name: "TLS13-TrailingKeyShareData",
10578 config: Config{
10579 MaxVersion: VersionTLS13,
10580 Bugs: ProtocolBugs{
10581 TrailingKeyShareData: true,
10582 },
10583 },
10584 shouldFail: true,
10585 expectedError: ":DECODE_ERROR:",
10586 })
David Benjamin7f78df42016-10-05 22:33:19 -040010587
10588 testCases = append(testCases, testCase{
10589 name: "TLS13-AlwaysSelectPSKIdentity",
10590 config: Config{
10591 MaxVersion: VersionTLS13,
10592 Bugs: ProtocolBugs{
10593 AlwaysSelectPSKIdentity: true,
10594 },
10595 },
10596 shouldFail: true,
10597 expectedError: ":UNEXPECTED_EXTENSION:",
10598 })
10599
10600 testCases = append(testCases, testCase{
10601 name: "TLS13-InvalidPSKIdentity",
10602 config: Config{
10603 MaxVersion: VersionTLS13,
10604 Bugs: ProtocolBugs{
10605 SelectPSKIdentityOnResume: 1,
10606 },
10607 },
10608 resumeSession: true,
10609 shouldFail: true,
10610 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10611 })
David Benjamin1286bee2016-10-07 15:25:06 -040010612
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010613 testCases = append(testCases, testCase{
10614 testType: serverTest,
10615 name: "TLS13-ExtraPSKIdentity",
10616 config: Config{
10617 MaxVersion: VersionTLS13,
10618 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010619 ExtraPSKIdentity: true,
10620 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010621 },
10622 },
10623 resumeSession: true,
10624 })
10625
David Benjamin1286bee2016-10-07 15:25:06 -040010626 // Test that unknown NewSessionTicket extensions are tolerated.
10627 testCases = append(testCases, testCase{
10628 name: "TLS13-CustomTicketExtension",
10629 config: Config{
10630 MaxVersion: VersionTLS13,
10631 Bugs: ProtocolBugs{
10632 CustomTicketExtension: "1234",
10633 },
10634 },
10635 })
Steven Valdez2d850622017-01-11 11:34:52 -050010636
Steven Valdez2d850622017-01-11 11:34:52 -050010637 testCases = append(testCases, testCase{
10638 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010639 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010640 config: Config{
10641 MaxVersion: VersionTLS13,
10642 MaxEarlyDataSize: 16384,
10643 },
10644 resumeConfig: &Config{
10645 MaxVersion: VersionTLS13,
10646 MaxEarlyDataSize: 16384,
10647 Bugs: ProtocolBugs{
10648 AlwaysRejectEarlyData: true,
10649 },
10650 },
10651 resumeSession: true,
10652 flags: []string{
10653 "-enable-early-data",
10654 "-expect-early-data-info",
10655 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010656 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010657 },
10658 })
10659
10660 testCases = append(testCases, testCase{
10661 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010662 name: "TLS13-EarlyData-RejectTicket-Client",
10663 config: Config{
10664 MaxVersion: VersionTLS13,
10665 MaxEarlyDataSize: 16384,
10666 Certificates: []Certificate{rsaCertificate},
10667 },
10668 resumeConfig: &Config{
10669 MaxVersion: VersionTLS13,
10670 MaxEarlyDataSize: 16384,
10671 Certificates: []Certificate{ecdsaP256Certificate},
10672 SessionTicketsDisabled: true,
10673 },
10674 resumeSession: true,
10675 expectResumeRejected: true,
10676 flags: []string{
10677 "-enable-early-data",
10678 "-expect-early-data-info",
10679 "-expect-reject-early-data",
10680 "-on-resume-shim-writes-first",
10681 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10682 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10683 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10684 // Session tickets are disabled, so the runner will not send a ticket.
10685 "-on-retry-expect-no-session",
10686 },
10687 })
10688
10689 testCases = append(testCases, testCase{
10690 testType: clientTest,
10691 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010692 config: Config{
10693 MaxVersion: VersionTLS13,
10694 MaxEarlyDataSize: 16384,
10695 },
10696 resumeConfig: &Config{
10697 MaxVersion: VersionTLS13,
10698 MaxEarlyDataSize: 16384,
10699 Bugs: ProtocolBugs{
10700 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10701 },
10702 },
10703 resumeSession: true,
10704 flags: []string{
10705 "-enable-early-data",
10706 "-expect-early-data-info",
10707 "-expect-reject-early-data",
10708 },
10709 })
10710
10711 // The client must check the server does not send the early_data
10712 // extension while rejecting the session.
10713 testCases = append(testCases, testCase{
10714 testType: clientTest,
10715 name: "TLS13-EarlyDataWithoutResume-Client",
10716 config: Config{
10717 MaxVersion: VersionTLS13,
10718 MaxEarlyDataSize: 16384,
10719 },
10720 resumeConfig: &Config{
10721 MaxVersion: VersionTLS13,
10722 SessionTicketsDisabled: true,
10723 Bugs: ProtocolBugs{
10724 SendEarlyDataExtension: true,
10725 },
10726 },
10727 resumeSession: true,
10728 flags: []string{
10729 "-enable-early-data",
10730 "-expect-early-data-info",
10731 },
10732 shouldFail: true,
10733 expectedError: ":UNEXPECTED_EXTENSION:",
10734 })
10735
10736 // The client must fail with a dedicated error code if the server
10737 // responds with TLS 1.2 when offering 0-RTT.
10738 testCases = append(testCases, testCase{
10739 testType: clientTest,
10740 name: "TLS13-EarlyDataVersionDowngrade-Client",
10741 config: Config{
10742 MaxVersion: VersionTLS13,
10743 MaxEarlyDataSize: 16384,
10744 },
10745 resumeConfig: &Config{
10746 MaxVersion: VersionTLS12,
10747 },
10748 resumeSession: true,
10749 flags: []string{
10750 "-enable-early-data",
10751 "-expect-early-data-info",
10752 },
10753 shouldFail: true,
10754 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10755 })
10756
10757 // Test that the client rejects an (unsolicited) early_data extension if
10758 // the server sent an HRR.
10759 testCases = append(testCases, testCase{
10760 testType: clientTest,
10761 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10762 config: Config{
10763 MaxVersion: VersionTLS13,
10764 MaxEarlyDataSize: 16384,
10765 },
10766 resumeConfig: &Config{
10767 MaxVersion: VersionTLS13,
10768 MaxEarlyDataSize: 16384,
10769 Bugs: ProtocolBugs{
10770 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10771 SendEarlyDataExtension: true,
10772 },
10773 },
10774 resumeSession: true,
10775 flags: []string{
10776 "-enable-early-data",
10777 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010778 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010779 },
10780 shouldFail: true,
10781 expectedError: ":UNEXPECTED_EXTENSION:",
10782 })
10783
10784 fooString := "foo"
10785 barString := "bar"
10786
10787 // Test that the client reports the correct ALPN after a 0-RTT reject
10788 // that changed it.
10789 testCases = append(testCases, testCase{
10790 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010791 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 MaxEarlyDataSize: 16384,
10795 Bugs: ProtocolBugs{
10796 ALPNProtocol: &fooString,
10797 },
10798 },
10799 resumeConfig: &Config{
10800 MaxVersion: VersionTLS13,
10801 MaxEarlyDataSize: 16384,
10802 Bugs: ProtocolBugs{
10803 ALPNProtocol: &barString,
10804 },
10805 },
10806 resumeSession: true,
10807 flags: []string{
10808 "-advertise-alpn", "\x03foo\x03bar",
10809 "-enable-early-data",
10810 "-expect-early-data-info",
10811 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010812 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010813 "-on-resume-expect-alpn", "foo",
10814 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010815 },
10816 })
10817
10818 // Test that the client reports the correct ALPN after a 0-RTT reject if
10819 // ALPN was omitted from the first connection.
10820 testCases = append(testCases, testCase{
10821 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010822 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010823 config: Config{
10824 MaxVersion: VersionTLS13,
10825 MaxEarlyDataSize: 16384,
10826 },
10827 resumeConfig: &Config{
10828 MaxVersion: VersionTLS13,
10829 MaxEarlyDataSize: 16384,
10830 NextProtos: []string{"foo"},
10831 },
10832 resumeSession: true,
10833 flags: []string{
10834 "-advertise-alpn", "\x03foo\x03bar",
10835 "-enable-early-data",
10836 "-expect-early-data-info",
10837 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010838 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010839 "-on-resume-expect-alpn", "",
10840 "-on-retry-expect-alpn", "foo",
10841 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010842 },
10843 })
10844
10845 // Test that the client reports the correct ALPN after a 0-RTT reject if
10846 // ALPN was omitted from the second connection.
10847 testCases = append(testCases, testCase{
10848 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010849 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010850 config: Config{
10851 MaxVersion: VersionTLS13,
10852 MaxEarlyDataSize: 16384,
10853 NextProtos: []string{"foo"},
10854 },
10855 resumeConfig: &Config{
10856 MaxVersion: VersionTLS13,
10857 MaxEarlyDataSize: 16384,
10858 },
10859 resumeSession: true,
10860 flags: []string{
10861 "-advertise-alpn", "\x03foo\x03bar",
10862 "-enable-early-data",
10863 "-expect-early-data-info",
10864 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010865 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010866 "-on-resume-expect-alpn", "foo",
10867 "-on-retry-expect-alpn", "",
10868 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010869 },
10870 })
10871
10872 // Test that the client enforces ALPN match on 0-RTT accept.
10873 testCases = append(testCases, testCase{
10874 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010875 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010876 config: Config{
10877 MaxVersion: VersionTLS13,
10878 MaxEarlyDataSize: 16384,
10879 Bugs: ProtocolBugs{
10880 ALPNProtocol: &fooString,
10881 },
10882 },
10883 resumeConfig: &Config{
10884 MaxVersion: VersionTLS13,
10885 MaxEarlyDataSize: 16384,
10886 Bugs: ProtocolBugs{
10887 AlwaysAcceptEarlyData: true,
10888 ALPNProtocol: &barString,
10889 },
10890 },
10891 resumeSession: true,
10892 flags: []string{
10893 "-advertise-alpn", "\x03foo\x03bar",
10894 "-enable-early-data",
10895 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010896 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010897 "-on-resume-expect-alpn", "foo",
10898 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010899 },
10900 shouldFail: true,
10901 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10902 })
10903
10904 // Test that the server correctly rejects 0-RTT when the previous
10905 // session did not allow early data on resumption.
10906 testCases = append(testCases, testCase{
10907 testType: serverTest,
10908 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10909 config: Config{
10910 MaxVersion: VersionTLS13,
10911 },
10912 resumeConfig: &Config{
10913 MaxVersion: VersionTLS13,
10914 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010915 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010916 ExpectEarlyDataAccepted: false,
10917 },
10918 },
10919 resumeSession: true,
10920 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010921 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010922 "-expect-reject-early-data",
10923 },
10924 })
10925
10926 // Test that we reject early data where ALPN is omitted from the first
10927 // connection.
10928 testCases = append(testCases, testCase{
10929 testType: serverTest,
10930 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10931 config: Config{
10932 MaxVersion: VersionTLS13,
10933 NextProtos: []string{},
10934 },
10935 resumeConfig: &Config{
10936 MaxVersion: VersionTLS13,
10937 NextProtos: []string{"foo"},
10938 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010939 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010940 ExpectEarlyDataAccepted: false,
10941 },
10942 },
10943 resumeSession: true,
10944 flags: []string{
10945 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010946 "-on-initial-select-alpn", "",
10947 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010948 },
10949 })
10950
10951 // Test that we reject early data where ALPN is omitted from the second
10952 // connection.
10953 testCases = append(testCases, testCase{
10954 testType: serverTest,
10955 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10956 config: Config{
10957 MaxVersion: VersionTLS13,
10958 NextProtos: []string{"foo"},
10959 },
10960 resumeConfig: &Config{
10961 MaxVersion: VersionTLS13,
10962 NextProtos: []string{},
10963 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010964 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010965 ExpectEarlyDataAccepted: false,
10966 },
10967 },
10968 resumeSession: true,
10969 flags: []string{
10970 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010971 "-on-initial-select-alpn", "foo",
10972 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010973 },
10974 })
10975
10976 // Test that we reject early data with mismatched ALPN.
10977 testCases = append(testCases, testCase{
10978 testType: serverTest,
10979 name: "TLS13-EarlyData-ALPNMismatch-Server",
10980 config: Config{
10981 MaxVersion: VersionTLS13,
10982 NextProtos: []string{"foo"},
10983 },
10984 resumeConfig: &Config{
10985 MaxVersion: VersionTLS13,
10986 NextProtos: []string{"bar"},
10987 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010988 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010989 ExpectEarlyDataAccepted: false,
10990 },
10991 },
10992 resumeSession: true,
10993 flags: []string{
10994 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010995 "-on-initial-select-alpn", "foo",
10996 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010997 },
10998 })
10999
David Benjamin6bb507b2017-03-29 16:35:57 -050011000 // Test that the client offering 0-RTT and Channel ID forbids the server
11001 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011002 testCases = append(testCases, testCase{
11003 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011004 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011005 config: Config{
11006 MaxVersion: VersionTLS13,
11007 MaxEarlyDataSize: 16384,
11008 RequestChannelID: true,
11009 },
11010 resumeSession: true,
11011 expectChannelID: true,
11012 shouldFail: true,
11013 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
11014 flags: []string{
11015 "-enable-early-data",
11016 "-expect-early-data-info",
11017 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11018 },
11019 })
11020
David Benjamin6bb507b2017-03-29 16:35:57 -050011021 // Test that the client offering Channel ID and 0-RTT allows the server
11022 // to decline 0-RTT.
11023 testCases = append(testCases, testCase{
11024 testType: clientTest,
11025 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11026 config: Config{
11027 MaxVersion: VersionTLS13,
11028 MaxEarlyDataSize: 16384,
11029 RequestChannelID: true,
11030 Bugs: ProtocolBugs{
11031 AlwaysRejectEarlyData: true,
11032 },
11033 },
11034 resumeSession: true,
11035 expectChannelID: true,
11036 flags: []string{
11037 "-enable-early-data",
11038 "-expect-early-data-info",
11039 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11040 "-expect-reject-early-data",
11041 },
11042 })
11043
11044 // Test that the client offering Channel ID and 0-RTT allows the server
11045 // to decline Channel ID.
11046 testCases = append(testCases, testCase{
11047 testType: clientTest,
11048 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11049 config: Config{
11050 MaxVersion: VersionTLS13,
11051 MaxEarlyDataSize: 16384,
11052 },
11053 resumeSession: true,
11054 flags: []string{
11055 "-enable-early-data",
11056 "-expect-early-data-info",
11057 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11058 "-expect-accept-early-data",
11059 },
11060 })
11061
11062 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11063 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011064 testCases = append(testCases, testCase{
11065 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011066 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011067 config: Config{
11068 MaxVersion: VersionTLS13,
11069 ChannelID: channelIDKey,
11070 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011071 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011072 ExpectEarlyDataAccepted: false,
11073 },
11074 },
11075 resumeSession: true,
11076 expectChannelID: true,
11077 flags: []string{
11078 "-enable-early-data",
11079 "-expect-reject-early-data",
11080 "-expect-channel-id",
11081 base64.StdEncoding.EncodeToString(channelIDBytes),
11082 },
11083 })
11084
David Benjamin6bb507b2017-03-29 16:35:57 -050011085 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11086 // if not offered Channel ID.
11087 testCases = append(testCases, testCase{
11088 testType: serverTest,
11089 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11090 config: Config{
11091 MaxVersion: VersionTLS13,
11092 Bugs: ProtocolBugs{
11093 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11094 ExpectEarlyDataAccepted: true,
11095 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11096 },
11097 },
11098 resumeSession: true,
11099 expectChannelID: false,
11100 flags: []string{
11101 "-enable-early-data",
11102 "-expect-accept-early-data",
11103 "-enable-channel-id",
11104 },
11105 })
11106
David Benjamin32c89272017-03-26 13:54:21 -050011107 // Test that the server rejects 0-RTT streams without end_of_early_data.
11108 // The subsequent records should fail to decrypt.
11109 testCases = append(testCases, testCase{
11110 testType: serverTest,
11111 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11112 config: Config{
11113 MaxVersion: VersionTLS13,
11114 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011115 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011116 ExpectEarlyDataAccepted: true,
11117 SkipEndOfEarlyData: true,
11118 },
11119 },
11120 resumeSession: true,
11121 flags: []string{"-enable-early-data"},
11122 shouldFail: true,
11123 expectedLocalError: "remote error: bad record MAC",
11124 expectedError: ":BAD_DECRYPT:",
11125 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011126
11127 testCases = append(testCases, testCase{
11128 testType: serverTest,
11129 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11130 config: Config{
11131 MaxVersion: VersionTLS13,
11132 },
11133 resumeConfig: &Config{
11134 MaxVersion: VersionTLS13,
11135 Bugs: ProtocolBugs{
11136 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11137 SendStrayEarlyHandshake: true,
11138 ExpectEarlyDataAccepted: true},
11139 },
11140 resumeSession: true,
11141 shouldFail: true,
11142 expectedError: ":UNEXPECTED_RECORD:",
11143 expectedLocalError: "remote error: unexpected message",
11144 flags: []string{
11145 "-enable-early-data",
11146 },
11147 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011148}
11149
David Benjaminabbbee12016-10-31 19:20:42 -040011150func addTLS13CipherPreferenceTests() {
11151 // Test that client preference is honored if the shim has AES hardware
11152 // and ChaCha20-Poly1305 is preferred otherwise.
11153 testCases = append(testCases, testCase{
11154 testType: serverTest,
11155 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11156 config: Config{
11157 MaxVersion: VersionTLS13,
11158 CipherSuites: []uint16{
11159 TLS_CHACHA20_POLY1305_SHA256,
11160 TLS_AES_128_GCM_SHA256,
11161 },
11162 },
11163 flags: []string{
11164 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11165 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11166 },
11167 })
11168
11169 testCases = append(testCases, testCase{
11170 testType: serverTest,
11171 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11172 config: Config{
11173 MaxVersion: VersionTLS13,
11174 CipherSuites: []uint16{
11175 TLS_AES_128_GCM_SHA256,
11176 TLS_CHACHA20_POLY1305_SHA256,
11177 },
11178 },
11179 flags: []string{
11180 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11181 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11182 },
11183 })
11184
11185 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11186 // whether it has AES hardware.
11187 testCases = append(testCases, testCase{
11188 name: "TLS13-CipherPreference-Client",
11189 config: Config{
11190 MaxVersion: VersionTLS13,
11191 // Use the client cipher order. (This is the default but
11192 // is listed to be explicit.)
11193 PreferServerCipherSuites: false,
11194 },
11195 flags: []string{
11196 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11197 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11198 },
11199 })
11200}
11201
David Benjaminf3fbade2016-09-19 13:08:16 -040011202func addPeekTests() {
11203 // Test SSL_peek works, including on empty records.
11204 testCases = append(testCases, testCase{
11205 name: "Peek-Basic",
11206 sendEmptyRecords: 1,
11207 flags: []string{"-peek-then-read"},
11208 })
11209
11210 // Test SSL_peek can drive the initial handshake.
11211 testCases = append(testCases, testCase{
11212 name: "Peek-ImplicitHandshake",
11213 flags: []string{
11214 "-peek-then-read",
11215 "-implicit-handshake",
11216 },
11217 })
11218
11219 // Test SSL_peek can discover and drive a renegotiation.
11220 testCases = append(testCases, testCase{
11221 name: "Peek-Renegotiate",
11222 config: Config{
11223 MaxVersion: VersionTLS12,
11224 },
11225 renegotiate: 1,
11226 flags: []string{
11227 "-peek-then-read",
11228 "-renegotiate-freely",
11229 "-expect-total-renegotiations", "1",
11230 },
11231 })
11232
11233 // Test SSL_peek can discover a close_notify.
11234 testCases = append(testCases, testCase{
11235 name: "Peek-Shutdown",
11236 config: Config{
11237 Bugs: ProtocolBugs{
11238 ExpectCloseNotify: true,
11239 },
11240 },
11241 flags: []string{
11242 "-peek-then-read",
11243 "-check-close-notify",
11244 },
11245 })
11246
11247 // Test SSL_peek can discover an alert.
11248 testCases = append(testCases, testCase{
11249 name: "Peek-Alert",
11250 config: Config{
11251 Bugs: ProtocolBugs{
11252 SendSpuriousAlert: alertRecordOverflow,
11253 },
11254 },
11255 flags: []string{"-peek-then-read"},
11256 shouldFail: true,
11257 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11258 })
11259
11260 // Test SSL_peek can handle KeyUpdate.
11261 testCases = append(testCases, testCase{
11262 name: "Peek-KeyUpdate",
11263 config: Config{
11264 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011265 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011266 sendKeyUpdates: 1,
11267 keyUpdateRequest: keyUpdateNotRequested,
11268 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011269 })
11270}
11271
David Benjamine6f22212016-11-08 14:28:24 -050011272func addRecordVersionTests() {
11273 for _, ver := range tlsVersions {
11274 // Test that the record version is enforced.
11275 testCases = append(testCases, testCase{
11276 name: "CheckRecordVersion-" + ver.name,
11277 config: Config{
11278 MinVersion: ver.version,
11279 MaxVersion: ver.version,
11280 Bugs: ProtocolBugs{
11281 SendRecordVersion: 0x03ff,
11282 },
11283 },
11284 shouldFail: true,
11285 expectedError: ":WRONG_VERSION_NUMBER:",
11286 })
11287
11288 // Test that the ClientHello may use any record version, for
11289 // compatibility reasons.
11290 testCases = append(testCases, testCase{
11291 testType: serverTest,
11292 name: "LooseInitialRecordVersion-" + ver.name,
11293 config: Config{
11294 MinVersion: ver.version,
11295 MaxVersion: ver.version,
11296 Bugs: ProtocolBugs{
11297 SendInitialRecordVersion: 0x03ff,
11298 },
11299 },
11300 })
11301
11302 // Test that garbage ClientHello record versions are rejected.
11303 testCases = append(testCases, testCase{
11304 testType: serverTest,
11305 name: "GarbageInitialRecordVersion-" + ver.name,
11306 config: Config{
11307 MinVersion: ver.version,
11308 MaxVersion: ver.version,
11309 Bugs: ProtocolBugs{
11310 SendInitialRecordVersion: 0xffff,
11311 },
11312 },
11313 shouldFail: true,
11314 expectedError: ":WRONG_VERSION_NUMBER:",
11315 })
11316 }
11317}
11318
David Benjamin2c516452016-11-15 10:16:54 +090011319func addCertificateTests() {
11320 // Test that a certificate chain with intermediate may be sent and
11321 // received as both client and server.
11322 for _, ver := range tlsVersions {
11323 testCases = append(testCases, testCase{
11324 testType: clientTest,
11325 name: "SendReceiveIntermediate-Client-" + ver.name,
11326 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011327 MinVersion: ver.version,
11328 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011329 Certificates: []Certificate{rsaChainCertificate},
11330 ClientAuth: RequireAnyClientCert,
11331 },
11332 expectPeerCertificate: &rsaChainCertificate,
11333 flags: []string{
11334 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11335 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11336 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11337 },
11338 })
11339
11340 testCases = append(testCases, testCase{
11341 testType: serverTest,
11342 name: "SendReceiveIntermediate-Server-" + ver.name,
11343 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011344 MinVersion: ver.version,
11345 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011346 Certificates: []Certificate{rsaChainCertificate},
11347 },
11348 expectPeerCertificate: &rsaChainCertificate,
11349 flags: []string{
11350 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11351 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11352 "-require-any-client-certificate",
11353 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11354 },
11355 })
11356 }
11357}
11358
David Benjaminbbaf3672016-11-17 10:53:09 +090011359func addRetainOnlySHA256ClientCertTests() {
11360 for _, ver := range tlsVersions {
11361 // Test that enabling
11362 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11363 // actually requesting a client certificate is a no-op.
11364 testCases = append(testCases, testCase{
11365 testType: serverTest,
11366 name: "RetainOnlySHA256-NoCert-" + ver.name,
11367 config: Config{
11368 MinVersion: ver.version,
11369 MaxVersion: ver.version,
11370 },
11371 flags: []string{
11372 "-retain-only-sha256-client-cert-initial",
11373 "-retain-only-sha256-client-cert-resume",
11374 },
11375 resumeSession: true,
11376 })
11377
11378 // Test that when retaining only a SHA-256 certificate is
11379 // enabled, the hash appears as expected.
11380 testCases = append(testCases, testCase{
11381 testType: serverTest,
11382 name: "RetainOnlySHA256-Cert-" + ver.name,
11383 config: Config{
11384 MinVersion: ver.version,
11385 MaxVersion: ver.version,
11386 Certificates: []Certificate{rsaCertificate},
11387 },
11388 flags: []string{
11389 "-verify-peer",
11390 "-retain-only-sha256-client-cert-initial",
11391 "-retain-only-sha256-client-cert-resume",
11392 "-expect-sha256-client-cert-initial",
11393 "-expect-sha256-client-cert-resume",
11394 },
11395 resumeSession: true,
11396 })
11397
11398 // Test that when the config changes from on to off, a
11399 // resumption is rejected because the server now wants the full
11400 // certificate chain.
11401 testCases = append(testCases, testCase{
11402 testType: serverTest,
11403 name: "RetainOnlySHA256-OnOff-" + ver.name,
11404 config: Config{
11405 MinVersion: ver.version,
11406 MaxVersion: ver.version,
11407 Certificates: []Certificate{rsaCertificate},
11408 },
11409 flags: []string{
11410 "-verify-peer",
11411 "-retain-only-sha256-client-cert-initial",
11412 "-expect-sha256-client-cert-initial",
11413 },
11414 resumeSession: true,
11415 expectResumeRejected: true,
11416 })
11417
11418 // Test that when the config changes from off to on, a
11419 // resumption is rejected because the server now wants just the
11420 // hash.
11421 testCases = append(testCases, testCase{
11422 testType: serverTest,
11423 name: "RetainOnlySHA256-OffOn-" + ver.name,
11424 config: Config{
11425 MinVersion: ver.version,
11426 MaxVersion: ver.version,
11427 Certificates: []Certificate{rsaCertificate},
11428 },
11429 flags: []string{
11430 "-verify-peer",
11431 "-retain-only-sha256-client-cert-resume",
11432 "-expect-sha256-client-cert-resume",
11433 },
11434 resumeSession: true,
11435 expectResumeRejected: true,
11436 })
11437 }
11438}
11439
Adam Langleya4b91982016-12-12 12:05:53 -080011440func addECDSAKeyUsageTests() {
11441 p256 := elliptic.P256()
11442 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11443 if err != nil {
11444 panic(err)
11445 }
11446
11447 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11448 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11449 if err != nil {
11450 panic(err)
11451 }
11452
11453 template := x509.Certificate{
11454 SerialNumber: serialNumber,
11455 Subject: pkix.Name{
11456 Organization: []string{"Acme Co"},
11457 },
11458 NotBefore: time.Now(),
11459 NotAfter: time.Now(),
11460
11461 // An ECC certificate with only the keyAgreement key usgae may
11462 // be used with ECDH, but not ECDSA.
11463 KeyUsage: x509.KeyUsageKeyAgreement,
11464 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11465 BasicConstraintsValid: true,
11466 }
11467
11468 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11469 if err != nil {
11470 panic(err)
11471 }
11472
11473 cert := Certificate{
11474 Certificate: [][]byte{derBytes},
11475 PrivateKey: priv,
11476 }
11477
11478 for _, ver := range tlsVersions {
11479 if ver.version < VersionTLS12 {
11480 continue
11481 }
11482
11483 testCases = append(testCases, testCase{
11484 testType: clientTest,
11485 name: "ECDSAKeyUsage-" + ver.name,
11486 config: Config{
11487 MinVersion: ver.version,
11488 MaxVersion: ver.version,
11489 Certificates: []Certificate{cert},
11490 },
11491 shouldFail: true,
11492 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11493 })
11494 }
11495}
11496
David Benjamin8c26d752017-03-26 15:13:51 -050011497func addExtraHandshakeTests() {
11498 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11499 // to ensure there is no transport I/O.
11500 testCases = append(testCases, testCase{
11501 testType: clientTest,
11502 name: "ExtraHandshake-Client-TLS12",
11503 config: Config{
11504 MinVersion: VersionTLS12,
11505 MaxVersion: VersionTLS12,
11506 },
11507 flags: []string{
11508 "-async",
11509 "-no-op-extra-handshake",
11510 },
11511 })
11512 testCases = append(testCases, testCase{
11513 testType: serverTest,
11514 name: "ExtraHandshake-Server-TLS12",
11515 config: Config{
11516 MinVersion: VersionTLS12,
11517 MaxVersion: VersionTLS12,
11518 },
11519 flags: []string{
11520 "-async",
11521 "-no-op-extra-handshake",
11522 },
11523 })
11524 testCases = append(testCases, testCase{
11525 testType: clientTest,
11526 name: "ExtraHandshake-Client-TLS13",
11527 config: Config{
11528 MinVersion: VersionTLS13,
11529 MaxVersion: VersionTLS13,
11530 },
11531 flags: []string{
11532 "-async",
11533 "-no-op-extra-handshake",
11534 },
11535 })
11536 testCases = append(testCases, testCase{
11537 testType: serverTest,
11538 name: "ExtraHandshake-Server-TLS13",
11539 config: Config{
11540 MinVersion: VersionTLS13,
11541 MaxVersion: VersionTLS13,
11542 },
11543 flags: []string{
11544 "-async",
11545 "-no-op-extra-handshake",
11546 },
11547 })
11548
11549 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11550 testCases = append(testCases, testCase{
11551 testType: serverTest,
11552 name: "ExtraHandshake-Server-EarlyData-TLS13",
11553 config: Config{
11554 MaxVersion: VersionTLS13,
11555 MinVersion: VersionTLS13,
11556 Bugs: ProtocolBugs{
11557 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11558 ExpectEarlyDataAccepted: true,
11559 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11560 },
11561 },
11562 messageCount: 2,
11563 resumeSession: true,
11564 flags: []string{
11565 "-async",
11566 "-enable-early-data",
11567 "-expect-accept-early-data",
11568 "-no-op-extra-handshake",
11569 },
11570 })
11571
11572 // An extra SSL_do_handshake drives the handshake to completion in False
11573 // Start. We test this by handshaking twice and asserting the False
11574 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11575 // how the test works.
11576 testCases = append(testCases, testCase{
11577 testType: clientTest,
11578 name: "ExtraHandshake-FalseStart",
11579 config: Config{
11580 MaxVersion: VersionTLS12,
11581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11582 NextProtos: []string{"foo"},
11583 Bugs: ProtocolBugs{
11584 ExpectFalseStart: true,
11585 AlertBeforeFalseStartTest: alertAccessDenied,
11586 },
11587 },
11588 flags: []string{
11589 "-handshake-twice",
11590 "-false-start",
11591 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011592 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011593 },
11594 shimWritesFirst: true,
11595 shouldFail: true,
11596 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11597 expectedLocalError: "tls: peer did not false start: EOF",
11598 })
11599}
11600
Adam Langley7c803a62015-06-15 15:35:05 -070011601func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011602 defer wg.Done()
11603
11604 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011605 var err error
11606
David Benjaminba28dfc2016-11-15 17:47:21 +090011607 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011608 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11609 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011610 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011611 if err != nil {
11612 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11613 }
11614 break
11615 }
11616 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011617 } else if *repeatUntilFailure {
11618 for err == nil {
11619 statusChan <- statusMsg{test: test, started: true}
11620 err = runTest(test, shimPath, -1)
11621 }
11622 } else {
11623 statusChan <- statusMsg{test: test, started: true}
11624 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011625 }
Adam Langley95c29f32014-06-20 12:00:00 -070011626 statusChan <- statusMsg{test: test, err: err}
11627 }
11628}
11629
11630type statusMsg struct {
11631 test *testCase
11632 started bool
11633 err error
11634}
11635
David Benjamin5f237bc2015-02-11 17:14:15 -050011636func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011637 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011638
David Benjamin5f237bc2015-02-11 17:14:15 -050011639 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011640 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011641 if !*pipe {
11642 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011643 var erase string
11644 for i := 0; i < lineLen; i++ {
11645 erase += "\b \b"
11646 }
11647 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011648 }
11649
Adam Langley95c29f32014-06-20 12:00:00 -070011650 if msg.started {
11651 started++
11652 } else {
11653 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011654
11655 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011656 if msg.err == errUnimplemented {
11657 if *pipe {
11658 // Print each test instead of a status line.
11659 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11660 }
11661 unimplemented++
11662 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11663 } else {
11664 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11665 failed++
11666 testOutput.addResult(msg.test.name, "FAIL")
11667 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011668 } else {
11669 if *pipe {
11670 // Print each test instead of a status line.
11671 fmt.Printf("PASSED (%s)\n", msg.test.name)
11672 }
11673 testOutput.addResult(msg.test.name, "PASS")
11674 }
Adam Langley95c29f32014-06-20 12:00:00 -070011675 }
11676
David Benjamin5f237bc2015-02-11 17:14:15 -050011677 if !*pipe {
11678 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011679 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011680 lineLen = len(line)
11681 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011682 }
Adam Langley95c29f32014-06-20 12:00:00 -070011683 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011684
11685 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011686}
11687
11688func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011689 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011690 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011691 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011692
Adam Langley7c803a62015-06-15 15:35:05 -070011693 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011694 addCipherSuiteTests()
11695 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011696 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011697 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011698 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011699 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011700 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011701 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011702 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011703 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011704 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011705 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011706 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011707 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011708 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011709 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011710 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011711 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011712 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011713 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011714 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011715 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011716 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011717 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011718 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011719 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011720 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011721 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011722 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011723 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011724 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011725 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011726 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011727 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011728
11729 var wg sync.WaitGroup
11730
Adam Langley7c803a62015-06-15 15:35:05 -070011731 statusChan := make(chan statusMsg, *numWorkers)
11732 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011733 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011734
EKRf71d7ed2016-08-06 13:25:12 -070011735 if len(*shimConfigFile) != 0 {
11736 encoded, err := ioutil.ReadFile(*shimConfigFile)
11737 if err != nil {
11738 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11739 os.Exit(1)
11740 }
11741
11742 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11743 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11744 os.Exit(1)
11745 }
11746 }
11747
David Benjamin025b3d32014-07-01 19:53:04 -040011748 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011749
Adam Langley7c803a62015-06-15 15:35:05 -070011750 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011751 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011752 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011753 }
11754
David Benjamin270f0a72016-03-17 14:41:36 -040011755 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011756 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011757 matched := true
11758 if len(*testToRun) != 0 {
11759 var err error
11760 matched, err = filepath.Match(*testToRun, testCases[i].name)
11761 if err != nil {
11762 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11763 os.Exit(1)
11764 }
11765 }
11766
EKRf71d7ed2016-08-06 13:25:12 -070011767 if !*includeDisabled {
11768 for pattern := range shimConfig.DisabledTests {
11769 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11770 if err != nil {
11771 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11772 os.Exit(1)
11773 }
11774
11775 if isDisabled {
11776 matched = false
11777 break
11778 }
11779 }
11780 }
11781
David Benjamin17e12922016-07-28 18:04:43 -040011782 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011783 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011784 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011785
11786 // Only run one test if repeating until failure.
11787 if *repeatUntilFailure {
11788 break
11789 }
Adam Langley95c29f32014-06-20 12:00:00 -070011790 }
11791 }
David Benjamin17e12922016-07-28 18:04:43 -040011792
David Benjamin270f0a72016-03-17 14:41:36 -040011793 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011794 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011795 os.Exit(1)
11796 }
Adam Langley95c29f32014-06-20 12:00:00 -070011797
11798 close(testChan)
11799 wg.Wait()
11800 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011801 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011802
11803 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011804
11805 if *jsonOutput != "" {
11806 if err := testOutput.writeTo(*jsonOutput); err != nil {
11807 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11808 }
11809 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011810
EKR842ae6c2016-07-27 09:22:05 +020011811 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11812 os.Exit(1)
11813 }
11814
11815 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011816 os.Exit(1)
11817 }
Adam Langley95c29f32014-06-20 12:00:00 -070011818}