blob: 64d0f87a28d96d804311f4435de68a47c1b9e24b [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdezc94998a2017-06-20 10:55:02 -0400266// configVersionToWire maps a protocol version to the default wire version to
267// test at that protocol.
268//
269// TODO(davidben): Rather than mapping these, make tlsVersions contains a list
270// of wire versions and test all of them.
271func configVersionToWire(vers uint16, protocol protocol) uint16 {
272 if protocol == dtls {
273 switch vers {
274 case VersionTLS12:
275 return VersionDTLS12
276 case VersionTLS10:
277 return VersionDTLS10
278 }
279 } else {
280 switch vers {
281 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
282 return vers
283 case VersionTLS13:
284 return tls13DraftVersion
285 }
286 }
287
288 panic("unknown version")
289}
290
Adam Langley2ff79332017-02-28 13:45:39 -0800291// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
292func encodeDERValues(values [][]byte) string {
293 var ret string
294 for i, v := range values {
295 if i > 0 {
296 ret += ","
297 }
298 ret += hex.EncodeToString(v)
299 }
300
301 return ret
302}
303
David Benjamin025b3d32014-07-01 19:53:04 -0400304type testType int
305
306const (
307 clientTest testType = iota
308 serverTest
309)
310
David Benjamin6fd297b2014-08-11 18:43:38 -0400311type protocol int
312
313const (
314 tls protocol = iota
315 dtls
316)
317
David Benjaminfc7b0862014-09-06 13:21:53 -0400318const (
319 alpn = 1
320 npn = 2
321)
322
Adam Langley95c29f32014-06-20 12:00:00 -0700323type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400324 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400325 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700326 name string
327 config Config
328 shouldFail bool
329 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700330 // expectedLocalError, if not empty, contains a substring that must be
331 // found in the local error.
332 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400333 // expectedVersion, if non-zero, specifies the TLS version that must be
334 // negotiated.
335 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400336 // expectedResumeVersion, if non-zero, specifies the TLS version that
337 // must be negotiated on resumption. If zero, expectedVersion is used.
338 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400339 // expectedCipher, if non-zero, specifies the TLS cipher suite that
340 // should be negotiated.
341 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400342 // expectChannelID controls whether the connection should have
343 // negotiated a Channel ID with channelIDKey.
344 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400345 // expectedNextProto controls whether the connection should
346 // negotiate a next protocol via NPN or ALPN.
347 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 // expectNoNextProto, if true, means that no next protocol should be
349 // negotiated.
350 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400351 // expectedNextProtoType, if non-zero, is the expected next
352 // protocol negotiation mechanism.
353 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500354 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
355 // should be negotiated. If zero, none should be negotiated.
356 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100357 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
358 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100359 // expectedSCTList, if not nil, is the expected SCT list to be received.
360 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700361 // expectedPeerSignatureAlgorithm, if not zero, is the signature
362 // algorithm that the peer should have used in the handshake.
363 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400364 // expectedCurveID, if not zero, is the curve that the handshake should
365 // have used.
366 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700367 // messageLen is the length, in bytes, of the test message that will be
368 // sent.
369 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400370 // messageCount is the number of test messages that will be sent.
371 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400372 // certFile is the path to the certificate to use for the server.
373 certFile string
374 // keyFile is the path to the private key to use for the server.
375 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400376 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400377 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400378 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400379 // resumeRenewedSession controls whether a third connection should be
380 // tested which attempts to resume the second connection's session.
381 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700382 // expectResumeRejected, if true, specifies that the attempted
383 // resumption must be rejected by the client. This is only valid for a
384 // serverTest.
385 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400386 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // resumption. Unless newSessionsOnResume is set,
388 // SessionTicketKey, ServerSessionCache, and
389 // ClientSessionCache are copied from the initial connection's
390 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400391 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500392 // newSessionsOnResume, if true, will cause resumeConfig to
393 // use a different session resumption context.
394 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400395 // noSessionCache, if true, will cause the server to run without a
396 // session cache.
397 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400398 // sendPrefix sends a prefix on the socket before actually performing a
399 // handshake.
400 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400401 // shimWritesFirst controls whether the shim sends an initial "hello"
402 // message before doing a roundtrip with the runner.
403 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400404 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
405 // does not complete the write until responding to the first runner
406 // message.
407 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400408 // shimShutsDown, if true, runs a test where the shim shuts down the
409 // connection immediately after the handshake rather than echoing
410 // messages from the runner.
411 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400412 // renegotiate indicates the number of times the connection should be
413 // renegotiated during the exchange.
414 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400415 // sendHalfHelloRequest, if true, causes the server to send half a
416 // HelloRequest when the handshake completes.
417 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700418 // renegotiateCiphers is a list of ciphersuite ids that will be
419 // switched in just before renegotiation.
420 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500421 // replayWrites, if true, configures the underlying transport
422 // to replay every write it makes in DTLS tests.
423 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 // damageFirstWrite, if true, configures the underlying transport to
425 // damage the final byte of the first application data write.
426 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400427 // exportKeyingMaterial, if non-zero, configures the test to exchange
428 // keying material and verify they match.
429 exportKeyingMaterial int
430 exportLabel string
431 exportContext string
432 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400433 // flags, if not empty, contains a list of command-line flags that will
434 // be passed to the shim program.
435 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700436 // testTLSUnique, if true, causes the shim to send the tls-unique value
437 // which will be compared against the expected value.
438 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400439 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400440 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400441 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400442 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400443 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400444 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400445 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
446 // be sent before each test message.
447 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400448 // sendKeyUpdates is the number of consecutive key updates to send
449 // before and after the test message.
450 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400451 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
452 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400453 // expectMessageDropped, if true, means the test message is expected to
454 // be dropped by the client rather than echoed back.
455 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900456 // expectPeerCertificate, if not nil, is the certificate chain the peer
457 // is expected to send.
458 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500459 // shimPrefix is the prefix that the shim will send to the server.
460 shimPrefix string
461 // resumeShimPrefix is the prefix that the shim will send to the server on a
462 // resumption.
463 resumeShimPrefix string
Adam Langley95c29f32014-06-20 12:00:00 -0700464}
465
Adam Langley7c803a62015-06-15 15:35:05 -0700466var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700467
David Benjamin0fde2eb2017-06-30 19:11:22 -0400468func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if len(data) == 0 {
470 return
471 }
472
David Benjamin0fde2eb2017-06-30 19:11:22 -0400473 settings, err := ioutil.ReadFile(path)
474 if err != nil {
475 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500476 return
477 }
478
David Benjamin0fde2eb2017-06-30 19:11:22 -0400479 settings = append(settings, data...)
480 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
481 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500482 }
483}
484
David Benjamin3ed59772016-03-08 12:50:21 -0500485// A timeoutConn implements an idle timeout on each Read and Write operation.
486type timeoutConn struct {
487 net.Conn
488 timeout time.Duration
489}
490
491func (t *timeoutConn) Read(b []byte) (int, error) {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
495 return t.Conn.Read(b)
496}
497
498func (t *timeoutConn) Write(b []byte) (int, error) {
499 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
500 return 0, err
501 }
502 return t.Conn.Write(b)
503}
504
David Benjamin0fde2eb2017-06-30 19:11:22 -0400505func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400506 if !test.noSessionCache {
507 if config.ClientSessionCache == nil {
508 config.ClientSessionCache = NewLRUClientSessionCache(1)
509 }
510 if config.ServerSessionCache == nil {
511 config.ServerSessionCache = NewLRUServerSessionCache(1)
512 }
513 }
514 if test.testType == clientTest {
515 if len(config.Certificates) == 0 {
516 config.Certificates = []Certificate{rsaCertificate}
517 }
518 } else {
519 // Supply a ServerName to ensure a constant session cache key,
520 // rather than falling back to net.Conn.RemoteAddr.
521 if len(config.ServerName) == 0 {
522 config.ServerName = "test"
523 }
524 }
525 if *fuzzer {
526 config.Bugs.NullAllCiphers = true
527 }
David Benjamin01a90572016-09-22 00:11:43 -0400528 if *deterministic {
529 config.Time = func() time.Time { return time.Unix(1234, 1234) }
530 }
David Benjamine54af062016-08-08 19:21:18 -0400531
David Benjamin01784b42016-06-07 18:00:52 -0400532 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500533
David Benjamin6fd297b2014-08-11 18:43:38 -0400534 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500535 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
536 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500537 }
538
David Benjamin9867b7d2016-03-01 23:25:48 -0500539 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500540 local, peer := "client", "server"
541 if test.testType == clientTest {
542 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500543 }
David Benjaminebda9b32015-11-02 15:33:18 -0500544 connDebug := &recordingConn{
545 Conn: conn,
546 isDatagram: test.protocol == dtls,
547 local: local,
548 peer: peer,
549 }
550 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500551 if *flagDebug {
552 defer connDebug.WriteTo(os.Stdout)
553 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400554 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500555 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 path := transcriptPrefix + strconv.Itoa(num)
557 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500558 }()
559 }
David Benjaminebda9b32015-11-02 15:33:18 -0500560
561 if config.Bugs.PacketAdaptor != nil {
562 config.Bugs.PacketAdaptor.debug = connDebug
563 }
564 }
565
566 if test.replayWrites {
567 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400568 }
569
David Benjamin3ed59772016-03-08 12:50:21 -0500570 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500571 if test.damageFirstWrite {
572 connDamage = newDamageAdaptor(conn)
573 conn = connDamage
574 }
575
David Benjamin6fd297b2014-08-11 18:43:38 -0400576 if test.sendPrefix != "" {
577 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
578 return err
579 }
David Benjamin98e882e2014-08-08 13:24:34 -0400580 }
581
David Benjamin1d5c83e2014-07-22 19:20:02 -0400582 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400583 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400584 if test.protocol == dtls {
585 tlsConn = DTLSServer(conn, config)
586 } else {
587 tlsConn = Server(conn, config)
588 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400589 } else {
590 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400591 if test.protocol == dtls {
592 tlsConn = DTLSClient(conn, config)
593 } else {
594 tlsConn = Client(conn, config)
595 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400596 }
David Benjamin30789da2015-08-29 22:56:45 -0400597 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598
Adam Langley95c29f32014-06-20 12:00:00 -0700599 if err := tlsConn.Handshake(); err != nil {
600 return err
601 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700602
David Benjamin01fe8202014-09-24 15:21:44 -0400603 // TODO(davidben): move all per-connection expectations into a dedicated
604 // expectations struct that can be specified separately for the two
605 // legs.
606 expectedVersion := test.expectedVersion
607 if isResume && test.expectedResumeVersion != 0 {
608 expectedVersion = test.expectedResumeVersion
609 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 connState := tlsConn.ConnectionState()
611 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400612 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400613 }
614
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700615 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400616 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
617 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700618 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
619 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
620 }
David Benjamin90da8c82015-04-20 14:57:57 -0400621
David Benjamina08e49d2014-08-24 01:46:07 -0400622 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700623 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if channelID == nil {
625 return fmt.Errorf("no channel ID negotiated")
626 }
627 if channelID.Curve != channelIDKey.Curve ||
628 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
629 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
630 return fmt.Errorf("incorrect channel ID")
631 }
632 }
633
David Benjaminae2888f2014-09-06 12:58:58 -0400634 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700635 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400636 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
637 }
638 }
639
David Benjaminc7ce9772015-10-09 19:32:41 -0400640 if test.expectNoNextProto {
641 if actual := connState.NegotiatedProtocol; actual != "" {
642 return fmt.Errorf("got unexpected next proto %s", actual)
643 }
644 }
645
David Benjaminfc7b0862014-09-06 13:21:53 -0400646 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700647 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400648 return fmt.Errorf("next proto type mismatch")
649 }
650 }
651
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700652 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500653 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
654 }
655
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100656 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300657 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100658 }
659
Paul Lietar4fac72e2015-09-09 13:44:55 +0100660 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
661 return fmt.Errorf("SCT list mismatch")
662 }
663
Nick Harper60edffd2016-06-21 15:19:24 -0700664 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
665 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400666 }
667
Steven Valdez5440fe02016-07-18 12:40:30 -0400668 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
669 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
670 }
671
David Benjamin2c516452016-11-15 10:16:54 +0900672 if test.expectPeerCertificate != nil {
673 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
674 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
675 }
676 for i, cert := range connState.PeerCertificates {
677 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
678 return fmt.Errorf("peer certificate %d did not match", i+1)
679 }
680 }
681 }
682
David Benjaminc565ebb2015-04-03 04:06:36 -0400683 if test.exportKeyingMaterial > 0 {
684 actual := make([]byte, test.exportKeyingMaterial)
685 if _, err := io.ReadFull(tlsConn, actual); err != nil {
686 return err
687 }
688 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
689 if err != nil {
690 return err
691 }
692 if !bytes.Equal(actual, expected) {
693 return fmt.Errorf("keying material mismatch")
694 }
695 }
696
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700697 if test.testTLSUnique {
698 var peersValue [12]byte
699 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
700 return err
701 }
702 expected := tlsConn.ConnectionState().TLSUnique
703 if !bytes.Equal(peersValue[:], expected) {
704 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
705 }
706 }
707
David Benjamin47921102016-07-28 11:29:18 -0400708 if test.sendHalfHelloRequest {
709 tlsConn.SendHalfHelloRequest()
710 }
711
Steven Valdeze831a812017-03-09 14:56:07 -0500712 shimPrefix := test.shimPrefix
713 if isResume {
714 shimPrefix = test.resumeShimPrefix
715 }
716 if test.shimWritesFirst || test.readWithUnfinishedWrite {
717 shimPrefix = "hello"
718 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400719 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400720 // If readWithUnfinishedWrite is set, the shim prefix will be
721 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500722 if shimPrefix != "" && !test.readWithUnfinishedWrite {
723 var buf = make([]byte, len(shimPrefix))
724 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400725 if err != nil {
726 return err
727 }
Steven Valdeze831a812017-03-09 14:56:07 -0500728 if string(buf) != shimPrefix {
729 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400730 }
Steven Valdeze831a812017-03-09 14:56:07 -0500731 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400732 }
733
Adam Langleycf2d4f42014-10-28 19:06:14 -0700734 if test.renegotiateCiphers != nil {
735 config.CipherSuites = test.renegotiateCiphers
736 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400737 for i := 0; i < test.renegotiate; i++ {
738 if err := tlsConn.Renegotiate(); err != nil {
739 return err
740 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700741 }
742 } else if test.renegotiateCiphers != nil {
743 panic("renegotiateCiphers without renegotiate")
744 }
745
David Benjamin5fa3eba2015-01-22 16:35:40 -0500746 if test.damageFirstWrite {
747 connDamage.setDamage(true)
748 tlsConn.Write([]byte("DAMAGED WRITE"))
749 connDamage.setDamage(false)
750 }
751
David Benjamin8e6db492015-07-25 18:29:23 -0400752 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700753 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400754 if test.protocol == dtls {
755 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
756 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700757 // Read until EOF.
758 _, err := io.Copy(ioutil.Discard, tlsConn)
759 return err
760 }
David Benjamin4417d052015-04-05 04:17:25 -0400761 if messageLen == 0 {
762 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700763 }
Adam Langley95c29f32014-06-20 12:00:00 -0700764
David Benjamin8e6db492015-07-25 18:29:23 -0400765 messageCount := test.messageCount
766 if messageCount == 0 {
767 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400768 }
769
David Benjamin8e6db492015-07-25 18:29:23 -0400770 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400771 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400772 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400773 }
774
David Benjamin8e6db492015-07-25 18:29:23 -0400775 for i := 0; i < test.sendEmptyRecords; i++ {
776 tlsConn.Write(nil)
777 }
778
779 for i := 0; i < test.sendWarningAlerts; i++ {
780 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
781 }
782
David Benjamin24e58862017-06-14 18:45:29 -0400783 if test.sendBogusAlertType {
784 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
785 }
786
David Benjaminbbba9392017-04-06 12:54:12 -0400787 testMessage := make([]byte, messageLen)
788 for i := range testMessage {
789 testMessage[i] = 0x42 ^ byte(j)
790 }
791 tlsConn.Write(testMessage)
792
793 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500794 if shimPrefix != "" {
795 var buf = make([]byte, len(shimPrefix))
796 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400797 if err != nil {
798 return err
799 }
Steven Valdeze831a812017-03-09 14:56:07 -0500800 if string(buf) != shimPrefix {
801 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400802 }
Steven Valdeze831a812017-03-09 14:56:07 -0500803 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400804 }
805
David Benjamin4f75aaf2015-09-01 16:53:10 -0400806 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400807 // The shim will not respond.
808 continue
809 }
810
David Benjaminbbba9392017-04-06 12:54:12 -0400811 // Process the KeyUpdate ACK. However many KeyUpdates the runner
812 // sends, the shim should respond only once.
813 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
814 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
815 return err
816 }
817 }
818
David Benjamin8e6db492015-07-25 18:29:23 -0400819 buf := make([]byte, len(testMessage))
820 if test.protocol == dtls {
821 bufTmp := make([]byte, len(buf)+1)
822 n, err := tlsConn.Read(bufTmp)
823 if err != nil {
824 return err
825 }
826 if n != len(buf) {
827 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
828 }
829 copy(buf, bufTmp)
830 } else {
831 _, err := io.ReadFull(tlsConn, buf)
832 if err != nil {
833 return err
834 }
835 }
836
837 for i, v := range buf {
838 if v != testMessage[i]^0xff {
839 return fmt.Errorf("bad reply contents at byte %d", i)
840 }
Adam Langley95c29f32014-06-20 12:00:00 -0700841 }
842 }
843
844 return nil
845}
846
David Benjamin325b5c32014-07-01 19:40:31 -0400847func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400848 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700849 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400850 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700851 }
David Benjamin325b5c32014-07-01 19:40:31 -0400852 valgrindArgs = append(valgrindArgs, path)
853 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700854
David Benjamin325b5c32014-07-01 19:40:31 -0400855 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700856}
857
David Benjamin325b5c32014-07-01 19:40:31 -0400858func gdbOf(path string, args ...string) *exec.Cmd {
859 xtermArgs := []string{"-e", "gdb", "--args"}
860 xtermArgs = append(xtermArgs, path)
861 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamind16bf342015-12-18 00:53:12 -0500866func lldbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "lldb", "--"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
870
871 return exec.Command("xterm", xtermArgs...)
872}
873
EKR842ae6c2016-07-27 09:22:05 +0200874var (
875 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
876 errUnimplemented = errors.New("child process does not implement needed flags")
877)
Adam Langley69a01602014-11-17 17:26:55 -0800878
David Benjamin87c8a642015-02-21 01:54:29 -0500879// accept accepts a connection from listener, unless waitChan signals a process
880// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400881func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500882 type connOrError struct {
883 conn net.Conn
884 err error
885 }
886 connChan := make(chan connOrError, 1)
887 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400888 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500889 conn, err := listener.Accept()
890 connChan <- connOrError{conn, err}
891 close(connChan)
892 }()
893 select {
894 case result := <-connChan:
895 return result.conn, result.err
896 case childErr := <-waitChan:
897 waitChan <- childErr
898 return nil, fmt.Errorf("child exited early: %s", childErr)
899 }
900}
901
EKRf71d7ed2016-08-06 13:25:12 -0700902func translateExpectedError(errorStr string) string {
903 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
904 return translated
905 }
906
907 if *looseErrors {
908 return ""
909 }
910
911 return errorStr
912}
913
Adam Langley7c803a62015-06-15 15:35:05 -0700914func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400915 // Help debugging panics on the Go side.
916 defer func() {
917 if r := recover(); r != nil {
918 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
919 panic(r)
920 }
921 }()
922
Adam Langley38311732014-10-16 19:04:35 -0700923 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
924 panic("Error expected without shouldFail in " + test.name)
925 }
926
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700927 if test.expectResumeRejected && !test.resumeSession {
928 panic("expectResumeRejected without resumeSession in " + test.name)
929 }
930
Adam Langley33b1d4f2016-12-07 15:03:45 -0800931 for _, ver := range tlsVersions {
932 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
933 continue
934 }
935
936 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
937 continue
938 }
939
940 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
941 }
942
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700943 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
944 if err != nil {
945 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
946 }
David Benjamin87c8a642015-02-21 01:54:29 -0500947 if err != nil {
948 panic(err)
949 }
950 defer func() {
951 if listener != nil {
952 listener.Close()
953 }
954 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700955
David Benjamin87c8a642015-02-21 01:54:29 -0500956 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400957 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400958 flags = append(flags, "-server")
959
David Benjamin025b3d32014-07-01 19:53:04 -0400960 flags = append(flags, "-key-file")
961 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700962 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400963 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700964 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400965 }
966
967 flags = append(flags, "-cert-file")
968 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700969 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400970 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700971 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400972 }
973 }
David Benjamin5a593af2014-08-11 19:51:50 -0400974
David Benjamin6fd297b2014-08-11 18:43:38 -0400975 if test.protocol == dtls {
976 flags = append(flags, "-dtls")
977 }
978
David Benjamin46662482016-08-17 00:51:00 -0400979 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400980 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400981 resumeCount++
982 if test.resumeRenewedSession {
983 resumeCount++
984 }
985 }
986
987 if resumeCount > 0 {
988 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400989 }
990
David Benjamine58c4f52014-08-24 03:47:07 -0400991 if test.shimWritesFirst {
992 flags = append(flags, "-shim-writes-first")
993 }
994
David Benjaminbbba9392017-04-06 12:54:12 -0400995 if test.readWithUnfinishedWrite {
996 flags = append(flags, "-read-with-unfinished-write")
997 }
998
David Benjamin30789da2015-08-29 22:56:45 -0400999 if test.shimShutsDown {
1000 flags = append(flags, "-shim-shuts-down")
1001 }
1002
David Benjaminc565ebb2015-04-03 04:06:36 -04001003 if test.exportKeyingMaterial > 0 {
1004 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1005 flags = append(flags, "-export-label", test.exportLabel)
1006 flags = append(flags, "-export-context", test.exportContext)
1007 if test.useExportContext {
1008 flags = append(flags, "-use-export-context")
1009 }
1010 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001011 if test.expectResumeRejected {
1012 flags = append(flags, "-expect-session-miss")
1013 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001014
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001015 if test.testTLSUnique {
1016 flags = append(flags, "-tls-unique")
1017 }
1018
David Benjamin0fde2eb2017-06-30 19:11:22 -04001019 var transcriptPrefix string
1020 if len(*transcriptDir) != 0 {
1021 protocol := "tls"
1022 if test.protocol == dtls {
1023 protocol = "dtls"
1024 }
1025
1026 side := "client"
1027 if test.testType == serverTest {
1028 side = "server"
1029 }
1030
1031 dir := filepath.Join(*transcriptDir, protocol, side)
1032 if err := os.MkdirAll(dir, 0755); err != nil {
1033 return err
1034 }
1035 transcriptPrefix = filepath.Join(dir, test.name+"-")
1036 flags = append(flags, "-write-settings", transcriptPrefix)
1037 }
1038
David Benjamin025b3d32014-07-01 19:53:04 -04001039 flags = append(flags, test.flags...)
1040
1041 var shim *exec.Cmd
1042 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001043 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001044 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001045 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001046 } else if *useLLDB {
1047 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001048 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001049 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001050 }
David Benjamin025b3d32014-07-01 19:53:04 -04001051 shim.Stdin = os.Stdin
1052 var stdoutBuf, stderrBuf bytes.Buffer
1053 shim.Stdout = &stdoutBuf
1054 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001055 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001056 shim.Env = os.Environ()
1057 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001058 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001059 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001060 }
1061 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1062 }
David Benjamin025b3d32014-07-01 19:53:04 -04001063
1064 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001065 panic(err)
1066 }
David Benjamin87c8a642015-02-21 01:54:29 -05001067 waitChan := make(chan error, 1)
1068 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001069
1070 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001071
David Benjamin7a4aaa42016-09-20 17:58:14 -04001072 if *deterministic {
1073 config.Rand = &deterministicRand{}
1074 }
1075
David Benjamin87c8a642015-02-21 01:54:29 -05001076 conn, err := acceptOrWait(listener, waitChan)
1077 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001078 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001079 conn.Close()
1080 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001081
David Benjamin46662482016-08-17 00:51:00 -04001082 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001083 var resumeConfig Config
1084 if test.resumeConfig != nil {
1085 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001086 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001087 resumeConfig.SessionTicketKey = config.SessionTicketKey
1088 resumeConfig.ClientSessionCache = config.ClientSessionCache
1089 resumeConfig.ServerSessionCache = config.ServerSessionCache
1090 }
David Benjamin2e045a92016-06-08 13:09:56 -04001091 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001092 } else {
1093 resumeConfig = config
1094 }
David Benjamin87c8a642015-02-21 01:54:29 -05001095 var connResume net.Conn
1096 connResume, err = acceptOrWait(listener, waitChan)
1097 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001098 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001099 connResume.Close()
1100 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001101 }
1102
David Benjamin87c8a642015-02-21 01:54:29 -05001103 // Close the listener now. This is to avoid hangs should the shim try to
1104 // open more connections than expected.
1105 listener.Close()
1106 listener = nil
1107
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001108 var shimKilledLock sync.Mutex
1109 var shimKilled bool
1110 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1111 shimKilledLock.Lock()
1112 shimKilled = true
1113 shimKilledLock.Unlock()
1114 shim.Process.Kill()
1115 })
David Benjamin87c8a642015-02-21 01:54:29 -05001116 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001117 waitTimeout.Stop()
1118 shimKilledLock.Lock()
1119 if shimKilled && err == nil {
1120 err = errors.New("timeout waiting for the shim to exit.")
1121 }
1122 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001123 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001124 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001125 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1126 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001127 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001128 case 89:
1129 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001130 case 99:
1131 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001132 }
1133 }
Adam Langley95c29f32014-06-20 12:00:00 -07001134
David Benjamin9bea3492016-03-02 10:59:16 -05001135 // Account for Windows line endings.
1136 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1137 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001138
1139 // Separate the errors from the shim and those from tools like
1140 // AddressSanitizer.
1141 var extraStderr string
1142 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1143 stderr = stderrParts[0]
1144 extraStderr = stderrParts[1]
1145 }
1146
Adam Langley95c29f32014-06-20 12:00:00 -07001147 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001148 expectedError := translateExpectedError(test.expectedError)
1149 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001150
Adam Langleyac61fa32014-06-23 12:03:11 -07001151 localError := "none"
1152 if err != nil {
1153 localError = err.Error()
1154 }
1155 if len(test.expectedLocalError) != 0 {
1156 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1157 }
Adam Langley95c29f32014-06-20 12:00:00 -07001158
1159 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001160 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001161 if childErr != nil {
1162 childError = childErr.Error()
1163 }
1164
1165 var msg string
1166 switch {
1167 case failed && !test.shouldFail:
1168 msg = "unexpected failure"
1169 case !failed && test.shouldFail:
1170 msg = "unexpected success"
1171 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001172 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001173 default:
1174 panic("internal error")
1175 }
1176
David Benjamin9aafb642016-09-20 19:36:53 -04001177 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001178 }
1179
David Benjamind2ba8892016-09-20 19:41:04 -04001180 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001181 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001182 }
1183
David Benjamind2ba8892016-09-20 19:41:04 -04001184 if *useValgrind && isValgrindError {
1185 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1186 }
1187
Adam Langley95c29f32014-06-20 12:00:00 -07001188 return nil
1189}
1190
David Benjaminaa012042016-12-10 13:33:05 -05001191type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001192 name string
1193 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001194 // excludeFlag is the legacy shim flag to disable the version.
1195 excludeFlag string
1196 hasDTLS bool
1197 // shimTLS and shimDTLS are values the shim uses to refer to these
1198 // versions in TLS and DTLS, respectively.
1199 shimTLS, shimDTLS int
1200}
1201
1202func (vers tlsVersion) shimFlag(protocol protocol) string {
1203 if protocol == dtls {
1204 return strconv.Itoa(vers.shimDTLS)
1205 }
1206 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001207}
1208
1209var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001210 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1211 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1212 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1213 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1214 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001215}
1216
David Benjaminaa012042016-12-10 13:33:05 -05001217type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001218 name string
1219 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001220}
1221
1222var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001223 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001224 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001225 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001226 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001227 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001228 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001229 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001230 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1231 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001232 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1233 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001234 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001235 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001236 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001237 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001238 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001239 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001240 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001241 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001242 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001243 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001244 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1245 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001246 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1247 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001248 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001249 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1250 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1251 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001252 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001253}
1254
David Benjamin8b8c0062014-11-23 02:47:52 -05001255func hasComponent(suiteName, component string) bool {
1256 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1257}
1258
David Benjaminf7768e42014-08-31 02:06:47 -04001259func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001260 return hasComponent(suiteName, "GCM") ||
1261 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001262 hasComponent(suiteName, "SHA384") ||
1263 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001264}
1265
Nick Harper1fd39d82016-06-14 18:14:35 -07001266func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001267 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001268}
1269
David Benjamin8b8c0062014-11-23 02:47:52 -05001270func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001271 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001272}
1273
Adam Langleya7997f12015-05-14 17:38:50 -07001274func bigFromHex(hex string) *big.Int {
1275 ret, ok := new(big.Int).SetString(hex, 16)
1276 if !ok {
1277 panic("failed to parse hex number 0x" + hex)
1278 }
1279 return ret
1280}
1281
Adam Langley7c803a62015-06-15 15:35:05 -07001282func addBasicTests() {
1283 basicTests := []testCase{
1284 {
Adam Langley7c803a62015-06-15 15:35:05 -07001285 name: "NoFallbackSCSV",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 FailIfNotFallbackSCSV: true,
1289 },
1290 },
1291 shouldFail: true,
1292 expectedLocalError: "no fallback SCSV found",
1293 },
1294 {
1295 name: "SendFallbackSCSV",
1296 config: Config{
1297 Bugs: ProtocolBugs{
1298 FailIfNotFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-fallback-scsv"},
1302 },
1303 {
1304 name: "ClientCertificateTypes",
1305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001306 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 ClientAuth: RequestClientCert,
1308 ClientCertificateTypes: []byte{
1309 CertTypeDSSSign,
1310 CertTypeRSASign,
1311 CertTypeECDSASign,
1312 },
1313 },
1314 flags: []string{
1315 "-expect-certificate-types",
1316 base64.StdEncoding.EncodeToString([]byte{
1317 CertTypeDSSSign,
1318 CertTypeRSASign,
1319 CertTypeECDSASign,
1320 }),
1321 },
1322 },
1323 {
Adam Langley7c803a62015-06-15 15:35:05 -07001324 name: "UnauthenticatedECDH",
1325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001326 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1328 Bugs: ProtocolBugs{
1329 UnauthenticatedECDH: true,
1330 },
1331 },
1332 shouldFail: true,
1333 expectedError: ":UNEXPECTED_MESSAGE:",
1334 },
1335 {
1336 name: "SkipCertificateStatus",
1337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001338 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1340 Bugs: ProtocolBugs{
1341 SkipCertificateStatus: true,
1342 },
1343 },
1344 flags: []string{
1345 "-enable-ocsp-stapling",
1346 },
1347 },
1348 {
1349 name: "SkipServerKeyExchange",
1350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001351 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001352 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1353 Bugs: ProtocolBugs{
1354 SkipServerKeyExchange: true,
1355 },
1356 },
1357 shouldFail: true,
1358 expectedError: ":UNEXPECTED_MESSAGE:",
1359 },
1360 {
Adam Langley7c803a62015-06-15 15:35:05 -07001361 testType: serverTest,
1362 name: "Alert",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 SendSpuriousAlert: alertRecordOverflow,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1370 },
1371 {
1372 protocol: dtls,
1373 testType: serverTest,
1374 name: "Alert-DTLS",
1375 config: Config{
1376 Bugs: ProtocolBugs{
1377 SendSpuriousAlert: alertRecordOverflow,
1378 },
1379 },
1380 shouldFail: true,
1381 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1382 },
1383 {
1384 testType: serverTest,
1385 name: "FragmentAlert",
1386 config: Config{
1387 Bugs: ProtocolBugs{
1388 FragmentAlert: true,
1389 SendSpuriousAlert: alertRecordOverflow,
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":BAD_ALERT:",
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "FragmentAlert-DTLS",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 FragmentAlert: true,
1402 SendSpuriousAlert: alertRecordOverflow,
1403 },
1404 },
1405 shouldFail: true,
1406 expectedError: ":BAD_ALERT:",
1407 },
1408 {
1409 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001410 name: "DoubleAlert",
1411 config: Config{
1412 Bugs: ProtocolBugs{
1413 DoubleAlert: true,
1414 SendSpuriousAlert: alertRecordOverflow,
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":BAD_ALERT:",
1419 },
1420 {
1421 protocol: dtls,
1422 testType: serverTest,
1423 name: "DoubleAlert-DTLS",
1424 config: Config{
1425 Bugs: ProtocolBugs{
1426 DoubleAlert: true,
1427 SendSpuriousAlert: alertRecordOverflow,
1428 },
1429 },
1430 shouldFail: true,
1431 expectedError: ":BAD_ALERT:",
1432 },
1433 {
Adam Langley7c803a62015-06-15 15:35:05 -07001434 name: "SkipNewSessionTicket",
1435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001436 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SkipNewSessionTicket: true,
1439 },
1440 },
1441 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001442 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001443 },
1444 {
1445 testType: serverTest,
1446 name: "FallbackSCSV",
1447 config: Config{
1448 MaxVersion: VersionTLS11,
1449 Bugs: ProtocolBugs{
1450 SendFallbackSCSV: true,
1451 },
1452 },
David Benjamin56cadc32016-12-16 19:54:11 -05001453 shouldFail: true,
1454 expectedError: ":INAPPROPRIATE_FALLBACK:",
1455 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001456 },
1457 {
1458 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001459 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001460 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001461 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001462 Bugs: ProtocolBugs{
1463 SendFallbackSCSV: true,
1464 },
1465 },
1466 },
1467 {
1468 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001469 name: "FallbackSCSV-VersionMatch-TLS12",
1470 config: Config{
1471 MaxVersion: VersionTLS12,
1472 Bugs: ProtocolBugs{
1473 SendFallbackSCSV: true,
1474 },
1475 },
1476 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1477 },
1478 {
1479 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001480 name: "FragmentedClientVersion",
1481 config: Config{
1482 Bugs: ProtocolBugs{
1483 MaxHandshakeRecordLength: 1,
1484 FragmentClientVersion: true,
1485 },
1486 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001487 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001488 },
1489 {
Adam Langley7c803a62015-06-15 15:35:05 -07001490 testType: serverTest,
1491 name: "HttpGET",
1492 sendPrefix: "GET / HTTP/1.0\n",
1493 shouldFail: true,
1494 expectedError: ":HTTP_REQUEST:",
1495 },
1496 {
1497 testType: serverTest,
1498 name: "HttpPOST",
1499 sendPrefix: "POST / HTTP/1.0\n",
1500 shouldFail: true,
1501 expectedError: ":HTTP_REQUEST:",
1502 },
1503 {
1504 testType: serverTest,
1505 name: "HttpHEAD",
1506 sendPrefix: "HEAD / HTTP/1.0\n",
1507 shouldFail: true,
1508 expectedError: ":HTTP_REQUEST:",
1509 },
1510 {
1511 testType: serverTest,
1512 name: "HttpPUT",
1513 sendPrefix: "PUT / HTTP/1.0\n",
1514 shouldFail: true,
1515 expectedError: ":HTTP_REQUEST:",
1516 },
1517 {
1518 testType: serverTest,
1519 name: "HttpCONNECT",
1520 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1521 shouldFail: true,
1522 expectedError: ":HTTPS_PROXY_REQUEST:",
1523 },
1524 {
1525 testType: serverTest,
1526 name: "Garbage",
1527 sendPrefix: "blah",
1528 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001529 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001530 },
1531 {
Adam Langley7c803a62015-06-15 15:35:05 -07001532 name: "RSAEphemeralKey",
1533 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001534 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001535 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1536 Bugs: ProtocolBugs{
1537 RSAEphemeralKey: true,
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_MESSAGE:",
1542 },
1543 {
1544 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001545 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001546 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001547 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001548 },
1549 {
1550 protocol: dtls,
1551 name: "DisableEverything-DTLS",
1552 flags: []string{"-no-tls12", "-no-tls1"},
1553 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001554 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001555 },
1556 {
Adam Langley7c803a62015-06-15 15:35:05 -07001557 protocol: dtls,
1558 testType: serverTest,
1559 name: "MTU",
1560 config: Config{
1561 Bugs: ProtocolBugs{
1562 MaxPacketLength: 256,
1563 },
1564 },
1565 flags: []string{"-mtu", "256"},
1566 },
1567 {
1568 protocol: dtls,
1569 testType: serverTest,
1570 name: "MTUExceeded",
1571 config: Config{
1572 Bugs: ProtocolBugs{
1573 MaxPacketLength: 255,
1574 },
1575 },
1576 flags: []string{"-mtu", "256"},
1577 shouldFail: true,
1578 expectedLocalError: "dtls: exceeded maximum packet length",
1579 },
1580 {
Adam Langley7c803a62015-06-15 15:35:05 -07001581 name: "EmptyCertificateList",
1582 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001583 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001584 Bugs: ProtocolBugs{
1585 EmptyCertificateList: true,
1586 },
1587 },
1588 shouldFail: true,
1589 expectedError: ":DECODE_ERROR:",
1590 },
1591 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001592 name: "EmptyCertificateList-TLS13",
1593 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001594 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001595 Bugs: ProtocolBugs{
1596 EmptyCertificateList: true,
1597 },
1598 },
1599 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001600 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001601 },
1602 {
Adam Langley7c803a62015-06-15 15:35:05 -07001603 name: "TLSFatalBadPackets",
1604 damageFirstWrite: true,
1605 shouldFail: true,
1606 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1607 },
1608 {
1609 protocol: dtls,
1610 name: "DTLSIgnoreBadPackets",
1611 damageFirstWrite: true,
1612 },
1613 {
1614 protocol: dtls,
1615 name: "DTLSIgnoreBadPackets-Async",
1616 damageFirstWrite: true,
1617 flags: []string{"-async"},
1618 },
1619 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001620 name: "AppDataBeforeHandshake",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1624 },
1625 },
1626 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001627 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001628 },
1629 {
1630 name: "AppDataBeforeHandshake-Empty",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 AppDataBeforeHandshake: []byte{},
1634 },
1635 },
1636 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001637 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001638 },
1639 {
1640 protocol: dtls,
1641 name: "AppDataBeforeHandshake-DTLS",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "AppDataBeforeHandshake-DTLS-Empty",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 AppDataBeforeHandshake: []byte{},
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
Adam Langley7c803a62015-06-15 15:35:05 -07001662 name: "AppDataAfterChangeCipherSpec",
1663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 Bugs: ProtocolBugs{
1666 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1667 },
1668 },
1669 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001670 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001671 },
1672 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001673 name: "AppDataAfterChangeCipherSpec-Empty",
1674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001675 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001676 Bugs: ProtocolBugs{
1677 AppDataAfterChangeCipherSpec: []byte{},
1678 },
1679 },
1680 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001681 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001682 },
1683 {
Adam Langley7c803a62015-06-15 15:35:05 -07001684 protocol: dtls,
1685 name: "AppDataAfterChangeCipherSpec-DTLS",
1686 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001687 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001688 Bugs: ProtocolBugs{
1689 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1690 },
1691 },
1692 // BoringSSL's DTLS implementation will drop the out-of-order
1693 // application data.
1694 },
1695 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001696 protocol: dtls,
1697 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001699 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001700 Bugs: ProtocolBugs{
1701 AppDataAfterChangeCipherSpec: []byte{},
1702 },
1703 },
1704 // BoringSSL's DTLS implementation will drop the out-of-order
1705 // application data.
1706 },
1707 {
Adam Langley7c803a62015-06-15 15:35:05 -07001708 name: "AlertAfterChangeCipherSpec",
1709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001710 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001711 Bugs: ProtocolBugs{
1712 AlertAfterChangeCipherSpec: alertRecordOverflow,
1713 },
1714 },
1715 shouldFail: true,
1716 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1717 },
1718 {
1719 protocol: dtls,
1720 name: "AlertAfterChangeCipherSpec-DTLS",
1721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001722 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001723 Bugs: ProtocolBugs{
1724 AlertAfterChangeCipherSpec: alertRecordOverflow,
1725 },
1726 },
1727 shouldFail: true,
1728 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1729 },
1730 {
1731 protocol: dtls,
1732 name: "ReorderHandshakeFragments-Small-DTLS",
1733 config: Config{
1734 Bugs: ProtocolBugs{
1735 ReorderHandshakeFragments: true,
1736 // Small enough that every handshake message is
1737 // fragmented.
1738 MaxHandshakeRecordLength: 2,
1739 },
1740 },
1741 },
1742 {
1743 protocol: dtls,
1744 name: "ReorderHandshakeFragments-Large-DTLS",
1745 config: Config{
1746 Bugs: ProtocolBugs{
1747 ReorderHandshakeFragments: true,
1748 // Large enough that no handshake message is
1749 // fragmented.
1750 MaxHandshakeRecordLength: 2048,
1751 },
1752 },
1753 },
1754 {
1755 protocol: dtls,
1756 name: "MixCompleteMessageWithFragments-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 ReorderHandshakeFragments: true,
1760 MixCompleteMessageWithFragments: true,
1761 MaxHandshakeRecordLength: 2,
1762 },
1763 },
1764 },
1765 {
1766 name: "SendInvalidRecordType",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 SendInvalidRecordType: true,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":UNEXPECTED_RECORD:",
1774 },
1775 {
1776 protocol: dtls,
1777 name: "SendInvalidRecordType-DTLS",
1778 config: Config{
1779 Bugs: ProtocolBugs{
1780 SendInvalidRecordType: true,
1781 },
1782 },
1783 shouldFail: true,
1784 expectedError: ":UNEXPECTED_RECORD:",
1785 },
1786 {
1787 name: "FalseStart-SkipServerSecondLeg",
1788 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001789 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1791 NextProtos: []string{"foo"},
1792 Bugs: ProtocolBugs{
1793 SkipNewSessionTicket: true,
1794 SkipChangeCipherSpec: true,
1795 SkipFinished: true,
1796 ExpectFalseStart: true,
1797 },
1798 },
1799 flags: []string{
1800 "-false-start",
1801 "-handshake-never-done",
1802 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001803 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001804 },
1805 shimWritesFirst: true,
1806 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001807 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001808 },
1809 {
1810 name: "FalseStart-SkipServerSecondLeg-Implicit",
1811 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001812 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1814 NextProtos: []string{"foo"},
1815 Bugs: ProtocolBugs{
1816 SkipNewSessionTicket: true,
1817 SkipChangeCipherSpec: true,
1818 SkipFinished: true,
1819 },
1820 },
1821 flags: []string{
1822 "-implicit-handshake",
1823 "-false-start",
1824 "-handshake-never-done",
1825 "-advertise-alpn", "\x03foo",
1826 },
1827 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001828 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001829 },
1830 {
1831 testType: serverTest,
1832 name: "FailEarlyCallback",
1833 flags: []string{"-fail-early-callback"},
1834 shouldFail: true,
1835 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001836 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001837 },
1838 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001839 name: "FailCertCallback-Client-TLS12",
1840 config: Config{
1841 MaxVersion: VersionTLS12,
1842 ClientAuth: RequestClientCert,
1843 },
1844 flags: []string{"-fail-cert-callback"},
1845 shouldFail: true,
1846 expectedError: ":CERT_CB_ERROR:",
1847 expectedLocalError: "remote error: internal error",
1848 },
1849 {
1850 testType: serverTest,
1851 name: "FailCertCallback-Server-TLS12",
1852 config: Config{
1853 MaxVersion: VersionTLS12,
1854 },
1855 flags: []string{"-fail-cert-callback"},
1856 shouldFail: true,
1857 expectedError: ":CERT_CB_ERROR:",
1858 expectedLocalError: "remote error: internal error",
1859 },
1860 {
1861 name: "FailCertCallback-Client-TLS13",
1862 config: Config{
1863 MaxVersion: VersionTLS13,
1864 ClientAuth: RequestClientCert,
1865 },
1866 flags: []string{"-fail-cert-callback"},
1867 shouldFail: true,
1868 expectedError: ":CERT_CB_ERROR:",
1869 expectedLocalError: "remote error: internal error",
1870 },
1871 {
1872 testType: serverTest,
1873 name: "FailCertCallback-Server-TLS13",
1874 config: Config{
1875 MaxVersion: VersionTLS13,
1876 },
1877 flags: []string{"-fail-cert-callback"},
1878 shouldFail: true,
1879 expectedError: ":CERT_CB_ERROR:",
1880 expectedLocalError: "remote error: internal error",
1881 },
1882 {
Adam Langley7c803a62015-06-15 15:35:05 -07001883 protocol: dtls,
1884 name: "FragmentMessageTypeMismatch-DTLS",
1885 config: Config{
1886 Bugs: ProtocolBugs{
1887 MaxHandshakeRecordLength: 2,
1888 FragmentMessageTypeMismatch: true,
1889 },
1890 },
1891 shouldFail: true,
1892 expectedError: ":FRAGMENT_MISMATCH:",
1893 },
1894 {
1895 protocol: dtls,
1896 name: "FragmentMessageLengthMismatch-DTLS",
1897 config: Config{
1898 Bugs: ProtocolBugs{
1899 MaxHandshakeRecordLength: 2,
1900 FragmentMessageLengthMismatch: true,
1901 },
1902 },
1903 shouldFail: true,
1904 expectedError: ":FRAGMENT_MISMATCH:",
1905 },
1906 {
1907 protocol: dtls,
1908 name: "SplitFragments-Header-DTLS",
1909 config: Config{
1910 Bugs: ProtocolBugs{
1911 SplitFragments: 2,
1912 },
1913 },
1914 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001915 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001916 },
1917 {
1918 protocol: dtls,
1919 name: "SplitFragments-Boundary-DTLS",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 SplitFragments: dtlsRecordHeaderLen,
1923 },
1924 },
1925 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001926 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001927 },
1928 {
1929 protocol: dtls,
1930 name: "SplitFragments-Body-DTLS",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SplitFragments: dtlsRecordHeaderLen + 1,
1934 },
1935 },
1936 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001937 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001938 },
1939 {
1940 protocol: dtls,
1941 name: "SendEmptyFragments-DTLS",
1942 config: Config{
1943 Bugs: ProtocolBugs{
1944 SendEmptyFragments: true,
1945 },
1946 },
1947 },
1948 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001949 name: "BadFinished-Client",
1950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001951 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001952 Bugs: ProtocolBugs{
1953 BadFinished: true,
1954 },
1955 },
1956 shouldFail: true,
1957 expectedError: ":DIGEST_CHECK_FAILED:",
1958 },
1959 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001960 name: "BadFinished-Client-TLS13",
1961 config: Config{
1962 MaxVersion: VersionTLS13,
1963 Bugs: ProtocolBugs{
1964 BadFinished: true,
1965 },
1966 },
1967 shouldFail: true,
1968 expectedError: ":DIGEST_CHECK_FAILED:",
1969 },
1970 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001971 testType: serverTest,
1972 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001974 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001975 Bugs: ProtocolBugs{
1976 BadFinished: true,
1977 },
1978 },
1979 shouldFail: true,
1980 expectedError: ":DIGEST_CHECK_FAILED:",
1981 },
1982 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001983 testType: serverTest,
1984 name: "BadFinished-Server-TLS13",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 Bugs: ProtocolBugs{
1988 BadFinished: true,
1989 },
1990 },
1991 shouldFail: true,
1992 expectedError: ":DIGEST_CHECK_FAILED:",
1993 },
1994 {
Adam Langley7c803a62015-06-15 15:35:05 -07001995 name: "FalseStart-BadFinished",
1996 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001997 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1999 NextProtos: []string{"foo"},
2000 Bugs: ProtocolBugs{
2001 BadFinished: true,
2002 ExpectFalseStart: true,
2003 },
2004 },
2005 flags: []string{
2006 "-false-start",
2007 "-handshake-never-done",
2008 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002009 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002010 },
2011 shimWritesFirst: true,
2012 shouldFail: true,
2013 expectedError: ":DIGEST_CHECK_FAILED:",
2014 },
2015 {
2016 name: "NoFalseStart-NoALPN",
2017 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002018 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002019 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2020 Bugs: ProtocolBugs{
2021 ExpectFalseStart: true,
2022 AlertBeforeFalseStartTest: alertAccessDenied,
2023 },
2024 },
2025 flags: []string{
2026 "-false-start",
2027 },
2028 shimWritesFirst: true,
2029 shouldFail: true,
2030 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2031 expectedLocalError: "tls: peer did not false start: EOF",
2032 },
2033 {
2034 name: "NoFalseStart-NoAEAD",
2035 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002036 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2038 NextProtos: []string{"foo"},
2039 Bugs: ProtocolBugs{
2040 ExpectFalseStart: true,
2041 AlertBeforeFalseStartTest: alertAccessDenied,
2042 },
2043 },
2044 flags: []string{
2045 "-false-start",
2046 "-advertise-alpn", "\x03foo",
2047 },
2048 shimWritesFirst: true,
2049 shouldFail: true,
2050 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2051 expectedLocalError: "tls: peer did not false start: EOF",
2052 },
2053 {
2054 name: "NoFalseStart-RSA",
2055 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002056 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002057 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2058 NextProtos: []string{"foo"},
2059 Bugs: ProtocolBugs{
2060 ExpectFalseStart: true,
2061 AlertBeforeFalseStartTest: alertAccessDenied,
2062 },
2063 },
2064 flags: []string{
2065 "-false-start",
2066 "-advertise-alpn", "\x03foo",
2067 },
2068 shimWritesFirst: true,
2069 shouldFail: true,
2070 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2071 expectedLocalError: "tls: peer did not false start: EOF",
2072 },
2073 {
Adam Langley7c803a62015-06-15 15:35:05 -07002074 protocol: dtls,
2075 name: "SendSplitAlert-Sync",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 SendSplitAlert: true,
2079 },
2080 },
2081 },
2082 {
2083 protocol: dtls,
2084 name: "SendSplitAlert-Async",
2085 config: Config{
2086 Bugs: ProtocolBugs{
2087 SendSplitAlert: true,
2088 },
2089 },
2090 flags: []string{"-async"},
2091 },
2092 {
2093 protocol: dtls,
2094 name: "PackDTLSHandshake",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 MaxHandshakeRecordLength: 2,
2098 PackHandshakeFragments: 20,
2099 PackHandshakeRecords: 200,
2100 },
2101 },
2102 },
2103 {
Adam Langley7c803a62015-06-15 15:35:05 -07002104 name: "SendEmptyRecords-Pass",
2105 sendEmptyRecords: 32,
2106 },
2107 {
2108 name: "SendEmptyRecords",
2109 sendEmptyRecords: 33,
2110 shouldFail: true,
2111 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2112 },
2113 {
2114 name: "SendEmptyRecords-Async",
2115 sendEmptyRecords: 33,
2116 flags: []string{"-async"},
2117 shouldFail: true,
2118 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2119 },
2120 {
David Benjamine8e84b92016-08-03 15:39:47 -04002121 name: "SendWarningAlerts-Pass",
2122 config: Config{
2123 MaxVersion: VersionTLS12,
2124 },
Adam Langley7c803a62015-06-15 15:35:05 -07002125 sendWarningAlerts: 4,
2126 },
2127 {
David Benjamine8e84b92016-08-03 15:39:47 -04002128 protocol: dtls,
2129 name: "SendWarningAlerts-DTLS-Pass",
2130 config: Config{
2131 MaxVersion: VersionTLS12,
2132 },
Adam Langley7c803a62015-06-15 15:35:05 -07002133 sendWarningAlerts: 4,
2134 },
2135 {
David Benjamine8e84b92016-08-03 15:39:47 -04002136 name: "SendWarningAlerts-TLS13",
2137 config: Config{
2138 MaxVersion: VersionTLS13,
2139 },
2140 sendWarningAlerts: 4,
2141 shouldFail: true,
2142 expectedError: ":BAD_ALERT:",
2143 expectedLocalError: "remote error: error decoding message",
2144 },
2145 {
2146 name: "SendWarningAlerts",
2147 config: Config{
2148 MaxVersion: VersionTLS12,
2149 },
Adam Langley7c803a62015-06-15 15:35:05 -07002150 sendWarningAlerts: 5,
2151 shouldFail: true,
2152 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2153 },
2154 {
David Benjamine8e84b92016-08-03 15:39:47 -04002155 name: "SendWarningAlerts-Async",
2156 config: Config{
2157 MaxVersion: VersionTLS12,
2158 },
Adam Langley7c803a62015-06-15 15:35:05 -07002159 sendWarningAlerts: 5,
2160 flags: []string{"-async"},
2161 shouldFail: true,
2162 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2163 },
David Benjaminba4594a2015-06-18 18:36:15 -04002164 {
David Benjamin24e58862017-06-14 18:45:29 -04002165 name: "SendBogusAlertType",
2166 sendBogusAlertType: true,
2167 shouldFail: true,
2168 expectedError: ":UNKNOWN_ALERT_TYPE:",
2169 expectedLocalError: "remote error: illegal parameter",
2170 },
2171 {
2172 protocol: dtls,
2173 name: "SendBogusAlertType-DTLS",
2174 sendBogusAlertType: true,
2175 shouldFail: true,
2176 expectedError: ":UNKNOWN_ALERT_TYPE:",
2177 expectedLocalError: "remote error: illegal parameter",
2178 },
2179 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002180 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002181 config: Config{
2182 MaxVersion: VersionTLS13,
2183 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002184 sendKeyUpdates: 33,
2185 keyUpdateRequest: keyUpdateNotRequested,
2186 shouldFail: true,
2187 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002188 },
2189 {
David Benjaminba4594a2015-06-18 18:36:15 -04002190 name: "EmptySessionID",
2191 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002192 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002193 SessionTicketsDisabled: true,
2194 },
2195 noSessionCache: true,
2196 flags: []string{"-expect-no-session"},
2197 },
David Benjamin30789da2015-08-29 22:56:45 -04002198 {
2199 name: "Unclean-Shutdown",
2200 config: Config{
2201 Bugs: ProtocolBugs{
2202 NoCloseNotify: true,
2203 ExpectCloseNotify: true,
2204 },
2205 },
2206 shimShutsDown: true,
2207 flags: []string{"-check-close-notify"},
2208 shouldFail: true,
2209 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2210 },
2211 {
2212 name: "Unclean-Shutdown-Ignored",
2213 config: Config{
2214 Bugs: ProtocolBugs{
2215 NoCloseNotify: true,
2216 },
2217 },
2218 shimShutsDown: true,
2219 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002220 {
David Benjaminfa214e42016-05-10 17:03:10 -04002221 name: "Unclean-Shutdown-Alert",
2222 config: Config{
2223 Bugs: ProtocolBugs{
2224 SendAlertOnShutdown: alertDecompressionFailure,
2225 ExpectCloseNotify: true,
2226 },
2227 },
2228 shimShutsDown: true,
2229 flags: []string{"-check-close-notify"},
2230 shouldFail: true,
2231 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2232 },
2233 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002234 name: "LargePlaintext",
2235 config: Config{
2236 Bugs: ProtocolBugs{
2237 SendLargeRecords: true,
2238 },
2239 },
2240 messageLen: maxPlaintext + 1,
2241 shouldFail: true,
2242 expectedError: ":DATA_LENGTH_TOO_LONG:",
2243 },
2244 {
2245 protocol: dtls,
2246 name: "LargePlaintext-DTLS",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendLargeRecords: true,
2250 },
2251 },
2252 messageLen: maxPlaintext + 1,
2253 shouldFail: true,
2254 expectedError: ":DATA_LENGTH_TOO_LONG:",
2255 },
2256 {
2257 name: "LargeCiphertext",
2258 config: Config{
2259 Bugs: ProtocolBugs{
2260 SendLargeRecords: true,
2261 },
2262 },
2263 messageLen: maxPlaintext * 2,
2264 shouldFail: true,
2265 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2266 },
2267 {
2268 protocol: dtls,
2269 name: "LargeCiphertext-DTLS",
2270 config: Config{
2271 Bugs: ProtocolBugs{
2272 SendLargeRecords: true,
2273 },
2274 },
2275 messageLen: maxPlaintext * 2,
2276 // Unlike the other four cases, DTLS drops records which
2277 // are invalid before authentication, so the connection
2278 // does not fail.
2279 expectMessageDropped: true,
2280 },
David Benjamindd6fed92015-10-23 17:41:12 -04002281 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002282 name: "BadHelloRequest-1",
2283 renegotiate: 1,
2284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002285 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002286 Bugs: ProtocolBugs{
2287 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2288 },
2289 },
2290 flags: []string{
2291 "-renegotiate-freely",
2292 "-expect-total-renegotiations", "1",
2293 },
2294 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002295 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002296 },
2297 {
2298 name: "BadHelloRequest-2",
2299 renegotiate: 1,
2300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002301 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002302 Bugs: ProtocolBugs{
2303 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2304 },
2305 },
2306 flags: []string{
2307 "-renegotiate-freely",
2308 "-expect-total-renegotiations", "1",
2309 },
2310 shouldFail: true,
2311 expectedError: ":BAD_HELLO_REQUEST:",
2312 },
David Benjaminef1b0092015-11-21 14:05:44 -05002313 {
2314 testType: serverTest,
2315 name: "SupportTicketsWithSessionID",
2316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002317 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002318 SessionTicketsDisabled: true,
2319 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002320 resumeConfig: &Config{
2321 MaxVersion: VersionTLS12,
2322 },
David Benjaminef1b0092015-11-21 14:05:44 -05002323 resumeSession: true,
2324 },
David Benjamin02edcd02016-07-27 17:40:37 -04002325 {
2326 protocol: dtls,
2327 name: "DTLS-SendExtraFinished",
2328 config: Config{
2329 Bugs: ProtocolBugs{
2330 SendExtraFinished: true,
2331 },
2332 },
2333 shouldFail: true,
2334 expectedError: ":UNEXPECTED_RECORD:",
2335 },
2336 {
2337 protocol: dtls,
2338 name: "DTLS-SendExtraFinished-Reordered",
2339 config: Config{
2340 Bugs: ProtocolBugs{
2341 MaxHandshakeRecordLength: 2,
2342 ReorderHandshakeFragments: true,
2343 SendExtraFinished: true,
2344 },
2345 },
2346 shouldFail: true,
2347 expectedError: ":UNEXPECTED_RECORD:",
2348 },
David Benjamine97fb482016-07-29 09:23:07 -04002349 {
2350 testType: serverTest,
2351 name: "V2ClientHello-EmptyRecordPrefix",
2352 config: Config{
2353 // Choose a cipher suite that does not involve
2354 // elliptic curves, so no extensions are
2355 // involved.
2356 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002357 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002358 Bugs: ProtocolBugs{
2359 SendV2ClientHello: true,
2360 },
2361 },
2362 sendPrefix: string([]byte{
2363 byte(recordTypeHandshake),
2364 3, 1, // version
2365 0, 0, // length
2366 }),
2367 // A no-op empty record may not be sent before V2ClientHello.
2368 shouldFail: true,
2369 expectedError: ":WRONG_VERSION_NUMBER:",
2370 },
2371 {
2372 testType: serverTest,
2373 name: "V2ClientHello-WarningAlertPrefix",
2374 config: Config{
2375 // Choose a cipher suite that does not involve
2376 // elliptic curves, so no extensions are
2377 // involved.
2378 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002379 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002380 Bugs: ProtocolBugs{
2381 SendV2ClientHello: true,
2382 },
2383 },
2384 sendPrefix: string([]byte{
2385 byte(recordTypeAlert),
2386 3, 1, // version
2387 0, 2, // length
2388 alertLevelWarning, byte(alertDecompressionFailure),
2389 }),
2390 // A no-op warning alert may not be sent before V2ClientHello.
2391 shouldFail: true,
2392 expectedError: ":WRONG_VERSION_NUMBER:",
2393 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002394 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002395 name: "KeyUpdate-Client",
2396 config: Config{
2397 MaxVersion: VersionTLS13,
2398 },
2399 sendKeyUpdates: 1,
2400 keyUpdateRequest: keyUpdateNotRequested,
2401 },
2402 {
2403 testType: serverTest,
2404 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002405 config: Config{
2406 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002407 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002408 sendKeyUpdates: 1,
2409 keyUpdateRequest: keyUpdateNotRequested,
2410 },
2411 {
2412 name: "KeyUpdate-InvalidRequestMode",
2413 config: Config{
2414 MaxVersion: VersionTLS13,
2415 },
2416 sendKeyUpdates: 1,
2417 keyUpdateRequest: 42,
2418 shouldFail: true,
2419 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002420 },
David Benjaminabe94e32016-09-04 14:18:58 -04002421 {
David Benjaminbbba9392017-04-06 12:54:12 -04002422 // Test that KeyUpdates are acknowledged properly.
2423 name: "KeyUpdate-RequestACK",
2424 config: Config{
2425 MaxVersion: VersionTLS13,
2426 Bugs: ProtocolBugs{
2427 RejectUnsolicitedKeyUpdate: true,
2428 },
2429 },
2430 // Test the shim receiving many KeyUpdates in a row.
2431 sendKeyUpdates: 5,
2432 messageCount: 5,
2433 keyUpdateRequest: keyUpdateRequested,
2434 },
2435 {
2436 // Test that KeyUpdates are acknowledged properly if the
2437 // peer's KeyUpdate is discovered while a write is
2438 // pending.
2439 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2440 config: Config{
2441 MaxVersion: VersionTLS13,
2442 Bugs: ProtocolBugs{
2443 RejectUnsolicitedKeyUpdate: true,
2444 },
2445 },
2446 // Test the shim receiving many KeyUpdates in a row.
2447 sendKeyUpdates: 5,
2448 messageCount: 5,
2449 keyUpdateRequest: keyUpdateRequested,
2450 readWithUnfinishedWrite: true,
2451 flags: []string{"-async"},
2452 },
2453 {
David Benjaminabe94e32016-09-04 14:18:58 -04002454 name: "SendSNIWarningAlert",
2455 config: Config{
2456 MaxVersion: VersionTLS12,
2457 Bugs: ProtocolBugs{
2458 SendSNIWarningAlert: true,
2459 },
2460 },
2461 },
David Benjaminc241d792016-09-09 10:34:20 -04002462 {
2463 testType: serverTest,
2464 name: "ExtraCompressionMethods-TLS12",
2465 config: Config{
2466 MaxVersion: VersionTLS12,
2467 Bugs: ProtocolBugs{
2468 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2469 },
2470 },
2471 },
2472 {
2473 testType: serverTest,
2474 name: "ExtraCompressionMethods-TLS13",
2475 config: Config{
2476 MaxVersion: VersionTLS13,
2477 Bugs: ProtocolBugs{
2478 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2479 },
2480 },
2481 shouldFail: true,
2482 expectedError: ":INVALID_COMPRESSION_LIST:",
2483 expectedLocalError: "remote error: illegal parameter",
2484 },
2485 {
2486 testType: serverTest,
2487 name: "NoNullCompression-TLS12",
2488 config: Config{
2489 MaxVersion: VersionTLS12,
2490 Bugs: ProtocolBugs{
2491 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2492 },
2493 },
2494 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002495 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002496 expectedLocalError: "remote error: illegal parameter",
2497 },
2498 {
2499 testType: serverTest,
2500 name: "NoNullCompression-TLS13",
2501 config: Config{
2502 MaxVersion: VersionTLS13,
2503 Bugs: ProtocolBugs{
2504 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2505 },
2506 },
2507 shouldFail: true,
2508 expectedError: ":INVALID_COMPRESSION_LIST:",
2509 expectedLocalError: "remote error: illegal parameter",
2510 },
David Benjamin413e79e2017-07-01 10:11:53 -04002511 // Test that the client rejects invalid compression methods
2512 // from the server.
2513 {
2514 testType: clientTest,
2515 name: "InvalidCompressionMethod",
2516 config: Config{
2517 MaxVersion: VersionTLS12,
2518 Bugs: ProtocolBugs{
2519 SendCompressionMethod: 1,
2520 },
2521 },
2522 shouldFail: true,
2523 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2524 expectedLocalError: "remote error: illegal parameter",
2525 },
David Benjamin65ac9972016-09-02 21:35:25 -04002526 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002527 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002528 config: Config{
2529 MaxVersion: VersionTLS12,
2530 Bugs: ProtocolBugs{
2531 ExpectGREASE: true,
2532 },
2533 },
2534 flags: []string{"-enable-grease"},
2535 },
2536 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002537 name: "GREASE-Client-TLS13",
2538 config: Config{
2539 MaxVersion: VersionTLS13,
2540 Bugs: ProtocolBugs{
2541 ExpectGREASE: true,
2542 },
2543 },
2544 flags: []string{"-enable-grease"},
2545 },
2546 {
2547 testType: serverTest,
2548 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002549 config: Config{
2550 MaxVersion: VersionTLS13,
2551 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002552 // TLS 1.3 servers are expected to
2553 // always enable GREASE. TLS 1.3 is new,
2554 // so there is no existing ecosystem to
2555 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002556 ExpectGREASE: true,
2557 },
2558 },
David Benjamin65ac9972016-09-02 21:35:25 -04002559 },
David Benjamine3fbb362017-01-06 16:19:28 -05002560 {
2561 // Test the server so there is a large certificate as
2562 // well as application data.
2563 testType: serverTest,
2564 name: "MaxSendFragment",
2565 config: Config{
2566 Bugs: ProtocolBugs{
2567 MaxReceivePlaintext: 512,
2568 },
2569 },
2570 messageLen: 1024,
2571 flags: []string{
2572 "-max-send-fragment", "512",
2573 "-read-size", "1024",
2574 },
2575 },
2576 {
2577 // Test the server so there is a large certificate as
2578 // well as application data.
2579 testType: serverTest,
2580 name: "MaxSendFragment-TooLarge",
2581 config: Config{
2582 Bugs: ProtocolBugs{
2583 // Ensure that some of the records are
2584 // 512.
2585 MaxReceivePlaintext: 511,
2586 },
2587 },
2588 messageLen: 1024,
2589 flags: []string{
2590 "-max-send-fragment", "512",
2591 "-read-size", "1024",
2592 },
2593 shouldFail: true,
2594 expectedLocalError: "local error: record overflow",
2595 },
Adam Langley7c803a62015-06-15 15:35:05 -07002596 }
Adam Langley7c803a62015-06-15 15:35:05 -07002597 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002598
2599 // Test that very large messages can be received.
2600 cert := rsaCertificate
2601 for i := 0; i < 50; i++ {
2602 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2603 }
2604 testCases = append(testCases, testCase{
2605 name: "LargeMessage",
2606 config: Config{
2607 Certificates: []Certificate{cert},
2608 },
2609 })
2610 testCases = append(testCases, testCase{
2611 protocol: dtls,
2612 name: "LargeMessage-DTLS",
2613 config: Config{
2614 Certificates: []Certificate{cert},
2615 },
2616 })
2617
2618 // They are rejected if the maximum certificate chain length is capped.
2619 testCases = append(testCases, testCase{
2620 name: "LargeMessage-Reject",
2621 config: Config{
2622 Certificates: []Certificate{cert},
2623 },
2624 flags: []string{"-max-cert-list", "16384"},
2625 shouldFail: true,
2626 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2627 })
2628 testCases = append(testCases, testCase{
2629 protocol: dtls,
2630 name: "LargeMessage-Reject-DTLS",
2631 config: Config{
2632 Certificates: []Certificate{cert},
2633 },
2634 flags: []string{"-max-cert-list", "16384"},
2635 shouldFail: true,
2636 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2637 })
Adam Langley7c803a62015-06-15 15:35:05 -07002638}
2639
David Benjaminaa012042016-12-10 13:33:05 -05002640func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2641 const psk = "12345"
2642 const pskIdentity = "luggage combo"
2643
2644 var prefix string
2645 if protocol == dtls {
2646 if !ver.hasDTLS {
2647 return
2648 }
2649 prefix = "D"
2650 }
2651
2652 var cert Certificate
2653 var certFile string
2654 var keyFile string
2655 if hasComponent(suite.name, "ECDSA") {
2656 cert = ecdsaP256Certificate
2657 certFile = ecdsaP256CertificateFile
2658 keyFile = ecdsaP256KeyFile
2659 } else {
2660 cert = rsaCertificate
2661 certFile = rsaCertificateFile
2662 keyFile = rsaKeyFile
2663 }
2664
2665 var flags []string
2666 if hasComponent(suite.name, "PSK") {
2667 flags = append(flags,
2668 "-psk", psk,
2669 "-psk-identity", pskIdentity)
2670 }
2671 if hasComponent(suite.name, "NULL") {
2672 // NULL ciphers must be explicitly enabled.
2673 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2674 }
David Benjaminaa012042016-12-10 13:33:05 -05002675
2676 var shouldServerFail, shouldClientFail bool
2677 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2678 // BoringSSL clients accept ECDHE on SSLv3, but
2679 // a BoringSSL server will never select it
2680 // because the extension is missing.
2681 shouldServerFail = true
2682 }
2683 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2684 shouldClientFail = true
2685 shouldServerFail = true
2686 }
2687 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2688 shouldClientFail = true
2689 shouldServerFail = true
2690 }
2691 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2692 shouldClientFail = true
2693 shouldServerFail = true
2694 }
2695 if !isDTLSCipher(suite.name) && protocol == dtls {
2696 shouldClientFail = true
2697 shouldServerFail = true
2698 }
2699
2700 var sendCipherSuite uint16
2701 var expectedServerError, expectedClientError string
2702 serverCipherSuites := []uint16{suite.id}
2703 if shouldServerFail {
2704 expectedServerError = ":NO_SHARED_CIPHER:"
2705 }
2706 if shouldClientFail {
2707 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2708 // Configure the server to select ciphers as normal but
2709 // select an incompatible cipher in ServerHello.
2710 serverCipherSuites = nil
2711 sendCipherSuite = suite.id
2712 }
2713
David Benjamincdb6fe92017-02-07 16:06:48 -05002714 // For cipher suites and versions where exporters are defined, verify
2715 // that they interoperate.
2716 var exportKeyingMaterial int
2717 if ver.version > VersionSSL30 {
2718 exportKeyingMaterial = 1024
2719 }
2720
David Benjaminaa012042016-12-10 13:33:05 -05002721 testCases = append(testCases, testCase{
2722 testType: serverTest,
2723 protocol: protocol,
2724 name: prefix + ver.name + "-" + suite.name + "-server",
2725 config: Config{
2726 MinVersion: ver.version,
2727 MaxVersion: ver.version,
2728 CipherSuites: []uint16{suite.id},
2729 Certificates: []Certificate{cert},
2730 PreSharedKey: []byte(psk),
2731 PreSharedKeyIdentity: pskIdentity,
2732 Bugs: ProtocolBugs{
2733 AdvertiseAllConfiguredCiphers: true,
2734 },
2735 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002736 certFile: certFile,
2737 keyFile: keyFile,
2738 flags: flags,
2739 resumeSession: true,
2740 shouldFail: shouldServerFail,
2741 expectedError: expectedServerError,
2742 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002743 })
2744
2745 testCases = append(testCases, testCase{
2746 testType: clientTest,
2747 protocol: protocol,
2748 name: prefix + ver.name + "-" + suite.name + "-client",
2749 config: Config{
2750 MinVersion: ver.version,
2751 MaxVersion: ver.version,
2752 CipherSuites: serverCipherSuites,
2753 Certificates: []Certificate{cert},
2754 PreSharedKey: []byte(psk),
2755 PreSharedKeyIdentity: pskIdentity,
2756 Bugs: ProtocolBugs{
2757 IgnorePeerCipherPreferences: shouldClientFail,
2758 SendCipherSuite: sendCipherSuite,
2759 },
2760 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002761 flags: flags,
2762 resumeSession: true,
2763 shouldFail: shouldClientFail,
2764 expectedError: expectedClientError,
2765 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002766 })
2767
David Benjamin6f600d62016-12-21 16:06:54 -05002768 if shouldClientFail {
2769 return
2770 }
2771
2772 // Ensure the maximum record size is accepted.
2773 testCases = append(testCases, testCase{
2774 protocol: protocol,
2775 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2776 config: Config{
2777 MinVersion: ver.version,
2778 MaxVersion: ver.version,
2779 CipherSuites: []uint16{suite.id},
2780 Certificates: []Certificate{cert},
2781 PreSharedKey: []byte(psk),
2782 PreSharedKeyIdentity: pskIdentity,
2783 },
2784 flags: flags,
2785 messageLen: maxPlaintext,
2786 })
2787
2788 // Test bad records for all ciphers. Bad records are fatal in TLS
2789 // and ignored in DTLS.
2790 var shouldFail bool
2791 var expectedError string
2792 if protocol == tls {
2793 shouldFail = true
2794 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2795 }
2796
2797 testCases = append(testCases, testCase{
2798 protocol: protocol,
2799 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2800 config: Config{
2801 MinVersion: ver.version,
2802 MaxVersion: ver.version,
2803 CipherSuites: []uint16{suite.id},
2804 Certificates: []Certificate{cert},
2805 PreSharedKey: []byte(psk),
2806 PreSharedKeyIdentity: pskIdentity,
2807 },
2808 flags: flags,
2809 damageFirstWrite: true,
2810 messageLen: maxPlaintext,
2811 shouldFail: shouldFail,
2812 expectedError: expectedError,
2813 })
David Benjaminaa012042016-12-10 13:33:05 -05002814}
2815
Adam Langley95c29f32014-06-20 12:00:00 -07002816func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002817 const bogusCipher = 0xfe00
2818
Adam Langley95c29f32014-06-20 12:00:00 -07002819 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002820 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002821 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002822 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002823 }
David Benjamin2c99d282015-09-01 10:23:00 -04002824 }
Adam Langley95c29f32014-06-20 12:00:00 -07002825 }
Adam Langleya7997f12015-05-14 17:38:50 -07002826
2827 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002828 name: "NoSharedCipher",
2829 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002830 MaxVersion: VersionTLS12,
2831 CipherSuites: []uint16{},
2832 },
2833 shouldFail: true,
2834 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2835 })
2836
2837 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002838 name: "NoSharedCipher-TLS13",
2839 config: Config{
2840 MaxVersion: VersionTLS13,
2841 CipherSuites: []uint16{},
2842 },
2843 shouldFail: true,
2844 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2845 })
2846
2847 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002848 name: "UnsupportedCipherSuite",
2849 config: Config{
2850 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002851 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002852 Bugs: ProtocolBugs{
2853 IgnorePeerCipherPreferences: true,
2854 },
2855 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002856 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002857 shouldFail: true,
2858 expectedError: ":WRONG_CIPHER_RETURNED:",
2859 })
2860
2861 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002862 name: "ServerHelloBogusCipher",
2863 config: Config{
2864 MaxVersion: VersionTLS12,
2865 Bugs: ProtocolBugs{
2866 SendCipherSuite: bogusCipher,
2867 },
2868 },
2869 shouldFail: true,
2870 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2871 })
2872 testCases = append(testCases, testCase{
2873 name: "ServerHelloBogusCipher-TLS13",
2874 config: Config{
2875 MaxVersion: VersionTLS13,
2876 Bugs: ProtocolBugs{
2877 SendCipherSuite: bogusCipher,
2878 },
2879 },
2880 shouldFail: true,
2881 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2882 })
2883
David Benjamin241ae832016-01-15 03:04:54 -05002884 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002885 testCases = append(testCases, testCase{
2886 testType: serverTest,
2887 name: "UnknownCipher",
2888 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002889 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002890 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002891 Bugs: ProtocolBugs{
2892 AdvertiseAllConfiguredCiphers: true,
2893 },
2894 },
2895 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002896
2897 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002898 testCases = append(testCases, testCase{
2899 testType: serverTest,
2900 name: "UnknownCipher-TLS13",
2901 config: Config{
2902 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002903 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002904 Bugs: ProtocolBugs{
2905 AdvertiseAllConfiguredCiphers: true,
2906 },
David Benjamin241ae832016-01-15 03:04:54 -05002907 },
2908 })
2909
David Benjamin78679342016-09-16 19:42:05 -04002910 // Test empty ECDHE_PSK identity hints work as expected.
2911 testCases = append(testCases, testCase{
2912 name: "EmptyECDHEPSKHint",
2913 config: Config{
2914 MaxVersion: VersionTLS12,
2915 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2916 PreSharedKey: []byte("secret"),
2917 },
2918 flags: []string{"-psk", "secret"},
2919 })
2920
2921 // Test empty PSK identity hints work as expected, even if an explicit
2922 // ServerKeyExchange is sent.
2923 testCases = append(testCases, testCase{
2924 name: "ExplicitEmptyPSKHint",
2925 config: Config{
2926 MaxVersion: VersionTLS12,
2927 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2928 PreSharedKey: []byte("secret"),
2929 Bugs: ProtocolBugs{
2930 AlwaysSendPreSharedKeyIdentityHint: true,
2931 },
2932 },
2933 flags: []string{"-psk", "secret"},
2934 })
David Benjamin69522112017-03-28 15:38:29 -05002935
2936 // Test that clients enforce that the server-sent certificate and cipher
2937 // suite match in TLS 1.2.
2938 testCases = append(testCases, testCase{
2939 name: "CertificateCipherMismatch-RSA",
2940 config: Config{
2941 MaxVersion: VersionTLS12,
2942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2943 Certificates: []Certificate{rsaCertificate},
2944 Bugs: ProtocolBugs{
2945 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2946 },
2947 },
2948 shouldFail: true,
2949 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2950 })
2951 testCases = append(testCases, testCase{
2952 name: "CertificateCipherMismatch-ECDSA",
2953 config: Config{
2954 MaxVersion: VersionTLS12,
2955 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2956 Certificates: []Certificate{ecdsaP256Certificate},
2957 Bugs: ProtocolBugs{
2958 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2959 },
2960 },
2961 shouldFail: true,
2962 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2963 })
2964 testCases = append(testCases, testCase{
2965 name: "CertificateCipherMismatch-Ed25519",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2969 Certificates: []Certificate{ed25519Certificate},
2970 Bugs: ProtocolBugs{
2971 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2972 },
2973 },
2974 shouldFail: true,
2975 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2976 })
2977
2978 // Test that servers decline to select a cipher suite which is
2979 // inconsistent with their configured certificate.
2980 testCases = append(testCases, testCase{
2981 testType: serverTest,
2982 name: "ServerCipherFilter-RSA",
2983 config: Config{
2984 MaxVersion: VersionTLS12,
2985 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2986 },
2987 flags: []string{
2988 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2989 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2990 },
2991 shouldFail: true,
2992 expectedError: ":NO_SHARED_CIPHER:",
2993 })
2994 testCases = append(testCases, testCase{
2995 testType: serverTest,
2996 name: "ServerCipherFilter-ECDSA",
2997 config: Config{
2998 MaxVersion: VersionTLS12,
2999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3000 },
3001 flags: []string{
3002 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3003 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3004 },
3005 shouldFail: true,
3006 expectedError: ":NO_SHARED_CIPHER:",
3007 })
3008 testCases = append(testCases, testCase{
3009 testType: serverTest,
3010 name: "ServerCipherFilter-Ed25519",
3011 config: Config{
3012 MaxVersion: VersionTLS12,
3013 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3014 },
3015 flags: []string{
3016 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3017 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3018 },
3019 shouldFail: true,
3020 expectedError: ":NO_SHARED_CIPHER:",
3021 })
Adam Langley95c29f32014-06-20 12:00:00 -07003022}
3023
3024func addBadECDSASignatureTests() {
3025 for badR := BadValue(1); badR < NumBadValues; badR++ {
3026 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003027 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003028 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3029 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003030 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003031 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003032 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003033 Bugs: ProtocolBugs{
3034 BadECDSAR: badR,
3035 BadECDSAS: badS,
3036 },
3037 },
3038 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003039 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003040 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003041 testCases = append(testCases, testCase{
3042 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3043 config: Config{
3044 MaxVersion: VersionTLS13,
3045 Certificates: []Certificate{ecdsaP256Certificate},
3046 Bugs: ProtocolBugs{
3047 BadECDSAR: badR,
3048 BadECDSAS: badS,
3049 },
3050 },
3051 shouldFail: true,
3052 expectedError: ":BAD_SIGNATURE:",
3053 })
Adam Langley95c29f32014-06-20 12:00:00 -07003054 }
3055 }
3056}
3057
Adam Langley80842bd2014-06-20 12:00:00 -07003058func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003059 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003060 name: "MaxCBCPadding",
3061 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003062 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003063 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3064 Bugs: ProtocolBugs{
3065 MaxPadding: true,
3066 },
3067 },
3068 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3069 })
David Benjamin025b3d32014-07-01 19:53:04 -04003070 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003071 name: "BadCBCPadding",
3072 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003073 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003074 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3075 Bugs: ProtocolBugs{
3076 PaddingFirstByteBad: true,
3077 },
3078 },
3079 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003080 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003081 })
3082 // OpenSSL previously had an issue where the first byte of padding in
3083 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003084 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003085 name: "BadCBCPadding255",
3086 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003087 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003088 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3089 Bugs: ProtocolBugs{
3090 MaxPadding: true,
3091 PaddingFirstByteBadIf255: true,
3092 },
3093 },
3094 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3095 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003096 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003097 })
3098}
3099
Kenny Root7fdeaf12014-08-05 15:23:37 -07003100func addCBCSplittingTests() {
3101 testCases = append(testCases, testCase{
3102 name: "CBCRecordSplitting",
3103 config: Config{
3104 MaxVersion: VersionTLS10,
3105 MinVersion: VersionTLS10,
3106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3107 },
David Benjaminac8302a2015-09-01 17:18:15 -04003108 messageLen: -1, // read until EOF
3109 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003110 flags: []string{
3111 "-async",
3112 "-write-different-record-sizes",
3113 "-cbc-record-splitting",
3114 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003115 })
3116 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003117 name: "CBCRecordSplittingPartialWrite",
3118 config: Config{
3119 MaxVersion: VersionTLS10,
3120 MinVersion: VersionTLS10,
3121 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3122 },
3123 messageLen: -1, // read until EOF
3124 flags: []string{
3125 "-async",
3126 "-write-different-record-sizes",
3127 "-cbc-record-splitting",
3128 "-partial-write",
3129 },
3130 })
3131}
3132
David Benjamin636293b2014-07-08 17:59:18 -04003133func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003134 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003135 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003136 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3137 cert, err := x509.ParseCertificate(cert.Certificate[0])
3138 if err != nil {
3139 panic(err)
3140 }
3141 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003142 }
Adam Langley2ff79332017-02-28 13:45:39 -08003143 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003144
David Benjamin636293b2014-07-08 17:59:18 -04003145 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003146 testCases = append(testCases, testCase{
3147 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003148 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003149 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003150 MinVersion: ver.version,
3151 MaxVersion: ver.version,
3152 ClientAuth: RequireAnyClientCert,
3153 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003154 },
3155 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003156 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3157 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003158 },
3159 })
3160 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003161 testType: serverTest,
3162 name: ver.name + "-Server-ClientAuth-RSA",
3163 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003164 MinVersion: ver.version,
3165 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003166 Certificates: []Certificate{rsaCertificate},
3167 },
3168 flags: []string{"-require-any-client-certificate"},
3169 })
David Benjamine098ec22014-08-27 23:13:20 -04003170 if ver.version != VersionSSL30 {
3171 testCases = append(testCases, testCase{
3172 testType: serverTest,
3173 name: ver.name + "-Server-ClientAuth-ECDSA",
3174 config: Config{
3175 MinVersion: ver.version,
3176 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003177 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003178 },
3179 flags: []string{"-require-any-client-certificate"},
3180 })
3181 testCases = append(testCases, testCase{
3182 testType: clientTest,
3183 name: ver.name + "-Client-ClientAuth-ECDSA",
3184 config: Config{
3185 MinVersion: ver.version,
3186 MaxVersion: ver.version,
3187 ClientAuth: RequireAnyClientCert,
3188 ClientCAs: certPool,
3189 },
3190 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003191 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3192 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003193 },
3194 })
3195 }
Adam Langley37646832016-08-01 16:16:46 -07003196
3197 testCases = append(testCases, testCase{
3198 name: "NoClientCertificate-" + ver.name,
3199 config: Config{
3200 MinVersion: ver.version,
3201 MaxVersion: ver.version,
3202 ClientAuth: RequireAnyClientCert,
3203 },
3204 shouldFail: true,
3205 expectedLocalError: "client didn't provide a certificate",
3206 })
3207
3208 testCases = append(testCases, testCase{
3209 // Even if not configured to expect a certificate, OpenSSL will
3210 // return X509_V_OK as the verify_result.
3211 testType: serverTest,
3212 name: "NoClientCertificateRequested-Server-" + ver.name,
3213 config: Config{
3214 MinVersion: ver.version,
3215 MaxVersion: ver.version,
3216 },
3217 flags: []string{
3218 "-expect-verify-result",
3219 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003220 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003221 })
3222
3223 testCases = append(testCases, testCase{
3224 // If a client certificate is not provided, OpenSSL will still
3225 // return X509_V_OK as the verify_result.
3226 testType: serverTest,
3227 name: "NoClientCertificate-Server-" + ver.name,
3228 config: Config{
3229 MinVersion: ver.version,
3230 MaxVersion: ver.version,
3231 },
3232 flags: []string{
3233 "-expect-verify-result",
3234 "-verify-peer",
3235 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003236 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003237 })
3238
David Benjamin1db9e1b2016-10-07 20:51:43 -04003239 certificateRequired := "remote error: certificate required"
3240 if ver.version < VersionTLS13 {
3241 // Prior to TLS 1.3, the generic handshake_failure alert
3242 // was used.
3243 certificateRequired = "remote error: handshake failure"
3244 }
Adam Langley37646832016-08-01 16:16:46 -07003245 testCases = append(testCases, testCase{
3246 testType: serverTest,
3247 name: "RequireAnyClientCertificate-" + ver.name,
3248 config: Config{
3249 MinVersion: ver.version,
3250 MaxVersion: ver.version,
3251 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003252 flags: []string{"-require-any-client-certificate"},
3253 shouldFail: true,
3254 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3255 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003256 })
3257
3258 if ver.version != VersionSSL30 {
3259 testCases = append(testCases, testCase{
3260 testType: serverTest,
3261 name: "SkipClientCertificate-" + ver.name,
3262 config: Config{
3263 MinVersion: ver.version,
3264 MaxVersion: ver.version,
3265 Bugs: ProtocolBugs{
3266 SkipClientCertificate: true,
3267 },
3268 },
3269 // Setting SSL_VERIFY_PEER allows anonymous clients.
3270 flags: []string{"-verify-peer"},
3271 shouldFail: true,
3272 expectedError: ":UNEXPECTED_MESSAGE:",
3273 })
3274 }
Adam Langley2ff79332017-02-28 13:45:39 -08003275
3276 testCases = append(testCases, testCase{
3277 testType: serverTest,
3278 name: ver.name + "-Server-CertReq-CA-List",
3279 config: Config{
3280 MinVersion: ver.version,
3281 MaxVersion: ver.version,
3282 Certificates: []Certificate{rsaCertificate},
3283 Bugs: ProtocolBugs{
3284 ExpectCertificateReqNames: caNames,
3285 },
3286 },
3287 flags: []string{
3288 "-require-any-client-certificate",
3289 "-use-client-ca-list", encodeDERValues(caNames),
3290 },
3291 })
3292
3293 testCases = append(testCases, testCase{
3294 testType: clientTest,
3295 name: ver.name + "-Client-CertReq-CA-List",
3296 config: Config{
3297 MinVersion: ver.version,
3298 MaxVersion: ver.version,
3299 Certificates: []Certificate{rsaCertificate},
3300 ClientAuth: RequireAnyClientCert,
3301 ClientCAs: certPool,
3302 },
3303 flags: []string{
3304 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3305 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3306 "-expect-client-ca-list", encodeDERValues(caNames),
3307 },
3308 })
David Benjamin636293b2014-07-08 17:59:18 -04003309 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003310
David Benjaminc032dfa2016-05-12 14:54:57 -04003311 // Client auth is only legal in certificate-based ciphers.
3312 testCases = append(testCases, testCase{
3313 testType: clientTest,
3314 name: "ClientAuth-PSK",
3315 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003316 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003317 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3318 PreSharedKey: []byte("secret"),
3319 ClientAuth: RequireAnyClientCert,
3320 },
3321 flags: []string{
3322 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3323 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3324 "-psk", "secret",
3325 },
3326 shouldFail: true,
3327 expectedError: ":UNEXPECTED_MESSAGE:",
3328 })
3329 testCases = append(testCases, testCase{
3330 testType: clientTest,
3331 name: "ClientAuth-ECDHE_PSK",
3332 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003333 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003334 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3335 PreSharedKey: []byte("secret"),
3336 ClientAuth: RequireAnyClientCert,
3337 },
3338 flags: []string{
3339 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3340 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3341 "-psk", "secret",
3342 },
3343 shouldFail: true,
3344 expectedError: ":UNEXPECTED_MESSAGE:",
3345 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003346
3347 // Regression test for a bug where the client CA list, if explicitly
3348 // set to NULL, was mis-encoded.
3349 testCases = append(testCases, testCase{
3350 testType: serverTest,
3351 name: "Null-Client-CA-List",
3352 config: Config{
3353 MaxVersion: VersionTLS12,
3354 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003355 Bugs: ProtocolBugs{
3356 ExpectCertificateReqNames: [][]byte{},
3357 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003358 },
3359 flags: []string{
3360 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003361 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003362 },
3363 })
David Benjamin636293b2014-07-08 17:59:18 -04003364}
3365
Adam Langley75712922014-10-10 16:23:43 -07003366func addExtendedMasterSecretTests() {
3367 const expectEMSFlag = "-expect-extended-master-secret"
3368
3369 for _, with := range []bool{false, true} {
3370 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003371 if with {
3372 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003373 }
3374
3375 for _, isClient := range []bool{false, true} {
3376 suffix := "-Server"
3377 testType := serverTest
3378 if isClient {
3379 suffix = "-Client"
3380 testType = clientTest
3381 }
3382
3383 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003384 // In TLS 1.3, the extension is irrelevant and
3385 // always reports as enabled.
3386 var flags []string
3387 if with || ver.version >= VersionTLS13 {
3388 flags = []string{expectEMSFlag}
3389 }
3390
Adam Langley75712922014-10-10 16:23:43 -07003391 test := testCase{
3392 testType: testType,
3393 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3394 config: Config{
3395 MinVersion: ver.version,
3396 MaxVersion: ver.version,
3397 Bugs: ProtocolBugs{
3398 NoExtendedMasterSecret: !with,
3399 RequireExtendedMasterSecret: with,
3400 },
3401 },
David Benjamin48cae082014-10-27 01:06:24 -04003402 flags: flags,
3403 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003404 }
3405 if test.shouldFail {
3406 test.expectedLocalError = "extended master secret required but not supported by peer"
3407 }
3408 testCases = append(testCases, test)
3409 }
3410 }
3411 }
3412
Adam Langleyba5934b2015-06-02 10:50:35 -07003413 for _, isClient := range []bool{false, true} {
3414 for _, supportedInFirstConnection := range []bool{false, true} {
3415 for _, supportedInResumeConnection := range []bool{false, true} {
3416 boolToWord := func(b bool) string {
3417 if b {
3418 return "Yes"
3419 }
3420 return "No"
3421 }
3422 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3423 if isClient {
3424 suffix += "Client"
3425 } else {
3426 suffix += "Server"
3427 }
3428
3429 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003430 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003431 Bugs: ProtocolBugs{
3432 RequireExtendedMasterSecret: true,
3433 },
3434 }
3435
3436 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003437 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003438 Bugs: ProtocolBugs{
3439 NoExtendedMasterSecret: true,
3440 },
3441 }
3442
3443 test := testCase{
3444 name: "ExtendedMasterSecret-" + suffix,
3445 resumeSession: true,
3446 }
3447
3448 if !isClient {
3449 test.testType = serverTest
3450 }
3451
3452 if supportedInFirstConnection {
3453 test.config = supportedConfig
3454 } else {
3455 test.config = noSupportConfig
3456 }
3457
3458 if supportedInResumeConnection {
3459 test.resumeConfig = &supportedConfig
3460 } else {
3461 test.resumeConfig = &noSupportConfig
3462 }
3463
3464 switch suffix {
3465 case "YesToYes-Client", "YesToYes-Server":
3466 // When a session is resumed, it should
3467 // still be aware that its master
3468 // secret was generated via EMS and
3469 // thus it's safe to use tls-unique.
3470 test.flags = []string{expectEMSFlag}
3471 case "NoToYes-Server":
3472 // If an original connection did not
3473 // contain EMS, but a resumption
3474 // handshake does, then a server should
3475 // not resume the session.
3476 test.expectResumeRejected = true
3477 case "YesToNo-Server":
3478 // Resuming an EMS session without the
3479 // EMS extension should cause the
3480 // server to abort the connection.
3481 test.shouldFail = true
3482 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3483 case "NoToYes-Client":
3484 // A client should abort a connection
3485 // where the server resumed a non-EMS
3486 // session but echoed the EMS
3487 // extension.
3488 test.shouldFail = true
3489 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3490 case "YesToNo-Client":
3491 // A client should abort a connection
3492 // where the server didn't echo EMS
3493 // when the session used it.
3494 test.shouldFail = true
3495 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3496 }
3497
3498 testCases = append(testCases, test)
3499 }
3500 }
3501 }
David Benjamin163c9562016-08-29 23:14:17 -04003502
3503 // Switching EMS on renegotiation is forbidden.
3504 testCases = append(testCases, testCase{
3505 name: "ExtendedMasterSecret-Renego-NoEMS",
3506 config: Config{
3507 MaxVersion: VersionTLS12,
3508 Bugs: ProtocolBugs{
3509 NoExtendedMasterSecret: true,
3510 NoExtendedMasterSecretOnRenegotiation: true,
3511 },
3512 },
3513 renegotiate: 1,
3514 flags: []string{
3515 "-renegotiate-freely",
3516 "-expect-total-renegotiations", "1",
3517 },
3518 })
3519
3520 testCases = append(testCases, testCase{
3521 name: "ExtendedMasterSecret-Renego-Upgrade",
3522 config: Config{
3523 MaxVersion: VersionTLS12,
3524 Bugs: ProtocolBugs{
3525 NoExtendedMasterSecret: true,
3526 },
3527 },
3528 renegotiate: 1,
3529 flags: []string{
3530 "-renegotiate-freely",
3531 "-expect-total-renegotiations", "1",
3532 },
3533 shouldFail: true,
3534 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3535 })
3536
3537 testCases = append(testCases, testCase{
3538 name: "ExtendedMasterSecret-Renego-Downgrade",
3539 config: Config{
3540 MaxVersion: VersionTLS12,
3541 Bugs: ProtocolBugs{
3542 NoExtendedMasterSecretOnRenegotiation: true,
3543 },
3544 },
3545 renegotiate: 1,
3546 flags: []string{
3547 "-renegotiate-freely",
3548 "-expect-total-renegotiations", "1",
3549 },
3550 shouldFail: true,
3551 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3552 })
Adam Langley75712922014-10-10 16:23:43 -07003553}
3554
David Benjamin582ba042016-07-07 12:33:25 -07003555type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003556 protocol protocol
3557 async bool
3558 splitHandshake bool
3559 packHandshakeFlight bool
3560 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003561}
3562
David Benjamin43ec06f2014-08-05 02:28:57 -04003563// Adds tests that try to cover the range of the handshake state machine, under
3564// various conditions. Some of these are redundant with other tests, but they
3565// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003566func addAllStateMachineCoverageTests() {
3567 for _, async := range []bool{false, true} {
3568 for _, protocol := range []protocol{tls, dtls} {
3569 addStateMachineCoverageTests(stateMachineTestConfig{
3570 protocol: protocol,
3571 async: async,
3572 })
3573 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003574 protocol: protocol,
3575 async: async,
3576 implicitHandshake: true,
3577 })
3578 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003579 protocol: protocol,
3580 async: async,
3581 splitHandshake: true,
3582 })
3583 if protocol == tls {
3584 addStateMachineCoverageTests(stateMachineTestConfig{
3585 protocol: protocol,
3586 async: async,
3587 packHandshakeFlight: true,
3588 })
3589 }
3590 }
3591 }
3592}
3593
3594func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003595 var tests []testCase
3596
3597 // Basic handshake, with resumption. Client and server,
3598 // session ID and session ticket.
3599 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003600 name: "Basic-Client",
3601 config: Config{
3602 MaxVersion: VersionTLS12,
3603 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003604 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003605 // Ensure session tickets are used, not session IDs.
3606 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003607 })
3608 tests = append(tests, testCase{
3609 name: "Basic-Client-RenewTicket",
3610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003611 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003612 Bugs: ProtocolBugs{
3613 RenewTicketOnResume: true,
3614 },
3615 },
David Benjamin46662482016-08-17 00:51:00 -04003616 flags: []string{"-expect-ticket-renewal"},
3617 resumeSession: true,
3618 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003619 })
3620 tests = append(tests, testCase{
3621 name: "Basic-Client-NoTicket",
3622 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003623 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003624 SessionTicketsDisabled: true,
3625 },
3626 resumeSession: true,
3627 })
3628 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003629 testType: serverTest,
3630 name: "Basic-Server",
3631 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003632 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003633 Bugs: ProtocolBugs{
3634 RequireSessionTickets: true,
3635 },
3636 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003637 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003638 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003639 })
3640 tests = append(tests, testCase{
3641 testType: serverTest,
3642 name: "Basic-Server-NoTickets",
3643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003644 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003645 SessionTicketsDisabled: true,
3646 },
3647 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003648 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003649 })
3650 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003651 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003652 name: "Basic-Server-EarlyCallback",
3653 config: Config{
3654 MaxVersion: VersionTLS12,
3655 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003656 flags: []string{"-use-early-callback"},
3657 resumeSession: true,
3658 })
3659
Steven Valdez143e8b32016-07-11 13:19:03 -04003660 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003661 if config.protocol == tls {
3662 tests = append(tests, testCase{
3663 name: "TLS13-1RTT-Client",
3664 config: Config{
3665 MaxVersion: VersionTLS13,
3666 MinVersion: VersionTLS13,
3667 },
David Benjamin46662482016-08-17 00:51:00 -04003668 resumeSession: true,
3669 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003670 })
3671
3672 tests = append(tests, testCase{
3673 testType: serverTest,
3674 name: "TLS13-1RTT-Server",
3675 config: Config{
3676 MaxVersion: VersionTLS13,
3677 MinVersion: VersionTLS13,
3678 },
David Benjamin46662482016-08-17 00:51:00 -04003679 resumeSession: true,
3680 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003681 // TLS 1.3 uses tickets, so the session should not be
3682 // cached statefully.
3683 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003684 })
3685
3686 tests = append(tests, testCase{
3687 name: "TLS13-HelloRetryRequest-Client",
3688 config: Config{
3689 MaxVersion: VersionTLS13,
3690 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003691 // P-384 requires a HelloRetryRequest against BoringSSL's default
3692 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003693 CurvePreferences: []CurveID{CurveP384},
3694 Bugs: ProtocolBugs{
3695 ExpectMissingKeyShare: true,
3696 },
3697 },
3698 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3699 resumeSession: true,
3700 })
3701
3702 tests = append(tests, testCase{
3703 testType: serverTest,
3704 name: "TLS13-HelloRetryRequest-Server",
3705 config: Config{
3706 MaxVersion: VersionTLS13,
3707 MinVersion: VersionTLS13,
3708 // Require a HelloRetryRequest for every curve.
3709 DefaultCurves: []CurveID{},
3710 },
3711 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3712 resumeSession: true,
3713 })
Steven Valdez2d850622017-01-11 11:34:52 -05003714
Steven Valdez2d850622017-01-11 11:34:52 -05003715 tests = append(tests, testCase{
3716 testType: clientTest,
3717 name: "TLS13-EarlyData-Client",
3718 config: Config{
3719 MaxVersion: VersionTLS13,
3720 MinVersion: VersionTLS13,
3721 MaxEarlyDataSize: 16384,
3722 },
Steven Valdeze831a812017-03-09 14:56:07 -05003723 resumeConfig: &Config{
3724 MaxVersion: VersionTLS13,
3725 MinVersion: VersionTLS13,
3726 MaxEarlyDataSize: 16384,
3727 Bugs: ProtocolBugs{
3728 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3729 },
3730 },
Steven Valdez2d850622017-01-11 11:34:52 -05003731 resumeSession: true,
3732 flags: []string{
3733 "-enable-early-data",
3734 "-expect-early-data-info",
3735 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003736 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003737 },
3738 })
3739
3740 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003741 testType: clientTest,
3742 name: "TLS13-EarlyData-TooMuchData-Client",
3743 config: Config{
3744 MaxVersion: VersionTLS13,
3745 MinVersion: VersionTLS13,
3746 MaxEarlyDataSize: 2,
3747 },
3748 resumeConfig: &Config{
3749 MaxVersion: VersionTLS13,
3750 MinVersion: VersionTLS13,
3751 MaxEarlyDataSize: 2,
3752 Bugs: ProtocolBugs{
3753 ExpectEarlyData: [][]byte{{'h', 'e'}},
3754 },
3755 },
3756 resumeShimPrefix: "llo",
3757 resumeSession: true,
3758 flags: []string{
3759 "-enable-early-data",
3760 "-expect-early-data-info",
3761 "-expect-accept-early-data",
3762 "-on-resume-shim-writes-first",
3763 },
3764 })
3765
3766 // Unfinished writes can only be tested when operations are async. EarlyData
3767 // can't be tested as part of an ImplicitHandshake in this case since
3768 // otherwise the early data will be sent as normal data.
3769 if config.async && !config.implicitHandshake {
3770 tests = append(tests, testCase{
3771 testType: clientTest,
3772 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3773 config: Config{
3774 MaxVersion: VersionTLS13,
3775 MinVersion: VersionTLS13,
3776 MaxEarlyDataSize: 16384,
3777 },
3778 resumeConfig: &Config{
3779 MaxVersion: VersionTLS13,
3780 MinVersion: VersionTLS13,
3781 MaxEarlyDataSize: 16384,
3782 Bugs: ProtocolBugs{
3783 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3784 },
3785 },
3786 resumeSession: true,
3787 flags: []string{
3788 "-enable-early-data",
3789 "-expect-early-data-info",
3790 "-expect-accept-early-data",
3791 "-on-resume-read-with-unfinished-write",
3792 "-on-resume-shim-writes-first",
3793 },
3794 })
3795
3796 // Rejected unfinished writes are discarded (from the
3797 // perspective of the calling application) on 0-RTT
3798 // reject.
3799 tests = append(tests, testCase{
3800 testType: clientTest,
3801 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3802 config: Config{
3803 MaxVersion: VersionTLS13,
3804 MinVersion: VersionTLS13,
3805 MaxEarlyDataSize: 16384,
3806 },
3807 resumeConfig: &Config{
3808 MaxVersion: VersionTLS13,
3809 MinVersion: VersionTLS13,
3810 MaxEarlyDataSize: 16384,
3811 Bugs: ProtocolBugs{
3812 AlwaysRejectEarlyData: true,
3813 },
3814 },
3815 resumeSession: true,
3816 flags: []string{
3817 "-enable-early-data",
3818 "-expect-early-data-info",
3819 "-expect-reject-early-data",
3820 "-on-resume-read-with-unfinished-write",
3821 "-on-resume-shim-writes-first",
3822 },
3823 })
3824 }
3825
3826 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003827 testType: serverTest,
3828 name: "TLS13-EarlyData-Server",
3829 config: Config{
3830 MaxVersion: VersionTLS13,
3831 MinVersion: VersionTLS13,
3832 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003833 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003834 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003835 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003836 },
3837 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003838 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003839 resumeSession: true,
3840 flags: []string{
3841 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003842 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003843 },
3844 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003845
3846 tests = append(tests, testCase{
3847 testType: serverTest,
3848 name: "TLS13-MaxEarlyData-Server",
3849 config: Config{
3850 MaxVersion: VersionTLS13,
3851 MinVersion: VersionTLS13,
3852 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003853 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003854 ExpectEarlyDataAccepted: true,
3855 },
3856 },
3857 messageCount: 2,
3858 resumeSession: true,
3859 flags: []string{
3860 "-enable-early-data",
3861 "-expect-accept-early-data",
3862 },
3863 shouldFail: true,
3864 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
3865 })
David Benjamine73c7f42016-08-17 00:29:33 -04003866 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003867
David Benjamin760b1dd2015-05-15 23:33:48 -04003868 // TLS client auth.
3869 tests = append(tests, testCase{
3870 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003871 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003873 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003874 ClientAuth: RequestClientCert,
3875 },
3876 })
3877 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003878 testType: serverTest,
3879 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003880 config: Config{
3881 MaxVersion: VersionTLS12,
3882 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003883 // Setting SSL_VERIFY_PEER allows anonymous clients.
3884 flags: []string{"-verify-peer"},
3885 })
David Benjamin582ba042016-07-07 12:33:25 -07003886 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003887 tests = append(tests, testCase{
3888 testType: clientTest,
3889 name: "ClientAuth-NoCertificate-Client-SSL3",
3890 config: Config{
3891 MaxVersion: VersionSSL30,
3892 ClientAuth: RequestClientCert,
3893 },
3894 })
3895 tests = append(tests, testCase{
3896 testType: serverTest,
3897 name: "ClientAuth-NoCertificate-Server-SSL3",
3898 config: Config{
3899 MaxVersion: VersionSSL30,
3900 },
3901 // Setting SSL_VERIFY_PEER allows anonymous clients.
3902 flags: []string{"-verify-peer"},
3903 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003904 tests = append(tests, testCase{
3905 testType: clientTest,
3906 name: "ClientAuth-NoCertificate-Client-TLS13",
3907 config: Config{
3908 MaxVersion: VersionTLS13,
3909 ClientAuth: RequestClientCert,
3910 },
3911 })
3912 tests = append(tests, testCase{
3913 testType: serverTest,
3914 name: "ClientAuth-NoCertificate-Server-TLS13",
3915 config: Config{
3916 MaxVersion: VersionTLS13,
3917 },
3918 // Setting SSL_VERIFY_PEER allows anonymous clients.
3919 flags: []string{"-verify-peer"},
3920 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003921 }
3922 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003923 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003924 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003926 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003927 ClientAuth: RequireAnyClientCert,
3928 },
3929 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003930 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3931 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003932 },
3933 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003934 tests = append(tests, testCase{
3935 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003936 name: "ClientAuth-RSA-Client-TLS13",
3937 config: Config{
3938 MaxVersion: VersionTLS13,
3939 ClientAuth: RequireAnyClientCert,
3940 },
3941 flags: []string{
3942 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3943 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3944 },
3945 })
3946 tests = append(tests, testCase{
3947 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003948 name: "ClientAuth-ECDSA-Client",
3949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003950 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003951 ClientAuth: RequireAnyClientCert,
3952 },
3953 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003954 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3955 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003956 },
3957 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003958 tests = append(tests, testCase{
3959 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003960 name: "ClientAuth-ECDSA-Client-TLS13",
3961 config: Config{
3962 MaxVersion: VersionTLS13,
3963 ClientAuth: RequireAnyClientCert,
3964 },
3965 flags: []string{
3966 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3967 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3968 },
3969 })
3970 tests = append(tests, testCase{
3971 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 name: "ClientAuth-NoCertificate-OldCallback",
3973 config: Config{
3974 MaxVersion: VersionTLS12,
3975 ClientAuth: RequestClientCert,
3976 },
3977 flags: []string{"-use-old-client-cert-callback"},
3978 })
3979 tests = append(tests, testCase{
3980 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003981 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3982 config: Config{
3983 MaxVersion: VersionTLS13,
3984 ClientAuth: RequestClientCert,
3985 },
3986 flags: []string{"-use-old-client-cert-callback"},
3987 })
3988 tests = append(tests, testCase{
3989 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003990 name: "ClientAuth-OldCallback",
3991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003992 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003993 ClientAuth: RequireAnyClientCert,
3994 },
3995 flags: []string{
3996 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3997 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3998 "-use-old-client-cert-callback",
3999 },
4000 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004001 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004002 testType: clientTest,
4003 name: "ClientAuth-OldCallback-TLS13",
4004 config: Config{
4005 MaxVersion: VersionTLS13,
4006 ClientAuth: RequireAnyClientCert,
4007 },
4008 flags: []string{
4009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4011 "-use-old-client-cert-callback",
4012 },
4013 })
4014 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004015 testType: serverTest,
4016 name: "ClientAuth-Server",
4017 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004018 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004019 Certificates: []Certificate{rsaCertificate},
4020 },
4021 flags: []string{"-require-any-client-certificate"},
4022 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004023 tests = append(tests, testCase{
4024 testType: serverTest,
4025 name: "ClientAuth-Server-TLS13",
4026 config: Config{
4027 MaxVersion: VersionTLS13,
4028 Certificates: []Certificate{rsaCertificate},
4029 },
4030 flags: []string{"-require-any-client-certificate"},
4031 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004032
David Benjamin4c3ddf72016-06-29 18:13:53 -04004033 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004034 tests = append(tests, testCase{
4035 testType: serverTest,
4036 name: "Basic-Server-RSA",
4037 config: Config{
4038 MaxVersion: VersionTLS12,
4039 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4040 },
4041 flags: []string{
4042 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4043 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4044 },
4045 })
4046 tests = append(tests, testCase{
4047 testType: serverTest,
4048 name: "Basic-Server-ECDHE-RSA",
4049 config: Config{
4050 MaxVersion: VersionTLS12,
4051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4052 },
4053 flags: []string{
4054 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4055 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4056 },
4057 })
4058 tests = append(tests, testCase{
4059 testType: serverTest,
4060 name: "Basic-Server-ECDHE-ECDSA",
4061 config: Config{
4062 MaxVersion: VersionTLS12,
4063 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4064 },
4065 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004066 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4067 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004068 },
4069 })
David Benjamin69522112017-03-28 15:38:29 -05004070 tests = append(tests, testCase{
4071 testType: serverTest,
4072 name: "Basic-Server-Ed25519",
4073 config: Config{
4074 MaxVersion: VersionTLS12,
4075 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4076 },
4077 flags: []string{
4078 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4079 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4080 "-enable-ed25519",
4081 },
4082 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004083
David Benjamin760b1dd2015-05-15 23:33:48 -04004084 // No session ticket support; server doesn't send NewSessionTicket.
4085 tests = append(tests, testCase{
4086 name: "SessionTicketsDisabled-Client",
4087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004088 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004089 SessionTicketsDisabled: true,
4090 },
4091 })
4092 tests = append(tests, testCase{
4093 testType: serverTest,
4094 name: "SessionTicketsDisabled-Server",
4095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004096 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004097 SessionTicketsDisabled: true,
4098 },
4099 })
4100
4101 // Skip ServerKeyExchange in PSK key exchange if there's no
4102 // identity hint.
4103 tests = append(tests, testCase{
4104 name: "EmptyPSKHint-Client",
4105 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004106 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004107 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4108 PreSharedKey: []byte("secret"),
4109 },
4110 flags: []string{"-psk", "secret"},
4111 })
4112 tests = append(tests, testCase{
4113 testType: serverTest,
4114 name: "EmptyPSKHint-Server",
4115 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004116 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004117 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4118 PreSharedKey: []byte("secret"),
4119 },
4120 flags: []string{"-psk", "secret"},
4121 })
4122
David Benjamin4c3ddf72016-06-29 18:13:53 -04004123 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004124 tests = append(tests, testCase{
4125 testType: clientTest,
4126 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004127 config: Config{
4128 MaxVersion: VersionTLS12,
4129 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004130 flags: []string{
4131 "-enable-ocsp-stapling",
4132 "-expect-ocsp-response",
4133 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004134 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004135 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004136 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004137 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004138 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004139 testType: serverTest,
4140 name: "OCSPStapling-Server",
4141 config: Config{
4142 MaxVersion: VersionTLS12,
4143 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004144 expectedOCSPResponse: testOCSPResponse,
4145 flags: []string{
4146 "-ocsp-response",
4147 base64.StdEncoding.EncodeToString(testOCSPResponse),
4148 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004149 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004150 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004151 tests = append(tests, testCase{
4152 testType: clientTest,
4153 name: "OCSPStapling-Client-TLS13",
4154 config: Config{
4155 MaxVersion: VersionTLS13,
4156 },
4157 flags: []string{
4158 "-enable-ocsp-stapling",
4159 "-expect-ocsp-response",
4160 base64.StdEncoding.EncodeToString(testOCSPResponse),
4161 "-verify-peer",
4162 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004163 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004164 })
4165 tests = append(tests, testCase{
4166 testType: serverTest,
4167 name: "OCSPStapling-Server-TLS13",
4168 config: Config{
4169 MaxVersion: VersionTLS13,
4170 },
4171 expectedOCSPResponse: testOCSPResponse,
4172 flags: []string{
4173 "-ocsp-response",
4174 base64.StdEncoding.EncodeToString(testOCSPResponse),
4175 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004176 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004177 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004178
David Benjamin4c3ddf72016-06-29 18:13:53 -04004179 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004180 for _, vers := range tlsVersions {
4181 if config.protocol == dtls && !vers.hasDTLS {
4182 continue
4183 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004184 for _, testType := range []testType{clientTest, serverTest} {
4185 suffix := "-Client"
4186 if testType == serverTest {
4187 suffix = "-Server"
4188 }
4189 suffix += "-" + vers.name
4190
4191 flag := "-verify-peer"
4192 if testType == serverTest {
4193 flag = "-require-any-client-certificate"
4194 }
4195
4196 tests = append(tests, testCase{
4197 testType: testType,
4198 name: "CertificateVerificationSucceed" + suffix,
4199 config: Config{
4200 MaxVersion: vers.version,
4201 Certificates: []Certificate{rsaCertificate},
4202 },
4203 flags: []string{
4204 flag,
4205 "-expect-verify-result",
4206 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004207 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004208 })
4209 tests = append(tests, testCase{
4210 testType: testType,
4211 name: "CertificateVerificationFail" + suffix,
4212 config: Config{
4213 MaxVersion: vers.version,
4214 Certificates: []Certificate{rsaCertificate},
4215 },
4216 flags: []string{
4217 flag,
4218 "-verify-fail",
4219 },
4220 shouldFail: true,
4221 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4222 })
4223 }
4224
4225 // By default, the client is in a soft fail mode where the peer
4226 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004227 tests = append(tests, testCase{
4228 testType: clientTest,
4229 name: "CertificateVerificationSoftFail-" + vers.name,
4230 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004231 MaxVersion: vers.version,
4232 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004233 },
4234 flags: []string{
4235 "-verify-fail",
4236 "-expect-verify-result",
4237 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004238 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004239 })
4240 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004241
David Benjamin1d4f4c02016-07-26 18:03:08 -04004242 tests = append(tests, testCase{
4243 name: "ShimSendAlert",
4244 flags: []string{"-send-alert"},
4245 shimWritesFirst: true,
4246 shouldFail: true,
4247 expectedLocalError: "remote error: decompression failure",
4248 })
4249
David Benjamin582ba042016-07-07 12:33:25 -07004250 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004251 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004252 name: "Renegotiate-Client",
4253 config: Config{
4254 MaxVersion: VersionTLS12,
4255 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004256 renegotiate: 1,
4257 flags: []string{
4258 "-renegotiate-freely",
4259 "-expect-total-renegotiations", "1",
4260 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004261 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004262
David Benjamin47921102016-07-28 11:29:18 -04004263 tests = append(tests, testCase{
4264 name: "SendHalfHelloRequest",
4265 config: Config{
4266 MaxVersion: VersionTLS12,
4267 Bugs: ProtocolBugs{
4268 PackHelloRequestWithFinished: config.packHandshakeFlight,
4269 },
4270 },
4271 sendHalfHelloRequest: true,
4272 flags: []string{"-renegotiate-ignore"},
4273 shouldFail: true,
4274 expectedError: ":UNEXPECTED_RECORD:",
4275 })
4276
David Benjamin760b1dd2015-05-15 23:33:48 -04004277 // NPN on client and server; results in post-handshake message.
4278 tests = append(tests, testCase{
4279 name: "NPN-Client",
4280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004281 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004282 NextProtos: []string{"foo"},
4283 },
4284 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004285 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004286 expectedNextProto: "foo",
4287 expectedNextProtoType: npn,
4288 })
4289 tests = append(tests, testCase{
4290 testType: serverTest,
4291 name: "NPN-Server",
4292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004293 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004294 NextProtos: []string{"bar"},
4295 },
4296 flags: []string{
4297 "-advertise-npn", "\x03foo\x03bar\x03baz",
4298 "-expect-next-proto", "bar",
4299 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004300 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004301 expectedNextProto: "bar",
4302 expectedNextProtoType: npn,
4303 })
4304
4305 // TODO(davidben): Add tests for when False Start doesn't trigger.
4306
4307 // Client does False Start and negotiates NPN.
4308 tests = append(tests, testCase{
4309 name: "FalseStart",
4310 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004311 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004312 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4313 NextProtos: []string{"foo"},
4314 Bugs: ProtocolBugs{
4315 ExpectFalseStart: true,
4316 },
4317 },
4318 flags: []string{
4319 "-false-start",
4320 "-select-next-proto", "foo",
4321 },
4322 shimWritesFirst: true,
4323 resumeSession: true,
4324 })
4325
4326 // Client does False Start and negotiates ALPN.
4327 tests = append(tests, testCase{
4328 name: "FalseStart-ALPN",
4329 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004330 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004331 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4332 NextProtos: []string{"foo"},
4333 Bugs: ProtocolBugs{
4334 ExpectFalseStart: true,
4335 },
4336 },
4337 flags: []string{
4338 "-false-start",
4339 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004340 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004341 },
4342 shimWritesFirst: true,
4343 resumeSession: true,
4344 })
4345
David Benjamin760b1dd2015-05-15 23:33:48 -04004346 // False Start without session tickets.
4347 tests = append(tests, testCase{
4348 name: "FalseStart-SessionTicketsDisabled",
4349 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004350 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004351 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4352 NextProtos: []string{"foo"},
4353 SessionTicketsDisabled: true,
4354 Bugs: ProtocolBugs{
4355 ExpectFalseStart: true,
4356 },
4357 },
4358 flags: []string{
4359 "-false-start",
4360 "-select-next-proto", "foo",
4361 },
4362 shimWritesFirst: true,
4363 })
4364
4365 // Server parses a V2ClientHello.
4366 tests = append(tests, testCase{
4367 testType: serverTest,
4368 name: "SendV2ClientHello",
4369 config: Config{
4370 // Choose a cipher suite that does not involve
4371 // elliptic curves, so no extensions are
4372 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004373 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004374 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004375 Bugs: ProtocolBugs{
4376 SendV2ClientHello: true,
4377 },
4378 },
4379 })
4380
Nick Harper60a85cb2016-09-23 16:25:11 -07004381 // Test Channel ID
4382 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004383 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004384 continue
4385 }
4386 // Client sends a Channel ID.
4387 tests = append(tests, testCase{
4388 name: "ChannelID-Client-" + ver.name,
4389 config: Config{
4390 MaxVersion: ver.version,
4391 RequestChannelID: true,
4392 },
4393 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4394 resumeSession: true,
4395 expectChannelID: true,
4396 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004397
Nick Harper60a85cb2016-09-23 16:25:11 -07004398 // Server accepts a Channel ID.
4399 tests = append(tests, testCase{
4400 testType: serverTest,
4401 name: "ChannelID-Server-" + ver.name,
4402 config: Config{
4403 MaxVersion: ver.version,
4404 ChannelID: channelIDKey,
4405 },
4406 flags: []string{
4407 "-expect-channel-id",
4408 base64.StdEncoding.EncodeToString(channelIDBytes),
4409 },
4410 resumeSession: true,
4411 expectChannelID: true,
4412 })
4413
4414 tests = append(tests, testCase{
4415 testType: serverTest,
4416 name: "InvalidChannelIDSignature-" + ver.name,
4417 config: Config{
4418 MaxVersion: ver.version,
4419 ChannelID: channelIDKey,
4420 Bugs: ProtocolBugs{
4421 InvalidChannelIDSignature: true,
4422 },
4423 },
4424 flags: []string{"-enable-channel-id"},
4425 shouldFail: true,
4426 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4427 })
4428 }
David Benjamin30789da2015-08-29 22:56:45 -04004429
David Benjaminf8fcdf32016-06-08 15:56:13 -04004430 // Channel ID and NPN at the same time, to ensure their relative
4431 // ordering is correct.
4432 tests = append(tests, testCase{
4433 name: "ChannelID-NPN-Client",
4434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004435 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004436 RequestChannelID: true,
4437 NextProtos: []string{"foo"},
4438 },
4439 flags: []string{
4440 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4441 "-select-next-proto", "foo",
4442 },
4443 resumeSession: true,
4444 expectChannelID: true,
4445 expectedNextProto: "foo",
4446 expectedNextProtoType: npn,
4447 })
4448 tests = append(tests, testCase{
4449 testType: serverTest,
4450 name: "ChannelID-NPN-Server",
4451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004452 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004453 ChannelID: channelIDKey,
4454 NextProtos: []string{"bar"},
4455 },
4456 flags: []string{
4457 "-expect-channel-id",
4458 base64.StdEncoding.EncodeToString(channelIDBytes),
4459 "-advertise-npn", "\x03foo\x03bar\x03baz",
4460 "-expect-next-proto", "bar",
4461 },
4462 resumeSession: true,
4463 expectChannelID: true,
4464 expectedNextProto: "bar",
4465 expectedNextProtoType: npn,
4466 })
4467
David Benjamin30789da2015-08-29 22:56:45 -04004468 // Bidirectional shutdown with the runner initiating.
4469 tests = append(tests, testCase{
4470 name: "Shutdown-Runner",
4471 config: Config{
4472 Bugs: ProtocolBugs{
4473 ExpectCloseNotify: true,
4474 },
4475 },
4476 flags: []string{"-check-close-notify"},
4477 })
4478
David Benjamine3843d42017-03-25 18:00:56 -05004479 if !config.implicitHandshake {
4480 // Bidirectional shutdown with the shim initiating. The runner,
4481 // in the meantime, sends garbage before the close_notify which
4482 // the shim must ignore. This test is disabled under implicit
4483 // handshake tests because the shim never reads or writes.
4484 tests = append(tests, testCase{
4485 name: "Shutdown-Shim",
4486 config: Config{
4487 MaxVersion: VersionTLS12,
4488 Bugs: ProtocolBugs{
4489 ExpectCloseNotify: true,
4490 },
David Benjamin30789da2015-08-29 22:56:45 -04004491 },
David Benjamine3843d42017-03-25 18:00:56 -05004492 shimShutsDown: true,
4493 sendEmptyRecords: 1,
4494 sendWarningAlerts: 1,
4495 flags: []string{"-check-close-notify"},
4496 })
4497 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004498 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004499 // TODO(davidben): DTLS 1.3 will want a similar thing for
4500 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004501 tests = append(tests, testCase{
4502 name: "SkipHelloVerifyRequest",
4503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004504 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004505 Bugs: ProtocolBugs{
4506 SkipHelloVerifyRequest: true,
4507 },
4508 },
4509 })
4510 }
4511
David Benjamin760b1dd2015-05-15 23:33:48 -04004512 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004513 test.protocol = config.protocol
4514 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004515 test.name += "-DTLS"
4516 }
David Benjamin582ba042016-07-07 12:33:25 -07004517 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004518 test.name += "-Async"
4519 test.flags = append(test.flags, "-async")
4520 } else {
4521 test.name += "-Sync"
4522 }
David Benjamin582ba042016-07-07 12:33:25 -07004523 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004524 test.name += "-SplitHandshakeRecords"
4525 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004526 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004527 test.config.Bugs.MaxPacketLength = 256
4528 test.flags = append(test.flags, "-mtu", "256")
4529 }
4530 }
David Benjamin582ba042016-07-07 12:33:25 -07004531 if config.packHandshakeFlight {
4532 test.name += "-PackHandshakeFlight"
4533 test.config.Bugs.PackHandshakeFlight = true
4534 }
David Benjamine3843d42017-03-25 18:00:56 -05004535 if config.implicitHandshake {
4536 test.name += "-ImplicitHandshake"
4537 test.flags = append(test.flags, "-implicit-handshake")
4538 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004539 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004540 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004541}
4542
Adam Langley524e7172015-02-20 16:04:00 -08004543func addDDoSCallbackTests() {
4544 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004545 for _, resume := range []bool{false, true} {
4546 suffix := "Resume"
4547 if resume {
4548 suffix = "No" + suffix
4549 }
4550
4551 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004552 testType: serverTest,
4553 name: "Server-DDoS-OK-" + suffix,
4554 config: Config{
4555 MaxVersion: VersionTLS12,
4556 },
Adam Langley524e7172015-02-20 16:04:00 -08004557 flags: []string{"-install-ddos-callback"},
4558 resumeSession: resume,
4559 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4563 config: Config{
4564 MaxVersion: VersionTLS13,
4565 },
4566 flags: []string{"-install-ddos-callback"},
4567 resumeSession: resume,
4568 })
Adam Langley524e7172015-02-20 16:04:00 -08004569
4570 failFlag := "-fail-ddos-callback"
4571 if resume {
4572 failFlag = "-fail-second-ddos-callback"
4573 }
4574 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004575 testType: serverTest,
4576 name: "Server-DDoS-Reject-" + suffix,
4577 config: Config{
4578 MaxVersion: VersionTLS12,
4579 },
David Benjamin2c66e072016-09-16 15:58:00 -04004580 flags: []string{"-install-ddos-callback", failFlag},
4581 resumeSession: resume,
4582 shouldFail: true,
4583 expectedError: ":CONNECTION_REJECTED:",
4584 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004585 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004586 testCases = append(testCases, testCase{
4587 testType: serverTest,
4588 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4589 config: Config{
4590 MaxVersion: VersionTLS13,
4591 },
David Benjamin2c66e072016-09-16 15:58:00 -04004592 flags: []string{"-install-ddos-callback", failFlag},
4593 resumeSession: resume,
4594 shouldFail: true,
4595 expectedError: ":CONNECTION_REJECTED:",
4596 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004597 })
Adam Langley524e7172015-02-20 16:04:00 -08004598 }
4599}
4600
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004601func addVersionNegotiationTests() {
4602 for i, shimVers := range tlsVersions {
4603 // Assemble flags to disable all newer versions on the shim.
4604 var flags []string
4605 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004606 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004607 }
4608
Steven Valdezfdd10992016-09-15 16:27:05 -04004609 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004610 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004611 protocols := []protocol{tls}
4612 if runnerVers.hasDTLS && shimVers.hasDTLS {
4613 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004614 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004615 for _, protocol := range protocols {
4616 expectedVersion := shimVers.version
4617 if runnerVers.version < shimVers.version {
4618 expectedVersion = runnerVers.version
4619 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004620
David Benjamin8b8c0062014-11-23 02:47:52 -05004621 suffix := shimVers.name + "-" + runnerVers.name
4622 if protocol == dtls {
4623 suffix += "-DTLS"
4624 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004625
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004626 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004627 clientVers := shimVers.version
4628 if clientVers > VersionTLS10 {
4629 clientVers = VersionTLS10
4630 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004631 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004632 serverVers := expectedVersion
4633 if expectedVersion >= VersionTLS13 {
4634 serverVers = VersionTLS10
4635 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004636 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004637
David Benjamin8b8c0062014-11-23 02:47:52 -05004638 testCases = append(testCases, testCase{
4639 protocol: protocol,
4640 testType: clientTest,
4641 name: "VersionNegotiation-Client-" + suffix,
4642 config: Config{
4643 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004644 Bugs: ProtocolBugs{
4645 ExpectInitialRecordVersion: clientVers,
4646 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004647 },
4648 flags: flags,
4649 expectedVersion: expectedVersion,
4650 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004651 testCases = append(testCases, testCase{
4652 protocol: protocol,
4653 testType: clientTest,
4654 name: "VersionNegotiation-Client2-" + suffix,
4655 config: Config{
4656 MaxVersion: runnerVers.version,
4657 Bugs: ProtocolBugs{
4658 ExpectInitialRecordVersion: clientVers,
4659 },
4660 },
David Benjamin353577c2017-06-29 15:54:58 -04004661 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004662 expectedVersion: expectedVersion,
4663 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004664
4665 testCases = append(testCases, testCase{
4666 protocol: protocol,
4667 testType: serverTest,
4668 name: "VersionNegotiation-Server-" + suffix,
4669 config: Config{
4670 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004671 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004672 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004673 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004674 },
4675 flags: flags,
4676 expectedVersion: expectedVersion,
4677 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004678 testCases = append(testCases, testCase{
4679 protocol: protocol,
4680 testType: serverTest,
4681 name: "VersionNegotiation-Server2-" + suffix,
4682 config: Config{
4683 MaxVersion: runnerVers.version,
4684 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004685 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004686 },
4687 },
David Benjamin353577c2017-06-29 15:54:58 -04004688 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004689 expectedVersion: expectedVersion,
4690 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004691 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004692 }
4693 }
David Benjamin95c69562016-06-29 18:15:03 -04004694
Steven Valdezfdd10992016-09-15 16:27:05 -04004695 // Test the version extension at all versions.
4696 for _, vers := range tlsVersions {
4697 protocols := []protocol{tls}
4698 if vers.hasDTLS {
4699 protocols = append(protocols, dtls)
4700 }
4701 for _, protocol := range protocols {
4702 suffix := vers.name
4703 if protocol == dtls {
4704 suffix += "-DTLS"
4705 }
4706
Steven Valdezc94998a2017-06-20 10:55:02 -04004707 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004708 testCases = append(testCases, testCase{
4709 protocol: protocol,
4710 testType: serverTest,
4711 name: "VersionNegotiationExtension-" + suffix,
4712 config: Config{
4713 Bugs: ProtocolBugs{
4714 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4715 },
4716 },
4717 expectedVersion: vers.version,
4718 })
4719 }
4720
4721 }
4722
4723 // If all versions are unknown, negotiation fails.
4724 testCases = append(testCases, testCase{
4725 testType: serverTest,
4726 name: "NoSupportedVersions",
4727 config: Config{
4728 Bugs: ProtocolBugs{
4729 SendSupportedVersions: []uint16{0x1111},
4730 },
4731 },
4732 shouldFail: true,
4733 expectedError: ":UNSUPPORTED_PROTOCOL:",
4734 })
4735 testCases = append(testCases, testCase{
4736 protocol: dtls,
4737 testType: serverTest,
4738 name: "NoSupportedVersions-DTLS",
4739 config: Config{
4740 Bugs: ProtocolBugs{
4741 SendSupportedVersions: []uint16{0x1111},
4742 },
4743 },
4744 shouldFail: true,
4745 expectedError: ":UNSUPPORTED_PROTOCOL:",
4746 })
4747
4748 testCases = append(testCases, testCase{
4749 testType: serverTest,
4750 name: "ClientHelloVersionTooHigh",
4751 config: Config{
4752 MaxVersion: VersionTLS13,
4753 Bugs: ProtocolBugs{
4754 SendClientVersion: 0x0304,
4755 OmitSupportedVersions: true,
4756 },
4757 },
4758 expectedVersion: VersionTLS12,
4759 })
4760
4761 testCases = append(testCases, testCase{
4762 testType: serverTest,
4763 name: "ConflictingVersionNegotiation",
4764 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004765 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004766 SendClientVersion: VersionTLS12,
4767 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004768 },
4769 },
David Benjaminad75a662016-09-30 15:42:59 -04004770 // The extension takes precedence over the ClientHello version.
4771 expectedVersion: VersionTLS11,
4772 })
4773
4774 testCases = append(testCases, testCase{
4775 testType: serverTest,
4776 name: "ConflictingVersionNegotiation-2",
4777 config: Config{
4778 Bugs: ProtocolBugs{
4779 SendClientVersion: VersionTLS11,
4780 SendSupportedVersions: []uint16{VersionTLS12},
4781 },
4782 },
4783 // The extension takes precedence over the ClientHello version.
4784 expectedVersion: VersionTLS12,
4785 })
4786
4787 testCases = append(testCases, testCase{
4788 testType: serverTest,
4789 name: "RejectFinalTLS13",
4790 config: Config{
4791 Bugs: ProtocolBugs{
4792 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4793 },
4794 },
4795 // We currently implement a draft TLS 1.3 version. Ensure that
4796 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004797 expectedVersion: VersionTLS12,
4798 })
4799
Brian Smithf85d3232016-10-28 10:34:06 -10004800 // Test that the maximum version is selected regardless of the
4801 // client-sent order.
4802 testCases = append(testCases, testCase{
4803 testType: serverTest,
4804 name: "IgnoreClientVersionOrder",
4805 config: Config{
4806 Bugs: ProtocolBugs{
4807 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4808 },
4809 },
4810 expectedVersion: VersionTLS13,
4811 })
4812
David Benjamin95c69562016-06-29 18:15:03 -04004813 // Test for version tolerance.
4814 testCases = append(testCases, testCase{
4815 testType: serverTest,
4816 name: "MinorVersionTolerance",
4817 config: Config{
4818 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004819 SendClientVersion: 0x03ff,
4820 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004821 },
4822 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004823 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004824 })
4825 testCases = append(testCases, testCase{
4826 testType: serverTest,
4827 name: "MajorVersionTolerance",
4828 config: Config{
4829 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004830 SendClientVersion: 0x0400,
4831 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004832 },
4833 },
David Benjaminad75a662016-09-30 15:42:59 -04004834 // TLS 1.3 must be negotiated with the supported_versions
4835 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004836 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004837 })
David Benjaminad75a662016-09-30 15:42:59 -04004838 testCases = append(testCases, testCase{
4839 testType: serverTest,
4840 name: "VersionTolerance-TLS13",
4841 config: Config{
4842 Bugs: ProtocolBugs{
4843 // Although TLS 1.3 does not use
4844 // ClientHello.version, it still tolerates high
4845 // values there.
4846 SendClientVersion: 0x0400,
4847 },
4848 },
4849 expectedVersion: VersionTLS13,
4850 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004851
David Benjamin95c69562016-06-29 18:15:03 -04004852 testCases = append(testCases, testCase{
4853 protocol: dtls,
4854 testType: serverTest,
4855 name: "MinorVersionTolerance-DTLS",
4856 config: Config{
4857 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004858 SendClientVersion: 0xfe00,
4859 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004860 },
4861 },
4862 expectedVersion: VersionTLS12,
4863 })
4864 testCases = append(testCases, testCase{
4865 protocol: dtls,
4866 testType: serverTest,
4867 name: "MajorVersionTolerance-DTLS",
4868 config: Config{
4869 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004870 SendClientVersion: 0xfdff,
4871 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004872 },
4873 },
4874 expectedVersion: VersionTLS12,
4875 })
4876
4877 // Test that versions below 3.0 are rejected.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "VersionTooLow",
4881 config: Config{
4882 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004883 SendClientVersion: 0x0200,
4884 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004885 },
4886 },
4887 shouldFail: true,
4888 expectedError: ":UNSUPPORTED_PROTOCOL:",
4889 })
4890 testCases = append(testCases, testCase{
4891 protocol: dtls,
4892 testType: serverTest,
4893 name: "VersionTooLow-DTLS",
4894 config: Config{
4895 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004896 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004897 },
4898 },
4899 shouldFail: true,
4900 expectedError: ":UNSUPPORTED_PROTOCOL:",
4901 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004902
David Benjamin2dc02042016-09-19 19:57:37 -04004903 testCases = append(testCases, testCase{
4904 name: "ServerBogusVersion",
4905 config: Config{
4906 Bugs: ProtocolBugs{
4907 SendServerHelloVersion: 0x1234,
4908 },
4909 },
4910 shouldFail: true,
4911 expectedError: ":UNSUPPORTED_PROTOCOL:",
4912 })
4913
David Benjamin1f61f0d2016-07-10 12:20:35 -04004914 // Test TLS 1.3's downgrade signal.
4915 testCases = append(testCases, testCase{
4916 name: "Downgrade-TLS12-Client",
4917 config: Config{
4918 Bugs: ProtocolBugs{
4919 NegotiateVersion: VersionTLS12,
4920 },
4921 },
David Benjamin592b5322016-09-30 15:15:01 -04004922 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004923 // TODO(davidben): This test should fail once TLS 1.3 is final
4924 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004925 })
4926 testCases = append(testCases, testCase{
4927 testType: serverTest,
4928 name: "Downgrade-TLS12-Server",
4929 config: Config{
4930 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004931 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004932 },
4933 },
David Benjamin592b5322016-09-30 15:15:01 -04004934 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004935 // TODO(davidben): This test should fail once TLS 1.3 is final
4936 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004937 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004938}
4939
David Benjaminaccb4542014-12-12 23:44:33 -05004940func addMinimumVersionTests() {
4941 for i, shimVers := range tlsVersions {
4942 // Assemble flags to disable all older versions on the shim.
4943 var flags []string
4944 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04004945 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05004946 }
4947
4948 for _, runnerVers := range tlsVersions {
4949 protocols := []protocol{tls}
4950 if runnerVers.hasDTLS && shimVers.hasDTLS {
4951 protocols = append(protocols, dtls)
4952 }
4953 for _, protocol := range protocols {
4954 suffix := shimVers.name + "-" + runnerVers.name
4955 if protocol == dtls {
4956 suffix += "-DTLS"
4957 }
David Benjaminaccb4542014-12-12 23:44:33 -05004958
David Benjaminaccb4542014-12-12 23:44:33 -05004959 var expectedVersion uint16
4960 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004961 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004962 if runnerVers.version >= shimVers.version {
4963 expectedVersion = runnerVers.version
4964 } else {
4965 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004966 expectedError = ":UNSUPPORTED_PROTOCOL:"
4967 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004968 }
4969
4970 testCases = append(testCases, testCase{
4971 protocol: protocol,
4972 testType: clientTest,
4973 name: "MinimumVersion-Client-" + suffix,
4974 config: Config{
4975 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004976 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004977 // Ensure the server does not decline to
4978 // select a version (versions extension) or
4979 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04004980 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04004981 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004982 },
David Benjaminaccb4542014-12-12 23:44:33 -05004983 },
David Benjamin87909c02014-12-13 01:55:01 -05004984 flags: flags,
4985 expectedVersion: expectedVersion,
4986 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004987 expectedError: expectedError,
4988 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004989 })
4990 testCases = append(testCases, testCase{
4991 protocol: protocol,
4992 testType: clientTest,
4993 name: "MinimumVersion-Client2-" + suffix,
4994 config: Config{
4995 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004996 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004997 // Ensure the server does not decline to
4998 // select a version (versions extension) or
4999 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005000 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005001 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005002 },
David Benjaminaccb4542014-12-12 23:44:33 -05005003 },
David Benjamin353577c2017-06-29 15:54:58 -04005004 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005005 expectedVersion: expectedVersion,
5006 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005007 expectedError: expectedError,
5008 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005009 })
5010
5011 testCases = append(testCases, testCase{
5012 protocol: protocol,
5013 testType: serverTest,
5014 name: "MinimumVersion-Server-" + suffix,
5015 config: Config{
5016 MaxVersion: runnerVers.version,
5017 },
David Benjamin87909c02014-12-13 01:55:01 -05005018 flags: flags,
5019 expectedVersion: expectedVersion,
5020 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005021 expectedError: expectedError,
5022 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005023 })
5024 testCases = append(testCases, testCase{
5025 protocol: protocol,
5026 testType: serverTest,
5027 name: "MinimumVersion-Server2-" + suffix,
5028 config: Config{
5029 MaxVersion: runnerVers.version,
5030 },
David Benjamin353577c2017-06-29 15:54:58 -04005031 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005032 expectedVersion: expectedVersion,
5033 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005034 expectedError: expectedError,
5035 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005036 })
5037 }
5038 }
5039 }
5040}
5041
David Benjamine78bfde2014-09-06 12:45:15 -04005042func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005043 // TODO(davidben): Extensions, where applicable, all move their server
5044 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5045 // tests for both. Also test interaction with 0-RTT when implemented.
5046
David Benjamin97d17d92016-07-14 16:12:00 -04005047 // Repeat extensions tests all versions except SSL 3.0.
5048 for _, ver := range tlsVersions {
5049 if ver.version == VersionSSL30 {
5050 continue
5051 }
5052
David Benjamin97d17d92016-07-14 16:12:00 -04005053 // Test that duplicate extensions are rejected.
5054 testCases = append(testCases, testCase{
5055 testType: clientTest,
5056 name: "DuplicateExtensionClient-" + ver.name,
5057 config: Config{
5058 MaxVersion: ver.version,
5059 Bugs: ProtocolBugs{
5060 DuplicateExtension: true,
5061 },
David Benjamine78bfde2014-09-06 12:45:15 -04005062 },
David Benjamin97d17d92016-07-14 16:12:00 -04005063 shouldFail: true,
5064 expectedLocalError: "remote error: error decoding message",
5065 })
5066 testCases = append(testCases, testCase{
5067 testType: serverTest,
5068 name: "DuplicateExtensionServer-" + ver.name,
5069 config: Config{
5070 MaxVersion: ver.version,
5071 Bugs: ProtocolBugs{
5072 DuplicateExtension: true,
5073 },
David Benjamine78bfde2014-09-06 12:45:15 -04005074 },
David Benjamin97d17d92016-07-14 16:12:00 -04005075 shouldFail: true,
5076 expectedLocalError: "remote error: error decoding message",
5077 })
5078
5079 // Test SNI.
5080 testCases = append(testCases, testCase{
5081 testType: clientTest,
5082 name: "ServerNameExtensionClient-" + ver.name,
5083 config: Config{
5084 MaxVersion: ver.version,
5085 Bugs: ProtocolBugs{
5086 ExpectServerName: "example.com",
5087 },
David Benjamine78bfde2014-09-06 12:45:15 -04005088 },
David Benjamin97d17d92016-07-14 16:12:00 -04005089 flags: []string{"-host-name", "example.com"},
5090 })
5091 testCases = append(testCases, testCase{
5092 testType: clientTest,
5093 name: "ServerNameExtensionClientMismatch-" + ver.name,
5094 config: Config{
5095 MaxVersion: ver.version,
5096 Bugs: ProtocolBugs{
5097 ExpectServerName: "mismatch.com",
5098 },
David Benjamine78bfde2014-09-06 12:45:15 -04005099 },
David Benjamin97d17d92016-07-14 16:12:00 -04005100 flags: []string{"-host-name", "example.com"},
5101 shouldFail: true,
5102 expectedLocalError: "tls: unexpected server name",
5103 })
5104 testCases = append(testCases, testCase{
5105 testType: clientTest,
5106 name: "ServerNameExtensionClientMissing-" + ver.name,
5107 config: Config{
5108 MaxVersion: ver.version,
5109 Bugs: ProtocolBugs{
5110 ExpectServerName: "missing.com",
5111 },
David Benjamine78bfde2014-09-06 12:45:15 -04005112 },
David Benjamin97d17d92016-07-14 16:12:00 -04005113 shouldFail: true,
5114 expectedLocalError: "tls: unexpected server name",
5115 })
5116 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005117 testType: clientTest,
5118 name: "TolerateServerNameAck-" + ver.name,
5119 config: Config{
5120 MaxVersion: ver.version,
5121 Bugs: ProtocolBugs{
5122 SendServerNameAck: true,
5123 },
5124 },
5125 flags: []string{"-host-name", "example.com"},
5126 resumeSession: true,
5127 })
5128 testCases = append(testCases, testCase{
5129 testType: clientTest,
5130 name: "UnsolicitedServerNameAck-" + ver.name,
5131 config: Config{
5132 MaxVersion: ver.version,
5133 Bugs: ProtocolBugs{
5134 SendServerNameAck: true,
5135 },
5136 },
5137 shouldFail: true,
5138 expectedError: ":UNEXPECTED_EXTENSION:",
5139 expectedLocalError: "remote error: unsupported extension",
5140 })
5141 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005142 testType: serverTest,
5143 name: "ServerNameExtensionServer-" + ver.name,
5144 config: Config{
5145 MaxVersion: ver.version,
5146 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005147 },
David Benjamin97d17d92016-07-14 16:12:00 -04005148 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005149 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005150 })
5151
5152 // Test ALPN.
5153 testCases = append(testCases, testCase{
5154 testType: clientTest,
5155 name: "ALPNClient-" + ver.name,
5156 config: Config{
5157 MaxVersion: ver.version,
5158 NextProtos: []string{"foo"},
5159 },
5160 flags: []string{
5161 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5162 "-expect-alpn", "foo",
5163 },
5164 expectedNextProto: "foo",
5165 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005166 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005167 })
5168 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005169 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005170 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005171 config: Config{
5172 MaxVersion: ver.version,
5173 Bugs: ProtocolBugs{
5174 SendALPN: "baz",
5175 },
5176 },
5177 flags: []string{
5178 "-advertise-alpn", "\x03foo\x03bar",
5179 },
5180 shouldFail: true,
5181 expectedError: ":INVALID_ALPN_PROTOCOL:",
5182 expectedLocalError: "remote error: illegal parameter",
5183 })
5184 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005185 testType: clientTest,
5186 name: "ALPNClient-AllowUnknown-" + ver.name,
5187 config: Config{
5188 MaxVersion: ver.version,
5189 Bugs: ProtocolBugs{
5190 SendALPN: "baz",
5191 },
5192 },
5193 flags: []string{
5194 "-advertise-alpn", "\x03foo\x03bar",
5195 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005196 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005197 },
5198 })
5199 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005200 testType: serverTest,
5201 name: "ALPNServer-" + ver.name,
5202 config: Config{
5203 MaxVersion: ver.version,
5204 NextProtos: []string{"foo", "bar", "baz"},
5205 },
5206 flags: []string{
5207 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5208 "-select-alpn", "foo",
5209 },
5210 expectedNextProto: "foo",
5211 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005212 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005213 })
5214 testCases = append(testCases, testCase{
5215 testType: serverTest,
5216 name: "ALPNServer-Decline-" + ver.name,
5217 config: Config{
5218 MaxVersion: ver.version,
5219 NextProtos: []string{"foo", "bar", "baz"},
5220 },
5221 flags: []string{"-decline-alpn"},
5222 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005223 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005224 })
5225
David Benjamin25fe85b2016-08-09 20:00:32 -04005226 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5227 // called once.
5228 testCases = append(testCases, testCase{
5229 testType: serverTest,
5230 name: "ALPNServer-Async-" + ver.name,
5231 config: Config{
5232 MaxVersion: ver.version,
5233 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005234 // Prior to TLS 1.3, exercise the asynchronous session callback.
5235 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005236 },
5237 flags: []string{
5238 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5239 "-select-alpn", "foo",
5240 "-async",
5241 },
5242 expectedNextProto: "foo",
5243 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005244 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005245 })
5246
David Benjamin97d17d92016-07-14 16:12:00 -04005247 var emptyString string
5248 testCases = append(testCases, testCase{
5249 testType: clientTest,
5250 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5251 config: Config{
5252 MaxVersion: ver.version,
5253 NextProtos: []string{""},
5254 Bugs: ProtocolBugs{
5255 // A server returning an empty ALPN protocol
5256 // should be rejected.
5257 ALPNProtocol: &emptyString,
5258 },
5259 },
5260 flags: []string{
5261 "-advertise-alpn", "\x03foo",
5262 },
5263 shouldFail: true,
5264 expectedError: ":PARSE_TLSEXT:",
5265 })
5266 testCases = append(testCases, testCase{
5267 testType: serverTest,
5268 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5269 config: Config{
5270 MaxVersion: ver.version,
5271 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005272 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005273 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005274 },
David Benjamin97d17d92016-07-14 16:12:00 -04005275 flags: []string{
5276 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005277 },
David Benjamin97d17d92016-07-14 16:12:00 -04005278 shouldFail: true,
5279 expectedError: ":PARSE_TLSEXT:",
5280 })
5281
5282 // Test NPN and the interaction with ALPN.
5283 if ver.version < VersionTLS13 {
5284 // Test that the server prefers ALPN over NPN.
5285 testCases = append(testCases, testCase{
5286 testType: serverTest,
5287 name: "ALPNServer-Preferred-" + ver.name,
5288 config: Config{
5289 MaxVersion: ver.version,
5290 NextProtos: []string{"foo", "bar", "baz"},
5291 },
5292 flags: []string{
5293 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5294 "-select-alpn", "foo",
5295 "-advertise-npn", "\x03foo\x03bar\x03baz",
5296 },
5297 expectedNextProto: "foo",
5298 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005299 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005300 })
5301 testCases = append(testCases, testCase{
5302 testType: serverTest,
5303 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5304 config: Config{
5305 MaxVersion: ver.version,
5306 NextProtos: []string{"foo", "bar", "baz"},
5307 Bugs: ProtocolBugs{
5308 SwapNPNAndALPN: true,
5309 },
5310 },
5311 flags: []string{
5312 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5313 "-select-alpn", "foo",
5314 "-advertise-npn", "\x03foo\x03bar\x03baz",
5315 },
5316 expectedNextProto: "foo",
5317 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005318 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005319 })
5320
5321 // Test that negotiating both NPN and ALPN is forbidden.
5322 testCases = append(testCases, testCase{
5323 name: "NegotiateALPNAndNPN-" + ver.name,
5324 config: Config{
5325 MaxVersion: ver.version,
5326 NextProtos: []string{"foo", "bar", "baz"},
5327 Bugs: ProtocolBugs{
5328 NegotiateALPNAndNPN: true,
5329 },
5330 },
5331 flags: []string{
5332 "-advertise-alpn", "\x03foo",
5333 "-select-next-proto", "foo",
5334 },
5335 shouldFail: true,
5336 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5337 })
5338 testCases = append(testCases, testCase{
5339 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5340 config: Config{
5341 MaxVersion: ver.version,
5342 NextProtos: []string{"foo", "bar", "baz"},
5343 Bugs: ProtocolBugs{
5344 NegotiateALPNAndNPN: true,
5345 SwapNPNAndALPN: true,
5346 },
5347 },
5348 flags: []string{
5349 "-advertise-alpn", "\x03foo",
5350 "-select-next-proto", "foo",
5351 },
5352 shouldFail: true,
5353 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5354 })
David Benjamin97d17d92016-07-14 16:12:00 -04005355 }
5356
5357 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005358
5359 // Resume with a corrupt ticket.
5360 testCases = append(testCases, testCase{
5361 testType: serverTest,
5362 name: "CorruptTicket-" + ver.name,
5363 config: Config{
5364 MaxVersion: ver.version,
5365 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005366 FilterTicket: func(in []byte) ([]byte, error) {
5367 in[len(in)-1] ^= 1
5368 return in, nil
5369 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005370 },
5371 },
5372 resumeSession: true,
5373 expectResumeRejected: true,
5374 })
5375 // Test the ticket callback, with and without renewal.
5376 testCases = append(testCases, testCase{
5377 testType: serverTest,
5378 name: "TicketCallback-" + ver.name,
5379 config: Config{
5380 MaxVersion: ver.version,
5381 },
5382 resumeSession: true,
5383 flags: []string{"-use-ticket-callback"},
5384 })
5385 testCases = append(testCases, testCase{
5386 testType: serverTest,
5387 name: "TicketCallback-Renew-" + ver.name,
5388 config: Config{
5389 MaxVersion: ver.version,
5390 Bugs: ProtocolBugs{
5391 ExpectNewTicket: true,
5392 },
5393 },
5394 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5395 resumeSession: true,
5396 })
5397
5398 // Test that the ticket callback is only called once when everything before
5399 // it in the ClientHello is asynchronous. This corrupts the ticket so
5400 // certificate selection callbacks run.
5401 testCases = append(testCases, testCase{
5402 testType: serverTest,
5403 name: "TicketCallback-SingleCall-" + ver.name,
5404 config: Config{
5405 MaxVersion: ver.version,
5406 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005407 FilterTicket: func(in []byte) ([]byte, error) {
5408 in[len(in)-1] ^= 1
5409 return in, nil
5410 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005411 },
5412 },
5413 resumeSession: true,
5414 expectResumeRejected: true,
5415 flags: []string{
5416 "-use-ticket-callback",
5417 "-async",
5418 },
5419 })
5420
David Benjamind4c349b2017-02-09 14:07:17 -05005421 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005422 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005423 testCases = append(testCases, testCase{
5424 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005425 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005426 config: Config{
5427 MaxVersion: ver.version,
5428 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005429 EmptyTicketSessionID: true,
5430 },
5431 },
5432 resumeSession: true,
5433 })
5434 testCases = append(testCases, testCase{
5435 testType: serverTest,
5436 name: "TicketSessionIDLength-16-" + ver.name,
5437 config: Config{
5438 MaxVersion: ver.version,
5439 Bugs: ProtocolBugs{
5440 TicketSessionIDLength: 16,
5441 },
5442 },
5443 resumeSession: true,
5444 })
5445 testCases = append(testCases, testCase{
5446 testType: serverTest,
5447 name: "TicketSessionIDLength-32-" + ver.name,
5448 config: Config{
5449 MaxVersion: ver.version,
5450 Bugs: ProtocolBugs{
5451 TicketSessionIDLength: 32,
5452 },
5453 },
5454 resumeSession: true,
5455 })
5456 testCases = append(testCases, testCase{
5457 testType: serverTest,
5458 name: "TicketSessionIDLength-33-" + ver.name,
5459 config: Config{
5460 MaxVersion: ver.version,
5461 Bugs: ProtocolBugs{
5462 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005463 },
5464 },
5465 resumeSession: true,
5466 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005467 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005468 expectedError: ":DECODE_ERROR:",
5469 })
5470 }
5471
5472 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5473 // are ignored.
5474 if ver.hasDTLS {
5475 testCases = append(testCases, testCase{
5476 protocol: dtls,
5477 name: "SRTP-Client-" + ver.name,
5478 config: Config{
5479 MaxVersion: ver.version,
5480 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5481 },
5482 flags: []string{
5483 "-srtp-profiles",
5484 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5485 },
5486 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5487 })
5488 testCases = append(testCases, testCase{
5489 protocol: dtls,
5490 testType: serverTest,
5491 name: "SRTP-Server-" + ver.name,
5492 config: Config{
5493 MaxVersion: ver.version,
5494 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5495 },
5496 flags: []string{
5497 "-srtp-profiles",
5498 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5499 },
5500 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5501 })
5502 // Test that the MKI is ignored.
5503 testCases = append(testCases, testCase{
5504 protocol: dtls,
5505 testType: serverTest,
5506 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5507 config: Config{
5508 MaxVersion: ver.version,
5509 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5510 Bugs: ProtocolBugs{
5511 SRTPMasterKeyIdentifer: "bogus",
5512 },
5513 },
5514 flags: []string{
5515 "-srtp-profiles",
5516 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5517 },
5518 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5519 })
5520 // Test that SRTP isn't negotiated on the server if there were
5521 // no matching profiles.
5522 testCases = append(testCases, testCase{
5523 protocol: dtls,
5524 testType: serverTest,
5525 name: "SRTP-Server-NoMatch-" + ver.name,
5526 config: Config{
5527 MaxVersion: ver.version,
5528 SRTPProtectionProfiles: []uint16{100, 101, 102},
5529 },
5530 flags: []string{
5531 "-srtp-profiles",
5532 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5533 },
5534 expectedSRTPProtectionProfile: 0,
5535 })
5536 // Test that the server returning an invalid SRTP profile is
5537 // flagged as an error by the client.
5538 testCases = append(testCases, testCase{
5539 protocol: dtls,
5540 name: "SRTP-Client-NoMatch-" + ver.name,
5541 config: Config{
5542 MaxVersion: ver.version,
5543 Bugs: ProtocolBugs{
5544 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5545 },
5546 },
5547 flags: []string{
5548 "-srtp-profiles",
5549 "SRTP_AES128_CM_SHA1_80",
5550 },
5551 shouldFail: true,
5552 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5553 })
5554 }
5555
5556 // Test SCT list.
5557 testCases = append(testCases, testCase{
5558 name: "SignedCertificateTimestampList-Client-" + ver.name,
5559 testType: clientTest,
5560 config: Config{
5561 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005562 },
David Benjamin97d17d92016-07-14 16:12:00 -04005563 flags: []string{
5564 "-enable-signed-cert-timestamps",
5565 "-expect-signed-cert-timestamps",
5566 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005567 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005568 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005569 })
David Benjamindaa88502016-10-04 16:32:16 -04005570
Adam Langleycfa08c32016-11-17 13:21:27 -08005571 var differentSCTList []byte
5572 differentSCTList = append(differentSCTList, testSCTList...)
5573 differentSCTList[len(differentSCTList)-1] ^= 1
5574
David Benjamindaa88502016-10-04 16:32:16 -04005575 // The SCT extension did not specify that it must only be sent on resumption as it
5576 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005577 testCases = append(testCases, testCase{
5578 name: "SendSCTListOnResume-" + ver.name,
5579 config: Config{
5580 MaxVersion: ver.version,
5581 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005582 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005583 },
David Benjamind98452d2015-06-16 14:16:23 -04005584 },
David Benjamin97d17d92016-07-14 16:12:00 -04005585 flags: []string{
5586 "-enable-signed-cert-timestamps",
5587 "-expect-signed-cert-timestamps",
5588 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005589 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005590 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005591 })
David Benjamindaa88502016-10-04 16:32:16 -04005592
David Benjamin97d17d92016-07-14 16:12:00 -04005593 testCases = append(testCases, testCase{
5594 name: "SignedCertificateTimestampList-Server-" + ver.name,
5595 testType: serverTest,
5596 config: Config{
5597 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005598 },
David Benjamin97d17d92016-07-14 16:12:00 -04005599 flags: []string{
5600 "-signed-cert-timestamps",
5601 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005602 },
David Benjamin97d17d92016-07-14 16:12:00 -04005603 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005604 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005605 })
David Benjamin53210cb2016-11-16 09:01:48 +09005606
Adam Langleycfa08c32016-11-17 13:21:27 -08005607 emptySCTListCert := *testCerts[0].cert
5608 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5609
5610 // Test empty SCT list.
5611 testCases = append(testCases, testCase{
5612 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5613 testType: clientTest,
5614 config: Config{
5615 MaxVersion: ver.version,
5616 Certificates: []Certificate{emptySCTListCert},
5617 },
5618 flags: []string{
5619 "-enable-signed-cert-timestamps",
5620 },
5621 shouldFail: true,
5622 expectedError: ":ERROR_PARSING_EXTENSION:",
5623 })
5624
5625 emptySCTCert := *testCerts[0].cert
5626 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5627
5628 // Test empty SCT in non-empty list.
5629 testCases = append(testCases, testCase{
5630 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5631 testType: clientTest,
5632 config: Config{
5633 MaxVersion: ver.version,
5634 Certificates: []Certificate{emptySCTCert},
5635 },
5636 flags: []string{
5637 "-enable-signed-cert-timestamps",
5638 },
5639 shouldFail: true,
5640 expectedError: ":ERROR_PARSING_EXTENSION:",
5641 })
5642
David Benjamin53210cb2016-11-16 09:01:48 +09005643 // Test that certificate-related extensions are not sent unsolicited.
5644 testCases = append(testCases, testCase{
5645 testType: serverTest,
5646 name: "UnsolicitedCertificateExtensions-" + ver.name,
5647 config: Config{
5648 MaxVersion: ver.version,
5649 Bugs: ProtocolBugs{
5650 NoOCSPStapling: true,
5651 NoSignedCertificateTimestamps: true,
5652 },
5653 },
5654 flags: []string{
5655 "-ocsp-response",
5656 base64.StdEncoding.EncodeToString(testOCSPResponse),
5657 "-signed-cert-timestamps",
5658 base64.StdEncoding.EncodeToString(testSCTList),
5659 },
5660 })
David Benjamin97d17d92016-07-14 16:12:00 -04005661 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005662
Paul Lietar4fac72e2015-09-09 13:44:55 +01005663 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005664 testType: clientTest,
5665 name: "ClientHelloPadding",
5666 config: Config{
5667 Bugs: ProtocolBugs{
5668 RequireClientHelloSize: 512,
5669 },
5670 },
5671 // This hostname just needs to be long enough to push the
5672 // ClientHello into F5's danger zone between 256 and 511 bytes
5673 // long.
5674 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5675 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005676
5677 // Extensions should not function in SSL 3.0.
5678 testCases = append(testCases, testCase{
5679 testType: serverTest,
5680 name: "SSLv3Extensions-NoALPN",
5681 config: Config{
5682 MaxVersion: VersionSSL30,
5683 NextProtos: []string{"foo", "bar", "baz"},
5684 },
5685 flags: []string{
5686 "-select-alpn", "foo",
5687 },
5688 expectNoNextProto: true,
5689 })
5690
5691 // Test session tickets separately as they follow a different codepath.
5692 testCases = append(testCases, testCase{
5693 testType: serverTest,
5694 name: "SSLv3Extensions-NoTickets",
5695 config: Config{
5696 MaxVersion: VersionSSL30,
5697 Bugs: ProtocolBugs{
5698 // Historically, session tickets in SSL 3.0
5699 // failed in different ways depending on whether
5700 // the client supported renegotiation_info.
5701 NoRenegotiationInfo: true,
5702 },
5703 },
5704 resumeSession: true,
5705 })
5706 testCases = append(testCases, testCase{
5707 testType: serverTest,
5708 name: "SSLv3Extensions-NoTickets2",
5709 config: Config{
5710 MaxVersion: VersionSSL30,
5711 },
5712 resumeSession: true,
5713 })
5714
5715 // But SSL 3.0 does send and process renegotiation_info.
5716 testCases = append(testCases, testCase{
5717 testType: serverTest,
5718 name: "SSLv3Extensions-RenegotiationInfo",
5719 config: Config{
5720 MaxVersion: VersionSSL30,
5721 Bugs: ProtocolBugs{
5722 RequireRenegotiationInfo: true,
5723 },
5724 },
David Benjamind2610042017-01-03 10:49:28 -05005725 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005726 })
5727 testCases = append(testCases, testCase{
5728 testType: serverTest,
5729 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5730 config: Config{
5731 MaxVersion: VersionSSL30,
5732 Bugs: ProtocolBugs{
5733 NoRenegotiationInfo: true,
5734 SendRenegotiationSCSV: true,
5735 RequireRenegotiationInfo: true,
5736 },
5737 },
David Benjamind2610042017-01-03 10:49:28 -05005738 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005739 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005740
5741 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5742 // in ServerHello.
5743 testCases = append(testCases, testCase{
5744 name: "NPN-Forbidden-TLS13",
5745 config: Config{
5746 MaxVersion: VersionTLS13,
5747 NextProtos: []string{"foo"},
5748 Bugs: ProtocolBugs{
5749 NegotiateNPNAtAllVersions: true,
5750 },
5751 },
5752 flags: []string{"-select-next-proto", "foo"},
5753 shouldFail: true,
5754 expectedError: ":ERROR_PARSING_EXTENSION:",
5755 })
5756 testCases = append(testCases, testCase{
5757 name: "EMS-Forbidden-TLS13",
5758 config: Config{
5759 MaxVersion: VersionTLS13,
5760 Bugs: ProtocolBugs{
5761 NegotiateEMSAtAllVersions: true,
5762 },
5763 },
5764 shouldFail: true,
5765 expectedError: ":ERROR_PARSING_EXTENSION:",
5766 })
5767 testCases = append(testCases, testCase{
5768 name: "RenegotiationInfo-Forbidden-TLS13",
5769 config: Config{
5770 MaxVersion: VersionTLS13,
5771 Bugs: ProtocolBugs{
5772 NegotiateRenegotiationInfoAtAllVersions: true,
5773 },
5774 },
5775 shouldFail: true,
5776 expectedError: ":ERROR_PARSING_EXTENSION:",
5777 })
5778 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005779 name: "Ticket-Forbidden-TLS13",
5780 config: Config{
5781 MaxVersion: VersionTLS12,
5782 },
5783 resumeConfig: &Config{
5784 MaxVersion: VersionTLS13,
5785 Bugs: ProtocolBugs{
5786 AdvertiseTicketExtension: true,
5787 },
5788 },
5789 resumeSession: true,
5790 shouldFail: true,
5791 expectedError: ":ERROR_PARSING_EXTENSION:",
5792 })
5793
5794 // Test that illegal extensions in TLS 1.3 are declined by the server if
5795 // offered in ClientHello. The runner's server will fail if this occurs,
5796 // so we exercise the offering path. (EMS and Renegotiation Info are
5797 // implicit in every test.)
5798 testCases = append(testCases, testCase{
5799 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005800 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005801 config: Config{
5802 MaxVersion: VersionTLS13,
5803 NextProtos: []string{"bar"},
5804 },
5805 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5806 })
David Benjamin196df5b2016-09-21 16:23:27 -04005807
David Benjamindaa88502016-10-04 16:32:16 -04005808 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5809 // tolerated.
5810 testCases = append(testCases, testCase{
5811 name: "SendOCSPResponseOnResume-TLS12",
5812 config: Config{
5813 MaxVersion: VersionTLS12,
5814 Bugs: ProtocolBugs{
5815 SendOCSPResponseOnResume: []byte("bogus"),
5816 },
5817 },
5818 flags: []string{
5819 "-enable-ocsp-stapling",
5820 "-expect-ocsp-response",
5821 base64.StdEncoding.EncodeToString(testOCSPResponse),
5822 },
5823 resumeSession: true,
5824 })
5825
David Benjamindaa88502016-10-04 16:32:16 -04005826 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005827 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005828 config: Config{
5829 MaxVersion: VersionTLS13,
5830 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005831 SendExtensionOnCertificate: testOCSPExtension,
5832 },
5833 },
5834 shouldFail: true,
5835 expectedError: ":UNEXPECTED_EXTENSION:",
5836 })
5837
5838 testCases = append(testCases, testCase{
5839 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5840 config: Config{
5841 MaxVersion: VersionTLS13,
5842 Bugs: ProtocolBugs{
5843 SendExtensionOnCertificate: testSCTExtension,
5844 },
5845 },
5846 shouldFail: true,
5847 expectedError: ":UNEXPECTED_EXTENSION:",
5848 })
5849
5850 // Test that extensions on client certificates are never accepted.
5851 testCases = append(testCases, testCase{
5852 name: "SendExtensionOnClientCertificate-TLS13",
5853 testType: serverTest,
5854 config: Config{
5855 MaxVersion: VersionTLS13,
5856 Certificates: []Certificate{rsaCertificate},
5857 Bugs: ProtocolBugs{
5858 SendExtensionOnCertificate: testOCSPExtension,
5859 },
5860 },
5861 flags: []string{
5862 "-enable-ocsp-stapling",
5863 "-require-any-client-certificate",
5864 },
5865 shouldFail: true,
5866 expectedError: ":UNEXPECTED_EXTENSION:",
5867 })
5868
5869 testCases = append(testCases, testCase{
5870 name: "SendUnknownExtensionOnCertificate-TLS13",
5871 config: Config{
5872 MaxVersion: VersionTLS13,
5873 Bugs: ProtocolBugs{
5874 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5875 },
5876 },
5877 shouldFail: true,
5878 expectedError: ":UNEXPECTED_EXTENSION:",
5879 })
5880
Adam Langleycfa08c32016-11-17 13:21:27 -08005881 var differentSCTList []byte
5882 differentSCTList = append(differentSCTList, testSCTList...)
5883 differentSCTList[len(differentSCTList)-1] ^= 1
5884
Steven Valdeza833c352016-11-01 13:39:36 -04005885 // Test that extensions on intermediates are allowed but ignored.
5886 testCases = append(testCases, testCase{
5887 name: "IgnoreExtensionsOnIntermediates-TLS13",
5888 config: Config{
5889 MaxVersion: VersionTLS13,
5890 Certificates: []Certificate{rsaChainCertificate},
5891 Bugs: ProtocolBugs{
5892 // Send different values on the intermediate. This tests
5893 // the intermediate's extensions do not override the
5894 // leaf's.
5895 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005896 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005897 },
5898 },
5899 flags: []string{
5900 "-enable-ocsp-stapling",
5901 "-expect-ocsp-response",
5902 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005903 "-enable-signed-cert-timestamps",
5904 "-expect-signed-cert-timestamps",
5905 base64.StdEncoding.EncodeToString(testSCTList),
5906 },
5907 resumeSession: true,
5908 })
5909
5910 // Test that extensions are not sent on intermediates when configured
5911 // only for a leaf.
5912 testCases = append(testCases, testCase{
5913 testType: serverTest,
5914 name: "SendNoExtensionsOnIntermediate-TLS13",
5915 config: Config{
5916 MaxVersion: VersionTLS13,
5917 Bugs: ProtocolBugs{
5918 ExpectNoExtensionsOnIntermediate: true,
5919 },
5920 },
5921 flags: []string{
5922 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5923 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5924 "-ocsp-response",
5925 base64.StdEncoding.EncodeToString(testOCSPResponse),
5926 "-signed-cert-timestamps",
5927 base64.StdEncoding.EncodeToString(testSCTList),
5928 },
5929 })
5930
5931 // Test that extensions are not sent on client certificates.
5932 testCases = append(testCases, testCase{
5933 name: "SendNoClientCertificateExtensions-TLS13",
5934 config: Config{
5935 MaxVersion: VersionTLS13,
5936 ClientAuth: RequireAnyClientCert,
5937 },
5938 flags: []string{
5939 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5940 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5941 "-ocsp-response",
5942 base64.StdEncoding.EncodeToString(testOCSPResponse),
5943 "-signed-cert-timestamps",
5944 base64.StdEncoding.EncodeToString(testSCTList),
5945 },
5946 })
5947
5948 testCases = append(testCases, testCase{
5949 name: "SendDuplicateExtensionsOnCerts-TLS13",
5950 config: Config{
5951 MaxVersion: VersionTLS13,
5952 Bugs: ProtocolBugs{
5953 SendDuplicateCertExtensions: true,
5954 },
5955 },
5956 flags: []string{
5957 "-enable-ocsp-stapling",
5958 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005959 },
5960 resumeSession: true,
5961 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005962 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005963 })
Adam Langley9b885c52016-11-18 14:21:03 -08005964
5965 testCases = append(testCases, testCase{
5966 name: "SignedCertificateTimestampListInvalid-Server",
5967 testType: serverTest,
5968 flags: []string{
5969 "-signed-cert-timestamps",
5970 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5971 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005972 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005973 expectedError: ":INVALID_SCT_LIST:",
5974 })
David Benjamine78bfde2014-09-06 12:45:15 -04005975}
5976
David Benjamin01fe8202014-09-24 15:21:44 -04005977func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005978 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005979 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005980 // SSL 3.0 does not have tickets and TLS 1.3 does not
5981 // have session IDs, so skip their cross-resumption
5982 // tests.
5983 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5984 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5985 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005986 }
5987
David Benjamin8b8c0062014-11-23 02:47:52 -05005988 protocols := []protocol{tls}
5989 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5990 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005991 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005992 for _, protocol := range protocols {
5993 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5994 if protocol == dtls {
5995 suffix += "-DTLS"
5996 }
5997
David Benjaminece3de92015-03-16 18:02:20 -04005998 if sessionVers.version == resumeVers.version {
5999 testCases = append(testCases, testCase{
6000 protocol: protocol,
6001 name: "Resume-Client" + suffix,
6002 resumeSession: true,
6003 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006004 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006005 Bugs: ProtocolBugs{
6006 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6007 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6008 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006009 },
David Benjaminece3de92015-03-16 18:02:20 -04006010 expectedVersion: sessionVers.version,
6011 expectedResumeVersion: resumeVers.version,
6012 })
6013 } else {
David Benjamin405da482016-08-08 17:25:07 -04006014 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6015
6016 // Offering a TLS 1.3 session sends an empty session ID, so
6017 // there is no way to convince a non-lookahead client the
6018 // session was resumed. It will appear to the client that a
6019 // stray ChangeCipherSpec was sent.
6020 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6021 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006022 }
6023
David Benjaminece3de92015-03-16 18:02:20 -04006024 testCases = append(testCases, testCase{
6025 protocol: protocol,
6026 name: "Resume-Client-Mismatch" + suffix,
6027 resumeSession: true,
6028 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006029 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006030 },
David Benjaminece3de92015-03-16 18:02:20 -04006031 expectedVersion: sessionVers.version,
6032 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006033 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006034 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006035 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006036 },
6037 },
6038 expectedResumeVersion: resumeVers.version,
6039 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006040 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006041 })
6042 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006043
6044 testCases = append(testCases, testCase{
6045 protocol: protocol,
6046 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006047 resumeSession: true,
6048 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006049 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006050 },
6051 expectedVersion: sessionVers.version,
6052 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006053 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006054 },
6055 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006056 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006057 expectedResumeVersion: resumeVers.version,
6058 })
6059
David Benjamin8b8c0062014-11-23 02:47:52 -05006060 testCases = append(testCases, testCase{
6061 protocol: protocol,
6062 testType: serverTest,
6063 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006064 resumeSession: true,
6065 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006066 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006067 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006068 expectedVersion: sessionVers.version,
6069 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006070 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006071 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006072 Bugs: ProtocolBugs{
6073 SendBothTickets: true,
6074 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006075 },
6076 expectedResumeVersion: resumeVers.version,
6077 })
6078 }
David Benjamin01fe8202014-09-24 15:21:44 -04006079 }
6080 }
David Benjaminece3de92015-03-16 18:02:20 -04006081
David Benjamin4199b0d2016-11-01 13:58:25 -04006082 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006083 testCases = append(testCases, testCase{
6084 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006085 name: "ShimTicketRewritable",
6086 resumeSession: true,
6087 config: Config{
6088 MaxVersion: VersionTLS12,
6089 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6090 Bugs: ProtocolBugs{
6091 FilterTicket: func(in []byte) ([]byte, error) {
6092 in, err := SetShimTicketVersion(in, VersionTLS12)
6093 if err != nil {
6094 return nil, err
6095 }
6096 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6097 },
6098 },
6099 },
6100 flags: []string{
6101 "-ticket-key",
6102 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6103 },
6104 })
6105
6106 // Resumptions are declined if the version does not match.
6107 testCases = append(testCases, testCase{
6108 testType: serverTest,
6109 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006110 resumeSession: true,
6111 config: Config{
6112 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006113 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006114 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006115 FilterTicket: func(in []byte) ([]byte, error) {
6116 return SetShimTicketVersion(in, VersionTLS13)
6117 },
6118 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006119 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006120 flags: []string{
6121 "-ticket-key",
6122 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6123 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006124 expectResumeRejected: true,
6125 })
6126
6127 testCases = append(testCases, testCase{
6128 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006129 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006130 resumeSession: true,
6131 config: Config{
6132 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006133 Bugs: ProtocolBugs{
6134 FilterTicket: func(in []byte) ([]byte, error) {
6135 return SetShimTicketVersion(in, VersionTLS12)
6136 },
6137 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006138 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006139 flags: []string{
6140 "-ticket-key",
6141 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6142 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006143 expectResumeRejected: true,
6144 })
6145
David Benjamin4199b0d2016-11-01 13:58:25 -04006146 // Resumptions are declined if the cipher is invalid or disabled.
6147 testCases = append(testCases, testCase{
6148 testType: serverTest,
6149 name: "Resume-Server-DeclineBadCipher",
6150 resumeSession: true,
6151 config: Config{
6152 MaxVersion: VersionTLS12,
6153 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006154 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006155 FilterTicket: func(in []byte) ([]byte, error) {
6156 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6157 },
6158 },
6159 },
6160 flags: []string{
6161 "-ticket-key",
6162 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6163 },
6164 expectResumeRejected: true,
6165 })
6166
6167 testCases = append(testCases, testCase{
6168 testType: serverTest,
6169 name: "Resume-Server-DeclineBadCipher-2",
6170 resumeSession: true,
6171 config: Config{
6172 MaxVersion: VersionTLS12,
6173 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006174 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006175 FilterTicket: func(in []byte) ([]byte, error) {
6176 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6177 },
6178 },
6179 },
6180 flags: []string{
6181 "-cipher", "AES128",
6182 "-ticket-key",
6183 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6184 },
6185 expectResumeRejected: true,
6186 })
6187
David Benjaminf01f42a2016-11-16 19:05:33 +09006188 // Sessions are not resumed if they do not use the preferred cipher.
6189 testCases = append(testCases, testCase{
6190 testType: serverTest,
6191 name: "Resume-Server-CipherNotPreferred",
6192 resumeSession: true,
6193 config: Config{
6194 MaxVersion: VersionTLS12,
6195 Bugs: ProtocolBugs{
6196 ExpectNewTicket: true,
6197 FilterTicket: func(in []byte) ([]byte, error) {
6198 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6199 },
6200 },
6201 },
6202 flags: []string{
6203 "-ticket-key",
6204 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6205 },
6206 shouldFail: false,
6207 expectResumeRejected: true,
6208 })
6209
6210 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6211 // PRF hashes match, but BoringSSL will always decline such resumptions.
6212 testCases = append(testCases, testCase{
6213 testType: serverTest,
6214 name: "Resume-Server-CipherNotPreferred-TLS13",
6215 resumeSession: true,
6216 config: Config{
6217 MaxVersion: VersionTLS13,
6218 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6219 Bugs: ProtocolBugs{
6220 FilterTicket: func(in []byte) ([]byte, error) {
6221 // If the client (runner) offers ChaCha20-Poly1305 first, the
6222 // server (shim) always prefers it. Switch it to AES-GCM.
6223 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6224 },
6225 },
6226 },
6227 flags: []string{
6228 "-ticket-key",
6229 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6230 },
6231 shouldFail: false,
6232 expectResumeRejected: true,
6233 })
6234
6235 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006236 testCases = append(testCases, testCase{
6237 testType: serverTest,
6238 name: "Resume-Server-DeclineBadCipher-TLS13",
6239 resumeSession: true,
6240 config: Config{
6241 MaxVersion: VersionTLS13,
6242 Bugs: ProtocolBugs{
6243 FilterTicket: func(in []byte) ([]byte, error) {
6244 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6245 },
6246 },
6247 },
6248 flags: []string{
6249 "-ticket-key",
6250 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6251 },
6252 expectResumeRejected: true,
6253 })
6254
David Benjaminf01f42a2016-11-16 19:05:33 +09006255 // If the client does not offer the cipher from the session, decline to
6256 // resume. Clients are forbidden from doing this, but BoringSSL selects
6257 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006258 testCases = append(testCases, testCase{
6259 testType: serverTest,
6260 name: "Resume-Server-UnofferedCipher",
6261 resumeSession: true,
6262 config: Config{
6263 MaxVersion: VersionTLS12,
6264 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6265 },
6266 resumeConfig: &Config{
6267 MaxVersion: VersionTLS12,
6268 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6269 Bugs: ProtocolBugs{
6270 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6271 },
6272 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006273 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006274 })
6275
David Benjaminf01f42a2016-11-16 19:05:33 +09006276 // In TLS 1.3, clients may advertise a cipher list which does not
6277 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006278 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6279 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006280 testCases = append(testCases, testCase{
6281 testType: serverTest,
6282 name: "Resume-Server-UnofferedCipher-TLS13",
6283 resumeSession: true,
6284 config: Config{
6285 MaxVersion: VersionTLS13,
6286 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6287 },
6288 resumeConfig: &Config{
6289 MaxVersion: VersionTLS13,
6290 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6291 Bugs: ProtocolBugs{
6292 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6293 },
6294 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006295 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006296 })
6297
David Benjamin4199b0d2016-11-01 13:58:25 -04006298 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006299 testCases = append(testCases, testCase{
6300 name: "Resume-Client-CipherMismatch",
6301 resumeSession: true,
6302 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006303 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006304 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6305 },
6306 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006307 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006308 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6309 Bugs: ProtocolBugs{
6310 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6311 },
6312 },
6313 shouldFail: true,
6314 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6315 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006316
David Benjamine1cc35e2016-11-16 16:25:58 +09006317 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6318 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006319 testCases = append(testCases, testCase{
6320 name: "Resume-Client-CipherMismatch-TLS13",
6321 resumeSession: true,
6322 config: Config{
6323 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006324 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006325 },
6326 resumeConfig: &Config{
6327 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006328 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6329 },
6330 })
6331
6332 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6333 testCases = append(testCases, testCase{
6334 name: "Resume-Client-PRFMismatch-TLS13",
6335 resumeSession: true,
6336 config: Config{
6337 MaxVersion: VersionTLS13,
6338 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6339 },
6340 resumeConfig: &Config{
6341 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006342 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006343 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006344 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006345 },
6346 },
6347 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006348 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006349 })
Steven Valdeza833c352016-11-01 13:39:36 -04006350
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "Resume-Server-BinderWrongLength",
6354 resumeSession: true,
6355 config: Config{
6356 MaxVersion: VersionTLS13,
6357 Bugs: ProtocolBugs{
6358 SendShortPSKBinder: true,
6359 },
6360 },
6361 shouldFail: true,
6362 expectedLocalError: "remote error: error decrypting message",
6363 expectedError: ":DIGEST_CHECK_FAILED:",
6364 })
6365
6366 testCases = append(testCases, testCase{
6367 testType: serverTest,
6368 name: "Resume-Server-NoPSKBinder",
6369 resumeSession: true,
6370 config: Config{
6371 MaxVersion: VersionTLS13,
6372 Bugs: ProtocolBugs{
6373 SendNoPSKBinder: true,
6374 },
6375 },
6376 shouldFail: true,
6377 expectedLocalError: "remote error: error decoding message",
6378 expectedError: ":DECODE_ERROR:",
6379 })
6380
6381 testCases = append(testCases, testCase{
6382 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006383 name: "Resume-Server-ExtraPSKBinder",
6384 resumeSession: true,
6385 config: Config{
6386 MaxVersion: VersionTLS13,
6387 Bugs: ProtocolBugs{
6388 SendExtraPSKBinder: true,
6389 },
6390 },
6391 shouldFail: true,
6392 expectedLocalError: "remote error: illegal parameter",
6393 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6394 })
6395
6396 testCases = append(testCases, testCase{
6397 testType: serverTest,
6398 name: "Resume-Server-ExtraIdentityNoBinder",
6399 resumeSession: true,
6400 config: Config{
6401 MaxVersion: VersionTLS13,
6402 Bugs: ProtocolBugs{
6403 ExtraPSKIdentity: true,
6404 },
6405 },
6406 shouldFail: true,
6407 expectedLocalError: "remote error: illegal parameter",
6408 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6409 })
6410
6411 testCases = append(testCases, testCase{
6412 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006413 name: "Resume-Server-InvalidPSKBinder",
6414 resumeSession: true,
6415 config: Config{
6416 MaxVersion: VersionTLS13,
6417 Bugs: ProtocolBugs{
6418 SendInvalidPSKBinder: true,
6419 },
6420 },
6421 shouldFail: true,
6422 expectedLocalError: "remote error: error decrypting message",
6423 expectedError: ":DIGEST_CHECK_FAILED:",
6424 })
6425
6426 testCases = append(testCases, testCase{
6427 testType: serverTest,
6428 name: "Resume-Server-PSKBinderFirstExtension",
6429 resumeSession: true,
6430 config: Config{
6431 MaxVersion: VersionTLS13,
6432 Bugs: ProtocolBugs{
6433 PSKBinderFirst: true,
6434 },
6435 },
6436 shouldFail: true,
6437 expectedLocalError: "remote error: illegal parameter",
6438 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6439 })
David Benjamin01fe8202014-09-24 15:21:44 -04006440}
6441
Adam Langley2ae77d22014-10-28 17:29:33 -07006442func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006443 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006444 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006445 testType: serverTest,
6446 name: "Renegotiate-Server-Forbidden",
6447 config: Config{
6448 MaxVersion: VersionTLS12,
6449 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006450 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006451 shouldFail: true,
6452 expectedError: ":NO_RENEGOTIATION:",
6453 expectedLocalError: "remote error: no renegotiation",
6454 })
Adam Langley5021b222015-06-12 18:27:58 -07006455 // The server shouldn't echo the renegotiation extension unless
6456 // requested by the client.
6457 testCases = append(testCases, testCase{
6458 testType: serverTest,
6459 name: "Renegotiate-Server-NoExt",
6460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006461 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006462 Bugs: ProtocolBugs{
6463 NoRenegotiationInfo: true,
6464 RequireRenegotiationInfo: true,
6465 },
6466 },
6467 shouldFail: true,
6468 expectedLocalError: "renegotiation extension missing",
6469 })
6470 // The renegotiation SCSV should be sufficient for the server to echo
6471 // the extension.
6472 testCases = append(testCases, testCase{
6473 testType: serverTest,
6474 name: "Renegotiate-Server-NoExt-SCSV",
6475 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006476 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006477 Bugs: ProtocolBugs{
6478 NoRenegotiationInfo: true,
6479 SendRenegotiationSCSV: true,
6480 RequireRenegotiationInfo: true,
6481 },
6482 },
6483 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006484 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006485 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006486 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006487 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006488 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006489 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006490 },
6491 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006492 renegotiate: 1,
6493 flags: []string{
6494 "-renegotiate-freely",
6495 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006496 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006497 },
David Benjamincdea40c2015-03-19 14:09:43 -04006498 })
6499 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006500 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006501 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006503 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006504 Bugs: ProtocolBugs{
6505 EmptyRenegotiationInfo: true,
6506 },
6507 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006508 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006509 shouldFail: true,
6510 expectedError: ":RENEGOTIATION_MISMATCH:",
6511 })
6512 testCases = append(testCases, testCase{
6513 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006514 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006517 Bugs: ProtocolBugs{
6518 BadRenegotiationInfo: true,
6519 },
6520 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006521 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006522 shouldFail: true,
6523 expectedError: ":RENEGOTIATION_MISMATCH:",
6524 })
6525 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006526 name: "Renegotiate-Client-BadExt2",
6527 renegotiate: 1,
6528 config: Config{
6529 MaxVersion: VersionTLS12,
6530 Bugs: ProtocolBugs{
6531 BadRenegotiationInfoEnd: true,
6532 },
6533 },
6534 flags: []string{"-renegotiate-freely"},
6535 shouldFail: true,
6536 expectedError: ":RENEGOTIATION_MISMATCH:",
6537 })
6538 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006539 name: "Renegotiate-Client-Downgrade",
6540 renegotiate: 1,
6541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006542 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006543 Bugs: ProtocolBugs{
6544 NoRenegotiationInfoAfterInitial: true,
6545 },
6546 },
6547 flags: []string{"-renegotiate-freely"},
6548 shouldFail: true,
6549 expectedError: ":RENEGOTIATION_MISMATCH:",
6550 })
6551 testCases = append(testCases, testCase{
6552 name: "Renegotiate-Client-Upgrade",
6553 renegotiate: 1,
6554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006555 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006556 Bugs: ProtocolBugs{
6557 NoRenegotiationInfoInInitial: true,
6558 },
6559 },
6560 flags: []string{"-renegotiate-freely"},
6561 shouldFail: true,
6562 expectedError: ":RENEGOTIATION_MISMATCH:",
6563 })
6564 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006565 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006566 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006568 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006569 Bugs: ProtocolBugs{
6570 NoRenegotiationInfo: true,
6571 },
6572 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006573 flags: []string{
6574 "-renegotiate-freely",
6575 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006576 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006577 },
David Benjamincff0b902015-05-15 23:09:47 -04006578 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006579
6580 // Test that the server may switch ciphers on renegotiation without
6581 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006582 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006583 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006584 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006585 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006586 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006587 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006588 },
6589 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006590 flags: []string{
6591 "-renegotiate-freely",
6592 "-expect-total-renegotiations", "1",
6593 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006594 })
6595 testCases = append(testCases, testCase{
6596 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006597 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006598 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006599 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006600 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6601 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006602 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006603 flags: []string{
6604 "-renegotiate-freely",
6605 "-expect-total-renegotiations", "1",
6606 },
David Benjaminb16346b2015-04-08 19:16:58 -04006607 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006608
6609 // Test that the server may not switch versions on renegotiation.
6610 testCases = append(testCases, testCase{
6611 name: "Renegotiate-Client-SwitchVersion",
6612 config: Config{
6613 MaxVersion: VersionTLS12,
6614 // Pick a cipher which exists at both versions.
6615 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6616 Bugs: ProtocolBugs{
6617 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006618 // Avoid failing early at the record layer.
6619 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006620 },
6621 },
6622 renegotiate: 1,
6623 flags: []string{
6624 "-renegotiate-freely",
6625 "-expect-total-renegotiations", "1",
6626 },
6627 shouldFail: true,
6628 expectedError: ":WRONG_SSL_VERSION:",
6629 })
6630
David Benjaminb16346b2015-04-08 19:16:58 -04006631 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006632 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006633 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006634 config: Config{
6635 MaxVersion: VersionTLS10,
6636 Bugs: ProtocolBugs{
6637 RequireSameRenegoClientVersion: true,
6638 },
6639 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006640 flags: []string{
6641 "-renegotiate-freely",
6642 "-expect-total-renegotiations", "1",
6643 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006644 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006645 testCases = append(testCases, testCase{
6646 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006647 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006648 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006649 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006650 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6651 NextProtos: []string{"foo"},
6652 },
6653 flags: []string{
6654 "-false-start",
6655 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006656 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006657 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006658 },
6659 shimWritesFirst: true,
6660 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006661
6662 // Client-side renegotiation controls.
6663 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006664 name: "Renegotiate-Client-Forbidden-1",
6665 config: Config{
6666 MaxVersion: VersionTLS12,
6667 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006668 renegotiate: 1,
6669 shouldFail: true,
6670 expectedError: ":NO_RENEGOTIATION:",
6671 expectedLocalError: "remote error: no renegotiation",
6672 })
6673 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006674 name: "Renegotiate-Client-Once-1",
6675 config: Config{
6676 MaxVersion: VersionTLS12,
6677 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006678 renegotiate: 1,
6679 flags: []string{
6680 "-renegotiate-once",
6681 "-expect-total-renegotiations", "1",
6682 },
6683 })
6684 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006685 name: "Renegotiate-Client-Freely-1",
6686 config: Config{
6687 MaxVersion: VersionTLS12,
6688 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006689 renegotiate: 1,
6690 flags: []string{
6691 "-renegotiate-freely",
6692 "-expect-total-renegotiations", "1",
6693 },
6694 })
6695 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006696 name: "Renegotiate-Client-Once-2",
6697 config: Config{
6698 MaxVersion: VersionTLS12,
6699 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006700 renegotiate: 2,
6701 flags: []string{"-renegotiate-once"},
6702 shouldFail: true,
6703 expectedError: ":NO_RENEGOTIATION:",
6704 expectedLocalError: "remote error: no renegotiation",
6705 })
6706 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006707 name: "Renegotiate-Client-Freely-2",
6708 config: Config{
6709 MaxVersion: VersionTLS12,
6710 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006711 renegotiate: 2,
6712 flags: []string{
6713 "-renegotiate-freely",
6714 "-expect-total-renegotiations", "2",
6715 },
6716 })
Adam Langley27a0d082015-11-03 13:34:10 -08006717 testCases = append(testCases, testCase{
6718 name: "Renegotiate-Client-NoIgnore",
6719 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006720 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006721 Bugs: ProtocolBugs{
6722 SendHelloRequestBeforeEveryAppDataRecord: true,
6723 },
6724 },
6725 shouldFail: true,
6726 expectedError: ":NO_RENEGOTIATION:",
6727 })
6728 testCases = append(testCases, testCase{
6729 name: "Renegotiate-Client-Ignore",
6730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006731 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006732 Bugs: ProtocolBugs{
6733 SendHelloRequestBeforeEveryAppDataRecord: true,
6734 },
6735 },
6736 flags: []string{
6737 "-renegotiate-ignore",
6738 "-expect-total-renegotiations", "0",
6739 },
6740 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006741
David Benjamin34941c02016-10-08 11:45:31 -04006742 // Renegotiation is not allowed at SSL 3.0.
6743 testCases = append(testCases, testCase{
6744 name: "Renegotiate-Client-SSL3",
6745 config: Config{
6746 MaxVersion: VersionSSL30,
6747 },
6748 renegotiate: 1,
6749 flags: []string{
6750 "-renegotiate-freely",
6751 "-expect-total-renegotiations", "1",
6752 },
6753 shouldFail: true,
6754 expectedError: ":NO_RENEGOTIATION:",
6755 expectedLocalError: "remote error: no renegotiation",
6756 })
6757
David Benjamina1eaba12017-01-01 23:19:22 -05006758 // Renegotiation is not allowed when there is an unfinished write.
6759 testCases = append(testCases, testCase{
6760 name: "Renegotiate-Client-UnfinishedWrite",
6761 config: Config{
6762 MaxVersion: VersionTLS12,
6763 },
David Benjaminbbba9392017-04-06 12:54:12 -04006764 renegotiate: 1,
6765 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006766 flags: []string{
6767 "-async",
6768 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006769 },
6770 shouldFail: true,
6771 expectedError: ":NO_RENEGOTIATION:",
6772 // We do not successfully send the no_renegotiation alert in
6773 // this case. https://crbug.com/boringssl/130
6774 })
6775
David Benjamin07ab5d42017-02-09 20:11:41 -05006776 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006777 testCases = append(testCases, testCase{
6778 name: "StrayHelloRequest",
6779 config: Config{
6780 MaxVersion: VersionTLS12,
6781 Bugs: ProtocolBugs{
6782 SendHelloRequestBeforeEveryHandshakeMessage: true,
6783 },
6784 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006785 shouldFail: true,
6786 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006787 })
6788 testCases = append(testCases, testCase{
6789 name: "StrayHelloRequest-Packed",
6790 config: Config{
6791 MaxVersion: VersionTLS12,
6792 Bugs: ProtocolBugs{
6793 PackHandshakeFlight: true,
6794 SendHelloRequestBeforeEveryHandshakeMessage: true,
6795 },
6796 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006797 shouldFail: true,
6798 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006799 })
6800
David Benjamin12d2c482016-07-24 10:56:51 -04006801 // Test renegotiation works if HelloRequest and server Finished come in
6802 // the same record.
6803 testCases = append(testCases, testCase{
6804 name: "Renegotiate-Client-Packed",
6805 config: Config{
6806 MaxVersion: VersionTLS12,
6807 Bugs: ProtocolBugs{
6808 PackHandshakeFlight: true,
6809 PackHelloRequestWithFinished: true,
6810 },
6811 },
6812 renegotiate: 1,
6813 flags: []string{
6814 "-renegotiate-freely",
6815 "-expect-total-renegotiations", "1",
6816 },
6817 })
6818
David Benjamin397c8e62016-07-08 14:14:36 -07006819 // Renegotiation is forbidden in TLS 1.3.
6820 testCases = append(testCases, testCase{
6821 name: "Renegotiate-Client-TLS13",
6822 config: Config{
6823 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006824 Bugs: ProtocolBugs{
6825 SendHelloRequestBeforeEveryAppDataRecord: true,
6826 },
David Benjamin397c8e62016-07-08 14:14:36 -07006827 },
David Benjamin397c8e62016-07-08 14:14:36 -07006828 flags: []string{
6829 "-renegotiate-freely",
6830 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006831 shouldFail: true,
6832 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006833 })
6834
6835 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6836 testCases = append(testCases, testCase{
6837 name: "StrayHelloRequest-TLS13",
6838 config: Config{
6839 MaxVersion: VersionTLS13,
6840 Bugs: ProtocolBugs{
6841 SendHelloRequestBeforeEveryHandshakeMessage: true,
6842 },
6843 },
6844 shouldFail: true,
6845 expectedError: ":UNEXPECTED_MESSAGE:",
6846 })
David Benjamind2610042017-01-03 10:49:28 -05006847
6848 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6849 // always reads as supporting it, regardless of whether it was
6850 // negotiated.
6851 testCases = append(testCases, testCase{
6852 name: "AlwaysReportRenegotiationInfo-TLS13",
6853 config: Config{
6854 MaxVersion: VersionTLS13,
6855 Bugs: ProtocolBugs{
6856 NoRenegotiationInfo: true,
6857 },
6858 },
6859 flags: []string{
6860 "-expect-secure-renegotiation",
6861 },
6862 })
David Benjamina58baaf2017-02-28 20:54:28 -05006863
6864 // Certificates may not change on renegotiation.
6865 testCases = append(testCases, testCase{
6866 name: "Renegotiation-CertificateChange",
6867 config: Config{
6868 MaxVersion: VersionTLS12,
6869 Certificates: []Certificate{rsaCertificate},
6870 Bugs: ProtocolBugs{
6871 RenegotiationCertificate: &rsaChainCertificate,
6872 },
6873 },
6874 renegotiate: 1,
6875 flags: []string{"-renegotiate-freely"},
6876 shouldFail: true,
6877 expectedError: ":SERVER_CERT_CHANGED:",
6878 })
6879 testCases = append(testCases, testCase{
6880 name: "Renegotiation-CertificateChange-2",
6881 config: Config{
6882 MaxVersion: VersionTLS12,
6883 Certificates: []Certificate{rsaCertificate},
6884 Bugs: ProtocolBugs{
6885 RenegotiationCertificate: &rsa1024Certificate,
6886 },
6887 },
6888 renegotiate: 1,
6889 flags: []string{"-renegotiate-freely"},
6890 shouldFail: true,
6891 expectedError: ":SERVER_CERT_CHANGED:",
6892 })
David Benjaminbbf42462017-03-14 21:27:10 -04006893
6894 // We do not negotiate ALPN after the initial handshake. This is
6895 // error-prone and only risks bugs in consumers.
6896 testCases = append(testCases, testCase{
6897 testType: clientTest,
6898 name: "Renegotiation-ForbidALPN",
6899 config: Config{
6900 MaxVersion: VersionTLS12,
6901 Bugs: ProtocolBugs{
6902 // Forcibly negotiate ALPN on both initial and
6903 // renegotiation handshakes. The test stack will
6904 // internally check the client does not offer
6905 // it.
6906 SendALPN: "foo",
6907 },
6908 },
6909 flags: []string{
6910 "-advertise-alpn", "\x03foo\x03bar\x03baz",
6911 "-expect-alpn", "foo",
6912 "-renegotiate-freely",
6913 },
6914 renegotiate: 1,
6915 shouldFail: true,
6916 expectedError: ":UNEXPECTED_EXTENSION:",
6917 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006918}
6919
David Benjamin5e961c12014-11-07 01:48:35 -05006920func addDTLSReplayTests() {
6921 // Test that sequence number replays are detected.
6922 testCases = append(testCases, testCase{
6923 protocol: dtls,
6924 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006925 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006926 replayWrites: true,
6927 })
6928
David Benjamin8e6db492015-07-25 18:29:23 -04006929 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006930 // than the retransmit window.
6931 testCases = append(testCases, testCase{
6932 protocol: dtls,
6933 name: "DTLS-Replay-LargeGaps",
6934 config: Config{
6935 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006936 SequenceNumberMapping: func(in uint64) uint64 {
6937 return in * 127
6938 },
David Benjamin5e961c12014-11-07 01:48:35 -05006939 },
6940 },
David Benjamin8e6db492015-07-25 18:29:23 -04006941 messageCount: 200,
6942 replayWrites: true,
6943 })
6944
6945 // Test the incoming sequence number changing non-monotonically.
6946 testCases = append(testCases, testCase{
6947 protocol: dtls,
6948 name: "DTLS-Replay-NonMonotonic",
6949 config: Config{
6950 Bugs: ProtocolBugs{
6951 SequenceNumberMapping: func(in uint64) uint64 {
6952 return in ^ 31
6953 },
6954 },
6955 },
6956 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006957 replayWrites: true,
6958 })
6959}
6960
Nick Harper60edffd2016-06-21 15:19:24 -07006961var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006962 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006963 id signatureAlgorithm
6964 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006965}{
Nick Harper60edffd2016-06-21 15:19:24 -07006966 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6967 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6968 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6969 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006970 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08006971 // The “P256” in the following line is not a mistake. In TLS 1.2 the
6972 // hash function doesn't have to match the curve and so the same
6973 // signature algorithm works with P-224.
6974 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07006975 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6976 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6977 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006978 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6979 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6980 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05006981 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04006982 // Tests for key types prior to TLS 1.2.
6983 {"RSA", 0, testCertRSA},
6984 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006985}
6986
Nick Harper60edffd2016-06-21 15:19:24 -07006987const fakeSigAlg1 signatureAlgorithm = 0x2a01
6988const fakeSigAlg2 signatureAlgorithm = 0xff01
6989
6990func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006991 // Not all ciphers involve a signature. Advertise a list which gives all
6992 // versions a signing cipher.
6993 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006994 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006995 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6996 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6997 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6998 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006999 }
David Benjamin5208fd42016-07-13 21:43:25 -04007000
David Benjaminca3d5452016-07-14 12:51:01 -04007001 var allAlgorithms []signatureAlgorithm
7002 for _, alg := range testSignatureAlgorithms {
7003 if alg.id != 0 {
7004 allAlgorithms = append(allAlgorithms, alg.id)
7005 }
7006 }
7007
Nick Harper60edffd2016-06-21 15:19:24 -07007008 // Make sure each signature algorithm works. Include some fake values in
7009 // the list and ensure they're ignored.
7010 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007011 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007012 if (ver.version < VersionTLS12) != (alg.id == 0) {
7013 continue
7014 }
7015
7016 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7017 // or remove it in C.
7018 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007019 continue
7020 }
Nick Harper60edffd2016-06-21 15:19:24 -07007021
David Benjamin3ef76972016-10-17 17:59:54 -04007022 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007023 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007024 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007025 shouldSignFail = true
7026 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007027 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007028 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007029 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7030 shouldSignFail = true
7031 shouldVerifyFail = true
7032 }
7033 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7034 // the curve has to match the hash size.
7035 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007036 shouldSignFail = true
7037 shouldVerifyFail = true
7038 }
7039
7040 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7041 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7042 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007043 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007044
7045 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007046 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007047 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007048 }
7049 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007050 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007051 }
David Benjamin000800a2014-11-14 01:43:59 -05007052
David Benjamin1fb125c2016-07-08 18:52:12 -07007053 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007054
David Benjamin7a41d372016-07-09 11:21:54 -07007055 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007056 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007057 config: Config{
7058 MaxVersion: ver.version,
7059 ClientAuth: RequireAnyClientCert,
7060 VerifySignatureAlgorithms: []signatureAlgorithm{
7061 fakeSigAlg1,
7062 alg.id,
7063 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007064 },
David Benjamin7a41d372016-07-09 11:21:54 -07007065 },
7066 flags: []string{
7067 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7068 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7069 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007070 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007071 },
David Benjamin3ef76972016-10-17 17:59:54 -04007072 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007073 expectedError: signError,
7074 expectedPeerSignatureAlgorithm: alg.id,
7075 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007076
David Benjamin7a41d372016-07-09 11:21:54 -07007077 testCases = append(testCases, testCase{
7078 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007079 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007080 config: Config{
7081 MaxVersion: ver.version,
7082 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7083 SignSignatureAlgorithms: []signatureAlgorithm{
7084 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007085 },
David Benjamin7a41d372016-07-09 11:21:54 -07007086 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007087 SkipECDSACurveCheck: shouldVerifyFail,
7088 IgnoreSignatureVersionChecks: shouldVerifyFail,
7089 // Some signature algorithms may not be advertised.
7090 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007091 },
David Benjamin7a41d372016-07-09 11:21:54 -07007092 },
7093 flags: []string{
7094 "-require-any-client-certificate",
7095 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7096 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007097 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007098 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007099 // Resume the session to assert the peer signature
7100 // algorithm is reported on both handshakes.
7101 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007102 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007103 expectedError: verifyError,
7104 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007105
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007106 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007107 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007108 testCases = append(testCases, testCase{
7109 testType: serverTest,
7110 name: "ServerAuth-Sign" + suffix,
7111 config: Config{
7112 MaxVersion: ver.version,
7113 CipherSuites: signingCiphers,
7114 VerifySignatureAlgorithms: []signatureAlgorithm{
7115 fakeSigAlg1,
7116 alg.id,
7117 fakeSigAlg2,
7118 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007119 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007120 flags: []string{
7121 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7122 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7123 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007124 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007125 },
7126 shouldFail: shouldSignFail,
7127 expectedError: signError,
7128 expectedPeerSignatureAlgorithm: alg.id,
7129 })
7130 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007131
7132 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007133 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007134 config: Config{
7135 MaxVersion: ver.version,
7136 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007137 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007138 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007139 alg.id,
7140 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007141 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007142 SkipECDSACurveCheck: shouldVerifyFail,
7143 IgnoreSignatureVersionChecks: shouldVerifyFail,
7144 // Some signature algorithms may not be advertised.
7145 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007146 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007147 },
7148 flags: []string{
7149 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7150 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007151 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007152 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007153 // Resume the session to assert the peer signature
7154 // algorithm is reported on both handshakes.
7155 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007156 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007157 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007158 })
David Benjamin5208fd42016-07-13 21:43:25 -04007159
David Benjamin3ef76972016-10-17 17:59:54 -04007160 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007161 testCases = append(testCases, testCase{
7162 testType: serverTest,
7163 name: "ClientAuth-InvalidSignature" + suffix,
7164 config: Config{
7165 MaxVersion: ver.version,
7166 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7167 SignSignatureAlgorithms: []signatureAlgorithm{
7168 alg.id,
7169 },
7170 Bugs: ProtocolBugs{
7171 InvalidSignature: true,
7172 },
7173 },
7174 flags: []string{
7175 "-require-any-client-certificate",
7176 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007177 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007178 },
7179 shouldFail: true,
7180 expectedError: ":BAD_SIGNATURE:",
7181 })
7182
7183 testCases = append(testCases, testCase{
7184 name: "ServerAuth-InvalidSignature" + suffix,
7185 config: Config{
7186 MaxVersion: ver.version,
7187 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7188 CipherSuites: signingCiphers,
7189 SignSignatureAlgorithms: []signatureAlgorithm{
7190 alg.id,
7191 },
7192 Bugs: ProtocolBugs{
7193 InvalidSignature: true,
7194 },
7195 },
David Benjamin69522112017-03-28 15:38:29 -05007196 flags: []string{
7197 "-enable-all-curves",
7198 "-enable-ed25519",
7199 },
David Benjamin5208fd42016-07-13 21:43:25 -04007200 shouldFail: true,
7201 expectedError: ":BAD_SIGNATURE:",
7202 })
7203 }
David Benjaminca3d5452016-07-14 12:51:01 -04007204
David Benjamin3ef76972016-10-17 17:59:54 -04007205 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007206 testCases = append(testCases, testCase{
7207 name: "ClientAuth-Sign-Negotiate" + suffix,
7208 config: Config{
7209 MaxVersion: ver.version,
7210 ClientAuth: RequireAnyClientCert,
7211 VerifySignatureAlgorithms: allAlgorithms,
7212 },
7213 flags: []string{
7214 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7215 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7216 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007217 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007218 "-signing-prefs", strconv.Itoa(int(alg.id)),
7219 },
7220 expectedPeerSignatureAlgorithm: alg.id,
7221 })
7222
7223 testCases = append(testCases, testCase{
7224 testType: serverTest,
7225 name: "ServerAuth-Sign-Negotiate" + suffix,
7226 config: Config{
7227 MaxVersion: ver.version,
7228 CipherSuites: signingCiphers,
7229 VerifySignatureAlgorithms: allAlgorithms,
7230 },
7231 flags: []string{
7232 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7233 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7234 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007235 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007236 "-signing-prefs", strconv.Itoa(int(alg.id)),
7237 },
7238 expectedPeerSignatureAlgorithm: alg.id,
7239 })
7240 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007241 }
David Benjamin000800a2014-11-14 01:43:59 -05007242 }
7243
Nick Harper60edffd2016-06-21 15:19:24 -07007244 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007245 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007246 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007247 config: Config{
7248 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007249 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007250 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007251 signatureECDSAWithP521AndSHA512,
7252 signatureRSAPKCS1WithSHA384,
7253 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007254 },
7255 },
7256 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007257 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7258 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007259 },
Nick Harper60edffd2016-06-21 15:19:24 -07007260 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007261 })
7262
7263 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007264 name: "ClientAuth-SignatureType-TLS13",
7265 config: Config{
7266 ClientAuth: RequireAnyClientCert,
7267 MaxVersion: VersionTLS13,
7268 VerifySignatureAlgorithms: []signatureAlgorithm{
7269 signatureECDSAWithP521AndSHA512,
7270 signatureRSAPKCS1WithSHA384,
7271 signatureRSAPSSWithSHA384,
7272 signatureECDSAWithSHA1,
7273 },
7274 },
7275 flags: []string{
7276 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7277 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7278 },
7279 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7280 })
7281
7282 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007283 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007284 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007286 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007287 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007288 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007289 signatureECDSAWithP521AndSHA512,
7290 signatureRSAPKCS1WithSHA384,
7291 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007292 },
7293 },
Nick Harper60edffd2016-06-21 15:19:24 -07007294 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007295 })
7296
Steven Valdez143e8b32016-07-11 13:19:03 -04007297 testCases = append(testCases, testCase{
7298 testType: serverTest,
7299 name: "ServerAuth-SignatureType-TLS13",
7300 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007301 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007302 VerifySignatureAlgorithms: []signatureAlgorithm{
7303 signatureECDSAWithP521AndSHA512,
7304 signatureRSAPKCS1WithSHA384,
7305 signatureRSAPSSWithSHA384,
7306 signatureECDSAWithSHA1,
7307 },
7308 },
7309 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7310 })
7311
David Benjamina95e9f32016-07-08 16:28:04 -07007312 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007313 testCases = append(testCases, testCase{
7314 testType: serverTest,
7315 name: "Verify-ClientAuth-SignatureType",
7316 config: Config{
7317 MaxVersion: VersionTLS12,
7318 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007319 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007320 signatureRSAPKCS1WithSHA256,
7321 },
7322 Bugs: ProtocolBugs{
7323 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7324 },
7325 },
7326 flags: []string{
7327 "-require-any-client-certificate",
7328 },
7329 shouldFail: true,
7330 expectedError: ":WRONG_SIGNATURE_TYPE:",
7331 })
7332
7333 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007334 testType: serverTest,
7335 name: "Verify-ClientAuth-SignatureType-TLS13",
7336 config: Config{
7337 MaxVersion: VersionTLS13,
7338 Certificates: []Certificate{rsaCertificate},
7339 SignSignatureAlgorithms: []signatureAlgorithm{
7340 signatureRSAPSSWithSHA256,
7341 },
7342 Bugs: ProtocolBugs{
7343 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7344 },
7345 },
7346 flags: []string{
7347 "-require-any-client-certificate",
7348 },
7349 shouldFail: true,
7350 expectedError: ":WRONG_SIGNATURE_TYPE:",
7351 })
7352
7353 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007354 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007355 config: Config{
7356 MaxVersion: VersionTLS12,
7357 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007358 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007359 signatureRSAPKCS1WithSHA256,
7360 },
7361 Bugs: ProtocolBugs{
7362 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":WRONG_SIGNATURE_TYPE:",
7367 })
7368
Steven Valdez143e8b32016-07-11 13:19:03 -04007369 testCases = append(testCases, testCase{
7370 name: "Verify-ServerAuth-SignatureType-TLS13",
7371 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007372 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007373 SignSignatureAlgorithms: []signatureAlgorithm{
7374 signatureRSAPSSWithSHA256,
7375 },
7376 Bugs: ProtocolBugs{
7377 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7378 },
7379 },
7380 shouldFail: true,
7381 expectedError: ":WRONG_SIGNATURE_TYPE:",
7382 })
7383
David Benjamin51dd7d62016-07-08 16:07:01 -07007384 // Test that, if the list is missing, the peer falls back to SHA-1 in
7385 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007386 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007387 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007389 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007390 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007391 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007392 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007393 },
7394 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007395 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007396 },
7397 },
7398 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007399 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7400 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007401 },
7402 })
7403
7404 testCases = append(testCases, testCase{
7405 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007406 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007407 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007408 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007409 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007410 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007411 },
7412 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007413 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007414 },
7415 },
David Benjaminee32bea2016-08-17 13:36:44 -04007416 flags: []string{
7417 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7418 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7419 },
7420 })
7421
7422 testCases = append(testCases, testCase{
7423 name: "ClientAuth-SHA1-Fallback-ECDSA",
7424 config: Config{
7425 MaxVersion: VersionTLS12,
7426 ClientAuth: RequireAnyClientCert,
7427 VerifySignatureAlgorithms: []signatureAlgorithm{
7428 signatureECDSAWithSHA1,
7429 },
7430 Bugs: ProtocolBugs{
7431 NoSignatureAlgorithms: true,
7432 },
7433 },
7434 flags: []string{
7435 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7436 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7437 },
7438 })
7439
7440 testCases = append(testCases, testCase{
7441 testType: serverTest,
7442 name: "ServerAuth-SHA1-Fallback-ECDSA",
7443 config: Config{
7444 MaxVersion: VersionTLS12,
7445 VerifySignatureAlgorithms: []signatureAlgorithm{
7446 signatureECDSAWithSHA1,
7447 },
7448 Bugs: ProtocolBugs{
7449 NoSignatureAlgorithms: true,
7450 },
7451 },
7452 flags: []string{
7453 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7454 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7455 },
David Benjamin000800a2014-11-14 01:43:59 -05007456 })
David Benjamin72dc7832015-03-16 17:49:43 -04007457
David Benjamin51dd7d62016-07-08 16:07:01 -07007458 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007459 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007460 config: Config{
7461 MaxVersion: VersionTLS13,
7462 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007463 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007464 signatureRSAPKCS1WithSHA1,
7465 },
7466 Bugs: ProtocolBugs{
7467 NoSignatureAlgorithms: true,
7468 },
7469 },
7470 flags: []string{
7471 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7472 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7473 },
David Benjamin48901652016-08-01 12:12:47 -04007474 shouldFail: true,
7475 // An empty CertificateRequest signature algorithm list is a
7476 // syntax error in TLS 1.3.
7477 expectedError: ":DECODE_ERROR:",
7478 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007479 })
7480
7481 testCases = append(testCases, testCase{
7482 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007483 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007484 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007485 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007486 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007487 signatureRSAPKCS1WithSHA1,
7488 },
7489 Bugs: ProtocolBugs{
7490 NoSignatureAlgorithms: true,
7491 },
7492 },
7493 shouldFail: true,
7494 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7495 })
7496
David Benjaminb62d2872016-07-18 14:55:02 +02007497 // Test that hash preferences are enforced. BoringSSL does not implement
7498 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007499 testCases = append(testCases, testCase{
7500 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007501 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007503 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007504 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007505 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007506 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007507 },
7508 Bugs: ProtocolBugs{
7509 IgnorePeerSignatureAlgorithmPreferences: true,
7510 },
7511 },
7512 flags: []string{"-require-any-client-certificate"},
7513 shouldFail: true,
7514 expectedError: ":WRONG_SIGNATURE_TYPE:",
7515 })
7516
7517 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007518 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007520 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007522 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007523 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007524 },
7525 Bugs: ProtocolBugs{
7526 IgnorePeerSignatureAlgorithmPreferences: true,
7527 },
7528 },
7529 shouldFail: true,
7530 expectedError: ":WRONG_SIGNATURE_TYPE:",
7531 })
David Benjaminb62d2872016-07-18 14:55:02 +02007532 testCases = append(testCases, testCase{
7533 testType: serverTest,
7534 name: "ClientAuth-Enforced-TLS13",
7535 config: Config{
7536 MaxVersion: VersionTLS13,
7537 Certificates: []Certificate{rsaCertificate},
7538 SignSignatureAlgorithms: []signatureAlgorithm{
7539 signatureRSAPKCS1WithMD5,
7540 },
7541 Bugs: ProtocolBugs{
7542 IgnorePeerSignatureAlgorithmPreferences: true,
7543 IgnoreSignatureVersionChecks: true,
7544 },
7545 },
7546 flags: []string{"-require-any-client-certificate"},
7547 shouldFail: true,
7548 expectedError: ":WRONG_SIGNATURE_TYPE:",
7549 })
7550
7551 testCases = append(testCases, testCase{
7552 name: "ServerAuth-Enforced-TLS13",
7553 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007554 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007555 SignSignatureAlgorithms: []signatureAlgorithm{
7556 signatureRSAPKCS1WithMD5,
7557 },
7558 Bugs: ProtocolBugs{
7559 IgnorePeerSignatureAlgorithmPreferences: true,
7560 IgnoreSignatureVersionChecks: true,
7561 },
7562 },
7563 shouldFail: true,
7564 expectedError: ":WRONG_SIGNATURE_TYPE:",
7565 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007566
7567 // Test that the agreed upon digest respects the client preferences and
7568 // the server digests.
7569 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007570 name: "NoCommonAlgorithms-Digests",
7571 config: Config{
7572 MaxVersion: VersionTLS12,
7573 ClientAuth: RequireAnyClientCert,
7574 VerifySignatureAlgorithms: []signatureAlgorithm{
7575 signatureRSAPKCS1WithSHA512,
7576 signatureRSAPKCS1WithSHA1,
7577 },
7578 },
7579 flags: []string{
7580 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7581 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7582 "-digest-prefs", "SHA256",
7583 },
7584 shouldFail: true,
7585 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7586 })
7587 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007588 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007589 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007590 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007591 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007592 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007593 signatureRSAPKCS1WithSHA512,
7594 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007595 },
7596 },
7597 flags: []string{
7598 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7599 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007600 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007601 },
David Benjaminca3d5452016-07-14 12:51:01 -04007602 shouldFail: true,
7603 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7604 })
7605 testCases = append(testCases, testCase{
7606 name: "NoCommonAlgorithms-TLS13",
7607 config: Config{
7608 MaxVersion: VersionTLS13,
7609 ClientAuth: RequireAnyClientCert,
7610 VerifySignatureAlgorithms: []signatureAlgorithm{
7611 signatureRSAPSSWithSHA512,
7612 signatureRSAPSSWithSHA384,
7613 },
7614 },
7615 flags: []string{
7616 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7617 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7618 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7619 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007620 shouldFail: true,
7621 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007622 })
7623 testCases = append(testCases, testCase{
7624 name: "Agree-Digest-SHA256",
7625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007626 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007627 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007628 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007629 signatureRSAPKCS1WithSHA1,
7630 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007631 },
7632 },
7633 flags: []string{
7634 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7635 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007636 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007637 },
Nick Harper60edffd2016-06-21 15:19:24 -07007638 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007639 })
7640 testCases = append(testCases, testCase{
7641 name: "Agree-Digest-SHA1",
7642 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007643 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007644 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007645 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007646 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007647 },
7648 },
7649 flags: []string{
7650 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7651 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007652 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007653 },
Nick Harper60edffd2016-06-21 15:19:24 -07007654 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007655 })
7656 testCases = append(testCases, testCase{
7657 name: "Agree-Digest-Default",
7658 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007659 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007660 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007661 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007662 signatureRSAPKCS1WithSHA256,
7663 signatureECDSAWithP256AndSHA256,
7664 signatureRSAPKCS1WithSHA1,
7665 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007666 },
7667 },
7668 flags: []string{
7669 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7670 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7671 },
Nick Harper60edffd2016-06-21 15:19:24 -07007672 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007673 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007674
David Benjaminca3d5452016-07-14 12:51:01 -04007675 // Test that the signing preference list may include extra algorithms
7676 // without negotiation problems.
7677 testCases = append(testCases, testCase{
7678 testType: serverTest,
7679 name: "FilterExtraAlgorithms",
7680 config: Config{
7681 MaxVersion: VersionTLS12,
7682 VerifySignatureAlgorithms: []signatureAlgorithm{
7683 signatureRSAPKCS1WithSHA256,
7684 },
7685 },
7686 flags: []string{
7687 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7688 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7689 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7690 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7691 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7692 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7693 },
7694 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7695 })
7696
David Benjamin4c3ddf72016-06-29 18:13:53 -04007697 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7698 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007699 testCases = append(testCases, testCase{
7700 name: "CheckLeafCurve",
7701 config: Config{
7702 MaxVersion: VersionTLS12,
7703 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007704 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007705 },
7706 flags: []string{"-p384-only"},
7707 shouldFail: true,
7708 expectedError: ":BAD_ECC_CERT:",
7709 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007710
7711 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7712 testCases = append(testCases, testCase{
7713 name: "CheckLeafCurve-TLS13",
7714 config: Config{
7715 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007716 Certificates: []Certificate{ecdsaP256Certificate},
7717 },
7718 flags: []string{"-p384-only"},
7719 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007720
7721 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7722 testCases = append(testCases, testCase{
7723 name: "ECDSACurveMismatch-Verify-TLS12",
7724 config: Config{
7725 MaxVersion: VersionTLS12,
7726 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7727 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007728 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007729 signatureECDSAWithP384AndSHA384,
7730 },
7731 },
7732 })
7733
7734 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7735 testCases = append(testCases, testCase{
7736 name: "ECDSACurveMismatch-Verify-TLS13",
7737 config: Config{
7738 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007739 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007740 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007741 signatureECDSAWithP384AndSHA384,
7742 },
7743 Bugs: ProtocolBugs{
7744 SkipECDSACurveCheck: true,
7745 },
7746 },
7747 shouldFail: true,
7748 expectedError: ":WRONG_SIGNATURE_TYPE:",
7749 })
7750
7751 // Signature algorithm selection in TLS 1.3 should take the curve into
7752 // account.
7753 testCases = append(testCases, testCase{
7754 testType: serverTest,
7755 name: "ECDSACurveMismatch-Sign-TLS13",
7756 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007757 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007758 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007759 signatureECDSAWithP384AndSHA384,
7760 signatureECDSAWithP256AndSHA256,
7761 },
7762 },
7763 flags: []string{
7764 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7765 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7766 },
7767 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7768 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007769
7770 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7771 // server does not attempt to sign in that case.
7772 testCases = append(testCases, testCase{
7773 testType: serverTest,
7774 name: "RSA-PSS-Large",
7775 config: Config{
7776 MaxVersion: VersionTLS13,
7777 VerifySignatureAlgorithms: []signatureAlgorithm{
7778 signatureRSAPSSWithSHA512,
7779 },
7780 },
7781 flags: []string{
7782 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7783 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7784 },
7785 shouldFail: true,
7786 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7787 })
David Benjamin57e929f2016-08-30 00:30:38 -04007788
7789 // Test that RSA-PSS is enabled by default for TLS 1.2.
7790 testCases = append(testCases, testCase{
7791 testType: clientTest,
7792 name: "RSA-PSS-Default-Verify",
7793 config: Config{
7794 MaxVersion: VersionTLS12,
7795 SignSignatureAlgorithms: []signatureAlgorithm{
7796 signatureRSAPSSWithSHA256,
7797 },
7798 },
7799 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7800 })
7801
7802 testCases = append(testCases, testCase{
7803 testType: serverTest,
7804 name: "RSA-PSS-Default-Sign",
7805 config: Config{
7806 MaxVersion: VersionTLS12,
7807 VerifySignatureAlgorithms: []signatureAlgorithm{
7808 signatureRSAPSSWithSHA256,
7809 },
7810 },
7811 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7812 })
David Benjamin69522112017-03-28 15:38:29 -05007813
7814 // TLS 1.1 and below has no way to advertise support for or negotiate
7815 // Ed25519's signature algorithm.
7816 testCases = append(testCases, testCase{
7817 testType: clientTest,
7818 name: "NoEd25519-TLS11-ServerAuth-Verify",
7819 config: Config{
7820 MaxVersion: VersionTLS11,
7821 Certificates: []Certificate{ed25519Certificate},
7822 Bugs: ProtocolBugs{
7823 // Sign with Ed25519 even though it is TLS 1.1.
7824 UseLegacySigningAlgorithm: signatureEd25519,
7825 },
7826 },
7827 flags: []string{"-enable-ed25519"},
7828 shouldFail: true,
7829 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7830 })
7831 testCases = append(testCases, testCase{
7832 testType: serverTest,
7833 name: "NoEd25519-TLS11-ServerAuth-Sign",
7834 config: Config{
7835 MaxVersion: VersionTLS11,
7836 },
7837 flags: []string{
7838 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7839 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7840 },
7841 shouldFail: true,
7842 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7843 })
7844 testCases = append(testCases, testCase{
7845 testType: serverTest,
7846 name: "NoEd25519-TLS11-ClientAuth-Verify",
7847 config: Config{
7848 MaxVersion: VersionTLS11,
7849 Certificates: []Certificate{ed25519Certificate},
7850 Bugs: ProtocolBugs{
7851 // Sign with Ed25519 even though it is TLS 1.1.
7852 UseLegacySigningAlgorithm: signatureEd25519,
7853 },
7854 },
7855 flags: []string{
7856 "-enable-ed25519",
7857 "-require-any-client-certificate",
7858 },
7859 shouldFail: true,
7860 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7861 })
7862 testCases = append(testCases, testCase{
7863 testType: clientTest,
7864 name: "NoEd25519-TLS11-ClientAuth-Sign",
7865 config: Config{
7866 MaxVersion: VersionTLS11,
7867 ClientAuth: RequireAnyClientCert,
7868 },
7869 flags: []string{
7870 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7871 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7872 },
7873 shouldFail: true,
7874 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7875 })
7876
7877 // Test Ed25519 is not advertised by default.
7878 testCases = append(testCases, testCase{
7879 testType: clientTest,
7880 name: "Ed25519DefaultDisable-NoAdvertise",
7881 config: Config{
7882 Certificates: []Certificate{ed25519Certificate},
7883 },
7884 shouldFail: true,
7885 expectedLocalError: "tls: no common signature algorithms",
7886 })
7887
7888 // Test Ed25519, when disabled, is not accepted if the peer ignores our
7889 // preferences.
7890 testCases = append(testCases, testCase{
7891 testType: clientTest,
7892 name: "Ed25519DefaultDisable-NoAccept",
7893 config: Config{
7894 Certificates: []Certificate{ed25519Certificate},
7895 Bugs: ProtocolBugs{
7896 IgnorePeerSignatureAlgorithmPreferences: true,
7897 },
7898 },
7899 shouldFail: true,
7900 expectedLocalError: "remote error: illegal parameter",
7901 expectedError: ":WRONG_SIGNATURE_TYPE:",
7902 })
David Benjamin71c21b42017-04-14 17:05:40 -04007903
7904 // Test that configuring verify preferences changes what the client
7905 // advertises.
7906 testCases = append(testCases, testCase{
7907 name: "VerifyPreferences-Advertised",
7908 config: Config{
7909 Certificates: []Certificate{rsaCertificate},
7910 SignSignatureAlgorithms: []signatureAlgorithm{
7911 signatureRSAPSSWithSHA256,
7912 signatureRSAPSSWithSHA384,
7913 signatureRSAPSSWithSHA512,
7914 },
7915 },
7916 flags: []string{
7917 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7918 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7919 },
7920 })
7921
7922 // Test that the client advertises a set which the runner can find
7923 // nothing in common with.
7924 testCases = append(testCases, testCase{
7925 name: "VerifyPreferences-NoCommonAlgorithms",
7926 config: Config{
7927 Certificates: []Certificate{rsaCertificate},
7928 SignSignatureAlgorithms: []signatureAlgorithm{
7929 signatureRSAPSSWithSHA256,
7930 signatureRSAPSSWithSHA512,
7931 },
7932 },
7933 flags: []string{
7934 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7935 },
7936 shouldFail: true,
7937 expectedLocalError: "tls: no common signature algorithms",
7938 })
7939
7940 // Test that the client enforces its preferences when configured.
7941 testCases = append(testCases, testCase{
7942 name: "VerifyPreferences-Enforced",
7943 config: Config{
7944 Certificates: []Certificate{rsaCertificate},
7945 SignSignatureAlgorithms: []signatureAlgorithm{
7946 signatureRSAPSSWithSHA256,
7947 signatureRSAPSSWithSHA512,
7948 },
7949 Bugs: ProtocolBugs{
7950 IgnorePeerSignatureAlgorithmPreferences: true,
7951 },
7952 },
7953 flags: []string{
7954 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7955 },
7956 shouldFail: true,
7957 expectedLocalError: "remote error: illegal parameter",
7958 expectedError: ":WRONG_SIGNATURE_TYPE:",
7959 })
7960
7961 // Test that explicitly configuring Ed25519 is as good as changing the
7962 // boolean toggle.
7963 testCases = append(testCases, testCase{
7964 name: "VerifyPreferences-Ed25519",
7965 config: Config{
7966 Certificates: []Certificate{ed25519Certificate},
7967 },
7968 flags: []string{
7969 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
7970 },
7971 })
David Benjamin000800a2014-11-14 01:43:59 -05007972}
7973
David Benjamin83f90402015-01-27 01:09:43 -05007974// timeouts is the retransmit schedule for BoringSSL. It doubles and
7975// caps at 60 seconds. On the 13th timeout, it gives up.
7976var timeouts = []time.Duration{
7977 1 * time.Second,
7978 2 * time.Second,
7979 4 * time.Second,
7980 8 * time.Second,
7981 16 * time.Second,
7982 32 * time.Second,
7983 60 * time.Second,
7984 60 * time.Second,
7985 60 * time.Second,
7986 60 * time.Second,
7987 60 * time.Second,
7988 60 * time.Second,
7989 60 * time.Second,
7990}
7991
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007992// shortTimeouts is an alternate set of timeouts which would occur if the
7993// initial timeout duration was set to 250ms.
7994var shortTimeouts = []time.Duration{
7995 250 * time.Millisecond,
7996 500 * time.Millisecond,
7997 1 * time.Second,
7998 2 * time.Second,
7999 4 * time.Second,
8000 8 * time.Second,
8001 16 * time.Second,
8002 32 * time.Second,
8003 60 * time.Second,
8004 60 * time.Second,
8005 60 * time.Second,
8006 60 * time.Second,
8007 60 * time.Second,
8008}
8009
David Benjamin83f90402015-01-27 01:09:43 -05008010func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008011 // These tests work by coordinating some behavior on both the shim and
8012 // the runner.
8013 //
8014 // TimeoutSchedule configures the runner to send a series of timeout
8015 // opcodes to the shim (see packetAdaptor) immediately before reading
8016 // each peer handshake flight N. The timeout opcode both simulates a
8017 // timeout in the shim and acts as a synchronization point to help the
8018 // runner bracket each handshake flight.
8019 //
8020 // We assume the shim does not read from the channel eagerly. It must
8021 // first wait until it has sent flight N and is ready to receive
8022 // handshake flight N+1. At this point, it will process the timeout
8023 // opcode. It must then immediately respond with a timeout ACK and act
8024 // as if the shim was idle for the specified amount of time.
8025 //
8026 // The runner then drops all packets received before the ACK and
8027 // continues waiting for flight N. This ordering results in one attempt
8028 // at sending flight N to be dropped. For the test to complete, the
8029 // shim must send flight N again, testing that the shim implements DTLS
8030 // retransmit on a timeout.
8031
Steven Valdez143e8b32016-07-11 13:19:03 -04008032 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008033 // likely be more epochs to cross and the final message's retransmit may
8034 // be more complex.
8035
David Benjamin11c82892017-02-23 20:40:31 -05008036 // Test that this is indeed the timeout schedule. Stress all
8037 // four patterns of handshake.
8038 for i := 1; i < len(timeouts); i++ {
8039 number := strconv.Itoa(i)
8040 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008041 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008042 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008043 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008044 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008045 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008046 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008047 },
8048 },
8049 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008050 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008051 })
David Benjamin11c82892017-02-23 20:40:31 -05008052 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008053 protocol: dtls,
8054 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008055 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008057 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008058 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008059 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008060 },
8061 },
8062 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008063 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008064 })
8065 }
David Benjamin11c82892017-02-23 20:40:31 -05008066
8067 // Test that exceeding the timeout schedule hits a read
8068 // timeout.
8069 testCases = append(testCases, testCase{
8070 protocol: dtls,
8071 name: "DTLS-Retransmit-Timeout",
8072 config: Config{
8073 MaxVersion: VersionTLS12,
8074 Bugs: ProtocolBugs{
8075 TimeoutSchedule: timeouts,
8076 },
8077 },
8078 resumeSession: true,
8079 flags: []string{"-async"},
8080 shouldFail: true,
8081 expectedError: ":READ_TIMEOUT_EXPIRED:",
8082 })
8083
8084 // Test that timeout handling has a fudge factor, due to API
8085 // problems.
8086 testCases = append(testCases, testCase{
8087 protocol: dtls,
8088 name: "DTLS-Retransmit-Fudge",
8089 config: Config{
8090 MaxVersion: VersionTLS12,
8091 Bugs: ProtocolBugs{
8092 TimeoutSchedule: []time.Duration{
8093 timeouts[0] - 10*time.Millisecond,
8094 },
8095 },
8096 },
8097 resumeSession: true,
8098 flags: []string{"-async"},
8099 })
8100
8101 // Test that the final Finished retransmitting isn't
8102 // duplicated if the peer badly fragments everything.
8103 testCases = append(testCases, testCase{
8104 testType: serverTest,
8105 protocol: dtls,
8106 name: "DTLS-Retransmit-Fragmented",
8107 config: Config{
8108 MaxVersion: VersionTLS12,
8109 Bugs: ProtocolBugs{
8110 TimeoutSchedule: []time.Duration{timeouts[0]},
8111 MaxHandshakeRecordLength: 2,
8112 },
8113 },
8114 flags: []string{"-async"},
8115 })
8116
8117 // Test the timeout schedule when a shorter initial timeout duration is set.
8118 testCases = append(testCases, testCase{
8119 protocol: dtls,
8120 name: "DTLS-Retransmit-Short-Client",
8121 config: Config{
8122 MaxVersion: VersionTLS12,
8123 Bugs: ProtocolBugs{
8124 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8125 },
8126 },
8127 resumeSession: true,
8128 flags: []string{
8129 "-async",
8130 "-initial-timeout-duration-ms", "250",
8131 },
8132 })
8133 testCases = append(testCases, testCase{
8134 protocol: dtls,
8135 testType: serverTest,
8136 name: "DTLS-Retransmit-Short-Server",
8137 config: Config{
8138 MaxVersion: VersionTLS12,
8139 Bugs: ProtocolBugs{
8140 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8141 },
8142 },
8143 resumeSession: true,
8144 flags: []string{
8145 "-async",
8146 "-initial-timeout-duration-ms", "250",
8147 },
8148 })
David Benjamin83f90402015-01-27 01:09:43 -05008149}
8150
David Benjaminc565ebb2015-04-03 04:06:36 -04008151func addExportKeyingMaterialTests() {
8152 for _, vers := range tlsVersions {
8153 if vers.version == VersionSSL30 {
8154 continue
8155 }
8156 testCases = append(testCases, testCase{
8157 name: "ExportKeyingMaterial-" + vers.name,
8158 config: Config{
8159 MaxVersion: vers.version,
8160 },
8161 exportKeyingMaterial: 1024,
8162 exportLabel: "label",
8163 exportContext: "context",
8164 useExportContext: true,
8165 })
8166 testCases = append(testCases, testCase{
8167 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8168 config: Config{
8169 MaxVersion: vers.version,
8170 },
8171 exportKeyingMaterial: 1024,
8172 })
8173 testCases = append(testCases, testCase{
8174 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8175 config: Config{
8176 MaxVersion: vers.version,
8177 },
8178 exportKeyingMaterial: 1024,
8179 useExportContext: true,
8180 })
8181 testCases = append(testCases, testCase{
8182 name: "ExportKeyingMaterial-Small-" + vers.name,
8183 config: Config{
8184 MaxVersion: vers.version,
8185 },
8186 exportKeyingMaterial: 1,
8187 exportLabel: "label",
8188 exportContext: "context",
8189 useExportContext: true,
8190 })
8191 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008192
David Benjaminc565ebb2015-04-03 04:06:36 -04008193 testCases = append(testCases, testCase{
8194 name: "ExportKeyingMaterial-SSL3",
8195 config: Config{
8196 MaxVersion: VersionSSL30,
8197 },
8198 exportKeyingMaterial: 1024,
8199 exportLabel: "label",
8200 exportContext: "context",
8201 useExportContext: true,
8202 shouldFail: true,
8203 expectedError: "failed to export keying material",
8204 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008205
8206 // Exporters work during a False Start.
8207 testCases = append(testCases, testCase{
8208 name: "ExportKeyingMaterial-FalseStart",
8209 config: Config{
8210 MaxVersion: VersionTLS12,
8211 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8212 NextProtos: []string{"foo"},
8213 Bugs: ProtocolBugs{
8214 ExpectFalseStart: true,
8215 },
8216 },
8217 flags: []string{
8218 "-false-start",
8219 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008220 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008221 },
8222 shimWritesFirst: true,
8223 exportKeyingMaterial: 1024,
8224 exportLabel: "label",
8225 exportContext: "context",
8226 useExportContext: true,
8227 })
8228
8229 // Exporters do not work in the middle of a renegotiation. Test this by
8230 // triggering the exporter after every SSL_read call and configuring the
8231 // shim to run asynchronously.
8232 testCases = append(testCases, testCase{
8233 name: "ExportKeyingMaterial-Renegotiate",
8234 config: Config{
8235 MaxVersion: VersionTLS12,
8236 },
8237 renegotiate: 1,
8238 flags: []string{
8239 "-async",
8240 "-use-exporter-between-reads",
8241 "-renegotiate-freely",
8242 "-expect-total-renegotiations", "1",
8243 },
8244 shouldFail: true,
8245 expectedError: "failed to export keying material",
8246 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008247}
8248
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008249func addTLSUniqueTests() {
8250 for _, isClient := range []bool{false, true} {
8251 for _, isResumption := range []bool{false, true} {
8252 for _, hasEMS := range []bool{false, true} {
8253 var suffix string
8254 if isResumption {
8255 suffix = "Resume-"
8256 } else {
8257 suffix = "Full-"
8258 }
8259
8260 if hasEMS {
8261 suffix += "EMS-"
8262 } else {
8263 suffix += "NoEMS-"
8264 }
8265
8266 if isClient {
8267 suffix += "Client"
8268 } else {
8269 suffix += "Server"
8270 }
8271
8272 test := testCase{
8273 name: "TLSUnique-" + suffix,
8274 testTLSUnique: true,
8275 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008276 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008277 Bugs: ProtocolBugs{
8278 NoExtendedMasterSecret: !hasEMS,
8279 },
8280 },
8281 }
8282
8283 if isResumption {
8284 test.resumeSession = true
8285 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008286 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008287 Bugs: ProtocolBugs{
8288 NoExtendedMasterSecret: !hasEMS,
8289 },
8290 }
8291 }
8292
8293 if isResumption && !hasEMS {
8294 test.shouldFail = true
8295 test.expectedError = "failed to get tls-unique"
8296 }
8297
8298 testCases = append(testCases, test)
8299 }
8300 }
8301 }
8302}
8303
Adam Langley09505632015-07-30 18:10:13 -07008304func addCustomExtensionTests() {
8305 expectedContents := "custom extension"
8306 emptyString := ""
8307
8308 for _, isClient := range []bool{false, true} {
8309 suffix := "Server"
8310 flag := "-enable-server-custom-extension"
8311 testType := serverTest
8312 if isClient {
8313 suffix = "Client"
8314 flag = "-enable-client-custom-extension"
8315 testType = clientTest
8316 }
8317
8318 testCases = append(testCases, testCase{
8319 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008320 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008322 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008323 Bugs: ProtocolBugs{
8324 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008325 ExpectedCustomExtension: &expectedContents,
8326 },
8327 },
8328 flags: []string{flag},
8329 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008330 testCases = append(testCases, testCase{
8331 testType: testType,
8332 name: "CustomExtensions-" + suffix + "-TLS13",
8333 config: Config{
8334 MaxVersion: VersionTLS13,
8335 Bugs: ProtocolBugs{
8336 CustomExtension: expectedContents,
8337 ExpectedCustomExtension: &expectedContents,
8338 },
8339 },
8340 flags: []string{flag},
8341 })
Adam Langley09505632015-07-30 18:10:13 -07008342
Steven Valdez2a070722017-03-25 20:54:16 -05008343 // 0-RTT is not currently supported with Custom Extensions.
8344 testCases = append(testCases, testCase{
8345 testType: testType,
8346 name: "CustomExtensions-" + suffix + "-EarlyData",
8347 config: Config{
8348 MaxVersion: VersionTLS13,
8349 Bugs: ProtocolBugs{
8350 CustomExtension: expectedContents,
8351 ExpectedCustomExtension: &expectedContents,
8352 },
8353 },
8354 shouldFail: true,
8355 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8356 flags: []string{flag, "-enable-early-data"},
8357 })
8358
Adam Langley09505632015-07-30 18:10:13 -07008359 // If the parse callback fails, the handshake should also fail.
8360 testCases = append(testCases, testCase{
8361 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008362 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008364 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008365 Bugs: ProtocolBugs{
8366 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008367 ExpectedCustomExtension: &expectedContents,
8368 },
8369 },
David Benjamin399e7c92015-07-30 23:01:27 -04008370 flags: []string{flag},
8371 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008372 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8373 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008374 testCases = append(testCases, testCase{
8375 testType: testType,
8376 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8377 config: Config{
8378 MaxVersion: VersionTLS13,
8379 Bugs: ProtocolBugs{
8380 CustomExtension: expectedContents + "foo",
8381 ExpectedCustomExtension: &expectedContents,
8382 },
8383 },
8384 flags: []string{flag},
8385 shouldFail: true,
8386 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8387 })
Adam Langley09505632015-07-30 18:10:13 -07008388
8389 // If the add callback fails, the handshake should also fail.
8390 testCases = append(testCases, testCase{
8391 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008392 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008394 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008395 Bugs: ProtocolBugs{
8396 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008397 ExpectedCustomExtension: &expectedContents,
8398 },
8399 },
David Benjamin399e7c92015-07-30 23:01:27 -04008400 flags: []string{flag, "-custom-extension-fail-add"},
8401 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008402 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8403 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008404 testCases = append(testCases, testCase{
8405 testType: testType,
8406 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8407 config: Config{
8408 MaxVersion: VersionTLS13,
8409 Bugs: ProtocolBugs{
8410 CustomExtension: expectedContents,
8411 ExpectedCustomExtension: &expectedContents,
8412 },
8413 },
8414 flags: []string{flag, "-custom-extension-fail-add"},
8415 shouldFail: true,
8416 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8417 })
Adam Langley09505632015-07-30 18:10:13 -07008418
8419 // If the add callback returns zero, no extension should be
8420 // added.
8421 skipCustomExtension := expectedContents
8422 if isClient {
8423 // For the case where the client skips sending the
8424 // custom extension, the server must not “echo” it.
8425 skipCustomExtension = ""
8426 }
8427 testCases = append(testCases, testCase{
8428 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008429 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008431 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008432 Bugs: ProtocolBugs{
8433 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008434 ExpectedCustomExtension: &emptyString,
8435 },
8436 },
8437 flags: []string{flag, "-custom-extension-skip"},
8438 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008439 testCases = append(testCases, testCase{
8440 testType: testType,
8441 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8442 config: Config{
8443 MaxVersion: VersionTLS13,
8444 Bugs: ProtocolBugs{
8445 CustomExtension: skipCustomExtension,
8446 ExpectedCustomExtension: &emptyString,
8447 },
8448 },
8449 flags: []string{flag, "-custom-extension-skip"},
8450 })
Adam Langley09505632015-07-30 18:10:13 -07008451 }
8452
8453 // The custom extension add callback should not be called if the client
8454 // doesn't send the extension.
8455 testCases = append(testCases, testCase{
8456 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008457 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008459 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008460 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008461 ExpectedCustomExtension: &emptyString,
8462 },
8463 },
8464 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8465 })
Adam Langley2deb9842015-08-07 11:15:37 -07008466
Steven Valdez143e8b32016-07-11 13:19:03 -04008467 testCases = append(testCases, testCase{
8468 testType: serverTest,
8469 name: "CustomExtensions-NotCalled-Server-TLS13",
8470 config: Config{
8471 MaxVersion: VersionTLS13,
8472 Bugs: ProtocolBugs{
8473 ExpectedCustomExtension: &emptyString,
8474 },
8475 },
8476 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8477 })
8478
Adam Langley2deb9842015-08-07 11:15:37 -07008479 // Test an unknown extension from the server.
8480 testCases = append(testCases, testCase{
8481 testType: clientTest,
8482 name: "UnknownExtension-Client",
8483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008484 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008485 Bugs: ProtocolBugs{
8486 CustomExtension: expectedContents,
8487 },
8488 },
David Benjamin0c40a962016-08-01 12:05:50 -04008489 shouldFail: true,
8490 expectedError: ":UNEXPECTED_EXTENSION:",
8491 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008492 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008493 testCases = append(testCases, testCase{
8494 testType: clientTest,
8495 name: "UnknownExtension-Client-TLS13",
8496 config: Config{
8497 MaxVersion: VersionTLS13,
8498 Bugs: ProtocolBugs{
8499 CustomExtension: expectedContents,
8500 },
8501 },
David Benjamin0c40a962016-08-01 12:05:50 -04008502 shouldFail: true,
8503 expectedError: ":UNEXPECTED_EXTENSION:",
8504 expectedLocalError: "remote error: unsupported extension",
8505 })
David Benjamin490469f2016-10-05 22:44:38 -04008506 testCases = append(testCases, testCase{
8507 testType: clientTest,
8508 name: "UnknownUnencryptedExtension-Client-TLS13",
8509 config: Config{
8510 MaxVersion: VersionTLS13,
8511 Bugs: ProtocolBugs{
8512 CustomUnencryptedExtension: expectedContents,
8513 },
8514 },
8515 shouldFail: true,
8516 expectedError: ":UNEXPECTED_EXTENSION:",
8517 // The shim must send an alert, but alerts at this point do not
8518 // get successfully decrypted by the runner.
8519 expectedLocalError: "local error: bad record MAC",
8520 })
8521 testCases = append(testCases, testCase{
8522 testType: clientTest,
8523 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8524 config: Config{
8525 MaxVersion: VersionTLS13,
8526 Bugs: ProtocolBugs{
8527 SendUnencryptedALPN: "foo",
8528 },
8529 },
8530 flags: []string{
8531 "-advertise-alpn", "\x03foo\x03bar",
8532 },
8533 shouldFail: true,
8534 expectedError: ":UNEXPECTED_EXTENSION:",
8535 // The shim must send an alert, but alerts at this point do not
8536 // get successfully decrypted by the runner.
8537 expectedLocalError: "local error: bad record MAC",
8538 })
David Benjamin0c40a962016-08-01 12:05:50 -04008539
8540 // Test a known but unoffered extension from the server.
8541 testCases = append(testCases, testCase{
8542 testType: clientTest,
8543 name: "UnofferedExtension-Client",
8544 config: Config{
8545 MaxVersion: VersionTLS12,
8546 Bugs: ProtocolBugs{
8547 SendALPN: "alpn",
8548 },
8549 },
8550 shouldFail: true,
8551 expectedError: ":UNEXPECTED_EXTENSION:",
8552 expectedLocalError: "remote error: unsupported extension",
8553 })
8554 testCases = append(testCases, testCase{
8555 testType: clientTest,
8556 name: "UnofferedExtension-Client-TLS13",
8557 config: Config{
8558 MaxVersion: VersionTLS13,
8559 Bugs: ProtocolBugs{
8560 SendALPN: "alpn",
8561 },
8562 },
8563 shouldFail: true,
8564 expectedError: ":UNEXPECTED_EXTENSION:",
8565 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008566 })
Adam Langley09505632015-07-30 18:10:13 -07008567}
8568
David Benjaminb36a3952015-12-01 18:53:13 -05008569func addRSAClientKeyExchangeTests() {
8570 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8571 testCases = append(testCases, testCase{
8572 testType: serverTest,
8573 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8574 config: Config{
8575 // Ensure the ClientHello version and final
8576 // version are different, to detect if the
8577 // server uses the wrong one.
8578 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008579 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008580 Bugs: ProtocolBugs{
8581 BadRSAClientKeyExchange: bad,
8582 },
8583 },
8584 shouldFail: true,
8585 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8586 })
8587 }
David Benjamine63d9d72016-09-19 18:27:34 -04008588
8589 // The server must compare whatever was in ClientHello.version for the
8590 // RSA premaster.
8591 testCases = append(testCases, testCase{
8592 testType: serverTest,
8593 name: "SendClientVersion-RSA",
8594 config: Config{
8595 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8596 Bugs: ProtocolBugs{
8597 SendClientVersion: 0x1234,
8598 },
8599 },
8600 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8601 })
David Benjaminb36a3952015-12-01 18:53:13 -05008602}
8603
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008604var testCurves = []struct {
8605 name string
8606 id CurveID
8607}{
Adam Langley764ab982017-03-10 18:01:30 -08008608 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008609 {"P-256", CurveP256},
8610 {"P-384", CurveP384},
8611 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008612 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008613}
8614
Steven Valdez5440fe02016-07-18 12:40:30 -04008615const bogusCurve = 0x1234
8616
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008617func addCurveTests() {
8618 for _, curve := range testCurves {
8619 testCases = append(testCases, testCase{
8620 name: "CurveTest-Client-" + curve.name,
8621 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008622 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8624 CurvePreferences: []CurveID{curve.id},
8625 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008626 flags: []string{
8627 "-enable-all-curves",
8628 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8629 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008630 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008631 })
8632 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008633 name: "CurveTest-Client-" + curve.name + "-TLS13",
8634 config: Config{
8635 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008636 CurvePreferences: []CurveID{curve.id},
8637 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008638 flags: []string{
8639 "-enable-all-curves",
8640 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8641 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008642 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008643 })
8644 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008645 testType: serverTest,
8646 name: "CurveTest-Server-" + curve.name,
8647 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008648 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008649 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8650 CurvePreferences: []CurveID{curve.id},
8651 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008652 flags: []string{
8653 "-enable-all-curves",
8654 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8655 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008656 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008657 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008658 testCases = append(testCases, testCase{
8659 testType: serverTest,
8660 name: "CurveTest-Server-" + curve.name + "-TLS13",
8661 config: Config{
8662 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008663 CurvePreferences: []CurveID{curve.id},
8664 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008665 flags: []string{
8666 "-enable-all-curves",
8667 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8668 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008669 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008670 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008671 }
David Benjamin241ae832016-01-15 03:04:54 -05008672
8673 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008674 testCases = append(testCases, testCase{
8675 testType: serverTest,
8676 name: "UnknownCurve",
8677 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008678 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008679 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8680 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8681 },
8682 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008683
Steven Valdez803c77a2016-09-06 14:13:43 -04008684 // The server must be tolerant to bogus curves.
8685 testCases = append(testCases, testCase{
8686 testType: serverTest,
8687 name: "UnknownCurve-TLS13",
8688 config: Config{
8689 MaxVersion: VersionTLS13,
8690 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8691 },
8692 })
8693
David Benjamin4c3ddf72016-06-29 18:13:53 -04008694 // The server must not consider ECDHE ciphers when there are no
8695 // supported curves.
8696 testCases = append(testCases, testCase{
8697 testType: serverTest,
8698 name: "NoSupportedCurves",
8699 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008700 MaxVersion: VersionTLS12,
8701 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8702 Bugs: ProtocolBugs{
8703 NoSupportedCurves: true,
8704 },
8705 },
8706 shouldFail: true,
8707 expectedError: ":NO_SHARED_CIPHER:",
8708 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008709 testCases = append(testCases, testCase{
8710 testType: serverTest,
8711 name: "NoSupportedCurves-TLS13",
8712 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008713 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008714 Bugs: ProtocolBugs{
8715 NoSupportedCurves: true,
8716 },
8717 },
8718 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008719 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008720 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008721
8722 // The server must fall back to another cipher when there are no
8723 // supported curves.
8724 testCases = append(testCases, testCase{
8725 testType: serverTest,
8726 name: "NoCommonCurves",
8727 config: Config{
8728 MaxVersion: VersionTLS12,
8729 CipherSuites: []uint16{
8730 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008731 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008732 },
8733 CurvePreferences: []CurveID{CurveP224},
8734 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008735 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008736 })
8737
8738 // The client must reject bogus curves and disabled curves.
8739 testCases = append(testCases, testCase{
8740 name: "BadECDHECurve",
8741 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008742 MaxVersion: VersionTLS12,
8743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8744 Bugs: ProtocolBugs{
8745 SendCurve: bogusCurve,
8746 },
8747 },
8748 shouldFail: true,
8749 expectedError: ":WRONG_CURVE:",
8750 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008751 testCases = append(testCases, testCase{
8752 name: "BadECDHECurve-TLS13",
8753 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008754 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008755 Bugs: ProtocolBugs{
8756 SendCurve: bogusCurve,
8757 },
8758 },
8759 shouldFail: true,
8760 expectedError: ":WRONG_CURVE:",
8761 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008762
8763 testCases = append(testCases, testCase{
8764 name: "UnsupportedCurve",
8765 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008766 MaxVersion: VersionTLS12,
8767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8768 CurvePreferences: []CurveID{CurveP256},
8769 Bugs: ProtocolBugs{
8770 IgnorePeerCurvePreferences: true,
8771 },
8772 },
8773 flags: []string{"-p384-only"},
8774 shouldFail: true,
8775 expectedError: ":WRONG_CURVE:",
8776 })
8777
David Benjamin4f921572016-07-17 14:20:10 +02008778 testCases = append(testCases, testCase{
8779 // TODO(davidben): Add a TLS 1.3 version where
8780 // HelloRetryRequest requests an unsupported curve.
8781 name: "UnsupportedCurve-ServerHello-TLS13",
8782 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008783 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008784 CurvePreferences: []CurveID{CurveP384},
8785 Bugs: ProtocolBugs{
8786 SendCurve: CurveP256,
8787 },
8788 },
8789 flags: []string{"-p384-only"},
8790 shouldFail: true,
8791 expectedError: ":WRONG_CURVE:",
8792 })
8793
David Benjamin4c3ddf72016-06-29 18:13:53 -04008794 // Test invalid curve points.
8795 testCases = append(testCases, testCase{
8796 name: "InvalidECDHPoint-Client",
8797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008798 MaxVersion: VersionTLS12,
8799 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8800 CurvePreferences: []CurveID{CurveP256},
8801 Bugs: ProtocolBugs{
8802 InvalidECDHPoint: true,
8803 },
8804 },
8805 shouldFail: true,
8806 expectedError: ":INVALID_ENCODING:",
8807 })
8808 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008809 name: "InvalidECDHPoint-Client-TLS13",
8810 config: Config{
8811 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008812 CurvePreferences: []CurveID{CurveP256},
8813 Bugs: ProtocolBugs{
8814 InvalidECDHPoint: true,
8815 },
8816 },
8817 shouldFail: true,
8818 expectedError: ":INVALID_ENCODING:",
8819 })
8820 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008821 testType: serverTest,
8822 name: "InvalidECDHPoint-Server",
8823 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008824 MaxVersion: VersionTLS12,
8825 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8826 CurvePreferences: []CurveID{CurveP256},
8827 Bugs: ProtocolBugs{
8828 InvalidECDHPoint: true,
8829 },
8830 },
8831 shouldFail: true,
8832 expectedError: ":INVALID_ENCODING:",
8833 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008834 testCases = append(testCases, testCase{
8835 testType: serverTest,
8836 name: "InvalidECDHPoint-Server-TLS13",
8837 config: Config{
8838 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008839 CurvePreferences: []CurveID{CurveP256},
8840 Bugs: ProtocolBugs{
8841 InvalidECDHPoint: true,
8842 },
8843 },
8844 shouldFail: true,
8845 expectedError: ":INVALID_ENCODING:",
8846 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008847
8848 // The previous curve ID should be reported on TLS 1.2 resumption.
8849 testCases = append(testCases, testCase{
8850 name: "CurveID-Resume-Client",
8851 config: Config{
8852 MaxVersion: VersionTLS12,
8853 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8854 CurvePreferences: []CurveID{CurveX25519},
8855 },
8856 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8857 resumeSession: true,
8858 })
8859 testCases = append(testCases, testCase{
8860 testType: serverTest,
8861 name: "CurveID-Resume-Server",
8862 config: Config{
8863 MaxVersion: VersionTLS12,
8864 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8865 CurvePreferences: []CurveID{CurveX25519},
8866 },
8867 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8868 resumeSession: true,
8869 })
8870
8871 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8872 // one should be reported.
8873 testCases = append(testCases, testCase{
8874 name: "CurveID-Resume-Client-TLS13",
8875 config: Config{
8876 MaxVersion: VersionTLS13,
8877 CurvePreferences: []CurveID{CurveX25519},
8878 },
8879 resumeConfig: &Config{
8880 MaxVersion: VersionTLS13,
8881 CurvePreferences: []CurveID{CurveP256},
8882 },
8883 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008884 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8885 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008886 },
8887 resumeSession: true,
8888 })
8889 testCases = append(testCases, testCase{
8890 testType: serverTest,
8891 name: "CurveID-Resume-Server-TLS13",
8892 config: Config{
8893 MaxVersion: VersionTLS13,
8894 CurvePreferences: []CurveID{CurveX25519},
8895 },
8896 resumeConfig: &Config{
8897 MaxVersion: VersionTLS13,
8898 CurvePreferences: []CurveID{CurveP256},
8899 },
8900 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008901 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8902 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008903 },
8904 resumeSession: true,
8905 })
David Benjamina81967b2016-12-22 09:16:57 -05008906
8907 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8908 testCases = append(testCases, testCase{
8909 name: "PointFormat-ServerHello-TLS12",
8910 config: Config{
8911 MaxVersion: VersionTLS12,
8912 Bugs: ProtocolBugs{
8913 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8914 },
8915 },
8916 })
8917 testCases = append(testCases, testCase{
8918 name: "PointFormat-EncryptedExtensions-TLS13",
8919 config: Config{
8920 MaxVersion: VersionTLS13,
8921 Bugs: ProtocolBugs{
8922 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8923 },
8924 },
8925 shouldFail: true,
8926 expectedError: ":ERROR_PARSING_EXTENSION:",
8927 })
8928
8929 // Test that we tolerate unknown point formats, as long as
8930 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8931 // check they are still functional.
8932 testCases = append(testCases, testCase{
8933 name: "PointFormat-Client-Tolerance",
8934 config: Config{
8935 MaxVersion: VersionTLS12,
8936 Bugs: ProtocolBugs{
8937 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8938 },
8939 },
8940 })
8941 testCases = append(testCases, testCase{
8942 testType: serverTest,
8943 name: "PointFormat-Server-Tolerance",
8944 config: Config{
8945 MaxVersion: VersionTLS12,
8946 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8947 Bugs: ProtocolBugs{
8948 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8949 },
8950 },
8951 })
8952
8953 // Test TLS 1.2 does not require the point format extension to be
8954 // present.
8955 testCases = append(testCases, testCase{
8956 name: "PointFormat-Client-Missing",
8957 config: Config{
8958 MaxVersion: VersionTLS12,
8959 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8960 Bugs: ProtocolBugs{
8961 SendSupportedPointFormats: []byte{},
8962 },
8963 },
8964 })
8965 testCases = append(testCases, testCase{
8966 testType: serverTest,
8967 name: "PointFormat-Server-Missing",
8968 config: Config{
8969 MaxVersion: VersionTLS12,
8970 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8971 Bugs: ProtocolBugs{
8972 SendSupportedPointFormats: []byte{},
8973 },
8974 },
8975 })
8976
8977 // If the point format extension is present, uncompressed points must be
8978 // offered. BoringSSL requires this whether or not ECDHE is used.
8979 testCases = append(testCases, testCase{
8980 name: "PointFormat-Client-MissingUncompressed",
8981 config: Config{
8982 MaxVersion: VersionTLS12,
8983 Bugs: ProtocolBugs{
8984 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8985 },
8986 },
8987 shouldFail: true,
8988 expectedError: ":ERROR_PARSING_EXTENSION:",
8989 })
8990 testCases = append(testCases, testCase{
8991 testType: serverTest,
8992 name: "PointFormat-Server-MissingUncompressed",
8993 config: Config{
8994 MaxVersion: VersionTLS12,
8995 Bugs: ProtocolBugs{
8996 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8997 },
8998 },
8999 shouldFail: true,
9000 expectedError: ":ERROR_PARSING_EXTENSION:",
9001 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009002}
9003
David Benjaminc9ae27c2016-06-24 22:56:37 -04009004func addTLS13RecordTests() {
9005 testCases = append(testCases, testCase{
9006 name: "TLS13-RecordPadding",
9007 config: Config{
9008 MaxVersion: VersionTLS13,
9009 MinVersion: VersionTLS13,
9010 Bugs: ProtocolBugs{
9011 RecordPadding: 10,
9012 },
9013 },
9014 })
9015
9016 testCases = append(testCases, testCase{
9017 name: "TLS13-EmptyRecords",
9018 config: Config{
9019 MaxVersion: VersionTLS13,
9020 MinVersion: VersionTLS13,
9021 Bugs: ProtocolBugs{
9022 OmitRecordContents: true,
9023 },
9024 },
9025 shouldFail: true,
9026 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9027 })
9028
9029 testCases = append(testCases, testCase{
9030 name: "TLS13-OnlyPadding",
9031 config: Config{
9032 MaxVersion: VersionTLS13,
9033 MinVersion: VersionTLS13,
9034 Bugs: ProtocolBugs{
9035 OmitRecordContents: true,
9036 RecordPadding: 10,
9037 },
9038 },
9039 shouldFail: true,
9040 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9041 })
9042
9043 testCases = append(testCases, testCase{
9044 name: "TLS13-WrongOuterRecord",
9045 config: Config{
9046 MaxVersion: VersionTLS13,
9047 MinVersion: VersionTLS13,
9048 Bugs: ProtocolBugs{
9049 OuterRecordType: recordTypeHandshake,
9050 },
9051 },
9052 shouldFail: true,
9053 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9054 })
9055}
9056
Steven Valdez5b986082016-09-01 12:29:49 -04009057func addSessionTicketTests() {
9058 testCases = append(testCases, testCase{
9059 // In TLS 1.2 and below, empty NewSessionTicket messages
9060 // mean the server changed its mind on sending a ticket.
9061 name: "SendEmptySessionTicket",
9062 config: Config{
9063 MaxVersion: VersionTLS12,
9064 Bugs: ProtocolBugs{
9065 SendEmptySessionTicket: true,
9066 },
9067 },
9068 flags: []string{"-expect-no-session"},
9069 })
9070
9071 // Test that the server ignores unknown PSK modes.
9072 testCases = append(testCases, testCase{
9073 testType: serverTest,
9074 name: "TLS13-SendUnknownModeSessionTicket-Server",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 Bugs: ProtocolBugs{
9078 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009079 },
9080 },
9081 resumeSession: true,
9082 expectedResumeVersion: VersionTLS13,
9083 })
9084
Steven Valdeza833c352016-11-01 13:39:36 -04009085 // Test that the server does not send session tickets with no matching key exchange mode.
9086 testCases = append(testCases, testCase{
9087 testType: serverTest,
9088 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9089 config: Config{
9090 MaxVersion: VersionTLS13,
9091 Bugs: ProtocolBugs{
9092 SendPSKKeyExchangeModes: []byte{0x1a},
9093 ExpectNoNewSessionTicket: true,
9094 },
9095 },
9096 })
9097
9098 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009099 testCases = append(testCases, testCase{
9100 testType: serverTest,
9101 name: "TLS13-SendBadKEModeSessionTicket-Server",
9102 config: Config{
9103 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009104 },
9105 resumeConfig: &Config{
9106 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009107 Bugs: ProtocolBugs{
9108 SendPSKKeyExchangeModes: []byte{0x1a},
9109 },
9110 },
9111 resumeSession: true,
9112 expectResumeRejected: true,
9113 })
9114
Steven Valdeza833c352016-11-01 13:39:36 -04009115 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009116 testCases = append(testCases, testCase{
9117 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009118 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009119 config: Config{
9120 MaxVersion: VersionTLS13,
9121 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009122 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009123 },
9124 },
Steven Valdeza833c352016-11-01 13:39:36 -04009125 resumeSession: true,
9126 flags: []string{
9127 "-resumption-delay", "10",
9128 },
Steven Valdez5b986082016-09-01 12:29:49 -04009129 })
9130
Steven Valdeza833c352016-11-01 13:39:36 -04009131 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009132 testCases = append(testCases, testCase{
9133 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009134 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009135 config: Config{
9136 MaxVersion: VersionTLS13,
9137 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009138 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009139 },
9140 },
Steven Valdeza833c352016-11-01 13:39:36 -04009141 resumeSession: true,
9142 shouldFail: true,
9143 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009144 })
9145
David Benjamin35ac5b72017-03-03 15:05:56 -05009146 // Test that the server's ticket age skew reporting works.
9147 testCases = append(testCases, testCase{
9148 testType: serverTest,
9149 name: "TLS13-TicketAgeSkew-Forward",
9150 config: Config{
9151 MaxVersion: VersionTLS13,
9152 Bugs: ProtocolBugs{
9153 SendTicketAge: 15 * time.Second,
9154 },
9155 },
David Benjamin065d7332017-03-26 10:51:43 -05009156 resumeSession: true,
9157 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009158 flags: []string{
9159 "-resumption-delay", "10",
9160 "-expect-ticket-age-skew", "5",
9161 },
9162 })
9163 testCases = append(testCases, testCase{
9164 testType: serverTest,
9165 name: "TLS13-TicketAgeSkew-Backward",
9166 config: Config{
9167 MaxVersion: VersionTLS13,
9168 Bugs: ProtocolBugs{
9169 SendTicketAge: 5 * time.Second,
9170 },
9171 },
David Benjamin065d7332017-03-26 10:51:43 -05009172 resumeSession: true,
9173 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009174 flags: []string{
9175 "-resumption-delay", "10",
9176 "-expect-ticket-age-skew", "-5",
9177 },
9178 })
9179
Steven Valdez08b65f42016-12-07 15:29:45 -05009180 testCases = append(testCases, testCase{
9181 testType: clientTest,
9182 name: "TLS13-SendTicketEarlyDataInfo",
9183 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009184 MaxVersion: VersionTLS13,
9185 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009186 },
9187 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009188 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009189 "-expect-early-data-info",
9190 },
9191 })
9192
David Benjamin9b160662017-01-25 19:53:43 -05009193 // Test that 0-RTT tickets are ignored in clients unless opted in.
9194 testCases = append(testCases, testCase{
9195 testType: clientTest,
9196 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9197 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009198 MaxVersion: VersionTLS13,
9199 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009200 },
9201 })
9202
Steven Valdez08b65f42016-12-07 15:29:45 -05009203 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009204 testType: clientTest,
9205 name: "TLS13-DuplicateTicketEarlyDataInfo",
9206 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009207 MaxVersion: VersionTLS13,
9208 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009209 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009210 DuplicateTicketEarlyDataInfo: true,
9211 },
9212 },
9213 shouldFail: true,
9214 expectedError: ":DUPLICATE_EXTENSION:",
9215 expectedLocalError: "remote error: illegal parameter",
9216 })
9217
9218 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009219 testType: serverTest,
9220 name: "TLS13-ExpectTicketEarlyDataInfo",
9221 config: Config{
9222 MaxVersion: VersionTLS13,
9223 Bugs: ProtocolBugs{
9224 ExpectTicketEarlyDataInfo: true,
9225 },
9226 },
9227 flags: []string{
9228 "-enable-early-data",
9229 },
9230 })
David Benjamin17b30832017-01-28 14:00:32 -05009231
9232 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9233 // is honored.
9234 testCases = append(testCases, testCase{
9235 testType: clientTest,
9236 name: "TLS13-HonorServerSessionTicketLifetime",
9237 config: Config{
9238 MaxVersion: VersionTLS13,
9239 Bugs: ProtocolBugs{
9240 SendTicketLifetime: 20 * time.Second,
9241 },
9242 },
9243 flags: []string{
9244 "-resumption-delay", "19",
9245 },
9246 resumeSession: true,
9247 })
9248 testCases = append(testCases, testCase{
9249 testType: clientTest,
9250 name: "TLS13-HonorServerSessionTicketLifetime-2",
9251 config: Config{
9252 MaxVersion: VersionTLS13,
9253 Bugs: ProtocolBugs{
9254 SendTicketLifetime: 20 * time.Second,
9255 // The client should not offer the expired session.
9256 ExpectNoTLS13PSK: true,
9257 },
9258 },
9259 flags: []string{
9260 "-resumption-delay", "21",
9261 },
David Benjamin023d4192017-02-06 13:49:07 -05009262 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009263 expectResumeRejected: true,
9264 })
Steven Valdez5b986082016-09-01 12:29:49 -04009265}
9266
David Benjamin82261be2016-07-07 14:32:50 -07009267func addChangeCipherSpecTests() {
9268 // Test missing ChangeCipherSpecs.
9269 testCases = append(testCases, testCase{
9270 name: "SkipChangeCipherSpec-Client",
9271 config: Config{
9272 MaxVersion: VersionTLS12,
9273 Bugs: ProtocolBugs{
9274 SkipChangeCipherSpec: true,
9275 },
9276 },
9277 shouldFail: true,
9278 expectedError: ":UNEXPECTED_RECORD:",
9279 })
9280 testCases = append(testCases, testCase{
9281 testType: serverTest,
9282 name: "SkipChangeCipherSpec-Server",
9283 config: Config{
9284 MaxVersion: VersionTLS12,
9285 Bugs: ProtocolBugs{
9286 SkipChangeCipherSpec: true,
9287 },
9288 },
9289 shouldFail: true,
9290 expectedError: ":UNEXPECTED_RECORD:",
9291 })
9292 testCases = append(testCases, testCase{
9293 testType: serverTest,
9294 name: "SkipChangeCipherSpec-Server-NPN",
9295 config: Config{
9296 MaxVersion: VersionTLS12,
9297 NextProtos: []string{"bar"},
9298 Bugs: ProtocolBugs{
9299 SkipChangeCipherSpec: true,
9300 },
9301 },
9302 flags: []string{
9303 "-advertise-npn", "\x03foo\x03bar\x03baz",
9304 },
9305 shouldFail: true,
9306 expectedError: ":UNEXPECTED_RECORD:",
9307 })
9308
9309 // Test synchronization between the handshake and ChangeCipherSpec.
9310 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9311 // rejected. Test both with and without handshake packing to handle both
9312 // when the partial post-CCS message is in its own record and when it is
9313 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009314 for _, packed := range []bool{false, true} {
9315 var suffix string
9316 if packed {
9317 suffix = "-Packed"
9318 }
9319
9320 testCases = append(testCases, testCase{
9321 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9322 config: Config{
9323 MaxVersion: VersionTLS12,
9324 Bugs: ProtocolBugs{
9325 FragmentAcrossChangeCipherSpec: true,
9326 PackHandshakeFlight: packed,
9327 },
9328 },
9329 shouldFail: true,
9330 expectedError: ":UNEXPECTED_RECORD:",
9331 })
9332 testCases = append(testCases, testCase{
9333 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9334 config: Config{
9335 MaxVersion: VersionTLS12,
9336 },
9337 resumeSession: true,
9338 resumeConfig: &Config{
9339 MaxVersion: VersionTLS12,
9340 Bugs: ProtocolBugs{
9341 FragmentAcrossChangeCipherSpec: true,
9342 PackHandshakeFlight: packed,
9343 },
9344 },
9345 shouldFail: true,
9346 expectedError: ":UNEXPECTED_RECORD:",
9347 })
9348 testCases = append(testCases, testCase{
9349 testType: serverTest,
9350 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9351 config: Config{
9352 MaxVersion: VersionTLS12,
9353 Bugs: ProtocolBugs{
9354 FragmentAcrossChangeCipherSpec: true,
9355 PackHandshakeFlight: packed,
9356 },
9357 },
9358 shouldFail: true,
9359 expectedError: ":UNEXPECTED_RECORD:",
9360 })
9361 testCases = append(testCases, testCase{
9362 testType: serverTest,
9363 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9364 config: Config{
9365 MaxVersion: VersionTLS12,
9366 },
9367 resumeSession: true,
9368 resumeConfig: &Config{
9369 MaxVersion: VersionTLS12,
9370 Bugs: ProtocolBugs{
9371 FragmentAcrossChangeCipherSpec: true,
9372 PackHandshakeFlight: packed,
9373 },
9374 },
9375 shouldFail: true,
9376 expectedError: ":UNEXPECTED_RECORD:",
9377 })
9378 testCases = append(testCases, testCase{
9379 testType: serverTest,
9380 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9381 config: Config{
9382 MaxVersion: VersionTLS12,
9383 NextProtos: []string{"bar"},
9384 Bugs: ProtocolBugs{
9385 FragmentAcrossChangeCipherSpec: true,
9386 PackHandshakeFlight: packed,
9387 },
9388 },
9389 flags: []string{
9390 "-advertise-npn", "\x03foo\x03bar\x03baz",
9391 },
9392 shouldFail: true,
9393 expectedError: ":UNEXPECTED_RECORD:",
9394 })
9395 }
9396
David Benjamin61672812016-07-14 23:10:43 -04009397 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9398 // messages in the handshake queue. Do this by testing the server
9399 // reading the client Finished, reversing the flight so Finished comes
9400 // first.
9401 testCases = append(testCases, testCase{
9402 protocol: dtls,
9403 testType: serverTest,
9404 name: "SendUnencryptedFinished-DTLS",
9405 config: Config{
9406 MaxVersion: VersionTLS12,
9407 Bugs: ProtocolBugs{
9408 SendUnencryptedFinished: true,
9409 ReverseHandshakeFragments: true,
9410 },
9411 },
9412 shouldFail: true,
9413 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9414 })
9415
Steven Valdez143e8b32016-07-11 13:19:03 -04009416 // Test synchronization between encryption changes and the handshake in
9417 // TLS 1.3, where ChangeCipherSpec is implicit.
9418 testCases = append(testCases, testCase{
9419 name: "PartialEncryptedExtensionsWithServerHello",
9420 config: Config{
9421 MaxVersion: VersionTLS13,
9422 Bugs: ProtocolBugs{
9423 PartialEncryptedExtensionsWithServerHello: true,
9424 },
9425 },
9426 shouldFail: true,
9427 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9428 })
9429 testCases = append(testCases, testCase{
9430 testType: serverTest,
9431 name: "PartialClientFinishedWithClientHello",
9432 config: Config{
9433 MaxVersion: VersionTLS13,
9434 Bugs: ProtocolBugs{
9435 PartialClientFinishedWithClientHello: true,
9436 },
9437 },
9438 shouldFail: true,
9439 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9440 })
9441
David Benjamin82261be2016-07-07 14:32:50 -07009442 // Test that early ChangeCipherSpecs are handled correctly.
9443 testCases = append(testCases, testCase{
9444 testType: serverTest,
9445 name: "EarlyChangeCipherSpec-server-1",
9446 config: Config{
9447 MaxVersion: VersionTLS12,
9448 Bugs: ProtocolBugs{
9449 EarlyChangeCipherSpec: 1,
9450 },
9451 },
9452 shouldFail: true,
9453 expectedError: ":UNEXPECTED_RECORD:",
9454 })
9455 testCases = append(testCases, testCase{
9456 testType: serverTest,
9457 name: "EarlyChangeCipherSpec-server-2",
9458 config: Config{
9459 MaxVersion: VersionTLS12,
9460 Bugs: ProtocolBugs{
9461 EarlyChangeCipherSpec: 2,
9462 },
9463 },
9464 shouldFail: true,
9465 expectedError: ":UNEXPECTED_RECORD:",
9466 })
9467 testCases = append(testCases, testCase{
9468 protocol: dtls,
9469 name: "StrayChangeCipherSpec",
9470 config: Config{
9471 // TODO(davidben): Once DTLS 1.3 exists, test
9472 // that stray ChangeCipherSpec messages are
9473 // rejected.
9474 MaxVersion: VersionTLS12,
9475 Bugs: ProtocolBugs{
9476 StrayChangeCipherSpec: true,
9477 },
9478 },
9479 })
9480
9481 // Test that the contents of ChangeCipherSpec are checked.
9482 testCases = append(testCases, testCase{
9483 name: "BadChangeCipherSpec-1",
9484 config: Config{
9485 MaxVersion: VersionTLS12,
9486 Bugs: ProtocolBugs{
9487 BadChangeCipherSpec: []byte{2},
9488 },
9489 },
9490 shouldFail: true,
9491 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9492 })
9493 testCases = append(testCases, testCase{
9494 name: "BadChangeCipherSpec-2",
9495 config: Config{
9496 MaxVersion: VersionTLS12,
9497 Bugs: ProtocolBugs{
9498 BadChangeCipherSpec: []byte{1, 1},
9499 },
9500 },
9501 shouldFail: true,
9502 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9503 })
9504 testCases = append(testCases, testCase{
9505 protocol: dtls,
9506 name: "BadChangeCipherSpec-DTLS-1",
9507 config: Config{
9508 MaxVersion: VersionTLS12,
9509 Bugs: ProtocolBugs{
9510 BadChangeCipherSpec: []byte{2},
9511 },
9512 },
9513 shouldFail: true,
9514 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9515 })
9516 testCases = append(testCases, testCase{
9517 protocol: dtls,
9518 name: "BadChangeCipherSpec-DTLS-2",
9519 config: Config{
9520 MaxVersion: VersionTLS12,
9521 Bugs: ProtocolBugs{
9522 BadChangeCipherSpec: []byte{1, 1},
9523 },
9524 },
9525 shouldFail: true,
9526 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9527 })
9528}
9529
David Benjamincd2c8062016-09-09 11:28:16 -04009530type perMessageTest struct {
9531 messageType uint8
9532 test testCase
9533}
9534
9535// makePerMessageTests returns a series of test templates which cover each
9536// message in the TLS handshake. These may be used with bugs like
9537// WrongMessageType to fully test a per-message bug.
9538func makePerMessageTests() []perMessageTest {
9539 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009540 for _, protocol := range []protocol{tls, dtls} {
9541 var suffix string
9542 if protocol == dtls {
9543 suffix = "-DTLS"
9544 }
9545
David Benjamincd2c8062016-09-09 11:28:16 -04009546 ret = append(ret, perMessageTest{
9547 messageType: typeClientHello,
9548 test: testCase{
9549 protocol: protocol,
9550 testType: serverTest,
9551 name: "ClientHello" + suffix,
9552 config: Config{
9553 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009554 },
9555 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009556 })
9557
9558 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009559 ret = append(ret, perMessageTest{
9560 messageType: typeHelloVerifyRequest,
9561 test: testCase{
9562 protocol: protocol,
9563 name: "HelloVerifyRequest" + suffix,
9564 config: Config{
9565 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009566 },
9567 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009568 })
9569 }
9570
David Benjamincd2c8062016-09-09 11:28:16 -04009571 ret = append(ret, perMessageTest{
9572 messageType: typeServerHello,
9573 test: testCase{
9574 protocol: protocol,
9575 name: "ServerHello" + suffix,
9576 config: Config{
9577 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009578 },
9579 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009580 })
9581
David Benjamincd2c8062016-09-09 11:28:16 -04009582 ret = append(ret, perMessageTest{
9583 messageType: typeCertificate,
9584 test: testCase{
9585 protocol: protocol,
9586 name: "ServerCertificate" + suffix,
9587 config: Config{
9588 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009589 },
9590 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009591 })
9592
David Benjamincd2c8062016-09-09 11:28:16 -04009593 ret = append(ret, perMessageTest{
9594 messageType: typeCertificateStatus,
9595 test: testCase{
9596 protocol: protocol,
9597 name: "CertificateStatus" + suffix,
9598 config: Config{
9599 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009600 },
David Benjamincd2c8062016-09-09 11:28:16 -04009601 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009602 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009603 })
9604
David Benjamincd2c8062016-09-09 11:28:16 -04009605 ret = append(ret, perMessageTest{
9606 messageType: typeServerKeyExchange,
9607 test: testCase{
9608 protocol: protocol,
9609 name: "ServerKeyExchange" + suffix,
9610 config: Config{
9611 MaxVersion: VersionTLS12,
9612 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009613 },
9614 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009615 })
9616
David Benjamincd2c8062016-09-09 11:28:16 -04009617 ret = append(ret, perMessageTest{
9618 messageType: typeCertificateRequest,
9619 test: testCase{
9620 protocol: protocol,
9621 name: "CertificateRequest" + suffix,
9622 config: Config{
9623 MaxVersion: VersionTLS12,
9624 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009625 },
9626 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009627 })
9628
David Benjamincd2c8062016-09-09 11:28:16 -04009629 ret = append(ret, perMessageTest{
9630 messageType: typeServerHelloDone,
9631 test: testCase{
9632 protocol: protocol,
9633 name: "ServerHelloDone" + suffix,
9634 config: Config{
9635 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009636 },
9637 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009638 })
9639
David Benjamincd2c8062016-09-09 11:28:16 -04009640 ret = append(ret, perMessageTest{
9641 messageType: typeCertificate,
9642 test: testCase{
9643 testType: serverTest,
9644 protocol: protocol,
9645 name: "ClientCertificate" + suffix,
9646 config: Config{
9647 Certificates: []Certificate{rsaCertificate},
9648 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009649 },
David Benjamincd2c8062016-09-09 11:28:16 -04009650 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009651 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009652 })
9653
David Benjamincd2c8062016-09-09 11:28:16 -04009654 ret = append(ret, perMessageTest{
9655 messageType: typeCertificateVerify,
9656 test: testCase{
9657 testType: serverTest,
9658 protocol: protocol,
9659 name: "CertificateVerify" + suffix,
9660 config: Config{
9661 Certificates: []Certificate{rsaCertificate},
9662 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009663 },
David Benjamincd2c8062016-09-09 11:28:16 -04009664 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009665 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009666 })
9667
David Benjamincd2c8062016-09-09 11:28:16 -04009668 ret = append(ret, perMessageTest{
9669 messageType: typeClientKeyExchange,
9670 test: testCase{
9671 testType: serverTest,
9672 protocol: protocol,
9673 name: "ClientKeyExchange" + suffix,
9674 config: Config{
9675 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009676 },
9677 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009678 })
9679
9680 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009681 ret = append(ret, perMessageTest{
9682 messageType: typeNextProtocol,
9683 test: testCase{
9684 testType: serverTest,
9685 protocol: protocol,
9686 name: "NextProtocol" + suffix,
9687 config: Config{
9688 MaxVersion: VersionTLS12,
9689 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009690 },
David Benjamincd2c8062016-09-09 11:28:16 -04009691 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009692 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009693 })
9694
David Benjamincd2c8062016-09-09 11:28:16 -04009695 ret = append(ret, perMessageTest{
9696 messageType: typeChannelID,
9697 test: testCase{
9698 testType: serverTest,
9699 protocol: protocol,
9700 name: "ChannelID" + suffix,
9701 config: Config{
9702 MaxVersion: VersionTLS12,
9703 ChannelID: channelIDKey,
9704 },
9705 flags: []string{
9706 "-expect-channel-id",
9707 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009708 },
9709 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009710 })
9711 }
9712
David Benjamincd2c8062016-09-09 11:28:16 -04009713 ret = append(ret, perMessageTest{
9714 messageType: typeFinished,
9715 test: testCase{
9716 testType: serverTest,
9717 protocol: protocol,
9718 name: "ClientFinished" + suffix,
9719 config: Config{
9720 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009721 },
9722 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009723 })
9724
David Benjamincd2c8062016-09-09 11:28:16 -04009725 ret = append(ret, perMessageTest{
9726 messageType: typeNewSessionTicket,
9727 test: testCase{
9728 protocol: protocol,
9729 name: "NewSessionTicket" + suffix,
9730 config: Config{
9731 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009732 },
9733 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009734 })
9735
David Benjamincd2c8062016-09-09 11:28:16 -04009736 ret = append(ret, perMessageTest{
9737 messageType: typeFinished,
9738 test: testCase{
9739 protocol: protocol,
9740 name: "ServerFinished" + suffix,
9741 config: Config{
9742 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009743 },
9744 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009745 })
9746
9747 }
David Benjamincd2c8062016-09-09 11:28:16 -04009748
9749 ret = append(ret, perMessageTest{
9750 messageType: typeClientHello,
9751 test: testCase{
9752 testType: serverTest,
9753 name: "TLS13-ClientHello",
9754 config: Config{
9755 MaxVersion: VersionTLS13,
9756 },
9757 },
9758 })
9759
9760 ret = append(ret, perMessageTest{
9761 messageType: typeServerHello,
9762 test: testCase{
9763 name: "TLS13-ServerHello",
9764 config: Config{
9765 MaxVersion: VersionTLS13,
9766 },
9767 },
9768 })
9769
9770 ret = append(ret, perMessageTest{
9771 messageType: typeEncryptedExtensions,
9772 test: testCase{
9773 name: "TLS13-EncryptedExtensions",
9774 config: Config{
9775 MaxVersion: VersionTLS13,
9776 },
9777 },
9778 })
9779
9780 ret = append(ret, perMessageTest{
9781 messageType: typeCertificateRequest,
9782 test: testCase{
9783 name: "TLS13-CertificateRequest",
9784 config: Config{
9785 MaxVersion: VersionTLS13,
9786 ClientAuth: RequireAnyClientCert,
9787 },
9788 },
9789 })
9790
9791 ret = append(ret, perMessageTest{
9792 messageType: typeCertificate,
9793 test: testCase{
9794 name: "TLS13-ServerCertificate",
9795 config: Config{
9796 MaxVersion: VersionTLS13,
9797 },
9798 },
9799 })
9800
9801 ret = append(ret, perMessageTest{
9802 messageType: typeCertificateVerify,
9803 test: testCase{
9804 name: "TLS13-ServerCertificateVerify",
9805 config: Config{
9806 MaxVersion: VersionTLS13,
9807 },
9808 },
9809 })
9810
9811 ret = append(ret, perMessageTest{
9812 messageType: typeFinished,
9813 test: testCase{
9814 name: "TLS13-ServerFinished",
9815 config: Config{
9816 MaxVersion: VersionTLS13,
9817 },
9818 },
9819 })
9820
9821 ret = append(ret, perMessageTest{
9822 messageType: typeCertificate,
9823 test: testCase{
9824 testType: serverTest,
9825 name: "TLS13-ClientCertificate",
9826 config: Config{
9827 Certificates: []Certificate{rsaCertificate},
9828 MaxVersion: VersionTLS13,
9829 },
9830 flags: []string{"-require-any-client-certificate"},
9831 },
9832 })
9833
9834 ret = append(ret, perMessageTest{
9835 messageType: typeCertificateVerify,
9836 test: testCase{
9837 testType: serverTest,
9838 name: "TLS13-ClientCertificateVerify",
9839 config: Config{
9840 Certificates: []Certificate{rsaCertificate},
9841 MaxVersion: VersionTLS13,
9842 },
9843 flags: []string{"-require-any-client-certificate"},
9844 },
9845 })
9846
9847 ret = append(ret, perMessageTest{
9848 messageType: typeFinished,
9849 test: testCase{
9850 testType: serverTest,
9851 name: "TLS13-ClientFinished",
9852 config: Config{
9853 MaxVersion: VersionTLS13,
9854 },
9855 },
9856 })
9857
9858 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009859}
9860
David Benjamincd2c8062016-09-09 11:28:16 -04009861func addWrongMessageTypeTests() {
9862 for _, t := range makePerMessageTests() {
9863 t.test.name = "WrongMessageType-" + t.test.name
9864 t.test.config.Bugs.SendWrongMessageType = t.messageType
9865 t.test.shouldFail = true
9866 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9867 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009868
David Benjamincd2c8062016-09-09 11:28:16 -04009869 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9870 // In TLS 1.3, a bad ServerHello means the client sends
9871 // an unencrypted alert while the server expects
9872 // encryption, so the alert is not readable by runner.
9873 t.test.expectedLocalError = "local error: bad record MAC"
9874 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009875
David Benjamincd2c8062016-09-09 11:28:16 -04009876 testCases = append(testCases, t.test)
9877 }
David Benjaminebacdee2017-04-08 11:00:45 -04009878
9879 // The processing order for TLS 1.3 version negotiation is such that one
9880 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
9881 // TLS 1.2. Test that we do not do this.
9882 testCases = append(testCases, testCase{
9883 name: "SendServerHelloAsHelloRetryRequest",
9884 config: Config{
9885 MaxVersion: VersionTLS12,
9886 Bugs: ProtocolBugs{
9887 SendServerHelloAsHelloRetryRequest: true,
9888 },
9889 },
9890 shouldFail: true,
9891 expectedError: ":UNEXPECTED_MESSAGE:",
9892 expectedLocalError: "remote error: unexpected message",
9893 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009894}
9895
David Benjamin639846e2016-09-09 11:41:18 -04009896func addTrailingMessageDataTests() {
9897 for _, t := range makePerMessageTests() {
9898 t.test.name = "TrailingMessageData-" + t.test.name
9899 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9900 t.test.shouldFail = true
9901 t.test.expectedError = ":DECODE_ERROR:"
9902 t.test.expectedLocalError = "remote error: error decoding message"
9903
9904 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9905 // In TLS 1.3, a bad ServerHello means the client sends
9906 // an unencrypted alert while the server expects
9907 // encryption, so the alert is not readable by runner.
9908 t.test.expectedLocalError = "local error: bad record MAC"
9909 }
9910
9911 if t.messageType == typeFinished {
9912 // Bad Finished messages read as the verify data having
9913 // the wrong length.
9914 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9915 t.test.expectedLocalError = "remote error: error decrypting message"
9916 }
9917
9918 testCases = append(testCases, t.test)
9919 }
9920}
9921
Steven Valdez143e8b32016-07-11 13:19:03 -04009922func addTLS13HandshakeTests() {
9923 testCases = append(testCases, testCase{
9924 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009925 name: "NegotiatePSKResumption-TLS13",
9926 config: Config{
9927 MaxVersion: VersionTLS13,
9928 Bugs: ProtocolBugs{
9929 NegotiatePSKResumption: true,
9930 },
9931 },
9932 resumeSession: true,
9933 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009934 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009935 })
9936
9937 testCases = append(testCases, testCase{
9938 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009939 name: "MissingKeyShare-Client",
9940 config: Config{
9941 MaxVersion: VersionTLS13,
9942 Bugs: ProtocolBugs{
9943 MissingKeyShare: true,
9944 },
9945 },
9946 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009947 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009948 })
9949
9950 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009951 testType: serverTest,
9952 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009953 config: Config{
9954 MaxVersion: VersionTLS13,
9955 Bugs: ProtocolBugs{
9956 MissingKeyShare: true,
9957 },
9958 },
9959 shouldFail: true,
9960 expectedError: ":MISSING_KEY_SHARE:",
9961 })
9962
9963 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009964 testType: serverTest,
9965 name: "DuplicateKeyShares",
9966 config: Config{
9967 MaxVersion: VersionTLS13,
9968 Bugs: ProtocolBugs{
9969 DuplicateKeyShares: true,
9970 },
9971 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009972 shouldFail: true,
9973 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009974 })
9975
9976 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009977 testType: serverTest,
9978 name: "SkipEarlyData",
9979 config: Config{
9980 MaxVersion: VersionTLS13,
9981 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009982 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009983 },
9984 },
9985 })
9986
9987 testCases = append(testCases, testCase{
9988 testType: serverTest,
9989 name: "SkipEarlyData-OmitEarlyDataExtension",
9990 config: Config{
9991 MaxVersion: VersionTLS13,
9992 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009993 SendFakeEarlyDataLength: 4,
9994 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009995 },
9996 },
9997 shouldFail: true,
9998 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9999 })
10000
10001 testCases = append(testCases, testCase{
10002 testType: serverTest,
10003 name: "SkipEarlyData-TooMuchData",
10004 config: Config{
10005 MaxVersion: VersionTLS13,
10006 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010007 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010008 },
10009 },
10010 shouldFail: true,
10011 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10012 })
10013
10014 testCases = append(testCases, testCase{
10015 testType: serverTest,
10016 name: "SkipEarlyData-Interleaved",
10017 config: Config{
10018 MaxVersion: VersionTLS13,
10019 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010020 SendFakeEarlyDataLength: 4,
10021 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010022 },
10023 },
10024 shouldFail: true,
10025 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10026 })
10027
10028 testCases = append(testCases, testCase{
10029 testType: serverTest,
10030 name: "SkipEarlyData-EarlyDataInTLS12",
10031 config: Config{
10032 MaxVersion: VersionTLS13,
10033 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010034 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010035 },
10036 },
10037 shouldFail: true,
10038 expectedError: ":UNEXPECTED_RECORD:",
10039 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10040 })
10041
10042 testCases = append(testCases, testCase{
10043 testType: serverTest,
10044 name: "SkipEarlyData-HRR",
10045 config: Config{
10046 MaxVersion: VersionTLS13,
10047 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010048 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010049 },
10050 DefaultCurves: []CurveID{},
10051 },
10052 })
10053
10054 testCases = append(testCases, testCase{
10055 testType: serverTest,
10056 name: "SkipEarlyData-HRR-Interleaved",
10057 config: Config{
10058 MaxVersion: VersionTLS13,
10059 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010060 SendFakeEarlyDataLength: 4,
10061 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010062 },
10063 DefaultCurves: []CurveID{},
10064 },
10065 shouldFail: true,
10066 expectedError: ":UNEXPECTED_RECORD:",
10067 })
10068
10069 testCases = append(testCases, testCase{
10070 testType: serverTest,
10071 name: "SkipEarlyData-HRR-TooMuchData",
10072 config: Config{
10073 MaxVersion: VersionTLS13,
10074 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010075 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010076 },
10077 DefaultCurves: []CurveID{},
10078 },
10079 shouldFail: true,
10080 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10081 })
10082
10083 // Test that skipping early data looking for cleartext correctly
10084 // processes an alert record.
10085 testCases = append(testCases, testCase{
10086 testType: serverTest,
10087 name: "SkipEarlyData-HRR-FatalAlert",
10088 config: Config{
10089 MaxVersion: VersionTLS13,
10090 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010091 SendEarlyAlert: true,
10092 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010093 },
10094 DefaultCurves: []CurveID{},
10095 },
10096 shouldFail: true,
10097 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10098 })
10099
10100 testCases = append(testCases, testCase{
10101 testType: serverTest,
10102 name: "SkipEarlyData-SecondClientHelloEarlyData",
10103 config: Config{
10104 MaxVersion: VersionTLS13,
10105 Bugs: ProtocolBugs{
10106 SendEarlyDataOnSecondClientHello: true,
10107 },
10108 DefaultCurves: []CurveID{},
10109 },
10110 shouldFail: true,
10111 expectedLocalError: "remote error: bad record MAC",
10112 })
10113
10114 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010115 testType: clientTest,
10116 name: "EmptyEncryptedExtensions",
10117 config: Config{
10118 MaxVersion: VersionTLS13,
10119 Bugs: ProtocolBugs{
10120 EmptyEncryptedExtensions: true,
10121 },
10122 },
10123 shouldFail: true,
10124 expectedLocalError: "remote error: error decoding message",
10125 })
10126
10127 testCases = append(testCases, testCase{
10128 testType: clientTest,
10129 name: "EncryptedExtensionsWithKeyShare",
10130 config: Config{
10131 MaxVersion: VersionTLS13,
10132 Bugs: ProtocolBugs{
10133 EncryptedExtensionsWithKeyShare: true,
10134 },
10135 },
10136 shouldFail: true,
10137 expectedLocalError: "remote error: unsupported extension",
10138 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010139
10140 testCases = append(testCases, testCase{
10141 testType: serverTest,
10142 name: "SendHelloRetryRequest",
10143 config: Config{
10144 MaxVersion: VersionTLS13,
10145 // Require a HelloRetryRequest for every curve.
10146 DefaultCurves: []CurveID{},
10147 },
10148 expectedCurveID: CurveX25519,
10149 })
10150
10151 testCases = append(testCases, testCase{
10152 testType: serverTest,
10153 name: "SendHelloRetryRequest-2",
10154 config: Config{
10155 MaxVersion: VersionTLS13,
10156 DefaultCurves: []CurveID{CurveP384},
10157 },
10158 // Although the ClientHello did not predict our preferred curve,
10159 // we always select it whether it is predicted or not.
10160 expectedCurveID: CurveX25519,
10161 })
10162
10163 testCases = append(testCases, testCase{
10164 name: "UnknownCurve-HelloRetryRequest",
10165 config: Config{
10166 MaxVersion: VersionTLS13,
10167 // P-384 requires HelloRetryRequest in BoringSSL.
10168 CurvePreferences: []CurveID{CurveP384},
10169 Bugs: ProtocolBugs{
10170 SendHelloRetryRequestCurve: bogusCurve,
10171 },
10172 },
10173 shouldFail: true,
10174 expectedError: ":WRONG_CURVE:",
10175 })
10176
10177 testCases = append(testCases, testCase{
10178 name: "DisabledCurve-HelloRetryRequest",
10179 config: Config{
10180 MaxVersion: VersionTLS13,
10181 CurvePreferences: []CurveID{CurveP256},
10182 Bugs: ProtocolBugs{
10183 IgnorePeerCurvePreferences: true,
10184 },
10185 },
10186 flags: []string{"-p384-only"},
10187 shouldFail: true,
10188 expectedError: ":WRONG_CURVE:",
10189 })
10190
10191 testCases = append(testCases, testCase{
10192 name: "UnnecessaryHelloRetryRequest",
10193 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010194 MaxVersion: VersionTLS13,
10195 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010196 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010197 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010198 },
10199 },
10200 shouldFail: true,
10201 expectedError: ":WRONG_CURVE:",
10202 })
10203
10204 testCases = append(testCases, testCase{
10205 name: "SecondHelloRetryRequest",
10206 config: Config{
10207 MaxVersion: VersionTLS13,
10208 // P-384 requires HelloRetryRequest in BoringSSL.
10209 CurvePreferences: []CurveID{CurveP384},
10210 Bugs: ProtocolBugs{
10211 SecondHelloRetryRequest: true,
10212 },
10213 },
10214 shouldFail: true,
10215 expectedError: ":UNEXPECTED_MESSAGE:",
10216 })
10217
10218 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010219 name: "HelloRetryRequest-Empty",
10220 config: Config{
10221 MaxVersion: VersionTLS13,
10222 Bugs: ProtocolBugs{
10223 AlwaysSendHelloRetryRequest: true,
10224 },
10225 },
10226 shouldFail: true,
10227 expectedError: ":DECODE_ERROR:",
10228 })
10229
10230 testCases = append(testCases, testCase{
10231 name: "HelloRetryRequest-DuplicateCurve",
10232 config: Config{
10233 MaxVersion: VersionTLS13,
10234 // P-384 requires a HelloRetryRequest against BoringSSL's default
10235 // configuration. Assert this ExpectMissingKeyShare.
10236 CurvePreferences: []CurveID{CurveP384},
10237 Bugs: ProtocolBugs{
10238 ExpectMissingKeyShare: true,
10239 DuplicateHelloRetryRequestExtensions: true,
10240 },
10241 },
10242 shouldFail: true,
10243 expectedError: ":DUPLICATE_EXTENSION:",
10244 expectedLocalError: "remote error: illegal parameter",
10245 })
10246
10247 testCases = append(testCases, testCase{
10248 name: "HelloRetryRequest-Cookie",
10249 config: Config{
10250 MaxVersion: VersionTLS13,
10251 Bugs: ProtocolBugs{
10252 SendHelloRetryRequestCookie: []byte("cookie"),
10253 },
10254 },
10255 })
10256
10257 testCases = append(testCases, testCase{
10258 name: "HelloRetryRequest-DuplicateCookie",
10259 config: Config{
10260 MaxVersion: VersionTLS13,
10261 Bugs: ProtocolBugs{
10262 SendHelloRetryRequestCookie: []byte("cookie"),
10263 DuplicateHelloRetryRequestExtensions: true,
10264 },
10265 },
10266 shouldFail: true,
10267 expectedError: ":DUPLICATE_EXTENSION:",
10268 expectedLocalError: "remote error: illegal parameter",
10269 })
10270
10271 testCases = append(testCases, testCase{
10272 name: "HelloRetryRequest-EmptyCookie",
10273 config: Config{
10274 MaxVersion: VersionTLS13,
10275 Bugs: ProtocolBugs{
10276 SendHelloRetryRequestCookie: []byte{},
10277 },
10278 },
10279 shouldFail: true,
10280 expectedError: ":DECODE_ERROR:",
10281 })
10282
10283 testCases = append(testCases, testCase{
10284 name: "HelloRetryRequest-Cookie-Curve",
10285 config: Config{
10286 MaxVersion: VersionTLS13,
10287 // P-384 requires HelloRetryRequest in BoringSSL.
10288 CurvePreferences: []CurveID{CurveP384},
10289 Bugs: ProtocolBugs{
10290 SendHelloRetryRequestCookie: []byte("cookie"),
10291 ExpectMissingKeyShare: true,
10292 },
10293 },
10294 })
10295
10296 testCases = append(testCases, testCase{
10297 name: "HelloRetryRequest-Unknown",
10298 config: Config{
10299 MaxVersion: VersionTLS13,
10300 Bugs: ProtocolBugs{
10301 CustomHelloRetryRequestExtension: "extension",
10302 },
10303 },
10304 shouldFail: true,
10305 expectedError: ":UNEXPECTED_EXTENSION:",
10306 expectedLocalError: "remote error: unsupported extension",
10307 })
10308
10309 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010310 testType: serverTest,
10311 name: "SecondClientHelloMissingKeyShare",
10312 config: Config{
10313 MaxVersion: VersionTLS13,
10314 DefaultCurves: []CurveID{},
10315 Bugs: ProtocolBugs{
10316 SecondClientHelloMissingKeyShare: true,
10317 },
10318 },
10319 shouldFail: true,
10320 expectedError: ":MISSING_KEY_SHARE:",
10321 })
10322
10323 testCases = append(testCases, testCase{
10324 testType: serverTest,
10325 name: "SecondClientHelloWrongCurve",
10326 config: Config{
10327 MaxVersion: VersionTLS13,
10328 DefaultCurves: []CurveID{},
10329 Bugs: ProtocolBugs{
10330 MisinterpretHelloRetryRequestCurve: CurveP521,
10331 },
10332 },
10333 shouldFail: true,
10334 expectedError: ":WRONG_CURVE:",
10335 })
10336
10337 testCases = append(testCases, testCase{
10338 name: "HelloRetryRequestVersionMismatch",
10339 config: Config{
10340 MaxVersion: VersionTLS13,
10341 // P-384 requires HelloRetryRequest in BoringSSL.
10342 CurvePreferences: []CurveID{CurveP384},
10343 Bugs: ProtocolBugs{
10344 SendServerHelloVersion: 0x0305,
10345 },
10346 },
10347 shouldFail: true,
10348 expectedError: ":WRONG_VERSION_NUMBER:",
10349 })
10350
10351 testCases = append(testCases, testCase{
10352 name: "HelloRetryRequestCurveMismatch",
10353 config: Config{
10354 MaxVersion: VersionTLS13,
10355 // P-384 requires HelloRetryRequest in BoringSSL.
10356 CurvePreferences: []CurveID{CurveP384},
10357 Bugs: ProtocolBugs{
10358 // Send P-384 (correct) in the HelloRetryRequest.
10359 SendHelloRetryRequestCurve: CurveP384,
10360 // But send P-256 in the ServerHello.
10361 SendCurve: CurveP256,
10362 },
10363 },
10364 shouldFail: true,
10365 expectedError: ":WRONG_CURVE:",
10366 })
10367
10368 // Test the server selecting a curve that requires a HelloRetryRequest
10369 // without sending it.
10370 testCases = append(testCases, testCase{
10371 name: "SkipHelloRetryRequest",
10372 config: Config{
10373 MaxVersion: VersionTLS13,
10374 // P-384 requires HelloRetryRequest in BoringSSL.
10375 CurvePreferences: []CurveID{CurveP384},
10376 Bugs: ProtocolBugs{
10377 SkipHelloRetryRequest: true,
10378 },
10379 },
10380 shouldFail: true,
10381 expectedError: ":WRONG_CURVE:",
10382 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010383
10384 testCases = append(testCases, testCase{
10385 name: "TLS13-RequestContextInHandshake",
10386 config: Config{
10387 MaxVersion: VersionTLS13,
10388 MinVersion: VersionTLS13,
10389 ClientAuth: RequireAnyClientCert,
10390 Bugs: ProtocolBugs{
10391 SendRequestContext: []byte("request context"),
10392 },
10393 },
10394 flags: []string{
10395 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10396 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10397 },
10398 shouldFail: true,
10399 expectedError: ":DECODE_ERROR:",
10400 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010401
10402 testCases = append(testCases, testCase{
10403 testType: serverTest,
10404 name: "TLS13-TrailingKeyShareData",
10405 config: Config{
10406 MaxVersion: VersionTLS13,
10407 Bugs: ProtocolBugs{
10408 TrailingKeyShareData: true,
10409 },
10410 },
10411 shouldFail: true,
10412 expectedError: ":DECODE_ERROR:",
10413 })
David Benjamin7f78df42016-10-05 22:33:19 -040010414
10415 testCases = append(testCases, testCase{
10416 name: "TLS13-AlwaysSelectPSKIdentity",
10417 config: Config{
10418 MaxVersion: VersionTLS13,
10419 Bugs: ProtocolBugs{
10420 AlwaysSelectPSKIdentity: true,
10421 },
10422 },
10423 shouldFail: true,
10424 expectedError: ":UNEXPECTED_EXTENSION:",
10425 })
10426
10427 testCases = append(testCases, testCase{
10428 name: "TLS13-InvalidPSKIdentity",
10429 config: Config{
10430 MaxVersion: VersionTLS13,
10431 Bugs: ProtocolBugs{
10432 SelectPSKIdentityOnResume: 1,
10433 },
10434 },
10435 resumeSession: true,
10436 shouldFail: true,
10437 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10438 })
David Benjamin1286bee2016-10-07 15:25:06 -040010439
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010440 testCases = append(testCases, testCase{
10441 testType: serverTest,
10442 name: "TLS13-ExtraPSKIdentity",
10443 config: Config{
10444 MaxVersion: VersionTLS13,
10445 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010446 ExtraPSKIdentity: true,
10447 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010448 },
10449 },
10450 resumeSession: true,
10451 })
10452
David Benjamin1286bee2016-10-07 15:25:06 -040010453 // Test that unknown NewSessionTicket extensions are tolerated.
10454 testCases = append(testCases, testCase{
10455 name: "TLS13-CustomTicketExtension",
10456 config: Config{
10457 MaxVersion: VersionTLS13,
10458 Bugs: ProtocolBugs{
10459 CustomTicketExtension: "1234",
10460 },
10461 },
10462 })
Steven Valdez2d850622017-01-11 11:34:52 -050010463
Steven Valdez2d850622017-01-11 11:34:52 -050010464 testCases = append(testCases, testCase{
10465 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010466 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010467 config: Config{
10468 MaxVersion: VersionTLS13,
10469 MaxEarlyDataSize: 16384,
10470 },
10471 resumeConfig: &Config{
10472 MaxVersion: VersionTLS13,
10473 MaxEarlyDataSize: 16384,
10474 Bugs: ProtocolBugs{
10475 AlwaysRejectEarlyData: true,
10476 },
10477 },
10478 resumeSession: true,
10479 flags: []string{
10480 "-enable-early-data",
10481 "-expect-early-data-info",
10482 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010483 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010484 },
10485 })
10486
10487 testCases = append(testCases, testCase{
10488 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010489 name: "TLS13-EarlyData-RejectTicket-Client",
10490 config: Config{
10491 MaxVersion: VersionTLS13,
10492 MaxEarlyDataSize: 16384,
10493 Certificates: []Certificate{rsaCertificate},
10494 },
10495 resumeConfig: &Config{
10496 MaxVersion: VersionTLS13,
10497 MaxEarlyDataSize: 16384,
10498 Certificates: []Certificate{ecdsaP256Certificate},
10499 SessionTicketsDisabled: true,
10500 },
10501 resumeSession: true,
10502 expectResumeRejected: true,
10503 flags: []string{
10504 "-enable-early-data",
10505 "-expect-early-data-info",
10506 "-expect-reject-early-data",
10507 "-on-resume-shim-writes-first",
10508 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10509 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10510 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10511 // Session tickets are disabled, so the runner will not send a ticket.
10512 "-on-retry-expect-no-session",
10513 },
10514 })
10515
10516 testCases = append(testCases, testCase{
10517 testType: clientTest,
10518 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010519 config: Config{
10520 MaxVersion: VersionTLS13,
10521 MaxEarlyDataSize: 16384,
10522 },
10523 resumeConfig: &Config{
10524 MaxVersion: VersionTLS13,
10525 MaxEarlyDataSize: 16384,
10526 Bugs: ProtocolBugs{
10527 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10528 },
10529 },
10530 resumeSession: true,
10531 flags: []string{
10532 "-enable-early-data",
10533 "-expect-early-data-info",
10534 "-expect-reject-early-data",
10535 },
10536 })
10537
10538 // The client must check the server does not send the early_data
10539 // extension while rejecting the session.
10540 testCases = append(testCases, testCase{
10541 testType: clientTest,
10542 name: "TLS13-EarlyDataWithoutResume-Client",
10543 config: Config{
10544 MaxVersion: VersionTLS13,
10545 MaxEarlyDataSize: 16384,
10546 },
10547 resumeConfig: &Config{
10548 MaxVersion: VersionTLS13,
10549 SessionTicketsDisabled: true,
10550 Bugs: ProtocolBugs{
10551 SendEarlyDataExtension: true,
10552 },
10553 },
10554 resumeSession: true,
10555 flags: []string{
10556 "-enable-early-data",
10557 "-expect-early-data-info",
10558 },
10559 shouldFail: true,
10560 expectedError: ":UNEXPECTED_EXTENSION:",
10561 })
10562
10563 // The client must fail with a dedicated error code if the server
10564 // responds with TLS 1.2 when offering 0-RTT.
10565 testCases = append(testCases, testCase{
10566 testType: clientTest,
10567 name: "TLS13-EarlyDataVersionDowngrade-Client",
10568 config: Config{
10569 MaxVersion: VersionTLS13,
10570 MaxEarlyDataSize: 16384,
10571 },
10572 resumeConfig: &Config{
10573 MaxVersion: VersionTLS12,
10574 },
10575 resumeSession: true,
10576 flags: []string{
10577 "-enable-early-data",
10578 "-expect-early-data-info",
10579 },
10580 shouldFail: true,
10581 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10582 })
10583
10584 // Test that the client rejects an (unsolicited) early_data extension if
10585 // the server sent an HRR.
10586 testCases = append(testCases, testCase{
10587 testType: clientTest,
10588 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10589 config: Config{
10590 MaxVersion: VersionTLS13,
10591 MaxEarlyDataSize: 16384,
10592 },
10593 resumeConfig: &Config{
10594 MaxVersion: VersionTLS13,
10595 MaxEarlyDataSize: 16384,
10596 Bugs: ProtocolBugs{
10597 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10598 SendEarlyDataExtension: true,
10599 },
10600 },
10601 resumeSession: true,
10602 flags: []string{
10603 "-enable-early-data",
10604 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010605 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010606 },
10607 shouldFail: true,
10608 expectedError: ":UNEXPECTED_EXTENSION:",
10609 })
10610
10611 fooString := "foo"
10612 barString := "bar"
10613
10614 // Test that the client reports the correct ALPN after a 0-RTT reject
10615 // that changed it.
10616 testCases = append(testCases, testCase{
10617 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010618 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010619 config: Config{
10620 MaxVersion: VersionTLS13,
10621 MaxEarlyDataSize: 16384,
10622 Bugs: ProtocolBugs{
10623 ALPNProtocol: &fooString,
10624 },
10625 },
10626 resumeConfig: &Config{
10627 MaxVersion: VersionTLS13,
10628 MaxEarlyDataSize: 16384,
10629 Bugs: ProtocolBugs{
10630 ALPNProtocol: &barString,
10631 },
10632 },
10633 resumeSession: true,
10634 flags: []string{
10635 "-advertise-alpn", "\x03foo\x03bar",
10636 "-enable-early-data",
10637 "-expect-early-data-info",
10638 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010639 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010640 "-on-resume-expect-alpn", "foo",
10641 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010642 },
10643 })
10644
10645 // Test that the client reports the correct ALPN after a 0-RTT reject if
10646 // ALPN was omitted from the first connection.
10647 testCases = append(testCases, testCase{
10648 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010649 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010650 config: Config{
10651 MaxVersion: VersionTLS13,
10652 MaxEarlyDataSize: 16384,
10653 },
10654 resumeConfig: &Config{
10655 MaxVersion: VersionTLS13,
10656 MaxEarlyDataSize: 16384,
10657 NextProtos: []string{"foo"},
10658 },
10659 resumeSession: true,
10660 flags: []string{
10661 "-advertise-alpn", "\x03foo\x03bar",
10662 "-enable-early-data",
10663 "-expect-early-data-info",
10664 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010665 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010666 "-on-resume-expect-alpn", "",
10667 "-on-retry-expect-alpn", "foo",
10668 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010669 },
10670 })
10671
10672 // Test that the client reports the correct ALPN after a 0-RTT reject if
10673 // ALPN was omitted from the second connection.
10674 testCases = append(testCases, testCase{
10675 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010676 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010677 config: Config{
10678 MaxVersion: VersionTLS13,
10679 MaxEarlyDataSize: 16384,
10680 NextProtos: []string{"foo"},
10681 },
10682 resumeConfig: &Config{
10683 MaxVersion: VersionTLS13,
10684 MaxEarlyDataSize: 16384,
10685 },
10686 resumeSession: true,
10687 flags: []string{
10688 "-advertise-alpn", "\x03foo\x03bar",
10689 "-enable-early-data",
10690 "-expect-early-data-info",
10691 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010692 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010693 "-on-resume-expect-alpn", "foo",
10694 "-on-retry-expect-alpn", "",
10695 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010696 },
10697 })
10698
10699 // Test that the client enforces ALPN match on 0-RTT accept.
10700 testCases = append(testCases, testCase{
10701 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010702 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010703 config: Config{
10704 MaxVersion: VersionTLS13,
10705 MaxEarlyDataSize: 16384,
10706 Bugs: ProtocolBugs{
10707 ALPNProtocol: &fooString,
10708 },
10709 },
10710 resumeConfig: &Config{
10711 MaxVersion: VersionTLS13,
10712 MaxEarlyDataSize: 16384,
10713 Bugs: ProtocolBugs{
10714 AlwaysAcceptEarlyData: true,
10715 ALPNProtocol: &barString,
10716 },
10717 },
10718 resumeSession: true,
10719 flags: []string{
10720 "-advertise-alpn", "\x03foo\x03bar",
10721 "-enable-early-data",
10722 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010723 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010724 "-on-resume-expect-alpn", "foo",
10725 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010726 },
10727 shouldFail: true,
10728 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10729 })
10730
10731 // Test that the server correctly rejects 0-RTT when the previous
10732 // session did not allow early data on resumption.
10733 testCases = append(testCases, testCase{
10734 testType: serverTest,
10735 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10736 config: Config{
10737 MaxVersion: VersionTLS13,
10738 },
10739 resumeConfig: &Config{
10740 MaxVersion: VersionTLS13,
10741 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010742 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010743 ExpectEarlyDataAccepted: false,
10744 },
10745 },
10746 resumeSession: true,
10747 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010748 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010749 "-expect-reject-early-data",
10750 },
10751 })
10752
10753 // Test that we reject early data where ALPN is omitted from the first
10754 // connection.
10755 testCases = append(testCases, testCase{
10756 testType: serverTest,
10757 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10758 config: Config{
10759 MaxVersion: VersionTLS13,
10760 NextProtos: []string{},
10761 },
10762 resumeConfig: &Config{
10763 MaxVersion: VersionTLS13,
10764 NextProtos: []string{"foo"},
10765 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010766 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010767 ExpectEarlyDataAccepted: false,
10768 },
10769 },
10770 resumeSession: true,
10771 flags: []string{
10772 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010773 "-on-initial-select-alpn", "",
10774 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010775 },
10776 })
10777
10778 // Test that we reject early data where ALPN is omitted from the second
10779 // connection.
10780 testCases = append(testCases, testCase{
10781 testType: serverTest,
10782 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10783 config: Config{
10784 MaxVersion: VersionTLS13,
10785 NextProtos: []string{"foo"},
10786 },
10787 resumeConfig: &Config{
10788 MaxVersion: VersionTLS13,
10789 NextProtos: []string{},
10790 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010791 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010792 ExpectEarlyDataAccepted: false,
10793 },
10794 },
10795 resumeSession: true,
10796 flags: []string{
10797 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010798 "-on-initial-select-alpn", "foo",
10799 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010800 },
10801 })
10802
10803 // Test that we reject early data with mismatched ALPN.
10804 testCases = append(testCases, testCase{
10805 testType: serverTest,
10806 name: "TLS13-EarlyData-ALPNMismatch-Server",
10807 config: Config{
10808 MaxVersion: VersionTLS13,
10809 NextProtos: []string{"foo"},
10810 },
10811 resumeConfig: &Config{
10812 MaxVersion: VersionTLS13,
10813 NextProtos: []string{"bar"},
10814 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010815 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010816 ExpectEarlyDataAccepted: false,
10817 },
10818 },
10819 resumeSession: true,
10820 flags: []string{
10821 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010822 "-on-initial-select-alpn", "foo",
10823 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010824 },
10825 })
10826
David Benjamin6bb507b2017-03-29 16:35:57 -050010827 // Test that the client offering 0-RTT and Channel ID forbids the server
10828 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010829 testCases = append(testCases, testCase{
10830 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010831 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010832 config: Config{
10833 MaxVersion: VersionTLS13,
10834 MaxEarlyDataSize: 16384,
10835 RequestChannelID: true,
10836 },
10837 resumeSession: true,
10838 expectChannelID: true,
10839 shouldFail: true,
10840 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10841 flags: []string{
10842 "-enable-early-data",
10843 "-expect-early-data-info",
10844 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10845 },
10846 })
10847
David Benjamin6bb507b2017-03-29 16:35:57 -050010848 // Test that the client offering Channel ID and 0-RTT allows the server
10849 // to decline 0-RTT.
10850 testCases = append(testCases, testCase{
10851 testType: clientTest,
10852 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10853 config: Config{
10854 MaxVersion: VersionTLS13,
10855 MaxEarlyDataSize: 16384,
10856 RequestChannelID: true,
10857 Bugs: ProtocolBugs{
10858 AlwaysRejectEarlyData: true,
10859 },
10860 },
10861 resumeSession: true,
10862 expectChannelID: true,
10863 flags: []string{
10864 "-enable-early-data",
10865 "-expect-early-data-info",
10866 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10867 "-expect-reject-early-data",
10868 },
10869 })
10870
10871 // Test that the client offering Channel ID and 0-RTT allows the server
10872 // to decline Channel ID.
10873 testCases = append(testCases, testCase{
10874 testType: clientTest,
10875 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10876 config: Config{
10877 MaxVersion: VersionTLS13,
10878 MaxEarlyDataSize: 16384,
10879 },
10880 resumeSession: true,
10881 flags: []string{
10882 "-enable-early-data",
10883 "-expect-early-data-info",
10884 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10885 "-expect-accept-early-data",
10886 },
10887 })
10888
10889 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
10890 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050010891 testCases = append(testCases, testCase{
10892 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010893 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050010894 config: Config{
10895 MaxVersion: VersionTLS13,
10896 ChannelID: channelIDKey,
10897 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050010898 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050010899 ExpectEarlyDataAccepted: false,
10900 },
10901 },
10902 resumeSession: true,
10903 expectChannelID: true,
10904 flags: []string{
10905 "-enable-early-data",
10906 "-expect-reject-early-data",
10907 "-expect-channel-id",
10908 base64.StdEncoding.EncodeToString(channelIDBytes),
10909 },
10910 })
10911
David Benjamin6bb507b2017-03-29 16:35:57 -050010912 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
10913 // if not offered Channel ID.
10914 testCases = append(testCases, testCase{
10915 testType: serverTest,
10916 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
10917 config: Config{
10918 MaxVersion: VersionTLS13,
10919 Bugs: ProtocolBugs{
10920 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10921 ExpectEarlyDataAccepted: true,
10922 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10923 },
10924 },
10925 resumeSession: true,
10926 expectChannelID: false,
10927 flags: []string{
10928 "-enable-early-data",
10929 "-expect-accept-early-data",
10930 "-enable-channel-id",
10931 },
10932 })
10933
David Benjamin32c89272017-03-26 13:54:21 -050010934 // Test that the server rejects 0-RTT streams without end_of_early_data.
10935 // The subsequent records should fail to decrypt.
10936 testCases = append(testCases, testCase{
10937 testType: serverTest,
10938 name: "TLS13-EarlyData-SkipEndOfEarlyData",
10939 config: Config{
10940 MaxVersion: VersionTLS13,
10941 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010942 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050010943 ExpectEarlyDataAccepted: true,
10944 SkipEndOfEarlyData: true,
10945 },
10946 },
10947 resumeSession: true,
10948 flags: []string{"-enable-early-data"},
10949 shouldFail: true,
10950 expectedLocalError: "remote error: bad record MAC",
10951 expectedError: ":BAD_DECRYPT:",
10952 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050010953
10954 testCases = append(testCases, testCase{
10955 testType: serverTest,
10956 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
10957 config: Config{
10958 MaxVersion: VersionTLS13,
10959 },
10960 resumeConfig: &Config{
10961 MaxVersion: VersionTLS13,
10962 Bugs: ProtocolBugs{
10963 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10964 SendStrayEarlyHandshake: true,
10965 ExpectEarlyDataAccepted: true},
10966 },
10967 resumeSession: true,
10968 shouldFail: true,
10969 expectedError: ":UNEXPECTED_RECORD:",
10970 expectedLocalError: "remote error: unexpected message",
10971 flags: []string{
10972 "-enable-early-data",
10973 },
10974 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010975}
10976
David Benjaminabbbee12016-10-31 19:20:42 -040010977func addTLS13CipherPreferenceTests() {
10978 // Test that client preference is honored if the shim has AES hardware
10979 // and ChaCha20-Poly1305 is preferred otherwise.
10980 testCases = append(testCases, testCase{
10981 testType: serverTest,
10982 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
10983 config: Config{
10984 MaxVersion: VersionTLS13,
10985 CipherSuites: []uint16{
10986 TLS_CHACHA20_POLY1305_SHA256,
10987 TLS_AES_128_GCM_SHA256,
10988 },
10989 },
10990 flags: []string{
10991 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10992 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10993 },
10994 })
10995
10996 testCases = append(testCases, testCase{
10997 testType: serverTest,
10998 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
10999 config: Config{
11000 MaxVersion: VersionTLS13,
11001 CipherSuites: []uint16{
11002 TLS_AES_128_GCM_SHA256,
11003 TLS_CHACHA20_POLY1305_SHA256,
11004 },
11005 },
11006 flags: []string{
11007 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11008 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11009 },
11010 })
11011
11012 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11013 // whether it has AES hardware.
11014 testCases = append(testCases, testCase{
11015 name: "TLS13-CipherPreference-Client",
11016 config: Config{
11017 MaxVersion: VersionTLS13,
11018 // Use the client cipher order. (This is the default but
11019 // is listed to be explicit.)
11020 PreferServerCipherSuites: false,
11021 },
11022 flags: []string{
11023 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11024 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11025 },
11026 })
11027}
11028
David Benjaminf3fbade2016-09-19 13:08:16 -040011029func addPeekTests() {
11030 // Test SSL_peek works, including on empty records.
11031 testCases = append(testCases, testCase{
11032 name: "Peek-Basic",
11033 sendEmptyRecords: 1,
11034 flags: []string{"-peek-then-read"},
11035 })
11036
11037 // Test SSL_peek can drive the initial handshake.
11038 testCases = append(testCases, testCase{
11039 name: "Peek-ImplicitHandshake",
11040 flags: []string{
11041 "-peek-then-read",
11042 "-implicit-handshake",
11043 },
11044 })
11045
11046 // Test SSL_peek can discover and drive a renegotiation.
11047 testCases = append(testCases, testCase{
11048 name: "Peek-Renegotiate",
11049 config: Config{
11050 MaxVersion: VersionTLS12,
11051 },
11052 renegotiate: 1,
11053 flags: []string{
11054 "-peek-then-read",
11055 "-renegotiate-freely",
11056 "-expect-total-renegotiations", "1",
11057 },
11058 })
11059
11060 // Test SSL_peek can discover a close_notify.
11061 testCases = append(testCases, testCase{
11062 name: "Peek-Shutdown",
11063 config: Config{
11064 Bugs: ProtocolBugs{
11065 ExpectCloseNotify: true,
11066 },
11067 },
11068 flags: []string{
11069 "-peek-then-read",
11070 "-check-close-notify",
11071 },
11072 })
11073
11074 // Test SSL_peek can discover an alert.
11075 testCases = append(testCases, testCase{
11076 name: "Peek-Alert",
11077 config: Config{
11078 Bugs: ProtocolBugs{
11079 SendSpuriousAlert: alertRecordOverflow,
11080 },
11081 },
11082 flags: []string{"-peek-then-read"},
11083 shouldFail: true,
11084 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11085 })
11086
11087 // Test SSL_peek can handle KeyUpdate.
11088 testCases = append(testCases, testCase{
11089 name: "Peek-KeyUpdate",
11090 config: Config{
11091 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011092 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011093 sendKeyUpdates: 1,
11094 keyUpdateRequest: keyUpdateNotRequested,
11095 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011096 })
11097}
11098
David Benjamine6f22212016-11-08 14:28:24 -050011099func addRecordVersionTests() {
11100 for _, ver := range tlsVersions {
11101 // Test that the record version is enforced.
11102 testCases = append(testCases, testCase{
11103 name: "CheckRecordVersion-" + ver.name,
11104 config: Config{
11105 MinVersion: ver.version,
11106 MaxVersion: ver.version,
11107 Bugs: ProtocolBugs{
11108 SendRecordVersion: 0x03ff,
11109 },
11110 },
11111 shouldFail: true,
11112 expectedError: ":WRONG_VERSION_NUMBER:",
11113 })
11114
11115 // Test that the ClientHello may use any record version, for
11116 // compatibility reasons.
11117 testCases = append(testCases, testCase{
11118 testType: serverTest,
11119 name: "LooseInitialRecordVersion-" + ver.name,
11120 config: Config{
11121 MinVersion: ver.version,
11122 MaxVersion: ver.version,
11123 Bugs: ProtocolBugs{
11124 SendInitialRecordVersion: 0x03ff,
11125 },
11126 },
11127 })
11128
11129 // Test that garbage ClientHello record versions are rejected.
11130 testCases = append(testCases, testCase{
11131 testType: serverTest,
11132 name: "GarbageInitialRecordVersion-" + ver.name,
11133 config: Config{
11134 MinVersion: ver.version,
11135 MaxVersion: ver.version,
11136 Bugs: ProtocolBugs{
11137 SendInitialRecordVersion: 0xffff,
11138 },
11139 },
11140 shouldFail: true,
11141 expectedError: ":WRONG_VERSION_NUMBER:",
11142 })
11143 }
11144}
11145
David Benjamin2c516452016-11-15 10:16:54 +090011146func addCertificateTests() {
11147 // Test that a certificate chain with intermediate may be sent and
11148 // received as both client and server.
11149 for _, ver := range tlsVersions {
11150 testCases = append(testCases, testCase{
11151 testType: clientTest,
11152 name: "SendReceiveIntermediate-Client-" + ver.name,
11153 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011154 MinVersion: ver.version,
11155 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011156 Certificates: []Certificate{rsaChainCertificate},
11157 ClientAuth: RequireAnyClientCert,
11158 },
11159 expectPeerCertificate: &rsaChainCertificate,
11160 flags: []string{
11161 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11162 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11163 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11164 },
11165 })
11166
11167 testCases = append(testCases, testCase{
11168 testType: serverTest,
11169 name: "SendReceiveIntermediate-Server-" + ver.name,
11170 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011171 MinVersion: ver.version,
11172 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011173 Certificates: []Certificate{rsaChainCertificate},
11174 },
11175 expectPeerCertificate: &rsaChainCertificate,
11176 flags: []string{
11177 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11178 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11179 "-require-any-client-certificate",
11180 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11181 },
11182 })
11183 }
11184}
11185
David Benjaminbbaf3672016-11-17 10:53:09 +090011186func addRetainOnlySHA256ClientCertTests() {
11187 for _, ver := range tlsVersions {
11188 // Test that enabling
11189 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11190 // actually requesting a client certificate is a no-op.
11191 testCases = append(testCases, testCase{
11192 testType: serverTest,
11193 name: "RetainOnlySHA256-NoCert-" + ver.name,
11194 config: Config{
11195 MinVersion: ver.version,
11196 MaxVersion: ver.version,
11197 },
11198 flags: []string{
11199 "-retain-only-sha256-client-cert-initial",
11200 "-retain-only-sha256-client-cert-resume",
11201 },
11202 resumeSession: true,
11203 })
11204
11205 // Test that when retaining only a SHA-256 certificate is
11206 // enabled, the hash appears as expected.
11207 testCases = append(testCases, testCase{
11208 testType: serverTest,
11209 name: "RetainOnlySHA256-Cert-" + ver.name,
11210 config: Config{
11211 MinVersion: ver.version,
11212 MaxVersion: ver.version,
11213 Certificates: []Certificate{rsaCertificate},
11214 },
11215 flags: []string{
11216 "-verify-peer",
11217 "-retain-only-sha256-client-cert-initial",
11218 "-retain-only-sha256-client-cert-resume",
11219 "-expect-sha256-client-cert-initial",
11220 "-expect-sha256-client-cert-resume",
11221 },
11222 resumeSession: true,
11223 })
11224
11225 // Test that when the config changes from on to off, a
11226 // resumption is rejected because the server now wants the full
11227 // certificate chain.
11228 testCases = append(testCases, testCase{
11229 testType: serverTest,
11230 name: "RetainOnlySHA256-OnOff-" + ver.name,
11231 config: Config{
11232 MinVersion: ver.version,
11233 MaxVersion: ver.version,
11234 Certificates: []Certificate{rsaCertificate},
11235 },
11236 flags: []string{
11237 "-verify-peer",
11238 "-retain-only-sha256-client-cert-initial",
11239 "-expect-sha256-client-cert-initial",
11240 },
11241 resumeSession: true,
11242 expectResumeRejected: true,
11243 })
11244
11245 // Test that when the config changes from off to on, a
11246 // resumption is rejected because the server now wants just the
11247 // hash.
11248 testCases = append(testCases, testCase{
11249 testType: serverTest,
11250 name: "RetainOnlySHA256-OffOn-" + ver.name,
11251 config: Config{
11252 MinVersion: ver.version,
11253 MaxVersion: ver.version,
11254 Certificates: []Certificate{rsaCertificate},
11255 },
11256 flags: []string{
11257 "-verify-peer",
11258 "-retain-only-sha256-client-cert-resume",
11259 "-expect-sha256-client-cert-resume",
11260 },
11261 resumeSession: true,
11262 expectResumeRejected: true,
11263 })
11264 }
11265}
11266
Adam Langleya4b91982016-12-12 12:05:53 -080011267func addECDSAKeyUsageTests() {
11268 p256 := elliptic.P256()
11269 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11270 if err != nil {
11271 panic(err)
11272 }
11273
11274 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11275 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11276 if err != nil {
11277 panic(err)
11278 }
11279
11280 template := x509.Certificate{
11281 SerialNumber: serialNumber,
11282 Subject: pkix.Name{
11283 Organization: []string{"Acme Co"},
11284 },
11285 NotBefore: time.Now(),
11286 NotAfter: time.Now(),
11287
11288 // An ECC certificate with only the keyAgreement key usgae may
11289 // be used with ECDH, but not ECDSA.
11290 KeyUsage: x509.KeyUsageKeyAgreement,
11291 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11292 BasicConstraintsValid: true,
11293 }
11294
11295 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11296 if err != nil {
11297 panic(err)
11298 }
11299
11300 cert := Certificate{
11301 Certificate: [][]byte{derBytes},
11302 PrivateKey: priv,
11303 }
11304
11305 for _, ver := range tlsVersions {
11306 if ver.version < VersionTLS12 {
11307 continue
11308 }
11309
11310 testCases = append(testCases, testCase{
11311 testType: clientTest,
11312 name: "ECDSAKeyUsage-" + ver.name,
11313 config: Config{
11314 MinVersion: ver.version,
11315 MaxVersion: ver.version,
11316 Certificates: []Certificate{cert},
11317 },
11318 shouldFail: true,
11319 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11320 })
11321 }
11322}
11323
David Benjamin8c26d752017-03-26 15:13:51 -050011324func addExtraHandshakeTests() {
11325 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11326 // to ensure there is no transport I/O.
11327 testCases = append(testCases, testCase{
11328 testType: clientTest,
11329 name: "ExtraHandshake-Client-TLS12",
11330 config: Config{
11331 MinVersion: VersionTLS12,
11332 MaxVersion: VersionTLS12,
11333 },
11334 flags: []string{
11335 "-async",
11336 "-no-op-extra-handshake",
11337 },
11338 })
11339 testCases = append(testCases, testCase{
11340 testType: serverTest,
11341 name: "ExtraHandshake-Server-TLS12",
11342 config: Config{
11343 MinVersion: VersionTLS12,
11344 MaxVersion: VersionTLS12,
11345 },
11346 flags: []string{
11347 "-async",
11348 "-no-op-extra-handshake",
11349 },
11350 })
11351 testCases = append(testCases, testCase{
11352 testType: clientTest,
11353 name: "ExtraHandshake-Client-TLS13",
11354 config: Config{
11355 MinVersion: VersionTLS13,
11356 MaxVersion: VersionTLS13,
11357 },
11358 flags: []string{
11359 "-async",
11360 "-no-op-extra-handshake",
11361 },
11362 })
11363 testCases = append(testCases, testCase{
11364 testType: serverTest,
11365 name: "ExtraHandshake-Server-TLS13",
11366 config: Config{
11367 MinVersion: VersionTLS13,
11368 MaxVersion: VersionTLS13,
11369 },
11370 flags: []string{
11371 "-async",
11372 "-no-op-extra-handshake",
11373 },
11374 })
11375
11376 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11377 testCases = append(testCases, testCase{
11378 testType: serverTest,
11379 name: "ExtraHandshake-Server-EarlyData-TLS13",
11380 config: Config{
11381 MaxVersion: VersionTLS13,
11382 MinVersion: VersionTLS13,
11383 Bugs: ProtocolBugs{
11384 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11385 ExpectEarlyDataAccepted: true,
11386 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11387 },
11388 },
11389 messageCount: 2,
11390 resumeSession: true,
11391 flags: []string{
11392 "-async",
11393 "-enable-early-data",
11394 "-expect-accept-early-data",
11395 "-no-op-extra-handshake",
11396 },
11397 })
11398
11399 // An extra SSL_do_handshake drives the handshake to completion in False
11400 // Start. We test this by handshaking twice and asserting the False
11401 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11402 // how the test works.
11403 testCases = append(testCases, testCase{
11404 testType: clientTest,
11405 name: "ExtraHandshake-FalseStart",
11406 config: Config{
11407 MaxVersion: VersionTLS12,
11408 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11409 NextProtos: []string{"foo"},
11410 Bugs: ProtocolBugs{
11411 ExpectFalseStart: true,
11412 AlertBeforeFalseStartTest: alertAccessDenied,
11413 },
11414 },
11415 flags: []string{
11416 "-handshake-twice",
11417 "-false-start",
11418 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011419 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011420 },
11421 shimWritesFirst: true,
11422 shouldFail: true,
11423 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11424 expectedLocalError: "tls: peer did not false start: EOF",
11425 })
11426}
11427
Adam Langley7c803a62015-06-15 15:35:05 -070011428func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011429 defer wg.Done()
11430
11431 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011432 var err error
11433
David Benjaminba28dfc2016-11-15 17:47:21 +090011434 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011435 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11436 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011437 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011438 if err != nil {
11439 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11440 }
11441 break
11442 }
11443 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011444 } else if *repeatUntilFailure {
11445 for err == nil {
11446 statusChan <- statusMsg{test: test, started: true}
11447 err = runTest(test, shimPath, -1)
11448 }
11449 } else {
11450 statusChan <- statusMsg{test: test, started: true}
11451 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011452 }
Adam Langley95c29f32014-06-20 12:00:00 -070011453 statusChan <- statusMsg{test: test, err: err}
11454 }
11455}
11456
11457type statusMsg struct {
11458 test *testCase
11459 started bool
11460 err error
11461}
11462
David Benjamin5f237bc2015-02-11 17:14:15 -050011463func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011464 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011465
David Benjamin5f237bc2015-02-11 17:14:15 -050011466 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011467 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011468 if !*pipe {
11469 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011470 var erase string
11471 for i := 0; i < lineLen; i++ {
11472 erase += "\b \b"
11473 }
11474 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011475 }
11476
Adam Langley95c29f32014-06-20 12:00:00 -070011477 if msg.started {
11478 started++
11479 } else {
11480 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011481
11482 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011483 if msg.err == errUnimplemented {
11484 if *pipe {
11485 // Print each test instead of a status line.
11486 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11487 }
11488 unimplemented++
11489 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11490 } else {
11491 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11492 failed++
11493 testOutput.addResult(msg.test.name, "FAIL")
11494 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011495 } else {
11496 if *pipe {
11497 // Print each test instead of a status line.
11498 fmt.Printf("PASSED (%s)\n", msg.test.name)
11499 }
11500 testOutput.addResult(msg.test.name, "PASS")
11501 }
Adam Langley95c29f32014-06-20 12:00:00 -070011502 }
11503
David Benjamin5f237bc2015-02-11 17:14:15 -050011504 if !*pipe {
11505 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011506 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011507 lineLen = len(line)
11508 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011509 }
Adam Langley95c29f32014-06-20 12:00:00 -070011510 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011511
11512 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011513}
11514
11515func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011516 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011517 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011518 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011519
Adam Langley7c803a62015-06-15 15:35:05 -070011520 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011521 addCipherSuiteTests()
11522 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011523 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011524 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011525 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011526 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011527 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011528 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011529 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011530 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011531 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011532 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011533 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011534 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011535 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011536 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011537 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011538 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011539 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011540 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011541 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011542 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011543 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011544 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011545 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011546 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011547 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011548 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011549 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011550 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011551 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011552 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011553 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011554 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011555
11556 var wg sync.WaitGroup
11557
Adam Langley7c803a62015-06-15 15:35:05 -070011558 statusChan := make(chan statusMsg, *numWorkers)
11559 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011560 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011561
EKRf71d7ed2016-08-06 13:25:12 -070011562 if len(*shimConfigFile) != 0 {
11563 encoded, err := ioutil.ReadFile(*shimConfigFile)
11564 if err != nil {
11565 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11566 os.Exit(1)
11567 }
11568
11569 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11570 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11571 os.Exit(1)
11572 }
11573 }
11574
David Benjamin025b3d32014-07-01 19:53:04 -040011575 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011576
Adam Langley7c803a62015-06-15 15:35:05 -070011577 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011578 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011579 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011580 }
11581
David Benjamin270f0a72016-03-17 14:41:36 -040011582 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011583 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011584 matched := true
11585 if len(*testToRun) != 0 {
11586 var err error
11587 matched, err = filepath.Match(*testToRun, testCases[i].name)
11588 if err != nil {
11589 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11590 os.Exit(1)
11591 }
11592 }
11593
EKRf71d7ed2016-08-06 13:25:12 -070011594 if !*includeDisabled {
11595 for pattern := range shimConfig.DisabledTests {
11596 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11597 if err != nil {
11598 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11599 os.Exit(1)
11600 }
11601
11602 if isDisabled {
11603 matched = false
11604 break
11605 }
11606 }
11607 }
11608
David Benjamin17e12922016-07-28 18:04:43 -040011609 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011610 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011611 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011612
11613 // Only run one test if repeating until failure.
11614 if *repeatUntilFailure {
11615 break
11616 }
Adam Langley95c29f32014-06-20 12:00:00 -070011617 }
11618 }
David Benjamin17e12922016-07-28 18:04:43 -040011619
David Benjamin270f0a72016-03-17 14:41:36 -040011620 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011621 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011622 os.Exit(1)
11623 }
Adam Langley95c29f32014-06-20 12:00:00 -070011624
11625 close(testChan)
11626 wg.Wait()
11627 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011628 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011629
11630 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011631
11632 if *jsonOutput != "" {
11633 if err := testOutput.writeTo(*jsonOutput); err != nil {
11634 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11635 }
11636 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011637
EKR842ae6c2016-07-27 09:22:05 +020011638 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11639 os.Exit(1)
11640 }
11641
11642 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011643 os.Exit(1)
11644 }
Adam Langley95c29f32014-06-20 12:00:00 -070011645}