blob: d9218f269bea9912c96d43c5e78cf9b840e89f81 [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
Adam Langley2ff79332017-02-28 13:45:39 -0800266// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
267func encodeDERValues(values [][]byte) string {
268 var ret string
269 for i, v := range values {
270 if i > 0 {
271 ret += ","
272 }
273 ret += hex.EncodeToString(v)
274 }
275
276 return ret
277}
278
David Benjamin025b3d32014-07-01 19:53:04 -0400279type testType int
280
281const (
282 clientTest testType = iota
283 serverTest
284)
285
David Benjamin6fd297b2014-08-11 18:43:38 -0400286type protocol int
287
288const (
289 tls protocol = iota
290 dtls
291)
292
David Benjaminfc7b0862014-09-06 13:21:53 -0400293const (
294 alpn = 1
295 npn = 2
296)
297
Adam Langley95c29f32014-06-20 12:00:00 -0700298type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400299 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400300 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700301 name string
302 config Config
303 shouldFail bool
304 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700305 // expectedLocalError, if not empty, contains a substring that must be
306 // found in the local error.
307 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400308 // expectedVersion, if non-zero, specifies the TLS version that must be
309 // negotiated.
310 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400311 // expectedResumeVersion, if non-zero, specifies the TLS version that
312 // must be negotiated on resumption. If zero, expectedVersion is used.
313 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400314 // expectedCipher, if non-zero, specifies the TLS cipher suite that
315 // should be negotiated.
316 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400317 // expectChannelID controls whether the connection should have
318 // negotiated a Channel ID with channelIDKey.
319 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400320 // expectedNextProto controls whether the connection should
321 // negotiate a next protocol via NPN or ALPN.
322 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400323 // expectNoNextProto, if true, means that no next protocol should be
324 // negotiated.
325 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400326 // expectedNextProtoType, if non-zero, is the expected next
327 // protocol negotiation mechanism.
328 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500329 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
330 // should be negotiated. If zero, none should be negotiated.
331 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100332 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
333 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100334 // expectedSCTList, if not nil, is the expected SCT list to be received.
335 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700336 // expectedPeerSignatureAlgorithm, if not zero, is the signature
337 // algorithm that the peer should have used in the handshake.
338 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400339 // expectedCurveID, if not zero, is the curve that the handshake should
340 // have used.
341 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700342 // messageLen is the length, in bytes, of the test message that will be
343 // sent.
344 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400345 // messageCount is the number of test messages that will be sent.
346 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400347 // certFile is the path to the certificate to use for the server.
348 certFile string
349 // keyFile is the path to the private key to use for the server.
350 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400351 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400352 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400353 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400354 // resumeRenewedSession controls whether a third connection should be
355 // tested which attempts to resume the second connection's session.
356 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700357 // expectResumeRejected, if true, specifies that the attempted
358 // resumption must be rejected by the client. This is only valid for a
359 // serverTest.
360 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400361 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500362 // resumption. Unless newSessionsOnResume is set,
363 // SessionTicketKey, ServerSessionCache, and
364 // ClientSessionCache are copied from the initial connection's
365 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400366 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500367 // newSessionsOnResume, if true, will cause resumeConfig to
368 // use a different session resumption context.
369 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400370 // noSessionCache, if true, will cause the server to run without a
371 // session cache.
372 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400373 // sendPrefix sends a prefix on the socket before actually performing a
374 // handshake.
375 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400376 // shimWritesFirst controls whether the shim sends an initial "hello"
377 // message before doing a roundtrip with the runner.
378 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400379 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
380 // does not complete the write until responding to the first runner
381 // message.
382 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400383 // shimShutsDown, if true, runs a test where the shim shuts down the
384 // connection immediately after the handshake rather than echoing
385 // messages from the runner.
386 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400387 // renegotiate indicates the number of times the connection should be
388 // renegotiated during the exchange.
389 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400390 // sendHalfHelloRequest, if true, causes the server to send half a
391 // HelloRequest when the handshake completes.
392 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700393 // renegotiateCiphers is a list of ciphersuite ids that will be
394 // switched in just before renegotiation.
395 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500396 // replayWrites, if true, configures the underlying transport
397 // to replay every write it makes in DTLS tests.
398 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500399 // damageFirstWrite, if true, configures the underlying transport to
400 // damage the final byte of the first application data write.
401 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400402 // exportKeyingMaterial, if non-zero, configures the test to exchange
403 // keying material and verify they match.
404 exportKeyingMaterial int
405 exportLabel string
406 exportContext string
407 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400408 // flags, if not empty, contains a list of command-line flags that will
409 // be passed to the shim program.
410 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700411 // testTLSUnique, if true, causes the shim to send the tls-unique value
412 // which will be compared against the expected value.
413 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400414 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400415 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400416 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400417 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400418 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400419 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400420 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
421 // be sent before each test message.
422 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400423 // sendKeyUpdates is the number of consecutive key updates to send
424 // before and after the test message.
425 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400426 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
427 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400428 // expectMessageDropped, if true, means the test message is expected to
429 // be dropped by the client rather than echoed back.
430 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900431 // expectPeerCertificate, if not nil, is the certificate chain the peer
432 // is expected to send.
433 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500434 // shimPrefix is the prefix that the shim will send to the server.
435 shimPrefix string
436 // resumeShimPrefix is the prefix that the shim will send to the server on a
437 // resumption.
438 resumeShimPrefix string
Adam Langley95c29f32014-06-20 12:00:00 -0700439}
440
Adam Langley7c803a62015-06-15 15:35:05 -0700441var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700442
David Benjaminc07afb72016-09-22 10:18:58 -0400443func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500444 if len(data) == 0 {
445 return
446 }
447
448 protocol := "tls"
449 if test.protocol == dtls {
450 protocol = "dtls"
451 }
452
453 side := "client"
454 if test.testType == serverTest {
455 side = "server"
456 }
457
458 dir := path.Join(*transcriptDir, protocol, side)
459 if err := os.MkdirAll(dir, 0755); err != nil {
460 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
461 return
462 }
463
David Benjaminc07afb72016-09-22 10:18:58 -0400464 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500465 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
466 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
467 }
468}
469
David Benjamin3ed59772016-03-08 12:50:21 -0500470// A timeoutConn implements an idle timeout on each Read and Write operation.
471type timeoutConn struct {
472 net.Conn
473 timeout time.Duration
474}
475
476func (t *timeoutConn) Read(b []byte) (int, error) {
477 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
478 return 0, err
479 }
480 return t.Conn.Read(b)
481}
482
483func (t *timeoutConn) Write(b []byte) (int, error) {
484 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
485 return 0, err
486 }
487 return t.Conn.Write(b)
488}
489
David Benjaminc07afb72016-09-22 10:18:58 -0400490func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400491 if !test.noSessionCache {
492 if config.ClientSessionCache == nil {
493 config.ClientSessionCache = NewLRUClientSessionCache(1)
494 }
495 if config.ServerSessionCache == nil {
496 config.ServerSessionCache = NewLRUServerSessionCache(1)
497 }
498 }
499 if test.testType == clientTest {
500 if len(config.Certificates) == 0 {
501 config.Certificates = []Certificate{rsaCertificate}
502 }
503 } else {
504 // Supply a ServerName to ensure a constant session cache key,
505 // rather than falling back to net.Conn.RemoteAddr.
506 if len(config.ServerName) == 0 {
507 config.ServerName = "test"
508 }
509 }
510 if *fuzzer {
511 config.Bugs.NullAllCiphers = true
512 }
David Benjamin01a90572016-09-22 00:11:43 -0400513 if *deterministic {
514 config.Time = func() time.Time { return time.Unix(1234, 1234) }
515 }
David Benjamine54af062016-08-08 19:21:18 -0400516
David Benjamin01784b42016-06-07 18:00:52 -0400517 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500518
David Benjamin6fd297b2014-08-11 18:43:38 -0400519 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500520 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
521 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500522 }
523
David Benjamin9867b7d2016-03-01 23:25:48 -0500524 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500525 local, peer := "client", "server"
526 if test.testType == clientTest {
527 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500528 }
David Benjaminebda9b32015-11-02 15:33:18 -0500529 connDebug := &recordingConn{
530 Conn: conn,
531 isDatagram: test.protocol == dtls,
532 local: local,
533 peer: peer,
534 }
535 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500536 if *flagDebug {
537 defer connDebug.WriteTo(os.Stdout)
538 }
539 if len(*transcriptDir) != 0 {
540 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400541 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500542 }()
543 }
David Benjaminebda9b32015-11-02 15:33:18 -0500544
545 if config.Bugs.PacketAdaptor != nil {
546 config.Bugs.PacketAdaptor.debug = connDebug
547 }
548 }
549
550 if test.replayWrites {
551 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400552 }
553
David Benjamin3ed59772016-03-08 12:50:21 -0500554 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500555 if test.damageFirstWrite {
556 connDamage = newDamageAdaptor(conn)
557 conn = connDamage
558 }
559
David Benjamin6fd297b2014-08-11 18:43:38 -0400560 if test.sendPrefix != "" {
561 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
562 return err
563 }
David Benjamin98e882e2014-08-08 13:24:34 -0400564 }
565
David Benjamin1d5c83e2014-07-22 19:20:02 -0400566 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400567 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400568 if test.protocol == dtls {
569 tlsConn = DTLSServer(conn, config)
570 } else {
571 tlsConn = Server(conn, config)
572 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400573 } else {
574 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400575 if test.protocol == dtls {
576 tlsConn = DTLSClient(conn, config)
577 } else {
578 tlsConn = Client(conn, config)
579 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400580 }
David Benjamin30789da2015-08-29 22:56:45 -0400581 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400582
Adam Langley95c29f32014-06-20 12:00:00 -0700583 if err := tlsConn.Handshake(); err != nil {
584 return err
585 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700586
David Benjamin01fe8202014-09-24 15:21:44 -0400587 // TODO(davidben): move all per-connection expectations into a dedicated
588 // expectations struct that can be specified separately for the two
589 // legs.
590 expectedVersion := test.expectedVersion
591 if isResume && test.expectedResumeVersion != 0 {
592 expectedVersion = test.expectedResumeVersion
593 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700594 connState := tlsConn.ConnectionState()
595 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400596 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400597 }
598
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700599 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400600 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
601 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700602 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
603 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
604 }
David Benjamin90da8c82015-04-20 14:57:57 -0400605
David Benjamina08e49d2014-08-24 01:46:07 -0400606 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700607 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400608 if channelID == nil {
609 return fmt.Errorf("no channel ID negotiated")
610 }
611 if channelID.Curve != channelIDKey.Curve ||
612 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
613 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
614 return fmt.Errorf("incorrect channel ID")
615 }
616 }
617
David Benjaminae2888f2014-09-06 12:58:58 -0400618 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700619 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400620 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
621 }
622 }
623
David Benjaminc7ce9772015-10-09 19:32:41 -0400624 if test.expectNoNextProto {
625 if actual := connState.NegotiatedProtocol; actual != "" {
626 return fmt.Errorf("got unexpected next proto %s", actual)
627 }
628 }
629
David Benjaminfc7b0862014-09-06 13:21:53 -0400630 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700631 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400632 return fmt.Errorf("next proto type mismatch")
633 }
634 }
635
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700636 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500637 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
638 }
639
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100640 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300641 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100642 }
643
Paul Lietar4fac72e2015-09-09 13:44:55 +0100644 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
645 return fmt.Errorf("SCT list mismatch")
646 }
647
Nick Harper60edffd2016-06-21 15:19:24 -0700648 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
649 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400650 }
651
Steven Valdez5440fe02016-07-18 12:40:30 -0400652 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
653 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
654 }
655
David Benjamin2c516452016-11-15 10:16:54 +0900656 if test.expectPeerCertificate != nil {
657 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
658 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
659 }
660 for i, cert := range connState.PeerCertificates {
661 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
662 return fmt.Errorf("peer certificate %d did not match", i+1)
663 }
664 }
665 }
666
David Benjaminc565ebb2015-04-03 04:06:36 -0400667 if test.exportKeyingMaterial > 0 {
668 actual := make([]byte, test.exportKeyingMaterial)
669 if _, err := io.ReadFull(tlsConn, actual); err != nil {
670 return err
671 }
672 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
673 if err != nil {
674 return err
675 }
676 if !bytes.Equal(actual, expected) {
677 return fmt.Errorf("keying material mismatch")
678 }
679 }
680
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700681 if test.testTLSUnique {
682 var peersValue [12]byte
683 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
684 return err
685 }
686 expected := tlsConn.ConnectionState().TLSUnique
687 if !bytes.Equal(peersValue[:], expected) {
688 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
689 }
690 }
691
David Benjamin47921102016-07-28 11:29:18 -0400692 if test.sendHalfHelloRequest {
693 tlsConn.SendHalfHelloRequest()
694 }
695
Steven Valdeze831a812017-03-09 14:56:07 -0500696 shimPrefix := test.shimPrefix
697 if isResume {
698 shimPrefix = test.resumeShimPrefix
699 }
700 if test.shimWritesFirst || test.readWithUnfinishedWrite {
701 shimPrefix = "hello"
702 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400703 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400704 // If readWithUnfinishedWrite is set, the shim prefix will be
705 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500706 if shimPrefix != "" && !test.readWithUnfinishedWrite {
707 var buf = make([]byte, len(shimPrefix))
708 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400709 if err != nil {
710 return err
711 }
Steven Valdeze831a812017-03-09 14:56:07 -0500712 if string(buf) != shimPrefix {
713 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400714 }
Steven Valdeze831a812017-03-09 14:56:07 -0500715 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400716 }
717
Adam Langleycf2d4f42014-10-28 19:06:14 -0700718 if test.renegotiateCiphers != nil {
719 config.CipherSuites = test.renegotiateCiphers
720 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400721 for i := 0; i < test.renegotiate; i++ {
722 if err := tlsConn.Renegotiate(); err != nil {
723 return err
724 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700725 }
726 } else if test.renegotiateCiphers != nil {
727 panic("renegotiateCiphers without renegotiate")
728 }
729
David Benjamin5fa3eba2015-01-22 16:35:40 -0500730 if test.damageFirstWrite {
731 connDamage.setDamage(true)
732 tlsConn.Write([]byte("DAMAGED WRITE"))
733 connDamage.setDamage(false)
734 }
735
David Benjamin8e6db492015-07-25 18:29:23 -0400736 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700737 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400738 if test.protocol == dtls {
739 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
740 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700741 // Read until EOF.
742 _, err := io.Copy(ioutil.Discard, tlsConn)
743 return err
744 }
David Benjamin4417d052015-04-05 04:17:25 -0400745 if messageLen == 0 {
746 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700747 }
Adam Langley95c29f32014-06-20 12:00:00 -0700748
David Benjamin8e6db492015-07-25 18:29:23 -0400749 messageCount := test.messageCount
750 if messageCount == 0 {
751 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400752 }
753
David Benjamin8e6db492015-07-25 18:29:23 -0400754 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400755 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400756 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400757 }
758
David Benjamin8e6db492015-07-25 18:29:23 -0400759 for i := 0; i < test.sendEmptyRecords; i++ {
760 tlsConn.Write(nil)
761 }
762
763 for i := 0; i < test.sendWarningAlerts; i++ {
764 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
765 }
766
David Benjamin24e58862017-06-14 18:45:29 -0400767 if test.sendBogusAlertType {
768 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
769 }
770
David Benjaminbbba9392017-04-06 12:54:12 -0400771 testMessage := make([]byte, messageLen)
772 for i := range testMessage {
773 testMessage[i] = 0x42 ^ byte(j)
774 }
775 tlsConn.Write(testMessage)
776
777 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500778 if shimPrefix != "" {
779 var buf = make([]byte, len(shimPrefix))
780 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400781 if err != nil {
782 return err
783 }
Steven Valdeze831a812017-03-09 14:56:07 -0500784 if string(buf) != shimPrefix {
785 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400786 }
Steven Valdeze831a812017-03-09 14:56:07 -0500787 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400788 }
789
David Benjamin4f75aaf2015-09-01 16:53:10 -0400790 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400791 // The shim will not respond.
792 continue
793 }
794
David Benjaminbbba9392017-04-06 12:54:12 -0400795 // Process the KeyUpdate ACK. However many KeyUpdates the runner
796 // sends, the shim should respond only once.
797 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
798 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
799 return err
800 }
801 }
802
David Benjamin8e6db492015-07-25 18:29:23 -0400803 buf := make([]byte, len(testMessage))
804 if test.protocol == dtls {
805 bufTmp := make([]byte, len(buf)+1)
806 n, err := tlsConn.Read(bufTmp)
807 if err != nil {
808 return err
809 }
810 if n != len(buf) {
811 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
812 }
813 copy(buf, bufTmp)
814 } else {
815 _, err := io.ReadFull(tlsConn, buf)
816 if err != nil {
817 return err
818 }
819 }
820
821 for i, v := range buf {
822 if v != testMessage[i]^0xff {
823 return fmt.Errorf("bad reply contents at byte %d", i)
824 }
Adam Langley95c29f32014-06-20 12:00:00 -0700825 }
826 }
827
828 return nil
829}
830
David Benjamin325b5c32014-07-01 19:40:31 -0400831func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400832 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700833 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400834 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700835 }
David Benjamin325b5c32014-07-01 19:40:31 -0400836 valgrindArgs = append(valgrindArgs, path)
837 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700838
David Benjamin325b5c32014-07-01 19:40:31 -0400839 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700840}
841
David Benjamin325b5c32014-07-01 19:40:31 -0400842func gdbOf(path string, args ...string) *exec.Cmd {
843 xtermArgs := []string{"-e", "gdb", "--args"}
844 xtermArgs = append(xtermArgs, path)
845 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700846
David Benjamin325b5c32014-07-01 19:40:31 -0400847 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700848}
849
David Benjamind16bf342015-12-18 00:53:12 -0500850func lldbOf(path string, args ...string) *exec.Cmd {
851 xtermArgs := []string{"-e", "lldb", "--"}
852 xtermArgs = append(xtermArgs, path)
853 xtermArgs = append(xtermArgs, args...)
854
855 return exec.Command("xterm", xtermArgs...)
856}
857
EKR842ae6c2016-07-27 09:22:05 +0200858var (
859 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
860 errUnimplemented = errors.New("child process does not implement needed flags")
861)
Adam Langley69a01602014-11-17 17:26:55 -0800862
David Benjamin87c8a642015-02-21 01:54:29 -0500863// accept accepts a connection from listener, unless waitChan signals a process
864// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400865func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500866 type connOrError struct {
867 conn net.Conn
868 err error
869 }
870 connChan := make(chan connOrError, 1)
871 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400872 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500873 conn, err := listener.Accept()
874 connChan <- connOrError{conn, err}
875 close(connChan)
876 }()
877 select {
878 case result := <-connChan:
879 return result.conn, result.err
880 case childErr := <-waitChan:
881 waitChan <- childErr
882 return nil, fmt.Errorf("child exited early: %s", childErr)
883 }
884}
885
EKRf71d7ed2016-08-06 13:25:12 -0700886func translateExpectedError(errorStr string) string {
887 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
888 return translated
889 }
890
891 if *looseErrors {
892 return ""
893 }
894
895 return errorStr
896}
897
Adam Langley7c803a62015-06-15 15:35:05 -0700898func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400899 // Help debugging panics on the Go side.
900 defer func() {
901 if r := recover(); r != nil {
902 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
903 panic(r)
904 }
905 }()
906
Adam Langley38311732014-10-16 19:04:35 -0700907 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
908 panic("Error expected without shouldFail in " + test.name)
909 }
910
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700911 if test.expectResumeRejected && !test.resumeSession {
912 panic("expectResumeRejected without resumeSession in " + test.name)
913 }
914
Adam Langley33b1d4f2016-12-07 15:03:45 -0800915 for _, ver := range tlsVersions {
916 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
917 continue
918 }
919
920 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
921 continue
922 }
923
924 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))
925 }
926
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700927 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
928 if err != nil {
929 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
930 }
David Benjamin87c8a642015-02-21 01:54:29 -0500931 if err != nil {
932 panic(err)
933 }
934 defer func() {
935 if listener != nil {
936 listener.Close()
937 }
938 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700939
David Benjamin87c8a642015-02-21 01:54:29 -0500940 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400941 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400942 flags = append(flags, "-server")
943
David Benjamin025b3d32014-07-01 19:53:04 -0400944 flags = append(flags, "-key-file")
945 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700946 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400947 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700948 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400949 }
950
951 flags = append(flags, "-cert-file")
952 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700953 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400954 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700955 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400956 }
957 }
David Benjamin5a593af2014-08-11 19:51:50 -0400958
David Benjamin6fd297b2014-08-11 18:43:38 -0400959 if test.protocol == dtls {
960 flags = append(flags, "-dtls")
961 }
962
David Benjamin46662482016-08-17 00:51:00 -0400963 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400964 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400965 resumeCount++
966 if test.resumeRenewedSession {
967 resumeCount++
968 }
969 }
970
971 if resumeCount > 0 {
972 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400973 }
974
David Benjamine58c4f52014-08-24 03:47:07 -0400975 if test.shimWritesFirst {
976 flags = append(flags, "-shim-writes-first")
977 }
978
David Benjaminbbba9392017-04-06 12:54:12 -0400979 if test.readWithUnfinishedWrite {
980 flags = append(flags, "-read-with-unfinished-write")
981 }
982
David Benjamin30789da2015-08-29 22:56:45 -0400983 if test.shimShutsDown {
984 flags = append(flags, "-shim-shuts-down")
985 }
986
David Benjaminc565ebb2015-04-03 04:06:36 -0400987 if test.exportKeyingMaterial > 0 {
988 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
989 flags = append(flags, "-export-label", test.exportLabel)
990 flags = append(flags, "-export-context", test.exportContext)
991 if test.useExportContext {
992 flags = append(flags, "-use-export-context")
993 }
994 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700995 if test.expectResumeRejected {
996 flags = append(flags, "-expect-session-miss")
997 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400998
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700999 if test.testTLSUnique {
1000 flags = append(flags, "-tls-unique")
1001 }
1002
David Benjamin025b3d32014-07-01 19:53:04 -04001003 flags = append(flags, test.flags...)
1004
1005 var shim *exec.Cmd
1006 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001007 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001008 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001009 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001010 } else if *useLLDB {
1011 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001012 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001013 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001014 }
David Benjamin025b3d32014-07-01 19:53:04 -04001015 shim.Stdin = os.Stdin
1016 var stdoutBuf, stderrBuf bytes.Buffer
1017 shim.Stdout = &stdoutBuf
1018 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001019 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001020 shim.Env = os.Environ()
1021 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001022 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001023 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001024 }
1025 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1026 }
David Benjamin025b3d32014-07-01 19:53:04 -04001027
1028 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001029 panic(err)
1030 }
David Benjamin87c8a642015-02-21 01:54:29 -05001031 waitChan := make(chan error, 1)
1032 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001033
1034 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001035
David Benjamin7a4aaa42016-09-20 17:58:14 -04001036 if *deterministic {
1037 config.Rand = &deterministicRand{}
1038 }
1039
David Benjamin87c8a642015-02-21 01:54:29 -05001040 conn, err := acceptOrWait(listener, waitChan)
1041 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001042 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001043 conn.Close()
1044 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001045
David Benjamin46662482016-08-17 00:51:00 -04001046 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001047 var resumeConfig Config
1048 if test.resumeConfig != nil {
1049 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001050 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001051 resumeConfig.SessionTicketKey = config.SessionTicketKey
1052 resumeConfig.ClientSessionCache = config.ClientSessionCache
1053 resumeConfig.ServerSessionCache = config.ServerSessionCache
1054 }
David Benjamin2e045a92016-06-08 13:09:56 -04001055 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001056 } else {
1057 resumeConfig = config
1058 }
David Benjamin87c8a642015-02-21 01:54:29 -05001059 var connResume net.Conn
1060 connResume, err = acceptOrWait(listener, waitChan)
1061 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001062 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001063 connResume.Close()
1064 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001065 }
1066
David Benjamin87c8a642015-02-21 01:54:29 -05001067 // Close the listener now. This is to avoid hangs should the shim try to
1068 // open more connections than expected.
1069 listener.Close()
1070 listener = nil
1071
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001072 var shimKilledLock sync.Mutex
1073 var shimKilled bool
1074 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1075 shimKilledLock.Lock()
1076 shimKilled = true
1077 shimKilledLock.Unlock()
1078 shim.Process.Kill()
1079 })
David Benjamin87c8a642015-02-21 01:54:29 -05001080 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001081 waitTimeout.Stop()
1082 shimKilledLock.Lock()
1083 if shimKilled && err == nil {
1084 err = errors.New("timeout waiting for the shim to exit.")
1085 }
1086 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001087 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001088 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001089 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1090 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001091 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001092 case 89:
1093 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001094 case 99:
1095 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001096 }
1097 }
Adam Langley95c29f32014-06-20 12:00:00 -07001098
David Benjamin9bea3492016-03-02 10:59:16 -05001099 // Account for Windows line endings.
1100 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1101 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001102
1103 // Separate the errors from the shim and those from tools like
1104 // AddressSanitizer.
1105 var extraStderr string
1106 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1107 stderr = stderrParts[0]
1108 extraStderr = stderrParts[1]
1109 }
1110
Adam Langley95c29f32014-06-20 12:00:00 -07001111 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001112 expectedError := translateExpectedError(test.expectedError)
1113 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001114
Adam Langleyac61fa32014-06-23 12:03:11 -07001115 localError := "none"
1116 if err != nil {
1117 localError = err.Error()
1118 }
1119 if len(test.expectedLocalError) != 0 {
1120 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1121 }
Adam Langley95c29f32014-06-20 12:00:00 -07001122
1123 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001124 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001125 if childErr != nil {
1126 childError = childErr.Error()
1127 }
1128
1129 var msg string
1130 switch {
1131 case failed && !test.shouldFail:
1132 msg = "unexpected failure"
1133 case !failed && test.shouldFail:
1134 msg = "unexpected success"
1135 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001136 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001137 default:
1138 panic("internal error")
1139 }
1140
David Benjamin9aafb642016-09-20 19:36:53 -04001141 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 -07001142 }
1143
David Benjamind2ba8892016-09-20 19:41:04 -04001144 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001145 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001146 }
1147
David Benjamind2ba8892016-09-20 19:41:04 -04001148 if *useValgrind && isValgrindError {
1149 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1150 }
1151
Adam Langley95c29f32014-06-20 12:00:00 -07001152 return nil
1153}
1154
David Benjaminaa012042016-12-10 13:33:05 -05001155type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001156 name string
1157 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001158 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001159 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001160}
1161
1162var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001163 {"SSL3", VersionSSL30, "-no-ssl3", false},
1164 {"TLS1", VersionTLS10, "-no-tls1", true},
1165 {"TLS11", VersionTLS11, "-no-tls11", false},
1166 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001167 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001168}
1169
David Benjaminaa012042016-12-10 13:33:05 -05001170type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001171 name string
1172 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001173}
1174
1175var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001176 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001177 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001178 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001179 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001180 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001181 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001182 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001183 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1184 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001185 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1186 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001187 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001188 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001189 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001190 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001191 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001192 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001193 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001194 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001195 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001196 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001197 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1198 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001199 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1200 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001201 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001202 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1203 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1204 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001205 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001206}
1207
David Benjamin8b8c0062014-11-23 02:47:52 -05001208func hasComponent(suiteName, component string) bool {
1209 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1210}
1211
David Benjaminf7768e42014-08-31 02:06:47 -04001212func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001213 return hasComponent(suiteName, "GCM") ||
1214 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001215 hasComponent(suiteName, "SHA384") ||
1216 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001217}
1218
Nick Harper1fd39d82016-06-14 18:14:35 -07001219func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001220 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001221}
1222
David Benjamin8b8c0062014-11-23 02:47:52 -05001223func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001224 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001225}
1226
Adam Langleya7997f12015-05-14 17:38:50 -07001227func bigFromHex(hex string) *big.Int {
1228 ret, ok := new(big.Int).SetString(hex, 16)
1229 if !ok {
1230 panic("failed to parse hex number 0x" + hex)
1231 }
1232 return ret
1233}
1234
Adam Langley7c803a62015-06-15 15:35:05 -07001235func addBasicTests() {
1236 basicTests := []testCase{
1237 {
Adam Langley7c803a62015-06-15 15:35:05 -07001238 name: "NoFallbackSCSV",
1239 config: Config{
1240 Bugs: ProtocolBugs{
1241 FailIfNotFallbackSCSV: true,
1242 },
1243 },
1244 shouldFail: true,
1245 expectedLocalError: "no fallback SCSV found",
1246 },
1247 {
1248 name: "SendFallbackSCSV",
1249 config: Config{
1250 Bugs: ProtocolBugs{
1251 FailIfNotFallbackSCSV: true,
1252 },
1253 },
1254 flags: []string{"-fallback-scsv"},
1255 },
1256 {
1257 name: "ClientCertificateTypes",
1258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001260 ClientAuth: RequestClientCert,
1261 ClientCertificateTypes: []byte{
1262 CertTypeDSSSign,
1263 CertTypeRSASign,
1264 CertTypeECDSASign,
1265 },
1266 },
1267 flags: []string{
1268 "-expect-certificate-types",
1269 base64.StdEncoding.EncodeToString([]byte{
1270 CertTypeDSSSign,
1271 CertTypeRSASign,
1272 CertTypeECDSASign,
1273 }),
1274 },
1275 },
1276 {
Adam Langley7c803a62015-06-15 15:35:05 -07001277 name: "UnauthenticatedECDH",
1278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001279 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001280 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1281 Bugs: ProtocolBugs{
1282 UnauthenticatedECDH: true,
1283 },
1284 },
1285 shouldFail: true,
1286 expectedError: ":UNEXPECTED_MESSAGE:",
1287 },
1288 {
1289 name: "SkipCertificateStatus",
1290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001291 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001292 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1293 Bugs: ProtocolBugs{
1294 SkipCertificateStatus: true,
1295 },
1296 },
1297 flags: []string{
1298 "-enable-ocsp-stapling",
1299 },
1300 },
1301 {
1302 name: "SkipServerKeyExchange",
1303 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001304 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001305 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1306 Bugs: ProtocolBugs{
1307 SkipServerKeyExchange: true,
1308 },
1309 },
1310 shouldFail: true,
1311 expectedError: ":UNEXPECTED_MESSAGE:",
1312 },
1313 {
Adam Langley7c803a62015-06-15 15:35:05 -07001314 testType: serverTest,
1315 name: "Alert",
1316 config: Config{
1317 Bugs: ProtocolBugs{
1318 SendSpuriousAlert: alertRecordOverflow,
1319 },
1320 },
1321 shouldFail: true,
1322 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1323 },
1324 {
1325 protocol: dtls,
1326 testType: serverTest,
1327 name: "Alert-DTLS",
1328 config: Config{
1329 Bugs: ProtocolBugs{
1330 SendSpuriousAlert: alertRecordOverflow,
1331 },
1332 },
1333 shouldFail: true,
1334 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1335 },
1336 {
1337 testType: serverTest,
1338 name: "FragmentAlert",
1339 config: Config{
1340 Bugs: ProtocolBugs{
1341 FragmentAlert: true,
1342 SendSpuriousAlert: alertRecordOverflow,
1343 },
1344 },
1345 shouldFail: true,
1346 expectedError: ":BAD_ALERT:",
1347 },
1348 {
1349 protocol: dtls,
1350 testType: serverTest,
1351 name: "FragmentAlert-DTLS",
1352 config: Config{
1353 Bugs: ProtocolBugs{
1354 FragmentAlert: true,
1355 SendSpuriousAlert: alertRecordOverflow,
1356 },
1357 },
1358 shouldFail: true,
1359 expectedError: ":BAD_ALERT:",
1360 },
1361 {
1362 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001363 name: "DoubleAlert",
1364 config: Config{
1365 Bugs: ProtocolBugs{
1366 DoubleAlert: true,
1367 SendSpuriousAlert: alertRecordOverflow,
1368 },
1369 },
1370 shouldFail: true,
1371 expectedError: ":BAD_ALERT:",
1372 },
1373 {
1374 protocol: dtls,
1375 testType: serverTest,
1376 name: "DoubleAlert-DTLS",
1377 config: Config{
1378 Bugs: ProtocolBugs{
1379 DoubleAlert: true,
1380 SendSpuriousAlert: alertRecordOverflow,
1381 },
1382 },
1383 shouldFail: true,
1384 expectedError: ":BAD_ALERT:",
1385 },
1386 {
Adam Langley7c803a62015-06-15 15:35:05 -07001387 name: "SkipNewSessionTicket",
1388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001389 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001390 Bugs: ProtocolBugs{
1391 SkipNewSessionTicket: true,
1392 },
1393 },
1394 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001395 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001396 },
1397 {
1398 testType: serverTest,
1399 name: "FallbackSCSV",
1400 config: Config{
1401 MaxVersion: VersionTLS11,
1402 Bugs: ProtocolBugs{
1403 SendFallbackSCSV: true,
1404 },
1405 },
David Benjamin56cadc32016-12-16 19:54:11 -05001406 shouldFail: true,
1407 expectedError: ":INAPPROPRIATE_FALLBACK:",
1408 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001409 },
1410 {
1411 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001412 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001413 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001414 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001415 Bugs: ProtocolBugs{
1416 SendFallbackSCSV: true,
1417 },
1418 },
1419 },
1420 {
1421 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001422 name: "FallbackSCSV-VersionMatch-TLS12",
1423 config: Config{
1424 MaxVersion: VersionTLS12,
1425 Bugs: ProtocolBugs{
1426 SendFallbackSCSV: true,
1427 },
1428 },
1429 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1430 },
1431 {
1432 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001433 name: "FragmentedClientVersion",
1434 config: Config{
1435 Bugs: ProtocolBugs{
1436 MaxHandshakeRecordLength: 1,
1437 FragmentClientVersion: true,
1438 },
1439 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001440 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001441 },
1442 {
Adam Langley7c803a62015-06-15 15:35:05 -07001443 testType: serverTest,
1444 name: "HttpGET",
1445 sendPrefix: "GET / HTTP/1.0\n",
1446 shouldFail: true,
1447 expectedError: ":HTTP_REQUEST:",
1448 },
1449 {
1450 testType: serverTest,
1451 name: "HttpPOST",
1452 sendPrefix: "POST / HTTP/1.0\n",
1453 shouldFail: true,
1454 expectedError: ":HTTP_REQUEST:",
1455 },
1456 {
1457 testType: serverTest,
1458 name: "HttpHEAD",
1459 sendPrefix: "HEAD / HTTP/1.0\n",
1460 shouldFail: true,
1461 expectedError: ":HTTP_REQUEST:",
1462 },
1463 {
1464 testType: serverTest,
1465 name: "HttpPUT",
1466 sendPrefix: "PUT / HTTP/1.0\n",
1467 shouldFail: true,
1468 expectedError: ":HTTP_REQUEST:",
1469 },
1470 {
1471 testType: serverTest,
1472 name: "HttpCONNECT",
1473 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1474 shouldFail: true,
1475 expectedError: ":HTTPS_PROXY_REQUEST:",
1476 },
1477 {
1478 testType: serverTest,
1479 name: "Garbage",
1480 sendPrefix: "blah",
1481 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001482 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001483 },
1484 {
Adam Langley7c803a62015-06-15 15:35:05 -07001485 name: "RSAEphemeralKey",
1486 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001487 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001488 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1489 Bugs: ProtocolBugs{
1490 RSAEphemeralKey: true,
1491 },
1492 },
1493 shouldFail: true,
1494 expectedError: ":UNEXPECTED_MESSAGE:",
1495 },
1496 {
1497 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001498 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001499 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001500 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001501 },
1502 {
1503 protocol: dtls,
1504 name: "DisableEverything-DTLS",
1505 flags: []string{"-no-tls12", "-no-tls1"},
1506 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001507 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001508 },
1509 {
Adam Langley7c803a62015-06-15 15:35:05 -07001510 protocol: dtls,
1511 testType: serverTest,
1512 name: "MTU",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 MaxPacketLength: 256,
1516 },
1517 },
1518 flags: []string{"-mtu", "256"},
1519 },
1520 {
1521 protocol: dtls,
1522 testType: serverTest,
1523 name: "MTUExceeded",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 MaxPacketLength: 255,
1527 },
1528 },
1529 flags: []string{"-mtu", "256"},
1530 shouldFail: true,
1531 expectedLocalError: "dtls: exceeded maximum packet length",
1532 },
1533 {
Adam Langley7c803a62015-06-15 15:35:05 -07001534 name: "EmptyCertificateList",
1535 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001536 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001537 Bugs: ProtocolBugs{
1538 EmptyCertificateList: true,
1539 },
1540 },
1541 shouldFail: true,
1542 expectedError: ":DECODE_ERROR:",
1543 },
1544 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001545 name: "EmptyCertificateList-TLS13",
1546 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001547 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001548 Bugs: ProtocolBugs{
1549 EmptyCertificateList: true,
1550 },
1551 },
1552 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001553 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001554 },
1555 {
Adam Langley7c803a62015-06-15 15:35:05 -07001556 name: "TLSFatalBadPackets",
1557 damageFirstWrite: true,
1558 shouldFail: true,
1559 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1560 },
1561 {
1562 protocol: dtls,
1563 name: "DTLSIgnoreBadPackets",
1564 damageFirstWrite: true,
1565 },
1566 {
1567 protocol: dtls,
1568 name: "DTLSIgnoreBadPackets-Async",
1569 damageFirstWrite: true,
1570 flags: []string{"-async"},
1571 },
1572 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001573 name: "AppDataBeforeHandshake",
1574 config: Config{
1575 Bugs: ProtocolBugs{
1576 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1577 },
1578 },
1579 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001580 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001581 },
1582 {
1583 name: "AppDataBeforeHandshake-Empty",
1584 config: Config{
1585 Bugs: ProtocolBugs{
1586 AppDataBeforeHandshake: []byte{},
1587 },
1588 },
1589 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001590 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001591 },
1592 {
1593 protocol: dtls,
1594 name: "AppDataBeforeHandshake-DTLS",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1598 },
1599 },
1600 shouldFail: true,
1601 expectedError: ":UNEXPECTED_RECORD:",
1602 },
1603 {
1604 protocol: dtls,
1605 name: "AppDataBeforeHandshake-DTLS-Empty",
1606 config: Config{
1607 Bugs: ProtocolBugs{
1608 AppDataBeforeHandshake: []byte{},
1609 },
1610 },
1611 shouldFail: true,
1612 expectedError: ":UNEXPECTED_RECORD:",
1613 },
1614 {
Adam Langley7c803a62015-06-15 15:35:05 -07001615 name: "AppDataAfterChangeCipherSpec",
1616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001617 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001618 Bugs: ProtocolBugs{
1619 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1620 },
1621 },
1622 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001623 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001624 },
1625 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001626 name: "AppDataAfterChangeCipherSpec-Empty",
1627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001628 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001629 Bugs: ProtocolBugs{
1630 AppDataAfterChangeCipherSpec: []byte{},
1631 },
1632 },
1633 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001634 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001635 },
1636 {
Adam Langley7c803a62015-06-15 15:35:05 -07001637 protocol: dtls,
1638 name: "AppDataAfterChangeCipherSpec-DTLS",
1639 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001640 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001641 Bugs: ProtocolBugs{
1642 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1643 },
1644 },
1645 // BoringSSL's DTLS implementation will drop the out-of-order
1646 // application data.
1647 },
1648 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001649 protocol: dtls,
1650 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1651 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001652 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001653 Bugs: ProtocolBugs{
1654 AppDataAfterChangeCipherSpec: []byte{},
1655 },
1656 },
1657 // BoringSSL's DTLS implementation will drop the out-of-order
1658 // application data.
1659 },
1660 {
Adam Langley7c803a62015-06-15 15:35:05 -07001661 name: "AlertAfterChangeCipherSpec",
1662 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001663 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001664 Bugs: ProtocolBugs{
1665 AlertAfterChangeCipherSpec: alertRecordOverflow,
1666 },
1667 },
1668 shouldFail: true,
1669 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1670 },
1671 {
1672 protocol: dtls,
1673 name: "AlertAfterChangeCipherSpec-DTLS",
1674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001675 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001676 Bugs: ProtocolBugs{
1677 AlertAfterChangeCipherSpec: alertRecordOverflow,
1678 },
1679 },
1680 shouldFail: true,
1681 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1682 },
1683 {
1684 protocol: dtls,
1685 name: "ReorderHandshakeFragments-Small-DTLS",
1686 config: Config{
1687 Bugs: ProtocolBugs{
1688 ReorderHandshakeFragments: true,
1689 // Small enough that every handshake message is
1690 // fragmented.
1691 MaxHandshakeRecordLength: 2,
1692 },
1693 },
1694 },
1695 {
1696 protocol: dtls,
1697 name: "ReorderHandshakeFragments-Large-DTLS",
1698 config: Config{
1699 Bugs: ProtocolBugs{
1700 ReorderHandshakeFragments: true,
1701 // Large enough that no handshake message is
1702 // fragmented.
1703 MaxHandshakeRecordLength: 2048,
1704 },
1705 },
1706 },
1707 {
1708 protocol: dtls,
1709 name: "MixCompleteMessageWithFragments-DTLS",
1710 config: Config{
1711 Bugs: ProtocolBugs{
1712 ReorderHandshakeFragments: true,
1713 MixCompleteMessageWithFragments: true,
1714 MaxHandshakeRecordLength: 2,
1715 },
1716 },
1717 },
1718 {
1719 name: "SendInvalidRecordType",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 SendInvalidRecordType: true,
1723 },
1724 },
1725 shouldFail: true,
1726 expectedError: ":UNEXPECTED_RECORD:",
1727 },
1728 {
1729 protocol: dtls,
1730 name: "SendInvalidRecordType-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 SendInvalidRecordType: true,
1734 },
1735 },
1736 shouldFail: true,
1737 expectedError: ":UNEXPECTED_RECORD:",
1738 },
1739 {
1740 name: "FalseStart-SkipServerSecondLeg",
1741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001742 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1744 NextProtos: []string{"foo"},
1745 Bugs: ProtocolBugs{
1746 SkipNewSessionTicket: true,
1747 SkipChangeCipherSpec: true,
1748 SkipFinished: true,
1749 ExpectFalseStart: true,
1750 },
1751 },
1752 flags: []string{
1753 "-false-start",
1754 "-handshake-never-done",
1755 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001756 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001757 },
1758 shimWritesFirst: true,
1759 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001760 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 },
1762 {
1763 name: "FalseStart-SkipServerSecondLeg-Implicit",
1764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001765 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1767 NextProtos: []string{"foo"},
1768 Bugs: ProtocolBugs{
1769 SkipNewSessionTicket: true,
1770 SkipChangeCipherSpec: true,
1771 SkipFinished: true,
1772 },
1773 },
1774 flags: []string{
1775 "-implicit-handshake",
1776 "-false-start",
1777 "-handshake-never-done",
1778 "-advertise-alpn", "\x03foo",
1779 },
1780 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001781 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001782 },
1783 {
1784 testType: serverTest,
1785 name: "FailEarlyCallback",
1786 flags: []string{"-fail-early-callback"},
1787 shouldFail: true,
1788 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001789 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001790 },
1791 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001792 name: "FailCertCallback-Client-TLS12",
1793 config: Config{
1794 MaxVersion: VersionTLS12,
1795 ClientAuth: RequestClientCert,
1796 },
1797 flags: []string{"-fail-cert-callback"},
1798 shouldFail: true,
1799 expectedError: ":CERT_CB_ERROR:",
1800 expectedLocalError: "remote error: internal error",
1801 },
1802 {
1803 testType: serverTest,
1804 name: "FailCertCallback-Server-TLS12",
1805 config: Config{
1806 MaxVersion: VersionTLS12,
1807 },
1808 flags: []string{"-fail-cert-callback"},
1809 shouldFail: true,
1810 expectedError: ":CERT_CB_ERROR:",
1811 expectedLocalError: "remote error: internal error",
1812 },
1813 {
1814 name: "FailCertCallback-Client-TLS13",
1815 config: Config{
1816 MaxVersion: VersionTLS13,
1817 ClientAuth: RequestClientCert,
1818 },
1819 flags: []string{"-fail-cert-callback"},
1820 shouldFail: true,
1821 expectedError: ":CERT_CB_ERROR:",
1822 expectedLocalError: "remote error: internal error",
1823 },
1824 {
1825 testType: serverTest,
1826 name: "FailCertCallback-Server-TLS13",
1827 config: Config{
1828 MaxVersion: VersionTLS13,
1829 },
1830 flags: []string{"-fail-cert-callback"},
1831 shouldFail: true,
1832 expectedError: ":CERT_CB_ERROR:",
1833 expectedLocalError: "remote error: internal error",
1834 },
1835 {
Adam Langley7c803a62015-06-15 15:35:05 -07001836 protocol: dtls,
1837 name: "FragmentMessageTypeMismatch-DTLS",
1838 config: Config{
1839 Bugs: ProtocolBugs{
1840 MaxHandshakeRecordLength: 2,
1841 FragmentMessageTypeMismatch: true,
1842 },
1843 },
1844 shouldFail: true,
1845 expectedError: ":FRAGMENT_MISMATCH:",
1846 },
1847 {
1848 protocol: dtls,
1849 name: "FragmentMessageLengthMismatch-DTLS",
1850 config: Config{
1851 Bugs: ProtocolBugs{
1852 MaxHandshakeRecordLength: 2,
1853 FragmentMessageLengthMismatch: true,
1854 },
1855 },
1856 shouldFail: true,
1857 expectedError: ":FRAGMENT_MISMATCH:",
1858 },
1859 {
1860 protocol: dtls,
1861 name: "SplitFragments-Header-DTLS",
1862 config: Config{
1863 Bugs: ProtocolBugs{
1864 SplitFragments: 2,
1865 },
1866 },
1867 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001868 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001869 },
1870 {
1871 protocol: dtls,
1872 name: "SplitFragments-Boundary-DTLS",
1873 config: Config{
1874 Bugs: ProtocolBugs{
1875 SplitFragments: dtlsRecordHeaderLen,
1876 },
1877 },
1878 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001879 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001880 },
1881 {
1882 protocol: dtls,
1883 name: "SplitFragments-Body-DTLS",
1884 config: Config{
1885 Bugs: ProtocolBugs{
1886 SplitFragments: dtlsRecordHeaderLen + 1,
1887 },
1888 },
1889 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001890 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001891 },
1892 {
1893 protocol: dtls,
1894 name: "SendEmptyFragments-DTLS",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 SendEmptyFragments: true,
1898 },
1899 },
1900 },
1901 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001902 name: "BadFinished-Client",
1903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001904 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001905 Bugs: ProtocolBugs{
1906 BadFinished: true,
1907 },
1908 },
1909 shouldFail: true,
1910 expectedError: ":DIGEST_CHECK_FAILED:",
1911 },
1912 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001913 name: "BadFinished-Client-TLS13",
1914 config: Config{
1915 MaxVersion: VersionTLS13,
1916 Bugs: ProtocolBugs{
1917 BadFinished: true,
1918 },
1919 },
1920 shouldFail: true,
1921 expectedError: ":DIGEST_CHECK_FAILED:",
1922 },
1923 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001924 testType: serverTest,
1925 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001926 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001927 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001928 Bugs: ProtocolBugs{
1929 BadFinished: true,
1930 },
1931 },
1932 shouldFail: true,
1933 expectedError: ":DIGEST_CHECK_FAILED:",
1934 },
1935 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001936 testType: serverTest,
1937 name: "BadFinished-Server-TLS13",
1938 config: Config{
1939 MaxVersion: VersionTLS13,
1940 Bugs: ProtocolBugs{
1941 BadFinished: true,
1942 },
1943 },
1944 shouldFail: true,
1945 expectedError: ":DIGEST_CHECK_FAILED:",
1946 },
1947 {
Adam Langley7c803a62015-06-15 15:35:05 -07001948 name: "FalseStart-BadFinished",
1949 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001950 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001951 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1952 NextProtos: []string{"foo"},
1953 Bugs: ProtocolBugs{
1954 BadFinished: true,
1955 ExpectFalseStart: true,
1956 },
1957 },
1958 flags: []string{
1959 "-false-start",
1960 "-handshake-never-done",
1961 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001962 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001963 },
1964 shimWritesFirst: true,
1965 shouldFail: true,
1966 expectedError: ":DIGEST_CHECK_FAILED:",
1967 },
1968 {
1969 name: "NoFalseStart-NoALPN",
1970 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001971 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001972 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1973 Bugs: ProtocolBugs{
1974 ExpectFalseStart: true,
1975 AlertBeforeFalseStartTest: alertAccessDenied,
1976 },
1977 },
1978 flags: []string{
1979 "-false-start",
1980 },
1981 shimWritesFirst: true,
1982 shouldFail: true,
1983 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1984 expectedLocalError: "tls: peer did not false start: EOF",
1985 },
1986 {
1987 name: "NoFalseStart-NoAEAD",
1988 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001989 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1991 NextProtos: []string{"foo"},
1992 Bugs: ProtocolBugs{
1993 ExpectFalseStart: true,
1994 AlertBeforeFalseStartTest: alertAccessDenied,
1995 },
1996 },
1997 flags: []string{
1998 "-false-start",
1999 "-advertise-alpn", "\x03foo",
2000 },
2001 shimWritesFirst: true,
2002 shouldFail: true,
2003 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2004 expectedLocalError: "tls: peer did not false start: EOF",
2005 },
2006 {
2007 name: "NoFalseStart-RSA",
2008 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002009 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002010 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2011 NextProtos: []string{"foo"},
2012 Bugs: ProtocolBugs{
2013 ExpectFalseStart: true,
2014 AlertBeforeFalseStartTest: alertAccessDenied,
2015 },
2016 },
2017 flags: []string{
2018 "-false-start",
2019 "-advertise-alpn", "\x03foo",
2020 },
2021 shimWritesFirst: true,
2022 shouldFail: true,
2023 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2024 expectedLocalError: "tls: peer did not false start: EOF",
2025 },
2026 {
Adam Langley7c803a62015-06-15 15:35:05 -07002027 protocol: dtls,
2028 name: "SendSplitAlert-Sync",
2029 config: Config{
2030 Bugs: ProtocolBugs{
2031 SendSplitAlert: true,
2032 },
2033 },
2034 },
2035 {
2036 protocol: dtls,
2037 name: "SendSplitAlert-Async",
2038 config: Config{
2039 Bugs: ProtocolBugs{
2040 SendSplitAlert: true,
2041 },
2042 },
2043 flags: []string{"-async"},
2044 },
2045 {
2046 protocol: dtls,
2047 name: "PackDTLSHandshake",
2048 config: Config{
2049 Bugs: ProtocolBugs{
2050 MaxHandshakeRecordLength: 2,
2051 PackHandshakeFragments: 20,
2052 PackHandshakeRecords: 200,
2053 },
2054 },
2055 },
2056 {
Adam Langley7c803a62015-06-15 15:35:05 -07002057 name: "SendEmptyRecords-Pass",
2058 sendEmptyRecords: 32,
2059 },
2060 {
2061 name: "SendEmptyRecords",
2062 sendEmptyRecords: 33,
2063 shouldFail: true,
2064 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2065 },
2066 {
2067 name: "SendEmptyRecords-Async",
2068 sendEmptyRecords: 33,
2069 flags: []string{"-async"},
2070 shouldFail: true,
2071 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2072 },
2073 {
David Benjamine8e84b92016-08-03 15:39:47 -04002074 name: "SendWarningAlerts-Pass",
2075 config: Config{
2076 MaxVersion: VersionTLS12,
2077 },
Adam Langley7c803a62015-06-15 15:35:05 -07002078 sendWarningAlerts: 4,
2079 },
2080 {
David Benjamine8e84b92016-08-03 15:39:47 -04002081 protocol: dtls,
2082 name: "SendWarningAlerts-DTLS-Pass",
2083 config: Config{
2084 MaxVersion: VersionTLS12,
2085 },
Adam Langley7c803a62015-06-15 15:35:05 -07002086 sendWarningAlerts: 4,
2087 },
2088 {
David Benjamine8e84b92016-08-03 15:39:47 -04002089 name: "SendWarningAlerts-TLS13",
2090 config: Config{
2091 MaxVersion: VersionTLS13,
2092 },
2093 sendWarningAlerts: 4,
2094 shouldFail: true,
2095 expectedError: ":BAD_ALERT:",
2096 expectedLocalError: "remote error: error decoding message",
2097 },
2098 {
2099 name: "SendWarningAlerts",
2100 config: Config{
2101 MaxVersion: VersionTLS12,
2102 },
Adam Langley7c803a62015-06-15 15:35:05 -07002103 sendWarningAlerts: 5,
2104 shouldFail: true,
2105 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2106 },
2107 {
David Benjamine8e84b92016-08-03 15:39:47 -04002108 name: "SendWarningAlerts-Async",
2109 config: Config{
2110 MaxVersion: VersionTLS12,
2111 },
Adam Langley7c803a62015-06-15 15:35:05 -07002112 sendWarningAlerts: 5,
2113 flags: []string{"-async"},
2114 shouldFail: true,
2115 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2116 },
David Benjaminba4594a2015-06-18 18:36:15 -04002117 {
David Benjamin24e58862017-06-14 18:45:29 -04002118 name: "SendBogusAlertType",
2119 sendBogusAlertType: true,
2120 shouldFail: true,
2121 expectedError: ":UNKNOWN_ALERT_TYPE:",
2122 expectedLocalError: "remote error: illegal parameter",
2123 },
2124 {
2125 protocol: dtls,
2126 name: "SendBogusAlertType-DTLS",
2127 sendBogusAlertType: true,
2128 shouldFail: true,
2129 expectedError: ":UNKNOWN_ALERT_TYPE:",
2130 expectedLocalError: "remote error: illegal parameter",
2131 },
2132 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002133 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002134 config: Config{
2135 MaxVersion: VersionTLS13,
2136 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002137 sendKeyUpdates: 33,
2138 keyUpdateRequest: keyUpdateNotRequested,
2139 shouldFail: true,
2140 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002141 },
2142 {
David Benjaminba4594a2015-06-18 18:36:15 -04002143 name: "EmptySessionID",
2144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002145 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002146 SessionTicketsDisabled: true,
2147 },
2148 noSessionCache: true,
2149 flags: []string{"-expect-no-session"},
2150 },
David Benjamin30789da2015-08-29 22:56:45 -04002151 {
2152 name: "Unclean-Shutdown",
2153 config: Config{
2154 Bugs: ProtocolBugs{
2155 NoCloseNotify: true,
2156 ExpectCloseNotify: true,
2157 },
2158 },
2159 shimShutsDown: true,
2160 flags: []string{"-check-close-notify"},
2161 shouldFail: true,
2162 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2163 },
2164 {
2165 name: "Unclean-Shutdown-Ignored",
2166 config: Config{
2167 Bugs: ProtocolBugs{
2168 NoCloseNotify: true,
2169 },
2170 },
2171 shimShutsDown: true,
2172 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002173 {
David Benjaminfa214e42016-05-10 17:03:10 -04002174 name: "Unclean-Shutdown-Alert",
2175 config: Config{
2176 Bugs: ProtocolBugs{
2177 SendAlertOnShutdown: alertDecompressionFailure,
2178 ExpectCloseNotify: true,
2179 },
2180 },
2181 shimShutsDown: true,
2182 flags: []string{"-check-close-notify"},
2183 shouldFail: true,
2184 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2185 },
2186 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002187 name: "LargePlaintext",
2188 config: Config{
2189 Bugs: ProtocolBugs{
2190 SendLargeRecords: true,
2191 },
2192 },
2193 messageLen: maxPlaintext + 1,
2194 shouldFail: true,
2195 expectedError: ":DATA_LENGTH_TOO_LONG:",
2196 },
2197 {
2198 protocol: dtls,
2199 name: "LargePlaintext-DTLS",
2200 config: Config{
2201 Bugs: ProtocolBugs{
2202 SendLargeRecords: true,
2203 },
2204 },
2205 messageLen: maxPlaintext + 1,
2206 shouldFail: true,
2207 expectedError: ":DATA_LENGTH_TOO_LONG:",
2208 },
2209 {
2210 name: "LargeCiphertext",
2211 config: Config{
2212 Bugs: ProtocolBugs{
2213 SendLargeRecords: true,
2214 },
2215 },
2216 messageLen: maxPlaintext * 2,
2217 shouldFail: true,
2218 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2219 },
2220 {
2221 protocol: dtls,
2222 name: "LargeCiphertext-DTLS",
2223 config: Config{
2224 Bugs: ProtocolBugs{
2225 SendLargeRecords: true,
2226 },
2227 },
2228 messageLen: maxPlaintext * 2,
2229 // Unlike the other four cases, DTLS drops records which
2230 // are invalid before authentication, so the connection
2231 // does not fail.
2232 expectMessageDropped: true,
2233 },
David Benjamindd6fed92015-10-23 17:41:12 -04002234 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002235 name: "BadHelloRequest-1",
2236 renegotiate: 1,
2237 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002238 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002239 Bugs: ProtocolBugs{
2240 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2241 },
2242 },
2243 flags: []string{
2244 "-renegotiate-freely",
2245 "-expect-total-renegotiations", "1",
2246 },
2247 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002248 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002249 },
2250 {
2251 name: "BadHelloRequest-2",
2252 renegotiate: 1,
2253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002254 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002255 Bugs: ProtocolBugs{
2256 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2257 },
2258 },
2259 flags: []string{
2260 "-renegotiate-freely",
2261 "-expect-total-renegotiations", "1",
2262 },
2263 shouldFail: true,
2264 expectedError: ":BAD_HELLO_REQUEST:",
2265 },
David Benjaminef1b0092015-11-21 14:05:44 -05002266 {
2267 testType: serverTest,
2268 name: "SupportTicketsWithSessionID",
2269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002270 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002271 SessionTicketsDisabled: true,
2272 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002273 resumeConfig: &Config{
2274 MaxVersion: VersionTLS12,
2275 },
David Benjaminef1b0092015-11-21 14:05:44 -05002276 resumeSession: true,
2277 },
David Benjamin02edcd02016-07-27 17:40:37 -04002278 {
2279 protocol: dtls,
2280 name: "DTLS-SendExtraFinished",
2281 config: Config{
2282 Bugs: ProtocolBugs{
2283 SendExtraFinished: true,
2284 },
2285 },
2286 shouldFail: true,
2287 expectedError: ":UNEXPECTED_RECORD:",
2288 },
2289 {
2290 protocol: dtls,
2291 name: "DTLS-SendExtraFinished-Reordered",
2292 config: Config{
2293 Bugs: ProtocolBugs{
2294 MaxHandshakeRecordLength: 2,
2295 ReorderHandshakeFragments: true,
2296 SendExtraFinished: true,
2297 },
2298 },
2299 shouldFail: true,
2300 expectedError: ":UNEXPECTED_RECORD:",
2301 },
David Benjamine97fb482016-07-29 09:23:07 -04002302 {
2303 testType: serverTest,
2304 name: "V2ClientHello-EmptyRecordPrefix",
2305 config: Config{
2306 // Choose a cipher suite that does not involve
2307 // elliptic curves, so no extensions are
2308 // involved.
2309 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002310 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002311 Bugs: ProtocolBugs{
2312 SendV2ClientHello: true,
2313 },
2314 },
2315 sendPrefix: string([]byte{
2316 byte(recordTypeHandshake),
2317 3, 1, // version
2318 0, 0, // length
2319 }),
2320 // A no-op empty record may not be sent before V2ClientHello.
2321 shouldFail: true,
2322 expectedError: ":WRONG_VERSION_NUMBER:",
2323 },
2324 {
2325 testType: serverTest,
2326 name: "V2ClientHello-WarningAlertPrefix",
2327 config: Config{
2328 // Choose a cipher suite that does not involve
2329 // elliptic curves, so no extensions are
2330 // involved.
2331 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002332 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002333 Bugs: ProtocolBugs{
2334 SendV2ClientHello: true,
2335 },
2336 },
2337 sendPrefix: string([]byte{
2338 byte(recordTypeAlert),
2339 3, 1, // version
2340 0, 2, // length
2341 alertLevelWarning, byte(alertDecompressionFailure),
2342 }),
2343 // A no-op warning alert may not be sent before V2ClientHello.
2344 shouldFail: true,
2345 expectedError: ":WRONG_VERSION_NUMBER:",
2346 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002347 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002348 name: "KeyUpdate-Client",
2349 config: Config{
2350 MaxVersion: VersionTLS13,
2351 },
2352 sendKeyUpdates: 1,
2353 keyUpdateRequest: keyUpdateNotRequested,
2354 },
2355 {
2356 testType: serverTest,
2357 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002358 config: Config{
2359 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002360 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002361 sendKeyUpdates: 1,
2362 keyUpdateRequest: keyUpdateNotRequested,
2363 },
2364 {
2365 name: "KeyUpdate-InvalidRequestMode",
2366 config: Config{
2367 MaxVersion: VersionTLS13,
2368 },
2369 sendKeyUpdates: 1,
2370 keyUpdateRequest: 42,
2371 shouldFail: true,
2372 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002373 },
David Benjaminabe94e32016-09-04 14:18:58 -04002374 {
David Benjaminbbba9392017-04-06 12:54:12 -04002375 // Test that KeyUpdates are acknowledged properly.
2376 name: "KeyUpdate-RequestACK",
2377 config: Config{
2378 MaxVersion: VersionTLS13,
2379 Bugs: ProtocolBugs{
2380 RejectUnsolicitedKeyUpdate: true,
2381 },
2382 },
2383 // Test the shim receiving many KeyUpdates in a row.
2384 sendKeyUpdates: 5,
2385 messageCount: 5,
2386 keyUpdateRequest: keyUpdateRequested,
2387 },
2388 {
2389 // Test that KeyUpdates are acknowledged properly if the
2390 // peer's KeyUpdate is discovered while a write is
2391 // pending.
2392 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2393 config: Config{
2394 MaxVersion: VersionTLS13,
2395 Bugs: ProtocolBugs{
2396 RejectUnsolicitedKeyUpdate: true,
2397 },
2398 },
2399 // Test the shim receiving many KeyUpdates in a row.
2400 sendKeyUpdates: 5,
2401 messageCount: 5,
2402 keyUpdateRequest: keyUpdateRequested,
2403 readWithUnfinishedWrite: true,
2404 flags: []string{"-async"},
2405 },
2406 {
David Benjaminabe94e32016-09-04 14:18:58 -04002407 name: "SendSNIWarningAlert",
2408 config: Config{
2409 MaxVersion: VersionTLS12,
2410 Bugs: ProtocolBugs{
2411 SendSNIWarningAlert: true,
2412 },
2413 },
2414 },
David Benjaminc241d792016-09-09 10:34:20 -04002415 {
2416 testType: serverTest,
2417 name: "ExtraCompressionMethods-TLS12",
2418 config: Config{
2419 MaxVersion: VersionTLS12,
2420 Bugs: ProtocolBugs{
2421 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2422 },
2423 },
2424 },
2425 {
2426 testType: serverTest,
2427 name: "ExtraCompressionMethods-TLS13",
2428 config: Config{
2429 MaxVersion: VersionTLS13,
2430 Bugs: ProtocolBugs{
2431 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2432 },
2433 },
2434 shouldFail: true,
2435 expectedError: ":INVALID_COMPRESSION_LIST:",
2436 expectedLocalError: "remote error: illegal parameter",
2437 },
2438 {
2439 testType: serverTest,
2440 name: "NoNullCompression-TLS12",
2441 config: Config{
2442 MaxVersion: VersionTLS12,
2443 Bugs: ProtocolBugs{
2444 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2445 },
2446 },
2447 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002448 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002449 expectedLocalError: "remote error: illegal parameter",
2450 },
2451 {
2452 testType: serverTest,
2453 name: "NoNullCompression-TLS13",
2454 config: Config{
2455 MaxVersion: VersionTLS13,
2456 Bugs: ProtocolBugs{
2457 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2458 },
2459 },
2460 shouldFail: true,
2461 expectedError: ":INVALID_COMPRESSION_LIST:",
2462 expectedLocalError: "remote error: illegal parameter",
2463 },
David Benjamin65ac9972016-09-02 21:35:25 -04002464 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002465 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002466 config: Config{
2467 MaxVersion: VersionTLS12,
2468 Bugs: ProtocolBugs{
2469 ExpectGREASE: true,
2470 },
2471 },
2472 flags: []string{"-enable-grease"},
2473 },
2474 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002475 name: "GREASE-Client-TLS13",
2476 config: Config{
2477 MaxVersion: VersionTLS13,
2478 Bugs: ProtocolBugs{
2479 ExpectGREASE: true,
2480 },
2481 },
2482 flags: []string{"-enable-grease"},
2483 },
2484 {
2485 testType: serverTest,
2486 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002487 config: Config{
2488 MaxVersion: VersionTLS13,
2489 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002490 // TLS 1.3 servers are expected to
2491 // always enable GREASE. TLS 1.3 is new,
2492 // so there is no existing ecosystem to
2493 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002494 ExpectGREASE: true,
2495 },
2496 },
David Benjamin65ac9972016-09-02 21:35:25 -04002497 },
David Benjamine3fbb362017-01-06 16:19:28 -05002498 {
2499 // Test the server so there is a large certificate as
2500 // well as application data.
2501 testType: serverTest,
2502 name: "MaxSendFragment",
2503 config: Config{
2504 Bugs: ProtocolBugs{
2505 MaxReceivePlaintext: 512,
2506 },
2507 },
2508 messageLen: 1024,
2509 flags: []string{
2510 "-max-send-fragment", "512",
2511 "-read-size", "1024",
2512 },
2513 },
2514 {
2515 // Test the server so there is a large certificate as
2516 // well as application data.
2517 testType: serverTest,
2518 name: "MaxSendFragment-TooLarge",
2519 config: Config{
2520 Bugs: ProtocolBugs{
2521 // Ensure that some of the records are
2522 // 512.
2523 MaxReceivePlaintext: 511,
2524 },
2525 },
2526 messageLen: 1024,
2527 flags: []string{
2528 "-max-send-fragment", "512",
2529 "-read-size", "1024",
2530 },
2531 shouldFail: true,
2532 expectedLocalError: "local error: record overflow",
2533 },
Adam Langley7c803a62015-06-15 15:35:05 -07002534 }
Adam Langley7c803a62015-06-15 15:35:05 -07002535 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002536
2537 // Test that very large messages can be received.
2538 cert := rsaCertificate
2539 for i := 0; i < 50; i++ {
2540 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2541 }
2542 testCases = append(testCases, testCase{
2543 name: "LargeMessage",
2544 config: Config{
2545 Certificates: []Certificate{cert},
2546 },
2547 })
2548 testCases = append(testCases, testCase{
2549 protocol: dtls,
2550 name: "LargeMessage-DTLS",
2551 config: Config{
2552 Certificates: []Certificate{cert},
2553 },
2554 })
2555
2556 // They are rejected if the maximum certificate chain length is capped.
2557 testCases = append(testCases, testCase{
2558 name: "LargeMessage-Reject",
2559 config: Config{
2560 Certificates: []Certificate{cert},
2561 },
2562 flags: []string{"-max-cert-list", "16384"},
2563 shouldFail: true,
2564 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2565 })
2566 testCases = append(testCases, testCase{
2567 protocol: dtls,
2568 name: "LargeMessage-Reject-DTLS",
2569 config: Config{
2570 Certificates: []Certificate{cert},
2571 },
2572 flags: []string{"-max-cert-list", "16384"},
2573 shouldFail: true,
2574 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2575 })
Adam Langley7c803a62015-06-15 15:35:05 -07002576}
2577
David Benjaminaa012042016-12-10 13:33:05 -05002578func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2579 const psk = "12345"
2580 const pskIdentity = "luggage combo"
2581
2582 var prefix string
2583 if protocol == dtls {
2584 if !ver.hasDTLS {
2585 return
2586 }
2587 prefix = "D"
2588 }
2589
2590 var cert Certificate
2591 var certFile string
2592 var keyFile string
2593 if hasComponent(suite.name, "ECDSA") {
2594 cert = ecdsaP256Certificate
2595 certFile = ecdsaP256CertificateFile
2596 keyFile = ecdsaP256KeyFile
2597 } else {
2598 cert = rsaCertificate
2599 certFile = rsaCertificateFile
2600 keyFile = rsaKeyFile
2601 }
2602
2603 var flags []string
2604 if hasComponent(suite.name, "PSK") {
2605 flags = append(flags,
2606 "-psk", psk,
2607 "-psk-identity", pskIdentity)
2608 }
2609 if hasComponent(suite.name, "NULL") {
2610 // NULL ciphers must be explicitly enabled.
2611 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2612 }
David Benjaminaa012042016-12-10 13:33:05 -05002613
2614 var shouldServerFail, shouldClientFail bool
2615 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2616 // BoringSSL clients accept ECDHE on SSLv3, but
2617 // a BoringSSL server will never select it
2618 // because the extension is missing.
2619 shouldServerFail = true
2620 }
2621 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2622 shouldClientFail = true
2623 shouldServerFail = true
2624 }
2625 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2626 shouldClientFail = true
2627 shouldServerFail = true
2628 }
2629 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2630 shouldClientFail = true
2631 shouldServerFail = true
2632 }
2633 if !isDTLSCipher(suite.name) && protocol == dtls {
2634 shouldClientFail = true
2635 shouldServerFail = true
2636 }
2637
2638 var sendCipherSuite uint16
2639 var expectedServerError, expectedClientError string
2640 serverCipherSuites := []uint16{suite.id}
2641 if shouldServerFail {
2642 expectedServerError = ":NO_SHARED_CIPHER:"
2643 }
2644 if shouldClientFail {
2645 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2646 // Configure the server to select ciphers as normal but
2647 // select an incompatible cipher in ServerHello.
2648 serverCipherSuites = nil
2649 sendCipherSuite = suite.id
2650 }
2651
David Benjamincdb6fe92017-02-07 16:06:48 -05002652 // For cipher suites and versions where exporters are defined, verify
2653 // that they interoperate.
2654 var exportKeyingMaterial int
2655 if ver.version > VersionSSL30 {
2656 exportKeyingMaterial = 1024
2657 }
2658
David Benjaminaa012042016-12-10 13:33:05 -05002659 testCases = append(testCases, testCase{
2660 testType: serverTest,
2661 protocol: protocol,
2662 name: prefix + ver.name + "-" + suite.name + "-server",
2663 config: Config{
2664 MinVersion: ver.version,
2665 MaxVersion: ver.version,
2666 CipherSuites: []uint16{suite.id},
2667 Certificates: []Certificate{cert},
2668 PreSharedKey: []byte(psk),
2669 PreSharedKeyIdentity: pskIdentity,
2670 Bugs: ProtocolBugs{
2671 AdvertiseAllConfiguredCiphers: true,
2672 },
2673 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002674 certFile: certFile,
2675 keyFile: keyFile,
2676 flags: flags,
2677 resumeSession: true,
2678 shouldFail: shouldServerFail,
2679 expectedError: expectedServerError,
2680 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002681 })
2682
2683 testCases = append(testCases, testCase{
2684 testType: clientTest,
2685 protocol: protocol,
2686 name: prefix + ver.name + "-" + suite.name + "-client",
2687 config: Config{
2688 MinVersion: ver.version,
2689 MaxVersion: ver.version,
2690 CipherSuites: serverCipherSuites,
2691 Certificates: []Certificate{cert},
2692 PreSharedKey: []byte(psk),
2693 PreSharedKeyIdentity: pskIdentity,
2694 Bugs: ProtocolBugs{
2695 IgnorePeerCipherPreferences: shouldClientFail,
2696 SendCipherSuite: sendCipherSuite,
2697 },
2698 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002699 flags: flags,
2700 resumeSession: true,
2701 shouldFail: shouldClientFail,
2702 expectedError: expectedClientError,
2703 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002704 })
2705
David Benjamin6f600d62016-12-21 16:06:54 -05002706 if shouldClientFail {
2707 return
2708 }
2709
2710 // Ensure the maximum record size is accepted.
2711 testCases = append(testCases, testCase{
2712 protocol: protocol,
2713 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2714 config: Config{
2715 MinVersion: ver.version,
2716 MaxVersion: ver.version,
2717 CipherSuites: []uint16{suite.id},
2718 Certificates: []Certificate{cert},
2719 PreSharedKey: []byte(psk),
2720 PreSharedKeyIdentity: pskIdentity,
2721 },
2722 flags: flags,
2723 messageLen: maxPlaintext,
2724 })
2725
2726 // Test bad records for all ciphers. Bad records are fatal in TLS
2727 // and ignored in DTLS.
2728 var shouldFail bool
2729 var expectedError string
2730 if protocol == tls {
2731 shouldFail = true
2732 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2733 }
2734
2735 testCases = append(testCases, testCase{
2736 protocol: protocol,
2737 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2738 config: Config{
2739 MinVersion: ver.version,
2740 MaxVersion: ver.version,
2741 CipherSuites: []uint16{suite.id},
2742 Certificates: []Certificate{cert},
2743 PreSharedKey: []byte(psk),
2744 PreSharedKeyIdentity: pskIdentity,
2745 },
2746 flags: flags,
2747 damageFirstWrite: true,
2748 messageLen: maxPlaintext,
2749 shouldFail: shouldFail,
2750 expectedError: expectedError,
2751 })
David Benjaminaa012042016-12-10 13:33:05 -05002752}
2753
Adam Langley95c29f32014-06-20 12:00:00 -07002754func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002755 const bogusCipher = 0xfe00
2756
Adam Langley95c29f32014-06-20 12:00:00 -07002757 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002758 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002759 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002760 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002761 }
David Benjamin2c99d282015-09-01 10:23:00 -04002762 }
Adam Langley95c29f32014-06-20 12:00:00 -07002763 }
Adam Langleya7997f12015-05-14 17:38:50 -07002764
2765 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002766 name: "NoSharedCipher",
2767 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002768 MaxVersion: VersionTLS12,
2769 CipherSuites: []uint16{},
2770 },
2771 shouldFail: true,
2772 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2773 })
2774
2775 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002776 name: "NoSharedCipher-TLS13",
2777 config: Config{
2778 MaxVersion: VersionTLS13,
2779 CipherSuites: []uint16{},
2780 },
2781 shouldFail: true,
2782 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2783 })
2784
2785 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002786 name: "UnsupportedCipherSuite",
2787 config: Config{
2788 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002789 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002790 Bugs: ProtocolBugs{
2791 IgnorePeerCipherPreferences: true,
2792 },
2793 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002794 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002795 shouldFail: true,
2796 expectedError: ":WRONG_CIPHER_RETURNED:",
2797 })
2798
2799 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002800 name: "ServerHelloBogusCipher",
2801 config: Config{
2802 MaxVersion: VersionTLS12,
2803 Bugs: ProtocolBugs{
2804 SendCipherSuite: bogusCipher,
2805 },
2806 },
2807 shouldFail: true,
2808 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2809 })
2810 testCases = append(testCases, testCase{
2811 name: "ServerHelloBogusCipher-TLS13",
2812 config: Config{
2813 MaxVersion: VersionTLS13,
2814 Bugs: ProtocolBugs{
2815 SendCipherSuite: bogusCipher,
2816 },
2817 },
2818 shouldFail: true,
2819 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2820 })
2821
David Benjamin241ae832016-01-15 03:04:54 -05002822 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002823 testCases = append(testCases, testCase{
2824 testType: serverTest,
2825 name: "UnknownCipher",
2826 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002827 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002828 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002829 Bugs: ProtocolBugs{
2830 AdvertiseAllConfiguredCiphers: true,
2831 },
2832 },
2833 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002834
2835 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002836 testCases = append(testCases, testCase{
2837 testType: serverTest,
2838 name: "UnknownCipher-TLS13",
2839 config: Config{
2840 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002841 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002842 Bugs: ProtocolBugs{
2843 AdvertiseAllConfiguredCiphers: true,
2844 },
David Benjamin241ae832016-01-15 03:04:54 -05002845 },
2846 })
2847
David Benjamin78679342016-09-16 19:42:05 -04002848 // Test empty ECDHE_PSK identity hints work as expected.
2849 testCases = append(testCases, testCase{
2850 name: "EmptyECDHEPSKHint",
2851 config: Config{
2852 MaxVersion: VersionTLS12,
2853 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2854 PreSharedKey: []byte("secret"),
2855 },
2856 flags: []string{"-psk", "secret"},
2857 })
2858
2859 // Test empty PSK identity hints work as expected, even if an explicit
2860 // ServerKeyExchange is sent.
2861 testCases = append(testCases, testCase{
2862 name: "ExplicitEmptyPSKHint",
2863 config: Config{
2864 MaxVersion: VersionTLS12,
2865 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2866 PreSharedKey: []byte("secret"),
2867 Bugs: ProtocolBugs{
2868 AlwaysSendPreSharedKeyIdentityHint: true,
2869 },
2870 },
2871 flags: []string{"-psk", "secret"},
2872 })
David Benjamin69522112017-03-28 15:38:29 -05002873
2874 // Test that clients enforce that the server-sent certificate and cipher
2875 // suite match in TLS 1.2.
2876 testCases = append(testCases, testCase{
2877 name: "CertificateCipherMismatch-RSA",
2878 config: Config{
2879 MaxVersion: VersionTLS12,
2880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2881 Certificates: []Certificate{rsaCertificate},
2882 Bugs: ProtocolBugs{
2883 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2884 },
2885 },
2886 shouldFail: true,
2887 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2888 })
2889 testCases = append(testCases, testCase{
2890 name: "CertificateCipherMismatch-ECDSA",
2891 config: Config{
2892 MaxVersion: VersionTLS12,
2893 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2894 Certificates: []Certificate{ecdsaP256Certificate},
2895 Bugs: ProtocolBugs{
2896 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2897 },
2898 },
2899 shouldFail: true,
2900 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2901 })
2902 testCases = append(testCases, testCase{
2903 name: "CertificateCipherMismatch-Ed25519",
2904 config: Config{
2905 MaxVersion: VersionTLS12,
2906 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2907 Certificates: []Certificate{ed25519Certificate},
2908 Bugs: ProtocolBugs{
2909 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2910 },
2911 },
2912 shouldFail: true,
2913 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2914 })
2915
2916 // Test that servers decline to select a cipher suite which is
2917 // inconsistent with their configured certificate.
2918 testCases = append(testCases, testCase{
2919 testType: serverTest,
2920 name: "ServerCipherFilter-RSA",
2921 config: Config{
2922 MaxVersion: VersionTLS12,
2923 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2924 },
2925 flags: []string{
2926 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2927 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2928 },
2929 shouldFail: true,
2930 expectedError: ":NO_SHARED_CIPHER:",
2931 })
2932 testCases = append(testCases, testCase{
2933 testType: serverTest,
2934 name: "ServerCipherFilter-ECDSA",
2935 config: Config{
2936 MaxVersion: VersionTLS12,
2937 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2938 },
2939 flags: []string{
2940 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2941 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
2942 },
2943 shouldFail: true,
2944 expectedError: ":NO_SHARED_CIPHER:",
2945 })
2946 testCases = append(testCases, testCase{
2947 testType: serverTest,
2948 name: "ServerCipherFilter-Ed25519",
2949 config: Config{
2950 MaxVersion: VersionTLS12,
2951 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2952 },
2953 flags: []string{
2954 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
2955 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
2956 },
2957 shouldFail: true,
2958 expectedError: ":NO_SHARED_CIPHER:",
2959 })
Adam Langley95c29f32014-06-20 12:00:00 -07002960}
2961
2962func addBadECDSASignatureTests() {
2963 for badR := BadValue(1); badR < NumBadValues; badR++ {
2964 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002965 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002966 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2967 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002968 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002969 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002970 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002971 Bugs: ProtocolBugs{
2972 BadECDSAR: badR,
2973 BadECDSAS: badS,
2974 },
2975 },
2976 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002977 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002978 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002979 testCases = append(testCases, testCase{
2980 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2981 config: Config{
2982 MaxVersion: VersionTLS13,
2983 Certificates: []Certificate{ecdsaP256Certificate},
2984 Bugs: ProtocolBugs{
2985 BadECDSAR: badR,
2986 BadECDSAS: badS,
2987 },
2988 },
2989 shouldFail: true,
2990 expectedError: ":BAD_SIGNATURE:",
2991 })
Adam Langley95c29f32014-06-20 12:00:00 -07002992 }
2993 }
2994}
2995
Adam Langley80842bd2014-06-20 12:00:00 -07002996func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002997 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002998 name: "MaxCBCPadding",
2999 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003000 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003001 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3002 Bugs: ProtocolBugs{
3003 MaxPadding: true,
3004 },
3005 },
3006 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3007 })
David Benjamin025b3d32014-07-01 19:53:04 -04003008 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003009 name: "BadCBCPadding",
3010 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003011 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003012 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3013 Bugs: ProtocolBugs{
3014 PaddingFirstByteBad: true,
3015 },
3016 },
3017 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003018 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003019 })
3020 // OpenSSL previously had an issue where the first byte of padding in
3021 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003022 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003023 name: "BadCBCPadding255",
3024 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003025 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3027 Bugs: ProtocolBugs{
3028 MaxPadding: true,
3029 PaddingFirstByteBadIf255: true,
3030 },
3031 },
3032 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3033 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003034 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003035 })
3036}
3037
Kenny Root7fdeaf12014-08-05 15:23:37 -07003038func addCBCSplittingTests() {
3039 testCases = append(testCases, testCase{
3040 name: "CBCRecordSplitting",
3041 config: Config{
3042 MaxVersion: VersionTLS10,
3043 MinVersion: VersionTLS10,
3044 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3045 },
David Benjaminac8302a2015-09-01 17:18:15 -04003046 messageLen: -1, // read until EOF
3047 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003048 flags: []string{
3049 "-async",
3050 "-write-different-record-sizes",
3051 "-cbc-record-splitting",
3052 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003053 })
3054 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003055 name: "CBCRecordSplittingPartialWrite",
3056 config: Config{
3057 MaxVersion: VersionTLS10,
3058 MinVersion: VersionTLS10,
3059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3060 },
3061 messageLen: -1, // read until EOF
3062 flags: []string{
3063 "-async",
3064 "-write-different-record-sizes",
3065 "-cbc-record-splitting",
3066 "-partial-write",
3067 },
3068 })
3069}
3070
David Benjamin636293b2014-07-08 17:59:18 -04003071func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003072 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003073 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003074 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3075 cert, err := x509.ParseCertificate(cert.Certificate[0])
3076 if err != nil {
3077 panic(err)
3078 }
3079 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003080 }
Adam Langley2ff79332017-02-28 13:45:39 -08003081 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003082
David Benjamin636293b2014-07-08 17:59:18 -04003083 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003084 testCases = append(testCases, testCase{
3085 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003086 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003087 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003088 MinVersion: ver.version,
3089 MaxVersion: ver.version,
3090 ClientAuth: RequireAnyClientCert,
3091 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003092 },
3093 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003094 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3095 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003096 },
3097 })
3098 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003099 testType: serverTest,
3100 name: ver.name + "-Server-ClientAuth-RSA",
3101 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003102 MinVersion: ver.version,
3103 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003104 Certificates: []Certificate{rsaCertificate},
3105 },
3106 flags: []string{"-require-any-client-certificate"},
3107 })
David Benjamine098ec22014-08-27 23:13:20 -04003108 if ver.version != VersionSSL30 {
3109 testCases = append(testCases, testCase{
3110 testType: serverTest,
3111 name: ver.name + "-Server-ClientAuth-ECDSA",
3112 config: Config{
3113 MinVersion: ver.version,
3114 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003115 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003116 },
3117 flags: []string{"-require-any-client-certificate"},
3118 })
3119 testCases = append(testCases, testCase{
3120 testType: clientTest,
3121 name: ver.name + "-Client-ClientAuth-ECDSA",
3122 config: Config{
3123 MinVersion: ver.version,
3124 MaxVersion: ver.version,
3125 ClientAuth: RequireAnyClientCert,
3126 ClientCAs: certPool,
3127 },
3128 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003129 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3130 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003131 },
3132 })
3133 }
Adam Langley37646832016-08-01 16:16:46 -07003134
3135 testCases = append(testCases, testCase{
3136 name: "NoClientCertificate-" + ver.name,
3137 config: Config{
3138 MinVersion: ver.version,
3139 MaxVersion: ver.version,
3140 ClientAuth: RequireAnyClientCert,
3141 },
3142 shouldFail: true,
3143 expectedLocalError: "client didn't provide a certificate",
3144 })
3145
3146 testCases = append(testCases, testCase{
3147 // Even if not configured to expect a certificate, OpenSSL will
3148 // return X509_V_OK as the verify_result.
3149 testType: serverTest,
3150 name: "NoClientCertificateRequested-Server-" + ver.name,
3151 config: Config{
3152 MinVersion: ver.version,
3153 MaxVersion: ver.version,
3154 },
3155 flags: []string{
3156 "-expect-verify-result",
3157 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003158 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003159 })
3160
3161 testCases = append(testCases, testCase{
3162 // If a client certificate is not provided, OpenSSL will still
3163 // return X509_V_OK as the verify_result.
3164 testType: serverTest,
3165 name: "NoClientCertificate-Server-" + ver.name,
3166 config: Config{
3167 MinVersion: ver.version,
3168 MaxVersion: ver.version,
3169 },
3170 flags: []string{
3171 "-expect-verify-result",
3172 "-verify-peer",
3173 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003174 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003175 })
3176
David Benjamin1db9e1b2016-10-07 20:51:43 -04003177 certificateRequired := "remote error: certificate required"
3178 if ver.version < VersionTLS13 {
3179 // Prior to TLS 1.3, the generic handshake_failure alert
3180 // was used.
3181 certificateRequired = "remote error: handshake failure"
3182 }
Adam Langley37646832016-08-01 16:16:46 -07003183 testCases = append(testCases, testCase{
3184 testType: serverTest,
3185 name: "RequireAnyClientCertificate-" + ver.name,
3186 config: Config{
3187 MinVersion: ver.version,
3188 MaxVersion: ver.version,
3189 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003190 flags: []string{"-require-any-client-certificate"},
3191 shouldFail: true,
3192 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3193 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003194 })
3195
3196 if ver.version != VersionSSL30 {
3197 testCases = append(testCases, testCase{
3198 testType: serverTest,
3199 name: "SkipClientCertificate-" + ver.name,
3200 config: Config{
3201 MinVersion: ver.version,
3202 MaxVersion: ver.version,
3203 Bugs: ProtocolBugs{
3204 SkipClientCertificate: true,
3205 },
3206 },
3207 // Setting SSL_VERIFY_PEER allows anonymous clients.
3208 flags: []string{"-verify-peer"},
3209 shouldFail: true,
3210 expectedError: ":UNEXPECTED_MESSAGE:",
3211 })
3212 }
Adam Langley2ff79332017-02-28 13:45:39 -08003213
3214 testCases = append(testCases, testCase{
3215 testType: serverTest,
3216 name: ver.name + "-Server-CertReq-CA-List",
3217 config: Config{
3218 MinVersion: ver.version,
3219 MaxVersion: ver.version,
3220 Certificates: []Certificate{rsaCertificate},
3221 Bugs: ProtocolBugs{
3222 ExpectCertificateReqNames: caNames,
3223 },
3224 },
3225 flags: []string{
3226 "-require-any-client-certificate",
3227 "-use-client-ca-list", encodeDERValues(caNames),
3228 },
3229 })
3230
3231 testCases = append(testCases, testCase{
3232 testType: clientTest,
3233 name: ver.name + "-Client-CertReq-CA-List",
3234 config: Config{
3235 MinVersion: ver.version,
3236 MaxVersion: ver.version,
3237 Certificates: []Certificate{rsaCertificate},
3238 ClientAuth: RequireAnyClientCert,
3239 ClientCAs: certPool,
3240 },
3241 flags: []string{
3242 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3243 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3244 "-expect-client-ca-list", encodeDERValues(caNames),
3245 },
3246 })
David Benjamin636293b2014-07-08 17:59:18 -04003247 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003248
David Benjaminc032dfa2016-05-12 14:54:57 -04003249 // Client auth is only legal in certificate-based ciphers.
3250 testCases = append(testCases, testCase{
3251 testType: clientTest,
3252 name: "ClientAuth-PSK",
3253 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003254 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003255 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3256 PreSharedKey: []byte("secret"),
3257 ClientAuth: RequireAnyClientCert,
3258 },
3259 flags: []string{
3260 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3261 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3262 "-psk", "secret",
3263 },
3264 shouldFail: true,
3265 expectedError: ":UNEXPECTED_MESSAGE:",
3266 })
3267 testCases = append(testCases, testCase{
3268 testType: clientTest,
3269 name: "ClientAuth-ECDHE_PSK",
3270 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003271 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003272 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3273 PreSharedKey: []byte("secret"),
3274 ClientAuth: RequireAnyClientCert,
3275 },
3276 flags: []string{
3277 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3278 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3279 "-psk", "secret",
3280 },
3281 shouldFail: true,
3282 expectedError: ":UNEXPECTED_MESSAGE:",
3283 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003284
3285 // Regression test for a bug where the client CA list, if explicitly
3286 // set to NULL, was mis-encoded.
3287 testCases = append(testCases, testCase{
3288 testType: serverTest,
3289 name: "Null-Client-CA-List",
3290 config: Config{
3291 MaxVersion: VersionTLS12,
3292 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003293 Bugs: ProtocolBugs{
3294 ExpectCertificateReqNames: [][]byte{},
3295 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003296 },
3297 flags: []string{
3298 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003299 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003300 },
3301 })
David Benjamin636293b2014-07-08 17:59:18 -04003302}
3303
Adam Langley75712922014-10-10 16:23:43 -07003304func addExtendedMasterSecretTests() {
3305 const expectEMSFlag = "-expect-extended-master-secret"
3306
3307 for _, with := range []bool{false, true} {
3308 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003309 if with {
3310 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003311 }
3312
3313 for _, isClient := range []bool{false, true} {
3314 suffix := "-Server"
3315 testType := serverTest
3316 if isClient {
3317 suffix = "-Client"
3318 testType = clientTest
3319 }
3320
3321 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003322 // In TLS 1.3, the extension is irrelevant and
3323 // always reports as enabled.
3324 var flags []string
3325 if with || ver.version >= VersionTLS13 {
3326 flags = []string{expectEMSFlag}
3327 }
3328
Adam Langley75712922014-10-10 16:23:43 -07003329 test := testCase{
3330 testType: testType,
3331 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3332 config: Config{
3333 MinVersion: ver.version,
3334 MaxVersion: ver.version,
3335 Bugs: ProtocolBugs{
3336 NoExtendedMasterSecret: !with,
3337 RequireExtendedMasterSecret: with,
3338 },
3339 },
David Benjamin48cae082014-10-27 01:06:24 -04003340 flags: flags,
3341 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003342 }
3343 if test.shouldFail {
3344 test.expectedLocalError = "extended master secret required but not supported by peer"
3345 }
3346 testCases = append(testCases, test)
3347 }
3348 }
3349 }
3350
Adam Langleyba5934b2015-06-02 10:50:35 -07003351 for _, isClient := range []bool{false, true} {
3352 for _, supportedInFirstConnection := range []bool{false, true} {
3353 for _, supportedInResumeConnection := range []bool{false, true} {
3354 boolToWord := func(b bool) string {
3355 if b {
3356 return "Yes"
3357 }
3358 return "No"
3359 }
3360 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3361 if isClient {
3362 suffix += "Client"
3363 } else {
3364 suffix += "Server"
3365 }
3366
3367 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003368 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003369 Bugs: ProtocolBugs{
3370 RequireExtendedMasterSecret: true,
3371 },
3372 }
3373
3374 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003375 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003376 Bugs: ProtocolBugs{
3377 NoExtendedMasterSecret: true,
3378 },
3379 }
3380
3381 test := testCase{
3382 name: "ExtendedMasterSecret-" + suffix,
3383 resumeSession: true,
3384 }
3385
3386 if !isClient {
3387 test.testType = serverTest
3388 }
3389
3390 if supportedInFirstConnection {
3391 test.config = supportedConfig
3392 } else {
3393 test.config = noSupportConfig
3394 }
3395
3396 if supportedInResumeConnection {
3397 test.resumeConfig = &supportedConfig
3398 } else {
3399 test.resumeConfig = &noSupportConfig
3400 }
3401
3402 switch suffix {
3403 case "YesToYes-Client", "YesToYes-Server":
3404 // When a session is resumed, it should
3405 // still be aware that its master
3406 // secret was generated via EMS and
3407 // thus it's safe to use tls-unique.
3408 test.flags = []string{expectEMSFlag}
3409 case "NoToYes-Server":
3410 // If an original connection did not
3411 // contain EMS, but a resumption
3412 // handshake does, then a server should
3413 // not resume the session.
3414 test.expectResumeRejected = true
3415 case "YesToNo-Server":
3416 // Resuming an EMS session without the
3417 // EMS extension should cause the
3418 // server to abort the connection.
3419 test.shouldFail = true
3420 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3421 case "NoToYes-Client":
3422 // A client should abort a connection
3423 // where the server resumed a non-EMS
3424 // session but echoed the EMS
3425 // extension.
3426 test.shouldFail = true
3427 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3428 case "YesToNo-Client":
3429 // A client should abort a connection
3430 // where the server didn't echo EMS
3431 // when the session used it.
3432 test.shouldFail = true
3433 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3434 }
3435
3436 testCases = append(testCases, test)
3437 }
3438 }
3439 }
David Benjamin163c9562016-08-29 23:14:17 -04003440
3441 // Switching EMS on renegotiation is forbidden.
3442 testCases = append(testCases, testCase{
3443 name: "ExtendedMasterSecret-Renego-NoEMS",
3444 config: Config{
3445 MaxVersion: VersionTLS12,
3446 Bugs: ProtocolBugs{
3447 NoExtendedMasterSecret: true,
3448 NoExtendedMasterSecretOnRenegotiation: true,
3449 },
3450 },
3451 renegotiate: 1,
3452 flags: []string{
3453 "-renegotiate-freely",
3454 "-expect-total-renegotiations", "1",
3455 },
3456 })
3457
3458 testCases = append(testCases, testCase{
3459 name: "ExtendedMasterSecret-Renego-Upgrade",
3460 config: Config{
3461 MaxVersion: VersionTLS12,
3462 Bugs: ProtocolBugs{
3463 NoExtendedMasterSecret: true,
3464 },
3465 },
3466 renegotiate: 1,
3467 flags: []string{
3468 "-renegotiate-freely",
3469 "-expect-total-renegotiations", "1",
3470 },
3471 shouldFail: true,
3472 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3473 })
3474
3475 testCases = append(testCases, testCase{
3476 name: "ExtendedMasterSecret-Renego-Downgrade",
3477 config: Config{
3478 MaxVersion: VersionTLS12,
3479 Bugs: ProtocolBugs{
3480 NoExtendedMasterSecretOnRenegotiation: true,
3481 },
3482 },
3483 renegotiate: 1,
3484 flags: []string{
3485 "-renegotiate-freely",
3486 "-expect-total-renegotiations", "1",
3487 },
3488 shouldFail: true,
3489 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3490 })
Adam Langley75712922014-10-10 16:23:43 -07003491}
3492
David Benjamin582ba042016-07-07 12:33:25 -07003493type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003494 protocol protocol
3495 async bool
3496 splitHandshake bool
3497 packHandshakeFlight bool
3498 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003499}
3500
David Benjamin43ec06f2014-08-05 02:28:57 -04003501// Adds tests that try to cover the range of the handshake state machine, under
3502// various conditions. Some of these are redundant with other tests, but they
3503// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003504func addAllStateMachineCoverageTests() {
3505 for _, async := range []bool{false, true} {
3506 for _, protocol := range []protocol{tls, dtls} {
3507 addStateMachineCoverageTests(stateMachineTestConfig{
3508 protocol: protocol,
3509 async: async,
3510 })
3511 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003512 protocol: protocol,
3513 async: async,
3514 implicitHandshake: true,
3515 })
3516 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003517 protocol: protocol,
3518 async: async,
3519 splitHandshake: true,
3520 })
3521 if protocol == tls {
3522 addStateMachineCoverageTests(stateMachineTestConfig{
3523 protocol: protocol,
3524 async: async,
3525 packHandshakeFlight: true,
3526 })
3527 }
3528 }
3529 }
3530}
3531
3532func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003533 var tests []testCase
3534
3535 // Basic handshake, with resumption. Client and server,
3536 // session ID and session ticket.
3537 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003538 name: "Basic-Client",
3539 config: Config{
3540 MaxVersion: VersionTLS12,
3541 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003542 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003543 // Ensure session tickets are used, not session IDs.
3544 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003545 })
3546 tests = append(tests, testCase{
3547 name: "Basic-Client-RenewTicket",
3548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003549 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003550 Bugs: ProtocolBugs{
3551 RenewTicketOnResume: true,
3552 },
3553 },
David Benjamin46662482016-08-17 00:51:00 -04003554 flags: []string{"-expect-ticket-renewal"},
3555 resumeSession: true,
3556 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003557 })
3558 tests = append(tests, testCase{
3559 name: "Basic-Client-NoTicket",
3560 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003561 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003562 SessionTicketsDisabled: true,
3563 },
3564 resumeSession: true,
3565 })
3566 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003567 testType: serverTest,
3568 name: "Basic-Server",
3569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003570 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003571 Bugs: ProtocolBugs{
3572 RequireSessionTickets: true,
3573 },
3574 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003575 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003576 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003577 })
3578 tests = append(tests, testCase{
3579 testType: serverTest,
3580 name: "Basic-Server-NoTickets",
3581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003582 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003583 SessionTicketsDisabled: true,
3584 },
3585 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003586 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003587 })
3588 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003589 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003590 name: "Basic-Server-EarlyCallback",
3591 config: Config{
3592 MaxVersion: VersionTLS12,
3593 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003594 flags: []string{"-use-early-callback"},
3595 resumeSession: true,
3596 })
3597
Steven Valdez143e8b32016-07-11 13:19:03 -04003598 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003599 if config.protocol == tls {
3600 tests = append(tests, testCase{
3601 name: "TLS13-1RTT-Client",
3602 config: Config{
3603 MaxVersion: VersionTLS13,
3604 MinVersion: VersionTLS13,
3605 },
David Benjamin46662482016-08-17 00:51:00 -04003606 resumeSession: true,
3607 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003608 })
3609
3610 tests = append(tests, testCase{
3611 testType: serverTest,
3612 name: "TLS13-1RTT-Server",
3613 config: Config{
3614 MaxVersion: VersionTLS13,
3615 MinVersion: VersionTLS13,
3616 },
David Benjamin46662482016-08-17 00:51:00 -04003617 resumeSession: true,
3618 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003619 // TLS 1.3 uses tickets, so the session should not be
3620 // cached statefully.
3621 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003622 })
3623
3624 tests = append(tests, testCase{
3625 name: "TLS13-HelloRetryRequest-Client",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003629 // P-384 requires a HelloRetryRequest against BoringSSL's default
3630 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003631 CurvePreferences: []CurveID{CurveP384},
3632 Bugs: ProtocolBugs{
3633 ExpectMissingKeyShare: true,
3634 },
3635 },
3636 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3637 resumeSession: true,
3638 })
3639
3640 tests = append(tests, testCase{
3641 testType: serverTest,
3642 name: "TLS13-HelloRetryRequest-Server",
3643 config: Config{
3644 MaxVersion: VersionTLS13,
3645 MinVersion: VersionTLS13,
3646 // Require a HelloRetryRequest for every curve.
3647 DefaultCurves: []CurveID{},
3648 },
3649 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3650 resumeSession: true,
3651 })
Steven Valdez2d850622017-01-11 11:34:52 -05003652
Steven Valdez2d850622017-01-11 11:34:52 -05003653 tests = append(tests, testCase{
3654 testType: clientTest,
3655 name: "TLS13-EarlyData-Client",
3656 config: Config{
3657 MaxVersion: VersionTLS13,
3658 MinVersion: VersionTLS13,
3659 MaxEarlyDataSize: 16384,
3660 },
Steven Valdeze831a812017-03-09 14:56:07 -05003661 resumeConfig: &Config{
3662 MaxVersion: VersionTLS13,
3663 MinVersion: VersionTLS13,
3664 MaxEarlyDataSize: 16384,
3665 Bugs: ProtocolBugs{
3666 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3667 },
3668 },
Steven Valdez2d850622017-01-11 11:34:52 -05003669 resumeSession: true,
3670 flags: []string{
3671 "-enable-early-data",
3672 "-expect-early-data-info",
3673 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003674 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003675 },
3676 })
3677
3678 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003679 testType: clientTest,
3680 name: "TLS13-EarlyData-TooMuchData-Client",
3681 config: Config{
3682 MaxVersion: VersionTLS13,
3683 MinVersion: VersionTLS13,
3684 MaxEarlyDataSize: 2,
3685 },
3686 resumeConfig: &Config{
3687 MaxVersion: VersionTLS13,
3688 MinVersion: VersionTLS13,
3689 MaxEarlyDataSize: 2,
3690 Bugs: ProtocolBugs{
3691 ExpectEarlyData: [][]byte{{'h', 'e'}},
3692 },
3693 },
3694 resumeShimPrefix: "llo",
3695 resumeSession: true,
3696 flags: []string{
3697 "-enable-early-data",
3698 "-expect-early-data-info",
3699 "-expect-accept-early-data",
3700 "-on-resume-shim-writes-first",
3701 },
3702 })
3703
3704 // Unfinished writes can only be tested when operations are async. EarlyData
3705 // can't be tested as part of an ImplicitHandshake in this case since
3706 // otherwise the early data will be sent as normal data.
3707 if config.async && !config.implicitHandshake {
3708 tests = append(tests, testCase{
3709 testType: clientTest,
3710 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3711 config: Config{
3712 MaxVersion: VersionTLS13,
3713 MinVersion: VersionTLS13,
3714 MaxEarlyDataSize: 16384,
3715 },
3716 resumeConfig: &Config{
3717 MaxVersion: VersionTLS13,
3718 MinVersion: VersionTLS13,
3719 MaxEarlyDataSize: 16384,
3720 Bugs: ProtocolBugs{
3721 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3722 },
3723 },
3724 resumeSession: true,
3725 flags: []string{
3726 "-enable-early-data",
3727 "-expect-early-data-info",
3728 "-expect-accept-early-data",
3729 "-on-resume-read-with-unfinished-write",
3730 "-on-resume-shim-writes-first",
3731 },
3732 })
3733
3734 // Rejected unfinished writes are discarded (from the
3735 // perspective of the calling application) on 0-RTT
3736 // reject.
3737 tests = append(tests, testCase{
3738 testType: clientTest,
3739 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3740 config: Config{
3741 MaxVersion: VersionTLS13,
3742 MinVersion: VersionTLS13,
3743 MaxEarlyDataSize: 16384,
3744 },
3745 resumeConfig: &Config{
3746 MaxVersion: VersionTLS13,
3747 MinVersion: VersionTLS13,
3748 MaxEarlyDataSize: 16384,
3749 Bugs: ProtocolBugs{
3750 AlwaysRejectEarlyData: true,
3751 },
3752 },
3753 resumeSession: true,
3754 flags: []string{
3755 "-enable-early-data",
3756 "-expect-early-data-info",
3757 "-expect-reject-early-data",
3758 "-on-resume-read-with-unfinished-write",
3759 "-on-resume-shim-writes-first",
3760 },
3761 })
3762 }
3763
3764 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003765 testType: serverTest,
3766 name: "TLS13-EarlyData-Server",
3767 config: Config{
3768 MaxVersion: VersionTLS13,
3769 MinVersion: VersionTLS13,
3770 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003771 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003772 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003773 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003774 },
3775 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003776 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003777 resumeSession: true,
3778 flags: []string{
3779 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003780 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003781 },
3782 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003783
3784 tests = append(tests, testCase{
3785 testType: serverTest,
3786 name: "TLS13-MaxEarlyData-Server",
3787 config: Config{
3788 MaxVersion: VersionTLS13,
3789 MinVersion: VersionTLS13,
3790 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003791 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003792 ExpectEarlyDataAccepted: true,
3793 },
3794 },
3795 messageCount: 2,
3796 resumeSession: true,
3797 flags: []string{
3798 "-enable-early-data",
3799 "-expect-accept-early-data",
3800 },
3801 shouldFail: true,
3802 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
3803 })
David Benjamine73c7f42016-08-17 00:29:33 -04003804 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003805
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 // TLS client auth.
3807 tests = append(tests, testCase{
3808 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003809 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003811 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003812 ClientAuth: RequestClientCert,
3813 },
3814 })
3815 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003816 testType: serverTest,
3817 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003818 config: Config{
3819 MaxVersion: VersionTLS12,
3820 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003821 // Setting SSL_VERIFY_PEER allows anonymous clients.
3822 flags: []string{"-verify-peer"},
3823 })
David Benjamin582ba042016-07-07 12:33:25 -07003824 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003825 tests = append(tests, testCase{
3826 testType: clientTest,
3827 name: "ClientAuth-NoCertificate-Client-SSL3",
3828 config: Config{
3829 MaxVersion: VersionSSL30,
3830 ClientAuth: RequestClientCert,
3831 },
3832 })
3833 tests = append(tests, testCase{
3834 testType: serverTest,
3835 name: "ClientAuth-NoCertificate-Server-SSL3",
3836 config: Config{
3837 MaxVersion: VersionSSL30,
3838 },
3839 // Setting SSL_VERIFY_PEER allows anonymous clients.
3840 flags: []string{"-verify-peer"},
3841 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003842 tests = append(tests, testCase{
3843 testType: clientTest,
3844 name: "ClientAuth-NoCertificate-Client-TLS13",
3845 config: Config{
3846 MaxVersion: VersionTLS13,
3847 ClientAuth: RequestClientCert,
3848 },
3849 })
3850 tests = append(tests, testCase{
3851 testType: serverTest,
3852 name: "ClientAuth-NoCertificate-Server-TLS13",
3853 config: Config{
3854 MaxVersion: VersionTLS13,
3855 },
3856 // Setting SSL_VERIFY_PEER allows anonymous clients.
3857 flags: []string{"-verify-peer"},
3858 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003859 }
3860 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003861 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003862 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003864 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003865 ClientAuth: RequireAnyClientCert,
3866 },
3867 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003868 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3869 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003870 },
3871 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003872 tests = append(tests, testCase{
3873 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003874 name: "ClientAuth-RSA-Client-TLS13",
3875 config: Config{
3876 MaxVersion: VersionTLS13,
3877 ClientAuth: RequireAnyClientCert,
3878 },
3879 flags: []string{
3880 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3881 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3882 },
3883 })
3884 tests = append(tests, testCase{
3885 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003886 name: "ClientAuth-ECDSA-Client",
3887 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003888 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003889 ClientAuth: RequireAnyClientCert,
3890 },
3891 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003892 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3893 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003894 },
3895 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003896 tests = append(tests, testCase{
3897 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003898 name: "ClientAuth-ECDSA-Client-TLS13",
3899 config: Config{
3900 MaxVersion: VersionTLS13,
3901 ClientAuth: RequireAnyClientCert,
3902 },
3903 flags: []string{
3904 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3905 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3906 },
3907 })
3908 tests = append(tests, testCase{
3909 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003910 name: "ClientAuth-NoCertificate-OldCallback",
3911 config: Config{
3912 MaxVersion: VersionTLS12,
3913 ClientAuth: RequestClientCert,
3914 },
3915 flags: []string{"-use-old-client-cert-callback"},
3916 })
3917 tests = append(tests, testCase{
3918 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003919 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3920 config: Config{
3921 MaxVersion: VersionTLS13,
3922 ClientAuth: RequestClientCert,
3923 },
3924 flags: []string{"-use-old-client-cert-callback"},
3925 })
3926 tests = append(tests, testCase{
3927 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003928 name: "ClientAuth-OldCallback",
3929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003930 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003931 ClientAuth: RequireAnyClientCert,
3932 },
3933 flags: []string{
3934 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3935 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3936 "-use-old-client-cert-callback",
3937 },
3938 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003939 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003940 testType: clientTest,
3941 name: "ClientAuth-OldCallback-TLS13",
3942 config: Config{
3943 MaxVersion: VersionTLS13,
3944 ClientAuth: RequireAnyClientCert,
3945 },
3946 flags: []string{
3947 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3948 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3949 "-use-old-client-cert-callback",
3950 },
3951 })
3952 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 testType: serverTest,
3954 name: "ClientAuth-Server",
3955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003956 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003957 Certificates: []Certificate{rsaCertificate},
3958 },
3959 flags: []string{"-require-any-client-certificate"},
3960 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003961 tests = append(tests, testCase{
3962 testType: serverTest,
3963 name: "ClientAuth-Server-TLS13",
3964 config: Config{
3965 MaxVersion: VersionTLS13,
3966 Certificates: []Certificate{rsaCertificate},
3967 },
3968 flags: []string{"-require-any-client-certificate"},
3969 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003970
David Benjamin4c3ddf72016-06-29 18:13:53 -04003971 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 tests = append(tests, testCase{
3973 testType: serverTest,
3974 name: "Basic-Server-RSA",
3975 config: Config{
3976 MaxVersion: VersionTLS12,
3977 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3978 },
3979 flags: []string{
3980 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3981 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3982 },
3983 })
3984 tests = append(tests, testCase{
3985 testType: serverTest,
3986 name: "Basic-Server-ECDHE-RSA",
3987 config: Config{
3988 MaxVersion: VersionTLS12,
3989 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3990 },
3991 flags: []string{
3992 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3993 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3994 },
3995 })
3996 tests = append(tests, testCase{
3997 testType: serverTest,
3998 name: "Basic-Server-ECDHE-ECDSA",
3999 config: Config{
4000 MaxVersion: VersionTLS12,
4001 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4002 },
4003 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004004 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4005 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004006 },
4007 })
David Benjamin69522112017-03-28 15:38:29 -05004008 tests = append(tests, testCase{
4009 testType: serverTest,
4010 name: "Basic-Server-Ed25519",
4011 config: Config{
4012 MaxVersion: VersionTLS12,
4013 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4014 },
4015 flags: []string{
4016 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4017 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4018 "-enable-ed25519",
4019 },
4020 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021
David Benjamin760b1dd2015-05-15 23:33:48 -04004022 // No session ticket support; server doesn't send NewSessionTicket.
4023 tests = append(tests, testCase{
4024 name: "SessionTicketsDisabled-Client",
4025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004026 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004027 SessionTicketsDisabled: true,
4028 },
4029 })
4030 tests = append(tests, testCase{
4031 testType: serverTest,
4032 name: "SessionTicketsDisabled-Server",
4033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004034 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004035 SessionTicketsDisabled: true,
4036 },
4037 })
4038
4039 // Skip ServerKeyExchange in PSK key exchange if there's no
4040 // identity hint.
4041 tests = append(tests, testCase{
4042 name: "EmptyPSKHint-Client",
4043 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004044 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004045 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4046 PreSharedKey: []byte("secret"),
4047 },
4048 flags: []string{"-psk", "secret"},
4049 })
4050 tests = append(tests, testCase{
4051 testType: serverTest,
4052 name: "EmptyPSKHint-Server",
4053 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004054 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004055 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4056 PreSharedKey: []byte("secret"),
4057 },
4058 flags: []string{"-psk", "secret"},
4059 })
4060
David Benjamin4c3ddf72016-06-29 18:13:53 -04004061 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004062 tests = append(tests, testCase{
4063 testType: clientTest,
4064 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004065 config: Config{
4066 MaxVersion: VersionTLS12,
4067 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004068 flags: []string{
4069 "-enable-ocsp-stapling",
4070 "-expect-ocsp-response",
4071 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004072 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004073 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004074 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004075 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004076 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004077 testType: serverTest,
4078 name: "OCSPStapling-Server",
4079 config: Config{
4080 MaxVersion: VersionTLS12,
4081 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004082 expectedOCSPResponse: testOCSPResponse,
4083 flags: []string{
4084 "-ocsp-response",
4085 base64.StdEncoding.EncodeToString(testOCSPResponse),
4086 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004087 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004088 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004089 tests = append(tests, testCase{
4090 testType: clientTest,
4091 name: "OCSPStapling-Client-TLS13",
4092 config: Config{
4093 MaxVersion: VersionTLS13,
4094 },
4095 flags: []string{
4096 "-enable-ocsp-stapling",
4097 "-expect-ocsp-response",
4098 base64.StdEncoding.EncodeToString(testOCSPResponse),
4099 "-verify-peer",
4100 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004101 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004102 })
4103 tests = append(tests, testCase{
4104 testType: serverTest,
4105 name: "OCSPStapling-Server-TLS13",
4106 config: Config{
4107 MaxVersion: VersionTLS13,
4108 },
4109 expectedOCSPResponse: testOCSPResponse,
4110 flags: []string{
4111 "-ocsp-response",
4112 base64.StdEncoding.EncodeToString(testOCSPResponse),
4113 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004114 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004115 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004116
David Benjamin4c3ddf72016-06-29 18:13:53 -04004117 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004118 for _, vers := range tlsVersions {
4119 if config.protocol == dtls && !vers.hasDTLS {
4120 continue
4121 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004122 for _, testType := range []testType{clientTest, serverTest} {
4123 suffix := "-Client"
4124 if testType == serverTest {
4125 suffix = "-Server"
4126 }
4127 suffix += "-" + vers.name
4128
4129 flag := "-verify-peer"
4130 if testType == serverTest {
4131 flag = "-require-any-client-certificate"
4132 }
4133
4134 tests = append(tests, testCase{
4135 testType: testType,
4136 name: "CertificateVerificationSucceed" + suffix,
4137 config: Config{
4138 MaxVersion: vers.version,
4139 Certificates: []Certificate{rsaCertificate},
4140 },
4141 flags: []string{
4142 flag,
4143 "-expect-verify-result",
4144 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004145 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004146 })
4147 tests = append(tests, testCase{
4148 testType: testType,
4149 name: "CertificateVerificationFail" + suffix,
4150 config: Config{
4151 MaxVersion: vers.version,
4152 Certificates: []Certificate{rsaCertificate},
4153 },
4154 flags: []string{
4155 flag,
4156 "-verify-fail",
4157 },
4158 shouldFail: true,
4159 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4160 })
4161 }
4162
4163 // By default, the client is in a soft fail mode where the peer
4164 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004165 tests = append(tests, testCase{
4166 testType: clientTest,
4167 name: "CertificateVerificationSoftFail-" + vers.name,
4168 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004169 MaxVersion: vers.version,
4170 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004171 },
4172 flags: []string{
4173 "-verify-fail",
4174 "-expect-verify-result",
4175 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004176 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004177 })
4178 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004179
David Benjamin1d4f4c02016-07-26 18:03:08 -04004180 tests = append(tests, testCase{
4181 name: "ShimSendAlert",
4182 flags: []string{"-send-alert"},
4183 shimWritesFirst: true,
4184 shouldFail: true,
4185 expectedLocalError: "remote error: decompression failure",
4186 })
4187
David Benjamin582ba042016-07-07 12:33:25 -07004188 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004189 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004190 name: "Renegotiate-Client",
4191 config: Config{
4192 MaxVersion: VersionTLS12,
4193 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004194 renegotiate: 1,
4195 flags: []string{
4196 "-renegotiate-freely",
4197 "-expect-total-renegotiations", "1",
4198 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004199 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004200
David Benjamin47921102016-07-28 11:29:18 -04004201 tests = append(tests, testCase{
4202 name: "SendHalfHelloRequest",
4203 config: Config{
4204 MaxVersion: VersionTLS12,
4205 Bugs: ProtocolBugs{
4206 PackHelloRequestWithFinished: config.packHandshakeFlight,
4207 },
4208 },
4209 sendHalfHelloRequest: true,
4210 flags: []string{"-renegotiate-ignore"},
4211 shouldFail: true,
4212 expectedError: ":UNEXPECTED_RECORD:",
4213 })
4214
David Benjamin760b1dd2015-05-15 23:33:48 -04004215 // NPN on client and server; results in post-handshake message.
4216 tests = append(tests, testCase{
4217 name: "NPN-Client",
4218 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004219 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004220 NextProtos: []string{"foo"},
4221 },
4222 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004223 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004224 expectedNextProto: "foo",
4225 expectedNextProtoType: npn,
4226 })
4227 tests = append(tests, testCase{
4228 testType: serverTest,
4229 name: "NPN-Server",
4230 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004231 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004232 NextProtos: []string{"bar"},
4233 },
4234 flags: []string{
4235 "-advertise-npn", "\x03foo\x03bar\x03baz",
4236 "-expect-next-proto", "bar",
4237 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004238 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004239 expectedNextProto: "bar",
4240 expectedNextProtoType: npn,
4241 })
4242
4243 // TODO(davidben): Add tests for when False Start doesn't trigger.
4244
4245 // Client does False Start and negotiates NPN.
4246 tests = append(tests, testCase{
4247 name: "FalseStart",
4248 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004249 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004250 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4251 NextProtos: []string{"foo"},
4252 Bugs: ProtocolBugs{
4253 ExpectFalseStart: true,
4254 },
4255 },
4256 flags: []string{
4257 "-false-start",
4258 "-select-next-proto", "foo",
4259 },
4260 shimWritesFirst: true,
4261 resumeSession: true,
4262 })
4263
4264 // Client does False Start and negotiates ALPN.
4265 tests = append(tests, testCase{
4266 name: "FalseStart-ALPN",
4267 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004268 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004269 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4270 NextProtos: []string{"foo"},
4271 Bugs: ProtocolBugs{
4272 ExpectFalseStart: true,
4273 },
4274 },
4275 flags: []string{
4276 "-false-start",
4277 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004278 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004279 },
4280 shimWritesFirst: true,
4281 resumeSession: true,
4282 })
4283
David Benjamin760b1dd2015-05-15 23:33:48 -04004284 // False Start without session tickets.
4285 tests = append(tests, testCase{
4286 name: "FalseStart-SessionTicketsDisabled",
4287 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004288 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4290 NextProtos: []string{"foo"},
4291 SessionTicketsDisabled: true,
4292 Bugs: ProtocolBugs{
4293 ExpectFalseStart: true,
4294 },
4295 },
4296 flags: []string{
4297 "-false-start",
4298 "-select-next-proto", "foo",
4299 },
4300 shimWritesFirst: true,
4301 })
4302
4303 // Server parses a V2ClientHello.
4304 tests = append(tests, testCase{
4305 testType: serverTest,
4306 name: "SendV2ClientHello",
4307 config: Config{
4308 // Choose a cipher suite that does not involve
4309 // elliptic curves, so no extensions are
4310 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004311 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004312 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004313 Bugs: ProtocolBugs{
4314 SendV2ClientHello: true,
4315 },
4316 },
4317 })
4318
Nick Harper60a85cb2016-09-23 16:25:11 -07004319 // Test Channel ID
4320 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004321 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004322 continue
4323 }
4324 // Client sends a Channel ID.
4325 tests = append(tests, testCase{
4326 name: "ChannelID-Client-" + ver.name,
4327 config: Config{
4328 MaxVersion: ver.version,
4329 RequestChannelID: true,
4330 },
4331 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4332 resumeSession: true,
4333 expectChannelID: true,
4334 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004335
Nick Harper60a85cb2016-09-23 16:25:11 -07004336 // Server accepts a Channel ID.
4337 tests = append(tests, testCase{
4338 testType: serverTest,
4339 name: "ChannelID-Server-" + ver.name,
4340 config: Config{
4341 MaxVersion: ver.version,
4342 ChannelID: channelIDKey,
4343 },
4344 flags: []string{
4345 "-expect-channel-id",
4346 base64.StdEncoding.EncodeToString(channelIDBytes),
4347 },
4348 resumeSession: true,
4349 expectChannelID: true,
4350 })
4351
4352 tests = append(tests, testCase{
4353 testType: serverTest,
4354 name: "InvalidChannelIDSignature-" + ver.name,
4355 config: Config{
4356 MaxVersion: ver.version,
4357 ChannelID: channelIDKey,
4358 Bugs: ProtocolBugs{
4359 InvalidChannelIDSignature: true,
4360 },
4361 },
4362 flags: []string{"-enable-channel-id"},
4363 shouldFail: true,
4364 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4365 })
4366 }
David Benjamin30789da2015-08-29 22:56:45 -04004367
David Benjaminf8fcdf32016-06-08 15:56:13 -04004368 // Channel ID and NPN at the same time, to ensure their relative
4369 // ordering is correct.
4370 tests = append(tests, testCase{
4371 name: "ChannelID-NPN-Client",
4372 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004373 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004374 RequestChannelID: true,
4375 NextProtos: []string{"foo"},
4376 },
4377 flags: []string{
4378 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4379 "-select-next-proto", "foo",
4380 },
4381 resumeSession: true,
4382 expectChannelID: true,
4383 expectedNextProto: "foo",
4384 expectedNextProtoType: npn,
4385 })
4386 tests = append(tests, testCase{
4387 testType: serverTest,
4388 name: "ChannelID-NPN-Server",
4389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004390 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004391 ChannelID: channelIDKey,
4392 NextProtos: []string{"bar"},
4393 },
4394 flags: []string{
4395 "-expect-channel-id",
4396 base64.StdEncoding.EncodeToString(channelIDBytes),
4397 "-advertise-npn", "\x03foo\x03bar\x03baz",
4398 "-expect-next-proto", "bar",
4399 },
4400 resumeSession: true,
4401 expectChannelID: true,
4402 expectedNextProto: "bar",
4403 expectedNextProtoType: npn,
4404 })
4405
David Benjamin30789da2015-08-29 22:56:45 -04004406 // Bidirectional shutdown with the runner initiating.
4407 tests = append(tests, testCase{
4408 name: "Shutdown-Runner",
4409 config: Config{
4410 Bugs: ProtocolBugs{
4411 ExpectCloseNotify: true,
4412 },
4413 },
4414 flags: []string{"-check-close-notify"},
4415 })
4416
David Benjamine3843d42017-03-25 18:00:56 -05004417 if !config.implicitHandshake {
4418 // Bidirectional shutdown with the shim initiating. The runner,
4419 // in the meantime, sends garbage before the close_notify which
4420 // the shim must ignore. This test is disabled under implicit
4421 // handshake tests because the shim never reads or writes.
4422 tests = append(tests, testCase{
4423 name: "Shutdown-Shim",
4424 config: Config{
4425 MaxVersion: VersionTLS12,
4426 Bugs: ProtocolBugs{
4427 ExpectCloseNotify: true,
4428 },
David Benjamin30789da2015-08-29 22:56:45 -04004429 },
David Benjamine3843d42017-03-25 18:00:56 -05004430 shimShutsDown: true,
4431 sendEmptyRecords: 1,
4432 sendWarningAlerts: 1,
4433 flags: []string{"-check-close-notify"},
4434 })
4435 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004436 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004437 // TODO(davidben): DTLS 1.3 will want a similar thing for
4438 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004439 tests = append(tests, testCase{
4440 name: "SkipHelloVerifyRequest",
4441 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004442 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004443 Bugs: ProtocolBugs{
4444 SkipHelloVerifyRequest: true,
4445 },
4446 },
4447 })
4448 }
4449
David Benjamin760b1dd2015-05-15 23:33:48 -04004450 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004451 test.protocol = config.protocol
4452 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004453 test.name += "-DTLS"
4454 }
David Benjamin582ba042016-07-07 12:33:25 -07004455 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004456 test.name += "-Async"
4457 test.flags = append(test.flags, "-async")
4458 } else {
4459 test.name += "-Sync"
4460 }
David Benjamin582ba042016-07-07 12:33:25 -07004461 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004462 test.name += "-SplitHandshakeRecords"
4463 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004464 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004465 test.config.Bugs.MaxPacketLength = 256
4466 test.flags = append(test.flags, "-mtu", "256")
4467 }
4468 }
David Benjamin582ba042016-07-07 12:33:25 -07004469 if config.packHandshakeFlight {
4470 test.name += "-PackHandshakeFlight"
4471 test.config.Bugs.PackHandshakeFlight = true
4472 }
David Benjamine3843d42017-03-25 18:00:56 -05004473 if config.implicitHandshake {
4474 test.name += "-ImplicitHandshake"
4475 test.flags = append(test.flags, "-implicit-handshake")
4476 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004477 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004478 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004479}
4480
Adam Langley524e7172015-02-20 16:04:00 -08004481func addDDoSCallbackTests() {
4482 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004483 for _, resume := range []bool{false, true} {
4484 suffix := "Resume"
4485 if resume {
4486 suffix = "No" + suffix
4487 }
4488
4489 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004490 testType: serverTest,
4491 name: "Server-DDoS-OK-" + suffix,
4492 config: Config{
4493 MaxVersion: VersionTLS12,
4494 },
Adam Langley524e7172015-02-20 16:04:00 -08004495 flags: []string{"-install-ddos-callback"},
4496 resumeSession: resume,
4497 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004498 testCases = append(testCases, testCase{
4499 testType: serverTest,
4500 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4501 config: Config{
4502 MaxVersion: VersionTLS13,
4503 },
4504 flags: []string{"-install-ddos-callback"},
4505 resumeSession: resume,
4506 })
Adam Langley524e7172015-02-20 16:04:00 -08004507
4508 failFlag := "-fail-ddos-callback"
4509 if resume {
4510 failFlag = "-fail-second-ddos-callback"
4511 }
4512 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004513 testType: serverTest,
4514 name: "Server-DDoS-Reject-" + suffix,
4515 config: Config{
4516 MaxVersion: VersionTLS12,
4517 },
David Benjamin2c66e072016-09-16 15:58:00 -04004518 flags: []string{"-install-ddos-callback", failFlag},
4519 resumeSession: resume,
4520 shouldFail: true,
4521 expectedError: ":CONNECTION_REJECTED:",
4522 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004523 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004524 testCases = append(testCases, testCase{
4525 testType: serverTest,
4526 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4527 config: Config{
4528 MaxVersion: VersionTLS13,
4529 },
David Benjamin2c66e072016-09-16 15:58:00 -04004530 flags: []string{"-install-ddos-callback", failFlag},
4531 resumeSession: resume,
4532 shouldFail: true,
4533 expectedError: ":CONNECTION_REJECTED:",
4534 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004535 })
Adam Langley524e7172015-02-20 16:04:00 -08004536 }
4537}
4538
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004539func addVersionNegotiationTests() {
4540 for i, shimVers := range tlsVersions {
4541 // Assemble flags to disable all newer versions on the shim.
4542 var flags []string
4543 for _, vers := range tlsVersions[i+1:] {
4544 flags = append(flags, vers.flag)
4545 }
4546
Steven Valdezfdd10992016-09-15 16:27:05 -04004547 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004548 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004549 protocols := []protocol{tls}
4550 if runnerVers.hasDTLS && shimVers.hasDTLS {
4551 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004552 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004553 for _, protocol := range protocols {
4554 expectedVersion := shimVers.version
4555 if runnerVers.version < shimVers.version {
4556 expectedVersion = runnerVers.version
4557 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004558
David Benjamin8b8c0062014-11-23 02:47:52 -05004559 suffix := shimVers.name + "-" + runnerVers.name
4560 if protocol == dtls {
4561 suffix += "-DTLS"
4562 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004563
David Benjamin1eb367c2014-12-12 18:17:51 -05004564 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4565
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004566 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004567 clientVers := shimVers.version
4568 if clientVers > VersionTLS10 {
4569 clientVers = VersionTLS10
4570 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004571 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004572 serverVers := expectedVersion
4573 if expectedVersion >= VersionTLS13 {
4574 serverVers = VersionTLS10
4575 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004576 serverVers = versionToWire(serverVers, protocol == dtls)
4577
David Benjamin8b8c0062014-11-23 02:47:52 -05004578 testCases = append(testCases, testCase{
4579 protocol: protocol,
4580 testType: clientTest,
4581 name: "VersionNegotiation-Client-" + suffix,
4582 config: Config{
4583 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004584 Bugs: ProtocolBugs{
4585 ExpectInitialRecordVersion: clientVers,
4586 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004587 },
4588 flags: flags,
4589 expectedVersion: expectedVersion,
4590 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004591 testCases = append(testCases, testCase{
4592 protocol: protocol,
4593 testType: clientTest,
4594 name: "VersionNegotiation-Client2-" + suffix,
4595 config: Config{
4596 MaxVersion: runnerVers.version,
4597 Bugs: ProtocolBugs{
4598 ExpectInitialRecordVersion: clientVers,
4599 },
4600 },
4601 flags: []string{"-max-version", shimVersFlag},
4602 expectedVersion: expectedVersion,
4603 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004604
4605 testCases = append(testCases, testCase{
4606 protocol: protocol,
4607 testType: serverTest,
4608 name: "VersionNegotiation-Server-" + suffix,
4609 config: Config{
4610 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004611 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004612 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004613 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004614 },
4615 flags: flags,
4616 expectedVersion: expectedVersion,
4617 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004618 testCases = append(testCases, testCase{
4619 protocol: protocol,
4620 testType: serverTest,
4621 name: "VersionNegotiation-Server2-" + suffix,
4622 config: Config{
4623 MaxVersion: runnerVers.version,
4624 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004625 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004626 },
4627 },
4628 flags: []string{"-max-version", shimVersFlag},
4629 expectedVersion: expectedVersion,
4630 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004631 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004632 }
4633 }
David Benjamin95c69562016-06-29 18:15:03 -04004634
Steven Valdezfdd10992016-09-15 16:27:05 -04004635 // Test the version extension at all versions.
4636 for _, vers := range tlsVersions {
4637 protocols := []protocol{tls}
4638 if vers.hasDTLS {
4639 protocols = append(protocols, dtls)
4640 }
4641 for _, protocol := range protocols {
4642 suffix := vers.name
4643 if protocol == dtls {
4644 suffix += "-DTLS"
4645 }
4646
4647 wireVersion := versionToWire(vers.version, protocol == dtls)
4648 testCases = append(testCases, testCase{
4649 protocol: protocol,
4650 testType: serverTest,
4651 name: "VersionNegotiationExtension-" + suffix,
4652 config: Config{
4653 Bugs: ProtocolBugs{
4654 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4655 },
4656 },
4657 expectedVersion: vers.version,
4658 })
4659 }
4660
4661 }
4662
4663 // If all versions are unknown, negotiation fails.
4664 testCases = append(testCases, testCase{
4665 testType: serverTest,
4666 name: "NoSupportedVersions",
4667 config: Config{
4668 Bugs: ProtocolBugs{
4669 SendSupportedVersions: []uint16{0x1111},
4670 },
4671 },
4672 shouldFail: true,
4673 expectedError: ":UNSUPPORTED_PROTOCOL:",
4674 })
4675 testCases = append(testCases, testCase{
4676 protocol: dtls,
4677 testType: serverTest,
4678 name: "NoSupportedVersions-DTLS",
4679 config: Config{
4680 Bugs: ProtocolBugs{
4681 SendSupportedVersions: []uint16{0x1111},
4682 },
4683 },
4684 shouldFail: true,
4685 expectedError: ":UNSUPPORTED_PROTOCOL:",
4686 })
4687
4688 testCases = append(testCases, testCase{
4689 testType: serverTest,
4690 name: "ClientHelloVersionTooHigh",
4691 config: Config{
4692 MaxVersion: VersionTLS13,
4693 Bugs: ProtocolBugs{
4694 SendClientVersion: 0x0304,
4695 OmitSupportedVersions: true,
4696 },
4697 },
4698 expectedVersion: VersionTLS12,
4699 })
4700
4701 testCases = append(testCases, testCase{
4702 testType: serverTest,
4703 name: "ConflictingVersionNegotiation",
4704 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004705 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004706 SendClientVersion: VersionTLS12,
4707 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004708 },
4709 },
David Benjaminad75a662016-09-30 15:42:59 -04004710 // The extension takes precedence over the ClientHello version.
4711 expectedVersion: VersionTLS11,
4712 })
4713
4714 testCases = append(testCases, testCase{
4715 testType: serverTest,
4716 name: "ConflictingVersionNegotiation-2",
4717 config: Config{
4718 Bugs: ProtocolBugs{
4719 SendClientVersion: VersionTLS11,
4720 SendSupportedVersions: []uint16{VersionTLS12},
4721 },
4722 },
4723 // The extension takes precedence over the ClientHello version.
4724 expectedVersion: VersionTLS12,
4725 })
4726
4727 testCases = append(testCases, testCase{
4728 testType: serverTest,
4729 name: "RejectFinalTLS13",
4730 config: Config{
4731 Bugs: ProtocolBugs{
4732 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4733 },
4734 },
4735 // We currently implement a draft TLS 1.3 version. Ensure that
4736 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004737 expectedVersion: VersionTLS12,
4738 })
4739
Brian Smithf85d3232016-10-28 10:34:06 -10004740 // Test that the maximum version is selected regardless of the
4741 // client-sent order.
4742 testCases = append(testCases, testCase{
4743 testType: serverTest,
4744 name: "IgnoreClientVersionOrder",
4745 config: Config{
4746 Bugs: ProtocolBugs{
4747 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4748 },
4749 },
4750 expectedVersion: VersionTLS13,
4751 })
4752
David Benjamin95c69562016-06-29 18:15:03 -04004753 // Test for version tolerance.
4754 testCases = append(testCases, testCase{
4755 testType: serverTest,
4756 name: "MinorVersionTolerance",
4757 config: Config{
4758 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004759 SendClientVersion: 0x03ff,
4760 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004761 },
4762 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004763 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004764 })
4765 testCases = append(testCases, testCase{
4766 testType: serverTest,
4767 name: "MajorVersionTolerance",
4768 config: Config{
4769 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004770 SendClientVersion: 0x0400,
4771 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004772 },
4773 },
David Benjaminad75a662016-09-30 15:42:59 -04004774 // TLS 1.3 must be negotiated with the supported_versions
4775 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004776 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004777 })
David Benjaminad75a662016-09-30 15:42:59 -04004778 testCases = append(testCases, testCase{
4779 testType: serverTest,
4780 name: "VersionTolerance-TLS13",
4781 config: Config{
4782 Bugs: ProtocolBugs{
4783 // Although TLS 1.3 does not use
4784 // ClientHello.version, it still tolerates high
4785 // values there.
4786 SendClientVersion: 0x0400,
4787 },
4788 },
4789 expectedVersion: VersionTLS13,
4790 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004791
David Benjamin95c69562016-06-29 18:15:03 -04004792 testCases = append(testCases, testCase{
4793 protocol: dtls,
4794 testType: serverTest,
4795 name: "MinorVersionTolerance-DTLS",
4796 config: Config{
4797 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004798 SendClientVersion: 0xfe00,
4799 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004800 },
4801 },
4802 expectedVersion: VersionTLS12,
4803 })
4804 testCases = append(testCases, testCase{
4805 protocol: dtls,
4806 testType: serverTest,
4807 name: "MajorVersionTolerance-DTLS",
4808 config: Config{
4809 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004810 SendClientVersion: 0xfdff,
4811 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004812 },
4813 },
4814 expectedVersion: VersionTLS12,
4815 })
4816
4817 // Test that versions below 3.0 are rejected.
4818 testCases = append(testCases, testCase{
4819 testType: serverTest,
4820 name: "VersionTooLow",
4821 config: Config{
4822 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004823 SendClientVersion: 0x0200,
4824 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004825 },
4826 },
4827 shouldFail: true,
4828 expectedError: ":UNSUPPORTED_PROTOCOL:",
4829 })
4830 testCases = append(testCases, testCase{
4831 protocol: dtls,
4832 testType: serverTest,
4833 name: "VersionTooLow-DTLS",
4834 config: Config{
4835 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004836 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004837 },
4838 },
4839 shouldFail: true,
4840 expectedError: ":UNSUPPORTED_PROTOCOL:",
4841 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004842
David Benjamin2dc02042016-09-19 19:57:37 -04004843 testCases = append(testCases, testCase{
4844 name: "ServerBogusVersion",
4845 config: Config{
4846 Bugs: ProtocolBugs{
4847 SendServerHelloVersion: 0x1234,
4848 },
4849 },
4850 shouldFail: true,
4851 expectedError: ":UNSUPPORTED_PROTOCOL:",
4852 })
4853
David Benjamin1f61f0d2016-07-10 12:20:35 -04004854 // Test TLS 1.3's downgrade signal.
4855 testCases = append(testCases, testCase{
4856 name: "Downgrade-TLS12-Client",
4857 config: Config{
4858 Bugs: ProtocolBugs{
4859 NegotiateVersion: VersionTLS12,
4860 },
4861 },
David Benjamin592b5322016-09-30 15:15:01 -04004862 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004863 // TODO(davidben): This test should fail once TLS 1.3 is final
4864 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004865 })
4866 testCases = append(testCases, testCase{
4867 testType: serverTest,
4868 name: "Downgrade-TLS12-Server",
4869 config: Config{
4870 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004871 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004872 },
4873 },
David Benjamin592b5322016-09-30 15:15:01 -04004874 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004875 // TODO(davidben): This test should fail once TLS 1.3 is final
4876 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004877 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004878}
4879
David Benjaminaccb4542014-12-12 23:44:33 -05004880func addMinimumVersionTests() {
4881 for i, shimVers := range tlsVersions {
4882 // Assemble flags to disable all older versions on the shim.
4883 var flags []string
4884 for _, vers := range tlsVersions[:i] {
4885 flags = append(flags, vers.flag)
4886 }
4887
4888 for _, runnerVers := range tlsVersions {
4889 protocols := []protocol{tls}
4890 if runnerVers.hasDTLS && shimVers.hasDTLS {
4891 protocols = append(protocols, dtls)
4892 }
4893 for _, protocol := range protocols {
4894 suffix := shimVers.name + "-" + runnerVers.name
4895 if protocol == dtls {
4896 suffix += "-DTLS"
4897 }
4898 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4899
David Benjaminaccb4542014-12-12 23:44:33 -05004900 var expectedVersion uint16
4901 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004902 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004903 if runnerVers.version >= shimVers.version {
4904 expectedVersion = runnerVers.version
4905 } else {
4906 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004907 expectedError = ":UNSUPPORTED_PROTOCOL:"
4908 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004909 }
4910
4911 testCases = append(testCases, testCase{
4912 protocol: protocol,
4913 testType: clientTest,
4914 name: "MinimumVersion-Client-" + suffix,
4915 config: Config{
4916 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004917 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004918 // Ensure the server does not decline to
4919 // select a version (versions extension) or
4920 // cipher (some ciphers depend on versions).
4921 NegotiateVersion: runnerVers.version,
4922 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004923 },
David Benjaminaccb4542014-12-12 23:44:33 -05004924 },
David Benjamin87909c02014-12-13 01:55:01 -05004925 flags: flags,
4926 expectedVersion: expectedVersion,
4927 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004928 expectedError: expectedError,
4929 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004930 })
4931 testCases = append(testCases, testCase{
4932 protocol: protocol,
4933 testType: clientTest,
4934 name: "MinimumVersion-Client2-" + suffix,
4935 config: Config{
4936 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004937 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004938 // Ensure the server does not decline to
4939 // select a version (versions extension) or
4940 // cipher (some ciphers depend on versions).
4941 NegotiateVersion: runnerVers.version,
4942 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004943 },
David Benjaminaccb4542014-12-12 23:44:33 -05004944 },
David Benjamin87909c02014-12-13 01:55:01 -05004945 flags: []string{"-min-version", shimVersFlag},
4946 expectedVersion: expectedVersion,
4947 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004948 expectedError: expectedError,
4949 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004950 })
4951
4952 testCases = append(testCases, testCase{
4953 protocol: protocol,
4954 testType: serverTest,
4955 name: "MinimumVersion-Server-" + suffix,
4956 config: Config{
4957 MaxVersion: runnerVers.version,
4958 },
David Benjamin87909c02014-12-13 01:55:01 -05004959 flags: flags,
4960 expectedVersion: expectedVersion,
4961 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004962 expectedError: expectedError,
4963 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004964 })
4965 testCases = append(testCases, testCase{
4966 protocol: protocol,
4967 testType: serverTest,
4968 name: "MinimumVersion-Server2-" + suffix,
4969 config: Config{
4970 MaxVersion: runnerVers.version,
4971 },
David Benjamin87909c02014-12-13 01:55:01 -05004972 flags: []string{"-min-version", shimVersFlag},
4973 expectedVersion: expectedVersion,
4974 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004975 expectedError: expectedError,
4976 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004977 })
4978 }
4979 }
4980 }
4981}
4982
David Benjamine78bfde2014-09-06 12:45:15 -04004983func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004984 // TODO(davidben): Extensions, where applicable, all move their server
4985 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4986 // tests for both. Also test interaction with 0-RTT when implemented.
4987
David Benjamin97d17d92016-07-14 16:12:00 -04004988 // Repeat extensions tests all versions except SSL 3.0.
4989 for _, ver := range tlsVersions {
4990 if ver.version == VersionSSL30 {
4991 continue
4992 }
4993
David Benjamin97d17d92016-07-14 16:12:00 -04004994 // Test that duplicate extensions are rejected.
4995 testCases = append(testCases, testCase{
4996 testType: clientTest,
4997 name: "DuplicateExtensionClient-" + ver.name,
4998 config: Config{
4999 MaxVersion: ver.version,
5000 Bugs: ProtocolBugs{
5001 DuplicateExtension: true,
5002 },
David Benjamine78bfde2014-09-06 12:45:15 -04005003 },
David Benjamin97d17d92016-07-14 16:12:00 -04005004 shouldFail: true,
5005 expectedLocalError: "remote error: error decoding message",
5006 })
5007 testCases = append(testCases, testCase{
5008 testType: serverTest,
5009 name: "DuplicateExtensionServer-" + ver.name,
5010 config: Config{
5011 MaxVersion: ver.version,
5012 Bugs: ProtocolBugs{
5013 DuplicateExtension: true,
5014 },
David Benjamine78bfde2014-09-06 12:45:15 -04005015 },
David Benjamin97d17d92016-07-14 16:12:00 -04005016 shouldFail: true,
5017 expectedLocalError: "remote error: error decoding message",
5018 })
5019
5020 // Test SNI.
5021 testCases = append(testCases, testCase{
5022 testType: clientTest,
5023 name: "ServerNameExtensionClient-" + ver.name,
5024 config: Config{
5025 MaxVersion: ver.version,
5026 Bugs: ProtocolBugs{
5027 ExpectServerName: "example.com",
5028 },
David Benjamine78bfde2014-09-06 12:45:15 -04005029 },
David Benjamin97d17d92016-07-14 16:12:00 -04005030 flags: []string{"-host-name", "example.com"},
5031 })
5032 testCases = append(testCases, testCase{
5033 testType: clientTest,
5034 name: "ServerNameExtensionClientMismatch-" + ver.name,
5035 config: Config{
5036 MaxVersion: ver.version,
5037 Bugs: ProtocolBugs{
5038 ExpectServerName: "mismatch.com",
5039 },
David Benjamine78bfde2014-09-06 12:45:15 -04005040 },
David Benjamin97d17d92016-07-14 16:12:00 -04005041 flags: []string{"-host-name", "example.com"},
5042 shouldFail: true,
5043 expectedLocalError: "tls: unexpected server name",
5044 })
5045 testCases = append(testCases, testCase{
5046 testType: clientTest,
5047 name: "ServerNameExtensionClientMissing-" + ver.name,
5048 config: Config{
5049 MaxVersion: ver.version,
5050 Bugs: ProtocolBugs{
5051 ExpectServerName: "missing.com",
5052 },
David Benjamine78bfde2014-09-06 12:45:15 -04005053 },
David Benjamin97d17d92016-07-14 16:12:00 -04005054 shouldFail: true,
5055 expectedLocalError: "tls: unexpected server name",
5056 })
5057 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005058 testType: clientTest,
5059 name: "TolerateServerNameAck-" + ver.name,
5060 config: Config{
5061 MaxVersion: ver.version,
5062 Bugs: ProtocolBugs{
5063 SendServerNameAck: true,
5064 },
5065 },
5066 flags: []string{"-host-name", "example.com"},
5067 resumeSession: true,
5068 })
5069 testCases = append(testCases, testCase{
5070 testType: clientTest,
5071 name: "UnsolicitedServerNameAck-" + ver.name,
5072 config: Config{
5073 MaxVersion: ver.version,
5074 Bugs: ProtocolBugs{
5075 SendServerNameAck: true,
5076 },
5077 },
5078 shouldFail: true,
5079 expectedError: ":UNEXPECTED_EXTENSION:",
5080 expectedLocalError: "remote error: unsupported extension",
5081 })
5082 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005083 testType: serverTest,
5084 name: "ServerNameExtensionServer-" + ver.name,
5085 config: Config{
5086 MaxVersion: ver.version,
5087 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005088 },
David Benjamin97d17d92016-07-14 16:12:00 -04005089 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005090 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005091 })
5092
5093 // Test ALPN.
5094 testCases = append(testCases, testCase{
5095 testType: clientTest,
5096 name: "ALPNClient-" + ver.name,
5097 config: Config{
5098 MaxVersion: ver.version,
5099 NextProtos: []string{"foo"},
5100 },
5101 flags: []string{
5102 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5103 "-expect-alpn", "foo",
5104 },
5105 expectedNextProto: "foo",
5106 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005107 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005108 })
5109 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005110 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005111 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005112 config: Config{
5113 MaxVersion: ver.version,
5114 Bugs: ProtocolBugs{
5115 SendALPN: "baz",
5116 },
5117 },
5118 flags: []string{
5119 "-advertise-alpn", "\x03foo\x03bar",
5120 },
5121 shouldFail: true,
5122 expectedError: ":INVALID_ALPN_PROTOCOL:",
5123 expectedLocalError: "remote error: illegal parameter",
5124 })
5125 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005126 testType: clientTest,
5127 name: "ALPNClient-AllowUnknown-" + ver.name,
5128 config: Config{
5129 MaxVersion: ver.version,
5130 Bugs: ProtocolBugs{
5131 SendALPN: "baz",
5132 },
5133 },
5134 flags: []string{
5135 "-advertise-alpn", "\x03foo\x03bar",
5136 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005137 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005138 },
5139 })
5140 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005141 testType: serverTest,
5142 name: "ALPNServer-" + ver.name,
5143 config: Config{
5144 MaxVersion: ver.version,
5145 NextProtos: []string{"foo", "bar", "baz"},
5146 },
5147 flags: []string{
5148 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5149 "-select-alpn", "foo",
5150 },
5151 expectedNextProto: "foo",
5152 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005153 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005154 })
5155 testCases = append(testCases, testCase{
5156 testType: serverTest,
5157 name: "ALPNServer-Decline-" + ver.name,
5158 config: Config{
5159 MaxVersion: ver.version,
5160 NextProtos: []string{"foo", "bar", "baz"},
5161 },
5162 flags: []string{"-decline-alpn"},
5163 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005164 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005165 })
5166
David Benjamin25fe85b2016-08-09 20:00:32 -04005167 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5168 // called once.
5169 testCases = append(testCases, testCase{
5170 testType: serverTest,
5171 name: "ALPNServer-Async-" + ver.name,
5172 config: Config{
5173 MaxVersion: ver.version,
5174 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005175 // Prior to TLS 1.3, exercise the asynchronous session callback.
5176 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005177 },
5178 flags: []string{
5179 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5180 "-select-alpn", "foo",
5181 "-async",
5182 },
5183 expectedNextProto: "foo",
5184 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005185 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005186 })
5187
David Benjamin97d17d92016-07-14 16:12:00 -04005188 var emptyString string
5189 testCases = append(testCases, testCase{
5190 testType: clientTest,
5191 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5192 config: Config{
5193 MaxVersion: ver.version,
5194 NextProtos: []string{""},
5195 Bugs: ProtocolBugs{
5196 // A server returning an empty ALPN protocol
5197 // should be rejected.
5198 ALPNProtocol: &emptyString,
5199 },
5200 },
5201 flags: []string{
5202 "-advertise-alpn", "\x03foo",
5203 },
5204 shouldFail: true,
5205 expectedError: ":PARSE_TLSEXT:",
5206 })
5207 testCases = append(testCases, testCase{
5208 testType: serverTest,
5209 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5210 config: Config{
5211 MaxVersion: ver.version,
5212 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005213 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005214 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005215 },
David Benjamin97d17d92016-07-14 16:12:00 -04005216 flags: []string{
5217 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005218 },
David Benjamin97d17d92016-07-14 16:12:00 -04005219 shouldFail: true,
5220 expectedError: ":PARSE_TLSEXT:",
5221 })
5222
5223 // Test NPN and the interaction with ALPN.
5224 if ver.version < VersionTLS13 {
5225 // Test that the server prefers ALPN over NPN.
5226 testCases = append(testCases, testCase{
5227 testType: serverTest,
5228 name: "ALPNServer-Preferred-" + ver.name,
5229 config: Config{
5230 MaxVersion: ver.version,
5231 NextProtos: []string{"foo", "bar", "baz"},
5232 },
5233 flags: []string{
5234 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5235 "-select-alpn", "foo",
5236 "-advertise-npn", "\x03foo\x03bar\x03baz",
5237 },
5238 expectedNextProto: "foo",
5239 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005240 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005241 })
5242 testCases = append(testCases, testCase{
5243 testType: serverTest,
5244 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5245 config: Config{
5246 MaxVersion: ver.version,
5247 NextProtos: []string{"foo", "bar", "baz"},
5248 Bugs: ProtocolBugs{
5249 SwapNPNAndALPN: true,
5250 },
5251 },
5252 flags: []string{
5253 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5254 "-select-alpn", "foo",
5255 "-advertise-npn", "\x03foo\x03bar\x03baz",
5256 },
5257 expectedNextProto: "foo",
5258 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005259 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005260 })
5261
5262 // Test that negotiating both NPN and ALPN is forbidden.
5263 testCases = append(testCases, testCase{
5264 name: "NegotiateALPNAndNPN-" + ver.name,
5265 config: Config{
5266 MaxVersion: ver.version,
5267 NextProtos: []string{"foo", "bar", "baz"},
5268 Bugs: ProtocolBugs{
5269 NegotiateALPNAndNPN: true,
5270 },
5271 },
5272 flags: []string{
5273 "-advertise-alpn", "\x03foo",
5274 "-select-next-proto", "foo",
5275 },
5276 shouldFail: true,
5277 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5278 })
5279 testCases = append(testCases, testCase{
5280 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5281 config: Config{
5282 MaxVersion: ver.version,
5283 NextProtos: []string{"foo", "bar", "baz"},
5284 Bugs: ProtocolBugs{
5285 NegotiateALPNAndNPN: true,
5286 SwapNPNAndALPN: true,
5287 },
5288 },
5289 flags: []string{
5290 "-advertise-alpn", "\x03foo",
5291 "-select-next-proto", "foo",
5292 },
5293 shouldFail: true,
5294 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5295 })
David Benjamin97d17d92016-07-14 16:12:00 -04005296 }
5297
5298 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005299
5300 // Resume with a corrupt ticket.
5301 testCases = append(testCases, testCase{
5302 testType: serverTest,
5303 name: "CorruptTicket-" + ver.name,
5304 config: Config{
5305 MaxVersion: ver.version,
5306 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005307 FilterTicket: func(in []byte) ([]byte, error) {
5308 in[len(in)-1] ^= 1
5309 return in, nil
5310 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005311 },
5312 },
5313 resumeSession: true,
5314 expectResumeRejected: true,
5315 })
5316 // Test the ticket callback, with and without renewal.
5317 testCases = append(testCases, testCase{
5318 testType: serverTest,
5319 name: "TicketCallback-" + ver.name,
5320 config: Config{
5321 MaxVersion: ver.version,
5322 },
5323 resumeSession: true,
5324 flags: []string{"-use-ticket-callback"},
5325 })
5326 testCases = append(testCases, testCase{
5327 testType: serverTest,
5328 name: "TicketCallback-Renew-" + ver.name,
5329 config: Config{
5330 MaxVersion: ver.version,
5331 Bugs: ProtocolBugs{
5332 ExpectNewTicket: true,
5333 },
5334 },
5335 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5336 resumeSession: true,
5337 })
5338
5339 // Test that the ticket callback is only called once when everything before
5340 // it in the ClientHello is asynchronous. This corrupts the ticket so
5341 // certificate selection callbacks run.
5342 testCases = append(testCases, testCase{
5343 testType: serverTest,
5344 name: "TicketCallback-SingleCall-" + ver.name,
5345 config: Config{
5346 MaxVersion: ver.version,
5347 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005348 FilterTicket: func(in []byte) ([]byte, error) {
5349 in[len(in)-1] ^= 1
5350 return in, nil
5351 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005352 },
5353 },
5354 resumeSession: true,
5355 expectResumeRejected: true,
5356 flags: []string{
5357 "-use-ticket-callback",
5358 "-async",
5359 },
5360 })
5361
David Benjamind4c349b2017-02-09 14:07:17 -05005362 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005363 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005364 testCases = append(testCases, testCase{
5365 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005366 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005367 config: Config{
5368 MaxVersion: ver.version,
5369 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005370 EmptyTicketSessionID: true,
5371 },
5372 },
5373 resumeSession: true,
5374 })
5375 testCases = append(testCases, testCase{
5376 testType: serverTest,
5377 name: "TicketSessionIDLength-16-" + ver.name,
5378 config: Config{
5379 MaxVersion: ver.version,
5380 Bugs: ProtocolBugs{
5381 TicketSessionIDLength: 16,
5382 },
5383 },
5384 resumeSession: true,
5385 })
5386 testCases = append(testCases, testCase{
5387 testType: serverTest,
5388 name: "TicketSessionIDLength-32-" + ver.name,
5389 config: Config{
5390 MaxVersion: ver.version,
5391 Bugs: ProtocolBugs{
5392 TicketSessionIDLength: 32,
5393 },
5394 },
5395 resumeSession: true,
5396 })
5397 testCases = append(testCases, testCase{
5398 testType: serverTest,
5399 name: "TicketSessionIDLength-33-" + ver.name,
5400 config: Config{
5401 MaxVersion: ver.version,
5402 Bugs: ProtocolBugs{
5403 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005404 },
5405 },
5406 resumeSession: true,
5407 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005408 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005409 expectedError: ":DECODE_ERROR:",
5410 })
5411 }
5412
5413 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5414 // are ignored.
5415 if ver.hasDTLS {
5416 testCases = append(testCases, testCase{
5417 protocol: dtls,
5418 name: "SRTP-Client-" + ver.name,
5419 config: Config{
5420 MaxVersion: ver.version,
5421 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5422 },
5423 flags: []string{
5424 "-srtp-profiles",
5425 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5426 },
5427 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5428 })
5429 testCases = append(testCases, testCase{
5430 protocol: dtls,
5431 testType: serverTest,
5432 name: "SRTP-Server-" + ver.name,
5433 config: Config{
5434 MaxVersion: ver.version,
5435 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5436 },
5437 flags: []string{
5438 "-srtp-profiles",
5439 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5440 },
5441 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5442 })
5443 // Test that the MKI is ignored.
5444 testCases = append(testCases, testCase{
5445 protocol: dtls,
5446 testType: serverTest,
5447 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5448 config: Config{
5449 MaxVersion: ver.version,
5450 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5451 Bugs: ProtocolBugs{
5452 SRTPMasterKeyIdentifer: "bogus",
5453 },
5454 },
5455 flags: []string{
5456 "-srtp-profiles",
5457 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5458 },
5459 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5460 })
5461 // Test that SRTP isn't negotiated on the server if there were
5462 // no matching profiles.
5463 testCases = append(testCases, testCase{
5464 protocol: dtls,
5465 testType: serverTest,
5466 name: "SRTP-Server-NoMatch-" + ver.name,
5467 config: Config{
5468 MaxVersion: ver.version,
5469 SRTPProtectionProfiles: []uint16{100, 101, 102},
5470 },
5471 flags: []string{
5472 "-srtp-profiles",
5473 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5474 },
5475 expectedSRTPProtectionProfile: 0,
5476 })
5477 // Test that the server returning an invalid SRTP profile is
5478 // flagged as an error by the client.
5479 testCases = append(testCases, testCase{
5480 protocol: dtls,
5481 name: "SRTP-Client-NoMatch-" + ver.name,
5482 config: Config{
5483 MaxVersion: ver.version,
5484 Bugs: ProtocolBugs{
5485 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5486 },
5487 },
5488 flags: []string{
5489 "-srtp-profiles",
5490 "SRTP_AES128_CM_SHA1_80",
5491 },
5492 shouldFail: true,
5493 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5494 })
5495 }
5496
5497 // Test SCT list.
5498 testCases = append(testCases, testCase{
5499 name: "SignedCertificateTimestampList-Client-" + ver.name,
5500 testType: clientTest,
5501 config: Config{
5502 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005503 },
David Benjamin97d17d92016-07-14 16:12:00 -04005504 flags: []string{
5505 "-enable-signed-cert-timestamps",
5506 "-expect-signed-cert-timestamps",
5507 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005508 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005509 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005510 })
David Benjamindaa88502016-10-04 16:32:16 -04005511
Adam Langleycfa08c32016-11-17 13:21:27 -08005512 var differentSCTList []byte
5513 differentSCTList = append(differentSCTList, testSCTList...)
5514 differentSCTList[len(differentSCTList)-1] ^= 1
5515
David Benjamindaa88502016-10-04 16:32:16 -04005516 // The SCT extension did not specify that it must only be sent on resumption as it
5517 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005518 testCases = append(testCases, testCase{
5519 name: "SendSCTListOnResume-" + ver.name,
5520 config: Config{
5521 MaxVersion: ver.version,
5522 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005523 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005524 },
David Benjamind98452d2015-06-16 14:16:23 -04005525 },
David Benjamin97d17d92016-07-14 16:12:00 -04005526 flags: []string{
5527 "-enable-signed-cert-timestamps",
5528 "-expect-signed-cert-timestamps",
5529 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005530 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005531 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005532 })
David Benjamindaa88502016-10-04 16:32:16 -04005533
David Benjamin97d17d92016-07-14 16:12:00 -04005534 testCases = append(testCases, testCase{
5535 name: "SignedCertificateTimestampList-Server-" + ver.name,
5536 testType: serverTest,
5537 config: Config{
5538 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005539 },
David Benjamin97d17d92016-07-14 16:12:00 -04005540 flags: []string{
5541 "-signed-cert-timestamps",
5542 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005543 },
David Benjamin97d17d92016-07-14 16:12:00 -04005544 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005545 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005546 })
David Benjamin53210cb2016-11-16 09:01:48 +09005547
Adam Langleycfa08c32016-11-17 13:21:27 -08005548 emptySCTListCert := *testCerts[0].cert
5549 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5550
5551 // Test empty SCT list.
5552 testCases = append(testCases, testCase{
5553 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5554 testType: clientTest,
5555 config: Config{
5556 MaxVersion: ver.version,
5557 Certificates: []Certificate{emptySCTListCert},
5558 },
5559 flags: []string{
5560 "-enable-signed-cert-timestamps",
5561 },
5562 shouldFail: true,
5563 expectedError: ":ERROR_PARSING_EXTENSION:",
5564 })
5565
5566 emptySCTCert := *testCerts[0].cert
5567 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5568
5569 // Test empty SCT in non-empty list.
5570 testCases = append(testCases, testCase{
5571 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5572 testType: clientTest,
5573 config: Config{
5574 MaxVersion: ver.version,
5575 Certificates: []Certificate{emptySCTCert},
5576 },
5577 flags: []string{
5578 "-enable-signed-cert-timestamps",
5579 },
5580 shouldFail: true,
5581 expectedError: ":ERROR_PARSING_EXTENSION:",
5582 })
5583
David Benjamin53210cb2016-11-16 09:01:48 +09005584 // Test that certificate-related extensions are not sent unsolicited.
5585 testCases = append(testCases, testCase{
5586 testType: serverTest,
5587 name: "UnsolicitedCertificateExtensions-" + ver.name,
5588 config: Config{
5589 MaxVersion: ver.version,
5590 Bugs: ProtocolBugs{
5591 NoOCSPStapling: true,
5592 NoSignedCertificateTimestamps: true,
5593 },
5594 },
5595 flags: []string{
5596 "-ocsp-response",
5597 base64.StdEncoding.EncodeToString(testOCSPResponse),
5598 "-signed-cert-timestamps",
5599 base64.StdEncoding.EncodeToString(testSCTList),
5600 },
5601 })
David Benjamin97d17d92016-07-14 16:12:00 -04005602 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005603
Paul Lietar4fac72e2015-09-09 13:44:55 +01005604 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005605 testType: clientTest,
5606 name: "ClientHelloPadding",
5607 config: Config{
5608 Bugs: ProtocolBugs{
5609 RequireClientHelloSize: 512,
5610 },
5611 },
5612 // This hostname just needs to be long enough to push the
5613 // ClientHello into F5's danger zone between 256 and 511 bytes
5614 // long.
5615 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5616 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005617
5618 // Extensions should not function in SSL 3.0.
5619 testCases = append(testCases, testCase{
5620 testType: serverTest,
5621 name: "SSLv3Extensions-NoALPN",
5622 config: Config{
5623 MaxVersion: VersionSSL30,
5624 NextProtos: []string{"foo", "bar", "baz"},
5625 },
5626 flags: []string{
5627 "-select-alpn", "foo",
5628 },
5629 expectNoNextProto: true,
5630 })
5631
5632 // Test session tickets separately as they follow a different codepath.
5633 testCases = append(testCases, testCase{
5634 testType: serverTest,
5635 name: "SSLv3Extensions-NoTickets",
5636 config: Config{
5637 MaxVersion: VersionSSL30,
5638 Bugs: ProtocolBugs{
5639 // Historically, session tickets in SSL 3.0
5640 // failed in different ways depending on whether
5641 // the client supported renegotiation_info.
5642 NoRenegotiationInfo: true,
5643 },
5644 },
5645 resumeSession: true,
5646 })
5647 testCases = append(testCases, testCase{
5648 testType: serverTest,
5649 name: "SSLv3Extensions-NoTickets2",
5650 config: Config{
5651 MaxVersion: VersionSSL30,
5652 },
5653 resumeSession: true,
5654 })
5655
5656 // But SSL 3.0 does send and process renegotiation_info.
5657 testCases = append(testCases, testCase{
5658 testType: serverTest,
5659 name: "SSLv3Extensions-RenegotiationInfo",
5660 config: Config{
5661 MaxVersion: VersionSSL30,
5662 Bugs: ProtocolBugs{
5663 RequireRenegotiationInfo: true,
5664 },
5665 },
David Benjamind2610042017-01-03 10:49:28 -05005666 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005667 })
5668 testCases = append(testCases, testCase{
5669 testType: serverTest,
5670 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5671 config: Config{
5672 MaxVersion: VersionSSL30,
5673 Bugs: ProtocolBugs{
5674 NoRenegotiationInfo: true,
5675 SendRenegotiationSCSV: true,
5676 RequireRenegotiationInfo: true,
5677 },
5678 },
David Benjamind2610042017-01-03 10:49:28 -05005679 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005680 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005681
5682 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5683 // in ServerHello.
5684 testCases = append(testCases, testCase{
5685 name: "NPN-Forbidden-TLS13",
5686 config: Config{
5687 MaxVersion: VersionTLS13,
5688 NextProtos: []string{"foo"},
5689 Bugs: ProtocolBugs{
5690 NegotiateNPNAtAllVersions: true,
5691 },
5692 },
5693 flags: []string{"-select-next-proto", "foo"},
5694 shouldFail: true,
5695 expectedError: ":ERROR_PARSING_EXTENSION:",
5696 })
5697 testCases = append(testCases, testCase{
5698 name: "EMS-Forbidden-TLS13",
5699 config: Config{
5700 MaxVersion: VersionTLS13,
5701 Bugs: ProtocolBugs{
5702 NegotiateEMSAtAllVersions: true,
5703 },
5704 },
5705 shouldFail: true,
5706 expectedError: ":ERROR_PARSING_EXTENSION:",
5707 })
5708 testCases = append(testCases, testCase{
5709 name: "RenegotiationInfo-Forbidden-TLS13",
5710 config: Config{
5711 MaxVersion: VersionTLS13,
5712 Bugs: ProtocolBugs{
5713 NegotiateRenegotiationInfoAtAllVersions: true,
5714 },
5715 },
5716 shouldFail: true,
5717 expectedError: ":ERROR_PARSING_EXTENSION:",
5718 })
5719 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005720 name: "Ticket-Forbidden-TLS13",
5721 config: Config{
5722 MaxVersion: VersionTLS12,
5723 },
5724 resumeConfig: &Config{
5725 MaxVersion: VersionTLS13,
5726 Bugs: ProtocolBugs{
5727 AdvertiseTicketExtension: true,
5728 },
5729 },
5730 resumeSession: true,
5731 shouldFail: true,
5732 expectedError: ":ERROR_PARSING_EXTENSION:",
5733 })
5734
5735 // Test that illegal extensions in TLS 1.3 are declined by the server if
5736 // offered in ClientHello. The runner's server will fail if this occurs,
5737 // so we exercise the offering path. (EMS and Renegotiation Info are
5738 // implicit in every test.)
5739 testCases = append(testCases, testCase{
5740 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005741 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005742 config: Config{
5743 MaxVersion: VersionTLS13,
5744 NextProtos: []string{"bar"},
5745 },
5746 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5747 })
David Benjamin196df5b2016-09-21 16:23:27 -04005748
David Benjamindaa88502016-10-04 16:32:16 -04005749 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5750 // tolerated.
5751 testCases = append(testCases, testCase{
5752 name: "SendOCSPResponseOnResume-TLS12",
5753 config: Config{
5754 MaxVersion: VersionTLS12,
5755 Bugs: ProtocolBugs{
5756 SendOCSPResponseOnResume: []byte("bogus"),
5757 },
5758 },
5759 flags: []string{
5760 "-enable-ocsp-stapling",
5761 "-expect-ocsp-response",
5762 base64.StdEncoding.EncodeToString(testOCSPResponse),
5763 },
5764 resumeSession: true,
5765 })
5766
David Benjamindaa88502016-10-04 16:32:16 -04005767 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005768 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005769 config: Config{
5770 MaxVersion: VersionTLS13,
5771 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005772 SendExtensionOnCertificate: testOCSPExtension,
5773 },
5774 },
5775 shouldFail: true,
5776 expectedError: ":UNEXPECTED_EXTENSION:",
5777 })
5778
5779 testCases = append(testCases, testCase{
5780 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5781 config: Config{
5782 MaxVersion: VersionTLS13,
5783 Bugs: ProtocolBugs{
5784 SendExtensionOnCertificate: testSCTExtension,
5785 },
5786 },
5787 shouldFail: true,
5788 expectedError: ":UNEXPECTED_EXTENSION:",
5789 })
5790
5791 // Test that extensions on client certificates are never accepted.
5792 testCases = append(testCases, testCase{
5793 name: "SendExtensionOnClientCertificate-TLS13",
5794 testType: serverTest,
5795 config: Config{
5796 MaxVersion: VersionTLS13,
5797 Certificates: []Certificate{rsaCertificate},
5798 Bugs: ProtocolBugs{
5799 SendExtensionOnCertificate: testOCSPExtension,
5800 },
5801 },
5802 flags: []string{
5803 "-enable-ocsp-stapling",
5804 "-require-any-client-certificate",
5805 },
5806 shouldFail: true,
5807 expectedError: ":UNEXPECTED_EXTENSION:",
5808 })
5809
5810 testCases = append(testCases, testCase{
5811 name: "SendUnknownExtensionOnCertificate-TLS13",
5812 config: Config{
5813 MaxVersion: VersionTLS13,
5814 Bugs: ProtocolBugs{
5815 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5816 },
5817 },
5818 shouldFail: true,
5819 expectedError: ":UNEXPECTED_EXTENSION:",
5820 })
5821
Adam Langleycfa08c32016-11-17 13:21:27 -08005822 var differentSCTList []byte
5823 differentSCTList = append(differentSCTList, testSCTList...)
5824 differentSCTList[len(differentSCTList)-1] ^= 1
5825
Steven Valdeza833c352016-11-01 13:39:36 -04005826 // Test that extensions on intermediates are allowed but ignored.
5827 testCases = append(testCases, testCase{
5828 name: "IgnoreExtensionsOnIntermediates-TLS13",
5829 config: Config{
5830 MaxVersion: VersionTLS13,
5831 Certificates: []Certificate{rsaChainCertificate},
5832 Bugs: ProtocolBugs{
5833 // Send different values on the intermediate. This tests
5834 // the intermediate's extensions do not override the
5835 // leaf's.
5836 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005837 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005838 },
5839 },
5840 flags: []string{
5841 "-enable-ocsp-stapling",
5842 "-expect-ocsp-response",
5843 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005844 "-enable-signed-cert-timestamps",
5845 "-expect-signed-cert-timestamps",
5846 base64.StdEncoding.EncodeToString(testSCTList),
5847 },
5848 resumeSession: true,
5849 })
5850
5851 // Test that extensions are not sent on intermediates when configured
5852 // only for a leaf.
5853 testCases = append(testCases, testCase{
5854 testType: serverTest,
5855 name: "SendNoExtensionsOnIntermediate-TLS13",
5856 config: Config{
5857 MaxVersion: VersionTLS13,
5858 Bugs: ProtocolBugs{
5859 ExpectNoExtensionsOnIntermediate: true,
5860 },
5861 },
5862 flags: []string{
5863 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5864 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5865 "-ocsp-response",
5866 base64.StdEncoding.EncodeToString(testOCSPResponse),
5867 "-signed-cert-timestamps",
5868 base64.StdEncoding.EncodeToString(testSCTList),
5869 },
5870 })
5871
5872 // Test that extensions are not sent on client certificates.
5873 testCases = append(testCases, testCase{
5874 name: "SendNoClientCertificateExtensions-TLS13",
5875 config: Config{
5876 MaxVersion: VersionTLS13,
5877 ClientAuth: RequireAnyClientCert,
5878 },
5879 flags: []string{
5880 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5881 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5882 "-ocsp-response",
5883 base64.StdEncoding.EncodeToString(testOCSPResponse),
5884 "-signed-cert-timestamps",
5885 base64.StdEncoding.EncodeToString(testSCTList),
5886 },
5887 })
5888
5889 testCases = append(testCases, testCase{
5890 name: "SendDuplicateExtensionsOnCerts-TLS13",
5891 config: Config{
5892 MaxVersion: VersionTLS13,
5893 Bugs: ProtocolBugs{
5894 SendDuplicateCertExtensions: true,
5895 },
5896 },
5897 flags: []string{
5898 "-enable-ocsp-stapling",
5899 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005900 },
5901 resumeSession: true,
5902 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005903 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005904 })
Adam Langley9b885c52016-11-18 14:21:03 -08005905
5906 testCases = append(testCases, testCase{
5907 name: "SignedCertificateTimestampListInvalid-Server",
5908 testType: serverTest,
5909 flags: []string{
5910 "-signed-cert-timestamps",
5911 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5912 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005913 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005914 expectedError: ":INVALID_SCT_LIST:",
5915 })
David Benjamine78bfde2014-09-06 12:45:15 -04005916}
5917
David Benjamin01fe8202014-09-24 15:21:44 -04005918func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005919 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005920 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005921 // SSL 3.0 does not have tickets and TLS 1.3 does not
5922 // have session IDs, so skip their cross-resumption
5923 // tests.
5924 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5925 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5926 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005927 }
5928
David Benjamin8b8c0062014-11-23 02:47:52 -05005929 protocols := []protocol{tls}
5930 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5931 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005932 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005933 for _, protocol := range protocols {
5934 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5935 if protocol == dtls {
5936 suffix += "-DTLS"
5937 }
5938
David Benjaminece3de92015-03-16 18:02:20 -04005939 if sessionVers.version == resumeVers.version {
5940 testCases = append(testCases, testCase{
5941 protocol: protocol,
5942 name: "Resume-Client" + suffix,
5943 resumeSession: true,
5944 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005945 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005946 Bugs: ProtocolBugs{
5947 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5948 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5949 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005950 },
David Benjaminece3de92015-03-16 18:02:20 -04005951 expectedVersion: sessionVers.version,
5952 expectedResumeVersion: resumeVers.version,
5953 })
5954 } else {
David Benjamin405da482016-08-08 17:25:07 -04005955 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5956
5957 // Offering a TLS 1.3 session sends an empty session ID, so
5958 // there is no way to convince a non-lookahead client the
5959 // session was resumed. It will appear to the client that a
5960 // stray ChangeCipherSpec was sent.
5961 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5962 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005963 }
5964
David Benjaminece3de92015-03-16 18:02:20 -04005965 testCases = append(testCases, testCase{
5966 protocol: protocol,
5967 name: "Resume-Client-Mismatch" + suffix,
5968 resumeSession: true,
5969 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005970 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005971 },
David Benjaminece3de92015-03-16 18:02:20 -04005972 expectedVersion: sessionVers.version,
5973 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005974 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005975 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005976 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005977 },
5978 },
5979 expectedResumeVersion: resumeVers.version,
5980 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005981 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005982 })
5983 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005984
5985 testCases = append(testCases, testCase{
5986 protocol: protocol,
5987 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005988 resumeSession: true,
5989 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005990 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005991 },
5992 expectedVersion: sessionVers.version,
5993 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005994 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005995 },
5996 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005997 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005998 expectedResumeVersion: resumeVers.version,
5999 })
6000
David Benjamin8b8c0062014-11-23 02:47:52 -05006001 testCases = append(testCases, testCase{
6002 protocol: protocol,
6003 testType: serverTest,
6004 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006005 resumeSession: true,
6006 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006007 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006008 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006009 expectedVersion: sessionVers.version,
6010 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006011 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006012 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006013 Bugs: ProtocolBugs{
6014 SendBothTickets: true,
6015 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006016 },
6017 expectedResumeVersion: resumeVers.version,
6018 })
6019 }
David Benjamin01fe8202014-09-24 15:21:44 -04006020 }
6021 }
David Benjaminece3de92015-03-16 18:02:20 -04006022
David Benjamin4199b0d2016-11-01 13:58:25 -04006023 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006024 testCases = append(testCases, testCase{
6025 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006026 name: "ShimTicketRewritable",
6027 resumeSession: true,
6028 config: Config{
6029 MaxVersion: VersionTLS12,
6030 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6031 Bugs: ProtocolBugs{
6032 FilterTicket: func(in []byte) ([]byte, error) {
6033 in, err := SetShimTicketVersion(in, VersionTLS12)
6034 if err != nil {
6035 return nil, err
6036 }
6037 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6038 },
6039 },
6040 },
6041 flags: []string{
6042 "-ticket-key",
6043 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6044 },
6045 })
6046
6047 // Resumptions are declined if the version does not match.
6048 testCases = append(testCases, testCase{
6049 testType: serverTest,
6050 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006051 resumeSession: true,
6052 config: Config{
6053 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006054 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006055 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006056 FilterTicket: func(in []byte) ([]byte, error) {
6057 return SetShimTicketVersion(in, VersionTLS13)
6058 },
6059 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006060 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006061 flags: []string{
6062 "-ticket-key",
6063 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6064 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006065 expectResumeRejected: true,
6066 })
6067
6068 testCases = append(testCases, testCase{
6069 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006070 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006071 resumeSession: true,
6072 config: Config{
6073 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006074 Bugs: ProtocolBugs{
6075 FilterTicket: func(in []byte) ([]byte, error) {
6076 return SetShimTicketVersion(in, VersionTLS12)
6077 },
6078 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006079 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006080 flags: []string{
6081 "-ticket-key",
6082 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6083 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006084 expectResumeRejected: true,
6085 })
6086
David Benjamin4199b0d2016-11-01 13:58:25 -04006087 // Resumptions are declined if the cipher is invalid or disabled.
6088 testCases = append(testCases, testCase{
6089 testType: serverTest,
6090 name: "Resume-Server-DeclineBadCipher",
6091 resumeSession: true,
6092 config: Config{
6093 MaxVersion: VersionTLS12,
6094 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006095 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006096 FilterTicket: func(in []byte) ([]byte, error) {
6097 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6098 },
6099 },
6100 },
6101 flags: []string{
6102 "-ticket-key",
6103 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6104 },
6105 expectResumeRejected: true,
6106 })
6107
6108 testCases = append(testCases, testCase{
6109 testType: serverTest,
6110 name: "Resume-Server-DeclineBadCipher-2",
6111 resumeSession: true,
6112 config: Config{
6113 MaxVersion: VersionTLS12,
6114 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006115 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006116 FilterTicket: func(in []byte) ([]byte, error) {
6117 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6118 },
6119 },
6120 },
6121 flags: []string{
6122 "-cipher", "AES128",
6123 "-ticket-key",
6124 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6125 },
6126 expectResumeRejected: true,
6127 })
6128
David Benjaminf01f42a2016-11-16 19:05:33 +09006129 // Sessions are not resumed if they do not use the preferred cipher.
6130 testCases = append(testCases, testCase{
6131 testType: serverTest,
6132 name: "Resume-Server-CipherNotPreferred",
6133 resumeSession: true,
6134 config: Config{
6135 MaxVersion: VersionTLS12,
6136 Bugs: ProtocolBugs{
6137 ExpectNewTicket: true,
6138 FilterTicket: func(in []byte) ([]byte, error) {
6139 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6140 },
6141 },
6142 },
6143 flags: []string{
6144 "-ticket-key",
6145 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6146 },
6147 shouldFail: false,
6148 expectResumeRejected: true,
6149 })
6150
6151 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6152 // PRF hashes match, but BoringSSL will always decline such resumptions.
6153 testCases = append(testCases, testCase{
6154 testType: serverTest,
6155 name: "Resume-Server-CipherNotPreferred-TLS13",
6156 resumeSession: true,
6157 config: Config{
6158 MaxVersion: VersionTLS13,
6159 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6160 Bugs: ProtocolBugs{
6161 FilterTicket: func(in []byte) ([]byte, error) {
6162 // If the client (runner) offers ChaCha20-Poly1305 first, the
6163 // server (shim) always prefers it. Switch it to AES-GCM.
6164 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6165 },
6166 },
6167 },
6168 flags: []string{
6169 "-ticket-key",
6170 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6171 },
6172 shouldFail: false,
6173 expectResumeRejected: true,
6174 })
6175
6176 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006177 testCases = append(testCases, testCase{
6178 testType: serverTest,
6179 name: "Resume-Server-DeclineBadCipher-TLS13",
6180 resumeSession: true,
6181 config: Config{
6182 MaxVersion: VersionTLS13,
6183 Bugs: ProtocolBugs{
6184 FilterTicket: func(in []byte) ([]byte, error) {
6185 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6186 },
6187 },
6188 },
6189 flags: []string{
6190 "-ticket-key",
6191 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6192 },
6193 expectResumeRejected: true,
6194 })
6195
David Benjaminf01f42a2016-11-16 19:05:33 +09006196 // If the client does not offer the cipher from the session, decline to
6197 // resume. Clients are forbidden from doing this, but BoringSSL selects
6198 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006199 testCases = append(testCases, testCase{
6200 testType: serverTest,
6201 name: "Resume-Server-UnofferedCipher",
6202 resumeSession: true,
6203 config: Config{
6204 MaxVersion: VersionTLS12,
6205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6206 },
6207 resumeConfig: &Config{
6208 MaxVersion: VersionTLS12,
6209 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6210 Bugs: ProtocolBugs{
6211 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6212 },
6213 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006214 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006215 })
6216
David Benjaminf01f42a2016-11-16 19:05:33 +09006217 // In TLS 1.3, clients may advertise a cipher list which does not
6218 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006219 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6220 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006221 testCases = append(testCases, testCase{
6222 testType: serverTest,
6223 name: "Resume-Server-UnofferedCipher-TLS13",
6224 resumeSession: true,
6225 config: Config{
6226 MaxVersion: VersionTLS13,
6227 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6228 },
6229 resumeConfig: &Config{
6230 MaxVersion: VersionTLS13,
6231 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6232 Bugs: ProtocolBugs{
6233 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6234 },
6235 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006236 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006237 })
6238
David Benjamin4199b0d2016-11-01 13:58:25 -04006239 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006240 testCases = append(testCases, testCase{
6241 name: "Resume-Client-CipherMismatch",
6242 resumeSession: true,
6243 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006244 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006245 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6246 },
6247 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006248 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006249 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6250 Bugs: ProtocolBugs{
6251 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6252 },
6253 },
6254 shouldFail: true,
6255 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6256 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006257
David Benjamine1cc35e2016-11-16 16:25:58 +09006258 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6259 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006260 testCases = append(testCases, testCase{
6261 name: "Resume-Client-CipherMismatch-TLS13",
6262 resumeSession: true,
6263 config: Config{
6264 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006265 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006266 },
6267 resumeConfig: &Config{
6268 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006269 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6270 },
6271 })
6272
6273 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6274 testCases = append(testCases, testCase{
6275 name: "Resume-Client-PRFMismatch-TLS13",
6276 resumeSession: true,
6277 config: Config{
6278 MaxVersion: VersionTLS13,
6279 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6280 },
6281 resumeConfig: &Config{
6282 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006283 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006284 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006285 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006286 },
6287 },
6288 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006289 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006290 })
Steven Valdeza833c352016-11-01 13:39:36 -04006291
6292 testCases = append(testCases, testCase{
6293 testType: serverTest,
6294 name: "Resume-Server-BinderWrongLength",
6295 resumeSession: true,
6296 config: Config{
6297 MaxVersion: VersionTLS13,
6298 Bugs: ProtocolBugs{
6299 SendShortPSKBinder: true,
6300 },
6301 },
6302 shouldFail: true,
6303 expectedLocalError: "remote error: error decrypting message",
6304 expectedError: ":DIGEST_CHECK_FAILED:",
6305 })
6306
6307 testCases = append(testCases, testCase{
6308 testType: serverTest,
6309 name: "Resume-Server-NoPSKBinder",
6310 resumeSession: true,
6311 config: Config{
6312 MaxVersion: VersionTLS13,
6313 Bugs: ProtocolBugs{
6314 SendNoPSKBinder: true,
6315 },
6316 },
6317 shouldFail: true,
6318 expectedLocalError: "remote error: error decoding message",
6319 expectedError: ":DECODE_ERROR:",
6320 })
6321
6322 testCases = append(testCases, testCase{
6323 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006324 name: "Resume-Server-ExtraPSKBinder",
6325 resumeSession: true,
6326 config: Config{
6327 MaxVersion: VersionTLS13,
6328 Bugs: ProtocolBugs{
6329 SendExtraPSKBinder: true,
6330 },
6331 },
6332 shouldFail: true,
6333 expectedLocalError: "remote error: illegal parameter",
6334 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6335 })
6336
6337 testCases = append(testCases, testCase{
6338 testType: serverTest,
6339 name: "Resume-Server-ExtraIdentityNoBinder",
6340 resumeSession: true,
6341 config: Config{
6342 MaxVersion: VersionTLS13,
6343 Bugs: ProtocolBugs{
6344 ExtraPSKIdentity: true,
6345 },
6346 },
6347 shouldFail: true,
6348 expectedLocalError: "remote error: illegal parameter",
6349 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6350 })
6351
6352 testCases = append(testCases, testCase{
6353 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006354 name: "Resume-Server-InvalidPSKBinder",
6355 resumeSession: true,
6356 config: Config{
6357 MaxVersion: VersionTLS13,
6358 Bugs: ProtocolBugs{
6359 SendInvalidPSKBinder: true,
6360 },
6361 },
6362 shouldFail: true,
6363 expectedLocalError: "remote error: error decrypting message",
6364 expectedError: ":DIGEST_CHECK_FAILED:",
6365 })
6366
6367 testCases = append(testCases, testCase{
6368 testType: serverTest,
6369 name: "Resume-Server-PSKBinderFirstExtension",
6370 resumeSession: true,
6371 config: Config{
6372 MaxVersion: VersionTLS13,
6373 Bugs: ProtocolBugs{
6374 PSKBinderFirst: true,
6375 },
6376 },
6377 shouldFail: true,
6378 expectedLocalError: "remote error: illegal parameter",
6379 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6380 })
David Benjamin01fe8202014-09-24 15:21:44 -04006381}
6382
Adam Langley2ae77d22014-10-28 17:29:33 -07006383func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006384 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006385 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006386 testType: serverTest,
6387 name: "Renegotiate-Server-Forbidden",
6388 config: Config{
6389 MaxVersion: VersionTLS12,
6390 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006391 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006392 shouldFail: true,
6393 expectedError: ":NO_RENEGOTIATION:",
6394 expectedLocalError: "remote error: no renegotiation",
6395 })
Adam Langley5021b222015-06-12 18:27:58 -07006396 // The server shouldn't echo the renegotiation extension unless
6397 // requested by the client.
6398 testCases = append(testCases, testCase{
6399 testType: serverTest,
6400 name: "Renegotiate-Server-NoExt",
6401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006402 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006403 Bugs: ProtocolBugs{
6404 NoRenegotiationInfo: true,
6405 RequireRenegotiationInfo: true,
6406 },
6407 },
6408 shouldFail: true,
6409 expectedLocalError: "renegotiation extension missing",
6410 })
6411 // The renegotiation SCSV should be sufficient for the server to echo
6412 // the extension.
6413 testCases = append(testCases, testCase{
6414 testType: serverTest,
6415 name: "Renegotiate-Server-NoExt-SCSV",
6416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006417 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006418 Bugs: ProtocolBugs{
6419 NoRenegotiationInfo: true,
6420 SendRenegotiationSCSV: true,
6421 RequireRenegotiationInfo: true,
6422 },
6423 },
6424 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006425 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006426 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006428 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006429 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006430 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006431 },
6432 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006433 renegotiate: 1,
6434 flags: []string{
6435 "-renegotiate-freely",
6436 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006437 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006438 },
David Benjamincdea40c2015-03-19 14:09:43 -04006439 })
6440 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006441 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006442 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006444 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006445 Bugs: ProtocolBugs{
6446 EmptyRenegotiationInfo: true,
6447 },
6448 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006449 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006450 shouldFail: true,
6451 expectedError: ":RENEGOTIATION_MISMATCH:",
6452 })
6453 testCases = append(testCases, testCase{
6454 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006455 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006457 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006458 Bugs: ProtocolBugs{
6459 BadRenegotiationInfo: true,
6460 },
6461 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006462 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006463 shouldFail: true,
6464 expectedError: ":RENEGOTIATION_MISMATCH:",
6465 })
6466 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006467 name: "Renegotiate-Client-Downgrade",
6468 renegotiate: 1,
6469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006470 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006471 Bugs: ProtocolBugs{
6472 NoRenegotiationInfoAfterInitial: true,
6473 },
6474 },
6475 flags: []string{"-renegotiate-freely"},
6476 shouldFail: true,
6477 expectedError: ":RENEGOTIATION_MISMATCH:",
6478 })
6479 testCases = append(testCases, testCase{
6480 name: "Renegotiate-Client-Upgrade",
6481 renegotiate: 1,
6482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006483 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006484 Bugs: ProtocolBugs{
6485 NoRenegotiationInfoInInitial: true,
6486 },
6487 },
6488 flags: []string{"-renegotiate-freely"},
6489 shouldFail: true,
6490 expectedError: ":RENEGOTIATION_MISMATCH:",
6491 })
6492 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006493 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006494 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006495 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006496 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006497 Bugs: ProtocolBugs{
6498 NoRenegotiationInfo: true,
6499 },
6500 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006501 flags: []string{
6502 "-renegotiate-freely",
6503 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006504 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006505 },
David Benjamincff0b902015-05-15 23:09:47 -04006506 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006507
6508 // Test that the server may switch ciphers on renegotiation without
6509 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006510 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006511 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006512 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006513 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006514 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006515 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006516 },
6517 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006518 flags: []string{
6519 "-renegotiate-freely",
6520 "-expect-total-renegotiations", "1",
6521 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006522 })
6523 testCases = append(testCases, testCase{
6524 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006525 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006526 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006527 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006528 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6529 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006530 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006531 flags: []string{
6532 "-renegotiate-freely",
6533 "-expect-total-renegotiations", "1",
6534 },
David Benjaminb16346b2015-04-08 19:16:58 -04006535 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006536
6537 // Test that the server may not switch versions on renegotiation.
6538 testCases = append(testCases, testCase{
6539 name: "Renegotiate-Client-SwitchVersion",
6540 config: Config{
6541 MaxVersion: VersionTLS12,
6542 // Pick a cipher which exists at both versions.
6543 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6544 Bugs: ProtocolBugs{
6545 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006546 // Avoid failing early at the record layer.
6547 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006548 },
6549 },
6550 renegotiate: 1,
6551 flags: []string{
6552 "-renegotiate-freely",
6553 "-expect-total-renegotiations", "1",
6554 },
6555 shouldFail: true,
6556 expectedError: ":WRONG_SSL_VERSION:",
6557 })
6558
David Benjaminb16346b2015-04-08 19:16:58 -04006559 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006560 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006561 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006562 config: Config{
6563 MaxVersion: VersionTLS10,
6564 Bugs: ProtocolBugs{
6565 RequireSameRenegoClientVersion: true,
6566 },
6567 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006568 flags: []string{
6569 "-renegotiate-freely",
6570 "-expect-total-renegotiations", "1",
6571 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006572 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006573 testCases = append(testCases, testCase{
6574 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006575 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006576 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006577 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006578 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6579 NextProtos: []string{"foo"},
6580 },
6581 flags: []string{
6582 "-false-start",
6583 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006584 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006585 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006586 },
6587 shimWritesFirst: true,
6588 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006589
6590 // Client-side renegotiation controls.
6591 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006592 name: "Renegotiate-Client-Forbidden-1",
6593 config: Config{
6594 MaxVersion: VersionTLS12,
6595 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006596 renegotiate: 1,
6597 shouldFail: true,
6598 expectedError: ":NO_RENEGOTIATION:",
6599 expectedLocalError: "remote error: no renegotiation",
6600 })
6601 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006602 name: "Renegotiate-Client-Once-1",
6603 config: Config{
6604 MaxVersion: VersionTLS12,
6605 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006606 renegotiate: 1,
6607 flags: []string{
6608 "-renegotiate-once",
6609 "-expect-total-renegotiations", "1",
6610 },
6611 })
6612 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006613 name: "Renegotiate-Client-Freely-1",
6614 config: Config{
6615 MaxVersion: VersionTLS12,
6616 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006617 renegotiate: 1,
6618 flags: []string{
6619 "-renegotiate-freely",
6620 "-expect-total-renegotiations", "1",
6621 },
6622 })
6623 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006624 name: "Renegotiate-Client-Once-2",
6625 config: Config{
6626 MaxVersion: VersionTLS12,
6627 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006628 renegotiate: 2,
6629 flags: []string{"-renegotiate-once"},
6630 shouldFail: true,
6631 expectedError: ":NO_RENEGOTIATION:",
6632 expectedLocalError: "remote error: no renegotiation",
6633 })
6634 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006635 name: "Renegotiate-Client-Freely-2",
6636 config: Config{
6637 MaxVersion: VersionTLS12,
6638 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006639 renegotiate: 2,
6640 flags: []string{
6641 "-renegotiate-freely",
6642 "-expect-total-renegotiations", "2",
6643 },
6644 })
Adam Langley27a0d082015-11-03 13:34:10 -08006645 testCases = append(testCases, testCase{
6646 name: "Renegotiate-Client-NoIgnore",
6647 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006648 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006649 Bugs: ProtocolBugs{
6650 SendHelloRequestBeforeEveryAppDataRecord: true,
6651 },
6652 },
6653 shouldFail: true,
6654 expectedError: ":NO_RENEGOTIATION:",
6655 })
6656 testCases = append(testCases, testCase{
6657 name: "Renegotiate-Client-Ignore",
6658 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006659 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006660 Bugs: ProtocolBugs{
6661 SendHelloRequestBeforeEveryAppDataRecord: true,
6662 },
6663 },
6664 flags: []string{
6665 "-renegotiate-ignore",
6666 "-expect-total-renegotiations", "0",
6667 },
6668 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006669
David Benjamin34941c02016-10-08 11:45:31 -04006670 // Renegotiation is not allowed at SSL 3.0.
6671 testCases = append(testCases, testCase{
6672 name: "Renegotiate-Client-SSL3",
6673 config: Config{
6674 MaxVersion: VersionSSL30,
6675 },
6676 renegotiate: 1,
6677 flags: []string{
6678 "-renegotiate-freely",
6679 "-expect-total-renegotiations", "1",
6680 },
6681 shouldFail: true,
6682 expectedError: ":NO_RENEGOTIATION:",
6683 expectedLocalError: "remote error: no renegotiation",
6684 })
6685
David Benjamina1eaba12017-01-01 23:19:22 -05006686 // Renegotiation is not allowed when there is an unfinished write.
6687 testCases = append(testCases, testCase{
6688 name: "Renegotiate-Client-UnfinishedWrite",
6689 config: Config{
6690 MaxVersion: VersionTLS12,
6691 },
David Benjaminbbba9392017-04-06 12:54:12 -04006692 renegotiate: 1,
6693 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006694 flags: []string{
6695 "-async",
6696 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006697 },
6698 shouldFail: true,
6699 expectedError: ":NO_RENEGOTIATION:",
6700 // We do not successfully send the no_renegotiation alert in
6701 // this case. https://crbug.com/boringssl/130
6702 })
6703
David Benjamin07ab5d42017-02-09 20:11:41 -05006704 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006705 testCases = append(testCases, testCase{
6706 name: "StrayHelloRequest",
6707 config: Config{
6708 MaxVersion: VersionTLS12,
6709 Bugs: ProtocolBugs{
6710 SendHelloRequestBeforeEveryHandshakeMessage: true,
6711 },
6712 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006713 shouldFail: true,
6714 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006715 })
6716 testCases = append(testCases, testCase{
6717 name: "StrayHelloRequest-Packed",
6718 config: Config{
6719 MaxVersion: VersionTLS12,
6720 Bugs: ProtocolBugs{
6721 PackHandshakeFlight: true,
6722 SendHelloRequestBeforeEveryHandshakeMessage: true,
6723 },
6724 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006725 shouldFail: true,
6726 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006727 })
6728
David Benjamin12d2c482016-07-24 10:56:51 -04006729 // Test renegotiation works if HelloRequest and server Finished come in
6730 // the same record.
6731 testCases = append(testCases, testCase{
6732 name: "Renegotiate-Client-Packed",
6733 config: Config{
6734 MaxVersion: VersionTLS12,
6735 Bugs: ProtocolBugs{
6736 PackHandshakeFlight: true,
6737 PackHelloRequestWithFinished: true,
6738 },
6739 },
6740 renegotiate: 1,
6741 flags: []string{
6742 "-renegotiate-freely",
6743 "-expect-total-renegotiations", "1",
6744 },
6745 })
6746
David Benjamin397c8e62016-07-08 14:14:36 -07006747 // Renegotiation is forbidden in TLS 1.3.
6748 testCases = append(testCases, testCase{
6749 name: "Renegotiate-Client-TLS13",
6750 config: Config{
6751 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006752 Bugs: ProtocolBugs{
6753 SendHelloRequestBeforeEveryAppDataRecord: true,
6754 },
David Benjamin397c8e62016-07-08 14:14:36 -07006755 },
David Benjamin397c8e62016-07-08 14:14:36 -07006756 flags: []string{
6757 "-renegotiate-freely",
6758 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006759 shouldFail: true,
6760 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006761 })
6762
6763 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6764 testCases = append(testCases, testCase{
6765 name: "StrayHelloRequest-TLS13",
6766 config: Config{
6767 MaxVersion: VersionTLS13,
6768 Bugs: ProtocolBugs{
6769 SendHelloRequestBeforeEveryHandshakeMessage: true,
6770 },
6771 },
6772 shouldFail: true,
6773 expectedError: ":UNEXPECTED_MESSAGE:",
6774 })
David Benjamind2610042017-01-03 10:49:28 -05006775
6776 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6777 // always reads as supporting it, regardless of whether it was
6778 // negotiated.
6779 testCases = append(testCases, testCase{
6780 name: "AlwaysReportRenegotiationInfo-TLS13",
6781 config: Config{
6782 MaxVersion: VersionTLS13,
6783 Bugs: ProtocolBugs{
6784 NoRenegotiationInfo: true,
6785 },
6786 },
6787 flags: []string{
6788 "-expect-secure-renegotiation",
6789 },
6790 })
David Benjamina58baaf2017-02-28 20:54:28 -05006791
6792 // Certificates may not change on renegotiation.
6793 testCases = append(testCases, testCase{
6794 name: "Renegotiation-CertificateChange",
6795 config: Config{
6796 MaxVersion: VersionTLS12,
6797 Certificates: []Certificate{rsaCertificate},
6798 Bugs: ProtocolBugs{
6799 RenegotiationCertificate: &rsaChainCertificate,
6800 },
6801 },
6802 renegotiate: 1,
6803 flags: []string{"-renegotiate-freely"},
6804 shouldFail: true,
6805 expectedError: ":SERVER_CERT_CHANGED:",
6806 })
6807 testCases = append(testCases, testCase{
6808 name: "Renegotiation-CertificateChange-2",
6809 config: Config{
6810 MaxVersion: VersionTLS12,
6811 Certificates: []Certificate{rsaCertificate},
6812 Bugs: ProtocolBugs{
6813 RenegotiationCertificate: &rsa1024Certificate,
6814 },
6815 },
6816 renegotiate: 1,
6817 flags: []string{"-renegotiate-freely"},
6818 shouldFail: true,
6819 expectedError: ":SERVER_CERT_CHANGED:",
6820 })
David Benjaminbbf42462017-03-14 21:27:10 -04006821
6822 // We do not negotiate ALPN after the initial handshake. This is
6823 // error-prone and only risks bugs in consumers.
6824 testCases = append(testCases, testCase{
6825 testType: clientTest,
6826 name: "Renegotiation-ForbidALPN",
6827 config: Config{
6828 MaxVersion: VersionTLS12,
6829 Bugs: ProtocolBugs{
6830 // Forcibly negotiate ALPN on both initial and
6831 // renegotiation handshakes. The test stack will
6832 // internally check the client does not offer
6833 // it.
6834 SendALPN: "foo",
6835 },
6836 },
6837 flags: []string{
6838 "-advertise-alpn", "\x03foo\x03bar\x03baz",
6839 "-expect-alpn", "foo",
6840 "-renegotiate-freely",
6841 },
6842 renegotiate: 1,
6843 shouldFail: true,
6844 expectedError: ":UNEXPECTED_EXTENSION:",
6845 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006846}
6847
David Benjamin5e961c12014-11-07 01:48:35 -05006848func addDTLSReplayTests() {
6849 // Test that sequence number replays are detected.
6850 testCases = append(testCases, testCase{
6851 protocol: dtls,
6852 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006853 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006854 replayWrites: true,
6855 })
6856
David Benjamin8e6db492015-07-25 18:29:23 -04006857 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006858 // than the retransmit window.
6859 testCases = append(testCases, testCase{
6860 protocol: dtls,
6861 name: "DTLS-Replay-LargeGaps",
6862 config: Config{
6863 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006864 SequenceNumberMapping: func(in uint64) uint64 {
6865 return in * 127
6866 },
David Benjamin5e961c12014-11-07 01:48:35 -05006867 },
6868 },
David Benjamin8e6db492015-07-25 18:29:23 -04006869 messageCount: 200,
6870 replayWrites: true,
6871 })
6872
6873 // Test the incoming sequence number changing non-monotonically.
6874 testCases = append(testCases, testCase{
6875 protocol: dtls,
6876 name: "DTLS-Replay-NonMonotonic",
6877 config: Config{
6878 Bugs: ProtocolBugs{
6879 SequenceNumberMapping: func(in uint64) uint64 {
6880 return in ^ 31
6881 },
6882 },
6883 },
6884 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006885 replayWrites: true,
6886 })
6887}
6888
Nick Harper60edffd2016-06-21 15:19:24 -07006889var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006890 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006891 id signatureAlgorithm
6892 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006893}{
Nick Harper60edffd2016-06-21 15:19:24 -07006894 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6895 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6896 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6897 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006898 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08006899 // The “P256” in the following line is not a mistake. In TLS 1.2 the
6900 // hash function doesn't have to match the curve and so the same
6901 // signature algorithm works with P-224.
6902 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07006903 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6904 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6905 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006906 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6907 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6908 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05006909 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04006910 // Tests for key types prior to TLS 1.2.
6911 {"RSA", 0, testCertRSA},
6912 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006913}
6914
Nick Harper60edffd2016-06-21 15:19:24 -07006915const fakeSigAlg1 signatureAlgorithm = 0x2a01
6916const fakeSigAlg2 signatureAlgorithm = 0xff01
6917
6918func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006919 // Not all ciphers involve a signature. Advertise a list which gives all
6920 // versions a signing cipher.
6921 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006922 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006923 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6924 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6925 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6926 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006927 }
David Benjamin5208fd42016-07-13 21:43:25 -04006928
David Benjaminca3d5452016-07-14 12:51:01 -04006929 var allAlgorithms []signatureAlgorithm
6930 for _, alg := range testSignatureAlgorithms {
6931 if alg.id != 0 {
6932 allAlgorithms = append(allAlgorithms, alg.id)
6933 }
6934 }
6935
Nick Harper60edffd2016-06-21 15:19:24 -07006936 // Make sure each signature algorithm works. Include some fake values in
6937 // the list and ensure they're ignored.
6938 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006939 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006940 if (ver.version < VersionTLS12) != (alg.id == 0) {
6941 continue
6942 }
6943
6944 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6945 // or remove it in C.
6946 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006947 continue
6948 }
Nick Harper60edffd2016-06-21 15:19:24 -07006949
David Benjamin3ef76972016-10-17 17:59:54 -04006950 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006951 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006952 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006953 shouldSignFail = true
6954 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006955 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006956 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08006957 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
6958 shouldSignFail = true
6959 shouldVerifyFail = true
6960 }
6961 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
6962 // the curve has to match the hash size.
6963 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04006964 shouldSignFail = true
6965 shouldVerifyFail = true
6966 }
6967
6968 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6969 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6970 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006971 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006972
6973 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006974 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006975 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006976 }
6977 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006978 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006979 }
David Benjamin000800a2014-11-14 01:43:59 -05006980
David Benjamin1fb125c2016-07-08 18:52:12 -07006981 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006982
David Benjamin7a41d372016-07-09 11:21:54 -07006983 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006984 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006985 config: Config{
6986 MaxVersion: ver.version,
6987 ClientAuth: RequireAnyClientCert,
6988 VerifySignatureAlgorithms: []signatureAlgorithm{
6989 fakeSigAlg1,
6990 alg.id,
6991 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006992 },
David Benjamin7a41d372016-07-09 11:21:54 -07006993 },
6994 flags: []string{
6995 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6996 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6997 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05006998 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07006999 },
David Benjamin3ef76972016-10-17 17:59:54 -04007000 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007001 expectedError: signError,
7002 expectedPeerSignatureAlgorithm: alg.id,
7003 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007004
David Benjamin7a41d372016-07-09 11:21:54 -07007005 testCases = append(testCases, testCase{
7006 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007007 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007008 config: Config{
7009 MaxVersion: ver.version,
7010 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7011 SignSignatureAlgorithms: []signatureAlgorithm{
7012 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007013 },
David Benjamin7a41d372016-07-09 11:21:54 -07007014 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007015 SkipECDSACurveCheck: shouldVerifyFail,
7016 IgnoreSignatureVersionChecks: shouldVerifyFail,
7017 // Some signature algorithms may not be advertised.
7018 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007019 },
David Benjamin7a41d372016-07-09 11:21:54 -07007020 },
7021 flags: []string{
7022 "-require-any-client-certificate",
7023 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7024 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007025 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007026 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007027 // Resume the session to assert the peer signature
7028 // algorithm is reported on both handshakes.
7029 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007030 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007031 expectedError: verifyError,
7032 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007033
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007034 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007035 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007036 testCases = append(testCases, testCase{
7037 testType: serverTest,
7038 name: "ServerAuth-Sign" + suffix,
7039 config: Config{
7040 MaxVersion: ver.version,
7041 CipherSuites: signingCiphers,
7042 VerifySignatureAlgorithms: []signatureAlgorithm{
7043 fakeSigAlg1,
7044 alg.id,
7045 fakeSigAlg2,
7046 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007047 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007048 flags: []string{
7049 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7050 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7051 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007052 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007053 },
7054 shouldFail: shouldSignFail,
7055 expectedError: signError,
7056 expectedPeerSignatureAlgorithm: alg.id,
7057 })
7058 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007059
7060 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007061 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007062 config: Config{
7063 MaxVersion: ver.version,
7064 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007065 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007066 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007067 alg.id,
7068 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007069 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007070 SkipECDSACurveCheck: shouldVerifyFail,
7071 IgnoreSignatureVersionChecks: shouldVerifyFail,
7072 // Some signature algorithms may not be advertised.
7073 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007074 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007075 },
7076 flags: []string{
7077 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7078 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007079 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007080 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007081 // Resume the session to assert the peer signature
7082 // algorithm is reported on both handshakes.
7083 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007084 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007085 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007086 })
David Benjamin5208fd42016-07-13 21:43:25 -04007087
David Benjamin3ef76972016-10-17 17:59:54 -04007088 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007089 testCases = append(testCases, testCase{
7090 testType: serverTest,
7091 name: "ClientAuth-InvalidSignature" + suffix,
7092 config: Config{
7093 MaxVersion: ver.version,
7094 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7095 SignSignatureAlgorithms: []signatureAlgorithm{
7096 alg.id,
7097 },
7098 Bugs: ProtocolBugs{
7099 InvalidSignature: true,
7100 },
7101 },
7102 flags: []string{
7103 "-require-any-client-certificate",
7104 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007105 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007106 },
7107 shouldFail: true,
7108 expectedError: ":BAD_SIGNATURE:",
7109 })
7110
7111 testCases = append(testCases, testCase{
7112 name: "ServerAuth-InvalidSignature" + suffix,
7113 config: Config{
7114 MaxVersion: ver.version,
7115 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7116 CipherSuites: signingCiphers,
7117 SignSignatureAlgorithms: []signatureAlgorithm{
7118 alg.id,
7119 },
7120 Bugs: ProtocolBugs{
7121 InvalidSignature: true,
7122 },
7123 },
David Benjamin69522112017-03-28 15:38:29 -05007124 flags: []string{
7125 "-enable-all-curves",
7126 "-enable-ed25519",
7127 },
David Benjamin5208fd42016-07-13 21:43:25 -04007128 shouldFail: true,
7129 expectedError: ":BAD_SIGNATURE:",
7130 })
7131 }
David Benjaminca3d5452016-07-14 12:51:01 -04007132
David Benjamin3ef76972016-10-17 17:59:54 -04007133 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007134 testCases = append(testCases, testCase{
7135 name: "ClientAuth-Sign-Negotiate" + suffix,
7136 config: Config{
7137 MaxVersion: ver.version,
7138 ClientAuth: RequireAnyClientCert,
7139 VerifySignatureAlgorithms: allAlgorithms,
7140 },
7141 flags: []string{
7142 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7143 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7144 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007145 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007146 "-signing-prefs", strconv.Itoa(int(alg.id)),
7147 },
7148 expectedPeerSignatureAlgorithm: alg.id,
7149 })
7150
7151 testCases = append(testCases, testCase{
7152 testType: serverTest,
7153 name: "ServerAuth-Sign-Negotiate" + suffix,
7154 config: Config{
7155 MaxVersion: ver.version,
7156 CipherSuites: signingCiphers,
7157 VerifySignatureAlgorithms: allAlgorithms,
7158 },
7159 flags: []string{
7160 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7161 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7162 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007163 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007164 "-signing-prefs", strconv.Itoa(int(alg.id)),
7165 },
7166 expectedPeerSignatureAlgorithm: alg.id,
7167 })
7168 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007169 }
David Benjamin000800a2014-11-14 01:43:59 -05007170 }
7171
Nick Harper60edffd2016-06-21 15:19:24 -07007172 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007173 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007174 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007175 config: Config{
7176 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007177 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007178 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007179 signatureECDSAWithP521AndSHA512,
7180 signatureRSAPKCS1WithSHA384,
7181 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007182 },
7183 },
7184 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007185 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7186 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007187 },
Nick Harper60edffd2016-06-21 15:19:24 -07007188 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007189 })
7190
7191 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007192 name: "ClientAuth-SignatureType-TLS13",
7193 config: Config{
7194 ClientAuth: RequireAnyClientCert,
7195 MaxVersion: VersionTLS13,
7196 VerifySignatureAlgorithms: []signatureAlgorithm{
7197 signatureECDSAWithP521AndSHA512,
7198 signatureRSAPKCS1WithSHA384,
7199 signatureRSAPSSWithSHA384,
7200 signatureECDSAWithSHA1,
7201 },
7202 },
7203 flags: []string{
7204 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7205 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7206 },
7207 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7208 })
7209
7210 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007211 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007212 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007214 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007215 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007216 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007217 signatureECDSAWithP521AndSHA512,
7218 signatureRSAPKCS1WithSHA384,
7219 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007220 },
7221 },
Nick Harper60edffd2016-06-21 15:19:24 -07007222 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007223 })
7224
Steven Valdez143e8b32016-07-11 13:19:03 -04007225 testCases = append(testCases, testCase{
7226 testType: serverTest,
7227 name: "ServerAuth-SignatureType-TLS13",
7228 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007229 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007230 VerifySignatureAlgorithms: []signatureAlgorithm{
7231 signatureECDSAWithP521AndSHA512,
7232 signatureRSAPKCS1WithSHA384,
7233 signatureRSAPSSWithSHA384,
7234 signatureECDSAWithSHA1,
7235 },
7236 },
7237 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7238 })
7239
David Benjamina95e9f32016-07-08 16:28:04 -07007240 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007241 testCases = append(testCases, testCase{
7242 testType: serverTest,
7243 name: "Verify-ClientAuth-SignatureType",
7244 config: Config{
7245 MaxVersion: VersionTLS12,
7246 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007247 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007248 signatureRSAPKCS1WithSHA256,
7249 },
7250 Bugs: ProtocolBugs{
7251 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7252 },
7253 },
7254 flags: []string{
7255 "-require-any-client-certificate",
7256 },
7257 shouldFail: true,
7258 expectedError: ":WRONG_SIGNATURE_TYPE:",
7259 })
7260
7261 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007262 testType: serverTest,
7263 name: "Verify-ClientAuth-SignatureType-TLS13",
7264 config: Config{
7265 MaxVersion: VersionTLS13,
7266 Certificates: []Certificate{rsaCertificate},
7267 SignSignatureAlgorithms: []signatureAlgorithm{
7268 signatureRSAPSSWithSHA256,
7269 },
7270 Bugs: ProtocolBugs{
7271 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7272 },
7273 },
7274 flags: []string{
7275 "-require-any-client-certificate",
7276 },
7277 shouldFail: true,
7278 expectedError: ":WRONG_SIGNATURE_TYPE:",
7279 })
7280
7281 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007282 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007283 config: Config{
7284 MaxVersion: VersionTLS12,
7285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007286 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007287 signatureRSAPKCS1WithSHA256,
7288 },
7289 Bugs: ProtocolBugs{
7290 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7291 },
7292 },
7293 shouldFail: true,
7294 expectedError: ":WRONG_SIGNATURE_TYPE:",
7295 })
7296
Steven Valdez143e8b32016-07-11 13:19:03 -04007297 testCases = append(testCases, testCase{
7298 name: "Verify-ServerAuth-SignatureType-TLS13",
7299 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007300 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007301 SignSignatureAlgorithms: []signatureAlgorithm{
7302 signatureRSAPSSWithSHA256,
7303 },
7304 Bugs: ProtocolBugs{
7305 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7306 },
7307 },
7308 shouldFail: true,
7309 expectedError: ":WRONG_SIGNATURE_TYPE:",
7310 })
7311
David Benjamin51dd7d62016-07-08 16:07:01 -07007312 // Test that, if the list is missing, the peer falls back to SHA-1 in
7313 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007314 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007315 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007317 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007318 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007319 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007320 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007321 },
7322 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007323 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007324 },
7325 },
7326 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007327 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7328 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007329 },
7330 })
7331
7332 testCases = append(testCases, testCase{
7333 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007334 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007335 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007336 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007337 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007338 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007339 },
7340 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007341 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007342 },
7343 },
David Benjaminee32bea2016-08-17 13:36:44 -04007344 flags: []string{
7345 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7346 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7347 },
7348 })
7349
7350 testCases = append(testCases, testCase{
7351 name: "ClientAuth-SHA1-Fallback-ECDSA",
7352 config: Config{
7353 MaxVersion: VersionTLS12,
7354 ClientAuth: RequireAnyClientCert,
7355 VerifySignatureAlgorithms: []signatureAlgorithm{
7356 signatureECDSAWithSHA1,
7357 },
7358 Bugs: ProtocolBugs{
7359 NoSignatureAlgorithms: true,
7360 },
7361 },
7362 flags: []string{
7363 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7364 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7365 },
7366 })
7367
7368 testCases = append(testCases, testCase{
7369 testType: serverTest,
7370 name: "ServerAuth-SHA1-Fallback-ECDSA",
7371 config: Config{
7372 MaxVersion: VersionTLS12,
7373 VerifySignatureAlgorithms: []signatureAlgorithm{
7374 signatureECDSAWithSHA1,
7375 },
7376 Bugs: ProtocolBugs{
7377 NoSignatureAlgorithms: true,
7378 },
7379 },
7380 flags: []string{
7381 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7382 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7383 },
David Benjamin000800a2014-11-14 01:43:59 -05007384 })
David Benjamin72dc7832015-03-16 17:49:43 -04007385
David Benjamin51dd7d62016-07-08 16:07:01 -07007386 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007387 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007388 config: Config{
7389 MaxVersion: VersionTLS13,
7390 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007391 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007392 signatureRSAPKCS1WithSHA1,
7393 },
7394 Bugs: ProtocolBugs{
7395 NoSignatureAlgorithms: true,
7396 },
7397 },
7398 flags: []string{
7399 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7400 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7401 },
David Benjamin48901652016-08-01 12:12:47 -04007402 shouldFail: true,
7403 // An empty CertificateRequest signature algorithm list is a
7404 // syntax error in TLS 1.3.
7405 expectedError: ":DECODE_ERROR:",
7406 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007407 })
7408
7409 testCases = append(testCases, testCase{
7410 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007411 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007412 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007413 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007414 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007415 signatureRSAPKCS1WithSHA1,
7416 },
7417 Bugs: ProtocolBugs{
7418 NoSignatureAlgorithms: true,
7419 },
7420 },
7421 shouldFail: true,
7422 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7423 })
7424
David Benjaminb62d2872016-07-18 14:55:02 +02007425 // Test that hash preferences are enforced. BoringSSL does not implement
7426 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007427 testCases = append(testCases, testCase{
7428 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007429 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007431 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007432 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007433 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007434 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007435 },
7436 Bugs: ProtocolBugs{
7437 IgnorePeerSignatureAlgorithmPreferences: true,
7438 },
7439 },
7440 flags: []string{"-require-any-client-certificate"},
7441 shouldFail: true,
7442 expectedError: ":WRONG_SIGNATURE_TYPE:",
7443 })
7444
7445 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007446 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007448 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007449 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007450 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007451 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007452 },
7453 Bugs: ProtocolBugs{
7454 IgnorePeerSignatureAlgorithmPreferences: true,
7455 },
7456 },
7457 shouldFail: true,
7458 expectedError: ":WRONG_SIGNATURE_TYPE:",
7459 })
David Benjaminb62d2872016-07-18 14:55:02 +02007460 testCases = append(testCases, testCase{
7461 testType: serverTest,
7462 name: "ClientAuth-Enforced-TLS13",
7463 config: Config{
7464 MaxVersion: VersionTLS13,
7465 Certificates: []Certificate{rsaCertificate},
7466 SignSignatureAlgorithms: []signatureAlgorithm{
7467 signatureRSAPKCS1WithMD5,
7468 },
7469 Bugs: ProtocolBugs{
7470 IgnorePeerSignatureAlgorithmPreferences: true,
7471 IgnoreSignatureVersionChecks: true,
7472 },
7473 },
7474 flags: []string{"-require-any-client-certificate"},
7475 shouldFail: true,
7476 expectedError: ":WRONG_SIGNATURE_TYPE:",
7477 })
7478
7479 testCases = append(testCases, testCase{
7480 name: "ServerAuth-Enforced-TLS13",
7481 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007482 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007483 SignSignatureAlgorithms: []signatureAlgorithm{
7484 signatureRSAPKCS1WithMD5,
7485 },
7486 Bugs: ProtocolBugs{
7487 IgnorePeerSignatureAlgorithmPreferences: true,
7488 IgnoreSignatureVersionChecks: true,
7489 },
7490 },
7491 shouldFail: true,
7492 expectedError: ":WRONG_SIGNATURE_TYPE:",
7493 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007494
7495 // Test that the agreed upon digest respects the client preferences and
7496 // the server digests.
7497 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007498 name: "NoCommonAlgorithms-Digests",
7499 config: Config{
7500 MaxVersion: VersionTLS12,
7501 ClientAuth: RequireAnyClientCert,
7502 VerifySignatureAlgorithms: []signatureAlgorithm{
7503 signatureRSAPKCS1WithSHA512,
7504 signatureRSAPKCS1WithSHA1,
7505 },
7506 },
7507 flags: []string{
7508 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7509 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7510 "-digest-prefs", "SHA256",
7511 },
7512 shouldFail: true,
7513 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7514 })
7515 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007516 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007518 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007519 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007520 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007521 signatureRSAPKCS1WithSHA512,
7522 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007523 },
7524 },
7525 flags: []string{
7526 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7527 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007528 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007529 },
David Benjaminca3d5452016-07-14 12:51:01 -04007530 shouldFail: true,
7531 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7532 })
7533 testCases = append(testCases, testCase{
7534 name: "NoCommonAlgorithms-TLS13",
7535 config: Config{
7536 MaxVersion: VersionTLS13,
7537 ClientAuth: RequireAnyClientCert,
7538 VerifySignatureAlgorithms: []signatureAlgorithm{
7539 signatureRSAPSSWithSHA512,
7540 signatureRSAPSSWithSHA384,
7541 },
7542 },
7543 flags: []string{
7544 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7545 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7546 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7547 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007548 shouldFail: true,
7549 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007550 })
7551 testCases = append(testCases, testCase{
7552 name: "Agree-Digest-SHA256",
7553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007554 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007555 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007556 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007557 signatureRSAPKCS1WithSHA1,
7558 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007559 },
7560 },
7561 flags: []string{
7562 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7563 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007564 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007565 },
Nick Harper60edffd2016-06-21 15:19:24 -07007566 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007567 })
7568 testCases = append(testCases, testCase{
7569 name: "Agree-Digest-SHA1",
7570 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007571 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007572 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007573 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007574 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007575 },
7576 },
7577 flags: []string{
7578 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7579 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007580 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007581 },
Nick Harper60edffd2016-06-21 15:19:24 -07007582 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007583 })
7584 testCases = append(testCases, testCase{
7585 name: "Agree-Digest-Default",
7586 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007587 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007588 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007589 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007590 signatureRSAPKCS1WithSHA256,
7591 signatureECDSAWithP256AndSHA256,
7592 signatureRSAPKCS1WithSHA1,
7593 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007594 },
7595 },
7596 flags: []string{
7597 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7598 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7599 },
Nick Harper60edffd2016-06-21 15:19:24 -07007600 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007601 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007602
David Benjaminca3d5452016-07-14 12:51:01 -04007603 // Test that the signing preference list may include extra algorithms
7604 // without negotiation problems.
7605 testCases = append(testCases, testCase{
7606 testType: serverTest,
7607 name: "FilterExtraAlgorithms",
7608 config: Config{
7609 MaxVersion: VersionTLS12,
7610 VerifySignatureAlgorithms: []signatureAlgorithm{
7611 signatureRSAPKCS1WithSHA256,
7612 },
7613 },
7614 flags: []string{
7615 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7616 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7617 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7618 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7619 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7620 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7621 },
7622 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7623 })
7624
David Benjamin4c3ddf72016-06-29 18:13:53 -04007625 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7626 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007627 testCases = append(testCases, testCase{
7628 name: "CheckLeafCurve",
7629 config: Config{
7630 MaxVersion: VersionTLS12,
7631 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007632 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007633 },
7634 flags: []string{"-p384-only"},
7635 shouldFail: true,
7636 expectedError: ":BAD_ECC_CERT:",
7637 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007638
7639 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7640 testCases = append(testCases, testCase{
7641 name: "CheckLeafCurve-TLS13",
7642 config: Config{
7643 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007644 Certificates: []Certificate{ecdsaP256Certificate},
7645 },
7646 flags: []string{"-p384-only"},
7647 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007648
7649 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7650 testCases = append(testCases, testCase{
7651 name: "ECDSACurveMismatch-Verify-TLS12",
7652 config: Config{
7653 MaxVersion: VersionTLS12,
7654 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7655 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007656 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007657 signatureECDSAWithP384AndSHA384,
7658 },
7659 },
7660 })
7661
7662 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7663 testCases = append(testCases, testCase{
7664 name: "ECDSACurveMismatch-Verify-TLS13",
7665 config: Config{
7666 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007667 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007668 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007669 signatureECDSAWithP384AndSHA384,
7670 },
7671 Bugs: ProtocolBugs{
7672 SkipECDSACurveCheck: true,
7673 },
7674 },
7675 shouldFail: true,
7676 expectedError: ":WRONG_SIGNATURE_TYPE:",
7677 })
7678
7679 // Signature algorithm selection in TLS 1.3 should take the curve into
7680 // account.
7681 testCases = append(testCases, testCase{
7682 testType: serverTest,
7683 name: "ECDSACurveMismatch-Sign-TLS13",
7684 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007685 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007686 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007687 signatureECDSAWithP384AndSHA384,
7688 signatureECDSAWithP256AndSHA256,
7689 },
7690 },
7691 flags: []string{
7692 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7693 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7694 },
7695 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7696 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007697
7698 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7699 // server does not attempt to sign in that case.
7700 testCases = append(testCases, testCase{
7701 testType: serverTest,
7702 name: "RSA-PSS-Large",
7703 config: Config{
7704 MaxVersion: VersionTLS13,
7705 VerifySignatureAlgorithms: []signatureAlgorithm{
7706 signatureRSAPSSWithSHA512,
7707 },
7708 },
7709 flags: []string{
7710 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7711 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7712 },
7713 shouldFail: true,
7714 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7715 })
David Benjamin57e929f2016-08-30 00:30:38 -04007716
7717 // Test that RSA-PSS is enabled by default for TLS 1.2.
7718 testCases = append(testCases, testCase{
7719 testType: clientTest,
7720 name: "RSA-PSS-Default-Verify",
7721 config: Config{
7722 MaxVersion: VersionTLS12,
7723 SignSignatureAlgorithms: []signatureAlgorithm{
7724 signatureRSAPSSWithSHA256,
7725 },
7726 },
7727 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7728 })
7729
7730 testCases = append(testCases, testCase{
7731 testType: serverTest,
7732 name: "RSA-PSS-Default-Sign",
7733 config: Config{
7734 MaxVersion: VersionTLS12,
7735 VerifySignatureAlgorithms: []signatureAlgorithm{
7736 signatureRSAPSSWithSHA256,
7737 },
7738 },
7739 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7740 })
David Benjamin69522112017-03-28 15:38:29 -05007741
7742 // TLS 1.1 and below has no way to advertise support for or negotiate
7743 // Ed25519's signature algorithm.
7744 testCases = append(testCases, testCase{
7745 testType: clientTest,
7746 name: "NoEd25519-TLS11-ServerAuth-Verify",
7747 config: Config{
7748 MaxVersion: VersionTLS11,
7749 Certificates: []Certificate{ed25519Certificate},
7750 Bugs: ProtocolBugs{
7751 // Sign with Ed25519 even though it is TLS 1.1.
7752 UseLegacySigningAlgorithm: signatureEd25519,
7753 },
7754 },
7755 flags: []string{"-enable-ed25519"},
7756 shouldFail: true,
7757 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7758 })
7759 testCases = append(testCases, testCase{
7760 testType: serverTest,
7761 name: "NoEd25519-TLS11-ServerAuth-Sign",
7762 config: Config{
7763 MaxVersion: VersionTLS11,
7764 },
7765 flags: []string{
7766 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7767 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7768 },
7769 shouldFail: true,
7770 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7771 })
7772 testCases = append(testCases, testCase{
7773 testType: serverTest,
7774 name: "NoEd25519-TLS11-ClientAuth-Verify",
7775 config: Config{
7776 MaxVersion: VersionTLS11,
7777 Certificates: []Certificate{ed25519Certificate},
7778 Bugs: ProtocolBugs{
7779 // Sign with Ed25519 even though it is TLS 1.1.
7780 UseLegacySigningAlgorithm: signatureEd25519,
7781 },
7782 },
7783 flags: []string{
7784 "-enable-ed25519",
7785 "-require-any-client-certificate",
7786 },
7787 shouldFail: true,
7788 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7789 })
7790 testCases = append(testCases, testCase{
7791 testType: clientTest,
7792 name: "NoEd25519-TLS11-ClientAuth-Sign",
7793 config: Config{
7794 MaxVersion: VersionTLS11,
7795 ClientAuth: RequireAnyClientCert,
7796 },
7797 flags: []string{
7798 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7799 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7800 },
7801 shouldFail: true,
7802 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7803 })
7804
7805 // Test Ed25519 is not advertised by default.
7806 testCases = append(testCases, testCase{
7807 testType: clientTest,
7808 name: "Ed25519DefaultDisable-NoAdvertise",
7809 config: Config{
7810 Certificates: []Certificate{ed25519Certificate},
7811 },
7812 shouldFail: true,
7813 expectedLocalError: "tls: no common signature algorithms",
7814 })
7815
7816 // Test Ed25519, when disabled, is not accepted if the peer ignores our
7817 // preferences.
7818 testCases = append(testCases, testCase{
7819 testType: clientTest,
7820 name: "Ed25519DefaultDisable-NoAccept",
7821 config: Config{
7822 Certificates: []Certificate{ed25519Certificate},
7823 Bugs: ProtocolBugs{
7824 IgnorePeerSignatureAlgorithmPreferences: true,
7825 },
7826 },
7827 shouldFail: true,
7828 expectedLocalError: "remote error: illegal parameter",
7829 expectedError: ":WRONG_SIGNATURE_TYPE:",
7830 })
David Benjamin71c21b42017-04-14 17:05:40 -04007831
7832 // Test that configuring verify preferences changes what the client
7833 // advertises.
7834 testCases = append(testCases, testCase{
7835 name: "VerifyPreferences-Advertised",
7836 config: Config{
7837 Certificates: []Certificate{rsaCertificate},
7838 SignSignatureAlgorithms: []signatureAlgorithm{
7839 signatureRSAPSSWithSHA256,
7840 signatureRSAPSSWithSHA384,
7841 signatureRSAPSSWithSHA512,
7842 },
7843 },
7844 flags: []string{
7845 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7846 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7847 },
7848 })
7849
7850 // Test that the client advertises a set which the runner can find
7851 // nothing in common with.
7852 testCases = append(testCases, testCase{
7853 name: "VerifyPreferences-NoCommonAlgorithms",
7854 config: Config{
7855 Certificates: []Certificate{rsaCertificate},
7856 SignSignatureAlgorithms: []signatureAlgorithm{
7857 signatureRSAPSSWithSHA256,
7858 signatureRSAPSSWithSHA512,
7859 },
7860 },
7861 flags: []string{
7862 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7863 },
7864 shouldFail: true,
7865 expectedLocalError: "tls: no common signature algorithms",
7866 })
7867
7868 // Test that the client enforces its preferences when configured.
7869 testCases = append(testCases, testCase{
7870 name: "VerifyPreferences-Enforced",
7871 config: Config{
7872 Certificates: []Certificate{rsaCertificate},
7873 SignSignatureAlgorithms: []signatureAlgorithm{
7874 signatureRSAPSSWithSHA256,
7875 signatureRSAPSSWithSHA512,
7876 },
7877 Bugs: ProtocolBugs{
7878 IgnorePeerSignatureAlgorithmPreferences: true,
7879 },
7880 },
7881 flags: []string{
7882 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
7883 },
7884 shouldFail: true,
7885 expectedLocalError: "remote error: illegal parameter",
7886 expectedError: ":WRONG_SIGNATURE_TYPE:",
7887 })
7888
7889 // Test that explicitly configuring Ed25519 is as good as changing the
7890 // boolean toggle.
7891 testCases = append(testCases, testCase{
7892 name: "VerifyPreferences-Ed25519",
7893 config: Config{
7894 Certificates: []Certificate{ed25519Certificate},
7895 },
7896 flags: []string{
7897 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
7898 },
7899 })
David Benjamin000800a2014-11-14 01:43:59 -05007900}
7901
David Benjamin83f90402015-01-27 01:09:43 -05007902// timeouts is the retransmit schedule for BoringSSL. It doubles and
7903// caps at 60 seconds. On the 13th timeout, it gives up.
7904var timeouts = []time.Duration{
7905 1 * time.Second,
7906 2 * time.Second,
7907 4 * time.Second,
7908 8 * time.Second,
7909 16 * time.Second,
7910 32 * time.Second,
7911 60 * time.Second,
7912 60 * time.Second,
7913 60 * time.Second,
7914 60 * time.Second,
7915 60 * time.Second,
7916 60 * time.Second,
7917 60 * time.Second,
7918}
7919
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007920// shortTimeouts is an alternate set of timeouts which would occur if the
7921// initial timeout duration was set to 250ms.
7922var shortTimeouts = []time.Duration{
7923 250 * time.Millisecond,
7924 500 * time.Millisecond,
7925 1 * time.Second,
7926 2 * time.Second,
7927 4 * time.Second,
7928 8 * time.Second,
7929 16 * time.Second,
7930 32 * time.Second,
7931 60 * time.Second,
7932 60 * time.Second,
7933 60 * time.Second,
7934 60 * time.Second,
7935 60 * time.Second,
7936}
7937
David Benjamin83f90402015-01-27 01:09:43 -05007938func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007939 // These tests work by coordinating some behavior on both the shim and
7940 // the runner.
7941 //
7942 // TimeoutSchedule configures the runner to send a series of timeout
7943 // opcodes to the shim (see packetAdaptor) immediately before reading
7944 // each peer handshake flight N. The timeout opcode both simulates a
7945 // timeout in the shim and acts as a synchronization point to help the
7946 // runner bracket each handshake flight.
7947 //
7948 // We assume the shim does not read from the channel eagerly. It must
7949 // first wait until it has sent flight N and is ready to receive
7950 // handshake flight N+1. At this point, it will process the timeout
7951 // opcode. It must then immediately respond with a timeout ACK and act
7952 // as if the shim was idle for the specified amount of time.
7953 //
7954 // The runner then drops all packets received before the ACK and
7955 // continues waiting for flight N. This ordering results in one attempt
7956 // at sending flight N to be dropped. For the test to complete, the
7957 // shim must send flight N again, testing that the shim implements DTLS
7958 // retransmit on a timeout.
7959
Steven Valdez143e8b32016-07-11 13:19:03 -04007960 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007961 // likely be more epochs to cross and the final message's retransmit may
7962 // be more complex.
7963
David Benjamin11c82892017-02-23 20:40:31 -05007964 // Test that this is indeed the timeout schedule. Stress all
7965 // four patterns of handshake.
7966 for i := 1; i < len(timeouts); i++ {
7967 number := strconv.Itoa(i)
7968 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007969 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05007970 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007972 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007973 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007974 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007975 },
7976 },
7977 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007978 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007979 })
David Benjamin11c82892017-02-23 20:40:31 -05007980 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007981 protocol: dtls,
7982 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05007983 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007985 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007986 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007987 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007988 },
7989 },
7990 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007991 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007992 })
7993 }
David Benjamin11c82892017-02-23 20:40:31 -05007994
7995 // Test that exceeding the timeout schedule hits a read
7996 // timeout.
7997 testCases = append(testCases, testCase{
7998 protocol: dtls,
7999 name: "DTLS-Retransmit-Timeout",
8000 config: Config{
8001 MaxVersion: VersionTLS12,
8002 Bugs: ProtocolBugs{
8003 TimeoutSchedule: timeouts,
8004 },
8005 },
8006 resumeSession: true,
8007 flags: []string{"-async"},
8008 shouldFail: true,
8009 expectedError: ":READ_TIMEOUT_EXPIRED:",
8010 })
8011
8012 // Test that timeout handling has a fudge factor, due to API
8013 // problems.
8014 testCases = append(testCases, testCase{
8015 protocol: dtls,
8016 name: "DTLS-Retransmit-Fudge",
8017 config: Config{
8018 MaxVersion: VersionTLS12,
8019 Bugs: ProtocolBugs{
8020 TimeoutSchedule: []time.Duration{
8021 timeouts[0] - 10*time.Millisecond,
8022 },
8023 },
8024 },
8025 resumeSession: true,
8026 flags: []string{"-async"},
8027 })
8028
8029 // Test that the final Finished retransmitting isn't
8030 // duplicated if the peer badly fragments everything.
8031 testCases = append(testCases, testCase{
8032 testType: serverTest,
8033 protocol: dtls,
8034 name: "DTLS-Retransmit-Fragmented",
8035 config: Config{
8036 MaxVersion: VersionTLS12,
8037 Bugs: ProtocolBugs{
8038 TimeoutSchedule: []time.Duration{timeouts[0]},
8039 MaxHandshakeRecordLength: 2,
8040 },
8041 },
8042 flags: []string{"-async"},
8043 })
8044
8045 // Test the timeout schedule when a shorter initial timeout duration is set.
8046 testCases = append(testCases, testCase{
8047 protocol: dtls,
8048 name: "DTLS-Retransmit-Short-Client",
8049 config: Config{
8050 MaxVersion: VersionTLS12,
8051 Bugs: ProtocolBugs{
8052 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8053 },
8054 },
8055 resumeSession: true,
8056 flags: []string{
8057 "-async",
8058 "-initial-timeout-duration-ms", "250",
8059 },
8060 })
8061 testCases = append(testCases, testCase{
8062 protocol: dtls,
8063 testType: serverTest,
8064 name: "DTLS-Retransmit-Short-Server",
8065 config: Config{
8066 MaxVersion: VersionTLS12,
8067 Bugs: ProtocolBugs{
8068 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8069 },
8070 },
8071 resumeSession: true,
8072 flags: []string{
8073 "-async",
8074 "-initial-timeout-duration-ms", "250",
8075 },
8076 })
David Benjamin83f90402015-01-27 01:09:43 -05008077}
8078
David Benjaminc565ebb2015-04-03 04:06:36 -04008079func addExportKeyingMaterialTests() {
8080 for _, vers := range tlsVersions {
8081 if vers.version == VersionSSL30 {
8082 continue
8083 }
8084 testCases = append(testCases, testCase{
8085 name: "ExportKeyingMaterial-" + vers.name,
8086 config: Config{
8087 MaxVersion: vers.version,
8088 },
8089 exportKeyingMaterial: 1024,
8090 exportLabel: "label",
8091 exportContext: "context",
8092 useExportContext: true,
8093 })
8094 testCases = append(testCases, testCase{
8095 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8096 config: Config{
8097 MaxVersion: vers.version,
8098 },
8099 exportKeyingMaterial: 1024,
8100 })
8101 testCases = append(testCases, testCase{
8102 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8103 config: Config{
8104 MaxVersion: vers.version,
8105 },
8106 exportKeyingMaterial: 1024,
8107 useExportContext: true,
8108 })
8109 testCases = append(testCases, testCase{
8110 name: "ExportKeyingMaterial-Small-" + vers.name,
8111 config: Config{
8112 MaxVersion: vers.version,
8113 },
8114 exportKeyingMaterial: 1,
8115 exportLabel: "label",
8116 exportContext: "context",
8117 useExportContext: true,
8118 })
8119 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008120
David Benjaminc565ebb2015-04-03 04:06:36 -04008121 testCases = append(testCases, testCase{
8122 name: "ExportKeyingMaterial-SSL3",
8123 config: Config{
8124 MaxVersion: VersionSSL30,
8125 },
8126 exportKeyingMaterial: 1024,
8127 exportLabel: "label",
8128 exportContext: "context",
8129 useExportContext: true,
8130 shouldFail: true,
8131 expectedError: "failed to export keying material",
8132 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008133
8134 // Exporters work during a False Start.
8135 testCases = append(testCases, testCase{
8136 name: "ExportKeyingMaterial-FalseStart",
8137 config: Config{
8138 MaxVersion: VersionTLS12,
8139 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8140 NextProtos: []string{"foo"},
8141 Bugs: ProtocolBugs{
8142 ExpectFalseStart: true,
8143 },
8144 },
8145 flags: []string{
8146 "-false-start",
8147 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008148 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008149 },
8150 shimWritesFirst: true,
8151 exportKeyingMaterial: 1024,
8152 exportLabel: "label",
8153 exportContext: "context",
8154 useExportContext: true,
8155 })
8156
8157 // Exporters do not work in the middle of a renegotiation. Test this by
8158 // triggering the exporter after every SSL_read call and configuring the
8159 // shim to run asynchronously.
8160 testCases = append(testCases, testCase{
8161 name: "ExportKeyingMaterial-Renegotiate",
8162 config: Config{
8163 MaxVersion: VersionTLS12,
8164 },
8165 renegotiate: 1,
8166 flags: []string{
8167 "-async",
8168 "-use-exporter-between-reads",
8169 "-renegotiate-freely",
8170 "-expect-total-renegotiations", "1",
8171 },
8172 shouldFail: true,
8173 expectedError: "failed to export keying material",
8174 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008175}
8176
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008177func addTLSUniqueTests() {
8178 for _, isClient := range []bool{false, true} {
8179 for _, isResumption := range []bool{false, true} {
8180 for _, hasEMS := range []bool{false, true} {
8181 var suffix string
8182 if isResumption {
8183 suffix = "Resume-"
8184 } else {
8185 suffix = "Full-"
8186 }
8187
8188 if hasEMS {
8189 suffix += "EMS-"
8190 } else {
8191 suffix += "NoEMS-"
8192 }
8193
8194 if isClient {
8195 suffix += "Client"
8196 } else {
8197 suffix += "Server"
8198 }
8199
8200 test := testCase{
8201 name: "TLSUnique-" + suffix,
8202 testTLSUnique: true,
8203 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008204 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008205 Bugs: ProtocolBugs{
8206 NoExtendedMasterSecret: !hasEMS,
8207 },
8208 },
8209 }
8210
8211 if isResumption {
8212 test.resumeSession = true
8213 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008214 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008215 Bugs: ProtocolBugs{
8216 NoExtendedMasterSecret: !hasEMS,
8217 },
8218 }
8219 }
8220
8221 if isResumption && !hasEMS {
8222 test.shouldFail = true
8223 test.expectedError = "failed to get tls-unique"
8224 }
8225
8226 testCases = append(testCases, test)
8227 }
8228 }
8229 }
8230}
8231
Adam Langley09505632015-07-30 18:10:13 -07008232func addCustomExtensionTests() {
8233 expectedContents := "custom extension"
8234 emptyString := ""
8235
8236 for _, isClient := range []bool{false, true} {
8237 suffix := "Server"
8238 flag := "-enable-server-custom-extension"
8239 testType := serverTest
8240 if isClient {
8241 suffix = "Client"
8242 flag = "-enable-client-custom-extension"
8243 testType = clientTest
8244 }
8245
8246 testCases = append(testCases, testCase{
8247 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008248 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008249 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008250 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008251 Bugs: ProtocolBugs{
8252 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008253 ExpectedCustomExtension: &expectedContents,
8254 },
8255 },
8256 flags: []string{flag},
8257 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008258 testCases = append(testCases, testCase{
8259 testType: testType,
8260 name: "CustomExtensions-" + suffix + "-TLS13",
8261 config: Config{
8262 MaxVersion: VersionTLS13,
8263 Bugs: ProtocolBugs{
8264 CustomExtension: expectedContents,
8265 ExpectedCustomExtension: &expectedContents,
8266 },
8267 },
8268 flags: []string{flag},
8269 })
Adam Langley09505632015-07-30 18:10:13 -07008270
Steven Valdez2a070722017-03-25 20:54:16 -05008271 // 0-RTT is not currently supported with Custom Extensions.
8272 testCases = append(testCases, testCase{
8273 testType: testType,
8274 name: "CustomExtensions-" + suffix + "-EarlyData",
8275 config: Config{
8276 MaxVersion: VersionTLS13,
8277 Bugs: ProtocolBugs{
8278 CustomExtension: expectedContents,
8279 ExpectedCustomExtension: &expectedContents,
8280 },
8281 },
8282 shouldFail: true,
8283 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8284 flags: []string{flag, "-enable-early-data"},
8285 })
8286
Adam Langley09505632015-07-30 18:10:13 -07008287 // If the parse callback fails, the handshake should also fail.
8288 testCases = append(testCases, testCase{
8289 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008290 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008292 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008293 Bugs: ProtocolBugs{
8294 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008295 ExpectedCustomExtension: &expectedContents,
8296 },
8297 },
David Benjamin399e7c92015-07-30 23:01:27 -04008298 flags: []string{flag},
8299 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008300 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8301 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008302 testCases = append(testCases, testCase{
8303 testType: testType,
8304 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8305 config: Config{
8306 MaxVersion: VersionTLS13,
8307 Bugs: ProtocolBugs{
8308 CustomExtension: expectedContents + "foo",
8309 ExpectedCustomExtension: &expectedContents,
8310 },
8311 },
8312 flags: []string{flag},
8313 shouldFail: true,
8314 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8315 })
Adam Langley09505632015-07-30 18:10:13 -07008316
8317 // If the add callback fails, the handshake should also fail.
8318 testCases = append(testCases, testCase{
8319 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008320 name: "CustomExtensions-FailAdd-" + 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 },
David Benjamin399e7c92015-07-30 23:01:27 -04008328 flags: []string{flag, "-custom-extension-fail-add"},
8329 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008330 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8331 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008332 testCases = append(testCases, testCase{
8333 testType: testType,
8334 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8335 config: Config{
8336 MaxVersion: VersionTLS13,
8337 Bugs: ProtocolBugs{
8338 CustomExtension: expectedContents,
8339 ExpectedCustomExtension: &expectedContents,
8340 },
8341 },
8342 flags: []string{flag, "-custom-extension-fail-add"},
8343 shouldFail: true,
8344 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8345 })
Adam Langley09505632015-07-30 18:10:13 -07008346
8347 // If the add callback returns zero, no extension should be
8348 // added.
8349 skipCustomExtension := expectedContents
8350 if isClient {
8351 // For the case where the client skips sending the
8352 // custom extension, the server must not “echo” it.
8353 skipCustomExtension = ""
8354 }
8355 testCases = append(testCases, testCase{
8356 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008357 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008359 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008360 Bugs: ProtocolBugs{
8361 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008362 ExpectedCustomExtension: &emptyString,
8363 },
8364 },
8365 flags: []string{flag, "-custom-extension-skip"},
8366 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008367 testCases = append(testCases, testCase{
8368 testType: testType,
8369 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8370 config: Config{
8371 MaxVersion: VersionTLS13,
8372 Bugs: ProtocolBugs{
8373 CustomExtension: skipCustomExtension,
8374 ExpectedCustomExtension: &emptyString,
8375 },
8376 },
8377 flags: []string{flag, "-custom-extension-skip"},
8378 })
Adam Langley09505632015-07-30 18:10:13 -07008379 }
8380
8381 // The custom extension add callback should not be called if the client
8382 // doesn't send the extension.
8383 testCases = append(testCases, testCase{
8384 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008385 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008387 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008388 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008389 ExpectedCustomExtension: &emptyString,
8390 },
8391 },
8392 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8393 })
Adam Langley2deb9842015-08-07 11:15:37 -07008394
Steven Valdez143e8b32016-07-11 13:19:03 -04008395 testCases = append(testCases, testCase{
8396 testType: serverTest,
8397 name: "CustomExtensions-NotCalled-Server-TLS13",
8398 config: Config{
8399 MaxVersion: VersionTLS13,
8400 Bugs: ProtocolBugs{
8401 ExpectedCustomExtension: &emptyString,
8402 },
8403 },
8404 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8405 })
8406
Adam Langley2deb9842015-08-07 11:15:37 -07008407 // Test an unknown extension from the server.
8408 testCases = append(testCases, testCase{
8409 testType: clientTest,
8410 name: "UnknownExtension-Client",
8411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008412 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008413 Bugs: ProtocolBugs{
8414 CustomExtension: expectedContents,
8415 },
8416 },
David Benjamin0c40a962016-08-01 12:05:50 -04008417 shouldFail: true,
8418 expectedError: ":UNEXPECTED_EXTENSION:",
8419 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008420 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008421 testCases = append(testCases, testCase{
8422 testType: clientTest,
8423 name: "UnknownExtension-Client-TLS13",
8424 config: Config{
8425 MaxVersion: VersionTLS13,
8426 Bugs: ProtocolBugs{
8427 CustomExtension: expectedContents,
8428 },
8429 },
David Benjamin0c40a962016-08-01 12:05:50 -04008430 shouldFail: true,
8431 expectedError: ":UNEXPECTED_EXTENSION:",
8432 expectedLocalError: "remote error: unsupported extension",
8433 })
David Benjamin490469f2016-10-05 22:44:38 -04008434 testCases = append(testCases, testCase{
8435 testType: clientTest,
8436 name: "UnknownUnencryptedExtension-Client-TLS13",
8437 config: Config{
8438 MaxVersion: VersionTLS13,
8439 Bugs: ProtocolBugs{
8440 CustomUnencryptedExtension: expectedContents,
8441 },
8442 },
8443 shouldFail: true,
8444 expectedError: ":UNEXPECTED_EXTENSION:",
8445 // The shim must send an alert, but alerts at this point do not
8446 // get successfully decrypted by the runner.
8447 expectedLocalError: "local error: bad record MAC",
8448 })
8449 testCases = append(testCases, testCase{
8450 testType: clientTest,
8451 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8452 config: Config{
8453 MaxVersion: VersionTLS13,
8454 Bugs: ProtocolBugs{
8455 SendUnencryptedALPN: "foo",
8456 },
8457 },
8458 flags: []string{
8459 "-advertise-alpn", "\x03foo\x03bar",
8460 },
8461 shouldFail: true,
8462 expectedError: ":UNEXPECTED_EXTENSION:",
8463 // The shim must send an alert, but alerts at this point do not
8464 // get successfully decrypted by the runner.
8465 expectedLocalError: "local error: bad record MAC",
8466 })
David Benjamin0c40a962016-08-01 12:05:50 -04008467
8468 // Test a known but unoffered extension from the server.
8469 testCases = append(testCases, testCase{
8470 testType: clientTest,
8471 name: "UnofferedExtension-Client",
8472 config: Config{
8473 MaxVersion: VersionTLS12,
8474 Bugs: ProtocolBugs{
8475 SendALPN: "alpn",
8476 },
8477 },
8478 shouldFail: true,
8479 expectedError: ":UNEXPECTED_EXTENSION:",
8480 expectedLocalError: "remote error: unsupported extension",
8481 })
8482 testCases = append(testCases, testCase{
8483 testType: clientTest,
8484 name: "UnofferedExtension-Client-TLS13",
8485 config: Config{
8486 MaxVersion: VersionTLS13,
8487 Bugs: ProtocolBugs{
8488 SendALPN: "alpn",
8489 },
8490 },
8491 shouldFail: true,
8492 expectedError: ":UNEXPECTED_EXTENSION:",
8493 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008494 })
Adam Langley09505632015-07-30 18:10:13 -07008495}
8496
David Benjaminb36a3952015-12-01 18:53:13 -05008497func addRSAClientKeyExchangeTests() {
8498 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8499 testCases = append(testCases, testCase{
8500 testType: serverTest,
8501 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8502 config: Config{
8503 // Ensure the ClientHello version and final
8504 // version are different, to detect if the
8505 // server uses the wrong one.
8506 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008507 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008508 Bugs: ProtocolBugs{
8509 BadRSAClientKeyExchange: bad,
8510 },
8511 },
8512 shouldFail: true,
8513 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8514 })
8515 }
David Benjamine63d9d72016-09-19 18:27:34 -04008516
8517 // The server must compare whatever was in ClientHello.version for the
8518 // RSA premaster.
8519 testCases = append(testCases, testCase{
8520 testType: serverTest,
8521 name: "SendClientVersion-RSA",
8522 config: Config{
8523 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8524 Bugs: ProtocolBugs{
8525 SendClientVersion: 0x1234,
8526 },
8527 },
8528 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8529 })
David Benjaminb36a3952015-12-01 18:53:13 -05008530}
8531
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008532var testCurves = []struct {
8533 name string
8534 id CurveID
8535}{
Adam Langley764ab982017-03-10 18:01:30 -08008536 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008537 {"P-256", CurveP256},
8538 {"P-384", CurveP384},
8539 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008540 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008541}
8542
Steven Valdez5440fe02016-07-18 12:40:30 -04008543const bogusCurve = 0x1234
8544
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008545func addCurveTests() {
8546 for _, curve := range testCurves {
8547 testCases = append(testCases, testCase{
8548 name: "CurveTest-Client-" + curve.name,
8549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008550 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008551 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8552 CurvePreferences: []CurveID{curve.id},
8553 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008554 flags: []string{
8555 "-enable-all-curves",
8556 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8557 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008558 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008559 })
8560 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008561 name: "CurveTest-Client-" + curve.name + "-TLS13",
8562 config: Config{
8563 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008564 CurvePreferences: []CurveID{curve.id},
8565 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008566 flags: []string{
8567 "-enable-all-curves",
8568 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8569 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008570 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008571 })
8572 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008573 testType: serverTest,
8574 name: "CurveTest-Server-" + curve.name,
8575 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008576 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008577 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8578 CurvePreferences: []CurveID{curve.id},
8579 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008580 flags: []string{
8581 "-enable-all-curves",
8582 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8583 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008584 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008585 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008586 testCases = append(testCases, testCase{
8587 testType: serverTest,
8588 name: "CurveTest-Server-" + curve.name + "-TLS13",
8589 config: Config{
8590 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008591 CurvePreferences: []CurveID{curve.id},
8592 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008593 flags: []string{
8594 "-enable-all-curves",
8595 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8596 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008597 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008598 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008599 }
David Benjamin241ae832016-01-15 03:04:54 -05008600
8601 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008602 testCases = append(testCases, testCase{
8603 testType: serverTest,
8604 name: "UnknownCurve",
8605 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008606 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008607 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8608 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8609 },
8610 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008611
Steven Valdez803c77a2016-09-06 14:13:43 -04008612 // The server must be tolerant to bogus curves.
8613 testCases = append(testCases, testCase{
8614 testType: serverTest,
8615 name: "UnknownCurve-TLS13",
8616 config: Config{
8617 MaxVersion: VersionTLS13,
8618 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8619 },
8620 })
8621
David Benjamin4c3ddf72016-06-29 18:13:53 -04008622 // The server must not consider ECDHE ciphers when there are no
8623 // supported curves.
8624 testCases = append(testCases, testCase{
8625 testType: serverTest,
8626 name: "NoSupportedCurves",
8627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008628 MaxVersion: VersionTLS12,
8629 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8630 Bugs: ProtocolBugs{
8631 NoSupportedCurves: true,
8632 },
8633 },
8634 shouldFail: true,
8635 expectedError: ":NO_SHARED_CIPHER:",
8636 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008637 testCases = append(testCases, testCase{
8638 testType: serverTest,
8639 name: "NoSupportedCurves-TLS13",
8640 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008641 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008642 Bugs: ProtocolBugs{
8643 NoSupportedCurves: true,
8644 },
8645 },
8646 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008647 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008648 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008649
8650 // The server must fall back to another cipher when there are no
8651 // supported curves.
8652 testCases = append(testCases, testCase{
8653 testType: serverTest,
8654 name: "NoCommonCurves",
8655 config: Config{
8656 MaxVersion: VersionTLS12,
8657 CipherSuites: []uint16{
8658 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008659 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008660 },
8661 CurvePreferences: []CurveID{CurveP224},
8662 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008663 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008664 })
8665
8666 // The client must reject bogus curves and disabled curves.
8667 testCases = append(testCases, testCase{
8668 name: "BadECDHECurve",
8669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008670 MaxVersion: VersionTLS12,
8671 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8672 Bugs: ProtocolBugs{
8673 SendCurve: bogusCurve,
8674 },
8675 },
8676 shouldFail: true,
8677 expectedError: ":WRONG_CURVE:",
8678 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008679 testCases = append(testCases, testCase{
8680 name: "BadECDHECurve-TLS13",
8681 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008682 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008683 Bugs: ProtocolBugs{
8684 SendCurve: bogusCurve,
8685 },
8686 },
8687 shouldFail: true,
8688 expectedError: ":WRONG_CURVE:",
8689 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008690
8691 testCases = append(testCases, testCase{
8692 name: "UnsupportedCurve",
8693 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008694 MaxVersion: VersionTLS12,
8695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8696 CurvePreferences: []CurveID{CurveP256},
8697 Bugs: ProtocolBugs{
8698 IgnorePeerCurvePreferences: true,
8699 },
8700 },
8701 flags: []string{"-p384-only"},
8702 shouldFail: true,
8703 expectedError: ":WRONG_CURVE:",
8704 })
8705
David Benjamin4f921572016-07-17 14:20:10 +02008706 testCases = append(testCases, testCase{
8707 // TODO(davidben): Add a TLS 1.3 version where
8708 // HelloRetryRequest requests an unsupported curve.
8709 name: "UnsupportedCurve-ServerHello-TLS13",
8710 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008711 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008712 CurvePreferences: []CurveID{CurveP384},
8713 Bugs: ProtocolBugs{
8714 SendCurve: CurveP256,
8715 },
8716 },
8717 flags: []string{"-p384-only"},
8718 shouldFail: true,
8719 expectedError: ":WRONG_CURVE:",
8720 })
8721
David Benjamin4c3ddf72016-06-29 18:13:53 -04008722 // Test invalid curve points.
8723 testCases = append(testCases, testCase{
8724 name: "InvalidECDHPoint-Client",
8725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008726 MaxVersion: VersionTLS12,
8727 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8728 CurvePreferences: []CurveID{CurveP256},
8729 Bugs: ProtocolBugs{
8730 InvalidECDHPoint: true,
8731 },
8732 },
8733 shouldFail: true,
8734 expectedError: ":INVALID_ENCODING:",
8735 })
8736 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008737 name: "InvalidECDHPoint-Client-TLS13",
8738 config: Config{
8739 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008740 CurvePreferences: []CurveID{CurveP256},
8741 Bugs: ProtocolBugs{
8742 InvalidECDHPoint: true,
8743 },
8744 },
8745 shouldFail: true,
8746 expectedError: ":INVALID_ENCODING:",
8747 })
8748 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008749 testType: serverTest,
8750 name: "InvalidECDHPoint-Server",
8751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008752 MaxVersion: VersionTLS12,
8753 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8754 CurvePreferences: []CurveID{CurveP256},
8755 Bugs: ProtocolBugs{
8756 InvalidECDHPoint: true,
8757 },
8758 },
8759 shouldFail: true,
8760 expectedError: ":INVALID_ENCODING:",
8761 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008762 testCases = append(testCases, testCase{
8763 testType: serverTest,
8764 name: "InvalidECDHPoint-Server-TLS13",
8765 config: Config{
8766 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008767 CurvePreferences: []CurveID{CurveP256},
8768 Bugs: ProtocolBugs{
8769 InvalidECDHPoint: true,
8770 },
8771 },
8772 shouldFail: true,
8773 expectedError: ":INVALID_ENCODING:",
8774 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008775
8776 // The previous curve ID should be reported on TLS 1.2 resumption.
8777 testCases = append(testCases, testCase{
8778 name: "CurveID-Resume-Client",
8779 config: Config{
8780 MaxVersion: VersionTLS12,
8781 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8782 CurvePreferences: []CurveID{CurveX25519},
8783 },
8784 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8785 resumeSession: true,
8786 })
8787 testCases = append(testCases, testCase{
8788 testType: serverTest,
8789 name: "CurveID-Resume-Server",
8790 config: Config{
8791 MaxVersion: VersionTLS12,
8792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8793 CurvePreferences: []CurveID{CurveX25519},
8794 },
8795 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8796 resumeSession: true,
8797 })
8798
8799 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8800 // one should be reported.
8801 testCases = append(testCases, testCase{
8802 name: "CurveID-Resume-Client-TLS13",
8803 config: Config{
8804 MaxVersion: VersionTLS13,
8805 CurvePreferences: []CurveID{CurveX25519},
8806 },
8807 resumeConfig: &Config{
8808 MaxVersion: VersionTLS13,
8809 CurvePreferences: []CurveID{CurveP256},
8810 },
8811 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008812 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8813 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008814 },
8815 resumeSession: true,
8816 })
8817 testCases = append(testCases, testCase{
8818 testType: serverTest,
8819 name: "CurveID-Resume-Server-TLS13",
8820 config: Config{
8821 MaxVersion: VersionTLS13,
8822 CurvePreferences: []CurveID{CurveX25519},
8823 },
8824 resumeConfig: &Config{
8825 MaxVersion: VersionTLS13,
8826 CurvePreferences: []CurveID{CurveP256},
8827 },
8828 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04008829 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8830 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05008831 },
8832 resumeSession: true,
8833 })
David Benjamina81967b2016-12-22 09:16:57 -05008834
8835 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8836 testCases = append(testCases, testCase{
8837 name: "PointFormat-ServerHello-TLS12",
8838 config: Config{
8839 MaxVersion: VersionTLS12,
8840 Bugs: ProtocolBugs{
8841 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8842 },
8843 },
8844 })
8845 testCases = append(testCases, testCase{
8846 name: "PointFormat-EncryptedExtensions-TLS13",
8847 config: Config{
8848 MaxVersion: VersionTLS13,
8849 Bugs: ProtocolBugs{
8850 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8851 },
8852 },
8853 shouldFail: true,
8854 expectedError: ":ERROR_PARSING_EXTENSION:",
8855 })
8856
8857 // Test that we tolerate unknown point formats, as long as
8858 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8859 // check they are still functional.
8860 testCases = append(testCases, testCase{
8861 name: "PointFormat-Client-Tolerance",
8862 config: Config{
8863 MaxVersion: VersionTLS12,
8864 Bugs: ProtocolBugs{
8865 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8866 },
8867 },
8868 })
8869 testCases = append(testCases, testCase{
8870 testType: serverTest,
8871 name: "PointFormat-Server-Tolerance",
8872 config: Config{
8873 MaxVersion: VersionTLS12,
8874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8875 Bugs: ProtocolBugs{
8876 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8877 },
8878 },
8879 })
8880
8881 // Test TLS 1.2 does not require the point format extension to be
8882 // present.
8883 testCases = append(testCases, testCase{
8884 name: "PointFormat-Client-Missing",
8885 config: Config{
8886 MaxVersion: VersionTLS12,
8887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8888 Bugs: ProtocolBugs{
8889 SendSupportedPointFormats: []byte{},
8890 },
8891 },
8892 })
8893 testCases = append(testCases, testCase{
8894 testType: serverTest,
8895 name: "PointFormat-Server-Missing",
8896 config: Config{
8897 MaxVersion: VersionTLS12,
8898 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8899 Bugs: ProtocolBugs{
8900 SendSupportedPointFormats: []byte{},
8901 },
8902 },
8903 })
8904
8905 // If the point format extension is present, uncompressed points must be
8906 // offered. BoringSSL requires this whether or not ECDHE is used.
8907 testCases = append(testCases, testCase{
8908 name: "PointFormat-Client-MissingUncompressed",
8909 config: Config{
8910 MaxVersion: VersionTLS12,
8911 Bugs: ProtocolBugs{
8912 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8913 },
8914 },
8915 shouldFail: true,
8916 expectedError: ":ERROR_PARSING_EXTENSION:",
8917 })
8918 testCases = append(testCases, testCase{
8919 testType: serverTest,
8920 name: "PointFormat-Server-MissingUncompressed",
8921 config: Config{
8922 MaxVersion: VersionTLS12,
8923 Bugs: ProtocolBugs{
8924 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8925 },
8926 },
8927 shouldFail: true,
8928 expectedError: ":ERROR_PARSING_EXTENSION:",
8929 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008930}
8931
David Benjaminc9ae27c2016-06-24 22:56:37 -04008932func addTLS13RecordTests() {
8933 testCases = append(testCases, testCase{
8934 name: "TLS13-RecordPadding",
8935 config: Config{
8936 MaxVersion: VersionTLS13,
8937 MinVersion: VersionTLS13,
8938 Bugs: ProtocolBugs{
8939 RecordPadding: 10,
8940 },
8941 },
8942 })
8943
8944 testCases = append(testCases, testCase{
8945 name: "TLS13-EmptyRecords",
8946 config: Config{
8947 MaxVersion: VersionTLS13,
8948 MinVersion: VersionTLS13,
8949 Bugs: ProtocolBugs{
8950 OmitRecordContents: true,
8951 },
8952 },
8953 shouldFail: true,
8954 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8955 })
8956
8957 testCases = append(testCases, testCase{
8958 name: "TLS13-OnlyPadding",
8959 config: Config{
8960 MaxVersion: VersionTLS13,
8961 MinVersion: VersionTLS13,
8962 Bugs: ProtocolBugs{
8963 OmitRecordContents: true,
8964 RecordPadding: 10,
8965 },
8966 },
8967 shouldFail: true,
8968 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8969 })
8970
8971 testCases = append(testCases, testCase{
8972 name: "TLS13-WrongOuterRecord",
8973 config: Config{
8974 MaxVersion: VersionTLS13,
8975 MinVersion: VersionTLS13,
8976 Bugs: ProtocolBugs{
8977 OuterRecordType: recordTypeHandshake,
8978 },
8979 },
8980 shouldFail: true,
8981 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8982 })
8983}
8984
Steven Valdez5b986082016-09-01 12:29:49 -04008985func addSessionTicketTests() {
8986 testCases = append(testCases, testCase{
8987 // In TLS 1.2 and below, empty NewSessionTicket messages
8988 // mean the server changed its mind on sending a ticket.
8989 name: "SendEmptySessionTicket",
8990 config: Config{
8991 MaxVersion: VersionTLS12,
8992 Bugs: ProtocolBugs{
8993 SendEmptySessionTicket: true,
8994 },
8995 },
8996 flags: []string{"-expect-no-session"},
8997 })
8998
8999 // Test that the server ignores unknown PSK modes.
9000 testCases = append(testCases, testCase{
9001 testType: serverTest,
9002 name: "TLS13-SendUnknownModeSessionTicket-Server",
9003 config: Config{
9004 MaxVersion: VersionTLS13,
9005 Bugs: ProtocolBugs{
9006 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009007 },
9008 },
9009 resumeSession: true,
9010 expectedResumeVersion: VersionTLS13,
9011 })
9012
Steven Valdeza833c352016-11-01 13:39:36 -04009013 // Test that the server does not send session tickets with no matching key exchange mode.
9014 testCases = append(testCases, testCase{
9015 testType: serverTest,
9016 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9017 config: Config{
9018 MaxVersion: VersionTLS13,
9019 Bugs: ProtocolBugs{
9020 SendPSKKeyExchangeModes: []byte{0x1a},
9021 ExpectNoNewSessionTicket: true,
9022 },
9023 },
9024 })
9025
9026 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009027 testCases = append(testCases, testCase{
9028 testType: serverTest,
9029 name: "TLS13-SendBadKEModeSessionTicket-Server",
9030 config: Config{
9031 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009032 },
9033 resumeConfig: &Config{
9034 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009035 Bugs: ProtocolBugs{
9036 SendPSKKeyExchangeModes: []byte{0x1a},
9037 },
9038 },
9039 resumeSession: true,
9040 expectResumeRejected: true,
9041 })
9042
Steven Valdeza833c352016-11-01 13:39:36 -04009043 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009044 testCases = append(testCases, testCase{
9045 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009046 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009047 config: Config{
9048 MaxVersion: VersionTLS13,
9049 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009050 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009051 },
9052 },
Steven Valdeza833c352016-11-01 13:39:36 -04009053 resumeSession: true,
9054 flags: []string{
9055 "-resumption-delay", "10",
9056 },
Steven Valdez5b986082016-09-01 12:29:49 -04009057 })
9058
Steven Valdeza833c352016-11-01 13:39:36 -04009059 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009060 testCases = append(testCases, testCase{
9061 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009062 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009063 config: Config{
9064 MaxVersion: VersionTLS13,
9065 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009066 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009067 },
9068 },
Steven Valdeza833c352016-11-01 13:39:36 -04009069 resumeSession: true,
9070 shouldFail: true,
9071 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009072 })
9073
David Benjamin35ac5b72017-03-03 15:05:56 -05009074 // Test that the server's ticket age skew reporting works.
9075 testCases = append(testCases, testCase{
9076 testType: serverTest,
9077 name: "TLS13-TicketAgeSkew-Forward",
9078 config: Config{
9079 MaxVersion: VersionTLS13,
9080 Bugs: ProtocolBugs{
9081 SendTicketAge: 15 * time.Second,
9082 },
9083 },
David Benjamin065d7332017-03-26 10:51:43 -05009084 resumeSession: true,
9085 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009086 flags: []string{
9087 "-resumption-delay", "10",
9088 "-expect-ticket-age-skew", "5",
9089 },
9090 })
9091 testCases = append(testCases, testCase{
9092 testType: serverTest,
9093 name: "TLS13-TicketAgeSkew-Backward",
9094 config: Config{
9095 MaxVersion: VersionTLS13,
9096 Bugs: ProtocolBugs{
9097 SendTicketAge: 5 * time.Second,
9098 },
9099 },
David Benjamin065d7332017-03-26 10:51:43 -05009100 resumeSession: true,
9101 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009102 flags: []string{
9103 "-resumption-delay", "10",
9104 "-expect-ticket-age-skew", "-5",
9105 },
9106 })
9107
Steven Valdez08b65f42016-12-07 15:29:45 -05009108 testCases = append(testCases, testCase{
9109 testType: clientTest,
9110 name: "TLS13-SendTicketEarlyDataInfo",
9111 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009112 MaxVersion: VersionTLS13,
9113 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009114 },
9115 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009116 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009117 "-expect-early-data-info",
9118 },
9119 })
9120
David Benjamin9b160662017-01-25 19:53:43 -05009121 // Test that 0-RTT tickets are ignored in clients unless opted in.
9122 testCases = append(testCases, testCase{
9123 testType: clientTest,
9124 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9125 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009126 MaxVersion: VersionTLS13,
9127 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009128 },
9129 })
9130
Steven Valdez08b65f42016-12-07 15:29:45 -05009131 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009132 testType: clientTest,
9133 name: "TLS13-DuplicateTicketEarlyDataInfo",
9134 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009135 MaxVersion: VersionTLS13,
9136 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009137 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009138 DuplicateTicketEarlyDataInfo: true,
9139 },
9140 },
9141 shouldFail: true,
9142 expectedError: ":DUPLICATE_EXTENSION:",
9143 expectedLocalError: "remote error: illegal parameter",
9144 })
9145
9146 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009147 testType: serverTest,
9148 name: "TLS13-ExpectTicketEarlyDataInfo",
9149 config: Config{
9150 MaxVersion: VersionTLS13,
9151 Bugs: ProtocolBugs{
9152 ExpectTicketEarlyDataInfo: true,
9153 },
9154 },
9155 flags: []string{
9156 "-enable-early-data",
9157 },
9158 })
David Benjamin17b30832017-01-28 14:00:32 -05009159
9160 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9161 // is honored.
9162 testCases = append(testCases, testCase{
9163 testType: clientTest,
9164 name: "TLS13-HonorServerSessionTicketLifetime",
9165 config: Config{
9166 MaxVersion: VersionTLS13,
9167 Bugs: ProtocolBugs{
9168 SendTicketLifetime: 20 * time.Second,
9169 },
9170 },
9171 flags: []string{
9172 "-resumption-delay", "19",
9173 },
9174 resumeSession: true,
9175 })
9176 testCases = append(testCases, testCase{
9177 testType: clientTest,
9178 name: "TLS13-HonorServerSessionTicketLifetime-2",
9179 config: Config{
9180 MaxVersion: VersionTLS13,
9181 Bugs: ProtocolBugs{
9182 SendTicketLifetime: 20 * time.Second,
9183 // The client should not offer the expired session.
9184 ExpectNoTLS13PSK: true,
9185 },
9186 },
9187 flags: []string{
9188 "-resumption-delay", "21",
9189 },
David Benjamin023d4192017-02-06 13:49:07 -05009190 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009191 expectResumeRejected: true,
9192 })
Steven Valdez5b986082016-09-01 12:29:49 -04009193}
9194
David Benjamin82261be2016-07-07 14:32:50 -07009195func addChangeCipherSpecTests() {
9196 // Test missing ChangeCipherSpecs.
9197 testCases = append(testCases, testCase{
9198 name: "SkipChangeCipherSpec-Client",
9199 config: Config{
9200 MaxVersion: VersionTLS12,
9201 Bugs: ProtocolBugs{
9202 SkipChangeCipherSpec: true,
9203 },
9204 },
9205 shouldFail: true,
9206 expectedError: ":UNEXPECTED_RECORD:",
9207 })
9208 testCases = append(testCases, testCase{
9209 testType: serverTest,
9210 name: "SkipChangeCipherSpec-Server",
9211 config: Config{
9212 MaxVersion: VersionTLS12,
9213 Bugs: ProtocolBugs{
9214 SkipChangeCipherSpec: true,
9215 },
9216 },
9217 shouldFail: true,
9218 expectedError: ":UNEXPECTED_RECORD:",
9219 })
9220 testCases = append(testCases, testCase{
9221 testType: serverTest,
9222 name: "SkipChangeCipherSpec-Server-NPN",
9223 config: Config{
9224 MaxVersion: VersionTLS12,
9225 NextProtos: []string{"bar"},
9226 Bugs: ProtocolBugs{
9227 SkipChangeCipherSpec: true,
9228 },
9229 },
9230 flags: []string{
9231 "-advertise-npn", "\x03foo\x03bar\x03baz",
9232 },
9233 shouldFail: true,
9234 expectedError: ":UNEXPECTED_RECORD:",
9235 })
9236
9237 // Test synchronization between the handshake and ChangeCipherSpec.
9238 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9239 // rejected. Test both with and without handshake packing to handle both
9240 // when the partial post-CCS message is in its own record and when it is
9241 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009242 for _, packed := range []bool{false, true} {
9243 var suffix string
9244 if packed {
9245 suffix = "-Packed"
9246 }
9247
9248 testCases = append(testCases, testCase{
9249 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9250 config: Config{
9251 MaxVersion: VersionTLS12,
9252 Bugs: ProtocolBugs{
9253 FragmentAcrossChangeCipherSpec: true,
9254 PackHandshakeFlight: packed,
9255 },
9256 },
9257 shouldFail: true,
9258 expectedError: ":UNEXPECTED_RECORD:",
9259 })
9260 testCases = append(testCases, testCase{
9261 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9262 config: Config{
9263 MaxVersion: VersionTLS12,
9264 },
9265 resumeSession: true,
9266 resumeConfig: &Config{
9267 MaxVersion: VersionTLS12,
9268 Bugs: ProtocolBugs{
9269 FragmentAcrossChangeCipherSpec: true,
9270 PackHandshakeFlight: packed,
9271 },
9272 },
9273 shouldFail: true,
9274 expectedError: ":UNEXPECTED_RECORD:",
9275 })
9276 testCases = append(testCases, testCase{
9277 testType: serverTest,
9278 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9279 config: Config{
9280 MaxVersion: VersionTLS12,
9281 Bugs: ProtocolBugs{
9282 FragmentAcrossChangeCipherSpec: true,
9283 PackHandshakeFlight: packed,
9284 },
9285 },
9286 shouldFail: true,
9287 expectedError: ":UNEXPECTED_RECORD:",
9288 })
9289 testCases = append(testCases, testCase{
9290 testType: serverTest,
9291 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9292 config: Config{
9293 MaxVersion: VersionTLS12,
9294 },
9295 resumeSession: true,
9296 resumeConfig: &Config{
9297 MaxVersion: VersionTLS12,
9298 Bugs: ProtocolBugs{
9299 FragmentAcrossChangeCipherSpec: true,
9300 PackHandshakeFlight: packed,
9301 },
9302 },
9303 shouldFail: true,
9304 expectedError: ":UNEXPECTED_RECORD:",
9305 })
9306 testCases = append(testCases, testCase{
9307 testType: serverTest,
9308 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9309 config: Config{
9310 MaxVersion: VersionTLS12,
9311 NextProtos: []string{"bar"},
9312 Bugs: ProtocolBugs{
9313 FragmentAcrossChangeCipherSpec: true,
9314 PackHandshakeFlight: packed,
9315 },
9316 },
9317 flags: []string{
9318 "-advertise-npn", "\x03foo\x03bar\x03baz",
9319 },
9320 shouldFail: true,
9321 expectedError: ":UNEXPECTED_RECORD:",
9322 })
9323 }
9324
David Benjamin61672812016-07-14 23:10:43 -04009325 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9326 // messages in the handshake queue. Do this by testing the server
9327 // reading the client Finished, reversing the flight so Finished comes
9328 // first.
9329 testCases = append(testCases, testCase{
9330 protocol: dtls,
9331 testType: serverTest,
9332 name: "SendUnencryptedFinished-DTLS",
9333 config: Config{
9334 MaxVersion: VersionTLS12,
9335 Bugs: ProtocolBugs{
9336 SendUnencryptedFinished: true,
9337 ReverseHandshakeFragments: true,
9338 },
9339 },
9340 shouldFail: true,
9341 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9342 })
9343
Steven Valdez143e8b32016-07-11 13:19:03 -04009344 // Test synchronization between encryption changes and the handshake in
9345 // TLS 1.3, where ChangeCipherSpec is implicit.
9346 testCases = append(testCases, testCase{
9347 name: "PartialEncryptedExtensionsWithServerHello",
9348 config: Config{
9349 MaxVersion: VersionTLS13,
9350 Bugs: ProtocolBugs{
9351 PartialEncryptedExtensionsWithServerHello: true,
9352 },
9353 },
9354 shouldFail: true,
9355 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9356 })
9357 testCases = append(testCases, testCase{
9358 testType: serverTest,
9359 name: "PartialClientFinishedWithClientHello",
9360 config: Config{
9361 MaxVersion: VersionTLS13,
9362 Bugs: ProtocolBugs{
9363 PartialClientFinishedWithClientHello: true,
9364 },
9365 },
9366 shouldFail: true,
9367 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9368 })
9369
David Benjamin82261be2016-07-07 14:32:50 -07009370 // Test that early ChangeCipherSpecs are handled correctly.
9371 testCases = append(testCases, testCase{
9372 testType: serverTest,
9373 name: "EarlyChangeCipherSpec-server-1",
9374 config: Config{
9375 MaxVersion: VersionTLS12,
9376 Bugs: ProtocolBugs{
9377 EarlyChangeCipherSpec: 1,
9378 },
9379 },
9380 shouldFail: true,
9381 expectedError: ":UNEXPECTED_RECORD:",
9382 })
9383 testCases = append(testCases, testCase{
9384 testType: serverTest,
9385 name: "EarlyChangeCipherSpec-server-2",
9386 config: Config{
9387 MaxVersion: VersionTLS12,
9388 Bugs: ProtocolBugs{
9389 EarlyChangeCipherSpec: 2,
9390 },
9391 },
9392 shouldFail: true,
9393 expectedError: ":UNEXPECTED_RECORD:",
9394 })
9395 testCases = append(testCases, testCase{
9396 protocol: dtls,
9397 name: "StrayChangeCipherSpec",
9398 config: Config{
9399 // TODO(davidben): Once DTLS 1.3 exists, test
9400 // that stray ChangeCipherSpec messages are
9401 // rejected.
9402 MaxVersion: VersionTLS12,
9403 Bugs: ProtocolBugs{
9404 StrayChangeCipherSpec: true,
9405 },
9406 },
9407 })
9408
9409 // Test that the contents of ChangeCipherSpec are checked.
9410 testCases = append(testCases, testCase{
9411 name: "BadChangeCipherSpec-1",
9412 config: Config{
9413 MaxVersion: VersionTLS12,
9414 Bugs: ProtocolBugs{
9415 BadChangeCipherSpec: []byte{2},
9416 },
9417 },
9418 shouldFail: true,
9419 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9420 })
9421 testCases = append(testCases, testCase{
9422 name: "BadChangeCipherSpec-2",
9423 config: Config{
9424 MaxVersion: VersionTLS12,
9425 Bugs: ProtocolBugs{
9426 BadChangeCipherSpec: []byte{1, 1},
9427 },
9428 },
9429 shouldFail: true,
9430 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9431 })
9432 testCases = append(testCases, testCase{
9433 protocol: dtls,
9434 name: "BadChangeCipherSpec-DTLS-1",
9435 config: Config{
9436 MaxVersion: VersionTLS12,
9437 Bugs: ProtocolBugs{
9438 BadChangeCipherSpec: []byte{2},
9439 },
9440 },
9441 shouldFail: true,
9442 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9443 })
9444 testCases = append(testCases, testCase{
9445 protocol: dtls,
9446 name: "BadChangeCipherSpec-DTLS-2",
9447 config: Config{
9448 MaxVersion: VersionTLS12,
9449 Bugs: ProtocolBugs{
9450 BadChangeCipherSpec: []byte{1, 1},
9451 },
9452 },
9453 shouldFail: true,
9454 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9455 })
9456}
9457
David Benjamincd2c8062016-09-09 11:28:16 -04009458type perMessageTest struct {
9459 messageType uint8
9460 test testCase
9461}
9462
9463// makePerMessageTests returns a series of test templates which cover each
9464// message in the TLS handshake. These may be used with bugs like
9465// WrongMessageType to fully test a per-message bug.
9466func makePerMessageTests() []perMessageTest {
9467 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009468 for _, protocol := range []protocol{tls, dtls} {
9469 var suffix string
9470 if protocol == dtls {
9471 suffix = "-DTLS"
9472 }
9473
David Benjamincd2c8062016-09-09 11:28:16 -04009474 ret = append(ret, perMessageTest{
9475 messageType: typeClientHello,
9476 test: testCase{
9477 protocol: protocol,
9478 testType: serverTest,
9479 name: "ClientHello" + suffix,
9480 config: Config{
9481 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009482 },
9483 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009484 })
9485
9486 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009487 ret = append(ret, perMessageTest{
9488 messageType: typeHelloVerifyRequest,
9489 test: testCase{
9490 protocol: protocol,
9491 name: "HelloVerifyRequest" + suffix,
9492 config: Config{
9493 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009494 },
9495 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009496 })
9497 }
9498
David Benjamincd2c8062016-09-09 11:28:16 -04009499 ret = append(ret, perMessageTest{
9500 messageType: typeServerHello,
9501 test: testCase{
9502 protocol: protocol,
9503 name: "ServerHello" + suffix,
9504 config: Config{
9505 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009506 },
9507 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009508 })
9509
David Benjamincd2c8062016-09-09 11:28:16 -04009510 ret = append(ret, perMessageTest{
9511 messageType: typeCertificate,
9512 test: testCase{
9513 protocol: protocol,
9514 name: "ServerCertificate" + suffix,
9515 config: Config{
9516 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009517 },
9518 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009519 })
9520
David Benjamincd2c8062016-09-09 11:28:16 -04009521 ret = append(ret, perMessageTest{
9522 messageType: typeCertificateStatus,
9523 test: testCase{
9524 protocol: protocol,
9525 name: "CertificateStatus" + suffix,
9526 config: Config{
9527 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009528 },
David Benjamincd2c8062016-09-09 11:28:16 -04009529 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009530 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009531 })
9532
David Benjamincd2c8062016-09-09 11:28:16 -04009533 ret = append(ret, perMessageTest{
9534 messageType: typeServerKeyExchange,
9535 test: testCase{
9536 protocol: protocol,
9537 name: "ServerKeyExchange" + suffix,
9538 config: Config{
9539 MaxVersion: VersionTLS12,
9540 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009541 },
9542 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009543 })
9544
David Benjamincd2c8062016-09-09 11:28:16 -04009545 ret = append(ret, perMessageTest{
9546 messageType: typeCertificateRequest,
9547 test: testCase{
9548 protocol: protocol,
9549 name: "CertificateRequest" + suffix,
9550 config: Config{
9551 MaxVersion: VersionTLS12,
9552 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009553 },
9554 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009555 })
9556
David Benjamincd2c8062016-09-09 11:28:16 -04009557 ret = append(ret, perMessageTest{
9558 messageType: typeServerHelloDone,
9559 test: testCase{
9560 protocol: protocol,
9561 name: "ServerHelloDone" + suffix,
9562 config: Config{
9563 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009564 },
9565 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009566 })
9567
David Benjamincd2c8062016-09-09 11:28:16 -04009568 ret = append(ret, perMessageTest{
9569 messageType: typeCertificate,
9570 test: testCase{
9571 testType: serverTest,
9572 protocol: protocol,
9573 name: "ClientCertificate" + suffix,
9574 config: Config{
9575 Certificates: []Certificate{rsaCertificate},
9576 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009577 },
David Benjamincd2c8062016-09-09 11:28:16 -04009578 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009579 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009580 })
9581
David Benjamincd2c8062016-09-09 11:28:16 -04009582 ret = append(ret, perMessageTest{
9583 messageType: typeCertificateVerify,
9584 test: testCase{
9585 testType: serverTest,
9586 protocol: protocol,
9587 name: "CertificateVerify" + suffix,
9588 config: Config{
9589 Certificates: []Certificate{rsaCertificate},
9590 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009591 },
David Benjamincd2c8062016-09-09 11:28:16 -04009592 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009593 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009594 })
9595
David Benjamincd2c8062016-09-09 11:28:16 -04009596 ret = append(ret, perMessageTest{
9597 messageType: typeClientKeyExchange,
9598 test: testCase{
9599 testType: serverTest,
9600 protocol: protocol,
9601 name: "ClientKeyExchange" + suffix,
9602 config: Config{
9603 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009604 },
9605 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009606 })
9607
9608 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009609 ret = append(ret, perMessageTest{
9610 messageType: typeNextProtocol,
9611 test: testCase{
9612 testType: serverTest,
9613 protocol: protocol,
9614 name: "NextProtocol" + suffix,
9615 config: Config{
9616 MaxVersion: VersionTLS12,
9617 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009618 },
David Benjamincd2c8062016-09-09 11:28:16 -04009619 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009620 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009621 })
9622
David Benjamincd2c8062016-09-09 11:28:16 -04009623 ret = append(ret, perMessageTest{
9624 messageType: typeChannelID,
9625 test: testCase{
9626 testType: serverTest,
9627 protocol: protocol,
9628 name: "ChannelID" + suffix,
9629 config: Config{
9630 MaxVersion: VersionTLS12,
9631 ChannelID: channelIDKey,
9632 },
9633 flags: []string{
9634 "-expect-channel-id",
9635 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009636 },
9637 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009638 })
9639 }
9640
David Benjamincd2c8062016-09-09 11:28:16 -04009641 ret = append(ret, perMessageTest{
9642 messageType: typeFinished,
9643 test: testCase{
9644 testType: serverTest,
9645 protocol: protocol,
9646 name: "ClientFinished" + suffix,
9647 config: Config{
9648 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009649 },
9650 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009651 })
9652
David Benjamincd2c8062016-09-09 11:28:16 -04009653 ret = append(ret, perMessageTest{
9654 messageType: typeNewSessionTicket,
9655 test: testCase{
9656 protocol: protocol,
9657 name: "NewSessionTicket" + suffix,
9658 config: Config{
9659 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009660 },
9661 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009662 })
9663
David Benjamincd2c8062016-09-09 11:28:16 -04009664 ret = append(ret, perMessageTest{
9665 messageType: typeFinished,
9666 test: testCase{
9667 protocol: protocol,
9668 name: "ServerFinished" + suffix,
9669 config: Config{
9670 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009671 },
9672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009673 })
9674
9675 }
David Benjamincd2c8062016-09-09 11:28:16 -04009676
9677 ret = append(ret, perMessageTest{
9678 messageType: typeClientHello,
9679 test: testCase{
9680 testType: serverTest,
9681 name: "TLS13-ClientHello",
9682 config: Config{
9683 MaxVersion: VersionTLS13,
9684 },
9685 },
9686 })
9687
9688 ret = append(ret, perMessageTest{
9689 messageType: typeServerHello,
9690 test: testCase{
9691 name: "TLS13-ServerHello",
9692 config: Config{
9693 MaxVersion: VersionTLS13,
9694 },
9695 },
9696 })
9697
9698 ret = append(ret, perMessageTest{
9699 messageType: typeEncryptedExtensions,
9700 test: testCase{
9701 name: "TLS13-EncryptedExtensions",
9702 config: Config{
9703 MaxVersion: VersionTLS13,
9704 },
9705 },
9706 })
9707
9708 ret = append(ret, perMessageTest{
9709 messageType: typeCertificateRequest,
9710 test: testCase{
9711 name: "TLS13-CertificateRequest",
9712 config: Config{
9713 MaxVersion: VersionTLS13,
9714 ClientAuth: RequireAnyClientCert,
9715 },
9716 },
9717 })
9718
9719 ret = append(ret, perMessageTest{
9720 messageType: typeCertificate,
9721 test: testCase{
9722 name: "TLS13-ServerCertificate",
9723 config: Config{
9724 MaxVersion: VersionTLS13,
9725 },
9726 },
9727 })
9728
9729 ret = append(ret, perMessageTest{
9730 messageType: typeCertificateVerify,
9731 test: testCase{
9732 name: "TLS13-ServerCertificateVerify",
9733 config: Config{
9734 MaxVersion: VersionTLS13,
9735 },
9736 },
9737 })
9738
9739 ret = append(ret, perMessageTest{
9740 messageType: typeFinished,
9741 test: testCase{
9742 name: "TLS13-ServerFinished",
9743 config: Config{
9744 MaxVersion: VersionTLS13,
9745 },
9746 },
9747 })
9748
9749 ret = append(ret, perMessageTest{
9750 messageType: typeCertificate,
9751 test: testCase{
9752 testType: serverTest,
9753 name: "TLS13-ClientCertificate",
9754 config: Config{
9755 Certificates: []Certificate{rsaCertificate},
9756 MaxVersion: VersionTLS13,
9757 },
9758 flags: []string{"-require-any-client-certificate"},
9759 },
9760 })
9761
9762 ret = append(ret, perMessageTest{
9763 messageType: typeCertificateVerify,
9764 test: testCase{
9765 testType: serverTest,
9766 name: "TLS13-ClientCertificateVerify",
9767 config: Config{
9768 Certificates: []Certificate{rsaCertificate},
9769 MaxVersion: VersionTLS13,
9770 },
9771 flags: []string{"-require-any-client-certificate"},
9772 },
9773 })
9774
9775 ret = append(ret, perMessageTest{
9776 messageType: typeFinished,
9777 test: testCase{
9778 testType: serverTest,
9779 name: "TLS13-ClientFinished",
9780 config: Config{
9781 MaxVersion: VersionTLS13,
9782 },
9783 },
9784 })
9785
9786 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009787}
9788
David Benjamincd2c8062016-09-09 11:28:16 -04009789func addWrongMessageTypeTests() {
9790 for _, t := range makePerMessageTests() {
9791 t.test.name = "WrongMessageType-" + t.test.name
9792 t.test.config.Bugs.SendWrongMessageType = t.messageType
9793 t.test.shouldFail = true
9794 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9795 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009796
David Benjamincd2c8062016-09-09 11:28:16 -04009797 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9798 // In TLS 1.3, a bad ServerHello means the client sends
9799 // an unencrypted alert while the server expects
9800 // encryption, so the alert is not readable by runner.
9801 t.test.expectedLocalError = "local error: bad record MAC"
9802 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009803
David Benjamincd2c8062016-09-09 11:28:16 -04009804 testCases = append(testCases, t.test)
9805 }
David Benjaminebacdee2017-04-08 11:00:45 -04009806
9807 // The processing order for TLS 1.3 version negotiation is such that one
9808 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
9809 // TLS 1.2. Test that we do not do this.
9810 testCases = append(testCases, testCase{
9811 name: "SendServerHelloAsHelloRetryRequest",
9812 config: Config{
9813 MaxVersion: VersionTLS12,
9814 Bugs: ProtocolBugs{
9815 SendServerHelloAsHelloRetryRequest: true,
9816 },
9817 },
9818 shouldFail: true,
9819 expectedError: ":UNEXPECTED_MESSAGE:",
9820 expectedLocalError: "remote error: unexpected message",
9821 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009822}
9823
David Benjamin639846e2016-09-09 11:41:18 -04009824func addTrailingMessageDataTests() {
9825 for _, t := range makePerMessageTests() {
9826 t.test.name = "TrailingMessageData-" + t.test.name
9827 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9828 t.test.shouldFail = true
9829 t.test.expectedError = ":DECODE_ERROR:"
9830 t.test.expectedLocalError = "remote error: error decoding message"
9831
9832 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9833 // In TLS 1.3, a bad ServerHello means the client sends
9834 // an unencrypted alert while the server expects
9835 // encryption, so the alert is not readable by runner.
9836 t.test.expectedLocalError = "local error: bad record MAC"
9837 }
9838
9839 if t.messageType == typeFinished {
9840 // Bad Finished messages read as the verify data having
9841 // the wrong length.
9842 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9843 t.test.expectedLocalError = "remote error: error decrypting message"
9844 }
9845
9846 testCases = append(testCases, t.test)
9847 }
9848}
9849
Steven Valdez143e8b32016-07-11 13:19:03 -04009850func addTLS13HandshakeTests() {
9851 testCases = append(testCases, testCase{
9852 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009853 name: "NegotiatePSKResumption-TLS13",
9854 config: Config{
9855 MaxVersion: VersionTLS13,
9856 Bugs: ProtocolBugs{
9857 NegotiatePSKResumption: true,
9858 },
9859 },
9860 resumeSession: true,
9861 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009862 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009863 })
9864
9865 testCases = append(testCases, testCase{
9866 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009867 name: "MissingKeyShare-Client",
9868 config: Config{
9869 MaxVersion: VersionTLS13,
9870 Bugs: ProtocolBugs{
9871 MissingKeyShare: true,
9872 },
9873 },
9874 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009875 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009876 })
9877
9878 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009879 testType: serverTest,
9880 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009881 config: Config{
9882 MaxVersion: VersionTLS13,
9883 Bugs: ProtocolBugs{
9884 MissingKeyShare: true,
9885 },
9886 },
9887 shouldFail: true,
9888 expectedError: ":MISSING_KEY_SHARE:",
9889 })
9890
9891 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009892 testType: serverTest,
9893 name: "DuplicateKeyShares",
9894 config: Config{
9895 MaxVersion: VersionTLS13,
9896 Bugs: ProtocolBugs{
9897 DuplicateKeyShares: true,
9898 },
9899 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009900 shouldFail: true,
9901 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009902 })
9903
9904 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009905 testType: serverTest,
9906 name: "SkipEarlyData",
9907 config: Config{
9908 MaxVersion: VersionTLS13,
9909 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009910 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009911 },
9912 },
9913 })
9914
9915 testCases = append(testCases, testCase{
9916 testType: serverTest,
9917 name: "SkipEarlyData-OmitEarlyDataExtension",
9918 config: Config{
9919 MaxVersion: VersionTLS13,
9920 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009921 SendFakeEarlyDataLength: 4,
9922 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009923 },
9924 },
9925 shouldFail: true,
9926 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9927 })
9928
9929 testCases = append(testCases, testCase{
9930 testType: serverTest,
9931 name: "SkipEarlyData-TooMuchData",
9932 config: Config{
9933 MaxVersion: VersionTLS13,
9934 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009935 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009936 },
9937 },
9938 shouldFail: true,
9939 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9940 })
9941
9942 testCases = append(testCases, testCase{
9943 testType: serverTest,
9944 name: "SkipEarlyData-Interleaved",
9945 config: Config{
9946 MaxVersion: VersionTLS13,
9947 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009948 SendFakeEarlyDataLength: 4,
9949 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009950 },
9951 },
9952 shouldFail: true,
9953 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9954 })
9955
9956 testCases = append(testCases, testCase{
9957 testType: serverTest,
9958 name: "SkipEarlyData-EarlyDataInTLS12",
9959 config: Config{
9960 MaxVersion: VersionTLS13,
9961 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009962 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009963 },
9964 },
9965 shouldFail: true,
9966 expectedError: ":UNEXPECTED_RECORD:",
9967 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9968 })
9969
9970 testCases = append(testCases, testCase{
9971 testType: serverTest,
9972 name: "SkipEarlyData-HRR",
9973 config: Config{
9974 MaxVersion: VersionTLS13,
9975 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009976 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009977 },
9978 DefaultCurves: []CurveID{},
9979 },
9980 })
9981
9982 testCases = append(testCases, testCase{
9983 testType: serverTest,
9984 name: "SkipEarlyData-HRR-Interleaved",
9985 config: Config{
9986 MaxVersion: VersionTLS13,
9987 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009988 SendFakeEarlyDataLength: 4,
9989 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009990 },
9991 DefaultCurves: []CurveID{},
9992 },
9993 shouldFail: true,
9994 expectedError: ":UNEXPECTED_RECORD:",
9995 })
9996
9997 testCases = append(testCases, testCase{
9998 testType: serverTest,
9999 name: "SkipEarlyData-HRR-TooMuchData",
10000 config: Config{
10001 MaxVersion: VersionTLS13,
10002 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010003 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010004 },
10005 DefaultCurves: []CurveID{},
10006 },
10007 shouldFail: true,
10008 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10009 })
10010
10011 // Test that skipping early data looking for cleartext correctly
10012 // processes an alert record.
10013 testCases = append(testCases, testCase{
10014 testType: serverTest,
10015 name: "SkipEarlyData-HRR-FatalAlert",
10016 config: Config{
10017 MaxVersion: VersionTLS13,
10018 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010019 SendEarlyAlert: true,
10020 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010021 },
10022 DefaultCurves: []CurveID{},
10023 },
10024 shouldFail: true,
10025 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10026 })
10027
10028 testCases = append(testCases, testCase{
10029 testType: serverTest,
10030 name: "SkipEarlyData-SecondClientHelloEarlyData",
10031 config: Config{
10032 MaxVersion: VersionTLS13,
10033 Bugs: ProtocolBugs{
10034 SendEarlyDataOnSecondClientHello: true,
10035 },
10036 DefaultCurves: []CurveID{},
10037 },
10038 shouldFail: true,
10039 expectedLocalError: "remote error: bad record MAC",
10040 })
10041
10042 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010043 testType: clientTest,
10044 name: "EmptyEncryptedExtensions",
10045 config: Config{
10046 MaxVersion: VersionTLS13,
10047 Bugs: ProtocolBugs{
10048 EmptyEncryptedExtensions: true,
10049 },
10050 },
10051 shouldFail: true,
10052 expectedLocalError: "remote error: error decoding message",
10053 })
10054
10055 testCases = append(testCases, testCase{
10056 testType: clientTest,
10057 name: "EncryptedExtensionsWithKeyShare",
10058 config: Config{
10059 MaxVersion: VersionTLS13,
10060 Bugs: ProtocolBugs{
10061 EncryptedExtensionsWithKeyShare: true,
10062 },
10063 },
10064 shouldFail: true,
10065 expectedLocalError: "remote error: unsupported extension",
10066 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010067
10068 testCases = append(testCases, testCase{
10069 testType: serverTest,
10070 name: "SendHelloRetryRequest",
10071 config: Config{
10072 MaxVersion: VersionTLS13,
10073 // Require a HelloRetryRequest for every curve.
10074 DefaultCurves: []CurveID{},
10075 },
10076 expectedCurveID: CurveX25519,
10077 })
10078
10079 testCases = append(testCases, testCase{
10080 testType: serverTest,
10081 name: "SendHelloRetryRequest-2",
10082 config: Config{
10083 MaxVersion: VersionTLS13,
10084 DefaultCurves: []CurveID{CurveP384},
10085 },
10086 // Although the ClientHello did not predict our preferred curve,
10087 // we always select it whether it is predicted or not.
10088 expectedCurveID: CurveX25519,
10089 })
10090
10091 testCases = append(testCases, testCase{
10092 name: "UnknownCurve-HelloRetryRequest",
10093 config: Config{
10094 MaxVersion: VersionTLS13,
10095 // P-384 requires HelloRetryRequest in BoringSSL.
10096 CurvePreferences: []CurveID{CurveP384},
10097 Bugs: ProtocolBugs{
10098 SendHelloRetryRequestCurve: bogusCurve,
10099 },
10100 },
10101 shouldFail: true,
10102 expectedError: ":WRONG_CURVE:",
10103 })
10104
10105 testCases = append(testCases, testCase{
10106 name: "DisabledCurve-HelloRetryRequest",
10107 config: Config{
10108 MaxVersion: VersionTLS13,
10109 CurvePreferences: []CurveID{CurveP256},
10110 Bugs: ProtocolBugs{
10111 IgnorePeerCurvePreferences: true,
10112 },
10113 },
10114 flags: []string{"-p384-only"},
10115 shouldFail: true,
10116 expectedError: ":WRONG_CURVE:",
10117 })
10118
10119 testCases = append(testCases, testCase{
10120 name: "UnnecessaryHelloRetryRequest",
10121 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010122 MaxVersion: VersionTLS13,
10123 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010124 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010125 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010126 },
10127 },
10128 shouldFail: true,
10129 expectedError: ":WRONG_CURVE:",
10130 })
10131
10132 testCases = append(testCases, testCase{
10133 name: "SecondHelloRetryRequest",
10134 config: Config{
10135 MaxVersion: VersionTLS13,
10136 // P-384 requires HelloRetryRequest in BoringSSL.
10137 CurvePreferences: []CurveID{CurveP384},
10138 Bugs: ProtocolBugs{
10139 SecondHelloRetryRequest: true,
10140 },
10141 },
10142 shouldFail: true,
10143 expectedError: ":UNEXPECTED_MESSAGE:",
10144 })
10145
10146 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010147 name: "HelloRetryRequest-Empty",
10148 config: Config{
10149 MaxVersion: VersionTLS13,
10150 Bugs: ProtocolBugs{
10151 AlwaysSendHelloRetryRequest: true,
10152 },
10153 },
10154 shouldFail: true,
10155 expectedError: ":DECODE_ERROR:",
10156 })
10157
10158 testCases = append(testCases, testCase{
10159 name: "HelloRetryRequest-DuplicateCurve",
10160 config: Config{
10161 MaxVersion: VersionTLS13,
10162 // P-384 requires a HelloRetryRequest against BoringSSL's default
10163 // configuration. Assert this ExpectMissingKeyShare.
10164 CurvePreferences: []CurveID{CurveP384},
10165 Bugs: ProtocolBugs{
10166 ExpectMissingKeyShare: true,
10167 DuplicateHelloRetryRequestExtensions: true,
10168 },
10169 },
10170 shouldFail: true,
10171 expectedError: ":DUPLICATE_EXTENSION:",
10172 expectedLocalError: "remote error: illegal parameter",
10173 })
10174
10175 testCases = append(testCases, testCase{
10176 name: "HelloRetryRequest-Cookie",
10177 config: Config{
10178 MaxVersion: VersionTLS13,
10179 Bugs: ProtocolBugs{
10180 SendHelloRetryRequestCookie: []byte("cookie"),
10181 },
10182 },
10183 })
10184
10185 testCases = append(testCases, testCase{
10186 name: "HelloRetryRequest-DuplicateCookie",
10187 config: Config{
10188 MaxVersion: VersionTLS13,
10189 Bugs: ProtocolBugs{
10190 SendHelloRetryRequestCookie: []byte("cookie"),
10191 DuplicateHelloRetryRequestExtensions: true,
10192 },
10193 },
10194 shouldFail: true,
10195 expectedError: ":DUPLICATE_EXTENSION:",
10196 expectedLocalError: "remote error: illegal parameter",
10197 })
10198
10199 testCases = append(testCases, testCase{
10200 name: "HelloRetryRequest-EmptyCookie",
10201 config: Config{
10202 MaxVersion: VersionTLS13,
10203 Bugs: ProtocolBugs{
10204 SendHelloRetryRequestCookie: []byte{},
10205 },
10206 },
10207 shouldFail: true,
10208 expectedError: ":DECODE_ERROR:",
10209 })
10210
10211 testCases = append(testCases, testCase{
10212 name: "HelloRetryRequest-Cookie-Curve",
10213 config: Config{
10214 MaxVersion: VersionTLS13,
10215 // P-384 requires HelloRetryRequest in BoringSSL.
10216 CurvePreferences: []CurveID{CurveP384},
10217 Bugs: ProtocolBugs{
10218 SendHelloRetryRequestCookie: []byte("cookie"),
10219 ExpectMissingKeyShare: true,
10220 },
10221 },
10222 })
10223
10224 testCases = append(testCases, testCase{
10225 name: "HelloRetryRequest-Unknown",
10226 config: Config{
10227 MaxVersion: VersionTLS13,
10228 Bugs: ProtocolBugs{
10229 CustomHelloRetryRequestExtension: "extension",
10230 },
10231 },
10232 shouldFail: true,
10233 expectedError: ":UNEXPECTED_EXTENSION:",
10234 expectedLocalError: "remote error: unsupported extension",
10235 })
10236
10237 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010238 testType: serverTest,
10239 name: "SecondClientHelloMissingKeyShare",
10240 config: Config{
10241 MaxVersion: VersionTLS13,
10242 DefaultCurves: []CurveID{},
10243 Bugs: ProtocolBugs{
10244 SecondClientHelloMissingKeyShare: true,
10245 },
10246 },
10247 shouldFail: true,
10248 expectedError: ":MISSING_KEY_SHARE:",
10249 })
10250
10251 testCases = append(testCases, testCase{
10252 testType: serverTest,
10253 name: "SecondClientHelloWrongCurve",
10254 config: Config{
10255 MaxVersion: VersionTLS13,
10256 DefaultCurves: []CurveID{},
10257 Bugs: ProtocolBugs{
10258 MisinterpretHelloRetryRequestCurve: CurveP521,
10259 },
10260 },
10261 shouldFail: true,
10262 expectedError: ":WRONG_CURVE:",
10263 })
10264
10265 testCases = append(testCases, testCase{
10266 name: "HelloRetryRequestVersionMismatch",
10267 config: Config{
10268 MaxVersion: VersionTLS13,
10269 // P-384 requires HelloRetryRequest in BoringSSL.
10270 CurvePreferences: []CurveID{CurveP384},
10271 Bugs: ProtocolBugs{
10272 SendServerHelloVersion: 0x0305,
10273 },
10274 },
10275 shouldFail: true,
10276 expectedError: ":WRONG_VERSION_NUMBER:",
10277 })
10278
10279 testCases = append(testCases, testCase{
10280 name: "HelloRetryRequestCurveMismatch",
10281 config: Config{
10282 MaxVersion: VersionTLS13,
10283 // P-384 requires HelloRetryRequest in BoringSSL.
10284 CurvePreferences: []CurveID{CurveP384},
10285 Bugs: ProtocolBugs{
10286 // Send P-384 (correct) in the HelloRetryRequest.
10287 SendHelloRetryRequestCurve: CurveP384,
10288 // But send P-256 in the ServerHello.
10289 SendCurve: CurveP256,
10290 },
10291 },
10292 shouldFail: true,
10293 expectedError: ":WRONG_CURVE:",
10294 })
10295
10296 // Test the server selecting a curve that requires a HelloRetryRequest
10297 // without sending it.
10298 testCases = append(testCases, testCase{
10299 name: "SkipHelloRetryRequest",
10300 config: Config{
10301 MaxVersion: VersionTLS13,
10302 // P-384 requires HelloRetryRequest in BoringSSL.
10303 CurvePreferences: []CurveID{CurveP384},
10304 Bugs: ProtocolBugs{
10305 SkipHelloRetryRequest: true,
10306 },
10307 },
10308 shouldFail: true,
10309 expectedError: ":WRONG_CURVE:",
10310 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010311
10312 testCases = append(testCases, testCase{
10313 name: "TLS13-RequestContextInHandshake",
10314 config: Config{
10315 MaxVersion: VersionTLS13,
10316 MinVersion: VersionTLS13,
10317 ClientAuth: RequireAnyClientCert,
10318 Bugs: ProtocolBugs{
10319 SendRequestContext: []byte("request context"),
10320 },
10321 },
10322 flags: []string{
10323 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10324 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10325 },
10326 shouldFail: true,
10327 expectedError: ":DECODE_ERROR:",
10328 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010329
10330 testCases = append(testCases, testCase{
10331 testType: serverTest,
10332 name: "TLS13-TrailingKeyShareData",
10333 config: Config{
10334 MaxVersion: VersionTLS13,
10335 Bugs: ProtocolBugs{
10336 TrailingKeyShareData: true,
10337 },
10338 },
10339 shouldFail: true,
10340 expectedError: ":DECODE_ERROR:",
10341 })
David Benjamin7f78df42016-10-05 22:33:19 -040010342
10343 testCases = append(testCases, testCase{
10344 name: "TLS13-AlwaysSelectPSKIdentity",
10345 config: Config{
10346 MaxVersion: VersionTLS13,
10347 Bugs: ProtocolBugs{
10348 AlwaysSelectPSKIdentity: true,
10349 },
10350 },
10351 shouldFail: true,
10352 expectedError: ":UNEXPECTED_EXTENSION:",
10353 })
10354
10355 testCases = append(testCases, testCase{
10356 name: "TLS13-InvalidPSKIdentity",
10357 config: Config{
10358 MaxVersion: VersionTLS13,
10359 Bugs: ProtocolBugs{
10360 SelectPSKIdentityOnResume: 1,
10361 },
10362 },
10363 resumeSession: true,
10364 shouldFail: true,
10365 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10366 })
David Benjamin1286bee2016-10-07 15:25:06 -040010367
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010368 testCases = append(testCases, testCase{
10369 testType: serverTest,
10370 name: "TLS13-ExtraPSKIdentity",
10371 config: Config{
10372 MaxVersion: VersionTLS13,
10373 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010374 ExtraPSKIdentity: true,
10375 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010376 },
10377 },
10378 resumeSession: true,
10379 })
10380
David Benjamin1286bee2016-10-07 15:25:06 -040010381 // Test that unknown NewSessionTicket extensions are tolerated.
10382 testCases = append(testCases, testCase{
10383 name: "TLS13-CustomTicketExtension",
10384 config: Config{
10385 MaxVersion: VersionTLS13,
10386 Bugs: ProtocolBugs{
10387 CustomTicketExtension: "1234",
10388 },
10389 },
10390 })
Steven Valdez2d850622017-01-11 11:34:52 -050010391
Steven Valdez2d850622017-01-11 11:34:52 -050010392 testCases = append(testCases, testCase{
10393 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010394 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010395 config: Config{
10396 MaxVersion: VersionTLS13,
10397 MaxEarlyDataSize: 16384,
10398 },
10399 resumeConfig: &Config{
10400 MaxVersion: VersionTLS13,
10401 MaxEarlyDataSize: 16384,
10402 Bugs: ProtocolBugs{
10403 AlwaysRejectEarlyData: true,
10404 },
10405 },
10406 resumeSession: true,
10407 flags: []string{
10408 "-enable-early-data",
10409 "-expect-early-data-info",
10410 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010411 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010412 },
10413 })
10414
10415 testCases = append(testCases, testCase{
10416 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010417 name: "TLS13-EarlyData-RejectTicket-Client",
10418 config: Config{
10419 MaxVersion: VersionTLS13,
10420 MaxEarlyDataSize: 16384,
10421 Certificates: []Certificate{rsaCertificate},
10422 },
10423 resumeConfig: &Config{
10424 MaxVersion: VersionTLS13,
10425 MaxEarlyDataSize: 16384,
10426 Certificates: []Certificate{ecdsaP256Certificate},
10427 SessionTicketsDisabled: true,
10428 },
10429 resumeSession: true,
10430 expectResumeRejected: true,
10431 flags: []string{
10432 "-enable-early-data",
10433 "-expect-early-data-info",
10434 "-expect-reject-early-data",
10435 "-on-resume-shim-writes-first",
10436 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10437 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10438 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10439 // Session tickets are disabled, so the runner will not send a ticket.
10440 "-on-retry-expect-no-session",
10441 },
10442 })
10443
10444 testCases = append(testCases, testCase{
10445 testType: clientTest,
10446 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010447 config: Config{
10448 MaxVersion: VersionTLS13,
10449 MaxEarlyDataSize: 16384,
10450 },
10451 resumeConfig: &Config{
10452 MaxVersion: VersionTLS13,
10453 MaxEarlyDataSize: 16384,
10454 Bugs: ProtocolBugs{
10455 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10456 },
10457 },
10458 resumeSession: true,
10459 flags: []string{
10460 "-enable-early-data",
10461 "-expect-early-data-info",
10462 "-expect-reject-early-data",
10463 },
10464 })
10465
10466 // The client must check the server does not send the early_data
10467 // extension while rejecting the session.
10468 testCases = append(testCases, testCase{
10469 testType: clientTest,
10470 name: "TLS13-EarlyDataWithoutResume-Client",
10471 config: Config{
10472 MaxVersion: VersionTLS13,
10473 MaxEarlyDataSize: 16384,
10474 },
10475 resumeConfig: &Config{
10476 MaxVersion: VersionTLS13,
10477 SessionTicketsDisabled: true,
10478 Bugs: ProtocolBugs{
10479 SendEarlyDataExtension: true,
10480 },
10481 },
10482 resumeSession: true,
10483 flags: []string{
10484 "-enable-early-data",
10485 "-expect-early-data-info",
10486 },
10487 shouldFail: true,
10488 expectedError: ":UNEXPECTED_EXTENSION:",
10489 })
10490
10491 // The client must fail with a dedicated error code if the server
10492 // responds with TLS 1.2 when offering 0-RTT.
10493 testCases = append(testCases, testCase{
10494 testType: clientTest,
10495 name: "TLS13-EarlyDataVersionDowngrade-Client",
10496 config: Config{
10497 MaxVersion: VersionTLS13,
10498 MaxEarlyDataSize: 16384,
10499 },
10500 resumeConfig: &Config{
10501 MaxVersion: VersionTLS12,
10502 },
10503 resumeSession: true,
10504 flags: []string{
10505 "-enable-early-data",
10506 "-expect-early-data-info",
10507 },
10508 shouldFail: true,
10509 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10510 })
10511
10512 // Test that the client rejects an (unsolicited) early_data extension if
10513 // the server sent an HRR.
10514 testCases = append(testCases, testCase{
10515 testType: clientTest,
10516 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10517 config: Config{
10518 MaxVersion: VersionTLS13,
10519 MaxEarlyDataSize: 16384,
10520 },
10521 resumeConfig: &Config{
10522 MaxVersion: VersionTLS13,
10523 MaxEarlyDataSize: 16384,
10524 Bugs: ProtocolBugs{
10525 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10526 SendEarlyDataExtension: true,
10527 },
10528 },
10529 resumeSession: true,
10530 flags: []string{
10531 "-enable-early-data",
10532 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010533 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010534 },
10535 shouldFail: true,
10536 expectedError: ":UNEXPECTED_EXTENSION:",
10537 })
10538
10539 fooString := "foo"
10540 barString := "bar"
10541
10542 // Test that the client reports the correct ALPN after a 0-RTT reject
10543 // that changed it.
10544 testCases = append(testCases, testCase{
10545 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010546 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010547 config: Config{
10548 MaxVersion: VersionTLS13,
10549 MaxEarlyDataSize: 16384,
10550 Bugs: ProtocolBugs{
10551 ALPNProtocol: &fooString,
10552 },
10553 },
10554 resumeConfig: &Config{
10555 MaxVersion: VersionTLS13,
10556 MaxEarlyDataSize: 16384,
10557 Bugs: ProtocolBugs{
10558 ALPNProtocol: &barString,
10559 },
10560 },
10561 resumeSession: true,
10562 flags: []string{
10563 "-advertise-alpn", "\x03foo\x03bar",
10564 "-enable-early-data",
10565 "-expect-early-data-info",
10566 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010567 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010568 "-on-resume-expect-alpn", "foo",
10569 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010570 },
10571 })
10572
10573 // Test that the client reports the correct ALPN after a 0-RTT reject if
10574 // ALPN was omitted from the first connection.
10575 testCases = append(testCases, testCase{
10576 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010577 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010578 config: Config{
10579 MaxVersion: VersionTLS13,
10580 MaxEarlyDataSize: 16384,
10581 },
10582 resumeConfig: &Config{
10583 MaxVersion: VersionTLS13,
10584 MaxEarlyDataSize: 16384,
10585 NextProtos: []string{"foo"},
10586 },
10587 resumeSession: true,
10588 flags: []string{
10589 "-advertise-alpn", "\x03foo\x03bar",
10590 "-enable-early-data",
10591 "-expect-early-data-info",
10592 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010593 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010594 "-on-resume-expect-alpn", "",
10595 "-on-retry-expect-alpn", "foo",
10596 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010597 },
10598 })
10599
10600 // Test that the client reports the correct ALPN after a 0-RTT reject if
10601 // ALPN was omitted from the second connection.
10602 testCases = append(testCases, testCase{
10603 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010604 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010605 config: Config{
10606 MaxVersion: VersionTLS13,
10607 MaxEarlyDataSize: 16384,
10608 NextProtos: []string{"foo"},
10609 },
10610 resumeConfig: &Config{
10611 MaxVersion: VersionTLS13,
10612 MaxEarlyDataSize: 16384,
10613 },
10614 resumeSession: true,
10615 flags: []string{
10616 "-advertise-alpn", "\x03foo\x03bar",
10617 "-enable-early-data",
10618 "-expect-early-data-info",
10619 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010620 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010621 "-on-resume-expect-alpn", "foo",
10622 "-on-retry-expect-alpn", "",
10623 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010624 },
10625 })
10626
10627 // Test that the client enforces ALPN match on 0-RTT accept.
10628 testCases = append(testCases, testCase{
10629 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010630 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010631 config: Config{
10632 MaxVersion: VersionTLS13,
10633 MaxEarlyDataSize: 16384,
10634 Bugs: ProtocolBugs{
10635 ALPNProtocol: &fooString,
10636 },
10637 },
10638 resumeConfig: &Config{
10639 MaxVersion: VersionTLS13,
10640 MaxEarlyDataSize: 16384,
10641 Bugs: ProtocolBugs{
10642 AlwaysAcceptEarlyData: true,
10643 ALPNProtocol: &barString,
10644 },
10645 },
10646 resumeSession: true,
10647 flags: []string{
10648 "-advertise-alpn", "\x03foo\x03bar",
10649 "-enable-early-data",
10650 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010651 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010652 "-on-resume-expect-alpn", "foo",
10653 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010654 },
10655 shouldFail: true,
10656 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10657 })
10658
10659 // Test that the server correctly rejects 0-RTT when the previous
10660 // session did not allow early data on resumption.
10661 testCases = append(testCases, testCase{
10662 testType: serverTest,
10663 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10664 config: Config{
10665 MaxVersion: VersionTLS13,
10666 },
10667 resumeConfig: &Config{
10668 MaxVersion: VersionTLS13,
10669 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010670 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010671 ExpectEarlyDataAccepted: false,
10672 },
10673 },
10674 resumeSession: true,
10675 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010676 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010677 "-expect-reject-early-data",
10678 },
10679 })
10680
10681 // Test that we reject early data where ALPN is omitted from the first
10682 // connection.
10683 testCases = append(testCases, testCase{
10684 testType: serverTest,
10685 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10686 config: Config{
10687 MaxVersion: VersionTLS13,
10688 NextProtos: []string{},
10689 },
10690 resumeConfig: &Config{
10691 MaxVersion: VersionTLS13,
10692 NextProtos: []string{"foo"},
10693 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010694 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010695 ExpectEarlyDataAccepted: false,
10696 },
10697 },
10698 resumeSession: true,
10699 flags: []string{
10700 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010701 "-on-initial-select-alpn", "",
10702 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010703 },
10704 })
10705
10706 // Test that we reject early data where ALPN is omitted from the second
10707 // connection.
10708 testCases = append(testCases, testCase{
10709 testType: serverTest,
10710 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10711 config: Config{
10712 MaxVersion: VersionTLS13,
10713 NextProtos: []string{"foo"},
10714 },
10715 resumeConfig: &Config{
10716 MaxVersion: VersionTLS13,
10717 NextProtos: []string{},
10718 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010719 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010720 ExpectEarlyDataAccepted: false,
10721 },
10722 },
10723 resumeSession: true,
10724 flags: []string{
10725 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010726 "-on-initial-select-alpn", "foo",
10727 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010728 },
10729 })
10730
10731 // Test that we reject early data with mismatched ALPN.
10732 testCases = append(testCases, testCase{
10733 testType: serverTest,
10734 name: "TLS13-EarlyData-ALPNMismatch-Server",
10735 config: Config{
10736 MaxVersion: VersionTLS13,
10737 NextProtos: []string{"foo"},
10738 },
10739 resumeConfig: &Config{
10740 MaxVersion: VersionTLS13,
10741 NextProtos: []string{"bar"},
10742 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010743 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010744 ExpectEarlyDataAccepted: false,
10745 },
10746 },
10747 resumeSession: true,
10748 flags: []string{
10749 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010750 "-on-initial-select-alpn", "foo",
10751 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010752 },
10753 })
10754
David Benjamin6bb507b2017-03-29 16:35:57 -050010755 // Test that the client offering 0-RTT and Channel ID forbids the server
10756 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010757 testCases = append(testCases, testCase{
10758 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010759 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010760 config: Config{
10761 MaxVersion: VersionTLS13,
10762 MaxEarlyDataSize: 16384,
10763 RequestChannelID: true,
10764 },
10765 resumeSession: true,
10766 expectChannelID: true,
10767 shouldFail: true,
10768 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10769 flags: []string{
10770 "-enable-early-data",
10771 "-expect-early-data-info",
10772 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10773 },
10774 })
10775
David Benjamin6bb507b2017-03-29 16:35:57 -050010776 // Test that the client offering Channel ID and 0-RTT allows the server
10777 // to decline 0-RTT.
10778 testCases = append(testCases, testCase{
10779 testType: clientTest,
10780 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10781 config: Config{
10782 MaxVersion: VersionTLS13,
10783 MaxEarlyDataSize: 16384,
10784 RequestChannelID: true,
10785 Bugs: ProtocolBugs{
10786 AlwaysRejectEarlyData: true,
10787 },
10788 },
10789 resumeSession: true,
10790 expectChannelID: true,
10791 flags: []string{
10792 "-enable-early-data",
10793 "-expect-early-data-info",
10794 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10795 "-expect-reject-early-data",
10796 },
10797 })
10798
10799 // Test that the client offering Channel ID and 0-RTT allows the server
10800 // to decline Channel ID.
10801 testCases = append(testCases, testCase{
10802 testType: clientTest,
10803 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
10804 config: Config{
10805 MaxVersion: VersionTLS13,
10806 MaxEarlyDataSize: 16384,
10807 },
10808 resumeSession: true,
10809 flags: []string{
10810 "-enable-early-data",
10811 "-expect-early-data-info",
10812 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10813 "-expect-accept-early-data",
10814 },
10815 })
10816
10817 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
10818 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050010819 testCases = append(testCases, testCase{
10820 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010821 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050010822 config: Config{
10823 MaxVersion: VersionTLS13,
10824 ChannelID: channelIDKey,
10825 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050010826 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050010827 ExpectEarlyDataAccepted: false,
10828 },
10829 },
10830 resumeSession: true,
10831 expectChannelID: true,
10832 flags: []string{
10833 "-enable-early-data",
10834 "-expect-reject-early-data",
10835 "-expect-channel-id",
10836 base64.StdEncoding.EncodeToString(channelIDBytes),
10837 },
10838 })
10839
David Benjamin6bb507b2017-03-29 16:35:57 -050010840 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
10841 // if not offered Channel ID.
10842 testCases = append(testCases, testCase{
10843 testType: serverTest,
10844 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
10845 config: Config{
10846 MaxVersion: VersionTLS13,
10847 Bugs: ProtocolBugs{
10848 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10849 ExpectEarlyDataAccepted: true,
10850 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10851 },
10852 },
10853 resumeSession: true,
10854 expectChannelID: false,
10855 flags: []string{
10856 "-enable-early-data",
10857 "-expect-accept-early-data",
10858 "-enable-channel-id",
10859 },
10860 })
10861
David Benjamin32c89272017-03-26 13:54:21 -050010862 // Test that the server rejects 0-RTT streams without end_of_early_data.
10863 // The subsequent records should fail to decrypt.
10864 testCases = append(testCases, testCase{
10865 testType: serverTest,
10866 name: "TLS13-EarlyData-SkipEndOfEarlyData",
10867 config: Config{
10868 MaxVersion: VersionTLS13,
10869 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010870 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050010871 ExpectEarlyDataAccepted: true,
10872 SkipEndOfEarlyData: true,
10873 },
10874 },
10875 resumeSession: true,
10876 flags: []string{"-enable-early-data"},
10877 shouldFail: true,
10878 expectedLocalError: "remote error: bad record MAC",
10879 expectedError: ":BAD_DECRYPT:",
10880 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050010881
10882 testCases = append(testCases, testCase{
10883 testType: serverTest,
10884 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
10885 config: Config{
10886 MaxVersion: VersionTLS13,
10887 },
10888 resumeConfig: &Config{
10889 MaxVersion: VersionTLS13,
10890 Bugs: ProtocolBugs{
10891 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10892 SendStrayEarlyHandshake: true,
10893 ExpectEarlyDataAccepted: true},
10894 },
10895 resumeSession: true,
10896 shouldFail: true,
10897 expectedError: ":UNEXPECTED_RECORD:",
10898 expectedLocalError: "remote error: unexpected message",
10899 flags: []string{
10900 "-enable-early-data",
10901 },
10902 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010903}
10904
David Benjaminabbbee12016-10-31 19:20:42 -040010905func addTLS13CipherPreferenceTests() {
10906 // Test that client preference is honored if the shim has AES hardware
10907 // and ChaCha20-Poly1305 is preferred otherwise.
10908 testCases = append(testCases, testCase{
10909 testType: serverTest,
10910 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
10911 config: Config{
10912 MaxVersion: VersionTLS13,
10913 CipherSuites: []uint16{
10914 TLS_CHACHA20_POLY1305_SHA256,
10915 TLS_AES_128_GCM_SHA256,
10916 },
10917 },
10918 flags: []string{
10919 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10920 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10921 },
10922 })
10923
10924 testCases = append(testCases, testCase{
10925 testType: serverTest,
10926 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
10927 config: Config{
10928 MaxVersion: VersionTLS13,
10929 CipherSuites: []uint16{
10930 TLS_AES_128_GCM_SHA256,
10931 TLS_CHACHA20_POLY1305_SHA256,
10932 },
10933 },
10934 flags: []string{
10935 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10936 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10937 },
10938 })
10939
10940 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
10941 // whether it has AES hardware.
10942 testCases = append(testCases, testCase{
10943 name: "TLS13-CipherPreference-Client",
10944 config: Config{
10945 MaxVersion: VersionTLS13,
10946 // Use the client cipher order. (This is the default but
10947 // is listed to be explicit.)
10948 PreferServerCipherSuites: false,
10949 },
10950 flags: []string{
10951 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
10952 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
10953 },
10954 })
10955}
10956
David Benjaminf3fbade2016-09-19 13:08:16 -040010957func addPeekTests() {
10958 // Test SSL_peek works, including on empty records.
10959 testCases = append(testCases, testCase{
10960 name: "Peek-Basic",
10961 sendEmptyRecords: 1,
10962 flags: []string{"-peek-then-read"},
10963 })
10964
10965 // Test SSL_peek can drive the initial handshake.
10966 testCases = append(testCases, testCase{
10967 name: "Peek-ImplicitHandshake",
10968 flags: []string{
10969 "-peek-then-read",
10970 "-implicit-handshake",
10971 },
10972 })
10973
10974 // Test SSL_peek can discover and drive a renegotiation.
10975 testCases = append(testCases, testCase{
10976 name: "Peek-Renegotiate",
10977 config: Config{
10978 MaxVersion: VersionTLS12,
10979 },
10980 renegotiate: 1,
10981 flags: []string{
10982 "-peek-then-read",
10983 "-renegotiate-freely",
10984 "-expect-total-renegotiations", "1",
10985 },
10986 })
10987
10988 // Test SSL_peek can discover a close_notify.
10989 testCases = append(testCases, testCase{
10990 name: "Peek-Shutdown",
10991 config: Config{
10992 Bugs: ProtocolBugs{
10993 ExpectCloseNotify: true,
10994 },
10995 },
10996 flags: []string{
10997 "-peek-then-read",
10998 "-check-close-notify",
10999 },
11000 })
11001
11002 // Test SSL_peek can discover an alert.
11003 testCases = append(testCases, testCase{
11004 name: "Peek-Alert",
11005 config: Config{
11006 Bugs: ProtocolBugs{
11007 SendSpuriousAlert: alertRecordOverflow,
11008 },
11009 },
11010 flags: []string{"-peek-then-read"},
11011 shouldFail: true,
11012 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11013 })
11014
11015 // Test SSL_peek can handle KeyUpdate.
11016 testCases = append(testCases, testCase{
11017 name: "Peek-KeyUpdate",
11018 config: Config{
11019 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011020 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011021 sendKeyUpdates: 1,
11022 keyUpdateRequest: keyUpdateNotRequested,
11023 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011024 })
11025}
11026
David Benjamine6f22212016-11-08 14:28:24 -050011027func addRecordVersionTests() {
11028 for _, ver := range tlsVersions {
11029 // Test that the record version is enforced.
11030 testCases = append(testCases, testCase{
11031 name: "CheckRecordVersion-" + ver.name,
11032 config: Config{
11033 MinVersion: ver.version,
11034 MaxVersion: ver.version,
11035 Bugs: ProtocolBugs{
11036 SendRecordVersion: 0x03ff,
11037 },
11038 },
11039 shouldFail: true,
11040 expectedError: ":WRONG_VERSION_NUMBER:",
11041 })
11042
11043 // Test that the ClientHello may use any record version, for
11044 // compatibility reasons.
11045 testCases = append(testCases, testCase{
11046 testType: serverTest,
11047 name: "LooseInitialRecordVersion-" + ver.name,
11048 config: Config{
11049 MinVersion: ver.version,
11050 MaxVersion: ver.version,
11051 Bugs: ProtocolBugs{
11052 SendInitialRecordVersion: 0x03ff,
11053 },
11054 },
11055 })
11056
11057 // Test that garbage ClientHello record versions are rejected.
11058 testCases = append(testCases, testCase{
11059 testType: serverTest,
11060 name: "GarbageInitialRecordVersion-" + ver.name,
11061 config: Config{
11062 MinVersion: ver.version,
11063 MaxVersion: ver.version,
11064 Bugs: ProtocolBugs{
11065 SendInitialRecordVersion: 0xffff,
11066 },
11067 },
11068 shouldFail: true,
11069 expectedError: ":WRONG_VERSION_NUMBER:",
11070 })
11071 }
11072}
11073
David Benjamin2c516452016-11-15 10:16:54 +090011074func addCertificateTests() {
11075 // Test that a certificate chain with intermediate may be sent and
11076 // received as both client and server.
11077 for _, ver := range tlsVersions {
11078 testCases = append(testCases, testCase{
11079 testType: clientTest,
11080 name: "SendReceiveIntermediate-Client-" + ver.name,
11081 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011082 MinVersion: ver.version,
11083 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011084 Certificates: []Certificate{rsaChainCertificate},
11085 ClientAuth: RequireAnyClientCert,
11086 },
11087 expectPeerCertificate: &rsaChainCertificate,
11088 flags: []string{
11089 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11090 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11091 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11092 },
11093 })
11094
11095 testCases = append(testCases, testCase{
11096 testType: serverTest,
11097 name: "SendReceiveIntermediate-Server-" + ver.name,
11098 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011099 MinVersion: ver.version,
11100 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011101 Certificates: []Certificate{rsaChainCertificate},
11102 },
11103 expectPeerCertificate: &rsaChainCertificate,
11104 flags: []string{
11105 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11106 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11107 "-require-any-client-certificate",
11108 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11109 },
11110 })
11111 }
11112}
11113
David Benjaminbbaf3672016-11-17 10:53:09 +090011114func addRetainOnlySHA256ClientCertTests() {
11115 for _, ver := range tlsVersions {
11116 // Test that enabling
11117 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11118 // actually requesting a client certificate is a no-op.
11119 testCases = append(testCases, testCase{
11120 testType: serverTest,
11121 name: "RetainOnlySHA256-NoCert-" + ver.name,
11122 config: Config{
11123 MinVersion: ver.version,
11124 MaxVersion: ver.version,
11125 },
11126 flags: []string{
11127 "-retain-only-sha256-client-cert-initial",
11128 "-retain-only-sha256-client-cert-resume",
11129 },
11130 resumeSession: true,
11131 })
11132
11133 // Test that when retaining only a SHA-256 certificate is
11134 // enabled, the hash appears as expected.
11135 testCases = append(testCases, testCase{
11136 testType: serverTest,
11137 name: "RetainOnlySHA256-Cert-" + ver.name,
11138 config: Config{
11139 MinVersion: ver.version,
11140 MaxVersion: ver.version,
11141 Certificates: []Certificate{rsaCertificate},
11142 },
11143 flags: []string{
11144 "-verify-peer",
11145 "-retain-only-sha256-client-cert-initial",
11146 "-retain-only-sha256-client-cert-resume",
11147 "-expect-sha256-client-cert-initial",
11148 "-expect-sha256-client-cert-resume",
11149 },
11150 resumeSession: true,
11151 })
11152
11153 // Test that when the config changes from on to off, a
11154 // resumption is rejected because the server now wants the full
11155 // certificate chain.
11156 testCases = append(testCases, testCase{
11157 testType: serverTest,
11158 name: "RetainOnlySHA256-OnOff-" + ver.name,
11159 config: Config{
11160 MinVersion: ver.version,
11161 MaxVersion: ver.version,
11162 Certificates: []Certificate{rsaCertificate},
11163 },
11164 flags: []string{
11165 "-verify-peer",
11166 "-retain-only-sha256-client-cert-initial",
11167 "-expect-sha256-client-cert-initial",
11168 },
11169 resumeSession: true,
11170 expectResumeRejected: true,
11171 })
11172
11173 // Test that when the config changes from off to on, a
11174 // resumption is rejected because the server now wants just the
11175 // hash.
11176 testCases = append(testCases, testCase{
11177 testType: serverTest,
11178 name: "RetainOnlySHA256-OffOn-" + ver.name,
11179 config: Config{
11180 MinVersion: ver.version,
11181 MaxVersion: ver.version,
11182 Certificates: []Certificate{rsaCertificate},
11183 },
11184 flags: []string{
11185 "-verify-peer",
11186 "-retain-only-sha256-client-cert-resume",
11187 "-expect-sha256-client-cert-resume",
11188 },
11189 resumeSession: true,
11190 expectResumeRejected: true,
11191 })
11192 }
11193}
11194
Adam Langleya4b91982016-12-12 12:05:53 -080011195func addECDSAKeyUsageTests() {
11196 p256 := elliptic.P256()
11197 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11198 if err != nil {
11199 panic(err)
11200 }
11201
11202 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11203 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11204 if err != nil {
11205 panic(err)
11206 }
11207
11208 template := x509.Certificate{
11209 SerialNumber: serialNumber,
11210 Subject: pkix.Name{
11211 Organization: []string{"Acme Co"},
11212 },
11213 NotBefore: time.Now(),
11214 NotAfter: time.Now(),
11215
11216 // An ECC certificate with only the keyAgreement key usgae may
11217 // be used with ECDH, but not ECDSA.
11218 KeyUsage: x509.KeyUsageKeyAgreement,
11219 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11220 BasicConstraintsValid: true,
11221 }
11222
11223 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11224 if err != nil {
11225 panic(err)
11226 }
11227
11228 cert := Certificate{
11229 Certificate: [][]byte{derBytes},
11230 PrivateKey: priv,
11231 }
11232
11233 for _, ver := range tlsVersions {
11234 if ver.version < VersionTLS12 {
11235 continue
11236 }
11237
11238 testCases = append(testCases, testCase{
11239 testType: clientTest,
11240 name: "ECDSAKeyUsage-" + ver.name,
11241 config: Config{
11242 MinVersion: ver.version,
11243 MaxVersion: ver.version,
11244 Certificates: []Certificate{cert},
11245 },
11246 shouldFail: true,
11247 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11248 })
11249 }
11250}
11251
David Benjamin8c26d752017-03-26 15:13:51 -050011252func addExtraHandshakeTests() {
11253 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11254 // to ensure there is no transport I/O.
11255 testCases = append(testCases, testCase{
11256 testType: clientTest,
11257 name: "ExtraHandshake-Client-TLS12",
11258 config: Config{
11259 MinVersion: VersionTLS12,
11260 MaxVersion: VersionTLS12,
11261 },
11262 flags: []string{
11263 "-async",
11264 "-no-op-extra-handshake",
11265 },
11266 })
11267 testCases = append(testCases, testCase{
11268 testType: serverTest,
11269 name: "ExtraHandshake-Server-TLS12",
11270 config: Config{
11271 MinVersion: VersionTLS12,
11272 MaxVersion: VersionTLS12,
11273 },
11274 flags: []string{
11275 "-async",
11276 "-no-op-extra-handshake",
11277 },
11278 })
11279 testCases = append(testCases, testCase{
11280 testType: clientTest,
11281 name: "ExtraHandshake-Client-TLS13",
11282 config: Config{
11283 MinVersion: VersionTLS13,
11284 MaxVersion: VersionTLS13,
11285 },
11286 flags: []string{
11287 "-async",
11288 "-no-op-extra-handshake",
11289 },
11290 })
11291 testCases = append(testCases, testCase{
11292 testType: serverTest,
11293 name: "ExtraHandshake-Server-TLS13",
11294 config: Config{
11295 MinVersion: VersionTLS13,
11296 MaxVersion: VersionTLS13,
11297 },
11298 flags: []string{
11299 "-async",
11300 "-no-op-extra-handshake",
11301 },
11302 })
11303
11304 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11305 testCases = append(testCases, testCase{
11306 testType: serverTest,
11307 name: "ExtraHandshake-Server-EarlyData-TLS13",
11308 config: Config{
11309 MaxVersion: VersionTLS13,
11310 MinVersion: VersionTLS13,
11311 Bugs: ProtocolBugs{
11312 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11313 ExpectEarlyDataAccepted: true,
11314 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11315 },
11316 },
11317 messageCount: 2,
11318 resumeSession: true,
11319 flags: []string{
11320 "-async",
11321 "-enable-early-data",
11322 "-expect-accept-early-data",
11323 "-no-op-extra-handshake",
11324 },
11325 })
11326
11327 // An extra SSL_do_handshake drives the handshake to completion in False
11328 // Start. We test this by handshaking twice and asserting the False
11329 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11330 // how the test works.
11331 testCases = append(testCases, testCase{
11332 testType: clientTest,
11333 name: "ExtraHandshake-FalseStart",
11334 config: Config{
11335 MaxVersion: VersionTLS12,
11336 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11337 NextProtos: []string{"foo"},
11338 Bugs: ProtocolBugs{
11339 ExpectFalseStart: true,
11340 AlertBeforeFalseStartTest: alertAccessDenied,
11341 },
11342 },
11343 flags: []string{
11344 "-handshake-twice",
11345 "-false-start",
11346 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011347 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011348 },
11349 shimWritesFirst: true,
11350 shouldFail: true,
11351 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11352 expectedLocalError: "tls: peer did not false start: EOF",
11353 })
11354}
11355
Adam Langley7c803a62015-06-15 15:35:05 -070011356func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011357 defer wg.Done()
11358
11359 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011360 var err error
11361
David Benjaminba28dfc2016-11-15 17:47:21 +090011362 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011363 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11364 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011365 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011366 if err != nil {
11367 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11368 }
11369 break
11370 }
11371 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011372 } else if *repeatUntilFailure {
11373 for err == nil {
11374 statusChan <- statusMsg{test: test, started: true}
11375 err = runTest(test, shimPath, -1)
11376 }
11377 } else {
11378 statusChan <- statusMsg{test: test, started: true}
11379 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011380 }
Adam Langley95c29f32014-06-20 12:00:00 -070011381 statusChan <- statusMsg{test: test, err: err}
11382 }
11383}
11384
11385type statusMsg struct {
11386 test *testCase
11387 started bool
11388 err error
11389}
11390
David Benjamin5f237bc2015-02-11 17:14:15 -050011391func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011392 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011393
David Benjamin5f237bc2015-02-11 17:14:15 -050011394 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011395 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011396 if !*pipe {
11397 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011398 var erase string
11399 for i := 0; i < lineLen; i++ {
11400 erase += "\b \b"
11401 }
11402 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011403 }
11404
Adam Langley95c29f32014-06-20 12:00:00 -070011405 if msg.started {
11406 started++
11407 } else {
11408 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011409
11410 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011411 if msg.err == errUnimplemented {
11412 if *pipe {
11413 // Print each test instead of a status line.
11414 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11415 }
11416 unimplemented++
11417 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11418 } else {
11419 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11420 failed++
11421 testOutput.addResult(msg.test.name, "FAIL")
11422 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011423 } else {
11424 if *pipe {
11425 // Print each test instead of a status line.
11426 fmt.Printf("PASSED (%s)\n", msg.test.name)
11427 }
11428 testOutput.addResult(msg.test.name, "PASS")
11429 }
Adam Langley95c29f32014-06-20 12:00:00 -070011430 }
11431
David Benjamin5f237bc2015-02-11 17:14:15 -050011432 if !*pipe {
11433 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011434 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011435 lineLen = len(line)
11436 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011437 }
Adam Langley95c29f32014-06-20 12:00:00 -070011438 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011439
11440 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011441}
11442
11443func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011444 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011445 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011446 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011447
Adam Langley7c803a62015-06-15 15:35:05 -070011448 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011449 addCipherSuiteTests()
11450 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011451 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011452 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011453 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011454 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011455 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011456 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011457 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011458 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011459 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011460 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011461 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011462 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011463 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011464 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011465 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011466 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011467 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011468 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011469 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011470 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011471 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011472 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011473 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011474 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011475 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011476 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011477 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011478 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011479 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011480 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011481 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011482 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011483
11484 var wg sync.WaitGroup
11485
Adam Langley7c803a62015-06-15 15:35:05 -070011486 statusChan := make(chan statusMsg, *numWorkers)
11487 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011488 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011489
EKRf71d7ed2016-08-06 13:25:12 -070011490 if len(*shimConfigFile) != 0 {
11491 encoded, err := ioutil.ReadFile(*shimConfigFile)
11492 if err != nil {
11493 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11494 os.Exit(1)
11495 }
11496
11497 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11498 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11499 os.Exit(1)
11500 }
11501 }
11502
David Benjamin025b3d32014-07-01 19:53:04 -040011503 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011504
Adam Langley7c803a62015-06-15 15:35:05 -070011505 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011506 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011507 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011508 }
11509
David Benjamin270f0a72016-03-17 14:41:36 -040011510 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011511 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011512 matched := true
11513 if len(*testToRun) != 0 {
11514 var err error
11515 matched, err = filepath.Match(*testToRun, testCases[i].name)
11516 if err != nil {
11517 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11518 os.Exit(1)
11519 }
11520 }
11521
EKRf71d7ed2016-08-06 13:25:12 -070011522 if !*includeDisabled {
11523 for pattern := range shimConfig.DisabledTests {
11524 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11525 if err != nil {
11526 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11527 os.Exit(1)
11528 }
11529
11530 if isDisabled {
11531 matched = false
11532 break
11533 }
11534 }
11535 }
11536
David Benjamin17e12922016-07-28 18:04:43 -040011537 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011538 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011539 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011540
11541 // Only run one test if repeating until failure.
11542 if *repeatUntilFailure {
11543 break
11544 }
Adam Langley95c29f32014-06-20 12:00:00 -070011545 }
11546 }
David Benjamin17e12922016-07-28 18:04:43 -040011547
David Benjamin270f0a72016-03-17 14:41:36 -040011548 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011549 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011550 os.Exit(1)
11551 }
Adam Langley95c29f32014-06-20 12:00:00 -070011552
11553 close(testChan)
11554 wg.Wait()
11555 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011556 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011557
11558 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011559
11560 if *jsonOutput != "" {
11561 if err := testOutput.writeTo(*jsonOutput); err != nil {
11562 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11563 }
11564 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011565
EKR842ae6c2016-07-27 09:22:05 +020011566 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11567 os.Exit(1)
11568 }
11569
11570 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011571 os.Exit(1)
11572 }
Adam Langley95c29f32014-06-20 12:00:00 -070011573}